diff --git a/src/rln.ts b/src/rln.ts index f0d4c2d..fd99bfd 100644 --- a/src/rln.ts +++ b/src/rln.ts @@ -32,12 +32,8 @@ function concatenate(...input: Uint8Array[]): Uint8Array { * @returns BigInt */ function buildBigIntFromUint8Array(array: Uint8Array): bigint { - const bigEndianArray = array.slice().reverse(); - // hack for Uint8Array.map that has Uint8Array -> Uint8Array definition that prevents from mapping to other types - const hexString = (bigEndianArray as unknown as number[]) - .map((b) => b.toString(16).padStart(2, "0")) - .join(""); - return BigInt(`0x${hexString}`); + const dataView = new DataView(array.buffer); + return dataView.getBigUint64(0, true); } const stringEncoder = new TextEncoder(); @@ -80,8 +76,8 @@ export class MembershipKey { static fromBytes(memKeys: Uint8Array): MembershipKey { const idKey = memKeys.subarray(0, 32); const idCommitment = memKeys.subarray(32); - const idCommitmentBitInt = buildBigIntFromUint8Array(idCommitment); - return new MembershipKey(idKey, idCommitment, idCommitmentBitInt); + const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment); + return new MembershipKey(idKey, idCommitment, idCommitmentBigInt); } } diff --git a/src/rln_contract.ts b/src/rln_contract.ts index 7ef0b9c..b39463f 100644 --- a/src/rln_contract.ts +++ b/src/rln_contract.ts @@ -91,11 +91,10 @@ export class RLNContract { const membershipKey = await rlnInstance.generateSeededMembershipKey( signature ); - const pubkey = ethers.BigNumber.from(membershipKey.IDCommitmentBigInt); const depositValue = await this.contract.MEMBERSHIP_DEPOSIT(); const txRegisterResponse: ethers.ContractTransaction = - await this.contract.register(pubkey, { + await this.contract.register(membershipKey.IDCommitmentBigInt, { value: depositValue, }); const txRegisterReceipt = await txRegisterResponse.wait();