@aeternity/aepp-sdk 12.0.0 → 12.1.2
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/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -15
- 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 +20765 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +7 -7
- package/es/AeSdk.mjs.map +1 -1
- package/es/AeSdkAepp.d.ts +4 -3
- package/es/AeSdkAepp.mjs +2 -1
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +22 -21
- package/es/AeSdkBase.mjs +25 -21
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkWallet.d.ts +4 -3
- package/es/AeSdkWallet.mjs +5 -1
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Node.d.ts +7 -10
- package/es/Node.mjs +63 -57
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +7 -4
- package/es/account/Base.mjs +3 -3
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Memory.d.ts +5 -4
- package/es/account/Memory.mjs +24 -2
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +6 -6
- package/es/account/Rpc.mjs +3 -2
- package/es/account/Rpc.mjs.map +1 -1
- package/es/aens.d.ts +27 -14
- package/es/aens.mjs +27 -21
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/Browser.d.ts +2 -1
- package/es/aepp-wallet-communication/connection/Browser.mjs +5 -2
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +5 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection-proxy.d.ts +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +1 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -5
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +8 -8
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.d.ts +17 -2
- package/es/aepp-wallet-communication/schema.mjs +54 -17
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -1
- package/es/aepp-wallet-communication/wallet-detector.mjs +2 -3
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/node/models/index.d.ts +6 -2
- package/es/apis/node/models/index.mjs.map +1 -1
- package/es/apis/node/models/mappers.mjs +4 -2
- package/es/apis/node/models/mappers.mjs.map +1 -1
- package/es/chain.d.ts +92 -64
- package/es/chain.mjs +190 -154
- package/es/chain.mjs.map +1 -1
- package/es/channel/handlers.d.ts +3 -3
- package/es/channel/handlers.mjs +42 -44
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/index.d.ts +43 -52
- package/es/channel/index.mjs +46 -49
- package/es/channel/index.mjs.map +1 -1
- package/es/channel/internal.d.ts +16 -15
- package/es/channel/internal.mjs +67 -62
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Compiler.d.ts +1 -0
- package/es/contract/Compiler.mjs +5 -4
- package/es/contract/Compiler.mjs.map +1 -1
- package/es/contract/aci.d.ts +17 -15
- package/es/contract/aci.mjs +58 -45
- package/es/contract/aci.mjs.map +1 -1
- package/es/contract/ga.d.ts +16 -15
- package/es/contract/ga.mjs +12 -7
- package/es/contract/ga.mjs.map +1 -1
- package/es/contract/methods.d.ts +9 -6
- package/es/contract/methods.mjs +9 -6
- package/es/contract/methods.mjs.map +1 -1
- 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 +4 -1
- package/es/index.mjs +4 -1
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +69 -62
- package/es/oracle.mjs +121 -103
- package/es/oracle.mjs.map +1 -1
- package/es/spend.d.ts +16 -15
- package/es/spend.mjs +19 -30
- package/es/spend.mjs.map +1 -1
- 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 +55 -26
- package/es/tx/builder/constants.mjs +60 -38
- package/es/tx/builder/constants.mjs.map +1 -1
- 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/{min-fee.mjs → builder/field-types/fee.mjs} +62 -60
- 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 +27 -33
- package/es/tx/builder/helpers.mjs +41 -47
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +25 -12
- package/es/tx/builder/index.mjs +74 -83
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +995 -144
- package/es/tx/builder/schema.mjs +121 -170
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +28 -27
- package/es/tx/index.mjs +97 -117
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +4 -3
- package/es/tx/validator.mjs +79 -92
- package/es/tx/validator.mjs.map +1 -1
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -1
- package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -1
- package/es/typings/bip32-path/index.d.mjs.map +1 -1
- 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.map +1 -1
- package/es/utils/amount-formatter.d.ts +9 -9
- package/es/utils/amount-formatter.mjs +17 -17
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.mjs +7 -7
- package/es/utils/autorest.mjs.map +1 -1
- package/es/utils/bignumber.mjs +2 -1
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/utils/bytes.mjs +1 -1
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +8 -23
- package/es/utils/crypto.mjs +15 -41
- 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 +6 -7
- package/es/utils/encoder.mjs +42 -26
- package/es/utils/encoder.mjs.map +1 -1
- package/es/utils/errors.d.ts +1 -11
- package/es/utils/errors.mjs +4 -20
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +18 -2
- package/es/utils/hd-wallet.mjs +64 -34
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.mjs +2 -2
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.mjs +4 -2
- package/es/utils/keystore.mjs.map +1 -1
- package/es/utils/mptree.d.ts +2 -2
- package/es/utils/mptree.mjs +11 -6
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +8 -2
- package/es/utils/other.mjs +15 -3
- package/es/utils/other.mjs.map +1 -1
- package/es/utils/semver-satisfies.d.ts +1 -1
- package/es/utils/semver-satisfies.mjs +2 -2
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.mjs.map +1 -1
- package/package.json +36 -34
- package/src/AeSdk.ts +30 -27
- package/src/AeSdkAepp.ts +93 -84
- package/src/AeSdkBase.ts +148 -130
- package/src/AeSdkWallet.ts +172 -156
- package/src/Node.ts +108 -102
- package/src/account/Base.ts +42 -32
- package/src/account/Memory.ts +45 -30
- package/src/account/Rpc.ts +32 -30
- package/src/aens.ts +124 -108
- package/src/aepp-wallet-communication/connection/Browser.ts +18 -15
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +22 -21
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +63 -52
- package/src/aepp-wallet-communication/connection-proxy.ts +8 -7
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +67 -61
- package/src/aepp-wallet-communication/rpc/types.ts +32 -32
- package/src/aepp-wallet-communication/schema.ts +117 -74
- package/src/aepp-wallet-communication/wallet-detector.ts +29 -28
- package/src/apis/node/code-model-v4.yaml +54 -20
- package/src/apis/node/models/index.ts +6 -2
- package/src/apis/node/models/mappers.ts +4 -2
- package/src/chain.ts +286 -228
- package/src/channel/handlers.ts +424 -372
- package/src/channel/index.ts +285 -251
- package/src/channel/internal.ts +248 -232
- package/src/contract/Compiler.ts +22 -21
- package/src/contract/aci.ts +267 -258
- package/src/contract/ga.ts +93 -72
- package/src/contract/methods.ts +32 -27
- package/src/deprecated/index.ts +172 -0
- package/src/deprecated/methods.ts +25 -0
- package/src/index.ts +37 -32
- package/src/oracle.ts +211 -189
- package/src/spend.ts +82 -70
- package/src/tx/builder/address.ts +50 -0
- package/src/tx/builder/constants.ts +82 -52
- 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 +112 -117
- package/src/tx/builder/index.ts +203 -197
- package/src/tx/builder/schema.ts +421 -465
- package/src/tx/index.ts +128 -135
- package/src/tx/validator.ts +165 -161
- package/src/typings/@aeternity__argon2-browser/index.d.ts +1 -1
- package/src/typings/@aeternity__uuid/index.d.ts +3 -1
- package/src/typings/bip32-path/index.d.ts +6 -6
- 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 +2 -2
- package/src/utils/amount-formatter.ts +41 -41
- package/src/utils/autorest.ts +57 -54
- package/src/utils/bignumber.ts +7 -6
- package/src/utils/bytes.ts +19 -19
- package/src/utils/crypto.ts +82 -94
- package/src/utils/encoder-types.ts +63 -0
- package/src/utils/encoder.ts +104 -56
- package/src/utils/errors.ts +246 -264
- package/src/utils/hd-wallet.ts +114 -82
- package/src/utils/json-big.ts +16 -15
- package/src/utils/keystore.ts +65 -62
- package/src/utils/mptree.ts +59 -56
- package/src/utils/other.ts +26 -18
- package/src/utils/semver-satisfies.ts +15 -11
- package/src/utils/string.ts +10 -10
- package/es/tx/builder/field-types.d.ts +0 -62
- package/es/tx/builder/field-types.mjs +0 -126
- package/es/tx/builder/field-types.mjs.map +0 -1
- package/es/tx/min-fee.d.ts +0 -20
- package/es/tx/min-fee.mjs.map +0 -1
- package/src/tx/builder/field-types.ts +0 -111
- package/src/tx/min-fee.ts +0 -136
|
@@ -15,23 +15,30 @@
|
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import BrowserConnection from './Browser'
|
|
19
|
-
import { MESSAGE_DIRECTION } from '../schema'
|
|
20
|
-
import { InternalError, RpcConnectionError } from '../../utils/errors'
|
|
18
|
+
import BrowserConnection from './Browser';
|
|
19
|
+
import { MESSAGE_DIRECTION } from '../schema';
|
|
20
|
+
import { InternalError, RpcConnectionError } from '../../utils/errors';
|
|
21
21
|
|
|
22
|
-
export type ImplPostMessage = Pick<Window, 'addEventListener' | 'removeEventListener' | 'postMessage'
|
|
22
|
+
export type ImplPostMessage = Pick<Window, 'addEventListener' | 'removeEventListener' | 'postMessage'>;
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Browser window Post Message connector module
|
|
26
|
+
* @category aepp wallet communication
|
|
26
27
|
*/
|
|
27
28
|
export default class BrowserWindowMessageConnection extends BrowserConnection {
|
|
28
|
-
origin?: string
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
origin?: string;
|
|
30
|
+
|
|
31
|
+
sendDirection?: MESSAGE_DIRECTION;
|
|
32
|
+
|
|
33
|
+
receiveDirection: MESSAGE_DIRECTION;
|
|
34
|
+
|
|
35
|
+
listener?: (this: Window, ev: MessageEvent<any>) => void;
|
|
36
|
+
|
|
37
|
+
#onDisconnect?: () => void;
|
|
38
|
+
|
|
39
|
+
#target?: ImplPostMessage;
|
|
40
|
+
|
|
41
|
+
#self: ImplPostMessage;
|
|
35
42
|
|
|
36
43
|
/**
|
|
37
44
|
* @param options - Options
|
|
@@ -43,7 +50,7 @@ export default class BrowserWindowMessageConnection extends BrowserConnection {
|
|
|
43
50
|
* Used for handling messages between content script and page
|
|
44
51
|
* @param options.receiveDirection Unwrapping messages from additional struct
|
|
45
52
|
*/
|
|
46
|
-
constructor
|
|
53
|
+
constructor({
|
|
47
54
|
target,
|
|
48
55
|
self = window,
|
|
49
56
|
origin,
|
|
@@ -51,61 +58,65 @@ export default class BrowserWindowMessageConnection extends BrowserConnection {
|
|
|
51
58
|
receiveDirection = MESSAGE_DIRECTION.to_aepp,
|
|
52
59
|
...options
|
|
53
60
|
}: {
|
|
54
|
-
target?: ImplPostMessage
|
|
55
|
-
self?: ImplPostMessage
|
|
56
|
-
origin?: string
|
|
57
|
-
sendDirection?: MESSAGE_DIRECTION
|
|
58
|
-
receiveDirection?: MESSAGE_DIRECTION
|
|
59
|
-
debug?: boolean
|
|
61
|
+
target?: ImplPostMessage;
|
|
62
|
+
self?: ImplPostMessage;
|
|
63
|
+
origin?: string;
|
|
64
|
+
sendDirection?: MESSAGE_DIRECTION;
|
|
65
|
+
receiveDirection?: MESSAGE_DIRECTION;
|
|
66
|
+
debug?: boolean;
|
|
60
67
|
} = {}) {
|
|
61
|
-
super(options)
|
|
62
|
-
this.#target = target
|
|
63
|
-
this.#self = self
|
|
64
|
-
this.origin = origin
|
|
65
|
-
this.sendDirection = sendDirection
|
|
66
|
-
this.receiveDirection = receiveDirection
|
|
68
|
+
super(options);
|
|
69
|
+
this.#target = target;
|
|
70
|
+
this.#self = self;
|
|
71
|
+
this.origin = origin;
|
|
72
|
+
this.sendDirection = sendDirection;
|
|
73
|
+
this.receiveDirection = receiveDirection;
|
|
67
74
|
}
|
|
68
75
|
|
|
69
|
-
isConnected
|
|
70
|
-
return this.listener != null
|
|
76
|
+
isConnected(): boolean {
|
|
77
|
+
return this.listener != null;
|
|
71
78
|
}
|
|
72
79
|
|
|
73
|
-
connect
|
|
80
|
+
connect(
|
|
74
81
|
onMessage: (message: any, origin: string, source: MessageEventSource | null) => void,
|
|
75
|
-
onDisconnect: () => void
|
|
82
|
+
onDisconnect: () => void,
|
|
76
83
|
): void {
|
|
77
|
-
super.connect(onMessage, onDisconnect)
|
|
84
|
+
super.connect(onMessage, onDisconnect);
|
|
78
85
|
this.listener = (message: MessageEvent<any>) => {
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
// TODO: strict validate origin and source instead of checking message structure
|
|
87
|
+
if (
|
|
88
|
+
typeof message.data !== 'object'
|
|
89
|
+
|| (message.data.jsonrpc ?? message.data.data?.jsonrpc) !== '2.0'
|
|
90
|
+
) return;
|
|
91
|
+
if (this.origin != null && this.origin !== message.origin) return;
|
|
92
|
+
if (this.#target != null && this.#target !== message.source) return;
|
|
93
|
+
this.receiveMessage(message);
|
|
94
|
+
let { data } = message;
|
|
84
95
|
if (data.type != null) {
|
|
85
|
-
if (message.data.type !== this.receiveDirection) return
|
|
86
|
-
data = data.data
|
|
96
|
+
if (message.data.type !== this.receiveDirection) return;
|
|
97
|
+
data = data.data;
|
|
87
98
|
}
|
|
88
|
-
onMessage(data, message.origin, message.source)
|
|
89
|
-
}
|
|
90
|
-
this.#self.addEventListener('message', this.listener)
|
|
91
|
-
this.#onDisconnect = onDisconnect
|
|
99
|
+
onMessage(data, message.origin, message.source);
|
|
100
|
+
};
|
|
101
|
+
this.#self.addEventListener('message', this.listener);
|
|
102
|
+
this.#onDisconnect = onDisconnect;
|
|
92
103
|
}
|
|
93
104
|
|
|
94
|
-
disconnect
|
|
95
|
-
super.disconnect()
|
|
105
|
+
disconnect(): void {
|
|
106
|
+
super.disconnect();
|
|
96
107
|
if (this.listener == null || this.#onDisconnect == null) {
|
|
97
|
-
throw new InternalError('Expected to not happen, required for TS')
|
|
108
|
+
throw new InternalError('Expected to not happen, required for TS');
|
|
98
109
|
}
|
|
99
|
-
this.#self.removeEventListener('message', this.listener)
|
|
100
|
-
delete this.listener
|
|
101
|
-
this.#onDisconnect()
|
|
102
|
-
this.#onDisconnect = undefined
|
|
110
|
+
this.#self.removeEventListener('message', this.listener);
|
|
111
|
+
delete this.listener;
|
|
112
|
+
this.#onDisconnect();
|
|
113
|
+
this.#onDisconnect = undefined;
|
|
103
114
|
}
|
|
104
115
|
|
|
105
|
-
sendMessage
|
|
106
|
-
if (this.#target == null) throw new RpcConnectionError('Can\'t send messages without target')
|
|
107
|
-
const message = this.sendDirection != null ? { type: this.sendDirection, data: msg } : msg
|
|
108
|
-
super.sendMessage(message)
|
|
109
|
-
this.#target.postMessage(message, this.origin ?? '*')
|
|
116
|
+
sendMessage(msg: any): void {
|
|
117
|
+
if (this.#target == null) throw new RpcConnectionError('Can\'t send messages without target');
|
|
118
|
+
const message = this.sendDirection != null ? { type: this.sendDirection, data: msg } : msg;
|
|
119
|
+
super.sendMessage(message);
|
|
120
|
+
this.#target.postMessage(message, this.origin ?? '*');
|
|
110
121
|
}
|
|
111
122
|
}
|
|
@@ -15,21 +15,22 @@
|
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import BrowserConnection from './connection/Browser'
|
|
18
|
+
import BrowserConnection from './connection/Browser';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Browser connection proxy
|
|
22
22
|
* Provide functionality to easily forward messages from one connection to another and back
|
|
23
|
+
* @category aepp wallet communication
|
|
23
24
|
* @param con1 - first connection
|
|
24
25
|
* @param con2 - second connection
|
|
25
26
|
* @returns a function to stop proxying
|
|
26
27
|
*/
|
|
27
28
|
export default (con1: BrowserConnection, con2: BrowserConnection): () => void => {
|
|
28
|
-
con1.connect((msg: any) => con2.sendMessage(msg), () => con2.disconnect())
|
|
29
|
-
con2.connect((msg: any) => con1.sendMessage(msg), () => con1.disconnect())
|
|
29
|
+
con1.connect((msg: any) => con2.sendMessage(msg), () => con2.disconnect());
|
|
30
|
+
con2.connect((msg: any) => con1.sendMessage(msg), () => con1.disconnect());
|
|
30
31
|
|
|
31
32
|
return () => {
|
|
32
|
-
con1.disconnect()
|
|
33
|
-
con2.disconnect()
|
|
34
|
-
}
|
|
35
|
-
}
|
|
33
|
+
con1.disconnect();
|
|
34
|
+
con2.disconnect();
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -1,102 +1,107 @@
|
|
|
1
|
-
import { RpcError, RpcInternalError, RpcMethodNotFoundError } from '../schema'
|
|
2
|
-
import BrowserConnection from '../connection/Browser'
|
|
3
|
-
import { InvalidRpcMessageError, MissingCallbackError } from '../../utils/errors'
|
|
1
|
+
import { RpcError, RpcInternalError, RpcMethodNotFoundError } from '../schema';
|
|
2
|
+
import BrowserConnection from '../connection/Browser';
|
|
3
|
+
import { InvalidRpcMessageError, MissingCallbackError } from '../../utils/errors';
|
|
4
4
|
|
|
5
5
|
interface JsonRpcRequest {
|
|
6
|
-
jsonrpc: '2.0'
|
|
7
|
-
id: number
|
|
8
|
-
method: string
|
|
9
|
-
params?: any
|
|
6
|
+
jsonrpc: '2.0';
|
|
7
|
+
id: number;
|
|
8
|
+
method: string;
|
|
9
|
+
params?: any;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
interface JsonRpcResponse {
|
|
13
|
-
jsonrpc: '2.0'
|
|
14
|
-
id: number
|
|
15
|
-
method: string
|
|
16
|
-
result?: any
|
|
13
|
+
jsonrpc: '2.0';
|
|
14
|
+
id: number;
|
|
15
|
+
method: string;
|
|
16
|
+
result?: any;
|
|
17
17
|
error?: {
|
|
18
|
-
code: number
|
|
19
|
-
message: string
|
|
20
|
-
data?: any
|
|
21
|
-
}
|
|
18
|
+
code: number;
|
|
19
|
+
message: string;
|
|
20
|
+
data?: any;
|
|
21
|
+
};
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
type RpcApiHandler = (p?: any) => any | undefined
|
|
25
|
-
type RpcApi<Api> = { [k in keyof Api]: RpcApiHandler }
|
|
24
|
+
type RpcApiHandler = (p?: any) => any | undefined;
|
|
25
|
+
type RpcApi<Api> = { [k in keyof Api]: RpcApiHandler };
|
|
26
26
|
type WithOrigin<Api extends RpcApi<Api>> = {
|
|
27
27
|
[k in keyof Api]: (p: Parameters<Api[k]>[0], origin: string) => ReturnType<Api[k]>
|
|
28
|
-
}
|
|
28
|
+
};
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Contain functionality for using RPC conection
|
|
32
|
+
* @category aepp wallet communication
|
|
32
33
|
* @param connection - Connection object
|
|
33
34
|
* @param onDisconnect - Disconnect callback
|
|
34
35
|
* @param methods - Object containing handlers for each request by name
|
|
35
36
|
*/
|
|
36
37
|
export default class RpcClient <
|
|
37
|
-
RemoteApi extends RpcApi<RemoteApi>, LocalApi extends RpcApi<LocalApi
|
|
38
|
+
RemoteApi extends RpcApi<RemoteApi>, LocalApi extends RpcApi<LocalApi>,
|
|
38
39
|
> {
|
|
39
|
-
connection: BrowserConnection
|
|
40
|
-
|
|
41
|
-
#
|
|
42
|
-
|
|
40
|
+
connection: BrowserConnection;
|
|
41
|
+
|
|
42
|
+
#callbacks = new Map<number, { resolve: (v: any) => void; reject: (e: Error) => void }>();
|
|
43
|
+
|
|
44
|
+
#messageId = 0;
|
|
45
|
+
|
|
46
|
+
#methods: WithOrigin<LocalApi>;
|
|
43
47
|
|
|
44
|
-
constructor
|
|
48
|
+
constructor(
|
|
45
49
|
connection: BrowserConnection,
|
|
46
50
|
onDisconnect: () => void,
|
|
47
|
-
methods: WithOrigin<LocalApi
|
|
51
|
+
methods: WithOrigin<LocalApi>,
|
|
48
52
|
) {
|
|
49
|
-
this.connection = connection
|
|
50
|
-
this.#methods = methods
|
|
51
|
-
connection.connect(this.#handleMessage.bind(this), onDisconnect)
|
|
53
|
+
this.connection = connection;
|
|
54
|
+
this.#methods = methods;
|
|
55
|
+
connection.connect(this.#handleMessage.bind(this), onDisconnect);
|
|
52
56
|
}
|
|
53
57
|
|
|
54
|
-
async #handleMessage
|
|
55
|
-
if (msg?.jsonrpc !== '2.0') throw new InvalidRpcMessageError(JSON.stringify(msg))
|
|
58
|
+
async #handleMessage(msg: JsonRpcRequest | JsonRpcResponse, origin: string): Promise<void> {
|
|
59
|
+
if (msg?.jsonrpc !== '2.0') throw new InvalidRpcMessageError(JSON.stringify(msg));
|
|
56
60
|
if ('result' in msg || 'error' in msg) {
|
|
57
|
-
this.#processResponse(msg)
|
|
58
|
-
return
|
|
61
|
+
this.#processResponse(msg);
|
|
62
|
+
return;
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
const request = msg as JsonRpcRequest
|
|
62
|
-
let result
|
|
65
|
+
const request = msg as JsonRpcRequest;
|
|
66
|
+
let result; let
|
|
67
|
+
error;
|
|
63
68
|
try {
|
|
64
|
-
if (!(request.method in this.#methods)) throw new RpcMethodNotFoundError()
|
|
65
|
-
const methodName = request.method as keyof LocalApi
|
|
66
|
-
result = await this.#methods[methodName](request.params, origin)
|
|
69
|
+
if (!(request.method in this.#methods)) throw new RpcMethodNotFoundError();
|
|
70
|
+
const methodName = request.method as keyof LocalApi;
|
|
71
|
+
result = await this.#methods[methodName](request.params, origin);
|
|
67
72
|
} catch (e) {
|
|
68
|
-
error = e instanceof RpcError ? e : new RpcInternalError()
|
|
73
|
+
error = e instanceof RpcError ? e : new RpcInternalError();
|
|
69
74
|
}
|
|
70
75
|
if (request.id != null) {
|
|
71
|
-
this.#sendResponse(request.id, request.method as keyof LocalApi, result, error)
|
|
76
|
+
this.#sendResponse(request.id, request.method as keyof LocalApi, result, error);
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
79
|
|
|
75
|
-
#sendRequest
|
|
80
|
+
#sendRequest(
|
|
76
81
|
id: number | undefined,
|
|
77
82
|
method: keyof RemoteApi | keyof LocalApi,
|
|
78
|
-
params?: any
|
|
83
|
+
params?: any,
|
|
79
84
|
): void {
|
|
80
85
|
this.connection.sendMessage({
|
|
81
86
|
jsonrpc: '2.0',
|
|
82
87
|
...id != null ? { id } : {},
|
|
83
88
|
method,
|
|
84
|
-
...params != null ? { params } : {}
|
|
85
|
-
})
|
|
89
|
+
...params != null ? { params } : {},
|
|
90
|
+
});
|
|
86
91
|
}
|
|
87
92
|
|
|
88
|
-
#sendResponse
|
|
93
|
+
#sendResponse(
|
|
89
94
|
id: number,
|
|
90
95
|
method: keyof RemoteApi | keyof LocalApi, // TODO: remove as far it is not required in JSON RPC
|
|
91
96
|
result?: any,
|
|
92
|
-
error?: any
|
|
97
|
+
error?: any,
|
|
93
98
|
): void {
|
|
94
99
|
this.connection.sendMessage({
|
|
95
100
|
jsonrpc: '2.0',
|
|
96
101
|
id,
|
|
97
102
|
method,
|
|
98
|
-
...error != null ? { error } : { result }
|
|
99
|
-
})
|
|
103
|
+
...error != null ? { error } : { result },
|
|
104
|
+
});
|
|
100
105
|
}
|
|
101
106
|
|
|
102
107
|
/**
|
|
@@ -105,13 +110,14 @@ export default class RpcClient <
|
|
|
105
110
|
* @param params - Method params
|
|
106
111
|
* @returns Promise which will be resolved after receiving response message
|
|
107
112
|
*/
|
|
108
|
-
async request<Name extends keyof RemoteApi>
|
|
109
|
-
name: Name,
|
|
113
|
+
async request<Name extends keyof RemoteApi>(
|
|
114
|
+
name: Name,
|
|
115
|
+
params: Parameters<RemoteApi[Name]>[0],
|
|
110
116
|
): Promise<ReturnType<RemoteApi[Name]>> {
|
|
111
|
-
this.#sendRequest(
|
|
112
|
-
return
|
|
113
|
-
this.#callbacks.set(this.#messageId, { resolve, reject })
|
|
114
|
-
})
|
|
117
|
+
this.#sendRequest(this.#messageId += 1, name, params);
|
|
118
|
+
return new Promise((resolve, reject) => {
|
|
119
|
+
this.#callbacks.set(this.#messageId, { resolve, reject });
|
|
120
|
+
});
|
|
115
121
|
}
|
|
116
122
|
|
|
117
123
|
/**
|
|
@@ -119,19 +125,19 @@ export default class RpcClient <
|
|
|
119
125
|
* @param name - Method name
|
|
120
126
|
* @param params - Method params
|
|
121
127
|
*/
|
|
122
|
-
notify<Name extends keyof RemoteApi>
|
|
123
|
-
this.#sendRequest(undefined, name, params)
|
|
128
|
+
notify<Name extends keyof RemoteApi>(name: Name, params: Parameters<RemoteApi[Name]>[0]): void {
|
|
129
|
+
this.#sendRequest(undefined, name, params);
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
/**
|
|
127
133
|
* Process response message
|
|
128
134
|
* @param msg - Message object
|
|
129
135
|
*/
|
|
130
|
-
#processResponse
|
|
131
|
-
const callbacks = this.#callbacks.get(id)
|
|
132
|
-
if (callbacks == null) throw new MissingCallbackError(id)
|
|
133
|
-
if (error != null) callbacks.reject(RpcError.deserialize(error))
|
|
134
|
-
else callbacks.resolve(result)
|
|
135
|
-
this.#callbacks.delete(id)
|
|
136
|
+
#processResponse({ id, error, result }: { id: number; error?: any; result?: any }): void {
|
|
137
|
+
const callbacks = this.#callbacks.get(id);
|
|
138
|
+
if (callbacks == null) throw new MissingCallbackError(id);
|
|
139
|
+
if (error != null) callbacks.reject(RpcError.deserialize(error));
|
|
140
|
+
else callbacks.resolve(result);
|
|
141
|
+
this.#callbacks.delete(id);
|
|
136
142
|
}
|
|
137
143
|
}
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import { send } from '../../spend'
|
|
2
|
-
import {
|
|
3
|
-
import { METHODS, SUBSCRIPTION_TYPES, WALLET_TYPE } from '../schema'
|
|
1
|
+
import { send } from '../../spend';
|
|
2
|
+
import { Encoded } from '../../utils/encoder';
|
|
3
|
+
import { METHODS, SUBSCRIPTION_TYPES, WALLET_TYPE } from '../schema';
|
|
4
4
|
|
|
5
5
|
export interface WalletInfo {
|
|
6
|
-
id: string
|
|
7
|
-
name: string
|
|
8
|
-
networkId: string
|
|
9
|
-
origin: string
|
|
10
|
-
type: WALLET_TYPE
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
networkId: string;
|
|
9
|
+
origin: string;
|
|
10
|
+
type: WALLET_TYPE;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export interface Accounts {
|
|
14
|
-
connected: { [pub:
|
|
15
|
-
current: { [pub:
|
|
14
|
+
connected: { [pub: Encoded.AccountAddress]: {} };
|
|
15
|
+
current: { [pub: Encoded.AccountAddress]: {} };
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export interface Node {
|
|
19
|
-
name: string
|
|
20
|
-
url: string
|
|
19
|
+
name: string;
|
|
20
|
+
url: string;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface Network {
|
|
24
|
-
networkId: string
|
|
25
|
-
node?: Node
|
|
24
|
+
networkId: string;
|
|
25
|
+
node?: Node;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
type Icons = Array<{ src: string
|
|
28
|
+
type Icons = Array<{ src: string; sizes?: string; type?: string; purpose?: string }>;
|
|
29
29
|
|
|
30
|
-
export const RPC_VERSION = 1
|
|
30
|
+
export const RPC_VERSION = 1;
|
|
31
31
|
|
|
32
32
|
export interface WalletApi {
|
|
33
33
|
[METHODS.connect]: (
|
|
34
|
-
p: { name: string
|
|
35
|
-
) => Promise<WalletInfo & { node?: Node }
|
|
34
|
+
p: { name: string; icons?: Icons; version: typeof RPC_VERSION; connectNode: boolean }
|
|
35
|
+
) => Promise<WalletInfo & { node?: Node }>;
|
|
36
36
|
|
|
37
|
-
[METHODS.closeConnection]: (p: any) => void
|
|
37
|
+
[METHODS.closeConnection]: (p: any) => void;
|
|
38
38
|
|
|
39
39
|
[METHODS.subscribeAddress]: (
|
|
40
|
-
p: { type: SUBSCRIPTION_TYPES
|
|
41
|
-
) => Promise<{ subscription: Array<'connected' | 'current'
|
|
40
|
+
p: { type: SUBSCRIPTION_TYPES; value: 'connected' | 'current' }
|
|
41
|
+
) => Promise<{ subscription: Array<'connected' | 'current'>; address: Accounts }>;
|
|
42
42
|
|
|
43
|
-
[METHODS.address]: () => Promise<
|
|
43
|
+
[METHODS.address]: () => Promise<Encoded.AccountAddress[]>;
|
|
44
44
|
|
|
45
45
|
[METHODS.sign]: ((
|
|
46
|
-
p: { tx:
|
|
46
|
+
p: { tx: Encoded.Transaction; onAccount: Encoded.AccountAddress; returnSigned: boolean }
|
|
47
47
|
) => Promise<{
|
|
48
48
|
/**
|
|
49
49
|
* @deprecated this is not a hash at all, will be removed later at the same time
|
|
50
50
|
* as dropping ability to broadcast transaction by wallet
|
|
51
51
|
*/
|
|
52
|
-
transactionHash?: Awaited<ReturnType<typeof send
|
|
53
|
-
signedTransaction?:
|
|
54
|
-
}>)
|
|
52
|
+
transactionHash?: Awaited<ReturnType<typeof send>>;
|
|
53
|
+
signedTransaction?: Encoded.Transaction;
|
|
54
|
+
}>);
|
|
55
55
|
|
|
56
56
|
[METHODS.signMessage]: (
|
|
57
|
-
p: { message: string
|
|
58
|
-
) => Promise<{ signature: string }
|
|
57
|
+
p: { message: string; onAccount: Encoded.AccountAddress }
|
|
58
|
+
) => Promise<{ signature: string }>;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export interface AeppApi {
|
|
62
|
-
[METHODS.updateAddress]: (a: Accounts) => void
|
|
63
|
-
[METHODS.updateNetwork]: (a: Network) => void
|
|
64
|
-
[METHODS.readyToConnect]: (w: WalletInfo) => void
|
|
65
|
-
[METHODS.closeConnection]: (p: any) => void
|
|
62
|
+
[METHODS.updateAddress]: (a: Accounts) => void;
|
|
63
|
+
[METHODS.updateNetwork]: (a: Network) => void;
|
|
64
|
+
[METHODS.readyToConnect]: (w: WalletInfo) => void;
|
|
65
|
+
[METHODS.closeConnection]: (p: any) => void;
|
|
66
66
|
}
|