@dynamic-labs-wallet/forward-mpc-client 0.6.0 → 0.8.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/dist/index.cjs +51 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -1
- package/dist/index.d.ts +58 -1
- package/dist/index.js +49 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/dist/index.d.cts
CHANGED
|
@@ -398,6 +398,63 @@ declare class ClientSessionEstablishFailedError extends ClientError {
|
|
|
398
398
|
constructor(context?: Record<string, unknown>);
|
|
399
399
|
}
|
|
400
400
|
|
|
401
|
+
/**
|
|
402
|
+
* Error classification result from Forward MPC operations.
|
|
403
|
+
*/
|
|
404
|
+
type ForwardMpcErrorType = 'ATTESTATION_FAILURE' | 'FORWARD_MPC_TIMEOUT' | 'FORWARD_MPC_ERROR';
|
|
405
|
+
/**
|
|
406
|
+
* Result of classifying a Forward MPC error.
|
|
407
|
+
*/
|
|
408
|
+
interface ForwardMpcErrorClassification {
|
|
409
|
+
/** The type of error encountered */
|
|
410
|
+
errorType: ForwardMpcErrorType;
|
|
411
|
+
/** Error code from ForwardMPCError, if available */
|
|
412
|
+
errorCode: string | undefined;
|
|
413
|
+
/** Error message */
|
|
414
|
+
errorMessage: string;
|
|
415
|
+
/** Attestation verification errors, if this is an attestation failure */
|
|
416
|
+
attestationErrors?: unknown[];
|
|
417
|
+
/** Whether the session was established before the error occurred */
|
|
418
|
+
sessionEstablished: boolean;
|
|
419
|
+
/** Whether this error should trigger a fallback to relay-based MPC */
|
|
420
|
+
shouldFallback: boolean;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Classifies a Forward MPC error and returns structured data for logging.
|
|
424
|
+
* Use this to standardize error handling across keygen, signing, and connect operations.
|
|
425
|
+
*
|
|
426
|
+
* @param error - The error to classify
|
|
427
|
+
* @returns Classification result with error details and recommended action
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* ```typescript
|
|
431
|
+
* try {
|
|
432
|
+
* await forwardMpcClient.sign(...);
|
|
433
|
+
* } catch (error) {
|
|
434
|
+
* const classification = classifyForwardMpcError(error);
|
|
435
|
+
* logger.warn(`Forward MPC ${operation} failed`, {
|
|
436
|
+
* ...classification,
|
|
437
|
+
* chainName,
|
|
438
|
+
* environmentId,
|
|
439
|
+
* });
|
|
440
|
+
* if (classification.shouldFallback) {
|
|
441
|
+
* // Fall through to relay-based MPC
|
|
442
|
+
* } else {
|
|
443
|
+
* throw error;
|
|
444
|
+
* }
|
|
445
|
+
* }
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
declare function classifyForwardMpcError(error: unknown): ForwardMpcErrorClassification;
|
|
449
|
+
/**
|
|
450
|
+
* Type guard to check if an error is a Forward MPC error that should be handled.
|
|
451
|
+
*/
|
|
452
|
+
declare function isForwardMpcError(error: unknown): error is ForwardMPCError;
|
|
453
|
+
/**
|
|
454
|
+
* Type guard to check if an error is an attestation failure.
|
|
455
|
+
*/
|
|
456
|
+
declare function isAttestationError(error: unknown): error is SessionAttestationError;
|
|
457
|
+
|
|
401
458
|
/**
|
|
402
459
|
* Nitro Enclave Attestation Document Verifier
|
|
403
460
|
* Uses Evervault's official WASM attestation bindings
|
|
@@ -430,4 +487,4 @@ declare class NitroAttestationVerifier implements AttestationVerifier {
|
|
|
430
487
|
verify(attestationDocBase64: string, expectedChallenge: string, nonce: Uint8Array): Promise<AttestationVerificationResult>;
|
|
431
488
|
}
|
|
432
489
|
|
|
433
|
-
export { AttestationErrorCode, type AttestationVerificationConfig, type AttestationVerificationResult, type AttestationVerifier, ClientError, type ClientEvents, ClientSessionEstablishFailedError, ClientUnsupportedAlgorithmError, type ClientV2Events, ErrorCode, type ExternalLogger, ForwardMPCClient, type ForwardMPCClientOptions, ForwardMPCClientSingleton, ForwardMPCClientV2, type ForwardMPCClientV2Options, ForwardMPCError, ForwardMPCErrorType, type KeygenParams, type KeygenResult, NitroAttestationVerifier, type ReceiveKeyParams, type ReceiveKeyResult, SessionAttestationError, SessionDisposedError, SessionError, SessionHandshakeError, SessionHandshakeInvalidResponseError, SessionMessageParseError, SessionRemoteError, SessionRequestTimeoutError, SessionServerError, type SignMessageParams, type SignMessageResult, TransportConnectionError, TransportConnectionTimeoutError, TransportError, TransportNotConnectedError };
|
|
490
|
+
export { AttestationErrorCode, type AttestationVerificationConfig, type AttestationVerificationResult, type AttestationVerifier, ClientError, type ClientEvents, ClientSessionEstablishFailedError, ClientUnsupportedAlgorithmError, type ClientV2Events, ErrorCode, type ExternalLogger, ForwardMPCClient, type ForwardMPCClientOptions, ForwardMPCClientSingleton, ForwardMPCClientV2, type ForwardMPCClientV2Options, ForwardMPCError, ForwardMPCErrorType, type ForwardMpcErrorClassification, type ForwardMpcErrorType, type KeygenParams, type KeygenResult, NitroAttestationVerifier, type ReceiveKeyParams, type ReceiveKeyResult, SessionAttestationError, SessionDisposedError, SessionError, SessionHandshakeError, SessionHandshakeInvalidResponseError, SessionMessageParseError, SessionRemoteError, SessionRequestTimeoutError, SessionServerError, type SignMessageParams, type SignMessageResult, TransportConnectionError, TransportConnectionTimeoutError, TransportError, TransportNotConnectedError, classifyForwardMpcError, isAttestationError, isForwardMpcError };
|
package/dist/index.d.ts
CHANGED
|
@@ -398,6 +398,63 @@ declare class ClientSessionEstablishFailedError extends ClientError {
|
|
|
398
398
|
constructor(context?: Record<string, unknown>);
|
|
399
399
|
}
|
|
400
400
|
|
|
401
|
+
/**
|
|
402
|
+
* Error classification result from Forward MPC operations.
|
|
403
|
+
*/
|
|
404
|
+
type ForwardMpcErrorType = 'ATTESTATION_FAILURE' | 'FORWARD_MPC_TIMEOUT' | 'FORWARD_MPC_ERROR';
|
|
405
|
+
/**
|
|
406
|
+
* Result of classifying a Forward MPC error.
|
|
407
|
+
*/
|
|
408
|
+
interface ForwardMpcErrorClassification {
|
|
409
|
+
/** The type of error encountered */
|
|
410
|
+
errorType: ForwardMpcErrorType;
|
|
411
|
+
/** Error code from ForwardMPCError, if available */
|
|
412
|
+
errorCode: string | undefined;
|
|
413
|
+
/** Error message */
|
|
414
|
+
errorMessage: string;
|
|
415
|
+
/** Attestation verification errors, if this is an attestation failure */
|
|
416
|
+
attestationErrors?: unknown[];
|
|
417
|
+
/** Whether the session was established before the error occurred */
|
|
418
|
+
sessionEstablished: boolean;
|
|
419
|
+
/** Whether this error should trigger a fallback to relay-based MPC */
|
|
420
|
+
shouldFallback: boolean;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Classifies a Forward MPC error and returns structured data for logging.
|
|
424
|
+
* Use this to standardize error handling across keygen, signing, and connect operations.
|
|
425
|
+
*
|
|
426
|
+
* @param error - The error to classify
|
|
427
|
+
* @returns Classification result with error details and recommended action
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* ```typescript
|
|
431
|
+
* try {
|
|
432
|
+
* await forwardMpcClient.sign(...);
|
|
433
|
+
* } catch (error) {
|
|
434
|
+
* const classification = classifyForwardMpcError(error);
|
|
435
|
+
* logger.warn(`Forward MPC ${operation} failed`, {
|
|
436
|
+
* ...classification,
|
|
437
|
+
* chainName,
|
|
438
|
+
* environmentId,
|
|
439
|
+
* });
|
|
440
|
+
* if (classification.shouldFallback) {
|
|
441
|
+
* // Fall through to relay-based MPC
|
|
442
|
+
* } else {
|
|
443
|
+
* throw error;
|
|
444
|
+
* }
|
|
445
|
+
* }
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
declare function classifyForwardMpcError(error: unknown): ForwardMpcErrorClassification;
|
|
449
|
+
/**
|
|
450
|
+
* Type guard to check if an error is a Forward MPC error that should be handled.
|
|
451
|
+
*/
|
|
452
|
+
declare function isForwardMpcError(error: unknown): error is ForwardMPCError;
|
|
453
|
+
/**
|
|
454
|
+
* Type guard to check if an error is an attestation failure.
|
|
455
|
+
*/
|
|
456
|
+
declare function isAttestationError(error: unknown): error is SessionAttestationError;
|
|
457
|
+
|
|
401
458
|
/**
|
|
402
459
|
* Nitro Enclave Attestation Document Verifier
|
|
403
460
|
* Uses Evervault's official WASM attestation bindings
|
|
@@ -430,4 +487,4 @@ declare class NitroAttestationVerifier implements AttestationVerifier {
|
|
|
430
487
|
verify(attestationDocBase64: string, expectedChallenge: string, nonce: Uint8Array): Promise<AttestationVerificationResult>;
|
|
431
488
|
}
|
|
432
489
|
|
|
433
|
-
export { AttestationErrorCode, type AttestationVerificationConfig, type AttestationVerificationResult, type AttestationVerifier, ClientError, type ClientEvents, ClientSessionEstablishFailedError, ClientUnsupportedAlgorithmError, type ClientV2Events, ErrorCode, type ExternalLogger, ForwardMPCClient, type ForwardMPCClientOptions, ForwardMPCClientSingleton, ForwardMPCClientV2, type ForwardMPCClientV2Options, ForwardMPCError, ForwardMPCErrorType, type KeygenParams, type KeygenResult, NitroAttestationVerifier, type ReceiveKeyParams, type ReceiveKeyResult, SessionAttestationError, SessionDisposedError, SessionError, SessionHandshakeError, SessionHandshakeInvalidResponseError, SessionMessageParseError, SessionRemoteError, SessionRequestTimeoutError, SessionServerError, type SignMessageParams, type SignMessageResult, TransportConnectionError, TransportConnectionTimeoutError, TransportError, TransportNotConnectedError };
|
|
490
|
+
export { AttestationErrorCode, type AttestationVerificationConfig, type AttestationVerificationResult, type AttestationVerifier, ClientError, type ClientEvents, ClientSessionEstablishFailedError, ClientUnsupportedAlgorithmError, type ClientV2Events, ErrorCode, type ExternalLogger, ForwardMPCClient, type ForwardMPCClientOptions, ForwardMPCClientSingleton, ForwardMPCClientV2, type ForwardMPCClientV2Options, ForwardMPCError, ForwardMPCErrorType, type ForwardMpcErrorClassification, type ForwardMpcErrorType, type KeygenParams, type KeygenResult, NitroAttestationVerifier, type ReceiveKeyParams, type ReceiveKeyResult, SessionAttestationError, SessionDisposedError, SessionError, SessionHandshakeError, SessionHandshakeInvalidResponseError, SessionMessageParseError, SessionRemoteError, SessionRequestTimeoutError, SessionServerError, type SignMessageParams, type SignMessageResult, TransportConnectionError, TransportConnectionTimeoutError, TransportError, TransportNotConnectedError, classifyForwardMpcError, isAttestationError, isForwardMpcError };
|
package/dist/index.js
CHANGED
|
@@ -1415,6 +1415,54 @@ var ForwardMPCClientSingleton = class extends ForwardMPCClientV2 {
|
|
|
1415
1415
|
}
|
|
1416
1416
|
};
|
|
1417
1417
|
|
|
1418
|
-
|
|
1418
|
+
// src/client-v2/error-classification.ts
|
|
1419
|
+
function classifyForwardMpcError(error) {
|
|
1420
|
+
if (error instanceof SessionAttestationError) {
|
|
1421
|
+
return {
|
|
1422
|
+
errorType: "ATTESTATION_FAILURE",
|
|
1423
|
+
errorCode: error.code,
|
|
1424
|
+
errorMessage: error.message,
|
|
1425
|
+
attestationErrors: error.context?.["errors"],
|
|
1426
|
+
sessionEstablished: false,
|
|
1427
|
+
shouldFallback: true
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
if (error instanceof SessionRequestTimeoutError) {
|
|
1431
|
+
return {
|
|
1432
|
+
errorType: "FORWARD_MPC_TIMEOUT",
|
|
1433
|
+
errorCode: error.code,
|
|
1434
|
+
errorMessage: error.message,
|
|
1435
|
+
sessionEstablished: true,
|
|
1436
|
+
shouldFallback: false
|
|
1437
|
+
};
|
|
1438
|
+
}
|
|
1439
|
+
if (error instanceof ForwardMPCError) {
|
|
1440
|
+
return {
|
|
1441
|
+
errorType: "FORWARD_MPC_ERROR",
|
|
1442
|
+
errorCode: error.code,
|
|
1443
|
+
errorMessage: error.message,
|
|
1444
|
+
sessionEstablished: true,
|
|
1445
|
+
shouldFallback: false
|
|
1446
|
+
};
|
|
1447
|
+
}
|
|
1448
|
+
return {
|
|
1449
|
+
errorType: "FORWARD_MPC_ERROR",
|
|
1450
|
+
errorCode: void 0,
|
|
1451
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
1452
|
+
sessionEstablished: false,
|
|
1453
|
+
shouldFallback: false
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1456
|
+
__name(classifyForwardMpcError, "classifyForwardMpcError");
|
|
1457
|
+
function isForwardMpcError(error) {
|
|
1458
|
+
return error instanceof ForwardMPCError;
|
|
1459
|
+
}
|
|
1460
|
+
__name(isForwardMpcError, "isForwardMpcError");
|
|
1461
|
+
function isAttestationError(error) {
|
|
1462
|
+
return error instanceof SessionAttestationError;
|
|
1463
|
+
}
|
|
1464
|
+
__name(isAttestationError, "isAttestationError");
|
|
1465
|
+
|
|
1466
|
+
export { AttestationErrorCode, ClientError, ClientSessionEstablishFailedError, ClientUnsupportedAlgorithmError, ErrorCode, ForwardMPCClient, ForwardMPCClientSingleton, ForwardMPCClientV2, ForwardMPCError, ForwardMPCErrorType, NitroAttestationVerifier, SessionAttestationError, SessionDisposedError, SessionError, SessionHandshakeError, SessionHandshakeInvalidResponseError, SessionMessageParseError, SessionRemoteError, SessionRequestTimeoutError, SessionServerError, TransportConnectionError, TransportConnectionTimeoutError, TransportError, TransportNotConnectedError, classifyForwardMpcError, isAttestationError, isForwardMpcError };
|
|
1419
1467
|
//# sourceMappingURL=index.js.map
|
|
1420
1468
|
//# sourceMappingURL=index.js.map
|