@rolly-dev/wasm-signer 0.5.1 → 0.6.2

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.
@@ -1,6 +1,17 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
+ /**
5
+ * Split a u64 amount into (lo, hi) u32 pair matching the circuit representation.
6
+ *
7
+ * Returns `[amount_lo, amount_hi]` as a `Uint32Array` of length 2.
8
+ *
9
+ * ```js
10
+ * const [lo, hi] = amount_split(123456789n);
11
+ * ```
12
+ */
13
+ export function amount_split(amount: bigint): Uint32Array;
14
+
4
15
  /**
5
16
  * Full Poseidon2 hash of an 8-element server seed.
6
17
  *
@@ -13,6 +24,17 @@
13
24
  */
14
25
  export function compute_server_seed_hash(server_seed: BigUint64Array): BigUint64Array;
15
26
 
27
+ /**
28
+ * Compute the transaction message hash (for debugging / verification).
29
+ *
30
+ * Returns `BigUint64Array` of length 4 — the same hash the circuit computes.
31
+ *
32
+ * ```js
33
+ * const hash = compute_tx_msg_hash(5, userId, 0, amountLo, amountHi);
34
+ * ```
35
+ */
36
+ export function compute_tx_msg_hash(tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number): BigUint64Array;
37
+
16
38
  /**
17
39
  * Create a `bet_auth` MAC that proves the user authorized this specific bet.
18
40
  *
@@ -123,6 +145,106 @@ export function poseidon2_hash(input: BigUint64Array): BigUint64Array;
123
145
  */
124
146
  export function poseidon2_two_to_one(left: BigUint64Array, right: BigUint64Array): BigUint64Array;
125
147
 
148
+ /**
149
+ * Derive a Schnorr secret key from entropy bytes (e.g. MetaMask signature).
150
+ *
151
+ * Takes at least 32 bytes, uses `Scalar::decode_reduce` to map them into
152
+ * the ECgFp5 scalar field. Returns hex-encoded secret key (80 chars = 40 bytes).
153
+ *
154
+ * ```js
155
+ * const skHex = schnorr_keygen(sigBytes.slice(0, 32));
156
+ * ```
157
+ */
158
+ export function schnorr_keygen(entropy: Uint8Array): string;
159
+
160
+ /**
161
+ * Get the w-encoding of a public key as 5 Goldilocks field elements (for circuit witness).
162
+ *
163
+ * Returns `BigUint64Array` of length 5.
164
+ *
165
+ * ```js
166
+ * const encode = schnorr_pk_encode(pkHex);
167
+ * // encode.length === 5
168
+ * ```
169
+ */
170
+ export function schnorr_pk_encode(pk_hex: string): BigUint64Array;
171
+
172
+ /**
173
+ * Compute pk_hash = Poseidon2(w_encoding[5]) from a hex-encoded public key.
174
+ *
175
+ * The w-encoding is the 40-byte (80 hex) representation returned by `schnorr_pubkey`.
176
+ * pk_hash is stored in the Merkle tree to bind the Schnorr key to an account.
177
+ *
178
+ * Returns `BigUint64Array` of length 4.
179
+ *
180
+ * ```js
181
+ * const pkHash = schnorr_pk_hash(pkHex);
182
+ * ```
183
+ */
184
+ export function schnorr_pk_hash(pk_hex: string): BigUint64Array;
185
+
186
+ /**
187
+ * Compute pk_hash as a hex string (for convenience).
188
+ *
189
+ * ```js
190
+ * const pkHashHex = schnorr_pk_hash_hex(pkHex);
191
+ * ```
192
+ */
193
+ export function schnorr_pk_hash_hex(pk_hex: string): string;
194
+
195
+ /**
196
+ * Compute the Schnorr public key from a hex-encoded secret key.
197
+ *
198
+ * Returns hex-encoded w-encoding of the ECgFp5 point (80 chars = 40 bytes).
199
+ *
200
+ * ```js
201
+ * const pkHex = schnorr_pubkey(skHex);
202
+ * ```
203
+ */
204
+ export function schnorr_pubkey(sk_hex: string): string;
205
+
206
+ /**
207
+ * Sign a ChangePubKey (tx_type=9) transaction.
208
+ *
209
+ * msg_hash = Poseidon2(9, user_id, new_pk_hash[0..4])
210
+ *
211
+ * The old key signs this message to authorize key rotation.
212
+ *
213
+ * Returns a JS object: `{ pubkey: "hex", sig_r: "hex", sig_s: "hex" }`
214
+ *
215
+ * ```js
216
+ * const sig = schnorr_sign_cpk(oldSkHex, userId, newPkHashArray);
217
+ * ```
218
+ */
219
+ export function schnorr_sign_cpk(old_sk_hex: string, user_id: number, new_pk_hash: BigUint64Array): any;
220
+
221
+ /**
222
+ * Sign a transaction with Schnorr (ECgFp5).
223
+ *
224
+ * msg_hash = Poseidon2(tx_type, user_id, currency_id, amount_lo, amount_hi)
225
+ *
226
+ * Returns a JS object: `{ pubkey: "hex", sig_r: "hex", sig_s: "hex" }`
227
+ *
228
+ * ```js
229
+ * const sig = schnorr_sign_tx(skHex, 5, userId, 0, amountBigInt);
230
+ * // sig.pubkey, sig.sig_r, sig.sig_s — all hex strings (80 chars each)
231
+ * ```
232
+ */
233
+ export function schnorr_sign_tx(sk_hex: string, tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number): any;
234
+
235
+ /**
236
+ * Verify a Schnorr signature for a transaction on the backend.
237
+ *
238
+ * Checks: s·G == R + H(R‖pk‖msg)·pk
239
+ *
240
+ * Returns `true` if signature is valid, `false` otherwise.
241
+ *
242
+ * ```js
243
+ * const ok = schnorr_verify_tx(pubkeyHex, sigRHex, sigSHex, 5, userId, 0, amountLo, amountHi);
244
+ * ```
245
+ */
246
+ export function schnorr_verify_tx(pk_hex: string, sig_r_hex: string, sig_s_hex: string, tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number): boolean;
247
+
126
248
  /**
127
249
  * Truncated seed hash — first 2 elements of `Poseidon2(server_seed)`.
128
250
  *