Skip to content

Commit

Permalink
Add support to reconfigure derivation_origin for VC issuer
Browse files Browse the repository at this point in the history
This PR allows to reconfigure the expected frontend hostname as well as
the derivation origin. This will be used in the future to simplify the
e2e tests.

Since this is most useful in e2e tests if the configuration is _not_
guarded by the controller, the guard is removed for the `configure`
method too for consistency.
  • Loading branch information
frederikrothenberger committed Jul 4, 2024
1 parent 9a8bae0 commit 62158ab
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions demos/vc_issuer/app/generated/vc_issuer_idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export const idlFactory = ({ IDL }) => {
],
[],
),
'set_derivation_origin' : IDL.Func([IDL.Text, IDL.Text], [], []),
'vc_consent_message' : IDL.Func(
[Icrc21VcConsentMessageRequest],
[IDL.Variant({ 'Ok' : Icrc21ConsentInfo, 'Err' : Icrc21Error })],
Expand Down
1 change: 1 addition & 0 deletions demos/vc_issuer/app/generated/vc_issuer_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export interface _SERVICE {
{ 'Ok' : PreparedCredentialData } |
{ 'Err' : IssueCredentialError }
>,
'set_derivation_origin' : ActorMethod<[string, string], undefined>,
'vc_consent_message' : ActorMethod<
[Icrc21VcConsentMessageRequest],
{ 'Ok' : Icrc21ConsentInfo } |
Expand Down
24 changes: 14 additions & 10 deletions demos/vc_issuer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn config_memory() -> Memory {
#[cfg(target_arch = "wasm32")]
use ic_cdk::println;

#[derive(CandidType, Deserialize)]
#[derive(CandidType, Deserialize, Clone)]
struct IssuerConfig {
/// Root of trust for checking canister signatures.
ic_root_key_raw: Vec<u8>,
Expand Down Expand Up @@ -143,7 +143,7 @@ struct IssuerInit {
#[candid_method(init)]
fn init(init_arg: Option<IssuerInit>) {
if let Some(init) = init_arg {
apply_config(init);
apply_config(IssuerConfig::from(init));
};

init_assets();
Expand All @@ -156,17 +156,21 @@ fn post_upgrade(init_arg: Option<IssuerInit>) {

#[update]
#[candid_method]
fn configure(config: IssuerInit) {
if ic_cdk::api::is_controller(&caller()) {
apply_config(config);
} else {
panic!("Only a controller can call configure().");
}
fn configure(init: IssuerInit) {
apply_config(IssuerConfig::from(init));
}

#[update]
fn set_derivation_origin(frontend_hostname: String, derivation_origin: String) {
let mut config: IssuerConfig = CONFIG.with_borrow(|config| config.get().clone());
config.derivation_origin = derivation_origin;
config.frontend_hostname = frontend_hostname;
apply_config(config);
}

fn apply_config(init: IssuerInit) {
fn apply_config(config: IssuerConfig) {
CONFIG
.with_borrow_mut(|config_cell| config_cell.set(IssuerConfig::from(init)))
.with_borrow_mut(|config_cell| config_cell.set(config))
.expect("failed to apply issuer config");
}

Expand Down
1 change: 1 addition & 0 deletions demos/vc_issuer/vc_demo_issuer.did
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ service: (opt IssuerConfig) -> {

/// Configure the issuer (e.g. set the root key), used for deployment/testing.
configure: (IssuerConfig) -> ();
set_derivation_origin: (frontend_hostname: text, derivation_origin: text) -> ();

/// API for obtaining information about users, for testing only.
/// In a real-world issuer the data acquisition functionality should be more elaborate and authenticated.
Expand Down
1 change: 1 addition & 0 deletions src/frontend/generated/vc_issuer_idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export const idlFactory = ({ IDL }) => {
],
[],
),
'set_derivation_origin' : IDL.Func([IDL.Text, IDL.Text], [], []),
'vc_consent_message' : IDL.Func(
[Icrc21VcConsentMessageRequest],
[IDL.Variant({ 'Ok' : Icrc21ConsentInfo, 'Err' : Icrc21Error })],
Expand Down
3 changes: 2 additions & 1 deletion src/vc-api/src/generated/vc_issuer_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface IssuedCredentialData { 'vc_jws' : string }
export interface IssuerConfig {
'derivation_origin' : string,
'idp_canister_ids' : Array<Principal>,
'ic_root_key_der' : Uint8Array | number[],
'ic_root_key_der' : [] | [Uint8Array | number[]],
'frontend_hostname' : string,
}
export interface PrepareCredentialRequest {
Expand Down Expand Up @@ -87,6 +87,7 @@ export interface _SERVICE {
{ 'Ok' : PreparedCredentialData } |
{ 'Err' : IssueCredentialError }
>,
'set_derivation_origin' : ActorMethod<[string, string], undefined>,
'vc_consent_message' : ActorMethod<
[Icrc21VcConsentMessageRequest],
{ 'Ok' : Icrc21ConsentInfo } |
Expand Down

0 comments on commit 62158ab

Please sign in to comment.