noah-clarity 0.1.0 → 0.3.0
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/contract.js +54 -5
- package/dist/proof.d.ts +16 -7
- package/dist/proof.js +25 -12
- package/dist/types.d.ts +9 -0
- package/package.json +1 -1
package/dist/contract.js
CHANGED
|
@@ -30,9 +30,21 @@ class KYCContract {
|
|
|
30
30
|
async registerKYC(params, privateKey) {
|
|
31
31
|
const senderAddress = (0, transactions_1.getAddressFromPrivateKey)(privateKey, this.network.version);
|
|
32
32
|
const { address, name } = this.parseContractAddress(this.config.kycRegistryAddress);
|
|
33
|
+
// Ensure commitment is exactly 32 bytes (64 hex chars)
|
|
34
|
+
const commitmentHex = params.commitment.replace('0x', '');
|
|
35
|
+
const commitmentBuffer = Buffer.from(commitmentHex, 'hex');
|
|
36
|
+
if (commitmentBuffer.length !== 32) {
|
|
37
|
+
throw new Error(`Invalid commitment length: expected 32 bytes, got ${commitmentBuffer.length}. Hex: ${commitmentHex.substring(0, 20)}...`);
|
|
38
|
+
}
|
|
39
|
+
// Ensure signature is exactly 65 bytes (130 hex chars)
|
|
40
|
+
const signatureHex = params.signature.replace('0x', '');
|
|
41
|
+
const signatureBuffer = Buffer.from(signatureHex, 'hex');
|
|
42
|
+
if (signatureBuffer.length !== 65) {
|
|
43
|
+
throw new Error(`Invalid signature length: expected 65 bytes, got ${signatureBuffer.length}. Hex: ${signatureHex.substring(0, 20)}...`);
|
|
44
|
+
}
|
|
33
45
|
const functionArgs = [
|
|
34
|
-
(0, transactions_1.bufferCV)(
|
|
35
|
-
(0, transactions_1.bufferCV)(
|
|
46
|
+
(0, transactions_1.bufferCV)(commitmentBuffer),
|
|
47
|
+
(0, transactions_1.bufferCV)(signatureBuffer),
|
|
36
48
|
(0, transactions_1.uintCV)(params.attesterId),
|
|
37
49
|
];
|
|
38
50
|
const txOptions = {
|
|
@@ -41,7 +53,7 @@ class KYCContract {
|
|
|
41
53
|
functionName: 'register-kyc',
|
|
42
54
|
functionArgs,
|
|
43
55
|
senderKey: privateKey,
|
|
44
|
-
fee: 1000
|
|
56
|
+
fee: 5000, // Increased from 1000 to 5000 microSTX (0.005 STX) for better reliability
|
|
45
57
|
network: this.network,
|
|
46
58
|
anchorMode: transactions_1.AnchorMode.Any,
|
|
47
59
|
postConditionMode: transactions_1.PostConditionMode.Allow,
|
|
@@ -52,10 +64,47 @@ class KYCContract {
|
|
|
52
64
|
return broadcastResponse.txid;
|
|
53
65
|
}
|
|
54
66
|
catch (error) {
|
|
67
|
+
// Capture detailed error information
|
|
68
|
+
let errorMessage = 'Transaction failed';
|
|
69
|
+
let errorDetails = {};
|
|
55
70
|
if (error instanceof Error) {
|
|
56
|
-
|
|
71
|
+
errorMessage = error.message;
|
|
72
|
+
errorDetails.message = error.message;
|
|
73
|
+
}
|
|
74
|
+
// Try to extract API response details
|
|
75
|
+
if (error?.error) {
|
|
76
|
+
errorDetails.apiError = error.error;
|
|
77
|
+
errorMessage = error.error;
|
|
78
|
+
}
|
|
79
|
+
if (error?.reason) {
|
|
80
|
+
errorDetails.reason = error.reason;
|
|
81
|
+
errorMessage = error.reason;
|
|
82
|
+
}
|
|
83
|
+
if (error?.response) {
|
|
84
|
+
try {
|
|
85
|
+
if (typeof error.response === 'string') {
|
|
86
|
+
errorDetails.response = error.response;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
errorDetails.response = JSON.stringify(error.response);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
errorDetails.response = String(error.response);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (error?.data) {
|
|
97
|
+
errorDetails.data = typeof error.data === 'string' ? error.data : JSON.stringify(error.data);
|
|
57
98
|
}
|
|
58
|
-
|
|
99
|
+
if (error?.status)
|
|
100
|
+
errorDetails.status = error.status;
|
|
101
|
+
if (error?.statusText)
|
|
102
|
+
errorDetails.statusText = error.statusText;
|
|
103
|
+
// Log the full error for debugging
|
|
104
|
+
console.error('Transaction broadcast error:', errorDetails);
|
|
105
|
+
// Provide detailed error message
|
|
106
|
+
const detailedMessage = errorDetails.response || errorDetails.reason || errorDetails.apiError || errorDetails.data || errorMessage;
|
|
107
|
+
throw new Error(`Transaction failed: ${detailedMessage}`);
|
|
59
108
|
}
|
|
60
109
|
}
|
|
61
110
|
/**
|
package/dist/proof.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Proof generation and verification utilities
|
|
3
3
|
*/
|
|
4
|
-
import { ProofRequest, ProofResponse, AttestationRequest, AttestationResponse, SDKConfig } from './types';
|
|
4
|
+
import { ProofRequest, ProofResponse, AttestationRequest, AttestationResponse, SDKConfig, ProtocolRequirements } from './types';
|
|
5
5
|
export declare class ProofService {
|
|
6
6
|
private proverServiceUrl;
|
|
7
7
|
private attesterServiceUrl;
|
|
@@ -19,11 +19,20 @@ export declare class ProofService {
|
|
|
19
19
|
*/
|
|
20
20
|
requestAttestation(request: AttestationRequest): Promise<AttestationResponse>;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
22
|
+
* Generate a proof matching protocol-specific requirements
|
|
23
|
+
*
|
|
24
|
+
* Takes user credential data and protocol requirements, then constructs
|
|
25
|
+
* a ProofRequest with protocol requirements as public inputs.
|
|
26
|
+
*
|
|
27
|
+
* @param userCredential User's credential data (private inputs)
|
|
28
|
+
* @param protocolRequirements Protocol's KYC requirements (public inputs)
|
|
29
|
+
* @returns Proof response with proof and public inputs
|
|
27
30
|
*/
|
|
28
|
-
|
|
31
|
+
generateProofForProtocol(userCredential: {
|
|
32
|
+
age: string;
|
|
33
|
+
jurisdiction: string;
|
|
34
|
+
is_accredited: string;
|
|
35
|
+
identity_data: string;
|
|
36
|
+
nonce: string;
|
|
37
|
+
}, protocolRequirements: ProtocolRequirements): Promise<ProofResponse>;
|
|
29
38
|
}
|
package/dist/proof.js
CHANGED
|
@@ -64,19 +64,32 @@ class ProofService {
|
|
|
64
64
|
return data;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
67
|
+
* Generate a proof matching protocol-specific requirements
|
|
68
|
+
*
|
|
69
|
+
* Takes user credential data and protocol requirements, then constructs
|
|
70
|
+
* a ProofRequest with protocol requirements as public inputs.
|
|
71
|
+
*
|
|
72
|
+
* @param userCredential User's credential data (private inputs)
|
|
73
|
+
* @param protocolRequirements Protocol's KYC requirements (public inputs)
|
|
74
|
+
* @returns Proof response with proof and public inputs
|
|
72
75
|
*/
|
|
73
|
-
async
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
async generateProofForProtocol(userCredential, protocolRequirements) {
|
|
77
|
+
// Construct ProofRequest with protocol requirements as public inputs
|
|
78
|
+
const proofRequest = {
|
|
79
|
+
// Private inputs (user's actual credential data)
|
|
80
|
+
age: userCredential.age,
|
|
81
|
+
jurisdiction: userCredential.jurisdiction,
|
|
82
|
+
is_accredited: userCredential.is_accredited,
|
|
83
|
+
identity_data: userCredential.identity_data,
|
|
84
|
+
nonce: userCredential.nonce,
|
|
85
|
+
// Public inputs (protocol requirements)
|
|
86
|
+
min_age: protocolRequirements.min_age.toString(),
|
|
87
|
+
allowed_jurisdictions: protocolRequirements.allowed_jurisdictions.map(j => j.toString()),
|
|
88
|
+
require_accreditation: protocolRequirements.require_accreditation ? '1' : '0',
|
|
89
|
+
commitment: '', // Will be computed by prover service
|
|
90
|
+
};
|
|
91
|
+
// Generate proof using existing method
|
|
92
|
+
return await this.generateProof(proofRequest);
|
|
80
93
|
}
|
|
81
94
|
}
|
|
82
95
|
exports.ProofService = ProofService;
|
package/dist/types.d.ts
CHANGED
|
@@ -55,3 +55,12 @@ export interface WalletConfig {
|
|
|
55
55
|
appIcon?: string;
|
|
56
56
|
redirectPath?: string;
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Protocol-specific KYC requirements
|
|
60
|
+
* Protocols define these requirements off-chain (e.g., in JSON/metadata)
|
|
61
|
+
*/
|
|
62
|
+
export interface ProtocolRequirements {
|
|
63
|
+
min_age: number;
|
|
64
|
+
allowed_jurisdictions: number[];
|
|
65
|
+
require_accreditation: boolean;
|
|
66
|
+
}
|