summaryrefslogtreecommitdiff
path: root/packages/anastasis-core
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2021-11-09 00:19:50 -0300
committerSebastian <sebasjm@gmail.com>2021-11-09 00:19:50 -0300
commit7f6101a24df0db86f33c3217e52838f09a25286d (patch)
tree9a8d170d4bfe2c2a49820fa10db46379140316d8 /packages/anastasis-core
parente369f26ec57c5571af81c534b378035a3e41919c (diff)
downloadwallet-core-7f6101a24df0db86f33c3217e52838f09a25286d.tar.gz
wallet-core-7f6101a24df0db86f33c3217e52838f09a25286d.tar.bz2
wallet-core-7f6101a24df0db86f33c3217e52838f09a25286d.zip
add provider/ remove provider
Diffstat (limited to 'packages/anastasis-core')
-rw-r--r--packages/anastasis-core/src/index.ts66
-rw-r--r--packages/anastasis-core/src/reducer-types.ts8
2 files changed, 74 insertions, 0 deletions
diff --git a/packages/anastasis-core/src/index.ts b/packages/anastasis-core/src/index.ts
index f88e6e8bc..15e1e5d97 100644
--- a/packages/anastasis-core/src/index.ts
+++ b/packages/anastasis-core/src/index.ts
@@ -65,6 +65,8 @@ import {
ActionArgsChangeVersion,
TruthMetaData,
ActionArgsUpdatePolicy,
+ ActionArgsAddProvider,
+ ActionArgsDeleteProvider,
} from "./reducer-types.js";
import fetchPonyfill from "fetch-ponyfill";
import {
@@ -1060,9 +1062,15 @@ async function recoveryEnterUserAttributes(
args: ActionArgsEnterUserAttributes,
): Promise<ReducerStateRecovery | ReducerStateError> {
// FIXME: validate attributes
+ const providerUrls = Object.keys(state.authentication_providers ?? {});
+ const newProviders = state.authentication_providers ?? {};
+ for (const url of providerUrls) {
+ newProviders[url] = await getProviderInfo(url);
+ }
const st: ReducerStateRecovery = {
...state,
identity_attributes: args.identity_attributes,
+ authentication_providers: newProviders,
};
return downloadPolicy(st);
}
@@ -1174,6 +1182,60 @@ function transitionRecoveryJump(
};
}
+//FIXME: doest the same that addProviderRecovery, but type are not generic enough
+async function addProviderBackup(
+ state: ReducerStateBackup,
+ args: ActionArgsAddProvider,
+): Promise<ReducerStateBackup> {
+ const info = await getProviderInfo(args.provider_url)
+ return {
+ ...state,
+ authentication_providers: {
+ ...(state.authentication_providers ?? {}),
+ [args.provider_url]: info,
+ },
+ };
+}
+
+//FIXME: doest the same that deleteProviderRecovery, but type are not generic enough
+async function deleteProviderBackup(
+ state: ReducerStateBackup,
+ args: ActionArgsDeleteProvider,
+): Promise<ReducerStateBackup> {
+ const authentication_providers = {... state.authentication_providers ?? {} }
+ delete authentication_providers[args.provider_url]
+ return {
+ ...state,
+ authentication_providers,
+ };
+}
+
+async function addProviderRecovery(
+ state: ReducerStateRecovery,
+ args: ActionArgsAddProvider,
+): Promise<ReducerStateRecovery> {
+ const info = await getProviderInfo(args.provider_url)
+ return {
+ ...state,
+ authentication_providers: {
+ ...(state.authentication_providers ?? {}),
+ [args.provider_url]: info,
+ },
+ };
+}
+
+async function deleteProviderRecovery(
+ state: ReducerStateRecovery,
+ args: ActionArgsDeleteProvider,
+): Promise<ReducerStateRecovery> {
+ const authentication_providers = {... state.authentication_providers ?? {} }
+ delete authentication_providers[args.provider_url]
+ return {
+ ...state,
+ authentication_providers,
+ };
+}
+
async function addAuthentication(
state: ReducerStateBackup,
args: ActionArgsAddAuthentication,
@@ -1408,6 +1470,8 @@ const backupTransitions: Record<
...transitionBackupJump("back", BackupStates.UserAttributesCollecting),
...transition("add_authentication", codecForAny(), addAuthentication),
...transition("delete_authentication", codecForAny(), deleteAuthentication),
+ ...transition("add_provider", codecForAny(), addProviderBackup),
+ ...transition("delete_provider", codecForAny(), deleteProviderBackup),
...transition("next", codecForAny(), nextFromAuthenticationsEditing),
},
[BackupStates.PoliciesReviewing]: {
@@ -1476,6 +1540,8 @@ const recoveryTransitions: Record<
[RecoveryStates.SecretSelecting]: {
...transitionRecoveryJump("back", RecoveryStates.UserAttributesCollecting),
...transitionRecoveryJump("next", RecoveryStates.ChallengeSelecting),
+ ...transition("add_provider", codecForAny(), addProviderRecovery),
+ ...transition("delete_provider", codecForAny(), deleteProviderRecovery),
...transition(
"change_version",
codecForActionArgsChangeVersion(),
diff --git a/packages/anastasis-core/src/reducer-types.ts b/packages/anastasis-core/src/reducer-types.ts
index 51b0045a0..3e6d6c852 100644
--- a/packages/anastasis-core/src/reducer-types.ts
+++ b/packages/anastasis-core/src/reducer-types.ts
@@ -334,6 +334,14 @@ export const codecForActionArgsEnterUserAttributes = () =>
.property("identity_attributes", codecForAny())
.build("ActionArgsEnterUserAttributes");
+export interface ActionArgsAddProvider {
+ provider_url: string;
+}
+
+export interface ActionArgsDeleteProvider {
+ provider_url: string;
+}
+
export interface ActionArgsAddAuthentication {
authentication_method: {
type: string;