@trufnetwork/sdk-js 0.5.4 → 0.5.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/README.md +1 -0
- package/dist/cjs/contracts-api/attestationAction.cjs +2 -1
- package/dist/cjs/contracts-api/attestationAction.cjs.map +2 -2
- package/dist/cjs/contracts-api/transactionAction.cjs +28 -0
- package/dist/cjs/contracts-api/transactionAction.cjs.map +2 -2
- package/dist/cjs/types/attestation.cjs.map +2 -2
- package/dist/cjs/types/transaction.cjs.map +1 -1
- package/dist/esm/contracts-api/attestationAction.mjs +2 -1
- package/dist/esm/contracts-api/attestationAction.mjs.map +2 -2
- package/dist/esm/contracts-api/transactionAction.mjs +28 -0
- package/dist/esm/contracts-api/transactionAction.mjs.map +2 -2
- package/dist/esm/types/attestation.mjs.map +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/contracts-api/attestationAction.d.ts +1 -1
- package/dist/types/contracts-api/attestationAction.d.ts.map +1 -1
- package/dist/types/contracts-api/transactionAction.d.ts.map +1 -1
- package/dist/types/types/attestation.d.ts +5 -0
- package/dist/types/types/attestation.d.ts.map +1 -1
- package/dist/types/types/transaction.d.ts +5 -0
- package/dist/types/types/transaction.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -335,6 +335,7 @@ const txEvent = await transactionAction.getTransactionEvent({
|
|
|
335
335
|
txId: '0xabcdef...'
|
|
336
336
|
});
|
|
337
337
|
console.log(`Method: ${txEvent.method}, Fee: ${txEvent.feeAmount} wei`);
|
|
338
|
+
console.log(`Timestamp (ms): ${txEvent.stampMs}`);
|
|
338
339
|
|
|
339
340
|
// List fees paid by wallet
|
|
340
341
|
const entries = await transactionAction.listTransactionFees({
|
|
@@ -155,7 +155,7 @@ var AttestationAction = class extends import_action.Action {
|
|
|
155
155
|
/**
|
|
156
156
|
* List attestation metadata with optional filtering
|
|
157
157
|
*
|
|
158
|
-
* This returns metadata for attestations, optionally filtered by requester address.
|
|
158
|
+
* This returns metadata for attestations, optionally filtered by requester address or request transaction ID.
|
|
159
159
|
* Supports pagination and sorting.
|
|
160
160
|
*
|
|
161
161
|
* @param input - Filter and pagination parameters
|
|
@@ -184,6 +184,7 @@ var AttestationAction = class extends import_action.Action {
|
|
|
184
184
|
const offset = input.offset ?? 0;
|
|
185
185
|
const params = {
|
|
186
186
|
$requester: input.requester ?? new Uint8Array(0),
|
|
187
|
+
$request_tx_id: input.requestTxId ?? null,
|
|
187
188
|
$limit: limit,
|
|
188
189
|
$offset: offset,
|
|
189
190
|
$order_by: input.orderBy ?? null
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/contracts-api/attestationAction.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Attestation action implementation\n *\n * This module provides methods for requesting, retrieving, and listing attestations.\n * Attestations are cryptographically signed proofs of query results that can be\n * consumed by smart contracts and external applications.\n */\n\nimport { Types, Utils } from '@trufnetwork/kwil-js';\nimport { Action } from './action';\nimport {\n RequestAttestationInput,\n RequestAttestationResult,\n GetSignedAttestationInput,\n SignedAttestationResult,\n ListAttestationsInput,\n AttestationMetadata,\n validateAttestationRequest,\n validateListAttestationsInput,\n} from '../types/attestation';\nimport { encodeActionArgs } from '../util/AttestationEncoding';\n\n/**\n * AttestationAction provides methods for working with data attestations\n *\n * Attestations enable validators to cryptographically sign query results,\n * providing verifiable proofs that can be used in smart contracts.\n *\n * @example\n * ```typescript\n * const client = new NodeTNClient({ ... });\n * const attestationAction = client.loadAttestationAction();\n *\n * // Request an attestation\n * const result = await attestationAction.requestAttestation({\n * dataProvider: \"0x4710a8d8f0d845da110086812a32de6d90d7ff5c\",\n * streamId: \"stai0000000000000000000000000000\",\n * actionName: \"get_record\",\n * args: [dataProvider, streamId, fromTime, toTime, null, false],\n * encryptSig: false,\n * maxFee: 1000000,\n * });\n *\n * // Wait for signing (1-2 blocks)\n * await new Promise(resolve => setTimeout(resolve, 10000));\n *\n * // Retrieve signed attestation\n * const signed = await attestationAction.getSignedAttestation({\n * requestTxId: result.requestTxId,\n * });\n * ```\n */\nexport class AttestationAction extends Action {\n /**\n * Request a signed attestation of query results\n *\n * This submits a transaction requesting that validators execute a query\n * and sign the results. The leader validator will sign the attestation\n * asynchronously (typically 1-2 blocks later).\n *\n * @param input - Attestation request parameters\n * @returns Promise resolving to request result with transaction ID\n * @throws Error if validation fails or transaction fails\n *\n * @example\n * ```typescript\n * const result = await attestationAction.requestAttestation({\n * dataProvider: \"0x4710a8d8f0d845da110086812a32de6d90d7ff5c\",\n * streamId: \"stai0000000000000000000000000000\",\n * actionName: \"get_record\",\n * args: [\n * \"0x4710a8d8f0d845da110086812a32de6d90d7ff5c\",\n * \"stai0000000000000000000000000000\",\n * Math.floor(Date.now() / 1000) - 86400, // 1 day ago\n * Math.floor(Date.now() / 1000),\n * null,\n * false,\n * ],\n * encryptSig: false,\n * maxFee: 1000000,\n * });\n * console.log(`Request TX ID: ${result.requestTxId}`);\n * ```\n */\n async requestAttestation(\n input: RequestAttestationInput\n ): Promise<RequestAttestationResult> {\n // Validate input\n validateAttestationRequest(input);\n\n // Encode arguments\n const argsBytes = encodeActionArgs(input.args);\n\n // Prepare named parameters for request_attestation action\n // Note: maxFee must be a string with NUMERIC type to encode as NUMERIC(788,0) for wei amounts\n const params: Types.NamedParams[] = [{\n $data_provider: input.dataProvider,\n $stream_id: input.streamId,\n $action_name: input.actionName,\n $args_bytes: argsBytes,\n $encrypt_sig: input.encryptSig,\n $max_fee: input.maxFee.toString(),\n }];\n\n // Specify types - maxFee needs NUMERIC(78,0) for large wei amounts\n const types = {\n $max_fee: Utils.DataType.Numeric(78, 0),\n };\n\n // Execute request_attestation action\n const result = await this.executeWithNamedParams('request_attestation', params, types);\n\n // Check for errors\n if (!result.data?.tx_hash) {\n throw new Error(\n 'Failed to request attestation: no transaction hash returned'\n );\n }\n\n // Return the 64-char hex tx_hash\n return {\n requestTxId: result.data.tx_hash,\n };\n }\n\n /**\n * Retrieve a complete signed attestation payload\n *\n * This fetches the signed attestation payload for a given request transaction ID.\n * The attestation must have been signed by the leader validator first.\n *\n * If the attestation is not yet signed, this will throw an error. Clients should\n * poll with exponential backoff or wait for 1-2 blocks after requesting.\n *\n * @param input - Request transaction ID\n * @returns Promise resolving to signed attestation payload\n * @throws Error if attestation not found or not yet signed\n *\n * @example\n * ```typescript\n * // Poll for signature\n * for (let i = 0; i < 15; i++) {\n * try {\n * const signed = await attestationAction.getSignedAttestation({\n * requestTxId: \"0x123...\",\n * });\n * console.log(`Payload: ${Buffer.from(signed.payload).toString('hex')}`);\n * break;\n * } catch (e) {\n * await new Promise(resolve => setTimeout(resolve, 2000));\n * }\n * }\n * ```\n */\n async getSignedAttestation(\n input: GetSignedAttestationInput\n ): Promise<SignedAttestationResult> {\n // Validate and normalize input\n const trimmed = input.requestTxId?.trim() || '';\n if (trimmed === '') {\n throw new Error('request_tx_id is required');\n }\n\n // Strip optional \"0x\" prefix and lowercase for normalization\n const normalizedRequestTxId = trimmed.startsWith('0x')\n ? trimmed.slice(2).toLowerCase()\n : trimmed.toLowerCase();\n\n // Call get_signed_attestation view action\n const result = await this.call<Array<{ payload: string | Uint8Array }>>(\n 'get_signed_attestation',\n { $request_tx_id: normalizedRequestTxId }\n );\n\n // Extract the right value from Either, or throw if Left\n const data = result.throw();\n\n // The action returns an array of rows - extract the first row\n if (!data || !Array.isArray(data) || data.length === 0) {\n throw new Error('No attestation found for request_tx_id - may not exist or is not yet signed');\n }\n\n const row = data[0];\n if (!row || !row.payload) {\n throw new Error('No payload in attestation row');\n }\n\n // Decode base64 to bytes\n let payloadBytes: Uint8Array;\n const payloadValue = row.payload;\n\n if (typeof payloadValue === 'string') {\n // Node.js environment\n if (typeof Buffer !== 'undefined') {\n payloadBytes = new Uint8Array(Buffer.from(payloadValue, 'base64'));\n } else {\n // Browser environment\n const binaryString = atob(payloadValue);\n payloadBytes = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n payloadBytes[i] = binaryString.charCodeAt(i);\n }\n }\n } else if (payloadValue instanceof Uint8Array) {\n // Already decoded\n payloadBytes = payloadValue;\n } else {\n throw new Error(`Unexpected payload type: ${typeof payloadValue}`);\n }\n\n return {\n payload: payloadBytes,\n };\n }\n\n /**\n * List attestation metadata with optional filtering\n *\n * This returns metadata for attestations, optionally filtered by requester address.\n * Supports pagination and sorting.\n *\n * @param input - Filter and pagination parameters\n * @returns Promise resolving to array of attestation metadata\n * @throws Error if parameters are invalid\n *\n * @example\n * ```typescript\n * // List my recent attestations\n * const myAddress = new Uint8Array(Buffer.from(wallet.address.slice(2), 'hex'));\n * const attestations = await attestationAction.listAttestations({\n * requester: myAddress,\n * limit: 10,\n * offset: 0,\n * orderBy: \"created_height desc\",\n * });\n *\n * attestations.forEach(att => {\n * console.log(`TX: ${att.requestTxId}, Height: ${att.createdHeight}`);\n * });\n * ```\n */\n async listAttestations(\n input: ListAttestationsInput\n ): Promise<AttestationMetadata[]> {\n // Validate input\n validateListAttestationsInput(input);\n\n // Set defaults\n const limit = input.limit ?? 5000;\n const offset = input.offset ?? 0;\n\n // Prepare parameters for list_attestations view action\n // Note: Empty Uint8Array represents BYTEA NULL (handled by kwil-js 0.9.10+)\n const params: Types.NamedParams = {\n $requester: input.requester ?? new Uint8Array(0),\n $limit: limit,\n $offset: offset,\n $order_by: input.orderBy ?? null,\n };\n\n // Call list_attestations view action\n const result = await this.call<any[]>('list_attestations', params);\n\n // Check for errors\n if (result.isLeft()) {\n throw new Error(\n `Failed to list attestations: HTTP status ${result.value}`\n );\n }\n\n // Extract the right value from Either\n // Note: result.value might be a getter function, so call it if needed\n const rightValue = typeof result.value === 'function' ? result.value() : result.value;\n const rows = Array.isArray(rightValue) ? rightValue : [];\n\n // If no rows, return empty array\n if (!rows || rows.length === 0) {\n return [];\n }\n\n // Parse rows into AttestationMetadata\n return rows.map((row: any, idx: number) => parseAttestationRow(row, idx));\n }\n}\n\n/**\n * Parse a single row from list_attestations result into AttestationMetadata\n *\n * Expected columns (in order):\n * 0. request_tx_id (TEXT)\n * 1. attestation_hash (BYTEA)\n * 2. requester (BYTEA)\n * 3. created_height (INT8)\n * 4. signed_height (INT8, nullable)\n * 5. encrypt_sig (BOOLEAN)\n */\nfunction parseAttestationRow(row: any, idx: number): AttestationMetadata {\n // kwil-js returns rows as objects with column names as keys\n // or as arrays depending on the query format\n let requestTxId: string;\n let attestationHash: Uint8Array;\n let requester: Uint8Array;\n let createdHeight: number;\n let signedHeight: number | null;\n let encryptSig: boolean;\n\n // Handle both array and object formats\n if (Array.isArray(row)) {\n // Array format: [col0, col1, col2, ...]\n if (row.length < 6) {\n throw new Error(\n `Row ${idx}: expected 6 columns, got ${row.length}`\n );\n }\n\n requestTxId = row[0];\n attestationHash = decodeBytea(row[1], idx, 'attestation_hash');\n requester = decodeBytea(row[2], idx, 'requester');\n createdHeight = parseInt(row[3], 10);\n signedHeight = row[4] !== null ? parseInt(row[4], 10) : null;\n encryptSig = row[5];\n } else {\n // Object format: { request_tx_id: ..., attestation_hash: ..., ... }\n requestTxId = row.request_tx_id;\n attestationHash = decodeBytea(row.attestation_hash, idx, 'attestation_hash');\n requester = decodeBytea(row.requester, idx, 'requester');\n createdHeight = parseInt(row.created_height, 10);\n signedHeight = row.signed_height !== null ? parseInt(row.signed_height, 10) : null;\n encryptSig = row.encrypt_sig;\n }\n\n return {\n requestTxId,\n attestationHash,\n requester,\n createdHeight,\n signedHeight,\n encryptSig,\n };\n}\n\n/**\n * Decode a BYTEA column from base64\n */\nfunction decodeBytea(value: any, rowIdx: number, colName: string): Uint8Array {\n if (value === null || value === undefined) {\n throw new Error(`Row ${rowIdx}: ${colName} is null or undefined`);\n }\n\n // If already Uint8Array, return as-is\n if (value instanceof Uint8Array) {\n return value;\n }\n\n // If string, decode from base64\n if (typeof value === 'string') {\n try {\n // Node.js environment\n if (typeof Buffer !== 'undefined') {\n return new Uint8Array(Buffer.from(value, 'base64'));\n } else {\n // Browser environment\n const binaryString = atob(value);\n const bytes = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n bytes[i] = binaryString.charCodeAt(i);\n }\n return bytes;\n }\n } catch (err) {\n throw new Error(\n `Row ${rowIdx}: failed to decode ${colName} as base64: ${err}`\n );\n }\n }\n\n throw new Error(\n `Row ${rowIdx}: expected ${colName} to be string or Uint8Array, got ${typeof value}`\n );\n}\n\n// Inline unit tests\nif (import.meta.vitest) {\n const { describe, it, expect } = import.meta.vitest;\n\n describe('decodeBytea', () => {\n it('should decode base64 string', () => {\n const base64 = Buffer.from([1, 2, 3, 4]).toString('base64');\n const decoded = decodeBytea(base64, 0, 'test');\n expect(Array.from(decoded)).toEqual([1, 2, 3, 4]);\n });\n\n it('should return Uint8Array as-is', () => {\n const bytes = new Uint8Array([1, 2, 3, 4]);\n const decoded = decodeBytea(bytes, 0, 'test');\n expect(decoded).toBe(bytes);\n });\n\n it('should throw on null', () => {\n expect(() => decodeBytea(null, 0, 'test')).toThrow('null or undefined');\n });\n\n it('should throw on invalid type', () => {\n expect(() => decodeBytea(123, 0, 'test')).toThrow('expected test to be string or Uint8Array');\n });\n });\n\n describe('parseAttestationRow', () => {\n it('should parse array format row', () => {\n const row = [\n 'tx123',\n Buffer.from([1, 2, 3]).toString('base64'),\n Buffer.from([4, 5, 6]).toString('base64'),\n '100',\n '200',\n true,\n ];\n\n const metadata = parseAttestationRow(row, 0);\n\n expect(metadata.requestTxId).toBe('tx123');\n expect(Array.from(metadata.attestationHash)).toEqual([1, 2, 3]);\n expect(Array.from(metadata.requester)).toEqual([4, 5, 6]);\n expect(metadata.createdHeight).toBe(100);\n expect(metadata.signedHeight).toBe(200);\n expect(metadata.encryptSig).toBe(true);\n });\n\n it('should parse object format row', () => {\n const row = {\n request_tx_id: 'tx456',\n attestation_hash: Buffer.from([7, 8, 9]).toString('base64'),\n requester: Buffer.from([10, 11, 12]).toString('base64'),\n created_height: '300',\n signed_height: null,\n encrypt_sig: false,\n };\n\n const metadata = parseAttestationRow(row, 0);\n\n expect(metadata.requestTxId).toBe('tx456');\n expect(Array.from(metadata.attestationHash)).toEqual([7, 8, 9]);\n expect(Array.from(metadata.requester)).toEqual([10, 11, 12]);\n expect(metadata.createdHeight).toBe(300);\n expect(metadata.signedHeight).toBe(null);\n expect(metadata.encryptSig).toBe(false);\n });\n });\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,qBAA6B;AAC7B,oBAAuB;AACvB,yBASO;AACP,iCAAiC;AApBjC;AAoDO,IAAM,oBAAN,cAAgC,qBAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgC5C,MAAM,mBACJ,OACmC;AAEnC,uDAA2B,KAAK;AAGhC,UAAM,gBAAY,6CAAiB,MAAM,IAAI;AAI7C,UAAM,SAA8B,CAAC;AAAA,MACnC,gBAAgB,MAAM;AAAA,MACtB,YAAY,MAAM;AAAA,MAClB,cAAc,MAAM;AAAA,MACpB,aAAa;AAAA,MACb,cAAc,MAAM;AAAA,MACpB,UAAU,MAAM,OAAO,SAAS;AAAA,IAClC,CAAC;AAGD,UAAM,QAAQ;AAAA,MACZ,UAAU,qBAAM,SAAS,QAAQ,IAAI,CAAC;AAAA,IACxC;AAGA,UAAM,SAAS,MAAM,KAAK,uBAAuB,uBAAuB,QAAQ,KAAK;AAGrF,QAAI,CAAC,OAAO,MAAM,SAAS;AACzB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAGA,WAAO;AAAA,MACL,aAAa,OAAO,KAAK;AAAA,IAC3B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA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,WAAW,EAAE,KAAK,OAAO;AACzC,aAAO,MAAM,KAAK,SAAS,eAAe,CAAC,EAAE,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC;AAC9D,aAAO,MAAM,KAAK,SAAS,SAAS,CAAC,EAAE,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC;AACxD,aAAO,SAAS,aAAa,EAAE,KAAK,GAAG;AACvC,aAAO,SAAS,YAAY,EAAE,KAAK,GAAG;AACtC,aAAO,SAAS,UAAU,EAAE,KAAK,IAAI;AAAA,IACvC,CAAC;AAED,OAAG,kCAAkC,MAAM;AACzC,YAAM,MAAM;AAAA,QACV,eAAe;AAAA,QACf,kBAAkB,OAAO,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,SAAS,QAAQ;AAAA,QAC1D,WAAW,OAAO,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,SAAS,QAAQ;AAAA,QACtD,gBAAgB;AAAA,QAChB,eAAe;AAAA,QACf,aAAa;AAAA,MACf;AAEA,YAAM,WAAW,oBAAoB,KAAK,CAAC;AAE3C,aAAO,SAAS,WAAW,EAAE,KAAK,OAAO;AACzC,aAAO,MAAM,KAAK,SAAS,eAAe,CAAC,EAAE,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC;AAC9D,aAAO,MAAM,KAAK,SAAS,SAAS,CAAC,EAAE,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC;AAC3D,aAAO,SAAS,aAAa,EAAE,KAAK,GAAG;AACvC,aAAO,SAAS,YAAY,EAAE,KAAK,IAAI;AACvC,aAAO,SAAS,UAAU,EAAE,KAAK,KAAK;AAAA,IACxC,CAAC;AAAA,EACH,CAAC;AACH;",
|
|
4
|
+
"sourcesContent": ["/**\n * Attestation action implementation\n *\n * This module provides methods for requesting, retrieving, and listing attestations.\n * Attestations are cryptographically signed proofs of query results that can be\n * consumed by smart contracts and external applications.\n */\n\nimport { Types, Utils } from '@trufnetwork/kwil-js';\nimport { Action } from './action';\nimport {\n RequestAttestationInput,\n RequestAttestationResult,\n GetSignedAttestationInput,\n SignedAttestationResult,\n ListAttestationsInput,\n AttestationMetadata,\n validateAttestationRequest,\n validateListAttestationsInput,\n} from '../types/attestation';\nimport { encodeActionArgs } from '../util/AttestationEncoding';\n\n/**\n * AttestationAction provides methods for working with data attestations\n *\n * Attestations enable validators to cryptographically sign query results,\n * providing verifiable proofs that can be used in smart contracts.\n *\n * @example\n * ```typescript\n * const client = new NodeTNClient({ ... });\n * const attestationAction = client.loadAttestationAction();\n *\n * // Request an attestation\n * const result = await attestationAction.requestAttestation({\n * dataProvider: \"0x4710a8d8f0d845da110086812a32de6d90d7ff5c\",\n * streamId: \"stai0000000000000000000000000000\",\n * actionName: \"get_record\",\n * args: [dataProvider, streamId, fromTime, toTime, null, false],\n * encryptSig: false,\n * maxFee: 1000000,\n * });\n *\n * // Wait for signing (1-2 blocks)\n * await new Promise(resolve => setTimeout(resolve, 10000));\n *\n * // Retrieve signed attestation\n * const signed = await attestationAction.getSignedAttestation({\n * requestTxId: result.requestTxId,\n * });\n * ```\n */\nexport class AttestationAction extends Action {\n /**\n * Request a signed attestation of query results\n *\n * This submits a transaction requesting that validators execute a query\n * and sign the results. The leader validator will sign the attestation\n * asynchronously (typically 1-2 blocks later).\n *\n * @param input - Attestation request parameters\n * @returns Promise resolving to request result with transaction ID\n * @throws Error if validation fails or transaction fails\n *\n * @example\n * ```typescript\n * const result = await attestationAction.requestAttestation({\n * dataProvider: \"0x4710a8d8f0d845da110086812a32de6d90d7ff5c\",\n * streamId: \"stai0000000000000000000000000000\",\n * actionName: \"get_record\",\n * args: [\n * \"0x4710a8d8f0d845da110086812a32de6d90d7ff5c\",\n * \"stai0000000000000000000000000000\",\n * Math.floor(Date.now() / 1000) - 86400, // 1 day ago\n * Math.floor(Date.now() / 1000),\n * null,\n * false,\n * ],\n * encryptSig: false,\n * maxFee: 1000000,\n * });\n * console.log(`Request TX ID: ${result.requestTxId}`);\n * ```\n */\n async requestAttestation(\n input: RequestAttestationInput\n ): Promise<RequestAttestationResult> {\n // Validate input\n validateAttestationRequest(input);\n\n // Encode arguments\n const argsBytes = encodeActionArgs(input.args);\n\n // Prepare named parameters for request_attestation action\n // Note: maxFee must be a string with NUMERIC type to encode as NUMERIC(788,0) for wei amounts\n const params: Types.NamedParams[] = [{\n $data_provider: input.dataProvider,\n $stream_id: input.streamId,\n $action_name: input.actionName,\n $args_bytes: argsBytes,\n $encrypt_sig: input.encryptSig,\n $max_fee: input.maxFee.toString(),\n }];\n\n // Specify types - maxFee needs NUMERIC(78,0) for large wei amounts\n const types = {\n $max_fee: Utils.DataType.Numeric(78, 0),\n };\n\n // Execute request_attestation action\n const result = await this.executeWithNamedParams('request_attestation', params, types);\n\n // Check for errors\n if (!result.data?.tx_hash) {\n throw new Error(\n 'Failed to request attestation: no transaction hash returned'\n );\n }\n\n // Return the 64-char hex tx_hash\n return {\n requestTxId: result.data.tx_hash,\n };\n }\n\n /**\n * Retrieve a complete signed attestation payload\n *\n * This fetches the signed attestation payload for a given request transaction ID.\n * The attestation must have been signed by the leader validator first.\n *\n * If the attestation is not yet signed, this will throw an error. Clients should\n * poll with exponential backoff or wait for 1-2 blocks after requesting.\n *\n * @param input - Request transaction ID\n * @returns Promise resolving to signed attestation payload\n * @throws Error if attestation not found or not yet signed\n *\n * @example\n * ```typescript\n * // Poll for signature\n * for (let i = 0; i < 15; i++) {\n * try {\n * const signed = await attestationAction.getSignedAttestation({\n * requestTxId: \"0x123...\",\n * });\n * console.log(`Payload: ${Buffer.from(signed.payload).toString('hex')}`);\n * break;\n * } catch (e) {\n * await new Promise(resolve => setTimeout(resolve, 2000));\n * }\n * }\n * ```\n */\n async getSignedAttestation(\n input: GetSignedAttestationInput\n ): Promise<SignedAttestationResult> {\n // Validate and normalize input\n const trimmed = input.requestTxId?.trim() || '';\n if (trimmed === '') {\n throw new Error('request_tx_id is required');\n }\n\n // Strip optional \"0x\" prefix and lowercase for normalization\n const normalizedRequestTxId = trimmed.startsWith('0x')\n ? trimmed.slice(2).toLowerCase()\n : trimmed.toLowerCase();\n\n // Call get_signed_attestation view action\n const result = await this.call<Array<{ payload: string | Uint8Array }>>(\n 'get_signed_attestation',\n { $request_tx_id: normalizedRequestTxId }\n );\n\n // Extract the right value from Either, or throw if Left\n const data = result.throw();\n\n // The action returns an array of rows - extract the first row\n if (!data || !Array.isArray(data) || data.length === 0) {\n throw new Error('No attestation found for request_tx_id - may not exist or is not yet signed');\n }\n\n const row = data[0];\n if (!row || !row.payload) {\n throw new Error('No payload in attestation row');\n }\n\n // Decode base64 to bytes\n let payloadBytes: Uint8Array;\n const payloadValue = row.payload;\n\n if (typeof payloadValue === 'string') {\n // Node.js environment\n if (typeof Buffer !== 'undefined') {\n payloadBytes = new Uint8Array(Buffer.from(payloadValue, 'base64'));\n } else {\n // Browser environment\n const binaryString = atob(payloadValue);\n payloadBytes = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n payloadBytes[i] = binaryString.charCodeAt(i);\n }\n }\n } else if (payloadValue instanceof Uint8Array) {\n // Already decoded\n payloadBytes = payloadValue;\n } else {\n throw new Error(`Unexpected payload type: ${typeof payloadValue}`);\n }\n\n return {\n payload: payloadBytes,\n };\n }\n\n /**\n * List attestation metadata with optional filtering\n *\n * This returns metadata for attestations, optionally filtered by requester address or request transaction ID.\n * Supports pagination and sorting.\n *\n * @param input - Filter and pagination parameters\n * @returns Promise resolving to array of attestation metadata\n * @throws Error if parameters are invalid\n *\n * @example\n * ```typescript\n * // List my recent attestations\n * const myAddress = new Uint8Array(Buffer.from(wallet.address.slice(2), 'hex'));\n * const attestations = await attestationAction.listAttestations({\n * requester: myAddress,\n * limit: 10,\n * offset: 0,\n * orderBy: \"created_height desc\",\n * });\n *\n * attestations.forEach(att => {\n * console.log(`TX: ${att.requestTxId}, Height: ${att.createdHeight}`);\n * });\n * ```\n */\n async listAttestations(\n input: ListAttestationsInput\n ): Promise<AttestationMetadata[]> {\n // Validate input\n validateListAttestationsInput(input);\n\n // Set defaults\n const limit = input.limit ?? 5000;\n const offset = input.offset ?? 0;\n\n // Prepare parameters for list_attestations view action\n // Note: Empty Uint8Array represents BYTEA NULL (handled by kwil-js 0.9.10+)\n const params: Types.NamedParams = {\n $requester: input.requester ?? new Uint8Array(0),\n $request_tx_id: input.requestTxId ?? null,\n $limit: limit,\n $offset: offset,\n $order_by: input.orderBy ?? null,\n };\n\n // Call list_attestations view action\n const result = await this.call<any[]>('list_attestations', params);\n\n // Check for errors\n if (result.isLeft()) {\n throw new Error(\n `Failed to list attestations: HTTP status ${result.value}`\n );\n }\n\n // Extract the right value from Either\n // Note: result.value might be a getter function, so call it if needed\n const rightValue = typeof result.value === 'function' ? result.value() : result.value;\n const rows = Array.isArray(rightValue) ? rightValue : [];\n\n // If no rows, return empty array\n if (!rows || rows.length === 0) {\n return [];\n }\n\n // Parse rows into AttestationMetadata\n return rows.map((row: any, idx: number) => parseAttestationRow(row, idx));\n }\n}\n\n/**\n * Parse a single row from list_attestations result into AttestationMetadata\n *\n * Expected columns (in order):\n * 0. request_tx_id (TEXT)\n * 1. attestation_hash (BYTEA)\n * 2. requester (BYTEA)\n * 3. created_height (INT8)\n * 4. signed_height (INT8, nullable)\n * 5. encrypt_sig (BOOLEAN)\n */\nfunction parseAttestationRow(row: any, idx: number): AttestationMetadata {\n // kwil-js returns rows as objects with column names as keys\n // or as arrays depending on the query format\n let requestTxId: string;\n let attestationHash: Uint8Array;\n let requester: Uint8Array;\n let createdHeight: number;\n let signedHeight: number | null;\n let encryptSig: boolean;\n\n // Handle both array and object formats\n if (Array.isArray(row)) {\n // Array format: [col0, col1, col2, ...]\n if (row.length < 6) {\n throw new Error(\n `Row ${idx}: expected 6 columns, got ${row.length}`\n );\n }\n\n requestTxId = row[0];\n attestationHash = decodeBytea(row[1], idx, 'attestation_hash');\n requester = decodeBytea(row[2], idx, 'requester');\n createdHeight = parseInt(row[3], 10);\n signedHeight = row[4] !== null ? parseInt(row[4], 10) : null;\n encryptSig = row[5];\n } else {\n // Object format: { request_tx_id: ..., attestation_hash: ..., ... }\n requestTxId = row.request_tx_id;\n attestationHash = decodeBytea(row.attestation_hash, idx, 'attestation_hash');\n requester = decodeBytea(row.requester, idx, 'requester');\n createdHeight = parseInt(row.created_height, 10);\n signedHeight = row.signed_height !== null ? parseInt(row.signed_height, 10) : null;\n encryptSig = row.encrypt_sig;\n }\n\n return {\n requestTxId,\n attestationHash,\n requester,\n createdHeight,\n signedHeight,\n encryptSig,\n };\n}\n\n/**\n * Decode a BYTEA column from base64\n */\nfunction decodeBytea(value: any, rowIdx: number, colName: string): Uint8Array {\n if (value === null || value === undefined) {\n throw new Error(`Row ${rowIdx}: ${colName} is null or undefined`);\n }\n\n // If already Uint8Array, return as-is\n if (value instanceof Uint8Array) {\n return value;\n }\n\n // If string, decode from base64\n if (typeof value === 'string') {\n try {\n // Node.js environment\n if (typeof Buffer !== 'undefined') {\n return new Uint8Array(Buffer.from(value, 'base64'));\n } else {\n // Browser environment\n const binaryString = atob(value);\n const bytes = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n bytes[i] = binaryString.charCodeAt(i);\n }\n return bytes;\n }\n } catch (err) {\n throw new Error(\n `Row ${rowIdx}: failed to decode ${colName} as base64: ${err}`\n );\n }\n }\n\n throw new Error(\n `Row ${rowIdx}: expected ${colName} to be string or Uint8Array, got ${typeof value}`\n );\n}\n\n// Inline unit tests\nif (import.meta.vitest) {\n const { describe, it, expect } = import.meta.vitest;\n\n describe('decodeBytea', () => {\n it('should decode base64 string', () => {\n const base64 = Buffer.from([1, 2, 3, 4]).toString('base64');\n const decoded = decodeBytea(base64, 0, 'test');\n expect(Array.from(decoded)).toEqual([1, 2, 3, 4]);\n });\n\n it('should return Uint8Array as-is', () => {\n const bytes = new Uint8Array([1, 2, 3, 4]);\n const decoded = decodeBytea(bytes, 0, 'test');\n expect(decoded).toBe(bytes);\n });\n\n it('should throw on null', () => {\n expect(() => decodeBytea(null, 0, 'test')).toThrow('null or undefined');\n });\n\n it('should throw on invalid type', () => {\n expect(() => decodeBytea(123, 0, 'test')).toThrow('expected test to be string or Uint8Array');\n });\n });\n\n describe('parseAttestationRow', () => {\n it('should parse array format row', () => {\n const row = [\n 'tx123',\n Buffer.from([1, 2, 3]).toString('base64'),\n Buffer.from([4, 5, 6]).toString('base64'),\n '100',\n '200',\n true,\n ];\n\n const metadata = parseAttestationRow(row, 0);\n\n expect(metadata.requestTxId).toBe('tx123');\n expect(Array.from(metadata.attestationHash)).toEqual([1, 2, 3]);\n expect(Array.from(metadata.requester)).toEqual([4, 5, 6]);\n expect(metadata.createdHeight).toBe(100);\n expect(metadata.signedHeight).toBe(200);\n expect(metadata.encryptSig).toBe(true);\n });\n\n it('should parse object format row', () => {\n const row = {\n request_tx_id: 'tx456',\n attestation_hash: Buffer.from([7, 8, 9]).toString('base64'),\n requester: Buffer.from([10, 11, 12]).toString('base64'),\n created_height: '300',\n signed_height: null,\n encrypt_sig: false,\n };\n\n const metadata = parseAttestationRow(row, 0);\n\n expect(metadata.requestTxId).toBe('tx456');\n expect(Array.from(metadata.attestationHash)).toEqual([7, 8, 9]);\n expect(Array.from(metadata.requester)).toEqual([10, 11, 12]);\n expect(metadata.createdHeight).toBe(300);\n expect(metadata.signedHeight).toBe(null);\n expect(metadata.encryptSig).toBe(false);\n });\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,qBAA6B;AAC7B,oBAAuB;AACvB,yBASO;AACP,iCAAiC;AApBjC;AAoDO,IAAM,oBAAN,cAAgC,qBAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgC5C,MAAM,mBACJ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ACf,aAAa;AAAA,MACf;AAEA,YAAM,WAAW,oBAAoB,KAAK,CAAC;AAE3C,aAAO,SAAS,WAAW,EAAE,KAAK,OAAO;AACzC,aAAO,MAAM,KAAK,SAAS,eAAe,CAAC,EAAE,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC;AAC9D,aAAO,MAAM,KAAK,SAAS,SAAS,CAAC,EAAE,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC;AAC3D,aAAO,SAAS,aAAa,EAAE,KAAK,GAAG;AACvC,aAAO,SAAS,YAAY,EAAE,KAAK,IAAI;AACvC,aAAO,SAAS,UAAU,EAAE,KAAK,KAAK;AAAA,IACxC,CAAC;AAAA,EACH,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -23,6 +23,32 @@ __export(transactionAction_exports, {
|
|
|
23
23
|
TransactionAction: () => TransactionAction
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(transactionAction_exports);
|
|
26
|
+
var INDEXER_BASE = "https://indexer.infra.truf.network";
|
|
27
|
+
function normalizeTransactionId(txId) {
|
|
28
|
+
const lower = txId.toLowerCase();
|
|
29
|
+
return lower.startsWith("0x") ? lower : `0x${lower}`;
|
|
30
|
+
}
|
|
31
|
+
async function fetchTransactionStampMs(blockHeight, txId) {
|
|
32
|
+
const url = `${INDEXER_BASE}/v0/chain/transactions?from-block=${blockHeight}&to-block=${blockHeight}&order=desc`;
|
|
33
|
+
try {
|
|
34
|
+
const response = await fetch(url);
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
console.warn(`Indexer returned ${response.status} while fetching block ${blockHeight} for tx ${txId}`);
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
const data = await response.json();
|
|
40
|
+
if (!data.ok || !Array.isArray(data.data)) {
|
|
41
|
+
console.warn(`Indexer payload malformed for block ${blockHeight} (tx ${txId})`);
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
const normalizedTargetHash = normalizeTransactionId(txId);
|
|
45
|
+
const tx = data.data.find((entry) => normalizeTransactionId(entry.hash) === normalizedTargetHash);
|
|
46
|
+
return tx?.stamp_ms ?? 0;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.warn(`Failed to fetch stamp_ms for tx ${txId} at block ${blockHeight}`, error);
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
26
52
|
var TransactionAction = class _TransactionAction {
|
|
27
53
|
kwilClient;
|
|
28
54
|
kwilSigner;
|
|
@@ -114,9 +140,11 @@ var TransactionAction = class _TransactionAction {
|
|
|
114
140
|
if (!Number.isFinite(blockHeight) || blockHeight < 0) {
|
|
115
141
|
throw new Error(`Invalid block height: ${row.block_height} (tx: ${row.tx_id})`);
|
|
116
142
|
}
|
|
143
|
+
const stampMs = await fetchTransactionStampMs(blockHeight, row.tx_id);
|
|
117
144
|
return {
|
|
118
145
|
txId: row.tx_id,
|
|
119
146
|
blockHeight,
|
|
147
|
+
stampMs,
|
|
120
148
|
method: row.method,
|
|
121
149
|
caller: row.caller,
|
|
122
150
|
feeAmount,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/contracts-api/transactionAction.ts"],
|
|
4
|
-
"sourcesContent": ["import { KwilSigner, NodeKwil, WebKwil
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { KwilSigner, NodeKwil, WebKwil } from \"@trufnetwork/kwil-js\";\r\nimport { TransactionEvent, FeeDistribution, GetTransactionEventInput } from \"../types/transaction\";\r\n\r\nconst INDEXER_BASE = \"https://indexer.infra.truf.network\";\r\n\r\nfunction normalizeTransactionId(txId: string): string {\r\n const lower = txId.toLowerCase();\r\n return lower.startsWith(\"0x\") ? lower : `0x${lower}`;\r\n}\r\n\r\nasync function fetchTransactionStampMs(blockHeight: number, txId: string): Promise<number> {\r\n const url = `${INDEXER_BASE}/v0/chain/transactions?from-block=${blockHeight}&to-block=${blockHeight}&order=desc`;\r\n try {\r\n const response = await fetch(url);\r\n if (!response.ok) {\r\n console.warn(`Indexer returned ${response.status} while fetching block ${blockHeight} for tx ${txId}`);\r\n return 0;\r\n }\r\n\r\n const data = await response.json() as {\r\n ok: boolean;\r\n data: Array<{\r\n block_height: number;\r\n hash: string;\r\n stamp_ms: number | null;\r\n }>;\r\n };\r\n\r\n if (!data.ok || !Array.isArray(data.data)) {\r\n console.warn(`Indexer payload malformed for block ${blockHeight} (tx ${txId})`);\r\n return 0;\r\n }\r\n\r\n const normalizedTargetHash = normalizeTransactionId(txId);\r\n const tx = data.data.find(entry => normalizeTransactionId(entry.hash) === normalizedTargetHash);\r\n return tx?.stamp_ms ?? 0;\r\n } catch (error) {\r\n console.warn(`Failed to fetch stamp_ms for tx ${txId} at block ${blockHeight}`, error);\r\n return 0;\r\n }\r\n}\r\n\r\n/**\r\n * Database row structure returned from get_transaction_event action\r\n */\r\ninterface TransactionEventRow {\r\n tx_id: string;\r\n block_height: string | number;\r\n method: string;\r\n caller: string;\r\n fee_amount: string | number;\r\n fee_recipient?: string | null;\r\n metadata?: string | null;\r\n fee_distributions: string;\r\n}\r\n\r\n/**\r\n * TransactionAction provides methods for querying transaction ledger data\r\n */\r\nexport class TransactionAction {\r\n protected kwilClient: WebKwil | NodeKwil;\r\n protected kwilSigner: KwilSigner;\r\n\r\n constructor(kwilClient: WebKwil | NodeKwil, kwilSigner: KwilSigner) {\r\n this.kwilClient = kwilClient;\r\n this.kwilSigner = kwilSigner;\r\n }\r\n\r\n /**\r\n * Fetches detailed transaction information by transaction hash\r\n *\r\n * @param input Transaction query input containing tx hash\r\n * @returns Promise resolving to transaction event with fee details\r\n * @throws Error if transaction not found or query fails\r\n *\r\n * @example\r\n * ```typescript\r\n * const txAction = client.loadTransactionAction();\r\n * const txEvent = await txAction.getTransactionEvent({\r\n * txId: \"0xabcdef123456...\"\r\n * });\r\n * console.log(`Method: ${txEvent.method}, Fee: ${txEvent.feeAmount} TRUF`);\r\n * ```\r\n */\r\n async getTransactionEvent(input: GetTransactionEventInput): Promise<TransactionEvent> {\r\n if (!input.txId || input.txId.trim() === \"\") {\r\n throw new Error(\"tx_id is required\");\r\n }\r\n\r\n const result = await this.kwilClient.call(\r\n {\r\n namespace: \"main\",\r\n name: \"get_transaction_event\",\r\n inputs: {\r\n $tx_id: input.txId,\r\n },\r\n },\r\n this.kwilSigner\r\n );\r\n\r\n if (result.status !== 200) {\r\n throw new Error(`Failed to get transaction event: HTTP ${result.status}`);\r\n }\r\n\r\n if (!result.data?.result || result.data.result.length === 0) {\r\n throw new Error(`Transaction not found: ${input.txId}`);\r\n }\r\n\r\n const row = result.data.result[0] as TransactionEventRow;\r\n\r\n // Validate required fields\r\n if (!row.method || typeof row.method !== 'string' || row.method.trim() === '') {\r\n throw new Error(`Missing or invalid method field (tx: ${row.tx_id})`);\r\n }\r\n\r\n if (!row.caller || typeof row.caller !== 'string' || row.caller.trim() === '') {\r\n throw new Error(`Missing or invalid caller field (tx: ${row.tx_id})`);\r\n }\r\n\r\n if (row.fee_amount === null || row.fee_amount === undefined) {\r\n throw new Error(`Missing fee_amount field (tx: ${row.tx_id})`);\r\n }\r\n\r\n // Validate fee_amount is numeric (can be string or number)\r\n const feeAmount = typeof row.fee_amount === 'string' ? row.fee_amount : String(row.fee_amount);\r\n const feeAmountNum = Number(feeAmount);\r\n if (isNaN(feeAmountNum) || !Number.isFinite(feeAmountNum)) {\r\n throw new Error(`Invalid fee_amount (not numeric): ${row.fee_amount} (tx: ${row.tx_id})`);\r\n }\r\n if (feeAmountNum < 0) {\r\n throw new Error(`Invalid fee_amount (negative): ${row.fee_amount} (tx: ${row.tx_id})`);\r\n }\r\n\r\n // Parse fee_distributions string: \"recipient1:amount1,recipient2:amount2\"\r\n const feeDistributions: FeeDistribution[] = [];\r\n if (row.fee_distributions && row.fee_distributions !== \"\") {\r\n const parts = row.fee_distributions.split(\",\");\r\n for (const part of parts) {\r\n const trimmedPart = part.trim();\r\n if (trimmedPart) {\r\n // Split only on first colon to handle addresses with colons\r\n const colonIndex = trimmedPart.indexOf(\":\");\r\n if (colonIndex === -1) {\r\n throw new Error(`Invalid fee distribution format (missing colon): ${trimmedPart} (tx: ${row.tx_id})`);\r\n }\r\n\r\n const recipient = trimmedPart.substring(0, colonIndex).trim();\r\n const amount = trimmedPart.substring(colonIndex + 1).trim();\r\n\r\n if (!recipient || !amount) {\r\n throw new Error(`Invalid fee distribution entry (empty recipient or amount): ${trimmedPart} (tx: ${row.tx_id})`);\r\n }\r\n\r\n // Validate amount is numeric and non-negative\r\n const amt = Number(amount);\r\n if (isNaN(amt) || !Number.isFinite(amt)) {\r\n throw new Error(`Invalid fee distribution amount (not numeric): ${amount} (tx: ${row.tx_id})`);\r\n }\r\n if (amt < 0) {\r\n throw new Error(`Invalid fee distribution amount (negative): ${amount} (tx: ${row.tx_id})`);\r\n }\r\n\r\n feeDistributions.push({ recipient, amount });\r\n }\r\n }\r\n }\r\n\r\n // Validate block height\r\n const blockHeight = typeof row.block_height === 'number'\r\n ? row.block_height\r\n : parseInt(row.block_height, 10);\r\n if (!Number.isFinite(blockHeight) || blockHeight < 0) {\r\n throw new Error(`Invalid block height: ${row.block_height} (tx: ${row.tx_id})`);\r\n }\r\n\r\n const stampMs = await fetchTransactionStampMs(blockHeight, row.tx_id);\r\n\r\n return {\r\n txId: row.tx_id,\r\n blockHeight,\r\n stampMs,\r\n method: row.method,\r\n caller: row.caller,\r\n feeAmount,\r\n feeRecipient: row.fee_recipient || undefined,\r\n metadata: row.metadata || undefined,\r\n feeDistributions,\r\n };\r\n }\r\n\r\n /**\r\n * Creates a TransactionAction instance from an existing client and signer\r\n *\r\n * @param kwilClient The Kwil client (Web or Node)\r\n * @param kwilSigner The Kwil signer for authentication\r\n * @returns A new TransactionAction instance\r\n */\r\n static fromClient(kwilClient: WebKwil | NodeKwil, kwilSigner: KwilSigner): T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,aAAa,IAAI,KAAK;AAEpE,WAAO;AAAA,MACL,MAAM,IAAI;AAAA,MACV;AAAA,MACA;AAAA,MACA,QAAQ,IAAI;AAAA,MACZ,QAAQ,IAAI;AAAA,MACZ;AAAA,MACA,cAAc,IAAI,iBAAiB;AAAA,MACnC,UAAU,IAAI,YAAY;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,OAAO,WAAW,YAAgC,YAA2C;AAC3F,WAAO,IAAI,mBAAkB,YAAY,UAAU;AAAA,EACrD;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/types/attestation.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Type definitions for attestation operations\n *\n * Attestations enable validators to cryptographically sign query results,\n * providing verifiable proofs that can be consumed by smart contracts and\n * external applications.\n */\n\n/**\n * Input parameters for requesting an attestation\n */\nexport interface RequestAttestationInput {\n /**\n * Data provider address (0x-prefixed, 42 characters)\n * Example: \"0x4710a8d8f0d845da110086812a32de6d90d7ff5c\"\n */\n dataProvider: string;\n\n /**\n * Stream ID (32 characters)\n * Example: \"stai0000000000000000000000000000\"\n */\n streamId: string;\n\n /**\n * Action name to attest (must be in allowlist)\n * Example: \"get_record\", \"get_index\"\n */\n actionName: string;\n\n /**\n * Action arguments (will be encoded)\n * Must match the signature of the action\n */\n args: any[];\n\n /**\n * Whether to encrypt the signature (must be false in MVP)\n * Future: ECIES encryption to requester's public key\n */\n encryptSig: boolean;\n\n /**\n * Maximum fee willing to pay (in wei, as NUMERIC(78,0))\n * Accepts number, string, or bigint for large values (up to 40 TRUF = 40e18 wei)\n * Transaction will abort if actual fee exceeds this\n * Accepts number, string, or bigint for large values\n */\n maxFee: number | string | bigint;\n}\n\n/**\n * Result of requesting an attestation\n */\nexport interface RequestAttestationResult {\n /**\n * Transaction ID for this attestation request\n * Use this to retrieve the signed attestation later\n */\n requestTxId: string;\n}\n\n/**\n * Input parameters for retrieving a signed attestation\n */\nexport interface GetSignedAttestationInput {\n /**\n * Transaction ID from request_attestation\n */\n requestTxId: string;\n}\n\n/**\n * Result of retrieving a signed attestation\n */\nexport interface SignedAttestationResult {\n /**\n * Complete attestation payload: canonical (8 fields) + signature\n *\n * Format: version | algo | height | provider | stream | action | args | result | signature\n *\n * This payload can be passed to EVM contracts for verification\n */\n payload: Uint8Array;\n}\n\n/**\n * Input parameters for listing attestations\n */\nexport interface ListAttestationsInput {\n /**\n * Optional: Filter by requester address (20 bytes)\n * If provided, only returns attestations requested by this address\n */\n requester?: Uint8Array;\n\n /**\n * Optional: Maximum number of results (1-5000, default 5000)\n */\n limit?: number;\n\n /**\n * Optional: Pagination offset (default 0)\n */\n offset?: number;\n\n /**\n * Optional: Sort order\n *\n * Allowed values:\n * - \"created_height asc\"\n * - \"created_height desc\"\n * - \"signed_height asc\"\n * - \"signed_height desc\"\n *\n * Case-insensitive\n */\n orderBy?: string;\n}\n\n/**\n * Metadata for a single attestation\n */\nexport interface AttestationMetadata {\n /**\n * Transaction ID for this attestation request\n */\n requestTxId: string;\n\n /**\n * Attestation hash (identifies this attestation)\n */\n attestationHash: Uint8Array;\n\n /**\n * Address of the requester (20 bytes)\n */\n requester: Uint8Array;\n\n /**\n * Block height when attestation was created\n */\n createdHeight: number;\n\n /**\n * Block height when attestation was signed (null if not yet signed)\n */\n signedHeight: number | null;\n\n /**\n * Whether signature is encrypted\n */\n encryptSig: boolean;\n}\n\n/**\n * Validates attestation request input\n *\n * @param input - The attestation request to validate\n * @throws Error if validation fails\n */\nexport function validateAttestationRequest(input: RequestAttestationInput): void {\n // Data provider validation\n if (input.dataProvider.length !== 42) {\n throw new Error(\n `data_provider must be 0x-prefixed 40 hex characters, got ${input.dataProvider.length} chars`\n );\n }\n\n if (!input.dataProvider.startsWith('0x')) {\n throw new Error('data_provider must start with 0x prefix');\n }\n\n // Validate hex after 0x prefix\n const hex = input.dataProvider.slice(2);\n if (!/^[0-9a-fA-F]{40}$/.test(hex)) {\n throw new Error('data_provider must contain valid hex characters after 0x prefix');\n }\n\n // Stream ID validation\n if (input.streamId.length !== 32) {\n throw new Error(`stream_id must be 32 characters, got ${input.streamId.length}`);\n }\n\n // Action name validation\n if (!input.actionName || input.actionName.trim() === '') {\n throw new Error('action_name cannot be empty');\n }\n\n // Encryption validation\n if (input.encryptSig) {\n throw new Error('encryption not implemented in MVP');\n }\n\n // Fee validation - handle number, string, or bigint\n const maxFeeNum = typeof input.maxFee === 'bigint'\n ? input.maxFee\n : typeof input.maxFee === 'string'\n ? BigInt(input.maxFee)\n : BigInt(Math.floor(input.maxFee));\n\n if (maxFeeNum < 0n) {\n throw new Error(`max_fee must be non-negative, got ${input.maxFee}`);\n }\n}\n\n/**\n * Whitelist of valid orderBy values (lowercase canonical form)\n */\nconst VALID_ORDER_BY_VALUES = [\n 'created_height asc',\n 'created_height desc',\n 'signed_height asc',\n 'signed_height desc',\n];\n\n/**\n * Validates orderBy parameter (case-insensitive)\n *\n * @param orderBy - The orderBy value to validate\n * @returns true if valid, false otherwise\n */\nexport function isValidOrderBy(orderBy: string): boolean {\n // Normalize to lowercase for case-insensitive comparison\n const normalized = orderBy.trim().toLowerCase();\n return VALID_ORDER_BY_VALUES.includes(normalized);\n}\n\n/**\n * Validates list attestations input\n *\n * @param input - The list attestations input to validate\n * @throws Error if validation fails\n */\nexport function validateListAttestationsInput(input: ListAttestationsInput): void {\n // Validate limit\n if (input.limit !== undefined) {\n if (input.limit < 1 || input.limit > 5000) {\n throw new Error('limit must be between 1 and 5000');\n }\n }\n\n // Validate offset\n if (input.offset !== undefined) {\n if (input.offset < 0) {\n throw new Error('offset must be non-negative');\n }\n }\n\n // Validate requester length\n if (input.requester !== undefined) {\n if (input.requester.length !== 20) {\n throw new Error('requester must be exactly 20 bytes');\n }\n }\n\n // Validate orderBy\n if (input.orderBy !== undefined) {\n if (!isValidOrderBy(input.orderBy)) {\n throw new Error(\n `Invalid orderBy value. Must be one of: ${VALID_ORDER_BY_VALUES.slice(0, 4).join(', ')}`\n );\n }\n }\n}\n\n// Inline unit tests\nif (import.meta.vitest) {\n const { describe, it, expect } = import.meta.vitest;\n\n describe('validateAttestationRequest', () => {\n it('should accept valid input', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0x4710a8d8f0d845da110086812a32de6d90d7ff5c',\n streamId: 'stai0000000000000000000000000000',\n actionName: 'get_record',\n args: [],\n encryptSig: false,\n maxFee: 1000000,\n })\n ).not.toThrow();\n });\n\n it('should reject invalid data_provider length', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0xinvalid',\n streamId: 'stai0000000000000000000000000000',\n actionName: 'get_record',\n args: [],\n encryptSig: false,\n maxFee: 1000,\n })\n ).toThrow('data_provider must be 0x-prefixed 40 hex characters');\n });\n\n it('should reject data_provider without 0x prefix', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '4710a8d8f0d845da110086812a32de6d90d7ff5c00',\n streamId: 'stai0000000000000000000000000000',\n actionName: 'get_record',\n args: [],\n encryptSig: false,\n maxFee: 1000,\n })\n ).toThrow('data_provider must start with 0x prefix');\n });\n\n it('should reject data_provider with invalid hex', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0xGGGGa8d8f0d845da110086812a32de6d90d7ff5c',\n streamId: 'stai0000000000000000000000000000',\n actionName: 'get_record',\n args: [],\n encryptSig: false,\n maxFee: 1000,\n })\n ).toThrow('data_provider must contain valid hex characters');\n });\n\n it('should reject short stream_id', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0x4710a8d8f0d845da110086812a32de6d90d7ff5c',\n streamId: 'short',\n actionName: 'get_record',\n args: [],\n encryptSig: false,\n maxFee: 1000,\n })\n ).toThrow('stream_id must be 32 characters');\n });\n\n it('should reject long stream_id', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0x4710a8d8f0d845da110086812a32de6d90d7ff5c',\n streamId: 'stai00000000000000000000000000000000',\n actionName: 'get_record',\n args: [],\n encryptSig: false,\n maxFee: 1000,\n })\n ).toThrow('stream_id must be 32 characters');\n });\n\n it('should reject empty action_name', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0x4710a8d8f0d845da110086812a32de6d90d7ff5c',\n streamId: 'stai0000000000000000000000000000',\n actionName: '',\n args: [],\n encryptSig: false,\n maxFee: 1000,\n })\n ).toThrow('action_name cannot be empty');\n });\n\n it('should reject whitespace-only action_name', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0x4710a8d8f0d845da110086812a32de6d90d7ff5c',\n streamId: 'stai0000000000000000000000000000',\n actionName: ' ',\n args: [],\n encryptSig: false,\n maxFee: 1000,\n })\n ).toThrow('action_name cannot be empty');\n });\n\n it('should reject encryptSig=true', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0x4710a8d8f0d845da110086812a32de6d90d7ff5c',\n streamId: 'stai0000000000000000000000000000',\n actionName: 'get_record',\n args: [],\n encryptSig: true,\n maxFee: 1000,\n })\n ).toThrow('encryption not implemented in MVP');\n });\n\n it('should reject negative maxFee', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0x4710a8d8f0d845da110086812a32de6d90d7ff5c',\n streamId: 'stai0000000000000000000000000000',\n actionName: 'get_record',\n args: [],\n encryptSig: false,\n maxFee: -1,\n })\n ).toThrow('max_fee must be non-negative');\n });\n });\n\n describe('isValidOrderBy', () => {\n it('should accept valid lowercase orderBy', () => {\n expect(isValidOrderBy('created_height asc')).toBe(true);\n expect(isValidOrderBy('created_height desc')).toBe(true);\n expect(isValidOrderBy('signed_height asc')).toBe(true);\n expect(isValidOrderBy('signed_height desc')).toBe(true);\n });\n\n it('should accept valid uppercase orderBy', () => {\n expect(isValidOrderBy('created_height ASC')).toBe(true);\n expect(isValidOrderBy('created_height DESC')).toBe(true);\n expect(isValidOrderBy('signed_height ASC')).toBe(true);\n expect(isValidOrderBy('signed_height DESC')).toBe(true);\n });\n\n it('should accept mixed case and trim whitespace', () => {\n expect(isValidOrderBy(' created_height ASC ')).toBe(true);\n expect(isValidOrderBy('Created_Height Desc')).toBe(true);\n expect(isValidOrderBy('SIGNED_HEIGHT asc')).toBe(true);\n expect(isValidOrderBy(' signed_height DESC ')).toBe(true);\n });\n\n it('should reject invalid orderBy', () => {\n expect(isValidOrderBy('invalid')).toBe(false);\n expect(isValidOrderBy('created_height')).toBe(false);\n expect(isValidOrderBy('created_height ascending')).toBe(false);\n expect(isValidOrderBy('')).toBe(false);\n });\n });\n\n describe('validateListAttestationsInput', () => {\n it('should accept valid input with all fields', () => {\n expect(() =>\n validateListAttestationsInput({\n requester: new Uint8Array(20),\n limit: 100,\n offset: 0,\n orderBy: 'created_height desc',\n })\n ).not.toThrow();\n });\n\n it('should accept valid input with no optional fields', () => {\n expect(() => validateListAttestationsInput({})).not.toThrow();\n });\n\n it('should reject limit < 1', () => {\n expect(() =>\n validateListAttestationsInput({\n limit: 0,\n })\n ).toThrow('limit must be between 1 and 5000');\n });\n\n it('should reject limit > 5000', () => {\n expect(() =>\n validateListAttestationsInput({\n limit: 5001,\n })\n ).toThrow('limit must be between 1 and 5000');\n });\n\n it('should reject negative offset', () => {\n expect(() =>\n validateListAttestationsInput({\n offset: -1,\n })\n ).toThrow('offset must be non-negative');\n });\n\n it('should reject requester != 20 bytes (too long)', () => {\n expect(() =>\n validateListAttestationsInput({\n requester: new Uint8Array(21),\n })\n ).toThrow('requester must be exactly 20 bytes');\n });\n\n it('should reject requester != 20 bytes (too short)', () => {\n expect(() =>\n validateListAttestationsInput({\n requester: new Uint8Array(19),\n })\n ).toThrow('requester must be exactly 20 bytes');\n });\n\n it('should reject invalid orderBy', () => {\n expect(() =>\n validateListAttestationsInput({\n orderBy: 'invalid',\n })\n ).toThrow('Invalid orderBy value');\n });\n });\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * Type definitions for attestation operations\n *\n * Attestations enable validators to cryptographically sign query results,\n * providing verifiable proofs that can be consumed by smart contracts and\n * external applications.\n */\n\n/**\n * Input parameters for requesting an attestation\n */\nexport interface RequestAttestationInput {\n /**\n * Data provider address (0x-prefixed, 42 characters)\n * Example: \"0x4710a8d8f0d845da110086812a32de6d90d7ff5c\"\n */\n dataProvider: string;\n\n /**\n * Stream ID (32 characters)\n * Example: \"stai0000000000000000000000000000\"\n */\n streamId: string;\n\n /**\n * Action name to attest (must be in allowlist)\n * Example: \"get_record\", \"get_index\"\n */\n actionName: string;\n\n /**\n * Action arguments (will be encoded)\n * Must match the signature of the action\n */\n args: any[];\n\n /**\n * Whether to encrypt the signature (must be false in MVP)\n * Future: ECIES encryption to requester's public key\n */\n encryptSig: boolean;\n\n /**\n * Maximum fee willing to pay (in wei, as NUMERIC(78,0))\n * Accepts number, string, or bigint for large values (up to 40 TRUF = 40e18 wei)\n * Transaction will abort if actual fee exceeds this\n * Accepts number, string, or bigint for large values\n */\n maxFee: number | string | bigint;\n}\n\n/**\n * Result of requesting an attestation\n */\nexport interface RequestAttestationResult {\n /**\n * Transaction ID for this attestation request\n * Use this to retrieve the signed attestation later\n */\n requestTxId: string;\n}\n\n/**\n * Input parameters for retrieving a signed attestation\n */\nexport interface GetSignedAttestationInput {\n /**\n * Transaction ID from request_attestation\n */\n requestTxId: string;\n}\n\n/**\n * Result of retrieving a signed attestation\n */\nexport interface SignedAttestationResult {\n /**\n * Complete attestation payload: canonical (8 fields) + signature\n *\n * Format: version | algo | height | provider | stream | action | args | result | signature\n *\n * This payload can be passed to EVM contracts for verification\n */\n payload: Uint8Array;\n}\n\n/**\n * Input parameters for listing attestations\n */\nexport interface ListAttestationsInput {\n /**\n * Optional: Filter by requester address (20 bytes)\n * If provided, only returns attestations requested by this address\n */\n requester?: Uint8Array;\n\n /**\n * Optional: Filter by request transaction ID\n * If provided, only returns attestations matching this transaction ID\n */\n requestTxId?: string;\n\n /**\n * Optional: Maximum number of results (1-5000, default 5000)\n */\n limit?: number;\n\n /**\n * Optional: Pagination offset (default 0)\n */\n offset?: number;\n\n /**\n * Optional: Sort order\n *\n * Allowed values:\n * - \"created_height asc\"\n * - \"created_height desc\"\n * - \"signed_height asc\"\n * - \"signed_height desc\"\n *\n * Case-insensitive\n */\n orderBy?: string;\n}\n\n/**\n * Metadata for a single attestation\n */\nexport interface AttestationMetadata {\n /**\n * Transaction ID for this attestation request\n */\n requestTxId: string;\n\n /**\n * Attestation hash (identifies this attestation)\n */\n attestationHash: Uint8Array;\n\n /**\n * Address of the requester (20 bytes)\n */\n requester: Uint8Array;\n\n /**\n * Block height when attestation was created\n */\n createdHeight: number;\n\n /**\n * Block height when attestation was signed (null if not yet signed)\n */\n signedHeight: number | null;\n\n /**\n * Whether signature is encrypted\n */\n encryptSig: boolean;\n}\n\n/**\n * Validates attestation request input\n *\n * @param input - The attestation request to validate\n * @throws Error if validation fails\n */\nexport function validateAttestationRequest(input: RequestAttestationInput): void {\n // Data provider validation\n if (input.dataProvider.length !== 42) {\n throw new Error(\n `data_provider must be 0x-prefixed 40 hex characters, got ${input.dataProvider.length} chars`\n );\n }\n\n if (!input.dataProvider.startsWith('0x')) {\n throw new Error('data_provider must start with 0x prefix');\n }\n\n // Validate hex after 0x prefix\n const hex = input.dataProvider.slice(2);\n if (!/^[0-9a-fA-F]{40}$/.test(hex)) {\n throw new Error('data_provider must contain valid hex characters after 0x prefix');\n }\n\n // Stream ID validation\n if (input.streamId.length !== 32) {\n throw new Error(`stream_id must be 32 characters, got ${input.streamId.length}`);\n }\n\n // Action name validation\n if (!input.actionName || input.actionName.trim() === '') {\n throw new Error('action_name cannot be empty');\n }\n\n // Encryption validation\n if (input.encryptSig) {\n throw new Error('encryption not implemented in MVP');\n }\n\n // Fee validation - handle number, string, or bigint\n const maxFeeNum = typeof input.maxFee === 'bigint'\n ? input.maxFee\n : typeof input.maxFee === 'string'\n ? BigInt(input.maxFee)\n : BigInt(Math.floor(input.maxFee));\n\n if (maxFeeNum < 0n) {\n throw new Error(`max_fee must be non-negative, got ${input.maxFee}`);\n }\n}\n\n/**\n * Whitelist of valid orderBy values (lowercase canonical form)\n */\nconst VALID_ORDER_BY_VALUES = [\n 'created_height asc',\n 'created_height desc',\n 'signed_height asc',\n 'signed_height desc',\n];\n\n/**\n * Validates orderBy parameter (case-insensitive)\n *\n * @param orderBy - The orderBy value to validate\n * @returns true if valid, false otherwise\n */\nexport function isValidOrderBy(orderBy: string): boolean {\n // Normalize to lowercase for case-insensitive comparison\n const normalized = orderBy.trim().toLowerCase();\n return VALID_ORDER_BY_VALUES.includes(normalized);\n}\n\n/**\n * Validates list attestations input\n *\n * @param input - The list attestations input to validate\n * @throws Error if validation fails\n */\nexport function validateListAttestationsInput(input: ListAttestationsInput): void {\n // Validate limit\n if (input.limit !== undefined) {\n if (input.limit < 1 || input.limit > 5000) {\n throw new Error('limit must be between 1 and 5000');\n }\n }\n\n // Validate offset\n if (input.offset !== undefined) {\n if (input.offset < 0) {\n throw new Error('offset must be non-negative');\n }\n }\n\n // Validate requester length\n if (input.requester !== undefined) {\n if (input.requester.length !== 20) {\n throw new Error('requester must be exactly 20 bytes');\n }\n }\n\n // Validate orderBy\n if (input.orderBy !== undefined) {\n if (!isValidOrderBy(input.orderBy)) {\n throw new Error(\n `Invalid orderBy value. Must be one of: ${VALID_ORDER_BY_VALUES.slice(0, 4).join(', ')}`\n );\n }\n }\n}\n\n// Inline unit tests\nif (import.meta.vitest) {\n const { describe, it, expect } = import.meta.vitest;\n\n describe('validateAttestationRequest', () => {\n it('should accept valid input', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0x4710a8d8f0d845da110086812a32de6d90d7ff5c',\n streamId: 'stai0000000000000000000000000000',\n actionName: 'get_record',\n args: [],\n encryptSig: false,\n maxFee: 1000000,\n })\n ).not.toThrow();\n });\n\n it('should reject invalid data_provider length', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0xinvalid',\n streamId: 'stai0000000000000000000000000000',\n actionName: 'get_record',\n args: [],\n encryptSig: false,\n maxFee: 1000,\n })\n ).toThrow('data_provider must be 0x-prefixed 40 hex characters');\n });\n\n it('should reject data_provider without 0x prefix', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '4710a8d8f0d845da110086812a32de6d90d7ff5c00',\n streamId: 'stai0000000000000000000000000000',\n actionName: 'get_record',\n args: [],\n encryptSig: false,\n maxFee: 1000,\n })\n ).toThrow('data_provider must start with 0x prefix');\n });\n\n it('should reject data_provider with invalid hex', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0xGGGGa8d8f0d845da110086812a32de6d90d7ff5c',\n streamId: 'stai0000000000000000000000000000',\n actionName: 'get_record',\n args: [],\n encryptSig: false,\n maxFee: 1000,\n })\n ).toThrow('data_provider must contain valid hex characters');\n });\n\n it('should reject short stream_id', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0x4710a8d8f0d845da110086812a32de6d90d7ff5c',\n streamId: 'short',\n actionName: 'get_record',\n args: [],\n encryptSig: false,\n maxFee: 1000,\n })\n ).toThrow('stream_id must be 32 characters');\n });\n\n it('should reject long stream_id', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0x4710a8d8f0d845da110086812a32de6d90d7ff5c',\n streamId: 'stai00000000000000000000000000000000',\n actionName: 'get_record',\n args: [],\n encryptSig: false,\n maxFee: 1000,\n })\n ).toThrow('stream_id must be 32 characters');\n });\n\n it('should reject empty action_name', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0x4710a8d8f0d845da110086812a32de6d90d7ff5c',\n streamId: 'stai0000000000000000000000000000',\n actionName: '',\n args: [],\n encryptSig: false,\n maxFee: 1000,\n })\n ).toThrow('action_name cannot be empty');\n });\n\n it('should reject whitespace-only action_name', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0x4710a8d8f0d845da110086812a32de6d90d7ff5c',\n streamId: 'stai0000000000000000000000000000',\n actionName: ' ',\n args: [],\n encryptSig: false,\n maxFee: 1000,\n })\n ).toThrow('action_name cannot be empty');\n });\n\n it('should reject encryptSig=true', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0x4710a8d8f0d845da110086812a32de6d90d7ff5c',\n streamId: 'stai0000000000000000000000000000',\n actionName: 'get_record',\n args: [],\n encryptSig: true,\n maxFee: 1000,\n })\n ).toThrow('encryption not implemented in MVP');\n });\n\n it('should reject negative maxFee', () => {\n expect(() =>\n validateAttestationRequest({\n dataProvider: '0x4710a8d8f0d845da110086812a32de6d90d7ff5c',\n streamId: 'stai0000000000000000000000000000',\n actionName: 'get_record',\n args: [],\n encryptSig: false,\n maxFee: -1,\n })\n ).toThrow('max_fee must be non-negative');\n });\n });\n\n describe('isValidOrderBy', () => {\n it('should accept valid lowercase orderBy', () => {\n expect(isValidOrderBy('created_height asc')).toBe(true);\n expect(isValidOrderBy('created_height desc')).toBe(true);\n expect(isValidOrderBy('signed_height asc')).toBe(true);\n expect(isValidOrderBy('signed_height desc')).toBe(true);\n });\n\n it('should accept valid uppercase orderBy', () => {\n expect(isValidOrderBy('created_height ASC')).toBe(true);\n expect(isValidOrderBy('created_height DESC')).toBe(true);\n expect(isValidOrderBy('signed_height ASC')).toBe(true);\n expect(isValidOrderBy('signed_height DESC')).toBe(true);\n });\n\n it('should accept mixed case and trim whitespace', () => {\n expect(isValidOrderBy(' created_height ASC ')).toBe(true);\n expect(isValidOrderBy('Created_Height Desc')).toBe(true);\n expect(isValidOrderBy('SIGNED_HEIGHT asc')).toBe(true);\n expect(isValidOrderBy(' signed_height DESC ')).toBe(true);\n });\n\n it('should reject invalid orderBy', () => {\n expect(isValidOrderBy('invalid')).toBe(false);\n expect(isValidOrderBy('created_height')).toBe(false);\n expect(isValidOrderBy('created_height ascending')).toBe(false);\n expect(isValidOrderBy('')).toBe(false);\n });\n });\n\n describe('validateListAttestationsInput', () => {\n it('should accept valid input with all fields', () => {\n expect(() =>\n validateListAttestationsInput({\n requester: new Uint8Array(20),\n limit: 100,\n offset: 0,\n orderBy: 'created_height desc',\n })\n ).not.toThrow();\n });\n\n it('should accept valid input with no optional fields', () => {\n expect(() => validateListAttestationsInput({})).not.toThrow();\n });\n\n it('should reject limit < 1', () => {\n expect(() =>\n validateListAttestationsInput({\n limit: 0,\n })\n ).toThrow('limit must be between 1 and 5000');\n });\n\n it('should reject limit > 5000', () => {\n expect(() =>\n validateListAttestationsInput({\n limit: 5001,\n })\n ).toThrow('limit must be between 1 and 5000');\n });\n\n it('should reject negative offset', () => {\n expect(() =>\n validateListAttestationsInput({\n offset: -1,\n })\n ).toThrow('offset must be non-negative');\n });\n\n it('should reject requester != 20 bytes (too long)', () => {\n expect(() =>\n validateListAttestationsInput({\n requester: new Uint8Array(21),\n })\n ).toThrow('requester must be exactly 20 bytes');\n });\n\n it('should reject requester != 20 bytes (too short)', () => {\n expect(() =>\n validateListAttestationsInput({\n requester: new Uint8Array(19),\n })\n ).toThrow('requester must be exactly 20 bytes');\n });\n\n it('should reject invalid orderBy', () => {\n expect(() =>\n validateListAttestationsInput({\n orderBy: 'invalid',\n })\n ).toThrow('Invalid orderBy value');\n });\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuKO,SAAS,2BAA2B,OAAsC;AAE/E,MAAI,MAAM,aAAa,WAAW,IAAI;AACpC,UAAM,IAAI;AAAA,MACR,4DAA4D,MAAM,aAAa,MAAM;AAAA,IACvF;AAAA,EACF;AAEA,MAAI,CAAC,MAAM,aAAa,WAAW,IAAI,GAAG;AACxC,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC3D;AAGA,QAAM,MAAM,MAAM,aAAa,MAAM,CAAC;AACtC,MAAI,CAAC,oBAAoB,KAAK,GAAG,GAAG;AAClC,UAAM,IAAI,MAAM,iEAAiE;AAAA,EACnF;AAGA,MAA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version": 3,
|
|
3
3
|
"sources": ["../../../src/types/transaction.ts"],
|
|
4
|
-
"sourcesContent": ["export interface LastTransaction {\r\n /** Block height */\r\n blockHeight: number;\r\n /** Which action was taken */\r\n method: string;\r\n /** Address that sent the on\u2010chain tx */\r\n sender: string;\r\n /** Hash of the on\u2010chain transaction */\r\n transactionHash: string;\r\n /** Millisecond timestamp from the block header */\r\n stampMs: number;\r\n}\r\n\r\n/**\r\n * Represents a single fee distribution\r\n */\r\nexport interface FeeDistribution {\r\n /** Recipient Ethereum address */\r\n recipient: string;\r\n /** Amount as string (handles large numbers) */\r\n amount: string;\r\n}\r\n\r\n/**\r\n * Represents a single transaction event from the ledger\r\n *\r\n * Fee Fields Relationship:\r\n * - feeAmount: Total fee charged for the transaction (as string to handle large numbers)\r\n * - feeRecipient: Primary fee recipient address (if single recipient). May be undefined for:\r\n * 1. Transactions from fee-exempt wallets (system:network_writer role)\r\n * 2. Transactions with multiple fee distributions (use feeDistributions instead)\r\n * - feeDistributions: Array of fee distributions to multiple recipients\r\n * - Aggregated using string_agg() in get_transaction_event query\r\n * - Parsed from \"recipient1:amount1,recipient2:amount2\" format\r\n * - Sum of amounts in feeDistributions equals feeAmount (when present)\r\n * - Empty array when there are no distributions or single recipient (use feeRecipient)\r\n */\r\nexport interface TransactionEvent {\r\n /** Transaction hash (0x-prefixed) */\r\n txId: string;\r\n /** Block height when transaction was included */\r\n blockHeight: number;\r\n /** Method name (e.g., \"deployStream\", \"insertRecords\") */\r\n method: string;\r\n /** Ethereum address of caller (lowercase, 0x-prefixed) */\r\n caller: string;\r\n /**\r\n * Total fee amount as string (handles large numbers with 18 decimals)\r\n * Will be \"0\" for fee-exempt wallets (system:network_writer role)\r\n */\r\n feeAmount: string;\r\n /**\r\n * Primary fee recipient address (lowercase, 0x-prefixed)\r\n * Undefined when:\r\n * - Wallet is fee-exempt (feeAmount === \"0\")\r\n * - Fee has multiple distributions (check feeDistributions)\r\n */\r\n feeRecipient?: string;\r\n /** Optional metadata JSON (nullable) */\r\n metadata?: string;\r\n /**\r\n * Array of fee distributions to multiple recipients\r\n * Aggregated from transaction_event_distributions table using string_agg()\r\n */\r\n feeDistributions: FeeDistribution[];\r\n}\r\n\r\n/**\r\n * Input for getting transaction event\r\n */\r\nexport interface GetTransactionEventInput {\r\n /** Transaction hash (with or without 0x prefix) */\r\n txId: string;\r\n}\r\n"],
|
|
4
|
+
"sourcesContent": ["export interface LastTransaction {\r\n /** Block height */\r\n blockHeight: number;\r\n /** Which action was taken */\r\n method: string;\r\n /** Address that sent the on\u2010chain tx */\r\n sender: string;\r\n /** Hash of the on\u2010chain transaction */\r\n transactionHash: string;\r\n /** Millisecond timestamp from the block header */\r\n stampMs: number;\r\n}\r\n\r\n/**\r\n * Represents a single fee distribution\r\n */\r\nexport interface FeeDistribution {\r\n /** Recipient Ethereum address */\r\n recipient: string;\r\n /** Amount as string (handles large numbers) */\r\n amount: string;\r\n}\r\n\r\n/**\r\n * Represents a single transaction event from the ledger\r\n *\r\n * Fee Fields Relationship:\r\n * - feeAmount: Total fee charged for the transaction (as string to handle large numbers)\r\n * - feeRecipient: Primary fee recipient address (if single recipient). May be undefined for:\r\n * 1. Transactions from fee-exempt wallets (system:network_writer role)\r\n * 2. Transactions with multiple fee distributions (use feeDistributions instead)\r\n * - feeDistributions: Array of fee distributions to multiple recipients\r\n * - Aggregated using string_agg() in get_transaction_event query\r\n * - Parsed from \"recipient1:amount1,recipient2:amount2\" format\r\n * - Sum of amounts in feeDistributions equals feeAmount (when present)\r\n * - Empty array when there are no distributions or single recipient (use feeRecipient)\r\n */\r\nexport interface TransactionEvent {\r\n /** Transaction hash (0x-prefixed) */\r\n txId: string;\r\n /** Block height when transaction was included */\r\n blockHeight: number;\r\n /**\r\n * Millisecond timestamp from the block header via indexer lookup.\r\n * Will be 0 when the indexer is unavailable.\r\n */\r\n stampMs: number;\r\n /** Method name (e.g., \"deployStream\", \"insertRecords\") */\r\n method: string;\r\n /** Ethereum address of caller (lowercase, 0x-prefixed) */\r\n caller: string;\r\n /**\r\n * Total fee amount as string (handles large numbers with 18 decimals)\r\n * Will be \"0\" for fee-exempt wallets (system:network_writer role)\r\n */\r\n feeAmount: string;\r\n /**\r\n * Primary fee recipient address (lowercase, 0x-prefixed)\r\n * Undefined when:\r\n * - Wallet is fee-exempt (feeAmount === \"0\")\r\n * - Fee has multiple distributions (check feeDistributions)\r\n */\r\n feeRecipient?: string;\r\n /** Optional metadata JSON (nullable) */\r\n metadata?: string;\r\n /**\r\n * Array of fee distributions to multiple recipients\r\n * Aggregated from transaction_event_distributions table using string_agg()\r\n */\r\n feeDistributions: FeeDistribution[];\r\n}\r\n\r\n/**\r\n * Input for getting transaction event\r\n */\r\nexport interface GetTransactionEventInput {\r\n /** Transaction hash (with or without 0x prefix) */\r\n txId: string;\r\n}\r\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -133,7 +133,7 @@ var AttestationAction = class extends Action {
|
|
|
133
133
|
/**
|
|
134
134
|
* List attestation metadata with optional filtering
|
|
135
135
|
*
|
|
136
|
-
* This returns metadata for attestations, optionally filtered by requester address.
|
|
136
|
+
* This returns metadata for attestations, optionally filtered by requester address or request transaction ID.
|
|
137
137
|
* Supports pagination and sorting.
|
|
138
138
|
*
|
|
139
139
|
* @param input - Filter and pagination parameters
|
|
@@ -162,6 +162,7 @@ var AttestationAction = class extends Action {
|
|
|
162
162
|
const offset = input.offset ?? 0;
|
|
163
163
|
const params = {
|
|
164
164
|
$requester: input.requester ?? new Uint8Array(0),
|
|
165
|
+
$request_tx_id: input.requestTxId ?? null,
|
|
165
166
|
$limit: limit,
|
|
166
167
|
$offset: offset,
|
|
167
168
|
$order_by: input.orderBy ?? null
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/contracts-api/attestationAction.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Attestation action implementation\n *\n * This module provides methods for requesting, retrieving, and listing attestations.\n * Attestations are cryptographically signed proofs of query results that can be\n * consumed by smart contracts and external applications.\n */\n\nimport { Types, Utils } from '@trufnetwork/kwil-js';\nimport { Action } from './action';\nimport {\n RequestAttestationInput,\n RequestAttestationResult,\n GetSignedAttestationInput,\n SignedAttestationResult,\n ListAttestationsInput,\n AttestationMetadata,\n validateAttestationRequest,\n validateListAttestationsInput,\n} from '../types/attestation';\nimport { encodeActionArgs } from '../util/AttestationEncoding';\n\n/**\n * AttestationAction provides methods for working with data attestations\n *\n * Attestations enable validators to cryptographically sign query results,\n * providing verifiable proofs that can be used in smart contracts.\n *\n * @example\n * ```typescript\n * const client = new NodeTNClient({ ... });\n * const attestationAction = client.loadAttestationAction();\n *\n * // Request an attestation\n * const result = await attestationAction.requestAttestation({\n * dataProvider: \"0x4710a8d8f0d845da110086812a32de6d90d7ff5c\",\n * streamId: \"stai0000000000000000000000000000\",\n * actionName: \"get_record\",\n * args: [dataProvider, streamId, fromTime, toTime, null, false],\n * encryptSig: false,\n * maxFee: 1000000,\n * });\n *\n * // Wait for signing (1-2 blocks)\n * await new Promise(resolve => setTimeout(resolve, 10000));\n *\n * // Retrieve signed attestation\n * const signed = await attestationAction.getSignedAttestation({\n * requestTxId: result.requestTxId,\n * });\n * ```\n */\nexport class AttestationAction extends Action {\n /**\n * Request a signed attestation of query results\n *\n * This submits a transaction requesting that validators execute a query\n * and sign the results. The leader validator will sign the attestation\n * asynchronously (typically 1-2 blocks later).\n *\n * @param input - Attestation request parameters\n * @returns Promise resolving to request result with transaction ID\n * @throws Error if validation fails or transaction fails\n *\n * @example\n * ```typescript\n * const result = await attestationAction.requestAttestation({\n * dataProvider: \"0x4710a8d8f0d845da110086812a32de6d90d7ff5c\",\n * streamId: \"stai0000000000000000000000000000\",\n * actionName: \"get_record\",\n * args: [\n * \"0x4710a8d8f0d845da110086812a32de6d90d7ff5c\",\n * \"stai0000000000000000000000000000\",\n * Math.floor(Date.now() / 1000) - 86400, // 1 day ago\n * Math.floor(Date.now() / 1000),\n * null,\n * false,\n * ],\n * encryptSig: false,\n * maxFee: 1000000,\n * });\n * console.log(`Request TX ID: ${result.requestTxId}`);\n * ```\n */\n async requestAttestation(\n input: RequestAttestationInput\n ): Promise<RequestAttestationResult> {\n // Validate input\n validateAttestationRequest(input);\n\n // Encode arguments\n const argsBytes = encodeActionArgs(input.args);\n\n // Prepare named parameters for request_attestation action\n // Note: maxFee must be a string with NUMERIC type to encode as NUMERIC(788,0) for wei amounts\n const params: Types.NamedParams[] = [{\n $data_provider: input.dataProvider,\n $stream_id: input.streamId,\n $action_name: input.actionName,\n $args_bytes: argsBytes,\n $encrypt_sig: input.encryptSig,\n $max_fee: input.maxFee.toString(),\n }];\n\n // Specify types - maxFee needs NUMERIC(78,0) for large wei amounts\n const types = {\n $max_fee: Utils.DataType.Numeric(78, 0),\n };\n\n // Execute request_attestation action\n const result = await this.executeWithNamedParams('request_attestation', params, types);\n\n // Check for errors\n if (!result.data?.tx_hash) {\n throw new Error(\n 'Failed to request attestation: no transaction hash returned'\n );\n }\n\n // Return the 64-char hex tx_hash\n return {\n requestTxId: result.data.tx_hash,\n };\n }\n\n /**\n * Retrieve a complete signed attestation payload\n *\n * This fetches the signed attestation payload for a given request transaction ID.\n * The attestation must have been signed by the leader validator first.\n *\n * If the attestation is not yet signed, this will throw an error. Clients should\n * poll with exponential backoff or wait for 1-2 blocks after requesting.\n *\n * @param input - Request transaction ID\n * @returns Promise resolving to signed attestation payload\n * @throws Error if attestation not found or not yet signed\n *\n * @example\n * ```typescript\n * // Poll for signature\n * for (let i = 0; i < 15; i++) {\n * try {\n * const signed = await attestationAction.getSignedAttestation({\n * requestTxId: \"0x123...\",\n * });\n * console.log(`Payload: ${Buffer.from(signed.payload).toString('hex')}`);\n * break;\n * } catch (e) {\n * await new Promise(resolve => setTimeout(resolve, 2000));\n * }\n * }\n * ```\n */\n async getSignedAttestation(\n input: GetSignedAttestationInput\n ): Promise<SignedAttestationResult> {\n // Validate and normalize input\n const trimmed = input.requestTxId?.trim() || '';\n if (trimmed === '') {\n throw new Error('request_tx_id is required');\n }\n\n // Strip optional \"0x\" prefix and lowercase for normalization\n const normalizedRequestTxId = trimmed.startsWith('0x')\n ? trimmed.slice(2).toLowerCase()\n : trimmed.toLowerCase();\n\n // Call get_signed_attestation view action\n const result = await this.call<Array<{ payload: string | Uint8Array }>>(\n 'get_signed_attestation',\n { $request_tx_id: normalizedRequestTxId }\n );\n\n // Extract the right value from Either, or throw if Left\n const data = result.throw();\n\n // The action returns an array of rows - extract the first row\n if (!data || !Array.isArray(data) || data.length === 0) {\n throw new Error('No attestation found for request_tx_id - may not exist or is not yet signed');\n }\n\n const row = data[0];\n if (!row || !row.payload) {\n throw new Error('No payload in attestation row');\n }\n\n // Decode base64 to bytes\n let payloadBytes: Uint8Array;\n const payloadValue = row.payload;\n\n if (typeof payloadValue === 'string') {\n // Node.js environment\n if (typeof Buffer !== 'undefined') {\n payloadBytes = new Uint8Array(Buffer.from(payloadValue, 'base64'));\n } else {\n // Browser environment\n const binaryString = atob(payloadValue);\n payloadBytes = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n payloadBytes[i] = binaryString.charCodeAt(i);\n }\n }\n } else if (payloadValue instanceof Uint8Array) {\n // Already decoded\n payloadBytes = payloadValue;\n } else {\n throw new Error(`Unexpected payload type: ${typeof payloadValue}`);\n }\n\n return {\n payload: payloadBytes,\n };\n }\n\n /**\n * List attestation metadata with optional filtering\n *\n * This returns metadata for attestations, optionally filtered by requester address.\n * Supports pagination and sorting.\n *\n * @param input - Filter and pagination parameters\n * @returns Promise resolving to array of attestation metadata\n * @throws Error if parameters are invalid\n *\n * @example\n * ```typescript\n * // List my recent attestations\n * const myAddress = new Uint8Array(Buffer.from(wallet.address.slice(2), 'hex'));\n * const attestations = await attestationAction.listAttestations({\n * requester: myAddress,\n * limit: 10,\n * offset: 0,\n * orderBy: \"created_height desc\",\n * });\n *\n * attestations.forEach(att => {\n * console.log(`TX: ${att.requestTxId}, Height: ${att.createdHeight}`);\n * });\n * ```\n */\n async listAttestations(\n input: ListAttestationsInput\n ): Promise<AttestationMetadata[]> {\n // Validate input\n validateListAttestationsInput(input);\n\n // Set defaults\n const limit = input.limit ?? 5000;\n const offset = input.offset ?? 0;\n\n // Prepare parameters for list_attestations view action\n // Note: Empty Uint8Array represents BYTEA NULL (handled by kwil-js 0.9.10+)\n const params: Types.NamedParams = {\n $requester: input.requester ?? new Uint8Array(0),\n $limit: limit,\n $offset: offset,\n $order_by: input.orderBy ?? null,\n };\n\n // Call list_attestations view action\n const result = await this.call<any[]>('list_attestations', params);\n\n // Check for errors\n if (result.isLeft()) {\n throw new Error(\n `Failed to list attestations: HTTP status ${result.value}`\n );\n }\n\n // Extract the right value from Either\n // Note: result.value might be a getter function, so call it if needed\n const rightValue = typeof result.value === 'function' ? result.value() : result.value;\n const rows = Array.isArray(rightValue) ? rightValue : [];\n\n // If no rows, return empty array\n if (!rows || rows.length === 0) {\n return [];\n }\n\n // Parse rows into AttestationMetadata\n return rows.map((row: any, idx: number) => parseAttestationRow(row, idx));\n }\n}\n\n/**\n * Parse a single row from list_attestations result into AttestationMetadata\n *\n * Expected columns (in order):\n * 0. request_tx_id (TEXT)\n * 1. attestation_hash (BYTEA)\n * 2. requester (BYTEA)\n * 3. created_height (INT8)\n * 4. signed_height (INT8, nullable)\n * 5. encrypt_sig (BOOLEAN)\n */\nfunction parseAttestationRow(row: any, idx: number): AttestationMetadata {\n // kwil-js returns rows as objects with column names as keys\n // or as arrays depending on the query format\n let requestTxId: string;\n let attestationHash: Uint8Array;\n let requester: Uint8Array;\n let createdHeight: number;\n let signedHeight: number | null;\n let encryptSig: boolean;\n\n // Handle both array and object formats\n if (Array.isArray(row)) {\n // Array format: [col0, col1, col2, ...]\n if (row.length < 6) {\n throw new Error(\n `Row ${idx}: expected 6 columns, got ${row.length}`\n );\n }\n\n requestTxId = row[0];\n attestationHash = decodeBytea(row[1], idx, 'attestation_hash');\n requester = decodeBytea(row[2], idx, 'requester');\n createdHeight = parseInt(row[3], 10);\n signedHeight = row[4] !== null ? parseInt(row[4], 10) : null;\n encryptSig = row[5];\n } else {\n // Object format: { request_tx_id: ..., attestation_hash: ..., ... }\n requestTxId = row.request_tx_id;\n attestationHash = decodeBytea(row.attestation_hash, idx, 'attestation_hash');\n requester = decodeBytea(row.requester, idx, 'requester');\n createdHeight = parseInt(row.created_height, 10);\n signedHeight = row.signed_height !== null ? parseInt(row.signed_height, 10) : null;\n encryptSig = row.encrypt_sig;\n }\n\n return {\n requestTxId,\n attestationHash,\n requester,\n createdHeight,\n signedHeight,\n encryptSig,\n };\n}\n\n/**\n * Decode a BYTEA column from base64\n */\nfunction decodeBytea(value: any, rowIdx: number, colName: string): Uint8Array {\n if (value === null || value === undefined) {\n throw new Error(`Row ${rowIdx}: ${colName} is null or undefined`);\n }\n\n // If already Uint8Array, return as-is\n if (value instanceof Uint8Array) {\n return value;\n }\n\n // If string, decode from base64\n if (typeof value === 'string') {\n try {\n // Node.js environment\n if (typeof Buffer !== 'undefined') {\n return new Uint8Array(Buffer.from(value, 'base64'));\n } else {\n // Browser environment\n const binaryString = atob(value);\n const bytes = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n bytes[i] = binaryString.charCodeAt(i);\n }\n return bytes;\n }\n } catch (err) {\n throw new Error(\n `Row ${rowIdx}: failed to decode ${colName} as base64: ${err}`\n );\n }\n }\n\n throw new Error(\n `Row ${rowIdx}: expected ${colName} to be string or Uint8Array, got ${typeof value}`\n );\n}\n\n// Inline unit tests\nif (import.meta.vitest) {\n const { describe, it, expect } = import.meta.vitest;\n\n describe('decodeBytea', () => {\n it('should decode base64 string', () => {\n const base64 = Buffer.from([1, 2, 3, 4]).toString('base64');\n const decoded = decodeBytea(base64, 0, 'test');\n expect(Array.from(decoded)).toEqual([1, 2, 3, 4]);\n });\n\n it('should return Uint8Array as-is', () => {\n const bytes = new Uint8Array([1, 2, 3, 4]);\n const decoded = decodeBytea(bytes, 0, 'test');\n expect(decoded).toBe(bytes);\n });\n\n it('should throw on null', () => {\n expect(() => decodeBytea(null, 0, 'test')).toThrow('null or undefined');\n });\n\n it('should throw on invalid type', () => {\n expect(() => decodeBytea(123, 0, 'test')).toThrow('expected test to be string or Uint8Array');\n });\n });\n\n describe('parseAttestationRow', () => {\n it('should parse array format row', () => {\n const row = [\n 'tx123',\n Buffer.from([1, 2, 3]).toString('base64'),\n Buffer.from([4, 5, 6]).toString('base64'),\n '100',\n '200',\n true,\n ];\n\n const metadata = parseAttestationRow(row, 0);\n\n expect(metadata.requestTxId).toBe('tx123');\n expect(Array.from(metadata.attestationHash)).toEqual([1, 2, 3]);\n expect(Array.from(metadata.requester)).toEqual([4, 5, 6]);\n expect(metadata.createdHeight).toBe(100);\n expect(metadata.signedHeight).toBe(200);\n expect(metadata.encryptSig).toBe(true);\n });\n\n it('should parse object format row', () => {\n const row = {\n request_tx_id: 'tx456',\n attestation_hash: Buffer.from([7, 8, 9]).toString('base64'),\n requester: Buffer.from([10, 11, 12]).toString('base64'),\n created_height: '300',\n signed_height: null,\n encrypt_sig: false,\n };\n\n const metadata = parseAttestationRow(row, 0);\n\n expect(metadata.requestTxId).toBe('tx456');\n expect(Array.from(metadata.attestationHash)).toEqual([7, 8, 9]);\n expect(Array.from(metadata.requester)).toEqual([10, 11, 12]);\n expect(metadata.createdHeight).toBe(300);\n expect(metadata.signedHeight).toBe(null);\n expect(metadata.encryptSig).toBe(false);\n });\n });\n}\n"],
|
|
5
|
-
"mappings": ";AAQA,SAAgB,aAAa;AAC7B,SAAS,cAAc;AACvB;AAAA,EAOE;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AAgC1B,IAAM,oBAAN,cAAgC,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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AAE,CAAC,EAAE,SAAS,QAAQ;AAAA,QACtD,gBAAgB;AAAA,QAChB,eAAe;AAAA,QACf,aAAa;AAAA,MACf;AAEA,YAAM,WAAW,oBAAoB,KAAK,CAAC;AAE3C,aAAO,SAAS,WAAW,EAAE,KAAK,OAAO;AACzC,aAAO,MAAM,KAAK,SAAS,eAAe,CAAC,EAAE,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC;AAC9D,aAAO,MAAM,KAAK,SAAS,SAAS,CAAC,EAAE,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC;AAC3D,aAAO,SAAS,aAAa,EAAE,KAAK,GAAG;AACvC,aAAO,SAAS,YAAY,EAAE,KAAK,IAAI;AACvC,aAAO,SAAS,UAAU,EAAE,KAAK,KAAK;AAAA,IACxC,CAAC;AAAA,EACH,CAAC;AACH;",
|
|
4
|
+
"sourcesContent": ["/**\n * Attestation action implementation\n *\n * This module provides methods for requesting, retrieving, and listing attestations.\n * Attestations are cryptographically signed proofs of query results that can be\n * consumed by smart contracts and external applications.\n */\n\nimport { Types, Utils } from '@trufnetwork/kwil-js';\nimport { Action } from './action';\nimport {\n RequestAttestationInput,\n RequestAttestationResult,\n GetSignedAttestationInput,\n SignedAttestationResult,\n ListAttestationsInput,\n AttestationMetadata,\n validateAttestationRequest,\n validateListAttestationsInput,\n} from '../types/attestation';\nimport { encodeActionArgs } from '../util/AttestationEncoding';\n\n/**\n * AttestationAction provides methods for working with data attestations\n *\n * Attestations enable validators to cryptographically sign query results,\n * providing verifiable proofs that can be used in smart contracts.\n *\n * @example\n * ```typescript\n * const client = new NodeTNClient({ ... });\n * const attestationAction = client.loadAttestationAction();\n *\n * // Request an attestation\n * const result = await attestationAction.requestAttestation({\n * dataProvider: \"0x4710a8d8f0d845da110086812a32de6d90d7ff5c\",\n * streamId: \"stai0000000000000000000000000000\",\n * actionName: \"get_record\",\n * args: [dataProvider, streamId, fromTime, toTime, null, false],\n * encryptSig: false,\n * maxFee: 1000000,\n * });\n *\n * // Wait for signing (1-2 blocks)\n * await new Promise(resolve => setTimeout(resolve, 10000));\n *\n * // Retrieve signed attestation\n * const signed = await attestationAction.getSignedAttestation({\n * requestTxId: result.requestTxId,\n * });\n * ```\n */\nexport class AttestationAction extends Action {\n /**\n * Request a signed attestation of query results\n *\n * This submits a transaction requesting that validators execute a query\n * and sign the results. The leader validator will sign the attestation\n * asynchronously (typically 1-2 blocks later).\n *\n * @param input - Attestation request parameters\n * @returns Promise resolving to request result with transaction ID\n * @throws Error if validation fails or transaction fails\n *\n * @example\n * ```typescript\n * const result = await attestationAction.requestAttestation({\n * dataProvider: \"0x4710a8d8f0d845da110086812a32de6d90d7ff5c\",\n * streamId: \"stai0000000000000000000000000000\",\n * actionName: \"get_record\",\n * args: [\n * \"0x4710a8d8f0d845da110086812a32de6d90d7ff5c\",\n * \"stai0000000000000000000000000000\",\n * Math.floor(Date.now() / 1000) - 86400, // 1 day ago\n * Math.floor(Date.now() / 1000),\n * null,\n * false,\n * ],\n * encryptSig: false,\n * maxFee: 1000000,\n * });\n * console.log(`Request TX ID: ${result.requestTxId}`);\n * ```\n */\n async requestAttestation(\n input: RequestAttestationInput\n ): Promise<RequestAttestationResult> {\n // Validate input\n validateAttestationRequest(input);\n\n // Encode arguments\n const argsBytes = encodeActionArgs(input.args);\n\n // Prepare named parameters for request_attestation action\n // Note: maxFee must be a string with NUMERIC type to encode as NUMERIC(788,0) for wei amounts\n const params: Types.NamedParams[] = [{\n $data_provider: input.dataProvider,\n $stream_id: input.streamId,\n $action_name: input.actionName,\n $args_bytes: argsBytes,\n $encrypt_sig: input.encryptSig,\n $max_fee: input.maxFee.toString(),\n }];\n\n // Specify types - maxFee needs NUMERIC(78,0) for large wei amounts\n const types = {\n $max_fee: Utils.DataType.Numeric(78, 0),\n };\n\n // Execute request_attestation action\n const result = await this.executeWithNamedParams('request_attestation', params, types);\n\n // Check for errors\n if (!result.data?.tx_hash) {\n throw new Error(\n 'Failed to request attestation: no transaction hash returned'\n );\n }\n\n // Return the 64-char hex tx_hash\n return {\n requestTxId: result.data.tx_hash,\n };\n }\n\n /**\n * Retrieve a complete signed attestation payload\n *\n * This fetches the signed attestation payload for a given request transaction ID.\n * The attestation must have been signed by the leader validator first.\n *\n * If the attestation is not yet signed, this will throw an error. Clients should\n * poll with exponential backoff or wait for 1-2 blocks after requesting.\n *\n * @param input - Request transaction ID\n * @returns Promise resolving to signed attestation payload\n * @throws Error if attestation not found or not yet signed\n *\n * @example\n * ```typescript\n * // Poll for signature\n * for (let i = 0; i < 15; i++) {\n * try {\n * const signed = await attestationAction.getSignedAttestation({\n * requestTxId: \"0x123...\",\n * });\n * console.log(`Payload: ${Buffer.from(signed.payload).toString('hex')}`);\n * break;\n * } catch (e) {\n * await new Promise(resolve => setTimeout(resolve, 2000));\n * }\n * }\n * ```\n */\n async getSignedAttestation(\n input: GetSignedAttestationInput\n ): Promise<SignedAttestationResult> {\n // Validate and normalize input\n const trimmed = input.requestTxId?.trim() || '';\n if (trimmed === '') {\n throw new Error('request_tx_id is required');\n }\n\n // Strip optional \"0x\" prefix and lowercase for normalization\n const normalizedRequestTxId = trimmed.startsWith('0x')\n ? trimmed.slice(2).toLowerCase()\n : trimmed.toLowerCase();\n\n // Call get_signed_attestation view action\n const result = await this.call<Array<{ payload: string | Uint8Array }>>(\n 'get_signed_attestation',\n { $request_tx_id: normalizedRequestTxId }\n );\n\n // Extract the right value from Either, or throw if Left\n const data = result.throw();\n\n // The action returns an array of rows - extract the first row\n if (!data || !Array.isArray(data) || data.length === 0) {\n throw new Error('No attestation found for request_tx_id - may not exist or is not yet signed');\n }\n\n const row = data[0];\n if (!row || !row.payload) {\n throw new Error('No payload in attestation row');\n }\n\n // Decode base64 to bytes\n let payloadBytes: Uint8Array;\n const payloadValue = row.payload;\n\n if (typeof payloadValue === 'string') {\n // Node.js environment\n if (typeof Buffer !== 'undefined') {\n payloadBytes = new Uint8Array(Buffer.from(payloadValue, 'base64'));\n } else {\n // Browser environment\n const binaryString = atob(payloadValue);\n payloadBytes = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n payloadBytes[i] = binaryString.charCodeAt(i);\n }\n }\n } else if (payloadValue instanceof Uint8Array) {\n // Already decoded\n payloadBytes = payloadValue;\n } else {\n throw new Error(`Unexpected payload type: ${typeof payloadValue}`);\n }\n\n return {\n payload: payloadBytes,\n };\n }\n\n /**\n * List attestation metadata with optional filtering\n *\n * This returns metadata for attestations, optionally filtered by requester address or request transaction ID.\n * Supports pagination and sorting.\n *\n * @param input - Filter and pagination parameters\n * @returns Promise resolving to array of attestation metadata\n * @throws Error if parameters are invalid\n *\n * @example\n * ```typescript\n * // List my recent attestations\n * const myAddress = new Uint8Array(Buffer.from(wallet.address.slice(2), 'hex'));\n * const attestations = await attestationAction.listAttestations({\n * requester: myAddress,\n * limit: 10,\n * offset: 0,\n * orderBy: \"created_height desc\",\n * });\n *\n * attestations.forEach(att => {\n * console.log(`TX: ${att.requestTxId}, Height: ${att.createdHeight}`);\n * });\n * ```\n */\n async listAttestations(\n input: ListAttestationsInput\n ): Promise<AttestationMetadata[]> {\n // Validate input\n validateListAttestationsInput(input);\n\n // Set defaults\n const limit = input.limit ?? 5000;\n const offset = input.offset ?? 0;\n\n // Prepare parameters for list_attestations view action\n // Note: Empty Uint8Array represents BYTEA NULL (handled by kwil-js 0.9.10+)\n const params: Types.NamedParams = {\n $requester: input.requester ?? new Uint8Array(0),\n $request_tx_id: input.requestTxId ?? null,\n $limit: limit,\n $offset: offset,\n $order_by: input.orderBy ?? null,\n };\n\n // Call list_attestations view action\n const result = await this.call<any[]>('list_attestations', params);\n\n // Check for errors\n if (result.isLeft()) {\n throw new Error(\n `Failed to list attestations: HTTP status ${result.value}`\n );\n }\n\n // Extract the right value from Either\n // Note: result.value might be a getter function, so call it if needed\n const rightValue = typeof result.value === 'function' ? result.value() : result.value;\n const rows = Array.isArray(rightValue) ? rightValue : [];\n\n // If no rows, return empty array\n if (!rows || rows.length === 0) {\n return [];\n }\n\n // Parse rows into AttestationMetadata\n return rows.map((row: any, idx: number) => parseAttestationRow(row, idx));\n }\n}\n\n/**\n * Parse a single row from list_attestations result into AttestationMetadata\n *\n * Expected columns (in order):\n * 0. request_tx_id (TEXT)\n * 1. attestation_hash (BYTEA)\n * 2. requester (BYTEA)\n * 3. created_height (INT8)\n * 4. signed_height (INT8, nullable)\n * 5. encrypt_sig (BOOLEAN)\n */\nfunction parseAttestationRow(row: any, idx: number): AttestationMetadata {\n // kwil-js returns rows as objects with column names as keys\n // or as arrays depending on the query format\n let requestTxId: string;\n let attestationHash: Uint8Array;\n let requester: Uint8Array;\n let createdHeight: number;\n let signedHeight: number | null;\n let encryptSig: boolean;\n\n // Handle both array and object formats\n if (Array.isArray(row)) {\n // Array format: [col0, col1, col2, ...]\n if (row.length < 6) {\n throw new Error(\n `Row ${idx}: expected 6 columns, got ${row.length}`\n );\n }\n\n requestTxId = row[0];\n attestationHash = decodeBytea(row[1], idx, 'attestation_hash');\n requester = decodeBytea(row[2], idx, 'requester');\n createdHeight = parseInt(row[3], 10);\n signedHeight = row[4] !== null ? parseInt(row[4], 10) : null;\n encryptSig = row[5];\n } else {\n // Object format: { request_tx_id: ..., attestation_hash: ..., ... }\n requestTxId = row.request_tx_id;\n attestationHash = decodeBytea(row.attestation_hash, idx, 'attestation_hash');\n requester = decodeBytea(row.requester, idx, 'requester');\n createdHeight = parseInt(row.created_height, 10);\n signedHeight = row.signed_height !== null ? parseInt(row.signed_height, 10) : null;\n encryptSig = row.encrypt_sig;\n }\n\n return {\n requestTxId,\n attestationHash,\n requester,\n createdHeight,\n signedHeight,\n encryptSig,\n };\n}\n\n/**\n * Decode a BYTEA column from base64\n */\nfunction decodeBytea(value: any, rowIdx: number, colName: string): Uint8Array {\n if (value === null || value === undefined) {\n throw new Error(`Row ${rowIdx}: ${colName} is null or undefined`);\n }\n\n // If already Uint8Array, return as-is\n if (value instanceof Uint8Array) {\n return value;\n }\n\n // If string, decode from base64\n if (typeof value === 'string') {\n try {\n // Node.js environment\n if (typeof Buffer !== 'undefined') {\n return new Uint8Array(Buffer.from(value, 'base64'));\n } else {\n // Browser environment\n const binaryString = atob(value);\n const bytes = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n bytes[i] = binaryString.charCodeAt(i);\n }\n return bytes;\n }\n } catch (err) {\n throw new Error(\n `Row ${rowIdx}: failed to decode ${colName} as base64: ${err}`\n );\n }\n }\n\n throw new Error(\n `Row ${rowIdx}: expected ${colName} to be string or Uint8Array, got ${typeof value}`\n );\n}\n\n// Inline unit tests\nif (import.meta.vitest) {\n const { describe, it, expect } = import.meta.vitest;\n\n describe('decodeBytea', () => {\n it('should decode base64 string', () => {\n const base64 = Buffer.from([1, 2, 3, 4]).toString('base64');\n const decoded = decodeBytea(base64, 0, 'test');\n expect(Array.from(decoded)).toEqual([1, 2, 3, 4]);\n });\n\n it('should return Uint8Array as-is', () => {\n const bytes = new Uint8Array([1, 2, 3, 4]);\n const decoded = decodeBytea(bytes, 0, 'test');\n expect(decoded).toBe(bytes);\n });\n\n it('should throw on null', () => {\n expect(() => decodeBytea(null, 0, 'test')).toThrow('null or undefined');\n });\n\n it('should throw on invalid type', () => {\n expect(() => decodeBytea(123, 0, 'test')).toThrow('expected test to be string or Uint8Array');\n });\n });\n\n describe('parseAttestationRow', () => {\n it('should parse array format row', () => {\n const row = [\n 'tx123',\n Buffer.from([1, 2, 3]).toString('base64'),\n Buffer.from([4, 5, 6]).toString('base64'),\n '100',\n '200',\n true,\n ];\n\n const metadata = parseAttestationRow(row, 0);\n\n expect(metadata.requestTxId).toBe('tx123');\n expect(Array.from(metadata.attestationHash)).toEqual([1, 2, 3]);\n expect(Array.from(metadata.requester)).toEqual([4, 5, 6]);\n expect(metadata.createdHeight).toBe(100);\n expect(metadata.signedHeight).toBe(200);\n expect(metadata.encryptSig).toBe(true);\n });\n\n it('should parse object format row', () => {\n const row = {\n request_tx_id: 'tx456',\n attestation_hash: Buffer.from([7, 8, 9]).toString('base64'),\n requester: Buffer.from([10, 11, 12]).toString('base64'),\n created_height: '300',\n signed_height: null,\n encrypt_sig: false,\n };\n\n const metadata = parseAttestationRow(row, 0);\n\n expect(metadata.requestTxId).toBe('tx456');\n expect(Array.from(metadata.attestationHash)).toEqual([7, 8, 9]);\n expect(Array.from(metadata.requester)).toEqual([10, 11, 12]);\n expect(metadata.createdHeight).toBe(300);\n expect(metadata.signedHeight).toBe(null);\n expect(metadata.encryptSig).toBe(false);\n });\n });\n}\n"],
|
|
5
|
+
"mappings": ";AAQA,SAAgB,aAAa;AAC7B,SAAS,cAAc;AACvB;AAAA,EAOE;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AAgC1B,IAAM,oBAAN,cAAgC,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgC5C,MAAM,mBACJ,OACmC;AAEnC,+BAA2B,KAAK;AAGhC,UAAM,YAAY,iBAAiB,MAAM,IAAI;AAI7C,UAAM,SAA8B,CAAC;AAAA,MACnC,gBAAgB,MAAM;AAAA,MACtB,YAAY,MAAM;AAAA,MAClB,cAAc,MAAM;AAAA,MACpB,aAAa;AAAA,MACb,cAAc,MAAM;AAAA,MACpB,UAAU,MAAM,OAAO,SAAS;AAAA,IAClC,CAAC;AAGD,UAAM,QAAQ;AAAA,MACZ,UAAU,MAAM,SAAS,QAAQ,IAAI,CAAC;AAAA,IACxC;AAGA,UAAM,SAAS,MAAM,KAAK,uBAAuB,uBAAuB,QAAQ,KAAK;AAGrF,QAAI,CAAC,OAAO,MAAM,SAAS;AACzB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAGA,WAAO;AAAA,MACL,aAAa,OAAO,KAAK;AAAA,IAC3B;AA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
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
|
|
5
5
|
// src/contracts-api/transactionAction.ts
|
|
6
|
+
var INDEXER_BASE = "https://indexer.infra.truf.network";
|
|
7
|
+
function normalizeTransactionId(txId) {
|
|
8
|
+
const lower = txId.toLowerCase();
|
|
9
|
+
return lower.startsWith("0x") ? lower : `0x${lower}`;
|
|
10
|
+
}
|
|
11
|
+
async function fetchTransactionStampMs(blockHeight, txId) {
|
|
12
|
+
const url = `${INDEXER_BASE}/v0/chain/transactions?from-block=${blockHeight}&to-block=${blockHeight}&order=desc`;
|
|
13
|
+
try {
|
|
14
|
+
const response = await fetch(url);
|
|
15
|
+
if (!response.ok) {
|
|
16
|
+
console.warn(`Indexer returned ${response.status} while fetching block ${blockHeight} for tx ${txId}`);
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
19
|
+
const data = await response.json();
|
|
20
|
+
if (!data.ok || !Array.isArray(data.data)) {
|
|
21
|
+
console.warn(`Indexer payload malformed for block ${blockHeight} (tx ${txId})`);
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
const normalizedTargetHash = normalizeTransactionId(txId);
|
|
25
|
+
const tx = data.data.find((entry) => normalizeTransactionId(entry.hash) === normalizedTargetHash);
|
|
26
|
+
return tx?.stamp_ms ?? 0;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.warn(`Failed to fetch stamp_ms for tx ${txId} at block ${blockHeight}`, error);
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
6
32
|
var TransactionAction = class _TransactionAction {
|
|
7
33
|
constructor(kwilClient, kwilSigner) {
|
|
8
34
|
__publicField(this, "kwilClient");
|
|
@@ -94,9 +120,11 @@ var TransactionAction = class _TransactionAction {
|
|
|
94
120
|
if (!Number.isFinite(blockHeight) || blockHeight < 0) {
|
|
95
121
|
throw new Error(`Invalid block height: ${row.block_height} (tx: ${row.tx_id})`);
|
|
96
122
|
}
|
|
123
|
+
const stampMs = await fetchTransactionStampMs(blockHeight, row.tx_id);
|
|
97
124
|
return {
|
|
98
125
|
txId: row.tx_id,
|
|
99
126
|
blockHeight,
|
|
127
|
+
stampMs,
|
|
100
128
|
method: row.method,
|
|
101
129
|
caller: row.caller,
|
|
102
130
|
feeAmount,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/contracts-api/transactionAction.ts"],
|
|
4
|
-
"sourcesContent": ["import { KwilSigner, NodeKwil, WebKwil
|
|
5
|
-
"mappings": ";;;;;
|
|
4
|
+
"sourcesContent": ["import { KwilSigner, NodeKwil, WebKwil } from \"@trufnetwork/kwil-js\";\r\nimport { TransactionEvent, FeeDistribution, GetTransactionEventInput } from \"../types/transaction\";\r\n\r\nconst INDEXER_BASE = \"https://indexer.infra.truf.network\";\r\n\r\nfunction normalizeTransactionId(txId: string): string {\r\n const lower = txId.toLowerCase();\r\n return lower.startsWith(\"0x\") ? lower : `0x${lower}`;\r\n}\r\n\r\nasync function fetchTransactionStampMs(blockHeight: number, txId: string): Promise<number> {\r\n const url = `${INDEXER_BASE}/v0/chain/transactions?from-block=${blockHeight}&to-block=${blockHeight}&order=desc`;\r\n try {\r\n const response = await fetch(url);\r\n if (!response.ok) {\r\n console.warn(`Indexer returned ${response.status} while fetching block ${blockHeight} for tx ${txId}`);\r\n return 0;\r\n }\r\n\r\n const data = await response.json() as {\r\n ok: boolean;\r\n data: Array<{\r\n block_height: number;\r\n hash: string;\r\n stamp_ms: number | null;\r\n }>;\r\n };\r\n\r\n if (!data.ok || !Array.isArray(data.data)) {\r\n console.warn(`Indexer payload malformed for block ${blockHeight} (tx ${txId})`);\r\n return 0;\r\n }\r\n\r\n const normalizedTargetHash = normalizeTransactionId(txId);\r\n const tx = data.data.find(entry => normalizeTransactionId(entry.hash) === normalizedTargetHash);\r\n return tx?.stamp_ms ?? 0;\r\n } catch (error) {\r\n console.warn(`Failed to fetch stamp_ms for tx ${txId} at block ${blockHeight}`, error);\r\n return 0;\r\n }\r\n}\r\n\r\n/**\r\n * Database row structure returned from get_transaction_event action\r\n */\r\ninterface TransactionEventRow {\r\n tx_id: string;\r\n block_height: string | number;\r\n method: string;\r\n caller: string;\r\n fee_amount: string | number;\r\n fee_recipient?: string | null;\r\n metadata?: string | null;\r\n fee_distributions: string;\r\n}\r\n\r\n/**\r\n * TransactionAction provides methods for querying transaction ledger data\r\n */\r\nexport class TransactionAction {\r\n protected kwilClient: WebKwil | NodeKwil;\r\n protected kwilSigner: KwilSigner;\r\n\r\n constructor(kwilClient: WebKwil | NodeKwil, kwilSigner: KwilSigner) {\r\n this.kwilClient = kwilClient;\r\n this.kwilSigner = kwilSigner;\r\n }\r\n\r\n /**\r\n * Fetches detailed transaction information by transaction hash\r\n *\r\n * @param input Transaction query input containing tx hash\r\n * @returns Promise resolving to transaction event with fee details\r\n * @throws Error if transaction not found or query fails\r\n *\r\n * @example\r\n * ```typescript\r\n * const txAction = client.loadTransactionAction();\r\n * const txEvent = await txAction.getTransactionEvent({\r\n * txId: \"0xabcdef123456...\"\r\n * });\r\n * console.log(`Method: ${txEvent.method}, Fee: ${txEvent.feeAmount} TRUF`);\r\n * ```\r\n */\r\n async getTransactionEvent(input: GetTransactionEventInput): Promise<TransactionEvent> {\r\n if (!input.txId || input.txId.trim() === \"\") {\r\n throw new Error(\"tx_id is required\");\r\n }\r\n\r\n const result = await this.kwilClient.call(\r\n {\r\n namespace: \"main\",\r\n name: \"get_transaction_event\",\r\n inputs: {\r\n $tx_id: input.txId,\r\n },\r\n },\r\n this.kwilSigner\r\n );\r\n\r\n if (result.status !== 200) {\r\n throw new Error(`Failed to get transaction event: HTTP ${result.status}`);\r\n }\r\n\r\n if (!result.data?.result || result.data.result.length === 0) {\r\n throw new Error(`Transaction not found: ${input.txId}`);\r\n }\r\n\r\n const row = result.data.result[0] as TransactionEventRow;\r\n\r\n // Validate required fields\r\n if (!row.method || typeof row.method !== 'string' || row.method.trim() === '') {\r\n throw new Error(`Missing or invalid method field (tx: ${row.tx_id})`);\r\n }\r\n\r\n if (!row.caller || typeof row.caller !== 'string' || row.caller.trim() === '') {\r\n throw new Error(`Missing or invalid caller field (tx: ${row.tx_id})`);\r\n }\r\n\r\n if (row.fee_amount === null || row.fee_amount === undefined) {\r\n throw new Error(`Missing fee_amount field (tx: ${row.tx_id})`);\r\n }\r\n\r\n // Validate fee_amount is numeric (can be string or number)\r\n const feeAmount = typeof row.fee_amount === 'string' ? row.fee_amount : String(row.fee_amount);\r\n const feeAmountNum = Number(feeAmount);\r\n if (isNaN(feeAmountNum) || !Number.isFinite(feeAmountNum)) {\r\n throw new Error(`Invalid fee_amount (not numeric): ${row.fee_amount} (tx: ${row.tx_id})`);\r\n }\r\n if (feeAmountNum < 0) {\r\n throw new Error(`Invalid fee_amount (negative): ${row.fee_amount} (tx: ${row.tx_id})`);\r\n }\r\n\r\n // Parse fee_distributions string: \"recipient1:amount1,recipient2:amount2\"\r\n const feeDistributions: FeeDistribution[] = [];\r\n if (row.fee_distributions && row.fee_distributions !== \"\") {\r\n const parts = row.fee_distributions.split(\",\");\r\n for (const part of parts) {\r\n const trimmedPart = part.trim();\r\n if (trimmedPart) {\r\n // Split only on first colon to handle addresses with colons\r\n const colonIndex = trimmedPart.indexOf(\":\");\r\n if (colonIndex === -1) {\r\n throw new Error(`Invalid fee distribution format (missing colon): ${trimmedPart} (tx: ${row.tx_id})`);\r\n }\r\n\r\n const recipient = trimmedPart.substring(0, colonIndex).trim();\r\n const amount = trimmedPart.substring(colonIndex + 1).trim();\r\n\r\n if (!recipient || !amount) {\r\n throw new Error(`Invalid fee distribution entry (empty recipient or amount): ${trimmedPart} (tx: ${row.tx_id})`);\r\n }\r\n\r\n // Validate amount is numeric and non-negative\r\n const amt = Number(amount);\r\n if (isNaN(amt) || !Number.isFinite(amt)) {\r\n throw new Error(`Invalid fee distribution amount (not numeric): ${amount} (tx: ${row.tx_id})`);\r\n }\r\n if (amt < 0) {\r\n throw new Error(`Invalid fee distribution amount (negative): ${amount} (tx: ${row.tx_id})`);\r\n }\r\n\r\n feeDistributions.push({ recipient, amount });\r\n }\r\n }\r\n }\r\n\r\n // Validate block height\r\n const blockHeight = typeof row.block_height === 'number'\r\n ? row.block_height\r\n : parseInt(row.block_height, 10);\r\n if (!Number.isFinite(blockHeight) || blockHeight < 0) {\r\n throw new Error(`Invalid block height: ${row.block_height} (tx: ${row.tx_id})`);\r\n }\r\n\r\n const stampMs = await fetchTransactionStampMs(blockHeight, row.tx_id);\r\n\r\n return {\r\n txId: row.tx_id,\r\n blockHeight,\r\n stampMs,\r\n method: row.method,\r\n caller: row.caller,\r\n feeAmount,\r\n feeRecipient: row.fee_recipient || undefined,\r\n metadata: row.metadata || undefined,\r\n feeDistributions,\r\n };\r\n }\r\n\r\n /**\r\n * Creates a TransactionAction instance from an existing client and signer\r\n *\r\n * @param kwilClient The Kwil client (Web or Node)\r\n * @param kwilSigner The Kwil signer for authentication\r\n * @returns A new TransactionAction instance\r\n */\r\n static fromClient(kwilClient: WebKwil | NodeKwil, kwilSigner: KwilSigner): TransactionAction {\r\n return new TransactionAction(kwilClient, kwilSigner);\r\n }\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;;;;AAGA,IAAM,eAAe;AAErB,SAAS,uBAAuB,MAAsB;AACpD,QAAM,QAAQ,KAAK,YAAY;AAC/B,SAAO,MAAM,WAAW,IAAI,IAAI,QAAQ,KAAK,KAAK;AACpD;AAEA,eAAe,wBAAwB,aAAqB,MAA+B;AACzF,QAAM,MAAM,GAAG,YAAY,qCAAqC,WAAW,aAAa,WAAW;AACnG,MAAI;AACF,UAAM,WAAW,MAAM,MAAM,GAAG;AAChC,QAAI,CAAC,SAAS,IAAI;AAChB,cAAQ,KAAK,oBAAoB,SAAS,MAAM,yBAAyB,WAAW,WAAW,IAAI,EAAE;AACrG,aAAO;AAAA,IACT;AAEA,UAAM,OAAO,MAAM,SAAS,KA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