@procivis/one-react-native-components 0.3.94 → 0.3.95

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,6 @@
1
- import { Claim, ClaimValue, DataTypeEnum, HistoryListItem, ProofInputClaim } from '@procivis/react-native-one-core';
1
+ import { HistoryListItem } from '@procivis/react-native-one-core';
2
2
  import moment, { Moment } from 'moment';
3
3
 
4
- import { nonEmptyFilter } from './filtering';
5
-
6
4
  export interface HistoryGroupByDaySection {
7
5
  data: HistoryListItem[];
8
6
  date: Moment;
@@ -30,42 +28,3 @@ export const groupEntriesByDay = (entries: HistoryListItem[]) => {
30
28
  return item;
31
29
  });
32
30
  };
33
-
34
- export const claimValueFromProofInputClaim = ({ schema, value }: ProofInputClaim): ClaimValue | undefined => {
35
- if (!value) {
36
- return undefined;
37
- }
38
-
39
- if (Array.isArray(value)) {
40
- const values = value.map(claimFromProofInputClaim).filter(nonEmptyFilter);
41
- return schema.dataType === (DataTypeEnum.Object as string)
42
- ? {
43
- array: schema.array,
44
- dataType: DataTypeEnum.Object,
45
- value: values,
46
- }
47
- : {
48
- array: true,
49
- dataType: schema.dataType,
50
- value: values,
51
- };
52
- }
53
-
54
- return {
55
- array: false,
56
- dataType: schema.dataType,
57
- value,
58
- };
59
- };
60
-
61
- export const claimFromProofInputClaim = (input: ProofInputClaim): Claim | undefined => {
62
- const value = claimValueFromProofInputClaim(input);
63
- if (!value) {
64
- return undefined;
65
- }
66
- return {
67
- ...value,
68
- id: input.schema.id,
69
- key: input.schema.key,
70
- };
71
- };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Claim,
3
+ ClaimValue,
3
4
  Config,
4
- DataTypeEnum,
5
5
  FailureHint,
6
6
  PresentationDefinitionV2ClaimValue,
7
7
  PresentationDefinitionV2CredentialClaim,
@@ -27,7 +27,7 @@ import {
27
27
  } from '.';
28
28
  import { ShareCredentialCardLabels, validityCheckedCardFromCredential } from './credential-sharing';
29
29
 
