aboutsummaryrefslogtreecommitdiff
path: root/packages/anastasis-core/src
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-04-14 21:00:03 +0200
committerFlorian Dold <florian@dold.me>2022-04-14 21:00:03 +0200
commit3957f529bf4afd96b9bee802e20693fc076968c9 (patch)
tree6286ae0b28f48e232322b05462195dc86a2f9a7f /packages/anastasis-core/src
parentbc05050524e3ade854ef36194fad4cdd4b5e15e5 (diff)
downloadwallet-core-3957f529bf4afd96b9bee802e20693fc076968c9.tar.xz
anastasis: no more currencies per country
Diffstat (limited to 'packages/anastasis-core/src')
-rw-r--r--packages/anastasis-core/src/anastasis-data.ts238
-rw-r--r--packages/anastasis-core/src/index.ts85
-rw-r--r--packages/anastasis-core/src/reducer-types.ts6
3 files changed, 189 insertions, 140 deletions
diff --git a/packages/anastasis-core/src/anastasis-data.ts b/packages/anastasis-core/src/anastasis-data.ts
index 924f4103d..cac4dc6c6 100644
--- a/packages/anastasis-core/src/anastasis-data.ts
+++ b/packages/anastasis-core/src/anastasis-data.ts
@@ -1,7 +1,6 @@
// This file is auto-generated, do not modify.
-// Generated from v0.2.0-4-g61ea83c on Tue, 05 Oct 2021 10:40:32 +0200
+// Generated from v0.2.0-151-g2ae958d on Thu, 14 Apr 2022 20:38:58 +0200
// To re-generate, run contrib/gen-ts.sh from the main anastasis code base.
-// XXX: Modified for demo, allowing demo providers for EUR
export const anastasisData = {
providersList: {
@@ -9,44 +8,36 @@ export const anastasisData = {
"SPDX-License-Identifier": "GPL3.0-or-later",
anastasis_provider: [
{
- url: "https://anastasis.demo.taler.net/",
- currency: "KUDOS",
+ url: "https://v1.anastasis.taler.net/",
+ name: "Bern University of Applied Sciences, Switzerland",
},
{
- url: "https://kudos.demo.anastasis.lu/",
- currency: "KUDOS",
+ url: "https://v1.anastasis.codeblau.de/",
+ name: "Codeblau GmbH, Germany",
},
{
- url: "https://anastasis.demo.taler.net/",
- currency: "EUR",
+ url: "https://v1.anastasis.openw3b.org/",
+ name: "Openw3b Foundation, India",
},
{
- url: "https://kudos.demo.anastasis.lu/",
- currency: "EUR",
- },
- {
- url: "https://anastasis.demo.taler.net/",
- currency: "CHF",
- },
- {
- url: "https://kudos.demo.anastasis.lu/",
- currency: "CHF",
+ url: "https://v1.anastasis.lu/",
+ name: "Anastasis SARL, Luxembourg",
},
{
url: "http://localhost:8086/",
- currency: "TESTKUDOS",
+ restricted: "xx",
},
{
url: "http://localhost:8087/",
- currency: "TESTKUDOS",
+ restricted: "xx",
},
{
url: "http://localhost:8088/",
- currency: "TESTKUDOS",
+ restricted: "xx",
},
{
url: "http://localhost:8089/",
- currency: "TESTKUDOS",
+ restricted: "xx",
},
],
},
@@ -62,7 +53,6 @@ export const anastasisData = {
de_DE: "Albanien",
en_UK: "Albania",
},
- currency: "ALL",
call_code: "+355",
},
{
@@ -73,7 +63,6 @@ export const anastasisData = {
de_DE: "Belgien",
en_UK: "Belgium",
},
- currency: "EUR",
call_code: "+32",
},
{
@@ -86,7 +75,6 @@ export const anastasisData = {
fr_FR: "Suisse",
en_UK: "Swiss",
},
- currency: "CHF",
call_code: "+41",
},
{
@@ -96,7 +84,6 @@ export const anastasisData = {
name_i18n: {
en_UK: "Czech Republic",
},
- currency: "CZK",
call_code: "+420",
},
{
@@ -110,7 +97,6 @@ export const anastasisData = {
fr_FR: "Allemagne",
en_UK: "Germany",
},
- currency: "EUR",
call_code: "+49",
},
{
@@ -121,7 +107,6 @@ export const anastasisData = {
name_i18n: {
en_UK: "Denmark",
},
- currency: "DKK",
call_code: "+45",
},
{
@@ -132,10 +117,19 @@ export const anastasisData = {
name_i18n: {
es_ES: "España",
},
- currency: "EUR",
call_code: "+44",
},
{
+ code: "fr",
+ name: "France",
+ continent: "Europe",
+ name_i18n: {
+ de_DE: "Frankreich",
+ fr_FR: "La France",
+ },
+ call_code: "+33",
+ },
+ {
code: "in",
name: "India",
continent: "India",
@@ -146,7 +140,6 @@ export const anastasisData = {
fr_FR: "l'Inde",
en_UK: "India",
},
- currency: "INR",
call_code: "+91",
},
{
@@ -157,7 +150,6 @@ export const anastasisData = {
de_DE: "Italien",
en_UK: "Italy",
},
- currency: "EUR",
call_code: "+39",
},
{
@@ -170,17 +162,26 @@ export const anastasisData = {
de_CH: "Japan",
en_UK: "Japan",
},
- currency: "JPY",
call_code: "+81",
},
{
- code: "sl",
+ code: "nl",
+ name: "Netherlands",
+ continent: "Europe",
+ name_i18n: {
+ de_DE: "Niederlande",
+ nl_NL: "Nederland",
+ en_UK: "Netherlands",
+ },
+ call_code: "+31",
+ },
+ {
+ code: "sk",
name: "Slovakia",
continent: "Europe",
name_i18n: {
en_UK: "Slovakia",
},
- currency: "EUR",
call_code: "+421",
},
{
@@ -194,37 +195,20 @@ export const anastasisData = {
fr_FR: "États-Unis d'Amérique (USA)",
en_UK: "United States of America (USA)",
},
- currency: "USD",
call_code: "+1",
},
{
code: "xx",
name: "Testland",
- continent: "Testcontinent",
- continent_i18n: { de_DE: "Testkontinent" },
+ continent: "Demoworld",
name_i18n: {
de_DE: "Testlandt",
de_CH: "Testlandi",
fr_FR: "Testpais",
en_UK: "Testland",
},
- currency: "TESTKUDOS",
call_code: "+00",
},
- {
- code: "xy",
- name: "Demoland",
- continent: "Testcontinent",
- continent_i18n: { de_DE: "Testkontinent" },
- name_i18n: {
- de_DE: "Demolandt",
- de_CH: "Demolandi",
- fr_FR: "Demopais",
- en_UK: "Demoland",
- },
- currency: "KUDOS",
- call_code: "+01",
- },
],
},
countryDetails: {
@@ -337,9 +321,9 @@ export const anastasisData = {
widget: "anastasis_gtk_ia_ahv",
uuid: "1da87570-ba16-4f62-8a7e-cbda92f51591",
"validation-regex":
- "^(756).[0-9]{4}.[0-9]{4}.[0-9]{2}|(756)[0-9]{10}$",
+ "^(756)\\.[0-9]{4}\\.[0-9]{4}\\.[0-9]{2}|(756)[0-9]{10}$",
"validation-logic": "CH_AHV_check",
- autocomplete: "???.????.????.??"
+ autocomplete: "???.????.????.??",
},
],
},
@@ -404,19 +388,6 @@ export const anastasisData = {
},
{
type: "string",
- name: "tax_number",
- label: "Taxpayer identification number",
- label_i18n: {
- de_DE: "Steuerliche Identifikationsnummer",
- en: "German taxpayer identification number",
- },
- widget: "anastasis_gtk_ia_tax_de",
- uuid: "dae48f85-e3ff-47a4-a4a3-ed981ed8c3c6",
- "validation-regex": "^[0-9]{11}$",
- "validation-logic": "DE_TIN_check",
- },
- {
- type: "string",
name: "social_security_number",
label: "Social security number",
label_i18n: {
@@ -429,6 +400,19 @@ export const anastasisData = {
"validation-logic": "DE_SVN_check",
optional: true,
},
+ {
+ type: "string",
+ name: "tax_number",
+ label: "Taxpayer identification number",
+ label_i18n: {
+ de_DE: "Steuerliche Identifikationsnummer",
+ en: "German taxpayer identification number",
+ },
+ widget: "anastasis_gtk_ia_tin_de",
+ uuid: "dae48f85-e3ff-47a4-a4a3-ed981ed8c3c6",
+ "validation-regex": "^[0-9]{11}$",
+ "validation-logic": "DE_TIN_check",
+ },
],
},
dk: {
@@ -514,6 +498,46 @@ export const anastasisData = {
},
],
},
+ fr: {
+ license: "GPLv3+",
+ "SPDX-License-Identifier": "GPL3.0-or-later",
+ required_attributes: [
+ {
+ type: "string",
+ name: "full_name",
+ label: "Full name",
+ widget: "anastasis_gtk_ia_full_name",
+ uuid: "9e8f463f-575f-42cb-85f3-759559997331",
+ },
+ {
+ type: "date",
+ name: "birthdate",
+ label: "Birthdate",
+ widget: "anastasis_gtk_ia_birthdate",
+ uuid: "83d655c7-bdb6-484d-904e-80c1058c8854",
+ },
+ {
+ type: "string",
+ name: "birthplace",
+ label: "Birthplace",
+ widget: "anastasis_gtk_ia_birthplace",
+ uuid: "4c822e8e-89c6-11eb-95c4-8b077ad8489f",
+ },
+ {
+ type: "string",
+ name: "social_security_number",
+ label: "Code Insee",
+ label_i18n: {
+ fr_FR: "Code Insee",
+ en: "INSEE code",
+ },
+ widget: "anastasis_gtk_ia_insee_fr",
+ uuid: "2f36a81c-3f6d-41f3-97ee-9c885bc41873",
+ "validation-regex": "^[0-9]{15}$",
+ "validation-logic": "FR_INSEE_check",
+ },
+ ],
+ },
in: {
license: "GPLv3+",
"SPDX-License-Identifier": "GPL3.0-or-later",
@@ -626,6 +650,46 @@ export const anastasisData = {
},
],
},
+ nl: {
+ license: "GPLv3+",
+ "SPDX-License-Identifier": "GPL3.0-or-later",
+ required_attributes: [
+ {
+ type: "string",
+ name: "full_name",
+ label: "Full name",
+ widget: "anastasis_gtk_ia_full_name",
+ uuid: "9e8f463f-575f-42cb-85f3-759559997331",
+ },
+ {
+ type: "date",
+ name: "birthdate",
+ label: "Birthdate",
+ widget: "anastasis_gtk_ia_birthdate",
+ uuid: "83d655c7-bdb6-484d-904e-80c1058c8854",
+ },
+ {
+ type: "string",
+ name: "birthplace",
+ label: "Birthplace",
+ widget: "anastasis_gtk_ia_birthplace",
+ uuid: "4c822e8e-89c6-11eb-95c4-8b077ad8489f",
+ },
+ {
+ type: "string",
+ name: "social_security_number",
+ label: "Citizen Service Number",
+ label_i18n: {
+ nl_NL: "Burgerservicenummer (BSN)",
+ en: "Citizen Service Number",
+ },
+ widget: "anastasis_gtk_ia_ssn_nl",
+ uuid: "b6bf1f14-1f85-4afb-af21-f54b88490bdc",
+ "validation-regex": "^[1-9][0-9]{8}$",
+ "validation-logic": "NL_BSN_check",
+ },
+ ],
+ },
sk: {
license: "GPLv3+",
"SPDX-License-Identifier": "GPL3.0-or-later",
@@ -702,35 +766,7 @@ export const anastasisData = {
xx: {
license: "GPLv3+",
"SPDX-License-Identifier": "GPL3.0-or-later",
- required_attributes: [
- {
- type: "string",
- name: "full_name",
- label: "Full name",
- widget: "anastasis_gtk_ia_full_name",
- uuid: "9e8f463f-575f-42cb-85f3-759559997331",
- },
- {
- type: "date",
- name: "birthdate",
- label: "Birthdate",
- widget: "anastasis_gtk_ia_birthdate",
- uuid: "83d655c7-bdb6-484d-904e-80c1058c8854",
- },
- {
- type: "string",
- name: "sq_number",
- label: "Square number",
- widget: "anastasis_gtk_xx_square",
- uuid: "ed790bca-89bf-11eb-96f2-233996cf644e",
- "validation-regex": "^[0-9]+$",
- "validation-logic": "XX_SQUARE_check",
- },
- ],
- },
- xy: {
- license: "GPLv3+",
- "SPDX-License-Identifier": "GPL3.0-or-later",
+ restricted: "xx",
required_attributes: [
{
type: "string",
@@ -754,6 +790,16 @@ export const anastasisData = {
uuid: "39190a95-cacb-4412-8bae-1f7da3f980b4",
"validation-regex": "^[0-9]+$",
"validation-logic": "XY_PRIME_check",
+ optional: true,
+ },
+ {
+ type: "string",
+ name: "sq_number",
+ label: "Square number",
+ widget: "anastasis_gtk_xx_square",
+ uuid: "ed790bca-89bf-11eb-96f2-233996cf644e",
+ "validation-regex": "^[0-9]+$",
+ "validation-logic": "XX_SQUARE_check",
},
],
},
diff --git a/packages/anastasis-core/src/index.ts b/packages/anastasis-core/src/index.ts
index 012667879..5dd560a2c 100644
--- a/packages/anastasis-core/src/index.ts
+++ b/packages/anastasis-core/src/index.ts
@@ -142,23 +142,13 @@ const logger = new Logger("anastasis-core:index.ts");
const ANASTASIS_HTTP_HEADER_POLICY_META_DATA = "Anastasis-Policy-Meta-Data";
-function getContinents(
- opts: { requireProvider?: boolean } = {},
-): ContinentInfo[] {
- const currenciesWithProvider = new Set<string>();
- anastasisData.providersList.anastasis_provider.forEach((x) => {
- currenciesWithProvider.add(x.currency);
- });
+function getContinents(): ContinentInfo[] {
const continentSet = new Set<string>();
const continents: ContinentInfo[] = [];
for (const country of anastasisData.countriesList.countries) {
if (continentSet.has(country.continent)) {
continue;
}
- if (opts.requireProvider && !currenciesWithProvider.has(country.currency)) {
- // Country's currency doesn't have any providers => skip
- continue;
- }
continentSet.add(country.continent);
continents.push({
...{ name_i18n: country.continent_i18n },
@@ -191,23 +181,14 @@ export class ReducerError extends Error {
* Get countries for a continent, abort with ReducerError
* exception when continent doesn't exist.
*/
-function getCountries(
- continent: string,
- opts: { requireProvider?: boolean } = {},
-): CountryInfo[] {
- const currenciesWithProvider = new Set<string>();
- anastasisData.providersList.anastasis_provider.forEach((x) => {
- currenciesWithProvider.add(x.currency);
- });
+function getCountries(continent: string): CountryInfo[] {
const countries = anastasisData.countriesList.countries.filter(
- (x) =>
- x.continent === continent &&
- (!opts.requireProvider || currenciesWithProvider.has(x.currency)),
+ (x) => x.continent === continent,
);
if (countries.length <= 0) {
throw new ReducerError({
code: TalerErrorCode.ANASTASIS_REDUCER_INPUT_INVALID,
- hint: "continent not found",
+ hint: `continent ${continent} not found`,
});
}
return countries;
@@ -217,9 +198,7 @@ export async function getBackupStartState(): Promise<ReducerStateBackup> {
return {
reducer_type: "backup",
backup_state: BackupStates.ContinentSelecting,
- continents: getContinents({
- requireProvider: true,
- }),
+ continents: getContinents(),
};
}
@@ -227,9 +206,7 @@ export async function getRecoveryStartState(): Promise<ReducerStateRecovery> {
return {
reducer_type: "recovery",
recovery_state: RecoveryStates.ContinentSelecting,
- continents: getContinents({
- requireProvider: true,
- }),
+ continents: getContinents(),
};
}
@@ -238,7 +215,6 @@ async function selectCountry(
args: ActionArgsSelectCountry,
): Promise<Partial<ReducerStateBackup> & Partial<ReducerStateRecovery>> {
const countryCode = args.country_code;
- const currencies = args.currencies;
const country = anastasisData.countriesList.countries.find(
(x) => x.code === countryCode,
);
@@ -258,7 +234,10 @@ async function selectCountry(
const providers: { [x: string]: AuthenticationProviderStatus } = {};
for (const prov of anastasisData.providersList.anastasis_provider) {
- if (currencies.includes(prov.currency)) {
+ let shouldAdd =
+ country.code === prov.restricted ||
+ (country.code !== "xx" && !prov.restricted);
+ if (shouldAdd) {
providers[prov.url] = {
status: "not-contacted",
};
@@ -270,7 +249,6 @@ async function selectCountry(
return {
selected_country: countryCode,
- currencies,
required_attributes: ra,
authentication_providers: providers,
};
@@ -1223,9 +1201,7 @@ async function backupSelectContinent(
state: ReducerStateBackup,
args: ActionArgsSelectContinent,
): Promise<ReducerStateBackup | ReducerStateError> {
- const countries = getCountries(args.continent, {
- requireProvider: true,
- });
+ const countries = getCountries(args.continent);
if (countries.length <= 0) {
return {
reducer_type: "error",
@@ -1245,9 +1221,7 @@ async function recoverySelectContinent(
state: ReducerStateRecovery,
args: ActionArgsSelectContinent,
): Promise<ReducerStateRecovery | ReducerStateError> {
- const countries = getCountries(args.continent, {
- requireProvider: true,
- });
+ const countries = getCountries(args.continent);
return {
...state,
recovery_state: RecoveryStates.CountrySelecting,
@@ -1540,6 +1514,40 @@ async function nextFromChallengeSelecting(
};
}
+async function syncProviders(
+ state: ReducerStateRecovery,
+ args: void,
+): Promise<ReducerStateRecovery | ReducerStateError> {
+ const escrowMethods = state.verbatim_recovery_document?.escrow_methods ?? [];
+ if (escrowMethods.length === 0) {
+ return {
+ reducer_type: "error",
+ code: TalerErrorCode.ANASTASIS_REDUCER_ACTION_INVALID,
+ hint: "Can't sync, no escrow methods in recovery doc.",
+ };
+ }
+ for (const x of escrowMethods) {
+ const pi = state.authentication_providers?.[x.url];
+ if (pi?.status === "ok") {
+ logger.info(`provider ${x.url} is synced`);
+ continue;
+ }
+ const newPi = await getProviderInfo(x.url);
+ return {
+ ...state,
+ authentication_providers: {
+ ...state.authentication_providers,
+ [x.url]: newPi,
+ },
+ };
+ }
+ return {
+ reducer_type: "error",
+ code: TalerErrorCode.ANASTASIS_REDUCER_PROVIDERS_ALREADY_SYNCED,
+ hint: "all providers are already synced",
+ };
+}
+
async function enterSecretName(
state: ReducerStateBackup,
args: ActionArgsEnterSecretName,
@@ -1714,6 +1722,7 @@ const recoveryTransitions: Record<
),
...transition("poll", codecForAny(), pollChallenges),
...transition("next", codecForAny(), nextFromChallengeSelecting),
+ ...transition("sync_providers", codecForAny(), syncProviders),
},
[RecoveryStates.ChallengeSolving]: {
...transitionRecoveryJump("back", RecoveryStates.ChallengeSelecting),
diff --git a/packages/anastasis-core/src/reducer-types.ts b/packages/anastasis-core/src/reducer-types.ts
index bb06ea7c3..a0af2f86e 100644
--- a/packages/anastasis-core/src/reducer-types.ts
+++ b/packages/anastasis-core/src/reducer-types.ts
@@ -41,7 +41,6 @@ export interface CountryInfo {
code: string;
name: string;
continent: string;
- currency: string;
}
export interface Policy {
@@ -77,8 +76,6 @@ export interface ReducerStateBackup {
backup_state: BackupStates;
- currencies?: string[];
-
continents?: ContinentInfo[];
countries?: CountryInfo[];
@@ -201,7 +198,6 @@ export interface ReducerStateRecovery {
selected_continent?: string;
selected_country?: string;
- currencies?: string[];
required_attributes?: UserAttributeSpec[];
@@ -406,7 +402,6 @@ export const codecForActionArgSelectContinent = () =>
export interface ActionArgsSelectCountry {
country_code: string;
- currencies: string[];
}
export interface ActionArgsSelectChallenge {
@@ -551,5 +546,4 @@ export const codecForActionArgsSelectChallenge = () =>
export const codecForActionArgSelectCountry = () =>
buildCodecForObject<ActionArgsSelectCountry>()
.property("country_code", codecForString())
- .property("currencies", codecForList(codecForString()))
.build("ActionArgSelectCountry");