|
1 | 1 | import { BorshSchema, borshDeserialize } from "borsher"; |
2 | 2 |
|
3 | | -export interface CommitmentSnapshot { |
4 | | - notes_root: number[]; |
5 | | - nullified_notes_root: number[]; |
| 3 | +export interface HyliUtxoStateBlob { |
| 4 | + output_note_commit0: number[]; |
| 5 | + output_note_commit1: number[]; |
| 6 | + nullifier0: number[]; |
| 7 | + nullifier1: number[]; |
6 | 8 | } |
7 | 9 |
|
8 | | -export interface UtxoBlob { |
9 | | - commit0: number[]; |
10 | | - commit1: number[]; |
| 10 | +export interface HyliUtxoBlob { |
| 11 | + input_note_commit0: number[]; |
| 12 | + input_note_commit1: number[]; |
11 | 13 | nullifier0: number[]; |
12 | 14 | nullifier1: number[]; |
13 | 15 | } |
14 | 16 |
|
15 | | -const commitmentSnapshotSchema = BorshSchema.Struct({ |
16 | | - notes_root: BorshSchema.Array(BorshSchema.u8, 32), |
17 | | - nullified_notes_root: BorshSchema.Array(BorshSchema.u8, 32), |
18 | | -}); |
| 17 | +export interface HyliSmtInclusionProofBlob { |
| 18 | + input_note_commit0: number[]; |
| 19 | + input_note_commit1: number[]; |
| 20 | + notes_root: number[]; |
| 21 | +} |
19 | 22 |
|
20 | | -export const deserializeUtxoStateAction = (data: number[]): CommitmentSnapshot => { |
21 | | - return borshDeserialize(commitmentSnapshotSchema, new Uint8Array(data)); |
| 23 | +export const deserializeUtxoStateAction = (data: number[]): HyliUtxoStateBlob => { |
| 24 | + if (data.length !== 128) { |
| 25 | + throw new Error(`Expected 128 bytes for utxo blob, got ${data.length}`); |
| 26 | + } |
| 27 | + return { |
| 28 | + output_note_commit0: data.slice(0, 32), |
| 29 | + output_note_commit1: data.slice(32, 64), |
| 30 | + nullifier0: data.slice(64, 96), |
| 31 | + nullifier1: data.slice(96, 128), |
| 32 | + }; |
22 | 33 | }; |
23 | 34 |
|
24 | | -export const deserializeUtxoBlob = (data: number[]): UtxoBlob => { |
| 35 | +export const deserializeUtxoBlob = (data: number[]): HyliUtxoBlob => { |
25 | 36 | if (data.length !== 128) { |
26 | 37 | throw new Error(`Expected 128 bytes for utxo blob, got ${data.length}`); |
27 | 38 | } |
28 | 39 | return { |
29 | | - commit0: data.slice(0, 32), |
30 | | - commit1: data.slice(32, 64), |
| 40 | + input_note_commit0: data.slice(0, 32), |
| 41 | + input_note_commit1: data.slice(32, 64), |
31 | 42 | nullifier0: data.slice(64, 96), |
32 | 43 | nullifier1: data.slice(96, 128), |
33 | 44 | }; |
34 | 45 | }; |
| 46 | + |
| 47 | +export const deserializeSmtInclusionProof = (data: number[]): HyliSmtInclusionProofBlob => { |
| 48 | + if (data.length < 96) { |
| 49 | + throw new Error(`Expected at least 96 bytes for SMT inclusion proof, got ${data.length}`); |
| 50 | + } |
| 51 | + return { |
| 52 | + input_note_commit0: data.slice(0, 32), |
| 53 | + input_note_commit1: data.slice(32, 64), |
| 54 | + notes_root: data.slice(64, 96), |
| 55 | + }; |
| 56 | +}; |
0 commit comments