@dynamic-labs-wallet/core 1.1.33 → 1.1.35
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/index.cjs +302 -134
- package/index.esm.js +300 -136
- package/package.json +2 -2
- package/src/api/api.d.ts +62 -2
- package/src/api/api.d.ts.map +1 -1
- package/src/api/index.d.ts +1 -0
- package/src/api/index.d.ts.map +1 -1
- package/src/api/signAndBroadcastRequestTooLargeError.d.ts +8 -0
- package/src/api/signAndBroadcastRequestTooLargeError.d.ts.map +1 -0
- package/src/constants.d.ts +1 -0
- package/src/constants.d.ts.map +1 -1
- package/src/eventStream/utils.d.ts +7 -0
- package/src/eventStream/utils.d.ts.map +1 -1
- package/src/types.d.ts +15 -0
- package/src/types.d.ts.map +1 -1
- package/src/utils/attachRequestIds.d.ts +8 -0
- package/src/utils/attachRequestIds.d.ts.map +1 -0
- package/src/utils/index.d.ts +3 -0
- package/src/utils/index.d.ts.map +1 -1
- package/src/utils/toJsonSafeContext.d.ts +4 -0
- package/src/utils/toJsonSafeContext.d.ts.map +1 -0
- package/src/utils/withTraceId.d.ts +7 -0
- package/src/utils/withTraceId.d.ts.map +1 -0
package/index.cjs
CHANGED
|
@@ -152,6 +152,7 @@ const FEATURE_FLAGS = {
|
|
|
152
152
|
ENABLE_FORWARD_MPC_CLIENT_FLAG: 'enable-forward-mpc-client',
|
|
153
153
|
ENABLE_HTTP_WAAS_TRANSPORT: 'enable-http-waas-transport',
|
|
154
154
|
ENABLE_HTTP_WAAS_TRANSPORT_SIGNMESSAGE: 'enable-http-waas-transport-signmessage',
|
|
155
|
+
ENABLE_HTTP_WAAS_TRANSPORT_EXPORT: 'enable-http-waas-transport-export',
|
|
155
156
|
ENABLE_ROOM_CACHE_FLAG: 'enable-mpc-room-cache',
|
|
156
157
|
ENABLE_SHARE_SET_RESHARE: 'enable-share-set-reshare',
|
|
157
158
|
ENABLE_TRON_MPC_FLAG: 'enable-tron-mpc',
|
|
@@ -1278,6 +1279,155 @@ const getElapsedTime = (startTime)=>{
|
|
|
1278
1279
|
};
|
|
1279
1280
|
};
|
|
1280
1281
|
|
|
1282
|
+
/**
|
|
1283
|
+
* Thrown when sign-and-broadcast answers 413: the request body is over the server's 640kb limit,
|
|
1284
|
+
* which multiple large messages plus calldata can reach.
|
|
1285
|
+
*/ class SignAndBroadcastRequestTooLargeError extends Error {
|
|
1286
|
+
constructor(){
|
|
1287
|
+
super('The sign-and-broadcast request is too large. Send less calldata or fewer fee attempts.');
|
|
1288
|
+
this.name = 'SignAndBroadcastRequestTooLargeError';
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
class WalletApiError extends Error {
|
|
1293
|
+
constructor(status, message, code){
|
|
1294
|
+
super(message);
|
|
1295
|
+
this.name = 'WalletApiError';
|
|
1296
|
+
this.status = status;
|
|
1297
|
+
this.code = code;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
const getResponseRecord = (error)=>{
|
|
1301
|
+
var _error_response;
|
|
1302
|
+
const data = (_error_response = error.response) == null ? void 0 : _error_response.data;
|
|
1303
|
+
return data && typeof data === 'object' ? data : undefined;
|
|
1304
|
+
};
|
|
1305
|
+
// The Key Share Service returns its machine-readable cause under `error_code`; other
|
|
1306
|
+
// backends use `code` or a bare `error`. Exported for callers that must skip handleAxiosError's own logging.
|
|
1307
|
+
const extractServerErrorCode = (error)=>{
|
|
1308
|
+
const record = getResponseRecord(error);
|
|
1309
|
+
const candidates = [
|
|
1310
|
+
record == null ? void 0 : record['code'],
|
|
1311
|
+
record == null ? void 0 : record['error_code'],
|
|
1312
|
+
record == null ? void 0 : record['error']
|
|
1313
|
+
];
|
|
1314
|
+
return candidates.find((value)=>typeof value === 'string');
|
|
1315
|
+
};
|
|
1316
|
+
const INTERNAL_SERVER_ERROR_MESSAGE = 'Internal server error';
|
|
1317
|
+
/**
|
|
1318
|
+
* `status` for a request that never received an HTTP response at all — the
|
|
1319
|
+
* client lost connectivity, the request was aborted, DNS/TLS failed, or CORS
|
|
1320
|
+
* blocked it. 0 matches the XHR/`fetch` convention for "no response".
|
|
1321
|
+
*
|
|
1322
|
+
* This used to be reported as `500 Internal server error`, which made a
|
|
1323
|
+
* client-side network failure indistinguishable from a backend fault: the
|
|
1324
|
+
* "Backend 500s" monitor counted 1,395 events on a day when the API returned
|
|
1325
|
+
* only 33 real 5xx responses.
|
|
1326
|
+
*/ const NETWORK_ERROR_STATUS = 0;
|
|
1327
|
+
const NETWORK_ERROR_CODE = 'NETWORK_ERROR';
|
|
1328
|
+
const NETWORK_ERROR_MESSAGE = 'Network error - no response received';
|
|
1329
|
+
const STATUS_MESSAGES = {
|
|
1330
|
+
400: 'Invalid request',
|
|
1331
|
+
403: 'Forbidden',
|
|
1332
|
+
422: 'Unprocessable content',
|
|
1333
|
+
429: 'Rate limited',
|
|
1334
|
+
500: INTERNAL_SERVER_ERROR_MESSAGE
|
|
1335
|
+
};
|
|
1336
|
+
const MISSING_AUTH_MESSAGE = 'Authorization header or cookie missing';
|
|
1337
|
+
// A 401 can mean the request carried no credentials, or carried credentials the
|
|
1338
|
+
// backend rejected — the two need different messages. The Authorization header
|
|
1339
|
+
// is readable so we can confirm its presence; the auth cookie is httpOnly, so we
|
|
1340
|
+
// can only report whether cookie mode was enabled (`withCredentials`), not that a
|
|
1341
|
+
// cookie was actually attached.
|
|
1342
|
+
const getRequestCredentials = (error)=>{
|
|
1343
|
+
var _error_config, _error_config1;
|
|
1344
|
+
const requestHeaders = (_error_config = error.config) == null ? void 0 : _error_config.headers;
|
|
1345
|
+
var _requestHeaders_Authorization;
|
|
1346
|
+
const hasAuthorizationHeader = Boolean((_requestHeaders_Authorization = requestHeaders == null ? void 0 : requestHeaders['Authorization']) != null ? _requestHeaders_Authorization : requestHeaders == null ? void 0 : requestHeaders['authorization']);
|
|
1347
|
+
const usesCookieAuth = Boolean((_error_config1 = error.config) == null ? void 0 : _error_config1.withCredentials);
|
|
1348
|
+
return {
|
|
1349
|
+
hasAuthorizationHeader,
|
|
1350
|
+
usesCookieAuth
|
|
1351
|
+
};
|
|
1352
|
+
};
|
|
1353
|
+
const resolveUnauthorizedMessage = (error)=>{
|
|
1354
|
+
const { hasAuthorizationHeader, usesCookieAuth } = getRequestCredentials(error);
|
|
1355
|
+
if (!hasAuthorizationHeader && !usesCookieAuth) {
|
|
1356
|
+
return MISSING_AUTH_MESSAGE;
|
|
1357
|
+
}
|
|
1358
|
+
const credentialDescriptions = [];
|
|
1359
|
+
if (hasAuthorizationHeader) {
|
|
1360
|
+
credentialDescriptions.push('Authorization header present');
|
|
1361
|
+
}
|
|
1362
|
+
if (usesCookieAuth) {
|
|
1363
|
+
credentialDescriptions.push('withCredentials enabled (cookie auth)');
|
|
1364
|
+
}
|
|
1365
|
+
return `Unauthorized (${credentialDescriptions.join(', ')})`;
|
|
1366
|
+
};
|
|
1367
|
+
const resolveStatusMessage = (status, error)=>{
|
|
1368
|
+
if (status === 401) {
|
|
1369
|
+
return resolveUnauthorizedMessage(error);
|
|
1370
|
+
}
|
|
1371
|
+
if (status && STATUS_MESSAGES[status]) {
|
|
1372
|
+
return STATUS_MESSAGES[status];
|
|
1373
|
+
}
|
|
1374
|
+
return undefined;
|
|
1375
|
+
};
|
|
1376
|
+
const handleAxiosError = (error, message, context, /**
|
|
1377
|
+
* Optional severity hint from the caller, for failures the caller knows are
|
|
1378
|
+
* expected (e.g. a business-rule rejection). It can only *lower* severity to
|
|
1379
|
+
* `warn` — a caller must not be able to escalate, and a genuine 5xx has to
|
|
1380
|
+
* stay at `error` regardless of what the call site believes.
|
|
1381
|
+
*
|
|
1382
|
+
* Without this the hint that `logError` accepts was silently discarded for
|
|
1383
|
+
* every AxiosError, which is the most common error type in the SDK.
|
|
1384
|
+
*/ options)=>{
|
|
1385
|
+
var _error_config, _error_config1, _error_response, _error_response1, _error_response2;
|
|
1386
|
+
const requestUrl = (_error_config = error.config) == null ? void 0 : _error_config.url;
|
|
1387
|
+
const requestBaseUrl = (_error_config1 = error.config) == null ? void 0 : _error_config1.baseURL;
|
|
1388
|
+
// The HTTP status MUST NOT be logged as a top-level `status` field: Datadog
|
|
1389
|
+
// reserves `status` for the log level and its remapper turns a numeric value
|
|
1390
|
+
// into `info`, silently burying every 4xx/5xx we emit here. `http.status_code`
|
|
1391
|
+
// is Datadog's standard attribute, so the level survives and these logs join
|
|
1392
|
+
// against edge/CDN logs on the same field.
|
|
1393
|
+
const logPayload = _extends({
|
|
1394
|
+
message,
|
|
1395
|
+
error: (_error_response = error.response) == null ? void 0 : _error_response.data,
|
|
1396
|
+
http: {
|
|
1397
|
+
status_code: (_error_response1 = error.response) == null ? void 0 : _error_response1.status
|
|
1398
|
+
}
|
|
1399
|
+
}, requestBaseUrl && {
|
|
1400
|
+
requestBaseUrl
|
|
1401
|
+
}, requestUrl && {
|
|
1402
|
+
requestUrl
|
|
1403
|
+
}, {
|
|
1404
|
+
context
|
|
1405
|
+
});
|
|
1406
|
+
const status = (_error_response2 = error.response) == null ? void 0 : _error_response2.status;
|
|
1407
|
+
// A 429 (Too Many Requests) is a transient rate-limit signal, not a code or
|
|
1408
|
+
// logic failure — and a request that never got a response is a client-side
|
|
1409
|
+
// connectivity problem, not a server fault. Both are logged at `warn` so they
|
|
1410
|
+
// don't pollute error dashboards or trigger PagerDuty. The 429 case covers
|
|
1411
|
+
// both Cloudflare WAF blocks and application-level rate limiting.
|
|
1412
|
+
const inferredLevel = status === 429 || status === undefined ? 'warn' : 'error';
|
|
1413
|
+
// A 5xx is a server fault: no call site is entitled to downgrade it, however
|
|
1414
|
+
// expected it believes the failure to be. The hint only applies below 500.
|
|
1415
|
+
const isServerFault = status !== undefined && status >= 500;
|
|
1416
|
+
const logLevel = (options == null ? void 0 : options.level) === 'warn' && !isServerFault ? 'warn' : inferredLevel;
|
|
1417
|
+
Logger[logLevel]('[DynamicWaasWalletClient] Axios error: ', logPayload);
|
|
1418
|
+
// No response at all: report it as such rather than laundering it into a 500.
|
|
1419
|
+
if (status === undefined) {
|
|
1420
|
+
throw new WalletApiError(NETWORK_ERROR_STATUS, NETWORK_ERROR_MESSAGE, NETWORK_ERROR_CODE);
|
|
1421
|
+
}
|
|
1422
|
+
var _resolveStatusMessage;
|
|
1423
|
+
// Preserve the real status. Collapsing every unmapped code to 500 made a 404
|
|
1424
|
+
// (backup not found) and a 504 (gateway timeout) both surface as
|
|
1425
|
+
// "Internal server error", so neither the caller nor a monitor could tell a
|
|
1426
|
+
// missing resource from an outage.
|
|
1427
|
+
const resolvedMessage = (_resolveStatusMessage = resolveStatusMessage(status, error)) != null ? _resolveStatusMessage : `Request failed with status ${status}`;
|
|
1428
|
+
throw new WalletApiError(status, resolvedMessage, extractServerErrorCode(error));
|
|
1429
|
+
};
|
|
1430
|
+
|
|
1281
1431
|
const getRequiredExternalKeyShareId = (ks)=>{
|
|
1282
1432
|
if (!ks.externalKeyShareId) {
|
|
1283
1433
|
throw new Error(`Missing externalKeyShareId for key share (id: ${ks.id}, keygenId: ${ks.keygenId})`);
|
|
@@ -1292,7 +1442,7 @@ const getRequiredExternalKeyShareId = (ks)=>{
|
|
|
1292
1442
|
* before it is posted and surfaces in Datadog exactly as the recovery path does.
|
|
1293
1443
|
*/ const assertDynamicLocationsHaveExternalKeyShareId = (locations)=>locations.filter((location)=>location.location === BackupLocation.DYNAMIC).forEach((location)=>getRequiredExternalKeyShareId(location));
|
|
1294
1444
|
|
|
1295
|
-
var version = "1.1.
|
|
1445
|
+
var version = "1.1.35";
|
|
1296
1446
|
|
|
1297
1447
|
/**
|
|
1298
1448
|
* Reads the Authorization header off an axios request config, which stores
|
|
@@ -1457,6 +1607,29 @@ const createWalletAccountRequestBody = ({ chainName, clientKeygenIds, thresholdS
|
|
|
1457
1607
|
businessAccountId
|
|
1458
1608
|
} : {});
|
|
1459
1609
|
};
|
|
1610
|
+
const MAX_SERVER_MESSAGE_LENGTH = 200;
|
|
1611
|
+
/**
|
|
1612
|
+
* A rejected sign-and-broadcast as a `WalletApiError` that names the server's reason and code, since the generic status text says nothing about which check failed. A failure with no response (timeout, no connection) passes through.
|
|
1613
|
+
*
|
|
1614
|
+
* @param error - What the request threw.
|
|
1615
|
+
*/ const toSignAndBroadcastApiError = (error)=>{
|
|
1616
|
+
if (!axios.isAxiosError(error) || !error.response) {
|
|
1617
|
+
return error;
|
|
1618
|
+
}
|
|
1619
|
+
const { status, data } = error.response;
|
|
1620
|
+
const code = extractServerErrorCode(error);
|
|
1621
|
+
const record = data && typeof data === 'object' ? data : undefined;
|
|
1622
|
+
const serverMessage = [
|
|
1623
|
+
record == null ? void 0 : record['error'],
|
|
1624
|
+
record == null ? void 0 : record['message']
|
|
1625
|
+
].find((candidate)=>typeof candidate === 'string' && candidate.length > 0 && candidate !== code);
|
|
1626
|
+
const detail = [
|
|
1627
|
+
serverMessage == null ? void 0 : serverMessage.slice(0, MAX_SERVER_MESSAGE_LENGTH),
|
|
1628
|
+
code && `code: ${code}`
|
|
1629
|
+
].filter(Boolean).join(', ');
|
|
1630
|
+
const suffix = detail ? ` (${detail})` : '';
|
|
1631
|
+
return new WalletApiError(status, `Sign and broadcast failed with status ${status}${suffix}`, code);
|
|
1632
|
+
};
|
|
1460
1633
|
class DynamicApiClient extends BaseClient {
|
|
1461
1634
|
async getBackupRelayToken({ traceContext }) {
|
|
1462
1635
|
const { data } = await this.apiClient.get(`${this.waasRoutePrefix}/keyShares/backup/token`, {
|
|
@@ -1585,6 +1758,74 @@ class DynamicApiClient extends BaseClient {
|
|
|
1585
1758
|
traceContext
|
|
1586
1759
|
});
|
|
1587
1760
|
}
|
|
1761
|
+
/**
|
|
1762
|
+
* Starts a sign-and-broadcast: Dynamic opens one signing room per message, you sign in each, and Dynamic then sends the transaction. The signature never comes back.
|
|
1763
|
+
*
|
|
1764
|
+
* @param params.walletId - The wallet that signs.
|
|
1765
|
+
* @param params.shareSetId - Which of the wallet's key sets to use. Defaults to its active one.
|
|
1766
|
+
* @param params.messages - The transaction once per fee attempt, in fee order, as the bytes to sign (RLP hex on EVM, message bytes on Solana). Not hashed.
|
|
1767
|
+
* @param params.contexts - What each message does in readable form (chain, recipient, amount), one per message in the same order. Dynamic checks each against the wallet and its policies.
|
|
1768
|
+
* @param params.broadcastOptions - Solana send settings: other required signers' signatures, and skipping the pre-send dry run.
|
|
1769
|
+
* @param params.isFormatted - `true` if each message is already a hash. `false` for a serialized transaction.
|
|
1770
|
+
* @param params.requestedCertainty - How sure to be before calling it confirmed: `fast`, `safe` or `final`, or `chain:` plus a chain-specific value. Defaults to `safe`.
|
|
1771
|
+
* @param params.externalReference - Your own label, returned on every event. Not unique.
|
|
1772
|
+
* @param params.roomIds - Signing rooms you already opened, one per message. Send all or none; Dynamic opens them when omitted.
|
|
1773
|
+
* @param params.approvalQuorum - Approvers' consent for a governed wallet, sent on the retry after `intent_required`.
|
|
1774
|
+
* @param params.idempotencyKey - Makes a retry safe: the same key replays the stored answer instead of sending twice.
|
|
1775
|
+
* @param params.dynamicRequestId - Id of this one request, to match client and server logs.
|
|
1776
|
+
* @param params.traceContext - Ties this call's logs to the server's, across retries. Created when omitted.
|
|
1777
|
+
* @param params.mfaToken - Proof of the user's multi-factor check, when the wallet needs one.
|
|
1778
|
+
* @param params.elevatedAccessToken - Proof of a recent re-login, when the wallet needs one.
|
|
1779
|
+
* @param params.onError - Called with the failure's message, never the raw error.
|
|
1780
|
+
* @returns The transaction record: its id, its status, and the signing rooms while signing is pending.
|
|
1781
|
+
* @throws SignAndBroadcastRequestTooLargeError when the body is over the server limit.
|
|
1782
|
+
* @throws SigningConsentRequiredError when a governed wallet needs approvers' consent first.
|
|
1783
|
+
* @throws WalletApiError when the server rejects it, with its reason and code.
|
|
1784
|
+
*/ async signAndBroadcast({ dynamicRequestId, walletId, shareSetId, contexts, broadcastOptions, messages, isFormatted, requestedCertainty, externalReference, roomIds, approvalQuorum, idempotencyKey, onError, mfaToken, elevatedAccessToken, traceContext }) {
|
|
1785
|
+
try {
|
|
1786
|
+
return await requestJson({
|
|
1787
|
+
apiClient: this.apiClient,
|
|
1788
|
+
dynamicRequestId,
|
|
1789
|
+
idempotencyKey,
|
|
1790
|
+
endpoint: `${this.waasRoutePrefix}/${walletId}/transactions/signAndBroadcast`,
|
|
1791
|
+
body: _extends({
|
|
1792
|
+
messages,
|
|
1793
|
+
contexts
|
|
1794
|
+
}, broadcastOptions ? {
|
|
1795
|
+
broadcastOptions
|
|
1796
|
+
} : {}, {
|
|
1797
|
+
isFormatted
|
|
1798
|
+
}, requestedCertainty ? {
|
|
1799
|
+
requestedCertainty
|
|
1800
|
+
} : {}, externalReference ? {
|
|
1801
|
+
externalReference
|
|
1802
|
+
} : {}, roomIds ? {
|
|
1803
|
+
roomIds
|
|
1804
|
+
} : {}, approvalQuorum ? {
|
|
1805
|
+
approvalQuorum
|
|
1806
|
+
} : {}, shareSetId ? {
|
|
1807
|
+
shareSetId
|
|
1808
|
+
} : {}),
|
|
1809
|
+
timeoutMs: 20000,
|
|
1810
|
+
timeoutMessage: 'Sign and broadcast timed out',
|
|
1811
|
+
onError,
|
|
1812
|
+
mfaToken,
|
|
1813
|
+
elevatedAccessToken,
|
|
1814
|
+
traceContext
|
|
1815
|
+
});
|
|
1816
|
+
} catch (error) {
|
|
1817
|
+
const response = error.response;
|
|
1818
|
+
if ((response == null ? void 0 : response.status) === 413) {
|
|
1819
|
+
throw new SignAndBroadcastRequestTooLargeError();
|
|
1820
|
+
}
|
|
1821
|
+
// A governed wallet with nothing signed yet answers 422 intent_required, as plain signing's stream does.
|
|
1822
|
+
const intentRequired = (response == null ? void 0 : response.status) === 422 ? asIntentRequiredFrom422Body(response.data) : undefined;
|
|
1823
|
+
if (intentRequired) {
|
|
1824
|
+
throw new SigningConsentRequiredError(intentRequired);
|
|
1825
|
+
}
|
|
1826
|
+
throw toSignAndBroadcastApiError(error);
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1588
1829
|
async refreshWalletAccountShares({ dynamicRequestId, walletId, shareSetId, onError, onCeremonyComplete, mfaToken, elevatedAccessToken, traceContext }) {
|
|
1589
1830
|
return createEventStreamPromise({
|
|
1590
1831
|
apiClient: this.apiClient,
|
|
@@ -1652,6 +1893,35 @@ class DynamicApiClient extends BaseClient {
|
|
|
1652
1893
|
});
|
|
1653
1894
|
}
|
|
1654
1895
|
/**
|
|
1896
|
+
* Plain-JSON (non-SSE) variant of `exportKey`. Hits the same
|
|
1897
|
+
* `/privateKey/export` endpoint; the `x-idempotency-key` header tells the
|
|
1898
|
+
* backend (when `enable-http-waas-transport-export` is on) to respond with
|
|
1899
|
+
* the OpenRoomResponse synchronously instead of streaming `room_created`
|
|
1900
|
+
* over SSE.
|
|
1901
|
+
*/ async requestExportKeyJson({ mfaToken, elevatedAccessToken, dynamicRequestId, walletId, shareSetId, exportId, bitcoinConfig, onError, traceContext, idempotencyKey, timeoutMs }) {
|
|
1902
|
+
const { addressType } = bitcoinConfig || {};
|
|
1903
|
+
const requestBody = _extends({
|
|
1904
|
+
exportId
|
|
1905
|
+
}, addressType ? {
|
|
1906
|
+
addressType
|
|
1907
|
+
} : {}, shareSetId ? {
|
|
1908
|
+
shareSetId
|
|
1909
|
+
} : {});
|
|
1910
|
+
return requestJson({
|
|
1911
|
+
apiClient: this.apiClient,
|
|
1912
|
+
dynamicRequestId,
|
|
1913
|
+
idempotencyKey,
|
|
1914
|
+
endpoint: `${this.waasRoutePrefix}/${walletId}/privateKey/export`,
|
|
1915
|
+
body: requestBody,
|
|
1916
|
+
timeoutMs: timeoutMs != null ? timeoutMs : 20000,
|
|
1917
|
+
timeoutMessage: 'Key export timed out',
|
|
1918
|
+
onError,
|
|
1919
|
+
mfaToken,
|
|
1920
|
+
elevatedAccessToken,
|
|
1921
|
+
traceContext
|
|
1922
|
+
});
|
|
1923
|
+
}
|
|
1924
|
+
/**
|
|
1655
1925
|
* Kick off the Aleo view-key export MPC ceremony. Returns the MPC room once
|
|
1656
1926
|
* redcoast + wallet-service have joined; the client then joins the same
|
|
1657
1927
|
* room via Sodot's `exportViewKey` to receive the view key.
|
|
@@ -2807,143 +3077,37 @@ const prepareRawMessageSigningPayload = (chainName, message)=>{
|
|
|
2807
3077
|
return typeof formatted === 'string' ? formatted : Buffer.from(formatted).toString('hex');
|
|
2808
3078
|
};
|
|
2809
3079
|
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
3080
|
+
/** Returns the context as plain JSON, with each bigint (which `JSON.stringify` throws on) turned into a string. */ const toJsonSafeContext = (context)=>{
|
|
3081
|
+
try {
|
|
3082
|
+
return JSON.parse(JSON.stringify(context, (_key, value)=>typeof value === 'bigint' ? String(value) : value));
|
|
3083
|
+
} catch (error) {
|
|
3084
|
+
throw new Error(`Could not serialize the signing context: ${error instanceof Error ? error.message : String(error)}`, {
|
|
3085
|
+
cause: error
|
|
3086
|
+
});
|
|
2816
3087
|
}
|
|
2817
|
-
}
|
|
2818
|
-
const getResponseRecord = (error)=>{
|
|
2819
|
-
var _error_response;
|
|
2820
|
-
const data = (_error_response = error.response) == null ? void 0 : _error_response.data;
|
|
2821
|
-
return data && typeof data === 'object' ? data : undefined;
|
|
2822
|
-
};
|
|
2823
|
-
// The Key Share Service returns its machine-readable cause under `error_code`; other
|
|
2824
|
-
// backends use `code` or a bare `error`. Exported for callers that must skip handleAxiosError's own logging.
|
|
2825
|
-
const extractServerErrorCode = (error)=>{
|
|
2826
|
-
const record = getResponseRecord(error);
|
|
2827
|
-
const candidates = [
|
|
2828
|
-
record == null ? void 0 : record['code'],
|
|
2829
|
-
record == null ? void 0 : record['error_code'],
|
|
2830
|
-
record == null ? void 0 : record['error']
|
|
2831
|
-
];
|
|
2832
|
-
return candidates.find((value)=>typeof value === 'string');
|
|
2833
3088
|
};
|
|
2834
|
-
|
|
3089
|
+
|
|
2835
3090
|
/**
|
|
2836
|
-
*
|
|
2837
|
-
*
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
* only 33 real 5xx responses.
|
|
2844
|
-
*/ const NETWORK_ERROR_STATUS = 0;
|
|
2845
|
-
const NETWORK_ERROR_CODE = 'NETWORK_ERROR';
|
|
2846
|
-
const NETWORK_ERROR_MESSAGE = 'Network error - no response received';
|
|
2847
|
-
const STATUS_MESSAGES = {
|
|
2848
|
-
400: 'Invalid request',
|
|
2849
|
-
403: 'Forbidden',
|
|
2850
|
-
422: 'Unprocessable content',
|
|
2851
|
-
429: 'Rate limited',
|
|
2852
|
-
500: INTERNAL_SERVER_ERROR_MESSAGE
|
|
2853
|
-
};
|
|
2854
|
-
const MISSING_AUTH_MESSAGE = 'Authorization header or cookie missing';
|
|
2855
|
-
// A 401 can mean the request carried no credentials, or carried credentials the
|
|
2856
|
-
// backend rejected — the two need different messages. The Authorization header
|
|
2857
|
-
// is readable so we can confirm its presence; the auth cookie is httpOnly, so we
|
|
2858
|
-
// can only report whether cookie mode was enabled (`withCredentials`), not that a
|
|
2859
|
-
// cookie was actually attached.
|
|
2860
|
-
const getRequestCredentials = (error)=>{
|
|
2861
|
-
var _error_config, _error_config1;
|
|
2862
|
-
const requestHeaders = (_error_config = error.config) == null ? void 0 : _error_config.headers;
|
|
2863
|
-
var _requestHeaders_Authorization;
|
|
2864
|
-
const hasAuthorizationHeader = Boolean((_requestHeaders_Authorization = requestHeaders == null ? void 0 : requestHeaders['Authorization']) != null ? _requestHeaders_Authorization : requestHeaders == null ? void 0 : requestHeaders['authorization']);
|
|
2865
|
-
const usesCookieAuth = Boolean((_error_config1 = error.config) == null ? void 0 : _error_config1.withCredentials);
|
|
2866
|
-
return {
|
|
2867
|
-
hasAuthorizationHeader,
|
|
2868
|
-
usesCookieAuth
|
|
2869
|
-
};
|
|
2870
|
-
};
|
|
2871
|
-
const resolveUnauthorizedMessage = (error)=>{
|
|
2872
|
-
const { hasAuthorizationHeader, usesCookieAuth } = getRequestCredentials(error);
|
|
2873
|
-
if (!hasAuthorizationHeader && !usesCookieAuth) {
|
|
2874
|
-
return MISSING_AUTH_MESSAGE;
|
|
2875
|
-
}
|
|
2876
|
-
const credentialDescriptions = [];
|
|
2877
|
-
if (hasAuthorizationHeader) {
|
|
2878
|
-
credentialDescriptions.push('Authorization header present');
|
|
2879
|
-
}
|
|
2880
|
-
if (usesCookieAuth) {
|
|
2881
|
-
credentialDescriptions.push('withCredentials enabled (cookie auth)');
|
|
2882
|
-
}
|
|
2883
|
-
return `Unauthorized (${credentialDescriptions.join(', ')})`;
|
|
2884
|
-
};
|
|
2885
|
-
const resolveStatusMessage = (status, error)=>{
|
|
2886
|
-
if (status === 401) {
|
|
2887
|
-
return resolveUnauthorizedMessage(error);
|
|
2888
|
-
}
|
|
2889
|
-
if (status && STATUS_MESSAGES[status]) {
|
|
2890
|
-
return STATUS_MESSAGES[status];
|
|
2891
|
-
}
|
|
2892
|
-
return undefined;
|
|
2893
|
-
};
|
|
2894
|
-
const handleAxiosError = (error, message, context, /**
|
|
2895
|
-
* Optional severity hint from the caller, for failures the caller knows are
|
|
2896
|
-
* expected (e.g. a business-rule rejection). It can only *lower* severity to
|
|
2897
|
-
* `warn` — a caller must not be able to escalate, and a genuine 5xx has to
|
|
2898
|
-
* stay at `error` regardless of what the call site believes.
|
|
2899
|
-
*
|
|
2900
|
-
* Without this the hint that `logError` accepts was silently discarded for
|
|
2901
|
-
* every AxiosError, which is the most common error type in the SDK.
|
|
2902
|
-
*/ options)=>{
|
|
2903
|
-
var _error_config, _error_config1, _error_response, _error_response1, _error_response2;
|
|
2904
|
-
const requestUrl = (_error_config = error.config) == null ? void 0 : _error_config.url;
|
|
2905
|
-
const requestBaseUrl = (_error_config1 = error.config) == null ? void 0 : _error_config1.baseURL;
|
|
2906
|
-
// The HTTP status MUST NOT be logged as a top-level `status` field: Datadog
|
|
2907
|
-
// reserves `status` for the log level and its remapper turns a numeric value
|
|
2908
|
-
// into `info`, silently burying every 4xx/5xx we emit here. `http.status_code`
|
|
2909
|
-
// is Datadog's standard attribute, so the level survives and these logs join
|
|
2910
|
-
// against edge/CDN logs on the same field.
|
|
2911
|
-
const logPayload = _extends({
|
|
2912
|
-
message,
|
|
2913
|
-
error: (_error_response = error.response) == null ? void 0 : _error_response.data,
|
|
2914
|
-
http: {
|
|
2915
|
-
status_code: (_error_response1 = error.response) == null ? void 0 : _error_response1.status
|
|
2916
|
-
}
|
|
2917
|
-
}, requestBaseUrl && {
|
|
2918
|
-
requestBaseUrl
|
|
2919
|
-
}, requestUrl && {
|
|
2920
|
-
requestUrl
|
|
2921
|
-
}, {
|
|
2922
|
-
context
|
|
3091
|
+
* Returns a trace context that always has an id, so a retrying operation can hand the same one to each attempt.
|
|
3092
|
+
* The id is 32 lowercase hex characters, a valid W3C trace id the server can continue.
|
|
3093
|
+
*/ const withTraceId = (traceContext)=>{
|
|
3094
|
+
var _traceContext_traceId, _traceContext_startTime;
|
|
3095
|
+
return _extends({}, traceContext, {
|
|
3096
|
+
traceId: (_traceContext_traceId = traceContext == null ? void 0 : traceContext.traceId) != null ? _traceContext_traceId : uuid.v4().replaceAll('-', ''),
|
|
3097
|
+
startTime: (_traceContext_startTime = traceContext == null ? void 0 : traceContext.startTime) != null ? _traceContext_startTime : Date.now()
|
|
2923
3098
|
});
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
// No response at all: report it as such rather than laundering it into a 500.
|
|
2937
|
-
if (status === undefined) {
|
|
2938
|
-
throw new WalletApiError(NETWORK_ERROR_STATUS, NETWORK_ERROR_MESSAGE, NETWORK_ERROR_CODE);
|
|
2939
|
-
}
|
|
2940
|
-
var _resolveStatusMessage;
|
|
2941
|
-
// Preserve the real status. Collapsing every unmapped code to 500 made a 404
|
|
2942
|
-
// (backup not found) and a 504 (gateway timeout) both surface as
|
|
2943
|
-
// "Internal server error", so neither the caller nor a monitor could tell a
|
|
2944
|
-
// missing resource from an outage.
|
|
2945
|
-
const resolvedMessage = (_resolveStatusMessage = resolveStatusMessage(status, error)) != null ? _resolveStatusMessage : `Request failed with status ${status}`;
|
|
2946
|
-
throw new WalletApiError(status, resolvedMessage, extractServerErrorCode(error));
|
|
3099
|
+
};
|
|
3100
|
+
|
|
3101
|
+
/** The ids a caller can quote to support so one failed attempt can be found in client and server logs. */ /** Sets `traceId` and `requestId` on a thrown error so apps can quote them, keeping any id already set. */ const attachRequestIds = (error, { traceId, requestId })=>{
|
|
3102
|
+
var _target, _target1;
|
|
3103
|
+
if (!error || typeof error !== 'object' || !Object.isExtensible(error)) {
|
|
3104
|
+
return;
|
|
3105
|
+
}
|
|
3106
|
+
const target = error;
|
|
3107
|
+
var _traceId;
|
|
3108
|
+
(_traceId = (_target = target).traceId) != null ? _traceId : _target.traceId = traceId;
|
|
3109
|
+
var _requestId;
|
|
3110
|
+
(_requestId = (_target1 = target).requestId) != null ? _requestId : _target1.requestId = requestId;
|
|
2947
3111
|
};
|
|
2948
3112
|
|
|
2949
3113
|
Object.defineProperty(exports, "SigningAlgorithm", {
|
|
@@ -3039,6 +3203,7 @@ exports.RELAY_APP_ID_HEADER = RELAY_APP_ID_HEADER;
|
|
|
3039
3203
|
exports.SDK_NAMESPACE = SDK_NAMESPACE;
|
|
3040
3204
|
exports.SERVER_SDK_ROUTE_PREFIX = SERVER_SDK_ROUTE_PREFIX;
|
|
3041
3205
|
exports.SOLANA_RPC_URL = SOLANA_RPC_URL;
|
|
3206
|
+
exports.SignAndBroadcastRequestTooLargeError = SignAndBroadcastRequestTooLargeError;
|
|
3042
3207
|
exports.SigningConsentRequiredError = SigningConsentRequiredError;
|
|
3043
3208
|
exports.SuccessEventType = SuccessEventType;
|
|
3044
3209
|
exports.ThresholdSignatureScheme = ThresholdSignatureScheme;
|
|
@@ -3047,6 +3212,7 @@ exports.WalletApiError = WalletApiError;
|
|
|
3047
3212
|
exports.WalletOperation = WalletOperation;
|
|
3048
3213
|
exports.WalletReadyState = WalletReadyState;
|
|
3049
3214
|
exports.assertDynamicLocationsHaveExternalKeyShareId = assertDynamicLocationsHaveExternalKeyShareId;
|
|
3215
|
+
exports.attachRequestIds = attachRequestIds;
|
|
3050
3216
|
exports.buildForwardMpcEnclaveUrl = buildForwardMpcEnclaveUrl;
|
|
3051
3217
|
exports.chain = chain;
|
|
3052
3218
|
exports.chainEnumToVerifiedCredentialName = chainEnumToVerifiedCredentialName;
|
|
@@ -3077,4 +3243,6 @@ exports.prepareRawMessageSigningPayload = prepareRawMessageSigningPayload;
|
|
|
3077
3243
|
exports.sanitizeBusinessAccountSignedIntent = sanitizeBusinessAccountSignedIntent;
|
|
3078
3244
|
exports.serializeError = serializeError;
|
|
3079
3245
|
exports.serializeMessageForForwardMPC = serializeMessageForForwardMPC;
|
|
3246
|
+
exports.toJsonSafeContext = toJsonSafeContext;
|
|
3080
3247
|
exports.verifiedCredentialNameToChainEnum = verifiedCredentialNameToChainEnum;
|
|
3248
|
+
exports.withTraceId = withTraceId;
|