@bifold/oca 1.0.0
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.
- package/README.md +33 -0
- package/build/__tests__/remote.test.d.ts +1 -0
- package/build/__tests__/remote.test.js +162 -0
- package/build/constants.d.ts +4 -0
- package/build/constants.js +7 -0
- package/build/formatters/credential/CredentialFormatter.d.ts +8 -0
- package/build/formatters/credential/CredentialFormatter.js +32 -0
- package/build/formatters/credential/DisplayAttribute.d.ts +11 -0
- package/build/formatters/credential/DisplayAttribute.js +18 -0
- package/build/formatters/credential/LocalizedCredential.d.ts +13 -0
- package/build/formatters/credential/LocalizedCredential.js +57 -0
- package/build/formatters/credential/index.d.ts +4 -0
- package/build/formatters/credential/index.js +12 -0
- package/build/formatters/index.d.ts +4 -0
- package/build/formatters/index.js +12 -0
- package/build/index.d.ts +5 -0
- package/build/index.js +34 -0
- package/build/interfaces/data/base/BaseOverlayData.interface.d.ts +5 -0
- package/build/interfaces/data/base/BaseOverlayData.interface.js +2 -0
- package/build/interfaces/data/branding/BrandingOverlayData.interface.d.ts +12 -0
- package/build/interfaces/data/branding/BrandingOverlayData.interface.js +2 -0
- package/build/interfaces/data/branding/LegacyBrandingOverlayData.interface.d.ts +15 -0
- package/build/interfaces/data/branding/LegacyBrandingOverlayData.interface.js +2 -0
- package/build/interfaces/data/bundle/OverlayBundleData.interface.d.ts +6 -0
- package/build/interfaces/data/bundle/OverlayBundleData.interface.js +2 -0
- package/build/interfaces/data/capture-base/CaptureBaseData.interface.d.ts +7 -0
- package/build/interfaces/data/capture-base/CaptureBaseData.interface.js +2 -0
- package/build/interfaces/data/index.d.ts +12 -0
- package/build/interfaces/data/index.js +2 -0
- package/build/interfaces/data/semantic/CharacterEncodingOverlayData.interface.d.ts +6 -0
- package/build/interfaces/data/semantic/CharacterEncodingOverlayData.interface.js +2 -0
- package/build/interfaces/data/semantic/FormatOverlayData.interface.d.ts +4 -0
- package/build/interfaces/data/semantic/FormatOverlayData.interface.js +2 -0
- package/build/interfaces/data/semantic/InformationOverlayData.interface.d.ts +5 -0
- package/build/interfaces/data/semantic/InformationOverlayData.interface.js +2 -0
- package/build/interfaces/data/semantic/LabelOverlayData.interface.d.ts +7 -0
- package/build/interfaces/data/semantic/LabelOverlayData.interface.js +2 -0
- package/build/interfaces/data/semantic/MetaOverlayData.interface.d.ts +12 -0
- package/build/interfaces/data/semantic/MetaOverlayData.interface.js +2 -0
- package/build/interfaces/data/semantic/StandardOverlayData.interface.d.ts +5 -0
- package/build/interfaces/data/semantic/StandardOverlayData.interface.js +2 -0
- package/build/interfaces/index.d.ts +2 -0
- package/build/interfaces/index.js +18 -0
- package/build/interfaces/overlay/OverlayBundleAttribute.interface.d.ts +9 -0
- package/build/interfaces/overlay/OverlayBundleAttribute.interface.js +2 -0
- package/build/interfaces/overlay/OverlayBundleMetadata.interface.d.ts +9 -0
- package/build/interfaces/overlay/OverlayBundleMetadata.interface.js +2 -0
- package/build/interfaces/overlay/index.d.ts +3 -0
- package/build/interfaces/overlay/index.js +2 -0
- package/build/legacy/index.d.ts +3 -0
- package/build/legacy/index.js +19 -0
- package/build/legacy/resolver/oca.d.ts +99 -0
- package/build/legacy/resolver/oca.js +239 -0
- package/build/legacy/resolver/record.d.ts +50 -0
- package/build/legacy/resolver/record.js +37 -0
- package/build/legacy/resolver/remote-oca.d.ts +186 -0
- package/build/legacy/resolver/remote-oca.js +536 -0
- package/build/types/OverlayTypeMap.d.ts +5 -0
- package/build/types/OverlayTypeMap.js +25 -0
- package/build/types/TypeEnums.d.ts +19 -0
- package/build/types/TypeEnums.js +24 -0
- package/build/types/base/BaseOverlay.d.ts +8 -0
- package/build/types/base/BaseOverlay.js +28 -0
- package/build/types/branding/BrandingOverlay.d.ts +15 -0
- package/build/types/branding/BrandingOverlay.js +68 -0
- package/build/types/branding/LegacyBrandingOverlay.d.ts +18 -0
- package/build/types/branding/LegacyBrandingOverlay.js +51 -0
- package/build/types/bundle/OverlayBundle.d.ts +20 -0
- package/build/types/bundle/OverlayBundle.js +167 -0
- package/build/types/capture-base/CaptureBase.d.ts +10 -0
- package/build/types/capture-base/CaptureBase.js +30 -0
- package/build/types/index.d.ts +14 -0
- package/build/types/index.js +33 -0
- package/build/types/semantic/CharacterEncodingOverlay.d.ts +9 -0
- package/build/types/semantic/CharacterEncodingOverlay.js +43 -0
- package/build/types/semantic/FormatOverlay.d.ts +7 -0
- package/build/types/semantic/FormatOverlay.js +30 -0
- package/build/types/semantic/InformationOverlay.d.ts +8 -0
- package/build/types/semantic/InformationOverlay.js +31 -0
- package/build/types/semantic/LabelOverlay.d.ts +10 -0
- package/build/types/semantic/LabelOverlay.js +41 -0
- package/build/types/semantic/MetaOverlay.d.ts +15 -0
- package/build/types/semantic/MetaOverlay.js +54 -0
- package/build/types/semantic/StandardOverlay.d.ts +8 -0
- package/build/types/semantic/StandardOverlay.js +38 -0
- package/build/utils/color/generateColor.d.ts +2 -0
- package/build/utils/color/generateColor.js +11 -0
- package/build/utils/color/hashCode.d.ts +8 -0
- package/build/utils/color/hashCode.js +12 -0
- package/build/utils/color/hashToRGBA.d.ts +8 -0
- package/build/utils/color/hashToRGBA.js +23 -0
- package/build/utils/color/index.d.ts +5 -0
- package/build/utils/color/index.js +15 -0
- package/build/utils/color/luminanceForHexColor.d.ts +7 -0
- package/build/utils/color/luminanceForHexColor.js +18 -0
- package/build/utils/color/mulberry32.d.ts +9 -0
- package/build/utils/color/mulberry32.js +16 -0
- package/build/utils/color/textColorForBackground.d.ts +1 -0
- package/build/utils/color/textColorForBackground.js +24 -0
- package/build/utils/credential-definition.d.ts +1 -0
- package/build/utils/credential-definition.js +21 -0
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.js +17 -0
- package/build/utils/logger.d.ts +5 -0
- package/build/utils/logger.js +17 -0
- package/build/utils/schema.d.ts +4 -0
- package/build/utils/schema.js +19 -0
- package/package.json +53 -0
- package/src/__tests__/__snapshots__/remote.test.ts.snap +293 -0
- package/src/__tests__/fixtures/bundle.json +131 -0
- package/src/__tests__/fixtures/oca.json +4 -0
- package/src/__tests__/fixtures/ocabundles.json +142 -0
- package/src/__tests__/remote.test.ts +180 -0
- package/src/constants.ts +7 -0
- package/src/formatters/credential/CredentialFormatter.ts +20 -0
- package/src/formatters/credential/DisplayAttribute.ts +29 -0
- package/src/formatters/credential/LocalizedCredential.ts +53 -0
- package/src/formatters/credential/index.ts +5 -0
- package/src/formatters/index.ts +5 -0
- package/src/index.ts +5 -0
- package/src/interfaces/data/base/BaseOverlayData.interface.ts +5 -0
- package/src/interfaces/data/branding/BrandingOverlayData.interface.ts +13 -0
- package/src/interfaces/data/branding/LegacyBrandingOverlayData.interface.ts +16 -0
- package/src/interfaces/data/bundle/OverlayBundleData.interface.ts +7 -0
- package/src/interfaces/data/capture-base/CaptureBaseData.interface.ts +7 -0
- package/src/interfaces/data/index.ts +25 -0
- package/src/interfaces/data/semantic/CharacterEncodingOverlayData.interface.ts +8 -0
- package/src/interfaces/data/semantic/FormatOverlayData.interface.ts +5 -0
- package/src/interfaces/data/semantic/InformationOverlayData.interface.ts +6 -0
- package/src/interfaces/data/semantic/LabelOverlayData.interface.ts +8 -0
- package/src/interfaces/data/semantic/MetaOverlayData.interface.ts +13 -0
- package/src/interfaces/data/semantic/StandardOverlayData.interface.ts +7 -0
- package/src/interfaces/index.ts +2 -0
- package/src/interfaces/overlay/OverlayBundleAttribute.interface.ts +9 -0
- package/src/interfaces/overlay/OverlayBundleMetadata.interface.ts +9 -0
- package/src/interfaces/overlay/index.ts +4 -0
- package/src/legacy/index.ts +3 -0
- package/src/legacy/resolver/oca.ts +377 -0
- package/src/legacy/resolver/record.ts +81 -0
- package/src/legacy/resolver/remote-oca.ts +661 -0
- package/src/types/OverlayTypeMap.ts +25 -0
- package/src/types/TypeEnums.ts +20 -0
- package/src/types/base/BaseOverlay.ts +18 -0
- package/src/types/branding/BrandingOverlay.ts +61 -0
- package/src/types/branding/LegacyBrandingOverlay.ts +47 -0
- package/src/types/bundle/OverlayBundle.ts +203 -0
- package/src/types/capture-base/CaptureBase.ts +22 -0
- package/src/types/index.ts +30 -0
- package/src/types/semantic/CharacterEncodingOverlay.ts +30 -0
- package/src/types/semantic/FormatOverlay.ts +15 -0
- package/src/types/semantic/InformationOverlay.ts +18 -0
- package/src/types/semantic/LabelOverlay.ts +30 -0
- package/src/types/semantic/MetaOverlay.ts +48 -0
- package/src/types/semantic/StandardOverlay.ts +24 -0
- package/src/utils/color/generateColor.ts +8 -0
- package/src/utils/color/hashCode.ts +11 -0
- package/src/utils/color/hashToRGBA.ts +22 -0
- package/src/utils/color/index.ts +7 -0
- package/src/utils/color/luminanceForHexColor.ts +19 -0
- package/src/utils/color/mulberry32.ts +15 -0
- package/src/utils/color/textColorForBackground.ts +18 -0
- package/src/utils/credential-definition.ts +19 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/logger.ts +14 -0
- package/src/utils/schema.ts +16 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import startCase from 'lodash.startcase'
|
|
2
|
+
|
|
3
|
+
import { defaultBundleLanguage } from '../../constants'
|
|
4
|
+
import {
|
|
5
|
+
IBrandingOverlayData,
|
|
6
|
+
ILegacyBrandingOverlayData,
|
|
7
|
+
IMetaOverlayData,
|
|
8
|
+
IOverlayBundleData,
|
|
9
|
+
} from '../../interfaces'
|
|
10
|
+
import {
|
|
11
|
+
BaseOverlay,
|
|
12
|
+
BrandingOverlay,
|
|
13
|
+
CaptureBase,
|
|
14
|
+
CharacterEncodingOverlay,
|
|
15
|
+
FormatOverlay,
|
|
16
|
+
LabelOverlay,
|
|
17
|
+
LegacyBrandingOverlay,
|
|
18
|
+
MetaOverlay,
|
|
19
|
+
OverlayBundle,
|
|
20
|
+
OverlayType,
|
|
21
|
+
} from '../../types'
|
|
22
|
+
import { generateColor } from '../../utils/color'
|
|
23
|
+
import { parseCredDefFromId } from '../../utils/credential-definition'
|
|
24
|
+
|
|
25
|
+
import { Field } from './record'
|
|
26
|
+
|
|
27
|
+
export const BrandingOverlayType = {
|
|
28
|
+
Branding01: OverlayType.Branding01,
|
|
29
|
+
Branding10: OverlayType.Branding10,
|
|
30
|
+
Branding11: OverlayType.Branding11,
|
|
31
|
+
} as const
|
|
32
|
+
|
|
33
|
+
export type BrandingOverlayType = (typeof BrandingOverlayType)[keyof typeof BrandingOverlayType]
|
|
34
|
+
export interface CredentialOverlay<T> {
|
|
35
|
+
bundle?: OCABundle
|
|
36
|
+
presentationFields?: Field[]
|
|
37
|
+
metaOverlay?: MetaOverlay
|
|
38
|
+
brandingOverlay?: T
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface OCABundleType {
|
|
42
|
+
get captureBase(): CaptureBase
|
|
43
|
+
get metaOverlay(): MetaOverlay | undefined
|
|
44
|
+
get labelOverlay(): LabelOverlay | undefined
|
|
45
|
+
get formatOverlay(): FormatOverlay | undefined
|
|
46
|
+
get characterEncodingOverlay(): CharacterEncodingOverlay | undefined
|
|
47
|
+
get brandingOverlay(): BrandingOverlay | LegacyBrandingOverlay | undefined
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface LanguageOverlay {
|
|
51
|
+
language: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type OCABundleResolveParams = {
|
|
55
|
+
identifiers: Identifiers
|
|
56
|
+
language?: string
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type OCABundleResolveDefaultParams = {
|
|
60
|
+
identifiers: Identifiers
|
|
61
|
+
meta?: Meta
|
|
62
|
+
language?: string
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type OCABundleResolveAllParams = {
|
|
66
|
+
identifiers: Identifiers
|
|
67
|
+
attributes?: Array<Field>
|
|
68
|
+
meta?: Meta
|
|
69
|
+
language?: string
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type OCABundleResolvePresentationFieldsParams = {
|
|
73
|
+
identifiers: Identifiers
|
|
74
|
+
attributes: Array<Field>
|
|
75
|
+
language?: string
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface OCABundleResolverType {
|
|
79
|
+
resolve(params: OCABundleResolveParams): Promise<OCABundle | undefined>
|
|
80
|
+
|
|
81
|
+
resolveDefaultBundle(params: OCABundleResolveDefaultParams): Promise<OCABundle | undefined>
|
|
82
|
+
|
|
83
|
+
presentationFields(params: OCABundleResolvePresentationFieldsParams): Promise<Field[]>
|
|
84
|
+
|
|
85
|
+
resolveAllBundles(
|
|
86
|
+
params: OCABundleResolveAllParams
|
|
87
|
+
): Promise<CredentialOverlay<BaseOverlay | BrandingOverlay | LegacyBrandingOverlay>>
|
|
88
|
+
|
|
89
|
+
getBrandingOverlayType(): BrandingOverlayType
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface OCABundleResolverOptions {
|
|
93
|
+
language?: string
|
|
94
|
+
brandingOverlayType?: BrandingOverlayType
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface Identifiers {
|
|
98
|
+
schemaId?: string
|
|
99
|
+
credentialDefinitionId?: string
|
|
100
|
+
templateId?: string
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface Meta {
|
|
104
|
+
alias?: string
|
|
105
|
+
credName?: string
|
|
106
|
+
credConnectionId?: string
|
|
107
|
+
logo?: string
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export class OCABundle implements OCABundleType {
|
|
111
|
+
private bundle: OverlayBundle
|
|
112
|
+
private options: OCABundleResolverOptions
|
|
113
|
+
|
|
114
|
+
public constructor(bundle: OverlayBundle, options?: OCABundleResolverOptions) {
|
|
115
|
+
this.bundle = bundle
|
|
116
|
+
this.options = {
|
|
117
|
+
brandingOverlayType: options?.brandingOverlayType ?? BrandingOverlayType.Branding10,
|
|
118
|
+
language: options?.language ?? defaultBundleLanguage,
|
|
119
|
+
}
|
|
120
|
+
// Make bundle overlay type come from options.brandingOverlayType
|
|
121
|
+
this.bundle.overlays.forEach((o) => {
|
|
122
|
+
if (o.type === BrandingOverlayType.Branding10 || o.type === BrandingOverlayType.Branding11) {
|
|
123
|
+
o.type = this.options.brandingOverlayType!
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public get captureBase(): CaptureBase {
|
|
129
|
+
const overlay = this.bundle.captureBase
|
|
130
|
+
|
|
131
|
+
if (!overlay) {
|
|
132
|
+
throw new Error('Capture Base must be defined')
|
|
133
|
+
}
|
|
134
|
+
return overlay
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public get characterEncodingOverlay(): CharacterEncodingOverlay | undefined {
|
|
138
|
+
return this.getOverlay<CharacterEncodingOverlay>(OverlayType.CharacterEncoding10)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public get formatOverlay(): FormatOverlay | undefined {
|
|
142
|
+
return this.getOverlay<FormatOverlay>(OverlayType.Format10)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public get labelOverlay(): LabelOverlay | undefined {
|
|
146
|
+
return this.getOverlay<LabelOverlay>(OverlayType.Label10, this.options.language)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public get metaOverlay(): MetaOverlay | undefined {
|
|
150
|
+
return this.getOverlay<MetaOverlay>(OverlayType.Meta10, this.options.language)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public get brandingOverlay(): BrandingOverlay | LegacyBrandingOverlay | undefined {
|
|
154
|
+
return this.getOverlay(this.options?.brandingOverlayType || BrandingOverlayType.Branding10)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public buildOverlay(name: string, language: string): MetaOverlay {
|
|
158
|
+
return new MetaOverlay({
|
|
159
|
+
capture_base: '',
|
|
160
|
+
type: OverlayType.Meta10,
|
|
161
|
+
name,
|
|
162
|
+
language,
|
|
163
|
+
description: '',
|
|
164
|
+
credential_help_text: '',
|
|
165
|
+
credential_support_url: '',
|
|
166
|
+
issuer: '',
|
|
167
|
+
issuer_description: '',
|
|
168
|
+
issuer_url: '',
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private getOverlay<T extends BaseOverlay>(type: string, language?: string): T | undefined {
|
|
173
|
+
if (type === OverlayType.CaptureBase10) {
|
|
174
|
+
return this.bundle.captureBase as unknown as T
|
|
175
|
+
}
|
|
176
|
+
if (language !== undefined) {
|
|
177
|
+
// we want to return branding even if there isn't a bundle for a given language
|
|
178
|
+
const overlay = this.bundle.overlays.find(
|
|
179
|
+
(item) =>
|
|
180
|
+
((item as unknown as LanguageOverlay).language === undefined && item.type === type.toString()) ||
|
|
181
|
+
(item.type === type.toString() && (item as unknown as LanguageOverlay).language === language)
|
|
182
|
+
) as T | undefined
|
|
183
|
+
if (overlay) {
|
|
184
|
+
return overlay
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return this.bundle.overlays.find((item) => item.type === type.toString()) as T
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export class DefaultOCABundleResolver implements OCABundleResolverType {
|
|
192
|
+
protected bundles: Record<string, OverlayBundle | string> = {}
|
|
193
|
+
protected options: OCABundleResolverOptions
|
|
194
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
195
|
+
private _log?: any
|
|
196
|
+
|
|
197
|
+
public constructor(
|
|
198
|
+
bundlesData: Record<string, IOverlayBundleData | string> = {},
|
|
199
|
+
options?: OCABundleResolverOptions
|
|
200
|
+
) {
|
|
201
|
+
for (const cid in bundlesData) {
|
|
202
|
+
try {
|
|
203
|
+
if (typeof bundlesData[cid] !== 'string') {
|
|
204
|
+
this.bundles[cid] = new OverlayBundle(cid, bundlesData[cid] as IOverlayBundleData)
|
|
205
|
+
} else {
|
|
206
|
+
this.bundles[cid] = bundlesData[cid] as string
|
|
207
|
+
}
|
|
208
|
+
} catch (error) {
|
|
209
|
+
// might get an error trying to parse javascript's default value
|
|
210
|
+
this.log?.error(`Error parsing bundle for ${cid}`, error)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
this.options = {
|
|
215
|
+
brandingOverlayType: options?.brandingOverlayType ?? BrandingOverlayType.Branding10,
|
|
216
|
+
language: options?.language ?? defaultBundleLanguage,
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Sets the log value.
|
|
222
|
+
* @param value - The new value for the log.
|
|
223
|
+
*/
|
|
224
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
225
|
+
public set log(value: any) {
|
|
226
|
+
this._log = value
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Get the log value.
|
|
231
|
+
*/
|
|
232
|
+
public get log() {
|
|
233
|
+
return this._log
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public getBrandingOverlayType(): BrandingOverlayType {
|
|
237
|
+
return this.options.brandingOverlayType ?? BrandingOverlayType.Branding10
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
private getDefaultBundle(params: OCABundleResolveDefaultParams) {
|
|
241
|
+
if (!params.language) {
|
|
242
|
+
params.language = defaultBundleLanguage
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const metaOverlay: IMetaOverlayData = {
|
|
246
|
+
capture_base: '',
|
|
247
|
+
type: OverlayType.Meta10,
|
|
248
|
+
name: startCase(
|
|
249
|
+
params.meta?.credName ??
|
|
250
|
+
parseCredDefFromId(params.identifiers?.credentialDefinitionId, params.identifiers?.schemaId)
|
|
251
|
+
),
|
|
252
|
+
issuer: params.meta?.alias || params.meta?.credConnectionId || 'Unknown Contact',
|
|
253
|
+
language: params.language ?? this.options?.language,
|
|
254
|
+
description: '',
|
|
255
|
+
credential_help_text: '',
|
|
256
|
+
credential_support_url: '',
|
|
257
|
+
issuer_description: '',
|
|
258
|
+
issuer_url: '',
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
let colorHash = 'default'
|
|
262
|
+
if (metaOverlay?.name) {
|
|
263
|
+
colorHash = metaOverlay.name
|
|
264
|
+
} else if (metaOverlay?.issuer) {
|
|
265
|
+
colorHash = metaOverlay.issuer
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const brandingOverlay01: ILegacyBrandingOverlayData = {
|
|
269
|
+
capture_base: '',
|
|
270
|
+
type: OverlayType.Branding01,
|
|
271
|
+
background_color: generateColor(colorHash),
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const brandingOverlay10: IBrandingOverlayData = {
|
|
275
|
+
capture_base: '',
|
|
276
|
+
type: OverlayType.Branding10,
|
|
277
|
+
primary_background_color: generateColor(colorHash),
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const brandingOverlay11: IBrandingOverlayData = {
|
|
281
|
+
capture_base: '',
|
|
282
|
+
type: OverlayType.Branding11,
|
|
283
|
+
primary_background_color: '#FFFFFF',
|
|
284
|
+
secondary_background_color: generateColor(colorHash),
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
let brandingOverlay =
|
|
288
|
+
this.getBrandingOverlayType() === BrandingOverlayType.Branding01 ? brandingOverlay01 : brandingOverlay10
|
|
289
|
+
|
|
290
|
+
if (this.getBrandingOverlayType() === BrandingOverlayType.Branding11) {
|
|
291
|
+
brandingOverlay = brandingOverlay11
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const bundle: OverlayBundle = new OverlayBundle(params.identifiers?.credentialDefinitionId as string, {
|
|
295
|
+
capture_base: {
|
|
296
|
+
attributes: {},
|
|
297
|
+
classification: '',
|
|
298
|
+
type: OverlayType.CaptureBase10,
|
|
299
|
+
flagged_attributes: [],
|
|
300
|
+
},
|
|
301
|
+
overlays: [metaOverlay, brandingOverlay],
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
return Promise.resolve(
|
|
305
|
+
new OCABundle(bundle, { ...this.options, language: params.language ?? this.options.language })
|
|
306
|
+
)
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
public resolveDefaultBundle(params: OCABundleResolveDefaultParams): Promise<OCABundle | undefined> {
|
|
310
|
+
return this.getDefaultBundle(params)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
public resolve(params: OCABundleResolveParams): Promise<OCABundle | undefined> {
|
|
314
|
+
const language = params.language || defaultBundleLanguage
|
|
315
|
+
for (const item of [
|
|
316
|
+
params.identifiers?.credentialDefinitionId,
|
|
317
|
+
params.identifiers?.schemaId,
|
|
318
|
+
params.identifiers?.templateId,
|
|
319
|
+
]) {
|
|
320
|
+
if (item && this.bundles[item] !== undefined) {
|
|
321
|
+
let bundle = this.bundles[item]
|
|
322
|
+
// if it is a string, it is a reference/alias to another one bundle
|
|
323
|
+
if (typeof bundle === 'string') {
|
|
324
|
+
bundle = this.bundles[bundle]
|
|
325
|
+
}
|
|
326
|
+
return Promise.resolve(
|
|
327
|
+
new OCABundle(bundle as OverlayBundle, { ...this.options, language: language ?? this.options.language })
|
|
328
|
+
)
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return Promise.resolve(undefined)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
public async presentationFields(params: OCABundleResolvePresentationFieldsParams): Promise<Field[]> {
|
|
335
|
+
const bundle = await this.resolve(params)
|
|
336
|
+
let presentationFields = [...params.attributes]
|
|
337
|
+
if (bundle?.captureBase?.attributes) {
|
|
338
|
+
// if the oca branding has the attributes set, only display those attributes
|
|
339
|
+
const bundleFields = Object.keys(bundle.captureBase.attributes)
|
|
340
|
+
presentationFields = presentationFields.filter((item) => item.name && bundleFields.includes(item.name))
|
|
341
|
+
for (let i = 0; i < presentationFields.length; i++) {
|
|
342
|
+
const presentationField = presentationFields[i]
|
|
343
|
+
const key = presentationField.name || ''
|
|
344
|
+
if (bundle.captureBase.attributes[key]) {
|
|
345
|
+
presentationField.label = bundle?.labelOverlay?.attributeLabels[key]
|
|
346
|
+
presentationField.format = bundle?.formatOverlay?.attributeFormats[key]
|
|
347
|
+
presentationField.type = bundle?.captureBase?.attributes?.[key]
|
|
348
|
+
presentationField.encoding = bundle?.characterEncodingOverlay?.attributeCharacterEncoding?.[key]
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return presentationFields
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
public async resolveAllBundles(
|
|
356
|
+
params: OCABundleResolveAllParams
|
|
357
|
+
): Promise<CredentialOverlay<BaseOverlay | BrandingOverlay | LegacyBrandingOverlay>> {
|
|
358
|
+
const [bundle, defaultBundle] = await Promise.all([this.resolve(params), this.resolveDefaultBundle(params)])
|
|
359
|
+
|
|
360
|
+
const fields = params.attributes
|
|
361
|
+
? await this.presentationFields({
|
|
362
|
+
...params,
|
|
363
|
+
attributes: params.attributes,
|
|
364
|
+
})
|
|
365
|
+
: []
|
|
366
|
+
|
|
367
|
+
const overlayBundle = bundle ?? defaultBundle
|
|
368
|
+
const metaOverlay = overlayBundle?.metaOverlay
|
|
369
|
+
const brandingOverlay = overlayBundle?.brandingOverlay
|
|
370
|
+
|
|
371
|
+
if (brandingOverlay && 'logo' in brandingOverlay && params.meta?.logo) {
|
|
372
|
+
brandingOverlay.logo = params.meta.logo
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return { bundle: overlayBundle, presentationFields: fields, metaOverlay, brandingOverlay }
|
|
376
|
+
}
|
|
377
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { AnonCredsNonRevokedInterval, AnonCredsProofRequestRestriction } from '@credo-ts/anoncreds'
|
|
2
|
+
|
|
3
|
+
export interface FieldParams {
|
|
4
|
+
name: string
|
|
5
|
+
format?: string
|
|
6
|
+
type?: string
|
|
7
|
+
encoding?: string
|
|
8
|
+
mimeType?: string
|
|
9
|
+
revoked?: boolean
|
|
10
|
+
credentialId?: string
|
|
11
|
+
label?: string
|
|
12
|
+
restrictions?: AnonCredsProofRequestRestriction[]
|
|
13
|
+
nonRevoked?: AnonCredsNonRevokedInterval
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface AttributeParams extends FieldParams {
|
|
17
|
+
value: string | number | null
|
|
18
|
+
revealed?: boolean
|
|
19
|
+
hasError?: boolean
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface PredicateParams extends FieldParams {
|
|
23
|
+
pValue: string | number | null
|
|
24
|
+
pType: string
|
|
25
|
+
parameterizable?: boolean
|
|
26
|
+
satisfied?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class Field {
|
|
30
|
+
public name: string
|
|
31
|
+
public format?: string
|
|
32
|
+
public type?: string
|
|
33
|
+
public encoding?: string
|
|
34
|
+
public mimeType?: string
|
|
35
|
+
public revoked?: boolean
|
|
36
|
+
public credentialId?: string
|
|
37
|
+
public label?: string
|
|
38
|
+
public restrictions?: AnonCredsProofRequestRestriction[]
|
|
39
|
+
public nonRevoked?: AnonCredsNonRevokedInterval
|
|
40
|
+
|
|
41
|
+
protected constructor(params: FieldParams) {
|
|
42
|
+
this.name = params.name
|
|
43
|
+
this.format = params.format
|
|
44
|
+
this.type = params.type
|
|
45
|
+
this.encoding = params.encoding
|
|
46
|
+
this.mimeType = params.mimeType
|
|
47
|
+
this.revoked = params.revoked
|
|
48
|
+
this.credentialId = params.credentialId
|
|
49
|
+
this.label = params.label
|
|
50
|
+
this.restrictions = params.restrictions
|
|
51
|
+
this.nonRevoked = params.nonRevoked
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export class Attribute extends Field {
|
|
56
|
+
public value: string | number | null
|
|
57
|
+
public revealed?: boolean
|
|
58
|
+
public hasError?: boolean
|
|
59
|
+
|
|
60
|
+
public constructor(params: AttributeParams) {
|
|
61
|
+
super(params)
|
|
62
|
+
this.value = params.value
|
|
63
|
+
this.revealed = params.revealed
|
|
64
|
+
this.hasError = params.hasError
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export class Predicate extends Field {
|
|
69
|
+
public pValue: string | number | null
|
|
70
|
+
public pType: string
|
|
71
|
+
public parameterizable?: boolean
|
|
72
|
+
public satisfied?: boolean
|
|
73
|
+
|
|
74
|
+
public constructor(params: PredicateParams) {
|
|
75
|
+
super(params)
|
|
76
|
+
this.pValue = params.pValue
|
|
77
|
+
this.pType = params.pType
|
|
78
|
+
this.parameterizable = params.parameterizable
|
|
79
|
+
this.satisfied = params.satisfied
|
|
80
|
+
}
|
|
81
|
+
}
|