@portal-hq/web 3.2.3 → 3.3.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/README.md +1 -1
- package/lib/commonjs/index.js +142 -18
- 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 +157 -37
- package/lib/commonjs/provider/index.test.js +1222 -0
- package/lib/esm/index.js +117 -17
- 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 +156 -37
- 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 +177 -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 +160 -37
- package/types.d.ts +295 -34
|
@@ -9,26 +9,146 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RequestMethod = void 0;
|
|
12
13
|
const errors_1 = require("./errors");
|
|
14
|
+
var RequestMethod;
|
|
15
|
+
(function (RequestMethod) {
|
|
16
|
+
RequestMethod["eth_accounts"] = "eth_accounts";
|
|
17
|
+
RequestMethod["eth_blockNumber"] = "eth_blockNumber";
|
|
18
|
+
RequestMethod["eth_call"] = "eth_call";
|
|
19
|
+
RequestMethod["eth_chainId"] = "eth_chainId";
|
|
20
|
+
RequestMethod["eth_coinbase"] = "eth_coinbase";
|
|
21
|
+
RequestMethod["eth_compileSolidity"] = "eth_compileSolidity";
|
|
22
|
+
RequestMethod["eth_compileLLL"] = "eth_compileLLL";
|
|
23
|
+
RequestMethod["eth_compileSerpent"] = "eth_compileSerpent";
|
|
24
|
+
RequestMethod["eth_estimateGas"] = "eth_estimateGas";
|
|
25
|
+
RequestMethod["eth_gasPrice"] = "eth_gasPrice";
|
|
26
|
+
RequestMethod["eth_getBalance"] = "eth_getBalance";
|
|
27
|
+
RequestMethod["eth_getBlockByHash"] = "eth_getBlockByHash";
|
|
28
|
+
RequestMethod["eth_getBlockByNumber"] = "eth_getBlockByNumber";
|
|
29
|
+
RequestMethod["eth_getBlockTransactionCountByHash"] = "eth_getBlockTransactionCountByHash";
|
|
30
|
+
RequestMethod["eth_getBlockTransactionCountByNumber"] = "eth_getBlockTransactionCountByNumber";
|
|
31
|
+
RequestMethod["eth_getCode"] = "eth_getCode";
|
|
32
|
+
RequestMethod["eth_getCompilers"] = "eth_getCompilers";
|
|
33
|
+
RequestMethod["eth_getFilterChange"] = "eth_getFilterChange";
|
|
34
|
+
RequestMethod["eth_getFilterLogs"] = "eth_getFilterLogs";
|
|
35
|
+
RequestMethod["eth_getLogs"] = "eth_getLogs";
|
|
36
|
+
RequestMethod["eth_getStorageAt"] = "eth_getStorageAt";
|
|
37
|
+
RequestMethod["eth_getTransactionByHash"] = "eth_getTransactionByHash";
|
|
38
|
+
RequestMethod["eth_getTransactionByBlockHashAndIndex"] = "eth_getTransactionByBlockHashAndIndex";
|
|
39
|
+
RequestMethod["eth_getTransactionByBlockNumberAndIndex"] = "eth_getTransactionByBlockNumberAndIndex";
|
|
40
|
+
RequestMethod["eth_getTransactionCount"] = "eth_getTransactionCount";
|
|
41
|
+
RequestMethod["eth_getTransactionReceipt"] = "eth_getTransactionReceipt";
|
|
42
|
+
RequestMethod["eth_getUncleByBlockHashAndIndex"] = "eth_getUncleByBlockHashAndIndex";
|
|
43
|
+
RequestMethod["eth_getUncleByBlockNumberAndIndex"] = "eth_getUncleByBlockNumberAndIndex";
|
|
44
|
+
RequestMethod["eth_getUncleCountByBlockHash"] = "eth_getUncleCountByBlockHash";
|
|
45
|
+
RequestMethod["eth_getUncleCountByBlockNumber"] = "eth_getUncleCountByBlockNumber";
|
|
46
|
+
RequestMethod["eth_getWork"] = "eth_getWork";
|
|
47
|
+
RequestMethod["eth_hashrate"] = "eth_hashrate";
|
|
48
|
+
RequestMethod["eth_mining"] = "eth_mining";
|
|
49
|
+
RequestMethod["eth_newBlockFilter"] = "eth_newBlockFilter";
|
|
50
|
+
RequestMethod["eth_newFilter"] = "eth_newFilter";
|
|
51
|
+
RequestMethod["eth_newPendingTransactionFilter"] = "eth_newPendingTransactionFilter";
|
|
52
|
+
RequestMethod["personal_sign"] = "personal_sign";
|
|
53
|
+
RequestMethod["eth_protocolVersion"] = "eth_protocolVersion";
|
|
54
|
+
RequestMethod["eth_requestAccounts"] = "eth_requestAccounts";
|
|
55
|
+
RequestMethod["eth_sendRawTransaction"] = "eth_sendRawTransaction";
|
|
56
|
+
RequestMethod["eth_sendTransaction"] = "eth_sendTransaction";
|
|
57
|
+
RequestMethod["eth_sign"] = "eth_sign";
|
|
58
|
+
RequestMethod["eth_signTransaction"] = "eth_signTransaction";
|
|
59
|
+
RequestMethod["eth_signTypedData"] = "eth_signTypedData";
|
|
60
|
+
RequestMethod["eth_signTypedData_v3"] = "eth_signTypedData_v3";
|
|
61
|
+
RequestMethod["eth_signTypedData_v4"] = "eth_signTypedData_v4";
|
|
62
|
+
RequestMethod["eth_submitHashrate"] = "eth_submitHashrate";
|
|
63
|
+
RequestMethod["eth_submitWork"] = "eth_submitWork";
|
|
64
|
+
RequestMethod["eth_syncing"] = "eth_syncing";
|
|
65
|
+
RequestMethod["eth_uninstallFilter"] = "eth_uninstallFilter";
|
|
66
|
+
// Net Methods
|
|
67
|
+
RequestMethod["net_listening"] = "net_listening";
|
|
68
|
+
RequestMethod["net_peerCount"] = "net_peerCount";
|
|
69
|
+
RequestMethod["net_version"] = "net_version";
|
|
70
|
+
// Web3 Methods
|
|
71
|
+
RequestMethod["web3_clientVersion"] = "web3_clientVersion";
|
|
72
|
+
RequestMethod["web3_sha3"] = "web3_sha3";
|
|
73
|
+
// Solana RPC Methods
|
|
74
|
+
RequestMethod["sol_getAccountInfo"] = "getAccountInfo";
|
|
75
|
+
RequestMethod["sol_getBalance"] = "getBalance";
|
|
76
|
+
RequestMethod["sol_getBlock"] = "getBlock";
|
|
77
|
+
RequestMethod["sol_getBlockCommitment"] = "getBlockCommitment";
|
|
78
|
+
RequestMethod["sol_getBlockHeight"] = "getBlockHeight";
|
|
79
|
+
RequestMethod["sol_getBlockProduction"] = "getBlockProduction";
|
|
80
|
+
RequestMethod["sol_getBlockTime"] = "getBlockTime";
|
|
81
|
+
RequestMethod["sol_getBlocks"] = "getBlocks";
|
|
82
|
+
RequestMethod["sol_getBlocksWithLimit"] = "getBlocksWithLimit";
|
|
83
|
+
RequestMethod["sol_getClusterNodes"] = "getClusterNodes";
|
|
84
|
+
RequestMethod["sol_getEpochInfo"] = "getEpochInfo";
|
|
85
|
+
RequestMethod["sol_getEpochSchedule"] = "getEpochSchedule";
|
|
86
|
+
RequestMethod["sol_getFeeForMessage"] = "getFeeForMessage";
|
|
87
|
+
RequestMethod["sol_getFirstAvailableBlock"] = "getFirstAvailableBlock";
|
|
88
|
+
RequestMethod["sol_getGenesisHash"] = "getGenesisHash";
|
|
89
|
+
RequestMethod["sol_getHealth"] = "getHealth";
|
|
90
|
+
RequestMethod["sol_getHighestSnapshotSlot"] = "getHighestSnapshotSlot";
|
|
91
|
+
RequestMethod["sol_getIdentity"] = "getIdentity";
|
|
92
|
+
RequestMethod["sol_getInflationGovernor"] = "getInflationGovernor";
|
|
93
|
+
RequestMethod["sol_getInflationRate"] = "getInflationRate";
|
|
94
|
+
RequestMethod["sol_getInflationReward"] = "getInflationReward";
|
|
95
|
+
RequestMethod["sol_getLargestAccounts"] = "getLargestAccounts";
|
|
96
|
+
RequestMethod["sol_getLatestBlockhash"] = "getLatestBlockhash";
|
|
97
|
+
RequestMethod["sol_getLeaderSchedule"] = "getLeaderSchedule";
|
|
98
|
+
RequestMethod["sol_getMaxRetransmitSlot"] = "getMaxRetransmitSlot";
|
|
99
|
+
RequestMethod["sol_getMaxShredInsertSlot"] = "getMaxShredInsertSlot";
|
|
100
|
+
RequestMethod["sol_getMinimumBalanceForRentExemption"] = "getMinimumBalanceForRentExemption";
|
|
101
|
+
RequestMethod["sol_getMultipleAccounts"] = "getMultipleAccounts";
|
|
102
|
+
RequestMethod["sol_getProgramAccounts"] = "getProgramAccounts";
|
|
103
|
+
RequestMethod["sol_getRecentPerformanceSamples"] = "getRecentPerformanceSamples";
|
|
104
|
+
RequestMethod["sol_getRecentPrioritizationFees"] = "getRecentPrioritizationFees";
|
|
105
|
+
RequestMethod["sol_getSignatureStatuses"] = "getSignatureStatuses";
|
|
106
|
+
RequestMethod["sol_getSignaturesForAddress"] = "getSignaturesForAddress";
|
|
107
|
+
RequestMethod["sol_getSlot"] = "getSlot";
|
|
108
|
+
RequestMethod["sol_getSlotLeader"] = "getSlotLeader";
|
|
109
|
+
RequestMethod["sol_getSlotLeaders"] = "getSlotLeaders";
|
|
110
|
+
RequestMethod["sol_getStakeActivation"] = "getStakeActivation";
|
|
111
|
+
RequestMethod["sol_getStakeMinimumDelegation"] = "getStakeMinimumDelegation";
|
|
112
|
+
RequestMethod["sol_getSupply"] = "getSupply";
|
|
113
|
+
RequestMethod["sol_getTokenAccountBalance"] = "getTokenAccountBalance";
|
|
114
|
+
RequestMethod["sol_getTokenAccountsByDelegate"] = "getTokenAccountsByDelegate";
|
|
115
|
+
RequestMethod["sol_getTokenAccountsByOwner"] = "getTokenAccountsByOwner";
|
|
116
|
+
RequestMethod["sol_getTokenLargestAccounts"] = "getTokenLargestAccounts";
|
|
117
|
+
RequestMethod["sol_getTokenSupply"] = "getTokenSupply";
|
|
118
|
+
RequestMethod["sol_getTransaction"] = "getTransaction";
|
|
119
|
+
RequestMethod["sol_getTransactionCount"] = "getTransactionCount";
|
|
120
|
+
RequestMethod["sol_getVersion"] = "getVersion";
|
|
121
|
+
RequestMethod["sol_getVoteAccounts"] = "getVoteAccounts";
|
|
122
|
+
RequestMethod["sol_isBlockhashValid"] = "isBlockhashValid";
|
|
123
|
+
RequestMethod["sol_minimumLedgerSlot"] = "minimumLedgerSlot";
|
|
124
|
+
RequestMethod["sol_requestAirdrop"] = "requestAirdrop";
|
|
125
|
+
RequestMethod["sol_sendTransaction"] = "sendTransaction";
|
|
126
|
+
RequestMethod["sol_simulateTransaction"] = "simulateTransaction";
|
|
127
|
+
// Solana Wallet Methods
|
|
128
|
+
RequestMethod["sol_signAndConfirmTransaction"] = "sol_signAndConfirmTransaction";
|
|
129
|
+
RequestMethod["sol_signAndSendTransaction"] = "sol_signAndSendTransaction";
|
|
130
|
+
RequestMethod["sol_signMessage"] = "sol_signMessage";
|
|
131
|
+
RequestMethod["sol_signTransaction"] = "sol_signTransaction";
|
|
132
|
+
})(RequestMethod = exports.RequestMethod || (exports.RequestMethod = {}));
|
|
13
133
|
const passiveSignerMethods = [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
134
|
+
RequestMethod.eth_accounts,
|
|
135
|
+
RequestMethod.eth_chainId,
|
|
136
|
+
RequestMethod.eth_requestAccounts,
|
|
17
137
|
];
|
|
18
138
|
const signerMethods = [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
139
|
+
RequestMethod.eth_accounts,
|
|
140
|
+
RequestMethod.eth_chainId,
|
|
141
|
+
RequestMethod.eth_requestAccounts,
|
|
142
|
+
RequestMethod.eth_sendTransaction,
|
|
143
|
+
RequestMethod.eth_sign,
|
|
144
|
+
RequestMethod.eth_signTransaction,
|
|
145
|
+
RequestMethod.eth_signTypedData_v3,
|
|
146
|
+
RequestMethod.eth_signTypedData_v4,
|
|
147
|
+
RequestMethod.personal_sign,
|
|
148
|
+
RequestMethod.sol_signAndConfirmTransaction,
|
|
149
|
+
RequestMethod.sol_signAndSendTransaction,
|
|
150
|
+
RequestMethod.sol_signMessage,
|
|
151
|
+
RequestMethod.sol_signTransaction,
|
|
32
152
|
];
|
|
33
153
|
class Provider {
|
|
34
154
|
constructor({ portal }) {
|
|
@@ -51,14 +171,14 @@ class Provider {
|
|
|
51
171
|
this.buildParams = (method, txParams) => {
|
|
52
172
|
let params = txParams;
|
|
53
173
|
switch (method) {
|
|
54
|
-
case
|
|
55
|
-
case
|
|
56
|
-
case
|
|
57
|
-
case
|
|
58
|
-
case
|
|
59
|
-
case
|
|
60
|
-
case
|
|
61
|
-
case
|
|
174
|
+
case RequestMethod.eth_sign:
|
|
175
|
+
case RequestMethod.personal_sign:
|
|
176
|
+
case RequestMethod.eth_signTypedData_v3:
|
|
177
|
+
case RequestMethod.eth_signTypedData_v4:
|
|
178
|
+
case RequestMethod.sol_signAndConfirmTransaction:
|
|
179
|
+
case RequestMethod.sol_signAndSendTransaction:
|
|
180
|
+
case RequestMethod.sol_signMessage:
|
|
181
|
+
case RequestMethod.sol_signTransaction:
|
|
62
182
|
if (!Array.isArray(txParams)) {
|
|
63
183
|
params = [txParams];
|
|
64
184
|
}
|
|
@@ -280,22 +400,22 @@ class Provider {
|
|
|
280
400
|
return;
|
|
281
401
|
}
|
|
282
402
|
switch (method) {
|
|
283
|
-
case
|
|
403
|
+
case RequestMethod.eth_chainId: {
|
|
284
404
|
this.enforceEip155ChainId(chainId);
|
|
285
405
|
const chainReferenceId = parseInt(chainId.split(':')[1]);
|
|
286
406
|
return `0x${chainReferenceId.toString(16)}`;
|
|
287
407
|
}
|
|
288
|
-
case
|
|
289
|
-
case
|
|
408
|
+
case RequestMethod.eth_accounts:
|
|
409
|
+
case RequestMethod.eth_requestAccounts: {
|
|
290
410
|
this.enforceEip155ChainId(chainId);
|
|
291
411
|
return [this.portal.address];
|
|
292
412
|
}
|
|
293
|
-
case
|
|
294
|
-
case
|
|
295
|
-
case
|
|
296
|
-
case
|
|
297
|
-
case
|
|
298
|
-
case
|
|
413
|
+
case RequestMethod.eth_sendTransaction:
|
|
414
|
+
case RequestMethod.eth_sign:
|
|
415
|
+
case RequestMethod.eth_signTransaction:
|
|
416
|
+
case RequestMethod.eth_signTypedData_v3:
|
|
417
|
+
case RequestMethod.eth_signTypedData_v4:
|
|
418
|
+
case RequestMethod.personal_sign: {
|
|
299
419
|
this.enforceEip155ChainId(chainId);
|
|
300
420
|
const result = yield this.portal.mpc.sign({
|
|
301
421
|
chainId: chainId,
|
|
@@ -305,10 +425,10 @@ class Provider {
|
|
|
305
425
|
});
|
|
306
426
|
return result;
|
|
307
427
|
}
|
|
308
|
-
case
|
|
309
|
-
case
|
|
310
|
-
case
|
|
311
|
-
case
|
|
428
|
+
case RequestMethod.sol_signAndConfirmTransaction:
|
|
429
|
+
case RequestMethod.sol_signAndSendTransaction:
|
|
430
|
+
case RequestMethod.sol_signMessage:
|
|
431
|
+
case RequestMethod.sol_signTransaction: {
|
|
312
432
|
this.enforceSolanaChainId(chainId);
|
|
313
433
|
const result = yield this.portal.mpc.sign({
|
|
314
434
|
chainId: chainId,
|