feat: Updater js class now uses async static construction (#34)

* feat: Updater js class now uses async static construction

* fix: remove the unneccessary getAddress on Updater
buddies-main-deployment
James Prestwich 4 years ago committed by James Prestwich
parent 880273a123
commit 6827db2996
No known key found for this signature in database
GPG Key ID: 7CC174C250AD83AD
  1. 16
      solidity/lib/index.js

@ -26,9 +26,17 @@ extendEnvironment((hre) => {
}
class Updater {
constructor(signer, originSlip44) {
constructor(signer, address, originSlip44, disableWarn) {
if (!disableWarn) {
throw new Error('Please use `Updater.fromSigner()` to instantiate.');
}
this.originSlip44 = originSlip44 ? originSlip44 : 0;
this.signer = signer;
this.address = address;
}
async static fromSigner(signer, originSlip44) {
return new Updater(signer, await signer.getAddress(), originSlip44, true);
}
domain() {
@ -38,8 +46,12 @@ extendEnvironment((hre) => {
);
}
message(oldRoot, newRoot) {
return ethers.utils.concat([this.domain(), oldRoot, newRoot]);
}
async signUpdate(oldRoot, newRoot) {
let message = ethers.utils.concat([this.domain(), oldRoot, newRoot]);
let message = this.message(oldRoot, newRoot);
let signature = await this.signer.signMessage(message);
return {
origin: this.originSlip44,

Loading…
Cancel
Save