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

Issue 2978: Verify signature for address helper #3703

Conversation

LunarFang416
Copy link

Closes solana-labs/web3.js-issue-conveyer#11

Added documentation for the verifySignatureForAddress helper function, which simplifies the process of verifying digital signatures for a given address. The function internally converts the address to a public key and verifies the signature for the associated data.

Copy link

changeset-bot bot commented Dec 10, 2024

⚠️ No Changeset found

Latest commit: e5c420b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@mergify mergify bot added the community label Dec 10, 2024
Copy link
Contributor

@mcintyre94 mcintyre94 left a comment

Choose a reason for hiding this comment

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

Thanks for taking a look at this, but I agree with Steve's comment on the issue here: https://github.com/solana-labs/solana-web3.js/issues/2978#issuecomment-2436528156

I don't think we want to implement this like this, because constructing the public key is relatively expensive and we don't want to encourage code that does that repeatedly. Eg if you verify 100 signatures then you should construct the public key once and then call crypto.subtle.verify 100 times, rather than calling this function 100 times.

Could you change this to just take address: Address and return Promise<CryptoKey>? The actual verification would live outside. So this could just be createPublicKeyForAddress or something like that.

In addition to land this PR we would need unit tests for the new function

It'd also be nice to update the deserialize-transaction example to use this function since that motivated the issue and it'd demonstrate its usage nicely.

): Promise<boolean> {
try {
// Encode the address to bytes
const addressBytes: ReadonlyUint8Array = new Uint8Array(getBase58Encoder().encode(address));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const addressBytes: ReadonlyUint8Array = new Uint8Array(getBase58Encoder().encode(address));
const addressBytes = getAddressEncoder().encode(address);

@steveluscher
Copy link
Collaborator

The 2.x line has moved. Can you reopen this PR at https://github.com/anza-xyz/solana-web3.js so that you get credit for the change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Experimental: Add a function to verify a signature for an address
3 participants