@sphereon/ui-components.credential-branding 0.2.1-unstable.6 → 0.2.1-unstable.67
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/LICENSE +201 -636
- package/README.md +1 -7
- 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 +284 -0
- package/dist/mapping/index.d.ts +1 -0
- package/dist/mapping/index.js +17 -0
- package/dist/services/ReactNativeImagePreloader.js +16 -3
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +17 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +18 -0
- package/package.json +8 -11
package/README.md
CHANGED
|
@@ -6,13 +6,7 @@
|
|
|
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
|
-
|
|
15
|
-
A UI Core package for shared logic / styling and localization between components related to Credential Branding
|
|
9
|
+
A UI Core package for shared logic between components related to Credential Branding
|
|
16
10
|
|
|
17
11
|
### Build
|
|
18
12
|
|
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,284 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
+
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;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
62
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
63
|
+
if (ar || !(i in from)) {
|
|
64
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
65
|
+
ar[i] = from[i];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
69
|
+
};
|
|
70
|
+
exports.__esModule = true;
|
|
71
|
+
exports.selectAppLocaleBranding = exports.toCredentialSummary = exports.toNonPersistedCredentialSummary = void 0;
|
|
72
|
+
var uuid_1 = require("uuid");
|
|
73
|
+
var utils_1 = require("@veramo/utils");
|
|
74
|
+
var ui_components_core_1 = require("@sphereon/ui-components.core");
|
|
75
|
+
var ssi_sdk_core_1 = require("@sphereon/ssi-sdk.core");
|
|
76
|
+
var utils_2 = require("../utils");
|
|
77
|
+
function findCorrelationIdName(correlationId, contacts) {
|
|
78
|
+
var contact = contacts.find(function (contact) {
|
|
79
|
+
return contact.identities.some(function (identity) { return identity.identifier.correlationId === correlationId; });
|
|
80
|
+
});
|
|
81
|
+
if (contact) {
|
|
82
|
+
return contact.contact.displayName;
|
|
83
|
+
}
|
|
84
|
+
return correlationId;
|
|
85
|
+
}
|
|
86
|
+
var toCredentialDetailsRow = function (object, subject, issuer) { return __awaiter(void 0, void 0, void 0, function () {
|
|
87
|
+
var rows, _i, _a, _b, key, value, image, _c, _d, _e, _f, _g, _h, label, contacts, _j, _k, _l, _m;
|
|
88
|
+
var _o, _p;
|
|
89
|
+
return __generator(this, function (_q) {
|
|
90
|
+
switch (_q.label) {
|
|
91
|
+
case 0:
|
|
92
|
+
rows = [];
|
|
93
|
+
_i = 0, _a = Object.entries(object);
|
|
94
|
+
_q.label = 1;
|
|
95
|
+
case 1:
|
|
96
|
+
if (!(_i < _a.length)) return [3, 17];
|
|
97
|
+
_b = _a[_i], key = _b[0], value = _b[1];
|
|
98
|
+
if (!key.toLowerCase().includes('image')) return [3, 7];
|
|
99
|
+
image = typeof value === 'string' ? value : value.id;
|
|
100
|
+
_d = (_c = rows).push;
|
|
101
|
+
_o = {
|
|
102
|
+
id: (0, uuid_1.v4)(),
|
|
103
|
+
label: 'image',
|
|
104
|
+
value: image
|
|
105
|
+
};
|
|
106
|
+
return [4, (0, utils_2.isImageAddress)(image)];
|
|
107
|
+
case 2:
|
|
108
|
+
if (!(_q.sent())) return [3, 5];
|
|
109
|
+
_f = ssi_sdk_core_1.getImageDimensions;
|
|
110
|
+
return [4, (0, ssi_sdk_core_1.downloadImage)(image)];
|
|
111
|
+
case 3: return [4, _f.apply(void 0, [(_q.sent()).base64Content])];
|
|
112
|
+
case 4:
|
|
113
|
+
_e = _q.sent();
|
|
114
|
+
return [3, 6];
|
|
115
|
+
case 5:
|
|
116
|
+
_e = undefined;
|
|
117
|
+
_q.label = 6;
|
|
118
|
+
case 6:
|
|
119
|
+
_d.apply(_c, [(_o.imageSize = _e,
|
|
120
|
+
_o)]);
|
|
121
|
+
return [3, 16];
|
|
122
|
+
case 7:
|
|
123
|
+
if (key === 'type') {
|
|
124
|
+
rows.push({
|
|
125
|
+
id: (0, uuid_1.v4)(),
|
|
126
|
+
label: key,
|
|
127
|
+
value: value
|
|
128
|
+
});
|
|
129
|
+
return [3, 16];
|
|
130
|
+
}
|
|
131
|
+
_q.label = 8;
|
|
132
|
+
case 8:
|
|
133
|
+
if (!(typeof value !== 'string')) return [3, 10];
|
|
134
|
+
_h = (_g = rows).concat;
|
|
135
|
+
return [4, toCredentialDetailsRow(value, subject, issuer)];
|
|
136
|
+
case 9:
|
|
137
|
+
rows = _h.apply(_g, [_q.sent()]);
|
|
138
|
+
return [3, 16];
|
|
139
|
+
case 10:
|
|
140
|
+
if (key === '0' || value === undefined) {
|
|
141
|
+
return [3, 16];
|
|
142
|
+
}
|
|
143
|
+
label = key;
|
|
144
|
+
if (key === 'id' && value.startsWith('did:')) {
|
|
145
|
+
label = 'subject';
|
|
146
|
+
}
|
|
147
|
+
if (value.startsWith('did:')) {
|
|
148
|
+
contacts = __spreadArray(__spreadArray([], (issuer ? [issuer] : []), true), (subject ? [subject] : []), true);
|
|
149
|
+
value = findCorrelationIdName(value, contacts);
|
|
150
|
+
}
|
|
151
|
+
_k = (_j = rows).push;
|
|
152
|
+
_p = {
|
|
153
|
+
id: (0, uuid_1.v4)(),
|
|
154
|
+
label: label,
|
|
155
|
+
value: value
|
|
156
|
+
};
|
|
157
|
+
return [4, (0, utils_2.isImageAddress)(value)];
|
|
158
|
+
case 11:
|
|
159
|
+
if (!(_q.sent())) return [3, 14];
|
|
160
|
+
_m = ssi_sdk_core_1.getImageDimensions;
|
|
161
|
+
return [4, (0, ssi_sdk_core_1.downloadImage)(value)];
|
|
162
|
+
case 12: return [4, _m.apply(void 0, [(_q.sent()).base64Content])];
|
|
163
|
+
case 13:
|
|
164
|
+
_l = _q.sent();
|
|
165
|
+
return [3, 15];
|
|
166
|
+
case 14:
|
|
167
|
+
_l = undefined;
|
|
168
|
+
_q.label = 15;
|
|
169
|
+
case 15:
|
|
170
|
+
_k.apply(_j, [(_p.imageSize = _l,
|
|
171
|
+
_p)]);
|
|
172
|
+
_q.label = 16;
|
|
173
|
+
case 16:
|
|
174
|
+
_i++;
|
|
175
|
+
return [3, 1];
|
|
176
|
+
case 17: return [2, rows];
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}); };
|
|
180
|
+
var toNonPersistedCredentialSummary = function (verifiableCredential, branding, issuer, subject) {
|
|
181
|
+
var _a;
|
|
182
|
+
return (0, exports.toCredentialSummary)({
|
|
183
|
+
verifiableCredential: verifiableCredential,
|
|
184
|
+
hash: (_a = verifiableCredential.id) !== null && _a !== void 0 ? _a : (0, utils_1.computeEntryHash)(verifiableCredential)
|
|
185
|
+
}, branding, issuer, subject);
|
|
186
|
+
};
|
|
187
|
+
exports.toNonPersistedCredentialSummary = toNonPersistedCredentialSummary;
|
|
188
|
+
var toCredentialSummary = function (_a, branding, issuer, subject) {
|
|
189
|
+
var hash = _a.hash, verifiableCredential = _a.verifiableCredential;
|
|
190
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
191
|
+
var expirationDate, issueDate, credentialStatus, title, properties, localeBranding, logo, url, name, issuerAlias;
|
|
192
|
+
var _b, _c, _d, _e;
|
|
193
|
+
return __generator(this, function (_f) {
|
|
194
|
+
switch (_f.label) {
|
|
195
|
+
case 0:
|
|
196
|
+
expirationDate = verifiableCredential.expirationDate
|
|
197
|
+
? new Date(verifiableCredential.expirationDate).valueOf() / ui_components_core_1.EPOCH_MILLISECONDS
|
|
198
|
+
: 0;
|
|
199
|
+
issueDate = new Date(verifiableCredential.issuanceDate).valueOf() / ui_components_core_1.EPOCH_MILLISECONDS;
|
|
200
|
+
credentialStatus = (0, utils_2.getCredentialStatus)(verifiableCredential);
|
|
201
|
+
title = verifiableCredential.name
|
|
202
|
+
? verifiableCredential.name
|
|
203
|
+
: !verifiableCredential.type
|
|
204
|
+
? 'unknown'
|
|
205
|
+
: typeof verifiableCredential.type === 'string'
|
|
206
|
+
? verifiableCredential.type
|
|
207
|
+
: verifiableCredential.type.filter(function (value) { return value !== 'VerifiableCredential'; })[0];
|
|
208
|
+
return [4, toCredentialDetailsRow(verifiableCredential.credentialSubject, subject, issuer)];
|
|
209
|
+
case 1:
|
|
210
|
+
properties = _f.sent();
|
|
211
|
+
return [4, (0, exports.selectAppLocaleBranding)({ localeBranding: branding })];
|
|
212
|
+
case 2:
|
|
213
|
+
localeBranding = _f.sent();
|
|
214
|
+
logo = (0, utils_2.getIssuerLogo)(verifiableCredential, localeBranding);
|
|
215
|
+
url = typeof verifiableCredential.issuer !== 'string' ? verifiableCredential.issuer.url : undefined;
|
|
216
|
+
name = typeof verifiableCredential.issuer === 'string'
|
|
217
|
+
? verifiableCredential.issuer
|
|
218
|
+
: (_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;
|
|
219
|
+
issuerAlias = undefined;
|
|
220
|
+
if (typeof (verifiableCredential === null || verifiableCredential === void 0 ? void 0 : verifiableCredential.issuer) === 'object' && ((_e = verifiableCredential.issuer) === null || _e === void 0 ? void 0 : _e.name)) {
|
|
221
|
+
issuerAlias = verifiableCredential.issuer.name;
|
|
222
|
+
}
|
|
223
|
+
if (!issuerAlias && issuer) {
|
|
224
|
+
issuerAlias = issuer.contact.displayName;
|
|
225
|
+
}
|
|
226
|
+
if (!issuerAlias) {
|
|
227
|
+
throw Error("Could not deduce issuer alias");
|
|
228
|
+
}
|
|
229
|
+
return [2, {
|
|
230
|
+
hash: hash,
|
|
231
|
+
id: verifiableCredential.id,
|
|
232
|
+
title: (localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.alias) || title,
|
|
233
|
+
credentialStatus: credentialStatus,
|
|
234
|
+
issueDate: issueDate,
|
|
235
|
+
expirationDate: expirationDate,
|
|
236
|
+
properties: properties,
|
|
237
|
+
branding: localeBranding,
|
|
238
|
+
issuer: {
|
|
239
|
+
name: name,
|
|
240
|
+
alias: issuerAlias ? (issuerAlias.length > 50 ? "".concat(issuerAlias.substring(0, 50), "...") : issuerAlias) : '',
|
|
241
|
+
image: logo,
|
|
242
|
+
url: url
|
|
243
|
+
}
|
|
244
|
+
}];
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
exports.toCredentialSummary = toCredentialSummary;
|
|
250
|
+
var selectAppLocaleBranding = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
251
|
+
var appLocale, localeBranding, logo, imagePreloader, ReactNativeImagePreloader, WebImagePreloader, backgroundImage;
|
|
252
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
253
|
+
return __generator(this, function (_h) {
|
|
254
|
+
switch (_h.label) {
|
|
255
|
+
case 0:
|
|
256
|
+
appLocale = ui_components_core_1.Localization.getLocale();
|
|
257
|
+
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; });
|
|
258
|
+
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);
|
|
259
|
+
if (!(typeof window === 'undefined')) return [3, 2];
|
|
260
|
+
return [4, Promise.resolve().then(function () { return __importStar(require('../services/ReactNativeImagePreloader')); })];
|
|
261
|
+
case 1:
|
|
262
|
+
ReactNativeImagePreloader = (_h.sent()).ReactNativeImagePreloader;
|
|
263
|
+
imagePreloader = new ReactNativeImagePreloader();
|
|
264
|
+
return [3, 4];
|
|
265
|
+
case 2: return [4, Promise.resolve().then(function () { return __importStar(require('../services/WebImagePreloader')); })];
|
|
266
|
+
case 3:
|
|
267
|
+
WebImagePreloader = (_h.sent()).WebImagePreloader;
|
|
268
|
+
imagePreloader = new WebImagePreloader();
|
|
269
|
+
_h.label = 4;
|
|
270
|
+
case 4:
|
|
271
|
+
if (logo) {
|
|
272
|
+
imagePreloader.preload([{ uri: logo }])["catch"](function () {
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
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);
|
|
276
|
+
if (backgroundImage) {
|
|
277
|
+
imagePreloader.preload([{ uri: backgroundImage }])["catch"](function () {
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
return [2, localeBranding];
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
}); };
|
|
284
|
+
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);
|
|
@@ -37,15 +37,28 @@ 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');
|
|
41
40
|
var ReactNativeImagePreloader = (function () {
|
|
42
41
|
function ReactNativeImagePreloader() {
|
|
43
42
|
}
|
|
44
43
|
ReactNativeImagePreloader.prototype.preload = function (sources) {
|
|
45
44
|
return __awaiter(this, void 0, void 0, function () {
|
|
45
|
+
var promises;
|
|
46
46
|
return __generator(this, function (_a) {
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
switch (_a.label) {
|
|
48
|
+
case 0:
|
|
49
|
+
promises = sources.map(function (source) {
|
|
50
|
+
return new Promise(function (resolve, reject) {
|
|
51
|
+
var img = new Image();
|
|
52
|
+
img.src = source.uri;
|
|
53
|
+
img.onload = function () { return resolve(); };
|
|
54
|
+
img.onerror = function (error) { return reject(error); };
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
return [4, Promise.all(promises)];
|
|
58
|
+
case 1:
|
|
59
|
+
_a.sent();
|
|
60
|
+
return [2];
|
|
61
|
+
}
|
|
49
62
|
});
|
|
50
63
|
});
|
|
51
64
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './IPreloadImage';
|