Skip to content

chore: Add a hint to use offline derivation in the examples#263

Open
randombit wants to merge 1 commit intomainfrom
jack/add-offline-derive-hint
Open

chore: Add a hint to use offline derivation in the examples#263
randombit wants to merge 1 commit intomainfrom
jack/add-offline-derive-hint

Conversation

@randombit
Copy link
Contributor

It is kind of a pain to use offline derivation in the examples, due to needing to reliably distinguish if they are running against PocketIC or mainnet. But we can leave a hint to readers of the examples that they might want to use offline derivation themselves.

It is kind of a pain to use offline derivation in the examples themselves,
due to needing to reliably handle (and thus distinguish) if they are
using PocketIC or mainnet. But we can leave a hint to readers that they
might want to use offline derivation themselves.
@randombit randombit requested a review from a team January 8, 2026 21:31
Comment on lines +100 to +102
// In production systems it would make sense to use the offline derivation
// support available in ic_vetkeys, eg DerivedPublicKey::derive_sub_key
// since this avoids the cycles and time overhead of a management canister call
Copy link
Contributor

@fspreiss fspreiss Jan 12, 2026

Choose a reason for hiding this comment

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

Here the key is fetched every time anew. Some examples (like examples/basic_timelock_ibe/backend/src/lib.rs) use caching, so they fetch the public key only once. This makes this already much better. We could at least do the caching-based approach in all examples.

Another idea is to detect in which environment we are (mainnet vs pocket-ic) from the key ID: the key ID is passed to the init method and the init-args are defined in the dfx.json.

Ideally we can find a way to automate this (not necessarily in this PR), because this would help developers.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about it more, detecting the environment would be nice, but it's not needed for the time being.

Adding the caching-based approach would already go a long way, and we can extend the hint that the caching could additionally also be done in the frontend, and that frontends could also use the Typescript-based offline key derivation if the caching is not possible (e.g., because there is no fixed context/input).

// In production systems it would make sense to use the offline derivation
// support available in ic_vetkeys, eg DerivedPublicKey::derive_sub_key
// since this avoids the cycles and time overhead of a management canister call
let response: VetKDPublicKeyResult = ic_cdk::management_canister::vetkd_public_key(&request)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is now also the encrypted_chat example, so maybe put the hint also there.

Comment on lines +100 to +102
// In production systems it would make sense to use the offline derivation
// support available in ic_vetkeys, eg DerivedPublicKey::derive_sub_key
// since this avoids the cycles and time overhead of a management canister call
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about it more, detecting the environment would be nice, but it's not needed for the time being.

Adding the caching-based approach would already go a long way, and we can extend the hint that the caching could additionally also be done in the frontend, and that frontends could also use the Typescript-based offline key derivation if the caching is not possible (e.g., because there is no fixed context/input).

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.

2 participants