@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/builder/index.mjs
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import _buffer from "buffer";
|
|
2
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
3
|
-
const {
|
|
4
|
-
Buffer: _Buffer
|
|
5
|
-
} = _buffer;
|
|
6
1
|
import _rlp from 'rlp';
|
|
7
2
|
const {
|
|
8
3
|
decode: rlpDecode,
|
|
@@ -11,259 +6,14 @@ const {
|
|
|
11
6
|
import { decode, encode, Encoding } from "../../utils/encoder.mjs";
|
|
12
7
|
import { AE_AMOUNT_FORMATS } from "../../utils/amount-formatter.mjs";
|
|
13
8
|
import { hash } from "../../utils/crypto.mjs";
|
|
14
|
-
import {
|
|
9
|
+
import { TX_SCHEMA } from "./schema.mjs";
|
|
15
10
|
import { Tag } from "./constants.mjs";
|
|
16
|
-
import { buildContractId,
|
|
17
|
-
import {
|
|
18
|
-
import { toBytes } from "../../utils/bytes.mjs";
|
|
19
|
-
import MPTree from "../../utils/mptree.mjs";
|
|
20
|
-
import { ArgumentError, DecodeError, InvalidTxParamsError, SchemaNotFoundError } from "../../utils/errors.mjs";
|
|
11
|
+
import { buildContractId, readInt } from "./helpers.mjs";
|
|
12
|
+
import { ArgumentError, DecodeError, SchemaNotFoundError } from "../../utils/errors.mjs";
|
|
21
13
|
import { isKeyOfObject } from "../../utils/other.mjs";
|
|
22
|
-
|
|
23
14
|
/**
|
|
24
15
|
* JavaScript-based Transaction builder
|
|
25
16
|
*/
|
|
26
|
-
// SERIALIZE AND DESERIALIZE PART
|
|
27
|
-
function deserializeField(value, type, prefix) {
|
|
28
|
-
if (value == null) return '';
|
|
29
|
-
|
|
30
|
-
switch (type) {
|
|
31
|
-
case FIELD_TYPES.ctVersion:
|
|
32
|
-
{
|
|
33
|
-
const [vm,, abi] = value;
|
|
34
|
-
return {
|
|
35
|
-
vmVersion: readInt(_Buffer.from([vm])),
|
|
36
|
-
abiVersion: readInt(_Buffer.from([abi]))
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
case FIELD_TYPES.abiVersion:
|
|
41
|
-
case FIELD_TYPES.ttlType:
|
|
42
|
-
return readInt(value);
|
|
43
|
-
|
|
44
|
-
case FIELD_TYPES.id:
|
|
45
|
-
return readId(value);
|
|
46
|
-
|
|
47
|
-
case FIELD_TYPES.ids:
|
|
48
|
-
return value.map(readId);
|
|
49
|
-
|
|
50
|
-
case FIELD_TYPES.bool:
|
|
51
|
-
return value[0] === 1;
|
|
52
|
-
|
|
53
|
-
case FIELD_TYPES.binary:
|
|
54
|
-
return encode(value, prefix);
|
|
55
|
-
|
|
56
|
-
case FIELD_TYPES.stateTree:
|
|
57
|
-
return encode(value, Encoding.StateTrees);
|
|
58
|
-
|
|
59
|
-
case FIELD_TYPES.string:
|
|
60
|
-
return value.toString();
|
|
61
|
-
|
|
62
|
-
case FIELD_TYPES.payload:
|
|
63
|
-
return encode(value, Encoding.Bytearray);
|
|
64
|
-
|
|
65
|
-
case FIELD_TYPES.pointers:
|
|
66
|
-
return readPointers(value);
|
|
67
|
-
|
|
68
|
-
case FIELD_TYPES.rlpBinary:
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
70
|
-
return unpackTx(encode(value, Encoding.Transaction));
|
|
71
|
-
|
|
72
|
-
case FIELD_TYPES.rlpBinaries:
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
74
|
-
return value.map(v => unpackTx(encode(v, Encoding.Transaction)));
|
|
75
|
-
|
|
76
|
-
case FIELD_TYPES.rawBinary:
|
|
77
|
-
return value;
|
|
78
|
-
|
|
79
|
-
case FIELD_TYPES.hex:
|
|
80
|
-
return value.toString('hex');
|
|
81
|
-
|
|
82
|
-
case FIELD_TYPES.offChainUpdates:
|
|
83
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
84
|
-
return value.map(v => unpackTx(encode(v, Encoding.Transaction)));
|
|
85
|
-
|
|
86
|
-
case FIELD_TYPES.callStack:
|
|
87
|
-
// TODO: fix this
|
|
88
|
-
return [readInt(value)];
|
|
89
|
-
|
|
90
|
-
case FIELD_TYPES.mptrees:
|
|
91
|
-
return value.map(t => new MPTree(t));
|
|
92
|
-
|
|
93
|
-
case FIELD_TYPES.callReturnType:
|
|
94
|
-
switch (readInt(value)) {
|
|
95
|
-
case '0':
|
|
96
|
-
return 'ok';
|
|
97
|
-
|
|
98
|
-
case '1':
|
|
99
|
-
return 'error';
|
|
100
|
-
|
|
101
|
-
case '2':
|
|
102
|
-
return 'revert';
|
|
103
|
-
|
|
104
|
-
default:
|
|
105
|
-
return value;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
case FIELD_TYPES.sophiaCodeTypeInfo:
|
|
109
|
-
return value.reduce((acc, _ref) => {
|
|
110
|
-
let [funHash, fnName, argType, outType] = _ref;
|
|
111
|
-
return { ...acc,
|
|
112
|
-
[fnName.toString()]: {
|
|
113
|
-
funHash,
|
|
114
|
-
argType,
|
|
115
|
-
outType
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
}, {});
|
|
119
|
-
|
|
120
|
-
default:
|
|
121
|
-
if (typeof type === 'number') return value;
|
|
122
|
-
return type.deserialize(value);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function serializeField(value, type, params) {
|
|
127
|
-
var _value$rlpEncoded;
|
|
128
|
-
|
|
129
|
-
switch (type) {
|
|
130
|
-
case FIELD_TYPES.abiVersion:
|
|
131
|
-
case FIELD_TYPES.ttlType:
|
|
132
|
-
return writeInt(value);
|
|
133
|
-
|
|
134
|
-
case FIELD_TYPES.id:
|
|
135
|
-
return writeId(value);
|
|
136
|
-
|
|
137
|
-
case FIELD_TYPES.ids:
|
|
138
|
-
return value.map(writeId);
|
|
139
|
-
|
|
140
|
-
case FIELD_TYPES.bool:
|
|
141
|
-
return _Buffer.from([value === true ? 1 : 0]);
|
|
142
|
-
|
|
143
|
-
case FIELD_TYPES.binary:
|
|
144
|
-
return decode(value);
|
|
145
|
-
|
|
146
|
-
case FIELD_TYPES.stateTree:
|
|
147
|
-
return decode(value);
|
|
148
|
-
|
|
149
|
-
case FIELD_TYPES.hex:
|
|
150
|
-
return _Buffer.from(value, 'hex');
|
|
151
|
-
|
|
152
|
-
case FIELD_TYPES.signatures:
|
|
153
|
-
return value.map(_Buffer.from);
|
|
154
|
-
|
|
155
|
-
case FIELD_TYPES.payload:
|
|
156
|
-
return typeof value === 'string' && value.split('_')[0] === 'ba' ? decode(value) : toBytes(value);
|
|
157
|
-
|
|
158
|
-
case FIELD_TYPES.string:
|
|
159
|
-
return toBytes(value);
|
|
160
|
-
|
|
161
|
-
case FIELD_TYPES.pointers:
|
|
162
|
-
return buildPointers(value);
|
|
163
|
-
|
|
164
|
-
case FIELD_TYPES.rlpBinary:
|
|
165
|
-
return (_value$rlpEncoded = value.rlpEncoded) !== null && _value$rlpEncoded !== void 0 ? _value$rlpEncoded : value;
|
|
166
|
-
|
|
167
|
-
case FIELD_TYPES.mptrees:
|
|
168
|
-
return value.map(t => t.serialize());
|
|
169
|
-
|
|
170
|
-
case FIELD_TYPES.ctVersion:
|
|
171
|
-
return _Buffer.from([...toBytes(value.vmVersion), 0, ...toBytes(value.abiVersion)]);
|
|
172
|
-
|
|
173
|
-
case FIELD_TYPES.callReturnType:
|
|
174
|
-
switch (value) {
|
|
175
|
-
case 'ok':
|
|
176
|
-
return writeInt(0);
|
|
177
|
-
|
|
178
|
-
case 'error':
|
|
179
|
-
return writeInt(1);
|
|
180
|
-
|
|
181
|
-
case 'revert':
|
|
182
|
-
return writeInt(2);
|
|
183
|
-
|
|
184
|
-
default:
|
|
185
|
-
return value;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
default:
|
|
189
|
-
if (typeof type === 'number') return value; // @ts-expect-error will be solved after removing the whole serializeField function
|
|
190
|
-
|
|
191
|
-
return type.serialize(value, params);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function validateField(value, type, prefix) {
|
|
196
|
-
// All fields are required
|
|
197
|
-
if (value == null) return 'Field is required'; // Validate type of value
|
|
198
|
-
|
|
199
|
-
switch (type) {
|
|
200
|
-
case FIELD_TYPES.id:
|
|
201
|
-
{
|
|
202
|
-
const prefixes = Array.isArray(prefix) ? prefix : [prefix];
|
|
203
|
-
|
|
204
|
-
if (!_includesInstanceProperty(prefixes).call(prefixes, value.split('_')[0])) {
|
|
205
|
-
if (prefix == null) {
|
|
206
|
-
return `'${String(value)}' prefix doesn't exist'`;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return `'${String(value)}' prefix doesn't match expected prefix '${prefix.toString()}'`;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return undefined;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
case FIELD_TYPES.ctVersion:
|
|
216
|
-
if (!(Boolean(value.abiVersion) && Boolean(value.vmVersion))) {
|
|
217
|
-
return 'Value must be an object with "vmVersion" and "abiVersion" fields';
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return undefined;
|
|
221
|
-
|
|
222
|
-
case FIELD_TYPES.pointers:
|
|
223
|
-
if (!Array.isArray(value)) return 'Value must be of type Array';
|
|
224
|
-
|
|
225
|
-
if (value.some(p => !(Boolean(p.key) && Boolean(p.id)))) {
|
|
226
|
-
return 'Value must contains only object\'s like \'{key: "account_pubkey", id: "ak_lkamsflkalsdalksdlasdlasdlamd"}\'';
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (value.length > 32) {
|
|
230
|
-
return `Expected 32 pointers or less, got ${value.length} instead`;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return undefined;
|
|
234
|
-
|
|
235
|
-
default:
|
|
236
|
-
return undefined;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Validate transaction params
|
|
241
|
-
* @category transaction builder
|
|
242
|
-
* @param params - Object with tx params
|
|
243
|
-
* @param schema - Transaction schema
|
|
244
|
-
* @param excludeKeys - Array of keys to exclude for validation
|
|
245
|
-
* @returns Object with validation errors
|
|
246
|
-
*/
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
export function validateParams(params, schema, _ref2) {
|
|
250
|
-
let {
|
|
251
|
-
excludeKeys = []
|
|
252
|
-
} = _ref2;
|
|
253
|
-
return Object.fromEntries(schema // TODO: allow optional keys in schema
|
|
254
|
-
.filter(_ref3 => {
|
|
255
|
-
var _context;
|
|
256
|
-
|
|
257
|
-
let [key] = _ref3;
|
|
258
|
-
return !_includesInstanceProperty(excludeKeys).call(excludeKeys, key) && !_includesInstanceProperty(_context = ['payload', 'nameFee', 'deposit', 'gasPrice', 'fee', 'gasLimit']).call(_context, key);
|
|
259
|
-
}).map(_ref4 => {
|
|
260
|
-
let [key, type, prefix] = _ref4;
|
|
261
|
-
return [key, validateField(params[key], type, prefix)];
|
|
262
|
-
}).filter(_ref5 => {
|
|
263
|
-
let [, message] = _ref5;
|
|
264
|
-
return message;
|
|
265
|
-
}));
|
|
266
|
-
}
|
|
267
17
|
/**
|
|
268
18
|
* Unpack binary transaction
|
|
269
19
|
* @category transaction builder
|
|
@@ -271,26 +21,28 @@ export function validateParams(params, schema, _ref2) {
|
|
|
271
21
|
* @param schema - Transaction schema
|
|
272
22
|
* @returns Object with transaction field's
|
|
273
23
|
*/
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
24
|
+
function unpackRawTx(binary, schema) {
|
|
25
|
+
if (binary.length !== schema.length) {
|
|
26
|
+
throw new ArgumentError('Transaction RLP length', schema.length, binary.length);
|
|
27
|
+
}
|
|
28
|
+
return schema.reduce((acc, _ref, index) => {
|
|
29
|
+
let [name, field] = _ref;
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
31
|
+
const deserialized = field.deserialize(binary[index], {
|
|
32
|
+
unpackTx
|
|
280
33
|
});
|
|
34
|
+
return {
|
|
35
|
+
...acc,
|
|
36
|
+
[name]: deserialized
|
|
37
|
+
};
|
|
281
38
|
}, {});
|
|
282
39
|
}
|
|
283
|
-
/**
|
|
284
|
-
* @category transaction builder
|
|
285
|
-
*/
|
|
286
40
|
|
|
287
41
|
/**
|
|
288
42
|
* Build transaction hash
|
|
289
43
|
* @category transaction builder
|
|
290
|
-
* @param
|
|
291
|
-
* @param type - Transaction type
|
|
44
|
+
* @param params - Object with tx params
|
|
292
45
|
* @param options - options
|
|
293
|
-
* @param options.excludeKeys - Array of keys to exclude for validation and build
|
|
294
46
|
* @param options.denomination - Denomination of amounts
|
|
295
47
|
* @param options.prefix - Prefix of transaction
|
|
296
48
|
* @throws {@link InvalidTxParamsError}
|
|
@@ -299,62 +51,38 @@ export function unpackRawTx(binary, schema) {
|
|
|
299
51
|
* @returns object.rlpEncoded rlp encoded transaction
|
|
300
52
|
* @returns object.binary binary transaction
|
|
301
53
|
*/
|
|
302
|
-
export function buildTx(
|
|
303
|
-
var
|
|
304
|
-
|
|
54
|
+
export function buildTx(params) {
|
|
55
|
+
var _params$version;
|
|
305
56
|
let {
|
|
306
|
-
|
|
307
|
-
prefix = Encoding.Transaction,
|
|
308
|
-
vsn,
|
|
57
|
+
prefix,
|
|
309
58
|
denomination = AE_AMOUNT_FORMATS.AETTOS
|
|
310
|
-
} = arguments.length >
|
|
311
|
-
const schemas = TX_SCHEMA[
|
|
312
|
-
(
|
|
313
|
-
if (!isKeyOfObject(
|
|
314
|
-
|
|
315
|
-
const params = _params;
|
|
316
|
-
params.VSN = vsn;
|
|
317
|
-
params.tag = type;
|
|
318
|
-
params.denomination = denomination;
|
|
319
|
-
const filteredSchema = schema.filter(_ref7 => {
|
|
320
|
-
let [key] = _ref7;
|
|
321
|
-
return !_includesInstanceProperty(excludeKeys).call(excludeKeys, key);
|
|
322
|
-
}); // Validation
|
|
323
|
-
|
|
324
|
-
const valid = validateParams(params, schema, {
|
|
325
|
-
excludeKeys
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
if (Object.keys(valid).length > 0) {
|
|
329
|
-
throw new InvalidTxParamsError(`Transaction build error. ${JSON.stringify(valid)}`);
|
|
59
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
60
|
+
const schemas = TX_SCHEMA[params.tag];
|
|
61
|
+
(_params$version = params.version) !== null && _params$version !== void 0 ? _params$version : params.version = Math.max(...Object.keys(schemas).map(a => +a));
|
|
62
|
+
if (!isKeyOfObject(params.version, schemas)) {
|
|
63
|
+
throw new SchemaNotFoundError('serialization', Tag[params.tag], params.version);
|
|
330
64
|
}
|
|
331
|
-
|
|
332
|
-
const binary =
|
|
333
|
-
let [key,
|
|
334
|
-
return
|
|
335
|
-
|
|
336
|
-
|
|
65
|
+
const schema = schemas[params.version];
|
|
66
|
+
const binary = schema.map(_ref2 => {
|
|
67
|
+
let [key, field] = _ref2;
|
|
68
|
+
return field.serialize(params[key], {
|
|
69
|
+
...params,
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
71
|
+
unpackTx,
|
|
72
|
+
buildTx,
|
|
73
|
+
denomination,
|
|
74
|
+
rebuildTx: overrideParams => buildTx({
|
|
75
|
+
...params,
|
|
337
76
|
...overrideParams
|
|
338
|
-
},
|
|
339
|
-
excludeKeys,
|
|
340
|
-
prefix: Encoding.Transaction,
|
|
341
|
-
vsn,
|
|
77
|
+
}, {
|
|
342
78
|
denomination
|
|
343
79
|
})
|
|
344
80
|
});
|
|
345
|
-
})
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
return
|
|
349
|
-
tx,
|
|
350
|
-
rlpEncoded,
|
|
351
|
-
binary,
|
|
352
|
-
txObject: unpackRawTx(binary, schema)
|
|
353
|
-
};
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// @ts-expect-error looks like a TypeScript edge case
|
|
84
|
+
return encode(rlpEncode(binary), prefix !== null && prefix !== void 0 ? prefix : Encoding.Transaction);
|
|
354
85
|
}
|
|
355
|
-
/**
|
|
356
|
-
* @category transaction builder
|
|
357
|
-
*/
|
|
358
86
|
|
|
359
87
|
/**
|
|
360
88
|
* Unpack transaction hash
|
|
@@ -366,50 +94,42 @@ export function buildTx(_params, type) {
|
|
|
366
94
|
* @returns object.txType Transaction type
|
|
367
95
|
*/
|
|
368
96
|
export function unpackTx(encodedTx, txType) {
|
|
369
|
-
const
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
if (
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
return {
|
|
378
|
-
txType: objId,
|
|
379
|
-
tx: unpackRawTx(binary, schema),
|
|
380
|
-
rlpEncoded
|
|
381
|
-
};
|
|
97
|
+
const binary = rlpDecode(decode(encodedTx));
|
|
98
|
+
const tag = +readInt(binary[0]);
|
|
99
|
+
if (!isKeyOfObject(tag, TX_SCHEMA)) throw new DecodeError(`Unknown transaction tag: ${tag}`);
|
|
100
|
+
if (txType != null && txType !== tag) throw new DecodeError(`Expected transaction to have ${Tag[txType]} tag, got ${Tag[tag]} instead`);
|
|
101
|
+
const version = +readInt(binary[1]);
|
|
102
|
+
if (!isKeyOfObject(version, TX_SCHEMA[tag])) throw new SchemaNotFoundError('deserialization', `tag ${tag}`, version);
|
|
103
|
+
const schema = TX_SCHEMA[tag][version];
|
|
104
|
+
return unpackRawTx(binary, schema);
|
|
382
105
|
}
|
|
106
|
+
|
|
383
107
|
/**
|
|
384
108
|
* Build a transaction hash
|
|
385
109
|
* @category transaction builder
|
|
386
110
|
* @param rawTx - base64 or rlp encoded transaction
|
|
387
111
|
* @returns Transaction hash
|
|
388
112
|
*/
|
|
389
|
-
|
|
390
113
|
export function buildTxHash(rawTx) {
|
|
391
114
|
const data = typeof rawTx === 'string' && rawTx.startsWith('tx_') ? decode(rawTx) : rawTx;
|
|
392
115
|
return encode(hash(data), Encoding.TxHash);
|
|
393
116
|
}
|
|
117
|
+
|
|
394
118
|
/**
|
|
395
119
|
* Build a contract public key by contractCreateTx or gaAttach
|
|
396
120
|
* @category contract
|
|
397
121
|
* @param contractTx - Transaction
|
|
398
122
|
* @returns Contract public key
|
|
399
123
|
*/
|
|
400
|
-
|
|
401
124
|
export function buildContractIdByContractTx(contractTx) {
|
|
402
|
-
var _context2;
|
|
403
|
-
|
|
404
125
|
const {
|
|
405
|
-
|
|
406
|
-
|
|
126
|
+
tag,
|
|
127
|
+
ownerId,
|
|
128
|
+
nonce
|
|
407
129
|
} = unpackTx(contractTx);
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
throw new ArgumentError('contractCreateTx', 'a contractCreateTx or gaAttach', txType);
|
|
130
|
+
if (![Tag.ContractCreateTx, Tag.GaAttachTx].includes(tag)) {
|
|
131
|
+
throw new ArgumentError('contractCreateTx', 'a contractCreateTx or gaAttach', tag);
|
|
411
132
|
}
|
|
412
|
-
|
|
413
|
-
return buildContractId(tx.ownerId, +tx.nonce);
|
|
133
|
+
return buildContractId(ownerId, +nonce);
|
|
414
134
|
}
|
|
415
135
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["decode","encode","Encoding","AE_AMOUNT_FORMATS","hash","FIELD_TYPES","TX_SCHEMA","Tag","buildContractId","buildPointers","readInt","readPointers","writeInt","readId","writeId","toBytes","MPTree","ArgumentError","DecodeError","InvalidTxParamsError","SchemaNotFoundError","isKeyOfObject","deserializeField","value","type","prefix","ctVersion","vm","abi","vmVersion","from","abiVersion","ttlType","id","ids","map","bool","binary","stateTree","StateTrees","string","toString","payload","Bytearray","pointers","rlpBinary","unpackTx","Transaction","rlpBinaries","v","rawBinary","hex","offChainUpdates","callStack","mptrees","t","callReturnType","sophiaCodeTypeInfo","reduce","acc","funHash","fnName","argType","outType","deserialize","serializeField","params","signatures","split","rlpEncoded","serialize","validateField","prefixes","Array","isArray","String","undefined","Boolean","some","p","key","length","validateParams","schema","excludeKeys","Object","fromEntries","filter","message","unpackRawTx","index","fieldType","assign","buildTx","_params","vsn","denomination","AETTOS","schemas","Math","max","keys","a","VSN","tag","filteredSchema","valid","JSON","stringify","txType","rebuildTx","overrideParams","e","rlpEncode","tx","txObject","encodedTx","rlpDecode","objId","buildTxHash","rawTx","data","startsWith","TxHash","buildContractIdByContractTx","contractTx","ContractCreateTx","GaAttachTx","ownerId","nonce"],"sources":["../../../src/tx/builder/index.ts"],"sourcesContent":["import { decode as rlpDecode, encode as rlpEncode, NestedUint8Array } from 'rlp';\nimport {\n decode, encode, Encoded, Encoding,\n} from '../../utils/encoder';\nimport { AE_AMOUNT_FORMATS } from '../../utils/amount-formatter';\nimport { hash } from '../../utils/crypto';\nimport { Field } from './field-types';\nimport {\n FIELD_TYPES,\n RawTxObject,\n TX_SCHEMA,\n TxField,\n TxParamsCommon,\n TxSchema,\n TxTypeSchemas,\n} from './schema';\nimport { Tag } from './constants';\nimport {\n buildContractId, buildPointers, readInt, readPointers, writeInt,\n} from './helpers';\nimport { readId, writeId } from './address';\nimport { toBytes } from '../../utils/bytes';\nimport MPTree, { MPTreeBinary } from '../../utils/mptree';\nimport {\n ArgumentError,\n DecodeError,\n InvalidTxParamsError,\n SchemaNotFoundError,\n} from '../../utils/errors';\nimport { isKeyOfObject } from '../../utils/other';\nimport { NamePointer } from '../../apis/node';\n\n/**\n * JavaScript-based Transaction builder\n */\n\n// SERIALIZE AND DESERIALIZE PART\nfunction deserializeField(\n value: any,\n type: FIELD_TYPES | Field,\n prefix?: Encoding | Encoding[],\n): any {\n if (value == null) return '';\n switch (type) {\n case FIELD_TYPES.ctVersion: {\n const [vm, , abi] = value;\n return {\n vmVersion: readInt(Buffer.from([vm])),\n abiVersion: readInt(Buffer.from([abi])),\n };\n }\n case FIELD_TYPES.abiVersion:\n case FIELD_TYPES.ttlType:\n return readInt(value);\n case FIELD_TYPES.id:\n return readId(value);\n case FIELD_TYPES.ids:\n return value.map(readId);\n case FIELD_TYPES.bool:\n return value[0] === 1;\n case FIELD_TYPES.binary:\n return encode(value, prefix as Encoding);\n case FIELD_TYPES.stateTree:\n return encode(value, Encoding.StateTrees);\n case FIELD_TYPES.string:\n return value.toString();\n case FIELD_TYPES.payload:\n return encode(value, Encoding.Bytearray);\n case FIELD_TYPES.pointers:\n return readPointers(value);\n case FIELD_TYPES.rlpBinary:\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return unpackTx(encode(value, Encoding.Transaction));\n case FIELD_TYPES.rlpBinaries:\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return value.map((v: Buffer) => unpackTx(encode(v, Encoding.Transaction)));\n case FIELD_TYPES.rawBinary:\n return value;\n case FIELD_TYPES.hex:\n return value.toString('hex');\n case FIELD_TYPES.offChainUpdates:\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return value.map((v: Buffer) => unpackTx(encode(v, Encoding.Transaction)));\n case FIELD_TYPES.callStack:\n // TODO: fix this\n return [readInt(value)];\n case FIELD_TYPES.mptrees:\n return value.map((t: MPTreeBinary) => new MPTree(t));\n case FIELD_TYPES.callReturnType:\n switch (readInt(value)) {\n case '0':\n return 'ok';\n case '1':\n return 'error';\n case '2':\n return 'revert';\n default:\n return value;\n }\n case FIELD_TYPES.sophiaCodeTypeInfo:\n return value.reduce(\n (acc: object, [funHash, fnName, argType, outType]: [\n funHash: Buffer,\n fnName: string,\n argType: string,\n outType: string,\n ]) => ({\n ...acc,\n [fnName.toString()]: { funHash, argType, outType },\n }),\n {},\n );\n default:\n if (typeof type === 'number') return value;\n return type.deserialize(value);\n }\n}\n\nfunction serializeField(value: any, type: FIELD_TYPES | Field, params: any): any {\n switch (type) {\n case FIELD_TYPES.abiVersion:\n case FIELD_TYPES.ttlType:\n return writeInt(value);\n case FIELD_TYPES.id:\n return writeId(value);\n case FIELD_TYPES.ids:\n return value.map(writeId);\n case FIELD_TYPES.bool:\n return Buffer.from([(value === true) ? 1 : 0]);\n case FIELD_TYPES.binary:\n return decode(value);\n case FIELD_TYPES.stateTree:\n return decode(value);\n case FIELD_TYPES.hex:\n return Buffer.from(value, 'hex');\n case FIELD_TYPES.signatures:\n return value.map(Buffer.from);\n case FIELD_TYPES.payload:\n return typeof value === 'string' && value.split('_')[0] === 'ba'\n ? decode(value as Encoded.Bytearray)\n : toBytes(value);\n case FIELD_TYPES.string:\n return toBytes(value);\n case FIELD_TYPES.pointers:\n return buildPointers(value);\n case FIELD_TYPES.rlpBinary:\n return value.rlpEncoded ?? value;\n case FIELD_TYPES.mptrees:\n return value.map((t: MPTree) => t.serialize());\n case FIELD_TYPES.ctVersion:\n return Buffer.from([...toBytes(value.vmVersion), 0, ...toBytes(value.abiVersion)]);\n case FIELD_TYPES.callReturnType:\n switch (value) {\n case 'ok': return writeInt(0);\n case 'error': return writeInt(1);\n case 'revert': return writeInt(2);\n default: return value;\n }\n default:\n if (typeof type === 'number') return value;\n // @ts-expect-error will be solved after removing the whole serializeField function\n return type.serialize(value, params);\n }\n}\n\nfunction validateField(\n value: any,\n type: FIELD_TYPES | Field,\n prefix?: Encoding | Encoding[],\n): string | undefined {\n // All fields are required\n if (value == null) return 'Field is required';\n\n // Validate type of value\n switch (type) {\n case FIELD_TYPES.id: {\n const prefixes = Array.isArray(prefix) ? prefix : [prefix];\n if (!prefixes.includes(value.split('_')[0])) {\n if (prefix == null) { return `'${String(value)}' prefix doesn't exist'`; }\n return `'${String(value)}' prefix doesn't match expected prefix '${prefix.toString()}'`;\n }\n return undefined;\n }\n case FIELD_TYPES.ctVersion:\n if (!(Boolean(value.abiVersion) && Boolean(value.vmVersion))) {\n return 'Value must be an object with \"vmVersion\" and \"abiVersion\" fields';\n }\n return undefined;\n case FIELD_TYPES.pointers:\n if (!Array.isArray(value)) return 'Value must be of type Array';\n if (value.some((p: NamePointer) => !(Boolean(p.key) && Boolean(p.id)))) {\n return 'Value must contains only object\\'s like \\'{key: \"account_pubkey\", id: \"ak_lkamsflkalsdalksdlasdlasdlamd\"}\\'';\n }\n if (value.length > 32) {\n return `Expected 32 pointers or less, got ${value.length} instead`;\n }\n return undefined;\n default:\n return undefined;\n }\n}\n\n/**\n * Validate transaction params\n * @category transaction builder\n * @param params - Object with tx params\n * @param schema - Transaction schema\n * @param excludeKeys - Array of keys to exclude for validation\n * @returns Object with validation errors\n */\nexport function validateParams(\n params: any,\n schema: TxField[],\n { excludeKeys = [] }: { excludeKeys: string[] },\n): object {\n return Object.fromEntries(\n schema\n // TODO: allow optional keys in schema\n .filter(([key]) => !excludeKeys.includes(key)\n && !['payload', 'nameFee', 'deposit', 'gasPrice', 'fee', 'gasLimit'].includes(key))\n .map(([key, type, prefix]) => [key, validateField(params[key], type, prefix)])\n .filter(([, message]) => message),\n );\n}\n\n/**\n * Unpack binary transaction\n * @category transaction builder\n * @param binary - Array with binary transaction field's\n * @param schema - Transaction schema\n * @returns Object with transaction field's\n */\nexport function unpackRawTx<Tx extends TxSchema>(\n binary: Uint8Array | NestedUint8Array,\n schema: TxField[],\n): RawTxObject<Tx> {\n return schema\n .reduce<any>(\n (\n acc,\n [key, fieldType, prefix],\n index,\n ) => Object.assign(acc, { [key]: deserializeField(binary[index], fieldType, prefix) }),\n {},\n );\n}\n\n/**\n * @category transaction builder\n */\nexport interface BuiltTx<Tx extends TxSchema, Prefix extends Encoding> {\n tx: Encoded.Generic<Prefix>;\n rlpEncoded: Uint8Array;\n binary: Uint8Array;\n txObject: RawTxObject<Tx>;\n}\n\n/**\n * Build transaction hash\n * @category transaction builder\n * @param _params - Object with tx params\n * @param type - Transaction type\n * @param options - options\n * @param options.excludeKeys - Array of keys to exclude for validation and build\n * @param options.denomination - Denomination of amounts\n * @param options.prefix - Prefix of transaction\n * @throws {@link InvalidTxParamsError}\n * @returns object\n * @returns object.tx Base64Check transaction hash with 'tx_' prefix\n * @returns object.rlpEncoded rlp encoded transaction\n * @returns object.binary binary transaction\n */\nexport function buildTx<TxType extends Tag, Prefix>(\n _params: Omit<TxTypeSchemas[TxType], 'tag' | 'VSN'> & { VSN?: number },\n type: TxType,\n {\n excludeKeys = [],\n prefix = Encoding.Transaction,\n vsn,\n denomination = AE_AMOUNT_FORMATS.AETTOS,\n }: {\n excludeKeys?: string[];\n prefix?: Encoding;\n vsn?: number;\n denomination?: AE_AMOUNT_FORMATS;\n } = {},\n): BuiltTx<TxSchema, Prefix extends Encoding ? Prefix : Encoding.Transaction> {\n const schemas = TX_SCHEMA[type];\n\n vsn ??= Math.max(...Object.keys(schemas).map((a) => +a));\n if (!isKeyOfObject(vsn, schemas)) throw new SchemaNotFoundError('serialization', Tag[type], vsn);\n\n const schema = schemas[vsn] as unknown as TxField[];\n\n const params = _params as TxParamsCommon & { onNode: Node; denomination?: AE_AMOUNT_FORMATS };\n params.VSN = vsn;\n params.tag = type;\n params.denomination = denomination;\n const filteredSchema = schema.filter(([key]) => !excludeKeys.includes(key));\n\n // Validation\n const valid = validateParams(params, schema, { excludeKeys });\n if (Object.keys(valid).length > 0) {\n throw new InvalidTxParamsError(`Transaction build error. ${JSON.stringify(valid)}`);\n }\n\n const binary = filteredSchema\n .map(([key, fieldType]: [keyof TxSchema, FIELD_TYPES, Encoding]) => (\n serializeField(\n params[key],\n fieldType,\n {\n ...params,\n txType: type,\n rebuildTx: (overrideParams: any) => buildTx(\n { ...params, ...overrideParams },\n type,\n {\n excludeKeys, prefix: Encoding.Transaction, vsn, denomination,\n },\n ),\n },\n )\n ))\n .filter((e) => e !== undefined);\n\n const rlpEncoded = rlpEncode(binary);\n const tx = encode(rlpEncoded, prefix);\n return {\n tx,\n rlpEncoded,\n binary,\n txObject: unpackRawTx<TxTypeSchemas[Tag]>(binary, schema),\n } as any;\n}\n\n/**\n * @category transaction builder\n */\nexport interface TxUnpacked<Tx extends TxSchema> {\n txType: Tag;\n tx: RawTxObject<Tx>;\n rlpEncoded: Uint8Array;\n}\n/**\n * Unpack transaction hash\n * @category transaction builder\n * @param encodedTx - Transaction to unpack\n * @param txType - Expected transaction type\n * @returns object\n * @returns object.tx Object with transaction param's\n * @returns object.txType Transaction type\n */\nexport function unpackTx<TxType extends Tag>(\n encodedTx: Encoded.Transaction | Encoded.Poi,\n txType?: TxType,\n): TxUnpacked<TxTypeSchemas[TxType]> {\n const rlpEncoded = decode(encodedTx);\n const binary = rlpDecode(rlpEncoded);\n const objId = +readInt(binary[0] as Buffer);\n if (!isKeyOfObject(objId, TX_SCHEMA)) throw new DecodeError(`Unknown transaction tag: ${objId}`);\n if (txType != null && txType !== objId) throw new DecodeError(`Expected transaction to have ${Tag[txType]} tag, got ${Tag[objId]} instead`);\n const vsn = +readInt(binary[1] as Buffer);\n if (!isKeyOfObject(vsn, TX_SCHEMA[objId])) throw new SchemaNotFoundError('deserialization', `tag ${objId}`, vsn);\n const schema = TX_SCHEMA[objId][vsn];\n return {\n txType: objId,\n tx: unpackRawTx<TxTypeSchemas[TxType]>(binary, schema),\n rlpEncoded,\n };\n}\n\n/**\n * Build a transaction hash\n * @category transaction builder\n * @param rawTx - base64 or rlp encoded transaction\n * @returns Transaction hash\n */\nexport function buildTxHash(rawTx: Encoded.Transaction | Uint8Array): Encoded.TxHash {\n const data = typeof rawTx === 'string' && rawTx.startsWith('tx_')\n ? decode(rawTx)\n : rawTx;\n return encode(hash(data), Encoding.TxHash);\n}\n\n/**\n * Build a contract public key by contractCreateTx or gaAttach\n * @category contract\n * @param contractTx - Transaction\n * @returns Contract public key\n */\nexport function buildContractIdByContractTx(\n contractTx: Encoded.Transaction,\n): Encoded.ContractAddress {\n const { txType, tx } = unpackTx<Tag.ContractCreateTx | Tag.GaAttachTx>(contractTx);\n if (![Tag.ContractCreateTx, Tag.GaAttachTx].includes(txType)) {\n throw new ArgumentError('contractCreateTx', 'a contractCreateTx or gaAttach', txType);\n }\n return buildContractId(tx.ownerId, +tx.nonce);\n}\n"],"mappings":";;;;;AAAA,iBAA2E,KAA3E;;;;;SAEEA,M,EAAQC,M,EAAiBC,Q;SAElBC,iB;SACAC,I;SAGPC,W,EAEAC,S;SAMOC,G;SAEPC,e,EAAiBC,a,EAAeC,O,EAASC,Y,EAAcC,Q;SAEhDC,M,EAAQC,O;SACRC,O;OACFC,M;SAELC,a,EACAC,W,EACAC,oB,EACAC,mB;SAEOC,a;;AAGT;AACA;AACA;AAEA;AACA,SAASC,gBAAT,CACEC,KADF,EAEEC,IAFF,EAGEC,MAHF,EAIO;EACL,IAAIF,KAAK,IAAI,IAAb,EAAmB,OAAO,EAAP;;EACnB,QAAQC,IAAR;IACE,KAAKnB,WAAW,CAACqB,SAAjB;MAA4B;QAC1B,MAAM,CAACC,EAAD,GAAOC,GAAP,IAAcL,KAApB;QACA,OAAO;UACLM,SAAS,EAAEnB,OAAO,CAAC,QAAOoB,IAAP,CAAY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,EAAMzF,SAAS,CAACgH,KAAD,CAAf,CAAlB,EAA2C,MAAM,IAAIlG,mBAAJ,CAAwB,iBAAxB,EAA4C,OAAMkG,KAAM,EAAxD,EAA2DvB,GAA3D,CAAN;EAC3C,MAAMZ,MAAM,GAAG7E,SAAS,CAACgH,KAAD,CAAT,CAAiBvB,GAAjB,CAAf;EACA,OAAO;IACLc,MAAM,EAAES,KADH;IAELJ,EAAE,EAAEzB,WAAW,CAAwBpD,MAAxB,EAAgC8C,MAAhC,CAFV;IAGLd;EAHK,CAAP;AAKD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASkD,WAAT,CAAqBC,KAArB,EAA8E;EACnF,MAAMC,IAAI,GAAG,OAAOD,KAAP,KAAiB,QAAjB,IAA6BA,KAAK,CAACE,UAAN,CAAiB,KAAjB,CAA7B,GACT1H,MAAM,CAACwH,KAAD,CADG,GAETA,KAFJ;EAGA,OAAOvH,MAAM,CAACG,IAAI,CAACqH,IAAD,CAAL,EAAavH,QAAQ,CAACyH,MAAtB,CAAb;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,2BAAT,CACLC,UADK,EAEoB;EAAA;;EACzB,MAAM;IAAEhB,MAAF;IAAUK;EAAV,IAAiBpE,QAAQ,CAAwC+E,UAAxC,CAA/B;;EACA,IAAI,CAAC,uCAACtH,GAAG,CAACuH,gBAAL,EAAuBvH,GAAG,CAACwH,UAA3B,mBAAgDlB,MAAhD,CAAL,EAA8D;IAC5D,MAAM,IAAI5F,aAAJ,CAAkB,kBAAlB,EAAsC,gCAAtC,EAAwE4F,MAAxE,CAAN;EACD;;EACD,OAAOrG,eAAe,CAAC0G,EAAE,CAACc,OAAJ,EAAa,CAACd,EAAE,CAACe,KAAjB,CAAtB;AACD"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["decode","encode","Encoding","AE_AMOUNT_FORMATS","hash","TX_SCHEMA","Tag","buildContractId","readInt","ArgumentError","DecodeError","SchemaNotFoundError","isKeyOfObject","unpackRawTx","binary","schema","length","reduce","acc","index","name","field","deserialized","deserialize","unpackTx","buildTx","params","prefix","denomination","AETTOS","schemas","tag","version","Math","max","Object","keys","map","a","key","serialize","rebuildTx","overrideParams","rlpEncode","Transaction","encodedTx","txType","rlpDecode","buildTxHash","rawTx","data","startsWith","TxHash","buildContractIdByContractTx","contractTx","ownerId","nonce","ContractCreateTx","GaAttachTx","includes"],"sources":["../../../src/tx/builder/index.ts"],"sourcesContent":["import { decode as rlpDecode, encode as rlpEncode, NestedUint8Array } from 'rlp';\nimport {\n decode, encode, Encoded, Encoding,\n} from '../../utils/encoder';\nimport { AE_AMOUNT_FORMATS } from '../../utils/amount-formatter';\nimport { hash } from '../../utils/crypto';\nimport { BinaryData, Field } from './field-types';\nimport {\n RawTxObject, TX_SCHEMA, TxField, TxSchema, TxTypeSchemas,\n} from './schema';\nimport { Tag } from './constants';\nimport { buildContractId, readInt } from './helpers';\nimport { ArgumentError, DecodeError, SchemaNotFoundError } from '../../utils/errors';\nimport { isKeyOfObject } from '../../utils/other';\n\n/**\n * JavaScript-based Transaction builder\n */\n\n/**\n * Unpack binary transaction\n * @category transaction builder\n * @param binary - Array with binary transaction field's\n * @param schema - Transaction schema\n * @returns Object with transaction field's\n */\nfunction unpackRawTx<Tx extends TxSchema>(\n binary: Uint8Array | NestedUint8Array,\n schema: TxField[],\n): RawTxObject<Tx> {\n if (binary.length !== schema.length) {\n throw new ArgumentError('Transaction RLP length', schema.length, binary.length);\n }\n return schema\n .reduce<any>(\n (\n acc,\n [name, field],\n index,\n ) => {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n const deserialized = field.deserialize(binary[index] as BinaryData, { unpackTx });\n return { ...acc, [name]: deserialized };\n },\n {},\n );\n}\n\n/**\n * Build transaction hash\n * @category transaction builder\n * @param params - Object with tx params\n * @param options - options\n * @param options.denomination - Denomination of amounts\n * @param options.prefix - Prefix of transaction\n * @throws {@link InvalidTxParamsError}\n * @returns object\n * @returns object.tx Base64Check transaction hash with 'tx_' prefix\n * @returns object.rlpEncoded rlp encoded transaction\n * @returns object.binary binary transaction\n */\nexport function buildTx<\n TxType extends Tag,\n E extends Encoding = Encoding.Transaction,\n>(\n params: { tag: TxType; version?: number } & Omit<TxTypeSchemas[TxType], 'tag' | 'version'>\n // TODO: get it from gas-limit.ts somehow\n & (TxType extends Tag.ContractCreateTx | Tag.ContractCallTx\n | Tag.ChannelOffChainUpdateCallContract | Tag.GaAttachTx | Tag.GaMetaTx\n ? { gasMax?: number } : {}),\n {\n prefix,\n denomination = AE_AMOUNT_FORMATS.AETTOS,\n }: {\n prefix?: E;\n denomination?: AE_AMOUNT_FORMATS;\n } = {},\n): Encoded.Generic<E> {\n const schemas = TX_SCHEMA[params.tag];\n params.version ??= Math.max(...Object.keys(schemas).map((a) => +a));\n if (!isKeyOfObject(params.version, schemas)) {\n throw new SchemaNotFoundError('serialization', Tag[params.tag], params.version);\n }\n const schema = schemas[params.version] as unknown as TxField[];\n\n const binary = schema.map(([key, field]: [keyof TxSchema, Field]) => (\n field.serialize(\n params[key],\n {\n ...params,\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n unpackTx,\n buildTx,\n denomination,\n rebuildTx: (overrideParams: any) => buildTx(\n { ...params, ...overrideParams },\n { denomination },\n ),\n },\n )\n ));\n\n // @ts-expect-error looks like a TypeScript edge case\n return encode(rlpEncode(binary), prefix ?? Encoding.Transaction);\n}\n\n/**\n * Unpack transaction hash\n * @category transaction builder\n * @param encodedTx - Transaction to unpack\n * @param txType - Expected transaction type\n * @returns object\n * @returns object.tx Object with transaction param's\n * @returns object.txType Transaction type\n */\nexport function unpackTx<TxType extends Tag>(\n encodedTx: Encoded.Transaction | Encoded.Poi,\n txType?: TxType,\n): RawTxObject<TxTypeSchemas[TxType]> {\n const binary = rlpDecode(decode(encodedTx));\n const tag = +readInt(binary[0] as Buffer);\n if (!isKeyOfObject(tag, TX_SCHEMA)) throw new DecodeError(`Unknown transaction tag: ${tag}`);\n if (txType != null && txType !== tag) throw new DecodeError(`Expected transaction to have ${Tag[txType]} tag, got ${Tag[tag]} instead`);\n const version = +readInt(binary[1] as Buffer);\n if (!isKeyOfObject(version, TX_SCHEMA[tag])) throw new SchemaNotFoundError('deserialization', `tag ${tag}`, version);\n const schema = TX_SCHEMA[tag][version];\n return unpackRawTx<TxTypeSchemas[TxType]>(binary, schema);\n}\n\n/**\n * Build a transaction hash\n * @category transaction builder\n * @param rawTx - base64 or rlp encoded transaction\n * @returns Transaction hash\n */\nexport function buildTxHash(rawTx: Encoded.Transaction | Uint8Array): Encoded.TxHash {\n const data = typeof rawTx === 'string' && rawTx.startsWith('tx_')\n ? decode(rawTx)\n : rawTx;\n return encode(hash(data), Encoding.TxHash);\n}\n\n/**\n * Build a contract public key by contractCreateTx or gaAttach\n * @category contract\n * @param contractTx - Transaction\n * @returns Contract public key\n */\nexport function buildContractIdByContractTx(\n contractTx: Encoded.Transaction,\n): Encoded.ContractAddress {\n const { tag, ownerId, nonce } = unpackTx<Tag.ContractCreateTx | Tag.GaAttachTx>(contractTx);\n if (![Tag.ContractCreateTx, Tag.GaAttachTx].includes(tag)) {\n throw new ArgumentError('contractCreateTx', 'a contractCreateTx or gaAttach', tag);\n }\n return buildContractId(ownerId, +nonce);\n}\n"],"mappings":"AAAA,iBAA2E,KAAK;AAAC;EAAA;EAAA;AAAA;AAAA,SAE/EA,MAAM,EAAEC,MAAM,EAAWC,QAAQ;AAAA,SAE1BC,iBAAiB;AAAA,SACjBC,IAAI;AAAA,SAGEC,SAAS;AAAA,SAEfC,GAAG;AAAA,SACHC,eAAe,EAAEC,OAAO;AAAA,SACxBC,aAAa,EAAEC,WAAW,EAAEC,mBAAmB;AAAA,SAC/CC,aAAa;AAEtB;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,WAAW,CAClBC,MAAqC,EACrCC,MAAiB,EACA;EACjB,IAAID,MAAM,CAACE,MAAM,KAAKD,MAAM,CAACC,MAA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