Skip to content

Commit

Permalink
chore: add seed length error (#1211)
Browse files Browse the repository at this point in the history
* chore: add seed length error

* fix: stateless js lint error
  • Loading branch information
ananas-block authored Sep 30, 2024
1 parent 12f1750 commit b9fb470
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion js/stateless.js/src/utils/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export async function deriveAddress(
seed: Uint8Array,
merkleTreePubkey: PublicKey = defaultTestStateTreeAccounts().merkleTree,
): Promise<PublicKey> {
if (seed.length != 32) {
throw new Error('Seed length is not 32 bytes.');
}
const bytes = merkleTreePubkey.toBytes();
const combined = Buffer.from([...bytes, ...seed]);
const hash = await hashToBn254FieldSizeBe(combined);
Expand Down Expand Up @@ -117,7 +120,11 @@ if (import.meta.vitest) {

describe('deriveAddress function', () => {
it('should derive a valid address from a seed and a merkle tree public key', async () => {
const seed = new Uint8Array([1, 2, 3, 4]);
const seed = new Uint8Array(32);
seed[0] = 1;
seed[1] = 2;
seed[2] = 3;
seed[3] = 4;
const merkleTreePubkey = new PublicKey(
'11111111111111111111111111111111',
);
Expand Down

0 comments on commit b9fb470

Please sign in to comment.