mirror of
https://github.com/logos-messaging/js-rln.git
synced 2026-01-08 00:23:12 +00:00
add BigInt to MembershipKey
This commit is contained in:
parent
468dc29f2e
commit
d042be85c9
20
src/rln.ts
20
src/rln.ts
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user