@sphereon/ssi-sdk.wellknown-did-issuer 0.33.1-feature.vcdm2.4 → 0.33.1-feature.vcdm2.tsup.19
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.cjs +620 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +116 -0
- package/dist/index.d.ts +112 -8
- package/dist/index.js +581 -11
- package/dist/index.js.map +1 -1
- package/package.json +27 -15
- package/src/agent/WellKnownDidIssuer.ts +2 -0
- package/dist/agent/WellKnownDidIssuer.d.ts +0 -35
- package/dist/agent/WellKnownDidIssuer.d.ts.map +0 -1
- package/dist/agent/WellKnownDidIssuer.js +0 -188
- package/dist/agent/WellKnownDidIssuer.js.map +0 -1
- package/dist/entities/DidConfigurationResourceEntity.d.ts +0 -14
- package/dist/entities/DidConfigurationResourceEntity.d.ts.map +0 -1
- package/dist/entities/DidConfigurationResourceEntity.js +0 -101
- package/dist/entities/DidConfigurationResourceEntity.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/migrations/generic/1-CreateWellknownDidIssuer.d.ts +0 -7
- package/dist/migrations/generic/1-CreateWellknownDidIssuer.d.ts.map +0 -1
- package/dist/migrations/generic/1-CreateWellknownDidIssuer.js +0 -50
- package/dist/migrations/generic/1-CreateWellknownDidIssuer.js.map +0 -1
- package/dist/migrations/generic/index.d.ts +0 -10
- package/dist/migrations/generic/index.d.ts.map +0 -1
- package/dist/migrations/generic/index.js +0 -10
- package/dist/migrations/generic/index.js.map +0 -1
- package/dist/migrations/index.d.ts +0 -2
- package/dist/migrations/index.d.ts.map +0 -1
- package/dist/migrations/index.js +0 -2
- package/dist/migrations/index.js.map +0 -1
- package/dist/migrations/internal-migrations-ormconfig.d.ts +0 -7
- package/dist/migrations/internal-migrations-ormconfig.d.ts.map +0 -1
- package/dist/migrations/internal-migrations-ormconfig.js +0 -27
- package/dist/migrations/internal-migrations-ormconfig.js.map +0 -1
- package/dist/migrations/postgres/1661165115000-CreateWellknownDidIssuer.d.ts +0 -7
- package/dist/migrations/postgres/1661165115000-CreateWellknownDidIssuer.d.ts.map +0 -1
- package/dist/migrations/postgres/1661165115000-CreateWellknownDidIssuer.js +0 -12
- package/dist/migrations/postgres/1661165115000-CreateWellknownDidIssuer.js.map +0 -1
- package/dist/migrations/sqlite/1661161799000-CreateWellknownDidIssuer.d.ts +0 -7
- package/dist/migrations/sqlite/1661161799000-CreateWellknownDidIssuer.d.ts.map +0 -1
- package/dist/migrations/sqlite/1661161799000-CreateWellknownDidIssuer.js +0 -12
- package/dist/migrations/sqlite/1661161799000-CreateWellknownDidIssuer.js.map +0 -1
- package/dist/types/IWellKnownDidIssuer.d.ts +0 -51
- package/dist/types/IWellKnownDidIssuer.d.ts.map +0 -1
- package/dist/types/IWellKnownDidIssuer.js +0 -2
- package/dist/types/IWellKnownDidIssuer.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,12 +1,582 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
5
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// plugin.schema.json
|
|
9
|
+
var require_plugin_schema = __commonJS({
|
|
10
|
+
"plugin.schema.json"(exports, module) {
|
|
11
|
+
module.exports = {
|
|
12
|
+
IWellKnownDidIssuer: {
|
|
13
|
+
components: {
|
|
14
|
+
schemas: {
|
|
15
|
+
IIssueDidConfigurationResourceArgs: {
|
|
16
|
+
type: "object",
|
|
17
|
+
properties: {
|
|
18
|
+
issuances: {
|
|
19
|
+
type: "array",
|
|
20
|
+
items: {
|
|
21
|
+
type: "object",
|
|
22
|
+
properties: {
|
|
23
|
+
additionalProperties: true
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
credentialIssuance: {
|
|
28
|
+
type: "string"
|
|
29
|
+
},
|
|
30
|
+
save: {
|
|
31
|
+
type: "boolean"
|
|
32
|
+
},
|
|
33
|
+
additionalProperties: false
|
|
34
|
+
},
|
|
35
|
+
required: ["issuances", "credentialIssuance"],
|
|
36
|
+
description: "Arguments needed for {@link IWellKnownDidIssuer.addLinkedDomainsService } "
|
|
37
|
+
},
|
|
38
|
+
IIssueDomainLinkageCredentialArgs: {
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: {
|
|
41
|
+
did: {
|
|
42
|
+
type: "string"
|
|
43
|
+
},
|
|
44
|
+
origin: {
|
|
45
|
+
type: "string"
|
|
46
|
+
},
|
|
47
|
+
serviceId: {
|
|
48
|
+
type: "string"
|
|
49
|
+
},
|
|
50
|
+
issuanceDate: {
|
|
51
|
+
type: "date"
|
|
52
|
+
},
|
|
53
|
+
expirationDate: {
|
|
54
|
+
type: "date"
|
|
55
|
+
},
|
|
56
|
+
save: {
|
|
57
|
+
type: "boolean"
|
|
58
|
+
},
|
|
59
|
+
options: {
|
|
60
|
+
type: "object",
|
|
61
|
+
properties: {
|
|
62
|
+
additionalProperties: true
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
credentialIssuance: {
|
|
66
|
+
type: "string"
|
|
67
|
+
},
|
|
68
|
+
additionalProperties: false
|
|
69
|
+
},
|
|
70
|
+
required: ["did", "origin", "expirationDate", "options"],
|
|
71
|
+
description: "Arguments needed for {@link IWellKnownDidIssuer.issueDomainLinkageCredential } "
|
|
72
|
+
},
|
|
73
|
+
IGetDidConfigurationResourceArgs: {
|
|
74
|
+
type: "object",
|
|
75
|
+
properties: {
|
|
76
|
+
origin: {
|
|
77
|
+
type: "string"
|
|
78
|
+
},
|
|
79
|
+
additionalProperties: false
|
|
80
|
+
},
|
|
81
|
+
required: ["origin"],
|
|
82
|
+
description: "Arguments needed for {@link IWellKnownDidIssuer.getDidConfigurationResource } "
|
|
83
|
+
},
|
|
84
|
+
IAddLinkedDomainsServiceArgs: {
|
|
85
|
+
type: "object",
|
|
86
|
+
properties: {
|
|
87
|
+
did: {
|
|
88
|
+
type: "string"
|
|
89
|
+
},
|
|
90
|
+
origin: {
|
|
91
|
+
type: "string"
|
|
92
|
+
},
|
|
93
|
+
serviceId: {
|
|
94
|
+
type: "string"
|
|
95
|
+
},
|
|
96
|
+
additionalProperties: false
|
|
97
|
+
},
|
|
98
|
+
required: ["did", "origin"],
|
|
99
|
+
description: "Arguments needed for {@link IWellKnownDidIssuer.addLinkedDomainsService } "
|
|
100
|
+
},
|
|
101
|
+
ISaveDidConfigurationResourceArgs: {
|
|
102
|
+
type: "object",
|
|
103
|
+
properties: {
|
|
104
|
+
origin: {
|
|
105
|
+
type: "string"
|
|
106
|
+
},
|
|
107
|
+
didConfigurationResource: {
|
|
108
|
+
type: "object",
|
|
109
|
+
properties: {
|
|
110
|
+
additionalProperties: true
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
additionalProperties: false
|
|
114
|
+
},
|
|
115
|
+
required: ["did", "origin"],
|
|
116
|
+
description: "Arguments needed for {@link IWellKnownDidIssuer.saveDidConfigurationResource } "
|
|
117
|
+
},
|
|
118
|
+
IRemoveCredentialIssuanceArgs: {
|
|
119
|
+
type: "object",
|
|
120
|
+
properties: {
|
|
121
|
+
origin: {
|
|
122
|
+
callbackName: "string"
|
|
123
|
+
},
|
|
124
|
+
additionalProperties: false
|
|
125
|
+
},
|
|
126
|
+
required: ["callbackName"],
|
|
127
|
+
description: "Arguments needed for {@link IWellKnownDidIssuer.removeCredentialIssuance } "
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
methods: {
|
|
131
|
+
addLinkedDomainsService: {
|
|
132
|
+
description: "Adds a LinkedDomains service to the DID",
|
|
133
|
+
arguments: {
|
|
134
|
+
$ref: "#/components/schemas/IAddLinkedDomainsServiceArgs"
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
getDidConfigurationResource: {
|
|
138
|
+
description: "Retrieves a DID configuration resource from the database",
|
|
139
|
+
arguments: {
|
|
140
|
+
$ref: "#/components/schemas/IGetDidConfigurationResourceArgs"
|
|
141
|
+
},
|
|
142
|
+
returnType: "object"
|
|
143
|
+
},
|
|
144
|
+
issueDidConfigurationResource: {
|
|
145
|
+
description: "Issues a DID configuration resource",
|
|
146
|
+
arguments: {
|
|
147
|
+
$ref: "#/components/schemas/IAddLinkedDomainsServiceArgs"
|
|
148
|
+
},
|
|
149
|
+
returnType: "object"
|
|
150
|
+
},
|
|
151
|
+
issueDomainLinkageCredential: {
|
|
152
|
+
description: "Retrieves a domain linkage credential",
|
|
153
|
+
arguments: {
|
|
154
|
+
$ref: "#/components/schemas/IIssueDomainLinkageCredentialArgs"
|
|
155
|
+
},
|
|
156
|
+
returnType: "object"
|
|
157
|
+
},
|
|
158
|
+
removeCredentialIssuance: {
|
|
159
|
+
description: "Removes a registered callback",
|
|
160
|
+
arguments: {
|
|
161
|
+
$ref: "#/components/schemas/IRemoveCredentialIssuanceArgs"
|
|
162
|
+
},
|
|
163
|
+
returnType: "boolean"
|
|
164
|
+
},
|
|
165
|
+
saveDidConfigurationResource: {
|
|
166
|
+
description: "Saves a DID configuration resource to the database",
|
|
167
|
+
arguments: {
|
|
168
|
+
$ref: "#/components/schemas/ISaveDidConfigurationResourceArgs"
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// src/entities/DidConfigurationResourceEntity.ts
|
|
179
|
+
import { Credential, Identifier, Claim } from "@veramo/data-store";
|
|
180
|
+
import { asArray, computeEntryHash, extractIssuer } from "@veramo/utils";
|
|
181
|
+
import { Entity, Column, PrimaryColumn, CreateDateColumn, UpdateDateColumn, ManyToMany, JoinTable, BaseEntity } from "typeorm";
|
|
182
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
183
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
184
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
185
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
186
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
187
|
+
}
|
|
188
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
189
|
+
function _ts_metadata(k, v) {
|
|
190
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
191
|
+
}
|
|
192
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
193
|
+
var DidConfigurationResourceEntity = class extends BaseEntity {
|
|
194
|
+
static {
|
|
195
|
+
__name(this, "DidConfigurationResourceEntity");
|
|
196
|
+
}
|
|
197
|
+
origin;
|
|
198
|
+
context;
|
|
199
|
+
// TODO cascade of delete should be true when the VC is only attached to one DID configuration resource
|
|
200
|
+
linkedDids;
|
|
201
|
+
createdAt;
|
|
202
|
+
lastUpdatedAt;
|
|
203
|
+
};
|
|
204
|
+
_ts_decorate([
|
|
205
|
+
PrimaryColumn({
|
|
206
|
+
nullable: false
|
|
207
|
+
}),
|
|
208
|
+
_ts_metadata("design:type", String)
|
|
209
|
+
], DidConfigurationResourceEntity.prototype, "origin", void 0);
|
|
210
|
+
_ts_decorate([
|
|
211
|
+
Column({
|
|
212
|
+
nullable: false
|
|
213
|
+
}),
|
|
214
|
+
_ts_metadata("design:type", String)
|
|
215
|
+
], DidConfigurationResourceEntity.prototype, "context", void 0);
|
|
216
|
+
_ts_decorate([
|
|
217
|
+
ManyToMany(() => Credential, (credential) => credential.hash, {
|
|
218
|
+
nullable: false,
|
|
219
|
+
cascade: true,
|
|
220
|
+
onDelete: "NO ACTION"
|
|
221
|
+
}),
|
|
222
|
+
JoinTable({
|
|
223
|
+
name: "DidConfigurationResourceCredentials"
|
|
224
|
+
}),
|
|
225
|
+
_ts_metadata("design:type", typeof Array === "undefined" ? Object : Array)
|
|
226
|
+
], DidConfigurationResourceEntity.prototype, "linkedDids", void 0);
|
|
227
|
+
_ts_decorate([
|
|
228
|
+
CreateDateColumn({
|
|
229
|
+
name: "created_at",
|
|
230
|
+
nullable: false
|
|
231
|
+
}),
|
|
232
|
+
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
233
|
+
], DidConfigurationResourceEntity.prototype, "createdAt", void 0);
|
|
234
|
+
_ts_decorate([
|
|
235
|
+
UpdateDateColumn({
|
|
236
|
+
name: "last_updated_at",
|
|
237
|
+
nullable: false
|
|
238
|
+
}),
|
|
239
|
+
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
240
|
+
], DidConfigurationResourceEntity.prototype, "lastUpdatedAt", void 0);
|
|
241
|
+
DidConfigurationResourceEntity = _ts_decorate([
|
|
242
|
+
Entity("DidConfigurationResource")
|
|
243
|
+
], DidConfigurationResourceEntity);
|
|
244
|
+
var didConfigurationResourceFrom = /* @__PURE__ */ __name((didConfigurationResource) => {
|
|
245
|
+
return {
|
|
246
|
+
"@context": didConfigurationResource.context,
|
|
247
|
+
linked_dids: linkedDidsFrom(didConfigurationResource.linkedDids)
|
|
248
|
+
};
|
|
249
|
+
}, "didConfigurationResourceFrom");
|
|
250
|
+
var linkedDidsFrom = /* @__PURE__ */ __name((credentials) => {
|
|
251
|
+
return credentials.map((credential) => credential?.raw?.proof?.type === "JwtProof2020" && typeof credential?.raw?.proof?.jwt === "string" ? credential.raw.proof.jwt : credential.raw);
|
|
252
|
+
}, "linkedDidsFrom");
|
|
253
|
+
var createCredentialEntity = /* @__PURE__ */ __name((vci) => {
|
|
254
|
+
const vc = vci;
|
|
255
|
+
const credential = new Credential();
|
|
256
|
+
credential.context = asArray(vc["@context"]);
|
|
257
|
+
credential.type = asArray(vc.type || []);
|
|
258
|
+
credential.id = vc.id;
|
|
259
|
+
if (vc.issuanceDate) {
|
|
260
|
+
credential.issuanceDate = new Date(vc.issuanceDate);
|
|
261
|
+
}
|
|
262
|
+
if (vc.expirationDate) {
|
|
263
|
+
credential.expirationDate = new Date(vc.expirationDate);
|
|
264
|
+
}
|
|
265
|
+
const issuer = new Identifier();
|
|
266
|
+
issuer.did = extractIssuer(vc);
|
|
267
|
+
credential.issuer = issuer;
|
|
268
|
+
if (vc.credentialSubject.id) {
|
|
269
|
+
const subject = new Identifier();
|
|
270
|
+
subject.did = vc.credentialSubject.id;
|
|
271
|
+
credential.subject = subject;
|
|
272
|
+
}
|
|
273
|
+
credential.claims = [];
|
|
274
|
+
for (const type in vc.credentialSubject) {
|
|
275
|
+
if (vc.credentialSubject.hasOwnProperty(type)) {
|
|
276
|
+
const value = vc.credentialSubject[type];
|
|
277
|
+
if (type !== "id") {
|
|
278
|
+
const isObj = typeof value === "function" || typeof value === "object" && !!value;
|
|
279
|
+
const claim = new Claim();
|
|
280
|
+
claim.hash = computeEntryHash(JSON.stringify(vc) + type);
|
|
281
|
+
claim.type = type;
|
|
282
|
+
claim.value = isObj ? JSON.stringify(value) : value;
|
|
283
|
+
claim.isObj = isObj;
|
|
284
|
+
claim.issuer = credential.issuer;
|
|
285
|
+
claim.subject = credential.subject;
|
|
286
|
+
claim.expirationDate = credential.expirationDate;
|
|
287
|
+
claim.issuanceDate = credential.issuanceDate;
|
|
288
|
+
claim.credentialType = credential.type;
|
|
289
|
+
claim.context = credential.context;
|
|
290
|
+
credential.claims.push(claim);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
credential.raw = vci;
|
|
295
|
+
return credential;
|
|
296
|
+
}, "createCredentialEntity");
|
|
297
|
+
|
|
298
|
+
// src/agent/WellKnownDidIssuer.ts
|
|
299
|
+
import { CredentialCorrelationType, CredentialRole } from "@sphereon/ssi-sdk.credential-store";
|
|
300
|
+
import { CredentialMapper, parseDid } from "@sphereon/ssi-types";
|
|
301
|
+
import { ServiceTypesEnum, WellKnownDidIssuer as Issuer } from "@sphereon/wellknown-dids-client";
|
|
302
|
+
import { normalizeCredential } from "did-jwt-vc";
|
|
303
|
+
import { v4 as uuidv4 } from "uuid";
|
|
304
|
+
import { RegulationType } from "@sphereon/ssi-sdk.data-store";
|
|
305
|
+
var WellKnownDidIssuer = class {
|
|
306
|
+
static {
|
|
307
|
+
__name(this, "WellKnownDidIssuer");
|
|
308
|
+
}
|
|
309
|
+
dbConnection;
|
|
310
|
+
schema;
|
|
311
|
+
methods;
|
|
312
|
+
credentialIssuances;
|
|
313
|
+
didConfigurationResourceRelations;
|
|
314
|
+
constructor(dbConnection, args) {
|
|
315
|
+
this.dbConnection = dbConnection;
|
|
316
|
+
this.schema = schema.IWellKnownDidVerifier;
|
|
317
|
+
this.methods = {
|
|
318
|
+
addLinkedDomainsService: this.addLinkedDomainsService.bind(this),
|
|
319
|
+
getDidConfigurationResource: this.getDidConfigurationResource.bind(this),
|
|
320
|
+
issueDidConfigurationResource: this.issueDidConfigurationResource.bind(this),
|
|
321
|
+
issueDomainLinkageCredential: this.issueDomainLinkageCredential.bind(this),
|
|
322
|
+
registerCredentialIssuance: this.registerCredentialIssuance.bind(this),
|
|
323
|
+
removeCredentialIssuance: this.removeCredentialIssuance.bind(this),
|
|
324
|
+
saveDidConfigurationResource: this.saveDidConfigurationResource.bind(this)
|
|
325
|
+
};
|
|
326
|
+
this.didConfigurationResourceRelations = [
|
|
327
|
+
"linkedDids"
|
|
328
|
+
];
|
|
329
|
+
this.credentialIssuances = args && args.credentialIssuances || {};
|
|
330
|
+
}
|
|
331
|
+
/** {@inheritDoc IWellKnownDidIssuer.registerSignatureVerification} */
|
|
332
|
+
async registerCredentialIssuance(args, context) {
|
|
333
|
+
if (this.credentialIssuances[args.callbackName] !== void 0) {
|
|
334
|
+
return Promise.reject(new Error(`Credential issuance with callbackName: ${args.callbackName} already present`));
|
|
335
|
+
}
|
|
336
|
+
this.credentialIssuances[args.callbackName] = args.credentialIssuance;
|
|
337
|
+
}
|
|
338
|
+
/** {@inheritDoc IWellKnownDidIssuer.removeSignatureVerification} */
|
|
339
|
+
async removeCredentialIssuance(args, context) {
|
|
340
|
+
return delete this.credentialIssuances[args.callbackName];
|
|
341
|
+
}
|
|
342
|
+
/** {@inheritDoc IWellKnownDidIssuer.issueDidConfigurationResource} */
|
|
343
|
+
async issueDidConfigurationResource(args, context) {
|
|
344
|
+
if (!args.issuances.every((issuance) => issuance.origin === args.issuances[0].origin)) {
|
|
345
|
+
return Promise.reject(Error("All verifiableCredentials should be issued for the same origin"));
|
|
346
|
+
}
|
|
347
|
+
const addServices = args.issuances.map((issuance) => this.addLinkedDomainsService({
|
|
348
|
+
did: issuance.did,
|
|
349
|
+
origin: issuance.origin,
|
|
350
|
+
serviceId: issuance.serviceId
|
|
351
|
+
}, context));
|
|
352
|
+
return Promise.all(addServices).then(async () => new Issuer().issueDidConfigurationResource({
|
|
353
|
+
issuances: await this.mapIssuances(args.issuances),
|
|
354
|
+
issueCallback: typeof args.credentialIssuance === "string" ? await this.getCredentialIssuance(args.credentialIssuance) : args.credentialIssuance
|
|
355
|
+
}).then(async (didConfigurationResource) => {
|
|
356
|
+
if (args.save) {
|
|
357
|
+
await this.saveDidConfigurationResource({
|
|
358
|
+
origin: args.issuances[0].origin,
|
|
359
|
+
didConfigurationResource
|
|
360
|
+
}, context);
|
|
361
|
+
}
|
|
362
|
+
return didConfigurationResource;
|
|
363
|
+
}).catch((error) => Promise.reject(Error(`Unable to issue DID configuration resource. Error: ${error.message}`))));
|
|
364
|
+
}
|
|
365
|
+
/** {@inheritDoc IWellKnownDidIssuer.saveDidConfigurationResource} */
|
|
366
|
+
async saveDidConfigurationResource(args, context) {
|
|
367
|
+
const didConfigurationEntity = {
|
|
368
|
+
origin: args.origin,
|
|
369
|
+
context: args.didConfigurationResource["@context"],
|
|
370
|
+
linkedDids: args.didConfigurationResource.linked_dids.map((credential) => createCredentialEntity(this.normalizeCredential(credential)))
|
|
371
|
+
};
|
|
372
|
+
await (await this.dbConnection).getRepository(DidConfigurationResourceEntity).save(didConfigurationEntity, {
|
|
373
|
+
transaction: true
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
/** {@inheritDoc IWellKnownDidIssuer.getDidConfigurationResource} */
|
|
377
|
+
async getDidConfigurationResource(args, context) {
|
|
378
|
+
const result = await (await this.dbConnection).getRepository(DidConfigurationResourceEntity).findOne({
|
|
379
|
+
where: {
|
|
380
|
+
origin: args.origin
|
|
381
|
+
},
|
|
382
|
+
relations: this.didConfigurationResourceRelations
|
|
383
|
+
});
|
|
384
|
+
if (!result) {
|
|
385
|
+
return Promise.reject(Error(`No DID configuration resource found for origin: ${args.origin}`));
|
|
386
|
+
}
|
|
387
|
+
return didConfigurationResourceFrom(result);
|
|
388
|
+
}
|
|
389
|
+
/** {@inheritDoc IWellKnownDidIssuer.issueDomainLinkageCredential} */
|
|
390
|
+
async issueDomainLinkageCredential(args, context) {
|
|
391
|
+
const did = parseDid(args.did).did;
|
|
392
|
+
if (new URL(args.origin).origin !== args.origin) {
|
|
393
|
+
return Promise.reject(Error(`Origin ${args.origin} is not valid`));
|
|
394
|
+
}
|
|
395
|
+
if (new URL(args.origin).protocol !== "https:") {
|
|
396
|
+
return Promise.reject(Error(`Origin ${args.origin} is not a https URL`));
|
|
397
|
+
}
|
|
398
|
+
if (args.issuanceDate && isNaN(Date.parse(args.issuanceDate))) {
|
|
399
|
+
return Promise.reject(Error(`IssuanceDate ${args.issuanceDate} is not a valid date`));
|
|
400
|
+
}
|
|
401
|
+
if (isNaN(Date.parse(args.expirationDate))) {
|
|
402
|
+
return Promise.reject(Error(`ExpirationDate ${args.expirationDate} is not a valid date`));
|
|
403
|
+
}
|
|
404
|
+
const credentialIssuance = typeof args.credentialIssuance === "string" ? await this.getCredentialIssuance(args.credentialIssuance) : args.credentialIssuance;
|
|
405
|
+
return new Issuer().issueDomainLinkageCredential({
|
|
406
|
+
did,
|
|
407
|
+
origin: args.origin,
|
|
408
|
+
issuanceDate: args.issuanceDate,
|
|
409
|
+
expirationDate: args.expirationDate,
|
|
410
|
+
options: args.options,
|
|
411
|
+
issueCallback: credentialIssuance
|
|
412
|
+
}).then(async (credential) => {
|
|
413
|
+
if (args.save) {
|
|
414
|
+
await this.saveDomainLinkageCredential(credential, context);
|
|
415
|
+
}
|
|
416
|
+
return credential;
|
|
417
|
+
}).catch((error) => Promise.reject(Error(`Unable to issue domain linkage credential for DID: ${did}. Error: ${error.message}`)));
|
|
418
|
+
}
|
|
419
|
+
/** {@inheritDoc IWellKnownDidIssuer.addLinkedDomainsService} */
|
|
420
|
+
async addLinkedDomainsService(args, context) {
|
|
421
|
+
const did = parseDid(args.did).did;
|
|
422
|
+
if (new URL(args.origin).origin !== args.origin) {
|
|
423
|
+
return Promise.reject(Error(`Origin ${args.origin} is not valid`));
|
|
424
|
+
}
|
|
425
|
+
if (new URL(args.origin).protocol !== "https:") {
|
|
426
|
+
return Promise.reject(Error(`Origin ${args.origin} is not a https URL`));
|
|
427
|
+
}
|
|
428
|
+
context.agent.didManagerGet({
|
|
429
|
+
did
|
|
430
|
+
}).catch(() => Promise.reject(Error("DID cannot be found"))).then(async (identifier) => {
|
|
431
|
+
if (!identifier.services || identifier.services.filter(
|
|
432
|
+
// TODO we should also check for the origins in the serviceEndpoint objects when we start supporting multiple origins
|
|
433
|
+
(service) => service.type === ServiceTypesEnum.LINKED_DOMAINS && service.serviceEndpoint === args.origin
|
|
434
|
+
).length === 0) {
|
|
435
|
+
await context.agent.didManagerAddService({
|
|
436
|
+
did: identifier.did,
|
|
437
|
+
service: {
|
|
438
|
+
id: args.serviceId || uuidv4(),
|
|
439
|
+
type: ServiceTypesEnum.LINKED_DOMAINS,
|
|
440
|
+
// TODO We should support a serviceEndpoint object here when we update to Veramo 3.1.6.next-165 or higher, as then we can support multiple origins
|
|
441
|
+
serviceEndpoint: args.origin
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
}).catch((error) => Promise.reject(Error(`Unable to add LinkedDomains service to DID: ${args.did}. Error: ${error.message}`)));
|
|
446
|
+
}
|
|
447
|
+
async getCredentialIssuance(callbackName) {
|
|
448
|
+
if (this.credentialIssuances[callbackName] === void 0) {
|
|
449
|
+
return Promise.reject(new Error(`Credential issuance not found for callbackName: ${callbackName}`));
|
|
450
|
+
}
|
|
451
|
+
return this.credentialIssuances[callbackName];
|
|
452
|
+
}
|
|
453
|
+
async saveDomainLinkageCredential(credential, context) {
|
|
454
|
+
const vc = this.normalizeCredential(credential);
|
|
455
|
+
return context.agent.crsAddCredential({
|
|
456
|
+
credential: {
|
|
457
|
+
rawDocument: JSON.stringify(vc),
|
|
458
|
+
credentialRole: CredentialRole.ISSUER,
|
|
459
|
+
regulationType: RegulationType.NON_REGULATED,
|
|
460
|
+
kmsKeyRef: "FIXME",
|
|
461
|
+
identifierMethod: "did",
|
|
462
|
+
issuerCorrelationId: CredentialMapper.issuerCorrelationIdFromIssuerType(vc.issuer),
|
|
463
|
+
issuerCorrelationType: CredentialCorrelationType.DID,
|
|
464
|
+
subjectCorrelationId: CredentialMapper.issuerCorrelationIdFromIssuerType(vc.issuer),
|
|
465
|
+
subjectCorrelationType: CredentialCorrelationType.DID
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
normalizeCredential(credential) {
|
|
470
|
+
return typeof credential === "string" ? normalizeCredential(credential) : credential;
|
|
471
|
+
}
|
|
472
|
+
async mapIssuances(issuances) {
|
|
473
|
+
const promises = issuances.map(async (issuance) => {
|
|
474
|
+
return {
|
|
475
|
+
...issuance,
|
|
476
|
+
issueCallback: typeof issuance.credentialIssuance === "string" ? await this.getCredentialIssuance(issuance.credentialIssuance) : issuance.credentialIssuance
|
|
477
|
+
};
|
|
478
|
+
});
|
|
479
|
+
return Promise.all(promises);
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
// src/migrations/generic/1-CreateWellknownDidIssuer.ts
|
|
484
|
+
import Debug from "debug";
|
|
485
|
+
|
|
486
|
+
// src/migrations/postgres/1661165115000-CreateWellknownDidIssuer.ts
|
|
487
|
+
var CreateWellknownDidIssuer1661165115000 = class {
|
|
488
|
+
static {
|
|
489
|
+
__name(this, "CreateWellknownDidIssuer1661165115000");
|
|
490
|
+
}
|
|
491
|
+
name = "CreateWellknownDidIssuer1661165115000";
|
|
492
|
+
async up(queryRunner) {
|
|
493
|
+
await queryRunner.query(`CREATE TABLE "DidConfigurationResource" ("origin" varchar NOT NULL, "context" varchar NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_Origin" PRIMARY KEY ("origin"))`);
|
|
494
|
+
await queryRunner.query(`CREATE TABLE "DidConfigurationResourceCredentials" ("didConfigurationResourceOrigin" varchar NOT NULL, "credentialHash" varchar NOT NULL)`);
|
|
495
|
+
}
|
|
496
|
+
async down(queryRunner) {
|
|
497
|
+
await queryRunner.query(`DROP TABLE "DidConfigurationResource"`);
|
|
498
|
+
await queryRunner.query(`DROP TABLE "DidConfigurationResourceCredentials"`);
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
// src/migrations/sqlite/1661161799000-CreateWellknownDidIssuer.ts
|
|
503
|
+
var CreateWellknownDidIssuer1661161799000 = class {
|
|
504
|
+
static {
|
|
505
|
+
__name(this, "CreateWellknownDidIssuer1661161799000");
|
|
506
|
+
}
|
|
507
|
+
name = "CreateWellknownDidIssuer1661161799000";
|
|
508
|
+
async up(queryRunner) {
|
|
509
|
+
await queryRunner.query(`CREATE TABLE "DidConfigurationResource" ("origin" varchar PRIMARY KEY NOT NULL, "context" varchar NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')))`);
|
|
510
|
+
await queryRunner.query(`CREATE TABLE "DidConfigurationResourceCredentials" ("didConfigurationResourceOrigin" varchar NOT NULL, "credentialHash" varchar NOT NULL)`);
|
|
511
|
+
}
|
|
512
|
+
async down(queryRunner) {
|
|
513
|
+
await queryRunner.query(`DROP TABLE "DidConfigurationResource"`);
|
|
514
|
+
await queryRunner.query(`DROP TABLE "DidConfigurationResourceCredentials"`);
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
// src/migrations/generic/1-CreateWellknownDidIssuer.ts
|
|
519
|
+
var debug = Debug("sphereon:ssi-sdk:migrations");
|
|
520
|
+
var CreateWellknownDidIssuer1661162010000 = class {
|
|
521
|
+
static {
|
|
522
|
+
__name(this, "CreateWellknownDidIssuer1661162010000");
|
|
523
|
+
}
|
|
524
|
+
name = "CreateWellknownDidIssuer1661162010000";
|
|
525
|
+
async up(queryRunner) {
|
|
526
|
+
debug("migration: creating well-known DID tables");
|
|
527
|
+
const dbType = queryRunner.connection.driver.options.type;
|
|
528
|
+
if (dbType === "postgres") {
|
|
529
|
+
debug("using postgres migration file");
|
|
530
|
+
const mig = new CreateWellknownDidIssuer1661165115000();
|
|
531
|
+
const up = await mig.up(queryRunner);
|
|
532
|
+
debug("Migration statements executed");
|
|
533
|
+
return up;
|
|
534
|
+
} else if (dbType === "sqlite" || dbType === "react-native" || dbType === "expo") {
|
|
535
|
+
debug("using sqlite/react-native migration file");
|
|
536
|
+
const mig = new CreateWellknownDidIssuer1661161799000();
|
|
537
|
+
const up = await mig.up(queryRunner);
|
|
538
|
+
debug("Migration statements executed");
|
|
539
|
+
return up;
|
|
540
|
+
} else {
|
|
541
|
+
return Promise.reject(`Migrations are currently only supported for sqlite, react-native, expor and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
async down(queryRunner) {
|
|
545
|
+
debug("reverting well-known DID tables");
|
|
546
|
+
const dbType = queryRunner.connection.driver.options.type;
|
|
547
|
+
if (dbType === "postgres") {
|
|
548
|
+
debug("using postgres migration file");
|
|
549
|
+
const mig = new CreateWellknownDidIssuer1661165115000();
|
|
550
|
+
const down = await mig.down(queryRunner);
|
|
551
|
+
debug("Migration statements executed");
|
|
552
|
+
return down;
|
|
553
|
+
} else if (dbType === "sqlite" || dbType === "react-native" || dbType === "expo") {
|
|
554
|
+
debug("using sqlite/react-native migration file");
|
|
555
|
+
const mig = new CreateWellknownDidIssuer1661161799000();
|
|
556
|
+
const down = await mig.down(queryRunner);
|
|
557
|
+
debug("Migration statements executed");
|
|
558
|
+
return down;
|
|
559
|
+
} else {
|
|
560
|
+
return Promise.reject(`Migrations are currently only supported for sqlite, react-native, expor and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
// src/migrations/generic/index.ts
|
|
566
|
+
var WellknownDidIssuerMigrations = [
|
|
567
|
+
CreateWellknownDidIssuer1661162010000
|
|
568
|
+
];
|
|
569
|
+
|
|
570
|
+
// src/index.ts
|
|
571
|
+
var schema = require_plugin_schema();
|
|
572
|
+
var WellknownDidIssuerEntities = [
|
|
573
|
+
DidConfigurationResourceEntity
|
|
574
|
+
];
|
|
575
|
+
export {
|
|
576
|
+
DidConfigurationResourceEntity,
|
|
577
|
+
WellKnownDidIssuer,
|
|
578
|
+
WellknownDidIssuerEntities,
|
|
579
|
+
WellknownDidIssuerMigrations,
|
|
580
|
+
schema
|
|
581
|
+
};
|
|
12
582
|
//# sourceMappingURL=index.js.map
|