@reclaimprotocol/client 0.1.27 → 0.1.28

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.
Files changed (73) hide show
  1. package/README.md +634 -42
  2. package/lib/api-client.d.ts +31 -0
  3. package/lib/api-client.js +112 -0
  4. package/lib/api-consts.d.ts +4 -0
  5. package/lib/api-consts.js +4 -0
  6. package/lib/api-errors.d.ts +13 -0
  7. package/lib/api-errors.js +30 -0
  8. package/lib/api.d.ts +7 -0
  9. package/lib/api.js +3 -0
  10. package/lib/attestor-proof.d.ts +6 -0
  11. package/lib/attestor-proof.js +45 -18
  12. package/lib/client.d.ts +1 -6
  13. package/lib/client.js +12 -33
  14. package/lib/consts.d.ts +1 -1
  15. package/lib/consts.js +1 -1
  16. package/lib/eip191.d.ts +4 -2
  17. package/lib/eip191.js +17 -1
  18. package/lib/errors.d.ts +38 -4
  19. package/lib/errors.js +99 -16
  20. package/lib/index.d.ts +9 -7
  21. package/lib/index.js +8 -4
  22. package/lib/jwks.d.ts +25 -1
  23. package/lib/jwks.js +69 -4
  24. package/lib/legacy-proof.d.ts +57 -0
  25. package/lib/legacy-proof.js +211 -0
  26. package/lib/proof-hash.d.ts +35 -0
  27. package/lib/proof-hash.js +216 -0
  28. package/lib/proof-recipe.d.ts +18 -0
  29. package/lib/proof-recipe.js +37 -0
  30. package/lib/proof-trust-constants.d.ts +3 -0
  31. package/lib/proof-trust-constants.js +43 -0
  32. package/lib/proof-types.d.ts +62 -0
  33. package/lib/proof-types.js +1 -0
  34. package/lib/proof-verification-error.d.ts +13 -0
  35. package/lib/proof-verification-error.js +11 -0
  36. package/lib/reclaim.d.ts +27 -5
  37. package/lib/reclaim.js +140 -14
  38. package/lib/result.d.ts +58 -6
  39. package/lib/result.js +252 -61
  40. package/lib/routes.gen.d.ts +54 -6
  41. package/lib/routes.gen.js +15 -3
  42. package/lib/tee-binding.d.ts +82 -0
  43. package/lib/tee-binding.js +112 -0
  44. package/lib/types/openapi.gen.d.ts +1343 -206
  45. package/lib/verification-clients.d.ts +17 -0
  46. package/lib/verification-clients.js +14 -0
  47. package/lib/verify-attestor-tee.d.ts +76 -0
  48. package/lib/verify-attestor-tee.js +243 -0
  49. package/lib/verify-tee.d.ts +32 -0
  50. package/lib/verify-tee.js +347 -0
  51. package/package.json +5 -1
  52. package/src/api.ts +15 -0
  53. package/src/attestor-proof.ts +57 -20
  54. package/src/client.ts +15 -38
  55. package/src/consts.ts +1 -2
  56. package/src/eip191.ts +31 -3
  57. package/src/errors.ts +132 -18
  58. package/src/index.ts +50 -5
  59. package/src/jwks.ts +128 -5
  60. package/src/legacy-proof.ts +367 -0
  61. package/src/proof-hash.ts +316 -0
  62. package/src/proof-recipe.ts +75 -0
  63. package/src/proof-trust-constants.ts +45 -0
  64. package/src/proof-types.ts +57 -0
  65. package/src/proof-verification-error.ts +13 -0
  66. package/src/reclaim.ts +206 -19
  67. package/src/result.ts +403 -68
  68. package/src/routes.gen.ts +15 -3
  69. package/src/tee-binding.ts +192 -0
  70. package/src/types/openapi.gen.ts +1343 -206
  71. package/src/verification-clients.ts +22 -0
  72. package/src/verify-attestor-tee.ts +365 -0
  73. package/src/verify-tee.ts +507 -0
