@xo-cash/utils 0.0.2 → 0.0.3-development.15744988955

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.mts CHANGED
@@ -1,4 +1,5 @@
1
- import { XOTemplate } from "@xo-cash/types";
1
+ import { CompilerBch } from "@bitauth/libauth";
2
+ import { XOInvitationVariableValue, XOTemplate } from "@xo-cash/types";
2
3
  import { z } from "zod";
3
4
  import { $ZodIssue } from "zod/v4/core";
4
5
 
@@ -32,6 +33,20 @@ declare const extendedJsonReplacer: (_propertyKey: string, value: unknown) => un
32
33
  * @returns The reconstructed value
33
34
  */
34
35
  declare const extendedJsonReviver: (_propertyKey: string, value: unknown) => unknown;
36
+ /**
37
+ * Serializes an object to a string using the {@link extendedJsonReplacer}.
38
+ *
39
+ * @param object The object to serialize.
40
+ * @returns The string representation of the object in Extended JSON format.
41
+ */
42
+ declare const toExtendedJson: (object: unknown) => string;
43
+ /**
44
+ * Deserializes a string to an object using the {@link extendedJsonReviver}.
45
+ *
46
+ * @param serializedObject The string to deserialize.
47
+ * @returns The object reconstructed from the string.
48
+ */
49
+ declare const fromExtendedJson: (serializedObject: string) => unknown;
35
50
  //#endregion
36
51
  //#region source/script.d.ts
37
52
  /**
@@ -41,6 +56,198 @@ declare const extendedJsonReviver: (_propertyKey: string, value: unknown) => unk
41
56
  */
42
57
  declare const scriptToScriptHash: (script: Uint8Array) => string;
43
58
  //#endregion
59
+ //#region source/sse-session/async-push-iterator.d.ts
60
+ /**
61
+ * An async iterable queue that bridges push-based producers and pull-based consumers.
62
+ *
63
+ * Composes an internal {@link ReadableStream} instead of extending it, so producers
64
+ * call {@link push} while consumers use standard async iteration (`for await...of`).
65
+ *
66
+ * ```ts
67
+ * const messages = new AsyncPushIterator<SSEvent>();
68
+ *
69
+ * // Producer (elsewhere)
70
+ * messages.push(event);
71
+ *
72
+ * // Consumer
73
+ * for await (const event of messages) {
74
+ * handle(event);
75
+ * }
76
+ * ```
77
+ *
78
+ * {@link Symbol.asyncIterator} returns `stream.values({ preventCancel: true })` so
79
+ * breaking out of `for await...of` does not cancel the underlying stream. That
80
+ * matters for long-lived sessions where the producer keeps pushing after a consumer
81
+ * stops reading early (for example, test helpers that only collect a fixed count).
82
+ */
83
+ declare class AsyncPushIterator<T> {
84
+ #private;
85
+ constructor();
86
+ /**
87
+ * Flag indicating if the iterator is closed.
88
+ */
89
+ get closed(): boolean;
90
+ /**
91
+ * Enqueues a value for the consumer.
92
+ *
93
+ * After {@link close}, pushes are silently dropped.
94
+ *
95
+ * @param value - The next value to yield from the iterator.
96
+ */
97
+ push(value: T): void;
98
+ /**
99
+ * Causes any future interactions with the associated stream to error with {@link error}.
100
+ * Calling this will also clear the pending values immediately, so iterators that were listening will not receive them.
101
+ *
102
+ * @param error - The error to throw from the stream.
103
+ */
104
+ error(error: Error): void;
105
+ /**
106
+ * Ends the stream.
107
+ *
108
+ * Marks the iterator closed so future {@link push} calls are ignored.
109
+ * Buffered values are still yielded before iteration completes.
110
+ */
111
+ close(): void;
112
+ /**
113
+ * Returns an async iterator over the composed stream.
114
+ *
115
+ * Uses `preventCancel: true` so early `break` from `for await...of` does not
116
+ * close the stream and block later pushes.
117
+ *
118
+ * Because values are discarded after being read, only a single consumer is supported.
119
+ * Additional consumers will receive a stream lock error. Unread values will be preserved until {@link close} is called.
120
+ */
121
+ [Symbol.asyncIterator](): AsyncIterableIterator<T>;
122
+ }
123
+ //#endregion
124
+ //#region source/sse-session/types.d.ts
125
+ /**
126
+ * Represents a Server-Sent Event.
127
+ */
128
+ interface SSEvent {
129
+ /**
130
+ * Event data.
131
+ */
132
+ data: string;
133
+ /**
134
+ * Event type.
135
+ * This value is optionally sent by the server. Traditional EventSource allows listeners for specific event types.
136
+ * The SSE Session collapses all event types into "message" event.
137
+ */
138
+ event?: string;
139
+ /**
140
+ * Event ID.
141
+ * This value is optionally sent by the server as a "checkpoint" the client can use to resume from using the Last-Event-ID header.
142
+ */
143
+ id?: string;
144
+ /**
145
+ * Reconnection time in milliseconds.
146
+ * This value is optionally sent by the server to indicate the server's preferred time before reconnecting
147
+ */
148
+ retry?: number;
149
+ }
150
+ //#endregion
151
+ //#region source/sse-session/sse-event-parser.d.ts
152
+ /**
153
+ * Optional encoders used when decoding incoming SSE bytes and re-encoding
154
+ * any buffered remainder between chunks.
155
+ */
156
+ interface SSEEventParserOptions {
157
+ /** Decodes raw stream bytes into text. Defaults to a new `TextDecoder`. */
158
+ textDecoder: TextDecoder;
159
+ }
160
+ /**
161
+ * Incrementally parses Server-Sent Events (SSE) from streamed byte chunks.
162
+ *
163
+ * SSE payloads are line-oriented: each event is a sequence of `field: value`
164
+ * lines terminated by a blank line. This parser accepts arbitrary chunk
165
+ * boundaries from a live HTTP response body and emits only complete events.
166
+ *
167
+ * Typical usage is one parser instance per connection, calling {@link parseEvents}
168
+ * for each chunk received from the stream:
169
+ *
170
+ * ```ts
171
+ * const parser = new SSEEventParser();
172
+ *
173
+ * for await (const chunk of response.body) {
174
+ * for (const event of parser.parseEvents(chunk)) {
175
+ * // handle event.data, event.event, event.id, event.retry
176
+ * }
177
+ * }
178
+ * ```
179
+ *
180
+ * Supported fields follow the SSE spec: `data`, `event`, `id`, and `retry`.
181
+ * Multiple `data:` lines in one event are joined with `\n`. An event is only
182
+ * emitted once a blank line is seen and at least one `data` field was collected.
183
+ */
184
+ declare class SSEEventParser {
185
+ #private;
186
+ /**
187
+ * Creates a parser for one SSE stream.
188
+ *
189
+ * Inject custom encoders in tests or when a non-default character encoding
190
+ * is required; production callers can rely on the defaults.
191
+ *
192
+ * @param options - Optional text encoders for decode/encode of stream bytes.
193
+ */
194
+ constructor(options?: Partial<SSEEventParserOptions>);
195
+ /**
196
+ * Clears any buffered bytes from a partial line or incomplete event.
197
+ *
198
+ * Call when abandoning a transport so the next connection does not prepend
199
+ * stale bytes to incoming chunks.
200
+ */
201
+ reset(): void;
202
+ /**
203
+ * Parses all complete SSE events contained in a newly received chunk.
204
+ *
205
+ * The chunk is appended to any bytes buffered from earlier calls. Complete
206
+ * events (blank-line delimited blocks with at least one `data` field) are
207
+ * returned immediately; any trailing partial line or in-progress event stays
208
+ * in the internal buffer until a later chunk completes it.
209
+ *
210
+ * @param chunk - Newly received SSE stream bytes.
211
+ * @returns Zero or more complete parsed SSE events from this chunk.
212
+ */
213
+ parseEvents(chunk: Uint8Array): SSEvent[];
214
+ /**
215
+ * Appends a new chunk to the buffered bytes and splits the combined payload
216
+ * into lines.
217
+ *
218
+ * Accepts `\r\n`, `\r`, and `\n` line endings so events parse correctly
219
+ * regardless of server or platform conventions.
220
+ */
221
+ private getBufferedLines;
222
+ /**
223
+ * Parses one SSE field line into an in-progress event.
224
+ *
225
+ * Lines without a colon are ignored. A single optional space after the colon
226
+ * is stripped from the field value, per the SSE spec.
227
+ */
228
+ private parseLine;
229
+ /**
230
+ * Applies a numeric `retry:` field to an in-progress event.
231
+ *
232
+ * Non-numeric values are ignored rather than failing the parse.
233
+ */
234
+ private parseRetry;
235
+ /**
236
+ * Constructs a completed SSE event from accumulated fields.
237
+ *
238
+ * Trims a trailing newline from multi-line `data` values so callers receive
239
+ * the payload without an extra line break at the end.
240
+ */
241
+ private completeEvent;
242
+ /**
243
+ * Preserves incomplete trailing lines for the next received chunk.
244
+ *
245
+ * Only lines that were fully processed (through a completed event boundary)
246
+ * are discarded; the remainder is re-encoded into {@link messageBuffer}.
247
+ */
248
+ private storeRemainingLines;
249
+ }
250
+ //#endregion
44
251
  //#region source/template/errors.d.ts
