@trufnetwork/sdk-js 0.4.10 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -0
- package/dist/cjs/client/client.cjs +11 -0
- package/dist/cjs/client/client.cjs.map +2 -2
- package/dist/cjs/contracts-api/action.cjs +8 -2
- package/dist/cjs/contracts-api/action.cjs.map +2 -2
- package/dist/cjs/contracts-api/attestationAction.cjs +322 -0
- package/dist/cjs/contracts-api/attestationAction.cjs.map +7 -0
- package/dist/cjs/index.common.cjs +2 -0
- package/dist/cjs/index.common.cjs.map +2 -2
- package/dist/cjs/internal.cjs +2 -0
- package/dist/cjs/internal.cjs.map +2 -2
- package/dist/cjs/types/attestation.cjs +297 -0
- package/dist/cjs/types/attestation.cjs.map +7 -0
- package/dist/cjs/util/AttestationEncoding.cjs +157 -0
- package/dist/cjs/util/AttestationEncoding.cjs.map +7 -0
- package/dist/esm/client/client.mjs +11 -0
- package/dist/esm/client/client.mjs.map +2 -2
- package/dist/esm/contracts-api/action.mjs +8 -2
- package/dist/esm/contracts-api/action.mjs.map +2 -2
- package/dist/esm/contracts-api/attestationAction.mjs +303 -0
- package/dist/esm/contracts-api/attestationAction.mjs.map +7 -0
- package/dist/esm/index.common.mjs +2 -0
- package/dist/esm/index.common.mjs.map +2 -2
- package/dist/esm/internal.mjs +2 -0
- package/dist/esm/internal.mjs.map +2 -2
- package/dist/esm/types/attestation.mjs +275 -0
- package/dist/esm/types/attestation.mjs.map +7 -0
- package/dist/esm/util/AttestationEncoding.mjs +135 -0
- package/dist/esm/util/AttestationEncoding.mjs.map +7 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/client/client.d.ts +6 -0
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/contracts-api/action.d.ts +8 -2
- package/dist/types/contracts-api/action.d.ts.map +1 -1
- package/dist/types/contracts-api/attestationAction.d.ts +131 -0
- package/dist/types/contracts-api/attestationAction.d.ts.map +1 -0
- package/dist/types/index.common.d.ts +2 -0
- package/dist/types/index.common.d.ts.map +1 -1
- package/dist/types/internal.d.ts +2 -0
- package/dist/types/internal.d.ts.map +1 -1
- package/dist/types/types/attestation.d.ts +155 -0
- package/dist/types/types/attestation.d.ts.map +1 -0
- package/dist/types/util/AttestationEncoding.d.ts +28 -0
- package/dist/types/util/AttestationEncoding.d.ts.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attestation action implementation
|
|
3
|
+
*
|
|
4
|
+
* This module provides methods for requesting, retrieving, and listing attestations.
|
|
5
|
+
* Attestations are cryptographically signed proofs of query results that can be
|
|
6
|
+
* consumed by smart contracts and external applications.
|
|
7
|
+
*/
|
|
8
|
+
import { Action } from './action';
|
|
9
|
+
import { RequestAttestationInput, RequestAttestationResult, GetSignedAttestationInput, SignedAttestationResult, ListAttestationsInput, AttestationMetadata } from '../types/attestation';
|
|
10
|
+
/**
|
|
11
|
+
* AttestationAction provides methods for working with data attestations
|
|
12
|
+
*
|
|
13
|
+
* Attestations enable validators to cryptographically sign query results,
|
|
14
|
+
* providing verifiable proofs that can be used in smart contracts.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const client = new NodeTNClient({ ... });
|
|
19
|
+
* const attestationAction = client.loadAttestationAction();
|
|
20
|
+
*
|
|
21
|
+
* // Request an attestation
|
|
22
|
+
* const result = await attestationAction.requestAttestation({
|
|
23
|
+
* dataProvider: "0x4710a8d8f0d845da110086812a32de6d90d7ff5c",
|
|
24
|
+
* streamId: "stai0000000000000000000000000000",
|
|
25
|
+
* actionName: "get_record",
|
|
26
|
+
* args: [dataProvider, streamId, fromTime, toTime, null, false],
|
|
27
|
+
* encryptSig: false,
|
|
28
|
+
* maxFee: 1000000,
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Wait for signing (1-2 blocks)
|
|
32
|
+
* await new Promise(resolve => setTimeout(resolve, 10000));
|
|
33
|
+
*
|
|
34
|
+
* // Retrieve signed attestation
|
|
35
|
+
* const signed = await attestationAction.getSignedAttestation({
|
|
36
|
+
* requestTxId: result.requestTxId,
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class AttestationAction extends Action {
|
|
41
|
+
/**
|
|
42
|
+
* Request a signed attestation of query results
|
|
43
|
+
*
|
|
44
|
+
* This submits a transaction requesting that validators execute a query
|
|
45
|
+
* and sign the results. The leader validator will sign the attestation
|
|
46
|
+
* asynchronously (typically 1-2 blocks later).
|
|
47
|
+
*
|
|
48
|
+
* @param input - Attestation request parameters
|
|
49
|
+
* @returns Promise resolving to request result with transaction ID
|
|
50
|
+
* @throws Error if validation fails or transaction fails
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const result = await attestationAction.requestAttestation({
|
|
55
|
+
* dataProvider: "0x4710a8d8f0d845da110086812a32de6d90d7ff5c",
|
|
56
|
+
* streamId: "stai0000000000000000000000000000",
|
|
57
|
+
* actionName: "get_record",
|
|
58
|
+
* args: [
|
|
59
|
+
* "0x4710a8d8f0d845da110086812a32de6d90d7ff5c",
|
|
60
|
+
* "stai0000000000000000000000000000",
|
|
61
|
+
* Math.floor(Date.now() / 1000) - 86400, // 1 day ago
|
|
62
|
+
* Math.floor(Date.now() / 1000),
|
|
63
|
+
* null,
|
|
64
|
+
* false,
|
|
65
|
+
* ],
|
|
66
|
+
* encryptSig: false,
|
|
67
|
+
* maxFee: 1000000,
|
|
68
|
+
* });
|
|
69
|
+
* console.log(`Request TX ID: ${result.requestTxId}`);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
requestAttestation(input: RequestAttestationInput): Promise<RequestAttestationResult>;
|
|
73
|
+
/**
|
|
74
|
+
* Retrieve a complete signed attestation payload
|
|
75
|
+
*
|
|
76
|
+
* This fetches the signed attestation payload for a given request transaction ID.
|
|
77
|
+
* The attestation must have been signed by the leader validator first.
|
|
78
|
+
*
|
|
79
|
+
* If the attestation is not yet signed, this will throw an error. Clients should
|
|
80
|
+
* poll with exponential backoff or wait for 1-2 blocks after requesting.
|
|
81
|
+
*
|
|
82
|
+
* @param input - Request transaction ID
|
|
83
|
+
* @returns Promise resolving to signed attestation payload
|
|
84
|
+
* @throws Error if attestation not found or not yet signed
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* // Poll for signature
|
|
89
|
+
* for (let i = 0; i < 15; i++) {
|
|
90
|
+
* try {
|
|
91
|
+
* const signed = await attestationAction.getSignedAttestation({
|
|
92
|
+
* requestTxId: "0x123...",
|
|
93
|
+
* });
|
|
94
|
+
* console.log(`Payload: ${Buffer.from(signed.payload).toString('hex')}`);
|
|
95
|
+
* break;
|
|
96
|
+
* } catch (e) {
|
|
97
|
+
* await new Promise(resolve => setTimeout(resolve, 2000));
|
|
98
|
+
* }
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
getSignedAttestation(input: GetSignedAttestationInput): Promise<SignedAttestationResult>;
|
|
103
|
+
/**
|
|
104
|
+
* List attestation metadata with optional filtering
|
|
105
|
+
*
|
|
106
|
+
* This returns metadata for attestations, optionally filtered by requester address.
|
|
107
|
+
* Supports pagination and sorting.
|
|
108
|
+
*
|
|
109
|
+
* @param input - Filter and pagination parameters
|
|
110
|
+
* @returns Promise resolving to array of attestation metadata
|
|
111
|
+
* @throws Error if parameters are invalid
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* // List my recent attestations
|
|
116
|
+
* const myAddress = new Uint8Array(Buffer.from(wallet.address.slice(2), 'hex'));
|
|
117
|
+
* const attestations = await attestationAction.listAttestations({
|
|
118
|
+
* requester: myAddress,
|
|
119
|
+
* limit: 10,
|
|
120
|
+
* offset: 0,
|
|
121
|
+
* orderBy: "created_height desc",
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* attestations.forEach(att => {
|
|
125
|
+
* console.log(`TX: ${att.requestTxId}, Height: ${att.createdHeight}`);
|
|
126
|
+
* });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
listAttestations(input: ListAttestationsInput): Promise<AttestationMetadata[]>;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=attestationAction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attestationAction.d.ts","sourceRoot":"","sources":["../../../src/contracts-api/attestationAction.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,EACzB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EAGpB,MAAM,sBAAsB,CAAC;AAG9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,iBAAkB,SAAQ,MAAM;IAC3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACG,kBAAkB,CACtB,KAAK,EAAE,uBAAuB,GAC7B,OAAO,CAAC,wBAAwB,CAAC;IAiCpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,oBAAoB,CACxB,KAAK,EAAE,yBAAyB,GAC/B,OAAO,CAAC,uBAAuB,CAAC;IA2DnC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACG,gBAAgB,CACpB,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,mBAAmB,EAAE,CAAC;CAqClC"}
|
|
@@ -15,4 +15,6 @@ export { PrimitiveAction } from "./contracts-api/primitiveAction";
|
|
|
15
15
|
export { ComposedAction } from "./contracts-api/composedAction";
|
|
16
16
|
export { RoleManagement } from "./contracts-api/roleManagement";
|
|
17
17
|
export type { GrantRoleInput, RevokeRoleInput, AreMembersOfInput, WalletMembership } from "./types/role";
|
|
18
|
+
export { AttestationAction } from "./contracts-api/attestationAction";
|
|
19
|
+
export type { RequestAttestationInput, RequestAttestationResult, GetSignedAttestationInput, SignedAttestationResult, ListAttestationsInput, AttestationMetadata } from "./types/attestation";
|
|
18
20
|
//# sourceMappingURL=index.common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.common.d.ts","sourceRoot":"","sources":["../../src/index.common.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,YAAY,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGjE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,YAAY,EAAE,YAAY,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC5G,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClF,YAAY,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACzE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,4BAA4B,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAGlK,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAG5D,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGhE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,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CAAC;AACtE,YAAY,EACV,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,EACzB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,qBAAqB,CAAC"}
|
package/dist/types/internal.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { Action } from "./contracts-api/action";
|
|
|
8
8
|
export { PrimitiveAction } from "./contracts-api/primitiveAction";
|
|
9
9
|
export { ComposedAction } from "./contracts-api/composedAction";
|
|
10
10
|
export { RoleManagement } from "./contracts-api/roleManagement";
|
|
11
|
+
export { AttestationAction } from "./contracts-api/attestationAction";
|
|
11
12
|
export { deployStream } from "./contracts-api/deployStream";
|
|
12
13
|
export { deleteStream } from "./contracts-api/deleteStream";
|
|
13
14
|
export { StreamId } from "./util/StreamId";
|
|
@@ -19,5 +20,6 @@ export type { StreamRecord, ListMetadataByHeightParams, MetadataQueryResult, Get
|
|
|
19
20
|
export type { InsertRecordInput } from "./contracts-api/primitiveAction";
|
|
20
21
|
export type { TaxonomySet, TaxonomyItem, ListTaxonomiesByHeightParams, GetTaxonomiesForStreamsParams, TaxonomyQueryResult } from "./contracts-api/composedAction";
|
|
21
22
|
export type { GrantRoleInput, RevokeRoleInput, AreMembersOfInput, WalletMembership } from "./types/role";
|
|
23
|
+
export type { RequestAttestationInput, RequestAttestationResult, GetSignedAttestationInput, SignedAttestationResult, ListAttestationsInput, AttestationMetadata } from "./types/attestation";
|
|
22
24
|
export type { VisibilityEnum } from "./util/visibility";
|
|
23
25
|
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAG/G,OAAO,EAAE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,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAG5D,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG/C,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAG5D,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGpD,YAAY,EACV,YAAY,EACZ,0BAA0B,EAC1B,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAGhC,YAAY,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAGzE,YAAY,EACV,WAAW,EACX,YAAY,EACZ,4BAA4B,EAC5B,6BAA6B,EAC7B,mBAAmB,EACpB,MAAM,gCAAgC,CAAC;AAGxC,YAAY,EACV,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,EACzB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,qBAAqB,CAAC;AAG7B,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for attestation operations
|
|
3
|
+
*
|
|
4
|
+
* Attestations enable validators to cryptographically sign query results,
|
|
5
|
+
* providing verifiable proofs that can be consumed by smart contracts and
|
|
6
|
+
* external applications.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Input parameters for requesting an attestation
|
|
10
|
+
*/
|
|
11
|
+
export interface RequestAttestationInput {
|
|
12
|
+
/**
|
|
13
|
+
* Data provider address (0x-prefixed, 42 characters)
|
|
14
|
+
* Example: "0x4710a8d8f0d845da110086812a32de6d90d7ff5c"
|
|
15
|
+
*/
|
|
16
|
+
dataProvider: string;
|
|
17
|
+
/**
|
|
18
|
+
* Stream ID (32 characters)
|
|
19
|
+
* Example: "stai0000000000000000000000000000"
|
|
20
|
+
*/
|
|
21
|
+
streamId: string;
|
|
22
|
+
/**
|
|
23
|
+
* Action name to attest (must be in allowlist)
|
|
24
|
+
* Example: "get_record", "get_index"
|
|
25
|
+
*/
|
|
26
|
+
actionName: string;
|
|
27
|
+
/**
|
|
28
|
+
* Action arguments (will be encoded)
|
|
29
|
+
* Must match the signature of the action
|
|
30
|
+
*/
|
|
31
|
+
args: any[];
|
|
32
|
+
/**
|
|
33
|
+
* Whether to encrypt the signature (must be false in MVP)
|
|
34
|
+
* Future: ECIES encryption to requester's public key
|
|
35
|
+
*/
|
|
36
|
+
encryptSig: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Maximum fee willing to pay (in smallest token unit)
|
|
39
|
+
* Transaction will abort if actual fee exceeds this
|
|
40
|
+
*/
|
|
41
|
+
maxFee: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Result of requesting an attestation
|
|
45
|
+
*/
|
|
46
|
+
export interface RequestAttestationResult {
|
|
47
|
+
/**
|
|
48
|
+
* Transaction ID for this attestation request
|
|
49
|
+
* Use this to retrieve the signed attestation later
|
|
50
|
+
*/
|
|
51
|
+
requestTxId: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Input parameters for retrieving a signed attestation
|
|
55
|
+
*/
|
|
56
|
+
export interface GetSignedAttestationInput {
|
|
57
|
+
/**
|
|
58
|
+
* Transaction ID from request_attestation
|
|
59
|
+
*/
|
|
60
|
+
requestTxId: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Result of retrieving a signed attestation
|
|
64
|
+
*/
|
|
65
|
+
export interface SignedAttestationResult {
|
|
66
|
+
/**
|
|
67
|
+
* Complete attestation payload: canonical (8 fields) + signature
|
|
68
|
+
*
|
|
69
|
+
* Format: version | algo | height | provider | stream | action | args | result | signature
|
|
70
|
+
*
|
|
71
|
+
* This payload can be passed to EVM contracts for verification
|
|
72
|
+
*/
|
|
73
|
+
payload: Uint8Array;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Input parameters for listing attestations
|
|
77
|
+
*/
|
|
78
|
+
export interface ListAttestationsInput {
|
|
79
|
+
/**
|
|
80
|
+
* Optional: Filter by requester address (20 bytes)
|
|
81
|
+
* If provided, only returns attestations requested by this address
|
|
82
|
+
*/
|
|
83
|
+
requester?: Uint8Array;
|
|
84
|
+
/**
|
|
85
|
+
* Optional: Maximum number of results (1-5000, default 5000)
|
|
86
|
+
*/
|
|
87
|
+
limit?: number;
|
|
88
|
+
/**
|
|
89
|
+
* Optional: Pagination offset (default 0)
|
|
90
|
+
*/
|
|
91
|
+
offset?: number;
|
|
92
|
+
/**
|
|
93
|
+
* Optional: Sort order
|
|
94
|
+
*
|
|
95
|
+
* Allowed values:
|
|
96
|
+
* - "created_height asc"
|
|
97
|
+
* - "created_height desc"
|
|
98
|
+
* - "signed_height asc"
|
|
99
|
+
* - "signed_height desc"
|
|
100
|
+
*
|
|
101
|
+
* Case-insensitive
|
|
102
|
+
*/
|
|
103
|
+
orderBy?: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Metadata for a single attestation
|
|
107
|
+
*/
|
|
108
|
+
export interface AttestationMetadata {
|
|
109
|
+
/**
|
|
110
|
+
* Transaction ID for this attestation request
|
|
111
|
+
*/
|
|
112
|
+
requestTxId: string;
|
|
113
|
+
/**
|
|
114
|
+
* Attestation hash (identifies this attestation)
|
|
115
|
+
*/
|
|
116
|
+
attestationHash: Uint8Array;
|
|
117
|
+
/**
|
|
118
|
+
* Address of the requester (20 bytes)
|
|
119
|
+
*/
|
|
120
|
+
requester: Uint8Array;
|
|
121
|
+
/**
|
|
122
|
+
* Block height when attestation was created
|
|
123
|
+
*/
|
|
124
|
+
createdHeight: number;
|
|
125
|
+
/**
|
|
126
|
+
* Block height when attestation was signed (null if not yet signed)
|
|
127
|
+
*/
|
|
128
|
+
signedHeight: number | null;
|
|
129
|
+
/**
|
|
130
|
+
* Whether signature is encrypted
|
|
131
|
+
*/
|
|
132
|
+
encryptSig: boolean;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Validates attestation request input
|
|
136
|
+
*
|
|
137
|
+
* @param input - The attestation request to validate
|
|
138
|
+
* @throws Error if validation fails
|
|
139
|
+
*/
|
|
140
|
+
export declare function validateAttestationRequest(input: RequestAttestationInput): void;
|
|
141
|
+
/**
|
|
142
|
+
* Validates orderBy parameter (case-insensitive)
|
|
143
|
+
*
|
|
144
|
+
* @param orderBy - The orderBy value to validate
|
|
145
|
+
* @returns true if valid, false otherwise
|
|
146
|
+
*/
|
|
147
|
+
export declare function isValidOrderBy(orderBy: string): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Validates list attestations input
|
|
150
|
+
*
|
|
151
|
+
* @param input - The list attestations input to validate
|
|
152
|
+
* @throws Error if validation fails
|
|
153
|
+
*/
|
|
154
|
+
export declare function validateListAttestationsInput(input: ListAttestationsInput): void;
|
|
155
|
+
//# sourceMappingURL=attestation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attestation.d.ts","sourceRoot":"","sources":["../../../src/types/attestation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;OAGG;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AAgB,6BAA6B,CAAC,KAAK,EAAE,qBAAqB,GAAG,IAAI,CA8BhF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Argument encoding for attestation requests
|
|
3
|
+
*
|
|
4
|
+
* This module encodes action arguments into the canonical format expected by
|
|
5
|
+
* the node's request_attestation action. It uses kwil-js's native encoding
|
|
6
|
+
* to ensure perfect compatibility with kwil-db's EncodedValue.MarshalBinary() format.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Encodes action arguments into canonical bytes using kwil-js utilities.
|
|
10
|
+
*
|
|
11
|
+
* Format: [arg_count:uint32(LE)][length:uint32(LE)][encoded_arg1][length:uint32(LE)][encoded_arg2]...
|
|
12
|
+
*
|
|
13
|
+
* Each encoded_arg uses kwil-db's EncodedValue.MarshalBinary() format.
|
|
14
|
+
*
|
|
15
|
+
* @param args - Array of arguments to encode
|
|
16
|
+
* @returns Encoded bytes
|
|
17
|
+
* @throws Error if any argument cannot be encoded
|
|
18
|
+
*/
|
|
19
|
+
export declare function encodeActionArgs(args: any[]): Uint8Array;
|
|
20
|
+
/**
|
|
21
|
+
* Reads a uint32 value in little-endian format (for testing)
|
|
22
|
+
*
|
|
23
|
+
* @param buffer - Source buffer
|
|
24
|
+
* @param offset - Offset in buffer
|
|
25
|
+
* @returns The uint32 value
|
|
26
|
+
*/
|
|
27
|
+
export declare function readUint32LE(buffer: Uint8Array, offset: number): number;
|
|
28
|
+
//# sourceMappingURL=AttestationEncoding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttestationEncoding.d.ts","sourceRoot":"","sources":["../../../src/util/AttestationEncoding.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,UAAU,CA2CxD;AAiBD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAOvE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trufnetwork/sdk-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "TRUF.NETWORK SDK for JavaScript/TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"test:integration": "vitest tests/integration/ --run"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@trufnetwork/kwil-js": "0.9.
|
|
54
|
+
"@trufnetwork/kwil-js": "^0.9.9",
|
|
55
55
|
"crypto-hash": "^3.1.0",
|
|
56
56
|
"ethers": "^6.13.5",
|
|
57
57
|
"lodash": "^4.17.21",
|