add BigInt to MembershipKey

This commit is contained in:
weboko 2023-01-24 03:16:44 +01:00
parent 468dc29f2e
commit d042be85c9
No known key found for this signature in database
2 changed files with 19 additions and 3 deletions

View File

@ -26,6 +26,20 @@ function concatenate(...input: Uint8Array[]): Uint8Array {
return result;
}
/**
* Transforms Uint8Array into BigInt
* @param array: Uint8Array
* @returns BigInt
*/
function buildBigIntFromUint8Array(array: Uint8Array): bigint {
const bigEndianArray = array.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 stringEncoder = new TextEncoder();
const DEPTH = 20;
@ -59,13 +73,15 @@ export async function create(): Promise<RLNInstance> {
export class MembershipKey {
constructor(
public readonly IDKey: Uint8Array,
public readonly IDCommitment: Uint8Array
public readonly IDCommitment: Uint8Array,
public readonly IDCommitmentBigInt: bigint
) {}
static fromBytes(memKeys: Uint8Array): MembershipKey {
const idKey = memKeys.subarray(0, 32);
const idCommitment = memKeys.subarray(32);
return new MembershipKey(idKey, idCommitment);
const idCommitmentBitInt = buildBigIntFromUint8Array(idCommitment);
return new MembershipKey(idKey, idCommitment, idCommitmentBitInt);
}
}

View File

@ -91,7 +91,7 @@ export class RLNContract {
const membershipKey = await rlnInstance.generateSeededMembershipKey(
signature
);
const pubkey = ethers.BigNumber.from(membershipKey.IDCommitment);
const pubkey = ethers.BigNumber.from(membershipKey.IDCommitmentBigInt);
const depositValue = await this.contract.MEMBERSHIP_DEPOSIT();
const txRegisterResponse: ethers.ContractTransaction =