@aeternity/aepp-sdk 11.0.0 → 12.1.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 +0 -22
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +2 -1
- package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +20764 -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 +70 -0
- package/es/AeSdkAepp.mjs +176 -0
- package/es/AeSdkAepp.mjs.map +1 -0
- package/es/AeSdkBase.d.ts +213 -0
- package/es/AeSdkBase.mjs +314 -0
- package/es/AeSdkBase.mjs.map +1 -0
- package/es/AeSdkWallet.d.ts +104 -0
- package/es/AeSdkWallet.mjs +326 -0
- package/es/AeSdkWallet.mjs.map +1 -0
- package/es/Node.d.ts +41 -0
- package/es/Node.mjs +147 -0
- package/es/Node.mjs.map +1 -0
- package/es/account/Base.d.ts +68 -0
- package/es/account/Base.mjs +123 -0
- package/es/account/Base.mjs.map +1 -0
- package/es/account/Memory.d.ts +26 -0
- package/es/account/Memory.mjs +103 -0
- package/es/account/Memory.mjs.map +1 -0
- package/es/account/Rpc.d.ts +27 -0
- package/es/account/Rpc.mjs +80 -0
- package/es/account/Rpc.mjs.map +1 -0
- package/es/aens.d.ts +222 -0
- package/es/aens.mjs +338 -0
- package/es/aens.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/Browser.d.ts +33 -0
- package/es/aepp-wallet-communication/connection/Browser.mjs +73 -0
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +18 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +58 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +36 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +146 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection-proxy.d.ts +11 -0
- package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +16 -11
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +34 -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 +105 -46
- package/es/aepp-wallet-communication/schema.mjs +251 -0
- package/es/aepp-wallet-communication/schema.mjs.map +1 -0
- package/es/aepp-wallet-communication/wallet-detector.d.ts +25 -0
- package/es/aepp-wallet-communication/wallet-detector.mjs +62 -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 +1065 -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 +4166 -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 +248 -0
- package/es/chain.mjs +560 -0
- package/es/chain.mjs.map +1 -0
- package/es/channel/handlers.d.ts +34 -0
- package/es/channel/handlers.mjs +164 -131
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/index.d.ts +625 -0
- package/es/channel/index.mjs +897 -902
- package/es/channel/index.mjs.map +1 -1
- package/es/channel/internal.d.ts +101 -0
- package/es/channel/internal.mjs +138 -88
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Compiler.d.ts +18 -0
- package/es/contract/Compiler.mjs +68 -0
- package/es/contract/Compiler.mjs.map +1 -0
- package/es/contract/aci.d.ts +127 -0
- package/es/contract/aci.mjs +225 -193
- package/es/contract/aci.mjs.map +1 -1
- package/es/contract/ga.d.ts +69 -0
- package/es/contract/ga.mjs +195 -0
- package/es/contract/ga.mjs.map +1 -0
- package/es/contract/methods.d.ts +71 -0
- package/es/contract/methods.mjs +104 -0
- package/es/contract/methods.mjs.map +1 -0
- package/es/deprecated/index.d.ts +143 -0
- package/es/deprecated/index.mjs +162 -0
- package/es/deprecated/index.mjs.map +1 -0
- package/es/deprecated/methods.d.ts +18 -0
- package/es/deprecated/methods.mjs +26 -0
- package/es/deprecated/methods.mjs.map +1 -0
- package/es/index.d.ts +35 -0
- package/es/index.mjs +35 -40
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +161 -0
- package/es/oracle.mjs +306 -0
- package/es/oracle.mjs.map +1 -0
- package/es/spend.d.ts +62 -0
- package/es/spend.mjs +111 -0
- package/es/spend.mjs.map +1 -0
- package/es/tx/builder/address.d.ts +25 -0
- package/es/tx/builder/address.mjs +45 -0
- package/es/tx/builder/address.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +70 -0
- package/es/tx/builder/constants.mjs +122 -0
- package/es/tx/builder/constants.mjs.map +1 -0
- package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
- package/es/tx/builder/field-types/coin-amount.mjs +26 -0
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
- package/es/tx/builder/field-types/deposit.d.ts +15 -0
- package/es/tx/builder/field-types/deposit.mjs +19 -0
- package/es/tx/builder/field-types/deposit.mjs.map +1 -0
- package/es/tx/builder/field-types/fee.d.ts +25 -0
- package/es/tx/builder/field-types/fee.mjs +150 -0
- package/es/tx/builder/field-types/fee.mjs.map +1 -0
- package/es/tx/builder/field-types/field.d.ts +6 -0
- package/es/tx/builder/field-types/field.mjs +15 -0
- package/es/tx/builder/field-types/field.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
- package/es/tx/builder/field-types/gas-limit.mjs +33 -0
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-price.d.ts +8 -0
- package/es/tx/builder/field-types/gas-price.mjs +18 -0
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
- package/es/tx/builder/field-types/index.d.ts +70 -0
- package/es/tx/builder/field-types/index.mjs +25 -0
- package/es/tx/builder/field-types/index.mjs.map +1 -0
- package/es/tx/builder/field-types/name-fee.d.ts +20 -0
- package/es/tx/builder/field-types/name-fee.mjs +24 -0
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
- package/es/tx/builder/field-types/name-id.d.ts +14 -0
- package/es/tx/builder/field-types/name-id.mjs +19 -0
- package/es/tx/builder/field-types/name-id.mjs.map +1 -0
- package/es/tx/builder/field-types/name.d.ts +13 -0
- package/es/tx/builder/field-types/name.mjs +18 -0
- package/es/tx/builder/field-types/name.mjs.map +1 -0
- package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
- package/es/tx/builder/field-types/short-u-int.mjs +12 -0
- package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
- package/es/tx/builder/field-types/u-int.d.ts +8 -0
- package/es/tx/builder/field-types/u-int.mjs +14 -0
- package/es/tx/builder/field-types/u-int.mjs.map +1 -0
- package/es/tx/builder/helpers.d.ts +125 -0
- package/es/tx/builder/helpers.mjs +94 -240
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +88 -0
- package/es/tx/builder/index.mjs +167 -358
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +1201 -0
- package/es/tx/builder/schema.mjs +175 -664
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +64 -0
- package/es/tx/index.mjs +151 -265
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +20 -0
- package/es/tx/validator.mjs +104 -124
- 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/sha-js/index.d.mjs +2 -0
- package/es/typings/sha-js/index.d.mjs.map +1 -0
- package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
- package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
- package/es/utils/amount-formatter.d.ts +42 -0
- package/es/utils/amount-formatter.mjs +36 -49
- 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 +11 -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 +11 -15
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +88 -0
- package/es/utils/crypto.mjs +64 -108
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder-types.d.ts +61 -0
- package/es/utils/encoder-types.mjs +36 -0
- package/es/utils/encoder-types.mjs.map +1 -0
- package/es/utils/encoder.d.ts +25 -0
- package/es/utils/encoder.mjs +118 -0
- package/es/utils/encoder.mjs.map +1 -0
- package/es/{errors.d.ts → utils/errors.d.ts} +246 -59
- package/es/utils/errors.mjs +313 -136
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +50 -0
- package/es/utils/hd-wallet.mjs +86 -45
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.d.ts +5 -0
- package/es/utils/json-big.mjs +12 -16
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.d.ts +51 -0
- package/es/utils/keystore.mjs +101 -194
- package/es/utils/keystore.mjs.map +1 -1
- package/es/{mptree.d.ts → utils/mptree.d.ts} +6 -9
- package/es/utils/mptree.mjs +22 -18
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +20 -0
- package/es/utils/other.mjs +32 -35
- package/es/utils/other.mjs.map +1 -1
- package/es/utils/semver-satisfies.d.ts +1 -0
- package/es/utils/semver-satisfies.mjs +2 -2
- 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 +56 -42
- package/src/AeSdk.ts +68 -0
- package/src/AeSdkAepp.ts +176 -0
- package/src/AeSdkBase.ts +338 -0
- package/src/AeSdkWallet.ts +348 -0
- package/src/Node.ts +173 -0
- package/src/account/Base.ts +124 -0
- package/src/account/Memory.ts +98 -0
- package/src/account/Rpc.ts +69 -0
- package/src/aens.ts +407 -0
- package/src/aepp-wallet-communication/connection/Browser.ts +71 -0
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +59 -0
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +122 -0
- package/{es/utils/crypto-ts.mjs → src/aepp-wallet-communication/connection-proxy.ts} +18 -18
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +143 -0
- package/src/aepp-wallet-communication/rpc/types.ts +66 -0
- package/src/aepp-wallet-communication/schema.ts +224 -0
- package/src/aepp-wallet-communication/wallet-detector.ts +72 -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 +10080 -0
- package/src/apis/node/index.ts +2 -0
- package/src/apis/node/models/index.ts +1257 -0
- package/src/apis/node/models/mappers.ts +4280 -0
- package/src/apis/node/models/parameters.ts +188 -0
- package/src/apis/node/node.ts +1299 -0
- package/src/chain.ts +502 -0
- package/src/channel/handlers.ts +817 -0
- package/src/channel/index.ts +1025 -0
- package/src/channel/internal.ts +361 -0
- package/src/contract/Compiler.ts +67 -0
- package/src/contract/aci.ts +538 -0
- package/src/contract/ga.ts +199 -0
- package/src/contract/methods.ts +123 -0
- package/src/deprecated/index.ts +170 -0
- package/src/deprecated/methods.ts +25 -0
- package/src/index.ts +56 -0
- package/src/oracle.ts +364 -0
- package/src/spend.ts +164 -0
- package/src/tx/builder/address.ts +50 -0
- package/src/tx/builder/constants.ts +126 -0
- package/src/tx/builder/field-types/coin-amount.ts +27 -0
- package/src/tx/builder/field-types/deposit.ts +21 -0
- package/src/tx/builder/field-types/fee.ts +143 -0
- package/src/tx/builder/field-types/field.ts +9 -0
- package/src/tx/builder/field-types/gas-limit.ts +41 -0
- package/src/tx/builder/field-types/gas-price.ts +16 -0
- package/src/tx/builder/field-types/index.ts +45 -0
- package/src/tx/builder/field-types/name-fee.ts +32 -0
- package/src/tx/builder/field-types/name-id.ts +20 -0
- package/src/tx/builder/field-types/name.ts +18 -0
- package/src/tx/builder/field-types/short-u-int.ts +11 -0
- package/src/tx/builder/field-types/u-int.ts +16 -0
- package/src/tx/builder/helpers.ts +248 -0
- package/src/tx/builder/index.ts +400 -0
- package/src/tx/builder/schema.ts +727 -0
- package/src/tx/index.ts +192 -0
- package/src/tx/validator.ts +230 -0
- package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
- package/src/typings/@aeternity__uuid/index.d.ts +5 -0
- package/src/typings/bip32-path/index.d.ts +33 -0
- package/src/typings/blakejs/index.d.ts +4 -32
- package/src/typings/sha-js/index.d.ts +5 -0
- package/src/typings/tweetnacl-auth/index.d.ts +14 -0
- package/src/utils/amount-formatter.ts +56 -69
- package/src/utils/autorest.ts +93 -0
- package/src/utils/bignumber.ts +11 -12
- package/src/utils/bytes.ts +29 -31
- package/src/utils/crypto.ts +205 -0
- package/src/utils/encoder-types.ts +63 -0
- package/src/utils/encoder.ts +146 -0
- package/src/utils/errors.ts +482 -366
- package/src/utils/hd-wallet.ts +166 -0
- package/src/utils/json-big.ts +27 -0
- package/src/utils/keystore.ts +182 -0
- package/src/utils/mptree.ts +64 -61
- package/src/utils/other.ts +34 -41
- package/src/utils/semver-satisfies.ts +15 -11
- package/src/utils/string.ts +18 -20
- 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/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/semver-satisfies.d.ts +0 -1
- package/es/string.d.ts +0 -26
- package/es/tx/builder/field-types.mjs +0 -74
- package/es/tx/builder/field-types.mjs.map +0 -1
- 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/handlers.js +0 -673
- package/src/channel/index.js +0 -898
- package/src/channel/internal.js +0 -237
- 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 -380
- package/src/tx/builder/index.js +0 -465
- package/src/tx/builder/schema.js +0 -1197
- 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 -229
- 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
|
@@ -0,0 +1,817 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ISC License (ISC)
|
|
3
|
+
* Copyright (c) 2018 aeternity developers
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
|
8
|
+
*
|
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
*/
|
|
17
|
+
/* eslint-disable consistent-return */
|
|
18
|
+
/* eslint-disable default-case */
|
|
19
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
20
|
+
import { generateKeyPair, encodeContractAddress } from '../utils/crypto';
|
|
21
|
+
import {
|
|
22
|
+
ChannelState,
|
|
23
|
+
options,
|
|
24
|
+
changeStatus,
|
|
25
|
+
changeState,
|
|
26
|
+
call,
|
|
27
|
+
send,
|
|
28
|
+
emit,
|
|
29
|
+
channelId,
|
|
30
|
+
disconnect,
|
|
31
|
+
fsmId,
|
|
32
|
+
ChannelMessage,
|
|
33
|
+
ChannelFsm,
|
|
34
|
+
SignTx,
|
|
35
|
+
} from './internal';
|
|
36
|
+
import { unpackTx, buildTx } from '../tx/builder';
|
|
37
|
+
import { encode, Encoded, Encoding } from '../utils/encoder';
|
|
38
|
+
import {
|
|
39
|
+
IllegalArgumentError,
|
|
40
|
+
InsufficientBalanceError,
|
|
41
|
+
ChannelConnectionError,
|
|
42
|
+
UnexpectedChannelMessageError,
|
|
43
|
+
} from '../utils/errors';
|
|
44
|
+
import type Channel from '.';
|
|
45
|
+
import { Tag } from '../tx/builder/constants';
|
|
46
|
+
|
|
47
|
+
export async function appendSignature(
|
|
48
|
+
tx: Encoded.Transaction,
|
|
49
|
+
signFn: SignTx,
|
|
50
|
+
): Promise<Encoded.Transaction | number | null> {
|
|
51
|
+
const { signatures, encodedTx } = unpackTx(tx, Tag.SignedTx).tx;
|
|
52
|
+
const result = await signFn(encode(encodedTx.rlpEncoded, Encoding.Transaction));
|
|
53
|
+
if (typeof result === 'string') {
|
|
54
|
+
const { tx: signedTx } = unpackTx(result, Tag.SignedTx);
|
|
55
|
+
return buildTx({
|
|
56
|
+
signatures: signatures.concat(signedTx.signatures),
|
|
57
|
+
encodedTx: signedTx.encodedTx.rlpEncoded,
|
|
58
|
+
}, Tag.SignedTx).tx;
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function handleUnexpectedMessage(
|
|
64
|
+
_channel: Channel,
|
|
65
|
+
message: ChannelMessage,
|
|
66
|
+
state: ChannelState,
|
|
67
|
+
): ChannelFsm {
|
|
68
|
+
state?.reject?.(Object.assign(
|
|
69
|
+
new UnexpectedChannelMessageError(`Unexpected message received:\n\n${JSON.stringify(message)}`),
|
|
70
|
+
{ wsMessage: message },
|
|
71
|
+
));
|
|
72
|
+
return { handler: channelOpen };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function awaitingConnection(
|
|
76
|
+
channel: Channel,
|
|
77
|
+
message: ChannelMessage,
|
|
78
|
+
): ChannelFsm | undefined {
|
|
79
|
+
if (message.method === 'channels.info') {
|
|
80
|
+
const channelInfoStatus: string = message.params.data.event;
|
|
81
|
+
if (['channel_accept', 'funding_created'].includes(channelInfoStatus)) {
|
|
82
|
+
changeStatus(channel, {
|
|
83
|
+
channel_accept: 'accepted',
|
|
84
|
+
funding_created: 'halfSigned',
|
|
85
|
+
}[channelInfoStatus as 'channel_accept' | 'funding_created']);
|
|
86
|
+
return { handler: awaitingChannelCreateTx };
|
|
87
|
+
}
|
|
88
|
+
if (message.params.data.event === 'channel_reestablished') {
|
|
89
|
+
return { handler: awaitingOpenConfirmation };
|
|
90
|
+
}
|
|
91
|
+
if (message.params.data.event === 'fsm_up') {
|
|
92
|
+
fsmId.set(channel, message.params.data.fsm_id);
|
|
93
|
+
return { handler: awaitingConnection };
|
|
94
|
+
}
|
|
95
|
+
return { handler: awaitingConnection };
|
|
96
|
+
}
|
|
97
|
+
if (message.method === 'channels.error') {
|
|
98
|
+
emit(channel, 'error', new ChannelConnectionError(message?.payload?.message));
|
|
99
|
+
return { handler: channelClosed };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export async function awaitingReconnection(
|
|
104
|
+
channel: Channel,
|
|
105
|
+
message: ChannelMessage,
|
|
106
|
+
state: ChannelState,
|
|
107
|
+
): Promise<ChannelFsm> {
|
|
108
|
+
if (message.method === 'channels.info') {
|
|
109
|
+
if (message.params.data.event === 'fsm_up') {
|
|
110
|
+
fsmId.set(channel, message.params.data.fsm_id);
|
|
111
|
+
changeState(channel, (await call(channel, 'channels.get.offchain_state', {})).signed_tx);
|
|
112
|
+
return { handler: channelOpen };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export async function awaitingChannelCreateTx(
|
|
119
|
+
channel: Channel,
|
|
120
|
+
message: ChannelMessage,
|
|
121
|
+
): Promise<ChannelFsm | undefined> {
|
|
122
|
+
const channelOptions = options.get(channel);
|
|
123
|
+
if (channelOptions != null) {
|
|
124
|
+
const tag = {
|
|
125
|
+
initiator: 'initiator_sign',
|
|
126
|
+
responder: 'responder_sign',
|
|
127
|
+
}[channelOptions.role];
|
|
128
|
+
if (message.method === `channels.sign.${tag}`) {
|
|
129
|
+
if (message.params.data.tx != null) {
|
|
130
|
+
const signedTx = await channelOptions.sign(tag, message.params.data.tx);
|
|
131
|
+
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { tx: signedTx } });
|
|
132
|
+
return { handler: awaitingOnChainTx };
|
|
133
|
+
}
|
|
134
|
+
const signedTx = await appendSignature(
|
|
135
|
+
message.params.data.signed_tx,
|
|
136
|
+
async (tx) => channelOptions.sign(tag, tx),
|
|
137
|
+
);
|
|
138
|
+
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { signed_tx: signedTx } });
|
|
139
|
+
return { handler: awaitingOnChainTx };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function awaitingOnChainTx(
|
|
145
|
+
channel: Channel,
|
|
146
|
+
message: ChannelMessage,
|
|
147
|
+
): ChannelFsm | undefined {
|
|
148
|
+
const channelOptions = options.get(channel);
|
|
149
|
+
if (channelOptions != null) {
|
|
150
|
+
if (message.method === 'channels.on_chain_tx') {
|
|
151
|
+
if (
|
|
152
|
+
message.params.data.info === 'funding_signed'
|
|
153
|
+
&& channelOptions.role === 'initiator'
|
|
154
|
+
) {
|
|
155
|
+
return { handler: awaitingBlockInclusion };
|
|
156
|
+
}
|
|
157
|
+
if (
|
|
158
|
+
message.params.data.info === 'funding_created'
|
|
159
|
+
&& channelOptions.role === 'responder'
|
|
160
|
+
) {
|
|
161
|
+
return { handler: awaitingBlockInclusion };
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (
|
|
165
|
+
message.method === 'channels.info'
|
|
166
|
+
&& message.params.data.event === 'funding_signed'
|
|
167
|
+
&& channelOptions.role === 'initiator'
|
|
168
|
+
) {
|
|
169
|
+
channelId.set(channel, message.params.channel_id);
|
|
170
|
+
changeStatus(channel, 'signed');
|
|
171
|
+
return { handler: awaitingOnChainTx };
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function awaitingBlockInclusion(
|
|
177
|
+
channel: Channel,
|
|
178
|
+
message: ChannelMessage,
|
|
179
|
+
): ChannelFsm | undefined {
|
|
180
|
+
if (message.method === 'channels.info') {
|
|
181
|
+
const handlers: {
|
|
182
|
+
[key: string]: (channel: Channel, message: ChannelMessage) => ChannelFsm | undefined;
|
|
183
|
+
} = {
|
|
184
|
+
funding_created: awaitingBlockInclusion,
|
|
185
|
+
own_funding_locked: awaitingBlockInclusion,
|
|
186
|
+
funding_locked: awaitingOpenConfirmation,
|
|
187
|
+
};
|
|
188
|
+
const handler = handlers[message.params.data.event as string];
|
|
189
|
+
if (handler != null) {
|
|
190
|
+
return { handler };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (message.method === 'channels.on_chain_tx') {
|
|
194
|
+
emit(channel, 'onChainTx', message.params.data.tx, {
|
|
195
|
+
info: message.params.data.info,
|
|
196
|
+
type: message.params.data.type,
|
|
197
|
+
});
|
|
198
|
+
return { handler: awaitingBlockInclusion };
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function awaitingOpenConfirmation(
|
|
203
|
+
channel: Channel,
|
|
204
|
+
message: ChannelMessage,
|
|
205
|
+
): ChannelFsm | undefined {
|
|
206
|
+
if (message.method === 'channels.info' && message.params.data.event === 'open') {
|
|
207
|
+
channelId.set(channel, message.params.channel_id);
|
|
208
|
+
return { handler: awaitingInitialState };
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export function awaitingInitialState(
|
|
213
|
+
channel: Channel,
|
|
214
|
+
message: ChannelMessage,
|
|
215
|
+
): ChannelFsm | undefined {
|
|
216
|
+
if (message.method === 'channels.update') {
|
|
217
|
+
changeState(channel, message.params.data.state);
|
|
218
|
+
return { handler: channelOpen };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export async function channelOpen(
|
|
223
|
+
channel: Channel,
|
|
224
|
+
message: ChannelMessage,
|
|
225
|
+
state: ChannelState,
|
|
226
|
+
): Promise<ChannelFsm | undefined> {
|
|
227
|
+
switch (message.method) {
|
|
228
|
+
case 'channels.info':
|
|
229
|
+
switch (message.params.data.event) {
|
|
230
|
+
case 'update':
|
|
231
|
+
case 'withdraw_created':
|
|
232
|
+
case 'deposit_created':
|
|
233
|
+
return { handler: awaitingTxSignRequest };
|
|
234
|
+
case 'own_withdraw_locked':
|
|
235
|
+
case 'withdraw_locked':
|
|
236
|
+
case 'own_deposit_locked':
|
|
237
|
+
case 'deposit_locked':
|
|
238
|
+
case 'peer_disconnected':
|
|
239
|
+
case 'channel_reestablished':
|
|
240
|
+
case 'open':
|
|
241
|
+
// TODO: Better handling of peer_disconnected event.
|
|
242
|
+
//
|
|
243
|
+
// We should enter intermediate state where offchain transactions
|
|
244
|
+
// are blocked until channel is reestablished.
|
|
245
|
+
emit(channel, message.params.data.event);
|
|
246
|
+
return { handler: channelOpen };
|
|
247
|
+
case 'fsm_up':
|
|
248
|
+
fsmId.set(channel, message.params.data.fsm_id);
|
|
249
|
+
return { handler: channelOpen };
|
|
250
|
+
case 'timeout':
|
|
251
|
+
case 'close_mutual':
|
|
252
|
+
return { handler: channelOpen };
|
|
253
|
+
case 'closing':
|
|
254
|
+
changeStatus(channel, 'closing');
|
|
255
|
+
return { handler: channelOpen };
|
|
256
|
+
case 'closed_confirmed':
|
|
257
|
+
changeStatus(channel, 'closed');
|
|
258
|
+
return { handler: channelClosed };
|
|
259
|
+
case 'died':
|
|
260
|
+
changeStatus(channel, 'died');
|
|
261
|
+
return { handler: channelClosed };
|
|
262
|
+
case 'shutdown':
|
|
263
|
+
return { handler: channelOpen };
|
|
264
|
+
}
|
|
265
|
+
break;
|
|
266
|
+
case 'channels.on_chain_tx':
|
|
267
|
+
emit(channel, 'onChainTx', message.params.data.tx, {
|
|
268
|
+
info: message.params.data.info,
|
|
269
|
+
type: message.params.data.type,
|
|
270
|
+
});
|
|
271
|
+
return { handler: channelOpen };
|
|
272
|
+
case 'channels.leave':
|
|
273
|
+
// TODO: emit event
|
|
274
|
+
return { handler: channelOpen };
|
|
275
|
+
case 'channels.update':
|
|
276
|
+
changeState(channel, message.params.data.state);
|
|
277
|
+
return { handler: channelOpen };
|
|
278
|
+
case 'channels.sign.shutdown_sign_ack':
|
|
279
|
+
return awaitingTxSignRequest(channel, message, state);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
channelOpen.enter = (channel: Channel) => {
|
|
283
|
+
changeStatus(channel, 'open');
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
export async function awaitingOffChainTx(
|
|
287
|
+
channel: Channel,
|
|
288
|
+
message: ChannelMessage,
|
|
289
|
+
state: ChannelState,
|
|
290
|
+
): Promise<ChannelFsm> {
|
|
291
|
+
if (message.method === 'channels.sign.update') {
|
|
292
|
+
const { sign } = state;
|
|
293
|
+
if (message.params.data.tx != null) {
|
|
294
|
+
const signedTx = await sign(message.params.data.tx, { updates: message.params.data.updates });
|
|
295
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { tx: signedTx } });
|
|
296
|
+
return { handler: awaitingOffChainUpdate, state };
|
|
297
|
+
}
|
|
298
|
+
const signedTx = await appendSignature(
|
|
299
|
+
message.params.data.signed_tx,
|
|
300
|
+
async (tx) => sign(tx, { updates: message.params.data.updates }),
|
|
301
|
+
);
|
|
302
|
+
if (typeof signedTx === 'string') {
|
|
303
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { signed_tx: signedTx } });
|
|
304
|
+
return { handler: awaitingOffChainUpdate, state };
|
|
305
|
+
}
|
|
306
|
+
if (typeof signedTx === 'number') {
|
|
307
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { error: signedTx } });
|
|
308
|
+
return { handler: awaitingOffChainTx, state };
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (message.method === 'channels.error') {
|
|
312
|
+
state.reject(new ChannelConnectionError(message.data.message));
|
|
313
|
+
return { handler: channelOpen };
|
|
314
|
+
}
|
|
315
|
+
if (message.error != null) {
|
|
316
|
+
const { data } = message.error ?? { data: [] };
|
|
317
|
+
if (data.find((i) => i.code === 1001) != null) {
|
|
318
|
+
state.reject(new InsufficientBalanceError('Insufficient balance'));
|
|
319
|
+
} else if (data.find((i) => i.code === 1002) != null) {
|
|
320
|
+
state.reject(new IllegalArgumentError('Amount cannot be negative'));
|
|
321
|
+
} else {
|
|
322
|
+
state.reject(new ChannelConnectionError(message.error.message));
|
|
323
|
+
}
|
|
324
|
+
return { handler: channelOpen };
|
|
325
|
+
}
|
|
326
|
+
if (message.method === 'channels.conflict') {
|
|
327
|
+
state.resolve({
|
|
328
|
+
accepted: false,
|
|
329
|
+
errorCode: message.params.data.error_code,
|
|
330
|
+
errorMessage: message.params.data.error_msg,
|
|
331
|
+
});
|
|
332
|
+
return { handler: channelOpen };
|
|
333
|
+
}
|
|
334
|
+
if (message.method === 'channels.info') {
|
|
335
|
+
if (message.params.data.event === 'aborted_update') {
|
|
336
|
+
state.resolve({ accepted: false });
|
|
337
|
+
return { handler: channelOpen };
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export function awaitingOffChainUpdate(
|
|
344
|
+
channel: Channel,
|
|
345
|
+
message: ChannelMessage,
|
|
346
|
+
state: ChannelState,
|
|
347
|
+
): ChannelFsm | undefined {
|
|
348
|
+
if (message.method === 'channels.update') {
|
|
349
|
+
changeState(channel, message.params.data.state);
|
|
350
|
+
state.resolve({ accepted: true, signedTx: message.params.data.state });
|
|
351
|
+
return { handler: channelOpen };
|
|
352
|
+
}
|
|
353
|
+
if (message.method === 'channels.conflict') {
|
|
354
|
+
state.resolve({
|
|
355
|
+
accepted: false,
|
|
356
|
+
errorCode: message.params.data.error_code,
|
|
357
|
+
errorMessage: message.params.data.error_msg,
|
|
358
|
+
});
|
|
359
|
+
return { handler: channelOpen };
|
|
360
|
+
}
|
|
361
|
+
if (message.method === 'channels.info') {
|
|
362
|
+
if (message.params.data.event === 'aborted_update') {
|
|
363
|
+
state.resolve({ accepted: false });
|
|
364
|
+
return { handler: channelOpen };
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (message.error != null) {
|
|
368
|
+
state.reject(new ChannelConnectionError(message.error.message));
|
|
369
|
+
return { handler: channelOpen };
|
|
370
|
+
}
|
|
371
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export async function awaitingTxSignRequest(
|
|
375
|
+
channel: Channel,
|
|
376
|
+
message: ChannelMessage,
|
|
377
|
+
state: ChannelState,
|
|
378
|
+
): Promise<ChannelFsm | undefined> {
|
|
379
|
+
const [, tag] = message.method.match(/^channels\.sign\.([^.]+)$/) ?? [];
|
|
380
|
+
const channelOptions = options.get(channel);
|
|
381
|
+
if (tag != null && (channelOptions != null)) {
|
|
382
|
+
if (message.params.data.tx != null) {
|
|
383
|
+
const signedTx = await channelOptions.sign(tag, message.params.data.tx, {
|
|
384
|
+
updates: message.params.data.updates,
|
|
385
|
+
});
|
|
386
|
+
if (signedTx != null) {
|
|
387
|
+
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { tx: signedTx } });
|
|
388
|
+
return { handler: channelOpen };
|
|
389
|
+
}
|
|
390
|
+
} else {
|
|
391
|
+
const signedTx = await appendSignature(
|
|
392
|
+
message.params.data.signed_tx,
|
|
393
|
+
async (tx) => channelOptions.sign(tag, tx, { updates: message.params.data.updates }),
|
|
394
|
+
);
|
|
395
|
+
if (typeof signedTx === 'string') {
|
|
396
|
+
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { signed_tx: signedTx } });
|
|
397
|
+
return { handler: channelOpen };
|
|
398
|
+
}
|
|
399
|
+
if (typeof signedTx === 'number') {
|
|
400
|
+
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { error: signedTx } });
|
|
401
|
+
return { handler: awaitingUpdateConflict, state };
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
// soft-reject via competing update
|
|
405
|
+
send(channel, {
|
|
406
|
+
jsonrpc: '2.0',
|
|
407
|
+
method: 'channels.update.new',
|
|
408
|
+
params: {
|
|
409
|
+
from: generateKeyPair().publicKey,
|
|
410
|
+
to: generateKeyPair().publicKey,
|
|
411
|
+
amount: 1,
|
|
412
|
+
},
|
|
413
|
+
});
|
|
414
|
+
return { handler: awaitingUpdateConflict, state };
|
|
415
|
+
}
|
|
416
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
export function awaitingUpdateConflict(
|
|
420
|
+
channel: Channel,
|
|
421
|
+
message: ChannelMessage,
|
|
422
|
+
state: ChannelState,
|
|
423
|
+
): ChannelFsm {
|
|
424
|
+
if (message.error != null) {
|
|
425
|
+
return { handler: awaitingUpdateConflict, state };
|
|
426
|
+
}
|
|
427
|
+
if (message.method === 'channels.conflict') {
|
|
428
|
+
return { handler: channelOpen };
|
|
429
|
+
}
|
|
430
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export async function awaitingShutdownTx(
|
|
434
|
+
channel: Channel,
|
|
435
|
+
message: ChannelMessage,
|
|
436
|
+
state: ChannelState,
|
|
437
|
+
): Promise<ChannelFsm | undefined> {
|
|
438
|
+
if (message.method === 'channels.sign.shutdown_sign') {
|
|
439
|
+
if (message.params.data.tx != null) {
|
|
440
|
+
const signedTx = await state.sign(message.params.data.tx);
|
|
441
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.shutdown_sign', params: { tx: signedTx } });
|
|
442
|
+
return { handler: awaitingShutdownOnChainTx, state };
|
|
443
|
+
}
|
|
444
|
+
const signedTx = await appendSignature(
|
|
445
|
+
message.params.data.signed_tx,
|
|
446
|
+
async (tx) => state.sign(tx),
|
|
447
|
+
);
|
|
448
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.shutdown_sign', params: { signed_tx: signedTx } });
|
|
449
|
+
return { handler: awaitingShutdownOnChainTx, state };
|
|
450
|
+
}
|
|
451
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
export function awaitingShutdownOnChainTx(
|
|
455
|
+
channel: Channel,
|
|
456
|
+
message: ChannelMessage,
|
|
457
|
+
state: ChannelState,
|
|
458
|
+
): ChannelFsm {
|
|
459
|
+
if (message.method === 'channels.on_chain_tx') {
|
|
460
|
+
// state.resolve(message.params.data.tx)
|
|
461
|
+
return { handler: channelClosed, state };
|
|
462
|
+
}
|
|
463
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export function awaitingLeave(
|
|
467
|
+
channel: Channel,
|
|
468
|
+
message: ChannelMessage,
|
|
469
|
+
state: ChannelState,
|
|
470
|
+
): ChannelFsm {
|
|
471
|
+
if (message.method === 'channels.leave') {
|
|
472
|
+
state.resolve({ channelId: message.params.channel_id, signedTx: message.params.data.state });
|
|
473
|
+
disconnect(channel);
|
|
474
|
+
return { handler: channelClosed };
|
|
475
|
+
}
|
|
476
|
+
if (message.method === 'channels.error') {
|
|
477
|
+
state.reject(new ChannelConnectionError(message.data.message));
|
|
478
|
+
return { handler: channelOpen };
|
|
479
|
+
}
|
|
480
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
export async function awaitingWithdrawTx(
|
|
484
|
+
channel: Channel,
|
|
485
|
+
message: ChannelMessage,
|
|
486
|
+
state: ChannelState,
|
|
487
|
+
): Promise<ChannelFsm | undefined> {
|
|
488
|
+
if (message.method === 'channels.sign.withdraw_tx') {
|
|
489
|
+
const { sign } = state;
|
|
490
|
+
if (message.params.data.tx != null) {
|
|
491
|
+
const signedTx = await sign(message.params.data.tx, { updates: message.params.data.updates });
|
|
492
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.withdraw_tx', params: { tx: signedTx } });
|
|
493
|
+
return { handler: awaitingWithdrawCompletion, state };
|
|
494
|
+
}
|
|
495
|
+
const signedTx = await appendSignature(
|
|
496
|
+
message.params.data.signed_tx,
|
|
497
|
+
async (tx) => sign(tx, { updates: message.params.data.updates }),
|
|
498
|
+
);
|
|
499
|
+
if (typeof signedTx === 'string') {
|
|
500
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.withdraw_tx', params: { signed_tx: signedTx } });
|
|
501
|
+
return { handler: awaitingWithdrawCompletion, state };
|
|
502
|
+
}
|
|
503
|
+
if (typeof signedTx === 'number') {
|
|
504
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.withdraw_tx', params: { error: signedTx } });
|
|
505
|
+
return { handler: awaitingWithdrawCompletion, state };
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
export function awaitingWithdrawCompletion(
|
|
512
|
+
channel: Channel,
|
|
513
|
+
message: ChannelMessage,
|
|
514
|
+
state: ChannelState,
|
|
515
|
+
): ChannelFsm {
|
|
516
|
+
if (message.method === 'channels.on_chain_tx') {
|
|
517
|
+
state.onOnChainTx?.(message.params.data.tx);
|
|
518
|
+
return { handler: awaitingWithdrawCompletion, state };
|
|
519
|
+
}
|
|
520
|
+
if (message.method === 'channels.info') {
|
|
521
|
+
if (['own_withdraw_locked', 'withdraw_locked'].includes(message.params.data.event)) {
|
|
522
|
+
const callbacks: {
|
|
523
|
+
[key: string]: Function | undefined;
|
|
524
|
+
} = {
|
|
525
|
+
own_withdraw_locked: state.onOwnWithdrawLocked,
|
|
526
|
+
withdraw_locked: state.onWithdrawLocked,
|
|
527
|
+
};
|
|
528
|
+
callbacks[message.params.data.event]?.();
|
|
529
|
+
return { handler: awaitingWithdrawCompletion, state };
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
if (message.method === 'channels.update') {
|
|
533
|
+
changeState(channel, message.params.data.state);
|
|
534
|
+
state.resolve({ accepted: true, signedTx: message.params.data.state });
|
|
535
|
+
return { handler: channelOpen };
|
|
536
|
+
}
|
|
537
|
+
if (message.method === 'channels.conflict') {
|
|
538
|
+
state.resolve({
|
|
539
|
+
accepted: false,
|
|
540
|
+
errorCode: message.params.data.error_code,
|
|
541
|
+
errorMessage: message.params.data.error_msg,
|
|
542
|
+
});
|
|
543
|
+
return { handler: channelOpen };
|
|
544
|
+
}
|
|
545
|
+
if (message.method === 'channels.info') {
|
|
546
|
+
if (message.params.data.event === 'aborted_update') {
|
|
547
|
+
state.resolve({ accepted: false });
|
|
548
|
+
return { handler: channelOpen };
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
export async function awaitingDepositTx(
|
|
555
|
+
channel: Channel,
|
|
556
|
+
message: ChannelMessage,
|
|
557
|
+
state: ChannelState,
|
|
558
|
+
): Promise<ChannelFsm | undefined> {
|
|
559
|
+
if (message.method === 'channels.sign.deposit_tx') {
|
|
560
|
+
const { sign } = state;
|
|
561
|
+
if (message.params.data.tx != null) {
|
|
562
|
+
const signedTx = await sign(
|
|
563
|
+
message.params.data.tx,
|
|
564
|
+
{ updates: message.params.data.updates },
|
|
565
|
+
);
|
|
566
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.deposit_tx', params: { tx: signedTx } });
|
|
567
|
+
return { handler: awaitingDepositCompletion, state };
|
|
568
|
+
}
|
|
569
|
+
const signedTx = await appendSignature(
|
|
570
|
+
message.params.data.signed_tx,
|
|
571
|
+
async (tx) => sign(tx, { updates: message.params.data.updates }),
|
|
572
|
+
);
|
|
573
|
+
if (typeof signedTx === 'string') {
|
|
574
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.deposit_tx', params: { signed_tx: signedTx } });
|
|
575
|
+
return { handler: awaitingDepositCompletion, state };
|
|
576
|
+
}
|
|
577
|
+
if (typeof signedTx === 'number') {
|
|
578
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.deposit_tx', params: { error: signedTx } });
|
|
579
|
+
return { handler: awaitingDepositCompletion, state };
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
export function awaitingDepositCompletion(
|
|
586
|
+
channel: Channel,
|
|
587
|
+
message: ChannelMessage,
|
|
588
|
+
state: ChannelState,
|
|
589
|
+
): ChannelFsm {
|
|
590
|
+
if (message.method === 'channels.on_chain_tx') {
|
|
591
|
+
state.onOnChainTx?.(message.params.data.tx);
|
|
592
|
+
return { handler: awaitingDepositCompletion, state };
|
|
593
|
+
}
|
|
594
|
+
if (message.method === 'channels.info') {
|
|
595
|
+
if (['own_deposit_locked', 'deposit_locked'].includes(message.params.data.event)) {
|
|
596
|
+
const callbacks: {
|
|
597
|
+
[key: string]: Function | undefined;
|
|
598
|
+
} = {
|
|
599
|
+
own_deposit_locked: state.onOwnDepositLocked,
|
|
600
|
+
deposit_locked: state.onDepositLocked,
|
|
601
|
+
};
|
|
602
|
+
callbacks[message.params.data.event]?.();
|
|
603
|
+
return { handler: awaitingDepositCompletion, state };
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
if (message.method === 'channels.update') {
|
|
607
|
+
changeState(channel, message.params.data.state);
|
|
608
|
+
state.resolve({ accepted: true, signedTx: message.params.data.state });
|
|
609
|
+
return { handler: channelOpen };
|
|
610
|
+
}
|
|
611
|
+
if (message.method === 'channels.conflict') {
|
|
612
|
+
state.resolve({
|
|
613
|
+
accepted: false,
|
|
614
|
+
errorCode: message.params.data.error_code,
|
|
615
|
+
errorMessage: message.params.data.error_msg,
|
|
616
|
+
});
|
|
617
|
+
return { handler: channelOpen };
|
|
618
|
+
}
|
|
619
|
+
if (message.method === 'channels.info') {
|
|
620
|
+
if (message.params.data.event === 'aborted_update') {
|
|
621
|
+
state.resolve({ accepted: false });
|
|
622
|
+
return { handler: channelOpen };
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
export async function awaitingNewContractTx(
|
|
629
|
+
channel: Channel,
|
|
630
|
+
message: ChannelMessage,
|
|
631
|
+
state: ChannelState,
|
|
632
|
+
): Promise<ChannelFsm | undefined> {
|
|
633
|
+
if (message.method === 'channels.sign.update') {
|
|
634
|
+
if (message.params.data.tx != null) {
|
|
635
|
+
const signedTx = await state.sign(message.params.data.tx);
|
|
636
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { tx: signedTx } });
|
|
637
|
+
return { handler: awaitingNewContractCompletion, state };
|
|
638
|
+
}
|
|
639
|
+
const signedTx = await appendSignature(
|
|
640
|
+
message.params.data.signed_tx,
|
|
641
|
+
async (tx) => state.sign(tx),
|
|
642
|
+
);
|
|
643
|
+
if (typeof signedTx === 'string') {
|
|
644
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { signed_tx: signedTx } });
|
|
645
|
+
return { handler: awaitingNewContractCompletion, state };
|
|
646
|
+
}
|
|
647
|
+
if (typeof signedTx === 'number') {
|
|
648
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { error: signedTx } });
|
|
649
|
+
return { handler: awaitingNewContractCompletion, state };
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
export function awaitingNewContractCompletion(
|
|
656
|
+
channel: Channel,
|
|
657
|
+
message: ChannelMessage,
|
|
658
|
+
state: ChannelState,
|
|
659
|
+
): ChannelFsm {
|
|
660
|
+
const channelOptions = options.get(channel);
|
|
661
|
+
if (message.method === 'channels.update') {
|
|
662
|
+
const { round } = unpackTx(message.params.data.state, Tag.SignedTx).tx.encodedTx.tx;
|
|
663
|
+
if (channelOptions?.role != null) {
|
|
664
|
+
let role: null | 'initiatorId' | 'responderId' = null;
|
|
665
|
+
if (channelOptions.role === 'initiator') role = 'initiatorId';
|
|
666
|
+
if (channelOptions.role === 'responder') role = 'responderId';
|
|
667
|
+
if (role != null) {
|
|
668
|
+
const owner = channelOptions?.[role];
|
|
669
|
+
changeState(channel, message.params.data.state);
|
|
670
|
+
state.resolve({
|
|
671
|
+
accepted: true,
|
|
672
|
+
address: encodeContractAddress(owner, round),
|
|
673
|
+
signedTx: message.params.data.state,
|
|
674
|
+
});
|
|
675
|
+
return { handler: channelOpen };
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
if (message.method === 'channels.conflict') {
|
|
680
|
+
state.resolve({
|
|
681
|
+
accepted: false,
|
|
682
|
+
errorCode: message.params.data.error_code,
|
|
683
|
+
errorMessage: message.params.data.error_msg,
|
|
684
|
+
});
|
|
685
|
+
return { handler: channelOpen };
|
|
686
|
+
}
|
|
687
|
+
if (message.method === 'channels.info') {
|
|
688
|
+
if (message.params.data.event === 'aborted_update') {
|
|
689
|
+
state.resolve({ accepted: false });
|
|
690
|
+
return { handler: channelOpen };
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
export async function awaitingCallContractUpdateTx(
|
|
697
|
+
channel: Channel,
|
|
698
|
+
message: ChannelMessage,
|
|
699
|
+
state: ChannelState,
|
|
700
|
+
): Promise<ChannelFsm | undefined> {
|
|
701
|
+
if (message.method === 'channels.sign.update') {
|
|
702
|
+
if (message.params.data.tx != null) {
|
|
703
|
+
const signedTx = await state.sign(
|
|
704
|
+
message.params.data.tx,
|
|
705
|
+
{ updates: message.params.data.updates },
|
|
706
|
+
);
|
|
707
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { tx: signedTx } });
|
|
708
|
+
return { handler: awaitingCallContractCompletion, state };
|
|
709
|
+
}
|
|
710
|
+
const signedTx = await appendSignature(
|
|
711
|
+
message.params.data.signed_tx,
|
|
712
|
+
async (tx) => state.sign(tx, { updates: message.params.data.updates }),
|
|
713
|
+
);
|
|
714
|
+
if (typeof signedTx === 'string') {
|
|
715
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { signed_tx: signedTx } });
|
|
716
|
+
return { handler: awaitingCallContractCompletion, state };
|
|
717
|
+
}
|
|
718
|
+
if (typeof signedTx === 'number') {
|
|
719
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { error: signedTx } });
|
|
720
|
+
return { handler: awaitingCallContractCompletion, state };
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
export async function awaitingCallContractForceProgressUpdate(
|
|
727
|
+
channel: Channel,
|
|
728
|
+
message: ChannelMessage,
|
|
729
|
+
state: ChannelState,
|
|
730
|
+
): Promise<ChannelFsm | undefined> {
|
|
731
|
+
if (message.method === 'channels.sign.force_progress_tx') {
|
|
732
|
+
const signedTx = await appendSignature(
|
|
733
|
+
message.params.data.signed_tx,
|
|
734
|
+
async (tx) => state.sign(tx, { updates: message.params.data.updates }),
|
|
735
|
+
);
|
|
736
|
+
send(
|
|
737
|
+
channel,
|
|
738
|
+
{ jsonrpc: '2.0', method: 'channels.force_progress_sign', params: { signed_tx: signedTx } },
|
|
739
|
+
);
|
|
740
|
+
return { handler: awaitingForceProgressCompletion, state };
|
|
741
|
+
}
|
|
742
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
export function awaitingForceProgressCompletion(
|
|
746
|
+
channel: Channel,
|
|
747
|
+
message: ChannelMessage,
|
|
748
|
+
state: ChannelState,
|
|
749
|
+
): ChannelFsm {
|
|
750
|
+
if (message.method === 'channels.on_chain_tx') {
|
|
751
|
+
state.onOnChainTx?.(message.params.data.tx);
|
|
752
|
+
emit(channel, 'onChainTx', message.params.data.tx, {
|
|
753
|
+
info: message.params.data.info,
|
|
754
|
+
type: message.params.data.type,
|
|
755
|
+
});
|
|
756
|
+
state.resolve({ accepted: true, tx: message.params.data.tx });
|
|
757
|
+
}
|
|
758
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
export function awaitingCallContractCompletion(
|
|
762
|
+
channel: Channel,
|
|
763
|
+
message: ChannelMessage,
|
|
764
|
+
state: ChannelState,
|
|
765
|
+
): ChannelFsm {
|
|
766
|
+
if (message.method === 'channels.update') {
|
|
767
|
+
changeState(channel, message.params.data.state);
|
|
768
|
+
state.resolve({ accepted: true, signedTx: message.params.data.state });
|
|
769
|
+
return { handler: channelOpen };
|
|
770
|
+
}
|
|
771
|
+
if (message.method === 'channels.conflict') {
|
|
772
|
+
state.resolve({
|
|
773
|
+
accepted: false,
|
|
774
|
+
errorCode: message.params.data.error_code,
|
|
775
|
+
errorMessage: message.params.data.error_msg,
|
|
776
|
+
});
|
|
777
|
+
return { handler: channelOpen };
|
|
778
|
+
}
|
|
779
|
+
if (message.method === 'channels.info') {
|
|
780
|
+
if (message.params.data.event === 'aborted_update') {
|
|
781
|
+
state.resolve({ accepted: false });
|
|
782
|
+
return { handler: channelOpen };
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
export function awaitingCallsPruned(
|
|
789
|
+
_channels: Channel[],
|
|
790
|
+
message: ChannelMessage,
|
|
791
|
+
state: ChannelState,
|
|
792
|
+
): ChannelFsm {
|
|
793
|
+
if (message.method === 'channels.calls_pruned.reply') {
|
|
794
|
+
state.resolve();
|
|
795
|
+
return { handler: channelOpen };
|
|
796
|
+
}
|
|
797
|
+
state.reject(new UnexpectedChannelMessageError('Unexpected message received'));
|
|
798
|
+
return { handler: channelClosed };
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
export function channelClosed(
|
|
802
|
+
_channel: Channel,
|
|
803
|
+
message: ChannelMessage,
|
|
804
|
+
state: ChannelState,
|
|
805
|
+
): ChannelFsm {
|
|
806
|
+
if (state == null) return { handler: channelClosed };
|
|
807
|
+
if (message.params.data.event === 'closing') return { handler: channelClosed, state };
|
|
808
|
+
if (message.params.data.info === 'channel_closed') {
|
|
809
|
+
state.closeTx = message.params.data.tx;
|
|
810
|
+
return { handler: channelClosed, state };
|
|
811
|
+
}
|
|
812
|
+
if (message.params.data.event === 'closed_confirmed') {
|
|
813
|
+
state.resolve(state.closeTx);
|
|
814
|
+
return { handler: channelClosed };
|
|
815
|
+
}
|
|
816
|
+
return { handler: channelClosed, state };
|
|
817
|
+
}
|