Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederik Rothenberger committed Nov 29, 2023
1 parent 1500f03 commit a2c04f6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/internet_identity/internet_identity.did
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ type AuthnMethodRegistrationInfo = record {
expiration: Timestamp;
};

type IdentityAuthnInfo = record {
authn_methods: vec AuthnMethod;
recovery_authn_methods: vec AuthnMethod;
};

type IdentityInfo = record {
authn_methods: vec AuthnMethodData;
authn_method_registration: opt AuthnMethodRegistrationInfo;
Expand All @@ -373,6 +378,10 @@ type IdentityRegisterResponse = variant {
invalid_metadata: text;
};

type IdentityAuthnInfoResponse = variant {
ok: IdentityAuthnInfo;
};

type IdentityInfoResponse = variant {
ok: IdentityInfo;
};
Expand Down Expand Up @@ -500,6 +509,9 @@ service : (opt InternetIdentityInit) -> {
// The sender needs to match the supplied authn_method.
identity_register: (AuthnMethodData, CaptchaResult, opt principal) -> (opt IdentityRegisterResponse);

// Returns information about the authentication methods of the identity with the given number.
identity_authn_info: (IdentityNumber) -> (opt IdentityAuthnInfoResponse) query;

// Returns information about the identity with the given number.
// Requires authentication.
identity_info: (IdentityNumber) -> (opt IdentityInfoResponse);
Expand Down
34 changes: 34 additions & 0 deletions src/internet_identity/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,40 @@ fn check_authentication(anchor_number: AnchorNumber) -> Result<(Anchor, DeviceKe
mod v2_api {
use super::*;

#[query]
#[candid_method(query)]
fn identity_authn_info(identity_number: IdentityNumber) -> Option<IdentityAuthnInfoResponse> {
let anchor =
state::storage_borrow(|storage| storage.read(identity_number).unwrap_or_default());

let authn_info = anchor.into_devices().into_iter().fold(
IdentityAuthnInfo {
authn_methods: vec![],
recovery_authn_methods: vec![],
},
|mut authn_info, device| {
let purpose = device.purpose;

let authn_method = if let Some(credential_id) = device.credential_id {
AuthnMethod::WebAuthn(WebAuthn {
credential_id,
pubkey: device.pubkey,
})
} else {
AuthnMethod::PubKey(PublicKeyAuthn {
pubkey: device.pubkey,
})
};
match purpose {
Purpose::Authentication => authn_info.authn_methods.push(authn_method),
Purpose::Recovery => authn_info.recovery_authn_methods.push(authn_method),
}
authn_info
},
);
Some(IdentityAuthnInfoResponse::Ok(authn_info))
}

#[update]
#[candid_method]
async fn captcha_create() -> Option<CaptchaCreateResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ pub struct AuthnMethodRegistration {
pub authn_method: Option<AuthnMethodData>,
}

#[derive(Clone, Debug, CandidType, Deserialize, Eq, PartialEq)]
pub struct IdentityAuthnInfo {
pub authn_methods: Vec<AuthnMethod>,
pub recovery_authn_methods: Vec<AuthnMethod>,
}

#[derive(Clone, Debug, CandidType, Deserialize, Eq, PartialEq)]
pub struct IdentityInfo {
pub authn_methods: Vec<AuthnMethodData>,
Expand All @@ -79,6 +85,11 @@ pub enum IdentityRegisterResponse {
InvalidMetadata(String),
}

pub enum IdentityAuthnInfoResponse {
#[serde(rename = "ok")]
Ok(IdentityAuthnInfo),
}

#[derive(Clone, Debug, CandidType, Deserialize, Eq, PartialEq)]
pub enum IdentityInfoResponse {
#[serde(rename = "ok")]
Expand Down

0 comments on commit a2c04f6

Please sign in to comment.