diff options
author | Florian Dold <florian@dold.me> | 2021-11-04 21:06:45 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-11-04 21:06:52 +0100 |
commit | 09d01a4bf16c3fcbe6020d8efd38cae34db53514 (patch) | |
tree | 95978a2a218d741d34bf6eca13164452fdf418ce /packages | |
parent | 3847f2ddb80c96a69caeeac5e312807c50f1dcbb (diff) | |
download | wallet-core-09d01a4bf16c3fcbe6020d8efd38cae34db53514.tar.xz |
anastasis-core: payments
Diffstat (limited to 'packages')
-rw-r--r-- | packages/anastasis-core/src/index.ts | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/packages/anastasis-core/src/index.ts b/packages/anastasis-core/src/index.ts index 238b658a0..53364fc08 100644 --- a/packages/anastasis-core/src/index.ts +++ b/packages/anastasis-core/src/index.ts @@ -443,17 +443,6 @@ async function prepareRecoveryData( async function uploadSecret( state: ReducerStateBackup, ): 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) { state = await prepareRecoveryData(state); } @@ -467,7 +456,7 @@ async function uploadSecret( const rd = recoveryData.recovery_document; const truthPayUris: string[] = []; - + const userIdCache: Record<string, UserIdentifier> = {}; for (const truthKey of Object.keys(truthMetadataMap)) { const tm = truthMetadataMap[truthKey]; const pol = state.policies![tm.policy_index]; @@ -480,10 +469,21 @@ async function uploadSecret( tm.truth_key, 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( tm.key_share, - uid, + userId, authMethod.type === "question" ? bytesToString(decodeCrock(authMethod.challenge)) : undefined, @@ -515,6 +515,7 @@ async function uploadSecret( }; } truthPayUris.push(talerPayUri); + continue; } return { code: TalerErrorCode.ANASTASIS_REDUCER_NETWORK_FAILED, @@ -535,7 +536,7 @@ async function uploadSecret( const policyPayUris: string[] = []; for (const prov of state.policy_providers!) { - const uid = uidMap[prov.provider_url]; + const uid = userIdCache[prov.provider_url]; const acctKeypair = accountKeypairDerive(uid); const zippedDoc = await compressRecoveryDoc(rd); const encRecoveryDoc = await encryptRecoveryDocument( @@ -607,6 +608,7 @@ async function uploadSecret( core_secret: undefined, backup_state: BackupStates.BackupFinished, success_details: successDetails, + payments: undefined, }; } @@ -1240,9 +1242,14 @@ const backupTransitions: Record< ), ...transition("enter_secret_name", codecForAny(), enterSecretName), }, - [BackupStates.PoliciesPaying]: {}, - [BackupStates.TruthsPaying]: {}, - [BackupStates.PoliciesPaying]: {}, + [BackupStates.PoliciesPaying]: { + ...transitionBackupJump("back", BackupStates.SecretEditing), + ...transition("pay", codecForAny(), uploadSecret), + }, + [BackupStates.TruthsPaying]: { + ...transitionBackupJump("back", BackupStates.SecretEditing), + ...transition("pay", codecForAny(), uploadSecret), + }, [BackupStates.BackupFinished]: { ...transitionBackupJump("back", BackupStates.SecretEditing), }, |