@aeternity/aepp-sdk 12.1.2 → 13.0.0-alpha.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/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 +6580 -8860
- 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 +27 -185
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkMethods.d.ts +124 -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 +7 -12
- package/es/Node.mjs +34 -47
- 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 +111 -0
- package/es/account/Generalized.mjs.map +1 -0
- package/es/account/Ledger.d.ts +28 -0
- package/es/account/Ledger.mjs +101 -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 -65
- 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 +3 -3
- package/es/aens.mjs +42 -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.mjs +3 -7
- 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 +4 -41
- 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 +1 -1
- package/es/chain.mjs +33 -58
- package/es/chain.mjs.map +1 -1
- package/es/channel/Base.d.ts +195 -0
- package/es/channel/Base.mjs +290 -0
- package/es/channel/Base.mjs.map +1 -0
- package/es/channel/Contract.d.ts +247 -0
- package/es/channel/Contract.mjs +420 -0
- package/es/channel/Contract.mjs.map +1 -0
- package/es/channel/Spend.d.ts +217 -0
- package/es/channel/Spend.mjs +383 -0
- package/es/channel/Spend.mjs.map +1 -0
- package/es/channel/handlers.d.ts +8 -21
- package/es/channel/handlers.mjs +141 -891
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/internal.d.ts +27 -21
- package/es/channel/internal.mjs +98 -190
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/{Compiler.d.ts → CompilerHttp.d.ts} +3 -3
- package/es/contract/{Compiler.mjs → CompilerHttp.mjs} +8 -13
- package/es/contract/CompilerHttp.mjs.map +1 -0
- package/es/contract/Contract.d.ts +235 -0
- package/es/contract/Contract.mjs +534 -0
- package/es/contract/Contract.mjs.map +1 -0
- package/es/contract/ga.d.ts +7 -33
- package/es/contract/ga.mjs +20 -112
- package/es/contract/ga.mjs.map +1 -1
- package/es/index.d.ts +9 -6
- package/es/index.mjs +8 -6
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +5 -5
- package/es/oracle.mjs +33 -39
- package/es/oracle.mjs.map +1 -1
- package/es/spend.d.ts +3 -3
- package/es/spend.mjs +17 -20
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/constants.d.ts +2 -1
- package/es/tx/builder/constants.mjs +12 -12
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/address.d.ts +15 -0
- package/es/tx/builder/field-types/address.mjs +42 -0
- package/es/tx/builder/field-types/address.mjs.map +1 -0
- package/es/tx/builder/field-types/addresses.d.ts +6 -0
- package/es/tx/builder/field-types/addresses.mjs +13 -0
- package/es/tx/builder/field-types/addresses.mjs.map +1 -0
- package/es/tx/builder/field-types/coin-amount.d.ts +1 -2
- 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/deposit.d.ts +0 -1
- 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/enumeration.d.ts +5 -0
- package/es/tx/builder/field-types/enumeration.mjs +21 -0
- package/es/tx/builder/field-types/enumeration.mjs.map +1 -0
- package/es/tx/builder/field-types/fee.d.ts +1 -9
- package/es/tx/builder/field-types/fee.mjs +9 -25
- 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.mjs +4 -9
- 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 +23 -11
- package/es/tx/builder/field-types/index.mjs +10 -3
- package/es/tx/builder/field-types/index.mjs.map +1 -1
- package/es/tx/builder/field-types/name-fee.d.ts +0 -1
- 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 +4 -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/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/u-int.d.ts +1 -1
- 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 +1 -21
- package/es/tx/builder/index.mjs +29 -148
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +336 -176
- package/es/tx/builder/schema.mjs +71 -78
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +3 -33
- package/es/tx/index.mjs +26 -43
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +2 -2
- package/es/tx/validator.mjs +86 -59
- 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 +12 -6
- package/es/utils/errors.mjs +87 -163
- 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/mptree.d.ts +1 -1
- package/es/utils/mptree.mjs +4 -26
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +3 -1
- 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 +87 -48
- package/src/AeSdk.ts +15 -11
- package/src/AeSdkAepp.ts +9 -7
- package/src/AeSdkBase.ts +28 -202
- package/src/AeSdkMethods.ts +170 -0
- package/src/AeSdkWallet.ts +16 -47
- package/src/Node.ts +11 -15
- 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 +10 -9
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +5 -4
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +3 -3
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +2 -2
- 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 +6 -3
- package/src/channel/Base.ts +327 -0
- package/src/channel/Contract.ts +487 -0
- package/src/channel/Spend.ts +403 -0
- package/src/channel/handlers.ts +154 -573
- package/src/channel/internal.ts +113 -142
- package/src/contract/{Compiler.ts → CompilerHttp.ts} +5 -5
- package/src/contract/Contract.ts +620 -0
- package/src/contract/ga.ts +18 -104
- package/src/index.ts +9 -8
- package/src/oracle.ts +7 -7
- package/src/spend.ts +5 -13
- package/src/tx/builder/constants.ts +1 -0
- package/src/tx/builder/field-types/address.ts +52 -0
- package/src/tx/builder/field-types/addresses.ts +18 -0
- package/src/tx/builder/field-types/coin-amount.ts +2 -8
- package/src/tx/builder/field-types/enumeration.ts +21 -0
- package/src/tx/builder/field-types/fee.ts +1 -3
- package/src/tx/builder/field-types/gas-limit.ts +2 -2
- package/src/tx/builder/field-types/gas-price.ts +0 -2
- package/src/tx/builder/field-types/index.ts +16 -6
- package/src/tx/builder/field-types/name-fee.ts +1 -1
- 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/u-int.ts +3 -2
- package/src/tx/builder/helpers.ts +10 -60
- package/src/tx/builder/index.ts +6 -65
- package/src/tx/builder/schema.ts +89 -100
- package/src/tx/index.ts +19 -15
- package/src/tx/validator.ts +36 -18
- package/src/typings/@aeternity__aepp-calldata/index.d.ts +20 -0
- package/src/utils/autorest.ts +16 -1
- package/src/utils/bytes.ts +5 -33
- package/src/utils/crypto.ts +23 -16
- package/src/utils/encoder.ts +0 -1
- package/src/utils/errors.ts +18 -12
- 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 +141 -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 +18 -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 +248 -0
- package/types-legacy/ts4.2/channel/Base.d.ts +194 -0
- package/types-legacy/ts4.2/channel/Contract.d.ts +247 -0
- package/types-legacy/ts4.2/channel/Spend.d.ts +217 -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/CompilerHttp.d.ts +18 -0
- package/types-legacy/ts4.2/contract/Contract.d.ts +237 -0
- package/types-legacy/ts4.2/contract/ga.d.ts +43 -0
- package/types-legacy/ts4.2/globals.d.ts +16 -0
- package/types-legacy/ts4.2/index.d.ts +39 -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 +71 -0
- package/types-legacy/ts4.2/tx/builder/field-types/address.d.ts +22 -0
- package/types-legacy/ts4.2/tx/builder/field-types/addresses.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/deposit.d.ts +14 -0
- package/types-legacy/ts4.2/tx/builder/field-types/enumeration.d.ts +5 -0
- package/types-legacy/ts4.2/tx/builder/field-types/fee.d.ts +17 -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 +12 -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 +85 -0
- package/types-legacy/ts4.2/tx/builder/field-types/name-fee.d.ts +19 -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/short-u-int.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/u-int.d.ts +8 -0
- package/types-legacy/ts4.2/tx/builder/helpers.d.ts +112 -0
- package/types-legacy/ts4.2/tx/builder/index.d.ts +68 -0
- package/types-legacy/ts4.2/tx/builder/schema.d.ts +2963 -0
- package/types-legacy/ts4.2/tx/index.d.ts +34 -0
- package/types-legacy/ts4.2/tx/validator.d.ts +20 -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 +480 -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/mptree.d.ts +32 -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 +141 -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 +18 -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 +248 -0
- package/types-legacy/ts4.5/channel/Base.d.ts +194 -0
- package/types-legacy/ts4.5/channel/Contract.d.ts +247 -0
- package/types-legacy/ts4.5/channel/Spend.d.ts +217 -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/CompilerHttp.d.ts +18 -0
- package/types-legacy/ts4.5/contract/Contract.d.ts +237 -0
- package/types-legacy/ts4.5/contract/ga.d.ts +43 -0
- package/types-legacy/ts4.5/index.d.ts +38 -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 +71 -0
- package/types-legacy/ts4.5/tx/builder/field-types/address.d.ts +22 -0
- package/types-legacy/ts4.5/tx/builder/field-types/addresses.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/deposit.d.ts +14 -0
- package/types-legacy/ts4.5/tx/builder/field-types/enumeration.d.ts +5 -0
- package/types-legacy/ts4.5/tx/builder/field-types/fee.d.ts +17 -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 +12 -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 +85 -0
- package/types-legacy/ts4.5/tx/builder/field-types/name-fee.d.ts +19 -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/short-u-int.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/u-int.d.ts +8 -0
- package/types-legacy/ts4.5/tx/builder/helpers.d.ts +112 -0
- package/types-legacy/ts4.5/tx/builder/index.d.ts +68 -0
- package/types-legacy/ts4.5/tx/builder/schema.d.ts +2963 -0
- package/types-legacy/ts4.5/tx/index.d.ts +34 -0
- package/types-legacy/ts4.5/tx/validator.d.ts +20 -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 +480 -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/mptree.d.ts +32 -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.mjs.map +0 -1
- package/es/contract/aci.d.ts +0 -127
- package/es/contract/aci.mjs +0 -509
- 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/src/channel/index.ts +0 -1025
- package/src/contract/aci.ts +0 -538
- 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/es/utils/keystore.mjs
CHANGED
|
@@ -1,42 +1,39 @@
|
|
|
1
|
+
import _buffer from "buffer";
|
|
2
|
+
const {
|
|
3
|
+
Buffer: _Buffer
|
|
4
|
+
} = _buffer;
|
|
1
5
|
import nacl from 'tweetnacl';
|
|
2
|
-
import { v4 as uuid } from '@aeternity/uuid';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import _aeternityArgon2BrowserDistArgon2BundledMinJs from '@aeternity/argon2-browser/dist/argon2-bundled.min.js';
|
|
6
|
+
import { v4 as uuid } from '@aeternity/uuid';
|
|
7
|
+
import _aeternityArgon from '@aeternity/argon2';
|
|
6
8
|
const {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} =
|
|
9
|
+
hash,
|
|
10
|
+
argon2id
|
|
11
|
+
} = _aeternityArgon;
|
|
10
12
|
import { getAddressFromPriv } from "./crypto.mjs";
|
|
11
|
-
import { bytesToHex, hexToBytes } from "./bytes.mjs";
|
|
12
13
|
import { InvalidPasswordError } from "./errors.mjs";
|
|
13
14
|
const DERIVED_KEY_FUNCTIONS = {
|
|
14
15
|
async argon2id(pass, salt, params) {
|
|
15
16
|
const {
|
|
16
|
-
memlimit_kib:
|
|
17
|
-
opslimit:
|
|
17
|
+
memlimit_kib: memoryCost,
|
|
18
|
+
opslimit: timeCost
|
|
18
19
|
} = params;
|
|
19
|
-
return (
|
|
20
|
-
|
|
21
|
-
pass,
|
|
20
|
+
return hash(pass, {
|
|
21
|
+
hashLength: 32,
|
|
22
22
|
salt,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
type:
|
|
26
|
-
})
|
|
23
|
+
timeCost,
|
|
24
|
+
memoryCost,
|
|
25
|
+
type: argon2id
|
|
26
|
+
});
|
|
27
27
|
}
|
|
28
|
-
|
|
29
28
|
};
|
|
30
29
|
const CRYPTO_FUNCTIONS = {
|
|
31
30
|
'xsalsa20-poly1305': {
|
|
32
31
|
encrypt: nacl.secretbox,
|
|
33
|
-
|
|
34
32
|
decrypt() {
|
|
35
33
|
const res = nacl.secretbox.open(...arguments);
|
|
36
34
|
if (res == null) throw new InvalidPasswordError();
|
|
37
35
|
return res;
|
|
38
36
|
}
|
|
39
|
-
|
|
40
37
|
}
|
|
41
38
|
};
|
|
42
39
|
const CRYPTO_DEFAULTS = {
|
|
@@ -49,63 +46,66 @@ const CRYPTO_DEFAULTS = {
|
|
|
49
46
|
parallelism: 1
|
|
50
47
|
}
|
|
51
48
|
};
|
|
49
|
+
|
|
52
50
|
/**
|
|
53
51
|
* Symmetric private key encryption using secret (derived) key.
|
|
52
|
+
* @category keystore
|
|
54
53
|
* @param plaintext - Data to be encrypted.
|
|
55
54
|
* @param key - Secret key.
|
|
56
55
|
* @param nonce - Randomly generated nonce.
|
|
57
56
|
* @param algo - Encryption algorithm.
|
|
58
57
|
* @returns Encrypted data.
|
|
59
58
|
*/
|
|
60
|
-
|
|
61
59
|
function encrypt(plaintext, key, nonce) {
|
|
62
60
|
let algo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : CRYPTO_DEFAULTS.symmetric_alg;
|
|
63
61
|
return CRYPTO_FUNCTIONS[algo].encrypt(plaintext, nonce, key);
|
|
64
62
|
}
|
|
63
|
+
|
|
65
64
|
/**
|
|
66
65
|
* Symmetric private key decryption using secret (derived) key.
|
|
66
|
+
* @category keystore
|
|
67
67
|
* @param ciphertext - Data to be decrypted.
|
|
68
68
|
* @param key - Secret key.
|
|
69
69
|
* @param nonce - Nonce from key-object.
|
|
70
70
|
* @param algo - Encryption algorithm.
|
|
71
71
|
* @returns Decrypted data.
|
|
72
72
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
73
|
function decrypt(ciphertext, key, nonce) {
|
|
76
74
|
let algo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : CRYPTO_DEFAULTS.symmetric_alg;
|
|
77
75
|
return CRYPTO_FUNCTIONS[algo].decrypt(ciphertext, nonce, key);
|
|
78
76
|
}
|
|
77
|
+
|
|
79
78
|
/**
|
|
80
79
|
* Derive secret key from password with key derivation function.
|
|
80
|
+
* @category keystore
|
|
81
81
|
* @param password - User-supplied password.
|
|
82
82
|
* @param nonce - Randomly generated nonce.
|
|
83
83
|
* @param kdf - Key derivation function.
|
|
84
84
|
* @param kdfParams - KDF parameters.
|
|
85
85
|
* @returns Secret key derived from password.
|
|
86
86
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
89
87
|
async function deriveKey(password, nonce, kdf, kdfParams) {
|
|
90
88
|
return DERIVED_KEY_FUNCTIONS[kdf](password, nonce, kdfParams);
|
|
91
89
|
}
|
|
90
|
+
|
|
92
91
|
/**
|
|
93
92
|
* Recover plaintext private key from secret-storage key object.
|
|
93
|
+
* @category keystore
|
|
94
94
|
* @param password - Keystore object password.
|
|
95
95
|
* @param keystore - Keystore object.
|
|
96
96
|
* @returns Plaintext private key.
|
|
97
97
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
98
|
export async function recover(password, _ref) {
|
|
101
99
|
let {
|
|
102
100
|
crypto
|
|
103
101
|
} = _ref;
|
|
104
|
-
const salt =
|
|
105
|
-
return
|
|
102
|
+
const salt = _Buffer.from(crypto.kdf_params.salt, 'hex');
|
|
103
|
+
return _Buffer.from(decrypt(_Buffer.from(crypto.ciphertext, 'hex'), await deriveKey(password, salt, crypto.kdf, crypto.kdf_params), _Buffer.from(crypto.cipher_params.nonce, 'hex'), crypto.symmetric_alg)).toString('hex');
|
|
106
104
|
}
|
|
105
|
+
|
|
107
106
|
/**
|
|
108
107
|
* Export private key to keystore secret-storage format.
|
|
108
|
+
* @category keystore
|
|
109
109
|
* @param name - Key name.
|
|
110
110
|
* @param password - User-supplied password.
|
|
111
111
|
* @param privateKey - Private key as hex-string or a Buffer.
|
|
@@ -115,16 +115,16 @@ export async function recover(password, _ref) {
|
|
|
115
115
|
* @param options.kdf - Key derivation function.
|
|
116
116
|
* @param options.kdf_params - KDF parameters.
|
|
117
117
|
*/
|
|
118
|
-
|
|
119
118
|
export async function dump(name, password, privateKey) {
|
|
120
119
|
let nonce = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : nacl.randomBytes(24);
|
|
121
120
|
let salt = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : nacl.randomBytes(16);
|
|
122
121
|
let options = arguments.length > 5 ? arguments[5] : undefined;
|
|
123
|
-
const opt = {
|
|
122
|
+
const opt = {
|
|
123
|
+
...CRYPTO_DEFAULTS,
|
|
124
124
|
...options
|
|
125
125
|
};
|
|
126
126
|
const derivedKey = await deriveKey(password, salt, opt.kdf, opt.kdf_params);
|
|
127
|
-
const payload = typeof privateKey === 'string' ?
|
|
127
|
+
const payload = typeof privateKey === 'string' ? _Buffer.from(privateKey, 'hex') : privateKey;
|
|
128
128
|
return {
|
|
129
129
|
name,
|
|
130
130
|
version: 1,
|
|
@@ -133,13 +133,14 @@ export async function dump(name, password, privateKey) {
|
|
|
133
133
|
crypto: {
|
|
134
134
|
secret_type: opt.secret_type,
|
|
135
135
|
symmetric_alg: opt.symmetric_alg,
|
|
136
|
-
ciphertext:
|
|
136
|
+
ciphertext: _Buffer.from(encrypt(payload, derivedKey, nonce, opt.symmetric_alg)).toString('hex'),
|
|
137
137
|
cipher_params: {
|
|
138
|
-
nonce:
|
|
138
|
+
nonce: _Buffer.from(nonce).toString('hex')
|
|
139
139
|
},
|
|
140
140
|
kdf: opt.kdf,
|
|
141
|
-
kdf_params: {
|
|
142
|
-
|
|
141
|
+
kdf_params: {
|
|
142
|
+
...opt.kdf_params,
|
|
143
|
+
salt: _Buffer.from(salt).toString('hex')
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
146
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keystore.mjs","names":["nacl","v4","uuid","getAddressFromPriv","
|
|
1
|
+
{"version":3,"file":"keystore.mjs","names":["nacl","v4","uuid","getAddressFromPriv","InvalidPasswordError","DERIVED_KEY_FUNCTIONS","argon2id","pass","salt","params","memlimit_kib","memoryCost","opslimit","timeCost","hash","hashLength","type","CRYPTO_FUNCTIONS","encrypt","secretbox","decrypt","res","open","CRYPTO_DEFAULTS","secret_type","symmetric_alg","kdf","kdf_params","parallelism","plaintext","key","nonce","algo","ciphertext","deriveKey","password","kdfParams","recover","crypto","from","cipher_params","toString","dump","name","privateKey","randomBytes","options","opt","derivedKey","payload","version","public_key","id"],"sources":["../../src/utils/keystore.ts"],"sourcesContent":["import nacl from 'tweetnacl';\nimport { v4 as uuid } from '@aeternity/uuid';\nimport { hash, argon2id } from '@aeternity/argon2';\nimport { getAddressFromPriv } from './crypto';\nimport { InvalidPasswordError } from './errors';\n\nconst DERIVED_KEY_FUNCTIONS = {\n async argon2id(\n pass: string | Uint8Array,\n salt: string | Uint8Array,\n params: Partial<Keystore['crypto']['kdf_params']>,\n ): Promise<Uint8Array> {\n const { memlimit_kib: memoryCost, opslimit: timeCost } = params;\n\n return hash(pass, {\n hashLength: 32,\n salt,\n timeCost,\n memoryCost,\n type: argon2id,\n });\n },\n};\n\nconst CRYPTO_FUNCTIONS = {\n 'xsalsa20-poly1305': {\n encrypt: nacl.secretbox,\n decrypt(...args: Parameters<typeof nacl.secretbox.open>): Uint8Array {\n const res = nacl.secretbox.open(...args);\n if (res == null) throw new InvalidPasswordError();\n return res;\n },\n },\n};\n\nexport interface Keystore {\n name: string;\n version: 1;\n public_key: string;\n id: string;\n crypto: {\n secret_type: 'ed25519';\n symmetric_alg: keyof typeof CRYPTO_FUNCTIONS;\n ciphertext: string;\n cipher_params: {\n nonce: string;\n };\n kdf: keyof typeof DERIVED_KEY_FUNCTIONS;\n kdf_params: {\n memlimit_kib: number;\n opslimit: number;\n parallelism: number;\n salt: string;\n };\n };\n}\n\nconst CRYPTO_DEFAULTS = {\n secret_type: 'ed25519',\n symmetric_alg: 'xsalsa20-poly1305',\n kdf: 'argon2id',\n kdf_params: {\n memlimit_kib: 65536,\n opslimit: 3,\n parallelism: 1,\n },\n} as const;\n\n/**\n * Symmetric private key encryption using secret (derived) key.\n * @category keystore\n * @param plaintext - Data to be encrypted.\n * @param key - Secret key.\n * @param nonce - Randomly generated nonce.\n * @param algo - Encryption algorithm.\n * @returns Encrypted data.\n */\nfunction encrypt(\n plaintext: Uint8Array,\n key: Uint8Array,\n nonce: Uint8Array,\n algo: keyof typeof CRYPTO_FUNCTIONS = CRYPTO_DEFAULTS.symmetric_alg,\n): Uint8Array {\n return CRYPTO_FUNCTIONS[algo].encrypt(plaintext, nonce, key);\n}\n\n/**\n * Symmetric private key decryption using secret (derived) key.\n * @category keystore\n * @param ciphertext - Data to be decrypted.\n * @param key - Secret key.\n * @param nonce - Nonce from key-object.\n * @param algo - Encryption algorithm.\n * @returns Decrypted data.\n */\nfunction decrypt(\n ciphertext: Uint8Array,\n key: Uint8Array,\n nonce: Uint8Array,\n algo: keyof typeof CRYPTO_FUNCTIONS = CRYPTO_DEFAULTS.symmetric_alg,\n): Uint8Array {\n return CRYPTO_FUNCTIONS[algo].decrypt(ciphertext, nonce, key);\n}\n\n/**\n * Derive secret key from password with key derivation function.\n * @category keystore\n * @param password - User-supplied password.\n * @param nonce - Randomly generated nonce.\n * @param kdf - Key derivation function.\n * @param kdfParams - KDF parameters.\n * @returns Secret key derived from password.\n */\nasync function deriveKey(\n password: string | Uint8Array,\n nonce: string | Uint8Array,\n kdf: Keystore['crypto']['kdf'],\n kdfParams: Omit<Keystore['crypto']['kdf_params'], 'salt'>,\n): Promise<Uint8Array> {\n return DERIVED_KEY_FUNCTIONS[kdf](password, nonce, kdfParams);\n}\n\n/**\n * Recover plaintext private key from secret-storage key object.\n * @category keystore\n * @param password - Keystore object password.\n * @param keystore - Keystore object.\n * @returns Plaintext private key.\n */\nexport async function recover(\n password: string | Uint8Array,\n { crypto }: Keystore,\n): Promise<string> {\n const salt = Buffer.from(crypto.kdf_params.salt, 'hex');\n return Buffer.from(decrypt(\n Buffer.from(crypto.ciphertext, 'hex'),\n await deriveKey(password, salt, crypto.kdf, crypto.kdf_params),\n Buffer.from(crypto.cipher_params.nonce, 'hex'),\n crypto.symmetric_alg,\n )).toString('hex');\n}\n\n/**\n * Export private key to keystore secret-storage format.\n * @category keystore\n * @param name - Key name.\n * @param password - User-supplied password.\n * @param privateKey - Private key as hex-string or a Buffer.\n * @param nonce - Randomly generated 24byte nonce.\n * @param salt - Randomly generated 16byte salt.\n * @param options - Encryption parameters.\n * @param options.kdf - Key derivation function.\n * @param options.kdf_params - KDF parameters.\n */\nexport async function dump(\n name: string,\n password: string | Uint8Array,\n privateKey: string | Uint8Array,\n nonce: Uint8Array = nacl.randomBytes(24),\n salt: Uint8Array = nacl.randomBytes(16),\n options?: Partial<Keystore['crypto']>,\n): Promise<Keystore> {\n const opt = { ...CRYPTO_DEFAULTS, ...options };\n const derivedKey = await deriveKey(password, salt, opt.kdf, opt.kdf_params);\n const payload = typeof privateKey === 'string' ? Buffer.from(privateKey, 'hex') : privateKey;\n return {\n name,\n version: 1,\n public_key: getAddressFromPriv(payload),\n id: uuid(),\n crypto: {\n secret_type: opt.secret_type,\n symmetric_alg: opt.symmetric_alg,\n ciphertext: Buffer.from(\n encrypt(payload, derivedKey, nonce, opt.symmetric_alg),\n ).toString('hex'),\n cipher_params: { nonce: Buffer.from(nonce).toString('hex') },\n kdf: opt.kdf,\n kdf_params: {\n ...opt.kdf_params,\n salt: Buffer.from(salt).toString('hex'),\n },\n },\n };\n}\n"],"mappings":";;;;AAAA,OAAOA,IAAI,MAAM,WAAW;AAC5B,SAASC,EAAE,IAAIC,IAAI,QAAQ,iBAAiB;AAC5C,4BAA+B,mBAAmB;AAAC;EAAA;EAAA;AAAA;AAAA,SAC1CC,kBAAkB;AAAA,SAClBC,oBAAoB;AAE7B,MAAMC,qBAAqB,GAAG;EAC5B,MAAMC,QAAQ,CACZC,IAAyB,EACzBC,IAAyB,EACzBC,MAAiD,EAC5B;IACrB,MAAM;MAAEC,YAAY,EAAEC,UAAU;MAAEC,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,GAAG,EAAEqB,GAAG,CAACpB,UAAU,CAAC;EAC3E,MAAMsB,OAAO,GAAG,OAAOL,UAAU,KAAK,QAAQ,GAAG,QAAOL,IAAI,CAACK,UAAU,EAAE,KAAK,CAAC,GAAGA,UAAU;EAC5F,OAAO;IACLD,IAAI;IACJO,OAAO,EAAE,CAAC;IACVC,UAAU,EAAEhD,kBAAkB,CAAC8C,OAAO,CAAC;IACvCG,EAAE,EAAElD,IAAI,EAAE;IACVoC,MAAM,EAAE;MACNd,WAAW,EAAEuB,GAAG,CAACvB,WAAW;MAC5BC,aAAa,EAAEsB,GAAG,CAACtB,aAAa;MAChCQ,UAAU,EAAE,QAAOM,IAAI,CACrBrB,OAAO,CAAC+B,OAAO,EAAED,UAAU,EAAEjB,KAAK,EAAEgB,GAAG,CAACtB,aAAa,CAAC,CACvD,CAACgB,QAAQ,CAAC,KAAK,CAAC;MACjBD,aAAa,EAAE;QAAET,KAAK,EAAE,QAAOQ,IAAI,CAACR,KAAK,CAAC,CAACU,QAAQ,CAAC,KAAK;MAAE,CAAC;MAC5Df,GAAG,EAAEqB,GAAG,CAACrB,GAAG;MACZC,UAAU,EAAE;QACV,GAAGoB,GAAG,CAACpB,UAAU;QACjBnB,IAAI,EAAE,QAAO+B,IAAI,CAAC/B,IAAI,CAAC,CAACiC,QAAQ,CAAC,KAAK;MACxC;IACF;EACF,CAAC;AACH"}
|
package/es/utils/mptree.d.ts
CHANGED
package/es/utils/mptree.mjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import _buffer from "buffer";
|
|
2
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
3
2
|
const {
|
|
4
3
|
Buffer: _Buffer
|
|
5
4
|
} = _buffer;
|
|
6
|
-
|
|
7
5
|
/*
|
|
8
6
|
* ISC License (ISC)
|
|
9
7
|
* Copyright (c) 2021 aeternity developers
|
|
@@ -29,24 +27,21 @@ const {
|
|
|
29
27
|
import { hash } from "./crypto.mjs";
|
|
30
28
|
import { MerkleTreeHashMismatchError, MissingNodeInTreeError, UnknownPathNibbleError, UnknownNodeLengthError } from "./errors.mjs";
|
|
31
29
|
var NodeType;
|
|
32
|
-
|
|
33
30
|
(function (NodeType) {
|
|
34
31
|
NodeType[NodeType["Branch"] = 0] = "Branch";
|
|
35
32
|
NodeType[NodeType["Extension"] = 1] = "Extension";
|
|
36
33
|
NodeType[NodeType["Leaf"] = 2] = "Leaf";
|
|
37
34
|
})(NodeType || (NodeType = {}));
|
|
38
|
-
|
|
39
35
|
export default class MPTree {
|
|
40
36
|
static nodeHash(node) {
|
|
41
37
|
return _Buffer.from(hash(rlpEncode(node))).toString('hex');
|
|
42
38
|
}
|
|
39
|
+
|
|
43
40
|
/**
|
|
44
41
|
* Deserialize Merkle Patricia Tree
|
|
45
42
|
* @param binary - Binary
|
|
46
43
|
* @returns Merkle Patricia Tree
|
|
47
44
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
45
|
constructor(binary) {
|
|
51
46
|
this.rootHash = binary[0].toString('hex');
|
|
52
47
|
this.nodes = Object.fromEntries(binary[1].map(node => [node[0].toString('hex'), node[1]]));
|
|
@@ -58,7 +53,6 @@ export default class MPTree {
|
|
|
58
53
|
type,
|
|
59
54
|
payload
|
|
60
55
|
} = MPTree.parseNode(node);
|
|
61
|
-
|
|
62
56
|
switch (type) {
|
|
63
57
|
case NodeType.Branch:
|
|
64
58
|
payload.slice(0, 16).filter(n => n.length).forEach(n => {
|
|
@@ -67,20 +61,16 @@ export default class MPTree {
|
|
|
67
61
|
}
|
|
68
62
|
});
|
|
69
63
|
break;
|
|
70
|
-
|
|
71
64
|
case NodeType.Extension:
|
|
72
65
|
if (this.nodes[payload[0].toString('hex')] === undefined) {
|
|
73
66
|
throw new MissingNodeInTreeError('Can\'t find a node by hash in extension node');
|
|
74
67
|
}
|
|
75
|
-
|
|
76
68
|
}
|
|
77
69
|
});
|
|
78
70
|
}
|
|
79
|
-
|
|
80
71
|
isEqual(tree) {
|
|
81
72
|
return this.rootHash === tree.rootHash;
|
|
82
73
|
}
|
|
83
|
-
|
|
84
74
|
static parseNode(node) {
|
|
85
75
|
switch (node.length) {
|
|
86
76
|
case 17:
|
|
@@ -89,50 +79,42 @@ export default class MPTree {
|
|
|
89
79
|
payload: node,
|
|
90
80
|
path: null
|
|
91
81
|
};
|
|
92
|
-
|
|
93
82
|
case 2:
|
|
94
83
|
{
|
|
95
|
-
var _context;
|
|
96
|
-
|
|
97
84
|
const nibble = node[0][0] >> 4; // eslint-disable-line no-bitwise
|
|
98
|
-
|
|
99
85
|
if (nibble > 3) throw new UnknownPathNibbleError(nibble);
|
|
100
86
|
const type = nibble <= 1 ? NodeType.Extension : NodeType.Leaf;
|
|
101
|
-
const slice =
|
|
87
|
+
const slice = [0, 2].includes(nibble) ? 2 : 1;
|
|
102
88
|
return {
|
|
103
89
|
type,
|
|
104
90
|
payload: [node[1]],
|
|
105
91
|
path: node[0].toString('hex').slice(slice)
|
|
106
92
|
};
|
|
107
93
|
}
|
|
108
|
-
|
|
109
94
|
default:
|
|
110
95
|
throw new UnknownNodeLengthError(node.length);
|
|
111
96
|
}
|
|
112
97
|
}
|
|
98
|
+
|
|
113
99
|
/**
|
|
114
100
|
* Serialize Merkle Patricia Tree
|
|
115
101
|
* @returns Binary
|
|
116
102
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
103
|
serialize() {
|
|
120
104
|
return [_Buffer.from(this.rootHash, 'hex'), Object.entries(this.nodes).map(_ref2 => {
|
|
121
105
|
let [mptHash, value] = _ref2;
|
|
122
106
|
return [_Buffer.from(mptHash, 'hex'), value];
|
|
123
107
|
})];
|
|
124
108
|
}
|
|
109
|
+
|
|
125
110
|
/**
|
|
126
111
|
* Retrieve value from Merkle Patricia Tree
|
|
127
112
|
* @param _key - The key of the element to retrieve
|
|
128
113
|
* @returns Value associated to the specified key
|
|
129
114
|
*/
|
|
130
|
-
|
|
131
|
-
|
|
132
115
|
get(_key) {
|
|
133
116
|
let searchFrom = this.rootHash;
|
|
134
117
|
let key = _key;
|
|
135
|
-
|
|
136
118
|
while (true) {
|
|
137
119
|
// eslint-disable-line no-constant-condition
|
|
138
120
|
const {
|
|
@@ -140,26 +122,22 @@ export default class MPTree {
|
|
|
140
122
|
payload,
|
|
141
123
|
path
|
|
142
124
|
} = MPTree.parseNode(this.nodes[searchFrom]);
|
|
143
|
-
|
|
144
125
|
switch (type) {
|
|
145
126
|
case NodeType.Branch:
|
|
146
127
|
if (key.length === 0) return payload[16];
|
|
147
128
|
searchFrom = payload[+`0x${key[0]}`].toString('hex');
|
|
148
129
|
key = key.substring(1);
|
|
149
130
|
break;
|
|
150
|
-
|
|
151
131
|
case NodeType.Extension:
|
|
152
132
|
if (key.substring(0, path === null || path === void 0 ? void 0 : path.length) !== path) return undefined;
|
|
153
133
|
searchFrom = payload[0].toString('hex');
|
|
154
134
|
key = key.substring(path.length);
|
|
155
135
|
break;
|
|
156
|
-
|
|
157
136
|
case NodeType.Leaf:
|
|
158
137
|
if (path !== key) return undefined;
|
|
159
138
|
return payload[0];
|
|
160
139
|
}
|
|
161
140
|
}
|
|
162
141
|
}
|
|
163
|
-
|
|
164
142
|
}
|
|
165
143
|
//# sourceMappingURL=mptree.mjs.map
|
package/es/utils/mptree.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mptree.mjs","names":["hash","MerkleTreeHashMismatchError","MissingNodeInTreeError","UnknownPathNibbleError","UnknownNodeLengthError","NodeType","MPTree","nodeHash","node","from","rlpEncode","toString","constructor","binary","rootHash","nodes","Object","fromEntries","map","undefined","entries","forEach","key","type","payload","parseNode","Branch","slice","filter","n","length","Extension","isEqual","tree","path","nibble","Leaf","serialize","mptHash","value","get","_key","searchFrom","substring"],"sources":["../../src/utils/mptree.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2021 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/* eslint-disable default-case */\nimport { encode as rlpEncode } from 'rlp';\nimport type { Input } from 'rlp';\nimport { hash } from './crypto';\nimport {\n MerkleTreeHashMismatchError,\n MissingNodeInTreeError,\n UnknownPathNibbleError,\n UnknownNodeLengthError,\n} from './errors';\n\nenum NodeType {\n Branch,\n Extension,\n Leaf,\n}\n\nexport type MPTreeBinary = [Buffer, Array<[Buffer, Buffer[]]>];\n\nexport default class MPTree {\n private readonly rootHash: string;\n\n private readonly nodes: { [key: string]: Buffer[] };\n\n private static nodeHash(node: Input): string {\n return Buffer.from(hash(rlpEncode(node))).toString('hex');\n }\n\n /**\n * Deserialize Merkle Patricia Tree\n * @param binary - Binary\n * @returns Merkle Patricia Tree\n */\n constructor(binary: MPTreeBinary) {\n this.rootHash = binary[0].toString('hex');\n this.nodes = Object.fromEntries(\n binary[1].map((node) => [node[0].toString('hex'), node[1]]),\n );\n\n if (this.nodes[this.rootHash] === undefined) throw new MissingNodeInTreeError('Can\\'t find a node by root hash');\n Object.entries(this.nodes).forEach(([key, node]) => {\n if (MPTree.nodeHash(node) !== key) throw new MerkleTreeHashMismatchError();\n const { type, payload } = MPTree.parseNode(node);\n switch (type) {\n case NodeType.Branch:\n payload\n .slice(0, 16)\n .filter((n) => n.length)\n .forEach((n) => {\n if (this.nodes[n.toString('hex')] === undefined) {\n throw new MissingNodeInTreeError('Can\\'t find a node by hash in branch node');\n }\n });\n break;\n case NodeType.Extension:\n if (this.nodes[payload[0].toString('hex')] === undefined) {\n throw new MissingNodeInTreeError('Can\\'t find a node by hash in extension node');\n }\n }\n });\n }\n\n isEqual(tree: MPTree): boolean {\n return this.rootHash === tree.rootHash;\n }\n\n private static parseNode(node: Buffer[]): {\n type: NodeType;\n payload: Buffer[];\n path: string | null;\n } {\n switch (node.length) {\n case 17:\n return { type: NodeType.Branch, payload: node, path: null };\n case 2: {\n const nibble = node[0][0] >> 4; // eslint-disable-line no-bitwise\n if (nibble > 3) throw new UnknownPathNibbleError(nibble);\n const type = nibble <= 1 ? NodeType.Extension : NodeType.Leaf;\n const slice = [0, 2].includes(nibble) ? 2 : 1;\n return { type, payload: [node[1]], path: node[0].toString('hex').slice(slice) };\n }\n default:\n throw new UnknownNodeLengthError(node.length);\n }\n }\n\n /**\n * Serialize Merkle Patricia Tree\n * @returns Binary\n */\n serialize(): MPTreeBinary {\n return [\n Buffer.from(this.rootHash, 'hex'),\n Object.entries(this.nodes).map(([mptHash, value]) => ([\n Buffer.from(mptHash, 'hex'),\n value,\n ])),\n ];\n }\n\n /**\n * Retrieve value from Merkle Patricia Tree\n * @param _key - The key of the element to retrieve\n * @returns Value associated to the specified key\n */\n get(_key: string): Buffer | undefined {\n let searchFrom = this.rootHash;\n let key = _key;\n while (true) { // eslint-disable-line no-constant-condition\n const { type, payload, path } = MPTree.parseNode(this.nodes[searchFrom]);\n switch (type) {\n case NodeType.Branch:\n if (key.length === 0) return payload[16];\n searchFrom = payload[+`0x${key[0]}`].toString('hex');\n key = key.substring(1);\n break;\n case NodeType.Extension:\n if (key.substring(0, path?.length) !== path) return undefined;\n searchFrom = payload[0].toString('hex');\n key = key.substring(path.length);\n break;\n case NodeType.Leaf:\n if (path !== key) return undefined;\n return payload[0];\n }\n }\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"mptree.mjs","names":["hash","MerkleTreeHashMismatchError","MissingNodeInTreeError","UnknownPathNibbleError","UnknownNodeLengthError","NodeType","MPTree","nodeHash","node","from","rlpEncode","toString","constructor","binary","rootHash","nodes","Object","fromEntries","map","undefined","entries","forEach","key","type","payload","parseNode","Branch","slice","filter","n","length","Extension","isEqual","tree","path","nibble","Leaf","includes","serialize","mptHash","value","get","_key","searchFrom","substring"],"sources":["../../src/utils/mptree.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2021 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/* eslint-disable default-case */\nimport { encode as rlpEncode } from 'rlp';\nimport type { Input } from 'rlp';\nimport { hash } from './crypto';\nimport {\n MerkleTreeHashMismatchError,\n MissingNodeInTreeError,\n UnknownPathNibbleError,\n UnknownNodeLengthError,\n} from './errors';\n\nenum NodeType {\n Branch,\n Extension,\n Leaf,\n}\n\nexport type MPTreeBinary = [Buffer, Array<[Buffer, Buffer[]]>];\n\nexport default class MPTree {\n private readonly rootHash: string;\n\n private readonly nodes: { [key: string]: Buffer[] };\n\n private static nodeHash(node: Input): string {\n return Buffer.from(hash(rlpEncode(node))).toString('hex');\n }\n\n /**\n * Deserialize Merkle Patricia Tree\n * @param binary - Binary\n * @returns Merkle Patricia Tree\n */\n constructor(binary: MPTreeBinary) {\n this.rootHash = binary[0].toString('hex');\n this.nodes = Object.fromEntries(\n binary[1].map((node) => [node[0].toString('hex'), node[1]]),\n );\n\n if (this.nodes[this.rootHash] === undefined) throw new MissingNodeInTreeError('Can\\'t find a node by root hash');\n Object.entries(this.nodes).forEach(([key, node]) => {\n if (MPTree.nodeHash(node) !== key) throw new MerkleTreeHashMismatchError();\n const { type, payload } = MPTree.parseNode(node);\n switch (type) {\n case NodeType.Branch:\n payload\n .slice(0, 16)\n .filter((n) => n.length)\n .forEach((n) => {\n if (this.nodes[n.toString('hex')] === undefined) {\n throw new MissingNodeInTreeError('Can\\'t find a node by hash in branch node');\n }\n });\n break;\n case NodeType.Extension:\n if (this.nodes[payload[0].toString('hex')] === undefined) {\n throw new MissingNodeInTreeError('Can\\'t find a node by hash in extension node');\n }\n }\n });\n }\n\n isEqual(tree: MPTree): boolean {\n return this.rootHash === tree.rootHash;\n }\n\n private static parseNode(node: Buffer[]): {\n type: NodeType;\n payload: Buffer[];\n path: string | null;\n } {\n switch (node.length) {\n case 17:\n return { type: NodeType.Branch, payload: node, path: null };\n case 2: {\n const nibble = node[0][0] >> 4; // eslint-disable-line no-bitwise\n if (nibble > 3) throw new UnknownPathNibbleError(nibble);\n const type = nibble <= 1 ? NodeType.Extension : NodeType.Leaf;\n const slice = [0, 2].includes(nibble) ? 2 : 1;\n return { type, payload: [node[1]], path: node[0].toString('hex').slice(slice) };\n }\n default:\n throw new UnknownNodeLengthError(node.length);\n }\n }\n\n /**\n * Serialize Merkle Patricia Tree\n * @returns Binary\n */\n serialize(): MPTreeBinary {\n return [\n Buffer.from(this.rootHash, 'hex'),\n Object.entries(this.nodes).map(([mptHash, value]) => ([\n Buffer.from(mptHash, 'hex'),\n value,\n ])),\n ];\n }\n\n /**\n * Retrieve value from Merkle Patricia Tree\n * @param _key - The key of the element to retrieve\n * @returns Value associated to the specified key\n */\n get(_key: string): Buffer | undefined {\n let searchFrom = this.rootHash;\n let key = _key;\n while (true) { // eslint-disable-line no-constant-condition\n const { type, payload, path } = MPTree.parseNode(this.nodes[searchFrom]);\n switch (type) {\n case NodeType.Branch:\n if (key.length === 0) return payload[16];\n searchFrom = payload[+`0x${key[0]}`].toString('hex');\n key = key.substring(1);\n break;\n case NodeType.Extension:\n if (key.substring(0, path?.length) !== path) return undefined;\n searchFrom = payload[0].toString('hex');\n key = key.substring(path.length);\n break;\n case NodeType.Leaf:\n if (path !== key) return undefined;\n return payload[0];\n }\n }\n }\n}\n"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,iBAAoC,KAAK;AAAC;EAAA;AAAA;AAAA,SAEjCA,IAAI;AAAA,SAEXC,2BAA2B,EAC3BC,sBAAsB,EACtBC,sBAAsB,EACtBC,sBAAsB;AAAA,IAGnBC,QAAQ;AAAA,WAARA,QAAQ;EAARA,QAAQ,CAARA,QAAQ;EAARA,QAAQ,CAARA,QAAQ;EAARA,QAAQ,CAARA,QAAQ;AAAA,GAARA,QAAQ,KAARA,QAAQ;AAQb,eAAe,MAAMC,MAAM,CAAC;EAK1B,OAAeC,QAAQ,CAACC,IAAW,EAAU;IAC3C,OAAO,QAAOC,IAAI,CAACT,IAAI,CAACU,SAAS,CAACF,IAAI,CAAC,CAAC,CAAC,CAACG,QAAQ,CAAC,KAAK,CAAC;EAC3D;;EAEA;AACF;AACA;AACA;AACA;EACEC,WAAW,CAACC,MAAoB,EAAE;IAChC,IAAI,CAACC,QAAQ,GAAGD,MAAM,CAAC,CAAC,CAAC,CAACF,QAAQ,CAAC,KAAK,CAAC;IACzC,IAAI,CAACI,KAAK,GAAGC,MAAM,CAACC,WAAW,CAC7BJ,MAAM,CAAC,CAAC,CAAC,CAACK,GAAG,CAAEV,IAAI,IAAK,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[], totalLength?:
|
|
|
11
11
|
* @param key - Maybe object key
|
|
12
12
|
* @param object - Object
|
|
13
13
|
*/
|
|
14
|
-
export declare function isKeyOfObject<T>(key: string | number | symbol, object: T): key is keyof T;
|
|
14
|
+
export declare function isKeyOfObject<T extends object>(key: string | number | symbol, object: T): key is keyof T;
|
|
15
15
|
/**
|
|
16
16
|
* Array item type guard
|
|
17
17
|
* @param item - Maybe array item
|
|
18
18
|
* @param array - Array
|
|
19
19
|
*/
|
|
20
20
|
export declare function isItemOfArray<T>(item: any, array: readonly T[]): item is T;
|
|
21
|
+
export declare function isAccountNotFoundError(error: Error): boolean;
|
|
22
|
+
export type UnionToIntersection<Union> = (Union extends any ? (k: Union) => void : never) extends ((k: infer Intersection) => void) ? Intersection : never;
|
package/es/utils/other.mjs
CHANGED
|
@@ -1,40 +1,44 @@
|
|
|
1
1
|
import _buffer from "buffer";
|
|
2
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
3
2
|
const {
|
|
4
3
|
Buffer: _Buffer
|
|
5
4
|
} = _buffer;
|
|
5
|
+
import { RestError } from '@azure/core-rest-pipeline';
|
|
6
6
|
export const pause = async duration => new Promise(resolve => {
|
|
7
7
|
setTimeout(resolve, duration);
|
|
8
8
|
});
|
|
9
|
-
export const mapObject = (object, fn) => Object.fromEntries(Object.entries(object).map(fn));
|
|
9
|
+
export const mapObject = (object, fn) => Object.fromEntries(Object.entries(object).map(fn));
|
|
10
10
|
|
|
11
|
+
// remove after dropping webpack4 support
|
|
11
12
|
const isWebpack4Buffer = (() => {
|
|
12
13
|
try {
|
|
13
14
|
_Buffer.concat([Uint8Array.from([])]);
|
|
14
|
-
|
|
15
15
|
return false;
|
|
16
16
|
} catch (error) {
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
19
|
})();
|
|
20
|
-
|
|
21
20
|
export const concatBuffers = isWebpack4Buffer ? (list, totalLength) => _Buffer.concat(list.map(el => _Buffer.from(el)), totalLength) : _Buffer.concat;
|
|
21
|
+
|
|
22
22
|
/**
|
|
23
23
|
* Object key type guard
|
|
24
24
|
* @param key - Maybe object key
|
|
25
25
|
* @param object - Object
|
|
26
26
|
*/
|
|
27
|
-
|
|
28
27
|
export function isKeyOfObject(key, object) {
|
|
29
28
|
return key in object;
|
|
30
29
|
}
|
|
30
|
+
|
|
31
31
|
/**
|
|
32
32
|
* Array item type guard
|
|
33
33
|
* @param item - Maybe array item
|
|
34
34
|
* @param array - Array
|
|
35
35
|
*/
|
|
36
|
-
|
|
37
36
|
export function isItemOfArray(item, array) {
|
|
38
|
-
return
|
|
37
|
+
return array.includes(item);
|
|
39
38
|
}
|
|
39
|
+
export function isAccountNotFoundError(error) {
|
|
40
|
+
return error instanceof RestError && error.statusCode === 404 && error.message.includes('Account not found');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// based on https://stackoverflow.com/a/50375286/6176994
|
|
40
44
|
//# sourceMappingURL=other.mjs.map
|
package/es/utils/other.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"other.mjs","names":["pause","duration","Promise","resolve","setTimeout","mapObject","object","fn","Object","fromEntries","entries","map","isWebpack4Buffer","concat","Uint8Array","from","error","concatBuffers","list","totalLength","el","isKeyOfObject","key","isItemOfArray","item","array"],"sources":["../../src/utils/other.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"other.mjs","names":["RestError","pause","duration","Promise","resolve","setTimeout","mapObject","object","fn","Object","fromEntries","entries","map","isWebpack4Buffer","concat","Uint8Array","from","error","concatBuffers","list","totalLength","el","isKeyOfObject","key","isItemOfArray","item","array","includes","isAccountNotFoundError","statusCode","message"],"sources":["../../src/utils/other.ts"],"sourcesContent":["import { RestError } from '@azure/core-rest-pipeline';\n\nexport const pause = async (duration: number): Promise<void> => new Promise((resolve) => {\n setTimeout(resolve, duration);\n});\n\nexport const mapObject = <InputV, OutputV>(\n object: { [k: string]: InputV },\n fn: (\n value: [string, InputV], index: number, array: Array<[string, InputV]>\n ) => [number | string, OutputV],\n): { [k: string]: OutputV } => Object.fromEntries(Object.entries(object).map(fn));\n\n// remove after dropping webpack4 support\nconst isWebpack4Buffer = (() => {\n try {\n Buffer.concat([Uint8Array.from([])]);\n return false;\n } catch (error) {\n return true;\n }\n})();\n\nexport const concatBuffers = isWebpack4Buffer\n ? (list: readonly Uint8Array[], totalLength?: number): Buffer => (\n Buffer.concat(list.map((el) => Buffer.from(el)), totalLength)\n )\n : Buffer.concat;\n\n/**\n * Object key type guard\n * @param key - Maybe object key\n * @param object - Object\n */\nexport function isKeyOfObject<T extends object>(\n key: string | number | symbol,\n object: T,\n): key is keyof T {\n return key in object;\n}\n\n/**\n * Array item type guard\n * @param item - Maybe array item\n * @param array - Array\n */\nexport function isItemOfArray<T>(item: any, array: readonly T[]): item is T {\n return array.includes(item);\n}\n\nexport function isAccountNotFoundError(error: Error): boolean {\n return error instanceof RestError && error.statusCode === 404\n && error.message.includes('Account not found');\n}\n\n// based on https://stackoverflow.com/a/50375286/6176994\nexport type UnionToIntersection<Union> =\n (Union extends any ? (k: Union) => void : never) extends ((k: infer Intersection) => void)\n ? Intersection : never;\n"],"mappings":";;;;AAAA,SAASA,SAAS,QAAQ,2BAA2B;AAErD,OAAO,MAAMC,KAAK,GAAG,MAAOC,QAAgB,IAAoB,IAAIC,OAAO,CAAEC,OAAO,IAAK;EACvFC,UAAU,CAACD,OAAO,EAAEF,QAAQ,CAAC;AAC/B,CAAC,CAAC;AAEF,OAAO,MAAMI,SAAS,GAAG,CACvBC,MAA+B,EAC/BC,EAE+B,KACFC,MAAM,CAACC,WAAW,CAACD,MAAM,CAACE,OAAO,CAACJ,MAAM,CAAC,CAACK,GAAG,CAACJ,EAAE,CAAC,CAAC;;AAEjF;AACA,MAAMK,gBAAgB,GAAG,CAAC,MAAM;EAC9B,IAAI;IACF,QAAOC,MAAM,CAAC,CAACC,UAAU,CAACC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IACpC,OAAO,KAAK;EACd,CAAC,CAAC,OAAOC,KAAK,EAAE;IACd,OAAO,IAAI;EACb;AACF,CAAC,GAAG;AAEJ,OAAO,MAAMC,aAAa,GAAGL,gBAAgB,GACzC,CAACM,IAA2B,EAAEC,WAAoB,KAClD,QAAON,MAAM,CAACK,IAAI,CAACP,GAAG,CAAES,EAAE,IAAK,QAAOL,IAAI,CAACK,EAAE,CAAC,CAAC,EAAED,WAAW,CAC7D,GACC,QAAON,MAAM;;AAEjB;AACA;AACA;AACA;AACA;AACA,OAAO,SAASQ,aAAa,CAC3BC,GAA6B,EAC7BhB,MAAS,EACO;EAChB,OAAOgB,GAAG,IAAIhB,MAAM;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASiB,aAAa,CAAIC,IAAS,EAAEC,KAAmB,EAAa;EAC1E,OAAOA,KAAK,CAACC,QAAQ,CAACF,IAAI,CAAC;AAC7B;AAEA,OAAO,SAASG,sBAAsB,CAACX,KAAY,EAAW;EAC5D,OAAOA,KAAK,YAAYjB,SAAS,IAAIiB,KAAK,CAACY,UAAU,KAAK,GAAG,IACxDZ,KAAK,CAACa,OAAO,CAACH,QAAQ,CAAC,mBAAmB,CAAC;AAClD;;AAEA"}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
export default function semverSatisfies(version, geVersion, ltVersion) {
|
|
2
2
|
const getComponents = v => v.split(/[-+]/)[0].split('.').map(i => +i);
|
|
3
|
-
|
|
4
3
|
const versionComponents = getComponents(version);
|
|
5
4
|
const geComponents = getComponents(geVersion);
|
|
6
5
|
const ltComponents = getComponents(ltVersion);
|
|
7
6
|
const base = Math.max(...versionComponents, ...geComponents, ...ltComponents) + 1;
|
|
8
|
-
|
|
9
7
|
const componentsToNumber = components => components.reverse().reduce((acc, n, idx) => acc + n * base ** idx, 0);
|
|
10
|
-
|
|
11
8
|
const vNumber = componentsToNumber(versionComponents);
|
|
12
9
|
const geNumber = componentsToNumber(geComponents);
|
|
13
10
|
const ltNumber = componentsToNumber(ltComponents);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semver-satisfies.mjs","names":["semverSatisfies","version","geVersion","ltVersion","getComponents","v","split","map","i","versionComponents","geComponents","ltComponents","base","Math","max","componentsToNumber","components","reverse","reduce","acc","n","idx","vNumber","geNumber","ltNumber"],"sources":["../../src/utils/semver-satisfies.ts"],"sourcesContent":["export default function semverSatisfies(\n version: string,\n geVersion: string,\n ltVersion: string,\n): boolean {\n const getComponents = (v: string): number[] => v\n .split(/[-+]/)[0].split('.').map((i) => +i);\n\n const versionComponents = getComponents(version);\n const geComponents = getComponents(geVersion);\n const ltComponents = getComponents(ltVersion);\n\n const base = Math.max(...versionComponents, ...geComponents, ...ltComponents) + 1;\n const componentsToNumber = (components: number[]): number => components.reverse()\n .reduce((acc, n, idx) => acc + n * base ** idx, 0);\n\n const vNumber = componentsToNumber(versionComponents);\n const geNumber = componentsToNumber(geComponents);\n const ltNumber = componentsToNumber(ltComponents);\n return vNumber >= geNumber && vNumber < ltNumber;\n}\n"],"mappings":"AAAA,eAAe,SAASA,
|
|
1
|
+
{"version":3,"file":"semver-satisfies.mjs","names":["semverSatisfies","version","geVersion","ltVersion","getComponents","v","split","map","i","versionComponents","geComponents","ltComponents","base","Math","max","componentsToNumber","components","reverse","reduce","acc","n","idx","vNumber","geNumber","ltNumber"],"sources":["../../src/utils/semver-satisfies.ts"],"sourcesContent":["export default function semverSatisfies(\n version: string,\n geVersion: string,\n ltVersion: string,\n): boolean {\n const getComponents = (v: string): number[] => v\n .split(/[-+]/)[0].split('.').map((i) => +i);\n\n const versionComponents = getComponents(version);\n const geComponents = getComponents(geVersion);\n const ltComponents = getComponents(ltVersion);\n\n const base = Math.max(...versionComponents, ...geComponents, ...ltComponents) + 1;\n const componentsToNumber = (components: number[]): number => components.reverse()\n .reduce((acc, n, idx) => acc + n * base ** idx, 0);\n\n const vNumber = componentsToNumber(versionComponents);\n const geNumber = componentsToNumber(geComponents);\n const ltNumber = componentsToNumber(ltComponents);\n return vNumber >= geNumber && vNumber < ltNumber;\n}\n"],"mappings":"AAAA,eAAe,SAASA,eAAe,CACrCC,OAAe,EACfC,SAAiB,EACjBC,SAAiB,EACR;EACT,MAAMC,aAAa,GAAIC,CAAS,IAAeA,CAAC,CAC7CC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAACA,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAAEC,CAAC,IAAK,CAACA,CAAC,CAAC;EAE7C,MAAMC,iBAAiB,GAAGL,aAAa,CAACH,OAAO,CAAC;EAChD,MAAMS,YAAY,GAAGN,aAAa,CAACF,SAAS,CAAC;EAC7C,MAAMS,YAAY,GAAGP,aAAa,CAACD,SAAS,CAAC;EAE7C,MAAMS,IAAI,GAAGC,IAAI,CAACC,GAAG,CAAC,GAAGL,iBAAiB,EAAE,GAAGC,YAAY,EAAE,GAAGC,YAAY,CAAC,GAAG,CAAC;EACjF,MAAMI,kBAAkB,GAAIC,UAAoB,IAAaA,UAAU,CAACC,OAAO,EAAE,CAC9EC,MAAM,CAAC,CAACC,GAAG,EAAEC,CAAC,EAAEC,GAAG,KAAKF,GAAG,GAAGC,CAAC,GAAGR,IAAI,IAAIS,GAAG,EAAE,CAAC,CAAC;EAEpD,MAAMC,OAAO,GAAGP,kBAAkB,CAACN,iBAAiB,CAAC;EACrD,MAAMc,QAAQ,GAAGR,kBAAkB,CAACL,YAAY,CAAC;EACjD,MAAMc,QAAQ,GAAGT,kBAAkB,CAACJ,YAAY,CAAC;EACjD,OAAOW,OAAO,IAAIC,QAAQ,IAAID,OAAO,GAAGE,QAAQ;AAClD"}
|
package/es/utils/string.d.ts
CHANGED
|
@@ -10,15 +10,3 @@ export declare function snakeToPascal(s: string): string;
|
|
|
10
10
|
* @returns Converted string
|
|
11
11
|
*/
|
|
12
12
|
export declare function pascalToSnake(s: string): string;
|
|
13
|
-
/**
|
|
14
|
-
* Check whether a string is valid hex.
|
|
15
|
-
* @param str - String to validate.
|
|
16
|
-
* @returns True if the string is valid hex, false otherwise.
|
|
17
|
-
*/
|
|
18
|
-
export declare function isHex(str: string): boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Check whether a string is valid base-64.
|
|
21
|
-
* @param str - String to validate.
|
|
22
|
-
* @returns True if the string is valid base-64, false otherwise.
|
|
23
|
-
*/
|
|
24
|
-
export declare function isBase64(str: string): boolean;
|
package/es/utils/string.mjs
CHANGED
|
@@ -23,33 +23,13 @@
|
|
|
23
23
|
export function snakeToPascal(s) {
|
|
24
24
|
return s.replace(/_./g, match => match[1].toUpperCase());
|
|
25
25
|
}
|
|
26
|
+
|
|
26
27
|
/**
|
|
27
28
|
* Convert string from PascalCase to snake_case
|
|
28
29
|
* @param s - String to convert
|
|
29
30
|
* @returns Converted string
|
|
30
31
|
*/
|
|
31
|
-
|
|
32
32
|
export function pascalToSnake(s) {
|
|
33
33
|
return s.replace(/[A-Z]/g, match => `_${match.toLowerCase()}`);
|
|
34
34
|
}
|
|
35
|
-
/**
|
|
36
|
-
* Check whether a string is valid hex.
|
|
37
|
-
* @param str - String to validate.
|
|
38
|
-
* @returns True if the string is valid hex, false otherwise.
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
export function isHex(str) {
|
|
42
|
-
return str.length % 2 === 0 && /^[0-9a-f]+$/i.test(str);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Check whether a string is valid base-64.
|
|
46
|
-
* @param str - String to validate.
|
|
47
|
-
* @returns True if the string is valid base-64, false otherwise.
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
export function isBase64(str) {
|
|
51
|
-
if (str.length % 4 > 0 || /[^0-9a-z+/=]/i.test(str)) return false;
|
|
52
|
-
const index = str.indexOf('=');
|
|
53
|
-
return index === -1 || /={1,2}/.test(str.slice(index));
|
|
54
|
-
}
|
|
55
35
|
//# sourceMappingURL=string.mjs.map
|