@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/index.js
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
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
|
+
class IdentityManager {
|
|
19
|
+
#inner
|
|
20
|
+
|
|
21
|
+
constructor(inner) {
|
|
22
|
+
this.#inner = inner
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static async initialize(config) {
|
|
26
|
+
return new IdentityManager(await call(native.IdentityManager.initialize(config)))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static async open(config) {
|
|
30
|
+
return new IdentityManager(await call(native.IdentityManager.open(config)))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async info() {
|
|
34
|
+
const value = await call(this.#inner.info())
|
|
35
|
+
return {
|
|
36
|
+
storeId: value.store_id,
|
|
37
|
+
schemaCompatible: value.schema_compatible,
|
|
38
|
+
identityCount: value.identity_count,
|
|
39
|
+
health: value.health,
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async list() {
|
|
44
|
+
return (await call(this.#inner.list())).map(identityDescriptor)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async create(request) {
|
|
48
|
+
return new ManagedIdentity(await call(this.#inner.create(createRequest(request))))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async get(reference) {
|
|
52
|
+
return new ManagedIdentity(await call(this.#inner.get(reference)))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
delete(reference) {
|
|
56
|
+
return call(this.#inner.delete(reference))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async recover() {
|
|
60
|
+
const value = await call(this.#inner.recover())
|
|
61
|
+
return { identityCount: value.identity_count }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async prepareIdentityTransition(request) {
|
|
65
|
+
return new IdentityTransitionSession(
|
|
66
|
+
await call(this.#inner.prepareIdentityTransition(identityTransitionRequest(request))),
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async resumeIdentityTransition(expectedCurrentDid) {
|
|
71
|
+
const session = await call(this.#inner.resumeIdentityTransition(expectedCurrentDid))
|
|
72
|
+
return session == null ? undefined : new IdentityTransitionSession(session)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
class ManagedIdentity {
|
|
77
|
+
#inner
|
|
78
|
+
|
|
79
|
+
constructor(inner) {
|
|
80
|
+
this.#inner = inner
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
reference() {
|
|
84
|
+
return call(this.#inner.reference())
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async publicIdentity() {
|
|
88
|
+
return publicIdentity(await call(this.#inner.publicIdentity()))
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
sign(request) {
|
|
92
|
+
return call(this.#inner.sign(request))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
verify(request) {
|
|
96
|
+
return call(this.#inner.verify(request))
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
signOriginProof(request) {
|
|
100
|
+
return call(this.#inner.signOriginProof(request))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async prepareDocumentChange(request) {
|
|
104
|
+
return new DocumentChangeSession(
|
|
105
|
+
await call(this.#inner.prepareDocumentChange(documentChangeRequest(request))),
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async resumeDocumentChange() {
|
|
110
|
+
const session = await call(this.#inner.resumeDocumentChange())
|
|
111
|
+
return session == null ? undefined : new DocumentChangeSession(session)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
class DocumentChangeSession {
|
|
116
|
+
#inner
|
|
117
|
+
|
|
118
|
+
constructor(inner) {
|
|
119
|
+
this.#inner = inner
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async candidate() {
|
|
123
|
+
return preparedChange(await call(this.#inner.candidate()))
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async beginPublication() {
|
|
127
|
+
return publicationAttempt(await call(this.#inner.beginPublication()))
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async complete(attempt, result) {
|
|
131
|
+
return documentChangeOutcome(
|
|
132
|
+
await call(this.#inner.complete(nativePublicationAttempt(attempt), publicationResult(result))),
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async reconcile(observation) {
|
|
137
|
+
return documentChangeOutcome(
|
|
138
|
+
await call(this.#inner.reconcile(verifiedRemoteDocument(observation))),
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
class IdentityTransitionSession {
|
|
144
|
+
#inner
|
|
145
|
+
|
|
146
|
+
constructor(inner) {
|
|
147
|
+
this.#inner = inner
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async candidate() {
|
|
151
|
+
return preparedIdentityTransition(await call(this.#inner.candidate()))
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async beginPublication() {
|
|
155
|
+
return identityTransitionAttempt(await call(this.#inner.beginPublication()))
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async complete(attempt, result) {
|
|
159
|
+
return identityTransitionOutcome(
|
|
160
|
+
await call(
|
|
161
|
+
this.#inner.complete(
|
|
162
|
+
nativeIdentityTransitionAttempt(attempt),
|
|
163
|
+
identityTransitionPublicationResult(result),
|
|
164
|
+
),
|
|
165
|
+
),
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async reconcile(observation) {
|
|
170
|
+
return identityTransitionOutcome(
|
|
171
|
+
await call(this.#inner.reconcile(identityTransitionObservation(observation))),
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function createRequest(value) {
|
|
177
|
+
return {
|
|
178
|
+
profile: value.profile,
|
|
179
|
+
domain: value.domain,
|
|
180
|
+
port: value.port,
|
|
181
|
+
path_segments: value.pathSegments,
|
|
182
|
+
capabilities: { did_wba: value.capabilities?.didWba ?? false },
|
|
183
|
+
managed_keys: value.managedKeys.map((key) => ({ fragment: key.fragment, role: key.role })),
|
|
184
|
+
external_keys: (value.externalKeys ?? []).map((key) => ({
|
|
185
|
+
kid: key.kid,
|
|
186
|
+
role: key.role,
|
|
187
|
+
material:
|
|
188
|
+
key.material.format === 'jwk'
|
|
189
|
+
? { format: 'jwk', public_key_jwk: key.material.publicKeyJwk }
|
|
190
|
+
: { format: 'multibase', value: key.material.value },
|
|
191
|
+
})),
|
|
192
|
+
services: (value.services ?? []).map((service) => ({
|
|
193
|
+
id: service.id,
|
|
194
|
+
service_type: service.serviceType,
|
|
195
|
+
service_endpoint: service.serviceEndpoint,
|
|
196
|
+
service_did: service.serviceDid,
|
|
197
|
+
profiles: service.profiles ?? [],
|
|
198
|
+
security_profiles: service.securityProfiles ?? [],
|
|
199
|
+
})),
|
|
200
|
+
agent_description_url: value.agentDescriptionUrl,
|
|
201
|
+
extensions: (value.extensions ?? []).map((extension) => ({
|
|
202
|
+
type: extension.type,
|
|
203
|
+
value: {
|
|
204
|
+
devices: extension.value.devices.map((device) => ({
|
|
205
|
+
device_id: device.deviceId,
|
|
206
|
+
signing_key_id: device.signingKeyId,
|
|
207
|
+
e2ee_key_id: device.e2eeKeyId,
|
|
208
|
+
profiles: device.profiles ?? [],
|
|
209
|
+
})),
|
|
210
|
+
},
|
|
211
|
+
})),
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function documentChangeRequest(value) {
|
|
216
|
+
return {
|
|
217
|
+
changes: value.changes.map((entry) => {
|
|
218
|
+
switch (entry.change) {
|
|
219
|
+
case 'rotate_signing_key':
|
|
220
|
+
return { change: entry.change, old_kid: entry.oldKid, new_fragment: entry.newFragment }
|
|
221
|
+
case 'add_authentication_key':
|
|
222
|
+
return { change: entry.change, key: publicKeyInput(entry.key) }
|
|
223
|
+
case 'remove_authentication_key':
|
|
224
|
+
return { change: entry.change, kid: entry.kid }
|
|
225
|
+
case 'add_device':
|
|
226
|
+
return {
|
|
227
|
+
change: entry.change,
|
|
228
|
+
device: {
|
|
229
|
+
device_id: entry.device.deviceId,
|
|
230
|
+
signing_key: publicKeyInput(entry.device.signingKey),
|
|
231
|
+
agreement_key: publicKeyInput(entry.device.agreementKey),
|
|
232
|
+
profiles: entry.device.profiles ?? [],
|
|
233
|
+
},
|
|
234
|
+
}
|
|
235
|
+
case 'remove_device':
|
|
236
|
+
return { change: entry.change, device_id: entry.deviceId }
|
|
237
|
+
case 'replace_services':
|
|
238
|
+
return {
|
|
239
|
+
change: entry.change,
|
|
240
|
+
services: entry.services.map((service) => ({
|
|
241
|
+
id: service.id,
|
|
242
|
+
service_type: service.serviceType,
|
|
243
|
+
service_endpoint: service.serviceEndpoint,
|
|
244
|
+
service_did: service.serviceDid,
|
|
245
|
+
profiles: service.profiles ?? [],
|
|
246
|
+
security_profiles: service.securityProfiles ?? [],
|
|
247
|
+
})),
|
|
248
|
+
}
|
|
249
|
+
default:
|
|
250
|
+
return entry
|
|
251
|
+
}
|
|
252
|
+
}),
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function identityTransitionRequest(value) {
|
|
257
|
+
return {
|
|
258
|
+
expected_current_did: value.expectedCurrentDid,
|
|
259
|
+
operation_id: value.operationId,
|
|
260
|
+
successor: {
|
|
261
|
+
store_id: value.successor.storeId,
|
|
262
|
+
identity_id: value.successor.identityId,
|
|
263
|
+
did: value.successor.did,
|
|
264
|
+
},
|
|
265
|
+
transition_document: value.transitionDocument,
|
|
266
|
+
provider_document: value.providerDocument,
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function publicKeyInput(value) {
|
|
271
|
+
return { kid: value.kid, public_key_multibase: value.publicKeyMultibase }
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function identityDescriptor(value) {
|
|
275
|
+
return { reference: identityReference(value.reference), state: value.state }
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function identityReference(value) {
|
|
279
|
+
return { storeId: value.store_id, identityId: value.identity_id, did: value.did }
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function publicIdentity(value) {
|
|
283
|
+
return {
|
|
284
|
+
reference: identityReference(value.reference),
|
|
285
|
+
state: value.state,
|
|
286
|
+
revision: value.revision,
|
|
287
|
+
document: value.document,
|
|
288
|
+
activeKeys: value.active_keys.map((key) => ({
|
|
289
|
+
kid: key.kid,
|
|
290
|
+
algorithm: key.algorithm,
|
|
291
|
+
purposes: key.purposes,
|
|
292
|
+
})),
|
|
293
|
+
capabilities: { didWba: value.capabilities.did_wba },
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function preparedChange(value) {
|
|
298
|
+
return {
|
|
299
|
+
operationId: value.operation_id,
|
|
300
|
+
candidateDocument: value.candidate_document,
|
|
301
|
+
candidateDigest: value.candidate_digest,
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function publicationAttempt(value) {
|
|
306
|
+
return {
|
|
307
|
+
operationId: value.operation_id,
|
|
308
|
+
candidateDigest: value.candidate_digest,
|
|
309
|
+
publicationGeneration: value.publication_generation,
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function nativePublicationAttempt(value) {
|
|
314
|
+
return {
|
|
315
|
+
operation_id: value.operationId,
|
|
316
|
+
candidate_digest: value.candidateDigest,
|
|
317
|
+
publication_generation: value.publicationGeneration,
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function publicationResult(value) {
|
|
322
|
+
if (value.result !== 'confirmed') return value
|
|
323
|
+
return { result: 'confirmed', evidence: publicationEvidence(value.evidence) }
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function verifiedRemoteDocument(value) {
|
|
327
|
+
return { document: value.document, evidence: publicationEvidence(value.evidence) }
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function publicationEvidence(value) {
|
|
331
|
+
return {
|
|
332
|
+
document_version: value.documentVersion,
|
|
333
|
+
registry_version: value.registryVersion,
|
|
334
|
+
document_digest: value.documentDigest,
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function documentChangeOutcome(value) {
|
|
339
|
+
if (value.outcome !== 'committed') return value
|
|
340
|
+
return { outcome: 'committed', identity: publicIdentity(value.identity) }
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function preparedIdentityTransition(value) {
|
|
344
|
+
return {
|
|
345
|
+
operationId: value.operation_id,
|
|
346
|
+
expectedCurrentDid: value.expected_current_did,
|
|
347
|
+
successorDid: value.successor_did,
|
|
348
|
+
predecessorDocument: value.predecessor_document,
|
|
349
|
+
successorDocument: value.successor_document,
|
|
350
|
+
predecessorDigest: value.predecessor_digest,
|
|
351
|
+
successorDigest: value.successor_digest,
|
|
352
|
+
assurance: value.assurance,
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function identityTransitionAttempt(value) {
|
|
357
|
+
return {
|
|
358
|
+
operationId: value.operation_id,
|
|
359
|
+
predecessorDigest: value.predecessor_digest,
|
|
360
|
+
successorDigest: value.successor_digest,
|
|
361
|
+
publicationGeneration: value.publication_generation,
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function nativeIdentityTransitionAttempt(value) {
|
|
366
|
+
return {
|
|
367
|
+
operation_id: value.operationId,
|
|
368
|
+
predecessor_digest: value.predecessorDigest,
|
|
369
|
+
successor_digest: value.successorDigest,
|
|
370
|
+
publication_generation: value.publicationGeneration,
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function identityTransitionPublicationResult(value) {
|
|
375
|
+
if (value.result !== 'confirmed') return value
|
|
376
|
+
return {
|
|
377
|
+
result: 'confirmed',
|
|
378
|
+
evidence: {
|
|
379
|
+
predecessor_digest: value.evidence.predecessorDigest,
|
|
380
|
+
successor_digest: value.evidence.successorDigest,
|
|
381
|
+
},
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function identityTransitionObservation(value) {
|
|
386
|
+
if (value.observation === 'remote_old') {
|
|
387
|
+
return { observation: 'remote_old', current_document: value.currentDocument }
|
|
388
|
+
}
|
|
389
|
+
return {
|
|
390
|
+
observation: 'published',
|
|
391
|
+
predecessor_document: value.predecessorDocument,
|
|
392
|
+
successor_document: value.successorDocument,
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function identityTransitionOutcome(value) {
|
|
397
|
+
if (value.outcome !== 'committed') return value
|
|
398
|
+
return { outcome: 'committed', currentDid: value.current_did }
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
module.exports = {
|
|
402
|
+
DocumentChangeSession,
|
|
403
|
+
IdentityManager,
|
|
404
|
+
IdentityTransitionSession,
|
|
405
|
+
ManagedIdentity,
|
|
406
|
+
}
|