@portal-hq/utils 0.3.2 → 0.3.4

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.
@@ -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,4 +1,18 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
18
  };
@@ -18,6 +32,7 @@ var mpc_signing_error_1 = require("./mpc-signing-error");
18
32
  Object.defineProperty(exports, "MpcSigningError", { enumerable: true, get: function () { return __importDefault(mpc_signing_error_1).default; } });
19
33
  var no_address_error_1 = require("./no-address-error");
20
34
  Object.defineProperty(exports, "NoAddressError", { enumerable: true, get: function () { return __importDefault(no_address_error_1).default; } });
35
+ __exportStar(require("./portal-error"), exports);
21
36
  var provider_rpc_error_1 = require("./provider-rpc-error");
22
37
  Object.defineProperty(exports, "ProviderRpcError", { enumerable: true, get: function () { return __importDefault(provider_rpc_error_1).default; } });
23
38
  Object.defineProperty(exports, "RpcErrorCodes", { enumerable: true, get: function () { return provider_rpc_error_1.RpcErrorCodes; } });
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PortalMpcError = exports.PortalErrorCodeTypes = exports.PortalErrorCodes = void 0;
4
+ var PortalErrorCodes;
5
+ (function (PortalErrorCodes) {
6
+ PortalErrorCodes[PortalErrorCodes["InvalidRankAndThreshold"] = 100] = "InvalidRankAndThreshold";
7
+ PortalErrorCodes[PortalErrorCodes["FailedToStartDkg"] = 101] = "FailedToStartDkg";
8
+ PortalErrorCodes[PortalErrorCodes["FailedToFinishDkg"] = 102] = "FailedToFinishDkg";
9
+ PortalErrorCodes[PortalErrorCodes["FailedToConvertDkgResult"] = 103] = "FailedToConvertDkgResult";
10
+ PortalErrorCodes[PortalErrorCodes["FailedToStartReshare"] = 104] = "FailedToStartReshare";
11
+ PortalErrorCodes[PortalErrorCodes["FailedToFinishReshare"] = 105] = "FailedToFinishReshare";
12
+ PortalErrorCodes[PortalErrorCodes["FailedToConvertReshareResult"] = 106] = "FailedToConvertReshareResult";
13
+ PortalErrorCodes[PortalErrorCodes["FailedToStartSign"] = 107] = "FailedToStartSign";
14
+ PortalErrorCodes[PortalErrorCodes["FailedToFinishSign"] = 108] = "FailedToFinishSign";
15
+ PortalErrorCodes[PortalErrorCodes["FailedToConvertSignResult"] = 109] = "FailedToConvertSignResult";
16
+ PortalErrorCodes[PortalErrorCodes["DkgProcessError"] = 110] = "DkgProcessError";
17
+ PortalErrorCodes[PortalErrorCodes["FailedToParseSocketMessage"] = 111] = "FailedToParseSocketMessage";
18
+ PortalErrorCodes[PortalErrorCodes["FailedToAddMessageToChannel"] = 112] = "FailedToAddMessageToChannel";
19
+ PortalErrorCodes[PortalErrorCodes["RefreshShareMismatch"] = 113] = "RefreshShareMismatch";
20
+ PortalErrorCodes[PortalErrorCodes["RefreshProcessError"] = 114] = "RefreshProcessError";
21
+ PortalErrorCodes[PortalErrorCodes["FailedToGetPaillierKeys"] = 115] = "FailedToGetPaillierKeys";
22
+ PortalErrorCodes[PortalErrorCodes["SigningShareMismatch"] = 116] = "SigningShareMismatch";
23
+ PortalErrorCodes[PortalErrorCodes["SigningProcessError"] = 117] = "SigningProcessError";
24
+ // Network Errors
25
+ PortalErrorCodes[PortalErrorCodes["FailedToSendSignRequest"] = 200] = "FailedToSendSignRequest";
26
+ PortalErrorCodes[PortalErrorCodes["BadRequest"] = 201] = "BadRequest";
27
+ PortalErrorCodes[PortalErrorCodes["InvalidApiKey"] = 202] = "InvalidApiKey";
28
+ PortalErrorCodes[PortalErrorCodes["NotFound"] = 203] = "NotFound";
29
+ PortalErrorCodes[PortalErrorCodes["FailedToReceive101StatusCode"] = 204] = "FailedToReceive101StatusCode";
30
+ PortalErrorCodes[PortalErrorCodes["FailedToCreateWebsocket"] = 205] = "FailedToCreateWebsocket";
31
+ PortalErrorCodes[PortalErrorCodes["DkgNetworkError"] = 206] = "DkgNetworkError";
32
+ PortalErrorCodes[PortalErrorCodes["FailedToReadPartialPublicKeyFromSocket"] = 207] = "FailedToReadPartialPublicKeyFromSocket";
33
+ PortalErrorCodes[PortalErrorCodes["FailedToWritePartialPublicKeyToSocket"] = 208] = "FailedToWritePartialPublicKeyToSocket";
34
+ PortalErrorCodes[PortalErrorCodes["FailedToReadFromSocketInListen"] = 209] = "FailedToReadFromSocketInListen";
35
+ PortalErrorCodes[PortalErrorCodes["RefreshNetworkError"] = 210] = "RefreshNetworkError";
36
+ PortalErrorCodes[PortalErrorCodes["SigningNetworkError"] = 211] = "SigningNetworkError";
37
+ // General Errors
38
+ PortalErrorCodes[PortalErrorCodes["FailedToComputeEthAddress"] = 300] = "FailedToComputeEthAddress";
39
+ PortalErrorCodes[PortalErrorCodes["FailedToCreateShareObject"] = 301] = "FailedToCreateShareObject";
40
+ PortalErrorCodes[PortalErrorCodes["IncorrectInputToSign"] = 302] = "IncorrectInputToSign";
41
+ PortalErrorCodes[PortalErrorCodes["FailedToConvertPublicKeyBytes"] = 303] = "FailedToConvertPublicKeyBytes";
42
+ PortalErrorCodes[PortalErrorCodes["FailedToComputeSignature"] = 304] = "FailedToComputeSignature";
43
+ PortalErrorCodes[PortalErrorCodes["FailedToParseInputShareObject"] = 305] = "FailedToParseInputShareObject";
44
+ PortalErrorCodes[PortalErrorCodes["IncorrectShareObjectType"] = 306] = "IncorrectShareObjectType";
45
+ PortalErrorCodes[PortalErrorCodes["FailedToConvertStringToBigInt"] = 307] = "FailedToConvertStringToBigInt";
46
+ PortalErrorCodes[PortalErrorCodes["FailedToPopulateTransaction"] = 308] = "FailedToPopulateTransaction";
47
+ PortalErrorCodes[PortalErrorCodes["FailedToBuildMessage"] = 309] = "FailedToBuildMessage";
48
+ PortalErrorCodes[PortalErrorCodes["UnsupportedEthMethod"] = 310] = "UnsupportedEthMethod";
49
+ PortalErrorCodes[PortalErrorCodes["NodeRpcError"] = 311] = "NodeRpcError";
50
+ PortalErrorCodes[PortalErrorCodes["FailedToInitializePublicKey"] = 312] = "FailedToInitializePublicKey";
51
+ PortalErrorCodes[PortalErrorCodes["FailedToCalculateSelfPublicKey"] = 313] = "FailedToCalculateSelfPublicKey";
52
+ PortalErrorCodes[PortalErrorCodes["FailedToUnmarshalPartialPublicKeyFromSocket"] = 314] = "FailedToUnmarshalPartialPublicKeyFromSocket";
53
+ PortalErrorCodes[PortalErrorCodes["FailedToMarshalPartialPublicKey"] = 315] = "FailedToMarshalPartialPublicKey";
54
+ // Encrypt/Decrypt Errors
55
+ PortalErrorCodes[PortalErrorCodes["FailedToCreateRandomDekBytes"] = 400] = "FailedToCreateRandomDekBytes";
56
+ PortalErrorCodes[PortalErrorCodes["FailedToCreateCipherBlock"] = 401] = "FailedToCreateCipherBlock";
57
+ PortalErrorCodes[PortalErrorCodes["FailedToCreateGcmCipher"] = 402] = "FailedToCreateGcmCipher";
58
+ PortalErrorCodes[PortalErrorCodes["FailedToReadNonceIntoBuffer"] = 403] = "FailedToReadNonceIntoBuffer";
59
+ PortalErrorCodes[PortalErrorCodes["FailedToDecodeKeyHexString"] = 404] = "FailedToDecodeKeyHexString";
60
+ PortalErrorCodes[PortalErrorCodes["FailedToDecodeCipherHexString"] = 405] = "FailedToDecodeCipherHexString";
61
+ PortalErrorCodes[PortalErrorCodes["FailedToGetNonceSize"] = 406] = "FailedToGetNonceSize";
62
+ PortalErrorCodes[PortalErrorCodes["FailedToDecryptCipher"] = 407] = "FailedToDecryptCipher";
63
+ })(PortalErrorCodes = exports.PortalErrorCodes || (exports.PortalErrorCodes = {}));
64
+ exports.PortalErrorCodeTypes = {
65
+ MpcErrors: Array.from({ length: 100 }, (_, i) => i + 100),
66
+ NetworkErrors: Array.from({ length: 100 }, (_, i) => i + 200),
67
+ GeneralErrors: Array.from({ length: 100 }, (_, i) => i + 300),
68
+ EncryptDecryptErrors: Array.from({ length: 100 }, (_, i) => i + 400),
69
+ };
70
+ class PortalMpcError extends Error {
71
+ constructor(error) {
72
+ super(error.message);
73
+ this.code = error.code;
74
+ }
75
+ }
76
+ exports.PortalMpcError = PortalMpcError;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var Events;
4
+ (function (Events) {
5
+ Events["PortalInitialized"] = "Portal Initialized";
6
+ Events["TransactionSigned"] = "Transaction Signed";
7
+ Events["WalletBackedUp"] = "Wallet Backed Up";
8
+ Events["WalletCreated"] = "Wallet Created";
9
+ Events["WalletRecovered"] = "Wallet Recovered";
10
+ })(Events || (Events = {}));
11
+ exports.default = Events;
@@ -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.HttpRequest = exports.parseRequest = exports.RpcErrorCodes = exports.ProviderRpcError = 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.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;
7
7
  var currency_1 = require("./currency");
