Skip to content

Commit

Permalink
Merge branch 'main' into frederik/vc-issuer-config
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikrothenberger committed Jul 4, 2024
2 parents 18aff13 + a76730d commit 3d87f1b
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 1 deletion.
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 @@ -108,6 +108,7 @@ export const idlFactory = ({ IDL }) => {
[],
),
'set_derivation_origin' : IDL.Func([IDL.Text, IDL.Text], [], []),
'set_alternative_origins' : IDL.Func([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 @@ -88,6 +88,7 @@ export interface _SERVICE {
{ 'Err' : IssueCredentialError }
>,
'set_derivation_origin' : ActorMethod<[string, string], undefined>,
'set_alternative_origins' : ActorMethod<[string], undefined>,
'vc_consent_message' : ActorMethod<
[Icrc21VcConsentMessageRequest],
{ 'Ok' : Icrc21ConsentInfo } |
Expand Down
17 changes: 16 additions & 1 deletion demos/vc_issuer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use vc_util::{
};
use SupportedCredentialType::{UniversityDegree, VerifiedAdult, VerifiedEmployee};

use asset_util::{collect_assets, CertifiedAssets};
use asset_util::{collect_assets, Asset, CertifiedAssets, ContentEncoding, ContentType};
use ic_cdk::api;
use ic_cdk_macros::post_upgrade;
use lazy_static::lazy_static;
Expand Down Expand Up @@ -455,6 +455,21 @@ fn static_headers() -> Vec<HeaderField> {
vec![("Access-Control-Allow-Origin".to_string(), "*".to_string())]
}

#[update]
fn set_alternative_origins(alternative_origins: String) {
const ALTERNATIVE_ORIGINS_PATH: &str = "/.well-known/ii-alternative-origins";
ASSETS.with_borrow_mut(|assets| {
let asset = Asset {
url_path: ALTERNATIVE_ORIGINS_PATH.to_string(),
content: alternative_origins.as_bytes().to_vec(),
encoding: ContentEncoding::Identity,
content_type: ContentType::JSON,
};
assets.certify_asset(asset, &static_headers())
});
update_root_hash()
}

fn main() {}

fn bachelor_degree_credential(
Expand Down
36 changes: 36 additions & 0 deletions demos/vc_issuer/tests/issue_credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@ mod api {
)
}

pub fn set_alternative_origins(
env: &StateMachine,
canister_id: CanisterId,
alternative_origins: &str,
) -> Result<(), CallError> {
call_candid(
env,
canister_id,
"set_alternative_origins",
(alternative_origins,),
)
}

pub fn add_employee(
env: &StateMachine,
canister_id: CanisterId,
Expand Down Expand Up @@ -758,6 +771,29 @@ fn should_configure() {
api::configure(&env, issuer_id, &DUMMY_ISSUER_INIT).expect("API call failed");
}

#[test]
fn should_set_alternative_origins() {
let env = env();
let issuer_id = install_canister(&env, VC_ISSUER_WASM.clone());
let alternative_origins = r#"{"alternativeOrigins":["https://test.issuer"]}"#;
let request = HttpRequest {
method: "GET".to_string(),
url: "/.well-known/ii-alternative-origins".to_string(),
headers: vec![],
body: ByteBuf::new(),
certificate_version: Some(2),
};

let http_response = http_request(&env, issuer_id, &request).expect("HTTP request failed");
assert_eq!(http_response.status_code, 404);

api::set_alternative_origins(&env, issuer_id, alternative_origins).expect("API call failed");

let http_response = http_request(&env, issuer_id, &request).expect("HTTP request failed");
assert_eq!(http_response.status_code, 200);
assert_eq!(&http_response.body, alternative_origins.as_bytes())
}

/// Verifies that the expected assets is delivered and certified.
#[test]
fn issuer_canister_serves_http_assets() -> Result<(), CallError> {
Expand Down
2 changes: 2 additions & 0 deletions demos/vc_issuer/vc_demo_issuer.did
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ 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) -> ();
// Sets the content of the alternative origins file.
set_alternative_origins: (alternative_origins: 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 @@ -108,6 +108,7 @@ export const idlFactory = ({ IDL }) => {
[],
),
'set_derivation_origin' : IDL.Func([IDL.Text, IDL.Text], [], []),
'set_alternative_origins' : IDL.Func([IDL.Text], [], []),
'vc_consent_message' : IDL.Func(
[Icrc21VcConsentMessageRequest],
[IDL.Variant({ 'Ok' : Icrc21ConsentInfo, 'Err' : Icrc21Error })],
Expand Down
1 change: 1 addition & 0 deletions src/vc-api/src/generated/vc_issuer_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface _SERVICE {
{ 'Err' : IssueCredentialError }
>,
'set_derivation_origin' : ActorMethod<[string, string], undefined>,
'set_alternative_origins' : ActorMethod<[string], undefined>,
'vc_consent_message' : ActorMethod<
[Icrc21VcConsentMessageRequest],
{ 'Ok' : Icrc21ConsentInfo } |
Expand Down

0 comments on commit 3d87f1b

Please sign in to comment.