@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
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import { generateKeyPair, encodeContractAddress } from '../utils/crypto'
|
|
19
19
|
import {
|
|
20
|
+
ChannelState,
|
|
20
21
|
options,
|
|
21
22
|
changeStatus,
|
|
22
23
|
changeState,
|
|
@@ -25,32 +26,42 @@ import {
|
|
|
25
26
|
emit,
|
|
26
27
|
channelId,
|
|
27
28
|
disconnect,
|
|
28
|
-
fsmId
|
|
29
|
+
fsmId,
|
|
30
|
+
ChannelMessage,
|
|
31
|
+
ChannelFsm,
|
|
32
|
+
SignTx
|
|
29
33
|
} from './internal'
|
|
30
34
|
import { unpackTx, buildTx } from '../tx/builder'
|
|
31
35
|
import { encode } from '../tx/builder/helpers'
|
|
36
|
+
import { EncodedData } from '../utils/encoder'
|
|
32
37
|
import {
|
|
33
38
|
IllegalArgumentError,
|
|
34
39
|
InsufficientBalanceError,
|
|
35
40
|
ChannelConnectionError,
|
|
36
41
|
UnexpectedChannelMessageError
|
|
37
42
|
} from '../utils/errors'
|
|
43
|
+
import Channel from '.'
|
|
44
|
+
import { TX_TYPE } from '../tx/builder/schema'
|
|
38
45
|
|
|
39
|
-
async function appendSignature (
|
|
40
|
-
|
|
46
|
+
export async function appendSignature (
|
|
47
|
+
tx: EncodedData<'tx'>, signFn: SignTx
|
|
48
|
+
): Promise<EncodedData<'tx'> | number | null> {
|
|
49
|
+
const { signatures, encodedTx } = unpackTx(tx, TX_TYPE.signed).tx
|
|
41
50
|
const result = await signFn(encode(encodedTx.rlpEncoded, 'tx'))
|
|
42
51
|
if (typeof result === 'string') {
|
|
43
|
-
const { tx: signedTx
|
|
52
|
+
const { tx: signedTx } = unpackTx(result, TX_TYPE.signed)
|
|
44
53
|
return buildTx({
|
|
45
54
|
signatures: signatures.concat(signedTx.signatures),
|
|
46
55
|
encodedTx: signedTx.encodedTx.rlpEncoded
|
|
47
|
-
},
|
|
56
|
+
}, TX_TYPE.signed).tx
|
|
48
57
|
}
|
|
49
58
|
return result
|
|
50
59
|
}
|
|
51
60
|
|
|
52
|
-
function handleUnexpectedMessage (
|
|
53
|
-
|
|
61
|
+
function handleUnexpectedMessage (
|
|
62
|
+
_channel: Channel, message: ChannelMessage, state: ChannelState
|
|
63
|
+
): ChannelFsm {
|
|
64
|
+
if (state?.reject != null) {
|
|
54
65
|
state.reject(Object.assign(
|
|
55
66
|
new UnexpectedChannelMessageError(`Unexpected message received:\n\n${JSON.stringify(message)}`),
|
|
56
67
|
{ wsMessage: message }
|
|
@@ -59,13 +70,16 @@ function handleUnexpectedMessage (channel, message, state) {
|
|
|
59
70
|
return { handler: channelOpen }
|
|
60
71
|
}
|
|
61
72
|
|
|
62
|
-
export function awaitingConnection (
|
|
73
|
+
export function awaitingConnection (
|
|
74
|
+
channel: Channel, message: ChannelMessage
|
|
75
|
+
): ChannelFsm | undefined {
|
|
63
76
|
if (message.method === 'channels.info') {
|
|
64
|
-
|
|
77
|
+
const channelInfoStatus: string = message.params.data.event
|
|
78
|
+
if (['channel_accept', 'funding_created'].includes(channelInfoStatus)) {
|
|
65
79
|
changeStatus(channel, {
|
|
66
80
|
channel_accept: 'accepted',
|
|
67
81
|
funding_created: 'halfSigned'
|
|
68
|
-
}[
|
|
82
|
+
}[channelInfoStatus as 'channel_accept' | 'funding_created'])
|
|
69
83
|
return { handler: awaitingChannelCreateTx }
|
|
70
84
|
}
|
|
71
85
|
if (message.params.data.event === 'channel_reestablished') {
|
|
@@ -78,12 +92,14 @@ export function awaitingConnection (channel, message, state) {
|
|
|
78
92
|
return { handler: awaitingConnection }
|
|
79
93
|
}
|
|
80
94
|
if (message.method === 'channels.error') {
|
|
81
|
-
emit(channel, 'error', new ChannelConnectionError(message
|
|
95
|
+
emit(channel, 'error', new ChannelConnectionError(message?.payload?.message))
|
|
82
96
|
return { handler: channelClosed }
|
|
83
97
|
}
|
|
84
98
|
}
|
|
85
99
|
|
|
86
|
-
export async function awaitingReconnection (
|
|
100
|
+
export async function awaitingReconnection (
|
|
101
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
102
|
+
): Promise<ChannelFsm> {
|
|
87
103
|
if (message.method === 'channels.info') {
|
|
88
104
|
if (message.params.data.event === 'fsm_up') {
|
|
89
105
|
fsmId.set(channel, message.params.data.fsm_id)
|
|
@@ -94,59 +110,74 @@ export async function awaitingReconnection (channel, message, state) {
|
|
|
94
110
|
return handleUnexpectedMessage(channel, message, state)
|
|
95
111
|
}
|
|
96
112
|
|
|
97
|
-
export async function awaitingChannelCreateTx (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
113
|
+
export async function awaitingChannelCreateTx (
|
|
114
|
+
channel: Channel, message: ChannelMessage
|
|
115
|
+
): Promise<ChannelFsm | undefined> {
|
|
116
|
+
const channelOptions = options.get(channel)
|
|
117
|
+
if (channelOptions != null) {
|
|
118
|
+
const tag = {
|
|
119
|
+
initiator: 'initiator_sign',
|
|
120
|
+
responder: 'responder_sign'
|
|
121
|
+
}[channelOptions.role]
|
|
122
|
+
if (message.method === `channels.sign.${tag}`) {
|
|
123
|
+
if (message.params.data.tx != null) {
|
|
124
|
+
const signedTx = await channelOptions.sign(tag, message.params.data.tx)
|
|
125
|
+
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { tx: signedTx } })
|
|
126
|
+
return { handler: awaitingOnChainTx }
|
|
127
|
+
}
|
|
128
|
+
const signedTx = await appendSignature(
|
|
129
|
+
message.params.data.signed_tx, async tx => await channelOptions.sign(tag, tx)
|
|
130
|
+
)
|
|
131
|
+
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { signed_tx: signedTx } })
|
|
106
132
|
return { handler: awaitingOnChainTx }
|
|
107
133
|
}
|
|
108
|
-
const signedTx = await appendSignature(
|
|
109
|
-
message.params.data.signed_tx, tx => options.get(channel).sign(tag, tx)
|
|
110
|
-
)
|
|
111
|
-
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { signed_tx: signedTx } })
|
|
112
|
-
return { handler: awaitingOnChainTx }
|
|
113
134
|
}
|
|
114
135
|
}
|
|
115
136
|
|
|
116
|
-
export function awaitingOnChainTx (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
) {
|
|
122
|
-
|
|
137
|
+
export function awaitingOnChainTx (
|
|
138
|
+
channel: Channel, message: ChannelMessage
|
|
139
|
+
): ChannelFsm | undefined {
|
|
140
|
+
const channelOptions = options.get(channel)
|
|
141
|
+
if (channelOptions != null) {
|
|
142
|
+
if (message.method === 'channels.on_chain_tx') {
|
|
143
|
+
if (
|
|
144
|
+
message.params.data.info === 'funding_signed' &&
|
|
145
|
+
channelOptions.role === 'initiator'
|
|
146
|
+
) {
|
|
147
|
+
return { handler: awaitingBlockInclusion }
|
|
148
|
+
}
|
|
149
|
+
if (
|
|
150
|
+
message.params.data.info === 'funding_created' &&
|
|
151
|
+
channelOptions.role === 'responder'
|
|
152
|
+
) {
|
|
153
|
+
return { handler: awaitingBlockInclusion }
|
|
154
|
+
}
|
|
123
155
|
}
|
|
124
156
|
if (
|
|
125
|
-
message.
|
|
126
|
-
|
|
157
|
+
message.method === 'channels.info' &&
|
|
158
|
+
message.params.data.event === 'funding_signed' &&
|
|
159
|
+
channelOptions.role === 'initiator'
|
|
127
160
|
) {
|
|
128
|
-
|
|
161
|
+
channelId.set(channel, message.params.channel_id)
|
|
162
|
+
changeStatus(channel, 'signed')
|
|
163
|
+
return { handler: awaitingOnChainTx }
|
|
129
164
|
}
|
|
130
165
|
}
|
|
131
|
-
if (
|
|
132
|
-
message.method === 'channels.info' &&
|
|
133
|
-
message.params.data.event === 'funding_signed' &&
|
|
134
|
-
options.get(channel).role === 'initiator'
|
|
135
|
-
) {
|
|
136
|
-
channelId.set(channel, message.params.channel_id)
|
|
137
|
-
changeStatus(channel, 'signed')
|
|
138
|
-
return { handler: awaitingOnChainTx }
|
|
139
|
-
}
|
|
140
166
|
}
|
|
141
167
|
|
|
142
|
-
export function awaitingBlockInclusion (
|
|
168
|
+
export function awaitingBlockInclusion (
|
|
169
|
+
channel: Channel, message: ChannelMessage
|
|
170
|
+
): ChannelFsm | undefined {
|
|
143
171
|
if (message.method === 'channels.info') {
|
|
144
|
-
const
|
|
172
|
+
const handlers: {
|
|
173
|
+
[key: string]: (channel: Channel, message: ChannelMessage) => ChannelFsm | undefined
|
|
174
|
+
} = {
|
|
145
175
|
funding_created: awaitingBlockInclusion,
|
|
146
176
|
own_funding_locked: awaitingBlockInclusion,
|
|
147
177
|
funding_locked: awaitingOpenConfirmation
|
|
148
|
-
}
|
|
149
|
-
|
|
178
|
+
}
|
|
179
|
+
const handler = handlers[message.params.data.event as string]
|
|
180
|
+
if (handler != null) {
|
|
150
181
|
return { handler }
|
|
151
182
|
}
|
|
152
183
|
}
|
|
@@ -159,21 +190,27 @@ export function awaitingBlockInclusion (channel, message, state) {
|
|
|
159
190
|
}
|
|
160
191
|
}
|
|
161
192
|
|
|
162
|
-
export function awaitingOpenConfirmation (
|
|
193
|
+
export function awaitingOpenConfirmation (
|
|
194
|
+
channel: Channel, message: ChannelMessage
|
|
195
|
+
): ChannelFsm | undefined {
|
|
163
196
|
if (message.method === 'channels.info' && message.params.data.event === 'open') {
|
|
164
197
|
channelId.set(channel, message.params.channel_id)
|
|
165
198
|
return { handler: awaitingInitialState }
|
|
166
199
|
}
|
|
167
200
|
}
|
|
168
201
|
|
|
169
|
-
export function awaitingInitialState (
|
|
202
|
+
export function awaitingInitialState (
|
|
203
|
+
channel: Channel, message: ChannelMessage
|
|
204
|
+
): ChannelFsm | undefined {
|
|
170
205
|
if (message.method === 'channels.update') {
|
|
171
206
|
changeState(channel, message.params.data.state)
|
|
172
207
|
return { handler: channelOpen }
|
|
173
208
|
}
|
|
174
209
|
}
|
|
175
210
|
|
|
176
|
-
export async function channelOpen (
|
|
211
|
+
export async function channelOpen (
|
|
212
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
213
|
+
): Promise<ChannelFsm | undefined> {
|
|
177
214
|
switch (message.method) {
|
|
178
215
|
case 'channels.info':
|
|
179
216
|
switch (message.params.data.event) {
|
|
@@ -226,23 +263,26 @@ export async function channelOpen (channel, message, state) {
|
|
|
226
263
|
changeState(channel, message.params.data.state)
|
|
227
264
|
return { handler: channelOpen }
|
|
228
265
|
case 'channels.sign.shutdown_sign_ack':
|
|
229
|
-
return awaitingTxSignRequest(channel, message, state)
|
|
266
|
+
return await awaitingTxSignRequest(channel, message, state)
|
|
230
267
|
}
|
|
231
268
|
}
|
|
232
|
-
channelOpen.enter = (channel) => {
|
|
269
|
+
channelOpen.enter = (channel: Channel) => {
|
|
233
270
|
changeStatus(channel, 'open')
|
|
234
271
|
}
|
|
235
272
|
|
|
236
|
-
export async function awaitingOffChainTx (
|
|
273
|
+
export async function awaitingOffChainTx (
|
|
274
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
275
|
+
): Promise<ChannelFsm> {
|
|
237
276
|
if (message.method === 'channels.sign.update') {
|
|
238
277
|
const { sign } = state
|
|
239
|
-
if (message.params.data.tx) {
|
|
240
|
-
const signedTx =
|
|
278
|
+
if (message.params.data.tx != null) {
|
|
279
|
+
const signedTx =
|
|
280
|
+
await sign(message.params.data.tx, { updates: message.params.data.updates })
|
|
241
281
|
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { tx: signedTx } })
|
|
242
282
|
return { handler: awaitingOffChainUpdate, state }
|
|
243
283
|
}
|
|
244
|
-
const signedTx = await appendSignature(message.params.data.signed_tx, tx =>
|
|
245
|
-
sign(tx, { updates: message.params.data.updates })
|
|
284
|
+
const signedTx = await appendSignature(message.params.data.signed_tx, async tx =>
|
|
285
|
+
await sign(tx, { updates: message.params.data.updates })
|
|
246
286
|
)
|
|
247
287
|
if (typeof signedTx === 'string') {
|
|
248
288
|
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { signed_tx: signedTx } })
|
|
@@ -257,11 +297,11 @@ export async function awaitingOffChainTx (channel, message, state) {
|
|
|
257
297
|
state.reject(new ChannelConnectionError(message.data.message))
|
|
258
298
|
return { handler: channelOpen }
|
|
259
299
|
}
|
|
260
|
-
if (message.error) {
|
|
261
|
-
const { data
|
|
262
|
-
if (data.find(i => i.code === 1001)) {
|
|
300
|
+
if (message.error != null) {
|
|
301
|
+
const { data } = message.error ?? { data: [] }
|
|
302
|
+
if (data.find(i => i.code === 1001) != null) {
|
|
263
303
|
state.reject(new InsufficientBalanceError('Insufficient balance'))
|
|
264
|
-
} else if (data.find(i => i.code === 1002)) {
|
|
304
|
+
} else if (data.find(i => i.code === 1002) != null) {
|
|
265
305
|
state.reject(new IllegalArgumentError('Amount cannot be negative'))
|
|
266
306
|
} else {
|
|
267
307
|
state.reject(new ChannelConnectionError(message.error.message))
|
|
@@ -285,7 +325,9 @@ export async function awaitingOffChainTx (channel, message, state) {
|
|
|
285
325
|
return handleUnexpectedMessage(channel, message, state)
|
|
286
326
|
}
|
|
287
327
|
|
|
288
|
-
export function awaitingOffChainUpdate (
|
|
328
|
+
export function awaitingOffChainUpdate (
|
|
329
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
330
|
+
): ChannelFsm | undefined {
|
|
289
331
|
if (message.method === 'channels.update') {
|
|
290
332
|
changeState(channel, message.params.data.state)
|
|
291
333
|
state.resolve({ accepted: true, signedTx: message.params.data.state })
|
|
@@ -305,27 +347,30 @@ export function awaitingOffChainUpdate (channel, message, state) {
|
|
|
305
347
|
return { handler: channelOpen }
|
|
306
348
|
}
|
|
307
349
|
}
|
|
308
|
-
if (message.error) {
|
|
350
|
+
if (message.error != null) {
|
|
309
351
|
state.reject(new ChannelConnectionError(message.error.message))
|
|
310
352
|
return { handler: channelOpen }
|
|
311
353
|
}
|
|
312
354
|
return handleUnexpectedMessage(channel, message, state)
|
|
313
355
|
}
|
|
314
356
|
|
|
315
|
-
export async function awaitingTxSignRequest (
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
357
|
+
export async function awaitingTxSignRequest (
|
|
358
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
359
|
+
): Promise<ChannelFsm | undefined> {
|
|
360
|
+
const [, tag] = message.method.match(/^channels\.sign\.([^.]+)$/) ?? []
|
|
361
|
+
const channelOptions = options.get(channel)
|
|
362
|
+
if (tag != null && (channelOptions != null)) {
|
|
363
|
+
if (message.params.data.tx != null) {
|
|
364
|
+
const signedTx = await channelOptions.sign(tag, message.params.data.tx, {
|
|
320
365
|
updates: message.params.data.updates
|
|
321
366
|
})
|
|
322
|
-
if (signedTx) {
|
|
367
|
+
if (signedTx != null) {
|
|
323
368
|
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { tx: signedTx } })
|
|
324
369
|
return { handler: channelOpen }
|
|
325
370
|
}
|
|
326
371
|
} else {
|
|
327
|
-
const signedTx = await appendSignature(message.params.data.signed_tx, tx =>
|
|
328
|
-
|
|
372
|
+
const signedTx = await appendSignature(message.params.data.signed_tx, async tx =>
|
|
373
|
+
await channelOptions.sign(tag, tx, { updates: message.params.data.updates })
|
|
329
374
|
)
|
|
330
375
|
if (typeof signedTx === 'string') {
|
|
331
376
|
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { signed_tx: signedTx } })
|
|
@@ -351,8 +396,10 @@ export async function awaitingTxSignRequest (channel, message, state) {
|
|
|
351
396
|
return handleUnexpectedMessage(channel, message, state)
|
|
352
397
|
}
|
|
353
398
|
|
|
354
|
-
export function awaitingUpdateConflict (
|
|
355
|
-
|
|
399
|
+
export function awaitingUpdateConflict (
|
|
400
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
401
|
+
): ChannelFsm {
|
|
402
|
+
if (message.error != null) {
|
|
356
403
|
return { handler: awaitingUpdateConflict, state }
|
|
357
404
|
}
|
|
358
405
|
if (message.method === 'channels.conflict') {
|
|
@@ -361,21 +408,26 @@ export function awaitingUpdateConflict (channel, message, state) {
|
|
|
361
408
|
return handleUnexpectedMessage(channel, message, state)
|
|
362
409
|
}
|
|
363
410
|
|
|
364
|
-
export async function awaitingShutdownTx (
|
|
411
|
+
export async function awaitingShutdownTx (
|
|
412
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
413
|
+
): Promise<ChannelFsm | undefined> {
|
|
365
414
|
if (message.method === 'channels.sign.shutdown_sign') {
|
|
366
|
-
if (message.params.data.tx) {
|
|
415
|
+
if (message.params.data.tx != null) {
|
|
367
416
|
const signedTx = await state.sign(message.params.data.tx)
|
|
368
417
|
send(channel, { jsonrpc: '2.0', method: 'channels.shutdown_sign', params: { tx: signedTx } })
|
|
369
418
|
return { handler: awaitingShutdownOnChainTx, state }
|
|
370
419
|
}
|
|
371
|
-
const signedTx = await appendSignature(message.params.data.signed_tx, tx =>
|
|
420
|
+
const signedTx = await appendSignature(message.params.data.signed_tx, async tx =>
|
|
421
|
+
await state.sign(tx))
|
|
372
422
|
send(channel, { jsonrpc: '2.0', method: 'channels.shutdown_sign', params: { signed_tx: signedTx } })
|
|
373
423
|
return { handler: awaitingShutdownOnChainTx, state }
|
|
374
424
|
}
|
|
375
425
|
return handleUnexpectedMessage(channel, message, state)
|
|
376
426
|
}
|
|
377
427
|
|
|
378
|
-
export function awaitingShutdownOnChainTx (
|
|
428
|
+
export function awaitingShutdownOnChainTx (
|
|
429
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
430
|
+
): ChannelFsm {
|
|
379
431
|
if (message.method === 'channels.on_chain_tx') {
|
|
380
432
|
// state.resolve(message.params.data.tx)
|
|
381
433
|
return { handler: channelClosed, state }
|
|
@@ -383,7 +435,9 @@ export function awaitingShutdownOnChainTx (channel, message, state) {
|
|
|
383
435
|
return handleUnexpectedMessage(channel, message, state)
|
|
384
436
|
}
|
|
385
437
|
|
|
386
|
-
export function awaitingLeave (
|
|
438
|
+
export function awaitingLeave (
|
|
439
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
440
|
+
): ChannelFsm {
|
|
387
441
|
if (message.method === 'channels.leave') {
|
|
388
442
|
state.resolve({ channelId: message.params.channel_id, signedTx: message.params.data.state })
|
|
389
443
|
disconnect(channel)
|
|
@@ -396,16 +450,19 @@ export function awaitingLeave (channel, message, state) {
|
|
|
396
450
|
return handleUnexpectedMessage(channel, message, state)
|
|
397
451
|
}
|
|
398
452
|
|
|
399
|
-
export async function awaitingWithdrawTx (
|
|
453
|
+
export async function awaitingWithdrawTx (
|
|
454
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
455
|
+
): Promise<ChannelFsm | undefined> {
|
|
400
456
|
if (message.method === 'channels.sign.withdraw_tx') {
|
|
401
457
|
const { sign } = state
|
|
402
|
-
if (message.params.data.tx) {
|
|
403
|
-
const signedTx =
|
|
458
|
+
if (message.params.data.tx != null) {
|
|
459
|
+
const signedTx =
|
|
460
|
+
await sign(message.params.data.tx, { updates: message.params.data.updates })
|
|
404
461
|
send(channel, { jsonrpc: '2.0', method: 'channels.withdraw_tx', params: { tx: signedTx } })
|
|
405
462
|
return { handler: awaitingWithdrawCompletion, state }
|
|
406
463
|
}
|
|
407
|
-
const signedTx = await appendSignature(message.params.data.signed_tx, tx =>
|
|
408
|
-
sign(tx, { updates: message.params.data.updates })
|
|
464
|
+
const signedTx = await appendSignature(message.params.data.signed_tx, async tx =>
|
|
465
|
+
await sign(tx, { updates: message.params.data.updates })
|
|
409
466
|
)
|
|
410
467
|
if (typeof signedTx === 'string') {
|
|
411
468
|
send(channel, { jsonrpc: '2.0', method: 'channels.withdraw_tx', params: { signed_tx: signedTx } })
|
|
@@ -419,20 +476,25 @@ export async function awaitingWithdrawTx (channel, message, state) {
|
|
|
419
476
|
return handleUnexpectedMessage(channel, message, state)
|
|
420
477
|
}
|
|
421
478
|
|
|
422
|
-
export function awaitingWithdrawCompletion (
|
|
479
|
+
export function awaitingWithdrawCompletion (
|
|
480
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
481
|
+
): ChannelFsm {
|
|
423
482
|
if (message.method === 'channels.on_chain_tx') {
|
|
424
|
-
if (state.onOnChainTx) {
|
|
483
|
+
if (state.onOnChainTx != null) {
|
|
425
484
|
state.onOnChainTx(message.params.data.tx)
|
|
426
485
|
}
|
|
427
486
|
return { handler: awaitingWithdrawCompletion, state }
|
|
428
487
|
}
|
|
429
488
|
if (message.method === 'channels.info') {
|
|
430
489
|
if (['own_withdraw_locked', 'withdraw_locked'].includes(message.params.data.event)) {
|
|
431
|
-
const
|
|
490
|
+
const callbacks: {
|
|
491
|
+
[key: string]: Function | undefined
|
|
492
|
+
} = {
|
|
432
493
|
own_withdraw_locked: state.onOwnWithdrawLocked,
|
|
433
494
|
withdraw_locked: state.onWithdrawLocked
|
|
434
|
-
}
|
|
435
|
-
|
|
495
|
+
}
|
|
496
|
+
const callback = callbacks[message.params.data.event]
|
|
497
|
+
if (callback != null) {
|
|
436
498
|
callback()
|
|
437
499
|
}
|
|
438
500
|
return { handler: awaitingWithdrawCompletion, state }
|
|
@@ -460,16 +522,19 @@ export function awaitingWithdrawCompletion (channel, message, state) {
|
|
|
460
522
|
return handleUnexpectedMessage(channel, message, state)
|
|
461
523
|
}
|
|
462
524
|
|
|
463
|
-
export async function awaitingDepositTx (
|
|
525
|
+
export async function awaitingDepositTx (
|
|
526
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
527
|
+
): Promise<ChannelFsm | undefined> {
|
|
464
528
|
if (message.method === 'channels.sign.deposit_tx') {
|
|
465
529
|
const { sign } = state
|
|
466
|
-
if (message.params.data.tx) {
|
|
467
|
-
const signedTx = await sign(message.params.data.tx,
|
|
530
|
+
if (message.params.data.tx != null) {
|
|
531
|
+
const signedTx = await sign(message.params.data.tx,
|
|
532
|
+
{ updates: message.params.data.updates })
|
|
468
533
|
send(channel, { jsonrpc: '2.0', method: 'channels.deposit_tx', params: { tx: signedTx } })
|
|
469
534
|
return { handler: awaitingDepositCompletion, state }
|
|
470
535
|
}
|
|
471
|
-
const signedTx = await appendSignature(message.params.data.signed_tx, tx =>
|
|
472
|
-
sign(tx, { updates: message.params.data.updates })
|
|
536
|
+
const signedTx = await appendSignature(message.params.data.signed_tx, async tx =>
|
|
537
|
+
await sign(tx, { updates: message.params.data.updates })
|
|
473
538
|
)
|
|
474
539
|
if (typeof signedTx === 'string') {
|
|
475
540
|
send(channel, { jsonrpc: '2.0', method: 'channels.deposit_tx', params: { signed_tx: signedTx } })
|
|
@@ -483,20 +548,25 @@ export async function awaitingDepositTx (channel, message, state) {
|
|
|
483
548
|
return handleUnexpectedMessage(channel, message, state)
|
|
484
549
|
}
|
|
485
550
|
|
|
486
|
-
export function awaitingDepositCompletion (
|
|
551
|
+
export function awaitingDepositCompletion (
|
|
552
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
553
|
+
): ChannelFsm {
|
|
487
554
|
if (message.method === 'channels.on_chain_tx') {
|
|
488
|
-
if (state.onOnChainTx) {
|
|
555
|
+
if (state.onOnChainTx != null) {
|
|
489
556
|
state.onOnChainTx(message.params.data.tx)
|
|
490
557
|
}
|
|
491
558
|
return { handler: awaitingDepositCompletion, state }
|
|
492
559
|
}
|
|
493
560
|
if (message.method === 'channels.info') {
|
|
494
561
|
if (['own_deposit_locked', 'deposit_locked'].includes(message.params.data.event)) {
|
|
495
|
-
const
|
|
562
|
+
const callbacks: {
|
|
563
|
+
[key: string]: Function | undefined
|
|
564
|
+
} = {
|
|
496
565
|
own_deposit_locked: state.onOwnDepositLocked,
|
|
497
566
|
deposit_locked: state.onDepositLocked
|
|
498
|
-
}
|
|
499
|
-
|
|
567
|
+
}
|
|
568
|
+
const callback = callbacks[message.params.data.event]
|
|
569
|
+
if (callback != null) {
|
|
500
570
|
callback()
|
|
501
571
|
}
|
|
502
572
|
return { handler: awaitingDepositCompletion, state }
|
|
@@ -524,14 +594,17 @@ export function awaitingDepositCompletion (channel, message, state) {
|
|
|
524
594
|
return handleUnexpectedMessage(channel, message, state)
|
|
525
595
|
}
|
|
526
596
|
|
|
527
|
-
export async function awaitingNewContractTx (
|
|
597
|
+
export async function awaitingNewContractTx (
|
|
598
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
599
|
+
): Promise<ChannelFsm | undefined> {
|
|
528
600
|
if (message.method === 'channels.sign.update') {
|
|
529
|
-
if (message.params.data.tx) {
|
|
601
|
+
if (message.params.data.tx != null) {
|
|
530
602
|
const signedTx = await state.sign(message.params.data.tx)
|
|
531
603
|
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { tx: signedTx } })
|
|
532
604
|
return { handler: awaitingNewContractCompletion, state }
|
|
533
605
|
}
|
|
534
|
-
const signedTx = await appendSignature(message.params.data.signed_tx,
|
|
606
|
+
const signedTx = await appendSignature(message.params.data.signed_tx,
|
|
607
|
+
async tx => await state.sign(tx))
|
|
535
608
|
if (typeof signedTx === 'string') {
|
|
536
609
|
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { signed_tx: signedTx } })
|
|
537
610
|
return { handler: awaitingNewContractCompletion, state }
|
|
@@ -544,20 +617,27 @@ export async function awaitingNewContractTx (channel, message, state) {
|
|
|
544
617
|
return handleUnexpectedMessage(channel, message, state)
|
|
545
618
|
}
|
|
546
619
|
|
|
547
|
-
export function awaitingNewContractCompletion (
|
|
620
|
+
export function awaitingNewContractCompletion (
|
|
621
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
622
|
+
): ChannelFsm {
|
|
623
|
+
const channelOptions = options.get(channel)
|
|
548
624
|
if (message.method === 'channels.update') {
|
|
549
|
-
const { round } = unpackTx(message.params.data.state).tx.encodedTx.tx
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
625
|
+
const { round } = unpackTx(message.params.data.state, TX_TYPE.signed).tx.encodedTx.tx
|
|
626
|
+
if (channelOptions?.role != null) {
|
|
627
|
+
const role = channelOptions.role === 'initiator'
|
|
628
|
+
? 'initiatorId'
|
|
629
|
+
: channelOptions.role === 'responder' ? 'responderId' : null
|
|
630
|
+
if (role != null) {
|
|
631
|
+
const owner = channelOptions?.[role]
|
|
632
|
+
changeState(channel, message.params.data.state)
|
|
633
|
+
state.resolve({
|
|
634
|
+
accepted: true,
|
|
635
|
+
address: encodeContractAddress(owner, round),
|
|
636
|
+
signedTx: message.params.data.state
|
|
637
|
+
})
|
|
638
|
+
return { handler: channelOpen }
|
|
639
|
+
}
|
|
640
|
+
}
|
|
561
641
|
}
|
|
562
642
|
if (message.method === 'channels.conflict') {
|
|
563
643
|
state.resolve({
|
|
@@ -576,9 +656,11 @@ export function awaitingNewContractCompletion (channel, message, state) {
|
|
|
576
656
|
return handleUnexpectedMessage(channel, message, state)
|
|
577
657
|
}
|
|
578
658
|
|
|
579
|
-
export async function awaitingCallContractUpdateTx (
|
|
659
|
+
export async function awaitingCallContractUpdateTx (
|
|
660
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
661
|
+
): Promise<ChannelFsm | undefined> {
|
|
580
662
|
if (message.method === 'channels.sign.update') {
|
|
581
|
-
if (message.params.data.tx) {
|
|
663
|
+
if (message.params.data.tx != null) {
|
|
582
664
|
const signedTx = await state.sign(
|
|
583
665
|
message.params.data.tx, { updates: message.params.data.updates }
|
|
584
666
|
)
|
|
@@ -587,7 +669,7 @@ export async function awaitingCallContractUpdateTx (channel, message, state) {
|
|
|
587
669
|
}
|
|
588
670
|
const signedTx = await appendSignature(
|
|
589
671
|
message.params.data.signed_tx,
|
|
590
|
-
tx => state.sign(tx, { updates: message.params.data.updates })
|
|
672
|
+
async tx => await state.sign(tx, { updates: message.params.data.updates })
|
|
591
673
|
)
|
|
592
674
|
if (typeof signedTx === 'string') {
|
|
593
675
|
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { signed_tx: signedTx } })
|
|
@@ -601,10 +683,12 @@ export async function awaitingCallContractUpdateTx (channel, message, state) {
|
|
|
601
683
|
return handleUnexpectedMessage(channel, message, state)
|
|
602
684
|
}
|
|
603
685
|
|
|
604
|
-
export async function awaitingCallContractForceProgressUpdate (
|
|
686
|
+
export async function awaitingCallContractForceProgressUpdate (
|
|
687
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
688
|
+
): Promise<ChannelFsm | undefined> {
|
|
605
689
|
if (message.method === 'channels.sign.force_progress_tx') {
|
|
606
|
-
const signedTx = await appendSignature(message.params.data.signed_tx, tx =>
|
|
607
|
-
state.sign(tx, { updates: message.params.data.updates })
|
|
690
|
+
const signedTx = await appendSignature(message.params.data.signed_tx, async tx =>
|
|
691
|
+
await state.sign(tx, { updates: message.params.data.updates })
|
|
608
692
|
)
|
|
609
693
|
send(channel, { jsonrpc: '2.0', method: 'channels.force_progress_sign', params: { signed_tx: signedTx } })
|
|
610
694
|
return { handler: awaitingForceProgressCompletion, state }
|
|
@@ -612,9 +696,11 @@ export async function awaitingCallContractForceProgressUpdate (channel, message,
|
|
|
612
696
|
return handleUnexpectedMessage(channel, message, state)
|
|
613
697
|
}
|
|
614
698
|
|
|
615
|
-
export function awaitingForceProgressCompletion (
|
|
699
|
+
export function awaitingForceProgressCompletion (
|
|
700
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
701
|
+
): ChannelFsm {
|
|
616
702
|
if (message.method === 'channels.on_chain_tx') {
|
|
617
|
-
if (state.onOnChainTx) {
|
|
703
|
+
if (state.onOnChainTx != null) {
|
|
618
704
|
state.onOnChainTx(message.params.data)
|
|
619
705
|
}
|
|
620
706
|
emit(channel, 'onChainTx', message.params.data.tx, {
|
|
@@ -626,7 +712,9 @@ export function awaitingForceProgressCompletion (channel, message, state) {
|
|
|
626
712
|
return handleUnexpectedMessage(channel, message, state)
|
|
627
713
|
}
|
|
628
714
|
|
|
629
|
-
export function awaitingCallContractCompletion (
|
|
715
|
+
export function awaitingCallContractCompletion (
|
|
716
|
+
channel: Channel, message: ChannelMessage, state: ChannelState
|
|
717
|
+
): ChannelFsm {
|
|
630
718
|
if (message.method === 'channels.update') {
|
|
631
719
|
changeState(channel, message.params.data.state)
|
|
632
720
|
state.resolve({ accepted: true, signedTx: message.params.data.state })
|
|
@@ -649,7 +737,9 @@ export function awaitingCallContractCompletion (channel, message, state) {
|
|
|
649
737
|
return handleUnexpectedMessage(channel, message, state)
|
|
650
738
|
}
|
|
651
739
|
|
|
652
|
-
export function awaitingCallsPruned (
|
|
740
|
+
export function awaitingCallsPruned (
|
|
741
|
+
_channels: Channel[], message: ChannelMessage, state: ChannelState
|
|
742
|
+
): ChannelFsm {
|
|
653
743
|
if (message.method === 'channels.calls_pruned.reply') {
|
|
654
744
|
state.resolve()
|
|
655
745
|
return { handler: channelOpen }
|
|
@@ -658,8 +748,10 @@ export function awaitingCallsPruned (channels, message, state) {
|
|
|
658
748
|
return { handler: channelClosed }
|
|
659
749
|
}
|
|
660
750
|
|
|
661
|
-
export function channelClosed (
|
|
662
|
-
|
|
751
|
+
export function channelClosed (
|
|
752
|
+
_channel: Channel, message: ChannelMessage, state: ChannelState
|
|
753
|
+
): ChannelFsm {
|
|
754
|
+
if (state == null) return { handler: channelClosed }
|
|
663
755
|
if (message.params.data.event === 'closing') return { handler: channelClosed, state }
|
|
664
756
|
if (message.params.data.info === 'channel_closed') {
|
|
665
757
|
state.closeTx = message.params.data.tx
|