feat: Implement delegation imports#621
Merged
Merged
Conversation
There was a problem hiding this comment.
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>toicp identity importand load the delegation chain JSON. - Extend
create_identityto optionally store a delegation chain and register the identity asIdentitySpec::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.
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>
Contributor
|
Pushed 4 follow-up commits addressing a review pass (details in each commit message):
No behavior change to the happy path; existing + delegation tests pass. |
lwshang
approved these changes
Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
--delegationflag toicp identity import.