@dynamic-labs-wallet/forward-mpc-client 0.9.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,8 +1,9 @@
1
1
  import EventEmitter$1, { EventEmitter } from 'eventemitter3';
2
- import { BaseWebSocketMessage, TraceContext, HashAlgorithm, encryptKeyshare, WebSocketError } from '@dynamic-labs-wallet/forward-mpc-shared';
2
+ import { BaseWebSocketMessage, TraceContext, HashAlgorithm, encryptKeyshare } from '@dynamic-labs-wallet/forward-mpc-shared';
3
3
  export { BaseWebSocketMessage, ErrorResponse, HandshakeV1RequestMessage, HandshakeV1ResponseMessage, SignMessageV1RequestMessage, SignMessageV1ResponseMessage, WebSocketError, WebSocketErrorType } from '@dynamic-labs-wallet/forward-mpc-shared';
4
4
  import { SigningAlgorithm } from '@dynamic-labs-wallet/primitives';
5
5
  export { SigningAlgorithm } from '@dynamic-labs-wallet/primitives';
6
+ export { A as AttestationErrorCode, C as ClientError, a as ClientSessionEstablishFailedError, b as ClientUnsupportedAlgorithmError, E as ErrorCode, F as ForwardMPCError, c as ForwardMPCErrorType, d as ForwardMpcErrorClassification, e as ForwardMpcErrorType, S as SessionAttestationError, f as SessionDisposedError, g as SessionError, h as SessionHandshakeError, i as SessionHandshakeInvalidResponseError, j as SessionMessageParseError, k as SessionRemoteError, l as SessionRequestTimeoutError, m as SessionServerError, T as TransportConnectionError, n as TransportConnectionTimeoutError, o as TransportError, p as TransportNotConnectedError, q as classifyForwardMpcError, r as isAttestationError, s as isForwardMpcError } from './utils-D77Qzra4.cjs';
6
7
 
