@bcts/envelope 1.0.0-alpha.5

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.
Files changed (44) hide show
  1. package/LICENSE +48 -0
  2. package/README.md +23 -0
  3. package/dist/index.cjs +2646 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +978 -0
  6. package/dist/index.d.cts.map +1 -0
  7. package/dist/index.d.mts +978 -0
  8. package/dist/index.d.mts.map +1 -0
  9. package/dist/index.iife.js +2644 -0
  10. package/dist/index.iife.js.map +1 -0
  11. package/dist/index.mjs +2552 -0
  12. package/dist/index.mjs.map +1 -0
  13. package/package.json +85 -0
  14. package/src/base/assertion.ts +179 -0
  15. package/src/base/assertions.ts +304 -0
  16. package/src/base/cbor.ts +122 -0
  17. package/src/base/digest.ts +204 -0
  18. package/src/base/elide.ts +526 -0
  19. package/src/base/envelope-decodable.ts +229 -0
  20. package/src/base/envelope-encodable.ts +71 -0
  21. package/src/base/envelope.ts +790 -0
  22. package/src/base/error.ts +421 -0
  23. package/src/base/index.ts +56 -0
  24. package/src/base/leaf.ts +226 -0
  25. package/src/base/queries.ts +374 -0
  26. package/src/base/walk.ts +241 -0
  27. package/src/base/wrap.ts +72 -0
  28. package/src/extension/attachment.ts +369 -0
  29. package/src/extension/compress.ts +293 -0
  30. package/src/extension/encrypt.ts +379 -0
  31. package/src/extension/expression.ts +404 -0
  32. package/src/extension/index.ts +72 -0
  33. package/src/extension/proof.ts +276 -0
  34. package/src/extension/recipient.ts +557 -0
  35. package/src/extension/salt.ts +223 -0
  36. package/src/extension/signature.ts +463 -0
  37. package/src/extension/types.ts +222 -0
  38. package/src/format/diagnostic.ts +116 -0
  39. package/src/format/hex.ts +25 -0
  40. package/src/format/index.ts +13 -0
  41. package/src/format/tree.ts +168 -0
  42. package/src/index.ts +32 -0
  43. package/src/utils/index.ts +8 -0
  44. package/src/utils/string.ts +48 -0
