@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/aens.mjs
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ISC License (ISC)
|
|
3
|
+
* Copyright (c) 2022 aeternity developers
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
|
8
|
+
*
|
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Aens methods - routines to interact with the æternity naming system
|
|
20
|
+
*
|
|
21
|
+
* The high-level description of the naming system is
|
|
22
|
+
* https://github.com/aeternity/protocol/blob/master/AENS.md in the protocol
|
|
23
|
+
* repository.
|
|
24
|
+
*/
|
|
25
|
+
import { salt } from "./utils/crypto.mjs";
|
|
26
|
+
import { commitmentHash, isAuctionName } from "./tx/builder/helpers.mjs";
|
|
27
|
+
import { CLIENT_TTL, NAME_TTL, TX_TYPE } from "./tx/builder/schema.mjs";
|
|
28
|
+
import { ArgumentError } from "./utils/errors.mjs";
|
|
29
|
+
import { send } from "./spend.mjs";
|
|
30
|
+
import { getName, height } from "./chain.mjs";
|
|
31
|
+
import { _buildTx } from "./tx/index.mjs";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Revoke a name
|
|
35
|
+
* @param name - Name hash
|
|
36
|
+
* @param options - Options
|
|
37
|
+
* @param options.onAccount - Make operation on specific account from sdk (you pass
|
|
38
|
+
* publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
|
|
39
|
+
* @param options.fee - fee
|
|
40
|
+
* @param options.ttl - ttl
|
|
41
|
+
* @param options.nonce - nonce
|
|
42
|
+
* @returns Transaction result
|
|
43
|
+
* @example
|
|
44
|
+
* ```js
|
|
45
|
+
* const name = 'test.chain'
|
|
46
|
+
* const nameObject = await sdkInstance.aensQuery(name)
|
|
47
|
+
*
|
|
48
|
+
* await sdkInstance.aensRevoke(name, { fee, ttl , nonce })
|
|
49
|
+
* // or
|
|
50
|
+
* await nameObject.revoke({ fee, ttl, nonce })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export async function aensRevoke(name, options) {
|
|
54
|
+
const nameRevokeTx = await _buildTx(TX_TYPE.nameRevoke, { ...options,
|
|
55
|
+
nameId: name,
|
|
56
|
+
accountId: await options.onAccount.address(options)
|
|
57
|
+
});
|
|
58
|
+
return await send(nameRevokeTx, options);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Update a name
|
|
63
|
+
* @param name - AENS name
|
|
64
|
+
* @param pointers - Map of pointer keys to corresponding addresses
|
|
65
|
+
* @param options - Options
|
|
66
|
+
* @param options.extendPointers - Get the pointers from the node and merge with provided
|
|
67
|
+
* ones. Pointers with the same type will be overwritten
|
|
68
|
+
* @param options.onAccount - Make operation on specific account from sdk (you
|
|
69
|
+
* pass publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
|
|
70
|
+
* @param options.fee - fee
|
|
71
|
+
* @param options.ttl - ttl
|
|
72
|
+
* @param options.nonce - nonce
|
|
73
|
+
* @param options.nameTtl - Name ttl represented in number of
|
|
74
|
+
* blocks (Max value is 50000 blocks)
|
|
75
|
+
* @param options.clientTtl=84600 a suggestion as to how long any
|
|
76
|
+
* clients should cache this information
|
|
77
|
+
* @throws Invalid pointer array error
|
|
78
|
+
* @example
|
|
79
|
+
* ```js
|
|
80
|
+
* const name = 'test.chain'
|
|
81
|
+
* const pointersArray = ['ak_asd23dasdas...,' 'ct_asdf34fasdasd...']
|
|
82
|
+
* const nameObject = await sdkInstance.aensQuery(name)
|
|
83
|
+
*
|
|
84
|
+
* await sdkInstance.aensUpdate(name, pointersArray, { nameTtl, ttl, fee, nonce, clientTtl })
|
|
85
|
+
* // or
|
|
86
|
+
* await nameObject.update(pointers, { nameTtl, ttl, fee, nonce, clientTtl })
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export async function aensUpdate(name, pointers, _ref) {
|
|
90
|
+
let {
|
|
91
|
+
extendPointers,
|
|
92
|
+
...options
|
|
93
|
+
} = _ref;
|
|
94
|
+
const allPointers = { ...(extendPointers === true && Object.fromEntries((await getName(name, options)).pointers.map(_ref2 => {
|
|
95
|
+
let {
|
|
96
|
+
key,
|
|
97
|
+
id
|
|
98
|
+
} = _ref2;
|
|
99
|
+
return [key, id];
|
|
100
|
+
}))),
|
|
101
|
+
...pointers
|
|
102
|
+
};
|
|
103
|
+
const nameUpdateTx = await _buildTx(TX_TYPE.nameUpdate, {
|
|
104
|
+
clientTtl: CLIENT_TTL,
|
|
105
|
+
nameTtl: NAME_TTL,
|
|
106
|
+
...options,
|
|
107
|
+
nameId: name,
|
|
108
|
+
accountId: await options.onAccount.address(options),
|
|
109
|
+
pointers: Object.entries(allPointers).map(_ref3 => {
|
|
110
|
+
let [key, id] = _ref3;
|
|
111
|
+
return {
|
|
112
|
+
key,
|
|
113
|
+
id: id.toString()
|
|
114
|
+
};
|
|
115
|
+
})
|
|
116
|
+
});
|
|
117
|
+
return await send(nameUpdateTx, options);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Transfer a domain to another account
|
|
122
|
+
* @param name - AENS name
|
|
123
|
+
* @param account - Recipient account publick key
|
|
124
|
+
* @param options - Options
|
|
125
|
+
* @param options.onAccount - Make operation on specific account from sdk (you pass
|
|
126
|
+
* publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
|
|
127
|
+
* @param options.fee - fee
|
|
128
|
+
* @param options.ttl - ttl
|
|
129
|
+
* @param options.nonce - nonce
|
|
130
|
+
* @returns Transaction result
|
|
131
|
+
* @example
|
|
132
|
+
* ```js
|
|
133
|
+
* const name = 'test.chain'
|
|
134
|
+
* const recipientPub = 'ak_asd23dasdas...'
|
|
135
|
+
* const nameObject = await sdkInstance.aensQuery(name)
|
|
136
|
+
*
|
|
137
|
+
* await sdkInstance.aensTransfer(name, recipientPub, { ttl, fee, nonce })
|
|
138
|
+
* // or
|
|
139
|
+
* await nameObject.transfer(recipientPub, { ttl, fee, nonce })
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export async function aensTransfer(name, account, options) {
|
|
143
|
+
const nameTransferTx = await _buildTx(TX_TYPE.nameTransfer, { ...options,
|
|
144
|
+
nameId: name,
|
|
145
|
+
accountId: await options.onAccount.address(options),
|
|
146
|
+
recipientId: account
|
|
147
|
+
});
|
|
148
|
+
return await send(nameTransferTx, options);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Query the AENS name info from the node
|
|
153
|
+
* and return the object with info and predefined functions for manipulating name
|
|
154
|
+
* @param name - AENS name
|
|
155
|
+
* @param opt - Options
|
|
156
|
+
* @returns
|
|
157
|
+
* @example
|
|
158
|
+
* ```js
|
|
159
|
+
* const nameObject = sdkInstance.aensQuery('test.chain')
|
|
160
|
+
* console.log(nameObject)
|
|
161
|
+
* {
|
|
162
|
+
* id, // name hash
|
|
163
|
+
* pointers, // array of pointers
|
|
164
|
+
* update, // Update name function
|
|
165
|
+
* extendTtl, // Extend Ttl name function
|
|
166
|
+
* transfer, // Transfer name function
|
|
167
|
+
* revoke // Revoke name function
|
|
168
|
+
* }
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
export async function aensQuery(name, opt) {
|
|
172
|
+
const nameEntry = await getName(name, opt);
|
|
173
|
+
return Object.freeze({ ...nameEntry,
|
|
174
|
+
id: nameEntry.id,
|
|
175
|
+
owner: nameEntry.owner,
|
|
176
|
+
|
|
177
|
+
async update(pointers, options) {
|
|
178
|
+
return { ...(await aensUpdate(name, pointers, { ...opt,
|
|
179
|
+
...options
|
|
180
|
+
})),
|
|
181
|
+
...(await aensQuery(name, { ...opt,
|
|
182
|
+
...options
|
|
183
|
+
}))
|
|
184
|
+
};
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
async transfer(account, options) {
|
|
188
|
+
return { ...(await aensTransfer(name, account, { ...opt,
|
|
189
|
+
...options
|
|
190
|
+
})),
|
|
191
|
+
...(await aensQuery(name, { ...opt,
|
|
192
|
+
...options
|
|
193
|
+
}))
|
|
194
|
+
};
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
async revoke(options) {
|
|
198
|
+
return await aensRevoke(name, { ...opt,
|
|
199
|
+
...options
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
|
|
203
|
+
async extendTtl() {
|
|
204
|
+
let nameTtl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : NAME_TTL;
|
|
205
|
+
let options = arguments.length > 1 ? arguments[1] : undefined;
|
|
206
|
+
|
|
207
|
+
if (nameTtl > NAME_TTL || nameTtl <= 0) {
|
|
208
|
+
throw new ArgumentError('nameTtl', `a number between 1 and ${NAME_TTL} blocks`, nameTtl);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return { ...(await aensUpdate(name, {}, { ...opt,
|
|
212
|
+
...options,
|
|
213
|
+
nameTtl,
|
|
214
|
+
extendPointers: true
|
|
215
|
+
})),
|
|
216
|
+
...(await aensQuery(name, { ...opt,
|
|
217
|
+
...options
|
|
218
|
+
}))
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Claim a previously preclaimed registration. This can only be done after the
|
|
226
|
+
* preclaim step
|
|
227
|
+
* @param name - AENS name
|
|
228
|
+
* @param salt - Salt from pre-claim, or 0 if it's a bid
|
|
229
|
+
* @param options - options
|
|
230
|
+
* @param options.onAccount - Make operation on specific account from sdk (you pass
|
|
231
|
+
* publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
|
|
232
|
+
* @param options.fee - fee
|
|
233
|
+
* @param options.ttl - ttl
|
|
234
|
+
* @param options.nonce - nonce
|
|
235
|
+
* @param options.nameFee - Name Fee (By default calculated by sdk)
|
|
236
|
+
* @returns the result of the claim
|
|
237
|
+
* @example
|
|
238
|
+
* ```js
|
|
239
|
+
* const name = 'test.chain'
|
|
240
|
+
* const salt = preclaimResult.salt // salt from pre-claim transaction
|
|
241
|
+
*
|
|
242
|
+
* await sdkInstance.aensClaim(name, salt, { ttl, fee, nonce, nameFee })
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
|
|
246
|
+
export async function aensClaim(name, salt, options) {
|
|
247
|
+
const claimTx = await _buildTx(TX_TYPE.nameClaim, { ...options,
|
|
248
|
+
accountId: await options.onAccount.address(options),
|
|
249
|
+
nameSalt: salt,
|
|
250
|
+
name
|
|
251
|
+
});
|
|
252
|
+
const result = await send(claimTx, options);
|
|
253
|
+
|
|
254
|
+
if (!isAuctionName(name)) {
|
|
255
|
+
const nameInter = result.blockHeight != null && result.blockHeight > 0 ? await aensQuery(name, options) : {};
|
|
256
|
+
return Object.assign(result, nameInter);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Preclaim a name. Sends a hash of the name and a random salt to the node
|
|
264
|
+
* @param name - AENS name
|
|
265
|
+
* @param options - Options
|
|
266
|
+
* @param options.onAccount - Make operation on specific account from sdk (you pass
|
|
267
|
+
* publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
|
|
268
|
+
* @param options.fee - fee
|
|
269
|
+
* @param options.ttl - ttl
|
|
270
|
+
* @param options.nonce - nonce
|
|
271
|
+
* @example
|
|
272
|
+
* ```js
|
|
273
|
+
* const name = 'test.chain'
|
|
274
|
+
* const salt = preclaimResult.salt // salt from pre-claim transaction
|
|
275
|
+
*
|
|
276
|
+
* await sdkInstance.aensPreclaim(name, { ttl, fee, nonce })
|
|
277
|
+
* {
|
|
278
|
+
* ...transactionResult,
|
|
279
|
+
* claim, // Claim function (options={}) => claimTransactionResult
|
|
280
|
+
* salt,
|
|
281
|
+
* commitmentId
|
|
282
|
+
* }
|
|
283
|
+
* ```
|
|
284
|
+
*/
|
|
285
|
+
export async function aensPreclaim(name, options) {
|
|
286
|
+
const _salt = salt();
|
|
287
|
+
|
|
288
|
+
const currentHeight = await height(options);
|
|
289
|
+
const commitmentId = commitmentHash(name, _salt);
|
|
290
|
+
const preclaimTx = await _buildTx(TX_TYPE.namePreClaim, { ...options,
|
|
291
|
+
accountId: await options.onAccount.address(options),
|
|
292
|
+
commitmentId
|
|
293
|
+
});
|
|
294
|
+
return Object.freeze({ ...(await send(preclaimTx, options)),
|
|
295
|
+
height: currentHeight,
|
|
296
|
+
salt: _salt,
|
|
297
|
+
commitmentId,
|
|
298
|
+
|
|
299
|
+
async claim(opts) {
|
|
300
|
+
return await aensClaim(name, _salt, { ...options,
|
|
301
|
+
...opts
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Bid to name auction
|
|
310
|
+
* @param name - Domain name
|
|
311
|
+
* @param nameFee - Name fee (bid fee)
|
|
312
|
+
* @param options - Options
|
|
313
|
+
* @param options.onAccount - Make operation on specific account from sdk (you pass
|
|
314
|
+
* publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
|
|
315
|
+
* @param options.fee - fee
|
|
316
|
+
* @param options.ttl - ttl
|
|
317
|
+
* @param options.nonce - nonce
|
|
318
|
+
* @returns Transaction result
|
|
319
|
+
* @example
|
|
320
|
+
* ```js
|
|
321
|
+
* const name = 'test.chain'
|
|
322
|
+
* const bidFee = computeBidFee(name, startFee, incrementPercentage)
|
|
323
|
+
*
|
|
324
|
+
* await sdkInstance.aensBid(name, 213109412839123, { ttl, fee, nonce })
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
327
|
+
export async function aensBid(name, nameFee, options) {
|
|
328
|
+
return await aensClaim(name, 0, { ...options,
|
|
329
|
+
nameFee
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
//# sourceMappingURL=aens.mjs.map
|
package/es/aens.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aens.mjs","names":["salt","commitmentHash","isAuctionName","CLIENT_TTL","NAME_TTL","TX_TYPE","ArgumentError","send","getName","height","_buildTx","aensRevoke","name","options","nameRevokeTx","nameRevoke","nameId","accountId","onAccount","address","aensUpdate","pointers","extendPointers","allPointers","Object","fromEntries","map","key","id","nameUpdateTx","nameUpdate","clientTtl","nameTtl","entries","toString","aensTransfer","account","nameTransferTx","nameTransfer","recipientId","aensQuery","opt","nameEntry","freeze","owner","update","transfer","revoke","extendTtl","aensClaim","claimTx","nameClaim","nameSalt","result","nameInter","blockHeight","assign","aensPreclaim","_salt","currentHeight","commitmentId","preclaimTx","namePreClaim","claim","opts","aensBid","nameFee"],"sources":["../src/aens.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2022 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 * Aens methods - routines to interact with the æternity naming system\n *\n * The high-level description of the naming system is\n * https://github.com/aeternity/protocol/blob/master/AENS.md in the protocol\n * repository.\n */\n\nimport { salt } from './utils/crypto'\nimport { commitmentHash, isAuctionName, Pointer } from './tx/builder/helpers'\nimport { CLIENT_TTL, NAME_TTL, TX_TYPE, AensName } from './tx/builder/schema'\nimport { ArgumentError } from './utils/errors'\nimport { EncodedData } from './utils/encoder'\nimport BigNumber from 'bignumber.js'\nimport { send, SendOptions } from './spend'\nimport { getName, height } from './chain'\nimport { _buildTx, BuildTxOptions } from './tx'\nimport { TransformNodeType } from './Node'\nimport { NameEntry } from './apis/node'\nimport AccountBase from './account/Base'\n\ninterface KeyPointers {\n [key: string]: string | Buffer\n}\n\n/**\n * Revoke a name\n * @param name - Name hash\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @returns Transaction result\n * @example\n * ```js\n * const name = 'test.chain'\n * const nameObject = await sdkInstance.aensQuery(name)\n *\n * await sdkInstance.aensRevoke(name, { fee, ttl , nonce })\n * // or\n * await nameObject.revoke({ fee, ttl, nonce })\n * ```\n */\nexport async function aensRevoke (\n name: AensName, options: AensRevokeOptions\n): ReturnType<typeof send> {\n const nameRevokeTx = await _buildTx(TX_TYPE.nameRevoke, {\n ...options,\n nameId: name,\n accountId: await options.onAccount.address(options)\n })\n return await send(nameRevokeTx, options)\n}\n\ninterface AensRevokeOptions extends\n BuildTxOptions<TX_TYPE.nameRevoke, 'nameId' | 'accountId'>,\n SendOptions {}\n\n/**\n * Update a name\n * @param name - AENS name\n * @param pointers - Map of pointer keys to corresponding addresses\n * @param options - Options\n * @param options.extendPointers - Get the pointers from the node and merge with provided\n * ones. Pointers with the same type will be overwritten\n * @param options.onAccount - Make operation on specific account from sdk (you\n * pass publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @param options.nameTtl - Name ttl represented in number of\n * blocks (Max value is 50000 blocks)\n * @param options.clientTtl=84600 a suggestion as to how long any\n * clients should cache this information\n * @throws Invalid pointer array error\n * @example\n * ```js\n * const name = 'test.chain'\n * const pointersArray = ['ak_asd23dasdas...,' 'ct_asdf34fasdasd...']\n * const nameObject = await sdkInstance.aensQuery(name)\n *\n * await sdkInstance.aensUpdate(name, pointersArray, { nameTtl, ttl, fee, nonce, clientTtl })\n * // or\n * await nameObject.update(pointers, { nameTtl, ttl, fee, nonce, clientTtl })\n * ```\n */\nexport async function aensUpdate (\n name: AensName, pointers: KeyPointers, { extendPointers, ...options }: AensUpdateOptions\n): ReturnType<typeof send> {\n const allPointers = {\n ...extendPointers === true && Object.fromEntries(\n (await getName(name, options)).pointers\n .map(({ key, id }: { key: string, id: string }) => [key, id])\n ),\n ...pointers\n }\n\n const nameUpdateTx = await _buildTx(TX_TYPE.nameUpdate, {\n clientTtl: CLIENT_TTL,\n nameTtl: NAME_TTL,\n ...options,\n nameId: name,\n accountId: await options.onAccount.address(options),\n pointers: Object.entries(allPointers).map(([key, id]) => ({ key, id: id.toString() }))\n })\n\n return await send(nameUpdateTx, options)\n}\n\ninterface AensUpdateOptions extends\n BuildTxOptions<TX_TYPE.nameUpdate, 'nameId' | 'accountId' | 'pointers' | 'clientTtl' | 'nameTtl'>,\n SendOptions {\n extendPointers?: boolean\n clientTtl?: number\n nameTtl?: number\n}\n\n/**\n * Transfer a domain to another account\n * @param name - AENS name\n * @param account - Recipient account publick key\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @returns Transaction result\n * @example\n * ```js\n * const name = 'test.chain'\n * const recipientPub = 'ak_asd23dasdas...'\n * const nameObject = await sdkInstance.aensQuery(name)\n *\n * await sdkInstance.aensTransfer(name, recipientPub, { ttl, fee, nonce })\n * // or\n * await nameObject.transfer(recipientPub, { ttl, fee, nonce })\n * ```\n */\nexport async function aensTransfer (\n name: AensName, account: EncodedData<'ak'>, options: AensTransferOptions\n): ReturnType<typeof send> {\n const nameTransferTx = await _buildTx(TX_TYPE.nameTransfer, {\n ...options,\n nameId: name,\n accountId: await options.onAccount.address(options),\n recipientId: account\n })\n\n return await send(nameTransferTx, options)\n}\n\ninterface AensTransferOptions extends\n BuildTxOptions<TX_TYPE.nameTransfer, 'nameId' | 'accountId' | 'recipientId'>,\n SendOptions {}\n\n/**\n * Query the AENS name info from the node\n * and return the object with info and predefined functions for manipulating name\n * @param name - AENS name\n * @param opt - Options\n * @returns\n * @example\n * ```js\n * const nameObject = sdkInstance.aensQuery('test.chain')\n * console.log(nameObject)\n * {\n * id, // name hash\n * pointers, // array of pointers\n * update, // Update name function\n * extendTtl, // Extend Ttl name function\n * transfer, // Transfer name function\n * revoke // Revoke name function\n * }\n * ```\n */\nexport async function aensQuery (\n name: AensName,\n opt: Parameters<typeof getName>[1] & Parameters<typeof aensUpdate>[2]\n & Parameters<typeof aensTransfer>[2]\n): Promise<Readonly<\n TransformNodeType<NameEntry> & {\n id: EncodedData<'nm'>\n owner: EncodedData<'ak'>\n pointers: KeyPointers | Pointer[]\n ttl: number\n update: (\n pointers: KeyPointers,\n options?: Omit<Parameters<typeof aensQuery>[1], 'onNode' | 'onCompiler' | 'onAccount'> & {\n onAccount?: AccountBase\n }\n ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>\n transfer: (\n account: EncodedData<'ak'>,\n options?: Parameters<typeof aensQuery>[1]\n ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>\n revoke: (options?: Omit<Parameters<typeof aensRevoke>[1], 'onNode' | 'onCompiler' | 'onAccount'> & {\n onAccount?: AccountBase\n }\n ) => ReturnType<typeof aensRevoke>\n extendTtl: (\n nameTtl: number,\n options?: Omit<Parameters<typeof aensQuery>[1], 'onNode' | 'onCompiler' | 'onAccount'>\n ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>\n }\n >> {\n const nameEntry = await getName(name, opt)\n return Object.freeze({\n ...nameEntry,\n id: nameEntry.id as EncodedData<'nm'>,\n owner: nameEntry.owner as EncodedData<'ak'>,\n async update (pointers, options) {\n return {\n ...await aensUpdate(name, pointers, { ...opt, ...options }),\n ...await aensQuery(name, { ...opt, ...options })\n }\n },\n async transfer (account, options) {\n return {\n ...await aensTransfer(name, account, { ...opt, ...options }),\n ...await aensQuery(name, { ...opt, ...options })\n }\n },\n async revoke (options) {\n return await aensRevoke(name, { ...opt, ...options })\n },\n async extendTtl (nameTtl = NAME_TTL, options) {\n if (nameTtl > NAME_TTL || nameTtl <= 0) {\n throw new ArgumentError('nameTtl', `a number between 1 and ${NAME_TTL} blocks`, nameTtl)\n }\n\n return {\n ...await aensUpdate(name, {}, { ...opt, ...options, nameTtl, extendPointers: true }),\n ...await aensQuery(name, { ...opt, ...options })\n }\n }\n })\n}\n\n/**\n * Claim a previously preclaimed registration. This can only be done after the\n * preclaim step\n * @param name - AENS name\n * @param salt - Salt from pre-claim, or 0 if it's a bid\n * @param options - options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @param options.nameFee - Name Fee (By default calculated by sdk)\n * @returns the result of the claim\n * @example\n * ```js\n * const name = 'test.chain'\n * const salt = preclaimResult.salt // salt from pre-claim transaction\n *\n * await sdkInstance.aensClaim(name, salt, { ttl, fee, nonce, nameFee })\n * ```\n */\nexport async function aensClaim (\n name: AensName, salt: number, options: AensClaimOptions\n): Promise<AensClaimReturnType> {\n const claimTx = await _buildTx(TX_TYPE.nameClaim, {\n ...options,\n accountId: await options.onAccount.address(options),\n nameSalt: salt,\n name\n })\n\n const result = await send(claimTx, options)\n if (!isAuctionName(name)) {\n const nameInter = result.blockHeight != null && result.blockHeight > 0\n ? await aensQuery(name, options)\n : {}\n return Object.assign(result, nameInter)\n }\n return result\n}\n\ntype AensClaimOptionsType = BuildTxOptions<TX_TYPE.nameClaim, 'accountId' | 'nameSalt' | 'name'>\n& SendOptions & Parameters<typeof aensQuery>[1]\ninterface AensClaimOptions extends AensClaimOptionsType {}\ninterface AensClaimReturnType extends\n Awaited<ReturnType<typeof send>>,\n Partial<Awaited<ReturnType<typeof aensQuery>>> {}\n\n/**\n * Preclaim a name. Sends a hash of the name and a random salt to the node\n * @param name - AENS name\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @example\n * ```js\n * const name = 'test.chain'\n * const salt = preclaimResult.salt // salt from pre-claim transaction\n *\n * await sdkInstance.aensPreclaim(name, { ttl, fee, nonce })\n * {\n * ...transactionResult,\n * claim, // Claim function (options={}) => claimTransactionResult\n * salt,\n * commitmentId\n * }\n * ```\n */\nexport async function aensPreclaim (\n name: AensName, options: AensPreclaimOptions\n): Promise<Readonly<\n Awaited<ReturnType<typeof send>> & {\n height: number\n salt: number\n commitmentId: string\n claim: (opts?: Parameters<typeof aensClaim>[2]) => ReturnType<typeof aensClaim>\n }\n >> {\n const _salt = salt()\n const currentHeight = await height(options)\n const commitmentId = commitmentHash(name, _salt)\n\n const preclaimTx = await _buildTx(TX_TYPE.namePreClaim, {\n ...options,\n accountId: await options.onAccount.address(options),\n commitmentId\n })\n\n return Object.freeze({\n ...await send(preclaimTx, options),\n height: currentHeight,\n salt: _salt,\n commitmentId,\n async claim (opts?: Parameters<typeof aensClaim>[2]) {\n return await aensClaim(name, _salt, { ...options, ...opts })\n }\n })\n}\n\ninterface AensPreclaimOptions extends\n BuildTxOptions<TX_TYPE.namePreClaim, 'accountId' | 'commitmentId'>,\n SendOptions,\n AensClaimOptions {}\n\n/**\n * Bid to name auction\n * @param name - Domain name\n * @param nameFee - Name fee (bid fee)\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @returns Transaction result\n * @example\n * ```js\n * const name = 'test.chain'\n * const bidFee = computeBidFee(name, startFee, incrementPercentage)\n *\n * await sdkInstance.aensBid(name, 213109412839123, { ttl, fee, nonce })\n * ```\n */\nexport async function aensBid (\n name: AensName,\n nameFee: number | string | BigNumber,\n options: Omit<Parameters<typeof aensClaim>[2], 'nameFee'>\n): ReturnType<typeof aensClaim> {\n return await aensClaim(name, 0, { ...options, nameFee })\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;AACA;SAESA,I;SACAC,c,EAAgBC,a;SAChBC,U,EAAYC,Q,EAAUC,O;SACtBC,a;SAGAC,I;SACAC,O,EAASC,M;SACTC,Q;;AAST;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,UAAf,CACLC,IADK,EACWC,OADX,EAEoB;EACzB,MAAMC,YAAY,GAAG,MAAMJ,QAAQ,CAACL,OAAO,CAACU,UAAT,EAAqB,EACtD,G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C,MAAM,CAACmB,MAAP,CAAc,EACnB,IAAG,MAAMpC,IAAI,CAACsD,UAAD,EAAahD,OAAb,CAAb,CADmB;IAEnBJ,MAAM,EAAEkD,aAFW;IAGnB3D,IAAI,EAAE0D,KAHa;IAInBE,YAJmB;;IAKnB,MAAMG,KAAN,CAAaC,IAAb,EAAqD;MACnD,OAAO,MAAMf,SAAS,CAACrC,IAAD,EAAO8C,KAAP,EAAc,EAAE,GAAG7C,OAAL;QAAc,GAAGmD;MAAjB,CAAd,CAAtB;IACD;;EAPkB,CAAd,CAAP;AASD;;AAOD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,OAAf,CACLrD,IADK,EAELsD,OAFK,EAGLrD,OAHK,EAIyB;EAC9B,OAAO,MAAMoC,SAAS,CAACrC,IAAD,EAAO,CAAP,EAAU,EAAE,GAAGC,OAAL;IAAcqD;EAAd,CAAV,CAAtB;AACD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser connection base interface
|
|
3
|
+
*/
|
|
4
|
+
export default abstract class BrowserConnection {
|
|
5
|
+
debug: boolean;
|
|
6
|
+
protected constructor({ debug }: {
|
|
7
|
+
debug?: boolean;
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Connect
|
|
11
|
+
* @param onMessage - Message handler
|
|
12
|
+
* @param onDisconnect - trigger when runtime connection in closed
|
|
13
|
+
*/
|
|
14
|
+
connect(onMessage: (message: any, origin: string, source: any) => void, onDisconnect: () => void): void;
|
|
15
|
+
/**
|
|
16
|
+
* Disconnect
|
|
17
|
+
*/
|
|
18
|
+
disconnect(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Send message
|
|
21
|
+
*/
|
|
22
|
+
protected receiveMessage(message: any): void;
|
|
23
|
+
/**
|
|
24
|
+
* Send message
|
|
25
|
+
*/
|
|
26
|
+
sendMessage(message: any): void;
|
|
27
|
+
/**
|
|
28
|
+
* Check if connected
|
|
29
|
+
* @returns Is connected
|
|
30
|
+
*/
|
|
31
|
+
abstract isConnected(): boolean;
|
|
32
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ISC License (ISC)
|
|
3
|
+
* Copyright (c) 2022 aeternity developers
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
|
8
|
+
*
|
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
*/
|
|
17
|
+
import { AlreadyConnectedError, NoWalletConnectedError } from "../../utils/errors.mjs";
|
|
18
|
+
/**
|
|
19
|
+
* Browser connection base interface
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
export default class BrowserConnection {
|
|
23
|
+
constructor(_ref) {
|
|
24
|
+
let {
|
|
25
|
+
debug = false
|
|
26
|
+
} = _ref;
|
|
27
|
+
this.debug = debug;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Connect
|
|
31
|
+
* @param onMessage - Message handler
|
|
32
|
+
* @param onDisconnect - trigger when runtime connection in closed
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
connect(onMessage, onDisconnect) {
|
|
37
|
+
if (this.isConnected()) throw new AlreadyConnectedError('You already connected');
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Disconnect
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
disconnect() {
|
|
45
|
+
if (!this.isConnected()) throw new NoWalletConnectedError('You dont have connection. Please connect before');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Send message
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
receiveMessage(message) {
|
|
53
|
+
if (this.debug) console.log('Receive message:', message);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Send message
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
sendMessage(message) {
|
|
61
|
+
if (this.debug) console.log('Send message:', message);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Check if connected
|
|
65
|
+
* @returns Is connected
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=Browser.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Browser.mjs","names":["AlreadyConnectedError","NoWalletConnectedError","BrowserConnection","constructor","debug","connect","onMessage","onDisconnect","isConnected","disconnect","receiveMessage","message","console","log","sendMessage"],"sources":["../../../src/aepp-wallet-communication/connection/Browser.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2022 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\nimport { AlreadyConnectedError, NoWalletConnectedError } from '../../utils/errors'\n\n/**\n * Browser connection base interface\n */\nexport default abstract class BrowserConnection {\n debug: boolean\n\n protected constructor ({ debug = false }: { debug?: boolean }) {\n this.debug = debug\n }\n\n /**\n * Connect\n * @param onMessage - Message handler\n * @param onDisconnect - trigger when runtime connection in closed\n */\n connect (\n onMessage: (message: any, origin: string, source: any) => void,\n onDisconnect: () => void\n ): void {\n if (this.isConnected()) throw new AlreadyConnectedError('You already connected')\n }\n\n /**\n * Disconnect\n */\n disconnect (): void {\n if (!this.isConnected()) throw new NoWalletConnectedError('You dont have connection. Please connect before')\n }\n\n /**\n * Send message\n */\n protected receiveMessage (message: any): void {\n if (this.debug) console.log('Receive message:', message)\n }\n\n /**\n * Send message\n */\n sendMessage (message: any): void {\n if (this.debug) console.log('Send message:', message)\n }\n\n /**\n * Check if connected\n * @returns Is connected\n */\n abstract isConnected (): boolean\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;SAESA,qB,EAAuBC,sB;AAEhC;AACA;AACA;;AACA,eAAe,MAAeC,iBAAf,CAAiC;EAGpCC,WAAW,OAA0C;IAAA,IAAxC;MAAEC,KAAK,GAAG;IAAV,CAAwC;IAC7D,KAAKA,KAAL,GAAaA,KAAb;EACD;EAED;AACF;AACA;AACA;AACA;;;EACEC,OAAO,CACLC,SADK,EAELC,YAFK,EAGC;IACN,IAAI,KAAKC,WAAL,EAAJ,EAAwB,MAAM,IAAIR,qBAAJ,CAA0B,uBAA1B,CAAN;EACzB;EAED;AACF;AACA;;;EACES,UAAU,GAAU;IAClB,IAAI,CAAC,KAAKD,WAAL,EAAL,EAAyB,MAAM,IAAIP,sBAAJ,CAA2B,iDAA3B,CAAN;EAC1B;EAED;AACF;AACA;;;EACYS,cAAc,CAAEC,OAAF,EAAsB;IAC5C,IAAI,KAAKP,KAAT,EAAgBQ,OAAO,CAACC,GAAR,CAAY,kBAAZ,EAAgCF,OAAhC;EACjB;EAED;AACF;AACA;;;EACEG,WAAW,CAAEH,OAAF,EAAsB;IAC/B,IAAI,KAAKP,KAAT,EAAgBQ,OAAO,CAACC,GAAR,CAAY,eAAZ,EAA6BF,OAA7B;EACjB;EAED;AACF;AACA;AACA;;;AA3CgD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Runtime } from 'webextension-polyfill';
|
|
2
|
+
import BrowserConnection from './Browser';
|
|
3
|
+
/**
|
|
4
|
+
* BrowserRuntimeConnection
|
|
5
|
+
* Handle browser runtime communication
|
|
6
|
+
*/
|
|
7
|
+
export default class BrowserRuntimeConnection extends BrowserConnection {
|
|
8
|
+
port: Runtime.Port;
|
|
9
|
+
constructor({ port, ...options }: {
|
|
10
|
+
port: Runtime.Port;
|
|
11
|
+
debug: boolean;
|
|
12
|
+
});
|
|
13
|
+
disconnect(): void;
|
|
14
|
+
connect(onMessage: (message: any, origin: string, source: Runtime.Port) => void, onDisconnect: () => void): void;
|
|
15
|
+
sendMessage(message: any): void;
|
|
16
|
+
isConnected(): boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ISC License (ISC)
|
|
3
|
+
* Copyright (c) 2022 aeternity developers
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
|
8
|
+
*
|
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
*/
|
|
17
|
+
import BrowserConnection from "./Browser.mjs";
|
|
18
|
+
/**
|
|
19
|
+
* BrowserRuntimeConnection
|
|
20
|
+
* Handle browser runtime communication
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export default class BrowserRuntimeConnection extends BrowserConnection {
|
|
24
|
+
constructor(_ref) {
|
|
25
|
+
let {
|
|
26
|
+
port,
|
|
27
|
+
...options
|
|
28
|
+
} = _ref;
|
|
29
|
+
super(options);
|
|
30
|
+
this.port = port;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
disconnect() {
|
|
34
|
+
super.disconnect();
|
|
35
|
+
this.port.disconnect();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
connect(onMessage, onDisconnect) {
|
|
39
|
+
super.connect(onMessage, onDisconnect);
|
|
40
|
+
this.port.onMessage.addListener((message, port) => {
|
|
41
|
+
this.receiveMessage(message);
|
|
42
|
+
onMessage(message, port.name, port);
|
|
43
|
+
});
|
|
44
|
+
this.port.onDisconnect.addListener(onDisconnect);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
sendMessage(message) {
|
|
48
|
+
super.sendMessage(message);
|
|
49
|
+
this.port.postMessage(message);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
isConnected() {
|
|
53
|
+
return this.port.onMessage.hasListeners();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=BrowserRuntime.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BrowserRuntime.mjs","names":["BrowserConnection","BrowserRuntimeConnection","constructor","port","options","disconnect","connect","onMessage","onDisconnect","addListener","message","receiveMessage","name","sendMessage","postMessage","isConnected","hasListeners"],"sources":["../../../src/aepp-wallet-communication/connection/BrowserRuntime.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2022 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\nimport { Runtime } from 'webextension-polyfill'\nimport BrowserConnection from './Browser'\n\n/**\n * BrowserRuntimeConnection\n * Handle browser runtime communication\n */\nexport default class BrowserRuntimeConnection extends BrowserConnection {\n port: Runtime.Port\n\n constructor ({ port, ...options }: { port: Runtime.Port, debug: boolean }) {\n super(options)\n this.port = port\n }\n\n disconnect (): void {\n super.disconnect()\n this.port.disconnect()\n }\n\n connect (\n onMessage: (message: any, origin: string, source: Runtime.Port) => void,\n onDisconnect: () => void\n ): void {\n super.connect(onMessage, onDisconnect)\n this.port.onMessage.addListener((message, port) => {\n this.receiveMessage(message)\n onMessage(message, port.name, port)\n })\n this.port.onDisconnect.addListener(onDisconnect)\n }\n\n sendMessage (message: any): void {\n super.sendMessage(message)\n this.port.postMessage(message)\n }\n\n isConnected (): boolean {\n return this.port.onMessage.hasListeners()\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;OAGOA,iB;AAEP;AACA;AACA;AACA;;AACA,eAAe,MAAMC,wBAAN,SAAuCD,iBAAvC,CAAyD;EAGtEE,WAAW,OAAgE;IAAA,IAA9D;MAAEC,IAAF;MAAQ,GAAGC;IAAX,CAA8D;IACzE,MAAMA,OAAN;IACA,KAAKD,IAAL,GAAYA,IAAZ;EACD;;EAEDE,UAAU,GAAU;IAClB,MAAMA,UAAN;IACA,KAAKF,IAAL,CAAUE,UAAV;EACD;;EAEDC,OAAO,CACLC,SADK,EAELC,YAFK,EAGC;IACN,MAAMF,OAAN,CAAcC,SAAd,EAAyBC,YAAzB;IACA,KAAKL,IAAL,CAAUI,SAAV,CAAoBE,WAApB,CAAgC,CAACC,OAAD,EAAUP,IAAV,KAAmB;MACjD,KAAKQ,cAAL,CAAoBD,OAApB;MACAH,SAAS,CAACG,OAAD,EAAUP,IAAI,CAACS,IAAf,EAAqBT,IAArB,CAAT;IACD,CAHD;IAIA,KAAKA,IAAL,CAAUK,YAAV,CAAuBC,WAAvB,CAAmCD,YAAnC;EACD;;EAEDK,WAAW,CAAEH,OAAF,EAAsB;IAC/B,MAAMG,WAAN,CAAkBH,OAAlB;IACA,KAAKP,IAAL,CAAUW,WAAV,CAAsBJ,OAAtB;EACD;;EAEDK,WAAW,GAAa;IACtB,OAAO,KAAKZ,IAAL,CAAUI,SAAV,CAAoBS,YAApB,EAAP;EACD;;AAhCqE"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import BrowserConnection from './Browser';
|
|
2
|
+
import { MESSAGE_DIRECTION } from '../schema';
|
|
3
|
+
export declare type ImplPostMessage = Pick<Window, 'addEventListener' | 'removeEventListener' | 'postMessage'>;
|
|
4
|
+
/**
|
|
5
|
+
* Browser window Post Message connector module
|
|
6
|
+
*/
|
|
7
|
+
export default class BrowserWindowMessageConnection extends BrowserConnection {
|
|
8
|
+
#private;
|
|
9
|
+
origin?: string;
|
|
10
|
+
sendDirection?: MESSAGE_DIRECTION;
|
|
11
|
+
receiveDirection: MESSAGE_DIRECTION;
|
|
12
|
+
listener?: (this: Window, ev: MessageEvent<any>) => void;
|
|
13
|
+
/**
|
|
14
|
+
* @param options - Options
|
|
15
|
+
* @param options.target Target window for message
|
|
16
|
+
* @param options.self Host window for message
|
|
17
|
+
* @param options.origin Origin of receiver
|
|
18
|
+
* @param options.sendDirection Wrapping messages into additional struct
|
|
19
|
+
* `({ type: 'to_aepp' || 'to_waellet', data })`
|
|
20
|
+
* Used for handling messages between content script and page
|
|
21
|
+
* @param options.receiveDirection Unwrapping messages from additional struct
|
|
22
|
+
*/
|
|
23
|
+
constructor({ target, self, origin, sendDirection, receiveDirection, ...options }?: {
|
|
24
|
+
target?: ImplPostMessage;
|
|
25
|
+
self?: ImplPostMessage;
|
|
26
|
+
origin?: string;
|
|
27
|
+
sendDirection?: MESSAGE_DIRECTION;
|
|
28
|
+
receiveDirection?: MESSAGE_DIRECTION;
|
|
29
|
+
debug?: boolean;
|
|
30
|
+
});
|
|
31
|
+
isConnected(): boolean;
|
|
32
|
+
connect(onMessage: (message: any, origin: string, source: MessageEventSource | null) => void, onDisconnect: () => void): void;
|
|
33
|
+
disconnect(): void;
|
|
34
|
+
sendMessage(msg: any): void;
|
|
35
|
+
}
|