noah-avalanche-sdk 0.1.2

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 (103) hide show
  1. package/README.md +892 -0
  2. package/dist/core/APIClient.d.ts +71 -0
  3. package/dist/core/APIClient.d.ts.map +1 -0
  4. package/dist/core/APIClient.js +92 -0
  5. package/dist/core/APIClient.js.map +1 -0
  6. package/dist/core/ContractClient.d.ts +38 -0
  7. package/dist/core/ContractClient.d.ts.map +1 -0
  8. package/dist/core/ContractClient.js +209 -0
  9. package/dist/core/ContractClient.js.map +1 -0
  10. package/dist/core/NoahSDK.d.ts +43 -0
  11. package/dist/core/NoahSDK.d.ts.map +1 -0
  12. package/dist/core/NoahSDK.js +93 -0
  13. package/dist/core/NoahSDK.js.map +1 -0
  14. package/dist/core/WalletAdapter.d.ts +188 -0
  15. package/dist/core/WalletAdapter.d.ts.map +1 -0
  16. package/dist/core/WalletAdapter.js +425 -0
  17. package/dist/core/WalletAdapter.js.map +1 -0
  18. package/dist/hooks/index.d.ts +18 -0
  19. package/dist/hooks/index.d.ts.map +1 -0
  20. package/dist/hooks/index.js +15 -0
  21. package/dist/hooks/index.js.map +1 -0
  22. package/dist/hooks/useCredentials.d.ts +136 -0
  23. package/dist/hooks/useCredentials.d.ts.map +1 -0
  24. package/dist/hooks/useCredentials.js +217 -0
  25. package/dist/hooks/useCredentials.js.map +1 -0
  26. package/dist/hooks/useProtocol.d.ts +117 -0
  27. package/dist/hooks/useProtocol.d.ts.map +1 -0
  28. package/dist/hooks/useProtocol.js +165 -0
  29. package/dist/hooks/useProtocol.js.map +1 -0
  30. package/dist/hooks/useUser.d.ts +159 -0
  31. package/dist/hooks/useUser.d.ts.map +1 -0
  32. package/dist/hooks/useUser.js +188 -0
  33. package/dist/hooks/useUser.js.map +1 -0
  34. package/dist/index.d.ts +28 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +26 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/issuer/IssuerClient.d.ts +98 -0
  39. package/dist/issuer/IssuerClient.d.ts.map +1 -0
  40. package/dist/issuer/IssuerClient.js +159 -0
  41. package/dist/issuer/IssuerClient.js.map +1 -0
  42. package/dist/protocol/ProtocolClient.d.ts +124 -0
  43. package/dist/protocol/ProtocolClient.d.ts.map +1 -0
  44. package/dist/protocol/ProtocolClient.js +265 -0
  45. package/dist/protocol/ProtocolClient.js.map +1 -0
  46. package/dist/protocol/RequirementsManager.d.ts +9 -0
  47. package/dist/protocol/RequirementsManager.d.ts.map +1 -0
  48. package/dist/protocol/RequirementsManager.js +9 -0
  49. package/dist/protocol/RequirementsManager.js.map +1 -0
  50. package/dist/user/ProofGenerator.d.ts +49 -0
  51. package/dist/user/ProofGenerator.d.ts.map +1 -0
  52. package/dist/user/ProofGenerator.js +80 -0
  53. package/dist/user/ProofGenerator.js.map +1 -0
  54. package/dist/user/UserClient.d.ts +191 -0
  55. package/dist/user/UserClient.d.ts.map +1 -0
  56. package/dist/user/UserClient.js +338 -0
  57. package/dist/user/UserClient.js.map +1 -0
  58. package/dist/utils/credentials.d.ts +47 -0
  59. package/dist/utils/credentials.d.ts.map +1 -0
  60. package/dist/utils/credentials.js +99 -0
  61. package/dist/utils/credentials.js.map +1 -0
  62. package/dist/utils/identity.d.ts +22 -0
  63. package/dist/utils/identity.d.ts.map +1 -0
  64. package/dist/utils/identity.js +35 -0
  65. package/dist/utils/identity.js.map +1 -0
  66. package/dist/utils/jurisdiction.d.ts +21 -0
  67. package/dist/utils/jurisdiction.d.ts.map +1 -0
  68. package/dist/utils/jurisdiction.js +64 -0
  69. package/dist/utils/jurisdiction.js.map +1 -0
  70. package/dist/utils/mrz.d.ts +16 -0
  71. package/dist/utils/mrz.d.ts.map +1 -0
  72. package/dist/utils/mrz.js +91 -0
  73. package/dist/utils/mrz.js.map +1 -0
  74. package/dist/utils/ocr.d.ts +31 -0
  75. package/dist/utils/ocr.d.ts.map +1 -0
  76. package/dist/utils/ocr.js +69 -0
  77. package/dist/utils/ocr.js.map +1 -0
  78. package/dist/utils/types.d.ts +122 -0
  79. package/dist/utils/types.d.ts.map +1 -0
  80. package/dist/utils/types.js +2 -0
  81. package/dist/utils/types.js.map +1 -0
  82. package/package.json +53 -0
  83. package/src/core/APIClient.ts +165 -0
  84. package/src/core/ContractClient.ts +266 -0
  85. package/src/core/NoahSDK.ts +123 -0
  86. package/src/core/WalletAdapter.ts +546 -0
  87. package/src/hooks/index.ts +31 -0
  88. package/src/hooks/types.d.ts +18 -0
  89. package/src/hooks/useCredentials.ts +359 -0
  90. package/src/hooks/useProtocol.ts +284 -0
  91. package/src/hooks/useUser.ts +331 -0
  92. package/src/index.ts +80 -0
  93. package/src/issuer/IssuerClient.ts +209 -0
  94. package/src/protocol/ProtocolClient.ts +330 -0
  95. package/src/protocol/RequirementsManager.ts +16 -0
  96. package/src/user/ProofGenerator.ts +113 -0
  97. package/src/user/UserClient.ts +440 -0
  98. package/src/utils/credentials.ts +122 -0
  99. package/src/utils/identity.ts +46 -0
  100. package/src/utils/jurisdiction.ts +83 -0
  101. package/src/utils/mrz.ts +113 -0
  102. package/src/utils/ocr.ts +84 -0
  103. package/src/utils/types.ts +144 -0
@@ -0,0 +1,80 @@
1
+ /**
2
+ * ProofGenerator - Browser-side ZK Proof Generation
3
+ *
4
+ * This class manages the lifecycle of the ZK prover:
5
+ * 1. Loading the WASM module
6
+ * 2. Caching artifacts in IndexedDB
7
+ * 3. Executing proofs in a Web Worker (optional but recommended)
8
+ */
9
+ export class ProofGenerator {
10
+ constructor() {
11
+ this.wasmLoaded = false;
12
+ this.wasmBinary = null;
13
+ }
14
+ /**
15
+ * Load the ZK prover artifacts
16
+ * @param wasmUrl - URL to the noah_prover.wasm file
17
+ */
18
+ async loadProver(wasmUrl = '/noah_prover.wasm') {
19
+ if (this.wasmLoaded)
20
+ return;
21
+ try {
22
+ // 1. Try to load from IndexedDB cache
23
+ const cached = await this.getCachedWasm();
24
+ if (cached) {
25
+ this.wasmBinary = cached;
26
+ }
27
+ else {
28
+ // 2. Download from URL
29
+ const response = await fetch(wasmUrl);
30
+ if (!response.ok)
31
+ throw new Error(`Failed to fetch WASM from ${wasmUrl}`);
32
+ this.wasmBinary = await response.arrayBuffer();
33
+ // 3. Cache for next time
34
+ await this.cacheWasm(this.wasmBinary);
35
+ }
36
+ this.wasmLoaded = true;
37
+ }
38
+ catch (error) {
39
+ throw new Error(`Failed to load prover: ${error.message}`);
40
+ }
41
+ }
42
+ /**
43
+ * Generate a ZK proof locally
44
+ * @param input - Circuit assignment data
45
+ */
46
+ async generateProof(input) {
47
+ if (!this.wasmLoaded) {
48
+ await this.loadProver();
49
+ }
50
+ // This is a simulation/placeholder for the Go-WASM bridge call
51
+ // In a real implementation, you would use:
52
+ // const go = new Go();
53
+ // const result = await WebAssembly.instantiate(this.wasmBinary, go.importObject);
54
+ // go.run(result.instance);
55
+ // const proofResult = globalThis.generateNoahProof(JSON.stringify(input));
56
+ console.log('Generating proof locally with input:', input);
57
+ // Simulate some work
58
+ await new Promise(resolve => setTimeout(resolve, 1000));
59
+ return {
60
+ proof: {
61
+ a: ["0", "0"],
62
+ b: [["0", "0"], ["0", "0"]],
63
+ c: ["0", "0"]
64
+ },
65
+ publicSignals: [], // This would be populated by the WASM
66
+ nullifier: "0x" + Math.random().toString(16).substring(2, 66),
67
+ packedFlags: 15, // All checks pass
68
+ success: true
69
+ };
70
+ }
71
+ async getCachedWasm() {
72
+ // Basic IndexedDB retrieval placeholder
73
+ return null;
74
+ }
75
+ async cacheWasm(binary) {
76
+ // Basic IndexedDB storage placeholder
77
+ console.log('Caching WASM binary, size:', binary.byteLength);
78
+ }
79
+ }
80
+ //# sourceMappingURL=ProofGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProofGenerator.js","sourceRoot":"","sources":["../../src/user/ProofGenerator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA4BH,MAAM,OAAO,cAAc;IAIzB;QAHQ,eAAU,GA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C,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;QAExD,OAAO;YACL,KAAK,EAAE;gBACL,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;gBACb,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;gBAC3B,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;aACH;YACZ,aAAa,EAAE,EAAE,EAAE,sCAAsC;YACzD,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC;YAC7D,WAAW,EAAE,EAAE,EAAE,kBAAkB;YACnC,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,aAAa;QACzB,wCAAwC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,KAAK,CAAC,SAAS,CAAC,MAAmB;QACzC,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IAC/D,CAAC;CACF"}
@@ -0,0 +1,191 @@
1
+ import type { Signer } from 'ethers';
2
+ import type { Requirements, ZKProof, TransactionResult, ContractAddresses } from '../utils/types';
3
+ /**
4
+ * Credential data structure for proof generation
5
+ */
6
+ export interface Credential {
7
+ credentialHash: string;
8
+ age: number;
9
+ jurisdiction: string | number;
10
+ accredited: number;
11
+ passportNumber?: string;
12
+ expiryDate?: number;
13
+ userAddress?: string;
14
+ }
15
+ /**
16
+ * Proof generation result
17
+ */
18
+ export interface ProofResult {
19
+ proof: ZKProof;
20
+ publicSignals: string[];
21
+ nullifier: string;
22
+ packedFlags: number;
23
+ credentialHash: string;
24
+ success: boolean;
25
+ }
26
+ /**
27
+ * UserClient configuration options
28
+ */
29
+ export interface UserClientConfig {
30
+ contractAddresses?: Partial<ContractAddresses>;
31
+ rpcUrl?: string;
32
+ wasmUrl?: string;
33
+ mockMode?: boolean;
34
+ }
35
+ /**
36
+ * UserClient - High-level API for end-user applications
37
+ *
38
+ * Provides a simple interface for users to:
39
+ * - Generate ZK proofs from credentials
40
+ * - Verify and grant access to protocols
41
+ * - Check credential validity
42
+ * - Get protocol requirements
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * import { UserClient } from '@noah-protocol/sdk';
47
+ * import { ethers } from 'ethers';
48
+ *
49
+ * const provider = new ethers.BrowserProvider(window.ethereum);
50
+ * const signer = await provider.getSigner();
51
+ * const user = new UserClient(signer);
52
+ *
53
+ * // Generate proof
54
+ * const proof = await user.generateProof(credential, requirements);
55
+ *
56
+ * // Verify and grant access
57
+ * await user.verifyAndGrantAccess(proof, protocolAddress);
58
+ * ```
59
+ */
60
+ export declare class UserClient {
61
+ private signer;
62
+ private contractClient;
63
+ private proofGenerator;
64
+ private mockMode;
65
+ private wasmUrl?;
66
+ private identityManager;
67
+ constructor(signer: Signer, config?: UserClientConfig);
68
+ /**
69
+ * Generate a ZK proof from credential data and protocol requirements
70
+ *
71
+ * @param credential - Credential data (age, jurisdiction, accredited, credentialHash)
72
+ * @param requirements - Protocol requirements (minAge, allowedJurisdictions, requireAccredited)
73
+ * @returns Promise resolving to proof result with proof, publicSignals, and credentialHash
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const credential = {
78
+ * credentialHash: '0x1234...',
79
+ * age: 25,
80
+ * jurisdiction: 'US',
81
+ * accredited: 1,
82
+ * userAddress: '0x...'
83
+ * };
84
+ *
85
+ * const requirements = {
86
+ * protocolAddress: '0x...',
87
+ * minAge: 21,
88
+ * allowedJurisdictions: ['US', 'UK'],
89
+ * requireAccredited: true
90
+ * };
91
+ *
92
+ * const proof = await user.generateProof(credential, requirements);
93
+ * ```
94
+ */
95
+ generateProof(credential: Credential, requirements: Requirements & {
96
+ protocolAddress: string;
97
+ }): Promise<ProofResult>;
98
+ /**
99
+ * High-level method to generate proof directly from an image (OCR -> MRZ -> ZK)
100
+ *
101
+ * @param imageSource - URL, File, or Blob of the document image
102
+ * @param requirements - Protocol requirements
103
+ * @returns Promise resolving to proof result
104
+ */
105
+ proveFromImage(imageSource: string | File | Blob, requirements: Requirements & {
106
+ protocolAddress: string;
107
+ }): Promise<ProofResult>;
108
+ private performPreFlightChecks;
109
+ private generateMockProof;
110
+ /**
111
+ * Verify proof and grant access to a protocol
112
+ *
113
+ * This method calls the smart contract's verifyAndGrantAccess function,
114
+ * which verifies the ZK proof and grants the user access to the protocol.
115
+ *
116
+ * @param proofResult - Proof result from generateProof()
117
+ * @param protocolAddress - Protocol contract address (optional, can be inferred from proof)
118
+ * @param userAddress - User's wallet address (optional, defaults to signer address)
119
+ * @returns Promise resolving to transaction result with hash and receipt
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * const proof = await user.generateProof(credential, requirements);
124
+ * const tx = await user.verifyAndGrantAccess(proof, protocolAddress);
125
+ * console.log('Transaction hash:', tx.transactionHash);
126
+ * ```
127
+ */
128
+ verifyAndGrantAccess(proofResult: ProofResult, protocolAddress?: string, userAddress?: string): Promise<TransactionResult>;
129
+ /**
130
+ * Check if a credential is valid (exists and not revoked)
131
+ *
132
+ * @param credentialHash - The credential hash to check (bytes32)
133
+ * @returns Promise resolving to true if credential is valid, false otherwise
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * const isValid = await user.checkCredentialValidity('0x1234...');
138
+ * if (isValid) {
139
+ * console.log('Credential is valid');
140
+ * }
141
+ * ```
142
+ */
143
+ checkCredentialValidity(credentialHash: string): Promise<boolean>;
144
+ /**
145
+ * Get protocol requirements
146
+ *
147
+ * @param protocolAddress - The protocol contract address
148
+ * @returns Promise resolving to requirements object (minAge, allowedJurisdictions, requireAccredited)
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * const requirements = await user.getProtocolRequirements('0x...');
153
+ * console.log('Min age:', requirements.minAge);
154
+ * console.log('Allowed jurisdictions:', requirements.allowedJurisdictions);
155
+ * ```
156
+ */
157
+ getProtocolRequirements(protocolAddress: string): Promise<Requirements>;
158
+ /**
159
+ * Check if user has access to a protocol
160
+ *
161
+ * @param protocolAddress - The protocol contract address
162
+ * @param userAddress - The user's wallet address (optional, defaults to signer address)
163
+ * @returns Promise resolving to true if user has access, false otherwise
164
+ *
165
+ * @example
166
+ * ```typescript
167
+ * const hasAccess = await user.hasAccess('0x...');
168
+ * if (hasAccess) {
169
+ * console.log('User has access to protocol');
170
+ * }
171
+ * ```
172
+ */
173
+ hasAccess(protocolAddress: string, userAddress?: string): Promise<boolean>;
174
+ /**
175
+ * Get user's credential hash for a protocol
176
+ *
177
+ * @param protocolAddress - The protocol contract address
178
+ * @param userAddress - The user's wallet address (optional, defaults to signer address)
179
+ * @returns Promise resolving to credential hash (bytes32) or empty string if not set
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * const credentialHash = await user.getUserCredential('0x...');
184
+ * if (credentialHash) {
185
+ * console.log('User credential:', credentialHash);
186
+ * }
187
+ * ```
188
+ */
189
+ getUserCredential(protocolAddress: string, userAddress?: string): Promise<string>;
190
+ }
191
+ //# sourceMappingURL=UserClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserClient.d.ts","sourceRoot":"","sources":["../../src/user/UserClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAOlG;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,C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W,EAAE,WAAW,EACxB,eAAe,CAAC,EAAE,MAAM,EACxB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,iBAAiB,CAAC;IAsC7B;;;;;;;;;;;;;OAaG;IACG,uBAAuB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAcvE;;;;;;;;;;;;OAYG;IACG,uBAAuB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAc7E;;;;;;;;;;;;;;OAcG;IACG,SAAS,CACb,eAAe,EAAE,MAAM,EACvB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,OAAO,CAAC;IAgBnB;;;;;;;;;;;;;;OAcG;IACG,iBAAiB,CACrB,eAAe,EAAE,MAAM,EACvB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,MAAM,CAAC;CAenB"}
@@ -0,0 +1,338 @@
1
+ import { ContractClient } from '../core/ContractClient';
2
+ import { ProofGenerator } from './ProofGenerator';
3
+ import { IdentityManager } from '../utils/identity';
4
+ import { jurisdictionStringToHash } from '../utils/jurisdiction';
5
+ import { generateCredentialHash } from '../utils/credentials';
6
+ /**
7
+ * UserClient - High-level API for end-user applications
8
+ *
9
+ * Provides a simple interface for users to:
10
+ * - Generate ZK proofs from credentials
11
+ * - Verify and grant access to protocols
12
+ * - Check credential validity
13
+ * - Get protocol requirements
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { UserClient } from '@noah-protocol/sdk';
18
+ * import { ethers } from 'ethers';
19
+ *
20
+ * const provider = new ethers.BrowserProvider(window.ethereum);
21
+ * const signer = await provider.getSigner();
22
+ * const user = new UserClient(signer);
23
+ *
24
+ * // Generate proof
25
+ * const proof = await user.generateProof(credential, requirements);
26
+ *
27
+ * // Verify and grant access
28
+ * await user.verifyAndGrantAccess(proof, protocolAddress);
29
+ * ```
30
+ */
31
+ export class UserClient {
32
+ constructor(signer, config = {}) {
33
+ if (!signer) {
34
+ throw new Error('Signer is required');
35
+ }
36
+ this.signer = signer;
37
+ this.mockMode = config.mockMode || false;
38
+ this.wasmUrl = config.wasmUrl;
39
+ this.contractClient = new ContractClient({
40
+ provider: signer.provider || undefined,
41
+ contractAddresses: config.contractAddresses,
42
+ rpcUrl: config.rpcUrl,
43
+ });
44
+ this.proofGenerator = new ProofGenerator();
45
+ this.identityManager = new IdentityManager();
46
+ }
47
+ /**
48
+ * Generate a ZK proof from credential data and protocol requirements
49
+ *
50
+ * @param credential - Credential data (age, jurisdiction, accredited, credentialHash)
51
+ * @param requirements - Protocol requirements (minAge, allowedJurisdictions, requireAccredited)
52
+ * @returns Promise resolving to proof result with proof, publicSignals, and credentialHash
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const credential = {
57
+ * credentialHash: '0x1234...',
58
+ * age: 25,
59
+ * jurisdiction: 'US',
60
+ * accredited: 1,
61
+ * userAddress: '0x...'
62
+ * };
63
+ *
64
+ * const requirements = {
65
+ * protocolAddress: '0x...',
66
+ * minAge: 21,
67
+ * allowedJurisdictions: ['US', 'UK'],
68
+ * requireAccredited: true
69
+ * };
70
+ *
71
+ * const proof = await user.generateProof(credential, requirements);
72
+ * ```
73
+ */
74
+ async generateProof(credential, requirements) {
75
+ if (this.mockMode) {
76
+ return this.generateMockProof(credential, requirements);
77
+ }
78
+ // 1. Pre-flight checks
79
+ await this.performPreFlightChecks(credential, requirements);
80
+ try {
81
+ // 2. Prepare inputs for Gnark circuit
82
+ const jurisdictionValue = typeof credential.jurisdiction === 'string'
83
+ ? BigInt(jurisdictionStringToHash(credential.jurisdiction))
84
+ : BigInt(credential.jurisdiction);
85
+ const userAddr = await this.signer.getAddress();
86
+ const passportNum = BigInt('0x' + Buffer.from(credential.passportNumber || '0').toString('hex'));
87
+ const input = {
88
+ actualAge: credential.age,
89
+ actualJurisdiction: Number(jurisdictionValue),
90
+ actualAccredited: credential.accredited,
91
+ credentialHash: credential.credentialHash,
92
+ passportNumber: passportNum.toString(),
93
+ expiryDate: 20300101, // Placeholder: YYYYMMDD
94
+ minAge: requirements.minAge,
95
+ recipientAddress: BigInt(userAddr).toString(),
96
+ currentDate: Math.floor(Date.now() / 1000),
97
+ allowedJurisdictions: (requirements.allowedJurisdictions || []).map(j => Number(BigInt(j))),
98
+ sanctionedCountries: [], // To be populated from on-chain or config
99
+ requireAccredited: requirements.requireAccredited ? 1 : 0,
100
+ credentialHashPublic: credential.credentialHash
101
+ };
102
+ // 3. Load and execute WASM prover
103
+ await this.proofGenerator.loadProver(this.wasmUrl);
104
+ const result = await this.proofGenerator.generateProof(input);
105
+ return {
106
+ proof: result.proof,
107
+ publicSignals: result.publicSignals,
108
+ nullifier: result.nullifier,
109
+ packedFlags: result.packedFlags,
110
+ credentialHash: credential.credentialHash,
111
+ success: result.success,
112
+ };
113
+ }
114
+ catch (error) {
115
+ throw new Error(`Failed to generate proof: ${error.message || 'Unknown error'}`);
116
+ }
117
+ }
118
+ /**
119
+ * High-level method to generate proof directly from an image (OCR -> MRZ -> ZK)
120
+ *
121
+ * @param imageSource - URL, File, or Blob of the document image
122
+ * @param requirements - Protocol requirements
123
+ * @returns Promise resolving to proof result
124
+ */
125
+ async proveFromImage(imageSource, requirements) {
126
+ if (this.mockMode) {
127
+ // Mock credential for testing
128
+ const mockCredential = {
129
+ credentialHash: generateCredentialHash({
130
+ userAddress: 'mock-user',
131
+ age: 25,
132
+ jurisdiction: 'US',
133
+ accredited: true
134
+ }).credentialHash,
135
+ age: 25,
136
+ jurisdiction: 'US',
137
+ accredited: 1,
138
+ passportNumber: 'P12345678',
139
+ };
140
+ return this.generateMockProof(mockCredential, requirements);
141
+ }
142
+ try {
143
+ // 1. Extract data via OCR
144
+ const profile = await this.identityManager.extractFromImage(imageSource);
145
+ // 2. Prepare credential
146
+ const credential = {
147
+ credentialHash: generateCredentialHash({
148
+ userAddress: await this.signer.getAddress(),
149
+ age: profile.age,
150
+ jurisdiction: profile.nationality,
151
+ accredited: false // Default non-accredited, can be updated if logic allows
152
+ }).credentialHash,
153
+ age: profile.age,
154
+ jurisdiction: profile.nationality,
155
+ accredited: 0,
156
+ passportNumber: profile.passportNumber,
157
+ expiryDate: Math.floor(profile.expiryDate.getTime() / 1000)
158
+ };
159
+ // 3. Generate proof
160
+ return await this.generateProof(credential, requirements);
161
+ }
162
+ catch (error) {
163
+ throw new Error(`Failed to prove from image: ${error.message}`);
164
+ }
165
+ finally {
166
+ await this.identityManager.cleanup();
167
+ }
168
+ }
169
+ async performPreFlightChecks(credential, requirements) {
170
+ // Check if credential is valid on-chain
171
+ const isValid = await this.contractClient.isCredentialValid(credential.credentialHash);
172
+ if (!isValid)
173
+ throw new Error('Credential is not valid or has been revoked');
174
+ // Check if nullifier is already used (if we can derive it here)
175
+ // In production, the nullifier should be derived the same way as in the circuit
176
+ // const nullifier = deriveNullifier(credential.passportNumber, requirements.protocolAddress);
177
+ // const isUsed = await this.contractClient.isNullifierUsed(nullifier);
178
+ // if (isUsed) throw new Error('This document has already been used for this protocol');
179
+ }
180
+ async generateMockProof(credential, requirements) {
181
+ console.log('[MockMode] Generating proof for', credential.credentialHash);
182
+ await new Promise(resolve => setTimeout(resolve, 800));
183
+ return {
184
+ proof: { a: ["0", "0"], b: [["0", "0"], ["0", "0"]], c: ["0", "0"] },
185
+ publicSignals: new Array(28).fill("0"),
186
+ nullifier: "0xmocknullifier" + Math.random().toString(16).substring(2, 8),
187
+ packedFlags: 15,
188
+ credentialHash: credential.credentialHash,
189
+ success: true
190
+ };
191
+ }
192
+ /**
193
+ * Verify proof and grant access to a protocol
194
+ *
195
+ * This method calls the smart contract's verifyAndGrantAccess function,
196
+ * which verifies the ZK proof and grants the user access to the protocol.
197
+ *
198
+ * @param proofResult - Proof result from generateProof()
199
+ * @param protocolAddress - Protocol contract address (optional, can be inferred from proof)
200
+ * @param userAddress - User's wallet address (optional, defaults to signer address)
201
+ * @returns Promise resolving to transaction result with hash and receipt
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * const proof = await user.generateProof(credential, requirements);
206
+ * const tx = await user.verifyAndGrantAccess(proof, protocolAddress);
207
+ * console.log('Transaction hash:', tx.transactionHash);
208
+ * ```
209
+ */
210
+ async verifyAndGrantAccess(proofResult, protocolAddress, userAddress) {
211
+ // Remove unused protocolAddress parameter warning
212
+ void protocolAddress;
213
+ if (!proofResult || !proofResult.proof) {
214
+ throw new Error('Proof result is required');
215
+ }
216
+ if (!proofResult.publicSignals || proofResult.publicSignals.length < 13) {
217
+ throw new Error('Public signals are required and must have at least 13 elements');
218
+ }
219
+ if (!proofResult.credentialHash) {
220
+ throw new Error('Credential hash is required in proof result');
221
+ }
222
+ // Get user address from signer if not provided
223
+ const finalUserAddress = userAddress || (await this.signer.getAddress());
224
+ // Note: The contract uses msg.sender (the signer's address) as the protocol address
225
+ // The protocolAddress parameter is kept for API consistency but is not used in the contract call
226
+ try {
227
+ const result = await this.contractClient.verifyAndGrantAccess(this.signer, proofResult.proof, proofResult.publicSignals, proofResult.credentialHash, finalUserAddress);
228
+ return result;
229
+ }
230
+ catch (error) {
231
+ throw new Error(`Failed to verify proof and grant access: ${error.message || 'Unknown error'}`);
232
+ }
233
+ }
234
+ /**
235
+ * Check if a credential is valid (exists and not revoked)
236
+ *
237
+ * @param credentialHash - The credential hash to check (bytes32)
238
+ * @returns Promise resolving to true if credential is valid, false otherwise
239
+ *
240
+ * @example
241
+ * ```typescript
242
+ * const isValid = await user.checkCredentialValidity('0x1234...');
243
+ * if (isValid) {
244
+ * console.log('Credential is valid');
245
+ * }
246
+ * ```
247
+ */
248
+ async checkCredentialValidity(credentialHash) {
249
+ if (!credentialHash) {
250
+ throw new Error('Credential hash is required');
251
+ }
252
+ try {
253
+ return await this.contractClient.isCredentialValid(credentialHash);
254
+ }
255
+ catch (error) {
256
+ throw new Error(`Failed to check credential validity: ${error.message || 'Unknown error'}`);
257
+ }
258
+ }
259
+ /**
260
+ * Get protocol requirements
261
+ *
262
+ * @param protocolAddress - The protocol contract address
263
+ * @returns Promise resolving to requirements object (minAge, allowedJurisdictions, requireAccredited)
264
+ *
265
+ * @example
266
+ * ```typescript
267
+ * const requirements = await user.getProtocolRequirements('0x...');
268
+ * console.log('Min age:', requirements.minAge);
269
+ * console.log('Allowed jurisdictions:', requirements.allowedJurisdictions);
270
+ * ```
271
+ */
272
+ async getProtocolRequirements(protocolAddress) {
273
+ if (!protocolAddress) {
274
+ throw new Error('Protocol address is required');
275
+ }
276
+ try {
277
+ return await this.contractClient.getRequirements(protocolAddress);
278
+ }
279
+ catch (error) {
280
+ throw new Error(`Failed to get protocol requirements: ${error.message || 'Unknown error'}`);
281
+ }
282
+ }
283
+ /**
284
+ * Check if user has access to a protocol
285
+ *
286
+ * @param protocolAddress - The protocol contract address
287
+ * @param userAddress - The user's wallet address (optional, defaults to signer address)
288
+ * @returns Promise resolving to true if user has access, false otherwise
289
+ *
290
+ * @example
291
+ * ```typescript
292
+ * const hasAccess = await user.hasAccess('0x...');
293
+ * if (hasAccess) {
294
+ * console.log('User has access to protocol');
295
+ * }
296
+ * ```
297
+ */
298
+ async hasAccess(protocolAddress, userAddress) {
299
+ if (!protocolAddress) {
300
+ throw new Error('Protocol address is required');
301
+ }
302
+ const finalUserAddress = userAddress || (await this.signer.getAddress());
303
+ try {
304
+ return await this.contractClient.hasAccess(protocolAddress, finalUserAddress);
305
+ }
306
+ catch (error) {
307
+ throw new Error(`Failed to check access: ${error.message || 'Unknown error'}`);
308
+ }
309
+ }
310
+ /**
311
+ * Get user's credential hash for a protocol
312
+ *
313
+ * @param protocolAddress - The protocol contract address
314
+ * @param userAddress - The user's wallet address (optional, defaults to signer address)
315
+ * @returns Promise resolving to credential hash (bytes32) or empty string if not set
316
+ *
317
+ * @example
318
+ * ```typescript
319
+ * const credentialHash = await user.getUserCredential('0x...');
320
+ * if (credentialHash) {
321
+ * console.log('User credential:', credentialHash);
322
+ * }
323
+ * ```
324
+ */
325
+ async getUserCredential(protocolAddress, userAddress) {
326
+ if (!protocolAddress) {
327
+ throw new Error('Protocol address is required');
328
+ }
329
+ const finalUserAddress = userAddress || (await this.signer.getAddress());
330
+ try {
331
+ return await this.contractClient.getUserCredential(protocolAddress, finalUserAddress);
332
+ }
333
+ catch (error) {
334
+ throw new Error(`Failed to get user credential: ${error.message || 'Unknown error'}`);
335
+ }
336
+ }
337
+ }
338
+ //# sourceMappingURL=UserClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserClient.js","sourceRoot":"","sources":["../../src/user/UserClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAoB,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAqC9D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,OAAO,UAAU;IAQrB,YAAY,MAAc,EAAE,SAA2B,EAAE;QACvD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACxC,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,KAAK,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAE9B,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,CAAC;YACvC,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,SAAS;YACtC,iBAAiB,EAAE,MAAM,CAAC,iBAAkD;YAC5E,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC,CAAC;QAEH,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC;QAC3C,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,EAAE,C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AI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC;QACxF,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CACb,kCAAkC,KAAK,CAAC,OAAO,IAAI,eAAe,EAAE,CACrE,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,47 @@
1
+ import type { CredentialData, CredentialHashResult } from './types.js';
2
+ /**
3
+ * Generate a credential hash from user data
4
+ *
5
+ * The credential hash is computed using Keccak256 from a formatted string containing:
6
+ * - User address
7
+ * - Age
8
+ * - Jurisdiction (converted to hash)
9
+ * - Accredited status
10
+ * - Timestamp
11
+ *
12
+ * @param userData - The credential data to hash
13
+ * @returns Object containing the credential hash, jurisdiction hash, credential data string, and timestamp
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const credential = {
18
+ * userAddress: "0x1234...",
19
+ * age: 25,
20
+ * jurisdiction: "US",
21
+ * accredited: true
22
+ * };
23
+ *
24
+ * const result = generateCredentialHash(credential);
25
+ * console.log(result.credentialHash); // "0x..."
26
+ * ```
27
+ */
28
+ export declare function generateCredentialHash(userData: CredentialData): CredentialHashResult;
29
+ /**
30
+ * Validate a credential hash format
31
+ * @param hash - The credential hash to validate
32
+ * @returns True if the hash is valid (starts with 0x and is 66 characters)
33
+ */
34
+ export declare function isValidCredentialHash(hash: string): boolean;
35
+ /**
36
+ * Validate a user address format
37
+ * @param address - The Ethereum address to validate
38
+ * @returns True if the address is valid
39
+ */
40
+ export declare function isValidAddress(address: string): boolean;
41
+ /**
42
+ * Normalize an Ethereum address to checksum format
43
+ * @param address - The address to normalize
44
+ * @returns The checksummed address
45
+ */
46
+ export declare function toChecksumAddress(address: string): string;
47
+ //# sourceMappingURL=credentials.d.ts.map