anastasis-core: payments
This commit is contained in:
parent
3847f2ddb8
commit
09d01a4bf1
@ -443,17 +443,6 @@ async function prepareRecoveryData(
|
|||||||
async function uploadSecret(
|
async function uploadSecret(
|
||||||
state: ReducerStateBackup,
|
state: ReducerStateBackup,
|
||||||
): Promise<ReducerStateBackup | ReducerStateError> {
|
): Promise<ReducerStateBackup | ReducerStateError> {
|
||||||
const uidMap: Record<string, UserIdentifier> = {};
|
|
||||||
for (const prov of state.policy_providers!) {
|
|
||||||
const provider = state.authentication_providers![
|
|
||||||
prov.provider_url
|
|
||||||
] as AuthenticationProviderStatusOk;
|
|
||||||
uidMap[prov.provider_url] = await userIdentifierDerive(
|
|
||||||
state.identity_attributes!,
|
|
||||||
provider.salt,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!state.recovery_data) {
|
if (!state.recovery_data) {
|
||||||
state = await prepareRecoveryData(state);
|
state = await prepareRecoveryData(state);
|
||||||
}
|
}
|
||||||
@ -467,7 +456,7 @@ async function uploadSecret(
|
|||||||
const rd = recoveryData.recovery_document;
|
const rd = recoveryData.recovery_document;
|
||||||
|
|
||||||
const truthPayUris: string[] = [];
|
const truthPayUris: string[] = [];
|
||||||
|
const userIdCache: Record<string, UserIdentifier> = {};
|
||||||
for (const truthKey of Object.keys(truthMetadataMap)) {
|
for (const truthKey of Object.keys(truthMetadataMap)) {
|
||||||
const tm = truthMetadataMap[truthKey];
|
const tm = truthMetadataMap[truthKey];
|
||||||
const pol = state.policies![tm.policy_index];
|
const pol = state.policies![tm.policy_index];
|
||||||
@ -480,10 +469,21 @@ async function uploadSecret(
|
|||||||
tm.truth_key,
|
tm.truth_key,
|
||||||
truthValue,
|
truthValue,
|
||||||
);
|
);
|
||||||
const uid = uidMap[meth.provider];
|
logger.info(`uploading to ${meth.provider}`);
|
||||||
|
let userId = userIdCache[meth.provider];
|
||||||
|
if (!userId) {
|
||||||
|
const provider = state.authentication_providers![
|
||||||
|
meth.provider
|
||||||
|
] as AuthenticationProviderStatusOk;
|
||||||
|
userId = userIdCache[meth.provider] = await userIdentifierDerive(
|
||||||
|
state.identity_attributes!,
|
||||||
|
provider.salt,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// FIXME: check that the question salt is okay here, looks weird.
|
||||||
const encryptedKeyShare = await encryptKeyshare(
|
const encryptedKeyShare = await encryptKeyshare(
|
||||||
tm.key_share,
|
tm.key_share,
|
||||||
uid,
|
userId,
|
||||||
authMethod.type === "question"
|
authMethod.type === "question"
|
||||||
? bytesToString(decodeCrock(authMethod.challenge))
|
? bytesToString(decodeCrock(authMethod.challenge))
|
||||||
: undefined,
|
: undefined,
|
||||||
@ -515,6 +515,7 @@ async function uploadSecret(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
truthPayUris.push(talerPayUri);
|
truthPayUris.push(talerPayUri);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
code: TalerErrorCode.ANASTASIS_REDUCER_NETWORK_FAILED,
|
code: TalerErrorCode.ANASTASIS_REDUCER_NETWORK_FAILED,
|
||||||
@ -535,7 +536,7 @@ async function uploadSecret(
|
|||||||
const policyPayUris: string[] = [];
|
const policyPayUris: string[] = [];
|
||||||
|
|
||||||
for (const prov of state.policy_providers!) {
|
for (const prov of state.policy_providers!) {
|
||||||
const uid = uidMap[prov.provider_url];
|
const uid = userIdCache[prov.provider_url];
|
||||||
const acctKeypair = accountKeypairDerive(uid);
|
const acctKeypair = accountKeypairDerive(uid);
|
||||||
const zippedDoc = await compressRecoveryDoc(rd);
|
const zippedDoc = await compressRecoveryDoc(rd);
|
||||||
const encRecoveryDoc = await encryptRecoveryDocument(
|
const encRecoveryDoc = await encryptRecoveryDocument(
|
||||||
@ -607,6 +608,7 @@ async function uploadSecret(
|
|||||||
core_secret: undefined,
|
core_secret: undefined,
|
||||||
backup_state: BackupStates.BackupFinished,
|
backup_state: BackupStates.BackupFinished,
|
||||||
success_details: successDetails,
|
success_details: successDetails,
|
||||||
|
payments: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1240,9 +1242,14 @@ const backupTransitions: Record<
|
|||||||
),
|
),
|
||||||
...transition("enter_secret_name", codecForAny(), enterSecretName),
|
...transition("enter_secret_name", codecForAny(), enterSecretName),
|
||||||
},
|
},
|
||||||
[BackupStates.PoliciesPaying]: {},
|
[BackupStates.PoliciesPaying]: {
|
||||||
[BackupStates.TruthsPaying]: {},
|
...transitionBackupJump("back", BackupStates.SecretEditing),
|
||||||
[BackupStates.PoliciesPaying]: {},
|
...transition("pay", codecForAny(), uploadSecret),
|
||||||
|
},
|
||||||
|
[BackupStates.TruthsPaying]: {
|
||||||
|
...transitionBackupJump("back", BackupStates.SecretEditing),
|
||||||
|
...transition("pay", codecForAny(), uploadSecret),
|
||||||
|
},
|
||||||
[BackupStates.BackupFinished]: {
|
[BackupStates.BackupFinished]: {
|
||||||
...transitionBackupJump("back", BackupStates.SecretEditing),
|
...transitionBackupJump("back", BackupStates.SecretEditing),
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user