noah-clarity 0.2.0 → 0.3.1

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 +102 -5
  2. package/package.json +1 -1
package/dist/contract.js CHANGED
@@ -29,10 +29,25 @@ class KYCContract {
29
29
  */
30
30
  async registerKYC(params, privateKey) {
31
31
  const senderAddress = (0, transactions_1.getAddressFromPrivateKey)(privateKey, this.network.version);
32
+ // #region agent log
33
+ fetch('http://127.0.0.1:7249/ingest/b239a7fb-669e-478f-b888-bd46beaadedf', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ location: 'contract.ts:50', 'message': 'registerKYC entry', 'data': { senderAddress, network: this.network.coreApiUrl, attesterId: params.attesterId, commitmentLength: params.commitment.length, signatureLength: params.signature.length }, timestamp: Date.now(), sessionId: 'debug-session', runId: 'run1', hypothesisId: 'A' }) }).catch(() => { });
34
+ // #endregion agent log
32
35
  const { address, name } = this.parseContractAddress(this.config.kycRegistryAddress);
36
+ // Ensure commitment is exactly 32 bytes (64 hex chars)
37
+ const commitmentHex = params.commitment.replace('0x', '');
38
+ const commitmentBuffer = Buffer.from(commitmentHex, 'hex');
39
+ if (commitmentBuffer.length !== 32) {
40
+ throw new Error(`Invalid commitment length: expected 32 bytes, got ${commitmentBuffer.length}. Hex: ${commitmentHex.substring(0, 20)}...`);
41
+ }
42
+ // Ensure signature is exactly 65 bytes (130 hex chars)
43
+ const signatureHex = params.signature.replace('0x', '');
44
+ const signatureBuffer = Buffer.from(signatureHex, 'hex');
45
+ if (signatureBuffer.length !== 65) {
46
+ throw new Error(`Invalid signature length: expected 65 bytes, got ${signatureBuffer.length}. Hex: ${signatureHex.substring(0, 20)}...`);
47
+ }
33
48
  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')),
49
+ (0, transactions_1.bufferCV)(commitmentBuffer),
50
+ (0, transactions_1.bufferCV)(signatureBuffer),
36
51
  (0, transactions_1.uintCV)(params.attesterId),
37
52
  ];
38
53
  const txOptions = {
@@ -41,21 +56,103 @@ class KYCContract {
41
56
  functionName: 'register-kyc',
42
57
  functionArgs,
43
58
  senderKey: privateKey,
44
- fee: 1000,
59
+ fee: 5000, // Increased from 1000 to 5000 microSTX (0.005 STX) for better reliability
45
60
  network: this.network,
46
61
  anchorMode: transactions_1.AnchorMode.Any,
47
62
  postConditionMode: transactions_1.PostConditionMode.Allow,
48
63
  };
64
+ // #region agent log
65
+ fetch('http://127.0.0.1:7249/ingest/b239a7fb-669e-478f-b888-bd46beaadedf', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ location: 'contract.ts:74', 'message': 'Transaction options before makeContractCall', 'data': { contractAddress: address, contractName: name, functionName: 'register-kyc', fee: txOptions.fee, anchorMode: txOptions.anchorMode, postConditionMode: txOptions.postConditionMode, networkUrl: this.network.coreApiUrl }, timestamp: Date.now(), sessionId: 'debug-session', runId: 'run1', hypothesisId: 'B' }) }).catch(() => { });
66
+ // #endregion agent log
49
67
  try {
50
68
  const transaction = await (0, transactions_1.makeContractCall)(txOptions);
69
+ // #region agent log
70
+ const serializedTx = transaction.serialize();
71
+ const txData = {
72
+ txId: transaction.txid(),
73
+ nonce: transaction.auth?.spendingCondition?.nonce,
74
+ serializedTxLength: serializedTx.byteLength,
75
+ };
76
+ fetch('http://127.0.0.1:7249/ingest/b239a7fb-669e-478f-b888-bd46beaadedf', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ location: 'contract.ts:87', 'message': 'Transaction created, before broadcast', 'data': txData, timestamp: Date.now(), sessionId: 'debug-session', runId: 'run1', hypothesisId: 'A' }) }).catch(() => { });
77
+ // #endregion agent log
51
78
  const broadcastResponse = await (0, transactions_1.broadcastTransaction)(transaction, this.network);
