diff options
author | Florian Dold <florian@dold.me> | 2021-11-04 17:55:05 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-11-04 17:55:05 +0100 |
commit | 5c6f38091068d67f88edda1d776e3c5f86c1a94e (patch) | |
tree | 0bfce34e412034eafe7be6b5c4bc5ea32e725902 /packages/anastasis-core/src/index.ts | |
parent | 4ebeb00243598f7a0caf79ef405134b14f68400e (diff) | |
download | wallet-core-5c6f38091068d67f88edda1d776e3c5f86c1a94e.tar.xz |
anastasis-core: support secret version selection
Diffstat (limited to 'packages/anastasis-core/src/index.ts')
-rw-r--r-- | packages/anastasis-core/src/index.ts | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/packages/anastasis-core/src/index.ts b/packages/anastasis-core/src/index.ts index c1a6d3ff0..2ed69b55a 100644 --- a/packages/anastasis-core/src/index.ts +++ b/packages/anastasis-core/src/index.ts @@ -64,6 +64,8 @@ import { ReducerStateRecovery, SuccessDetails, UserAttributeSpec, + codecForActionArgsChangeVersion, + ActionArgsChangeVersion, } from "./reducer-types.js"; import fetchPonyfill from "fetch-ponyfill"; import { @@ -578,6 +580,7 @@ async function downloadPolicy( const newProviderStatus: { [url: string]: AuthenticationProviderStatusOk } = {}; const userAttributes = state.identity_attributes!; + const restrictProvider = state.selected_provider_url; // FIXME: Shouldn't we also store the status of bad providers? for (const url of providerUrls) { const pi = await getProviderInfo(url); @@ -592,9 +595,17 @@ async function downloadPolicy( if (!pi) { continue; } + if (restrictProvider && url !== state.selected_provider_url) { + // User wants specific provider. + continue; + } const userId = await userIdentifierDerive(userAttributes, pi.salt); const acctKeypair = accountKeypairDerive(userId); - const resp = await fetch(new URL(`policy/${acctKeypair.pub}`, url).href); + const reqUrl = new URL(`policy/${acctKeypair.pub}`, url); + if (state.selected_version) { + reqUrl.searchParams.set("version", `${state.selected_version}`); + } + const resp = await fetch(reqUrl.href); if (resp.status !== 200) { continue; } @@ -842,6 +853,18 @@ async function recoveryEnterUserAttributes( return downloadPolicy(st); } +async function changeVersion( + state: ReducerStateRecovery, + args: ActionArgsChangeVersion, +): Promise<ReducerStateRecovery | ReducerStateError> { + const st: ReducerStateRecovery = { + ...state, + selected_version: args.version, + selected_provider_url: args.provider_url, + }; + return downloadPolicy(st); +} + async function selectChallenge( state: ReducerStateRecovery, ta: ActionArgsSelectChallenge, @@ -1209,6 +1232,11 @@ const recoveryTransitions: Record< [RecoveryStates.SecretSelecting]: { ...transitionRecoveryJump("back", RecoveryStates.UserAttributesCollecting), ...transitionRecoveryJump("next", RecoveryStates.ChallengeSelecting), + ...transition( + "change_version", + codecForActionArgsChangeVersion(), + changeVersion, + ), }, [RecoveryStates.ChallengeSelecting]: { ...transitionRecoveryJump("back", RecoveryStates.SecretSelecting), |