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

feat: add passkey authenticator to sui #18126

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

feat: add passkey authenticator to sui #18126

wants to merge 13 commits into from

Conversation

joyqvq
Copy link
Contributor

@joyqvq joyqvq commented Jun 7, 2024

Description

implementation for sui-foundation/sips#9

Test plan

added unit tests and e2e tests. also tested with real passkey result from frontend

credential id (base64): 9Aj01fIn/T555beIoJ7swA87mLc=

pubkey (hex): 03e61ebc6b1796021e33fd3937298f2c460e77e5bb7fbeb3c42f7e0f11f67792cb

sui address: 0xb88d3e91880e6befc13881a4a7d5b4d2dfa402ae2b149cd9b36d6e084ba25925

tx bytes: AAAAALiNPpGIDmvvwTiBpKfVtNLfpAKuKxSc2bNtbghLolklAfuV/HGZhQdRfe9WXfY8A7b76qucni1/FFaa7LlYHgcGAgAAAAAAAAAgUuv6miRJNCj1OhyRzP5sZyrIU1DSRTLrXfvbmp9cuuu4jT6RiA5r78E4gaSn1bTS36QCrisUnNmzbW4IS6JZJegDAAAAAAAAgIQeAAAAAAAA

tx digest (hex): 000000f1b6d366d79ae9d2d98da7909b8fa4d856f64c4b9663a1d875d7823f5e8585e4

authenticatorData (hex): 49960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97631d00000000

clientDataJSON: `{"type":"webauthn.get","challenge":"AAAA8bbTZtea6dLZjaeQm4-k2Fb2TEuWY6HYddeCP16FheQ","origin":"http://localhost:5173","crossOrigin":false}`

r1 signature (hex): 02ecbbf52b29ec5d306501d00f175bd084d909a4f9a92318cf3df1fa3a86028cbe2dcc606a99f69817991bab559b744039c21b417c988056969b8fec78d17bad7c03e61ebc6b1796021e33fd3937298f2c460e77e5bb7fbeb3c42f7e0f11f67792cb

encoded sui signature (base64): BiVJlg3liA6MaHQ0Fw9kdmBbj+SuuaKGMseZXPO6gx2XYx0AAAAAigF7InR5cGUiOiJ3ZWJhdXRobi5nZXQiLCJjaGFsbGVuZ2UiOiJBQUFBOGJiVFp0ZWE2ZExaamFlUW00LWsyRmIyVEV1V1k2SFlkZGVDUDE2RmhlUSIsIm9yaWdpbiI6Imh0dHA6Ly9sb2NhbGhvc3Q6NTE3MyIsImNyb3NzT3JpZ2luIjpmYWxzZX1iAuy79Ssp7F0wZQHQDxdb0ITZCaT5qSMYzz3x+jqGAoy+Lcxgapn2mBeZG6tVm3RAOcIbQXyYgFaWm4/seNF7rXwD5h68axeWAh4z/Tk3KY8sRg535bt/vrPEL34PEfZ3kss=

encoded webuahthn signature length: 278

signature verified: true

localnet onchain verified, digest: DSt3BdgByH5WgKuysdwPMLrCtH2HZhvtzGNBJarBA7VR

Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • Indexer:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:

Copy link

vercel bot commented Jun 7, 2024

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

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 26, 2024 10:21pm
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Jun 26, 2024 10:21pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Jun 26, 2024 10:21pm
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Jun 26, 2024 10:21pm

Copy link
Contributor

@benr-ml benr-ml left a comment

Choose a reason for hiding this comment

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

Let's control the rollout of this feature with a protocol config.