@@ -0,0 +1,978 @@
1
+ import { Cbor, CborMap, CborTagged, CborTaggedDecodable, CborTaggedEncodable, tagsForValues } from "@bcts/dcbor";
2
+ import { KnownValue } from "@bcts/known-values";
3
+
4
+ //#region src/base/digest.d.ts
5
+ declare class Digest {
6
+ #private;
7
+ constructor(data: Uint8Array);
8
+ data(): Uint8Array;
9
+ static fromImage(image: Uint8Array): Digest;
10
+ static fromDigests(digests: Digest[]): Digest;
11
+ hex(): string;
12
+ short(): string;
13
+ static fromHex(hex: string): Digest;
14
+ equals(other: Digest): boolean;
15
+ toString(): string;
16
+ clone(): Digest;
17
+ }
18
+ interface DigestProvider {
19
+ digest(): Digest;
20
+ }
21
+ //#endregion
22
+ //#region src/base/envelope-encodable.d.ts
23
+ interface EnvelopeEncodable {
24
+ intoEnvelope(): Envelope$1;
25
+ }
26
+ declare function isEnvelopeEncodable(value: unknown): value is EnvelopeEncodable;
27
+ type EnvelopeEncodableValue = EnvelopeEncodable | string | number | boolean | bigint | Uint8Array | null | undefined | Envelope$1;
28
+ //#endregion
29
+ //#region src/base/assertion.d.ts
30
+ declare class Assertion implements DigestProvider {
31
+ #private;
32
+ constructor(predicate: EnvelopeEncodable | Envelope$1, object: EnvelopeEncodable | Envelope$1);
33
+ predicate(): Envelope$1;
34
+ object(): Envelope$1;
35
+ digest(): Digest;
36
+ equals(other: Assertion): boolean;
37
+ toCbor(): Cbor;
38
+ static fromCbor(cbor: Cbor): Assertion;
39
+ static fromCborMap(map: CborMap): Assertion;
40
+ toString(): string;
41
+ clone(): Assertion;
42
+ }
43
+ //#endregion
44
+ //#region src/extension/compress.d.ts
45
+ declare class Compressed {
46
+ #private;
47
+ constructor(compressedData: Uint8Array, digest?: Digest);
48
+ static fromDecompressedData(decompressedData: Uint8Array, digest?: Digest): Compressed;
49
+ compressedData(): Uint8Array;
50
+ digestOpt(): Digest | undefined;
51
+ decompress(): Uint8Array;
52
+ }
53
+ declare module "../base/envelope" {
54
+ interface Envelope {
55
+ compress(): Envelope;
56
+ decompress(): Envelope;
57
+ compressSubject(): Envelope;
58
+ decompressSubject(): Envelope;
59
+ isCompressed(): boolean;
60
+ }
61
+ }
62
+ declare function registerCompressExtension(): void;
63
+ //#endregion
64
+ //#region src/extension/encrypt.d.ts
65
+ declare class SymmetricKey {
66
+ #private;
67
+ constructor(key: Uint8Array);
68
+ static generate(): SymmetricKey;
69
+ static from(key: Uint8Array): SymmetricKey;
70
+ data(): Uint8Array;
71
+ encrypt(plaintext: Uint8Array, digest: Digest): EncryptedMessage;
72
+ decrypt(message: EncryptedMessage): Uint8Array;
73
+ }
74
+ declare class EncryptedMessage {
75
+ #private;
76
+ constructor(ciphertext: Uint8Array, nonce: Uint8Array, authTag: Uint8Array, aadDigest?: Digest);
77
+ ciphertext(): Uint8Array;
78
+ nonce(): Uint8Array;
79
+ authTag(): Uint8Array;
80
+ aadDigest(): Digest | undefined;
81
+ digest(): Digest;
82
+ }
83
+ declare module "../base/envelope" {
84
+ interface Envelope {
85
+ encryptSubject(key: SymmetricKey): Envelope;
86
+ decryptSubject(key: SymmetricKey): Envelope;
87
+ encrypt(key: SymmetricKey): Envelope;
88
+ decrypt(key: SymmetricKey): Envelope;
89
+ isEncrypted(): boolean;
90
+ }
91
+ }
92
+ declare function registerEncryptExtension(): void;
93
+ //#endregion
94
+ //#region src/base/envelope.d.ts
95
+ type EnvelopeCase = {
96
+ type: "node";
97
+ subject: Envelope$1;
98
+ assertions: Envelope$1[];
99
+ digest: Digest;
100
+ } | {
101
+ type: "leaf";
102
+ cbor: Cbor;
103
+ digest: Digest;
104
+ } | {
105
+ type: "wrapped";
106
+ envelope: Envelope$1;
107
+ digest: Digest;
108
+ } | {
109
+ type: "assertion";
110
+ assertion: Assertion;
111
+ } | {
112
+ type: "elided";
113
+ digest: Digest;
114
+ } | {
115
+ type: "knownValue";
116
+ value: KnownValue;
117
+ digest: Digest;
118
+ } | {
119
+ type: "encrypted";
120
+ message: EncryptedMessage;
121
+ } | {
122
+ type: "compressed";
123
+ value: Compressed;
124
+ };
125
+ declare class Envelope$1 implements DigestProvider {
126
+ #private;
127
+ private constructor();
128
+ case(): EnvelopeCase;
129
+ static new(subject: EnvelopeEncodableValue): Envelope$1;
130
+ static newOrNull(subject: EnvelopeEncodableValue | undefined): Envelope$1;
131
+ static newOrNone(subject: EnvelopeEncodableValue | undefined): Envelope$1 | undefined;
132
+ static fromCase(envelopeCase: EnvelopeCase): Envelope$1;
133
+ static newAssertion(predicate: EnvelopeEncodableValue, object: EnvelopeEncodableValue): Envelope$1;
134
+ static null(): Envelope$1;
135
+ static newWithUncheckedAssertions(subject: Envelope$1, uncheckedAssertions: Envelope$1[]): Envelope$1;
136
+ static newWithAssertions(subject: Envelope$1, assertions: Envelope$1[]): Envelope$1;
137
+ static newWithAssertion(assertion: Assertion): Envelope$1;
138
+ static newWithKnownValue(value: KnownValue | number | bigint): Envelope$1;
139
+ static newWithEncrypted(encryptedMessage: EncryptedMessage): Envelope$1;
140
+ static newWithCompressed(compressed: Compressed): Envelope$1;
141
+ static newElided(digest: Digest): Envelope$1;
142
+ static newLeaf(value: unknown): Envelope$1;
143
+ static newWrapped(envelope: Envelope$1): Envelope$1;
144
+ digest(): Digest;
145
+ subject(): Envelope$1;
146
+ isSubjectAssertion(): boolean;
147
+ isSubjectObscured(): boolean;
148
+ private static valueToCbor;
149
+ private static cborToBytes;
150
+ untaggedCbor(): Cbor;
151
+ taggedCbor(): Cbor;
152
+ static fromUntaggedCbor(cbor: Cbor): Envelope$1;
153
+ static fromTaggedCbor(cbor: Cbor): Envelope$1;
154
+ addAssertion(predicate: EnvelopeEncodableValue, object: EnvelopeEncodableValue): Envelope$1;
155
+ addAssertionEnvelope(assertion: Envelope$1): Envelope$1;
156
+ toString(): string;
157
+ clone(): Envelope$1;
158
+ treeFormat: (options?: {
159
+ hideNodes?: boolean;
160
+ highlightDigests?: Set<string>;
161
+ digestDisplay?: "short" | "full";
162
+ }) => string;
163
+ shortId: (format?: "short" | "full") => string;
164
+ summary: (maxLength?: number) => string;
165
+ hex: () => string;
166
+ cborBytes: () => Uint8Array;
167
+ diagnostic: () => string;
168
+ }
169
+ //#endregion
170
+ //#region src/base/error.d.ts
171
+ declare enum ErrorCode {
172
+ ALREADY_ELIDED = "ALREADY_ELIDED",
173
+ AMBIGUOUS_PREDICATE = "AMBIGUOUS_PREDICATE",
174
+ INVALID_DIGEST = "INVALID_DIGEST",
175
+ INVALID_FORMAT = "INVALID_FORMAT",
176
+ MISSING_DIGEST = "MISSING_DIGEST",
177
+ NONEXISTENT_PREDICATE = "NONEXISTENT_PREDICATE",
178
+ NOT_WRAPPED = "NOT_WRAPPED",
179
+ NOT_LEAF = "NOT_LEAF",
180
+ NOT_ASSERTION = "NOT_ASSERTION",
181
+ INVALID_ASSERTION = "INVALID_ASSERTION",
182
+ INVALID_ATTACHMENT = "INVALID_ATTACHMENT",
183
+ NONEXISTENT_ATTACHMENT = "NONEXISTENT_ATTACHMENT",
184
+ AMBIGUOUS_ATTACHMENT = "AMBIGUOUS_ATTACHMENT",
185
+ ALREADY_COMPRESSED = "ALREADY_COMPRESSED",
186
+ NOT_COMPRESSED = "NOT_COMPRESSED",
187
+ ALREADY_ENCRYPTED = "ALREADY_ENCRYPTED",
188
+ NOT_ENCRYPTED = "NOT_ENCRYPTED",
189
+ NOT_KNOWN_VALUE = "NOT_KNOWN_VALUE",
190
+ UNKNOWN_RECIPIENT = "UNKNOWN_RECIPIENT",
191
+ UNKNOWN_SECRET = "UNKNOWN_SECRET",
192
+ UNVERIFIED_SIGNATURE = "UNVERIFIED_SIGNATURE",
193
+ INVALID_OUTER_SIGNATURE_TYPE = "INVALID_OUTER_SIGNATURE_TYPE",
194
+ INVALID_INNER_SIGNATURE_TYPE = "INVALID_INNER_SIGNATURE_TYPE",
195
+ UNVERIFIED_INNER_SIGNATURE = "UNVERIFIED_INNER_SIGNATURE",
196
+ INVALID_SIGNATURE_TYPE = "INVALID_SIGNATURE_TYPE",
197
+ INVALID_SHARES = "INVALID_SHARES",
198
+ SSKR = "SSKR",
199
+ INVALID_TYPE = "INVALID_TYPE",
200
+ AMBIGUOUS_TYPE = "AMBIGUOUS_TYPE",
201
+ UNEXPECTED_RESPONSE_ID = "UNEXPECTED_RESPONSE_ID",
202
+ INVALID_RESPONSE = "INVALID_RESPONSE",
203
+ CBOR = "CBOR",
204
+ COMPONENTS = "COMPONENTS",
205
+ GENERAL = "GENERAL",
206
+ }
207
+ declare class EnvelopeError extends Error {
208
+ readonly code: ErrorCode;
209
+ readonly cause?: Error;
210
+ constructor(code: ErrorCode, message: string, cause?: Error);
211
+ static alreadyElided(): EnvelopeError;
212
+ static ambiguousPredicate(): EnvelopeError;
213
+ static invalidDigest(): EnvelopeError;
214
+ static invalidFormat(): EnvelopeError;
215
+ static missingDigest(): EnvelopeError;
216
+ static nonexistentPredicate(): EnvelopeError;
217
+ static notWrapped(): EnvelopeError;
218
+ static notLeaf(): EnvelopeError;
219
+ static notAssertion(): EnvelopeError;
220
+ static invalidAssertion(): EnvelopeError;
221
+ static invalidAttachment(): EnvelopeError;
222
+ static nonexistentAttachment(): EnvelopeError;
223
+ static ambiguousAttachment(): EnvelopeError;
224
+ static alreadyCompressed(): EnvelopeError;
225
+ static notCompressed(): EnvelopeError;
226
+ static alreadyEncrypted(): EnvelopeError;
227
+ static notEncrypted(): EnvelopeError;
228
+ static notKnownValue(): EnvelopeError;
229
+ static unknownRecipient(): EnvelopeError;
230
+ static unknownSecret(): EnvelopeError;
231
+ static unverifiedSignature(): EnvelopeError;
232
+ static invalidOuterSignatureType(): EnvelopeError;
233
+ static invalidInnerSignatureType(): EnvelopeError;
234
+ static unverifiedInnerSignature(): EnvelopeError;
235
+ static invalidSignatureType(): EnvelopeError;
236
+ static invalidShares(): EnvelopeError;
237
+ static sskr(message: string, cause?: Error): EnvelopeError;
238
+ static invalidType(): EnvelopeError;
239
+ static ambiguousType(): EnvelopeError;
240
+ static unexpectedResponseId(): EnvelopeError;
241
+ static invalidResponse(): EnvelopeError;
242
+ static cbor(message: string, cause?: Error): EnvelopeError;
243
+ static components(message: string, cause?: Error): EnvelopeError;
244
+ static general(message: string, cause?: Error): EnvelopeError;
245
+ static msg(message: string): EnvelopeError;
246
+ }
247
+ //#endregion
248
+ //#region src/base/cbor.d.ts
249
+ declare class EnvelopeCBORTagged implements CborTagged {
250
+ cborTags(): ReturnType<typeof tagsForValues>;
251
+ static cborTags(): number[];
252
+ }
253
+ declare class EnvelopeCBORTaggedEncodable implements CborTaggedEncodable {
254
+ private readonly envelope;
255
+ constructor(envelope: Envelope$1);
256
+ cborTags(): ReturnType<typeof tagsForValues>;
257
+ untaggedCbor(): Cbor;
258
+ taggedCbor(): Cbor;
259
+ }
260
+ declare class EnvelopeCBORTaggedDecodable<T = Envelope$1> implements CborTaggedDecodable<T> {
261
+ cborTags(): ReturnType<typeof tagsForValues>;
262
+ static fromUntaggedCbor(cbor: Cbor): Envelope$1;
263
+ static fromTaggedCbor(cbor: Cbor): Envelope$1;
264
+ fromUntaggedCbor(cbor: Cbor): T;
265
+ fromTaggedCbor(cbor: Cbor): T;
266
+ }
267
+ declare function envelopeToCbor(envelope: Envelope$1): Cbor;
268
+ declare function envelopeFromCbor(cbor: Cbor): Envelope$1;
269
+ declare function envelopeToBytes(envelope: Envelope$1): Uint8Array;
270
+ declare function envelopeFromBytes(bytes: Uint8Array): Envelope$1;
271
+ //#endregion
272
+ //#region src/base/envelope-decodable.d.ts
273
+ declare function extractString(envelope: Envelope$1): string;
274
+ declare function extractNumber(envelope: Envelope$1): number;
275
+ declare function extractBoolean(envelope: Envelope$1): boolean;
276
+ declare function extractBytes(envelope: Envelope$1): Uint8Array;
277
+ declare function extractNull(envelope: Envelope$1): null;
278
+ declare module "./envelope" {
279
+ interface Envelope {
280
+ tryLeaf(): Cbor;
281
+ extractString(): string;
282
+ extractNumber(): number;
283
+ extractBoolean(): boolean;
284
+ extractBytes(): Uint8Array;
285
+ extractNull(): null;
286
+ }
287
+ }
288
+ declare class EnvelopeDecoder {
289
+ static tryFromCbor(cbor: Cbor): Envelope$1;
290
+ static tryFromCborData(data: Uint8Array): Envelope$1;
291
+ }
292
+ //#endregion
293
+ //#region src/base/elide.d.ts
294
+ declare enum ObscureType {
295
+ Elided = "elided",
296
+ Encrypted = "encrypted",
297
+ Compressed = "compressed",
298
+ }
299
+ type ObscureAction = {
300
+ type: "elide";
301
+ } | {
302
+ type: "encrypt";
303
+ key: unknown;
304
+ } | {
305
+ type: "compress";
306
+ };
307
+ declare function elideAction(): ObscureAction;
308
+ declare module "./envelope" {
309
+ interface Envelope {
310
+ elide(): Envelope;
311
+ elideRemovingSetWithAction(target: Set<Digest>, action: ObscureAction): Envelope;
312
+ elideRemovingSet(target: Set<Digest>): Envelope;
313
+ elideRemovingArrayWithAction(target: DigestProvider[], action: ObscureAction): Envelope;
314
+ elideRemovingArray(target: DigestProvider[]): Envelope;
315
+ elideRemovingTargetWithAction(target: DigestProvider, action: ObscureAction): Envelope;
316
+ elideRemovingTarget(target: DigestProvider): Envelope;
317
+ elideRevealingSetWithAction(target: Set<Digest>, action: ObscureAction): Envelope;
318
+ elideRevealingSet(target: Set<Digest>): Envelope;
319
+ elideRevealingArrayWithAction(target: DigestProvider[], action: ObscureAction): Envelope;
320
+ elideRevealingArray(target: DigestProvider[]): Envelope;
321
+ elideRevealingTargetWithAction(target: DigestProvider, action: ObscureAction): Envelope;
322
+ elideRevealingTarget(target: DigestProvider): Envelope;
323
+ unelide(envelope: Envelope): Envelope;
324
+ nodesMatching(targetDigests: Set<Digest> | undefined, obscureTypes: ObscureType[]): Set<Digest>;
325
+ walkUnelide(envelopes: Envelope[]): Envelope;
326
+ walkReplace(target: Set<Digest>, replacement: Envelope): Envelope;
327
+ isIdenticalTo(other: Envelope): boolean;
328
+ }
329
+ }
330
+ //# sourceMappingURL=elide.d.ts.map
331
+ //#endregion
332
+ //#region src/base/walk.d.ts
333
+ declare enum EdgeType {
334
+ None = "none",
335
+ Subject = "subject",
336
+ Assertion = "assertion",
337
+ Predicate = "predicate",
338
+ Object = "object",
339
+ Content = "content",
340
+ }
341
+ declare function edgeLabel(edgeType: EdgeType): string | undefined;
342
+ type Visitor<State> = (envelope: Envelope$1, level: number, incomingEdge: EdgeType, state: State) => [State, boolean];
343
+ declare module "./envelope" {
344
+ interface Envelope {
345
+ walk<State>(hideNodes: boolean, state: State, visit: Visitor<State>): void;
346
+ }
347
+ }
348
+ //# sourceMappingURL=walk.d.ts.map
349
+ //#endregion
350
+ //#region src/base/assertions.d.ts
351
+ declare module "./envelope" {
352
+ interface Envelope {
353
+ addAssertionEnvelopes(assertions: Envelope[]): Envelope;
354
+ addOptionalAssertionEnvelope(assertion: Envelope | undefined): Envelope;
355
+ addOptionalAssertion(predicate: EnvelopeEncodableValue, object: EnvelopeEncodableValue | undefined): Envelope;
356
+ addNonemptyStringAssertion(predicate: EnvelopeEncodableValue, str: string): Envelope;
357
+ addAssertions(envelopes: Envelope[]): Envelope;
358
+ addAssertionIf(condition: boolean, predicate: EnvelopeEncodableValue, object: EnvelopeEncodableValue): Envelope;
359
+ addAssertionEnvelopeIf(condition: boolean, assertionEnvelope: Envelope): Envelope;
360
+ removeAssertion(target: Envelope): Envelope;
361
+ replaceAssertion(assertion: Envelope, newAssertion: Envelope): Envelope;
362
+ replaceSubject(subject: Envelope): Envelope;
363
+ assertions(): Envelope[];
364
+ }
365
+ }
366
+ //# sourceMappingURL=assertions.d.ts.map
367
+ //#endregion
368
+ //#region src/base/leaf.d.ts
369
+ declare module "./envelope" {
370
+ interface Envelope {
371
+ isFalse(): boolean;
372
+ isTrue(): boolean;
373
+ isBool(): boolean;
374
+ isNumber(): boolean;
375
+ isSubjectNumber(): boolean;
376
+ isNaN(): boolean;
377
+ isSubjectNaN(): boolean;
378
+ isNull(): boolean;
379
+ tryByteString(): Uint8Array;
380
+ asByteString(): Uint8Array | undefined;
381
+ asArray(): readonly Cbor[] | undefined;
382
+ asMap(): CborMap | undefined;
383
+ asText(): string | undefined;
384
+ asLeaf(): Cbor | undefined;
385
+ }
386
+ }
387
+ //# sourceMappingURL=leaf.d.ts.map
388
+ //#endregion
389
+ //#region src/base/queries.d.ts
390
+ declare module "./envelope" {
391
+ interface Envelope {
392
+ hasAssertions(): boolean;
393
+ asAssertion(): Envelope | undefined;
394
+ tryAssertion(): Envelope;
395
+ asPredicate(): Envelope | undefined;
396
+ tryPredicate(): Envelope;
397
+ asObject(): Envelope | undefined;
398
+ tryObject(): Envelope;
399
+ isAssertion(): boolean;
400
+ isElided(): boolean;
401
+ isLeaf(): boolean;
402
+ isNode(): boolean;
403
+ isWrapped(): boolean;
404
+ isInternal(): boolean;
405
+ isObscured(): boolean;
406
+ assertionsWithPredicate(predicate: EnvelopeEncodableValue): Envelope[];
407
+ assertionWithPredicate(predicate: EnvelopeEncodableValue): Envelope;
408
+ optionalAssertionWithPredicate(predicate: EnvelopeEncodableValue): Envelope | undefined;
409
+ objectForPredicate(predicate: EnvelopeEncodableValue): Envelope;
410
+ optionalObjectForPredicate(predicate: EnvelopeEncodableValue): Envelope | undefined;
411
+ objectsForPredicate(predicate: EnvelopeEncodableValue): Envelope[];
412
+ elementsCount(): number;
413
+ }
414
+ }
415
+ //# sourceMappingURL=queries.d.ts.map
416
+ //#endregion
417
+ //#region src/base/wrap.d.ts
418
+ declare module "./envelope" {
419
+ interface Envelope {
420
+ wrap(): Envelope;
421
+ tryUnwrap(): Envelope;
422
+ unwrap(): Envelope;
423
+ }
424
+ }
425
+ //#endregion
426
+ //#region src/extension/types.d.ts
427
+ declare const IS_A = "isA";
428
+ declare module "../base/envelope" {
429
+ interface Envelope {
430
+ addType(object: EnvelopeEncodableValue): Envelope;
431
+ types(): Envelope[];
432
+ getType(): Envelope;
433
+ hasType(t: EnvelopeEncodableValue): boolean;
434
+ checkType(t: EnvelopeEncodableValue): void;
435
+ }
436
+ }
437
+ //# sourceMappingURL=types.d.ts.map
438
+ //#endregion
439
+ //#region src/extension/salt.d.ts
440
+ declare const SALT = "salt";
441
+ declare module "../base/envelope" {
442
+ interface Envelope {
443
+ addSalt(): Envelope;
444
+ addSaltWithLength(count: number): Envelope;
445
+ addSaltBytes(saltBytes: Uint8Array): Envelope;
446
+ addSaltInRange(min: number, max: number): Envelope;
447
+ }
448
+ }
449
+ //# sourceMappingURL=salt.d.ts.map
450
+
451
+ //#endregion
452
+ //#region src/extension/signature.d.ts
453
+ /**
454
+ * Signature Extension for Gordian Envelope
455
+ *
456
+ * Provides functionality for digitally signing Envelopes and verifying signatures,
457
+ * with optional metadata support.
458
+ *
459
+ * The signature extension allows:
460
+ * - Signing envelope subjects to validate their authenticity
461
+ * - Adding metadata to signatures (e.g., signer identity, date, purpose)
462
+ * - Verification of signatures, both with and without metadata
463
+ * - Support for multiple signatures on a single envelope
464
+ */
465
+ /**
466
+ * Known value for the 'signed' predicate.
467
+ * This is the standard predicate used for signature assertions.
468
+ */
469
+ declare const SIGNED = "signed";
470
+ /**
471
+ * Known value for the 'verifiedBy' predicate.
472
+ * Used to indicate verification status.
473
+ */
474
+ declare const VERIFIED_BY = "verifiedBy";
475
+ /**
476
+ * Known value for the 'note' predicate.
477
+ * Used for adding notes/comments to signatures.
478
+ */
479
+ declare const NOTE = "note";
480
+ /**
481
+ * Represents a cryptographic signature.
482
+ */
483
+ declare class Signature {
484
+ #private;
485
+ constructor(data: Uint8Array);
486
+ /**
487
+ * Returns the raw signature bytes.
488
+ */
489
+ data(): Uint8Array;
490
+ /**
491
+ * Returns the hex-encoded signature.
492
+ */
493
+ hex(): string;
494
+ /**
495
+ * Creates a Signature from hex string.
496
+ */
497
+ static fromHex(hex: string): Signature;
498
+ }
499
+ /**
500
+ * Interface for types that can sign data.
501
+ */
502
+ interface Signer {
503
+ /**
504
+ * Signs the provided data and returns a Signature.
505
+ */
506
+ sign(data: Uint8Array): Signature;
507
+ }
508
+ /**
509
+ * Interface for types that can verify signatures.
510
+ */
511
+ interface Verifier {
512
+ /**
513
+ * Verifies a signature against the provided data.
514
+ * Returns true if the signature is valid.
515
+ */
516
+ verify(data: Uint8Array, signature: Signature): boolean;
517
+ }
518
+ /**
519
+ * ECDSA signing key using secp256k1 curve.
520
+ * Uses @bcts/crypto functions.
521
+ */
522
+ declare class SigningPrivateKey implements Signer {
523
+ #private;
524
+ constructor(privateKey: Uint8Array);
525
+ /**
526
+ * Generates a new random private key.
527
+ */
528
+ static generate(): SigningPrivateKey;
529
+ /**
530
+ * Creates a private key from hex string.
531
+ */
532
+ static fromHex(hex: string): SigningPrivateKey;
533
+ /**
534
+ * Returns the corresponding public key.
535
+ */
536
+ publicKey(): SigningPublicKey;
537
+ /**
538
+ * Signs data and returns a Signature.
539
+ */
540
+ sign(data: Uint8Array): Signature;
541
+ /**
542
+ * Returns the raw private key bytes.
543
+ */
544
+ data(): Uint8Array;
545
+ }
546
+ /**
547
+ * ECDSA public key for signature verification using secp256k1 curve.
548
+ * Uses @bcts/crypto functions.
549
+ */
550
+ declare class SigningPublicKey implements Verifier {
551
+ #private;
552
+ constructor(publicKey: Uint8Array);
553
+ /**
554
+ * Creates a public key from hex string.
555
+ */
556
+ static fromHex(hex: string): SigningPublicKey;
557
+ /**
558
+ * Verifies a signature against the provided data.
559
+ */
560
+ verify(data: Uint8Array, signature: Signature): boolean;
561
+ /**
562
+ * Returns the raw public key bytes.
563
+ */
564
+ data(): Uint8Array;
565
+ /**
566
+ * Returns the hex-encoded public key.
567
+ */
568
+ hex(): string;
569
+ }
570
+ /**
571
+ * Metadata that can be attached to a signature.
572
+ */
573
+ declare class SignatureMetadata {
574
+ #private;
575
+ /**
576
+ * Adds an assertion to the metadata.
577
+ */
578
+ withAssertion(predicate: string, object: unknown): SignatureMetadata;
579
+ /**
580
+ * Returns all assertions in the metadata.
581
+ */
582
+ assertions(): [string, unknown][];
583
+ /**
584
+ * Returns true if this metadata has any assertions.
585
+ */
586
+ hasAssertions(): boolean;
587
+ }
588
+ /**
589
+ * Support for signing envelopes and verifying signatures.
590
+ */
591
+ declare module "../base/envelope" {
592
+ interface Envelope {
593
+ /**
594
+ * Creates a signature for the envelope's subject and returns a new
595
+ * envelope with a 'signed': Signature assertion.
596
+ *
597
+ * @param signer - The signing key
598
+ * @returns The signed envelope
599
+ *
600
+ * @example
601
+ * ```typescript
602
+ * const privateKey = SigningPrivateKey.generate();
603
+ * const envelope = Envelope.new("Hello, world!");
604
+ * const signed = envelope.addSignature(privateKey);
605
+ * ```
606
+ */
607
+ addSignature(signer: Signer): Envelope;
608
+ /**
609
+ * Creates a signature for the envelope's subject with optional metadata.
610
+ *
611
+ * @param signer - The signing key
612
+ * @param metadata - Optional metadata to attach to the signature
613
+ * @returns The signed envelope
614
+ */
615
+ addSignatureWithMetadata(signer: Signer, metadata?: SignatureMetadata): Envelope;
616
+ /**
617
+ * Creates multiple signatures for the envelope's subject.
618
+ *
619
+ * @param signers - Array of signing keys
620
+ * @returns The envelope with multiple signatures
621
+ */
622
+ addSignatures(signers: Signer[]): Envelope;
623
+ /**
624
+ * Returns whether this envelope has a valid signature from the given verifier.
625
+ *
626
+ * @param verifier - The public key to verify against
627
+ * @returns True if a valid signature from this verifier exists
628
+ */
629
+ hasSignatureFrom(verifier: Verifier): boolean;
630
+ /**
631
+ * Verifies that this envelope has a valid signature from the given verifier
632
+ * and returns the envelope.
633
+ *
634
+ * @param verifier - The public key to verify against
635
+ * @returns The verified envelope
636
+ * @throws {EnvelopeError} If no valid signature is found
637
+ */
638
+ verifySignatureFrom(verifier: Verifier): Envelope;
639
+ /**
640
+ * Returns all signature assertions in this envelope.
641
+ *
642
+ * @returns Array of signature envelopes
643
+ */
644
+ signatures(): Envelope[];
645
+ }
646
+ }
647
+ //# sourceMappingURL=signature.d.ts.map
648
+ //#endregion
649
+ //#region src/extension/attachment.d.ts
650
+ /**
651
+ * Known value for the 'attachment' predicate.
652
+ */
653
+ declare const ATTACHMENT = "attachment";
654
+ /**
655
+ * Known value for the 'vendor' predicate.
656
+ */
657
+ declare const VENDOR = "vendor";
658
+ /**
659
+ * Known value for the 'conformsTo' predicate.
660
+ */
661
+ declare const CONFORMS_TO = "conformsTo";
662
+ /**
663
+ * A container for vendor-specific metadata attachments.
664
+ *
665
+ * Attachments provides a flexible mechanism for attaching arbitrary metadata
666
+ * to envelopes without modifying their core structure.
667
+ */
668
+ declare class Attachments {
669
+ #private;
670
+ /**
671
+ * Creates a new empty attachments container.
672
+ */
673
+ constructor();
674
+ /**
675
+ * Adds a new attachment with the specified payload and metadata.
676
+ *
677
+ * @param payload - The data to attach
678
+ * @param vendor - A string identifying the entity that defined the attachment format
679
+ * @param conformsTo - Optional URI identifying the structure the payload conforms to
680
+ */
681
+ add(payload: EnvelopeEncodableValue, vendor: string, conformsTo?: string): void;
682
+ /**
683
+ * Retrieves an attachment by its digest.
684
+ *
685
+ * @param digest - The unique digest of the attachment to retrieve
686
+ * @returns The envelope if found, or undefined
687
+ */
688
+ get(digest: Digest): Envelope$1 | undefined;
689
+ /**
690
+ * Removes an attachment by its digest.
691
+ *
692
+ * @param digest - The unique digest of the attachment to remove
693
+ * @returns The removed envelope if found, or undefined
694
+ */
695
+ remove(digest: Digest): Envelope$1 | undefined;
696
+ /**
697
+ * Removes all attachments from the container.
698
+ */
699
+ clear(): void;
700
+ /**
701
+ * Returns whether the container has any attachments.
702
+ */
703
+ isEmpty(): boolean;
704
+ /**
705
+ * Adds all attachments from this container to an envelope.
706
+ *
707
+ * @param envelope - The envelope to add attachments to
708
+ * @returns A new envelope with all attachments added as assertions
709
+ */
710
+ addToEnvelope(envelope: Envelope$1): Envelope$1;
711
+ /**
712
+ * Creates an Attachments container from an envelope's attachment assertions.
713
+ *
714
+ * @param envelope - The envelope to extract attachments from
715
+ * @returns A new Attachments container with the envelope's attachments
716
+ */
717
+ static fromEnvelope(envelope: Envelope$1): Attachments;
718
+ }
719
+ /**
720
+ * Support for attachments in envelopes.
721
+ */
722
+ declare module "../base/envelope" {
723
+ interface Envelope {
724
+ /**
725
+ * Creates a new envelope with an attachment as its subject.
726
+ *
727
+ * The attachment consists of:
728
+ * - The predicate 'attachment'
729
+ * - An object that is a wrapped envelope containing:
730
+ * - The payload (as the subject)
731
+ * - A required 'vendor': String assertion
732
+ * - An optional 'conformsTo': String assertion
733
+ *
734
+ * @param payload - The content of the attachment
735
+ * @param vendor - A string identifying the entity (typically reverse domain name)
736
+ * @param conformsTo - Optional URI identifying the format of the attachment
737
+ * @returns A new attachment envelope
738
+ *
739
+ * @example
740
+ * ```typescript
741
+ * const attachment = Envelope.newAttachment(
742
+ * "Custom data",
743
+ * "com.example",
744
+ * "https://example.com/format/v1"
745
+ * );
746
+ * ```
747
+ */
748
+ addAttachment(payload: EnvelopeEncodableValue, vendor: string, conformsTo?: string): Envelope$1;
749
+ /**
750
+ * Returns the payload of an attachment envelope.
751
+ *
752
+ * @returns The payload envelope
753
+ * @throws {EnvelopeError} If the envelope is not a valid attachment
754
+ */
755
+ attachmentPayload(): Envelope$1;
756
+ /**
757
+ * Returns the vendor identifier of an attachment envelope.
758
+ *
759
+ * @returns The vendor string
760
+ * @throws {EnvelopeError} If the envelope is not a valid attachment
761
+ */
762
+ attachmentVendor(): string;
763
+ /**
764
+ * Returns the optional conformsTo URI of an attachment envelope.
765
+ *
766
+ * @returns The conformsTo string if present, or undefined
767
+ * @throws {EnvelopeError} If the envelope is not a valid attachment
768
+ */
769
+ attachmentConformsTo(): string | undefined;
770
+ /**
771
+ * Returns all attachment assertions in this envelope.
772
+ *
773
+ * @returns Array of attachment envelopes
774
+ */
775
+ attachments(): Envelope$1[];
776
+ /**
777
+ * Searches for attachments matching the given vendor and conformsTo.
778
+ *
779
+ * @param vendor - Optional vendor identifier to match
780
+ * @param conformsTo - Optional conformsTo URI to match
781
+ * @returns Array of matching attachment envelopes
782
+ */
783
+ attachmentsWithVendorAndConformsTo(vendor?: string, conformsTo?: string): Envelope$1[];
784
+ }
785
+ namespace Envelope {
786
+ /**
787
+ * Creates a new attachment envelope.
788
+ *
789
+ * @param payload - The content of the attachment
790
+ * @param vendor - A string identifying the entity
791
+ * @param conformsTo - Optional URI identifying the format
792
+ * @returns A new attachment envelope
793
+ */
794
+ function newAttachment(payload: EnvelopeEncodableValue, vendor: string, conformsTo?: string): Envelope$1;
795
+ }
796
+ }
797
+ //# sourceMappingURL=attachment.d.ts.map
798
+ //#endregion
799
+ //#region src/extension/recipient.d.ts
800
+ declare const HAS_RECIPIENT = "hasRecipient";
801
+ declare class PublicKeyBase {
802
+ #private;
803
+ constructor(publicKey: Uint8Array);
804
+ data(): Uint8Array;
805
+ hex(): string;
806
+ static fromHex(hex: string): PublicKeyBase;
807
+ }
808
+ declare class PrivateKeyBase {
809
+ #private;
810
+ private constructor();
811
+ static generate(): PrivateKeyBase;
812
+ static fromBytes(privateKey: Uint8Array, publicKey: Uint8Array): PrivateKeyBase;
813
+ static fromHex(privateHex: string, publicHex: string): PrivateKeyBase;
814
+ publicKeys(): PublicKeyBase;
815
+ data(): Uint8Array;
816
+ hex(): string;
817
+ unseal(sealedMessage: SealedMessage): SymmetricKey;
818
+ }
819
+ declare class SealedMessage {
820
+ #private;
821
+ constructor(data: Uint8Array);
822
+ static seal(contentKey: SymmetricKey, recipientPublicKey: PublicKeyBase): SealedMessage;
823
+ decrypt(recipientPrivate: Uint8Array, _recipientPublic: Uint8Array): Uint8Array;
824
+ data(): Uint8Array;
825
+ hex(): string;
826
+ static fromHex(hex: string): SealedMessage;
827
+ }
828
+ declare module "../base/envelope" {
829
+ interface Envelope {
830
+ encryptSubjectToRecipient(recipientPublicKey: PublicKeyBase): Envelope;
831
+ encryptSubjectToRecipients(recipients: PublicKeyBase[]): Envelope;
832
+ addRecipient(recipientPublicKey: PublicKeyBase, contentKey: SymmetricKey): Envelope;
833
+ decryptSubjectToRecipient(recipientPrivateKey: PrivateKeyBase): Envelope;
834
+ decryptToRecipient(recipientPrivateKey: PrivateKeyBase): Envelope;
835
+ encryptToRecipients(recipients: PublicKeyBase[]): Envelope;
836
+ recipients(): SealedMessage[];
837
+ }
838
+ }
839
+ //#endregion
840
+ //#region src/extension/expression.d.ts
841
+ declare const CBOR_TAG_FUNCTION = 40006;
842
+ declare const CBOR_TAG_PARAMETER = 40007;
843
+ declare const CBOR_TAG_PLACEHOLDER = 40008;
844
+ declare const CBOR_TAG_REPLACEMENT = 40009;
845
+ declare const FUNCTION_IDS: {
846
+ readonly ADD: 1;
847
+ readonly SUB: 2;
848
+ readonly MUL: 3;
849
+ readonly DIV: 4;
850
+ readonly NEG: 5;
851
+ readonly LT: 6;
852
+ readonly LE: 7;
853
+ readonly GT: 8;
854
+ readonly GE: 9;
855
+ readonly EQ: 10;
856
+ readonly NE: 11;
857
+ readonly AND: 12;
858
+ readonly OR: 13;
859
+ readonly XOR: 14;
860
+ readonly NOT: 15;
861
+ };
862
+ declare const PARAMETER_IDS: {
863
+ readonly BLANK: 1;
864
+ readonly LHS: 2;
865
+ readonly RHS: 3;
866
+ };
867
+ type FunctionID = number | string;
868
+ type ParameterID = number | string;
869
+ declare class Function {
870
+ #private;
871
+ constructor(id: FunctionID);
872
+ id(): FunctionID;
873
+ isNumeric(): boolean;
874
+ isString(): boolean;
875
+ envelope(): Envelope$1;
876
+ withParameter(param: ParameterID, value: EnvelopeEncodableValue): Expression;
877
+ static fromNumeric(id: number): Function;
878
+ static fromString(name: string): Function;
879
+ toString(): string;
880
+ }
881
+ declare class Parameter {
882
+ #private;
883
+ constructor(id: ParameterID, value: Envelope$1);
884
+ id(): ParameterID;
885
+ value(): Envelope$1;
886
+ isNumeric(): boolean;
887
+ isString(): boolean;
888
+ envelope(): Envelope$1;
889
+ static blank(value: EnvelopeEncodableValue): Parameter;
890
+ static lhs(value: EnvelopeEncodableValue): Parameter;
891
+ static rhs(value: EnvelopeEncodableValue): Parameter;
892
+ toString(): string;
893
+ }
894
+ declare class Expression {
895
+ #private;
896
+ constructor(func: Function);
897
+ function(): Function;
898
+ parameters(): Parameter[];
899
+ withParameter(param: ParameterID, value: EnvelopeEncodableValue): Expression;
900
+ withParameters(params: Record<string, EnvelopeEncodableValue>): Expression;
901
+ getParameter(param: ParameterID): Envelope$1 | undefined;
902
+ hasParameter(param: ParameterID): boolean;
903
+ envelope(): Envelope$1;
904
+ static fromEnvelope(envelope: Envelope$1): Expression;
905
+ toString(): string;
906
+ }
907
+ declare function add(lhs: EnvelopeEncodableValue, rhs: EnvelopeEncodableValue): Expression;
908
+ declare function sub(lhs: EnvelopeEncodableValue, rhs: EnvelopeEncodableValue): Expression;
909
+ declare function mul(lhs: EnvelopeEncodableValue, rhs: EnvelopeEncodableValue): Expression;
910
+ declare function div(lhs: EnvelopeEncodableValue, rhs: EnvelopeEncodableValue): Expression;
911
+ declare function neg(value: EnvelopeEncodableValue): Expression;
912
+ declare function lt(lhs: EnvelopeEncodableValue, rhs: EnvelopeEncodableValue): Expression;
913
+ declare function gt(lhs: EnvelopeEncodableValue, rhs: EnvelopeEncodableValue): Expression;
914
+ declare function eq(lhs: EnvelopeEncodableValue, rhs: EnvelopeEncodableValue): Expression;
915
+ declare function and(lhs: EnvelopeEncodableValue, rhs: EnvelopeEncodableValue): Expression;
916
+ declare function or(lhs: EnvelopeEncodableValue, rhs: EnvelopeEncodableValue): Expression;
917
+ declare function not(value: EnvelopeEncodableValue): Expression;
918
+ //#endregion
919
+ //#region src/extension/proof.d.ts
920
+ declare module "../base/envelope" {
921
+ interface Envelope {
922
+ proofContainsSet(target: Set<Digest>): Envelope | undefined;
923
+ proofContainsTarget(target: Envelope): Envelope | undefined;
924
+ confirmContainsSet(target: Set<Digest>, proof: Envelope): boolean;
925
+ confirmContainsTarget(target: Envelope, proof: Envelope): boolean;
926
+ }
927
+ }
928
+ //#endregion
929
+ //#region src/format/tree.d.ts
930
+ interface TreeFormatOptions {
931
+ hideNodes?: boolean;
932
+ highlightDigests?: Set<string>;
933
+ digestDisplay?: "short" | "full";
934
+ }
935
+ //#endregion
936
+ //#region src/utils/string.d.ts
937
+ /**
938
+ * String utility functions used throughout the envelope library.
939
+ *
940
+ * Provides helper methods for string formatting and manipulation.
941
+ */
942
+ /**
943
+ * Flanks a string with specified left and right delimiters.
944
+ *
945
+ * @param str - The string to flank
946
+ * @param left - The left delimiter
947
+ * @param right - The right delimiter
948
+ * @returns The flanked string
949
+ *
950
+ * @example
951
+ * ```typescript
952
+ * flanked('hello', '"', '"') // Returns: "hello"
953
+ * flanked('name', "'", "'") // Returns: 'name'
954
+ * flanked('item', '[', ']') // Returns: [item]
955
+ * ```
956
+ */
957
+ declare function flanked(str: string, left: string, right: string): string;
958
+ /**
959
+ * Extension methods for String objects to support fluent API style.
960
+ */
961
+ declare global {
962
+ interface String {
963
+ /**
964
+ * Flanks this string with specified left and right delimiters.
965
+ *
966
+ * @param left - The left delimiter
967
+ * @param right - The right delimiter
968
+ * @returns The flanked string
969
+ */
970
+ flankedBy(left: string, right: string): string;
971
+ }
972
+ }
973
+ //#endregion
974
+ //#region src/index.d.ts
975
+ declare const VERSION = "0.37.0";
976
+ //#endregion
977
+ export { ATTACHMENT, Assertion, Attachments, CBOR_TAG_FUNCTION, CBOR_TAG_PARAMETER, CBOR_TAG_PLACEHOLDER, CBOR_TAG_REPLACEMENT, CONFORMS_TO, Compressed, Digest, type DigestProvider, EdgeType, EncryptedMessage, Envelope$1 as Envelope, EnvelopeCBORTagged, EnvelopeCBORTaggedDecodable, EnvelopeCBORTaggedEncodable, type EnvelopeCase, EnvelopeDecoder, type EnvelopeEncodable, type EnvelopeEncodableValue, EnvelopeError, ErrorCode, Expression, FUNCTION_IDS, Function, type FunctionID, HAS_RECIPIENT, IS_A, NOTE, type ObscureAction, ObscureType, PARAMETER_IDS, Parameter, type ParameterID, PrivateKeyBase, PublicKeyBase, SALT, SIGNED, SealedMessage, Signature, SignatureMetadata, type Signer, SigningPrivateKey, SigningPublicKey, SymmetricKey, TreeFormatOptions, VENDOR, VERIFIED_BY, VERSION, type Verifier, type Visitor, add, and, div, edgeLabel, elideAction, envelopeFromBytes, envelopeFromCbor, envelopeToBytes, envelopeToCbor, eq, extractBoolean, extractBytes, extractNull, extractNumber, extractString, flanked, gt, isEnvelopeEncodable, lt, mul, neg, not, or, registerCompressExtension, registerEncryptExtension, sub };
978
+ //# sourceMappingURL=index.d.mts.map