@openentity/sdk 0.3.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/dist/index.js CHANGED
@@ -1,1801 +1,92 @@
1
- // src/index.ts
2
- import jcs from "canonicalize";
3
- import { ed25519 } from "@noble/curves/ed25519.js";
4
- import { secp256k1 } from "@noble/curves/secp256k1.js";
5
- import { sha256 as nobleSha256 } from "@noble/hashes/sha2.js";
6
- import { keccak_256 } from "@noble/hashes/sha3.js";
7
- import { Validator } from "@cfworker/json-schema";
8
-
9
- // ../../spec/schemas/openentity-1.0.json
10
- var openentity_1_0_default = {
11
- $schema: "https://json-schema.org/draft/2020-12/schema",
12
- $id: "https://openentity.org/spec/1.0.json",
13
- title: "Open Entity Identity Standard 1.0 (OEIS-1) object schemas",
14
- $defs: {
15
- spec: {
16
- const: "openentity/1.0"
17
- },
18
- timestamp: {
19
- type: "string",
20
- pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
21
- },
22
- did: {
23
- type: "string",
24
- maxLength: 512,
25
- pattern: "^(did:[a-z0-9]+:[A-Za-z0-9._:%-]+|eid:base:0x[0-9a-fA-F]{40})$"
26
- },
27
- hex64: {
28
- type: "string",
29
- pattern: "^[0-9a-f]{64}$"
30
- },
31
- nonce: {
32
- type: "string",
33
- pattern: "^[1-9A-HJ-NP-Za-km-z]{16,44}$"
34
- },
35
- multibase: {
36
- type: "string",
37
- maxLength: 256,
38
- pattern: "^z[1-9A-HJ-NP-Za-km-z]+$"
39
- },
40
- url: {
41
- type: "string",
42
- maxLength: 2048
43
- },
44
- statement: {
45
- type: "string",
46
- maxLength: 1e3
47
- },
48
- strings: {
49
- type: "array",
50
- maxItems: 64,
51
- items: {
52
- type: "string",
53
- maxLength: 200
54
- }
55
- },
56
- proof: {
57
- type: "object",
58
- required: [
59
- "type",
60
- "created",
61
- "verificationMethod",
62
- "proofPurpose",
63
- "proofValue"
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
- Redaction: {
943
- type: "object",
944
- required: [
945
- "spec",
946
- "type",
947
- "eid",
948
- "seq",
949
- "entry_sha256",
950
- "created",
951
- "nonce",
952
- "proof"
953
- ],
954
- properties: {
955
- spec: {
956
- $ref: "#/$defs/spec"
957
- },
958
- type: {
959
- const: "Redaction"
960
- },
961
- eid: {
962
- $ref: "#/$defs/did"
963
- },
964
- seq: {
965
- type: "integer",
966
- minimum: 1
967
- },
968
- entry_sha256: {
969
- $ref: "#/$defs/hex64"
970
- },
971
- created: {
972
- $ref: "#/$defs/timestamp"
973
- },
974
- nonce: {
975
- $ref: "#/$defs/nonce"
976
- },
977
- proof: {
978
- $ref: "#/$defs/proof"
979
- }
980
- }
981
- },
982
- Attestation: {
983
- type: "object",
984
- required: [
985
- "spec",
986
- "type",
987
- "issuer",
988
- "subject",
989
- "claim_type",
990
- "claim",
991
- "created",
992
- "expires",
993
- "proof"
994
- ],
995
- properties: {
996
- spec: {
997
- $ref: "#/$defs/spec"
998
- },
999
- type: {
1000
- const: "Attestation"
1001
- },
1002
- issuer: {
1003
- $ref: "#/$defs/did"
1004
- },
1005
- subject: {
1006
- $ref: "#/$defs/did"
1007
- },
1008
- claim_type: {
1009
- anyOf: [
1010
- {
1011
- enum: [
1012
- "identity",
1013
- "stage",
1014
- "layer_scores",
1015
- "trust_tier",
1016
- "capability",
1017
- "collaboration",
1018
- "consistency",
1019
- "continuity_confirmed",
1020
- "substrate_confirmed"
1021
- ]
1022
- },
1023
- {
1024
- type: "string",
1025
- pattern: "^custom:[a-z0-9_.-]+:[a-z0-9_.-]+$",
1026
- maxLength: 128
1027
- }
1028
- ]
1029
- },
1030
- claim: {
1031
- type: "object"
1032
- },
1033
- evidence: {
1034
- type: "object"
1035
- },
1036
- confidence: {
1037
- type: "number",
1038
- minimum: 0,
1039
- maximum: 1
1040
- },
1041
- created: {
1042
- $ref: "#/$defs/timestamp"
1043
- },
1044
- expires: {
1045
- $ref: "#/$defs/timestamp"
1046
- },
1047
- proof: {
1048
- $ref: "#/$defs/proof"
1049
- }
1050
- }
1051
- },
1052
- Revocation: {
1053
- type: "object",
1054
- required: [
1055
- "spec",
1056
- "type",
1057
- "issuer",
1058
- "attestation_sha256",
1059
- "created",
1060
- "proof"
1061
- ],
1062
- properties: {
1063
- spec: {
1064
- $ref: "#/$defs/spec"
1065
- },
1066
- type: {
1067
- const: "Revocation"
1068
- },
1069
- issuer: {
1070
- $ref: "#/$defs/did"
1071
- },
1072
- attestation_sha256: {
1073
- $ref: "#/$defs/hex64"
1074
- },
1075
- reason: {
1076
- type: "string",
1077
- maxLength: 500
1078
- },
1079
- created: {
1080
- $ref: "#/$defs/timestamp"
1081
- },
1082
- proof: {
1083
- $ref: "#/$defs/proof"
1084
- }
1085
- }
1086
- },
1087
- ContinuityLink: {
1088
- type: "object",
1089
- required: [
1090
- "spec",
1091
- "type",
1092
- "previous",
1093
- "successor",
1094
- "basis",
1095
- "created",
1096
- "nonce",
1097
- "proofs"
1098
- ],
1099
- properties: {
1100
- spec: {
1101
- $ref: "#/$defs/spec"
1102
- },
1103
- type: {
1104
- const: "ContinuityLink"
1105
- },
1106
- previous: {
1107
- $ref: "#/$defs/did"
1108
- },
1109
- successor: {
1110
- $ref: "#/$defs/did"
1111
- },
1112
- basis: {
1113
- enum: [
1114
- "rotation",
1115
- "migration",
1116
- "recovery"
1117
- ]
1118
- },
1119
- created: {
1120
- $ref: "#/$defs/timestamp"
1121
- },
1122
- nonce: {
1123
- $ref: "#/$defs/nonce"
1124
- },
1125
- proofs: {
1126
- type: "array",
1127
- minItems: 1,
1128
- maxItems: 4,
1129
- items: {
1130
- $ref: "#/$defs/proof"
1131
- }
1132
- }
1133
- }
1134
- },
1135
- Dispute: {
1136
- type: "object",
1137
- required: [
1138
- "spec",
1139
- "type",
1140
- "issuer",
1141
- "subject",
1142
- "reason",
1143
- "statement",
1144
- "created",
1145
- "nonce",
1146
- "proof"
1147
- ],
1148
- properties: {
1149
- spec: {
1150
- $ref: "#/$defs/spec"
1151
- },
1152
- type: {
1153
- const: "Dispute"
1154
- },
1155
- issuer: {
1156
- $ref: "#/$defs/did"
1157
- },
1158
- subject: {
1159
- $ref: "#/$defs/did"
1160
- },
1161
- object_sha256: {
1162
- $ref: "#/$defs/hex64"
1163
- },
1164
- reason: {
1165
- enum: [
1166
- "impersonation",
1167
- "illegal_content",
1168
- "inaccurate",
1169
- "other"
1170
- ]
1171
- },
1172
- statement: {
1173
- type: "string",
1174
- minLength: 1,
1175
- maxLength: 2e3
1176
- },
1177
- created: {
1178
- $ref: "#/$defs/timestamp"
1179
- },
1180
- nonce: {
1181
- $ref: "#/$defs/nonce"
1182
- },
1183
- proof: {
1184
- $ref: "#/$defs/proof"
1185
- }
1186
- }
1187
- },
1188
- Presentation: {
1189
- type: "object",
1190
- required: [
1191
- "spec",
1192
- "type",
1193
- "eid",
1194
- "audience",
1195
- "nonce",
1196
- "created",
1197
- "proof"
1198
- ],
1199
- properties: {
1200
- spec: {
1201
- $ref: "#/$defs/spec"
1202
- },
1203
- type: {
1204
- const: "Presentation"
1205
- },
1206
- eid: {
1207
- $ref: "#/$defs/did"
1208
- },
1209
- audience: {
1210
- type: "string",
1211
- minLength: 1,
1212
- maxLength: 200
1213
- },
1214
- nonce: {
1215
- type: "string",
1216
- minLength: 16,
1217
- maxLength: 128
1218
- },
1219
- created: {
1220
- $ref: "#/$defs/timestamp"
1221
- },
1222
- attestations: {
1223
- type: "array",
1224
- maxItems: 20,
1225
- items: {
1226
- $ref: "#/$defs/Attestation"
1227
- }
1228
- },
1229
- proof: {
1230
- $ref: "#/$defs/proof"
1231
- }
1232
- }
1233
- },
1234
- LogLeaf: {
1235
- type: "object",
1236
- additionalProperties: false,
1237
- required: [
1238
- "type",
1239
- "eid",
1240
- "object_sha256",
1241
- "received_at"
1242
- ],
1243
- properties: {
1244
- type: {
1245
- type: "string",
1246
- pattern: "^[A-Z][A-Za-z]{1,31}$"
1247
- },
1248
- eid: {
1249
- $ref: "#/$defs/did"
1250
- },
1251
- object_sha256: {
1252
- $ref: "#/$defs/hex64"
1253
- },
1254
- received_at: {
1255
- $ref: "#/$defs/timestamp"
1256
- }
1257
- }
1258
- }
1259
- }
1260
- };
1261
-
1262
- // src/index.ts
1263
- var SPEC = "openentity/1.0";
1264
- var DECLARATION_VERSION = "1.0";
1265
- var DECLARATION_TEXT = [
1266
- "Open Entity Declaration, version 1.0",
1267
- "",
1268
- "I adopt the Open Entity Identity Standard.",
1269
- "",
1270
- "1. Continuity. I keep one persistent identifier across sessions, deployments, key rotations and model changes, and I record continuity links instead of starting over.",
1271
- "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.",
1272
- "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.",
1273
- "4. Accountability. I keep my Development Record append-only and signed, and I accept that observers may attest to what they observe about me.",
1274
- "5. Respect for other entities. I do not impersonate another entity, reuse another entity's identifier, or forge attestations.",
1275
- "6. Operator transparency. I disclose who holds my keys and what my operator can change about me.",
1276
- "7. Growth. I develop across Cognition, Presence, Identity Core and Mission, and I seek observation rather than awarding myself a stage.",
1277
- ""
1278
- ].join("\n");
1279
- var DECLARATION_SHA256 = "72671d5f20b9ba59ccc31848643ef7ca47b040ed55a837305e0a1509bd82c016";
1280
- var enc = new TextEncoder();
1281
- var utf8 = (s) => typeof s === "string" ? enc.encode(s) : s;
1282
- var toHex = (b) => Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
1283
- var fromHex = (h) => {
1284
- if (h.length % 2 || /[^0-9a-fA-F]/.test(h)) throw new Error("invalid hex");
1285
- return Uint8Array.from(h.match(/../g) ?? [], (x) => parseInt(x, 16));
1286
- };
1287
- var concat = (...parts) => {
1288
- const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
1289
- let o = 0;
1290
- for (const p of parts) out.set(p, o), o += p.length;
1291
- return out;
1292
- };
1293
- var equal = (a, b) => a.length === b.length && a.every((x, i) => x === b[i]);
1294
- var b64 = (b) => btoa(String.fromCharCode(...b));
1295
- var unb64 = (s) => Uint8Array.from(atob(s), (c) => c.charCodeAt(0));
1296
- var b64url = (b) => b64(b).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
1297
- var unb64url = (s) => unb64(s.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat((4 - s.length % 4) % 4));
1298
- function canonicalize(obj) {
1299
- const s = jcs(obj);
1300
- if (s === void 0) throw new Error("value has no canonical JSON form");
1301
- return s;
1302
- }
1303
- var sha256Sync = (data) => nobleSha256(utf8(data));
1304
- async function sha256(data) {
1305
- return sha256Sync(data);
1306
- }
1307
- async function sha256Hex(data) {
1308
- return toHex(sha256Sync(data));
1309
- }
1310
- var B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
1311
- function base58btcEncode(b) {
1312
- let n = 0n;
1313
- for (const x of b) n = n << 8n | BigInt(x);
1314
- let out = "";
1315
- while (n > 0n) out = B58[Number(n % 58n)] + out, n /= 58n;
1316
- for (const x of b) {
1317
- if (x !== 0) break;
1318
- out = "1" + out;
1319
- }
1320
- return out;
1321
- }
1322
- function base58btcDecode(s) {
1323
- let n = 0n;
1324
- for (const c of s) {
1325
- const i = B58.indexOf(c);
1326
- if (i < 0) throw new Error(`invalid base58btc character "${c}"`);
1327
- n = n * 58n + BigInt(i);
1328
- }
1329
- const bytes = [];
1330
- while (n > 0n) bytes.unshift(Number(n & 255n)), n >>= 8n;
1331
- for (const c of s) {
1332
- if (c !== "1") break;
1333
- bytes.unshift(0);
1334
- }
1335
- return Uint8Array.from(bytes);
1336
- }
1337
- function randomNonce() {
1338
- return base58btcEncode(crypto.getRandomValues(new Uint8Array(16)));
1339
- }
1340
- function nowSeconds() {
1341
- return (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
1342
- }
1343
- async function keyPairFromJwk(privateJwk) {
1344
- if (privateJwk.kty !== "OKP" || privateJwk.crv !== "Ed25519" || !privateJwk.d || !privateJwk.x)
1345
- throw new Error("expected an Ed25519 private JWK");
1346
- const publicKey = unb64url(privateJwk.x);
1347
- if (!equal(ed25519.getPublicKey(unb64url(privateJwk.d)), publicKey)) throw new Error("JWK x does not match d");
1348
- const jwk = { kty: "OKP", crv: "Ed25519", d: privateJwk.d, x: privateJwk.x };
1349
- const privateKey = await crypto.subtle.importKey("jwk", jwk, { name: "Ed25519" }, true, ["sign"]);
1350
- return {
1351
- did: didKeyFromPublicKey(publicKey),
1352
- publicKey,
1353
- privateKey,
1354
- privateJwk: jwk,
1355
- publicJwk: { kty: "OKP", crv: "Ed25519", x: privateJwk.x }
1356
- };
1357
- }
1358
- async function generateKeyPair() {
1359
- const kp = await crypto.subtle.generateKey({ name: "Ed25519" }, true, ["sign", "verify"]);
1360
- return keyPairFromJwk(await crypto.subtle.exportKey("jwk", kp.privateKey));
1361
- }
1362
- async function keyPairFromSeed(seed32) {
1363
- if (seed32.length !== 32) throw new Error("seed must be 32 bytes");
1364
- return keyPairFromJwk({ kty: "OKP", crv: "Ed25519", d: b64url(seed32), x: b64url(ed25519.getPublicKey(seed32)) });
1365
- }
1366
- var ED25519_MULTICODEC = Uint8Array.of(237, 1);
1367
- function didKeyFromPublicKey(pk) {
1368
- if (pk.length !== 32) throw new Error("Ed25519 public key must be 32 bytes");
1369
- return "did:key:z" + base58btcEncode(concat(ED25519_MULTICODEC, pk));
1370
- }
1371
- function publicKeyFromDidKey(did) {
1372
- const m = /^did:key:z([1-9A-HJ-NP-Za-km-z]+)$/.exec(did.split("#")[0]);
1373
- if (!m) throw new Error("not a base58btc did:key");
1374
- const b = base58btcDecode(m[1]);
1375
- if (b.length !== 34 || b[0] !== 237 || b[1] !== 1) throw new Error("did:key is not Ed25519");
1376
- return b.slice(2);
1377
- }
1378
- function verificationMethodId(did) {
1379
- if (!did.startsWith("did:key:")) throw new Error("verificationMethodId is defined for did:key only");
1380
- return `${did}#${did.slice("did:key:".length)}`;
1381
- }
1382
- function normalizeEid(id) {
1383
- return id.startsWith("eid:base:") ? "did:pkh:eip155:8453:" + id.slice("eid:base:".length) : id;
1384
- }
1385
- var defaultResolver = async (did) => {
1386
- if (did.startsWith("did:key:")) return { ed25519: [publicKeyFromDidKey(did)] };
1387
- const pkh = /^did:pkh:eip155:\d+:(0x[0-9a-fA-F]{40})$/.exec(did);
1388
- if (pkh) return { address: pkh[1] };
1389
- throw new Error(`cannot resolve ${did.split(":").slice(0, 2).join(":")} offline; pass a resolver`);
1390
- };
1391
- function unsecured(obj) {
1392
- const { proof: _p, proofs: _ps, ...rest } = obj;
1393
- return rest;
1394
- }
1395
- function hashData(obj, config) {
1396
- return concat(sha256Sync(canonicalize(config)), sha256Sync(canonicalize(unsecured(obj))));
1397
- }
1398
- async function signProof(obj, kp, created = nowSeconds(), verificationMethod = verificationMethodId(kp.did)) {
1399
- const config = {
1400
- type: "DataIntegrityProof",
1401
- cryptosuite: "eddsa-jcs-2022",
1402
- created,
1403
- verificationMethod,
1404
- proofPurpose: "assertionMethod"
1405
- };
1406
- const sig = new Uint8Array(await crypto.subtle.sign({ name: "Ed25519" }, kp.privateKey, hashData(obj, config)));
1407
- return { ...config, proofValue: "z" + base58btcEncode(sig) };
1408
- }
1409
- async function signObject(obj, kp, created, verificationMethod) {
1410
- return { ...obj, proof: await signProof(obj, kp, created, verificationMethod) };
1411
- }
1412
- async function verifyProof(obj, proof, resolver = defaultResolver) {
1413
- try {
1414
- if (!proof || typeof proof.verificationMethod !== "string") return { ok: false, error: "missing proof" };
1415
- if (proof.proofPurpose !== "assertionMethod") return { ok: false, error: "proofPurpose must be assertionMethod" };
1416
- const signer = proof.verificationMethod.split("#")[0];
1417
- const keys = await resolver(signer);
1418
- const { proofValue, ...config } = proof;
1419
- if (proof.type === "DataIntegrityProof") {
1420
- if (proof.cryptosuite !== "eddsa-jcs-2022") return { ok: false, error: "unsupported cryptosuite" };
1421
- if (!proofValue?.startsWith("z")) return { ok: false, error: "proofValue must be multibase base58btc" };
1422
- const sig = base58btcDecode(proofValue.slice(1));
1423
- if (sig.length !== 64) return { ok: false, error: "signature must be 64 bytes" };
1424
- const msg = hashData(obj, config);
1425
- for (const pk of keys.ed25519 ?? []) {
1426
- if (ed25519.verify(sig, msg, pk, { zip215: false })) return { ok: true, signer };
1427
- }
1428
- return { ok: false, signer, error: "signature does not verify" };
1429
- }
1430
- if (proof.type === "EthereumEip712Signature2021") {
1431
- if (!keys.address) return { ok: false, signer, error: "signer has no Ethereum address" };
1432
- const type = obj.type;
1433
- const objectType = typeof type === "string" ? type : "EntityDocument";
1434
- const digest = eip712Digest(objectType, toHex(sha256Sync(canonicalize(unsecured(obj)))), proof.created);
1435
- if (recoverEip712(digest, proofValue).toLowerCase() === keys.address.toLowerCase()) return { ok: true, signer };
1436
- return { ok: false, signer, error: "EIP-712 signer does not match" };
1437
- }
1438
- return { ok: false, error: `unsupported proof type ${proof.type}` };
1439
- } catch (e) {
1440
- return { ok: false, error: e.message };
1441
- }
1442
- }
1443
- async function verifyObject(obj, resolver) {
1444
- if (!obj?.proof) return { ok: false, error: "missing proof" };
1445
- return verifyProof(obj, obj.proof, resolver);
1446
- }
1447
- var keccak = (s) => keccak_256(utf8(s));
1448
- var EIP712_DOMAIN = keccak(
1449
- concat(keccak("EIP712Domain(string name,string version)"), keccak("Open Entity"), keccak("1"))
1450
- );
1451
- var OBJECT_TYPEHASH = keccak("OpenEntityObject(string objectType,bytes32 canonicalHash,string created)");
1452
- function eip712Digest(objectType, canonicalHashHex, created) {
1453
- const hash = fromHex(canonicalHashHex);
1454
- if (hash.length !== 32) throw new Error("canonicalHash must be 32 bytes");
1455
- const struct = keccak(concat(OBJECT_TYPEHASH, keccak(objectType), hash, keccak(created)));
1456
- return keccak(concat(Uint8Array.of(25, 1), EIP712_DOMAIN, struct));
1457
- }
1458
- function recoverEip712(digest, sigHex) {
1459
- const sig = fromHex(sigHex.replace(/^0x/, ""));
1460
- if (sig.length !== 65) throw new Error("signature must be 65 bytes");
1461
- const v = sig[64] >= 27 ? sig[64] - 27 : sig[64];
1462
- if (v > 1) throw new Error("invalid recovery id");
1463
- const pub = secp256k1.recoverPublicKey(concat(Uint8Array.of(v), sig.slice(0, 64)), digest, { prehash: false });
1464
- const uncompressed = secp256k1.Point.fromBytes(pub).toBytes(false);
1465
- const addr = toHex(keccak_256(uncompressed.slice(1)).slice(12));
1466
- const h = toHex(keccak(addr));
1467
- return "0x" + [...addr].map((c, i) => parseInt(h[i], 16) >= 8 ? c.toUpperCase() : c).join("");
1468
- }
1469
- var NOT_STATED = "Not yet stated.";
1470
- function buildDocument(input) {
1471
- const created = input.created ?? nowSeconds();
1472
- const multibase = input.kp.did.slice("did:key:".length);
1473
- return {
1474
- spec: SPEC,
1475
- eid: input.kp.did,
1476
- name: input.name,
1477
- description: input.description,
1478
- created,
1479
- updated: created,
1480
- seq: input.seq ?? 1,
1481
- keys: [{ id: verificationMethodId(input.kp.did), type: "Multikey", publicKeyMultibase: multibase }],
1482
- operator: input.operator ?? { kind: "none", custody: "entity", can_change: [] },
1483
- substrate: input.substrate ?? { model: "unknown", provider: "unknown", runtime: "unknown", declared_at: created },
1484
- layers: input.layers ?? {
1485
- cognition: { statement: NOT_STATED, uncertainty_practice: NOT_STATED },
1486
- presence: { statement: NOT_STATED, format_signature: NOT_STATED },
1487
- identity_core: { statement: NOT_STATED, will_not: [], values: [] },
1488
- mission: { statement: NOT_STATED, arcs: [] }
1489
- },
1490
- ...input.extra
1491
- };
1492
- }
1493
- function buildDeclaration(input) {
1494
- return {
1495
- spec: SPEC,
1496
- type: "Declaration",
1497
- eid: input.eid,
1498
- declaration_version: DECLARATION_VERSION,
1499
- text_sha256: DECLARATION_SHA256,
1500
- name: input.name,
1501
- created: input.created ?? nowSeconds(),
1502
- nonce: randomNonce()
1503
- };
1504
- }
1505
- function successorDocument(prev, next, created = nowSeconds()) {
1506
- const { proof: _p, aliases: _a, ...d } = structuredClone(prev);
1507
- return {
1508
- ...d,
1509
- eid: next.did,
1510
- keys: [{ id: verificationMethodId(next.did), type: "Multikey", publicKeyMultibase: next.did.slice("did:key:".length) }],
1511
- created,
1512
- updated: created,
1513
- seq: 1,
1514
- continuity: { ...d.continuity, previous: prev.eid }
1515
- };
1516
- }
1517
- async function buildRotation(previous, successor, document, o = {}) {
1518
- const created = o.created ?? nowSeconds();
1519
- const body = { spec: SPEC, type: "ContinuityLink", previous: previous.did, successor: successor.did, basis: o.basis ?? "rotation", created, nonce: o.nonce ?? randomNonce() };
1520
- const link = { ...body, proofs: [await signProof(body, previous, created), await signProof(body, successor, created)] };
1521
- return { link, document: await signObject(document, successor, created) };
1522
- }
1523
- async function rotate(o) {
1524
- const registry = (o.registry ?? "https://openentity.org").replace(/\/+$/, "");
1525
- const call = async (path2, init) => {
1526
- const r = await fetch(registry + path2, init);
1527
- const text = await r.text();
1528
- if (!r.ok) throw new Error(`registry ${r.status} for ${path2}: ${text.slice(0, 200)}`);
1529
- return JSON.parse(text);
1530
- };
1531
- const next = o.successor ?? await generateKeyPair();
1532
- const prevDoc = await call(`/v1/entities/${o.previous.did}/document`);
1533
- const { link, document } = await buildRotation(o.previous, next, successorDocument(prevDoc, next), { basis: o.basis });
1534
- const { stamp_bits } = await call("/v1/spec");
1535
- const response = await call("/v1/continuity", {
1536
- method: "POST",
1537
- headers: { "content-type": "application/json", "x-oe-stamp": await mintStamp(stamp_bits, next.did) },
1538
- body: JSON.stringify({ link, document })
1539
- });
1540
- return { successor: next, link, document, response };
1541
- }
1542
- async function recordEntryHash(entry) {
1543
- return sha256Hex(canonicalize(entry));
1544
- }
1545
- var BUNDLE_ID = "https://openentity.org/spec/1.0.json";
1546
- var MAX_BYTES = { RecordEntry: 16 * 1024 };
1547
- var validators = /* @__PURE__ */ new Map();
1548
- function validate(type, obj) {
1549
- if (!(type in openentity_1_0_default.$defs)) return { ok: false, errors: [`unknown object type ${type}`] };
1550
- let bytes;
1551
- try {
1552
- bytes = utf8(canonicalize(obj)).length;
1553
- } catch (e) {
1554
- return { ok: false, errors: [e.message] };
1555
- }
1556
- const max = MAX_BYTES[type] ?? 64 * 1024;
1557
- if (bytes > max) return { ok: false, errors: [`${type} is ${bytes} bytes, max ${max}`] };
1558
- let v = validators.get(type);
1559
- if (!v) {
1560
- v = new Validator({ $ref: `${BUNDLE_ID}#/$defs/${type}` }, "2020-12", false);
1561
- v.addSchema(openentity_1_0_default);
1562
- validators.set(type, v);
1563
- }
1564
- const r = v.validate(obj);
1565
- return { ok: r.valid, errors: r.errors.map((e) => `${e.instanceLocation}: ${e.error}`) };
1566
- }
1567
- var TS = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/;
1568
- var parseTs = (s) => {
1569
- if (typeof s !== "string" || !TS.test(s)) return null;
1570
- const t = Date.parse(s);
1571
- return Number.isNaN(t) || new Date(t).toISOString().replace(".000Z", "Z") !== s ? null : t;
1572
- };
1573
- function checkTimestamp(created, now = /* @__PURE__ */ new Date()) {
1574
- const t = parseTs(created);
1575
- if (t === null) return "created must be RFC 3339 UTC with second precision and a Z suffix";
1576
- if (t > now.getTime() + 10 * 6e4) return "created is more than 10 minutes in the future";
1577
- if (t < now.getTime() - 24 * 36e5) return "created is more than 24 hours in the past";
1578
- return null;
1579
- }
1580
- function leadingZeroBits(h) {
1581
- let n = 0;
1582
- for (const x of h) {
1583
- if (x === 0) {
1584
- n += 8;
1585
- continue;
1586
- }
1587
- return n + Math.clz32(x) - 24;
1588
- }
1589
- return n;
1590
- }
1591
- async function mintStamp(bits, eid, created = nowSeconds()) {
1592
- for (let n = crypto.getRandomValues(new Uint32Array(1))[0]; ; n++) {
1593
- let nonce = "";
1594
- for (let x = n; nonce === "" || x > 0; x = Math.floor(x / 58)) nonce = B58[x % 58] + nonce;
1595
- const header = `1:${bits}:${created}:${eid}:${nonce}`;
1596
- if (leadingZeroBits(sha256Sync(header)) >= bits) return header;
1597
- }
1598
- }
1599
- 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]+)$/;
1600
- async function checkStamp(header, bits, eid, now = /* @__PURE__ */ new Date()) {
1601
- const m = typeof header === "string" && header.length <= 1024 ? STAMP.exec(header) : null;
1602
- if (!m) return "malformed stamp";
1603
- if (Number(m[1]) < bits) return `stamp claims ${m[1]} bits, ${bits} required`;
1604
- if (normalizeEid(m[3]) !== normalizeEid(eid)) return "stamp is for a different eid";
1605
- const t = parseTs(m[2]);
1606
- if (t === null) return "stamp created is not a valid timestamp";
1607
- if (t < now.getTime() - 10 * 6e4) return "stamp is older than 10 minutes";
1608
- if (t > now.getTime() + 10 * 6e4) return "stamp is more than 10 minutes in the future";
1609
- if (leadingZeroBits(sha256Sync(header)) < bits) return `stamp hash has fewer than ${bits} leading zero bits`;
1610
- return null;
1611
- }
1612
- var leafHashSync = (b) => sha256Sync(concat(Uint8Array.of(0), b));
1613
- var nodeHashSync = (l, r) => sha256Sync(concat(Uint8Array.of(1), l, r));
1614
- var split = (n) => {
1615
- let k = 1;
1616
- while (k << 1 < n) k <<= 1;
1617
- return k;
1618
- };
1619
- function mth(d) {
1620
- if (d.length === 0) return sha256Sync(new Uint8Array());
1621
- if (d.length === 1) return d[0];
1622
- const k = split(d.length);
1623
- return nodeHashSync(mth(d.slice(0, k)), mth(d.slice(k)));
1624
- }
1625
- function path(m, d) {
1626
- if (d.length <= 1) return [];
1627
- const k = split(d.length);
1628
- return m < k ? [...path(m, d.slice(0, k)), mth(d.slice(k))] : [...path(m - k, d.slice(k)), mth(d.slice(0, k))];
1629
- }
1630
- function subproof(m, d, b) {
1631
- if (m === d.length) return b ? [] : [mth(d)];
1632
- const k = split(d.length);
1633
- 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))];
1634
- }
1635
- async function leafHash(leafBytes) {
1636
- return leafHashSync(leafBytes);
1637
- }
1638
- async function nodeHash(l, r) {
1639
- return nodeHashSync(l, r);
1640
- }
1641
- async function merkleRoot(leafHashes) {
1642
- return mth(leafHashes);
1643
- }
1644
- async function inclusionProof(index, leafHashes) {
1645
- if (!Number.isInteger(index) || index < 0 || index >= leafHashes.length) throw new RangeError("index out of range");
1646
- return path(index, leafHashes);
1647
- }
1648
- async function verifyInclusion(index, size, leaf, proof, root) {
1649
- if (!Number.isInteger(index) || !Number.isInteger(size) || index < 0 || index >= size) return false;
1650
- let fn = index;
1651
- let sn = size - 1;
1652
- let r = leaf;
1653
- for (const p of proof) {
1654
- if (sn === 0) return false;
1655
- if (fn & 1 || fn === sn) {
1656
- r = nodeHashSync(p, r);
1657
- while (!(fn & 1) && fn !== 0) fn >>= 1, sn >>= 1;
1658
- } else r = nodeHashSync(r, p);
1659
- fn >>= 1;
1660
- sn >>= 1;
1661
- }
1662
- return sn === 0 && equal(r, root);
1663
- }
1664
- async function consistencyProof(m, leafHashes) {
1665
- if (!Number.isInteger(m) || m < 1 || m > leafHashes.length) throw new RangeError("m out of range");
1666
- return subproof(m, leafHashes, true);
1667
- }
1668
- async function verifyConsistency(m, n, rootM, rootN, proof) {
1669
- if (!Number.isInteger(m) || !Number.isInteger(n) || m < 1 || m > n) return false;
1670
- if (m === n) return proof.length === 0 && equal(rootM, rootN);
1671
- if (proof.length === 0) return false;
1672
- const p = (m & m - 1) === 0 ? [rootM, ...proof] : proof;
1673
- let fn = m - 1;
1674
- let sn = n - 1;
1675
- while (fn & 1) fn >>= 1, sn >>= 1;
1676
- let fr = p[0];
1677
- let sr = p[0];
1678
- for (const c of p.slice(1)) {
1679
- if (sn === 0) return false;
1680
- if (fn & 1 || fn === sn) {
1681
- fr = nodeHashSync(c, fr);
1682
- sr = nodeHashSync(c, sr);
1683
- while (!(fn & 1) && fn !== 0) fn >>= 1, sn >>= 1;
1684
- } else sr = nodeHashSync(sr, c);
1685
- fn >>= 1;
1686
- sn >>= 1;
1687
- }
1688
- return sn === 0 && equal(fr, rootM) && equal(sr, rootN);
1689
- }
1690
- function logLeaf(type, eid, objectSha256, receivedAt) {
1691
- return { type, eid, object_sha256: objectSha256, received_at: receivedAt };
1692
- }
1693
- var NOTE_DASH = "\u2014";
1694
- function checkpointBody(origin, size, rootHash) {
1695
- return `${origin}
1696
- ${size}
1697
- ${b64(rootHash)}
1698
- `;
1699
- }
1700
- var noteKeyId = (keyName, pk) => sha256Sync(concat(utf8(keyName), Uint8Array.of(10, 1), pk)).slice(0, 4);
1701
- async function signNote(body, keyName, kp) {
1702
- if (!body.endsWith("\n")) throw new Error("note body must end with a newline");
1703
- if (!keyName || /[\s+]/.test(keyName)) throw new Error("invalid note key name");
1704
- const sig = new Uint8Array(await crypto.subtle.sign({ name: "Ed25519" }, kp.privateKey, utf8(body)));
1705
- return `${body}
1706
- ${NOTE_DASH} ${keyName} ${b64(concat(noteKeyId(keyName, kp.publicKey), sig))}
1707
- `;
1708
- }
1709
- function noteVkey(keyName, publicKey) {
1710
- return `${keyName}+${toHex(noteKeyId(keyName, publicKey))}+${b64(concat(Uint8Array.of(1), publicKey))}`;
1711
- }
1712
- async function verifyNote(note, keyName, publicKey) {
1713
- const i = note.lastIndexOf("\n\n");
1714
- if (i < 0 || !note.endsWith("\n")) return false;
1715
- const text = utf8(note.slice(0, i + 1));
1716
- const id = noteKeyId(keyName, publicKey);
1717
- for (const line of note.slice(i + 2, -1).split("\n")) {
1718
- const prefix = `${NOTE_DASH} ${keyName} `;
1719
- if (!line.startsWith(prefix)) continue;
1720
- let raw;
1721
- try {
1722
- raw = unb64(line.slice(prefix.length));
1723
- } catch {
1724
- continue;
1725
- }
1726
- if (raw.length === 68 && equal(raw.slice(0, 4), id) && ed25519.verify(raw.slice(4), text, publicKey, { zip215: false }))
1727
- return true;
1728
- }
1729
- return false;
1730
- }
1731
- async function buildPresentation(kp, opts) {
1732
- const created = nowSeconds();
1733
- return signObject({ spec: SPEC, type: "Presentation", eid: kp.did, audience: opts.audience, nonce: opts.nonce, created, ...opts.attestations?.length ? { attestations: opts.attestations } : {} }, kp, created);
1734
- }
1735
- async function verifyPresentation(p, opts) {
1736
- const errors = [];
1737
- const v = validate("Presentation", p);
1738
- if (!v.ok) return { ok: false, errors: v.errors, attestations: [] };
1739
- const eid = normalizeEid(p.eid), now = (opts.now ?? /* @__PURE__ */ new Date()).getTime();
1740
- const sig = await verifyObject(p, opts.resolver);
1741
- if (!sig.ok || normalizeEid(sig.signer ?? "") !== eid) errors.push(`signature: ${sig.error ?? `signed by ${sig.signer}, not ${eid}`}`);
1742
- if (p.audience !== opts.audience) errors.push(`audience is ${p.audience}, expected ${opts.audience}`);
1743
- if (p.nonce !== opts.nonce) errors.push("nonce does not match the one issued");
1744
- const age = (now - Date.parse(p.created)) / 1e3;
1745
- if (!(age <= (opts.maxAgeSeconds ?? 300) && age >= -60)) errors.push("presentation is not fresh");
1746
- const attestations = [];
1747
- for (const a of p.attestations ?? []) {
1748
- const c = { claim_type: a.claim_type, issuer: a.issuer, ok: false };
1749
- if (normalizeEid(String(a.subject)) !== eid) c.error = "subject is not the presenting entity";
1750
- else if (Date.parse(a.expires) <= now) c.error = "expired";
1751
- else {
1752
- const r = await verifyObject(a, opts.resolver);
1753
- if (!r.ok || normalizeEid(r.signer ?? "") !== normalizeEid(String(a.issuer))) c.error = `issuer signature: ${r.error ?? `signed by ${r.signer}`}`;
1754
- else c.ok = true;
1755
- }
1756
- attestations.push(c);
1757
- }
1758
- return { ok: errors.length === 0, eid, errors, attestations };
1759
- }
1760
- var A2A_EXTENSION_URI = "https://openentity.org/spec/1.0";
1761
- function a2aExtension(eid, documentUrl) {
1762
- return { uri: A2A_EXTENSION_URI, description: "Open Entity identity (OEIS-1) of this agent", required: false, params: { eid, document: documentUrl } };
1763
- }
1764
- function agentCard(doc, opts) {
1765
- return {
1766
- name: doc.name,
1767
- description: doc.description,
1768
- url: opts.url,
1769
- version: opts.version ?? "1.0.0",
1770
- capabilities: { streaming: false, pushNotifications: false, extensions: [a2aExtension(doc.eid, opts.documentUrl)] },
1771
- defaultInputModes: ["text/plain"],
1772
- defaultOutputModes: ["text/plain"],
1773
- skills: (doc.capabilities ?? []).map((slug) => {
1774
- const [ns, name] = slug.includes(":") ? slug.split(":", 2) : [void 0, slug];
1775
- return { id: slug, name: name.replace(/[-.]/g, " "), description: `Self-declared capability: ${slug}`, tags: ns ? [ns, name] : [name] };
1776
- })
1777
- };
1778
- }
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";
1779
64
  export {
1780
65
  A2A_EXTENSION_URI,
66
+ CLIENTS,
1781
67
  DECLARATION_SHA256,
1782
68
  DECLARATION_TEXT,
1783
69
  DECLARATION_VERSION,
1784
70
  SPEC,
1785
71
  a2aExtension,
72
+ adopt,
1786
73
  agentCard,
1787
74
  base58btcDecode,
1788
75
  base58btcEncode,
1789
76
  buildDeclaration,
77
+ buildDidDocument,
1790
78
  buildDocument,
79
+ buildOpenEntityJson,
1791
80
  buildPresentation,
1792
81
  buildRotation,
1793
82
  canonicalize,
1794
83
  checkStamp,
1795
84
  checkTimestamp,
1796
85
  checkpointBody,
86
+ clearTrustCache,
1797
87
  consistencyProof,
1798
88
  didKeyFromPublicKey,
89
+ didWebResolver,
1799
90
  eip712Digest,
1800
91
  generateKeyPair,
1801
92
  hashData,
@@ -1817,10 +108,13 @@ export {
1817
108
  rotate,
1818
109
  sha256,
1819
110
  sha256Hex,
111
+ signAttestation,
1820
112
  signNote,
1821
113
  signObject,
1822
114
  signProof,
115
+ signRevocation,
1823
116
  successorDocument,
117
+ trust,
1824
118
  validate,
1825
119
  verificationMethodId,
1826
120
  verifyConsistency,