@aeternity/aepp-sdk 12.1.3 → 13.0.0-alpha.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/bin/aesophia_cli +0 -0
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +12031 -11231
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +7 -3
- package/es/AeSdk.mjs +17 -22
- package/es/AeSdk.mjs.map +1 -1
- package/es/AeSdkAepp.d.ts +6 -5
- package/es/AeSdkAepp.mjs +7 -30
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +18 -140
- package/es/AeSdkBase.mjs +30 -184
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkMethods.d.ts +123 -0
- package/es/AeSdkMethods.mjs +122 -0
- package/es/AeSdkMethods.mjs.map +1 -0
- package/es/AeSdkWallet.d.ts +7 -21
- package/es/AeSdkWallet.mjs +38 -86
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Node.d.ts +11 -15
- package/es/Node.mjs +35 -48
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +24 -40
- package/es/account/Base.mjs +1 -101
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Generalized.d.ts +16 -0
- package/es/account/Generalized.mjs +113 -0
- package/es/account/Generalized.mjs.map +1 -0
- package/es/account/Ledger.d.ts +28 -0
- package/es/account/Ledger.mjs +102 -0
- package/es/account/Ledger.mjs.map +1 -0
- package/es/account/LedgerFactory.d.ts +39 -0
- package/es/account/LedgerFactory.mjs +81 -0
- package/es/account/LedgerFactory.mjs.map +1 -0
- package/es/account/Memory.d.ts +13 -17
- package/es/account/Memory.mjs +43 -64
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +6 -8
- package/es/account/Rpc.mjs +14 -32
- package/es/account/Rpc.mjs.map +1 -1
- package/es/aens.d.ts +4 -4
- package/es/aens.mjs +46 -41
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/Browser.mjs +9 -13
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +22 -11
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +0 -31
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +3 -3
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -42
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +7 -1
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.mjs +14 -68
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.mjs +0 -3
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/compiler/compiler.d.ts +23 -29
- package/es/apis/compiler/compiler.mjs +128 -189
- package/es/apis/compiler/compiler.mjs.map +1 -1
- package/es/apis/compiler/index.mjs.map +1 -1
- package/es/apis/compiler/models/index.d.ts +82 -135
- package/es/apis/compiler/models/index.mjs +1 -47
- package/es/apis/compiler/models/index.mjs.map +1 -1
- package/es/apis/compiler/models/mappers.d.ts +8 -8
- package/es/apis/compiler/models/mappers.mjs +165 -183
- package/es/apis/compiler/models/mappers.mjs.map +1 -1
- package/es/apis/compiler/models/parameters.d.ts +0 -1
- package/es/apis/compiler/models/parameters.mjs +5 -9
- package/es/apis/compiler/models/parameters.mjs.map +1 -1
- package/es/apis/node/index.mjs.map +1 -1
- package/es/apis/node/models/index.d.ts +48 -48
- package/es/apis/node/models/mappers.mjs +12 -6
- package/es/apis/node/models/mappers.mjs.map +1 -1
- package/es/apis/node/models/parameters.mjs.map +1 -1
- package/es/apis/node/node.mjs +43 -84
- package/es/apis/node/node.mjs.map +1 -1
- package/es/chain.d.ts +10 -2
- package/es/chain.mjs +37 -59
- package/es/chain.mjs.map +1 -1
- package/es/channel/Base.d.ts +200 -0
- package/es/channel/Base.mjs +293 -0
- package/es/channel/Base.mjs.map +1 -0
- package/es/channel/Contract.d.ts +248 -0
- package/es/channel/Contract.mjs +420 -0
- package/es/channel/Contract.mjs.map +1 -0
- package/es/channel/Spend.d.ts +219 -0
- package/es/channel/Spend.mjs +385 -0
- package/es/channel/Spend.mjs.map +1 -0
- package/es/channel/handlers.d.ts +8 -21
- package/es/channel/handlers.mjs +151 -899
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/internal.d.ts +27 -21
- package/es/channel/internal.mjs +101 -191
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Contract.d.ts +210 -0
- package/es/contract/Contract.mjs +551 -0
- package/es/contract/Contract.mjs.map +1 -0
- package/es/contract/compiler/Base.d.ts +81 -0
- package/es/contract/compiler/Base.mjs +5 -0
- package/es/contract/compiler/Base.mjs.map +1 -0
- package/es/contract/compiler/Cli.d.ts +23 -0
- package/es/contract/compiler/Cli.mjs +155 -0
- package/es/contract/compiler/Cli.mjs.map +1 -0
- package/es/contract/compiler/Http.d.ts +32 -0
- package/es/contract/compiler/Http.mjs +118 -0
- package/es/contract/compiler/Http.mjs.map +1 -0
- package/es/contract/compiler/HttpNode.d.ts +17 -0
- package/es/contract/compiler/HttpNode.mjs +26 -0
- package/es/contract/compiler/HttpNode.mjs.map +1 -0
- package/es/contract/compiler/getFileSystem.d.ts +6 -0
- package/es/contract/compiler/getFileSystem.mjs +40 -0
- package/es/contract/compiler/getFileSystem.mjs.map +1 -0
- package/es/contract/ga.d.ts +9 -34
- package/es/contract/ga.mjs +29 -112
- package/es/contract/ga.mjs.map +1 -1
- package/es/index-browser.d.ts +39 -0
- package/es/index-browser.mjs +55 -0
- package/es/index-browser.mjs.map +1 -0
- package/es/index.d.ts +4 -35
- package/es/index.mjs +4 -51
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +5 -5
- package/es/oracle.mjs +34 -40
- package/es/oracle.mjs.map +1 -1
- package/es/spend.d.ts +3 -3
- package/es/spend.mjs +18 -23
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/constants.d.ts +30 -2
- package/es/tx/builder/constants.mjs +43 -14
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/abi-version.d.ts +10 -0
- package/es/tx/builder/field-types/abi-version.mjs +20 -0
- package/es/tx/builder/field-types/abi-version.mjs.map +1 -0
- package/es/tx/builder/field-types/address.d.ts +14 -0
- package/es/tx/builder/field-types/address.mjs +51 -0
- package/es/tx/builder/field-types/address.mjs.map +1 -0
- package/es/tx/builder/field-types/array.d.ts +7 -0
- package/es/tx/builder/field-types/array.mjs +11 -0
- package/es/tx/builder/field-types/array.mjs.map +1 -0
- package/es/tx/builder/field-types/boolean.d.ts +6 -0
- package/es/tx/builder/field-types/boolean.mjs +13 -0
- package/es/tx/builder/field-types/boolean.mjs.map +1 -0
- package/es/tx/builder/field-types/coin-amount.d.ts +2 -3
- package/es/tx/builder/field-types/coin-amount.mjs +4 -12
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
- package/es/tx/builder/field-types/ct-version.d.ts +30 -0
- package/es/tx/builder/field-types/ct-version.mjs +48 -0
- package/es/tx/builder/field-types/ct-version.mjs.map +1 -0
- package/es/tx/builder/field-types/deposit.d.ts +1 -2
- package/es/tx/builder/field-types/deposit.mjs +2 -4
- package/es/tx/builder/field-types/deposit.mjs.map +1 -1
- package/es/tx/builder/field-types/encoded.d.ts +6 -0
- package/es/tx/builder/field-types/encoded.mjs +21 -0
- package/es/tx/builder/field-types/encoded.mjs.map +1 -0
- package/es/tx/builder/field-types/entry.d.ts +11 -0
- package/es/tx/builder/field-types/entry.mjs +31 -0
- package/es/tx/builder/field-types/entry.mjs.map +1 -0
- package/es/tx/builder/field-types/enumeration.d.ts +7 -0
- package/es/tx/builder/field-types/enumeration.mjs +30 -0
- package/es/tx/builder/field-types/enumeration.mjs.map +1 -0
- package/es/tx/builder/field-types/fee.d.ts +10 -15
- package/es/tx/builder/field-types/fee.mjs +31 -43
- package/es/tx/builder/field-types/fee.mjs.map +1 -1
- package/es/tx/builder/field-types/field.mjs +0 -2
- package/es/tx/builder/field-types/field.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-limit.d.ts +5 -2
- package/es/tx/builder/field-types/gas-limit.mjs +12 -14
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-price.d.ts +1 -2
- package/es/tx/builder/field-types/gas-price.mjs +3 -7
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
- package/es/tx/builder/field-types/index.d.ts +80 -30
- package/es/tx/builder/field-types/index.mjs +34 -9
- package/es/tx/builder/field-types/index.mjs.map +1 -1
- package/es/tx/builder/field-types/mptree.d.ts +37 -0
- package/es/tx/builder/field-types/mptree.mjs +268 -0
- package/es/tx/builder/field-types/mptree.mjs.map +1 -0
- package/es/tx/builder/field-types/name-fee.d.ts +1 -3
- package/es/tx/builder/field-types/name-fee.mjs +3 -5
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
- package/es/tx/builder/field-types/name-id.d.ts +1 -4
- package/es/tx/builder/field-types/name-id.mjs +5 -10
- package/es/tx/builder/field-types/name-id.mjs.map +1 -1
- package/es/tx/builder/field-types/name.mjs +0 -2
- package/es/tx/builder/field-types/name.mjs.map +1 -1
- package/es/tx/builder/field-types/pointers.d.ts +23 -0
- package/es/tx/builder/field-types/pointers.mjs +36 -0
- package/es/tx/builder/field-types/pointers.mjs.map +1 -0
- package/es/tx/builder/field-types/raw.d.ts +6 -0
- package/es/tx/builder/field-types/raw.mjs +13 -0
- package/es/tx/builder/field-types/raw.mjs.map +1 -0
- package/es/tx/builder/field-types/short-u-int-const.d.ts +5 -0
- package/es/tx/builder/field-types/short-u-int-const.mjs +16 -0
- package/es/tx/builder/field-types/short-u-int-const.mjs.map +1 -0
- package/es/tx/builder/field-types/short-u-int.mjs +0 -2
- package/es/tx/builder/field-types/short-u-int.mjs.map +1 -1
- package/es/tx/builder/field-types/string.d.ts +6 -0
- package/es/tx/builder/field-types/string.mjs +10 -0
- package/es/tx/builder/field-types/string.mjs.map +1 -0
- package/es/tx/builder/field-types/u-int.d.ts +1 -2
- package/es/tx/builder/field-types/u-int.mjs +3 -4
- package/es/tx/builder/field-types/u-int.mjs.map +1 -1
- package/es/tx/builder/helpers.d.ts +2 -32
- package/es/tx/builder/helpers.mjs +19 -71
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +11 -49
- package/es/tx/builder/index.mjs +57 -337
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +2367 -667
- package/es/tx/builder/schema.mjs +70 -145
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +4 -49
- package/es/tx/index.mjs +38 -112
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +4 -6
- package/es/tx/validator.mjs +104 -90
- package/es/tx/validator.mjs.map +1 -1
- package/es/typings/{@aeternity__argon2-browser → @aeternity__aepp-calldata}/index.d.mjs +0 -0
- package/es/typings/@aeternity__aepp-calldata/index.d.mjs.map +1 -0
- package/es/utils/amount-formatter.mjs +4 -10
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.d.ts +1 -0
- package/es/utils/autorest.mjs +17 -19
- package/es/utils/autorest.mjs.map +1 -1
- package/es/utils/bignumber.mjs +4 -7
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/utils/bytes.d.ts +0 -17
- package/es/utils/bytes.mjs +6 -35
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +15 -8
- package/es/utils/crypto.mjs +40 -40
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder-types.d.ts +28 -28
- package/es/utils/encoder-types.mjs +0 -1
- package/es/utils/encoder-types.mjs.map +1 -1
- package/es/utils/encoder.d.ts +0 -1
- package/es/utils/encoder.mjs +7 -15
- package/es/utils/encoder.mjs.map +1 -1
- package/es/utils/errors.d.ts +15 -14
- package/es/utils/errors.mjs +86 -172
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +27 -19
- package/es/utils/hd-wallet.mjs +42 -26
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.mjs +0 -8
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.d.ts +2 -0
- package/es/utils/keystore.mjs +37 -36
- package/es/utils/keystore.mjs.map +1 -1
- package/es/utils/other.d.ts +4 -2
- package/es/utils/other.mjs +11 -7
- package/es/utils/other.mjs.map +1 -1
- package/es/utils/semver-satisfies.mjs +0 -3
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.d.ts +0 -12
- package/es/utils/string.mjs +1 -21
- package/es/utils/string.mjs.map +1 -1
- package/package.json +98 -51
- package/src/AeSdk.ts +15 -11
- package/src/AeSdkAepp.ts +9 -7
- package/src/AeSdkBase.ts +31 -202
- package/src/AeSdkMethods.ts +169 -0
- package/src/AeSdkWallet.ts +16 -47
- package/src/Node.ts +17 -18
- package/src/account/Base.ts +29 -75
- package/src/account/Generalized.ts +98 -0
- package/src/account/Ledger.ts +131 -0
- package/src/account/LedgerFactory.ts +86 -0
- package/src/account/Memory.ts +46 -60
- package/src/account/Rpc.ts +17 -26
- package/src/aens.ts +13 -11
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +21 -9
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +3 -3
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +4 -4
- package/src/aepp-wallet-communication/rpc/types.ts +11 -1
- package/src/aepp-wallet-communication/schema.ts +18 -18
- package/src/apis/compiler/code-model-v4.yaml +681 -888
- package/src/apis/compiler/compiler.ts +113 -154
- package/src/apis/compiler/models/index.ts +80 -140
- package/src/apis/compiler/models/mappers.ts +165 -183
- package/src/apis/compiler/models/parameters.ts +6 -12
- package/src/chain.ts +11 -6
- package/src/channel/Base.ts +335 -0
- package/src/channel/Contract.ts +488 -0
- package/src/channel/Spend.ts +408 -0
- package/src/channel/handlers.ts +164 -582
- package/src/channel/internal.ts +114 -143
- package/src/contract/Contract.ts +610 -0
- package/src/contract/compiler/Base.ts +94 -0
- package/src/contract/compiler/Cli.ts +134 -0
- package/src/contract/compiler/Http.ts +124 -0
- package/src/contract/compiler/HttpNode.ts +26 -0
- package/src/contract/compiler/getFileSystem.ts +42 -0
- package/src/contract/ga.ts +23 -106
- package/src/index-browser.ts +58 -0
- package/src/index.ts +4 -55
- package/src/oracle.ts +8 -8
- package/src/spend.ts +6 -14
- package/src/tx/builder/constants.ts +33 -3
- package/src/tx/builder/field-types/abi-version.ts +21 -0
- package/src/tx/builder/field-types/address.ts +62 -0
- package/src/tx/builder/field-types/array.ts +19 -0
- package/src/tx/builder/field-types/boolean.ts +9 -0
- package/src/tx/builder/field-types/coin-amount.ts +4 -9
- package/src/tx/builder/field-types/ct-version.ts +50 -0
- package/src/tx/builder/field-types/deposit.ts +1 -1
- package/src/tx/builder/field-types/encoded.ts +27 -0
- package/src/tx/builder/field-types/entry.ts +31 -0
- package/src/tx/builder/field-types/enumeration.ts +32 -0
- package/src/tx/builder/field-types/fee.ts +39 -21
- package/src/tx/builder/field-types/gas-limit.ts +13 -8
- package/src/tx/builder/field-types/gas-price.ts +0 -2
- package/src/tx/builder/field-types/index.ts +54 -15
- package/src/tx/builder/field-types/mptree.ts +242 -0
- package/src/tx/builder/field-types/name-fee.ts +2 -3
- package/src/tx/builder/field-types/name-id.ts +7 -10
- package/src/tx/builder/field-types/pointers.ts +41 -0
- package/src/tx/builder/field-types/raw.ts +9 -0
- package/src/tx/builder/field-types/short-u-int-const.ts +20 -0
- package/src/tx/builder/field-types/string.ts +11 -0
- package/src/tx/builder/field-types/u-int.ts +4 -5
- package/src/tx/builder/helpers.ts +10 -60
- package/src/tx/builder/index.ts +65 -308
- package/src/tx/builder/schema.ts +280 -341
- package/src/tx/index.ts +40 -103
- package/src/tx/validator.ts +91 -96
- package/src/typings/@aeternity__aepp-calldata/index.d.ts +20 -0
- package/src/utils/autorest.ts +16 -1
- package/src/utils/bytes.ts +6 -34
- package/src/utils/crypto.ts +23 -16
- package/src/utils/encoder.ts +0 -1
- package/src/utils/errors.ts +22 -25
- package/src/utils/hd-wallet.ts +30 -9
- package/src/utils/keystore.ts +24 -21
- package/src/utils/other.ts +16 -1
- package/src/utils/string.ts +0 -20
- package/types-legacy/ts4.2/AeSdk.d.ts +41 -0
- package/types-legacy/ts4.2/AeSdkAepp.d.ts +71 -0
- package/types-legacy/ts4.2/AeSdkBase.d.ts +91 -0
- package/types-legacy/ts4.2/AeSdkMethods.d.ts +140 -0
- package/types-legacy/ts4.2/AeSdkWallet.d.ts +90 -0
- package/types-legacy/ts4.2/Node.d.ts +78 -0
- package/types-legacy/ts4.2/account/Base.d.ts +52 -0
- package/types-legacy/ts4.2/account/Generalized.d.ts +16 -0
- package/types-legacy/ts4.2/account/Ledger.d.ts +28 -0
- package/types-legacy/ts4.2/account/LedgerFactory.d.ts +39 -0
- package/types-legacy/ts4.2/account/Memory.d.ts +22 -0
- package/types-legacy/ts4.2/account/Rpc.d.ts +25 -0
- package/types-legacy/ts4.2/aens.d.ts +222 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/connection/Browser.d.ts +33 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserRuntime.d.ts +19 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +36 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/connection-proxy.d.ts +11 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/rpc/RpcClient.d.ts +34 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +83 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/schema.d.ts +133 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/wallet-detector.d.ts +25 -0
- package/types-legacy/ts4.2/apis/compiler/compiler.d.ts +86 -0
- package/types-legacy/ts4.2/apis/compiler/index.d.ts +2 -0
- package/types-legacy/ts4.2/apis/compiler/models/index.d.ts +195 -0
- package/types-legacy/ts4.2/apis/compiler/models/mappers.d.ts +23 -0
- package/types-legacy/ts4.2/apis/compiler/models/parameters.d.ts +12 -0
- package/types-legacy/ts4.2/apis/node/index.d.ts +2 -0
- package/types-legacy/ts4.2/apis/node/models/index.d.ts +1065 -0
- package/types-legacy/ts4.2/apis/node/models/mappers.d.ts +95 -0
- package/types-legacy/ts4.2/apis/node/models/parameters.d.ts +17 -0
- package/types-legacy/ts4.2/apis/node/node.d.ts +215 -0
- package/types-legacy/ts4.2/chain.d.ts +256 -0
- package/types-legacy/ts4.2/channel/Base.d.ts +199 -0
- package/types-legacy/ts4.2/channel/Contract.d.ts +248 -0
- package/types-legacy/ts4.2/channel/Spend.d.ts +219 -0
- package/types-legacy/ts4.2/channel/handlers.d.ts +21 -0
- package/types-legacy/ts4.2/channel/internal.d.ts +107 -0
- package/types-legacy/ts4.2/contract/Contract.d.ts +212 -0
- package/types-legacy/ts4.2/contract/compiler/Base.d.ts +81 -0
- package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +23 -0
- package/types-legacy/ts4.2/contract/compiler/Http.d.ts +32 -0
- package/types-legacy/ts4.2/contract/compiler/HttpNode.d.ts +17 -0
- package/types-legacy/ts4.2/contract/compiler/getFileSystem.d.ts +6 -0
- package/types-legacy/ts4.2/contract/ga.d.ts +44 -0
- package/types-legacy/ts4.2/globals.d.ts +16 -0
- package/types-legacy/ts4.2/index-browser.d.ts +39 -0
- package/types-legacy/ts4.2/index.d.ts +5 -0
- package/types-legacy/ts4.2/oracle.d.ts +161 -0
- package/types-legacy/ts4.2/spend.d.ts +62 -0
- package/types-legacy/ts4.2/tx/builder/constants.d.ts +98 -0
- package/types-legacy/ts4.2/tx/builder/field-types/abi-version.d.ts +10 -0
- package/types-legacy/ts4.2/tx/builder/field-types/address.d.ts +21 -0
- package/types-legacy/ts4.2/tx/builder/field-types/array.d.ts +7 -0
- package/types-legacy/ts4.2/tx/builder/field-types/boolean.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +12 -0
- package/types-legacy/ts4.2/tx/builder/field-types/ct-version.d.ts +42 -0
- package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +14 -0
- package/types-legacy/ts4.2/tx/builder/field-types/encoded.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/entry.d.ts +11 -0
- package/types-legacy/ts4.2/tx/builder/field-types/enumeration.d.ts +7 -0
- package/types-legacy/ts4.2/tx/builder/field-types/fee.d.ts +20 -0
- package/types-legacy/ts4.2/tx/builder/field-types/field.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/gas-limit.d.ts +15 -0
- package/types-legacy/ts4.2/tx/builder/field-types/gas-price.d.ts +7 -0
- package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +129 -0
- package/types-legacy/ts4.2/tx/builder/field-types/mptree.d.ts +43 -0
- package/types-legacy/ts4.2/tx/builder/field-types/name-fee.d.ts +18 -0
- package/types-legacy/ts4.2/tx/builder/field-types/name-id.d.ts +11 -0
- package/types-legacy/ts4.2/tx/builder/field-types/name.d.ts +13 -0
- package/types-legacy/ts4.2/tx/builder/field-types/pointers.d.ts +26 -0
- package/types-legacy/ts4.2/tx/builder/field-types/raw.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/short-u-int-const.d.ts +5 -0
- package/types-legacy/ts4.2/tx/builder/field-types/short-u-int.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/string.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/u-int.d.ts +7 -0
- package/types-legacy/ts4.2/tx/builder/helpers.d.ts +112 -0
- package/types-legacy/ts4.2/tx/builder/index.d.ts +50 -0
- package/types-legacy/ts4.2/tx/builder/schema.d.ts +4675 -0
- package/types-legacy/ts4.2/tx/index.d.ts +19 -0
- package/types-legacy/ts4.2/tx/validator.d.ts +18 -0
- package/types-legacy/ts4.2/utils/amount-formatter.d.ts +42 -0
- package/types-legacy/ts4.2/utils/autorest.d.ts +7 -0
- package/types-legacy/ts4.2/utils/bignumber.d.ts +13 -0
- package/types-legacy/ts4.2/utils/bytes.d.ts +9 -0
- package/types-legacy/ts4.2/utils/crypto.d.ts +95 -0
- package/types-legacy/ts4.2/utils/encoder-types.d.ts +61 -0
- package/types-legacy/ts4.2/utils/encoder.d.ts +24 -0
- package/types-legacy/ts4.2/utils/errors.d.ts +475 -0
- package/types-legacy/ts4.2/utils/hd-wallet.d.ts +65 -0
- package/types-legacy/ts4.2/utils/json-big.d.ts +5 -0
- package/types-legacy/ts4.2/utils/keystore.d.ts +53 -0
- package/types-legacy/ts4.2/utils/other.d.ts +31 -0
- package/types-legacy/ts4.2/utils/semver-satisfies.d.ts +1 -0
- package/types-legacy/ts4.2/utils/string.d.ts +12 -0
- package/types-legacy/ts4.5/AeSdk.d.ts +41 -0
- package/types-legacy/ts4.5/AeSdkAepp.d.ts +71 -0
- package/types-legacy/ts4.5/AeSdkBase.d.ts +91 -0
- package/types-legacy/ts4.5/AeSdkMethods.d.ts +140 -0
- package/types-legacy/ts4.5/AeSdkWallet.d.ts +90 -0
- package/types-legacy/ts4.5/Node.d.ts +78 -0
- package/types-legacy/ts4.5/account/Base.d.ts +52 -0
- package/types-legacy/ts4.5/account/Generalized.d.ts +16 -0
- package/types-legacy/ts4.5/account/Ledger.d.ts +28 -0
- package/types-legacy/ts4.5/account/LedgerFactory.d.ts +39 -0
- package/types-legacy/ts4.5/account/Memory.d.ts +22 -0
- package/types-legacy/ts4.5/account/Rpc.d.ts +25 -0
- package/types-legacy/ts4.5/aens.d.ts +222 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/connection/Browser.d.ts +33 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserRuntime.d.ts +19 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +36 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/connection-proxy.d.ts +11 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/rpc/RpcClient.d.ts +34 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +83 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/schema.d.ts +133 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/wallet-detector.d.ts +25 -0
- package/types-legacy/ts4.5/apis/compiler/compiler.d.ts +86 -0
- package/types-legacy/ts4.5/apis/compiler/index.d.ts +2 -0
- package/types-legacy/ts4.5/apis/compiler/models/index.d.ts +195 -0
- package/types-legacy/ts4.5/apis/compiler/models/mappers.d.ts +23 -0
- package/types-legacy/ts4.5/apis/compiler/models/parameters.d.ts +12 -0
- package/types-legacy/ts4.5/apis/node/index.d.ts +2 -0
- package/types-legacy/ts4.5/apis/node/models/index.d.ts +1065 -0
- package/types-legacy/ts4.5/apis/node/models/mappers.d.ts +95 -0
- package/types-legacy/ts4.5/apis/node/models/parameters.d.ts +17 -0
- package/types-legacy/ts4.5/apis/node/node.d.ts +215 -0
- package/types-legacy/ts4.5/chain.d.ts +256 -0
- package/types-legacy/ts4.5/channel/Base.d.ts +199 -0
- package/types-legacy/ts4.5/channel/Contract.d.ts +248 -0
- package/types-legacy/ts4.5/channel/Spend.d.ts +219 -0
- package/types-legacy/ts4.5/channel/handlers.d.ts +21 -0
- package/types-legacy/ts4.5/channel/internal.d.ts +107 -0
- package/types-legacy/ts4.5/contract/Contract.d.ts +212 -0
- package/types-legacy/ts4.5/contract/compiler/Base.d.ts +81 -0
- package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +23 -0
- package/types-legacy/ts4.5/contract/compiler/Http.d.ts +32 -0
- package/types-legacy/ts4.5/contract/compiler/HttpNode.d.ts +17 -0
- package/types-legacy/ts4.5/contract/compiler/getFileSystem.d.ts +6 -0
- package/types-legacy/ts4.5/contract/ga.d.ts +44 -0
- package/types-legacy/ts4.5/index-browser.d.ts +39 -0
- package/types-legacy/ts4.5/index.d.ts +4 -0
- package/types-legacy/ts4.5/oracle.d.ts +161 -0
- package/types-legacy/ts4.5/spend.d.ts +62 -0
- package/types-legacy/ts4.5/tx/builder/constants.d.ts +98 -0
- package/types-legacy/ts4.5/tx/builder/field-types/abi-version.d.ts +10 -0
- package/types-legacy/ts4.5/tx/builder/field-types/address.d.ts +21 -0
- package/types-legacy/ts4.5/tx/builder/field-types/array.d.ts +7 -0
- package/types-legacy/ts4.5/tx/builder/field-types/boolean.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +12 -0
- package/types-legacy/ts4.5/tx/builder/field-types/ct-version.d.ts +42 -0
- package/types-legacy/ts4.5/tx/builder/field-types/deposit.d.ts +14 -0
- package/types-legacy/ts4.5/tx/builder/field-types/encoded.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/entry.d.ts +11 -0
- package/types-legacy/ts4.5/tx/builder/field-types/enumeration.d.ts +7 -0
- package/types-legacy/ts4.5/tx/builder/field-types/fee.d.ts +20 -0
- package/types-legacy/ts4.5/tx/builder/field-types/field.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/gas-limit.d.ts +15 -0
- package/types-legacy/ts4.5/tx/builder/field-types/gas-price.d.ts +7 -0
- package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +129 -0
- package/types-legacy/ts4.5/tx/builder/field-types/mptree.d.ts +43 -0
- package/types-legacy/ts4.5/tx/builder/field-types/name-fee.d.ts +18 -0
- package/types-legacy/ts4.5/tx/builder/field-types/name-id.d.ts +11 -0
- package/types-legacy/ts4.5/tx/builder/field-types/name.d.ts +13 -0
- package/types-legacy/ts4.5/tx/builder/field-types/pointers.d.ts +26 -0
- package/types-legacy/ts4.5/tx/builder/field-types/raw.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/short-u-int-const.d.ts +5 -0
- package/types-legacy/ts4.5/tx/builder/field-types/short-u-int.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/string.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/u-int.d.ts +7 -0
- package/types-legacy/ts4.5/tx/builder/helpers.d.ts +112 -0
- package/types-legacy/ts4.5/tx/builder/index.d.ts +50 -0
- package/types-legacy/ts4.5/tx/builder/schema.d.ts +4675 -0
- package/types-legacy/ts4.5/tx/index.d.ts +19 -0
- package/types-legacy/ts4.5/tx/validator.d.ts +18 -0
- package/types-legacy/ts4.5/utils/amount-formatter.d.ts +42 -0
- package/types-legacy/ts4.5/utils/autorest.d.ts +7 -0
- package/types-legacy/ts4.5/utils/bignumber.d.ts +13 -0
- package/types-legacy/ts4.5/utils/bytes.d.ts +9 -0
- package/types-legacy/ts4.5/utils/crypto.d.ts +95 -0
- package/types-legacy/ts4.5/utils/encoder-types.d.ts +61 -0
- package/types-legacy/ts4.5/utils/encoder.d.ts +24 -0
- package/types-legacy/ts4.5/utils/errors.d.ts +475 -0
- package/types-legacy/ts4.5/utils/hd-wallet.d.ts +65 -0
- package/types-legacy/ts4.5/utils/json-big.d.ts +5 -0
- package/types-legacy/ts4.5/utils/keystore.d.ts +53 -0
- package/types-legacy/ts4.5/utils/other.d.ts +31 -0
- package/types-legacy/ts4.5/utils/semver-satisfies.d.ts +1 -0
- package/types-legacy/ts4.5/utils/string.d.ts +12 -0
- package/es/channel/index.d.ts +0 -625
- package/es/channel/index.mjs +0 -975
- package/es/channel/index.mjs.map +0 -1
- package/es/contract/Compiler.d.ts +0 -18
- package/es/contract/Compiler.mjs +0 -68
- package/es/contract/Compiler.mjs.map +0 -1
- package/es/contract/aci.d.ts +0 -127
- package/es/contract/aci.mjs +0 -508
- package/es/contract/aci.mjs.map +0 -1
- package/es/contract/methods.d.ts +0 -71
- package/es/contract/methods.mjs +0 -104
- package/es/contract/methods.mjs.map +0 -1
- package/es/deprecated/index.d.ts +0 -143
- package/es/deprecated/index.mjs +0 -162
- package/es/deprecated/index.mjs.map +0 -1
- package/es/deprecated/methods.d.ts +0 -18
- package/es/deprecated/methods.mjs +0 -26
- package/es/deprecated/methods.mjs.map +0 -1
- package/es/tx/builder/address.d.ts +0 -25
- package/es/tx/builder/address.mjs +0 -45
- package/es/tx/builder/address.mjs.map +0 -1
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +0 -1
- package/es/utils/mptree.d.ts +0 -26
- package/es/utils/mptree.mjs +0 -165
- package/es/utils/mptree.mjs.map +0 -1
- package/src/channel/index.ts +0 -1025
- package/src/contract/Compiler.ts +0 -67
- package/src/contract/aci.ts +0 -537
- package/src/contract/methods.ts +0 -123
- package/src/deprecated/index.ts +0 -172
- package/src/deprecated/methods.ts +0 -25
- package/src/tx/builder/address.ts +0 -50
- package/src/typings/@aeternity__argon2-browser/index.d.ts +0 -3
- package/src/utils/mptree.ts +0 -145
package/es/tx/validator.mjs
CHANGED
|
@@ -1,56 +1,40 @@
|
|
|
1
1
|
import _buffer from "buffer";
|
|
2
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
3
2
|
const {
|
|
4
3
|
Buffer: _Buffer
|
|
5
4
|
} = _buffer;
|
|
6
5
|
import BigNumber from 'bignumber.js';
|
|
7
6
|
import { hash, verify } from "../utils/crypto.mjs";
|
|
8
|
-
import {
|
|
7
|
+
import { ProtocolToVmAbi } from "./builder/field-types/ct-version.mjs";
|
|
9
8
|
import { Tag } from "./builder/constants.mjs";
|
|
10
|
-
import { unpackTx } from "./builder/index.mjs";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
9
|
+
import { buildTx, unpackTx } from "./builder/index.mjs";
|
|
10
|
+
import { concatBuffers, isAccountNotFoundError } from "../utils/other.mjs";
|
|
11
|
+
import { decode } from "../utils/encoder.mjs";
|
|
12
|
+
import Node from "../Node.mjs";
|
|
13
|
+
import { genAggressiveCacheGetResponsesPolicy } from "../utils/autorest.mjs";
|
|
14
14
|
const validators = [];
|
|
15
|
-
|
|
16
15
|
const getSenderAddress = tx => ['senderId', 'accountId', 'ownerId', 'callerId', 'oracleId', 'fromId', 'initiator', 'gaId', 'payerId'].map(key => tx[key]).filter(a => a).map(a => a === null || a === void 0 ? void 0 : a.toString().replace(/^ok_/, 'ak_'))[0];
|
|
17
|
-
|
|
18
|
-
* Transaction Validator
|
|
19
|
-
* This function validates some of transaction properties,
|
|
20
|
-
* to make sure it can be posted it to the chain
|
|
21
|
-
* @category transaction builder
|
|
22
|
-
* @param transaction - Base64Check-encoded transaction
|
|
23
|
-
* @param node - Node to validate transaction against
|
|
24
|
-
* @param parentTxTypes - Types of parent transactions
|
|
25
|
-
* @returns Array with verification errors
|
|
26
|
-
* @example const errors = await verifyTransaction(transaction, node)
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export default async function verifyTransaction(transaction, node) {
|
|
16
|
+
async function verifyTransactionInternal(tx, node, parentTxTypes) {
|
|
31
17
|
var _getSenderAddress;
|
|
32
|
-
|
|
33
|
-
let parentTxTypes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
34
|
-
const {
|
|
35
|
-
tx,
|
|
36
|
-
txType
|
|
37
|
-
} = unpackTx(transaction);
|
|
38
|
-
const address = (_getSenderAddress = getSenderAddress(tx)) !== null && _getSenderAddress !== void 0 ? _getSenderAddress : txType === Tag.SignedTx ? getSenderAddress(tx.encodedTx.tx) : undefined;
|
|
18
|
+
const address = (_getSenderAddress = getSenderAddress(tx)) !== null && _getSenderAddress !== void 0 ? _getSenderAddress : tx.tag === Tag.SignedTx ? getSenderAddress(tx.encodedTx) : undefined;
|
|
39
19
|
const [account, {
|
|
40
20
|
height
|
|
41
21
|
}, {
|
|
42
22
|
consensusProtocolVersion,
|
|
43
23
|
nodeNetworkId
|
|
44
|
-
}] = await Promise.all([address == null ? undefined : node.getAccountByPubkey(address).catch(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
24
|
+
}] = await Promise.all([address == null ? undefined : node.getAccountByPubkey(address).catch(error => {
|
|
25
|
+
if (!isAccountNotFoundError(error)) throw error;
|
|
26
|
+
return {
|
|
27
|
+
id: address,
|
|
28
|
+
balance: 0n,
|
|
29
|
+
nonce: 0
|
|
30
|
+
};
|
|
31
|
+
})
|
|
32
|
+
// TODO: remove after fixing https://github.com/aeternity/aepp-sdk-js/issues/1537
|
|
33
|
+
.then(acc => ({
|
|
34
|
+
...acc,
|
|
50
35
|
id: acc.id
|
|
51
36
|
})), node.getCurrentKeyBlockHeight(), node.getNodeInfo()]);
|
|
52
37
|
return (await Promise.all(validators.map(v => v(tx, {
|
|
53
|
-
txType,
|
|
54
38
|
node,
|
|
55
39
|
account,
|
|
56
40
|
height,
|
|
@@ -59,6 +43,24 @@ export default async function verifyTransaction(transaction, node) {
|
|
|
59
43
|
parentTxTypes
|
|
60
44
|
})))).flat();
|
|
61
45
|
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Transaction Validator
|
|
49
|
+
* This function validates some transaction properties,
|
|
50
|
+
* to make sure it can be posted it to the chain
|
|
51
|
+
* @category transaction builder
|
|
52
|
+
* @param transaction - Base64Check-encoded transaction
|
|
53
|
+
* @param nodeNotCached - Node to validate transaction against
|
|
54
|
+
* @returns Array with verification errors
|
|
55
|
+
* @example const errors = await verifyTransaction(transaction, node)
|
|
56
|
+
*/
|
|
57
|
+
export default async function verifyTransaction(transaction, nodeNotCached) {
|
|
58
|
+
const node = new Node(nodeNotCached.$host, {
|
|
59
|
+
ignoreVersion: true
|
|
60
|
+
});
|
|
61
|
+
node.pipeline.addPolicy(genAggressiveCacheGetResponsesPolicy());
|
|
62
|
+
return verifyTransactionInternal(unpackTx(transaction), node, []);
|
|
63
|
+
}
|
|
62
64
|
validators.push((_ref, _ref2) => {
|
|
63
65
|
let {
|
|
64
66
|
encodedTx,
|
|
@@ -69,16 +71,14 @@ validators.push((_ref, _ref2) => {
|
|
|
69
71
|
nodeNetworkId,
|
|
70
72
|
parentTxTypes
|
|
71
73
|
} = _ref2;
|
|
72
|
-
if ((encodedTx !== null && encodedTx !== void 0 ? encodedTx : signatures)
|
|
74
|
+
if ((encodedTx !== null && encodedTx !== void 0 ? encodedTx : signatures) == null) return [];
|
|
73
75
|
if (account == null) return [];
|
|
74
|
-
if (signatures.length !== 1) return []; // TODO: Support multisignature
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
const decodedPub = decode(account.id);
|
|
81
|
-
if (verify(txWithNetworkId, signatures[0], decodedPub) || verify(txHashWithNetworkId, signatures[0], decodedPub)) return [];
|
|
76
|
+
if (signatures.length !== 1) return []; // TODO: Support multisignature like in state channels
|
|
77
|
+
const prefix = _Buffer.from([nodeNetworkId, ...(parentTxTypes.includes(Tag.PayingForTx) ? ['inner_tx'] : [])].join('-'));
|
|
78
|
+
const txBinary = decode(buildTx(encodedTx));
|
|
79
|
+
const txWithNetworkId = concatBuffers([prefix, txBinary]);
|
|
80
|
+
const txHashWithNetworkId = concatBuffers([prefix, hash(txBinary)]);
|
|
81
|
+
if (verify(txWithNetworkId, signatures[0], account.id) || verify(txHashWithNetworkId, signatures[0], account.id)) return [];
|
|
82
82
|
return [{
|
|
83
83
|
message: 'Signature cannot be verified, please ensure that you transaction have' + ' the correct prefix and the correct private key for the sender address',
|
|
84
84
|
key: 'InvalidSignature',
|
|
@@ -87,15 +87,15 @@ validators.push((_ref, _ref2) => {
|
|
|
87
87
|
}, async (_ref3, _ref4) => {
|
|
88
88
|
let {
|
|
89
89
|
encodedTx,
|
|
90
|
-
tx
|
|
90
|
+
tx,
|
|
91
|
+
tag
|
|
91
92
|
} = _ref3;
|
|
92
93
|
let {
|
|
93
94
|
node,
|
|
94
|
-
parentTxTypes
|
|
95
|
-
txType
|
|
95
|
+
parentTxTypes
|
|
96
96
|
} = _ref4;
|
|
97
|
-
if ((encodedTx !== null && encodedTx !== void 0 ? encodedTx : tx)
|
|
98
|
-
return
|
|
97
|
+
if ((encodedTx !== null && encodedTx !== void 0 ? encodedTx : tx) == null) return [];
|
|
98
|
+
return verifyTransactionInternal(encodedTx !== null && encodedTx !== void 0 ? encodedTx : tx, node, [...parentTxTypes, tag]);
|
|
99
99
|
}, (_ref5, _ref6) => {
|
|
100
100
|
let {
|
|
101
101
|
ttl
|
|
@@ -103,7 +103,7 @@ validators.push((_ref, _ref2) => {
|
|
|
103
103
|
let {
|
|
104
104
|
height
|
|
105
105
|
} = _ref6;
|
|
106
|
-
if (ttl
|
|
106
|
+
if (ttl == null) return [];
|
|
107
107
|
ttl = +ttl;
|
|
108
108
|
if (ttl === 0 || ttl >= height) return [];
|
|
109
109
|
return [{
|
|
@@ -113,22 +113,21 @@ validators.push((_ref, _ref2) => {
|
|
|
113
113
|
}];
|
|
114
114
|
}, (_ref7, _ref8) => {
|
|
115
115
|
var _ref9, _fee;
|
|
116
|
-
|
|
117
116
|
let {
|
|
118
117
|
amount,
|
|
119
118
|
fee,
|
|
120
119
|
nameFee,
|
|
121
|
-
tx
|
|
120
|
+
tx,
|
|
121
|
+
tag
|
|
122
122
|
} = _ref7;
|
|
123
123
|
let {
|
|
124
124
|
account,
|
|
125
|
-
parentTxTypes
|
|
126
|
-
txType
|
|
125
|
+
parentTxTypes
|
|
127
126
|
} = _ref8;
|
|
128
127
|
if (account == null) return [];
|
|
129
|
-
if (((_ref9 = amount !== null && amount !== void 0 ? amount : fee) !== null && _ref9 !== void 0 ? _ref9 : nameFee)
|
|
128
|
+
if (((_ref9 = amount !== null && amount !== void 0 ? amount : fee) !== null && _ref9 !== void 0 ? _ref9 : nameFee) == null) return [];
|
|
130
129
|
(_fee = fee) !== null && _fee !== void 0 ? _fee : fee = 0;
|
|
131
|
-
const cost = new BigNumber(fee).plus(nameFee !== null && nameFee !== void 0 ? nameFee : 0).plus(amount !== null && amount !== void 0 ? amount : 0).plus(
|
|
130
|
+
const cost = new BigNumber(fee).plus(nameFee !== null && nameFee !== void 0 ? nameFee : 0).plus(amount !== null && amount !== void 0 ? amount : 0).plus(tag === Tag.PayingForTx ? tx.encodedTx.fee : 0).minus(parentTxTypes.includes(Tag.PayingForTx) ? fee : 0);
|
|
132
131
|
if (cost.lte(account.balance.toString())) return [];
|
|
133
132
|
return [{
|
|
134
133
|
message: `Account balance ${account.balance.toString()} is not enough to execute the transaction that costs ${cost.toFixed()}`,
|
|
@@ -137,17 +136,40 @@ validators.push((_ref, _ref2) => {
|
|
|
137
136
|
}];
|
|
138
137
|
}, (_ref10, _ref11) => {
|
|
139
138
|
let {
|
|
140
|
-
|
|
139
|
+
signatures,
|
|
140
|
+
tag
|
|
141
141
|
} = _ref10;
|
|
142
|
+
let {
|
|
143
|
+
account
|
|
144
|
+
} = _ref11;
|
|
145
|
+
if (account == null) return [];
|
|
146
|
+
let message;
|
|
147
|
+
if (tag === Tag.SignedTx && account.kind === 'generalized' && signatures.length !== 0) {
|
|
148
|
+
message = 'Generalized account can\'t be used to generate SignedTx with signatures';
|
|
149
|
+
}
|
|
150
|
+
if (tag === Tag.GaMetaTx && account.kind === 'basic') {
|
|
151
|
+
message = 'Basic account can\'t be used to generate GaMetaTx';
|
|
152
|
+
}
|
|
153
|
+
if (message == null) return [];
|
|
154
|
+
return [{
|
|
155
|
+
message,
|
|
156
|
+
key: 'InvalidAccountType',
|
|
157
|
+
checkedKeys: ['tag']
|
|
158
|
+
}];
|
|
159
|
+
}, (_ref12, _ref13) => {
|
|
160
|
+
let {
|
|
161
|
+
nonce
|
|
162
|
+
} = _ref12;
|
|
142
163
|
let {
|
|
143
164
|
account,
|
|
144
165
|
parentTxTypes
|
|
145
|
-
} =
|
|
146
|
-
if (nonce == null || account == null ||
|
|
166
|
+
} = _ref13;
|
|
167
|
+
if (nonce == null || account == null || parentTxTypes.includes(Tag.GaMetaTx)) return [];
|
|
147
168
|
nonce = +nonce;
|
|
148
169
|
const validNonce = account.nonce + 1;
|
|
149
170
|
if (nonce === validNonce) return [];
|
|
150
|
-
return [{
|
|
171
|
+
return [{
|
|
172
|
+
...(nonce < validNonce ? {
|
|
151
173
|
message: `Nonce ${nonce} is already used, valid nonce is ${validNonce}`,
|
|
152
174
|
key: 'NonceAlreadyUsed'
|
|
153
175
|
} : {
|
|
@@ -156,53 +178,46 @@ validators.push((_ref, _ref2) => {
|
|
|
156
178
|
}),
|
|
157
179
|
checkedKeys: ['nonce']
|
|
158
180
|
}];
|
|
159
|
-
}, (
|
|
181
|
+
}, (_ref14, _ref15) => {
|
|
182
|
+
var _ref16, _ref17;
|
|
160
183
|
let {
|
|
161
184
|
ctVersion,
|
|
162
|
-
abiVersion
|
|
163
|
-
|
|
185
|
+
abiVersion,
|
|
186
|
+
tag
|
|
187
|
+
} = _ref14;
|
|
164
188
|
let {
|
|
165
|
-
txType,
|
|
166
189
|
consensusProtocolVersion
|
|
167
|
-
} =
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
190
|
+
} = _ref15;
|
|
191
|
+
const oracleCall = Tag.Oracle === tag || Tag.OracleRegisterTx === tag;
|
|
192
|
+
const contractCreate = Tag.ContractCreateTx === tag || Tag.GaAttachTx === tag;
|
|
193
|
+
const contractCall = Tag.ContractCallTx === tag || Tag.GaMetaTx === tag;
|
|
194
|
+
const type = (_ref16 = (_ref17 = oracleCall ? 'oracle-call' : null) !== null && _ref17 !== void 0 ? _ref17 : contractCreate ? 'contract-create' : null) !== null && _ref16 !== void 0 ? _ref16 : contractCall ? 'contract-call' : null;
|
|
195
|
+
if (type == null) return [];
|
|
196
|
+
// TODO: remove assertion after fixing buildTx types
|
|
197
|
+
const protocol = ProtocolToVmAbi[consensusProtocolVersion][type];
|
|
174
198
|
|
|
199
|
+
// If not contract create tx
|
|
175
200
|
if (ctVersion == null) ctVersion = {
|
|
176
201
|
abiVersion
|
|
177
202
|
};
|
|
178
|
-
|
|
179
|
-
if (txProtocol == null) return [];
|
|
180
|
-
|
|
181
|
-
if (Object.entries(ctVersion).some(_ref14 => {
|
|
182
|
-
var _context;
|
|
183
|
-
|
|
184
|
-
let [key, value] = _ref14;
|
|
185
|
-
return !_includesInstanceProperty(_context = txProtocol[key]).call(_context, +value);
|
|
186
|
-
})) {
|
|
203
|
+
if (!protocol.abiVersion.includes(ctVersion.abiVersion) || contractCreate && !protocol.vmVersion.includes(ctVersion.vmVersion)) {
|
|
187
204
|
return [{
|
|
188
|
-
message: `ABI/VM version ${JSON.stringify(ctVersion)} is wrong, supported is: ${JSON.stringify(
|
|
205
|
+
message: `ABI/VM version ${JSON.stringify(ctVersion)} is wrong, supported is: ${JSON.stringify(protocol)}`,
|
|
189
206
|
key: 'VmAndAbiVersionMismatch',
|
|
190
207
|
checkedKeys: ['ctVersion', 'abiVersion']
|
|
191
208
|
}];
|
|
192
209
|
}
|
|
193
|
-
|
|
194
210
|
return [];
|
|
195
|
-
}, async (
|
|
211
|
+
}, async (_ref18, _ref19) => {
|
|
196
212
|
let {
|
|
197
|
-
contractId
|
|
198
|
-
|
|
213
|
+
contractId,
|
|
214
|
+
tag
|
|
215
|
+
} = _ref18;
|
|
199
216
|
let {
|
|
200
|
-
txType,
|
|
201
217
|
node
|
|
202
|
-
} =
|
|
203
|
-
if (Tag.ContractCallTx !==
|
|
218
|
+
} = _ref19;
|
|
219
|
+
if (Tag.ContractCallTx !== tag) return [];
|
|
204
220
|
contractId = contractId;
|
|
205
|
-
|
|
206
221
|
try {
|
|
207
222
|
const {
|
|
208
223
|
active
|
|
@@ -215,7 +230,6 @@ validators.push((_ref, _ref2) => {
|
|
|
215
230
|
}];
|
|
216
231
|
} catch (error) {
|
|
217
232
|
var _error$response, _error$response$parse;
|
|
218
|
-
|
|
219
233
|
if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : (_error$response$parse = _error$response.parsedBody) === null || _error$response$parse === void 0 ? void 0 : _error$response$parse.reason) == null) throw error;
|
|
220
234
|
return [{
|
|
221
235
|
message: error.response.parsedBody.reason,
|
package/es/tx/validator.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.mjs","names":["BigNumber","hash","verify","PROTOCOL_VM_ABI","Tag","unpackTx","UnsupportedProtocolError","concatBuffers","isKeyOfObject","decode","encode","Encoding","validators","getSenderAddress","tx","map","key","filter","a","toString","replace","verifyTransaction","transaction","node","parentTxTypes","txType","address","SignedTx","encodedTx","undefined","account","height","consensusProtocolVersion","nodeNetworkId","Promise","all","getAccountByPubkey","catch","id","balance","nonce","then","acc","getCurrentKeyBlockHeight","getNodeInfo","v","flat","push","signatures","length","prefix","from","PayingForTx","join","txWithNetworkId","rlpEncoded","txHashWithNetworkId","decodedPub","message","checkedKeys","Transaction","ttl","amount","fee","nameFee","cost","plus","minus","lte","toFixed","GaMetaTx","validNonce","ctVersion","abiVersion","protocol","txProtocol","Object","entries","some","value","JSON","stringify","contractId","ContractCallTx","active","getContract","error","response","parsedBody","reason"],"sources":["../../src/tx/validator.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { hash, verify } from '../utils/crypto';\nimport {\n CtVersion,\n PROTOCOL_VM_ABI,\n RawTxObject,\n TxParamsCommon,\n TxSchema,\n TxTypeSchemas,\n} from './builder/schema';\nimport { Tag } from './builder/constants';\nimport { TxUnpacked, unpackTx } from './builder';\nimport { UnsupportedProtocolError } from '../utils/errors';\nimport { concatBuffers, isKeyOfObject } from '../utils/other';\nimport {\n decode, encode, Encoded, Encoding,\n} from '../utils/encoder';\nimport Node from '../Node';\n\ninterface Account {\n balance: bigint;\n id: Encoded.AccountAddress;\n nonce: number;\n}\n\nexport interface ValidatorResult {\n message: string;\n key: string;\n checkedKeys: string[];\n}\n\ntype Validator = (\n tx: {\n encodedTx: TxUnpacked<TxSchema>;\n signatures: Buffer[];\n tx: TxUnpacked<TxSchema> & {\n tx: TxTypeSchemas[Tag.SignedTx];\n };\n nonce?: number;\n ttl?: number;\n amount?: number;\n fee?: number;\n nameFee?: number;\n ctVersion?: Partial<CtVersion>;\n abiVersion?: number;\n contractId?: Encoded.ContractAddress;\n },\n options: {\n account?: Account;\n nodeNetworkId: string;\n parentTxTypes: Tag[];\n node: Node;\n txType: Tag;\n height: number;\n consensusProtocolVersion: number;\n }\n) => ValidatorResult[] | Promise<ValidatorResult[]>;\n\nconst validators: Validator[] = [];\n\nconst getSenderAddress = (\n tx: TxParamsCommon | RawTxObject<TxSchema>,\n): Encoded.AccountAddress | undefined => [\n 'senderId', 'accountId', 'ownerId', 'callerId',\n 'oracleId', 'fromId', 'initiator', 'gaId', 'payerId',\n]\n .map((key: keyof TxSchema) => tx[key])\n .filter((a) => a)\n .map((a) => a?.toString().replace(/^ok_/, 'ak_'))[0] as Encoded.AccountAddress | undefined;\n\n/**\n * Transaction Validator\n * This function validates some of transaction properties,\n * to make sure it can be posted it to the chain\n * @category transaction builder\n * @param transaction - Base64Check-encoded transaction\n * @param node - Node to validate transaction against\n * @param parentTxTypes - Types of parent transactions\n * @returns Array with verification errors\n * @example const errors = await verifyTransaction(transaction, node)\n */\nexport default async function verifyTransaction(\n transaction: Encoded.Transaction | Encoded.Poi,\n node: Node,\n parentTxTypes: Tag[] = [],\n): Promise<ValidatorResult[]> {\n const { tx, txType } = unpackTx<Tag.SignedTx>(transaction);\n const address = getSenderAddress(tx)\n ?? (txType === Tag.SignedTx ? getSenderAddress(tx.encodedTx.tx) : undefined);\n const [account, { height }, { consensusProtocolVersion, nodeNetworkId }] = await Promise.all([\n address == null\n ? undefined\n : node.getAccountByPubkey(address)\n .catch(() => ({ id: address, balance: 0n, nonce: 0 }))\n // TODO: remove after fixing https://github.com/aeternity/aepp-sdk-js/issues/1537\n .then((acc) => ({ ...acc, id: acc.id as Encoded.AccountAddress })),\n node.getCurrentKeyBlockHeight(),\n node.getNodeInfo(),\n ]);\n\n return (await Promise.all(\n validators.map((v) => v(\n tx as any,\n {\n txType, node, account, height, consensusProtocolVersion, nodeNetworkId, parentTxTypes,\n },\n )),\n )).flat();\n}\n\nvalidators.push(\n ({ encodedTx, signatures }, { account, nodeNetworkId, parentTxTypes }) => {\n if ((encodedTx ?? signatures) === undefined) return [];\n if (account == null) return [];\n if (signatures.length !== 1) return []; // TODO: Support multisignature?\n const prefix = Buffer.from([\n nodeNetworkId,\n ...parentTxTypes.includes(Tag.PayingForTx) ? ['inner_tx'] : [],\n ].join('-'));\n const txWithNetworkId = concatBuffers([prefix, encodedTx.rlpEncoded]);\n const txHashWithNetworkId = concatBuffers([prefix, hash(encodedTx.rlpEncoded)]);\n const decodedPub = decode(account.id);\n if (verify(txWithNetworkId, signatures[0], decodedPub)\n || verify(txHashWithNetworkId, signatures[0], decodedPub)) return [];\n return [{\n message: 'Signature cannot be verified, please ensure that you transaction have'\n + ' the correct prefix and the correct private key for the sender address',\n key: 'InvalidSignature',\n checkedKeys: ['encodedTx', 'signatures'],\n }];\n },\n async ({ encodedTx, tx }, { node, parentTxTypes, txType }) => {\n if ((encodedTx ?? tx) === undefined) return [];\n return verifyTransaction(\n encode((encodedTx ?? tx).rlpEncoded, Encoding.Transaction),\n node,\n [...parentTxTypes, txType],\n );\n },\n ({ ttl }, { height }) => {\n if (ttl === undefined) return [];\n ttl = +ttl;\n if (ttl === 0 || ttl >= height) return [];\n return [{\n message: `TTL ${ttl} is already expired, current height is ${height}`,\n key: 'ExpiredTTL',\n checkedKeys: ['ttl'],\n }];\n },\n ({\n amount, fee, nameFee, tx,\n }, { account, parentTxTypes, txType }) => {\n if (account == null) return [];\n if ((amount ?? fee ?? nameFee) === undefined) return [];\n fee ??= 0;\n const cost = new BigNumber(fee).plus(nameFee ?? 0).plus(amount ?? 0)\n .plus(txType === Tag.PayingForTx ? (tx.tx.encodedTx.tx).fee : 0)\n .minus(parentTxTypes.includes(Tag.PayingForTx) ? fee : 0);\n if (cost.lte(account.balance.toString())) return [];\n return [{\n message: `Account balance ${account.balance.toString()} is not enough to execute the transaction that costs ${cost.toFixed()}`,\n key: 'InsufficientBalance',\n checkedKeys: ['amount', 'fee', 'nameFee'],\n }];\n },\n ({ nonce }, { account, parentTxTypes }) => {\n if (nonce == null || account == null || parentTxTypes.includes(Tag.GaMetaTx)) return [];\n nonce = +nonce;\n const validNonce = account.nonce + 1;\n if (nonce === validNonce) return [];\n return [{\n ...nonce < validNonce\n ? {\n message: `Nonce ${nonce} is already used, valid nonce is ${validNonce}`,\n key: 'NonceAlreadyUsed',\n }\n : {\n message: `Nonce ${nonce} is too high, valid nonce is ${validNonce}`,\n key: 'NonceHigh',\n },\n checkedKeys: ['nonce'],\n }];\n },\n ({ ctVersion, abiVersion }, { txType, consensusProtocolVersion }) => {\n if (!isKeyOfObject(consensusProtocolVersion, PROTOCOL_VM_ABI)) {\n throw new UnsupportedProtocolError(`Unsupported protocol: ${consensusProtocolVersion}`);\n }\n const protocol = PROTOCOL_VM_ABI[consensusProtocolVersion];\n\n // If not contract create tx\n if (ctVersion == null) ctVersion = { abiVersion };\n const txProtocol = protocol[txType as keyof typeof protocol];\n if (txProtocol == null) return [];\n if (Object.entries(ctVersion).some(\n ([\n key,\n value,\n ]: [\n key:keyof typeof txProtocol,\n value:any]) => !(txProtocol[key].includes(+value as never)),\n )) {\n return [{\n message: `ABI/VM version ${JSON.stringify(ctVersion)} is wrong, supported is: ${JSON.stringify(txProtocol)}`,\n key: 'VmAndAbiVersionMismatch',\n checkedKeys: ['ctVersion', 'abiVersion'],\n }];\n }\n return [];\n },\n async ({ contractId }, { txType, node }) => {\n if (Tag.ContractCallTx !== txType) return [];\n contractId = contractId as Encoded.ContractAddress;\n try {\n const { active } = await node.getContract(contractId);\n if (active) return [];\n return [{\n message: `Contract ${contractId} is not active`,\n key: 'ContractNotActive',\n checkedKeys: ['contractId'],\n }];\n } catch (error) {\n if (error.response?.parsedBody?.reason == null) throw error;\n return [{\n message: error.response.parsedBody.reason,\n key: 'ContractNotFound',\n checkedKeys: ['contractId'],\n }];\n }\n },\n);\n"],"mappings":";;;;;AAAA,OAAOA,SAAP,MAAsB,cAAtB;SACSC,I,EAAMC,M;SAGbC,e;SAMOC,G;SACYC,Q;SACZC,wB;SACAC,a,EAAeC,a;SAEtBC,M,EAAQC,M,EAAiBC,Q;AA2C3B,MAAMC,UAAuB,GAAG,EAAhC;;AAEA,MAAMC,gBAAgB,GACpBC,EADuB,IAEgB,CACvC,UADuC,EAC3B,WAD2B,EACd,SADc,EACH,UADG,EAEvC,UAFuC,EAE3B,QAF2B,EAEjB,WAFiB,EAEJ,MAFI,EAEI,SAFJ,EAItCC,GAJsC,CAIjCC,GAAD,IAAyBF,EAAE,CAACE,GAAD,CAJO,EAKtCC,MALsC,CAK9BC,CAAD,IAAOA,CALwB,EAMtCH,GANsC,CAMjCG,CAAD,IAAOA,CAAP,aAAOA,CAAP,uBAAOA,CAAC,CAAEC,QAAH,GAAcC,OAAd,CAAsB,MAAtB,EAA8B,KAA9B,CAN2B,EAMW,CANX,CAFzC;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAe,eAAeC,iBAAf,CACbC,WADa,EAEbC,IAFa,EAIe;EAAA;;EAAA,IAD5BC,aAC4B,uEADL,EACK;EAC5B,MAAM;IAAEV,EAAF;IAAMW;EAAN,IAAiBpB,QAAQ,CAAeiB,WAAf,CAA/B;EACA,MAAMI,OAAO,wBAAGb,gBAAgB,CAACC,EAAD,CAAnB,iEACPW,MAAM,KAAKrB,GAAG,CAACuB,QAAf,GAA0Bd,gBAAgB,CAACC,EAAE,CAACc,SAAH,CAAad,EAAd,CAA1C,GAA8De,SAD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N1B,OAAO,EAAG,YAAWwB,UAAW,gBAD1B;MAENlE,GAAG,EAAE,mBAFC;MAGN2C,WAAW,EAAE,CAAC,YAAD;IAHP,CAAD,CAAP;EAKD,CARD,CAQE,OAAO2B,KAAP,EAAc;IAAA;;IACd,IAAI,oBAAAA,KAAK,CAACC,QAAN,6FAAgBC,UAAhB,gFAA4BC,MAA5B,KAAsC,IAA1C,EAAgD,MAAMH,KAAN;IAChD,OAAO,CAAC;MACN5B,OAAO,EAAE4B,KAAK,CAACC,QAAN,CAAeC,UAAf,CAA0BC,MAD7B;MAENzE,GAAG,EAAE,kBAFC;MAGN2C,WAAW,EAAE,CAAC,YAAD;IAHP,CAAD,CAAP;EAKD;AACF,CAtHH"}
|
|
1
|
+
{"version":3,"file":"validator.mjs","names":["BigNumber","hash","verify","ProtocolToVmAbi","Tag","buildTx","unpackTx","concatBuffers","isAccountNotFoundError","decode","Node","genAggressiveCacheGetResponsesPolicy","validators","getSenderAddress","tx","map","key","filter","a","toString","replace","verifyTransactionInternal","node","parentTxTypes","address","tag","SignedTx","encodedTx","undefined","account","height","consensusProtocolVersion","nodeNetworkId","Promise","all","getAccountByPubkey","catch","error","id","balance","nonce","then","acc","getCurrentKeyBlockHeight","getNodeInfo","v","flat","verifyTransaction","transaction","nodeNotCached","$host","ignoreVersion","pipeline","addPolicy","push","signatures","length","prefix","from","includes","PayingForTx","join","txBinary","txWithNetworkId","txHashWithNetworkId","message","checkedKeys","ttl","amount","fee","nameFee","cost","plus","minus","lte","toFixed","kind","GaMetaTx","validNonce","ctVersion","abiVersion","oracleCall","Oracle","OracleRegisterTx","contractCreate","ContractCreateTx","GaAttachTx","contractCall","ContractCallTx","type","protocol","vmVersion","JSON","stringify","contractId","active","getContract","response","parsedBody","reason"],"sources":["../../src/tx/validator.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { hash, verify } from '../utils/crypto';\nimport { RawTxObject, TxParamsCommon, TxSchema } from './builder/schema';\nimport { ProtocolToVmAbi } from './builder/field-types/ct-version';\nimport { Tag, ConsensusProtocolVersion } from './builder/constants';\nimport { buildTx, unpackTx } from './builder';\nimport { concatBuffers, isAccountNotFoundError } from '../utils/other';\nimport { Encoded, decode } from '../utils/encoder';\nimport Node, { TransformNodeType } from '../Node';\nimport { Account } from '../apis/node';\nimport { genAggressiveCacheGetResponsesPolicy } from '../utils/autorest';\n\nexport interface ValidatorResult {\n message: string;\n key: string;\n checkedKeys: string[];\n}\n\ntype UnpackedTx = ReturnType<typeof unpackTx>['tx'];\n\ntype Validator = (\n tx: UnpackedTx,\n options: {\n // TODO: remove after fixing node types\n account?: TransformNodeType<Account> & { id: Encoded.AccountAddress };\n nodeNetworkId: string;\n parentTxTypes: Tag[];\n node: Node;\n height: number;\n consensusProtocolVersion: ConsensusProtocolVersion;\n }\n) => ValidatorResult[] | Promise<ValidatorResult[]>;\n\nconst validators: Validator[] = [];\n\nconst getSenderAddress = (\n tx: TxParamsCommon | RawTxObject<TxSchema>,\n): Encoded.AccountAddress | undefined => [\n 'senderId', 'accountId', 'ownerId', 'callerId',\n 'oracleId', 'fromId', 'initiator', 'gaId', 'payerId',\n]\n .map((key: keyof TxSchema) => tx[key])\n .filter((a) => a)\n .map((a) => a?.toString().replace(/^ok_/, 'ak_'))[0] as Encoded.AccountAddress | undefined;\n\nasync function verifyTransactionInternal(\n tx: UnpackedTx,\n node: Node,\n parentTxTypes: Tag[],\n): Promise<ValidatorResult[]> {\n const address = getSenderAddress(tx)\n ?? (tx.tag === Tag.SignedTx ? getSenderAddress(tx.encodedTx) : undefined);\n const [account, { height }, { consensusProtocolVersion, nodeNetworkId }] = await Promise.all([\n address == null\n ? undefined\n : node.getAccountByPubkey(address)\n .catch((error) => {\n if (!isAccountNotFoundError(error)) throw error;\n return { id: address, balance: 0n, nonce: 0 };\n })\n // TODO: remove after fixing https://github.com/aeternity/aepp-sdk-js/issues/1537\n .then((acc) => ({ ...acc, id: acc.id as Encoded.AccountAddress })),\n node.getCurrentKeyBlockHeight(),\n node.getNodeInfo(),\n ]);\n\n return (await Promise.all(\n validators.map((v) => v(\n tx,\n {\n node, account, height, consensusProtocolVersion, nodeNetworkId, parentTxTypes,\n },\n )),\n )).flat();\n}\n\n/**\n * Transaction Validator\n * This function validates some transaction properties,\n * to make sure it can be posted it to the chain\n * @category transaction builder\n * @param transaction - Base64Check-encoded transaction\n * @param nodeNotCached - Node to validate transaction against\n * @returns Array with verification errors\n * @example const errors = await verifyTransaction(transaction, node)\n */\nexport default async function verifyTransaction(\n transaction: Parameters<typeof unpackTx>[0],\n nodeNotCached: Node,\n): Promise<ValidatorResult[]> {\n const node = new Node(nodeNotCached.$host, { ignoreVersion: true });\n node.pipeline.addPolicy(genAggressiveCacheGetResponsesPolicy());\n return verifyTransactionInternal(unpackTx(transaction), node, []);\n}\n\nvalidators.push(\n ({ encodedTx, signatures }, { account, nodeNetworkId, parentTxTypes }) => {\n if ((encodedTx ?? signatures) == null) return [];\n if (account == null) return [];\n if (signatures.length !== 1) return []; // TODO: Support multisignature like in state channels\n const prefix = Buffer.from([\n nodeNetworkId,\n ...parentTxTypes.includes(Tag.PayingForTx) ? ['inner_tx'] : [],\n ].join('-'));\n const txBinary = decode(buildTx(encodedTx));\n const txWithNetworkId = concatBuffers([prefix, txBinary]);\n const txHashWithNetworkId = concatBuffers([prefix, hash(txBinary)]);\n if (verify(txWithNetworkId, signatures[0], account.id)\n || verify(txHashWithNetworkId, signatures[0], account.id)) return [];\n return [{\n message: 'Signature cannot be verified, please ensure that you transaction have'\n + ' the correct prefix and the correct private key for the sender address',\n key: 'InvalidSignature',\n checkedKeys: ['encodedTx', 'signatures'],\n }];\n },\n async ({ encodedTx, tx, tag }, { node, parentTxTypes }) => {\n if ((encodedTx ?? tx) == null) return [];\n return verifyTransactionInternal(encodedTx ?? tx, node, [...parentTxTypes, tag]);\n },\n ({ ttl }, { height }) => {\n if (ttl == null) return [];\n ttl = +ttl;\n if (ttl === 0 || ttl >= height) return [];\n return [{\n message: `TTL ${ttl} is already expired, current height is ${height}`,\n key: 'ExpiredTTL',\n checkedKeys: ['ttl'],\n }];\n },\n ({\n amount, fee, nameFee, tx, tag,\n }, { account, parentTxTypes }) => {\n if (account == null) return [];\n if ((amount ?? fee ?? nameFee) == null) return [];\n fee ??= 0;\n const cost = new BigNumber(fee).plus(nameFee ?? 0).plus(amount ?? 0)\n .plus(tag === Tag.PayingForTx ? tx.encodedTx.fee : 0)\n .minus(parentTxTypes.includes(Tag.PayingForTx) ? fee : 0);\n if (cost.lte(account.balance.toString())) return [];\n return [{\n message: `Account balance ${account.balance.toString()} is not enough to execute the transaction that costs ${cost.toFixed()}`,\n key: 'InsufficientBalance',\n checkedKeys: ['amount', 'fee', 'nameFee'],\n }];\n },\n ({ signatures, tag }, { account }) => {\n if (account == null) return [];\n let message;\n if (tag === Tag.SignedTx && account.kind === 'generalized' && signatures.length !== 0) {\n message = 'Generalized account can\\'t be used to generate SignedTx with signatures';\n }\n if (tag === Tag.GaMetaTx && account.kind === 'basic') {\n message = 'Basic account can\\'t be used to generate GaMetaTx';\n }\n if (message == null) return [];\n return [{ message, key: 'InvalidAccountType', checkedKeys: ['tag'] }];\n },\n ({ nonce }, { account, parentTxTypes }) => {\n if (nonce == null || account == null || parentTxTypes.includes(Tag.GaMetaTx)) return [];\n nonce = +nonce;\n const validNonce = account.nonce + 1;\n if (nonce === validNonce) return [];\n return [{\n ...nonce < validNonce\n ? {\n message: `Nonce ${nonce} is already used, valid nonce is ${validNonce}`,\n key: 'NonceAlreadyUsed',\n }\n : {\n message: `Nonce ${nonce} is too high, valid nonce is ${validNonce}`,\n key: 'NonceHigh',\n },\n checkedKeys: ['nonce'],\n }];\n },\n ({ ctVersion, abiVersion, tag }, { consensusProtocolVersion }) => {\n const oracleCall = Tag.Oracle === tag || Tag.OracleRegisterTx === tag;\n const contractCreate = Tag.ContractCreateTx === tag || Tag.GaAttachTx === tag;\n const contractCall = Tag.ContractCallTx === tag || Tag.GaMetaTx === tag;\n const type = (oracleCall ? 'oracle-call' : null)\n ?? (contractCreate ? 'contract-create' : null)\n ?? (contractCall ? 'contract-call' : null);\n if (type == null) return [];\n // TODO: remove assertion after fixing buildTx types\n const protocol = ProtocolToVmAbi[consensusProtocolVersion][type] as unknown as {\n abiVersion: any[];\n vmVersion: any[];\n };\n\n // If not contract create tx\n if (ctVersion == null) ctVersion = { abiVersion };\n if (\n !protocol.abiVersion.includes(ctVersion.abiVersion)\n || (contractCreate && !protocol.vmVersion.includes(ctVersion.vmVersion))\n ) {\n return [{\n message: `ABI/VM version ${JSON.stringify(ctVersion)} is wrong, supported is: ${JSON.stringify(protocol)}`,\n key: 'VmAndAbiVersionMismatch',\n checkedKeys: ['ctVersion', 'abiVersion'],\n }];\n }\n return [];\n },\n async ({ contractId, tag }, { node }) => {\n if (Tag.ContractCallTx !== tag) return [];\n contractId = contractId as Encoded.ContractAddress;\n try {\n const { active } = await node.getContract(contractId);\n if (active) return [];\n return [{\n message: `Contract ${contractId} is not active`,\n key: 'ContractNotActive',\n checkedKeys: ['contractId'],\n }];\n } catch (error) {\n if (error.response?.parsedBody?.reason == null) throw error;\n return [{\n message: error.response.parsedBody.reason,\n key: 'ContractNotFound',\n checkedKeys: ['contractId'],\n }];\n }\n },\n);\n"],"mappings":";;;;AAAA,OAAOA,SAAS,MAAM,cAAc;AAAC,SAC5BC,IAAI,EAAEC,MAAM;AAAA,SAEZC,eAAe;AAAA,SACfC,GAAG;AAAA,SACHC,OAAO,EAAEC,QAAQ;AAAA,SACjBC,aAAa,EAAEC,sBAAsB;AAAA,SAC5BC,MAAM;AAAA,OACjBC,IAAI;AAAA,SAEFC,oCAAoC;AAuB7C,MAAMC,UAAuB,GAAG,EAAE;AAElC,MAAMC,gBAAgB,GACpBC,EAA0C,IACH,CACvC,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAC9C,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,CACrD,CACEC,GAAG,CAAEC,GAAmB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IAAErE;EAAI,CAAC;EAAA,IAAE;IAAEH;EAAK,CAAC;EAClC,IAAIlB,GAAG,CAACoF,cAAc,KAAK/D,GAAG,EAAE,OAAO,EAAE;EACzCqE,UAAU,GAAGA,UAAqC;EAClD,IAAI;IACF,MAAM;MAAEC;IAAO,CAAC,GAAG,MAAMzE,IAAI,CAAC0E,WAAW,CAACF,UAAU,CAAC;IACrD,IAAIC,MAAM,EAAE,OAAO,EAAE;IACrB,OAAO,CAAC;MACN9B,OAAO,EAAG,YAAW6B,UAAW,gBAAe;MAC/C9E,GAAG,EAAE,mBAAmB;MACxBkD,WAAW,EAAE,CAAC,YAAY;IAC5B,CAAC,CAAC;EACJ,CAAC,CAAC,OAAO7B,KAAK,EAAE;IAAA;IACd,IAAI,oBAAAA,KAAK,CAAC4D,QAAQ,6EAAd,gBAAgBC,UAAU,0DAA1B,sBAA4BC,MAAM,KAAI,IAAI,EAAE,MAAM9D,KAAK;IAC3D,OAAO,CAAC;MACN4B,OAAO,EAAE5B,KAAK,CAAC4D,QAAQ,CAACC,UAAU,CAACC,MAAM;MACzCnF,GAAG,EAAE,kBAAkB;MACvBkD,WAAW,EAAE,CAAC,YAAY;IAC5B,CAAC,CAAC;EACJ;AACF,CAAC,CACF"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mjs","names":[],"sources":["../../../src/typings/@aeternity__aepp-calldata/index.d.ts"],"sourcesContent":["declare module '@aeternity/aepp-calldata' {\n // eslint-disable-next-line import/prefer-default-export\n export class Encoder {\n constructor(aci: object);\n\n encode(contract: string, funName: string, args: any[]): `cb_${string}`;\n\n decode(contract: string, funName: string, data: `cb_${string}`): any;\n\n decodeString(data: `cb_${string}`): Uint8Array;\n\n decodeFateString(data: `cb_${string}`): string;\n\n decodeEvent(\n contract: string,\n encodedData: `cb_${string}`,\n topics: BigInt[],\n ): { [key: string]: any[] };\n }\n}\n"],"mappings":""}
|
|
@@ -18,10 +18,10 @@ import BigNumber from 'bignumber.js';
|
|
|
18
18
|
import { isBigNumber } from "./bignumber.mjs";
|
|
19
19
|
import { ArgumentError } from "./errors.mjs";
|
|
20
20
|
export let AE_AMOUNT_FORMATS;
|
|
21
|
+
|
|
21
22
|
/**
|
|
22
23
|
* DENOMINATION_MAGNITUDE
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
25
|
(function (AE_AMOUNT_FORMATS) {
|
|
26
26
|
AE_AMOUNT_FORMATS["AE"] = "ae";
|
|
27
27
|
AE_AMOUNT_FORMATS["MILI_AE"] = "miliAE";
|
|
@@ -31,7 +31,6 @@ export let AE_AMOUNT_FORMATS;
|
|
|
31
31
|
AE_AMOUNT_FORMATS["FEMTO_AE"] = "femtoAE";
|
|
32
32
|
AE_AMOUNT_FORMATS["AETTOS"] = "aettos";
|
|
33
33
|
})(AE_AMOUNT_FORMATS || (AE_AMOUNT_FORMATS = {}));
|
|
34
|
-
|
|
35
34
|
const DENOMINATION_MAGNITUDE = {
|
|
36
35
|
[AE_AMOUNT_FORMATS.AE]: 0,
|
|
37
36
|
[AE_AMOUNT_FORMATS.MILI_AE]: -3,
|
|
@@ -41,6 +40,7 @@ const DENOMINATION_MAGNITUDE = {
|
|
|
41
40
|
[AE_AMOUNT_FORMATS.FEMTO_AE]: -15,
|
|
42
41
|
[AE_AMOUNT_FORMATS.AETTOS]: -18
|
|
43
42
|
};
|
|
43
|
+
|
|
44
44
|
/**
|
|
45
45
|
* Convert amount from one to other denomination
|
|
46
46
|
* @param value - amount to convert
|
|
@@ -49,7 +49,6 @@ const DENOMINATION_MAGNITUDE = {
|
|
|
49
49
|
* @param options.targetDenomination - target denomination,
|
|
50
50
|
* can be ['ae', 'aettos']
|
|
51
51
|
*/
|
|
52
|
-
|
|
53
52
|
export const formatAmount = (value, _ref) => {
|
|
54
53
|
let {
|
|
55
54
|
denomination = AE_AMOUNT_FORMATS.AETTOS,
|
|
@@ -58,13 +57,13 @@ export const formatAmount = (value, _ref) => {
|
|
|
58
57
|
if (!isBigNumber(value)) throw new ArgumentError('value', 'a number', value);
|
|
59
58
|
return new BigNumber(typeof value === 'bigint' ? value.toString() : value).shiftedBy(DENOMINATION_MAGNITUDE[denomination] - DENOMINATION_MAGNITUDE[targetDenomination]).toFixed();
|
|
60
59
|
};
|
|
60
|
+
|
|
61
61
|
/**
|
|
62
62
|
* Convert amount to AE
|
|
63
63
|
* @param value - amount to convert
|
|
64
64
|
* @param options - options
|
|
65
65
|
* @param options.denomination - denomination of amount, can be ['ae', 'aettos']
|
|
66
66
|
*/
|
|
67
|
-
|
|
68
67
|
export const toAe = function (value) {
|
|
69
68
|
let {
|
|
70
69
|
denomination = AE_AMOUNT_FORMATS.AETTOS
|
|
@@ -74,13 +73,13 @@ export const toAe = function (value) {
|
|
|
74
73
|
targetDenomination: AE_AMOUNT_FORMATS.AE
|
|
75
74
|
});
|
|
76
75
|
};
|
|
76
|
+
|
|
77
77
|
/**
|
|
78
78
|
* Convert amount to aettos
|
|
79
79
|
* @param value - amount to convert
|
|
80
80
|
* @param options - options
|
|
81
81
|
* @param options.denomination - denomination of amount, can be ['ae', 'aettos']
|
|
82
82
|
*/
|
|
83
|
-
|
|
84
83
|
export const toAettos = function (value) {
|
|
85
84
|
let {
|
|
86
85
|
denomination = AE_AMOUNT_FORMATS.AE
|
|
@@ -102,18 +101,13 @@ const prefixes = [{
|
|
|
102
101
|
name: 'pico',
|
|
103
102
|
magnitude: -12
|
|
104
103
|
}];
|
|
105
|
-
|
|
106
104
|
const getNearestPrefix = exponent => prefixes.reduce((p, n) => Math.abs(n.magnitude - exponent) < Math.abs(p.magnitude - exponent) ? n : p);
|
|
107
|
-
|
|
108
105
|
const getLowerBoundPrefix = exponent => {
|
|
109
106
|
var _prefixes$find;
|
|
110
|
-
|
|
111
107
|
return (_prefixes$find = prefixes.find(p => p.magnitude <= exponent)) !== null && _prefixes$find !== void 0 ? _prefixes$find : prefixes[prefixes.length - 1];
|
|
112
108
|
};
|
|
113
|
-
|
|
114
109
|
export default (rawValue => {
|
|
115
110
|
var _value$e;
|
|
116
|
-
|
|
117
111
|
const value = new BigNumber(rawValue);
|
|
118
112
|
const exp = (_value$e = value.e) !== null && _value$e !== void 0 ? _value$e : 0;
|
|
119
113
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amount-formatter.mjs","names":["BigNumber","isBigNumber","ArgumentError","AE_AMOUNT_FORMATS","DENOMINATION_MAGNITUDE","AE","MILI_AE","MICRO_AE","NANO_AE","PICO_AE","FEMTO_AE","AETTOS","formatAmount","value","denomination","targetDenomination","toString","shiftedBy","toFixed","toAe","toAettos","prefixes","name","magnitude","getNearestPrefix","exponent","reduce","p","n","Math","abs","getLowerBoundPrefix","find","length","rawValue","exp","e","v","precision","min"],"sources":["../../src/utils/amount-formatter.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 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 BigNumber from 'bignumber.js';\nimport { isBigNumber } from './bignumber';\nimport { ArgumentError } from './errors';\n\nexport enum AE_AMOUNT_FORMATS {\n AE = 'ae',\n MILI_AE = 'miliAE',\n MICRO_AE = 'microAE',\n NANO_AE = 'nanoAE',\n PICO_AE = 'picoAE',\n FEMTO_AE = 'femtoAE',\n AETTOS = 'aettos',\n}\n\n/**\n * DENOMINATION_MAGNITUDE\n */\nconst DENOMINATION_MAGNITUDE = {\n [AE_AMOUNT_FORMATS.AE]: 0,\n [AE_AMOUNT_FORMATS.MILI_AE]: -3,\n [AE_AMOUNT_FORMATS.MICRO_AE]: -6,\n [AE_AMOUNT_FORMATS.NANO_AE]: -9,\n [AE_AMOUNT_FORMATS.PICO_AE]: -12,\n [AE_AMOUNT_FORMATS.FEMTO_AE]: -15,\n [AE_AMOUNT_FORMATS.AETTOS]: -18,\n} as const;\n\n/**\n * Convert amount from one to other denomination\n * @param value - amount to convert\n * @param options - options\n * @param options.denomination - denomination of amount, can be ['ae', 'aettos']\n * @param options.targetDenomination - target denomination,\n * can be ['ae', 'aettos']\n */\nexport const formatAmount = (\n value: string | number | bigint | BigNumber,\n { denomination = AE_AMOUNT_FORMATS.AETTOS, targetDenomination = AE_AMOUNT_FORMATS.AETTOS }:\n { denomination?: AE_AMOUNT_FORMATS; targetDenomination?: AE_AMOUNT_FORMATS },\n): string => {\n if (!isBigNumber(value)) throw new ArgumentError('value', 'a number', value);\n\n return new BigNumber(typeof value === 'bigint' ? value.toString() : value)\n .shiftedBy(DENOMINATION_MAGNITUDE[denomination] - DENOMINATION_MAGNITUDE[targetDenomination])\n .toFixed();\n};\n\n/**\n * Convert amount to AE\n * @param value - amount to convert\n * @param options - options\n * @param options.denomination - denomination of amount, can be ['ae', 'aettos']\n */\nexport const toAe = (\n value: string | number | BigNumber,\n { denomination = AE_AMOUNT_FORMATS.AETTOS }: { denomination?: AE_AMOUNT_FORMATS } = {},\n): string => formatAmount(value, { denomination, targetDenomination: AE_AMOUNT_FORMATS.AE });\n\n/**\n * Convert amount to aettos\n * @param value - amount to convert\n * @param options - options\n * @param options.denomination - denomination of amount, can be ['ae', 'aettos']\n */\nexport const toAettos = (\n value: string | number | BigNumber,\n { denomination = AE_AMOUNT_FORMATS.AE }: { denomination?: AE_AMOUNT_FORMATS } = {},\n): string => formatAmount(value, { denomination });\n\ninterface Prefix {\n name: string;\n magnitude: number;\n}\n\nconst prefixes: Prefix[] = [\n { name: 'exa', magnitude: 18 },\n { name: 'giga', magnitude: 9 },\n { name: '', magnitude: 0 },\n { name: 'pico', magnitude: -12 },\n];\n\nconst getNearestPrefix = (exponent: number): Prefix => prefixes.reduce((p, n) => (\n Math.abs(n.magnitude - exponent) < Math.abs(p.magnitude - exponent) ? n : p));\n\nconst getLowerBoundPrefix = (exponent: number): Prefix => prefixes\n .find((p) => p.magnitude <= exponent) ?? prefixes[prefixes.length - 1];\n\nexport default (rawValue: string | number | BigNumber): string => {\n const value: BigNumber = new BigNumber(rawValue);\n\n const exp = value.e ?? 0;\n const { name, magnitude } = (exp < 0 ? getNearestPrefix : getLowerBoundPrefix)(exp);\n const v = value\n .shiftedBy(-magnitude)\n .precision(9 + Math.min(exp - magnitude, 0))\n .toFixed();\n return `${v}${name !== '' ? ' ' : ''}${name}`;\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,
|
|
1
|
+
{"version":3,"file":"amount-formatter.mjs","names":["BigNumber","isBigNumber","ArgumentError","AE_AMOUNT_FORMATS","DENOMINATION_MAGNITUDE","AE","MILI_AE","MICRO_AE","NANO_AE","PICO_AE","FEMTO_AE","AETTOS","formatAmount","value","denomination","targetDenomination","toString","shiftedBy","toFixed","toAe","toAettos","prefixes","name","magnitude","getNearestPrefix","exponent","reduce","p","n","Math","abs","getLowerBoundPrefix","find","length","rawValue","exp","e","v","precision","min"],"sources":["../../src/utils/amount-formatter.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 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 BigNumber from 'bignumber.js';\nimport { isBigNumber } from './bignumber';\nimport { ArgumentError } from './errors';\n\nexport enum AE_AMOUNT_FORMATS {\n AE = 'ae',\n MILI_AE = 'miliAE',\n MICRO_AE = 'microAE',\n NANO_AE = 'nanoAE',\n PICO_AE = 'picoAE',\n FEMTO_AE = 'femtoAE',\n AETTOS = 'aettos',\n}\n\n/**\n * DENOMINATION_MAGNITUDE\n */\nconst DENOMINATION_MAGNITUDE = {\n [AE_AMOUNT_FORMATS.AE]: 0,\n [AE_AMOUNT_FORMATS.MILI_AE]: -3,\n [AE_AMOUNT_FORMATS.MICRO_AE]: -6,\n [AE_AMOUNT_FORMATS.NANO_AE]: -9,\n [AE_AMOUNT_FORMATS.PICO_AE]: -12,\n [AE_AMOUNT_FORMATS.FEMTO_AE]: -15,\n [AE_AMOUNT_FORMATS.AETTOS]: -18,\n} as const;\n\n/**\n * Convert amount from one to other denomination\n * @param value - amount to convert\n * @param options - options\n * @param options.denomination - denomination of amount, can be ['ae', 'aettos']\n * @param options.targetDenomination - target denomination,\n * can be ['ae', 'aettos']\n */\nexport const formatAmount = (\n value: string | number | bigint | BigNumber,\n { denomination = AE_AMOUNT_FORMATS.AETTOS, targetDenomination = AE_AMOUNT_FORMATS.AETTOS }:\n { denomination?: AE_AMOUNT_FORMATS; targetDenomination?: AE_AMOUNT_FORMATS },\n): string => {\n if (!isBigNumber(value)) throw new ArgumentError('value', 'a number', value);\n\n return new BigNumber(typeof value === 'bigint' ? value.toString() : value)\n .shiftedBy(DENOMINATION_MAGNITUDE[denomination] - DENOMINATION_MAGNITUDE[targetDenomination])\n .toFixed();\n};\n\n/**\n * Convert amount to AE\n * @param value - amount to convert\n * @param options - options\n * @param options.denomination - denomination of amount, can be ['ae', 'aettos']\n */\nexport const toAe = (\n value: string | number | BigNumber,\n { denomination = AE_AMOUNT_FORMATS.AETTOS }: { denomination?: AE_AMOUNT_FORMATS } = {},\n): string => formatAmount(value, { denomination, targetDenomination: AE_AMOUNT_FORMATS.AE });\n\n/**\n * Convert amount to aettos\n * @param value - amount to convert\n * @param options - options\n * @param options.denomination - denomination of amount, can be ['ae', 'aettos']\n */\nexport const toAettos = (\n value: string | number | BigNumber,\n { denomination = AE_AMOUNT_FORMATS.AE }: { denomination?: AE_AMOUNT_FORMATS } = {},\n): string => formatAmount(value, { denomination });\n\ninterface Prefix {\n name: string;\n magnitude: number;\n}\n\nconst prefixes: Prefix[] = [\n { name: 'exa', magnitude: 18 },\n { name: 'giga', magnitude: 9 },\n { name: '', magnitude: 0 },\n { name: 'pico', magnitude: -12 },\n];\n\nconst getNearestPrefix = (exponent: number): Prefix => prefixes.reduce((p, n) => (\n Math.abs(n.magnitude - exponent) < Math.abs(p.magnitude - exponent) ? n : p));\n\nconst getLowerBoundPrefix = (exponent: number): Prefix => prefixes\n .find((p) => p.magnitude <= exponent) ?? prefixes[prefixes.length - 1];\n\nexport default (rawValue: string | number | BigNumber): string => {\n const value: BigNumber = new BigNumber(rawValue);\n\n const exp = value.e ?? 0;\n const { name, magnitude } = (exp < 0 ? getNearestPrefix : getLowerBoundPrefix)(exp);\n const v = value\n .shiftedBy(-magnitude)\n .precision(9 + Math.min(exp - magnitude, 0))\n .toFixed();\n return `${v}${name !== '' ? ' ' : ''}${name}`;\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;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2DAAIJ,QAAQ,CAACA,QAAQ,CAACY,MAAM,GAAG,CAAC,CAAC;AAAA;AAExE,gBAAgBC,QAAqC,IAAa;EAAA;EAChE,MAAMrB,KAAgB,GAAG,IAAIb,SAAS,CAACkC,QAAQ,CAAC;EAEhD,MAAMC,GAAG,eAAGtB,KAAK,CAACuB,CAAC,+CAAI,CAAC;EACxB,MAAM;IAAEd,IAAI;IAAEC;EAAU,CAAC,GAAG,CAACY,GAAG,GAAG,CAAC,GAAGX,gBAAgB,GAAGO,mBAAmB,EAAEI,GAAG,CAAC;EACnF,MAAME,CAAC,GAAGxB,KAAK,CACZI,SAAS,CAAC,CAACM,SAAS,CAAC,CACrBe,SAAS,CAAC,CAAC,GAAGT,IAAI,CAACU,GAAG,CAACJ,GAAG,GAAGZ,SAAS,EAAE,CAAC,CAAC,CAAC,CAC3CL,OAAO,EAAE;EACZ,OAAQ,GAAEmB,CAAE,GAAEf,IAAI,KAAK,EAAE,GAAG,GAAG,GAAG,EAAG,GAAEA,IAAK,EAAC;AAC/C,CAAC"}
|
package/es/utils/autorest.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ import { PipelinePolicy } from '@azure/core-rest-pipeline';
|
|
|
2
2
|
import { AdditionalPolicyConfig } from '@azure/core-client';
|
|
3
3
|
export declare const genRequestQueuesPolicy: () => AdditionalPolicyConfig;
|
|
4
4
|
export declare const genCombineGetRequestsPolicy: () => AdditionalPolicyConfig;
|
|
5
|
+
export declare const genAggressiveCacheGetResponsesPolicy: () => PipelinePolicy;
|
|
5
6
|
export declare const genErrorFormatterPolicy: (getMessage: (b: any) => string) => AdditionalPolicyConfig;
|
|
6
7
|
export declare const genVersionCheckPolicy: (name: string, ignorePath: string, versionPromise: Promise<string>, geVersion: string, ltVersion: string) => PipelinePolicy;
|
package/es/utils/autorest.mjs
CHANGED
|
@@ -7,23 +7,18 @@ export const genRequestQueuesPolicy = () => {
|
|
|
7
7
|
return {
|
|
8
8
|
policy: {
|
|
9
9
|
name: 'request-queues',
|
|
10
|
-
|
|
11
10
|
async sendRequest(request, next) {
|
|
12
11
|
var _requestQueues$get;
|
|
13
|
-
|
|
14
12
|
const key = request.headers.get('__queue');
|
|
15
13
|
request.headers.delete('__queue');
|
|
16
|
-
|
|
17
14
|
const getResponse = async () => next(request);
|
|
18
|
-
|
|
19
15
|
if (key == null) return getResponse();
|
|
20
|
-
const req = ((_requestQueues$get = requestQueues.get(key)) !== null && _requestQueues$get !== void 0 ? _requestQueues$get : Promise.resolve()).then(getResponse, getResponse);
|
|
16
|
+
const req = ((_requestQueues$get = requestQueues.get(key)) !== null && _requestQueues$get !== void 0 ? _requestQueues$get : Promise.resolve()).then(getResponse, getResponse);
|
|
17
|
+
// TODO: remove after fixing https://github.com/aeternity/aeternity/issues/3803
|
|
21
18
|
// gap to ensure that node won't reject the nonce
|
|
22
|
-
|
|
23
19
|
requestQueues.set(key, req.then(async () => pause(750)));
|
|
24
20
|
return req;
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
},
|
|
28
23
|
position: 'perCall'
|
|
29
24
|
};
|
|
@@ -32,66 +27,69 @@ export const genCombineGetRequestsPolicy = () => {
|
|
|
32
27
|
const pendingGetRequests = new Map();
|
|
33
28
|
return {
|
|
34
29
|
policy: {
|
|
35
|
-
name: 'combine-requests',
|
|
36
|
-
|
|
30
|
+
name: 'combine-get-requests',
|
|
37
31
|
async sendRequest(request, next) {
|
|
38
32
|
var _pendingGetRequests$g;
|
|
39
|
-
|
|
40
33
|
if (request.method !== 'GET') return next(request);
|
|
41
34
|
const key = JSON.stringify([request.url, request.body]);
|
|
42
35
|
const response = (_pendingGetRequests$g = pendingGetRequests.get(key)) !== null && _pendingGetRequests$g !== void 0 ? _pendingGetRequests$g : next(request);
|
|
43
36
|
pendingGetRequests.set(key, response);
|
|
44
|
-
|
|
45
37
|
try {
|
|
46
38
|
return await response;
|
|
47
39
|
} finally {
|
|
48
40
|
pendingGetRequests.delete(key);
|
|
49
41
|
}
|
|
50
42
|
}
|
|
51
|
-
|
|
52
43
|
},
|
|
53
44
|
position: 'perCall'
|
|
54
45
|
};
|
|
55
46
|
};
|
|
47
|
+
export const genAggressiveCacheGetResponsesPolicy = () => {
|
|
48
|
+
const getRequests = new Map();
|
|
49
|
+
return {
|
|
50
|
+
name: 'aggressive-cache-get-responses',
|
|
51
|
+
async sendRequest(request, next) {
|
|
52
|
+
var _getRequests$get;
|
|
53
|
+
if (request.method !== 'GET') return next(request);
|
|
54
|
+
const key = JSON.stringify([request.url, request.body]);
|
|
55
|
+
const response = (_getRequests$get = getRequests.get(key)) !== null && _getRequests$get !== void 0 ? _getRequests$get : next(request);
|
|
56
|
+
getRequests.set(key, response);
|
|
57
|
+
return response;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
56
61
|
export const genErrorFormatterPolicy = getMessage => ({
|
|
57
62
|
policy: {
|
|
58
63
|
name: 'error-formatter',
|
|
59
|
-
|
|
60
64
|
async sendRequest(request, next) {
|
|
61
65
|
try {
|
|
62
66
|
return await next(request);
|
|
63
67
|
} catch (error) {
|
|
64
68
|
var _error$response;
|
|
65
|
-
|
|
66
69
|
if (!(error instanceof RestError) || error.request == null) throw error;
|
|
67
70
|
if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.bodyAsText) == null) throw error;
|
|
68
71
|
let body;
|
|
69
|
-
|
|
70
72
|
try {
|
|
71
73
|
body = JSON.parse(error.response.bodyAsText);
|
|
72
74
|
} catch (e) {
|
|
73
75
|
throw error;
|
|
74
76
|
}
|
|
75
|
-
|
|
76
77
|
error.message = `${new URL(error.request.url).pathname.slice(1)} error`;
|
|
77
78
|
const message = getMessage(body);
|
|
78
79
|
if (message !== '') error.message += `:${message}`;
|
|
79
80
|
throw error;
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
|
-
|
|
83
83
|
},
|
|
84
84
|
position: 'perCall'
|
|
85
85
|
});
|
|
86
86
|
export const genVersionCheckPolicy = (name, ignorePath, versionPromise, geVersion, ltVersion) => ({
|
|
87
87
|
name: 'version-check',
|
|
88
|
-
|
|
89
88
|
async sendRequest(request, next) {
|
|
90
89
|
if (new URL(request.url).pathname === ignorePath) return next(request);
|
|
91
90
|
const args = [await versionPromise, geVersion, ltVersion];
|
|
92
91
|
if (!semverSatisfies(...args)) throw new UnsupportedVersionError(name, ...args);
|
|
93
92
|
return next(request);
|
|
94
93
|
}
|
|
95
|
-
|
|
96
94
|
});
|
|
97
95
|
//# sourceMappingURL=autorest.mjs.map
|