@dynamic-labs-wallet/forward-mpc-client 0.5.4 → 0.6.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 +55 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -5
- package/dist/index.d.ts +32 -5
- package/dist/index.js +55 -17
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -91,6 +91,7 @@ declare class ForwardMPCClient extends EventEmitter {
|
|
|
91
91
|
roomUuid: string;
|
|
92
92
|
traceContext?: TraceContext;
|
|
93
93
|
userId?: string;
|
|
94
|
+
walletId?: string;
|
|
94
95
|
environmentId?: string;
|
|
95
96
|
}): Promise<any>;
|
|
96
97
|
/**
|
|
@@ -284,7 +285,11 @@ declare const ErrorCode: {
|
|
|
284
285
|
readonly HANDSHAKE_FAILED: "HANDSHAKE_FAILED";
|
|
285
286
|
readonly HANDSHAKE_INVALID_RESPONSE: "HANDSHAKE_INVALID_RESPONSE";
|
|
286
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";
|
|
287
291
|
readonly ATTESTATION_NONCE_MISSING: "ATTESTATION_NONCE_MISSING";
|
|
292
|
+
readonly ATTESTATION_DOCUMENT_MISSING: "ATTESTATION_DOCUMENT_MISSING";
|
|
288
293
|
readonly REQUEST_TIMEOUT: "REQUEST_TIMEOUT";
|
|
289
294
|
readonly SESSION_DISPOSED: "SESSION_DISPOSED";
|
|
290
295
|
readonly SERVER_ERROR: "SERVER_ERROR";
|
|
@@ -293,6 +298,25 @@ declare const ErrorCode: {
|
|
|
293
298
|
readonly UNSUPPORTED_ALGORITHM: "UNSUPPORTED_ALGORITHM";
|
|
294
299
|
};
|
|
295
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];
|
|
296
320
|
declare const ForwardMPCErrorType: {
|
|
297
321
|
readonly TRANSPORT: "transport";
|
|
298
322
|
readonly SESSION: "session";
|
|
@@ -337,11 +361,14 @@ declare class SessionHandshakeError extends SessionError {
|
|
|
337
361
|
declare class SessionHandshakeInvalidResponseError extends SessionError {
|
|
338
362
|
constructor(context?: Record<string, unknown>);
|
|
339
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
|
+
*/
|
|
340
369
|
declare class SessionAttestationError extends SessionError {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
declare class SessionAttestationNonceMissingError extends SessionError {
|
|
344
|
-
constructor(context?: Record<string, unknown>);
|
|
370
|
+
readonly cause?: unknown;
|
|
371
|
+
constructor(message?: string, code?: ErrorCode, context?: Record<string, unknown>, cause?: unknown);
|
|
345
372
|
}
|
|
346
373
|
declare class SessionRequestTimeoutError extends SessionError {
|
|
347
374
|
constructor(context?: Record<string, unknown>);
|
|
@@ -403,4 +430,4 @@ declare class NitroAttestationVerifier implements AttestationVerifier {
|
|
|
403
430
|
verify(attestationDocBase64: string, expectedChallenge: string, nonce: Uint8Array): Promise<AttestationVerificationResult>;
|
|
404
431
|
}
|
|
405
432
|
|
|
406
|
-
export { 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,
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -91,6 +91,7 @@ declare class ForwardMPCClient extends EventEmitter {
|
|
|
91
91
|
roomUuid: string;
|
|
92
92
|
traceContext?: TraceContext;
|
|
93
93
|
userId?: string;
|
|
94
|
+
walletId?: string;
|
|
94
95
|
environmentId?: string;
|
|
95
96
|
}): Promise<any>;
|
|
96
97
|
/**
|
|
@@ -284,7 +285,11 @@ declare const ErrorCode: {
|
|
|
284
285
|
readonly HANDSHAKE_FAILED: "HANDSHAKE_FAILED";
|
|
285
286
|
readonly HANDSHAKE_INVALID_RESPONSE: "HANDSHAKE_INVALID_RESPONSE";
|
|
286
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";
|
|
287
291
|
readonly ATTESTATION_NONCE_MISSING: "ATTESTATION_NONCE_MISSING";
|
|
292
|
+
readonly ATTESTATION_DOCUMENT_MISSING: "ATTESTATION_DOCUMENT_MISSING";
|
|
288
293
|
readonly REQUEST_TIMEOUT: "REQUEST_TIMEOUT";
|
|
289
294
|
readonly SESSION_DISPOSED: "SESSION_DISPOSED";
|
|
290
295
|
readonly SERVER_ERROR: "SERVER_ERROR";
|
|
@@ -293,6 +298,25 @@ declare const ErrorCode: {
|
|
|
293
298
|
readonly UNSUPPORTED_ALGORITHM: "UNSUPPORTED_ALGORITHM";
|
|
294
299
|
};
|
|
295
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];
|
|
296
320
|
declare const ForwardMPCErrorType: {
|
|
297
321
|
readonly TRANSPORT: "transport";
|
|
298
322
|
readonly SESSION: "session";
|
|
@@ -337,11 +361,14 @@ declare class SessionHandshakeError extends SessionError {
|
|
|
337
361
|
declare class SessionHandshakeInvalidResponseError extends SessionError {
|
|
338
362
|
constructor(context?: Record<string, unknown>);
|
|
339
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
|
+
*/
|
|
340
369
|
declare class SessionAttestationError extends SessionError {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
declare class SessionAttestationNonceMissingError extends SessionError {
|
|
344
|
-
constructor(context?: Record<string, unknown>);
|
|
370
|
+
readonly cause?: unknown;
|
|
371
|
+
constructor(message?: string, code?: ErrorCode, context?: Record<string, unknown>, cause?: unknown);
|
|
345
372
|
}
|
|
346
373
|
declare class SessionRequestTimeoutError extends SessionError {
|
|
347
374
|
constructor(context?: Record<string, unknown>);
|
|
@@ -403,4 +430,4 @@ declare class NitroAttestationVerifier implements AttestationVerifier {
|
|
|
403
430
|
verify(attestationDocBase64: string, expectedChallenge: string, nonce: Uint8Array): Promise<AttestationVerificationResult>;
|
|
404
431
|
}
|
|
405
432
|
|
|
406
|
-
export { 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,
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -489,6 +489,7 @@ var ForwardMPCClient = class extends EventEmitter {
|
|
|
489
489
|
roomUuid: params.roomUuid,
|
|
490
490
|
traceContext: params.traceContext,
|
|
491
491
|
userId: params.userId,
|
|
492
|
+
walletId: params.walletId,
|
|
492
493
|
environmentId: params.environmentId
|
|
493
494
|
});
|
|
494
495
|
return this.sendRequest(request);
|
|
@@ -591,7 +592,11 @@ var ErrorCode = {
|
|
|
591
592
|
HANDSHAKE_FAILED: "HANDSHAKE_FAILED",
|
|
592
593
|
HANDSHAKE_INVALID_RESPONSE: "HANDSHAKE_INVALID_RESPONSE",
|
|
593
594
|
ATTESTATION_FAILED: "ATTESTATION_FAILED",
|
|
595
|
+
ATTESTATION_PCR_MISMATCH: "ATTESTATION_PCR_MISMATCH",
|
|
596
|
+
ATTESTATION_CHALLENGE_MISMATCH: "ATTESTATION_CHALLENGE_MISMATCH",
|
|
597
|
+
ATTESTATION_NONCE_MISMATCH: "ATTESTATION_NONCE_MISMATCH",
|
|
594
598
|
ATTESTATION_NONCE_MISSING: "ATTESTATION_NONCE_MISSING",
|
|
599
|
+
ATTESTATION_DOCUMENT_MISSING: "ATTESTATION_DOCUMENT_MISSING",
|
|
595
600
|
REQUEST_TIMEOUT: "REQUEST_TIMEOUT",
|
|
596
601
|
SESSION_DISPOSED: "SESSION_DISPOSED",
|
|
597
602
|
SERVER_ERROR: "SERVER_ERROR",
|
|
@@ -600,6 +605,20 @@ var ErrorCode = {
|
|
|
600
605
|
SESSION_ESTABLISH_FAILED: "SESSION_ESTABLISH_FAILED",
|
|
601
606
|
UNSUPPORTED_ALGORITHM: "UNSUPPORTED_ALGORITHM"
|
|
602
607
|
};
|
|
608
|
+
var AttestationErrorCode = {
|
|
609
|
+
/** Generic / unrecognised attestation failure */
|
|
610
|
+
FAILED: ErrorCode.ATTESTATION_FAILED,
|
|
611
|
+
/** PCR8 hash mismatch — enclave measurement changed */
|
|
612
|
+
PCR_MISMATCH: ErrorCode.ATTESTATION_PCR_MISMATCH,
|
|
613
|
+
/** Challenge / ciphertext binding mismatch */
|
|
614
|
+
CHALLENGE_MISMATCH: ErrorCode.ATTESTATION_CHALLENGE_MISMATCH,
|
|
615
|
+
/** Nonce value mismatch — possible tampering */
|
|
616
|
+
NONCE_MISMATCH: ErrorCode.ATTESTATION_NONCE_MISMATCH,
|
|
617
|
+
/** Nonce field missing from attestation document */
|
|
618
|
+
NONCE_MISSING: ErrorCode.ATTESTATION_NONCE_MISSING,
|
|
619
|
+
/** Server did not return an attestation document */
|
|
620
|
+
DOCUMENT_MISSING: ErrorCode.ATTESTATION_DOCUMENT_MISSING
|
|
621
|
+
};
|
|
603
622
|
var ForwardMPCErrorType = {
|
|
604
623
|
TRANSPORT: "transport",
|
|
605
624
|
SESSION: "session",
|
|
@@ -702,16 +721,12 @@ var SessionAttestationError = class extends SessionError {
|
|
|
702
721
|
static {
|
|
703
722
|
__name(this, "SessionAttestationError");
|
|
704
723
|
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
__name(this, "SessionAttestationNonceMissingError");
|
|
712
|
-
}
|
|
713
|
-
constructor(context) {
|
|
714
|
-
super("Nonce missing from attestation document", ErrorCode.ATTESTATION_NONCE_MISSING, context);
|
|
724
|
+
cause;
|
|
725
|
+
constructor(message = "Attestation verification failed", code = ErrorCode.ATTESTATION_FAILED, context, cause) {
|
|
726
|
+
super(message, code, context);
|
|
727
|
+
if (cause !== void 0) {
|
|
728
|
+
this.cause = cause;
|
|
729
|
+
}
|
|
715
730
|
}
|
|
716
731
|
};
|
|
717
732
|
var SessionRequestTimeoutError = class extends SessionError {
|
|
@@ -1002,9 +1017,7 @@ var Session = class _Session {
|
|
|
1002
1017
|
if (!data.attestationDoc) {
|
|
1003
1018
|
sharedSecret.fill(0);
|
|
1004
1019
|
nonceBytes.fill(0);
|
|
1005
|
-
throw new SessionAttestationError(
|
|
1006
|
-
reason: "Server did not return an attestation document"
|
|
1007
|
-
});
|
|
1020
|
+
throw new SessionAttestationError("Server did not return an attestation document", ErrorCode.ATTESTATION_DOCUMENT_MISSING);
|
|
1008
1021
|
}
|
|
1009
1022
|
try {
|
|
1010
1023
|
await _Session.verifyAttestation(data.attestationDoc, cipherText, nonceBytes, options.attestationVerifier);
|
|
@@ -1092,7 +1105,13 @@ var Session = class _Session {
|
|
|
1092
1105
|
requestId
|
|
1093
1106
|
}));
|
|
1094
1107
|
} else {
|
|
1095
|
-
|
|
1108
|
+
const data = msg.getData();
|
|
1109
|
+
const maybeError = data !== null && typeof data === "object" && "error" in data ? data.error : void 0;
|
|
1110
|
+
if (isWebSocketError(maybeError)) {
|
|
1111
|
+
reject(new SessionRemoteError(maybeError));
|
|
1112
|
+
} else {
|
|
1113
|
+
resolve(data);
|
|
1114
|
+
}
|
|
1096
1115
|
}
|
|
1097
1116
|
}, "handler");
|
|
1098
1117
|
transport.on("message", handler);
|
|
@@ -1130,10 +1149,29 @@ var Session = class _Session {
|
|
|
1130
1149
|
const expectedChallenge = Array.from(challengeHash).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1131
1150
|
const result = await verifier.verify(attestationDocBase64, expectedChallenge, nonce);
|
|
1132
1151
|
if (!result.valid) {
|
|
1133
|
-
|
|
1152
|
+
const primaryError = result.errors[0] || "";
|
|
1153
|
+
throw new SessionAttestationError("Attestation verification failed", _Session.classifyAttestationError(primaryError), {
|
|
1134
1154
|
errors: result.errors
|
|
1135
|
-
});
|
|
1155
|
+
}, primaryError);
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
/**
|
|
1159
|
+
* Classifies an attestation verifier error message into a specific ErrorCode.
|
|
1160
|
+
*/
|
|
1161
|
+
static classifyAttestationError(primaryError) {
|
|
1162
|
+
if (primaryError.includes("PCR verification failed")) {
|
|
1163
|
+
return ErrorCode.ATTESTATION_PCR_MISMATCH;
|
|
1164
|
+
}
|
|
1165
|
+
if (primaryError.includes("challenge mismatch") || primaryError.includes("ciphertext hash") || primaryError.includes("user data") || primaryError.includes("ciphertext binding")) {
|
|
1166
|
+
return ErrorCode.ATTESTATION_CHALLENGE_MISMATCH;
|
|
1167
|
+
}
|
|
1168
|
+
if (primaryError.includes("No nonce found")) {
|
|
1169
|
+
return ErrorCode.ATTESTATION_NONCE_MISSING;
|
|
1170
|
+
}
|
|
1171
|
+
if (primaryError.includes("nonce mismatch") || primaryError.includes("Nonce length mismatch") || primaryError.includes("Nonce verification failed")) {
|
|
1172
|
+
return ErrorCode.ATTESTATION_NONCE_MISMATCH;
|
|
1136
1173
|
}
|
|
1174
|
+
return ErrorCode.ATTESTATION_FAILED;
|
|
1137
1175
|
}
|
|
1138
1176
|
};
|
|
1139
1177
|
|
|
@@ -1377,6 +1415,6 @@ var ForwardMPCClientSingleton = class extends ForwardMPCClientV2 {
|
|
|
1377
1415
|
}
|
|
1378
1416
|
};
|
|
1379
1417
|
|
|
1380
|
-
export { ClientError, ClientSessionEstablishFailedError, ClientUnsupportedAlgorithmError, ErrorCode, ForwardMPCClient, ForwardMPCClientSingleton, ForwardMPCClientV2, ForwardMPCError, ForwardMPCErrorType, NitroAttestationVerifier, SessionAttestationError,
|
|
1418
|
+
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 };
|
|
1381
1419
|
//# sourceMappingURL=index.js.map
|
|
1382
1420
|
//# sourceMappingURL=index.js.map
|