8
8
  Object.defineProperty(exports, "convertLocalToCrypto", { enumerable: true, get: function () { return currency_1.convertLocalToCrypto; } });
9
9
  Object.defineProperty(exports, "convertCryptoToLocal", { enumerable: true, get: function () { return currency_1.convertCryptoToLocal; } });
@@ -19,8 +19,13 @@ Object.defineProperty(exports, "InvalidGatewayConfigError", { enumerable: true,
19
19
  Object.defineProperty(exports, "MissingOptionError", { enumerable: true, get: function () { return errors_1.MissingOptionError; } });
20
20
  Object.defineProperty(exports, "MpcSigningError", { enumerable: true, get: function () { return errors_1.MpcSigningError; } });
21
21
  Object.defineProperty(exports, "NoAddressError", { enumerable: true, get: function () { return errors_1.NoAddressError; } });
22
+ Object.defineProperty(exports, "PortalErrorCodes", { enumerable: true, get: function () { return errors_1.PortalErrorCodes; } });
23
+ Object.defineProperty(exports, "PortalErrorCodeTypes", { enumerable: true, get: function () { return errors_1.PortalErrorCodeTypes; } });
24
+ Object.defineProperty(exports, "PortalMpcError", { enumerable: true, get: function () { return errors_1.PortalMpcError; } });
22
25
  Object.defineProperty(exports, "ProviderRpcError", { enumerable: true, get: function () { return errors_1.ProviderRpcError; } });
23
26
  Object.defineProperty(exports, "RpcErrorCodes", { enumerable: true, get: function () { return errors_1.RpcErrorCodes; } });
27
+ var events_1 = require("./events");
28
+ Object.defineProperty(exports, "Events", { enumerable: true, get: function () { return __importDefault(events_1).default; } });
24
29
  var eth_requests_1 = require("./eth-requests");
25
30
  Object.defineProperty(exports, "parseRequest", { enumerable: true, get: function () { return eth_requests_1.parseRequest; } });
26
31
  var http_request_1 = require("./http-request");
@@ -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
+ };
@@ -5,4 +5,5 @@ export { default as InvalidGatewayConfigError } from './invalid-gateway-config-e
5
5
  export { default as MissingOptionError } from './missing-option-error';
6
6
  export { default as MpcSigningError } from './mpc-signing-error';
7
7
  export { default as NoAddressError } from './no-address-error';
8
+ export * from './portal-error';
8
9
  export { default as ProviderRpcError, RpcErrorCodes, } from './provider-rpc-error';
@@ -0,0 +1,72 @@
1
+ export var PortalErrorCodes;
2
+ (function (PortalErrorCodes) {
3
+ PortalErrorCodes[PortalErrorCodes["InvalidRankAndThreshold"] = 100] = "InvalidRankAndThreshold";
4
+ PortalErrorCodes[PortalErrorCodes["FailedToStartDkg"] = 101] = "FailedToStartDkg";
5
+ PortalErrorCodes[PortalErrorCodes["FailedToFinishDkg"] = 102] = "FailedToFinishDkg";
6
+ PortalErrorCodes[PortalErrorCodes["FailedToConvertDkgResult"] = 103] = "FailedToConvertDkgResult";
7
+ PortalErrorCodes[PortalErrorCodes["FailedToStartReshare"] = 104] = "FailedToStartReshare";
8
+ PortalErrorCodes[PortalErrorCodes["FailedToFinishReshare"] = 105] = "FailedToFinishReshare";
9
+ PortalErrorCodes[PortalErrorCodes["FailedToConvertReshareResult"] = 106] = "FailedToConvertReshareResult";
10
+ PortalErrorCodes[PortalErrorCodes["FailedToStartSign"] = 107] = "FailedToStartSign";
11
+ PortalErrorCodes[PortalErrorCodes["FailedToFinishSign"] = 108] = "FailedToFinishSign";
12
+ PortalErrorCodes[PortalErrorCodes["FailedToConvertSignResult"] = 109] = "FailedToConvertSignResult";
13
+ PortalErrorCodes[PortalErrorCodes["DkgProcessError"] = 110] = "DkgProcessError";
14
+ PortalErrorCodes[PortalErrorCodes["FailedToParseSocketMessage"] = 111] = "FailedToParseSocketMessage";
15
+ PortalErrorCodes[PortalErrorCodes["FailedToAddMessageToChannel"] = 112] = "FailedToAddMessageToChannel";
16
+ PortalErrorCodes[PortalErrorCodes["RefreshShareMismatch"] = 113] = "RefreshShareMismatch";
17
+ PortalErrorCodes[PortalErrorCodes["RefreshProcessError"] = 114] = "RefreshProcessError";
18
+ PortalErrorCodes[PortalErrorCodes["FailedToGetPaillierKeys"] = 115] = "FailedToGetPaillierKeys";
19
+ PortalErrorCodes[PortalErrorCodes["SigningShareMismatch"] = 116] = "SigningShareMismatch";
20
+ PortalErrorCodes[PortalErrorCodes["SigningProcessError"] = 117] = "SigningProcessError";
21
+ // Network Errors
22
+ PortalErrorCodes[PortalErrorCodes["FailedToSendSignRequest"] = 200] = "FailedToSendSignRequest";
23
+ PortalErrorCodes[PortalErrorCodes["BadRequest"] = 201] = "BadRequest";
24
+ PortalErrorCodes[PortalErrorCodes["InvalidApiKey"] = 202] = "InvalidApiKey";
25
+ PortalErrorCodes[PortalErrorCodes["NotFound"] = 203] = "NotFound";
26
+ PortalErrorCodes[PortalErrorCodes["FailedToReceive101StatusCode"] = 204] = "FailedToReceive101StatusCode";
27
+ PortalErrorCodes[PortalErrorCodes["FailedToCreateWebsocket"] = 205] = "FailedToCreateWebsocket";
28
+ PortalErrorCodes[PortalErrorCodes["DkgNetworkError"] = 206] = "DkgNetworkError";
29
+ PortalErrorCodes[PortalErrorCodes["FailedToReadPartialPublicKeyFromSocket"] = 207] = "FailedToReadPartialPublicKeyFromSocket";
30
+ PortalErrorCodes[PortalErrorCodes["FailedToWritePartialPublicKeyToSocket"] = 208] = "FailedToWritePartialPublicKeyToSocket";
31
+ PortalErrorCodes[PortalErrorCodes["FailedToReadFromSocketInListen"] = 209] = "FailedToReadFromSocketInListen";
32
+ PortalErrorCodes[PortalErrorCodes["RefreshNetworkError"] = 210] = "RefreshNetworkError";
33
+ PortalErrorCodes[PortalErrorCodes["SigningNetworkError"] = 211] = "SigningNetworkError";
34
+ // General Errors
35
+ PortalErrorCodes[PortalErrorCodes["FailedToComputeEthAddress"] = 300] = "FailedToComputeEthAddress";
36
+ PortalErrorCodes[PortalErrorCodes["FailedToCreateShareObject"] = 301] = "FailedToCreateShareObject";
37
+ PortalErrorCodes[PortalErrorCodes["IncorrectInputToSign"] = 302] = "IncorrectInputToSign";
38
+ PortalErrorCodes[PortalErrorCodes["FailedToConvertPublicKeyBytes"] = 303] = "FailedToConvertPublicKeyBytes";
39
+ PortalErrorCodes[PortalErrorCodes["FailedToComputeSignature"] = 304] = "FailedToComputeSignature";
40
+ PortalErrorCodes[PortalErrorCodes["FailedToParseInputShareObject"] = 305] = "FailedToParseInputShareObject";
41
+ PortalErrorCodes[PortalErrorCodes["IncorrectShareObjectType"] = 306] = "IncorrectShareObjectType";
42
+ PortalErrorCodes[PortalErrorCodes["FailedToConvertStringToBigInt"] = 307] = "FailedToConvertStringToBigInt";
43
+ PortalErrorCodes[PortalErrorCodes["FailedToPopulateTransaction"] = 308] = "FailedToPopulateTransaction";
44
+ PortalErrorCodes[PortalErrorCodes["FailedToBuildMessage"] = 309] = "FailedToBuildMessage";
45
+ PortalErrorCodes[PortalErrorCodes["UnsupportedEthMethod"] = 310] = "UnsupportedEthMethod";
46
+ PortalErrorCodes[PortalErrorCodes["NodeRpcError"] = 311] = "NodeRpcError";
47
+ PortalErrorCodes[PortalErrorCodes["FailedToInitializePublicKey"] = 312] = "FailedToInitializePublicKey";
48
+ PortalErrorCodes[PortalErrorCodes["FailedToCalculateSelfPublicKey"] = 313] = "FailedToCalculateSelfPublicKey";
49
+ PortalErrorCodes[PortalErrorCodes["FailedToUnmarshalPartialPublicKeyFromSocket"] = 314] = "FailedToUnmarshalPartialPublicKeyFromSocket";
50
+ PortalErrorCodes[PortalErrorCodes["FailedToMarshalPartialPublicKey"] = 315] = "FailedToMarshalPartialPublicKey";
51
+ // Encrypt/Decrypt Errors
52
+ PortalErrorCodes[PortalErrorCodes["FailedToCreateRandomDekBytes"] = 400] = "FailedToCreateRandomDekBytes";
53
+ PortalErrorCodes[PortalErrorCodes["FailedToCreateCipherBlock"] = 401] = "FailedToCreateCipherBlock";
54
+ PortalErrorCodes[PortalErrorCodes["FailedToCreateGcmCipher"] = 402] = "FailedToCreateGcmCipher";
55
+ PortalErrorCodes[PortalErrorCodes["FailedToReadNonceIntoBuffer"] = 403] = "FailedToReadNonceIntoBuffer";
56
+ PortalErrorCodes[PortalErrorCodes["FailedToDecodeKeyHexString"] = 404] = "FailedToDecodeKeyHexString";
57
+ PortalErrorCodes[PortalErrorCodes["FailedToDecodeCipherHexString"] = 405] = "FailedToDecodeCipherHexString";
58
+ PortalErrorCodes[PortalErrorCodes["FailedToGetNonceSize"] = 406] = "FailedToGetNonceSize";
59
+ PortalErrorCodes[PortalErrorCodes["FailedToDecryptCipher"] = 407] = "FailedToDecryptCipher";
60
+ })(PortalErrorCodes || (PortalErrorCodes = {}));
61
+ export const PortalErrorCodeTypes = {
62
+ MpcErrors: Array.from({ length: 100 }, (_, i) => i + 100),
63
+ NetworkErrors: Array.from({ length: 100 }, (_, i) => i + 200),
64
+ GeneralErrors: Array.from({ length: 100 }, (_, i) => i + 300),
65
+ EncryptDecryptErrors: Array.from({ length: 100 }, (_, i) => i + 400),
66
+ };
67
+ export class PortalMpcError extends Error {
68
+ constructor(error) {
69
+ super(error.message);
70
+ this.code = error.code;
71
+ }
72
+ }
@@ -0,0 +1,9 @@
1
+ var Events;
2
+ (function (Events) {
3
+ Events["PortalInitialized"] = "Portal Initialized";
4
+ Events["TransactionSigned"] = "Transaction Signed";
5
+ Events["WalletBackedUp"] = "Wallet Backed Up";
6
+ Events["WalletCreated"] = "Wallet Created";
7
+ Events["WalletRecovered"] = "Wallet Recovered";
8
+ })(Events || (Events = {}));
9
+ export default Events;
package/lib/esm/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export { convertLocalToCrypto, convertCryptoToLocal, convert } from './currency';
2
2
  export { KeychainAdapter, Storage } from './definitions';
3
- export { HttpError, InvalidApiKeyError, InvalidChainIdError, InvalidGatewayConfigError, MissingOptionError, MpcSigningError, NoAddressError, ProviderRpcError, RpcErrorCodes, } from './errors';
3
+ export { HttpError, InvalidApiKeyError, InvalidChainIdError, InvalidGatewayConfigError, MissingOptionError, MpcSigningError, NoAddressError, PortalErrorCodes, PortalErrorCodeTypes, PortalMpcError, ProviderRpcError, RpcErrorCodes, } from './errors';
4
+ export { default as Events } from './events';
4
5
  export { parseRequest } from './eth-requests';
5
6
  export { default as HttpRequest } from './http-request';
6
7
  export { HttpRequester } from './requesters';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portal-hq/utils",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "main": "lib/commonjs/index",
5
5
  "module": "lib/esm/index",
6
6
  "source": "src/index",
@@ -5,6 +5,7 @@ export { default as InvalidGatewayConfigError } from './invalid-gateway-config-e
5
5
  export { default as MissingOptionError } from './missing-option-error'
6
6
  export { default as MpcSigningError } from './mpc-signing-error'
7
7
  export { default as NoAddressError } from './no-address-error'
8
+ export * from './portal-error'
8
9
  export {
9
10
  default as ProviderRpcError,
10
11
  RpcErrorCodes,
@@ -0,0 +1,87 @@
1
+ export interface PortalError {
2
+ code: number
3
+ message: string
4
+ }
5
+
6
+ export enum PortalErrorCodes {
7
+ InvalidRankAndThreshold = 100,
8
+ FailedToStartDkg = 101,
9
+ FailedToFinishDkg = 102,
10
+ FailedToConvertDkgResult = 103,
11
+ FailedToStartReshare = 104,
12
+ FailedToFinishReshare = 105,
13
+ FailedToConvertReshareResult = 106,
14
+ FailedToStartSign = 107,
15
+ FailedToFinishSign = 108,
16
+ FailedToConvertSignResult = 109,
17
+ DkgProcessError = 110,
18
+ FailedToParseSocketMessage = 111,
19
+ FailedToAddMessageToChannel = 112,
20
+ RefreshShareMismatch = 113,
21
+ RefreshProcessError = 114,
22
+ FailedToGetPaillierKeys = 115,
23
+ SigningShareMismatch = 116,
24
+ SigningProcessError = 117,
25
+
26
+ // Network Errors
27
+
28
+ FailedToSendSignRequest = 200,
29
+ BadRequest = 201,
30
+ InvalidApiKey = 202,
31
+ NotFound = 203,
32
+ FailedToReceive101StatusCode = 204,
33
+ FailedToCreateWebsocket = 205,
34
+ DkgNetworkError = 206,
35
+ FailedToReadPartialPublicKeyFromSocket = 207,
36
+ FailedToWritePartialPublicKeyToSocket = 208,
37
+ FailedToReadFromSocketInListen = 209,
38
+ RefreshNetworkError = 210,
39
+ SigningNetworkError = 211,
40
+
41
+ // General Errors
42
+
43
+ FailedToComputeEthAddress = 300,
44
+ FailedToCreateShareObject = 301,
45
+ IncorrectInputToSign = 302,
46
+ FailedToConvertPublicKeyBytes = 303,
47
+ FailedToComputeSignature = 304,
48
+ FailedToParseInputShareObject = 305,
49
+ IncorrectShareObjectType = 306,
50
+ FailedToConvertStringToBigInt = 307,
51
+ FailedToPopulateTransaction = 308,
52
+ FailedToBuildMessage = 309,
53
+ UnsupportedEthMethod = 310,
54
+ NodeRpcError = 311,
55
+ FailedToInitializePublicKey = 312,
56
+ FailedToCalculateSelfPublicKey = 313,
57
+ FailedToUnmarshalPartialPublicKeyFromSocket = 314,
58
+ FailedToMarshalPartialPublicKey = 315,
59
+
60
+ // Encrypt/Decrypt Errors
61
+
62
+ FailedToCreateRandomDekBytes = 400,
63
+ FailedToCreateCipherBlock = 401,
64
+ FailedToCreateGcmCipher = 402,
65
+ FailedToReadNonceIntoBuffer = 403,
66
+ FailedToDecodeKeyHexString = 404,
67
+ FailedToDecodeCipherHexString = 405,
68
+ FailedToGetNonceSize = 406,
69
+ FailedToDecryptCipher = 407,
70
+ }
71
+
72
+ export const PortalErrorCodeTypes = {
73
+ MpcErrors: Array.from({ length: 100 }, (_, i) => i + 100),
74
+ NetworkErrors: Array.from({ length: 100 }, (_, i) => i + 200),
75
+ GeneralErrors: Array.from({ length: 100 }, (_, i) => i + 300),
76
+ EncryptDecryptErrors: Array.from({ length: 100 }, (_, i) => i + 400),
77
+ }
78
+
79
+ export class PortalMpcError extends Error {
80
+ code: PortalErrorCodes
81
+
82
+ public constructor(error: PortalError) {
83
+ super(error.message)
84
+
85
+ this.code = error.code
86
+ }
87
+ }
@@ -0,0 +1,9 @@
1
+ enum Events {
2
+ PortalInitialized = 'Portal Initialized',
3
+ TransactionSigned = 'Transaction Signed',
4
+ WalletBackedUp = 'Wallet Backed Up',
5
+ WalletCreated = 'Wallet Created',
6
+ WalletRecovered = 'Wallet Recovered',
7
+ }
8
+
9
+ export default Events
package/src/index.ts CHANGED
@@ -10,10 +10,16 @@ export {
10
10
  MissingOptionError,
11
11
  MpcSigningError,
12
12
  NoAddressError,
13
+ PortalError,
14
+ PortalErrorCodes,
15
+ PortalErrorCodeTypes,
16
+ PortalMpcError,
13
17
  ProviderRpcError,
14
18
  RpcErrorCodes,
15
19
  } from './errors'
16
20
 
21
+ export { default as Events } from './events'
22
+
17
23
  export { parseRequest } from './eth-requests'
18
24
 
19
25
  export { default as HttpRequest } from './http-request'