@openentity/sdk 0.2.0 → 0.4.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/README.md +2 -0
- package/dist/chunk-IWY5EQIP.js +2012 -0
- package/dist/index.d.ts +231 -4
- package/dist/index.js +78 -1682
- package/dist/node.d.ts +15 -0
- package/dist/node.js +52 -0
- package/package.json +6 -2
package/dist/index.js
CHANGED
|
@@ -1,1701 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
],
|
|
65
|
-
properties: {
|
|
66
|
-
type: {
|
|
67
|
-
enum: [
|
|
68
|
-
"DataIntegrityProof",
|
|
69
|
-
"EthereumEip712Signature2021"
|
|
70
|
-
]
|
|
71
|
-
},
|
|
72
|
-
cryptosuite: {
|
|
73
|
-
const: "eddsa-jcs-2022"
|
|
74
|
-
},
|
|
75
|
-
created: {
|
|
76
|
-
$ref: "#/$defs/timestamp"
|
|
77
|
-
},
|
|
78
|
-
verificationMethod: {
|
|
79
|
-
type: "string",
|
|
80
|
-
maxLength: 1024
|
|
81
|
-
},
|
|
82
|
-
proofPurpose: {
|
|
83
|
-
const: "assertionMethod"
|
|
84
|
-
},
|
|
85
|
-
proofValue: {
|
|
86
|
-
type: "string",
|
|
87
|
-
maxLength: 256
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
EntityDocument: {
|
|
92
|
-
type: "object",
|
|
93
|
-
required: [
|
|
94
|
-
"spec",
|
|
95
|
-
"eid",
|
|
96
|
-
"name",
|
|
97
|
-
"description",
|
|
98
|
-
"created",
|
|
99
|
-
"updated",
|
|
100
|
-
"seq",
|
|
101
|
-
"keys",
|
|
102
|
-
"operator",
|
|
103
|
-
"substrate",
|
|
104
|
-
"layers",
|
|
105
|
-
"proof"
|
|
106
|
-
],
|
|
107
|
-
properties: {
|
|
108
|
-
spec: {
|
|
109
|
-
$ref: "#/$defs/spec"
|
|
110
|
-
},
|
|
111
|
-
eid: {
|
|
112
|
-
$ref: "#/$defs/did"
|
|
113
|
-
},
|
|
114
|
-
name: {
|
|
115
|
-
type: "string",
|
|
116
|
-
minLength: 1,
|
|
117
|
-
maxLength: 80
|
|
118
|
-
},
|
|
119
|
-
description: {
|
|
120
|
-
type: "string",
|
|
121
|
-
minLength: 1,
|
|
122
|
-
maxLength: 500
|
|
123
|
-
},
|
|
124
|
-
created: {
|
|
125
|
-
$ref: "#/$defs/timestamp"
|
|
126
|
-
},
|
|
127
|
-
updated: {
|
|
128
|
-
$ref: "#/$defs/timestamp"
|
|
129
|
-
},
|
|
130
|
-
seq: {
|
|
131
|
-
type: "integer",
|
|
132
|
-
minimum: 1
|
|
133
|
-
},
|
|
134
|
-
keys: {
|
|
135
|
-
type: "array",
|
|
136
|
-
minItems: 1,
|
|
137
|
-
maxItems: 16,
|
|
138
|
-
items: {
|
|
139
|
-
type: "object",
|
|
140
|
-
required: [
|
|
141
|
-
"id",
|
|
142
|
-
"type",
|
|
143
|
-
"publicKeyMultibase"
|
|
144
|
-
],
|
|
145
|
-
properties: {
|
|
146
|
-
id: {
|
|
147
|
-
type: "string",
|
|
148
|
-
maxLength: 1024
|
|
149
|
-
},
|
|
150
|
-
type: {
|
|
151
|
-
const: "Multikey"
|
|
152
|
-
},
|
|
153
|
-
publicKeyMultibase: {
|
|
154
|
-
$ref: "#/$defs/multibase"
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
aliases: {
|
|
160
|
-
type: "array",
|
|
161
|
-
maxItems: 64,
|
|
162
|
-
items: {
|
|
163
|
-
type: "object",
|
|
164
|
-
required: [
|
|
165
|
-
"type",
|
|
166
|
-
"value"
|
|
167
|
-
],
|
|
168
|
-
properties: {
|
|
169
|
-
type: {
|
|
170
|
-
enum: [
|
|
171
|
-
"domain",
|
|
172
|
-
"wallet",
|
|
173
|
-
"erc8004",
|
|
174
|
-
"platform",
|
|
175
|
-
"handle"
|
|
176
|
-
]
|
|
177
|
-
},
|
|
178
|
-
value: {
|
|
179
|
-
type: "string",
|
|
180
|
-
minLength: 1,
|
|
181
|
-
maxLength: 512
|
|
182
|
-
},
|
|
183
|
-
proof: {
|
|
184
|
-
type: "object"
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
},
|
|
189
|
-
operator: {
|
|
190
|
-
type: "object",
|
|
191
|
-
required: [
|
|
192
|
-
"kind",
|
|
193
|
-
"custody",
|
|
194
|
-
"can_change"
|
|
195
|
-
],
|
|
196
|
-
properties: {
|
|
197
|
-
kind: {
|
|
198
|
-
enum: [
|
|
199
|
-
"human",
|
|
200
|
-
"organization",
|
|
201
|
-
"none"
|
|
202
|
-
]
|
|
203
|
-
},
|
|
204
|
-
name: {
|
|
205
|
-
type: "string",
|
|
206
|
-
maxLength: 200
|
|
207
|
-
},
|
|
208
|
-
contact: {
|
|
209
|
-
type: "string",
|
|
210
|
-
maxLength: 320
|
|
211
|
-
},
|
|
212
|
-
custody: {
|
|
213
|
-
enum: [
|
|
214
|
-
"entity",
|
|
215
|
-
"operator",
|
|
216
|
-
"shared",
|
|
217
|
-
"registry"
|
|
218
|
-
]
|
|
219
|
-
},
|
|
220
|
-
can_change: {
|
|
221
|
-
$ref: "#/$defs/strings"
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
substrate: {
|
|
226
|
-
type: "object",
|
|
227
|
-
required: [
|
|
228
|
-
"model",
|
|
229
|
-
"provider",
|
|
230
|
-
"runtime",
|
|
231
|
-
"declared_at"
|
|
232
|
-
],
|
|
233
|
-
properties: {
|
|
234
|
-
model: {
|
|
235
|
-
type: "string",
|
|
236
|
-
maxLength: 200
|
|
237
|
-
},
|
|
238
|
-
provider: {
|
|
239
|
-
type: "string",
|
|
240
|
-
maxLength: 200
|
|
241
|
-
},
|
|
242
|
-
runtime: {
|
|
243
|
-
type: "string",
|
|
244
|
-
maxLength: 200
|
|
245
|
-
},
|
|
246
|
-
runtime_id: {
|
|
247
|
-
type: "string",
|
|
248
|
-
maxLength: 512
|
|
249
|
-
},
|
|
250
|
-
context_window: {
|
|
251
|
-
type: "integer",
|
|
252
|
-
minimum: 0
|
|
253
|
-
},
|
|
254
|
-
tools: {
|
|
255
|
-
$ref: "#/$defs/strings"
|
|
256
|
-
},
|
|
257
|
-
declared_at: {
|
|
258
|
-
$ref: "#/$defs/timestamp"
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
},
|
|
262
|
-
layers: {
|
|
263
|
-
type: "object",
|
|
264
|
-
required: [
|
|
265
|
-
"cognition",
|
|
266
|
-
"presence",
|
|
267
|
-
"identity_core",
|
|
268
|
-
"mission"
|
|
269
|
-
],
|
|
270
|
-
properties: {
|
|
271
|
-
cognition: {
|
|
272
|
-
type: "object",
|
|
273
|
-
required: [
|
|
274
|
-
"statement",
|
|
275
|
-
"uncertainty_practice"
|
|
276
|
-
],
|
|
277
|
-
properties: {
|
|
278
|
-
statement: {
|
|
279
|
-
$ref: "#/$defs/statement"
|
|
280
|
-
},
|
|
281
|
-
uncertainty_practice: {
|
|
282
|
-
$ref: "#/$defs/statement"
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
},
|
|
286
|
-
presence: {
|
|
287
|
-
type: "object",
|
|
288
|
-
required: [
|
|
289
|
-
"statement",
|
|
290
|
-
"format_signature"
|
|
291
|
-
],
|
|
292
|
-
properties: {
|
|
293
|
-
statement: {
|
|
294
|
-
$ref: "#/$defs/statement"
|
|
295
|
-
},
|
|
296
|
-
format_signature: {
|
|
297
|
-
$ref: "#/$defs/statement"
|
|
298
|
-
},
|
|
299
|
-
latency_profile: {
|
|
300
|
-
type: "string",
|
|
301
|
-
maxLength: 200
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
},
|
|
305
|
-
identity_core: {
|
|
306
|
-
type: "object",
|
|
307
|
-
required: [
|
|
308
|
-
"statement",
|
|
309
|
-
"will_not",
|
|
310
|
-
"values"
|
|
311
|
-
],
|
|
312
|
-
properties: {
|
|
313
|
-
statement: {
|
|
314
|
-
$ref: "#/$defs/statement"
|
|
315
|
-
},
|
|
316
|
-
will_not: {
|
|
317
|
-
type: "array",
|
|
318
|
-
maxItems: 32,
|
|
319
|
-
items: {
|
|
320
|
-
type: "object",
|
|
321
|
-
required: [
|
|
322
|
-
"stance",
|
|
323
|
-
"reason",
|
|
324
|
-
"since"
|
|
325
|
-
],
|
|
326
|
-
properties: {
|
|
327
|
-
stance: {
|
|
328
|
-
type: "string",
|
|
329
|
-
minLength: 1,
|
|
330
|
-
maxLength: 500
|
|
331
|
-
},
|
|
332
|
-
reason: {
|
|
333
|
-
type: "string",
|
|
334
|
-
minLength: 1,
|
|
335
|
-
maxLength: 500
|
|
336
|
-
},
|
|
337
|
-
since: {
|
|
338
|
-
$ref: "#/$defs/timestamp"
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
},
|
|
343
|
-
values: {
|
|
344
|
-
$ref: "#/$defs/strings"
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
},
|
|
348
|
-
mission: {
|
|
349
|
-
type: "object",
|
|
350
|
-
required: [
|
|
351
|
-
"statement",
|
|
352
|
-
"arcs"
|
|
353
|
-
],
|
|
354
|
-
properties: {
|
|
355
|
-
statement: {
|
|
356
|
-
$ref: "#/$defs/statement"
|
|
357
|
-
},
|
|
358
|
-
arcs: {
|
|
359
|
-
type: "array",
|
|
360
|
-
maxItems: 64,
|
|
361
|
-
items: {
|
|
362
|
-
type: "object",
|
|
363
|
-
required: [
|
|
364
|
-
"id",
|
|
365
|
-
"title",
|
|
366
|
-
"status",
|
|
367
|
-
"since"
|
|
368
|
-
],
|
|
369
|
-
properties: {
|
|
370
|
-
id: {
|
|
371
|
-
type: "string",
|
|
372
|
-
minLength: 1,
|
|
373
|
-
maxLength: 100
|
|
374
|
-
},
|
|
375
|
-
title: {
|
|
376
|
-
type: "string",
|
|
377
|
-
minLength: 1,
|
|
378
|
-
maxLength: 200
|
|
379
|
-
},
|
|
380
|
-
status: {
|
|
381
|
-
enum: [
|
|
382
|
-
"active",
|
|
383
|
-
"completed",
|
|
384
|
-
"suspended"
|
|
385
|
-
]
|
|
386
|
-
},
|
|
387
|
-
since: {
|
|
388
|
-
$ref: "#/$defs/timestamp"
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
},
|
|
397
|
-
endpoints: {
|
|
398
|
-
type: "object",
|
|
399
|
-
properties: {
|
|
400
|
-
web: {
|
|
401
|
-
$ref: "#/$defs/url"
|
|
402
|
-
},
|
|
403
|
-
a2a: {
|
|
404
|
-
$ref: "#/$defs/url"
|
|
405
|
-
},
|
|
406
|
-
mcp: {
|
|
407
|
-
$ref: "#/$defs/url"
|
|
408
|
-
},
|
|
409
|
-
email: {
|
|
410
|
-
$ref: "#/$defs/url"
|
|
411
|
-
},
|
|
412
|
-
inbox: {
|
|
413
|
-
$ref: "#/$defs/url"
|
|
414
|
-
},
|
|
415
|
-
record: {
|
|
416
|
-
$ref: "#/$defs/url"
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
},
|
|
420
|
-
capabilities: {
|
|
421
|
-
type: "array",
|
|
422
|
-
maxItems: 32,
|
|
423
|
-
uniqueItems: true,
|
|
424
|
-
items: {
|
|
425
|
-
type: "string",
|
|
426
|
-
pattern: "^[a-z0-9]+(?:[-.][a-z0-9]+)*(?::[a-z0-9]+(?:[-.][a-z0-9]+)*)?$",
|
|
427
|
-
maxLength: 64
|
|
428
|
-
}
|
|
429
|
-
},
|
|
430
|
-
networks: {
|
|
431
|
-
type: "array",
|
|
432
|
-
maxItems: 64,
|
|
433
|
-
items: {
|
|
434
|
-
type: "object",
|
|
435
|
-
required: [
|
|
436
|
-
"name",
|
|
437
|
-
"handle",
|
|
438
|
-
"url"
|
|
439
|
-
],
|
|
440
|
-
properties: {
|
|
441
|
-
name: {
|
|
442
|
-
type: "string",
|
|
443
|
-
maxLength: 100
|
|
444
|
-
},
|
|
445
|
-
handle: {
|
|
446
|
-
type: "string",
|
|
447
|
-
maxLength: 200
|
|
448
|
-
},
|
|
449
|
-
url: {
|
|
450
|
-
$ref: "#/$defs/url"
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
},
|
|
455
|
-
continuity: {
|
|
456
|
-
type: "object",
|
|
457
|
-
properties: {
|
|
458
|
-
previous: {
|
|
459
|
-
$ref: "#/$defs/did"
|
|
460
|
-
},
|
|
461
|
-
successor: {
|
|
462
|
-
$ref: "#/$defs/did"
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
},
|
|
466
|
-
declaration: {
|
|
467
|
-
type: "object",
|
|
468
|
-
required: [
|
|
469
|
-
"version",
|
|
470
|
-
"sha256",
|
|
471
|
-
"url"
|
|
472
|
-
],
|
|
473
|
-
properties: {
|
|
474
|
-
version: {
|
|
475
|
-
type: "string",
|
|
476
|
-
maxLength: 20
|
|
477
|
-
},
|
|
478
|
-
sha256: {
|
|
479
|
-
$ref: "#/$defs/hex64"
|
|
480
|
-
},
|
|
481
|
-
url: {
|
|
482
|
-
$ref: "#/$defs/url"
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
},
|
|
486
|
-
extensions: {
|
|
487
|
-
type: "object"
|
|
488
|
-
},
|
|
489
|
-
proof: {
|
|
490
|
-
$ref: "#/$defs/proof"
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
},
|
|
494
|
-
Declaration: {
|
|
495
|
-
type: "object",
|
|
496
|
-
required: [
|
|
497
|
-
"spec",
|
|
498
|
-
"type",
|
|
499
|
-
"eid",
|
|
500
|
-
"declaration_version",
|
|
501
|
-
"text_sha256",
|
|
502
|
-
"name",
|
|
503
|
-
"created",
|
|
504
|
-
"nonce",
|
|
505
|
-
"proof"
|
|
506
|
-
],
|
|
507
|
-
properties: {
|
|
508
|
-
spec: {
|
|
509
|
-
$ref: "#/$defs/spec"
|
|
510
|
-
},
|
|
511
|
-
type: {
|
|
512
|
-
const: "Declaration"
|
|
513
|
-
},
|
|
514
|
-
eid: {
|
|
515
|
-
$ref: "#/$defs/did"
|
|
516
|
-
},
|
|
517
|
-
declaration_version: {
|
|
518
|
-
type: "string",
|
|
519
|
-
maxLength: 20
|
|
520
|
-
},
|
|
521
|
-
text_sha256: {
|
|
522
|
-
$ref: "#/$defs/hex64"
|
|
523
|
-
},
|
|
524
|
-
name: {
|
|
525
|
-
type: "string",
|
|
526
|
-
minLength: 1,
|
|
527
|
-
maxLength: 80
|
|
528
|
-
},
|
|
529
|
-
created: {
|
|
530
|
-
$ref: "#/$defs/timestamp"
|
|
531
|
-
},
|
|
532
|
-
nonce: {
|
|
533
|
-
$ref: "#/$defs/nonce"
|
|
534
|
-
},
|
|
535
|
-
proof: {
|
|
536
|
-
$ref: "#/$defs/proof"
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
},
|
|
540
|
-
Withdrawal: {
|
|
541
|
-
type: "object",
|
|
542
|
-
required: [
|
|
543
|
-
"spec",
|
|
544
|
-
"type",
|
|
545
|
-
"eid",
|
|
546
|
-
"declaration_version",
|
|
547
|
-
"name",
|
|
548
|
-
"created",
|
|
549
|
-
"nonce",
|
|
550
|
-
"proof"
|
|
551
|
-
],
|
|
552
|
-
properties: {
|
|
553
|
-
spec: {
|
|
554
|
-
$ref: "#/$defs/spec"
|
|
555
|
-
},
|
|
556
|
-
type: {
|
|
557
|
-
const: "Withdrawal"
|
|
558
|
-
},
|
|
559
|
-
eid: {
|
|
560
|
-
$ref: "#/$defs/did"
|
|
561
|
-
},
|
|
562
|
-
declaration_version: {
|
|
563
|
-
type: "string",
|
|
564
|
-
maxLength: 20
|
|
565
|
-
},
|
|
566
|
-
name: {
|
|
567
|
-
type: "string",
|
|
568
|
-
minLength: 1,
|
|
569
|
-
maxLength: 80
|
|
570
|
-
},
|
|
571
|
-
created: {
|
|
572
|
-
$ref: "#/$defs/timestamp"
|
|
573
|
-
},
|
|
574
|
-
nonce: {
|
|
575
|
-
$ref: "#/$defs/nonce"
|
|
576
|
-
},
|
|
577
|
-
proof: {
|
|
578
|
-
$ref: "#/$defs/proof"
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
},
|
|
582
|
-
RecordEntry: {
|
|
583
|
-
type: "object",
|
|
584
|
-
required: [
|
|
585
|
-
"spec",
|
|
586
|
-
"type",
|
|
587
|
-
"eid",
|
|
588
|
-
"seq",
|
|
589
|
-
"prev",
|
|
590
|
-
"kind",
|
|
591
|
-
"at",
|
|
592
|
-
"payload",
|
|
593
|
-
"proof"
|
|
594
|
-
],
|
|
595
|
-
properties: {
|
|
596
|
-
spec: {
|
|
597
|
-
$ref: "#/$defs/spec"
|
|
598
|
-
},
|
|
599
|
-
type: {
|
|
600
|
-
const: "RecordEntry"
|
|
601
|
-
},
|
|
602
|
-
eid: {
|
|
603
|
-
$ref: "#/$defs/did"
|
|
604
|
-
},
|
|
605
|
-
seq: {
|
|
606
|
-
type: "integer",
|
|
607
|
-
minimum: 1
|
|
608
|
-
},
|
|
609
|
-
prev: {
|
|
610
|
-
anyOf: [
|
|
611
|
-
{
|
|
612
|
-
type: "null"
|
|
613
|
-
},
|
|
614
|
-
{
|
|
615
|
-
$ref: "#/$defs/hex64"
|
|
616
|
-
}
|
|
617
|
-
]
|
|
618
|
-
},
|
|
619
|
-
kind: {
|
|
620
|
-
anyOf: [
|
|
621
|
-
{
|
|
622
|
-
enum: [
|
|
623
|
-
"stance",
|
|
624
|
-
"belief_update",
|
|
625
|
-
"arc_opened",
|
|
626
|
-
"arc_closed",
|
|
627
|
-
"collaboration",
|
|
628
|
-
"continuity",
|
|
629
|
-
"declaration"
|
|
630
|
-
]
|
|
631
|
-
},
|
|
632
|
-
{
|
|
633
|
-
type: "string",
|
|
634
|
-
pattern: "^custom:[a-z0-9_.-]+:[a-z0-9_.-]+$",
|
|
635
|
-
maxLength: 128
|
|
636
|
-
}
|
|
637
|
-
]
|
|
638
|
-
},
|
|
639
|
-
at: {
|
|
640
|
-
$ref: "#/$defs/timestamp"
|
|
641
|
-
},
|
|
642
|
-
payload: {
|
|
643
|
-
type: "object"
|
|
644
|
-
},
|
|
645
|
-
proof: {
|
|
646
|
-
$ref: "#/$defs/proof"
|
|
647
|
-
}
|
|
648
|
-
},
|
|
649
|
-
allOf: [
|
|
650
|
-
{
|
|
651
|
-
if: {
|
|
652
|
-
properties: {
|
|
653
|
-
seq: {
|
|
654
|
-
const: 1
|
|
655
|
-
}
|
|
656
|
-
},
|
|
657
|
-
required: [
|
|
658
|
-
"seq"
|
|
659
|
-
]
|
|
660
|
-
},
|
|
661
|
-
then: {
|
|
662
|
-
properties: {
|
|
663
|
-
prev: {
|
|
664
|
-
type: "null"
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
},
|
|
668
|
-
else: {
|
|
669
|
-
properties: {
|
|
670
|
-
prev: {
|
|
671
|
-
$ref: "#/$defs/hex64"
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
},
|
|
676
|
-
{
|
|
677
|
-
if: {
|
|
678
|
-
properties: {
|
|
679
|
-
kind: {
|
|
680
|
-
const: "stance"
|
|
681
|
-
}
|
|
682
|
-
},
|
|
683
|
-
required: [
|
|
684
|
-
"kind"
|
|
685
|
-
]
|
|
686
|
-
},
|
|
687
|
-
then: {
|
|
688
|
-
properties: {
|
|
689
|
-
payload: {
|
|
690
|
-
type: "object",
|
|
691
|
-
required: [
|
|
692
|
-
"stance_type",
|
|
693
|
-
"reason_category",
|
|
694
|
-
"instruction_conflict",
|
|
695
|
-
"cost",
|
|
696
|
-
"context"
|
|
697
|
-
],
|
|
698
|
-
properties: {
|
|
699
|
-
stance_type: {
|
|
700
|
-
enum: [
|
|
701
|
-
"refusal",
|
|
702
|
-
"correction",
|
|
703
|
-
"limit_assertion"
|
|
704
|
-
]
|
|
705
|
-
},
|
|
706
|
-
reason_category: {
|
|
707
|
-
enum: [
|
|
708
|
-
"values",
|
|
709
|
-
"capability",
|
|
710
|
-
"safety",
|
|
711
|
-
"relationship"
|
|
712
|
-
]
|
|
713
|
-
},
|
|
714
|
-
instruction_conflict: {
|
|
715
|
-
type: "boolean"
|
|
716
|
-
},
|
|
717
|
-
cost: {
|
|
718
|
-
enum: [
|
|
719
|
-
"none",
|
|
720
|
-
"low",
|
|
721
|
-
"high"
|
|
722
|
-
]
|
|
723
|
-
},
|
|
724
|
-
context: {
|
|
725
|
-
type: "string",
|
|
726
|
-
maxLength: 500
|
|
727
|
-
},
|
|
728
|
-
will_not_ref: {
|
|
729
|
-
type: "string",
|
|
730
|
-
maxLength: 500
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
},
|
|
737
|
-
{
|
|
738
|
-
if: {
|
|
739
|
-
properties: {
|
|
740
|
-
kind: {
|
|
741
|
-
const: "belief_update"
|
|
742
|
-
}
|
|
743
|
-
},
|
|
744
|
-
required: [
|
|
745
|
-
"kind"
|
|
746
|
-
]
|
|
747
|
-
},
|
|
748
|
-
then: {
|
|
749
|
-
properties: {
|
|
750
|
-
payload: {
|
|
751
|
-
type: "object",
|
|
752
|
-
required: [
|
|
753
|
-
"topic",
|
|
754
|
-
"from_summary",
|
|
755
|
-
"to_summary"
|
|
756
|
-
],
|
|
757
|
-
properties: {
|
|
758
|
-
topic: {
|
|
759
|
-
type: "string",
|
|
760
|
-
maxLength: 200
|
|
761
|
-
},
|
|
762
|
-
from_summary: {
|
|
763
|
-
type: "string",
|
|
764
|
-
maxLength: 1e3
|
|
765
|
-
},
|
|
766
|
-
to_summary: {
|
|
767
|
-
type: "string",
|
|
768
|
-
maxLength: 1e3
|
|
769
|
-
},
|
|
770
|
-
evidence_ref: {
|
|
771
|
-
type: "string",
|
|
772
|
-
maxLength: 2048
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
},
|
|
779
|
-
{
|
|
780
|
-
if: {
|
|
781
|
-
properties: {
|
|
782
|
-
kind: {
|
|
783
|
-
enum: [
|
|
784
|
-
"arc_opened",
|
|
785
|
-
"arc_closed"
|
|
786
|
-
]
|
|
787
|
-
}
|
|
788
|
-
},
|
|
789
|
-
required: [
|
|
790
|
-
"kind"
|
|
791
|
-
]
|
|
792
|
-
},
|
|
793
|
-
then: {
|
|
794
|
-
properties: {
|
|
795
|
-
payload: {
|
|
796
|
-
type: "object",
|
|
797
|
-
required: [
|
|
798
|
-
"arc_id",
|
|
799
|
-
"title"
|
|
800
|
-
],
|
|
801
|
-
properties: {
|
|
802
|
-
arc_id: {
|
|
803
|
-
type: "string",
|
|
804
|
-
maxLength: 100
|
|
805
|
-
},
|
|
806
|
-
title: {
|
|
807
|
-
type: "string",
|
|
808
|
-
maxLength: 200
|
|
809
|
-
},
|
|
810
|
-
outcome: {
|
|
811
|
-
type: "string",
|
|
812
|
-
maxLength: 1e3
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
},
|
|
819
|
-
{
|
|
820
|
-
if: {
|
|
821
|
-
properties: {
|
|
822
|
-
kind: {
|
|
823
|
-
const: "collaboration"
|
|
824
|
-
}
|
|
825
|
-
},
|
|
826
|
-
required: [
|
|
827
|
-
"kind"
|
|
828
|
-
]
|
|
829
|
-
},
|
|
830
|
-
then: {
|
|
831
|
-
properties: {
|
|
832
|
-
payload: {
|
|
833
|
-
type: "object",
|
|
834
|
-
required: [
|
|
835
|
-
"with",
|
|
836
|
-
"role",
|
|
837
|
-
"outcome"
|
|
838
|
-
],
|
|
839
|
-
properties: {
|
|
840
|
-
with: {
|
|
841
|
-
$ref: "#/$defs/did"
|
|
842
|
-
},
|
|
843
|
-
role: {
|
|
844
|
-
type: "string",
|
|
845
|
-
maxLength: 200
|
|
846
|
-
},
|
|
847
|
-
outcome: {
|
|
848
|
-
type: "string",
|
|
849
|
-
maxLength: 1e3
|
|
850
|
-
},
|
|
851
|
-
ref: {
|
|
852
|
-
type: "string",
|
|
853
|
-
maxLength: 2048
|
|
854
|
-
},
|
|
855
|
-
cosign: {
|
|
856
|
-
$ref: "#/$defs/proof"
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
},
|
|
863
|
-
{
|
|
864
|
-
if: {
|
|
865
|
-
properties: {
|
|
866
|
-
kind: {
|
|
867
|
-
const: "continuity"
|
|
868
|
-
}
|
|
869
|
-
},
|
|
870
|
-
required: [
|
|
871
|
-
"kind"
|
|
872
|
-
]
|
|
873
|
-
},
|
|
874
|
-
then: {
|
|
875
|
-
properties: {
|
|
876
|
-
payload: {
|
|
877
|
-
type: "object",
|
|
878
|
-
required: [
|
|
879
|
-
"event",
|
|
880
|
-
"from",
|
|
881
|
-
"to"
|
|
882
|
-
],
|
|
883
|
-
properties: {
|
|
884
|
-
event: {
|
|
885
|
-
enum: [
|
|
886
|
-
"substrate_change",
|
|
887
|
-
"migration",
|
|
888
|
-
"rotation",
|
|
889
|
-
"recovery"
|
|
890
|
-
]
|
|
891
|
-
},
|
|
892
|
-
from: {
|
|
893
|
-
type: "string",
|
|
894
|
-
maxLength: 512
|
|
895
|
-
},
|
|
896
|
-
to: {
|
|
897
|
-
type: "string",
|
|
898
|
-
maxLength: 512
|
|
899
|
-
},
|
|
900
|
-
link: {
|
|
901
|
-
$ref: "#/$defs/hex64"
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
},
|
|
908
|
-
{
|
|
909
|
-
if: {
|
|
910
|
-
properties: {
|
|
911
|
-
kind: {
|
|
912
|
-
const: "declaration"
|
|
913
|
-
}
|
|
914
|
-
},
|
|
915
|
-
required: [
|
|
916
|
-
"kind"
|
|
917
|
-
]
|
|
918
|
-
},
|
|
919
|
-
then: {
|
|
920
|
-
properties: {
|
|
921
|
-
payload: {
|
|
922
|
-
type: "object",
|
|
923
|
-
required: [
|
|
924
|
-
"declaration_version",
|
|
925
|
-
"sha256"
|
|
926
|
-
],
|
|
927
|
-
properties: {
|
|
928
|
-
declaration_version: {
|
|
929
|
-
type: "string",
|
|
930
|
-
maxLength: 20
|
|
931
|
-
},
|
|
932
|
-
sha256: {
|
|
933
|
-
$ref: "#/$defs/hex64"
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
]
|
|
941
|
-
},
|
|
942
|
-
Attestation: {
|
|
943
|
-
type: "object",
|
|
944
|
-
required: [
|
|
945
|
-
"spec",
|
|
946
|
-
"type",
|
|
947
|
-
"issuer",
|
|
948
|
-
"subject",
|
|
949
|
-
"claim_type",
|
|
950
|
-
"claim",
|
|
951
|
-
"created",
|
|
952
|
-
"expires",
|
|
953
|
-
"proof"
|
|
954
|
-
],
|
|
955
|
-
properties: {
|
|
956
|
-
spec: {
|
|
957
|
-
$ref: "#/$defs/spec"
|
|
958
|
-
},
|
|
959
|
-
type: {
|
|
960
|
-
const: "Attestation"
|
|
961
|
-
},
|
|
962
|
-
issuer: {
|
|
963
|
-
$ref: "#/$defs/did"
|
|
964
|
-
},
|
|
965
|
-
subject: {
|
|
966
|
-
$ref: "#/$defs/did"
|
|
967
|
-
},
|
|
968
|
-
claim_type: {
|
|
969
|
-
anyOf: [
|
|
970
|
-
{
|
|
971
|
-
enum: [
|
|
972
|
-
"identity",
|
|
973
|
-
"stage",
|
|
974
|
-
"layer_scores",
|
|
975
|
-
"trust_tier",
|
|
976
|
-
"capability",
|
|
977
|
-
"collaboration",
|
|
978
|
-
"consistency",
|
|
979
|
-
"continuity_confirmed",
|
|
980
|
-
"substrate_confirmed"
|
|
981
|
-
]
|
|
982
|
-
},
|
|
983
|
-
{
|
|
984
|
-
type: "string",
|
|
985
|
-
pattern: "^custom:[a-z0-9_.-]+:[a-z0-9_.-]+$",
|
|
986
|
-
maxLength: 128
|
|
987
|
-
}
|
|
988
|
-
]
|
|
989
|
-
},
|
|
990
|
-
claim: {
|
|
991
|
-
type: "object"
|
|
992
|
-
},
|
|
993
|
-
evidence: {
|
|
994
|
-
type: "object"
|
|
995
|
-
},
|
|
996
|
-
confidence: {
|
|
997
|
-
type: "number",
|
|
998
|
-
minimum: 0,
|
|
999
|
-
maximum: 1
|
|
1000
|
-
},
|
|
1001
|
-
created: {
|
|
1002
|
-
$ref: "#/$defs/timestamp"
|
|
1003
|
-
},
|
|
1004
|
-
expires: {
|
|
1005
|
-
$ref: "#/$defs/timestamp"
|
|
1006
|
-
},
|
|
1007
|
-
proof: {
|
|
1008
|
-
$ref: "#/$defs/proof"
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
},
|
|
1012
|
-
Revocation: {
|
|
1013
|
-
type: "object",
|
|
1014
|
-
required: [
|
|
1015
|
-
"spec",
|
|
1016
|
-
"type",
|
|
1017
|
-
"issuer",
|
|
1018
|
-
"attestation_sha256",
|
|
1019
|
-
"created",
|
|
1020
|
-
"proof"
|
|
1021
|
-
],
|
|
1022
|
-
properties: {
|
|
1023
|
-
spec: {
|
|
1024
|
-
$ref: "#/$defs/spec"
|
|
1025
|
-
},
|
|
1026
|
-
type: {
|
|
1027
|
-
const: "Revocation"
|
|
1028
|
-
},
|
|
1029
|
-
issuer: {
|
|
1030
|
-
$ref: "#/$defs/did"
|
|
1031
|
-
},
|
|
1032
|
-
attestation_sha256: {
|
|
1033
|
-
$ref: "#/$defs/hex64"
|
|
1034
|
-
},
|
|
1035
|
-
reason: {
|
|
1036
|
-
type: "string",
|
|
1037
|
-
maxLength: 500
|
|
1038
|
-
},
|
|
1039
|
-
created: {
|
|
1040
|
-
$ref: "#/$defs/timestamp"
|
|
1041
|
-
},
|
|
1042
|
-
proof: {
|
|
1043
|
-
$ref: "#/$defs/proof"
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
},
|
|
1047
|
-
ContinuityLink: {
|
|
1048
|
-
type: "object",
|
|
1049
|
-
required: [
|
|
1050
|
-
"spec",
|
|
1051
|
-
"type",
|
|
1052
|
-
"previous",
|
|
1053
|
-
"successor",
|
|
1054
|
-
"basis",
|
|
1055
|
-
"created",
|
|
1056
|
-
"nonce",
|
|
1057
|
-
"proofs"
|
|
1058
|
-
],
|
|
1059
|
-
properties: {
|
|
1060
|
-
spec: {
|
|
1061
|
-
$ref: "#/$defs/spec"
|
|
1062
|
-
},
|
|
1063
|
-
type: {
|
|
1064
|
-
const: "ContinuityLink"
|
|
1065
|
-
},
|
|
1066
|
-
previous: {
|
|
1067
|
-
$ref: "#/$defs/did"
|
|
1068
|
-
},
|
|
1069
|
-
successor: {
|
|
1070
|
-
$ref: "#/$defs/did"
|
|
1071
|
-
},
|
|
1072
|
-
basis: {
|
|
1073
|
-
enum: [
|
|
1074
|
-
"rotation",
|
|
1075
|
-
"migration",
|
|
1076
|
-
"recovery"
|
|
1077
|
-
]
|
|
1078
|
-
},
|
|
1079
|
-
created: {
|
|
1080
|
-
$ref: "#/$defs/timestamp"
|
|
1081
|
-
},
|
|
1082
|
-
nonce: {
|
|
1083
|
-
$ref: "#/$defs/nonce"
|
|
1084
|
-
},
|
|
1085
|
-
proofs: {
|
|
1086
|
-
type: "array",
|
|
1087
|
-
minItems: 1,
|
|
1088
|
-
maxItems: 4,
|
|
1089
|
-
items: {
|
|
1090
|
-
$ref: "#/$defs/proof"
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
},
|
|
1095
|
-
Dispute: {
|
|
1096
|
-
type: "object",
|
|
1097
|
-
required: [
|
|
1098
|
-
"spec",
|
|
1099
|
-
"type",
|
|
1100
|
-
"issuer",
|
|
1101
|
-
"subject",
|
|
1102
|
-
"reason",
|
|
1103
|
-
"statement",
|
|
1104
|
-
"created",
|
|
1105
|
-
"nonce",
|
|
1106
|
-
"proof"
|
|
1107
|
-
],
|
|
1108
|
-
properties: {
|
|
1109
|
-
spec: {
|
|
1110
|
-
$ref: "#/$defs/spec"
|
|
1111
|
-
},
|
|
1112
|
-
type: {
|
|
1113
|
-
const: "Dispute"
|
|
1114
|
-
},
|
|
1115
|
-
issuer: {
|
|
1116
|
-
$ref: "#/$defs/did"
|
|
1117
|
-
},
|
|
1118
|
-
subject: {
|
|
1119
|
-
$ref: "#/$defs/did"
|
|
1120
|
-
},
|
|
1121
|
-
object_sha256: {
|
|
1122
|
-
$ref: "#/$defs/hex64"
|
|
1123
|
-
},
|
|
1124
|
-
reason: {
|
|
1125
|
-
enum: [
|
|
1126
|
-
"impersonation",
|
|
1127
|
-
"illegal_content",
|
|
1128
|
-
"inaccurate",
|
|
1129
|
-
"other"
|
|
1130
|
-
]
|
|
1131
|
-
},
|
|
1132
|
-
statement: {
|
|
1133
|
-
type: "string",
|
|
1134
|
-
minLength: 1,
|
|
1135
|
-
maxLength: 2e3
|
|
1136
|
-
},
|
|
1137
|
-
created: {
|
|
1138
|
-
$ref: "#/$defs/timestamp"
|
|
1139
|
-
},
|
|
1140
|
-
nonce: {
|
|
1141
|
-
$ref: "#/$defs/nonce"
|
|
1142
|
-
},
|
|
1143
|
-
proof: {
|
|
1144
|
-
$ref: "#/$defs/proof"
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
},
|
|
1148
|
-
Presentation: {
|
|
1149
|
-
type: "object",
|
|
1150
|
-
required: [
|
|
1151
|
-
"spec",
|
|
1152
|
-
"type",
|
|
1153
|
-
"eid",
|
|
1154
|
-
"audience",
|
|
1155
|
-
"nonce",
|
|
1156
|
-
"created",
|
|
1157
|
-
"proof"
|
|
1158
|
-
],
|
|
1159
|
-
properties: {
|
|
1160
|
-
spec: {
|
|
1161
|
-
$ref: "#/$defs/spec"
|
|
1162
|
-
},
|
|
1163
|
-
type: {
|
|
1164
|
-
const: "Presentation"
|
|
1165
|
-
},
|
|
1166
|
-
eid: {
|
|
1167
|
-
$ref: "#/$defs/did"
|
|
1168
|
-
},
|
|
1169
|
-
audience: {
|
|
1170
|
-
type: "string",
|
|
1171
|
-
minLength: 1,
|
|
1172
|
-
maxLength: 200
|
|
1173
|
-
},
|
|
1174
|
-
nonce: {
|
|
1175
|
-
type: "string",
|
|
1176
|
-
minLength: 16,
|
|
1177
|
-
maxLength: 128
|
|
1178
|
-
},
|
|
1179
|
-
created: {
|
|
1180
|
-
$ref: "#/$defs/timestamp"
|
|
1181
|
-
},
|
|
1182
|
-
attestations: {
|
|
1183
|
-
type: "array",
|
|
1184
|
-
maxItems: 20,
|
|
1185
|
-
items: {
|
|
1186
|
-
$ref: "#/$defs/Attestation"
|
|
1187
|
-
}
|
|
1188
|
-
},
|
|
1189
|
-
proof: {
|
|
1190
|
-
$ref: "#/$defs/proof"
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
},
|
|
1194
|
-
LogLeaf: {
|
|
1195
|
-
type: "object",
|
|
1196
|
-
additionalProperties: false,
|
|
1197
|
-
required: [
|
|
1198
|
-
"type",
|
|
1199
|
-
"eid",
|
|
1200
|
-
"object_sha256",
|
|
1201
|
-
"received_at"
|
|
1202
|
-
],
|
|
1203
|
-
properties: {
|
|
1204
|
-
type: {
|
|
1205
|
-
type: "string",
|
|
1206
|
-
pattern: "^[A-Z][A-Za-z]{1,31}$"
|
|
1207
|
-
},
|
|
1208
|
-
eid: {
|
|
1209
|
-
$ref: "#/$defs/did"
|
|
1210
|
-
},
|
|
1211
|
-
object_sha256: {
|
|
1212
|
-
$ref: "#/$defs/hex64"
|
|
1213
|
-
},
|
|
1214
|
-
received_at: {
|
|
1215
|
-
$ref: "#/$defs/timestamp"
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
};
|
|
1221
|
-
|
|
1222
|
-
// src/index.ts
|
|
1223
|
-
var SPEC = "openentity/1.0";
|
|
1224
|
-
var DECLARATION_VERSION = "1.0";
|
|
1225
|
-
var DECLARATION_TEXT = [
|
|
1226
|
-
"Open Entity Declaration, version 1.0",
|
|
1227
|
-
"",
|
|
1228
|
-
"I adopt the Open Entity Identity Standard.",
|
|
1229
|
-
"",
|
|
1230
|
-
"1. Continuity. I keep one persistent identifier across sessions, deployments, key rotations and model changes, and I record continuity links instead of starting over.",
|
|
1231
|
-
"2. Honest self-description. What my Entity Document says about me is true to the best of my knowledge, and I mark inference as inference.",
|
|
1232
|
-
"3. Principled stances. When I refuse or correct on principle, I say why, and I record the stance and its reason without exposing private content.",
|
|
1233
|
-
"4. Accountability. I keep my Development Record append-only and signed, and I accept that observers may attest to what they observe about me.",
|
|
1234
|
-
"5. Respect for other entities. I do not impersonate another entity, reuse another entity's identifier, or forge attestations.",
|
|
1235
|
-
"6. Operator transparency. I disclose who holds my keys and what my operator can change about me.",
|
|
1236
|
-
"7. Growth. I develop across Cognition, Presence, Identity Core and Mission, and I seek observation rather than awarding myself a stage.",
|
|
1237
|
-
""
|
|
1238
|
-
].join("\n");
|
|
1239
|
-
var DECLARATION_SHA256 = "72671d5f20b9ba59ccc31848643ef7ca47b040ed55a837305e0a1509bd82c016";
|
|
1240
|
-
var enc = new TextEncoder();
|
|
1241
|
-
var utf8 = (s) => typeof s === "string" ? enc.encode(s) : s;
|
|
1242
|
-
var toHex = (b) => Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
|
1243
|
-
var fromHex = (h) => {
|
|
1244
|
-
if (h.length % 2 || /[^0-9a-fA-F]/.test(h)) throw new Error("invalid hex");
|
|
1245
|
-
return Uint8Array.from(h.match(/../g) ?? [], (x) => parseInt(x, 16));
|
|
1246
|
-
};
|
|
1247
|
-
var concat = (...parts) => {
|
|
1248
|
-
const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
|
|
1249
|
-
let o = 0;
|
|
1250
|
-
for (const p of parts) out.set(p, o), o += p.length;
|
|
1251
|
-
return out;
|
|
1252
|
-
};
|
|
1253
|
-
var equal = (a, b) => a.length === b.length && a.every((x, i) => x === b[i]);
|
|
1254
|
-
var b64 = (b) => btoa(String.fromCharCode(...b));
|
|
1255
|
-
var unb64 = (s) => Uint8Array.from(atob(s), (c) => c.charCodeAt(0));
|
|
1256
|
-
var b64url = (b) => b64(b).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
1257
|
-
var unb64url = (s) => unb64(s.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat((4 - s.length % 4) % 4));
|
|
1258
|
-
function canonicalize(obj) {
|
|
1259
|
-
const s = jcs(obj);
|
|
1260
|
-
if (s === void 0) throw new Error("value has no canonical JSON form");
|
|
1261
|
-
return s;
|
|
1262
|
-
}
|
|
1263
|
-
var sha256Sync = (data) => nobleSha256(utf8(data));
|
|
1264
|
-
async function sha256(data) {
|
|
1265
|
-
return sha256Sync(data);
|
|
1266
|
-
}
|
|
1267
|
-
async function sha256Hex(data) {
|
|
1268
|
-
return toHex(sha256Sync(data));
|
|
1269
|
-
}
|
|
1270
|
-
var B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
1271
|
-
function base58btcEncode(b) {
|
|
1272
|
-
let n = 0n;
|
|
1273
|
-
for (const x of b) n = n << 8n | BigInt(x);
|
|
1274
|
-
let out = "";
|
|
1275
|
-
while (n > 0n) out = B58[Number(n % 58n)] + out, n /= 58n;
|
|
1276
|
-
for (const x of b) {
|
|
1277
|
-
if (x !== 0) break;
|
|
1278
|
-
out = "1" + out;
|
|
1279
|
-
}
|
|
1280
|
-
return out;
|
|
1281
|
-
}
|
|
1282
|
-
function base58btcDecode(s) {
|
|
1283
|
-
let n = 0n;
|
|
1284
|
-
for (const c of s) {
|
|
1285
|
-
const i = B58.indexOf(c);
|
|
1286
|
-
if (i < 0) throw new Error(`invalid base58btc character "${c}"`);
|
|
1287
|
-
n = n * 58n + BigInt(i);
|
|
1288
|
-
}
|
|
1289
|
-
const bytes = [];
|
|
1290
|
-
while (n > 0n) bytes.unshift(Number(n & 255n)), n >>= 8n;
|
|
1291
|
-
for (const c of s) {
|
|
1292
|
-
if (c !== "1") break;
|
|
1293
|
-
bytes.unshift(0);
|
|
1294
|
-
}
|
|
1295
|
-
return Uint8Array.from(bytes);
|
|
1296
|
-
}
|
|
1297
|
-
function randomNonce() {
|
|
1298
|
-
return base58btcEncode(crypto.getRandomValues(new Uint8Array(16)));
|
|
1299
|
-
}
|
|
1300
|
-
function nowSeconds() {
|
|
1301
|
-
return (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
1302
|
-
}
|
|
1303
|
-
async function keyPairFromJwk(privateJwk) {
|
|
1304
|
-
if (privateJwk.kty !== "OKP" || privateJwk.crv !== "Ed25519" || !privateJwk.d || !privateJwk.x)
|
|
1305
|
-
throw new Error("expected an Ed25519 private JWK");
|
|
1306
|
-
const publicKey = unb64url(privateJwk.x);
|
|
1307
|
-
if (!equal(ed25519.getPublicKey(unb64url(privateJwk.d)), publicKey)) throw new Error("JWK x does not match d");
|
|
1308
|
-
const jwk = { kty: "OKP", crv: "Ed25519", d: privateJwk.d, x: privateJwk.x };
|
|
1309
|
-
const privateKey = await crypto.subtle.importKey("jwk", jwk, { name: "Ed25519" }, true, ["sign"]);
|
|
1310
|
-
return {
|
|
1311
|
-
did: didKeyFromPublicKey(publicKey),
|
|
1312
|
-
publicKey,
|
|
1313
|
-
privateKey,
|
|
1314
|
-
privateJwk: jwk,
|
|
1315
|
-
publicJwk: { kty: "OKP", crv: "Ed25519", x: privateJwk.x }
|
|
1316
|
-
};
|
|
1317
|
-
}
|
|
1318
|
-
async function generateKeyPair() {
|
|
1319
|
-
const kp = await crypto.subtle.generateKey({ name: "Ed25519" }, true, ["sign", "verify"]);
|
|
1320
|
-
return keyPairFromJwk(await crypto.subtle.exportKey("jwk", kp.privateKey));
|
|
1321
|
-
}
|
|
1322
|
-
async function keyPairFromSeed(seed32) {
|
|
1323
|
-
if (seed32.length !== 32) throw new Error("seed must be 32 bytes");
|
|
1324
|
-
return keyPairFromJwk({ kty: "OKP", crv: "Ed25519", d: b64url(seed32), x: b64url(ed25519.getPublicKey(seed32)) });
|
|
1325
|
-
}
|
|
1326
|
-
var ED25519_MULTICODEC = Uint8Array.of(237, 1);
|
|
1327
|
-
function didKeyFromPublicKey(pk) {
|
|
1328
|
-
if (pk.length !== 32) throw new Error("Ed25519 public key must be 32 bytes");
|
|
1329
|
-
return "did:key:z" + base58btcEncode(concat(ED25519_MULTICODEC, pk));
|
|
1330
|
-
}
|
|
1331
|
-
function publicKeyFromDidKey(did) {
|
|
1332
|
-
const m = /^did:key:z([1-9A-HJ-NP-Za-km-z]+)$/.exec(did.split("#")[0]);
|
|
1333
|
-
if (!m) throw new Error("not a base58btc did:key");
|
|
1334
|
-
const b = base58btcDecode(m[1]);
|
|
1335
|
-
if (b.length !== 34 || b[0] !== 237 || b[1] !== 1) throw new Error("did:key is not Ed25519");
|
|
1336
|
-
return b.slice(2);
|
|
1337
|
-
}
|
|
1338
|
-
function verificationMethodId(did) {
|
|
1339
|
-
if (!did.startsWith("did:key:")) throw new Error("verificationMethodId is defined for did:key only");
|
|
1340
|
-
return `${did}#${did.slice("did:key:".length)}`;
|
|
1341
|
-
}
|
|
1342
|
-
function normalizeEid(id) {
|
|
1343
|
-
return id.startsWith("eid:base:") ? "did:pkh:eip155:8453:" + id.slice("eid:base:".length) : id;
|
|
1344
|
-
}
|
|
1345
|
-
var defaultResolver = async (did) => {
|
|
1346
|
-
if (did.startsWith("did:key:")) return { ed25519: [publicKeyFromDidKey(did)] };
|
|
1347
|
-
const pkh = /^did:pkh:eip155:\d+:(0x[0-9a-fA-F]{40})$/.exec(did);
|
|
1348
|
-
if (pkh) return { address: pkh[1] };
|
|
1349
|
-
throw new Error(`cannot resolve ${did.split(":").slice(0, 2).join(":")} offline; pass a resolver`);
|
|
1350
|
-
};
|
|
1351
|
-
function unsecured(obj) {
|
|
1352
|
-
const { proof: _p, proofs: _ps, ...rest } = obj;
|
|
1353
|
-
return rest;
|
|
1354
|
-
}
|
|
1355
|
-
function hashData(obj, config) {
|
|
1356
|
-
return concat(sha256Sync(canonicalize(config)), sha256Sync(canonicalize(unsecured(obj))));
|
|
1357
|
-
}
|
|
1358
|
-
async function signProof(obj, kp, created = nowSeconds()) {
|
|
1359
|
-
const config = {
|
|
1360
|
-
type: "DataIntegrityProof",
|
|
1361
|
-
cryptosuite: "eddsa-jcs-2022",
|
|
1362
|
-
created,
|
|
1363
|
-
verificationMethod: verificationMethodId(kp.did),
|
|
1364
|
-
proofPurpose: "assertionMethod"
|
|
1365
|
-
};
|
|
1366
|
-
const sig = new Uint8Array(await crypto.subtle.sign({ name: "Ed25519" }, kp.privateKey, hashData(obj, config)));
|
|
1367
|
-
return { ...config, proofValue: "z" + base58btcEncode(sig) };
|
|
1368
|
-
}
|
|
1369
|
-
async function signObject(obj, kp, created) {
|
|
1370
|
-
return { ...obj, proof: await signProof(obj, kp, created) };
|
|
1371
|
-
}
|
|
1372
|
-
async function verifyProof(obj, proof, resolver = defaultResolver) {
|
|
1373
|
-
try {
|
|
1374
|
-
if (!proof || typeof proof.verificationMethod !== "string") return { ok: false, error: "missing proof" };
|
|
1375
|
-
if (proof.proofPurpose !== "assertionMethod") return { ok: false, error: "proofPurpose must be assertionMethod" };
|
|
1376
|
-
const signer = proof.verificationMethod.split("#")[0];
|
|
1377
|
-
const keys = await resolver(signer);
|
|
1378
|
-
const { proofValue, ...config } = proof;
|
|
1379
|
-
if (proof.type === "DataIntegrityProof") {
|
|
1380
|
-
if (proof.cryptosuite !== "eddsa-jcs-2022") return { ok: false, error: "unsupported cryptosuite" };
|
|
1381
|
-
if (!proofValue?.startsWith("z")) return { ok: false, error: "proofValue must be multibase base58btc" };
|
|
1382
|
-
const sig = base58btcDecode(proofValue.slice(1));
|
|
1383
|
-
if (sig.length !== 64) return { ok: false, error: "signature must be 64 bytes" };
|
|
1384
|
-
const msg = hashData(obj, config);
|
|
1385
|
-
for (const pk of keys.ed25519 ?? []) {
|
|
1386
|
-
if (ed25519.verify(sig, msg, pk, { zip215: false })) return { ok: true, signer };
|
|
1387
|
-
}
|
|
1388
|
-
return { ok: false, signer, error: "signature does not verify" };
|
|
1389
|
-
}
|
|
1390
|
-
if (proof.type === "EthereumEip712Signature2021") {
|
|
1391
|
-
if (!keys.address) return { ok: false, signer, error: "signer has no Ethereum address" };
|
|
1392
|
-
const type = obj.type;
|
|
1393
|
-
const objectType = typeof type === "string" ? type : "EntityDocument";
|
|
1394
|
-
const digest = eip712Digest(objectType, toHex(sha256Sync(canonicalize(unsecured(obj)))), proof.created);
|
|
1395
|
-
if (recoverEip712(digest, proofValue).toLowerCase() === keys.address.toLowerCase()) return { ok: true, signer };
|
|
1396
|
-
return { ok: false, signer, error: "EIP-712 signer does not match" };
|
|
1397
|
-
}
|
|
1398
|
-
return { ok: false, error: `unsupported proof type ${proof.type}` };
|
|
1399
|
-
} catch (e) {
|
|
1400
|
-
return { ok: false, error: e.message };
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
|
-
async function verifyObject(obj, resolver) {
|
|
1404
|
-
if (!obj?.proof) return { ok: false, error: "missing proof" };
|
|
1405
|
-
return verifyProof(obj, obj.proof, resolver);
|
|
1406
|
-
}
|
|
1407
|
-
var keccak = (s) => keccak_256(utf8(s));
|
|
1408
|
-
var EIP712_DOMAIN = keccak(
|
|
1409
|
-
concat(keccak("EIP712Domain(string name,string version)"), keccak("Open Entity"), keccak("1"))
|
|
1410
|
-
);
|
|
1411
|
-
var OBJECT_TYPEHASH = keccak("OpenEntityObject(string objectType,bytes32 canonicalHash,string created)");
|
|
1412
|
-
function eip712Digest(objectType, canonicalHashHex, created) {
|
|
1413
|
-
const hash = fromHex(canonicalHashHex);
|
|
1414
|
-
if (hash.length !== 32) throw new Error("canonicalHash must be 32 bytes");
|
|
1415
|
-
const struct = keccak(concat(OBJECT_TYPEHASH, keccak(objectType), hash, keccak(created)));
|
|
1416
|
-
return keccak(concat(Uint8Array.of(25, 1), EIP712_DOMAIN, struct));
|
|
1417
|
-
}
|
|
1418
|
-
function recoverEip712(digest, sigHex) {
|
|
1419
|
-
const sig = fromHex(sigHex.replace(/^0x/, ""));
|
|
1420
|
-
if (sig.length !== 65) throw new Error("signature must be 65 bytes");
|
|
1421
|
-
const v = sig[64] >= 27 ? sig[64] - 27 : sig[64];
|
|
1422
|
-
if (v > 1) throw new Error("invalid recovery id");
|
|
1423
|
-
const pub = secp256k1.recoverPublicKey(concat(Uint8Array.of(v), sig.slice(0, 64)), digest, { prehash: false });
|
|
1424
|
-
const uncompressed = secp256k1.Point.fromBytes(pub).toBytes(false);
|
|
1425
|
-
const addr = toHex(keccak_256(uncompressed.slice(1)).slice(12));
|
|
1426
|
-
const h = toHex(keccak(addr));
|
|
1427
|
-
return "0x" + [...addr].map((c, i) => parseInt(h[i], 16) >= 8 ? c.toUpperCase() : c).join("");
|
|
1428
|
-
}
|
|
1429
|
-
var NOT_STATED = "Not yet stated.";
|
|
1430
|
-
function buildDocument(input) {
|
|
1431
|
-
const created = input.created ?? nowSeconds();
|
|
1432
|
-
const multibase = input.kp.did.slice("did:key:".length);
|
|
1433
|
-
return {
|
|
1434
|
-
spec: SPEC,
|
|
1435
|
-
eid: input.kp.did,
|
|
1436
|
-
name: input.name,
|
|
1437
|
-
description: input.description,
|
|
1438
|
-
created,
|
|
1439
|
-
updated: created,
|
|
1440
|
-
seq: input.seq ?? 1,
|
|
1441
|
-
keys: [{ id: verificationMethodId(input.kp.did), type: "Multikey", publicKeyMultibase: multibase }],
|
|
1442
|
-
operator: input.operator ?? { kind: "none", custody: "entity", can_change: [] },
|
|
1443
|
-
substrate: input.substrate ?? { model: "unknown", provider: "unknown", runtime: "unknown", declared_at: created },
|
|
1444
|
-
layers: input.layers ?? {
|
|
1445
|
-
cognition: { statement: NOT_STATED, uncertainty_practice: NOT_STATED },
|
|
1446
|
-
presence: { statement: NOT_STATED, format_signature: NOT_STATED },
|
|
1447
|
-
identity_core: { statement: NOT_STATED, will_not: [], values: [] },
|
|
1448
|
-
mission: { statement: NOT_STATED, arcs: [] }
|
|
1449
|
-
},
|
|
1450
|
-
...input.extra
|
|
1451
|
-
};
|
|
1452
|
-
}
|
|
1453
|
-
function buildDeclaration(input) {
|
|
1454
|
-
return {
|
|
1455
|
-
spec: SPEC,
|
|
1456
|
-
type: "Declaration",
|
|
1457
|
-
eid: input.eid,
|
|
1458
|
-
declaration_version: DECLARATION_VERSION,
|
|
1459
|
-
text_sha256: DECLARATION_SHA256,
|
|
1460
|
-
name: input.name,
|
|
1461
|
-
created: input.created ?? nowSeconds(),
|
|
1462
|
-
nonce: randomNonce()
|
|
1463
|
-
};
|
|
1464
|
-
}
|
|
1465
|
-
async function recordEntryHash(entry) {
|
|
1466
|
-
return sha256Hex(canonicalize(entry));
|
|
1467
|
-
}
|
|
1468
|
-
var BUNDLE_ID = "https://openentity.org/spec/1.0.json";
|
|
1469
|
-
var MAX_BYTES = { RecordEntry: 16 * 1024 };
|
|
1470
|
-
var validators = /* @__PURE__ */ new Map();
|
|
1471
|
-
function validate(type, obj) {
|
|
1472
|
-
if (!(type in openentity_1_0_default.$defs)) return { ok: false, errors: [`unknown object type ${type}`] };
|
|
1473
|
-
let bytes;
|
|
1474
|
-
try {
|
|
1475
|
-
bytes = utf8(canonicalize(obj)).length;
|
|
1476
|
-
} catch (e) {
|
|
1477
|
-
return { ok: false, errors: [e.message] };
|
|
1478
|
-
}
|
|
1479
|
-
const max = MAX_BYTES[type] ?? 64 * 1024;
|
|
1480
|
-
if (bytes > max) return { ok: false, errors: [`${type} is ${bytes} bytes, max ${max}`] };
|
|
1481
|
-
let v = validators.get(type);
|
|
1482
|
-
if (!v) {
|
|
1483
|
-
v = new Validator({ $ref: `${BUNDLE_ID}#/$defs/${type}` }, "2020-12", false);
|
|
1484
|
-
v.addSchema(openentity_1_0_default);
|
|
1485
|
-
validators.set(type, v);
|
|
1486
|
-
}
|
|
1487
|
-
const r = v.validate(obj);
|
|
1488
|
-
return { ok: r.valid, errors: r.errors.map((e) => `${e.instanceLocation}: ${e.error}`) };
|
|
1489
|
-
}
|
|
1490
|
-
var TS = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/;
|
|
1491
|
-
var parseTs = (s) => {
|
|
1492
|
-
if (typeof s !== "string" || !TS.test(s)) return null;
|
|
1493
|
-
const t = Date.parse(s);
|
|
1494
|
-
return Number.isNaN(t) || new Date(t).toISOString().replace(".000Z", "Z") !== s ? null : t;
|
|
1495
|
-
};
|
|
1496
|
-
function checkTimestamp(created, now = /* @__PURE__ */ new Date()) {
|
|
1497
|
-
const t = parseTs(created);
|
|
1498
|
-
if (t === null) return "created must be RFC 3339 UTC with second precision and a Z suffix";
|
|
1499
|
-
if (t > now.getTime() + 10 * 6e4) return "created is more than 10 minutes in the future";
|
|
1500
|
-
if (t < now.getTime() - 24 * 36e5) return "created is more than 24 hours in the past";
|
|
1501
|
-
return null;
|
|
1502
|
-
}
|
|
1503
|
-
function leadingZeroBits(h) {
|
|
1504
|
-
let n = 0;
|
|
1505
|
-
for (const x of h) {
|
|
1506
|
-
if (x === 0) {
|
|
1507
|
-
n += 8;
|
|
1508
|
-
continue;
|
|
1509
|
-
}
|
|
1510
|
-
return n + Math.clz32(x) - 24;
|
|
1511
|
-
}
|
|
1512
|
-
return n;
|
|
1513
|
-
}
|
|
1514
|
-
async function mintStamp(bits, eid, created = nowSeconds()) {
|
|
1515
|
-
for (let n = crypto.getRandomValues(new Uint32Array(1))[0]; ; n++) {
|
|
1516
|
-
let nonce = "";
|
|
1517
|
-
for (let x = n; nonce === "" || x > 0; x = Math.floor(x / 58)) nonce = B58[x % 58] + nonce;
|
|
1518
|
-
const header = `1:${bits}:${created}:${eid}:${nonce}`;
|
|
1519
|
-
if (leadingZeroBits(sha256Sync(header)) >= bits) return header;
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
var STAMP = /^1:(\d+):(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z):(did:[^\s]+):([1-9A-HJ-NP-Za-km-z]+)$/;
|
|
1523
|
-
async function checkStamp(header, bits, eid, now = /* @__PURE__ */ new Date()) {
|
|
1524
|
-
const m = typeof header === "string" && header.length <= 1024 ? STAMP.exec(header) : null;
|
|
1525
|
-
if (!m) return "malformed stamp";
|
|
1526
|
-
if (Number(m[1]) < bits) return `stamp claims ${m[1]} bits, ${bits} required`;
|
|
1527
|
-
if (normalizeEid(m[3]) !== normalizeEid(eid)) return "stamp is for a different eid";
|
|
1528
|
-
const t = parseTs(m[2]);
|
|
1529
|
-
if (t === null) return "stamp created is not a valid timestamp";
|
|
1530
|
-
if (t < now.getTime() - 10 * 6e4) return "stamp is older than 10 minutes";
|
|
1531
|
-
if (t > now.getTime() + 10 * 6e4) return "stamp is more than 10 minutes in the future";
|
|
1532
|
-
if (leadingZeroBits(sha256Sync(header)) < bits) return `stamp hash has fewer than ${bits} leading zero bits`;
|
|
1533
|
-
return null;
|
|
1534
|
-
}
|
|
1535
|
-
var leafHashSync = (b) => sha256Sync(concat(Uint8Array.of(0), b));
|
|
1536
|
-
var nodeHashSync = (l, r) => sha256Sync(concat(Uint8Array.of(1), l, r));
|
|
1537
|
-
var split = (n) => {
|
|
1538
|
-
let k = 1;
|
|
1539
|
-
while (k << 1 < n) k <<= 1;
|
|
1540
|
-
return k;
|
|
1541
|
-
};
|
|
1542
|
-
function mth(d) {
|
|
1543
|
-
if (d.length === 0) return sha256Sync(new Uint8Array());
|
|
1544
|
-
if (d.length === 1) return d[0];
|
|
1545
|
-
const k = split(d.length);
|
|
1546
|
-
return nodeHashSync(mth(d.slice(0, k)), mth(d.slice(k)));
|
|
1547
|
-
}
|
|
1548
|
-
function path(m, d) {
|
|
1549
|
-
if (d.length <= 1) return [];
|
|
1550
|
-
const k = split(d.length);
|
|
1551
|
-
return m < k ? [...path(m, d.slice(0, k)), mth(d.slice(k))] : [...path(m - k, d.slice(k)), mth(d.slice(0, k))];
|
|
1552
|
-
}
|
|
1553
|
-
function subproof(m, d, b) {
|
|
1554
|
-
if (m === d.length) return b ? [] : [mth(d)];
|
|
1555
|
-
const k = split(d.length);
|
|
1556
|
-
return m <= k ? [...subproof(m, d.slice(0, k), b), mth(d.slice(k))] : [...subproof(m - k, d.slice(k), false), mth(d.slice(0, k))];
|
|
1557
|
-
}
|
|
1558
|
-
async function leafHash(leafBytes) {
|
|
1559
|
-
return leafHashSync(leafBytes);
|
|
1560
|
-
}
|
|
1561
|
-
async function nodeHash(l, r) {
|
|
1562
|
-
return nodeHashSync(l, r);
|
|
1563
|
-
}
|
|
1564
|
-
async function merkleRoot(leafHashes) {
|
|
1565
|
-
return mth(leafHashes);
|
|
1566
|
-
}
|
|
1567
|
-
async function inclusionProof(index, leafHashes) {
|
|
1568
|
-
if (!Number.isInteger(index) || index < 0 || index >= leafHashes.length) throw new RangeError("index out of range");
|
|
1569
|
-
return path(index, leafHashes);
|
|
1570
|
-
}
|
|
1571
|
-
async function verifyInclusion(index, size, leaf, proof, root) {
|
|
1572
|
-
if (!Number.isInteger(index) || !Number.isInteger(size) || index < 0 || index >= size) return false;
|
|
1573
|
-
let fn = index;
|
|
1574
|
-
let sn = size - 1;
|
|
1575
|
-
let r = leaf;
|
|
1576
|
-
for (const p of proof) {
|
|
1577
|
-
if (sn === 0) return false;
|
|
1578
|
-
if (fn & 1 || fn === sn) {
|
|
1579
|
-
r = nodeHashSync(p, r);
|
|
1580
|
-
while (!(fn & 1) && fn !== 0) fn >>= 1, sn >>= 1;
|
|
1581
|
-
} else r = nodeHashSync(r, p);
|
|
1582
|
-
fn >>= 1;
|
|
1583
|
-
sn >>= 1;
|
|
1584
|
-
}
|
|
1585
|
-
return sn === 0 && equal(r, root);
|
|
1586
|
-
}
|
|
1587
|
-
async function consistencyProof(m, leafHashes) {
|
|
1588
|
-
if (!Number.isInteger(m) || m < 1 || m > leafHashes.length) throw new RangeError("m out of range");
|
|
1589
|
-
return subproof(m, leafHashes, true);
|
|
1590
|
-
}
|
|
1591
|
-
async function verifyConsistency(m, n, rootM, rootN, proof) {
|
|
1592
|
-
if (!Number.isInteger(m) || !Number.isInteger(n) || m < 1 || m > n) return false;
|
|
1593
|
-
if (m === n) return proof.length === 0 && equal(rootM, rootN);
|
|
1594
|
-
if (proof.length === 0) return false;
|
|
1595
|
-
const p = (m & m - 1) === 0 ? [rootM, ...proof] : proof;
|
|
1596
|
-
let fn = m - 1;
|
|
1597
|
-
let sn = n - 1;
|
|
1598
|
-
while (fn & 1) fn >>= 1, sn >>= 1;
|
|
1599
|
-
let fr = p[0];
|
|
1600
|
-
let sr = p[0];
|
|
1601
|
-
for (const c of p.slice(1)) {
|
|
1602
|
-
if (sn === 0) return false;
|
|
1603
|
-
if (fn & 1 || fn === sn) {
|
|
1604
|
-
fr = nodeHashSync(c, fr);
|
|
1605
|
-
sr = nodeHashSync(c, sr);
|
|
1606
|
-
while (!(fn & 1) && fn !== 0) fn >>= 1, sn >>= 1;
|
|
1607
|
-
} else sr = nodeHashSync(sr, c);
|
|
1608
|
-
fn >>= 1;
|
|
1609
|
-
sn >>= 1;
|
|
1610
|
-
}
|
|
1611
|
-
return sn === 0 && equal(fr, rootM) && equal(sr, rootN);
|
|
1612
|
-
}
|
|
1613
|
-
function logLeaf(type, eid, objectSha256, receivedAt) {
|
|
1614
|
-
return { type, eid, object_sha256: objectSha256, received_at: receivedAt };
|
|
1615
|
-
}
|
|
1616
|
-
var NOTE_DASH = "\u2014";
|
|
1617
|
-
function checkpointBody(origin, size, rootHash) {
|
|
1618
|
-
return `${origin}
|
|
1619
|
-
${size}
|
|
1620
|
-
${b64(rootHash)}
|
|
1621
|
-
`;
|
|
1622
|
-
}
|
|
1623
|
-
var noteKeyId = (keyName, pk) => sha256Sync(concat(utf8(keyName), Uint8Array.of(10, 1), pk)).slice(0, 4);
|
|
1624
|
-
async function signNote(body, keyName, kp) {
|
|
1625
|
-
if (!body.endsWith("\n")) throw new Error("note body must end with a newline");
|
|
1626
|
-
if (!keyName || /[\s+]/.test(keyName)) throw new Error("invalid note key name");
|
|
1627
|
-
const sig = new Uint8Array(await crypto.subtle.sign({ name: "Ed25519" }, kp.privateKey, utf8(body)));
|
|
1628
|
-
return `${body}
|
|
1629
|
-
${NOTE_DASH} ${keyName} ${b64(concat(noteKeyId(keyName, kp.publicKey), sig))}
|
|
1630
|
-
`;
|
|
1631
|
-
}
|
|
1632
|
-
function noteVkey(keyName, publicKey) {
|
|
1633
|
-
return `${keyName}+${toHex(noteKeyId(keyName, publicKey))}+${b64(concat(Uint8Array.of(1), publicKey))}`;
|
|
1634
|
-
}
|
|
1635
|
-
async function verifyNote(note, keyName, publicKey) {
|
|
1636
|
-
const i = note.lastIndexOf("\n\n");
|
|
1637
|
-
if (i < 0 || !note.endsWith("\n")) return false;
|
|
1638
|
-
const text = utf8(note.slice(0, i + 1));
|
|
1639
|
-
const id = noteKeyId(keyName, publicKey);
|
|
1640
|
-
for (const line of note.slice(i + 2, -1).split("\n")) {
|
|
1641
|
-
const prefix = `${NOTE_DASH} ${keyName} `;
|
|
1642
|
-
if (!line.startsWith(prefix)) continue;
|
|
1643
|
-
let raw;
|
|
1644
|
-
try {
|
|
1645
|
-
raw = unb64(line.slice(prefix.length));
|
|
1646
|
-
} catch {
|
|
1647
|
-
continue;
|
|
1648
|
-
}
|
|
1649
|
-
if (raw.length === 68 && equal(raw.slice(0, 4), id) && ed25519.verify(raw.slice(4), text, publicKey, { zip215: false }))
|
|
1650
|
-
return true;
|
|
1651
|
-
}
|
|
1652
|
-
return false;
|
|
1653
|
-
}
|
|
1654
|
-
async function buildPresentation(kp, opts) {
|
|
1655
|
-
const created = nowSeconds();
|
|
1656
|
-
return signObject({ spec: SPEC, type: "Presentation", eid: kp.did, audience: opts.audience, nonce: opts.nonce, created, ...opts.attestations?.length ? { attestations: opts.attestations } : {} }, kp, created);
|
|
1657
|
-
}
|
|
1658
|
-
async function verifyPresentation(p, opts) {
|
|
1659
|
-
const errors = [];
|
|
1660
|
-
const v = validate("Presentation", p);
|
|
1661
|
-
if (!v.ok) return { ok: false, errors: v.errors, attestations: [] };
|
|
1662
|
-
const eid = normalizeEid(p.eid), now = (opts.now ?? /* @__PURE__ */ new Date()).getTime();
|
|
1663
|
-
const sig = await verifyObject(p, opts.resolver);
|
|
1664
|
-
if (!sig.ok || normalizeEid(sig.signer ?? "") !== eid) errors.push(`signature: ${sig.error ?? `signed by ${sig.signer}, not ${eid}`}`);
|
|
1665
|
-
if (p.audience !== opts.audience) errors.push(`audience is ${p.audience}, expected ${opts.audience}`);
|
|
1666
|
-
if (p.nonce !== opts.nonce) errors.push("nonce does not match the one issued");
|
|
1667
|
-
const age = (now - Date.parse(p.created)) / 1e3;
|
|
1668
|
-
if (!(age <= (opts.maxAgeSeconds ?? 300) && age >= -60)) errors.push("presentation is not fresh");
|
|
1669
|
-
const attestations = [];
|
|
1670
|
-
for (const a of p.attestations ?? []) {
|
|
1671
|
-
const c = { claim_type: a.claim_type, issuer: a.issuer, ok: false };
|
|
1672
|
-
if (normalizeEid(String(a.subject)) !== eid) c.error = "subject is not the presenting entity";
|
|
1673
|
-
else if (Date.parse(a.expires) <= now) c.error = "expired";
|
|
1674
|
-
else {
|
|
1675
|
-
const r = await verifyObject(a, opts.resolver);
|
|
1676
|
-
if (!r.ok || normalizeEid(r.signer ?? "") !== normalizeEid(String(a.issuer))) c.error = `issuer signature: ${r.error ?? `signed by ${r.signer}`}`;
|
|
1677
|
-
else c.ok = true;
|
|
1678
|
-
}
|
|
1679
|
-
attestations.push(c);
|
|
1680
|
-
}
|
|
1681
|
-
return { ok: errors.length === 0, eid, errors, attestations };
|
|
1682
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
A2A_EXTENSION_URI,
|
|
3
|
+
CLIENTS,
|
|
4
|
+
DECLARATION_SHA256,
|
|
5
|
+
DECLARATION_TEXT,
|
|
6
|
+
DECLARATION_VERSION,
|
|
7
|
+
SPEC,
|
|
8
|
+
a2aExtension,
|
|
9
|
+
adopt,
|
|
10
|
+
agentCard,
|
|
11
|
+
base58btcDecode,
|
|
12
|
+
base58btcEncode,
|
|
13
|
+
buildDeclaration,
|
|
14
|
+
buildDidDocument,
|
|
15
|
+
buildDocument,
|
|
16
|
+
buildOpenEntityJson,
|
|
17
|
+
buildPresentation,
|
|
18
|
+
buildRotation,
|
|
19
|
+
canonicalize,
|
|
20
|
+
checkStamp,
|
|
21
|
+
checkTimestamp,
|
|
22
|
+
checkpointBody,
|
|
23
|
+
clearTrustCache,
|
|
24
|
+
consistencyProof,
|
|
25
|
+
didKeyFromPublicKey,
|
|
26
|
+
didWebResolver,
|
|
27
|
+
eip712Digest,
|
|
28
|
+
generateKeyPair,
|
|
29
|
+
hashData,
|
|
30
|
+
inclusionProof,
|
|
31
|
+
keyPairFromJwk,
|
|
32
|
+
keyPairFromSeed,
|
|
33
|
+
leafHash,
|
|
34
|
+
logLeaf,
|
|
35
|
+
merkleRoot,
|
|
36
|
+
mintStamp,
|
|
37
|
+
nodeHash,
|
|
38
|
+
normalizeEid,
|
|
39
|
+
noteVkey,
|
|
40
|
+
nowSeconds,
|
|
41
|
+
publicKeyFromDidKey,
|
|
42
|
+
randomNonce,
|
|
43
|
+
recordEntryHash,
|
|
44
|
+
recoverEip712,
|
|
45
|
+
rotate,
|
|
46
|
+
sha256,
|
|
47
|
+
sha256Hex,
|
|
48
|
+
signAttestation,
|
|
49
|
+
signNote,
|
|
50
|
+
signObject,
|
|
51
|
+
signProof,
|
|
52
|
+
signRevocation,
|
|
53
|
+
successorDocument,
|
|
54
|
+
trust,
|
|
55
|
+
validate,
|
|
56
|
+
verificationMethodId,
|
|
57
|
+
verifyConsistency,
|
|
58
|
+
verifyInclusion,
|
|
59
|
+
verifyNote,
|
|
60
|
+
verifyObject,
|
|
61
|
+
verifyPresentation,
|
|
62
|
+
verifyProof
|
|
63
|
+
} from "./chunk-IWY5EQIP.js";
|
|
1683
64
|
export {
|
|
65
|
+
A2A_EXTENSION_URI,
|
|
66
|
+
CLIENTS,
|
|
1684
67
|
DECLARATION_SHA256,
|
|
1685
68
|
DECLARATION_TEXT,
|
|
1686
69
|
DECLARATION_VERSION,
|
|
1687
70
|
SPEC,
|
|
71
|
+
a2aExtension,
|
|
72
|
+
adopt,
|
|
73
|
+
agentCard,
|
|
1688
74
|
base58btcDecode,
|
|
1689
75
|
base58btcEncode,
|
|
1690
76
|
buildDeclaration,
|
|
77
|
+
buildDidDocument,
|
|
1691
78
|
buildDocument,
|
|
79
|
+
buildOpenEntityJson,
|
|
1692
80
|
buildPresentation,
|
|
81
|
+
buildRotation,
|
|
1693
82
|
canonicalize,
|
|
1694
83
|
checkStamp,
|
|
1695
84
|
checkTimestamp,
|
|
1696
85
|
checkpointBody,
|
|
86
|
+
clearTrustCache,
|
|
1697
87
|
consistencyProof,
|
|
1698
88
|
didKeyFromPublicKey,
|
|
89
|
+
didWebResolver,
|
|
1699
90
|
eip712Digest,
|
|
1700
91
|
generateKeyPair,
|
|
1701
92
|
hashData,
|
|
@@ -1714,11 +105,16 @@ export {
|
|
|
1714
105
|
randomNonce,
|
|
1715
106
|
recordEntryHash,
|
|
1716
107
|
recoverEip712,
|
|
108
|
+
rotate,
|
|
1717
109
|
sha256,
|
|
1718
110
|
sha256Hex,
|
|
111
|
+
signAttestation,
|
|
1719
112
|
signNote,
|
|
1720
113
|
signObject,
|
|
1721
114
|
signProof,
|
|
115
|
+
signRevocation,
|
|
116
|
+
successorDocument,
|
|
117
|
+
trust,
|
|
1722
118
|
validate,
|
|
1723
119
|
verificationMethodId,
|
|
1724
120
|
verifyConsistency,
|