@portal-hq/provider 2.0.1 → 2.0.3

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.
@@ -181,7 +181,7 @@ class Provider {
181
181
  * @param args The arguments of the request being made
182
182
  * @returns Promise<any>
183
183
  */
184
- request({ method, params, connect, }) {
184
+ request({ method, params, chainId, connect, }) {
185
185
  return __awaiter(this, void 0, void 0, function* () {
186
186
  if (method === 'eth_chainId') {
187
187
  return this.chainId;
@@ -206,6 +206,7 @@ class Provider {
206
206
  const transactionHash = yield this.handleSigningRequests({
207
207
  method,
208
208
  params,
209
+ chainId,
209
210
  connect,
210
211
  });
211
212
  if (transactionHash) {
@@ -249,7 +250,7 @@ class Provider {
249
250
  this.emit('chainChanged', {
250
251
  chainId: this.chainId,
251
252
  });
252
- if (connect) {
253
+ if (connect && connect.connected) {
253
254
  connect.emit('portalConnect_chainChanged', {
254
255
  chainId: this.chainId,
255
256
  });
@@ -264,7 +265,7 @@ class Provider {
264
265
  *
265
266
  * @param args The arguments of the request being made
266
267
  */
267
- getApproval({ method, params, connect, }) {
268
+ getApproval({ method, params, chainId, connect, }) {
268
269
  return __awaiter(this, void 0, void 0, function* () {
269
270
  // If autoApprove is enabled, just resolve to true
270
271
  if (this.autoApprove) {
@@ -305,12 +306,14 @@ class Provider {
305
306
  connect.emit('portalConnect_signingRequested', {
306
307
  method,
307
308
  params,
309
+ chainId,
308
310
  });
309
311
  }
310
312
  else {
311
313
  this.emit('portal_signingRequested', {
312
314
  method,
313
315
  params,
316
+ chainId,
314
317
  });
315
318
  }
316
319
  });
@@ -348,12 +351,12 @@ class Provider {
348
351
  * @param args The arguments of the request being made
349
352
  * @returns Promise<any>
350
353
  */
351
- handleSigningRequests({ method, params, connect, }) {
354
+ handleSigningRequests({ method, params, chainId, connect, }) {
352
355
  var _a;
353
356
  return __awaiter(this, void 0, void 0, function* () {
354
357
  const isApproved = passiveSignerMethods.includes(method)
355
358
  ? true
356
- : yield this.getApproval({ method, params, connect });
359
+ : yield this.getApproval({ method, params, chainId, connect });
357
360
  if (!isApproved) {
358
361
  this.log.info(`[PortalProvider] Request for signing method '${method}' could not be completed because it was not approved by the user.`);
359
362
  return;
@@ -61,7 +61,11 @@ class MpcSigner {
61
61
  break;
62
62
  }
63
63
  const signingShare = yield this.signingShare;
64
- const result = yield this.mpc.sign(apiKey, this.mpcHost, signingShare, message.method, JSON.stringify(this.buildParams(method, params)), provider.gatewayUrl, provider.chainId.toString(), this.version);
64
+ const metadata = JSON.stringify({
65
+ clientPlatform: 'REACT_NATIVE',
66
+ mpcServerVersion: this.version,
67
+ });
68
+ const result = yield this.mpc.sign(apiKey, this.mpcHost, signingShare, message.method, JSON.stringify(this.buildParams(method, params)), provider.gatewayUrl, provider.chainId.toString(), metadata);
65
69
  const { data, error } = JSON.parse(String(result));
66
70
  if (error && error.code > 0) {
67
71
  throw new utils_1.PortalMpcError(error);
@@ -179,7 +179,7 @@ class Provider {
179
179
  * @param args The arguments of the request being made
180
180
  * @returns Promise<any>
181
181
  */
182
- request({ method, params, connect, }) {
182
+ request({ method, params, chainId, connect, }) {
183
183
  return __awaiter(this, void 0, void 0, function* () {
184
184
  if (method === 'eth_chainId') {
185
185
  return this.chainId;
@@ -204,6 +204,7 @@ class Provider {
204
204
  const transactionHash = yield this.handleSigningRequests({
205
205
  method,
206
206
  params,
207
+ chainId,
207
208
  connect,
208
209
  });
209
210
  if (transactionHash) {
@@ -247,7 +248,7 @@ class Provider {
247
248
  this.emit('chainChanged', {
248
249
  chainId: this.chainId,
249
250
  });
250
- if (connect) {
251
+ if (connect && connect.connected) {
251
252
  connect.emit('portalConnect_chainChanged', {
252
253
  chainId: this.chainId,
253
254
  });
@@ -262,7 +263,7 @@ class Provider {
262
263
  *
263
264
  * @param args The arguments of the request being made
264
265
  */
265
- getApproval({ method, params, connect, }) {
266
+ getApproval({ method, params, chainId, connect, }) {
266
267
  return __awaiter(this, void 0, void 0, function* () {
267
268
  // If autoApprove is enabled, just resolve to true
268
269
  if (this.autoApprove) {
@@ -303,12 +304,14 @@ class Provider {
303
304
  connect.emit('portalConnect_signingRequested', {
304
305
  method,
305
306
  params,
307
+ chainId,
306
308
  });
307
309
  }
308
310
  else {
309
311
  this.emit('portal_signingRequested', {
310
312
  method,
311
313
  params,
314
+ chainId,
312
315
  });
313
316
  }
314
317
  });
@@ -346,12 +349,12 @@ class Provider {
346
349
  * @param args The arguments of the request being made
347
350
  * @returns Promise<any>
348
351
  */
349
- handleSigningRequests({ method, params, connect, }) {
352
+ handleSigningRequests({ method, params, chainId, connect, }) {
350
353
  var _a;
351
354
  return __awaiter(this, void 0, void 0, function* () {
352
355
  const isApproved = passiveSignerMethods.includes(method)
353
356
  ? true
354
- : yield this.getApproval({ method, params, connect });
357
+ : yield this.getApproval({ method, params, chainId, connect });
355
358
  if (!isApproved) {
356
359
  this.log.info(`[PortalProvider] Request for signing method '${method}' could not be completed because it was not approved by the user.`);
357
360
  return;
@@ -59,7 +59,11 @@ class MpcSigner {
59
59
  break;
60
60
  }
61
61
  const signingShare = yield this.signingShare;
62
- const result = yield this.mpc.sign(apiKey, this.mpcHost, signingShare, message.method, JSON.stringify(this.buildParams(method, params)), provider.gatewayUrl, provider.chainId.toString(), this.version);
62
+ const metadata = JSON.stringify({
63
+ clientPlatform: 'REACT_NATIVE',
64
+ mpcServerVersion: this.version,
65
+ });
66
+ const result = yield this.mpc.sign(apiKey, this.mpcHost, signingShare, message.method, JSON.stringify(this.buildParams(method, params)), provider.gatewayUrl, provider.chainId.toString(), metadata);
63
67
  const { data, error } = JSON.parse(String(result));
64
68
  if (error && error.code > 0) {
65
69
  throw new PortalMpcError(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portal-hq/provider",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "license": "MIT",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/esm/index",
@@ -19,8 +19,8 @@
19
19
  "test": "jest"
20
20
  },
21
21
  "dependencies": {
22
- "@portal-hq/connect": "^2.0.1",
23
- "@portal-hq/utils": "^2.0.1"
22
+ "@portal-hq/connect": "^2.0.3",
23
+ "@portal-hq/utils": "^2.0.3"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@babel/preset-typescript": "^7.18.6",
@@ -30,5 +30,5 @@
30
30
  "ts-jest": "^29.0.3",
31
31
  "typescript": "^4.8.4"
32
32
  },
33
- "gitHead": "95132d009b1a7a08d6c05be9323dd21354c4adf0"
33
+ "gitHead": "c333fe5280f16a5c5f70b7ae768f112baf7156ba"
34
34
  }
@@ -252,6 +252,7 @@ class Provider implements IPortalProvider {
252
252
  public async request({
253
253
  method,
254
254
  params,
255
+ chainId,
255
256
  connect,
256
257
  }: RequestArguments): Promise<any> {
257
258
  if (method === 'eth_chainId') {
@@ -281,6 +282,7 @@ class Provider implements IPortalProvider {
281
282
  const transactionHash = await this.handleSigningRequests({
282
283
  method,
283
284
  params,
285
+ chainId,
284
286
  connect,
285
287
  })
286
288
 
@@ -314,7 +316,10 @@ class Provider implements IPortalProvider {
314
316
  * @param chainId The numerical ID of the chain to switch to
315
317
  * @returns BaseProvider
316
318
  */
317
- public async setChainId(chainId: number, connect?: PortalConnect): Promise<Provider> {
319
+ public async setChainId(
320
+ chainId: number,
321
+ connect?: PortalConnect,
322
+ ): Promise<Provider> {
318
323
  // Update the chainId
319
324
  this.chainId = chainId
320
325
 
@@ -328,8 +333,7 @@ class Provider implements IPortalProvider {
328
333
  chainId: this.chainId,
329
334
  } as SwitchEthereumChainParameter)
330
335
 
331
-
332
- if (connect) {
336
+ if (connect && connect.connected) {
333
337
  connect.emit('portalConnect_chainChanged', {
334
338
  chainId: this.chainId,
335
339
  } as SwitchEthereumChainParameter)
@@ -348,6 +352,7 @@ class Provider implements IPortalProvider {
348
352
  protected async getApproval({
349
353
  method,
350
354
  params,
355
+ chainId,
351
356
  connect,
352
357
  }: RequestArguments): Promise<boolean> {
353
358
  // If autoApprove is enabled, just resolve to true
@@ -409,11 +414,13 @@ class Provider implements IPortalProvider {
409
414
  connect.emit('portalConnect_signingRequested', {
410
415
  method,
411
416
  params,
417
+ chainId,
412
418
  })
413
419
  } else {
414
420
  this.emit('portal_signingRequested', {
415
421
  method,
416
422
  params,
423
+ chainId,
417
424
  })
418
425
  }
419
426
  })
@@ -455,11 +462,12 @@ class Provider implements IPortalProvider {
455
462
  private async handleSigningRequests({
456
463
  method,
457
464
  params,
465
+ chainId,
458
466
  connect,
459
467
  }: RequestArguments): Promise<any> {
460
468
  const isApproved = passiveSignerMethods.includes(method)
461
469
  ? true
462
- : await this.getApproval({ method, params, connect })
470
+ : await this.getApproval({ method, params, chainId, connect })
463
471
 
464
472
  if (!isApproved) {
465
473
  this.log.info(
@@ -68,6 +68,11 @@ class MpcSigner implements Signer {
68
68
 
69
69
  const signingShare = await this.signingShare
70
70
 
71
+ const metadata = JSON.stringify({
72
+ clientPlatform: 'REACT_NATIVE',
73
+ mpcServerVersion: this.version,
74
+ })
75
+
71
76
  const result = await this.mpc.sign(
72
77
  apiKey,
73
78
  this.mpcHost,
@@ -76,7 +81,7 @@ class MpcSigner implements Signer {
76
81
  JSON.stringify(this.buildParams(method, params)),
77
82
  provider.gatewayUrl,
78
83
  provider.chainId.toString(),
79
- this.version,
84
+ metadata,
80
85
  )
81
86
 
82
87
  const { data, error } = JSON.parse(String(result)) as SigningResponse
package/types.d.ts CHANGED
@@ -24,18 +24,23 @@ export interface MpcSignerOptions extends SignerOptions {
24
24
  version?: string
25
25
  }
26
26
 
27
+ export interface PortalMobileMpcMetadata {
28
+ clientPlatform: string
29
+ mpcServerVersion: string
30
+ }
31
+
27
32
  export interface PortalMobileMpc {
28
33
  generate: (
29
34
  clientApiKey: string,
30
35
  mpcApiUrl: string,
31
- mpcVersion: string,
36
+ metadata: string,
32
37
  ) => Promise<string>
33
38
  rotate: (
34
39
  clientApiKey: string,
35
40
  mpcApiUrl: string,
36
41
  isSim: boolean,
37
42
  dkgResult?: string,
38
- mpcVersion: string,
43
+ metadata: string,
39
44
  ) => Promise<string>
40
45
  sign: (
41
46
  clientApiKey: string,
@@ -45,7 +50,7 @@ export interface PortalMobileMpc {
45
50
  requestId: string,
46
51
  mpcUrl: string,
47
52
  chainId: string,
48
- mpcVersion: string,
53
+ metadata: string,
49
54
  ) => Promise<string>
50
55
  }
51
56