@chironbuilder/ootle-sdk 0.1.20 → 0.1.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.
@@ -0,0 +1,436 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Decrypted contents of an inbound stealth UTXO.
6
+ */
7
+ export class DecryptedOutputResult {
8
+ private constructor();
9
+ free(): void;
10
+ [Symbol.dispose](): void;
11
+ /**
12
+ * The 32-byte commitment mask scalar.
13
+ */
14
+ mask: Uint8Array;
15
+ /**
16
+ * JSON-encoded `Memo` (variants: `U256` / `Message` / `Bytes` / `PayRefAndBytes`), or `null` if
17
+ * the payload carried no memo or `skipMemo` was set.
18
+ */
19
+ get memo_json(): string | undefined;
20
+ /**
21
+ * JSON-encoded `Memo` (variants: `U256` / `Message` / `Bytes` / `PayRefAndBytes`), or `null` if
22
+ * the payload carried no memo or `skipMemo` was set.
23
+ */
24
+ set memo_json(value: string | null | undefined);
25
+ /**
26
+ * The plaintext value (u64).
27
+ */
28
+ value: bigint;
29
+ }
30
+
31
+ /**
32
+ * A generated keypair (raw bytes).
33
+ */
34
+ export class KeypairResult {
35
+ private constructor();
36
+ free(): void;
37
+ [Symbol.dispose](): void;
38
+ public_key: Uint8Array;
39
+ secret_key: Uint8Array;
40
+ }
41
+
42
+ /**
43
+ * A pair of Ootle public keys derived from an OotleSecretKey.
44
+ */
45
+ export class OotlePublicKey {
46
+ private constructor();
47
+ free(): void;
48
+ [Symbol.dispose](): void;
49
+ /**
50
+ * The owner (spending) public key bytes.
51
+ */
52
+ owner_key: Uint8Array;
53
+ /**
54
+ * The view-only public key bytes.
55
+ */
56
+ view_key: Uint8Array;
57
+ }
58
+
59
+ /**
60
+ * A pair of Ootle secret keys (owner + view).
61
+ */
62
+ export class OotleSecretKey {
63
+ private constructor();
64
+ free(): void;
65
+ [Symbol.dispose](): void;
66
+ /**
67
+ * The owner (spending) secret key bytes.
68
+ */
69
+ owner_key: Uint8Array;
70
+ /**
71
+ * The view-only secret key bytes.
72
+ */
73
+ view_key: Uint8Array;
74
+ }
75
+
76
+ /**
77
+ * Parsed components of an Ootle address.
78
+ */
79
+ export class ParsedOotleAddress {
80
+ private constructor();
81
+ free(): void;
82
+ [Symbol.dispose](): void;
83
+ /**
84
+ * Optional pay reference / memo bytes.
85
+ */
86
+ get memo(): Uint8Array | undefined;
87
+ /**
88
+ * Optional pay reference / memo bytes.
89
+ */
90
+ set memo(value: Uint8Array | null | undefined);
91
+ /**
92
+ * The network byte.
93
+ */
94
+ network: number;
95
+ /**
96
+ * The owner (spending) public key bytes.
97
+ */
98
+ owner_key: Uint8Array;
99
+ /**
100
+ * The view-only public key bytes.
101
+ */
102
+ view_key: Uint8Array;
103
+ }
104
+
105
+ /**
106
+ * Result of a Schnorr signature operation (raw bytes). Also used for balance proof signatures, which
107
+ * share the `(public_nonce, signature)` shape.
108
+ */
109
+ export class SchnorrSignatureResult {
110
+ private constructor();
111
+ free(): void;
112
+ [Symbol.dispose](): void;
113
+ public_nonce: Uint8Array;
114
+ signature: Uint8Array;
115
+ }
116
+
117
+ /**
118
+ * Result of generating a stealth outputs statement.
119
+ */
120
+ export class StealthOutputsResult {
121
+ private constructor();
122
+ free(): void;
123
+ [Symbol.dispose](): void;
124
+ /**
125
+ * Sum of all witness masks, suitable for use as the `aggregated_output_mask` argument to
126
+ * `generateStealthBalanceProofSignature`.
127
+ */
128
+ aggregated_output_mask: Uint8Array;
129
+ /**
130
+ * JSON-serialized `StealthOutputsStatement` (the wire-format payload).
131
+ */
132
+ statement_json: string;
133
+ }
134
+
135
+ /**
136
+ * Add a signer to a transaction (unsigned or unsealed JSON).
137
+ *
138
+ * Accepts either an `UnsignedTransactionV1` or `UnsealedTransactionV1` JSON string.
139
+ * Returns the `UnsealedTransactionV1` (with the new signature appended) as a JSON string.
140
+ */
141
+ export function addTransactionSigner(tx_json: string, signer_secret_key: Uint8Array, seal_signer_public_key: Uint8Array): string;
142
+
143
+ /**
144
+ * Aggregate the commitment masks of stealth inputs into a single 32-byte Ristretto scalar.
145
+ *
146
+ * `masks_concat` is the concatenated bytes of all input masks (32 bytes per mask, so the input
147
+ * length must be a multiple of 32). Pass an empty array to obtain the zero scalar.
148
+ *
149
+ * Returns the sum as 32 bytes, suitable as the `aggregated_input_mask` argument to
150
+ * `generateStealthBalanceProofSignature`. The output side of the same balance proof is aggregated
151
+ * automatically by `generateStealthOutputsStatement` (returned as `aggregated_output_mask`).
152
+ */
153
+ export function aggregateInputMasks(masks_concat: Uint8Array): Uint8Array;
154
+
155
+ /**
156
+ * BOR-encode a Transaction (JSON string) → base64 string (TransactionEnvelope format).
157
+ */
158
+ export function borEncodeTransaction(transaction_json: string): string;
159
+
160
+ /**
161
+ * Build a script-path `SpendWitness` revealing `leaf` from the committed `conditions` set, optionally
162
+ * supplying a witness `data` blob the leaf's predicate interprets (e.g. a hashlock preimage). Returns a
163
+ * JSON object: `{ "witness": <SpendWitness>, "condition_root": <Hash32> }`.
164
+ *
165
+ * `conditions_json` is the JSON array of `SpendCondition` leaves exactly as passed to
166
+ * `createStealthOutputWitness`'s `PayTo::Conditions` when the output was created; `leaf_json` is the
167
+ * single leaf being revealed. The returned `condition_root` must match the `Script` root recorded in
168
+ * that output's `SpendAuthorization` -- record it against the spent input via
169
+ * `buildStealthInputsStatementFromInputs`.
170
+ *
171
+ * Pass an empty `data` array for a leaf whose predicate needs no spender-supplied data (e.g. a plain
172
+ * timelock refund).
173
+ */
174
+ export function buildScriptPathWitness(conditions_json: string, leaf_json: string, data: Uint8Array): string;
175
+
176
+ /**
177
+ * Build a `StealthInputsStatement` JSON from raw input commitments and a revealed amount.
178
+ *
179
+ * `input_commitments` is the concatenated bytes of all 32-byte commitments (so the length must be a
180
+ * multiple of 32). Pass an empty array for a revealed-only statement.
181
+ *
182
+ * This is a convenience helper so callers don't need to hand-craft the wire JSON; the result is used
183
+ * as the `inputs_statement_json` argument to `generateStealthBalanceProofSignature` and friends.
184
+ */
185
+ export function buildStealthInputsStatement(input_commitments: Uint8Array, revealed_amount_microtari: bigint): string;
186
+
187
+ /**
188
+ * Build a `StealthInputsStatement` JSON from a JSON array of per-input `{commitment, witness}` pairs
189
+ * and a revealed amount.
190
+ *
191
+ * Unlike `buildStealthInputsStatement`, which only builds key-path inputs from raw commitment bytes,
192
+ * this accepts a caller-supplied `witness` per input -- the only way to spend an output committed with
193
+ * `PayTo::Conditions` (e.g. claiming or refunding an HTLC-style hashlock/timelock output). Build each
194
+ * script-path input's witness with `buildScriptPathWitness` first; a plain key-path input can still be
195
+ * included in the same call, either with `"witness":"KeyPath"` or by omitting `witness` entirely
196
+ * (defaults to key path).
197
+ *
198
+ * `inputs_json` shape: `[{ "commitment": <hex 32 bytes>, "witness"?: <SpendWitness> }, ...]`.
199
+ */
200
+ export function buildStealthInputsStatementFromInputs(inputs_json: string, revealed_amount_microtari: bigint): string;
201
+
202
+ /**
203
+ * Build a complete `StealthTransferStatement` JSON from unblinded input/output witnesses.
204
+ *
205
+ * Unlike `generateStealthOutputsStatement` / `buildStealthInputsStatementFromInputs` +
206
+ * `generateStealthBalanceProofSignature`, which build and sign each half of a transfer
207
+ * separately, this wraps the single primitive that produces the *entire*, internally-consistent
208
+ * statement in one call, including a covenant balance-integrity proof for any script-path input
209
+ * whose revealed leaf gates on `Covenant::BalancePreserved` (see `ootle_wasm_core::stealth::
210
+ * transfer::build_stealth_transfer_statement` for when a claim is and isn't needed).
211
+ *
212
+ * `input_witnesses_json` is a JSON array of `{ "mask_and_value": { "value": <u64>, "mask": <hex
213
+ * 32 bytes> }, "witness"?: <SpendWitness>, "condition_root"?: <Hash32> }` -- each entry's
214
+ * `witness`/`condition_root` are the exact pair `buildScriptPathWitness` returns, for a
215
+ * script-path input; omit both for a plain key-path input. Mixing key-path and script-path
216
+ * inputs in one call is supported.
217
+ *
218
+ * `output_witnesses_json` is a JSON array of the same `{ "witness": {...}, "auth": ..., "tag":
219
+ * ... }` shape `createStealthOutputWitness` returns -- collect one entry per output (including
220
+ * change).
221
+ */
222
+ export function buildStealthTransferStatement(input_witnesses_json: string, revealed_input_amount_microtari: bigint, output_witnesses_json: string, revealed_output_amount_microtari: bigint, revealed_receiver: Uint8Array): string;
223
+
224
+ /**
225
+ * Build a single stealth output witness entirely client-side (sender side), mirroring the wallet
226
+ * daemon's `create_output_witness`.
227
+ *
228
+ * A fresh commitment mask and ephemeral nonce are generated internally; the recipient recovers the
229
+ * value and mask by decrypting `encrypted_data`. Returns one witness as a JSON string with the shape:
230
+ * ```text
231
+ * {
232
+ * "witness": {
233
+ * "amount": <u64>,
234
+ * "mask": <hex 32 bytes>,
235
+ * "sender_public_nonce": <hex 32 bytes>,
236
+ * "minimum_value_promise": <u64>,
237
+ * "encrypted_data": <hex variable-length>,
238
+ * "resource_view_key": <hex 32 bytes | null>
239
+ * },
240
+ * "auth": <SpendAuthorization>,
241
+ * "tag": <u32>
242
+ * }
243
+ * ```
244
+ * Collect one witness per output (including change) into a JSON array and pass it to
245
+ * `generateStealthOutputsStatement`.
246
+ *
247
+ * - `network` is the network byte (0x00 = MainNet, 0x10 = LocalNet, 0x26 = Esmeralda, ...).
248
+ * - `destination_account_public_key` / `destination_view_public_key` are the recipient's 32-byte keys.
249
+ * - `resource_address` is the `resource_<hex>` string of the resource being sent.
250
+ * - `resource_view_key` is the resource view-key holder's 32-byte public key, or `null` for resources without a
251
+ * viewable balance (when set, the output receives an ElGamal proof at statement time).
252
+ * - `memo_json` is an optional JSON-encoded `Memo` to embed in the encrypted payload.
253
+ * - `pay_to_json` is an optional JSON-encoded `PayTo`: `"StealthPublicKey"` (the default when `null`, producing a
254
+ * one-time stealth spend key) or `{"AccessRule": <AccessRule>}`.
255
+ * - `minimum_value_promise` is the range-proof lower bound and must be `<= amount` (use `0` normally).
256
+ */
257
+ export function createStealthOutputWitness(network: number, destination_account_public_key: Uint8Array, destination_view_public_key: Uint8Array, amount: bigint, resource_address: string, resource_view_key: Uint8Array | null | undefined, memo_json: string | null | undefined, pay_to_json: string | null | undefined, minimum_value_promise: bigint): string;
258
+
259
+ /**
260
+ * Brute-force decrypt an ElGamal viewable-balance proof to recover the bound value.
261
+ *
262
+ * Tries each value in `[min_value, max_value]` (inclusive). Returns `null` (via `Option`) if no
263
+ * candidate matches. Uses an on-the-fly value lookup — there is no precomputed table dependency, so
264
+ * callers should keep the range tight (large ranges produce proportional CPU cost).
265
+ *
266
+ * `commitment` is the Pedersen commitment the proof is bound to. Both the view public key and the
267
+ * view secret key are required: the public key is used to re-verify the ZK proof (rejecting tampered
268
+ * proofs before decrypting), the secret key performs the ElGamal decryption itself.
269
+ */
270
+ export function decryptElgamalViewableBalance(proof_json: string, commitment: Uint8Array, view_public_key: Uint8Array, view_secret_key: Uint8Array, min_value: bigint, max_value: bigint): bigint | undefined;
271
+
272
+ /**
273
+ * Derive the AEAD encryption key for `encrypted_data` from a Diffie-Hellman shared secret: `H(DH(s, P))`.
274
+ * Sender derives it with `(sender_secret_nonce, recipient_view_pub)`; receiver derives the same key
275
+ * with `(recipient_view_secret, sender_public_nonce)`.
276
+ */
277
+ export function encryptedDataDhKdfAead(private_key: Uint8Array, public_key: Uint8Array): Uint8Array;
278
+
279
+ /**
280
+ * Generate an ElGamal viewable-balance proof: a zero-knowledge proof that `amount` is the value bound
281
+ * by `commitment`, encrypted to the resource view-key holder.
282
+ *
283
+ * Returns the JSON-encoded `ViewableBalanceProof` (8 × 32-byte fields).
284
+ */
285
+ export function generateElgamalViewableBalanceProof(mask: Uint8Array, amount: bigint, commitment: Uint8Array, view_public_key: Uint8Array): string;
286
+
287
+ /**
288
+ * Generate an extended bulletproof aggregating range proofs for a set of output witnesses, proving
289
+ * each amount is in `[minimum_value_promise, 2^64)`. The number of witnesses is padded to the next
290
+ * power of two internally.
291
+ *
292
+ * `witnesses_json` is a JSON array of "flat" output witnesses (the `witness` field shape from
293
+ * [`generate_stealth_outputs_statement`] — without the surrounding `auth` / `tag`).
294
+ *
295
+ * Returns the raw range proof bytes (may be empty if the input array is empty).
296
+ */
297
+ export function generateExtendedBulletProof(witnesses_json: string): Uint8Array;
298
+
299
+ /**
300
+ * Generate a new random Ristretto keypair.
301
+ * Returns { secret_key: Uint8Array, public_key: Uint8Array }.
302
+ */
303
+ export function generateKeypair(): KeypairResult;
304
+
305
+ /**
306
+ * Generate an Ootle address (bech32m string) from public keys.
307
+ *
308
+ * `network` is the network byte (0x00 = MainNet, 0x10 = LocalNet, 0x26 = Esmeralda, etc.).
309
+ * `memo` is an optional pay reference (max 64 bytes).
310
+ */
311
+ export function generateOotleAddress(owner_public_key: Uint8Array, view_public_key: Uint8Array, network: number, memo?: Uint8Array | null): string;
312
+
313
+ /**
314
+ * Generate a new random pair of Ootle secret keys (owner + view).
315
+ * Returns { owner_key: Uint8Array, view_key: Uint8Array }.
316
+ */
317
+ export function generateOotleSecretKey(): OotleSecretKey;
318
+
319
+ /**
320
+ * Sign the balance proof for a stealth transfer.
321
+ *
322
+ * `aggregated_input_mask` and `aggregated_output_mask` are the 32-byte sums of all input / output
323
+ * commitment masks respectively. Returns a `(public_nonce, signature)` pair (each 32 bytes); the pair
324
+ * may be all-zeros for revealed-only transfers — callers normally omit the balance proof in that case.
325
+ */
326
+ export function generateStealthBalanceProofSignature(aggregated_input_mask: Uint8Array, aggregated_output_mask: Uint8Array, inputs_statement_json: string, outputs_statement_json: string, covenant_claims_json: string): SchnorrSignatureResult;
327
+
328
+ /**
329
+ * Generate the output side of a stealth transfer: per-output Pedersen commitments and encrypted data,
330
+ * optional ElGamal viewable-balance proofs (for outputs with a `resource_view_key`), and an aggregated
331
+ * bulletproof range proof.
332
+ *
333
+ * `witnesses_json` is a JSON array of stealth output witnesses. Each entry has the shape:
334
+ * ```text
335
+ * {
336
+ * "witness": {
337
+ * "amount": <u64>,
338
+ * "mask": <hex 32 bytes>,
339
+ * "sender_public_nonce": <hex 32 bytes>,
340
+ * "minimum_value_promise": <u64>,
341
+ * "encrypted_data": <hex variable-length>,
342
+ * "resource_view_key": <hex 32 bytes | null>
343
+ * },
344
+ * "auth": <SpendAuthorization>,
345
+ * "tag": <u32>
346
+ * }
347
+ * ```
348
+ *
349
+ * Returns the serialized statement plus the aggregated output mask, which the sender feeds to
350
+ * `generateStealthBalanceProofSignature` together with the aggregated input mask.
351
+ */
352
+ export function generateStealthOutputsStatement(witnesses_json: string, revealed_output_amount_microtari: bigint, revealed_receiver: Uint8Array): StealthOutputsResult;
353
+
354
+ /**
355
+ * Hash an UnsignedTransactionV1 (JSON string) for signing.
356
+ * Returns the 64-byte signing message that must be Schnorr-signed.
357
+ *
358
+ * `seal_signer_public_key` is the raw bytes of the seal signer's public key (account owner).
359
+ */
360
+ export function hashUnsignedTransaction(unsigned_tx_json: string, seal_signer_public_key: Uint8Array): Uint8Array;
361
+
362
+ /**
363
+ * Called automatically when the WASM module is instantiated. Do not call directly.
364
+ */
365
+ export function on_start(): void;
366
+
367
+ /**
368
+ * Derive the Ootle public keys from a pair of secret keys.
369
+ * Returns { owner_key: Uint8Array, view_key: Uint8Array }.
370
+ */
371
+ export function ootlePublicKeyFromSecretKey(owner_key: Uint8Array, view_key: Uint8Array): OotlePublicKey;
372
+
373
+ /**
374
+ * Parse a bech32m Ootle address string into its components.
375
+ * Returns { owner_key: Uint8Array, view_key: Uint8Array, network: number, memo: Uint8Array | undefined }.
376
+ */
377
+ export function parseOotleAddress(address: string): ParsedOotleAddress;
378
+
379
+ /**
380
+ * Derive the public key from a secret key (both raw bytes).
381
+ */
382
+ export function publicKeyFromSecretKey(secret_key: Uint8Array): Uint8Array;
383
+
384
+ /**
385
+ * Schnorr-sign a message with a secret key.
386
+ * Returns { public_nonce: Uint8Array, signature: Uint8Array }.
387
+ */
388
+ export function schnorrSign(secret_key: Uint8Array, message: Uint8Array): SchnorrSignatureResult;
389
+
390
+ /**
391
+ * Seal a transaction (unsigned or unsealed JSON) with the seal signer's secret key.
392
+ *
393
+ * Accepts either an `UnsignedTransactionV1` or `UnsealedTransactionV1` JSON string.
394
+ * Returns the sealed `Transaction` as a JSON string.
395
+ */
396
+ export function sealTransaction(tx_json: string, seal_signer_secret_key: Uint8Array): string;
397
+
398
+ /**
399
+ * Derive the recipient's stealth spending scalar `c + k`, where `c = H(network || k.G * r)`. The
400
+ * receiver runs this with their account secret key (`private_key`) and the sender-provided public
401
+ * nonce to obtain the one-time secret that controls the stealth output.
402
+ *
403
+ * `network` is the network byte (0x00 = MainNet, 0x10 = LocalNet, 0x26 = Esmeralda, ...).
404
+ */
405
+ export function stealthDhSecret(network: number, private_key: Uint8Array, public_nonce: Uint8Array): Uint8Array;
406
+
407
+ /**
408
+ * Decrypt and verify the AEAD payload of an inbound stealth UTXO.
409
+ *
410
+ * `output_commitment` is the 32-byte Pedersen commitment; `encrypted_data` is the variable-length
411
+ * XChaCha20Poly1305-encrypted blob; `encryption_key` is the 32-byte AEAD key derived via
412
+ * `encryptedDataDhKdfAead`. Setting `skip_memo` to `true` returns no memo even if the payload carries
413
+ * one (useful when only the value / mask are needed).
414
+ *
415
+ * Throws on AEAD failure or on a commitment mismatch — either indicates the payload was not produced
416
+ * for this view key.
417
+ */
418
+ export function unblindOutput(output_commitment: Uint8Array, encrypted_data: Uint8Array, encryption_key: Uint8Array, skip_memo: boolean): DecryptedOutputResult;
419
+
420
+ /**
421
+ * Pre-flight check that a balance proof signature is cryptographically valid for the given input /
422
+ * output statements. Returns `false` on a malformed proof or invalid signature; the engine performs
423
+ * the authoritative check at submission.
424
+ */
425
+ export function validateBalanceProofSignature(public_nonce: Uint8Array, signature: Uint8Array, inputs_statement_json: string, outputs_statement_json: string, covenant_claims_json: string): boolean;
426
+
427
+ /**
428
+ * Run the same validation the engine performs on a complete `StealthTransferStatement` envelope:
429
+ * structural sanity, commitment well-formedness, range and balance-proof verification.
430
+ *
431
+ * `view_key` is the 32-byte resource view public key, required for resources with a viewable balance
432
+ * and rejected otherwise. Pass `null` for resources without a view key.
433
+ *
434
+ * Throws on a validation failure; returns successfully on a valid statement.
435
+ */
436
+ export function validateStealthTransfer(transfer_json: string, view_key?: Uint8Array | null): void;
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./ootle_wasm.d.ts" */
2
+ import * as wasm from "./ootle_wasm_bg.wasm";
3
+ import { __wbg_set_wasm } from "./ootle_wasm_bg.js";
4
+
5
+ __wbg_set_wasm(wasm);
6
+ wasm.__wbindgen_start();
7
+ export {
8
+ DecryptedOutputResult, KeypairResult, OotlePublicKey, OotleSecretKey, ParsedOotleAddress, SchnorrSignatureResult, StealthOutputsResult, addTransactionSigner, aggregateInputMasks, borEncodeTransaction, buildScriptPathWitness, buildStealthInputsStatement, buildStealthInputsStatementFromInputs, buildStealthTransferStatement, createStealthOutputWitness, decryptElgamalViewableBalance, encryptedDataDhKdfAead, generateElgamalViewableBalanceProof, generateExtendedBulletProof, generateKeypair, generateOotleAddress, generateOotleSecretKey, generateStealthBalanceProofSignature, generateStealthOutputsStatement, hashUnsignedTransaction, on_start, ootlePublicKeyFromSecretKey, parseOotleAddress, publicKeyFromSecretKey, schnorrSign, sealTransaction, stealthDhSecret, unblindOutput, validateBalanceProofSignature, validateStealthTransfer
9
+ } from "./ootle_wasm_bg.js";