@clawdstrike/wasm 0.1.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/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # @backbay/wasm
2
+
3
+ WebAssembly bindings for clawdstrike cryptographic verification.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @backbay/wasm
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Browser (ES Modules)
14
+
15
+ ```javascript
16
+ import init, {
17
+ verify_ed25519,
18
+ hash_sha256,
19
+ hash_keccak256,
20
+ verify_receipt,
21
+ verify_merkle_proof
22
+ } from '@backbay/wasm';
23
+
24
+ // Initialize WASM module (required once)
25
+ await init();
26
+
27
+ // Hash data
28
+ const hash = hash_sha256(new TextEncoder().encode('hello'));
29
+ console.log(hash); // 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
30
+
31
+ // Verify Ed25519 signature
32
+ const valid = verify_ed25519(publicKeyHex, messageBytes, signatureHex);
33
+
34
+ // Verify a signed receipt
35
+ const result = verify_receipt(receiptJson, signerPubkeyHex, null);
36
+ console.log(result.valid, result.signer_valid);
37
+ ```
38
+
39
+ ### Node.js
40
+
41
+ ```javascript
42
+ const { verify_ed25519, hash_sha256 } = require('@backbay/wasm');
43
+
44
+ const hash = hash_sha256(Buffer.from('hello'));
45
+ ```
46
+
47
+ ## API
48
+
49
+ ### Hashing
50
+
51
+ - `hash_sha256(data: Uint8Array): string` - SHA-256 hash (hex, no prefix)
52
+ - `hash_sha256_prefixed(data: Uint8Array): string` - SHA-256 hash (hex, 0x prefix)
53
+ - `hash_keccak256(data: Uint8Array): string` - Keccak-256 hash (hex, 0x prefix)
54
+
55
+ ### Signatures
56
+
57
+ - `verify_ed25519(pubkey_hex: string, message: Uint8Array, sig_hex: string): boolean`
58
+
59
+ ### Receipts
60
+
61
+ - `verify_receipt(receipt_json: string, signer_pubkey_hex: string, cosigner_pubkey_hex?: string): VerificationResult`
62
+ - `hash_receipt(receipt_json: string, algorithm: "sha256" | "keccak256"): string`
63
+ - `get_canonical_json(receipt_json: string): string`
64
+
65
+ ### Merkle Trees
66
+
67
+ - `verify_merkle_proof(leaf_hash_hex: string, proof_json: string, root_hex: string): boolean`
68
+ - `compute_merkle_root(leaf_hashes_json: string): string`
69
+ - `generate_merkle_proof(leaf_hashes_json: string, leaf_index: number): string`
70
+
71
+ ## Bundle Size
72
+
73
+ - Uncompressed: ~268KB
74
+ - Gzipped: ~90KB
75
+
76
+ The WASM binary is automatically loaded when you call `init()`.
77
+
78
+ ## TypeScript
79
+
80
+ Full TypeScript definitions are included. The `VerificationResult` type:
81
+
82
+ ```typescript
83
+ interface VerificationResult {
84
+ valid: boolean;
85
+ signer_valid: boolean;
86
+ cosigner_valid: boolean | null;
87
+ errors: string[];
88
+ }
89
+ ```
90
+
91
+ ## License
92
+
93
+ MIT
package/hush_wasm.d.ts ADDED
@@ -0,0 +1,127 @@
1
+ /**
2
+ * TypeScript type definitions for @clawdstrike/wasm
3
+ *
4
+ * These augment the auto-generated wasm-bindgen types with
5
+ * more detailed documentation and type information.
6
+ */
7
+
8
+ /** Verification result from verify_receipt */
9
+ export interface VerificationResult {
10
+ /** Overall validity - true only if all signatures are valid */
11
+ valid: boolean;
12
+ /** Primary signer signature valid */
13
+ signer_valid: boolean;
14
+ /** Co-signer signature valid (null if no co-signer) */
15
+ cosigner_valid: boolean | null;
16
+ /** Error messages if verification failed */
17
+ errors: string[];
18
+ }
19
+
20
+ /** Initialize the WASM module (called automatically on import) */
21
+ export function init(): void;
22
+
23
+ /** Get the WASM module version */
24
+ export function version(): string;
25
+
26
+ /**
27
+ * Compute SHA-256 hash of data
28
+ * @param data - Bytes to hash
29
+ * @returns Hex-encoded hash (64 chars, no prefix)
30
+ */
31
+ export function hash_sha256(data: Uint8Array): string;
32
+
33
+ /**
34
+ * Compute SHA-256 hash with 0x prefix
35
+ * @param data - Bytes to hash
36
+ * @returns Hex-encoded hash with 0x prefix
37
+ */
38
+ export function hash_sha256_prefixed(data: Uint8Array): string;
39
+
40
+ /**
41
+ * Compute Keccak-256 hash (Ethereum-compatible)
42
+ * @param data - Bytes to hash
43
+ * @returns Hex-encoded hash with 0x prefix
44
+ */
45
+ export function hash_keccak256(data: Uint8Array): string;
46
+
47
+ /**
48
+ * Verify an Ed25519 signature
49
+ * @param publicKeyHex - Hex-encoded public key (32 bytes)
50
+ * @param message - Message bytes that were signed
51
+ * @param signatureHex - Hex-encoded signature (64 bytes)
52
+ * @returns true if signature is valid
53
+ * @throws Error if keys/signature are malformed
54
+ */
55
+ export function verify_ed25519(
56
+ publicKeyHex: string,
57
+ message: Uint8Array,
58
+ signatureHex: string
59
+ ): boolean;
60
+
61
+ /**
62
+ * Verify a signed receipt
63
+ * @param receiptJson - JSON-serialized SignedReceipt
64
+ * @param signerPubkeyHex - Hex-encoded signer public key
65
+ * @param cosignerPubkeyHex - Optional hex-encoded co-signer public key
66
+ * @returns Verification result object
67
+ * @throws Error if JSON is malformed or keys are invalid
68
+ */
69
+ export function verify_receipt(
70
+ receiptJson: string,
71
+ signerPubkeyHex: string,
72
+ cosignerPubkeyHex?: string
73
+ ): VerificationResult;
74
+
75
+ /**
76
+ * Hash a receipt using specified algorithm
77
+ * @param receiptJson - JSON-serialized Receipt
78
+ * @param algorithm - "sha256" or "keccak256"
79
+ * @returns Hex-encoded hash with 0x prefix
80
+ * @throws Error if JSON is malformed or algorithm is invalid
81
+ */
82
+ export function hash_receipt(
83
+ receiptJson: string,
84
+ algorithm: 'sha256' | 'keccak256'
85
+ ): string;
86
+
87
+ /**
88
+ * Get canonical JSON representation of a receipt
89
+ * @param receiptJson - JSON-serialized Receipt
90
+ * @returns Canonical JSON (sorted keys, no whitespace)
91
+ * @throws Error if JSON is malformed
92
+ */
93
+ export function get_canonical_json(receiptJson: string): string;
94
+
95
+ /**
96
+ * Verify a Merkle inclusion proof
97
+ * @param leafHashHex - Hex-encoded leaf hash
98
+ * @param proofJson - JSON-serialized MerkleProof
99
+ * @param rootHex - Hex-encoded expected root hash
100
+ * @returns true if proof is valid
101
+ * @throws Error if hashes are malformed
102
+ */
103
+ export function verify_merkle_proof(
104
+ leafHashHex: string,
105
+ proofJson: string,
106
+ rootHex: string
107
+ ): boolean;
108
+
109
+ /**
110
+ * Compute Merkle root from leaf hashes
111
+ * @param leafHashesJson - JSON array of hex-encoded leaf hashes
112
+ * @returns Hex-encoded root with 0x prefix
113
+ * @throws Error if hashes are malformed
114
+ */
115
+ export function compute_merkle_root(leafHashesJson: string): string;
116
+
117
+ /**
118
+ * Generate a Merkle inclusion proof
119
+ * @param leafHashesJson - JSON array of hex-encoded leaf hashes
120
+ * @param leafIndex - 0-based index of leaf to prove
121
+ * @returns JSON-serialized MerkleProof
122
+ * @throws Error if index is out of bounds
123
+ */
124
+ export function generate_merkle_proof(
125
+ leafHashesJson: string,
126
+ leafIndex: number
127
+ ): string;
package/hush_wasm.js ADDED
@@ -0,0 +1,604 @@
1
+ /* @ts-self-types="./hush_wasm.d.ts" */
2
+
3
+ /**
4
+ * Compute Merkle root from leaf hashes.
5
+ *
6
+ * # Arguments
7
+ * * `leaf_hashes_json` - JSON array of hex-encoded leaf hashes
8
+ *
9
+ * # Returns
10
+ * Hex-encoded Merkle root (with 0x prefix)
11
+ * @param {string} leaf_hashes_json
12
+ * @returns {string}
13
+ */
14
+ export function compute_merkle_root(leaf_hashes_json) {
15
+ let deferred3_0;
16
+ let deferred3_1;
17
+ try {
18
+ const ptr0 = passStringToWasm0(leaf_hashes_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
19
+ const len0 = WASM_VECTOR_LEN;
20
+ const ret = wasm.compute_merkle_root(ptr0, len0);
21
+ var ptr2 = ret[0];
22
+ var len2 = ret[1];
23
+ if (ret[3]) {
24
+ ptr2 = 0; len2 = 0;
25
+ throw takeFromExternrefTable0(ret[2]);
26
+ }
27
+ deferred3_0 = ptr2;
28
+ deferred3_1 = len2;
29
+ return getStringFromWasm0(ptr2, len2);
30
+ } finally {
31
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Generate a Merkle proof for a specific leaf index.
37
+ *
38
+ * # Arguments
39
+ * * `leaf_hashes_json` - JSON array of hex-encoded leaf hashes
40
+ * * `leaf_index` - Index of the leaf to prove (0-based)
41
+ *
42
+ * # Returns
43
+ * JSON-serialized MerkleProof
44
+ * @param {string} leaf_hashes_json
45
+ * @param {number} leaf_index
46
+ * @returns {string}
47
+ */
48
+ export function generate_merkle_proof(leaf_hashes_json, leaf_index) {
49
+ let deferred3_0;
50
+ let deferred3_1;
51
+ try {
52
+ const ptr0 = passStringToWasm0(leaf_hashes_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
53
+ const len0 = WASM_VECTOR_LEN;
54
+ const ret = wasm.generate_merkle_proof(ptr0, len0, leaf_index);
55
+ var ptr2 = ret[0];
56
+ var len2 = ret[1];
57
+ if (ret[3]) {
58
+ ptr2 = 0; len2 = 0;
59
+ throw takeFromExternrefTable0(ret[2]);
60
+ }
61
+ deferred3_0 = ptr2;
62
+ deferred3_1 = len2;
63
+ return getStringFromWasm0(ptr2, len2);
64
+ } finally {
65
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Get the canonical JSON representation of a receipt.
71
+ * This is the exact bytes that are signed.
72
+ *
73
+ * # Arguments
74
+ * * `receipt_json` - JSON-serialized Receipt
75
+ *
76
+ * # Returns
77
+ * Canonical JSON string (sorted keys, no extra whitespace)
78
+ * @param {string} receipt_json
79
+ * @returns {string}
80
+ */
81
+ export function get_canonical_json(receipt_json) {
82
+ let deferred3_0;
83
+ let deferred3_1;
84
+ try {
85
+ const ptr0 = passStringToWasm0(receipt_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
86
+ const len0 = WASM_VECTOR_LEN;
87
+ const ret = wasm.get_canonical_json(ptr0, len0);
88
+ var ptr2 = ret[0];
89
+ var len2 = ret[1];
90
+ if (ret[3]) {
91
+ ptr2 = 0; len2 = 0;
92
+ throw takeFromExternrefTable0(ret[2]);
93
+ }
94
+ deferred3_0 = ptr2;
95
+ deferred3_1 = len2;
96
+ return getStringFromWasm0(ptr2, len2);
97
+ } finally {
98
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Compute Keccak-256 hash of data (Ethereum-compatible).
104
+ *
105
+ * # Arguments
106
+ * * `data` - The bytes to hash
107
+ *
108
+ * # Returns
109
+ * Hex-encoded hash with 0x prefix (66 characters)
110
+ * @param {Uint8Array} data
111
+ * @returns {string}
112
+ */
113
+ export function hash_keccak256(data) {
114
+ let deferred2_0;
115
+ let deferred2_1;
116
+ try {
117
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
118
+ const len0 = WASM_VECTOR_LEN;
119
+ const ret = wasm.hash_keccak256(ptr0, len0);
120
+ deferred2_0 = ret[0];
121
+ deferred2_1 = ret[1];
122
+ return getStringFromWasm0(ret[0], ret[1]);
123
+ } finally {
124
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Hash a Receipt to get its canonical hash.
130
+ *
131
+ * # Arguments
132
+ * * `receipt_json` - JSON-serialized Receipt (unsigned)
133
+ * * `algorithm` - "sha256" or "keccak256"
134
+ *
135
+ * # Returns
136
+ * Hex-encoded hash with 0x prefix
137
+ * @param {string} receipt_json
138
+ * @param {string} algorithm
139
+ * @returns {string}
140
+ */
141
+ export function hash_receipt(receipt_json, algorithm) {
142
+ let deferred4_0;
143
+ let deferred4_1;
144
+ try {
145
+ const ptr0 = passStringToWasm0(receipt_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
146
+ const len0 = WASM_VECTOR_LEN;
147
+ const ptr1 = passStringToWasm0(algorithm, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
148
+ const len1 = WASM_VECTOR_LEN;
149
+ const ret = wasm.hash_receipt(ptr0, len0, ptr1, len1);
150
+ var ptr3 = ret[0];
151
+ var len3 = ret[1];
152
+ if (ret[3]) {
153
+ ptr3 = 0; len3 = 0;
154
+ throw takeFromExternrefTable0(ret[2]);
155
+ }
156
+ deferred4_0 = ptr3;
157
+ deferred4_1 = len3;
158
+ return getStringFromWasm0(ptr3, len3);
159
+ } finally {
160
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Compute SHA-256 hash of data.
166
+ *
167
+ * # Arguments
168
+ * * `data` - The bytes to hash
169
+ *
170
+ * # Returns
171
+ * Hex-encoded hash (64 characters, no 0x prefix)
172
+ * @param {Uint8Array} data
173
+ * @returns {string}
174
+ */
175
+ export function hash_sha256(data) {
176
+ let deferred2_0;
177
+ let deferred2_1;
178
+ try {
179
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
180
+ const len0 = WASM_VECTOR_LEN;
181
+ const ret = wasm.hash_sha256(ptr0, len0);
182
+ deferred2_0 = ret[0];
183
+ deferred2_1 = ret[1];
184
+ return getStringFromWasm0(ret[0], ret[1]);
185
+ } finally {
186
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
187
+ }
188
+ }
189
+
190
+ /**
191
+ * Compute SHA-256 hash with 0x prefix.
192
+ *
193
+ * # Arguments
194
+ * * `data` - The bytes to hash
195
+ *
196
+ * # Returns
197
+ * Hex-encoded hash with 0x prefix (66 characters)
198
+ * @param {Uint8Array} data
199
+ * @returns {string}
200
+ */
201
+ export function hash_sha256_prefixed(data) {
202
+ let deferred2_0;
203
+ let deferred2_1;
204
+ try {
205
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
206
+ const len0 = WASM_VECTOR_LEN;
207
+ const ret = wasm.hash_sha256_prefixed(ptr0, len0);
208
+ deferred2_0 = ret[0];
209
+ deferred2_1 = ret[1];
210
+ return getStringFromWasm0(ret[0], ret[1]);
211
+ } finally {
212
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
213
+ }
214
+ }
215
+
216
+ /**
217
+ * Initialize the WASM module (call once at startup)
218
+ */
219
+ export function init() {
220
+ wasm.init();
221
+ }
222
+
223
+ /**
224
+ * Verify an Ed25519 signature over a message.
225
+ *
226
+ * # Arguments
227
+ * * `public_key_hex` - Hex-encoded public key (32 bytes, with or without 0x prefix)
228
+ * * `message` - The message bytes that were signed
229
+ * * `signature_hex` - Hex-encoded signature (64 bytes, with or without 0x prefix)
230
+ *
231
+ * # Returns
232
+ * `true` if the signature is valid, `false` otherwise
233
+ * @param {string} public_key_hex
234
+ * @param {Uint8Array} message
235
+ * @param {string} signature_hex
236
+ * @returns {boolean}
237
+ */
238
+ export function verify_ed25519(public_key_hex, message, signature_hex) {
239
+ const ptr0 = passStringToWasm0(public_key_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
240
+ const len0 = WASM_VECTOR_LEN;
241
+ const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
242
+ const len1 = WASM_VECTOR_LEN;
243
+ const ptr2 = passStringToWasm0(signature_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
244
+ const len2 = WASM_VECTOR_LEN;
245
+ const ret = wasm.verify_ed25519(ptr0, len0, ptr1, len1, ptr2, len2);
246
+ if (ret[2]) {
247
+ throw takeFromExternrefTable0(ret[1]);
248
+ }
249
+ return ret[0] !== 0;
250
+ }
251
+
252
+ /**
253
+ * Verify a Merkle inclusion proof.
254
+ *
255
+ * # Arguments
256
+ * * `leaf_hash_hex` - Hex-encoded leaf hash (with or without 0x prefix)
257
+ * * `proof_json` - JSON-serialized MerkleProof
258
+ * * `root_hex` - Hex-encoded expected root hash (with or without 0x prefix)
259
+ *
260
+ * # Returns
261
+ * `true` if the proof is valid, `false` otherwise
262
+ * @param {string} leaf_hash_hex
263
+ * @param {string} proof_json
264
+ * @param {string} root_hex
265
+ * @returns {boolean}
266
+ */
267
+ export function verify_merkle_proof(leaf_hash_hex, proof_json, root_hex) {
268
+ const ptr0 = passStringToWasm0(leaf_hash_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
269
+ const len0 = WASM_VECTOR_LEN;
270
+ const ptr1 = passStringToWasm0(proof_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
271
+ const len1 = WASM_VECTOR_LEN;
272
+ const ptr2 = passStringToWasm0(root_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
273
+ const len2 = WASM_VECTOR_LEN;
274
+ const ret = wasm.verify_merkle_proof(ptr0, len0, ptr1, len1, ptr2, len2);
275
+ if (ret[2]) {
276
+ throw takeFromExternrefTable0(ret[1]);
277
+ }
278
+ return ret[0] !== 0;
279
+ }
280
+
281
+ /**
282
+ * Verify a signed Receipt.
283
+ *
284
+ * # Arguments
285
+ * * `receipt_json` - JSON-serialized SignedReceipt
286
+ * * `signer_pubkey_hex` - Hex-encoded signer public key
287
+ * * `cosigner_pubkey_hex` - Optional hex-encoded co-signer public key
288
+ *
289
+ * # Returns
290
+ * JavaScript object with verification result:
291
+ * ```json
292
+ * {
293
+ * "valid": true,
294
+ * "signer_valid": true,
295
+ * "cosigner_valid": null,
296
+ * "errors": []
297
+ * }
298
+ * ```
299
+ * @param {string} receipt_json
300
+ * @param {string} signer_pubkey_hex
301
+ * @param {string | null} [cosigner_pubkey_hex]
302
+ * @returns {any}
303
+ */
304
+ export function verify_receipt(receipt_json, signer_pubkey_hex, cosigner_pubkey_hex) {
305
+ const ptr0 = passStringToWasm0(receipt_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
306
+ const len0 = WASM_VECTOR_LEN;
307
+ const ptr1 = passStringToWasm0(signer_pubkey_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
308
+ const len1 = WASM_VECTOR_LEN;
309
+ var ptr2 = isLikeNone(cosigner_pubkey_hex) ? 0 : passStringToWasm0(cosigner_pubkey_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
310
+ var len2 = WASM_VECTOR_LEN;
311
+ const ret = wasm.verify_receipt(ptr0, len0, ptr1, len1, ptr2, len2);
312
+ if (ret[2]) {
313
+ throw takeFromExternrefTable0(ret[1]);
314
+ }
315
+ return takeFromExternrefTable0(ret[0]);
316
+ }
317
+
318
+ /**
319
+ * Get version information about this WASM module
320
+ * @returns {string}
321
+ */
322
+ export function version() {
323
+ let deferred1_0;
324
+ let deferred1_1;
325
+ try {
326
+ const ret = wasm.version();
327
+ deferred1_0 = ret[0];
328
+ deferred1_1 = ret[1];
329
+ return getStringFromWasm0(ret[0], ret[1]);
330
+ } finally {
331
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
332
+ }
333
+ }
334
+
335
+ function __wbg_get_imports() {
336
+ const import0 = {
337
+ __proto__: null,
338
+ __wbg_Error_8c4e43fe74559d73: function(arg0, arg1) {
339
+ const ret = Error(getStringFromWasm0(arg0, arg1));
340
+ return ret;
341
+ },
342
+ __wbg_String_8f0eb39a4a4c2f66: function(arg0, arg1) {
343
+ const ret = String(arg1);
344
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
345
+ const len1 = WASM_VECTOR_LEN;
346
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
347
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
348
+ },
349
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
350
+ throw new Error(getStringFromWasm0(arg0, arg1));
351
+ },
352
+ __wbg_error_7534b8e9a36f1ab4: function(arg0, arg1) {
353
+ let deferred0_0;
354
+ let deferred0_1;
355
+ try {
356
+ deferred0_0 = arg0;
357
+ deferred0_1 = arg1;
358
+ console.error(getStringFromWasm0(arg0, arg1));
359
+ } finally {
360
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
361
+ }
362
+ },
363
+ __wbg_new_361308b2356cecd0: function() {
364
+ const ret = new Object();
365
+ return ret;
366
+ },
367
+ __wbg_new_3eb36ae241fe6f44: function() {
368
+ const ret = new Array();
369
+ return ret;
370
+ },
371
+ __wbg_new_8a6f238a6ece86ea: function() {
372
+ const ret = new Error();
373
+ return ret;
374
+ },
375
+ __wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
376
+ arg0[arg1] = arg2;
377
+ },
378
+ __wbg_set_f43e577aea94465b: function(arg0, arg1, arg2) {
379
+ arg0[arg1 >>> 0] = arg2;
380
+ },
381
+ __wbg_stack_0ed75d68575b0f3c: function(arg0, arg1) {
382
+ const ret = arg1.stack;
383
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
384
+ const len1 = WASM_VECTOR_LEN;
385
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
386
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
387
+ },
388
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
389
+ // Cast intrinsic for `Ref(String) -> Externref`.
390
+ const ret = getStringFromWasm0(arg0, arg1);
391
+ return ret;
392
+ },
393
+ __wbindgen_init_externref_table: function() {
394
+ const table = wasm.__wbindgen_externrefs;
395
+ const offset = table.grow(4);
396
+ table.set(0, undefined);
397
+ table.set(offset + 0, undefined);
398
+ table.set(offset + 1, null);
399
+ table.set(offset + 2, true);
400
+ table.set(offset + 3, false);
401
+ },
402
+ };
403
+ return {
404
+ __proto__: null,
405
+ "./hush_wasm_bg.js": import0,
406
+ };
407
+ }
408
+
409
+ let cachedDataViewMemory0 = null;
410
+ function getDataViewMemory0() {
411
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
412
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
413
+ }
414
+ return cachedDataViewMemory0;
415
+ }
416
+
417
+ function getStringFromWasm0(ptr, len) {
418
+ ptr = ptr >>> 0;
419
+ return decodeText(ptr, len);
420
+ }
421
+
422
+ let cachedUint8ArrayMemory0 = null;
423
+ function getUint8ArrayMemory0() {
424
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
425
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
426
+ }
427
+ return cachedUint8ArrayMemory0;
428
+ }
429
+
430
+ function isLikeNone(x) {
431
+ return x === undefined || x === null;
432
+ }
433
+
434
+ function passArray8ToWasm0(arg, malloc) {
435
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
436
+ getUint8ArrayMemory0().set(arg, ptr / 1);
437
+ WASM_VECTOR_LEN = arg.length;
438
+ return ptr;
439
+ }
440
+
441
+ function passStringToWasm0(arg, malloc, realloc) {
442
+ if (realloc === undefined) {
443
+ const buf = cachedTextEncoder.encode(arg);
444
+ const ptr = malloc(buf.length, 1) >>> 0;
445
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
446
+ WASM_VECTOR_LEN = buf.length;
447
+ return ptr;
448
+ }
449
+
450
+ let len = arg.length;
451
+ let ptr = malloc(len, 1) >>> 0;
452
+
453
+ const mem = getUint8ArrayMemory0();
454
+
455
+ let offset = 0;
456
+
457
+ for (; offset < len; offset++) {
458
+ const code = arg.charCodeAt(offset);
459
+ if (code > 0x7F) break;
460
+ mem[ptr + offset] = code;
461
+ }
462
+ if (offset !== len) {
463
+ if (offset !== 0) {
464
+ arg = arg.slice(offset);
465
+ }
466
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
467
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
468
+ const ret = cachedTextEncoder.encodeInto(arg, view);
469
+
470
+ offset += ret.written;
471
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
472
+ }
473
+
474
+ WASM_VECTOR_LEN = offset;
475
+ return ptr;
476
+ }
477
+
478
+ function takeFromExternrefTable0(idx) {
479
+ const value = wasm.__wbindgen_externrefs.get(idx);
480
+ wasm.__externref_table_dealloc(idx);
481
+ return value;
482
+ }
483
+
484
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
485
+ cachedTextDecoder.decode();
486
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
487
+ let numBytesDecoded = 0;
488
+ function decodeText(ptr, len) {
489
+ numBytesDecoded += len;
490
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
491
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
492
+ cachedTextDecoder.decode();
493
+ numBytesDecoded = len;
494
+ }
495
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
496
+ }
497
+
498
+ const cachedTextEncoder = new TextEncoder();
499
+
500
+ if (!('encodeInto' in cachedTextEncoder)) {
501
+ cachedTextEncoder.encodeInto = function (arg, view) {
502
+ const buf = cachedTextEncoder.encode(arg);
503
+ view.set(buf);
504
+ return {
505
+ read: arg.length,
506
+ written: buf.length
507
+ };
508
+ };
509
+ }
510
+
511
+ let WASM_VECTOR_LEN = 0;
512
+
513
+ let wasmModule, wasm;
514
+ function __wbg_finalize_init(instance, module) {
515
+ wasm = instance.exports;
516
+ wasmModule = module;
517
+ cachedDataViewMemory0 = null;
518
+ cachedUint8ArrayMemory0 = null;
519
+ wasm.__wbindgen_start();
520
+ return wasm;
521
+ }
522
+
523
+ async function __wbg_load(module, imports) {
524
+ if (typeof Response === 'function' && module instanceof Response) {
525
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
526
+ try {
527
+ return await WebAssembly.instantiateStreaming(module, imports);
528
+ } catch (e) {
529
+ const validResponse = module.ok && expectedResponseType(module.type);
530
+
531
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
532
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
533
+
534
+ } else { throw e; }
535
+ }
536
+ }
537
+
538
+ const bytes = await module.arrayBuffer();
539
+ return await WebAssembly.instantiate(bytes, imports);
540
+ } else {
541
+ const instance = await WebAssembly.instantiate(module, imports);
542
+
543
+ if (instance instanceof WebAssembly.Instance) {
544
+ return { instance, module };
545
+ } else {
546
+ return instance;
547
+ }
548
+ }
549
+
550
+ function expectedResponseType(type) {
551
+ switch (type) {
552
+ case 'basic': case 'cors': case 'default': return true;
553
+ }
554
+ return false;
555
+ }
556
+ }
557
+
558
+ function initSync(module) {
559
+ if (wasm !== undefined) return wasm;
560
+
561
+
562
+ if (module !== undefined) {
563
+ if (Object.getPrototypeOf(module) === Object.prototype) {
564
+ ({module} = module)
565
+ } else {
566
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
567
+ }
568
+ }
569
+
570
+ const imports = __wbg_get_imports();
571
+ if (!(module instanceof WebAssembly.Module)) {
572
+ module = new WebAssembly.Module(module);
573
+ }
574
+ const instance = new WebAssembly.Instance(module, imports);
575
+ return __wbg_finalize_init(instance, module);
576
+ }
577
+
578
+ async function __wbg_init(module_or_path) {
579
+ if (wasm !== undefined) return wasm;
580
+
581
+
582
+ if (module_or_path !== undefined) {
583
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
584
+ ({module_or_path} = module_or_path)
585
+ } else {
586
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
587
+ }
588
+ }
589
+
590
+ if (module_or_path === undefined) {
591
+ module_or_path = new URL('hush_wasm_bg.wasm', import.meta.url);
592
+ }
593
+ const imports = __wbg_get_imports();
594
+
595
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
596
+ module_or_path = fetch(module_or_path);
597
+ }
598
+
599
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
600
+
601
+ return __wbg_finalize_init(instance, module);
602
+ }
603
+
604
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,21 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const compute_merkle_root: (a: number, b: number) => [number, number, number, number];
5
+ export const generate_merkle_proof: (a: number, b: number, c: number) => [number, number, number, number];
6
+ export const get_canonical_json: (a: number, b: number) => [number, number, number, number];
7
+ export const hash_keccak256: (a: number, b: number) => [number, number];
8
+ export const hash_receipt: (a: number, b: number, c: number, d: number) => [number, number, number, number];
9
+ export const hash_sha256: (a: number, b: number) => [number, number];
10
+ export const hash_sha256_prefixed: (a: number, b: number) => [number, number];
11
+ export const verify_ed25519: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
12
+ export const verify_merkle_proof: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
13
+ export const verify_receipt: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
14
+ export const version: () => [number, number];
15
+ export const init: () => void;
16
+ export const __wbindgen_malloc: (a: number, b: number) => number;
17
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
18
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
19
+ export const __wbindgen_externrefs: WebAssembly.Table;
20
+ export const __externref_table_dealloc: (a: number) => void;
21
+ export const __wbindgen_start: () => void;
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@clawdstrike/wasm",
3
+ "version": "0.1.0",
4
+ "description": "WebAssembly bindings for clawdstrike cryptographic verification",
5
+ "main": "hush_wasm.js",
6
+ "types": "hush_wasm.d.ts",
7
+ "files": [
8
+ "hush_wasm_bg.wasm",
9
+ "hush_wasm.js",
10
+ "hush_wasm.d.ts",
11
+ "hush_wasm_bg.wasm.d.ts"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/backbay-labs/clawdstrike.git",
16
+ "directory": "crates/libs/hush-wasm"
17
+ },
18
+ "keywords": [
19
+ "wasm",
20
+ "webassembly",
21
+ "cryptography",
22
+ "verification",
23
+ "attestation",
24
+ "ed25519",
25
+ "merkle",
26
+ "clawdstrike"
27
+ ],
28
+ "author": "Clawdstrike Contributors",
29
+ "license": "Apache-2.0",
30
+ "bugs": {
31
+ "url": "https://github.com/backbay-labs/clawdstrike/issues"
32
+ },
33
+ "homepage": "https://clawdstrike.dev"
34
+ }