Skip to content

feat: Implement delegation imports#621

Merged
adamspofford-dfinity merged 9 commits into
mainfrom
spofford/import-delegation
Jun 23, 2026
Merged

feat: Implement delegation imports#621
adamspofford-dfinity merged 9 commits into
mainfrom
spofford/import-delegation

Conversation

@adamspofford-dfinity

@adamspofford-dfinity adamspofford-dfinity commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Adds a --delegation flag to icp identity import.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds support for importing delegation-based identities by introducing a --delegation <FILE> flag on icp identity import, wiring it through to identity creation so a delegation chain can be stored alongside the imported session key and the identity principal is derived from the chain root.

Changes:

  • Add --delegation <FILE> to icp identity import and load the delegation chain JSON.
  • Extend create_identity to optionally store a delegation chain and register the identity as IdentitySpec::Delegation.
  • Add an integration test covering successful delegated import and rejection on session-key mismatch (plus a new test asset public key PEM).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
docs/reference/cli.md Documents the new --delegation flag for icp identity import.
crates/icp/src/identity/mod.rs Updates internal test to pass the new delegation parameter to create_identity.
crates/icp/src/identity/key.rs Implements delegation-aware identity creation, new error variants, keyring naming adjustment, and chain persistence.
crates/icp-cli/src/commands/identity/import.rs Adds the --delegation CLI flag, loads the chain JSON, and passes it into identity creation for PEM/seed imports.
crates/icp-cli/src/commands/identity/new.rs Updates identity creation call signature to include delegation: None.
crates/icp-cli/tests/identity_tests.rs Adds an end-to-end test for importing an identity with an attached delegation chain.
crates/icp-cli/tests/assets/session_p256.pub.pem Adds a public-key PEM used by the new delegation import test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/reference/cli.md Outdated
Comment thread crates/icp/src/identity/key.rs
@adamspofford-dfinity adamspofford-dfinity marked this pull request as ready for review June 23, 2026 16:05
@adamspofford-dfinity adamspofford-dfinity requested a review from a team as a code owner June 23, 2026 16:05
adamspofford-dfinity and others added 6 commits June 23, 2026 09:18
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
`create_identity` constructed the temporary validation identity twice in
the delegation branch — once to read the session public key for the
key-mismatch check, and again to hand to `DelegatedIdentity::new`. Build
it once, read its public key, then move it into the validation call. Each
construction clones the secret key and boxes a new identity, so this drops
a redundant key clone on every delegation import.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
`create_identity` validated a delegation chain's structure and signatures
before persisting it, but never checked expiry. An already-expired (or
about-to-expire) chain therefore imported "successfully" and then failed
on every later load with `DelegationExpired`, since the load path
(`load_webauth_identity`) checks `is_expiring_soon`. Reject such chains at
import using the same 2-minute grace as the load path, so anything that
would fail to load fails up front with a clear error.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
`create_identity` (delegation import) and `link_webauth_identity`
contained a near-verbatim copy of the same chain-validation logic
(`to_agent_types` + `DelegatedIdentity::new` + warn-and-continue on a
mainnet-root-key mismatch), plus parallel error variants
(`CreateIdentity{Convert,Validate}Chain` vs `Dlg{Convert,Validate}Chain`).

Extract `validate_session_delegation_chain` and a shared
`ValidateDelegationChainError`, and route both callers through it via a
transparent error variant. A future fix to chain validation now lives in
one place.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lwshang

lwshang commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Pushed 4 follow-up commits addressing a review pass (details in each commit message):

  • Reject expired chains at import — an expired/about-to-expire chain used to import "successfully" then fail on every load; now it fails up front, matching the load-path expiry check.
  • Share chain validation — extracted validate_session_delegation_chain so create_identity and link_webauth_identity no longer carry near-duplicate validation logic + parallel error variants.
  • Build the validation session identity once instead of twice in the delegation branch.
  • CHANGELOG typo fix.

No behavior change to the happy path; existing + delegation tests pass.

@adamspofford-dfinity adamspofford-dfinity enabled auto-merge (squash) June 23, 2026 18:06
@adamspofford-dfinity adamspofford-dfinity merged commit 8a8356d into main Jun 23, 2026
95 checks passed
@adamspofford-dfinity adamspofford-dfinity deleted the spofford/import-delegation branch June 23, 2026 18:16
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