@portal-hq/utils 5.0.0 → 5.1.0
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/config/index.js +1 -0
- package/lib/commonjs/credentials/index.js +4 -2
- package/lib/commonjs/errors/http-error.js +27 -0
- package/lib/commonjs/errors/index.js +7 -1
- package/lib/commonjs/errors/portal-policy-error.js +83 -0
- package/lib/commonjs/events/index.js +29 -0
- package/lib/commonjs/index.js +6 -1
- package/lib/commonjs/version/version.json +1 -1
- package/lib/esm/config/index.js +1 -0
- package/lib/esm/credentials/index.js +5 -3
- package/lib/esm/errors/http-error.js +27 -0
- package/lib/esm/errors/index.js +1 -0
- package/lib/esm/errors/portal-policy-error.js +77 -0
- package/lib/esm/events/index.js +29 -0
- package/lib/esm/index.js +1 -1
- package/lib/esm/version/version.json +1 -1
- package/package.json +2 -2
- package/src/config/index.ts +1 -0
- package/src/credentials/index.ts +5 -3
- package/src/errors/http-error.ts +40 -1
- package/src/errors/index.ts +7 -0
- package/src/errors/portal-policy-error.ts +97 -0
- package/src/events/index.ts +30 -0
- package/src/index.ts +5 -0
- package/src/version/version.json +1 -1
- package/types.d.ts +26 -11
|
@@ -20,6 +20,7 @@ exports.SUPPORTED_CHAINS = [
|
|
|
20
20
|
{ namespace: 'eip155', reference: '84532' },
|
|
21
21
|
{ namespace: 'eip155', reference: '143' },
|
|
22
22
|
{ namespace: 'eip155', reference: '10143' },
|
|
23
|
+
{ namespace: 'eip155', reference: '42161' },
|
|
23
24
|
{ namespace: 'solana', reference: '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' },
|
|
24
25
|
{ namespace: 'solana', reference: 'EtWTRABZaYq6iMfeYKouRu166VU2xqa1' },
|
|
25
26
|
];
|
|
@@ -226,7 +226,9 @@ exports.reportUnauthorized = reportUnauthorized;
|
|
|
226
226
|
* envelope rather than a status code any requester here can see.
|
|
227
227
|
*
|
|
228
228
|
* The binary's error is rethrown unchanged either way — the invalidation is
|
|
229
|
-
* bookkeeping, and callers keep branching on `PortalMpcError` and its `id`.
|
|
229
|
+
* bookkeeping, and callers keep branching on `PortalMpcError` and its `id`. A
|
|
230
|
+
* Policy Engine rejection is promoted to `PortalPolicyError`, a subclass, so
|
|
231
|
+
* that stays true.
|
|
230
232
|
*/
|
|
231
233
|
function failFromMpcError(credentials, error) {
|
|
232
234
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -238,7 +240,7 @@ function failFromMpcError(credentials, error) {
|
|
|
238
240
|
logger_1.sdkLogger.error('[Portal] Failed to invalidate a credential the MPC binary rejected', bookkeeping);
|
|
239
241
|
}
|
|
240
242
|
}
|
|
241
|
-
throw
|
|
243
|
+
throw (0, errors_1.mpcErrorFrom)(error);
|
|
242
244
|
});
|
|
243
245
|
}
|
|
244
246
|
exports.failFromMpcError = failFromMpcError;
|
|
@@ -6,6 +6,33 @@ class HttpError extends Error {
|
|
|
6
6
|
// Set the prototype explicitly.
|
|
7
7
|
Object.setPrototypeOf(this, HttpError.prototype);
|
|
8
8
|
this.status = status;
|
|
9
|
+
const body = parseJsonBody(message);
|
|
10
|
+
if (!isJsonObject(body)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (typeof body.error === 'string') {
|
|
14
|
+
this.errorMessage = body.error;
|
|
15
|
+
}
|
|
16
|
+
if (typeof body.id === 'string') {
|
|
17
|
+
this.id = body.id;
|
|
18
|
+
}
|
|
19
|
+
if (isJsonObject(body.details)) {
|
|
20
|
+
this.details = body.details;
|
|
21
|
+
}
|
|
9
22
|
}
|
|
10
23
|
}
|
|
24
|
+
function parseJsonBody(responseText) {
|
|
25
|
+
if (responseText.trim() === '') {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(responseText);
|
|
30
|
+
}
|
|
31
|
+
catch (_a) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function isJsonObject(value) {
|
|
36
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
37
|
+
}
|
|
11
38
|
exports.default = HttpError;
|
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.RpcErrorCodes = exports.ProviderRpcError = exports.PortalCredentialErrorReason = exports.PortalCredentialError = exports.PortalAuthErrorReason = exports.PortalAuthError = exports.NoAddressError = exports.MpcSigningError = exports.MissingOptionError = exports.InvalidGatewayConfigError = exports.InvalidChainIdError = exports.InvalidApiKeyError = exports.HttpError = exports.CloudStorageReadError = void 0;
|
|
20
|
+
exports.RpcErrorCodes = exports.ProviderRpcError = exports.mpcErrorFrom = exports.isPolicyViolation = exports.PolicyErrorId = exports.POLICY_ERROR_ID_PREFIX = exports.PortalPolicyError = exports.PortalCredentialErrorReason = exports.PortalCredentialError = exports.PortalAuthErrorReason = exports.PortalAuthError = exports.NoAddressError = exports.MpcSigningError = exports.MissingOptionError = exports.InvalidGatewayConfigError = exports.InvalidChainIdError = exports.InvalidApiKeyError = exports.HttpError = exports.CloudStorageReadError = void 0;
|
|
21
21
|
var cloud_storage_read_error_1 = require("./cloud-storage-read-error");
|
|
22
22
|
Object.defineProperty(exports, "CloudStorageReadError", { enumerable: true, get: function () { return __importDefault(cloud_storage_read_error_1).default; } });
|
|
23
23
|
var http_error_1 = require("./http-error");
|
|
@@ -41,6 +41,12 @@ var portal_credential_error_1 = require("./portal-credential-error");
|
|
|
41
41
|
Object.defineProperty(exports, "PortalCredentialError", { enumerable: true, get: function () { return __importDefault(portal_credential_error_1).default; } });
|
|
42
42
|
Object.defineProperty(exports, "PortalCredentialErrorReason", { enumerable: true, get: function () { return portal_credential_error_1.PortalCredentialErrorReason; } });
|
|
43
43
|
__exportStar(require("./portal-error"), exports);
|
|
44
|
+
var portal_policy_error_1 = require("./portal-policy-error");
|
|
45
|
+
Object.defineProperty(exports, "PortalPolicyError", { enumerable: true, get: function () { return __importDefault(portal_policy_error_1).default; } });
|
|
46
|
+
Object.defineProperty(exports, "POLICY_ERROR_ID_PREFIX", { enumerable: true, get: function () { return portal_policy_error_1.POLICY_ERROR_ID_PREFIX; } });
|
|
47
|
+
Object.defineProperty(exports, "PolicyErrorId", { enumerable: true, get: function () { return portal_policy_error_1.PolicyErrorId; } });
|
|
48
|
+
Object.defineProperty(exports, "isPolicyViolation", { enumerable: true, get: function () { return portal_policy_error_1.isPolicyViolation; } });
|
|
49
|
+
Object.defineProperty(exports, "mpcErrorFrom", { enumerable: true, get: function () { return portal_policy_error_1.mpcErrorFrom; } });
|
|
44
50
|
var provider_rpc_error_1 = require("./provider-rpc-error");
|
|
45
51
|
Object.defineProperty(exports, "ProviderRpcError", { enumerable: true, get: function () { return __importDefault(provider_rpc_error_1).default; } });
|
|
46
52
|
Object.defineProperty(exports, "RpcErrorCodes", { enumerable: true, get: function () { return provider_rpc_error_1.RpcErrorCodes; } });
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.mpcErrorFrom = exports.PortalPolicyError = exports.isPolicyViolation = exports.PolicyErrorId = exports.POLICY_ERROR_ID_PREFIX = void 0;
|
|
5
|
+
const portal_error_1 = require("./portal-error");
|
|
6
|
+
/**
|
|
7
|
+
* Every Policy Engine rejection the gateway emits carries an ID under this
|
|
8
|
+
* prefix. Classification is by prefix, not by a known-ID list, so a policy kind
|
|
9
|
+
* added to the gateway later is still recognised without an SDK release.
|
|
10
|
+
*/
|
|
11
|
+
exports.POLICY_ERROR_ID_PREFIX = 'POLICY_';
|
|
12
|
+
/** The policy IDs the gateway emits today. The set is open — see the prefix. */
|
|
13
|
+
exports.PolicyErrorId = {
|
|
14
|
+
AmountLimitExceeded: 'POLICY_AMOUNT_LIMIT_EXCEEDED',
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Whether an error reports a Policy Engine rejection.
|
|
18
|
+
*
|
|
19
|
+
* Accepts a raw error envelope or a thrown {@link PortalMpcError}. Matched on
|
|
20
|
+
* the ID, never the companion `code` — the binary maps policy IDs onto a
|
|
21
|
+
* generic legacy code — and never on the message text.
|
|
22
|
+
*/
|
|
23
|
+
const isPolicyViolation = (error) => {
|
|
24
|
+
if (typeof error !== 'object' || error === null) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const { id } = error;
|
|
28
|
+
return typeof id === 'string' && id.startsWith(exports.POLICY_ERROR_ID_PREFIX);
|
|
29
|
+
};
|
|
30
|
+
exports.isPolicyViolation = isPolicyViolation;
|
|
31
|
+
/**
|
|
32
|
+
* Cross-copy brand. `instanceof` compares prototypes, so it returns `false`
|
|
33
|
+
* when a consumer's tree resolves two `@portal-hq/utils` — a real policy
|
|
34
|
+
* rejection would then silently degrade to an ordinary MPC failure.
|
|
35
|
+
*
|
|
36
|
+
* This key and the members {@link PortalPolicyError.is} implies are a
|
|
37
|
+
* compatibility contract: changing either breaks recognition between copies.
|
|
38
|
+
*/
|
|
39
|
+
const BRAND = Symbol.for('@portal-hq/utils/PortalPolicyError');
|
|
40
|
+
/**
|
|
41
|
+
* A transaction the Policy Engine refused to sign. Extends
|
|
42
|
+
* {@link PortalMpcError} so callers already branching on that type, or reading
|
|
43
|
+
* its `id`, keep working unchanged. `id` always carries the `POLICY_*`
|
|
44
|
+
* identifier here, even though the inherited type leaves it optional.
|
|
45
|
+
*
|
|
46
|
+
* The rejection is terminal: the same request will be refused again, so it is
|
|
47
|
+
* not retried and it never invalidates the credential — the session is fine,
|
|
48
|
+
* the transaction is not.
|
|
49
|
+
*/
|
|
50
|
+
class PortalPolicyError extends portal_error_1.PortalMpcError {
|
|
51
|
+
constructor(error, cause) {
|
|
52
|
+
super(error);
|
|
53
|
+
/** @internal Cross-copy brand. Read it through {@link PortalPolicyError.is}. */
|
|
54
|
+
this[_a] = true;
|
|
55
|
+
Object.setPrototypeOf(this, PortalPolicyError.prototype);
|
|
56
|
+
this.cause = cause;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Brand check — see BRAND. Narrowing a branded error from another copy to
|
|
60
|
+
* this class is intentional.
|
|
61
|
+
*/
|
|
62
|
+
static is(error) {
|
|
63
|
+
return (typeof error === 'object' &&
|
|
64
|
+
error !== null &&
|
|
65
|
+
error[BRAND] === true);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.PortalPolicyError = PortalPolicyError;
|
|
69
|
+
_a = BRAND;
|
|
70
|
+
/**
|
|
71
|
+
* Builds the error for an MPC envelope, promoting a Policy Engine rejection to
|
|
72
|
+
* {@link PortalPolicyError}. Every other envelope stays a {@link PortalMpcError},
|
|
73
|
+
* so only the policy path changes shape.
|
|
74
|
+
*
|
|
75
|
+
* @internal Exported only so the provider packages can share it across the
|
|
76
|
+
* package boundary. Not part of the public API — catch {@link PortalPolicyError}
|
|
77
|
+
* or call {@link isPolicyViolation} instead.
|
|
78
|
+
*/
|
|
79
|
+
const mpcErrorFrom = (error, cause) => (0, exports.isPolicyViolation)(error)
|
|
80
|
+
? new PortalPolicyError(error, cause)
|
|
81
|
+
: new portal_error_1.PortalMpcError(error);
|
|
82
|
+
exports.mpcErrorFrom = mpcErrorFrom;
|
|
83
|
+
exports.default = PortalPolicyError;
|
|
@@ -35,6 +35,18 @@ var Events;
|
|
|
35
35
|
Events["YieldXyzGetHistoricalActions"] = "YieldXyz Get Historical Actions";
|
|
36
36
|
Events["YieldXyzGetTransaction"] = "YieldXyz Get Transaction";
|
|
37
37
|
Events["YieldXyzTrack"] = "YieldXyz Track";
|
|
38
|
+
Events["YieldXyzBorrowGetIntegrations"] = "YieldXyz Borrow Get Integrations";
|
|
39
|
+
Events["YieldXyzBorrowGetIntegration"] = "YieldXyz Borrow Get Integration";
|
|
40
|
+
Events["YieldXyzBorrowGetMarkets"] = "YieldXyz Borrow Get Markets";
|
|
41
|
+
Events["YieldXyzBorrowGetMarket"] = "YieldXyz Borrow Get Market";
|
|
42
|
+
Events["YieldXyzBorrowGetPositions"] = "YieldXyz Borrow Get Positions";
|
|
43
|
+
Events["YieldXyzBorrowGetLiquidations"] = "YieldXyz Borrow Get Liquidations";
|
|
44
|
+
Events["YieldXyzBorrowCreateAction"] = "YieldXyz Borrow Create Action";
|
|
45
|
+
Events["YieldXyzBorrowGetActions"] = "YieldXyz Borrow Get Actions";
|
|
46
|
+
Events["YieldXyzBorrowGetAction"] = "YieldXyz Borrow Get Action";
|
|
47
|
+
Events["YieldXyzBorrowStepAction"] = "YieldXyz Borrow Step Action";
|
|
48
|
+
Events["YieldXyzBorrowSubmitTransaction"] = "YieldXyz Borrow Submit Transaction";
|
|
49
|
+
Events["YieldXyzBorrowGetHealth"] = "YieldXyz Borrow Get Health";
|
|
38
50
|
Events["LifiGetRoutes"] = "Lifi Get Routes";
|
|
39
51
|
Events["LifiGetQuote"] = "Lifi Get Quote";
|
|
40
52
|
Events["LifiGetStatus"] = "Lifi Get Status";
|
|
@@ -89,5 +101,22 @@ var Events;
|
|
|
89
101
|
Events["MeldGetBuyLimits"] = "Meld Get Buy Limits";
|
|
90
102
|
Events["MeldGetSellLimits"] = "Meld Get Sell Limits";
|
|
91
103
|
Events["MeldGetKycLimits"] = "Meld Get Kyc Limits";
|
|
104
|
+
Events["YieldXyzPerpsGetProviders"] = "YieldXyz Perps Get Providers";
|
|
105
|
+
Events["YieldXyzPerpsGetProvider"] = "YieldXyz Perps Get Provider";
|
|
106
|
+
Events["YieldXyzPerpsGetMarkets"] = "YieldXyz Perps Get Markets";
|
|
107
|
+
Events["YieldXyzPerpsGetMarket"] = "YieldXyz Perps Get Market";
|
|
108
|
+
Events["YieldXyzPerpsGetMarketCandles"] = "YieldXyz Perps Get Market Candles";
|
|
109
|
+
Events["YieldXyzPerpsGetPositions"] = "YieldXyz Perps Get Positions";
|
|
110
|
+
Events["YieldXyzPerpsGetOrders"] = "YieldXyz Perps Get Orders";
|
|
111
|
+
Events["YieldXyzPerpsGetBalances"] = "YieldXyz Perps Get Balances";
|
|
112
|
+
Events["YieldXyzPerpsCreateAction"] = "YieldXyz Perps Create Action";
|
|
113
|
+
Events["YieldXyzPerpsGetActions"] = "YieldXyz Perps Get Actions";
|
|
114
|
+
Events["YieldXyzPerpsGetAction"] = "YieldXyz Perps Get Action";
|
|
115
|
+
Events["YieldXyzPerpsSubmitTransaction"] = "YieldXyz Perps Submit Transaction";
|
|
116
|
+
Events["YieldXyzPerpsGetActivity"] = "YieldXyz Perps Get Activity";
|
|
117
|
+
Events["YieldXyzPerpsGetEvents"] = "YieldXyz Perps Get Events";
|
|
118
|
+
Events["YieldXyzPerpsGetEvent"] = "YieldXyz Perps Get Event";
|
|
119
|
+
Events["YieldXyzPerpsGetHealth"] = "YieldXyz Perps Get Health";
|
|
120
|
+
Events["YieldXyzPerpsGetProvidersHealth"] = "YieldXyz Perps Get Providers Health";
|
|
92
121
|
})(Events || (Events = {}));
|
|
93
122
|
exports.default = Events;
|
package/lib/commonjs/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.PortalMpcError = exports.PortalErrorCodeTypes = exports.PortalErrorCodes = exports.MPC_AUTH_FAILED_ERROR_ID = exports.PortalCredentialErrorReason = exports.PortalCredentialError = exports.PortalAuthErrorReason = exports.PortalAuthError = exports.NoAddressError = exports.MpcSigningError = exports.MissingOptionError = exports.InvalidGatewayConfigError = exports.InvalidChainIdError = exports.InvalidApiKeyError = exports.HttpError = exports.CloudStorageReadError = exports.Storage = exports.PortalRequestMethod = exports.PasswordStorage = exports.MpcStatuses = exports.KeychainAdapter = exports.convert = exports.convertCryptoToLocal = exports.convertLocalToCrypto = exports.staticApiKeyOf = exports.resolveCredentialToken = exports.resolveCredentials = exports.reportUnauthorized = exports.onCredentialsInvalidated = exports.invalidateCredentials = exports.failFromMpcError = exports.StaticCredentials = exports.DEFAULT_HOSTS = exports.buildDefaultGatewayConfig = exports.NAMESPACE_TO_CURVE = exports.ALL_CHAIN_IDS = exports.BITCOIN_CHAIN_IDS = exports.TRON_CHAIN_IDS = exports.SOLANA_CHAIN_IDS = exports.EVM_CHAIN_IDS = exports.DEFAULT_CHAIN_ID_CAIP2 = exports.DEFAULT_CHAIN_ID_NUMERIC = exports.CAIP2_CHAIN_ID_REGEX = exports.FRIENDLY_CHAIN_NAME_TO_CAIP2 = exports.SUPPORTED_BITCOIN_P2WPKH_CHAINS = exports.CHAIN_NAMESPACES = exports.getChainNameForId = exports.getChainIdForName = exports.chainNameToId = exports.chainIdToName = void 0;
|
|
7
|
-
exports.sdkLogger = exports.UUID_V4_REGEX = exports.TRACE_ID_HEADER = exports.createExecutionContext = exports.generateTraceId = exports.EvaluateTransactionOperationType = exports.HttpRequester = exports.PortalRequests = exports.HttpRequest = exports.parseRequest = exports.numberToHexString = exports.getClientPlatformVersion = exports.Events = exports.RpcErrorCodes = exports.ProviderRpcError = exports.isMpcAuthFailure = void 0;
|
|
7
|
+
exports.sdkLogger = exports.UUID_V4_REGEX = exports.TRACE_ID_HEADER = exports.createExecutionContext = exports.generateTraceId = exports.EvaluateTransactionOperationType = exports.HttpRequester = exports.PortalRequests = exports.HttpRequest = exports.parseRequest = exports.numberToHexString = exports.getClientPlatformVersion = exports.Events = exports.RpcErrorCodes = exports.ProviderRpcError = exports.mpcErrorFrom = exports.isPolicyViolation = exports.isMpcAuthFailure = exports.PolicyErrorId = exports.POLICY_ERROR_ID_PREFIX = exports.PortalPolicyError = void 0;
|
|
8
8
|
var chains_1 = require("./chains");
|
|
9
9
|
Object.defineProperty(exports, "chainIdToName", { enumerable: true, get: function () { return chains_1.chainIdToName; } });
|
|
10
10
|
Object.defineProperty(exports, "chainNameToId", { enumerable: true, get: function () { return chains_1.chainNameToId; } });
|
|
@@ -61,7 +61,12 @@ Object.defineProperty(exports, "MPC_AUTH_FAILED_ERROR_ID", { enumerable: true, g
|
|
|
61
61
|
Object.defineProperty(exports, "PortalErrorCodes", { enumerable: true, get: function () { return errors_1.PortalErrorCodes; } });
|
|
62
62
|
Object.defineProperty(exports, "PortalErrorCodeTypes", { enumerable: true, get: function () { return errors_1.PortalErrorCodeTypes; } });
|
|
63
63
|
Object.defineProperty(exports, "PortalMpcError", { enumerable: true, get: function () { return errors_1.PortalMpcError; } });
|
|
64
|
+
Object.defineProperty(exports, "PortalPolicyError", { enumerable: true, get: function () { return errors_1.PortalPolicyError; } });
|
|
65
|
+
Object.defineProperty(exports, "POLICY_ERROR_ID_PREFIX", { enumerable: true, get: function () { return errors_1.POLICY_ERROR_ID_PREFIX; } });
|
|
66
|
+
Object.defineProperty(exports, "PolicyErrorId", { enumerable: true, get: function () { return errors_1.PolicyErrorId; } });
|
|
64
67
|
Object.defineProperty(exports, "isMpcAuthFailure", { enumerable: true, get: function () { return errors_1.isMpcAuthFailure; } });
|
|
68
|
+
Object.defineProperty(exports, "isPolicyViolation", { enumerable: true, get: function () { return errors_1.isPolicyViolation; } });
|
|
69
|
+
Object.defineProperty(exports, "mpcErrorFrom", { enumerable: true, get: function () { return errors_1.mpcErrorFrom; } });
|
|
65
70
|
Object.defineProperty(exports, "ProviderRpcError", { enumerable: true, get: function () { return errors_1.ProviderRpcError; } });
|
|
66
71
|
Object.defineProperty(exports, "RpcErrorCodes", { enumerable: true, get: function () { return errors_1.RpcErrorCodes; } });
|
|
67
72
|
var events_1 = require("./events");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "version": "5.
|
|
1
|
+
{ "version": "5.1.0" }
|
package/lib/esm/config/index.js
CHANGED
|
@@ -17,6 +17,7 @@ export const SUPPORTED_CHAINS = [
|
|
|
17
17
|
{ namespace: 'eip155', reference: '84532' },
|
|
18
18
|
{ namespace: 'eip155', reference: '143' },
|
|
19
19
|
{ namespace: 'eip155', reference: '10143' },
|
|
20
|
+
{ namespace: 'eip155', reference: '42161' },
|
|
20
21
|
{ namespace: 'solana', reference: '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' },
|
|
21
22
|
{ namespace: 'solana', reference: 'EtWTRABZaYq6iMfeYKouRu166VU2xqa1' },
|
|
22
23
|
];
|
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
var _a;
|
|
11
|
-
import { InvalidApiKeyError, PortalCredentialError, PortalCredentialErrorReason,
|
|
11
|
+
import { InvalidApiKeyError, PortalCredentialError, PortalCredentialErrorReason, isMpcAuthFailure, mpcErrorFrom, } from '../errors';
|
|
12
12
|
import { sdkLogger } from '../logger';
|
|
13
13
|
/**
|
|
14
14
|
* Cross-copy brand. The key and the branded shape (a string `value`) are a
|
|
@@ -217,7 +217,9 @@ export function reportUnauthorized(credentials) {
|
|
|
217
217
|
* envelope rather than a status code any requester here can see.
|
|
218
218
|
*
|
|
219
219
|
* The binary's error is rethrown unchanged either way — the invalidation is
|
|
220
|
-
* bookkeeping, and callers keep branching on `PortalMpcError` and its `id`.
|
|
220
|
+
* bookkeeping, and callers keep branching on `PortalMpcError` and its `id`. A
|
|
221
|
+
* Policy Engine rejection is promoted to `PortalPolicyError`, a subclass, so
|
|
222
|
+
* that stays true.
|
|
221
223
|
*/
|
|
222
224
|
export function failFromMpcError(credentials, error) {
|
|
223
225
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -229,7 +231,7 @@ export function failFromMpcError(credentials, error) {
|
|
|
229
231
|
sdkLogger.error('[Portal] Failed to invalidate a credential the MPC binary rejected', bookkeeping);
|
|
230
232
|
}
|
|
231
233
|
}
|
|
232
|
-
throw
|
|
234
|
+
throw mpcErrorFrom(error);
|
|
233
235
|
});
|
|
234
236
|
}
|
|
235
237
|
/**
|
|
@@ -4,6 +4,33 @@ class HttpError extends Error {
|
|
|
4
4
|
// Set the prototype explicitly.
|
|
5
5
|
Object.setPrototypeOf(this, HttpError.prototype);
|
|
6
6
|
this.status = status;
|
|
7
|
+
const body = parseJsonBody(message);
|
|
8
|
+
if (!isJsonObject(body)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (typeof body.error === 'string') {
|
|
12
|
+
this.errorMessage = body.error;
|
|
13
|
+
}
|
|
14
|
+
if (typeof body.id === 'string') {
|
|
15
|
+
this.id = body.id;
|
|
16
|
+
}
|
|
17
|
+
if (isJsonObject(body.details)) {
|
|
18
|
+
this.details = body.details;
|
|
19
|
+
}
|
|
7
20
|
}
|
|
8
21
|
}
|
|
22
|
+
function parseJsonBody(responseText) {
|
|
23
|
+
if (responseText.trim() === '') {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(responseText);
|
|
28
|
+
}
|
|
29
|
+
catch (_a) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function isJsonObject(value) {
|
|
34
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
35
|
+
}
|
|
9
36
|
export default HttpError;
|
package/lib/esm/errors/index.js
CHANGED
|
@@ -9,4 +9,5 @@ export { default as NoAddressError } from './no-address-error';
|
|
|
9
9
|
export { default as PortalAuthError, PortalAuthErrorReason, } from './portal-auth-error';
|
|
10
10
|
export { default as PortalCredentialError, PortalCredentialErrorReason, } from './portal-credential-error';
|
|
11
11
|
export * from './portal-error';
|
|
12
|
+
export { default as PortalPolicyError, POLICY_ERROR_ID_PREFIX, PolicyErrorId, isPolicyViolation, mpcErrorFrom, } from './portal-policy-error';
|
|
12
13
|
export { default as ProviderRpcError, RpcErrorCodes, } from './provider-rpc-error';
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { PortalMpcError } from './portal-error';
|
|
3
|
+
/**
|
|
4
|
+
* Every Policy Engine rejection the gateway emits carries an ID under this
|
|
5
|
+
* prefix. Classification is by prefix, not by a known-ID list, so a policy kind
|
|
6
|
+
* added to the gateway later is still recognised without an SDK release.
|
|
7
|
+
*/
|
|
8
|
+
export const POLICY_ERROR_ID_PREFIX = 'POLICY_';
|
|
9
|
+
/** The policy IDs the gateway emits today. The set is open — see the prefix. */
|
|
10
|
+
export const PolicyErrorId = {
|
|
11
|
+
AmountLimitExceeded: 'POLICY_AMOUNT_LIMIT_EXCEEDED',
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Whether an error reports a Policy Engine rejection.
|
|
15
|
+
*
|
|
16
|
+
* Accepts a raw error envelope or a thrown {@link PortalMpcError}. Matched on
|
|
17
|
+
* the ID, never the companion `code` — the binary maps policy IDs onto a
|
|
18
|
+
* generic legacy code — and never on the message text.
|
|
19
|
+
*/
|
|
20
|
+
export const isPolicyViolation = (error) => {
|
|
21
|
+
if (typeof error !== 'object' || error === null) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const { id } = error;
|
|
25
|
+
return typeof id === 'string' && id.startsWith(POLICY_ERROR_ID_PREFIX);
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Cross-copy brand. `instanceof` compares prototypes, so it returns `false`
|
|
29
|
+
* when a consumer's tree resolves two `@portal-hq/utils` — a real policy
|
|
30
|
+
* rejection would then silently degrade to an ordinary MPC failure.
|
|
31
|
+
*
|
|
32
|
+
* This key and the members {@link PortalPolicyError.is} implies are a
|
|
33
|
+
* compatibility contract: changing either breaks recognition between copies.
|
|
34
|
+
*/
|
|
35
|
+
const BRAND = Symbol.for('@portal-hq/utils/PortalPolicyError');
|
|
36
|
+
/**
|
|
37
|
+
* A transaction the Policy Engine refused to sign. Extends
|
|
38
|
+
* {@link PortalMpcError} so callers already branching on that type, or reading
|
|
39
|
+
* its `id`, keep working unchanged. `id` always carries the `POLICY_*`
|
|
40
|
+
* identifier here, even though the inherited type leaves it optional.
|
|
41
|
+
*
|
|
42
|
+
* The rejection is terminal: the same request will be refused again, so it is
|
|
43
|
+
* not retried and it never invalidates the credential — the session is fine,
|
|
44
|
+
* the transaction is not.
|
|
45
|
+
*/
|
|
46
|
+
export class PortalPolicyError extends PortalMpcError {
|
|
47
|
+
constructor(error, cause) {
|
|
48
|
+
super(error);
|
|
49
|
+
/** @internal Cross-copy brand. Read it through {@link PortalPolicyError.is}. */
|
|
50
|
+
this[_a] = true;
|
|
51
|
+
Object.setPrototypeOf(this, PortalPolicyError.prototype);
|
|
52
|
+
this.cause = cause;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Brand check — see BRAND. Narrowing a branded error from another copy to
|
|
56
|
+
* this class is intentional.
|
|
57
|
+
*/
|
|
58
|
+
static is(error) {
|
|
59
|
+
return (typeof error === 'object' &&
|
|
60
|
+
error !== null &&
|
|
61
|
+
error[BRAND] === true);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
_a = BRAND;
|
|
65
|
+
/**
|
|
66
|
+
* Builds the error for an MPC envelope, promoting a Policy Engine rejection to
|
|
67
|
+
* {@link PortalPolicyError}. Every other envelope stays a {@link PortalMpcError},
|
|
68
|
+
* so only the policy path changes shape.
|
|
69
|
+
*
|
|
70
|
+
* @internal Exported only so the provider packages can share it across the
|
|
71
|
+
* package boundary. Not part of the public API — catch {@link PortalPolicyError}
|
|
72
|
+
* or call {@link isPolicyViolation} instead.
|
|
73
|
+
*/
|
|
74
|
+
export const mpcErrorFrom = (error, cause) => isPolicyViolation(error)
|
|
75
|
+
? new PortalPolicyError(error, cause)
|
|
76
|
+
: new PortalMpcError(error);
|
|
77
|
+
export default PortalPolicyError;
|
package/lib/esm/events/index.js
CHANGED
|
@@ -33,6 +33,18 @@ var Events;
|
|
|
33
33
|
Events["YieldXyzGetHistoricalActions"] = "YieldXyz Get Historical Actions";
|
|
34
34
|
Events["YieldXyzGetTransaction"] = "YieldXyz Get Transaction";
|
|
35
35
|
Events["YieldXyzTrack"] = "YieldXyz Track";
|
|
36
|
+
Events["YieldXyzBorrowGetIntegrations"] = "YieldXyz Borrow Get Integrations";
|
|
37
|
+
Events["YieldXyzBorrowGetIntegration"] = "YieldXyz Borrow Get Integration";
|
|
38
|
+
Events["YieldXyzBorrowGetMarkets"] = "YieldXyz Borrow Get Markets";
|
|
39
|
+
Events["YieldXyzBorrowGetMarket"] = "YieldXyz Borrow Get Market";
|
|
40
|
+
Events["YieldXyzBorrowGetPositions"] = "YieldXyz Borrow Get Positions";
|
|
41
|
+
Events["YieldXyzBorrowGetLiquidations"] = "YieldXyz Borrow Get Liquidations";
|
|
42
|
+
Events["YieldXyzBorrowCreateAction"] = "YieldXyz Borrow Create Action";
|
|
43
|
+
Events["YieldXyzBorrowGetActions"] = "YieldXyz Borrow Get Actions";
|
|
44
|
+
Events["YieldXyzBorrowGetAction"] = "YieldXyz Borrow Get Action";
|
|
45
|
+
Events["YieldXyzBorrowStepAction"] = "YieldXyz Borrow Step Action";
|
|
46
|
+
Events["YieldXyzBorrowSubmitTransaction"] = "YieldXyz Borrow Submit Transaction";
|
|
47
|
+
Events["YieldXyzBorrowGetHealth"] = "YieldXyz Borrow Get Health";
|
|
36
48
|
Events["LifiGetRoutes"] = "Lifi Get Routes";
|
|
37
49
|
Events["LifiGetQuote"] = "Lifi Get Quote";
|
|
38
50
|
Events["LifiGetStatus"] = "Lifi Get Status";
|
|
@@ -87,5 +99,22 @@ var Events;
|
|
|
87
99
|
Events["MeldGetBuyLimits"] = "Meld Get Buy Limits";
|
|
88
100
|
Events["MeldGetSellLimits"] = "Meld Get Sell Limits";
|
|
89
101
|
Events["MeldGetKycLimits"] = "Meld Get Kyc Limits";
|
|
102
|
+
Events["YieldXyzPerpsGetProviders"] = "YieldXyz Perps Get Providers";
|
|
103
|
+
Events["YieldXyzPerpsGetProvider"] = "YieldXyz Perps Get Provider";
|
|
104
|
+
Events["YieldXyzPerpsGetMarkets"] = "YieldXyz Perps Get Markets";
|
|
105
|
+
Events["YieldXyzPerpsGetMarket"] = "YieldXyz Perps Get Market";
|
|
106
|
+
Events["YieldXyzPerpsGetMarketCandles"] = "YieldXyz Perps Get Market Candles";
|
|
107
|
+
Events["YieldXyzPerpsGetPositions"] = "YieldXyz Perps Get Positions";
|
|
108
|
+
Events["YieldXyzPerpsGetOrders"] = "YieldXyz Perps Get Orders";
|
|
109
|
+
Events["YieldXyzPerpsGetBalances"] = "YieldXyz Perps Get Balances";
|
|
110
|
+
Events["YieldXyzPerpsCreateAction"] = "YieldXyz Perps Create Action";
|
|
111
|
+
Events["YieldXyzPerpsGetActions"] = "YieldXyz Perps Get Actions";
|
|
112
|
+
Events["YieldXyzPerpsGetAction"] = "YieldXyz Perps Get Action";
|
|
113
|
+
Events["YieldXyzPerpsSubmitTransaction"] = "YieldXyz Perps Submit Transaction";
|
|
114
|
+
Events["YieldXyzPerpsGetActivity"] = "YieldXyz Perps Get Activity";
|
|
115
|
+
Events["YieldXyzPerpsGetEvents"] = "YieldXyz Perps Get Events";
|
|
116
|
+
Events["YieldXyzPerpsGetEvent"] = "YieldXyz Perps Get Event";
|
|
117
|
+
Events["YieldXyzPerpsGetHealth"] = "YieldXyz Perps Get Health";
|
|
118
|
+
Events["YieldXyzPerpsGetProvidersHealth"] = "YieldXyz Perps Get Providers Health";
|
|
90
119
|
})(Events || (Events = {}));
|
|
91
120
|
export default Events;
|
package/lib/esm/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { buildDefaultGatewayConfig, DEFAULT_HOSTS } from './config';
|
|
|
3
3
|
export { StaticCredentials, failFromMpcError, invalidateCredentials, onCredentialsInvalidated, reportUnauthorized, resolveCredentials, resolveCredentialToken, staticApiKeyOf, } from './credentials';
|
|
4
4
|
export { convertLocalToCrypto, convertCryptoToLocal, convert } from './currency';
|
|
5
5
|
export { KeychainAdapter, MpcStatuses, PasswordStorage, PortalRequestMethod, Storage, } from './definitions';
|
|
6
|
-
export { CloudStorageReadError, HttpError, InvalidApiKeyError, InvalidChainIdError, InvalidGatewayConfigError, MissingOptionError, MpcSigningError, NoAddressError, PortalAuthError, PortalAuthErrorReason, PortalCredentialError, PortalCredentialErrorReason, MPC_AUTH_FAILED_ERROR_ID, PortalErrorCodes, PortalErrorCodeTypes, PortalMpcError, isMpcAuthFailure, ProviderRpcError, RpcErrorCodes, } from './errors';
|
|
6
|
+
export { CloudStorageReadError, HttpError, InvalidApiKeyError, InvalidChainIdError, InvalidGatewayConfigError, MissingOptionError, MpcSigningError, NoAddressError, PortalAuthError, PortalAuthErrorReason, PortalCredentialError, PortalCredentialErrorReason, MPC_AUTH_FAILED_ERROR_ID, PortalErrorCodes, PortalErrorCodeTypes, PortalMpcError, PortalPolicyError, POLICY_ERROR_ID_PREFIX, PolicyErrorId, isMpcAuthFailure, isPolicyViolation, mpcErrorFrom, ProviderRpcError, RpcErrorCodes, } from './errors';
|
|
7
7
|
export { default as Events } from './events';
|
|
8
8
|
export { getClientPlatformVersion } from './version';
|
|
9
9
|
export { numberToHexString, parseRequest } from './eth-requests';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "version": "5.
|
|
1
|
+
{ "version": "5.1.0" }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portal-hq/utils",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0",
|
|
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": "354d4c662edfbed3dac786621e8ff351fe394ee8"
|
|
30
30
|
}
|
package/src/config/index.ts
CHANGED
|
@@ -21,6 +21,7 @@ export const SUPPORTED_CHAINS: ReadonlyArray<{
|
|
|
21
21
|
{ namespace: 'eip155', reference: '84532' },
|
|
22
22
|
{ namespace: 'eip155', reference: '143' },
|
|
23
23
|
{ namespace: 'eip155', reference: '10143' },
|
|
24
|
+
{ namespace: 'eip155', reference: '42161' },
|
|
24
25
|
{ namespace: 'solana', reference: '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' },
|
|
25
26
|
{ namespace: 'solana', reference: 'EtWTRABZaYq6iMfeYKouRu166VU2xqa1' },
|
|
26
27
|
]
|
package/src/credentials/index.ts
CHANGED
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
PortalCredentialError,
|
|
5
5
|
PortalCredentialErrorReason,
|
|
6
6
|
type PortalError,
|
|
7
|
-
PortalMpcError,
|
|
8
7
|
isMpcAuthFailure,
|
|
8
|
+
mpcErrorFrom,
|
|
9
9
|
} from '../errors'
|
|
10
10
|
import { sdkLogger } from '../logger'
|
|
11
11
|
|
|
@@ -268,7 +268,9 @@ export async function reportUnauthorized(
|
|
|
268
268
|
* envelope rather than a status code any requester here can see.
|
|
269
269
|
*
|
|
270
270
|
* The binary's error is rethrown unchanged either way — the invalidation is
|
|
271
|
-
* bookkeeping, and callers keep branching on `PortalMpcError` and its `id`.
|
|
271
|
+
* bookkeeping, and callers keep branching on `PortalMpcError` and its `id`. A
|
|
272
|
+
* Policy Engine rejection is promoted to `PortalPolicyError`, a subclass, so
|
|
273
|
+
* that stays true.
|
|
272
274
|
*/
|
|
273
275
|
export async function failFromMpcError(
|
|
274
276
|
credentials: PortalCredentials,
|
|
@@ -285,7 +287,7 @@ export async function failFromMpcError(
|
|
|
285
287
|
}
|
|
286
288
|
}
|
|
287
289
|
|
|
288
|
-
throw
|
|
290
|
+
throw mpcErrorFrom(error)
|
|
289
291
|
}
|
|
290
292
|
|
|
291
293
|
/**
|
package/src/errors/http-error.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type HttpErrorOptions,
|
|
3
|
+
type JsonObject,
|
|
4
|
+
type JsonValue,
|
|
5
|
+
} from '../../types'
|
|
2
6
|
|
|
3
7
|
class HttpError extends Error {
|
|
4
8
|
/** The HTTP status code that produced this error, so callers can distinguish retryable (5xx) from terminal (4xx) failures. */
|
|
5
9
|
public status: number
|
|
10
|
+
/** The Portal API error message (`error` in the response body), when present. */
|
|
11
|
+
public errorMessage?: string
|
|
12
|
+
/** The stable Portal API error identifier (`id` in the response body), when present. */
|
|
13
|
+
public id?: string
|
|
14
|
+
/** Structured error details (`details` in the response body), when present. */
|
|
15
|
+
public details?: JsonObject
|
|
6
16
|
|
|
7
17
|
constructor({ message, status, statusText }: HttpErrorOptions) {
|
|
8
18
|
super(`${status} - ${statusText}: ${message}`)
|
|
@@ -11,7 +21,36 @@ class HttpError extends Error {
|
|
|
11
21
|
Object.setPrototypeOf(this, HttpError.prototype)
|
|
12
22
|
|
|
13
23
|
this.status = status
|
|
24
|
+
|
|
25
|
+
const body = parseJsonBody(message)
|
|
26
|
+
if (!isJsonObject(body)) {
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
if (typeof body.error === 'string') {
|
|
30
|
+
this.errorMessage = body.error
|
|
31
|
+
}
|
|
32
|
+
if (typeof body.id === 'string') {
|
|
33
|
+
this.id = body.id
|
|
34
|
+
}
|
|
35
|
+
if (isJsonObject(body.details)) {
|
|
36
|
+
this.details = body.details
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function parseJsonBody(responseText: string): JsonValue | undefined {
|
|
42
|
+
if (responseText.trim() === '') {
|
|
43
|
+
return undefined
|
|
14
44
|
}
|
|
45
|
+
try {
|
|
46
|
+
return JSON.parse(responseText) as JsonValue
|
|
47
|
+
} catch {
|
|
48
|
+
return undefined
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isJsonObject(value: JsonValue | undefined): value is JsonObject {
|
|
53
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
15
54
|
}
|
|
16
55
|
|
|
17
56
|
export default HttpError
|
package/src/errors/index.ts
CHANGED
|
@@ -17,6 +17,13 @@ export {
|
|
|
17
17
|
type PortalCredentialErrorOptions,
|
|
18
18
|
} from './portal-credential-error'
|
|
19
19
|
export * from './portal-error'
|
|
20
|
+
export {
|
|
21
|
+
default as PortalPolicyError,
|
|
22
|
+
POLICY_ERROR_ID_PREFIX,
|
|
23
|
+
PolicyErrorId,
|
|
24
|
+
isPolicyViolation,
|
|
25
|
+
mpcErrorFrom,
|
|
26
|
+
} from './portal-policy-error'
|
|
20
27
|
export {
|
|
21
28
|
default as ProviderRpcError,
|
|
22
29
|
RpcErrorCodes,
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { type PortalError, PortalMpcError } from './portal-error'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Every Policy Engine rejection the gateway emits carries an ID under this
|
|
5
|
+
* prefix. Classification is by prefix, not by a known-ID list, so a policy kind
|
|
6
|
+
* added to the gateway later is still recognised without an SDK release.
|
|
7
|
+
*/
|
|
8
|
+
export const POLICY_ERROR_ID_PREFIX = 'POLICY_'
|
|
9
|
+
|
|
10
|
+
/** The policy IDs the gateway emits today. The set is open — see the prefix. */
|
|
11
|
+
export const PolicyErrorId = {
|
|
12
|
+
AmountLimitExceeded: 'POLICY_AMOUNT_LIMIT_EXCEEDED',
|
|
13
|
+
} as const
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Whether an error reports a Policy Engine rejection.
|
|
17
|
+
*
|
|
18
|
+
* Accepts a raw error envelope or a thrown {@link PortalMpcError}. Matched on
|
|
19
|
+
* the ID, never the companion `code` — the binary maps policy IDs onto a
|
|
20
|
+
* generic legacy code — and never on the message text.
|
|
21
|
+
*/
|
|
22
|
+
export const isPolicyViolation = (error: unknown): boolean => {
|
|
23
|
+
if (typeof error !== 'object' || error === null) {
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const { id } = error as { id?: unknown }
|
|
28
|
+
|
|
29
|
+
return typeof id === 'string' && id.startsWith(POLICY_ERROR_ID_PREFIX)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Cross-copy brand. `instanceof` compares prototypes, so it returns `false`
|
|
34
|
+
* when a consumer's tree resolves two `@portal-hq/utils` — a real policy
|
|
35
|
+
* rejection would then silently degrade to an ordinary MPC failure.
|
|
36
|
+
*
|
|
37
|
+
* This key and the members {@link PortalPolicyError.is} implies are a
|
|
38
|
+
* compatibility contract: changing either breaks recognition between copies.
|
|
39
|
+
*/
|
|
40
|
+
const BRAND: unique symbol = Symbol.for('@portal-hq/utils/PortalPolicyError')
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A transaction the Policy Engine refused to sign. Extends
|
|
44
|
+
* {@link PortalMpcError} so callers already branching on that type, or reading
|
|
45
|
+
* its `id`, keep working unchanged. `id` always carries the `POLICY_*`
|
|
46
|
+
* identifier here, even though the inherited type leaves it optional.
|
|
47
|
+
*
|
|
48
|
+
* The rejection is terminal: the same request will be refused again, so it is
|
|
49
|
+
* not retried and it never invalidates the credential — the session is fine,
|
|
50
|
+
* the transaction is not.
|
|
51
|
+
*/
|
|
52
|
+
export class PortalPolicyError extends PortalMpcError {
|
|
53
|
+
/** The underlying failure, when the rejection arrived wrapped in one. */
|
|
54
|
+
public readonly cause?: unknown
|
|
55
|
+
|
|
56
|
+
/** @internal Cross-copy brand. Read it through {@link PortalPolicyError.is}. */
|
|
57
|
+
public readonly [BRAND] = true
|
|
58
|
+
|
|
59
|
+
public constructor(error: PortalError, cause?: unknown) {
|
|
60
|
+
super(error)
|
|
61
|
+
|
|
62
|
+
Object.setPrototypeOf(this, PortalPolicyError.prototype)
|
|
63
|
+
|
|
64
|
+
this.cause = cause
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Brand check — see BRAND. Narrowing a branded error from another copy to
|
|
69
|
+
* this class is intentional.
|
|
70
|
+
*/
|
|
71
|
+
public static is(error: unknown): error is PortalPolicyError {
|
|
72
|
+
return (
|
|
73
|
+
typeof error === 'object' &&
|
|
74
|
+
error !== null &&
|
|
75
|
+
(error as { [BRAND]?: unknown })[BRAND] === true
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Builds the error for an MPC envelope, promoting a Policy Engine rejection to
|
|
82
|
+
* {@link PortalPolicyError}. Every other envelope stays a {@link PortalMpcError},
|
|
83
|
+
* so only the policy path changes shape.
|
|
84
|
+
*
|
|
85
|
+
* @internal Exported only so the provider packages can share it across the
|
|
86
|
+
* package boundary. Not part of the public API — catch {@link PortalPolicyError}
|
|
87
|
+
* or call {@link isPolicyViolation} instead.
|
|
88
|
+
*/
|
|
89
|
+
export const mpcErrorFrom = (
|
|
90
|
+
error: PortalError,
|
|
91
|
+
cause?: unknown,
|
|
92
|
+
): PortalMpcError =>
|
|
93
|
+
isPolicyViolation(error)
|
|
94
|
+
? new PortalPolicyError(error, cause)
|
|
95
|
+
: new PortalMpcError(error)
|
|
96
|
+
|
|
97
|
+
export default PortalPolicyError
|
package/src/events/index.ts
CHANGED
|
@@ -33,6 +33,18 @@ enum Events {
|
|
|
33
33
|
YieldXyzGetHistoricalActions = 'YieldXyz Get Historical Actions',
|
|
34
34
|
YieldXyzGetTransaction = 'YieldXyz Get Transaction',
|
|
35
35
|
YieldXyzTrack = 'YieldXyz Track',
|
|
36
|
+
YieldXyzBorrowGetIntegrations = 'YieldXyz Borrow Get Integrations',
|
|
37
|
+
YieldXyzBorrowGetIntegration = 'YieldXyz Borrow Get Integration',
|
|
38
|
+
YieldXyzBorrowGetMarkets = 'YieldXyz Borrow Get Markets',
|
|
39
|
+
YieldXyzBorrowGetMarket = 'YieldXyz Borrow Get Market',
|
|
40
|
+
YieldXyzBorrowGetPositions = 'YieldXyz Borrow Get Positions',
|
|
41
|
+
YieldXyzBorrowGetLiquidations = 'YieldXyz Borrow Get Liquidations',
|
|
42
|
+
YieldXyzBorrowCreateAction = 'YieldXyz Borrow Create Action',
|
|
43
|
+
YieldXyzBorrowGetActions = 'YieldXyz Borrow Get Actions',
|
|
44
|
+
YieldXyzBorrowGetAction = 'YieldXyz Borrow Get Action',
|
|
45
|
+
YieldXyzBorrowStepAction = 'YieldXyz Borrow Step Action',
|
|
46
|
+
YieldXyzBorrowSubmitTransaction = 'YieldXyz Borrow Submit Transaction',
|
|
47
|
+
YieldXyzBorrowGetHealth = 'YieldXyz Borrow Get Health',
|
|
36
48
|
LifiGetRoutes = 'Lifi Get Routes',
|
|
37
49
|
LifiGetQuote = 'Lifi Get Quote',
|
|
38
50
|
LifiGetStatus = 'Lifi Get Status',
|
|
@@ -95,6 +107,24 @@ enum Events {
|
|
|
95
107
|
MeldGetBuyLimits = 'Meld Get Buy Limits',
|
|
96
108
|
MeldGetSellLimits = 'Meld Get Sell Limits',
|
|
97
109
|
MeldGetKycLimits = 'Meld Get Kyc Limits',
|
|
110
|
+
|
|
111
|
+
YieldXyzPerpsGetProviders = 'YieldXyz Perps Get Providers',
|
|
112
|
+
YieldXyzPerpsGetProvider = 'YieldXyz Perps Get Provider',
|
|
113
|
+
YieldXyzPerpsGetMarkets = 'YieldXyz Perps Get Markets',
|
|
114
|
+
YieldXyzPerpsGetMarket = 'YieldXyz Perps Get Market',
|
|
115
|
+
YieldXyzPerpsGetMarketCandles = 'YieldXyz Perps Get Market Candles',
|
|
116
|
+
YieldXyzPerpsGetPositions = 'YieldXyz Perps Get Positions',
|
|
117
|
+
YieldXyzPerpsGetOrders = 'YieldXyz Perps Get Orders',
|
|
118
|
+
YieldXyzPerpsGetBalances = 'YieldXyz Perps Get Balances',
|
|
119
|
+
YieldXyzPerpsCreateAction = 'YieldXyz Perps Create Action',
|
|
120
|
+
YieldXyzPerpsGetActions = 'YieldXyz Perps Get Actions',
|
|
121
|
+
YieldXyzPerpsGetAction = 'YieldXyz Perps Get Action',
|
|
122
|
+
YieldXyzPerpsSubmitTransaction = 'YieldXyz Perps Submit Transaction',
|
|
123
|
+
YieldXyzPerpsGetActivity = 'YieldXyz Perps Get Activity',
|
|
124
|
+
YieldXyzPerpsGetEvents = 'YieldXyz Perps Get Events',
|
|
125
|
+
YieldXyzPerpsGetEvent = 'YieldXyz Perps Get Event',
|
|
126
|
+
YieldXyzPerpsGetHealth = 'YieldXyz Perps Get Health',
|
|
127
|
+
YieldXyzPerpsGetProvidersHealth = 'YieldXyz Perps Get Providers Health',
|
|
98
128
|
}
|
|
99
129
|
|
|
100
130
|
export default Events
|
package/src/index.ts
CHANGED
|
@@ -71,7 +71,12 @@ export {
|
|
|
71
71
|
PortalErrorCodes,
|
|
72
72
|
PortalErrorCodeTypes,
|
|
73
73
|
PortalMpcError,
|
|
74
|
+
PortalPolicyError,
|
|
75
|
+
POLICY_ERROR_ID_PREFIX,
|
|
76
|
+
PolicyErrorId,
|
|
74
77
|
isMpcAuthFailure,
|
|
78
|
+
isPolicyViolation,
|
|
79
|
+
mpcErrorFrom,
|
|
75
80
|
ProviderRpcError,
|
|
76
81
|
RpcErrorCodes,
|
|
77
82
|
} from './errors'
|
package/src/version/version.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "version": "5.
|
|
1
|
+
{ "version": "5.1.0" }
|
package/types.d.ts
CHANGED
|
@@ -62,6 +62,7 @@ interface ClientResponseMetadataNamespaces {
|
|
|
62
62
|
bip122?: ClientResponseNamespaceMetadataItem
|
|
63
63
|
stellar?: ClientResponseNamespaceMetadataItem
|
|
64
64
|
tron?: ClientResponseNamespaceMetadataItem
|
|
65
|
+
xrpl?: ClientResponseNamespaceMetadataItem
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
interface ClientResponseNamespaceMetadataItem {
|
|
@@ -157,6 +158,7 @@ export interface AddressesByNamespace {
|
|
|
157
158
|
solana?: string
|
|
158
159
|
stellar?: string
|
|
159
160
|
tron?: string
|
|
161
|
+
xrpl?: string
|
|
160
162
|
/**
|
|
161
163
|
* Bitcoin has no single canonical address: the encoding is per-network and
|
|
162
164
|
* per-script-type, so addresses are keyed by script type and network rather
|
|
@@ -219,6 +221,17 @@ export interface Presignature {
|
|
|
219
221
|
data: string
|
|
220
222
|
}
|
|
221
223
|
|
|
224
|
+
/** Any value a JSON document can hold. */
|
|
225
|
+
export type JsonValue =
|
|
226
|
+
| string
|
|
227
|
+
| number
|
|
228
|
+
| boolean
|
|
229
|
+
| null
|
|
230
|
+
| JsonValue[]
|
|
231
|
+
| { [key: string]: JsonValue }
|
|
232
|
+
|
|
233
|
+
export type JsonObject = { [key: string]: JsonValue }
|
|
234
|
+
|
|
222
235
|
export interface HttpErrorOptions {
|
|
223
236
|
message: string
|
|
224
237
|
status: number
|
|
@@ -597,16 +610,17 @@ export interface BlockaidValidationFeature {
|
|
|
597
610
|
type: string
|
|
598
611
|
featureId: string
|
|
599
612
|
description: string
|
|
600
|
-
address?: string
|
|
613
|
+
address?: string | null
|
|
601
614
|
}
|
|
602
615
|
|
|
603
616
|
export interface BlockaidValidation {
|
|
604
|
-
classification?: string
|
|
605
|
-
description?: string
|
|
617
|
+
classification?: string | null
|
|
618
|
+
description?: string | null
|
|
606
619
|
features: BlockaidValidationFeature[]
|
|
607
|
-
reason?: string
|
|
608
|
-
resultType:
|
|
620
|
+
reason?: string | null
|
|
621
|
+
resultType: 'Benign' | 'Warning' | 'Malicious' | 'Error'
|
|
609
622
|
status: string
|
|
623
|
+
error?: string | null
|
|
610
624
|
}
|
|
611
625
|
|
|
612
626
|
export interface BlockaidAssetDiff {
|
|
@@ -617,15 +631,16 @@ export interface BlockaidAssetDiff {
|
|
|
617
631
|
|
|
618
632
|
export interface BlockaidSimulation {
|
|
619
633
|
accountAddress?: string
|
|
620
|
-
accountSummary
|
|
621
|
-
addressDetails
|
|
622
|
-
assetsDiffs
|
|
634
|
+
accountSummary?: Record<string, any>
|
|
635
|
+
addressDetails?: Record<string, any>
|
|
636
|
+
assetsDiffs?: Record<string, BlockaidAssetDiff[]>
|
|
623
637
|
block?: number
|
|
624
638
|
chain?: string
|
|
625
|
-
exposures
|
|
639
|
+
exposures?: Record<string, any>
|
|
626
640
|
status: string
|
|
627
|
-
totalUsdDiff
|
|
628
|
-
totalUsdExposure
|
|
641
|
+
totalUsdDiff?: Record<string, any>
|
|
642
|
+
totalUsdExposure?: Record<string, any>
|
|
643
|
+
error?: string
|
|
629
644
|
}
|
|
630
645
|
|
|
631
646
|
export interface BlockaidValidateTrxRes {
|