@agent-network-protocol/anp-identity 0.2.0-dsh-test.20260831.1
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 -0
- package/NOTICE.md +3 -0
- package/README.md +71 -0
- package/SOURCE.md +5 -0
- package/checksums.json +53 -0
- package/index.d.ts +342 -0
- package/index.js +406 -0
- package/native.cjs +724 -0
- package/package.json +69 -0
- package/provenance.json +19 -0
- package/provider.d.ts +384 -0
- package/provider.js +774 -0
- package/sbom.cdx.json +3148 -0
package/provider.js
ADDED
|
@@ -0,0 +1,774 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const native = require('./native.cjs')
|
|
4
|
+
|
|
5
|
+
async function call(operation) {
|
|
6
|
+
try {
|
|
7
|
+
return await operation
|
|
8
|
+
} catch (error) {
|
|
9
|
+
const match = /ANP_IDENTITY_CODE:([^:]+):(.*)$/s.exec(String(error.message))
|
|
10
|
+
if (match) {
|
|
11
|
+
error.code = match[1]
|
|
12
|
+
error.message = match[2]
|
|
13
|
+
}
|
|
14
|
+
throw error
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function callSync(operation) {
|
|
19
|
+
try {
|
|
20
|
+
return operation()
|
|
21
|
+
} catch (error) {
|
|
22
|
+
const match = /ANP_IDENTITY_CODE:([^:]+):(.*)$/s.exec(String(error.message))
|
|
23
|
+
if (match) {
|
|
24
|
+
error.code = match[1]
|
|
25
|
+
error.message = match[2]
|
|
26
|
+
}
|
|
27
|
+
throw error
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
class IdentityProvider {
|
|
32
|
+
#inner
|
|
33
|
+
|
|
34
|
+
constructor(inner) {
|
|
35
|
+
this.#inner = inner
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static async initialize(config) {
|
|
39
|
+
return new IdentityProvider(await call(native.IdentityProvider.initialize(config)))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static async open(config) {
|
|
43
|
+
return new IdentityProvider(await call(native.IdentityProvider.open(config)))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
acquireLease(request) {
|
|
47
|
+
return new ProviderLease(callSync(() => this.#inner.acquireLease(request)))
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
class ProviderLease {
|
|
52
|
+
#inner
|
|
53
|
+
|
|
54
|
+
constructor(inner) {
|
|
55
|
+
this.#inner = inner
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
dispose() {
|
|
59
|
+
return this.#inner.dispose()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async info() {
|
|
63
|
+
const value = await call(this.#inner.info())
|
|
64
|
+
return {
|
|
65
|
+
storeId: value.store_id,
|
|
66
|
+
schemaCompatible: value.schema_compatible,
|
|
67
|
+
identityCount: value.identity_count,
|
|
68
|
+
health: value.health,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async recover() {
|
|
73
|
+
const value = await call(this.#inner.recover())
|
|
74
|
+
return { identityCount: value.identity_count }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async list() {
|
|
78
|
+
return (await call(this.#inner.list())).map(identityDescriptor)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async publicIdentity(reference) {
|
|
82
|
+
return publicIdentity(await call(this.#inner.publicIdentity(reference)))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async hostStatus(reference) {
|
|
86
|
+
const value = await call(this.#inner.hostStatus(reference))
|
|
87
|
+
return {
|
|
88
|
+
rootCapability: value.root_capability,
|
|
89
|
+
rootKeyFingerprint: value.root_key_fingerprint,
|
|
90
|
+
checkpoint: value.checkpoint == null ? undefined : checkpoint(value.checkpoint),
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
recoverIdentity(reference) {
|
|
95
|
+
return call(this.#inner.recoverIdentity(reference))
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async create(request) {
|
|
99
|
+
return publicIdentity(await call(this.#inner.create(createRequest(request))))
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
delete(reference) {
|
|
103
|
+
return call(this.#inner.delete(reference))
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
verify(reference, request) {
|
|
107
|
+
return call(this.#inner.verify(reference, request))
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
sign(reference, request) {
|
|
111
|
+
return call(this.#inner.sign(reference, request))
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
signOriginProof(reference, request) {
|
|
115
|
+
return call(this.#inner.signOriginProof(reference, request))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
signObjectProof(reference, request) {
|
|
119
|
+
return call(this.#inner.signObjectProof(reference, proofRequest(request)))
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
signDocumentProof(reference, request) {
|
|
123
|
+
return call(this.#inner.signDocumentProof(reference, documentProofRequest(request)))
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async prepareHttpSignature(request) {
|
|
127
|
+
return httpAttempt(await call(this.#inner.prepareHttpSignature(request)))
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
prepareLegacyDidWba(reference, request) {
|
|
131
|
+
return call(
|
|
132
|
+
this.#inner.prepareLegacyDidWba(
|
|
133
|
+
reference,
|
|
134
|
+
request.kid,
|
|
135
|
+
request.serviceDomain,
|
|
136
|
+
request.version,
|
|
137
|
+
),
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async prepareDocumentChange(reference, request) {
|
|
142
|
+
return new ProviderDocumentChangeSession(
|
|
143
|
+
await call(
|
|
144
|
+
this.#inner.prepareDocumentChange(reference, documentChangeRequest(request)),
|
|
145
|
+
),
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async resumeDocumentChange(reference) {
|
|
150
|
+
const session = await call(this.#inner.resumeDocumentChange(reference))
|
|
151
|
+
return session == null ? undefined : new ProviderDocumentChangeSession(session)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async prepareIdentityTransition(request) {
|
|
155
|
+
return new ProviderIdentityTransitionSession(
|
|
156
|
+
await call(this.#inner.prepareIdentityTransition(identityTransitionRequest(request))),
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async resumeIdentityTransition(expectedCurrentDid) {
|
|
161
|
+
const session = await call(this.#inner.resumeIdentityTransition(expectedCurrentDid))
|
|
162
|
+
return session == null ? undefined : new ProviderIdentityTransitionSession(session)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
adoptVerifiedDocument(reference, remote) {
|
|
166
|
+
return call(this.#inner.adoptVerifiedDocument(reference, verifiedRemoteDocument(remote)))
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async beginDeviceEnrollment(request) {
|
|
170
|
+
return new ProviderEnrollmentSession(
|
|
171
|
+
await call(this.#inner.beginDeviceEnrollment(deviceEnrollmentRequest(request))),
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async beginRequestSigningEnrollment(request) {
|
|
176
|
+
return new ProviderEnrollmentSession(
|
|
177
|
+
await call(
|
|
178
|
+
this.#inner.beginRequestSigningEnrollment(requestSigningEnrollmentRequest(request)),
|
|
179
|
+
),
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async resumeEnrollment(reference) {
|
|
184
|
+
const session = await call(this.#inner.resumeEnrollment(reference))
|
|
185
|
+
return session == null ? undefined : new ProviderEnrollmentSession(session)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
importWrappedRoot(reference, envelope) {
|
|
189
|
+
return call(this.#inner.importWrappedRoot(reference, wrappedRootEnvelope(envelope)))
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
confirmRootPromotion(reference, request) {
|
|
193
|
+
return call(
|
|
194
|
+
this.#inner.confirmRootPromotion(reference, {
|
|
195
|
+
remote: verifiedRemoteDocument(request.remote),
|
|
196
|
+
}),
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
signPendingRootObjectProof(reference, request) {
|
|
201
|
+
return call(this.#inner.signPendingRootObjectProof(reference, proofRequest(request)))
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async ecdhSealed(request) {
|
|
205
|
+
return sealedDelivery(await call(this.#inner.ecdhSealed(request)))
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async exportRootKeySealed(request) {
|
|
209
|
+
return sealedDelivery(await call(this.#inner.exportRootKeySealed(request)))
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async prepareLegacyRootImport(request) {
|
|
213
|
+
const prepared = await call(
|
|
214
|
+
this.#inner.prepareLegacyRootImport({
|
|
215
|
+
...request,
|
|
216
|
+
evidence: rootImportEvidence(request.evidence),
|
|
217
|
+
}),
|
|
218
|
+
)
|
|
219
|
+
return new PreparedRootImport(prepared)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
async prepareIdentityMaterialImport(request) {
|
|
223
|
+
const prepared = await call(
|
|
224
|
+
this.#inner.prepareIdentityMaterialImport({
|
|
225
|
+
remote: verifiedRemoteDocument(request.remote),
|
|
226
|
+
didWba: request.didWba,
|
|
227
|
+
keys: request.keys.map((key) => ({
|
|
228
|
+
kid: key.kid,
|
|
229
|
+
purpose: key.purpose,
|
|
230
|
+
encoding: key.encoding,
|
|
231
|
+
})),
|
|
232
|
+
requestId: request.requestId,
|
|
233
|
+
}),
|
|
234
|
+
)
|
|
235
|
+
return new PreparedIdentityMaterialImport(prepared)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
class ProviderDocumentChangeSession {
|
|
241
|
+
#inner
|
|
242
|
+
|
|
243
|
+
constructor(inner) {
|
|
244
|
+
this.#inner = inner
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async candidate() {
|
|
248
|
+
return preparedChange(await call(this.#inner.candidate()))
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
hostPhase() {
|
|
252
|
+
return call(this.#inner.hostPhase())
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async beginPublication() {
|
|
256
|
+
return publicationAttempt(await call(this.#inner.beginPublication()))
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async complete(attempt, result) {
|
|
260
|
+
return documentChangeOutcome(
|
|
261
|
+
await call(this.#inner.complete(nativePublicationAttempt(attempt), publicationResult(result))),
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async reconcile(observation) {
|
|
266
|
+
return documentChangeOutcome(
|
|
267
|
+
await call(this.#inner.reconcile(verifiedRemoteDocument(observation))),
|
|
268
|
+
)
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
class ProviderIdentityTransitionSession {
|
|
273
|
+
#inner
|
|
274
|
+
|
|
275
|
+
constructor(inner) {
|
|
276
|
+
this.#inner = inner
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
async candidate() {
|
|
280
|
+
return preparedIdentityTransition(await call(this.#inner.candidate()))
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async beginPublication() {
|
|
284
|
+
return identityTransitionAttempt(await call(this.#inner.beginPublication()))
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
async complete(attempt, result) {
|
|
288
|
+
return identityTransitionOutcome(
|
|
289
|
+
await call(
|
|
290
|
+
this.#inner.complete(
|
|
291
|
+
nativeIdentityTransitionAttempt(attempt),
|
|
292
|
+
identityTransitionPublicationResult(result),
|
|
293
|
+
),
|
|
294
|
+
),
|
|
295
|
+
)
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async reconcile(observation) {
|
|
299
|
+
return identityTransitionOutcome(
|
|
300
|
+
await call(this.#inner.reconcile(identityTransitionObservation(observation))),
|
|
301
|
+
)
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
class ProviderEnrollmentSession {
|
|
306
|
+
#inner
|
|
307
|
+
|
|
308
|
+
constructor(inner) {
|
|
309
|
+
this.#inner = inner
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
async proposal() {
|
|
313
|
+
return enrollmentProposal(await call(this.#inner.proposal()))
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
signDeviceAssertion(payload) {
|
|
317
|
+
return call(this.#inner.signDeviceAssertion(payload))
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
async deriveDeviceSharedSecretSealed(request) {
|
|
321
|
+
return sealedDelivery(await call(this.#inner.deriveDeviceSharedSecretSealed(request)))
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
activate(remote) {
|
|
325
|
+
return call(this.#inner.activate(verifiedRemoteDocument(remote)))
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
cancel() {
|
|
329
|
+
return call(this.#inner.cancel())
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
class PreparedRootImport {
|
|
334
|
+
#inner
|
|
335
|
+
|
|
336
|
+
constructor(inner) {
|
|
337
|
+
this.#inner = inner
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
offer() {
|
|
341
|
+
return importOffer(this.#inner.offer())
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
complete(token, envelope) {
|
|
345
|
+
return call(this.#inner.complete(token, nativeEnvelope(envelope)))
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
class PreparedIdentityMaterialImport {
|
|
350
|
+
#inner
|
|
351
|
+
|
|
352
|
+
constructor(inner) {
|
|
353
|
+
this.#inner = inner
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
offer() {
|
|
357
|
+
const value = this.#inner.offer()
|
|
358
|
+
return {
|
|
359
|
+
target: identityReference(value.target),
|
|
360
|
+
recipientPublicKey: Buffer.from(value.recipient_public_key),
|
|
361
|
+
requestId: value.request_id,
|
|
362
|
+
token: value.token,
|
|
363
|
+
authorization: authorizationContext(value.authorization),
|
|
364
|
+
itemAad: value.item_aad_b64u,
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
async complete(token, envelopes) {
|
|
369
|
+
return publicIdentity(
|
|
370
|
+
await call(this.#inner.complete(token, envelopes.map(nativeEnvelope))),
|
|
371
|
+
)
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function importOffer(value) {
|
|
376
|
+
return {
|
|
377
|
+
recipientPublicKey: Buffer.from(value.recipient_public_key),
|
|
378
|
+
requestId: value.request_id,
|
|
379
|
+
token: value.token,
|
|
380
|
+
authorization: authorizationContext(value.authorization),
|
|
381
|
+
aad: value.aad_b64u,
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function authorizationContext(value) {
|
|
386
|
+
return {
|
|
387
|
+
providerInstanceId: value.provider_instance_id,
|
|
388
|
+
parentLeaseId: value.parent_lease_id,
|
|
389
|
+
consumer: value.consumer,
|
|
390
|
+
capability: value.capability,
|
|
391
|
+
storeId: value.store_id,
|
|
392
|
+
expiresAt: value.expires_at,
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function sealedEnvelope(value) {
|
|
397
|
+
return {
|
|
398
|
+
protocol: value.protocol,
|
|
399
|
+
suite: value.suite,
|
|
400
|
+
encappedKey: value.encapped_key_b64u,
|
|
401
|
+
ciphertext: value.ciphertext_b64u,
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function sealedDelivery(value) {
|
|
406
|
+
return {
|
|
407
|
+
envelope: sealedEnvelope(value.envelope),
|
|
408
|
+
authorization: authorizationContext(value.authorization),
|
|
409
|
+
aad: value.aad,
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function nativeEnvelope(value) {
|
|
414
|
+
return {
|
|
415
|
+
protocol: value.protocol,
|
|
416
|
+
suite: value.suite,
|
|
417
|
+
encapped_key_b64u: value.encappedKey,
|
|
418
|
+
ciphertext_b64u: value.ciphertext,
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function httpAttempt(value) {
|
|
423
|
+
return {
|
|
424
|
+
bindingDigest: value.binding_digest,
|
|
425
|
+
kid: value.kid,
|
|
426
|
+
headerPatch: value.header_patch,
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function rootImportEvidence(value) {
|
|
431
|
+
return {
|
|
432
|
+
transfer_id: value.transferId,
|
|
433
|
+
source_did: value.sourceDid,
|
|
434
|
+
target_did: value.targetDid,
|
|
435
|
+
sender_device_id: value.senderDeviceId,
|
|
436
|
+
recipient_device_id: value.recipientDeviceId,
|
|
437
|
+
recipient_agreement_kid: value.recipientAgreementKid,
|
|
438
|
+
root_kid: value.rootKid,
|
|
439
|
+
checkpoint: {
|
|
440
|
+
document_version: value.checkpoint.documentVersion,
|
|
441
|
+
registry_version: value.checkpoint.registryVersion,
|
|
442
|
+
document_digest: value.checkpoint.documentDigest,
|
|
443
|
+
},
|
|
444
|
+
accepted_at: value.acceptedAt,
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function verifiedRemoteDocument(value) {
|
|
449
|
+
return {
|
|
450
|
+
document: value.document,
|
|
451
|
+
evidence: {
|
|
452
|
+
document_version: value.evidence.documentVersion,
|
|
453
|
+
registry_version: value.evidence.registryVersion,
|
|
454
|
+
document_digest: value.evidence.documentDigest,
|
|
455
|
+
},
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function checkpoint(value) {
|
|
460
|
+
return {
|
|
461
|
+
documentVersion: value.document_version,
|
|
462
|
+
registryVersion: value.registry_version,
|
|
463
|
+
documentDigest: value.document_digest,
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function identityDescriptor(value) {
|
|
468
|
+
return { reference: identityReference(value.reference), state: value.state }
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function identityReference(value) {
|
|
472
|
+
return { storeId: value.store_id, identityId: value.identity_id, did: value.did }
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function publicIdentity(value) {
|
|
476
|
+
return {
|
|
477
|
+
reference: identityReference(value.reference),
|
|
478
|
+
state: value.state,
|
|
479
|
+
revision: value.revision,
|
|
480
|
+
document: value.document,
|
|
481
|
+
activeKeys: value.active_keys.map((key) => ({
|
|
482
|
+
kid: key.kid,
|
|
483
|
+
algorithm: key.algorithm,
|
|
484
|
+
purposes: key.purposes,
|
|
485
|
+
})),
|
|
486
|
+
capabilities: { didWba: value.capabilities.did_wba },
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function createRequest(value) {
|
|
491
|
+
return {
|
|
492
|
+
profile: value.profile,
|
|
493
|
+
domain: value.domain,
|
|
494
|
+
port: value.port,
|
|
495
|
+
path_segments: value.pathSegments,
|
|
496
|
+
capabilities: { did_wba: value.capabilities?.didWba ?? false },
|
|
497
|
+
managed_keys: value.managedKeys.map((key) => ({ fragment: key.fragment, role: key.role })),
|
|
498
|
+
external_keys: (value.externalKeys ?? []).map((key) => ({
|
|
499
|
+
kid: key.kid,
|
|
500
|
+
role: key.role,
|
|
501
|
+
material:
|
|
502
|
+
key.material.format === 'jwk'
|
|
503
|
+
? { format: 'jwk', public_key_jwk: key.material.publicKeyJwk }
|
|
504
|
+
: { format: 'multibase', value: key.material.value },
|
|
505
|
+
})),
|
|
506
|
+
services: (value.services ?? []).map(nativeService),
|
|
507
|
+
agent_description_url: value.agentDescriptionUrl,
|
|
508
|
+
extensions: (value.extensions ?? []).map((extension) => ({
|
|
509
|
+
type: extension.type,
|
|
510
|
+
value: {
|
|
511
|
+
devices: extension.value.devices.map((device) => ({
|
|
512
|
+
device_id: device.deviceId,
|
|
513
|
+
signing_key_id: device.signingKeyId,
|
|
514
|
+
e2ee_key_id: device.e2eeKeyId,
|
|
515
|
+
profiles: device.profiles ?? [],
|
|
516
|
+
})),
|
|
517
|
+
},
|
|
518
|
+
})),
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function documentChangeRequest(value) {
|
|
523
|
+
return {
|
|
524
|
+
changes: value.changes.map((entry) => {
|
|
525
|
+
switch (entry.change) {
|
|
526
|
+
case 'rotate_signing_key':
|
|
527
|
+
return { change: entry.change, old_kid: entry.oldKid, new_fragment: entry.newFragment }
|
|
528
|
+
case 'add_authentication_key':
|
|
529
|
+
return { change: entry.change, key: publicKeyInput(entry.key) }
|
|
530
|
+
case 'remove_authentication_key':
|
|
531
|
+
return { change: entry.change, kid: entry.kid }
|
|
532
|
+
case 'add_device':
|
|
533
|
+
return {
|
|
534
|
+
change: entry.change,
|
|
535
|
+
device: {
|
|
536
|
+
device_id: entry.device.deviceId,
|
|
537
|
+
signing_key: publicKeyInput(entry.device.signingKey),
|
|
538
|
+
agreement_key: publicKeyInput(entry.device.agreementKey),
|
|
539
|
+
profiles: entry.device.profiles ?? [],
|
|
540
|
+
},
|
|
541
|
+
}
|
|
542
|
+
case 'remove_device':
|
|
543
|
+
return { change: entry.change, device_id: entry.deviceId }
|
|
544
|
+
case 'replace_services':
|
|
545
|
+
return { change: entry.change, services: entry.services.map(nativeService) }
|
|
546
|
+
default:
|
|
547
|
+
return entry
|
|
548
|
+
}
|
|
549
|
+
}),
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
function publicKeyInput(value) {
|
|
554
|
+
return { kid: value.kid, public_key_multibase: value.publicKeyMultibase }
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function nativeService(value) {
|
|
558
|
+
return {
|
|
559
|
+
id: value.id,
|
|
560
|
+
service_type: value.serviceType,
|
|
561
|
+
service_endpoint: value.serviceEndpoint,
|
|
562
|
+
service_did: value.serviceDid,
|
|
563
|
+
profiles: value.profiles ?? [],
|
|
564
|
+
security_profiles: value.securityProfiles ?? [],
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function preparedChange(value) {
|
|
569
|
+
return {
|
|
570
|
+
operationId: value.operation_id,
|
|
571
|
+
candidateDocument: value.candidate_document,
|
|
572
|
+
candidateDigest: value.candidate_digest,
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
function publicationAttempt(value) {
|
|
577
|
+
return {
|
|
578
|
+
operationId: value.operation_id,
|
|
579
|
+
candidateDigest: value.candidate_digest,
|
|
580
|
+
publicationGeneration: value.publication_generation,
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
function nativePublicationAttempt(value) {
|
|
585
|
+
return {
|
|
586
|
+
operation_id: value.operationId,
|
|
587
|
+
candidate_digest: value.candidateDigest,
|
|
588
|
+
publication_generation: value.publicationGeneration,
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function publicationResult(value) {
|
|
593
|
+
if (value.result !== 'confirmed') return value
|
|
594
|
+
return {
|
|
595
|
+
result: 'confirmed',
|
|
596
|
+
evidence: {
|
|
597
|
+
document_version: value.evidence.documentVersion,
|
|
598
|
+
registry_version: value.evidence.registryVersion,
|
|
599
|
+
document_digest: value.evidence.documentDigest,
|
|
600
|
+
},
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function documentChangeOutcome(value) {
|
|
605
|
+
if (value.outcome !== 'committed') return value
|
|
606
|
+
return { outcome: 'committed', identity: publicIdentity(value.identity) }
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function identityTransitionRequest(value) {
|
|
610
|
+
return {
|
|
611
|
+
expected_current_did: value.expectedCurrentDid,
|
|
612
|
+
operation_id: value.operationId,
|
|
613
|
+
successor: {
|
|
614
|
+
store_id: value.successor.storeId,
|
|
615
|
+
identity_id: value.successor.identityId,
|
|
616
|
+
did: value.successor.did,
|
|
617
|
+
},
|
|
618
|
+
transition_document: value.transitionDocument,
|
|
619
|
+
provider_document: value.providerDocument,
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
function preparedIdentityTransition(value) {
|
|
624
|
+
return {
|
|
625
|
+
operationId: value.operation_id,
|
|
626
|
+
expectedCurrentDid: value.expected_current_did,
|
|
627
|
+
successorDid: value.successor_did,
|
|
628
|
+
predecessorDocument: value.predecessor_document,
|
|
629
|
+
successorDocument: value.successor_document,
|
|
630
|
+
predecessorDigest: value.predecessor_digest,
|
|
631
|
+
successorDigest: value.successor_digest,
|
|
632
|
+
assurance: value.assurance,
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
function identityTransitionAttempt(value) {
|
|
637
|
+
return {
|
|
638
|
+
operationId: value.operation_id,
|
|
639
|
+
predecessorDigest: value.predecessor_digest,
|
|
640
|
+
successorDigest: value.successor_digest,
|
|
641
|
+
publicationGeneration: value.publication_generation,
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function nativeIdentityTransitionAttempt(value) {
|
|
646
|
+
return {
|
|
647
|
+
operation_id: value.operationId,
|
|
648
|
+
predecessor_digest: value.predecessorDigest,
|
|
649
|
+
successor_digest: value.successorDigest,
|
|
650
|
+
publication_generation: value.publicationGeneration,
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
function identityTransitionPublicationResult(value) {
|
|
655
|
+
if (value.result !== 'confirmed') return value
|
|
656
|
+
return {
|
|
657
|
+
result: 'confirmed',
|
|
658
|
+
evidence: {
|
|
659
|
+
predecessor_digest: value.evidence.predecessorDigest,
|
|
660
|
+
successor_digest: value.evidence.successorDigest,
|
|
661
|
+
},
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
function identityTransitionObservation(value) {
|
|
666
|
+
if (value.observation === 'remote_old') {
|
|
667
|
+
return { observation: 'remote_old', current_document: value.currentDocument }
|
|
668
|
+
}
|
|
669
|
+
return {
|
|
670
|
+
observation: 'published',
|
|
671
|
+
predecessor_document: value.predecessorDocument,
|
|
672
|
+
successor_document: value.successorDocument,
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
function identityTransitionOutcome(value) {
|
|
677
|
+
if (value.outcome !== 'committed') return value
|
|
678
|
+
return { outcome: 'committed', currentDid: value.current_did }
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
function proofRequest(value) {
|
|
682
|
+
return {
|
|
683
|
+
key: value.kid == null ? 'default' : { kid: value.kid },
|
|
684
|
+
document: value.document,
|
|
685
|
+
issuer_did: value.issuerDid,
|
|
686
|
+
created: value.created,
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
function documentProofRequest(value) {
|
|
691
|
+
return {
|
|
692
|
+
key: value.kid == null ? 'default' : { kid: value.kid },
|
|
693
|
+
document: value.document,
|
|
694
|
+
options: {
|
|
695
|
+
proof_purpose: value.options?.proofPurpose,
|
|
696
|
+
proof_type: value.options?.proofType,
|
|
697
|
+
cryptosuite: value.options?.cryptosuite,
|
|
698
|
+
created: value.options?.created,
|
|
699
|
+
domain: value.options?.domain,
|
|
700
|
+
challenge: value.options?.challenge,
|
|
701
|
+
},
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
function deviceEnrollmentRequest(value) {
|
|
706
|
+
return {
|
|
707
|
+
remote: verifiedRemoteDocument(value.remote),
|
|
708
|
+
device_id: value.deviceId,
|
|
709
|
+
device_signing_fragment: value.deviceSigningFragment,
|
|
710
|
+
device_agreement_fragment: value.deviceAgreementFragment,
|
|
711
|
+
profiles: value.profiles ?? [],
|
|
712
|
+
capabilities: { did_wba: value.capabilities?.didWba ?? false },
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
function requestSigningEnrollmentRequest(value) {
|
|
717
|
+
return {
|
|
718
|
+
remote: verifiedRemoteDocument(value.remote),
|
|
719
|
+
fragment: value.fragment,
|
|
720
|
+
capabilities: { did_wba: value.capabilities?.didWba ?? false },
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
function enrollmentProposal(value) {
|
|
725
|
+
const kind =
|
|
726
|
+
value.kind.kind === 'device'
|
|
727
|
+
? {
|
|
728
|
+
kind: 'device',
|
|
729
|
+
deviceId: value.kind.device_id,
|
|
730
|
+
signingKey: enrollmentKey(value.kind.signing_key),
|
|
731
|
+
agreementKey: enrollmentKey(value.kind.agreement_key),
|
|
732
|
+
profiles: value.kind.profiles,
|
|
733
|
+
}
|
|
734
|
+
: { kind: 'request_signing', signingKey: enrollmentKey(value.kind.signing_key) }
|
|
735
|
+
return {
|
|
736
|
+
enrollmentId: value.enrollment_id,
|
|
737
|
+
identity: identityReference(value.identity),
|
|
738
|
+
kind,
|
|
739
|
+
rootKeyFingerprint: value.root_key_fingerprint,
|
|
740
|
+
checkpoint: checkpoint(value.checkpoint),
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
function enrollmentKey(value) {
|
|
745
|
+
return { kid: value.kid, publicKeyMultibase: value.public_key_multibase }
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
function wrappedRootEnvelope(value) {
|
|
749
|
+
return {
|
|
750
|
+
type: value.type,
|
|
751
|
+
version: value.version,
|
|
752
|
+
context: {
|
|
753
|
+
source_did: value.context.sourceDid,
|
|
754
|
+
target_did: value.context.targetDid,
|
|
755
|
+
sender_device_id: value.context.senderDeviceId,
|
|
756
|
+
recipient_device_id: value.context.recipientDeviceId,
|
|
757
|
+
recipient_agreement_kid: value.context.recipientAgreementKid,
|
|
758
|
+
root_kid: value.context.rootKid,
|
|
759
|
+
checkpoint: {
|
|
760
|
+
document_version: value.context.checkpoint.documentVersion,
|
|
761
|
+
registry_version: value.context.checkpoint.registryVersion,
|
|
762
|
+
document_digest: value.context.checkpoint.documentDigest,
|
|
763
|
+
},
|
|
764
|
+
created_at: value.context.createdAt,
|
|
765
|
+
expires_at: value.context.expiresAt,
|
|
766
|
+
},
|
|
767
|
+
ephemeral_public_b64u: value.ephemeralPublic,
|
|
768
|
+
nonce_b64u: value.nonce,
|
|
769
|
+
ciphertext_b64u: value.ciphertext,
|
|
770
|
+
signature_b64u: value.signature,
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
module.exports = { IdentityProvider }
|