noah-clarity 0.2.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.
Files changed (2) hide show
  1. package/dist/contract.js +54 -5
  2. 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)(Buffer.from(params.commitment.replace('0x', ''), 'hex')),
35
- (0, transactions_1.bufferCV)(Buffer.from(params.signature.replace('0x', ''), 'hex')),
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
- throw new Error(`Transaction failed: ${error.message}`);
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
- throw new Error(`Transaction failed: ${String(error)}`);
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "noah-clarity",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "TypeScript SDK for Noah-v2 KYC system on Stacks",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",