@thru/sdk 0.2.22
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.abi.md +112 -0
- package/README.md +342 -0
- package/dist/abi/index.cjs +946 -0
- package/dist/abi/index.cjs.map +1 -0
- package/dist/abi/index.d.cts +331 -0
- package/dist/abi/index.d.ts +331 -0
- package/dist/abi/index.js +892 -0
- package/dist/abi/index.js.map +1 -0
- package/dist/abi/wasm/bundler/abi_reflect_wasm.d.ts +65 -0
- package/dist/abi/wasm/bundler/abi_reflect_wasm.js +5 -0
- package/dist/abi/wasm/bundler/abi_reflect_wasm_bg.js +412 -0
- package/dist/abi/wasm/bundler/abi_reflect_wasm_bg.wasm +0 -0
- package/dist/abi/wasm/bundler/abi_reflect_wasm_bg.wasm.d.ts +24 -0
- package/dist/abi/wasm/bundler/package.json +17 -0
- package/dist/abi/wasm/node/abi_reflect_wasm.d.ts +65 -0
- package/dist/abi/wasm/node/abi_reflect_wasm.js +425 -0
- package/dist/abi/wasm/node/abi_reflect_wasm_bg.wasm +0 -0
- package/dist/abi/wasm/node/abi_reflect_wasm_bg.wasm.d.ts +24 -0
- package/dist/abi/wasm/node/package.json +11 -0
- package/dist/abi/wasm/web/abi_reflect_wasm.d.ts +114 -0
- package/dist/abi/wasm/web/abi_reflect_wasm.js +499 -0
- package/dist/abi/wasm/web/abi_reflect_wasm_bg.wasm +0 -0
- package/dist/abi/wasm/web/abi_reflect_wasm_bg.wasm.d.ts +24 -0
- package/dist/abi/wasm/web/package.json +15 -0
- package/dist/chunk-CVBQ4UPL.js +3614 -0
- package/dist/chunk-CVBQ4UPL.js.map +1 -0
- package/dist/chunk-NSBPE2FW.js +15 -0
- package/dist/chunk-NSBPE2FW.js.map +1 -0
- package/dist/chunk-RL3Q6FDE.js +105 -0
- package/dist/chunk-RL3Q6FDE.js.map +1 -0
- package/dist/chunk-UDIXYJXC.js +260 -0
- package/dist/chunk-UDIXYJXC.js.map +1 -0
- package/dist/chunk-YQDWOMNO.js +271 -0
- package/dist/chunk-YQDWOMNO.js.map +1 -0
- package/dist/client-Cfi7zRLm.d.cts +1247 -0
- package/dist/client-worIo0a3.d.ts +1247 -0
- package/dist/client.cjs +3791 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +7 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +7 -0
- package/dist/client.js.map +1 -0
- package/dist/crypto/index.cjs +170 -0
- package/dist/crypto/index.cjs.map +1 -0
- package/dist/crypto/index.d.cts +60 -0
- package/dist/crypto/index.d.ts +60 -0
- package/dist/crypto/index.js +5 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/helpers/index.cjs +270 -0
- package/dist/helpers/index.cjs.map +1 -0
- package/dist/helpers/index.d.cts +15 -0
- package/dist/helpers/index.d.ts +15 -0
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/proto/index.cjs +433 -0
- package/dist/proto/index.cjs.map +1 -0
- package/dist/proto/index.d.cts +435 -0
- package/dist/proto/index.d.ts +435 -0
- package/dist/proto/index.js +4 -0
- package/dist/proto/index.js.map +1 -0
- package/dist/sdk.cjs +4137 -0
- package/dist/sdk.cjs.map +1 -0
- package/dist/sdk.d.cts +36 -0
- package/dist/sdk.d.ts +36 -0
- package/dist/sdk.js +7 -0
- package/dist/sdk.js.map +1 -0
- package/dist/streaming_service_pb-DvCdJiCr.d.cts +4877 -0
- package/dist/streaming_service_pb-DvCdJiCr.d.ts +4877 -0
- package/dist/webcrypto-LTajLAad.d.cts +3 -0
- package/dist/webcrypto-LTajLAad.d.ts +3 -0
- package/package.json +88 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
interface ByteRange {
|
|
2
|
+
offset: number;
|
|
3
|
+
size: number;
|
|
4
|
+
}
|
|
5
|
+
type FormattedValue = null | string | number | boolean | bigint | FormattedValue[] | {
|
|
6
|
+
[key: string]: FormattedValue;
|
|
7
|
+
} | {
|
|
8
|
+
variant: string;
|
|
9
|
+
value: FormattedValue | null;
|
|
10
|
+
};
|
|
11
|
+
type FormattedValueWithByteRange = {
|
|
12
|
+
value: FormattedValue;
|
|
13
|
+
_byteRange: ByteRange;
|
|
14
|
+
} | {
|
|
15
|
+
hex: string;
|
|
16
|
+
_byteRange: ByteRange;
|
|
17
|
+
} | {
|
|
18
|
+
variant: string;
|
|
19
|
+
value: FormattedValue | null;
|
|
20
|
+
_byteRange: ByteRange;
|
|
21
|
+
};
|
|
22
|
+
interface FormattedReflection {
|
|
23
|
+
typeName: string;
|
|
24
|
+
kind: string | null | undefined;
|
|
25
|
+
value: FormattedValue;
|
|
26
|
+
byteRange?: ByteRange;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type JsonValue = unknown;
|
|
30
|
+
/**
|
|
31
|
+
* Configure the URL from which to load the WASM file.
|
|
32
|
+
* Must be called before any reflection functions are used.
|
|
33
|
+
*
|
|
34
|
+
* This is useful for environments like Next.js where bundler-based WASM loading
|
|
35
|
+
* doesn't work. Instead, copy the WASM file to your public directory and call:
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { configureWasm } from "@thru/sdk/abi";
|
|
40
|
+
* configureWasm("/wasm/abi_reflect_wasm_bg.wasm");
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @param url - URL or path to the WASM file (e.g., "/wasm/abi_reflect_wasm_bg.wasm")
|
|
44
|
+
*/
|
|
45
|
+
declare function configureWasm(url: string): void;
|
|
46
|
+
type BinaryLike = Uint8Array | ArrayBuffer | ArrayBufferView | number[];
|
|
47
|
+
declare function reflect(abiYaml: string, typeName: string, payload: {
|
|
48
|
+
type: 'binary';
|
|
49
|
+
value: BinaryLike;
|
|
50
|
+
} | {
|
|
51
|
+
type: 'hex';
|
|
52
|
+
value: string;
|
|
53
|
+
}): Promise<JsonValue>;
|
|
54
|
+
declare function buildLayoutIr(abiYaml: string): Promise<JsonValue>;
|
|
55
|
+
type ReflectRootPayload = {
|
|
56
|
+
type: 'binary';
|
|
57
|
+
value: BinaryLike;
|
|
58
|
+
} | {
|
|
59
|
+
type: 'hex';
|
|
60
|
+
value: string;
|
|
61
|
+
};
|
|
62
|
+
declare function reflectInstruction(abiYaml: string, payload: ReflectRootPayload): Promise<JsonValue>;
|
|
63
|
+
declare function reflectAccount(abiYaml: string, payload: ReflectRootPayload): Promise<JsonValue>;
|
|
64
|
+
declare function reflectEvent(abiYaml: string, payload: ReflectRootPayload): Promise<JsonValue>;
|
|
65
|
+
declare function ensureWasmLoaded(): Promise<void>;
|
|
66
|
+
interface FormatOptions {
|
|
67
|
+
includeByteOffsets?: boolean;
|
|
68
|
+
}
|
|
69
|
+
declare function formatReflection(raw: JsonValue, options?: FormatOptions): FormattedReflection;
|
|
70
|
+
type Manifest = Record<string, string>;
|
|
71
|
+
/**
|
|
72
|
+
* Reflect a binary buffer using a pre-resolved manifest.
|
|
73
|
+
*
|
|
74
|
+
* @param manifest - Map of package names to ABI YAML content
|
|
75
|
+
* @param rootPackage - The package containing the target type
|
|
76
|
+
* @param typeName - The type name to parse
|
|
77
|
+
* @param payload - Binary data to reflect
|
|
78
|
+
*/
|
|
79
|
+
declare function reflectWithManifest(manifest: Manifest, rootPackage: string, typeName: string, payload: ReflectRootPayload): Promise<JsonValue>;
|
|
80
|
+
/**
|
|
81
|
+
* Reflect an instruction using a pre-resolved manifest.
|
|
82
|
+
*/
|
|
83
|
+
declare function reflectInstructionWithManifest(manifest: Manifest, rootPackage: string, payload: ReflectRootPayload): Promise<JsonValue>;
|
|
84
|
+
/**
|
|
85
|
+
* Reflect an account using a pre-resolved manifest.
|
|
86
|
+
*/
|
|
87
|
+
declare function reflectAccountWithManifest(manifest: Manifest, rootPackage: string, payload: ReflectRootPayload): Promise<JsonValue>;
|
|
88
|
+
/**
|
|
89
|
+
* Reflect an event using a pre-resolved manifest.
|
|
90
|
+
*/
|
|
91
|
+
declare function reflectEventWithManifest(manifest: Manifest, rootPackage: string, payload: ReflectRootPayload): Promise<JsonValue>;
|
|
92
|
+
/**
|
|
93
|
+
* Build layout IR using a pre-resolved manifest.
|
|
94
|
+
*/
|
|
95
|
+
declare function buildLayoutIrWithManifest(manifest: Manifest, rootPackage: string): Promise<JsonValue>;
|
|
96
|
+
/**
|
|
97
|
+
* Get the list of package names in a manifest.
|
|
98
|
+
*/
|
|
99
|
+
declare function getManifestPackages(manifest: Manifest): Promise<string[]>;
|
|
100
|
+
interface ManifestPackageInfo {
|
|
101
|
+
name: string;
|
|
102
|
+
package: string;
|
|
103
|
+
version: number;
|
|
104
|
+
type_count: number;
|
|
105
|
+
has_root_types: boolean;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Validate a manifest and return information about its contents.
|
|
109
|
+
*/
|
|
110
|
+
declare function validateManifest(manifest: Manifest): Promise<ManifestPackageInfo[]>;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Import Source Types
|
|
114
|
+
*
|
|
115
|
+
* These types mirror the Rust ImportSource enum and related types.
|
|
116
|
+
*/
|
|
117
|
+
type OnchainTarget = "program" | "abi-meta" | "abi";
|
|
118
|
+
type RevisionSpec = {
|
|
119
|
+
type: "exact";
|
|
120
|
+
value: number;
|
|
121
|
+
} | {
|
|
122
|
+
type: "minimum";
|
|
123
|
+
value: number;
|
|
124
|
+
} | {
|
|
125
|
+
type: "latest";
|
|
126
|
+
} | {
|
|
127
|
+
type: "atSlot";
|
|
128
|
+
slot: bigint;
|
|
129
|
+
};
|
|
130
|
+
type ImportSource = {
|
|
131
|
+
type: "path";
|
|
132
|
+
path: string;
|
|
133
|
+
} | {
|
|
134
|
+
type: "git";
|
|
135
|
+
url: string;
|
|
136
|
+
ref: string;
|
|
137
|
+
path: string;
|
|
138
|
+
} | {
|
|
139
|
+
type: "http";
|
|
140
|
+
url: string;
|
|
141
|
+
} | {
|
|
142
|
+
type: "onchain";
|
|
143
|
+
address: string;
|
|
144
|
+
target: OnchainTarget;
|
|
145
|
+
network: string;
|
|
146
|
+
revision: RevisionSpec;
|
|
147
|
+
};
|
|
148
|
+
interface PackageId {
|
|
149
|
+
packageName: string;
|
|
150
|
+
version: string;
|
|
151
|
+
}
|
|
152
|
+
interface ResolvedPackage {
|
|
153
|
+
id: PackageId;
|
|
154
|
+
source: ImportSource;
|
|
155
|
+
abiYaml: string;
|
|
156
|
+
dependencies: PackageId[];
|
|
157
|
+
isRemote: boolean;
|
|
158
|
+
}
|
|
159
|
+
interface ResolutionResult {
|
|
160
|
+
root: ResolvedPackage;
|
|
161
|
+
allPackages: ResolvedPackage[];
|
|
162
|
+
manifest: Record<string, string>;
|
|
163
|
+
}
|
|
164
|
+
declare class ResolutionError extends Error {
|
|
165
|
+
code: "CYCLIC_DEPENDENCY" | "VERSION_CONFLICT" | "FETCH_ERROR" | "PARSE_ERROR" | "NOT_FOUND" | "UNSUPPORTED_IMPORT_TYPE";
|
|
166
|
+
details?: unknown | undefined;
|
|
167
|
+
constructor(code: "CYCLIC_DEPENDENCY" | "VERSION_CONFLICT" | "FETCH_ERROR" | "PARSE_ERROR" | "NOT_FOUND" | "UNSUPPORTED_IMPORT_TYPE", message: string, details?: unknown | undefined);
|
|
168
|
+
}
|
|
169
|
+
declare const ABI_ACCOUNT_HEADER_SIZE = 45;
|
|
170
|
+
declare const ABI_STATE_OPEN = 0;
|
|
171
|
+
declare const ABI_STATE_FINALIZED = 1;
|
|
172
|
+
interface AbiAccountData {
|
|
173
|
+
abiMetaAccount: Uint8Array;
|
|
174
|
+
revision: bigint;
|
|
175
|
+
state: number;
|
|
176
|
+
content: string;
|
|
177
|
+
}
|
|
178
|
+
interface RpcEndpoints {
|
|
179
|
+
[network: string]: string;
|
|
180
|
+
}
|
|
181
|
+
declare const DEFAULT_RPC_ENDPOINTS: RpcEndpoints;
|
|
182
|
+
interface AbiMetadata {
|
|
183
|
+
package: string;
|
|
184
|
+
name?: string;
|
|
185
|
+
"abi-version": number;
|
|
186
|
+
"package-version": string;
|
|
187
|
+
description: string;
|
|
188
|
+
imports?: ImportSourceYaml[];
|
|
189
|
+
}
|
|
190
|
+
type ImportSourceYaml = {
|
|
191
|
+
type: "path";
|
|
192
|
+
path: string;
|
|
193
|
+
} | {
|
|
194
|
+
type: "git";
|
|
195
|
+
url: string;
|
|
196
|
+
ref: string;
|
|
197
|
+
path: string;
|
|
198
|
+
} | {
|
|
199
|
+
type: "http";
|
|
200
|
+
url: string;
|
|
201
|
+
} | {
|
|
202
|
+
type: "onchain";
|
|
203
|
+
address: string;
|
|
204
|
+
target?: OnchainTarget;
|
|
205
|
+
network: string;
|
|
206
|
+
revision?: number | string;
|
|
207
|
+
};
|
|
208
|
+
interface AbiFile {
|
|
209
|
+
abi: AbiMetadata;
|
|
210
|
+
types: unknown[];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* On-chain ABI Fetcher
|
|
215
|
+
*
|
|
216
|
+
* Fetches ABI content from on-chain accounts.
|
|
217
|
+
*/
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Minimal interface for a Thru RPC client that can fetch raw accounts.
|
|
221
|
+
* This is compatible with @thru/sdk client but doesn't require it.
|
|
222
|
+
*/
|
|
223
|
+
interface ThruRpcClient {
|
|
224
|
+
query: {
|
|
225
|
+
getRawAccount: (request: {
|
|
226
|
+
address: {
|
|
227
|
+
value: Uint8Array;
|
|
228
|
+
};
|
|
229
|
+
versionContext: Record<string, unknown>;
|
|
230
|
+
}) => Promise<{
|
|
231
|
+
rawData?: Uint8Array;
|
|
232
|
+
}>;
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Derive the official ABI account address for a given program.
|
|
237
|
+
*
|
|
238
|
+
* This performs the same derivation as OnchainFetcher.fetch() with target="program",
|
|
239
|
+
* returning the raw 32-byte address of the ABI account.
|
|
240
|
+
*/
|
|
241
|
+
declare function deriveOfficialAbiAddress(programAddress: string, abiManagerProgramId?: string): Promise<Uint8Array>;
|
|
242
|
+
/**
|
|
243
|
+
* Parse ABI account data from raw bytes.
|
|
244
|
+
*
|
|
245
|
+
* Account header layout (45 bytes):
|
|
246
|
+
* - abi_meta_account: [u8; 32]
|
|
247
|
+
* - revision: u64 (little-endian)
|
|
248
|
+
* - state: u8 (0x00=OPEN, 0x01=FINALIZED)
|
|
249
|
+
* - content_sz: u32 (little-endian)
|
|
250
|
+
* - content: [u8; content_sz]
|
|
251
|
+
*/
|
|
252
|
+
declare function parseAbiAccountData(data: Uint8Array): AbiAccountData;
|
|
253
|
+
/**
|
|
254
|
+
* Check if a revision matches the specification.
|
|
255
|
+
*
|
|
256
|
+
* Note: `atSlot` skips this check entirely in `OnchainFetcher.fetch` — the
|
|
257
|
+
* constraint there is "whatever revision was active at this slot", and the
|
|
258
|
+
* RPC's version_context handles that selection server-side.
|
|
259
|
+
*/
|
|
260
|
+
declare function revisionMatches(revision: bigint, spec: RevisionSpec): boolean;
|
|
261
|
+
interface OnchainFetcherConfig {
|
|
262
|
+
rpcEndpoints?: RpcEndpoints;
|
|
263
|
+
thruClient?: ThruRpcClient;
|
|
264
|
+
abiManagerProgramId?: string;
|
|
265
|
+
abiManagerIsEphemeral?: boolean;
|
|
266
|
+
}
|
|
267
|
+
interface FetchResult {
|
|
268
|
+
abiYaml: string;
|
|
269
|
+
revision: bigint;
|
|
270
|
+
isFinalized: boolean;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Fetcher for on-chain ABI accounts.
|
|
274
|
+
*
|
|
275
|
+
* Supports fetching ABI from:
|
|
276
|
+
* - Official ABI via program (target: "program")
|
|
277
|
+
* - ABI via ABI meta account (target: "abi-meta")
|
|
278
|
+
* - Direct ABI account (target: "abi")
|
|
279
|
+
*/
|
|
280
|
+
declare class OnchainFetcher {
|
|
281
|
+
private rpcEndpoints;
|
|
282
|
+
private thruClient?;
|
|
283
|
+
private abiManagerProgramId;
|
|
284
|
+
private abiManagerIsEphemeral;
|
|
285
|
+
constructor(config?: OnchainFetcherConfig);
|
|
286
|
+
/**
|
|
287
|
+
* Fetch ABI content from an on-chain account.
|
|
288
|
+
*
|
|
289
|
+
* The `revision` parameter controls both how the account is selected
|
|
290
|
+
* server-side (via version_context when `atSlot` is used) and whether the
|
|
291
|
+
* returned revision is validated against an expected value (`exact` /
|
|
292
|
+
* `minimum`). For `atSlot`, the returned `FetchResult.revision` reflects
|
|
293
|
+
* the revision that was active at that slot.
|
|
294
|
+
*/
|
|
295
|
+
fetch(address: string, target: OnchainTarget, network: string, revision: RevisionSpec): Promise<FetchResult>;
|
|
296
|
+
/**
|
|
297
|
+
* Get the RPC endpoint for a network.
|
|
298
|
+
*/
|
|
299
|
+
getRpcEndpoint(network: string): string;
|
|
300
|
+
private parseAddress;
|
|
301
|
+
private fetchAccountData;
|
|
302
|
+
private fetchWithThruClient;
|
|
303
|
+
private fetchWithHttp;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Import Resolver
|
|
308
|
+
*
|
|
309
|
+
* Resolves ABI imports and builds a manifest for WASM consumption.
|
|
310
|
+
*/
|
|
311
|
+
|
|
312
|
+
interface ResolverConfig {
|
|
313
|
+
onchainFetcher?: OnchainFetcher;
|
|
314
|
+
rpcEndpoints?: RpcEndpoints;
|
|
315
|
+
maxDepth?: number;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Resolve all imports for an ABI and return a manifest.
|
|
319
|
+
*
|
|
320
|
+
* The resolver only supports on-chain imports for browser environments.
|
|
321
|
+
* For path imports, use the CLI `bundle` command.
|
|
322
|
+
*/
|
|
323
|
+
declare function resolveImports(rootAbiYaml: string, config?: ResolverConfig): Promise<ResolutionResult>;
|
|
324
|
+
/**
|
|
325
|
+
* Create a manifest from an ABI and its resolved imports.
|
|
326
|
+
*
|
|
327
|
+
* The manifest maps package names to ABI YAML content.
|
|
328
|
+
*/
|
|
329
|
+
declare function createManifest(result: ResolutionResult): Record<string, string>;
|
|
330
|
+
|
|
331
|
+
export { ABI_ACCOUNT_HEADER_SIZE, ABI_STATE_FINALIZED, ABI_STATE_OPEN, type AbiAccountData, type AbiFile, type AbiMetadata, type ByteRange, DEFAULT_RPC_ENDPOINTS, type FetchResult, type FormatOptions, type FormattedReflection, type FormattedValue, type FormattedValueWithByteRange, type ImportSource, type ImportSourceYaml, type Manifest, type ManifestPackageInfo, OnchainFetcher, type OnchainFetcherConfig, type OnchainTarget, type PackageId, ResolutionError, type ResolutionResult, type ResolvedPackage, type ResolverConfig, type RevisionSpec, type RpcEndpoints, type ThruRpcClient, buildLayoutIr, buildLayoutIrWithManifest, configureWasm, createManifest, deriveOfficialAbiAddress, ensureWasmLoaded, formatReflection, getManifestPackages, parseAbiAccountData, reflect, reflectAccount, reflectAccountWithManifest, reflectEvent, reflectEventWithManifest, reflectInstruction, reflectInstructionWithManifest, reflectWithManifest, resolveImports, revisionMatches, validateManifest };
|