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

sdk: fix personal message to use bcs #12997

Merged
merged 3 commits into from
Jul 19, 2023
Merged

sdk: fix personal message to use bcs #12997

merged 3 commits into from
Jul 19, 2023

Conversation

joyqvq
Copy link
Contributor

@joyqvq joyqvq commented Jul 14, 2023

Description

fix a bug that the signMessage in rust vs typescript has a discrepancy. this is make typescript use bcs serialization for a vector instead of just a plain vector.

PersonalMessage {
  message: Vec<u8>
}

Test Plan

existing tests in ts still passes (bc verify and sign are both changed to the new format).
tested against rust that a ts produced sig now verifies in rust.


If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process.

Type of Change (Check all that apply)

  • protocol change
  • user-visible impact
  • breaking change for a client SDKs
  • breaking change for FNs (FN binary must upgrade)
  • breaking change for validators or node operators (must upgrade binaries)
  • breaking change for on-chain data layout
  • necessitate either a data wipe or data migration

Release notes

@joyqvq joyqvq requested a review from a team as a code owner July 14, 2023 15:32
@vercel
Copy link

vercel bot commented Jul 14, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
explorer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2023 7:38pm
explorer-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2023 7:38pm
multisig-toolkit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2023 7:38pm
sui-kiosk ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2023 7:38pm
sui-wallet-kit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2023 7:38pm
wallet-adapter ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2023 7:38pm

export async function verifySignature(
bytes: Uint8Array,
signature: SerializedSignature,
): Promise<false | PublicKey> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this is a good way to handle returns of these methods, but I think getting back the public key is useful here so you can also validate that the key used to sign a message was the expected one

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 dont have strong preference but slight preference just having it to return true/false is more intuitive and easier to return to the outer level

Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than false | publicKey I wonder if this should just throw? I do agree getting the public key back is pretty useful, because often you want to validate ownership of an address and without the return here it becomes multi-step.

Copy link
Contributor

Choose a reason for hiding this comment

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

updated this to throw

@hayes-mysten
Copy link
Contributor

@Jordan-Mysten I updated this with the changes we talked about today. I forgot we were going to do this as 2 separate changes, I can split it up if thats easier, but I think most of the changes here are pretty straight forward

sdk/typescript/src/cryptography/publickey.ts Show resolved Hide resolved
sdk/typescript/src/keypairs/ed25519/publickey.ts Outdated Show resolved Hide resolved
sdk/typescript/src/utils/verify.ts Outdated Show resolved Hide resolved
export async function verifySignature(
bytes: Uint8Array,
signature: SerializedSignature,
): Promise<false | PublicKey> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than false | publicKey I wonder if this should just throw? I do agree getting the public key back is pretty useful, because often you want to validate ownership of an address and without the return here it becomes multi-step.

@hayes-mysten hayes-mysten merged commit 09f4ed3 into main Jul 19, 2023
@hayes-mysten hayes-mysten deleted the fix-sdk branch July 19, 2023 19:06
hayes-mysten added a commit that referenced this pull request Jul 19, 2023
## Description 

Closes #12931. Add feature to
verify a multisig in typescript. depends on
#12997
## Test Plan 

unit tests. 
---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes

---------

Co-authored-by: Michael Hayes <michael.hayes@mystenlabs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants