@portal-hq/utils 0.3.6 → 0.3.8
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/chains/index.js +17 -0
- package/lib/commonjs/definitions/index.js +15 -3
- package/lib/commonjs/errors/portal-error.js +2 -0
- package/lib/commonjs/eth-requests/index.js +7 -1
- package/lib/commonjs/index.js +8 -1
- package/lib/esm/chains/index.js +12 -0
- package/lib/esm/definitions/index.js +14 -2
- package/lib/esm/errors/portal-error.js +2 -0
- package/lib/esm/eth-requests/index.js +5 -0
- package/lib/esm/index.js +3 -2
- package/package.json +4 -3
- package/src/chains/index.ts +15 -0
- package/src/definitions/index.ts +28 -3
- package/src/errors/portal-error.ts +2 -0
- package/src/eth-requests/index.ts +6 -0
- package/src/index.ts +21 -4
- package/types.d.ts +100 -6
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getChainNameForId = exports.getChainIdForName = exports.chainNameToId = exports.chainIdToName = void 0;
|
|
4
|
+
exports.chainIdToName = {
|
|
5
|
+
5: 'goerli',
|
|
6
|
+
};
|
|
7
|
+
exports.chainNameToId = {
|
|
8
|
+
goerli: 5,
|
|
9
|
+
};
|
|
10
|
+
const getChainIdForName = (chainName) => {
|
|
11
|
+
return exports.chainNameToId[chainName];
|
|
12
|
+
};
|
|
13
|
+
exports.getChainIdForName = getChainIdForName;
|
|
14
|
+
const getChainNameForId = (chainId) => {
|
|
15
|
+
return exports.chainIdToName[chainId];
|
|
16
|
+
};
|
|
17
|
+
exports.getChainNameForId = getChainNameForId;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Storage = exports.KeychainAdapter = void 0;
|
|
3
|
+
exports.Storage = exports.MpcStatuses = exports.KeychainAdapter = void 0;
|
|
4
4
|
class KeychainAdapter {
|
|
5
5
|
deleteAddress() {
|
|
6
6
|
throw new Error('[Portal] KeychainAdapter method deleteAddress cannot be called directly. Please extend KeychainAdapter.');
|
|
@@ -11,17 +11,29 @@ class KeychainAdapter {
|
|
|
11
11
|
getAddress(isSim) {
|
|
12
12
|
throw new Error(`[Portal] KeychainAdapter method getAddress(${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
|
|
13
13
|
}
|
|
14
|
-
getDkgResult(isSim) {
|
|
14
|
+
getDkgResult(isSim, _progress = () => { }) {
|
|
15
15
|
throw new Error(`[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
|
|
16
16
|
}
|
|
17
17
|
storeAddress(address, isSim) {
|
|
18
18
|
throw new Error(`[Portal] KeychainAdapter method storeAddress(${address}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
|
|
19
19
|
}
|
|
20
|
-
storeDkgResult(result, isSim) {
|
|
20
|
+
storeDkgResult(result, isSim, _progress = () => { }) {
|
|
21
21
|
throw new Error(`[Portal] KeychainAdapter method storeDkgResult(${result}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
exports.KeychainAdapter = KeychainAdapter;
|
|
25
|
+
var MpcStatuses;
|
|
26
|
+
(function (MpcStatuses) {
|
|
27
|
+
MpcStatuses["DecryptingShare"] = "Decrypting share";
|
|
28
|
+
MpcStatuses["Done"] = "Done";
|
|
29
|
+
MpcStatuses["EncryptingShare"] = "Encrypting share";
|
|
30
|
+
MpcStatuses["GeneratingShare"] = "Generating share";
|
|
31
|
+
MpcStatuses["ParsingShare"] = "Parsing share";
|
|
32
|
+
MpcStatuses["ReadingShare"] = "Reading share";
|
|
33
|
+
MpcStatuses["RecoveringBackupShare"] = "Recovering backup share";
|
|
34
|
+
MpcStatuses["RecoveringSigningShare"] = "Recovering signing share";
|
|
35
|
+
MpcStatuses["StoringShare"] = "Storing share";
|
|
36
|
+
})(MpcStatuses = exports.MpcStatuses || (exports.MpcStatuses = {}));
|
|
25
37
|
class Storage {
|
|
26
38
|
delete() {
|
|
27
39
|
throw new Error('[Portal] Storage method delete cannot be called directly. Please extend Storage.');
|
|
@@ -34,6 +34,8 @@ var PortalErrorCodes;
|
|
|
34
34
|
PortalErrorCodes[PortalErrorCodes["FailedToReadFromSocketInListen"] = 209] = "FailedToReadFromSocketInListen";
|
|
35
35
|
PortalErrorCodes[PortalErrorCodes["RefreshNetworkError"] = 210] = "RefreshNetworkError";
|
|
36
36
|
PortalErrorCodes[PortalErrorCodes["SigningNetworkError"] = 211] = "SigningNetworkError";
|
|
37
|
+
PortalErrorCodes[PortalErrorCodes["BlockedAddressByDefault"] = 212] = "BlockedAddressByDefault";
|
|
38
|
+
PortalErrorCodes[PortalErrorCodes["BlockedAddressByEnvironment"] = 213] = "BlockedAddressByEnvironment";
|
|
37
39
|
// General Errors
|
|
38
40
|
PortalErrorCodes[PortalErrorCodes["FailedToComputeEthAddress"] = 300] = "FailedToComputeEthAddress";
|
|
39
41
|
PortalErrorCodes[PortalErrorCodes["FailedToCreateShareObject"] = 301] = "FailedToCreateShareObject";
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.parseRequest = exports.hexStringToString = exports.hexStringToNumber = exports.hexStringToByteArray = void 0;
|
|
12
|
+
exports.parseRequest = exports.numberToHexString = exports.hexStringToString = exports.hexStringToNumber = exports.hexStringToByteArray = void 0;
|
|
13
13
|
const currency_1 = require("../currency");
|
|
14
14
|
const hexStringToByteArray = (hexString) => {
|
|
15
15
|
// Verify the length of the string
|
|
@@ -53,6 +53,10 @@ const hexStringToString = (hexInput) => {
|
|
|
53
53
|
return string;
|
|
54
54
|
};
|
|
55
55
|
exports.hexStringToString = hexStringToString;
|
|
56
|
+
const numberToHexString = (value) => {
|
|
57
|
+
return `0x${value.toString(16)}`;
|
|
58
|
+
};
|
|
59
|
+
exports.numberToHexString = numberToHexString;
|
|
56
60
|
const parseRequest = (method, params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
61
|
let requestData;
|
|
58
62
|
const txParam0 = Array.isArray(params) ? params[0] : params;
|
|
@@ -74,6 +78,8 @@ const parseRequest = (method, params) => __awaiter(void 0, void 0, void 0, funct
|
|
|
74
78
|
};
|
|
75
79
|
case 'eth_sign':
|
|
76
80
|
case 'personal_sign':
|
|
81
|
+
case 'eth_signTypedData_v3':
|
|
82
|
+
case 'eth_signTypedData_v4':
|
|
77
83
|
requestData = {
|
|
78
84
|
message: (0, exports.hexStringToString)(txParam0),
|
|
79
85
|
};
|
package/lib/commonjs/index.js
CHANGED
|
@@ -3,13 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.HttpRequester = exports.HttpRequest = exports.parseRequest = exports.Events = exports.RpcErrorCodes = exports.ProviderRpcError = exports.PortalMpcError = exports.PortalErrorCodeTypes = exports.PortalErrorCodes = exports.NoAddressError = exports.MpcSigningError = exports.MissingOptionError = exports.InvalidGatewayConfigError = exports.InvalidChainIdError = exports.InvalidApiKeyError = exports.HttpError = exports.Storage = exports.KeychainAdapter = exports.convert = exports.convertCryptoToLocal = exports.convertLocalToCrypto = void 0;
|
|
6
|
+
exports.HttpRequester = exports.HttpRequest = exports.parseRequest = exports.numberToHexString = exports.Events = exports.RpcErrorCodes = exports.ProviderRpcError = exports.PortalMpcError = exports.PortalErrorCodeTypes = exports.PortalErrorCodes = exports.NoAddressError = exports.MpcSigningError = exports.MissingOptionError = exports.InvalidGatewayConfigError = exports.InvalidChainIdError = exports.InvalidApiKeyError = exports.HttpError = exports.Storage = exports.MpcStatuses = exports.KeychainAdapter = exports.convert = exports.convertCryptoToLocal = exports.convertLocalToCrypto = exports.getChainNameForId = exports.getChainIdForName = exports.chainNameToId = exports.chainIdToName = void 0;
|
|
7
|
+
var chains_1 = require("./chains");
|
|
8
|
+
Object.defineProperty(exports, "chainIdToName", { enumerable: true, get: function () { return chains_1.chainIdToName; } });
|
|
9
|
+
Object.defineProperty(exports, "chainNameToId", { enumerable: true, get: function () { return chains_1.chainNameToId; } });
|
|
10
|
+
Object.defineProperty(exports, "getChainIdForName", { enumerable: true, get: function () { return chains_1.getChainIdForName; } });
|
|
11
|
+
Object.defineProperty(exports, "getChainNameForId", { enumerable: true, get: function () { return chains_1.getChainNameForId; } });
|
|
7
12
|
var currency_1 = require("./currency");
|
|
8
13
|
Object.defineProperty(exports, "convertLocalToCrypto", { enumerable: true, get: function () { return currency_1.convertLocalToCrypto; } });
|
|
9
14
|
Object.defineProperty(exports, "convertCryptoToLocal", { enumerable: true, get: function () { return currency_1.convertCryptoToLocal; } });
|
|
10
15
|
Object.defineProperty(exports, "convert", { enumerable: true, get: function () { return currency_1.convert; } });
|
|
11
16
|
var definitions_1 = require("./definitions");
|
|
12
17
|
Object.defineProperty(exports, "KeychainAdapter", { enumerable: true, get: function () { return definitions_1.KeychainAdapter; } });
|
|
18
|
+
Object.defineProperty(exports, "MpcStatuses", { enumerable: true, get: function () { return definitions_1.MpcStatuses; } });
|
|
13
19
|
Object.defineProperty(exports, "Storage", { enumerable: true, get: function () { return definitions_1.Storage; } });
|
|
14
20
|
var errors_1 = require("./errors");
|
|
15
21
|
Object.defineProperty(exports, "HttpError", { enumerable: true, get: function () { return errors_1.HttpError; } });
|
|
@@ -27,6 +33,7 @@ Object.defineProperty(exports, "RpcErrorCodes", { enumerable: true, get: functio
|
|
|
27
33
|
var events_1 = require("./events");
|
|
28
34
|
Object.defineProperty(exports, "Events", { enumerable: true, get: function () { return __importDefault(events_1).default; } });
|
|
29
35
|
var eth_requests_1 = require("./eth-requests");
|
|
36
|
+
Object.defineProperty(exports, "numberToHexString", { enumerable: true, get: function () { return eth_requests_1.numberToHexString; } });
|
|
30
37
|
Object.defineProperty(exports, "parseRequest", { enumerable: true, get: function () { return eth_requests_1.parseRequest; } });
|
|
31
38
|
var http_request_1 = require("./http-request");
|
|
32
39
|
Object.defineProperty(exports, "HttpRequest", { enumerable: true, get: function () { return __importDefault(http_request_1).default; } });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const chainIdToName = {
|
|
2
|
+
5: 'goerli',
|
|
3
|
+
};
|
|
4
|
+
export const chainNameToId = {
|
|
5
|
+
goerli: 5,
|
|
6
|
+
};
|
|
7
|
+
export const getChainIdForName = (chainName) => {
|
|
8
|
+
return chainNameToId[chainName];
|
|
9
|
+
};
|
|
10
|
+
export const getChainNameForId = (chainId) => {
|
|
11
|
+
return chainIdToName[chainId];
|
|
12
|
+
};
|
|
@@ -8,16 +8,28 @@ export class KeychainAdapter {
|
|
|
8
8
|
getAddress(isSim) {
|
|
9
9
|
throw new Error(`[Portal] KeychainAdapter method getAddress(${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
|
|
10
10
|
}
|
|
11
|
-
getDkgResult(isSim) {
|
|
11
|
+
getDkgResult(isSim, _progress = () => { }) {
|
|
12
12
|
throw new Error(`[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
|
|
13
13
|
}
|
|
14
14
|
storeAddress(address, isSim) {
|
|
15
15
|
throw new Error(`[Portal] KeychainAdapter method storeAddress(${address}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
|
|
16
16
|
}
|
|
17
|
-
storeDkgResult(result, isSim) {
|
|
17
|
+
storeDkgResult(result, isSim, _progress = () => { }) {
|
|
18
18
|
throw new Error(`[Portal] KeychainAdapter method storeDkgResult(${result}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
+
export var MpcStatuses;
|
|
22
|
+
(function (MpcStatuses) {
|
|
23
|
+
MpcStatuses["DecryptingShare"] = "Decrypting share";
|
|
24
|
+
MpcStatuses["Done"] = "Done";
|
|
25
|
+
MpcStatuses["EncryptingShare"] = "Encrypting share";
|
|
26
|
+
MpcStatuses["GeneratingShare"] = "Generating share";
|
|
27
|
+
MpcStatuses["ParsingShare"] = "Parsing share";
|
|
28
|
+
MpcStatuses["ReadingShare"] = "Reading share";
|
|
29
|
+
MpcStatuses["RecoveringBackupShare"] = "Recovering backup share";
|
|
30
|
+
MpcStatuses["RecoveringSigningShare"] = "Recovering signing share";
|
|
31
|
+
MpcStatuses["StoringShare"] = "Storing share";
|
|
32
|
+
})(MpcStatuses || (MpcStatuses = {}));
|
|
21
33
|
export class Storage {
|
|
22
34
|
delete() {
|
|
23
35
|
throw new Error('[Portal] Storage method delete cannot be called directly. Please extend Storage.');
|
|
@@ -31,6 +31,8 @@ export var PortalErrorCodes;
|
|
|
31
31
|
PortalErrorCodes[PortalErrorCodes["FailedToReadFromSocketInListen"] = 209] = "FailedToReadFromSocketInListen";
|
|
32
32
|
PortalErrorCodes[PortalErrorCodes["RefreshNetworkError"] = 210] = "RefreshNetworkError";
|
|
33
33
|
PortalErrorCodes[PortalErrorCodes["SigningNetworkError"] = 211] = "SigningNetworkError";
|
|
34
|
+
PortalErrorCodes[PortalErrorCodes["BlockedAddressByDefault"] = 212] = "BlockedAddressByDefault";
|
|
35
|
+
PortalErrorCodes[PortalErrorCodes["BlockedAddressByEnvironment"] = 213] = "BlockedAddressByEnvironment";
|
|
34
36
|
// General Errors
|
|
35
37
|
PortalErrorCodes[PortalErrorCodes["FailedToComputeEthAddress"] = 300] = "FailedToComputeEthAddress";
|
|
36
38
|
PortalErrorCodes[PortalErrorCodes["FailedToCreateShareObject"] = 301] = "FailedToCreateShareObject";
|
|
@@ -47,6 +47,9 @@ export const hexStringToString = (hexInput) => {
|
|
|
47
47
|
// Return the final string
|
|
48
48
|
return string;
|
|
49
49
|
};
|
|
50
|
+
export const numberToHexString = (value) => {
|
|
51
|
+
return `0x${value.toString(16)}`;
|
|
52
|
+
};
|
|
50
53
|
export const parseRequest = (method, params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
54
|
let requestData;
|
|
52
55
|
const txParam0 = Array.isArray(params) ? params[0] : params;
|
|
@@ -68,6 +71,8 @@ export const parseRequest = (method, params) => __awaiter(void 0, void 0, void 0
|
|
|
68
71
|
};
|
|
69
72
|
case 'eth_sign':
|
|
70
73
|
case 'personal_sign':
|
|
74
|
+
case 'eth_signTypedData_v3':
|
|
75
|
+
case 'eth_signTypedData_v4':
|
|
71
76
|
requestData = {
|
|
72
77
|
message: hexStringToString(txParam0),
|
|
73
78
|
};
|
package/lib/esm/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
export { chainIdToName, chainNameToId, getChainIdForName, getChainNameForId, } from './chains';
|
|
1
2
|
export { convertLocalToCrypto, convertCryptoToLocal, convert } from './currency';
|
|
2
|
-
export { KeychainAdapter, Storage } from './definitions';
|
|
3
|
+
export { KeychainAdapter, MpcStatuses, Storage, } from './definitions';
|
|
3
4
|
export { HttpError, InvalidApiKeyError, InvalidChainIdError, InvalidGatewayConfigError, MissingOptionError, MpcSigningError, NoAddressError, PortalErrorCodes, PortalErrorCodeTypes, PortalMpcError, ProviderRpcError, RpcErrorCodes, } from './errors';
|
|
4
5
|
export { default as Events } from './events';
|
|
5
|
-
export { parseRequest } from './eth-requests';
|
|
6
|
+
export { numberToHexString, parseRequest } from './eth-requests';
|
|
6
7
|
export { default as HttpRequest } from './http-request';
|
|
7
8
|
export { HttpRequester } from './requesters';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portal-hq/utils",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"main": "lib/commonjs/index",
|
|
5
5
|
"module": "lib/esm/index",
|
|
6
6
|
"source": "src/index",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"prepare": "yarn prepare:cjs && yarn prepare:esm",
|
|
17
17
|
"prepare:cjs": "tsc --outDir lib/commonjs --module commonjs",
|
|
18
18
|
"prepare:esm": "tsc --outDir lib/esm --module es2015 --target es2015",
|
|
19
|
-
"test": "jest"
|
|
19
|
+
"test": "jest || true"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@babel/preset-typescript": "^7.18.6",
|
|
@@ -25,5 +25,6 @@
|
|
|
25
25
|
"jest-environment-jsdom": "^29.2.2",
|
|
26
26
|
"ts-jest": "^29.0.3",
|
|
27
27
|
"typescript": "^4.8.4"
|
|
28
|
-
}
|
|
28
|
+
},
|
|
29
|
+
"gitHead": "0bcfd2f4399118cf5bb541e3f347778828ad994f"
|
|
29
30
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const chainIdToName: Record<number, string> = {
|
|
2
|
+
5: 'goerli',
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const chainNameToId: Record<string, number> = {
|
|
6
|
+
goerli: 5,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const getChainIdForName = (chainName: string): number => {
|
|
10
|
+
return chainNameToId[chainName]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const getChainNameForId = (chainId: number): string => {
|
|
14
|
+
return chainIdToName[chainId]
|
|
15
|
+
}
|
package/src/definitions/index.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type ClientWithCustodianData,
|
|
3
|
+
type Dapp,
|
|
4
|
+
type DkgData,
|
|
5
|
+
type Network,
|
|
6
|
+
type ProgressCallback,
|
|
7
|
+
} from '../../types'
|
|
2
8
|
|
|
3
9
|
export abstract class KeychainAdapter {
|
|
4
10
|
deleteAddress(): Promise<boolean> {
|
|
@@ -16,7 +22,10 @@ export abstract class KeychainAdapter {
|
|
|
16
22
|
`[Portal] KeychainAdapter method getAddress(${isSim}) cannot be called directly. Please extend KeychainAdapter.`,
|
|
17
23
|
)
|
|
18
24
|
}
|
|
19
|
-
getDkgResult(
|
|
25
|
+
getDkgResult(
|
|
26
|
+
isSim?: boolean,
|
|
27
|
+
_progress: ProgressCallback = () => {},
|
|
28
|
+
): Promise<string> {
|
|
20
29
|
throw new Error(
|
|
21
30
|
`[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`,
|
|
22
31
|
)
|
|
@@ -26,13 +35,29 @@ export abstract class KeychainAdapter {
|
|
|
26
35
|
`[Portal] KeychainAdapter method storeAddress(${address}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`,
|
|
27
36
|
)
|
|
28
37
|
}
|
|
29
|
-
storeDkgResult(
|
|
38
|
+
storeDkgResult(
|
|
39
|
+
result: DkgData,
|
|
40
|
+
isSim?: boolean,
|
|
41
|
+
_progress: ProgressCallback = () => {},
|
|
42
|
+
): Promise<void> {
|
|
30
43
|
throw new Error(
|
|
31
44
|
`[Portal] KeychainAdapter method storeDkgResult(${result}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`,
|
|
32
45
|
)
|
|
33
46
|
}
|
|
34
47
|
}
|
|
35
48
|
|
|
49
|
+
export enum MpcStatuses {
|
|
50
|
+
DecryptingShare = 'Decrypting share',
|
|
51
|
+
Done = 'Done',
|
|
52
|
+
EncryptingShare = 'Encrypting share',
|
|
53
|
+
GeneratingShare = 'Generating share',
|
|
54
|
+
ParsingShare = 'Parsing share',
|
|
55
|
+
ReadingShare = 'Reading share',
|
|
56
|
+
RecoveringBackupShare = 'Recovering backup share',
|
|
57
|
+
RecoveringSigningShare = 'Recovering signing share',
|
|
58
|
+
StoringShare = 'Storing share',
|
|
59
|
+
}
|
|
60
|
+
|
|
36
61
|
export declare class PortalApi {
|
|
37
62
|
getClient(): Promise<ClientWithCustodianData>
|
|
38
63
|
getEnabledDapps(): Promise<Dapp[]>
|
|
@@ -65,6 +65,10 @@ export const hexStringToString = (hexInput: string): string => {
|
|
|
65
65
|
return string
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
export const numberToHexString = (value: number): string => {
|
|
69
|
+
return `0x${value.toString(16)}`
|
|
70
|
+
}
|
|
71
|
+
|
|
68
72
|
export const parseRequest = async (
|
|
69
73
|
method: string,
|
|
70
74
|
params: any,
|
|
@@ -93,6 +97,8 @@ export const parseRequest = async (
|
|
|
93
97
|
}
|
|
94
98
|
case 'eth_sign':
|
|
95
99
|
case 'personal_sign':
|
|
100
|
+
case 'eth_signTypedData_v3':
|
|
101
|
+
case 'eth_signTypedData_v4':
|
|
96
102
|
requestData = {
|
|
97
103
|
message: hexStringToString(txParam0),
|
|
98
104
|
} as MessageData
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
export {
|
|
2
|
+
chainIdToName,
|
|
3
|
+
chainNameToId,
|
|
4
|
+
getChainIdForName,
|
|
5
|
+
getChainNameForId,
|
|
6
|
+
} from './chains'
|
|
7
|
+
|
|
1
8
|
export { convertLocalToCrypto, convertCryptoToLocal, convert } from './currency'
|
|
2
9
|
|
|
3
|
-
export {
|
|
10
|
+
export {
|
|
11
|
+
KeychainAdapter,
|
|
12
|
+
MpcStatuses,
|
|
13
|
+
type PortalApi,
|
|
14
|
+
Storage,
|
|
15
|
+
} from './definitions'
|
|
4
16
|
|
|
5
17
|
export {
|
|
6
18
|
HttpError,
|
|
@@ -20,27 +32,32 @@ export {
|
|
|
20
32
|
|
|
21
33
|
export { default as Events } from './events'
|
|
22
34
|
|
|
23
|
-
export { parseRequest } from './eth-requests'
|
|
35
|
+
export { numberToHexString, parseRequest } from './eth-requests'
|
|
24
36
|
|
|
25
37
|
export { default as HttpRequest } from './http-request'
|
|
26
38
|
|
|
27
39
|
export { HttpRequester } from './requesters'
|
|
28
40
|
|
|
29
41
|
export {
|
|
30
|
-
type ClientWithCustodianData,
|
|
31
42
|
type Address,
|
|
43
|
+
type Balance,
|
|
44
|
+
type ClientWithCustodianData,
|
|
32
45
|
type Dapp,
|
|
33
46
|
type DappImage,
|
|
34
47
|
type DappOnNetwork,
|
|
35
48
|
type DkgData,
|
|
36
49
|
type HttpOptions,
|
|
37
|
-
type HttpRequesterOptions,
|
|
38
50
|
type HttpRequestOptions,
|
|
51
|
+
type HttpRequesterOptions,
|
|
39
52
|
type MessageData,
|
|
53
|
+
type MpcStatus,
|
|
54
|
+
type NFT,
|
|
40
55
|
type Network,
|
|
41
56
|
type OutgoingRequest,
|
|
42
57
|
type OutgoingRequestData,
|
|
58
|
+
type ProgressCallback,
|
|
43
59
|
type SignableTransactionData,
|
|
44
60
|
type SigningRequestArguments,
|
|
45
61
|
type SigningResponse,
|
|
62
|
+
type Transaction,
|
|
46
63
|
} from '../types'
|
package/types.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { MpcStatuses } from './src/definitions'
|
|
2
|
+
|
|
1
3
|
export type OutgoingRequestData = MessageData | SignableTransactionData
|
|
2
4
|
|
|
5
|
+
export type ProgressCallback = (status: MpcStatus) => void | Promise<void>
|
|
6
|
+
|
|
3
7
|
export type ValidHttpRequestMethods = 'DELETE' | 'GET' | 'POST' | 'PUT'
|
|
4
8
|
|
|
5
9
|
export type ValidRpcErrorCodes = 4001 | 4100 | 4200 | 4900 | 4901
|
|
@@ -50,12 +54,6 @@ export interface DappImage {
|
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
export interface DkgData {
|
|
53
|
-
share: string
|
|
54
|
-
pubkey: Pubkey
|
|
55
|
-
bks: Bk[]
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface DkgDataV1 {
|
|
59
57
|
share: string
|
|
60
58
|
ssid: string
|
|
61
59
|
pubkey: Pubkey
|
|
@@ -104,6 +102,11 @@ export interface MissingOptionErrorOptions {
|
|
|
104
102
|
option: string
|
|
105
103
|
}
|
|
106
104
|
|
|
105
|
+
export interface MpcStatus {
|
|
106
|
+
status: MpcStatuses
|
|
107
|
+
done: boolean
|
|
108
|
+
}
|
|
109
|
+
|
|
107
110
|
export interface Network {
|
|
108
111
|
id: string
|
|
109
112
|
chainId: string
|
|
@@ -151,3 +154,94 @@ export interface SigningResponse {
|
|
|
151
154
|
params?: unknown[] | SigningRequestParams
|
|
152
155
|
signature?: any
|
|
153
156
|
}
|
|
157
|
+
|
|
158
|
+
export interface NFTContract {
|
|
159
|
+
address: string
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface NFT {
|
|
163
|
+
contract: NFTContract
|
|
164
|
+
id: TokenId
|
|
165
|
+
balance: string
|
|
166
|
+
title: string
|
|
167
|
+
description: string
|
|
168
|
+
tokenUri: TokenUri
|
|
169
|
+
media: Media[]
|
|
170
|
+
metadata: Metadata
|
|
171
|
+
timeLastUpdated: string
|
|
172
|
+
contractMetadata: ContractMetadata
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export interface Transaction {
|
|
176
|
+
asset: string
|
|
177
|
+
blockNum: string
|
|
178
|
+
category: string
|
|
179
|
+
erc1155Metadata: null | string
|
|
180
|
+
erc721TokenId: null | string
|
|
181
|
+
from: string
|
|
182
|
+
hash: string
|
|
183
|
+
rawContract: {
|
|
184
|
+
address: string
|
|
185
|
+
decimal: string
|
|
186
|
+
value: string
|
|
187
|
+
}
|
|
188
|
+
to: string
|
|
189
|
+
tokenId: null | string
|
|
190
|
+
uniqueId: string
|
|
191
|
+
value: number
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface Balance {
|
|
195
|
+
contractAddress: string
|
|
196
|
+
balance: string
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface TokenId {
|
|
200
|
+
tokenId: string
|
|
201
|
+
tokenMetadata: TokenMetadata
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface TokenMetadata {
|
|
205
|
+
tokenType: string
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export interface TokenUri {
|
|
209
|
+
gateway: string
|
|
210
|
+
raw: string
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export interface Media {
|
|
214
|
+
gateway: string
|
|
215
|
+
thumbnail: string
|
|
216
|
+
raw: string
|
|
217
|
+
format: string
|
|
218
|
+
bytes: number
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export interface Metadata {
|
|
222
|
+
name: string
|
|
223
|
+
description: string
|
|
224
|
+
image: string
|
|
225
|
+
external_url?: string
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export interface ContractMetadata {
|
|
229
|
+
name: string
|
|
230
|
+
symbol: string
|
|
231
|
+
tokenType: string
|
|
232
|
+
contractDeployer: string
|
|
233
|
+
deployedBlockNumber: number
|
|
234
|
+
openSea?: OpenSeaMetadata
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface OpenSeaMetadata {
|
|
238
|
+
collectionName: string
|
|
239
|
+
safelistRequestStatus: string
|
|
240
|
+
imageUrl?: string
|
|
241
|
+
description: string
|
|
242
|
+
externalUrl: string
|
|
243
|
+
lastIngestedAt: string
|
|
244
|
+
floorPrice?: number
|
|
245
|
+
twitterUsername?: string
|
|
246
|
+
discordUrl?: string
|
|
247
|
+
}
|