7
8
  /**
8
9
  * Result of attestation document verification
@@ -278,183 +279,6 @@ declare class ForwardMPCClientV2 extends EventEmitter$1<ClientV2Events> {
278
279
  declare class ForwardMPCClientSingleton extends ForwardMPCClientV2 {
279
280
  }
280
281
 
281
- declare const ErrorCode: {
282
- readonly CONNECTION_FAILED: "CONNECTION_FAILED";
283
- readonly CONNECTION_TIMEOUT: "CONNECTION_TIMEOUT";
284
- readonly NOT_CONNECTED: "NOT_CONNECTED";
285
- readonly HANDSHAKE_FAILED: "HANDSHAKE_FAILED";
286
- readonly HANDSHAKE_INVALID_RESPONSE: "HANDSHAKE_INVALID_RESPONSE";
287
- readonly ATTESTATION_FAILED: "ATTESTATION_FAILED";
288
- readonly ATTESTATION_PCR_MISMATCH: "ATTESTATION_PCR_MISMATCH";
289
- readonly ATTESTATION_CHALLENGE_MISMATCH: "ATTESTATION_CHALLENGE_MISMATCH";
290
- readonly ATTESTATION_NONCE_MISMATCH: "ATTESTATION_NONCE_MISMATCH";
291
- readonly ATTESTATION_NONCE_MISSING: "ATTESTATION_NONCE_MISSING";
292
- readonly ATTESTATION_DOCUMENT_MISSING: "ATTESTATION_DOCUMENT_MISSING";
293
- readonly REQUEST_TIMEOUT: "REQUEST_TIMEOUT";
294
- readonly SESSION_DISPOSED: "SESSION_DISPOSED";
295
- readonly SERVER_ERROR: "SERVER_ERROR";
296
- readonly MESSAGE_PARSE_FAILED: "MESSAGE_PARSE_FAILED";
297
- readonly SESSION_ESTABLISH_FAILED: "SESSION_ESTABLISH_FAILED";
298
- readonly UNSUPPORTED_ALGORITHM: "UNSUPPORTED_ALGORITHM";
299
- };
300
- type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
301
- /**
302
- * Focused subset of ErrorCode for attestation verification failures.
303
- * Use with `error.code` to distinguish failure modes on SessionAttestationError.
304
- */
305
- declare const AttestationErrorCode: {
306
- /** Generic / unrecognised attestation failure */
307
- readonly FAILED: "ATTESTATION_FAILED";
308
- /** PCR8 hash mismatch — enclave measurement changed */
309
- readonly PCR_MISMATCH: "ATTESTATION_PCR_MISMATCH";
310
- /** Challenge / ciphertext binding mismatch */
311
- readonly CHALLENGE_MISMATCH: "ATTESTATION_CHALLENGE_MISMATCH";
312
- /** Nonce value mismatch — possible tampering */
313
- readonly NONCE_MISMATCH: "ATTESTATION_NONCE_MISMATCH";
314
- /** Nonce field missing from attestation document */
315
- readonly NONCE_MISSING: "ATTESTATION_NONCE_MISSING";
316
- /** Server did not return an attestation document */
317
- readonly DOCUMENT_MISSING: "ATTESTATION_DOCUMENT_MISSING";
318
- };
319
- type AttestationErrorCode = (typeof AttestationErrorCode)[keyof typeof AttestationErrorCode];
320
- declare const ForwardMPCErrorType: {
321
- readonly TRANSPORT: "transport";
322
- readonly SESSION: "session";
323
- readonly CLIENT: "client";
324
- };
325
- type ForwardMPCErrorType = (typeof ForwardMPCErrorType)[keyof typeof ForwardMPCErrorType];
326
- /**
327
- * Abstract root for all Forward MPC errors.
328
- * `instanceof ForwardMPCError` is true for every error thrown by this library.
329
- */
330
- declare abstract class ForwardMPCError extends Error {
331
- readonly code: ErrorCode;
332
- readonly type: ForwardMPCErrorType;
333
- readonly context?: Record<string, unknown>;
334
- constructor(message: string, code: ErrorCode, type: ForwardMPCErrorType, context?: Record<string, unknown>);
335
- toJSON(): Record<string, unknown>;
336
- }
337
- /** Abstract base for errors originating from the WebSocket / transport layer. */
338
- declare abstract class TransportError extends ForwardMPCError {
339
- constructor(message: string, code: ErrorCode, context?: Record<string, unknown>);
340
- }
341
- /** Abstract base for errors originating from the session / crypto / protocol layer. */
342
- declare abstract class SessionError extends ForwardMPCError {
343
- constructor(message: string, code: ErrorCode, context?: Record<string, unknown>);
344
- }
345
- /** Abstract base for errors originating from the client / application layer. */
346
- declare abstract class ClientError extends ForwardMPCError {
347
- constructor(message: string, code: ErrorCode, context?: Record<string, unknown>);
348
- }
349
- declare class TransportConnectionError extends TransportError {
350
- constructor(context?: Record<string, unknown>);
351
- }
352
- declare class TransportConnectionTimeoutError extends TransportError {
353
- constructor(context?: Record<string, unknown>);
354
- }
355
- declare class TransportNotConnectedError extends TransportError {
356
- constructor(context?: Record<string, unknown>);
357
- }
358
- declare class SessionHandshakeError extends SessionError {
359
- constructor(reason: string, context?: Record<string, unknown>);
360
- }
361
- declare class SessionHandshakeInvalidResponseError extends SessionError {
362
- constructor(context?: Record<string, unknown>);
363
- }
364
- /**
365
- * Attestation verification failure.
366
- * Use `error.code` to distinguish failure reasons (e.g. ATTESTATION_PCR_MISMATCH)
367
- * and `error.cause` to inspect the original verifier error.
368
- */
369
- declare class SessionAttestationError extends SessionError {
370
- readonly cause?: unknown;
371
- constructor(message?: string, code?: ErrorCode, context?: Record<string, unknown>, cause?: unknown);
372
- }
373
- declare class SessionRequestTimeoutError extends SessionError {
374
- constructor(context?: Record<string, unknown>);
375
- }
376
- declare class SessionDisposedError extends SessionError {
377
- constructor(context?: Record<string, unknown>);
378
- }
379
- declare class SessionServerError extends SessionError {
380
- constructor(reason: string, context?: Record<string, unknown>);
381
- }
382
- declare class SessionMessageParseError extends SessionError {
383
- constructor(context?: Record<string, unknown>);
384
- }
385
- /**
386
- * The remote server returned an explicit error response.
387
- * Carries the full WebSocketError payload so callers can inspect
388
- * `serverError.type` and `serverError.details`.
389
- */
390
- declare class SessionRemoteError extends SessionError {
391
- readonly serverError: WebSocketError;
392
- constructor(serverError: WebSocketError, context?: Record<string, unknown>);
393
- }
394
- declare class ClientUnsupportedAlgorithmError extends ClientError {
395
- constructor(context?: Record<string, unknown>);
396
- }
397
- declare class ClientSessionEstablishFailedError extends ClientError {
398
- constructor(context?: Record<string, unknown>);
399
- }
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
-
458
282
  /**
459
283
  * Nitro Enclave Attestation Document Verifier
460
284
  * Uses Evervault's official WASM attestation bindings
@@ -487,4 +311,4 @@ declare class NitroAttestationVerifier implements AttestationVerifier {
487
311
  verify(attestationDocBase64: string, expectedChallenge: string, nonce: Uint8Array): Promise<AttestationVerificationResult>;
488
312
  }
489
313
 
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 };
314
+ export { type AttestationVerificationConfig, type AttestationVerificationResult, type AttestationVerifier, type ClientEvents, type ClientV2Events, type ExternalLogger, ForwardMPCClient, type ForwardMPCClientOptions, ForwardMPCClientSingleton, ForwardMPCClientV2, type ForwardMPCClientV2Options, type KeygenParams, type KeygenResult, NitroAttestationVerifier, type ReceiveKeyParams, type ReceiveKeyResult, type SignMessageParams, type SignMessageResult };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import EventEmitter$1, { EventEmitter } from 'eventemitter3';
2
- import { BaseWebSocketMessage, TraceContext, HashAlgorithm, encryptKeyshare, WebSocketError } from '@dynamic-labs-wallet/forward-mpc-shared';
2
+ import { BaseWebSocketMessage, TraceContext, HashAlgorithm, encryptKeyshare } from '@dynamic-labs-wallet/forward-mpc-shared';
3
3
  export { BaseWebSocketMessage, ErrorResponse, HandshakeV1RequestMessage, HandshakeV1ResponseMessage, SignMessageV1RequestMessage, SignMessageV1ResponseMessage, WebSocketError, WebSocketErrorType } from '@dynamic-labs-wallet/forward-mpc-shared';
4
4
  import { SigningAlgorithm } from '@dynamic-labs-wallet/primitives';
5
5
  export { SigningAlgorithm } from '@dynamic-labs-wallet/primitives';
6
+ export { A as AttestationErrorCode, C as ClientError, a as ClientSessionEstablishFailedError, b as ClientUnsupportedAlgorithmError, E as ErrorCode, F as ForwardMPCError, c as ForwardMPCErrorType, d as ForwardMpcErrorClassification, e as ForwardMpcErrorType, S as SessionAttestationError, f as SessionDisposedError, g as SessionError, h as SessionHandshakeError, i as SessionHandshakeInvalidResponseError, j as SessionMessageParseError, k as SessionRemoteError, l as SessionRequestTimeoutError, m as SessionServerError, T as TransportConnectionError, n as TransportConnectionTimeoutError, o as TransportError, p as TransportNotConnectedError, q as classifyForwardMpcError, r as isAttestationError, s as isForwardMpcError } from './utils-D77Qzra4.js';
6
7
 
7
8
  /**
8
9
  * Result of attestation document verification
@@ -278,183 +279,6 @@ declare class ForwardMPCClientV2 extends EventEmitter$1<ClientV2Events> {
278
279
  declare class ForwardMPCClientSingleton extends ForwardMPCClientV2 {
279
280
  }
280
281
 
281
- declare const ErrorCode: {
282
- readonly CONNECTION_FAILED: "CONNECTION_FAILED";
283
- readonly CONNECTION_TIMEOUT: "CONNECTION_TIMEOUT";
284
- readonly NOT_CONNECTED: "NOT_CONNECTED";
285
- readonly HANDSHAKE_FAILED: "HANDSHAKE_FAILED";
286
- readonly HANDSHAKE_INVALID_RESPONSE: "HANDSHAKE_INVALID_RESPONSE";
287
- readonly ATTESTATION_FAILED: "ATTESTATION_FAILED";
288
- readonly ATTESTATION_PCR_MISMATCH: "ATTESTATION_PCR_MISMATCH";
289
- readonly ATTESTATION_CHALLENGE_MISMATCH: "ATTESTATION_CHALLENGE_MISMATCH";
290
- readonly ATTESTATION_NONCE_MISMATCH: "ATTESTATION_NONCE_MISMATCH";
291
- readonly ATTESTATION_NONCE_MISSING: "ATTESTATION_NONCE_MISSING";
292
- readonly ATTESTATION_DOCUMENT_MISSING: "ATTESTATION_DOCUMENT_MISSING";
293
- readonly REQUEST_TIMEOUT: "REQUEST_TIMEOUT";
294
- readonly SESSION_DISPOSED: "SESSION_DISPOSED";
295
- readonly SERVER_ERROR: "SERVER_ERROR";
296
- readonly MESSAGE_PARSE_FAILED: "MESSAGE_PARSE_FAILED";
297
- readonly SESSION_ESTABLISH_FAILED: "SESSION_ESTABLISH_FAILED";
298
- readonly UNSUPPORTED_ALGORITHM: "UNSUPPORTED_ALGORITHM";
299
- };
300
- type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
301
- /**
302
- * Focused subset of ErrorCode for attestation verification failures.
303
- * Use with `error.code` to distinguish failure modes on SessionAttestationError.
304
- */
305
- declare const AttestationErrorCode: {
306
- /** Generic / unrecognised attestation failure */
307
- readonly FAILED: "ATTESTATION_FAILED";
308
- /** PCR8 hash mismatch — enclave measurement changed */
309
- readonly PCR_MISMATCH: "ATTESTATION_PCR_MISMATCH";
310
- /** Challenge / ciphertext binding mismatch */
311
- readonly CHALLENGE_MISMATCH: "ATTESTATION_CHALLENGE_MISMATCH";
312
- /** Nonce value mismatch — possible tampering */
313
- readonly NONCE_MISMATCH: "ATTESTATION_NONCE_MISMATCH";
314
- /** Nonce field missing from attestation document */
315
- readonly NONCE_MISSING: "ATTESTATION_NONCE_MISSING";
316
- /** Server did not return an attestation document */
317
- readonly DOCUMENT_MISSING: "ATTESTATION_DOCUMENT_MISSING";
318
- };
319
- type AttestationErrorCode = (typeof AttestationErrorCode)[keyof typeof AttestationErrorCode];
320
- declare const ForwardMPCErrorType: {
321
- readonly TRANSPORT: "transport";
322
- readonly SESSION: "session";
323
- readonly CLIENT: "client";
324
- };
325
- type ForwardMPCErrorType = (typeof ForwardMPCErrorType)[keyof typeof ForwardMPCErrorType];
326
- /**
327
- * Abstract root for all Forward MPC errors.
328
- * `instanceof ForwardMPCError` is true for every error thrown by this library.
329
- */
330
- declare abstract class ForwardMPCError extends Error {
331
- readonly code: ErrorCode;
332
- readonly type: ForwardMPCErrorType;
333
- readonly context?: Record<string, unknown>;
334
- constructor(message: string, code: ErrorCode, type: ForwardMPCErrorType, context?: Record<string, unknown>);
335
- toJSON(): Record<string, unknown>;
336
- }
337
- /** Abstract base for errors originating from the WebSocket / transport layer. */
338
- declare abstract class TransportError extends ForwardMPCError {
339
- constructor(message: string, code: ErrorCode, context?: Record<string, unknown>);
340
- }
341
- /** Abstract base for errors originating from the session / crypto / protocol layer. */
342
- declare abstract class SessionError extends ForwardMPCError {
343
- constructor(message: string, code: ErrorCode, context?: Record<string, unknown>);
344
- }
345
- /** Abstract base for errors originating from the client / application layer. */
346
- declare abstract class ClientError extends ForwardMPCError {
347
- constructor(message: string, code: ErrorCode, context?: Record<string, unknown>);
348
- }
349
- declare class TransportConnectionError extends TransportError {
350
- constructor(context?: Record<string, unknown>);
351
- }
352
- declare class TransportConnectionTimeoutError extends TransportError {
353
- constructor(context?: Record<string, unknown>);
354
- }
355
- declare class TransportNotConnectedError extends TransportError {
356
- constructor(context?: Record<string, unknown>);
357
- }
358
- declare class SessionHandshakeError extends SessionError {
359
- constructor(reason: string, context?: Record<string, unknown>);
360
- }
361
- declare class SessionHandshakeInvalidResponseError extends SessionError {
362
- constructor(context?: Record<string, unknown>);
363
- }
364
- /**
365
- * Attestation verification failure.
366
- * Use `error.code` to distinguish failure reasons (e.g. ATTESTATION_PCR_MISMATCH)
367
- * and `error.cause` to inspect the original verifier error.
368
- */
369
- declare class SessionAttestationError extends SessionError {
370
- readonly cause?: unknown;
371
- constructor(message?: string, code?: ErrorCode, context?: Record<string, unknown>, cause?: unknown);
372
- }
373
- declare class SessionRequestTimeoutError extends SessionError {
374
- constructor(context?: Record<string, unknown>);
375
- }
376
- declare class SessionDisposedError extends SessionError {
377
- constructor(context?: Record<string, unknown>);
378
- }
379
- declare class SessionServerError extends SessionError {
380
- constructor(reason: string, context?: Record<string, unknown>);
381
- }
382
- declare class SessionMessageParseError extends SessionError {
383
- constructor(context?: Record<string, unknown>);
384
- }
385
- /**
386
- * The remote server returned an explicit error response.
387
- * Carries the full WebSocketError payload so callers can inspect
388
- * `serverError.type` and `serverError.details`.
389
- */
390
- declare class SessionRemoteError extends SessionError {
391
- readonly serverError: WebSocketError;
392
- constructor(serverError: WebSocketError, context?: Record<string, unknown>);
393
- }
394
- declare class ClientUnsupportedAlgorithmError extends ClientError {
395
- constructor(context?: Record<string, unknown>);
396
- }
397
- declare class ClientSessionEstablishFailedError extends ClientError {
398
- constructor(context?: Record<string, unknown>);
399
- }
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
-
458
282
  /**
459
283
  * Nitro Enclave Attestation Document Verifier
460
284
  * Uses Evervault's official WASM attestation bindings
@@ -487,4 +311,4 @@ declare class NitroAttestationVerifier implements AttestationVerifier {
487
311
  verify(attestationDocBase64: string, expectedChallenge: string, nonce: Uint8Array): Promise<AttestationVerificationResult>;
488
312
  }
489
313
 
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 };
314
+ export { type AttestationVerificationConfig, type AttestationVerificationResult, type AttestationVerifier, type ClientEvents, type ClientV2Events, type ExternalLogger, ForwardMPCClient, type ForwardMPCClientOptions, ForwardMPCClientSingleton, ForwardMPCClientV2, type ForwardMPCClientV2Options, type KeygenParams, type KeygenResult, NitroAttestationVerifier, type ReceiveKeyParams, type ReceiveKeyResult, type SignMessageParams, type SignMessageResult };
package/dist/index.js CHANGED
@@ -16,6 +16,96 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
16
16
  var ATTESTATION_CONSTANTS = {
17
17
  // Maximum age of attestation document in milliseconds
18
18
  MAX_ATTESTATION_AGE: 5 * 60 * 1e3};
19
+
20
+ // src/attestation/attestationDocReader.ts
21
+ var PCRS_LABEL_AND_MAP_HEADER = new Uint8Array([
22
+ 100,
23
+ 112,
24
+ 99,
25
+ 114,
26
+ 115,
27
+ 176
28
+ ]);
29
+ var BSTR_48_PREFIX = new Uint8Array([
30
+ 88,
31
+ 48
32
+ ]);
33
+ var PCR_VALUE_BYTES = 48;
34
+ var PCR_ENTRIES = 16;
35
+ var TRACKED_PCRS = /* @__PURE__ */ new Set([
36
+ 0,
37
+ 1,
38
+ 2,
39
+ 8
40
+ ]);
41
+ function decodeBase64ToBytes(base64) {
42
+ if (typeof atob !== "undefined") {
43
+ const binary = atob(base64);
44
+ const out = new Uint8Array(binary.length);
45
+ for (let i = 0; i < binary.length; i++) {
46
+ out[i] = binary.codePointAt(i) ?? 0;
47
+ }
48
+ return out;
49
+ }
50
+ return new Uint8Array(Buffer.from(base64, "base64"));
51
+ }
52
+ __name(decodeBase64ToBytes, "decodeBase64ToBytes");
53
+ function bytesToHex(bytes) {
54
+ let out = "";
55
+ for (const b of bytes) {
56
+ out += b.toString(16).padStart(2, "0");
57
+ }
58
+ return out;
59
+ }
60
+ __name(bytesToHex, "bytesToHex");
61
+ function findMarker(haystack, needle) {
62
+ outer: for (let i = 0; i <= haystack.length - needle.length; i++) {
63
+ for (let j = 0; j < needle.length; j++) {
64
+ if (haystack[i + j] !== needle[j]) continue outer;
65
+ }
66
+ return i;
67
+ }
68
+ return -1;
69
+ }
70
+ __name(findMarker, "findMarker");
71
+ function extractPcrsFromAttestationDoc(attestationDocBase64) {
72
+ const pcrs = {};
73
+ if (!attestationDocBase64) return pcrs;
74
+ try {
75
+ const bytes = decodeBase64ToBytes(attestationDocBase64);
76
+ const markerIdx = findMarker(bytes, PCRS_LABEL_AND_MAP_HEADER);
77
+ if (markerIdx < 0) return pcrs;
78
+ let pos = markerIdx + PCRS_LABEL_AND_MAP_HEADER.length;
79
+ for (let i = 0; i < PCR_ENTRIES; i++) {
80
+ if (pos + 1 + BSTR_48_PREFIX.length + PCR_VALUE_BYTES > bytes.length) {
81
+ break;
82
+ }
83
+ const key = bytes[pos++];
84
+ if (bytes[pos] !== BSTR_48_PREFIX[0] || bytes[pos + 1] !== BSTR_48_PREFIX[1]) {
85
+ break;
86
+ }
87
+ pos += BSTR_48_PREFIX.length;
88
+ const value = bytes.subarray(pos, pos + PCR_VALUE_BYTES);
89
+ pos += PCR_VALUE_BYTES;
90
+ if (TRACKED_PCRS.has(key)) {
91
+ pcrs[key] = bytesToHex(value);
92
+ }
93
+ }
94
+ } catch {
95
+ }
96
+ return pcrs;
97
+ }
98
+ __name(extractPcrsFromAttestationDoc, "extractPcrsFromAttestationDoc");
99
+ function formatPcrMismatchDetail(expectedPcr8, receivedPcrs) {
100
+ const receivedParts = [];
101
+ if (receivedPcrs[8] !== void 0) receivedParts.push(`pcr8=${receivedPcrs[8]}`);
102
+ if (receivedPcrs[0] !== void 0) receivedParts.push(`pcr0=${receivedPcrs[0]}`);
103
+ if (receivedPcrs[1] !== void 0) receivedParts.push(`pcr1=${receivedPcrs[1]}`);
104
+ if (receivedPcrs[2] !== void 0) receivedParts.push(`pcr2=${receivedPcrs[2]}`);
105
+ const received = receivedParts.length > 0 ? receivedParts.join(", ") : "unavailable";
106
+ return `expected pcr8=${expectedPcr8}; received ${received}`;
107
+ }
108
+ __name(formatPcrMismatchDetail, "formatPcrMismatchDetail");
19
109
  var NitroAttestationVerifier = class {
20
110
  static {
21
111
  __name(this, "NitroAttestationVerifier");
@@ -85,10 +175,12 @@ var NitroAttestationVerifier = class {
85
175
  expectedPcrs
86
176
  ]);
87
177
  if (!isValid) {
178
+ const receivedPcrs = extractPcrsFromAttestationDoc(attestationDocBase64);
179
+ const detail = formatPcrMismatchDetail(this.config.expectedPcr8, receivedPcrs);
88
180
  return {
89
181
  valid: false,
90
182
  errors: [
91
- "Attestation document PCR verification failed"
183
+ `Attestation document PCR verification failed (${detail})`
92
184
  ],
93
185
  timestamp: Date.now()
94
186
  };
@@ -591,6 +683,8 @@ var ForwardMPCClient = class extends EventEmitter {
591
683
  }
592
684
  }
593
685
  };
