@tari-project/ootle-wasm 0.30.1 → 0.31.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/ootle_wasm.d.ts +185 -1
- package/ootle_wasm.js +1 -1
- package/ootle_wasm_bg.js +501 -98
- package/ootle_wasm_bg.wasm +0 -0
- package/package.json +2 -2
- package/LICENSE +0 -29
package/ootle_wasm.d.ts
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
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
|
+
|
|
4
31
|
/**
|
|
5
32
|
* A generated keypair (raw bytes).
|
|
6
33
|
*/
|
|
@@ -76,7 +103,8 @@ export class ParsedOotleAddress {
|
|
|
76
103
|
}
|
|
77
104
|
|
|
78
105
|
/**
|
|
79
|
-
* Result of a Schnorr signature operation (raw bytes).
|
|
106
|
+
* Result of a Schnorr signature operation (raw bytes). Also used for balance proof signatures, which
|
|
107
|
+
* share the `(public_nonce, signature)` shape.
|
|
80
108
|
*/
|
|
81
109
|
export class SchnorrSignatureResult {
|
|
82
110
|
private constructor();
|
|
@@ -86,6 +114,24 @@ export class SchnorrSignatureResult {
|
|
|
86
114
|
signature: Uint8Array;
|
|
87
115
|
}
|
|
88
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
|
+
|
|
89
135
|
/**
|
|
90
136
|
* Add a signer to a transaction (unsigned or unsealed JSON).
|
|
91
137
|
*
|
|
@@ -94,11 +140,74 @@ export class SchnorrSignatureResult {
|
|
|
94
140
|
*/
|
|
95
141
|
export function addTransactionSigner(tx_json: string, signer_secret_key: Uint8Array, seal_signer_public_key: Uint8Array): string;
|
|
96
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
|
+
|
|
97
155
|
/**
|
|
98
156
|
* BOR-encode a Transaction (JSON string) → base64 string (TransactionEnvelope format).
|
|
99
157
|
*/
|
|
100
158
|
export function borEncodeTransaction(transaction_json: string): string;
|
|
101
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Build a `StealthInputsStatement` JSON from raw input commitments and a revealed amount.
|
|
162
|
+
*
|
|
163
|
+
* `input_commitments` is the concatenated bytes of all 32-byte commitments (so the length must be a
|
|
164
|
+
* multiple of 32). Pass an empty array for a revealed-only statement.
|
|
165
|
+
*
|
|
166
|
+
* This is a convenience helper so callers don't need to hand-craft the wire JSON; the result is used
|
|
167
|
+
* as the `inputs_statement_json` argument to `generateStealthBalanceProofSignature` and friends.
|
|
168
|
+
*/
|
|
169
|
+
export function buildStealthInputsStatement(input_commitments: Uint8Array, revealed_amount_microtari: bigint): string;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Brute-force decrypt an ElGamal viewable-balance proof to recover the bound value.
|
|
173
|
+
*
|
|
174
|
+
* Tries each value in `[min_value, max_value]` (inclusive). Returns `null` (via `Option`) if no
|
|
175
|
+
* candidate matches. Uses an on-the-fly value lookup — there is no precomputed table dependency, so
|
|
176
|
+
* callers should keep the range tight (large ranges produce proportional CPU cost).
|
|
177
|
+
*
|
|
178
|
+
* `commitment` is the Pedersen commitment the proof is bound to. Both the view public key and the
|
|
179
|
+
* view secret key are required: the public key is used to re-verify the ZK proof (rejecting tampered
|
|
180
|
+
* proofs before decrypting), the secret key performs the ElGamal decryption itself.
|
|
181
|
+
*/
|
|
182
|
+
export function decryptElgamalViewableBalance(proof_json: string, commitment: Uint8Array, view_public_key: Uint8Array, view_secret_key: Uint8Array, min_value: bigint, max_value: bigint): bigint | undefined;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Derive the AEAD encryption key for `encrypted_data` from a Diffie-Hellman shared secret: `H(DH(s, P))`.
|
|
186
|
+
* Sender derives it with `(sender_secret_nonce, recipient_view_pub)`; receiver derives the same key
|
|
187
|
+
* with `(recipient_view_secret, sender_public_nonce)`.
|
|
188
|
+
*/
|
|
189
|
+
export function encryptedDataDhKdfAead(private_key: Uint8Array, public_key: Uint8Array): Uint8Array;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Generate an ElGamal viewable-balance proof: a zero-knowledge proof that `amount` is the value bound
|
|
193
|
+
* by `commitment`, encrypted to the resource view-key holder.
|
|
194
|
+
*
|
|
195
|
+
* Returns the JSON-encoded `ViewableBalanceProof` (8 × 32-byte fields).
|
|
196
|
+
*/
|
|
197
|
+
export function generateElgamalViewableBalanceProof(mask: Uint8Array, amount: bigint, commitment: Uint8Array, view_public_key: Uint8Array): string;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Generate an extended bulletproof aggregating range proofs for a set of output witnesses, proving
|
|
201
|
+
* each amount is in `[minimum_value_promise, 2^64)`. The number of witnesses is padded to the next
|
|
202
|
+
* power of two internally.
|
|
203
|
+
*
|
|
204
|
+
* `witnesses_json` is a JSON array of "flat" output witnesses (the `witness` field shape from
|
|
205
|
+
* [`generate_stealth_outputs_statement`] — without the surrounding `spend_condition` / `tag`).
|
|
206
|
+
*
|
|
207
|
+
* Returns the raw range proof bytes (may be empty if the input array is empty).
|
|
208
|
+
*/
|
|
209
|
+
export function generateExtendedBulletProof(witnesses_json: string): Uint8Array;
|
|
210
|
+
|
|
102
211
|
/**
|
|
103
212
|
* Generate a new random Ristretto keypair.
|
|
104
213
|
* Returns { secret_key: Uint8Array, public_key: Uint8Array }.
|
|
@@ -119,6 +228,41 @@ export function generateOotleAddress(owner_public_key: Uint8Array, view_public_k
|
|
|
119
228
|
*/
|
|
120
229
|
export function generateOotleSecretKey(): OotleSecretKey;
|
|
121
230
|
|
|
231
|
+
/**
|
|
232
|
+
* Sign the balance proof for a stealth transfer.
|
|
233
|
+
*
|
|
234
|
+
* `aggregated_input_mask` and `aggregated_output_mask` are the 32-byte sums of all input / output
|
|
235
|
+
* commitment masks respectively. Returns a `(public_nonce, signature)` pair (each 32 bytes); the pair
|
|
236
|
+
* may be all-zeros for revealed-only transfers — callers normally omit the balance proof in that case.
|
|
237
|
+
*/
|
|
238
|
+
export function generateStealthBalanceProofSignature(aggregated_input_mask: Uint8Array, aggregated_output_mask: Uint8Array, inputs_statement_json: string, outputs_statement_json: string): SchnorrSignatureResult;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Generate the output side of a stealth transfer: per-output Pedersen commitments and encrypted data,
|
|
242
|
+
* optional ElGamal viewable-balance proofs (for outputs with a `resource_view_key`), and an aggregated
|
|
243
|
+
* bulletproof range proof.
|
|
244
|
+
*
|
|
245
|
+
* `witnesses_json` is a JSON array of stealth output witnesses. Each entry has the shape:
|
|
246
|
+
* ```text
|
|
247
|
+
* {
|
|
248
|
+
* "witness": {
|
|
249
|
+
* "amount": <u64>,
|
|
250
|
+
* "mask": <hex 32 bytes>,
|
|
251
|
+
* "sender_public_nonce": <hex 32 bytes>,
|
|
252
|
+
* "minimum_value_promise": <u64>,
|
|
253
|
+
* "encrypted_data": <hex variable-length>,
|
|
254
|
+
* "resource_view_key": <hex 32 bytes | null>
|
|
255
|
+
* },
|
|
256
|
+
* "spend_condition": <SpendCondition>,
|
|
257
|
+
* "tag": <u32>
|
|
258
|
+
* }
|
|
259
|
+
* ```
|
|
260
|
+
*
|
|
261
|
+
* Returns the serialized statement plus the aggregated output mask, which the sender feeds to
|
|
262
|
+
* `generateStealthBalanceProofSignature` together with the aggregated input mask.
|
|
263
|
+
*/
|
|
264
|
+
export function generateStealthOutputsStatement(witnesses_json: string, revealed_output_amount_microtari: bigint): StealthOutputsResult;
|
|
265
|
+
|
|
122
266
|
/**
|
|
123
267
|
* Hash an UnsignedTransactionV1 (JSON string) for signing.
|
|
124
268
|
* Returns the 64-byte signing message that must be Schnorr-signed.
|
|
@@ -162,3 +306,43 @@ export function schnorrSign(secret_key: Uint8Array, message: Uint8Array): Schnor
|
|
|
162
306
|
* Returns the sealed `Transaction` as a JSON string.
|
|
163
307
|
*/
|
|
164
308
|
export function sealTransaction(tx_json: string, seal_signer_secret_key: Uint8Array): string;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Derive the recipient's stealth spending scalar `c + k`, where `c = H(network || k.G * r)`. The
|
|
312
|
+
* receiver runs this with their account secret key (`private_key`) and the sender-provided public
|
|
313
|
+
* nonce to obtain the one-time secret that controls the stealth output.
|
|
314
|
+
*
|
|
315
|
+
* `network` is the network byte (0x00 = MainNet, 0x10 = LocalNet, 0x26 = Esmeralda, ...).
|
|
316
|
+
*/
|
|
317
|
+
export function stealthDhSecret(network: number, private_key: Uint8Array, public_nonce: Uint8Array): Uint8Array;
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Decrypt and verify the AEAD payload of an inbound stealth UTXO.
|
|
321
|
+
*
|
|
322
|
+
* `output_commitment` is the 32-byte Pedersen commitment; `encrypted_data` is the variable-length
|
|
323
|
+
* XChaCha20Poly1305-encrypted blob; `encryption_key` is the 32-byte AEAD key derived via
|
|
324
|
+
* `encryptedDataDhKdfAead`. Setting `skip_memo` to `true` returns no memo even if the payload carries
|
|
325
|
+
* one (useful when only the value / mask are needed).
|
|
326
|
+
*
|
|
327
|
+
* Throws on AEAD failure or on a commitment mismatch — either indicates the payload was not produced
|
|
328
|
+
* for this view key.
|
|
329
|
+
*/
|
|
330
|
+
export function unblindOutput(output_commitment: Uint8Array, encrypted_data: Uint8Array, encryption_key: Uint8Array, skip_memo: boolean): DecryptedOutputResult;
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Pre-flight check that a balance proof signature is cryptographically valid for the given input /
|
|
334
|
+
* output statements. Returns `false` on a malformed proof or invalid signature; the engine performs
|
|
335
|
+
* the authoritative check at submission.
|
|
336
|
+
*/
|
|
337
|
+
export function validateBalanceProofSignature(public_nonce: Uint8Array, signature: Uint8Array, inputs_statement_json: string, outputs_statement_json: string): boolean;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Run the same validation the engine performs on a complete `StealthTransferStatement` envelope:
|
|
341
|
+
* structural sanity, commitment well-formedness, range and balance-proof verification.
|
|
342
|
+
*
|
|
343
|
+
* `view_key` is the 32-byte resource view public key, required for resources with a viewable balance
|
|
344
|
+
* and rejected otherwise. Pass `null` for resources without a view key.
|
|
345
|
+
*
|
|
346
|
+
* Throws on a validation failure; returns successfully on a valid statement.
|
|
347
|
+
*/
|
|
348
|
+
export function validateStealthTransfer(transfer_json: string, view_key?: Uint8Array | null): void;
|
package/ootle_wasm.js
CHANGED
|
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./ootle_wasm_bg.js";
|
|
|
5
5
|
__wbg_set_wasm(wasm);
|
|
6
6
|
wasm.__wbindgen_start();
|
|
7
7
|
export {
|
|
8
|
-
KeypairResult, OotlePublicKey, OotleSecretKey, ParsedOotleAddress, SchnorrSignatureResult, addTransactionSigner, borEncodeTransaction, generateKeypair, generateOotleAddress, generateOotleSecretKey, hashUnsignedTransaction, on_start, ootlePublicKeyFromSecretKey, parseOotleAddress, publicKeyFromSecretKey, schnorrSign, sealTransaction
|
|
8
|
+
DecryptedOutputResult, KeypairResult, OotlePublicKey, OotleSecretKey, ParsedOotleAddress, SchnorrSignatureResult, StealthOutputsResult, addTransactionSigner, aggregateInputMasks, borEncodeTransaction, buildStealthInputsStatement, decryptElgamalViewableBalance, encryptedDataDhKdfAead, generateElgamalViewableBalanceProof, generateExtendedBulletProof, generateKeypair, generateOotleAddress, generateOotleSecretKey, generateStealthBalanceProofSignature, generateStealthOutputsStatement, hashUnsignedTransaction, on_start, ootlePublicKeyFromSecretKey, parseOotleAddress, publicKeyFromSecretKey, schnorrSign, sealTransaction, stealthDhSecret, unblindOutput, validateBalanceProofSignature, validateStealthTransfer
|
|
9
9
|
} from "./ootle_wasm_bg.js";
|
package/ootle_wasm_bg.js
CHANGED
|
@@ -1,3 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decrypted contents of an inbound stealth UTXO.
|
|
3
|
+
*/
|
|
4
|
+
export class DecryptedOutputResult {
|
|
5
|
+
static __wrap(ptr) {
|
|
6
|
+
ptr = ptr >>> 0;
|
|
7
|
+
const obj = Object.create(DecryptedOutputResult.prototype);
|
|
8
|
+
obj.__wbg_ptr = ptr;
|
|
9
|
+
DecryptedOutputResultFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
__destroy_into_raw() {
|
|
13
|
+
const ptr = this.__wbg_ptr;
|
|
14
|
+
this.__wbg_ptr = 0;
|
|
15
|
+
DecryptedOutputResultFinalization.unregister(this);
|
|
16
|
+
return ptr;
|
|
17
|
+
}
|
|
18
|
+
free() {
|
|
19
|
+
const ptr = this.__destroy_into_raw();
|
|
20
|
+
wasm.__wbg_decryptedoutputresult_free(ptr, 0);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The 32-byte commitment mask scalar.
|
|
24
|
+
* @returns {Uint8Array}
|
|
25
|
+
*/
|
|
26
|
+
get mask() {
|
|
27
|
+
const ret = wasm.__wbg_get_decryptedoutputresult_mask(this.__wbg_ptr);
|
|
28
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
29
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
30
|
+
return v1;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* JSON-encoded `Memo` (variants: `U256` / `Message` / `Bytes` / `PayRefAndBytes`), or `null` if
|
|
34
|
+
* the payload carried no memo or `skipMemo` was set.
|
|
35
|
+
* @returns {string | undefined}
|
|
36
|
+
*/
|
|
37
|
+
get memo_json() {
|
|
38
|
+
const ret = wasm.__wbg_get_decryptedoutputresult_memo_json(this.__wbg_ptr);
|
|
39
|
+
let v1;
|
|
40
|
+
if (ret[0] !== 0) {
|
|
41
|
+
v1 = getStringFromWasm0(ret[0], ret[1]).slice();
|
|
42
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
43
|
+
}
|
|
44
|
+
return v1;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The plaintext value (u64).
|
|
48
|
+
* @returns {bigint}
|
|
49
|
+
*/
|
|
50
|
+
get value() {
|
|
51
|
+
const ret = wasm.__wbg_get_decryptedoutputresult_value(this.__wbg_ptr);
|
|
52
|
+
return BigInt.asUintN(64, ret);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The 32-byte commitment mask scalar.
|
|
56
|
+
* @param {Uint8Array} arg0
|
|
57
|
+
*/
|
|
58
|
+
set mask(arg0) {
|
|
59
|
+
const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
|
|
60
|
+
const len0 = WASM_VECTOR_LEN;
|
|
61
|
+
wasm.__wbg_set_decryptedoutputresult_mask(this.__wbg_ptr, ptr0, len0);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* JSON-encoded `Memo` (variants: `U256` / `Message` / `Bytes` / `PayRefAndBytes`), or `null` if
|
|
65
|
+
* the payload carried no memo or `skipMemo` was set.
|
|
66
|
+
* @param {string | null} [arg0]
|
|
67
|
+
*/
|
|
68
|
+
set memo_json(arg0) {
|
|
69
|
+
var ptr0 = isLikeNone(arg0) ? 0 : passStringToWasm0(arg0, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
70
|
+
var len0 = WASM_VECTOR_LEN;
|
|
71
|
+
wasm.__wbg_set_decryptedoutputresult_memo_json(this.__wbg_ptr, ptr0, len0);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The plaintext value (u64).
|
|
75
|
+
* @param {bigint} arg0
|
|
76
|
+
*/
|
|
77
|
+
set value(arg0) {
|
|
78
|
+
wasm.__wbg_set_decryptedoutputresult_value(this.__wbg_ptr, arg0);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (Symbol.dispose) DecryptedOutputResult.prototype[Symbol.dispose] = DecryptedOutputResult.prototype.free;
|
|
82
|
+
|
|
1
83
|
/**
|
|
2
84
|
* A generated keypair (raw bytes).
|
|
3
85
|
*/
|
|
@@ -280,7 +362,8 @@ export class ParsedOotleAddress {
|
|
|
280
362
|
if (Symbol.dispose) ParsedOotleAddress.prototype[Symbol.dispose] = ParsedOotleAddress.prototype.free;
|
|
281
363
|
|
|
282
364
|
/**
|
|
283
|
-
* Result of a Schnorr signature operation (raw bytes).
|
|
365
|
+
* Result of a Schnorr signature operation (raw bytes). Also used for balance proof signatures, which
|
|
366
|
+
* share the `(public_nonce, signature)` shape.
|
|
284
367
|
*/
|
|
285
368
|
export class SchnorrSignatureResult {
|
|
286
369
|
static __wrap(ptr) {
|
|
@@ -337,6 +420,76 @@ export class SchnorrSignatureResult {
|
|
|
337
420
|
}
|
|
338
421
|
if (Symbol.dispose) SchnorrSignatureResult.prototype[Symbol.dispose] = SchnorrSignatureResult.prototype.free;
|
|
339
422
|
|
|
423
|
+
/**
|
|
424
|
+
* Result of generating a stealth outputs statement.
|
|
425
|
+
*/
|
|
426
|
+
export class StealthOutputsResult {
|
|
427
|
+
static __wrap(ptr) {
|
|
428
|
+
ptr = ptr >>> 0;
|
|
429
|
+
const obj = Object.create(StealthOutputsResult.prototype);
|
|
430
|
+
obj.__wbg_ptr = ptr;
|
|
431
|
+
StealthOutputsResultFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
432
|
+
return obj;
|
|
433
|
+
}
|
|
434
|
+
__destroy_into_raw() {
|
|
435
|
+
const ptr = this.__wbg_ptr;
|
|
436
|
+
this.__wbg_ptr = 0;
|
|
437
|
+
StealthOutputsResultFinalization.unregister(this);
|
|
438
|
+
return ptr;
|
|
439
|
+
}
|
|
440
|
+
free() {
|
|
441
|
+
const ptr = this.__destroy_into_raw();
|
|
442
|
+
wasm.__wbg_stealthoutputsresult_free(ptr, 0);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Sum of all witness masks, suitable for use as the `aggregated_output_mask` argument to
|
|
446
|
+
* `generateStealthBalanceProofSignature`.
|
|
447
|
+
* @returns {Uint8Array}
|
|
448
|
+
*/
|
|
449
|
+
get aggregated_output_mask() {
|
|
450
|
+
const ret = wasm.__wbg_get_stealthoutputsresult_aggregated_output_mask(this.__wbg_ptr);
|
|
451
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
452
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
453
|
+
return v1;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* JSON-serialized `StealthOutputsStatement` (the wire-format payload).
|
|
457
|
+
* @returns {string}
|
|
458
|
+
*/
|
|
459
|
+
get statement_json() {
|
|
460
|
+
let deferred1_0;
|
|
461
|
+
let deferred1_1;
|
|
462
|
+
try {
|
|
463
|
+
const ret = wasm.__wbg_get_stealthoutputsresult_statement_json(this.__wbg_ptr);
|
|
464
|
+
deferred1_0 = ret[0];
|
|
465
|
+
deferred1_1 = ret[1];
|
|
466
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
467
|
+
} finally {
|
|
468
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Sum of all witness masks, suitable for use as the `aggregated_output_mask` argument to
|
|
473
|
+
* `generateStealthBalanceProofSignature`.
|
|
474
|
+
* @param {Uint8Array} arg0
|
|
475
|
+
*/
|
|
476
|
+
set aggregated_output_mask(arg0) {
|
|
477
|
+
const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
|
|
478
|
+
const len0 = WASM_VECTOR_LEN;
|
|
479
|
+
wasm.__wbg_set_keypairresult_public_key(this.__wbg_ptr, ptr0, len0);
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* JSON-serialized `StealthOutputsStatement` (the wire-format payload).
|
|
483
|
+
* @param {string} arg0
|
|
484
|
+
*/
|
|
485
|
+
set statement_json(arg0) {
|
|
486
|
+
const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
487
|
+
const len0 = WASM_VECTOR_LEN;
|
|
488
|
+
wasm.__wbg_set_keypairresult_secret_key(this.__wbg_ptr, ptr0, len0);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
if (Symbol.dispose) StealthOutputsResult.prototype[Symbol.dispose] = StealthOutputsResult.prototype.free;
|
|
492
|
+
|
|
340
493
|
/**
|
|
341
494
|
* Add a signer to a transaction (unsigned or unsealed JSON).
|
|
342
495
|
*
|
|
@@ -372,6 +525,30 @@ export function addTransactionSigner(tx_json, signer_secret_key, seal_signer_pub
|
|
|
372
525
|
}
|
|
373
526
|
}
|
|
374
527
|
|
|
528
|
+
/**
|
|
529
|
+
* Aggregate the commitment masks of stealth inputs into a single 32-byte Ristretto scalar.
|
|
530
|
+
*
|
|
531
|
+
* `masks_concat` is the concatenated bytes of all input masks (32 bytes per mask, so the input
|
|
532
|
+
* length must be a multiple of 32). Pass an empty array to obtain the zero scalar.
|
|
533
|
+
*
|
|
534
|
+
* Returns the sum as 32 bytes, suitable as the `aggregated_input_mask` argument to
|
|
535
|
+
* `generateStealthBalanceProofSignature`. The output side of the same balance proof is aggregated
|
|
536
|
+
* automatically by `generateStealthOutputsStatement` (returned as `aggregated_output_mask`).
|
|
537
|
+
* @param {Uint8Array} masks_concat
|
|
538
|
+
* @returns {Uint8Array}
|
|
539
|
+
*/
|
|
540
|
+
export function aggregateInputMasks(masks_concat) {
|
|
541
|
+
const ptr0 = passArray8ToWasm0(masks_concat, wasm.__wbindgen_malloc);
|
|
542
|
+
const len0 = WASM_VECTOR_LEN;
|
|
543
|
+
const ret = wasm.aggregateInputMasks(ptr0, len0);
|
|
544
|
+
if (ret[3]) {
|
|
545
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
546
|
+
}
|
|
547
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
548
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
549
|
+
return v2;
|
|
550
|
+
}
|
|
551
|
+
|
|
375
552
|
/**
|
|
376
553
|
* BOR-encode a Transaction (JSON string) → base64 string (TransactionEnvelope format).
|
|
377
554
|
* @param {string} transaction_json
|
|
@@ -398,6 +575,155 @@ export function borEncodeTransaction(transaction_json) {
|
|
|
398
575
|
}
|
|
399
576
|
}
|
|
400
577
|
|
|
578
|
+
/**
|
|
579
|
+
* Build a `StealthInputsStatement` JSON from raw input commitments and a revealed amount.
|
|
580
|
+
*
|
|
581
|
+
* `input_commitments` is the concatenated bytes of all 32-byte commitments (so the length must be a
|
|
582
|
+
* multiple of 32). Pass an empty array for a revealed-only statement.
|
|
583
|
+
*
|
|
584
|
+
* This is a convenience helper so callers don't need to hand-craft the wire JSON; the result is used
|
|
585
|
+
* as the `inputs_statement_json` argument to `generateStealthBalanceProofSignature` and friends.
|
|
586
|
+
* @param {Uint8Array} input_commitments
|
|
587
|
+
* @param {bigint} revealed_amount_microtari
|
|
588
|
+
* @returns {string}
|
|
589
|
+
*/
|
|
590
|
+
export function buildStealthInputsStatement(input_commitments, revealed_amount_microtari) {
|
|
591
|
+
let deferred3_0;
|
|
592
|
+
let deferred3_1;
|
|
593
|
+
try {
|
|
594
|
+
const ptr0 = passArray8ToWasm0(input_commitments, wasm.__wbindgen_malloc);
|
|
595
|
+
const len0 = WASM_VECTOR_LEN;
|
|
596
|
+
const ret = wasm.buildStealthInputsStatement(ptr0, len0, revealed_amount_microtari);
|
|
597
|
+
var ptr2 = ret[0];
|
|
598
|
+
var len2 = ret[1];
|
|
599
|
+
if (ret[3]) {
|
|
600
|
+
ptr2 = 0; len2 = 0;
|
|
601
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
602
|
+
}
|
|
603
|
+
deferred3_0 = ptr2;
|
|
604
|
+
deferred3_1 = len2;
|
|
605
|
+
return getStringFromWasm0(ptr2, len2);
|
|
606
|
+
} finally {
|
|
607
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Brute-force decrypt an ElGamal viewable-balance proof to recover the bound value.
|
|
613
|
+
*
|
|
614
|
+
* Tries each value in `[min_value, max_value]` (inclusive). Returns `null` (via `Option`) if no
|
|
615
|
+
* candidate matches. Uses an on-the-fly value lookup — there is no precomputed table dependency, so
|
|
616
|
+
* callers should keep the range tight (large ranges produce proportional CPU cost).
|
|
617
|
+
*
|
|
618
|
+
* `commitment` is the Pedersen commitment the proof is bound to. Both the view public key and the
|
|
619
|
+
* view secret key are required: the public key is used to re-verify the ZK proof (rejecting tampered
|
|
620
|
+
* proofs before decrypting), the secret key performs the ElGamal decryption itself.
|
|
621
|
+
* @param {string} proof_json
|
|
622
|
+
* @param {Uint8Array} commitment
|
|
623
|
+
* @param {Uint8Array} view_public_key
|
|
624
|
+
* @param {Uint8Array} view_secret_key
|
|
625
|
+
* @param {bigint} min_value
|
|
626
|
+
* @param {bigint} max_value
|
|
627
|
+
* @returns {bigint | undefined}
|
|
628
|
+
*/
|
|
629
|
+
export function decryptElgamalViewableBalance(proof_json, commitment, view_public_key, view_secret_key, min_value, max_value) {
|
|
630
|
+
const ptr0 = passStringToWasm0(proof_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
631
|
+
const len0 = WASM_VECTOR_LEN;
|
|
632
|
+
const ptr1 = passArray8ToWasm0(commitment, wasm.__wbindgen_malloc);
|
|
633
|
+
const len1 = WASM_VECTOR_LEN;
|
|
634
|
+
const ptr2 = passArray8ToWasm0(view_public_key, wasm.__wbindgen_malloc);
|
|
635
|
+
const len2 = WASM_VECTOR_LEN;
|
|
636
|
+
const ptr3 = passArray8ToWasm0(view_secret_key, wasm.__wbindgen_malloc);
|
|
637
|
+
const len3 = WASM_VECTOR_LEN;
|
|
638
|
+
const ret = wasm.decryptElgamalViewableBalance(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, min_value, max_value);
|
|
639
|
+
if (ret[3]) {
|
|
640
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
641
|
+
}
|
|
642
|
+
return ret[0] === 0 ? undefined : BigInt.asUintN(64, ret[1]);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Derive the AEAD encryption key for `encrypted_data` from a Diffie-Hellman shared secret: `H(DH(s, P))`.
|
|
647
|
+
* Sender derives it with `(sender_secret_nonce, recipient_view_pub)`; receiver derives the same key
|
|
648
|
+
* with `(recipient_view_secret, sender_public_nonce)`.
|
|
649
|
+
* @param {Uint8Array} private_key
|
|
650
|
+
* @param {Uint8Array} public_key
|
|
651
|
+
* @returns {Uint8Array}
|
|
652
|
+
*/
|
|
653
|
+
export function encryptedDataDhKdfAead(private_key, public_key) {
|
|
654
|
+
const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
|
|
655
|
+
const len0 = WASM_VECTOR_LEN;
|
|
656
|
+
const ptr1 = passArray8ToWasm0(public_key, wasm.__wbindgen_malloc);
|
|
657
|
+
const len1 = WASM_VECTOR_LEN;
|
|
658
|
+
const ret = wasm.encryptedDataDhKdfAead(ptr0, len0, ptr1, len1);
|
|
659
|
+
if (ret[3]) {
|
|
660
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
661
|
+
}
|
|
662
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
663
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
664
|
+
return v3;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Generate an ElGamal viewable-balance proof: a zero-knowledge proof that `amount` is the value bound
|
|
669
|
+
* by `commitment`, encrypted to the resource view-key holder.
|
|
670
|
+
*
|
|
671
|
+
* Returns the JSON-encoded `ViewableBalanceProof` (8 × 32-byte fields).
|
|
672
|
+
* @param {Uint8Array} mask
|
|
673
|
+
* @param {bigint} amount
|
|
674
|
+
* @param {Uint8Array} commitment
|
|
675
|
+
* @param {Uint8Array} view_public_key
|
|
676
|
+
* @returns {string}
|
|
677
|
+
*/
|
|
678
|
+
export function generateElgamalViewableBalanceProof(mask, amount, commitment, view_public_key) {
|
|
679
|
+
let deferred5_0;
|
|
680
|
+
let deferred5_1;
|
|
681
|
+
try {
|
|
682
|
+
const ptr0 = passArray8ToWasm0(mask, wasm.__wbindgen_malloc);
|
|
683
|
+
const len0 = WASM_VECTOR_LEN;
|
|
684
|
+
const ptr1 = passArray8ToWasm0(commitment, wasm.__wbindgen_malloc);
|
|
685
|
+
const len1 = WASM_VECTOR_LEN;
|
|
686
|
+
const ptr2 = passArray8ToWasm0(view_public_key, wasm.__wbindgen_malloc);
|
|
687
|
+
const len2 = WASM_VECTOR_LEN;
|
|
688
|
+
const ret = wasm.generateElgamalViewableBalanceProof(ptr0, len0, amount, ptr1, len1, ptr2, len2);
|
|
689
|
+
var ptr4 = ret[0];
|
|
690
|
+
var len4 = ret[1];
|
|
691
|
+
if (ret[3]) {
|
|
692
|
+
ptr4 = 0; len4 = 0;
|
|
693
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
694
|
+
}
|
|
695
|
+
deferred5_0 = ptr4;
|
|
696
|
+
deferred5_1 = len4;
|
|
697
|
+
return getStringFromWasm0(ptr4, len4);
|
|
698
|
+
} finally {
|
|
699
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* Generate an extended bulletproof aggregating range proofs for a set of output witnesses, proving
|
|
705
|
+
* each amount is in `[minimum_value_promise, 2^64)`. The number of witnesses is padded to the next
|
|
706
|
+
* power of two internally.
|
|
707
|
+
*
|
|
708
|
+
* `witnesses_json` is a JSON array of "flat" output witnesses (the `witness` field shape from
|
|
709
|
+
* [`generate_stealth_outputs_statement`] — without the surrounding `spend_condition` / `tag`).
|
|
710
|
+
*
|
|
711
|
+
* Returns the raw range proof bytes (may be empty if the input array is empty).
|
|
712
|
+
* @param {string} witnesses_json
|
|
713
|
+
* @returns {Uint8Array}
|
|
714
|
+
*/
|
|
715
|
+
export function generateExtendedBulletProof(witnesses_json) {
|
|
716
|
+
const ptr0 = passStringToWasm0(witnesses_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
717
|
+
const len0 = WASM_VECTOR_LEN;
|
|
718
|
+
const ret = wasm.generateExtendedBulletProof(ptr0, len0);
|
|
719
|
+
if (ret[3]) {
|
|
720
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
721
|
+
}
|
|
722
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
723
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
724
|
+
return v2;
|
|
725
|
+
}
|
|
726
|
+
|
|
401
727
|
/**
|
|
402
728
|
* Generate a new random Ristretto keypair.
|
|
403
729
|
* Returns { secret_key: Uint8Array, public_key: Uint8Array }.
|
|
@@ -454,6 +780,71 @@ export function generateOotleSecretKey() {
|
|
|
454
780
|
return OotleSecretKey.__wrap(ret);
|
|
455
781
|
}
|
|
456
782
|
|
|
783
|
+
/**
|
|
784
|
+
* Sign the balance proof for a stealth transfer.
|
|
785
|
+
*
|
|
786
|
+
* `aggregated_input_mask` and `aggregated_output_mask` are the 32-byte sums of all input / output
|
|
787
|
+
* commitment masks respectively. Returns a `(public_nonce, signature)` pair (each 32 bytes); the pair
|
|
788
|
+
* may be all-zeros for revealed-only transfers — callers normally omit the balance proof in that case.
|
|
789
|
+
* @param {Uint8Array} aggregated_input_mask
|
|
790
|
+
* @param {Uint8Array} aggregated_output_mask
|
|
791
|
+
* @param {string} inputs_statement_json
|
|
792
|
+
* @param {string} outputs_statement_json
|
|
793
|
+
* @returns {SchnorrSignatureResult}
|
|
794
|
+
*/
|
|
795
|
+
export function generateStealthBalanceProofSignature(aggregated_input_mask, aggregated_output_mask, inputs_statement_json, outputs_statement_json) {
|
|
796
|
+
const ptr0 = passArray8ToWasm0(aggregated_input_mask, wasm.__wbindgen_malloc);
|
|
797
|
+
const len0 = WASM_VECTOR_LEN;
|
|
798
|
+
const ptr1 = passArray8ToWasm0(aggregated_output_mask, wasm.__wbindgen_malloc);
|
|
799
|
+
const len1 = WASM_VECTOR_LEN;
|
|
800
|
+
const ptr2 = passStringToWasm0(inputs_statement_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
801
|
+
const len2 = WASM_VECTOR_LEN;
|
|
802
|
+
const ptr3 = passStringToWasm0(outputs_statement_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
803
|
+
const len3 = WASM_VECTOR_LEN;
|
|
804
|
+
const ret = wasm.generateStealthBalanceProofSignature(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
805
|
+
if (ret[2]) {
|
|
806
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
807
|
+
}
|
|
808
|
+
return SchnorrSignatureResult.__wrap(ret[0]);
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
/**
|
|
812
|
+
* Generate the output side of a stealth transfer: per-output Pedersen commitments and encrypted data,
|
|
813
|
+
* optional ElGamal viewable-balance proofs (for outputs with a `resource_view_key`), and an aggregated
|
|
814
|
+
* bulletproof range proof.
|
|
815
|
+
*
|
|
816
|
+
* `witnesses_json` is a JSON array of stealth output witnesses. Each entry has the shape:
|
|
817
|
+
* ```text
|
|
818
|
+
* {
|
|
819
|
+
* "witness": {
|
|
820
|
+
* "amount": <u64>,
|
|
821
|
+
* "mask": <hex 32 bytes>,
|
|
822
|
+
* "sender_public_nonce": <hex 32 bytes>,
|
|
823
|
+
* "minimum_value_promise": <u64>,
|
|
824
|
+
* "encrypted_data": <hex variable-length>,
|
|
825
|
+
* "resource_view_key": <hex 32 bytes | null>
|
|
826
|
+
* },
|
|
827
|
+
* "spend_condition": <SpendCondition>,
|
|
828
|
+
* "tag": <u32>
|
|
829
|
+
* }
|
|
830
|
+
* ```
|
|
831
|
+
*
|
|
832
|
+
* Returns the serialized statement plus the aggregated output mask, which the sender feeds to
|
|
833
|
+
* `generateStealthBalanceProofSignature` together with the aggregated input mask.
|
|
834
|
+
* @param {string} witnesses_json
|
|
835
|
+
* @param {bigint} revealed_output_amount_microtari
|
|
836
|
+
* @returns {StealthOutputsResult}
|
|
837
|
+
*/
|
|
838
|
+
export function generateStealthOutputsStatement(witnesses_json, revealed_output_amount_microtari) {
|
|
839
|
+
const ptr0 = passStringToWasm0(witnesses_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
840
|
+
const len0 = WASM_VECTOR_LEN;
|
|
841
|
+
const ret = wasm.generateStealthOutputsStatement(ptr0, len0, revealed_output_amount_microtari);
|
|
842
|
+
if (ret[2]) {
|
|
843
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
844
|
+
}
|
|
845
|
+
return StealthOutputsResult.__wrap(ret[0]);
|
|
846
|
+
}
|
|
847
|
+
|
|
457
848
|
/**
|
|
458
849
|
* Hash an UnsignedTransactionV1 (JSON string) for signing.
|
|
459
850
|
* Returns the 64-byte signing message that must be Schnorr-signed.
|
|
@@ -586,113 +977,119 @@ export function sealTransaction(tx_json, seal_signer_secret_key) {
|
|
|
586
977
|
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
587
978
|
}
|
|
588
979
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* Derive the recipient's stealth spending scalar `c + k`, where `c = H(network || k.G * r)`. The
|
|
983
|
+
* receiver runs this with their account secret key (`private_key`) and the sender-provided public
|
|
984
|
+
* nonce to obtain the one-time secret that controls the stealth output.
|
|
985
|
+
*
|
|
986
|
+
* `network` is the network byte (0x00 = MainNet, 0x10 = LocalNet, 0x26 = Esmeralda, ...).
|
|
987
|
+
* @param {number} network
|
|
988
|
+
* @param {Uint8Array} private_key
|
|
989
|
+
* @param {Uint8Array} public_nonce
|
|
990
|
+
* @returns {Uint8Array}
|
|
991
|
+
*/
|
|
992
|
+
export function stealthDhSecret(network, private_key, public_nonce) {
|
|
993
|
+
const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
|
|
994
|
+
const len0 = WASM_VECTOR_LEN;
|
|
995
|
+
const ptr1 = passArray8ToWasm0(public_nonce, wasm.__wbindgen_malloc);
|
|
996
|
+
const len1 = WASM_VECTOR_LEN;
|
|
997
|
+
const ret = wasm.stealthDhSecret(network, ptr0, len0, ptr1, len1);
|
|
998
|
+
if (ret[3]) {
|
|
999
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
1000
|
+
}
|
|
1001
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
1002
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
1003
|
+
return v3;
|
|
592
1004
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
1005
|
+
|
|
1006
|
+
/**
|
|
1007
|
+
* Decrypt and verify the AEAD payload of an inbound stealth UTXO.
|
|
1008
|
+
*
|
|
1009
|
+
* `output_commitment` is the 32-byte Pedersen commitment; `encrypted_data` is the variable-length
|
|
1010
|
+
* XChaCha20Poly1305-encrypted blob; `encryption_key` is the 32-byte AEAD key derived via
|
|
1011
|
+
* `encryptedDataDhKdfAead`. Setting `skip_memo` to `true` returns no memo even if the payload carries
|
|
1012
|
+
* one (useful when only the value / mask are needed).
|
|
1013
|
+
*
|
|
1014
|
+
* Throws on AEAD failure or on a commitment mismatch — either indicates the payload was not produced
|
|
1015
|
+
* for this view key.
|
|
1016
|
+
* @param {Uint8Array} output_commitment
|
|
1017
|
+
* @param {Uint8Array} encrypted_data
|
|
1018
|
+
* @param {Uint8Array} encryption_key
|
|
1019
|
+
* @param {boolean} skip_memo
|
|
1020
|
+
* @returns {DecryptedOutputResult}
|
|
1021
|
+
*/
|
|
1022
|
+
export function unblindOutput(output_commitment, encrypted_data, encryption_key, skip_memo) {
|
|
1023
|
+
const ptr0 = passArray8ToWasm0(output_commitment, wasm.__wbindgen_malloc);
|
|
1024
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1025
|
+
const ptr1 = passArray8ToWasm0(encrypted_data, wasm.__wbindgen_malloc);
|
|
1026
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1027
|
+
const ptr2 = passArray8ToWasm0(encryption_key, wasm.__wbindgen_malloc);
|
|
1028
|
+
const len2 = WASM_VECTOR_LEN;
|
|
1029
|
+
const ret = wasm.unblindOutput(ptr0, len0, ptr1, len1, ptr2, len2, skip_memo);
|
|
1030
|
+
if (ret[2]) {
|
|
1031
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
1032
|
+
}
|
|
1033
|
+
return DecryptedOutputResult.__wrap(ret[0]);
|
|
596
1034
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* Pre-flight check that a balance proof signature is cryptographically valid for the given input /
|
|
1038
|
+
* output statements. Returns `false` on a malformed proof or invalid signature; the engine performs
|
|
1039
|
+
* the authoritative check at submission.
|
|
1040
|
+
* @param {Uint8Array} public_nonce
|
|
1041
|
+
* @param {Uint8Array} signature
|
|
1042
|
+
* @param {string} inputs_statement_json
|
|
1043
|
+
* @param {string} outputs_statement_json
|
|
1044
|
+
* @returns {boolean}
|
|
1045
|
+
*/
|
|
1046
|
+
export function validateBalanceProofSignature(public_nonce, signature, inputs_statement_json, outputs_statement_json) {
|
|
1047
|
+
const ptr0 = passArray8ToWasm0(public_nonce, wasm.__wbindgen_malloc);
|
|
1048
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1049
|
+
const ptr1 = passArray8ToWasm0(signature, wasm.__wbindgen_malloc);
|
|
1050
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1051
|
+
const ptr2 = passStringToWasm0(inputs_statement_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1052
|
+
const len2 = WASM_VECTOR_LEN;
|
|
1053
|
+
const ptr3 = passStringToWasm0(outputs_statement_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1054
|
+
const len3 = WASM_VECTOR_LEN;
|
|
1055
|
+
const ret = wasm.validateBalanceProofSignature(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
1056
|
+
if (ret[2]) {
|
|
1057
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
1058
|
+
}
|
|
1059
|
+
return ret[0] !== 0;
|
|
601
1060
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
1061
|
+
|
|
1062
|
+
/**
|
|
1063
|
+
* Run the same validation the engine performs on a complete `StealthTransferStatement` envelope:
|
|
1064
|
+
* structural sanity, commitment well-formedness, range and balance-proof verification.
|
|
1065
|
+
*
|
|
1066
|
+
* `view_key` is the 32-byte resource view public key, required for resources with a viewable balance
|
|
1067
|
+
* and rejected otherwise. Pass `null` for resources without a view key.
|
|
1068
|
+
*
|
|
1069
|
+
* Throws on a validation failure; returns successfully on a valid statement.
|
|
1070
|
+
* @param {string} transfer_json
|
|
1071
|
+
* @param {Uint8Array | null} [view_key]
|
|
1072
|
+
*/
|
|
1073
|
+
export function validateStealthTransfer(transfer_json, view_key) {
|
|
1074
|
+
const ptr0 = passStringToWasm0(transfer_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1075
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1076
|
+
var ptr1 = isLikeNone(view_key) ? 0 : passArray8ToWasm0(view_key, wasm.__wbindgen_malloc);
|
|
1077
|
+
var len1 = WASM_VECTOR_LEN;
|
|
1078
|
+
const ret = wasm.validateStealthTransfer(ptr0, len0, ptr1, len1);
|
|
1079
|
+
if (ret[1]) {
|
|
1080
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
1081
|
+
}
|
|
605
1082
|
}
|
|
606
|
-
export function
|
|
607
|
-
const ret = arg0
|
|
1083
|
+
export function __wbg_Error_8c4e43fe74559d73(arg0, arg1) {
|
|
1084
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
608
1085
|
return ret;
|
|
609
1086
|
}
|
|
610
1087
|
export function __wbg___wbindgen_throw_be289d5034ed271b(arg0, arg1) {
|
|
611
1088
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
612
1089
|
}
|
|
613
|
-
export function
|
|
614
|
-
|
|
615
|
-
return ret;
|
|
616
|
-
}, arguments); }
|
|
617
|
-
export function __wbg_call_4708e0c13bdc8e95() { return handleError(function (arg0, arg1, arg2) {
|
|
618
|
-
const ret = arg0.call(arg1, arg2);
|
|
619
|
-
return ret;
|
|
620
|
-
}, arguments); }
|
|
621
|
-
export function __wbg_crypto_86f2631e91b51511(arg0) {
|
|
622
|
-
const ret = arg0.crypto;
|
|
623
|
-
return ret;
|
|
624
|
-
}
|
|
625
|
-
export function __wbg_getRandomValues_b3f15fcbfabb0f8b() { return handleError(function (arg0, arg1) {
|
|
626
|
-
arg0.getRandomValues(arg1);
|
|
627
|
-
}, arguments); }
|
|
628
|
-
export function __wbg_length_32ed9a279acd054c(arg0) {
|
|
629
|
-
const ret = arg0.length;
|
|
630
|
-
return ret;
|
|
631
|
-
}
|
|
632
|
-
export function __wbg_msCrypto_d562bbe83e0d4b91(arg0) {
|
|
633
|
-
const ret = arg0.msCrypto;
|
|
634
|
-
return ret;
|
|
635
|
-
}
|
|
636
|
-
export function __wbg_new_no_args_1c7c842f08d00ebb(arg0, arg1) {
|
|
637
|
-
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
638
|
-
return ret;
|
|
639
|
-
}
|
|
640
|
-
export function __wbg_new_with_length_a2c39cbe88fd8ff1(arg0) {
|
|
641
|
-
const ret = new Uint8Array(arg0 >>> 0);
|
|
642
|
-
return ret;
|
|
643
|
-
}
|
|
644
|
-
export function __wbg_node_e1f24f89a7336c2e(arg0) {
|
|
645
|
-
const ret = arg0.node;
|
|
646
|
-
return ret;
|
|
647
|
-
}
|
|
648
|
-
export function __wbg_process_3975fd6c72f520aa(arg0) {
|
|
649
|
-
const ret = arg0.process;
|
|
650
|
-
return ret;
|
|
651
|
-
}
|
|
652
|
-
export function __wbg_prototypesetcall_bdcdcc5842e4d77d(arg0, arg1, arg2) {
|
|
653
|
-
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
654
|
-
}
|
|
655
|
-
export function __wbg_randomFillSync_f8c153b79f285817() { return handleError(function (arg0, arg1) {
|
|
656
|
-
arg0.randomFillSync(arg1);
|
|
1090
|
+
export function __wbg_getRandomValues_e9de607763a970bd() { return handleError(function (arg0, arg1) {
|
|
1091
|
+
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
657
1092
|
}, arguments); }
|
|
658
|
-
export function __wbg_require_b74f47fc2d022fd6() { return handleError(function () {
|
|
659
|
-
const ret = module.require;
|
|
660
|
-
return ret;
|
|
661
|
-
}, arguments); }
|
|
662
|
-
export function __wbg_static_accessor_GLOBAL_12837167ad935116() {
|
|
663
|
-
const ret = typeof global === 'undefined' ? null : global;
|
|
664
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
665
|
-
}
|
|
666
|
-
export function __wbg_static_accessor_GLOBAL_THIS_e628e89ab3b1c95f() {
|
|
667
|
-
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
668
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
669
|
-
}
|
|
670
|
-
export function __wbg_static_accessor_SELF_a621d3dfbb60d0ce() {
|
|
671
|
-
const ret = typeof self === 'undefined' ? null : self;
|
|
672
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
673
|
-
}
|
|
674
|
-
export function __wbg_static_accessor_WINDOW_f8727f0cf888e0bd() {
|
|
675
|
-
const ret = typeof window === 'undefined' ? null : window;
|
|
676
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
677
|
-
}
|
|
678
|
-
export function __wbg_subarray_a96e1fef17ed23cb(arg0, arg1, arg2) {
|
|
679
|
-
const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
|
680
|
-
return ret;
|
|
681
|
-
}
|
|
682
|
-
export function __wbg_versions_4e31226f5e8dc909(arg0) {
|
|
683
|
-
const ret = arg0.versions;
|
|
684
|
-
return ret;
|
|
685
|
-
}
|
|
686
|
-
export function __wbindgen_cast_0000000000000001(arg0, arg1) {
|
|
687
|
-
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
|
|
688
|
-
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
689
|
-
return ret;
|
|
690
|
-
}
|
|
691
|
-
export function __wbindgen_cast_0000000000000002(arg0, arg1) {
|
|
692
|
-
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
693
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
694
|
-
return ret;
|
|
695
|
-
}
|
|
696
1093
|
export function __wbindgen_init_externref_table() {
|
|
697
1094
|
const table = wasm.__wbindgen_externrefs;
|
|
698
1095
|
const offset = table.grow(4);
|
|
@@ -702,6 +1099,9 @@ export function __wbindgen_init_externref_table() {
|
|
|
702
1099
|
table.set(offset + 2, true);
|
|
703
1100
|
table.set(offset + 3, false);
|
|
704
1101
|
}
|
|
1102
|
+
const DecryptedOutputResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1103
|
+
? { register: () => {}, unregister: () => {} }
|
|
1104
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_decryptedoutputresult_free(ptr >>> 0, 1));
|
|
705
1105
|
const KeypairResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
706
1106
|
? { register: () => {}, unregister: () => {} }
|
|
707
1107
|
: new FinalizationRegistry(ptr => wasm.__wbg_keypairresult_free(ptr >>> 0, 1));
|
|
@@ -717,6 +1117,9 @@ const ParsedOotleAddressFinalization = (typeof FinalizationRegistry === 'undefin
|
|
|
717
1117
|
const SchnorrSignatureResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
718
1118
|
? { register: () => {}, unregister: () => {} }
|
|
719
1119
|
: new FinalizationRegistry(ptr => wasm.__wbg_schnorrsignatureresult_free(ptr >>> 0, 1));
|
|
1120
|
+
const StealthOutputsResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1121
|
+
? { register: () => {}, unregister: () => {} }
|
|
1122
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_stealthoutputsresult_free(ptr >>> 0, 1));
|
|
720
1123
|
|
|
721
1124
|
function addToExternrefTable0(obj) {
|
|
722
1125
|
const idx = wasm.__externref_table_alloc();
|
package/ootle_wasm_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"The Tari Development Community"
|
|
6
6
|
],
|
|
7
7
|
"description": "WASM bindings for Tari Ootle client-side crypto — thin wasm-bindgen shell over ootle-wasm-core",
|
|
8
|
-
"version": "0.
|
|
8
|
+
"version": "0.31.0",
|
|
9
9
|
"license": "BSD-3-Clause",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -27,4 +27,4 @@
|
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
}
|
|
30
|
-
}
|
|
30
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
BSD 3-Clause License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2019, The Tari Developer Community
|
|
4
|
-
All rights reserved.
|
|
5
|
-
|
|
6
|
-
Redistribution and use in source and binary forms, with or without
|
|
7
|
-
modification, are permitted provided that the following conditions are met:
|
|
8
|
-
|
|
9
|
-
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
-
list of conditions and the following disclaimer.
|
|
11
|
-
|
|
12
|
-
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
-
this list of conditions and the following disclaimer in the documentation
|
|
14
|
-
and/or other materials provided with the distribution.
|
|
15
|
-
|
|
16
|
-
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
-
contributors may be used to endorse or promote products derived from
|
|
18
|
-
this software without specific prior written permission.
|
|
19
|
-
|
|
20
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|