@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
|
@@ -14,114 +14,101 @@
|
|
|
14
14
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
|
+
import BigNumber from 'bignumber.js';
|
|
18
|
+
import { isBigNumber } from './bignumber';
|
|
19
|
+
import { ArgumentError } from './errors';
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* AE amount formats
|
|
29
|
-
*/
|
|
30
|
-
export const AE_AMOUNT_FORMATS = {
|
|
31
|
-
AE: 'ae',
|
|
32
|
-
MILI_AE: 'miliAE',
|
|
33
|
-
MICRO_AE: 'microAE',
|
|
34
|
-
NANO_AE: 'nanoAE',
|
|
35
|
-
PICO_AE: 'picoAE',
|
|
36
|
-
FEMTO_AE: 'femtoAE',
|
|
37
|
-
AETTOS: 'aettos'
|
|
21
|
+
export enum AE_AMOUNT_FORMATS {
|
|
22
|
+
AE = 'ae',
|
|
23
|
+
MILI_AE = 'miliAE',
|
|
24
|
+
MICRO_AE = 'microAE',
|
|
25
|
+
NANO_AE = 'nanoAE',
|
|
26
|
+
PICO_AE = 'picoAE',
|
|
27
|
+
FEMTO_AE = 'femtoAE',
|
|
28
|
+
AETTOS = 'aettos',
|
|
38
29
|
}
|
|
39
30
|
|
|
40
31
|
/**
|
|
41
32
|
* DENOMINATION_MAGNITUDE
|
|
42
33
|
*/
|
|
43
|
-
|
|
34
|
+
const DENOMINATION_MAGNITUDE = {
|
|
44
35
|
[AE_AMOUNT_FORMATS.AE]: 0,
|
|
45
36
|
[AE_AMOUNT_FORMATS.MILI_AE]: -3,
|
|
46
37
|
[AE_AMOUNT_FORMATS.MICRO_AE]: -6,
|
|
47
38
|
[AE_AMOUNT_FORMATS.NANO_AE]: -9,
|
|
48
39
|
[AE_AMOUNT_FORMATS.PICO_AE]: -12,
|
|
49
40
|
[AE_AMOUNT_FORMATS.FEMTO_AE]: -15,
|
|
50
|
-
[AE_AMOUNT_FORMATS.AETTOS]: -18
|
|
51
|
-
}
|
|
41
|
+
[AE_AMOUNT_FORMATS.AETTOS]: -18,
|
|
42
|
+
} as const;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Convert amount from one to other denomination
|
|
46
|
+
* @param value - amount to convert
|
|
47
|
+
* @param options - options
|
|
48
|
+
* @param options.denomination - denomination of amount, can be ['ae', 'aettos']
|
|
49
|
+
* @param options.targetDenomination - target denomination,
|
|
50
|
+
* can be ['ae', 'aettos']
|
|
51
|
+
*/
|
|
52
|
+
export const formatAmount = (
|
|
53
|
+
value: string | number | bigint | BigNumber,
|
|
54
|
+
{ denomination = AE_AMOUNT_FORMATS.AETTOS, targetDenomination = AE_AMOUNT_FORMATS.AETTOS }:
|
|
55
|
+
{ denomination?: AE_AMOUNT_FORMATS; targetDenomination?: AE_AMOUNT_FORMATS },
|
|
56
|
+
): string => {
|
|
57
|
+
if (!isBigNumber(value)) throw new ArgumentError('value', 'a number', value);
|
|
58
|
+
|
|
59
|
+
return new BigNumber(typeof value === 'bigint' ? value.toString() : value)
|
|
60
|
+
.shiftedBy(DENOMINATION_MAGNITUDE[denomination] - DENOMINATION_MAGNITUDE[targetDenomination])
|
|
61
|
+
.toFixed();
|
|
62
|
+
};
|
|
52
63
|
|
|
53
64
|
/**
|
|
54
65
|
* Convert amount to AE
|
|
55
|
-
* @param
|
|
56
|
-
* @param
|
|
57
|
-
* @param
|
|
58
|
-
* @return {String}
|
|
66
|
+
* @param value - amount to convert
|
|
67
|
+
* @param options - options
|
|
68
|
+
* @param options.denomination - denomination of amount, can be ['ae', 'aettos']
|
|
59
69
|
*/
|
|
60
70
|
export const toAe = (
|
|
61
71
|
value: string | number | BigNumber,
|
|
62
|
-
{ denomination = AE_AMOUNT_FORMATS.AETTOS } = {}
|
|
63
|
-
): string => formatAmount(value, { denomination, targetDenomination: AE_AMOUNT_FORMATS.AE })
|
|
72
|
+
{ denomination = AE_AMOUNT_FORMATS.AETTOS }: { denomination?: AE_AMOUNT_FORMATS } = {},
|
|
73
|
+
): string => formatAmount(value, { denomination, targetDenomination: AE_AMOUNT_FORMATS.AE });
|
|
64
74
|
|
|
65
75
|
/**
|
|
66
76
|
* Convert amount to aettos
|
|
67
|
-
* @param
|
|
68
|
-
* @param
|
|
69
|
-
* @param
|
|
70
|
-
* @return {String}
|
|
77
|
+
* @param value - amount to convert
|
|
78
|
+
* @param options - options
|
|
79
|
+
* @param options.denomination - denomination of amount, can be ['ae', 'aettos']
|
|
71
80
|
*/
|
|
72
81
|
export const toAettos = (
|
|
73
82
|
value: string | number | BigNumber,
|
|
74
|
-
{ denomination = AE_AMOUNT_FORMATS.AE } = {}
|
|
75
|
-
): string => formatAmount(value, { denomination })
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Convert amount from one to other denomination
|
|
79
|
-
* @param {String|Number|BigNumber} value amount to convert
|
|
80
|
-
* @param {Object} [options={}] options
|
|
81
|
-
* @param {String} [options.denomination='aettos'] denomination of amount, can be ['ae', 'aettos']
|
|
82
|
-
* @param {String} [options.targetDenomination='aettos'] target denomination, can be ['ae', 'aettos']
|
|
83
|
-
* @return {String}
|
|
84
|
-
*/
|
|
85
|
-
export const formatAmount = (
|
|
86
|
-
value: string | number | BigNumber,
|
|
87
|
-
{ denomination = AE_AMOUNT_FORMATS.AETTOS, targetDenomination = AE_AMOUNT_FORMATS.AETTOS } = {}
|
|
88
|
-
): string => {
|
|
89
|
-
const denominations = Object.values(AE_AMOUNT_FORMATS)
|
|
90
|
-
if (!denominations.includes(denomination)) throw new InvalidDenominationError(`Invalid denomination: ${denomination}`)
|
|
91
|
-
if (!denominations.includes(targetDenomination)) throw new InvalidDenominationError(`Invalid target denomination: ${targetDenomination}`)
|
|
92
|
-
if (!isBigNumber(value)) throw new ArgumentError('value', `a number`, value)
|
|
93
|
-
|
|
94
|
-
return new BigNumber(value)
|
|
95
|
-
.shiftedBy(DENOMINATION_MAGNITUDE[denomination] - DENOMINATION_MAGNITUDE[targetDenomination])
|
|
96
|
-
.toFixed()
|
|
97
|
-
}
|
|
83
|
+
{ denomination = AE_AMOUNT_FORMATS.AE }: { denomination?: AE_AMOUNT_FORMATS } = {},
|
|
84
|
+
): string => formatAmount(value, { denomination });
|
|
98
85
|
|
|
99
86
|
interface Prefix {
|
|
100
|
-
name: string
|
|
101
|
-
magnitude: number
|
|
87
|
+
name: string;
|
|
88
|
+
magnitude: number;
|
|
102
89
|
}
|
|
103
90
|
|
|
104
91
|
const prefixes: Prefix[] = [
|
|
105
92
|
{ name: 'exa', magnitude: 18 },
|
|
106
93
|
{ name: 'giga', magnitude: 9 },
|
|
107
94
|
{ name: '', magnitude: 0 },
|
|
108
|
-
{ name: 'pico', magnitude: -12 }
|
|
109
|
-
]
|
|
95
|
+
{ name: 'pico', magnitude: -12 },
|
|
96
|
+
];
|
|
110
97
|
|
|
111
98
|
const getNearestPrefix = (exponent: number): Prefix => prefixes.reduce((p, n) => (
|
|
112
|
-
Math.abs(n.magnitude - exponent) < Math.abs(p.magnitude - exponent) ? n : p))
|
|
99
|
+
Math.abs(n.magnitude - exponent) < Math.abs(p.magnitude - exponent) ? n : p));
|
|
113
100
|
|
|
114
101
|
const getLowerBoundPrefix = (exponent: number): Prefix => prefixes
|
|
115
|
-
.find(p => p.magnitude <= exponent) ?? prefixes[prefixes.length - 1]
|
|
102
|
+
.find((p) => p.magnitude <= exponent) ?? prefixes[prefixes.length - 1];
|
|
116
103
|
|
|
117
104
|
export default (rawValue: string | number | BigNumber): string => {
|
|
118
|
-
const value: BigNumber = new BigNumber(rawValue)
|
|
105
|
+
const value: BigNumber = new BigNumber(rawValue);
|
|
119
106
|
|
|
120
|
-
const exp = value.e ?? 0
|
|
121
|
-
const { name, magnitude } = (exp < 0 ? getNearestPrefix : getLowerBoundPrefix)(exp)
|
|
107
|
+
const exp = value.e ?? 0;
|
|
108
|
+
const { name, magnitude } = (exp < 0 ? getNearestPrefix : getLowerBoundPrefix)(exp);
|
|
122
109
|
const v = value
|
|
123
110
|
.shiftedBy(-magnitude)
|
|
124
111
|
.precision(9 + Math.min(exp - magnitude, 0))
|
|
125
|
-
.toFixed()
|
|
126
|
-
return `${v}${name !== '' ? ' ' : ''}${name}
|
|
127
|
-
}
|
|
112
|
+
.toFixed();
|
|
113
|
+
return `${v}${name !== '' ? ' ' : ''}${name}`;
|
|
114
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { RestError, PipelineResponse, PipelinePolicy } from '@azure/core-rest-pipeline';
|
|
2
|
+
import { AdditionalPolicyConfig } from '@azure/core-client';
|
|
3
|
+
import { pause } from './other';
|
|
4
|
+
import semverSatisfies from './semver-satisfies';
|
|
5
|
+
import { UnsupportedVersionError } from './errors';
|
|
6
|
+
|
|
7
|
+
export const genRequestQueuesPolicy = (): AdditionalPolicyConfig => {
|
|
8
|
+
const requestQueues = new Map<string, Promise<unknown>>();
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
policy: {
|
|
12
|
+
name: 'request-queues',
|
|
13
|
+
async sendRequest(request, next) {
|
|
14
|
+
const key = request.headers.get('__queue');
|
|
15
|
+
request.headers.delete('__queue');
|
|
16
|
+
const getResponse = async (): Promise<PipelineResponse> => next(request);
|
|
17
|
+
if (key == null) return getResponse();
|
|
18
|
+
const req = (requestQueues.get(key) ?? Promise.resolve()).then(getResponse, getResponse);
|
|
19
|
+
// TODO: remove after fixing https://github.com/aeternity/aeternity/issues/3803
|
|
20
|
+
// gap to ensure that node won't reject the nonce
|
|
21
|
+
requestQueues.set(key, req.then(async () => pause(750)));
|
|
22
|
+
return req;
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
position: 'perCall',
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const genCombineGetRequestsPolicy = (): AdditionalPolicyConfig => {
|
|
30
|
+
const pendingGetRequests = new Map<string, Promise<PipelineResponse>>();
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
policy: {
|
|
34
|
+
name: 'combine-requests',
|
|
35
|
+
async sendRequest(request, next) {
|
|
36
|
+
if (request.method !== 'GET') return next(request);
|
|
37
|
+
const key = JSON.stringify([request.url, request.body]);
|
|
38
|
+
const response = pendingGetRequests.get(key) ?? next(request);
|
|
39
|
+
pendingGetRequests.set(key, response);
|
|
40
|
+
try {
|
|
41
|
+
return await response;
|
|
42
|
+
} finally {
|
|
43
|
+
pendingGetRequests.delete(key);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
position: 'perCall',
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const genErrorFormatterPolicy = (
|
|
52
|
+
getMessage: (b: any) => string,
|
|
53
|
+
): AdditionalPolicyConfig => ({
|
|
54
|
+
policy: {
|
|
55
|
+
name: 'error-formatter',
|
|
56
|
+
async sendRequest(request, next) {
|
|
57
|
+
try {
|
|
58
|
+
return await next(request);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (!(error instanceof RestError) || error.request == null) throw error;
|
|
61
|
+
if (error.response?.bodyAsText == null) throw error;
|
|
62
|
+
|
|
63
|
+
let body;
|
|
64
|
+
try {
|
|
65
|
+
body = JSON.parse(error.response.bodyAsText);
|
|
66
|
+
} catch (e) {
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
error.message = `${new URL(error.request.url).pathname.slice(1)} error`;
|
|
70
|
+
const message = getMessage(body);
|
|
71
|
+
if (message !== '') error.message += `:${message}`;
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
position: 'perCall',
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
export const genVersionCheckPolicy = (
|
|
80
|
+
name: string,
|
|
81
|
+
ignorePath: string,
|
|
82
|
+
versionPromise: Promise<string>,
|
|
83
|
+
geVersion: string,
|
|
84
|
+
ltVersion: string,
|
|
85
|
+
): PipelinePolicy => ({
|
|
86
|
+
name: 'version-check',
|
|
87
|
+
async sendRequest(request, next) {
|
|
88
|
+
if (new URL(request.url).pathname === ignorePath) return next(request);
|
|
89
|
+
const args = [await versionPromise, geVersion, ltVersion] as const;
|
|
90
|
+
if (!semverSatisfies(...args)) throw new UnsupportedVersionError(name, ...args);
|
|
91
|
+
return next(request);
|
|
92
|
+
},
|
|
93
|
+
});
|
package/src/utils/bignumber.ts
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Big Number Helpers
|
|
3
|
-
* @module @aeternity/aepp-sdk/es/utils/bignumber
|
|
4
|
-
* @example import { isBigNumber, ceil } from '@aeternity/aepp-sdk/es/utils/bignumber'
|
|
5
3
|
*/
|
|
6
|
-
import BigNumber from 'bignumber.js'
|
|
4
|
+
import BigNumber from 'bignumber.js';
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
|
-
* Check if value is BigNumber, Number or number string representation
|
|
10
|
-
* @param
|
|
11
|
-
* @return {Boolean}
|
|
7
|
+
* Check if value is BigNumber, Number, BigInt or number string representation
|
|
8
|
+
* @param number - number to check
|
|
12
9
|
*/
|
|
13
|
-
export const isBigNumber = (number: string | number | BigNumber): boolean =>
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
export const isBigNumber = (number: string | number | bigint | BigNumber): boolean => {
|
|
11
|
+
if (typeof number === 'bigint') return true;
|
|
12
|
+
return ['number', 'object', 'string'].includes(typeof number)
|
|
13
|
+
// eslint-disable-next-line no-restricted-globals
|
|
14
|
+
&& (!isNaN(number as number) || Number.isInteger(number) || BigNumber.isBigNumber(number));
|
|
15
|
+
};
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* BigNumber ceil operation
|
|
19
|
-
* @param {BigNumber} bigNumber
|
|
20
|
-
* @return {BigNumber}
|
|
21
19
|
*/
|
|
22
|
-
export const ceil = (bigNumber: BigNumber): BigNumber => bigNumber
|
|
20
|
+
export const ceil = (bigNumber: BigNumber): BigNumber => bigNumber
|
|
21
|
+
.integerValue(BigNumber.ROUND_CEIL);
|
package/src/utils/bytes.ts
CHANGED
|
@@ -14,61 +14,59 @@
|
|
|
14
14
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
|
-
import BigNumber from 'bignumber.js'
|
|
18
|
-
import { NoSerializerFoundError, TypeError } from './errors'
|
|
19
|
-
import { isBase64, isHex } from './string'
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Bytes module
|
|
23
|
-
* @module @aeternity/aepp-sdk/es/utils/bytes
|
|
24
|
-
* @example import { Crypto } from '@aeternity/aepp-sdk'
|
|
25
|
-
*/
|
|
17
|
+
import BigNumber from 'bignumber.js';
|
|
18
|
+
import { NoSerializerFoundError, TypeError } from './errors';
|
|
19
|
+
import { isBase64, isHex } from './string';
|
|
26
20
|
|
|
27
21
|
/**
|
|
28
22
|
* Convert bignumber to byte array
|
|
29
|
-
* @param
|
|
30
|
-
* @
|
|
23
|
+
* @param x - bignumber instance
|
|
24
|
+
* @returns Buffer
|
|
31
25
|
*/
|
|
32
|
-
export function bigNumberToByteArray
|
|
33
|
-
if (!x.isInteger()) throw new TypeError(`Unexpected not integer value: ${x.toFixed()}`)
|
|
34
|
-
let hexString = x.toString(16)
|
|
35
|
-
if (hexString.length % 2 === 1) hexString =
|
|
36
|
-
return Buffer.from(hexString, 'hex')
|
|
26
|
+
export function bigNumberToByteArray(x: BigNumber): Buffer {
|
|
27
|
+
if (!x.isInteger()) throw new TypeError(`Unexpected not integer value: ${x.toFixed()}`);
|
|
28
|
+
let hexString = x.toString(16);
|
|
29
|
+
if (hexString.length % 2 === 1) hexString = `0${hexString}`;
|
|
30
|
+
return Buffer.from(hexString, 'hex');
|
|
37
31
|
}
|
|
38
32
|
|
|
39
33
|
/**
|
|
40
34
|
* Convert string, number, or BigNumber to byte array
|
|
41
|
-
* @param
|
|
42
|
-
* @param
|
|
43
|
-
* @
|
|
35
|
+
* @param val - value to convert
|
|
36
|
+
* @param big - enables force conversion to BigNumber
|
|
37
|
+
* @returns Buffer
|
|
44
38
|
*/
|
|
45
|
-
export function toBytes
|
|
39
|
+
export function toBytes(val?: null | string | number | BigNumber, big = false): Buffer {
|
|
46
40
|
// Encode a value to bytes.
|
|
47
41
|
// If the value is an int it will be encoded as bytes big endian
|
|
48
42
|
// Raises ValueError if the input is not an int or string
|
|
49
43
|
|
|
50
|
-
if (val === undefined || val === null) return Buffer.from([])
|
|
44
|
+
if (val === undefined || val === null) return Buffer.from([]);
|
|
51
45
|
if (Number.isInteger(val) || BigNumber.isBigNumber(val) || big) {
|
|
52
|
-
if (!BigNumber.isBigNumber(val)) val = new BigNumber(val)
|
|
53
|
-
return bigNumberToByteArray(val)
|
|
46
|
+
if (!BigNumber.isBigNumber(val)) val = new BigNumber(val);
|
|
47
|
+
return bigNumberToByteArray(val);
|
|
54
48
|
}
|
|
55
49
|
if (typeof val === 'string') {
|
|
56
|
-
return Buffer.from(val)
|
|
50
|
+
return Buffer.from(val);
|
|
57
51
|
}
|
|
58
|
-
throw new NoSerializerFoundError()
|
|
52
|
+
throw new NoSerializerFoundError();
|
|
59
53
|
}
|
|
60
54
|
|
|
61
55
|
/**
|
|
62
56
|
* Convert a string to a Buffer. If encoding is not specified, hex-encoding
|
|
63
57
|
* will be used if the input is valid hex. If the input is valid base64 but
|
|
64
58
|
* not valid hex, base64 will be used. Otherwise, utf8 will be used.
|
|
65
|
-
* @param
|
|
66
|
-
* @param
|
|
67
|
-
* @
|
|
59
|
+
* @param str - String to be converted.
|
|
60
|
+
* @param enc - Encoding of the input string.
|
|
61
|
+
* @returns Buffer containing the input data.
|
|
68
62
|
*/
|
|
69
|
-
export function str2buf
|
|
63
|
+
export function str2buf(str: string, enc?: BufferEncoding): Buffer {
|
|
70
64
|
return Buffer.from(
|
|
71
65
|
str,
|
|
72
|
-
enc ?? (isHex(str) ? 'hex' : undefined) ?? (isBase64(str) ? 'base64' : undefined)
|
|
73
|
-
)
|
|
66
|
+
enc ?? (isHex(str) ? 'hex' : undefined) ?? (isBase64(str) ? 'base64' : undefined),
|
|
67
|
+
);
|
|
74
68
|
}
|
|
69
|
+
|
|
70
|
+
export const bytesToHex = (b: Uint8Array): string => Buffer.from(b).toString('hex');
|
|
71
|
+
|
|
72
|
+
export const hexToBytes = (s: string): Uint8Array => Buffer.from(s, 'hex');
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ISC License (ISC)
|
|
3
|
+
* Copyright 2018 aeternity developers
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
|
8
|
+
*
|
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
*/
|
|
17
|
+
import nacl, { SignKeyPair } from 'tweetnacl';
|
|
18
|
+
// js extension is required for mjs build, not importing the whole package to reduce bundle size
|
|
19
|
+
// eslint-disable-next-line import/extensions
|
|
20
|
+
import { blake2b } from 'blakejs/blake2b.js';
|
|
21
|
+
import { encode as varuintEncode } from 'varuint-bitcoin';
|
|
22
|
+
|
|
23
|
+
import { str2buf } from './bytes';
|
|
24
|
+
import { concatBuffers } from './other';
|
|
25
|
+
import {
|
|
26
|
+
decode, encode, Encoded, Encoding,
|
|
27
|
+
} from './encoder';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Generate address from secret key
|
|
31
|
+
* @param secret - Private key
|
|
32
|
+
* @returns Public key encoded as address
|
|
33
|
+
*/
|
|
34
|
+
export function getAddressFromPriv(secret: string | Uint8Array): Encoded.AccountAddress {
|
|
35
|
+
const secretBuffer = typeof secret === 'string' ? str2buf(secret) : secret;
|
|
36
|
+
const keys = nacl.sign.keyPair.fromSecretKey(secretBuffer);
|
|
37
|
+
return encode(keys.publicKey, Encoding.AccountAddress);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Check if address is valid
|
|
42
|
+
* @param address - Address
|
|
43
|
+
* @param prefix - Transaction prefix. Default: 'ak'
|
|
44
|
+
* @returns is valid
|
|
45
|
+
*/
|
|
46
|
+
export function isAddressValid(
|
|
47
|
+
address: string,
|
|
48
|
+
prefix: Encoding = Encoding.AccountAddress,
|
|
49
|
+
): boolean {
|
|
50
|
+
try {
|
|
51
|
+
decode(address as Encoded.Generic<typeof prefix>);
|
|
52
|
+
return true;
|
|
53
|
+
} catch (e) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Generate a random salt (positive integer)
|
|
60
|
+
* @returns random salt
|
|
61
|
+
*/
|
|
62
|
+
export function genSalt(): number {
|
|
63
|
+
return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Converts a positive integer to the smallest possible
|
|
68
|
+
* representation in a binary digit representation
|
|
69
|
+
* @param value - Value to encode
|
|
70
|
+
* @returns Encoded number
|
|
71
|
+
*/
|
|
72
|
+
export function encodeUnsigned(value: number): Buffer {
|
|
73
|
+
const binary = Buffer.allocUnsafe(4);
|
|
74
|
+
binary.writeUInt32BE(value);
|
|
75
|
+
return binary.slice(binary.findIndex((i) => i !== 0));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Calculate 256bits Blake2b hash of `input`
|
|
80
|
+
* @param input - Data to hash
|
|
81
|
+
* @returns Hash
|
|
82
|
+
*/
|
|
83
|
+
export function hash(input: string | Uint8Array): Buffer {
|
|
84
|
+
return Buffer.from(blake2b(input, undefined, 32)); // 256 bits
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Todo Duplicated in tx builder. remove
|
|
88
|
+
/**
|
|
89
|
+
* Compute contract address
|
|
90
|
+
* @category contract
|
|
91
|
+
* @param owner - Address of contract owner
|
|
92
|
+
* @param nonce - Round when contract was created
|
|
93
|
+
* @returns Contract address
|
|
94
|
+
*/
|
|
95
|
+
export function encodeContractAddress(
|
|
96
|
+
owner: Encoded.AccountAddress,
|
|
97
|
+
nonce: number,
|
|
98
|
+
): Encoded.ContractAddress {
|
|
99
|
+
const publicKey = decode(owner);
|
|
100
|
+
const binary = concatBuffers([publicKey, encodeUnsigned(nonce)]);
|
|
101
|
+
return encode(hash(binary), Encoding.ContractAddress);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// KEY-PAIR HELPERS
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Generate keyPair from secret key
|
|
108
|
+
* @param secret - secret key
|
|
109
|
+
* @returns Object with Private(privateKey) and Public(publicKey) keys
|
|
110
|
+
*/
|
|
111
|
+
export function generateKeyPairFromSecret(secret: Uint8Array): SignKeyPair {
|
|
112
|
+
return nacl.sign.keyPair.fromSecretKey(secret);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Generate a random ED25519 keypair
|
|
117
|
+
* @param raw - Whether to return raw (binary) keys
|
|
118
|
+
* @returns Key pair
|
|
119
|
+
*/
|
|
120
|
+
export function generateKeyPair(raw: true): { publicKey: Buffer; secretKey: Buffer };
|
|
121
|
+
export function generateKeyPair(raw?: false): {
|
|
122
|
+
publicKey: Encoded.AccountAddress; secretKey: string;
|
|
123
|
+
};
|
|
124
|
+
export function generateKeyPair(raw = false): {
|
|
125
|
+
publicKey: Encoded.AccountAddress | Buffer;
|
|
126
|
+
secretKey: string | Buffer;
|
|
127
|
+
} {
|
|
128
|
+
const keyPair = nacl.sign.keyPair();
|
|
129
|
+
const publicBuffer = Buffer.from(keyPair.publicKey);
|
|
130
|
+
const secretBuffer = Buffer.from(keyPair.secretKey);
|
|
131
|
+
|
|
132
|
+
if (raw) {
|
|
133
|
+
return {
|
|
134
|
+
publicKey: publicBuffer,
|
|
135
|
+
secretKey: secretBuffer,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
publicKey: encode(publicBuffer, Encoding.AccountAddress),
|
|
140
|
+
secretKey: secretBuffer.toString('hex'),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// SIGNATURES
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Generate signature
|
|
148
|
+
* @param data - Data to sign
|
|
149
|
+
* @param privateKey - Key to sign with
|
|
150
|
+
* @returns Signature
|
|
151
|
+
*/
|
|
152
|
+
export function sign(data: string | Uint8Array, privateKey: string | Uint8Array): Uint8Array {
|
|
153
|
+
return nacl.sign.detached(Buffer.from(data), Buffer.from(privateKey));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Verify that signature was signed by public key
|
|
158
|
+
* @param data - Data to verify
|
|
159
|
+
* @param signature - Signature to verify
|
|
160
|
+
* @param publicKey - Key to verify against
|
|
161
|
+
* @returns Valid?
|
|
162
|
+
*/
|
|
163
|
+
export function verify(
|
|
164
|
+
data: Uint8Array,
|
|
165
|
+
signature: Uint8Array,
|
|
166
|
+
publicKey: string | Uint8Array,
|
|
167
|
+
): boolean {
|
|
168
|
+
const publicKeyBuffer = typeof publicKey === 'string' ? str2buf(publicKey) : publicKey;
|
|
169
|
+
return nacl.sign.detached.verify(data, signature, publicKeyBuffer);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function messageToHash(message: string): Buffer {
|
|
173
|
+
const p = Buffer.from('aeternity Signed Message:\n', 'utf8');
|
|
174
|
+
const msg = Buffer.from(message, 'utf8');
|
|
175
|
+
return hash(concatBuffers([varuintEncode(p.length), p, varuintEncode(msg.length), msg]));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function signMessage(message: string, privateKey: string | Buffer): Uint8Array {
|
|
179
|
+
return sign(messageToHash(message), privateKey);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function verifyMessage(
|
|
183
|
+
str: string,
|
|
184
|
+
signature: Uint8Array,
|
|
185
|
+
publicKey: string | Uint8Array,
|
|
186
|
+
): boolean {
|
|
187
|
+
return verify(messageToHash(str), signature, publicKey);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Check key pair for validity
|
|
192
|
+
*
|
|
193
|
+
* Sign a message, and then verifying that signature
|
|
194
|
+
* @param privateKey - Private key to verify
|
|
195
|
+
* @param publicKey - Public key to verify
|
|
196
|
+
* @returns Valid?
|
|
197
|
+
*/
|
|
198
|
+
export function isValidKeypair(
|
|
199
|
+
privateKey: string | Uint8Array,
|
|
200
|
+
publicKey: string | Uint8Array,
|
|
201
|
+
): boolean {
|
|
202
|
+
const message = Buffer.from('TheMessage');
|
|
203
|
+
const signature = sign(message, privateKey);
|
|
204
|
+
return verify(message, signature, publicKey);
|
|
205
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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 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
|
+
|
|
35
|
+
export type KeyBlockHash = `${Encoding.KeyBlockHash}_${string}`;
|
|
36
|
+
export type MicroBlockHash = `${Encoding.MicroBlockHash}_${string}`;
|
|
37
|
+
export type BlockPofHash = `${Encoding.BlockPofHash}_${string}`;
|
|
38
|
+
export type BlockTxHash = `${Encoding.BlockTxHash}_${string}`;
|
|
39
|
+
export type BlockStateHash = `${Encoding.BlockStateHash}_${string}`;
|
|
40
|
+
export type Channel = `${Encoding.Channel}_${string}`;
|
|
41
|
+
export type ContractAddress = `${Encoding.ContractAddress}_${string}`;
|
|
42
|
+
export type ContractBytearray = `${Encoding.ContractBytearray}_${string}`;
|
|
43
|
+
export type ContractStoreKey = `${Encoding.ContractStoreKey}_${string}`;
|
|
44
|
+
export type ContractStoreValue = `${Encoding.ContractStoreValue}_${string}`;
|
|
45
|
+
export type Transaction = `${Encoding.Transaction}_${string}`;
|
|
46
|
+
export type TxHash = `${Encoding.TxHash}_${string}`;
|
|
47
|
+
export type OracleAddress = `${Encoding.OracleAddress}_${string}`;
|
|
48
|
+
export type OracleQuery = `${Encoding.OracleQuery}_${string}`;
|
|
49
|
+
export type OracleQueryId = `${Encoding.OracleQueryId}_${string}`;
|
|
50
|
+
export type OracleResponse = `${Encoding.OracleResponse}_${string}`;
|
|
51
|
+
export type AccountAddress = `${Encoding.AccountAddress}_${string}`;
|
|
52
|
+
export type Signature = `${Encoding.Signature}_${string}`;
|
|
53
|
+
export type Commitment = `${Encoding.Commitment}_${string}`;
|
|
54
|
+
export type PeerPubkey = `${Encoding.PeerPubkey}_${string}`;
|
|
55
|
+
export type Name = `${Encoding.Name}_${string}`;
|
|
56
|
+
export type State = `${Encoding.State}_${string}`;
|
|
57
|
+
export type Poi = `${Encoding.Poi}_${string}`;
|
|
58
|
+
export type StateTrees = `${Encoding.StateTrees}_${string}`;
|
|
59
|
+
export type CallStateTree = `${Encoding.CallStateTree}_${string}`;
|
|
60
|
+
export type Bytearray = `${Encoding.Bytearray}_${string}`;
|
|
61
|
+
|
|
62
|
+
export type Generic<Type extends Encoding> = `${Type}_${string}`;
|
|
63
|
+
export type Any = `${Encoding}_${string}`;
|