mirror of
https://github.com/logos-messaging/js-rln.git
synced 2026-01-05 23:23:12 +00:00
fix: zeroPad util (#87)
* fix: idCommitmnet little endianess * stop double conversion * fix problem with zeroPad * fix test
This commit is contained in:
parent
0c98a266e2
commit
9b1e8187da
1
example/package-lock.json
generated
1
example/package-lock.json
generated
@ -19,6 +19,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"..": {
|
"..": {
|
||||||
|
"name": "@waku/rln",
|
||||||
"version": "0.1.1",
|
"version": "0.1.1",
|
||||||
"license": "MIT OR Apache-2.0",
|
"license": "MIT OR Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@ -47,3 +47,17 @@ export function buildBigIntFromUint8Array(array: Uint8Array): bigint {
|
|||||||
const dataView = new DataView(array.buffer);
|
const dataView = new DataView(array.buffer);
|
||||||
return dataView.getBigUint64(0, true);
|
return dataView.getBigUint64(0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fills with zeros to set length
|
||||||
|
* @param array little endian Uint8Array
|
||||||
|
* @param length amount to pad
|
||||||
|
* @returns little endian Uint8Array padded with zeros to set length
|
||||||
|
*/
|
||||||
|
export function zeroPadLE(array: Uint8Array, length: number): Uint8Array {
|
||||||
|
const result = new Uint8Array(length);
|
||||||
|
for (let i = 0; i < length; i++) {
|
||||||
|
result[i] = array[i] || 0;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
@ -66,7 +66,7 @@ describe("RLN Contract abstraction", () => {
|
|||||||
function mockEvent(): ethers.Event {
|
function mockEvent(): ethers.Event {
|
||||||
return {
|
return {
|
||||||
args: {
|
args: {
|
||||||
idCommitment: "0x9e7d3f8f8c7a1d2bef96a2e8dbb8e7c1ea9a9ab78d6b3c6c3c",
|
idCommitment: { _hex: "0xb3df1c4e5600ef2b" },
|
||||||
index: ethers.BigNumber.from(1),
|
index: ethers.BigNumber.from(1),
|
||||||
},
|
},
|
||||||
} as unknown as ethers.Event;
|
} as unknown as ethers.Event;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { hexToBytes } from "@waku/utils/bytes";
|
import { hexToBytes } from "@waku/utils/bytes";
|
||||||
import { ethers } from "ethers";
|
import { ethers } from "ethers";
|
||||||
|
|
||||||
|
import { zeroPadLE } from "./byte_utils.js";
|
||||||
import { RLN_REGISTRY_ABI, RLN_STORAGE_ABI } from "./constants.js";
|
import { RLN_REGISTRY_ABI, RLN_STORAGE_ABI } from "./constants.js";
|
||||||
import { IdentityCredential, RLNInstance } from "./rln.js";
|
import { IdentityCredential, RLNInstance } from "./rln.js";
|
||||||
import { MerkleRootTracker } from "./root_tracker.js";
|
import { MerkleRootTracker } from "./root_tracker.js";
|
||||||
@ -170,7 +171,7 @@ export class RLNContract {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const idCommitment = hexToBytes(_idCommitment?._hex);
|
const idCommitment = zeroPadLE(hexToBytes(_idCommitment?._hex), 32);
|
||||||
rlnInstance.insertMember(idCommitment);
|
rlnInstance.insertMember(idCommitment);
|
||||||
this._members.set(index.toNumber(), {
|
this._members.set(index.toNumber(), {
|
||||||
index,
|
index,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user