@aeternity/aepp-sdk 11.0.1 → 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/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +12 -19
- 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 +90 -46
- 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.mjs +147 -112
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/index.d.ts +634 -0
- package/es/channel/index.mjs +898 -900
- package/es/channel/index.mjs.map +1 -1
- package/es/channel/internal.d.ts +100 -0
- package/es/channel/internal.mjs +97 -51
- package/es/channel/internal.mjs.map +1 -1
- 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 +199 -180
- package/es/contract/aci.mjs.map +1 -1
- 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 +32 -40
- package/es/index.mjs.map +1 -1
- 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 +11 -19
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types.d.ts +62 -0
- package/es/tx/builder/field-types.mjs +62 -10
- package/es/tx/builder/field-types.mjs.map +1 -1
- package/es/tx/builder/helpers.d.ts +131 -0
- package/es/tx/builder/helpers.mjs +71 -169
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +75 -0
- package/es/tx/builder/index.mjs +141 -323
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +350 -0
- package/es/tx/builder/schema.mjs +173 -510
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +63 -0
- package/es/tx/index.mjs +171 -265
- package/es/tx/index.mjs.map +1 -1
- 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 +64 -71
- package/es/tx/validator.mjs.map +1 -1
- 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.map +1 -1
- 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.mjs +28 -41
- package/es/utils/amount-formatter.mjs.map +1 -1
- 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 +10 -8
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
- package/es/utils/bytes.mjs +10 -14
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +103 -0
- package/es/utils/crypto.mjs +60 -68
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder.d.ts +26 -0
- package/es/utils/encoder.mjs +47 -51
- package/es/utils/encoder.mjs.map +1 -1
- package/es/{errors.d.ts → utils/errors.d.ts} +254 -57
- package/es/utils/errors.mjs +318 -125
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +34 -0
- package/es/utils/hd-wallet.mjs +27 -16
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.d.ts +5 -0
- package/es/utils/json-big.mjs +10 -14
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.d.ts +51 -0
- package/es/utils/keystore.mjs +98 -193
- package/es/utils/keystore.mjs.map +1 -1
- package/es/{mptree.d.ts → utils/mptree.d.ts} +5 -8
- package/es/utils/mptree.mjs +13 -14
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +14 -0
- package/es/utils/other.mjs +21 -36
- package/es/utils/other.mjs.map +1 -1
- package/es/{semver-satisfies.d.ts → utils/semver-satisfies.d.ts} +0 -0
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.d.ts +24 -0
- package/es/utils/string.mjs +8 -10
- package/es/utils/string.mjs.map +1 -1
- package/package.json +49 -39
- 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.mjs → src/aepp-wallet-communication/connection-proxy.ts} +16 -17
- 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} +220 -128
- 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.js → constants.ts} +12 -16
- 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 -42
- package/src/utils/autorest.ts +90 -0
- package/src/utils/bignumber.ts +9 -11
- package/src/utils/bytes.ts +12 -14
- package/src/utils/crypto.ts +217 -0
- package/src/utils/encoder.ts +52 -55
- package/src/utils/errors.ts +268 -134
- 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 +14 -14
- package/src/utils/other.ts +28 -43
- package/src/utils/string.ts +8 -10
- package/es/account/base.mjs +0 -179
- package/es/account/base.mjs.map +0 -1
- package/es/account/memory.mjs +0 -99
- package/es/account/memory.mjs.map +0 -1
- package/es/account/multiple.mjs +0 -179
- package/es/account/multiple.mjs.map +0 -1
- package/es/ae/aens.mjs +0 -404
- package/es/ae/aens.mjs.map +0 -1
- package/es/ae/aepp.mjs +0 -45
- package/es/ae/aepp.mjs.map +0 -1
- package/es/ae/contract.mjs +0 -159
- package/es/ae/contract.mjs.map +0 -1
- package/es/ae/index.mjs +0 -207
- package/es/ae/index.mjs.map +0 -1
- package/es/ae/oracle.mjs +0 -339
- package/es/ae/oracle.mjs.map +0 -1
- package/es/ae/universal.mjs +0 -45
- package/es/ae/universal.mjs.map +0 -1
- package/es/ae/wallet.mjs +0 -50
- package/es/ae/wallet.mjs.map +0 -1
- package/es/amount-formatter.d.ts +0 -58
- package/es/bignumber.d.ts +0 -18
- package/es/chain/index.mjs +0 -272
- package/es/chain/index.mjs.map +0 -1
- package/es/chain/node.mjs +0 -442
- package/es/chain/node.mjs.map +0 -1
- package/es/contract/compiler.mjs +0 -115
- package/es/contract/compiler.mjs.map +0 -1
- package/es/contract/ga/helpers.mjs +0 -30
- package/es/contract/ga/helpers.mjs.map +0 -1
- package/es/contract/ga/index.mjs +0 -178
- package/es/contract/ga/index.mjs.map +0 -1
- package/es/crypto-ts.d.ts +0 -9
- package/es/encoder.d.ts +0 -26
- package/es/node-pool/index.mjs +0 -188
- package/es/node-pool/index.mjs.map +0 -1
- package/es/node.mjs +0 -133
- package/es/node.mjs.map +0 -1
- package/es/other.d.ts +0 -31
- package/es/string.d.ts +0 -26
- package/es/tx/tx-object.mjs +0 -283
- package/es/tx/tx-object.mjs.map +0 -1
- package/es/tx/tx.mjs +0 -938
- package/es/tx/tx.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs +0 -132
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +0 -183
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/index.mjs +0 -87
- package/es/utils/aepp-wallet-communication/connection/index.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs +0 -98
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/helpers.mjs +0 -92
- package/es/utils/aepp-wallet-communication/helpers.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +0 -375
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +0 -275
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +0 -541
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.mjs +0 -102
- package/es/utils/aepp-wallet-communication/schema.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs +0 -110
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +0 -1
- package/es/utils/async-init.mjs +0 -64
- package/es/utils/async-init.mjs.map +0 -1
- package/es/utils/crypto-ts.mjs.map +0 -1
- package/es/utils/swagger.mjs +0 -164
- package/es/utils/swagger.mjs.map +0 -1
- package/src/account/base.js +0 -153
- package/src/account/memory.js +0 -83
- package/src/account/multiple.js +0 -162
- package/src/ae/aens.js +0 -361
- package/src/ae/aepp.js +0 -45
- package/src/ae/contract.js +0 -148
- package/src/ae/index.js +0 -168
- package/src/ae/oracle.js +0 -311
- package/src/ae/universal.js +0 -47
- package/src/ae/wallet.js +0 -50
- package/src/chain/index.js +0 -269
- package/src/chain/node.js +0 -320
- package/src/channel/index.js +0 -903
- package/src/channel/internal.js +0 -236
- package/src/contract/aci.js +0 -376
- package/src/contract/compiler.js +0 -100
- package/src/contract/ga/helpers.js +0 -19
- package/src/contract/ga/index.js +0 -150
- package/src/index.js +0 -89
- package/src/node-pool/index.js +0 -172
- package/src/node.js +0 -116
- package/src/tx/builder/field-types.js +0 -61
- package/src/tx/builder/helpers.js +0 -334
- package/src/tx/builder/index.js +0 -465
- package/src/tx/builder/schema.js +0 -1100
- package/src/tx/index.js +0 -301
- package/src/tx/tx-object.js +0 -187
- package/src/tx/tx.js +0 -631
- package/src/tx/validator.js +0 -181
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -119
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -165
- package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -86
- package/src/utils/aepp-wallet-communication/helpers.js +0 -60
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -294
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -232
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -401
- package/src/utils/aepp-wallet-communication/schema.ts +0 -80
- package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -92
- package/src/utils/async-init.js +0 -45
- package/src/utils/crypto.js +0 -219
- package/src/utils/hd-wallet.js +0 -100
- package/src/utils/json-big.js +0 -26
- package/src/utils/keystore.js +0 -219
- package/src/utils/swagger.js +0 -156
package/es/utils/other.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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;
|
package/es/utils/string.mjs
CHANGED
|
@@ -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) {
|
package/es/utils/string.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,6 +1,6 @@
|
|
|
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",
|
|
@@ -11,17 +11,18 @@
|
|
|
11
11
|
"sideEffects": false,
|
|
12
12
|
"scripts": {
|
|
13
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": "
|
|
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
|
-
"lint": "eslint .",
|
|
18
|
+
"docs:api": "typedoc",
|
|
19
|
+
"lint": "eslint . --ext .ts,.js",
|
|
19
20
|
"test": "nyc mocha './test/unit/' './test/integration/'",
|
|
20
21
|
"test:integration": "nyc mocha './test/integration/'",
|
|
21
22
|
"test:unit": "nyc mocha './test/unit/'",
|
|
22
23
|
"test:watch": "mocha './test/unit/' './test/integration/' --watch",
|
|
23
24
|
"prepare": "npm run build",
|
|
24
|
-
"prepublishOnly": "npm run docs:examples",
|
|
25
|
+
"prepublishOnly": "test/examples.sh && npm run docs:examples && npm run docs:api",
|
|
25
26
|
"release": "standard-version --skip.tag --infile docs/CHANGELOG.md"
|
|
26
27
|
},
|
|
27
28
|
"license": "ISC",
|
|
@@ -34,25 +35,24 @@
|
|
|
34
35
|
"dependencies": {
|
|
35
36
|
"@aeternity/aepp-calldata": "^1.1.1",
|
|
36
37
|
"@aeternity/argon2-browser": "^0.1.2",
|
|
37
|
-
"@aeternity/blakejs": "^1.1.2",
|
|
38
|
-
"@aeternity/json-bigint": "^0.3.1",
|
|
39
38
|
"@aeternity/uuid": "^0.0.1",
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
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
43
|
"bignumber.js": "^9.0.2",
|
|
45
44
|
"bip32-path": "^0.4.2",
|
|
46
|
-
"
|
|
45
|
+
"blakejs": "^1.2.1",
|
|
46
|
+
"bs58": "^5.0.0",
|
|
47
47
|
"buffer": "^6.0.3",
|
|
48
|
-
"cross-fetch": "^3.1.5",
|
|
49
48
|
"events": "^3.3.0",
|
|
49
|
+
"json-bigint": "^1.0.0",
|
|
50
50
|
"process": "^0.11.10",
|
|
51
51
|
"rlp": "^3.0.0",
|
|
52
52
|
"sha.js": "^2.4.11",
|
|
53
|
-
"swagger-client": "^3.18.4",
|
|
54
53
|
"tweetnacl": "^1.0.3",
|
|
55
54
|
"tweetnacl-auth": "^1.0.1",
|
|
55
|
+
"varuint-bitcoin": "^1.1.2",
|
|
56
56
|
"websocket": "^1.0.34"
|
|
57
57
|
},
|
|
58
58
|
"repository": {
|
|
@@ -60,40 +60,50 @@
|
|
|
60
60
|
"url": "https://github.com/aeternity/aepp-sdk-js"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@babel/cli": "^7.17.
|
|
64
|
-
"@babel/core": "^7.
|
|
65
|
-
"@babel/node": "^7.
|
|
66
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
67
|
-
"@babel/preset-env": "^7.
|
|
68
|
-
"@babel/preset-typescript": "^7.
|
|
69
|
-
"@babel/register": "^7.17.
|
|
70
|
-
"@commitlint/cli": "^
|
|
71
|
-
"@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",
|
|
72
74
|
"@types/bn.js": "^5.1.0",
|
|
73
|
-
"@types/
|
|
74
|
-
"@types/chai": "^
|
|
75
|
-
"@types/
|
|
76
|
-
"@types/
|
|
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",
|
|
77
80
|
"@types/sha.js": "^2.4.0",
|
|
78
|
-
"@
|
|
79
|
-
"@
|
|
80
|
-
"
|
|
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",
|
|
81
88
|
"babel-plugin-add-import-extension": "^1.6.0",
|
|
82
89
|
"babel-plugin-import-globals": "^2.0.0",
|
|
83
90
|
"babel-plugin-transform-default-named-imports": "^1.2.2",
|
|
84
91
|
"chai": "^4.3.6",
|
|
85
92
|
"chai-as-promised": "^7.1.1",
|
|
86
|
-
"eslint": "^8.
|
|
87
|
-
"eslint-config-standard": "^17.0.0
|
|
88
|
-
"
|
|
89
|
-
"
|
|
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",
|
|
90
98
|
"nyc": "^15.1.0",
|
|
91
|
-
"sinon": "^
|
|
92
|
-
"source-map": "^0.7.
|
|
93
|
-
"standard-version": "^9.
|
|
94
|
-
"ts-node": "^10.
|
|
95
|
-
"
|
|
96
|
-
"
|
|
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",
|
|
97
107
|
"webpack-bundle-analyzer": "^4.5.0",
|
|
98
108
|
"webpack-cli": "^4.9.2"
|
|
99
109
|
},
|
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
|
+
}
|
package/src/AeSdkAepp.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import AeSdkBase, { Account } from './AeSdkBase'
|
|
2
|
+
import AccountBase from './account/Base'
|
|
3
|
+
import AccountRpc from './account/Rpc'
|
|
4
|
+
import { decode, EncodedData } from './utils/encoder'
|
|
5
|
+
import { Accounts, RPC_VERSION, WalletInfo, Network, WalletApi, AeppApi } from './aepp-wallet-communication/rpc/types'
|
|
6
|
+
import RpcClient from './aepp-wallet-communication/rpc/RpcClient'
|
|
7
|
+
import { METHODS, SUBSCRIPTION_TYPES } from './aepp-wallet-communication/schema'
|
|
8
|
+
import {
|
|
9
|
+
AlreadyConnectedError,
|
|
10
|
+
NoWalletConnectedError,
|
|
11
|
+
UnsubscribedAccountError,
|
|
12
|
+
UnAuthorizedAccountError,
|
|
13
|
+
RpcConnectionError
|
|
14
|
+
} from './utils/errors'
|
|
15
|
+
import Node from './Node'
|
|
16
|
+
import BrowserConnection from './aepp-wallet-communication/connection/Browser'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* RPC handler for AEPP side
|
|
20
|
+
* Contain functionality for wallet interaction and connect it to sdk
|
|
21
|
+
*/
|
|
22
|
+
export default class AeSdkAepp extends AeSdkBase {
|
|
23
|
+
name: string
|
|
24
|
+
onAddressChange: (a: Accounts) => void
|
|
25
|
+
onDisconnect: (p: any) => void
|
|
26
|
+
onNetworkChange: (a: Network) => void
|
|
27
|
+
rpcClient?: RpcClient<WalletApi, AeppApi>
|
|
28
|
+
_accounts?: Accounts
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param options - Options
|
|
32
|
+
* @param options.name - Aepp name
|
|
33
|
+
* @param options.onAddressChange - Call-back function for update address event
|
|
34
|
+
* @param options.onDisconnect - Call-back function for disconnect event
|
|
35
|
+
* @param options.onNetworkChange - Call-back function for update network event
|
|
36
|
+
*/
|
|
37
|
+
constructor ({
|
|
38
|
+
name,
|
|
39
|
+
onAddressChange = () => {},
|
|
40
|
+
onDisconnect = () => {},
|
|
41
|
+
onNetworkChange = () => {},
|
|
42
|
+
...other
|
|
43
|
+
}: {
|
|
44
|
+
name: string
|
|
45
|
+
onAddressChange: (a: Accounts) => void
|
|
46
|
+
onDisconnect: (p: any) => void
|
|
47
|
+
onNetworkChange: (a: Network) => void
|
|
48
|
+
} & ConstructorParameters<typeof AeSdkBase>[0]) {
|
|
49
|
+
super(other)
|
|
50
|
+
this.onAddressChange = onAddressChange
|
|
51
|
+
this.onDisconnect = onDisconnect
|
|
52
|
+
this.onNetworkChange = onNetworkChange
|
|
53
|
+
this.name = name
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
_resolveAccount (account: Account = this.addresses()[0]): AccountBase {
|
|
57
|
+
if (typeof account === 'string') {
|
|
58
|
+
const address = account as EncodedData<'ak'>
|
|
59
|
+
decode(address)
|
|
60
|
+
if (!this.addresses().includes(address)) throw new UnAuthorizedAccountError(address)
|
|
61
|
+
account = new AccountRpc({ rpcClient: this.rpcClient, address })
|
|
62
|
+
}
|
|
63
|
+
if (account == null) this._ensureAccountAccess()
|
|
64
|
+
return super._resolveAccount(account)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
addresses (): Array<EncodedData<'ak'>> {
|
|
68
|
+
if (this._accounts == null) return []
|
|
69
|
+
const current = Object.keys(this._accounts.current)[0]
|
|
70
|
+
return [
|
|
71
|
+
...current != null ? [current] : [], ...Object.keys(this._accounts.connected)
|
|
72
|
+
] as Array<EncodedData<'ak'>>
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Connect to wallet
|
|
77
|
+
* @param connection - Wallet connection object
|
|
78
|
+
* @param options - Options
|
|
79
|
+
* @param options.connectNode - Request wallet to bind node
|
|
80
|
+
* @param options.name - Node name
|
|
81
|
+
* @param options.select - Select this node as current
|
|
82
|
+
*/
|
|
83
|
+
async connectToWallet (
|
|
84
|
+
connection: BrowserConnection,
|
|
85
|
+
{ connectNode = false, name = 'wallet-node', select = false }:
|
|
86
|
+
{ connectNode?: boolean, name?: string, select?: boolean } = {}
|
|
87
|
+
): Promise<WalletInfo> {
|
|
88
|
+
if (this.rpcClient != null) throw new AlreadyConnectedError('You are already connected to wallet')
|
|
89
|
+
let disconnectParams: any
|
|
90
|
+
const client = new RpcClient<WalletApi, AeppApi>(
|
|
91
|
+
connection,
|
|
92
|
+
() => {
|
|
93
|
+
delete this.rpcClient
|
|
94
|
+
delete this._accounts
|
|
95
|
+
this.onDisconnect(disconnectParams)
|
|
96
|
+
}, {
|
|
97
|
+
[METHODS.updateAddress]: (params) => {
|
|
98
|
+
this._accounts = params
|
|
99
|
+
this.onAddressChange(params)
|
|
100
|
+
},
|
|
101
|
+
[METHODS.updateNetwork]: (params) => {
|
|
102
|
+
const { node } = params
|
|
103
|
+
if (node != null) this.addNode(node.name, new Node(node.url), true)
|
|
104
|
+
this.onNetworkChange(params)
|
|
105
|
+
},
|
|
106
|
+
[METHODS.closeConnection]: (params) => {
|
|
107
|
+
disconnectParams = params
|
|
108
|
+
client.connection.disconnect()
|
|
109
|
+
},
|
|
110
|
+
[METHODS.readyToConnect]: () => {}
|
|
111
|
+
}
|
|
112
|
+
)
|
|
113
|
+
const { node, ...walletInfo } = await client.request(
|
|
114
|
+
METHODS.connect, { name: this.name, version: RPC_VERSION, connectNode }
|
|
115
|
+
)
|
|
116
|
+
if (connectNode) {
|
|
117
|
+
if (node == null) throw new RpcConnectionError('Missing URLs of the Node')
|
|
118
|
+
this.addNode(name, new Node(node.url), select)
|
|
119
|
+
}
|
|
120
|
+
this.rpcClient = client
|
|
121
|
+
return walletInfo
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Disconnect from wallet
|
|
126
|
+
*/
|
|
127
|
+
disconnectWallet (): void {
|
|
128
|
+
this._ensureConnected()
|
|
129
|
+
this.rpcClient.notify(METHODS.closeConnection, { reason: 'bye' })
|
|
130
|
+
this.rpcClient.connection.disconnect()
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Ask addresses from wallet
|
|
135
|
+
* @returns Addresses from wallet
|
|
136
|
+
*/
|
|
137
|
+
async askAddresses (): Promise<Array<EncodedData<'ak'>>> {
|
|
138
|
+
this._ensureAccountAccess()
|
|
139
|
+
return await this.rpcClient.request(METHODS.address, undefined)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Subscribe for addresses from wallet
|
|
144
|
+
* @param type - Subscription type
|
|
145
|
+
* @param value - Should be one of 'current' (the selected account), 'connected' (all)
|
|
146
|
+
* @returns Accounts from wallet
|
|
147
|
+
*/
|
|
148
|
+
async subscribeAddress (
|
|
149
|
+
type: SUBSCRIPTION_TYPES, value: 'current' | 'connected'
|
|
150
|
+
): Promise<ReturnType<WalletApi[METHODS.subscribeAddress]>> {
|
|
151
|
+
this._ensureConnected()
|
|
152
|
+
const result = await this.rpcClient.request(METHODS.subscribeAddress, { type, value })
|
|
153
|
+
this._accounts = result.address
|
|
154
|
+
return result
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
_ensureConnected (): asserts this is AeSdkAepp & { rpcClient: NonNullable<AeSdkAepp['rpcClient']> } {
|
|
158
|
+
if (this.rpcClient != null) return
|
|
159
|
+
throw new NoWalletConnectedError('You are not connected to Wallet')
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
_ensureAccountAccess (): asserts this is AeSdkAepp & { rpcClient: NonNullable<AeSdkAepp['rpcClient']> } {
|
|
163
|
+
this._ensureConnected()
|
|
164
|
+
if (this.addresses().length !== 0) return
|
|
165
|
+
throw new UnsubscribedAccountError()
|
|
166
|
+
}
|
|
167
|
+
}
|