@aeternity/aepp-sdk 11.0.1 → 12.1.1
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 +20765 -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 +136 -85
- 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 +61 -47
- package/es/tx/builder/constants.mjs.map +1 -1
- 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 -198
- 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 -561
- 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 -98
- 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 +71 -59
- package/es/utils/encoder.mjs.map +1 -1
- 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 +55 -43
- 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 +172 -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 +116 -71
- 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/encoder.d.ts +0 -26
- 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 -903
- package/src/channel/internal.js +0 -236
- 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/constants.js +0 -100
- package/src/tx/builder/field-types.js +0 -61
- package/src/tx/builder/helpers.js +0 -334
- package/src/tx/builder/index.js +0 -465
- package/src/tx/builder/schema.js +0 -1100
- 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 -219
- 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
package/es/utils/keystore.mjs
CHANGED
|
@@ -1,240 +1,147 @@
|
|
|
1
|
-
import _buffer from "buffer";
|
|
2
|
-
const {
|
|
3
|
-
Buffer: _Buffer
|
|
4
|
-
} = _buffer;
|
|
5
1
|
import nacl from 'tweetnacl';
|
|
6
|
-
import { v4 as uuid } from '@aeternity/uuid';
|
|
2
|
+
import { v4 as uuid } from '@aeternity/uuid'; // js extension is required for mjs build
|
|
3
|
+
// eslint-disable-next-line import/extensions
|
|
4
|
+
|
|
7
5
|
import _aeternityArgon2BrowserDistArgon2BundledMinJs from '@aeternity/argon2-browser/dist/argon2-bundled.min.js';
|
|
8
6
|
const {
|
|
9
7
|
ArgonType,
|
|
10
8
|
hash
|
|
11
9
|
} = _aeternityArgon2BrowserDistArgon2BundledMinJs;
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
opslimit: 3,
|
|
30
|
-
parallelism: 1
|
|
31
|
-
}
|
|
10
|
+
import { getAddressFromPriv } from "./crypto.mjs";
|
|
11
|
+
import { bytesToHex, hexToBytes } from "./bytes.mjs";
|
|
12
|
+
import { InvalidPasswordError } from "./errors.mjs";
|
|
13
|
+
const DERIVED_KEY_FUNCTIONS = {
|
|
14
|
+
async argon2id(pass, salt, params) {
|
|
15
|
+
const {
|
|
16
|
+
memlimit_kib: mem,
|
|
17
|
+
opslimit: time
|
|
18
|
+
} = params;
|
|
19
|
+
return (await hash({
|
|
20
|
+
hashLen: 32,
|
|
21
|
+
pass,
|
|
22
|
+
salt,
|
|
23
|
+
time,
|
|
24
|
+
mem,
|
|
25
|
+
type: ArgonType.Argon2id
|
|
26
|
+
})).hash;
|
|
32
27
|
}
|
|
33
|
-
}; // DERIVED KEY PART
|
|
34
28
|
|
|
35
|
-
const DERIVED_KEY_FUNCTIONS = {
|
|
36
|
-
argon2id: deriveKeyUsingArgon2id
|
|
37
29
|
};
|
|
38
|
-
export async function deriveKeyUsingArgon2id(pass, salt, options) {
|
|
39
|
-
const {
|
|
40
|
-
memlimit_kib: mem,
|
|
41
|
-
opslimit: time
|
|
42
|
-
} = options.kdf_params;
|
|
43
|
-
const result = (await hash({
|
|
44
|
-
hashLen: 32,
|
|
45
|
-
pass,
|
|
46
|
-
salt,
|
|
47
|
-
time,
|
|
48
|
-
mem,
|
|
49
|
-
type: ArgonType.Argon2id
|
|
50
|
-
})).hash;
|
|
51
|
-
return _Buffer.from(result);
|
|
52
|
-
} // CRYPTO PART
|
|
53
|
-
|
|
54
30
|
const CRYPTO_FUNCTIONS = {
|
|
55
31
|
'xsalsa20-poly1305': {
|
|
56
|
-
encrypt:
|
|
57
|
-
decrypt: decryptXsalsa20Poly1305
|
|
58
|
-
}
|
|
59
|
-
};
|
|
32
|
+
encrypt: nacl.secretbox,
|
|
60
33
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
} = _ref;
|
|
67
|
-
return nacl.secretbox(plaintext, nonce, key);
|
|
68
|
-
}
|
|
34
|
+
decrypt() {
|
|
35
|
+
const res = nacl.secretbox.open(...arguments);
|
|
36
|
+
if (res == null) throw new InvalidPasswordError();
|
|
37
|
+
return res;
|
|
38
|
+
}
|
|
69
39
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const CRYPTO_DEFAULTS = {
|
|
43
|
+
secret_type: 'ed25519',
|
|
44
|
+
symmetric_alg: 'xsalsa20-poly1305',
|
|
45
|
+
kdf: 'argon2id',
|
|
46
|
+
kdf_params: {
|
|
47
|
+
memlimit_kib: 65536,
|
|
48
|
+
opslimit: 3,
|
|
49
|
+
parallelism: 1
|
|
50
|
+
}
|
|
51
|
+
};
|
|
80
52
|
/**
|
|
81
53
|
* Symmetric private key encryption using secret (derived) key.
|
|
82
|
-
* @param
|
|
83
|
-
* @param
|
|
84
|
-
* @param
|
|
85
|
-
* @param
|
|
86
|
-
* @
|
|
54
|
+
* @param plaintext - Data to be encrypted.
|
|
55
|
+
* @param key - Secret key.
|
|
56
|
+
* @param nonce - Randomly generated nonce.
|
|
57
|
+
* @param algo - Encryption algorithm.
|
|
58
|
+
* @returns Encrypted data.
|
|
87
59
|
*/
|
|
88
60
|
|
|
89
|
-
|
|
90
61
|
function encrypt(plaintext, key, nonce) {
|
|
91
|
-
let algo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] :
|
|
92
|
-
|
|
93
|
-
return CRYPTO_FUNCTIONS[algo].encrypt({
|
|
94
|
-
plaintext,
|
|
95
|
-
nonce,
|
|
96
|
-
key
|
|
97
|
-
});
|
|
62
|
+
let algo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : CRYPTO_DEFAULTS.symmetric_alg;
|
|
63
|
+
return CRYPTO_FUNCTIONS[algo].encrypt(plaintext, nonce, key);
|
|
98
64
|
}
|
|
99
65
|
/**
|
|
100
66
|
* Symmetric private key decryption using secret (derived) key.
|
|
101
|
-
* @param
|
|
102
|
-
* @param
|
|
103
|
-
* @param
|
|
104
|
-
* @param
|
|
105
|
-
* @
|
|
67
|
+
* @param ciphertext - Data to be decrypted.
|
|
68
|
+
* @param key - Secret key.
|
|
69
|
+
* @param nonce - Nonce from key-object.
|
|
70
|
+
* @param algo - Encryption algorithm.
|
|
71
|
+
* @returns Decrypted data.
|
|
106
72
|
*/
|
|
107
73
|
|
|
108
74
|
|
|
109
|
-
function decrypt(ciphertext, key, nonce
|
|
110
|
-
|
|
111
|
-
return CRYPTO_FUNCTIONS[algo].decrypt(
|
|
112
|
-
ciphertext,
|
|
113
|
-
nonce,
|
|
114
|
-
key
|
|
115
|
-
});
|
|
75
|
+
function decrypt(ciphertext, key, nonce) {
|
|
76
|
+
let algo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : CRYPTO_DEFAULTS.symmetric_alg;
|
|
77
|
+
return CRYPTO_FUNCTIONS[algo].decrypt(ciphertext, nonce, key);
|
|
116
78
|
}
|
|
117
79
|
/**
|
|
118
80
|
* Derive secret key from password with key derivation function.
|
|
119
|
-
* @param
|
|
120
|
-
* @param
|
|
121
|
-
* @param
|
|
122
|
-
* @param
|
|
123
|
-
* @
|
|
124
|
-
* @return {Buffer} Secret key derived from password.
|
|
81
|
+
* @param password - User-supplied password.
|
|
82
|
+
* @param nonce - Randomly generated nonce.
|
|
83
|
+
* @param kdf - Key derivation function.
|
|
84
|
+
* @param kdfParams - KDF parameters.
|
|
85
|
+
* @returns Secret key derived from password.
|
|
125
86
|
*/
|
|
126
87
|
|
|
127
88
|
|
|
128
|
-
async function deriveKey(password, nonce) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
89
|
+
async function deriveKey(password, nonce, kdf, kdfParams) {
|
|
90
|
+
return DERIVED_KEY_FUNCTIONS[kdf](password, nonce, kdfParams);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Recover plaintext private key from secret-storage key object.
|
|
94
|
+
* @param password - Keystore object password.
|
|
95
|
+
* @param keystore - Keystore object.
|
|
96
|
+
* @returns Plaintext private key.
|
|
97
|
+
*/
|
|
135
98
|
|
|
136
|
-
if (!Object.prototype.hasOwnProperty.call(DERIVED_KEY_FUNCTIONS, options.kdf)) {
|
|
137
|
-
throw new UnsupportedAlgorithmError(options.kdf);
|
|
138
|
-
}
|
|
139
99
|
|
|
140
|
-
|
|
100
|
+
export async function recover(password, _ref) {
|
|
101
|
+
let {
|
|
102
|
+
crypto
|
|
103
|
+
} = _ref;
|
|
104
|
+
const salt = hexToBytes(crypto.kdf_params.salt);
|
|
105
|
+
return bytesToHex(decrypt(hexToBytes(crypto.ciphertext), await deriveKey(password, salt, crypto.kdf, crypto.kdf_params), hexToBytes(crypto.cipher_params.nonce), crypto.symmetric_alg));
|
|
141
106
|
}
|
|
142
107
|
/**
|
|
143
|
-
*
|
|
144
|
-
* @param
|
|
145
|
-
* @param
|
|
146
|
-
* @param
|
|
147
|
-
* @param
|
|
148
|
-
* @param
|
|
149
|
-
* @param
|
|
150
|
-
* @param
|
|
151
|
-
* @param
|
|
152
|
-
* @param {Object=} options.kdf_params KDF parameters (default: constants.<kdf>).
|
|
153
|
-
* @return {Object}
|
|
108
|
+
* Export private key to keystore secret-storage format.
|
|
109
|
+
* @param name - Key name.
|
|
110
|
+
* @param password - User-supplied password.
|
|
111
|
+
* @param privateKey - Private key as hex-string or a Buffer.
|
|
112
|
+
* @param nonce - Randomly generated 24byte nonce.
|
|
113
|
+
* @param salt - Randomly generated 16byte salt.
|
|
114
|
+
* @param options - Encryption parameters.
|
|
115
|
+
* @param options.kdf - Key derivation function.
|
|
116
|
+
* @param options.kdf_params - KDF parameters.
|
|
154
117
|
*/
|
|
155
118
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
let
|
|
159
|
-
|
|
160
|
-
|
|
119
|
+
export async function dump(name, password, privateKey) {
|
|
120
|
+
let nonce = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : nacl.randomBytes(24);
|
|
121
|
+
let salt = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : nacl.randomBytes(16);
|
|
122
|
+
let options = arguments.length > 5 ? arguments[5] : undefined;
|
|
123
|
+
const opt = { ...CRYPTO_DEFAULTS,
|
|
124
|
+
...options
|
|
125
|
+
};
|
|
126
|
+
const derivedKey = await deriveKey(password, salt, opt.kdf, opt.kdf_params);
|
|
127
|
+
const payload = typeof privateKey === 'string' ? hexToBytes(privateKey) : privateKey;
|
|
128
|
+
return {
|
|
161
129
|
name,
|
|
162
130
|
version: 1,
|
|
163
|
-
public_key: getAddressFromPriv(
|
|
164
|
-
id: uuid()
|
|
165
|
-
|
|
166
|
-
crypto: Object.assign({
|
|
131
|
+
public_key: getAddressFromPriv(payload),
|
|
132
|
+
id: uuid(),
|
|
133
|
+
crypto: {
|
|
167
134
|
secret_type: opt.secret_type,
|
|
168
135
|
symmetric_alg: opt.symmetric_alg,
|
|
169
|
-
ciphertext:
|
|
136
|
+
ciphertext: bytesToHex(encrypt(payload, derivedKey, nonce, opt.symmetric_alg)),
|
|
170
137
|
cipher_params: {
|
|
171
|
-
nonce:
|
|
172
|
-
}
|
|
173
|
-
}, {
|
|
138
|
+
nonce: bytesToHex(nonce)
|
|
139
|
+
},
|
|
174
140
|
kdf: opt.kdf,
|
|
175
141
|
kdf_params: { ...opt.kdf_params,
|
|
176
|
-
salt:
|
|
142
|
+
salt: bytesToHex(salt)
|
|
177
143
|
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export function getAddressFromPriv(secret) {
|
|
183
|
-
const keys = nacl.sign.keyPair.fromSecretKey(str2buf(secret));
|
|
184
|
-
|
|
185
|
-
const publicBuffer = _Buffer.from(keys.publicKey);
|
|
186
|
-
|
|
187
|
-
return encode(publicBuffer, 'ak');
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Recover plaintext private key from secret-storage key object.
|
|
191
|
-
* @param {String} password Keystore object password.
|
|
192
|
-
* @param {Object} keyObject Keystore object.
|
|
193
|
-
* @return {Buffer} Plaintext private key.
|
|
194
|
-
*/
|
|
195
|
-
|
|
196
|
-
export async function recover(password, keyObject) {
|
|
197
|
-
validateKeyObj(keyObject);
|
|
198
|
-
const nonce = Uint8Array.from(str2buf(keyObject.crypto.cipher_params.nonce));
|
|
199
|
-
const salt = Uint8Array.from(str2buf(keyObject.crypto.kdf_params.salt));
|
|
200
|
-
const kdfParams = keyObject.crypto.kdf_params;
|
|
201
|
-
const kdf = keyObject.crypto.kdf;
|
|
202
|
-
const key = await decrypt(Uint8Array.from(str2buf(keyObject.crypto.ciphertext)), await deriveKey(password, salt, {
|
|
203
|
-
kdf,
|
|
204
|
-
kdf_params: kdfParams
|
|
205
|
-
}), nonce, keyObject.crypto.symmetric_alg);
|
|
206
|
-
if (!key) throw new InvalidPasswordError('Invalid password');
|
|
207
|
-
if (_Buffer.from(key).length === 64) return _Buffer.from(key).toString('hex');
|
|
208
|
-
return _Buffer.from(key).toString('utf-8');
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Export private key to keystore secret-storage format.
|
|
212
|
-
* @param {String} name Key name.
|
|
213
|
-
* @param {String} password User-supplied password.
|
|
214
|
-
* @param {String|Buffer} privateKey Private key as hex-string or a Buffer.
|
|
215
|
-
* @param {Buffer} nonce Randomly generated 24byte nonce.
|
|
216
|
-
* @param {Buffer} salt Randomly generated 16byte salt.
|
|
217
|
-
* @param {Object=} options Encryption parameters.
|
|
218
|
-
* @param {String=} options.kdf Key derivation function (default: pbkdf2).
|
|
219
|
-
* @param {String=} options.cipher Symmetric cipher (default: constants.cipher).
|
|
220
|
-
* @param {Object=} options.kdfparams KDF parameters (default: constants.<kdf>).
|
|
221
|
-
* @return {Object}
|
|
222
|
-
*/
|
|
223
|
-
|
|
224
|
-
export async function dump(name, password, privateKey) {
|
|
225
|
-
let nonce = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : nacl.randomBytes(24);
|
|
226
|
-
let salt = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : nacl.randomBytes(16);
|
|
227
|
-
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
228
|
-
const opt = Object.assign({}, DEFAULTS.crypto, options);
|
|
229
|
-
return marshal(name, await deriveKey(password, salt, opt), typeof privateKey === 'string' ? _Buffer.from(privateKey, 'hex') : privateKey, nonce, salt, opt);
|
|
230
|
-
}
|
|
231
|
-
export function validateKeyObj(obj) {
|
|
232
|
-
const root = ['crypto', 'id', 'version', 'public_key'];
|
|
233
|
-
const cryptoKeys = ['cipher_params', 'ciphertext', 'symmetric_alg', 'kdf', 'kdf_params'];
|
|
234
|
-
const missingRootKeys = root.filter(key => !Object.prototype.hasOwnProperty.call(obj, key));
|
|
235
|
-
if (missingRootKeys.length) throw new InvalidKeyError(`Invalid key file format. Require properties: ${missingRootKeys}`);
|
|
236
|
-
const missingCryptoKeys = cryptoKeys.filter(key => !Object.prototype.hasOwnProperty.call(obj.crypto, key));
|
|
237
|
-
if (missingCryptoKeys.length) throw new InvalidKeyError(`Invalid key file format. Require properties: ${missingCryptoKeys}`);
|
|
238
|
-
return true;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
239
146
|
}
|
|
240
147
|
//# sourceMappingURL=keystore.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/keystore.js"],"names":["nacl","v4","uuid","encode","str2buf","ArgumentError","InvalidKeyError","UnsupportedAlgorithmError","InvalidPasswordError","DEFAULTS","crypto","secret_type","symmetric_alg","kdf","kdf_params","memlimit_kib","opslimit","parallelism","DERIVED_KEY_FUNCTIONS","argon2id","deriveKeyUsingArgon2id","pass","salt","options","mem","time","result","hash","hashLen","type","ArgonType","Argon2id","from","CRYPTO_FUNCTIONS","encrypt","encryptXsalsa20Poly1305","decrypt","decryptXsalsa20Poly1305","plaintext","key","nonce","secretbox","ciphertext","res","open","algo","deriveKey","password","Object","prototype","hasOwnProperty","call","marshal","name","derivedKey","privateKey","opt","assign","version","public_key","getAddressFromPriv","id","toString","cipher_params","secret","keys","sign","keyPair","fromSecretKey","publicBuffer","publicKey","recover","keyObject","validateKeyObj","Uint8Array","kdfParams","length","dump","randomBytes","obj","root","cryptoKeys","missingRootKeys","filter","missingCryptoKeys"],"mappings":";;;;AAAA,OAAOA,IAAP,MAAiB,WAAjB;AACA,SAASC,EAAE,IAAIC,IAAf,QAA2B,iBAA3B;AACA,0DAAgC,sDAAhC;;;;;SACSC,M;SACAC,O;SAEPC,a,EAAeC,e,EAAiBC,yB,EAA2BC,oB;AAG7D;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMC,QAAQ,GAAG;AACfC,EAAAA,MAAM,EAAE;AACNC,IAAAA,WAAW,EAAE,SADP;AAENC,IAAAA,aAAa,EAAE,mBAFT;AAGNC,IAAAA,GAAG,EAAE,UAHC;AAINC,IAAAA,UAAU,EAAE;AACVC,MAAAA,YAAY,EAAE,KADJ;AAEVC,MAAAA,QAAQ,EAAE,CAF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,UAAZ,EAAwB,KAAxB,CAAjC,GAAkEA,UAHtD,EAIZf,KAJY,EAKZlB,IALY,EAMZkC,GANY,CAAd;AAQD;AAED,OAAO,SAASiB,cAAT,CAAyBM,GAAzB,EAA8B;AACnC,QAAMC,IAAI,GAAG,CAAC,QAAD,EAAW,IAAX,EAAiB,SAAjB,EAA4B,YAA5B,CAAb;AACA,QAAMC,UAAU,GAAG,CAAC,eAAD,EAAkB,YAAlB,EAAgC,eAAhC,EAAiD,KAAjD,EAAwD,YAAxD,CAAnB;AAEA,QAAMC,eAAe,GAAGF,IAAI,CAACG,MAAL,CAAY5C,GAAG,IAAI,CAACS,MAAM,CAACC,SAAP,CAAiBC,cAAjB,CAAgCC,IAAhC,CAAqC4B,GAArC,EAA0CxC,GAA1C,CAApB,CAAxB;AACA,MAAI2C,eAAe,CAACN,MAApB,EAA4B,MAAM,IAAItE,eAAJ,CAAqB,gDAA+C4E,eAAgB,EAApF,CAAN;AAE5B,QAAME,iBAAiB,GAAGH,UAAU,CACjCE,MADuB,CAChB5C,GAAG,IAAI,CAACS,MAAM,CAACC,SAAP,CAAiBC,cAAjB,CAAgCC,IAAhC,CAAqC4B,GAAG,CAACrE,MAAzC,EAAiD6B,GAAjD,CADQ,CAA1B;AAEA,MAAI6C,iBAAiB,CAACR,MAAtB,EAA8B,MAAM,IAAItE,eAAJ,CAAqB,gDAA+C8E,iBAAkB,EAAtF,CAAN;AAE9B,SAAO,IAAP;AACD","sourcesContent":["import nacl from 'tweetnacl'\nimport { v4 as uuid } from '@aeternity/uuid'\nimport { ArgonType, hash } from '@aeternity/argon2-browser/dist/argon2-bundled.min.js'\nimport { encode } from '../tx/builder/helpers'\nimport { str2buf } from './bytes'\nimport {\n ArgumentError, InvalidKeyError, UnsupportedAlgorithmError, InvalidPasswordError\n} from './errors'\n\n/**\n * KeyStore module\n * @module @aeternity/aepp-sdk/es/utils/keystore\n * @example import { Keystore } from '@aeternity/aepp-sdk'\n * @example const { Keystore } = require('@aeternity/aepp-sdk')\n */\n\nconst DEFAULTS = {\n crypto: {\n secret_type: 'ed25519',\n symmetric_alg: 'xsalsa20-poly1305',\n kdf: 'argon2id',\n kdf_params: {\n memlimit_kib: 65536,\n opslimit: 3,\n parallelism: 1\n }\n }\n}\n\n// DERIVED KEY PART\nconst DERIVED_KEY_FUNCTIONS = {\n argon2id: deriveKeyUsingArgon2id\n}\n\nexport async function deriveKeyUsingArgon2id (pass, salt, options) {\n const { memlimit_kib: mem, opslimit: time } = options.kdf_params\n\n const result = (await hash({\n hashLen: 32,\n pass,\n salt,\n time,\n mem,\n type: ArgonType.Argon2id\n })).hash\n return Buffer.from(result)\n}\n\n// CRYPTO PART\nconst CRYPTO_FUNCTIONS = {\n 'xsalsa20-poly1305': { encrypt: encryptXsalsa20Poly1305, decrypt: decryptXsalsa20Poly1305 }\n}\n\nfunction encryptXsalsa20Poly1305 ({ plaintext, key, nonce }) {\n return nacl.secretbox(plaintext, nonce, key)\n}\n\nfunction decryptXsalsa20Poly1305 ({ ciphertext, key, nonce }) {\n const res = nacl.secretbox.open(ciphertext, nonce, key)\n if (!res) throw new InvalidPasswordError('Invalid password or nonce')\n return res\n}\n\n/**\n * Symmetric private key encryption using secret (derived) key.\n * @param {Buffer|string} plaintext Data to be encrypted.\n * @param {Buffer|string} key Secret key.\n * @param {Buffer|string} nonce Randomly generated nonce.\n * @param {string=} algo Encryption algorithm (default: DEFAULTS.crypto.symmetric_alg).\n * @return {Buffer} Encrypted data.\n */\nfunction encrypt (plaintext, key, nonce, algo = DEFAULTS.crypto.symmetric_alg) {\n if (!CRYPTO_FUNCTIONS[algo]) throw new UnsupportedAlgorithmError(algo)\n return CRYPTO_FUNCTIONS[algo].encrypt({ plaintext, nonce, key })\n}\n\n/**\n * Symmetric private key decryption using secret (derived) key.\n * @param {Buffer|Uint8Array} ciphertext Data to be decrypted.\n * @param {Buffer|Uint8Array} key Secret key.\n * @param {Buffer|Uint8Array} nonce Nonce from key-object.\n * @param {string=} algo Encryption algorithm.\n * @return {Buffer} Decrypted data.\n */\nfunction decrypt (ciphertext, key, nonce, algo) {\n if (!CRYPTO_FUNCTIONS[algo]) throw new UnsupportedAlgorithmError(algo)\n return CRYPTO_FUNCTIONS[algo].decrypt({ ciphertext, nonce, key })\n}\n\n/**\n * Derive secret key from password with key derivation function.\n * @param {string} password User-supplied password.\n * @param {Buffer|Uint8Array} nonce Randomly generated nonce.\n * @param {Object=} options Encryption parameters.\n * @param {string=} options.kdf Key derivation function (default: DEFAULTS.crypto.kdf).\n * @param {Object=} options.kdf_params KDF parameters (default: DEFAULTS.crypto.kdf_params).\n * @return {Buffer} Secret key derived from password.\n */\nasync function deriveKey (password, nonce, options = {\n kdf_params: DEFAULTS.crypto.kdf_params,\n kdf: DEFAULTS.crypto.kdf\n}) {\n if (!nonce) throw new ArgumentError('nonce', 'provided', nonce)\n if (password == null) throw new ArgumentError('password', 'provided', password)\n\n if (!Object.prototype.hasOwnProperty.call(DERIVED_KEY_FUNCTIONS, options.kdf)) {\n throw new UnsupportedAlgorithmError(options.kdf)\n }\n\n return DERIVED_KEY_FUNCTIONS[options.kdf](password, nonce, options)\n}\n\n/**\n * Assemble key data object in secret-storage format.\n * @param {Buffer} name Key name.\n * @param {Buffer} derivedKey Password-derived secret key.\n * @param {Buffer} privateKey Private key.\n * @param {Buffer} nonce Randomly generated 24byte nonce.\n * @param {Buffer} salt Randomly generated 16byte salt.\n * @param {Object=} options Encryption parameters.\n * @param {string=} options.kdf Key derivation function (default: argon2id).\n * @param {string=} options.cipher Symmetric cipher (default: constants.cipher).\n * @param {Object=} options.kdf_params KDF parameters (default: constants.<kdf>).\n * @return {Object}\n */\nfunction marshal (name, derivedKey, privateKey, nonce, salt, options = {}) {\n const opt = Object.assign({}, DEFAULTS.crypto, options)\n return Object.assign(\n { name, version: 1, public_key: getAddressFromPriv(privateKey), id: uuid() },\n {\n crypto: Object.assign(\n {\n secret_type: opt.secret_type,\n symmetric_alg: opt.symmetric_alg,\n ciphertext: Buffer.from(encrypt(Buffer.from(privateKey), derivedKey, nonce, opt.symmetric_alg)).toString('hex'),\n cipher_params: { nonce: Buffer.from(nonce).toString('hex') }\n },\n { kdf: opt.kdf, kdf_params: { ...opt.kdf_params, salt: Buffer.from(salt).toString('hex') } }\n )\n }\n )\n}\n\nexport function getAddressFromPriv (secret) {\n const keys = nacl.sign.keyPair.fromSecretKey(str2buf(secret))\n const publicBuffer = Buffer.from(keys.publicKey)\n return encode(publicBuffer, 'ak')\n}\n\n/**\n * Recover plaintext private key from secret-storage key object.\n * @param {String} password Keystore object password.\n * @param {Object} keyObject Keystore object.\n * @return {Buffer} Plaintext private key.\n */\nexport async function recover (password, keyObject) {\n validateKeyObj(keyObject)\n const nonce = Uint8Array.from(str2buf(keyObject.crypto.cipher_params.nonce))\n const salt = Uint8Array.from(str2buf(keyObject.crypto.kdf_params.salt))\n const kdfParams = keyObject.crypto.kdf_params\n const kdf = keyObject.crypto.kdf\n\n const key = await decrypt(\n Uint8Array.from(str2buf(keyObject.crypto.ciphertext)),\n await deriveKey(password, salt, { kdf, kdf_params: kdfParams }),\n nonce,\n keyObject.crypto.symmetric_alg\n )\n if (!key) throw new InvalidPasswordError('Invalid password')\n\n if (Buffer.from(key).length === 64) return Buffer.from(key).toString('hex')\n return Buffer.from(key).toString('utf-8')\n}\n\n/**\n * Export private key to keystore secret-storage format.\n * @param {String} name Key name.\n * @param {String} password User-supplied password.\n * @param {String|Buffer} privateKey Private key as hex-string or a Buffer.\n * @param {Buffer} nonce Randomly generated 24byte nonce.\n * @param {Buffer} salt Randomly generated 16byte salt.\n * @param {Object=} options Encryption parameters.\n * @param {String=} options.kdf Key derivation function (default: pbkdf2).\n * @param {String=} options.cipher Symmetric cipher (default: constants.cipher).\n * @param {Object=} options.kdfparams KDF parameters (default: constants.<kdf>).\n * @return {Object}\n */\nexport async function dump (\n name,\n password,\n privateKey,\n nonce = nacl.randomBytes(24),\n salt = nacl.randomBytes(16),\n options = {}\n) {\n const opt = Object.assign({}, DEFAULTS.crypto, options)\n return marshal(\n name,\n await deriveKey(password, salt, opt),\n typeof privateKey === 'string' ? Buffer.from(privateKey, 'hex') : privateKey,\n nonce,\n salt,\n opt\n )\n}\n\nexport function validateKeyObj (obj) {\n const root = ['crypto', 'id', 'version', 'public_key']\n const cryptoKeys = ['cipher_params', 'ciphertext', 'symmetric_alg', 'kdf', 'kdf_params']\n\n const missingRootKeys = root.filter(key => !Object.prototype.hasOwnProperty.call(obj, key))\n if (missingRootKeys.length) throw new InvalidKeyError(`Invalid key file format. Require properties: ${missingRootKeys}`)\n\n const missingCryptoKeys = cryptoKeys\n .filter(key => !Object.prototype.hasOwnProperty.call(obj.crypto, key))\n if (missingCryptoKeys.length) throw new InvalidKeyError(`Invalid key file format. Require properties: ${missingCryptoKeys}`)\n\n return true\n}\n"],"file":"keystore.mjs"}
|
|
1
|
+
{"version":3,"file":"keystore.mjs","names":["nacl","v4","uuid","getAddressFromPriv","bytesToHex","hexToBytes","InvalidPasswordError","DERIVED_KEY_FUNCTIONS","argon2id","pass","salt","params","memlimit_kib","mem","opslimit","time","hash","hashLen","type","ArgonType","Argon2id","CRYPTO_FUNCTIONS","encrypt","secretbox","decrypt","res","open","CRYPTO_DEFAULTS","secret_type","symmetric_alg","kdf","kdf_params","parallelism","plaintext","key","nonce","algo","ciphertext","deriveKey","password","kdfParams","recover","crypto","cipher_params","dump","name","privateKey","randomBytes","options","opt","derivedKey","payload","version","public_key","id"],"sources":["../../src/utils/keystore.ts"],"sourcesContent":["import nacl from 'tweetnacl';\nimport { v4 as uuid } from '@aeternity/uuid';\n// js extension is required for mjs build\n// eslint-disable-next-line import/extensions\nimport { ArgonType, hash } from '@aeternity/argon2-browser/dist/argon2-bundled.min.js';\nimport { getAddressFromPriv } from './crypto';\nimport { bytesToHex, hexToBytes } from './bytes';\nimport { InvalidPasswordError } from './errors';\n\nconst DERIVED_KEY_FUNCTIONS = {\n async argon2id(\n pass: string | Uint8Array,\n salt: string | Uint8Array,\n params: Partial<Keystore['crypto']['kdf_params']>,\n ): Promise<Uint8Array> {\n const { memlimit_kib: mem, opslimit: time } = params;\n\n return (await hash({\n hashLen: 32,\n pass,\n salt,\n time,\n mem,\n type: ArgonType.Argon2id,\n })).hash;\n },\n};\n\nconst CRYPTO_FUNCTIONS = {\n 'xsalsa20-poly1305': {\n encrypt: nacl.secretbox,\n decrypt(...args: Parameters<typeof nacl.secretbox.open>): Uint8Array {\n const res = nacl.secretbox.open(...args);\n if (res == null) throw new InvalidPasswordError();\n return res;\n },\n },\n};\n\nexport interface Keystore {\n name: string;\n version: 1;\n public_key: string;\n id: string;\n crypto: {\n secret_type: 'ed25519';\n symmetric_alg: keyof typeof CRYPTO_FUNCTIONS;\n ciphertext: string;\n cipher_params: {\n nonce: string;\n };\n kdf: keyof typeof DERIVED_KEY_FUNCTIONS;\n kdf_params: {\n memlimit_kib: number;\n opslimit: number;\n parallelism: number;\n salt: string;\n };\n };\n}\n\nconst CRYPTO_DEFAULTS = {\n secret_type: 'ed25519',\n symmetric_alg: 'xsalsa20-poly1305',\n kdf: 'argon2id',\n kdf_params: {\n memlimit_kib: 65536,\n opslimit: 3,\n parallelism: 1,\n },\n} as const;\n\n/**\n * Symmetric private key encryption using secret (derived) key.\n * @param plaintext - Data to be encrypted.\n * @param key - Secret key.\n * @param nonce - Randomly generated nonce.\n * @param algo - Encryption algorithm.\n * @returns Encrypted data.\n */\nfunction encrypt(\n plaintext: Uint8Array,\n key: Uint8Array,\n nonce: Uint8Array,\n algo: keyof typeof CRYPTO_FUNCTIONS = CRYPTO_DEFAULTS.symmetric_alg,\n): Uint8Array {\n return CRYPTO_FUNCTIONS[algo].encrypt(plaintext, nonce, key);\n}\n\n/**\n * Symmetric private key decryption using secret (derived) key.\n * @param ciphertext - Data to be decrypted.\n * @param key - Secret key.\n * @param nonce - Nonce from key-object.\n * @param algo - Encryption algorithm.\n * @returns Decrypted data.\n */\nfunction decrypt(\n ciphertext: Uint8Array,\n key: Uint8Array,\n nonce: Uint8Array,\n algo: keyof typeof CRYPTO_FUNCTIONS = CRYPTO_DEFAULTS.symmetric_alg,\n): Uint8Array {\n return CRYPTO_FUNCTIONS[algo].decrypt(ciphertext, nonce, key);\n}\n\n/**\n * Derive secret key from password with key derivation function.\n * @param password - User-supplied password.\n * @param nonce - Randomly generated nonce.\n * @param kdf - Key derivation function.\n * @param kdfParams - KDF parameters.\n * @returns Secret key derived from password.\n */\nasync function deriveKey(\n password: string | Uint8Array,\n nonce: string | Uint8Array,\n kdf: Keystore['crypto']['kdf'],\n kdfParams: Omit<Keystore['crypto']['kdf_params'], 'salt'>,\n): Promise<Uint8Array> {\n return DERIVED_KEY_FUNCTIONS[kdf](password, nonce, kdfParams);\n}\n\n/**\n * Recover plaintext private key from secret-storage key object.\n * @param password - Keystore object password.\n * @param keystore - Keystore object.\n * @returns Plaintext private key.\n */\nexport async function recover(\n password: string | Uint8Array,\n { crypto }: Keystore,\n): Promise<string> {\n const salt = hexToBytes(crypto.kdf_params.salt);\n return bytesToHex(decrypt(\n hexToBytes(crypto.ciphertext),\n await deriveKey(password, salt, crypto.kdf, crypto.kdf_params),\n hexToBytes(crypto.cipher_params.nonce),\n crypto.symmetric_alg,\n ));\n}\n\n/**\n * Export private key to keystore secret-storage format.\n * @param name - Key name.\n * @param password - User-supplied password.\n * @param privateKey - Private key as hex-string or a Buffer.\n * @param nonce - Randomly generated 24byte nonce.\n * @param salt - Randomly generated 16byte salt.\n * @param options - Encryption parameters.\n * @param options.kdf - Key derivation function.\n * @param options.kdf_params - KDF parameters.\n */\nexport async function dump(\n name: string,\n password: string | Uint8Array,\n privateKey: string | Uint8Array,\n nonce: Uint8Array = nacl.randomBytes(24),\n salt: Uint8Array = nacl.randomBytes(16),\n options?: Partial<Keystore['crypto']>,\n): Promise<Keystore> {\n const opt = { ...CRYPTO_DEFAULTS, ...options };\n const derivedKey = await deriveKey(password, salt, opt.kdf, opt.kdf_params);\n const payload = typeof privateKey === 'string' ? hexToBytes(privateKey) : privateKey;\n return {\n name,\n version: 1,\n public_key: getAddressFromPriv(payload),\n id: uuid(),\n crypto: {\n secret_type: opt.secret_type,\n symmetric_alg: opt.symmetric_alg,\n ciphertext: bytesToHex(encrypt(payload, derivedKey, nonce, opt.symmetric_alg)),\n cipher_params: { nonce: bytesToHex(nonce) },\n kdf: opt.kdf,\n kdf_params: {\n ...opt.kdf_params,\n salt: bytesToHex(salt),\n },\n },\n };\n}\n"],"mappings":"AAAA,OAAOA,IAAP,MAAiB,WAAjB;AACA,SAASC,EAAE,IAAIC,IAAf,QAA2B,iBAA3B,C,CACA;AACA;;AACA,0DAAgC,sDAAhC;;;;;SACSC,kB;SACAC,U,EAAYC,U;SACZC,oB;AAET,MAAMC,qBAAqB,GAAG;EAC5B,MAAMC,QAAN,CACEC,IADF,EAEEC,IAFF,EAGEC,MAHF,EAIuB;IACrB,MAAM;MAAEC,YAAY,EAAEC,GAAhB;MAAqBC,QAAQ,EAAEC;IAA/B,IAAwCJ,MAA9C;IAEA,OAAO,CAAC,MAAMK,IAAI,CAAC;MACjBC,OAAO,EAAE,EADQ;MAEjBR,IAFiB;MAGjBC,IAHiB;MAIjBK,IAJiB;MAKjBF,GALiB;MAMjBK,IAAI,EAAEC,SAAS,CAACC;IANC,CAAD,CAAX,EAOHJ,IAPJ;EAQD;;AAhB2B,CAA9B;AAmBA,MAAMK,gBAAgB,GAAG;EACvB,qBAAqB;IACnBC,OAAO,EAAEtB,IAAI,CAACuB,SADK;;IAEnBC,OAAO,GAA8D;MACnE,MAAMC,GAAG,GAAGzB,IAAI,CAACuB,SAAL,CAAeG,IAAf,CAAoB,YAApB,CAAZ;MACA,IAAID,GAAG,IAAI,IAAX,EAAiB,MAAM,IAAInB,oBAAJ,EAAN;MACjB,OAAOmB,GAAP;IACD;;EANkB;AADE,CAAzB;AAiCA,MAAME,eAAe,GAAG;EACtBC,WAAW,EAAE,SADS;EAEtBC,aAAa,EAAE,mBAFO;EAGtBC,GAAG,EAAE,UAHiB;EAItBC,U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,CAACM,IAAD;MAFN;IANN;EALH,CAAP;AAiBD"}
|
|
@@ -6,24 +6,21 @@ export default class MPTree {
|
|
|
6
6
|
private static nodeHash;
|
|
7
7
|
/**
|
|
8
8
|
* Deserialize Merkle Patricia Tree
|
|
9
|
-
* @
|
|
10
|
-
* @
|
|
11
|
-
* @return {MPTree} Merkle Patricia Tree
|
|
9
|
+
* @param binary - Binary
|
|
10
|
+
* @returns Merkle Patricia Tree
|
|
12
11
|
*/
|
|
13
12
|
constructor(binary: MPTreeBinary);
|
|
14
13
|
isEqual(tree: MPTree): boolean;
|
|
15
14
|
private static parseNode;
|
|
16
15
|
/**
|
|
17
16
|
* Serialize Merkle Patricia Tree
|
|
18
|
-
* @
|
|
19
|
-
* @return {Array} Binary
|
|
17
|
+
* @returns Binary
|
|
20
18
|
*/
|
|
21
19
|
serialize(): MPTreeBinary;
|
|
22
20
|
/**
|
|
23
21
|
* Retrieve value from Merkle Patricia Tree
|
|
24
|
-
* @
|
|
25
|
-
* @
|
|
26
|
-
* @return {Buffer} Value associated to the specified key
|
|
22
|
+
* @param _key - The key of the element to retrieve
|
|
23
|
+
* @returns Value associated to the specified key
|
|
27
24
|
*/
|
|
28
|
-
get(
|
|
25
|
+
get(_key: string): Buffer | undefined;
|
|
29
26
|
}
|
package/es/utils/mptree.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _buffer from "buffer";
|
|
2
|
+
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
2
3
|
const {
|
|
3
4
|
Buffer: _Buffer
|
|
4
5
|
} = _buffer;
|
|
@@ -19,11 +20,13 @@ const {
|
|
|
19
20
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
20
21
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
21
22
|
*/
|
|
23
|
+
|
|
24
|
+
/* eslint-disable default-case */
|
|
22
25
|
import _rlp from 'rlp';
|
|
23
26
|
const {
|
|
24
27
|
encode: rlpEncode
|
|
25
28
|
} = _rlp;
|
|
26
|
-
import { hash } from "./crypto
|
|
29
|
+
import { hash } from "./crypto.mjs";
|
|
27
30
|
import { MerkleTreeHashMismatchError, MissingNodeInTreeError, UnknownPathNibbleError, UnknownNodeLengthError } from "./errors.mjs";
|
|
28
31
|
var NodeType;
|
|
29
32
|
|
|
@@ -39,9 +42,8 @@ export default class MPTree {
|
|
|
39
42
|
}
|
|
40
43
|
/**
|
|
41
44
|
* Deserialize Merkle Patricia Tree
|
|
42
|
-
* @
|
|
43
|
-
* @
|
|
44
|
-
* @return {MPTree} Merkle Patricia Tree
|
|
45
|
+
* @param binary - Binary
|
|
46
|
+
* @returns Merkle Patricia Tree
|
|
45
47
|
*/
|
|
46
48
|
|
|
47
49
|
|
|
@@ -90,15 +92,17 @@ export default class MPTree {
|
|
|
90
92
|
|
|
91
93
|
case 2:
|
|
92
94
|
{
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
var _context;
|
|
96
|
+
|
|
97
|
+
const nibble = node[0][0] >> 4; // eslint-disable-line no-bitwise
|
|
98
|
+
|
|
95
99
|
if (nibble > 3) throw new UnknownPathNibbleError(nibble);
|
|
96
100
|
const type = nibble <= 1 ? NodeType.Extension : NodeType.Leaf;
|
|
97
|
-
const slice = [0, 2].
|
|
101
|
+
const slice = _includesInstanceProperty(_context = [0, 2]).call(_context, nibble) ? 2 : 1;
|
|
98
102
|
return {
|
|
99
103
|
type,
|
|
100
104
|
payload: [node[1]],
|
|
101
|
-
path:
|
|
105
|
+
path: node[0].toString('hex').slice(slice)
|
|
102
106
|
};
|
|
103
107
|
}
|
|
104
108
|
|
|
@@ -108,8 +112,7 @@ export default class MPTree {
|
|
|
108
112
|
}
|
|
109
113
|
/**
|
|
110
114
|
* Serialize Merkle Patricia Tree
|
|
111
|
-
* @
|
|
112
|
-
* @return {Array} Binary
|
|
115
|
+
* @returns Binary
|
|
113
116
|
*/
|
|
114
117
|
|
|
115
118
|
|
|
@@ -121,16 +124,17 @@ export default class MPTree {
|
|
|
121
124
|
}
|
|
122
125
|
/**
|
|
123
126
|
* Retrieve value from Merkle Patricia Tree
|
|
124
|
-
* @
|
|
125
|
-
* @
|
|
126
|
-
* @return {Buffer} Value associated to the specified key
|
|
127
|
+
* @param _key - The key of the element to retrieve
|
|
128
|
+
* @returns Value associated to the specified key
|
|
127
129
|
*/
|
|
128
130
|
|
|
129
131
|
|
|
130
|
-
get(
|
|
132
|
+
get(_key) {
|
|
131
133
|
let searchFrom = this.rootHash;
|
|
134
|
+
let key = _key;
|
|
132
135
|
|
|
133
136
|
while (true) {
|
|
137
|
+
// eslint-disable-line no-constant-condition
|
|
134
138
|
const {
|
|
135
139
|
type,
|
|
136
140
|
payload,
|
|
@@ -140,14 +144,14 @@ export default class MPTree {
|
|
|
140
144
|
switch (type) {
|
|
141
145
|
case NodeType.Branch:
|
|
142
146
|
if (key.length === 0) return payload[16];
|
|
143
|
-
searchFrom = payload[
|
|
144
|
-
key = key.
|
|
147
|
+
searchFrom = payload[+`0x${key[0]}`].toString('hex');
|
|
148
|
+
key = key.substring(1);
|
|
145
149
|
break;
|
|
146
150
|
|
|
147
151
|
case NodeType.Extension:
|
|
148
|
-
if (key.
|
|
152
|
+
if (key.substring(0, path === null || path === void 0 ? void 0 : path.length) !== path) return undefined;
|
|
149
153
|
searchFrom = payload[0].toString('hex');
|
|
150
|
-
key = key.
|
|
154
|
+
key = key.substring(path.length);
|
|
151
155
|
break;
|
|
152
156
|
|
|
153
157
|
case NodeType.Leaf:
|
package/es/utils/mptree.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"mptree.mjs","names":["hash","MerkleTreeHashMismatchError","MissingNodeInTreeError","UnknownPathNibbleError","UnknownNodeLengthError","NodeType","MPTree","nodeHash","node","from","rlpEncode","toString","constructor","binary","rootHash","nodes","Object","fromEntries","map","undefined","entries","forEach","key","type","payload","parseNode","Branch","slice","filter","n","length","Extension","isEqual","tree","path","nibble","Leaf","serialize","mptHash","value","get","_key","searchFrom","substring"],"sources":["../../src/utils/mptree.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2021 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/* eslint-disable default-case */\nimport { encode as rlpEncode } from 'rlp';\nimport type { Input } from 'rlp';\nimport { hash } from './crypto';\nimport {\n MerkleTreeHashMismatchError,\n MissingNodeInTreeError,\n UnknownPathNibbleError,\n UnknownNodeLengthError,\n} from './errors';\n\nenum NodeType {\n Branch,\n Extension,\n Leaf,\n}\n\nexport type MPTreeBinary = [Buffer, Array<[Buffer, Buffer[]]>];\n\nexport default class MPTree {\n private readonly rootHash: string;\n\n private readonly nodes: { [key: string]: Buffer[] };\n\n private static nodeHash(node: Input): string {\n return Buffer.from(hash(rlpEncode(node))).toString('hex');\n }\n\n /**\n * Deserialize Merkle Patricia Tree\n * @param binary - Binary\n * @returns Merkle Patricia Tree\n */\n constructor(binary: MPTreeBinary) {\n this.rootHash = binary[0].toString('hex');\n this.nodes = Object.fromEntries(\n binary[1].map((node) => [node[0].toString('hex'), node[1]]),\n );\n\n if (this.nodes[this.rootHash] === undefined) throw new MissingNodeInTreeError('Can\\'t find a node by root hash');\n Object.entries(this.nodes).forEach(([key, node]) => {\n if (MPTree.nodeHash(node) !== key) throw new MerkleTreeHashMismatchError();\n const { type, payload } = MPTree.parseNode(node);\n switch (type) {\n case NodeType.Branch:\n payload\n .slice(0, 16)\n .filter((n) => n.length)\n .forEach((n) => {\n if (this.nodes[n.toString('hex')] === undefined) {\n throw new MissingNodeInTreeError('Can\\'t find a node by hash in branch node');\n }\n });\n break;\n case NodeType.Extension:\n if (this.nodes[payload[0].toString('hex')] === undefined) {\n throw new MissingNodeInTreeError('Can\\'t find a node by hash in extension node');\n }\n }\n });\n }\n\n isEqual(tree: MPTree): boolean {\n return this.rootHash === tree.rootHash;\n }\n\n private static parseNode(node: Buffer[]): {\n type: NodeType;\n payload: Buffer[];\n path: string | null;\n } {\n switch (node.length) {\n case 17:\n return { type: NodeType.Branch, payload: node, path: null };\n case 2: {\n const nibble = node[0][0] >> 4; // eslint-disable-line no-bitwise\n if (nibble > 3) throw new UnknownPathNibbleError(nibble);\n const type = nibble <= 1 ? NodeType.Extension : NodeType.Leaf;\n const slice = [0, 2].includes(nibble) ? 2 : 1;\n return { type, payload: [node[1]], path: node[0].toString('hex').slice(slice) };\n }\n default:\n throw new UnknownNodeLengthError(node.length);\n }\n }\n\n /**\n * Serialize Merkle Patricia Tree\n * @returns Binary\n */\n serialize(): MPTreeBinary {\n return [\n Buffer.from(this.rootHash, 'hex'),\n Object.entries(this.nodes).map(([mptHash, value]) => ([\n Buffer.from(mptHash, 'hex'),\n value,\n ])),\n ];\n }\n\n /**\n * Retrieve value from Merkle Patricia Tree\n * @param _key - The key of the element to retrieve\n * @returns Value associated to the specified key\n */\n get(_key: string): Buffer | undefined {\n let searchFrom = this.rootHash;\n let key = _key;\n while (true) { // eslint-disable-line no-constant-condition\n const { type, payload, path } = MPTree.parseNode(this.nodes[searchFrom]);\n switch (type) {\n case NodeType.Branch:\n if (key.length === 0) return payload[16];\n searchFrom = payload[+`0x${key[0]}`].toString('hex');\n key = key.substring(1);\n break;\n case NodeType.Extension:\n if (key.substring(0, path?.length) !== path) return undefined;\n searchFrom = payload[0].toString('hex');\n key = key.substring(path.length);\n break;\n case NodeType.Leaf:\n if (path !== key) return undefined;\n return payload[0];\n }\n }\n }\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,iBAAoC,KAApC;;;;SAESA,I;SAEPC,2B,EACAC,sB,EACAC,sB,EACAC,sB;IAGGC,Q;;WAAAA,Q;EAAAA,Q,CAAAA,Q;EAAAA,Q,CAAAA,Q;EAAAA,Q,CAAAA,Q;GAAAA,Q,KAAAA,Q;;AAQL,eAAe,MAAMC,MAAN,CAAa;EAKH,OAARC,QAAQ,CAACC,IAAD,EAAsB;IAC3C,OAAO,QAAOC,IAAP,CAAYT,IAAI,CAACU,SAAS,CAACF,IAAD,CAAV,CAAhB,EAAmCG,QAAnC,CAA4C,KAA5C,CAAP;EACD;EAED;AACF;AACA;AACA;AACA;;;EACEC,WAAW,CAACC,MAAD,EAAuB;IAChC,KAAKC,QAAL,GAAgBD,MAAM,CAAC,CAAD,CAAN,CAAUF,QAAV,CAAmB,KAAnB,CAAhB;IACA,KAAKI,KAAL,GAAaC,MAAM,CAACC,WAAP,CACXJ,MAAM,CAAC,CAAD,CAAN,CAAUK,GAAV,CAAeV,IAAD,IAAU,CAACA,IAAI,CAAC,CAAD,CAAJ,CAAQG,QAAR,CAAiB,KAAjB,CAAD,EAA0BH,IAAI,CAAC,CAAD,CAA9B,CAAxB,CADW,CAAb;IAIA,IAAI,KAAKO,KAAL,CAAW,KAAKD,QAAhB,MAA8BK,SAAlC,EAA6C,MAAM,IAAIjB,sBAAJ,CAA2B,iCAA3B,CAAN;IAC7Cc,MAAM,CAACI,OAAP,CAAe,KAAKL,KAApB,EAA2BM,OAA3B,CAAmC,QAAiB;MAAA,IAAhB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AAQnB,IAAR;QACE,KAAKlB,QAAQ,CAACqB,MAAd;UACE,IAAIJ,GAAG,CAACQ,MAAJ,KAAe,CAAnB,EAAsB,OAAON,OAAO,CAAC,EAAD,CAAd;UACtBkB,UAAU,GAAGlB,OAAO,CAAC,CAAE,KAAIF,GAAG,CAAC,CAAD,CAAI,EAAd,CAAP,CAAwBX,QAAxB,CAAiC,KAAjC,CAAb;UACAW,GAAG,GAAGA,GAAG,CAACqB,SAAJ,CAAc,CAAd,CAAN;UACA;;QACF,KAAKtC,QAAQ,CAAC0B,SAAd;UACE,IAAIT,GAAG,CAACqB,SAAJ,CAAc,CAAd,EAAiBT,IAAjB,aAAiBA,IAAjB,uBAAiBA,IAAI,CAAEJ,MAAvB,MAAmCI,IAAvC,EAA6C,OAAOf,SAAP;UAC7CuB,UAAU,GAAGlB,OAAO,CAAC,CAAD,CAAP,CAAWb,QAAX,CAAoB,KAApB,CAAb;UACAW,GAAG,GAAGA,GAAG,CAACqB,SAAJ,CAAcT,IAAI,CAACJ,MAAnB,CAAN;UACA;;QACF,KAAKzB,QAAQ,CAAC+B,IAAd;UACE,IAAIF,IAAI,KAAKZ,GAAb,EAAkB,OAAOH,SAAP;UAClB,OAAOK,OAAO,CAAC,CAAD,CAAd;MAbJ;IAeD;EACF;;AA3GyB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare const pause: (duration: number) => Promise<void>;
|
|
3
|
+
export declare const mapObject: <InputV, OutputV>(object: {
|
|
4
|
+
[k: string]: InputV;
|
|
5
|
+
}, fn: (value: [string, InputV], index: number, array: [string, InputV][]) => [string | number, OutputV]) => {
|
|
6
|
+
[k: string]: OutputV;
|
|
7
|
+
};
|
|
8
|
+
export declare const concatBuffers: (list: readonly Uint8Array[], totalLength?: number | undefined) => Buffer;
|
|
9
|
+
/**
|
|
10
|
+
* Object key type guard
|
|
11
|
+
* @param key - Maybe object key
|
|
12
|
+
* @param object - Object
|
|
13
|
+
*/
|
|
14
|
+
export declare function isKeyOfObject<T>(key: string | number | symbol, object: T): key is keyof T;
|
|
15
|
+
/**
|
|
16
|
+
* Array item type guard
|
|
17
|
+
* @param item - Maybe array item
|
|
18
|
+
* @param array - Array
|
|
19
|
+
*/
|
|
20
|
+
export declare function isItemOfArray<T>(item: any, array: readonly T[]): item is T;
|