@portal-hq/web 3.2.3 → 3.3.1
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/README.md +1 -1
- package/lib/commonjs/index.js +147 -19
- package/lib/commonjs/index.test.js +548 -0
- package/lib/commonjs/mpc/errors/index.js +1 -1
- package/lib/commonjs/mpc/index.js +145 -2
- package/lib/commonjs/mpc/index.test.js +1414 -0
- package/lib/commonjs/provider/index.js +172 -39
- package/lib/commonjs/provider/index.test.js +1222 -0
- package/lib/esm/index.js +122 -18
- package/lib/esm/index.test.js +520 -0
- package/lib/esm/mpc/errors/index.js +1 -1
- package/lib/esm/mpc/index.js +145 -2
- package/lib/esm/mpc/index.test.js +1409 -0
- package/lib/esm/provider/index.js +171 -39
- package/lib/esm/provider/index.test.js +1217 -0
- package/package.json +5 -5
- package/src/__mocks/constants.ts +771 -0
- package/src/__mocks/portal/mpc.ts +27 -0
- package/src/__mocks/portal/portal.ts +14 -0
- package/src/__mocks/portal/provider.ts +7 -0
- package/src/index.test.ts +820 -0
- package/src/index.ts +183 -44
- package/src/mpc/errors/index.ts +1 -1
- package/src/mpc/index.test.ts +1716 -0
- package/src/mpc/index.ts +182 -2
- package/src/provider/index.test.ts +1570 -0
- package/src/provider/index.ts +184 -39
- package/types.d.ts +298 -33
|
@@ -8,28 +8,147 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { ProviderRpcError, RpcErrorCodes } from './errors';
|
|
11
|
+
export var RequestMethod;
|
|
12
|
+
(function (RequestMethod) {
|
|
13
|
+
RequestMethod["eth_accounts"] = "eth_accounts";
|
|
14
|
+
RequestMethod["eth_blockNumber"] = "eth_blockNumber";
|
|
15
|
+
RequestMethod["eth_call"] = "eth_call";
|
|
16
|
+
RequestMethod["eth_chainId"] = "eth_chainId";
|
|
17
|
+
RequestMethod["eth_coinbase"] = "eth_coinbase";
|
|
18
|
+
RequestMethod["eth_compileSolidity"] = "eth_compileSolidity";
|
|
19
|
+
RequestMethod["eth_compileLLL"] = "eth_compileLLL";
|
|
20
|
+
RequestMethod["eth_compileSerpent"] = "eth_compileSerpent";
|
|
21
|
+
RequestMethod["eth_estimateGas"] = "eth_estimateGas";
|
|
22
|
+
RequestMethod["eth_gasPrice"] = "eth_gasPrice";
|
|
23
|
+
RequestMethod["eth_getBalance"] = "eth_getBalance";
|
|
24
|
+
RequestMethod["eth_getBlockByHash"] = "eth_getBlockByHash";
|
|
25
|
+
RequestMethod["eth_getBlockByNumber"] = "eth_getBlockByNumber";
|
|
26
|
+
RequestMethod["eth_getBlockTransactionCountByHash"] = "eth_getBlockTransactionCountByHash";
|
|
27
|
+
RequestMethod["eth_getBlockTransactionCountByNumber"] = "eth_getBlockTransactionCountByNumber";
|
|
28
|
+
RequestMethod["eth_getCode"] = "eth_getCode";
|
|
29
|
+
RequestMethod["eth_getCompilers"] = "eth_getCompilers";
|
|
30
|
+
RequestMethod["eth_getFilterChange"] = "eth_getFilterChange";
|
|
31
|
+
RequestMethod["eth_getFilterLogs"] = "eth_getFilterLogs";
|
|
32
|
+
RequestMethod["eth_getLogs"] = "eth_getLogs";
|
|
33
|
+
RequestMethod["eth_getStorageAt"] = "eth_getStorageAt";
|
|
34
|
+
RequestMethod["eth_getTransactionByHash"] = "eth_getTransactionByHash";
|
|
35
|
+
RequestMethod["eth_getTransactionByBlockHashAndIndex"] = "eth_getTransactionByBlockHashAndIndex";
|
|
36
|
+
RequestMethod["eth_getTransactionByBlockNumberAndIndex"] = "eth_getTransactionByBlockNumberAndIndex";
|
|
37
|
+
RequestMethod["eth_getTransactionCount"] = "eth_getTransactionCount";
|
|
38
|
+
RequestMethod["eth_getTransactionReceipt"] = "eth_getTransactionReceipt";
|
|
39
|
+
RequestMethod["eth_getUncleByBlockHashAndIndex"] = "eth_getUncleByBlockHashAndIndex";
|
|
40
|
+
RequestMethod["eth_getUncleByBlockNumberAndIndex"] = "eth_getUncleByBlockNumberAndIndex";
|
|
41
|
+
RequestMethod["eth_getUncleCountByBlockHash"] = "eth_getUncleCountByBlockHash";
|
|
42
|
+
RequestMethod["eth_getUncleCountByBlockNumber"] = "eth_getUncleCountByBlockNumber";
|
|
43
|
+
RequestMethod["eth_getWork"] = "eth_getWork";
|
|
44
|
+
RequestMethod["eth_hashrate"] = "eth_hashrate";
|
|
45
|
+
RequestMethod["eth_mining"] = "eth_mining";
|
|
46
|
+
RequestMethod["eth_newBlockFilter"] = "eth_newBlockFilter";
|
|
47
|
+
RequestMethod["eth_newFilter"] = "eth_newFilter";
|
|
48
|
+
RequestMethod["eth_newPendingTransactionFilter"] = "eth_newPendingTransactionFilter";
|
|
49
|
+
RequestMethod["personal_sign"] = "personal_sign";
|
|
50
|
+
RequestMethod["eth_protocolVersion"] = "eth_protocolVersion";
|
|
51
|
+
RequestMethod["eth_requestAccounts"] = "eth_requestAccounts";
|
|
52
|
+
RequestMethod["eth_sendRawTransaction"] = "eth_sendRawTransaction";
|
|
53
|
+
RequestMethod["eth_sendTransaction"] = "eth_sendTransaction";
|
|
54
|
+
RequestMethod["eth_sign"] = "eth_sign";
|
|
55
|
+
RequestMethod["eth_signTransaction"] = "eth_signTransaction";
|
|
56
|
+
RequestMethod["eth_signTypedData"] = "eth_signTypedData";
|
|
57
|
+
RequestMethod["eth_signTypedData_v3"] = "eth_signTypedData_v3";
|
|
58
|
+
RequestMethod["eth_signTypedData_v4"] = "eth_signTypedData_v4";
|
|
59
|
+
RequestMethod["eth_submitHashrate"] = "eth_submitHashrate";
|
|
60
|
+
RequestMethod["eth_submitWork"] = "eth_submitWork";
|
|
61
|
+
RequestMethod["eth_syncing"] = "eth_syncing";
|
|
62
|
+
RequestMethod["eth_uninstallFilter"] = "eth_uninstallFilter";
|
|
63
|
+
// Net Methods
|
|
64
|
+
RequestMethod["net_listening"] = "net_listening";
|
|
65
|
+
RequestMethod["net_peerCount"] = "net_peerCount";
|
|
66
|
+
RequestMethod["net_version"] = "net_version";
|
|
67
|
+
// Web3 Methods
|
|
68
|
+
RequestMethod["web3_clientVersion"] = "web3_clientVersion";
|
|
69
|
+
RequestMethod["web3_sha3"] = "web3_sha3";
|
|
70
|
+
// Solana RPC Methods
|
|
71
|
+
RequestMethod["sol_getAccountInfo"] = "getAccountInfo";
|
|
72
|
+
RequestMethod["sol_getBalance"] = "getBalance";
|
|
73
|
+
RequestMethod["sol_getBlock"] = "getBlock";
|
|
74
|
+
RequestMethod["sol_getBlockCommitment"] = "getBlockCommitment";
|
|
75
|
+
RequestMethod["sol_getBlockHeight"] = "getBlockHeight";
|
|
76
|
+
RequestMethod["sol_getBlockProduction"] = "getBlockProduction";
|
|
77
|
+
RequestMethod["sol_getBlockTime"] = "getBlockTime";
|
|
78
|
+
RequestMethod["sol_getBlocks"] = "getBlocks";
|
|
79
|
+
RequestMethod["sol_getBlocksWithLimit"] = "getBlocksWithLimit";
|
|
80
|
+
RequestMethod["sol_getClusterNodes"] = "getClusterNodes";
|
|
81
|
+
RequestMethod["sol_getEpochInfo"] = "getEpochInfo";
|
|
82
|
+
RequestMethod["sol_getEpochSchedule"] = "getEpochSchedule";
|
|
83
|
+
RequestMethod["sol_getFeeForMessage"] = "getFeeForMessage";
|
|
84
|
+
RequestMethod["sol_getFirstAvailableBlock"] = "getFirstAvailableBlock";
|
|
85
|
+
RequestMethod["sol_getGenesisHash"] = "getGenesisHash";
|
|
86
|
+
RequestMethod["sol_getHealth"] = "getHealth";
|
|
87
|
+
RequestMethod["sol_getHighestSnapshotSlot"] = "getHighestSnapshotSlot";
|
|
88
|
+
RequestMethod["sol_getIdentity"] = "getIdentity";
|
|
89
|
+
RequestMethod["sol_getInflationGovernor"] = "getInflationGovernor";
|
|
90
|
+
RequestMethod["sol_getInflationRate"] = "getInflationRate";
|
|
91
|
+
RequestMethod["sol_getInflationReward"] = "getInflationReward";
|
|
92
|
+
RequestMethod["sol_getLargestAccounts"] = "getLargestAccounts";
|
|
93
|
+
RequestMethod["sol_getLatestBlockhash"] = "getLatestBlockhash";
|
|
94
|
+
RequestMethod["sol_getLeaderSchedule"] = "getLeaderSchedule";
|
|
95
|
+
RequestMethod["sol_getMaxRetransmitSlot"] = "getMaxRetransmitSlot";
|
|
96
|
+
RequestMethod["sol_getMaxShredInsertSlot"] = "getMaxShredInsertSlot";
|
|
97
|
+
RequestMethod["sol_getMinimumBalanceForRentExemption"] = "getMinimumBalanceForRentExemption";
|
|
98
|
+
RequestMethod["sol_getMultipleAccounts"] = "getMultipleAccounts";
|
|
99
|
+
RequestMethod["sol_getProgramAccounts"] = "getProgramAccounts";
|
|
100
|
+
RequestMethod["sol_getRecentPerformanceSamples"] = "getRecentPerformanceSamples";
|
|
101
|
+
RequestMethod["sol_getRecentPrioritizationFees"] = "getRecentPrioritizationFees";
|
|
102
|
+
RequestMethod["sol_getSignatureStatuses"] = "getSignatureStatuses";
|
|
103
|
+
RequestMethod["sol_getSignaturesForAddress"] = "getSignaturesForAddress";
|
|
104
|
+
RequestMethod["sol_getSlot"] = "getSlot";
|
|
105
|
+
RequestMethod["sol_getSlotLeader"] = "getSlotLeader";
|
|
106
|
+
RequestMethod["sol_getSlotLeaders"] = "getSlotLeaders";
|
|
107
|
+
RequestMethod["sol_getStakeActivation"] = "getStakeActivation";
|
|
108
|
+
RequestMethod["sol_getStakeMinimumDelegation"] = "getStakeMinimumDelegation";
|
|
109
|
+
RequestMethod["sol_getSupply"] = "getSupply";
|
|
110
|
+
RequestMethod["sol_getTokenAccountBalance"] = "getTokenAccountBalance";
|
|
111
|
+
RequestMethod["sol_getTokenAccountsByDelegate"] = "getTokenAccountsByDelegate";
|
|
112
|
+
RequestMethod["sol_getTokenAccountsByOwner"] = "getTokenAccountsByOwner";
|
|
113
|
+
RequestMethod["sol_getTokenLargestAccounts"] = "getTokenLargestAccounts";
|
|
114
|
+
RequestMethod["sol_getTokenSupply"] = "getTokenSupply";
|
|
115
|
+
RequestMethod["sol_getTransaction"] = "getTransaction";
|
|
116
|
+
RequestMethod["sol_getTransactionCount"] = "getTransactionCount";
|
|
117
|
+
RequestMethod["sol_getVersion"] = "getVersion";
|
|
118
|
+
RequestMethod["sol_getVoteAccounts"] = "getVoteAccounts";
|
|
119
|
+
RequestMethod["sol_isBlockhashValid"] = "isBlockhashValid";
|
|
120
|
+
RequestMethod["sol_minimumLedgerSlot"] = "minimumLedgerSlot";
|
|
121
|
+
RequestMethod["sol_requestAirdrop"] = "requestAirdrop";
|
|
122
|
+
RequestMethod["sol_sendTransaction"] = "sendTransaction";
|
|
123
|
+
RequestMethod["sol_simulateTransaction"] = "simulateTransaction";
|
|
124
|
+
// Solana Wallet Methods
|
|
125
|
+
RequestMethod["sol_signAndConfirmTransaction"] = "sol_signAndConfirmTransaction";
|
|
126
|
+
RequestMethod["sol_signAndSendTransaction"] = "sol_signAndSendTransaction";
|
|
127
|
+
RequestMethod["sol_signMessage"] = "sol_signMessage";
|
|
128
|
+
RequestMethod["sol_signTransaction"] = "sol_signTransaction";
|
|
129
|
+
})(RequestMethod || (RequestMethod = {}));
|
|
11
130
|
const passiveSignerMethods = [
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
131
|
+
RequestMethod.eth_accounts,
|
|
132
|
+
RequestMethod.eth_chainId,
|
|
133
|
+
RequestMethod.eth_requestAccounts,
|
|
15
134
|
];
|
|
16
135
|
const signerMethods = [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
136
|
+
RequestMethod.eth_accounts,
|
|
137
|
+
RequestMethod.eth_chainId,
|
|
138
|
+
RequestMethod.eth_requestAccounts,
|
|
139
|
+
RequestMethod.eth_sendTransaction,
|
|
140
|
+
RequestMethod.eth_sign,
|
|
141
|
+
RequestMethod.eth_signTransaction,
|
|
142
|
+
RequestMethod.eth_signTypedData_v3,
|
|
143
|
+
RequestMethod.eth_signTypedData_v4,
|
|
144
|
+
RequestMethod.personal_sign,
|
|
145
|
+
RequestMethod.sol_signAndConfirmTransaction,
|
|
146
|
+
RequestMethod.sol_signAndSendTransaction,
|
|
147
|
+
RequestMethod.sol_signMessage,
|
|
148
|
+
RequestMethod.sol_signTransaction,
|
|
30
149
|
];
|
|
31
150
|
class Provider {
|
|
32
|
-
constructor({ portal }) {
|
|
151
|
+
constructor({ portal, chainId }) {
|
|
33
152
|
this.enforceEip155ChainId = (chainId) => {
|
|
34
153
|
if (!chainId) {
|
|
35
154
|
throw new Error('[PortalProvider] Chain ID is required for the operation');
|
|
@@ -49,14 +168,14 @@ class Provider {
|
|
|
49
168
|
this.buildParams = (method, txParams) => {
|
|
50
169
|
let params = txParams;
|
|
51
170
|
switch (method) {
|
|
52
|
-
case
|
|
53
|
-
case
|
|
54
|
-
case
|
|
55
|
-
case
|
|
56
|
-
case
|
|
57
|
-
case
|
|
58
|
-
case
|
|
59
|
-
case
|
|
171
|
+
case RequestMethod.eth_sign:
|
|
172
|
+
case RequestMethod.personal_sign:
|
|
173
|
+
case RequestMethod.eth_signTypedData_v3:
|
|
174
|
+
case RequestMethod.eth_signTypedData_v4:
|
|
175
|
+
case RequestMethod.sol_signAndConfirmTransaction:
|
|
176
|
+
case RequestMethod.sol_signAndSendTransaction:
|
|
177
|
+
case RequestMethod.sol_signMessage:
|
|
178
|
+
case RequestMethod.sol_signTransaction:
|
|
60
179
|
if (!Array.isArray(txParams)) {
|
|
61
180
|
params = [txParams];
|
|
62
181
|
}
|
|
@@ -68,8 +187,14 @@ class Provider {
|
|
|
68
187
|
}
|
|
69
188
|
return params;
|
|
70
189
|
};
|
|
190
|
+
this.getCAIP2ChainId = (chainId) => {
|
|
191
|
+
if (!chainId && !this.chainReferenceId)
|
|
192
|
+
throw new Error('[PortalProvider] Chain ID is required for the operation');
|
|
193
|
+
return chainId || `eip155:${this.chainReferenceId}`;
|
|
194
|
+
};
|
|
71
195
|
this.events = {};
|
|
72
196
|
this.portal = portal;
|
|
197
|
+
this.chainReferenceId = chainId;
|
|
73
198
|
}
|
|
74
199
|
/**
|
|
75
200
|
* Invokes all registered event handlers with the data provided
|
|
@@ -132,9 +257,10 @@ class Provider {
|
|
|
132
257
|
* @param args The arguments of the request being made
|
|
133
258
|
* @returns Promise<any>
|
|
134
259
|
*/
|
|
135
|
-
request({ chainId, method, params, }) {
|
|
260
|
+
request({ chainId: requestChainId, method, params, }) {
|
|
136
261
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
262
|
const isSignerMethod = signerMethods.includes(method);
|
|
263
|
+
const chainId = this.getCAIP2ChainId(requestChainId);
|
|
138
264
|
if (!isSignerMethod && !method.startsWith('wallet_')) {
|
|
139
265
|
// Send to Gateway for RPC calls
|
|
140
266
|
const response = yield this.handleGatewayRequest({
|
|
@@ -182,6 +308,12 @@ class Provider {
|
|
|
182
308
|
}
|
|
183
309
|
});
|
|
184
310
|
}
|
|
311
|
+
setChainId(chainId) {
|
|
312
|
+
if (!Number.isInteger(chainId))
|
|
313
|
+
throw new Error(`[PortalProvider] Chain ID must be an integer, got ${chainId}`);
|
|
314
|
+
this.chainReferenceId = chainId;
|
|
315
|
+
this.emit('chainChanged', { chainId });
|
|
316
|
+
}
|
|
185
317
|
/************************
|
|
186
318
|
* Private Methods
|
|
187
319
|
************************/
|
|
@@ -278,22 +410,22 @@ class Provider {
|
|
|
278
410
|
return;
|
|
279
411
|
}
|
|
280
412
|
switch (method) {
|
|
281
|
-
case
|
|
413
|
+
case RequestMethod.eth_chainId: {
|
|
282
414
|
this.enforceEip155ChainId(chainId);
|
|
283
415
|
const chainReferenceId = parseInt(chainId.split(':')[1]);
|
|
284
416
|
return `0x${chainReferenceId.toString(16)}`;
|
|
285
417
|
}
|
|
286
|
-
case
|
|
287
|
-
case
|
|
418
|
+
case RequestMethod.eth_accounts:
|
|
419
|
+
case RequestMethod.eth_requestAccounts: {
|
|
288
420
|
this.enforceEip155ChainId(chainId);
|
|
289
421
|
return [this.portal.address];
|
|
290
422
|
}
|
|
291
|
-
case
|
|
292
|
-
case
|
|
293
|
-
case
|
|
294
|
-
case
|
|
295
|
-
case
|
|
296
|
-
case
|
|
423
|
+
case RequestMethod.eth_sendTransaction:
|
|
424
|
+
case RequestMethod.eth_sign:
|
|
425
|
+
case RequestMethod.eth_signTransaction:
|
|
426
|
+
case RequestMethod.eth_signTypedData_v3:
|
|
427
|
+
case RequestMethod.eth_signTypedData_v4:
|
|
428
|
+
case RequestMethod.personal_sign: {
|
|
297
429
|
this.enforceEip155ChainId(chainId);
|
|
298
430
|
const result = yield this.portal.mpc.sign({
|
|
299
431
|
chainId: chainId,
|
|
@@ -303,10 +435,10 @@ class Provider {
|
|
|
303
435
|
});
|
|
304
436
|
return result;
|
|
305
437
|
}
|
|
306
|
-
case
|
|
307
|
-
case
|
|
308
|
-
case
|
|
309
|
-
case
|
|
438
|
+
case RequestMethod.sol_signAndConfirmTransaction:
|
|
439
|
+
case RequestMethod.sol_signAndSendTransaction:
|
|
440
|
+
case RequestMethod.sol_signMessage:
|
|
441
|
+
case RequestMethod.sol_signTransaction: {
|
|
310
442
|
this.enforceSolanaChainId(chainId);
|
|
311
443
|
const result = yield this.portal.mpc.sign({
|
|
312
444
|
chainId: chainId,
|