52
79
  return broadcastResponse.txid;
53
80
  }
54
81
  catch (error) {
82
+ // #region agent log
83
+ const errorKeys = error ? Object.keys(error) : [];
84
+ const errorStructure = {
85
+ hasError: !!error,
86
+ hasResponse: !!error?.response,
87
+ hasData: !!error?.data,
88
+ hasStatus: !!error?.status,
89
+ hasStatusText: !!error?.statusText,
90
+ hasReason: !!error?.reason,
91
+ hasMessage: !!error?.message,
92
+ errorKeys: errorKeys,
93
+ errorType: error?.constructor?.name,
94
+ status: error?.status,
95
+ statusText: error?.statusText,
96
+ };
97
+ fetch('http://127.0.0.1:7249/ingest/b239a7fb-669e-478f-b888-bd46beaadedf', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ location: 'contract.ts:91', 'message': 'Error object structure', 'data': errorStructure, timestamp: Date.now(), sessionId: 'debug-session', runId: 'run1', hypothesisId: 'C' }) }).catch(() => { });
98
+ // #endregion agent log
99
+ // Capture detailed error information
100
+ let errorMessage = 'Transaction failed';
101
+ let errorDetails = {};
55
102
  if (error instanceof Error) {
56
- throw new Error(`Transaction failed: ${error.message}`);
103
+ errorMessage = error.message;
104
+ errorDetails.message = error.message;
105
+ }
106
+ // Try to extract API response details
107
+ if (error?.error) {
108
+ errorDetails.apiError = error.error;
109
+ errorMessage = error.error;
110
+ }
111
+ if (error?.reason) {
112
+ errorDetails.reason = error.reason;
113
+ errorMessage = error.reason;
114
+ }
115
+ if (error?.response) {
116
+ try {
117
+ if (typeof error.response === 'string') {
118
+ errorDetails.response = error.response;
119
+ }
120
+ else {
121
+ errorDetails.response = JSON.stringify(error.response);
122
+ }
123
+ }
124
+ catch (e) {
125
+ errorDetails.response = String(error.response);
126
+ }
127
+ }
128
+ if (error?.data) {
129
+ errorDetails.data = typeof error.data === 'string' ? error.data : JSON.stringify(error.data);
130
+ }
131
+ if (error?.status)
132
+ errorDetails.status = error.status;
133
+ if (error?.statusText)
134
+ errorDetails.statusText = error.statusText;
135
+ // #region agent log
136
+ fetch('http://127.0.0.1:7249/ingest/b239a7fb-669e-478f-b888-bd46beaadedf', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ location: 'contract.ts:120', 'message': 'Error details captured', 'data': errorDetails, timestamp: Date.now(), sessionId: 'debug-session', runId: 'run1', hypothesisId: 'C' }) }).catch(() => { });
137
+ // #endregion agent log
138
+ // Try to extract response body if it exists
139
+ let responseBody = null;
140
+ if (error?.response?.data) {
141
+ responseBody = error.response.data;
142
+ }
143
+ else if (error?.data) {
144
+ responseBody = error.data;
145
+ }
146
+ // #region agent log
147
+ if (responseBody) {
148
+ fetch('http://127.0.0.1:7249/ingest/b239a7fb-669e-478f-b888-bd46beaadedf', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ location: 'contract.ts:135', 'message': 'API response body', 'data': { responseBody: typeof responseBody === 'string' ? responseBody : JSON.stringify(responseBody) }, timestamp: Date.now(), sessionId: 'debug-session', runId: 'run1', hypothesisId: 'C' }) }).catch(() => { });
57
149
  }
58
- throw new Error(`Transaction failed: ${String(error)}`);
150
+ // #endregion agent log
151
+ // Log the full error for debugging
152
+ console.error('Transaction broadcast error:', errorDetails);
153
+ // Provide detailed error message
154
+ const detailedMessage = responseBody || errorDetails.response || errorDetails.reason || errorDetails.apiError || errorDetails.data || errorMessage;
155
+ throw new Error(`Transaction failed: ${detailedMessage}`);
59
156
  }
60
157
  }
61
158
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "noah-clarity",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
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",