quantum-coin-js-sdk 1.0.39 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitignore +2 -1
- package/README.md +109 -768
- package/index.d.ts +76 -545
- package/index.js +319 -1194
- package/package.json +20 -5
- package/wasmBase64.js +7 -16
- package/wasm_exec.js +575 -587
- package/.idea/.name +0 -1
- package/.idea/modules.xml +0 -8
- package/.idea/quantum-coin-js-sdk.iml +0 -12
- package/.idea/vcs.xml +0 -6
- package/.vs/ProjectSettings.json +0 -3
- package/.vs/VSWorkspaceState.json +0 -8
- package/.vs/quantum-coin-js-sdk/FileContentIndex/a9d6de82-cfc3-4c22-ac38-06d706ff3673.vsidx +0 -0
- package/.vs/quantum-coin-js-sdk/FileContentIndex/fdc816df-1898-4153-99f2-c69ef4c2283b.vsidx +0 -0
- package/.vs/quantum-coin-js-sdk/config/applicationhost.config +0 -1011
- package/.vs/quantum-coin-js-sdk/v17/.wsuo +0 -0
- package/.vs/quantum-coin-js-sdk/v17/DocumentLayout.backup.json +0 -39
- package/.vs/quantum-coin-js-sdk/v17/DocumentLayout.json +0 -57
- package/.vs/slnx.sqlite +0 -0
- package/example/README.md +0 -14
- package/example/conversion-example.js +0 -19
- package/example/example-create-contract.js +0 -396
- package/example/example-encode-decode-rlp.js +0 -225
- package/example/example-event-pack-unpack.js +0 -391
- package/example/example-misc.js +0 -100
- package/example/example-rpc-send-signRawTransaction.js +0 -318
- package/example/example-rpc-send.js +0 -115
- package/example/example-send.js +0 -69
- package/example/example-token-pack-unpack.js +0 -960
- package/example/example-wallet-version4.js +0 -34
- package/example/example-wallet.js +0 -43
- package/example/example.js +0 -405
- package/example/node_modules/.bin/sdkgen +0 -16
- package/example/node_modules/.bin/sdkgen.cmd +0 -17
- package/example/node_modules/.bin/sdkgen.ps1 +0 -28
- package/example/node_modules/.package-lock.json +0 -47
- package/example/node_modules/quantumcoin/.github/workflows/publish-npmjs.yaml +0 -22
- package/example/node_modules/quantumcoin/LICENSE +0 -21
- package/example/node_modules/quantumcoin/README-SDK.md +0 -828
- package/example/node_modules/quantumcoin/README.md +0 -197
- package/example/node_modules/quantumcoin/config.d.ts +0 -50
- package/example/node_modules/quantumcoin/config.js +0 -123
- package/example/node_modules/quantumcoin/examples/AllSolidityTypes.sol +0 -184
- package/example/node_modules/quantumcoin/examples/SimpleIERC20.sol +0 -74
- package/example/node_modules/quantumcoin/examples/events.js +0 -41
- package/example/node_modules/quantumcoin/examples/events.ts +0 -35
- package/example/node_modules/quantumcoin/examples/example-generator-sdk-js.js +0 -100
- package/example/node_modules/quantumcoin/examples/example-generator-sdk-js.ts +0 -77
- package/example/node_modules/quantumcoin/examples/example-generator-sdk-ts.js +0 -100
- package/example/node_modules/quantumcoin/examples/example-generator-sdk-ts.ts +0 -77
- package/example/node_modules/quantumcoin/examples/example.js +0 -67
- package/example/node_modules/quantumcoin/examples/example.ts +0 -56
- package/example/node_modules/quantumcoin/examples/offline-signing.js +0 -77
- package/example/node_modules/quantumcoin/examples/offline-signing.ts +0 -65
- package/example/node_modules/quantumcoin/examples/package-lock.json +0 -596
- package/example/node_modules/quantumcoin/examples/package.json +0 -32
- package/example/node_modules/quantumcoin/examples/read-operations.js +0 -32
- package/example/node_modules/quantumcoin/examples/read-operations.ts +0 -31
- package/example/node_modules/quantumcoin/examples/sdk-generator-erc20.inline.json +0 -251
- package/example/node_modules/quantumcoin/examples/solidity-types.ts +0 -43
- package/example/node_modules/quantumcoin/examples/wallet-offline.js +0 -36
- package/example/node_modules/quantumcoin/examples/wallet-offline.ts +0 -26
- package/example/node_modules/quantumcoin/generate-sdk.js +0 -1846
- package/example/node_modules/quantumcoin/index.js +0 -12
- package/example/node_modules/quantumcoin/package.json +0 -95
- package/example/node_modules/quantumcoin/scripts/copy-declarations.js +0 -31
- package/example/node_modules/quantumcoin/scripts/run-all-one-by-one.js +0 -151
- package/example/node_modules/quantumcoin/src/abi/fragments.d.ts +0 -42
- package/example/node_modules/quantumcoin/src/abi/fragments.js +0 -63
- package/example/node_modules/quantumcoin/src/abi/index.d.ts +0 -13
- package/example/node_modules/quantumcoin/src/abi/index.js +0 -9
- package/example/node_modules/quantumcoin/src/abi/interface.d.ts +0 -128
- package/example/node_modules/quantumcoin/src/abi/interface.js +0 -605
- package/example/node_modules/quantumcoin/src/abi/js-abi-coder.d.ts +0 -8
- package/example/node_modules/quantumcoin/src/abi/js-abi-coder.js +0 -538
- package/example/node_modules/quantumcoin/src/constants.d.ts +0 -61
- package/example/node_modules/quantumcoin/src/constants.js +0 -94
- package/example/node_modules/quantumcoin/src/contract/contract-factory.d.ts +0 -28
- package/example/node_modules/quantumcoin/src/contract/contract-factory.js +0 -111
- package/example/node_modules/quantumcoin/src/contract/contract.d.ts +0 -113
- package/example/node_modules/quantumcoin/src/contract/contract.js +0 -408
- package/example/node_modules/quantumcoin/src/contract/index.d.ts +0 -9
- package/example/node_modules/quantumcoin/src/contract/index.js +0 -9
- package/example/node_modules/quantumcoin/src/errors/index.d.ts +0 -92
- package/example/node_modules/quantumcoin/src/errors/index.js +0 -200
- package/example/node_modules/quantumcoin/src/generator/index.d.ts +0 -81
- package/example/node_modules/quantumcoin/src/generator/index.js +0 -1571
- package/example/node_modules/quantumcoin/src/index.d.ts +0 -122
- package/example/node_modules/quantumcoin/src/index.js +0 -41
- package/example/node_modules/quantumcoin/src/internal/hex.d.ts +0 -68
- package/example/node_modules/quantumcoin/src/internal/hex.js +0 -180
- package/example/node_modules/quantumcoin/src/providers/extra-providers.d.ts +0 -139
- package/example/node_modules/quantumcoin/src/providers/extra-providers.js +0 -614
- package/example/node_modules/quantumcoin/src/providers/index.d.ts +0 -17
- package/example/node_modules/quantumcoin/src/providers/index.js +0 -10
- package/example/node_modules/quantumcoin/src/providers/json-rpc-provider.d.ts +0 -12
- package/example/node_modules/quantumcoin/src/providers/json-rpc-provider.js +0 -89
- package/example/node_modules/quantumcoin/src/providers/provider.d.ts +0 -206
- package/example/node_modules/quantumcoin/src/providers/provider.js +0 -524
- package/example/node_modules/quantumcoin/src/types/index.d.ts +0 -214
- package/example/node_modules/quantumcoin/src/types/index.js +0 -9
- package/example/node_modules/quantumcoin/src/utils/address.d.ts +0 -58
- package/example/node_modules/quantumcoin/src/utils/address.js +0 -144
- package/example/node_modules/quantumcoin/src/utils/encoding.d.ts +0 -120
- package/example/node_modules/quantumcoin/src/utils/encoding.js +0 -306
- package/example/node_modules/quantumcoin/src/utils/fixednumber.d.ts +0 -57
- package/example/node_modules/quantumcoin/src/utils/fixednumber.js +0 -366
- package/example/node_modules/quantumcoin/src/utils/hashing.d.ts +0 -76
- package/example/node_modules/quantumcoin/src/utils/hashing.js +0 -298
- package/example/node_modules/quantumcoin/src/utils/index.d.ts +0 -63
- package/example/node_modules/quantumcoin/src/utils/index.js +0 -14
- package/example/node_modules/quantumcoin/src/utils/result.d.ts +0 -57
- package/example/node_modules/quantumcoin/src/utils/result.js +0 -128
- package/example/node_modules/quantumcoin/src/utils/rlp.d.ts +0 -12
- package/example/node_modules/quantumcoin/src/utils/rlp.js +0 -215
- package/example/node_modules/quantumcoin/src/utils/units.d.ts +0 -29
- package/example/node_modules/quantumcoin/src/utils/units.js +0 -107
- package/example/node_modules/quantumcoin/src/wallet/index.d.ts +0 -10
- package/example/node_modules/quantumcoin/src/wallet/index.js +0 -8
- package/example/node_modules/quantumcoin/src/wallet/wallet.d.ts +0 -192
- package/example/node_modules/quantumcoin/src/wallet/wallet.js +0 -713
- package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.dynamic.test.js +0 -207
- package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.dynamic.test.ts +0 -191
- package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.fixtures.js +0 -231
- package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.generated-sdks.e2e.test.js +0 -387
- package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.generated-sdks.e2e.test.ts +0 -350
- package/example/node_modules/quantumcoin/test/e2e/generator-interface.e2e.test.js +0 -165
- package/example/node_modules/quantumcoin/test/e2e/generator-interface.e2e.test.ts +0 -160
- package/example/node_modules/quantumcoin/test/e2e/helpers.js +0 -59
- package/example/node_modules/quantumcoin/test/e2e/signing-context-and-fee.e2e.test.js +0 -141
- package/example/node_modules/quantumcoin/test/e2e/signing-context-and-fee.e2e.test.ts +0 -128
- package/example/node_modules/quantumcoin/test/e2e/simple-erc20.generated-sdks.e2e.test.js +0 -168
- package/example/node_modules/quantumcoin/test/e2e/simple-erc20.generated-sdks.e2e.test.ts +0 -141
- package/example/node_modules/quantumcoin/test/e2e/transactional.test.js +0 -245
- package/example/node_modules/quantumcoin/test/e2e/transactional.test.ts +0 -208
- package/example/node_modules/quantumcoin/test/e2e/typed-generator.e2e.test.js +0 -407
- package/example/node_modules/quantumcoin/test/e2e/typed-generator.e2e.test.ts +0 -337
- package/example/node_modules/quantumcoin/test/fixtures/ConstructorParam.sol +0 -23
- package/example/node_modules/quantumcoin/test/fixtures/MultiContracts.sol +0 -37
- package/example/node_modules/quantumcoin/test/fixtures/SimpleStorage.sol +0 -18
- package/example/node_modules/quantumcoin/test/fixtures/StakingContract.abi.json +0 -1
- package/example/node_modules/quantumcoin/test/integration/ipc-provider.test.js +0 -49
- package/example/node_modules/quantumcoin/test/integration/ipc-provider.test.ts +0 -44
- package/example/node_modules/quantumcoin/test/integration/provider.test.js +0 -88
- package/example/node_modules/quantumcoin/test/integration/provider.test.ts +0 -85
- package/example/node_modules/quantumcoin/test/integration/ws-provider.test.js +0 -41
- package/example/node_modules/quantumcoin/test/integration/ws-provider.test.ts +0 -38
- package/example/node_modules/quantumcoin/test/security/abi-decoder-bounds.test.js +0 -122
- package/example/node_modules/quantumcoin/test/security/contract-overrides.test.js +0 -112
- package/example/node_modules/quantumcoin/test/security/generator-injection.test.js +0 -195
- package/example/node_modules/quantumcoin/test/security/malformed-input.test.js +0 -330
- package/example/node_modules/quantumcoin/test/security/malformed-input.test.ts +0 -35
- package/example/node_modules/quantumcoin/test/security/rpc-numeric-bounds.test.js +0 -81
- package/example/node_modules/quantumcoin/test/security/rpc-trust.test.js +0 -202
- package/example/node_modules/quantumcoin/test/unit/_encrypted-output.txt +0 -6
- package/example/node_modules/quantumcoin/test/unit/_log-encrypted-jsons.js +0 -45
- package/example/node_modules/quantumcoin/test/unit/_write-keystore-fixture.js +0 -16
- package/example/node_modules/quantumcoin/test/unit/abi-interface.test.js +0 -110
- package/example/node_modules/quantumcoin/test/unit/abi-interface.test.ts +0 -109
- package/example/node_modules/quantumcoin/test/unit/address-wallet.test.js +0 -923
- package/example/node_modules/quantumcoin/test/unit/address-wallet.test.ts +0 -877
- package/example/node_modules/quantumcoin/test/unit/browser-provider.test.js +0 -85
- package/example/node_modules/quantumcoin/test/unit/browser-provider.test.ts +0 -79
- package/example/node_modules/quantumcoin/test/unit/contract.test.js +0 -85
- package/example/node_modules/quantumcoin/test/unit/contract.test.ts +0 -83
- package/example/node_modules/quantumcoin/test/unit/encoding-units-rlp.test.js +0 -127
- package/example/node_modules/quantumcoin/test/unit/encoding-units-rlp.test.ts +0 -91
- package/example/node_modules/quantumcoin/test/unit/errors.test.js +0 -77
- package/example/node_modules/quantumcoin/test/unit/errors.test.ts +0 -76
- package/example/node_modules/quantumcoin/test/unit/filter-by-blockhash.test.js +0 -55
- package/example/node_modules/quantumcoin/test/unit/filter-by-blockhash.test.ts +0 -54
- package/example/node_modules/quantumcoin/test/unit/fixednumber.test.js +0 -656
- package/example/node_modules/quantumcoin/test/unit/fixednumber.test.ts +0 -660
- package/example/node_modules/quantumcoin/test/unit/fixtures/encrypted-keystores-48-32-36.js +0 -9
- package/example/node_modules/quantumcoin/test/unit/generate-contract-cli.test.js +0 -42
- package/example/node_modules/quantumcoin/test/unit/generate-contract-cli.test.ts +0 -41
- package/example/node_modules/quantumcoin/test/unit/generate-sdk-artifacts-json.test.js +0 -113
- package/example/node_modules/quantumcoin/test/unit/generate-sdk-artifacts-json.test.ts +0 -110
- package/example/node_modules/quantumcoin/test/unit/generator.test.js +0 -149
- package/example/node_modules/quantumcoin/test/unit/generator.test.ts +0 -148
- package/example/node_modules/quantumcoin/test/unit/hashing.test.js +0 -64
- package/example/node_modules/quantumcoin/test/unit/hashing.test.ts +0 -63
- package/example/node_modules/quantumcoin/test/unit/init.test.js +0 -39
- package/example/node_modules/quantumcoin/test/unit/init.test.ts +0 -38
- package/example/node_modules/quantumcoin/test/unit/interface.test.js +0 -56
- package/example/node_modules/quantumcoin/test/unit/interface.test.ts +0 -54
- package/example/node_modules/quantumcoin/test/unit/internal-hex.test.js +0 -81
- package/example/node_modules/quantumcoin/test/unit/internal-hex.test.ts +0 -80
- package/example/node_modules/quantumcoin/test/unit/populate-transaction.test.js +0 -98
- package/example/node_modules/quantumcoin/test/unit/populate-transaction.test.ts +0 -64
- package/example/node_modules/quantumcoin/test/unit/providers.test.js +0 -252
- package/example/node_modules/quantumcoin/test/unit/providers.test.ts +0 -251
- package/example/node_modules/quantumcoin/test/unit/result.test.js +0 -80
- package/example/node_modules/quantumcoin/test/unit/result.test.ts +0 -79
- package/example/node_modules/quantumcoin/test/unit/solidity-types.test.js +0 -49
- package/example/node_modules/quantumcoin/test/unit/solidity-types.test.ts +0 -39
- package/example/node_modules/quantumcoin/test/unit/utils.test.js +0 -57
- package/example/node_modules/quantumcoin/test/unit/utils.test.ts +0 -56
- package/example/node_modules/quantumcoin/test/verbose-logger.js +0 -74
- package/example/node_modules/quantumcoin/tsconfig.build.json +0 -14
- package/example/node_modules/seed-words/.github/workflows/publish-npmjs.yaml +0 -22
- package/example/node_modules/seed-words/BUILD.md +0 -7
- package/example/node_modules/seed-words/LICENSE +0 -121
- package/example/node_modules/seed-words/README.md +0 -67
- package/example/node_modules/seed-words/dist/seedwords.d.ts +0 -39
- package/example/node_modules/seed-words/package.json +0 -27
- package/example/node_modules/seed-words/seedwords.js +0 -315
- package/example/node_modules/seed-words/seedwords.txt +0 -65536
- package/example/node_modules/seed-words/tsconfig.json +0 -21
- package/example/package-lock.json +0 -56
- package/example/package.json +0 -15
- package/tests/encrypted-32.json +0 -1
- package/tests/encrypted-36.json +0 -1
- package/tests/encrypted-48.json +0 -1
- package/tests/generate-verify-vectors.js +0 -91
- package/tests/get-gas-price.test.js +0 -59
- package/tests/non-transactional.preinit.test.js +0 -41
- package/tests/non-transactional.test.js +0 -1389
- package/tests/scrypt.test.js +0 -128
- package/tests/sign-raw-keytype5-context-null.test.js +0 -107
- package/tests/sign-raw-transaction.test.js +0 -196
- package/tests/sign-verify.test.js +0 -311
- package/tests/transactional.relay.test.js +0 -131
- package/tests/transactional.rpc.test.js +0 -103
- package/tests/verify-vectors.json +0 -95035
package/index.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
*
|
|
24
24
|
* //Example initialization with specific values
|
|
25
25
|
* //Initialize the SDK first before invoking any other function
|
|
26
|
-
* var clientConfigVal = new qcsdk.Config(
|
|
26
|
+
* var clientConfigVal = new qcsdk.Config(123123); //Initialization with Mainnet Config (Block Explorer: https://QuantumScan.com)
|
|
27
27
|
* qcsdk.initialize(clientConfigVal).then((initResult) => {
|
|
28
28
|
*
|
|
29
29
|
* }
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
|
|
34
34
|
var wasmexec = require('./wasm_exec');
|
|
35
35
|
var wasmBase64 = require('./wasmBase64');
|
|
36
|
-
const crypto = require("crypto");
|
|
37
36
|
var seedwords = require('seed-words');
|
|
38
37
|
|
|
39
38
|
var config = null;
|
|
@@ -41,8 +40,6 @@ var isInitialized = false;
|
|
|
41
40
|
/** CIRCL WASM namespace (set after InitAccountsWebAssembly). Use getCircl() for access. */
|
|
42
41
|
var circl = null;
|
|
43
42
|
const DEFAULT_GAS = 21000;
|
|
44
|
-
const API_KEY_HEADER_NAME = "X-API-KEY";
|
|
45
|
-
const REQUEST_ID_HEADER_NAME = "X-REQUEST-ID";
|
|
46
43
|
|
|
47
44
|
// Dynamic-fee gas pricing (mirrors quantum-coin-go core/types/dynamic_fee_tx.go).
|
|
48
45
|
// Base dynamic price = defaults.DEFAULT_PRICE / 10. BigInt is used because the
|
|
@@ -68,59 +65,26 @@ const SCRYPT_SUPPORTED_P = 1;
|
|
|
68
65
|
const SCRYPT_SUPPORTED_DKLEN = 32;
|
|
69
66
|
const INVALID_KEY_TYPE = -1001;
|
|
70
67
|
const CIRCL_CRYPTO_FAILURE = -1002;
|
|
71
|
-
const EXPECTED_WASM_SHA256 = "
|
|
68
|
+
const EXPECTED_WASM_SHA256 = "e2d721ae6dd7c1b855623a54050892892c1161ef9d49c76f77d106d37ec0b555";
|
|
72
69
|
|
|
73
70
|
/**
|
|
74
71
|
* @class
|
|
75
72
|
* @constructor
|
|
76
73
|
* @public
|
|
77
|
-
* @classdesc This is the configuration class required to initialize
|
|
74
|
+
* @classdesc This is the configuration class required to initialize the Quantum Coin SDK for offline operations such as wallet management and transaction signing.
|
|
78
75
|
*/
|
|
79
76
|
class Config {
|
|
80
77
|
/**
|
|
81
78
|
* Creates a config class
|
|
82
|
-
* @param {string} readUrl - The Read API URL pointing to a read relay. See https://github.com/quantumcoinproject/quantum-coin-go/tree/main/relay. The following URLs are community maintained. Please use your own relay service. Mainnet: https://sdk.readrelay.quantumcoinapi.com
|
|
83
|
-
* @param {string} writeUrl - The Write API URL pointing to a write relay. See https://github.com/quantumcoinproject/quantum-coin-go/tree/main/relay. The following URLs are community maintained. Please use your own relay service. Mainnet: https://sdk.writerelay.quantumcoinapi.com
|
|
84
79
|
* @param {number} chainId - The chain id of the blockchain. Mainnet chainId is 123123. Testnet T4 chainId is 310324.
|
|
85
|
-
* @param {string} readApiKey - Optional parameter if authorization is enabled for the relay service. API Key for authorization. Defaults to null which indicates no authorization.
|
|
86
|
-
* @param {string} writeApiKey - Optional parameter if authorization is enabled for the relay service. API Key for authorization. Defaults to null which indicates no authorization.
|
|
87
80
|
*/
|
|
88
|
-
|
|
89
|
-
constructor(readUrl, writeUrl, chainId, readApiKey, writeApiKey) {
|
|
90
|
-
/**
|
|
91
|
-
* The Read API URL pointing to a read relay. See https://github.com/quantumcoinproject/quantum-coin-go/tree/main/relay
|
|
92
|
-
* @type {string}
|
|
93
|
-
* @public
|
|
94
|
-
*/
|
|
95
|
-
this.readUrl = readUrl;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* The Read API URL pointing to a read relay. See https://github.com/quantumcoinproject/quantum-coin-go/tree/main/relay
|
|
99
|
-
* @type {string}
|
|
100
|
-
* @public
|
|
101
|
-
*/
|
|
102
|
-
this.writeUrl = writeUrl;
|
|
103
|
-
|
|
81
|
+
constructor(chainId) {
|
|
104
82
|
/**
|
|
105
83
|
* The chain id of the blockchain. Mainnet chainId is 123123. Testnet T4 chainId is 310324.
|
|
106
84
|
* @type {number}
|
|
107
85
|
* @public
|
|
108
86
|
*/
|
|
109
87
|
this.chainId = chainId;
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* API Key for authorization if authorization is enabled for the relay service. Defaults to null which indicates no authorization.
|
|
113
|
-
* @type {string}
|
|
114
|
-
* @public
|
|
115
|
-
*/
|
|
116
|
-
this.readApiKey = readApiKey;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* API Key for authorization if authorization is enabled for the relay service. Defaults to null which indicates no authorization.
|
|
120
|
-
* @type {string}
|
|
121
|
-
* @public
|
|
122
|
-
*/
|
|
123
|
-
this.writeApiKey = writeApiKey;
|
|
124
88
|
}
|
|
125
89
|
}
|
|
126
90
|
|
|
@@ -163,509 +127,21 @@ class Wallet {
|
|
|
163
127
|
|
|
164
128
|
/**
|
|
165
129
|
* Pre-expansion seed bytes. Can be null if the wallet was not created from a seed.
|
|
166
|
-
* @type {Uint8Array|number[]|null}
|
|
167
|
-
* @public
|
|
168
|
-
*/
|
|
169
|
-
this.preExpansionSeed = preExpansionSeed || null;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* @class
|
|
175
|
-
* @constructor
|
|
176
|
-
* @public
|
|
177
|
-
* @classdesc This class represents a Block.
|
|
178
|
-
*/
|
|
179
|
-
class BlockDetails {
|
|
180
|
-
constructor(blockNumber) {
|
|
181
|
-
/**
|
|
182
|
-
* Block Number of the block
|
|
183
|
-
* @type {number}
|
|
184
|
-
* @public
|
|
185
|
-
*/
|
|
186
|
-
this.blockNumber = blockNumber;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* @class
|
|
192
|
-
* @constructor
|
|
193
|
-
* @public
|
|
194
|
-
* @classdesc This class represents a result from invoking the getLatestBlock function.
|
|
195
|
-
*/
|
|
196
|
-
class LatestBlockDetailsResult {
|
|
197
|
-
constructor(resultCode, blockDetails, response, requestId, err) {
|
|
198
|
-
/**
|
|
199
|
-
* Represents the result of the operation. A value of 0 represents that the operation succeeded. Any other value indicates the operation failed. See the result code section for more details.
|
|
200
|
-
* @type {number}
|
|
201
|
-
* @public
|
|
202
|
-
*/
|
|
203
|
-
this.resultCode = resultCode;
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* An object of type BlockDetails representing the block. This value is null if the value of resultCode is not 0.
|
|
207
|
-
* @type {BlockDetails}
|
|
208
|
-
* @public
|
|
209
|
-
*/
|
|
210
|
-
this.blockDetails = blockDetails;
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* An object of representing the raw Response returned by the service. For details, see https://developer.mozilla.org/en-US/docs/Web/API/Response. This value can be null if the value of resultCode is not 0.
|
|
214
|
-
* @type {Object}
|
|
215
|
-
* @public
|
|
216
|
-
*/
|
|
217
|
-
this.response = response;
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* An unique id to represent the request. This can be null if request failed before it could be sent.
|
|
221
|
-
* @type {string}
|
|
222
|
-
* @public
|
|
223
|
-
*/
|
|
224
|
-
this.requestId = requestId;
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
|
|
228
|
-
* @type {Error}
|
|
229
|
-
* @public
|
|
230
|
-
*/
|
|
231
|
-
this.err = err;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* @class
|
|
237
|
-
* @constructor
|
|
238
|
-
* @public
|
|
239
|
-
* @classdesc This class represents an Account.
|
|
240
|
-
*/
|
|
241
|
-
class AccountDetails {
|
|
242
|
-
constructor(address, balance, nonce, blockNumber) {
|
|
243
|
-
/**
|
|
244
|
-
* Address of the wallet. Is 66 bytes in length including 0x.
|
|
245
|
-
* @type {string}
|
|
246
|
-
* @public
|
|
247
|
-
*/
|
|
248
|
-
this.address = address;
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Balance of the account in wei. To convert this to ethers, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei
|
|
252
|
-
* @type {string}
|
|
253
|
-
* @public
|
|
254
|
-
*/
|
|
255
|
-
this.balance = balance;
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* A monotonically increasing number representing the nonce of the account. After each transaction from the account that gets registered in the blockchain, the nonce increases by 1.
|
|
259
|
-
* @type {number}
|
|
260
|
-
* @public
|
|
261
|
-
*/
|
|
262
|
-
this.nonce = nonce;
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* The block number as of which the Account details was retrieved.
|
|
266
|
-
* @type {number}
|
|
267
|
-
* @public
|
|
268
|
-
*/
|
|
269
|
-
this.blockNumber = blockNumber;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* @class
|
|
275
|
-
* @constructor
|
|
276
|
-
* @public
|
|
277
|
-
* @classdesc This class represents a result from invoking the getAccountDetails function.
|
|
278
|
-
*/
|
|
279
|
-
class AccountDetailsResult {
|
|
280
|
-
constructor(resultCode, accountDetails, response, requestId, err) {
|
|
281
|
-
/**
|
|
282
|
-
* Represents the result of the operation. A value of 0 represents that the operation succeeded. Any other value indicates the operation failed. See the result code section for more details.
|
|
283
|
-
* @type {number}
|
|
284
|
-
* @public
|
|
285
|
-
*/
|
|
286
|
-
this.resultCode = resultCode;
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* An object of type AccountDetails representing the block. This value is null if the value of resultCode is not 0.
|
|
290
|
-
* @type {AccountDetails}
|
|
291
|
-
* @public
|
|
292
|
-
*/
|
|
293
|
-
this.accountDetails = accountDetails;
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* An object of representing the raw Response returned by the service. For details, see https://developer.mozilla.org/en-US/docs/Web/API/Response. This value can be null if the value of resultCode is not 0.
|
|
297
|
-
* @type {Object}
|
|
298
|
-
* @public
|
|
299
|
-
*/
|
|
300
|
-
this.response = response;
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* An unique id to represent the request. This can be null if request failed before it could be sent.
|
|
304
|
-
* @type {string}
|
|
305
|
-
* @public
|
|
306
|
-
*/
|
|
307
|
-
this.requestId = requestId;
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
|
|
311
|
-
* @type {Error}
|
|
312
|
-
* @public
|
|
313
|
-
*/
|
|
314
|
-
this.err = err;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* @class
|
|
320
|
-
* @constructor
|
|
321
|
-
* @public
|
|
322
|
-
* @classdesc This class represents a result from invoking the signSendCoinTransaction function.
|
|
323
|
-
*/
|
|
324
|
-
class SignResult {
|
|
325
|
-
constructor(resultCode, txnHash, txnData) {
|
|
326
|
-
/**
|
|
327
|
-
* Represents the result of the operation. A value of 0 represents that the operation succeeded. Any other value indicates the operation failed. See the result code section for more details.
|
|
328
|
-
* @type {number}
|
|
329
|
-
* @public
|
|
330
|
-
*/
|
|
331
|
-
this.resultCode = resultCode;
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Hash of the Transaction, to uniquely identify it. Is 66 bytes in length including 0x. This value is null if the value of resultCode is not 0.
|
|
335
|
-
* @type {string}
|
|
336
|
-
* @public
|
|
337
|
-
*/
|
|
338
|
-
this.txnHash = txnHash;
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* A payload representing the signed transaction.
|
|
342
|
-
* To actually send a transaction, this payload can then be taken to to a different device that is connected to the blockchain relay and then sent using the postTransaction function.
|
|
343
|
-
* This value is null if the value of resultCode is not 0.
|
|
344
|
-
* @type {string}
|
|
345
|
-
* @public
|
|
346
|
-
*/
|
|
347
|
-
this.txnData = txnData;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* @class
|
|
353
|
-
* @constructor
|
|
354
|
-
* @public
|
|
355
|
-
* @classdesc This class represents a result from invoking the sendCoins function.
|
|
356
|
-
*/
|
|
357
|
-
class SendResult {
|
|
358
|
-
constructor(resultCode, txnHash, response, requestId, err) {
|
|
359
|
-
/**
|
|
360
|
-
* Represents the result of the operation. A value of 0 represents that the operation succeeded. Any other value indicates the operation failed. See the result code section for more details.
|
|
361
|
-
* @type {number}
|
|
362
|
-
* @public
|
|
363
|
-
*/
|
|
364
|
-
this.resultCode = resultCode;
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Hash of the Transaction, to uniquely identify it. Is 66 bytes in length including 0x. This value is null if the value of resultCode is not 0.
|
|
368
|
-
* @type {string}
|
|
369
|
-
* @public
|
|
370
|
-
*/
|
|
371
|
-
this.txnHash = txnHash;
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* An object of representing the raw Response returned by the service. For details, see https://developer.mozilla.org/en-US/docs/Web/API/Response. This value can be null if the value of resultCode is not 0.
|
|
375
|
-
* @type {Object}
|
|
376
|
-
* @public
|
|
377
|
-
*/
|
|
378
|
-
this.response = response;
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* An unique id to represent the request. This can be null if request failed before it could be sent.
|
|
382
|
-
* @type {string}
|
|
383
|
-
* @public
|
|
384
|
-
*/
|
|
385
|
-
this.requestId = requestId;
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
|
|
389
|
-
* @type {Error}
|
|
390
|
-
* @public
|
|
391
|
-
*/
|
|
392
|
-
this.err = err;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* @class
|
|
398
|
-
* @constructor
|
|
399
|
-
* @public
|
|
400
|
-
* @classdesc This class represents a Receipt of a transaction that is registered in the blockchain. The transactionReceipt field can be null unless the transaction is registered with the blockchain.
|
|
401
|
-
* While the transaction is pending, this field will be null. You should consider the transaction as succeeded only if the status field's value is 0x1 (success).
|
|
402
|
-
*/
|
|
403
|
-
class TransactionReceipt {
|
|
404
|
-
constructor() {
|
|
405
|
-
/**
|
|
406
|
-
* A hexadecimal string representing the total amount of gas used when this transaction was executed in the block.
|
|
407
|
-
* @type {string}
|
|
408
|
-
* @public
|
|
409
|
-
*/
|
|
410
|
-
this.cumulativeGasUsed = null;
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* A hexadecimal string representing the sum of the base fee and tip paid per unit of gas.
|
|
414
|
-
* @type {string}
|
|
415
|
-
* @public
|
|
416
|
-
*/
|
|
417
|
-
this.effectiveGasPrice = null;
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* A hexadecimal string representing the amount of gas used by this specific transaction alone.
|
|
421
|
-
* @type {string}
|
|
422
|
-
* @public
|
|
423
|
-
*/
|
|
424
|
-
this.gasUsed = null;
|
|
425
|
-
|
|
426
|
-
/**
|
|
427
|
-
* A hexadecimal string representing either 0x1 (success) or 0x0 (failure). Failed transactions can also incur gas fee. You should consider the transaction as succeeded only if the status value is 0x1 (success).
|
|
428
|
-
* @type {string}
|
|
429
|
-
* @public
|
|
430
|
-
*/
|
|
431
|
-
this.status = null;
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* Hash of the Transaction, to uniquely identify it. Is 66 bytes in length including 0x.
|
|
435
|
-
* @type {string}
|
|
436
|
-
* @public
|
|
437
|
-
*/
|
|
438
|
-
this.hash = null;
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* A hexadecimal string representing the transaction type. 0x0 is DefaultFeeTxType.
|
|
442
|
-
* @type {string}
|
|
443
|
-
* @public
|
|
444
|
-
*/
|
|
445
|
-
this.type = null;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* @class
|
|
451
|
-
* @constructor
|
|
452
|
-
* @public
|
|
453
|
-
* @classdesc This class represents details of a transaction. You should consider the transaction as succeeded only if the status field of the receipt object is 0x1 (success).
|
|
454
|
-
*/
|
|
455
|
-
class TransactionDetails {
|
|
456
|
-
constructor() {
|
|
457
|
-
/**
|
|
458
|
-
* A hexadecimal string representing the hash of the block that registered the transaction. This field can be null if the transaction was not registered in the blockchain.
|
|
459
|
-
* @type {string}
|
|
460
|
-
* @public
|
|
461
|
-
*/
|
|
462
|
-
this.blockHash = null;
|
|
463
|
-
|
|
464
|
-
/**
|
|
465
|
-
* The number of the block that registered the transaction. This field can be null if the transaction was not registered in the blockchain.
|
|
466
|
-
* @type {number}
|
|
467
|
-
* @public
|
|
468
|
-
*/
|
|
469
|
-
this.blockNumber = null;
|
|
470
|
-
|
|
471
|
-
/**
|
|
472
|
-
* A 66 character hexadecimal string representing the address the transaction is sent from.
|
|
473
|
-
* @type {string}
|
|
474
|
-
* @public
|
|
475
|
-
*/
|
|
476
|
-
this.from = null;
|
|
477
|
-
|
|
478
|
-
/**
|
|
479
|
-
* A hexadecimal string representing the gas provided for the transaction execution.
|
|
480
|
-
* @type {string}
|
|
481
|
-
* @public
|
|
482
|
-
*/
|
|
483
|
-
this.gas = null;
|
|
484
|
-
|
|
485
|
-
/**
|
|
486
|
-
* A hexadecimal string representing the gasPrice used for each paid gas, in Wei.
|
|
487
|
-
* @type {string}
|
|
488
|
-
* @public
|
|
489
|
-
*/
|
|
490
|
-
this.gasPrice = null;
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* A 66 character hexadecimal string representing the hash of the transaction.
|
|
494
|
-
* @type {string}
|
|
495
|
-
* @public
|
|
496
|
-
*/
|
|
497
|
-
this.hash = null;
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* A hexadecimal string representing the compiled code of a contract OR the hash of the invoked method signature and encoded parameters.
|
|
501
|
-
* @type {string}
|
|
502
|
-
* @public
|
|
503
|
-
*/
|
|
504
|
-
this.input = null;
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
* A monotonically increasing number representing the nonce of the account. After each transaction from the account that gets registered in the blockchain, the nonce increases by 1.
|
|
508
|
-
* @type {number}
|
|
509
|
-
* @public
|
|
510
|
-
*/
|
|
511
|
-
this.nonce = null;
|
|
512
|
-
|
|
513
|
-
/**
|
|
514
|
-
* A 66 character hexadecimal string representing address the transaction is directed to.
|
|
515
|
-
* @type {string}
|
|
516
|
-
* @public
|
|
517
|
-
*/
|
|
518
|
-
this.to = null;
|
|
519
|
-
|
|
520
|
-
/**
|
|
521
|
-
* A hexadecimal string representing the value sent with this transaction. The value can be 0 for smart contract transactions, since it only represents the number of coins sent.
|
|
522
|
-
* @type {string}
|
|
523
|
-
* @public
|
|
524
|
-
*/
|
|
525
|
-
this.value = null;
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* The receipt of the transaction. This field will be null while the transaction is pending (not yet registered in the blockchain).
|
|
529
|
-
* @type {TransactionReceipt}
|
|
530
|
-
* @public
|
|
531
|
-
*/
|
|
532
|
-
this.receipt = null;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
/**
|
|
538
|
-
* @class
|
|
539
|
-
* @constructor
|
|
540
|
-
* @public
|
|
541
|
-
* @classdesc This class represents a result from invoking the getTransactionDetails function. If transactions get discarded by the blockchain, for reasons such as due to lower than minimum gas fees or invalid nonce, the resultCode will always contain a non-zero value (failure).
|
|
542
|
-
*/
|
|
543
|
-
class TransactionDetailsResult {
|
|
544
|
-
constructor(resultCode, transactionDetails, response, requestId, err) {
|
|
545
|
-
/**
|
|
546
|
-
* Represents the result of the operation. A value of 0 represents that the operation succeeded. Any other value indicates the operation failed. See the result code section for more details.
|
|
547
|
-
* @type {number}
|
|
548
|
-
* @public
|
|
549
|
-
*/
|
|
550
|
-
|
|
551
|
-
this.resultCode = resultCode;
|
|
552
|
-
|
|
553
|
-
/**
|
|
554
|
-
* An object of type TransactionDetails representing the transaction. This value is null if the value of resultCode is not 0.
|
|
555
|
-
* @type {TransactionDetails}
|
|
556
|
-
* @public
|
|
557
|
-
*/
|
|
558
|
-
this.transactionDetails = transactionDetails;
|
|
559
|
-
|
|
560
|
-
/**
|
|
561
|
-
* An object of representing the raw Response returned by the service. For details, see https://developer.mozilla.org/en-US/docs/Web/API/Response. This value can be null if the value of resultCode is not 0.
|
|
562
|
-
* @type {Object}
|
|
563
|
-
* @public
|
|
564
|
-
*/
|
|
565
|
-
this.response = response;
|
|
566
|
-
|
|
567
|
-
/**
|
|
568
|
-
* An unique id to represent the request. This can be null if request failed before it could be sent.
|
|
569
|
-
* @type {string}
|
|
570
|
-
* @public
|
|
571
|
-
*/
|
|
572
|
-
this.requestId = requestId;
|
|
573
|
-
|
|
574
|
-
/**
|
|
575
|
-
* An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
|
|
576
|
-
* @type {Error}
|
|
577
|
-
* @public
|
|
578
|
-
*/
|
|
579
|
-
this.err = err;
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
/**
|
|
584
|
-
* @class
|
|
585
|
-
* @constructor
|
|
586
|
-
* @public
|
|
587
|
-
* @classdesc This class represents a transaction of an account. You should consider the transaction as succeeded only if the status field is 0x1 (success).
|
|
588
|
-
*/
|
|
589
|
-
class AccountTransactionCompact {
|
|
590
|
-
constructor() {
|
|
591
|
-
/**
|
|
592
|
-
* The number of the block that registered the transaction. This field can be null if the transaction was not registered in the blockchain.
|
|
593
|
-
* @type {number}
|
|
594
|
-
* @public
|
|
595
|
-
*/
|
|
596
|
-
this.blockNumber = null;
|
|
597
|
-
|
|
598
|
-
/**
|
|
599
|
-
* A 66 character hexadecimal string representing the address the transaction is sent from.
|
|
600
|
-
* @type {string}
|
|
601
|
-
* @public
|
|
602
|
-
*/
|
|
603
|
-
this.from = null;
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
* A 66 character hexadecimal string representing the hash of the transaction.
|
|
607
|
-
* @type {string}
|
|
608
|
-
* @public
|
|
609
|
-
*/
|
|
610
|
-
this.hash = null;
|
|
611
|
-
|
|
612
|
-
/**
|
|
613
|
-
* A 66 character hexadecimal string representing address the transaction is directed to.
|
|
614
|
-
* @type {string}
|
|
615
|
-
* @public
|
|
616
|
-
*/
|
|
617
|
-
this.to = null;
|
|
618
|
-
|
|
619
|
-
/**
|
|
620
|
-
* A hexadecimal string representing the value sent with this transaction. The value can be 0 for smart contract transactions, since it only represents the number of coins sent.
|
|
621
|
-
* @type {string}
|
|
622
|
-
* @public
|
|
623
|
-
*/
|
|
624
|
-
this.value = null;
|
|
625
|
-
|
|
626
|
-
/**
|
|
627
|
-
* A hexadecimal string representing either 0x1 (success) or 0x0 (failure). Failed transactions can also incur gas fee. You should consider the transaction as succeeded only if the status value is 0x1 (success).
|
|
628
|
-
* @type {string}
|
|
629
|
-
* @public
|
|
630
|
-
*/
|
|
631
|
-
this.status = null;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
/**
|
|
637
|
-
* @class
|
|
638
|
-
* @constructor
|
|
639
|
-
* @public
|
|
640
|
-
* @classdesc This class represents a list of account transactions returned by the listAccountTransactionDetails function.
|
|
641
|
-
*/
|
|
642
|
-
class ListAccountTransactionsResponse {
|
|
643
|
-
constructor() {
|
|
644
|
-
/**
|
|
645
|
-
* The number of pages available for listing.
|
|
646
|
-
* @type {number}
|
|
647
|
-
* @public
|
|
648
|
-
*/
|
|
649
|
-
this.pageCount = null;
|
|
650
|
-
|
|
651
|
-
/**
|
|
652
|
-
* An array of type AccountTransactionCompact, containing the list of transactions. Can be null if no items are available.
|
|
653
|
-
* @type {(AccountTransactionCompact|Array)}
|
|
130
|
+
* @type {Uint8Array|number[]|null}
|
|
654
131
|
* @public
|
|
655
132
|
*/
|
|
656
|
-
this.
|
|
133
|
+
this.preExpansionSeed = preExpansionSeed || null;
|
|
657
134
|
}
|
|
658
|
-
|
|
659
135
|
}
|
|
660
136
|
|
|
661
137
|
/**
|
|
662
138
|
* @class
|
|
663
139
|
* @constructor
|
|
664
140
|
* @public
|
|
665
|
-
* @classdesc This class represents a result from invoking the
|
|
141
|
+
* @classdesc This class represents a result from invoking the signSendCoinTransaction function.
|
|
666
142
|
*/
|
|
667
|
-
class
|
|
668
|
-
constructor(resultCode,
|
|
143
|
+
class SignResult {
|
|
144
|
+
constructor(resultCode, txnHash, txnData) {
|
|
669
145
|
/**
|
|
670
146
|
* Represents the result of the operation. A value of 0 represents that the operation succeeded. Any other value indicates the operation failed. See the result code section for more details.
|
|
671
147
|
* @type {number}
|
|
@@ -674,32 +150,20 @@ class AccountTransactionsResult {
|
|
|
674
150
|
this.resultCode = resultCode;
|
|
675
151
|
|
|
676
152
|
/**
|
|
677
|
-
*
|
|
678
|
-
* @type {ListAccountTransactionsResponse}
|
|
679
|
-
* @public
|
|
680
|
-
*/
|
|
681
|
-
this.listAccountTransactionsResponse = listAccountTransactionsResponse;
|
|
682
|
-
|
|
683
|
-
/**
|
|
684
|
-
* An object of representing the raw Response returned by the service. For details, see https://developer.mozilla.org/en-US/docs/Web/API/Response. This value can be null if the value of resultCode is not 0.
|
|
685
|
-
* @type {Object}
|
|
686
|
-
* @public
|
|
687
|
-
*/
|
|
688
|
-
this.response = response;
|
|
689
|
-
|
|
690
|
-
/**
|
|
691
|
-
* An unique id to represent the request. This can be null if request failed before it could be sent.
|
|
153
|
+
* Hash of the Transaction, to uniquely identify it. Is 66 bytes in length including 0x. This value is null if the value of resultCode is not 0.
|
|
692
154
|
* @type {string}
|
|
693
155
|
* @public
|
|
694
156
|
*/
|
|
695
|
-
this.
|
|
157
|
+
this.txnHash = txnHash;
|
|
696
158
|
|
|
697
159
|
/**
|
|
698
|
-
*
|
|
699
|
-
*
|
|
160
|
+
* A payload representing the signed transaction.
|
|
161
|
+
* To actually send a transaction, this payload can then be broadcast to the blockchain from a connected device (for example, via a relay or RPC endpoint).
|
|
162
|
+
* This value is null if the value of resultCode is not 0.
|
|
163
|
+
* @type {string}
|
|
700
164
|
* @public
|
|
701
165
|
*/
|
|
702
|
-
this.
|
|
166
|
+
this.txnData = txnData;
|
|
703
167
|
}
|
|
704
168
|
}
|
|
705
169
|
|
|
@@ -866,18 +330,46 @@ function getGlobalObject() {
|
|
|
866
330
|
return (typeof globalThis !== 'undefined' ? globalThis : typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : this);
|
|
867
331
|
}
|
|
868
332
|
|
|
333
|
+
function base64ToBytesFast(b64) {
|
|
334
|
+
if (typeof Buffer !== 'undefined' && typeof Buffer.from === 'function') {
|
|
335
|
+
return new Uint8Array(Buffer.from(b64, 'base64'));
|
|
336
|
+
}
|
|
337
|
+
if (typeof Uint8Array.fromBase64 === 'function') {
|
|
338
|
+
return Uint8Array.fromBase64(b64);
|
|
339
|
+
}
|
|
340
|
+
const bin = atob(b64);
|
|
341
|
+
const bytes = new Uint8Array(bin.length);
|
|
342
|
+
for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
|
|
343
|
+
return bytes;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
async function gunzipToUint8Array(compressed) {
|
|
347
|
+
const ds = new DecompressionStream('gzip');
|
|
348
|
+
const stream = new Response(compressed).body.pipeThrough(ds);
|
|
349
|
+
const buf = await new Response(stream).arrayBuffer();
|
|
350
|
+
return new Uint8Array(buf);
|
|
351
|
+
}
|
|
352
|
+
|
|
869
353
|
async function InitAccountsWebAssembly() {
|
|
870
|
-
const
|
|
354
|
+
const GoCtor = getGlobalObject().Go;
|
|
355
|
+
if (typeof GoCtor !== 'function') {
|
|
356
|
+
throw new Error("Go WASM runtime not found (wasm_exec.js not loaded)");
|
|
357
|
+
}
|
|
358
|
+
const go = new GoCtor();
|
|
871
359
|
let mod, inst;
|
|
872
360
|
var base64wasm = wasmBase64.getBase64Wasm();
|
|
873
361
|
|
|
874
|
-
const
|
|
875
|
-
if (
|
|
362
|
+
const compressed = base64ToBytesFast(base64wasm);
|
|
363
|
+
if (compressed === null || compressed === undefined || compressed.length === 0) {
|
|
876
364
|
throw new Error("Error parsing base64");
|
|
877
365
|
}
|
|
878
|
-
const wasmBytes =
|
|
366
|
+
const wasmBytes = await gunzipToUint8Array(compressed);
|
|
879
367
|
|
|
880
|
-
|
|
368
|
+
// Platform-agnostic integrity check via the Web Crypto API (available in
|
|
369
|
+
// browsers and Node 16+ as globalThis.crypto.subtle). Runs before the WASM
|
|
370
|
+
// is initialized, so it cannot use the WASM's own Sha256.
|
|
371
|
+
const digest = await getGlobalObject().crypto.subtle.digest('SHA-256', wasmBytes);
|
|
372
|
+
const hashHex = Array.from(new Uint8Array(digest), b => b.toString(16).padStart(2, '0')).join('');
|
|
881
373
|
if (hashHex !== EXPECTED_WASM_SHA256) {
|
|
882
374
|
throw new Error("WASM integrity check failed");
|
|
883
375
|
}
|
|
@@ -960,9 +452,9 @@ async function initialize(clientConfig) {
|
|
|
960
452
|
return false;
|
|
961
453
|
}
|
|
962
454
|
if (clientConfig === null || clientConfig === undefined) {
|
|
963
|
-
clientConfig = new Config(
|
|
455
|
+
clientConfig = new Config(123123); //default
|
|
964
456
|
}
|
|
965
|
-
if (clientConfig.
|
|
457
|
+
if (clientConfig.chainId === null || clientConfig.chainId === undefined) {
|
|
966
458
|
return false;
|
|
967
459
|
}
|
|
968
460
|
await InitAccountsWebAssembly();
|
|
@@ -1390,10 +882,6 @@ function bytesToBase64(bytes) {
|
|
|
1390
882
|
return btoa(binString);
|
|
1391
883
|
}
|
|
1392
884
|
|
|
1393
|
-
function getRandomRequestId() {
|
|
1394
|
-
return crypto.randomBytes(20).toString('hex');
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
885
|
function isByteArray(array) {
|
|
1398
886
|
if (!array) return false;
|
|
1399
887
|
if (array.byteLength !== undefined) return true;
|
|
@@ -1401,6 +889,27 @@ function isByteArray(array) {
|
|
|
1401
889
|
return false;
|
|
1402
890
|
}
|
|
1403
891
|
|
|
892
|
+
// Normalizes a bytes-like value (Uint8Array or number[]) to a Uint8Array.
|
|
893
|
+
// Returns null for unsupported inputs.
|
|
894
|
+
function toU8Bytes(value) {
|
|
895
|
+
if (value instanceof Uint8Array) {
|
|
896
|
+
return value;
|
|
897
|
+
}
|
|
898
|
+
if (Array.isArray(value)) {
|
|
899
|
+
return Uint8Array.from(value);
|
|
900
|
+
}
|
|
901
|
+
return null;
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// Normalizes a secret-like value (string -> UTF-8 bytes, or bytes-like) to a
|
|
905
|
+
// Uint8Array. Returns null for unsupported inputs.
|
|
906
|
+
function toU8Secret(value) {
|
|
907
|
+
if (typeof value === 'string' || value instanceof String) {
|
|
908
|
+
return new TextEncoder().encode(String(value));
|
|
909
|
+
}
|
|
910
|
+
return toU8Bytes(value);
|
|
911
|
+
}
|
|
912
|
+
|
|
1404
913
|
/**
|
|
1405
914
|
* The verifyWallet function verifies whether a Wallet is valid or not. To mitigate spoofing and other attachs, it is highly recommended to verify a wallet, especially if it is from an untrusted source.
|
|
1406
915
|
*
|
|
@@ -1503,538 +1012,136 @@ function serializeWallet(wallet) {
|
|
|
1503
1012
|
*
|
|
1504
1013
|
* @function deserializeWallet
|
|
1505
1014
|
* @param {string} walletJson - A JSON string representing the wallet to deserialize.
|
|
1506
|
-
* @return {Wallet|null} Returns the Wallet corresponding to the walletJson. If the wallet is invalid or the JSON is malformed, null is returned.
|
|
1507
|
-
*/
|
|
1508
|
-
function deserializeWallet(walletJson) {
|
|
1509
|
-
if (isInitialized === false) {
|
|
1510
|
-
return -1000;
|
|
1511
|
-
}
|
|
1512
|
-
|
|
1513
|
-
try {
|
|
1514
|
-
var tempWallet = JSON.parse(walletJson);
|
|
1515
|
-
if (tempWallet == null || typeof tempWallet !== 'object') {
|
|
1516
|
-
return null;
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
var preExpansionSeed = null;
|
|
1520
|
-
if (tempWallet.preExpansionSeed != null && tempWallet.preExpansionSeed.length > 0) {
|
|
1521
|
-
preExpansionSeed = base64ToBytes(tempWallet.preExpansionSeed);
|
|
1522
|
-
}
|
|
1523
|
-
|
|
1524
|
-
var wallet = new Wallet(tempWallet.address, base64ToBytes(tempWallet.privateKey), base64ToBytes(tempWallet.publicKey), preExpansionSeed);
|
|
1525
|
-
|
|
1526
|
-
if (verifyWallet(wallet) === false) {
|
|
1527
|
-
return null;
|
|
1528
|
-
}
|
|
1529
|
-
|
|
1530
|
-
return wallet;
|
|
1531
|
-
} catch (e) {
|
|
1532
|
-
return null;
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
|
|
1536
|
-
function transactionGetSigningHash(fromaddress, nonce, toaddress, amount, gas, chainid, data) {
|
|
1537
|
-
let messageData = TxnSigningHash(fromaddress, nonce, toaddress, amount, gas, chainid, data);
|
|
1538
|
-
var messageBytes = [];
|
|
1539
|
-
for (var i = 0; i < messageData.length; ++i) {
|
|
1540
|
-
messageBytes.push(messageData.charCodeAt(i));
|
|
1541
|
-
}
|
|
1542
|
-
return messageBytes;
|
|
1543
|
-
}
|
|
1544
|
-
|
|
1545
|
-
function transactionGetTransactionHash(fromaddress, nonce, toaddress, amount, gas, chainid, data, pkkey, sig) {
|
|
1546
|
-
const arrayPkDataToPass = pkkey.toString().split(",");
|
|
1547
|
-
const typedPkArray = new Uint8Array(arrayPkDataToPass.length);
|
|
1548
|
-
for (let i = 0; i < arrayPkDataToPass.length; i++) {
|
|
1549
|
-
typedPkArray[i] = arrayPkDataToPass[i];
|
|
1550
|
-
}
|
|
1551
|
-
const arraySigDataToPass = sig.toString().split(",");
|
|
1552
|
-
const typedSigArray = new Uint8Array(arraySigDataToPass.length);
|
|
1553
|
-
for (let i = 0; i < arraySigDataToPass.length; i++) {
|
|
1554
|
-
typedSigArray[i] = arraySigDataToPass[i];
|
|
1555
|
-
}
|
|
1556
|
-
var txnHash = TxnHash(fromaddress, nonce, toaddress, amount, gas, chainid, data, typedPkArray, typedSigArray)
|
|
1557
|
-
return txnHash;
|
|
1558
|
-
}
|
|
1559
|
-
|
|
1560
|
-
function transactionGetData(fromaddress, nonce, toaddress, amount, gas, chainid, data, pkkey, sig) {
|
|
1561
|
-
const arrayPkDataToPass = pkkey.toString().split(",");
|
|
1562
|
-
const typedPkArray = new Uint8Array(arrayPkDataToPass.length);
|
|
1563
|
-
for (let i = 0; i < arrayPkDataToPass.length; i++) {
|
|
1564
|
-
typedPkArray[i] = arrayPkDataToPass[i];
|
|
1565
|
-
}
|
|
1566
|
-
const arraySigDataToPass = sig.toString().split(",");
|
|
1567
|
-
const typedSigArray = new Uint8Array(arraySigDataToPass.length);
|
|
1568
|
-
for (let i = 0; i < arraySigDataToPass.length; i++) {
|
|
1569
|
-
typedSigArray[i] = arraySigDataToPass[i];
|
|
1570
|
-
}
|
|
1571
|
-
var txnData = TxnData(fromaddress, nonce, toaddress, amount, gas, chainid, data, typedPkArray, typedSigArray)
|
|
1572
|
-
return txnData;
|
|
1573
|
-
}
|
|
1574
|
-
|
|
1575
|
-
function transactionGetSigningHash2(fromaddress, nonce, toaddress, valueInWeiHex, gas, chainid, data, remarks, signingContext) {
|
|
1576
|
-
let messageDataReturn = TxnSigningHash2(fromaddress, nonce, toaddress, valueInWeiHex, gas, chainid, data, remarks, signingContext);
|
|
1577
|
-
if (messageDataReturn && messageDataReturn.error) {
|
|
1578
|
-
return null;
|
|
1579
|
-
}
|
|
1580
|
-
var messageData = messageDataReturn.result;
|
|
1581
|
-
var messageBytes = [];
|
|
1582
|
-
for (var i = 0; i < messageData.length; ++i) {
|
|
1583
|
-
messageBytes.push(messageData.charCodeAt(i));
|
|
1584
|
-
}
|
|
1585
|
-
return messageBytes;
|
|
1586
|
-
}
|
|
1587
|
-
|
|
1588
|
-
function transactionGetTransactionHash2(fromaddress, nonce, toaddress, valueInWeiHex, gas, chainid, data, remarks, signingContext, pkkey, sig) {
|
|
1589
|
-
const arrayPkDataToPass = pkkey.toString().split(",");
|
|
1590
|
-
const typedPkArray = new Uint8Array(arrayPkDataToPass.length);
|
|
1591
|
-
for (let i = 0; i < arrayPkDataToPass.length; i++) {
|
|
1592
|
-
typedPkArray[i] = arrayPkDataToPass[i];
|
|
1593
|
-
}
|
|
1594
|
-
const arraySigDataToPass = sig.toString().split(",");
|
|
1595
|
-
const typedSigArray = new Uint8Array(arraySigDataToPass.length);
|
|
1596
|
-
for (let i = 0; i < arraySigDataToPass.length; i++) {
|
|
1597
|
-
typedSigArray[i] = arraySigDataToPass[i];
|
|
1598
|
-
}
|
|
1599
|
-
var txnHashReturn = TxnHash2(fromaddress, nonce, toaddress, valueInWeiHex, gas, chainid, data, remarks, signingContext, typedPkArray, typedSigArray)
|
|
1600
|
-
if (txnHashReturn && txnHashReturn.error) {
|
|
1601
|
-
return null;
|
|
1602
|
-
}
|
|
1603
|
-
return txnHashReturn.result;
|
|
1604
|
-
}
|
|
1605
|
-
|
|
1606
|
-
function transactionGetData2(fromaddress, nonce, toaddress, valueInWeiHex, gas, chainid, data, remarks, signingContext, pkkey, sig) {
|
|
1607
|
-
const arrayPkDataToPass = pkkey.toString().split(",");
|
|
1608
|
-
const typedPkArray = new Uint8Array(arrayPkDataToPass.length);
|
|
1609
|
-
for (let i = 0; i < arrayPkDataToPass.length; i++) {
|
|
1610
|
-
typedPkArray[i] = arrayPkDataToPass[i];
|
|
1611
|
-
}
|
|
1612
|
-
const arraySigDataToPass = sig.toString().split(",");
|
|
1613
|
-
const typedSigArray = new Uint8Array(arraySigDataToPass.length);
|
|
1614
|
-
for (let i = 0; i < arraySigDataToPass.length; i++) {
|
|
1615
|
-
typedSigArray[i] = arraySigDataToPass[i];
|
|
1616
|
-
}
|
|
1617
|
-
var txnDataReturn = TxnData2(fromaddress, nonce, toaddress, valueInWeiHex, gas, chainid, data, remarks, signingContext, typedPkArray, typedSigArray)
|
|
1618
|
-
if (txnDataReturn && txnDataReturn.error) {
|
|
1619
|
-
return null;
|
|
1620
|
-
}
|
|
1621
|
-
return txnDataReturn.result;
|
|
1622
|
-
}
|
|
1623
|
-
|
|
1624
|
-
/**
|
|
1625
|
-
* The postTransaction function posts a signed transaction to the blockchain.
|
|
1626
|
-
* This method can be used in conjunction with the signSendCoinTransaction method to submit a transaction that was signed using a cold wallet (offline or disconnected or air-gapped wallet).
|
|
1627
|
-
*
|
|
1628
|
-
* @async
|
|
1629
|
-
* @function postTransaction
|
|
1630
|
-
* @param {string} txnData - A signed transaction string returned by the signSendCoinTransaction function.
|
|
1631
|
-
* @return {Promise<SendResult>} Returns a promise of type SendResult. txnHash will be null in SendResult.
|
|
1632
|
-
*/
|
|
1633
|
-
async function postTransaction(txnData) {
|
|
1634
|
-
if (isInitialized === false) {
|
|
1635
|
-
return -1000;
|
|
1636
|
-
}
|
|
1637
|
-
|
|
1638
|
-
if (txnData == null) {
|
|
1639
|
-
return new SendResult(-600, null, null, null);
|
|
1640
|
-
}
|
|
1641
|
-
var url = config.writeUrl + "/transactions";
|
|
1642
|
-
|
|
1643
|
-
let requestId = getRandomRequestId();
|
|
1644
|
-
|
|
1645
|
-
let reqHeaders = new Headers({
|
|
1646
|
-
"Content-Type": "application/json"
|
|
1647
|
-
});
|
|
1648
|
-
reqHeaders.append(REQUEST_ID_HEADER_NAME, requestId);
|
|
1649
|
-
if (config.writeApiKey !== null) {
|
|
1650
|
-
reqHeaders.append(API_KEY_HEADER_NAME, config.writeApiKey); }
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
let txnDataJson = JSON.stringify({ txnData: txnData });
|
|
1654
|
-
|
|
1655
|
-
try {
|
|
1656
|
-
const response = await fetch(url, {
|
|
1657
|
-
method: 'POST',
|
|
1658
|
-
headers: reqHeaders,
|
|
1659
|
-
body: txnDataJson
|
|
1660
|
-
});
|
|
1661
|
-
|
|
1662
|
-
if (response == null) {
|
|
1663
|
-
return new SendResult(-601, null, null, requestId);
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
if (response.status === 200 || response.status === 204) {
|
|
1667
|
-
return new SendResult(0, null, response, requestId);
|
|
1668
|
-
}
|
|
1669
|
-
|
|
1670
|
-
return new SendResult(-602, null, response, requestId);
|
|
1671
|
-
} catch(error) {
|
|
1672
|
-
return new SendResult(-10000, null, null, requestId, error);
|
|
1673
|
-
}
|
|
1674
|
-
}
|
|
1675
|
-
|
|
1676
|
-
/**
|
|
1677
|
-
* The getLatestBlockDetails function returns details of the latest block of the blockchain.
|
|
1678
|
-
*
|
|
1679
|
-
* @async
|
|
1680
|
-
* @function getLatestBlockDetails
|
|
1681
|
-
* @return {Promise<LatestBlockDetailsResult>} Returns a promise of an object of type LatestBlockDetailsResult.
|
|
1682
|
-
*/
|
|
1683
|
-
async function getLatestBlockDetails() {
|
|
1684
|
-
if (isInitialized === false) {
|
|
1685
|
-
return -1000;
|
|
1686
|
-
}
|
|
1687
|
-
|
|
1688
|
-
let requestId = getRandomRequestId();
|
|
1689
|
-
|
|
1690
|
-
let reqHeaders = new Headers({
|
|
1691
|
-
"Content-Type": "application/json"
|
|
1692
|
-
});
|
|
1693
|
-
reqHeaders.append(REQUEST_ID_HEADER_NAME, requestId);
|
|
1694
|
-
if (config.readApiKey !== null) {
|
|
1695
|
-
reqHeaders.append(API_KEY_HEADER_NAME, config.readApiKey);
|
|
1696
|
-
}
|
|
1697
|
-
|
|
1698
|
-
var url = config.readUrl + "/latestblock";
|
|
1699
|
-
|
|
1700
|
-
try {
|
|
1701
|
-
const response = await fetch(url, {
|
|
1702
|
-
headers: reqHeaders,
|
|
1703
|
-
});
|
|
1704
|
-
|
|
1705
|
-
if (response == null) {
|
|
1706
|
-
return new LatestBlockDetailsResult(-100, null, response, requestId);
|
|
1707
|
-
}
|
|
1708
|
-
if (response.status !== 200) {
|
|
1709
|
-
return new LatestBlockDetailsResult(-101, null, response, requestId);
|
|
1710
|
-
}
|
|
1711
|
-
|
|
1712
|
-
const jsonObj = await response.json();
|
|
1713
|
-
if (jsonObj == null) {
|
|
1714
|
-
return new LatestBlockDetailsResult(-102, null, response, requestId);
|
|
1715
|
-
}
|
|
1716
|
-
const result = jsonObj.result;
|
|
1717
|
-
|
|
1718
|
-
if (result == null) {
|
|
1719
|
-
return new LatestBlockDetailsResult(-103, null, response, requestId);
|
|
1720
|
-
}
|
|
1721
|
-
|
|
1722
|
-
if (result.blockNumber == null) {
|
|
1723
|
-
return new LatestBlockDetailsResult(-104, null, response, requestId);
|
|
1724
|
-
}
|
|
1725
|
-
|
|
1726
|
-
let blockNumber = parseInt(result.blockNumber);
|
|
1727
|
-
if (Number.isInteger(blockNumber) === false) {
|
|
1728
|
-
return new LatestBlockDetailsResult(-105, null, response, requestId);
|
|
1729
|
-
}
|
|
1730
|
-
|
|
1731
|
-
var blockDetails = new BlockDetails(blockNumber);
|
|
1732
|
-
return new LatestBlockDetailsResult(0, blockDetails, response, requestId);
|
|
1733
|
-
} catch (error) {
|
|
1734
|
-
return new LatestBlockDetailsResult(-10000, null, null, requestId, error);
|
|
1735
|
-
}
|
|
1736
|
-
}
|
|
1737
|
-
|
|
1738
|
-
/**
|
|
1739
|
-
* The getAccountDetails function returns details of an account corresponding to the address.
|
|
1740
|
-
*
|
|
1741
|
-
* @async
|
|
1742
|
-
* @function getAccountDetails
|
|
1743
|
-
* @param {string} address - The address of the account of which the details have to be retrieved.
|
|
1744
|
-
* @return {Promise<AccountDetailsResult>} Returns a promise of type AccountDetailsResult.
|
|
1745
|
-
*/
|
|
1746
|
-
async function getAccountDetails(address) {
|
|
1747
|
-
if (isInitialized === false) {
|
|
1748
|
-
return -1000;
|
|
1749
|
-
}
|
|
1750
|
-
|
|
1751
|
-
if (address == null) {
|
|
1752
|
-
return new AccountDetailsResult(-200, null, null, null);
|
|
1753
|
-
}
|
|
1754
|
-
if (isAddressValid(address) === false) {
|
|
1755
|
-
return new AccountDetailsResult(-201, null, null, null);
|
|
1756
|
-
}
|
|
1757
|
-
|
|
1758
|
-
let nonce = 0;
|
|
1759
|
-
let balance = "0";
|
|
1760
|
-
let requestId = getRandomRequestId();
|
|
1761
|
-
|
|
1762
|
-
let reqHeaders = new Headers({
|
|
1763
|
-
"Content-Type": "application/json"
|
|
1764
|
-
});
|
|
1765
|
-
reqHeaders.append(REQUEST_ID_HEADER_NAME, requestId);
|
|
1766
|
-
if(config.readApiKey !== null) {
|
|
1767
|
-
reqHeaders.append(API_KEY_HEADER_NAME, config.readApiKey);
|
|
1768
|
-
}
|
|
1769
|
-
|
|
1770
|
-
var url = config.readUrl + "/account/" + address;
|
|
1771
|
-
|
|
1772
|
-
try {
|
|
1773
|
-
const response = await fetch(url, {
|
|
1774
|
-
headers: reqHeaders,
|
|
1775
|
-
});
|
|
1776
|
-
|
|
1777
|
-
if(response == null) {
|
|
1778
|
-
return new AccountDetailsResult(-202, null, response, requestId);
|
|
1779
|
-
}
|
|
1780
|
-
if (response.status !== 200) {
|
|
1781
|
-
return new AccountDetailsResult(-203, null, response, requestId);
|
|
1782
|
-
}
|
|
1783
|
-
|
|
1784
|
-
const jsonObj = await response.json();
|
|
1785
|
-
if (jsonObj == null) {
|
|
1786
|
-
return new AccountDetailsResult(-204, null, response, requestId);
|
|
1787
|
-
}
|
|
1788
|
-
const result = jsonObj.result;
|
|
1789
|
-
|
|
1790
|
-
if (result == null) {
|
|
1791
|
-
return new AccountDetailsResult(-205, null, response, requestId);
|
|
1792
|
-
}
|
|
1793
|
-
|
|
1794
|
-
if(result.blockNumber == null) {
|
|
1795
|
-
return new AccountDetailsResult(-206, null, response, requestId);
|
|
1796
|
-
}
|
|
1797
|
-
|
|
1798
|
-
let blockNumber = parseInt(result.blockNumber);
|
|
1799
|
-
if (Number.isInteger(blockNumber) === false) {
|
|
1800
|
-
return new AccountDetailsResult(-207, null, response, requestId);
|
|
1801
|
-
}
|
|
1802
|
-
|
|
1803
|
-
if (result.nonce === null) {
|
|
1804
|
-
nonce = 0;
|
|
1805
|
-
} else {
|
|
1806
|
-
let tempNonce = parseInt(result.nonce);
|
|
1807
|
-
if (Number.isInteger(tempNonce) === true) {
|
|
1808
|
-
nonce = tempNonce;
|
|
1809
|
-
if (nonce < 0) {
|
|
1810
|
-
return new AccountDetailsResult(-208, null, response, requestId);
|
|
1811
|
-
}
|
|
1812
|
-
} else {
|
|
1813
|
-
return new AccountDetailsResult(-209, null, response, requestId);
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
|
|
1817
|
-
if (result.balance != null) {
|
|
1818
|
-
if (isLargeNumber(result.balance) === false) {
|
|
1819
|
-
return new AccountDetailsResult(-210, null, response, requestId);
|
|
1820
|
-
} else {
|
|
1821
|
-
balance = result.balance;
|
|
1822
|
-
}
|
|
1823
|
-
}
|
|
1824
|
-
|
|
1825
|
-
var accountDetails = new AccountDetails(address, balance, nonce, blockNumber);
|
|
1826
|
-
return new AccountDetailsResult(0, accountDetails, response, requestId);
|
|
1827
|
-
|
|
1828
|
-
} catch (error) {
|
|
1829
|
-
return new AccountDetailsResult(-10000, null, null, requestId, error);
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
|
|
1833
|
-
/**
|
|
1834
|
-
* The getTransactionDetails function returns details of a transaction posted to the blockchain.
|
|
1835
|
-
* Transactions may take a while to get registered in the blockchain. After a transaction is submitted, it may take a while before it is available for reading.
|
|
1836
|
-
* Some transactions that have lower balance than the minimum required for gas fees may be discarded.
|
|
1837
|
-
* In these cases, the transactions may not be returned when invoking the getTransactionDetails function.
|
|
1838
|
-
* You should consider the transaction as succeeded only if the status field of the transactionReceipt object is 0x1 (success).
|
|
1839
|
-
* The transactionReceipt field can be null unless the transaction is registered with the blockchain.
|
|
1840
|
-
* @async
|
|
1841
|
-
* @function getTransactionDetails
|
|
1842
|
-
* @param {string} txnHash - The hash of the transaction to retrieve.
|
|
1843
|
-
* @return {Promise<TransactionDetailsResult>} Returns a promise of type TransactionDetailsResult.
|
|
1844
|
-
*/
|
|
1845
|
-
async function getTransactionDetails(txnHash) {
|
|
1846
|
-
if (isInitialized === false) {
|
|
1847
|
-
return -1000;
|
|
1848
|
-
}
|
|
1849
|
-
|
|
1850
|
-
if (txnHash == null) {
|
|
1851
|
-
return new TransactionDetailsResult(-300, null, null, null);
|
|
1852
|
-
}
|
|
1853
|
-
if (isAddressValid(txnHash) === false) {
|
|
1854
|
-
return new TransactionDetailsResult(-301, null, null, null);
|
|
1855
|
-
}
|
|
1856
|
-
|
|
1857
|
-
let requestId = getRandomRequestId();
|
|
1858
|
-
|
|
1859
|
-
let reqHeaders = new Headers({
|
|
1860
|
-
"Content-Type": "application/json"
|
|
1861
|
-
});
|
|
1862
|
-
reqHeaders.append(REQUEST_ID_HEADER_NAME, requestId);
|
|
1863
|
-
if (config.readApiKey !== null) {
|
|
1864
|
-
reqHeaders.append(API_KEY_HEADER_NAME, config.readApiKey);
|
|
1015
|
+
* @return {Wallet|null} Returns the Wallet corresponding to the walletJson. If the wallet is invalid or the JSON is malformed, null is returned.
|
|
1016
|
+
*/
|
|
1017
|
+
function deserializeWallet(walletJson) {
|
|
1018
|
+
if (isInitialized === false) {
|
|
1019
|
+
return -1000;
|
|
1865
1020
|
}
|
|
1866
1021
|
|
|
1867
|
-
var url = config.readUrl + "/transaction/" + txnHash;
|
|
1868
|
-
|
|
1869
1022
|
try {
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
if (response == null) {
|
|
1875
|
-
return new TransactionDetailsResult(-302, null, response, requestId);
|
|
1876
|
-
}
|
|
1877
|
-
if (response.status !== 200) {
|
|
1878
|
-
return new TransactionDetailsResult(-303, null, response, requestId);
|
|
1879
|
-
}
|
|
1880
|
-
|
|
1881
|
-
const jsonObj = await response.json();
|
|
1882
|
-
if (jsonObj == null) {
|
|
1883
|
-
return new TransactionDetailsResult(-304, null, response, requestId);
|
|
1023
|
+
var tempWallet = JSON.parse(walletJson);
|
|
1024
|
+
if (tempWallet == null || typeof tempWallet !== 'object') {
|
|
1025
|
+
return null;
|
|
1884
1026
|
}
|
|
1885
|
-
const result = jsonObj.result;
|
|
1886
1027
|
|
|
1887
|
-
|
|
1888
|
-
|
|
1028
|
+
var preExpansionSeed = null;
|
|
1029
|
+
if (tempWallet.preExpansionSeed != null && tempWallet.preExpansionSeed.length > 0) {
|
|
1030
|
+
preExpansionSeed = base64ToBytes(tempWallet.preExpansionSeed);
|
|
1889
1031
|
}
|
|
1890
1032
|
|
|
1891
|
-
var
|
|
1033
|
+
var wallet = new Wallet(tempWallet.address, base64ToBytes(tempWallet.privateKey), base64ToBytes(tempWallet.publicKey), preExpansionSeed);
|
|
1892
1034
|
|
|
1893
|
-
if (
|
|
1894
|
-
|
|
1895
|
-
if (Number.isInteger(tempBlockNumber) === true) {
|
|
1896
|
-
transactionDetails.blockNumber = tempBlockNumber;
|
|
1897
|
-
}
|
|
1898
|
-
if (tempBlockNumber < 0) {
|
|
1899
|
-
return new TransactionDetailsResult(-306, null, response, requestId);
|
|
1900
|
-
}
|
|
1035
|
+
if (verifyWallet(wallet) === false) {
|
|
1036
|
+
return null;
|
|
1901
1037
|
}
|
|
1902
1038
|
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
transactionDetails.gasPrice = result.gasPrice;
|
|
1907
|
-
transactionDetails.hash = result.hash;
|
|
1908
|
-
transactionDetails.input = result.input;
|
|
1909
|
-
transactionDetails.nonce = result.nonce;
|
|
1910
|
-
transactionDetails.to = result.to;
|
|
1911
|
-
transactionDetails.value = result.value;
|
|
1912
|
-
|
|
1913
|
-
if(result.receipt !== null) {
|
|
1914
|
-
transactionDetails.receipt = new TransactionReceipt();
|
|
1915
|
-
transactionDetails.receipt.cumulativeGasUsed = result.receipt.cumulativeGasUsed;
|
|
1916
|
-
transactionDetails.receipt.effectiveGasPrice = result.receipt.effectiveGasPrice;
|
|
1917
|
-
transactionDetails.receipt.gasUsed = result.receipt.gasUsed;
|
|
1918
|
-
transactionDetails.receipt.status = result.receipt.status;
|
|
1919
|
-
transactionDetails.receipt.hash = result.receipt.hash;
|
|
1920
|
-
transactionDetails.receipt.type = result.receipt.type;
|
|
1921
|
-
}
|
|
1922
|
-
|
|
1923
|
-
return new TransactionDetailsResult(0, transactionDetails, response, requestId);
|
|
1924
|
-
} catch (error) {
|
|
1925
|
-
return new TransactionDetailsResult(-10000, null, null, requestId, error);
|
|
1039
|
+
return wallet;
|
|
1040
|
+
} catch (e) {
|
|
1041
|
+
return null;
|
|
1926
1042
|
}
|
|
1927
1043
|
}
|
|
1928
1044
|
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
* You should consider the transaction as succeeded only if the status field of the AccountTransactionCompact object is 0x1 (success).
|
|
1935
|
-
* Both transactions from and transactions to the address will be returned in the list.
|
|
1936
|
-
* Use the getTransactionDetails function, passing the hash of the transaction to get detailed information about the transaction.
|
|
1937
|
-
* @async
|
|
1938
|
-
* @function listAccountTransactions
|
|
1939
|
-
* @param {string} address - The address for which the transactions have to be listed.
|
|
1940
|
-
* @param {number} pageNumber - The page number for which the transactions has to be listed for the account. Pass 0 to list the latest page. Pass 1 to list the oldest page. A maximum of 20 transactions are returned in each page. The response of this API includes a field that shows the pageCount (total number of pages available). You can pass any number between 1 to pageCount to get the corresponding page.
|
|
1941
|
-
* @return {Promise<AccountTransactionsResult>} Returns a promise of type AccountTransactionsResult.
|
|
1942
|
-
*/
|
|
1943
|
-
async function listAccountTransactions(address, pageNumber) {
|
|
1944
|
-
if (isInitialized === false) {
|
|
1945
|
-
return -1000;
|
|
1045
|
+
function transactionGetSigningHash(fromaddress, nonce, toaddress, amount, gas, chainid, data) {
|
|
1046
|
+
let messageData = TxnSigningHash(fromaddress, nonce, toaddress, amount, gas, chainid, data);
|
|
1047
|
+
var messageBytes = [];
|
|
1048
|
+
for (var i = 0; i < messageData.length; ++i) {
|
|
1049
|
+
messageBytes.push(messageData.charCodeAt(i));
|
|
1946
1050
|
}
|
|
1051
|
+
return messageBytes;
|
|
1052
|
+
}
|
|
1947
1053
|
|
|
1948
|
-
|
|
1949
|
-
|
|
1054
|
+
function transactionGetTransactionHash(fromaddress, nonce, toaddress, amount, gas, chainid, data, pkkey, sig) {
|
|
1055
|
+
const arrayPkDataToPass = pkkey.toString().split(",");
|
|
1056
|
+
const typedPkArray = new Uint8Array(arrayPkDataToPass.length);
|
|
1057
|
+
for (let i = 0; i < arrayPkDataToPass.length; i++) {
|
|
1058
|
+
typedPkArray[i] = arrayPkDataToPass[i];
|
|
1950
1059
|
}
|
|
1951
|
-
|
|
1952
|
-
|
|
1060
|
+
const arraySigDataToPass = sig.toString().split(",");
|
|
1061
|
+
const typedSigArray = new Uint8Array(arraySigDataToPass.length);
|
|
1062
|
+
for (let i = 0; i < arraySigDataToPass.length; i++) {
|
|
1063
|
+
typedSigArray[i] = arraySigDataToPass[i];
|
|
1953
1064
|
}
|
|
1065
|
+
var txnHash = TxnHash(fromaddress, nonce, toaddress, amount, gas, chainid, data, typedPkArray, typedSigArray)
|
|
1066
|
+
return txnHash;
|
|
1067
|
+
}
|
|
1954
1068
|
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1069
|
+
function transactionGetData(fromaddress, nonce, toaddress, amount, gas, chainid, data, pkkey, sig) {
|
|
1070
|
+
const arrayPkDataToPass = pkkey.toString().split(",");
|
|
1071
|
+
const typedPkArray = new Uint8Array(arrayPkDataToPass.length);
|
|
1072
|
+
for (let i = 0; i < arrayPkDataToPass.length; i++) {
|
|
1073
|
+
typedPkArray[i] = arrayPkDataToPass[i];
|
|
1959
1074
|
}
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
"Content-Type": "application/json"
|
|
1965
|
-
});
|
|
1966
|
-
reqHeaders.append(REQUEST_ID_HEADER_NAME, requestId);
|
|
1967
|
-
if (config.readApiKey !== null) {
|
|
1968
|
-
reqHeaders.append(API_KEY_HEADER_NAME, config.readApiKey);
|
|
1075
|
+
const arraySigDataToPass = sig.toString().split(",");
|
|
1076
|
+
const typedSigArray = new Uint8Array(arraySigDataToPass.length);
|
|
1077
|
+
for (let i = 0; i < arraySigDataToPass.length; i++) {
|
|
1078
|
+
typedSigArray[i] = arraySigDataToPass[i];
|
|
1969
1079
|
}
|
|
1080
|
+
var txnData = TxnData(fromaddress, nonce, toaddress, amount, gas, chainid, data, typedPkArray, typedSigArray)
|
|
1081
|
+
return txnData;
|
|
1082
|
+
}
|
|
1970
1083
|
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
}
|
|
1984
|
-
|
|
1985
|
-
const jsonObj = await response.json();
|
|
1986
|
-
|
|
1987
|
-
if (jsonObj === null) {
|
|
1988
|
-
return new AccountTransactionsResult(-705, null, response, requestId);
|
|
1989
|
-
}
|
|
1990
|
-
const result = jsonObj;
|
|
1991
|
-
|
|
1992
|
-
if (result.pageCount === null) {
|
|
1993
|
-
return new AccountTransactionsResult(-706, null, response, requestId);
|
|
1994
|
-
}
|
|
1084
|
+
function transactionGetSigningHash2(fromaddress, nonce, toaddress, valueInWeiHex, gas, chainid, data, remarks, signingContext) {
|
|
1085
|
+
let messageDataReturn = TxnSigningHash2(fromaddress, nonce, toaddress, valueInWeiHex, gas, chainid, data, remarks, signingContext);
|
|
1086
|
+
if (messageDataReturn && messageDataReturn.error) {
|
|
1087
|
+
return null;
|
|
1088
|
+
}
|
|
1089
|
+
var messageData = messageDataReturn.result;
|
|
1090
|
+
var messageBytes = [];
|
|
1091
|
+
for (var i = 0; i < messageData.length; ++i) {
|
|
1092
|
+
messageBytes.push(messageData.charCodeAt(i));
|
|
1093
|
+
}
|
|
1094
|
+
return messageBytes;
|
|
1095
|
+
}
|
|
1995
1096
|
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
txn.to = item.to;
|
|
2014
|
-
txn.value = item.value;
|
|
2015
|
-
txn.status = item.status;
|
|
2016
|
-
listAccountDetailsResponse.items.push(txn);
|
|
2017
|
-
}
|
|
2018
|
-
}
|
|
1097
|
+
function transactionGetTransactionHash2(fromaddress, nonce, toaddress, valueInWeiHex, gas, chainid, data, remarks, signingContext, pkkey, sig) {
|
|
1098
|
+
const arrayPkDataToPass = pkkey.toString().split(",");
|
|
1099
|
+
const typedPkArray = new Uint8Array(arrayPkDataToPass.length);
|
|
1100
|
+
for (let i = 0; i < arrayPkDataToPass.length; i++) {
|
|
1101
|
+
typedPkArray[i] = arrayPkDataToPass[i];
|
|
1102
|
+
}
|
|
1103
|
+
const arraySigDataToPass = sig.toString().split(",");
|
|
1104
|
+
const typedSigArray = new Uint8Array(arraySigDataToPass.length);
|
|
1105
|
+
for (let i = 0; i < arraySigDataToPass.length; i++) {
|
|
1106
|
+
typedSigArray[i] = arraySigDataToPass[i];
|
|
1107
|
+
}
|
|
1108
|
+
var txnHashReturn = TxnHash2(fromaddress, nonce, toaddress, valueInWeiHex, gas, chainid, data, remarks, signingContext, typedPkArray, typedSigArray)
|
|
1109
|
+
if (txnHashReturn && txnHashReturn.error) {
|
|
1110
|
+
return null;
|
|
1111
|
+
}
|
|
1112
|
+
return txnHashReturn.result;
|
|
1113
|
+
}
|
|
2019
1114
|
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
1115
|
+
function transactionGetData2(fromaddress, nonce, toaddress, valueInWeiHex, gas, chainid, data, remarks, signingContext, pkkey, sig) {
|
|
1116
|
+
const arrayPkDataToPass = pkkey.toString().split(",");
|
|
1117
|
+
const typedPkArray = new Uint8Array(arrayPkDataToPass.length);
|
|
1118
|
+
for (let i = 0; i < arrayPkDataToPass.length; i++) {
|
|
1119
|
+
typedPkArray[i] = arrayPkDataToPass[i];
|
|
1120
|
+
}
|
|
1121
|
+
const arraySigDataToPass = sig.toString().split(",");
|
|
1122
|
+
const typedSigArray = new Uint8Array(arraySigDataToPass.length);
|
|
1123
|
+
for (let i = 0; i < arraySigDataToPass.length; i++) {
|
|
1124
|
+
typedSigArray[i] = arraySigDataToPass[i];
|
|
1125
|
+
}
|
|
1126
|
+
var txnDataReturn = TxnData2(fromaddress, nonce, toaddress, valueInWeiHex, gas, chainid, data, remarks, signingContext, typedPkArray, typedSigArray)
|
|
1127
|
+
if (txnDataReturn && txnDataReturn.error) {
|
|
1128
|
+
return null;
|
|
2023
1129
|
}
|
|
1130
|
+
return txnDataReturn.result;
|
|
2024
1131
|
}
|
|
2025
1132
|
|
|
2026
1133
|
/**
|
|
2027
1134
|
* The signSendCoinTransaction function returns a signed transaction. The chainId used for signing should be provided in the initialize() function.
|
|
2028
1135
|
* Since the gas fee for sending coins is fixed at 1000 coins, there is no option to set the gas fee explicitly.
|
|
2029
|
-
* This function is useful for offline (cold storage) wallets, where you can sign a transaction offline and then
|
|
2030
|
-
* Another usecase for this function is when you want to first store a signed transaction to a database, then queue it and finally
|
|
1136
|
+
* This function is useful for offline (cold storage) wallets, where you can sign a transaction offline and then broadcast it from a connected device (for example, via a relay or RPC endpoint).
|
|
1137
|
+
* Another usecase for this function is when you want to first store a signed transaction to a database, then queue it and finally broadcast the transaction from a connected device.
|
|
2031
1138
|
*
|
|
2032
1139
|
* @deprecated Use signRawTransaction instead.
|
|
2033
1140
|
* @function signSendCoinTransaction
|
|
2034
1141
|
* @param {Wallet} wallet - A Wallet object from which the transaction has to be sent. The address corresponding to the Wallet should have enough coins to cover gas fees as well. A minimum of 1000 coins (1000000000000000000000 wei) are required for gas fees.
|
|
2035
1142
|
* @param {string} toAddress - The address to which the coins should be sent.
|
|
2036
1143
|
* @param {string} coins - The string representing the number of coins (in ether) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei
|
|
2037
|
-
* @param {number} nonce -
|
|
1144
|
+
* @param {number} nonce - A monotonically increasing number representing the nonce of the account. You have to carefully manage the state of the nonce to avoid sending the coins multiple times, such as when retrying after an error.
|
|
2038
1145
|
* @return {Promise<SignResult>} Returns a promise of type SignResult.
|
|
2039
1146
|
*/
|
|
2040
1147
|
async function signSendCoinTransaction(wallet, toAddress, coins, nonce) {
|
|
@@ -2107,15 +1214,15 @@ async function signSendCoinTransaction(wallet, toAddress, coins, nonce) {
|
|
|
2107
1214
|
/**
|
|
2108
1215
|
* The signTransaction function returns a signed transaction. The chainId used for signing should be provided in the initialize() function.
|
|
2109
1216
|
* Since the gas fee for sending coins is fixed at 1000 coins, there is no option to set the gas fee explicitly.
|
|
2110
|
-
* This function is useful for offline (cold storage) wallets, where you can sign a transaction offline and then
|
|
2111
|
-
* Another usecase for this function is when you want to first store a signed transaction to a database, then queue it and finally
|
|
1217
|
+
* This function is useful for offline (cold storage) wallets, where you can sign a transaction offline and then broadcast it from a connected device (for example, via a relay or RPC endpoint).
|
|
1218
|
+
* Another usecase for this function is when you want to first store a signed transaction to a database, then queue it and finally broadcast the transaction from a connected device.
|
|
2112
1219
|
*
|
|
2113
1220
|
* @deprecated Use signRawTransaction instead.
|
|
2114
1221
|
* @function signTransaction
|
|
2115
1222
|
* @param {Wallet} wallet - A Wallet object from which the transaction has to be sent. The address corresponding to the Wallet should have enough coins to cover gas fees as well. A minimum of 1000 coins (1000000000000000000000 wei) are required for gas fees.
|
|
2116
1223
|
* @param {string} toAddress - The address to which the coins should be sent.
|
|
2117
1224
|
* @param {string} coins - The string representing the number of coins (in ether) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei
|
|
2118
|
-
* @param {number} nonce -
|
|
1225
|
+
* @param {number} nonce - A monotonically increasing number representing the nonce of the account. You have to carefully manage the state of the nonce to avoid sending the coins multiple times, such as when retrying after an error.
|
|
2119
1226
|
* @param {string} data - Ignored. This parameter is accepted but not used. Use signRawTransaction to pass contract data.
|
|
2120
1227
|
* @return {Promise<SignResult>} Returns a promise of type SignResult.
|
|
2121
1228
|
*/
|
|
@@ -2225,8 +1332,8 @@ function hexStringToUint8Array(hex) {
|
|
|
2225
1332
|
* With this function, you can set the gasLimit explicitly compared to signTransaction.
|
|
2226
1333
|
* You can also pass data to be signed, such as when creating or invoking a smart contract.
|
|
2227
1334
|
* Since the gas fee is fixed at 1000 coins for 21000 units of gas, there is no option to set the gas fee explicitly.
|
|
2228
|
-
* This function is useful for offline (cold storage) wallets, where you can sign a transaction offline and then
|
|
2229
|
-
* Another usecase for this function is when you want to first store a signed transaction to a database, then queue it and finally
|
|
1335
|
+
* This function is useful for offline (cold storage) wallets, where you can sign a transaction offline and then broadcast it from a connected device (for example, via a relay or RPC endpoint).
|
|
1336
|
+
* Another usecase for this function is when you want to first store a signed transaction to a database, then queue it and finally broadcast the transaction from a connected device.
|
|
2230
1337
|
*
|
|
2231
1338
|
* @function signRawTransaction
|
|
2232
1339
|
* @param {TransactionSigningRequest} transactionSigningRequest - An object of type TransactionSigningRequest with the transaction signing details.
|
|
@@ -2498,104 +1605,6 @@ function verify(publicKey, signature, message) {
|
|
|
2498
1605
|
return { resultCode: 0, valid: true };
|
|
2499
1606
|
}
|
|
2500
1607
|
|
|
2501
|
-
/**
|
|
2502
|
-
* The sendCoins function posts a send-coin transaction to the blockchain. The chainId used for signing should be provided in the initialize() function.
|
|
2503
|
-
* Since the gas fee for sending coins is fixed at 1000 coins, there is no option to set the gas fee explicitly.
|
|
2504
|
-
* It may take many seconds after submitting a transaction before the transaction is returned by the getTransactionDetails function.
|
|
2505
|
-
* Transactions are usually committed in less than 30 seconds.
|
|
2506
|
-
*
|
|
2507
|
-
* @deprecated Use signRawTransaction and postTransaction instead.
|
|
2508
|
-
* @async
|
|
2509
|
-
* @function sendCoins
|
|
2510
|
-
* @param {Wallet} wallet - A Wallet object from which the transaction has to be sent. The address corresponding to the Wallet should have enough coins to cover gas fees as well. A minimum of 1000 coins (1000000000000000000000 wei) are required for gas fees.
|
|
2511
|
-
* @param {string} toAddress - The address to which the coins should be sent.
|
|
2512
|
-
* @param {string} coins - The string representing the number of coins (in ether) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei
|
|
2513
|
-
* @param {number} nonce - The nonce of the account retrieved by invoking the getAccountDetails function. You have to carefully manage state of the nonce to avoid sending the coins multiple times, such as when retrying sendCoins after a network error.
|
|
2514
|
-
* @return {Promise<SendResult>} Returns a promise of type SendResult.
|
|
2515
|
-
*/
|
|
2516
|
-
async function sendCoins(wallet, toAddress, coins, nonce) {
|
|
2517
|
-
if (isInitialized === false) {
|
|
2518
|
-
return -1000;
|
|
2519
|
-
}
|
|
2520
|
-
|
|
2521
|
-
if (wallet == null || toAddress == null || coins == null || nonce == null) {
|
|
2522
|
-
return new SendResult(-1, null, null, null);
|
|
2523
|
-
}
|
|
2524
|
-
|
|
2525
|
-
if (isAddressValid(toAddress) === false) {
|
|
2526
|
-
return new SendResult(-2, null, null, null);
|
|
2527
|
-
}
|
|
2528
|
-
|
|
2529
|
-
if (verifyWallet(wallet) === false) {
|
|
2530
|
-
return new SendResult(-3, null, null, null);
|
|
2531
|
-
}
|
|
2532
|
-
|
|
2533
|
-
if (isLargeNumber(coins) === false) {
|
|
2534
|
-
return new SendResult(-4, null, null, null);
|
|
2535
|
-
}
|
|
2536
|
-
|
|
2537
|
-
let tempNonce = parseInt(nonce);
|
|
2538
|
-
if (Number.isInteger(tempNonce) === false) {
|
|
2539
|
-
return new SendResult(-5, null, null, null);
|
|
2540
|
-
}
|
|
2541
|
-
nonce = tempNonce;
|
|
2542
|
-
if (nonce < 0) {
|
|
2543
|
-
return new SendResult(-6, null, null, null);
|
|
2544
|
-
}
|
|
2545
|
-
|
|
2546
|
-
let accountDetailsResult = await getAccountDetails(wallet.address);
|
|
2547
|
-
if (accountDetailsResult === null) {
|
|
2548
|
-
return new SendResult(-7, null, null, null);
|
|
2549
|
-
}
|
|
2550
|
-
|
|
2551
|
-
if (accountDetailsResult.resultCode !== 0) {
|
|
2552
|
-
return new SendResult(-7, null, null, null);
|
|
2553
|
-
}
|
|
2554
|
-
|
|
2555
|
-
if (accountDetailsResult.accountDetails.nonce !== nonce) {
|
|
2556
|
-
return new SendResult(-8, null, null, null);
|
|
2557
|
-
}
|
|
2558
|
-
|
|
2559
|
-
const contractData = null;
|
|
2560
|
-
|
|
2561
|
-
var txSigningHash = transactionGetSigningHash(wallet.address, nonce, toAddress, coins, DEFAULT_GAS, config.chainId, contractData);
|
|
2562
|
-
if (txSigningHash == null) {
|
|
2563
|
-
return new SendResult(-9, null, null, null);
|
|
2564
|
-
}
|
|
2565
|
-
const txSigningHashU8 = toUint8Array(txSigningHash);
|
|
2566
|
-
const hybridedsNs = circl && circl.hybrideds;
|
|
2567
|
-
if (!hybridedsNs) {
|
|
2568
|
-
return new SendResult(-10, null, null, null);
|
|
2569
|
-
}
|
|
2570
|
-
const sigRes = hybridedsNs.signCompact(toUint8Array(wallet.privateKey), txSigningHashU8);
|
|
2571
|
-
if (sigRes && sigRes.error) {
|
|
2572
|
-
return new SendResult(-10, null, null, null);
|
|
2573
|
-
}
|
|
2574
|
-
const verRes = hybridedsNs.verifyCompact(toUint8Array(wallet.publicKey), txSigningHashU8, sigRes.result);
|
|
2575
|
-
if (verRes && verRes.error) {
|
|
2576
|
-
return new SendResult(-10, null, null, null);
|
|
2577
|
-
}
|
|
2578
|
-
if (verRes.result !== true) {
|
|
2579
|
-
return new SendResult(-10, null, null, null);
|
|
2580
|
-
}
|
|
2581
|
-
const quantumSig = sigRes.result instanceof Uint8Array ? Array.from(sigRes.result) : sigRes.result;
|
|
2582
|
-
|
|
2583
|
-
var txHashHex = transactionGetTransactionHash(wallet.address, nonce, toAddress, coins, DEFAULT_GAS, config.chainId, contractData, wallet.publicKey, quantumSig);
|
|
2584
|
-
if (txHashHex == null) {
|
|
2585
|
-
return new SendResult(-11, null, null, null);
|
|
2586
|
-
}
|
|
2587
|
-
|
|
2588
|
-
var txnData = transactionGetData(wallet.address, nonce, toAddress, coins, DEFAULT_GAS, config.chainId, contractData, wallet.publicKey, quantumSig);
|
|
2589
|
-
if (txnData == null) {
|
|
2590
|
-
return new SendResult(-12, null, null, null);
|
|
2591
|
-
}
|
|
2592
|
-
|
|
2593
|
-
let sendResult = await postTransaction(txnData);
|
|
2594
|
-
sendResult.txnHash = txHashHex;
|
|
2595
|
-
|
|
2596
|
-
return sendResult;
|
|
2597
|
-
}
|
|
2598
|
-
|
|
2599
1608
|
/**
|
|
2600
1609
|
* The publicKeyFromSignature extracts the public key from a signature.
|
|
2601
1610
|
*
|
|
@@ -2665,24 +1674,25 @@ function addressFromPublicKey(publicKey) {
|
|
|
2665
1674
|
/**
|
|
2666
1675
|
* The scryptDeriveKey function derives a key from a secret and salt using the scrypt KDF.
|
|
2667
1676
|
*
|
|
2668
|
-
*
|
|
2669
|
-
*
|
|
1677
|
+
* Arbitrary scrypt parameters are supported. The classic set N=262144, r=8, p=1, dkLen=32
|
|
1678
|
+
* remains fully supported and byte-for-byte compatible with previous versions.
|
|
2670
1679
|
*
|
|
2671
1680
|
* @function scryptDeriveKey
|
|
2672
|
-
* @param {string} secret - The secret/passphrase
|
|
1681
|
+
* @param {string|Uint8Array|number[]} secret - The secret/passphrase. A string is encoded as UTF-8 bytes.
|
|
2673
1682
|
* @param {Uint8Array|number[]} salt - The salt as a byte array.
|
|
2674
|
-
* @param {number} N - The scrypt CPU/memory cost parameter
|
|
2675
|
-
* @param {number} r - The scrypt block size parameter.
|
|
2676
|
-
* @param {number} p - The scrypt parallelization parameter.
|
|
2677
|
-
* @param {number} dkLen - The derived key length in bytes.
|
|
2678
|
-
* @return {number[]} - Returns the
|
|
1683
|
+
* @param {number} N - The scrypt CPU/memory cost parameter (power of two, > 1).
|
|
1684
|
+
* @param {number} r - The scrypt block size parameter.
|
|
1685
|
+
* @param {number} p - The scrypt parallelization parameter.
|
|
1686
|
+
* @param {number} dkLen - The derived key length in bytes.
|
|
1687
|
+
* @return {number[]} - Returns the derived key as a byte array. Returns -1000 before initialize(), or null if the operation failed or the parameters are invalid.
|
|
2679
1688
|
*/
|
|
2680
1689
|
function scryptDeriveKey(secret, salt, N, r, p, dkLen) {
|
|
2681
1690
|
if (isInitialized === false) {
|
|
2682
1691
|
return -1000;
|
|
2683
1692
|
}
|
|
2684
1693
|
|
|
2685
|
-
|
|
1694
|
+
const secretU8 = toU8Secret(secret);
|
|
1695
|
+
if (secretU8 === null) {
|
|
2686
1696
|
return null;
|
|
2687
1697
|
}
|
|
2688
1698
|
|
|
@@ -2694,14 +1704,11 @@ function scryptDeriveKey(secret, salt, N, r, p, dkLen) {
|
|
|
2694
1704
|
return null;
|
|
2695
1705
|
}
|
|
2696
1706
|
|
|
2697
|
-
if (N !== SCRYPT_SUPPORTED_N || r !== SCRYPT_SUPPORTED_R || p !== SCRYPT_SUPPORTED_P || dkLen !== SCRYPT_SUPPORTED_DKLEN) {
|
|
2698
|
-
return null;
|
|
2699
|
-
}
|
|
2700
|
-
|
|
2701
1707
|
const saltU8 = salt instanceof Uint8Array ? salt : new Uint8Array(salt);
|
|
1708
|
+
const secretBase64 = bytesToBase64(secretU8);
|
|
2702
1709
|
const saltBase64 = bytesToBase64(saltU8);
|
|
2703
1710
|
|
|
2704
|
-
const derivedBase64 = Scrypt(
|
|
1711
|
+
const derivedBase64 = Scrypt(secretBase64, saltBase64, N, r, p, dkLen);
|
|
2705
1712
|
if (derivedBase64 == null || (typeof derivedBase64 !== 'string' && !(derivedBase64 instanceof String))) {
|
|
2706
1713
|
return null;
|
|
2707
1714
|
}
|
|
@@ -2709,6 +1716,135 @@ function scryptDeriveKey(secret, salt, N, r, p, dkLen) {
|
|
|
2709
1716
|
return Array.from(base64ToBytes(derivedBase64));
|
|
2710
1717
|
}
|
|
2711
1718
|
|
|
1719
|
+
/**
|
|
1720
|
+
* Computes a hash digest using the given WASM hash call.
|
|
1721
|
+
* @param {function(string): *} wasmCall - Thunk invoking the WASM global with a base64 string.
|
|
1722
|
+
* Passed as a thunk so the (bare) WASM global is only referenced after the
|
|
1723
|
+
* isInitialized guard - before WASM init the global does not exist.
|
|
1724
|
+
* @param {string|Uint8Array|number[]} data - Data to hash (string -> UTF-8 bytes).
|
|
1725
|
+
* @return {number[]|number|null} Byte array digest, -1000 before init, or null on invalid input.
|
|
1726
|
+
*/
|
|
1727
|
+
function _digest(wasmCall, data) {
|
|
1728
|
+
if (isInitialized === false) {
|
|
1729
|
+
return -1000;
|
|
1730
|
+
}
|
|
1731
|
+
const dataU8 = toU8Secret(data);
|
|
1732
|
+
if (dataU8 === null) {
|
|
1733
|
+
return null;
|
|
1734
|
+
}
|
|
1735
|
+
const outBase64 = wasmCall(bytesToBase64(dataU8));
|
|
1736
|
+
if (outBase64 == null || (typeof outBase64 !== 'string' && !(outBase64 instanceof String))) {
|
|
1737
|
+
return null;
|
|
1738
|
+
}
|
|
1739
|
+
return Array.from(base64ToBytes(outBase64));
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
/**
|
|
1743
|
+
* The sha256 function computes the SHA-256 digest of the input.
|
|
1744
|
+
*
|
|
1745
|
+
* @function sha256
|
|
1746
|
+
* @param {string|Uint8Array|number[]} data - The data to hash (string -> UTF-8 bytes).
|
|
1747
|
+
* @return {number[]} - The 32-byte digest as a byte array. Returns -1000 before initialize(), or null on invalid input.
|
|
1748
|
+
*/
|
|
1749
|
+
function sha256(data) {
|
|
1750
|
+
return _digest((b64) => Sha256(b64), data);
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
/**
|
|
1754
|
+
* The sha512 function computes the SHA-512 digest of the input.
|
|
1755
|
+
*
|
|
1756
|
+
* @function sha512
|
|
1757
|
+
* @param {string|Uint8Array|number[]} data - The data to hash (string -> UTF-8 bytes).
|
|
1758
|
+
* @return {number[]} - The 64-byte digest as a byte array. Returns -1000 before initialize(), or null on invalid input.
|
|
1759
|
+
*/
|
|
1760
|
+
function sha512(data) {
|
|
1761
|
+
return _digest((b64) => Sha512(b64), data);
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
/**
|
|
1765
|
+
* The keccak256 function computes the Keccak-256 digest of the input.
|
|
1766
|
+
* This is the Ethereum-style Keccak-256 (legacy padding), not SHA3-256.
|
|
1767
|
+
*
|
|
1768
|
+
* @function keccak256
|
|
1769
|
+
* @param {string|Uint8Array|number[]} data - The data to hash (string -> UTF-8 bytes).
|
|
1770
|
+
* @return {number[]} - The 32-byte digest as a byte array. Returns -1000 before initialize(), or null on invalid input.
|
|
1771
|
+
*/
|
|
1772
|
+
function keccak256(data) {
|
|
1773
|
+
return _digest((b64) => Keccak256(b64), data);
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
/**
|
|
1777
|
+
* The ripemd160 function computes the RIPEMD-160 digest of the input.
|
|
1778
|
+
*
|
|
1779
|
+
* @function ripemd160
|
|
1780
|
+
* @param {string|Uint8Array|number[]} data - The data to hash (string -> UTF-8 bytes).
|
|
1781
|
+
* @return {number[]} - The 20-byte digest as a byte array. Returns -1000 before initialize(), or null on invalid input.
|
|
1782
|
+
*/
|
|
1783
|
+
function ripemd160(data) {
|
|
1784
|
+
return _digest((b64) => Ripemd160(b64), data);
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
/**
|
|
1788
|
+
* The computeHmac function computes an HMAC over the data using the given key.
|
|
1789
|
+
*
|
|
1790
|
+
* @function computeHmac
|
|
1791
|
+
* @param {string} algorithm - The hash algorithm: "sha256" or "sha512".
|
|
1792
|
+
* @param {string|Uint8Array|number[]} key - The HMAC key (string -> UTF-8 bytes).
|
|
1793
|
+
* @param {string|Uint8Array|number[]} data - The data to authenticate (string -> UTF-8 bytes).
|
|
1794
|
+
* @return {number[]} - The HMAC as a byte array. Returns -1000 before initialize(), or null on invalid input.
|
|
1795
|
+
*/
|
|
1796
|
+
function computeHmac(algorithm, key, data) {
|
|
1797
|
+
if (isInitialized === false) {
|
|
1798
|
+
return -1000;
|
|
1799
|
+
}
|
|
1800
|
+
if (typeof algorithm !== 'string' && !(algorithm instanceof String)) {
|
|
1801
|
+
return null;
|
|
1802
|
+
}
|
|
1803
|
+
const keyU8 = toU8Secret(key);
|
|
1804
|
+
const dataU8 = toU8Secret(data);
|
|
1805
|
+
if (keyU8 === null || dataU8 === null) {
|
|
1806
|
+
return null;
|
|
1807
|
+
}
|
|
1808
|
+
const outBase64 = ComputeHmac(String(algorithm), bytesToBase64(keyU8), bytesToBase64(dataU8));
|
|
1809
|
+
if (outBase64 == null || (typeof outBase64 !== 'string' && !(outBase64 instanceof String))) {
|
|
1810
|
+
return null;
|
|
1811
|
+
}
|
|
1812
|
+
return Array.from(base64ToBytes(outBase64));
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
/**
|
|
1816
|
+
* The pbkdf2 function derives a key using PBKDF2.
|
|
1817
|
+
*
|
|
1818
|
+
* @function pbkdf2
|
|
1819
|
+
* @param {string|Uint8Array|number[]} password - The password (string -> UTF-8 bytes).
|
|
1820
|
+
* @param {Uint8Array|number[]} salt - The salt as a byte array.
|
|
1821
|
+
* @param {number} iterations - The iteration count (positive integer).
|
|
1822
|
+
* @param {number} keylen - The derived key length in bytes (positive integer).
|
|
1823
|
+
* @param {string} algorithm - The PRF hash algorithm: "sha256" or "sha512".
|
|
1824
|
+
* @return {number[]} - The derived key as a byte array. Returns -1000 before initialize(), or null on invalid input.
|
|
1825
|
+
*/
|
|
1826
|
+
function pbkdf2(password, salt, iterations, keylen, algorithm) {
|
|
1827
|
+
if (isInitialized === false) {
|
|
1828
|
+
return -1000;
|
|
1829
|
+
}
|
|
1830
|
+
const passwordU8 = toU8Secret(password);
|
|
1831
|
+
if (passwordU8 === null || isByteArray(salt) === false) {
|
|
1832
|
+
return null;
|
|
1833
|
+
}
|
|
1834
|
+
if (typeof iterations !== 'number' || typeof keylen !== 'number') {
|
|
1835
|
+
return null;
|
|
1836
|
+
}
|
|
1837
|
+
if (typeof algorithm !== 'string' && !(algorithm instanceof String)) {
|
|
1838
|
+
return null;
|
|
1839
|
+
}
|
|
1840
|
+
const saltU8 = salt instanceof Uint8Array ? salt : new Uint8Array(salt);
|
|
1841
|
+
const outBase64 = Pbkdf2(bytesToBase64(passwordU8), bytesToBase64(saltU8), iterations, keylen, String(algorithm));
|
|
1842
|
+
if (outBase64 == null || (typeof outBase64 !== 'string' && !(outBase64 instanceof String))) {
|
|
1843
|
+
return null;
|
|
1844
|
+
}
|
|
1845
|
+
return Array.from(base64ToBytes(outBase64));
|
|
1846
|
+
}
|
|
1847
|
+
|
|
2712
1848
|
/**
|
|
2713
1849
|
* The combinePublicKeySignature combines the public key and signature.
|
|
2714
1850
|
*
|
|
@@ -3186,27 +2322,10 @@ module.exports = {
|
|
|
3186
2322
|
deserializeEncryptedWallet,
|
|
3187
2323
|
verifyWallet,
|
|
3188
2324
|
newWallet,
|
|
3189
|
-
sendCoins,
|
|
3190
|
-
getAccountDetails,
|
|
3191
|
-
getTransactionDetails,
|
|
3192
2325
|
isAddressValid,
|
|
3193
|
-
getLatestBlockDetails,
|
|
3194
2326
|
signSendCoinTransaction,
|
|
3195
|
-
listAccountTransactions,
|
|
3196
|
-
postTransaction,
|
|
3197
2327
|
Config,
|
|
3198
2328
|
Wallet,
|
|
3199
|
-
BlockDetails,
|
|
3200
|
-
LatestBlockDetailsResult,
|
|
3201
|
-
AccountDetails,
|
|
3202
|
-
AccountDetailsResult,
|
|
3203
|
-
SendResult,
|
|
3204
|
-
TransactionReceipt,
|
|
3205
|
-
TransactionDetails,
|
|
3206
|
-
TransactionDetailsResult,
|
|
3207
|
-
AccountTransactionsResult,
|
|
3208
|
-
ListAccountTransactionsResponse,
|
|
3209
|
-
AccountTransactionCompact,
|
|
3210
2329
|
newWalletSeedWords,
|
|
3211
2330
|
openWalletFromSeed,
|
|
3212
2331
|
openWalletFromSeedWords,
|
|
@@ -3214,6 +2333,12 @@ module.exports = {
|
|
|
3214
2333
|
publicKeyFromPrivateKey,
|
|
3215
2334
|
addressFromPublicKey,
|
|
3216
2335
|
scryptDeriveKey,
|
|
2336
|
+
sha256,
|
|
2337
|
+
sha512,
|
|
2338
|
+
keccak256,
|
|
2339
|
+
ripemd160,
|
|
2340
|
+
computeHmac,
|
|
2341
|
+
pbkdf2,
|
|
3217
2342
|
combinePublicKeySignature,
|
|
3218
2343
|
TransactionSigningRequest,
|
|
3219
2344
|
signRawTransaction,
|