From 88a28a11e3368285ff96b1560b157d29ea05837b Mon Sep 17 00:00:00 2001 From: Sasha <118575614+weboko@users.noreply.github.com> Date: Wed, 19 Apr 2023 23:28:04 +0200 Subject: [PATCH] feat!: add registerMemberFromMembershipKey (#56) * add registerMemberFromMembershipKey * make better naming --- src/rln_contract.spec.ts | 2 +- src/rln_contract.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/rln_contract.spec.ts b/src/rln_contract.spec.ts index d8c5d43..c6159e9 100644 --- a/src/rln_contract.spec.ts +++ b/src/rln_contract.spec.ts @@ -46,7 +46,7 @@ describe("RLN Contract abstraction", () => { } as unknown as ethers.Contract; const contractSpy = chai.spy.on(rlnContract["_contract"], "register"); - await rlnContract.registerMember(rlnInstance, mockSignature); + await rlnContract.registerWithSignature(rlnInstance, mockSignature); chai.expect(contractSpy).to.have.been.called(); }); diff --git a/src/rln_contract.ts b/src/rln_contract.ts index b39463f..b1b8f62 100644 --- a/src/rln_contract.ts +++ b/src/rln_contract.ts @@ -1,7 +1,7 @@ import { ethers } from "ethers"; import { RLN_ABI } from "./constants.js"; -import { RLNInstance } from "./rln.js"; +import { MembershipKey, RLNInstance } from "./rln.js"; type Member = { pubkey: string; @@ -84,13 +84,20 @@ export class RLNContract { rlnInstance.insertMember(idCommitment); } - public async registerMember( + public async registerWithSignature( rlnInstance: RLNInstance, signature: string ): Promise { const membershipKey = await rlnInstance.generateSeededMembershipKey( signature ); + + return this.registerWithKey(membershipKey); + } + + public async registerWithKey( + membershipKey: MembershipKey + ): Promise { const depositValue = await this.contract.MEMBERSHIP_DEPOSIT(); const txRegisterResponse: ethers.ContractTransaction =