@aeternity/aepp-sdk 11.0.0 → 12.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/LICENSE +1 -1
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -22
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +2 -1
- package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +20764 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +37 -0
- package/es/AeSdk.mjs +81 -0
- package/es/AeSdk.mjs.map +1 -0
- package/es/AeSdkAepp.d.ts +70 -0
- package/es/AeSdkAepp.mjs +176 -0
- package/es/AeSdkAepp.mjs.map +1 -0
- package/es/AeSdkBase.d.ts +213 -0
- package/es/AeSdkBase.mjs +314 -0
- package/es/AeSdkBase.mjs.map +1 -0
- package/es/AeSdkWallet.d.ts +104 -0
- package/es/AeSdkWallet.mjs +326 -0
- package/es/AeSdkWallet.mjs.map +1 -0
- package/es/Node.d.ts +41 -0
- package/es/Node.mjs +147 -0
- package/es/Node.mjs.map +1 -0
- package/es/account/Base.d.ts +68 -0
- package/es/account/Base.mjs +123 -0
- package/es/account/Base.mjs.map +1 -0
- package/es/account/Memory.d.ts +26 -0
- package/es/account/Memory.mjs +103 -0
- package/es/account/Memory.mjs.map +1 -0
- package/es/account/Rpc.d.ts +27 -0
- package/es/account/Rpc.mjs +80 -0
- package/es/account/Rpc.mjs.map +1 -0
- package/es/aens.d.ts +222 -0
- package/es/aens.mjs +338 -0
- package/es/aens.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/Browser.d.ts +33 -0
- package/es/aepp-wallet-communication/connection/Browser.mjs +73 -0
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +18 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +58 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +36 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +146 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection-proxy.d.ts +11 -0
- package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +16 -11
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +34 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +169 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -0
- package/es/aepp-wallet-communication/rpc/types.d.ts +77 -0
- package/es/aepp-wallet-communication/rpc/types.mjs +3 -0
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -0
- package/es/aepp-wallet-communication/schema.d.ts +105 -46
- package/es/aepp-wallet-communication/schema.mjs +251 -0
- package/es/aepp-wallet-communication/schema.mjs.map +1 -0
- package/es/aepp-wallet-communication/wallet-detector.d.ts +25 -0
- package/es/aepp-wallet-communication/wallet-detector.mjs +62 -0
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/apis/compiler/compiler.d.ts +92 -0
- package/es/apis/compiler/compiler.mjs +576 -0
- package/es/apis/compiler/compiler.mjs.map +1 -0
- package/es/apis/compiler/index.d.ts +2 -0
- package/es/apis/compiler/index.mjs +3 -0
- package/es/apis/compiler/index.mjs.map +1 -0
- package/es/apis/compiler/models/index.d.ts +248 -0
- package/es/apis/compiler/models/index.mjs +48 -0
- package/es/apis/compiler/models/index.mjs.map +1 -0
- package/es/apis/compiler/models/mappers.d.ts +23 -0
- package/es/apis/compiler/models/mappers.mjs +585 -0
- package/es/apis/compiler/models/mappers.mjs.map +1 -0
- package/es/apis/compiler/models/parameters.d.ts +13 -0
- package/es/apis/compiler/models/parameters.mjs +71 -0
- package/es/apis/compiler/models/parameters.mjs.map +1 -0
- package/es/apis/node/index.d.ts +2 -0
- package/es/apis/node/index.mjs +3 -0
- package/es/apis/node/index.mjs.map +1 -0
- package/es/apis/node/models/index.d.ts +1065 -0
- package/es/apis/node/models/index.mjs +2 -0
- package/es/apis/node/models/index.mjs.map +1 -0
- package/es/apis/node/models/mappers.d.ts +95 -0
- package/es/apis/node/models/mappers.mjs +4166 -0
- package/es/apis/node/models/mappers.mjs.map +1 -0
- package/es/apis/node/models/parameters.d.ts +17 -0
- package/es/apis/node/models/parameters.mjs +165 -0
- package/es/apis/node/models/parameters.mjs.map +1 -0
- package/es/apis/node/node.d.ts +215 -0
- package/es/apis/node/node.mjs +1165 -0
- package/es/apis/node/node.mjs.map +1 -0
- package/es/chain.d.ts +248 -0
- package/es/chain.mjs +560 -0
- package/es/chain.mjs.map +1 -0
- package/es/channel/handlers.d.ts +34 -0
- package/es/channel/handlers.mjs +164 -131
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/index.d.ts +625 -0
- package/es/channel/index.mjs +897 -902
- package/es/channel/index.mjs.map +1 -1
- package/es/channel/internal.d.ts +101 -0
- package/es/channel/internal.mjs +138 -88
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Compiler.d.ts +18 -0
- package/es/contract/Compiler.mjs +68 -0
- package/es/contract/Compiler.mjs.map +1 -0
- package/es/contract/aci.d.ts +127 -0
- package/es/contract/aci.mjs +225 -193
- package/es/contract/aci.mjs.map +1 -1
- package/es/contract/ga.d.ts +69 -0
- package/es/contract/ga.mjs +195 -0
- package/es/contract/ga.mjs.map +1 -0
- package/es/contract/methods.d.ts +71 -0
- package/es/contract/methods.mjs +104 -0
- package/es/contract/methods.mjs.map +1 -0
- package/es/deprecated/index.d.ts +143 -0
- package/es/deprecated/index.mjs +162 -0
- package/es/deprecated/index.mjs.map +1 -0
- package/es/deprecated/methods.d.ts +18 -0
- package/es/deprecated/methods.mjs +26 -0
- package/es/deprecated/methods.mjs.map +1 -0
- package/es/index.d.ts +35 -0
- package/es/index.mjs +35 -40
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +161 -0
- package/es/oracle.mjs +306 -0
- package/es/oracle.mjs.map +1 -0
- package/es/spend.d.ts +62 -0
- package/es/spend.mjs +111 -0
- package/es/spend.mjs.map +1 -0
- package/es/tx/builder/address.d.ts +25 -0
- package/es/tx/builder/address.mjs +45 -0
- package/es/tx/builder/address.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +70 -0
- package/es/tx/builder/constants.mjs +122 -0
- package/es/tx/builder/constants.mjs.map +1 -0
- package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
- package/es/tx/builder/field-types/coin-amount.mjs +26 -0
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
- package/es/tx/builder/field-types/deposit.d.ts +15 -0
- package/es/tx/builder/field-types/deposit.mjs +19 -0
- package/es/tx/builder/field-types/deposit.mjs.map +1 -0
- package/es/tx/builder/field-types/fee.d.ts +25 -0
- package/es/tx/builder/field-types/fee.mjs +150 -0
- package/es/tx/builder/field-types/fee.mjs.map +1 -0
- package/es/tx/builder/field-types/field.d.ts +6 -0
- package/es/tx/builder/field-types/field.mjs +15 -0
- package/es/tx/builder/field-types/field.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
- package/es/tx/builder/field-types/gas-limit.mjs +33 -0
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-price.d.ts +8 -0
- package/es/tx/builder/field-types/gas-price.mjs +18 -0
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
- package/es/tx/builder/field-types/index.d.ts +70 -0
- package/es/tx/builder/field-types/index.mjs +25 -0
- package/es/tx/builder/field-types/index.mjs.map +1 -0
- package/es/tx/builder/field-types/name-fee.d.ts +20 -0
- package/es/tx/builder/field-types/name-fee.mjs +24 -0
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
- package/es/tx/builder/field-types/name-id.d.ts +14 -0
- package/es/tx/builder/field-types/name-id.mjs +19 -0
- package/es/tx/builder/field-types/name-id.mjs.map +1 -0
- package/es/tx/builder/field-types/name.d.ts +13 -0
- package/es/tx/builder/field-types/name.mjs +18 -0
- package/es/tx/builder/field-types/name.mjs.map +1 -0
- package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
- package/es/tx/builder/field-types/short-u-int.mjs +12 -0
- package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
- package/es/tx/builder/field-types/u-int.d.ts +8 -0
- package/es/tx/builder/field-types/u-int.mjs +14 -0
- package/es/tx/builder/field-types/u-int.mjs.map +1 -0
- package/es/tx/builder/helpers.d.ts +125 -0
- package/es/tx/builder/helpers.mjs +94 -240
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +88 -0
- package/es/tx/builder/index.mjs +167 -358
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +1201 -0
- package/es/tx/builder/schema.mjs +175 -664
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +64 -0
- package/es/tx/index.mjs +151 -265
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +20 -0
- package/es/tx/validator.mjs +104 -124
- package/es/tx/validator.mjs.map +1 -1
- package/es/typings/@aeternity__argon2-browser/index.d.mjs +2 -0
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -0
- package/es/typings/@aeternity__uuid/index.d.mjs +2 -0
- package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -0
- package/es/typings/bip32-path/index.d.mjs +2 -0
- package/es/typings/bip32-path/index.d.mjs.map +1 -0
- package/es/typings/blakejs/index.d.mjs.map +1 -1
- package/es/typings/sha-js/index.d.mjs +2 -0
- package/es/typings/sha-js/index.d.mjs.map +1 -0
- package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
- package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
- package/es/utils/amount-formatter.d.ts +42 -0
- package/es/utils/amount-formatter.mjs +36 -49
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.d.ts +6 -0
- package/es/utils/autorest.mjs +97 -0
- package/es/utils/autorest.mjs.map +1 -0
- package/es/utils/bignumber.d.ts +13 -0
- package/es/utils/bignumber.mjs +11 -8
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
- package/es/utils/bytes.mjs +11 -15
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +88 -0
- package/es/utils/crypto.mjs +64 -108
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder-types.d.ts +61 -0
- package/es/utils/encoder-types.mjs +36 -0
- package/es/utils/encoder-types.mjs.map +1 -0
- package/es/utils/encoder.d.ts +25 -0
- package/es/utils/encoder.mjs +118 -0
- package/es/utils/encoder.mjs.map +1 -0
- package/es/{errors.d.ts → utils/errors.d.ts} +246 -59
- package/es/utils/errors.mjs +313 -136
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +50 -0
- package/es/utils/hd-wallet.mjs +86 -45
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.d.ts +5 -0
- package/es/utils/json-big.mjs +12 -16
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.d.ts +51 -0
- package/es/utils/keystore.mjs +101 -194
- package/es/utils/keystore.mjs.map +1 -1
- package/es/{mptree.d.ts → utils/mptree.d.ts} +6 -9
- package/es/utils/mptree.mjs +22 -18
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +20 -0
- package/es/utils/other.mjs +32 -35
- package/es/utils/other.mjs.map +1 -1
- package/es/utils/semver-satisfies.d.ts +1 -0
- package/es/utils/semver-satisfies.mjs +2 -2
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.d.ts +24 -0
- package/es/utils/string.mjs +8 -10
- package/es/utils/string.mjs.map +1 -1
- package/package.json +56 -42
- package/src/AeSdk.ts +68 -0
- package/src/AeSdkAepp.ts +176 -0
- package/src/AeSdkBase.ts +338 -0
- package/src/AeSdkWallet.ts +348 -0
- package/src/Node.ts +173 -0
- package/src/account/Base.ts +124 -0
- package/src/account/Memory.ts +98 -0
- package/src/account/Rpc.ts +69 -0
- package/src/aens.ts +407 -0
- package/src/aepp-wallet-communication/connection/Browser.ts +71 -0
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +59 -0
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +122 -0
- package/{es/utils/crypto-ts.mjs → src/aepp-wallet-communication/connection-proxy.ts} +18 -18
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +143 -0
- package/src/aepp-wallet-communication/rpc/types.ts +66 -0
- package/src/aepp-wallet-communication/schema.ts +224 -0
- package/src/aepp-wallet-communication/wallet-detector.ts +72 -0
- package/src/apis/compiler/code-model-v4.yaml +2649 -0
- package/src/apis/compiler/compiler.ts +585 -0
- package/src/apis/compiler/index.ts +2 -0
- package/src/apis/compiler/models/index.ts +301 -0
- package/src/apis/compiler/models/mappers.ts +583 -0
- package/src/apis/compiler/models/parameters.ts +93 -0
- package/src/apis/node/code-model-v4.yaml +10080 -0
- package/src/apis/node/index.ts +2 -0
- package/src/apis/node/models/index.ts +1257 -0
- package/src/apis/node/models/mappers.ts +4280 -0
- package/src/apis/node/models/parameters.ts +188 -0
- package/src/apis/node/node.ts +1299 -0
- package/src/chain.ts +502 -0
- package/src/channel/handlers.ts +817 -0
- package/src/channel/index.ts +1025 -0
- package/src/channel/internal.ts +361 -0
- package/src/contract/Compiler.ts +67 -0
- package/src/contract/aci.ts +538 -0
- package/src/contract/ga.ts +199 -0
- package/src/contract/methods.ts +123 -0
- package/src/deprecated/index.ts +170 -0
- package/src/deprecated/methods.ts +25 -0
- package/src/index.ts +56 -0
- package/src/oracle.ts +364 -0
- package/src/spend.ts +164 -0
- package/src/tx/builder/address.ts +50 -0
- package/src/tx/builder/constants.ts +126 -0
- package/src/tx/builder/field-types/coin-amount.ts +27 -0
- package/src/tx/builder/field-types/deposit.ts +21 -0
- package/src/tx/builder/field-types/fee.ts +143 -0
- package/src/tx/builder/field-types/field.ts +9 -0
- package/src/tx/builder/field-types/gas-limit.ts +41 -0
- package/src/tx/builder/field-types/gas-price.ts +16 -0
- package/src/tx/builder/field-types/index.ts +45 -0
- package/src/tx/builder/field-types/name-fee.ts +32 -0
- package/src/tx/builder/field-types/name-id.ts +20 -0
- package/src/tx/builder/field-types/name.ts +18 -0
- package/src/tx/builder/field-types/short-u-int.ts +11 -0
- package/src/tx/builder/field-types/u-int.ts +16 -0
- package/src/tx/builder/helpers.ts +248 -0
- package/src/tx/builder/index.ts +400 -0
- package/src/tx/builder/schema.ts +727 -0
- package/src/tx/index.ts +192 -0
- package/src/tx/validator.ts +230 -0
- package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
- package/src/typings/@aeternity__uuid/index.d.ts +5 -0
- package/src/typings/bip32-path/index.d.ts +33 -0
- package/src/typings/blakejs/index.d.ts +4 -32
- package/src/typings/sha-js/index.d.ts +5 -0
- package/src/typings/tweetnacl-auth/index.d.ts +14 -0
- package/src/utils/amount-formatter.ts +56 -69
- package/src/utils/autorest.ts +93 -0
- package/src/utils/bignumber.ts +11 -12
- package/src/utils/bytes.ts +29 -31
- package/src/utils/crypto.ts +205 -0
- package/src/utils/encoder-types.ts +63 -0
- package/src/utils/encoder.ts +146 -0
- package/src/utils/errors.ts +482 -366
- package/src/utils/hd-wallet.ts +166 -0
- package/src/utils/json-big.ts +27 -0
- package/src/utils/keystore.ts +182 -0
- package/src/utils/mptree.ts +64 -61
- package/src/utils/other.ts +34 -41
- package/src/utils/semver-satisfies.ts +15 -11
- package/src/utils/string.ts +18 -20
- package/es/account/base.mjs +0 -179
- package/es/account/base.mjs.map +0 -1
- package/es/account/memory.mjs +0 -99
- package/es/account/memory.mjs.map +0 -1
- package/es/account/multiple.mjs +0 -179
- package/es/account/multiple.mjs.map +0 -1
- package/es/ae/aens.mjs +0 -404
- package/es/ae/aens.mjs.map +0 -1
- package/es/ae/aepp.mjs +0 -45
- package/es/ae/aepp.mjs.map +0 -1
- package/es/ae/contract.mjs +0 -159
- package/es/ae/contract.mjs.map +0 -1
- package/es/ae/index.mjs +0 -207
- package/es/ae/index.mjs.map +0 -1
- package/es/ae/oracle.mjs +0 -339
- package/es/ae/oracle.mjs.map +0 -1
- package/es/ae/universal.mjs +0 -45
- package/es/ae/universal.mjs.map +0 -1
- package/es/ae/wallet.mjs +0 -50
- package/es/ae/wallet.mjs.map +0 -1
- package/es/amount-formatter.d.ts +0 -58
- package/es/bignumber.d.ts +0 -18
- package/es/chain/index.mjs +0 -272
- package/es/chain/index.mjs.map +0 -1
- package/es/chain/node.mjs +0 -442
- package/es/chain/node.mjs.map +0 -1
- package/es/contract/compiler.mjs +0 -115
- package/es/contract/compiler.mjs.map +0 -1
- package/es/contract/ga/helpers.mjs +0 -30
- package/es/contract/ga/helpers.mjs.map +0 -1
- package/es/contract/ga/index.mjs +0 -178
- package/es/contract/ga/index.mjs.map +0 -1
- package/es/crypto-ts.d.ts +0 -9
- package/es/node-pool/index.mjs +0 -188
- package/es/node-pool/index.mjs.map +0 -1
- package/es/node.mjs +0 -133
- package/es/node.mjs.map +0 -1
- package/es/other.d.ts +0 -31
- package/es/semver-satisfies.d.ts +0 -1
- package/es/string.d.ts +0 -26
- package/es/tx/builder/field-types.mjs +0 -74
- package/es/tx/builder/field-types.mjs.map +0 -1
- package/es/tx/tx-object.mjs +0 -283
- package/es/tx/tx-object.mjs.map +0 -1
- package/es/tx/tx.mjs +0 -938
- package/es/tx/tx.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs +0 -132
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +0 -183
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/index.mjs +0 -87
- package/es/utils/aepp-wallet-communication/connection/index.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs +0 -98
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/helpers.mjs +0 -92
- package/es/utils/aepp-wallet-communication/helpers.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +0 -375
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +0 -275
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +0 -541
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.mjs +0 -102
- package/es/utils/aepp-wallet-communication/schema.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs +0 -110
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +0 -1
- package/es/utils/async-init.mjs +0 -64
- package/es/utils/async-init.mjs.map +0 -1
- package/es/utils/crypto-ts.mjs.map +0 -1
- package/es/utils/swagger.mjs +0 -164
- package/es/utils/swagger.mjs.map +0 -1
- package/src/account/base.js +0 -153
- package/src/account/memory.js +0 -83
- package/src/account/multiple.js +0 -162
- package/src/ae/aens.js +0 -361
- package/src/ae/aepp.js +0 -45
- package/src/ae/contract.js +0 -148
- package/src/ae/index.js +0 -168
- package/src/ae/oracle.js +0 -311
- package/src/ae/universal.js +0 -47
- package/src/ae/wallet.js +0 -50
- package/src/chain/index.js +0 -269
- package/src/chain/node.js +0 -320
- package/src/channel/handlers.js +0 -673
- package/src/channel/index.js +0 -898
- package/src/channel/internal.js +0 -237
- package/src/contract/aci.js +0 -376
- package/src/contract/compiler.js +0 -100
- package/src/contract/ga/helpers.js +0 -19
- package/src/contract/ga/index.js +0 -150
- package/src/index.js +0 -89
- package/src/node-pool/index.js +0 -172
- package/src/node.js +0 -116
- package/src/tx/builder/field-types.js +0 -61
- package/src/tx/builder/helpers.js +0 -380
- package/src/tx/builder/index.js +0 -465
- package/src/tx/builder/schema.js +0 -1197
- package/src/tx/index.js +0 -301
- package/src/tx/tx-object.js +0 -187
- package/src/tx/tx.js +0 -631
- package/src/tx/validator.js +0 -181
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -119
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -165
- package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -86
- package/src/utils/aepp-wallet-communication/helpers.js +0 -60
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -294
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -232
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -401
- package/src/utils/aepp-wallet-communication/schema.ts +0 -80
- package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -92
- package/src/utils/async-init.js +0 -45
- package/src/utils/crypto.js +0 -229
- package/src/utils/hd-wallet.js +0 -100
- package/src/utils/json-big.js +0 -26
- package/src/utils/keystore.js +0 -219
- package/src/utils/swagger.js +0 -156
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import nacl from 'tweetnacl';
|
|
2
|
+
import { full as hmac } from 'tweetnacl-auth';
|
|
3
|
+
import { fromString } from 'bip32-path';
|
|
4
|
+
import aesjs from 'aes-js';
|
|
5
|
+
import { sha256hash, encode, Encoding } from './encoder';
|
|
6
|
+
import { CryptographyError } from './errors';
|
|
7
|
+
import { bytesToHex } from './bytes';
|
|
8
|
+
import { concatBuffers } from './other';
|
|
9
|
+
|
|
10
|
+
const Ecb = aesjs.ModeOfOperation.ecb;
|
|
11
|
+
|
|
12
|
+
// TODO: at least don't export `encryptKey` and `decryptKey`
|
|
13
|
+
/**
|
|
14
|
+
* Encrypt given data using `password`
|
|
15
|
+
* @param password - Password to encrypt with
|
|
16
|
+
* @param binaryData - Data to encrypt
|
|
17
|
+
* @returns Encrypted data
|
|
18
|
+
* @deprecated use 'sha.js' and 'aes-js' packages directly instead
|
|
19
|
+
*/
|
|
20
|
+
export function encryptKey(password: string, binaryData: Uint8Array): Uint8Array {
|
|
21
|
+
const hashedPasswordBytes = sha256hash(password);
|
|
22
|
+
const aesEcb = new Ecb(hashedPasswordBytes);
|
|
23
|
+
return aesEcb.encrypt(binaryData);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Decrypt given data using `password`
|
|
28
|
+
* @param password - Password to decrypt with
|
|
29
|
+
* @param encrypted - Data to decrypt
|
|
30
|
+
* @returns Decrypted data
|
|
31
|
+
* @deprecated use 'sha.js' and 'aes-js' packages directly instead
|
|
32
|
+
*/
|
|
33
|
+
export function decryptKey(password: string, encrypted: Uint8Array): Uint8Array {
|
|
34
|
+
const encryptedBytes = Buffer.from(encrypted);
|
|
35
|
+
const hashedPasswordBytes = sha256hash(password);
|
|
36
|
+
const aesEcb = new Ecb(hashedPasswordBytes);
|
|
37
|
+
return aesEcb.decrypt(encryptedBytes);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @category exception
|
|
42
|
+
*/
|
|
43
|
+
export class DerivationError extends CryptographyError {
|
|
44
|
+
constructor(message: string) {
|
|
45
|
+
super(message);
|
|
46
|
+
this.name = 'DerivationError';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const ED25519_CURVE = Buffer.from('ed25519 seed');
|
|
51
|
+
const HARDENED_OFFSET = 0x80000000;
|
|
52
|
+
|
|
53
|
+
interface KeyTreeNode {
|
|
54
|
+
secretKey: Uint8Array;
|
|
55
|
+
chainCode: Uint8Array;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface HDWallet {
|
|
59
|
+
secretKey: string;
|
|
60
|
+
chainCode: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface Account {
|
|
64
|
+
secretKey: string;
|
|
65
|
+
publicKey: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
type Dec<N extends number> = [-1, 0, 1, 2, 3, 4][N];
|
|
69
|
+
type Bip32PathT<MaxLen extends number, H extends 'H' | 'h' | '\''> = MaxLen extends -1
|
|
70
|
+
? `${number}${H}`
|
|
71
|
+
: Bip32PathT<Dec<MaxLen>, H> | `${Bip32PathT<Dec<MaxLen>, H>}/${number}${H}`;
|
|
72
|
+
type Bip32Path<MaxLen extends number> =
|
|
73
|
+
'' | Bip32PathT<MaxLen, 'H'> | Bip32PathT<MaxLen, 'h'> | Bip32PathT<MaxLen, '\''>;
|
|
74
|
+
|
|
75
|
+
export function deriveChild({ secretKey, chainCode }: KeyTreeNode, index: number): KeyTreeNode {
|
|
76
|
+
if (index < HARDENED_OFFSET) {
|
|
77
|
+
throw new DerivationError(`Segment ${index} is not hardened`);
|
|
78
|
+
}
|
|
79
|
+
const indexBuffer = Buffer.allocUnsafe(4);
|
|
80
|
+
indexBuffer.writeUInt32BE(index, 0);
|
|
81
|
+
|
|
82
|
+
const data = concatBuffers([Buffer.alloc(1, 0), secretKey, indexBuffer]);
|
|
83
|
+
|
|
84
|
+
const I = hmac(data, chainCode);
|
|
85
|
+
const IL = I.slice(0, 32);
|
|
86
|
+
const IR = I.slice(32);
|
|
87
|
+
return {
|
|
88
|
+
secretKey: IL,
|
|
89
|
+
chainCode: IR,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function derivePathFromKey(path: Bip32Path<5>, key: KeyTreeNode): KeyTreeNode {
|
|
94
|
+
const segments = path === '' ? [] : fromString(path).toPathArray();
|
|
95
|
+
segments.forEach((segment, i) => {
|
|
96
|
+
if (segment < HARDENED_OFFSET) {
|
|
97
|
+
throw new DerivationError(`Segment #${i + 1} is not hardened`);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return segments.reduce((parentKey, segment) => deriveChild(parentKey, segment), key);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function getMasterKeyFromSeed(seed: Uint8Array): KeyTreeNode {
|
|
105
|
+
const I = hmac(seed, ED25519_CURVE);
|
|
106
|
+
const IL = I.slice(0, 32);
|
|
107
|
+
const IR = I.slice(32);
|
|
108
|
+
return {
|
|
109
|
+
secretKey: IL,
|
|
110
|
+
chainCode: IR,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function derivePathFromSeed(path: 'm' | `m/${Bip32Path<5>}`, seed: Uint8Array): KeyTreeNode {
|
|
115
|
+
if (!['m', 'm/'].includes(path.slice(0, 2))) {
|
|
116
|
+
throw new DerivationError('Root element is required');
|
|
117
|
+
}
|
|
118
|
+
const masterKey = getMasterKeyFromSeed(seed);
|
|
119
|
+
return derivePathFromKey(path.slice(2) as Bip32Path<5>, masterKey);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function formatAccount(keys: nacl.SignKeyPair): Account {
|
|
123
|
+
const { secretKey, publicKey } = keys;
|
|
124
|
+
return {
|
|
125
|
+
secretKey: bytesToHex(secretKey),
|
|
126
|
+
publicKey: encode(publicKey, Encoding.AccountAddress),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function getKeyPair(secretKey: Uint8Array): nacl.SignKeyPair {
|
|
131
|
+
return nacl.sign.keyPair.fromSeed(secretKey);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function generateSaveHDWalletFromSeed(seed: Uint8Array, password: string): HDWallet {
|
|
135
|
+
const walletKey = derivePathFromSeed('m/44h/457h', seed);
|
|
136
|
+
return {
|
|
137
|
+
secretKey: bytesToHex(encryptKey(password, walletKey.secretKey)),
|
|
138
|
+
chainCode: bytesToHex(encryptKey(password, walletKey.chainCode)),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function getSaveHDWalletAccounts(
|
|
143
|
+
saveHDWallet: HDWallet,
|
|
144
|
+
password: string,
|
|
145
|
+
accountCount: number,
|
|
146
|
+
): Account[] {
|
|
147
|
+
const walletKey = {
|
|
148
|
+
secretKey: decryptKey(password, Buffer.from(saveHDWallet.secretKey, 'hex')),
|
|
149
|
+
chainCode: decryptKey(password, Buffer.from(saveHDWallet.chainCode, 'hex')),
|
|
150
|
+
};
|
|
151
|
+
return (new Array(accountCount)).fill(undefined)
|
|
152
|
+
.map((_, idx) => formatAccount(getKeyPair(derivePathFromKey(`${idx}h/0h/0h`, walletKey).secretKey)));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export const getHdWalletAccountFromSeed = (
|
|
156
|
+
seed: Uint8Array,
|
|
157
|
+
accountIdx: number,
|
|
158
|
+
): Account & { idx: number } => {
|
|
159
|
+
const walletKey = derivePathFromSeed('m/44h/457h', seed);
|
|
160
|
+
const derived = derivePathFromKey(`${accountIdx}h/0h/0h`, walletKey);
|
|
161
|
+
const keyPair = getKeyPair(derived.secretKey);
|
|
162
|
+
return {
|
|
163
|
+
...formatAccount(keyPair),
|
|
164
|
+
idx: accountIdx,
|
|
165
|
+
};
|
|
166
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import JsonBig from 'json-bigint';
|
|
2
|
+
import BigNumber from 'bignumber.js';
|
|
3
|
+
import { mapObject } from './other';
|
|
4
|
+
|
|
5
|
+
const jsonBig = JsonBig({ storeAsString: true });
|
|
6
|
+
|
|
7
|
+
const convertValuesToBigNumbers = (value: any): any => {
|
|
8
|
+
if (typeof value === 'object' && value !== null && value.constructor === Object) {
|
|
9
|
+
return mapObject(value, ([k, v]) => [k, convertValuesToBigNumbers(v)]);
|
|
10
|
+
}
|
|
11
|
+
if (Array.isArray(value)) {
|
|
12
|
+
return value.map((item) => convertValuesToBigNumbers(item));
|
|
13
|
+
}
|
|
14
|
+
if (typeof value === 'string' && new BigNumber(value).toString(10) === value) {
|
|
15
|
+
const bn = new BigNumber(value);
|
|
16
|
+
bn.toJSON = () => bn.toString(10);
|
|
17
|
+
return bn;
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default {
|
|
23
|
+
stringify: (...args: Parameters<typeof JsonBig['stringify']>): string => (
|
|
24
|
+
jsonBig.stringify(convertValuesToBigNumbers(args[0]), ...args.slice(1))
|
|
25
|
+
),
|
|
26
|
+
parse: jsonBig.parse,
|
|
27
|
+
};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import nacl from 'tweetnacl';
|
|
2
|
+
import { v4 as uuid } from '@aeternity/uuid';
|
|
3
|
+
// js extension is required for mjs build
|
|
4
|
+
// eslint-disable-next-line import/extensions
|
|
5
|
+
import { ArgonType, hash } from '@aeternity/argon2-browser/dist/argon2-bundled.min.js';
|
|
6
|
+
import { getAddressFromPriv } from './crypto';
|
|
7
|
+
import { bytesToHex, hexToBytes } from './bytes';
|
|
8
|
+
import { InvalidPasswordError } from './errors';
|
|
9
|
+
|
|
10
|
+
const DERIVED_KEY_FUNCTIONS = {
|
|
11
|
+
async argon2id(
|
|
12
|
+
pass: string | Uint8Array,
|
|
13
|
+
salt: string | Uint8Array,
|
|
14
|
+
params: Partial<Keystore['crypto']['kdf_params']>,
|
|
15
|
+
): Promise<Uint8Array> {
|
|
16
|
+
const { memlimit_kib: mem, opslimit: time } = params;
|
|
17
|
+
|
|
18
|
+
return (await hash({
|
|
19
|
+
hashLen: 32,
|
|
20
|
+
pass,
|
|
21
|
+
salt,
|
|
22
|
+
time,
|
|
23
|
+
mem,
|
|
24
|
+
type: ArgonType.Argon2id,
|
|
25
|
+
})).hash;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const CRYPTO_FUNCTIONS = {
|
|
30
|
+
'xsalsa20-poly1305': {
|
|
31
|
+
encrypt: nacl.secretbox,
|
|
32
|
+
decrypt(...args: Parameters<typeof nacl.secretbox.open>): Uint8Array {
|
|
33
|
+
const res = nacl.secretbox.open(...args);
|
|
34
|
+
if (res == null) throw new InvalidPasswordError();
|
|
35
|
+
return res;
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export interface Keystore {
|
|
41
|
+
name: string;
|
|
42
|
+
version: 1;
|
|
43
|
+
public_key: string;
|
|
44
|
+
id: string;
|
|
45
|
+
crypto: {
|
|
46
|
+
secret_type: 'ed25519';
|
|
47
|
+
symmetric_alg: keyof typeof CRYPTO_FUNCTIONS;
|
|
48
|
+
ciphertext: string;
|
|
49
|
+
cipher_params: {
|
|
50
|
+
nonce: string;
|
|
51
|
+
};
|
|
52
|
+
kdf: keyof typeof DERIVED_KEY_FUNCTIONS;
|
|
53
|
+
kdf_params: {
|
|
54
|
+
memlimit_kib: number;
|
|
55
|
+
opslimit: number;
|
|
56
|
+
parallelism: number;
|
|
57
|
+
salt: string;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const CRYPTO_DEFAULTS = {
|
|
63
|
+
secret_type: 'ed25519',
|
|
64
|
+
symmetric_alg: 'xsalsa20-poly1305',
|
|
65
|
+
kdf: 'argon2id',
|
|
66
|
+
kdf_params: {
|
|
67
|
+
memlimit_kib: 65536,
|
|
68
|
+
opslimit: 3,
|
|
69
|
+
parallelism: 1,
|
|
70
|
+
},
|
|
71
|
+
} as const;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Symmetric private key encryption using secret (derived) key.
|
|
75
|
+
* @param plaintext - Data to be encrypted.
|
|
76
|
+
* @param key - Secret key.
|
|
77
|
+
* @param nonce - Randomly generated nonce.
|
|
78
|
+
* @param algo - Encryption algorithm.
|
|
79
|
+
* @returns Encrypted data.
|
|
80
|
+
*/
|
|
81
|
+
function encrypt(
|
|
82
|
+
plaintext: Uint8Array,
|
|
83
|
+
key: Uint8Array,
|
|
84
|
+
nonce: Uint8Array,
|
|
85
|
+
algo: keyof typeof CRYPTO_FUNCTIONS = CRYPTO_DEFAULTS.symmetric_alg,
|
|
86
|
+
): Uint8Array {
|
|
87
|
+
return CRYPTO_FUNCTIONS[algo].encrypt(plaintext, nonce, key);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Symmetric private key decryption using secret (derived) key.
|
|
92
|
+
* @param ciphertext - Data to be decrypted.
|
|
93
|
+
* @param key - Secret key.
|
|
94
|
+
* @param nonce - Nonce from key-object.
|
|
95
|
+
* @param algo - Encryption algorithm.
|
|
96
|
+
* @returns Decrypted data.
|
|
97
|
+
*/
|
|
98
|
+
function decrypt(
|
|
99
|
+
ciphertext: Uint8Array,
|
|
100
|
+
key: Uint8Array,
|
|
101
|
+
nonce: Uint8Array,
|
|
102
|
+
algo: keyof typeof CRYPTO_FUNCTIONS = CRYPTO_DEFAULTS.symmetric_alg,
|
|
103
|
+
): Uint8Array {
|
|
104
|
+
return CRYPTO_FUNCTIONS[algo].decrypt(ciphertext, nonce, key);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Derive secret key from password with key derivation function.
|
|
109
|
+
* @param password - User-supplied password.
|
|
110
|
+
* @param nonce - Randomly generated nonce.
|
|
111
|
+
* @param kdf - Key derivation function.
|
|
112
|
+
* @param kdfParams - KDF parameters.
|
|
113
|
+
* @returns Secret key derived from password.
|
|
114
|
+
*/
|
|
115
|
+
async function deriveKey(
|
|
116
|
+
password: string | Uint8Array,
|
|
117
|
+
nonce: string | Uint8Array,
|
|
118
|
+
kdf: Keystore['crypto']['kdf'],
|
|
119
|
+
kdfParams: Omit<Keystore['crypto']['kdf_params'], 'salt'>,
|
|
120
|
+
): Promise<Uint8Array> {
|
|
121
|
+
return DERIVED_KEY_FUNCTIONS[kdf](password, nonce, kdfParams);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Recover plaintext private key from secret-storage key object.
|
|
126
|
+
* @param password - Keystore object password.
|
|
127
|
+
* @param keystore - Keystore object.
|
|
128
|
+
* @returns Plaintext private key.
|
|
129
|
+
*/
|
|
130
|
+
export async function recover(
|
|
131
|
+
password: string | Uint8Array,
|
|
132
|
+
{ crypto }: Keystore,
|
|
133
|
+
): Promise<string> {
|
|
134
|
+
const salt = hexToBytes(crypto.kdf_params.salt);
|
|
135
|
+
return bytesToHex(decrypt(
|
|
136
|
+
hexToBytes(crypto.ciphertext),
|
|
137
|
+
await deriveKey(password, salt, crypto.kdf, crypto.kdf_params),
|
|
138
|
+
hexToBytes(crypto.cipher_params.nonce),
|
|
139
|
+
crypto.symmetric_alg,
|
|
140
|
+
));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Export private key to keystore secret-storage format.
|
|
145
|
+
* @param name - Key name.
|
|
146
|
+
* @param password - User-supplied password.
|
|
147
|
+
* @param privateKey - Private key as hex-string or a Buffer.
|
|
148
|
+
* @param nonce - Randomly generated 24byte nonce.
|
|
149
|
+
* @param salt - Randomly generated 16byte salt.
|
|
150
|
+
* @param options - Encryption parameters.
|
|
151
|
+
* @param options.kdf - Key derivation function.
|
|
152
|
+
* @param options.kdf_params - KDF parameters.
|
|
153
|
+
*/
|
|
154
|
+
export async function dump(
|
|
155
|
+
name: string,
|
|
156
|
+
password: string | Uint8Array,
|
|
157
|
+
privateKey: string | Uint8Array,
|
|
158
|
+
nonce: Uint8Array = nacl.randomBytes(24),
|
|
159
|
+
salt: Uint8Array = nacl.randomBytes(16),
|
|
160
|
+
options?: Partial<Keystore['crypto']>,
|
|
161
|
+
): Promise<Keystore> {
|
|
162
|
+
const opt = { ...CRYPTO_DEFAULTS, ...options };
|
|
163
|
+
const derivedKey = await deriveKey(password, salt, opt.kdf, opt.kdf_params);
|
|
164
|
+
const payload = typeof privateKey === 'string' ? hexToBytes(privateKey) : privateKey;
|
|
165
|
+
return {
|
|
166
|
+
name,
|
|
167
|
+
version: 1,
|
|
168
|
+
public_key: getAddressFromPriv(payload),
|
|
169
|
+
id: uuid(),
|
|
170
|
+
crypto: {
|
|
171
|
+
secret_type: opt.secret_type,
|
|
172
|
+
symmetric_alg: opt.symmetric_alg,
|
|
173
|
+
ciphertext: bytesToHex(encrypt(payload, derivedKey, nonce, opt.symmetric_alg)),
|
|
174
|
+
cipher_params: { nonce: bytesToHex(nonce) },
|
|
175
|
+
kdf: opt.kdf,
|
|
176
|
+
kdf_params: {
|
|
177
|
+
...opt.kdf_params,
|
|
178
|
+
salt: bytesToHex(salt),
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
package/src/utils/mptree.ts
CHANGED
|
@@ -15,127 +15,130 @@
|
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
import
|
|
20
|
-
import {
|
|
18
|
+
/* eslint-disable default-case */
|
|
19
|
+
import { encode as rlpEncode } from 'rlp';
|
|
20
|
+
import type { Input } from 'rlp';
|
|
21
|
+
import { hash } from './crypto';
|
|
21
22
|
import {
|
|
22
23
|
MerkleTreeHashMismatchError,
|
|
23
24
|
MissingNodeInTreeError,
|
|
24
25
|
UnknownPathNibbleError,
|
|
25
|
-
UnknownNodeLengthError
|
|
26
|
-
} from './errors'
|
|
26
|
+
UnknownNodeLengthError,
|
|
27
|
+
} from './errors';
|
|
27
28
|
|
|
28
29
|
enum NodeType {
|
|
29
30
|
Branch,
|
|
30
31
|
Extension,
|
|
31
|
-
Leaf
|
|
32
|
+
Leaf,
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
export type MPTreeBinary = [Buffer, Array<[Buffer, Buffer[]]>]
|
|
35
|
+
export type MPTreeBinary = [Buffer, Array<[Buffer, Buffer[]]>];
|
|
35
36
|
|
|
36
37
|
export default class MPTree {
|
|
37
|
-
private readonly rootHash: string
|
|
38
|
-
private readonly nodes: { [key: string]: Buffer[] }
|
|
38
|
+
private readonly rootHash: string;
|
|
39
39
|
|
|
40
|
-
private
|
|
41
|
-
|
|
40
|
+
private readonly nodes: { [key: string]: Buffer[] };
|
|
41
|
+
|
|
42
|
+
private static nodeHash(node: Input): string {
|
|
43
|
+
return Buffer.from(hash(rlpEncode(node))).toString('hex');
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
/**
|
|
45
47
|
* Deserialize Merkle Patricia Tree
|
|
46
|
-
* @
|
|
47
|
-
* @
|
|
48
|
-
* @return {MPTree} Merkle Patricia Tree
|
|
48
|
+
* @param binary - Binary
|
|
49
|
+
* @returns Merkle Patricia Tree
|
|
49
50
|
*/
|
|
50
|
-
constructor
|
|
51
|
-
this.rootHash = binary[0].toString('hex')
|
|
51
|
+
constructor(binary: MPTreeBinary) {
|
|
52
|
+
this.rootHash = binary[0].toString('hex');
|
|
52
53
|
this.nodes = Object.fromEntries(
|
|
53
|
-
binary[1].map((node) => [node[0].toString('hex'), node[1]])
|
|
54
|
-
)
|
|
54
|
+
binary[1].map((node) => [node[0].toString('hex'), node[1]]),
|
|
55
|
+
);
|
|
55
56
|
|
|
56
|
-
if (this.nodes[this.rootHash] === undefined) throw new MissingNodeInTreeError('Can\'t find a node by root hash')
|
|
57
|
+
if (this.nodes[this.rootHash] === undefined) throw new MissingNodeInTreeError('Can\'t find a node by root hash');
|
|
57
58
|
Object.entries(this.nodes).forEach(([key, node]) => {
|
|
58
|
-
if (MPTree.nodeHash(node) !== key) throw new MerkleTreeHashMismatchError()
|
|
59
|
-
const { type, payload } = MPTree.parseNode(node)
|
|
59
|
+
if (MPTree.nodeHash(node) !== key) throw new MerkleTreeHashMismatchError();
|
|
60
|
+
const { type, payload } = MPTree.parseNode(node);
|
|
60
61
|
switch (type) {
|
|
61
62
|
case NodeType.Branch:
|
|
62
63
|
payload
|
|
63
64
|
.slice(0, 16)
|
|
64
|
-
.filter(n => n.length)
|
|
65
|
+
.filter((n) => n.length)
|
|
65
66
|
.forEach((n) => {
|
|
66
67
|
if (this.nodes[n.toString('hex')] === undefined) {
|
|
67
|
-
throw new MissingNodeInTreeError('Can\'t find a node by hash in branch node')
|
|
68
|
+
throw new MissingNodeInTreeError('Can\'t find a node by hash in branch node');
|
|
68
69
|
}
|
|
69
|
-
})
|
|
70
|
-
break
|
|
70
|
+
});
|
|
71
|
+
break;
|
|
71
72
|
case NodeType.Extension:
|
|
72
73
|
if (this.nodes[payload[0].toString('hex')] === undefined) {
|
|
73
|
-
throw new MissingNodeInTreeError('Can\'t find a node by hash in extension node')
|
|
74
|
+
throw new MissingNodeInTreeError('Can\'t find a node by hash in extension node');
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
|
-
})
|
|
77
|
+
});
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
isEqual
|
|
80
|
-
return this.rootHash === tree.rootHash
|
|
80
|
+
isEqual(tree: MPTree): boolean {
|
|
81
|
+
return this.rootHash === tree.rootHash;
|
|
81
82
|
}
|
|
82
83
|
|
|
83
|
-
private static parseNode
|
|
84
|
+
private static parseNode(node: Buffer[]): {
|
|
85
|
+
type: NodeType;
|
|
86
|
+
payload: Buffer[];
|
|
87
|
+
path: string | null;
|
|
88
|
+
} {
|
|
84
89
|
switch (node.length) {
|
|
85
90
|
case 17:
|
|
86
|
-
return { type: NodeType.Branch, payload: node, path: null }
|
|
91
|
+
return { type: NodeType.Branch, payload: node, path: null };
|
|
87
92
|
case 2: {
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
return { type, payload: [node[1]], path: path.slice(slice) }
|
|
93
|
+
const nibble = node[0][0] >> 4; // eslint-disable-line no-bitwise
|
|
94
|
+
if (nibble > 3) throw new UnknownPathNibbleError(nibble);
|
|
95
|
+
const type = nibble <= 1 ? NodeType.Extension : NodeType.Leaf;
|
|
96
|
+
const slice = [0, 2].includes(nibble) ? 2 : 1;
|
|
97
|
+
return { type, payload: [node[1]], path: node[0].toString('hex').slice(slice) };
|
|
94
98
|
}
|
|
95
99
|
default:
|
|
96
|
-
throw new UnknownNodeLengthError(node.length)
|
|
100
|
+
throw new UnknownNodeLengthError(node.length);
|
|
97
101
|
}
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
/**
|
|
101
105
|
* Serialize Merkle Patricia Tree
|
|
102
|
-
* @
|
|
103
|
-
* @return {Array} Binary
|
|
106
|
+
* @returns Binary
|
|
104
107
|
*/
|
|
105
|
-
serialize
|
|
108
|
+
serialize(): MPTreeBinary {
|
|
106
109
|
return [
|
|
107
110
|
Buffer.from(this.rootHash, 'hex'),
|
|
108
111
|
Object.entries(this.nodes).map(([mptHash, value]) => ([
|
|
109
112
|
Buffer.from(mptHash, 'hex'),
|
|
110
|
-
value
|
|
111
|
-
]))
|
|
112
|
-
]
|
|
113
|
+
value,
|
|
114
|
+
])),
|
|
115
|
+
];
|
|
113
116
|
}
|
|
114
117
|
|
|
115
118
|
/**
|
|
116
119
|
* Retrieve value from Merkle Patricia Tree
|
|
117
|
-
* @
|
|
118
|
-
* @
|
|
119
|
-
* @return {Buffer} Value associated to the specified key
|
|
120
|
+
* @param _key - The key of the element to retrieve
|
|
121
|
+
* @returns Value associated to the specified key
|
|
120
122
|
*/
|
|
121
|
-
get
|
|
122
|
-
let searchFrom = this.rootHash
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
get(_key: string): Buffer | undefined {
|
|
124
|
+
let searchFrom = this.rootHash;
|
|
125
|
+
let key = _key;
|
|
126
|
+
while (true) { // eslint-disable-line no-constant-condition
|
|
127
|
+
const { type, payload, path } = MPTree.parseNode(this.nodes[searchFrom]);
|
|
125
128
|
switch (type) {
|
|
126
129
|
case NodeType.Branch:
|
|
127
|
-
if (key.length === 0) return payload[16]
|
|
128
|
-
searchFrom = payload[
|
|
129
|
-
key = key.
|
|
130
|
-
break
|
|
130
|
+
if (key.length === 0) return payload[16];
|
|
131
|
+
searchFrom = payload[+`0x${key[0]}`].toString('hex');
|
|
132
|
+
key = key.substring(1);
|
|
133
|
+
break;
|
|
131
134
|
case NodeType.Extension:
|
|
132
|
-
if (key.
|
|
133
|
-
searchFrom = payload[0].toString('hex')
|
|
134
|
-
key = key.
|
|
135
|
-
break
|
|
135
|
+
if (key.substring(0, path?.length) !== path) return undefined;
|
|
136
|
+
searchFrom = payload[0].toString('hex');
|
|
137
|
+
key = key.substring(path.length);
|
|
138
|
+
break;
|
|
136
139
|
case NodeType.Leaf:
|
|
137
|
-
if (path !== key) return undefined
|
|
138
|
-
return payload[0]
|
|
140
|
+
if (path !== key) return undefined;
|
|
141
|
+
return payload[0];
|
|
139
142
|
}
|
|
140
143
|
}
|
|
141
144
|
}
|
package/src/utils/other.ts
CHANGED
|
@@ -1,51 +1,44 @@
|
|
|
1
|
-
|
|
1
|
+
export const pause = async (duration: number): Promise<void> => new Promise((resolve) => {
|
|
2
|
+
setTimeout(resolve, duration);
|
|
3
|
+
});
|
|
2
4
|
|
|
3
|
-
export const
|
|
4
|
-
|
|
5
|
+
export const mapObject = <InputV, OutputV>(
|
|
6
|
+
object: { [k: string]: InputV },
|
|
7
|
+
fn: (
|
|
8
|
+
value: [string, InputV], index: number, array: Array<[string, InputV]>
|
|
9
|
+
) => [number | string, OutputV],
|
|
10
|
+
): { [k: string]: OutputV } => Object.fromEntries(Object.entries(object).map(fn));
|
|
5
11
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
// remove after dropping webpack4 support
|
|
13
|
+
const isWebpack4Buffer = (() => {
|
|
14
|
+
try {
|
|
15
|
+
Buffer.concat([Uint8Array.from([])]);
|
|
16
|
+
return false;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
})();
|
|
10
21
|
|
|
11
|
-
export const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
)
|
|
22
|
+
export const concatBuffers = isWebpack4Buffer
|
|
23
|
+
? (list: readonly Uint8Array[], totalLength?: number): Buffer => (
|
|
24
|
+
Buffer.concat(list.map((el) => Buffer.from(el)), totalLength)
|
|
25
|
+
)
|
|
26
|
+
: Buffer.concat;
|
|
15
27
|
|
|
16
28
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @
|
|
19
|
-
* @
|
|
20
|
-
* @rtype (fn: (s: String) => String) => (o: Object) => Object
|
|
21
|
-
* @param {Function} fn - Key transformation function
|
|
22
|
-
* @param {Object} object - Object to traverse
|
|
23
|
-
* @return {Object} Transformed object
|
|
29
|
+
* Object key type guard
|
|
30
|
+
* @param key - Maybe object key
|
|
31
|
+
* @param object - Object
|
|
24
32
|
*/
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
if (Array.isArray(object)) return object.map(i => traverseKeys(fn, i))
|
|
28
|
-
return mapObject(object, ([key, value]: [string, any]) => [
|
|
29
|
-
fn(key), traverseKeys(fn, value)
|
|
30
|
-
])
|
|
33
|
+
export function isKeyOfObject<T>(key: string | number | symbol, object: T): key is keyof T {
|
|
34
|
+
return key in object;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @
|
|
36
|
-
* @
|
|
37
|
-
* @param {Object} object - Object to traverse
|
|
38
|
-
* @return {Object} Transformed object
|
|
39
|
-
* @see pascalToSnake
|
|
38
|
+
* Array item type guard
|
|
39
|
+
* @param item - Maybe array item
|
|
40
|
+
* @param array - Array
|
|
40
41
|
*/
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* PascalCase key traversal
|
|
45
|
-
* @static
|
|
46
|
-
* @rtype (o: Object) => Object
|
|
47
|
-
* @param {Object} object - Object to traverse
|
|
48
|
-
* @return {Object} Transformed object
|
|
49
|
-
* @see snakeToPascal
|
|
50
|
-
*/
|
|
51
|
-
export const pascalizeKeys = traverseKeys.bind(null, snakeToPascal)
|
|
42
|
+
export function isItemOfArray<T>(item: any, array: readonly T[]): item is T {
|
|
43
|
+
return array.includes(item);
|
|
44
|
+
}
|