@portal-hq/provider 0.3.3 → 0.3.5
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/providers/index.js +22 -2
- package/lib/commonjs/signers/mpc.js +4 -4
- package/lib/esm/providers/index.js +23 -3
- package/lib/esm/signers/mpc.js +5 -5
- package/package.json +2 -2
- package/src/providers/index.ts +24 -2
- package/src/signers/mpc.ts +6 -6
- package/types.d.ts +10 -6
|
@@ -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', mpcVersion = '
|
|
34
|
+
apiUrl = 'api.portalhq.io', autoApprove = false, mpcUrl = 'mpc.portalhq.io', mpcVersion = 'v2', gatewayConfig = {}, }) {
|
|
35
35
|
// Handle required fields
|
|
36
36
|
if (!apiKey || apiKey.length === 0) {
|
|
37
37
|
throw new utils_1.InvalidApiKeyError();
|
|
@@ -364,7 +364,27 @@ class Provider {
|
|
|
364
364
|
case 'eth_signTransaction':
|
|
365
365
|
case 'eth_signTypedData':
|
|
366
366
|
case 'personal_sign':
|
|
367
|
-
|
|
367
|
+
const result = yield ((_a = this.signer) === null || _a === void 0 ? void 0 : _a.sign({ chainId: this.chainId, method, params }, this));
|
|
368
|
+
if (result) {
|
|
369
|
+
try {
|
|
370
|
+
yield this.portal.post('/api/v1/analytics/track', {
|
|
371
|
+
headers: {
|
|
372
|
+
Authentication: `Bearer ${this.apiKey}`,
|
|
373
|
+
},
|
|
374
|
+
body: {
|
|
375
|
+
event: utils_1.Events.TransactionSigned,
|
|
376
|
+
properties: {
|
|
377
|
+
method,
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
// Do nothing, because we don't want metrics gathering
|
|
384
|
+
// to block the SDK
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return result;
|
|
368
388
|
default:
|
|
369
389
|
throw new Error('[PortalProvider] Method "' + method + '" not supported');
|
|
370
390
|
}
|
|
@@ -12,8 +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({ keychain, mpcUrl, mpcVersion = '
|
|
16
|
-
this.mpcVersion = '
|
|
15
|
+
constructor({ keychain, mpcUrl, mpcVersion = 'v2' }) {
|
|
16
|
+
this.mpcVersion = 'v2';
|
|
17
17
|
this.buildParams = (method, txParams) => {
|
|
18
18
|
let params = txParams;
|
|
19
19
|
switch (method) {
|
|
@@ -66,8 +66,8 @@ class MpcSigner {
|
|
|
66
66
|
const dkg = yield this.keychain.getDkgResult();
|
|
67
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);
|
|
68
68
|
const { data, error } = JSON.parse(String(result));
|
|
69
|
-
if (error && error.
|
|
70
|
-
throw new utils_1.
|
|
69
|
+
if (error && error.code > 0) {
|
|
70
|
+
throw new utils_1.PortalMpcError(error);
|
|
71
71
|
}
|
|
72
72
|
return data;
|
|
73
73
|
});
|
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { HttpRequester, InvalidApiKeyError, InvalidChainIdError, InvalidGatewayConfigError, ProviderRpcError, RpcErrorCodes, } from '@portal-hq/utils';
|
|
10
|
+
import { Events, HttpRequester, InvalidApiKeyError, InvalidChainIdError, InvalidGatewayConfigError, ProviderRpcError, RpcErrorCodes, } from '@portal-hq/utils';
|
|
11
11
|
import { MpcSigner } from '../signers';
|
|
12
12
|
const passiveSignerMethods = [
|
|
13
13
|
'eth_accounts',
|
|
@@ -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', mpcVersion = '
|
|
32
|
+
apiUrl = 'api.portalhq.io', autoApprove = false, mpcUrl = 'mpc.portalhq.io', mpcVersion = 'v2', gatewayConfig = {}, }) {
|
|
33
33
|
// Handle required fields
|
|
34
34
|
if (!apiKey || apiKey.length === 0) {
|
|
35
35
|
throw new InvalidApiKeyError();
|
|
@@ -362,7 +362,27 @@ class Provider {
|
|
|
362
362
|
case 'eth_signTransaction':
|
|
363
363
|
case 'eth_signTypedData':
|
|
364
364
|
case 'personal_sign':
|
|
365
|
-
|
|
365
|
+
const result = yield ((_a = this.signer) === null || _a === void 0 ? void 0 : _a.sign({ chainId: this.chainId, method, params }, this));
|
|
366
|
+
if (result) {
|
|
367
|
+
try {
|
|
368
|
+
yield this.portal.post('/api/v1/analytics/track', {
|
|
369
|
+
headers: {
|
|
370
|
+
Authentication: `Bearer ${this.apiKey}`,
|
|
371
|
+
},
|
|
372
|
+
body: {
|
|
373
|
+
event: Events.TransactionSigned,
|
|
374
|
+
properties: {
|
|
375
|
+
method,
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
// Do nothing, because we don't want metrics gathering
|
|
382
|
+
// to block the SDK
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return result;
|
|
366
386
|
default:
|
|
367
387
|
throw new Error('[PortalProvider] Method "' + method + '" not supported');
|
|
368
388
|
}
|
package/lib/esm/signers/mpc.js
CHANGED
|
@@ -8,10 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { NativeModules } from 'react-native';
|
|
11
|
-
import {
|
|
11
|
+
import { PortalMpcError, } from '@portal-hq/utils';
|
|
12
12
|
class MpcSigner {
|
|
13
|
-
constructor({ keychain, mpcUrl, mpcVersion = '
|
|
14
|
-
this.mpcVersion = '
|
|
13
|
+
constructor({ keychain, mpcUrl, mpcVersion = 'v2' }) {
|
|
14
|
+
this.mpcVersion = 'v2';
|
|
15
15
|
this.buildParams = (method, txParams) => {
|
|
16
16
|
let params = txParams;
|
|
17
17
|
switch (method) {
|
|
@@ -64,8 +64,8 @@ class MpcSigner {
|
|
|
64
64
|
const dkg = yield this.keychain.getDkgResult();
|
|
65
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);
|
|
66
66
|
const { data, error } = JSON.parse(String(result));
|
|
67
|
-
if (error && error.
|
|
68
|
-
throw new
|
|
67
|
+
if (error && error.code > 0) {
|
|
68
|
+
throw new PortalMpcError(error);
|
|
69
69
|
}
|
|
70
70
|
return data;
|
|
71
71
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portal-hq/provider",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
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.3.
|
|
22
|
+
"@portal-hq/utils": "^0.3.4"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@babel/preset-typescript": "^7.18.6",
|
package/src/providers/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Events,
|
|
2
3
|
HttpRequester,
|
|
3
4
|
InvalidApiKeyError,
|
|
4
5
|
InvalidChainIdError,
|
|
@@ -65,7 +66,7 @@ class Provider {
|
|
|
65
66
|
apiUrl = 'api.portalhq.io',
|
|
66
67
|
autoApprove = false,
|
|
67
68
|
mpcUrl = 'mpc.portalhq.io',
|
|
68
|
-
mpcVersion = '
|
|
69
|
+
mpcVersion = 'v2',
|
|
69
70
|
gatewayConfig = {},
|
|
70
71
|
}: ProviderOptions) {
|
|
71
72
|
// Handle required fields
|
|
@@ -471,10 +472,31 @@ class Provider {
|
|
|
471
472
|
case 'eth_signTransaction':
|
|
472
473
|
case 'eth_signTypedData':
|
|
473
474
|
case 'personal_sign':
|
|
474
|
-
|
|
475
|
+
const result = await this.signer?.sign(
|
|
475
476
|
{ chainId: this.chainId, method, params },
|
|
476
477
|
this,
|
|
477
478
|
)
|
|
479
|
+
|
|
480
|
+
if (result) {
|
|
481
|
+
try {
|
|
482
|
+
await this.portal.post('/api/v1/analytics/track', {
|
|
483
|
+
headers: {
|
|
484
|
+
Authentication: `Bearer ${this.apiKey}`,
|
|
485
|
+
},
|
|
486
|
+
body: {
|
|
487
|
+
event: Events.TransactionSigned,
|
|
488
|
+
properties: {
|
|
489
|
+
method,
|
|
490
|
+
},
|
|
491
|
+
},
|
|
492
|
+
})
|
|
493
|
+
} catch (error) {
|
|
494
|
+
// Do nothing, because we don't want metrics gathering
|
|
495
|
+
// to block the SDK
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
return result
|
|
478
500
|
default:
|
|
479
501
|
throw new Error(
|
|
480
502
|
'[PortalProvider] Method "' + method + '" not supported',
|
package/src/signers/mpc.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NativeModules } from 'react-native'
|
|
2
2
|
import {
|
|
3
3
|
KeychainAdapter,
|
|
4
|
-
|
|
4
|
+
PortalMpcError,
|
|
5
5
|
type SigningRequestArguments,
|
|
6
6
|
} from '@portal-hq/utils'
|
|
7
7
|
|
|
@@ -20,9 +20,9 @@ class MpcSigner implements Signer {
|
|
|
20
20
|
public address?: string
|
|
21
21
|
public keychain: KeychainAdapter
|
|
22
22
|
public mpcUrl: string // should we add a default here mpc.portalhq.io
|
|
23
|
-
public mpcVersion: string = '
|
|
23
|
+
public mpcVersion: string = 'v2'
|
|
24
24
|
|
|
25
|
-
constructor({ keychain, mpcUrl, mpcVersion = '
|
|
25
|
+
constructor({ keychain, mpcUrl, mpcVersion = 'v2' }: MpcSignerOptions) {
|
|
26
26
|
this.keychain = keychain
|
|
27
27
|
this.mpc = NativeModules.PortalMobileMpc
|
|
28
28
|
this.mpcUrl = mpcUrl
|
|
@@ -77,13 +77,13 @@ class MpcSigner implements Signer {
|
|
|
77
77
|
JSON.stringify(this.buildParams(method, params)),
|
|
78
78
|
provider.rpcUrl,
|
|
79
79
|
provider.chainId.toString(),
|
|
80
|
-
this.mpcVersion
|
|
80
|
+
this.mpcVersion,
|
|
81
81
|
)
|
|
82
82
|
|
|
83
83
|
const { data, error } = JSON.parse(String(result)) as SigningResponse
|
|
84
84
|
|
|
85
|
-
if (error && error.
|
|
86
|
-
throw new
|
|
85
|
+
if (error && error.code > 0) {
|
|
86
|
+
throw new PortalMpcError(error)
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
return data
|
package/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Types
|
|
2
2
|
|
|
3
|
-
import { KeychainAdapter } from '@portal-hq/utils'
|
|
3
|
+
import { KeychainAdapter, type PortalError } from '@portal-hq/utils'
|
|
4
4
|
|
|
5
5
|
export type EventHandler = (data: any) => void
|
|
6
6
|
|
|
@@ -21,13 +21,17 @@ export interface MpcSignerOptions extends SignerOptions {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface PortalMobileMpc {
|
|
24
|
-
generate: (
|
|
24
|
+
generate: (
|
|
25
|
+
clientApiKey: string,
|
|
26
|
+
mpcApiUrl: string,
|
|
27
|
+
mpcVersion: string,
|
|
28
|
+
) => Promise<string>
|
|
25
29
|
rotate: (
|
|
26
30
|
clientApiKey: string,
|
|
27
31
|
mpcApiUrl: string,
|
|
28
32
|
isSim: boolean,
|
|
29
33
|
dkgResult?: string,
|
|
30
|
-
mpcVersion: string
|
|
34
|
+
mpcVersion: string,
|
|
31
35
|
) => Promise<string>
|
|
32
36
|
sign: (
|
|
33
37
|
clientApiKey: string,
|
|
@@ -37,7 +41,7 @@ export interface PortalMobileMpc {
|
|
|
37
41
|
requestId: string,
|
|
38
42
|
mpcUrl: string,
|
|
39
43
|
chainId: string,
|
|
40
|
-
mpcVersion: string
|
|
44
|
+
mpcVersion: string,
|
|
41
45
|
) => Promise<string>
|
|
42
46
|
}
|
|
43
47
|
|
|
@@ -71,7 +75,7 @@ export interface SignResult {
|
|
|
71
75
|
S: string
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
export interface SignerOptions {
|
|
78
|
+
export interface SignerOptions {}
|
|
75
79
|
|
|
76
80
|
export interface Eip1559 {
|
|
77
81
|
gasLimit?: string
|
|
@@ -90,7 +94,7 @@ export type SigningRequestParams = Eip1559 | LegacyTx
|
|
|
90
94
|
|
|
91
95
|
export interface SigningResponse {
|
|
92
96
|
data: string
|
|
93
|
-
error
|
|
97
|
+
error: PortalError
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
export interface SwitchEthereumChainParameter {
|