@reclaimprotocol/js-sdk 5.1.0 → 5.3.0-dev.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/README.md +57 -24
- package/dist/index.d.ts +66 -17
- package/dist/index.js +363 -716
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ Install the Reclaim Protocol SDK and a QR code generator:
|
|
|
37
37
|
npm install @reclaimprotocol/js-sdk react-qr-code
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
**Current SDK Version**:
|
|
40
|
+
**Current SDK Version**: 5.2.0
|
|
41
41
|
|
|
42
42
|
## Step 3: Set up your React component
|
|
43
43
|
|
|
@@ -703,31 +703,37 @@ const { isVerified } = await verifyProof(proof, {
|
|
|
703
703
|
|
|
704
704
|
## TEE Attestation Verification
|
|
705
705
|
|
|
706
|
-
The SDK supports verifying TEE (Trusted Execution Environment) attestations included in proofs.
|
|
706
|
+
The SDK supports verifying TEE (Trusted Execution Environment) attestations included in proofs. The attestation flow verifies the Google Confidential Computing OIDC token returned by Popcorn's GCP attestor and checks that it is bound to the proof nonce, application identity, and image digests.
|
|
707
707
|
|
|
708
|
-
###
|
|
708
|
+
### Requesting TEE Attestation
|
|
709
709
|
|
|
710
|
-
|
|
710
|
+
TEE attestation is requested by default during proof generation:
|
|
711
711
|
|
|
712
712
|
```javascript
|
|
713
|
-
const proofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER_ID
|
|
714
|
-
acceptTeeAttestation: true,
|
|
715
|
-
});
|
|
713
|
+
const proofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER_ID);
|
|
716
714
|
```
|
|
717
715
|
|
|
718
|
-
|
|
716
|
+
The request includes the SDK's attestation version so the attestor can continue serving older SDK clients when newer attestation formats are introduced.
|
|
717
|
+
|
|
718
|
+
To opt out, set `acceptTeeAttestation: false` during initialization.
|
|
719
719
|
|
|
720
|
-
|
|
720
|
+
### Verifying TEE Attestation via `verifyProof`
|
|
721
|
+
|
|
722
|
+
Provide a `teeAttestation` config to require and verify TEE attestation. The application ID is derived automatically from `appSecret`. If TEE data is missing or invalid, verification will fail with a `TeeVerificationError`.
|
|
721
723
|
|
|
722
724
|
```javascript
|
|
723
725
|
import { verifyProof, TeeVerificationError } from "@reclaimprotocol/js-sdk";
|
|
724
726
|
|
|
725
|
-
|
|
726
|
-
|
|
727
|
+
const { isVerified, isTeeAttestationVerified, data, error } = await verifyProof(proof, {
|
|
728
|
+
hashes: ['0xAbC...'],
|
|
729
|
+
teeAttestation: {
|
|
730
|
+
appSecret: APP_SECRET,
|
|
731
|
+
},
|
|
732
|
+
});
|
|
727
733
|
|
|
728
734
|
if (isVerified) {
|
|
729
|
-
console.log("Proof
|
|
730
|
-
console.log("TEE verified:",
|
|
735
|
+
console.log("Proof verified with hardware attestation");
|
|
736
|
+
console.log("TEE verified:", isTeeAttestationVerified); // always true when teeAttestation is provided and passes
|
|
731
737
|
console.log("Extracted parameters:", data[0].extractedParameters);
|
|
732
738
|
} else if (error instanceof TeeVerificationError) {
|
|
733
739
|
console.log("TEE verification failed:", error.message);
|
|
@@ -736,27 +742,54 @@ if (isVerified) {
|
|
|
736
742
|
}
|
|
737
743
|
```
|
|
738
744
|
|
|
739
|
-
|
|
745
|
+
The result includes `isTeeAttestationVerified`. It is `true` when `teeAttestation` was provided and verification passed, and `undefined` when `teeAttestation` was not requested.
|
|
740
746
|
|
|
741
|
-
|
|
747
|
+
### What TEE verification checks
|
|
748
|
+
|
|
749
|
+
- **Application binding**: Derives the application ID from `appSecret` and confirms the attestation was generated for your application
|
|
742
750
|
- **Nonce binding**: Ensures the attestation nonce matches the proof context
|
|
743
|
-
- **
|
|
744
|
-
- **
|
|
745
|
-
- **
|
|
746
|
-
- **
|
|
747
|
-
|
|
751
|
+
- **Session and timestamp binding**: Verifies the nonce metadata matches the proof session and is within the allowed skew
|
|
752
|
+
- **OIDC token signature**: Validates the Google Confidential Computing attestation JWT against Google's JWKS (responses are cached for 5 minutes)
|
|
753
|
+
- **Platform claims**: Confirms the expected GCP confidential-computing claims (issuer, secure boot, hardware model, GCE instance metadata)
|
|
754
|
+
- **Digest binding**: Confirms the workload and verifier image digests are present in the attestation token nonce list
|
|
755
|
+
|
|
756
|
+
### Standalone `verifyTeeAttestation`
|
|
748
757
|
|
|
749
|
-
You can
|
|
758
|
+
You can verify TEE attestation for a single proof without running full proof verification:
|
|
750
759
|
|
|
751
760
|
```javascript
|
|
752
761
|
import { verifyTeeAttestation } from "@reclaimprotocol/js-sdk";
|
|
753
762
|
|
|
754
|
-
const
|
|
755
|
-
if (
|
|
756
|
-
console.log("TEE attestation verified
|
|
763
|
+
const { isVerified, error } = await verifyTeeAttestation(proof, APP_SECRET);
|
|
764
|
+
if (isVerified) {
|
|
765
|
+
console.log("TEE attestation verified");
|
|
766
|
+
} else {
|
|
767
|
+
console.log("TEE verification failed:", error);
|
|
757
768
|
}
|
|
758
769
|
```
|
|
759
770
|
|
|
771
|
+
`appSecret` is your Reclaim application secret. The application ID is derived from it automatically.
|
|
772
|
+
|
|
773
|
+
### Browser vs Server Verification
|
|
774
|
+
|
|
775
|
+
TEE verification fetches Google's OIDC metadata and JWKS endpoints. In browser-only environments this may fail due to cross-origin restrictions.
|
|
776
|
+
|
|
777
|
+
For web apps, verify TEE attestations on the server:
|
|
778
|
+
|
|
779
|
+
```javascript
|
|
780
|
+
const response = await fetch('/api/verify-tee', {
|
|
781
|
+
method: 'POST',
|
|
782
|
+
headers: { 'Content-Type': 'application/json' },
|
|
783
|
+
body: JSON.stringify({ proofs }),
|
|
784
|
+
});
|
|
785
|
+
|
|
786
|
+
const { results } = await response.json();
|
|
787
|
+
console.log(results);
|
|
788
|
+
```
|
|
789
|
+
|
|
790
|
+
The server route should read the app secret from environment variables only (never accept it from the client request body). See the example app for a reference implementation:
|
|
791
|
+
- `example/src/app/api/verify-tee/route.ts`
|
|
792
|
+
|
|
760
793
|
## Error Handling
|
|
761
794
|
|
|
762
795
|
The SDK provides specific error types for different failure scenarios. Here's how to handle them:
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
|
+
declare const SUPPORTED_TEE_ATTESTATION_VERSIONS: readonly ["v2", "v3"];
|
|
2
|
+
type TeeAttestationVersion = typeof SUPPORTED_TEE_ATTESTATION_VERSIONS[number];
|
|
1
3
|
interface TeeAttestation {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
+
proof_version: TeeAttestationVersion;
|
|
5
|
+
tee_provider: string;
|
|
6
|
+
tee_technology: string;
|
|
4
7
|
nonce: string;
|
|
5
|
-
snp_report: string;
|
|
6
|
-
vlek_cert: string;
|
|
7
8
|
timestamp: string;
|
|
9
|
+
workload: {
|
|
10
|
+
container_name: string;
|
|
11
|
+
image_digest: string;
|
|
12
|
+
};
|
|
13
|
+
verifier: {
|
|
14
|
+
container_name: string;
|
|
15
|
+
image_digest: string;
|
|
16
|
+
};
|
|
17
|
+
attestation: {
|
|
18
|
+
token: string;
|
|
19
|
+
};
|
|
20
|
+
error?: {
|
|
21
|
+
code: string;
|
|
22
|
+
message: string;
|
|
23
|
+
};
|
|
8
24
|
}
|
|
9
25
|
interface Proof {
|
|
10
26
|
identifier: string;
|
|
@@ -56,6 +72,7 @@ interface Context {
|
|
|
56
72
|
applicationId: string;
|
|
57
73
|
sessionId: string;
|
|
58
74
|
timestamp: string;
|
|
75
|
+
attestationVersion?: TeeAttestationVersion;
|
|
59
76
|
};
|
|
60
77
|
}
|
|
61
78
|
interface Beacon {
|
|
@@ -345,13 +362,22 @@ type ValidationConfig = ValidationConfigWithHash | ValidationConfigWithProviderI
|
|
|
345
362
|
* Describes the comprehensive configuration required to initialize the proof verification process.
|
|
346
363
|
* Aligns with `ValidationConfig` options for verifying signatures alongside proof contents.
|
|
347
364
|
*/
|
|
365
|
+
type TeeAttestationConfig = {
|
|
366
|
+
/**
|
|
367
|
+
* Your application secret (Ethereum private key).
|
|
368
|
+
* Used to recompute the TEE attestation nonce and to derive the application ID
|
|
369
|
+
* for binding the attestation to your application.
|
|
370
|
+
*/
|
|
371
|
+
appSecret: string;
|
|
372
|
+
};
|
|
348
373
|
type VerificationConfig = ValidationConfig & {
|
|
349
374
|
/**
|
|
350
|
-
*
|
|
351
|
-
* When
|
|
352
|
-
*
|
|
375
|
+
* TEE attestation verification configuration.
|
|
376
|
+
* When provided, verifies the TEE attestation included in the proof.
|
|
377
|
+
* The result will include `isTeeAttestationVerified` and `isVerified` will be false
|
|
378
|
+
* if TEE attestation data is missing or verification fails.
|
|
353
379
|
*/
|
|
354
|
-
|
|
380
|
+
teeAttestation?: TeeAttestationConfig;
|
|
355
381
|
};
|
|
356
382
|
declare function assertValidProofsByHash(proofs: Proof[], config: ProviderHashRequirementsConfig): void;
|
|
357
383
|
declare function isHttpProviderClaimParams(claimParams: unknown): claimParams is HttpProviderClaimParams;
|
|
@@ -480,7 +506,9 @@ type ProofRequestOptions = {
|
|
|
480
506
|
*/
|
|
481
507
|
metadata?: Record<string, string>;
|
|
482
508
|
/**
|
|
483
|
-
*
|
|
509
|
+
* Generates a TEE attestation nonce during session initialization and expects a TEE attestation in the proof.
|
|
510
|
+
*
|
|
511
|
+
* @default true
|
|
484
512
|
*/
|
|
485
513
|
acceptTeeAttestation?: boolean;
|
|
486
514
|
};
|
|
@@ -665,6 +693,8 @@ type TemplateData = {
|
|
|
665
693
|
canAutoSubmit?: boolean;
|
|
666
694
|
metadata?: Record<string, string>;
|
|
667
695
|
preferredLocale?: ProofRequestOptions['preferredLocale'];
|
|
696
|
+
acceptTeeAttestation?: boolean;
|
|
697
|
+
teeAttestationVersion?: TeeAttestationVersion;
|
|
668
698
|
};
|
|
669
699
|
type TrustedData = {
|
|
670
700
|
context: Record<string, unknown>;
|
|
@@ -672,14 +702,14 @@ type TrustedData = {
|
|
|
672
702
|
};
|
|
673
703
|
type VerifyProofResultSuccess = {
|
|
674
704
|
isVerified: true;
|
|
675
|
-
|
|
705
|
+
isTeeAttestationVerified?: boolean;
|
|
676
706
|
error: undefined;
|
|
677
707
|
data: TrustedData[];
|
|
678
708
|
publicData: any[];
|
|
679
709
|
};
|
|
680
710
|
type VerifyProofResultFailure = {
|
|
681
711
|
isVerified: false;
|
|
682
|
-
|
|
712
|
+
isTeeAttestationVerified?: boolean;
|
|
683
713
|
error: Error;
|
|
684
714
|
data: [];
|
|
685
715
|
publicData: [];
|
|
@@ -743,8 +773,8 @@ type ProviderHashRequirementsResponse = {
|
|
|
743
773
|
* * All 3 functions above are alternatives of each other and result from these functions can be directly used as `config` parameter in this function for proof validation.
|
|
744
774
|
*
|
|
745
775
|
* @param proofOrProofs - A single proof object or an array of proof objects to be verified.
|
|
746
|
-
* @param config - Verification configuration that specifies required hashes, allowed extra hashes, or disables content validation. Optionally includes `
|
|
747
|
-
* @returns Verification result with `isVerified`, extracted `data` from each proof, optional `error` on failure
|
|
776
|
+
* @param config - Verification configuration that specifies required hashes, allowed extra hashes, or disables content validation. Optionally includes `teeAttestation` to require TEE attestation verification.
|
|
777
|
+
* @returns Verification result with `isVerified`, `isTeeAttestationVerified` (always boolean), extracted `data` from each proof, and optional `error` on failure. The application ID is derived from `appSecret` automatically.
|
|
748
778
|
*
|
|
749
779
|
* @example
|
|
750
780
|
* ```typescript
|
|
@@ -752,7 +782,7 @@ type ProviderHashRequirementsResponse = {
|
|
|
752
782
|
* const { isVerified, data } = await verifyProof(proof, request.getProviderVersion());
|
|
753
783
|
*
|
|
754
784
|
* // With TEE attestation verification (fails if TEE data is missing or invalid)
|
|
755
|
-
* const { isVerified,
|
|
785
|
+
* const { isVerified, isTeeAttestationVerified, data } = await verifyProof(proof, { ...request.getProviderVersion(), teeAttestation: { appSecret: APP_SECRET } });
|
|
756
786
|
*
|
|
757
787
|
* // Or, by manually providing the details:
|
|
758
788
|
*
|
|
@@ -1469,11 +1499,30 @@ declare function hashProofClaimParams(params: HttpProviderClaimParams): string |
|
|
|
1469
1499
|
*/
|
|
1470
1500
|
declare function getProviderParamsAsCanonicalizedString(params: HttpProviderClaimParams): string[];
|
|
1471
1501
|
|
|
1502
|
+
type TeeVerificationResult = {
|
|
1503
|
+
isVerified: boolean;
|
|
1504
|
+
error?: string;
|
|
1505
|
+
};
|
|
1472
1506
|
/**
|
|
1473
1507
|
* Validates the hardware TEE attestation included in the proof.
|
|
1474
|
-
*
|
|
1508
|
+
* Derives the application ID from `appSecret` and verifies the attestation
|
|
1509
|
+
* was generated for your application.
|
|
1510
|
+
* Returns a result object with `isVerified` and an optional `error` message.
|
|
1511
|
+
*
|
|
1512
|
+
* @param proof - The proof containing TEE attestation data
|
|
1513
|
+
* @param appSecret - Your application secret (Ethereum private key). Used to
|
|
1514
|
+
* derive the application ID and recompute the attestation nonce.
|
|
1515
|
+
*/
|
|
1516
|
+
declare function verifyTeeAttestation(proof: Proof, appSecret: string): Promise<TeeVerificationResult>;
|
|
1517
|
+
/**
|
|
1518
|
+
* Verifies TEE attestation for all proofs.
|
|
1519
|
+
* Throws `TeeVerificationError` if any proof is missing TEE data or fails verification.
|
|
1520
|
+
*
|
|
1521
|
+
* @param proofs - The proofs to verify
|
|
1522
|
+
* @param config - TEE attestation configuration containing the app secret
|
|
1523
|
+
* @throws {TeeVerificationError} When TEE data is missing or verification fails
|
|
1475
1524
|
*/
|
|
1476
|
-
declare function
|
|
1525
|
+
declare function runTeeVerification(proofs: Proof[], config: TeeAttestationConfig): Promise<void>;
|
|
1477
1526
|
|
|
1478
1527
|
declare const TeeVerificationError: {
|
|
1479
1528
|
new (message?: string, innerError?: unknown | undefined): {
|
|
@@ -1516,4 +1565,4 @@ declare function isDesktopDevice(): boolean;
|
|
|
1516
1565
|
*/
|
|
1517
1566
|
declare function clearDeviceCache(): void;
|
|
1518
1567
|
|
|
1519
|
-
export { type Beacon, type BeaconState, type BodySniff, ClaimCreationType, type ClaimID, type ClaimInfo, type CompleteClaimData, type Context, type CreateVerificationRequest, DeviceType, type EmbeddedFlowHandle, type ExtensionMessage, type FlowHandle, type HashRequirement, type HashableHttpProviderClaimParams, type HttpFormEntry, type HttpProviderClaimParams, type HttpRedirectionMethod, type HttpRedirectionOptions, type InitSessionResponse, type InjectedRequestSpec, type InterceptorRequestSpec, type ModalOptions, type OnError, type OnSuccess, type Proof, type ProofPropertiesJSON, type ProofRequestOptions, type ProviderClaimData, type ProviderConfigResponse, type ProviderHashRequirementSpec, type ProviderHashRequirementsConfig, type ProviderHashRequirementsResponse, type ProviderVersionConfig, type ProviderVersionInfo, RECLAIM_EXTENSION_ACTIONS, type ReclaimFlowInitOptions, type ReclaimFlowLaunchOptions, ReclaimProofRequest, type ReclaimProviderConfig, type ReclaimProviderConfigWithRequestSpec, type RequestSpec, type ResponseMatchSpec, type ResponseRedactionSpec, type SerializableModalOptions, SessionStatus, type SignedClaim, type StartSessionParams, type StatusUrlResponse, type TeeAttestation, TeeVerificationError, type TemplateData, type TrustedData, type UpdateSessionResponse, type ValidationConfig, type ValidationConfigWithDisabledValidation, type ValidationConfigWithHash, type ValidationConfigWithProviderInformation, type VerificationConfig, type VerifyProofResult, type VerifyProofResultFailure, type VerifyProofResultSuccess, type WitnessData, assertValidProofsByHash, assertValidateProof, assertVerifiedProof, clearDeviceCache, createLinkWithTemplateData, createSignDataForClaim, fetchProviderConfigs, fetchProviderHashRequirementsBy, fetchStatusUrl, generateSpecsFromRequestSpecTemplate, getAttestors, getDeviceType, getHttpProviderClaimParamsFromProof, getIdentifierFromClaimInfo, getMobileDeviceType, getProviderHashRequirementSpecFromProviderConfig, getProviderHashRequirementsFromSpec, getProviderParamsAsCanonicalizedString, getShortenedUrl, hashProofClaimParams, hashRequestSpec, initSession, isDesktopDevice, isHttpProviderClaimParams, isMobileDevice, recoverSignersOfSignedClaim, takePairsWhereValueIsArray, takeTemplateParametersFromProofs, transformForOnchain, updateSession, verifyProof, verifyTeeAttestation };
|
|
1568
|
+
export { type Beacon, type BeaconState, type BodySniff, ClaimCreationType, type ClaimID, type ClaimInfo, type CompleteClaimData, type Context, type CreateVerificationRequest, DeviceType, type EmbeddedFlowHandle, type ExtensionMessage, type FlowHandle, type HashRequirement, type HashableHttpProviderClaimParams, type HttpFormEntry, type HttpProviderClaimParams, type HttpRedirectionMethod, type HttpRedirectionOptions, type InitSessionResponse, type InjectedRequestSpec, type InterceptorRequestSpec, type ModalOptions, type OnError, type OnSuccess, type Proof, type ProofPropertiesJSON, type ProofRequestOptions, type ProviderClaimData, type ProviderConfigResponse, type ProviderHashRequirementSpec, type ProviderHashRequirementsConfig, type ProviderHashRequirementsResponse, type ProviderVersionConfig, type ProviderVersionInfo, RECLAIM_EXTENSION_ACTIONS, type ReclaimFlowInitOptions, type ReclaimFlowLaunchOptions, ReclaimProofRequest, type ReclaimProviderConfig, type ReclaimProviderConfigWithRequestSpec, type RequestSpec, type ResponseMatchSpec, type ResponseRedactionSpec, SUPPORTED_TEE_ATTESTATION_VERSIONS, type SerializableModalOptions, SessionStatus, type SignedClaim, type StartSessionParams, type StatusUrlResponse, type TeeAttestation, type TeeAttestationConfig, type TeeAttestationVersion, TeeVerificationError, type TeeVerificationResult, type TemplateData, type TrustedData, type UpdateSessionResponse, type ValidationConfig, type ValidationConfigWithDisabledValidation, type ValidationConfigWithHash, type ValidationConfigWithProviderInformation, type VerificationConfig, type VerifyProofResult, type VerifyProofResultFailure, type VerifyProofResultSuccess, type WitnessData, assertValidProofsByHash, assertValidateProof, assertVerifiedProof, clearDeviceCache, createLinkWithTemplateData, createSignDataForClaim, fetchProviderConfigs, fetchProviderHashRequirementsBy, fetchStatusUrl, generateSpecsFromRequestSpecTemplate, getAttestors, getDeviceType, getHttpProviderClaimParamsFromProof, getIdentifierFromClaimInfo, getMobileDeviceType, getProviderHashRequirementSpecFromProviderConfig, getProviderHashRequirementsFromSpec, getProviderParamsAsCanonicalizedString, getShortenedUrl, hashProofClaimParams, hashRequestSpec, initSession, isDesktopDevice, isHttpProviderClaimParams, isMobileDevice, recoverSignersOfSignedClaim, runTeeVerification, takePairsWhereValueIsArray, takeTemplateParametersFromProofs, transformForOnchain, updateSession, verifyProof, verifyTeeAttestation };
|