30
- const v2ClaimValueToClaimValue = (value: PresentationDefinitionV2ClaimValue): string | number | boolean | Claim[] => {
30
+ const v2ClaimValueToClaimValue = (value: PresentationDefinitionV2ClaimValue): ClaimValue => {
31
31
  if (!Array.isArray(value)) {
32
32
  return value;
33
33
  }
@@ -35,31 +35,10 @@ const v2ClaimValueToClaimValue = (value: PresentationDefinitionV2ClaimValue): st
35
35
  };
36
36
 
37
37
  const v2PresentationClaimToClaim = (claim: PresentationDefinitionV2CredentialClaim): Claim => {
38
- if (Array.isArray(claim.value)) {
39
- if (claim.schema.array) {
40
- return {
41
- array: claim.schema.array,
42
- dataType: claim.schema.datatype,
43
- id: claim.path,
44
- key: claim.path,
45
- value: v2ClaimValueToClaimValue(claim.value) as Claim[],
46
- };
47
- } else {
48
- return {
49
- array: claim.schema.array,
50
- dataType: DataTypeEnum.Object,
51
- id: claim.path,
52
- key: claim.path,
53
- value: v2ClaimValueToClaimValue(claim.value) as Claim[],
54
- };
55
- }
56
- }
57
38
  return {
58
- array: false,
59
- dataType: claim.schema.datatype,
60
- id: claim.path,
61
- key: claim.path,
62
- value: claim.value,
39
+ schema: claim.schema,
40
+ path: claim.path,
41
+ value: v2ClaimValueToClaimValue(claim.value),
63
42
  };
64
43
  };
65
44
 
@@ -124,28 +124,18 @@ const getAttributeSelectorStatus = (
124
124
  return selected ? SelectorStatus.SelectedCheckmark : SelectorStatus.Empty;
125
125
  };
126
126
 
127
- type ClaimWithOptionalPath = Claim & {
128
- path?: string;
129
- };
130
-
131
127
  type FlatClaim = Claim & {
132
- path: string;
133
128
  isArrayElement?: boolean;
134
129
  };
135
130
 
136
131
  // Returns a spread list of all claims with their full JSON path as key, including all intermediate objects
137
- const spreadClaims = (claims: ClaimWithOptionalPath[]): FlatClaim[] => {
138
- const claimsWithPath: FlatClaim[] = claims.map((c) => ({
139
- ...c,
140
- path: c.path ?? c.key,
141
- }));
142
- return claimsWithPath.reduce((acc, claim) => {
132
+ const spreadClaims = (claims: Claim[]): FlatClaim[] => {
133
+ return claims.reduce((acc, claim) => {
143
134
  const result = [claim];
144
135
  if (Array.isArray(claim.value)) {
145
- const nestedClaimsWithPath: FlatClaim[] = claim.value.map((c, i) => ({
136
+ const nestedClaimsWithPath: FlatClaim[] = claim.value.map((c) => ({
146
137
  ...c,
147
- path: claim.array ? `${c.key}/${i}` : c.key,
148
- isArrayElement: claim.array,
138
+ isArrayElement: claim.schema.array && claim.path.split('/').pop() !== claim.schema.key,
149
139
  }));
150
140
  result.push(...spreadClaims(nestedClaimsWithPath));
151
141
  }
@@ -47,21 +47,8 @@ export const supportsSelectiveDisclosure = (credential: CredentialListItem | und
47
47
  : undefined;
48
48
  };
49
49
 
50
- const findClaimByPathParts = (path: string[], claims?: Claim[]): Claim | undefined => {
51
- if (!claims?.length) {
52
- return undefined;
53
- }
54
- const [first, second, ...rest] = path;
55
- const claim = claims.find((c) => c.key === first);
56
- if (claim === undefined || second === undefined || claim.dataType !== DataTypeEnum.Object) {
57
- return claim;
58
- }
59
-
60
- return findClaimByPathParts([`${first}/${second}`, ...rest], claim.value as Claim[]);
61
- };
62
-
63
50
  export const findClaimByPath = (path: string | undefined, claims: Claim[] | undefined) =>
64
- path ? findClaimByPathParts(path.split('/'), claims) : undefined;
51
+ path ? claims?.find((claim) => claim.path === path) : undefined;
65
52
 
66
53
  const formatCredentialDetail = (claim: Claim, config: Config, testID: string): string => {
67
54
  const attributeValue = detailsCardAttributeValueFromClaim(claim, config, testID);
@@ -224,27 +211,20 @@ export const getCredentialCardPropsFromCredential = (
224
211
  export const detailsCardAttributeFromClaim = (claim: Claim, config: Config, testID: string): CredentialAttribute => {
225
212
  const value = detailsCardAttributeValueFromClaim(claim, config, testID);
226
213
  return {
227
- id: claim.id,
228
- name: claim.key.split('/').pop(),
229
- path: claim.key,
214
+ id: claim.path,
215
+ name: claim.path.split('/').pop(),
216
+ path: claim.path,
230
217
  ...value,
231
218
  };
232
219
  };
233
220
 
234
221
  const detailsCardAttributeValueFromClaim = (claim: Claim, config: Config, testID: string): CredentialAttributeValue => {
235
- const typeConfig = config?.datatype[claim.dataType];
222
+ const typeConfig = config?.datatype[claim.schema.datatype];
236
223
 
237
- if (claim.array) {
224
+ if (claim.schema.array) {
238
225
  return {
239
- values: (claim.value || []).map((arrayValue, index) => {
240
- return detailsCardAttributeFromClaim(
241
- {
242
- ...arrayValue,
243
- id: `${arrayValue.id}/${index}`,
244
- },
245
- config,
246
- concatTestID(testID, index.toString()),
247
- );
226
+ values: ((claim.value as Claim[]) || []).map((arrayValue, index) => {
227
+ return detailsCardAttributeFromClaim(arrayValue, config, concatTestID(testID, index.toString()));
248
228
  }),
249
229
  };
250
230
  } else {