@rolly-dev/wasm-signer 0.1.0 → 0.3.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 CHANGED
@@ -1,4 +1,4 @@
1
- # @rolly/wasm-signer
1
+ # @rolly-dev/wasm-signer
2
2
 
3
3
  Client-side Poseidon2 hashing and bet authentication for the Rolly ZK-Rollup casino.
4
4
 
@@ -24,7 +24,7 @@ const {
24
24
  derive_session_key,
25
25
  session_public_key,
26
26
  create_bet_auth,
27
- } = require('@rolly/wasm-signer');
27
+ } = require('@rolly-dev/wasm-signer');
28
28
 
29
29
  const hash = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
30
30
  // → BigUint64Array(4)
@@ -37,7 +37,7 @@ import {
37
37
  poseidon2_hash,
38
38
  derive_session_key,
39
39
  create_bet_auth,
40
- } from '@rolly/wasm-signer';
40
+ } from '@rolly-dev/wasm-signer';
41
41
 
42
42
  const hash = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
43
43
  ```
@@ -45,7 +45,7 @@ const hash = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
45
45
  ### React
46
46
 
47
47
  ```jsx
48
- import { useRollyWasm } from '@rolly/wasm-signer/react';
48
+ import { useRollyWasm } from '@rolly-dev/wasm-signer/react';
49
49
 
50
50
  function BetButton({ sessionKey, amount, nonce }) {
51
51
  const { ready, create_bet_auth } = useRollyWasm();
@@ -65,7 +65,7 @@ function BetButton({ sessionKey, amount, nonce }) {
65
65
 
66
66
  ```html
67
67
  <script type="module">
68
- import { init, poseidon2_hash } from '@rolly/wasm-signer';
68
+ import { init, poseidon2_hash } from '@rolly-dev/wasm-signer';
69
69
 
70
70
  await init(); // loads .wasm, must be called once
71
71
  const h = poseidon2_hash(BigUint64Array.from([1n, 2n]));
@@ -75,7 +75,7 @@ function BetButton({ sessionKey, amount, nonce }) {
75
75
  ### Manual init (advanced)
76
76
 
77
77
  ```javascript
78
- import init, { poseidon2_hash } from '@rolly/wasm-signer/init';
78
+ import init, { poseidon2_hash } from '@rolly-dev/wasm-signer/init';
79
79
 
80
80
  // custom wasm URL or ArrayBuffer
81
81
  await init('/assets/rolly_wasm_signer_bg.wasm');
@@ -100,7 +100,7 @@ poseidon2_hash(BigUint64Array.from([1n]));
100
100
 
101
101
  **Vite** — add to `optimizeDeps.exclude`:
102
102
  ```js
103
- optimizeDeps: { exclude: ['@rolly/wasm-signer'] }
103
+ optimizeDeps: { exclude: ['@rolly-dev/wasm-signer'] }
104
104
  ```
105
105
 
106
106
  **Webpack 5** — enable WASM experiments:
@@ -1,4 +1,4 @@
1
- # @rolly/wasm-signer
1
+ # @rolly-dev/wasm-signer
2
2
 
3
3
  Client-side Poseidon2 hashing and bet authentication for the Rolly ZK-Rollup casino.
4
4
 
@@ -24,7 +24,7 @@ const {
24
24
  derive_session_key,
25
25
  session_public_key,
26
26
  create_bet_auth,
27
- } = require('@rolly/wasm-signer');
27
+ } = require('@rolly-dev/wasm-signer');
28
28
 
29
29
  const hash = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
30
30
  // → BigUint64Array(4)
@@ -37,7 +37,7 @@ import {
37
37
  poseidon2_hash,
38
38
  derive_session_key,
39
39
  create_bet_auth,
40
- } from '@rolly/wasm-signer';
40
+ } from '@rolly-dev/wasm-signer';
41
41
 
42
42
  const hash = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
43
43
  ```
@@ -45,7 +45,7 @@ const hash = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
45
45
  ### React
46
46
 
47
47
  ```jsx
48
- import { useRollyWasm } from '@rolly/wasm-signer/react';
48
+ import { useRollyWasm } from '@rolly-dev/wasm-signer/react';
49
49
 
