diff options
author | Florian Dold <florian@dold.me> | 2022-04-12 20:55:34 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-04-12 20:55:34 +0200 |
commit | f3d8b4474302a00fd923581046b0f5828a4c5976 (patch) | |
tree | 973c69498cb822580c1ad3f42798768637e9f1fb /packages/anastasis-core/src/index.ts | |
parent | 1e92093a50962f4702339e872caa4f82af90af70 (diff) | |
download | wallet-core-f3d8b4474302a00fd923581046b0f5828a4c5976.tar.xz |
copyright headers
Diffstat (limited to 'packages/anastasis-core/src/index.ts')
-rw-r--r-- | packages/anastasis-core/src/index.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/packages/anastasis-core/src/index.ts b/packages/anastasis-core/src/index.ts index 5a9199e02..542e7eafb 100644 --- a/packages/anastasis-core/src/index.ts +++ b/packages/anastasis-core/src/index.ts @@ -74,6 +74,7 @@ import { DiscoveryResult, PolicyMetaInfo, ChallengeInfo, + AggregatedPolicyMetaInfo, } from "./reducer-types.js"; import fetchPonyfill from "fetch-ponyfill"; import { @@ -1451,6 +1452,37 @@ async function updateSecretExpiration( }); } +export function mergeDiscoveryAggregate( + newPolicies: PolicyMetaInfo[], + oldAgg: AggregatedPolicyMetaInfo[], +): AggregatedPolicyMetaInfo[] { + const aggregatedPolicies: AggregatedPolicyMetaInfo[] = [...oldAgg] ?? []; + const polHashToIndex: Record<string, number> = {}; + for (const pol of newPolicies) { + const oldIndex = polHashToIndex[pol.policy_hash]; + if (oldIndex != null) { + aggregatedPolicies[oldIndex].providers.push({ + provider_url: pol.provider_url, + version: pol.version, + }); + } else { + aggregatedPolicies.push({ + attribute_mask: pol.attribute_mask, + policy_hash: pol.policy_hash, + providers: [ + { + provider_url: pol.provider_url, + version: pol.version, + }, + ], + secret_name: pol.secret_name, + }); + polHashToIndex[pol.policy_hash] = aggregatedPolicies.length - 1; + } + } + return aggregatedPolicies; +} + const backupTransitions: Record< BackupStates, Transition<ReducerStateBackup> |