├── .gitignore ├── .travis.yml ├── DEV.md ├── DOCS.md ├── LICENSE ├── README.md ├── dist ├── bundle │ ├── moonlet-core.min.js │ └── moonlet-core.min.js.map ├── lib │ ├── blockchain │ │ ├── ethereum │ │ │ ├── account-utils.js │ │ │ ├── account-utils.js.map │ │ │ ├── account.js │ │ │ ├── account.js.map │ │ │ ├── class.index.js │ │ │ ├── class.index.js.map │ │ │ ├── config.js │ │ │ ├── config.js.map │ │ │ ├── networks.js │ │ │ ├── networks.js.map │ │ │ ├── node.js │ │ │ ├── node.js.map │ │ │ ├── transaction.js │ │ │ └── transaction.js.map │ │ └── zilliqa │ │ │ ├── account-utils.js │ │ │ ├── account-utils.js.map │ │ │ ├── account.js │ │ │ ├── account.js.map │ │ │ ├── class.index.js │ │ │ ├── class.index.js.map │ │ │ ├── config.js │ │ │ ├── config.js.map │ │ │ ├── networks.js │ │ │ ├── networks.js.map │ │ │ ├── node.js │ │ │ ├── node.js.map │ │ │ ├── transaction.js │ │ │ └── transaction.js.map │ ├── class.store.js │ ├── class.store.js.map │ ├── core │ │ ├── account-utils.js │ │ ├── account-utils.js.map │ │ ├── account.js │ │ ├── account.js.map │ │ ├── amount.js │ │ ├── amount.js.map │ │ ├── blockchain-config.js │ │ ├── blockchain-config.js.map │ │ ├── blockchain-implementation.js │ │ ├── blockchain-implementation.js.map │ │ ├── blockchain.js │ │ ├── blockchain.js.map │ │ ├── network.js │ │ ├── network.js.map │ │ ├── node.js │ │ ├── node.js.map │ │ ├── transaction.js │ │ ├── transaction.js.map │ │ ├── utils │ │ │ ├── hdkey.js │ │ │ ├── hdkey.js.map │ │ │ ├── mnemonic.js │ │ │ └── mnemonic.js.map │ │ ├── wallet.js │ │ └── wallet.js.map │ ├── index.js │ └── index.js.map └── types │ ├── blockchain │ ├── ethereum │ │ ├── account-utils.d.ts │ │ ├── account.d.ts │ │ ├── class.index.d.ts │ │ ├── config.d.ts │ │ ├── networks.d.ts │ │ ├── node.d.ts │ │ └── transaction.d.ts │ └── zilliqa │ │ ├── account-utils.d.ts │ │ ├── account.d.ts │ │ ├── class.index.d.ts │ │ ├── config.d.ts │ │ ├── networks.d.ts │ │ ├── node.d.ts │ │ └── transaction.d.ts │ ├── class.store.d.ts │ ├── core │ ├── account-utils.d.ts │ ├── account.d.ts │ ├── amount.d.ts │ ├── blockchain-config.d.ts │ ├── blockchain-implementation.d.ts │ ├── blockchain.d.ts │ ├── network.d.ts │ ├── node.d.ts │ ├── transaction.d.ts │ ├── utils │ │ ├── hdkey.d.ts │ │ └── mnemonic.d.ts │ └── wallet.d.ts │ └── index.d.ts ├── gulpfile.js ├── package-lock.json ├── package.json ├── scripts ├── TestRPCData │ └── .gitkeep ├── declarations.sh ├── rpc.sh ├── rpcs │ ├── _seed_words │ ├── account-fixtures.json │ ├── ethereum │ │ ├── startrpc.sh │ │ └── stoprpc.sh │ ├── start_all.sh │ ├── stop_all.sh │ └── zilliqa │ │ ├── startrpc.sh │ │ └── stoprpc.sh ├── run_coverage.sh ├── run_tests.sh └── testOutputToHtml.sh ├── src ├── blockchain │ ├── ethereum │ │ ├── account-utils.ts │ │ ├── account.ts │ │ ├── class.index.ts │ │ ├── config.ts │ │ ├── networks.ts │ │ ├── node.ts │ │ └── transaction.ts │ └── zilliqa │ │ ├── account-utils.ts │ │ ├── account.ts │ │ ├── class.index.ts │ │ ├── config.ts │ │ ├── networks.ts │ │ ├── node.ts │ │ └── transaction.ts ├── class.store.ts ├── core │ ├── account-utils.ts │ ├── account.ts │ ├── blockchain-config.ts │ ├── blockchain-implementation.ts │ ├── blockchain.ts │ ├── network.ts │ ├── node.ts │ ├── transaction.ts │ ├── transactions-tracker.ts │ ├── utils │ │ ├── hdkey.ts │ │ └── mnemonic.ts │ ├── wallet-event-emitter.ts │ └── wallet.ts ├── globals.d.ts └── index.ts ├── test.ts ├── test ├── 10_multiple_accounts.ts ├── 1_one_account.ts ├── 1_wallet_usage.ts ├── core │ ├── class.store.ts │ ├── hdkey.ts │ ├── mnemonics.ts │ └── wallet.ts ├── ethereum │ ├── account-utils.ts │ ├── account.ts │ ├── infura.ts │ ├── node.ts │ ├── solc │ │ ├── deployer.ts │ │ ├── non_payable_fallback.bin │ │ ├── non_payable_fallback.sol │ │ ├── payable_fallback.bin │ │ ├── payable_fallback.sol │ │ ├── payable_fallback_min.bin │ │ └── payable_fallback_min.sol │ ├── transaction.ts │ └── wallet.ts └── zilliqa │ ├── account-utils.ts │ ├── account.ts │ ├── node.ts │ ├── test.ts.disabled │ ├── transaction.ts │ ├── txn.ts.disabled │ └── wallet.ts ├── tsconfig.json ├── tslint.json └── types ├── blockchain ├── ethereum │ ├── account-utils.d.ts │ ├── account.d.ts │ ├── class.index.d.ts │ ├── networks.d.ts │ ├── node.d.ts │ └── transaction.d.ts └── zilliqa │ ├── account-utils.d.ts │ ├── account.d.ts │ ├── class.index.d.ts │ ├── networks.d.ts │ ├── node.d.ts │ └── transaction.d.ts ├── class.store.d.ts ├── core ├── account-utils.d.ts ├── account.d.ts ├── blockchain.d.ts ├── network.d.ts ├── node.d.ts ├── transaction.d.ts ├── utils │ ├── hdkey.d.ts │ └── mnemonic.d.ts └── wallet.d.ts └── index.d.ts /.gitignore: -------------------------------------------------------------------------------- 1 | \.idea/ 2 | node_modules/ 3 | yarn.lock 4 | coverage/ 5 | mochawesome-report/ 6 | \.DS_Store 7 | \.nyc_output 8 | scripts/TestRPCData/* 9 | !scripts/TestRPCData/.gitkeep 10 | tmp/ 11 | data/ -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "8.7.0" 4 | branches: 5 | only: 6 | - master 7 | install: 8 | - npm install 9 | script: 10 | - ganache-cli -p 8545 -a 10 -d -n -i 15 -m "exchange neither monster ethics bless cancel ghost excite business record warfare invite" > /dev/null & 11 | - kaya --f scripts/rpcs/account-fixtures.json > /dev/null & 12 | - sleep 5 13 | - npm run coveralls 14 | after_success: 15 | 16 | env: 17 | global: 18 | -------------------------------------------------------------------------------- /DEV.md: -------------------------------------------------------------------------------- 1 | 2 | 1. MnemonicUtils.getAvailableWordLists will return all available world lists that can be used to generate mnemonics. 3 | 4 | ``` 5 | wordlists: { 6 | EN: ENGLISH_WORDLIST, 7 | JA: JAPANESE_WORDLIST, 8 | chinese_simplified: CHINESE_SIMPLIFIED_WORDLIST, 9 | chinese_traditional: CHINESE_TRADITIONAL_WORDLIST, 10 | english: ENGLISH_WORDLIST, 11 | french: FRENCH_WORDLIST, 12 | italian: ITALIAN_WORDLIST, 13 | japanese: JAPANESE_WORDLIST, 14 | korean: KOREAN_WORDLIST, 15 | spanish: SPANISH_WORDLIST 16 | } 17 | ``` 18 | Note: using externally provided wordlists is not supported at the moment and should be PR'ed into upstream BIP39 package. 19 | 20 | 21 | ```typescript 22 | try { 23 | const nonce = await TestNode.getNonce( undefined ); 24 | assert.equal( nonce.constructor.name, "Error", "Should have returned an Error object" ); 25 | } catch (e) { 26 | console.log("catch:", e); 27 | } 28 | 29 | // OR 30 | 31 | const test = TestNode.getNonce( undefined ); 32 | test.then( ( res ) => { 33 | console.log("res:", res); 34 | }).catch( err => { 35 | console.log("2catch:", err); 36 | }); 37 | ``` 38 | 39 | ``` 40 | see/test/ 41 | ``` -------------------------------------------------------------------------------- /DOCS.md: -------------------------------------------------------------------------------- 1 | # Moonlet - Core Package 2 | 3 | [![Build Status](https://travis-ci.org/cryptolandtech/moonlet-core.svg?branch=master)](https://travis-ci.org/cryptolandtech/moonlet-core) [![Coverage Status](https://coveralls.io/repos/github/cryptolandtech/moonlet-core/badge.svg)](https://coveralls.io/github/cryptolandtech/moonlet-core) 4 | 5 | ## Repository 6 | 7 | [Code Repository](https://github.com/cryptolandtech/moonlet-core) 8 | 9 | ## Usage 10 | 11 | See [moonlet-core-usage repository](https://github.com/cryptolandtech/moonlet-core-usage) 12 | 13 | ## License 14 | 15 | MIT -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 cryptoland.tech 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Moonlet - Core Package 2 | 3 | [![Build Status](https://travis-ci.org/cryptolandtech/moonlet-core.svg?branch=master)](https://travis-ci.org/cryptolandtech/moonlet-core) [![Coverage Status](https://coveralls.io/repos/github/cryptolandtech/moonlet-core/badge.svg)](https://coveralls.io/github/cryptolandtech/moonlet-core) 4 | 5 | ## Usage 6 | 7 | See [moonlet-core-usage repository](https://github.com/cryptolandtech/moonlet-core-usage) 8 | 9 | ## Setup 10 | 11 | `npm install` 12 | 13 | ## Build lib 14 | 15 | `npm run build` 16 | 17 | ## Testing 18 | 19 | Run the whole testing suite 20 | 21 | ```bash 22 | npm run test 23 | ``` 24 | 25 | Single test run 26 | 27 | ```bash 28 | npm run test-single test/testfile.ts 29 | ``` 30 | 31 | Run tests in specific path 32 | 33 | ```bash 34 | npm run test-single "test/1.core/*.ts" 35 | ``` 36 | 37 | Test Coverage 38 | 39 | ```bash 40 | npm run coverage 41 | ``` 42 | 43 | ***All test commands have a -reuse option available, meant to allow developers to keep TestRPC running between multiple invocations.*** 44 | 45 | Example: 46 | 47 | ```bash 48 | npm run test-reuse 49 | npm run test-single-reuse test/testfile.ts 50 | npm run coverage-reuse 51 | ``` 52 | 53 | ## TestRPC Helpers 54 | 55 | Start All test rpcs 56 | 57 | ```bash 58 | npm run start-all-rpcs 59 | ``` 60 | 61 | Stop all running test rpcs ( that have pids stored ) 62 | 63 | ```bash 64 | npm run stop-all-rpcs 65 | ``` 66 | 67 | ## Adding support for new blockchains 68 | 69 | Fork this repo. 70 | 71 | add your identifier in src/core/blockchain.ts 72 | 73 | copy src/blockchain/ethereum to src/blockchain/yourblockchain and create your types 74 | 75 | add your class indexer into src/class.store.ts 76 | 77 | copy test/ethereum to test/yourblockchain and update the tests 78 | 79 | make sure to add your testrpc setup scripts in the /scripts folder 80 | 81 | Once complete, submit a PR. 82 | 83 | ## License 84 | 85 | MIT -------------------------------------------------------------------------------- /dist/lib/blockchain/ethereum/account-utils.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const account_utils_1 = require("../../core/account-utils"); 4 | const EthereumUtil = require('ethereumjs-util'); 5 | class EthereumAccountUtils extends account_utils_1.GenericAccountUtils { 6 | /** 7 | * Determines whether string is a valid checksummed address 8 | * @param key 9 | * @returns true if valid checksum address, false if not 10 | */ 11 | isValidChecksumAddress(key) { 12 | this.requireType(key, "string", "isValidChecksumAddress"); 13 | return EthereumUtil.isValidChecksumAddress(key); 14 | } 15 | /** 16 | * Converts an address to a checksummed address 17 | * @param key 18 | * @returns checksumed address 19 | */ 20 | toChecksumAddress(key) { 21 | this.requireType(key, "string", "toChecksumAddress"); 22 | return EthereumUtil.toChecksumAddress(key); 23 | } 24 | /** 25 | * Determines whether buffer contains a valid address 26 | * @param key 27 | * @returns true if valid address, false if not 28 | */ 29 | isValidAddress(key) { 30 | this.requireType(key, "Buffer", "isValidAddress"); 31 | return EthereumUtil.isValidAddress(key); 32 | } 33 | /** 34 | * Determines whether buffer contains a valid private key 35 | * @param key 36 | * @returns true if valid private, false if not 37 | */ 38 | isValidPrivate(key) { 39 | this.requireType(key, "Buffer", "isValidPrivate"); 40 | let privateKey = key.toString(); 41 | if (privateKey.length === 66) { 42 | privateKey = privateKey.replace("0x", ""); 43 | } 44 | return !!privateKey.match(/^[0-9a-fA-F]{64}$/); 45 | } 46 | /** 47 | * Determines whether buffer contains a valid public key 48 | * @param key 49 | * @returns true if valid public, false if not 50 | */ 51 | isValidPublic(key) { 52 | this.requireType(key, "Buffer", "isValidPublic"); 53 | return EthereumUtil.isValidPublic(key); 54 | } 55 | /** 56 | * Converts a public key to address 57 | * @param key 58 | * @returns address 59 | */ 60 | publicToAddress(key) { 61 | this.requireType(key, "Buffer", "publicToAddress"); 62 | return EthereumUtil.pubToAddress(key); 63 | } 64 | /** 65 | * Converts a private key to public key 66 | * @param privateKey 67 | * @returns public key 68 | */ 69 | privateToPublic(privateKey) { 70 | this.requireType(privateKey, "Buffer", "privateToPublic"); 71 | return EthereumUtil.privateToPublic(privateKey); 72 | } 73 | /** 74 | * Converts a private key to address 75 | * @param privateKey 76 | * @returns address 77 | */ 78 | privateToAddress(privateKey) { 79 | this.requireType(privateKey, "Buffer", "privateToAddress"); 80 | return EthereumUtil.privateToAddress(privateKey); 81 | } 82 | /** 83 | * Converts an address buffer to a checksummed address string 84 | * @param key 85 | * @returns checksumed address 86 | */ 87 | addressBufferToChecksum(key) { 88 | this.requireType(key, "Buffer", "addressBufferToChecksum"); 89 | if (key.length === 20 || key.length === 22) { 90 | return this.toChecksumAddress(key.toString("hex")); 91 | } 92 | throw new Error("address buffer length is invalid"); 93 | } 94 | /** 95 | * Converts a buffer to a hex string 96 | * @param buf 97 | * @returns string 98 | */ 99 | bufferToHex(buf) { 100 | this.requireType(buf, "Buffer", "bufferToHex"); 101 | return '0x' + buf.toString('hex'); 102 | } 103 | /** 104 | * Converts a balance to it's lowest denominator 105 | * @param input 106 | * @returns string 107 | */ 108 | balanceToStd(input) { 109 | this.requireType(input, "BigNumber", "balanceToStd"); 110 | return input.div(Math.pow(10, 18)).toString(); 111 | } 112 | } 113 | exports.EthereumAccountUtils = EthereumAccountUtils; 114 | //# sourceMappingURL=account-utils.js.map -------------------------------------------------------------------------------- /dist/lib/blockchain/ethereum/account-utils.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"account-utils.js","sourceRoot":"","sources":["../../../../src/blockchain/ethereum/account-utils.ts"],"names":[],"mappings":"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"} -------------------------------------------------------------------------------- /dist/lib/blockchain/ethereum/account.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const account_1 = require("../../core/account"); 7 | const transaction_1 = require("./transaction"); 8 | const account_utils_1 = require("./account-utils"); 9 | const ethereumjs_tx_1 = __importDefault(require("ethereumjs-tx")); 10 | class EthereumAccount extends account_1.GenericAccount { 11 | /** 12 | * Creates an instance of ethereum account. 13 | * @param accountOptions 14 | */ 15 | constructor(accountOptions) { 16 | super(accountOptions); 17 | this.supportsCancel = true; 18 | this.utils = new account_utils_1.EthereumAccountUtils(); 19 | this.tryHdWalletSetup(); 20 | } 21 | /** 22 | * Gets balance 23 | * @returns a promise of a balance 24 | */ 25 | getBalance() { 26 | return this.node.getBalance(this.address); 27 | } 28 | /** 29 | * Gets nonce 30 | * @returns a promise of a nonce 31 | */ 32 | getNonce() { 33 | return this.node.getNonce(this.address); 34 | } 35 | /** 36 | * Builds cancel transaction 37 | * 38 | * @remarks 39 | * Sending a transaction with the same nonce but with higher gas price 40 | * will cancel an existing non mined transaction if included into a block. 41 | * 42 | * @param nonce - account nonce 43 | * @param txGasPrice - gas price in lowest denominator ( wei ) 44 | * @returns a new cancel transaction 45 | */ 46 | buildCancelTransaction(nonce, txGasPrice) { 47 | return this.buildTransferTransaction(this.address, 0, nonce, txGasPrice, 21000); 48 | } 49 | /** 50 | * Builds transfer transaction 51 | * @param to 52 | * @param amount 53 | * @param nonce 54 | * @param txGasPrice 55 | * @param txGasLimit 56 | * @returns transfer transaction 57 | */ 58 | buildTransferTransaction(to, amount, nonce, txGasPrice, txGasLimit) { 59 | return this.buildTransaction(to, amount, nonce, Buffer.from(""), txGasPrice, txGasLimit); 60 | } 61 | /** 62 | * Params ethereum account 63 | * @param to 64 | * @param amount 65 | * @param nonce 66 | * @param txdata 67 | * @param [txGasPrice] 68 | * @param [txGasLimit] 69 | * @returns a cost estimate 70 | */ 71 | estimateTransaction(to, amount, nonce, txdata, txGasPrice = 1, txGasLimit = 6700000) { 72 | return this.node.estimateGas(this.buildTransaction(to, amount, nonce, txdata, txGasPrice, txGasLimit).toParams()); 73 | } 74 | /** 75 | * Builds transaction 76 | * @param to 77 | * @param amount 78 | * @param nonce 79 | * @param txdata 80 | * @param txGasPrice 81 | * @param txGasLimit 82 | * @returns transaction 83 | */ 84 | buildTransaction(to, amount, nonce, txdata, txGasPrice = 1, txGasLimit = 6700000) { 85 | return new transaction_1.EthereumTransaction(this.address, // from me 86 | to, // to actual receiver 87 | amount, // value in wei 88 | nonce, // account nonce 89 | { 90 | gasPrice: txGasPrice, 91 | gasLimit: txGasLimit, 92 | chainId: this.node.network.chainId, 93 | data: txdata, 94 | }); 95 | } 96 | /** 97 | * Signs transaction 98 | * @param transaction 99 | * @returns serialized data 100 | */ 101 | signTransaction(transaction) { 102 | const tx = new ethereumjs_tx_1.default(transaction.toParams()); 103 | tx.sign(Buffer.from(this.privateKey.replace("0x", ""), "hex")); 104 | const serialized = tx.serialize(); 105 | transaction.setSignedResult(serialized); 106 | return serialized; 107 | } 108 | } 109 | exports.EthereumAccount = EthereumAccount; 110 | //# sourceMappingURL=account.js.map -------------------------------------------------------------------------------- /dist/lib/blockchain/ethereum/account.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../src/blockchain/ethereum/account.ts"],"names":[],"mappings":";;;;;AAAA,gDAAqE;AACrE,+CAAiF;AACjF,mDAAuD;AAEvD,kEAAyC;AAEzC,MAAa,eAAgB,SAAQ,wBAAgE;IAGjG;;;OAGG;IACH,YAAY,cAA+B;QACvC,KAAK,CAAC,cAAc,CAAC,CAAC;QAPnB,mBAAc,GAAY,IAAI,CAAC;QAQlC,IAAI,CAAC,KAAK,GAAG,IAAI,oCAAoB,EAAE,CAAC;QACxC,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACI,UAAU;QACb,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAE,IAAI,CAAC,OAAO,CAAE,CAAC;IAChD,CAAC;IAED;;;OAGG;IACI,QAAQ;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;;;;;OAUG;IACI,sBAAsB,CAAC,KAAa,EAAE,UAAkB;QAC3D,OAAO,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;IACpF,CAAC;IAED;;;;;;;;OAQG;IACI,wBAAwB,CAAC,EAAU,EAAE,MAAc,EAAE,KAAa,EAAE,UAAkB,EAAE,UAAkB;QAC7G,OAAO,IAAI,CAAC,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IAC7F,CAAC;IAED;;;;;;;;;OASG;IACI,mBAAmB,CAAC,EAAU,EAAE,MAAc,EAAE,KAAa,EAAE,MAAc,EAAE,aAAqB,CAAC,EAAE,aAAqB,OAAO;QACtI,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CACxB,IAAI,CAAC,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,QAAQ,EAAE,CACtF,CAAC;IACN,CAAC;IAED;;;;;;;;;OASG;IACI,gBAAgB,CAAC,EAAU,EAAE,MAAc,EAAE,KAAa,EAAE,MAAc,EAAE,aAAqB,CAAC,EAAE,aAAqB,OAAO;QACnI,OAAO,IAAI,iCAAmB,CAC1B,IAAI,CAAC,OAAO,EAAgB,UAAU;QACtC,EAAE,EAA0B,qBAAqB;QACjD,MAAM,EAAsB,eAAe;QAC3C,KAAK,EAAuB,gBAAgB;QAC5C;YACI,QAAQ,EAAE,UAAU;YACpB,QAAQ,EAAE,UAAU;YACpB,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO;YAClC,IAAI,EAAE,MAAM;SACf,CACJ,CAAC;IACN,CAAC;IAED;;;;OAIG;IACI,eAAe,CAAC,WAAgC;QACnD,MAAM,EAAE,GAAG,IAAI,uBAAY,CAAE,WAAW,CAAC,QAAQ,EAAE,CAAE,CAAC;QACtD,EAAE,CAAC,IAAI,CAAE,MAAM,CAAC,IAAI,CAAE,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAG,KAAK,CAAE,CAAE,CAAC;QACpE,MAAM,UAAU,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC;QAClC,WAAW,CAAC,eAAe,CAAE,UAAU,CAAE,CAAC;QAC1C,OAAO,UAAU,CAAC;IACtB,CAAC;CAEJ;AA/GD,0CA+GC"} -------------------------------------------------------------------------------- /dist/lib/blockchain/ethereum/class.index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const account_1 = require("./account"); 7 | const node_1 = require("./node"); 8 | const transaction_1 = require("./transaction"); 9 | const config_1 = __importDefault(require("./config")); 10 | const networks_1 = __importDefault(require("./networks")); 11 | const AvailableClasses = { 12 | EthereumAccount: account_1.EthereumAccount, 13 | EthereumNode: node_1.EthereumNode, 14 | EthereumTransaction: transaction_1.EthereumTransaction, 15 | }; 16 | exports.Ethereum = { 17 | AvailableClasses, 18 | config: config_1.default, 19 | networks: networks_1.default, 20 | }; 21 | exports.default = exports.Ethereum; 22 | //# sourceMappingURL=class.index.js.map -------------------------------------------------------------------------------- /dist/lib/blockchain/ethereum/class.index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"class.index.js","sourceRoot":"","sources":["../../../../src/blockchain/ethereum/class.index.ts"],"names":[],"mappings":";;;;;AAEA,uCAA4C;AAC5C,iCAAsC;AACtC,+CAAoD;AAEpD,sDAA8B;AAC9B,0DAAkC;AAElC,MAAM,gBAAgB,GAAG;IACrB,eAAe,EAAf,yBAAe;IACf,YAAY,EAAZ,mBAAY;IACZ,mBAAmB,EAAnB,iCAAmB;CACtB,CAAC;AAEW,QAAA,QAAQ,GAA8B;IAC/C,gBAAgB;IAChB,MAAM,EAAN,gBAAM;IACN,QAAQ,EAAR,kBAAQ;CACX,CAAC;AAEF,kBAAe,gBAAQ,CAAC"} -------------------------------------------------------------------------------- /dist/lib/blockchain/ethereum/config.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const blockchain_1 = require("./../../core/blockchain"); 4 | exports.EthereumConfig = { 5 | blockchain: blockchain_1.Blockchain.ETHEREUM, 6 | mainCoin: "ETH", 7 | units: { 8 | wei: 18, 9 | kwei: 15, 10 | mwei: 12, 11 | gwei: 9, 12 | szabo: 6, 13 | finney: 3, 14 | ether: 0, 15 | kether: -3, 16 | mether: -6, 17 | gether: -9, 18 | tether: -12, 19 | }, 20 | unitsExtra: { 21 | ada: 15, 22 | femtoether: 15, 23 | babbage: 12, 24 | picoether: 12, 25 | nano: 9, 26 | shannon: 9, 27 | nanoether: 9, 28 | microether: 6, 29 | micro: 6, 30 | milliether: 3, 31 | milli: 3, 32 | grand: -3, 33 | einstein: -3, 34 | }, 35 | }; 36 | exports.default = exports.EthereumConfig; 37 | //# sourceMappingURL=config.js.map -------------------------------------------------------------------------------- /dist/lib/blockchain/ethereum/config.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../src/blockchain/ethereum/config.ts"],"names":[],"mappings":";;AAAA,wDAAqD;AAGxC,QAAA,cAAc,GAAsB;IAC7C,UAAU,EAAE,uBAAU,CAAC,QAAQ;IAC/B,QAAQ,EAAE,KAAK;IACf,KAAK,EAAE;QACH,GAAG,EAAE,EAAE;QACP,IAAI,EAAE,EAAE;QACR,IAAI,EAAE,EAAE;QACR,IAAI,EAAE,CAAC;QACP,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,CAAC;QACT,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,CAAC,CAAC;QACV,MAAM,EAAE,CAAC,CAAC;QACV,MAAM,EAAE,CAAC,CAAC;QACV,MAAM,EAAE,CAAC,EAAE;KACd;IACD,UAAU,EAAE;QACR,GAAG,EAAE,EAAE;QACP,UAAU,EAAE,EAAE;QACd,OAAO,EAAE,EAAE;QACX,SAAS,EAAE,EAAE;QACb,IAAI,EAAE,CAAC;QACP,OAAO,EAAE,CAAC;QACV,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,CAAC;QACb,KAAK,EAAE,CAAC;QACR,UAAU,EAAE,CAAC;QACb,KAAK,EAAE,CAAC;QACR,KAAK,EAAE,CAAC,CAAC;QACT,QAAQ,EAAE,CAAC,CAAC;KACf;CACJ,CAAC;AAEF,kBAAe,sBAAc,CAAC"} -------------------------------------------------------------------------------- /dist/lib/blockchain/ethereum/networks.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const blockchain_1 = require("../../core/blockchain"); 4 | const networks = [ 5 | { 6 | network_id: 0, 7 | name: "Main net", 8 | chainId: 1, 9 | blockchain: blockchain_1.Blockchain.ETHEREUM, 10 | mainNet: true, 11 | url: "https://mainnet.infura.io/v3/1fc164b9a9054e4bab0f54e3d8d312b8", 12 | HDCoinValue: 60, 13 | }, 14 | { 15 | network_id: 1, 16 | name: "Ropsten", 17 | chainId: 3, 18 | blockchain: blockchain_1.Blockchain.ETHEREUM, 19 | mainNet: false, 20 | url: "https://ropsten.infura.io/v3/1fc164b9a9054e4bab0f54e3d8d312b8", 21 | HDCoinValue: 1, 22 | }, 23 | { 24 | network_id: 2, 25 | name: "Rinkeby", 26 | chainId: 4, 27 | blockchain: blockchain_1.Blockchain.ETHEREUM, 28 | mainNet: false, 29 | url: "https://rinkeby.infura.io/v3/1fc164b9a9054e4bab0f54e3d8d312b8", 30 | HDCoinValue: 1, 31 | }, 32 | { 33 | network_id: 3, 34 | name: "Kovan", 35 | chainId: 42, 36 | blockchain: blockchain_1.Blockchain.ETHEREUM, 37 | mainNet: false, 38 | url: "https://kovan.infura.io/v3/1fc164b9a9054e4bab0f54e3d8d312b8", 39 | HDCoinValue: 1, 40 | }, 41 | { 42 | network_id: 4, 43 | name: "Ganache - TestRPC", 44 | chainId: 15, 45 | blockchain: blockchain_1.Blockchain.ETHEREUM, 46 | mainNet: false, 47 | url: "http://127.0.0.1:8545/", 48 | HDCoinValue: 60, 49 | }, 50 | ]; 51 | exports.default = networks; 52 | //# sourceMappingURL=networks.js.map -------------------------------------------------------------------------------- /dist/lib/blockchain/ethereum/networks.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"networks.js","sourceRoot":"","sources":["../../../../src/blockchain/ethereum/networks.ts"],"names":[],"mappings":";;AAAA,sDAAmD;AAGnD,MAAM,QAAQ,GAAc;IACxB;QACI,UAAU,EAAE,CAAC;QACb,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,CAAC;QACV,UAAU,EAAE,uBAAU,CAAC,QAAQ;QAC/B,OAAO,EAAE,IAAI;QACb,GAAG,EAAE,+DAA+D;QACpE,WAAW,EAAE,EAAE;KAClB;IACD;QACI,UAAU,EAAE,CAAC;QACb,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,CAAC;QACV,UAAU,EAAE,uBAAU,CAAC,QAAQ;QAC/B,OAAO,EAAE,KAAK;QACd,GAAG,EAAE,+DAA+D;QACpE,WAAW,EAAE,CAAC;KACjB;IACD;QACI,UAAU,EAAE,CAAC;QACb,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,CAAC;QACV,UAAU,EAAE,uBAAU,CAAC,QAAQ;QAC/B,OAAO,EAAE,KAAK;QACd,GAAG,EAAE,+DAA+D;QACpE,WAAW,EAAE,CAAC;KACjB;IACD;QACI,UAAU,EAAE,CAAC;QACb,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,EAAE;QACX,UAAU,EAAE,uBAAU,CAAC,QAAQ;QAC/B,OAAO,EAAE,KAAK;QACd,GAAG,EAAE,6DAA6D;QAClE,WAAW,EAAE,CAAC;KACjB;IACD;QACI,UAAU,EAAE,CAAC;QACb,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE,EAAE;QACX,UAAU,EAAE,uBAAU,CAAC,QAAQ;QAC/B,OAAO,EAAE,KAAK;QACd,GAAG,EAAE,wBAAwB;QAC7B,WAAW,EAAE,EAAE;KAClB;CACJ,CAAC;AAEF,kBAAe,QAAQ,CAAC"} -------------------------------------------------------------------------------- /dist/lib/blockchain/ethereum/node.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const node_1 = require("../../core/node"); 7 | const networks_1 = __importDefault(require("./networks")); 8 | class EthereumNode extends node_1.GenericNode { 9 | /** 10 | * Creates an instance of ethereum node. 11 | * @param [network] 12 | */ 13 | constructor(network) { 14 | super(); 15 | this.NETWORKS = networks_1.default; 16 | this.init(network); 17 | } 18 | /** 19 | * Gets balance 20 | * @param caddress 21 | * @returns balance 22 | */ 23 | getBalance(caddress) { 24 | return this.rpcCall("eth_getBalance", [ 25 | caddress, 26 | 'latest', 27 | ], "BigNumber"); 28 | } 29 | /** 30 | * Gets nonce 31 | * @param caddress 32 | * @returns nonce 33 | */ 34 | getNonce(caddress) { 35 | return this.rpcCall("eth_getTransactionCount", [ 36 | caddress, 37 | 'latest', 38 | ], "number"); 39 | } 40 | /** 41 | * Estimates gas 42 | * @param callArguments 43 | * @returns gas estimate 44 | */ 45 | estimateGas(callArguments) { 46 | return this.rpcCall("eth_estimateGas", [ 47 | callArguments, 48 | ], "number"); 49 | } 50 | /** 51 | * Gets transaction receipt 52 | * @param transaction 53 | * @returns transaction receipt 54 | */ 55 | getTransactionReceipt(transaction) { 56 | if (transaction.receipt !== undefined) { 57 | return Promise.resolve(transaction.receipt); 58 | } 59 | else { 60 | return this.rpcCall("eth_getTransactionReceipt", [transaction.txn], "raw").then(data => { 61 | transaction.setReceiptStatus(data); 62 | return Promise.resolve(data); 63 | }).catch(error => { 64 | return Promise.reject(error); 65 | }); 66 | } 67 | } 68 | /** 69 | * Sends a transaction to the current network 70 | * @param transaction 71 | * @returns result 72 | */ 73 | send(transaction) { 74 | return this.sendRaw("0x" + transaction.raw.toString("hex")); 75 | } 76 | /** 77 | * Sends a raw transaction to the current network 78 | * @param data 79 | * @returns result 80 | */ 81 | sendRaw(data) { 82 | return this.rpcCall("eth_sendRawTransaction", [data], "raw"); 83 | } 84 | } 85 | EthereumNode.NETWORKS = networks_1.default; 86 | exports.EthereumNode = EthereumNode; 87 | //# sourceMappingURL=node.js.map -------------------------------------------------------------------------------- /dist/lib/blockchain/ethereum/node.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"node.js","sourceRoot":"","sources":["../../../../src/blockchain/ethereum/node.ts"],"names":[],"mappings":";;;;;AAAA,0CAA8C;AAE9C,0DAAkC;AAIlC,MAAa,YAAa,SAAQ,kBAAW;IAIzC;;;OAGG;IACH,YAAY,OAAiB;QACzB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,QAAQ,GAAG,kBAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACI,UAAU,CAAC,QAAgB;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE;YAClC,QAAQ;YACR,QAAQ;SACX,EAAE,WAAW,CAAiB,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACI,QAAQ,CAAC,QAAgB;QAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,yBAAyB,EAAE;YAC3C,QAAQ;YACR,QAAQ;SACX,EAAE,QAAQ,CAAiB,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,aAAkB;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE;YACnC,aAAa;SAChB,EAAE,QAAQ,CAAiB,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACI,qBAAqB,CAAC,WAAgC;QACzD,IAAK,WAAW,CAAC,OAAO,KAAK,SAAS,EAAG;YACrC,OAAO,OAAO,CAAC,OAAO,CAAE,WAAW,CAAC,OAAO,CAAE,CAAC;SACjD;aAAM;YACH,OAAO,IAAI,CAAC,OAAO,CAAC,2BAA2B,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBACnF,WAAW,CAAC,gBAAgB,CAAE,IAAI,CAAE,CAAC;gBACrC,OAAO,OAAO,CAAC,OAAO,CAAE,IAAI,CAAE,CAAC;YACnC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;gBACb,OAAO,OAAO,CAAC,MAAM,CAAE,KAAK,CAAE,CAAC;YACnC,CAAC,CAAC,CAAC;SACN;IACL,CAAC;IAED;;;;OAIG;IACI,IAAI,CAAC,WAAgC;QACxC,OAAO,IAAI,CAAC,OAAO,CAAE,IAAI,GAAG,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAE,CAAC;IAClE,CAAC;IAED;;;;OAIG;IACI,OAAO,CAAC,IAAS;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,wBAAwB,EAAE,CAAE,IAAI,CAAE,EAAE,KAAK,CAAiB,CAAC;IACnF,CAAC;;AAjFsB,qBAAQ,GAAc,kBAAQ,CAAC;AAF1D,oCAoFC"} -------------------------------------------------------------------------------- /dist/lib/blockchain/ethereum/transaction.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const transaction_1 = require("../../core/transaction"); 4 | class EthereumTransaction extends transaction_1.GenericTransaction { 5 | /** 6 | * Creates an instance of an ethereum transaction. 7 | * @param from 8 | * @param to 9 | * @param amount 10 | * @param nonce 11 | * @param options 12 | */ 13 | constructor(from, to, amount, nonce, options) { 14 | super(from, to, nonce, options); 15 | this.amount = amount; 16 | this.value = amount; 17 | this.chainId = options.chainId; 18 | this.gasPrice = options.gasPrice; 19 | this.gasLimit = options.gasLimit; 20 | this.data = options.data || Buffer.from(""); 21 | } 22 | /** 23 | * Converts current transaction to a parameters object required for transaction signing 24 | * @returns parameters object 25 | */ 26 | toParams() { 27 | return { 28 | nonce: this.getNumberToHex(this.nonce), 29 | gasPrice: this.getNumberToHex(this.gasPrice), 30 | gasLimit: this.getNumberToHex(this.gasLimit), 31 | to: this.to, 32 | value: this.getNumberToHex(this.value), 33 | data: "0x" + this.data, 34 | chainId: this.getNumberToHex(this.chainId), 35 | }; 36 | } 37 | } 38 | exports.EthereumTransaction = EthereumTransaction; 39 | //# sourceMappingURL=transaction.js.map -------------------------------------------------------------------------------- /dist/lib/blockchain/ethereum/transaction.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../../src/blockchain/ethereum/transaction.ts"],"names":[],"mappings":";;AAAA,wDAAiF;AAUjF,MAAa,mBAAoB,SAAQ,gCAA+C;IAOpF;;;;;;;OAOG;IACH,YAAY,IAAY,EAAE,EAAU,EAAE,MAAc,EAAE,KAAa,EAAE,OAAoC;QACrG,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAEhC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAChD,CAAC;IAED;;;OAGG;IACI,QAAQ;QACX,OAAO;YACH,KAAK,EAAE,IAAI,CAAC,cAAc,CAAE,IAAI,CAAC,KAAK,CAAS;YAC/C,QAAQ,EAAE,IAAI,CAAC,cAAc,CAAE,IAAI,CAAC,QAAQ,CAAE;YAC9C,QAAQ,EAAE,IAAI,CAAC,cAAc,CAAE,IAAI,CAAC,QAAQ,CAAE;YAC9C,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,KAAK,EAAE,IAAI,CAAC,cAAc,CAAE,IAAI,CAAC,KAAK,CAAE;YACxC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC,IAAI;YACtB,OAAO,EAAE,IAAI,CAAC,cAAc,CAAE,IAAI,CAAC,OAAO,CAAE;SAC/C,CAAC;IACN,CAAC;CACJ;AAzCD,kDAyCC"} -------------------------------------------------------------------------------- /dist/lib/blockchain/zilliqa/account-utils.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"account-utils.js","sourceRoot":"","sources":["../../../../src/blockchain/zilliqa/account-utils.ts"],"names":[],"mappings":"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"} -------------------------------------------------------------------------------- /dist/lib/blockchain/zilliqa/account.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importStar = (this && this.__importStar) || function (mod) { 3 | if (mod && mod.__esModule) return mod; 4 | var result = {}; 5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; 6 | result["default"] = mod; 7 | return result; 8 | }; 9 | Object.defineProperty(exports, "__esModule", { value: true }); 10 | const account_1 = require("../../core/account"); 11 | const transaction_1 = require("./transaction"); 12 | const account_utils_1 = require("./account-utils"); 13 | const ZilliqaJsCrypto = __importStar(require("@zilliqa-js/crypto")); 14 | class ZilliqaAccount extends account_1.GenericAccount { 15 | /** 16 | * Creates an instance of zilliqa account. 17 | * @param accountOptions 18 | */ 19 | constructor(accountOptions) { 20 | super(accountOptions); 21 | this.utils = new account_utils_1.ZilliqaAccountUtils(); 22 | this.tryHdWalletSetup(); 23 | } 24 | /** 25 | * Gets balance 26 | * @returns a promise of a balance 27 | */ 28 | getBalance() { 29 | return this.node.getBalance(this.address); 30 | } 31 | /** 32 | * Gets nonce 33 | * @returns a promise of a nonce 34 | */ 35 | getNonce() { 36 | return this.node.getNonce(this.address); 37 | } 38 | /** 39 | * Builds transfer transaction 40 | * @param to 41 | * @param amount 42 | * @param nonce 43 | * @param txGasLimit 44 | * @param txGasPrice 45 | * @returns transfer transaction 46 | */ 47 | buildTransferTransaction(to, amount, nonce, txGasLimit, txGasPrice) { 48 | return this.buildTransaction(to, amount, nonce, Buffer.from(""), txGasPrice, txGasLimit); 49 | } 50 | /** 51 | * Estimates transaction 52 | * @param to 53 | * @param amount 54 | * @param nonce 55 | * @param txdata 56 | * @param [txGasPrice] 57 | * @param [txGasLimit] 58 | * @returns a cost estimate 59 | */ 60 | estimateTransaction(to, amount, nonce, txdata, txGasPrice, txGasLimit) { 61 | throw new Error("Method not implemented."); 62 | /* 63 | can be used once GetGasEstimate is implemented in the LookupNode 64 | // https://github.com/Zilliqa/Zilliqa/blob/db00328e78364c5ae6049f483d8f5bc696027d79/src/libServer/Server.cpp#L580 65 | // not implemented yet.. returns "Hello" 66 | 67 | return this.node.estimateGas( 68 | this.buildTransaction(to, amount, nonce, txdata, txGasPrice, txGasLimit).toParams() 69 | ); 70 | */ 71 | } 72 | /** 73 | * Builds transaction 74 | * @param to 75 | * @param amount 76 | * @param nonce 77 | * @param txdata 78 | * @param txGasPrice 79 | * @param txGasLimit 80 | * @returns transaction 81 | */ 82 | buildTransaction(to, amount, nonce, txdata, txGasPrice = 0, txGasLimit = 8000000) { 83 | return new transaction_1.ZilliqaTransaction(this.address, // from me 84 | to, // to actual receiver 85 | amount, // value in qa 86 | nonce, // account nonce 87 | { 88 | gasPrice: txGasPrice, 89 | gasLimit: txGasLimit, 90 | chainId: this.node.network.chainId, 91 | data: txdata, 92 | }); 93 | } 94 | /** 95 | * Signs transaction 96 | * @param transaction 97 | * @returns serialized data 98 | */ 99 | signTransaction(transaction) { 100 | const TXObject = transaction.toParams(this.publicKey.replace("0x", "")); 101 | // the address should be checksummed and we need to lowercase it for signing 102 | TXObject.toAddr = TXObject.toAddr.toLowerCase(); 103 | const bytes = transaction.getProtoEncodedTx(TXObject); 104 | const signature = ZilliqaJsCrypto.sign(bytes, this.privateKey.replace("0x", ""), this.publicKey.replace("0x", "")); 105 | TXObject.signature = signature; 106 | const serialized = Buffer.from(JSON.stringify(TXObject)); 107 | transaction.TXObject = TXObject; 108 | transaction.setSignedResult(serialized); 109 | return serialized; 110 | } 111 | /** 112 | * not supported 113 | */ 114 | buildCancelTransaction(nonce, txGasPrice) { 115 | return false; 116 | } 117 | } 118 | exports.ZilliqaAccount = ZilliqaAccount; 119 | //# sourceMappingURL=account.js.map -------------------------------------------------------------------------------- /dist/lib/blockchain/zilliqa/account.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../src/blockchain/zilliqa/account.ts"],"names":[],"mappings":";;;;;;;;;AAAA,gDAAqE;AACrE,+CAA+E;AAC/E,mDAAsD;AAGtD,oEAAsD;AAEtD,MAAa,cAAe,SAAQ,wBAA8D;IAE9F;;;OAGG;IACH,YAAY,cAA+B;QACvC,KAAK,CAAC,cAAc,CAAC,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,mCAAmB,EAAE,CAAC;QACvC,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACI,UAAU;QACb,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED;;;OAGG;IACI,QAAQ;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;;;OAQG;IACI,wBAAwB,CAAC,EAAU,EAAE,MAAc,EAAE,KAAa,EAAE,UAAkB,EAAE,UAAkB;QAC7G,OAAO,IAAI,CAAC,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IAC7F,CAAC;IAED;;;;;;;;;OASG;IACI,mBAAmB,CAAC,EAAU,EAAE,MAAc,EAAE,KAAa,EAAE,MAAc,EAAE,UAAmB,EAAE,UAAmB;QAE1H,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC3C;;;;;;;;UAQE;IACN,CAAC;IAED;;;;;;;;;OASG;IACI,gBAAgB,CAAC,EAAU,EAAE,MAAc,EAAE,KAAa,EAAE,MAAc,EAAE,aAAqB,CAAC,EAAE,aAAqB,OAAO;QACnI,OAAO,IAAI,gCAAkB,CACzB,IAAI,CAAC,OAAO,EAAgB,UAAU;QACtC,EAAE,EAA0B,qBAAqB;QACjD,MAAM,EAAsB,cAAc;QAC1C,KAAK,EAAuB,gBAAgB;QAC5C;YACI,QAAQ,EAAE,UAAU;YACpB,QAAQ,EAAE,UAAU;YACpB,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO;YAClC,IAAI,EAAE,MAAM;SACf,CACJ,CAAC;IACN,CAAC;IAED;;;;OAIG;IACI,eAAe,CAAC,WAA+B;QAElD,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAE,CAAC;QAE1E,4EAA4E;QAC5E,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QAEhD,MAAM,KAAK,GAAG,WAAW,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QACtD,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,CAClC,KAAK,EACL,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EACjC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CACnC,CAAC;QAEF,QAAQ,CAAC,SAAS,GAAG,SAAS,CAAC;QAE/B,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;QACzD,WAAW,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAChC,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;QACxC,OAAO,UAAU,CAAC;IACtB,CAAC;IAED;;OAEG;IACI,sBAAsB,CAAC,KAAa,EAAE,UAAkB;QAC3D,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AA3HD,wCA2HC"} -------------------------------------------------------------------------------- /dist/lib/blockchain/zilliqa/class.index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const account_1 = require("./account"); 7 | const node_1 = require("./node"); 8 | const transaction_1 = require("./transaction"); 9 | const config_1 = __importDefault(require("./config")); 10 | const networks_1 = __importDefault(require("./networks")); 11 | const AvailableClasses = { 12 | ZilliqaAccount: account_1.ZilliqaAccount, 13 | ZilliqaNode: node_1.ZilliqaNode, 14 | ZilliqaTransaction: transaction_1.ZilliqaTransaction, 15 | }; 16 | exports.Zilliqa = { 17 | AvailableClasses, 18 | config: config_1.default, 19 | networks: networks_1.default, 20 | }; 21 | exports.default = exports.Zilliqa; 22 | //# sourceMappingURL=class.index.js.map -------------------------------------------------------------------------------- /dist/lib/blockchain/zilliqa/class.index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"class.index.js","sourceRoot":"","sources":["../../../../src/blockchain/zilliqa/class.index.ts"],"names":[],"mappings":";;;;;AAAA,uCAA2C;AAC3C,iCAAqC;AACrC,+CAAmD;AAEnD,sDAA8B;AAC9B,0DAAkC;AAGlC,MAAM,gBAAgB,GAAG;IACrB,cAAc,EAAd,wBAAc;IACd,WAAW,EAAX,kBAAW;IACX,kBAAkB,EAAlB,gCAAkB;CACrB,CAAC;AAEW,QAAA,OAAO,GAA8B;IAC9C,gBAAgB;IAChB,MAAM,EAAN,gBAAM;IACN,QAAQ,EAAR,kBAAQ;CACX,CAAC;AAEF,kBAAe,eAAO,CAAC"} -------------------------------------------------------------------------------- /dist/lib/blockchain/zilliqa/config.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const blockchain_1 = require("./../../core/blockchain"); 4 | exports.ZilliqaConfig = { 5 | blockchain: blockchain_1.Blockchain.ZILLIQA, 6 | mainCoin: "ZIL", 7 | }; 8 | exports.default = exports.ZilliqaConfig; 9 | //# sourceMappingURL=config.js.map -------------------------------------------------------------------------------- /dist/lib/blockchain/zilliqa/config.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../src/blockchain/zilliqa/config.ts"],"names":[],"mappings":";;AAAA,wDAAqD;AAGxC,QAAA,aAAa,GAAsB;IAC5C,UAAU,EAAE,uBAAU,CAAC,OAAO;IAC9B,QAAQ,EAAE,KAAK;CAClB,CAAC;AAEF,kBAAe,qBAAa,CAAC"} -------------------------------------------------------------------------------- /dist/lib/blockchain/zilliqa/networks.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const blockchain_1 = require("../../core/blockchain"); 4 | const networks = [ 5 | { 6 | network_id: 0, 7 | name: "Main net", 8 | chainId: 1, 9 | blockchain: blockchain_1.Blockchain.ZILLIQA, 10 | mainNet: true, 11 | url: "https://api.zilliqa.com/", 12 | HDCoinValue: 10018, 13 | }, 14 | { 15 | network_id: 1, 16 | name: "Test net", 17 | chainId: 2, 18 | blockchain: blockchain_1.Blockchain.ZILLIQA, 19 | mainNet: false, 20 | url: "https://api.testnet.zilliqa.com/", 21 | HDCoinValue: 1, 22 | }, 23 | { 24 | network_id: 2, 25 | name: "Kaya - TestRPC", 26 | chainId: 2, 27 | blockchain: blockchain_1.Blockchain.ZILLIQA, 28 | mainNet: false, 29 | url: "http://127.0.0.1:4200/", 30 | HDCoinValue: 1, 31 | }, 32 | ]; 33 | exports.default = networks; 34 | //# sourceMappingURL=networks.js.map -------------------------------------------------------------------------------- /dist/lib/blockchain/zilliqa/networks.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"networks.js","sourceRoot":"","sources":["../../../../src/blockchain/zilliqa/networks.ts"],"names":[],"mappings":";;AAAA,sDAAmD;AAGnD,MAAM,QAAQ,GAAc;IACxB;QACI,UAAU,EAAE,CAAC;QACb,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,CAAC;QACV,UAAU,EAAE,uBAAU,CAAC,OAAO;QAC9B,OAAO,EAAE,IAAI;QACb,GAAG,EAAE,0BAA0B;QAC/B,WAAW,EAAE,KAAK;KACrB;IACD;QACI,UAAU,EAAE,CAAC;QACb,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,CAAC;QACV,UAAU,EAAE,uBAAU,CAAC,OAAO;QAC9B,OAAO,EAAE,KAAK;QACd,GAAG,EAAE,kCAAkC;QACvC,WAAW,EAAE,CAAC;KACjB;IACD;QACI,UAAU,EAAE,CAAC;QACb,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,CAAC;QACV,UAAU,EAAE,uBAAU,CAAC,OAAO;QAC9B,OAAO,EAAE,KAAK;QACd,GAAG,EAAE,wBAAwB;QAC7B,WAAW,EAAE,CAAC;KACjB;CACJ,CAAC;AAEF,kBAAe,QAAQ,CAAC"} -------------------------------------------------------------------------------- /dist/lib/blockchain/zilliqa/node.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const node_1 = require("../../core/node"); 7 | const networks_1 = __importDefault(require("./networks")); 8 | const bignumber_js_1 = require("bignumber.js"); 9 | class ZilliqaNode extends node_1.GenericNode { 10 | /** 11 | * Creates an instance of zilliqa node. 12 | * @param [network] 13 | */ 14 | constructor(network) { 15 | super(); 16 | this.NETWORKS = networks_1.default; 17 | this.init(network); 18 | } 19 | /** 20 | * Gets balance 21 | * @param caddress 22 | * @returns balance 23 | */ 24 | getBalance(caddress) { 25 | const call = this.rpcCall("GetBalance", [caddress.replace("0x", "").toLowerCase()], ""); 26 | return call.then((data) => { 27 | return new bignumber_js_1.BigNumber(data.balance); 28 | }).catch((error) => { 29 | if (error.message === "Account is not created") { 30 | return Promise.resolve(new bignumber_js_1.BigNumber(0)); 31 | } 32 | return Promise.reject(new Error(error)); 33 | }); 34 | } 35 | /** 36 | * Gets nonce 37 | * @param caddress 38 | * @returns nonce 39 | */ 40 | getNonce(caddress) { 41 | const call = this.rpcCall("GetBalance", [caddress.replace("0x", "").toLowerCase()], ""); 42 | return call.then((data) => { 43 | return data.nonce; 44 | }).catch((error) => { 45 | if (error.message === "Account is not created") { 46 | return Promise.resolve(0); 47 | } 48 | return Promise.reject(new Error(error)); 49 | }); 50 | } 51 | /** 52 | * Estimates gas 53 | * @param callArguments 54 | * @returns gas estimate 55 | */ 56 | estimateGas(callArguments) { 57 | throw new Error("Method not implemented."); 58 | /* 59 | // https://github.com/Zilliqa/Zilliqa/blob/db00328e78364c5ae6049f483d8f5bc696027d79/src/libServer/Server.cpp#L580 60 | // not implemented yet.. returns "Hello" 61 | return this.rpcCall("GetGasEstimate", [ 62 | callArguments, 63 | ], "number") as Promise; 64 | */ 65 | } 66 | /** 67 | * Gets transaction receipt 68 | * @param transaction 69 | * @returns transaction receipt 70 | */ 71 | getTransactionReceipt(transaction) { 72 | if (transaction.receipt !== undefined) { 73 | return Promise.resolve(transaction.receipt); 74 | } 75 | else { 76 | return Promise.resolve(transaction.txn.TranID); 77 | } 78 | } 79 | /** 80 | * Sends a transaction to the current network 81 | * @param transaction 82 | * @returns result 83 | */ 84 | send(transaction) { 85 | // cast properties as expected by Zilliqa Nodes. 86 | const SendObject = transaction.TXObject; 87 | SendObject.amount = SendObject.amount.toString(); 88 | SendObject.gasPrice = SendObject.gasPrice.toString(); 89 | SendObject.gasLimit = SendObject.gasLimit.toString(); 90 | return this.sendRaw(SendObject); 91 | } 92 | /** 93 | * Sends a raw transaction to the current network 94 | * @param data 95 | * @returns result 96 | */ 97 | sendRaw(data) { 98 | return this.rpcCall("CreateTransaction", [data], "raw"); 99 | } 100 | } 101 | ZilliqaNode.NETWORKS = networks_1.default; 102 | exports.ZilliqaNode = ZilliqaNode; 103 | //# sourceMappingURL=node.js.map -------------------------------------------------------------------------------- /dist/lib/blockchain/zilliqa/node.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"node.js","sourceRoot":"","sources":["../../../../src/blockchain/zilliqa/node.ts"],"names":[],"mappings":";;;;;AAAA,0CAA8C;AAE9C,0DAAkC;AAClC,+CAAyC;AAGzC,MAAa,WAAY,SAAQ,kBAAW;IAIxC;;;OAGG;IACH,YAAY,OAAiB;QACzB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,QAAQ,GAAG,kBAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACI,UAAU,CAAC,QAAgB;QAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAE,EAAE,EAAE,CAAiB,CAAC;QAC1G,OAAO,IAAI,CAAC,IAAI,CAAE,CAAC,IAAI,EAAE,EAAE;YACvB,OAAO,IAAI,wBAAS,CAAE,IAAI,CAAC,OAAO,CAAE,CAAC;QACzC,CAAC,CAAC,CAAC,KAAK,CAAE,CAAC,KAAK,EAAE,EAAE;YAChB,IAAI,KAAK,CAAC,OAAO,KAAK,wBAAwB,EAAE;gBAC5C,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,wBAAS,CAAC,CAAC,CAAC,CAAC,CAAC;aAC5C;YACD,OAAO,OAAO,CAAC,MAAM,CAAE,IAAI,KAAK,CAAC,KAAK,CAAC,CAAE,CAAC;QAC9C,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;OAIG;IACI,QAAQ,CAAC,QAAgB;QAC5B,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAE,EAAE,EAAE,CAAiB,CAAC;QAC1G,OAAO,IAAI,CAAC,IAAI,CAAE,CAAC,IAAI,EAAE,EAAE;YACvB,OAAO,IAAI,CAAC,KAAK,CAAC;QACtB,CAAC,CAAC,CAAC,KAAK,CAAE,CAAC,KAAK,EAAE,EAAE;YAChB,IAAI,KAAK,CAAC,OAAO,KAAK,wBAAwB,EAAE;gBAC5C,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;aAC7B;YACD,OAAO,OAAO,CAAC,MAAM,CAAE,IAAI,KAAK,CAAC,KAAK,CAAC,CAAE,CAAC;QAC9C,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,aAAkB;QACjC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC3C;;;;;;UAME;IACN,CAAC;IAED;;;;OAIG;IACI,qBAAqB,CAAC,WAA+B;QACxD,IAAK,WAAW,CAAC,OAAO,KAAK,SAAS,EAAG;YACrC,OAAO,OAAO,CAAC,OAAO,CAAE,WAAW,CAAC,OAAO,CAAE,CAAC;SACjD;aAAM;YACH,OAAO,OAAO,CAAC,OAAO,CAAE,WAAW,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC;SACpD;IACL,CAAC;IAED;;;;OAIG;IACI,IAAI,CAAC,WAA+B;QAEvC,gDAAgD;QAChD,MAAM,UAAU,GAAG,WAAW,CAAC,QAAQ,CAAC;QACxC,UAAU,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACjD,UAAU,CAAC,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACrD,UAAU,CAAC,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAErD,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACI,OAAO,CAAC,IAAS;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,CAAiB,CAAC;IAC5E,CAAC;;AAlGsB,oBAAQ,GAAc,kBAAQ,CAAC;AAF1D,kCAqGC"} -------------------------------------------------------------------------------- /dist/lib/blockchain/zilliqa/transaction.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const transaction_1 = require("../../core/transaction"); 4 | const util_1 = require("@zilliqa-js/util"); 5 | const account_1 = require("@zilliqa-js/account"); 6 | class ZilliqaTransaction extends transaction_1.GenericTransaction { 7 | /** 8 | * Creates an instance of a zilliqa transaction. 9 | * @param from 10 | * @param to 11 | * @param amount 12 | * @param nonce 13 | * @param options 14 | */ 15 | constructor(from, to, amount, nonce, options) { 16 | super(from, to, nonce, options); 17 | this.version = 1; 18 | this.amount = amount; 19 | this.pubKey = options.pubKey || ""; 20 | this.code = options.code || Buffer.from(""); 21 | this.chainId = options.chainId; 22 | this.gasPrice = options.gasPrice; 23 | this.gasLimit = options.gasLimit; 24 | } 25 | /** 26 | * Converts current transaction to a parameters object required for transaction signing 27 | * @returns parameters object 28 | */ 29 | toParams(subPubKey) { 30 | return { 31 | version: (this.chainId << 16) + this.version, 32 | toAddr: this.to.replace("0x", ""), 33 | nonce: this.nonce, 34 | pubKey: subPubKey || "", 35 | amount: new util_1.BN(this.amount), 36 | gasPrice: new util_1.BN(this.gasPrice), 37 | gasLimit: util_1.Long.fromNumber(this.gasLimit), 38 | code: '', 39 | data: '', 40 | signature: "", 41 | }; 42 | } 43 | /** 44 | * Gets proto encoded tx 45 | * @param TXObject 46 | * @returns proto encoded tx 47 | */ 48 | getProtoEncodedTx(TXObject) { 49 | return account_1.util.encodeTransactionProto(TXObject); 50 | } 51 | } 52 | exports.ZilliqaTransaction = ZilliqaTransaction; 53 | //# sourceMappingURL=transaction.js.map -------------------------------------------------------------------------------- /dist/lib/blockchain/zilliqa/transaction.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../../src/blockchain/zilliqa/transaction.ts"],"names":[],"mappings":";;AAAA,wDAAiF;AACjF,2CAA4C;AAC5C,iDAAmE;AAWnE,MAAa,kBAAmB,SAAQ,gCAA8C;IAalF;;;;;;;OAOG;IACH,YAAY,IAAY,EAAE,EAAU,EAAE,MAAc,EAAE,KAAa,EAAE,OAAmC;QACpG,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QArB7B,YAAO,GAAW,CAAC,CAAC;QAuBvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAE5C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IACrC,CAAC;IAED;;;OAGG;IACI,QAAQ,CAAE,SAAkB;QAE/B,OAAO;YACH,OAAO,EAAE,CAAE,IAAI,CAAC,OAAO,IAAI,EAAE,CAAE,GAAG,IAAI,CAAC,OAAO;YAC9C,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;YACjC,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,SAAS,IAAI,EAAE;YACvB,MAAM,EAAE,IAAI,SAAE,CAAE,IAAI,CAAC,MAAM,CAAE;YAC7B,QAAQ,EAAE,IAAI,SAAE,CAAE,IAAI,CAAC,QAAQ,CAAE;YACjC,QAAQ,EAAE,WAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC;YACxC,IAAI,EAAE,EAAE;YACR,IAAI,EAAE,EAAE;YACR,SAAS,EAAE,EAAE;SAChB,CAAC;IACN,CAAC;IAED;;;;OAIG;IACI,iBAAiB,CAAC,QAAQ;QAC7B,OAAO,cAAoB,CAAC,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IACjE,CAAC;CACJ;AA7DD,gDA6DC"} -------------------------------------------------------------------------------- /dist/lib/class.store.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const node_1 = require("./core/node"); 4 | class DynamicClass { 5 | constructor() { 6 | this.classStore = [ 7 | node_1.GenericNode, 8 | ]; 9 | } 10 | /** 11 | * Collects and index classes so we can instantiate them later 12 | * @param object 13 | */ 14 | collectClasses(object) { 15 | for (const name in object) { 16 | if (object[name]) { 17 | this.classStore[name] = object[name]; 18 | } 19 | } 20 | } 21 | /** 22 | * Gets a class instance for supplied name and options 23 | * @param className 24 | * @param [opts] 25 | * @returns supplied class instance 26 | */ 27 | getInstance(className, opts) { 28 | if (this.classStore[className] === undefined || this.classStore[className] === null) { 29 | throw new Error(`Class type of \'${className}\' is not loaded.`); 30 | } 31 | if (opts === undefined) { 32 | return new this.classStore[className](); 33 | } 34 | else if (typeof opts === "object") { 35 | if (opts[0] !== undefined) { 36 | return new this.classStore[className](...opts); 37 | } 38 | else { 39 | return new this.classStore[className](opts); 40 | } 41 | } 42 | else { 43 | throw new Error(`Class type of \'${className}\' is not loaded.`); 44 | } 45 | } 46 | } 47 | exports.default = DynamicClass; 48 | //# sourceMappingURL=class.store.js.map -------------------------------------------------------------------------------- /dist/lib/class.store.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"class.store.js","sourceRoot":"","sources":["../../src/class.store.ts"],"names":[],"mappings":";;AAAA,sCAA0C;AAE1C,MAAqB,YAAY;IAAjC;QACW,eAAU,GAAQ;YACrB,kBAAW;SACd,CAAC;IAqCN,CAAC;IAnCG;;;OAGG;IACI,cAAc,CAAE,MAAW;QAC9B,KAAM,MAAM,IAAI,IAAI,MAAM,EAAG;YACzB,IAAK,MAAM,CAAC,IAAI,CAAC,EAAG;gBAChB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;aACxC;SACJ;IACL,CAAC;IAED;;;;;OAKG;IACI,WAAW,CAAC,SAAiB,EAAE,IAAU;QAC5C,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,SAAS,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE;YACjF,MAAM,IAAI,KAAK,CAAC,mBAAmB,SAAS,mBAAmB,CAAC,CAAC;SACpE;QAED,IAAK,IAAI,KAAK,SAAS,EAAG;YACtB,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;SAC3C;aAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAG;YAClC,IAAK,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,EAAG;gBACzB,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;aAClD;iBAAM;gBACH,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC;aAC/C;SACJ;aAAM;YACH,MAAM,IAAI,KAAK,CAAC,mBAAmB,SAAS,mBAAmB,CAAC,CAAC;SACpE;IACL,CAAC;CACJ;AAxCD,+BAwCC"} -------------------------------------------------------------------------------- /dist/lib/core/account-utils.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const bignumber_js_1 = require("bignumber.js"); 4 | class GenericAccountUtils { 5 | /** 6 | * Parameter type validation 7 | * @param target 8 | * @param expected 9 | * @param method 10 | * @returns true if type matches 11 | */ 12 | requireType(target, expected, method) { 13 | if (expected === "Buffer") { 14 | if (!Buffer.isBuffer(target)) { 15 | throw new Error(method + ": parameter must be a Buffer()."); 16 | } 17 | } 18 | else if (expected === "BigNumber") { 19 | if (!bignumber_js_1.BigNumber.isBigNumber(target)) { 20 | throw new Error(method + ": parameter must be of type BigNumber."); 21 | } 22 | } 23 | else if (typeof target !== expected) { 24 | if (target.constructor.name !== expected) { 25 | throw new Error(method + ": parameter must be of type " + expected + "."); 26 | } 27 | } 28 | return true; 29 | } 30 | } 31 | exports.GenericAccountUtils = GenericAccountUtils; 32 | //# sourceMappingURL=account-utils.js.map -------------------------------------------------------------------------------- /dist/lib/core/account-utils.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"account-utils.js","sourceRoot":"","sources":["../../../src/core/account-utils.ts"],"names":[],"mappings":";;AAAA,+CAAyC;AAEzC,MAAsB,mBAAmB;IAErC;;;;;;OAMG;IACI,WAAW,CAAE,MAAW,EAAE,QAAgB,EAAE,MAAc;QAC7D,IAAK,QAAQ,KAAK,QAAQ,EAAE;YACxB,IAAK,CAAC,MAAM,CAAC,QAAQ,CAAE,MAAM,CAAE,EAAG;gBAC9B,MAAM,IAAI,KAAK,CAAC,MAAM,GAAG,iCAAiC,CAAC,CAAC;aAC/D;SACJ;aAAM,IAAK,QAAQ,KAAK,WAAW,EAAE;YAClC,IAAK,CAAC,wBAAS,CAAC,WAAW,CAAE,MAAM,CAAE,EAAG;gBACpC,MAAM,IAAI,KAAK,CAAC,MAAM,GAAG,wCAAwC,CAAC,CAAC;aACtE;SACJ;aAAM,IAAK,OAAO,MAAM,KAAK,QAAQ,EAAG;YACrC,IAAK,MAAM,CAAC,WAAW,CAAC,IAAI,KAAK,QAAQ,EAAE;gBACvC,MAAM,IAAI,KAAK,CAAC,MAAM,GAAG,8BAA8B,GAAG,QAAQ,GAAG,GAAG,CAAC,CAAC;aAC7E;SACJ;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CA+EJ;AAvGD,kDAuGC"} -------------------------------------------------------------------------------- /dist/lib/core/account.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const transaction_1 = require("./transaction"); 4 | var AccountType; 5 | (function (AccountType) { 6 | AccountType["HD"] = "HD"; 7 | AccountType["LOOSE"] = "LOOSE"; 8 | AccountType["HARDWARE"] = "HARDWARE"; 9 | })(AccountType = exports.AccountType || (exports.AccountType = {})); 10 | class GenericAccount { 11 | /** 12 | * Creates an instance of generic account. 13 | * @param accountOptions 14 | */ 15 | constructor(accountOptions) { 16 | this.address = ""; 17 | this.publicKey = ""; 18 | this.privateKey = ""; 19 | this.supportsCancel = false; 20 | this.transactions = []; 21 | this.node = accountOptions.node; 22 | switch (accountOptions.type) { 23 | case AccountType.HD: 24 | if (!accountOptions.hd) { 25 | throw new Error("accountOptions.hd parameter missing"); 26 | } 27 | this.hd = accountOptions.hd; 28 | break; 29 | case AccountType.LOOSE: 30 | if (!accountOptions.privateKey) { 31 | throw new Error("accountOptions.privateKey parameter missing"); 32 | } 33 | this.privateKey = accountOptions.privateKey; 34 | break; 35 | case AccountType.HARDWARE: 36 | if (!accountOptions.address) { 37 | throw new Error("accountOptions.address parameter missing"); 38 | } 39 | this.address = accountOptions.address; 40 | break; 41 | default: 42 | throw new Error("accountOptions.type '" + accountOptions.type + "' not found"); 43 | } 44 | this.type = accountOptions.type; 45 | } 46 | static getImplementedClassName(name) { 47 | name = name.toLowerCase(); 48 | return name.charAt(0).toUpperCase() + name.slice(1) + "Account"; 49 | } 50 | /** 51 | * Trys hd wallet setup 52 | */ 53 | tryHdWalletSetup() { 54 | if (this.type === AccountType.HD && this.hd !== undefined) { 55 | this.privateKey = this.utils.bufferToHex(this.hd.getPrivateKey()); 56 | this.publicKey = this.utils.bufferToHex(this.utils.privateToPublic(this.hd.getPrivateKey())); 57 | this.address = this.utils.toChecksumAddress(this.utils.privateToAddress(this.hd.getPrivateKey()).toString("hex")); 58 | } 59 | } 60 | /** 61 | * Gets transactions 62 | * @returns transactions 63 | */ 64 | getTransactions() { 65 | return this.transactions; 66 | } 67 | /** 68 | * Sends generic account 69 | * @param transaction 70 | * @param [cb] 71 | * @param [cbtype] 72 | * @returns send 73 | */ 74 | send(transaction, cb, cbtype) { 75 | this.transactions.push(transaction); 76 | if (transaction.status === transaction_1.TransactionStatus.SIGNED) { 77 | transaction.setPending(); 78 | return this.node.send(transaction).then((txndata) => { 79 | transaction.setTxn(txndata); 80 | if (cb !== undefined && cbtype === "txn") { 81 | cb(null, txndata); 82 | } 83 | // kaya does not throw this error properly.. 84 | if (transaction.txn === "Invalid Tx Json") { 85 | throw new Error("Invalid Tx Json"); 86 | } 87 | // load extra transaction details 88 | return this.node.getTransactionReceipt(transaction).then(receiptdata => { 89 | if (cb !== undefined && cbtype === undefined) { 90 | cb(null, receiptdata); 91 | } 92 | return Promise.resolve({ txn: txndata, receipt: receiptdata }); 93 | }); 94 | }).catch((error) => { 95 | if (cb !== undefined) { 96 | cb(error); 97 | } 98 | return Promise.reject(new Error(error)); 99 | }); 100 | } 101 | return Promise.reject(new Error("Transaction status needs to be SIGNED")); 102 | } 103 | } 104 | exports.GenericAccount = GenericAccount; 105 | //# sourceMappingURL=account.js.map -------------------------------------------------------------------------------- /dist/lib/core/account.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../src/core/account.ts"],"names":[],"mappings":";;AAAA,+CAA2F;AAM3F,IAAY,WAIX;AAJD,WAAY,WAAW;IACnB,wBAAS,CAAA;IACT,8BAAe,CAAA;IACf,oCAAqB,CAAA;AACzB,CAAC,EAJW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAItB;AAYD,MAAsB,cAAc;IAoBhC;;;OAGG;IACH,YAAY,cAA+B;QAbpC,YAAO,GAAW,EAAE,CAAC;QACrB,cAAS,GAAW,EAAE,CAAC;QACvB,eAAU,GAAW,EAAE,CAAC;QAIxB,mBAAc,GAAY,KAAK,CAAC;QAC/B,iBAAY,GAAQ,EAAE,CAAC;QAO3B,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC;QAEhC,QAAQ,cAAc,CAAC,IAAI,EAAE;YACzB,KAAK,WAAW,CAAC,EAAE;gBACf,IAAI,CAAC,cAAc,CAAC,EAAE,EAAE;oBACpB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;iBAC1D;gBACD,IAAI,CAAC,EAAE,GAAG,cAAc,CAAC,EAAE,CAAC;gBAC5B,MAAM;YACV,KAAK,WAAW,CAAC,KAAK;gBAClB,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE;oBAC5B,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;iBAClE;gBACD,IAAI,CAAC,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC;gBAC5C,MAAM;YACV,KAAK,WAAW,CAAC,QAAQ;gBACrB,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;oBACzB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;iBAC/D;gBACD,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC;gBACtC,MAAM;YAEV;gBACI,MAAM,IAAI,KAAK,CAAC,uBAAuB,GAAG,cAAc,CAAC,IAAI,GAAG,aAAa,CAAC,CAAC;SACtF;QAED,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC;IACpC,CAAC;IA/CM,MAAM,CAAC,uBAAuB,CAAC,IAAY;QAC9C,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IACpE,CAAC;IA8CD;;OAEG;IACI,gBAAgB;QACnB,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE,KAAK,SAAS,EAAG;YACxD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAE,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAE,CAAC;YACpE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAE,IAAI,CAAC,KAAK,CAAC,eAAe,CAAE,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAE,CAAE,CAAC;YACjG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAE,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAE,CAAC;SACzH;IACL,CAAC;IAED;;;OAGG;IACI,eAAe;QAClB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACI,IAAI,CAAC,WAAc,EAAE,EAAQ,EAAE,MAAe;QACjD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAE,WAAW,CAAE,CAAC;QAEtC,IAAI,WAAW,CAAC,MAAM,KAAK,+BAAiB,CAAC,MAAM,EAAE;YACjD,WAAW,CAAC,UAAU,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAE,WAAW,CAAE,CAAC,IAAI,CAAE,CAAC,OAAO,EAAE,EAAE;gBACnD,WAAW,CAAC,MAAM,CAAE,OAAO,CAAE,CAAC;gBAC9B,IAAI,EAAE,KAAK,SAAS,IAAI,MAAM,KAAK,KAAK,EAAE;oBACtC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;iBACrB;gBAED,4CAA4C;gBAC5C,IAAI,WAAW,CAAC,GAAG,KAAK,iBAAiB,EAAE;oBACvC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;iBACtC;gBAED,iCAAiC;gBACjC,OAAO,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAE,WAAW,CAAE,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE;oBACrE,IAAI,EAAE,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS,EAAE;wBAC1C,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;qBACzB;oBACD,OAAO,OAAO,CAAC,OAAO,CAAE,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAC,CAAE,CAAC;gBACpE,CAAC,CAAC,CAAC;YAEP,CAAC,CAAC,CAAC,KAAK,CAAE,CAAC,KAAK,EAAE,EAAE;gBAChB,IAAI,EAAE,KAAK,SAAS,EAAE;oBAClB,EAAE,CAAC,KAAK,CAAC,CAAC;iBACb;gBACD,OAAO,OAAO,CAAC,MAAM,CAAE,IAAI,KAAK,CAAC,KAAK,CAAC,CAAE,CAAC;YAC9C,CAAC,CAAC,CAAC;SAEN;QACD,OAAO,OAAO,CAAC,MAAM,CAAE,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAE,CAAC;IAChF,CAAC;CAqEJ;AAtLD,wCAsLC"} -------------------------------------------------------------------------------- /dist/lib/core/amount.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const bignumber_js_1 = __importDefault(require("bignumber.js")); 7 | class Amount { 8 | /** 9 | * Creates an instance of amount. 10 | * @param value 11 | * @param coin 12 | * @param [unit] 13 | */ 14 | constructor(value, coin, unit) { 15 | if (typeof value === 'number') { 16 | value = new bignumber_js_1.default(value); 17 | } 18 | this.value = value; 19 | this.coin = coin; 20 | this.withUnit(unit, () => { 21 | this.value.multipliedBy(Math.pow(10, -Amount.config.get(coin)[unit])); 22 | }); 23 | } 24 | /** 25 | * Add configuration 26 | * @param config 27 | */ 28 | static addConfig(config) { 29 | if (config && config.blockchain && config.units) { 30 | Amount.config.set(config.blockchain, config.units || {}); 31 | } 32 | } 33 | plus(amount) { 34 | this.assertSameCoins(this.coin, amount.coin); 35 | return new Amount(this.value.plus(amount.toBigNumber()), this.coin); 36 | } 37 | minus(amount) { 38 | this.assertSameCoins(this.coin, amount.coin); 39 | return new Amount(this.value.minus(amount.toBigNumber()), this.coin); 40 | } 41 | dividedBy(amount) { 42 | this.assertSameCoins(this.coin, amount.coin); 43 | return new Amount(this.value.dividedBy(amount.toBigNumber()), this.coin); 44 | } 45 | multipliedBy(amount) { 46 | this.assertSameCoins(this.coin, amount.coin); 47 | return new Amount(this.value.multipliedBy(amount.toBigNumber()), this.coin); 48 | } 49 | toBigNumber(unit) { 50 | let value; 51 | this.withUnit(unit, () => { 52 | value = this.value.multipliedBy(Math.pow(10, Amount.config.get(this.coin)[unit])); 53 | }); 54 | return value || this.value; 55 | } 56 | toNumber(unit) { 57 | return this.toBigNumber(unit).toNumber(); 58 | } 59 | toString(unit) { 60 | return this.toBigNumber(unit).toString(); 61 | } 62 | withUnit(unit, cb) { 63 | if (unit) { 64 | if (Amount.config.get(this.coin)[unit]) { 65 | return cb(); 66 | } 67 | else { 68 | throw new Error(`${unit} is not a unit of ${this.coin}`); 69 | } 70 | } 71 | } 72 | assertSameCoins(coin1, coin2) { 73 | if (coin1 !== coin2) { 74 | throw new Error('Cannot add two amounts with different coins'); 75 | } 76 | } 77 | } 78 | Amount.config = new Map(); 79 | exports.Amount = Amount; 80 | //# sourceMappingURL=amount.js.map -------------------------------------------------------------------------------- /dist/lib/core/amount.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"amount.js","sourceRoot":"","sources":["../../../src/core/amount.ts"],"names":[],"mappings":"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"} -------------------------------------------------------------------------------- /dist/lib/core/blockchain-config.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=blockchain-config.js.map -------------------------------------------------------------------------------- /dist/lib/core/blockchain-config.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"blockchain-config.js","sourceRoot":"","sources":["../../../src/core/blockchain-config.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/lib/core/blockchain-implementation.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=blockchain-implementation.js.map -------------------------------------------------------------------------------- /dist/lib/core/blockchain-implementation.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"blockchain-implementation.js","sourceRoot":"","sources":["../../../src/core/blockchain-implementation.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/lib/core/blockchain.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var Blockchain; 4 | (function (Blockchain) { 5 | Blockchain["ETHEREUM"] = "ETHEREUM"; 6 | Blockchain["ZILLIQA"] = "ZILLIQA"; 7 | })(Blockchain = exports.Blockchain || (exports.Blockchain = {})); 8 | //# sourceMappingURL=blockchain.js.map -------------------------------------------------------------------------------- /dist/lib/core/blockchain.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"blockchain.js","sourceRoot":"","sources":["../../../src/core/blockchain.ts"],"names":[],"mappings":";;AAAA,IAAY,UAGX;AAHD,WAAY,UAAU;IAClB,mCAAqB,CAAA;IACrB,iCAAmB,CAAA;AACvB,CAAC,EAHW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAGrB"} -------------------------------------------------------------------------------- /dist/lib/core/network.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=network.js.map -------------------------------------------------------------------------------- /dist/lib/core/network.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"network.js","sourceRoot":"","sources":["../../../src/core/network.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/lib/core/node.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const bignumber_js_1 = require("bignumber.js"); 7 | const axios_1 = __importDefault(require("axios")); 8 | class GenericNode { 9 | constructor() { 10 | this.customNetworkUrl = false; 11 | this.connected = false; 12 | this.NETWORKS = []; 13 | this.network = this.NETWORKS[0]; 14 | this.HDRootKey = null; 15 | this.callId = 0; 16 | } 17 | /** 18 | * Gets implemented class name 19 | * @param name 20 | * @returns class name string 21 | */ 22 | static getImplementedClassName(name) { 23 | name = name.toLowerCase(); 24 | return name.charAt(0).toUpperCase() + name.slice(1) + "Node"; 25 | } 26 | /** 27 | * Initialises node on specified network or default if network param is not supplied 28 | * @param [network] 29 | */ 30 | init(network) { 31 | network = network || this.NETWORKS[0]; 32 | this.customNetworkUrl = false; 33 | this.blockchain = network.blockchain; 34 | this.network = Object.assign({}, network); 35 | } 36 | /** 37 | * Gets current network path string 38 | * @returns current network path string 39 | */ 40 | getCurrentNetworkPathString() { 41 | return `m/44'/` + this.network.HDCoinValue + `'/0'/0`; 42 | } 43 | /** 44 | * Gets current network 45 | * @returns network 46 | */ 47 | getNetwork() { 48 | return this.network; 49 | } 50 | /** 51 | * Sets custom network url 52 | * @param url 53 | */ 54 | setCustomNetworkUrl(url) { 55 | this.network.url = url; 56 | this.customNetworkUrl = true; 57 | } 58 | /** 59 | * Resets custom network url 60 | */ 61 | resetCustomNetworkUrl() { 62 | for (const net in this.NETWORKS) { 63 | if (this.network.chainId === this.NETWORKS[net].chainId) { 64 | this.network.url = this.NETWORKS[net].url; 65 | this.customNetworkUrl = false; 66 | } 67 | } 68 | } 69 | /** 70 | * Posts an RPC call to the current network 71 | * @param method - RPC Method name 72 | * @param params - RPC Method parameters 73 | * @param [dec] - Result decoder type 74 | * @returns raw or decoded result 75 | */ 76 | rpcCall(method, params, dec) { 77 | const callData = this.buildCall(method, params); 78 | const callOptions = {}; 79 | const action = axios_1.default.post(this.network.url, callData, callOptions); 80 | // console.log( "CallData: ", callData ); 81 | return action.then((data) => { 82 | // console.log( "return result:", data ); 83 | if (data.data.result !== undefined) { 84 | return this.resultDecoder(data.data.result, dec); 85 | } 86 | else { 87 | return Promise.reject(data.data.error.message); 88 | } 89 | }).catch((error) => { 90 | return Promise.reject(new Error(error)); 91 | }); 92 | } 93 | /** 94 | * Build an RPC call 95 | * @param cmethod 96 | * @param cparams 97 | * @returns call 98 | */ 99 | buildCall(cmethod, cparams) { 100 | return { 101 | jsonrpc: '2.0', 102 | method: cmethod, 103 | params: cparams, 104 | id: ++this.callId, 105 | }; 106 | } 107 | /** 108 | * Converts the received data into the requested type 109 | * @param data 110 | * @param [type] 111 | * @returns decoded result 112 | */ 113 | resultDecoder(data, type) { 114 | if (type === "raw" || type === undefined || type === "" || type === null) { 115 | return data; 116 | } 117 | else if (type === "BigNumber") { 118 | return new bignumber_js_1.BigNumber(data); 119 | } 120 | else if (type === "number") { 121 | return parseInt(data, 16); // radix js default = 16 122 | } 123 | else if (type === "Buffer") { 124 | return Buffer.from(data); 125 | } 126 | throw new Error("type: [" + type + "] not implemented"); 127 | } 128 | } 129 | GenericNode.NETWORKS = []; 130 | exports.GenericNode = GenericNode; 131 | //# sourceMappingURL=node.js.map -------------------------------------------------------------------------------- /dist/lib/core/node.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"node.js","sourceRoot":"","sources":["../../../src/core/node.ts"],"names":[],"mappings":"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"} -------------------------------------------------------------------------------- /dist/lib/core/transaction.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var TransactionStatus; 4 | (function (TransactionStatus) { 5 | TransactionStatus["NEW"] = "NEW"; 6 | TransactionStatus["SIGNED"] = "SIGNED"; 7 | TransactionStatus["PENDING"] = "PENDING"; 8 | TransactionStatus["FINAL"] = "FINAL"; 9 | })(TransactionStatus = exports.TransactionStatus || (exports.TransactionStatus = {})); 10 | class GenericTransaction { 11 | constructor(from, to, nonce, options) { 12 | this.txn = ""; 13 | this.raw = Buffer.from(""); 14 | this.status = TransactionStatus.NEW; 15 | this.times = []; 16 | this.from = from; 17 | this.to = to; 18 | this.nonce = nonce; 19 | this.options = options; 20 | this.addTime("creation"); 21 | } 22 | static getImplementedClassName(name) { 23 | name = name.toLowerCase(); 24 | return name.charAt(0).toUpperCase() + name.slice(1) + "Transaction"; 25 | } 26 | /** 27 | * Sets transaction status to signed, adds raw data and indexes event 28 | * @param data 29 | */ 30 | setSignedResult(data) { 31 | this.addTime("signed"); 32 | this.status = TransactionStatus.SIGNED; 33 | this.raw = data; 34 | } 35 | /** 36 | * Sets transaction status to pending and indexes event 37 | * @param data 38 | */ 39 | setPending() { 40 | this.addTime("pending"); 41 | this.status = TransactionStatus.PENDING; 42 | } 43 | /** 44 | * Sets transaction status to final, adds txn and indexes event 45 | * @param data 46 | */ 47 | setTxn(txn) { 48 | this.addTime("final"); 49 | this.status = TransactionStatus.FINAL; 50 | this.txn = txn; 51 | } 52 | /** 53 | * Sets transaction receipt and indexes event 54 | * @param data 55 | */ 56 | setReceiptStatus(receipt) { 57 | this.addTime("receipt"); 58 | this.receipt = receipt; 59 | } 60 | /** 61 | * Converts number to hex string 62 | * @param num 63 | * @returns hex representation 64 | */ 65 | getNumberToHex(num) { 66 | return "0x" + num.toString(16); 67 | } 68 | /** 69 | * Adds time to current event 70 | * @param eventName 71 | */ 72 | addTime(eventName) { 73 | this.times.push({ 74 | name: eventName, 75 | unixtime: Math.round((new Date()).getTime() / 1000), 76 | }); 77 | } 78 | } 79 | exports.GenericTransaction = GenericTransaction; 80 | //# sourceMappingURL=transaction.js.map -------------------------------------------------------------------------------- /dist/lib/core/transaction.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../src/core/transaction.ts"],"names":[],"mappings":";;AAOA,IAAY,iBAKX;AALD,WAAY,iBAAiB;IACzB,gCAAW,CAAA;IACX,sCAAiB,CAAA;IACjB,wCAAmB,CAAA;IACnB,oCAAe,CAAA;AACnB,CAAC,EALW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAK5B;AAED,MAAsB,kBAAkB;IAmBpC,YAAY,IAAY,EAAE,EAAU,EAAE,KAAa,EAAE,OAAW;QALzD,QAAG,GAAW,EAAE,CAAC;QACjB,QAAG,GAAW,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9B,WAAM,GAAsB,iBAAiB,CAAC,GAAG,CAAC;QAClD,UAAK,GAAQ,EAAE,CAAC;QAGnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC7B,CAAC;IAxBM,MAAM,CAAC,uBAAuB,CAAC,IAAY;QAC9C,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC;IACxE,CAAC;IAuBD;;;OAGG;IACI,eAAe,CAAE,IAAY;QAChC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC;QACvC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;IACpB,CAAC;IAED;;;OAGG;IACI,UAAU;QACb,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC;IAC5C,CAAC;IAED;;;OAGG;IACI,MAAM,CAAE,GAAW;QACtB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,iBAAiB,CAAC,KAAK,CAAC;QACtC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;IAED;;;OAGG;IACI,gBAAgB,CAAE,OAAY;QACjC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACI,cAAc,CAAE,GAAW;QAC9B,OAAO,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,OAAO,CAAC,SAAiB;QAC5B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;SACtD,CAAC,CAAC;IACP,CAAC;CAOJ;AA3FD,gDA2FC"} -------------------------------------------------------------------------------- /dist/lib/core/utils/hdkey.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const npmhdkeyobject = require("hdkey"); 4 | class HDKey { 5 | static fromHDKey(npmhdkey) { 6 | const ret = new HDKey(); 7 | ret.npmhdkey = npmhdkey; 8 | return ret; 9 | } 10 | static fromMasterSeed(seedBuffer) { 11 | return HDKey.fromHDKey(npmhdkeyobject.fromMasterSeed(seedBuffer)); 12 | } 13 | derivePath(path) { 14 | return HDKey.fromHDKey(this.npmhdkey.derive(path)); 15 | } 16 | deriveChild(index) { 17 | return HDKey.fromHDKey(this.npmhdkey.deriveChild(index)); 18 | } 19 | getPrivateKey() { 20 | return this.npmhdkey._privateKey; 21 | } 22 | getPrivateKeyString() { 23 | return this.npmhdkey._privateKey.toString("hex"); 24 | } 25 | } 26 | exports.default = HDKey; 27 | //# sourceMappingURL=hdkey.js.map -------------------------------------------------------------------------------- /dist/lib/core/utils/hdkey.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"hdkey.js","sourceRoot":"","sources":["../../../../src/core/utils/hdkey.ts"],"names":[],"mappings":";;AAAA,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAExC,MAAqB,KAAK;IAEf,MAAM,CAAC,SAAS,CAAE,QAAe;QACpC,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACxB,OAAO,GAAG,CAAC;IACf,CAAC;IAEM,MAAM,CAAC,cAAc,CAAE,UAAkB;QAC5C,OAAO,KAAK,CAAC,SAAS,CAAE,cAAc,CAAC,cAAc,CAAE,UAAU,CAAE,CAAE,CAAC;IAC1E,CAAC;IAIM,UAAU,CAAE,IAAS;QACxB,OAAO,KAAK,CAAC,SAAS,CAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAE,CAAC;IACzD,CAAC;IAEM,WAAW,CAAE,KAAU;QAC1B,OAAO,KAAK,CAAC,SAAS,CAAE,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAE,CAAC;IAC/D,CAAC;IAEM,aAAa;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;IACrC,CAAC;IAEM,mBAAmB;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC;CACJ;AA7BD,wBA6BC"} -------------------------------------------------------------------------------- /dist/lib/core/utils/mnemonic.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importStar = (this && this.__importStar) || function (mod) { 3 | if (mod && mod.__esModule) return mod; 4 | var result = {}; 5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; 6 | result["default"] = mod; 7 | return result; 8 | }; 9 | Object.defineProperty(exports, "__esModule", { value: true }); 10 | const bip = __importStar(require("bip39")); 11 | class Mnemonic { 12 | static getAvailableWordLists() { 13 | return bip.wordlists; 14 | } 15 | static generateMnemonic(language) { 16 | language = language || "EN"; 17 | const wordlists = Mnemonic.getAvailableWordLists(); 18 | if (Object.keys(wordlists).find(k => k === language)) { 19 | return bip.generateMnemonic(undefined, undefined, wordlists[language]); 20 | } 21 | throw new Error("Mnemonics language '" + language + "' is not supported."); 22 | } 23 | static mnemonicToSeed(mnemonic, language, password) { 24 | language = language || "EN"; 25 | const wordlists = Mnemonic.getAvailableWordLists(); 26 | if (bip.validateMnemonic(mnemonic, wordlists[language])) { 27 | return bip.mnemonicToSeed(mnemonic, password); 28 | } 29 | throw new Error("Invalid Mnemonic."); 30 | } 31 | static getWordsFromMnemonic(mnemonic, language) { 32 | const JPSeparator = '\u3000'; 33 | language = language || "EN"; 34 | if (language === "JP" || language === "JA") { 35 | return mnemonic.split(JPSeparator); 36 | } 37 | else { 38 | return mnemonic.split(" "); 39 | } 40 | } 41 | } 42 | exports.default = Mnemonic; 43 | //# sourceMappingURL=mnemonic.js.map -------------------------------------------------------------------------------- /dist/lib/core/utils/mnemonic.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"mnemonic.js","sourceRoot":"","sources":["../../../../src/core/utils/mnemonic.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA6B;AAM7B,MAAqB,QAAQ;IAElB,MAAM,CAAC,qBAAqB;QAC/B,OAAO,GAAG,CAAC,SAAS,CAAC;IACzB,CAAC;IAEM,MAAM,CAAC,gBAAgB,CAAC,QAAiB;QAC5C,QAAQ,GAAG,QAAQ,IAAI,IAAI,CAAC;QAC5B,MAAM,SAAS,GAAG,QAAQ,CAAC,qBAAqB,EAAE,CAAC;QAEnD,IAAK,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC,EAAG;YACpD,OAAO,GAAG,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,QAAe,CAAC,CAAC,CAAC;SACjF;QAED,MAAM,IAAI,KAAK,CAAC,sBAAsB,GAAG,QAAQ,GAAG,qBAAqB,CAAC,CAAC;IAC/E,CAAC;IAEM,MAAM,CAAC,cAAc,CAAC,QAAgB,EAAE,QAAiB,EAAE,QAAiB;QAC/E,QAAQ,GAAG,QAAQ,IAAI,IAAI,CAAC;QAC5B,MAAM,SAAS,GAAG,QAAQ,CAAC,qBAAqB,EAAE,CAAC;QAEnD,IAAK,GAAG,CAAC,gBAAgB,CAAC,QAAQ,EAAE,SAAS,CAAC,QAAe,CAAC,CAAC,EAAG;YAC9D,OAAO,GAAG,CAAC,cAAc,CAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;SAClD;QACD,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACzC,CAAC;IAEM,MAAM,CAAC,oBAAoB,CAAC,QAAgB,EAAE,QAAiB;QAClE,MAAM,WAAW,GAAG,QAAQ,CAAC;QAC7B,QAAQ,GAAG,QAAQ,IAAI,IAAI,CAAC;QAC5B,IAAK,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,IAAI,EAAE;YACzC,OAAO,QAAQ,CAAC,KAAK,CAAE,WAAW,CAAE,CAAC;SACxC;aAAM;YACH,OAAO,QAAQ,CAAC,KAAK,CAAE,GAAG,CAAE,CAAC;SAChC;IACL,CAAC;CACJ;AApCD,2BAoCC"} -------------------------------------------------------------------------------- /dist/lib/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const wallet_1 = __importDefault(require("./core/wallet")); 7 | exports.Wallet = wallet_1.default; 8 | const blockchain_1 = require("./core/blockchain"); 9 | exports.Blockchains = blockchain_1.Blockchain; 10 | const account_1 = require("./core/account"); 11 | exports.AccountType = account_1.AccountType; 12 | const mnemonic_1 = __importDefault(require("./core/utils/mnemonic")); 13 | exports.MnemonicUtils = mnemonic_1.default; 14 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/lib/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;AAAA,2DAAmC;AAM/B,iBANG,gBAAM,CAMH;AALV,kDAA8D;AAM1D,sBANmB,uBAAW,CAMnB;AALf,4CAA6C;AAMzC,sBANK,qBAAW,CAML;AALf,qEAAkD;AAM9C,wBANG,kBAAa,CAMH"} -------------------------------------------------------------------------------- /dist/types/blockchain/ethereum/account-utils.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { GenericAccountUtils } from "../../core/account-utils"; 3 | import { BigNumber } from "bignumber.js"; 4 | export declare class EthereumAccountUtils extends GenericAccountUtils { 5 | /** 6 | * Determines whether string is a valid checksummed address 7 | * @param key 8 | * @returns true if valid checksum address, false if not 9 | */ 10 | isValidChecksumAddress(key: string): boolean; 11 | /** 12 | * Converts an address to a checksummed address 13 | * @param key 14 | * @returns checksumed address 15 | */ 16 | toChecksumAddress(key: string): string; 17 | /** 18 | * Determines whether buffer contains a valid address 19 | * @param key 20 | * @returns true if valid address, false if not 21 | */ 22 | isValidAddress(key: Buffer): boolean; 23 | /** 24 | * Determines whether buffer contains a valid private key 25 | * @param key 26 | * @returns true if valid private, false if not 27 | */ 28 | isValidPrivate(key: Buffer): boolean; 29 | /** 30 | * Determines whether buffer contains a valid public key 31 | * @param key 32 | * @returns true if valid public, false if not 33 | */ 34 | isValidPublic(key: Buffer): boolean; 35 | /** 36 | * Converts a public key to address 37 | * @param key 38 | * @returns address 39 | */ 40 | publicToAddress(key: Buffer): Buffer; 41 | /** 42 | * Converts a private key to public key 43 | * @param privateKey 44 | * @returns public key 45 | */ 46 | privateToPublic(privateKey: Buffer): Buffer; 47 | /** 48 | * Converts a private key to address 49 | * @param privateKey 50 | * @returns address 51 | */ 52 | privateToAddress(privateKey: Buffer): Buffer; 53 | /** 54 | * Converts an address buffer to a checksummed address string 55 | * @param key 56 | * @returns checksumed address 57 | */ 58 | addressBufferToChecksum(key: Buffer): string; 59 | /** 60 | * Converts a buffer to a hex string 61 | * @param buf 62 | * @returns string 63 | */ 64 | bufferToHex(buf: Buffer): string; 65 | /** 66 | * Converts a balance to it's lowest denominator 67 | * @param input 68 | * @returns string 69 | */ 70 | balanceToStd(input: BigNumber): string; 71 | } 72 | -------------------------------------------------------------------------------- /dist/types/blockchain/ethereum/account.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { GenericAccount, IaccountOptions } from "../../core/account"; 3 | import { EthereumTransaction, IEthereumTransactionOptions } from "./transaction"; 4 | import { BigNumber } from "bignumber.js"; 5 | export declare class EthereumAccount extends GenericAccount { 6 | supportsCancel: boolean; 7 | /** 8 | * Creates an instance of ethereum account. 9 | * @param accountOptions 10 | */ 11 | constructor(accountOptions: IaccountOptions); 12 | /** 13 | * Gets balance 14 | * @returns a promise of a balance 15 | */ 16 | getBalance(): Promise; 17 | /** 18 | * Gets nonce 19 | * @returns a promise of a nonce 20 | */ 21 | getNonce(): Promise; 22 | /** 23 | * Builds cancel transaction 24 | * 25 | * @remarks 26 | * Sending a transaction with the same nonce but with higher gas price 27 | * will cancel an existing non mined transaction if included into a block. 28 | * 29 | * @param nonce - account nonce 30 | * @param txGasPrice - gas price in lowest denominator ( wei ) 31 | * @returns a new cancel transaction 32 | */ 33 | buildCancelTransaction(nonce: number, txGasPrice: number): EthereumTransaction; 34 | /** 35 | * Builds transfer transaction 36 | * @param to 37 | * @param amount 38 | * @param nonce 39 | * @param txGasPrice 40 | * @param txGasLimit 41 | * @returns transfer transaction 42 | */ 43 | buildTransferTransaction(to: string, amount: number, nonce: number, txGasPrice: number, txGasLimit: number): EthereumTransaction; 44 | /** 45 | * Params ethereum account 46 | * @param to 47 | * @param amount 48 | * @param nonce 49 | * @param txdata 50 | * @param [txGasPrice] 51 | * @param [txGasLimit] 52 | * @returns a cost estimate 53 | */ 54 | estimateTransaction(to: string, amount: number, nonce: number, txdata: Buffer, txGasPrice?: number, txGasLimit?: number): Promise; 55 | /** 56 | * Builds transaction 57 | * @param to 58 | * @param amount 59 | * @param nonce 60 | * @param txdata 61 | * @param txGasPrice 62 | * @param txGasLimit 63 | * @returns transaction 64 | */ 65 | buildTransaction(to: string, amount: number, nonce: number, txdata: Buffer, txGasPrice?: number, txGasLimit?: number): EthereumTransaction; 66 | /** 67 | * Signs transaction 68 | * @param transaction 69 | * @returns serialized data 70 | */ 71 | signTransaction(transaction: EthereumTransaction): Buffer; 72 | } 73 | -------------------------------------------------------------------------------- /dist/types/blockchain/ethereum/class.index.d.ts: -------------------------------------------------------------------------------- 1 | import { IBlockchainImplementation } from "../../core/blockchain-implementation"; 2 | export declare const Ethereum: IBlockchainImplementation; 3 | export default Ethereum; 4 | -------------------------------------------------------------------------------- /dist/types/blockchain/ethereum/config.d.ts: -------------------------------------------------------------------------------- 1 | import { IBlockchainConfig } from '../../core/blockchain-config'; 2 | export declare const EthereumConfig: IBlockchainConfig; 3 | export default EthereumConfig; 4 | -------------------------------------------------------------------------------- /dist/types/blockchain/ethereum/networks.d.ts: -------------------------------------------------------------------------------- 1 | import { Network } from '../../core/network'; 2 | declare const networks: Network[]; 3 | export default networks; 4 | -------------------------------------------------------------------------------- /dist/types/blockchain/ethereum/node.d.ts: -------------------------------------------------------------------------------- 1 | import { GenericNode } from "../../core/node"; 2 | import { Network } from "../../core/network"; 3 | import { BigNumber } from 'bignumber.js'; 4 | import { EthereumTransaction } from "./transaction"; 5 | export declare class EthereumNode extends GenericNode { 6 | static readonly NETWORKS: Network[]; 7 | /** 8 | * Creates an instance of ethereum node. 9 | * @param [network] 10 | */ 11 | constructor(network?: Network); 12 | /** 13 | * Gets balance 14 | * @param caddress 15 | * @returns balance 16 | */ 17 | getBalance(caddress: string): Promise; 18 | /** 19 | * Gets nonce 20 | * @param caddress 21 | * @returns nonce 22 | */ 23 | getNonce(caddress: string): Promise; 24 | /** 25 | * Estimates gas 26 | * @param callArguments 27 | * @returns gas estimate 28 | */ 29 | estimateGas(callArguments: any): Promise; 30 | /** 31 | * Gets transaction receipt 32 | * @param transaction 33 | * @returns transaction receipt 34 | */ 35 | getTransactionReceipt(transaction: EthereumTransaction): Promise; 36 | /** 37 | * Sends a transaction to the current network 38 | * @param transaction 39 | * @returns result 40 | */ 41 | send(transaction: EthereumTransaction): Promise; 42 | /** 43 | * Sends a raw transaction to the current network 44 | * @param data 45 | * @returns result 46 | */ 47 | sendRaw(data: any): Promise; 48 | } 49 | -------------------------------------------------------------------------------- /dist/types/blockchain/ethereum/transaction.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { GenericTransaction, ITransactionOptions } from '../../core/transaction'; 3 | export interface IEthereumTransactionOptions extends ITransactionOptions { 4 | gasPrice: number; 5 | gasLimit: number; 6 | chainId: number; 7 | data?: Buffer; 8 | } 9 | export declare class EthereumTransaction extends GenericTransaction { 10 | value: number; 11 | chainId: number; 12 | gasPrice: number; 13 | gasLimit: number; 14 | amount: number; 15 | /** 16 | * Creates an instance of an ethereum transaction. 17 | * @param from 18 | * @param to 19 | * @param amount 20 | * @param nonce 21 | * @param options 22 | */ 23 | constructor(from: string, to: string, amount: number, nonce: number, options: IEthereumTransactionOptions); 24 | /** 25 | * Converts current transaction to a parameters object required for transaction signing 26 | * @returns parameters object 27 | */ 28 | toParams(): { 29 | nonce: any; 30 | gasPrice: string; 31 | gasLimit: string; 32 | to: string; 33 | value: string; 34 | data: string; 35 | chainId: string; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /dist/types/blockchain/zilliqa/account-utils.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { GenericAccountUtils } from "../../core/account-utils"; 3 | import { BigNumber } from "bignumber.js"; 4 | export declare class ZilliqaAccountUtils extends GenericAccountUtils { 5 | /** 6 | * Determines whether string is a valid checksummed address 7 | * @param key 8 | * @returns true if valid checksum address, false if not 9 | */ 10 | isValidChecksumAddress(address: string): boolean; 11 | /** 12 | * Converts an address to a checksummed address 13 | * @param key 14 | * @returns checksumed address 15 | */ 16 | toChecksumAddress(address: string): string; 17 | /** 18 | * Determines whether buffer contains a valid address 19 | * @param key 20 | * @returns true if valid address, false if not 21 | */ 22 | isValidAddress(key: Buffer): boolean; 23 | /** 24 | * Determines whether buffer contains a valid private key 25 | * @param key 26 | * @returns true if valid private, false if not 27 | */ 28 | isValidPrivate(key: Buffer): boolean; 29 | /** 30 | * Determines whether buffer contains a valid public key 31 | * @param key 32 | * @returns true if valid public, false if not 33 | */ 34 | isValidPublic(key: Buffer): boolean; 35 | /** 36 | * Converts a public key to address 37 | * @param key 38 | * @returns address 39 | */ 40 | publicToAddress(key: Buffer): Buffer; 41 | /** 42 | * Converts a private key to public key 43 | * @param privateKey 44 | * @returns public key 45 | */ 46 | privateToPublic(privateKey: Buffer): Buffer; 47 | /** 48 | * Converts a private key to address 49 | * @param privateKey 50 | * @returns address 51 | */ 52 | privateToAddress(privateKey: Buffer): Buffer; 53 | /** 54 | * Converts an address buffer to a checksummed address string 55 | * @param key 56 | * @returns checksumed address 57 | */ 58 | addressBufferToChecksum(key: Buffer): string; 59 | /** 60 | * Converts a buffer to a hex string 61 | * @param buf 62 | * @returns string 63 | */ 64 | bufferToHex(buf: Buffer): string; 65 | /** 66 | * Converts a balance to it's lowest denominator 67 | * @param input 68 | * @returns string 69 | */ 70 | balanceToStd(input: BigNumber): string; 71 | } 72 | -------------------------------------------------------------------------------- /dist/types/blockchain/zilliqa/account.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { GenericAccount, IaccountOptions } from "../../core/account"; 3 | import { ZilliqaTransaction, IZilliqaTransactionOptions } from "./transaction"; 4 | import { BigNumber } from "bignumber.js"; 5 | export declare class ZilliqaAccount extends GenericAccount { 6 | /** 7 | * Creates an instance of zilliqa account. 8 | * @param accountOptions 9 | */ 10 | constructor(accountOptions: IaccountOptions); 11 | /** 12 | * Gets balance 13 | * @returns a promise of a balance 14 | */ 15 | getBalance(): Promise; 16 | /** 17 | * Gets nonce 18 | * @returns a promise of a nonce 19 | */ 20 | getNonce(): Promise; 21 | /** 22 | * Builds transfer transaction 23 | * @param to 24 | * @param amount 25 | * @param nonce 26 | * @param txGasLimit 27 | * @param txGasPrice 28 | * @returns transfer transaction 29 | */ 30 | buildTransferTransaction(to: string, amount: number, nonce: number, txGasLimit: number, txGasPrice: number): ZilliqaTransaction; 31 | /** 32 | * Estimates transaction 33 | * @param to 34 | * @param amount 35 | * @param nonce 36 | * @param txdata 37 | * @param [txGasPrice] 38 | * @param [txGasLimit] 39 | * @returns a cost estimate 40 | */ 41 | estimateTransaction(to: string, amount: number, nonce: number, txdata: Buffer, txGasPrice?: number, txGasLimit?: number): Promise; 42 | /** 43 | * Builds transaction 44 | * @param to 45 | * @param amount 46 | * @param nonce 47 | * @param txdata 48 | * @param txGasPrice 49 | * @param txGasLimit 50 | * @returns transaction 51 | */ 52 | buildTransaction(to: string, amount: number, nonce: number, txdata: Buffer, txGasPrice?: number, txGasLimit?: number): ZilliqaTransaction; 53 | /** 54 | * Signs transaction 55 | * @param transaction 56 | * @returns serialized data 57 | */ 58 | signTransaction(transaction: ZilliqaTransaction): Buffer; 59 | /** 60 | * not supported 61 | */ 62 | buildCancelTransaction(nonce: number, txGasPrice: number): ZilliqaTransaction | false; 63 | } 64 | -------------------------------------------------------------------------------- /dist/types/blockchain/zilliqa/class.index.d.ts: -------------------------------------------------------------------------------- 1 | import { IBlockchainImplementation } from "../../core/blockchain-implementation"; 2 | export declare const Zilliqa: IBlockchainImplementation; 3 | export default Zilliqa; 4 | -------------------------------------------------------------------------------- /dist/types/blockchain/zilliqa/config.d.ts: -------------------------------------------------------------------------------- 1 | import { IBlockchainConfig } from '../../core/blockchain-config'; 2 | export declare const ZilliqaConfig: IBlockchainConfig; 3 | export default ZilliqaConfig; 4 | -------------------------------------------------------------------------------- /dist/types/blockchain/zilliqa/networks.d.ts: -------------------------------------------------------------------------------- 1 | import { Network } from '../../core/network'; 2 | declare const networks: Network[]; 3 | export default networks; 4 | -------------------------------------------------------------------------------- /dist/types/blockchain/zilliqa/node.d.ts: -------------------------------------------------------------------------------- 1 | import { GenericNode } from "../../core/node"; 2 | import { Network } from "../../core/network"; 3 | import { BigNumber } from 'bignumber.js'; 4 | import { ZilliqaTransaction } from "./transaction"; 5 | export declare class ZilliqaNode extends GenericNode { 6 | static readonly NETWORKS: Network[]; 7 | /** 8 | * Creates an instance of zilliqa node. 9 | * @param [network] 10 | */ 11 | constructor(network?: Network); 12 | /** 13 | * Gets balance 14 | * @param caddress 15 | * @returns balance 16 | */ 17 | getBalance(caddress: string): Promise; 18 | /** 19 | * Gets nonce 20 | * @param caddress 21 | * @returns nonce 22 | */ 23 | getNonce(caddress: string): Promise; 24 | /** 25 | * Estimates gas 26 | * @param callArguments 27 | * @returns gas estimate 28 | */ 29 | estimateGas(callArguments: any): Promise; 30 | /** 31 | * Gets transaction receipt 32 | * @param transaction 33 | * @returns transaction receipt 34 | */ 35 | getTransactionReceipt(transaction: ZilliqaTransaction): Promise; 36 | /** 37 | * Sends a transaction to the current network 38 | * @param transaction 39 | * @returns result 40 | */ 41 | send(transaction: ZilliqaTransaction): Promise; 42 | /** 43 | * Sends a raw transaction to the current network 44 | * @param data 45 | * @returns result 46 | */ 47 | sendRaw(data: any): Promise; 48 | } 49 | -------------------------------------------------------------------------------- /dist/types/blockchain/zilliqa/transaction.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | import { GenericTransaction, ITransactionOptions } from '../../core/transaction'; 5 | import { BN, Long } from '@zilliqa-js/util'; 6 | export interface IZilliqaTransactionOptions extends ITransactionOptions { 7 | gasPrice: number; 8 | gasLimit: number; 9 | chainId: number; 10 | pubKey?: string; 11 | code?: Buffer; 12 | data?: Buffer; 13 | } 14 | export declare class ZilliqaTransaction extends GenericTransaction { 15 | version: number; 16 | pubKey: string; 17 | code: Buffer; 18 | amount: number; 19 | chainId: number; 20 | gasPrice: number; 21 | gasLimit: number; 22 | TXObject: any; 23 | txn: any; 24 | /** 25 | * Creates an instance of a zilliqa transaction. 26 | * @param from 27 | * @param to 28 | * @param amount 29 | * @param nonce 30 | * @param options 31 | */ 32 | constructor(from: string, to: string, amount: number, nonce: number, options: IZilliqaTransactionOptions); 33 | /** 34 | * Converts current transaction to a parameters object required for transaction signing 35 | * @returns parameters object 36 | */ 37 | toParams(subPubKey?: string): { 38 | version: number; 39 | toAddr: string; 40 | nonce: number; 41 | pubKey: string; 42 | amount: BN; 43 | gasPrice: BN; 44 | gasLimit: Long; 45 | code: string; 46 | data: string; 47 | signature: string; 48 | }; 49 | /** 50 | * Gets proto encoded tx 51 | * @param TXObject 52 | * @returns proto encoded tx 53 | */ 54 | getProtoEncodedTx(TXObject: any): Buffer; 55 | } 56 | -------------------------------------------------------------------------------- /dist/types/class.store.d.ts: -------------------------------------------------------------------------------- 1 | export default class DynamicClass { 2 | classStore: any; 3 | /** 4 | * Collects and index classes so we can instantiate them later 5 | * @param object 6 | */ 7 | collectClasses(object: any): void; 8 | /** 9 | * Gets a class instance for supplied name and options 10 | * @param className 11 | * @param [opts] 12 | * @returns supplied class instance 13 | */ 14 | getInstance(className: string, opts?: any): any; 15 | } 16 | -------------------------------------------------------------------------------- /dist/types/core/account-utils.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { BigNumber } from "bignumber.js"; 3 | export declare abstract class GenericAccountUtils { 4 | /** 5 | * Parameter type validation 6 | * @param target 7 | * @param expected 8 | * @param method 9 | * @returns true if type matches 10 | */ 11 | requireType(target: any, expected: string, method: string): boolean; 12 | /** 13 | * Determines whether string is a valid checksummed address 14 | * @param key 15 | * @returns true if valid checksum address, false if not 16 | */ 17 | abstract isValidChecksumAddress(key: string): boolean; 18 | /** 19 | * Converts an address to a checksummed address 20 | * @param key 21 | * @returns checksumed address 22 | */ 23 | abstract toChecksumAddress(key: string): string; 24 | /** 25 | * Determines whether buffer contains a valid address 26 | * @param key 27 | * @returns true if valid address, false if not 28 | */ 29 | abstract isValidAddress(key: Buffer): boolean; 30 | /** 31 | * Determines whether buffer contains a valid private key 32 | * @param key 33 | * @returns true if valid private, false if not 34 | */ 35 | abstract isValidPrivate(key: Buffer): boolean; 36 | /** 37 | * Determines whether buffer contains a valid public key 38 | * @param key 39 | * @returns true if valid public, false if not 40 | */ 41 | abstract isValidPublic(key: Buffer): boolean; 42 | /** 43 | * Converts a public key to address 44 | * @param key 45 | * @returns address 46 | */ 47 | abstract publicToAddress(key: Buffer): Buffer; 48 | /** 49 | * Converts a private key to public key 50 | * @param privateKey 51 | * @returns public key 52 | */ 53 | abstract privateToPublic(privateKey: Buffer): Buffer; 54 | /** 55 | * Converts a private key to address 56 | * @param privateKey 57 | * @returns address 58 | */ 59 | abstract privateToAddress(privateKey: Buffer): Buffer; 60 | /** 61 | * Converts an address buffer to a checksummed address string 62 | * @param key 63 | * @returns checksumed address 64 | */ 65 | abstract addressBufferToChecksum(key: Buffer): string; 66 | /** 67 | * Converts a buffer to a hex string 68 | * @param buf 69 | * @returns string 70 | */ 71 | abstract bufferToHex(buf: Buffer): string; 72 | /** 73 | * Converts a balance to it's lowest denominator 74 | * @param input 75 | * @returns string 76 | */ 77 | abstract balanceToStd(input: number | string | BigNumber): string; 78 | } 79 | -------------------------------------------------------------------------------- /dist/types/core/account.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { GenericTransaction, ITransactionOptions } from './transaction'; 3 | import { GenericNode } from "./node"; 4 | import HDKey from './utils/hdkey'; 5 | import { GenericAccountUtils } from './account-utils'; 6 | import { BigNumber } from "bignumber.js"; 7 | export declare enum AccountType { 8 | HD = "HD", 9 | LOOSE = "LOOSE", 10 | HARDWARE = "HARDWARE" 11 | } 12 | export interface IaccountOptions { 13 | node: GenericNode; 14 | privateKey?: string; 15 | publicKey?: string; 16 | address?: string; 17 | type: AccountType; 18 | hd?: any; 19 | } 20 | export declare abstract class GenericAccount { 21 | static getImplementedClassName(name: string): string; 22 | node: GenericNode; 23 | address: string; 24 | publicKey: string; 25 | privateKey: string; 26 | type: AccountType; 27 | hd: HDKey | any; 28 | utils: GenericAccountUtils | any; 29 | supportsCancel: boolean; 30 | private transactions; 31 | /** 32 | * Creates an instance of generic account. 33 | * @param accountOptions 34 | */ 35 | constructor(accountOptions: IaccountOptions); 36 | /** 37 | * Trys hd wallet setup 38 | */ 39 | tryHdWalletSetup(): void; 40 | /** 41 | * Gets transactions 42 | * @returns transactions 43 | */ 44 | getTransactions(): T[]; 45 | /** 46 | * Sends generic account 47 | * @param transaction 48 | * @param [cb] 49 | * @param [cbtype] 50 | * @returns send 51 | */ 52 | send(transaction: T, cb?: any, cbtype?: string): Promise<{ 53 | txn: any; 54 | receipt: any; 55 | }>; 56 | /** 57 | * Gets balance 58 | * @returns balance 59 | */ 60 | abstract getBalance(): Promise; 61 | /** 62 | * Gets nonce 63 | * @returns nonce 64 | */ 65 | abstract getNonce(): Promise; 66 | /** 67 | * Builds cancel transaction if supported by the implementation 68 | * 69 | * @remarks 70 | * Sending a transaction with the same nonce but with higher gas price 71 | * will cancel an existing non mined transaction if included into a block. 72 | * 73 | * @param nonce - account nonce 74 | * @param txGasPrice - gas price in lowest denominator 75 | * @returns a new cancel transaction 76 | */ 77 | abstract buildCancelTransaction(nonce: number, txGasPrice: number): GenericTransaction | false; 78 | /** 79 | * Builds transfer transaction 80 | * @param to 81 | * @param amount 82 | * @param nonce 83 | * @param txGasLimit 84 | * @param txGasPrice 85 | * @returns transfer transaction 86 | */ 87 | abstract buildTransferTransaction(to: string, amount: number, nonce: number, txGasPrice: number, txGasLimit: number): T; 88 | /** 89 | * Estimates transaction 90 | * @param to 91 | * @param amount 92 | * @param nonce 93 | * @param txdata 94 | * @param [txGasPrice] 95 | * @param [txGasLimit] 96 | * @returns a cost estimate 97 | */ 98 | abstract estimateTransaction(to: string, amount: number, nonce: number, txdata: Buffer, txGasPrice?: number, txGasLimit?: number): Promise; 99 | /** 100 | * Builds transaction 101 | * @param to 102 | * @param amount 103 | * @param nonce 104 | * @param txdata 105 | * @param gasLimit 106 | * @param gasPrice 107 | * @returns transaction 108 | */ 109 | abstract buildTransaction(to: string, amount: number, nonce: number, txdata: Buffer, gasPrice: number, gasLimit: number): GenericTransaction; 110 | /** 111 | * Signs transaction 112 | * @param transaction 113 | * @returns serialized data 114 | */ 115 | abstract signTransaction(transaction: T): Buffer; 116 | } 117 | -------------------------------------------------------------------------------- /dist/types/core/amount.d.ts: -------------------------------------------------------------------------------- 1 | import { IBlockchainConfig } from './blockchain-config'; 2 | import BigNumber from 'bignumber.js'; 3 | export declare class Amount { 4 | static config: Map; 7 | /** 8 | * Add configuration 9 | * @param config 10 | */ 11 | static addConfig(config: IBlockchainConfig): void; 12 | coin: string; 13 | private value; 14 | /** 15 | * Creates an instance of amount. 16 | * @param value 17 | * @param coin 18 | * @param [unit] 19 | */ 20 | constructor(value: number | BigNumber, coin: string, unit?: string); 21 | plus(amount: Amount): Amount; 22 | minus(amount: Amount): Amount; 23 | dividedBy(amount: Amount): Amount; 24 | multipliedBy(amount: Amount): Amount; 25 | toBigNumber(unit?: string): BigNumber; 26 | toNumber(unit?: string): number; 27 | toString(unit?: string): string; 28 | private withUnit; 29 | private assertSameCoins; 30 | } 31 | -------------------------------------------------------------------------------- /dist/types/core/blockchain-config.d.ts: -------------------------------------------------------------------------------- 1 | import { Blockchain } from './blockchain'; 2 | export interface IBlockchainConfig { 3 | blockchain: Blockchain; 4 | mainCoin: string; 5 | units?: { 6 | [unit: string]: number; 7 | }; 8 | unitsExtra?: { 9 | [unit: string]: number; 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /dist/types/core/blockchain-implementation.d.ts: -------------------------------------------------------------------------------- 1 | import { IBlockchainConfig } from "./blockchain-config"; 2 | import { Network } from "./network"; 3 | export interface IBlockchainImplementation { 4 | AvailableClasses: { 5 | [className: string]: any; 6 | }; 7 | config: IBlockchainConfig; 8 | networks: Network[]; 9 | } 10 | -------------------------------------------------------------------------------- /dist/types/core/blockchain.d.ts: -------------------------------------------------------------------------------- 1 | export declare enum Blockchain { 2 | ETHEREUM = "ETHEREUM", 3 | ZILLIQA = "ZILLIQA" 4 | } 5 | -------------------------------------------------------------------------------- /dist/types/core/network.d.ts: -------------------------------------------------------------------------------- 1 | import { Blockchain } from "./blockchain"; 2 | export interface Network { 3 | network_id: number; 4 | blockchain: Blockchain; 5 | chainId: number; 6 | name: string; 7 | url: string; 8 | mainNet: boolean; 9 | HDCoinValue: number; 10 | } 11 | -------------------------------------------------------------------------------- /dist/types/core/node.d.ts: -------------------------------------------------------------------------------- 1 | import { Network } from "./network"; 2 | import { BigNumber } from "bignumber.js"; 3 | import { GenericTransaction } from "./transaction"; 4 | export declare abstract class GenericNode { 5 | static readonly NETWORKS: Network[]; 6 | /** 7 | * Gets implemented class name 8 | * @param name 9 | * @returns class name string 10 | */ 11 | static getImplementedClassName(name: string): string; 12 | customNetworkUrl: boolean; 13 | connected: boolean; 14 | NETWORKS: Network[]; 15 | network: Network; 16 | blockchain: any; 17 | HDRootKey: any; 18 | callId: number; 19 | /** 20 | * Initialises node on specified network or default if network param is not supplied 21 | * @param [network] 22 | */ 23 | init(network?: Network): void; 24 | /** 25 | * Gets current network path string 26 | * @returns current network path string 27 | */ 28 | getCurrentNetworkPathString(): any; 29 | /** 30 | * Gets current network 31 | * @returns network 32 | */ 33 | getNetwork(): Network; 34 | /** 35 | * Sets custom network url 36 | * @param url 37 | */ 38 | setCustomNetworkUrl(url: string): void; 39 | /** 40 | * Resets custom network url 41 | */ 42 | resetCustomNetworkUrl(): void; 43 | /** 44 | * Posts an RPC call to the current network 45 | * @param method - RPC Method name 46 | * @param params - RPC Method parameters 47 | * @param [dec] - Result decoder type 48 | * @returns raw or decoded result 49 | */ 50 | rpcCall(method: string, params: any, dec?: string): Promise; 51 | /** 52 | * Build an RPC call 53 | * @param cmethod 54 | * @param cparams 55 | * @returns call 56 | */ 57 | buildCall(cmethod: string, cparams: any): any; 58 | /** 59 | * Converts the received data into the requested type 60 | * @param data 61 | * @param [type] 62 | * @returns decoded result 63 | */ 64 | resultDecoder(data: any, type?: string): any; 65 | /** 66 | * Gets transaction receipt 67 | * @param transaction 68 | * @returns transaction receipt 69 | */ 70 | abstract getTransactionReceipt(transaction: GenericTransaction): Promise; 71 | /** 72 | * Gets balance 73 | * @param address 74 | * @returns balance 75 | */ 76 | abstract getBalance(address: string): Promise; 77 | /** 78 | * Gets nonce 79 | * @param address 80 | * @returns nonce 81 | */ 82 | abstract getNonce(address: string): Promise; 83 | /** 84 | * Estimates gas 85 | * @param callArguments 86 | * @returns gas estimate 87 | */ 88 | abstract estimateGas(callArguments: any): Promise; 89 | /** 90 | * Sends a transaction to the current network 91 | * @param transaction 92 | * @returns result 93 | */ 94 | abstract send(transaction: GenericTransaction): Promise; 95 | } 96 | -------------------------------------------------------------------------------- /dist/types/core/transaction.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { ITransactionOptions } from './transaction'; 3 | export interface ITransactionOptions { 4 | } 5 | export declare enum TransactionStatus { 6 | NEW = "NEW", 7 | SIGNED = "SIGNED", 8 | PENDING = "PENDING", 9 | FINAL = "FINAL" 10 | } 11 | export declare abstract class GenericTransaction { 12 | static getImplementedClassName(name: string): string; 13 | from: string; 14 | to: string; 15 | nonce: number; 16 | options: TO; 17 | data: Buffer; 18 | receipt: any; 19 | txn: string; 20 | raw: Buffer; 21 | status: TransactionStatus; 22 | times: any; 23 | constructor(from: string, to: string, nonce: number, options: TO); 24 | /** 25 | * Sets transaction status to signed, adds raw data and indexes event 26 | * @param data 27 | */ 28 | setSignedResult(data: Buffer): void; 29 | /** 30 | * Sets transaction status to pending and indexes event 31 | * @param data 32 | */ 33 | setPending(): void; 34 | /** 35 | * Sets transaction status to final, adds txn and indexes event 36 | * @param data 37 | */ 38 | setTxn(txn: string): void; 39 | /** 40 | * Sets transaction receipt and indexes event 41 | * @param data 42 | */ 43 | setReceiptStatus(receipt: any): void; 44 | /** 45 | * Converts number to hex string 46 | * @param num 47 | * @returns hex representation 48 | */ 49 | getNumberToHex(num: number): string; 50 | /** 51 | * Adds time to current event 52 | * @param eventName 53 | */ 54 | addTime(eventName: string): void; 55 | /** 56 | * Converts current transaction to a parameters object required for transaction signing 57 | * @returns parameters object 58 | */ 59 | abstract toParams(): any; 60 | } 61 | -------------------------------------------------------------------------------- /dist/types/core/utils/hdkey.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | export default class HDKey { 3 | static fromHDKey(npmhdkey: HDKey): HDKey; 4 | static fromMasterSeed(seedBuffer: Buffer): HDKey; 5 | npmhdkey: any; 6 | derivePath(path: any): HDKey; 7 | deriveChild(index: any): HDKey; 8 | getPrivateKey(): Buffer; 9 | getPrivateKeyString(): string; 10 | } 11 | -------------------------------------------------------------------------------- /dist/types/core/utils/mnemonic.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | interface WordListItem { 3 | [key: string]: string[]; 4 | } 5 | export default class Mnemonic { 6 | static getAvailableWordLists(): WordListItem; 7 | static generateMnemonic(language?: string): string; 8 | static mnemonicToSeed(mnemonic: string, language?: string, password?: string): Buffer; 9 | static getWordsFromMnemonic(mnemonic: string, language?: string): string[]; 10 | } 11 | export {}; 12 | -------------------------------------------------------------------------------- /dist/types/index.d.ts: -------------------------------------------------------------------------------- 1 | import Wallet from "./core/wallet"; 2 | import { Blockchain as Blockchains } from "./core/blockchain"; 3 | import { AccountType } from "./core/account"; 4 | import MnemonicUtils from "./core/utils/mnemonic"; 5 | export { Wallet, Blockchains, AccountType, MnemonicUtils, }; 6 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | const browserify = require('browserify'); 2 | const gulp = require('gulp'); 3 | const source = require('vinyl-source-stream'); 4 | const buffer = require('vinyl-buffer'); 5 | const uglify = require('gulp-uglify-es').default; 6 | const gutil = require('gulp-util'); 7 | const sourcemaps = require('gulp-sourcemaps'); 8 | const babelify = require('babelify'); 9 | const es2015presets = require('babel-preset-es2015'); 10 | 11 | gulp.task('build', function () { 12 | // set up the browserify instance on a task basis 13 | 14 | const c = browserify({ 15 | entries: './dist/lib/index.js', 16 | debug: true, 17 | transform: [babelify.configure({ 18 | extensions: ['.ts', '.js'], 19 | presets: [ es2015presets ] 20 | })] 21 | }); 22 | 23 | 24 | return c.bundle() 25 | .pipe(source('../bundle/moonlet-core.min.js')) 26 | .pipe(buffer()) 27 | .pipe(sourcemaps.init({ loadMaps: true })) 28 | // Add transformation tasks to the pipeline here 29 | .pipe(uglify()) 30 | .on('error', gutil.log) 31 | .pipe(sourcemaps.write('./')) 32 | .pipe(gulp.dest('./dist/bundle')); 33 | }); 34 | 35 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "moonlet-core", 3 | "version": "0.0.1", 4 | "description": "Moonlet - Core Package", 5 | "main": "dist/lib/index.js", 6 | "types": "dist/types/index.d.ts", 7 | "scripts": { 8 | "build": "npm run build:lib && npm run build:dec", 9 | "build:gulp": "gulp build", 10 | "build:lib": "tsc --skipLibCheck -p .", 11 | "build:dec": "scripts/declarations.sh", 12 | "build:docs": "./node_modules/.bin/typedoc --out ../cryptolandtech.github.io/moonlet-core/ --readme DOCS.md", 13 | "coverage": "scripts/run_coverage.sh all", 14 | "coverage-reuse": "scripts/run_coverage.sh all use-existing", 15 | "test": "scripts/run_tests.sh all", 16 | "test-reuse": "scripts/run_tests.sh all use-existing", 17 | "test-single": "scripts/run_tests.sh single", 18 | "test-single-reuse": "scripts/run_tests.sh single use-existing", 19 | "testToHtml": "scripts/testOutputToHtml.sh", 20 | "start-all-rpcs": "scripts/rpcs/start_all.sh", 21 | "stop-all-rpcs": "scripts/rpcs/stop_all.sh", 22 | "coverallstest": "./node_modules/.bin/ts-mocha --require source-map-support/register --full-trace --colors --paths -p ./ test/*/*.ts test/*.ts", 23 | "coveralls": "nyc npm run coverallstest && nyc report --reporter=text-lcov | coveralls" 24 | }, 25 | "bin": { 26 | "rpcs": "./scripts/rpc.sh" 27 | }, 28 | "nyc": { 29 | "extension": [ 30 | ".ts", 31 | ".tsx" 32 | ], 33 | "include": "src", 34 | "exclude": [ 35 | "**/*.d.ts" 36 | ], 37 | "reporter": [ 38 | "text", 39 | "html" 40 | ], 41 | "all": true 42 | }, 43 | "repository": { 44 | "type": "git", 45 | "url": "git+https://github.com/cryptolandtech/moonlet-core" 46 | }, 47 | "keywords": [ 48 | "moonlet-core", 49 | "crypto", 50 | "wallet" 51 | ], 52 | "author": "Micky Socaci ", 53 | "license": "MIT", 54 | "bugs": { 55 | "url": "https://github.com/cryptolandtech/moonlet-core/issues" 56 | }, 57 | "homepage": "https://github.com/cryptolandtech/moonlet-core#readme", 58 | "dependencies": { 59 | "@zilliqa-js/account": "0.6.0", 60 | "@zilliqa-js/crypto": "0.6.0", 61 | "@zilliqa-js/util": "0.6.0", 62 | "axios": "0.18.0", 63 | "babel-plugin-transform-builtin-extend": "^1.1.2", 64 | "bignumber.js": "8.0.2", 65 | "bip39": "2.5.0", 66 | "ethereumjs-tx": "1.3.7", 67 | "ethereumjs-util": "6.0.0", 68 | "hdkey": "1.1.0" 69 | }, 70 | "devDependencies": { 71 | "tslint-microsoft-contrib": "^6.0.0", 72 | "tslib": "^1.9.3", 73 | "tslint": "^5.12.0", 74 | "chai": "^4.2.0", 75 | "ts-mocha": "^1.3.0", 76 | "ganache-cli": "^6.1.8", 77 | "kaya": "git+https://github.com/cryptolandtech/kaya.git", 78 | "@types/chai": "^4.1.6", 79 | "@types/ethereumjs-tx": "^1.0.0", 80 | "@types/mocha": "^5.2.5", 81 | "@types/node": "^10.12.18", 82 | "babel-cli": "^6.26.0", 83 | "babel-core": "^6.26.3", 84 | "babel-preset-es2015": "^6.24.1", 85 | "babelify": "^8.0.0", 86 | "browserify": "^16.2.3", 87 | "colors": "^1.3.3", 88 | "compression-webpack-plugin": "^1.1.12", 89 | "coveralls": "^3.0.2", 90 | "cross-env": "^5.2.0", 91 | "gulp": "^3.9.1", 92 | "gulp-sourcemaps": "^2.6.4", 93 | "gulp-uglify-es": "^1.0.4", 94 | "gulp-util": "^3.0.8", 95 | "istanbul": "^0.4.5", 96 | "laksa-core-crypto": "0.0.45", 97 | "mocha": "^4.1.0", 98 | "mocha-lcov-reporter": "^1.3.0", 99 | "mocha-loader": "^1.1.3", 100 | "mocha-webpack": "^1.0.1", 101 | "nyc": "^13.1.0", 102 | "safe-buffer": "^5.1.2", 103 | "source-map-support": "^0.5.9", 104 | "tsify": "^4.0.0", 105 | "typedoc": "^0.14.0", 106 | "typescript": "^3.2.1", 107 | "vinyl-buffer": "^1.0.1", 108 | "vinyl-source-stream": "^2.0.0" 109 | }, 110 | "engines": { 111 | "node": ">=6.0.0" 112 | }, 113 | "standard": { 114 | "env": "mocha", 115 | "globals": [ 116 | "describe", 117 | "it" 118 | ] 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /scripts/TestRPCData/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cryptolandtech/moonlet-core/531fda8f35c78f6967ca443def60cda84ddc79a6/scripts/TestRPCData/.gitkeep -------------------------------------------------------------------------------- /scripts/declarations.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tsc --declaration true --emitDeclarationOnly --declarationDir dist/types --skipLibCheck -p . 3 | 4 | # due to some bug or bad import we need to replace all src/core/transaction 5 | # imports from the results to the proper path 6 | 7 | find dist/types -type f -print0 | xargs -0 sed -i 's/src\/core\/transaction/\.\/transaction/g' 8 | -------------------------------------------------------------------------------- /scripts/rpc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd node_modules/wws-core.js/ 3 | if [[ "$1" == "start" ]]; then 4 | sh ./scripts/rpcs/start_all.sh 5 | else 6 | sh ./scripts/rpcs/stop_all.sh 7 | fi 8 | -------------------------------------------------------------------------------- /scripts/rpcs/_seed_words: -------------------------------------------------------------------------------- 1 | exchange neither monster ethics bless cancel ghost excite business record warfare invite -------------------------------------------------------------------------------- /scripts/rpcs/account-fixtures.json: -------------------------------------------------------------------------------- 1 | { 2 | "17f343a7a13bac8026d6c84e2ee2925aeba1fa61": { 3 | "privateKey": "ed50e832ef7722239de17e49cd40d86c16df4649275452af470e9b84ef14eea8", 4 | "amount": 100000, 5 | "nonce": 0 6 | }, 7 | "693e20469bffde10dd4d252d5f907cebbd201bb6": { 8 | "privateKey": "195adc169bab9b6ed6c858089a42e47692b2c7fbe5a1b109c7225bcbd1ca89b9", 9 | "amount": 100000, 10 | "nonce": 0 11 | }, 12 | "78e44924bbc5f4b2c60b2aa9cedf7e0e66c68e36": { 13 | "privateKey": "29658ab3df1ba6bbefd52365f8048dbcb56313cd3ebae31a3c0bb76d9d083fd1", 14 | "amount": 100000, 15 | "nonce": 0 16 | }, 17 | "94af5652316326d299985d6ea0fcfb8353717dec": { 18 | "privateKey": "254cfa989a2681d0213fbc27340882a286e526b17aa9d16108e9d3d43c1548ac", 19 | "amount": 100000, 20 | "nonce": 0 21 | }, 22 | "c4c29d19c63fe6eee06145de24c0a6813e452b62": { 23 | "privateKey": "fa6959db47bc4b12aae0e45ea145d2ba9bb51d2a610f8536be743d93e19d9ec2", 24 | "amount": 100000, 25 | "nonce": 0 26 | }, 27 | "baf5f8f783de95a157d294ac74f9ffb77ded0a99": { 28 | "privateKey": "032827725aad3ee0d9ab22e44bffc9d2a2fdea9a3eb885ad6b64e3723a3bade6", 29 | "amount": 100000, 30 | "nonce": 0 31 | }, 32 | "240f1f305271bef98b7ed021fb9939ce2db65bc1": { 33 | "privateKey": "febfcd14fb3e24e37944870436014474dcfafc4edb8f331f11da67d189883edd", 34 | "amount": 100000, 35 | "nonce": 0 36 | }, 37 | "bb620c967a86e98ec620712692bca463645b35a0": { 38 | "privateKey": "5185dbb2b53756bfbbbd3ed4dc828dd8a25d4d1a7471c2590db7d538f8ba4604", 39 | "amount": 100000, 40 | "nonce": 0 41 | }, 42 | "44526c8eef2efab582b049003741079b36f7ad3b": { 43 | "privateKey": "3b6ea2747a253b93abbb2aceebf4d687bc3c937bd40adc00e709168d69d8cdfe", 44 | "amount": 100000, 45 | "nonce": 0 46 | }, 47 | "22537dfddb1232be8ce10c7fc4b784f61a4375a9": { 48 | "privateKey": "0da6b2b62792202ad94d44ac66b58a751783f3dd36551c994b0864216d726652", 49 | "amount": 100000, 50 | "nonce": 0 51 | } 52 | } -------------------------------------------------------------------------------- /scripts/rpcs/ethereum/startrpc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Exit script as soon as a command fails. 4 | set -o errexit 5 | 6 | moduleName="ethereum" 7 | softwareName="ganache-cli" 8 | testrpc_port=8545 9 | SeedFile="scripts/rpcs/_seed_words" 10 | seedWords=$(<"$SeedFile") 11 | 12 | testrpc_running() { 13 | nc -z localhost "$testrpc_port" 14 | } 15 | 16 | start_testrpc() { 17 | ganache-cli -a 10 -d -n -i 15 -p $testrpc_port -m "$seedWords" > scripts/TestRPCData/$moduleName.output.log & 18 | testrpc_pid=$! 19 | echo $testrpc_pid > scripts/TestRPCData/$moduleName.process.pid 20 | } 21 | 22 | if testrpc_running; then 23 | if [[ "$1" != "use-existing" ]]; then 24 | echo "Killing existing $softwareName instance at port $testrpc_port" 25 | kill -9 $( lsof -i -P | grep $testrpc_port | awk '{print $2}' ) > /dev/null 26 | echo "Starting new $softwareName instance at port $testrpc_port" 27 | start_testrpc 28 | else 29 | echo "Using $softwareName instance at port $testrpc_port" 30 | fi 31 | else 32 | echo "Starting new $softwareName instance at port $testrpc_port" 33 | start_testrpc 34 | fi 35 | 36 | if testrpc_running; then 37 | echo "$softwareName initialised." 38 | else 39 | echo "$softwareName did not initialize yet. Sleeping for 2 seconds.." 40 | sleep 2 41 | fi -------------------------------------------------------------------------------- /scripts/rpcs/ethereum/stoprpc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | moduleName="ethereum" 4 | softwareName="ganache-cli" 5 | PIDFile="scripts/TestRPCData/$moduleName.process.pid" 6 | CurPID=$(<"$PIDFile") 7 | 8 | if [[ "$1" != "use-existing" ]]; then 9 | kill -9 $CurPID 10 | echo "Killing existing $softwareName instance at pid $CurPID." 11 | echo "" > $PIDFile 12 | else 13 | echo "Leaving $softwareName instance at pid $CurPID running." 14 | fi 15 | -------------------------------------------------------------------------------- /scripts/rpcs/start_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sh scripts/rpcs/ethereum/startrpc.sh $1 3 | sh scripts/rpcs/zilliqa/startrpc.sh $1 4 | 5 | -------------------------------------------------------------------------------- /scripts/rpcs/stop_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sh scripts/rpcs/ethereum/stoprpc.sh $1 3 | sh scripts/rpcs/zilliqa/stoprpc.sh $1 4 | -------------------------------------------------------------------------------- /scripts/rpcs/zilliqa/startrpc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Exit script as soon as a command fails. 4 | set -o errexit 5 | 6 | moduleName="zilliqa" 7 | softwareName="Kaya" 8 | testrpc_port=4200 9 | SeedFile="scripts/rpcs/_seed_words" 10 | seedWords=$(<"$SeedFile") 11 | 12 | testrpc_running() { 13 | nc -z localhost "$testrpc_port" 14 | } 15 | 16 | start_testrpc() { 17 | npx kaya -v --f scripts/rpcs/account-fixtures.json > scripts/TestRPCData/$moduleName.output.log & 18 | testrpc_pid=$! 19 | echo $testrpc_pid > scripts/TestRPCData/$moduleName.process.pid 20 | } 21 | 22 | if testrpc_running; then 23 | if [[ "$1" != "use-existing" ]]; then 24 | echo "Killing existing $softwareName instance at port $testrpc_port" 25 | kill -9 $( lsof -i -P | grep $testrpc_port | awk '{print $2}' ) > /dev/null 26 | echo "Starting new $softwareName instance at port $testrpc_port" 27 | start_testrpc 28 | else 29 | echo "Using $softwareName instance at port $testrpc_port" 30 | fi 31 | else 32 | echo "Starting new $softwareName instance at port $testrpc_port" 33 | start_testrpc 34 | fi 35 | 36 | if testrpc_running; then 37 | echo "$softwareName initialised." 38 | else 39 | echo "$softwareName did not initialize yet. Sleeping for 2 seconds.." 40 | sleep 2 41 | fi -------------------------------------------------------------------------------- /scripts/rpcs/zilliqa/stoprpc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | moduleName="zilliqa" 4 | softwareName="Kaya" 5 | PIDFile="scripts/TestRPCData/$moduleName.process.pid" 6 | CurPID=$(<"$PIDFile") 7 | 8 | if [[ "$1" != "use-existing" ]]; then 9 | kill -9 $CurPID 10 | echo "Killing existing $softwareName instance at pid $CurPID." 11 | echo "" > $PIDFile 12 | else 13 | echo "Leaving $softwareName instance at pid $CurPID running." 14 | fi 15 | -------------------------------------------------------------------------------- /scripts/run_coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sh scripts/rpcs/start_all.sh $2 3 | echo "" 4 | echo "--------------------------------------------------------------------" 5 | echo " Running all tests in \"test\" folder:" 6 | echo "--------------------------------------------------------------------" 7 | 8 | npx nyc mocha --require ts-node/register \ 9 | --require source-map-support/register \ 10 | --full-trace \ 11 | --bail \ 12 | --colors \ 13 | --paths -p ./ test/*/*.ts test/*.ts 14 | 15 | echo "--------------------------------------------------------------------" 16 | echo "" 17 | sh scripts/rpcs/stop_all.sh $2 18 | echo "" -------------------------------------------------------------------------------- /scripts/run_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sh scripts/rpcs/start_all.sh $2 3 | echo "" 4 | echo "--------------------------------------------------------------------" 5 | 6 | if [[ "$1" = "all" ]]; then 7 | echo " Running all tests in \"test\" folder:" 8 | else 9 | echo " Running tests in path \"$3\"" 10 | fi 11 | 12 | echo "--------------------------------------------------------------------" 13 | 14 | if [[ "$1" = "all" ]]; then 15 | ./node_modules/.bin/ts-mocha --require source-map-support/register \ 16 | --full-trace \ 17 | --colors \ 18 | --paths -p ./ test/*/*.ts test/*.ts 19 | 20 | else 21 | ./node_modules/.bin/ts-mocha --require source-map-support/register \ 22 | --full-trace \ 23 | --colors \ 24 | --paths -p ./ $3 25 | fi 26 | 27 | echo "--------------------------------------------------------------------" 28 | echo "" 29 | sh scripts/rpcs/stop_all.sh $2 30 | echo "" 31 | -------------------------------------------------------------------------------- /scripts/testOutputToHtml.sh: -------------------------------------------------------------------------------- 1 | time npm run test > output/test.log && aha --black -f output/test.log > output/test.html -------------------------------------------------------------------------------- /src/blockchain/ethereum/account-utils.ts: -------------------------------------------------------------------------------- 1 | import { GenericAccountUtils } from "../../core/account-utils"; 2 | import { BigNumber } from "bignumber.js"; 3 | const EthereumUtil = require('ethereumjs-util'); 4 | 5 | export class EthereumAccountUtils extends GenericAccountUtils { 6 | 7 | /** 8 | * Determines whether string is a valid checksummed address 9 | * @param key 10 | * @returns true if valid checksum address, false if not 11 | */ 12 | public isValidChecksumAddress( key: string ): boolean { 13 | this.requireType(key, "string", "isValidChecksumAddress"); 14 | return EthereumUtil.isValidChecksumAddress(key); 15 | } 16 | 17 | /** 18 | * Converts an address to a checksummed address 19 | * @param key 20 | * @returns checksumed address 21 | */ 22 | public toChecksumAddress( key: string ): string { 23 | this.requireType(key, "string", "toChecksumAddress"); 24 | return EthereumUtil.toChecksumAddress(key); 25 | } 26 | 27 | /** 28 | * Determines whether buffer contains a valid address 29 | * @param key 30 | * @returns true if valid address, false if not 31 | */ 32 | public isValidAddress( key: Buffer ): boolean { 33 | this.requireType(key, "Buffer", "isValidAddress"); 34 | let address = key.toString('hex'); 35 | 36 | if (address.indexOf('0x') !== 0) { 37 | address = '0x' + address; 38 | } 39 | return EthereumUtil.isValidAddress(address); 40 | } 41 | 42 | /** 43 | * Determines whether buffer contains a valid private key 44 | * @param key 45 | * @returns true if valid private, false if not 46 | */ 47 | public isValidPrivate( key: Buffer ): boolean { 48 | this.requireType(key, "Buffer", "isValidPrivate"); 49 | 50 | let privateKey = key.toString(); 51 | if (privateKey.length === 66) { 52 | privateKey = privateKey.replace("0x", ""); 53 | } 54 | return !!privateKey.match(/^[0-9a-fA-F]{64}$/); 55 | } 56 | 57 | /** 58 | * Determines whether buffer contains a valid public key 59 | * @param key 60 | * @returns true if valid public, false if not 61 | */ 62 | public isValidPublic( key: Buffer ): boolean { 63 | this.requireType(key, "Buffer", "isValidPublic"); 64 | return EthereumUtil.isValidPublic( key ); 65 | } 66 | 67 | /** 68 | * Converts a public key to address 69 | * @param key 70 | * @returns address 71 | */ 72 | public publicToAddress( key: Buffer ): Buffer { 73 | this.requireType(key, "Buffer", "publicToAddress"); 74 | return EthereumUtil.pubToAddress(key); 75 | } 76 | 77 | /** 78 | * Converts a private key to public key 79 | * @param privateKey 80 | * @returns public key 81 | */ 82 | public privateToPublic( privateKey: Buffer ): Buffer { 83 | this.requireType(privateKey, "Buffer", "privateToPublic"); 84 | return EthereumUtil.privateToPublic(privateKey); 85 | } 86 | 87 | /** 88 | * Converts a private key to address 89 | * @param privateKey 90 | * @returns address 91 | */ 92 | public privateToAddress( privateKey: Buffer ): Buffer { 93 | this.requireType(privateKey, "Buffer", "privateToAddress"); 94 | return EthereumUtil.privateToAddress(privateKey); 95 | } 96 | 97 | /** 98 | * Converts an address buffer to a checksummed address string 99 | * @param key 100 | * @returns checksumed address 101 | */ 102 | public addressBufferToChecksum( key: Buffer ): string { 103 | this.requireType(key, "Buffer", "addressBufferToChecksum"); 104 | if ( key.length === 20 || key.length === 22 ) { 105 | return this.toChecksumAddress( key.toString("hex") ); 106 | } 107 | throw new Error("address buffer length is invalid"); 108 | } 109 | 110 | /** 111 | * Converts a buffer to a hex string 112 | * @param buf 113 | * @returns string 114 | */ 115 | public bufferToHex( buf: Buffer ): string { 116 | this.requireType(buf, "Buffer", "bufferToHex"); 117 | return '0x' + buf.toString('hex'); 118 | } 119 | 120 | /** 121 | * Converts a balance to it's lowest denominator 122 | * @param input 123 | * @returns string 124 | */ 125 | public balanceToStd( input: BigNumber ): string { 126 | this.requireType(input, "BigNumber", "balanceToStd"); 127 | return input.div(10 ** 18).toString(); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/blockchain/ethereum/class.index.ts: -------------------------------------------------------------------------------- 1 | import { IBlockchainImplementation } from "../../core/blockchain-implementation"; 2 | 3 | import { EthereumAccount } from "./account"; 4 | import { EthereumNode } from "./node"; 5 | import { EthereumTransaction } from "./transaction"; 6 | 7 | import config from "./config"; 8 | import networks from "./networks"; 9 | import { EthereumAccountUtils } from "./account-utils"; 10 | 11 | const AvailableClasses = { 12 | EthereumAccount, 13 | EthereumNode, 14 | EthereumTransaction, 15 | EthereumAccountUtils 16 | }; 17 | 18 | export const Ethereum: IBlockchainImplementation = { 19 | AvailableClasses, 20 | config, 21 | networks, 22 | }; 23 | 24 | export default Ethereum; 25 | -------------------------------------------------------------------------------- /src/blockchain/ethereum/config.ts: -------------------------------------------------------------------------------- 1 | import { Blockchain } from './../../core/blockchain'; 2 | import { IBlockchainConfig } from '../../core/blockchain-config'; 3 | 4 | export const EthereumConfig: IBlockchainConfig = { 5 | blockchain: Blockchain.ETHEREUM, 6 | mainCoin: "ETH", 7 | units: { 8 | wei: 18, 9 | kwei: 15, 10 | mwei: 12, 11 | gwei: 9, 12 | szabo: 6, 13 | finney: 3, 14 | ether: 0, 15 | kether: -3, 16 | mether: -6, 17 | gether: -9, 18 | tether: -12, 19 | }, 20 | unitsExtra: { 21 | ada: 15, 22 | femtoether: 15, 23 | babbage: 12, 24 | picoether: 12, 25 | nano: 9, 26 | shannon: 9, 27 | nanoether: 9, 28 | microether: 6, 29 | micro: 6, 30 | milliether: 3, 31 | milli: 3, 32 | grand: -3, 33 | einstein: -3, 34 | }, 35 | }; 36 | 37 | export default EthereumConfig; 38 | -------------------------------------------------------------------------------- /src/blockchain/ethereum/networks.ts: -------------------------------------------------------------------------------- 1 | import { Blockchain } from '../../core/blockchain'; 2 | import { Network } from '../../core/network'; 3 | 4 | const networks: Network[] = [ 5 | { 6 | network_id: 0, 7 | name: "Main Network", 8 | chainId: 1, 9 | blockchain: Blockchain.ETHEREUM, 10 | mainNet: true, 11 | explorerTxPattern: "https://etherscan.io/tx/0x{txn}", 12 | explorerAccountPattern: "https://etherscan.io/address/0x{addr}", 13 | url: "https://mainnet.infura.io/v3/1fc164b9a9054e4bab0f54e3d8d312b8", 14 | HDCoinValue: 60, // 60 = Ethereum Main Network! 15 | }, 16 | { 17 | network_id: 1, 18 | name: "Ropsten", 19 | chainId: 3, 20 | blockchain: Blockchain.ETHEREUM, 21 | mainNet: false, 22 | explorerTxPattern: "https://ropsten.etherscan.io/tx/0x{txn}", 23 | explorerAccountPattern: "https://ropsten.etherscan.io/address/0x{addr}", 24 | url: "https://ropsten.infura.io/v3/1fc164b9a9054e4bab0f54e3d8d312b8", 25 | HDCoinValue: 1, // Test Net 26 | }, 27 | { 28 | network_id: 2, 29 | name: "Rinkeby", 30 | chainId: 4, 31 | blockchain: Blockchain.ETHEREUM, 32 | mainNet: false, 33 | explorerTxPattern: "https://rinkeby.etherscan.io/tx/0x{txn}", 34 | explorerAccountPattern: "https://rinkeby.etherscan.io/address/0x{addr}", 35 | url: "https://rinkeby.infura.io/v3/1fc164b9a9054e4bab0f54e3d8d312b8", 36 | HDCoinValue: 1, // Test Net 37 | }, 38 | { 39 | network_id: 3, 40 | name: "Kovan", 41 | chainId: 42, 42 | blockchain: Blockchain.ETHEREUM, 43 | mainNet: false, 44 | explorerTxPattern: "https://kovan.etherscan.io/tx/0x{txn}", 45 | explorerAccountPattern: "https://kovan.etherscan.io/address/0x{addr}", 46 | url: "https://kovan.infura.io/v3/1fc164b9a9054e4bab0f54e3d8d312b8", 47 | HDCoinValue: 1, // Test Net 48 | }, 49 | { 50 | network_id: 4, 51 | name: "Ganache - TestRPC", 52 | chainId: 15, 53 | blockchain: Blockchain.ETHEREUM, 54 | mainNet: false, 55 | url: "http://127.0.0.1:8545/", 56 | HDCoinValue: 60, // 60 since ganache wants to emulate Main Net 57 | }, 58 | ]; 59 | 60 | export default networks; 61 | -------------------------------------------------------------------------------- /src/blockchain/ethereum/node.ts: -------------------------------------------------------------------------------- 1 | import { GenericNode } from "../../core/node"; 2 | import { Network } from "../../core/network"; 3 | import networks from "./networks"; 4 | import { BigNumber } from 'bignumber.js'; 5 | import { EthereumTransaction } from "./transaction"; 6 | 7 | export class EthereumNode extends GenericNode { 8 | 9 | public static readonly NETWORKS: Network[] = networks; 10 | 11 | /** 12 | * Creates an instance of ethereum node. 13 | * @param [network] 14 | */ 15 | constructor(network?: Network) { 16 | super(); 17 | this.NETWORKS = networks; 18 | this.init(network); 19 | } 20 | 21 | /** 22 | * Gets balance 23 | * @param caddress 24 | * @returns balance 25 | */ 26 | public getBalance(caddress: string): Promise { 27 | return this.rpcCall("eth_getBalance", [ 28 | caddress, 29 | 'latest', 30 | ], "BigNumber") as Promise; 31 | } 32 | 33 | /** 34 | * Gets nonce 35 | * @param caddress 36 | * @returns nonce 37 | */ 38 | public getNonce(caddress: string): Promise { 39 | return this.rpcCall("eth_getTransactionCount", [ 40 | caddress, 41 | 'latest', 42 | ], "number") as Promise; 43 | } 44 | 45 | /** 46 | * Estimates gas 47 | * @param callArguments 48 | * @returns gas estimate 49 | */ 50 | public estimateGas(callArguments: any): Promise { 51 | return this.rpcCall("eth_estimateGas", [ 52 | callArguments, 53 | ], "number") as Promise; 54 | } 55 | 56 | /** 57 | * Gets transaction receipt 58 | * @param transaction 59 | * @returns transaction receipt 60 | */ 61 | public getTransactionReceipt(transaction: EthereumTransaction): Promise { 62 | return this.rpcCall("eth_getTransactionReceipt", [transaction.id], "raw").then(data => { 63 | return Promise.resolve( data ); 64 | }).catch(error => { 65 | return Promise.reject( error ); 66 | }); 67 | } 68 | 69 | /** 70 | * Sends a transaction to the current network 71 | * @param transaction 72 | * @returns result 73 | */ 74 | public send(transaction: EthereumTransaction): Promise { 75 | return this.sendRaw( "0x" + transaction.raw.toString("hex") ); 76 | } 77 | 78 | /** 79 | * Sends a raw transaction to the current network 80 | * @param data 81 | * @returns result 82 | */ 83 | public sendRaw(data: any): Promise { 84 | return this.rpcCall("eth_sendRawTransaction", [ data ], "raw") as Promise; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/blockchain/ethereum/transaction.ts: -------------------------------------------------------------------------------- 1 | import EthereumJsTx from 'ethereumjs-tx'; 2 | import { BigNumber } from 'bignumber.js'; 3 | import { TransactionStatus } from './../../core/transaction'; 4 | import { GenericTransaction, ITransactionOptions } from '../../core/transaction'; 5 | import { WalletEventEmitter, WalletEventType } from '../../core/wallet-event-emitter'; 6 | import { Blockchain } from '../../core/blockchain'; 7 | 8 | export interface IEthereumTransactionOptions extends ITransactionOptions { 9 | gasPrice: number; 10 | gasLimit: number; 11 | chainId: number; 12 | data?: Buffer; 13 | } 14 | 15 | export class EthereumTransaction extends GenericTransaction { 16 | public chainId: number; 17 | public gasPrice: number; 18 | public gasLimit: number; 19 | public usedGas: number; 20 | 21 | /** 22 | * Creates an instance of an ethereum transaction. 23 | * @param from 24 | * @param to 25 | * @param amount 26 | * @param nonce 27 | * @param options 28 | */ 29 | constructor(from: string, to: string, amount: string, nonce: number, options: IEthereumTransactionOptions) { 30 | super(from, to, amount, nonce, options); 31 | 32 | this.chainId = options.chainId; 33 | this.gasPrice = options.gasPrice; 34 | this.gasLimit = options.gasLimit; 35 | this.data = options.data || Buffer.from(""); 36 | } 37 | 38 | /** 39 | * Converts current transaction to a parameters object required for transaction signing 40 | * @returns parameters object 41 | */ 42 | public toParams() { 43 | return { 44 | nonce: this.getNumberToHex( this.nonce ) as any, 45 | gasPrice: this.getNumberToHex( this.gasPrice ), 46 | gasLimit: this.getNumberToHex( this.gasLimit ), 47 | to: this.to, 48 | value: this.getNumberToHex( new BigNumber(this.amount) ), 49 | data: "0x" + this.data, 50 | chainId: this.getNumberToHex( this.chainId ), 51 | 52 | v: this.getNumberToHex( this.chainId ), 53 | r: "0x00", 54 | s: "0x00" 55 | }; 56 | } 57 | 58 | public serialize() { 59 | const tx = new EthereumJsTx( this.toParams() ); 60 | return tx.serialize().toString('hex'); 61 | } 62 | 63 | public setLedgerSignResult(params) { 64 | 65 | const tx = new EthereumJsTx( Object.assign(this.toParams(), { 66 | r: '0x' + params.r, 67 | s: '0x' + params.s, 68 | v: '0x' + params.v 69 | }) ); 70 | this.setSignedResult(tx.serialize()); 71 | } 72 | 73 | public setTxn(data: any) { 74 | super.setTxn(data); 75 | if (data) { 76 | this.id = data; 77 | } 78 | } 79 | 80 | public updateData(data: any) { 81 | if (data.transactionHash.toLowerCase() === this.id.toLowerCase()) { 82 | let status = parseInt(data.status, 16); 83 | 84 | this.usedGas = parseInt(data.gasUsed, 16); 85 | this.setStatus(status === 1 ? TransactionStatus.SUCCESS : TransactionStatus.FAILED); 86 | 87 | WalletEventEmitter.emit(WalletEventType.TRANSACTION_UPDATE, { 88 | blockchain: Blockchain.ETHEREUM, 89 | address: this.from, 90 | transactionId: this.id, 91 | status: this.status 92 | }); 93 | 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/blockchain/zilliqa/class.index.ts: -------------------------------------------------------------------------------- 1 | import { ZilliqaAccountUtils } from './account-utils'; 2 | import { ZilliqaAccount } from "./account"; 3 | import { ZilliqaNode } from "./node"; 4 | import { ZilliqaTransaction } from "./transaction"; 5 | 6 | import config from "./config"; 7 | import networks from "./networks"; 8 | import { IBlockchainImplementation } from "../../core/blockchain-implementation"; 9 | 10 | const AvailableClasses = { 11 | ZilliqaAccount, 12 | ZilliqaNode, 13 | ZilliqaTransaction, 14 | ZilliqaAccountUtils 15 | }; 16 | 17 | export const Zilliqa: IBlockchainImplementation = { 18 | AvailableClasses, 19 | config, 20 | networks, 21 | }; 22 | 23 | export default Zilliqa; 24 | -------------------------------------------------------------------------------- /src/blockchain/zilliqa/config.ts: -------------------------------------------------------------------------------- 1 | import { Blockchain } from './../../core/blockchain'; 2 | import { IBlockchainConfig } from '../../core/blockchain-config'; 3 | 4 | export const ZilliqaConfig: IBlockchainConfig = { 5 | blockchain: Blockchain.ZILLIQA, 6 | mainCoin: "ZIL", 7 | }; 8 | 9 | export default ZilliqaConfig; 10 | -------------------------------------------------------------------------------- /src/blockchain/zilliqa/networks.ts: -------------------------------------------------------------------------------- 1 | import { Blockchain } from '../../core/blockchain'; 2 | import { Network } from '../../core/network'; 3 | 4 | const networks: Network[] = [ 5 | { 6 | network_id: 0, 7 | name: "Main Network", 8 | chainId: 1, 9 | blockchain: Blockchain.ZILLIQA, 10 | mainNet: true, 11 | url: "https://api.zilliqa.com/", 12 | explorerTxPattern: "https://viewblock.io/zilliqa/tx/0x{txn}", 13 | explorerAccountPattern: 'https://viewblock.io/zilliqa/address/{addr}', 14 | HDCoinValue: 313, 15 | }, 16 | { 17 | network_id: 1, 18 | name: "Dev", 19 | chainId: 333, 20 | blockchain: Blockchain.ZILLIQA, 21 | mainNet: false, 22 | url: "https://dev-api.zilliqa.com/", 23 | explorerTxPattern: "https://viewblock.io/zilliqa/tx/0x{txn}?network=testnet", 24 | explorerAccountPattern: 'https://viewblock.io/zilliqa/address/{addr}?network=testnet', 25 | HDCoinValue: 1, // testnet 26 | }, 27 | { 28 | network_id: 2, 29 | name: "Kaya - TestRPC", 30 | chainId: 2, 31 | blockchain: Blockchain.ZILLIQA, 32 | mainNet: false, 33 | url: "http://127.0.0.1:4200/", 34 | HDCoinValue: 1, // Test Net 35 | }, 36 | ]; 37 | 38 | export default networks; 39 | -------------------------------------------------------------------------------- /src/blockchain/zilliqa/node.ts: -------------------------------------------------------------------------------- 1 | import { GenericNode } from "../../core/node"; 2 | import { Network } from "../../core/network"; 3 | import networks from "./networks"; 4 | import { BigNumber } from 'bignumber.js'; 5 | import { ZilliqaTransaction } from "./transaction"; 6 | import * as ZilliqaJsCrypto from "@zilliqa-js/crypto/dist/util"; 7 | 8 | import { fromBech32Address, toBech32Address } from "@zilliqa-js/crypto/dist/bech32" 9 | 10 | export class ZilliqaNode extends GenericNode { 11 | 12 | public static readonly NETWORKS: Network[] = networks; 13 | 14 | /** 15 | * Creates an instance of zilliqa node. 16 | * @param [network] 17 | */ 18 | constructor(network?: Network) { 19 | super(); 20 | this.NETWORKS = networks; 21 | this.init(network); 22 | } 23 | 24 | /** 25 | * Gets balance 26 | * @param caddress 27 | * @returns balance 28 | */ 29 | public getBalance(caddress: string): Promise { 30 | const call = this.rpcCall("GetBalance", [ fromBech32Address(caddress).replace("0x", "").toLowerCase() ], "") as Promise; 31 | return call.then( (data) => { 32 | return new BigNumber( data.balance ); 33 | }).catch( (error) => { 34 | if (error.message === "Account is not created") { 35 | return Promise.resolve(new BigNumber(0)); 36 | } 37 | return Promise.reject( new Error(error) ); 38 | }); 39 | } 40 | 41 | /** 42 | * Gets nonce 43 | * @param caddress 44 | * @returns nonce 45 | */ 46 | public getNonce(caddress: string): Promise { 47 | const call = this.rpcCall("GetBalance", [ fromBech32Address(caddress).replace("0x", "").toLowerCase() ], "") as Promise; 48 | return call.then( (data) => { 49 | return data.nonce; 50 | }).catch( (error) => { 51 | if (error.message === "Account is not created") { 52 | return Promise.resolve(0); 53 | } 54 | return Promise.reject( new Error(error) ); 55 | }); 56 | } 57 | 58 | /** 59 | * Estimates gas 60 | * @param callArguments 61 | * @returns gas estimate 62 | */ 63 | public estimateGas(callArguments: any): Promise { 64 | throw new Error("Method not implemented."); 65 | /* 66 | // https://github.com/Zilliqa/Zilliqa/blob/db0 0328e78364c5ae6049f483d8f5bc696027d79/src/libServer/Server.cpp#L580 67 | // not implemented yet.. returns "Hello" 68 | return this.rpcCall("GetGasEstimate", [ 69 | callArguments, 70 | ], "number") as Promise; 71 | */ 72 | } 73 | 74 | /** 75 | * Gets transaction receipt 76 | * @param transaction 77 | * @returns transaction receipt 78 | */ 79 | public getTransactionReceipt(transaction: ZilliqaTransaction): Promise { 80 | if (transaction.id) { 81 | return this.rpcCall("GetTransaction", [ transaction.id.replace("0x", "").toLowerCase() ], "").then(data => { 82 | data.toAddr = toBech32Address(data.toAddr); 83 | return data; 84 | }) as Promise; 85 | } else { 86 | return Promise.reject('No transaction id available.'); 87 | } 88 | } 89 | 90 | /** 91 | * Sends a transaction to the current network 92 | * @param transaction 93 | * @returns result 94 | */ 95 | public send(transaction: ZilliqaTransaction): Promise { 96 | 97 | // cast properties as expected by Zilliqa Nodes. 98 | const SendObject = transaction.TXObject; 99 | SendObject.amount = SendObject.amount.toString(); 100 | SendObject.gasPrice = SendObject.gasPrice.toString(); 101 | SendObject.gasLimit = SendObject.gasLimit.toString(); 102 | 103 | // remove once core accepts 0x 104 | SendObject.toAddr = ZilliqaJsCrypto.toChecksumAddress( SendObject.toAddr ).replace("0x", ""); 105 | 106 | return this.sendRaw(SendObject); 107 | } 108 | 109 | /** 110 | * Sends a raw transaction to the current network 111 | * @param data 112 | * @returns result 113 | */ 114 | public sendRaw(data: any): Promise { 115 | return this.rpcCall("CreateTransaction", [data], "raw") as Promise; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/class.store.ts: -------------------------------------------------------------------------------- 1 | import { GenericNode } from "./core/node"; 2 | 3 | export default class DynamicClass { 4 | public classStore: any = [ 5 | GenericNode, 6 | ]; 7 | 8 | /** 9 | * Collects and index classes so we can instantiate them later 10 | * @param object 11 | */ 12 | public collectClasses( object: any ) { 13 | for ( const name in object ) { 14 | if ( object[name] ) { 15 | this.classStore[name] = object[name]; 16 | } 17 | } 18 | } 19 | 20 | /** 21 | * Gets a class instance for supplied name and options 22 | * @param className 23 | * @param [opts] 24 | * @returns supplied class instance 25 | */ 26 | public getInstance(className: string, opts?: any) { 27 | if (this.classStore[className] === undefined || this.classStore[className] === null) { 28 | throw new Error(`Class type of \'${className}\' is not loaded.`); 29 | } 30 | 31 | if ( opts === undefined ) { 32 | return new this.classStore[className](); 33 | } else if (typeof opts === "object" ) { 34 | if ( opts[0] !== undefined ) { 35 | return new this.classStore[className](...opts); 36 | } else { 37 | return new this.classStore[className](opts); 38 | } 39 | } else { 40 | throw new Error(`Class type of \'${className}\' is not loaded.`); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/core/account-utils.ts: -------------------------------------------------------------------------------- 1 | import { BigNumber } from "bignumber.js"; 2 | 3 | export abstract class GenericAccountUtils { 4 | 5 | public static getImplementedClassName(name: string) { 6 | name = name.toLowerCase(); 7 | return name.charAt(0).toUpperCase() + name.slice(1) + "AccountUtils"; 8 | } 9 | 10 | /** 11 | * Parameter type validation 12 | * @param target 13 | * @param expected 14 | * @param method 15 | * @returns true if type matches 16 | */ 17 | public requireType( target: any, expected: string, method: string ): boolean { 18 | if ( expected === "Buffer") { 19 | if ( !Buffer.isBuffer( target ) ) { 20 | throw new Error(method + ": parameter must be a Buffer()."); 21 | } 22 | } else if ( expected === "BigNumber") { 23 | if ( !BigNumber.isBigNumber( target ) ) { 24 | throw new Error(method + ": parameter must be of type BigNumber."); 25 | } 26 | } else if ( typeof target !== expected ) { 27 | if ( target.constructor.name !== expected) { 28 | throw new Error(method + ": parameter must be of type " + expected + "."); 29 | } 30 | } 31 | return true; 32 | } 33 | 34 | /** 35 | * Determines whether string is a valid checksummed address 36 | * @param key 37 | * @returns true if valid checksum address, false if not 38 | */ 39 | public abstract isValidChecksumAddress( key: string ): boolean; 40 | 41 | /** 42 | * Converts an address to a checksummed address 43 | * @param key 44 | * @returns checksumed address 45 | */ 46 | public abstract toChecksumAddress( key: string ): string; 47 | 48 | /** 49 | * Determines whether buffer contains a valid address 50 | * @param key 51 | * @returns true if valid address, false if not 52 | */ 53 | public abstract isValidAddress( key: Buffer ): boolean; 54 | 55 | /** 56 | * Determines whether buffer contains a valid private key 57 | * @param key 58 | * @returns true if valid private, false if not 59 | */ 60 | public abstract isValidPrivate( key: Buffer ): boolean; 61 | 62 | /** 63 | * Determines whether buffer contains a valid public key 64 | * @param key 65 | * @returns true if valid public, false if not 66 | */ 67 | public abstract isValidPublic( key: Buffer ): boolean; 68 | 69 | /** 70 | * Converts a public key to address 71 | * @param key 72 | * @returns address 73 | */ 74 | public abstract publicToAddress( key: Buffer ): Buffer; 75 | 76 | /** 77 | * Converts a private key to public key 78 | * @param privateKey 79 | * @returns public key 80 | */ 81 | public abstract privateToPublic( privateKey: Buffer ): Buffer; 82 | 83 | /** 84 | * Converts a private key to address 85 | * @param privateKey 86 | * @returns address 87 | */ 88 | public abstract privateToAddress( privateKey: Buffer ): Buffer; 89 | 90 | /** 91 | * Converts an address buffer to a checksummed address string 92 | * @param key 93 | * @returns checksumed address 94 | */ 95 | public abstract addressBufferToChecksum( key: Buffer ): string; 96 | 97 | /** 98 | * Converts a buffer to a hex string 99 | * @param buf 100 | * @returns string 101 | */ 102 | public abstract bufferToHex( buf: Buffer): string; 103 | 104 | /** 105 | * Converts a balance to it's lowest denominator 106 | * @param input 107 | * @returns string 108 | */ 109 | public abstract balanceToStd( input: number | string | BigNumber): string; 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/core/blockchain-config.ts: -------------------------------------------------------------------------------- 1 | import { Blockchain } from './blockchain'; 2 | export interface IBlockchainConfig { 3 | blockchain: Blockchain; 4 | mainCoin: string; 5 | units?: { 6 | [unit: string]: number, 7 | }; 8 | unitsExtra?: { 9 | [unit: string]: number, 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /src/core/blockchain-implementation.ts: -------------------------------------------------------------------------------- 1 | import { IBlockchainConfig } from "./blockchain-config"; 2 | import { Network } from "./network"; 3 | 4 | export interface IBlockchainImplementation { 5 | AvailableClasses: { 6 | [className: string]: any, 7 | }; 8 | config: IBlockchainConfig; 9 | networks: Network[]; 10 | } 11 | -------------------------------------------------------------------------------- /src/core/blockchain.ts: -------------------------------------------------------------------------------- 1 | export enum Blockchain { 2 | ETHEREUM = "ETHEREUM", 3 | ZILLIQA = "ZILLIQA", 4 | } 5 | -------------------------------------------------------------------------------- /src/core/network.ts: -------------------------------------------------------------------------------- 1 | import { Blockchain } from "./blockchain"; 2 | 3 | export interface Network { 4 | network_id: number; 5 | blockchain: Blockchain; 6 | chainId: number; 7 | name: string; 8 | url: string; 9 | mainNet: boolean; 10 | explorerTxPattern?: string; 11 | explorerAccountPattern?: string; 12 | HDCoinValue: number; 13 | } 14 | -------------------------------------------------------------------------------- /src/core/transaction.ts: -------------------------------------------------------------------------------- 1 | import { BigNumber } from 'bignumber.js'; 2 | import { ITransactionOptions } from './transaction'; 3 | 4 | export interface ITransactionOptions { 5 | // 6 | } 7 | 8 | export enum TransactionStatus { 9 | CREATED = "CREATED", 10 | SIGNED = "SIGNED", 11 | SUBMITTED = "SUBMITTED", 12 | PENDING = "PENDING", 13 | SUCCESS = "SUCCESS", 14 | FAILED = "FAILED" 15 | } 16 | 17 | export abstract class GenericTransaction { 18 | 19 | public static getImplementedClassName(name: string) { 20 | name = name.toLowerCase(); 21 | return name.charAt(0).toUpperCase() + name.slice(1) + "Transaction"; 22 | } 23 | 24 | public id: string = ""; 25 | public from: string; 26 | public to: string; 27 | public nonce: number; 28 | public amount: string; 29 | public options: TO; 30 | public data: Buffer; 31 | 32 | // public receipt: any; 33 | public raw: Buffer = Buffer.from(""); 34 | public status: TransactionStatus = TransactionStatus.CREATED; 35 | public times: any = []; 36 | 37 | constructor(from: string, to: string, amount: string, nonce: number, options: TO) { 38 | this.from = from; 39 | this.to = to; 40 | this.nonce = nonce; 41 | this.options = options; 42 | this.amount = amount; 43 | 44 | this.addTime(TransactionStatus.CREATED); 45 | } 46 | 47 | /** 48 | * Sets transaction status to signed, adds raw data and indexes event 49 | * @param data 50 | */ 51 | public setSignedResult( data: Buffer ) { 52 | this.addTime(TransactionStatus.SIGNED); 53 | this.status = TransactionStatus.SIGNED; 54 | this.raw = data; 55 | } 56 | 57 | /** 58 | * Sets transaction status to pending and indexes event 59 | * @param data 60 | */ 61 | public setPending() { 62 | this.addTime(TransactionStatus.PENDING); 63 | this.status = TransactionStatus.PENDING; 64 | } 65 | 66 | public setStatus(status: TransactionStatus) { 67 | this.addTime(status); 68 | this.status = status; 69 | }; 70 | 71 | /** 72 | * Sets transaction status to final, adds txn and indexes event 73 | * @param data 74 | */ 75 | public setTxn( txn: string ) { 76 | this.addTime(TransactionStatus.SUBMITTED); 77 | this.status = TransactionStatus.PENDING; 78 | } 79 | 80 | /** 81 | * Converts number to hex string 82 | * @param num 83 | * @returns hex representation 84 | */ 85 | public getNumberToHex( num: number | BigNumber ): string { 86 | return "0x" + num.toString(16); 87 | } 88 | 89 | /** 90 | * Adds time to current event 91 | * @param eventName 92 | */ 93 | public addTime(eventName: string) { 94 | this.times.push({ 95 | name: eventName, 96 | unixtime: Math.round((new Date()).getTime() / 1000), 97 | }); 98 | } 99 | 100 | /** 101 | * Converts current transaction to a parameters object required for transaction signing 102 | * @returns parameters object 103 | */ 104 | public abstract toParams(); 105 | 106 | public abstract updateData(data: any); 107 | public abstract serialize(); 108 | public abstract setLedgerSignResult(params); 109 | } 110 | -------------------------------------------------------------------------------- /src/core/transactions-tracker.ts: -------------------------------------------------------------------------------- 1 | import { GenericTransaction, TransactionStatus } from './transaction'; 2 | 3 | import { GenericAccount } from "./account"; 4 | 5 | export class TransactionTracker { 6 | private static timeoutRef; 7 | private static readonly TIME_INTERVAL = 30000; // 30 sec 8 | private static transactions: {account: GenericAccount, transaction: GenericTransaction}[] = []; 9 | 10 | static register(account: GenericAccount, transaction: GenericTransaction) { 11 | if (transaction.status !== TransactionStatus.SUCCESS && transaction.status !== TransactionStatus.FAILED) { 12 | TransactionTracker.transactions.push({account, transaction}); 13 | TransactionTracker.run(); 14 | } 15 | } 16 | 17 | static stop() { 18 | if (TransactionTracker.timeoutRef) { 19 | clearTimeout(TransactionTracker.timeoutRef); 20 | TransactionTracker.timeoutRef = undefined; 21 | } 22 | } 23 | 24 | static run(interval?: number) { 25 | TransactionTracker.stop(); 26 | TransactionTracker.timeoutRef = setTimeout(() => { 27 | TransactionTracker.transactions.map(async (tx) => { 28 | try { 29 | if (tx.transaction.status !== TransactionStatus.SUCCESS && tx.transaction.status !== TransactionStatus.FAILED) { 30 | let receipt = await tx.account.node.getTransactionReceipt(tx.transaction); 31 | //console.log(receipt); 32 | tx.transaction.updateData(receipt); 33 | } else { 34 | let index = TransactionTracker.transactions.indexOf(tx); 35 | TransactionTracker.transactions.splice(index, 1); 36 | } 37 | } catch { 38 | // TODO handle errors 39 | } 40 | }); 41 | 42 | if (TransactionTracker.transactions.length > 0) { 43 | TransactionTracker.run(); 44 | } else { 45 | TransactionTracker.stop(); 46 | } 47 | }, interval || TransactionTracker.TIME_INTERVAL); 48 | } 49 | } -------------------------------------------------------------------------------- /src/core/utils/hdkey.ts: -------------------------------------------------------------------------------- 1 | const npmhdkeyobject = require("hdkey"); 2 | 3 | export default class HDKey { 4 | 5 | public static fromHDKey( npmhdkey: HDKey ): HDKey { 6 | const ret = new HDKey(); 7 | ret.npmhdkey = npmhdkey; 8 | return ret; 9 | } 10 | 11 | public static fromMasterSeed( seedBuffer: Buffer ): HDKey { 12 | return HDKey.fromHDKey( npmhdkeyobject.fromMasterSeed( seedBuffer ) ); 13 | } 14 | 15 | public npmhdkey: any; 16 | 17 | public derivePath( path: any ): HDKey { 18 | return HDKey.fromHDKey( this.npmhdkey.derive(path) ); 19 | } 20 | 21 | public deriveChild( index: any ): HDKey { 22 | return HDKey.fromHDKey( this.npmhdkey.deriveChild(index) ); 23 | } 24 | 25 | public getPrivateKey(): Buffer { 26 | return this.npmhdkey._privateKey; 27 | } 28 | 29 | public getPrivateKeyString(): string { 30 | return this.npmhdkey._privateKey.toString("hex"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/core/utils/mnemonic.ts: -------------------------------------------------------------------------------- 1 | import * as bip from "bip39"; 2 | 3 | interface WordListItem { 4 | [key: string]: string[]; 5 | } 6 | 7 | export default class Mnemonic { 8 | 9 | public static getAvailableWordLists(): WordListItem { 10 | return bip.wordlists; 11 | } 12 | 13 | public static generateMnemonic(language?: string ): string { 14 | language = language || "EN"; 15 | const wordlists = Mnemonic.getAvailableWordLists(); 16 | 17 | if ( Object.keys(wordlists).find(k => k === language) ) { 18 | return bip.generateMnemonic(undefined, undefined, wordlists[language as any]); 19 | } 20 | 21 | throw new Error("Mnemonics language '" + language + "' is not supported."); 22 | } 23 | 24 | public static mnemonicToSeed(mnemonic: string, language?: string, password?: string): Buffer { 25 | language = language || "EN"; 26 | const wordlists = Mnemonic.getAvailableWordLists(); 27 | 28 | if ( bip.validateMnemonic(mnemonic, wordlists[language as any]) ) { 29 | return bip.mnemonicToSeed (mnemonic, password); 30 | } 31 | throw new Error("Invalid Mnemonic."); 32 | } 33 | 34 | public static getWordsFromMnemonic(mnemonic: string, language?: string): string[] { 35 | const JPSeparator = '\u3000'; 36 | language = language || "EN"; 37 | if ( language === "JP" || language === "JA") { 38 | return mnemonic.split( JPSeparator ); 39 | } else { 40 | return mnemonic.split( " " ); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/core/wallet-event-emitter.ts: -------------------------------------------------------------------------------- 1 | import { TransactionStatus } from './transaction'; 2 | import { Blockchain } from './blockchain'; 3 | export enum WalletEventType { 4 | TRANSACTION_UPDATE = 'TRANSACTION_UPDATE' 5 | } 6 | 7 | export type WalletEventData = IWalletTransactionUpdate; 8 | 9 | export interface IWalletTransactionUpdate { 10 | blockchain: Blockchain, 11 | address: string, 12 | transactionId: string, 13 | status: TransactionStatus 14 | } 15 | 16 | export class WalletEventEmitter { 17 | private static subscribers = []; 18 | 19 | static emit(type: WalletEventType, data?: WalletEventData) { 20 | setTimeout(() => 21 | WalletEventEmitter.subscribers.map(callback => { 22 | if (typeof callback === 'function') { 23 | callback(type, data); 24 | } 25 | }) 26 | ); 27 | }; 28 | 29 | static subscribe(callback: (type: WalletEventType, data: WalletEventData) => any): () => any { 30 | if (typeof callback === 'function') { 31 | WalletEventEmitter.subscribers.push(callback); 32 | } 33 | 34 | return () => { 35 | WalletEventEmitter.subscribers.splice(WalletEventEmitter.subscribers.indexOf(callback), 1); 36 | } 37 | }; 38 | } -------------------------------------------------------------------------------- /src/globals.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'bip39'; 2 | declare module 'hdkey'; 3 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import Wallet from "./core/wallet"; 2 | import { Blockchain as Blockchains } from "./core/blockchain"; 3 | import { AccountType } from "./core/account"; 4 | import MnemonicUtils from "./core/utils/mnemonic"; 5 | 6 | export { 7 | Wallet, 8 | Blockchains, 9 | AccountType, 10 | MnemonicUtils, 11 | }; 12 | -------------------------------------------------------------------------------- /test.ts: -------------------------------------------------------------------------------- 1 | import { WalletEventEmitter, WalletEventType, WalletEventData } from './src/core/wallet-event-emitter'; 2 | import { TransactionTracker } from './src/core/transactions-tracker'; 3 | import { ZilliqaTransaction } from './src/blockchain/zilliqa/transaction'; 4 | import { Ethereum } from './src/blockchain/ethereum/class.index'; 5 | import Wallet from './src/core/wallet'; 6 | import Zilliqa from './src/blockchain/zilliqa/class.index'; 7 | import { Blockchain } from './src/core/blockchain'; 8 | 9 | 10 | WalletEventEmitter.subscribe((type: WalletEventType, data: WalletEventData) => { 11 | console.log('Event', type, data); 12 | }); 13 | 14 | (async function () { 15 | 16 | 17 | const x = new Wallet('gadget clean certain tiger abandon prevent light pluck muscle obtain mobile agree'); 18 | x.loadBlockchain(Ethereum); 19 | x.loadBlockchain(Zilliqa); 20 | 21 | const eth = x.createAccount(Blockchain.ETHEREUM, 2); 22 | const eth2 = x.createAccount(Blockchain.ETHEREUM, 2); 23 | 24 | const zil = x.createAccount(Blockchain.ZILLIQA, 1); 25 | const zil2 = x.createAccount(Blockchain.ZILLIQA, 1); 26 | 27 | x.switchNetwork(Blockchain.ETHEREUM, 2); 28 | x.switchNetwork(Blockchain.ZILLIQA, 1); 29 | 30 | console.log(x.getBlockchain(Blockchain.ETHEREUM).getAccounts().map(a => a.address)); 31 | console.log(x.getBlockchain(Blockchain.ZILLIQA).getAccounts().map(a => a.address)); 32 | 33 | 34 | // const zilTx = zil.buildTransferTransaction( 35 | // zil2.address, 36 | // 1 * Math.pow(10, 12), 37 | // 21, 38 | // 1000000000, 39 | // 1 40 | // ); 41 | // zil.signTransaction(zilTx); 42 | // zil.send(zilTx); 43 | 44 | 45 | const ethTx = eth.buildTransferTransaction( 46 | eth2.address, 47 | 0.1 * Math.pow(10, 18), 48 | 9, 49 | 20 * Math.pow(10, 9), 50 | 21000 51 | ); 52 | eth.signTransaction(ethTx); 53 | eth.send(ethTx); 54 | })(); -------------------------------------------------------------------------------- /test/1_one_account.ts: -------------------------------------------------------------------------------- 1 | import { assert } from "chai"; 2 | import mocha from "mocha"; 3 | 4 | import { Wallet, Blockchains, AccountType, MnemonicUtils } from "../src/index"; 5 | import { GenericAccount } from "../src/core/account"; 6 | import { GenericNode } from "../src/core/node"; 7 | import { GenericTransaction } from "../src/core/transaction"; 8 | import { GenericAccountUtils } from "../src/core/account-utils"; 9 | import Ethereum from "../src/blockchain/ethereum/class.index"; 10 | import Zilliqa from "../src/blockchain/zilliqa/class.index"; 11 | 12 | const mnemonic = "exchange neither monster ethics bless cancel ghost excite business record warfare invite"; 13 | 14 | describe("Integration", async () => { 15 | 16 | describe("Wallet: constructed with parameters ( mnemonic, language = EN )", async () => { 17 | 18 | describe("create one Ethereum account", async () => { 19 | 20 | const defaultWallet: Wallet = new Wallet(mnemonic, "EN"); 21 | defaultWallet.loadBlockchain(Ethereum); 22 | defaultWallet.loadBlockchain(Zilliqa); 23 | const blockchain = Blockchains.ETHEREUM; 24 | const AccountClassTypeString = GenericAccount.getImplementedClassName( Blockchains[blockchain] ); 25 | const NodeClassTypeString = GenericNode.getImplementedClassName( Blockchains[blockchain] ); 26 | const account = defaultWallet.createAccount(blockchain); 27 | 28 | it("should create first account", async () => { 29 | 30 | const getAccount = defaultWallet.getAccounts(blockchain)[0]; 31 | const getIndex = defaultWallet.accounts.get(blockchain)[0]; 32 | 33 | assert.equal( getAccount.constructor.name, AccountClassTypeString, "class does not match expected" ); 34 | assert.equal( account, getAccount, "Accounts do not match" ); 35 | assert.equal( account, getIndex, "Accounts do not match" ); 36 | 37 | assert.equal( NodeClassTypeString, account.node.constructor.name, "class does not match expected" ); 38 | 39 | const HDKey = account.hd; 40 | assert.isNotNull( HDKey, "HDRootKey should not be null" ); 41 | assert.isTrue( account.utils.isValidPrivate( Buffer.from( account.privateKey ) ), "private key is invalid" ); 42 | assert.equal( HDKey.constructor.name, "HDKey", "HDKey class does not match expected" ); 43 | assert.equal( HDKey.npmhdkey.depth, 5, "HDKey depth does not match" ); 44 | assert.equal( HDKey.npmhdkey.index, 0, "HDKey index does not match" ); 45 | 46 | }); 47 | 48 | it("wallet should have 1 account", async () => { 49 | const getAccounts = defaultWallet.getAccounts(blockchain); 50 | assert.equal( getAccounts.length, 1, "getAccounts length does not match" ); 51 | }); 52 | }); 53 | 54 | }); 55 | 56 | }); 57 | -------------------------------------------------------------------------------- /test/core/class.store.ts: -------------------------------------------------------------------------------- 1 | import { assert } from "chai"; 2 | import mocha from "mocha"; 3 | import DynamicClass from "../../src/class.store"; 4 | 5 | describe("Core", async () => { 6 | 7 | describe("DynamicClass loader", async () => { 8 | 9 | describe("getInstance()", async () => { 10 | it("should fail silent on collect Classes", async () => { 11 | const classStore = new DynamicClass(); 12 | classStore.collectClasses({ 13 | ClassName: false, 14 | }); 15 | }); 16 | 17 | it("should throw if requested class name is not found in store", async () => { 18 | const classStore = new DynamicClass(); 19 | 20 | assert.throws(() => { 21 | // @ts-ignore: we're testing for this scenario 22 | classStore.getInstance("test", undefined); 23 | }, /^Class type of \'test\' is not loaded\.$/); 24 | 25 | }); 26 | }); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /test/core/hdkey.ts: -------------------------------------------------------------------------------- 1 | import { assert } from "chai"; 2 | import mocha from "mocha"; 3 | import HDKey from "../../src/core/utils/hdkey"; 4 | import { Wallet, Blockchains, AccountType, MnemonicUtils } from "../../src/index"; 5 | 6 | const mnemonic = "exchange neither monster ethics bless cancel ghost excite business record warfare invite"; 7 | const lang = "EN"; 8 | const seed = MnemonicUtils.mnemonicToSeed( mnemonic, lang ); 9 | const ethereumwallet0PrivateKey = "e49c840fcb71fafcaa068c7d45a6b99f8d5b6064effe7d793b6490641e75cca8"; 10 | 11 | describe("Core", async () => { 12 | 13 | describe("HDKey class", async () => { 14 | 15 | describe("getPrivateKey()", async () => { 16 | 17 | it("should properly return a Buffer containing the first private key derrivated from the provided seed", async () => { 18 | const hdkey = HDKey.fromMasterSeed(seed); 19 | const HDRootKey = hdkey.derivePath(`m/44'/60'/0'/0`); 20 | const AccountHDKey = HDRootKey.deriveChild( 0 ); 21 | const PrivateKey = AccountHDKey.getPrivateKey(); 22 | assert.equal( PrivateKey.toString("hex"), ethereumwallet0PrivateKey, "Did not return the expected private key"); 23 | }); 24 | 25 | }); 26 | 27 | describe("getPrivateKeyString()", async () => { 28 | 29 | it("should properly return a string containing the first private key derrivated from the provided seed", async () => { 30 | const hdkey = HDKey.fromMasterSeed(seed); 31 | const HDRootKey = hdkey.derivePath(`m/44'/60'/0'/0`); 32 | const AccountHDKey = HDRootKey.deriveChild( 0 ); 33 | const PrivateKey = AccountHDKey.getPrivateKeyString(); 34 | assert.equal( PrivateKey, ethereumwallet0PrivateKey, "Did not return the expected private key"); 35 | }); 36 | 37 | }); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /test/core/mnemonics.ts: -------------------------------------------------------------------------------- 1 | import { assert } from "chai"; 2 | import mocha from "mocha"; 3 | import { Wallet, Blockchains, AccountType, MnemonicUtils } from "../../src/index"; 4 | 5 | describe("Core", async () => { 6 | 7 | describe("MnemonicUtils class", async () => { 8 | 9 | describe("getWordsFromMnemonic()", async () => { 10 | 11 | it("should properly split 12 words for 'EN' language", async () => { 12 | const words = MnemonicUtils.getWordsFromMnemonic( "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", "EN" ); 13 | assert.equal( words.length, 12, "Did not return 12 words in an array"); 14 | }); 15 | 16 | // JA is using '\u3000' as a separator instead of a '\u0020' 17 | it("should properly split 12 words for 'JA' language", async () => { 18 | const words = MnemonicUtils.getWordsFromMnemonic( 'ようじ てんめつ いだく こうりつ けいさつ てはい せつりつ ぐこう えしゃく かんたん ごうほう けんにん', "JA" ); 19 | assert.equal( words.length, 12, "Did not return 12 words in an array"); 20 | }); 21 | 22 | }); 23 | 24 | describe("generateMnemonic()", async () => { 25 | 26 | it("should properly generate a 12 words mnemonic phrase for 'EN' language", async () => { 27 | const lang = "EN"; 28 | const mnemonic = MnemonicUtils.generateMnemonic(lang); 29 | const words = MnemonicUtils.getWordsFromMnemonic( mnemonic, lang ); 30 | assert.equal( words.length, 12, "Did not return 12 words in an array"); 31 | }); 32 | 33 | it("should properly generate a 12 words mnemonic phrase for 'chinese_simplified' language", async () => { 34 | const lang = "chinese_simplified"; 35 | const mnemonic = MnemonicUtils.generateMnemonic(lang); 36 | const words = MnemonicUtils.getWordsFromMnemonic( mnemonic, lang ); 37 | assert.equal( words.length, 12, "Did not return 12 words in an array"); 38 | }); 39 | 40 | it("should properly generate a 12 words mnemonic phrase for 'JA' language", async () => { 41 | const lang = "JA"; 42 | const mnemonic = MnemonicUtils.generateMnemonic(lang); 43 | const words = MnemonicUtils.getWordsFromMnemonic( mnemonic, lang ); 44 | assert.equal( words.length, 12, "Did not return 12 words in an array"); 45 | }); 46 | 47 | it("should throw if supplied language does not have a wordlist", async () => { 48 | const lang = "UNKNOWN"; 49 | assert.throws(() => { 50 | MnemonicUtils.generateMnemonic(lang); 51 | }, /^Mnemonics language \'UNKNOWN\' is not supported.$/); 52 | }); 53 | 54 | }); 55 | 56 | describe("mnemonicToSeed()", async () => { 57 | 58 | it("should return a 64 byte Buffer", async () => { 59 | const lang = "EN"; 60 | const seed = MnemonicUtils.mnemonicToSeed( "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", lang ); 61 | assert.equal( seed.length, 64, "Did not return a 64 byte buffer"); 62 | }); 63 | 64 | it("should also accept a password 'salt' parameter", async () => { 65 | const password = "salt"; 66 | const lang = "EN"; 67 | const seed = MnemonicUtils.mnemonicToSeed( "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", lang, password ); 68 | assert.equal( seed.length, 64, "Did not return a 64 byte buffer"); 69 | }); 70 | 71 | it("should throw if supplied mnemonic is invalid", async () => { 72 | const lang = "EN"; 73 | assert.throws(() => { 74 | MnemonicUtils.mnemonicToSeed("this is an invalid mnemonic", lang); 75 | }, /^Invalid Mnemonic.$/); 76 | }); 77 | }); 78 | }); 79 | }); 80 | -------------------------------------------------------------------------------- /test/ethereum/infura.ts: -------------------------------------------------------------------------------- 1 | import { Ethereum } from './../../src/blockchain/ethereum/class.index'; 2 | import { assert } from "chai"; 3 | import mocha from "mocha"; 4 | 5 | import DynamicClassMapper from "../../src/class.store"; 6 | 7 | import { Wallet, Blockchains } from "../../src/index"; 8 | import { GenericNode } from "../../src/core/node"; 9 | import { GenericAccount } from "../../src/core/account"; 10 | import { BigNumber } from 'bignumber.js'; 11 | import { EthereumTransaction } from "../../src/blockchain/ethereum/transaction"; 12 | 13 | import EthereumTx from 'ethereumjs-tx'; 14 | import { GenericTransaction } from "../../src/core/transaction"; 15 | import Zilliqa from '../../src/blockchain/zilliqa/class.index'; 16 | 17 | const mapper = new DynamicClassMapper(); 18 | mapper.collectClasses(Zilliqa.AvailableClasses); 19 | mapper.collectClasses(Ethereum.AvailableClasses); 20 | const DynamicClassName = GenericNode.getImplementedClassName( Blockchains[Blockchains.ETHEREUM] ); 21 | 22 | const receiverAddress = "0x52b333c238Bf73888fDDe266E9D2A39B75752807"; 23 | const mnemonic = "exchange neither monster ethics bless cancel ghost excite business record warfare invite"; 24 | 25 | /* 26 | describe("Core", async () => { 27 | 28 | describe("EthereumNode", async () => { 29 | 30 | describe("Infura test", async () => { 31 | 32 | const defaultWallet: Wallet = new Wallet(mnemonic, "EN"); 33 | defaultWallet.loadBlockchain(Ethereum); 34 | defaultWallet.loadBlockchain(Zilliqa); 35 | const blockchain = Blockchains.ETHEREUM; 36 | const WalletBlockchain = defaultWallet.getBlockchain( blockchain ); 37 | const WalletTestNode: GenericNode = WalletBlockchain.getNode(); 38 | WalletTestNode.init( WalletTestNode.NETWORKS[ 2 ] ); 39 | const account = defaultWallet.createAccount(blockchain); 40 | 41 | it("should work", async () => { 42 | try { 43 | const nonce = await account.getNonce(); 44 | const tx = account.buildTransferTransaction(receiverAddress, 1, nonce, 30, 21000); 45 | account.signTransaction(tx); 46 | await account.send(tx); 47 | 48 | } catch (e) { 49 | console.log(e); 50 | } 51 | }); 52 | }); 53 | }); 54 | }); 55 | */ 56 | -------------------------------------------------------------------------------- /test/ethereum/solc/deployer.ts: -------------------------------------------------------------------------------- 1 | import EthereumTx from 'ethereumjs-tx'; 2 | 3 | export default class Deployer { 4 | 5 | public address: string; 6 | public privateKey: string; 7 | public node: any; 8 | 9 | constructor( address: string, privateKey: string) { 10 | this.address = address; 11 | this.privateKey = privateKey; 12 | } 13 | 14 | public async createTx( node: any, txdata: string ): Promise { 15 | const tx = new EthereumTx( { 16 | from: this.address, 17 | nonce: await node.getNonce(this.address), 18 | data: txdata, 19 | gasPrice: 20000000000, // default rpc 20 | gasLimit: 6700000, 21 | }); 22 | tx.sign( Buffer.from( this.privateKey, "hex" ) ); 23 | return tx.serialize(); 24 | } 25 | 26 | public async getTransactionReceipt(id: string): Promise { 27 | return this.node.rpcCall("eth_getTransactionReceipt", [id], "raw") as Promise; 28 | } 29 | 30 | public async deployContract(node: any, txdata: string ): Promise { 31 | this.node = node; 32 | const tx = await this.createTx( node, txdata ); 33 | const txHash = await this.node.sendRaw( tx ); 34 | return this.getTransactionReceipt( txHash ); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /test/ethereum/solc/non_payable_fallback.bin: -------------------------------------------------------------------------------- 1 | 6080604052348015600f57600080fd5b50603e80601d6000396000f3006080604052348015600f57600080fd5b500000a165627a7a72305820314703b0f77a5338ad6a5fea41ad7065949be7496f42d96e630efb1a00a375670029 2 | -------------------------------------------------------------------------------- /test/ethereum/solc/non_payable_fallback.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.24; 2 | 3 | 4 | contract Test { 5 | 6 | function () public { 7 | 8 | } 9 | 10 | } -------------------------------------------------------------------------------- /test/ethereum/solc/payable_fallback.bin: -------------------------------------------------------------------------------- 1 | 6080604052348015600f57600080fd5b50606f8061001e6000396000f300608060405261040060405160005b82811015602457603281830152600881019050600d565b5060005b82811015603e5780820151506008810190506028565b5050500000a165627a7a72305820d8b52161cc7dd91db64169b7e0d4b1faad7ee6db73b996ce302f7a9c1465edf50029 -------------------------------------------------------------------------------- /test/ethereum/solc/payable_fallback.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.24; 2 | 3 | contract Test { 4 | 5 | function () public payable { 6 | 7 | assembly { 8 | // gas to waste 9 | let BytesToStore := 1024 10 | 11 | // load free memory pointer 12 | let pointer := mload(0x40) 13 | 14 | for { let n := 0 } lt(n, BytesToStore ) { n := add(n, 8) } { 15 | mstore( add( pointer, n ), 0x32 ) 16 | } 17 | 18 | for { let n := 0 } lt(n, BytesToStore ) { n := add(n, 8) } { 19 | let x := mload( add( pointer, n ) ) 20 | } 21 | // mstore( pointer, 64 ) 22 | } 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /test/ethereum/solc/payable_fallback_min.bin: -------------------------------------------------------------------------------- 1 | 6080604052348015600f57600080fd5b50603280601d6000396000f30060806040520000a165627a7a72305820f7ae5472b0a9d2b297a12e299f949f82331739e58d9623bce903c56186734ba40029 -------------------------------------------------------------------------------- /test/ethereum/solc/payable_fallback_min.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.24; 2 | 3 | contract Test { 4 | 5 | function () public payable { 6 | 7 | } 8 | 9 | } -------------------------------------------------------------------------------- /test/ethereum/transaction.ts: -------------------------------------------------------------------------------- 1 | import { Ethereum } from './../../src/blockchain/ethereum/class.index'; 2 | import { assert } from "chai"; 3 | import mocha from "mocha"; 4 | 5 | import { Wallet, Blockchains, AccountType, MnemonicUtils } from "../../src/index"; 6 | import { GenericAccount } from "../../src/core/account"; 7 | import { GenericNode } from "../../src/core/node"; 8 | import { GenericTransaction } from "../../src/core/transaction"; 9 | import { GenericAccountUtils } from "../../src/core/account-utils"; 10 | 11 | import DynamicClassMapper from "../../src/class.store"; 12 | import Zilliqa from '../../src/blockchain/zilliqa/class.index'; 13 | 14 | const mapper = new DynamicClassMapper(); 15 | mapper.collectClasses(Zilliqa.AvailableClasses); 16 | mapper.collectClasses(Ethereum.AvailableClasses); 17 | const DynamicClassName = GenericNode.getImplementedClassName( Blockchains[Blockchains.ETHEREUM] ); 18 | 19 | const mnemonic = "exchange neither monster ethics bless cancel ghost excite business record warfare invite"; 20 | 21 | describe("Core", async () => { 22 | 23 | describe("EthereumTransaction", async () => { 24 | 25 | describe("one Ethereum account", async () => { 26 | 27 | const defaultWallet: Wallet = new Wallet(mnemonic, "EN"); 28 | defaultWallet.loadBlockchain(Ethereum); 29 | defaultWallet.loadBlockchain(Zilliqa); 30 | const blockchain = Blockchains.ETHEREUM; 31 | const AccountClassTypeString = GenericAccount.getImplementedClassName( Blockchains[blockchain] ); 32 | const NodeClassTypeString = GenericNode.getImplementedClassName( Blockchains[blockchain] ); 33 | const TransactionClassTypeString = GenericTransaction.getImplementedClassName( Blockchains[blockchain] ); 34 | 35 | const account = defaultWallet.createAccount(blockchain); 36 | 37 | it("should create first account", async () => { 38 | 39 | const getAccount = defaultWallet.getAccounts(blockchain)[0]; 40 | const getIndex = defaultWallet.accounts.get(blockchain)[0]; 41 | 42 | assert.equal( getAccount.constructor.name, AccountClassTypeString, "class does not match expected" ); 43 | assert.equal( account, getAccount, "Accounts do not match" ); 44 | assert.equal( account, getIndex, "Accounts do not match" ); 45 | 46 | assert.equal( NodeClassTypeString, account.node.constructor.name, "class does not match expected" ); 47 | 48 | const HDKey = account.hd; 49 | assert.isNotNull( HDKey, "HDRootKey should not be null" ); 50 | assert.isTrue( account.utils.isValidPrivate( Buffer.from( account.privateKey ) ), "private key is invalid" ); 51 | assert.equal( HDKey.constructor.name, "HDKey", "HDKey class does not match expected" ); 52 | assert.equal( HDKey.npmhdkey.depth, 5, "HDKey depth does not match" ); 53 | assert.equal( HDKey.npmhdkey.index, 0, "HDKey index does not match" ); 54 | 55 | }); 56 | 57 | it("wallet should have 1 account", async () => { 58 | const getAccounts = defaultWallet.getAccounts(blockchain); 59 | assert.equal( getAccounts.length, 1, "getAccounts length does not match" ); 60 | }); 61 | 62 | 63 | }); 64 | 65 | }); 66 | 67 | }); 68 | -------------------------------------------------------------------------------- /test/zilliqa/test.ts.disabled: -------------------------------------------------------------------------------- 1 | const { Transaction } = require('@zilliqa-js/account'); 2 | const { BN, Long, bytes, units } = require('@zilliqa-js/util'); 3 | const { Zilliqa } = require('@zilliqa-js/zilliqa'); 4 | const CP = require ('@zilliqa-js/crypto'); 5 | 6 | const zilliqa = new Zilliqa('https://api.zilliqa.com'); 7 | 8 | // These are set by the core protocol, and may vary per-chain. 9 | // These numbers are JUST AN EXAMPLE. They will NOT WORK on the public testnet 10 | // or mainnet. Please check what they are before proceeding, or your 11 | // transactions will simply be rejected. 12 | const CHAIN_ID = 62; 13 | const MSG_VERSION = 1; 14 | const VER = bytes.pack(CHAIN_ID, MSG_VERSION); 15 | 16 | // Populate the wallet with an account 17 | const privkey = '891E98DBEF714F120958405F5CF1FA4F47496D0B287E514C1A7EC02805DA3C13'; 18 | const testReceiverAddress = "0x99959F33842946AeF50A7573b8c3cBf04Df339c7"; 19 | const receiverAddr = CP.toChecksumAddress( testReceiverAddress ).replace("0x", ""); 20 | zilliqa.wallet.addByPrivateKey(privkey); 21 | 22 | const add = CP.getAddressFromPrivateKey(privkey); 23 | console.log('Your account address is:'); 24 | console.log(`0x${add}`); 25 | 26 | async function testBlockchain() { 27 | try { 28 | // GetBalance 29 | const balance = await zilliqa.blockchain.getBalance(add); 30 | console.log('Your account balance is:'); 31 | console.log(balance.result); 32 | let tx = zilliqa.transactions.new({ 33 | version: VER, 34 | toAddr: receiverAddr, 35 | // Note all transactional values has to be converted to Qa (the smallest accounting unit) when using the Zilliqa protocol. 36 | // 1 Qa is 10^-12 Zil. 37 | amount: units.toQa('10', units.Units.Zil), // Sending an amount in Zil and converting the amount to Qa. 38 | gasPrice: units.toQa('1000', units.Units.Li), // gasPrice is measured in Li. 1 Li is 10^-6 Zil. 39 | gasLimit: Long.fromNumber(1), 40 | }); 41 | 42 | console.log("Params: \n", tx.txParams); 43 | console.log("Object: \n", tx); 44 | // Send a transaction to the network 45 | tx = await zilliqa.blockchain.createTransaction(tx, 35, 1000); 46 | console.log("The transaction status is:"); 47 | console.log(tx.receipt); 48 | } catch (err) { 49 | console.log(err); 50 | } 51 | } 52 | 53 | testBlockchain(); 54 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "esModuleInterop": true, 4 | "baseUrl": "./", 5 | "outDir": "./dist/lib/", 6 | "sourceMap": true, 7 | "strict": true, 8 | "resolveJsonModule": true, 9 | "moduleResolution": "node", 10 | "experimentalDecorators": true, 11 | "lib": ["es5", "es2015", "es2016", "es2017", "dom"], 12 | "allowSyntheticDefaultImports": true, 13 | "types": [ 14 | // add node as an option 15 | "node" 16 | ], 17 | "module": "commonjs", 18 | "target": "es6", 19 | "noImplicitReturns": true, 20 | "noImplicitThis": true, 21 | "noImplicitAny": false, 22 | "strictNullChecks": false, 23 | "suppressImplicitAnyIndexErrors": true, 24 | "noUnusedLocals": false 25 | }, 26 | "include": [ 27 | "./src/**/**/**/*" 28 | ], 29 | "exclude": [ 30 | "node_modules", 31 | "**/*.spec.ts" 32 | ] 33 | } -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "defaultSeverity": "error", 3 | "extends": [ 4 | "tslint:recommended" 5 | ], 6 | "jsRules": {}, 7 | "rules": { 8 | "quotemark": [ 9 | false 10 | ], 11 | "indent": [ 12 | true, 13 | "spaces" 14 | ], 15 | "max-line-length": [ 16 | false 17 | ], 18 | "interface-name": [ 19 | false 20 | ], 21 | "arrow-parens": false, 22 | // Pending fix for shorthand property names. 23 | "object-literal-sort-keys": false, 24 | "no-console": [ 25 | true, 26 | "debug", 27 | "info", 28 | "time", 29 | "timeEnd", 30 | "trace" 31 | ], 32 | "no-var-keyword": true, 33 | "no-var-requires": false, 34 | "prefer-for-of": false, 35 | "ordered-imports": false, 36 | "no-empty-interface": false, 37 | "no-bitwise": false 38 | }, 39 | "rulesDirectory": [] 40 | } -------------------------------------------------------------------------------- /types/blockchain/ethereum/account-utils.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { GenericAccountUtils } from "../../core/account-utils"; 3 | import { BigNumber } from "bignumber.js"; 4 | export declare class EthereumAccountUtils extends GenericAccountUtils { 5 | isValidChecksumAddress(key: string): boolean; 6 | toChecksumAddress(key: string): string; 7 | isValidAddress(key: Buffer): boolean; 8 | isValidPrivate(key: Buffer): boolean; 9 | isValidPublic(key: Buffer): boolean; 10 | publicToAddress(key: Buffer): Buffer; 11 | privateToPublic(privateKey: Buffer): Buffer; 12 | privateToAddress(privateKey: Buffer): Buffer; 13 | addressBufferToChecksum(key: Buffer): string; 14 | bufferToHex(buf: Buffer): string; 15 | balanceToStd(input: number | string | BigNumber): string; 16 | } 17 | -------------------------------------------------------------------------------- /types/blockchain/ethereum/account.d.ts: -------------------------------------------------------------------------------- 1 | import { GenericAccount, IaccountOptions } from "../../core/account"; 2 | import { EthereumTransaction, IEthereumTransactionOptions } from "./transaction"; 3 | import { BigNumber } from "bignumber.js"; 4 | export declare class EthereumAccount extends GenericAccount { 5 | defaultGasPriceInGwei: number; 6 | constructor(accountOptions: IaccountOptions); 7 | getBalance(): Promise; 8 | getNonce(): Promise; 9 | GWeiToWei(input: number): number; 10 | signTransaction(transaction: EthereumTransaction): boolean; 11 | signMessage(message: string): boolean; 12 | buildTransferTransaction(to: string, amount: number, nonce: number, options?: IEthereumTransactionOptions): EthereumTransaction; 13 | buildCancelTransaction(nonce: number, priceInGWei?: number): EthereumTransaction; 14 | buildTransaction(): EthereumTransaction; 15 | send(transaction: EthereumTransaction): Promise; 16 | } 17 | -------------------------------------------------------------------------------- /types/blockchain/ethereum/class.index.d.ts: -------------------------------------------------------------------------------- 1 | import { EthereumAccount } from "./account"; 2 | import { EthereumNode } from "./node"; 3 | import { EthereumTransaction } from "./transaction"; 4 | declare const AvailableClasses: { 5 | EthereumAccount: typeof EthereumAccount; 6 | EthereumNode: typeof EthereumNode; 7 | EthereumTransaction: typeof EthereumTransaction; 8 | }; 9 | export { AvailableClasses, }; 10 | -------------------------------------------------------------------------------- /types/blockchain/ethereum/networks.d.ts: -------------------------------------------------------------------------------- 1 | import { Network } from '../../core/network'; 2 | declare const networks: Network[]; 3 | export default networks; 4 | -------------------------------------------------------------------------------- /types/blockchain/ethereum/node.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { GenericNode } from "../../core/node"; 3 | import { Network } from "../../core/network"; 4 | import { BigNumber } from 'bignumber.js'; 5 | export declare class EthereumNode extends GenericNode { 6 | static readonly NETWORKS: Network[]; 7 | constructor(network?: Network); 8 | getBalance(caddress: string): Promise; 9 | getNonce(caddress: string): Promise; 10 | send(rawTransaction: Buffer): Promise; 11 | } 12 | -------------------------------------------------------------------------------- /types/blockchain/ethereum/transaction.d.ts: -------------------------------------------------------------------------------- 1 | import { GenericTransaction, ITransactionOptions } from '../../core/transaction'; 2 | export interface IEthereumTransactionOptions extends ITransactionOptions { 3 | gasPrice: number; 4 | gasLimit: number; 5 | chainId: number; 6 | } 7 | export declare class EthereumTransaction extends GenericTransaction { 8 | value: number; 9 | chainId: number; 10 | gasPrice: number; 11 | gasLimit: number; 12 | constructor(from: string, to: string, amount: number, nonce: number, options: IEthereumTransactionOptions); 13 | } 14 | -------------------------------------------------------------------------------- /types/blockchain/zilliqa/account-utils.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { GenericAccountUtils } from "../../core/account-utils"; 3 | import { BigNumber } from "bignumber.js"; 4 | export declare class ZilliqaAccountUtils extends GenericAccountUtils { 5 | isValidChecksumAddress(address: string): boolean; 6 | toChecksumAddress(address: string): string; 7 | isValidAddress(key: Buffer): boolean; 8 | isValidPrivate(key: Buffer): boolean; 9 | isValidPublic(key: Buffer): boolean; 10 | publicToAddress(key: Buffer): Buffer; 11 | privateToPublic(privateKey: Buffer): Buffer; 12 | privateToAddress(privateKey: Buffer): Buffer; 13 | addressBufferToChecksum(key: Buffer): string; 14 | bufferToHex(buf: Buffer): string; 15 | balanceToStd(input: number | string | BigNumber): string; 16 | } 17 | -------------------------------------------------------------------------------- /types/blockchain/zilliqa/account.d.ts: -------------------------------------------------------------------------------- 1 | import { GenericAccount, IaccountOptions } from "../../core/account"; 2 | import { ZilliqaTransaction, IZilliqaTransactionOptions } from "./transaction"; 3 | import { BigNumber } from "bignumber.js"; 4 | export declare class ZilliqaAccount extends GenericAccount { 5 | constructor(accountOptions: IaccountOptions); 6 | getBalance(): Promise; 7 | getNonce(): Promise; 8 | signTransaction(transaction: ZilliqaTransaction): boolean; 9 | signMessage(message: string): boolean; 10 | buildTransferTransaction(to: string, amount: number, nonce: number, options?: IZilliqaTransactionOptions): ZilliqaTransaction; 11 | buildCancelTransaction(nonce: number, priceInZil?: number): ZilliqaTransaction; 12 | buildTransaction(): ZilliqaTransaction; 13 | send(transaction: ZilliqaTransaction): Promise; 14 | } 15 | -------------------------------------------------------------------------------- /types/blockchain/zilliqa/class.index.d.ts: -------------------------------------------------------------------------------- 1 | import { ZilliqaAccount } from "./account"; 2 | import { ZilliqaNode } from "./node"; 3 | import { ZilliqaTransaction } from "./transaction"; 4 | declare const AvailableClasses: { 5 | ZilliqaAccount: typeof ZilliqaAccount; 6 | ZilliqaNode: typeof ZilliqaNode; 7 | ZilliqaTransaction: typeof ZilliqaTransaction; 8 | }; 9 | export { AvailableClasses, }; 10 | -------------------------------------------------------------------------------- /types/blockchain/zilliqa/networks.d.ts: -------------------------------------------------------------------------------- 1 | import { Network } from '../../core/network'; 2 | declare const networks: Network[]; 3 | export default networks; 4 | -------------------------------------------------------------------------------- /types/blockchain/zilliqa/node.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { GenericNode } from "../../core/node"; 3 | import { Network } from "../../core/network"; 4 | import { BigNumber } from 'bignumber.js'; 5 | export declare class ZilliqaNode extends GenericNode { 6 | static readonly NETWORKS: Network[]; 7 | constructor(network?: Network); 8 | getBalance(address: string): Promise; 9 | getNonce(caddress: string): Promise; 10 | send(rawTransaction: Buffer): Promise; 11 | } 12 | -------------------------------------------------------------------------------- /types/blockchain/zilliqa/transaction.d.ts: -------------------------------------------------------------------------------- 1 | import { GenericTransaction, ITransactionOptions } from '../../core/transaction'; 2 | export interface IZilliqaTransactionOptions extends ITransactionOptions { 3 | gasPrice: number; 4 | gasLimit: number; 5 | pubKey: string; 6 | code: string; 7 | } 8 | export declare class ZilliqaTransaction extends GenericTransaction { 9 | version: number; 10 | pubKey: string; 11 | code: string; 12 | constructor(from: string, to: string, amount: number, nonce: number, options: IZilliqaTransactionOptions); 13 | } 14 | -------------------------------------------------------------------------------- /types/class.store.d.ts: -------------------------------------------------------------------------------- 1 | export default class DynamicClass { 2 | constructor(); 3 | collectClasses(object: any): void; 4 | getInstance(className: string, opts?: any): any; 5 | } 6 | -------------------------------------------------------------------------------- /types/core/account-utils.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { BigNumber } from "bignumber.js"; 3 | export declare abstract class GenericAccountUtils { 4 | requireType(target: any, expected: string, method: string): boolean; 5 | abstract isValidChecksumAddress(key: string): boolean; 6 | abstract toChecksumAddress(key: string): string; 7 | abstract isValidAddress(key: Buffer): boolean; 8 | abstract isValidPrivate(key: Buffer): boolean; 9 | abstract isValidPublic(key: Buffer): boolean; 10 | abstract publicToAddress(key: Buffer): Buffer; 11 | abstract privateToPublic(privateKey: Buffer): Buffer; 12 | abstract privateToAddress(privateKey: Buffer): Buffer; 13 | abstract addressBufferToChecksum(key: Buffer): string; 14 | abstract bufferToHex(buf: Buffer): string; 15 | abstract balanceToStd(input: number | string | BigNumber): string; 16 | } 17 | -------------------------------------------------------------------------------- /types/core/account.d.ts: -------------------------------------------------------------------------------- 1 | import { GenericTransaction, ITransactionOptions } from './transaction'; 2 | import { GenericNode } from "./node"; 3 | import HDKey from './utils/hdkey'; 4 | import { GenericAccountUtils } from './account-utils'; 5 | import { BigNumber } from "bignumber.js"; 6 | export declare enum AccountType { 7 | HD = "HD", 8 | LOOSE = "LOOSE", 9 | HARDWARE = "HARDWARE" 10 | } 11 | export interface IaccountOptions { 12 | node: GenericNode; 13 | privateKey?: string; 14 | publicKey?: string; 15 | address?: string; 16 | type: AccountType; 17 | hd?: any; 18 | } 19 | export declare abstract class GenericAccount { 20 | static getImplementedClassName(name: string): string; 21 | node: GenericNode; 22 | address: string; 23 | publicKey: string; 24 | privateKey: string; 25 | type: AccountType; 26 | hd: HDKey | any; 27 | utils: GenericAccountUtils | any; 28 | private transactions; 29 | constructor(accountOptions: IaccountOptions); 30 | tryHdWalletSetup(): void; 31 | getTransactions(): T[]; 32 | abstract getBalance(): Promise; 33 | abstract getNonce(): Promise; 34 | abstract buildTransferTransaction(to: string, amount: number, nonce: number, options?: TO): T; 35 | abstract buildCancelTransaction(nonce: number, priceInGWei: number): T; 36 | abstract buildTransaction(): T; 37 | abstract signTransaction(transaction: T): boolean; 38 | abstract signMessage(message: string): boolean; 39 | abstract send(transaction: T): Promise; 40 | } 41 | -------------------------------------------------------------------------------- /types/core/blockchain.d.ts: -------------------------------------------------------------------------------- 1 | export declare enum Blockchain { 2 | ETHEREUM = 0, 3 | ZILLIQA = 1 4 | } 5 | -------------------------------------------------------------------------------- /types/core/network.d.ts: -------------------------------------------------------------------------------- 1 | import { Blockchain } from "./blockchain"; 2 | export interface Network { 3 | blockchain: Blockchain; 4 | chainId: number; 5 | name: string; 6 | url: string; 7 | mainNet: boolean; 8 | HDCoinValue: number; 9 | } 10 | -------------------------------------------------------------------------------- /types/core/node.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { Network } from "./network"; 3 | import { BigNumber } from "bignumber.js"; 4 | export declare abstract class GenericNode { 5 | static readonly NETWORKS: Network[]; 6 | static getImplementedClassName(name: string): string; 7 | customNetworkUrl: boolean; 8 | connected: boolean; 9 | NETWORKS: Network[]; 10 | network: Network; 11 | blockchain: any; 12 | HDRootKey: any; 13 | callId: number; 14 | init(network?: Network): void; 15 | abstract getBalance(address: string): Promise; 16 | abstract getNonce(address: string): Promise; 17 | abstract send(rawTransaction: Buffer): Promise; 18 | getCurrentNetworkPathString(): any; 19 | getNetwork(): Network; 20 | setCustomNetworkUrl(url: string): void; 21 | resetCustomNetworkUrl(): void; 22 | call(method: string, params: any, cb?: any): Promise | void; 23 | buildCall(cmethod: string, cparams: any): any; 24 | } 25 | -------------------------------------------------------------------------------- /types/core/transaction.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { ITransactionOptions } from './transaction'; 3 | export interface ITransactionOptions { 4 | } 5 | export declare enum TransactionStatus { 6 | NEW = "NEW", 7 | SIGNED = "SIGNED", 8 | PENDING = "PENDING", 9 | FINAL = "FINAL" 10 | } 11 | export declare abstract class GenericTransaction { 12 | static getImplementedClassName(name: string): string; 13 | from: string; 14 | to: string; 15 | nonce: number; 16 | options: TO; 17 | txn: string; 18 | raw: Buffer; 19 | status: TransactionStatus; 20 | constructor(from: string, to: string, amount: number, nonce: number, options: TO); 21 | } 22 | -------------------------------------------------------------------------------- /types/core/utils/hdkey.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | export default class HDKey { 3 | static fromHDKey(npmhdkey: HDKey): HDKey; 4 | static fromMasterSeed(seedBuffer: Buffer): HDKey; 5 | npmhdkey: any; 6 | derivePath(path: any): HDKey; 7 | deriveChild(index: any): HDKey; 8 | getPrivateKey(): Buffer; 9 | getPrivateKeyString(): string; 10 | } 11 | -------------------------------------------------------------------------------- /types/core/utils/mnemonic.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | interface WordListItem { 3 | [key: string]: string[]; 4 | } 5 | export default class Mnemonic { 6 | static getAvailableWordLists(): WordListItem[]; 7 | static generateMnemonic(language?: string): string; 8 | static mnemonicToSeed(mnemonic: string, language?: string, password?: string): Buffer; 9 | static getWordsFromMnemonic(mnemonic: string, language?: string): string[]; 10 | } 11 | export {}; 12 | -------------------------------------------------------------------------------- /types/core/wallet.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { Blockchain } from "./blockchain"; 3 | import { GenericNode } from "./node"; 4 | import { GenericAccount } from "./account"; 5 | import DynamicClassMapper from "../class.store"; 6 | export default class Wallet { 7 | static fromJson(json: string): void; 8 | mnemonics: string; 9 | mnemonicslang: string; 10 | seed: Buffer; 11 | hdroots: Map; 12 | nodes: Map>; 13 | accounts: Map; 14 | private mapper; 15 | constructor(mnemonics?: string, language?: string, mnemonicPassword?: string); 16 | getClassMapper(): DynamicClassMapper; 17 | getAccounts(blockchain: Blockchain): GenericAccount[]; 18 | getAccountsMap(): Map; 19 | getBlockchain(blockchain: Blockchain): { 20 | getNode: () => GenericNode; 21 | getAccounts: () => GenericAccount, import("src/core/transaction").ITransactionOptions>[]; 22 | createAccount: () => GenericAccount, import("src/core/transaction").ITransactionOptions>; 23 | importAccount: (account: GenericAccount, import("src/core/transaction").ITransactionOptions>) => void; 24 | }; 25 | getNode(blockchain: Blockchain, networkId?: number): GenericNode; 26 | createAccount(blockchain: Blockchain, networkId?: number): GenericAccount; 27 | requireImplementation(blockchain: Blockchain, method: string): boolean; 28 | importAccount(account: GenericAccount): void; 29 | } 30 | -------------------------------------------------------------------------------- /types/index.d.ts: -------------------------------------------------------------------------------- 1 | import Wallet from "./core/wallet"; 2 | import { Blockchain as Blockchains } from "./core/blockchain"; 3 | import { AccountType } from "./core/account"; 4 | import MnemonicUtils from "./core/utils/mnemonic"; 5 | export { Wallet, Blockchains, AccountType, MnemonicUtils, }; 6 | declare global { 7 | interface Window { 8 | Wallet: typeof Wallet; 9 | } 10 | } 11 | --------------------------------------------------------------------------------