@portal-hq/web 3.3.0 → 3.3.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/lib/commonjs/index.js +5 -1
- package/lib/commonjs/mpc/index.js +1 -1
- package/lib/commonjs/provider/index.js +15 -2
- package/lib/esm/index.js +5 -1
- package/lib/esm/mpc/index.js +1 -1
- package/lib/esm/provider/index.js +15 -2
- package/package.json +1 -1
- package/src/index.ts +6 -0
- package/src/mpc/index.ts +1 -1
- package/src/provider/index.ts +24 -2
- package/types.d.ts +4 -0
package/lib/commonjs/index.js
CHANGED
|
@@ -47,7 +47,7 @@ class Portal {
|
|
|
47
47
|
// Required
|
|
48
48
|
rpcConfig,
|
|
49
49
|
// Optional
|
|
50
|
-
apiKey, authToken, authUrl, autoApprove = false, gdrive, passkey, host = 'web.portalhq.io', mpcVersion = 'v6', mpcHost = 'mpc-client.portalhq.io', featureFlags = {}, }) {
|
|
50
|
+
apiKey, authToken, authUrl, autoApprove = false, gdrive, passkey, host = 'web.portalhq.io', mpcVersion = 'v6', mpcHost = 'mpc-client.portalhq.io', featureFlags = {}, chainId, }) {
|
|
51
51
|
this.errorCallbacks = [];
|
|
52
52
|
this.readyCallbacks = [];
|
|
53
53
|
this.sendEth = ({ chainId, to, value, }) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -83,6 +83,7 @@ class Portal {
|
|
|
83
83
|
});
|
|
84
84
|
this.provider = new provider_1.default({
|
|
85
85
|
portal: this,
|
|
86
|
+
chainId: chainId ? Number(chainId) : undefined,
|
|
86
87
|
});
|
|
87
88
|
}
|
|
88
89
|
/*****************************
|
|
@@ -312,6 +313,9 @@ class Portal {
|
|
|
312
313
|
return this.provider.request(request);
|
|
313
314
|
});
|
|
314
315
|
}
|
|
316
|
+
updateChain(newChainId) {
|
|
317
|
+
this.provider.setChainId(Number(newChainId));
|
|
318
|
+
}
|
|
315
319
|
/**
|
|
316
320
|
* Estimates the amount of gas that will be required to execute an Ethereum transaction.
|
|
317
321
|
*
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.MpcErrorCodes = exports.MpcError = void 0;
|
|
13
13
|
const errors_1 = require("./errors");
|
|
14
14
|
const index_1 = require("../index");
|
|
15
|
-
const WEB_SDK_VERSION = '3.3.
|
|
15
|
+
const WEB_SDK_VERSION = '3.3.2';
|
|
16
16
|
class Mpc {
|
|
17
17
|
get ready() {
|
|
18
18
|
return this._ready;
|
|
@@ -151,7 +151,7 @@ const signerMethods = [
|
|
|
151
151
|
RequestMethod.sol_signTransaction,
|
|
152
152
|
];
|
|
153
153
|
class Provider {
|
|
154
|
-
constructor({ portal }) {
|
|
154
|
+
constructor({ portal, chainId }) {
|
|
155
155
|
this.enforceEip155ChainId = (chainId) => {
|
|
156
156
|
if (!chainId) {
|
|
157
157
|
throw new Error('[PortalProvider] Chain ID is required for the operation');
|
|
@@ -190,8 +190,14 @@ class Provider {
|
|
|
190
190
|
}
|
|
191
191
|
return params;
|
|
192
192
|
};
|
|
193
|
+
this.getCAIP2ChainId = (chainId) => {
|
|
194
|
+
if (!chainId && !this.chainReferenceId)
|
|
195
|
+
throw new Error('[PortalProvider] Chain ID is required for the operation');
|
|
196
|
+
return chainId || `eip155:${this.chainReferenceId}`;
|
|
197
|
+
};
|
|
193
198
|
this.events = {};
|
|
194
199
|
this.portal = portal;
|
|
200
|
+
this.chainReferenceId = chainId;
|
|
195
201
|
}
|
|
196
202
|
/**
|
|
197
203
|
* Invokes all registered event handlers with the data provided
|
|
@@ -254,9 +260,10 @@ class Provider {
|
|
|
254
260
|
* @param args The arguments of the request being made
|
|
255
261
|
* @returns Promise<any>
|
|
256
262
|
*/
|
|
257
|
-
request({ chainId, method, params, }) {
|
|
263
|
+
request({ chainId: requestChainId, method, params, }) {
|
|
258
264
|
return __awaiter(this, void 0, void 0, function* () {
|
|
259
265
|
const isSignerMethod = signerMethods.includes(method);
|
|
266
|
+
const chainId = this.getCAIP2ChainId(requestChainId);
|
|
260
267
|
if (!isSignerMethod && !method.startsWith('wallet_')) {
|
|
261
268
|
// Send to Gateway for RPC calls
|
|
262
269
|
const response = yield this.handleGatewayRequest({
|
|
@@ -304,6 +311,12 @@ class Provider {
|
|
|
304
311
|
}
|
|
305
312
|
});
|
|
306
313
|
}
|
|
314
|
+
setChainId(chainId) {
|
|
315
|
+
if (!Number.isInteger(chainId))
|
|
316
|
+
throw new Error(`[PortalProvider] Chain ID must be an integer, got ${chainId}`);
|
|
317
|
+
this.chainReferenceId = chainId;
|
|
318
|
+
this.emit('chainChanged', { chainId });
|
|
319
|
+
}
|
|
307
320
|
/************************
|
|
308
321
|
* Private Methods
|
|
309
322
|
************************/
|
package/lib/esm/index.js
CHANGED
|
@@ -18,7 +18,7 @@ class Portal {
|
|
|
18
18
|
// Required
|
|
19
19
|
rpcConfig,
|
|
20
20
|
// Optional
|
|
21
|
-
apiKey, authToken, authUrl, autoApprove = false, gdrive, passkey, host = 'web.portalhq.io', mpcVersion = 'v6', mpcHost = 'mpc-client.portalhq.io', featureFlags = {}, }) {
|
|
21
|
+
apiKey, authToken, authUrl, autoApprove = false, gdrive, passkey, host = 'web.portalhq.io', mpcVersion = 'v6', mpcHost = 'mpc-client.portalhq.io', featureFlags = {}, chainId, }) {
|
|
22
22
|
this.errorCallbacks = [];
|
|
23
23
|
this.readyCallbacks = [];
|
|
24
24
|
this.sendEth = ({ chainId, to, value, }) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -54,6 +54,7 @@ class Portal {
|
|
|
54
54
|
});
|
|
55
55
|
this.provider = new Provider({
|
|
56
56
|
portal: this,
|
|
57
|
+
chainId: chainId ? Number(chainId) : undefined,
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
60
|
/*****************************
|
|
@@ -283,6 +284,9 @@ class Portal {
|
|
|
283
284
|
return this.provider.request(request);
|
|
284
285
|
});
|
|
285
286
|
}
|
|
287
|
+
updateChain(newChainId) {
|
|
288
|
+
this.provider.setChainId(Number(newChainId));
|
|
289
|
+
}
|
|
286
290
|
/**
|
|
287
291
|
* Estimates the amount of gas that will be required to execute an Ethereum transaction.
|
|
288
292
|
*
|
package/lib/esm/mpc/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { PortalMpcError } from './errors';
|
|
11
11
|
import { BackupMethods, } from '../index';
|
|
12
|
-
const WEB_SDK_VERSION = '3.3.
|
|
12
|
+
const WEB_SDK_VERSION = '3.3.2';
|
|
13
13
|
class Mpc {
|
|
14
14
|
get ready() {
|
|
15
15
|
return this._ready;
|
|
@@ -148,7 +148,7 @@ const signerMethods = [
|
|
|
148
148
|
RequestMethod.sol_signTransaction,
|
|
149
149
|
];
|
|
150
150
|
class Provider {
|
|
151
|
-
constructor({ portal }) {
|
|
151
|
+
constructor({ portal, chainId }) {
|
|
152
152
|
this.enforceEip155ChainId = (chainId) => {
|
|
153
153
|
if (!chainId) {
|
|
154
154
|
throw new Error('[PortalProvider] Chain ID is required for the operation');
|
|
@@ -187,8 +187,14 @@ class Provider {
|
|
|
187
187
|
}
|
|
188
188
|
return params;
|
|
189
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
|
+
};
|
|
190
195
|
this.events = {};
|
|
191
196
|
this.portal = portal;
|
|
197
|
+
this.chainReferenceId = chainId;
|
|
192
198
|
}
|
|
193
199
|
/**
|
|
194
200
|
* Invokes all registered event handlers with the data provided
|
|
@@ -251,9 +257,10 @@ class Provider {
|
|
|
251
257
|
* @param args The arguments of the request being made
|
|
252
258
|
* @returns Promise<any>
|
|
253
259
|
*/
|
|
254
|
-
request({ chainId, method, params, }) {
|
|
260
|
+
request({ chainId: requestChainId, method, params, }) {
|
|
255
261
|
return __awaiter(this, void 0, void 0, function* () {
|
|
256
262
|
const isSignerMethod = signerMethods.includes(method);
|
|
263
|
+
const chainId = this.getCAIP2ChainId(requestChainId);
|
|
257
264
|
if (!isSignerMethod && !method.startsWith('wallet_')) {
|
|
258
265
|
// Send to Gateway for RPC calls
|
|
259
266
|
const response = yield this.handleGatewayRequest({
|
|
@@ -301,6 +308,12 @@ class Provider {
|
|
|
301
308
|
}
|
|
302
309
|
});
|
|
303
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
|
+
}
|
|
304
317
|
/************************
|
|
305
318
|
* Private Methods
|
|
306
319
|
************************/
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -76,6 +76,7 @@ class Portal {
|
|
|
76
76
|
mpcVersion = 'v6',
|
|
77
77
|
mpcHost = 'mpc-client.portalhq.io',
|
|
78
78
|
featureFlags = {},
|
|
79
|
+
chainId,
|
|
79
80
|
}: PortalOptions) {
|
|
80
81
|
this.apiKey = apiKey
|
|
81
82
|
this.authToken = authToken
|
|
@@ -100,6 +101,7 @@ class Portal {
|
|
|
100
101
|
|
|
101
102
|
this.provider = new Provider({
|
|
102
103
|
portal: this,
|
|
104
|
+
chainId: chainId ? Number(chainId): undefined,
|
|
103
105
|
})
|
|
104
106
|
}
|
|
105
107
|
|
|
@@ -388,6 +390,10 @@ class Portal {
|
|
|
388
390
|
return this.provider.request(request)
|
|
389
391
|
}
|
|
390
392
|
|
|
393
|
+
public updateChain(newChainId: string) {
|
|
394
|
+
this.provider.setChainId(Number(newChainId))
|
|
395
|
+
}
|
|
396
|
+
|
|
391
397
|
/**
|
|
392
398
|
* Estimates the amount of gas that will be required to execute an Ethereum transaction.
|
|
393
399
|
*
|
package/src/mpc/index.ts
CHANGED
package/src/provider/index.ts
CHANGED
|
@@ -160,9 +160,13 @@ class Provider {
|
|
|
160
160
|
|
|
161
161
|
private portal: Portal
|
|
162
162
|
|
|
163
|
-
|
|
163
|
+
// eip155 chain reference ID
|
|
164
|
+
private chainReferenceId?: number
|
|
165
|
+
|
|
166
|
+
constructor({ portal, chainId }: ProviderOptions) {
|
|
164
167
|
this.events = {}
|
|
165
168
|
this.portal = portal
|
|
169
|
+
this.chainReferenceId = chainId
|
|
166
170
|
}
|
|
167
171
|
|
|
168
172
|
/**
|
|
@@ -241,11 +245,12 @@ class Provider {
|
|
|
241
245
|
* @returns Promise<any>
|
|
242
246
|
*/
|
|
243
247
|
public async request({
|
|
244
|
-
chainId,
|
|
248
|
+
chainId: requestChainId,
|
|
245
249
|
method,
|
|
246
250
|
params,
|
|
247
251
|
}: RequestArguments): Promise<any> {
|
|
248
252
|
const isSignerMethod = signerMethods.includes(method)
|
|
253
|
+
const chainId = this.getCAIP2ChainId(requestChainId)
|
|
249
254
|
|
|
250
255
|
if (!isSignerMethod && !method.startsWith('wallet_')) {
|
|
251
256
|
// Send to Gateway for RPC calls
|
|
@@ -297,6 +302,16 @@ class Provider {
|
|
|
297
302
|
}
|
|
298
303
|
}
|
|
299
304
|
|
|
305
|
+
public setChainId(chainId: number) {
|
|
306
|
+
if (!Number.isInteger(chainId))
|
|
307
|
+
throw new Error(
|
|
308
|
+
`[PortalProvider] Chain ID must be an integer, got ${chainId}`,
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
this.chainReferenceId = chainId
|
|
312
|
+
this.emit('chainChanged', { chainId })
|
|
313
|
+
}
|
|
314
|
+
|
|
300
315
|
/************************
|
|
301
316
|
* Private Methods
|
|
302
317
|
************************/
|
|
@@ -523,6 +538,13 @@ class Provider {
|
|
|
523
538
|
|
|
524
539
|
return params
|
|
525
540
|
}
|
|
541
|
+
|
|
542
|
+
private getCAIP2ChainId = (chainId?: string) => {
|
|
543
|
+
if (!chainId && !this.chainReferenceId)
|
|
544
|
+
throw new Error('[PortalProvider] Chain ID is required for the operation')
|
|
545
|
+
|
|
546
|
+
return chainId || `eip155:${this.chainReferenceId}`
|
|
547
|
+
}
|
|
526
548
|
}
|
|
527
549
|
|
|
528
550
|
export default Provider
|
package/types.d.ts
CHANGED
|
@@ -367,11 +367,15 @@ export interface PortalOptions {
|
|
|
367
367
|
keychain?: KeychainAdapter
|
|
368
368
|
mpcVersion?: string
|
|
369
369
|
featureFlags?: FeatureFlags
|
|
370
|
+
chainId?: string
|
|
370
371
|
}
|
|
371
372
|
|
|
372
373
|
export interface ProviderOptions {
|
|
373
374
|
// Required options
|
|
374
375
|
portal: Portal
|
|
376
|
+
|
|
377
|
+
// Optional
|
|
378
|
+
chainId?: number
|
|
375
379
|
}
|
|
376
380
|
|
|
377
381
|
export interface QuoteArgs {
|