50
50
  function BetButton({ sessionKey, amount, nonce }) {
51
51
  const { ready, create_bet_auth } = useRollyWasm();
@@ -65,7 +65,7 @@ function BetButton({ sessionKey, amount, nonce }) {
65
65
 
66
66
  ```html
67
67
  <script type="module">
68
- import { init, poseidon2_hash } from '@rolly/wasm-signer';
68
+ import { init, poseidon2_hash } from '@rolly-dev/wasm-signer';
69
69
 
70
70
  await init(); // loads .wasm, must be called once
71
71
  const h = poseidon2_hash(BigUint64Array.from([1n, 2n]));
@@ -75,7 +75,7 @@ function BetButton({ sessionKey, amount, nonce }) {
75
75
  ### Manual init (advanced)
76
76
 
77
77
  ```javascript
78
- import init, { poseidon2_hash } from '@rolly/wasm-signer/init';
78
+ import init, { poseidon2_hash } from '@rolly-dev/wasm-signer/init';
79
79
 
80
80
  // custom wasm URL or ArrayBuffer
81
81
  await init('/assets/rolly_wasm_signer_bg.wasm');
@@ -100,7 +100,7 @@ poseidon2_hash(BigUint64Array.from([1n]));
100
100
 
101
101
  **Vite** — add to `optimizeDeps.exclude`:
102
102
  ```js
103
- optimizeDeps: { exclude: ['@rolly/wasm-signer'] }
103
+ optimizeDeps: { exclude: ['@rolly-dev/wasm-signer'] }
104
104
  ```
105
105
 
106
106
  **Webpack 5** — enable WASM experiments:
@@ -59,6 +59,18 @@ export function create_bet_auth(session_key: BigUint64Array, bet_amount: bigint,
59
59
  */
60
60
  export function derive_session_key(sig_bytes: Uint8Array): BigUint64Array;
61
61
 
62
+ /**
63
+ * Convert any Goldilocks field elements to a hex string.
64
+ *
65
+ * Each u64 is encoded as 8 little-endian bytes → 16 hex chars.
66
+ * For 4 elements: 64 hex chars (32 bytes).
67
+ *
68
+ * ```js
69
+ * const hex = goldilocks_fields_to_hex(BigUint64Array.from([1n, 2n, 3n, 4n]));
70
+ * ```
71
+ */
72
+ export function goldilocks_fields_to_hex(fields: BigUint64Array): string;
73
+
62
74
  /**
63
75
  * Returns the Goldilocks prime: p = 2^64 - 2^32 + 1.
64
76
  */
@@ -118,3 +130,32 @@ export function seed_hash_truncated(server_seed: BigUint64Array): BigUint64Array
118
130
  * `session_key` must be exactly 4 elements (output of `derive_session_key`).
119
131
  */
120
132
  export function session_public_key(session_key: BigUint64Array): BigUint64Array;
133
+
134
+ /**
135
+ * Convert a user seed string to 4 Goldilocks field elements.
136
+ *
137
+ * `SHA-256(str)` → split into 4 × 8 LE bytes → reduce each mod p.
138
+ *
139
+ * This matches the backend's `stringToUserSeed` and produces the exact
140
+ * field elements used in the provably-fair random computation:
141
+ * `random = Poseidon2(server_seed ‖ user_seed)`
142
+ *
143
+ * ```js
144
+ * const fields = string_to_user_seed("my-seed-123");
145
+ * // fields.length === 4, each < GOLDILOCKS_P
146
+ * ```
147
+ */
148
+ export function string_to_user_seed(input: string): BigUint64Array;
149
+
150
+ /**
151
+ * Convert a user seed string directly to a hex representation.
152
+ *
153
+ * Equivalent to `goldiLocksFieldsToHex(stringToUserSeed(str))`.
154
+ * Returns a 64-character lowercase hex string (32 bytes).
155
+ *
156
+ * ```js
157
+ * const hex = string_to_user_seed_hex("my-seed-123");
158
+ * // hex === "a1b2c3..." (64 chars)
159
+ * ```
160
+ */
161
+ export function string_to_user_seed_hex(input: string): string;
@@ -111,6 +111,38 @@ function derive_session_key(sig_bytes) {
111
111
  }
112
112
  exports.derive_session_key = derive_session_key;
113
113
 
114
+ /**
115
+ * Convert any Goldilocks field elements to a hex string.
116
+ *
117
+ * Each u64 is encoded as 8 little-endian bytes → 16 hex chars.
118
+ * For 4 elements: 64 hex chars (32 bytes).
119
+ *
120
+ * ```js
121
+ * const hex = goldilocks_fields_to_hex(BigUint64Array.from([1n, 2n, 3n, 4n]));
122
+ * ```
123
+ * @param {BigUint64Array} fields
124
+ * @returns {string}
125
+ */
126
+ function goldilocks_fields_to_hex(fields) {
127
+ let deferred2_0;
128
+ let deferred2_1;
129
+ try {
130
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
131
+ const ptr0 = passArray64ToWasm0(fields, wasm.__wbindgen_export);
132
+ const len0 = WASM_VECTOR_LEN;
133
+ wasm.goldilocks_fields_to_hex(retptr, ptr0, len0);
134
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
135
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
136
+ deferred2_0 = r0;
137
+ deferred2_1 = r1;
138
+ return getStringFromWasm0(r0, r1);
139
+ } finally {
140
+ wasm.__wbindgen_add_to_stack_pointer(16);
141
+ wasm.__wbindgen_export2(deferred2_0, deferred2_1, 1);
142
+ }
143
+ }
144
+ exports.goldilocks_fields_to_hex = goldilocks_fields_to_hex;
145
+
114
146
  /**
115
147
  * Returns the Goldilocks prime: p = 2^64 - 2^32 + 1.
116
148
  * @returns {bigint}
@@ -253,6 +285,72 @@ function session_public_key(session_key) {
253
285
  }
254
286
  exports.session_public_key = session_public_key;
255
287
 
288
+ /**
289
+ * Convert a user seed string to 4 Goldilocks field elements.
290
+ *
291
+ * `SHA-256(str)` → split into 4 × 8 LE bytes → reduce each mod p.
292
+ *
293
+ * This matches the backend's `stringToUserSeed` and produces the exact
294
+ * field elements used in the provably-fair random computation:
295
+ * `random = Poseidon2(server_seed ‖ user_seed)`
296
+ *
297
+ * ```js
298
+ * const fields = string_to_user_seed("my-seed-123");
299
+ * // fields.length === 4, each < GOLDILOCKS_P
300
+ * ```
301
+ * @param {string} input
302
+ * @returns {BigUint64Array}
303
+ */
304
+ function string_to_user_seed(input) {
305
+ try {
306
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
307
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export3);
308
+ const len0 = WASM_VECTOR_LEN;
309
+ wasm.string_to_user_seed(retptr, ptr0, len0);
310
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
311
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
312
+ var v2 = getArrayU64FromWasm0(r0, r1).slice();
313
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
314
+ return v2;
315
+ } finally {
316
+ wasm.__wbindgen_add_to_stack_pointer(16);
317
+ }
318
+ }
319
+ exports.string_to_user_seed = string_to_user_seed;
320
+
321
+ /**
322
+ * Convert a user seed string directly to a hex representation.
323
+ *
324
+ * Equivalent to `goldiLocksFieldsToHex(stringToUserSeed(str))`.
325
+ * Returns a 64-character lowercase hex string (32 bytes).
326
+ *
327
+ * ```js
328
+ * const hex = string_to_user_seed_hex("my-seed-123");
329
+ * // hex === "a1b2c3..." (64 chars)
330
+ * ```
331
+ * @param {string} input
332
+ * @returns {string}
333
+ */
334
+ function string_to_user_seed_hex(input) {
335
+ let deferred2_0;
336
+ let deferred2_1;
337
+ try {
338
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
339
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export3);
340
+ const len0 = WASM_VECTOR_LEN;
341
+ wasm.string_to_user_seed_hex(retptr, ptr0, len0);
342
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
343
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
344
+ deferred2_0 = r0;
345
+ deferred2_1 = r1;
346
+ return getStringFromWasm0(r0, r1);
347
+ } finally {
348
+ wasm.__wbindgen_add_to_stack_pointer(16);
349
+ wasm.__wbindgen_export2(deferred2_0, deferred2_1, 1);
350
+ }
351
+ }
352
+ exports.string_to_user_seed_hex = string_to_user_seed_hex;
353
+
256
354
  function __wbg_get_imports() {
257
355
  const import0 = {
258
356
  __proto__: null,
@@ -314,12 +412,62 @@ function passArray8ToWasm0(arg, malloc) {
314
412
  return ptr;
315
413
  }
316
414
 
415
+ function passStringToWasm0(arg, malloc, realloc) {
416
+ if (realloc === undefined) {
417
+ const buf = cachedTextEncoder.encode(arg);
418
+ const ptr = malloc(buf.length, 1) >>> 0;
419
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
420
+ WASM_VECTOR_LEN = buf.length;
421
+ return ptr;
422
+ }
423
+
424
+ let len = arg.length;
425
+ let ptr = malloc(len, 1) >>> 0;
426
+
427
+ const mem = getUint8ArrayMemory0();
428
+
429
+ let offset = 0;
430
+
431
+ for (; offset < len; offset++) {
432
+ const code = arg.charCodeAt(offset);
433
+ if (code > 0x7F) break;
434
+ mem[ptr + offset] = code;
435
+ }
436
+ if (offset !== len) {
437
+ if (offset !== 0) {
438
+ arg = arg.slice(offset);
439
+ }
440
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
441
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
442
+ const ret = cachedTextEncoder.encodeInto(arg, view);
443
+
444
+ offset += ret.written;
445
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
446
+ }
447
+
448
+ WASM_VECTOR_LEN = offset;
449
+ return ptr;
450
+ }
451
+
317
452
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
318
453
  cachedTextDecoder.decode();
319
454
  function decodeText(ptr, len) {
320
455
  return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
321
456
  }
322
457
 
458
+ const cachedTextEncoder = new TextEncoder();
459
+
460
+ if (!('encodeInto' in cachedTextEncoder)) {
461
+ cachedTextEncoder.encodeInto = function (arg, view) {
462
+ const buf = cachedTextEncoder.encode(arg);
463
+ view.set(buf);
464
+ return {
465
+ read: arg.length,
466
+ written: buf.length
467
+ };
468
+ };
469
+ }
470
+
323
471
  let WASM_VECTOR_LEN = 0;
324
472
 
325
473
  const wasmPath = `${__dirname}/rolly_wasm_signer_bg.wasm`;
Binary file
@@ -4,12 +4,16 @@ export const memory: WebAssembly.Memory;
4
4
  export const compute_server_seed_hash: (a: number, b: number, c: number) => void;
5
5
  export const create_bet_auth: (a: number, b: number, c: number, d: bigint, e: bigint) => void;
6
6
  export const derive_session_key: (a: number, b: number, c: number) => void;
7
+ export const goldilocks_fields_to_hex: (a: number, b: number, c: number) => void;
7
8
  export const goldilocks_reduce: (a: bigint) => bigint;
8
9
  export const poseidon2_hash: (a: number, b: number, c: number) => void;
9
10
  export const poseidon2_two_to_one: (a: number, b: number, c: number, d: number, e: number) => void;
10
11
  export const seed_hash_truncated: (a: number, b: number, c: number) => void;
11
12
  export const session_public_key: (a: number, b: number, c: number) => void;
13
+ export const string_to_user_seed: (a: number, b: number, c: number) => void;
14
+ export const string_to_user_seed_hex: (a: number, b: number, c: number) => void;
12
15
  export const goldilocks_modulus: () => bigint;
13
16
  export const __wbindgen_add_to_stack_pointer: (a: number) => number;
14
17
  export const __wbindgen_export: (a: number, b: number) => number;
15
18
  export const __wbindgen_export2: (a: number, b: number, c: number) => void;
19
+ export const __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
@@ -1,4 +1,4 @@
1
- # @rolly/wasm-signer
1
+ # @rolly-dev/wasm-signer
2
2
 
3
3
  Client-side Poseidon2 hashing and bet authentication for the Rolly ZK-Rollup casino.
4
4
 
@@ -24,7 +24,7 @@ const {
24
24
  derive_session_key,
25
25
  session_public_key,
26
26
  create_bet_auth,
27
- } = require('@rolly/wasm-signer');
27
+ } = require('@rolly-dev/wasm-signer');
28
28
 
29
29
  const hash = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
30
30
  // → BigUint64Array(4)
@@ -37,7 +37,7 @@ import {
37
37
  poseidon2_hash,
38
38
  derive_session_key,
39
39
  create_bet_auth,
40
- } from '@rolly/wasm-signer';
40
+ } from '@rolly-dev/wasm-signer';
41
41
 
42
42
  const hash = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
43
43
  ```
@@ -45,7 +45,7 @@ const hash = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
45
45
  ### React
46
46
 
47
47
  ```jsx
48
- import { useRollyWasm } from '@rolly/wasm-signer/react';
48
+ import { useRollyWasm } from '@rolly-dev/wasm-signer/react';
49
49
 
50
50
  function BetButton({ sessionKey, amount, nonce }) {
51
51
  const { ready, create_bet_auth } = useRollyWasm();
@@ -65,7 +65,7 @@ function BetButton({ sessionKey, amount, nonce }) {
65
65
 
66
66
  ```html
67
67
  <script type="module">
68
- import { init, poseidon2_hash } from '@rolly/wasm-signer';
68
+ import { init, poseidon2_hash } from '@rolly-dev/wasm-signer';
69
69
 
70
70
  await init(); // loads .wasm, must be called once
71
71
  const h = poseidon2_hash(BigUint64Array.from([1n, 2n]));
@@ -75,7 +75,7 @@ function BetButton({ sessionKey, amount, nonce }) {
75
75
  ### Manual init (advanced)
76
76
 
77
77
  ```javascript
78
- import init, { poseidon2_hash } from '@rolly/wasm-signer/init';
78
+ import init, { poseidon2_hash } from '@rolly-dev/wasm-signer/init';
79
79
 
80
80
  // custom wasm URL or ArrayBuffer
81
81
  await init('/assets/rolly_wasm_signer_bg.wasm');
@@ -100,7 +100,7 @@ poseidon2_hash(BigUint64Array.from([1n]));
100
100
 
101
101
  **Vite** — add to `optimizeDeps.exclude`:
102
102
  ```js
103
- optimizeDeps: { exclude: ['@rolly/wasm-signer'] }
103
+ optimizeDeps: { exclude: ['@rolly-dev/wasm-signer'] }
104
104
  ```
105
105
 
106
106
  **Webpack 5** — enable WASM experiments:
@@ -59,6 +59,18 @@ export function create_bet_auth(session_key: BigUint64Array, bet_amount: bigint,
59
59
  */
60
60
  export function derive_session_key(sig_bytes: Uint8Array): BigUint64Array;
61
61
 
62
+ /**
63
+ * Convert any Goldilocks field elements to a hex string.
64
+ *
65
+ * Each u64 is encoded as 8 little-endian bytes → 16 hex chars.
66
+ * For 4 elements: 64 hex chars (32 bytes).
67
+ *
68
+ * ```js
69
+ * const hex = goldilocks_fields_to_hex(BigUint64Array.from([1n, 2n, 3n, 4n]));
70
+ * ```
71
+ */
72
+ export function goldilocks_fields_to_hex(fields: BigUint64Array): string;
73
+
62
74
  /**
63
75
  * Returns the Goldilocks prime: p = 2^64 - 2^32 + 1.
64
76
  */
@@ -119,6 +131,35 @@ export function seed_hash_truncated(server_seed: BigUint64Array): BigUint64Array
119
131
  */
120
132
  export function session_public_key(session_key: BigUint64Array): BigUint64Array;
121
133
 
134
+ /**
135
+ * Convert a user seed string to 4 Goldilocks field elements.
136
+ *
137
+ * `SHA-256(str)` → split into 4 × 8 LE bytes → reduce each mod p.
138
+ *
139
+ * This matches the backend's `stringToUserSeed` and produces the exact
140
+ * field elements used in the provably-fair random computation:
141
+ * `random = Poseidon2(server_seed ‖ user_seed)`
142
+ *
143
+ * ```js
144
+ * const fields = string_to_user_seed("my-seed-123");
145
+ * // fields.length === 4, each < GOLDILOCKS_P
146
+ * ```
147
+ */
148
+ export function string_to_user_seed(input: string): BigUint64Array;
149
+
150
+ /**
151
+ * Convert a user seed string directly to a hex representation.
152
+ *
153
+ * Equivalent to `goldiLocksFieldsToHex(stringToUserSeed(str))`.
154
+ * Returns a 64-character lowercase hex string (32 bytes).
155
+ *
156
+ * ```js
157
+ * const hex = string_to_user_seed_hex("my-seed-123");
158
+ * // hex === "a1b2c3..." (64 chars)
159
+ * ```
160
+ */
161
+ export function string_to_user_seed_hex(input: string): string;
162
+
122
163
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
123
164
 
124
165
  export interface InitOutput {
@@ -126,15 +167,19 @@ export interface InitOutput {
126
167
  readonly compute_server_seed_hash: (a: number, b: number, c: number) => void;
127
168
  readonly create_bet_auth: (a: number, b: number, c: number, d: bigint, e: bigint) => void;
128
169
  readonly derive_session_key: (a: number, b: number, c: number) => void;
170
+ readonly goldilocks_fields_to_hex: (a: number, b: number, c: number) => void;
129
171
  readonly goldilocks_reduce: (a: bigint) => bigint;
130
172
  readonly poseidon2_hash: (a: number, b: number, c: number) => void;
131
173
  readonly poseidon2_two_to_one: (a: number, b: number, c: number, d: number, e: number) => void;
132
174
  readonly seed_hash_truncated: (a: number, b: number, c: number) => void;
133
175
  readonly session_public_key: (a: number, b: number, c: number) => void;
176
+ readonly string_to_user_seed: (a: number, b: number, c: number) => void;
177
+ readonly string_to_user_seed_hex: (a: number, b: number, c: number) => void;
134
178
  readonly goldilocks_modulus: () => bigint;
135
179
  readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
136
180
  readonly __wbindgen_export: (a: number, b: number) => number;
137
181
  readonly __wbindgen_export2: (a: number, b: number, c: number) => void;
182
+ readonly __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
138
183
  }
139
184
 
140
185
  export type SyncInitInput = BufferSource | WebAssembly.Module;
@@ -108,6 +108,37 @@ export function derive_session_key(sig_bytes) {
108
108
  }
109
109
  }
110
110
 
111
+ /**
112
+ * Convert any Goldilocks field elements to a hex string.
113
+ *
114
+ * Each u64 is encoded as 8 little-endian bytes → 16 hex chars.
115
+ * For 4 elements: 64 hex chars (32 bytes).
116
+ *
117
+ * ```js
118
+ * const hex = goldilocks_fields_to_hex(BigUint64Array.from([1n, 2n, 3n, 4n]));
119
+ * ```
120
+ * @param {BigUint64Array} fields
121
+ * @returns {string}
122
+ */
123
+ export function goldilocks_fields_to_hex(fields) {
124
+ let deferred2_0;
125
+ let deferred2_1;
126
+ try {
127
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
128
+ const ptr0 = passArray64ToWasm0(fields, wasm.__wbindgen_export);
129
+ const len0 = WASM_VECTOR_LEN;
130
+ wasm.goldilocks_fields_to_hex(retptr, ptr0, len0);
131
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
132
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
133
+ deferred2_0 = r0;
134
+ deferred2_1 = r1;
135
+ return getStringFromWasm0(r0, r1);
136
+ } finally {
137
+ wasm.__wbindgen_add_to_stack_pointer(16);
138
+ wasm.__wbindgen_export2(deferred2_0, deferred2_1, 1);
139
+ }
140
+ }
141
+
111
142
  /**
112
143
  * Returns the Goldilocks prime: p = 2^64 - 2^32 + 1.
113
144
  * @returns {bigint}
@@ -244,6 +275,70 @@ export function session_public_key(session_key) {
244
275
  }
245
276
  }
246
277
 
278
+ /**
279
+ * Convert a user seed string to 4 Goldilocks field elements.
280
+ *
281
+ * `SHA-256(str)` → split into 4 × 8 LE bytes → reduce each mod p.
282
+ *
283
+ * This matches the backend's `stringToUserSeed` and produces the exact
284
+ * field elements used in the provably-fair random computation:
285
+ * `random = Poseidon2(server_seed ‖ user_seed)`
286
+ *
287
+ * ```js
288
+ * const fields = string_to_user_seed("my-seed-123");
289
+ * // fields.length === 4, each < GOLDILOCKS_P
290
+ * ```
291
+ * @param {string} input
292
+ * @returns {BigUint64Array}
293
+ */
294
+ export function string_to_user_seed(input) {
295
+ try {
296
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
297
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export3);
298
+ const len0 = WASM_VECTOR_LEN;
299
+ wasm.string_to_user_seed(retptr, ptr0, len0);
300
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
301
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
302
+ var v2 = getArrayU64FromWasm0(r0, r1).slice();
303
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
304
+ return v2;
305
+ } finally {
306
+ wasm.__wbindgen_add_to_stack_pointer(16);
307
+ }
308
+ }
309
+
310
+ /**
311
+ * Convert a user seed string directly to a hex representation.
312
+ *
313
+ * Equivalent to `goldiLocksFieldsToHex(stringToUserSeed(str))`.
314
+ * Returns a 64-character lowercase hex string (32 bytes).
315
+ *
316
+ * ```js
317
+ * const hex = string_to_user_seed_hex("my-seed-123");
318
+ * // hex === "a1b2c3..." (64 chars)
319
+ * ```
320
+ * @param {string} input
321
+ * @returns {string}
322
+ */
323
+ export function string_to_user_seed_hex(input) {
324
+ let deferred2_0;
325
+ let deferred2_1;
326
+ try {
327
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
328
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export3);
329
+ const len0 = WASM_VECTOR_LEN;
330
+ wasm.string_to_user_seed_hex(retptr, ptr0, len0);
331
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
332
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
333
+ deferred2_0 = r0;
334
+ deferred2_1 = r1;
335
+ return getStringFromWasm0(r0, r1);
336
+ } finally {
337
+ wasm.__wbindgen_add_to_stack_pointer(16);
338
+ wasm.__wbindgen_export2(deferred2_0, deferred2_1, 1);
339
+ }
340
+ }
341
+
247
342
  function __wbg_get_imports() {
248
343
  const import0 = {
249
344
  __proto__: null,
@@ -305,6 +400,43 @@ function passArray8ToWasm0(arg, malloc) {
305
400
  return ptr;
306
401
  }
307
402
 
403
+ function passStringToWasm0(arg, malloc, realloc) {
404
+ if (realloc === undefined) {
405
+ const buf = cachedTextEncoder.encode(arg);
406
+ const ptr = malloc(buf.length, 1) >>> 0;
407
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
408
+ WASM_VECTOR_LEN = buf.length;
409
+ return ptr;
410
+ }
411
+
412
+ let len = arg.length;
413
+ let ptr = malloc(len, 1) >>> 0;
414
+
415
+ const mem = getUint8ArrayMemory0();
416
+
417
+ let offset = 0;
418
+
419
+ for (; offset < len; offset++) {
420
+ const code = arg.charCodeAt(offset);
421
+ if (code > 0x7F) break;
422
+ mem[ptr + offset] = code;
423
+ }
424
+ if (offset !== len) {
425
+ if (offset !== 0) {
426
+ arg = arg.slice(offset);
427
+ }
428
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
429
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
430
+ const ret = cachedTextEncoder.encodeInto(arg, view);
431
+
432
+ offset += ret.written;
433
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
434
+ }
435
+
436
+ WASM_VECTOR_LEN = offset;
437
+ return ptr;
438
+ }
439
+
308
440
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
309
441
  cachedTextDecoder.decode();
310
442
  const MAX_SAFARI_DECODE_BYTES = 2146435072;
@@ -319,6 +451,19 @@ function decodeText(ptr, len) {
319
451
  return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
320
452
  }
321
453
 
454
+ const cachedTextEncoder = new TextEncoder();
455
+
456
+ if (!('encodeInto' in cachedTextEncoder)) {
457
+ cachedTextEncoder.encodeInto = function (arg, view) {
458
+ const buf = cachedTextEncoder.encode(arg);
459
+ view.set(buf);
460
+ return {
461
+ read: arg.length,
462
+ written: buf.length
463
+ };
464
+ };
465
+ }
466
+
322
467
  let WASM_VECTOR_LEN = 0;
323
468
 
324
469
  let wasmModule, wasm;
Binary file
@@ -4,12 +4,16 @@ export const memory: WebAssembly.Memory;
4
4
  export const compute_server_seed_hash: (a: number, b: number, c: number) => void;
5
5
  export const create_bet_auth: (a: number, b: number, c: number, d: bigint, e: bigint) => void;
6
6
  export const derive_session_key: (a: number, b: number, c: number) => void;
7
+ export const goldilocks_fields_to_hex: (a: number, b: number, c: number) => void;
7
8
  export const goldilocks_reduce: (a: bigint) => bigint;
8
9
  export const poseidon2_hash: (a: number, b: number, c: number) => void;
9
10
  export const poseidon2_two_to_one: (a: number, b: number, c: number, d: number, e: number) => void;
10
11
  export const seed_hash_truncated: (a: number, b: number, c: number) => void;
11
12
  export const session_public_key: (a: number, b: number, c: number) => void;
13
+ export const string_to_user_seed: (a: number, b: number, c: number) => void;
14
+ export const string_to_user_seed_hex: (a: number, b: number, c: number) => void;
12
15
  export const goldilocks_modulus: () => bigint;
13
16
  export const __wbindgen_add_to_stack_pointer: (a: number) => number;
14
17
  export const __wbindgen_export: (a: number, b: number) => number;
15
18
  export const __wbindgen_export2: (a: number, b: number, c: number) => void;
19
+ export const __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
@@ -0,0 +1,16 @@
1
+ export {
2
+ poseidon2_hash,
3
+ poseidon2_two_to_one,
4
+ derive_session_key,
5
+ session_public_key,
6
+ create_bet_auth,
7
+ compute_server_seed_hash,
8
+ seed_hash_truncated,
9
+ string_to_user_seed,
10
+ string_to_user_seed_hex,
11
+ goldilocks_fields_to_hex,
12
+ goldilocks_modulus,
13
+ goldilocks_reduce,
14
+ } from '../dist/web/rolly_wasm_signer.js';
15
+
16
+ export { default as init } from '../dist/web/rolly_wasm_signer.js';
package/js/browser.mjs CHANGED
@@ -8,6 +8,9 @@ export {
8
8
  create_bet_auth,
9
9
  compute_server_seed_hash,
10
10
  seed_hash_truncated,
11
+ string_to_user_seed,
12
+ string_to_user_seed_hex,
13
+ goldilocks_fields_to_hex,
11
14
  goldilocks_modulus,
12
15
  goldilocks_reduce,
13
16
  } from '../dist/web/rolly_wasm_signer.js';
package/js/index.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ export {
2
+ poseidon2_hash,
3
+ poseidon2_two_to_one,
4
+ derive_session_key,
5
+ session_public_key,
6
+ create_bet_auth,
7
+ compute_server_seed_hash,
8
+ seed_hash_truncated,
9
+ string_to_user_seed,
10
+ string_to_user_seed_hex,
11
+ goldilocks_fields_to_hex,
12
+ goldilocks_modulus,
13
+ goldilocks_reduce,
14
+ } from '../dist/node/rolly_wasm_signer.js';
package/js/node.cjs CHANGED
@@ -10,6 +10,9 @@ module.exports = {
10
10
  create_bet_auth: wasm.create_bet_auth,
11
11
  compute_server_seed_hash: wasm.compute_server_seed_hash,
12
12
  seed_hash_truncated: wasm.seed_hash_truncated,
13
+ string_to_user_seed: wasm.string_to_user_seed,
14
+ string_to_user_seed_hex: wasm.string_to_user_seed_hex,
15
+ goldilocks_fields_to_hex: wasm.goldilocks_fields_to_hex,
13
16
  goldilocks_modulus: wasm.goldilocks_modulus,
14
17
  goldilocks_reduce: wasm.goldilocks_reduce,
15
18
  };
package/js/node.mjs CHANGED
@@ -11,6 +11,9 @@ export const {
11
11
  create_bet_auth,
12
12
  compute_server_seed_hash,
13
13
  seed_hash_truncated,
14
+ string_to_user_seed,
15
+ string_to_user_seed_hex,
16
+ goldilocks_fields_to_hex,
14
17
  goldilocks_modulus,
15
18
  goldilocks_reduce,
16
19
  } = wasm;
package/js/react.d.mts ADDED
@@ -0,0 +1,18 @@
1
+ export interface RollyWasmResult {
2
+ ready: boolean;
3
+ error: Error | null;
4
+ poseidon2_hash: ((input: BigUint64Array) => BigUint64Array) | null;
5
+ poseidon2_two_to_one: ((left: BigUint64Array, right: BigUint64Array) => BigUint64Array) | null;
6
+ derive_session_key: ((sig_bytes: Uint8Array) => BigUint64Array) | null;
7
+ session_public_key: ((session_key: BigUint64Array) => BigUint64Array) | null;
8
+ create_bet_auth: ((session_key: BigUint64Array, bet_amount: bigint, nonce: bigint) => BigUint64Array) | null;
9
+ compute_server_seed_hash: ((server_seed: BigUint64Array) => BigUint64Array) | null;
10
+ seed_hash_truncated: ((server_seed: BigUint64Array) => BigUint64Array) | null;
11
+ string_to_user_seed: ((input: string) => BigUint64Array) | null;
12
+ string_to_user_seed_hex: ((input: string) => string) | null;
13
+ goldilocks_fields_to_hex: ((fields: BigUint64Array) => string) | null;
14
+ goldilocks_modulus: (() => bigint) | null;
15
+ goldilocks_reduce: ((value: bigint) => bigint) | null;
16
+ }
17
+
18
+ export function useRollyWasm(): RollyWasmResult;
package/js/react.mjs CHANGED
@@ -7,6 +7,9 @@ import init, {
7
7
  create_bet_auth,
8
8
  compute_server_seed_hash,
9
9
  seed_hash_truncated,
10
+ string_to_user_seed,
11
+ string_to_user_seed_hex,
12
+ goldilocks_fields_to_hex,
10
13
  goldilocks_modulus,
11
14
  goldilocks_reduce,
12
15
  } from '../dist/web/rolly_wasm_signer.js';
@@ -51,6 +54,9 @@ export function useRollyWasm() {
51
54
  create_bet_auth: ready ? create_bet_auth : null,
52
55
  compute_server_seed_hash: ready ? compute_server_seed_hash : null,
53
56
  seed_hash_truncated: ready ? seed_hash_truncated : null,
57
+ string_to_user_seed: ready ? string_to_user_seed : null,
58
+ string_to_user_seed_hex: ready ? string_to_user_seed_hex : null,
59
+ goldilocks_fields_to_hex: ready ? goldilocks_fields_to_hex : null,
54
60
  goldilocks_modulus: ready ? goldilocks_modulus : null,
55
61
  goldilocks_reduce: ready ? goldilocks_reduce : null,
56
62
  };
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@rolly-dev/wasm-signer",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Poseidon2 hashing & bet signing for Rolly ZK-Rollup (WASM, Goldilocks field)",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
+ "types": "./js/index.d.ts",
8
9
  "node": {
9
10
  "require": "./js/node.cjs",
10
11
  "import": "./js/node.mjs"
@@ -13,15 +14,17 @@
13
14
  "default": "./js/browser.mjs"
14
15
  },
15
16
  "./react": {
17
+ "types": "./js/react.d.mts",
16
18
  "default": "./js/react.mjs"
17
19
  },
18
20
  "./init": {
21
+ "types": "./dist/web/rolly_wasm_signer.d.ts",
19
22
  "default": "./dist/web/rolly_wasm_signer.js"
20
23
  }
21
24
  },
22
25
  "main": "./js/node.cjs",
23
26
  "module": "./js/browser.mjs",
24
- "types": "./dist/node/rolly_wasm_signer.d.ts",
27
+ "types": "./js/index.d.ts",
25
28
  "files": [
26
29
  "dist/",
27
30
  "js/"