@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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/aepp-wallet-communication/content-script-bridge.js"],"names":["stampit","UnsupportedPlatformError","MissingParamError","run","allowCrossOrigin","extConnection","connect","msg","pageConnection","sendMessage","origin","source","window","stop","disconnect","init","methods"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,WAApB;SACSC,wB,EAA0BC,iB;AAEnC;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,GAAT,GAAgB;AACd,QAAMC,gBAAgB,GAAG,KAAKA,gBAA9B,CADc,CAEd;;AACA,OAAKC,aAAL,CAAmBC,OAAnB,CAA4BC,GAAD,IAAS;AAClC,SAAKC,cAAL,CAAoBC,WAApB,CAAgCF,GAAhC;AACD,GAFD,EAHc,CAMd;;AACA,OAAKC,cAAL,CAAoBF,OAApB,CAA4B,CAACC,GAAD,EAAMG,MAAN,EAAcC,MAAd,KAAyB;AACnD,QAAI,CAACP,gBAAD,IAAqBO,MAAM,KAAKC,MAApC,EAA4C;AAC5C,SAAKP,aAAL,CAAmBI,WAAnB,CAA+BF,GAA/B;AACD,GAHD;AAID;AAED;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASM,IAAT,GAAiB;AACf,OAAKR,aAAL,CAAmBS,UAAnB;AACA,OAAKN,cAAL,CAAoBM,UAApB;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAed,OAAO,CAAC;AACrBe,EAAAA,IAAI,OAA+D;AAAA,QAA7D;AAAEP,MAAAA,cAAF;AAAkBH,MAAAA,aAAlB;AAAiCD,MAAAA,gBAAgB,GAAG;AAApD,KAA6D;AACjE,QAAI,CAACQ,MAAL,EAAa,MAAM,IAAIX,wBAAJ,CAA6B,6DAA7B,CAAN;AACb,QAAI,CAACO,cAAL,EAAqB,MAAM,IAAIN,iBAAJ,CAAsB,yBAAtB,CAAN;AACrB,QAAI,CAACG,aAAL,EAAoB,MAAM,IAAIH,iBAAJ,CAAsB,wBAAtB,CAAN;AACpB,SAAKE,gBAAL,GAAwBA,gBAAxB;AACA,SAAKI,cAAL,GAAsBA,cAAtB;AACA,SAAKH,aAAL,GAAqBA,aAArB;AACD,GARoB;;AASrBW,EAAAA,OAAO,EAAE;AAAEb,IAAAA,GAAF;AAAOU,IAAAA;AAAP;AATY,CAAD,CAAtB","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 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 * Content Script Bridge module\n *\n * @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/content-script-bridge\n * @export ContentScriptBridge\n * @example\n * import ContentScriptBridge\n * from '@aeternity/aepp-sdk/es/utils/wallet-communication/content-script-bridge\n */\nimport stampit from '@stamp/it'\nimport { UnsupportedPlatformError, MissingParamError } from '../errors'\n\n/**\n * Start message proxy\n * @function run\n * @instance\n * @return {void}\n */\nfunction run () {\n const allowCrossOrigin = this.allowCrossOrigin\n // Connect to extension using runtime\n this.extConnection.connect((msg) => {\n this.pageConnection.sendMessage(msg)\n })\n // Connect to page using window.postMessage\n this.pageConnection.connect((msg, origin, source) => {\n if (!allowCrossOrigin && source !== window) return\n this.extConnection.sendMessage(msg)\n })\n}\n\n/**\n * Stop message proxy\n * @function stop\n * @instance\n * @return {void}\n */\nfunction stop () {\n this.extConnection.disconnect()\n this.pageConnection.disconnect()\n}\n\n/**\n * ContentScriptBridge stamp\n * Provide functionality to easly redirect messages from page to extension and from extension to\n * page through content script\n * Using Runtime(Extension) and WindowPostMessage(Web-Page) connections\n * @function\n * @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/content-script-bridge\n * @rtype Stamp\n * @param {Object} params - Initializer object\n * @param {Object} params.pageConnection - Page connection object\n * (@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/\n * browser-window-message)\n * @param {Object} params.extConnection - Extension connection object\n * (@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-runtime)\n * @return {Object}\n */\nexport default stampit({\n init ({ pageConnection, extConnection, allowCrossOrigin = false }) {\n if (!window) throw new UnsupportedPlatformError('Window object not found, you can run bridge only in browser')\n if (!pageConnection) throw new MissingParamError('pageConnection required')\n if (!extConnection) throw new MissingParamError('extConnection required')\n this.allowCrossOrigin = allowCrossOrigin\n this.pageConnection = pageConnection\n this.extConnection = extConnection\n },\n methods: { run, stop }\n})\n"],"file":"content-script-bridge.mjs"}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Browser helper functions
|
|
3
|
-
*/
|
|
4
|
-
import { NoBrowserFoundError } from "../errors.mjs";
|
|
5
|
-
export const getBrowserAPI = function () {
|
|
6
|
-
let force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
7
|
-
const {
|
|
8
|
-
chrome,
|
|
9
|
-
browser
|
|
10
|
-
} = window; // Chrome, Opera support
|
|
11
|
-
|
|
12
|
-
if (typeof chrome !== 'undefined' && chrome === Object(chrome)) return chrome; // Firefox support
|
|
13
|
-
|
|
14
|
-
if (typeof browser !== 'undefined' && browser === Object(browser)) return browser;
|
|
15
|
-
if (!force) throw new NoBrowserFoundError();
|
|
16
|
-
return {};
|
|
17
|
-
};
|
|
18
|
-
export const isInIframe = () => window !== window.parent;
|
|
19
|
-
/**
|
|
20
|
-
* RPC helper functions
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
export const sendMessage = connection => {
|
|
24
|
-
let messageId = 0;
|
|
25
|
-
return function (_ref) {
|
|
26
|
-
let {
|
|
27
|
-
id,
|
|
28
|
-
method,
|
|
29
|
-
params,
|
|
30
|
-
result,
|
|
31
|
-
error
|
|
32
|
-
} = _ref;
|
|
33
|
-
let isNotificationOrResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
34
|
-
// Increment id for each request
|
|
35
|
-
isNotificationOrResponse || (messageId += 1);
|
|
36
|
-
id = isNotificationOrResponse ? id || null : messageId;
|
|
37
|
-
const msgData = params ? {
|
|
38
|
-
params
|
|
39
|
-
} : result ? {
|
|
40
|
-
result
|
|
41
|
-
} : {
|
|
42
|
-
error
|
|
43
|
-
};
|
|
44
|
-
connection.sendMessage({
|
|
45
|
-
jsonrpc: '2.0',
|
|
46
|
-
...(id ? {
|
|
47
|
-
id
|
|
48
|
-
} : {}),
|
|
49
|
-
method,
|
|
50
|
-
...msgData
|
|
51
|
-
});
|
|
52
|
-
return id;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
export const getHandler = function (schema, msg) {
|
|
56
|
-
let {
|
|
57
|
-
debug = false
|
|
58
|
-
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
59
|
-
const handler = schema[msg.method];
|
|
60
|
-
|
|
61
|
-
if (!handler || typeof handler !== 'function') {
|
|
62
|
-
debug && console.log(`Unknown message method ${msg.method}`);
|
|
63
|
-
return () => async () => true;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return handler;
|
|
67
|
-
};
|
|
68
|
-
export const message = function (method) {
|
|
69
|
-
let params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
70
|
-
return {
|
|
71
|
-
method,
|
|
72
|
-
params
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
export const responseMessage = function (id, method) {
|
|
76
|
-
let {
|
|
77
|
-
error,
|
|
78
|
-
result
|
|
79
|
-
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
80
|
-
return {
|
|
81
|
-
id,
|
|
82
|
-
method,
|
|
83
|
-
...(error ? {
|
|
84
|
-
error
|
|
85
|
-
} : {
|
|
86
|
-
result
|
|
87
|
-
})
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
export const sendResponseMessage = client => (id, method, data) => client.sendMessage(responseMessage(id, method, data), true);
|
|
91
|
-
export const isValidAccounts = accounts => ['', 'connected', 'current'].filter(k => typeof (k ? accounts[k] : accounts) === 'object').length === 3;
|
|
92
|
-
//# sourceMappingURL=helpers.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/aepp-wallet-communication/helpers.js"],"names":["NoBrowserFoundError","getBrowserAPI","force","chrome","browser","window","Object","isInIframe","parent","sendMessage","connection","messageId","id","method","params","result","error","isNotificationOrResponse","msgData","jsonrpc","getHandler","schema","msg","debug","handler","console","log","message","responseMessage","sendResponseMessage","client","data","isValidAccounts","accounts","filter","k","length"],"mappings":"AAAA;AACA;AACA;SACSA,mB;AAET,OAAO,MAAMC,aAAa,GAAG,YAAmB;AAAA,MAAlBC,KAAkB,uEAAV,KAAU;AAC9C,QAAM;AAAEC,IAAAA,MAAF;AAAUC,IAAAA;AAAV,MAAsBC,MAA5B,CAD8C,CAE9C;;AACA,MAAI,OAAOF,MAAP,KAAkB,WAAlB,IAAiCA,MAAM,KAAKG,MAAM,CAACH,MAAD,CAAtD,EAAgE,OAAOA,MAAP,CAHlB,CAI9C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AG,CAACT,MAAL,CAAtB;;AACA,MAAI,CAACW,OAAD,IAAY,OAAOA,OAAP,KAAmB,UAAnC,EAA+C;AAC7CD,IAAAA,KAAK,IAAIE,OAAO,CAACC,GAAR,CAAa,0BAAyBJ,GAAG,CAACT,MAAO,EAAjD,CAAT;AACA,WAAO,MAAM,YAAY,IAAzB;AACD;;AACD,SAAOW,OAAP;AACD,CAPM;AASP,OAAO,MAAMG,OAAO,GAAG,UAACd,MAAD;AAAA,MAASC,MAAT,uEAAkB,EAAlB;AAAA,SAA0B;AAAED,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAA1B;AAAA,CAAhB;AAEP,OAAO,MAAMc,eAAe,GAAG,UAAChB,EAAD,EAAKC,MAAL;AAAA,MAAa;AAAEG,IAAAA,KAAF;AAASD,IAAAA;AAAT,GAAb,uEAAiC,EAAjC;AAAA,SAC5B;AAAEH,IAAAA,EAAF;AAAMC,IAAAA,MAAN;AAAc,QAAIG,KAAK,GAAG;AAAEA,MAAAA;AAAF,KAAH,GAAe;AAAED,MAAAA;AAAF,KAAxB;AAAd,GAD4B;AAAA,CAAxB;AAGP,OAAO,MAAMc,mBAAmB,GAAIC,MAAD,IAAY,CAAClB,EAAD,EAAKC,MAAL,EAAakB,IAAb,KAC7CD,MAAM,CAACrB,WAAP,CAAmBmB,eAAe,CAAChB,EAAD,EAAKC,MAAL,EAAakB,IAAb,CAAlC,EAAsD,IAAtD,CADK;AAGP,OAAO,MAAMC,eAAe,GAAIC,QAAD,IAAe,CAAC,EAAD,EAAK,WAAL,EAAkB,SAAlB,EAA6BC,MAA7B,CAAoCC,CAAC,IAAI,QAAQA,CAAC,GAAGF,QAAQ,CAACE,CAAD,CAAX,GAAiBF,QAA1B,MAAwC,QAAjF,CAAD,CAA6FG,MAA7F,KAAwG,CAA9I","sourcesContent":["/**\n * Browser helper functions\n */\nimport { NoBrowserFoundError } from '../errors'\n\nexport const getBrowserAPI = (force = false) => {\n const { chrome, browser } = window\n // Chrome, Opera support\n if (typeof chrome !== 'undefined' && chrome === Object(chrome)) return chrome\n // Firefox support\n if (typeof browser !== 'undefined' && browser === Object(browser)) return browser\n if (!force) throw new NoBrowserFoundError()\n return {}\n}\n\nexport const isInIframe = () => window !== window.parent\n\n/**\n * RPC helper functions\n */\nexport const sendMessage = (connection) => {\n let messageId = 0\n\n return ({ id, method, params, result, error }, isNotificationOrResponse = false) => {\n // Increment id for each request\n isNotificationOrResponse || (messageId += 1)\n id = isNotificationOrResponse ? (id || null) : messageId\n const msgData = params\n ? { params }\n : result\n ? { result }\n : { error }\n connection.sendMessage({\n jsonrpc: '2.0',\n ...id ? { id } : {},\n method,\n ...msgData\n })\n return id\n }\n}\n\nexport const getHandler = (schema, msg, { debug = false } = {}) => {\n const handler = schema[msg.method]\n if (!handler || typeof handler !== 'function') {\n debug && console.log(`Unknown message method ${msg.method}`)\n return () => async () => true\n }\n return handler\n}\n\nexport const message = (method, params = {}) => ({ method, params })\n\nexport const responseMessage = (id, method, { error, result } = {}) =>\n ({ id, method, ...(error ? { error } : { result }) })\n\nexport const sendResponseMessage = (client) => (id, method, data) =>\n client.sendMessage(responseMessage(id, method, data), true)\n\nexport const isValidAccounts = (accounts) => (['', 'connected', 'current'].filter(k => typeof (k ? accounts[k] : accounts) === 'object')).length === 3\n"],"file":"helpers.mjs"}
|
|
@@ -1,375 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RPC handler for AEPP side
|
|
3
|
-
*
|
|
4
|
-
* @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc
|
|
5
|
-
* @export AeppRpc
|
|
6
|
-
* @example
|
|
7
|
-
* import ContentScriptBridge
|
|
8
|
-
* from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc'
|
|
9
|
-
*/
|
|
10
|
-
import { v4 as uuid } from '@aeternity/uuid';
|
|
11
|
-
import Ae from "../../../ae/index.mjs";
|
|
12
|
-
import RpcClient from "./rpc-client.mjs";
|
|
13
|
-
import { getHandler, message } from "../helpers.mjs";
|
|
14
|
-
import { METHODS, RPC_STATUS, VERSION } from "../schema.mjs";
|
|
15
|
-
import { AlreadyConnectedError, NoWalletConnectedError, UnsubscribedAccountError, UnAuthorizedAccountError, ArgumentError, RpcConnectionError } from "../../errors.mjs";
|
|
16
|
-
import Node from "../../../node.mjs";
|
|
17
|
-
const NOTIFICATIONS = {
|
|
18
|
-
[METHODS.updateAddress]: instance => _ref => {
|
|
19
|
-
let {
|
|
20
|
-
params
|
|
21
|
-
} = _ref;
|
|
22
|
-
instance.rpcClient.accounts = params;
|
|
23
|
-
instance.onAddressChange(params);
|
|
24
|
-
},
|
|
25
|
-
[METHODS.updateNetwork]: instance => async _ref2 => {
|
|
26
|
-
let {
|
|
27
|
-
params
|
|
28
|
-
} = _ref2;
|
|
29
|
-
const {
|
|
30
|
-
networkId,
|
|
31
|
-
node
|
|
32
|
-
} = params;
|
|
33
|
-
instance.rpcClient.info.networkId = networkId;
|
|
34
|
-
node && instance.addNode(node.name, await Node(node), true);
|
|
35
|
-
instance.onNetworkChange(params);
|
|
36
|
-
},
|
|
37
|
-
[METHODS.closeConnection]: instance => msg => {
|
|
38
|
-
instance.disconnectWallet();
|
|
39
|
-
instance.onDisconnect(msg.params);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const RESPONSES = {
|
|
43
|
-
[METHODS.address]: instance => msg => instance.rpcClient.processResponse(msg),
|
|
44
|
-
[METHODS.connect]: instance => msg => {
|
|
45
|
-
if (msg.result) instance.rpcClient.info.status = RPC_STATUS.CONNECTED;
|
|
46
|
-
instance.rpcClient.processResponse(msg);
|
|
47
|
-
},
|
|
48
|
-
[METHODS.subscribeAddress]: instance => msg => {
|
|
49
|
-
if (msg.result) {
|
|
50
|
-
if (msg.result.address) {
|
|
51
|
-
instance.rpcClient.accounts = msg.result.address;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (msg.result.subscription) {
|
|
55
|
-
instance.rpcClient.addressSubscription = msg.result.subscription;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
instance.rpcClient.processResponse(msg, _ref3 => {
|
|
60
|
-
let {
|
|
61
|
-
id,
|
|
62
|
-
result
|
|
63
|
-
} = _ref3;
|
|
64
|
-
return [result];
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
[METHODS.sign]: instance => msg => {
|
|
68
|
-
instance.rpcClient.processResponse(msg, _ref4 => {
|
|
69
|
-
let {
|
|
70
|
-
id,
|
|
71
|
-
result
|
|
72
|
-
} = _ref4;
|
|
73
|
-
return [result.signedTransaction || result.transactionHash];
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
[METHODS.signMessage]: instance => msg => {
|
|
77
|
-
instance.rpcClient.processResponse(msg, _ref5 => {
|
|
78
|
-
let {
|
|
79
|
-
id,
|
|
80
|
-
result
|
|
81
|
-
} = _ref5;
|
|
82
|
-
return [result.signature];
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
const REQUESTS = {};
|
|
87
|
-
|
|
88
|
-
const handleMessage = instance => async msg => {
|
|
89
|
-
if (!msg.id) {
|
|
90
|
-
return getHandler(NOTIFICATIONS, msg, {
|
|
91
|
-
debug: instance.debug
|
|
92
|
-
})(instance)(msg);
|
|
93
|
-
} else if (Object.prototype.hasOwnProperty.call(instance.rpcClient.callbacks, msg.id)) {
|
|
94
|
-
return getHandler(RESPONSES, msg, {
|
|
95
|
-
debug: instance.debug
|
|
96
|
-
})(instance)(msg);
|
|
97
|
-
} else {
|
|
98
|
-
return getHandler(REQUESTS, msg, {
|
|
99
|
-
debug: instance.debug
|
|
100
|
-
})(instance)(msg);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
/**
|
|
104
|
-
* Contain functionality for wallet interaction and connect it to sdk
|
|
105
|
-
* @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc
|
|
106
|
-
* @function
|
|
107
|
-
* @rtype Stamp
|
|
108
|
-
* @param {Object} param Init params object
|
|
109
|
-
* @param {String=} [param.name] Aepp name
|
|
110
|
-
* @param {Function} onAddressChange Call-back function for update address event
|
|
111
|
-
* @param {Function} onDisconnect Call-back function for disconnect event
|
|
112
|
-
* @param {Function} onNetworkChange Call-back function for update network event
|
|
113
|
-
* @param {Object} connection Wallet connection object
|
|
114
|
-
* @return {Object}
|
|
115
|
-
*/
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
export default Ae.compose({
|
|
119
|
-
async init(_ref6) {
|
|
120
|
-
let {
|
|
121
|
-
name,
|
|
122
|
-
connection,
|
|
123
|
-
debug = false,
|
|
124
|
-
...other
|
|
125
|
-
} = _ref6;
|
|
126
|
-
['onAddressChange', 'onDisconnect', 'onNetworkChange'].forEach(event => {
|
|
127
|
-
var _other$event;
|
|
128
|
-
|
|
129
|
-
const handler = (_other$event = other[event]) !== null && _other$event !== void 0 ? _other$event : () => {};
|
|
130
|
-
if (typeof handler !== 'function') throw new ArgumentError(event, 'a function', handler);
|
|
131
|
-
this[event] = handler;
|
|
132
|
-
});
|
|
133
|
-
this.connection = connection;
|
|
134
|
-
this.name = name;
|
|
135
|
-
this.debug = debug;
|
|
136
|
-
|
|
137
|
-
if (connection) {
|
|
138
|
-
// Init RPCClient
|
|
139
|
-
await this.connectToWallet(connection);
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
|
|
143
|
-
deepProps: {
|
|
144
|
-
Ae: {
|
|
145
|
-
defaults: {
|
|
146
|
-
walletBroadcast: true
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
methods: {
|
|
151
|
-
sign() {},
|
|
152
|
-
|
|
153
|
-
addresses() {
|
|
154
|
-
if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError();
|
|
155
|
-
return [this.rpcClient.currentAccount, ...Object.keys(this.rpcClient.accounts.connected)];
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Connect to wallet
|
|
160
|
-
* @function connectToWallet
|
|
161
|
-
* @instance
|
|
162
|
-
* @rtype (connection: Object) => void
|
|
163
|
-
* @param {Object} connection Wallet connection object
|
|
164
|
-
* @param {Object} [options={}]
|
|
165
|
-
* @param {Boolean} [options.connectNode=true] - Request wallet to bind node
|
|
166
|
-
* @param {String} [options.name=wallet-node] - Node name
|
|
167
|
-
* @param {Boolean} [options.select=false] - Select this node as current
|
|
168
|
-
* @return {Object}
|
|
169
|
-
*/
|
|
170
|
-
async connectToWallet(connection) {
|
|
171
|
-
let {
|
|
172
|
-
connectNode = false,
|
|
173
|
-
name = 'wallet-node',
|
|
174
|
-
select = false
|
|
175
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
176
|
-
if (this.rpcClient && this.rpcClient.isConnected()) throw new AlreadyConnectedError('You are already connected to wallet ' + this.rpcClient);
|
|
177
|
-
this.rpcClient = RpcClient({
|
|
178
|
-
connection,
|
|
179
|
-
networkId: this.getNetworkId({
|
|
180
|
-
force: true
|
|
181
|
-
}),
|
|
182
|
-
...connection.connectionInfo,
|
|
183
|
-
id: uuid(),
|
|
184
|
-
handlers: [handleMessage(this), this.onDisconnect]
|
|
185
|
-
});
|
|
186
|
-
const walletInfo = await this.sendConnectRequest(connectNode);
|
|
187
|
-
|
|
188
|
-
if (connectNode && !Object.prototype.hasOwnProperty.call(walletInfo, 'node')) {
|
|
189
|
-
throw new RpcConnectionError('Missing URLs of the Node');
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
connectNode && this.addNode(name, await Node(walletInfo.node), select);
|
|
193
|
-
return walletInfo;
|
|
194
|
-
},
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Disconnect from wallet
|
|
198
|
-
* @function disconnectWallet
|
|
199
|
-
* @instance
|
|
200
|
-
* @rtype (force: Boolean = false) => void
|
|
201
|
-
* @param {Boolean} sendDisconnect=false Force sending close connection message
|
|
202
|
-
* @return {void}
|
|
203
|
-
*/
|
|
204
|
-
async disconnectWallet() {
|
|
205
|
-
let sendDisconnect = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
206
|
-
if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet');
|
|
207
|
-
sendDisconnect && this.rpcClient.sendMessage(message(METHODS.closeConnection, {
|
|
208
|
-
reason: 'bye'
|
|
209
|
-
}), true);
|
|
210
|
-
this.rpcClient.disconnect();
|
|
211
|
-
this.rpcClient = null;
|
|
212
|
-
},
|
|
213
|
-
|
|
214
|
-
async address() {
|
|
215
|
-
let {
|
|
216
|
-
onAccount
|
|
217
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
218
|
-
if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet');
|
|
219
|
-
const current = this.rpcClient.currentAccount;
|
|
220
|
-
if (!current) throw new UnsubscribedAccountError();
|
|
221
|
-
|
|
222
|
-
if (onAccount && !this.rpcClient.hasAccessToAccount(onAccount)) {
|
|
223
|
-
throw new UnAuthorizedAccountError(onAccount);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return onAccount || current;
|
|
227
|
-
},
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Ask address from wallet
|
|
231
|
-
* @function askAddresses
|
|
232
|
-
* @instance
|
|
233
|
-
* @rtype () => Promise
|
|
234
|
-
* @return {Promise} Address from wallet
|
|
235
|
-
*/
|
|
236
|
-
async askAddresses() {
|
|
237
|
-
if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet');
|
|
238
|
-
if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError();
|
|
239
|
-
return this.rpcClient.request(METHODS.address);
|
|
240
|
-
},
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Subscribe for addresses from wallet
|
|
244
|
-
* @function subscribeAddress
|
|
245
|
-
* @instance
|
|
246
|
-
* @rtype (type: String, value: String) => Promise
|
|
247
|
-
* @param {String} type Should be one of 'current' (the selected account), 'connected' (all)
|
|
248
|
-
* @param {String} value Subscription action('subscribe'|'unsubscribe')
|
|
249
|
-
* @return {Promise} Address from wallet
|
|
250
|
-
*/
|
|
251
|
-
async subscribeAddress(type, value) {
|
|
252
|
-
if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet');
|
|
253
|
-
return this.rpcClient.request(METHODS.subscribeAddress, {
|
|
254
|
-
type,
|
|
255
|
-
value
|
|
256
|
-
});
|
|
257
|
-
},
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Overwriting of `signTransaction` AE method
|
|
261
|
-
* All sdk API which use it will be send notification to wallet and wait for callBack
|
|
262
|
-
* @function signTransaction
|
|
263
|
-
* @instance
|
|
264
|
-
* @rtype (tx: String, options = {}) => Promise
|
|
265
|
-
* @return {Promise<String>} Signed transaction
|
|
266
|
-
*/
|
|
267
|
-
async signTransaction(tx) {
|
|
268
|
-
let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
269
|
-
if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet');
|
|
270
|
-
if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError();
|
|
271
|
-
|
|
272
|
-
if (opt.onAccount && !this.rpcClient.hasAccessToAccount(opt.onAccount)) {
|
|
273
|
-
throw new UnAuthorizedAccountError(opt.onAccount);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
return this.rpcClient.request(METHODS.sign, { ...opt,
|
|
277
|
-
tx,
|
|
278
|
-
returnSigned: true,
|
|
279
|
-
networkId: this.getNetworkId()
|
|
280
|
-
});
|
|
281
|
-
},
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Overwriting of `signMessage` AE method
|
|
285
|
-
* All sdk API which use it will be send notification to wallet and wait for callBack
|
|
286
|
-
* @function signMessage
|
|
287
|
-
* @instance
|
|
288
|
-
* @rtype (msg: String, options = {}) => Promise
|
|
289
|
-
* @return {Promise<String>} Signed transaction
|
|
290
|
-
*/
|
|
291
|
-
async signMessage(msg) {
|
|
292
|
-
let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
293
|
-
if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet');
|
|
294
|
-
if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError();
|
|
295
|
-
|
|
296
|
-
if (opt.onAccount && !this.rpcClient.hasAccessToAccount(opt.onAccount)) {
|
|
297
|
-
throw new UnAuthorizedAccountError(opt.onAccount);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
return this.rpcClient.request(METHODS.signMessage, { ...opt,
|
|
301
|
-
message: msg
|
|
302
|
-
});
|
|
303
|
-
},
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Send connection request to wallet
|
|
307
|
-
* @function sendConnectRequest
|
|
308
|
-
* @instance
|
|
309
|
-
* @param {Boolean} connectNode - Request wallet to bind node
|
|
310
|
-
* @rtype () => Promise
|
|
311
|
-
* @return {Promise} Connection response
|
|
312
|
-
*/
|
|
313
|
-
async sendConnectRequest(connectNode) {
|
|
314
|
-
return this.rpcClient.request(METHODS.connect, {
|
|
315
|
-
name: this.name,
|
|
316
|
-
version: VERSION,
|
|
317
|
-
networkId: this.getNetworkId({
|
|
318
|
-
force: true
|
|
319
|
-
}),
|
|
320
|
-
connectNode
|
|
321
|
-
});
|
|
322
|
-
},
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Overwriting of `send` AE method
|
|
326
|
-
* All sdk API which use it will be send notification to wallet and wait for callBack
|
|
327
|
-
* This method will sign, broadcast and wait until transaction will be accepted using rpc
|
|
328
|
-
* communication with wallet
|
|
329
|
-
* @function send
|
|
330
|
-
* @instance
|
|
331
|
-
* @rtype (tx: String, options = {}) => Promise
|
|
332
|
-
* @param {String} tx
|
|
333
|
-
* @param {Object} [options={}]
|
|
334
|
-
* @param {Object} [options.walletBroadcast=true]
|
|
335
|
-
* @return {Promise<Object>} Transaction broadcast result
|
|
336
|
-
*/
|
|
337
|
-
async send(tx) {
|
|
338
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
339
|
-
if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet');
|
|
340
|
-
if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError();
|
|
341
|
-
|
|
342
|
-
if (options.onAccount && !this.rpcClient.hasAccessToAccount(options.onAccount)) {
|
|
343
|
-
throw new UnAuthorizedAccountError(options.onAccount);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
const opt = { ...this.Ae.defaults,
|
|
347
|
-
...options
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
if (!opt.walletBroadcast) {
|
|
351
|
-
const signed = await this.signTransaction(tx, {
|
|
352
|
-
onAccount: opt.onAccount
|
|
353
|
-
});
|
|
354
|
-
return this.sendTransaction(signed, opt);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
return this.rpcClient.request(METHODS.sign, {
|
|
358
|
-
onAccount: opt.onAccount,
|
|
359
|
-
tx,
|
|
360
|
-
returnSigned: false,
|
|
361
|
-
networkId: this.getNetworkId()
|
|
362
|
-
});
|
|
363
|
-
},
|
|
364
|
-
|
|
365
|
-
isConnected() {
|
|
366
|
-
return this.rpcClient && this.rpcClient.isConnected();
|
|
367
|
-
},
|
|
368
|
-
|
|
369
|
-
isSubscribedAccount() {
|
|
370
|
-
return typeof this.rpcClient.currentAccount !== 'undefined';
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
}
|
|
374
|
-
});
|
|
375
|
-
//# sourceMappingURL=aepp-rpc.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utils/aepp-wallet-communication/rpc/aepp-rpc.js"],"names":["v4","uuid","Ae","RpcClient","getHandler","message","METHODS","RPC_STATUS","VERSION","AlreadyConnectedError","NoWalletConnectedError","UnsubscribedAccountError","UnAuthorizedAccountError","ArgumentError","RpcConnectionError","Node","NOTIFICATIONS","updateAddress","instance","params","rpcClient","accounts","onAddressChange","updateNetwork","networkId","node","info","addNode","name","onNetworkChange","closeConnection","msg","disconnectWallet","onDisconnect","RESPONSES","address","processResponse","connect","result","status","CONNECTED","subscribeAddress","subscription","addressSubscription","id","sign","signedTransaction","transactionHash","signMessage","signature","REQUESTS","handleMessage","debug","Object","prototype","hasOwnProperty","call","callbacks","compose","init","connection","other","forEach","event","handler","connectToWallet","deepProps","defaults","walletBroadcast","methods","addresses","isSubscribedAccount","currentAccount","keys","connected","connectNode","select","isConnected","getNetworkId","force","connectionInfo","handlers","walletInfo","sendConnectRequest","sendDisconnect","sendMessage","reason","disconnect","onAccount","current","hasAccessToAccount","askAddresses","request","type","value","signTransaction","tx","opt","returnSigned","version","send","options","signed","sendTransaction"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,EAAE,IAAIC,IAAf,QAA2B,iBAA3B;OACOC,E;OACAC,S;SACEC,U,EAAYC,O;SACZC,O,EAASC,U,EAAYC,O;SAE5BC,qB,EACAC,sB,EACAC,wB,EACAC,wB,EACAC,a,EACAC,kB;OAEKC,I;AAEP,MAAMC,aAAa,GAAG;AACpB,GAACV,OAAO,CAACW,aAAT,GAA0BC,QAAD,IACvB,QAAgB;AAAA,QAAf;AAAEC,MAAAA;AAAF,KAAe;AACdD,IAAAA,QAAQ,CAACE,SAAT,CAAmBC,QAAnB,GAA8BF,MAA9B;AACAD,IAAAA,QAAQ,CAACI,eAAT,CAAyBH,MAAzB;AACD,GALiB;AAMpB,GAACb,OAAO,CAACiB,aAAT,GAA0BL,QAAD,IACvB,eAAsB;AAAA,QAAf;AAAEC,MAAAA;AAAF,KAAe;AACpB,UAAM;AAAEK,MAAAA,SAAF;AAAaC,MAAAA;AAAb,QAAsBN,MAA5B;AACAD,IAAAA,QAAQ,CAACE,SAAT,CAAmBM,IAAnB,CAAwBF,SAAxB,GAAoCA,SAApC;AACAC,IAAAA,IAAI,I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AAN;AACzB,UAAI,CAAC,KAAK6D,mBAAL,EAAL,EAAiC,MAAM,IAAI5D,wBAAJ,EAAN;;AACjC,UAAI0F,OAAO,CAACb,SAAR,IAAqB,CAAC,KAAKpE,SAAL,CAAesE,kBAAf,CAAkCW,OAAO,CAACb,SAA1C,CAA1B,EAAgF;AAC9E,cAAM,IAAI5E,wBAAJ,CAA6ByF,OAAO,CAACb,SAArC,CAAN;AACD;;AACD,YAAMS,GAAG,GAAG,EAAE,GAAG,KAAK/F,EAAL,CAAQiE,QAAb;AAAuB,WAAGkC;AAA1B,OAAZ;;AACA,UAAI,CAACJ,GAAG,CAAC7B,eAAT,EAA0B;AACxB,cAAMkC,MAAM,GAAG,MAAM,KAAKP,eAAL,CAAqBC,EAArB,EAAyB;AAAER,UAAAA,SAAS,EAAES,GAAG,CAACT;AAAjB,SAAzB,CAArB;AACA,eAAO,KAAKe,eAAL,CAAqBD,MAArB,EAA6BL,GAA7B,CAAP;AACD;;AACD,aAAO,KAAK7E,SAAL,CAAewE,OAAf,CACLtF,OAAO,CAACuC,IADH,EAEL;AAAE2C,QAAAA,SAAS,EAAES,GAAG,CAACT,SAAjB;AAA4BQ,QAAAA,EAA5B;AAAgCE,QAAAA,YAAY,EAAE,KAA9C;AAAqD1E,QAAAA,SAAS,EAAE,KAAKsD,YAAL;AAAhE,OAFK,CAAP;AAID,KApKM;;AAqKPD,IAAAA,WAAW,GAAI;AAAE,aAAQ,KAAKzD,SAAL,IAAkB,KAAKA,SAAL,CAAeyD,WAAf,EAA1B;AAAyD,KArKnE;;AAsKPN,IAAAA,mBAAmB,GAAI;AAAE,aAAO,OAAO,KAAKnD,SAAL,CAAeoD,cAAtB,KAAyC,WAAhD;AAA6D;;AAtK/E;AAvBe,CAAX,CAAf","sourcesContent":["/**\n * RPC handler for AEPP side\n *\n * @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc\n * @export AeppRpc\n * @example\n * import ContentScriptBridge\n * from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc'\n */\nimport { v4 as uuid } from '@aeternity/uuid'\nimport Ae from '../../../ae'\nimport RpcClient from './rpc-client'\nimport { getHandler, message } from '../helpers'\nimport { METHODS, RPC_STATUS, VERSION } from '../schema'\nimport {\n AlreadyConnectedError,\n NoWalletConnectedError,\n UnsubscribedAccountError,\n UnAuthorizedAccountError,\n ArgumentError,\n RpcConnectionError\n} from '../../errors'\nimport Node from '../../../node'\n\nconst NOTIFICATIONS = {\n [METHODS.updateAddress]: (instance) =>\n ({ params }) => {\n instance.rpcClient.accounts = params\n instance.onAddressChange(params)\n },\n [METHODS.updateNetwork]: (instance) =>\n async ({ params }) => {\n const { networkId, node } = params\n instance.rpcClient.info.networkId = networkId\n node && instance.addNode(node.name, await Node(node), true)\n instance.onNetworkChange(params)\n },\n [METHODS.closeConnection]: (instance) =>\n (msg) => {\n instance.disconnectWallet()\n instance.onDisconnect(msg.params)\n }\n}\n\nconst RESPONSES = {\n [METHODS.address]: (instance) =>\n (msg) => instance.rpcClient.processResponse(msg),\n [METHODS.connect]: (instance) =>\n (msg) => {\n if (msg.result) instance.rpcClient.info.status = RPC_STATUS.CONNECTED\n instance.rpcClient.processResponse(msg)\n },\n [METHODS.subscribeAddress]: (instance) =>\n (msg) => {\n if (msg.result) {\n if (msg.result.address) {\n instance.rpcClient.accounts = msg.result.address\n }\n if (msg.result.subscription) {\n instance.rpcClient.addressSubscription = msg.result.subscription\n }\n }\n\n instance.rpcClient.processResponse(msg, ({ id, result }) => [result])\n },\n [METHODS.sign]: (instance) =>\n (msg) => {\n instance.rpcClient.processResponse(\n msg, ({ id, result }) => [result.signedTransaction || result.transactionHash]\n )\n },\n [METHODS.signMessage]: (instance) =>\n (msg) => {\n instance.rpcClient.processResponse(msg, ({ id, result }) => [result.signature])\n }\n}\n\nconst REQUESTS = {}\n\nconst handleMessage = (instance) => async (msg) => {\n if (!msg.id) {\n return getHandler(NOTIFICATIONS, msg, { debug: instance.debug })(instance)(msg)\n } else if (Object.prototype.hasOwnProperty.call(instance.rpcClient.callbacks, msg.id)) {\n return getHandler(RESPONSES, msg, { debug: instance.debug })(instance)(msg)\n } else {\n return getHandler(REQUESTS, msg, { debug: instance.debug })(instance)(msg)\n }\n}\n\n/**\n * Contain functionality for wallet interaction and connect it to sdk\n * @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc\n * @function\n * @rtype Stamp\n * @param {Object} param Init params object\n * @param {String=} [param.name] Aepp name\n * @param {Function} onAddressChange Call-back function for update address event\n * @param {Function} onDisconnect Call-back function for disconnect event\n * @param {Function} onNetworkChange Call-back function for update network event\n * @param {Object} connection Wallet connection object\n * @return {Object}\n */\nexport default Ae.compose({\n async init ({\n name,\n connection,\n debug = false,\n ...other\n }) {\n ['onAddressChange', 'onDisconnect', 'onNetworkChange'].forEach(event => {\n const handler = other[event] ?? (() => {})\n if (typeof handler !== 'function') throw new ArgumentError(event, 'a function', handler)\n this[event] = handler\n })\n\n this.connection = connection\n this.name = name\n this.debug = debug\n\n if (connection) {\n // Init RPCClient\n await this.connectToWallet(connection)\n }\n },\n deepProps: { Ae: { defaults: { walletBroadcast: true } } },\n methods: {\n sign () {\n },\n addresses () {\n if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError()\n return [this.rpcClient.currentAccount, ...Object.keys(this.rpcClient.accounts.connected)]\n },\n /**\n * Connect to wallet\n * @function connectToWallet\n * @instance\n * @rtype (connection: Object) => void\n * @param {Object} connection Wallet connection object\n * @param {Object} [options={}]\n * @param {Boolean} [options.connectNode=true] - Request wallet to bind node\n * @param {String} [options.name=wallet-node] - Node name\n * @param {Boolean} [options.select=false] - Select this node as current\n * @return {Object}\n */\n async connectToWallet (connection, { connectNode = false, name = 'wallet-node', select = false } = {}) {\n if (this.rpcClient && this.rpcClient.isConnected()) throw new AlreadyConnectedError('You are already connected to wallet ' + this.rpcClient)\n this.rpcClient = RpcClient({\n connection,\n networkId: this.getNetworkId({ force: true }),\n ...connection.connectionInfo,\n id: uuid(),\n handlers: [handleMessage(this), this.onDisconnect]\n })\n const walletInfo = await this.sendConnectRequest(connectNode)\n if (connectNode && !Object.prototype.hasOwnProperty.call(walletInfo, 'node')) {\n throw new RpcConnectionError('Missing URLs of the Node')\n }\n connectNode && this.addNode(name, await Node(walletInfo.node), select)\n return walletInfo\n },\n /**\n * Disconnect from wallet\n * @function disconnectWallet\n * @instance\n * @rtype (force: Boolean = false) => void\n * @param {Boolean} sendDisconnect=false Force sending close connection message\n * @return {void}\n */\n async disconnectWallet (sendDisconnect = true) {\n if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')\n sendDisconnect && this.rpcClient.sendMessage(message(METHODS.closeConnection, { reason: 'bye' }), true)\n this.rpcClient.disconnect()\n this.rpcClient = null\n },\n async address ({ onAccount } = {}) {\n if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')\n const current = this.rpcClient.currentAccount\n if (!current) throw new UnsubscribedAccountError()\n if (onAccount && !this.rpcClient.hasAccessToAccount(onAccount)) {\n throw new UnAuthorizedAccountError(onAccount)\n }\n return onAccount || current\n },\n /**\n * Ask address from wallet\n * @function askAddresses\n * @instance\n * @rtype () => Promise\n * @return {Promise} Address from wallet\n */\n async askAddresses () {\n if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')\n if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError()\n return this.rpcClient.request(METHODS.address)\n },\n /**\n * Subscribe for addresses from wallet\n * @function subscribeAddress\n * @instance\n * @rtype (type: String, value: String) => Promise\n * @param {String} type Should be one of 'current' (the selected account), 'connected' (all)\n * @param {String} value Subscription action('subscribe'|'unsubscribe')\n * @return {Promise} Address from wallet\n */\n async subscribeAddress (type, value) {\n if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')\n return this.rpcClient.request(METHODS.subscribeAddress, { type, value })\n },\n /**\n * Overwriting of `signTransaction` AE method\n * All sdk API which use it will be send notification to wallet and wait for callBack\n * @function signTransaction\n * @instance\n * @rtype (tx: String, options = {}) => Promise\n * @return {Promise<String>} Signed transaction\n */\n async signTransaction (tx, opt = {}) {\n if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')\n if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError()\n if (opt.onAccount && !this.rpcClient.hasAccessToAccount(opt.onAccount)) {\n throw new UnAuthorizedAccountError(opt.onAccount)\n }\n return this.rpcClient.request(\n METHODS.sign,\n { ...opt, tx, returnSigned: true, networkId: this.getNetworkId() }\n )\n },\n /**\n * Overwriting of `signMessage` AE method\n * All sdk API which use it will be send notification to wallet and wait for callBack\n * @function signMessage\n * @instance\n * @rtype (msg: String, options = {}) => Promise\n * @return {Promise<String>} Signed transaction\n */\n async signMessage (msg, opt = {}) {\n if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')\n if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError()\n if (opt.onAccount && !this.rpcClient.hasAccessToAccount(opt.onAccount)) {\n throw new UnAuthorizedAccountError(opt.onAccount)\n }\n return this.rpcClient.request(METHODS.signMessage, { ...opt, message: msg })\n },\n /**\n * Send connection request to wallet\n * @function sendConnectRequest\n * @instance\n * @param {Boolean} connectNode - Request wallet to bind node\n * @rtype () => Promise\n * @return {Promise} Connection response\n */\n async sendConnectRequest (connectNode) {\n return this.rpcClient.request(\n METHODS.connect, {\n name: this.name,\n version: VERSION,\n networkId: this.getNetworkId({ force: true }),\n connectNode\n }\n )\n },\n /**\n * Overwriting of `send` AE method\n * All sdk API which use it will be send notification to wallet and wait for callBack\n * This method will sign, broadcast and wait until transaction will be accepted using rpc\n * communication with wallet\n * @function send\n * @instance\n * @rtype (tx: String, options = {}) => Promise\n * @param {String} tx\n * @param {Object} [options={}]\n * @param {Object} [options.walletBroadcast=true]\n * @return {Promise<Object>} Transaction broadcast result\n */\n async send (tx, options = {}) {\n if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')\n if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError()\n if (options.onAccount && !this.rpcClient.hasAccessToAccount(options.onAccount)) {\n throw new UnAuthorizedAccountError(options.onAccount)\n }\n const opt = { ...this.Ae.defaults, ...options }\n if (!opt.walletBroadcast) {\n const signed = await this.signTransaction(tx, { onAccount: opt.onAccount })\n return this.sendTransaction(signed, opt)\n }\n return this.rpcClient.request(\n METHODS.sign,\n { onAccount: opt.onAccount, tx, returnSigned: false, networkId: this.getNetworkId() }\n )\n },\n isConnected () { return (this.rpcClient && this.rpcClient.isConnected()) },\n isSubscribedAccount () { return typeof this.rpcClient.currentAccount !== 'undefined' }\n }\n})\n"],"file":"aepp-rpc.mjs"}
|