Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented avoid throwing an error if private key is missing unless .send() is executed #931

Merged
merged 8 commits into from
May 31, 2023
11 changes: 7 additions & 4 deletions src/lib/account_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1899,10 +1899,13 @@ function addMissingSignatures(
let i = additionalPublicKeys.findIndex((pk) =>
pk.equals(accountUpdate.body.publicKey).toBoolean()
);
if (i === -1)
throw Error(
`addMissingSignatures: Cannot add signature for ${accountUpdate.publicKey.toBase58()}, private key is missing.`
);
if (i === -1) {
// private key is missing, but we are not throwing an error here
// there is a change signature will be added by the wallet
// if not, error will be thrown by verifyAccountUpdate
// while .send() execution
return accountUpdate as AccountUpdate & { lazyAuthorization?: LazyProof };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're lying about the type here, I'm not sure if that's a good idea :/ Could you instead at least set the signature to an empty string or dummy signature, and use Authorization.setSignature? that way, at least the types are correct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed an update, thanks for noticing this! I just copy-pasted badly...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, looks good to merge now!

}
privateKey = additionalKeys[i];
}
let transactionCommitment = accountUpdate.body.useFullCommitment.toBoolean()
Expand Down
Loading