@sphereon/ui-components.credential-branding 0.2.1-unstable.13 → 0.2.1-unstable.5

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 CHANGED
@@ -6,6 +6,12 @@
6
6
  <br>
7
7
  </h1>
8
8
 
9
+ ---
10
+
11
+ **Warning: This package still is in every early development. Breaking changes without notice will happen at this point!**
12
+
13
+ ---
14
+
9
15
  A UI Core package for shared logic / styling and localization between components related to Credential Branding
10
16
 
11
17
  ### Build
package/dist/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- export * from './mapping';
2
- export * from './services';
3
- export * from './types';
4
- export * from './utils';
1
+ import { UniqueVerifiableCredential, VerifiableCredential } from '@veramo/core';
2
+ import { IBasicCredentialLocaleBranding, IBasicIssuerLocaleBranding, Party } from '@sphereon/ssi-sdk.data-store';
3
+ import { ICredential } from '@sphereon/ssi-types';
4
+ import { CredentialSummary, ISelectAppLocaleBrandingArgs } from './types';
5
+ export declare const toNonPersistedCredentialSummary: (verifiableCredential: ICredential | VerifiableCredential, branding?: Array<IBasicCredentialLocaleBranding>, issuer?: Party, subject?: Party) => Promise<CredentialSummary>;
6
+ export declare const toCredentialSummary: ({ hash, verifiableCredential }: UniqueVerifiableCredential, branding?: Array<IBasicCredentialLocaleBranding>, issuer?: Party, subject?: Party) => Promise<CredentialSummary>;
7
+ export declare const selectAppLocaleBranding: (args: ISelectAppLocaleBrandingArgs) => Promise<IBasicCredentialLocaleBranding | IBasicIssuerLocaleBranding | undefined>;
package/dist/index.js CHANGED
@@ -1,20 +1,257 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
7
44
  }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
45
+ return to.concat(ar || Array.prototype.slice.call(from));
15
46
  };
16
47
  exports.__esModule = true;
17
- __exportStar(require("./mapping"), exports);
18
- __exportStar(require("./services"), exports);
19
- __exportStar(require("./types"), exports);
20
- __exportStar(require("./utils"), exports);
48
+ exports.selectAppLocaleBranding = exports.toCredentialSummary = exports.toNonPersistedCredentialSummary = void 0;
49
+ var uuid_1 = require("uuid");
50
+ var utils_1 = require("@veramo/utils");
51
+ var ui_components_core_1 = require("@sphereon/ui-components.core");
52
+ var ssi_sdk_core_1 = require("@sphereon/ssi-sdk.core");
53
+ var ImageUtils_1 = require("./utils/ImageUtils");
54
+ var MappingUtils_1 = require("./utils/MappingUtils");
55
+ var ReactNativeImagePreloader_1 = require("./services/ReactNativeImagePreloader");
56
+ var WebImagePreloader_1 = require("./services/WebImagePreloader");
57
+ function findCorrelationIdName(correlationId, contacts) {
58
+ var contact = contacts.find(function (contact) {
59
+ return contact.identities.some(function (identity) { return identity.identifier.correlationId === correlationId; });
60
+ });
61
+ if (contact) {
62
+ return contact.contact.displayName;
63
+ }
64
+ return correlationId;
65
+ }
66
+ var toCredentialDetailsRow = function (object, subject, issuer) { return __awaiter(void 0, void 0, void 0, function () {
67
+ var rows, _i, _a, _b, key, value, image, _c, _d, _e, _f, _g, _h, label, contacts, _j, _k, _l, _m;
68
+ var _o, _p;
69
+ return __generator(this, function (_q) {
70
+ switch (_q.label) {
71
+ case 0:
72
+ rows = [];
73
+ _i = 0, _a = Object.entries(object);
74
+ _q.label = 1;
75
+ case 1:
76
+ if (!(_i < _a.length)) return [3, 17];
77
+ _b = _a[_i], key = _b[0], value = _b[1];
78
+ if (!key.toLowerCase().includes('image')) return [3, 7];
79
+ image = typeof value === 'string' ? value : value.id;
80
+ _d = (_c = rows).push;
81
+ _o = {
82
+ id: (0, uuid_1.v4)(),
83
+ label: 'image',
84
+ value: image
85
+ };
86
+ return [4, (0, ImageUtils_1.isImageAddress)(image)];
87
+ case 2:
88
+ if (!(_q.sent())) return [3, 5];
89
+ _f = ssi_sdk_core_1.getImageDimensions;
90
+ return [4, (0, ssi_sdk_core_1.downloadImage)(image)];
91
+ case 3: return [4, _f.apply(void 0, [(_q.sent()).base64Content])];
92
+ case 4:
93
+ _e = _q.sent();
94
+ return [3, 6];
95
+ case 5:
96
+ _e = undefined;
97
+ _q.label = 6;
98
+ case 6:
99
+ _d.apply(_c, [(_o.imageSize = _e,
100
+ _o)]);
101
+ return [3, 16];
102
+ case 7:
103
+ if (key === 'type') {
104
+ rows.push({
105
+ id: (0, uuid_1.v4)(),
106
+ label: key,
107
+ value: value
108
+ });
109
+ return [3, 16];
110
+ }
111
+ _q.label = 8;
112
+ case 8:
113
+ if (!(typeof value !== 'string')) return [3, 10];
114
+ _h = (_g = rows).concat;
115
+ return [4, toCredentialDetailsRow(value, subject, issuer)];
116
+ case 9:
117
+ rows = _h.apply(_g, [_q.sent()]);
118
+ return [3, 16];
119
+ case 10:
120
+ console.log("==>".concat(key, ":").concat(value));
121
+ if (key === '0' || value === undefined) {
122
+ return [3, 16];
123
+ }
124
+ label = key;
125
+ if (key === 'id' && value.startsWith('did:')) {
126
+ label = 'subject';
127
+ }
128
+ if (value.startsWith('did:')) {
129
+ console.log("did: ".concat(value));
130
+ contacts = __spreadArray(__spreadArray([], (issuer ? [issuer] : []), true), (subject ? [subject] : []), true);
131
+ value = findCorrelationIdName(value, contacts);
132
+ }
133
+ _k = (_j = rows).push;
134
+ _p = {
135
+ id: (0, uuid_1.v4)(),
136
+ label: label,
137
+ value: value
138
+ };
139
+ return [4, (0, ImageUtils_1.isImageAddress)(value)];
140
+ case 11:
141
+ if (!(_q.sent())) return [3, 14];
142
+ _m = ssi_sdk_core_1.getImageDimensions;
143
+ return [4, (0, ssi_sdk_core_1.downloadImage)(value)];
144
+ case 12: return [4, _m.apply(void 0, [(_q.sent()).base64Content])];
145
+ case 13:
146
+ _l = _q.sent();
147
+ return [3, 15];
148
+ case 14:
149
+ _l = undefined;
150
+ _q.label = 15;
151
+ case 15:
152
+ _k.apply(_j, [(_p.imageSize = _l,
153
+ _p)]);
154
+ _q.label = 16;
155
+ case 16:
156
+ _i++;
157
+ return [3, 1];
158
+ case 17: return [2, rows];
159
+ }
160
+ });
161
+ }); };
162
+ var toNonPersistedCredentialSummary = function (verifiableCredential, branding, issuer, subject) {
163
+ var _a;
164
+ return (0, exports.toCredentialSummary)({
165
+ verifiableCredential: verifiableCredential,
166
+ hash: (_a = verifiableCredential.id) !== null && _a !== void 0 ? _a : (0, utils_1.computeEntryHash)(verifiableCredential)
167
+ }, branding, issuer, subject);
168
+ };
169
+ exports.toNonPersistedCredentialSummary = toNonPersistedCredentialSummary;
170
+ var toCredentialSummary = function (_a, branding, issuer, subject) {
171
+ var hash = _a.hash, verifiableCredential = _a.verifiableCredential;
172
+ return __awaiter(void 0, void 0, void 0, function () {
173
+ var expirationDate, issueDate, credentialStatus, title, properties, localeBranding, logo, url, name, issuerAlias;
174
+ var _b, _c, _d, _e;
175
+ return __generator(this, function (_f) {
176
+ switch (_f.label) {
177
+ case 0:
178
+ expirationDate = verifiableCredential.expirationDate
179
+ ? new Date(verifiableCredential.expirationDate).valueOf() / ui_components_core_1.EPOCH_MILLISECONDS
180
+ : 0;
181
+ issueDate = new Date(verifiableCredential.issuanceDate).valueOf() / ui_components_core_1.EPOCH_MILLISECONDS;
182
+ credentialStatus = (0, MappingUtils_1.getCredentialStatus)(verifiableCredential);
183
+ title = verifiableCredential.name
184
+ ? verifiableCredential.name
185
+ : !verifiableCredential.type
186
+ ? 'unknown'
187
+ : typeof verifiableCredential.type === 'string'
188
+ ? verifiableCredential.type
189
+ : verifiableCredential.type.filter(function (value) { return value !== 'VerifiableCredential'; })[0];
190
+ return [4, toCredentialDetailsRow(verifiableCredential.credentialSubject, subject, issuer)];
191
+ case 1:
192
+ properties = _f.sent();
193
+ return [4, (0, exports.selectAppLocaleBranding)({ localeBranding: branding })];
194
+ case 2:
195
+ localeBranding = _f.sent();
196
+ logo = (0, ImageUtils_1.getIssuerLogo)(verifiableCredential, localeBranding);
197
+ url = typeof verifiableCredential.issuer !== 'string' ? verifiableCredential.issuer.url : undefined;
198
+ name = typeof verifiableCredential.issuer === 'string'
199
+ ? verifiableCredential.issuer
200
+ : (_c = (_b = verifiableCredential.issuer) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : (_d = verifiableCredential.issuer) === null || _d === void 0 ? void 0 : _d.id;
201
+ issuerAlias = undefined;
202
+ if (typeof (verifiableCredential === null || verifiableCredential === void 0 ? void 0 : verifiableCredential.issuer) === 'object' && ((_e = verifiableCredential.issuer) === null || _e === void 0 ? void 0 : _e.name)) {
203
+ issuerAlias = verifiableCredential.issuer.name;
204
+ }
205
+ if (!issuerAlias && issuer) {
206
+ issuerAlias = issuer.contact.displayName;
207
+ }
208
+ if (!issuerAlias) {
209
+ throw Error("Could not deduce issuer alias");
210
+ }
211
+ return [2, {
212
+ hash: hash,
213
+ id: verifiableCredential.id,
214
+ title: (localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.alias) || title,
215
+ credentialStatus: credentialStatus,
216
+ issueDate: issueDate,
217
+ expirationDate: expirationDate,
218
+ properties: properties,
219
+ branding: localeBranding,
220
+ issuer: {
221
+ name: name,
222
+ alias: issuerAlias ? (issuerAlias.length > 50 ? "".concat(issuerAlias.substring(0, 50), "...") : issuerAlias) : '',
223
+ image: logo,
224
+ url: url
225
+ }
226
+ }];
227
+ }
228
+ });
229
+ });
230
+ };
231
+ exports.toCredentialSummary = toCredentialSummary;
232
+ var selectAppLocaleBranding = function (args) { return __awaiter(void 0, void 0, void 0, function () {
233
+ var appLocale, localeBranding, logo, imagePreloader, backgroundImage;
234
+ var _a, _b, _c, _d, _e, _f, _g;
235
+ return __generator(this, function (_h) {
236
+ appLocale = ui_components_core_1.Localization.getLocale();
237
+ localeBranding = (_a = args.localeBranding) === null || _a === void 0 ? void 0 : _a.find(function (branding) { var _a; return ((_a = branding.locale) === null || _a === void 0 ? void 0 : _a.startsWith(appLocale)) || branding.locale === undefined; });
238
+ logo = ((_b = localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.logo) === null || _b === void 0 ? void 0 : _b.dataUri) || ((_c = localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.logo) === null || _c === void 0 ? void 0 : _c.uri);
239
+ if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
240
+ imagePreloader = new ReactNativeImagePreloader_1.ReactNativeImagePreloader();
241
+ }
242
+ else {
243
+ imagePreloader = new WebImagePreloader_1.WebImagePreloader();
244
+ }
245
+ if (logo) {
246
+ imagePreloader.preload([{ uri: logo }])["catch"](function () {
247
+ });
248
+ }
249
+ backgroundImage = ((_e = (_d = localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.background) === null || _d === void 0 ? void 0 : _d.image) === null || _e === void 0 ? void 0 : _e.dataUri) || ((_g = (_f = localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.background) === null || _f === void 0 ? void 0 : _f.image) === null || _g === void 0 ? void 0 : _g.uri);
250
+ if (backgroundImage) {
251
+ imagePreloader.preload([{ uri: backgroundImage }])["catch"](function () {
252
+ });
253
+ }
254
+ return [2, localeBranding];
255
+ });
256
+ }); };
257
+ exports.selectAppLocaleBranding = selectAppLocaleBranding;
@@ -37,12 +37,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  exports.__esModule = true;
39
39
  exports.ReactNativeImagePreloader = void 0;
40
+ var FastImage = require('react-native-fast-image');
40
41
  var ReactNativeImagePreloader = (function () {
41
42
  function ReactNativeImagePreloader() {
42
43
  }
43
44
  ReactNativeImagePreloader.prototype.preload = function (sources) {
44
45
  return __awaiter(this, void 0, void 0, function () {
45
46
  return __generator(this, function (_a) {
47
+ FastImage.preload(sources);
46
48
  return [2];
47
49
  });
48
50
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sphereon/ui-components.credential-branding",
3
3
  "private": false,
4
- "version": "0.2.1-unstable.13+c3ab5eb",
4
+ "version": "0.2.1-unstable.5+5c9a628",
5
5
  "description": "SSI UI components credential Branding",
6
6
  "repository": "git@github.com:Sphereon-Opensource/UI-Components.git",
7
7
  "author": "Sphereon <dev@sphereon.com>",
@@ -28,19 +28,23 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@sphereon/ssi-sdk.core": "0.23.5-unstable.74+9c3c2083",
32
- "@sphereon/ssi-sdk.data-store": "0.23.5-unstable.74+9c3c2083",
33
- "@sphereon/ssi-types": "0.23.5-unstable.74+9c3c2083",
34
- "@sphereon/ui-components.core": "0.2.1-unstable.13+c3ab5eb",
31
+ "@sphereon/ssi-sdk.core": "^0.23.4",
32
+ "@sphereon/ssi-sdk.data-store": "0.23.4",
33
+ "@sphereon/ssi-types": "^0.23.4",
34
+ "@sphereon/ui-components.core": "0.2.1-unstable.5+5c9a628",
35
35
  "@veramo/core": "4.2.0",
36
36
  "@veramo/utils": "4.2.0",
37
37
  "i18n-js": "^3.8.0",
38
+ "lodash.memoize": "^4.1.2",
39
+ "styled-components": "^5.3.3",
38
40
  "uuid": "^9.0.1"
39
41
  },
40
42
  "devDependencies": {
41
43
  "@types/i18n-js": "^3.8.4",
44
+ "@types/lodash.memoize": "^4.1.7",
42
45
  "@types/node": "^20.4.0",
43
46
  "@types/react": "~18.2.67",
47
+ "@types/styled-components": "^5.1.15",
44
48
  "@types/uuid": "^9.0.8",
45
49
  "react": "18.2.0",
46
50
  "typescript": "4.9.5"
@@ -48,5 +52,5 @@
48
52
  "peerDependencies": {
49
53
  "react": ">= 18"
50
54
  },
51
- "gitHead": "c3ab5eba4c4b4351a9bf9e8eef24e4e4179aa4a4"
55
+ "gitHead": "5c9a628778acb42f1d54fd23fafc187ea7d08eca"
52
56
  }
@@ -1,7 +0,0 @@
1
- import { UniqueVerifiableCredential, VerifiableCredential } from '@veramo/core';
2
- import { IBasicCredentialLocaleBranding, IBasicIssuerLocaleBranding, Party } from '@sphereon/ssi-sdk.data-store';
3
- import { ICredential } from '@sphereon/ssi-types';
4
- import { CredentialSummary, ISelectAppLocaleBrandingArgs } from '../types';
5
- export declare const toNonPersistedCredentialSummary: (verifiableCredential: ICredential | VerifiableCredential, branding?: Array<IBasicCredentialLocaleBranding>, issuer?: Party, subject?: Party) => Promise<CredentialSummary>;
6
- export declare const toCredentialSummary: ({ hash, verifiableCredential }: UniqueVerifiableCredential, branding?: Array<IBasicCredentialLocaleBranding>, issuer?: Party, subject?: Party) => Promise<CredentialSummary>;
7
- export declare const selectAppLocaleBranding: (args: ISelectAppLocaleBrandingArgs) => Promise<IBasicCredentialLocaleBranding | IBasicIssuerLocaleBranding | undefined>;
@@ -1,253 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
- if (ar || !(i in from)) {
41
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
- ar[i] = from[i];
43
- }
44
- }
45
- return to.concat(ar || Array.prototype.slice.call(from));
46
- };
47
- exports.__esModule = true;
48
- exports.selectAppLocaleBranding = exports.toCredentialSummary = exports.toNonPersistedCredentialSummary = void 0;
49
- var uuid_1 = require("uuid");
50
- var utils_1 = require("@veramo/utils");
51
- var ui_components_core_1 = require("@sphereon/ui-components.core");
52
- var ssi_sdk_core_1 = require("@sphereon/ssi-sdk.core");
53
- var services_1 = require("../services");
54
- var utils_2 = require("../utils");
55
- function findCorrelationIdName(correlationId, contacts) {
56
- var contact = contacts.find(function (contact) {
57
- return contact.identities.some(function (identity) { return identity.identifier.correlationId === correlationId; });
58
- });
59
- if (contact) {
60
- return contact.contact.displayName;
61
- }
62
- return correlationId;
63
- }
64
- var toCredentialDetailsRow = function (object, subject, issuer) { return __awaiter(void 0, void 0, void 0, function () {
65
- var rows, _i, _a, _b, key, value, image, _c, _d, _e, _f, _g, _h, label, contacts, _j, _k, _l, _m;
66
- var _o, _p;
67
- return __generator(this, function (_q) {
68
- switch (_q.label) {
69
- case 0:
70
- rows = [];
71
- _i = 0, _a = Object.entries(object);
72
- _q.label = 1;
73
- case 1:
74
- if (!(_i < _a.length)) return [3, 17];
75
- _b = _a[_i], key = _b[0], value = _b[1];
76
- if (!key.toLowerCase().includes('image')) return [3, 7];
77
- image = typeof value === 'string' ? value : value.id;
78
- _d = (_c = rows).push;
79
- _o = {
80
- id: (0, uuid_1.v4)(),
81
- label: 'image',
82
- value: image
83
- };
84
- return [4, (0, utils_2.isImageAddress)(image)];
85
- case 2:
86
- if (!(_q.sent())) return [3, 5];
87
- _f = ssi_sdk_core_1.getImageDimensions;
88
- return [4, (0, ssi_sdk_core_1.downloadImage)(image)];
89
- case 3: return [4, _f.apply(void 0, [(_q.sent()).base64Content])];
90
- case 4:
91
- _e = _q.sent();
92
- return [3, 6];
93
- case 5:
94
- _e = undefined;
95
- _q.label = 6;
96
- case 6:
97
- _d.apply(_c, [(_o.imageSize = _e,
98
- _o)]);
99
- return [3, 16];
100
- case 7:
101
- if (key === 'type') {
102
- rows.push({
103
- id: (0, uuid_1.v4)(),
104
- label: key,
105
- value: value
106
- });
107
- return [3, 16];
108
- }
109
- _q.label = 8;
110
- case 8:
111
- if (!(typeof value !== 'string')) return [3, 10];
112
- _h = (_g = rows).concat;
113
- return [4, toCredentialDetailsRow(value, subject, issuer)];
114
- case 9:
115
- rows = _h.apply(_g, [_q.sent()]);
116
- return [3, 16];
117
- case 10:
118
- if (key === '0' || value === undefined) {
119
- return [3, 16];
120
- }
121
- label = key;
122
- if (key === 'id' && value.startsWith('did:')) {
123
- label = 'subject';
124
- }
125
- if (value.startsWith('did:')) {
126
- contacts = __spreadArray(__spreadArray([], (issuer ? [issuer] : []), true), (subject ? [subject] : []), true);
127
- value = findCorrelationIdName(value, contacts);
128
- }
129
- _k = (_j = rows).push;
130
- _p = {
131
- id: (0, uuid_1.v4)(),
132
- label: label,
133
- value: value
134
- };
135
- return [4, (0, utils_2.isImageAddress)(value)];
136
- case 11:
137
- if (!(_q.sent())) return [3, 14];
138
- _m = ssi_sdk_core_1.getImageDimensions;
139
- return [4, (0, ssi_sdk_core_1.downloadImage)(value)];
140
- case 12: return [4, _m.apply(void 0, [(_q.sent()).base64Content])];
141
- case 13:
142
- _l = _q.sent();
143
- return [3, 15];
144
- case 14:
145
- _l = undefined;
146
- _q.label = 15;
147
- case 15:
148
- _k.apply(_j, [(_p.imageSize = _l,
149
- _p)]);
150
- _q.label = 16;
151
- case 16:
152
- _i++;
153
- return [3, 1];
154
- case 17: return [2, rows];
155
- }
156
- });
157
- }); };
158
- var toNonPersistedCredentialSummary = function (verifiableCredential, branding, issuer, subject) {
159
- var _a;
160
- return (0, exports.toCredentialSummary)({
161
- verifiableCredential: verifiableCredential,
162
- hash: (_a = verifiableCredential.id) !== null && _a !== void 0 ? _a : (0, utils_1.computeEntryHash)(verifiableCredential)
163
- }, branding, issuer, subject);
164
- };
165
- exports.toNonPersistedCredentialSummary = toNonPersistedCredentialSummary;
166
- var toCredentialSummary = function (_a, branding, issuer, subject) {
167
- var hash = _a.hash, verifiableCredential = _a.verifiableCredential;
168
- return __awaiter(void 0, void 0, void 0, function () {
169
- var expirationDate, issueDate, credentialStatus, title, properties, localeBranding, logo, url, name, issuerAlias;
170
- var _b, _c, _d, _e;
171
- return __generator(this, function (_f) {
172
- switch (_f.label) {
173
- case 0:
174
- expirationDate = verifiableCredential.expirationDate
175
- ? new Date(verifiableCredential.expirationDate).valueOf() / ui_components_core_1.EPOCH_MILLISECONDS
176
- : 0;
177
- issueDate = new Date(verifiableCredential.issuanceDate).valueOf() / ui_components_core_1.EPOCH_MILLISECONDS;
178
- credentialStatus = (0, utils_2.getCredentialStatus)(verifiableCredential);
179
- title = verifiableCredential.name
180
- ? verifiableCredential.name
181
- : !verifiableCredential.type
182
- ? 'unknown'
183
- : typeof verifiableCredential.type === 'string'
184
- ? verifiableCredential.type
185
- : verifiableCredential.type.filter(function (value) { return value !== 'VerifiableCredential'; })[0];
186
- return [4, toCredentialDetailsRow(verifiableCredential.credentialSubject, subject, issuer)];
187
- case 1:
188
- properties = _f.sent();
189
- return [4, (0, exports.selectAppLocaleBranding)({ localeBranding: branding })];
190
- case 2:
191
- localeBranding = _f.sent();
192
- logo = (0, utils_2.getIssuerLogo)(verifiableCredential, localeBranding);
193
- url = typeof verifiableCredential.issuer !== 'string' ? verifiableCredential.issuer.url : undefined;
194
- name = typeof verifiableCredential.issuer === 'string'
195
- ? verifiableCredential.issuer
196
- : (_c = (_b = verifiableCredential.issuer) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : (_d = verifiableCredential.issuer) === null || _d === void 0 ? void 0 : _d.id;
197
- issuerAlias = undefined;
198
- if (typeof (verifiableCredential === null || verifiableCredential === void 0 ? void 0 : verifiableCredential.issuer) === 'object' && ((_e = verifiableCredential.issuer) === null || _e === void 0 ? void 0 : _e.name)) {
199
- issuerAlias = verifiableCredential.issuer.name;
200
- }
201
- if (!issuerAlias && issuer) {
202
- issuerAlias = issuer.contact.displayName;
203
- }
204
- if (!issuerAlias) {
205
- throw Error("Could not deduce issuer alias");
206
- }
207
- return [2, {
208
- hash: hash,
209
- id: verifiableCredential.id,
210
- title: (localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.alias) || title,
211
- credentialStatus: credentialStatus,
212
- issueDate: issueDate,
213
- expirationDate: expirationDate,
214
- properties: properties,
215
- branding: localeBranding,
216
- issuer: {
217
- name: name,
218
- alias: issuerAlias ? (issuerAlias.length > 50 ? "".concat(issuerAlias.substring(0, 50), "...") : issuerAlias) : '',
219
- image: logo,
220
- url: url
221
- }
222
- }];
223
- }
224
- });
225
- });
226
- };
227
- exports.toCredentialSummary = toCredentialSummary;
228
- var selectAppLocaleBranding = function (args) { return __awaiter(void 0, void 0, void 0, function () {
229
- var appLocale, localeBranding, logo, imagePreloader, backgroundImage;
230
- var _a, _b, _c, _d, _e, _f, _g;
231
- return __generator(this, function (_h) {
232
- appLocale = ui_components_core_1.Localization.getLocale();
233
- localeBranding = (_a = args.localeBranding) === null || _a === void 0 ? void 0 : _a.find(function (branding) { var _a; return ((_a = branding.locale) === null || _a === void 0 ? void 0 : _a.startsWith(appLocale)) || branding.locale === undefined; });
234
- logo = ((_b = localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.logo) === null || _b === void 0 ? void 0 : _b.dataUri) || ((_c = localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.logo) === null || _c === void 0 ? void 0 : _c.uri);
235
- if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
236
- imagePreloader = new services_1.ReactNativeImagePreloader();
237
- }
238
- else {
239
- imagePreloader = new services_1.WebImagePreloader();
240
- }
241
- if (logo) {
242
- imagePreloader.preload([{ uri: logo }])["catch"](function () {
243
- });
244
- }
245
- backgroundImage = ((_e = (_d = localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.background) === null || _d === void 0 ? void 0 : _d.image) === null || _e === void 0 ? void 0 : _e.dataUri) || ((_g = (_f = localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.background) === null || _f === void 0 ? void 0 : _f.image) === null || _g === void 0 ? void 0 : _g.uri);
246
- if (backgroundImage) {
247
- imagePreloader.preload([{ uri: backgroundImage }])["catch"](function () {
248
- });
249
- }
250
- return [2, localeBranding];
251
- });
252
- }); };
253
- exports.selectAppLocaleBranding = selectAppLocaleBranding;
@@ -1 +0,0 @@
1
- export * from './CredentialMapper';
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- exports.__esModule = true;
17
- __exportStar(require("./CredentialMapper"), exports);
@@ -1,3 +0,0 @@
1
- export * from './WebImagePreloader';
2
- export * from './IPreloadImage';
3
- export * from './ReactNativeImagePreloader';