@portal-hq/provider 0.2.7 → 0.2.9
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/package.json +2 -2
- package/src/providers/index.ts +2 -9
- package/src/requesters/http.ts +2 -2
- package/src/signers/abstract.ts +3 -5
- package/src/signers/http.ts +8 -10
- package/src/signers/mpc.ts +6 -3
- package/types.d.ts +1 -7
- package/lib/commonjs/index.js +0 -8
- package/lib/commonjs/providers/index.js +0 -383
- package/lib/commonjs/requesters/http.js +0 -52
- package/lib/commonjs/requesters/index.js +0 -8
- package/lib/commonjs/signers/abstract.js +0 -19
- package/lib/commonjs/signers/http.js +0 -58
- package/lib/commonjs/signers/index.js +0 -12
- package/lib/commonjs/signers/mpc.js +0 -75
- package/lib/esm/index.js +0 -1
- package/lib/esm/providers/index.js +0 -381
- package/lib/esm/requesters/http.js +0 -50
- package/lib/esm/requesters/index.js +0 -1
- package/lib/esm/signers/abstract.js +0 -17
- package/lib/esm/signers/http.js +0 -56
- package/lib/esm/signers/index.js +0 -3
- package/lib/esm/signers/mpc.js +0 -73
package/lib/esm/signers/mpc.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { NativeModules } from 'react-native';
|
|
11
|
-
import { MpcSigningError } from '@portal-hq/utils';
|
|
12
|
-
class MpcSigner {
|
|
13
|
-
constructor(opts) {
|
|
14
|
-
this.buildParams = (method, txParams) => {
|
|
15
|
-
let params = txParams;
|
|
16
|
-
switch (method) {
|
|
17
|
-
case 'eth_sign':
|
|
18
|
-
case 'personal_sign':
|
|
19
|
-
if (!Array.isArray(txParams)) {
|
|
20
|
-
params = [txParams];
|
|
21
|
-
}
|
|
22
|
-
break;
|
|
23
|
-
default:
|
|
24
|
-
if (Array.isArray(txParams)) {
|
|
25
|
-
params = txParams[0];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return params;
|
|
29
|
-
};
|
|
30
|
-
this.keychain = opts.keychain;
|
|
31
|
-
this.mpc = NativeModules.PortalMobileMpc;
|
|
32
|
-
this.mpcUrl = opts.mpcUrl;
|
|
33
|
-
if (!this.mpc) {
|
|
34
|
-
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
|
-
}
|
|
36
|
-
}
|
|
37
|
-
get address() {
|
|
38
|
-
return (() => __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
if (this._address) {
|
|
40
|
-
return this._address;
|
|
41
|
-
}
|
|
42
|
-
const address = yield this.keychain.getAddress();
|
|
43
|
-
this._address = address;
|
|
44
|
-
return address;
|
|
45
|
-
}))();
|
|
46
|
-
}
|
|
47
|
-
sign(message, provider) {
|
|
48
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
const address = yield this.keychain.getAddress();
|
|
50
|
-
const apiKey = provider.apiKey;
|
|
51
|
-
const { method, params } = message;
|
|
52
|
-
switch (method) {
|
|
53
|
-
case 'eth_requestAccounts':
|
|
54
|
-
return [address];
|
|
55
|
-
case 'eth_accounts':
|
|
56
|
-
return [address];
|
|
57
|
-
default:
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
console.log(`[Portal:MpcSigner] Requesting signature from PortalMobileMpc for:`, JSON.stringify(message, null, 2));
|
|
61
|
-
const dkg = yield this.keychain.getDkgResult();
|
|
62
|
-
console.log(`[PortalMpcSigner] RPC URL: ${provider.rpcUrl}`);
|
|
63
|
-
const result = yield this.mpc.sign(apiKey, this.mpcUrl, dkg, message.method, JSON.stringify(this.buildParams(method, params)), provider.rpcUrl, provider.chainId.toString());
|
|
64
|
-
console.log(`[PortalMpcSigner] Result: `, result);
|
|
65
|
-
const { data, error } = JSON.parse(String(result));
|
|
66
|
-
if (error && error.length) {
|
|
67
|
-
throw new MpcSigningError(error);
|
|
68
|
-
}
|
|
69
|
-
return data;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
export default MpcSigner;
|