@aeternity/aepp-sdk 13.2.2 → 13.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/bin/aesophia_cli +0 -0
- package/bin/aesophia_cli_8 +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 +9171 -7086
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +3 -0
- package/es/AeSdk.mjs +12 -12
- package/es/AeSdk.mjs.map +1 -1
- package/es/AeSdkAepp.d.ts +0 -1
- package/es/AeSdkAepp.mjs +12 -16
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +61 -6
- package/es/AeSdkBase.mjs +150 -69
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkMethods.d.ts +19 -7
- package/es/AeSdkMethods.mjs +39 -38
- package/es/AeSdkMethods.mjs.map +1 -1
- package/es/AeSdkWallet.mjs +86 -55
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Middleware.mjs +31 -27
- package/es/Middleware.mjs.map +1 -1
- package/es/MiddlewareSubscriber.mjs +5 -14
- package/es/MiddlewareSubscriber.mjs.map +1 -1
- package/es/Node.d.ts +10 -2
- package/es/Node.mjs +53 -54
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +39 -3
- package/es/account/Base.mjs +35 -1
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Generalized.d.ts +2 -0
- package/es/account/Generalized.mjs +15 -6
- package/es/account/Generalized.mjs.map +1 -1
- package/es/account/Ledger.d.ts +2 -0
- package/es/account/Ledger.mjs +14 -5
- package/es/account/Ledger.mjs.map +1 -1
- package/es/account/LedgerFactory.mjs +4 -6
- package/es/account/LedgerFactory.mjs.map +1 -1
- package/es/account/Memory.d.ts +15 -4
- package/es/account/Memory.mjs +96 -31
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +16 -5
- package/es/account/Rpc.mjs +94 -21
- package/es/account/Rpc.mjs.map +1 -1
- package/es/aens.d.ts +17 -44
- package/es/aens.mjs +32 -71
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/Browser.mjs +3 -4
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +3 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +7 -5
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +8 -9
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +7 -7
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +14 -0
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.d.ts +2 -0
- package/es/aepp-wallet-communication/schema.mjs +2 -0
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.mjs +4 -5
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/compiler/compiler.mjs.map +1 -1
- package/es/apis/compiler/models/index.d.ts +1 -0
- package/es/apis/compiler/models/index.mjs.map +1 -1
- package/es/apis/compiler/models/mappers.mjs +13 -0
- package/es/apis/compiler/models/mappers.mjs.map +1 -1
- package/es/apis/compiler/models/parameters.mjs.map +1 -1
- package/es/apis/middleware/middleware.d.ts +23 -5
- package/es/apis/middleware/middleware.mjs +114 -18
- package/es/apis/middleware/middleware.mjs.map +1 -1
- package/es/apis/middleware/models/index.d.ts +164 -15
- package/es/apis/middleware/models/index.mjs +53 -3
- package/es/apis/middleware/models/index.mjs.map +1 -1
- package/es/apis/middleware/models/mappers.d.ts +8 -1
- package/es/apis/middleware/models/mappers.mjs +376 -3
- package/es/apis/middleware/models/mappers.mjs.map +1 -1
- package/es/apis/middleware/models/parameters.d.ts +6 -3
- package/es/apis/middleware/models/parameters.mjs +38 -11
- package/es/apis/middleware/models/parameters.mjs.map +1 -1
- package/es/apis/node/models/index.d.ts +66 -2
- package/es/apis/node/models/index.mjs.map +1 -1
- package/es/apis/node/models/mappers.d.ts +5 -1
- package/es/apis/node/models/mappers.mjs +229 -7
- package/es/apis/node/models/mappers.mjs.map +1 -1
- package/es/apis/node/models/parameters.d.ts +2 -2
- package/es/apis/node/models/parameters.mjs +2 -2
- package/es/apis/node/models/parameters.mjs.map +1 -1
- package/es/apis/node/node.d.ts +24 -3
- package/es/apis/node/node.mjs +135 -3
- package/es/apis/node/node.mjs.map +1 -1
- package/es/chain.d.ts +14 -44
- package/es/chain.mjs +125 -219
- package/es/chain.mjs.map +1 -1
- package/es/channel/Base.d.ts +3 -47
- package/es/channel/Base.mjs +21 -54
- package/es/channel/Base.mjs.map +1 -1
- package/es/channel/Contract.d.ts +16 -25
- package/es/channel/Contract.mjs +39 -63
- package/es/channel/Contract.mjs.map +1 -1
- package/es/channel/Spend.d.ts +0 -8
- package/es/channel/Spend.mjs +17 -29
- package/es/channel/Spend.mjs.map +1 -1
- package/es/channel/handlers.mjs +1 -1
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/internal.d.ts +104 -5
- package/es/channel/internal.mjs +26 -34
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Contract.d.ts +9 -1
- package/es/contract/Contract.mjs +67 -73
- package/es/contract/Contract.mjs.map +1 -1
- package/es/contract/compiler/Base.d.ts +14 -8
- package/es/contract/compiler/Base.mjs.map +1 -1
- package/es/contract/compiler/Cli.d.ts +5 -9
- package/es/contract/compiler/Cli.mjs +45 -23
- package/es/contract/compiler/Cli.mjs.map +1 -1
- package/es/contract/compiler/Cli8.d.ts +13 -0
- package/es/contract/compiler/Cli8.mjs +22 -0
- package/es/contract/compiler/Cli8.mjs.map +1 -0
- package/es/contract/compiler/Http.d.ts +3 -9
- package/es/contract/compiler/Http.mjs +28 -16
- package/es/contract/compiler/Http.mjs.map +1 -1
- package/es/contract/compiler/HttpNode.d.ts +2 -5
- package/es/contract/compiler/HttpNode.mjs.map +1 -1
- package/es/contract/delegation-signature.d.ts +2 -1
- package/es/contract/delegation-signature.mjs +18 -14
- package/es/contract/delegation-signature.mjs.map +1 -1
- package/es/contract/ga.d.ts +1 -2
- package/es/contract/ga.mjs +23 -25
- package/es/contract/ga.mjs.map +1 -1
- package/es/deprecated.d.ts +38 -0
- package/es/deprecated.mjs +45 -0
- package/es/deprecated.mjs.map +1 -1
- package/es/index-browser.d.ts +10 -5
- package/es/index-browser.mjs +9 -5
- package/es/index-browser.mjs.map +1 -1
- package/es/index.d.ts +1 -0
- package/es/index.mjs +1 -0
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +6 -37
- package/es/oracle.mjs +32 -66
- package/es/oracle.mjs.map +1 -1
- package/es/send-transaction.d.ts +53 -0
- package/es/send-transaction.mjs +109 -0
- package/es/send-transaction.mjs.map +1 -0
- package/es/spend.d.ts +4 -3
- package/es/spend.mjs +6 -1
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/common.d.ts +29 -0
- package/es/tx/builder/common.mjs +42 -0
- package/es/tx/builder/common.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +4 -4
- package/es/tx/builder/constants.mjs +6 -15
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/delegation/index.d.ts +20 -0
- package/es/tx/builder/delegation/index.mjs +24 -0
- package/es/tx/builder/delegation/index.mjs.map +1 -0
- package/es/tx/builder/delegation/schema.d.ts +130 -0
- package/es/tx/builder/delegation/schema.generated.d.ts +141 -0
- package/es/tx/builder/delegation/schema.generated.mjs +2 -0
- package/es/tx/builder/delegation/schema.generated.mjs.map +1 -0
- package/es/tx/builder/delegation/schema.mjs +54 -0
- package/es/tx/builder/delegation/schema.mjs.map +1 -0
- package/es/tx/builder/field-types/abi-version.mjs +8 -11
- package/es/tx/builder/field-types/abi-version.mjs.map +1 -1
- package/es/tx/builder/field-types/address.mjs +1 -4
- package/es/tx/builder/field-types/address.mjs.map +1 -1
- package/es/tx/builder/field-types/coin-amount.d.ts +2 -2
- package/es/tx/builder/field-types/coin-amount.mjs +6 -6
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
- package/es/tx/builder/field-types/ct-version.mjs +3 -4
- package/es/tx/builder/field-types/ct-version.mjs.map +1 -1
- package/es/tx/builder/field-types/entry.mjs +7 -13
- package/es/tx/builder/field-types/entry.mjs.map +1 -1
- package/es/tx/builder/field-types/fee.d.ts +19 -11
- package/es/tx/builder/field-types/fee.mjs +56 -38
- package/es/tx/builder/field-types/fee.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-limit.mjs +13 -15
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-price.d.ts +10 -2
- package/es/tx/builder/field-types/gas-price.mjs +52 -3
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
- package/es/tx/builder/field-types/index.d.ts +31 -29
- package/es/tx/builder/field-types/index.mjs +31 -29
- package/es/tx/builder/field-types/index.mjs.map +1 -1
- package/es/tx/builder/field-types/map.mjs +20 -31
- package/es/tx/builder/field-types/map.mjs.map +1 -1
- package/es/tx/builder/field-types/mptree.mjs +14 -29
- package/es/tx/builder/field-types/mptree.mjs.map +1 -1
- package/es/tx/builder/field-types/name-fee.d.ts +1 -1
- package/es/tx/builder/field-types/name-fee.mjs +1 -1
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
- package/es/tx/builder/field-types/nonce.d.ts +1 -0
- package/es/tx/builder/field-types/nonce.mjs +2 -0
- package/es/tx/builder/field-types/nonce.mjs.map +1 -1
- package/es/tx/builder/field-types/pointers.mjs +4 -7
- package/es/tx/builder/field-types/pointers.mjs.map +1 -1
- package/es/tx/builder/field-types/pointers2.d.ts +23 -0
- package/es/tx/builder/field-types/pointers2.mjs +65 -0
- package/es/tx/builder/field-types/pointers2.mjs.map +1 -0
- package/es/tx/builder/field-types/query-fee.d.ts +19 -0
- package/es/tx/builder/field-types/query-fee.mjs +20 -0
- package/es/tx/builder/field-types/query-fee.mjs.map +1 -0
- package/es/tx/builder/field-types/ttl.d.ts +9 -1
- package/es/tx/builder/field-types/ttl.mjs +19 -8
- package/es/tx/builder/field-types/ttl.mjs.map +1 -1
- package/es/tx/builder/field-types/with-default.d.ts +7 -0
- package/es/tx/builder/field-types/with-default.mjs +9 -0
- package/es/tx/builder/field-types/with-default.mjs.map +1 -0
- package/es/tx/builder/field-types/with-formatting.d.ts +7 -0
- package/es/tx/builder/field-types/with-formatting.mjs +9 -0
- package/es/tx/builder/field-types/with-formatting.mjs.map +1 -0
- package/es/tx/builder/field-types/wrapped.mjs +6 -8
- package/es/tx/builder/field-types/wrapped.mjs.map +1 -1
- package/es/tx/builder/helpers.d.ts +2 -2
- package/es/tx/builder/helpers.mjs +12 -21
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +17 -10
- package/es/tx/builder/index.mjs +39 -65
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +478 -257
- package/es/tx/builder/schema.generated.d.ts +39 -3
- package/es/tx/builder/schema.generated.mjs.map +1 -1
- package/es/tx/builder/schema.mjs +48 -36
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/execution-cost.d.ts +6 -5
- package/es/tx/execution-cost.mjs +16 -17
- package/es/tx/execution-cost.mjs.map +1 -1
- package/es/tx/transaction-signer.mjs +1 -4
- package/es/tx/transaction-signer.mjs.map +1 -1
- package/es/tx/validator.mjs +61 -42
- package/es/tx/validator.mjs.map +1 -1
- package/es/utils/amount-formatter.mjs +15 -22
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.d.ts +2 -3
- package/es/utils/autorest.mjs +40 -24
- package/es/utils/autorest.mjs.map +1 -1
- package/es/utils/bytes.mjs +1 -2
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +8 -4
- package/es/utils/crypto.mjs +17 -13
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/errors.d.ts +6 -0
- package/es/utils/errors.mjs +12 -6
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +2 -0
- package/es/utils/hd-wallet.mjs +6 -5
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.mjs +2 -10
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/jwt.d.ts +53 -0
- package/es/utils/jwt.mjs +120 -0
- package/es/utils/jwt.mjs.map +1 -0
- package/es/utils/keystore.d.ts +6 -2
- package/es/utils/keystore.mjs +8 -16
- package/es/utils/keystore.mjs.map +1 -1
- package/es/utils/typed-data.mjs +1 -0
- package/es/utils/typed-data.mjs.map +1 -1
- package/es/utils/wrap-proxy.d.ts +2 -0
- package/es/utils/wrap-proxy.mjs +15 -0
- package/es/utils/wrap-proxy.mjs.map +1 -0
- package/package.json +57 -51
- package/src/AeSdk.ts +3 -0
- package/src/AeSdkAepp.ts +0 -1
- package/src/AeSdkBase.ts +97 -10
- package/src/AeSdkMethods.ts +37 -33
- package/src/AeSdkWallet.ts +22 -3
- package/src/Middleware.ts +16 -8
- package/src/MiddlewareSubscriber.ts +1 -1
- package/src/Node.ts +37 -18
- package/src/account/Base.ts +62 -3
- package/src/account/Generalized.ts +10 -0
- package/src/account/Ledger.ts +10 -0
- package/src/account/Memory.ts +83 -9
- package/src/account/Rpc.ts +69 -6
- package/src/aens.ts +35 -56
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +3 -0
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +2 -2
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +4 -2
- package/src/aepp-wallet-communication/rpc/types.ts +13 -0
- package/src/aepp-wallet-communication/schema.ts +2 -0
- package/src/apis/compiler/compiler.ts +93 -93
- package/src/apis/compiler/models/index.ts +1 -0
- package/src/apis/compiler/models/mappers.ts +178 -165
- package/src/apis/compiler/models/parameters.ts +18 -18
- package/src/apis/middleware/middleware.ts +462 -341
- package/src/apis/middleware/models/index.ts +258 -56
- package/src/apis/middleware/models/mappers.ts +2357 -1919
- package/src/apis/middleware/models/parameters.ts +172 -142
- package/src/apis/node/models/index.ts +79 -2
- package/src/apis/node/models/mappers.ts +1529 -1302
- package/src/apis/node/models/parameters.ts +51 -51
- package/src/apis/node/node.ts +420 -275
- package/src/chain.ts +42 -128
- package/src/channel/Base.ts +14 -47
- package/src/channel/Contract.ts +18 -26
- package/src/channel/Spend.ts +0 -8
- package/src/channel/internal.ts +115 -13
- package/src/contract/Contract.ts +26 -8
- package/src/contract/compiler/Base.ts +15 -8
- package/src/contract/compiler/Cli.ts +37 -21
- package/src/contract/compiler/Cli8.ts +17 -0
- package/src/contract/compiler/Http.ts +24 -14
- package/src/contract/compiler/HttpNode.ts +2 -2
- package/src/contract/delegation-signature.ts +11 -5
- package/src/contract/ga.ts +4 -3
- package/src/deprecated.ts +36 -0
- package/src/index-browser.ts +14 -7
- package/src/index.ts +1 -0
- package/src/oracle.ts +11 -54
- package/src/send-transaction.ts +136 -0
- package/src/spend.ts +25 -11
- package/src/tx/builder/common.ts +74 -0
- package/src/tx/builder/constants.ts +6 -9
- package/src/tx/builder/delegation/index.ts +28 -0
- package/src/tx/builder/delegation/schema.generated.ts +143 -0
- package/src/tx/builder/delegation/schema.ts +61 -0
- package/src/tx/builder/field-types/coin-amount.ts +3 -2
- package/src/tx/builder/field-types/entry.ts +1 -4
- package/src/tx/builder/field-types/fee.ts +71 -43
- package/src/tx/builder/field-types/gas-limit.ts +4 -4
- package/src/tx/builder/field-types/gas-price.ts +58 -2
- package/src/tx/builder/field-types/index.ts +31 -59
- package/src/tx/builder/field-types/name-fee.ts +1 -1
- package/src/tx/builder/field-types/nonce.ts +7 -1
- package/src/tx/builder/field-types/pointers2.ts +62 -0
- package/src/tx/builder/field-types/query-fee.ts +25 -0
- package/src/tx/builder/field-types/ttl.ts +13 -3
- package/src/tx/builder/field-types/with-default.ts +18 -0
- package/src/tx/builder/field-types/with-formatting.ts +18 -0
- package/src/tx/builder/helpers.ts +2 -2
- package/src/tx/builder/index.ts +42 -59
- package/src/tx/builder/schema.generated.ts +39 -3
- package/src/tx/builder/schema.ts +55 -29
- package/src/tx/execution-cost.ts +6 -5
- package/src/tx/validator.ts +31 -5
- package/src/utils/autorest.ts +36 -27
- package/src/utils/crypto.ts +23 -13
- package/src/utils/errors.ts +10 -0
- package/src/utils/hd-wallet.ts +2 -0
- package/src/utils/jwt.ts +126 -0
- package/src/utils/keystore.ts +6 -2
- package/src/utils/wrap-proxy.ts +24 -0
- package/types-legacy/ts4.2/AeSdk.d.ts +3 -0
- package/types-legacy/ts4.2/AeSdkAepp.d.ts +0 -1
- package/types-legacy/ts4.2/AeSdkBase.d.ts +61 -6
- package/types-legacy/ts4.2/AeSdkMethods.d.ts +19 -7
- package/types-legacy/ts4.2/Node.d.ts +14 -1
- package/types-legacy/ts4.2/account/Base.d.ts +39 -3
- package/types-legacy/ts4.2/account/Generalized.d.ts +2 -0
- package/types-legacy/ts4.2/account/Ledger.d.ts +2 -0
- package/types-legacy/ts4.2/account/Memory.d.ts +15 -4
- package/types-legacy/ts4.2/account/Rpc.d.ts +16 -5
- package/types-legacy/ts4.2/aens.d.ts +17 -44
- package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserRuntime.d.ts +3 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +14 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/schema.d.ts +2 -0
- package/types-legacy/ts4.2/apis/compiler/models/index.d.ts +1 -0
- package/types-legacy/ts4.2/apis/middleware/middleware.d.ts +23 -5
- package/types-legacy/ts4.2/apis/middleware/models/index.d.ts +164 -15
- package/types-legacy/ts4.2/apis/middleware/models/mappers.d.ts +8 -1
- package/types-legacy/ts4.2/apis/middleware/models/parameters.d.ts +6 -3
- package/types-legacy/ts4.2/apis/node/models/index.d.ts +66 -2
- package/types-legacy/ts4.2/apis/node/models/mappers.d.ts +5 -1
- package/types-legacy/ts4.2/apis/node/models/parameters.d.ts +2 -2
- package/types-legacy/ts4.2/apis/node/node.d.ts +24 -3
- package/types-legacy/ts4.2/chain.d.ts +14 -44
- package/types-legacy/ts4.2/channel/Base.d.ts +3 -47
- package/types-legacy/ts4.2/channel/Contract.d.ts +16 -25
- package/types-legacy/ts4.2/channel/Spend.d.ts +0 -8
- package/types-legacy/ts4.2/channel/internal.d.ts +104 -5
- package/types-legacy/ts4.2/contract/Contract.d.ts +9 -1
- package/types-legacy/ts4.2/contract/compiler/Base.d.ts +14 -8
- package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +5 -9
- package/types-legacy/ts4.2/contract/compiler/Cli8.d.ts +13 -0
- package/types-legacy/ts4.2/contract/compiler/Http.d.ts +3 -9
- package/types-legacy/ts4.2/contract/compiler/HttpNode.d.ts +2 -5
- package/types-legacy/ts4.2/contract/delegation-signature.d.ts +2 -1
- package/types-legacy/ts4.2/contract/ga.d.ts +1 -2
- package/types-legacy/ts4.2/deprecated.d.ts +38 -0
- package/types-legacy/ts4.2/index-browser.d.ts +10 -5
- package/types-legacy/ts4.2/index.d.ts +1 -0
- package/types-legacy/ts4.2/oracle.d.ts +6 -37
- package/types-legacy/ts4.2/send-transaction.d.ts +53 -0
- package/types-legacy/ts4.2/spend.d.ts +4 -3
- package/types-legacy/ts4.2/tx/builder/common.d.ts +32 -0
- package/types-legacy/ts4.2/tx/builder/constants.d.ts +4 -4
- package/types-legacy/ts4.2/tx/builder/delegation/index.d.ts +20 -0
- package/types-legacy/ts4.2/tx/builder/delegation/schema.d.ts +136 -0
- package/types-legacy/ts4.2/tx/builder/delegation/schema.generated.d.ts +141 -0
- package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +2 -2
- package/types-legacy/ts4.2/tx/builder/field-types/fee.d.ts +19 -11
- package/types-legacy/ts4.2/tx/builder/field-types/gas-price.d.ts +10 -2
- package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +31 -29
- package/types-legacy/ts4.2/tx/builder/field-types/name-fee.d.ts +1 -1
- package/types-legacy/ts4.2/tx/builder/field-types/nonce.d.ts +1 -0
- package/types-legacy/ts4.2/tx/builder/field-types/pointers2.d.ts +26 -0
- package/types-legacy/ts4.2/tx/builder/field-types/query-fee.d.ts +19 -0
- package/types-legacy/ts4.2/tx/builder/field-types/ttl.d.ts +9 -1
- package/types-legacy/ts4.2/tx/builder/field-types/with-default.d.ts +7 -0
- package/types-legacy/ts4.2/tx/builder/field-types/with-formatting.d.ts +7 -0
- package/types-legacy/ts4.2/tx/builder/helpers.d.ts +2 -2
- package/types-legacy/ts4.2/tx/builder/index.d.ts +17 -10
- package/types-legacy/ts4.2/tx/builder/schema.d.ts +482 -257
- package/types-legacy/ts4.2/tx/builder/schema.generated.d.ts +39 -3
- package/types-legacy/ts4.2/tx/execution-cost.d.ts +6 -5
- package/types-legacy/ts4.2/utils/autorest.d.ts +2 -3
- package/types-legacy/ts4.2/utils/crypto.d.ts +8 -4
- package/types-legacy/ts4.2/utils/errors.d.ts +6 -0
- package/types-legacy/ts4.2/utils/hd-wallet.d.ts +2 -0
- package/types-legacy/ts4.2/utils/jwt.d.ts +53 -0
- package/types-legacy/ts4.2/utils/keystore.d.ts +6 -2
- package/types-legacy/ts4.2/utils/wrap-proxy.d.ts +2 -0
- package/types-legacy/ts4.5/AeSdk.d.ts +3 -0
- package/types-legacy/ts4.5/AeSdkAepp.d.ts +0 -1
- package/types-legacy/ts4.5/AeSdkBase.d.ts +61 -6
- package/types-legacy/ts4.5/AeSdkMethods.d.ts +19 -7
- package/types-legacy/ts4.5/Node.d.ts +14 -1
- package/types-legacy/ts4.5/account/Base.d.ts +39 -3
- package/types-legacy/ts4.5/account/Generalized.d.ts +2 -0
- package/types-legacy/ts4.5/account/Ledger.d.ts +2 -0
- package/types-legacy/ts4.5/account/Memory.d.ts +15 -4
- package/types-legacy/ts4.5/account/Rpc.d.ts +16 -5
- package/types-legacy/ts4.5/aens.d.ts +17 -44
- package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserRuntime.d.ts +3 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +14 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/schema.d.ts +2 -0
- package/types-legacy/ts4.5/apis/compiler/models/index.d.ts +1 -0
- package/types-legacy/ts4.5/apis/middleware/middleware.d.ts +23 -5
- package/types-legacy/ts4.5/apis/middleware/models/index.d.ts +164 -15
- package/types-legacy/ts4.5/apis/middleware/models/mappers.d.ts +8 -1
- package/types-legacy/ts4.5/apis/middleware/models/parameters.d.ts +6 -3
- package/types-legacy/ts4.5/apis/node/models/index.d.ts +66 -2
- package/types-legacy/ts4.5/apis/node/models/mappers.d.ts +5 -1
- package/types-legacy/ts4.5/apis/node/models/parameters.d.ts +2 -2
- package/types-legacy/ts4.5/apis/node/node.d.ts +24 -3
- package/types-legacy/ts4.5/chain.d.ts +14 -44
- package/types-legacy/ts4.5/channel/Base.d.ts +3 -47
- package/types-legacy/ts4.5/channel/Contract.d.ts +16 -25
- package/types-legacy/ts4.5/channel/Spend.d.ts +0 -8
- package/types-legacy/ts4.5/channel/internal.d.ts +104 -5
- package/types-legacy/ts4.5/contract/Contract.d.ts +9 -1
- package/types-legacy/ts4.5/contract/compiler/Base.d.ts +14 -8
- package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +5 -9
- package/types-legacy/ts4.5/contract/compiler/Cli8.d.ts +13 -0
- package/types-legacy/ts4.5/contract/compiler/Http.d.ts +3 -9
- package/types-legacy/ts4.5/contract/compiler/HttpNode.d.ts +2 -5
- package/types-legacy/ts4.5/contract/delegation-signature.d.ts +2 -1
- package/types-legacy/ts4.5/contract/ga.d.ts +1 -2
- package/types-legacy/ts4.5/deprecated.d.ts +38 -0
- package/types-legacy/ts4.5/index-browser.d.ts +10 -5
- package/types-legacy/ts4.5/index.d.ts +1 -0
- package/types-legacy/ts4.5/oracle.d.ts +6 -37
- package/types-legacy/ts4.5/send-transaction.d.ts +53 -0
- package/types-legacy/ts4.5/spend.d.ts +4 -3
- package/types-legacy/ts4.5/tx/builder/common.d.ts +32 -0
- package/types-legacy/ts4.5/tx/builder/constants.d.ts +4 -4
- package/types-legacy/ts4.5/tx/builder/delegation/index.d.ts +20 -0
- package/types-legacy/ts4.5/tx/builder/delegation/schema.d.ts +136 -0
- package/types-legacy/ts4.5/tx/builder/delegation/schema.generated.d.ts +141 -0
- package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +2 -2
- package/types-legacy/ts4.5/tx/builder/field-types/fee.d.ts +19 -11
- package/types-legacy/ts4.5/tx/builder/field-types/gas-price.d.ts +10 -2
- package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +31 -29
- package/types-legacy/ts4.5/tx/builder/field-types/name-fee.d.ts +1 -1
- package/types-legacy/ts4.5/tx/builder/field-types/nonce.d.ts +1 -0
- package/types-legacy/ts4.5/tx/builder/field-types/pointers2.d.ts +26 -0
- package/types-legacy/ts4.5/tx/builder/field-types/query-fee.d.ts +19 -0
- package/types-legacy/ts4.5/tx/builder/field-types/ttl.d.ts +9 -1
- package/types-legacy/ts4.5/tx/builder/field-types/with-default.d.ts +7 -0
- package/types-legacy/ts4.5/tx/builder/field-types/with-formatting.d.ts +7 -0
- package/types-legacy/ts4.5/tx/builder/helpers.d.ts +2 -2
- package/types-legacy/ts4.5/tx/builder/index.d.ts +17 -10
- package/types-legacy/ts4.5/tx/builder/schema.d.ts +482 -257
- package/types-legacy/ts4.5/tx/builder/schema.generated.d.ts +39 -3
- package/types-legacy/ts4.5/tx/execution-cost.d.ts +6 -5
- package/types-legacy/ts4.5/utils/autorest.d.ts +2 -3
- package/types-legacy/ts4.5/utils/crypto.d.ts +8 -4
- package/types-legacy/ts4.5/utils/errors.d.ts +6 -0
- package/types-legacy/ts4.5/utils/hd-wallet.d.ts +2 -0
- package/types-legacy/ts4.5/utils/jwt.d.ts +53 -0
- package/types-legacy/ts4.5/utils/keystore.d.ts +6 -2
- package/types-legacy/ts4.5/utils/wrap-proxy.d.ts +2 -0
- package/es/tx/builder/field-types/deposit.d.ts +0 -15
- package/es/tx/builder/field-types/deposit.mjs +0 -18
- package/es/tx/builder/field-types/deposit.mjs.map +0 -1
- package/src/tx/builder/field-types/deposit.ts +0 -23
- package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +0 -15
- package/types-legacy/ts4.5/tx/builder/field-types/deposit.d.ts +0 -15
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-default.mjs","names":["withDefault","defaultValue","field","serialize","value","params"],"sources":["../../../../src/tx/builder/field-types/with-default.ts"],"sourcesContent":["export default function withDefault<Input, Output, Binary>(\n defaultValue: Input,\n field: {\n serialize: (value: Input, params: unknown) => Binary;\n deserialize: (value: Binary, params: unknown) => Output;\n },\n): {\n serialize: (value: Input | undefined, params: unknown) => Binary;\n deserialize: (value: Binary, params: unknown) => Output;\n } {\n return {\n ...field,\n\n serialize(value, params) {\n return field.serialize(value ?? defaultValue, params);\n },\n };\n}\n"],"mappings":"AAAA,eAAe,SAASA,WAAWA,CACjCC,YAAmB,EACnBC,KAGC,EAIC;EACF,OAAO;IACL,GAAGA,KAAK;IAERC,SAASA,CAACC,KAAK,EAAEC,MAAM,EAAE;MACvB,OAAOH,KAAK,CAACC,SAAS,CAACC,KAAK,aAALA,KAAK,cAALA,KAAK,GAAIH,YAAY,EAAEI,MAAM,CAAC;IACvD;EACF,CAAC;AACH"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export default function withFormatting<Input, Output, Binary, Params, Options>(format: (v: Input | undefined) => Input, field: {
|
|
2
|
+
serialize: (value: Input, params: Params, options: Options) => Binary;
|
|
3
|
+
deserialize: (value: Binary) => Output;
|
|
4
|
+
}): {
|
|
5
|
+
serialize: (value: Input | undefined, params: Params, options: Options) => Binary;
|
|
6
|
+
deserialize: (value: Binary) => Output;
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-formatting.mjs","names":["withFormatting","format","field","serialize","value","params","options"],"sources":["../../../../src/tx/builder/field-types/with-formatting.ts"],"sourcesContent":["export default function withFormatting<Input, Output, Binary, Params, Options>(\n format: (v: Input | undefined) => Input,\n field: {\n serialize: (value: Input, params: Params, options: Options) => Binary;\n deserialize: (value: Binary) => Output;\n },\n): {\n serialize: (value: Input | undefined, params: Params, options: Options) => Binary;\n deserialize: (value: Binary) => Output;\n } {\n return {\n ...field,\n\n serialize(value, params, options) {\n return field.serialize(format(value), params, options);\n },\n };\n}\n"],"mappings":"AAAA,eAAe,SAASA,cAAcA,CACpCC,MAAuC,EACvCC,KAGC,EAIC;EACF,OAAO;IACL,GAAGA,KAAK;IAERC,SAASA,CAACC,KAAK,EAAEC,MAAM,EAAEC,OAAO,EAAE;MAChC,OAAOJ,KAAK,CAACC,SAAS,CAACF,MAAM,CAACG,KAAK,CAAC,EAAEC,MAAM,EAAEC,OAAO,CAAC;IACxD;EACF,CAAC;AACH"}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import { encode, Encoding, decode } from "../../../utils/encoder.mjs";
|
|
2
2
|
export default function genWrappedField(tag) {
|
|
3
3
|
return {
|
|
4
|
-
serialize(payload,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} = _ref;
|
|
4
|
+
serialize(payload, {
|
|
5
|
+
buildTx
|
|
6
|
+
}) {
|
|
8
7
|
return decode(buildTx({
|
|
9
8
|
tag,
|
|
10
9
|
payload
|
|
11
10
|
}));
|
|
12
11
|
},
|
|
13
|
-
deserialize(buffer,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} = _ref2;
|
|
12
|
+
deserialize(buffer, {
|
|
13
|
+
unpackTx
|
|
14
|
+
}) {
|
|
17
15
|
return unpackTx(encode(buffer, Encoding.Transaction), tag).payload;
|
|
18
16
|
},
|
|
19
17
|
recursiveType: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapped.mjs","names":["encode","Encoding","decode","genWrappedField","tag","serialize","payload","
|
|
1
|
+
{"version":3,"file":"wrapped.mjs","names":["encode","Encoding","decode","genWrappedField","tag","serialize","payload","buildTx","deserialize","buffer","unpackTx","Transaction","recursiveType"],"sources":["../../../../src/tx/builder/field-types/wrapped.ts"],"sourcesContent":["import { Tag } from '../constants';\nimport { encode, Encoding, decode } from '../../../utils/encoder';\nimport type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index';\n\ntype TagWrapping = Tag.AccountsMtree | Tag.CallsMtree | Tag.ChannelsMtree | Tag.ContractsMtree\n| Tag.NameserviceMtree | Tag.OraclesMtree;\n\nexport default function genWrappedField<T extends TagWrapping>(tag: T): {\n serialize: (\n // TODO: replace with `(TxParams & { tag: T })['payload']`,\n // but fix TS2502 value is referenced directly or indirectly in its own type annotation\n value: any, options: { buildTx: typeof buildTxType }\n ) => Buffer;\n deserialize: (\n value: Buffer, options: { unpackTx: typeof unpackTxType },\n // TODO: replace with `(TxUnpacked & { tag: T })['payload']`,\n // TS2577 Return type annotation circularly references itself\n ) => any;\n recursiveType: true;\n} {\n return {\n serialize(payload, { buildTx }) {\n return decode(buildTx({ tag, payload }));\n },\n\n deserialize(buffer, { unpackTx }) {\n return unpackTx<TagWrapping>(encode(buffer, Encoding.Transaction), tag).payload;\n },\n\n recursiveType: true,\n };\n}\n"],"mappings":"SACSA,MAAM,EAAEC,QAAQ,EAAEC,MAAM;AAMjC,eAAe,SAASC,eAAeA,CAAwBC,GAAM,EAYnE;EACA,OAAO;IACLC,SAASA,CAACC,OAAO,EAAE;MAAEC;IAAQ,CAAC,EAAE;MAC9B,OAAOL,MAAM,CAACK,OAAO,CAAC;QAAEH,GAAG;QAAEE;MAAQ,CAAC,CAAC,CAAC;IAC1C,CAAC;IAEDE,WAAWA,CAACC,MAAM,EAAE;MAAEC;IAAS,CAAC,EAAE;MAChC,OAAOA,QAAQ,CAAcV,MAAM,CAACS,MAAM,EAAER,QAAQ,CAACU,WAAW,CAAC,EAAEP,GAAG,CAAC,CAACE,OAAO;IACjF,CAAC;IAEDM,aAAa,EAAE;EACjB,CAAC;AACH"}
|
|
@@ -49,13 +49,13 @@ export declare function readInt(buf?: Buffer): string;
|
|
|
49
49
|
/**
|
|
50
50
|
* Ensure that name is valid AENS name, would throw an exception otherwise
|
|
51
51
|
* @category AENS
|
|
52
|
-
* @param
|
|
52
|
+
* @param maybeName - AENS name
|
|
53
53
|
*/
|
|
54
54
|
export declare function ensureName(maybeName: string): asserts maybeName is AensName;
|
|
55
55
|
/**
|
|
56
56
|
* Is AENS name valid
|
|
57
57
|
* @category AENS
|
|
58
|
-
* @param
|
|
58
|
+
* @param maybeName - AENS name
|
|
59
59
|
*/
|
|
60
60
|
export declare function isNameValid(maybeName: string): maybeName is AensName;
|
|
61
61
|
declare const encodingToPointerKey: readonly [readonly [Encoded.Encoding.AccountAddress, "account_pubkey"], readonly [Encoded.Encoding.OracleAddress, "oracle_pubkey"], readonly [Encoded.Encoding.ContractAddress, "contract_pubkey"], readonly [Encoded.Encoding.Channel, "channel"]];
|
|
@@ -92,8 +92,7 @@ export function produceNameId(name) {
|
|
|
92
92
|
* @param salt - Random number
|
|
93
93
|
* @returns Commitment hash
|
|
94
94
|
*/
|
|
95
|
-
export function commitmentHash(name) {
|
|
96
|
-
let salt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : genSalt();
|
|
95
|
+
export function commitmentHash(name, salt = genSalt()) {
|
|
97
96
|
return encode(hash(concatBuffers([_Buffer.from(nameToPunycode(name)), _Buffer.from(salt.toString(16).padStart(64, '0'), 'hex')])), Encoding.Commitment);
|
|
98
97
|
}
|
|
99
98
|
|
|
@@ -103,15 +102,14 @@ export function commitmentHash(name) {
|
|
|
103
102
|
* @param buf - Value
|
|
104
103
|
* @returns Buffer Buffer from number(BigEndian)
|
|
105
104
|
*/
|
|
106
|
-
export function readInt() {
|
|
107
|
-
let buf = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _Buffer.from([]);
|
|
105
|
+
export function readInt(buf = _Buffer.from([])) {
|
|
108
106
|
return new BigNumber(_Buffer.from(buf).toString('hex'), 16).toString(10);
|
|
109
107
|
}
|
|
110
108
|
|
|
111
109
|
/**
|
|
112
110
|
* Ensure that name is valid AENS name, would throw an exception otherwise
|
|
113
111
|
* @category AENS
|
|
114
|
-
* @param
|
|
112
|
+
* @param maybeName - AENS name
|
|
115
113
|
*/
|
|
116
114
|
export function ensureName(maybeName) {
|
|
117
115
|
nameToPunycode(maybeName);
|
|
@@ -120,7 +118,7 @@ export function ensureName(maybeName) {
|
|
|
120
118
|
/**
|
|
121
119
|
* Is AENS name valid
|
|
122
120
|
* @category AENS
|
|
123
|
-
* @param
|
|
121
|
+
* @param maybeName - AENS name
|
|
124
122
|
*/
|
|
125
123
|
// TODO: consider renaming to isName
|
|
126
124
|
export function isNameValid(maybeName) {
|
|
@@ -142,15 +140,9 @@ export function getDefaultPointerKey(identifier) {
|
|
|
142
140
|
var _encodingToPointerKey;
|
|
143
141
|
decode(identifier);
|
|
144
142
|
const encoding = identifier.substring(0, 2);
|
|
145
|
-
const result = (_encodingToPointerKey = encodingToPointerKey.find(
|
|
146
|
-
let [e] = _ref;
|
|
147
|
-
return e === encoding;
|
|
148
|
-
})) === null || _encodingToPointerKey === void 0 ? void 0 : _encodingToPointerKey[1];
|
|
143
|
+
const result = (_encodingToPointerKey = encodingToPointerKey.find(([e]) => e === encoding)) === null || _encodingToPointerKey === void 0 ? void 0 : _encodingToPointerKey[1];
|
|
149
144
|
if (result != null) return result;
|
|
150
|
-
throw new ArgumentError('identifier', `prefixed with one of ${encodingToPointerKey.map(
|
|
151
|
-
let [e] = _ref2;
|
|
152
|
-
return `${e}_`;
|
|
153
|
-
}).join(', ')}`, identifier);
|
|
145
|
+
throw new ArgumentError('identifier', `prefixed with one of ${encodingToPointerKey.map(([e]) => `${e}_`).join(', ')}`, identifier);
|
|
154
146
|
}
|
|
155
147
|
|
|
156
148
|
/**
|
|
@@ -173,11 +165,10 @@ export function getMinimumNameFee(name) {
|
|
|
173
165
|
* @param options.increment - Bid multiplier(In percentage, must be between 0 and 1)
|
|
174
166
|
* @returns Bid fee
|
|
175
167
|
*/
|
|
176
|
-
export function computeBidFee(name
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
168
|
+
export function computeBidFee(name, {
|
|
169
|
+
startFee,
|
|
170
|
+
increment = NAME_FEE_BID_INCREMENT
|
|
171
|
+
} = {}) {
|
|
181
172
|
if (!(Number(increment) === increment && increment % 1 !== 0)) throw new IllegalBidFeeError(`Increment must be float. Current increment ${increment}`);
|
|
182
173
|
if (increment < NAME_FEE_BID_INCREMENT) throw new IllegalBidFeeError(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`);
|
|
183
174
|
// FIXME: increment should be used somehow here
|
|
@@ -193,9 +184,9 @@ export function computeBidFee(name) {
|
|
|
193
184
|
* @returns Auction end height
|
|
194
185
|
*/
|
|
195
186
|
export function computeAuctionEndBlock(name, claimHeight) {
|
|
196
|
-
var
|
|
187
|
+
var _ref, _ref2, _ref3;
|
|
197
188
|
const length = nameToPunycode(name).length - AENS_SUFFIX.length;
|
|
198
|
-
const h = (
|
|
189
|
+
const h = (_ref = (_ref2 = (_ref3 = length <= 4 ? 62 * NAME_BID_TIMEOUT_BLOCKS : null) !== null && _ref3 !== void 0 ? _ref3 : length <= 8 ? 31 * NAME_BID_TIMEOUT_BLOCKS : null) !== null && _ref2 !== void 0 ? _ref2 : length <= 12 ? NAME_BID_TIMEOUT_BLOCKS : null) !== null && _ref !== void 0 ? _ref : 0;
|
|
199
190
|
return h + claimHeight;
|
|
200
191
|
}
|
|
201
192
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.mjs","names":["BigNumber","genSalt","hash","decode","encode","Encoding","toBytes","concatBuffers","NAME_BID_RANGES","NAME_BID_TIMEOUT_BLOCKS","NAME_FEE_BID_INCREMENT","NAME_MAX_LENGTH_FEE","ceil","ArgumentError","IllegalBidFeeError","buildContractId","ownerId","nonce","ownerIdAndNonce","_Buffer","from","b2bHash","ContractAddress","oracleQueryId","senderId","oracleId","_int32","val","nonceBE","alloc","length","OracleQueryId","AENS_SUFFIX","nameToPunycode","maybeName","name","suffix","other","split","slice","test","punycode","u","URL","username","password","port","search","pathname","host","error","TypeError","message","includes","produceNameId","Name","commitmentHash","salt","arguments","undefined","toString","padStart","Commitment","readInt","buf","ensureName","isNameValid","encodingToPointerKey","AccountAddress","OracleAddress","Channel","getDefaultPointerKey","identifier","_encodingToPointerKey","encoding","substring","result","find","_ref","e","map","_ref2","join","getMinimumNameFee","nameLength","Math","min","computeBidFee","startFee","increment","Number","times","plus","computeAuctionEndBlock","claimHeight","_ref3","_ref4","_ref5","h","isAuctionName"],"sources":["../../../src/tx/builder/helpers.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { genSalt, hash } from '../../utils/crypto';\nimport {\n decode, encode, Encoded, Encoding,\n} from '../../utils/encoder';\nimport { toBytes } from '../../utils/bytes';\nimport { concatBuffers } from '../../utils/other';\nimport {\n AensName,\n NAME_BID_RANGES,\n NAME_BID_TIMEOUT_BLOCKS,\n NAME_FEE_BID_INCREMENT,\n NAME_MAX_LENGTH_FEE,\n} from './constants';\nimport { ceil } from '../../utils/bignumber';\nimport { ArgumentError, IllegalBidFeeError } from '../../utils/errors';\n\n/**\n * JavaScript-based Transaction builder helper function's\n */\n\n/**\n * Build a contract public key\n * @category contract\n * @param ownerId - The public key of the owner account\n * @param nonce - the nonce of the transaction\n * @returns Contract public key\n */\nexport function buildContractId(\n ownerId: Encoded.AccountAddress,\n nonce: number | BigNumber,\n): Encoded.ContractAddress {\n const ownerIdAndNonce = Buffer.from([...decode(ownerId), ...toBytes(nonce)]);\n const b2bHash = hash(ownerIdAndNonce);\n return encode(b2bHash, Encoding.ContractAddress);\n}\n\n/**\n * Build a oracle query id\n * @category oracle\n * @param senderId - The public key of the sender account\n * @param nonce - the nonce of the transaction\n * @param oracleId - The oracle public key\n * @returns Contract public key\n */\nexport function oracleQueryId(\n senderId: Encoded.AccountAddress,\n nonce: number | BigNumber | string,\n oracleId: Encoded.OracleAddress,\n): Encoded.OracleQueryId {\n function _int32(val: number | string | BigNumber): Buffer {\n const nonceBE = toBytes(val, true);\n return concatBuffers([Buffer.alloc(32 - nonceBE.length), nonceBE]);\n }\n\n const b2bHash = hash(\n Buffer.from([...decode(senderId), ..._int32(nonce), ...decode(oracleId)]),\n );\n return encode(b2bHash, Encoding.OracleQueryId);\n}\n\nconst AENS_SUFFIX = '.chain';\n\nexport function nameToPunycode(maybeName: string): AensName {\n const [name, suffix, ...other] = maybeName.split('.');\n if (other.length !== 0) throw new ArgumentError('aens name', 'including only one dot', maybeName);\n if (suffix !== AENS_SUFFIX.slice(1)) {\n throw new ArgumentError('aens name', `suffixed with ${AENS_SUFFIX}`, maybeName);\n }\n if (/\\p{Emoji_Presentation}/u.test(name)) {\n throw new ArgumentError('aens name', 'not containing emoji', maybeName);\n }\n let punycode;\n try {\n const u = new URL(`http://${name}.${suffix}`);\n if (u.username + u.password + u.port + u.search + u.hash !== '' || u.pathname !== '/') {\n throw new ArgumentError('aens name', 'valid', maybeName);\n }\n punycode = u.host;\n } catch (error) {\n if (error instanceof TypeError && error.message.includes('Invalid URL')) {\n throw new ArgumentError('aens name', 'valid', maybeName);\n }\n throw error;\n }\n if (!/^[a-z0-9.-]+$/i.test(punycode)) {\n throw new ArgumentError('aens name', 'without illegal chars', maybeName);\n }\n if (punycode.length > 63 + AENS_SUFFIX.length) {\n throw new ArgumentError('aens name', 'not too long', maybeName);\n }\n return punycode as AensName;\n}\n\n/**\n * Encode an AENS name\n * @category AENS\n * @param name - Name to encode\n * @returns `nm_` prefixed encoded AENS name\n */\nexport function produceNameId(name: AensName): Encoded.Name {\n return encode(hash(nameToPunycode(name)), Encoding.Name);\n}\n\n/**\n * Generate the commitment hash by hashing the salt and\n * name, base 58 encoding the result and prepending 'cm_'\n * @category transaction builder\n * @param name - Name to be registered\n * @param salt - Random number\n * @returns Commitment hash\n */\nexport function commitmentHash(\n name: AensName,\n salt: number = genSalt(),\n): Encoded.Commitment {\n return encode(\n hash(concatBuffers([\n Buffer.from(nameToPunycode(name)),\n Buffer.from(salt.toString(16).padStart(64, '0'), 'hex'),\n ])),\n Encoding.Commitment,\n );\n}\n\n/**\n * Utility function to convert bytes to int\n * @category transaction builder\n * @param buf - Value\n * @returns Buffer Buffer from number(BigEndian)\n */\nexport function readInt(buf: Buffer = Buffer.from([])): string {\n return new BigNumber(Buffer.from(buf).toString('hex'), 16).toString(10);\n}\n\n/**\n * Ensure that name is valid AENS name, would throw an exception otherwise\n * @category AENS\n * @param name - AENS name\n */\nexport function ensureName(maybeName: string): asserts maybeName is AensName {\n nameToPunycode(maybeName);\n}\n\n/**\n * Is AENS name valid\n * @category AENS\n * @param name - AENS name\n */\n// TODO: consider renaming to isName\nexport function isNameValid(maybeName: string): maybeName is AensName {\n try {\n ensureName(maybeName);\n return true;\n } catch (error) {\n return false;\n }\n}\n\nconst encodingToPointerKey = [\n [Encoding.AccountAddress, 'account_pubkey'],\n [Encoding.OracleAddress, 'oracle_pubkey'],\n [Encoding.ContractAddress, 'contract_pubkey'],\n [Encoding.Channel, 'channel'],\n] as const;\n\n/**\n * @category AENS\n * @param identifier - account/oracle/contract address, or channel\n * @returns default AENS pointer key\n */\nexport function getDefaultPointerKey(\n identifier: Encoded.Generic<typeof encodingToPointerKey[number][0]>,\n): typeof encodingToPointerKey[number][1] {\n decode(identifier);\n const encoding = identifier.substring(0, 2);\n const result = encodingToPointerKey.find(([e]) => e === encoding)?.[1];\n if (result != null) return result;\n throw new ArgumentError(\n 'identifier',\n `prefixed with one of ${encodingToPointerKey.map(([e]) => `${e}_`).join(', ')}`,\n identifier,\n );\n}\n\n/**\n * Get the minimum AENS name fee\n * @category AENS\n * @param name - the AENS name to get the fee for\n * @returns the minimum fee for the AENS name auction\n */\nexport function getMinimumNameFee(name: AensName): BigNumber {\n const nameLength = nameToPunycode(name).length - AENS_SUFFIX.length;\n return NAME_BID_RANGES[Math.min(nameLength, NAME_MAX_LENGTH_FEE)];\n}\n\n/**\n * Compute bid fee for AENS auction\n * @category AENS\n * @param name - the AENS name to get the fee for\n * @param options - Options\n * @param options.startFee - Auction start fee\n * @param options.increment - Bid multiplier(In percentage, must be between 0 and 1)\n * @returns Bid fee\n */\nexport function computeBidFee(\n name: AensName,\n { startFee, increment = NAME_FEE_BID_INCREMENT }:\n { startFee?: number | string | BigNumber; increment?: number } = {},\n): BigNumber {\n if (!(Number(increment) === increment && increment % 1 !== 0)) throw new IllegalBidFeeError(`Increment must be float. Current increment ${increment}`);\n if (increment < NAME_FEE_BID_INCREMENT) throw new IllegalBidFeeError(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`);\n // FIXME: increment should be used somehow here\n return ceil(\n new BigNumber(startFee ?? getMinimumNameFee(name))\n .times(new BigNumber(NAME_FEE_BID_INCREMENT).plus(1)),\n );\n}\n\n/**\n * Compute auction end height\n * @category AENS\n * @param name - Name to compute auction end for\n * @param claimHeight - Auction starting height\n * @see {@link https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L273}\n * @returns Auction end height\n */\nexport function computeAuctionEndBlock(name: AensName, claimHeight: number): number {\n const length = nameToPunycode(name).length - AENS_SUFFIX.length;\n const h = (length <= 4 ? 62 * NAME_BID_TIMEOUT_BLOCKS : null)\n ?? (length <= 8 ? 31 * NAME_BID_TIMEOUT_BLOCKS : null)\n ?? (length <= 12 ? NAME_BID_TIMEOUT_BLOCKS : null)\n ?? 0;\n return h + claimHeight;\n}\n\n/**\n * Is name accept going to auction\n * @category AENS\n */\nexport function isAuctionName(name: AensName): boolean {\n return nameToPunycode(name).length < 13 + AENS_SUFFIX.length;\n}\n"],"mappings":";;;;AAAA,OAAOA,SAAS,MAAM,cAAc;AAAC,SAC5BC,OAAO,EAAEC,IAAI;AAAA,SAEpBC,MAAM,EAAEC,MAAM,EAAWC,QAAQ;AAAA,SAE1BC,OAAO;AAAA,SACPC,aAAa;AAAA,SAGpBC,eAAe,EACfC,uBAAuB,EACvBC,sBAAsB,EACtBC,mBAAmB;AAAA,SAEZC,IAAI;AAAA,SACJC,aAAa,EAAEC,kBAAkB;AAE1C;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAC7BC,OAA+B,EAC/BC,KAAyB,EACA;EACzB,MAAMC,eAAe,GAAGC,OAAA,CAAOC,IAAI,CAAC,CAAC,GAAGjB,MAAM,CAACa,OAAO,CAAC,EAAE,GAAGV,OAAO,CAACW,KAAK,CAAC,CAAC,CAAC;EAC5E,MAAMI,OAAO,GAAGnB,IAAI,CAACgB,eAAe,CAAC;EACrC,OAAOd,MAAM,CAACiB,OAAO,EAAEhB,QAAQ,CAACiB,eAAe,CAAC;AAClD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAC3BC,QAAgC,EAChCP,KAAkC,EAClCQ,QAA+B,EACR;EACvB,SAASC,MAAMA,CAACC,GAAgC,EAAU;IACxD,MAAMC,OAAO,GAAGtB,OAAO,CAACqB,GAAG,EAAE,IAAI,CAAC;IAClC,OAAOpB,aAAa,CAAC,CAACY,OAAA,CAAOU,KAAK,CAAC,EAAE,GAAGD,OAAO,CAACE,MAAM,CAAC,EAAEF,OAAO,CAAC,CAAC;EACpE;EAEA,MAAMP,OAAO,GAAGnB,IAAI,CAClBiB,OAAA,CAAOC,IAAI,CAAC,CAAC,GAAGjB,MAAM,CAACqB,QAAQ,CAAC,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Q,GAAIL,iBAAiB,CAAChD,IAAI,CAAC,CAAC,CAC/CwD,KAAK,CAAC,IAAI3F,SAAS,CAACU,sBAAsB,CAAC,CAACkF,IAAI,CAAC,CAAC,CAAC,CACxD,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,sBAAsBA,CAAC1D,IAAc,EAAE2D,WAAmB,EAAU;EAAA,IAAAC,KAAA,EAAAC,KAAA,EAAAC,KAAA;EAClF,MAAMnE,MAAM,GAAGG,cAAc,CAACE,IAAI,CAAC,CAACL,MAAM,GAAGE,WAAW,CAACF,MAAM;EAC/D,MAAMoE,CAAC,IAAAH,KAAA,IAAAC,KAAA,IAAAC,KAAA,GAAInE,MAAM,IAAI,CAAC,GAAG,EAAE,GAAGrB,uBAAuB,GAAG,IAAI,cAAAwF,KAAA,cAAAA,KAAA,GACtDnE,MAAM,IAAI,CAAC,GAAG,EAAE,GAAGrB,uBAAuB,GAAG,IAAI,cAAAuF,KAAA,cAAAA,KAAA,GACjDlE,MAAM,IAAI,EAAE,GAAGrB,uBAAuB,GAAG,IAAI,cAAAsF,KAAA,cAAAA,KAAA,GAC9C,CAAC;EACN,OAAOG,CAAC,GAAGJ,WAAW;AACxB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASK,aAAaA,CAAChE,IAAc,EAAW;EACrD,OAAOF,cAAc,CAACE,IAAI,CAAC,CAACL,MAAM,GAAG,EAAE,GAAGE,WAAW,CAACF,MAAM;AAC9D"}
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":["BigNumber","genSalt","hash","decode","encode","Encoding","toBytes","concatBuffers","NAME_BID_RANGES","NAME_BID_TIMEOUT_BLOCKS","NAME_FEE_BID_INCREMENT","NAME_MAX_LENGTH_FEE","ceil","ArgumentError","IllegalBidFeeError","buildContractId","ownerId","nonce","ownerIdAndNonce","_Buffer","from","b2bHash","ContractAddress","oracleQueryId","senderId","oracleId","_int32","val","nonceBE","alloc","length","OracleQueryId","AENS_SUFFIX","nameToPunycode","maybeName","name","suffix","other","split","slice","test","punycode","u","URL","username","password","port","search","pathname","host","error","TypeError","message","includes","produceNameId","Name","commitmentHash","salt","toString","padStart","Commitment","readInt","buf","ensureName","isNameValid","encodingToPointerKey","AccountAddress","OracleAddress","Channel","getDefaultPointerKey","identifier","_encodingToPointerKey","encoding","substring","result","find","e","map","join","getMinimumNameFee","nameLength","Math","min","computeBidFee","startFee","increment","Number","times","plus","computeAuctionEndBlock","claimHeight","_ref","_ref2","_ref3","h","isAuctionName"],"sources":["../../../src/tx/builder/helpers.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { genSalt, hash } from '../../utils/crypto';\nimport {\n decode, encode, Encoded, Encoding,\n} from '../../utils/encoder';\nimport { toBytes } from '../../utils/bytes';\nimport { concatBuffers } from '../../utils/other';\nimport {\n AensName,\n NAME_BID_RANGES,\n NAME_BID_TIMEOUT_BLOCKS,\n NAME_FEE_BID_INCREMENT,\n NAME_MAX_LENGTH_FEE,\n} from './constants';\nimport { ceil } from '../../utils/bignumber';\nimport { ArgumentError, IllegalBidFeeError } from '../../utils/errors';\n\n/**\n * JavaScript-based Transaction builder helper function's\n */\n\n/**\n * Build a contract public key\n * @category contract\n * @param ownerId - The public key of the owner account\n * @param nonce - the nonce of the transaction\n * @returns Contract public key\n */\nexport function buildContractId(\n ownerId: Encoded.AccountAddress,\n nonce: number | BigNumber,\n): Encoded.ContractAddress {\n const ownerIdAndNonce = Buffer.from([...decode(ownerId), ...toBytes(nonce)]);\n const b2bHash = hash(ownerIdAndNonce);\n return encode(b2bHash, Encoding.ContractAddress);\n}\n\n/**\n * Build a oracle query id\n * @category oracle\n * @param senderId - The public key of the sender account\n * @param nonce - the nonce of the transaction\n * @param oracleId - The oracle public key\n * @returns Contract public key\n */\nexport function oracleQueryId(\n senderId: Encoded.AccountAddress,\n nonce: number | BigNumber | string,\n oracleId: Encoded.OracleAddress,\n): Encoded.OracleQueryId {\n function _int32(val: number | string | BigNumber): Buffer {\n const nonceBE = toBytes(val, true);\n return concatBuffers([Buffer.alloc(32 - nonceBE.length), nonceBE]);\n }\n\n const b2bHash = hash(\n Buffer.from([...decode(senderId), ..._int32(nonce), ...decode(oracleId)]),\n );\n return encode(b2bHash, Encoding.OracleQueryId);\n}\n\nconst AENS_SUFFIX = '.chain';\n\nexport function nameToPunycode(maybeName: string): AensName {\n const [name, suffix, ...other] = maybeName.split('.');\n if (other.length !== 0) throw new ArgumentError('aens name', 'including only one dot', maybeName);\n if (suffix !== AENS_SUFFIX.slice(1)) {\n throw new ArgumentError('aens name', `suffixed with ${AENS_SUFFIX}`, maybeName);\n }\n if (/\\p{Emoji_Presentation}/u.test(name)) {\n throw new ArgumentError('aens name', 'not containing emoji', maybeName);\n }\n let punycode;\n try {\n const u = new URL(`http://${name}.${suffix}`);\n if (u.username + u.password + u.port + u.search + u.hash !== '' || u.pathname !== '/') {\n throw new ArgumentError('aens name', 'valid', maybeName);\n }\n punycode = u.host;\n } catch (error) {\n if (error instanceof TypeError && error.message.includes('Invalid URL')) {\n throw new ArgumentError('aens name', 'valid', maybeName);\n }\n throw error;\n }\n if (!/^[a-z0-9.-]+$/i.test(punycode)) {\n throw new ArgumentError('aens name', 'without illegal chars', maybeName);\n }\n if (punycode.length > 63 + AENS_SUFFIX.length) {\n throw new ArgumentError('aens name', 'not too long', maybeName);\n }\n return punycode as AensName;\n}\n\n/**\n * Encode an AENS name\n * @category AENS\n * @param name - Name to encode\n * @returns `nm_` prefixed encoded AENS name\n */\nexport function produceNameId(name: AensName): Encoded.Name {\n return encode(hash(nameToPunycode(name)), Encoding.Name);\n}\n\n/**\n * Generate the commitment hash by hashing the salt and\n * name, base 58 encoding the result and prepending 'cm_'\n * @category transaction builder\n * @param name - Name to be registered\n * @param salt - Random number\n * @returns Commitment hash\n */\nexport function commitmentHash(\n name: AensName,\n salt: number = genSalt(),\n): Encoded.Commitment {\n return encode(\n hash(concatBuffers([\n Buffer.from(nameToPunycode(name)),\n Buffer.from(salt.toString(16).padStart(64, '0'), 'hex'),\n ])),\n Encoding.Commitment,\n );\n}\n\n/**\n * Utility function to convert bytes to int\n * @category transaction builder\n * @param buf - Value\n * @returns Buffer Buffer from number(BigEndian)\n */\nexport function readInt(buf: Buffer = Buffer.from([])): string {\n return new BigNumber(Buffer.from(buf).toString('hex'), 16).toString(10);\n}\n\n/**\n * Ensure that name is valid AENS name, would throw an exception otherwise\n * @category AENS\n * @param maybeName - AENS name\n */\nexport function ensureName(maybeName: string): asserts maybeName is AensName {\n nameToPunycode(maybeName);\n}\n\n/**\n * Is AENS name valid\n * @category AENS\n * @param maybeName - AENS name\n */\n// TODO: consider renaming to isName\nexport function isNameValid(maybeName: string): maybeName is AensName {\n try {\n ensureName(maybeName);\n return true;\n } catch (error) {\n return false;\n }\n}\n\nconst encodingToPointerKey = [\n [Encoding.AccountAddress, 'account_pubkey'],\n [Encoding.OracleAddress, 'oracle_pubkey'],\n [Encoding.ContractAddress, 'contract_pubkey'],\n [Encoding.Channel, 'channel'],\n] as const;\n\n/**\n * @category AENS\n * @param identifier - account/oracle/contract address, or channel\n * @returns default AENS pointer key\n */\nexport function getDefaultPointerKey(\n identifier: Encoded.Generic<typeof encodingToPointerKey[number][0]>,\n): typeof encodingToPointerKey[number][1] {\n decode(identifier);\n const encoding = identifier.substring(0, 2);\n const result = encodingToPointerKey.find(([e]) => e === encoding)?.[1];\n if (result != null) return result;\n throw new ArgumentError(\n 'identifier',\n `prefixed with one of ${encodingToPointerKey.map(([e]) => `${e}_`).join(', ')}`,\n identifier,\n );\n}\n\n/**\n * Get the minimum AENS name fee\n * @category AENS\n * @param name - the AENS name to get the fee for\n * @returns the minimum fee for the AENS name auction\n */\nexport function getMinimumNameFee(name: AensName): BigNumber {\n const nameLength = nameToPunycode(name).length - AENS_SUFFIX.length;\n return NAME_BID_RANGES[Math.min(nameLength, NAME_MAX_LENGTH_FEE)];\n}\n\n/**\n * Compute bid fee for AENS auction\n * @category AENS\n * @param name - the AENS name to get the fee for\n * @param options - Options\n * @param options.startFee - Auction start fee\n * @param options.increment - Bid multiplier(In percentage, must be between 0 and 1)\n * @returns Bid fee\n */\nexport function computeBidFee(\n name: AensName,\n { startFee, increment = NAME_FEE_BID_INCREMENT }:\n { startFee?: number | string | BigNumber; increment?: number } = {},\n): BigNumber {\n if (!(Number(increment) === increment && increment % 1 !== 0)) throw new IllegalBidFeeError(`Increment must be float. Current increment ${increment}`);\n if (increment < NAME_FEE_BID_INCREMENT) throw new IllegalBidFeeError(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`);\n // FIXME: increment should be used somehow here\n return ceil(\n new BigNumber(startFee ?? getMinimumNameFee(name))\n .times(new BigNumber(NAME_FEE_BID_INCREMENT).plus(1)),\n );\n}\n\n/**\n * Compute auction end height\n * @category AENS\n * @param name - Name to compute auction end for\n * @param claimHeight - Auction starting height\n * @see {@link https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L273}\n * @returns Auction end height\n */\nexport function computeAuctionEndBlock(name: AensName, claimHeight: number): number {\n const length = nameToPunycode(name).length - AENS_SUFFIX.length;\n const h = (length <= 4 ? 62 * NAME_BID_TIMEOUT_BLOCKS : null)\n ?? (length <= 8 ? 31 * NAME_BID_TIMEOUT_BLOCKS : null)\n ?? (length <= 12 ? NAME_BID_TIMEOUT_BLOCKS : null)\n ?? 0;\n return h + claimHeight;\n}\n\n/**\n * Is name accept going to auction\n * @category AENS\n */\nexport function isAuctionName(name: AensName): boolean {\n return nameToPunycode(name).length < 13 + AENS_SUFFIX.length;\n}\n"],"mappings":";;;;AAAA,OAAOA,SAAS,MAAM,cAAc;AAAC,SAC5BC,OAAO,EAAEC,IAAI;AAAA,SAEpBC,MAAM,EAAEC,MAAM,EAAWC,QAAQ;AAAA,SAE1BC,OAAO;AAAA,SACPC,aAAa;AAAA,SAGpBC,eAAe,EACfC,uBAAuB,EACvBC,sBAAsB,EACtBC,mBAAmB;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AAI,EAAE,GAAGrB,uBAAuB,GAAG,IAAI,cAAAkF,IAAA,cAAAA,IAAA,GAC9C,CAAC;EACN,OAAOG,CAAC,GAAGJ,WAAW;AACxB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASK,aAAaA,CAAC5D,IAAc,EAAW;EACrD,OAAOF,cAAc,CAACE,IAAI,CAAC,CAACL,MAAM,GAAG,EAAE,GAAGE,WAAW,CAACF,MAAM;AAC9D"}
|
package/es/tx/builder/index.d.ts
CHANGED
|
@@ -8,29 +8,36 @@ import { Tag } from './constants';
|
|
|
8
8
|
export declare function getSchema(tag: Tag, version?: number): Array<[string, Field]>;
|
|
9
9
|
type TxEncoding = Encoding.Transaction | Encoding.Poi | Encoding.StateTrees | Encoding.CallStateTree;
|
|
10
10
|
/**
|
|
11
|
-
* Build transaction
|
|
11
|
+
* Build transaction
|
|
12
12
|
* @category transaction builder
|
|
13
|
-
* @param params -
|
|
14
|
-
* @param options - options
|
|
15
|
-
* @param options.prefix - Prefix of transaction
|
|
16
|
-
* @returns object Base64Check transaction hash with 'tx_' prefix
|
|
13
|
+
* @param params - Transaction params
|
|
17
14
|
*/
|
|
18
|
-
export declare function buildTx
|
|
19
|
-
|
|
15
|
+
export declare function buildTx(params: TxParams): Encoded.Transaction;
|
|
16
|
+
/**
|
|
17
|
+
* Build node entry with a custom encoding
|
|
18
|
+
* @param params - Entry params
|
|
19
|
+
* @param options - Options
|
|
20
|
+
* @param options.prefix - Output encoding
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildTx<E extends TxEncoding>(params: TxParams, { prefix }: {
|
|
23
|
+
prefix: E;
|
|
20
24
|
}): Encoded.Generic<E>;
|
|
21
25
|
export type BuildTxOptions<TxType extends Tag, OmitFields extends string> = Omit<TxParamsAsync & {
|
|
22
26
|
tag: TxType;
|
|
23
27
|
}, 'tag' | OmitFields>;
|
|
24
28
|
/**
|
|
29
|
+
* Build transaction async (may request node for additional data)
|
|
25
30
|
* @category transaction builder
|
|
31
|
+
* @param params - Transaction params
|
|
32
|
+
* @returns tx_-encoded transaction
|
|
26
33
|
*/
|
|
27
34
|
export declare function buildTxAsync(params: TxParamsAsync): Promise<Encoded.Transaction>;
|
|
28
35
|
/**
|
|
29
36
|
* Unpack transaction encoded as string
|
|
30
37
|
* @category transaction builder
|
|
31
|
-
* @param encodedTx -
|
|
38
|
+
* @param encodedTx - Encoded transaction
|
|
32
39
|
* @param txType - Expected transaction type
|
|
33
|
-
* @returns
|
|
40
|
+
* @returns Transaction params
|
|
34
41
|
*/
|
|
35
42
|
export declare function unpackTx<TxType extends Tag>(encodedTx: Encoded.Generic<TxEncoding>, txType?: TxType): TxUnpacked & {
|
|
36
43
|
tag: TxType;
|
|
@@ -43,7 +50,7 @@ export declare function unpackTx<TxType extends Tag>(encodedTx: Encoded.Generic<
|
|
|
43
50
|
*/
|
|
44
51
|
export declare function buildTxHash(rawTx: Encoded.Transaction | Uint8Array): Encoded.TxHash;
|
|
45
52
|
/**
|
|
46
|
-
* Build a contract public key by contractCreateTx or
|
|
53
|
+
* Build a contract public key by contractCreateTx, gaAttach or signedTx
|
|
47
54
|
* @category contract
|
|
48
55
|
* @param contractTx - Transaction
|
|
49
56
|
* @returns Contract public key
|
package/es/tx/builder/index.mjs
CHANGED
|
@@ -1,64 +1,52 @@
|
|
|
1
|
-
import _rlp from 'rlp';
|
|
2
|
-
const {
|
|
3
|
-
decode: rlpDecode,
|
|
4
|
-
encode: rlpEncode
|
|
5
|
-
} = _rlp;
|
|
6
1
|
import { decode, encode, Encoding } from "../../utils/encoder.mjs";
|
|
7
2
|
import { hash } from "../../utils/crypto.mjs";
|
|
8
3
|
import { txSchema } from "./schema.mjs";
|
|
9
4
|
import { Tag } from "./constants.mjs";
|
|
10
|
-
import { buildContractId
|
|
11
|
-
import {
|
|
5
|
+
import { buildContractId } from "./helpers.mjs";
|
|
6
|
+
import { getSchema as getSchemaCommon, packRecord, unpackRecord } from "./common.mjs";
|
|
7
|
+
import { ArgumentError } from "../../utils/errors.mjs";
|
|
12
8
|
/**
|
|
13
9
|
* JavaScript-based Transaction builder
|
|
14
10
|
*/
|
|
15
11
|
export function getSchema(tag, version) {
|
|
16
|
-
|
|
17
|
-
const schemas = txSchema.filter(s => s.tag.constValue === tag);
|
|
18
|
-
if (schemas.length === 0) throw new SchemaNotFoundError(`${Tag[tag]} (${tag})`, 0);
|
|
19
|
-
(_version = version) !== null && _version !== void 0 ? _version : version = Math.max(...schemas.map(schema => schema.version.constValue));
|
|
20
|
-
const schema = schemas.find(s => s.version.constValue === version);
|
|
21
|
-
if (schema == null) throw new SchemaNotFoundError(`${Tag[tag]} (${tag})`, version);
|
|
22
|
-
return Object.entries(schema);
|
|
12
|
+
return getSchemaCommon(txSchema, Tag, tag, version);
|
|
23
13
|
}
|
|
14
|
+
|
|
24
15
|
/**
|
|
25
|
-
* Build transaction
|
|
16
|
+
* Build transaction
|
|
26
17
|
* @category transaction builder
|
|
27
|
-
* @param params -
|
|
28
|
-
* @param options - options
|
|
29
|
-
* @param options.prefix - Prefix of transaction
|
|
30
|
-
* @returns object Base64Check transaction hash with 'tx_' prefix
|
|
18
|
+
* @param params - Transaction params
|
|
31
19
|
*/
|
|
32
|
-
export function buildTx(params) {
|
|
33
|
-
let {
|
|
34
|
-
prefix
|
|
35
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
36
|
-
const schema = getSchema(params.tag, params.version);
|
|
37
|
-
const binary = schema.map(_ref => {
|
|
38
|
-
let [key, field] = _ref;
|
|
39
|
-
return field.serialize(
|
|
40
|
-
// @ts-expect-error the type of `params[key]` can't be determined accurately
|
|
41
|
-
params[key], {
|
|
42
|
-
...params,
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
44
|
-
unpackTx,
|
|
45
|
-
buildTx,
|
|
46
|
-
rebuildTx: overrideParams => buildTx({
|
|
47
|
-
...params,
|
|
48
|
-
...overrideParams
|
|
49
|
-
})
|
|
50
|
-
}, params);
|
|
51
|
-
});
|
|
52
20
|
|
|
53
|
-
|
|
54
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Build node entry with a custom encoding
|
|
23
|
+
* @param params - Entry params
|
|
24
|
+
* @param options - Options
|
|
25
|
+
* @param options.prefix - Output encoding
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export function buildTx(params, {
|
|
29
|
+
prefix
|
|
30
|
+
} = {}) {
|
|
31
|
+
return packRecord(txSchema, Tag, params, {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
33
|
+
unpackTx,
|
|
34
|
+
buildTx,
|
|
35
|
+
rebuildTx: overrideParams => buildTx({
|
|
36
|
+
...params,
|
|
37
|
+
...overrideParams
|
|
38
|
+
})
|
|
39
|
+
}, prefix !== null && prefix !== void 0 ? prefix : Encoding.Transaction);
|
|
55
40
|
}
|
|
41
|
+
// TODO: require onNode because it is the only reason this builder is async [breaking change]
|
|
56
42
|
/**
|
|
43
|
+
* Build transaction async (may request node for additional data)
|
|
57
44
|
* @category transaction builder
|
|
45
|
+
* @param params - Transaction params
|
|
46
|
+
* @returns tx_-encoded transaction
|
|
58
47
|
*/
|
|
59
48
|
export async function buildTxAsync(params) {
|
|
60
|
-
await Promise.all(getSchema(params.tag, params.version).map(async
|
|
61
|
-
let [key, field] = _ref2;
|
|
49
|
+
await Promise.all(getSchema(params.tag, params.version).map(async ([key, field]) => {
|
|
62
50
|
if (field.prepare == null) return;
|
|
63
51
|
// @ts-expect-error the type of `params[key]` can't be determined accurately
|
|
64
52
|
params[key] = await field.prepare(params[key], params, params);
|
|
@@ -71,30 +59,15 @@ export async function buildTxAsync(params) {
|
|
|
71
59
|
/**
|
|
72
60
|
* Unpack transaction encoded as string
|
|
73
61
|
* @category transaction builder
|
|
74
|
-
* @param encodedTx -
|
|
62
|
+
* @param encodedTx - Encoded transaction
|
|
75
63
|
* @param txType - Expected transaction type
|
|
76
|
-
* @returns
|
|
64
|
+
* @returns Transaction params
|
|
77
65
|
*/
|
|
78
66
|
export function unpackTx(encodedTx, txType) {
|
|
79
|
-
|
|
80
|
-
const tag = +readInt(binary[0]);
|
|
81
|
-
const version = +readInt(binary[1]);
|
|
82
|
-
const schema = getSchema(tag, version);
|
|
83
|
-
if (txType != null && txType !== tag) throw new DecodeError(`Expected transaction to have ${Tag[txType]} tag, got ${Tag[tag]} instead`);
|
|
84
|
-
if (binary.length !== schema.length) {
|
|
85
|
-
throw new ArgumentError('Transaction RLP length', schema.length, binary.length);
|
|
86
|
-
}
|
|
87
|
-
return schema.reduce((acc, _ref3, index) => {
|
|
88
|
-
let [name, field] = _ref3;
|
|
67
|
+
return unpackRecord(txSchema, Tag, encodedTx, txType, {
|
|
89
68
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
});
|
|
93
|
-
return {
|
|
94
|
-
...acc,
|
|
95
|
-
[name]: deserialized
|
|
96
|
-
};
|
|
97
|
-
}, {});
|
|
69
|
+
unpackTx
|
|
70
|
+
});
|
|
98
71
|
}
|
|
99
72
|
|
|
100
73
|
/**
|
|
@@ -109,13 +82,14 @@ export function buildTxHash(rawTx) {
|
|
|
109
82
|
}
|
|
110
83
|
|
|
111
84
|
/**
|
|
112
|
-
* Build a contract public key by contractCreateTx or
|
|
85
|
+
* Build a contract public key by contractCreateTx, gaAttach or signedTx
|
|
113
86
|
* @category contract
|
|
114
87
|
* @param contractTx - Transaction
|
|
115
88
|
* @returns Contract public key
|
|
116
89
|
*/
|
|
117
90
|
export function buildContractIdByContractTx(contractTx) {
|
|
118
|
-
|
|
91
|
+
let params = unpackTx(contractTx);
|
|
92
|
+
if (Tag.SignedTx === params.tag) params = params.encodedTx;
|
|
119
93
|
if (Tag.ContractCreateTx !== params.tag && Tag.GaAttachTx !== params.tag) {
|
|
120
94
|
throw new ArgumentError('contractTx', 'a contractCreateTx or gaAttach', params.tag);
|
|
121
95
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["decode","encode","Encoding","hash","txSchema","Tag","buildContractId","getSchema","getSchemaCommon","packRecord","unpackRecord","ArgumentError","tag","version","buildTx","params","prefix","unpackTx","rebuildTx","overrideParams","Transaction","buildTxAsync","Promise","all","map","key","field","prepare","encodedTx","txType","buildTxHash","rawTx","data","startsWith","TxHash","buildContractIdByContractTx","contractTx","SignedTx","ContractCreateTx","GaAttachTx","ownerId","nonce"],"sources":["../../../src/tx/builder/index.ts"],"sourcesContent":["import {\n decode, encode, Encoded, Encoding,\n} from '../../utils/encoder';\nimport { hash } from '../../utils/crypto';\nimport { Field } from './field-types';\nimport { txSchema } from './schema';\nimport { TxUnpacked, TxParams, TxParamsAsync } from './schema.generated';\nimport { Tag } from './constants';\nimport { buildContractId } from './helpers';\nimport { getSchema as getSchemaCommon, packRecord, unpackRecord } from './common';\nimport { ArgumentError } from '../../utils/errors';\n\n/**\n * JavaScript-based Transaction builder\n */\n\nexport function getSchema(tag: Tag, version?: number): Array<[string, Field]> {\n return getSchemaCommon(txSchema, Tag, tag, version);\n}\n\ntype TxEncoding = Encoding.Transaction | Encoding.Poi | Encoding.StateTrees\n| Encoding.CallStateTree;\n\n/**\n * Build transaction\n * @category transaction builder\n * @param params - Transaction params\n */\nexport function buildTx(params: TxParams): Encoded.Transaction;\n/**\n * Build node entry with a custom encoding\n * @param params - Entry params\n * @param options - Options\n * @param options.prefix - Output encoding\n */\nexport function buildTx<E extends TxEncoding>(\n params: TxParams,\n { prefix }: { prefix: E },\n): Encoded.Generic<E>;\nexport function buildTx(\n params: TxParams,\n { prefix }: { prefix?: TxEncoding } = {},\n): Encoded.Generic<TxEncoding> {\n return packRecord(txSchema, Tag, params, {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n unpackTx,\n buildTx,\n rebuildTx: (overrideParams: any) => buildTx(\n { ...params, ...overrideParams },\n ),\n }, prefix ?? Encoding.Transaction);\n}\n\nexport type BuildTxOptions <TxType extends Tag, OmitFields extends string> =\n Omit<TxParamsAsync & { tag: TxType }, 'tag' | OmitFields>;\n\n// TODO: require onNode because it is the only reason this builder is async [breaking change]\n/**\n * Build transaction async (may request node for additional data)\n * @category transaction builder\n * @param params - Transaction params\n * @returns tx_-encoded transaction\n */\nexport async function buildTxAsync(params: TxParamsAsync): Promise<Encoded.Transaction> {\n await Promise.all(\n getSchema(params.tag, params.version)\n .map(async ([key, field]) => {\n if (field.prepare == null) return;\n // @ts-expect-error the type of `params[key]` can't be determined accurately\n params[key] = await field.prepare(params[key], params, params);\n }),\n );\n\n // @ts-expect-error after preparation properties should be compatible with sync tx builder\n return buildTx(params);\n}\n\n/**\n * Unpack transaction encoded as string\n * @category transaction builder\n * @param encodedTx - Encoded transaction\n * @param txType - Expected transaction type\n * @returns Transaction params\n */\nexport function unpackTx<TxType extends Tag>(\n encodedTx: Encoded.Generic<TxEncoding>,\n txType?: TxType,\n): TxUnpacked & { tag: TxType } {\n return unpackRecord(txSchema, Tag, encodedTx, txType, {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n unpackTx,\n }) as any;\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, gaAttach or signedTx\n * @category contract\n * @param contractTx - Transaction\n * @returns Contract public key\n */\nexport function buildContractIdByContractTx(\n contractTx: Encoded.Transaction,\n): Encoded.ContractAddress {\n let params = unpackTx(contractTx);\n if (Tag.SignedTx === params.tag) params = params.encodedTx;\n if (Tag.ContractCreateTx !== params.tag && Tag.GaAttachTx !== params.tag) {\n throw new ArgumentError('contractTx', 'a contractCreateTx or gaAttach', params.tag);\n }\n return buildContractId(params.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