@aeternity/aepp-sdk 10.0.0 → 12.0.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 +15 -14
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +13 -40
- 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 +1 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +37 -0
- package/es/AeSdk.mjs +81 -0
- package/es/AeSdk.mjs.map +1 -0
- package/es/AeSdkAepp.d.ts +69 -0
- package/es/AeSdkAepp.mjs +175 -0
- package/es/AeSdkAepp.mjs.map +1 -0
- package/es/AeSdkBase.d.ts +212 -0
- package/es/AeSdkBase.mjs +310 -0
- package/es/AeSdkBase.mjs.map +1 -0
- package/es/AeSdkWallet.d.ts +103 -0
- package/es/AeSdkWallet.mjs +322 -0
- package/es/AeSdkWallet.mjs.map +1 -0
- package/es/Node.d.ts +44 -0
- package/es/Node.mjs +141 -0
- package/es/Node.mjs.map +1 -0
- package/es/account/Base.d.ts +65 -0
- package/es/account/Base.mjs +123 -0
- package/es/account/Base.mjs.map +1 -0
- package/es/account/Memory.d.ts +25 -0
- package/es/account/Memory.mjs +81 -0
- package/es/account/Memory.mjs.map +1 -0
- package/es/account/Rpc.d.ts +27 -0
- package/es/account/Rpc.mjs +79 -0
- package/es/account/Rpc.mjs.map +1 -0
- package/es/aens.d.ts +209 -0
- package/es/aens.mjs +332 -0
- package/es/aens.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/Browser.d.ts +32 -0
- package/es/aepp-wallet-communication/connection/Browser.mjs +70 -0
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +17 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +57 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +35 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +142 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection-proxy.d.ts +10 -0
- package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +15 -11
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +33 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +169 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -0
- package/es/aepp-wallet-communication/rpc/types.d.ts +77 -0
- package/es/aepp-wallet-communication/rpc/types.mjs +3 -0
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -0
- package/es/aepp-wallet-communication/schema.d.ts +118 -0
- package/es/aepp-wallet-communication/schema.mjs +214 -0
- package/es/aepp-wallet-communication/schema.mjs.map +1 -0
- package/es/aepp-wallet-communication/wallet-detector.d.ts +24 -0
- package/es/aepp-wallet-communication/wallet-detector.mjs +63 -0
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/apis/compiler/compiler.d.ts +92 -0
- package/es/apis/compiler/compiler.mjs +576 -0
- package/es/apis/compiler/compiler.mjs.map +1 -0
- package/es/apis/compiler/index.d.ts +2 -0
- package/es/apis/compiler/index.mjs +3 -0
- package/es/apis/compiler/index.mjs.map +1 -0
- package/es/apis/compiler/models/index.d.ts +248 -0
- package/es/apis/compiler/models/index.mjs +48 -0
- package/es/apis/compiler/models/index.mjs.map +1 -0
- package/es/apis/compiler/models/mappers.d.ts +23 -0
- package/es/apis/compiler/models/mappers.mjs +585 -0
- package/es/apis/compiler/models/mappers.mjs.map +1 -0
- package/es/apis/compiler/models/parameters.d.ts +13 -0
- package/es/apis/compiler/models/parameters.mjs +71 -0
- package/es/apis/compiler/models/parameters.mjs.map +1 -0
- package/es/apis/node/index.d.ts +2 -0
- package/es/apis/node/index.mjs +3 -0
- package/es/apis/node/index.mjs.map +1 -0
- package/es/apis/node/models/index.d.ts +1061 -0
- package/es/apis/node/models/index.mjs +2 -0
- package/es/apis/node/models/index.mjs.map +1 -0
- package/es/apis/node/models/mappers.d.ts +95 -0
- package/es/apis/node/models/mappers.mjs +4164 -0
- package/es/apis/node/models/mappers.mjs.map +1 -0
- package/es/apis/node/models/parameters.d.ts +17 -0
- package/es/apis/node/models/parameters.mjs +165 -0
- package/es/apis/node/models/parameters.mjs.map +1 -0
- package/es/apis/node/node.d.ts +215 -0
- package/es/apis/node/node.mjs +1165 -0
- package/es/apis/node/node.mjs.map +1 -0
- package/es/chain.d.ts +220 -0
- package/es/chain.mjs +524 -0
- package/es/chain.mjs.map +1 -0
- package/es/channel/handlers.d.ts +34 -0
- package/es/channel/{handlers.js → handlers.mjs} +163 -130
- package/es/channel/handlers.mjs.map +1 -0
- package/es/channel/index.d.ts +634 -0
- package/es/channel/index.mjs +978 -0
- package/es/channel/index.mjs.map +1 -0
- package/es/channel/internal.d.ts +100 -0
- package/es/channel/internal.mjs +328 -0
- package/es/channel/internal.mjs.map +1 -0
- package/es/contract/Compiler.d.ts +17 -0
- package/es/contract/Compiler.mjs +67 -0
- package/es/contract/Compiler.mjs.map +1 -0
- package/es/contract/aci.d.ts +125 -0
- package/es/contract/aci.mjs +496 -0
- package/es/contract/aci.mjs.map +1 -0
- package/es/contract/ga.d.ts +68 -0
- package/es/contract/ga.mjs +190 -0
- package/es/contract/ga.mjs.map +1 -0
- package/es/contract/methods.d.ts +68 -0
- package/es/contract/methods.mjs +101 -0
- package/es/contract/methods.mjs.map +1 -0
- package/es/index.d.ts +32 -0
- package/es/index.mjs +49 -0
- package/es/index.mjs.map +1 -0
- package/es/oracle.d.ts +154 -0
- package/es/oracle.mjs +288 -0
- package/es/oracle.mjs.map +1 -0
- package/es/spend.d.ts +61 -0
- package/es/spend.mjs +122 -0
- package/es/spend.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +41 -0
- package/es/tx/builder/constants.mjs +100 -0
- package/es/tx/builder/constants.mjs.map +1 -0
- package/es/tx/builder/field-types.d.ts +62 -0
- package/es/tx/builder/field-types.mjs +126 -0
- package/es/tx/builder/field-types.mjs.map +1 -0
- package/es/tx/builder/helpers.d.ts +131 -0
- package/es/tx/builder/helpers.mjs +223 -0
- package/es/tx/builder/helpers.mjs.map +1 -0
- package/es/tx/builder/index.d.ts +75 -0
- package/es/tx/builder/index.mjs +424 -0
- package/es/tx/builder/index.mjs.map +1 -0
- package/es/tx/builder/schema.d.ts +350 -0
- package/es/tx/builder/schema.mjs +320 -0
- package/es/tx/builder/schema.mjs.map +1 -0
- package/es/tx/index.d.ts +63 -0
- package/es/tx/index.mjs +209 -0
- package/es/tx/index.mjs.map +1 -0
- package/es/tx/min-fee.d.ts +20 -0
- package/es/tx/min-fee.mjs +148 -0
- package/es/tx/min-fee.mjs.map +1 -0
- package/es/tx/validator.d.ts +19 -0
- package/es/tx/validator.mjs +240 -0
- package/es/tx/validator.mjs.map +1 -0
- package/es/typings/@aeternity__argon2-browser/index.d.mjs +2 -0
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -0
- package/es/typings/@aeternity__uuid/index.d.mjs +2 -0
- package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -0
- package/es/typings/bip32-path/index.d.mjs +2 -0
- package/es/typings/bip32-path/index.d.mjs.map +1 -0
- package/es/typings/blakejs/index.d.mjs +2 -0
- package/es/typings/blakejs/index.d.mjs.map +1 -0
- package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
- package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
- package/es/utils/amount-formatter.d.ts +42 -0
- package/es/utils/{amount-formatter.js → amount-formatter.mjs} +38 -44
- package/es/utils/amount-formatter.mjs.map +1 -0
- package/es/utils/autorest.d.ts +6 -0
- package/es/utils/autorest.mjs +97 -0
- package/es/utils/autorest.mjs.map +1 -0
- package/es/utils/bignumber.d.ts +13 -0
- package/es/utils/bignumber.mjs +23 -0
- package/es/utils/bignumber.mjs.map +1 -0
- package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
- package/es/utils/{bytes.js → bytes.mjs} +26 -22
- package/es/utils/bytes.mjs.map +1 -0
- package/es/utils/crypto.d.ts +103 -0
- package/es/utils/crypto.mjs +221 -0
- package/es/utils/crypto.mjs.map +1 -0
- package/es/utils/encoder.d.ts +26 -0
- package/es/utils/encoder.mjs +102 -0
- package/es/utils/encoder.mjs.map +1 -0
- package/es/utils/errors.d.ts +481 -0
- package/es/utils/errors.mjs +882 -0
- package/es/utils/errors.mjs.map +1 -0
- package/es/utils/hd-wallet.d.ts +34 -0
- package/es/utils/hd-wallet.mjs +122 -0
- package/es/utils/hd-wallet.mjs.map +1 -0
- package/es/utils/json-big.d.ts +5 -0
- package/es/utils/json-big.mjs +41 -0
- package/es/utils/json-big.mjs.map +1 -0
- package/es/utils/keystore.d.ts +51 -0
- package/es/utils/keystore.mjs +145 -0
- package/es/utils/keystore.mjs.map +1 -0
- package/es/{mptree.d.ts → utils/mptree.d.ts} +5 -8
- package/es/utils/{mptree.js → mptree.mjs} +33 -25
- package/es/utils/mptree.mjs.map +1 -0
- package/es/utils/other.d.ts +14 -0
- package/es/utils/other.mjs +28 -0
- package/es/utils/other.mjs.map +1 -0
- package/es/{semver-satisfies.d.ts → utils/semver-satisfies.d.ts} +0 -0
- package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
- package/es/utils/semver-satisfies.mjs.map +1 -0
- package/es/utils/string.d.ts +24 -0
- package/es/utils/{string.js → string.mjs} +9 -11
- package/es/utils/string.mjs.map +1 -0
- package/package.json +67 -64
- package/src/AeSdk.ts +65 -0
- package/src/AeSdkAepp.ts +167 -0
- package/src/AeSdkBase.ts +320 -0
- package/src/AeSdkWallet.ts +332 -0
- package/src/Node.ts +167 -0
- package/src/account/Base.ts +114 -0
- package/src/account/Memory.ts +83 -0
- package/src/account/Rpc.ts +67 -0
- package/src/aens.ts +391 -0
- package/src/aepp-wallet-communication/connection/Browser.ts +68 -0
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +58 -0
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +111 -0
- package/{es/utils/crypto-ts.js → src/aepp-wallet-communication/connection-proxy.ts} +16 -9
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +137 -0
- package/src/aepp-wallet-communication/rpc/types.ts +66 -0
- package/src/aepp-wallet-communication/schema.ts +181 -0
- package/src/aepp-wallet-communication/wallet-detector.ts +71 -0
- package/src/apis/compiler/code-model-v4.yaml +2649 -0
- package/src/apis/compiler/compiler.ts +585 -0
- package/src/apis/compiler/index.ts +2 -0
- package/src/apis/compiler/models/index.ts +301 -0
- package/src/apis/compiler/models/mappers.ts +583 -0
- package/src/apis/compiler/models/parameters.ts +93 -0
- package/src/apis/node/code-model-v4.yaml +10046 -0
- package/src/apis/node/index.ts +2 -0
- package/src/apis/node/models/index.ts +1253 -0
- package/src/apis/node/models/mappers.ts +4278 -0
- package/src/apis/node/models/parameters.ts +188 -0
- package/src/apis/node/node.ts +1299 -0
- package/src/chain.ts +444 -0
- package/src/channel/{handlers.js → handlers.ts} +238 -143
- package/src/channel/index.ts +991 -0
- package/src/channel/internal.ts +345 -0
- package/src/contract/Compiler.ts +66 -0
- package/src/contract/aci.ts +529 -0
- package/src/contract/ga.ts +178 -0
- package/src/contract/methods.ts +118 -0
- package/src/index.ts +51 -0
- package/src/oracle.ts +342 -0
- package/src/spend.ts +152 -0
- package/src/tx/builder/constants.ts +96 -0
- package/src/tx/builder/field-types.ts +111 -0
- package/src/tx/builder/helpers.ts +253 -0
- package/src/tx/builder/index.ts +394 -0
- package/src/tx/builder/schema.ts +771 -0
- package/src/tx/index.ts +199 -0
- package/src/tx/min-fee.ts +136 -0
- package/src/tx/validator.ts +226 -0
- package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
- package/src/typings/@aeternity__uuid/index.d.ts +3 -0
- package/src/typings/bip32-path/index.d.ts +33 -0
- package/src/typings/tweetnacl-auth/index.d.ts +14 -0
- package/src/utils/amount-formatter.ts +29 -41
- package/src/utils/autorest.ts +90 -0
- package/src/utils/bignumber.ts +9 -19
- package/src/utils/bytes.ts +15 -16
- package/src/utils/crypto.ts +217 -0
- package/src/utils/encoder.ts +98 -0
- package/src/utils/errors.ts +817 -0
- package/src/utils/hd-wallet.ts +134 -0
- package/src/utils/json-big.ts +26 -0
- package/src/utils/keystore.ts +179 -0
- package/src/utils/mptree.ts +26 -20
- package/src/utils/other.ts +28 -43
- package/src/utils/string.ts +8 -10
- package/CHANGELOG.md +0 -1603
- package/es/account/base.js +0 -169
- package/es/account/base.js.map +0 -1
- package/es/account/memory.js +0 -84
- package/es/account/memory.js.map +0 -1
- package/es/account/multiple.js +0 -178
- package/es/account/multiple.js.map +0 -1
- package/es/ae/aens.js +0 -408
- package/es/ae/aens.js.map +0 -1
- package/es/ae/aepp.js +0 -45
- package/es/ae/aepp.js.map +0 -1
- package/es/ae/contract.js +0 -312
- package/es/ae/contract.js.map +0 -1
- package/es/ae/index.js +0 -206
- package/es/ae/index.js.map +0 -1
- package/es/ae/oracle.js +0 -322
- package/es/ae/oracle.js.map +0 -1
- package/es/ae/universal.js +0 -45
- package/es/ae/universal.js.map +0 -1
- package/es/ae/wallet.js +0 -50
- package/es/ae/wallet.js.map +0 -1
- package/es/amount-formatter.d.ts +0 -58
- package/es/bignumber.d.ts +0 -24
- package/es/chain/index.js +0 -256
- package/es/chain/index.js.map +0 -1
- package/es/chain/node.js +0 -394
- package/es/chain/node.js.map +0 -1
- package/es/channel/handlers.js.map +0 -1
- package/es/channel/index.js +0 -980
- package/es/channel/index.js.map +0 -1
- package/es/channel/internal.js +0 -266
- package/es/channel/internal.js.map +0 -1
- package/es/contract/aci/helpers.js +0 -298
- package/es/contract/aci/helpers.js.map +0 -1
- package/es/contract/aci/index.js +0 -361
- package/es/contract/aci/index.js.map +0 -1
- package/es/contract/aci/transformation.js +0 -66
- package/es/contract/aci/transformation.js.map +0 -1
- package/es/contract/compiler.js +0 -244
- package/es/contract/compiler.js.map +0 -1
- package/es/contract/ga/helpers.js +0 -22
- package/es/contract/ga/helpers.js.map +0 -1
- package/es/contract/ga/index.js +0 -170
- package/es/contract/ga/index.js.map +0 -1
- package/es/contract/index.js +0 -162
- package/es/contract/index.js.map +0 -1
- package/es/crypto-ts.d.ts +0 -9
- package/es/index.js +0 -57
- package/es/index.js.map +0 -1
- package/es/node-pool/index.js +0 -187
- package/es/node-pool/index.js.map +0 -1
- package/es/node.js +0 -132
- package/es/node.js.map +0 -1
- package/es/other.d.ts +0 -31
- package/es/string.d.ts +0 -26
- package/es/tx/builder/helpers.js +0 -305
- package/es/tx/builder/helpers.js.map +0 -1
- package/es/tx/builder/index.js +0 -595
- package/es/tx/builder/index.js.map +0 -1
- package/es/tx/builder/schema.js +0 -814
- package/es/tx/builder/schema.js.map +0 -1
- package/es/tx/index.js +0 -300
- package/es/tx/index.js.map +0 -1
- package/es/tx/tx-object.js +0 -276
- package/es/tx/tx-object.js.map +0 -1
- package/es/tx/tx.js +0 -937
- package/es/tx/tx.js.map +0 -1
- package/es/tx/validator.js +0 -208
- package/es/tx/validator.js.map +0 -1
- package/es/typings/blakejs/index.d.js +0 -2
- package/es/typings/blakejs/index.d.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -131
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -184
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/index.js +0 -84
- package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +0 -97
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
- package/es/utils/aepp-wallet-communication/helpers.js +0 -103
- package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -329
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -270
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -533
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.js +0 -107
- package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -109
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
- package/es/utils/amount-formatter.js.map +0 -1
- package/es/utils/async-init.js +0 -67
- package/es/utils/async-init.js.map +0 -1
- package/es/utils/bignumber.js +0 -28
- package/es/utils/bignumber.js.map +0 -1
- package/es/utils/bytes.js.map +0 -1
- package/es/utils/crypto-ts.js.map +0 -1
- package/es/utils/crypto.js +0 -304
- package/es/utils/crypto.js.map +0 -1
- package/es/utils/hd-wallet.js +0 -112
- package/es/utils/hd-wallet.js.map +0 -1
- package/es/utils/json-big.js +0 -45
- package/es/utils/json-big.js.map +0 -1
- package/es/utils/keystore.js +0 -228
- package/es/utils/keystore.js.map +0 -1
- package/es/utils/mptree.js.map +0 -1
- package/es/utils/other.js +0 -43
- package/es/utils/other.js.map +0 -1
- package/es/utils/semver-satisfies.js.map +0 -1
- package/es/utils/string.js.map +0 -1
- package/es/utils/swagger.js +0 -132
- package/es/utils/swagger.js.map +0 -1
- package/src/account/base.js +0 -153
- package/src/account/memory.js +0 -78
- package/src/account/multiple.js +0 -154
- package/src/ae/aens.js +0 -366
- package/src/ae/aepp.js +0 -45
- package/src/ae/contract.js +0 -285
- package/src/ae/index.js +0 -167
- package/src/ae/oracle.js +0 -296
- package/src/ae/universal.js +0 -47
- package/src/ae/wallet.js +0 -50
- package/src/chain/index.js +0 -250
- package/src/chain/node.js +0 -293
- package/src/channel/index.js +0 -898
- package/src/channel/internal.js +0 -231
- package/src/contract/aci/index.js +0 -317
- package/src/contract/aci/transformation.js +0 -72
- package/src/contract/compiler.js +0 -195
- package/src/contract/ga/helpers.js +0 -17
- package/src/contract/ga/index.js +0 -147
- package/src/contract/index.js +0 -163
- package/src/index.js +0 -90
- package/src/node-pool/index.js +0 -171
- package/src/node.js +0 -118
- package/src/tx/builder/helpers.js +0 -325
- package/src/tx/builder/index.js +0 -460
- package/src/tx/builder/schema.js +0 -1211
- package/src/tx/index.js +0 -301
- package/src/tx/tx-object.js +0 -186
- package/src/tx/tx.js +0 -622
- package/src/tx/validator.js +0 -161
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -114
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -161
- package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -85
- package/src/utils/aepp-wallet-communication/helpers.js +0 -70
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -268
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -223
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -390
- package/src/utils/aepp-wallet-communication/schema.js +0 -108
- package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -91
- package/src/utils/async-init.js +0 -41
- package/src/utils/crypto.js +0 -312
- package/src/utils/hd-wallet.js +0 -115
- package/src/utils/json-big.js +0 -26
- package/src/utils/keystore.js +0 -223
- package/src/utils/swagger.js +0 -133
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import _buffer from "buffer";
|
|
2
|
+
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
3
|
+
const {
|
|
4
|
+
Buffer: _Buffer
|
|
5
|
+
} = _buffer;
|
|
6
|
+
|
|
1
7
|
/*
|
|
2
8
|
* ISC License (ISC)
|
|
3
9
|
* Copyright (c) 2021 aeternity developers
|
|
@@ -14,8 +20,12 @@
|
|
|
14
20
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
21
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
22
|
*/
|
|
17
|
-
import
|
|
18
|
-
|
|
23
|
+
import _rlp from 'rlp';
|
|
24
|
+
const {
|
|
25
|
+
encode: rlpEncode
|
|
26
|
+
} = _rlp;
|
|
27
|
+
import { hash } from "./crypto.mjs";
|
|
28
|
+
import { MerkleTreeHashMismatchError, MissingNodeInTreeError, UnknownPathNibbleError, UnknownNodeLengthError } from "./errors.mjs";
|
|
19
29
|
var NodeType;
|
|
20
30
|
|
|
21
31
|
(function (NodeType) {
|
|
@@ -26,23 +36,22 @@ var NodeType;
|
|
|
26
36
|
|
|
27
37
|
export default class MPTree {
|
|
28
38
|
static nodeHash(node) {
|
|
29
|
-
return
|
|
39
|
+
return _Buffer.from(hash(rlpEncode(node))).toString('hex');
|
|
30
40
|
}
|
|
31
41
|
/**
|
|
32
42
|
* Deserialize Merkle Patricia Tree
|
|
33
|
-
* @
|
|
34
|
-
* @
|
|
35
|
-
* @return {MPTree} Merkle Patricia Tree
|
|
43
|
+
* @param binary - Binary
|
|
44
|
+
* @returns Merkle Patricia Tree
|
|
36
45
|
*/
|
|
37
46
|
|
|
38
47
|
|
|
39
48
|
constructor(binary) {
|
|
40
49
|
this.rootHash = binary[0].toString('hex');
|
|
41
50
|
this.nodes = Object.fromEntries(binary[1].map(node => [node[0].toString('hex'), node[1]]));
|
|
42
|
-
if (this.nodes[this.rootHash] === undefined) throw new
|
|
51
|
+
if (this.nodes[this.rootHash] === undefined) throw new MissingNodeInTreeError('Can\'t find a node by root hash');
|
|
43
52
|
Object.entries(this.nodes).forEach(_ref => {
|
|
44
53
|
let [key, node] = _ref;
|
|
45
|
-
if (MPTree.nodeHash(node) !== key) throw new
|
|
54
|
+
if (MPTree.nodeHash(node) !== key) throw new MerkleTreeHashMismatchError();
|
|
46
55
|
const {
|
|
47
56
|
type,
|
|
48
57
|
payload
|
|
@@ -52,14 +61,14 @@ export default class MPTree {
|
|
|
52
61
|
case NodeType.Branch:
|
|
53
62
|
payload.slice(0, 16).filter(n => n.length).forEach(n => {
|
|
54
63
|
if (this.nodes[n.toString('hex')] === undefined) {
|
|
55
|
-
throw new
|
|
64
|
+
throw new MissingNodeInTreeError('Can\'t find a node by hash in branch node');
|
|
56
65
|
}
|
|
57
66
|
});
|
|
58
67
|
break;
|
|
59
68
|
|
|
60
69
|
case NodeType.Extension:
|
|
61
70
|
if (this.nodes[payload[0].toString('hex')] === undefined) {
|
|
62
|
-
throw new
|
|
71
|
+
throw new MissingNodeInTreeError('Can\'t find a node by hash in extension node');
|
|
63
72
|
}
|
|
64
73
|
|
|
65
74
|
}
|
|
@@ -81,40 +90,39 @@ export default class MPTree {
|
|
|
81
90
|
|
|
82
91
|
case 2:
|
|
83
92
|
{
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
93
|
+
var _context;
|
|
94
|
+
|
|
95
|
+
const nibble = node[0][0] >> 4;
|
|
96
|
+
if (nibble > 3) throw new UnknownPathNibbleError(nibble);
|
|
87
97
|
const type = nibble <= 1 ? NodeType.Extension : NodeType.Leaf;
|
|
88
|
-
const slice = [0, 2].
|
|
98
|
+
const slice = _includesInstanceProperty(_context = [0, 2]).call(_context, nibble) ? 2 : 1;
|
|
89
99
|
return {
|
|
90
100
|
type,
|
|
91
101
|
payload: [node[1]],
|
|
92
|
-
path:
|
|
102
|
+
path: node[0].toString('hex').slice(slice)
|
|
93
103
|
};
|
|
94
104
|
}
|
|
95
105
|
|
|
96
106
|
default:
|
|
97
|
-
throw new
|
|
107
|
+
throw new UnknownNodeLengthError(node.length);
|
|
98
108
|
}
|
|
99
109
|
}
|
|
100
110
|
/**
|
|
101
111
|
* Serialize Merkle Patricia Tree
|
|
102
|
-
* @
|
|
103
|
-
* @return {Array} Binary
|
|
112
|
+
* @returns Binary
|
|
104
113
|
*/
|
|
105
114
|
|
|
106
115
|
|
|
107
116
|
serialize() {
|
|
108
|
-
return [
|
|
117
|
+
return [_Buffer.from(this.rootHash, 'hex'), Object.entries(this.nodes).map(_ref2 => {
|
|
109
118
|
let [mptHash, value] = _ref2;
|
|
110
|
-
return [
|
|
119
|
+
return [_Buffer.from(mptHash, 'hex'), value];
|
|
111
120
|
})];
|
|
112
121
|
}
|
|
113
122
|
/**
|
|
114
123
|
* Retrieve value from Merkle Patricia Tree
|
|
115
|
-
* @
|
|
116
|
-
* @
|
|
117
|
-
* @return {Buffer} Value associated to the specified key
|
|
124
|
+
* @param key - The key of the element to retrieve
|
|
125
|
+
* @returns Value associated to the specified key
|
|
118
126
|
*/
|
|
119
127
|
|
|
120
128
|
|
|
@@ -131,7 +139,7 @@ export default class MPTree {
|
|
|
131
139
|
switch (type) {
|
|
132
140
|
case NodeType.Branch:
|
|
133
141
|
if (key.length === 0) return payload[16];
|
|
134
|
-
searchFrom = payload[
|
|
142
|
+
searchFrom = payload[+`0x${key[0]}`].toString('hex');
|
|
135
143
|
key = key.substr(1);
|
|
136
144
|
break;
|
|
137
145
|
|
|
@@ -149,4 +157,4 @@ export default class MPTree {
|
|
|
149
157
|
}
|
|
150
158
|
|
|
151
159
|
}
|
|
152
|
-
//# sourceMappingURL=mptree.
|
|
160
|
+
//# sourceMappingURL=mptree.mjs.map
|
|
@@ -0,0 +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","searchFrom","substr"],"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\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 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\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 while (true) {\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.substr(1)\n break\n case NodeType.Extension:\n if (key.substr(0, path?.length) !== path) return undefined\n searchFrom = payload[0].toString('hex')\n key = key.substr(path.length)\n break\n case NodeType.Leaf:\n if (path !== key) return undefined\n return payload[0]\n }\n }\n }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare const pause: (duration: number) => Promise<void>;
|
|
3
|
+
export declare const mapObject: <InputV, OutputV>(object: {
|
|
4
|
+
[k: string]: InputV;
|
|
5
|
+
}, fn: (value: [string, InputV], index: number, array: [string, InputV][]) => [string | number, OutputV]) => {
|
|
6
|
+
[k: string]: OutputV;
|
|
7
|
+
};
|
|
8
|
+
export declare const concatBuffers: (list: readonly Uint8Array[], totalLength?: number | undefined) => Buffer;
|
|
9
|
+
/**
|
|
10
|
+
* Object key type guard
|
|
11
|
+
* @param key - Object key
|
|
12
|
+
* @param object - object
|
|
13
|
+
*/
|
|
14
|
+
export declare function isKeyOfObject<T>(key: string | number | symbol, object: T): key is keyof T;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import _buffer from "buffer";
|
|
2
|
+
const {
|
|
3
|
+
Buffer: _Buffer
|
|
4
|
+
} = _buffer;
|
|
5
|
+
export const pause = async duration => await new Promise(resolve => setTimeout(resolve, duration));
|
|
6
|
+
export const mapObject = (object, fn) => Object.fromEntries(Object.entries(object).map(fn)); // remove after dropping webpack4 support
|
|
7
|
+
|
|
8
|
+
const isWebpack4Buffer = (() => {
|
|
9
|
+
try {
|
|
10
|
+
_Buffer.concat([Uint8Array.from([])]);
|
|
11
|
+
|
|
12
|
+
return false;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
})();
|
|
17
|
+
|
|
18
|
+
export const concatBuffers = isWebpack4Buffer ? (list, totalLength) => _Buffer.concat(list.map(el => _Buffer.from(el)), totalLength) : _Buffer.concat;
|
|
19
|
+
/**
|
|
20
|
+
* Object key type guard
|
|
21
|
+
* @param key - Object key
|
|
22
|
+
* @param object - object
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export function isKeyOfObject(key, object) {
|
|
26
|
+
return key in object;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=other.mjs.map
|
|
@@ -0,0 +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"],"sources":["../../src/utils/other.ts"],"sourcesContent":["export const pause = async (duration: number): Promise<void> =>\n await new Promise(resolve => setTimeout(resolve, duration))\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 : Buffer.concat\n\n/**\n * Object key type guard\n * @param key - Object key\n * @param object - object\n */\nexport function isKeyOfObject<T> (\n key: string | number | symbol,\n object: T\n): key is keyof T {\n return key in object\n}\n"],"mappings":";;;;AAAA,OAAO,MAAMA,KAAK,GAAG,MAAOC,QAAP,IACnB,MAAM,IAAIC,OAAJ,CAAYC,OAAO,IAAIC,UAAU,CAACD,OAAD,EAAUF,QAAV,CAAjC,CADD;AAGP,OAAO,MAAMI,SAAS,GAAG,CACvBC,MADuB,EAEvBC,EAFuB,KAKMC,MAAM,CAACC,WAAP,CAAmBD,MAAM,CAACE,OAAP,CAAeJ,MAAf,EAAuBK,GAAvB,CAA2BJ,EAA3B,CAAnB,CALxB,C,CAOP;;AACA,MAAMK,gBAAgB,GAAG,CAAC,MAAM;EAC9B,IAAI;IACF,QAAOC,MAAP,CAAc,CAACC,UAAU,CAACC,IAAX,CAAgB,EAAhB,CAAD,CAAd;;IACA,OAAO,KAAP;EACD,CAHD,CAGE,OAAOC,KAAP,EAAc;IACd,OAAO,IAAP;EACD;AACF,CAPwB,GAAzB;;AASA,OAAO,MAAMC,aAAa,GAAGL,gBAAgB,GACzC,CAACM,IAAD,EAA8BC,WAA9B,KACE,QAAON,MAAP,CAAcK,IAAI,CAACP,GAAL,CAASS,EAAE,IAAI,QAAOL,IAAP,CAAYK,EAAZ,CAAf,CAAd,EAA+CD,WAA/C,CAFuC,GAGzC,QAAON,MAHJ;AAKP;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASQ,aAAT,CACLC,GADK,EAELhB,MAFK,EAGW;EAChB,OAAOgB,GAAG,IAAIhB,MAAd;AACD"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semver-satisfies.mjs","names":["version","geVersion","ltVersion","getComponents","v","split","map","i","versionComponents","geComponents","ltComponents","base","Math","max","componentsToNumber","components","reverse","reduce","acc","n","idx","pow","vNumber","geNumber","ltNumber"],"sources":["../../src/utils/semver-satisfies.ts"],"sourcesContent":["export default function (version: string, geVersion: string, ltVersion: string): 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 * Math.pow(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,UAAUA,OAAV,EAA2BC,SAA3B,EAA8CC,SAA9C,EAA0E;EACvF,MAAMC,aAAa,GAAIC,CAAD,IAAyBA,CAAC,CAC7CC,KAD4C,CACtC,MADsC,EAC9B,CAD8B,EAC3BA,KAD2B,CACrB,GADqB,EAChBC,GADgB,CACZC,CAAC,IAAI,CAACA,CADM,CAA/C;;EAGA,MAAMC,iBAAiB,GAAGL,aAAa,CAACH,OAAD,CAAvC;EACA,MAAMS,YAAY,GAAGN,aAAa,CAACF,SAAD,CAAlC;EACA,MAAMS,YAAY,GAAGP,aAAa,CAACD,SAAD,CAAlC;EAEA,MAAMS,IAAI,GAAGC,IAAI,CAACC,GAAL,CAAS,GAAGL,iBAAZ,EAA+B,GAAGC,YAAlC,EAAgD,GAAGC,YAAnD,IAAmE,CAAhF;;EACA,MAAMI,kBAAkB,GAAIC,UAAD,IAAkCA,UAAU,CAACC,OAAX,GAC1DC,MAD0D,CACnD,CAACC,GAAD,EAAMC,CAAN,EAASC,GAAT,KAAiBF,GAAG,GAAGC,CAAC,GAAGP,IAAI,CAACS,GAAL,CAASV,IAAT,EAAeS,GAAf,CADwB,EACH,CADG,CAA7D;;EAGA,MAAME,OAAO,GAAGR,kBAAkB,CAACN,iBAAD,CAAlC;EACA,MAAMe,QAAQ,GAAGT,kBAAkB,CAACL,YAAD,CAAnC;EACA,MAAMe,QAAQ,GAAGV,kBAAkB,CAACJ,YAAD,CAAnC;EACA,OAAOY,OAAO,IAAIC,QAAX,IAAuBD,OAAO,GAAGE,QAAxC;AACD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert string from snake_case to PascalCase
|
|
3
|
+
* @param s - String to convert
|
|
4
|
+
* @returns Converted string
|
|
5
|
+
*/
|
|
6
|
+
export declare function snakeToPascal(s: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Convert string from PascalCase to snake_case
|
|
9
|
+
* @param s - String to convert
|
|
10
|
+
* @returns Converted string
|
|
11
|
+
*/
|
|
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;
|
|
@@ -17,18 +17,16 @@
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Convert string from snake_case to PascalCase
|
|
20
|
-
* @
|
|
21
|
-
* @
|
|
22
|
-
* @return {String} Converted string
|
|
20
|
+
* @param s - String to convert
|
|
21
|
+
* @returns Converted string
|
|
23
22
|
*/
|
|
24
23
|
export function snakeToPascal(s) {
|
|
25
24
|
return s.replace(/_./g, match => match[1].toUpperCase());
|
|
26
25
|
}
|
|
27
26
|
/**
|
|
28
27
|
* Convert string from PascalCase to snake_case
|
|
29
|
-
* @
|
|
30
|
-
* @
|
|
31
|
-
* @return {String} Converted string
|
|
28
|
+
* @param s - String to convert
|
|
29
|
+
* @returns Converted string
|
|
32
30
|
*/
|
|
33
31
|
|
|
34
32
|
export function pascalToSnake(s) {
|
|
@@ -36,8 +34,8 @@ export function pascalToSnake(s) {
|
|
|
36
34
|
}
|
|
37
35
|
/**
|
|
38
36
|
* Check whether a string is valid hex.
|
|
39
|
-
* @param
|
|
40
|
-
* @
|
|
37
|
+
* @param str - String to validate.
|
|
38
|
+
* @returns True if the string is valid hex, false otherwise.
|
|
41
39
|
*/
|
|
42
40
|
|
|
43
41
|
export function isHex(str) {
|
|
@@ -45,8 +43,8 @@ export function isHex(str) {
|
|
|
45
43
|
}
|
|
46
44
|
/**
|
|
47
45
|
* Check whether a string is valid base-64.
|
|
48
|
-
* @param
|
|
49
|
-
* @
|
|
46
|
+
* @param str - String to validate.
|
|
47
|
+
* @returns True if the string is valid base-64, false otherwise.
|
|
50
48
|
*/
|
|
51
49
|
|
|
52
50
|
export function isBase64(str) {
|
|
@@ -54,4 +52,4 @@ export function isBase64(str) {
|
|
|
54
52
|
const index = str.indexOf('=');
|
|
55
53
|
return index === -1 || /={1,2}/.test(str.slice(index));
|
|
56
54
|
}
|
|
57
|
-
//# sourceMappingURL=string.
|
|
55
|
+
//# sourceMappingURL=string.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.mjs","names":["snakeToPascal","s","replace","match","toUpperCase","pascalToSnake","toLowerCase","isHex","str","length","test","isBase64","index","indexOf","slice"],"sources":["../../src/utils/string.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Convert string from snake_case to PascalCase\n * @param s - String to convert\n * @returns Converted string\n */\nexport function snakeToPascal (s: string): string {\n return s.replace(/_./g, match => match[1].toUpperCase())\n}\n\n/**\n * Convert string from PascalCase to snake_case\n * @param s - String to convert\n * @returns Converted string\n */\nexport function pascalToSnake (s: string): string {\n return s.replace(/[A-Z]/g, match => `_${match.toLowerCase()}`)\n}\n\n/**\n * Check whether a string is valid hex.\n * @param str - String to validate.\n * @returns True if the string is valid hex, false otherwise.\n */\nexport function isHex (str: string): boolean {\n return str.length % 2 === 0 && /^[0-9a-f]+$/i.test(str)\n}\n\n/**\n * Check whether a string is valid base-64.\n * @param str - String to validate.\n * @returns True if the string is valid base-64, false otherwise.\n */\nexport function isBase64 (str: string): boolean {\n if (str.length % 4 > 0 || /[^0-9a-z+/=]/i.test(str)) return false\n const index = str.indexOf('=')\n return index === -1 || /={1,2}/.test(str.slice(index))\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,aAAT,CAAwBC,CAAxB,EAA2C;EAChD,OAAOA,CAAC,CAACC,OAAF,CAAU,KAAV,EAAiBC,KAAK,IAAIA,KAAK,CAAC,CAAD,CAAL,CAASC,WAAT,EAA1B,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,aAAT,CAAwBJ,CAAxB,EAA2C;EAChD,OAAOA,CAAC,CAACC,OAAF,CAAU,QAAV,EAAoBC,KAAK,IAAK,IAAGA,KAAK,CAACG,WAAN,EAAoB,EAArD,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,KAAT,CAAgBC,GAAhB,EAAsC;EAC3C,OAAOA,GAAG,CAACC,MAAJ,GAAa,CAAb,KAAmB,CAAnB,IAAwB,eAAeC,IAAf,CAAoBF,GAApB,CAA/B;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASG,QAAT,CAAmBH,GAAnB,EAAyC;EAC9C,IAAIA,GAAG,CAACC,MAAJ,GAAa,CAAb,GAAiB,CAAjB,IAAsB,gBAAgBC,IAAhB,CAAqBF,GAArB,CAA1B,EAAqD,OAAO,KAAP;EACrD,MAAMI,KAAK,GAAGJ,GAAG,CAACK,OAAJ,CAAY,GAAZ,CAAd;EACA,OAAOD,KAAK,KAAK,CAAC,CAAX,IAAgB,SAASF,IAAT,CAAcF,GAAG,CAACM,KAAJ,CAAUF,KAAV,CAAd,CAAvB;AACD"}
|
package/package.json
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeternity/aepp-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "SDK for the æternity blockchain",
|
|
5
5
|
"main": "dist/aepp-sdk.js",
|
|
6
6
|
"types": "es/index.d.ts",
|
|
7
|
-
"module": "es/index.
|
|
7
|
+
"module": "es/index.mjs",
|
|
8
8
|
"browser": {
|
|
9
9
|
"dist/aepp-sdk.js": "./dist/aepp-sdk.browser.js"
|
|
10
10
|
},
|
|
11
11
|
"sideEffects": false,
|
|
12
12
|
"scripts": {
|
|
13
|
-
"build:es": "tsc && babel src --config-file ./babel.esm.config.js --out-dir es --extensions
|
|
14
|
-
"build": "
|
|
13
|
+
"build:es": "tsc && babel src --config-file ./babel.esm.config.js --out-dir es --extensions .js,.ts --out-file-extension .mjs --source-maps true",
|
|
14
|
+
"build:api": "npx autorest tooling/autorest/compiler.yaml --output-artifact:code-model-v4 && npx autorest tooling/autorest/node.yaml --output-artifact:code-model-v4",
|
|
15
|
+
"build": "npm run build:api && webpack --mode=production && npm run build:es",
|
|
15
16
|
"build:dev": "webpack --mode=development && npm run build:es",
|
|
16
17
|
"docs:examples": "node tooling/docs/examples-to-md.js examples/node/*.js",
|
|
17
|
-
"docs:api": "
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"test": "nyc
|
|
21
|
-
"
|
|
22
|
-
"test:
|
|
23
|
-
"test:unit": "nyc --require @babel/register --require ts-node/register mocha './test/unit/*'",
|
|
24
|
-
"test:watch": "mocha --recursive --require @babel/register --require ts-node/register --watch --timeout 40s",
|
|
18
|
+
"docs:api": "typedoc",
|
|
19
|
+
"lint": "eslint . --ext .ts,.js",
|
|
20
|
+
"test": "nyc mocha './test/unit/' './test/integration/'",
|
|
21
|
+
"test:integration": "nyc mocha './test/integration/'",
|
|
22
|
+
"test:unit": "nyc mocha './test/unit/'",
|
|
23
|
+
"test:watch": "mocha './test/unit/' './test/integration/' --watch",
|
|
25
24
|
"prepare": "npm run build",
|
|
26
|
-
"prepublishOnly": "npm run docs:examples && npm run docs:
|
|
27
|
-
"release": "standard-version --skip.tag"
|
|
25
|
+
"prepublishOnly": "test/examples.sh && npm run docs:examples && npm run docs:api",
|
|
26
|
+
"release": "standard-version --skip.tag --infile docs/CHANGELOG.md"
|
|
28
27
|
},
|
|
29
28
|
"license": "ISC",
|
|
30
29
|
"keywords": [
|
|
@@ -34,32 +33,26 @@
|
|
|
34
33
|
"SDK"
|
|
35
34
|
],
|
|
36
35
|
"dependencies": {
|
|
37
|
-
"@aeternity/aepp-calldata": "^1.
|
|
38
|
-
"@aeternity/
|
|
39
|
-
"@aeternity/
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
36
|
+
"@aeternity/aepp-calldata": "^1.1.1",
|
|
37
|
+
"@aeternity/argon2-browser": "^0.1.2",
|
|
38
|
+
"@aeternity/uuid": "^0.0.1",
|
|
39
|
+
"@azure/core-client": "^1.6.0",
|
|
40
|
+
"@azure/core-rest-pipeline": "^1.9.0",
|
|
41
|
+
"@babel/runtime-corejs3": "^7.18.3",
|
|
43
42
|
"aes-js": "^3.1.2",
|
|
44
|
-
"bignumber.js": "^9.0.
|
|
43
|
+
"bignumber.js": "^9.0.2",
|
|
45
44
|
"bip32-path": "^0.4.2",
|
|
46
|
-
"blakejs": "^1.
|
|
47
|
-
"
|
|
45
|
+
"blakejs": "^1.2.1",
|
|
46
|
+
"bs58": "^5.0.0",
|
|
48
47
|
"buffer": "^6.0.3",
|
|
49
|
-
"cross-fetch": "^3.1.4",
|
|
50
|
-
"crypto-browserify": "^3.12.0",
|
|
51
48
|
"events": "^3.3.0",
|
|
52
|
-
"
|
|
53
|
-
"path-browserify": "^1.0.1",
|
|
49
|
+
"json-bigint": "^1.0.0",
|
|
54
50
|
"process": "^0.11.10",
|
|
55
|
-
"
|
|
56
|
-
"rlp": "^2.2.7",
|
|
51
|
+
"rlp": "^3.0.0",
|
|
57
52
|
"sha.js": "^2.4.11",
|
|
58
|
-
"stream-browserify": "^3.0.0",
|
|
59
|
-
"swagger-client": "^3.17.0",
|
|
60
53
|
"tweetnacl": "^1.0.3",
|
|
61
54
|
"tweetnacl-auth": "^1.0.1",
|
|
62
|
-
"
|
|
55
|
+
"varuint-bitcoin": "^1.1.2",
|
|
63
56
|
"websocket": "^1.0.34"
|
|
64
57
|
},
|
|
65
58
|
"repository": {
|
|
@@ -67,42 +60,52 @@
|
|
|
67
60
|
"url": "https://github.com/aeternity/aepp-sdk-js"
|
|
68
61
|
},
|
|
69
62
|
"devDependencies": {
|
|
70
|
-
"@babel/cli": "^7.
|
|
71
|
-
"@babel/core": "^7.
|
|
72
|
-
"@babel/node": "^7.
|
|
73
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
74
|
-
"@babel/preset-env": "^7.
|
|
75
|
-
"@babel/preset-typescript": "^7.
|
|
76
|
-
"@babel/register": "^7.
|
|
77
|
-
"@commitlint/cli": "^
|
|
78
|
-
"@commitlint/config-conventional": "^
|
|
63
|
+
"@babel/cli": "^7.17.10",
|
|
64
|
+
"@babel/core": "^7.18.2",
|
|
65
|
+
"@babel/node": "^7.17.10",
|
|
66
|
+
"@babel/plugin-transform-runtime": "^7.18.2",
|
|
67
|
+
"@babel/preset-env": "^7.18.2",
|
|
68
|
+
"@babel/preset-typescript": "^7.17.12",
|
|
69
|
+
"@babel/register": "^7.17.7",
|
|
70
|
+
"@commitlint/cli": "^17.0.2",
|
|
71
|
+
"@commitlint/config-conventional": "^17.0.2",
|
|
72
|
+
"@types/aes-js": "^3.1.1",
|
|
73
|
+
"@types/argon2-browser": "^1.18.1",
|
|
79
74
|
"@types/bn.js": "^5.1.0",
|
|
80
|
-
"@types/chai": "^4.
|
|
81
|
-
"@types/
|
|
82
|
-
"@types/
|
|
83
|
-
"@
|
|
84
|
-
"@
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
75
|
+
"@types/chai": "^4.3.1",
|
|
76
|
+
"@types/chai-as-promised": "^7.1.5",
|
|
77
|
+
"@types/json-bigint": "^1.0.1",
|
|
78
|
+
"@types/mocha": "^9.1.1",
|
|
79
|
+
"@types/node": "^17.0.42",
|
|
80
|
+
"@types/sha.js": "^2.4.0",
|
|
81
|
+
"@types/sinon": "^10.0.11",
|
|
82
|
+
"@types/uuid": "^8.3.4",
|
|
83
|
+
"@types/webextension-polyfill": "^0.9.0",
|
|
84
|
+
"@types/websocket": "^1.0.5",
|
|
85
|
+
"@typescript-eslint/eslint-plugin": "^5.27.1",
|
|
86
|
+
"@typescript-eslint/parser": "^5.27.1",
|
|
87
|
+
"babel-loader": "^8.2.5",
|
|
88
|
+
"babel-plugin-add-import-extension": "^1.6.0",
|
|
89
|
+
"babel-plugin-import-globals": "^2.0.0",
|
|
90
|
+
"babel-plugin-transform-default-named-imports": "^1.2.2",
|
|
91
|
+
"chai": "^4.3.6",
|
|
88
92
|
"chai-as-promised": "^7.1.1",
|
|
89
|
-
"
|
|
90
|
-
"eslint": "^
|
|
91
|
-
"eslint-
|
|
92
|
-
"eslint-plugin-
|
|
93
|
-
"
|
|
94
|
-
"eslint-plugin-promise": "^5.1.1",
|
|
95
|
-
"jsdoc-to-markdown": "^7.1.0",
|
|
96
|
-
"mocha": "^9.1.3",
|
|
93
|
+
"eslint": "^8.17.0",
|
|
94
|
+
"eslint-config-standard": "^17.0.0",
|
|
95
|
+
"eslint-plugin-rulesdir": "^0.2.1",
|
|
96
|
+
"eslint-plugin-tsdoc": "^0.2.16",
|
|
97
|
+
"mocha": "^10.0.0",
|
|
97
98
|
"nyc": "^15.1.0",
|
|
98
|
-
"sinon": "^
|
|
99
|
-
"source-map": "^0.7.
|
|
100
|
-
"standard-version": "^9.
|
|
101
|
-
"ts-node": "^10.
|
|
102
|
-
"
|
|
103
|
-
"
|
|
99
|
+
"sinon": "^14.0.0",
|
|
100
|
+
"source-map": "^0.7.4",
|
|
101
|
+
"standard-version": "^9.5.0",
|
|
102
|
+
"ts-node": "^10.8.1",
|
|
103
|
+
"typedoc": "^0.22.17",
|
|
104
|
+
"typedoc-plugin-missing-exports": "^0.22.6",
|
|
105
|
+
"typescript": "^4.7.3",
|
|
106
|
+
"webpack": "^5.73.0",
|
|
104
107
|
"webpack-bundle-analyzer": "^4.5.0",
|
|
105
|
-
"webpack-cli": "^4.9.
|
|
108
|
+
"webpack-cli": "^4.9.2"
|
|
106
109
|
},
|
|
107
110
|
"files": [
|
|
108
111
|
"dist",
|
package/src/AeSdk.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import AeSdkBase, { Account } from './AeSdkBase'
|
|
2
|
+
import AccountBase from './account/Base'
|
|
3
|
+
import { decode, EncodedData } from './utils/encoder'
|
|
4
|
+
import { UnavailableAccountError } from './utils/errors'
|
|
5
|
+
|
|
6
|
+
export default class AeSdk extends AeSdkBase {
|
|
7
|
+
accounts: { [key: EncodedData<'ak'>]: AccountBase } = {}
|
|
8
|
+
selectedAddress?: EncodedData<'ak'>
|
|
9
|
+
|
|
10
|
+
_resolveAccount (account: Account | EncodedData<'ak'> = this.selectedAddress): AccountBase {
|
|
11
|
+
if (typeof account === 'string') {
|
|
12
|
+
const address = account as EncodedData<'ak'>
|
|
13
|
+
decode(address)
|
|
14
|
+
if (this.accounts[address] == null) throw new UnavailableAccountError(account)
|
|
15
|
+
account = this.accounts[address]
|
|
16
|
+
}
|
|
17
|
+
return super._resolveAccount(account)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get accounts addresses
|
|
22
|
+
* @example addresses()
|
|
23
|
+
*/
|
|
24
|
+
addresses (): Array<EncodedData<'ak'>> {
|
|
25
|
+
return Object.keys(this.accounts) as Array<EncodedData<'ak'>>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Add specific account
|
|
30
|
+
* @param account - Account instance
|
|
31
|
+
* @param options - Options
|
|
32
|
+
* @param options.select - Select account
|
|
33
|
+
* @example addAccount(account)
|
|
34
|
+
*/
|
|
35
|
+
async addAccount (account: AccountBase, { select }: { select?: boolean } = {}): Promise<void> {
|
|
36
|
+
const address = await account.address()
|
|
37
|
+
this.accounts[address] = account
|
|
38
|
+
if (select === true) this.selectAccount(address)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Remove specific account
|
|
43
|
+
* @param address - Address of account to remove
|
|
44
|
+
* @example removeAccount(address)
|
|
45
|
+
*/
|
|
46
|
+
removeAccount (address: EncodedData<'ak'>): void {
|
|
47
|
+
if (this.accounts[address] == null) {
|
|
48
|
+
console.warn(`removeAccount: Account for ${address} not available`)
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
delete this.accounts[address] // eslint-disable-line @typescript-eslint/no-dynamic-delete
|
|
52
|
+
if (this.selectedAddress === address) delete this.selectedAddress
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Select specific account
|
|
57
|
+
* @param address - Address of account to select
|
|
58
|
+
* @example selectAccount('ak_xxxxxxxx')
|
|
59
|
+
*/
|
|
60
|
+
selectAccount (address: EncodedData<'ak'>): void {
|
|
61
|
+
decode(address)
|
|
62
|
+
if (this.accounts[address] == null) throw new UnavailableAccountError(address)
|
|
63
|
+
this.selectedAddress = address
|
|
64
|
+
}
|
|
65
|
+
}
|