From d9990a276000e5f07aac30f5363735ad88cf2bb5 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 3 Mar 2021 16:43:33 +0300 Subject: [PATCH] Add method for sending transfer requests. --- package-lock.json | 763 ++++++++++++++++++ package.json | 3 + src/app/_services/transaction.service.ts | 50 +- .../disbursement/disbursement.component.ts | 8 +- src/assets/js/ethtx/dist/hex.d.ts | 5 + src/assets/js/ethtx/dist/hex.js | 41 + src/assets/js/ethtx/dist/index.d.ts | 1 + src/assets/js/ethtx/dist/index.js | 5 + src/assets/js/ethtx/dist/tx.d.ts | 29 + src/assets/js/ethtx/dist/tx.js | 121 +++ src/environments/environment.prod.ts | 4 +- src/environments/environment.ts | 4 +- 12 files changed, 1018 insertions(+), 16 deletions(-) create mode 100644 src/assets/js/ethtx/dist/hex.d.ts create mode 100644 src/assets/js/ethtx/dist/hex.js create mode 100644 src/assets/js/ethtx/dist/index.d.ts create mode 100644 src/assets/js/ethtx/dist/index.js create mode 100644 src/assets/js/ethtx/dist/tx.d.ts create mode 100644 src/assets/js/ethtx/dist/tx.js diff --git a/package-lock.json b/package-lock.json index 6856ed8..e446ed9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,7 @@ "cic-client-meta": "0.0.7-alpha.3", "datatables.net": "^1.10.22", "datatables.net-dt": "^1.10.22", + "ethers": "^5.0.31", "jquery": "^3.5.1", "mocha": "^8.2.1", "moolb": "^0.1.0", @@ -34,6 +35,7 @@ "openpgp": "^4.10.10", "popper.js": "^1.16.1", "rxjs": "~6.6.0", + "sha3": "^2.1.4", "tslib": "^2.0.0", "vcard-parser": "^1.0.0", "vcards-js": "^2.10.0", @@ -59,6 +61,7 @@ "karma-jasmine-html-reporter": "^1.5.0", "karma-junit-reporter": "^2.0.1", "protractor": "~7.0.0", + "secp256k1": "^4.0.2", "ts-node": "~8.3.0", "tslint": "~6.1.0", "typescript": "~4.0.2" @@ -1942,6 +1945,25 @@ "@ethersproject/bytes": "^5.0.9" } }, + "node_modules/@ethersproject/basex": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/@ethersproject/basex/-/basex-5.0.8.tgz", + "integrity": "sha512-PCVKZIShBQUqAXjJSvaCidThPvL0jaaQZcewJc0sf8Xx05BizaOS8r3jdPdpNdY+/qZtRDqwHTSKjvR/xssyLQ==", + "funding": [ + { + "type": "individual", + "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "dependencies": { + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/properties": "^5.0.7" + } + }, "node_modules/@ethersproject/bignumber": { "version": "5.0.14", "resolved": "https://registry.npmjs.org/@ethersproject/bignumber/-/bignumber-5.0.14.tgz", @@ -1973,6 +1995,58 @@ "@ethersproject/bignumber": "^5.0.13" } }, + "node_modules/@ethersproject/contracts": { + "version": "5.0.11", + "resolved": "https://registry.npmjs.org/@ethersproject/contracts/-/contracts-5.0.11.tgz", + "integrity": "sha512-FTUUd/6x00dYL2VufE2VowZ7h3mAyBfCQMGwI3tKDIWka+C0CunllFiKrlYCdiHFuVeMotR65dIcnzbLn72MCw==", + "funding": [ + { + "type": "individual", + "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "dependencies": { + "@ethersproject/abi": "^5.0.10", + "@ethersproject/abstract-provider": "^5.0.8", + "@ethersproject/abstract-signer": "^5.0.10", + "@ethersproject/address": "^5.0.9", + "@ethersproject/bignumber": "^5.0.13", + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/constants": "^5.0.8", + "@ethersproject/logger": "^5.0.8", + "@ethersproject/properties": "^5.0.7" + } + }, + "node_modules/@ethersproject/contracts/node_modules/@ethersproject/abi": { + "version": "5.0.12", + "resolved": "https://registry.npmjs.org/@ethersproject/abi/-/abi-5.0.12.tgz", + "integrity": "sha512-Ujr/3bwyYYjXLDQfebeiiTuvOw9XtUKM8av6YkoBeMXyGQM9GkjrQlwJMNwGTmqjATH/ZNbRgCh98GjOLiIB1Q==", + "funding": [ + { + "type": "individual", + "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "dependencies": { + "@ethersproject/address": "^5.0.9", + "@ethersproject/bignumber": "^5.0.13", + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/constants": "^5.0.8", + "@ethersproject/hash": "^5.0.10", + "@ethersproject/keccak256": "^5.0.7", + "@ethersproject/logger": "^5.0.8", + "@ethersproject/properties": "^5.0.7", + "@ethersproject/strings": "^5.0.8" + } + }, "node_modules/@ethersproject/hash": { "version": "5.0.11", "resolved": "https://registry.npmjs.org/@ethersproject/hash/-/hash-5.0.11.tgz", @@ -1988,6 +2062,70 @@ "@ethersproject/strings": "^5.0.8" } }, + "node_modules/@ethersproject/hdnode": { + "version": "5.0.9", + "resolved": "https://registry.npmjs.org/@ethersproject/hdnode/-/hdnode-5.0.9.tgz", + "integrity": "sha512-S5UMmIC6XfFtqhUK4uTjD8GPNzSbE+sZ/0VMqFnA3zAJ+cEFZuEyhZDYnl2ItGJzjT4jsy+uEy1SIl3baYK1PQ==", + "funding": [ + { + "type": "individual", + "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "dependencies": { + "@ethersproject/abstract-signer": "^5.0.10", + "@ethersproject/basex": "^5.0.7", + "@ethersproject/bignumber": "^5.0.13", + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/logger": "^5.0.8", + "@ethersproject/pbkdf2": "^5.0.7", + "@ethersproject/properties": "^5.0.7", + "@ethersproject/sha2": "^5.0.7", + "@ethersproject/signing-key": "^5.0.8", + "@ethersproject/strings": "^5.0.8", + "@ethersproject/transactions": "^5.0.9", + "@ethersproject/wordlists": "^5.0.8" + } + }, + "node_modules/@ethersproject/json-wallets": { + "version": "5.0.11", + "resolved": "https://registry.npmjs.org/@ethersproject/json-wallets/-/json-wallets-5.0.11.tgz", + "integrity": "sha512-0GhWScWUlXXb4qJNp0wmkU95QS3YdN9UMOfMSEl76CRANWWrmyzxcBVSXSBu5iQ0/W8wO+xGlJJ3tpA6v3mbIw==", + "funding": [ + { + "type": "individual", + "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "dependencies": { + "@ethersproject/abstract-signer": "^5.0.10", + "@ethersproject/address": "^5.0.9", + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/hdnode": "^5.0.8", + "@ethersproject/keccak256": "^5.0.7", + "@ethersproject/logger": "^5.0.8", + "@ethersproject/pbkdf2": "^5.0.7", + "@ethersproject/properties": "^5.0.7", + "@ethersproject/random": "^5.0.7", + "@ethersproject/strings": "^5.0.8", + "@ethersproject/transactions": "^5.0.9", + "aes-js": "3.0.0", + "scrypt-js": "3.0.1" + } + }, + "node_modules/@ethersproject/json-wallets/node_modules/aes-js": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.0.0.tgz", + "integrity": "sha1-4h3xCtbCBTKVvLuNq0Cwnb6ofk0=" + }, "node_modules/@ethersproject/keccak256": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/@ethersproject/keccak256/-/keccak256-5.0.8.tgz", @@ -2015,6 +2153,25 @@ "@ethersproject/logger": "^5.0.8" } }, + "node_modules/@ethersproject/pbkdf2": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/@ethersproject/pbkdf2/-/pbkdf2-5.0.8.tgz", + "integrity": "sha512-UlmAMGbIPaS2xXsI38FbePVTfJMuU9jnwcqVn3p88HxPF4kD897ha+l3TNsBqJqf32UbQL5GImnf1oJkSKq4vQ==", + "funding": [ + { + "type": "individual", + "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "dependencies": { + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/sha2": "^5.0.7" + } + }, "node_modules/@ethersproject/properties": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/@ethersproject/properties/-/properties-5.0.8.tgz", @@ -2023,6 +2180,81 @@ "@ethersproject/logger": "^5.0.8" } }, + "node_modules/@ethersproject/providers": { + "version": "5.0.23", + "resolved": "https://registry.npmjs.org/@ethersproject/providers/-/providers-5.0.23.tgz", + "integrity": "sha512-eJ94z2tgPaUgUmxwd3BVkIzkgkbNIkY6wRPVas04LVaBTycObQbgj794aaUu2bfk7+Bn2B/gjUZtJW1ybxh9/A==", + "funding": [ + { + "type": "individual", + "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "dependencies": { + "@ethersproject/abstract-provider": "^5.0.8", + "@ethersproject/abstract-signer": "^5.0.10", + "@ethersproject/address": "^5.0.9", + "@ethersproject/basex": "^5.0.7", + "@ethersproject/bignumber": "^5.0.13", + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/constants": "^5.0.8", + "@ethersproject/hash": "^5.0.10", + "@ethersproject/logger": "^5.0.8", + "@ethersproject/networks": "^5.0.7", + "@ethersproject/properties": "^5.0.7", + "@ethersproject/random": "^5.0.7", + "@ethersproject/rlp": "^5.0.7", + "@ethersproject/sha2": "^5.0.7", + "@ethersproject/strings": "^5.0.8", + "@ethersproject/transactions": "^5.0.9", + "@ethersproject/web": "^5.0.12", + "bech32": "1.1.4", + "ws": "7.2.3" + } + }, + "node_modules/@ethersproject/providers/node_modules/ws": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz", + "integrity": "sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ==", + "engines": { + "node": ">=8.3.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/@ethersproject/random": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/@ethersproject/random/-/random-5.0.8.tgz", + "integrity": "sha512-4rHtotmd9NjklW0eDvByicEkL+qareIyFSbG1ShC8tPJJSAC0g55oQWzw+3nfdRCgBHRuEE7S8EcPcTVPvZ9cA==", + "funding": [ + { + "type": "individual", + "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "dependencies": { + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/logger": "^5.0.8" + } + }, "node_modules/@ethersproject/rlp": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/@ethersproject/rlp/-/rlp-5.0.8.tgz", @@ -2032,6 +2264,35 @@ "@ethersproject/logger": "^5.0.8" } }, + "node_modules/@ethersproject/sha2": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/@ethersproject/sha2/-/sha2-5.0.8.tgz", + "integrity": "sha512-ILP1ZgyvDj4rrdE+AXrTv9V88m7x87uga2VZ/FeULKPumOEw/4bGnJz/oQ8zDnDvVYRCJ+48VaQBS2CFLbk1ww==", + "funding": [ + { + "type": "individual", + "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "dependencies": { + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/logger": "^5.0.8", + "hash.js": "1.1.3" + } + }, + "node_modules/@ethersproject/sha2/node_modules/hash.js": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.3.tgz", + "integrity": "sha512-/UETyP0W22QILqS+6HowevwhEFJ3MBJnwTf75Qob9Wz9t0DPuisL8kW8YZMK62dHAKE1c1p+gY1TtOLY+USEHA==", + "dependencies": { + "inherits": "^2.0.3", + "minimalistic-assert": "^1.0.0" + } + }, "node_modules/@ethersproject/signing-key": { "version": "5.0.10", "resolved": "https://registry.npmjs.org/@ethersproject/signing-key/-/signing-key-5.0.10.tgz", @@ -2062,6 +2323,28 @@ "minimalistic-crypto-utils": "^1.0.1" } }, + "node_modules/@ethersproject/solidity": { + "version": "5.0.9", + "resolved": "https://registry.npmjs.org/@ethersproject/solidity/-/solidity-5.0.9.tgz", + "integrity": "sha512-LIxSAYEQgLRXE3mRPCq39ou61kqP8fDrGqEeNcaNJS3aLbmAOS8MZp56uK++WsdI9hj8sNsFh78hrAa6zR9Jag==", + "funding": [ + { + "type": "individual", + "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "dependencies": { + "@ethersproject/bignumber": "^5.0.13", + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/keccak256": "^5.0.7", + "@ethersproject/sha2": "^5.0.7", + "@ethersproject/strings": "^5.0.8" + } + }, "node_modules/@ethersproject/strings": { "version": "5.0.9", "resolved": "https://registry.npmjs.org/@ethersproject/strings/-/strings-5.0.9.tgz", @@ -2088,6 +2371,58 @@ "@ethersproject/signing-key": "^5.0.8" } }, + "node_modules/@ethersproject/units": { + "version": "5.0.10", + "resolved": "https://registry.npmjs.org/@ethersproject/units/-/units-5.0.10.tgz", + "integrity": "sha512-eaiHi9ham5lbC7qpqxpae7OY/nHJUnRUnFFuEwi2VB5Nwe3Np468OAV+e+HR+jAK4fHXQE6PFBTxWGtnZuO37g==", + "funding": [ + { + "type": "individual", + "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "dependencies": { + "@ethersproject/bignumber": "^5.0.13", + "@ethersproject/constants": "^5.0.8", + "@ethersproject/logger": "^5.0.8" + } + }, + "node_modules/@ethersproject/wallet": { + "version": "5.0.11", + "resolved": "https://registry.npmjs.org/@ethersproject/wallet/-/wallet-5.0.11.tgz", + "integrity": "sha512-2Fg/DOvUltR7aZTOyWWlQhru+SKvq2UE3uEhXSyCFgMqDQNuc2nHXh1SHJtN65jsEbjVIppOe1Q7EQMvhmeeRw==", + "funding": [ + { + "type": "individual", + "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "dependencies": { + "@ethersproject/abstract-provider": "^5.0.8", + "@ethersproject/abstract-signer": "^5.0.10", + "@ethersproject/address": "^5.0.9", + "@ethersproject/bignumber": "^5.0.13", + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/hash": "^5.0.10", + "@ethersproject/hdnode": "^5.0.8", + "@ethersproject/json-wallets": "^5.0.10", + "@ethersproject/keccak256": "^5.0.7", + "@ethersproject/logger": "^5.0.8", + "@ethersproject/properties": "^5.0.7", + "@ethersproject/random": "^5.0.7", + "@ethersproject/signing-key": "^5.0.8", + "@ethersproject/transactions": "^5.0.9", + "@ethersproject/wordlists": "^5.0.8" + } + }, "node_modules/@ethersproject/web": { "version": "5.0.13", "resolved": "https://registry.npmjs.org/@ethersproject/web/-/web-5.0.13.tgz", @@ -2100,6 +2435,28 @@ "@ethersproject/strings": "^5.0.8" } }, + "node_modules/@ethersproject/wordlists": { + "version": "5.0.9", + "resolved": "https://registry.npmjs.org/@ethersproject/wordlists/-/wordlists-5.0.9.tgz", + "integrity": "sha512-Sn6MTjZkfbriod6GG6+p43W09HOXT4gwcDVNj0YoPYlo4Zq2Fk6b1CU9KUX3c6aI17PrgYb4qwZm5BMuORyqyQ==", + "funding": [ + { + "type": "individual", + "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "dependencies": { + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/hash": "^5.0.10", + "@ethersproject/logger": "^5.0.8", + "@ethersproject/properties": "^5.0.7", + "@ethersproject/strings": "^5.0.8" + } + }, "node_modules/@istanbuljs/schema": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.2.tgz", @@ -3793,6 +4150,11 @@ "tweetnacl": "^0.14.3" } }, + "node_modules/bech32": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/bech32/-/bech32-1.1.4.tgz", + "integrity": "sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ==" + }, "node_modules/big.js": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", @@ -7141,6 +7503,79 @@ "node": ">=10.0.0" } }, + "node_modules/ethers": { + "version": "5.0.31", + "resolved": "https://registry.npmjs.org/ethers/-/ethers-5.0.31.tgz", + "integrity": "sha512-zpq0YbNFLFn+t+ibS8UkVWFeK5w6rVMSvbSHrHAQslfazovLnQ/mc2gdN5+6P45/k8fPgHrfHrYvJ4XvyK/S1A==", + "funding": [ + { + "type": "individual", + "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "dependencies": { + "@ethersproject/abi": "5.0.12", + "@ethersproject/abstract-provider": "5.0.9", + "@ethersproject/abstract-signer": "5.0.13", + "@ethersproject/address": "5.0.10", + "@ethersproject/base64": "5.0.8", + "@ethersproject/basex": "5.0.8", + "@ethersproject/bignumber": "5.0.14", + "@ethersproject/bytes": "5.0.10", + "@ethersproject/constants": "5.0.9", + "@ethersproject/contracts": "5.0.11", + "@ethersproject/hash": "5.0.11", + "@ethersproject/hdnode": "5.0.9", + "@ethersproject/json-wallets": "5.0.11", + "@ethersproject/keccak256": "5.0.8", + "@ethersproject/logger": "5.0.9", + "@ethersproject/networks": "5.0.8", + "@ethersproject/pbkdf2": "5.0.8", + "@ethersproject/properties": "5.0.8", + "@ethersproject/providers": "5.0.23", + "@ethersproject/random": "5.0.8", + "@ethersproject/rlp": "5.0.8", + "@ethersproject/sha2": "5.0.8", + "@ethersproject/signing-key": "5.0.10", + "@ethersproject/solidity": "5.0.9", + "@ethersproject/strings": "5.0.9", + "@ethersproject/transactions": "5.0.10", + "@ethersproject/units": "5.0.10", + "@ethersproject/wallet": "5.0.11", + "@ethersproject/web": "5.0.13", + "@ethersproject/wordlists": "5.0.9" + } + }, + "node_modules/ethers/node_modules/@ethersproject/abi": { + "version": "5.0.12", + "resolved": "https://registry.npmjs.org/@ethersproject/abi/-/abi-5.0.12.tgz", + "integrity": "sha512-Ujr/3bwyYYjXLDQfebeiiTuvOw9XtUKM8av6YkoBeMXyGQM9GkjrQlwJMNwGTmqjATH/ZNbRgCh98GjOLiIB1Q==", + "funding": [ + { + "type": "individual", + "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "dependencies": { + "@ethersproject/address": "^5.0.9", + "@ethersproject/bignumber": "^5.0.13", + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/constants": "^5.0.8", + "@ethersproject/hash": "^5.0.10", + "@ethersproject/keccak256": "^5.0.7", + "@ethersproject/logger": "^5.0.8", + "@ethersproject/properties": "^5.0.7", + "@ethersproject/strings": "^5.0.8" + } + }, "node_modules/ethjs-unit": { "version": "0.1.6", "resolved": "https://registry.npmjs.org/ethjs-unit/-/ethjs-unit-0.1.6.tgz", @@ -16013,6 +16448,37 @@ "sha.js": "bin.js" } }, + "node_modules/sha3": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/sha3/-/sha3-2.1.4.tgz", + "integrity": "sha512-S8cNxbyb0UGUM2VhRD4Poe5N58gJnJsLJ5vC7FYWGUmGhcsj4++WaIOBFVDxlG0W3To6xBuiRh+i0Qp2oNCOtg==", + "dependencies": { + "buffer": "6.0.3" + } + }, + "node_modules/sha3/node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, "node_modules/shebang-command": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", @@ -21787,6 +22253,15 @@ "@ethersproject/bytes": "^5.0.9" } }, + "@ethersproject/basex": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/@ethersproject/basex/-/basex-5.0.8.tgz", + "integrity": "sha512-PCVKZIShBQUqAXjJSvaCidThPvL0jaaQZcewJc0sf8Xx05BizaOS8r3jdPdpNdY+/qZtRDqwHTSKjvR/xssyLQ==", + "requires": { + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/properties": "^5.0.7" + } + }, "@ethersproject/bignumber": { "version": "5.0.14", "resolved": "https://registry.npmjs.org/@ethersproject/bignumber/-/bignumber-5.0.14.tgz", @@ -21820,6 +22295,40 @@ "@ethersproject/bignumber": "^5.0.13" } }, + "@ethersproject/contracts": { + "version": "5.0.11", + "resolved": "https://registry.npmjs.org/@ethersproject/contracts/-/contracts-5.0.11.tgz", + "integrity": "sha512-FTUUd/6x00dYL2VufE2VowZ7h3mAyBfCQMGwI3tKDIWka+C0CunllFiKrlYCdiHFuVeMotR65dIcnzbLn72MCw==", + "requires": { + "@ethersproject/abi": "^5.0.10", + "@ethersproject/abstract-provider": "^5.0.8", + "@ethersproject/abstract-signer": "^5.0.10", + "@ethersproject/address": "^5.0.9", + "@ethersproject/bignumber": "^5.0.13", + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/constants": "^5.0.8", + "@ethersproject/logger": "^5.0.8", + "@ethersproject/properties": "^5.0.7" + }, + "dependencies": { + "@ethersproject/abi": { + "version": "5.0.12", + "resolved": "https://registry.npmjs.org/@ethersproject/abi/-/abi-5.0.12.tgz", + "integrity": "sha512-Ujr/3bwyYYjXLDQfebeiiTuvOw9XtUKM8av6YkoBeMXyGQM9GkjrQlwJMNwGTmqjATH/ZNbRgCh98GjOLiIB1Q==", + "requires": { + "@ethersproject/address": "^5.0.9", + "@ethersproject/bignumber": "^5.0.13", + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/constants": "^5.0.8", + "@ethersproject/hash": "^5.0.10", + "@ethersproject/keccak256": "^5.0.7", + "@ethersproject/logger": "^5.0.8", + "@ethersproject/properties": "^5.0.7", + "@ethersproject/strings": "^5.0.8" + } + } + } + }, "@ethersproject/hash": { "version": "5.0.11", "resolved": "https://registry.npmjs.org/@ethersproject/hash/-/hash-5.0.11.tgz", @@ -21835,6 +22344,52 @@ "@ethersproject/strings": "^5.0.8" } }, + "@ethersproject/hdnode": { + "version": "5.0.9", + "resolved": "https://registry.npmjs.org/@ethersproject/hdnode/-/hdnode-5.0.9.tgz", + "integrity": "sha512-S5UMmIC6XfFtqhUK4uTjD8GPNzSbE+sZ/0VMqFnA3zAJ+cEFZuEyhZDYnl2ItGJzjT4jsy+uEy1SIl3baYK1PQ==", + "requires": { + "@ethersproject/abstract-signer": "^5.0.10", + "@ethersproject/basex": "^5.0.7", + "@ethersproject/bignumber": "^5.0.13", + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/logger": "^5.0.8", + "@ethersproject/pbkdf2": "^5.0.7", + "@ethersproject/properties": "^5.0.7", + "@ethersproject/sha2": "^5.0.7", + "@ethersproject/signing-key": "^5.0.8", + "@ethersproject/strings": "^5.0.8", + "@ethersproject/transactions": "^5.0.9", + "@ethersproject/wordlists": "^5.0.8" + } + }, + "@ethersproject/json-wallets": { + "version": "5.0.11", + "resolved": "https://registry.npmjs.org/@ethersproject/json-wallets/-/json-wallets-5.0.11.tgz", + "integrity": "sha512-0GhWScWUlXXb4qJNp0wmkU95QS3YdN9UMOfMSEl76CRANWWrmyzxcBVSXSBu5iQ0/W8wO+xGlJJ3tpA6v3mbIw==", + "requires": { + "@ethersproject/abstract-signer": "^5.0.10", + "@ethersproject/address": "^5.0.9", + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/hdnode": "^5.0.8", + "@ethersproject/keccak256": "^5.0.7", + "@ethersproject/logger": "^5.0.8", + "@ethersproject/pbkdf2": "^5.0.7", + "@ethersproject/properties": "^5.0.7", + "@ethersproject/random": "^5.0.7", + "@ethersproject/strings": "^5.0.8", + "@ethersproject/transactions": "^5.0.9", + "aes-js": "3.0.0", + "scrypt-js": "3.0.1" + }, + "dependencies": { + "aes-js": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.0.0.tgz", + "integrity": "sha1-4h3xCtbCBTKVvLuNq0Cwnb6ofk0=" + } + } + }, "@ethersproject/keccak256": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/@ethersproject/keccak256/-/keccak256-5.0.8.tgz", @@ -21864,6 +22419,15 @@ "@ethersproject/logger": "^5.0.8" } }, + "@ethersproject/pbkdf2": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/@ethersproject/pbkdf2/-/pbkdf2-5.0.8.tgz", + "integrity": "sha512-UlmAMGbIPaS2xXsI38FbePVTfJMuU9jnwcqVn3p88HxPF4kD897ha+l3TNsBqJqf32UbQL5GImnf1oJkSKq4vQ==", + "requires": { + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/sha2": "^5.0.7" + } + }, "@ethersproject/properties": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/@ethersproject/properties/-/properties-5.0.8.tgz", @@ -21872,6 +22436,49 @@ "@ethersproject/logger": "^5.0.8" } }, + "@ethersproject/providers": { + "version": "5.0.23", + "resolved": "https://registry.npmjs.org/@ethersproject/providers/-/providers-5.0.23.tgz", + "integrity": "sha512-eJ94z2tgPaUgUmxwd3BVkIzkgkbNIkY6wRPVas04LVaBTycObQbgj794aaUu2bfk7+Bn2B/gjUZtJW1ybxh9/A==", + "requires": { + "@ethersproject/abstract-provider": "^5.0.8", + "@ethersproject/abstract-signer": "^5.0.10", + "@ethersproject/address": "^5.0.9", + "@ethersproject/basex": "^5.0.7", + "@ethersproject/bignumber": "^5.0.13", + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/constants": "^5.0.8", + "@ethersproject/hash": "^5.0.10", + "@ethersproject/logger": "^5.0.8", + "@ethersproject/networks": "^5.0.7", + "@ethersproject/properties": "^5.0.7", + "@ethersproject/random": "^5.0.7", + "@ethersproject/rlp": "^5.0.7", + "@ethersproject/sha2": "^5.0.7", + "@ethersproject/strings": "^5.0.8", + "@ethersproject/transactions": "^5.0.9", + "@ethersproject/web": "^5.0.12", + "bech32": "1.1.4", + "ws": "7.2.3" + }, + "dependencies": { + "ws": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz", + "integrity": "sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ==", + "requires": {} + } + } + }, + "@ethersproject/random": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/@ethersproject/random/-/random-5.0.8.tgz", + "integrity": "sha512-4rHtotmd9NjklW0eDvByicEkL+qareIyFSbG1ShC8tPJJSAC0g55oQWzw+3nfdRCgBHRuEE7S8EcPcTVPvZ9cA==", + "requires": { + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/logger": "^5.0.8" + } + }, "@ethersproject/rlp": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/@ethersproject/rlp/-/rlp-5.0.8.tgz", @@ -21881,6 +22488,27 @@ "@ethersproject/logger": "^5.0.8" } }, + "@ethersproject/sha2": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/@ethersproject/sha2/-/sha2-5.0.8.tgz", + "integrity": "sha512-ILP1ZgyvDj4rrdE+AXrTv9V88m7x87uga2VZ/FeULKPumOEw/4bGnJz/oQ8zDnDvVYRCJ+48VaQBS2CFLbk1ww==", + "requires": { + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/logger": "^5.0.8", + "hash.js": "1.1.3" + }, + "dependencies": { + "hash.js": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.3.tgz", + "integrity": "sha512-/UETyP0W22QILqS+6HowevwhEFJ3MBJnwTf75Qob9Wz9t0DPuisL8kW8YZMK62dHAKE1c1p+gY1TtOLY+USEHA==", + "requires": { + "inherits": "^2.0.3", + "minimalistic-assert": "^1.0.0" + } + } + } + }, "@ethersproject/signing-key": { "version": "5.0.10", "resolved": "https://registry.npmjs.org/@ethersproject/signing-key/-/signing-key-5.0.10.tgz", @@ -21913,6 +22541,18 @@ } } }, + "@ethersproject/solidity": { + "version": "5.0.9", + "resolved": "https://registry.npmjs.org/@ethersproject/solidity/-/solidity-5.0.9.tgz", + "integrity": "sha512-LIxSAYEQgLRXE3mRPCq39ou61kqP8fDrGqEeNcaNJS3aLbmAOS8MZp56uK++WsdI9hj8sNsFh78hrAa6zR9Jag==", + "requires": { + "@ethersproject/bignumber": "^5.0.13", + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/keccak256": "^5.0.7", + "@ethersproject/sha2": "^5.0.7", + "@ethersproject/strings": "^5.0.8" + } + }, "@ethersproject/strings": { "version": "5.0.9", "resolved": "https://registry.npmjs.org/@ethersproject/strings/-/strings-5.0.9.tgz", @@ -21939,6 +22579,38 @@ "@ethersproject/signing-key": "^5.0.8" } }, + "@ethersproject/units": { + "version": "5.0.10", + "resolved": "https://registry.npmjs.org/@ethersproject/units/-/units-5.0.10.tgz", + "integrity": "sha512-eaiHi9ham5lbC7qpqxpae7OY/nHJUnRUnFFuEwi2VB5Nwe3Np468OAV+e+HR+jAK4fHXQE6PFBTxWGtnZuO37g==", + "requires": { + "@ethersproject/bignumber": "^5.0.13", + "@ethersproject/constants": "^5.0.8", + "@ethersproject/logger": "^5.0.8" + } + }, + "@ethersproject/wallet": { + "version": "5.0.11", + "resolved": "https://registry.npmjs.org/@ethersproject/wallet/-/wallet-5.0.11.tgz", + "integrity": "sha512-2Fg/DOvUltR7aZTOyWWlQhru+SKvq2UE3uEhXSyCFgMqDQNuc2nHXh1SHJtN65jsEbjVIppOe1Q7EQMvhmeeRw==", + "requires": { + "@ethersproject/abstract-provider": "^5.0.8", + "@ethersproject/abstract-signer": "^5.0.10", + "@ethersproject/address": "^5.0.9", + "@ethersproject/bignumber": "^5.0.13", + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/hash": "^5.0.10", + "@ethersproject/hdnode": "^5.0.8", + "@ethersproject/json-wallets": "^5.0.10", + "@ethersproject/keccak256": "^5.0.7", + "@ethersproject/logger": "^5.0.8", + "@ethersproject/properties": "^5.0.7", + "@ethersproject/random": "^5.0.7", + "@ethersproject/signing-key": "^5.0.8", + "@ethersproject/transactions": "^5.0.9", + "@ethersproject/wordlists": "^5.0.8" + } + }, "@ethersproject/web": { "version": "5.0.13", "resolved": "https://registry.npmjs.org/@ethersproject/web/-/web-5.0.13.tgz", @@ -21951,6 +22623,18 @@ "@ethersproject/strings": "^5.0.8" } }, + "@ethersproject/wordlists": { + "version": "5.0.9", + "resolved": "https://registry.npmjs.org/@ethersproject/wordlists/-/wordlists-5.0.9.tgz", + "integrity": "sha512-Sn6MTjZkfbriod6GG6+p43W09HOXT4gwcDVNj0YoPYlo4Zq2Fk6b1CU9KUX3c6aI17PrgYb4qwZm5BMuORyqyQ==", + "requires": { + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/hash": "^5.0.10", + "@ethersproject/logger": "^5.0.8", + "@ethersproject/properties": "^5.0.7", + "@ethersproject/strings": "^5.0.8" + } + }, "@istanbuljs/schema": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.2.tgz", @@ -23386,6 +24070,11 @@ "tweetnacl": "^0.14.3" } }, + "bech32": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/bech32/-/bech32-1.1.4.tgz", + "integrity": "sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ==" + }, "big.js": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", @@ -26282,6 +26971,61 @@ } } }, + "ethers": { + "version": "5.0.31", + "resolved": "https://registry.npmjs.org/ethers/-/ethers-5.0.31.tgz", + "integrity": "sha512-zpq0YbNFLFn+t+ibS8UkVWFeK5w6rVMSvbSHrHAQslfazovLnQ/mc2gdN5+6P45/k8fPgHrfHrYvJ4XvyK/S1A==", + "requires": { + "@ethersproject/abi": "5.0.12", + "@ethersproject/abstract-provider": "5.0.9", + "@ethersproject/abstract-signer": "5.0.13", + "@ethersproject/address": "5.0.10", + "@ethersproject/base64": "5.0.8", + "@ethersproject/basex": "5.0.8", + "@ethersproject/bignumber": "5.0.14", + "@ethersproject/bytes": "5.0.10", + "@ethersproject/constants": "5.0.9", + "@ethersproject/contracts": "5.0.11", + "@ethersproject/hash": "5.0.11", + "@ethersproject/hdnode": "5.0.9", + "@ethersproject/json-wallets": "5.0.11", + "@ethersproject/keccak256": "5.0.8", + "@ethersproject/logger": "5.0.9", + "@ethersproject/networks": "5.0.8", + "@ethersproject/pbkdf2": "5.0.8", + "@ethersproject/properties": "5.0.8", + "@ethersproject/providers": "5.0.23", + "@ethersproject/random": "5.0.8", + "@ethersproject/rlp": "5.0.8", + "@ethersproject/sha2": "5.0.8", + "@ethersproject/signing-key": "5.0.10", + "@ethersproject/solidity": "5.0.9", + "@ethersproject/strings": "5.0.9", + "@ethersproject/transactions": "5.0.10", + "@ethersproject/units": "5.0.10", + "@ethersproject/wallet": "5.0.11", + "@ethersproject/web": "5.0.13", + "@ethersproject/wordlists": "5.0.9" + }, + "dependencies": { + "@ethersproject/abi": { + "version": "5.0.12", + "resolved": "https://registry.npmjs.org/@ethersproject/abi/-/abi-5.0.12.tgz", + "integrity": "sha512-Ujr/3bwyYYjXLDQfebeiiTuvOw9XtUKM8av6YkoBeMXyGQM9GkjrQlwJMNwGTmqjATH/ZNbRgCh98GjOLiIB1Q==", + "requires": { + "@ethersproject/address": "^5.0.9", + "@ethersproject/bignumber": "^5.0.13", + "@ethersproject/bytes": "^5.0.9", + "@ethersproject/constants": "^5.0.8", + "@ethersproject/hash": "^5.0.10", + "@ethersproject/keccak256": "^5.0.7", + "@ethersproject/logger": "^5.0.8", + "@ethersproject/properties": "^5.0.7", + "@ethersproject/strings": "^5.0.8" + } + } + } + }, "ethjs-unit": { "version": "0.1.6", "resolved": "https://registry.npmjs.org/ethjs-unit/-/ethjs-unit-0.1.6.tgz", @@ -33646,6 +34390,25 @@ "safe-buffer": "^5.0.1" } }, + "sha3": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/sha3/-/sha3-2.1.4.tgz", + "integrity": "sha512-S8cNxbyb0UGUM2VhRD4Poe5N58gJnJsLJ5vC7FYWGUmGhcsj4++WaIOBFVDxlG0W3To6xBuiRh+i0Qp2oNCOtg==", + "requires": { + "buffer": "6.0.3" + }, + "dependencies": { + "buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "requires": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + } + } + }, "shebang-command": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", diff --git a/package.json b/package.json index e17abf2..063650e 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "cic-client-meta": "0.0.7-alpha.3", "datatables.net": "^1.10.22", "datatables.net-dt": "^1.10.22", + "ethers": "^5.0.31", "jquery": "^3.5.1", "mocha": "^8.2.1", "moolb": "^0.1.0", @@ -38,6 +39,7 @@ "openpgp": "^4.10.10", "popper.js": "^1.16.1", "rxjs": "~6.6.0", + "sha3": "^2.1.4", "tslib": "^2.0.0", "vcard-parser": "^1.0.0", "vcards-js": "^2.10.0", @@ -63,6 +65,7 @@ "karma-jasmine-html-reporter": "^1.5.0", "karma-junit-reporter": "^2.0.1", "protractor": "~7.0.0", + "secp256k1": "^4.0.2", "ts-node": "~8.3.0", "tslint": "~6.1.0", "typescript": "~4.0.2" diff --git a/src/app/_services/transaction.service.ts b/src/app/_services/transaction.service.ts index 1b4034a..3bba720 100644 --- a/src/app/_services/transaction.service.ts +++ b/src/app/_services/transaction.service.ts @@ -6,6 +6,14 @@ import {environment} from '@src/environments/environment'; import {User} from 'cic-client-meta'; import {UserService} from '@app/_services/user.service'; import { AccountIndex } from '@app/_helpers'; +import { Keccak } from 'sha3'; +import { utils } from 'ethers'; +import {add0x, fromHex, strip0x, toHex} from '@src/assets/js/ethtx/dist/hex'; +import {Tx} from '@src/assets/js/ethtx/dist'; +import {toValue} from '@src/assets/js/ethtx/dist/tx'; +import * as secp256k1 from 'secp256k1'; +import {AuthService} from '@app/_services/auth.service'; +const Web3 = require('web3'); @Injectable({ providedIn: 'root' @@ -16,9 +24,11 @@ export class TransactionService { transactionsSubject = this.transactionList.asObservable(); userInfo: any; request = new AccountIndex(environment.contractAddress); + web3 = new Web3(environment.web3Provider); constructor( private http: HttpClient, + private authService: AuthService, private userService: UserService ) { } @@ -74,14 +84,36 @@ export class TransactionService { this.userInfo = this.userService.getUser(await User.toKey(address)); } - transferRequest(tokenAddress: string, senderAddress: string, recipientAddress: string, value: number): Observable { - return this.http.post( - `${environment.cicEthUrl}/transfer`, - { - tokenAddress: tokenAddress, - from: senderAddress, - to: recipientAddress, - value: value, - }); + async transferRequest(tokenAddress: string, senderAddress: string, recipientAddress: string, value: number): Promise { + const hashFunction = new Keccak(256); + hashFunction.update('createRequest(address,address,address,uint256)'); + const hash = hashFunction.digest(); + const methodSignature = hash.toString('hex').substring(0, 8); + const abiCoder = new utils.AbiCoder(); + const abi = await abiCoder.encode(['address', 'address', 'address', 'uint256'], [senderAddress, recipientAddress, tokenAddress, value]); + const data = fromHex(methodSignature + strip0x(abi)); + const tx = new Tx(environment.bloxbergChainId); + tx.nonce = await this.web3.eth.getTransactionCount(senderAddress); + tx.gasPrice = await this.web3.eth.getGasPrice(); + tx.gasLimit = 8000000; + tx.to = fromHex(strip0x(recipientAddress)); + tx.value = toValue(value); + tx.data = data; + const txMsg = tx.message(); + const privateKey = this.authService.mutableKeyStore.getPrivateKey(); + if (!privateKey.isDecrypted()) { + const password = window.prompt('password'); + await privateKey.decrypt(password); + } + const signatureObject = secp256k1.ecdsaSign(txMsg, privateKey.keyPacket.privateParams.d); + const r = signatureObject.signature.slice(0, 32); + const s = signatureObject.signature.slice(32); + const v = signatureObject.recid; + tx.setSignature(r, s, v); + const txWire = add0x(toHex(tx.serializeRLP())); + const result = await this.web3.eth.sendSignedTransaction(txWire); + console.log('Result', result); + const transaction = await this.web3.eth.getTransaction(result.transactionHash); + console.log('Transaction', transaction); } } diff --git a/src/app/pages/accounts/disbursement/disbursement.component.ts b/src/app/pages/accounts/disbursement/disbursement.component.ts index 4fb8a28..29969f0 100644 --- a/src/app/pages/accounts/disbursement/disbursement.component.ts +++ b/src/app/pages/accounts/disbursement/disbursement.component.ts @@ -31,18 +31,16 @@ export class DisbursementComponent implements OnInit { get disbursementFormStub(): any { return this.disbursementForm.controls; } - createTransfer(): void { + async createTransfer(): Promise { this.submitted = true; if (this.disbursementForm.invalid) { return; } if (this.disbursementFormStub.transactionType.value === 'transfer') { - this.transactionService.transferRequest( + await this.transactionService.transferRequest( this.account.token, this.account.address, this.disbursementFormStub.recipient.value, this.disbursementFormStub.amount.value - ).pipe(first()).subscribe(res => { - console.log(res); - }); + ); } console.log(this.disbursementFormStub.transactionType.value); this.submitted = false; diff --git a/src/assets/js/ethtx/dist/hex.d.ts b/src/assets/js/ethtx/dist/hex.d.ts new file mode 100644 index 0000000..250b30f --- /dev/null +++ b/src/assets/js/ethtx/dist/hex.d.ts @@ -0,0 +1,5 @@ +declare function strip0x(hexString: string): string; +declare function add0x(hexString: string): string; +declare function fromHex(hexString: string): Uint8Array; +declare function toHex(bytes: Uint8Array): string; +export { fromHex, toHex, strip0x, add0x, }; diff --git a/src/assets/js/ethtx/dist/hex.js b/src/assets/js/ethtx/dist/hex.js new file mode 100644 index 0000000..4df6198 --- /dev/null +++ b/src/assets/js/ethtx/dist/hex.js @@ -0,0 +1,41 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.add0x = exports.strip0x = exports.toHex = exports.fromHex = void 0; +// improve +function validHex(hexString) { + return hexString; +} +function even(hexString) { + if (hexString.length % 2 != 0) { + hexString = '0' + hexString; + } + return hexString; +} +function strip0x(hexString) { + if (hexString.length < 2) { + throw new Error('invalid hex'); + } + else if (hexString.substring(0, 2) == '0x') { + hexString = hexString.substring(2); + } + return validHex(even(hexString)); +} +exports.strip0x = strip0x; +function add0x(hexString) { + if (hexString.length < 2) { + throw new Error('invalid hex'); + } + else if (hexString.substring(0, 2) != '0x') { + hexString = '0x' + hexString; + } + return validHex(even(hexString)); +} +exports.add0x = add0x; +function fromHex(hexString) { + return new Uint8Array(hexString.match(/.{1,2}/g).map(function (byte) { return parseInt(byte, 16); })); +} +exports.fromHex = fromHex; +function toHex(bytes) { + return bytes.reduce(function (str, byte) { return str + byte.toString(16).padStart(2, '0'); }, ''); +} +exports.toHex = toHex; diff --git a/src/assets/js/ethtx/dist/index.d.ts b/src/assets/js/ethtx/dist/index.d.ts new file mode 100644 index 0000000..9bf328c --- /dev/null +++ b/src/assets/js/ethtx/dist/index.d.ts @@ -0,0 +1 @@ +export { Tx } from './tx'; diff --git a/src/assets/js/ethtx/dist/index.js b/src/assets/js/ethtx/dist/index.js new file mode 100644 index 0000000..9c0e6f3 --- /dev/null +++ b/src/assets/js/ethtx/dist/index.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Tx = void 0; +var tx_1 = require("./tx"); +Object.defineProperty(exports, "Tx", { enumerable: true, get: function () { return tx_1.Tx; } }); diff --git a/src/assets/js/ethtx/dist/tx.d.ts b/src/assets/js/ethtx/dist/tx.d.ts new file mode 100644 index 0000000..526882d --- /dev/null +++ b/src/assets/js/ethtx/dist/tx.d.ts @@ -0,0 +1,29 @@ +declare function toValue(n: number): bigint; +declare function stringToValue(s: string): bigint; +declare function hexToValue(hx: string): bigint; +declare class Tx { + nonce: number; + gasPrice: number; + gasLimit: number; + to: Uint8Array; + value: bigint; + data: Uint8Array; + v: number; + r: Uint8Array; + s: Uint8Array; + chainId: number; + _signatureSet: boolean; + _workBuffer: ArrayBuffer; + _outBuffer: DataView; + _outBufferCursor: number; + constructor(chainId: number); + private serializeNumber; + private write; + serializeBytes(): Uint8Array; + canonicalOrder(): Uint8Array[]; + serializeRLP(): Uint8Array; + message(): Uint8Array; + setSignature(r: Uint8Array, s: Uint8Array, v: number): void; + clearSignature(): void; +} +export { Tx, stringToValue, hexToValue, toValue, }; diff --git a/src/assets/js/ethtx/dist/tx.js b/src/assets/js/ethtx/dist/tx.js new file mode 100644 index 0000000..4c294c8 --- /dev/null +++ b/src/assets/js/ethtx/dist/tx.js @@ -0,0 +1,121 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.toValue = exports.hexToValue = exports.stringToValue = exports.Tx = void 0; +var hex_1 = require("./hex"); +var sha3_1 = require("sha3"); +var RLP = require('rlp'); +function isAddress(a) { + return a !== undefined && a.length == 20; +} +function toValue(n) { + return BigInt(n); +} +exports.toValue = toValue; +function stringToValue(s) { + return BigInt(s); +} +exports.stringToValue = stringToValue; +function hexToValue(hx) { + return BigInt(hex_1.add0x(hx)); +} +exports.hexToValue = hexToValue; +var Tx = /** @class */ (function () { + function Tx(chainId) { + this.chainId = chainId; + this.nonce = 0; + this.gasPrice = 0; + this.gasLimit = 0; + this.to = new Uint8Array(32); + this.data = new Uint8Array(0); + this.value = BigInt(0); + this._workBuffer = new ArrayBuffer(32); + this._outBuffer = new DataView(new ArrayBuffer(1024 * 1024)); + this._outBufferCursor = 0; + this.clearSignature(); + } + Tx.prototype.serializeNumber = function (n) { + var view = new DataView(this._workBuffer); + view.setBigUint64(0, BigInt(0)); + view.setBigUint64(0, n); + var zeroOffset = 0; + for (zeroOffset = 0; zeroOffset < 8; zeroOffset++) { + if (view.getInt8(zeroOffset) > 0) { + break; + } + } + return new Uint8Array(this._workBuffer).slice(zeroOffset, 8); + }; + Tx.prototype.write = function (data) { + var _this = this; + data.forEach(function (v) { + _this._outBuffer.setInt8(_this._outBufferCursor, v); + _this._outBufferCursor++; + }); + }; + Tx.prototype.serializeBytes = function () { + if (!isAddress(this.to)) { + throw new Error('invalid address'); + } + var nonce = this.serializeNumber(BigInt(this.nonce)); + this.write(nonce); + var gasPrice = this.serializeNumber(BigInt(this.gasPrice)); + this.write(gasPrice); + var gasLimit = this.serializeNumber(BigInt(this.gasLimit)); + this.write(gasLimit); + this.write(this.to); + var value = this.serializeNumber(this.value); + this.write(value); + this.write(this.data); + var v = this.serializeNumber(BigInt(this.v)); + this.write(v); + this.write(this.r); + this.write(this.s); + return new Uint8Array(this._outBuffer.buffer).slice(0, this._outBufferCursor); + }; + Tx.prototype.canonicalOrder = function () { + return [ + this.serializeNumber(BigInt(this.nonce)), + this.serializeNumber(BigInt(this.gasPrice)), + this.serializeNumber(BigInt(this.gasLimit)), + this.to, + this.serializeNumber(this.value), + this.data, + this.serializeNumber(BigInt(this.v)), + this.r, + this.s, + ]; + }; + Tx.prototype.serializeRLP = function () { + return RLP.encode(this.canonicalOrder()); + }; + Tx.prototype.message = function () { + // TODO: Can we do without Buffer, pleeease? + var h = new sha3_1.Keccak(256); + var b = new Buffer(this.serializeRLP()); + h.update(b); + return h.digest(); + }; + Tx.prototype.setSignature = function (r, s, v) { + if (this._signatureSet) { + throw new Error('Signature already set'); + } + if (r.length != 32 || s.length != 32) { + throw new Error('Invalid signature length'); + } + if (v < 0 || v > 3) { + throw new Error('Invalid recid'); + } + this.r = r; + this.s = s; + this.v = (this.chainId * 2) + 35 + v; + this._signatureSet = true; + }; + Tx.prototype.clearSignature = function () { + this.r = new Uint8Array(0); + this.s = new Uint8Array(0); + this.v = this.chainId; + this._signatureSet = false; + }; + return Tx; +}()); +exports.Tx = Tx; diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index cd57751..0511dda 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,5 +1,6 @@ export const environment = { production: true, + bloxbergChainId: 8996, cicAuthUrl: 'http://localhost:4444', cicMetaUrl: 'http://localhost:63380', publicKeysUrl: 'http://localhost:8000', @@ -10,5 +11,6 @@ export const environment = { cicEthUrl: 'http://localhost:63314', contractAddress: '0xd0097a901AF4ac2E63A5b6E86be8Ad91f10b05d7', registryAddress: '0xf374d7B507767101a4bf3bA2a6B99AC737A44f6d', - trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C' + trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C', + transferAuthorizationAddress: '0xB542fd8bCb777f058997b7D8D06381A0571BF224' }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 310a3c1..69fea52 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -4,6 +4,7 @@ export const environment = { production: false, + bloxbergChainId: 8996, cicAuthUrl: 'http://localhost:4444', cicMetaUrl: 'http://localhost:63380', publicKeysUrl: 'http://localhost:8000', @@ -14,7 +15,8 @@ export const environment = { cicEthUrl: 'http://localhost:63314', contractAddress: '0xd0097a901AF4ac2E63A5b6E86be8Ad91f10b05d7', registryAddress: '0xf374d7B507767101a4bf3bA2a6B99AC737A44f6d', - trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C' + trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C', + transferAuthorizationAddress: '0xB542fd8bCb777f058997b7D8D06381A0571BF224' }; /*