@bcts/xid 1.0.0-alpha.10

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.
@@ -0,0 +1,1038 @@
1
+ import { KnownValue } from "@bcts/known-values";
2
+ import { Envelope, EnvelopeEncodable, PrivateKeyBase, PublicKeyBase, Signer } from "@bcts/envelope";
3
+ import { Reference, Salt, XID } from "@bcts/components";
4
+ import { ProvenanceMark, ProvenanceMarkGenerator, ProvenanceMarkResolution } from "@bcts/provenance-mark";
5
+ import { Cbor } from "@bcts/dcbor";
6
+
7
+ //#region src/error.d.ts
8
+ /**
9
+ * XID Error Types
10
+ *
11
+ * Error types returned when operating on XID Documents.
12
+ * Ported from bc-xid-rust/src/error.rs
13
+ */
14
+ declare enum XIDErrorCode {
15
+ DUPLICATE = "DUPLICATE",
16
+ NOT_FOUND = "NOT_FOUND",
17
+ STILL_REFERENCED = "STILL_REFERENCED",
18
+ EMPTY_VALUE = "EMPTY_VALUE",
19
+ UNKNOWN_PRIVILEGE = "UNKNOWN_PRIVILEGE",
20
+ INVALID_XID = "INVALID_XID",
21
+ MISSING_INCEPTION_KEY = "MISSING_INCEPTION_KEY",
22
+ INVALID_RESOLUTION_METHOD = "INVALID_RESOLUTION_METHOD",
23
+ MULTIPLE_PROVENANCE_MARKS = "MULTIPLE_PROVENANCE_MARKS",
24
+ UNEXPECTED_PREDICATE = "UNEXPECTED_PREDICATE",
25
+ UNEXPECTED_NESTED_ASSERTIONS = "UNEXPECTED_NESTED_ASSERTIONS",
26
+ NO_PERMISSIONS = "NO_PERMISSIONS",
27
+ NO_REFERENCES = "NO_REFERENCES",
28
+ UNKNOWN_KEY_REFERENCE = "UNKNOWN_KEY_REFERENCE",
29
+ UNKNOWN_DELEGATE_REFERENCE = "UNKNOWN_DELEGATE_REFERENCE",
30
+ KEY_NOT_FOUND_IN_DOCUMENT = "KEY_NOT_FOUND_IN_DOCUMENT",
31
+ DELEGATE_NOT_FOUND_IN_DOCUMENT = "DELEGATE_NOT_FOUND_IN_DOCUMENT",
32
+ INVALID_PASSWORD = "INVALID_PASSWORD",
33
+ ENVELOPE_NOT_SIGNED = "ENVELOPE_NOT_SIGNED",
34
+ SIGNATURE_VERIFICATION_FAILED = "SIGNATURE_VERIFICATION_FAILED",
35
+ NO_PROVENANCE_MARK = "NO_PROVENANCE_MARK",
36
+ GENERATOR_CONFLICT = "GENERATOR_CONFLICT",
37
+ NO_GENERATOR = "NO_GENERATOR",
38
+ CHAIN_ID_MISMATCH = "CHAIN_ID_MISMATCH",
39
+ SEQUENCE_MISMATCH = "SEQUENCE_MISMATCH",
40
+ ENVELOPE_PARSING = "ENVELOPE_PARSING",
41
+ COMPONENT = "COMPONENT",
42
+ CBOR = "CBOR",
43
+ PROVENANCE_MARK = "PROVENANCE_MARK",
44
+ }
45
+ declare class XIDError extends Error {
46
+ readonly code: XIDErrorCode;
47
+ readonly cause?: Error;
48
+ constructor(code: XIDErrorCode, message: string, cause?: Error);
49
+ /**
50
+ * Returned when attempting to add a duplicate item.
51
+ */
52
+ static duplicate(item: string): XIDError;
53
+ /**
54
+ * Returned when an item is not found.
55
+ */
56
+ static notFound(item: string): XIDError;
57
+ /**
58
+ * Returned when an item is still referenced by other items.
59
+ */
60
+ static stillReferenced(item: string): XIDError;
61
+ /**
62
+ * Returned when a value is invalid or empty.
63
+ */
64
+ static emptyValue(field: string): XIDError;
65
+ /**
66
+ * Returned when an unknown privilege is encountered.
67
+ */
68
+ static unknownPrivilege(): XIDError;
69
+ /**
70
+ * Returned when the XID is invalid.
71
+ */
72
+ static invalidXid(): XIDError;
73
+ /**
74
+ * Returned when the inception key is missing.
75
+ */
76
+ static missingInceptionKey(): XIDError;
77
+ /**
78
+ * Returned when the resolution method is invalid.
79
+ */
80
+ static invalidResolutionMethod(): XIDError;
81
+ /**
82
+ * Returned when multiple provenance marks are found.
83
+ */
84
+ static multipleProvenanceMarks(): XIDError;
85
+ /**
86
+ * Returned when an unexpected predicate is encountered.
87
+ */
88
+ static unexpectedPredicate(predicate: string): XIDError;
89
+ /**
90
+ * Returned when unexpected nested assertions are found.
91
+ */
92
+ static unexpectedNestedAssertions(): XIDError;
93
+ /**
94
+ * Returned when a service has no permissions.
95
+ */
96
+ static noPermissions(uri: string): XIDError;
97
+ /**
98
+ * Returned when a service has no key or delegate references.
99
+ */
100
+ static noReferences(uri: string): XIDError;
101
+ /**
102
+ * Returned when an unknown key reference is found in a service.
103
+ */
104
+ static unknownKeyReference(reference: string, uri: string): XIDError;
105
+ /**
106
+ * Returned when an unknown delegate reference is found in a service.
107
+ */
108
+ static unknownDelegateReference(reference: string, uri: string): XIDError;
109
+ /**
110
+ * Returned when a key is not found in the XID document.
111
+ */
112
+ static keyNotFoundInDocument(key: string): XIDError;
113
+ /**
114
+ * Returned when a delegate is not found in the XID document.
115
+ */
116
+ static delegateNotFoundInDocument(delegate: string): XIDError;
117
+ /**
118
+ * Returned when the password is invalid.
119
+ */
120
+ static invalidPassword(): XIDError;
121
+ /**
122
+ * Returned when the envelope is not signed.
123
+ */
124
+ static envelopeNotSigned(): XIDError;
125
+ /**
126
+ * Returned when signature verification fails.
127
+ */
128
+ static signatureVerificationFailed(): XIDError;
129
+ /**
130
+ * Returned when there is no provenance mark to advance.
131
+ */
132
+ static noProvenanceMark(): XIDError;
133
+ /**
134
+ * Returned when document already has generator but external generator was provided.
135
+ */
136
+ static generatorConflict(): XIDError;
137
+ /**
138
+ * Returned when document does not have generator but needs one.
139
+ */
140
+ static noGenerator(): XIDError;
141
+ /**
142
+ * Returned when generator chain ID doesn't match.
143
+ */
144
+ static chainIdMismatch(expected: Uint8Array, actual: Uint8Array): XIDError;
145
+ /**
146
+ * Returned when generator sequence doesn't match.
147
+ */
148
+ static sequenceMismatch(expected: number, actual: number): XIDError;
149
+ /**
150
+ * Envelope parsing error wrapper.
151
+ */
152
+ static envelopeParsing(cause?: Error): XIDError;
153
+ /**
154
+ * Component error wrapper.
155
+ */
156
+ static component(cause?: Error): XIDError;
157
+ /**
158
+ * CBOR error wrapper.
159
+ */
160
+ static cbor(cause?: Error): XIDError;
161
+ /**
162
+ * Provenance mark error wrapper.
163
+ */
164
+ static provenanceMark(cause?: Error): XIDError;
165
+ }
166
+ /**
167
+ * Result type for XID operations.
168
+ */
169
+ type XIDResult<T> = T;
170
+ //#endregion
171
+ //#region src/privilege.d.ts
172
+ /**
173
+ * Enum representing XID privileges.
174
+ */
175
+ declare enum Privilege {
176
+ /** Allow all applicable XID operations */
177
+ All = "All",
178
+ /** Authenticate as the subject (e.g., log into services) */
179
+ Auth = "Auth",
180
+ /** Sign digital communications as the subject */
181
+ Sign = "Sign",
182
+ /** Encrypt messages from the subject */
183
+ Encrypt = "Encrypt",
184
+ /** Elide data under the subject's control */
185
+ Elide = "Elide",
186
+ /** Issue or revoke verifiable credentials on the subject's authority */
187
+ Issue = "Issue",
188
+ /** Access resources under the subject's control */
189
+ Access = "Access",
190
+ /** Delegate privileges to third parties */
191
+ Delegate = "Delegate",
192
+ /** Verify (update) the XID document */
193
+ Verify = "Verify",
194
+ /** Update service endpoints */
195
+ Update = "Update",
196
+ /** Remove the inception key from the XID document */
197
+ Transfer = "Transfer",
198
+ /** Add or remove other verifiers (rotate keys) */
199
+ Elect = "Elect",
200
+ /** Transition to a new provenance mark chain */
201
+ Burn = "Burn",
202
+ /** Revoke the XID entirely */
203
+ Revoke = "Revoke",
204
+ }
205
+ /**
206
+ * Convert a Privilege to its corresponding KnownValue.
207
+ */
208
+ declare function privilegeToKnownValue(privilege: Privilege): KnownValue;
209
+ /**
210
+ * Convert a KnownValue to its corresponding Privilege.
211
+ */
212
+ declare function privilegeFromKnownValue(knownValue: KnownValue): Privilege;
213
+ /**
214
+ * Convert a Privilege to an Envelope.
215
+ */
216
+ declare function privilegeToEnvelope(privilege: Privilege): Envelope;
217
+ /**
218
+ * Convert an Envelope to a Privilege.
219
+ */
220
+ declare function privilegeFromEnvelope(envelope: Envelope): Privilege;
221
+ //#endregion
222
+ //#region src/permissions.d.ts
223
+ /**
224
+ * Interface for types that have permissions.
225
+ */
226
+ interface HasPermissions {
227
+ /**
228
+ * Get the permissions for this object.
229
+ */
230
+ permissions(): Permissions;
231
+ /**
232
+ * Get a mutable reference to the permissions.
233
+ */
234
+ permissionsMut(): Permissions;
235
+ }
236
+ /**
237
+ * Helper methods for HasPermissions implementers.
238
+ */
239
+ declare const HasPermissionsMixin: {
240
+ /**
241
+ * Get the set of allowed privileges.
242
+ */
243
+ allow(obj: HasPermissions): Set<Privilege>;
244
+ /**
245
+ * Get the set of denied privileges.
246
+ */
247
+ deny(obj: HasPermissions): Set<Privilege>;
248
+ /**
249
+ * Add an allowed privilege.
250
+ */
251
+ addAllow(obj: HasPermissions, privilege: Privilege): void;
252
+ /**
253
+ * Add a denied privilege.
254
+ */
255
+ addDeny(obj: HasPermissions, privilege: Privilege): void;
256
+ /**
257
+ * Remove an allowed privilege.
258
+ */
259
+ removeAllow(obj: HasPermissions, privilege: Privilege): void;
260
+ /**
261
+ * Remove a denied privilege.
262
+ */
263
+ removeDeny(obj: HasPermissions, privilege: Privilege): void;
264
+ /**
265
+ * Clear all permissions.
266
+ */
267
+ clearAllPermissions(obj: HasPermissions): void;
268
+ };
269
+ /**
270
+ * Represents the permissions granted to a key or delegate.
271
+ */
272
+ declare class Permissions implements HasPermissions {
273
+ allow: Set<Privilege>;
274
+ deny: Set<Privilege>;
275
+ constructor(allow?: Set<Privilege>, deny?: Set<Privilege>);
276
+ /**
277
+ * Create a new empty Permissions object.
278
+ */
279
+ static new(): Permissions;
280
+ /**
281
+ * Create a new Permissions object that allows all privileges.
282
+ */
283
+ static newAllowAll(): Permissions;
284
+ /**
285
+ * Add permissions assertions to an envelope.
286
+ */
287
+ addToEnvelope(envelope: Envelope): Envelope;
288
+ /**
289
+ * Try to extract Permissions from an envelope.
290
+ */
291
+ static tryFromEnvelope(envelope: Envelope): Permissions;
292
+ /**
293
+ * Add an allowed privilege.
294
+ */
295
+ addAllow(privilege: Privilege): void;
296
+ /**
297
+ * Add a denied privilege.
298
+ */
299
+ addDeny(privilege: Privilege): void;
300
+ /**
301
+ * Check if a specific privilege is allowed.
302
+ */
303
+ isAllowed(privilege: Privilege): boolean;
304
+ /**
305
+ * Check if a specific privilege is denied.
306
+ */
307
+ isDenied(privilege: Privilege): boolean;
308
+ permissions(): Permissions;
309
+ permissionsMut(): Permissions;
310
+ /**
311
+ * Check equality with another Permissions object.
312
+ */
313
+ equals(other: Permissions): boolean;
314
+ /**
315
+ * Clone this Permissions object.
316
+ */
317
+ clone(): Permissions;
318
+ }
319
+ //#endregion
320
+ //#region src/name.d.ts
321
+ /**
322
+ * XID Name (Nickname) Interface
323
+ *
324
+ * Provides the HasNickname interface for objects that can have a nickname.
325
+ *
326
+ * Ported from bc-xid-rust/src/name.rs
327
+ */
328
+ /**
329
+ * Interface for types that have a nickname.
330
+ */
331
+ interface HasNickname {
332
+ /**
333
+ * Get the nickname for this object.
334
+ */
335
+ nickname(): string;
336
+ /**
337
+ * Set the nickname for this object.
338
+ */
339
+ setNickname(name: string): void;
340
+ }
341
+ /**
342
+ * Helper methods for HasNickname implementers.
343
+ */
344
+ declare const HasNicknameMixin: {
345
+ /**
346
+ * Add a nickname, throwing if one already exists or is empty.
347
+ */
348
+ addNickname(obj: HasNickname, name: string): void;
349
+ };
350
+ //#endregion
351
+ //#region src/shared.d.ts
352
+ /**
353
+ * Shared Reference Wrapper
354
+ *
355
+ * Provides a wrapper for shared references to objects.
356
+ * In TypeScript, we don't have Arc/RwLock like Rust, but we can provide
357
+ * a simple wrapper that allows shared access to a value.
358
+ *
359
+ * Ported from bc-xid-rust/src/shared.rs
360
+ */
361
+ /**
362
+ * A wrapper for shared references to objects.
363
+ *
364
+ * Unlike Rust's Arc<RwLock<T>>, JavaScript uses reference semantics for objects,
365
+ * so this is primarily a type-safe wrapper that makes the sharing explicit.
366
+ */
367
+ declare class Shared<T> {
368
+ private readonly value;
369
+ constructor(value: T);
370
+ /**
371
+ * Create a new Shared instance.
372
+ */
373
+ static new<T>(value: T): Shared<T>;
374
+ /**
375
+ * Get a read-only reference to the value.
376
+ */
377
+ read(): T;
378
+ /**
379
+ * Get a mutable reference to the value.
380
+ */
381
+ write(): T;
382
+ /**
383
+ * Check equality with another Shared instance.
384
+ */
385
+ equals(other: Shared<T>): boolean;
386
+ /**
387
+ * Clone this Shared instance.
388
+ * Note: This creates a shallow copy in JS; for deep copy, implement on T.
389
+ */
390
+ clone(): Shared<T>;
391
+ }
392
+ //#endregion
393
+ //#region src/key.d.ts
394
+ /**
395
+ * Options for handling private keys in envelopes.
396
+ */
397
+ declare enum XIDPrivateKeyOptions {
398
+ /** Omit the private key from the envelope (default). */
399
+ Omit = "Omit",
400
+ /** Include the private key in plaintext (with salt for decorrelation). */
401
+ Include = "Include",
402
+ /** Include the private key assertion but elide it (maintains digest tree). */
403
+ Elide = "Elide",
404
+ /** Include the private key encrypted with a password. */
405
+ Encrypt = "Encrypt",
406
+ }
407
+ /**
408
+ * Configuration for encrypting private keys.
409
+ */
410
+ interface XIDPrivateKeyEncryptConfig {
411
+ type: XIDPrivateKeyOptions.Encrypt;
412
+ password: Uint8Array;
413
+ }
414
+ /**
415
+ * Union type for all private key options.
416
+ */
417
+ type XIDPrivateKeyOptionsValue = XIDPrivateKeyOptions.Omit | XIDPrivateKeyOptions.Include | XIDPrivateKeyOptions.Elide | XIDPrivateKeyEncryptConfig;
418
+ /**
419
+ * Private key data that can be either decrypted or encrypted.
420
+ */
421
+ type PrivateKeyData = {
422
+ type: "decrypted";
423
+ privateKeyBase: PrivateKeyBase;
424
+ } | {
425
+ type: "encrypted";
426
+ envelope: Envelope;
427
+ };
428
+ /**
429
+ * Represents a key in an XID document.
430
+ */
431
+ declare class Key implements HasNickname, HasPermissions, EnvelopeEncodable {
432
+ private readonly _publicKeyBase;
433
+ private readonly _privateKeys;
434
+ private _nickname;
435
+ private readonly _endpoints;
436
+ private readonly _permissions;
437
+ private constructor();
438
+ /**
439
+ * Create a new Key with only public keys.
440
+ */
441
+ static new(publicKeyBase: PublicKeyBase): Key;
442
+ /**
443
+ * Create a new Key with public keys and allow-all permissions.
444
+ */
445
+ static newAllowAll(publicKeyBase: PublicKeyBase): Key;
446
+ /**
447
+ * Create a new Key with private key base.
448
+ */
449
+ static newWithPrivateKeyBase(privateKeyBase: PrivateKeyBase): Key;
450
+ /**
451
+ * Get the public key base.
452
+ */
453
+ publicKeyBase(): PublicKeyBase;
454
+ /**
455
+ * Get the private key base, if available and decrypted.
456
+ */
457
+ privateKeyBase(): PrivateKeyBase | undefined;
458
+ /**
459
+ * Check if this key has decrypted private keys.
460
+ */
461
+ hasPrivateKeys(): boolean;
462
+ /**
463
+ * Check if this key has encrypted private keys.
464
+ */
465
+ hasEncryptedPrivateKeys(): boolean;
466
+ /**
467
+ * Get the salt used for private key decorrelation.
468
+ */
469
+ privateKeySalt(): Salt | undefined;
470
+ /**
471
+ * Get the reference for this key (based on public key).
472
+ */
473
+ reference(): Reference;
474
+ /**
475
+ * Get the endpoints set.
476
+ */
477
+ endpoints(): Set<string>;
478
+ /**
479
+ * Get the endpoints set for mutation.
480
+ */
481
+ endpointsMut(): Set<string>;
482
+ /**
483
+ * Add an endpoint.
484
+ */
485
+ addEndpoint(endpoint: string): void;
486
+ /**
487
+ * Add a permission.
488
+ */
489
+ addPermission(privilege: Privilege): void;
490
+ nickname(): string;
491
+ setNickname(name: string): void;
492
+ permissions(): Permissions;
493
+ permissionsMut(): Permissions;
494
+ /**
495
+ * Convert to envelope with specified options.
496
+ */
497
+ intoEnvelopeOpt(privateKeyOptions?: XIDPrivateKeyOptionsValue): Envelope;
498
+ intoEnvelope(): Envelope;
499
+ /**
500
+ * Try to extract a Key from an envelope, optionally with password for decryption.
501
+ */
502
+ static tryFromEnvelope(envelope: Envelope, password?: Uint8Array): Key;
503
+ /**
504
+ * Check equality with another Key.
505
+ */
506
+ equals(other: Key): boolean;
507
+ /**
508
+ * Get a hash key for use in Sets/Maps.
509
+ */
510
+ hashKey(): string;
511
+ /**
512
+ * Clone this Key.
513
+ */
514
+ clone(): Key;
515
+ }
516
+ //#endregion
517
+ //#region src/service.d.ts
518
+ /**
519
+ * Represents a service endpoint in an XID document.
520
+ */
521
+ declare class Service implements HasPermissions, EnvelopeEncodable {
522
+ private readonly _uri;
523
+ private _keyReferences;
524
+ private _delegateReferences;
525
+ private _permissions;
526
+ private _capability;
527
+ private _name;
528
+ constructor(uri: string);
529
+ /**
530
+ * Create a new Service with the given URI.
531
+ */
532
+ static new(uri: string): Service;
533
+ /**
534
+ * Get the service URI.
535
+ */
536
+ uri(): string;
537
+ /**
538
+ * Get the capability string.
539
+ */
540
+ capability(): string;
541
+ /**
542
+ * Set the capability string.
543
+ */
544
+ setCapability(capability: string): void;
545
+ /**
546
+ * Add a capability, throwing if one already exists or is empty.
547
+ */
548
+ addCapability(capability: string): void;
549
+ /**
550
+ * Get the key references set.
551
+ */
552
+ keyReferences(): Set<string>;
553
+ /**
554
+ * Get the key references set for mutation.
555
+ */
556
+ keyReferencesMut(): Set<string>;
557
+ /**
558
+ * Add a key reference by hex string.
559
+ */
560
+ addKeyReferenceHex(keyReferenceHex: string): void;
561
+ /**
562
+ * Add a key reference.
563
+ */
564
+ addKeyReference(keyReference: Reference): void;
565
+ /**
566
+ * Get the delegate references set.
567
+ */
568
+ delegateReferences(): Set<string>;
569
+ /**
570
+ * Get the delegate references set for mutation.
571
+ */
572
+ delegateReferencesMut(): Set<string>;
573
+ /**
574
+ * Add a delegate reference by hex string.
575
+ */
576
+ addDelegateReferenceHex(delegateReferenceHex: string): void;
577
+ /**
578
+ * Add a delegate reference.
579
+ */
580
+ addDelegateReference(delegateReference: Reference): void;
581
+ /**
582
+ * Get the name.
583
+ */
584
+ name(): string;
585
+ /**
586
+ * Set the name, throwing if one already exists or is empty.
587
+ */
588
+ setName(name: string): void;
589
+ permissions(): Permissions;
590
+ permissionsMut(): Permissions;
591
+ /**
592
+ * Convert to envelope.
593
+ */
594
+ intoEnvelope(): Envelope;
595
+ /**
596
+ * Try to extract a Service from an envelope.
597
+ */
598
+ static tryFromEnvelope(envelope: Envelope): Service;
599
+ /**
600
+ * Check equality with another Service (based on URI).
601
+ */
602
+ equals(other: Service): boolean;
603
+ /**
604
+ * Get a hash key for use in Sets/Maps.
605
+ */
606
+ hashKey(): string;
607
+ /**
608
+ * Clone this Service.
609
+ */
610
+ clone(): Service;
611
+ }
612
+ //#endregion
613
+ //#region src/delegate.d.ts
614
+ /**
615
+ * Forward declaration interface for XIDDocument to avoid circular dependency.
616
+ * The actual XIDDocument class implements this interface.
617
+ */
618
+ interface XIDDocumentType {
619
+ xid(): XID;
620
+ intoEnvelope(): Envelope;
621
+ clone(): XIDDocumentType;
622
+ }
623
+ /**
624
+ * Register the XIDDocument class to avoid circular dependency issues.
625
+ * Called by xid-document.ts when it loads.
626
+ */
627
+ declare function registerXIDDocumentClass(cls: {
628
+ tryFromEnvelope(envelope: Envelope): XIDDocumentType;
629
+ }): void;
630
+ /**
631
+ * Represents a delegate in an XID document.
632
+ */
633
+ declare class Delegate implements HasPermissions, EnvelopeEncodable {
634
+ private readonly _controller;
635
+ private readonly _permissions;
636
+ private constructor();
637
+ /**
638
+ * Create a new Delegate with the given controller document.
639
+ */
640
+ static new(controller: XIDDocumentType): Delegate;
641
+ /**
642
+ * Get the controller document.
643
+ */
644
+ controller(): Shared<XIDDocumentType>;
645
+ /**
646
+ * Get the XID of the controller.
647
+ */
648
+ xid(): XID;
649
+ /**
650
+ * Get the reference for this delegate.
651
+ */
652
+ reference(): Reference;
653
+ permissions(): Permissions;
654
+ permissionsMut(): Permissions;
655
+ /**
656
+ * Convert to envelope.
657
+ */
658
+ intoEnvelope(): Envelope;
659
+ /**
660
+ * Try to extract a Delegate from an envelope.
661
+ */
662
+ static tryFromEnvelope(envelope: Envelope): Delegate;
663
+ /**
664
+ * Check equality with another Delegate (based on controller XID).
665
+ */
666
+ equals(other: Delegate): boolean;
667
+ /**
668
+ * Get a hash key for use in Sets/Maps.
669
+ */
670
+ hashKey(): string;
671
+ /**
672
+ * Clone this Delegate.
673
+ */
674
+ clone(): Delegate;
675
+ }
676
+ //#endregion
677
+ //#region src/provenance.d.ts
678
+ /**
679
+ * Options for handling generators in envelopes.
680
+ */
681
+ declare enum XIDGeneratorOptions {
682
+ /** Omit the generator from the envelope (default). */
683
+ Omit = "Omit",
684
+ /** Include the generator in plaintext (with salt for decorrelation). */
685
+ Include = "Include",
686
+ /** Include the generator assertion but elide it (maintains digest tree). */
687
+ Elide = "Elide",
688
+ /** Include the generator encrypted with a password. */
689
+ Encrypt = "Encrypt",
690
+ }
691
+ /**
692
+ * Configuration for encrypting generators.
693
+ */
694
+ interface XIDGeneratorEncryptConfig {
695
+ type: XIDGeneratorOptions.Encrypt;
696
+ password: Uint8Array;
697
+ }
698
+ /**
699
+ * Union type for all generator options.
700
+ */
701
+ type XIDGeneratorOptionsValue = XIDGeneratorOptions.Omit | XIDGeneratorOptions.Include | XIDGeneratorOptions.Elide | XIDGeneratorEncryptConfig;
702
+ /**
703
+ * Generator data that can be either decrypted or encrypted.
704
+ */
705
+ type GeneratorData = {
706
+ type: "decrypted";
707
+ generator: ProvenanceMarkGenerator;
708
+ } | {
709
+ type: "encrypted";
710
+ envelope: Envelope;
711
+ };
712
+ /**
713
+ * Represents provenance information in an XID document.
714
+ */
715
+ declare class Provenance implements EnvelopeEncodable {
716
+ private _mark;
717
+ private _generator;
718
+ private constructor();
719
+ /**
720
+ * Create a new Provenance with just a mark.
721
+ */
722
+ static new(mark: ProvenanceMark): Provenance;
723
+ /**
724
+ * Create a new Provenance with a generator and mark.
725
+ */
726
+ static newWithGenerator(generator: ProvenanceMarkGenerator, mark: ProvenanceMark): Provenance;
727
+ /**
728
+ * Get the provenance mark.
729
+ */
730
+ mark(): ProvenanceMark;
731
+ /**
732
+ * Get the generator, if available and decrypted.
733
+ */
734
+ generator(): ProvenanceMarkGenerator | undefined;
735
+ /**
736
+ * Check if this provenance has a decrypted generator.
737
+ */
738
+ hasGenerator(): boolean;
739
+ /**
740
+ * Check if this provenance has an encrypted generator.
741
+ */
742
+ hasEncryptedGenerator(): boolean;
743
+ /**
744
+ * Get the salt used for generator decorrelation.
745
+ */
746
+ generatorSalt(): Salt | undefined;
747
+ /**
748
+ * Update the provenance mark.
749
+ */
750
+ setMark(mark: ProvenanceMark): void;
751
+ /**
752
+ * Set or replace the generator.
753
+ */
754
+ setGenerator(generator: ProvenanceMarkGenerator): void;
755
+ /**
756
+ * Take and remove the generator.
757
+ */
758
+ takeGenerator(): {
759
+ data: GeneratorData;
760
+ salt: Salt;
761
+ } | undefined;
762
+ /**
763
+ * Get a mutable reference to the generator, decrypting if necessary.
764
+ */
765
+ generatorMut(password?: Uint8Array): ProvenanceMarkGenerator | undefined;
766
+ /**
767
+ * Convert to envelope with specified options.
768
+ */
769
+ intoEnvelopeOpt(generatorOptions?: XIDGeneratorOptionsValue): Envelope;
770
+ intoEnvelope(): Envelope;
771
+ /**
772
+ * Try to extract a Provenance from an envelope, optionally with password for decryption.
773
+ */
774
+ static tryFromEnvelope(envelope: Envelope, password?: Uint8Array): Provenance;
775
+ /**
776
+ * Check equality with another Provenance.
777
+ */
778
+ equals(other: Provenance): boolean;
779
+ /**
780
+ * Clone this Provenance.
781
+ * Note: ProvenanceMark is immutable so we can use the same instance.
782
+ */
783
+ clone(): Provenance;
784
+ }
785
+ //#endregion
786
+ //#region src/xid-document.d.ts
787
+ /**
788
+ * Options for creating the inception key.
789
+ */
790
+ type XIDInceptionKeyOptions = {
791
+ type: "default";
792
+ } | {
793
+ type: "publicKeyBase";
794
+ publicKeyBase: PublicKeyBase;
795
+ } | {
796
+ type: "privateKeyBase";
797
+ privateKeyBase: PrivateKeyBase;
798
+ };
799
+ /**
800
+ * Options for creating the genesis mark.
801
+ */
802
+ type XIDGenesisMarkOptions = {
803
+ type: "none";
804
+ } | {
805
+ type: "passphrase";
806
+ passphrase: string;
807
+ resolution?: ProvenanceMarkResolution;
808
+ date?: Date;
809
+ info?: Cbor;
810
+ } | {
811
+ type: "seed";
812
+ seed: Uint8Array;
813
+ resolution?: ProvenanceMarkResolution;
814
+ date?: Date;
815
+ info?: Cbor;
816
+ };
817
+ /**
818
+ * Options for signing an envelope.
819
+ */
820
+ type XIDSigningOptions = {
821
+ type: "none";
822
+ } | {
823
+ type: "inception";
824
+ } | {
825
+ type: "privateKeyBase";
826
+ privateKeyBase: PrivateKeyBase;
827
+ };
828
+ /**
829
+ * Options for verifying the signature on an envelope when loading.
830
+ */
831
+ declare enum XIDVerifySignature {
832
+ /** Do not verify the signature (default). */
833
+ None = "None",
834
+ /** Verify that the envelope is signed with the inception key. */
835
+ Inception = "Inception",
836
+ }
837
+ /**
838
+ * Represents an XID document.
839
+ */
840
+ declare class XIDDocument implements EnvelopeEncodable {
841
+ private readonly _xid;
842
+ private readonly _resolutionMethods;
843
+ private readonly _keys;
844
+ private readonly _delegates;
845
+ private readonly _services;
846
+ private _provenance;
847
+ private constructor();
848
+ /**
849
+ * Create a new XIDDocument with the given options.
850
+ */
851
+ static new(keyOptions?: XIDInceptionKeyOptions, markOptions?: XIDGenesisMarkOptions): XIDDocument;
852
+ private static inceptionKeyForOptions;
853
+ private static genesisMarkWithOptions;
854
+ /**
855
+ * Create an XIDDocument from just an XID.
856
+ */
857
+ static fromXid(xid: XID): XIDDocument;
858
+ /**
859
+ * Get the XID.
860
+ */
861
+ xid(): XID;
862
+ /**
863
+ * Get the resolution methods.
864
+ */
865
+ resolutionMethods(): Set<string>;
866
+ /**
867
+ * Add a resolution method.
868
+ */
869
+ addResolutionMethod(method: string): void;
870
+ /**
871
+ * Remove a resolution method.
872
+ */
873
+ removeResolutionMethod(method: string): boolean;
874
+ /**
875
+ * Get all keys.
876
+ */
877
+ keys(): Key[];
878
+ /**
879
+ * Add a key.
880
+ */
881
+ addKey(key: Key): void;
882
+ /**
883
+ * Find a key by its public key base.
884
+ */
885
+ findKeyByPublicKeyBase(publicKeyBase: PublicKeyBase): Key | undefined;
886
+ /**
887
+ * Find a key by its reference.
888
+ */
889
+ findKeyByReference(reference: Reference): Key | undefined;
890
+ /**
891
+ * Take and remove a key.
892
+ */
893
+ takeKey(publicKeyBase: PublicKeyBase): Key | undefined;
894
+ /**
895
+ * Remove a key.
896
+ */
897
+ removeKey(publicKeyBase: PublicKeyBase): void;
898
+ /**
899
+ * Check if the given public key is the inception signing key.
900
+ */
901
+ isInceptionKey(publicKeyBase: PublicKeyBase): boolean;
902
+ /**
903
+ * Get the inception key, if it exists in the document.
904
+ */
905
+ inceptionKey(): Key | undefined;
906
+ /**
907
+ * Get the inception private key base, if available.
908
+ */
909
+ inceptionPrivateKeyBase(): PrivateKeyBase | undefined;
910
+ /**
911
+ * Remove the inception key from the document.
912
+ */
913
+ removeInceptionKey(): Key | undefined;
914
+ /**
915
+ * Check if the document is empty (no keys, delegates, services, or provenance).
916
+ */
917
+ isEmpty(): boolean;
918
+ /**
919
+ * Get all delegates.
920
+ */
921
+ delegates(): Delegate[];
922
+ /**
923
+ * Add a delegate.
924
+ */
925
+ addDelegate(delegate: Delegate): void;
926
+ /**
927
+ * Find a delegate by XID.
928
+ */
929
+ findDelegateByXid(xid: XID): Delegate | undefined;
930
+ /**
931
+ * Find a delegate by reference.
932
+ */
933
+ findDelegateByReference(reference: Reference): Delegate | undefined;
934
+ /**
935
+ * Take and remove a delegate.
936
+ */
937
+ takeDelegate(xid: XID): Delegate | undefined;
938
+ /**
939
+ * Remove a delegate.
940
+ */
941
+ removeDelegate(xid: XID): void;
942
+ /**
943
+ * Get all services.
944
+ */
945
+ services(): Service[];
946
+ /**
947
+ * Find a service by URI.
948
+ */
949
+ findServiceByUri(uri: string): Service | undefined;
950
+ /**
951
+ * Add a service.
952
+ */
953
+ addService(service: Service): void;
954
+ /**
955
+ * Take and remove a service.
956
+ */
957
+ takeService(uri: string): Service | undefined;
958
+ /**
959
+ * Remove a service.
960
+ */
961
+ removeService(uri: string): void;
962
+ /**
963
+ * Check service consistency.
964
+ */
965
+ checkServicesConsistency(): void;
966
+ /**
967
+ * Check consistency of a single service.
968
+ */
969
+ checkServiceConsistency(service: Service): void;
970
+ /**
971
+ * Check if any service references the given key.
972
+ */
973
+ servicesReferenceKey(publicKeyBase: PublicKeyBase): boolean;
974
+ /**
975
+ * Check if any service references the given delegate.
976
+ */
977
+ servicesReferenceDelegate(xid: XID): boolean;
978
+ /**
979
+ * Get the provenance mark.
980
+ */
981
+ provenance(): ProvenanceMark | undefined;
982
+ /**
983
+ * Get the provenance generator.
984
+ */
985
+ provenanceGenerator(): ProvenanceMarkGenerator | undefined;
986
+ /**
987
+ * Set the provenance.
988
+ */
989
+ setProvenance(provenance: ProvenanceMark | undefined): void;
990
+ /**
991
+ * Set provenance with generator.
992
+ */
993
+ setProvenanceWithGenerator(generator: ProvenanceMarkGenerator, mark: ProvenanceMark): void;
994
+ /**
995
+ * Advance the provenance mark using the embedded generator.
996
+ */
997
+ nextProvenanceMarkWithEmbeddedGenerator(password?: Uint8Array, date?: Date, info?: Cbor): void;
998
+ /**
999
+ * Advance the provenance mark using a provided generator.
1000
+ */
1001
+ nextProvenanceMarkWithProvidedGenerator(generator: ProvenanceMarkGenerator, date?: Date, info?: Cbor): void;
1002
+ /**
1003
+ * Convert to envelope with options.
1004
+ */
1005
+ toEnvelope(privateKeyOptions?: XIDPrivateKeyOptionsValue, generatorOptions?: XIDGeneratorOptionsValue, signingOptions?: XIDSigningOptions): Envelope;
1006
+ intoEnvelope(): Envelope;
1007
+ /**
1008
+ * Extract an XIDDocument from an envelope.
1009
+ */
1010
+ static fromEnvelope(envelope: Envelope, password?: Uint8Array, verifySignature?: XIDVerifySignature): XIDDocument;
1011
+ private static fromEnvelopeInner;
1012
+ /**
1013
+ * Create a signed envelope.
1014
+ */
1015
+ toSignedEnvelope(signingKey: Signer): Envelope;
1016
+ /**
1017
+ * Get the reference for this document.
1018
+ */
1019
+ reference(): Reference;
1020
+ /**
1021
+ * Check equality with another XIDDocument.
1022
+ */
1023
+ equals(other: XIDDocument): boolean;
1024
+ /**
1025
+ * Clone this XIDDocument.
1026
+ */
1027
+ clone(): XIDDocument;
1028
+ /**
1029
+ * Try to extract from envelope (alias for fromEnvelope with default options).
1030
+ */
1031
+ static tryFromEnvelope(envelope: Envelope): XIDDocument;
1032
+ }
1033
+ //#endregion
1034
+ //#region src/index.d.ts
1035
+ declare const VERSION = "1.0.0-alpha.3";
1036
+ //#endregion
1037
+ export { Delegate, type GeneratorData, type HasNickname, HasNicknameMixin, type HasPermissions, HasPermissionsMixin, Key, Permissions, type PrivateKeyData, Privilege, Provenance, Service, Shared, VERSION, XIDDocument, type XIDDocumentType, XIDError, XIDErrorCode, type XIDGeneratorEncryptConfig, XIDGeneratorOptions, type XIDGeneratorOptionsValue, type XIDGenesisMarkOptions, type XIDInceptionKeyOptions, type XIDPrivateKeyEncryptConfig, XIDPrivateKeyOptions, type XIDPrivateKeyOptionsValue, type XIDResult, type XIDSigningOptions, XIDVerifySignature, privilegeFromEnvelope, privilegeFromKnownValue, privilegeToEnvelope, privilegeToKnownValue, registerXIDDocumentClass };
1038
+ //# sourceMappingURL=index.d.mts.map