@reclaimprotocol/js-sdk 5.2.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 CHANGED
@@ -705,16 +705,18 @@ const { isVerified } = await verifyProof(proof, {
705
705
 
706
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
- ### Enabling TEE Attestation
708
+ ### Requesting TEE Attestation
709
709
 
710
- To request TEE attestation during proof generation, enable it during initialization:
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
 
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
+
718
720
  ### Verifying TEE Attestation via `verifyProof`
719
721
 
720
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`.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
+ declare const SUPPORTED_TEE_ATTESTATION_VERSIONS: readonly ["v2", "v3"];
2
+ type TeeAttestationVersion = typeof SUPPORTED_TEE_ATTESTATION_VERSIONS[number];
1
3
  interface TeeAttestation {
2
- proof_version: string;
4
+ proof_version: TeeAttestationVersion;
3
5
  tee_provider: string;
4
6
  tee_technology: string;
5
7
  nonce: string;
@@ -70,6 +72,7 @@ interface Context {
70
72
  applicationId: string;
71
73
  sessionId: string;
72
74
  timestamp: string;
75
+ attestationVersion?: TeeAttestationVersion;
73
76
  };
74
77
  }
75
78
  interface Beacon {
@@ -503,7 +506,9 @@ type ProofRequestOptions = {
503
506
  */
504
507
  metadata?: Record<string, string>;
505
508
  /**
506
- * If true, generates a TEE attestation nonce during session initialization and expects a TEE attestation in the proof.
509
+ * Generates a TEE attestation nonce during session initialization and expects a TEE attestation in the proof.
510
+ *
511
+ * @default true
507
512
  */
508
513
  acceptTeeAttestation?: boolean;
509
514
  };
@@ -688,6 +693,8 @@ type TemplateData = {
688
693
  canAutoSubmit?: boolean;
689
694
  metadata?: Record<string, string>;
690
695
  preferredLocale?: ProofRequestOptions['preferredLocale'];
696
+ acceptTeeAttestation?: boolean;
697
+ teeAttestationVersion?: TeeAttestationVersion;
691
698
  };
692
699
  type TrustedData = {
693
700
  context: Record<string, unknown>;
@@ -1558,4 +1565,4 @@ declare function isDesktopDevice(): boolean;
1558
1565
  */
1559
1566
  declare function clearDeviceCache(): void;
1560
1567
 
1561
- 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, type TeeAttestationConfig, 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 };
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 };
package/dist/index.js CHANGED
@@ -84,7 +84,7 @@ var require_package = __commonJS({
84
84
  "package.json"(exports2, module2) {
85
85
  module2.exports = {
86
86
  name: "@reclaimprotocol/js-sdk",
87
- version: "5.2.0",
87
+ version: "5.3.0-dev.1",
88
88
  description: "Designed to request proofs from the Reclaim protocol and manage the flow of claims and witness interactions.",
89
89
  main: "dist/index.js",
90
90
  types: "dist/index.d.ts",
@@ -1694,6 +1694,7 @@ var EXPECTED_ISSUER = "https://confidentialcomputing.googleapis.com";
1694
1694
  var EXPECTED_HW_MODEL = "GCP_AMD_SEV";
1695
1695
  var EXPECTED_TEE_PROVIDER = "gcp";
1696
1696
  var EXPECTED_TEE_TECHNOLOGY = "amd-sev";
1697
+ var SUPPORTED_PROOF_VERSIONS = ["v2", "v3"];
1697
1698
  var TOKEN_CLOCK_SKEW_S = 60;
1698
1699
  var NONCE_TIMESTAMP_MAX_SKEW_MS = 10 * 60 * 1e3;
1699
1700
  var BROWSER_ENVIRONMENT_ERROR = "TEE attestation verification is only supported in non-browser environments. Run verifyTeeAttestation on your server or API route.";
@@ -1933,12 +1934,17 @@ function assertAudienceClaim(aud) {
1933
1934
  }
1934
1935
  throw new Error("attestation token audience is missing");
1935
1936
  }
1937
+ function getProofVersion(teeAttestation) {
1938
+ var _a;
1939
+ return (_a = teeAttestation.proof_version) != null ? _a : teeAttestation.proofVersion;
1940
+ }
1936
1941
  function assertProofShape(teeAttestation) {
1937
1942
  var _a, _b, _c;
1938
1943
  if (teeAttestation.error) {
1939
1944
  throw new Error(`${teeAttestation.error.code}: ${teeAttestation.error.message}`);
1940
1945
  }
1941
- assert(teeAttestation.proof_version === "v2", `unexpected proof version: ${teeAttestation.proof_version}`);
1946
+ const proofVersion = getProofVersion(teeAttestation);
1947
+ assert(typeof proofVersion === "string" && SUPPORTED_PROOF_VERSIONS.includes(proofVersion), `unexpected proof version: ${proofVersion}`);
1942
1948
  assert(teeAttestation.tee_provider === EXPECTED_TEE_PROVIDER, `unexpected tee provider: ${teeAttestation.tee_provider}`);
1943
1949
  assert(teeAttestation.tee_technology === EXPECTED_TEE_TECHNOLOGY, `unexpected tee technology: ${teeAttestation.tee_technology}`);
1944
1950
  assert(typeof teeAttestation.nonce === "string" && teeAttestation.nonce.length > 0, "tee attestation nonce missing");
@@ -1948,6 +1954,26 @@ function assertProofShape(teeAttestation) {
1948
1954
  assert(typeof ((_b = teeAttestation.verifier) == null ? void 0 : _b.image_digest) === "string" && teeAttestation.verifier.image_digest.length > 0, "verifier image digest missing");
1949
1955
  assert(typeof ((_c = teeAttestation.attestation) == null ? void 0 : _c.token) === "string" && teeAttestation.attestation.token.length > 0, "attestation token missing");
1950
1956
  }
1957
+ function computeDigestBinding(teeAttestation) {
1958
+ return __async(this, null, function* () {
1959
+ const proofVersion = getProofVersion(teeAttestation);
1960
+ if (proofVersion === "v3") {
1961
+ assert(typeof teeAttestation.workload.container_name === "string" && teeAttestation.workload.container_name.length > 0, "workload container name missing");
1962
+ assert(typeof teeAttestation.verifier.container_name === "string" && teeAttestation.verifier.container_name.length > 0, "verifier container name missing");
1963
+ return sha256Hex([
1964
+ "v3",
1965
+ `workload.container_name=${teeAttestation.workload.container_name}`,
1966
+ `workload.image_digest=${teeAttestation.workload.image_digest}`,
1967
+ `verifier.container_name=${teeAttestation.verifier.container_name}`,
1968
+ `verifier.image_digest=${teeAttestation.verifier.image_digest}`
1969
+ ].join("\n"));
1970
+ }
1971
+ return sha256Hex(
1972
+ `${teeAttestation.workload.image_digest}
1973
+ ${teeAttestation.verifier.image_digest}`
1974
+ );
1975
+ });
1976
+ }
1951
1977
  function verifyGcpClaims(teeAttestation, expectedNonce) {
1952
1978
  return __async(this, null, function* () {
1953
1979
  var _a;
@@ -1955,10 +1981,7 @@ function verifyGcpClaims(teeAttestation, expectedNonce) {
1955
1981
  assert(claims.iss === EXPECTED_ISSUER, `unexpected issuer: ${claims.iss}`);
1956
1982
  assertAudienceClaim(claims.aud);
1957
1983
  assert(Array.isArray(claims.eat_nonce), "eat_nonce claim missing");
1958
- const digestBinding = yield sha256Hex(
1959
- `${teeAttestation.workload.image_digest}
1960
- ${teeAttestation.verifier.image_digest}`
1961
- );
1984
+ const digestBinding = yield computeDigestBinding(teeAttestation);
1962
1985
  assert(claims.eat_nonce.includes(expectedNonce), "request nonce is not present in attestation token");
1963
1986
  assert(claims.eat_nonce.includes(digestBinding), "digest-binding nonce is not present in attestation token");
1964
1987
  assert(claims.hwmodel === EXPECTED_HW_MODEL, `unexpected hwmodel: ${claims.hwmodel}`);
@@ -2025,6 +2048,7 @@ function runTeeVerification(proofs, config) {
2025
2048
  // src/Reclaim.ts
2026
2049
  var logger10 = logger_default.logger;
2027
2050
  var sdkVersion = require_package().version;
2051
+ var SDK_TEE_ATTESTATION_VERSION = "v3";
2028
2052
  function verifyProof(proofOrProofs, config) {
2029
2053
  return __async(this, null, function* () {
2030
2054
  const proofs = Array.isArray(proofOrProofs) ? proofOrProofs : [proofOrProofs];
@@ -2111,7 +2135,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2111
2135
  * @returns
2112
2136
  */
2113
2137
  this.getTemplateData = () => {
2114
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
2138
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
2115
2139
  if (!this.signature) {
2116
2140
  throw new SignatureNotFoundError("Signature is not set.");
2117
2141
  }
@@ -2151,7 +2175,9 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2151
2175
  log: (_h = (_g = this.options) == null ? void 0 : _g.log) != null ? _h : false,
2152
2176
  canAutoSubmit: (_j = (_i = this.options) == null ? void 0 : _i.canAutoSubmit) != null ? _j : true,
2153
2177
  metadata: (_k = this.options) == null ? void 0 : _k.metadata,
2154
- preferredLocale: (_l = this.options) == null ? void 0 : _l.preferredLocale
2178
+ preferredLocale: (_l = this.options) == null ? void 0 : _l.preferredLocale,
2179
+ acceptTeeAttestation: (_m = this.options) == null ? void 0 : _m.acceptTeeAttestation,
2180
+ teeAttestationVersion: (_o = (_n = this.context.attestationNonceData) == null ? void 0 : _n.attestationVersion) != null ? _o : SDK_TEE_ATTESTATION_VERSION
2155
2181
  };
2156
2182
  return templateData;
2157
2183
  };
@@ -2222,6 +2248,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2222
2248
  */
2223
2249
  static init(applicationId, appSecret, providerId, options) {
2224
2250
  return __async(this, null, function* () {
2251
+ var _a;
2225
2252
  try {
2226
2253
  validateFunctionParams([
2227
2254
  { paramName: "applicationId", input: applicationId, isString: true },
@@ -2303,14 +2330,17 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2303
2330
  }, "the constructor");
2304
2331
  }
2305
2332
  }
2306
- const proofRequestInstance = new _ReclaimProofRequest(applicationId, providerId, options);
2333
+ const proofRequestOptions = __spreadProps(__spreadValues({}, options), {
2334
+ acceptTeeAttestation: (_a = options == null ? void 0 : options.acceptTeeAttestation) != null ? _a : true
2335
+ });
2336
+ const proofRequestInstance = new _ReclaimProofRequest(applicationId, providerId, proofRequestOptions);
2307
2337
  const signature = yield proofRequestInstance.generateSignature(appSecret);
2308
2338
  proofRequestInstance.setSignature(signature);
2309
2339
  const data = yield initSession(providerId, applicationId, proofRequestInstance.timeStamp, signature, options == null ? void 0 : options.providerVersion);
2310
2340
  proofRequestInstance.sessionId = data.sessionId;
2311
2341
  proofRequestInstance.resolvedProviderVersion = data.resolvedProviderVersion;
2312
2342
  proofRequestInstance.context.reclaimSessionId = data.sessionId;
2313
- if (options == null ? void 0 : options.acceptTeeAttestation) {
2343
+ if (proofRequestOptions.acceptTeeAttestation) {
2314
2344
  const attestationNonce = generateAttestationNonce(
2315
2345
  appSecret,
2316
2346
  applicationId,
@@ -2320,7 +2350,8 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2320
2350
  proofRequestInstance.setAttestationContext(attestationNonce, {
2321
2351
  applicationId,
2322
2352
  sessionId: data.sessionId,
2323
- timestamp: proofRequestInstance.timeStamp
2353
+ timestamp: proofRequestInstance.timeStamp,
2354
+ attestationVersion: SDK_TEE_ATTESTATION_VERSION
2324
2355
  });
2325
2356
  }
2326
2357
  return proofRequestInstance;