@portal-hq/utils 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/currency/index.js +3 -3
- package/lib/commonjs/definitions/index.js +1 -1
- package/lib/commonjs/errors/portal-error.js +1 -1
- package/lib/commonjs/errors/provider-rpc-error.js +1 -1
- package/lib/commonjs/events/index.js +1 -0
- package/lib/commonjs/index.js +3 -1
- package/lib/commonjs/version/index.js +13 -0
- package/lib/commonjs/version/version.json +1 -0
- package/lib/esm/currency/index.js +3 -3
- package/lib/esm/events/index.js +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/version/index.js +6 -0
- package/lib/esm/version/version.json +1 -0
- package/package.json +2 -2
- package/src/definitions/index.ts +14 -4
- package/src/events/index.ts +1 -0
- package/src/index.ts +2 -0
- package/src/version/index.ts +7 -0
- package/src/version/version.json +1 -0
- package/types.d.ts +2 -28
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.convertLocalToCrypto = exports.convertCryptoToLocal = exports.convert = void 0;
|
|
13
13
|
const countries_1 = require("./countries");
|
|
14
|
-
const convert = (
|
|
14
|
+
const convert = (value_1, ...args_1) => __awaiter(void 0, [value_1, ...args_1], void 0, function* (value, from = 'ETH', countryCode) {
|
|
15
15
|
const country = countries_1.countryCodes[countryCode || 'US'];
|
|
16
16
|
if (!country) {
|
|
17
17
|
throw new Error(`Unable to find country name for country code: ${countryCode}.`);
|
|
@@ -27,7 +27,7 @@ const convert = (value, from = 'ETH', countryCode) => __awaiter(void 0, void 0,
|
|
|
27
27
|
return convertedValue;
|
|
28
28
|
});
|
|
29
29
|
exports.convert = convert;
|
|
30
|
-
const convertCryptoToLocal = (
|
|
30
|
+
const convertCryptoToLocal = (value_1, ...args_1) => __awaiter(void 0, [value_1, ...args_1], void 0, function* (value, from = 'ETH', countryCode) {
|
|
31
31
|
const country = countries_1.countryCodes[countryCode || 'US'];
|
|
32
32
|
if (!country) {
|
|
33
33
|
throw new Error(`Unable to find country name for country code: ${countryCode}.`);
|
|
@@ -43,7 +43,7 @@ const convertCryptoToLocal = (value, from = 'ETH', countryCode) => __awaiter(voi
|
|
|
43
43
|
return convertedValue;
|
|
44
44
|
});
|
|
45
45
|
exports.convertCryptoToLocal = convertCryptoToLocal;
|
|
46
|
-
const convertLocalToCrypto = (
|
|
46
|
+
const convertLocalToCrypto = (value_1, ...args_1) => __awaiter(void 0, [value_1, ...args_1], void 0, function* (value, to = 'ETH', countryCode) {
|
|
47
47
|
const country = countries_1.countryCodes[countryCode || 'US'];
|
|
48
48
|
if (!country) {
|
|
49
49
|
throw new Error(`Unable to find country name for country code: ${countryCode}.`);
|
|
@@ -60,7 +60,7 @@ var MpcStatuses;
|
|
|
60
60
|
MpcStatuses["RecoveringBackupShare"] = "Recovering backup share";
|
|
61
61
|
MpcStatuses["RecoveringSigningShare"] = "Recovering signing share";
|
|
62
62
|
MpcStatuses["StoringShare"] = "Storing share";
|
|
63
|
-
})(MpcStatuses
|
|
63
|
+
})(MpcStatuses || (exports.MpcStatuses = MpcStatuses = {}));
|
|
64
64
|
class Storage {
|
|
65
65
|
delete() {
|
|
66
66
|
throw new Error('[Portal] Storage method delete cannot be called directly. Please extend Storage.');
|
|
@@ -62,7 +62,7 @@ var PortalErrorCodes;
|
|
|
62
62
|
PortalErrorCodes[PortalErrorCodes["FailedToDecodeCipherHexString"] = 405] = "FailedToDecodeCipherHexString";
|
|
63
63
|
PortalErrorCodes[PortalErrorCodes["FailedToGetNonceSize"] = 406] = "FailedToGetNonceSize";
|
|
64
64
|
PortalErrorCodes[PortalErrorCodes["FailedToDecryptCipher"] = 407] = "FailedToDecryptCipher";
|
|
65
|
-
})(PortalErrorCodes
|
|
65
|
+
})(PortalErrorCodes || (exports.PortalErrorCodes = PortalErrorCodes = {}));
|
|
66
66
|
exports.PortalErrorCodeTypes = {
|
|
67
67
|
MpcErrors: Array.from({ length: 100 }, (_, i) => i + 100),
|
|
68
68
|
NetworkErrors: Array.from({ length: 100 }, (_, i) => i + 200),
|
|
@@ -8,7 +8,7 @@ var RpcErrorCodes;
|
|
|
8
8
|
RpcErrorCodes[RpcErrorCodes["UnsupportedMethod"] = 4200] = "UnsupportedMethod";
|
|
9
9
|
RpcErrorCodes[RpcErrorCodes["Disconnected"] = 4900] = "Disconnected";
|
|
10
10
|
RpcErrorCodes[RpcErrorCodes["ChainDisconnected"] = 4901] = "ChainDisconnected";
|
|
11
|
-
})(RpcErrorCodes
|
|
11
|
+
})(RpcErrorCodes || (exports.RpcErrorCodes = RpcErrorCodes = {}));
|
|
12
12
|
const providerErrors = {
|
|
13
13
|
4001: {
|
|
14
14
|
name: 'User Rejected Request',
|
|
@@ -25,5 +25,6 @@ var Events;
|
|
|
25
25
|
Events["StoredClientBackupShare"] = "Stored Client Backup Share";
|
|
26
26
|
Events["StoredClientBackupShareKey"] = "Stored Client Backup Share Key";
|
|
27
27
|
Events["StoredClientSigningShare"] = "Stored Client Signing Share";
|
|
28
|
+
Events["EjectClient"] = "Eject Client";
|
|
28
29
|
})(Events || (Events = {}));
|
|
29
30
|
exports.default = Events;
|
package/lib/commonjs/index.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.PortalRequests = 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.CloudStorageReadError = exports.Storage = exports.MpcStatuses = exports.KeychainAdapter = exports.convert = exports.convertCryptoToLocal = exports.convertLocalToCrypto = exports.getChainNameForId = exports.getChainIdForName = exports.chainNameToId = exports.chainIdToName = void 0;
|
|
6
|
+
exports.HttpRequester = exports.PortalRequests = exports.HttpRequest = exports.parseRequest = exports.numberToHexString = exports.getClientPlatformVersion = 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.CloudStorageReadError = exports.Storage = exports.MpcStatuses = exports.KeychainAdapter = exports.convert = exports.convertCryptoToLocal = exports.convertLocalToCrypto = exports.getChainNameForId = exports.getChainIdForName = exports.chainNameToId = exports.chainIdToName = void 0;
|
|
7
7
|
var chains_1 = require("./chains");
|
|
8
8
|
Object.defineProperty(exports, "chainIdToName", { enumerable: true, get: function () { return chains_1.chainIdToName; } });
|
|
9
9
|
Object.defineProperty(exports, "chainNameToId", { enumerable: true, get: function () { return chains_1.chainNameToId; } });
|
|
@@ -33,6 +33,8 @@ Object.defineProperty(exports, "ProviderRpcError", { enumerable: true, get: func
|
|
|
33
33
|
Object.defineProperty(exports, "RpcErrorCodes", { enumerable: true, get: function () { return errors_1.RpcErrorCodes; } });
|
|
34
34
|
var events_1 = require("./events");
|
|
35
35
|
Object.defineProperty(exports, "Events", { enumerable: true, get: function () { return __importDefault(events_1).default; } });
|
|
36
|
+
var version_1 = require("./version");
|
|
37
|
+
Object.defineProperty(exports, "getClientPlatformVersion", { enumerable: true, get: function () { return version_1.getClientPlatformVersion; } });
|
|
36
38
|
var eth_requests_1 = require("./eth-requests");
|
|
37
39
|
Object.defineProperty(exports, "numberToHexString", { enumerable: true, get: function () { return eth_requests_1.numberToHexString; } });
|
|
38
40
|
Object.defineProperty(exports, "parseRequest", { enumerable: true, get: function () { return eth_requests_1.parseRequest; } });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getClientPlatformVersion = void 0;
|
|
7
|
+
const version_json_1 = __importDefault(require("./version.json"));
|
|
8
|
+
const getClientPlatformVersion = () => {
|
|
9
|
+
if (!(version_json_1.default === null || version_json_1.default === void 0 ? void 0 : version_json_1.default.version))
|
|
10
|
+
return '';
|
|
11
|
+
return version_json_1.default.version;
|
|
12
|
+
};
|
|
13
|
+
exports.getClientPlatformVersion = getClientPlatformVersion;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "version": "4.1.1" }
|
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { countryCodes, currencyCodes } from './countries';
|
|
11
|
-
export const convert = (
|
|
11
|
+
export const convert = (value_1, ...args_1) => __awaiter(void 0, [value_1, ...args_1], void 0, function* (value, from = 'ETH', countryCode) {
|
|
12
12
|
const country = countryCodes[countryCode || 'US'];
|
|
13
13
|
if (!country) {
|
|
14
14
|
throw new Error(`Unable to find country name for country code: ${countryCode}.`);
|
|
@@ -23,7 +23,7 @@ export const convert = (value, from = 'ETH', countryCode) => __awaiter(void 0, v
|
|
|
23
23
|
const convertedValue = Math.round((value / (1 / data[to]) + Number.EPSILON) * 10000) / 10000;
|
|
24
24
|
return convertedValue;
|
|
25
25
|
});
|
|
26
|
-
export const convertCryptoToLocal = (
|
|
26
|
+
export const convertCryptoToLocal = (value_1, ...args_1) => __awaiter(void 0, [value_1, ...args_1], void 0, function* (value, from = 'ETH', countryCode) {
|
|
27
27
|
const country = countryCodes[countryCode || 'US'];
|
|
28
28
|
if (!country) {
|
|
29
29
|
throw new Error(`Unable to find country name for country code: ${countryCode}.`);
|
|
@@ -38,7 +38,7 @@ export const convertCryptoToLocal = (value, from = 'ETH', countryCode) => __awai
|
|
|
38
38
|
const convertedValue = Math.round(value * data[to] * 10000) / 10000;
|
|
39
39
|
return convertedValue;
|
|
40
40
|
});
|
|
41
|
-
export const convertLocalToCrypto = (
|
|
41
|
+
export const convertLocalToCrypto = (value_1, ...args_1) => __awaiter(void 0, [value_1, ...args_1], void 0, function* (value, to = 'ETH', countryCode) {
|
|
42
42
|
const country = countryCodes[countryCode || 'US'];
|
|
43
43
|
if (!country) {
|
|
44
44
|
throw new Error(`Unable to find country name for country code: ${countryCode}.`);
|
package/lib/esm/events/index.js
CHANGED
|
@@ -23,5 +23,6 @@ var Events;
|
|
|
23
23
|
Events["StoredClientBackupShare"] = "Stored Client Backup Share";
|
|
24
24
|
Events["StoredClientBackupShareKey"] = "Stored Client Backup Share Key";
|
|
25
25
|
Events["StoredClientSigningShare"] = "Stored Client Signing Share";
|
|
26
|
+
Events["EjectClient"] = "Eject Client";
|
|
26
27
|
})(Events || (Events = {}));
|
|
27
28
|
export default Events;
|
package/lib/esm/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { convertLocalToCrypto, convertCryptoToLocal, convert } from './currency'
|
|
|
3
3
|
export { KeychainAdapter, MpcStatuses, Storage, } from './definitions';
|
|
4
4
|
export { CloudStorageReadError, HttpError, InvalidApiKeyError, InvalidChainIdError, InvalidGatewayConfigError, MissingOptionError, MpcSigningError, NoAddressError, PortalErrorCodes, PortalErrorCodeTypes, PortalMpcError, ProviderRpcError, RpcErrorCodes, } from './errors';
|
|
5
5
|
export { default as Events } from './events';
|
|
6
|
+
export { getClientPlatformVersion } from './version';
|
|
6
7
|
export { numberToHexString, parseRequest } from './eth-requests';
|
|
7
8
|
export { default as HttpRequest } from './http-request';
|
|
8
9
|
export { default as PortalRequests } from './PortalRequests';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "version": "4.1.1" }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portal-hq/utils",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"main": "lib/commonjs/index",
|
|
5
5
|
"module": "lib/esm/index",
|
|
6
6
|
"source": "src/index",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"ts-jest": "^29.0.3",
|
|
27
27
|
"typescript": "^4.8.4"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "3c03bd4a6573b23865f655856cd0161706f3f30d"
|
|
30
30
|
}
|
package/src/definitions/index.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import PortalConnect from '@portal-hq/connect'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
BuildEip155TransactionResponse,
|
|
4
|
+
BuildSolanaTransactionResponse,
|
|
5
|
+
} from '@portal-hq/core/types'
|
|
3
6
|
|
|
4
7
|
import type {
|
|
5
8
|
AddressesByNamespace,
|
|
@@ -23,6 +26,7 @@ import type {
|
|
|
23
26
|
} from '../../types'
|
|
24
27
|
import PortalRequests from '../PortalRequests'
|
|
25
28
|
import { HttpRequester } from '../requesters'
|
|
29
|
+
import { BackupMethodsUpperCase } from '@portal-hq/core/src/mpc'
|
|
26
30
|
|
|
27
31
|
export type EventHandler = (data: any) => void
|
|
28
32
|
|
|
@@ -52,7 +56,12 @@ export interface IPortalApi {
|
|
|
52
56
|
apiKey: string
|
|
53
57
|
apiUrl: string
|
|
54
58
|
requests: HttpRequester
|
|
55
|
-
|
|
59
|
+
buildTransaction(
|
|
60
|
+
to: string,
|
|
61
|
+
token: string,
|
|
62
|
+
amount: string,
|
|
63
|
+
chain?: string,
|
|
64
|
+
): Promise<BuildEip155TransactionResponse | BuildSolanaTransactionResponse>
|
|
56
65
|
getBackupSharesMetadata(chainId?: string): Promise<BackupSharePairMetadata[]>
|
|
57
66
|
getBalances(chainId?: string): Promise<Balance[]>
|
|
58
67
|
getClient(): Promise<ClientResponse>
|
|
@@ -75,11 +84,11 @@ export interface IPortalApi {
|
|
|
75
84
|
offset?: number,
|
|
76
85
|
order?: GetTransactionsOrder,
|
|
77
86
|
): Promise<Transaction[]>
|
|
78
|
-
identify(traits?: Record<string, any>): Promise<{ success: boolean }>
|
|
79
87
|
prepareClientEject(
|
|
80
88
|
walletId: string,
|
|
81
|
-
backupMethod:
|
|
89
|
+
backupMethod: BackupMethodsUpperCase,
|
|
82
90
|
): Promise<string>
|
|
91
|
+
identify(traits?: Record<string, any>): Promise<{ success: boolean }>
|
|
83
92
|
simulateTransaction(
|
|
84
93
|
params: SimulateTransactionParam,
|
|
85
94
|
chainId?: string,
|
|
@@ -112,6 +121,7 @@ export interface IPortalApi {
|
|
|
112
121
|
| 'UNKNOWN',
|
|
113
122
|
): Promise<void>
|
|
114
123
|
storedClientSigningShares(signingSharePairIds: string[]): Promise<void>
|
|
124
|
+
ejectClient(): Promise<void>
|
|
115
125
|
track(
|
|
116
126
|
event: string,
|
|
117
127
|
properties?: Record<string, any>,
|
package/src/events/index.ts
CHANGED
|
@@ -23,6 +23,7 @@ enum Events {
|
|
|
23
23
|
StoredClientBackupShare = 'Stored Client Backup Share',
|
|
24
24
|
StoredClientBackupShareKey = 'Stored Client Backup Share Key',
|
|
25
25
|
StoredClientSigningShare = 'Stored Client Signing Share',
|
|
26
|
+
EjectClient = 'Eject Client',
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export default Events
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "version": "4.1.1" }
|
package/types.d.ts
CHANGED
|
@@ -7,8 +7,6 @@ import {
|
|
|
7
7
|
|
|
8
8
|
import { MpcStatuses } from './src/definitions'
|
|
9
9
|
|
|
10
|
-
export type MpcMember = 'client' | 'server'
|
|
11
|
-
|
|
12
10
|
export type OutgoingRequestData = MessageData | SignableTransactionData
|
|
13
11
|
|
|
14
12
|
export type ProgressCallback = (status: MpcStatus) => void | Promise<void>
|
|
@@ -22,11 +20,6 @@ export type ValidHttpRequestMethods =
|
|
|
22
20
|
|
|
23
21
|
export type ValidRpcErrorCodes = 4001 | 4100 | 4200 | 4900 | 4901
|
|
24
22
|
|
|
25
|
-
export interface Bk {
|
|
26
|
-
X: string
|
|
27
|
-
Rank: number
|
|
28
|
-
}
|
|
29
|
-
|
|
30
23
|
interface ClientResponse {
|
|
31
24
|
id: string
|
|
32
25
|
custodian: ClientResponseCustodian
|
|
@@ -52,8 +45,8 @@ interface ClientResponseCustodian {
|
|
|
52
45
|
|
|
53
46
|
interface ClientResponseEnvironment {
|
|
54
47
|
id: string
|
|
55
|
-
backupWithPortalEnabled?: boolean
|
|
56
48
|
name: string
|
|
49
|
+
backupWithPortalEnabled?: boolean
|
|
57
50
|
}
|
|
58
51
|
|
|
59
52
|
interface ClientResponseMetadata {
|
|
@@ -184,23 +177,9 @@ export interface PortalKeychainMetadata {
|
|
|
184
177
|
}
|
|
185
178
|
|
|
186
179
|
export interface DkgData {
|
|
187
|
-
|
|
188
|
-
bks: { [key: MpcMember]: Bk }
|
|
189
|
-
p: string
|
|
190
|
-
partialPubkey: { [key: MpcMember]: Pubkey }
|
|
191
|
-
pederson: { [key: MpcMember]: PedersonParams }
|
|
192
|
-
pubkey: Pubkey
|
|
193
|
-
q: string
|
|
180
|
+
backupSharePairId?: string
|
|
194
181
|
share: string
|
|
195
182
|
signingSharePairId?: string
|
|
196
|
-
backupSharePairId?: string
|
|
197
|
-
ssid: string
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export interface PedersonParams {
|
|
201
|
-
n: string
|
|
202
|
-
s: string
|
|
203
|
-
t: string
|
|
204
183
|
}
|
|
205
184
|
|
|
206
185
|
export interface HttpErrorOptions {
|
|
@@ -250,11 +229,6 @@ export interface OutgoingRequest {
|
|
|
250
229
|
data: OutgoingRequestData
|
|
251
230
|
}
|
|
252
231
|
|
|
253
|
-
export interface Pubkey {
|
|
254
|
-
X: string
|
|
255
|
-
Y: string
|
|
256
|
-
}
|
|
257
|
-
|
|
258
232
|
export interface QuoteArgs {
|
|
259
233
|
affiliateAddress?: string
|
|
260
234
|
buyAmount?: number
|