@@ -0,0 +1,82 @@
1
+ /** The exact domain used by the legacy JS SDK's hash-based TEE nonce. */
2
+ export declare const LEGACY_TEE_NONCE_DOMAIN = "RECLAIM_TEE_NONCE_V1";
3
+ /** The version that legacy SDK clients put in `attestationNonceData`. */
4
+ export declare const LEGACY_TEE_ATTESTATION_VERSION = "v3";
5
+ /** Domain for the authenticated, Builder-specific nonce registration. */
6
+ export declare const BUILDER_TEE_BINDING_DOMAIN = "RECLAIM_BUILDER_TEE_BINDING_V1";
7
+ /** The exact nonce context shape preserved into an emitted legacy proof. */
8
+ export interface LegacyTeeNonceData {
9
+ applicationId: string;
10
+ sessionId: string;
11
+ /** Decimal Unix milliseconds. Do not convert to Unix seconds. */
12
+ timestamp: string;
13
+ attestationVersion: typeof LEGACY_TEE_ATTESTATION_VERSION;
14
+ }
15
+ /** A legacy nonce and its context, forwarded unchanged by a VC. */
16
+ export interface LegacyTeeNonceContext {
17
+ attestationNonce: string;
18
+ attestationNonceData: LegacyTeeNonceData;
19
+ }
20
+ export type LegacyTeeNonceMode = 'hash' | 'signature';
21
+ /** Fields authenticated when registering a TEE binding with Builder. */
22
+ export interface BuilderTeeBindingPayload extends LegacyTeeNonceContext {
23
+ organizationId: string;
24
+ }
25
+ /** Builder registration data. `signature` is EIP-191 / `personal_sign`. */
26
+ export interface BuilderTeeBinding extends BuilderTeeBindingPayload {
27
+ payload: string;
28
+ signature: string;
29
+ }
30
+ /**
31
+ * Return the EIP-55 application ID a legacy verifier derives from an app
32
+ * secret. This is intentionally checksummed rather than the SDK's usual
33
+ * lowercase org address: the original SDK uses `ethers.Wallet(secret).address`.
34
+ */
35
+ export declare function legacyApplicationIdFromPrivateKey(privateKey: string): string;
36
+ /**
37
+ * Derive the exact 64-character lowercase nonce generated by the legacy SDK.
38
+ * `applicationId` is serialized byte-for-byte; it is deliberately not
39
+ * normalized here because legacy `generateAttestationNonce` does not normalize
40
+ * it either.
41
+ */
42
+ export declare function deriveLegacyTeeNonce(appSecret: string, data: Pick<LegacyTeeNonceData, 'applicationId' | 'sessionId' | 'timestamp'>): string;
43
+ /**
44
+ * Produce the older legacy nonce: an EIP-191 signature over
45
+ * `keccak256(applicationId:sessionId:timestamp)`. This is a nonce encoding,
46
+ * not a TEE attestation-version number; v2 and v3 attestations can carry it.
47
+ */
48
+ export declare function deriveLegacySignatureTeeNonce(appSecret: string, data: Pick<LegacyTeeNonceData, 'applicationId' | 'sessionId' | 'timestamp'>): string;
49
+ /**
50
+ * Create the legacy TEE context after Builder returns a session ID. Its
51
+ * application ID is derived from the same private key that later verifies the
52
+ * proof, so legacy TEE application binding succeeds without sending that key
53
+ * to Builder.
54
+ */
55
+ export declare function createLegacyTeeNonceContext(input: {
56
+ organizationVerificationPrivateKey: string;
57
+ sessionId: string;
58
+ /** Decimal Unix milliseconds, typically `Date.now().toString()`. */
59
+ timestamp: string;
60
+ /** Defaults to the current hash nonce. Use `signature` for old clients. */
61
+ nonceMode?: LegacyTeeNonceMode;
62
+ }): LegacyTeeNonceContext;
63
+ /**
64
+ * Canonical payload for Builder TEE-binding registration. Every field is a
65
+ * string and the fixed field order avoids JSON canonicalization differences.
66
+ */
67
+ export declare function builderTeeBindingPayload(payload: BuilderTeeBindingPayload): string;
68
+ /** Sign a canonical Builder TEE-binding payload using EIP-191.
69
+ * `personal_sign` callers can use the returned signature directly. */
70
+ export declare function signBuilderTeeBinding(payload: BuilderTeeBindingPayload, organizationVerificationPrivateKey: string): string;
71
+ /**
72
+ * Create a nonce context and its signed Builder registration in one local,
73
+ * stateless operation. The private key appears only as a function input and is
74
+ * never included in the returned object.
75
+ */
76
+ export declare function createBuilderTeeBinding(input: {
77
+ organizationId: string;
78
+ organizationVerificationPrivateKey: string;
79
+ sessionId: string;
80
+ timestamp: string;
81
+ nonceMode?: LegacyTeeNonceMode;
82
+ }): BuilderTeeBinding;
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Stateless helpers for registering an organization-owned, legacy-compatible
3
+ * TEE nonce with Builder after a verification session exists. The organization
4
+ * verification private key is used only locally: it derives the legacy app ID,
5
+ * produces the nonce, and signs the Builder registration payload.
6
+ */
7
+ import { keccak_256 } from '@noble/hashes/sha3.js';
8
+ import { signEip191 } from "./eip191.js";
9
+ import { bytesToHex } from "./encoding.js";
10
+ import { deriveFromPrivateKey } from "./keypair.js";
11
+ /** The exact domain used by the legacy JS SDK's hash-based TEE nonce. */
12
+ export const LEGACY_TEE_NONCE_DOMAIN = 'RECLAIM_TEE_NONCE_V1';
13
+ /** The version that legacy SDK clients put in `attestationNonceData`. */
14
+ export const LEGACY_TEE_ATTESTATION_VERSION = 'v3';
15
+ /** Domain for the authenticated, Builder-specific nonce registration. */
16
+ export const BUILDER_TEE_BINDING_DOMAIN = 'RECLAIM_BUILDER_TEE_BINDING_V1';
17
+ /**
18
+ * Return the EIP-55 application ID a legacy verifier derives from an app
19
+ * secret. This is intentionally checksummed rather than the SDK's usual
20
+ * lowercase org address: the original SDK uses `ethers.Wallet(secret).address`.
21
+ */
22
+ export function legacyApplicationIdFromPrivateKey(privateKey) {
23
+ const address = deriveFromPrivateKey(privateKey).address.slice(2);
24
+ const addressHash = bytesToHex(keccak_256(new TextEncoder().encode(address)));
25
+ const checksummed = [...address].map((char, index) => (Number.parseInt(addressHash[index], 16) >= 8
26
+ ? char.toUpperCase()
27
+ : char)).join('');
28
+ return '0x' + checksummed;
29
+ }
30
+ /**
31
+ * Derive the exact 64-character lowercase nonce generated by the legacy SDK.
32
+ * `applicationId` is serialized byte-for-byte; it is deliberately not
33
+ * normalized here because legacy `generateAttestationNonce` does not normalize
34
+ * it either.
35
+ */
36
+ export function deriveLegacyTeeNonce(appSecret, data) {
37
+ const payload = [
38
+ LEGACY_TEE_NONCE_DOMAIN,
39
+ data.applicationId,
40
+ data.sessionId,
41
+ data.timestamp,
42
+ appSecret,
43
+ ].join(':');
44
+ return bytesToHex(keccak_256(new TextEncoder().encode(payload)));
45
+ }
46
+ /**
47
+ * Produce the older legacy nonce: an EIP-191 signature over
48
+ * `keccak256(applicationId:sessionId:timestamp)`. This is a nonce encoding,
49
+ * not a TEE attestation-version number; v2 and v3 attestations can carry it.
50
+ */
51
+ export function deriveLegacySignatureTeeNonce(appSecret, data) {
52
+ const message = [data.applicationId, data.sessionId, data.timestamp].join(':');
53
+ return signEip191(keccak_256(new TextEncoder().encode(message)), appSecret);
54
+ }
55
+ /**
56
+ * Create the legacy TEE context after Builder returns a session ID. Its
57
+ * application ID is derived from the same private key that later verifies the
58
+ * proof, so legacy TEE application binding succeeds without sending that key
59
+ * to Builder.
60
+ */
61
+ export function createLegacyTeeNonceContext(input) {
62
+ const attestationNonceData = {
63
+ applicationId: legacyApplicationIdFromPrivateKey(input.organizationVerificationPrivateKey),
64
+ sessionId: input.sessionId,
65
+ timestamp: input.timestamp,
66
+ attestationVersion: LEGACY_TEE_ATTESTATION_VERSION,
67
+ };
68
+ return {
69
+ attestationNonce: input.nonceMode === 'signature'
70
+ ? deriveLegacySignatureTeeNonce(input.organizationVerificationPrivateKey, attestationNonceData)
71
+ : deriveLegacyTeeNonce(input.organizationVerificationPrivateKey, attestationNonceData),
72
+ attestationNonceData,
73
+ };
74
+ }
75
+ /**
76
+ * Canonical payload for Builder TEE-binding registration. Every field is a
77
+ * string and the fixed field order avoids JSON canonicalization differences.
78
+ */
79
+ export function builderTeeBindingPayload(payload) {
80
+ const { organizationId, attestationNonce, attestationNonceData } = payload;
81
+ return [
82
+ BUILDER_TEE_BINDING_DOMAIN,
83
+ organizationId,
84
+ attestationNonceData.sessionId,
85
+ attestationNonceData.applicationId,
86
+ attestationNonceData.timestamp,
87
+ attestationNonceData.attestationVersion,
88
+ attestationNonce,
89
+ ].join(':');
90
+ }
91
+ /** Sign a canonical Builder TEE-binding payload using EIP-191.
92
+ * `personal_sign` callers can use the returned signature directly. */
93
+ export function signBuilderTeeBinding(payload, organizationVerificationPrivateKey) {
94
+ return signEip191(builderTeeBindingPayload(payload), organizationVerificationPrivateKey);
95
+ }
96
+ /**
97
+ * Create a nonce context and its signed Builder registration in one local,
98
+ * stateless operation. The private key appears only as a function input and is
99
+ * never included in the returned object.
100
+ */
101
+ export function createBuilderTeeBinding(input) {
102
+ const context = createLegacyTeeNonceContext(input);
103
+ const payload = {
104
+ organizationId: input.organizationId,
105
+ ...context,
106
+ };
107
+ return {
108
+ ...payload,
109
+ payload: builderTeeBindingPayload(payload),
110
+ signature: signBuilderTeeBinding(payload, input.organizationVerificationPrivateKey),
111
+ };
112
+ }