@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
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { v4 as uuid } from '@aeternity/uuid'
|
|
2
|
+
import AeSdk from './AeSdk'
|
|
3
|
+
import { Account } from './AeSdkBase'
|
|
4
|
+
import verifyTransaction from './tx/validator'
|
|
5
|
+
import RpcClient from './aepp-wallet-communication/rpc/RpcClient'
|
|
6
|
+
import {
|
|
7
|
+
METHODS, RPC_STATUS, SUBSCRIPTION_TYPES, WALLET_TYPE,
|
|
8
|
+
RpcBroadcastError, RpcInvalidTransactionError,
|
|
9
|
+
RpcNotAuthorizeError, RpcPermissionDenyError, RpcUnsupportedProtocolError
|
|
10
|
+
} from './aepp-wallet-communication/schema'
|
|
11
|
+
import { UnknownRpcClientError } from './utils/errors'
|
|
12
|
+
import AccountBase from './account/Base'
|
|
13
|
+
import BrowserConnection from './aepp-wallet-communication/connection/Browser'
|
|
14
|
+
import {
|
|
15
|
+
Accounts,
|
|
16
|
+
AeppApi,
|
|
17
|
+
Network,
|
|
18
|
+
RPC_VERSION,
|
|
19
|
+
WalletApi,
|
|
20
|
+
WalletInfo
|
|
21
|
+
} from './aepp-wallet-communication/rpc/types'
|
|
22
|
+
import { EncodedData } from './utils/encoder'
|
|
23
|
+
import jsonBig from './utils/json-big'
|
|
24
|
+
|
|
25
|
+
type RpcClientWallet = RpcClient<AeppApi, WalletApi>
|
|
26
|
+
|
|
27
|
+
type OnConnection = (
|
|
28
|
+
clientId: string, params: Omit<Parameters<WalletApi[METHODS.connect]>[0], 'version'>, origin: string
|
|
29
|
+
) => void
|
|
30
|
+
|
|
31
|
+
type OnSubscription = (
|
|
32
|
+
clientId: string, params: Parameters<WalletApi[METHODS.subscribeAddress]>[0], origin: string
|
|
33
|
+
) => void
|
|
34
|
+
|
|
35
|
+
type OnSign = (
|
|
36
|
+
clientId: string, params: Parameters<WalletApi[METHODS.sign]>[0], origin: string
|
|
37
|
+
) => Promise<{ tx?: EncodedData<'tx'>, onAccount?: Account } | undefined> | Promise<void>
|
|
38
|
+
|
|
39
|
+
type OnDisconnect = (
|
|
40
|
+
clientId: string, params: Parameters<WalletApi[METHODS.closeConnection]>[0]
|
|
41
|
+
) => void
|
|
42
|
+
|
|
43
|
+
type OnAskAccounts = (
|
|
44
|
+
clientId: string, params: undefined, origin: string
|
|
45
|
+
) => void
|
|
46
|
+
|
|
47
|
+
type OnMessageSign = (
|
|
48
|
+
clientId: string, params: Parameters<WalletApi[METHODS.signMessage]>[0], origin: string
|
|
49
|
+
) => Promise<{ onAccount?: Account } | undefined> | Promise<void>
|
|
50
|
+
|
|
51
|
+
interface RpcClientsInfo {
|
|
52
|
+
id: string
|
|
53
|
+
status: RPC_STATUS
|
|
54
|
+
connectNode: boolean
|
|
55
|
+
addressSubscription: Set<'connected' | 'current'>
|
|
56
|
+
rpc: RpcClientWallet
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Contain functionality for aepp interaction and managing multiple aepps
|
|
61
|
+
*/
|
|
62
|
+
export default class AeSdkWallet extends AeSdk {
|
|
63
|
+
id: string
|
|
64
|
+
_type: WALLET_TYPE
|
|
65
|
+
name: string
|
|
66
|
+
_clients: Map<string, RpcClientsInfo>
|
|
67
|
+
onConnection: OnConnection
|
|
68
|
+
onSubscription: OnSubscription
|
|
69
|
+
onSign: OnSign
|
|
70
|
+
onDisconnect: OnDisconnect
|
|
71
|
+
onAskAccounts: OnAskAccounts
|
|
72
|
+
onMessageSign: OnMessageSign
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param options - Options
|
|
76
|
+
* @param options.name - Wallet name
|
|
77
|
+
* @param options.id - Wallet id
|
|
78
|
+
* @param options.type - Wallet type
|
|
79
|
+
* @param options.onConnection - Call-back function for incoming AEPP connection
|
|
80
|
+
* @param options.onSubscription - Call-back function for incoming AEPP account subscription
|
|
81
|
+
* @param options.onSign - Call-back function for incoming AEPP sign request
|
|
82
|
+
* @param options.onAskAccounts - Call-back function for incoming AEPP get address request
|
|
83
|
+
* @param options.onMessageSign - Call-back function for incoming AEPP sign message request
|
|
84
|
+
* @param options.onDisconnect - Call-back function for disconnect event
|
|
85
|
+
*/
|
|
86
|
+
constructor ({
|
|
87
|
+
name,
|
|
88
|
+
id,
|
|
89
|
+
type,
|
|
90
|
+
onConnection,
|
|
91
|
+
onSubscription,
|
|
92
|
+
onSign,
|
|
93
|
+
onDisconnect,
|
|
94
|
+
onAskAccounts,
|
|
95
|
+
onMessageSign,
|
|
96
|
+
...options
|
|
97
|
+
}: {
|
|
98
|
+
id: string
|
|
99
|
+
type: WALLET_TYPE
|
|
100
|
+
name: string
|
|
101
|
+
onConnection: OnConnection
|
|
102
|
+
onSubscription: OnSubscription
|
|
103
|
+
onSign: OnSign
|
|
104
|
+
onDisconnect: OnDisconnect
|
|
105
|
+
onAskAccounts: OnAskAccounts
|
|
106
|
+
onMessageSign: OnMessageSign
|
|
107
|
+
} & ConstructorParameters<typeof AeSdk>[0]) {
|
|
108
|
+
super(options)
|
|
109
|
+
this.onConnection = onConnection
|
|
110
|
+
this.onSubscription = onSubscription
|
|
111
|
+
this.onSign = onSign
|
|
112
|
+
this.onDisconnect = onDisconnect
|
|
113
|
+
this.onAskAccounts = onAskAccounts
|
|
114
|
+
this.onMessageSign = onMessageSign
|
|
115
|
+
this._clients = new Map()
|
|
116
|
+
this.name = name
|
|
117
|
+
this.id = id
|
|
118
|
+
this._type = type
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
_pushAccountsToApps (): void {
|
|
122
|
+
Array.from(this._clients.keys())
|
|
123
|
+
.filter(clientId => this._isRpcClientSubscribed(clientId))
|
|
124
|
+
.map(clientId => this._getClient(clientId).rpc)
|
|
125
|
+
.forEach(client => client.notify(METHODS.updateAddress, this.getAccounts()))
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
selectAccount (address: EncodedData<'ak'>): void {
|
|
129
|
+
super.selectAccount(address)
|
|
130
|
+
this._pushAccountsToApps()
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async addAccount (
|
|
134
|
+
account: AccountBase,
|
|
135
|
+
options?: Parameters<AeSdk['addAccount']>[1]
|
|
136
|
+
): Promise<void> {
|
|
137
|
+
await super.addAccount(account, options)
|
|
138
|
+
this._pushAccountsToApps()
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
_getNode (): { node: Network['node'] } {
|
|
142
|
+
this.ensureNodeConnected()
|
|
143
|
+
return { node: { url: this.api.url, name: this.selectedNodeName } }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async selectNode (name: string): Promise<void> {
|
|
147
|
+
super.selectNode(name)
|
|
148
|
+
const networkId = await this.getNetworkId()
|
|
149
|
+
Array.from(this._clients.keys())
|
|
150
|
+
.filter(clientId => this._isRpcClientConnected(clientId))
|
|
151
|
+
.map(clientId => this._getClient(clientId))
|
|
152
|
+
.forEach(client => {
|
|
153
|
+
client.rpc.notify(METHODS.updateNetwork, {
|
|
154
|
+
networkId,
|
|
155
|
+
...client.connectNode && this._getNode()
|
|
156
|
+
})
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
_getClient (clientId: string): RpcClientsInfo {
|
|
161
|
+
const client = this._clients.get(clientId)
|
|
162
|
+
if (client == null) throw new UnknownRpcClientError(clientId)
|
|
163
|
+
return client
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
_isRpcClientSubscribed (clientId: string): boolean {
|
|
167
|
+
return this._isRpcClientConnected(clientId) &&
|
|
168
|
+
this._getClient(clientId).addressSubscription.size !== 0
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
_isRpcClientConnected (clientId: string): boolean {
|
|
172
|
+
return RPC_STATUS.CONNECTED === this._getClient(clientId).status &&
|
|
173
|
+
this._getClient(clientId).rpc.connection.isConnected()
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
_disconnectRpcClient (clientId: string): void {
|
|
177
|
+
const client = this._getClient(clientId)
|
|
178
|
+
client.rpc.connection.disconnect()
|
|
179
|
+
client.status = RPC_STATUS.DISCONNECTED
|
|
180
|
+
client.addressSubscription = new Set()
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Remove specific RpcClient by ID
|
|
185
|
+
* @param id - Client ID
|
|
186
|
+
*/
|
|
187
|
+
removeRpcClient (id: string): void {
|
|
188
|
+
this._disconnectRpcClient(id)
|
|
189
|
+
this._clients.delete(id)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Add new client by AEPP connection
|
|
194
|
+
* @param clientConnection - AEPP connection object
|
|
195
|
+
* @returns Client ID
|
|
196
|
+
*/
|
|
197
|
+
addRpcClient (clientConnection: BrowserConnection): string {
|
|
198
|
+
// @TODO detect if aepp has some history based on origin????
|
|
199
|
+
// if yes use this instance for connection
|
|
200
|
+
const id = uuid()
|
|
201
|
+
let disconnectParams: any
|
|
202
|
+
const client: RpcClientsInfo = {
|
|
203
|
+
id,
|
|
204
|
+
status: RPC_STATUS.WAITING_FOR_CONNECTION_REQUEST,
|
|
205
|
+
addressSubscription: new Set(),
|
|
206
|
+
connectNode: false,
|
|
207
|
+
rpc: new RpcClient<AeppApi, WalletApi>(
|
|
208
|
+
clientConnection,
|
|
209
|
+
() => {
|
|
210
|
+
this._clients.delete(id)
|
|
211
|
+
this.onDisconnect(id, disconnectParams) // also related info
|
|
212
|
+
}, {
|
|
213
|
+
[METHODS.closeConnection]: (params) => {
|
|
214
|
+
disconnectParams = params
|
|
215
|
+
this._disconnectRpcClient(id)
|
|
216
|
+
},
|
|
217
|
+
// Store client info and prepare two fn for each client `connect` and `denyConnection`
|
|
218
|
+
// which automatically prepare and send response for that client
|
|
219
|
+
[METHODS.connect]: async ({ name, version, icons, connectNode }, origin) => {
|
|
220
|
+
if (version !== RPC_VERSION) throw new RpcUnsupportedProtocolError()
|
|
221
|
+
|
|
222
|
+
await this.onConnection(id, { name, icons, connectNode }, origin)
|
|
223
|
+
client.status = RPC_STATUS.CONNECTED
|
|
224
|
+
client.connectNode = connectNode
|
|
225
|
+
return {
|
|
226
|
+
...await this.getWalletInfo(),
|
|
227
|
+
...connectNode && this._getNode()
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
[METHODS.subscribeAddress]: async ({ type, value }, origin) => {
|
|
231
|
+
if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError()
|
|
232
|
+
|
|
233
|
+
await this.onSubscription(id, { type, value }, origin)
|
|
234
|
+
|
|
235
|
+
switch (type) {
|
|
236
|
+
case SUBSCRIPTION_TYPES.subscribe:
|
|
237
|
+
client.addressSubscription.add(value)
|
|
238
|
+
break
|
|
239
|
+
case SUBSCRIPTION_TYPES.unsubscribe:
|
|
240
|
+
client.addressSubscription.delete(value)
|
|
241
|
+
break
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
subscription: Array.from(client.addressSubscription),
|
|
246
|
+
address: this.getAccounts()
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
[METHODS.address]: async (params, origin) => {
|
|
250
|
+
if (!this._isRpcClientSubscribed(id)) throw new RpcNotAuthorizeError()
|
|
251
|
+
await this.onAskAccounts(id, params, origin)
|
|
252
|
+
return this.addresses()
|
|
253
|
+
},
|
|
254
|
+
[METHODS.sign]: async ({ tx, onAccount, returnSigned }, origin) => {
|
|
255
|
+
if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError()
|
|
256
|
+
onAccount ??= await this.address()
|
|
257
|
+
if (!this.addresses().includes(onAccount)) {
|
|
258
|
+
throw new RpcPermissionDenyError(onAccount)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const overrides = await this.onSign(id, { tx, returnSigned, onAccount }, origin)
|
|
262
|
+
onAccount = overrides?.onAccount ?? onAccount
|
|
263
|
+
tx = overrides?.tx ?? tx
|
|
264
|
+
if (returnSigned) {
|
|
265
|
+
return { signedTransaction: await this.signTransaction(tx, { onAccount }) }
|
|
266
|
+
}
|
|
267
|
+
try {
|
|
268
|
+
return jsonBig.parse(jsonBig.stringify({
|
|
269
|
+
transactionHash: await this.send(tx, { onAccount, verify: false })
|
|
270
|
+
}))
|
|
271
|
+
} catch (error) {
|
|
272
|
+
const validation = await verifyTransaction(tx, this.api)
|
|
273
|
+
if (validation.length > 0) throw new RpcInvalidTransactionError(validation)
|
|
274
|
+
throw new RpcBroadcastError(error.message)
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
[METHODS.signMessage]: async ({ message, onAccount }, origin) => {
|
|
278
|
+
if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError()
|
|
279
|
+
onAccount ??= await this.address()
|
|
280
|
+
if (!this.addresses().includes(onAccount)) {
|
|
281
|
+
throw new RpcPermissionDenyError(onAccount)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const overrides = await this.onMessageSign(id, { message, onAccount }, origin)
|
|
285
|
+
onAccount = overrides?.onAccount ?? onAccount
|
|
286
|
+
return {
|
|
287
|
+
// TODO: fix signMessage return type
|
|
288
|
+
signature: await this.signMessage(message, { onAccount, returnHex: true }) as
|
|
289
|
+
unknown as string
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
}
|
|
294
|
+
this._clients.set(id, client)
|
|
295
|
+
return id
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Send shareWalletInfo message to notify AEPP about wallet
|
|
300
|
+
* @param clientId - ID of RPC client send message to
|
|
301
|
+
*/
|
|
302
|
+
async shareWalletInfo (clientId: string): Promise<void> {
|
|
303
|
+
this._getClient(clientId).rpc.notify(METHODS.readyToConnect, await this.getWalletInfo())
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Get Wallet info object
|
|
308
|
+
* @returns Object with wallet information
|
|
309
|
+
*/
|
|
310
|
+
async getWalletInfo (): Promise<WalletInfo> {
|
|
311
|
+
return {
|
|
312
|
+
id: this.id,
|
|
313
|
+
name: this.name,
|
|
314
|
+
networkId: await this.getNetworkId(),
|
|
315
|
+
origin: window.location.origin,
|
|
316
|
+
type: this._type
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Get Wallet accounts
|
|
322
|
+
* @returns Object with accounts information (\{ connected: Object, current: Object \})
|
|
323
|
+
*/
|
|
324
|
+
getAccounts (): Accounts {
|
|
325
|
+
return {
|
|
326
|
+
current: this.selectedAddress != null ? { [this.selectedAddress]: {} } : {},
|
|
327
|
+
connected: this.addresses()
|
|
328
|
+
.filter((a) => a !== this.selectedAddress)
|
|
329
|
+
.reduce((acc, a) => ({ ...acc, [a]: {} }), {})
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
package/src/Node.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js'
|
|
2
|
+
import { OperationArguments, OperationSpec } from '@azure/core-client'
|
|
3
|
+
import {
|
|
4
|
+
genRequestQueuesPolicy, genCombineGetRequestsPolicy, genErrorFormatterPolicy,
|
|
5
|
+
genVersionCheckPolicy
|
|
6
|
+
} from './utils/autorest'
|
|
7
|
+
import { Node as NodeApi, NodeOptionalParams, ErrorModel } from './apis/node/'
|
|
8
|
+
import { mapObject } from './utils/other'
|
|
9
|
+
import { EncodedData } from './utils/encoder'
|
|
10
|
+
import { MissingParamError } from './utils/errors'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Obtain networkId from account or node
|
|
14
|
+
*/
|
|
15
|
+
export async function getNetworkId ({ networkId }: { networkId?: string } = {}): Promise<string> {
|
|
16
|
+
const res = networkId ?? this.networkId ?? (await this.api?.getStatus()).networkId
|
|
17
|
+
if (res != null) return res
|
|
18
|
+
throw new MissingParamError('networkId is not provided')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const bigIntPropertyNames = [
|
|
22
|
+
'balance', 'queryFee', 'fee', 'amount', 'nameFee', 'channelAmount',
|
|
23
|
+
'initiatorAmount', 'responderAmount', 'channelReserve', 'initiatorAmountFinal',
|
|
24
|
+
'responderAmountFinal', 'gasPrice', 'deposit'
|
|
25
|
+
] as const
|
|
26
|
+
|
|
27
|
+
const numberPropertyNames = [
|
|
28
|
+
'time', 'gas', 'gasUsed', 'nameSalt',
|
|
29
|
+
'nonce', 'nextNonce', 'height', 'blockHeight', 'top', 'topBlockHeight', 'ttl',
|
|
30
|
+
'inbound', 'outbound', 'peerCount', 'pendingTransactionsCount', 'effectiveAtHeight',
|
|
31
|
+
'version', 'solutions'
|
|
32
|
+
] as const
|
|
33
|
+
|
|
34
|
+
type BigIntPropertyNames = typeof bigIntPropertyNames[number]
|
|
35
|
+
type NumberPropertyNames = typeof numberPropertyNames[number]
|
|
36
|
+
type PreserveOptional<NewType, OrigType> =
|
|
37
|
+
OrigType extends undefined ? NewType | undefined : NewType
|
|
38
|
+
export type TransformNodeType<Type> =
|
|
39
|
+
Type extends (...args: infer Args) => infer Ret
|
|
40
|
+
? (...args: TransformNodeType<Args>) => TransformNodeType<Ret>
|
|
41
|
+
: Type extends [infer Item, ...infer Rest]
|
|
42
|
+
? [TransformNodeType<Item>, ...TransformNodeType<Rest>]
|
|
43
|
+
: Type extends Array<infer Item>
|
|
44
|
+
? Array<TransformNodeType<Item>>
|
|
45
|
+
: Type extends Promise<infer T>
|
|
46
|
+
? Promise<TransformNodeType<T>>
|
|
47
|
+
: Type extends { [P in any]: any }
|
|
48
|
+
? {
|
|
49
|
+
[Property in keyof Type]:
|
|
50
|
+
Property extends BigIntPropertyNames
|
|
51
|
+
? PreserveOptional<bigint, Type[Property]>
|
|
52
|
+
: Property extends NumberPropertyNames
|
|
53
|
+
? PreserveOptional<number, Type[Property]>
|
|
54
|
+
: Property extends 'txHash'
|
|
55
|
+
? PreserveOptional<EncodedData<'th'>, Type[Property]>
|
|
56
|
+
: TransformNodeType<Type[Property]>
|
|
57
|
+
}
|
|
58
|
+
: Type
|
|
59
|
+
type TransformedNode = new (...args: ConstructorParameters<typeof NodeApi>) => {
|
|
60
|
+
[Name in keyof InstanceType<typeof NodeApi>]: TransformNodeType<NodeApi[Name]>
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface NodeInfo {
|
|
64
|
+
url: string
|
|
65
|
+
nodeNetworkId: string
|
|
66
|
+
version: string
|
|
67
|
+
consensusProtocolVersion: number
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default class Node extends (NodeApi as unknown as TransformedNode) {
|
|
71
|
+
url: string
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @param url - Url for node API
|
|
75
|
+
* @param options - Options
|
|
76
|
+
* @param options.ignoreVersion - Don't check node version
|
|
77
|
+
*/
|
|
78
|
+
constructor (
|
|
79
|
+
url: string,
|
|
80
|
+
{ ignoreVersion = false, ...options }: NodeOptionalParams & { ignoreVersion?: boolean } = {}
|
|
81
|
+
) {
|
|
82
|
+
// eslint-disable-next-line constructor-super
|
|
83
|
+
super(url, {
|
|
84
|
+
allowInsecureConnection: true,
|
|
85
|
+
additionalPolicies: [
|
|
86
|
+
genRequestQueuesPolicy(),
|
|
87
|
+
genCombineGetRequestsPolicy(),
|
|
88
|
+
genErrorFormatterPolicy((body: ErrorModel) => ` ${body.reason}`)
|
|
89
|
+
],
|
|
90
|
+
...options
|
|
91
|
+
})
|
|
92
|
+
this.url = url
|
|
93
|
+
if (!ignoreVersion) {
|
|
94
|
+
const versionPromise = this.getStatus().then(({ nodeVersion }) => nodeVersion)
|
|
95
|
+
this.pipeline.addPolicy(genVersionCheckPolicy('node', '/v3/status', versionPromise, '6.2.0', '7.0.0'))
|
|
96
|
+
}
|
|
97
|
+
this.intAsString = true
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async getNodeInfo (): Promise<NodeInfo> {
|
|
101
|
+
const {
|
|
102
|
+
nodeVersion: version,
|
|
103
|
+
networkId: nodeNetworkId,
|
|
104
|
+
protocols,
|
|
105
|
+
topBlockHeight
|
|
106
|
+
} = await this.getStatus()
|
|
107
|
+
const consensusProtocolVersion = protocols
|
|
108
|
+
.filter(({ effectiveAtHeight }) => topBlockHeight >= effectiveAtHeight)
|
|
109
|
+
.reduce(
|
|
110
|
+
(acc, p) => p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc,
|
|
111
|
+
{ effectiveAtHeight: -1, version: 0 }
|
|
112
|
+
)
|
|
113
|
+
.version
|
|
114
|
+
return {
|
|
115
|
+
url: this.url,
|
|
116
|
+
nodeNetworkId,
|
|
117
|
+
version,
|
|
118
|
+
consensusProtocolVersion
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/27689
|
|
123
|
+
async sendOperationRequest (
|
|
124
|
+
operationArguments: OperationArguments, operationSpec: OperationSpec
|
|
125
|
+
): Promise<any> {
|
|
126
|
+
const args = mapObject(
|
|
127
|
+
operationArguments,
|
|
128
|
+
([key, value]) => [key, this.#encodeArg(value)]
|
|
129
|
+
) as OperationArguments
|
|
130
|
+
return this.#decodeRes(await super.sendOperationRequest(args, operationSpec))
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
#mapData (
|
|
134
|
+
data: any, transform: {
|
|
135
|
+
bigInt: (v: any) => any
|
|
136
|
+
number: (v: any) => any
|
|
137
|
+
}
|
|
138
|
+
): unknown {
|
|
139
|
+
if (Array.isArray(data)) return data.map(d => this.#mapData(d, transform))
|
|
140
|
+
if (data != null && typeof data === 'object') {
|
|
141
|
+
return mapObject(data, ([key, value]) => {
|
|
142
|
+
if (value == null) return [key, value]
|
|
143
|
+
if (bigIntPropertyNames.some(k => k === key)) return [key, transform.bigInt(value)]
|
|
144
|
+
if (numberPropertyNames.some(k => k === key)) return [key, transform.number(value)]
|
|
145
|
+
return [key, this.#mapData(value, transform)]
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
return data
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
#encodeArg (data: any): any {
|
|
152
|
+
return this.#mapData(data, {
|
|
153
|
+
bigInt: value => {
|
|
154
|
+
if (value instanceof BigNumber) return value.toFixed()
|
|
155
|
+
return value.toString()
|
|
156
|
+
},
|
|
157
|
+
number: value => value.toString()
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
#decodeRes (data: any): any {
|
|
162
|
+
return this.#mapData(data, {
|
|
163
|
+
bigInt: value => BigInt(value),
|
|
164
|
+
number: value => +value
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ISC License (ISC)
|
|
3
|
+
* Copyright (c) 2022 aeternity developers
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
|
8
|
+
*
|
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
*/
|
|
17
|
+
import { messageToHash, verifyMessage as verifyMessageCrypto, hash } from '../utils/crypto'
|
|
18
|
+
import { buildTx } from '../tx/builder'
|
|
19
|
+
import { decode, EncodedData } from '../utils/encoder'
|
|
20
|
+
import { TX_TYPE } from '../tx/builder/schema'
|
|
21
|
+
import { getNetworkId } from '../Node'
|
|
22
|
+
import { concatBuffers } from '../utils/other'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Check is provided object looks like an instance of AccountBase
|
|
26
|
+
* @param acc - Object to check
|
|
27
|
+
*/
|
|
28
|
+
export const isAccountBase = (acc: AccountBase | any): boolean =>
|
|
29
|
+
!['sign', 'address', 'signTransaction', 'signMessage'].some(f => typeof acc[f] !== 'function')
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Account is one of the three basic building blocks of an
|
|
33
|
+
* {@link AeSdk} and provides access to a signing key pair.
|
|
34
|
+
*/
|
|
35
|
+
export default abstract class AccountBase {
|
|
36
|
+
networkId?: string
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param options - Options
|
|
40
|
+
* @param options.networkId - Using for signing transactions
|
|
41
|
+
*/
|
|
42
|
+
constructor ({ networkId }: { networkId?: string } = {}) {
|
|
43
|
+
this.networkId ??= networkId
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Sign encoded transaction
|
|
48
|
+
* @param tx - Transaction to sign
|
|
49
|
+
* @param opt - Options
|
|
50
|
+
* @param opt.innerTx - Sign as inner transaction for PayingFor
|
|
51
|
+
* @returns Signed transaction
|
|
52
|
+
*/
|
|
53
|
+
async signTransaction (
|
|
54
|
+
tx: EncodedData<'tx'>,
|
|
55
|
+
{ innerTx, networkId, ...options }: { innerTx?: boolean, networkId?: string } = {}
|
|
56
|
+
): Promise<EncodedData<'tx'>> {
|
|
57
|
+
const prefixes = [await this.getNetworkId({ networkId })]
|
|
58
|
+
if (innerTx === true) prefixes.push('inner_tx')
|
|
59
|
+
const rlpBinaryTx = decode(tx)
|
|
60
|
+
const txWithNetworkId = concatBuffers([Buffer.from(prefixes.join('-')), hash(rlpBinaryTx)])
|
|
61
|
+
|
|
62
|
+
const signatures = [await this.sign(txWithNetworkId, options)]
|
|
63
|
+
return buildTx({ encodedTx: rlpBinaryTx, signatures }, TX_TYPE.signed).tx
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Get network Id
|
|
68
|
+
* @returns Network Id
|
|
69
|
+
*/
|
|
70
|
+
readonly getNetworkId = getNetworkId
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Sign message
|
|
74
|
+
* @param message - Message to sign
|
|
75
|
+
* @param opt - Options
|
|
76
|
+
* @returns Signature as hex string of Uint8Array
|
|
77
|
+
*/
|
|
78
|
+
async signMessage (
|
|
79
|
+
message: string, { returnHex = false, ...options }: { returnHex?: boolean } = {}
|
|
80
|
+
): Promise<string | Uint8Array> {
|
|
81
|
+
const sig = await this.sign(messageToHash(message), options)
|
|
82
|
+
return returnHex ? Buffer.from(sig).toString('hex') : sig
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Verify message
|
|
87
|
+
* @param message - Message to verify
|
|
88
|
+
* @param signature - Signature
|
|
89
|
+
* @param options - Options
|
|
90
|
+
*/
|
|
91
|
+
async verifyMessage (
|
|
92
|
+
message: string, signature: string | Uint8Array, options?: object
|
|
93
|
+
): Promise<boolean> {
|
|
94
|
+
return verifyMessageCrypto(
|
|
95
|
+
message,
|
|
96
|
+
typeof signature === 'string' ? Buffer.from(signature, 'hex') : signature,
|
|
97
|
+
decode(await this.address(options))
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Sign data blob
|
|
103
|
+
* @param data - Data blob to sign
|
|
104
|
+
* @param options - Options
|
|
105
|
+
* @returns Signed data blob
|
|
106
|
+
*/
|
|
107
|
+
abstract sign (data: string | Uint8Array, options?: any): Promise<Uint8Array>
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Obtain account address
|
|
111
|
+
* @returns Public account address
|
|
112
|
+
*/
|
|
113
|
+
abstract address (opt?: object): Promise<EncodedData<'ak'>>
|
|
114
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ISC License (ISC)
|
|
3
|
+
* Copyright (c) 2018 aeternity developers
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
|
8
|
+
*
|
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
*/
|
|
17
|
+
import AccountBase from './Base'
|
|
18
|
+
import { sign, isValidKeypair } from '../utils/crypto'
|
|
19
|
+
import { isHex } from '../utils/string'
|
|
20
|
+
import { decode } from '../tx/builder/helpers'
|
|
21
|
+
import { InvalidKeypairError, MissingParamError } from '../utils/errors'
|
|
22
|
+
import { EncodedData } from '../utils/encoder'
|
|
23
|
+
|
|
24
|
+
const secrets = new WeakMap()
|
|
25
|
+
|
|
26
|
+
export interface Keypair {
|
|
27
|
+
publicKey: EncodedData<'ak'>
|
|
28
|
+
secretKey: string | Uint8Array
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* In-memory account class
|
|
33
|
+
*/
|
|
34
|
+
export default class AccountMemory extends AccountBase {
|
|
35
|
+
isGa: boolean
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param options - Options
|
|
39
|
+
* @param options.keypair - Key pair to use
|
|
40
|
+
* @param options.keypair.publicKey - Public key
|
|
41
|
+
* @param options.keypair.secretKey - Private key
|
|
42
|
+
* @param options.gaId - Address of generalized account
|
|
43
|
+
*/
|
|
44
|
+
constructor (
|
|
45
|
+
{ keypair, gaId, ...options }: { keypair?: Keypair, gaId?: EncodedData<'ak'> } & ConstructorParameters<typeof AccountBase>[0]
|
|
46
|
+
) {
|
|
47
|
+
super(options)
|
|
48
|
+
|
|
49
|
+
this.isGa = gaId != null
|
|
50
|
+
if (this.isGa && gaId != null) {
|
|
51
|
+
decode(gaId)
|
|
52
|
+
secrets.set(this, { publicKey: gaId })
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (keypair == null) throw new MissingParamError('Either gaId or keypair is required')
|
|
57
|
+
|
|
58
|
+
if (
|
|
59
|
+
!Buffer.isBuffer(keypair.secretKey) &&
|
|
60
|
+
typeof keypair.secretKey === 'string' && !isHex(keypair.secretKey)
|
|
61
|
+
) throw new InvalidKeypairError('Secret key must be hex string or Buffer')
|
|
62
|
+
const secretKey = typeof keypair.secretKey === 'string'
|
|
63
|
+
? Buffer.from(keypair.secretKey, 'hex')
|
|
64
|
+
: keypair.secretKey
|
|
65
|
+
if (!isValidKeypair(secretKey, decode(keypair.publicKey))) {
|
|
66
|
+
throw new InvalidKeypairError('Invalid Key Pair')
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
secrets.set(this, {
|
|
70
|
+
secretKey,
|
|
71
|
+
publicKey: keypair.publicKey
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async sign (data: string | Uint8Array): Promise<Uint8Array> {
|
|
76
|
+
if (this.isGa) throw new InvalidKeypairError('You are trying to sign data using generalized account without keypair')
|
|
77
|
+
return sign(data, secrets.get(this).secretKey)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async address (): Promise<EncodedData<'ak'>> {
|
|
81
|
+
return secrets.get(this).publicKey
|
|
82
|
+
}
|
|
83
|
+
}
|