686
+
687
+ // src/client-v2/errors.ts
594
688
  var ErrorCode = {
595
689
  // Transport
596
690
  CONNECTION_FAILED: "CONNECTION_FAILED",
@@ -797,6 +891,21 @@ var ClientSessionEstablishFailedError = class extends ClientError {
797
891
  super("Failed to establish session", ErrorCode.SESSION_ESTABLISH_FAILED, context);
798
892
  }
799
893
  };
894
+ var FORWARD_MPC_ERROR_NAMES = /* @__PURE__ */ new Set([
895
+ "TransportConnectionError",
896
+ "TransportConnectionTimeoutError",
897
+ "TransportNotConnectedError",
898
+ "SessionHandshakeError",
899
+ "SessionHandshakeInvalidResponseError",
900
+ "SessionAttestationError",
901
+ "SessionRequestTimeoutError",
902
+ "SessionDisposedError",
903
+ "SessionServerError",
904
+ "SessionMessageParseError",
905
+ "SessionRemoteError",
906
+ "ClientUnsupportedAlgorithmError",
907
+ "ClientSessionEstablishFailedError"
908
+ ]);
800
909
 
801
910
  // src/client-v2/transport.ts
802
911
  var ForwardMPCTransport = class extends EventEmitter2 {
@@ -1424,8 +1533,22 @@ var ForwardMPCClientSingleton = class extends ForwardMPCClientV2 {
1424
1533
  };
1425
1534
 
1426
1535
  // src/client-v2/error-classification.ts
1536
+ function matchesForwardMpcErrorClass(error, ctor, name) {
1537
+ if (error instanceof ctor) {
1538
+ return true;
1539
+ }
1540
+ return error instanceof Error && error.name === name && typeof error.code === "string";
1541
+ }
1542
+ __name(matchesForwardMpcErrorClass, "matchesForwardMpcErrorClass");
1543
+ function matchesAnyForwardMpcError(error) {
1544
+ if (error instanceof ForwardMPCError) {
1545
+ return true;
1546
+ }
1547
+ return error instanceof Error && FORWARD_MPC_ERROR_NAMES.has(error.name) && typeof error.code === "string";
1548
+ }
1549
+ __name(matchesAnyForwardMpcError, "matchesAnyForwardMpcError");
1427
1550
  function classifyForwardMpcError(error) {
1428
- if (error instanceof SessionAttestationError) {
1551
+ if (matchesForwardMpcErrorClass(error, SessionAttestationError, "SessionAttestationError")) {
1429
1552
  return {
1430
1553
  errorType: "ATTESTATION_FAILURE",
1431
1554
  errorCode: error.code,
@@ -1435,22 +1558,22 @@ function classifyForwardMpcError(error) {
1435
1558
  shouldFallback: true
1436
1559
  };
1437
1560
  }
1438
- if (error instanceof SessionRequestTimeoutError) {
1561
+ if (matchesForwardMpcErrorClass(error, SessionRequestTimeoutError, "SessionRequestTimeoutError")) {
1439
1562
  return {
1440
1563
  errorType: "FORWARD_MPC_TIMEOUT",
1441
1564
  errorCode: error.code,
1442
1565
  errorMessage: error.message,
1443
1566
  sessionEstablished: true,
1444
- shouldFallback: false
1567
+ shouldFallback: true
1445
1568
  };
1446
1569
  }
1447
- if (error instanceof ForwardMPCError) {
1570
+ if (matchesAnyForwardMpcError(error)) {
1448
1571
  return {
1449
1572
  errorType: "FORWARD_MPC_ERROR",
1450
1573
  errorCode: error.code,
1451
1574
  errorMessage: error.message,
1452
1575
  sessionEstablished: true,
1453
- shouldFallback: false
1576
+ shouldFallback: true
1454
1577
  };
1455
1578
  }
1456
1579
  return {
@@ -1458,16 +1581,16 @@ function classifyForwardMpcError(error) {
1458
1581
  errorCode: void 0,
1459
1582
  errorMessage: error instanceof Error ? error.message : String(error),
1460
1583
  sessionEstablished: false,
1461
- shouldFallback: false
1584
+ shouldFallback: true
1462
1585
  };
1463
1586
  }
1464
1587
  __name(classifyForwardMpcError, "classifyForwardMpcError");
1465
1588
  function isForwardMpcError(error) {
1466
- return error instanceof ForwardMPCError;
1589
+ return matchesAnyForwardMpcError(error);
1467
1590
  }
1468
1591
  __name(isForwardMpcError, "isForwardMpcError");
1469
1592
  function isAttestationError(error) {
1470
- return error instanceof SessionAttestationError;
1593
+ return matchesForwardMpcErrorClass(error, SessionAttestationError, "SessionAttestationError");
1471
1594
  }
1472
1595
  __name(isAttestationError, "isAttestationError");
1473
1596