@sphereon/ui-components.credential-branding 0.2.1-unstable.6 → 0.2.1-unstable.8
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/dist/index.d.ts +4 -7
- package/dist/index.js +16 -252
- package/dist/mapping/CredentialMapper.d.ts +7 -0
- package/dist/mapping/CredentialMapper.js +256 -0
- package/dist/mapping/index.d.ts +1 -0
- package/dist/mapping/index.js +17 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.js +19 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +18 -0
- package/package.json +6 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
export * from './mapping';
|
|
2
|
+
export * from './services';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export * from './utils';
|
package/dist/index.js
CHANGED
|
@@ -1,256 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
}
|
|
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]; } };
|
|
44
7
|
}
|
|
45
|
-
|
|
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);
|
|
46
15
|
};
|
|
47
16
|
exports.__esModule = true;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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 WebImagePreloader_1 = require("./services/WebImagePreloader");
|
|
56
|
-
function findCorrelationIdName(correlationId, contacts) {
|
|
57
|
-
var contact = contacts.find(function (contact) {
|
|
58
|
-
return contact.identities.some(function (identity) { return identity.identifier.correlationId === correlationId; });
|
|
59
|
-
});
|
|
60
|
-
if (contact) {
|
|
61
|
-
return contact.contact.displayName;
|
|
62
|
-
}
|
|
63
|
-
return correlationId;
|
|
64
|
-
}
|
|
65
|
-
var toCredentialDetailsRow = function (object, subject, issuer) { return __awaiter(void 0, void 0, void 0, function () {
|
|
66
|
-
var rows, _i, _a, _b, key, value, image, _c, _d, _e, _f, _g, _h, label, contacts, _j, _k, _l, _m;
|
|
67
|
-
var _o, _p;
|
|
68
|
-
return __generator(this, function (_q) {
|
|
69
|
-
switch (_q.label) {
|
|
70
|
-
case 0:
|
|
71
|
-
rows = [];
|
|
72
|
-
_i = 0, _a = Object.entries(object);
|
|
73
|
-
_q.label = 1;
|
|
74
|
-
case 1:
|
|
75
|
-
if (!(_i < _a.length)) return [3, 17];
|
|
76
|
-
_b = _a[_i], key = _b[0], value = _b[1];
|
|
77
|
-
if (!key.toLowerCase().includes('image')) return [3, 7];
|
|
78
|
-
image = typeof value === 'string' ? value : value.id;
|
|
79
|
-
_d = (_c = rows).push;
|
|
80
|
-
_o = {
|
|
81
|
-
id: (0, uuid_1.v4)(),
|
|
82
|
-
label: 'image',
|
|
83
|
-
value: image
|
|
84
|
-
};
|
|
85
|
-
return [4, (0, ImageUtils_1.isImageAddress)(image)];
|
|
86
|
-
case 2:
|
|
87
|
-
if (!(_q.sent())) return [3, 5];
|
|
88
|
-
_f = ssi_sdk_core_1.getImageDimensions;
|
|
89
|
-
return [4, (0, ssi_sdk_core_1.downloadImage)(image)];
|
|
90
|
-
case 3: return [4, _f.apply(void 0, [(_q.sent()).base64Content])];
|
|
91
|
-
case 4:
|
|
92
|
-
_e = _q.sent();
|
|
93
|
-
return [3, 6];
|
|
94
|
-
case 5:
|
|
95
|
-
_e = undefined;
|
|
96
|
-
_q.label = 6;
|
|
97
|
-
case 6:
|
|
98
|
-
_d.apply(_c, [(_o.imageSize = _e,
|
|
99
|
-
_o)]);
|
|
100
|
-
return [3, 16];
|
|
101
|
-
case 7:
|
|
102
|
-
if (key === 'type') {
|
|
103
|
-
rows.push({
|
|
104
|
-
id: (0, uuid_1.v4)(),
|
|
105
|
-
label: key,
|
|
106
|
-
value: value
|
|
107
|
-
});
|
|
108
|
-
return [3, 16];
|
|
109
|
-
}
|
|
110
|
-
_q.label = 8;
|
|
111
|
-
case 8:
|
|
112
|
-
if (!(typeof value !== 'string')) return [3, 10];
|
|
113
|
-
_h = (_g = rows).concat;
|
|
114
|
-
return [4, toCredentialDetailsRow(value, subject, issuer)];
|
|
115
|
-
case 9:
|
|
116
|
-
rows = _h.apply(_g, [_q.sent()]);
|
|
117
|
-
return [3, 16];
|
|
118
|
-
case 10:
|
|
119
|
-
console.log("==>".concat(key, ":").concat(value));
|
|
120
|
-
if (key === '0' || value === undefined) {
|
|
121
|
-
return [3, 16];
|
|
122
|
-
}
|
|
123
|
-
label = key;
|
|
124
|
-
if (key === 'id' && value.startsWith('did:')) {
|
|
125
|
-
label = 'subject';
|
|
126
|
-
}
|
|
127
|
-
if (value.startsWith('did:')) {
|
|
128
|
-
console.log("did: ".concat(value));
|
|
129
|
-
contacts = __spreadArray(__spreadArray([], (issuer ? [issuer] : []), true), (subject ? [subject] : []), true);
|
|
130
|
-
value = findCorrelationIdName(value, contacts);
|
|
131
|
-
}
|
|
132
|
-
_k = (_j = rows).push;
|
|
133
|
-
_p = {
|
|
134
|
-
id: (0, uuid_1.v4)(),
|
|
135
|
-
label: label,
|
|
136
|
-
value: value
|
|
137
|
-
};
|
|
138
|
-
return [4, (0, ImageUtils_1.isImageAddress)(value)];
|
|
139
|
-
case 11:
|
|
140
|
-
if (!(_q.sent())) return [3, 14];
|
|
141
|
-
_m = ssi_sdk_core_1.getImageDimensions;
|
|
142
|
-
return [4, (0, ssi_sdk_core_1.downloadImage)(value)];
|
|
143
|
-
case 12: return [4, _m.apply(void 0, [(_q.sent()).base64Content])];
|
|
144
|
-
case 13:
|
|
145
|
-
_l = _q.sent();
|
|
146
|
-
return [3, 15];
|
|
147
|
-
case 14:
|
|
148
|
-
_l = undefined;
|
|
149
|
-
_q.label = 15;
|
|
150
|
-
case 15:
|
|
151
|
-
_k.apply(_j, [(_p.imageSize = _l,
|
|
152
|
-
_p)]);
|
|
153
|
-
_q.label = 16;
|
|
154
|
-
case 16:
|
|
155
|
-
_i++;
|
|
156
|
-
return [3, 1];
|
|
157
|
-
case 17: return [2, rows];
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}); };
|
|
161
|
-
var toNonPersistedCredentialSummary = function (verifiableCredential, branding, issuer, subject) {
|
|
162
|
-
var _a;
|
|
163
|
-
return (0, exports.toCredentialSummary)({
|
|
164
|
-
verifiableCredential: verifiableCredential,
|
|
165
|
-
hash: (_a = verifiableCredential.id) !== null && _a !== void 0 ? _a : (0, utils_1.computeEntryHash)(verifiableCredential)
|
|
166
|
-
}, branding, issuer, subject);
|
|
167
|
-
};
|
|
168
|
-
exports.toNonPersistedCredentialSummary = toNonPersistedCredentialSummary;
|
|
169
|
-
var toCredentialSummary = function (_a, branding, issuer, subject) {
|
|
170
|
-
var hash = _a.hash, verifiableCredential = _a.verifiableCredential;
|
|
171
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
172
|
-
var expirationDate, issueDate, credentialStatus, title, properties, localeBranding, logo, url, name, issuerAlias;
|
|
173
|
-
var _b, _c, _d, _e;
|
|
174
|
-
return __generator(this, function (_f) {
|
|
175
|
-
switch (_f.label) {
|
|
176
|
-
case 0:
|
|
177
|
-
expirationDate = verifiableCredential.expirationDate
|
|
178
|
-
? new Date(verifiableCredential.expirationDate).valueOf() / ui_components_core_1.EPOCH_MILLISECONDS
|
|
179
|
-
: 0;
|
|
180
|
-
issueDate = new Date(verifiableCredential.issuanceDate).valueOf() / ui_components_core_1.EPOCH_MILLISECONDS;
|
|
181
|
-
credentialStatus = (0, MappingUtils_1.getCredentialStatus)(verifiableCredential);
|
|
182
|
-
title = verifiableCredential.name
|
|
183
|
-
? verifiableCredential.name
|
|
184
|
-
: !verifiableCredential.type
|
|
185
|
-
? 'unknown'
|
|
186
|
-
: typeof verifiableCredential.type === 'string'
|
|
187
|
-
? verifiableCredential.type
|
|
188
|
-
: verifiableCredential.type.filter(function (value) { return value !== 'VerifiableCredential'; })[0];
|
|
189
|
-
return [4, toCredentialDetailsRow(verifiableCredential.credentialSubject, subject, issuer)];
|
|
190
|
-
case 1:
|
|
191
|
-
properties = _f.sent();
|
|
192
|
-
return [4, (0, exports.selectAppLocaleBranding)({ localeBranding: branding })];
|
|
193
|
-
case 2:
|
|
194
|
-
localeBranding = _f.sent();
|
|
195
|
-
logo = (0, ImageUtils_1.getIssuerLogo)(verifiableCredential, localeBranding);
|
|
196
|
-
url = typeof verifiableCredential.issuer !== 'string' ? verifiableCredential.issuer.url : undefined;
|
|
197
|
-
name = typeof verifiableCredential.issuer === 'string'
|
|
198
|
-
? verifiableCredential.issuer
|
|
199
|
-
: (_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;
|
|
200
|
-
issuerAlias = undefined;
|
|
201
|
-
if (typeof (verifiableCredential === null || verifiableCredential === void 0 ? void 0 : verifiableCredential.issuer) === 'object' && ((_e = verifiableCredential.issuer) === null || _e === void 0 ? void 0 : _e.name)) {
|
|
202
|
-
issuerAlias = verifiableCredential.issuer.name;
|
|
203
|
-
}
|
|
204
|
-
if (!issuerAlias && issuer) {
|
|
205
|
-
issuerAlias = issuer.contact.displayName;
|
|
206
|
-
}
|
|
207
|
-
if (!issuerAlias) {
|
|
208
|
-
throw Error("Could not deduce issuer alias");
|
|
209
|
-
}
|
|
210
|
-
return [2, {
|
|
211
|
-
hash: hash,
|
|
212
|
-
id: verifiableCredential.id,
|
|
213
|
-
title: (localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.alias) || title,
|
|
214
|
-
credentialStatus: credentialStatus,
|
|
215
|
-
issueDate: issueDate,
|
|
216
|
-
expirationDate: expirationDate,
|
|
217
|
-
properties: properties,
|
|
218
|
-
branding: localeBranding,
|
|
219
|
-
issuer: {
|
|
220
|
-
name: name,
|
|
221
|
-
alias: issuerAlias ? (issuerAlias.length > 50 ? "".concat(issuerAlias.substring(0, 50), "...") : issuerAlias) : '',
|
|
222
|
-
image: logo,
|
|
223
|
-
url: url
|
|
224
|
-
}
|
|
225
|
-
}];
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
};
|
|
230
|
-
exports.toCredentialSummary = toCredentialSummary;
|
|
231
|
-
var selectAppLocaleBranding = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
232
|
-
var appLocale, localeBranding, logo, imagePreloader, backgroundImage;
|
|
233
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
234
|
-
return __generator(this, function (_h) {
|
|
235
|
-
appLocale = ui_components_core_1.Localization.getLocale();
|
|
236
|
-
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; });
|
|
237
|
-
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);
|
|
238
|
-
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
239
|
-
throw new Error('Not implemented');
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
imagePreloader = new WebImagePreloader_1.WebImagePreloader();
|
|
243
|
-
}
|
|
244
|
-
if (logo) {
|
|
245
|
-
imagePreloader.preload([{ uri: logo }])["catch"](function () {
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
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);
|
|
249
|
-
if (backgroundImage) {
|
|
250
|
-
imagePreloader.preload([{ uri: backgroundImage }])["catch"](function () {
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
return [2, localeBranding];
|
|
254
|
-
});
|
|
255
|
-
}); };
|
|
256
|
-
exports.selectAppLocaleBranding = selectAppLocaleBranding;
|
|
17
|
+
__exportStar(require("./mapping"), exports);
|
|
18
|
+
__exportStar(require("./services"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
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>;
|
|
@@ -0,0 +1,256 @@
|
|
|
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 ImageUtils_1 = require("../utils/ImageUtils");
|
|
54
|
+
var WebImagePreloader_1 = require("../services/WebImagePreloader");
|
|
55
|
+
var MappingUtils_1 = require("../utils/MappingUtils");
|
|
56
|
+
function findCorrelationIdName(correlationId, contacts) {
|
|
57
|
+
var contact = contacts.find(function (contact) {
|
|
58
|
+
return contact.identities.some(function (identity) { return identity.identifier.correlationId === correlationId; });
|
|
59
|
+
});
|
|
60
|
+
if (contact) {
|
|
61
|
+
return contact.contact.displayName;
|
|
62
|
+
}
|
|
63
|
+
return correlationId;
|
|
64
|
+
}
|
|
65
|
+
var toCredentialDetailsRow = function (object, subject, issuer) { return __awaiter(void 0, void 0, void 0, function () {
|
|
66
|
+
var rows, _i, _a, _b, key, value, image, _c, _d, _e, _f, _g, _h, label, contacts, _j, _k, _l, _m;
|
|
67
|
+
var _o, _p;
|
|
68
|
+
return __generator(this, function (_q) {
|
|
69
|
+
switch (_q.label) {
|
|
70
|
+
case 0:
|
|
71
|
+
rows = [];
|
|
72
|
+
_i = 0, _a = Object.entries(object);
|
|
73
|
+
_q.label = 1;
|
|
74
|
+
case 1:
|
|
75
|
+
if (!(_i < _a.length)) return [3, 17];
|
|
76
|
+
_b = _a[_i], key = _b[0], value = _b[1];
|
|
77
|
+
if (!key.toLowerCase().includes('image')) return [3, 7];
|
|
78
|
+
image = typeof value === 'string' ? value : value.id;
|
|
79
|
+
_d = (_c = rows).push;
|
|
80
|
+
_o = {
|
|
81
|
+
id: (0, uuid_1.v4)(),
|
|
82
|
+
label: 'image',
|
|
83
|
+
value: image
|
|
84
|
+
};
|
|
85
|
+
return [4, (0, ImageUtils_1.isImageAddress)(image)];
|
|
86
|
+
case 2:
|
|
87
|
+
if (!(_q.sent())) return [3, 5];
|
|
88
|
+
_f = ssi_sdk_core_1.getImageDimensions;
|
|
89
|
+
return [4, (0, ssi_sdk_core_1.downloadImage)(image)];
|
|
90
|
+
case 3: return [4, _f.apply(void 0, [(_q.sent()).base64Content])];
|
|
91
|
+
case 4:
|
|
92
|
+
_e = _q.sent();
|
|
93
|
+
return [3, 6];
|
|
94
|
+
case 5:
|
|
95
|
+
_e = undefined;
|
|
96
|
+
_q.label = 6;
|
|
97
|
+
case 6:
|
|
98
|
+
_d.apply(_c, [(_o.imageSize = _e,
|
|
99
|
+
_o)]);
|
|
100
|
+
return [3, 16];
|
|
101
|
+
case 7:
|
|
102
|
+
if (key === 'type') {
|
|
103
|
+
rows.push({
|
|
104
|
+
id: (0, uuid_1.v4)(),
|
|
105
|
+
label: key,
|
|
106
|
+
value: value
|
|
107
|
+
});
|
|
108
|
+
return [3, 16];
|
|
109
|
+
}
|
|
110
|
+
_q.label = 8;
|
|
111
|
+
case 8:
|
|
112
|
+
if (!(typeof value !== 'string')) return [3, 10];
|
|
113
|
+
_h = (_g = rows).concat;
|
|
114
|
+
return [4, toCredentialDetailsRow(value, subject, issuer)];
|
|
115
|
+
case 9:
|
|
116
|
+
rows = _h.apply(_g, [_q.sent()]);
|
|
117
|
+
return [3, 16];
|
|
118
|
+
case 10:
|
|
119
|
+
console.log("==>".concat(key, ":").concat(value));
|
|
120
|
+
if (key === '0' || value === undefined) {
|
|
121
|
+
return [3, 16];
|
|
122
|
+
}
|
|
123
|
+
label = key;
|
|
124
|
+
if (key === 'id' && value.startsWith('did:')) {
|
|
125
|
+
label = 'subject';
|
|
126
|
+
}
|
|
127
|
+
if (value.startsWith('did:')) {
|
|
128
|
+
console.log("did: ".concat(value));
|
|
129
|
+
contacts = __spreadArray(__spreadArray([], (issuer ? [issuer] : []), true), (subject ? [subject] : []), true);
|
|
130
|
+
value = findCorrelationIdName(value, contacts);
|
|
131
|
+
}
|
|
132
|
+
_k = (_j = rows).push;
|
|
133
|
+
_p = {
|
|
134
|
+
id: (0, uuid_1.v4)(),
|
|
135
|
+
label: label,
|
|
136
|
+
value: value
|
|
137
|
+
};
|
|
138
|
+
return [4, (0, ImageUtils_1.isImageAddress)(value)];
|
|
139
|
+
case 11:
|
|
140
|
+
if (!(_q.sent())) return [3, 14];
|
|
141
|
+
_m = ssi_sdk_core_1.getImageDimensions;
|
|
142
|
+
return [4, (0, ssi_sdk_core_1.downloadImage)(value)];
|
|
143
|
+
case 12: return [4, _m.apply(void 0, [(_q.sent()).base64Content])];
|
|
144
|
+
case 13:
|
|
145
|
+
_l = _q.sent();
|
|
146
|
+
return [3, 15];
|
|
147
|
+
case 14:
|
|
148
|
+
_l = undefined;
|
|
149
|
+
_q.label = 15;
|
|
150
|
+
case 15:
|
|
151
|
+
_k.apply(_j, [(_p.imageSize = _l,
|
|
152
|
+
_p)]);
|
|
153
|
+
_q.label = 16;
|
|
154
|
+
case 16:
|
|
155
|
+
_i++;
|
|
156
|
+
return [3, 1];
|
|
157
|
+
case 17: return [2, rows];
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}); };
|
|
161
|
+
var toNonPersistedCredentialSummary = function (verifiableCredential, branding, issuer, subject) {
|
|
162
|
+
var _a;
|
|
163
|
+
return (0, exports.toCredentialSummary)({
|
|
164
|
+
verifiableCredential: verifiableCredential,
|
|
165
|
+
hash: (_a = verifiableCredential.id) !== null && _a !== void 0 ? _a : (0, utils_1.computeEntryHash)(verifiableCredential)
|
|
166
|
+
}, branding, issuer, subject);
|
|
167
|
+
};
|
|
168
|
+
exports.toNonPersistedCredentialSummary = toNonPersistedCredentialSummary;
|
|
169
|
+
var toCredentialSummary = function (_a, branding, issuer, subject) {
|
|
170
|
+
var hash = _a.hash, verifiableCredential = _a.verifiableCredential;
|
|
171
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
172
|
+
var expirationDate, issueDate, credentialStatus, title, properties, localeBranding, logo, url, name, issuerAlias;
|
|
173
|
+
var _b, _c, _d, _e;
|
|
174
|
+
return __generator(this, function (_f) {
|
|
175
|
+
switch (_f.label) {
|
|
176
|
+
case 0:
|
|
177
|
+
expirationDate = verifiableCredential.expirationDate
|
|
178
|
+
? new Date(verifiableCredential.expirationDate).valueOf() / ui_components_core_1.EPOCH_MILLISECONDS
|
|
179
|
+
: 0;
|
|
180
|
+
issueDate = new Date(verifiableCredential.issuanceDate).valueOf() / ui_components_core_1.EPOCH_MILLISECONDS;
|
|
181
|
+
credentialStatus = (0, MappingUtils_1.getCredentialStatus)(verifiableCredential);
|
|
182
|
+
title = verifiableCredential.name
|
|
183
|
+
? verifiableCredential.name
|
|
184
|
+
: !verifiableCredential.type
|
|
185
|
+
? 'unknown'
|
|
186
|
+
: typeof verifiableCredential.type === 'string'
|
|
187
|
+
? verifiableCredential.type
|
|
188
|
+
: verifiableCredential.type.filter(function (value) { return value !== 'VerifiableCredential'; })[0];
|
|
189
|
+
return [4, toCredentialDetailsRow(verifiableCredential.credentialSubject, subject, issuer)];
|
|
190
|
+
case 1:
|
|
191
|
+
properties = _f.sent();
|
|
192
|
+
return [4, (0, exports.selectAppLocaleBranding)({ localeBranding: branding })];
|
|
193
|
+
case 2:
|
|
194
|
+
localeBranding = _f.sent();
|
|
195
|
+
logo = (0, ImageUtils_1.getIssuerLogo)(verifiableCredential, localeBranding);
|
|
196
|
+
url = typeof verifiableCredential.issuer !== 'string' ? verifiableCredential.issuer.url : undefined;
|
|
197
|
+
name = typeof verifiableCredential.issuer === 'string'
|
|
198
|
+
? verifiableCredential.issuer
|
|
199
|
+
: (_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;
|
|
200
|
+
issuerAlias = undefined;
|
|
201
|
+
if (typeof (verifiableCredential === null || verifiableCredential === void 0 ? void 0 : verifiableCredential.issuer) === 'object' && ((_e = verifiableCredential.issuer) === null || _e === void 0 ? void 0 : _e.name)) {
|
|
202
|
+
issuerAlias = verifiableCredential.issuer.name;
|
|
203
|
+
}
|
|
204
|
+
if (!issuerAlias && issuer) {
|
|
205
|
+
issuerAlias = issuer.contact.displayName;
|
|
206
|
+
}
|
|
207
|
+
if (!issuerAlias) {
|
|
208
|
+
throw Error("Could not deduce issuer alias");
|
|
209
|
+
}
|
|
210
|
+
return [2, {
|
|
211
|
+
hash: hash,
|
|
212
|
+
id: verifiableCredential.id,
|
|
213
|
+
title: (localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.alias) || title,
|
|
214
|
+
credentialStatus: credentialStatus,
|
|
215
|
+
issueDate: issueDate,
|
|
216
|
+
expirationDate: expirationDate,
|
|
217
|
+
properties: properties,
|
|
218
|
+
branding: localeBranding,
|
|
219
|
+
issuer: {
|
|
220
|
+
name: name,
|
|
221
|
+
alias: issuerAlias ? (issuerAlias.length > 50 ? "".concat(issuerAlias.substring(0, 50), "...") : issuerAlias) : '',
|
|
222
|
+
image: logo,
|
|
223
|
+
url: url
|
|
224
|
+
}
|
|
225
|
+
}];
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
exports.toCredentialSummary = toCredentialSummary;
|
|
231
|
+
var selectAppLocaleBranding = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
232
|
+
var appLocale, localeBranding, logo, imagePreloader, backgroundImage;
|
|
233
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
234
|
+
return __generator(this, function (_h) {
|
|
235
|
+
appLocale = ui_components_core_1.Localization.getLocale();
|
|
236
|
+
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; });
|
|
237
|
+
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);
|
|
238
|
+
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
239
|
+
throw new Error('Not implemented');
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
imagePreloader = new WebImagePreloader_1.WebImagePreloader();
|
|
243
|
+
}
|
|
244
|
+
if (logo) {
|
|
245
|
+
imagePreloader.preload([{ uri: logo }])["catch"](function () {
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
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);
|
|
249
|
+
if (backgroundImage) {
|
|
250
|
+
imagePreloader.preload([{ uri: backgroundImage }])["catch"](function () {
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
return [2, localeBranding];
|
|
254
|
+
});
|
|
255
|
+
}); };
|
|
256
|
+
exports.selectAppLocaleBranding = selectAppLocaleBranding;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CredentialMapper';
|
|
@@ -0,0 +1,17 @@
|
|
|
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);
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./WebImagePreloader"), exports);
|
|
18
|
+
__exportStar(require("./IPreloadImage"), exports);
|
|
19
|
+
__exportStar(require("./ReactNativeImagePreloader"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./ImageUtils"), exports);
|
|
18
|
+
__exportStar(require("./MappingUtils"), exports);
|
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.
|
|
4
|
+
"version": "0.2.1-unstable.8+97f28d8",
|
|
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,23 +28,19 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@sphereon/ssi-sdk.core": "
|
|
32
|
-
"@sphereon/ssi-sdk.data-store": "0.23.
|
|
33
|
-
"@sphereon/ssi-types": "
|
|
34
|
-
"@sphereon/ui-components.core": "0.2.1-unstable.
|
|
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.8+97f28d8",
|
|
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",
|
|
40
38
|
"uuid": "^9.0.1"
|
|
41
39
|
},
|
|
42
40
|
"devDependencies": {
|
|
43
41
|
"@types/i18n-js": "^3.8.4",
|
|
44
|
-
"@types/lodash.memoize": "^4.1.7",
|
|
45
42
|
"@types/node": "^20.4.0",
|
|
46
43
|
"@types/react": "~18.2.67",
|
|
47
|
-
"@types/styled-components": "^5.1.15",
|
|
48
44
|
"@types/uuid": "^9.0.8",
|
|
49
45
|
"react": "18.2.0",
|
|
50
46
|
"typescript": "4.9.5"
|
|
@@ -52,5 +48,5 @@
|
|
|
52
48
|
"peerDependencies": {
|
|
53
49
|
"react": ">= 18"
|
|
54
50
|
},
|
|
55
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "97f28d8d19895339b6834e6fc793d774ecce88ae"
|
|
56
52
|
}
|