@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/crypto.mjs
CHANGED
|
@@ -19,48 +19,43 @@ const {
|
|
|
19
19
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
20
20
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
21
21
|
*/
|
|
22
|
+
import nacl from 'tweetnacl'; // js extension is required for mjs build, not importing the whole package to reduce bundle size
|
|
23
|
+
// eslint-disable-next-line import/extensions
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
import _blakejsBlake2bJs from 'blakejs/blake2b.js';
|
|
26
|
+
const {
|
|
27
|
+
blake2b
|
|
28
|
+
} = _blakejsBlake2bJs;
|
|
29
|
+
import _varuintBitcoin from 'varuint-bitcoin';
|
|
30
|
+
const {
|
|
31
|
+
encode: varuintEncode
|
|
32
|
+
} = _varuintBitcoin;
|
|
30
33
|
import { str2buf } from "./bytes.mjs";
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import { NotImplementedError } from "./errors.mjs";
|
|
34
|
-
export * from "./crypto-ts.mjs";
|
|
35
|
-
export { sha256hash };
|
|
36
|
-
const Ecb = aesjs.ModeOfOperation.ecb;
|
|
34
|
+
import { concatBuffers } from "./other.mjs";
|
|
35
|
+
import { decode, encode, Encoding } from "./encoder.mjs";
|
|
37
36
|
/**
|
|
38
37
|
* Generate address from secret key
|
|
39
|
-
* @
|
|
40
|
-
* @
|
|
41
|
-
* @return {String} Public key
|
|
38
|
+
* @param secret - Private key
|
|
39
|
+
* @returns Public key encoded as address
|
|
42
40
|
*/
|
|
43
41
|
|
|
44
42
|
export function getAddressFromPriv(secret) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return encode(publicBuffer, 'ak');
|
|
43
|
+
const secretBuffer = typeof secret === 'string' ? str2buf(secret) : secret;
|
|
44
|
+
const keys = nacl.sign.keyPair.fromSecretKey(secretBuffer);
|
|
45
|
+
return encode(keys.publicKey, Encoding.AccountAddress);
|
|
50
46
|
}
|
|
51
47
|
/**
|
|
52
48
|
* Check if address is valid
|
|
53
|
-
* @
|
|
54
|
-
* @param
|
|
55
|
-
* @
|
|
56
|
-
* @return {Boolean} valid
|
|
49
|
+
* @param address - Address
|
|
50
|
+
* @param prefix - Transaction prefix. Default: 'ak'
|
|
51
|
+
* @returns is valid
|
|
57
52
|
*/
|
|
58
53
|
|
|
59
54
|
export function isAddressValid(address) {
|
|
60
|
-
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] :
|
|
55
|
+
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Encoding.AccountAddress;
|
|
61
56
|
|
|
62
57
|
try {
|
|
63
|
-
decode(address
|
|
58
|
+
decode(address);
|
|
64
59
|
return true;
|
|
65
60
|
} catch (e) {
|
|
66
61
|
return false;
|
|
@@ -68,19 +63,17 @@ export function isAddressValid(address) {
|
|
|
68
63
|
}
|
|
69
64
|
/**
|
|
70
65
|
* Generate a random salt (positive integer)
|
|
71
|
-
* @
|
|
72
|
-
* @return {Number} random salt
|
|
66
|
+
* @returns random salt
|
|
73
67
|
*/
|
|
74
68
|
|
|
75
|
-
export function
|
|
69
|
+
export function genSalt() {
|
|
76
70
|
return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER));
|
|
77
71
|
}
|
|
78
72
|
/**
|
|
79
73
|
* Converts a positive integer to the smallest possible
|
|
80
74
|
* representation in a binary digit representation
|
|
81
|
-
* @
|
|
82
|
-
* @
|
|
83
|
-
* @return {Buffer} - Encoded data
|
|
75
|
+
* @param value - Value to encode
|
|
76
|
+
* @returns Encoded number
|
|
84
77
|
*/
|
|
85
78
|
|
|
86
79
|
export function encodeUnsigned(value) {
|
|
@@ -88,29 +81,35 @@ export function encodeUnsigned(value) {
|
|
|
88
81
|
|
|
89
82
|
binary.writeUInt32BE(value);
|
|
90
83
|
return binary.slice(binary.findIndex(i => i !== 0));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Calculate 256bits Blake2b hash of `input`
|
|
87
|
+
* @param input - Data to hash
|
|
88
|
+
* @returns Hash
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
export function hash(input) {
|
|
92
|
+
return _Buffer.from(blake2b(input, undefined, 32)); // 256 bits
|
|
91
93
|
} // Todo Duplicated in tx builder. remove
|
|
92
94
|
|
|
93
95
|
/**
|
|
94
96
|
* Compute contract address
|
|
95
|
-
* @
|
|
96
|
-
* @param
|
|
97
|
-
* @param
|
|
98
|
-
* @
|
|
97
|
+
* @category contract
|
|
98
|
+
* @param owner - Address of contract owner
|
|
99
|
+
* @param nonce - Round when contract was created
|
|
100
|
+
* @returns Contract address
|
|
99
101
|
*/
|
|
100
102
|
|
|
101
103
|
export function encodeContractAddress(owner, nonce) {
|
|
102
|
-
const publicKey = decode(owner
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return encode(hash(binary), 'ct');
|
|
104
|
+
const publicKey = decode(owner);
|
|
105
|
+
const binary = concatBuffers([publicKey, encodeUnsigned(nonce)]);
|
|
106
|
+
return encode(hash(binary), Encoding.ContractAddress);
|
|
107
107
|
} // KEY-PAIR HELPERS
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
110
|
* Generate keyPair from secret key
|
|
111
|
-
* @
|
|
112
|
-
* @
|
|
113
|
-
* @return {Object} - Object with Private(privateKey) and Public(publicKey) keys
|
|
111
|
+
* @param secret - secret key
|
|
112
|
+
* @returns Object with Private(privateKey) and Public(publicKey) keys
|
|
114
113
|
*/
|
|
115
114
|
|
|
116
115
|
export function generateKeyPairFromSecret(secret) {
|
|
@@ -118,14 +117,12 @@ export function generateKeyPairFromSecret(secret) {
|
|
|
118
117
|
}
|
|
119
118
|
/**
|
|
120
119
|
* Generate a random ED25519 keypair
|
|
121
|
-
* @
|
|
122
|
-
* @
|
|
123
|
-
* @return {Object} Key pair
|
|
120
|
+
* @param raw - Whether to return raw (binary) keys
|
|
121
|
+
* @returns Key pair
|
|
124
122
|
*/
|
|
125
123
|
|
|
126
124
|
export function generateKeyPair() {
|
|
127
125
|
let raw = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
128
|
-
// <node>/apps/aens/test/aens_test_utils.erl
|
|
129
126
|
const keyPair = nacl.sign.keyPair();
|
|
130
127
|
|
|
131
128
|
const publicBuffer = _Buffer.from(keyPair.publicKey);
|
|
@@ -137,48 +134,19 @@ export function generateKeyPair() {
|
|
|
137
134
|
publicKey: publicBuffer,
|
|
138
135
|
secretKey: secretBuffer
|
|
139
136
|
};
|
|
140
|
-
} else {
|
|
141
|
-
return {
|
|
142
|
-
publicKey: encode(publicBuffer, 'ak'),
|
|
143
|
-
secretKey: secretBuffer.toString('hex')
|
|
144
|
-
};
|
|
145
137
|
}
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Encrypt given data using `password`
|
|
149
|
-
* @rtype (password: String, binaryData: Buffer) => Uint8Array
|
|
150
|
-
* @param {String} password - Password to encrypt with
|
|
151
|
-
* @param {Buffer} binaryData - Data to encrypt
|
|
152
|
-
* @return {Uint8Array} Encrypted data
|
|
153
|
-
*/
|
|
154
|
-
|
|
155
|
-
export function encryptKey(password, binaryData) {
|
|
156
|
-
const hashedPasswordBytes = sha256hash(password);
|
|
157
|
-
const aesEcb = new Ecb(hashedPasswordBytes);
|
|
158
|
-
return aesEcb.encrypt(binaryData);
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Decrypt given data using `password`
|
|
162
|
-
* @rtype (password: String, encrypted: String) => Uint8Array
|
|
163
|
-
* @param {String} password - Password to decrypt with
|
|
164
|
-
* @param {String} encrypted - Data to decrypt
|
|
165
|
-
* @return {Buffer} Decrypted data
|
|
166
|
-
*/
|
|
167
|
-
|
|
168
|
-
export function decryptKey(password, encrypted) {
|
|
169
|
-
const encryptedBytes = _Buffer.from(encrypted);
|
|
170
138
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
139
|
+
return {
|
|
140
|
+
publicKey: encode(publicBuffer, Encoding.AccountAddress),
|
|
141
|
+
secretKey: secretBuffer.toString('hex')
|
|
142
|
+
};
|
|
174
143
|
} // SIGNATURES
|
|
175
144
|
|
|
176
145
|
/**
|
|
177
146
|
* Generate signature
|
|
178
|
-
* @
|
|
179
|
-
* @param
|
|
180
|
-
* @
|
|
181
|
-
* @return {Buffer|Uint8Array} Signature
|
|
147
|
+
* @param data - Data to sign
|
|
148
|
+
* @param privateKey - Key to sign with
|
|
149
|
+
* @returns Signature
|
|
182
150
|
*/
|
|
183
151
|
|
|
184
152
|
export function sign(data, privateKey) {
|
|
@@ -186,23 +154,22 @@ export function sign(data, privateKey) {
|
|
|
186
154
|
}
|
|
187
155
|
/**
|
|
188
156
|
* Verify that signature was signed by public key
|
|
189
|
-
* @
|
|
190
|
-
* @param
|
|
191
|
-
* @param
|
|
192
|
-
* @
|
|
193
|
-
* @return {Boolean} Valid?
|
|
157
|
+
* @param data - Data to verify
|
|
158
|
+
* @param signature - Signature to verify
|
|
159
|
+
* @param publicKey - Key to verify against
|
|
160
|
+
* @returns Valid?
|
|
194
161
|
*/
|
|
195
162
|
|
|
196
|
-
export function verify(
|
|
197
|
-
|
|
163
|
+
export function verify(data, signature, publicKey) {
|
|
164
|
+
const publicKeyBuffer = typeof publicKey === 'string' ? str2buf(publicKey) : publicKey;
|
|
165
|
+
return nacl.sign.detached.verify(data, signature, publicKeyBuffer);
|
|
198
166
|
}
|
|
199
167
|
export function messageToHash(message) {
|
|
200
168
|
const p = _Buffer.from('aeternity Signed Message:\n', 'utf8');
|
|
201
169
|
|
|
202
170
|
const msg = _Buffer.from(message, 'utf8');
|
|
203
171
|
|
|
204
|
-
|
|
205
|
-
return hash(_Buffer.concat([_Buffer.from([p.length]), p, _Buffer.from([msg.length]), msg]));
|
|
172
|
+
return hash(concatBuffers([varuintEncode(p.length), p, varuintEncode(msg.length), msg]));
|
|
206
173
|
}
|
|
207
174
|
export function signMessage(message, privateKey) {
|
|
208
175
|
return sign(messageToHash(message), privateKey);
|
|
@@ -214,10 +181,9 @@ export function verifyMessage(str, signature, publicKey) {
|
|
|
214
181
|
* Check key pair for validity
|
|
215
182
|
*
|
|
216
183
|
* Sign a message, and then verifying that signature
|
|
217
|
-
* @
|
|
218
|
-
* @param
|
|
219
|
-
* @
|
|
220
|
-
* @return {Boolean} Valid?
|
|
184
|
+
* @param privateKey - Private key to verify
|
|
185
|
+
* @param publicKey - Public key to verify
|
|
186
|
+
* @returns Valid?
|
|
221
187
|
*/
|
|
222
188
|
|
|
223
189
|
export function isValidKeypair(privateKey, publicKey) {
|
package/es/utils/crypto.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/crypto.js"],"names":["nacl","aesjs","str2buf","encode","decode","sha256hash","hash","NotImplementedError","Ecb","ModeOfOperation","ecb","getAddressFromPriv","secret","keys","sign","keyPair","fromSecretKey","publicBuffer","from","publicKey","isAddressValid","address","prefix","e","salt","Math","floor","random","Number","MAX_SAFE_INTEGER","encodeUnsigned","value","binary","allocUnsafe","writeUInt32BE","slice","findIndex","i","encodeContractAddress","owner","nonce","concat","generateKeyPairFromSecret","generateKeyPair","raw","secretBuffer","secretKey","toString","encryptKey","password","binaryData","hashedPasswordBytes","aesEcb","encrypt","decryptKey","encrypted","encryptedBytes","decrypt","data","privateKey","detached","verify","str","signature","Uint8Array","messageToHash","message","p","msg","length","signMessage","verifyMessage","isValidKeypair"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AAEA,OAAOA,IAAP,MAAiB,WAAjB;AACA,OAAOC,KAAP,MAAkB,QAAlB;SAESC,O;SACAC,M,EAAQC,M,EAAQC,U;SAChBC,I;SACAC,mB;;AAGT,SAASF,UAAT;AAEA,MAAMG,GAAG,GAAGP,KAAK,CAACQ,eAAN,CAAsBC,GAAlC;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,kBAAT,CAA6BC,MAA7B,EAAqC;AAC1C,QAAMC,IAAI,GAAGb,IAAI,CAACc,IAAL,CAAUC,OAAV,CAAkBC,aAAlB,CAAgCd,OAAO,CAACU,MAAD,CAAvC,CAAb;;AACA,QAAMK,YAAY,GAAG,QAAOC,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AA2C;AAChD,SAAO7C,IAAI,CAACmD,aAAa,CAACC,OAAD,CAAd,EAAyBP,UAAzB,CAAX;AACD;AAED,OAAO,SAASY,aAAT,CAAwBT,GAAxB,EAA6BC,SAA7B,EAAwC5C,SAAxC,EAAmD;AACxD,SAAO0C,MAAM,CAACI,aAAa,CAACH,GAAD,CAAd,EAAqBC,SAArB,EAAgC5C,SAAhC,CAAb;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASqD,cAAT,CAAyBb,UAAzB,EAAqCxC,SAArC,EAAgD;AACrD,QAAM+C,OAAO,GAAG,QAAOhD,IAAP,CAAY,YAAZ,CAAhB;;AACA,QAAM6C,SAAS,GAAGjD,IAAI,CAACoD,OAAD,EAAUP,UAAV,CAAtB;AACA,SAAOE,MAAM,CAACK,OAAD,EAAUH,SAAV,EAAqB5C,SAArB,CAAb;AACD","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright 2018 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/**\n * Crypto module\n * @module @aeternity/aepp-sdk/es/utils/crypto\n * @example import { Crypto } from '@aeternity/aepp-sdk'\n */\n\nimport nacl from 'tweetnacl'\nimport aesjs from 'aes-js'\n\nimport { str2buf } from './bytes'\nimport { encode, decode, sha256hash } from './encoder'\nimport { hash } from './crypto-ts'\nimport { NotImplementedError } from './errors'\n\nexport * from './crypto-ts'\nexport { sha256hash }\n\nconst Ecb = aesjs.ModeOfOperation.ecb\n\n/**\n * Generate address from secret key\n * @rtype (secret: String) => tx: Promise[String]\n * @param {String} secret - Private key\n * @return {String} Public key\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 * Check if address is valid\n * @rtype (input: String) => valid: Boolean\n * @param {String} address - Address\n * @param {String} prefix Transaction prefix. Default: 'ak'\n * @return {Boolean} valid\n */\nexport function isAddressValid (address, prefix = 'ak') {\n try {\n decode(address, prefix)\n return true\n } catch (e) {\n return false\n }\n}\n\n/**\n * Generate a random salt (positive integer)\n * @rtype () => salt: Number\n * @return {Number} random salt\n */\nexport function salt () {\n return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER))\n}\n\n/**\n * Converts a positive integer to the smallest possible\n * representation in a binary digit representation\n * @rtype (value: Number) => Buffer\n * @param {Number} value - Value to encode\n * @return {Buffer} - Encoded data\n */\nexport function encodeUnsigned (value) {\n const binary = Buffer.allocUnsafe(4)\n binary.writeUInt32BE(value)\n return binary.slice(binary.findIndex(i => i !== 0))\n}\n\n// Todo Duplicated in tx builder. remove\n/**\n * Compute contract address\n * @rtype (owner: String, nonce: Number) => String\n * @param {String} owner - Address of contract owner\n * @param {Number} nonce - Round when contract was created\n * @return {String} - Contract address\n */\nexport function encodeContractAddress (owner, nonce) {\n const publicKey = decode(owner, 'ak')\n const binary = Buffer.concat([publicKey, encodeUnsigned(nonce)])\n return encode(hash(binary), 'ct')\n}\n\n// KEY-PAIR HELPERS\n\n/**\n * Generate keyPair from secret key\n * @rtype (secret: Uint8Array) => KeyPair\n * @param {Uint8Array} secret - secret key\n * @return {Object} - Object with Private(privateKey) and Public(publicKey) keys\n */\nexport function generateKeyPairFromSecret (secret) {\n return nacl.sign.keyPair.fromSecretKey(secret)\n}\n\n/**\n * Generate a random ED25519 keypair\n * @rtype (raw: Boolean) => {publicKey: String | Buffer, secretKey: String | Buffer}\n * @param {Boolean} raw - Whether to return raw (binary) keys\n * @return {Object} Key pair\n */\nexport function generateKeyPair (raw = false) {\n // <node>/apps/aens/test/aens_test_utils.erl\n const keyPair = nacl.sign.keyPair()\n\n const publicBuffer = Buffer.from(keyPair.publicKey)\n const secretBuffer = Buffer.from(keyPair.secretKey)\n\n if (raw) {\n return {\n publicKey: publicBuffer,\n secretKey: secretBuffer\n }\n } else {\n return {\n publicKey: encode(publicBuffer, 'ak'),\n secretKey: secretBuffer.toString('hex')\n }\n }\n}\n\n/**\n * Encrypt given data using `password`\n * @rtype (password: String, binaryData: Buffer) => Uint8Array\n * @param {String} password - Password to encrypt with\n * @param {Buffer} binaryData - Data to encrypt\n * @return {Uint8Array} Encrypted data\n */\nexport function encryptKey (password, binaryData) {\n const hashedPasswordBytes = sha256hash(password)\n const aesEcb = new Ecb(hashedPasswordBytes)\n return aesEcb.encrypt(binaryData)\n}\n\n/**\n * Decrypt given data using `password`\n * @rtype (password: String, encrypted: String) => Uint8Array\n * @param {String} password - Password to decrypt with\n * @param {String} encrypted - Data to decrypt\n * @return {Buffer} Decrypted data\n */\nexport function decryptKey (password, encrypted) {\n const encryptedBytes = Buffer.from(encrypted)\n const hashedPasswordBytes = sha256hash(password)\n const aesEcb = new Ecb(hashedPasswordBytes)\n return Buffer.from(aesEcb.decrypt(encryptedBytes))\n}\n\n// SIGNATURES\n\n/**\n * Generate signature\n * @rtype (data: String|Buffer, privateKey: Buffer) => Buffer\n * @param {String|Buffer} data - Data to sign\n * @param {String|Buffer} privateKey - Key to sign with\n * @return {Buffer|Uint8Array} Signature\n */\nexport function sign (data, privateKey) {\n return nacl.sign.detached(Buffer.from(data), Buffer.from(privateKey))\n}\n\n/**\n * Verify that signature was signed by public key\n * @rtype (str: String, signature: Buffer, publicKey: Buffer) => Boolean\n * @param {String|Buffer} str - Data to verify\n * @param {Buffer} signature - Signature to verify\n * @param {Buffer} publicKey - Key to verify against\n * @return {Boolean} Valid?\n */\nexport function verify (str, signature, publicKey) {\n return nacl.sign.detached.verify(new Uint8Array(str), signature, publicKey)\n}\n\nexport function messageToHash (message) {\n const p = Buffer.from('aeternity Signed Message:\\n', 'utf8')\n const msg = Buffer.from(message, 'utf8')\n if (msg.length >= 0xFD) throw new NotImplementedError('Message too long')\n return hash(Buffer.concat([Buffer.from([p.length]), p, Buffer.from([msg.length]), msg]))\n}\n\nexport function signMessage (message, privateKey) {\n return sign(messageToHash(message), privateKey)\n}\n\nexport function verifyMessage (str, signature, publicKey) {\n return verify(messageToHash(str), signature, publicKey)\n}\n\n/**\n * Check key pair for validity\n *\n * Sign a message, and then verifying that signature\n * @rtype (privateKey: Buffer, publicKey: Buffer) => Boolean\n * @param {Buffer} privateKey - Private key to verify\n * @param {Buffer} publicKey - Public key to verify\n * @return {Boolean} Valid?\n */\nexport function isValidKeypair (privateKey, publicKey) {\n const message = Buffer.from('TheMessage')\n const signature = sign(message, privateKey)\n return verify(message, signature, publicKey)\n}\n"],"file":"crypto.mjs"}
|
|
1
|
+
{"version":3,"file":"crypto.mjs","names":["nacl","str2buf","concatBuffers","decode","encode","Encoding","getAddressFromPriv","secret","secretBuffer","keys","sign","keyPair","fromSecretKey","publicKey","AccountAddress","isAddressValid","address","prefix","e","genSalt","Math","floor","random","Number","MAX_SAFE_INTEGER","encodeUnsigned","value","binary","allocUnsafe","writeUInt32BE","slice","findIndex","i","hash","input","from","blake2b","undefined","encodeContractAddress","owner","nonce","ContractAddress","generateKeyPairFromSecret","generateKeyPair","raw","publicBuffer","secretKey","toString","data","privateKey","detached","verify","signature","publicKeyBuffer","messageToHash","message","p","msg","varuintEncode","length","signMessage","verifyMessage","str","isValidKeypair"],"sources":["../../src/utils/crypto.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright 2018 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 */\nimport nacl, { SignKeyPair } from 'tweetnacl';\n// js extension is required for mjs build, not importing the whole package to reduce bundle size\n// eslint-disable-next-line import/extensions\nimport { blake2b } from 'blakejs/blake2b.js';\nimport { encode as varuintEncode } from 'varuint-bitcoin';\n\nimport { str2buf } from './bytes';\nimport { concatBuffers } from './other';\nimport {\n decode, encode, Encoded, Encoding,\n} from './encoder';\n\n/**\n * Generate address from secret key\n * @param secret - Private key\n * @returns Public key encoded as address\n */\nexport function getAddressFromPriv(secret: string | Uint8Array): Encoded.AccountAddress {\n const secretBuffer = typeof secret === 'string' ? str2buf(secret) : secret;\n const keys = nacl.sign.keyPair.fromSecretKey(secretBuffer);\n return encode(keys.publicKey, Encoding.AccountAddress);\n}\n\n/**\n * Check if address is valid\n * @param address - Address\n * @param prefix - Transaction prefix. Default: 'ak'\n * @returns is valid\n */\nexport function isAddressValid(\n address: string,\n prefix: Encoding = Encoding.AccountAddress,\n): boolean {\n try {\n decode(address as Encoded.Generic<typeof prefix>);\n return true;\n } catch (e) {\n return false;\n }\n}\n\n/**\n * Generate a random salt (positive integer)\n * @returns random salt\n */\nexport function genSalt(): number {\n return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER));\n}\n\n/**\n * Converts a positive integer to the smallest possible\n * representation in a binary digit representation\n * @param value - Value to encode\n * @returns Encoded number\n */\nexport function encodeUnsigned(value: number): Buffer {\n const binary = Buffer.allocUnsafe(4);\n binary.writeUInt32BE(value);\n return binary.slice(binary.findIndex((i) => i !== 0));\n}\n\n/**\n * Calculate 256bits Blake2b hash of `input`\n * @param input - Data to hash\n * @returns Hash\n */\nexport function hash(input: string | Uint8Array): Buffer {\n return Buffer.from(blake2b(input, undefined, 32)); // 256 bits\n}\n\n// Todo Duplicated in tx builder. remove\n/**\n * Compute contract address\n * @category contract\n * @param owner - Address of contract owner\n * @param nonce - Round when contract was created\n * @returns Contract address\n */\nexport function encodeContractAddress(\n owner: Encoded.AccountAddress,\n nonce: number,\n): Encoded.ContractAddress {\n const publicKey = decode(owner);\n const binary = concatBuffers([publicKey, encodeUnsigned(nonce)]);\n return encode(hash(binary), Encoding.ContractAddress);\n}\n\n// KEY-PAIR HELPERS\n\n/**\n * Generate keyPair from secret key\n * @param secret - secret key\n * @returns Object with Private(privateKey) and Public(publicKey) keys\n */\nexport function generateKeyPairFromSecret(secret: Uint8Array): SignKeyPair {\n return nacl.sign.keyPair.fromSecretKey(secret);\n}\n\n/**\n * Generate a random ED25519 keypair\n * @param raw - Whether to return raw (binary) keys\n * @returns Key pair\n */\nexport function generateKeyPair(raw: true): { publicKey: Buffer; secretKey: Buffer };\nexport function generateKeyPair(raw?: false): {\n publicKey: Encoded.AccountAddress; secretKey: string;\n};\nexport function generateKeyPair(raw = false): {\n publicKey: Encoded.AccountAddress | Buffer;\n secretKey: string | Buffer;\n} {\n const keyPair = nacl.sign.keyPair();\n const publicBuffer = Buffer.from(keyPair.publicKey);\n const secretBuffer = Buffer.from(keyPair.secretKey);\n\n if (raw) {\n return {\n publicKey: publicBuffer,\n secretKey: secretBuffer,\n };\n }\n return {\n publicKey: encode(publicBuffer, Encoding.AccountAddress),\n secretKey: secretBuffer.toString('hex'),\n };\n}\n\n// SIGNATURES\n\n/**\n * Generate signature\n * @param data - Data to sign\n * @param privateKey - Key to sign with\n * @returns Signature\n */\nexport function sign(data: string | Uint8Array, privateKey: string | Uint8Array): Uint8Array {\n return nacl.sign.detached(Buffer.from(data), Buffer.from(privateKey));\n}\n\n/**\n * Verify that signature was signed by public key\n * @param data - Data to verify\n * @param signature - Signature to verify\n * @param publicKey - Key to verify against\n * @returns Valid?\n */\nexport function verify(\n data: Uint8Array,\n signature: Uint8Array,\n publicKey: string | Uint8Array,\n): boolean {\n const publicKeyBuffer = typeof publicKey === 'string' ? str2buf(publicKey) : publicKey;\n return nacl.sign.detached.verify(data, signature, publicKeyBuffer);\n}\n\nexport function messageToHash(message: string): Buffer {\n const p = Buffer.from('aeternity Signed Message:\\n', 'utf8');\n const msg = Buffer.from(message, 'utf8');\n return hash(concatBuffers([varuintEncode(p.length), p, varuintEncode(msg.length), msg]));\n}\n\nexport function signMessage(message: string, privateKey: string | Buffer): Uint8Array {\n return sign(messageToHash(message), privateKey);\n}\n\nexport function verifyMessage(\n str: string,\n signature: Uint8Array,\n publicKey: string | Uint8Array,\n): boolean {\n return verify(messageToHash(str), signature, publicKey);\n}\n\n/**\n * Check key pair for validity\n *\n * Sign a message, and then verifying that signature\n * @param privateKey - Private key to verify\n * @param publicKey - Public key to verify\n * @returns Valid?\n */\nexport function isValidKeypair(\n privateKey: string | Uint8Array,\n publicKey: string | Uint8Array,\n): boolean {\n const message = Buffer.from('TheMessage');\n const signature = sign(message, privateKey);\n return verify(message, signature, publicKey);\n}\n"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,IAAP,MAAkC,WAAlC,C,CACA;AACA;;AACA,8BAAwB,oBAAxB;;;;AACA,4BAAwC,iBAAxC;;;;SAESC,O;SACA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GAAG,QAAOpB,IAAP,CAAY,YAAZ,CAAhB;;EACA,MAAMiB,SAAS,GAAG1C,IAAI,CAAC6C,OAAD,EAAUN,UAAV,CAAtB;EACA,OAAOE,MAAM,CAACI,OAAD,EAAUH,SAAV,EAAqBvC,SAArB,CAAb;AACD"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category transaction builder
|
|
3
|
+
* @see {@link https://github.com/aeternity/protocol/blob/master/node/api/api_encoding.md}
|
|
4
|
+
* @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L205-L230}
|
|
5
|
+
*/
|
|
6
|
+
export declare enum Encoding {
|
|
7
|
+
KeyBlockHash = "kh",
|
|
8
|
+
MicroBlockHash = "mh",
|
|
9
|
+
BlockPofHash = "bf",
|
|
10
|
+
BlockTxHash = "bx",
|
|
11
|
+
BlockStateHash = "bs",
|
|
12
|
+
Channel = "ch",
|
|
13
|
+
ContractAddress = "ct",
|
|
14
|
+
ContractBytearray = "cb",
|
|
15
|
+
ContractStoreKey = "ck",
|
|
16
|
+
ContractStoreValue = "cv",
|
|
17
|
+
Transaction = "tx",
|
|
18
|
+
TxHash = "th",
|
|
19
|
+
OracleAddress = "ok",
|
|
20
|
+
OracleQuery = "ov",
|
|
21
|
+
OracleQueryId = "oq",
|
|
22
|
+
OracleResponse = "or",
|
|
23
|
+
AccountAddress = "ak",
|
|
24
|
+
Signature = "sg",
|
|
25
|
+
Commitment = "cm",
|
|
26
|
+
PeerPubkey = "pp",
|
|
27
|
+
Name = "nm",
|
|
28
|
+
State = "st",
|
|
29
|
+
Poi = "pi",
|
|
30
|
+
StateTrees = "ss",
|
|
31
|
+
CallStateTree = "cs",
|
|
32
|
+
Bytearray = "ba"
|
|
33
|
+
}
|
|
34
|
+
export declare type KeyBlockHash = `${Encoding.KeyBlockHash}_${string}`;
|
|
35
|
+
export declare type MicroBlockHash = `${Encoding.MicroBlockHash}_${string}`;
|
|
36
|
+
export declare type BlockPofHash = `${Encoding.BlockPofHash}_${string}`;
|
|
37
|
+
export declare type BlockTxHash = `${Encoding.BlockTxHash}_${string}`;
|
|
38
|
+
export declare type BlockStateHash = `${Encoding.BlockStateHash}_${string}`;
|
|
39
|
+
export declare type Channel = `${Encoding.Channel}_${string}`;
|
|
40
|
+
export declare type ContractAddress = `${Encoding.ContractAddress}_${string}`;
|
|
41
|
+
export declare type ContractBytearray = `${Encoding.ContractBytearray}_${string}`;
|
|
42
|
+
export declare type ContractStoreKey = `${Encoding.ContractStoreKey}_${string}`;
|
|
43
|
+
export declare type ContractStoreValue = `${Encoding.ContractStoreValue}_${string}`;
|
|
44
|
+
export declare type Transaction = `${Encoding.Transaction}_${string}`;
|
|
45
|
+
export declare type TxHash = `${Encoding.TxHash}_${string}`;
|
|
46
|
+
export declare type OracleAddress = `${Encoding.OracleAddress}_${string}`;
|
|
47
|
+
export declare type OracleQuery = `${Encoding.OracleQuery}_${string}`;
|
|
48
|
+
export declare type OracleQueryId = `${Encoding.OracleQueryId}_${string}`;
|
|
49
|
+
export declare type OracleResponse = `${Encoding.OracleResponse}_${string}`;
|
|
50
|
+
export declare type AccountAddress = `${Encoding.AccountAddress}_${string}`;
|
|
51
|
+
export declare type Signature = `${Encoding.Signature}_${string}`;
|
|
52
|
+
export declare type Commitment = `${Encoding.Commitment}_${string}`;
|
|
53
|
+
export declare type PeerPubkey = `${Encoding.PeerPubkey}_${string}`;
|
|
54
|
+
export declare type Name = `${Encoding.Name}_${string}`;
|
|
55
|
+
export declare type State = `${Encoding.State}_${string}`;
|
|
56
|
+
export declare type Poi = `${Encoding.Poi}_${string}`;
|
|
57
|
+
export declare type StateTrees = `${Encoding.StateTrees}_${string}`;
|
|
58
|
+
export declare type CallStateTree = `${Encoding.CallStateTree}_${string}`;
|
|
59
|
+
export declare type Bytearray = `${Encoding.Bytearray}_${string}`;
|
|
60
|
+
export declare type Generic<Type extends Encoding> = `${Type}_${string}`;
|
|
61
|
+
export declare type Any = `${Encoding}_${string}`;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category transaction builder
|
|
3
|
+
* @see {@link https://github.com/aeternity/protocol/blob/master/node/api/api_encoding.md}
|
|
4
|
+
* @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L205-L230}
|
|
5
|
+
*/
|
|
6
|
+
export let Encoding;
|
|
7
|
+
|
|
8
|
+
(function (Encoding) {
|
|
9
|
+
Encoding["KeyBlockHash"] = "kh";
|
|
10
|
+
Encoding["MicroBlockHash"] = "mh";
|
|
11
|
+
Encoding["BlockPofHash"] = "bf";
|
|
12
|
+
Encoding["BlockTxHash"] = "bx";
|
|
13
|
+
Encoding["BlockStateHash"] = "bs";
|
|
14
|
+
Encoding["Channel"] = "ch";
|
|
15
|
+
Encoding["ContractAddress"] = "ct";
|
|
16
|
+
Encoding["ContractBytearray"] = "cb";
|
|
17
|
+
Encoding["ContractStoreKey"] = "ck";
|
|
18
|
+
Encoding["ContractStoreValue"] = "cv";
|
|
19
|
+
Encoding["Transaction"] = "tx";
|
|
20
|
+
Encoding["TxHash"] = "th";
|
|
21
|
+
Encoding["OracleAddress"] = "ok";
|
|
22
|
+
Encoding["OracleQuery"] = "ov";
|
|
23
|
+
Encoding["OracleQueryId"] = "oq";
|
|
24
|
+
Encoding["OracleResponse"] = "or";
|
|
25
|
+
Encoding["AccountAddress"] = "ak";
|
|
26
|
+
Encoding["Signature"] = "sg";
|
|
27
|
+
Encoding["Commitment"] = "cm";
|
|
28
|
+
Encoding["PeerPubkey"] = "pp";
|
|
29
|
+
Encoding["Name"] = "nm";
|
|
30
|
+
Encoding["State"] = "st";
|
|
31
|
+
Encoding["Poi"] = "pi";
|
|
32
|
+
Encoding["StateTrees"] = "ss";
|
|
33
|
+
Encoding["CallStateTree"] = "cs";
|
|
34
|
+
Encoding["Bytearray"] = "ba";
|
|
35
|
+
})(Encoding || (Encoding = {}));
|
|
36
|
+
//# sourceMappingURL=encoder-types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoder-types.mjs","names":["Encoding"],"sources":["../../src/utils/encoder-types.ts"],"sourcesContent":["/**\n * @category transaction builder\n * @see {@link https://github.com/aeternity/protocol/blob/master/node/api/api_encoding.md}\n * @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L205-L230}\n */\nexport enum Encoding {\n KeyBlockHash = 'kh',\n MicroBlockHash = 'mh',\n BlockPofHash = 'bf',\n BlockTxHash = 'bx',\n BlockStateHash = 'bs',\n Channel = 'ch',\n ContractAddress = 'ct',\n ContractBytearray = 'cb',\n ContractStoreKey = 'ck',\n ContractStoreValue = 'cv',\n Transaction = 'tx',\n TxHash = 'th',\n OracleAddress = 'ok',\n OracleQuery = 'ov',\n OracleQueryId = 'oq',\n OracleResponse = 'or',\n AccountAddress = 'ak',\n Signature = 'sg',\n Commitment = 'cm',\n PeerPubkey = 'pp',\n Name = 'nm',\n State = 'st',\n Poi = 'pi',\n StateTrees = 'ss',\n CallStateTree = 'cs',\n Bytearray = 'ba',\n}\n\nexport type KeyBlockHash = `${Encoding.KeyBlockHash}_${string}`;\nexport type MicroBlockHash = `${Encoding.MicroBlockHash}_${string}`;\nexport type BlockPofHash = `${Encoding.BlockPofHash}_${string}`;\nexport type BlockTxHash = `${Encoding.BlockTxHash}_${string}`;\nexport type BlockStateHash = `${Encoding.BlockStateHash}_${string}`;\nexport type Channel = `${Encoding.Channel}_${string}`;\nexport type ContractAddress = `${Encoding.ContractAddress}_${string}`;\nexport type ContractBytearray = `${Encoding.ContractBytearray}_${string}`;\nexport type ContractStoreKey = `${Encoding.ContractStoreKey}_${string}`;\nexport type ContractStoreValue = `${Encoding.ContractStoreValue}_${string}`;\nexport type Transaction = `${Encoding.Transaction}_${string}`;\nexport type TxHash = `${Encoding.TxHash}_${string}`;\nexport type OracleAddress = `${Encoding.OracleAddress}_${string}`;\nexport type OracleQuery = `${Encoding.OracleQuery}_${string}`;\nexport type OracleQueryId = `${Encoding.OracleQueryId}_${string}`;\nexport type OracleResponse = `${Encoding.OracleResponse}_${string}`;\nexport type AccountAddress = `${Encoding.AccountAddress}_${string}`;\nexport type Signature = `${Encoding.Signature}_${string}`;\nexport type Commitment = `${Encoding.Commitment}_${string}`;\nexport type PeerPubkey = `${Encoding.PeerPubkey}_${string}`;\nexport type Name = `${Encoding.Name}_${string}`;\nexport type State = `${Encoding.State}_${string}`;\nexport type Poi = `${Encoding.Poi}_${string}`;\nexport type StateTrees = `${Encoding.StateTrees}_${string}`;\nexport type CallStateTree = `${Encoding.CallStateTree}_${string}`;\nexport type Bytearray = `${Encoding.Bytearray}_${string}`;\n\nexport type Generic<Type extends Encoding> = `${Type}_${string}`;\nexport type Any = `${Encoding}_${string}`;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,WAAYA,QAAZ;;WAAYA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;GAAAA,Q,KAAAA,Q"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as Encoded from './encoder-types';
|
|
3
|
+
import { Encoding } from './encoder-types';
|
|
4
|
+
export { Encoded, Encoding };
|
|
5
|
+
/**
|
|
6
|
+
* Calculate SHA256 hash of `input`
|
|
7
|
+
* @param input - Data to hash
|
|
8
|
+
* @returns Hash
|
|
9
|
+
* @deprecated use `SubtleCrypto.digest` or `sha.js` package instead
|
|
10
|
+
*/
|
|
11
|
+
export declare function sha256hash(input: Uint8Array | string): Buffer;
|
|
12
|
+
/**
|
|
13
|
+
* Decode data using the default encoding/decoding algorithm
|
|
14
|
+
* @param data - An Base58/64check encoded and prefixed string
|
|
15
|
+
* (ex tx_..., sg_..., ak_....)
|
|
16
|
+
* @returns Decoded data
|
|
17
|
+
*/
|
|
18
|
+
export declare function decode(data: Encoded.Any): Buffer;
|
|
19
|
+
/**
|
|
20
|
+
* Encode data using the default encoding/decoding algorithm
|
|
21
|
+
* @param data - An decoded data
|
|
22
|
+
* @param type - Prefix of Transaction
|
|
23
|
+
* @returns Encoded string Base58check or Base64check data
|
|
24
|
+
*/
|
|
25
|
+
export declare function encode<Type extends Encoding>(data: Uint8Array, type: Type): Encoded.Generic<Type>;
|
package/es/utils/encoder.mjs
CHANGED
|
@@ -2,45 +2,67 @@ import _buffer from "buffer";
|
|
|
2
2
|
const {
|
|
3
3
|
Buffer: _Buffer
|
|
4
4
|
} = _buffer;
|
|
5
|
-
import
|
|
6
|
-
|
|
5
|
+
import _bs from 'bs58'; // js extension is required for mjs build, not importing the whole package to reduce bundle size
|
|
6
|
+
// eslint-disable-next-line import/extensions
|
|
7
|
+
|
|
7
8
|
const {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
encode: bs58Encode,
|
|
10
|
+
decode: bs58Decode
|
|
11
|
+
} = _bs;
|
|
12
|
+
import Sha256 from 'sha.js/sha256.js';
|
|
13
|
+
import { DecodeError, ArgumentError, InvalidChecksumError, PayloadLengthError } from "./errors.mjs";
|
|
14
|
+
import { concatBuffers, isKeyOfObject } from "./other.mjs";
|
|
15
|
+
import * as Encoded from "./encoder-types.mjs";
|
|
16
|
+
import { Encoding } from "./encoder-types.mjs";
|
|
17
|
+
export { Encoded, Encoding };
|
|
11
18
|
/**
|
|
12
19
|
* Calculate SHA256 hash of `input`
|
|
13
|
-
* @
|
|
14
|
-
* @
|
|
15
|
-
* @
|
|
20
|
+
* @param input - Data to hash
|
|
21
|
+
* @returns Hash
|
|
22
|
+
* @deprecated use `SubtleCrypto.digest` or `sha.js` package instead
|
|
16
23
|
*/
|
|
17
24
|
|
|
18
25
|
export function sha256hash(input) {
|
|
19
|
-
return new
|
|
20
|
-
}
|
|
26
|
+
return new Sha256().update(input).digest();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L177-L202}
|
|
30
|
+
*/
|
|
21
31
|
|
|
22
|
-
const base64Types = [
|
|
23
|
-
const base58Types = [
|
|
32
|
+
const base64Types = [Encoding.ContractBytearray, Encoding.ContractStoreKey, Encoding.ContractStoreValue, Encoding.Transaction, Encoding.OracleQuery, Encoding.OracleResponse, Encoding.State, Encoding.Poi, Encoding.StateTrees, Encoding.CallStateTree, Encoding.Bytearray];
|
|
33
|
+
const base58Types = [Encoding.KeyBlockHash, Encoding.MicroBlockHash, Encoding.BlockPofHash, Encoding.BlockTxHash, Encoding.BlockStateHash, Encoding.Channel, Encoding.ContractAddress, Encoding.TxHash, Encoding.OracleAddress, Encoding.OracleQueryId, Encoding.AccountAddress, Encoding.Signature, Encoding.Commitment, Encoding.PeerPubkey, Encoding.Name];
|
|
34
|
+
/**
|
|
35
|
+
* @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L261-L286}
|
|
36
|
+
*/
|
|
24
37
|
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
38
|
+
const byteSizeForType = {
|
|
39
|
+
[Encoding.KeyBlockHash]: 32,
|
|
40
|
+
[Encoding.MicroBlockHash]: 32,
|
|
41
|
+
[Encoding.BlockPofHash]: 32,
|
|
42
|
+
[Encoding.BlockTxHash]: 32,
|
|
43
|
+
[Encoding.BlockStateHash]: 32,
|
|
44
|
+
[Encoding.Channel]: 32,
|
|
45
|
+
[Encoding.ContractAddress]: 32,
|
|
46
|
+
[Encoding.TxHash]: 32,
|
|
47
|
+
[Encoding.OracleAddress]: 32,
|
|
48
|
+
[Encoding.OracleQueryId]: 32,
|
|
49
|
+
[Encoding.AccountAddress]: 32,
|
|
50
|
+
[Encoding.Signature]: 64,
|
|
51
|
+
[Encoding.Commitment]: 32,
|
|
52
|
+
[Encoding.PeerPubkey]: 32,
|
|
53
|
+
[Encoding.State]: 32
|
|
29
54
|
};
|
|
30
55
|
|
|
31
56
|
function ensureValidLength(data, type) {
|
|
32
|
-
if (!
|
|
33
|
-
|
|
34
|
-
|
|
57
|
+
if (!isKeyOfObject(type, byteSizeForType)) return;
|
|
58
|
+
const reqLen = byteSizeForType[type];
|
|
59
|
+
if (reqLen == null || data.length === reqLen) return;
|
|
60
|
+
throw new PayloadLengthError(`Payload should be ${reqLen} bytes, got ${data.length} instead`);
|
|
35
61
|
}
|
|
36
62
|
|
|
37
63
|
const getChecksum = payload => sha256hash(sha256hash(payload)).slice(0, 4);
|
|
38
64
|
|
|
39
|
-
const addChecksum =
|
|
40
|
-
const payload = _Buffer.from(input);
|
|
41
|
-
|
|
42
|
-
return _Buffer.concat([payload, getChecksum(payload)]);
|
|
43
|
-
};
|
|
65
|
+
const addChecksum = payload => concatBuffers([payload, getChecksum(payload)]);
|
|
44
66
|
|
|
45
67
|
function getPayload(buffer) {
|
|
46
68
|
const payload = buffer.slice(0, -4);
|
|
@@ -53,54 +75,44 @@ const base64 = {
|
|
|
53
75
|
decode: string => getPayload(_Buffer.from(string, 'base64'))
|
|
54
76
|
};
|
|
55
77
|
const base58 = {
|
|
56
|
-
encode: buffer =>
|
|
57
|
-
decode: string => getPayload(
|
|
78
|
+
encode: buffer => bs58Encode(addChecksum(buffer)),
|
|
79
|
+
decode: string => getPayload(_Buffer.from(bs58Decode(string)))
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const parseType = maybeType => {
|
|
83
|
+
const base64Type = base64Types.find(t => t === maybeType);
|
|
84
|
+
if (base64Type != null) return [base64Type, base64];
|
|
85
|
+
const base58Type = base58Types.find(t => t === maybeType);
|
|
86
|
+
if (base58Type != null) return [base58Type, base58];
|
|
87
|
+
throw new ArgumentError('prefix', `one of ${[...base58Types, ...base64Types].join(', ')}`, maybeType);
|
|
58
88
|
};
|
|
59
89
|
/**
|
|
60
90
|
* Decode data using the default encoding/decoding algorithm
|
|
61
|
-
* @
|
|
62
|
-
*
|
|
63
|
-
* @
|
|
64
|
-
* @param {string} [requiredPrefix] Ensure that data have this prefix
|
|
65
|
-
* @return {Buffer} Decoded data
|
|
91
|
+
* @param data - An Base58/64check encoded and prefixed string
|
|
92
|
+
* (ex tx_..., sg_..., ak_....)
|
|
93
|
+
* @returns Decoded data
|
|
66
94
|
*/
|
|
67
95
|
|
|
68
|
-
export function decode(data, requiredPrefix) {
|
|
69
|
-
const [prefix, encodedPayload, extra] = data.split('_');
|
|
70
|
-
if (!encodedPayload) throw new DecodeError(`Encoded string missing payload: ${data}`);
|
|
71
|
-
if (extra) throw new DecodeError(`Encoded string have extra parts: ${data}`);
|
|
72
|
-
|
|
73
|
-
if (requiredPrefix && requiredPrefix !== prefix) {
|
|
74
|
-
throw new PrefixMismatchError(prefix, requiredPrefix);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const decoder = base64Types.includes(prefix) && base64.decode || base58Types.includes(prefix) && base58.decode;
|
|
78
96
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
97
|
+
export function decode(data) {
|
|
98
|
+
const [prefix, encodedPayload, extra] = data.split('_');
|
|
99
|
+
if (encodedPayload == null) throw new DecodeError(`Encoded string missing payload: ${data}`);
|
|
100
|
+
if (extra != null) throw new DecodeError(`Encoded string have extra parts: ${data}`);
|
|
101
|
+
const [type, encoder] = parseType(prefix);
|
|
102
|
+
const payload = encoder.decode(encodedPayload);
|
|
103
|
+
ensureValidLength(payload, type);
|
|
85
104
|
return payload;
|
|
86
105
|
}
|
|
87
106
|
/**
|
|
88
107
|
* Encode data using the default encoding/decoding algorithm
|
|
89
|
-
* @
|
|
90
|
-
* @
|
|
91
|
-
* @
|
|
92
|
-
* @param {string} type Prefix of Transaction
|
|
93
|
-
* @return {String} Encoded string Base58check or Base64check data
|
|
108
|
+
* @param data - An decoded data
|
|
109
|
+
* @param type - Prefix of Transaction
|
|
110
|
+
* @returns Encoded string Base58check or Base64check data
|
|
94
111
|
*/
|
|
95
112
|
|
|
96
113
|
export function encode(data, type) {
|
|
97
|
-
const encoder =
|
|
98
|
-
|
|
99
|
-
if (!encoder) {
|
|
100
|
-
throw new EncodeError(`Unknown type: ${type}`);
|
|
101
|
-
}
|
|
102
|
-
|
|
114
|
+
const [, encoder] = parseType(type);
|
|
103
115
|
ensureValidLength(data, type);
|
|
104
|
-
return `${type}_${encoder(data)}`;
|
|
116
|
+
return `${type}_${encoder.encode(data)}`;
|
|
105
117
|
}
|
|
106
118
|
//# sourceMappingURL=encoder.mjs.map
|