@portal-hq/provider 0.2.33 → 0.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.
@@ -31,7 +31,7 @@ class Provider {
31
31
  // Required options
32
32
  apiKey, chainId, keychain,
33
33
  // Optional options
34
- apiUrl = 'api.portalhq.io', autoApprove = false, mpcUrl = 'mpc.portalhq.io', gatewayConfig = {}, }) {
34
+ apiUrl = 'api.portalhq.io', autoApprove = false, mpcUrl = 'mpc.portalhq.io', mpcVersion = 'v1', gatewayConfig = {}, }) {
35
35
  // Handle required fields
36
36
  if (!apiKey || apiKey.length === 0) {
37
37
  throw new utils_1.InvalidApiKeyError();
@@ -54,6 +54,7 @@ class Provider {
54
54
  this.keychain = keychain;
55
55
  this.mpcUrl = mpcUrl;
56
56
  this.rpcUrl = this.getRpcUrl();
57
+ this.mpcVersion = mpcVersion;
57
58
  // Add a logger
58
59
  this.log = console;
59
60
  // Initialize Portal API HttpRequester
@@ -12,7 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const react_native_1 = require("react-native");
13
13
  const utils_1 = require("@portal-hq/utils");
14
14
  class MpcSigner {
15
- constructor(opts) {
15
+ constructor({ keychain, mpcUrl, mpcVersion = 'v1' }) {
16
+ this.mpcVersion = 'v1';
16
17
  this.buildParams = (method, txParams) => {
17
18
  let params = txParams;
18
19
  switch (method) {
@@ -29,9 +30,10 @@ class MpcSigner {
29
30
  }
30
31
  return params;
31
32
  };
32
- this.keychain = opts.keychain;
33
+ this.keychain = keychain;
33
34
  this.mpc = react_native_1.NativeModules.PortalMobileMpc;
34
- this.mpcUrl = opts.mpcUrl;
35
+ this.mpcUrl = mpcUrl;
36
+ this.mpcVersion = mpcVersion;
35
37
  if (!this.mpc) {
36
38
  throw new Error(`[Portal.Provider.MpcSigner] The MPC module could not be found by the signer. This is usually an issue with React Native linking. Please verify that the 'PortalReactNative' module is properly linked to this project.`);
37
39
  }
@@ -62,7 +64,7 @@ class MpcSigner {
62
64
  break;
63
65
  }
64
66
  const dkg = yield this.keychain.getDkgResult();
65
- const result = yield this.mpc.sign(apiKey, this.mpcUrl, dkg, message.method, JSON.stringify(this.buildParams(method, params)), provider.rpcUrl, provider.chainId.toString());
67
+ const result = yield this.mpc.sign(apiKey, this.mpcUrl, dkg, message.method, JSON.stringify(this.buildParams(method, params)), provider.rpcUrl, provider.chainId.toString(), this.mpcVersion);
66
68
  const { data, error } = JSON.parse(String(result));
67
69
  if (error && error.length) {
68
70
  throw new utils_1.MpcSigningError(error);
@@ -29,7 +29,7 @@ class Provider {
29
29
  // Required options
30
30
  apiKey, chainId, keychain,
31
31
  // Optional options
32
- apiUrl = 'api.portalhq.io', autoApprove = false, mpcUrl = 'mpc.portalhq.io', gatewayConfig = {}, }) {
32
+ apiUrl = 'api.portalhq.io', autoApprove = false, mpcUrl = 'mpc.portalhq.io', mpcVersion = 'v1', gatewayConfig = {}, }) {
33
33
  // Handle required fields
34
34
  if (!apiKey || apiKey.length === 0) {
35
35
  throw new InvalidApiKeyError();
@@ -52,6 +52,7 @@ class Provider {
52
52
  this.keychain = keychain;
53
53
  this.mpcUrl = mpcUrl;
54
54
  this.rpcUrl = this.getRpcUrl();
55
+ this.mpcVersion = mpcVersion;
55
56
  // Add a logger
56
57
  this.log = console;
57
58
  // Initialize Portal API HttpRequester
@@ -10,7 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { NativeModules } from 'react-native';
11
11
  import { MpcSigningError, } from '@portal-hq/utils';
12
12
  class MpcSigner {
13
- constructor(opts) {
13
+ constructor({ keychain, mpcUrl, mpcVersion = 'v1' }) {
14
+ this.mpcVersion = 'v1';
14
15
  this.buildParams = (method, txParams) => {
15
16
  let params = txParams;
16
17
  switch (method) {
@@ -27,9 +28,10 @@ class MpcSigner {
27
28
  }
28
29
  return params;
29
30
  };
30
- this.keychain = opts.keychain;
31
+ this.keychain = keychain;
31
32
  this.mpc = NativeModules.PortalMobileMpc;
32
- this.mpcUrl = opts.mpcUrl;
33
+ this.mpcUrl = mpcUrl;
34
+ this.mpcVersion = mpcVersion;
33
35
  if (!this.mpc) {
34
36
  throw new Error(`[Portal.Provider.MpcSigner] The MPC module could not be found by the signer. This is usually an issue with React Native linking. Please verify that the 'PortalReactNative' module is properly linked to this project.`);
35
37
  }
@@ -60,7 +62,7 @@ class MpcSigner {
60
62
  break;
61
63
  }
62
64
  const dkg = yield this.keychain.getDkgResult();
63
- const result = yield this.mpc.sign(apiKey, this.mpcUrl, dkg, message.method, JSON.stringify(this.buildParams(method, params)), provider.rpcUrl, provider.chainId.toString());
65
+ const result = yield this.mpc.sign(apiKey, this.mpcUrl, dkg, message.method, JSON.stringify(this.buildParams(method, params)), provider.rpcUrl, provider.chainId.toString(), this.mpcVersion);
64
66
  const { data, error } = JSON.parse(String(result));
65
67
  if (error && error.length) {
66
68
  throw new MpcSigningError(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portal-hq/provider",
3
- "version": "0.2.33",
3
+ "version": "0.3.0",
4
4
  "license": "MIT",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/esm/index",
@@ -19,7 +19,7 @@
19
19
  "test": "jest"
20
20
  },
21
21
  "dependencies": {
22
- "@portal-hq/utils": "^0.2.33"
22
+ "@portal-hq/utils": "^0.3.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@babel/preset-typescript": "^7.18.6",
@@ -53,6 +53,7 @@ class Provider {
53
53
  public rpc: HttpRequester
54
54
  public rpcUrl: string
55
55
  public signer: Signer
56
+ public mpcVersion: string
56
57
 
57
58
  constructor({
58
59
  // Required options
@@ -64,6 +65,7 @@ class Provider {
64
65
  apiUrl = 'api.portalhq.io',
65
66
  autoApprove = false,
66
67
  mpcUrl = 'mpc.portalhq.io',
68
+ mpcVersion = 'v1',
67
69
  gatewayConfig = {},
68
70
  }: ProviderOptions) {
69
71
  // Handle required fields
@@ -89,7 +91,7 @@ class Provider {
89
91
  this.keychain = keychain
90
92
  this.mpcUrl = mpcUrl
91
93
  this.rpcUrl = this.getRpcUrl()
92
-
94
+ this.mpcVersion = mpcVersion
93
95
  // Add a logger
94
96
  this.log = console
95
97
 
@@ -19,12 +19,14 @@ class MpcSigner implements Signer {
19
19
 
20
20
  public address?: string
21
21
  public keychain: KeychainAdapter
22
- public mpcUrl: string
22
+ public mpcUrl: string // should we add a default here mpc.portalhq.io
23
+ public mpcVersion: string = 'v1'
23
24
 
24
- constructor(opts: MpcSignerOptions) {
25
- this.keychain = opts.keychain
25
+ constructor({ keychain, mpcUrl, mpcVersion = 'v1' }: MpcSignerOptions) {
26
+ this.keychain = keychain
26
27
  this.mpc = NativeModules.PortalMobileMpc
27
- this.mpcUrl = opts.mpcUrl
28
+ this.mpcUrl = mpcUrl
29
+ this.mpcVersion = mpcVersion
28
30
 
29
31
  if (!this.mpc) {
30
32
  throw new Error(
@@ -75,6 +77,7 @@ class MpcSigner implements Signer {
75
77
  JSON.stringify(this.buildParams(method, params)),
76
78
  provider.rpcUrl,
77
79
  provider.chainId.toString(),
80
+ this.mpcVersion
78
81
  )
79
82
 
80
83
  const { data, error } = JSON.parse(String(result)) as SigningResponse
package/types.d.ts CHANGED
@@ -17,15 +17,17 @@ export interface GatewayConfig {
17
17
  export interface MpcSignerOptions extends SignerOptions {
18
18
  keychain: KeychainAdapter
19
19
  mpcUrl: string
20
+ mpcVersion?: string
20
21
  }
21
22
 
22
23
  export interface PortalMobileMpc {
23
- generate: (clientApiKey: string, mpcApiUrl: string) => Promise<string>
24
+ generate: (clientApiKey: string, mpcApiUrl: string, mpcVersion: string) => Promise<string>
24
25
  rotate: (
25
26
  clientApiKey: string,
26
27
  mpcApiUrl: string,
27
28
  isSim: boolean,
28
29
  dkgResult?: string,
30
+ mpcVersion: string
29
31
  ) => Promise<string>
30
32
  sign: (
31
33
  clientApiKey: string,
@@ -35,6 +37,7 @@ export interface PortalMobileMpc {
35
37
  requestId: string,
36
38
  mpcUrl: string,
37
39
  chainId: string,
40
+ mpcVersion: string
38
41
  ) => Promise<string>
39
42
  }
40
43
 
@@ -50,6 +53,7 @@ export interface ProviderOptions {
50
53
  autoApprove?: boolean
51
54
  enableMpc?: boolean
52
55
  mpcUrl?: string
56
+ mpcVersion?: string
53
57
  }
54
58
 
55
59
  export interface RegisteredEventHandler {