Cargo.toml Show resolved Hide resolved
crates/sui-types/src/passkey_authenticator.rs Outdated Show resolved Hide resolved
crates/sui-types/src/passkey_authenticator.rs Outdated Show resolved Hide resolved
crates/sui-types/src/passkey_authenticator.rs Outdated Show resolved Hide resolved
})?;
if author
!= SuiAddress::from(
&PublicKey::try_from_bytes(
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want it to be derived exactly like any r1 account? what are the pros and cons of not having it as a different account?

crates/sui-types/src/passkey_authenticator.rs Outdated Show resolved Hide resolved
@joyqvq
Copy link
Contributor Author

joyqvq commented Jun 10, 2024

addressed comments.

todo: add protocol config for devnet only(when review is stable to avoid merge conflicts)

open q for meeting:

  1. define it as r1 type at deser? how to make jsonschema work - done, requires a default impl for r1 pk and sig in fastcrypto
  2. any enforcing checks on origin? - no need
  3. derive address from pk or differently? - use passkey flag instead
  4. go over test cases, todo: add them to transaction_tests - done. serde test and a few hardcoded test cases needs to be in unit test, everything else in e2e test.

@@ -2465,7 +2465,8 @@ impl VersionedProtocolMessage for SenderSignedData {
}
GenericSignature::Signature(_)
| GenericSignature::MultiSigLegacy(_)
| GenericSignature::ZkLoginAuthenticator(_) => (),
| GenericSignature::ZkLoginAuthenticator(_)
| GenericSignature::PasskeyAuthenticator(_) => (),
Copy link
Contributor

Choose a reason for hiding this comment

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

we need to check for a protocol flag here, as the comments say (btw can you remove the comment about the code doing nothing, since checks have been added since that comment was written)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

    fn check_user_signature_protocol_compatibility(&self, config: &ProtocolConfig) -> SuiResult {
        if !config.zklogin_auth() && self.has_zklogin_sig() {
            return Err(SuiError::UnsupportedFeatureError {
                error: "zklogin is not enabled on this network".to_string(),
            });
        }

looks like we check this at a different place too, maybe we should keep them all at the same place?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we should be calling check_user_signature_protocol_compatibility inside here, and then call this function from validity_check()?
I have meant to continue working on the validity check refactoring but got distracted, will continue looking as we ll

Copy link
Contributor

Choose a reason for hiding this comment

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

btw I am refactoring this part in #18342


/// Normalized r1 signature returned by passkey.
/// Initialized from `user_signature` in `RawPasskeyAuthenticator`.
#[serde(skip)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need #[serde(skip)]? Does JsonSchema use it?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah JsonSchema recognizes serde attrs, but that's a good question on if we do need to include it or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Secp256r1Signature, Secp256r1PublicKey doesn't implement jsonschema - i can try adding them to fastcrypto, but is it necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a dumb question, how is this open json rpc generated spec being used?

Copy link
Contributor

Choose a reason for hiding this comment

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

honestly, for crypto stuff i think it can be ignored for now since afaik we just serialize crypto sigs to a base64 encoding in jsonrpc. So this is all ignored I believe.

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 see, ill leave it as is then.

crates/sui-types/src/passkey_authenticator.rs Show resolved Hide resolved
"description": "`clientDataJSON` contains a JSON-compatible UTF-8 encoded string of the client data which is passed to the authenticator by the client during the authentication request (see [CollectedClientData](https://www.w3.org/TR/webauthn-2/#dictdef-collectedclientdata))",
"type": "string"
},
"digest": {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this needed?
what about the signature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Secp256r1Signature, Secp256r1PublicKey does not currently derive JsonSchema, i will have to write a custom one. but since the generated format is not needed, we can ignore these fields.

@@ -2378,6 +2380,11 @@ impl SenderSignedData {
error: "zklogin is not enabled on this network".to_string(),
});
}
if !config.passkey_auth() && self.has_passkey_sig() {
Copy link
Contributor

Choose a reason for hiding this comment

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

btw I have refactored this function, you may have to rebase. The checks are now done with the matches

@joyqvq
Copy link
Contributor Author

joyqvq commented Jun 26, 2024

just went through a few more rebase - no major changes other than sequencing behind a bunch of other feature flags in protocol config. PTAL @benr-ml @bmwill @mystenmark @lxfind

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.

None yet

5 participants