@thru/abi 0.1.38 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -67,5 +67,252 @@ interface FormatOptions {
67
67
  includeByteOffsets?: boolean;
68
68
  }
69
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 ImportSource = {
128
+ type: "path";
129
+ path: string;
130
+ } | {
131
+ type: "git";
132
+ url: string;
133
+ ref: string;
134
+ path: string;
135
+ } | {
136
+ type: "http";
137
+ url: string;
138
+ } | {
139
+ type: "onchain";
140
+ address: string;
141
+ target: OnchainTarget;
142
+ network: string;
143
+ revision: RevisionSpec;
144
+ };
145
+ interface PackageId {
146
+ packageName: string;
147
+ version: string;
148
+ }
149
+ interface ResolvedPackage {
150
+ id: PackageId;
151
+ source: ImportSource;
152
+ abiYaml: string;
153
+ dependencies: PackageId[];
154
+ isRemote: boolean;
155
+ }
156
+ interface ResolutionResult {
157
+ root: ResolvedPackage;
158
+ allPackages: ResolvedPackage[];
159
+ manifest: Record<string, string>;
160
+ }
161
+ declare class ResolutionError extends Error {
162
+ code: "CYCLIC_DEPENDENCY" | "VERSION_CONFLICT" | "FETCH_ERROR" | "PARSE_ERROR" | "NOT_FOUND" | "UNSUPPORTED_IMPORT_TYPE";
163
+ details?: unknown | undefined;
164
+ constructor(code: "CYCLIC_DEPENDENCY" | "VERSION_CONFLICT" | "FETCH_ERROR" | "PARSE_ERROR" | "NOT_FOUND" | "UNSUPPORTED_IMPORT_TYPE", message: string, details?: unknown | undefined);
165
+ }
166
+ declare const ABI_ACCOUNT_HEADER_SIZE = 45;
167
+ declare const ABI_STATE_OPEN = 0;
168
+ declare const ABI_STATE_FINALIZED = 1;
169
+ interface AbiAccountData {
170
+ abiMetaAccount: Uint8Array;
171
+ revision: bigint;
172
+ state: number;
173
+ content: string;
174
+ }
175
+ interface RpcEndpoints {
176
+ [network: string]: string;
177
+ }
178
+ declare const DEFAULT_RPC_ENDPOINTS: RpcEndpoints;
179
+ interface AbiMetadata {
180
+ package: string;
181
+ name?: string;
182
+ "abi-version": number;
183
+ "package-version": string;
184
+ description: string;
185
+ imports?: ImportSourceYaml[];
186
+ }
187
+ type ImportSourceYaml = {
188
+ type: "path";
189
+ path: string;
190
+ } | {
191
+ type: "git";
192
+ url: string;
193
+ ref: string;
194
+ path: string;
195
+ } | {
196
+ type: "http";
197
+ url: string;
198
+ } | {
199
+ type: "onchain";
200
+ address: string;
201
+ target?: OnchainTarget;
202
+ network: string;
203
+ revision?: number | string;
204
+ };
205
+ interface AbiFile {
206
+ abi: AbiMetadata;
207
+ types: unknown[];
208
+ }
209
+
210
+ /**
211
+ * On-chain ABI Fetcher
212
+ *
213
+ * Fetches ABI content from on-chain accounts.
214
+ */
215
+
216
+ /**
217
+ * Minimal interface for a Thru RPC client that can fetch raw accounts.
218
+ * This is compatible with @thru/thru-sdk client but doesn't require it.
219
+ */
220
+ interface ThruRpcClient {
221
+ query: {
222
+ getRawAccount: (request: {
223
+ address: {
224
+ value: Uint8Array;
225
+ };
226
+ versionContext: Record<string, unknown>;
227
+ }) => Promise<{
228
+ rawData?: Uint8Array;
229
+ }>;
230
+ };
231
+ }
232
+ /**
233
+ * Derive the official ABI account address for a given program.
234
+ *
235
+ * This performs the same derivation as OnchainFetcher.fetch() with target="program",
236
+ * returning the raw 32-byte address of the ABI account.
237
+ */
238
+ declare function deriveOfficialAbiAddress(programAddress: string, abiManagerProgramId?: string): Promise<Uint8Array>;
239
+ /**
240
+ * Parse ABI account data from raw bytes.
241
+ *
242
+ * Account header layout (45 bytes):
243
+ * - abi_meta_account: [u8; 32]
244
+ * - revision: u64 (little-endian)
245
+ * - state: u8 (0x00=OPEN, 0x01=FINALIZED)
246
+ * - content_sz: u32 (little-endian)
247
+ * - content: [u8; content_sz]
248
+ */
249
+ declare function parseAbiAccountData(data: Uint8Array): AbiAccountData;
250
+ /**
251
+ * Check if a revision matches the specification.
252
+ */
253
+ declare function revisionMatches(revision: bigint, spec: RevisionSpec): boolean;
254
+ interface OnchainFetcherConfig {
255
+ rpcEndpoints?: RpcEndpoints;
256
+ thruClient?: ThruRpcClient;
257
+ abiManagerProgramId?: string;
258
+ abiManagerIsEphemeral?: boolean;
259
+ }
260
+ interface FetchResult {
261
+ abiYaml: string;
262
+ revision: bigint;
263
+ isFinalized: boolean;
264
+ }
265
+ /**
266
+ * Fetcher for on-chain ABI accounts.
267
+ *
268
+ * Supports fetching ABI from:
269
+ * - Official ABI via program (target: "program")
270
+ * - ABI via ABI meta account (target: "abi-meta")
271
+ * - Direct ABI account (target: "abi")
272
+ */
273
+ declare class OnchainFetcher {
274
+ private rpcEndpoints;
275
+ private thruClient?;
276
+ private abiManagerProgramId;
277
+ private abiManagerIsEphemeral;
278
+ constructor(config?: OnchainFetcherConfig);
279
+ /**
280
+ * Fetch ABI content from an on-chain account.
281
+ */
282
+ fetch(address: string, target: OnchainTarget, network: string, revision: RevisionSpec): Promise<FetchResult>;
283
+ /**
284
+ * Get the RPC endpoint for a network.
285
+ */
286
+ getRpcEndpoint(network: string): string;
287
+ private parseAddress;
288
+ private fetchAccountData;
289
+ private fetchWithThruClient;
290
+ private fetchWithHttp;
291
+ }
292
+
293
+ /**
294
+ * Import Resolver
295
+ *
296
+ * Resolves ABI imports and builds a manifest for WASM consumption.
297
+ */
298
+
299
+ interface ResolverConfig {
300
+ onchainFetcher?: OnchainFetcher;
301
+ rpcEndpoints?: RpcEndpoints;
302
+ maxDepth?: number;
303
+ }
304
+ /**
305
+ * Resolve all imports for an ABI and return a manifest.
306
+ *
307
+ * The resolver only supports on-chain imports for browser environments.
308
+ * For path imports, use the CLI `bundle` command.
309
+ */
310
+ declare function resolveImports(rootAbiYaml: string, config?: ResolverConfig): Promise<ResolutionResult>;
311
+ /**
312
+ * Create a manifest from an ABI and its resolved imports.
313
+ *
314
+ * The manifest maps package names to ABI YAML content.
315
+ */
316
+ declare function createManifest(result: ResolutionResult): Record<string, string>;
70
317
 
71
- export { type ByteRange, type FormatOptions, type FormattedReflection, type FormattedValue, type FormattedValueWithByteRange, buildLayoutIr, configureWasm, ensureWasmLoaded, formatReflection, reflect, reflectAccount, reflectEvent, reflectInstruction };
318
+ 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 };