Skip to content

Conversation

@satoshiotomakan
Copy link
Collaborator

@satoshiotomakan satoshiotomakan commented Oct 1, 2025

This pull request adds support for Passkey Session operations in the Barz module, enabling registration, removal, nonce encoding, and batch execution of transactions using passkey sessions. It introduces new ABI encoding functions, FFI bindings, and comprehensive tests to ensure correct behavior.

Passkey Session ABI and Encoding Support

  • Added BizPasskeySessionAccount struct in biz_passkey_session.rs with methods for registering, removing, and executing with passkey sessions, including ABI encoding logic for these operations.
  • Implemented helper functions in barz/core.rs for encoding register, remove, nonce, and batch execution calls for passkey sessions, with error handling for invalid public keys and nonce values. [1] [2]

FFI Bindings

  • Add Biz module
    • BREAKING Move Barz.getEncodedHash to Biz.getEncodedHash
    • BREAKING Move Barz.getSignedHash to Biz.getSignedHash
    • Add Biz.encodeRegisterSessionCall
    • Add Biz.encodeRemoveSessionCall
    • Add Biz.encodePasskeySessionNonce
    • Add Biz.encodeExecuteWithPasskeySessionCall
  • Add Eip7702 module
    • BREAKING Move Barz.getAuthorizationHash to Eip7702.getAuthorizationHash
    • BREAKING Move Barz.signAuthorization to Eip7702.signAuthorization
  • Add WebAuthnSolidity module with the following methods:
    • WebAuthnSolidity.getMessageHash
    • WebAuthnSolidity.GetFormattedSignature

Testing and Validation

  • Added extensive tests in barz_ffi.rs to validate passkey session registration, removal, nonce encoding, and batch execution, ensuring ABI outputs match expected values.

Refactoring and Internal Improvements

  • Refactored batch encoding logic in biz.rs to use a dedicated function for array token conversion, improving code clarity and reuse. [1] [2] [3] [4]
  • Updated module imports and error definitions to support new functionality and error cases. [1] [2] [3] [4]

/// \return The signed authorization.
#[tw_ffi(ty = static_function, class = TWEip7702, name = SignAuthorization)]
#[no_mangle]
pub unsafe extern "C" fn tw_eip7702_sign_authorization(
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the Ethereum message signature functionality meet your needs?

Refers:

MessageType_eip7702_authorization = 5;

fn test_message_signer_sign_eip7702_authorization() {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi @10gic, I think it does, but our client app depends on the function already, I want to leave it as is for now. But let me mark as deprecated

@satoshiotomakan satoshiotomakan marked this pull request as ready for review October 2, 2025 17:06
@github-actions
Copy link

github-actions bot commented Oct 2, 2025

Binary size comparison

➡️ aarch64-apple-ios:

- 14.11 MB
+ 14.15 MB 	 +50 KB

➡️ aarch64-apple-ios-sim:

- 14.11 MB
+ 14.16 MB 	 +50 KB

➡️ aarch64-linux-android:

- 18.57 MB
+ 18.64 MB 	 +72 KB

➡️ armv7-linux-androideabi:

- 15.53 MB
+ 15.59 MB 	 +60 KB

➡️ wasm32-unknown-emscripten:

- 13.23 MB
+ 13.29 MB 	 +54 KB

Copy link
Collaborator

@gupnik gupnik left a comment

Choose a reason for hiding this comment

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

Looks great @satoshiotomakan! Just asked for one minor clarification.


/// Encodes `Biz.removeSession` function call to deregister a session passkey public key.
///
/// \param session_passkey_public_key The nist256p1 (aka secp256p1) public key of the session passkey.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we support both nist and secp here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nist256p1 and secp256p1 are names of the same elliptic curve, however "official" and more recognized name is secp256p1. In WalletCore, we inherited this name from C++ TWCurve enum and TrezorCrypto, and we continue naming it like that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

"0x49960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630500000000";
let client_data_json = r#"{"type":"webauthn.get","challenge":"fRMDMfFrs9K8PXLbAoedB0XURSWS5Wcj3osnzx7gBsc","origin":"https://sign.coinbase.com","crossOrigin":false}"#;

// secp256p1 (nist256p1) private key.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same

use tw_memory::ffi::{Nonnull, NullableMut, RawPtrTrait};
use tw_misc::try_or_else;

/// Computes WebAuthn message hash to be signed with secp256p1 private key.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It says secp here though.

@satoshiotomakan satoshiotomakan merged commit 5198377 into master Oct 3, 2025
15 of 16 checks passed
@satoshiotomakan satoshiotomakan deleted the feat/barz-passkey branch October 3, 2025 07:49
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.

4 participants