diff options
author | Florian Dold <florian@dold.me> | 2021-11-04 21:56:02 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-11-04 21:56:02 +0100 |
commit | 34d2e4703d8a583c8e7c3c2ea398c1280acccd08 (patch) | |
tree | 5f281bebb30fd955d8a610014c5c9e65e64bea27 /packages/anastasis-core/src/index.ts | |
parent | 5a72e4ae3e9ebd77547ac5aa95cd0b54b39a34cd (diff) | |
download | wallet-core-34d2e4703d8a583c8e7c3c2ea398c1280acccd08.tar.xz |
anastasis-core: fix user id caching
Diffstat (limited to 'packages/anastasis-core/src/index.ts')
-rw-r--r-- | packages/anastasis-core/src/index.ts | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/packages/anastasis-core/src/index.ts b/packages/anastasis-core/src/index.ts index f2b8ff1d1..0f391b733 100644 --- a/packages/anastasis-core/src/index.ts +++ b/packages/anastasis-core/src/index.ts @@ -458,6 +458,19 @@ async function uploadSecret( const truthPayUris: string[] = []; const userIdCache: Record<string, UserIdentifier> = {}; + const getUserIdCaching = async (providerUrl: string) => { + let userId = userIdCache[providerUrl]; + if (!userId) { + const provider = state.authentication_providers![ + providerUrl + ] as AuthenticationProviderStatusOk; + userId = userIdCache[providerUrl] = await userIdentifierDerive( + state.identity_attributes!, + provider.salt, + ); + } + return userId; + }; for (const truthKey of Object.keys(truthMetadataMap)) { const tm = truthMetadataMap[truthKey]; const pol = state.policies![tm.policy_index]; @@ -471,16 +484,7 @@ async function uploadSecret( truthValue, ); 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, - ); - } + const userId = await getUserIdCaching(meth.provider); // FIXME: check that the question salt is okay here, looks weird. const encryptedKeyShare = await encryptKeyshare( tm.key_share, @@ -537,11 +541,11 @@ async function uploadSecret( const policyPayUris: string[] = []; for (const prov of state.policy_providers!) { - const uid = userIdCache[prov.provider_url]; - const acctKeypair = accountKeypairDerive(uid); + const userId = await getUserIdCaching(prov.provider_url); + const acctKeypair = accountKeypairDerive(userId); const zippedDoc = await compressRecoveryDoc(rd); const encRecoveryDoc = await encryptRecoveryDocument( - uid, + userId, encodeCrock(zippedDoc), ); const bodyHash = hash(decodeCrock(encRecoveryDoc)); |