Skip to content

feat(cast): KeyAuthorization signing via non-EOA wallets#14743

Merged
figtracer merged 32 commits into
masterfrom
mablr/sign-authorization-keychain
Jun 12, 2026
Merged

feat(cast): KeyAuthorization signing via non-EOA wallets#14743
figtracer merged 32 commits into
masterfrom
mablr/sign-authorization-keychain

Conversation

@mablr

@mablr mablr commented May 13, 2026

Copy link
Copy Markdown
Member

Depends on foundry-rs/foundry-core#67 and foundry-rs/foundry-browser-wallet#67 foundry-rs/foundry-browser-wallet#75.

Motivation

Close OSS-168

This PR wires the Foundry side of browser/passkey-backed KeyAuthorization signing into cast.

Changes

  • Supports normal root signers and --browser/passkey-backed root signers.
  • Rename as subcommand as cast key-authorization keeps cast key-auth as the short alias.
  • Emits JSON metadata including signature hash, RLP length, signer, authorized key type, signature type, and witness.

CLI example

Sign an authorization with the browser wallet:

cast key-authorization sign \
  0x1111111111111111111111111111111111111111 \
  --chain-id 4217 \
  --key-type secp256k1 \
  --expiry 1782647677 \
  --limit 0x20c0000000000000000000000000000000000000:10000000:1d \
  --scope 0x20c0000000000000000000000000000000000000:transfer \
  --browser \
  --json

Manual browser-wallet signing was also tested against foundry-browser-wallet running locally with npm run dev.

Add 'cast keychain sign-authorization' (alias 'sign-auth') for signing
a Tempo KeyAuthorization with the connected browser/passkey wallet.

- Converts CLI flags (--limit, --scope/--scopes, --expiry, --chain-id,
  key type) into tempo-primitives types
- Drives BrowserSigner::sign_key_authorization via the local wallet
  bridge
- Prints the RLP-encoded SignedKeyAuthorization as 0x-prefixed hex (or
  JSON)

Enforce policy completeness at clap arg-parsing time:
- 'spending_policy' group: --limit | --deny-all-spending (mutually
  exclusive, required)
- 'call_policy' group: --scope | --scopes | --deny-all-calls (mutually
  exclusive, required)

Cargo.toml: temporary local path override for foundry-wallets while the
companion foundry-core branch lands.

Co-authored-by: Amp <amp@ampcode.com>
@github-actions github-actions Bot added the stale label Jun 5, 2026
@mablr mablr added stop-stale and removed stale labels Jun 5, 2026
@foundry-rs foundry-rs deleted a comment from github-actions Bot Jun 5, 2026
@mablr mablr changed the title feat(cast): keychain sign-authorization subcommand feat(cast): add keychain authorization helpers Jun 5, 2026
@mablr mablr changed the title feat(cast): add keychain authorization helpers feat(cast): keychain authorization signing via non-EOA wallets Jun 5, 2026
@mablr mablr marked this pull request as ready for review June 5, 2026 15:29
Comment thread crates/cast/src/cmd/keychain.rs
@figtracer

Copy link
Copy Markdown
Member

One remaining pre-merge blocker: foundry-wallets still points at the moving mablr/sign-authorization-keychain branch.

Once foundry-core#67 lands, please switch this to the merged/released dependency, or at least a fixed rev/tag, so builds are reproducible.

@0xKarl98

0xKarl98 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

cast keychain authorize --limit now parses TOKEN:AMOUNT[:PERIOD] into TokenLimit.period at crates/cast/src/cmd/keychain.rs:515, but the pre-T3 legacy path later converts those limits into LegacyTokenLimit by copying only token and amount at crates/cast/src/cmd/keychain.rs:2695.

This means a user can request a periodic limit, have the command succeed, and silently receive a non-periodic legacy authorization. The legacy branch should reject any limit.period != 0 with a clear error that periodic limits require a T3-
capable AccountKeychain.

Suggested as following :

