From 3d71c4aa923aefc6ade9dfdef5c08f8440d96e9f Mon Sep 17 00:00:00 2001 From: Frederik Rothenberger Date: Fri, 25 Aug 2023 16:06:00 +0200 Subject: [PATCH 1/6] Add API v2 identity_register method This PR adds the API v2 `captcha_create` and `identity_register` methods to II. It also removes the calls to the legacy API from the API v2 integration tests. --- .../src/api/internet_identity/api_v2.rs | 32 ++- src/internet_identity/internet_identity.did | 25 +++ src/internet_identity/src/main.rs | 27 +++ .../v2_api/authn_method_test_helpers.rs | 36 ++-- .../integration/v2_api/identity_register.rs | 185 ++++++++++++++++++ .../tests/integration/v2_api/mod.rs | 1 + .../src/internet_identity/conversions.rs | 12 ++ .../src/internet_identity/types.rs | 2 +- .../src/internet_identity/types/api_v2.rs | 22 ++- 9 files changed, 319 insertions(+), 23 deletions(-) create mode 100644 src/internet_identity/tests/integration/v2_api/identity_register.rs diff --git a/src/canister_tests/src/api/internet_identity/api_v2.rs b/src/canister_tests/src/api/internet_identity/api_v2.rs index 653e4360c0..185cee59fe 100644 --- a/src/canister_tests/src/api/internet_identity/api_v2.rs +++ b/src/canister_tests/src/api/internet_identity/api_v2.rs @@ -1,12 +1,34 @@ use candid::Principal; use ic_cdk::api::management_canister::main::CanisterId; -use ic_test_state_machine_client::{call_candid_as, CallError, StateMachine}; -use internet_identity_interface::internet_identity::types::{ - AuthnMethodAddResponse, AuthnMethodData, AuthnMethodRemoveResponse, IdentityInfoResponse, - IdentityMetadataReplaceResponse, IdentityNumber, MetadataEntry, PublicKey, -}; +use ic_test_state_machine_client::{call_candid, call_candid_as, CallError, StateMachine}; +use internet_identity_interface::internet_identity::types::*; use std::collections::HashMap; +pub fn captcha_create( + env: &StateMachine, + canister_id: CanisterId, +) -> Result, CallError> { + call_candid(env, canister_id, "captcha_create", ()).map(|(x,)| x) +} + +pub fn identity_register( + env: &StateMachine, + canister_id: CanisterId, + sender: Principal, + authn_method: &AuthnMethodData, + challenge_attempt: &ChallengeAttempt, + temp_key: Option, +) -> Result, CallError> { + call_candid_as( + env, + canister_id, + sender, + "identity_register", + (authn_method, challenge_attempt, temp_key), + ) + .map(|(x,)| x) +} + pub fn identity_info( env: &StateMachine, canister_id: CanisterId, diff --git a/src/internet_identity/internet_identity.did b/src/internet_identity/internet_identity.did index 9db935b258..ae91dc6d1a 100644 --- a/src/internet_identity/internet_identity.did +++ b/src/internet_identity/internet_identity.did @@ -357,6 +357,21 @@ type IdentityInfo = record { metadata: MetadataMap; }; +type CaptchaCreateResponse = variant { + ok: Challenge; +}; + +type IdentityRegisterResponse = variant { + // Registration successful. + ok: IdentityNumber; + // No more registrations are possible in this instance of the II service canister. + canister_full; + // The challenge was not successful. + bad_challenge; + // The metadata of the provided authentication method contains invalid entries. + invalid_metadata: text; +}; + type IdentityInfoResponse = variant { ok: IdentityInfo; }; @@ -474,6 +489,16 @@ service : (opt InternetIdentityInit) -> { // A client decoding a response as `null` indicates outdated type information // and should be treated as an error. + + // Creates a new captcha. The solution needs to be submitted using the + // `identity_register` call. + captcha_create: () -> (opt CaptchaCreateResponse); + + // Registers a new identity with the given authn_method. + // A valid captcha solution to a previously generated captcha (using create_captcha) must be provided. + // The sender needs to match the supplied authn_method. + identity_register: (AuthnMethodData, ChallengeResult, opt principal) -> (opt IdentityRegisterResponse); + // Returns information about the identity with the given number. // Requires authentication. identity_info: (IdentityNumber) -> (opt IdentityInfoResponse); diff --git a/src/internet_identity/src/main.rs b/src/internet_identity/src/main.rs index dd6d41df92..69a8142d98 100644 --- a/src/internet_identity/src/main.rs +++ b/src/internet_identity/src/main.rs @@ -505,6 +505,33 @@ fn check_authentication(anchor_number: AnchorNumber) -> Result<(Anchor, DeviceKe mod v2_api { use super::*; + #[update] + #[candid_method] + async fn captcha_create() -> Option { + let challenge = anchor_management::registration::create_challenge().await; + Some(CaptchaCreateResponse::Ok(challenge)) + } + + #[update] + #[candid_method] + fn identity_register( + authn_method: AuthnMethodData, + challenge_result: ChallengeAttempt, + temp_key: Option, + ) -> Option { + let result = match DeviceWithUsage::try_from(authn_method) + .map_err(|err| IdentityRegisterResponse::InvalidMetadata(err.to_string())) + { + Ok(device) => IdentityRegisterResponse::from(register( + DeviceData::from(device), + challenge_result, + temp_key, + )), + Err(err) => err, + }; + Some(result) + } + #[update] #[candid_method] fn identity_info(identity_number: IdentityNumber) -> Option { diff --git a/src/internet_identity/tests/integration/v2_api/authn_method_test_helpers.rs b/src/internet_identity/tests/integration/v2_api/authn_method_test_helpers.rs index 5d94781e7c..fa8d624574 100644 --- a/src/internet_identity/tests/integration/v2_api/authn_method_test_helpers.rs +++ b/src/internet_identity/tests/integration/v2_api/authn_method_test_helpers.rs @@ -1,9 +1,10 @@ -use canister_tests::api::internet_identity as api; +use canister_tests::api::internet_identity::api_v2; +use canister_tests::match_value; use ic_cdk::api::management_canister::main::CanisterId; use ic_test_state_machine_client::StateMachine; use internet_identity_interface::internet_identity::types::{ - AuthnMethod, AuthnMethodData, AuthnMethodProtection, ChallengeAttempt, DeviceData, - DeviceWithUsage, IdentityNumber, PublicKeyAuthn, Purpose, RegisterResponse, + AuthnMethod, AuthnMethodData, AuthnMethodProtection, CaptchaCreateResponse, ChallengeAttempt, + IdentityNumber, IdentityRegisterResponse, PublicKeyAuthn, Purpose, }; use serde_bytes::ByteBuf; @@ -36,23 +37,26 @@ pub fn create_identity_with_authn_method( canister_id: CanisterId, authn_method: &AuthnMethodData, ) -> IdentityNumber { - let challenge = api::create_challenge(env, canister_id).unwrap(); - let device = DeviceData::from(DeviceWithUsage::try_from(authn_method.clone()).unwrap()); + match_value!( + api_v2::captcha_create(env, canister_id).unwrap(), + Some(CaptchaCreateResponse::Ok(challenge)) + ); + let challenge_attempt = ChallengeAttempt { chars: "a".to_string(), key: challenge.challenge_key, }; - let RegisterResponse::Registered { user_number } = api::register( - env, - canister_id, - device.principal(), - &device, - &challenge_attempt, - None, - ) - .unwrap() else { - panic!("Expected device to be registered"); - }; + match_value!( + api_v2::identity_register( + env, + canister_id, + authn_method.principal(), + authn_method, + &challenge_attempt, + None, + ), + Ok(Some(IdentityRegisterResponse::Ok(user_number))) + ); user_number } diff --git a/src/internet_identity/tests/integration/v2_api/identity_register.rs b/src/internet_identity/tests/integration/v2_api/identity_register.rs new file mode 100644 index 0000000000..8e35ec67ab --- /dev/null +++ b/src/internet_identity/tests/integration/v2_api/identity_register.rs @@ -0,0 +1,185 @@ +use crate::v2_api::authn_method_test_helpers::{ + create_identity_with_authn_method, test_authn_method, +}; +use candid::Principal; +use canister_tests::api::internet_identity::api_v2; +use canister_tests::framework::{ + arg_with_anchor_range, env, expect_user_error_with_message, install_ii_canister, + install_ii_canister_with_arg, II_WASM, +}; +use canister_tests::match_value; +use ic_test_state_machine_client::ErrorCode::CanisterCalledTrap; +use internet_identity_interface::internet_identity::types::{ + CaptchaCreateResponse, ChallengeAttempt, IdentityRegisterResponse, MetadataEntry, +}; +use regex::Regex; +use serde_bytes::ByteBuf; +use std::time::Duration; + +#[test] +fn should_register_new_identity() { + let env = env(); + let canister_id = + install_ii_canister_with_arg(&env, II_WASM.clone(), arg_with_anchor_range((42, 44))); + let authn_method = test_authn_method(); + let identity_number = create_identity_with_authn_method(&env, canister_id, &authn_method); + + assert_eq!(identity_number, 42); +} + +#[test] +fn should_register_multiple_identities() { + let env = env(); + let canister_id = install_ii_canister(&env, II_WASM.clone()); + let authn_method = test_authn_method(); + let identity_number_1 = create_identity_with_authn_method(&env, canister_id, &authn_method); + let identity_number_2 = create_identity_with_authn_method(&env, canister_id, &authn_method); + + assert_ne!(identity_number_1, identity_number_2); +} + +#[test] +fn should_not_exceed_configured_identity_range() { + let env = env(); + let canister_id = + install_ii_canister_with_arg(&env, II_WASM.clone(), arg_with_anchor_range((42, 44))); + + let authn_method = test_authn_method(); + create_identity_with_authn_method(&env, canister_id, &authn_method); + create_identity_with_authn_method(&env, canister_id, &authn_method); + + match_value!( + api_v2::captcha_create(&env, canister_id).unwrap(), + Some(CaptchaCreateResponse::Ok(challenge)) + ); + + match_value!( + api_v2::identity_register( + &env, + canister_id, + authn_method.principal(), + &authn_method, + &ChallengeAttempt { + chars: "a".to_string(), + key: challenge.challenge_key, + }, + None, + ), + Ok(Some(IdentityRegisterResponse::CanisterFull)) + ); +} + +#[test] +fn should_verify_sender_matches_authn_method() { + let env = env(); + let canister_id = install_ii_canister(&env, II_WASM.clone()); + + match_value!( + api_v2::captcha_create(&env, canister_id).unwrap(), + Some(CaptchaCreateResponse::Ok(challenge)) + ); + + let result = api_v2::identity_register( + &env, + canister_id, + Principal::anonymous(), + &test_authn_method(), + &ChallengeAttempt { + chars: "a".to_string(), + key: challenge.challenge_key, + }, + None, + ); + expect_user_error_with_message( + result, + CanisterCalledTrap, + Regex::new("[a-z\\d-]+ could not be authenticated against").unwrap(), + ); +} + +#[test] +fn should_not_allow_wrong_captcha() { + let env = env(); + let canister_id = install_ii_canister(&env, II_WASM.clone()); + let authn_method = test_authn_method(); + + match_value!( + api_v2::captcha_create(&env, canister_id).unwrap(), + Some(CaptchaCreateResponse::Ok(challenge)) + ); + + match_value!( + api_v2::identity_register( + &env, + canister_id, + authn_method.principal(), + &authn_method, + &ChallengeAttempt { + chars: "wrong solution".to_string(), + key: challenge.challenge_key, + }, + None, + ), + Ok(Some(IdentityRegisterResponse::BadChallenge)) + ); +} + +#[test] +fn should_not_allow_expired_captcha() { + let env = env(); + let canister_id = install_ii_canister(&env, II_WASM.clone()); + let authn_method = test_authn_method(); + + match_value!( + api_v2::captcha_create(&env, canister_id).unwrap(), + Some(CaptchaCreateResponse::Ok(challenge)) + ); + + env.advance_time(Duration::from_secs(301)); // one second longer than captcha validity + + match_value!( + api_v2::identity_register( + &env, + canister_id, + authn_method.principal(), + &authn_method, + &ChallengeAttempt { + chars: "wrong solution".to_string(), + key: challenge.challenge_key, + }, + None, + ), + Ok(Some(IdentityRegisterResponse::BadChallenge)) + ); +} + +#[test] +fn should_fail_on_invalid_metadata() { + let env = env(); + let canister_id = install_ii_canister(&env, II_WASM.clone()); + let mut authn_method = test_authn_method(); + authn_method.metadata.insert( + "usage".to_string(), + MetadataEntry::Bytes(ByteBuf::from("invalid")), + ); + + match_value!( + api_v2::captcha_create(&env, canister_id).unwrap(), + Some(CaptchaCreateResponse::Ok(challenge)) + ); + + match_value!( + api_v2::identity_register( + &env, + canister_id, + authn_method.principal(), + &authn_method, + &ChallengeAttempt { + chars: "a".to_string(), + key: challenge.challenge_key, + }, + None, + ), + Ok(Some(IdentityRegisterResponse::InvalidMetadata(_))) + ); +} diff --git a/src/internet_identity/tests/integration/v2_api/mod.rs b/src/internet_identity/tests/integration/v2_api/mod.rs index f2e0894e4e..731d0ae655 100644 --- a/src/internet_identity/tests/integration/v2_api/mod.rs +++ b/src/internet_identity/tests/integration/v2_api/mod.rs @@ -3,3 +3,4 @@ mod authn_method_remove; pub mod authn_method_test_helpers; mod identity_info; mod identity_metadata; +mod identity_register; diff --git a/src/internet_identity_interface/src/internet_identity/conversions.rs b/src/internet_identity_interface/src/internet_identity/conversions.rs index 3abbf1ebc6..d25077c5b5 100644 --- a/src/internet_identity_interface/src/internet_identity/conversions.rs +++ b/src/internet_identity_interface/src/internet_identity/conversions.rs @@ -250,3 +250,15 @@ impl TryFrom for DeviceWithUsage { }) } } + +impl From for IdentityRegisterResponse { + fn from(register_response: RegisterResponse) -> Self { + match register_response { + RegisterResponse::Registered { user_number } => { + IdentityRegisterResponse::Ok(user_number) + } + RegisterResponse::CanisterFull => IdentityRegisterResponse::CanisterFull, + RegisterResponse::BadChallenge => IdentityRegisterResponse::BadChallenge, + } + } +} diff --git a/src/internet_identity_interface/src/internet_identity/types.rs b/src/internet_identity_interface/src/internet_identity/types.rs index 7b88926e6f..34287c70b6 100644 --- a/src/internet_identity_interface/src/internet_identity/types.rs +++ b/src/internet_identity_interface/src/internet_identity/types.rs @@ -104,7 +104,7 @@ pub enum MetadataEntry { Map(HashMap), } -#[derive(Clone, Debug, CandidType, Deserialize)] +#[derive(Clone, Debug, CandidType, Deserialize, Eq, PartialEq)] pub struct Challenge { pub png_base64: String, pub challenge_key: ChallengeKey, diff --git a/src/internet_identity_interface/src/internet_identity/types/api_v2.rs b/src/internet_identity_interface/src/internet_identity/types/api_v2.rs index c3e117ca1b..75e2c1dde3 100644 --- a/src/internet_identity_interface/src/internet_identity/types/api_v2.rs +++ b/src/internet_identity_interface/src/internet_identity/types/api_v2.rs @@ -1,4 +1,6 @@ -use crate::internet_identity::types::{CredentialId, MetadataEntry, PublicKey, Purpose, Timestamp}; +use crate::internet_identity::types::{ + Challenge, CredentialId, MetadataEntry, PublicKey, Purpose, Timestamp, +}; use candid::{CandidType, Deserialize}; use std::collections::HashMap; @@ -59,6 +61,24 @@ pub struct IdentityInfo { pub metadata: HashMap, } +#[derive(Clone, Debug, CandidType, Deserialize, Eq, PartialEq)] +pub enum CaptchaCreateResponse { + #[serde(rename = "ok")] + Ok(Challenge), +} + +#[derive(Clone, Debug, CandidType, Deserialize, Eq, PartialEq)] +pub enum IdentityRegisterResponse { + #[serde(rename = "ok")] + Ok(IdentityNumber), + #[serde(rename = "canister_full")] + CanisterFull, + #[serde(rename = "bad_challenge")] + BadChallenge, + #[serde(rename = "invalid_metadata")] + InvalidMetadata(String), +} + #[derive(Clone, Debug, CandidType, Deserialize, Eq, PartialEq)] pub enum IdentityInfoResponse { #[serde(rename = "ok")] From 7830b4b6df7298042d1d2d05ad5b411e5d7da21c Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 29 Nov 2023 09:23:52 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=A4=96=20npm=20run=20generate=20auto-?= =?UTF-8?q?update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generated/internet_identity_idl.js | 21 +++++++++++++++---- .../generated/internet_identity_types.d.ts | 10 +++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/frontend/generated/internet_identity_idl.js b/src/frontend/generated/internet_identity_idl.js index f63412a68e..872bd2c436 100644 --- a/src/frontend/generated/internet_identity_idl.js +++ b/src/frontend/generated/internet_identity_idl.js @@ -99,6 +99,7 @@ export const idlFactory = ({ IDL }) => { 'png_base64' : IDL.Text, 'challenge_key' : ChallengeKey, }); + const CaptchaCreateResponse = IDL.Variant({ 'ok' : Challenge }); const DeployArchiveResult = IDL.Variant({ 'creation_in_progress' : IDL.Null, 'success' : IDL.Principal, @@ -215,6 +216,16 @@ export const idlFactory = ({ IDL }) => { }); const IdentityInfoResponse = IDL.Variant({ 'ok' : IdentityInfo }); const IdentityMetadataReplaceResponse = IDL.Variant({ 'ok' : IDL.Null }); + const ChallengeResult = IDL.Record({ + 'key' : ChallengeKey, + 'chars' : IDL.Text, + }); + const IdentityRegisterResponse = IDL.Variant({ + 'ok' : IdentityNumber, + 'invalid_metadata' : IDL.Text, + 'bad_challenge' : IDL.Null, + 'canister_full' : IDL.Null, + }); const UserKey = PublicKey; const PrepareIdAliasRequest = IDL.Record({ 'issuer' : FrontendHostname, @@ -230,10 +241,6 @@ export const idlFactory = ({ IDL }) => { 'ok' : PreparedIdAlias, 'authentication_failed' : IDL.Text, }); - const ChallengeResult = IDL.Record({ - 'key' : ChallengeKey, - 'chars' : IDL.Text, - }); const RegisterResponse = IDL.Variant({ 'bad_challenge' : IDL.Null, 'canister_full' : IDL.Null, @@ -276,6 +283,7 @@ export const idlFactory = ({ IDL }) => { [IDL.Opt(AuthnMethodRemoveResponse)], [], ), + 'captcha_create' : IDL.Func([], [IDL.Opt(CaptchaCreateResponse)], []), 'create_challenge' : IDL.Func([], [Challenge], []), 'deploy_archive' : IDL.Func([IDL.Vec(IDL.Nat8)], [DeployArchiveResult], []), 'enter_device_registration_mode' : IDL.Func([UserNumber], [Timestamp], []), @@ -314,6 +322,11 @@ export const idlFactory = ({ IDL }) => { [IDL.Opt(IdentityMetadataReplaceResponse)], [], ), + 'identity_register' : IDL.Func( + [AuthnMethodData, ChallengeResult, IDL.Opt(IDL.Principal)], + [IDL.Opt(IdentityRegisterResponse)], + [], + ), 'init_salt' : IDL.Func([], [], []), 'lookup' : IDL.Func([UserNumber], [IDL.Vec(DeviceData)], ['query']), 'prepare_delegation' : IDL.Func( diff --git a/src/frontend/generated/internet_identity_types.d.ts b/src/frontend/generated/internet_identity_types.d.ts index 87056266d2..b5e9907424 100644 --- a/src/frontend/generated/internet_identity_types.d.ts +++ b/src/frontend/generated/internet_identity_types.d.ts @@ -51,6 +51,7 @@ export interface BufferedArchiveEntry { 'anchor_number' : UserNumber, 'timestamp' : Timestamp, } +export type CaptchaCreateResponse = { 'ok' : Challenge }; export interface Challenge { 'png_base64' : string, 'challenge_key' : ChallengeKey, @@ -138,6 +139,10 @@ export interface IdentityInfo { export type IdentityInfoResponse = { 'ok' : IdentityInfo }; export type IdentityMetadataReplaceResponse = { 'ok' : null }; export type IdentityNumber = bigint; +export type IdentityRegisterResponse = { 'ok' : IdentityNumber } | + { 'invalid_metadata' : string } | + { 'bad_challenge' : null } | + { 'canister_full' : null }; export interface InternetIdentityInit { 'max_num_latest_delegation_origins' : [] | [bigint], 'assigned_user_number_range' : [] | [[bigint, bigint]], @@ -241,6 +246,7 @@ export interface _SERVICE { [IdentityNumber, PublicKey], [] | [AuthnMethodRemoveResponse] >, + 'captcha_create' : ActorMethod<[], [] | [CaptchaCreateResponse]>, 'create_challenge' : ActorMethod<[], Challenge>, 'deploy_archive' : ActorMethod<[Uint8Array | number[]], DeployArchiveResult>, 'enter_device_registration_mode' : ActorMethod<[UserNumber], Timestamp>, @@ -261,6 +267,10 @@ export interface _SERVICE { [IdentityNumber, MetadataMap], [] | [IdentityMetadataReplaceResponse] >, + 'identity_register' : ActorMethod< + [AuthnMethodData, ChallengeResult, [] | [Principal]], + [] | [IdentityRegisterResponse] + >, 'init_salt' : ActorMethod<[], undefined>, 'lookup' : ActorMethod<[UserNumber], Array>, 'prepare_delegation' : ActorMethod< From 9a961dde91d738ce8b55798d9d11d23b098a97d8 Mon Sep 17 00:00:00 2001 From: Frederik Rothenberger Date: Wed, 29 Nov 2023 13:35:55 +0100 Subject: [PATCH 3/6] Consistently use captcha instead of challenge --- src/internet_identity/internet_identity.did | 7 ++++--- .../src/internet_identity/types/api_v2.rs | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/internet_identity/internet_identity.did b/src/internet_identity/internet_identity.did index ae91dc6d1a..579dec6069 100644 --- a/src/internet_identity/internet_identity.did +++ b/src/internet_identity/internet_identity.did @@ -241,6 +241,7 @@ type ChallengeResult = record { key : ChallengeKey; chars : text; }; +type CaptchaResult = ChallengeResult; // Extra information about registration status for new devices type DeviceRegistrationInfo = record { @@ -366,8 +367,8 @@ type IdentityRegisterResponse = variant { ok: IdentityNumber; // No more registrations are possible in this instance of the II service canister. canister_full; - // The challenge was not successful. - bad_challenge; + // The captcha check was not successful. + bad_captcha; // The metadata of the provided authentication method contains invalid entries. invalid_metadata: text; }; @@ -497,7 +498,7 @@ service : (opt InternetIdentityInit) -> { // Registers a new identity with the given authn_method. // A valid captcha solution to a previously generated captcha (using create_captcha) must be provided. // The sender needs to match the supplied authn_method. - identity_register: (AuthnMethodData, ChallengeResult, opt principal) -> (opt IdentityRegisterResponse); + identity_register: (AuthnMethodData, CaptchaResult, opt principal) -> (opt IdentityRegisterResponse); // Returns information about the identity with the given number. // Requires authentication. diff --git a/src/internet_identity_interface/src/internet_identity/types/api_v2.rs b/src/internet_identity_interface/src/internet_identity/types/api_v2.rs index 75e2c1dde3..a65090f78c 100644 --- a/src/internet_identity_interface/src/internet_identity/types/api_v2.rs +++ b/src/internet_identity_interface/src/internet_identity/types/api_v2.rs @@ -73,8 +73,8 @@ pub enum IdentityRegisterResponse { Ok(IdentityNumber), #[serde(rename = "canister_full")] CanisterFull, - #[serde(rename = "bad_challenge")] - BadChallenge, + #[serde(rename = "bad_captcha")] + BadCaptcha, #[serde(rename = "invalid_metadata")] InvalidMetadata(String), } From 6c71a1809974436ff37b7767ac0103beb70b7495 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 29 Nov 2023 12:37:43 +0000 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=A4=96=20npm=20run=20generate=20auto-?= =?UTF-8?q?update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/generated/internet_identity_idl.js | 5 +++-- src/frontend/generated/internet_identity_types.d.ts | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/frontend/generated/internet_identity_idl.js b/src/frontend/generated/internet_identity_idl.js index 872bd2c436..168f16eb49 100644 --- a/src/frontend/generated/internet_identity_idl.js +++ b/src/frontend/generated/internet_identity_idl.js @@ -220,10 +220,11 @@ export const idlFactory = ({ IDL }) => { 'key' : ChallengeKey, 'chars' : IDL.Text, }); + const CaptchaResult = ChallengeResult; const IdentityRegisterResponse = IDL.Variant({ 'ok' : IdentityNumber, 'invalid_metadata' : IDL.Text, - 'bad_challenge' : IDL.Null, + 'bad_captcha' : IDL.Null, 'canister_full' : IDL.Null, }); const UserKey = PublicKey; @@ -323,7 +324,7 @@ export const idlFactory = ({ IDL }) => { [], ), 'identity_register' : IDL.Func( - [AuthnMethodData, ChallengeResult, IDL.Opt(IDL.Principal)], + [AuthnMethodData, CaptchaResult, IDL.Opt(IDL.Principal)], [IDL.Opt(IdentityRegisterResponse)], [], ), diff --git a/src/frontend/generated/internet_identity_types.d.ts b/src/frontend/generated/internet_identity_types.d.ts index b5e9907424..4cb3765de0 100644 --- a/src/frontend/generated/internet_identity_types.d.ts +++ b/src/frontend/generated/internet_identity_types.d.ts @@ -52,6 +52,7 @@ export interface BufferedArchiveEntry { 'timestamp' : Timestamp, } export type CaptchaCreateResponse = { 'ok' : Challenge }; +export type CaptchaResult = ChallengeResult; export interface Challenge { 'png_base64' : string, 'challenge_key' : ChallengeKey, @@ -141,7 +142,7 @@ export type IdentityMetadataReplaceResponse = { 'ok' : null }; export type IdentityNumber = bigint; export type IdentityRegisterResponse = { 'ok' : IdentityNumber } | { 'invalid_metadata' : string } | - { 'bad_challenge' : null } | + { 'bad_captcha' : null } | { 'canister_full' : null }; export interface InternetIdentityInit { 'max_num_latest_delegation_origins' : [] | [bigint], @@ -268,7 +269,7 @@ export interface _SERVICE { [] | [IdentityMetadataReplaceResponse] >, 'identity_register' : ActorMethod< - [AuthnMethodData, ChallengeResult, [] | [Principal]], + [AuthnMethodData, CaptchaResult, [] | [Principal]], [] | [IdentityRegisterResponse] >, 'init_salt' : ActorMethod<[], undefined>, From 1ed6b45c0dcdec2f888a70da966beddae1880684 Mon Sep 17 00:00:00 2001 From: Frederik Rothenberger Date: Wed, 29 Nov 2023 13:41:47 +0100 Subject: [PATCH 5/6] Fix conversion --- .../src/internet_identity/conversions.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internet_identity_interface/src/internet_identity/conversions.rs b/src/internet_identity_interface/src/internet_identity/conversions.rs index d25077c5b5..ff98ecce93 100644 --- a/src/internet_identity_interface/src/internet_identity/conversions.rs +++ b/src/internet_identity_interface/src/internet_identity/conversions.rs @@ -258,7 +258,7 @@ impl From for IdentityRegisterResponse { IdentityRegisterResponse::Ok(user_number) } RegisterResponse::CanisterFull => IdentityRegisterResponse::CanisterFull, - RegisterResponse::BadChallenge => IdentityRegisterResponse::BadChallenge, + RegisterResponse::BadChallenge => IdentityRegisterResponse::BadCaptcha, } } } From 3dc5ee41397371ba173f84656ac2ff7b1078f948 Mon Sep 17 00:00:00 2001 From: Frederik Rothenberger Date: Wed, 29 Nov 2023 13:45:33 +0100 Subject: [PATCH 6/6] Fix test --- .../tests/integration/v2_api/identity_register.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/internet_identity/tests/integration/v2_api/identity_register.rs b/src/internet_identity/tests/integration/v2_api/identity_register.rs index 8e35ec67ab..0c62b9bf5c 100644 --- a/src/internet_identity/tests/integration/v2_api/identity_register.rs +++ b/src/internet_identity/tests/integration/v2_api/identity_register.rs @@ -120,7 +120,7 @@ fn should_not_allow_wrong_captcha() { }, None, ), - Ok(Some(IdentityRegisterResponse::BadChallenge)) + Ok(Some(IdentityRegisterResponse::BadCaptcha)) ); } @@ -149,7 +149,7 @@ fn should_not_allow_expired_captcha() { }, None, ), - Ok(Some(IdentityRegisterResponse::BadChallenge)) + Ok(Some(IdentityRegisterResponse::BadCaptcha)) ); }