noah-clarity 0.3.4 → 0.3.6
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/config.d.ts +1 -0
- package/dist/config.js +2 -1
- package/dist/contract.d.ts +14 -2
- package/dist/contract.js +78 -6
- package/dist/types.d.ts +3 -0
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export declare function createSDKConfig(addresses: ContractAddresses, options?:
|
|
|
32
32
|
}): {
|
|
33
33
|
kycRegistryAddress: string;
|
|
34
34
|
attesterRegistryAddress: string;
|
|
35
|
+
revocationRegistryAddress: string;
|
|
35
36
|
network: "testnet" | "mainnet" | "devnet";
|
|
36
37
|
proverServiceUrl: string;
|
|
37
38
|
attesterServiceUrl: string;
|
package/dist/config.js
CHANGED
|
@@ -10,7 +10,7 @@ export const TESTNET_CONTRACTS = {
|
|
|
10
10
|
contracts: {
|
|
11
11
|
'attester-registry': 'STVAH96MR73TP2FZG2W4X220MEB4NEMJHPMVYQNS.Attester-registry',
|
|
12
12
|
'attester-registry-trait': 'STVAH96MR73TP2FZG2W4X220MEB4NEMJHPMVYQNS.attester-registry-trait',
|
|
13
|
-
'kyc-registry': 'STVAH96MR73TP2FZG2W4X220MEB4NEMJHPMVYQNS.
|
|
13
|
+
'kyc-registry': 'STVAH96MR73TP2FZG2W4X220MEB4NEMJHPMVYQNS.KYc-registry',
|
|
14
14
|
'revocation': 'STVAH96MR73TP2FZG2W4X220MEB4NEMJHPMVYQNS.revocation',
|
|
15
15
|
},
|
|
16
16
|
deployment_date: '2025-01-17',
|
|
@@ -40,6 +40,7 @@ export function createSDKConfig(addresses, options) {
|
|
|
40
40
|
return {
|
|
41
41
|
kycRegistryAddress: addresses.contracts['kyc-registry'],
|
|
42
42
|
attesterRegistryAddress: addresses.contracts['attester-registry'],
|
|
43
|
+
revocationRegistryAddress: addresses.contracts['revocation'],
|
|
43
44
|
network: addresses.network,
|
|
44
45
|
proverServiceUrl: options?.proverServiceUrl || 'http://localhost:8080',
|
|
45
46
|
attesterServiceUrl: options?.attesterServiceUrl || 'http://localhost:8081',
|
package/dist/contract.d.ts
CHANGED
|
@@ -20,11 +20,23 @@ export declare class KYCContract {
|
|
|
20
20
|
* @returns KYC status
|
|
21
21
|
*/
|
|
22
22
|
hasKYC(userPrincipal: string): Promise<KYCStatus>;
|
|
23
|
+
/**
|
|
24
|
+
* Get revocation root from the revocation registry contract
|
|
25
|
+
* @returns Revocation root (32-byte hex string) or null if contract not configured
|
|
26
|
+
*/
|
|
27
|
+
getRevocationRoot(): Promise<string | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Check if a commitment is revoked by checking the revocation root
|
|
30
|
+
* Note: This is a simplified check. For full verification, non-membership proofs are needed.
|
|
31
|
+
* @param commitment Commitment to check (hex string)
|
|
32
|
+
* @returns true if revoked, false if not revoked or if revocation checking is unavailable
|
|
33
|
+
*/
|
|
34
|
+
isCommitmentRevoked(commitment: string): Promise<boolean>;
|
|
23
35
|
/**
|
|
24
36
|
* Check if KYC is valid
|
|
25
|
-
*
|
|
37
|
+
* Now includes revocation checking
|
|
26
38
|
* @param userPrincipal User's Stacks principal
|
|
27
|
-
* @returns true if KYC is valid
|
|
39
|
+
* @returns true if KYC is valid (exists and not revoked)
|
|
28
40
|
*/
|
|
29
41
|
isKYCValid(userPrincipal: string): Promise<boolean>;
|
|
30
42
|
/**
|
package/dist/contract.js
CHANGED
|
@@ -290,15 +290,78 @@ export class KYCContract {
|
|
|
290
290
|
return { hasKYC: false };
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* Get revocation root from the revocation registry contract
|
|
295
|
+
* @returns Revocation root (32-byte hex string) or null if contract not configured
|
|
296
|
+
*/
|
|
297
|
+
async getRevocationRoot() {
|
|
298
|
+
if (!this.config.revocationRegistryAddress) {
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
const { address, name } = this.parseContractAddress(this.config.revocationRegistryAddress);
|
|
302
|
+
try {
|
|
303
|
+
const result = await callReadOnlyFunction({
|
|
304
|
+
contractAddress: address,
|
|
305
|
+
contractName: name,
|
|
306
|
+
functionName: 'get-revocation-root',
|
|
307
|
+
functionArgs: [],
|
|
308
|
+
network: this.network,
|
|
309
|
+
senderAddress: address,
|
|
310
|
+
});
|
|
311
|
+
const jsonResult = cvToJSON(result);
|
|
312
|
+
// Result is (ok (buff 32))
|
|
313
|
+
if (jsonResult.success === true || (jsonResult.type && jsonResult.type.includes('response'))) {
|
|
314
|
+
const rootValue = jsonResult.value?.value;
|
|
315
|
+
if (rootValue) {
|
|
316
|
+
// Convert buffer to hex string
|
|
317
|
+
return rootValue.startsWith('0x') ? rootValue : `0x${rootValue}`;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
catch (error) {
|
|
323
|
+
console.error('Error fetching revocation root:', error);
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Check if a commitment is revoked by checking the revocation root
|
|
329
|
+
* Note: This is a simplified check. For full verification, non-membership proofs are needed.
|
|
330
|
+
* @param commitment Commitment to check (hex string)
|
|
331
|
+
* @returns true if revoked, false if not revoked or if revocation checking is unavailable
|
|
332
|
+
*/
|
|
333
|
+
async isCommitmentRevoked(commitment) {
|
|
334
|
+
const root = await this.getRevocationRoot();
|
|
335
|
+
// If no revocation registry configured or root is zero (empty tree), nothing is revoked
|
|
336
|
+
if (!root || root === '0x0000000000000000000000000000000000000000000000000000000000000000') {
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
// TODO: Full revocation checking requires non-membership proof verification
|
|
340
|
+
// For now, we return false (not revoked) when root exists but we can't verify without proof
|
|
341
|
+
// In production, you should:
|
|
342
|
+
// 1. Request a non-membership proof from the attester service
|
|
343
|
+
// 2. Verify the proof using Merkle tree verification
|
|
344
|
+
// 3. Return true if proof verification fails or if commitment is in revocation tree
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
293
347
|
/**
|
|
294
348
|
* Check if KYC is valid
|
|
295
|
-
*
|
|
349
|
+
* Now includes revocation checking
|
|
296
350
|
* @param userPrincipal User's Stacks principal
|
|
297
|
-
* @returns true if KYC is valid
|
|
351
|
+
* @returns true if KYC is valid (exists and not revoked)
|
|
298
352
|
*/
|
|
299
353
|
async isKYCValid(userPrincipal) {
|
|
300
|
-
|
|
301
|
-
|
|
354
|
+
// First check if user has KYC record
|
|
355
|
+
const kycDetails = await this.getKYC(userPrincipal);
|
|
356
|
+
if (!kycDetails || !kycDetails.hasKYC || !kycDetails.commitment) {
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
// Check revocation status
|
|
360
|
+
const isRevoked = await this.isCommitmentRevoked(kycDetails.commitment);
|
|
361
|
+
if (isRevoked) {
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
return true;
|
|
302
365
|
}
|
|
303
366
|
/**
|
|
304
367
|
* Get KYC details for a user
|
|
@@ -318,14 +381,23 @@ export class KYCContract {
|
|
|
318
381
|
});
|
|
319
382
|
const jsonResult = cvToJSON(result);
|
|
320
383
|
// Result is (ok (some kyc-record)) or (ok none)
|
|
321
|
-
|
|
384
|
+
// cvToJSON returns structure: { success: true, type: "...", value: { type: "(optional ...)", value: { type: "(tuple ...)", value: { ... } } } }
|
|
385
|
+
if (jsonResult.success === true && jsonResult.value?.value?.value) {
|
|
322
386
|
const record = jsonResult.value.value.value;
|
|
323
|
-
|
|
387
|
+
const result = {
|
|
324
388
|
hasKYC: true,
|
|
325
389
|
commitment: record.commitment?.value,
|
|
326
390
|
attesterId: record['attester-id']?.value,
|
|
327
391
|
registeredAt: record['registered-at']?.value,
|
|
328
392
|
};
|
|
393
|
+
// Add history fields if present
|
|
394
|
+
if (record['previous-commitment']?.value) {
|
|
395
|
+
result.previousCommitment = record['previous-commitment'].value;
|
|
396
|
+
}
|
|
397
|
+
if (record['previous-registered-at']?.value !== undefined) {
|
|
398
|
+
result.previousRegisteredAt = record['previous-registered-at'].value;
|
|
399
|
+
}
|
|
400
|
+
return result;
|
|
329
401
|
}
|
|
330
402
|
else {
|
|
331
403
|
return null;
|
package/dist/types.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export interface KYCStatus {
|
|
|
6
6
|
commitment?: string;
|
|
7
7
|
attesterId?: number;
|
|
8
8
|
registeredAt?: number;
|
|
9
|
+
previousCommitment?: string;
|
|
10
|
+
previousRegisteredAt?: number;
|
|
9
11
|
}
|
|
10
12
|
export interface RegisterKYCParams {
|
|
11
13
|
commitment: string;
|
|
@@ -46,6 +48,7 @@ export interface AttestationResponse {
|
|
|
46
48
|
export interface SDKConfig {
|
|
47
49
|
kycRegistryAddress: string;
|
|
48
50
|
attesterRegistryAddress: string;
|
|
51
|
+
revocationRegistryAddress?: string;
|
|
49
52
|
proverServiceUrl?: string;
|
|
50
53
|
attesterServiceUrl?: string;
|
|
51
54
|
network?: 'mainnet' | 'testnet' | 'devnet';
|