if let Some(limit) = limits.iter().find(|limit| limit.period != 0) {
    eyre::bail!(
        "legacy AccountKeychain authorization does not support periodic limits; \
         remove the period from --limit {}:{}:{} or use a Tempo T3-capable chain",
        limit.token,
        limit.amount,
        limit.period
    );
}

let legacy_limits: Vec<LegacyTokenLimit> = limits
    .into_iter()
    .map(|l| LegacyTokenLimit { token: l.token, amount: l.amount })
    .collect();

@0xKarl98

Copy link
Copy Markdown
Contributor

KeyAuthorizationArgs::into_authorization applies --expiry, limits, and scopes before setting is_admin, so combinations like --admin --expiry 1 currently succeed and produce `KeyAuthorization { expiry: Some(1), is_admin: true, ... }

Tempo validation rejects admin authorizations carrying expiry, limits, or allowed call scopes, so cast key-authorization encode/sign can emit an artifact that is guaranteed to fail later.

Should reject these flag combinations upfront .

grandizzy and others added 2 commits June 11, 2026 09:45
Remove the not-yet-supported T5 KeyAuthorization fields from the cast key-authorization encode/sign surface. This drops witness, account binding, and admin-key flags from the CLI parser, artifact construction, and JSON output so cast no longer emits artifacts that rely on fields we are not ready to support.

Keep the lower-level witness inspection and burn/check RPC commands intact; those operate on already-existing stored authorizations or explicit AccountKeychain RPC state and do not expose witness creation through the key-authorization artifact helper.

Also reject periodic spending limits on the legacy pre-T3 authorizeKey path before building calldata. Previously TOKEN:AMOUNT:PERIOD parsed successfully but the legacy calldata conversion silently discarded the period.

Update the focused tests for the reduced key-authorization argument shape and keep stored authorization witness decoding covered directly. Refresh Cargo.lock so foundry-wallets resolves to the foundry-core branch head that restores the browser wallet assets to the master version.
@mablr

mablr commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

@0xKarl98 d4bd87b addresses your comments.

pre-T3 fix + out-scoped post-T5 KeyAuthorization fields support.

@grandizzy grandizzy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

pls check comments

Comment thread Cargo.toml Outdated
Comment thread crates/cast/src/cmd/keychain.rs
Comment thread crates/cast/src/cmd/keychain.rs Outdated
mablr added 5 commits June 11, 2026 15:45
Use a key-authorization-specific root signer check for cast key-authorization sign so --from mismatches report that an artifact signature must come from the expected root account, not that an AccountKeychain transaction signer is wrong.

Pin foundry-wallets to the fixed foundry-core revision 521a152b306bc21605d55d436097fde44327c2b6 and update Cargo.lock from the moving branch source to the matching rev source.

Add a focused unit test for the new key authorization signer mismatch error text.
Update foundry-wallets to foundry-core rev 4042c61abd24f065ce8387caf7ec0a35c24ed7ce, which rejects unsupported T5 KeyAuthorization fields before enqueueing browser signing requests.

Keep Cargo.lock pinned to the same fixed rev source so the dependency remains reproducible.
Restore --witness for cast key-authorization encode/sign so TIP-1053 witnesses can be included in the KeyAuthorization signing hash again.

Keep account/admin T5 fields out of scope; browser signing now safely rejects witness-bearing requests in foundry-wallets before enqueueing a browser prompt.

Add coverage for CLI witness parsing and for preserving an explicit zero witness as distinct from an omitted witness.
@mablr mablr removed T-blocked Type: blocked stop-stale labels Jun 11, 2026
@mablr mablr requested review from figtracer and grandizzy June 11, 2026 15:02

@figtracer figtracer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

left two inline comments.

Comment thread crates/cast/src/cmd/keychain.rs
Comment thread crates/cast/src/cmd/keychain.rs
@mablr mablr requested a review from figtracer June 11, 2026 16:03

@figtracer figtracer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@grandizzy grandizzy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm

@figtracer figtracer merged commit 98a9e64 into master Jun 12, 2026
20 checks passed
@figtracer figtracer deleted the mablr/sign-authorization-keychain branch June 12, 2026 08:29
@github-project-automation github-project-automation Bot moved this to Done in Foundry Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants