@sphereon/ui-components.credential-branding 0.2.1-unstable.9 → 0.2.1-unstable.92

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,255 +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
- console.log("==>".concat(key, ":").concat(value));
119
- if (key === '0' || value === undefined) {
120
- return [3, 16];
121
- }
122
- label = key;
123
- if (key === 'id' && value.startsWith('did:')) {
124
- label = 'subject';
125
- }
126
- if (value.startsWith('did:')) {
127
- console.log("did: ".concat(value));
128
- contacts = __spreadArray(__spreadArray([], (issuer ? [issuer] : []), true), (subject ? [subject] : []), true);
129
- value = findCorrelationIdName(value, contacts);
130
- }
131
- _k = (_j = rows).push;
132
- _p = {
133
- id: (0, uuid_1.v4)(),
134
- label: label,
135
- value: value
136
- };
137
- return [4, (0, utils_2.isImageAddress)(value)];
138
- case 11:
139
- if (!(_q.sent())) return [3, 14];
140
- _m = ssi_sdk_core_1.getImageDimensions;
141
- return [4, (0, ssi_sdk_core_1.downloadImage)(value)];
142
- case 12: return [4, _m.apply(void 0, [(_q.sent()).base64Content])];
143
- case 13:
144
- _l = _q.sent();
145
- return [3, 15];
146
- case 14:
147
- _l = undefined;
148
- _q.label = 15;
149
- case 15:
150
- _k.apply(_j, [(_p.imageSize = _l,
151
- _p)]);
152
- _q.label = 16;
153
- case 16:
154
- _i++;
155
- return [3, 1];
156
- case 17: return [2, rows];
157
- }
158
- });
159
- }); };
160
- var toNonPersistedCredentialSummary = function (verifiableCredential, branding, issuer, subject) {
161
- var _a;
162
- return (0, exports.toCredentialSummary)({
163
- verifiableCredential: verifiableCredential,
164
- hash: (_a = verifiableCredential.id) !== null && _a !== void 0 ? _a : (0, utils_1.computeEntryHash)(verifiableCredential)
165
- }, branding, issuer, subject);
166
- };
167
- exports.toNonPersistedCredentialSummary = toNonPersistedCredentialSummary;
168
- var toCredentialSummary = function (_a, branding, issuer, subject) {
169
- var hash = _a.hash, verifiableCredential = _a.verifiableCredential;
170
- return __awaiter(void 0, void 0, void 0, function () {
171
- var expirationDate, issueDate, credentialStatus, title, properties, localeBranding, logo, url, name, issuerAlias;
172
- var _b, _c, _d, _e;
173
- return __generator(this, function (_f) {
174
- switch (_f.label) {
175
- case 0:
176
- expirationDate = verifiableCredential.expirationDate
177
- ? new Date(verifiableCredential.expirationDate).valueOf() / ui_components_core_1.EPOCH_MILLISECONDS
178
- : 0;
179
- issueDate = new Date(verifiableCredential.issuanceDate).valueOf() / ui_components_core_1.EPOCH_MILLISECONDS;
180
- credentialStatus = (0, utils_2.getCredentialStatus)(verifiableCredential);
181
- title = verifiableCredential.name
182
- ? verifiableCredential.name
183
- : !verifiableCredential.type
184
- ? 'unknown'
185
- : typeof verifiableCredential.type === 'string'
186
- ? verifiableCredential.type
187
- : verifiableCredential.type.filter(function (value) { return value !== 'VerifiableCredential'; })[0];
188
- return [4, toCredentialDetailsRow(verifiableCredential.credentialSubject, subject, issuer)];
189
- case 1:
190
- properties = _f.sent();
191
- return [4, (0, exports.selectAppLocaleBranding)({ localeBranding: branding })];
192
- case 2:
193
- localeBranding = _f.sent();
194
- logo = (0, utils_2.getIssuerLogo)(verifiableCredential, localeBranding);
195
- url = typeof verifiableCredential.issuer !== 'string' ? verifiableCredential.issuer.url : undefined;
196
- name = typeof verifiableCredential.issuer === 'string'
197
- ? verifiableCredential.issuer
198
- : (_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;
199
- issuerAlias = undefined;
200
- if (typeof (verifiableCredential === null || verifiableCredential === void 0 ? void 0 : verifiableCredential.issuer) === 'object' && ((_e = verifiableCredential.issuer) === null || _e === void 0 ? void 0 : _e.name)) {
201
- issuerAlias = verifiableCredential.issuer.name;
202
- }
203
- if (!issuerAlias && issuer) {
204
- issuerAlias = issuer.contact.displayName;
205
- }
206
- if (!issuerAlias) {
207
- throw Error("Could not deduce issuer alias");
208
- }
209
- return [2, {
210
- hash: hash,
211
- id: verifiableCredential.id,
212
- title: (localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.alias) || title,
213
- credentialStatus: credentialStatus,
214
- issueDate: issueDate,
215
- expirationDate: expirationDate,
216
- properties: properties,
217
- branding: localeBranding,
218
- issuer: {
219
- name: name,
220
- alias: issuerAlias ? (issuerAlias.length > 50 ? "".concat(issuerAlias.substring(0, 50), "...") : issuerAlias) : '',
221
- image: logo,
222
- url: url
223
- }
224
- }];
225
- }
226
- });
227
- });
228
- };
229
- exports.toCredentialSummary = toCredentialSummary;
230
- var selectAppLocaleBranding = function (args) { return __awaiter(void 0, void 0, void 0, function () {
231
- var appLocale, localeBranding, logo, imagePreloader, backgroundImage;
232
- var _a, _b, _c, _d, _e, _f, _g;
233
- return __generator(this, function (_h) {
234
- appLocale = ui_components_core_1.Localization.getLocale();
235
- 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; });
236
- 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);
237
- if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
238
- imagePreloader = new services_1.ReactNativeImagePreloader();
239
- }
240
- else {
241
- imagePreloader = new services_1.WebImagePreloader();
242
- }
243
- if (logo) {
244
- imagePreloader.preload([{ uri: logo }])["catch"](function () {
245
- });
246
- }
247
- 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);
248
- if (backgroundImage) {
249
- imagePreloader.preload([{ uri: backgroundImage }])["catch"](function () {
250
- });
251
- }
252
- return [2, localeBranding];
253
- });
254
- }); };
255
- exports.selectAppLocaleBranding = selectAppLocaleBranding;
@@ -1 +0,0 @@
1
- export * from './CredentialMapper';