@portal-hq/provider 4.1.0-beta2 → 4.1.1
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 +11 -11
- package/lib/commonjs/signers/mpc.js +5 -6
- package/lib/esm/providers/index.js +11 -11
- package/lib/esm/signers/mpc.js +6 -7
- package/package.json +4 -4
- package/src/signers/mpc.ts +7 -6
- package/types.d.ts +1 -0
|
@@ -187,8 +187,8 @@ class Provider {
|
|
|
187
187
|
* @param args The arguments of the request being made
|
|
188
188
|
* @returns Promise<any>
|
|
189
189
|
*/
|
|
190
|
-
request(
|
|
191
|
-
return __awaiter(this,
|
|
190
|
+
request(_a) {
|
|
191
|
+
return __awaiter(this, arguments, void 0, function* ({ method, params, chainId, connect, }) {
|
|
192
192
|
chainId = chainId !== null && chainId !== void 0 ? chainId : this.chainId;
|
|
193
193
|
if (!chainId) {
|
|
194
194
|
throw new Error('[PortalProvider] No chainId provided');
|
|
@@ -320,8 +320,8 @@ class Provider {
|
|
|
320
320
|
*
|
|
321
321
|
* @param args The arguments of the request being made
|
|
322
322
|
*/
|
|
323
|
-
getApproval(
|
|
324
|
-
return __awaiter(this,
|
|
323
|
+
getApproval(_a) {
|
|
324
|
+
return __awaiter(this, arguments, void 0, function* ({ method, params, chainId, connect, }) {
|
|
325
325
|
// If autoApprove is enabled, just resolve to true
|
|
326
326
|
if (this.autoApprove) {
|
|
327
327
|
return true;
|
|
@@ -386,8 +386,8 @@ class Provider {
|
|
|
386
386
|
* @param args The arguments of the request being made
|
|
387
387
|
* @returns Promise<any>
|
|
388
388
|
*/
|
|
389
|
-
handleGatewayRequests(
|
|
390
|
-
return __awaiter(this,
|
|
389
|
+
handleGatewayRequests(_a) {
|
|
390
|
+
return __awaiter(this, arguments, void 0, function* ({ method, params, chainId, }) {
|
|
391
391
|
const gatewayUrl = this.getGatewayUrl(chainId);
|
|
392
392
|
// Pass request off to the gateway
|
|
393
393
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
@@ -407,9 +407,9 @@ class Provider {
|
|
|
407
407
|
* @param args The arguments of the request being made
|
|
408
408
|
* @returns Promise<any>
|
|
409
409
|
*/
|
|
410
|
-
handleSigningRequests(
|
|
411
|
-
|
|
412
|
-
|
|
410
|
+
handleSigningRequests(_a) {
|
|
411
|
+
return __awaiter(this, arguments, void 0, function* ({ method, params, chainId, connect, }) {
|
|
412
|
+
var _b, _c;
|
|
413
413
|
const isApproved = passiveSignerMethods.includes(method)
|
|
414
414
|
? true
|
|
415
415
|
: yield this.getApproval({ method, params, chainId, connect });
|
|
@@ -440,7 +440,7 @@ class Provider {
|
|
|
440
440
|
case 'sol_signAndSendTransaction':
|
|
441
441
|
case 'sol_signMessage':
|
|
442
442
|
case 'sol_signTransaction': {
|
|
443
|
-
const result = yield ((
|
|
443
|
+
const result = yield ((_b = this.signer) === null || _b === void 0 ? void 0 : _b.sign({
|
|
444
444
|
chainId: `${namespace}:${reference}`,
|
|
445
445
|
method,
|
|
446
446
|
params,
|
|
@@ -450,7 +450,7 @@ class Provider {
|
|
|
450
450
|
return result;
|
|
451
451
|
}
|
|
452
452
|
case 'raw_sign': {
|
|
453
|
-
const result = yield ((
|
|
453
|
+
const result = yield ((_c = this.signer) === null || _c === void 0 ? void 0 : _c.sign({
|
|
454
454
|
chainId: '',
|
|
455
455
|
method: '',
|
|
456
456
|
params,
|
|
@@ -39,27 +39,25 @@ class MpcSigner {
|
|
|
39
39
|
}
|
|
40
40
|
return params;
|
|
41
41
|
};
|
|
42
|
+
this.featureFlags = featureFlags;
|
|
42
43
|
this.keychain = keychain;
|
|
43
44
|
this.mpc = react_native_1.NativeModules.PortalMobileMpc;
|
|
44
45
|
this.mpcHost = mpcHost;
|
|
45
46
|
this.version = version;
|
|
46
|
-
this.featureFlags = featureFlags;
|
|
47
47
|
if (!this.mpc) {
|
|
48
48
|
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.`);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
sign(message, provider) {
|
|
52
|
-
var _a, _b;
|
|
53
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
const
|
|
55
|
-
const legacyAddress = yield this.keychain.getAddress();
|
|
53
|
+
const eip155Address = yield this.keychain.getEip155Address();
|
|
56
54
|
const apiKey = provider.apiKey;
|
|
57
55
|
const { method, chainId, curve, isRaw } = message;
|
|
58
56
|
switch (method) {
|
|
59
57
|
case 'eth_requestAccounts':
|
|
60
|
-
return [
|
|
58
|
+
return [eip155Address];
|
|
61
59
|
case 'eth_accounts':
|
|
62
|
-
return [
|
|
60
|
+
return [eip155Address];
|
|
63
61
|
default:
|
|
64
62
|
break;
|
|
65
63
|
}
|
|
@@ -73,6 +71,7 @@ class MpcSigner {
|
|
|
73
71
|
}
|
|
74
72
|
const metadata = {
|
|
75
73
|
clientPlatform: 'REACT_NATIVE',
|
|
74
|
+
clientPlatformVersion: (0, utils_1.getClientPlatformVersion)(),
|
|
76
75
|
isMultiBackupEnabled: this.featureFlags.isMultiBackupEnabled,
|
|
77
76
|
mpcServerVersion: this.version,
|
|
78
77
|
optimized: true,
|
|
@@ -185,8 +185,8 @@ class Provider {
|
|
|
185
185
|
* @param args The arguments of the request being made
|
|
186
186
|
* @returns Promise<any>
|
|
187
187
|
*/
|
|
188
|
-
request(
|
|
189
|
-
return __awaiter(this,
|
|
188
|
+
request(_a) {
|
|
189
|
+
return __awaiter(this, arguments, void 0, function* ({ method, params, chainId, connect, }) {
|
|
190
190
|
chainId = chainId !== null && chainId !== void 0 ? chainId : this.chainId;
|
|
191
191
|
if (!chainId) {
|
|
192
192
|
throw new Error('[PortalProvider] No chainId provided');
|
|
@@ -318,8 +318,8 @@ class Provider {
|
|
|
318
318
|
*
|
|
319
319
|
* @param args The arguments of the request being made
|
|
320
320
|
*/
|
|
321
|
-
getApproval(
|
|
322
|
-
return __awaiter(this,
|
|
321
|
+
getApproval(_a) {
|
|
322
|
+
return __awaiter(this, arguments, void 0, function* ({ method, params, chainId, connect, }) {
|
|
323
323
|
// If autoApprove is enabled, just resolve to true
|
|
324
324
|
if (this.autoApprove) {
|
|
325
325
|
return true;
|
|
@@ -384,8 +384,8 @@ class Provider {
|
|
|
384
384
|
* @param args The arguments of the request being made
|
|
385
385
|
* @returns Promise<any>
|
|
386
386
|
*/
|
|
387
|
-
handleGatewayRequests(
|
|
388
|
-
return __awaiter(this,
|
|
387
|
+
handleGatewayRequests(_a) {
|
|
388
|
+
return __awaiter(this, arguments, void 0, function* ({ method, params, chainId, }) {
|
|
389
389
|
const gatewayUrl = this.getGatewayUrl(chainId);
|
|
390
390
|
// Pass request off to the gateway
|
|
391
391
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
@@ -405,9 +405,9 @@ class Provider {
|
|
|
405
405
|
* @param args The arguments of the request being made
|
|
406
406
|
* @returns Promise<any>
|
|
407
407
|
*/
|
|
408
|
-
handleSigningRequests(
|
|
409
|
-
|
|
410
|
-
|
|
408
|
+
handleSigningRequests(_a) {
|
|
409
|
+
return __awaiter(this, arguments, void 0, function* ({ method, params, chainId, connect, }) {
|
|
410
|
+
var _b, _c;
|
|
411
411
|
const isApproved = passiveSignerMethods.includes(method)
|
|
412
412
|
? true
|
|
413
413
|
: yield this.getApproval({ method, params, chainId, connect });
|
|
@@ -438,7 +438,7 @@ class Provider {
|
|
|
438
438
|
case 'sol_signAndSendTransaction':
|
|
439
439
|
case 'sol_signMessage':
|
|
440
440
|
case 'sol_signTransaction': {
|
|
441
|
-
const result = yield ((
|
|
441
|
+
const result = yield ((_b = this.signer) === null || _b === void 0 ? void 0 : _b.sign({
|
|
442
442
|
chainId: `${namespace}:${reference}`,
|
|
443
443
|
method,
|
|
444
444
|
params,
|
|
@@ -448,7 +448,7 @@ class Provider {
|
|
|
448
448
|
return result;
|
|
449
449
|
}
|
|
450
450
|
case 'raw_sign': {
|
|
451
|
-
const result = yield ((
|
|
451
|
+
const result = yield ((_c = this.signer) === null || _c === void 0 ? void 0 : _c.sign({
|
|
452
452
|
chainId: '',
|
|
453
453
|
method: '',
|
|
454
454
|
params,
|
package/lib/esm/signers/mpc.js
CHANGED
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { PortalCurve } from '@portal-hq/core';
|
|
11
|
-
import { PortalMpcError, } from '@portal-hq/utils';
|
|
11
|
+
import { PortalMpcError, getClientPlatformVersion, } from '@portal-hq/utils';
|
|
12
12
|
import { NativeModules } from 'react-native';
|
|
13
13
|
class MpcSigner {
|
|
14
14
|
constructor({ keychain, mpcHost = 'mpc.portalhq.io', version = 'v6', featureFlags = {}, }) {
|
|
@@ -37,27 +37,25 @@ class MpcSigner {
|
|
|
37
37
|
}
|
|
38
38
|
return params;
|
|
39
39
|
};
|
|
40
|
+
this.featureFlags = featureFlags;
|
|
40
41
|
this.keychain = keychain;
|
|
41
42
|
this.mpc = NativeModules.PortalMobileMpc;
|
|
42
43
|
this.mpcHost = mpcHost;
|
|
43
44
|
this.version = version;
|
|
44
|
-
this.featureFlags = featureFlags;
|
|
45
45
|
if (!this.mpc) {
|
|
46
46
|
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.`);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
sign(message, provider) {
|
|
50
|
-
var _a, _b;
|
|
51
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
const
|
|
53
|
-
const legacyAddress = yield this.keychain.getAddress();
|
|
51
|
+
const eip155Address = yield this.keychain.getEip155Address();
|
|
54
52
|
const apiKey = provider.apiKey;
|
|
55
53
|
const { method, chainId, curve, isRaw } = message;
|
|
56
54
|
switch (method) {
|
|
57
55
|
case 'eth_requestAccounts':
|
|
58
|
-
return [
|
|
56
|
+
return [eip155Address];
|
|
59
57
|
case 'eth_accounts':
|
|
60
|
-
return [
|
|
58
|
+
return [eip155Address];
|
|
61
59
|
default:
|
|
62
60
|
break;
|
|
63
61
|
}
|
|
@@ -71,6 +69,7 @@ class MpcSigner {
|
|
|
71
69
|
}
|
|
72
70
|
const metadata = {
|
|
73
71
|
clientPlatform: 'REACT_NATIVE',
|
|
72
|
+
clientPlatformVersion: getClientPlatformVersion(),
|
|
74
73
|
isMultiBackupEnabled: this.featureFlags.isMultiBackupEnabled,
|
|
75
74
|
mpcServerVersion: this.version,
|
|
76
75
|
optimized: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portal-hq/provider",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.1",
|
|
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": "^4.1.
|
|
23
|
-
"@portal-hq/utils": "^4.1.
|
|
22
|
+
"@portal-hq/connect": "^4.1.1",
|
|
23
|
+
"@portal-hq/utils": "^4.1.1"
|
|
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": "
|
|
33
|
+
"gitHead": "3c03bd4a6573b23865f655856cd0161706f3f30d"
|
|
34
34
|
}
|
package/src/signers/mpc.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
KeychainAdapter,
|
|
6
6
|
PortalMpcError,
|
|
7
7
|
type SigningRequestArguments,
|
|
8
|
+
getClientPlatformVersion,
|
|
8
9
|
} from '@portal-hq/utils'
|
|
9
10
|
import { NativeModules } from 'react-native'
|
|
10
11
|
|
|
@@ -17,11 +18,11 @@ import {
|
|
|
17
18
|
import Signer from './abstract'
|
|
18
19
|
|
|
19
20
|
class MpcSigner implements Signer {
|
|
21
|
+
private featureFlags: FeatureFlags
|
|
20
22
|
private keychain: KeychainAdapter
|
|
21
23
|
private mpc: PortalMobileMpc
|
|
22
24
|
private mpcHost: string // should we add a default here mpc.portalhq.io
|
|
23
25
|
private version = 'v6'
|
|
24
|
-
private featureFlags: FeatureFlags
|
|
25
26
|
|
|
26
27
|
constructor({
|
|
27
28
|
keychain,
|
|
@@ -29,11 +30,11 @@ class MpcSigner implements Signer {
|
|
|
29
30
|
version = 'v6',
|
|
30
31
|
featureFlags = {},
|
|
31
32
|
}: MpcSignerOptions) {
|
|
33
|
+
this.featureFlags = featureFlags
|
|
32
34
|
this.keychain = keychain
|
|
33
35
|
this.mpc = NativeModules.PortalMobileMpc
|
|
34
36
|
this.mpcHost = mpcHost
|
|
35
37
|
this.version = version
|
|
36
|
-
this.featureFlags = featureFlags
|
|
37
38
|
|
|
38
39
|
if (!this.mpc) {
|
|
39
40
|
throw new Error(
|
|
@@ -46,8 +47,7 @@ class MpcSigner implements Signer {
|
|
|
46
47
|
message: SigningRequestArguments,
|
|
47
48
|
provider: IPortalProvider,
|
|
48
49
|
): Promise<any> {
|
|
49
|
-
const
|
|
50
|
-
const legacyAddress = await this.keychain.getAddress()
|
|
50
|
+
const eip155Address = await this.keychain.getEip155Address()
|
|
51
51
|
|
|
52
52
|
const apiKey = provider.apiKey
|
|
53
53
|
|
|
@@ -55,9 +55,9 @@ class MpcSigner implements Signer {
|
|
|
55
55
|
|
|
56
56
|
switch (method) {
|
|
57
57
|
case 'eth_requestAccounts':
|
|
58
|
-
return [
|
|
58
|
+
return [eip155Address]
|
|
59
59
|
case 'eth_accounts':
|
|
60
|
-
return [
|
|
60
|
+
return [eip155Address]
|
|
61
61
|
default:
|
|
62
62
|
break
|
|
63
63
|
}
|
|
@@ -77,6 +77,7 @@ class MpcSigner implements Signer {
|
|
|
77
77
|
|
|
78
78
|
const metadata: PortalMobileMpcMetadata = {
|
|
79
79
|
clientPlatform: 'REACT_NATIVE',
|
|
80
|
+
clientPlatformVersion: getClientPlatformVersion(),
|
|
80
81
|
isMultiBackupEnabled: this.featureFlags.isMultiBackupEnabled,
|
|
81
82
|
mpcServerVersion: this.version,
|
|
82
83
|
optimized: true,
|