45
252
  /**
46
253
  * Formats the Zod validation failures into a single string with one line each: "- <field>: <message>" and top level failures
@@ -161,17 +368,34 @@ declare const xoTemplateLockingTypeSchema: z.ZodEnum<{
161
368
  readonly P2SH: "p2sh";
162
369
  }>;
163
370
  /**
164
- * Validation schema for a primitive type identifier. Defines the set of primitive types
165
- * that can be declared in an XO template. Used by constants, variables, and data fields.
371
+ * Validation schema for a base type identifier.
372
+ * Accepts values from XOTemplateBaseTypes for the `type` field on constants, variables, and data.
166
373
  */
167
- declare const xoTemplatePrimitiveTypeSchema: z.ZodEnum<{
374
+ declare const xoTemplateBaseTypeSchema: z.ZodEnum<{
168
375
  readonly BOOLEAN: "boolean";
169
376
  readonly BYTES: "bytes";
170
377
  readonly INTEGER: "integer";
171
378
  readonly BIGINT: "bigint";
172
379
  readonly STRING: "string";
380
+ }>;
381
+ /**
382
+ * Validation schema for a primitive type identifier.
383
+ * Accepts values from XOTemplatePrimitiveTypes for the `hint` field on constants, variables, and data.
384
+ */
385
+ declare const xoTemplatePrimitiveTypeSchema: z.ZodEnum<{
173
386
  readonly PRIVATE_KEY: "private_key";
174
387
  readonly PUBLIC_KEY: "public_key";
388
+ readonly EXTENDED_PUBLIC_KEY: "extended_public_key";
389
+ readonly SATOSHIS: "satoshis";
390
+ readonly FUNGIBLE_TOKEN_AMOUNT: "token_amount";
391
+ readonly NON_FUNGIBLE_TOKEN_CAPABILITY: "token_capability";
392
+ readonly NON_FUNGIBLE_TOKEN_COMMITMENT: "token_commitment";
393
+ readonly TIMESTAMP: "timestamp";
394
+ readonly TOKEN_CATEGORY: "token_category";
395
+ readonly NFT_COMMITMENT: "nft_commitment";
396
+ readonly TRANSACTION_HASH: "transaction_hash";
397
+ readonly TEMPLATE_IDENTIFIER: "template_identifier";
398
+ readonly SCHNORR_SIGNATURE: "signature";
175
399
  }>;
176
400
  /**
177
401
  * Validation schema for byte array fields i.e. Uint8Array instance.
@@ -872,11 +1096,23 @@ declare const xoTemplateConstantSchema: z.ZodObject<{
872
1096
  readonly INTEGER: "integer";
873
1097
  readonly BIGINT: "bigint";
874
1098
  readonly STRING: "string";
875
- readonly PRIVATE_KEY: "private_key";
876
- readonly PUBLIC_KEY: "public_key";
877
1099
  }>;
878
1100
  value: z.ZodUnknown;
879
- hint: z.ZodOptional<z.ZodString>;
1101
+ hint: z.ZodOptional<z.ZodEnum<{
1102
+ readonly PRIVATE_KEY: "private_key";
1103
+ readonly PUBLIC_KEY: "public_key";
1104
+ readonly EXTENDED_PUBLIC_KEY: "extended_public_key";
1105
+ readonly SATOSHIS: "satoshis";
1106
+ readonly FUNGIBLE_TOKEN_AMOUNT: "token_amount";
1107
+ readonly NON_FUNGIBLE_TOKEN_CAPABILITY: "token_capability";
1108
+ readonly NON_FUNGIBLE_TOKEN_COMMITMENT: "token_commitment";
1109
+ readonly TIMESTAMP: "timestamp";
1110
+ readonly TOKEN_CATEGORY: "token_category";
1111
+ readonly NFT_COMMITMENT: "nft_commitment";
1112
+ readonly TRANSACTION_HASH: "transaction_hash";
1113
+ readonly TEMPLATE_IDENTIFIER: "template_identifier";
1114
+ readonly SCHNORR_SIGNATURE: "signature";
1115
+ }>>;
880
1116
  }, z.core.$strict>;
881
1117
  /**
882
1118
  * Validation schema for a data field definition.
@@ -896,11 +1132,23 @@ declare const xoTemplateDataSchema: z.ZodObject<{
896
1132
  readonly INTEGER: "integer";
897
1133
  readonly BIGINT: "bigint";
898
1134
  readonly STRING: "string";
899
- readonly PRIVATE_KEY: "private_key";
900
- readonly PUBLIC_KEY: "public_key";
901
1135
  }>;
902
1136
  value: z.ZodUnknown;
903
- hint: z.ZodOptional<z.ZodString>;
1137
+ hint: z.ZodOptional<z.ZodEnum<{
1138
+ readonly PRIVATE_KEY: "private_key";
1139
+ readonly PUBLIC_KEY: "public_key";
1140
+ readonly EXTENDED_PUBLIC_KEY: "extended_public_key";
1141
+ readonly SATOSHIS: "satoshis";
1142
+ readonly FUNGIBLE_TOKEN_AMOUNT: "token_amount";
1143
+ readonly NON_FUNGIBLE_TOKEN_CAPABILITY: "token_capability";
1144
+ readonly NON_FUNGIBLE_TOKEN_COMMITMENT: "token_commitment";
1145
+ readonly TIMESTAMP: "timestamp";
1146
+ readonly TOKEN_CATEGORY: "token_category";
1147
+ readonly NFT_COMMITMENT: "nft_commitment";
1148
+ readonly TRANSACTION_HASH: "transaction_hash";
1149
+ readonly TEMPLATE_IDENTIFIER: "template_identifier";
1150
+ readonly SCHNORR_SIGNATURE: "signature";
1151
+ }>>;
904
1152
  }, z.core.$strict>;
905
1153
  /**
906
1154
  * Validation schema for an import default value intent. Extends the base intent with optional
@@ -948,10 +1196,22 @@ declare const xoTemplateVariableSchema: z.ZodObject<{
948
1196
  readonly INTEGER: "integer";
949
1197
  readonly BIGINT: "bigint";
950
1198
  readonly STRING: "string";
1199
+ }>>;
1200
+ hint: z.ZodOptional<z.ZodEnum<{
951
1201
  readonly PRIVATE_KEY: "private_key";
952
1202
  readonly PUBLIC_KEY: "public_key";
1203
+ readonly EXTENDED_PUBLIC_KEY: "extended_public_key";
1204
+ readonly SATOSHIS: "satoshis";
1205
+ readonly FUNGIBLE_TOKEN_AMOUNT: "token_amount";
1206
+ readonly NON_FUNGIBLE_TOKEN_CAPABILITY: "token_capability";
1207
+ readonly NON_FUNGIBLE_TOKEN_COMMITMENT: "token_commitment";
1208
+ readonly TIMESTAMP: "timestamp";
1209
+ readonly TOKEN_CATEGORY: "token_category";
1210
+ readonly NFT_COMMITMENT: "nft_commitment";
1211
+ readonly TRANSACTION_HASH: "transaction_hash";
1212
+ readonly TEMPLATE_IDENTIFIER: "template_identifier";
1213
+ readonly SCHNORR_SIGNATURE: "signature";
953
1214
  }>>;
954
- hint: z.ZodOptional<z.ZodString>;
955
1215
  importDefaultValue: z.ZodOptional<z.ZodObject<{
956
1216
  templateIdentifier: z.ZodOptional<z.ZodString>;
957
1217
  role: z.ZodOptional<z.ZodString>;
@@ -1096,11 +1356,23 @@ declare const xoTemplateSchema: z.ZodObject<{
1096
1356
  readonly INTEGER: "integer";
1097
1357
  readonly BIGINT: "bigint";
1098
1358
  readonly STRING: "string";
1099
- readonly PRIVATE_KEY: "private_key";
1100
- readonly PUBLIC_KEY: "public_key";
1101
1359
  }>;
1102
1360
  value: z.ZodUnknown;
1103
- hint: z.ZodOptional<z.ZodString>;
1361
+ hint: z.ZodOptional<z.ZodEnum<{
1362
+ readonly PRIVATE_KEY: "private_key";
1363
+ readonly PUBLIC_KEY: "public_key";
1364
+ readonly EXTENDED_PUBLIC_KEY: "extended_public_key";
1365
+ readonly SATOSHIS: "satoshis";
1366
+ readonly FUNGIBLE_TOKEN_AMOUNT: "token_amount";
1367
+ readonly NON_FUNGIBLE_TOKEN_CAPABILITY: "token_capability";
1368
+ readonly NON_FUNGIBLE_TOKEN_COMMITMENT: "token_commitment";
1369
+ readonly TIMESTAMP: "timestamp";
1370
+ readonly TOKEN_CATEGORY: "token_category";
1371
+ readonly NFT_COMMITMENT: "nft_commitment";
1372
+ readonly TRANSACTION_HASH: "transaction_hash";
1373
+ readonly TEMPLATE_IDENTIFIER: "template_identifier";
1374
+ readonly SCHNORR_SIGNATURE: "signature";
1375
+ }>>;
1104
1376
  }, z.core.$strict>>>;
1105
1377
  transactions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
1106
1378
  name: z.ZodString;
@@ -1288,11 +1560,23 @@ declare const xoTemplateSchema: z.ZodObject<{
1288
1560
  readonly INTEGER: "integer";
1289
1561
  readonly BIGINT: "bigint";
1290
1562
  readonly STRING: "string";
1291
- readonly PRIVATE_KEY: "private_key";
1292
- readonly PUBLIC_KEY: "public_key";
1293
1563
  }>;
1294
1564
  value: z.ZodUnknown;
1295
- hint: z.ZodOptional<z.ZodString>;
1565
+ hint: z.ZodOptional<z.ZodEnum<{
1566
+ readonly PRIVATE_KEY: "private_key";
1567
+ readonly PUBLIC_KEY: "public_key";
1568
+ readonly EXTENDED_PUBLIC_KEY: "extended_public_key";
1569
+ readonly SATOSHIS: "satoshis";
1570
+ readonly FUNGIBLE_TOKEN_AMOUNT: "token_amount";
1571
+ readonly NON_FUNGIBLE_TOKEN_CAPABILITY: "token_capability";
1572
+ readonly NON_FUNGIBLE_TOKEN_COMMITMENT: "token_commitment";
1573
+ readonly TIMESTAMP: "timestamp";
1574
+ readonly TOKEN_CATEGORY: "token_category";
1575
+ readonly NFT_COMMITMENT: "nft_commitment";
1576
+ readonly TRANSACTION_HASH: "transaction_hash";
1577
+ readonly TEMPLATE_IDENTIFIER: "template_identifier";
1578
+ readonly SCHNORR_SIGNATURE: "signature";
1579
+ }>>;
1296
1580
  }, z.core.$strict>>>;
1297
1581
  variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
1298
1582
  name: z.ZodString;
@@ -1304,10 +1588,22 @@ declare const xoTemplateSchema: z.ZodObject<{
1304
1588
  readonly INTEGER: "integer";
1305
1589
  readonly BIGINT: "bigint";
1306
1590
  readonly STRING: "string";
1591
+ }>>;
1592
+ hint: z.ZodOptional<z.ZodEnum<{
1307
1593
  readonly PRIVATE_KEY: "private_key";
1308
1594
  readonly PUBLIC_KEY: "public_key";
1595
+ readonly EXTENDED_PUBLIC_KEY: "extended_public_key";
1596
+ readonly SATOSHIS: "satoshis";
1597
+ readonly FUNGIBLE_TOKEN_AMOUNT: "token_amount";
1598
+ readonly NON_FUNGIBLE_TOKEN_CAPABILITY: "token_capability";
1599
+ readonly NON_FUNGIBLE_TOKEN_COMMITMENT: "token_commitment";
1600
+ readonly TIMESTAMP: "timestamp";
1601
+ readonly TOKEN_CATEGORY: "token_category";
1602
+ readonly NFT_COMMITMENT: "nft_commitment";
1603
+ readonly TRANSACTION_HASH: "transaction_hash";
1604
+ readonly TEMPLATE_IDENTIFIER: "template_identifier";
1605
+ readonly SCHNORR_SIGNATURE: "signature";
1309
1606
  }>>;
1310
- hint: z.ZodOptional<z.ZodString>;
1311
1607
  importDefaultValue: z.ZodOptional<z.ZodObject<{
1312
1608
  templateIdentifier: z.ZodOptional<z.ZodString>;
1313
1609
  role: z.ZodOptional<z.ZodString>;
@@ -1333,6 +1629,274 @@ declare const xoTemplateSchema: z.ZodObject<{
1333
1629
  scenarios: z.ZodOptional<z.ZodUnknown>;
1334
1630
  }, z.core.$strict>;
1335
1631
  //#endregion
1632
+ //#region source/cash-assembly/evaluations.d.ts
1633
+ /**
1634
+ * Supported decode modes for compiled CashAssembly evaluation bytes.
1635
+ */
1636
+ type CompiledCashAssemblyDecodeMode = 'utf8' | 'hex' | 'boolean' | 'bigint' | 'uint8array';
1637
+ /**
1638
+ * Parameters for compiling CashAssembly string.
1639
+ */
1640
+ type CompileCashAssemblyStringParameters = {
1641
+ /**
1642
+ * Text that may embed CashAssembly evaluations such as `$(<fee>)` or `$(<expiry.toIso8601>)`.
1643
+ */
1644
+ cashAssemblyText: string;
1645
+ /**
1646
+ * Used for both primitive method evaluations and normal CashAssembly compilation.
1647
+ */
1648
+ variables: Record<string, XOInvitationVariableValue | Uint8Array>;
1649
+ /**
1650
+ * The mode to decode compiled evaluation bytes into a string.
1651
+ */
1652
+ evaluationDecodeMode?: CompiledCashAssemblyDecodeMode;
1653
+ /**
1654
+ * Optional template variable definitions. When provided, each `<name.method>` push whose `hint`
1655
+ * maps to a supported primitive class is resolved to bytes before CashAssembly compilation.
1656
+ */
1657
+ templateVariables?: XOTemplate['variables'];
1658
+ };
1659
+ /**
1660
+ * Checks if the expression is a CashAssembly expression.
1661
+ *
1662
+ * @param {unknown} expression - The expression to check.
1663
+ * @returns {boolean} True if the expression is a CashAssembly expression, false otherwise.
1664
+ */
1665
+ declare const isCashAssemblyExpression: (expression: unknown) => boolean;
1666
+ /**
1667
+ * Extracts all CashAssembly evaluations (i.e., substrings like $(...)) from the input text.
1668
+ *
1669
+ * @param {string} text - The input string to scan for CashAssembly evaluations.
1670
+ * @returns {string[]} An array of evaluation strings found in the input.
1671
+ *
1672
+ * @example
1673
+ * extractCashAssemblyEvaluations("OP_DUP <$(<foo>)> OP_HASH160 $(<bar>)");
1674
+ * // returns ['$(<foo>)', '$(<bar>)']
1675
+ */
1676
+ declare const extractCashAssemblyEvaluations: (text: string) => string[];
1677
+ /**
1678
+ * Extracts unique variable identifiers enclosed in angle brackets from each evaluation string.
1679
+ *
1680
+ * CashAssembly literal tokens such as hex bytes, numbers, and quoted strings are excluded via
1681
+ * {@link CASHASSEMBLY_LITERAL_TOKEN_PATTERN}. For example, `<0x02>` and `<"minting">` are not returned.
1682
+ *
1683
+ * @param {string[]} evaluations - An array of evaluation strings from which to extract variable names.
1684
+ * @returns {string[]} An array of variable names.
1685
+ */
1686
+ declare const extractVariablesFromEvaluations: (evaluations: string[]) => string[];
1687
+ /**
1688
+ * Decodes compiled CashAssembly evaluation bytes into a string representation.
1689
+ *
1690
+ * 'evaluationDecodeMode' determines how the evaluation bytes are interpreted and presented.
1691
+ * Use `bigint` for numeric values like satoshis, `utf8` for text labels, `hex` for binary data
1692
+ * such as hashes, and `boolean` to represent boolean values.
1693
+ *
1694
+ * @param {Uint8Array} compiledResult - The compiled evaluation bytecode.
1695
+ * @param {CompiledCashAssemblyDecodeMode} [evaluationDecodeMode='utf8'] - The decode mode used to convert
1696
+ * bytes to text.
1697
+ * @returns {string} The decoded value as a string suitable for inline replacement.
1698
+ * @throws {@link CashAssemblyVmNumberDecodeError} When `evaluationDecodeMode` is `bigint` and the bytes are not a VM number.
1699
+ */
1700
+ declare const decodeCompiledCashAssemblyEvaluation: (compiledResult: Uint8Array, evaluationDecodeMode?: CompiledCashAssemblyDecodeMode) => string;
1701
+ /**
1702
+ * Generates bytecode for a specific CashAssembly evaluation using given variable values and a prepared compiler.
1703
+ *
1704
+ * @param {CompilerBch} compiler - The libauth compiler from {@link compileCashAssemblyEvaluations}.
1705
+ * @param {string} evaluation - The specific evaluation string to compile.
1706
+ * @param {Record<string, Uint8Array>} variables - A record mapping variable names to their values.
1707
+ * @returns {Uint8Array} The compiled bytecode.
1708
+ * @throws {@link CashAssemblyRequiredVariableMissingError} If a required variable is not present.
1709
+ * @throws {@link CashAssemblyVariableTypeMismatchError} If a variable value is not a Uint8Array.
1710
+ * @throws {@link CashAssemblyCompilationFailedError} If libauth compilation fails.
1711
+ */
1712
+ declare const generateCashAssemblyBytecode: (compiler: CompilerBch, evaluation: string, variables: Record<string, Uint8Array>) => Uint8Array;
1713
+ /**
1714
+ * Prepares a compiler for the provided CashAssembly evaluations, setting required variables as 'WalletData'.
1715
+ *
1716
+ * @param {string[]} evaluations - Array of evaluation strings (e.g., ['$(<var1>)', '$(<var2> <var3>)']).
1717
+ * @returns {CompilerBch} A Libauth compiler instance for use with these evaluations.
1718
+ */
1719
+ declare const compileCashAssemblyEvaluations: (evaluations: string[]) => CompilerBch;
1720
+ /**
1721
+ * Compiles all CashAssembly evaluations in a text string and replaces each evaluation
1722
+ * with a decoded string representation.
1723
+ *
1724
+ * @param {CompileCashAssemblyStringParameters} parameters - Parameters for compiling the CashAssembly string.
1725
+ * @param {string} parameters.cashAssemblyText - The string with CashAssembly evaluations.
1726
+ * @param {Record<string, XOInvitationVariableValue | Uint8Array>} parameters.variables - Object mapping
1727
+ * variable names to values for compilation.
1728
+ * @param {CompiledCashAssemblyDecodeMode} [parameters.evaluationDecodeMode='utf8'] - The decode mode used
1729
+ * after each evaluation is compiled. See {@link decodeCompiledCashAssemblyEvaluation}.
1730
+ * @param {XOTemplate['variables']} [parameters.templateVariables] - Optional template variable definitions
1731
+ * used to resolve supported `<name.method>` pushes via each variable's `hint`.
1732
+ * @returns {string} Compiled text with all evaluations replaced by decoded string values.
1733
+ * @throws {@link CashAssemblyRequiredVariableMissingError} When a required variable is not present in the variables map.
1734
+ * @throws {@link CashAssemblyPrimitiveMethodMissingError} When a supported primitive hint has an unknown method.
1735
+ * @throws {@link CashAssemblyPrimitiveVariableMissingError} When a supported primitive method is missing its runtime value.
1736
+ * @throws {@link CashAssemblyUnsupportedValueTypeError} When a primitive method return type cannot be embedded as bytes.
1737
+ * @throws {@link CashAssemblyNumberNotSafeIntegerError} When a number variable is not a safe integer.
1738
+ * @throws {@link CashAssemblyVmNumberDecodeError} When `evaluationDecodeMode` is `bigint` and an evaluation is not a VM number.
1739
+ */
1740
+ declare const compileCashAssemblyString: (parameters: CompileCashAssemblyStringParameters) => string;
1741
+ //#endregion
1742
+ //#region source/cash-assembly/primitive-evaluations.d.ts
1743
+ /**
1744
+ * Inputs needed to resolve primitive method pushes from extracted CashAssembly identifiers.
1745
+ */
1746
+ type ResolvePrimitiveMethodBytesParameters = {
1747
+ /**
1748
+ * Variable identifiers from {@link extractVariablesFromEvaluations}, for example
1749
+ * `['amount.toSatoshis', 'fee.toSatoshis']`.
1750
+ */
1751
+ identifiers: string[];
1752
+ /**
1753
+ * Variable names and values object.
1754
+ */
1755
+ variables: Record<string, unknown>;
1756
+ /**
1757
+ * Template variable definitions. When omitted, no primitive methods are resolved.
1758
+ * The `hint` on each entry selects the primitive class.
1759
+ */
1760
+ templateVariables?: XOTemplate['variables'];
1761
+ };
1762
+ /**
1763
+ * Resolves supported `base.method` identifiers to CashAssembly variable bytes.
1764
+ *
1765
+ * Each single dot identifier whose `hint` maps to a supported primitive is resolved and stored under
1766
+ * the full identifier (`base.method`). Unsupported or multi dot identifiers are left for CashAssembly.
1767
+ *
1768
+ * When `templateVariables` is omitted, returns an empty map.
1769
+ *
1770
+ * @param {ResolvePrimitiveMethodBytesParameters} parameters - Identifiers, values, and optional template metadata.
1771
+ * @returns {Record<string, Uint8Array>} Resolved method identifiers mapped to bytes for CashAssembly pushes.
1772
+ * @throws {@link CashAssemblyPrimitiveMethodMissingError} When the hint is a supported primitive but the method is missing.
1773
+ * @throws {@link CashAssemblyPrimitiveVariableMissingError} When the runtime value is missing from the variables map.
1774
+ * @throws {@link CashAssemblyUnsupportedValueTypeError} When the method return type cannot be embedded.
1775
+ * @throws {@link CashAssemblyNumberNotSafeIntegerError} When a method return value is a number that is not a safe integer.
1776
+ */
1777
+ declare const resolvePrimitiveMethodBytes: (parameters: ResolvePrimitiveMethodBytesParameters) => Record<string, Uint8Array>;
1778
+ //#endregion
1779
+ //#region source/cash-assembly/bytes.d.ts
1780
+ /**
1781
+ * Converts a value into bytes representation.
1782
+ *
1783
+ * @param {unknown} value - Value to encode, should be one of: Uint8Array, bigint, boolean, string, or a safe integer number.
1784
+ * @param {string} valueIdentifier - Identifier used in error messages.
1785
+ * @returns {Uint8Array} Bytes representation of the value.
1786
+ * @throws {@link CashAssemblyNumberNotSafeIntegerError} When a number is not a safe integer.
1787
+ * @throws {@link CashAssemblyUnsupportedValueTypeError} When the value type cannot be resolved.
1788
+ */
1789
+ declare const convertValueToBytes: (value: unknown, valueIdentifier: string) => Uint8Array;
1790
+ //#endregion
1791
+ //#region source/cash-assembly/defaults.d.ts
1792
+ /**
1793
+ * Detects whether a string is a pure CashAssembly expression.
1794
+ *
1795
+ * CashAssembly expressions look like `$(<variable>)` or `$(<a> <b>)`. This pattern checks
1796
+ * that the entire string is one such expression and nothing else. It will not match if
1797
+ * there is other text surrounding the expression.
1798
+ *
1799
+ * For example:
1800
+ * `$(<fee>)` matches (a full expression)
1801
+ * `OP_DUP $(<fee>)` does not match (extra text before it)
1802
+ * `$()` does not match (empty expression)
1803
+ */
1804
+ declare const CASHASSEMBLY_EXPRESSION_PATTERN: RegExp;
1805
+ /**
1806
+ * Finds all CashAssembly evaluations embedded in a larger string.
1807
+ *
1808
+ * An evaluation looks like `$(...)`, for example `$(<fee>)` or `$(<a> <b>)`. This pattern
1809
+ * locates every occurrence in the input and returns them all (global flag `g`).
1810
+ * Empty evaluations `$()` are intentionally excluded because they reference no variables.
1811
+ *
1812
+ * For example, scanning `"OP_DUP <$(<pubkeyHash>)> OP_HASH160 $(<fee>)"` would return
1813
+ * `['$(<pubkeyHash>)', '$(<fee>)']`.
1814
+ */
1815
+ declare const CASHASSEMBLY_EVALUATION_PATTERN: RegExp;
1816
+ /**
1817
+ * Extracts variable names from angle-bracket references inside a CashAssembly evaluation.
1818
+ *
1819
+ * Inside an evaluation like `$(<pubkeyHash> <fee>)`, variables are referenced as `<name>`.
1820
+ * This pattern captures the name between the brackets. The global flag `g` allows iterating
1821
+ * over every variable reference in a single evaluation string.
1822
+ *
1823
+ * For example, running this against `$(<pubkeyHash> <fee>)` would return the variable names
1824
+ * `["pubkeyHash", "fee"]`.
1825
+ */
1826
+ declare const CASHASSEMBLY_VARIABLE_PATTERN: RegExp;
1827
+ /**
1828
+ * Identifies CashAssembly literal tokens that appear inside angle-bracket push statements.
1829
+ *
1830
+ * Inside an evaluation, not everything between `<` and `>` is a variable name. Literals are
1831
+ * also valid push contents: numeric literals (e.g. `<0>`, `<32>`), hex literals (`<0x02>`),
1832
+ * binary literals (`<0b1010>`), and string literals (`<"minting">`, `<'hello'>`). This pattern
1833
+ * matches any captured token that starts with a digit or a quote character.
1834
+ */
1835
+ declare const CASHASSEMBLY_LITERAL_TOKEN_PATTERN: RegExp;
1836
+ /**
1837
+ * Matches a single dot variable method reference inside an angle-bracket identifier.
1838
+ *
1839
+ * Used to detect primitive method references such as `expiry.toIso8601`.
1840
+ *
1841
+ * For example:
1842
+ * `expiry.toIso8601` matches (base `expiry`, method `toIso8601`)
1843
+ * `requestedSatoshis` does not match (no method)
1844
+ * `key.schnorr_signature.all_outputs` does not match (more than one dot)
1845
+ * `key.public_key` matches the pattern shape but it is only resolved
1846
+ * when `hint` maps to a primitive
1847
+ */
1848
+ declare const CASHASSEMBLY_VARIABLE_METHOD_REFERENCE_PATTERN: RegExp;
1849
+ //#endregion
1850
+ //#region source/cash-assembly/errors.d.ts
1851
+ /**
1852
+ * Error thrown when a required variable is missing.
1853
+ */
1854
+ declare class CashAssemblyRequiredVariableMissingError extends Error {
1855
+ constructor(variableNames?: string[]);
1856
+ }
1857
+ /**
1858
+ * Error thrown when cash assembly compilation fails.
1859
+ */
1860
+ declare class CashAssemblyCompilationFailedError extends Error {
1861
+ constructor(message?: string);
1862
+ }
1863
+ /**
1864
+ * Error thrown when a variable's runtime type does not match the type required for compilation.
1865
+ */
1866
+ declare class CashAssemblyVariableTypeMismatchError extends Error {
1867
+ constructor(variableKey: string, expectedType: string, actualType: string);
1868
+ }
1869
+ /**
1870
+ * Error thrown when a supported primitive hint does not expose the requested method.
1871
+ */
1872
+ declare class CashAssemblyPrimitiveMethodMissingError extends Error {
1873
+ constructor(identifier: string, methodName: string, hint: string);
1874
+ }
1875
+ /**
1876
+ * Error thrown when a value cannot be resolved as bytes.
1877
+ */
1878
+ declare class CashAssemblyUnsupportedValueTypeError extends Error {
1879
+ constructor(identifier: string, returnedType: string);
1880
+ }
1881
+ /**
1882
+ * Error thrown when a number cannot be safely encoded as a CashAssembly VM number.
1883
+ */
1884
+ declare class CashAssemblyNumberNotSafeIntegerError extends Error {
1885
+ constructor(identifier: string, value: number);
1886
+ }
1887
+ /**
1888
+ * Error thrown when a supported primitive is selected but its value is missing when provided in the variables map.
1889
+ */
1890
+ declare class CashAssemblyPrimitiveVariableMissingError extends Error {
1891
+ constructor(identifier: string, variableName: string);
1892
+ }
1893
+ /**
1894
+ * Error thrown when compiled evaluation bytes cannot be decoded as a VM number.
1895
+ */
1896
+ declare class CashAssemblyVmNumberDecodeError extends Error {
1897
+ constructor(reason: string);
1898
+ }
1899
+ //#endregion
1336
1900
  //#region source/template/serialization.d.ts
1337
1901
  /**
1338
1902
  * Serializes an XOTemplate to a JSON string. Encodes `bigint` and `Uint8Array` fields in
@@ -1344,5 +1908,5 @@ declare const xoTemplateSchema: z.ZodObject<{
1344
1908
  */
1345
1909
  declare const serializeTemplate: (template: XOTemplate) => string;
1346
1910
  //#endregion
1347
- export { TemplateInvalidError, TemplateJsonMalformedError, TemplateSerializationFailedError, VIEW_PROPERTIES_DESCRIPTION_MAX_LENGTH, VIEW_PROPERTIES_ICON_MAX_LENGTH, VIEW_PROPERTIES_NAME_MAX_LENGTH, bchVmVersionSchema, buildErrorDescription, extendedJsonReplacer, extendedJsonReviver, generateTemplateIdentifier, parseTemplate, satoshisSchema, scriptToScriptHash, serializeTemplate, uint8ArraySchema, xoTemplateActionIntentSchema, xoTemplateActionRequirementsSchema, xoTemplateActionRoleRequirementsSchema, xoTemplateActionRoleSchema, xoTemplateActionSchema, xoTemplateAssetAmountsSchema, xoTemplateConstantSchema, xoTemplateDataSchema, xoTemplateDefaultsSchema, xoTemplateIconSchema, xoTemplateImportDefaultValueSchema, xoTemplateInputSchema, xoTemplateIntentSchema, xoTemplateLockingScriptIntentSchema, xoTemplateLockingScriptRoleSchema, xoTemplateLockingScriptSchema, xoTemplateLockingTypeSchema, xoTemplateNftCapabilitySchema, xoTemplateNonFungibleTokenDetailsSchema, xoTemplateOutputIntentSchema, xoTemplateOutputSchema, xoTemplatePrimitiveTypeSchema, xoTemplateResourceSchema, xoTemplateRoleSlotSchema, xoTemplateRoleSlotsRequirementsSchema, xoTemplateSchema, xoTemplateStateSchema, xoTemplateTokenSchema, xoTemplateTransactionInputSchema, xoTemplateTransactionOutputSchema, xoTemplateTransactionRoleDataSchema, xoTemplateTransactionSchema, xoTemplateVariableSchema, xoTemplateViewPropertiesSchema };
1911
+ export { AsyncPushIterator, CASHASSEMBLY_EVALUATION_PATTERN, CASHASSEMBLY_EXPRESSION_PATTERN, CASHASSEMBLY_LITERAL_TOKEN_PATTERN, CASHASSEMBLY_VARIABLE_METHOD_REFERENCE_PATTERN, CASHASSEMBLY_VARIABLE_PATTERN, CashAssemblyCompilationFailedError, CashAssemblyNumberNotSafeIntegerError, CashAssemblyPrimitiveMethodMissingError, CashAssemblyPrimitiveVariableMissingError, CashAssemblyRequiredVariableMissingError, CashAssemblyUnsupportedValueTypeError, CashAssemblyVariableTypeMismatchError, CashAssemblyVmNumberDecodeError, CompileCashAssemblyStringParameters, CompiledCashAssemblyDecodeMode, ResolvePrimitiveMethodBytesParameters, SSEEventParser, SSEEventParserOptions, TemplateInvalidError, TemplateJsonMalformedError, TemplateSerializationFailedError, VIEW_PROPERTIES_DESCRIPTION_MAX_LENGTH, VIEW_PROPERTIES_ICON_MAX_LENGTH, VIEW_PROPERTIES_NAME_MAX_LENGTH, bchVmVersionSchema, buildErrorDescription, compileCashAssemblyEvaluations, compileCashAssemblyString, convertValueToBytes, decodeCompiledCashAssemblyEvaluation, extendedJsonReplacer, extendedJsonReviver, extractCashAssemblyEvaluations, extractVariablesFromEvaluations, fromExtendedJson, generateCashAssemblyBytecode, generateTemplateIdentifier, isCashAssemblyExpression, parseTemplate, resolvePrimitiveMethodBytes, satoshisSchema, scriptToScriptHash, serializeTemplate, toExtendedJson, uint8ArraySchema, xoTemplateActionIntentSchema, xoTemplateActionRequirementsSchema, xoTemplateActionRoleRequirementsSchema, xoTemplateActionRoleSchema, xoTemplateActionSchema, xoTemplateAssetAmountsSchema, xoTemplateBaseTypeSchema, xoTemplateConstantSchema, xoTemplateDataSchema, xoTemplateDefaultsSchema, xoTemplateIconSchema, xoTemplateImportDefaultValueSchema, xoTemplateInputSchema, xoTemplateIntentSchema, xoTemplateLockingScriptIntentSchema, xoTemplateLockingScriptRoleSchema, xoTemplateLockingScriptSchema, xoTemplateLockingTypeSchema, xoTemplateNftCapabilitySchema, xoTemplateNonFungibleTokenDetailsSchema, xoTemplateOutputIntentSchema, xoTemplateOutputSchema, xoTemplatePrimitiveTypeSchema, xoTemplateResourceSchema, xoTemplateRoleSlotSchema, xoTemplateRoleSlotsRequirementsSchema, xoTemplateSchema, xoTemplateStateSchema, xoTemplateTokenSchema, xoTemplateTransactionInputSchema, xoTemplateTransactionOutputSchema, xoTemplateTransactionRoleDataSchema, xoTemplateTransactionSchema, xoTemplateVariableSchema, xoTemplateViewPropertiesSchema };
1348
1912
  //# sourceMappingURL=index.d.mts.map