@bcts/components 1.0.0-alpha.22 → 1.0.0-alpha.23

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.
@@ -2,7 +2,18 @@ import { createTaggedCbor, decodeCbor, expectBytes, extractTaggedContent, tagsFo
2
2
  import { DIGEST } from "@bcts/tags";
3
3
  import { SHA256_SIZE, sha256 } from "@bcts/crypto";
4
4
  import { UR } from "@bcts/uniform-resources";
5
-
5
+ //#region \0rolldown/runtime.js
6
+ var __defProp = Object.defineProperty;
7
+ var __exportAll = (all, no_symbols) => {
8
+ let target = {};
9
+ for (var name in all) __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true
12
+ });
13
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
14
+ return target;
15
+ };
16
+ //#endregion
6
17
  //#region src/error.ts
7
18
  /**
8
19
  * Copyright © 2023-2026 Blockchain Commons, LLC
@@ -40,42 +51,42 @@ import { UR } from "@bcts/uniform-resources";
40
51
  * This enum allows programmatic checking of error types, matching the
41
52
  * Rust enum variants exactly.
42
53
  */
43
- let ErrorKind = /* @__PURE__ */ function(ErrorKind$1) {
54
+ let ErrorKind = /* @__PURE__ */ function(ErrorKind) {
44
55
  /** Invalid data size for the specified type */
45
- ErrorKind$1["InvalidSize"] = "InvalidSize";
56
+ ErrorKind["InvalidSize"] = "InvalidSize";
46
57
  /** Invalid data format or content */
47
- ErrorKind$1["InvalidData"] = "InvalidData";
58
+ ErrorKind["InvalidData"] = "InvalidData";
48
59
  /** Data too short for the expected type */
49
- ErrorKind$1["DataTooShort"] = "DataTooShort";
60
+ ErrorKind["DataTooShort"] = "DataTooShort";
50
61
  /** Cryptographic operation failed */
51
- ErrorKind$1["Crypto"] = "Crypto";
62
+ ErrorKind["Crypto"] = "Crypto";
52
63
  /** CBOR encoding or decoding error */
53
- ErrorKind$1["Cbor"] = "Cbor";
64
+ ErrorKind["Cbor"] = "Cbor";
54
65
  /** SSKR error */
55
- ErrorKind$1["Sskr"] = "Sskr";
66
+ ErrorKind["Sskr"] = "Sskr";
56
67
  /** SSH key operation failed */
57
- ErrorKind$1["Ssh"] = "Ssh";
68
+ ErrorKind["Ssh"] = "Ssh";
58
69
  /** URI parsing failed */
59
- ErrorKind$1["Uri"] = "Uri";
70
+ ErrorKind["Uri"] = "Uri";
60
71
  /** Data compression/decompression failed */
61
- ErrorKind$1["Compression"] = "Compression";
72
+ ErrorKind["Compression"] = "Compression";
62
73
  /** Post-quantum cryptography library error */
63
- ErrorKind$1["PostQuantum"] = "PostQuantum";
74
+ ErrorKind["PostQuantum"] = "PostQuantum";
64
75
  /** Signature level mismatch */
65
- ErrorKind$1["LevelMismatch"] = "LevelMismatch";
76
+ ErrorKind["LevelMismatch"] = "LevelMismatch";
66
77
  /** SSH agent operation failed */
67
- ErrorKind$1["SshAgent"] = "SshAgent";
78
+ ErrorKind["SshAgent"] = "SshAgent";
68
79
  /** Hex decoding error */
69
- ErrorKind$1["Hex"] = "Hex";
80
+ ErrorKind["Hex"] = "Hex";
70
81
  /** UTF-8 conversion error */
71
- ErrorKind$1["Utf8"] = "Utf8";
82
+ ErrorKind["Utf8"] = "Utf8";
72
83
  /** Environment variable error */
73
- ErrorKind$1["Env"] = "Env";
84
+ ErrorKind["Env"] = "Env";
74
85
  /** SSH agent client error */
75
- ErrorKind$1["SshAgentClient"] = "SshAgentClient";
86
+ ErrorKind["SshAgentClient"] = "SshAgentClient";
76
87
  /** General error with custom message */
77
- ErrorKind$1["General"] = "General";
78
- return ErrorKind$1;
88
+ ErrorKind["General"] = "General";
89
+ return ErrorKind;
79
90
  }({});
80
91
  /**
81
92
  * Error type for cryptographic and component operations.
@@ -121,7 +132,7 @@ var CryptoError = class CryptoError extends Error {
121
132
  */
122
133
  static invalidSizeForType(dataType, expected, actual) {
123
134
  return new CryptoError(`invalid ${dataType} size: expected ${expected}, got ${actual}`, {
124
- kind: ErrorKind.InvalidSize,
135
+ kind: "InvalidSize",
125
136
  dataType,
126
137
  expected,
127
138
  actual
@@ -145,7 +156,7 @@ var CryptoError = class CryptoError extends Error {
145
156
  */
146
157
  static invalidDataForType(dataType, reason) {
147
158
  return new CryptoError(`invalid ${dataType}: ${reason}`, {
148
- kind: ErrorKind.InvalidData,
159
+ kind: "InvalidData",
149
160
  dataType,
150
161
  reason
151
162
  });
@@ -161,7 +172,7 @@ var CryptoError = class CryptoError extends Error {
161
172
  */
162
173
  static dataTooShort(dataType, minimum, actual) {
163
174
  return new CryptoError(`data too short: ${dataType} expected at least ${minimum}, got ${actual}`, {
164
- kind: ErrorKind.DataTooShort,
175
+ kind: "DataTooShort",
165
176
  dataType,
166
177
  minimum,
167
178
  actual
@@ -202,7 +213,7 @@ var CryptoError = class CryptoError extends Error {
202
213
  */
203
214
  static crypto(message) {
204
215
  return new CryptoError(`cryptographic operation failed: ${message}`, {
205
- kind: ErrorKind.Crypto,
216
+ kind: "Crypto",
206
217
  message
207
218
  });
208
219
  }
@@ -215,7 +226,7 @@ var CryptoError = class CryptoError extends Error {
215
226
  */
216
227
  static postQuantum(message) {
217
228
  return new CryptoError(`post-quantum cryptography error: ${message}`, {
218
- kind: ErrorKind.PostQuantum,
229
+ kind: "PostQuantum",
219
230
  message
220
231
  });
221
232
  }
@@ -225,7 +236,7 @@ var CryptoError = class CryptoError extends Error {
225
236
  * Rust equivalent: `Error::LevelMismatch`
226
237
  */
227
238
  static levelMismatch() {
228
- return new CryptoError("signature level does not match key level", { kind: ErrorKind.LevelMismatch });
239
+ return new CryptoError("signature level does not match key level", { kind: "LevelMismatch" });
229
240
  }
230
241
  /**
231
242
  * Create a CBOR error.
@@ -236,7 +247,7 @@ var CryptoError = class CryptoError extends Error {
236
247
  */
237
248
  static cbor(message) {
238
249
  return new CryptoError(`CBOR error: ${message}`, {
239
- kind: ErrorKind.Cbor,
250
+ kind: "Cbor",
240
251
  message
241
252
  });
242
253
  }
@@ -249,7 +260,7 @@ var CryptoError = class CryptoError extends Error {
249
260
  */
250
261
  static hex(message) {
251
262
  return new CryptoError(`hex decoding error: ${message}`, {
252
- kind: ErrorKind.Hex,
263
+ kind: "Hex",
253
264
  message
254
265
  });
255
266
  }
@@ -262,7 +273,7 @@ var CryptoError = class CryptoError extends Error {
262
273
  */
263
274
  static utf8(message) {
264
275
  return new CryptoError(`UTF-8 conversion error: ${message}`, {
265
- kind: ErrorKind.Utf8,
276
+ kind: "Utf8",
266
277
  message
267
278
  });
268
279
  }
@@ -275,7 +286,7 @@ var CryptoError = class CryptoError extends Error {
275
286
  */
276
287
  static compression(message) {
277
288
  return new CryptoError(`compression error: ${message}`, {
278
- kind: ErrorKind.Compression,
289
+ kind: "Compression",
279
290
  message
280
291
  });
281
292
  }
@@ -288,7 +299,7 @@ var CryptoError = class CryptoError extends Error {
288
299
  */
289
300
  static uri(message) {
290
301
  return new CryptoError(`invalid URI: ${message}`, {
291
- kind: ErrorKind.Uri,
302
+ kind: "Uri",
292
303
  message
293
304
  });
294
305
  }
@@ -301,7 +312,7 @@ var CryptoError = class CryptoError extends Error {
301
312
  */
302
313
  static sskr(message) {
303
314
  return new CryptoError(`SSKR error: ${message}`, {
304
- kind: ErrorKind.Sskr,
315
+ kind: "Sskr",
305
316
  message
306
317
  });
307
318
  }
@@ -314,7 +325,7 @@ var CryptoError = class CryptoError extends Error {
314
325
  */
315
326
  static ssh(message) {
316
327
  return new CryptoError(`SSH operation failed: ${message}`, {
317
- kind: ErrorKind.Ssh,
328
+ kind: "Ssh",
318
329
  message
319
330
  });
320
331
  }
@@ -327,7 +338,7 @@ var CryptoError = class CryptoError extends Error {
327
338
  */
328
339
  static sshAgent(message) {
329
340
  return new CryptoError(`SSH agent error: ${message}`, {
330
- kind: ErrorKind.SshAgent,
341
+ kind: "SshAgent",
331
342
  message
332
343
  });
333
344
  }
@@ -340,7 +351,7 @@ var CryptoError = class CryptoError extends Error {
340
351
  */
341
352
  static sshAgentClient(message) {
342
353
  return new CryptoError(`SSH agent client error: ${message}`, {
343
- kind: ErrorKind.SshAgentClient,
354
+ kind: "SshAgentClient",
344
355
  message
345
356
  });
346
357
  }
@@ -353,7 +364,7 @@ var CryptoError = class CryptoError extends Error {
353
364
  */
354
365
  static env(message) {
355
366
  return new CryptoError(`environment variable error: ${message}`, {
356
- kind: ErrorKind.Env,
367
+ kind: "Env",
357
368
  message
358
369
  });
359
370
  }
@@ -366,7 +377,7 @@ var CryptoError = class CryptoError extends Error {
366
377
  */
367
378
  static general(message) {
368
379
  return new CryptoError(message, {
369
- kind: ErrorKind.General,
380
+ kind: "General",
370
381
  message
371
382
  });
372
383
  }
@@ -382,103 +393,103 @@ var CryptoError = class CryptoError extends Error {
382
393
  * Check if this is an InvalidSize error.
383
394
  */
384
395
  isInvalidSize() {
385
- return this.errorKind === ErrorKind.InvalidSize;
396
+ return this.errorKind === "InvalidSize";
386
397
  }
387
398
  /**
388
399
  * Check if this is an InvalidData error.
389
400
  */
390
401
  isInvalidData() {
391
- return this.errorKind === ErrorKind.InvalidData;
402
+ return this.errorKind === "InvalidData";
392
403
  }
393
404
  /**
394
405
  * Check if this is a DataTooShort error.
395
406
  */
396
407
  isDataTooShort() {
397
- return this.errorKind === ErrorKind.DataTooShort;
408
+ return this.errorKind === "DataTooShort";
398
409
  }
399
410
  /**
400
411
  * Check if this is a Crypto error.
401
412
  */
402
413
  isCrypto() {
403
- return this.errorKind === ErrorKind.Crypto;
414
+ return this.errorKind === "Crypto";
404
415
  }
405
416
  /**
406
417
  * Check if this is a Cbor error.
407
418
  */
408
419
  isCbor() {
409
- return this.errorKind === ErrorKind.Cbor;
420
+ return this.errorKind === "Cbor";
410
421
  }
411
422
  /**
412
423
  * Check if this is an Sskr error.
413
424
  */
414
425
  isSskr() {
415
- return this.errorKind === ErrorKind.Sskr;
426
+ return this.errorKind === "Sskr";
416
427
  }
417
428
  /**
418
429
  * Check if this is an Ssh error.
419
430
  */
420
431
  isSsh() {
421
- return this.errorKind === ErrorKind.Ssh;
432
+ return this.errorKind === "Ssh";
422
433
  }
423
434
  /**
424
435
  * Check if this is a Uri error.
425
436
  */
426
437
  isUri() {
427
- return this.errorKind === ErrorKind.Uri;
438
+ return this.errorKind === "Uri";
428
439
  }
429
440
  /**
430
441
  * Check if this is a Compression error.
431
442
  */
432
443
  isCompression() {
433
- return this.errorKind === ErrorKind.Compression;
444
+ return this.errorKind === "Compression";
434
445
  }
435
446
  /**
436
447
  * Check if this is a PostQuantum error.
437
448
  */
438
449
  isPostQuantum() {
439
- return this.errorKind === ErrorKind.PostQuantum;
450
+ return this.errorKind === "PostQuantum";
440
451
  }
441
452
  /**
442
453
  * Check if this is a LevelMismatch error.
443
454
  */
444
455
  isLevelMismatch() {
445
- return this.errorKind === ErrorKind.LevelMismatch;
456
+ return this.errorKind === "LevelMismatch";
446
457
  }
447
458
  /**
448
459
  * Check if this is an SshAgent error.
449
460
  */
450
461
  isSshAgent() {
451
- return this.errorKind === ErrorKind.SshAgent;
462
+ return this.errorKind === "SshAgent";
452
463
  }
453
464
  /**
454
465
  * Check if this is a Hex error.
455
466
  */
456
467
  isHex() {
457
- return this.errorKind === ErrorKind.Hex;
468
+ return this.errorKind === "Hex";
458
469
  }
459
470
  /**
460
471
  * Check if this is a Utf8 error.
461
472
  */
462
473
  isUtf8() {
463
- return this.errorKind === ErrorKind.Utf8;
474
+ return this.errorKind === "Utf8";
464
475
  }
465
476
  /**
466
477
  * Check if this is an Env error.
467
478
  */
468
479
  isEnv() {
469
- return this.errorKind === ErrorKind.Env;
480
+ return this.errorKind === "Env";
470
481
  }
471
482
  /**
472
483
  * Check if this is an SshAgentClient error.
473
484
  */
474
485
  isSshAgentClient() {
475
- return this.errorKind === ErrorKind.SshAgentClient;
486
+ return this.errorKind === "SshAgentClient";
476
487
  }
477
488
  /**
478
489
  * Check if this is a General error.
479
490
  */
480
491
  isGeneral() {
481
- return this.errorKind === ErrorKind.General;
492
+ return this.errorKind === "General";
482
493
  }
483
494
  };
484
495
  /**
@@ -499,7 +510,6 @@ function isCryptoError(result) {
499
510
  function isCryptoErrorKind(result, kind) {
500
511
  return isCryptoError(result) && result.errorKind === kind;
501
512
  }
502
-
503
513
  //#endregion
504
514
  //#region src/utils.ts
505
515
  /**
@@ -623,7 +633,6 @@ function bytesEqual(a, b) {
623
633
  for (let i = 0; i < a.length; i++) result |= a[i] ^ b[i];
624
634
  return result === 0;
625
635
  }
626
-
627
636
  //#endregion
628
637
  //#region src/digest.ts
629
638
  /**
@@ -669,6 +678,7 @@ function bytesEqual(a, b) {
669
678
  * console.log(digest2.hex()); // b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
670
679
  * ```
671
680
  */
681
+ var digest_exports = /* @__PURE__ */ __exportAll({ Digest: () => Digest });
672
682
  var Digest = class Digest {
673
683
  static DIGEST_SIZE = SHA256_SIZE;
674
684
  _data;
@@ -857,30 +867,30 @@ var Digest = class Digest {
857
867
  /**
858
868
  * Creates a Digest by decoding it from untagged CBOR.
859
869
  */
860
- fromUntaggedCbor(cbor$1) {
861
- const data = expectBytes(cbor$1);
870
+ fromUntaggedCbor(cbor) {
871
+ const data = expectBytes(cbor);
862
872
  return Digest.fromData(data);
863
873
  }
864
874
  /**
865
875
  * Creates a Digest by decoding it from tagged CBOR.
866
876
  */
867
- fromTaggedCbor(cbor$1) {
868
- validateTag(cbor$1, this.cborTags());
869
- const content = extractTaggedContent(cbor$1);
877
+ fromTaggedCbor(cbor) {
878
+ validateTag(cbor, this.cborTags());
879
+ const content = extractTaggedContent(cbor);
870
880
  return this.fromUntaggedCbor(content);
871
881
  }
872
882
  /**
873
883
  * Static method to decode from tagged CBOR.
874
884
  */
875
- static fromTaggedCbor(cbor$1) {
876
- return new Digest(new Uint8Array(Digest.DIGEST_SIZE)).fromTaggedCbor(cbor$1);
885
+ static fromTaggedCbor(cbor) {
886
+ return new Digest(new Uint8Array(Digest.DIGEST_SIZE)).fromTaggedCbor(cbor);
877
887
  }
878
888
  /**
879
889
  * Static method to decode from tagged CBOR binary data.
880
890
  */
881
891
  static fromTaggedCborData(data) {
882
- const cbor$1 = decodeCbor(data);
883
- return Digest.fromTaggedCbor(cbor$1);
892
+ const cbor = decodeCbor(data);
893
+ return Digest.fromTaggedCbor(cbor);
884
894
  }
885
895
  /**
886
896
  * Static method to decode from untagged CBOR binary data.
@@ -927,7 +937,7 @@ var Digest = class Digest {
927
937
  return digest.validate(image);
928
938
  }
929
939
  };
930
-
931
940
  //#endregion
932
- export { hexToBytes as a, ErrorKind as c, isError as d, fromBase64 as i, isCryptoError as l, bytesEqual as n, toBase64 as o, bytesToHex as r, CryptoError as s, Digest as t, isCryptoErrorKind as u };
933
- //# sourceMappingURL=digest-DFW8lGqJ.mjs.map
941
+ export { fromBase64 as a, CryptoError as c, isCryptoErrorKind as d, isError as f, bytesToHex as i, ErrorKind as l, digest_exports as n, hexToBytes as o, bytesEqual as r, toBase64 as s, Digest as t, isCryptoError as u };
942
+
943
+ //# sourceMappingURL=digest-B1bpgcdz.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"digest-B1bpgcdz.mjs","names":["TAG_DIGEST"],"sources":["../src/error.ts","../src/utils.ts","../src/digest.ts"],"sourcesContent":["/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Error types for cryptographic and component operations\n *\n * Ported from bc-components-rust/src/error.rs\n *\n * This module provides a unified error handling system that matches the Rust\n * implementation's error variants with full structural parity:\n *\n * - InvalidSize: Invalid data size for the specified type\n * - InvalidData: Invalid data format or content\n * - DataTooShort: Data too short for the expected type\n * - Crypto: Cryptographic operation failed\n * - Cbor: CBOR encoding or decoding error\n * - Sskr: SSKR error\n * - Ssh: SSH key operation failed\n * - Uri: URI parsing failed\n * - Compression: Data compression/decompression failed\n * - PostQuantum: Post-quantum cryptography library error\n * - LevelMismatch: Signature level mismatch\n * - SshAgent: SSH agent operation failed\n * - Hex: Hex decoding error\n * - Utf8: UTF-8 conversion error\n * - Env: Environment variable error\n * - SshAgentClient: SSH agent client error\n * - General: General error with custom message\n */\n\n/**\n * Error kind enum matching Rust's Error variants.\n *\n * This enum allows programmatic checking of error types, matching the\n * Rust enum variants exactly.\n */\nexport enum ErrorKind {\n /** Invalid data size for the specified type */\n InvalidSize = \"InvalidSize\",\n /** Invalid data format or content */\n InvalidData = \"InvalidData\",\n /** Data too short for the expected type */\n DataTooShort = \"DataTooShort\",\n /** Cryptographic operation failed */\n Crypto = \"Crypto\",\n /** CBOR encoding or decoding error */\n Cbor = \"Cbor\",\n /** SSKR error */\n Sskr = \"Sskr\",\n /** SSH key operation failed */\n Ssh = \"Ssh\",\n /** URI parsing failed */\n Uri = \"Uri\",\n /** Data compression/decompression failed */\n Compression = \"Compression\",\n /** Post-quantum cryptography library error */\n PostQuantum = \"PostQuantum\",\n /** Signature level mismatch */\n LevelMismatch = \"LevelMismatch\",\n /** SSH agent operation failed */\n SshAgent = \"SshAgent\",\n /** Hex decoding error */\n Hex = \"Hex\",\n /** UTF-8 conversion error */\n Utf8 = \"Utf8\",\n /** Environment variable error */\n Env = \"Env\",\n /** SSH agent client error */\n SshAgentClient = \"SshAgentClient\",\n /** General error with custom message */\n General = \"General\",\n}\n\n/**\n * Structured data for InvalidSize errors.\n */\nexport interface InvalidSizeData {\n dataType: string;\n expected: number;\n actual: number;\n}\n\n/**\n * Structured data for InvalidData errors.\n */\nexport interface InvalidDataData {\n dataType: string;\n reason: string;\n}\n\n/**\n * Structured data for DataTooShort errors.\n */\nexport interface DataTooShortData {\n dataType: string;\n minimum: number;\n actual: number;\n}\n\n/**\n * Union type for all possible error data.\n */\nexport type ErrorData =\n | ({ kind: ErrorKind.InvalidSize } & InvalidSizeData)\n | ({ kind: ErrorKind.InvalidData } & InvalidDataData)\n | ({ kind: ErrorKind.DataTooShort } & DataTooShortData)\n | { kind: ErrorKind.Crypto; message: string }\n | { kind: ErrorKind.Cbor; message: string }\n | { kind: ErrorKind.Sskr; message: string }\n | { kind: ErrorKind.Ssh; message: string }\n | { kind: ErrorKind.Uri; message: string }\n | { kind: ErrorKind.Compression; message: string }\n | { kind: ErrorKind.PostQuantum; message: string }\n | { kind: ErrorKind.LevelMismatch }\n | { kind: ErrorKind.SshAgent; message: string }\n | { kind: ErrorKind.Hex; message: string }\n | { kind: ErrorKind.Utf8; message: string }\n | { kind: ErrorKind.Env; message: string }\n | { kind: ErrorKind.SshAgentClient; message: string }\n | { kind: ErrorKind.General; message: string };\n\n/**\n * Error type for cryptographic and component operations.\n *\n * This class provides full structural parity with the Rust Error enum,\n * including:\n * - An `errorKind` property for programmatic error type checking\n * - Structured `errorData` for accessing error-specific fields\n * - Factory methods matching Rust's impl block\n */\nexport class CryptoError extends Error {\n /** The error kind for programmatic type checking */\n readonly errorKind: ErrorKind;\n\n /** Structured error data matching Rust's error variants */\n readonly errorData: ErrorData;\n\n private constructor(message: string, errorData: ErrorData) {\n super(message);\n this.name = \"CryptoError\";\n this.errorKind = errorData.kind;\n this.errorData = errorData;\n\n // Maintains proper stack trace in V8 environments\n const ErrorWithStackTrace = Error as {\n captureStackTrace?: (target: Error, ctor: unknown) => void;\n };\n if (typeof ErrorWithStackTrace.captureStackTrace === \"function\") {\n ErrorWithStackTrace.captureStackTrace(this, CryptoError);\n }\n }\n\n // ============================================================================\n // Size and Data Errors\n // ============================================================================\n\n /**\n * Create an invalid size error.\n *\n * Rust equivalent: `Error::InvalidSize { data_type, expected, actual }`\n *\n * @param expected - The expected size\n * @param actual - The actual size received\n */\n static invalidSize(expected: number, actual: number): CryptoError {\n return CryptoError.invalidSizeForType(\"data\", expected, actual);\n }\n\n /**\n * Create an invalid size error with a data type name.\n *\n * Rust equivalent: `Error::invalid_size(data_type, expected, actual)`\n *\n * @param dataType - The name of the data type\n * @param expected - The expected size\n * @param actual - The actual size received\n */\n static invalidSizeForType(dataType: string, expected: number, actual: number): CryptoError {\n return new CryptoError(`invalid ${dataType} size: expected ${expected}, got ${actual}`, {\n kind: ErrorKind.InvalidSize,\n dataType,\n expected,\n actual,\n });\n }\n\n /**\n * Create an invalid data error.\n *\n * @param message - Description of what's invalid\n */\n static invalidData(message: string): CryptoError {\n return CryptoError.invalidDataForType(\"data\", message);\n }\n\n /**\n * Create an invalid data error with a data type name.\n *\n * Rust equivalent: `Error::invalid_data(data_type, reason)`\n *\n * @param dataType - The name of the data type\n * @param reason - The reason the data is invalid\n */\n static invalidDataForType(dataType: string, reason: string): CryptoError {\n return new CryptoError(`invalid ${dataType}: ${reason}`, {\n kind: ErrorKind.InvalidData,\n dataType,\n reason,\n });\n }\n\n /**\n * Create a data too short error.\n *\n * Rust equivalent: `Error::data_too_short(data_type, minimum, actual)`\n *\n * @param dataType - The name of the data type\n * @param minimum - The minimum required size\n * @param actual - The actual size received\n */\n static dataTooShort(dataType: string, minimum: number, actual: number): CryptoError {\n return new CryptoError(\n `data too short: ${dataType} expected at least ${minimum}, got ${actual}`,\n {\n kind: ErrorKind.DataTooShort,\n dataType,\n minimum,\n actual,\n },\n );\n }\n\n // ============================================================================\n // Format and Input Errors (convenience methods)\n // ============================================================================\n\n /**\n * Create an invalid format error.\n *\n * @param message - Description of the format error\n */\n static invalidFormat(message: string): CryptoError {\n return CryptoError.invalidDataForType(\"format\", message);\n }\n\n /**\n * Create an invalid input error.\n *\n * @param message - Description of the invalid input\n */\n static invalidInput(message: string): CryptoError {\n return CryptoError.invalidDataForType(\"input\", message);\n }\n\n // ============================================================================\n // Cryptographic Errors\n // ============================================================================\n\n /**\n * Create a cryptographic operation failed error.\n *\n * Rust equivalent: `Error::crypto(msg)`\n *\n * @param message - Description of the failure\n */\n static cryptoOperation(message: string): CryptoError {\n return CryptoError.crypto(message);\n }\n\n /**\n * Create a crypto error.\n *\n * Rust equivalent: `Error::Crypto(msg)`\n *\n * @param message - Description of the failure\n */\n static crypto(message: string): CryptoError {\n return new CryptoError(`cryptographic operation failed: ${message}`, {\n kind: ErrorKind.Crypto,\n message,\n });\n }\n\n /**\n * Create a post-quantum cryptography error.\n *\n * Rust equivalent: `Error::post_quantum(msg)`\n *\n * @param message - Description of the failure\n */\n static postQuantum(message: string): CryptoError {\n return new CryptoError(`post-quantum cryptography error: ${message}`, {\n kind: ErrorKind.PostQuantum,\n message,\n });\n }\n\n /**\n * Create a signature level mismatch error.\n *\n * Rust equivalent: `Error::LevelMismatch`\n */\n static levelMismatch(): CryptoError {\n return new CryptoError(\"signature level does not match key level\", {\n kind: ErrorKind.LevelMismatch,\n });\n }\n\n // ============================================================================\n // Encoding/Serialization Errors\n // ============================================================================\n\n /**\n * Create a CBOR error.\n *\n * Rust equivalent: `Error::Cbor(err)`\n *\n * @param message - Description of the CBOR error\n */\n static cbor(message: string): CryptoError {\n return new CryptoError(`CBOR error: ${message}`, {\n kind: ErrorKind.Cbor,\n message,\n });\n }\n\n /**\n * Create a hex decoding error.\n *\n * Rust equivalent: `Error::Hex(err)`\n *\n * @param message - Description of the hex error\n */\n static hex(message: string): CryptoError {\n return new CryptoError(`hex decoding error: ${message}`, {\n kind: ErrorKind.Hex,\n message,\n });\n }\n\n /**\n * Create a UTF-8 conversion error.\n *\n * Rust equivalent: `Error::Utf8(err)`\n *\n * @param message - Description of the UTF-8 error\n */\n static utf8(message: string): CryptoError {\n return new CryptoError(`UTF-8 conversion error: ${message}`, {\n kind: ErrorKind.Utf8,\n message,\n });\n }\n\n // ============================================================================\n // Compression Errors\n // ============================================================================\n\n /**\n * Create a compression error.\n *\n * Rust equivalent: `Error::compression(msg)`\n *\n * @param message - Description of the compression error\n */\n static compression(message: string): CryptoError {\n return new CryptoError(`compression error: ${message}`, {\n kind: ErrorKind.Compression,\n message,\n });\n }\n\n // ============================================================================\n // URI Errors\n // ============================================================================\n\n /**\n * Create a URI parsing error.\n *\n * Rust equivalent: `Error::Uri(err)`\n *\n * @param message - Description of the URI error\n */\n static uri(message: string): CryptoError {\n return new CryptoError(`invalid URI: ${message}`, {\n kind: ErrorKind.Uri,\n message,\n });\n }\n\n // ============================================================================\n // SSKR Errors\n // ============================================================================\n\n /**\n * Create an SSKR error.\n *\n * Rust equivalent: `Error::Sskr(err)`\n *\n * @param message - Description of the SSKR error\n */\n static sskr(message: string): CryptoError {\n return new CryptoError(`SSKR error: ${message}`, {\n kind: ErrorKind.Sskr,\n message,\n });\n }\n\n // ============================================================================\n // SSH Errors\n // ============================================================================\n\n /**\n * Create an SSH operation error.\n *\n * Rust equivalent: `Error::ssh(msg)`\n *\n * @param message - Description of the SSH error\n */\n static ssh(message: string): CryptoError {\n return new CryptoError(`SSH operation failed: ${message}`, {\n kind: ErrorKind.Ssh,\n message,\n });\n }\n\n /**\n * Create an SSH agent error.\n *\n * Rust equivalent: `Error::ssh_agent(msg)`\n *\n * @param message - Description of the SSH agent error\n */\n static sshAgent(message: string): CryptoError {\n return new CryptoError(`SSH agent error: ${message}`, {\n kind: ErrorKind.SshAgent,\n message,\n });\n }\n\n /**\n * Create an SSH agent client error.\n *\n * Rust equivalent: `Error::ssh_agent_client(msg)`\n *\n * @param message - Description of the SSH agent client error\n */\n static sshAgentClient(message: string): CryptoError {\n return new CryptoError(`SSH agent client error: ${message}`, {\n kind: ErrorKind.SshAgentClient,\n message,\n });\n }\n\n // ============================================================================\n // Environment Errors\n // ============================================================================\n\n /**\n * Create an environment variable error.\n *\n * Rust equivalent: `Error::Env(err)`\n *\n * @param message - Description of the environment error\n */\n static env(message: string): CryptoError {\n return new CryptoError(`environment variable error: ${message}`, {\n kind: ErrorKind.Env,\n message,\n });\n }\n\n // ============================================================================\n // General Errors\n // ============================================================================\n\n /**\n * Create a general error with a custom message.\n *\n * Rust equivalent: `Error::general(msg)` / `Error::General(msg)`\n *\n * @param message - The error message\n */\n static general(message: string): CryptoError {\n return new CryptoError(message, {\n kind: ErrorKind.General,\n message,\n });\n }\n\n // ============================================================================\n // Error Kind Checking Methods\n // ============================================================================\n\n /**\n * Check if this error is of a specific kind.\n *\n * @param kind - The error kind to check\n */\n isKind(kind: ErrorKind): boolean {\n return this.errorKind === kind;\n }\n\n /**\n * Check if this is an InvalidSize error.\n */\n isInvalidSize(): this is CryptoError & {\n errorData: InvalidSizeData & { kind: ErrorKind.InvalidSize };\n } {\n return this.errorKind === ErrorKind.InvalidSize;\n }\n\n /**\n * Check if this is an InvalidData error.\n */\n isInvalidData(): this is CryptoError & {\n errorData: InvalidDataData & { kind: ErrorKind.InvalidData };\n } {\n return this.errorKind === ErrorKind.InvalidData;\n }\n\n /**\n * Check if this is a DataTooShort error.\n */\n isDataTooShort(): this is CryptoError & {\n errorData: DataTooShortData & { kind: ErrorKind.DataTooShort };\n } {\n return this.errorKind === ErrorKind.DataTooShort;\n }\n\n /**\n * Check if this is a Crypto error.\n */\n isCrypto(): boolean {\n return this.errorKind === ErrorKind.Crypto;\n }\n\n /**\n * Check if this is a Cbor error.\n */\n isCbor(): boolean {\n return this.errorKind === ErrorKind.Cbor;\n }\n\n /**\n * Check if this is an Sskr error.\n */\n isSskr(): boolean {\n return this.errorKind === ErrorKind.Sskr;\n }\n\n /**\n * Check if this is an Ssh error.\n */\n isSsh(): boolean {\n return this.errorKind === ErrorKind.Ssh;\n }\n\n /**\n * Check if this is a Uri error.\n */\n isUri(): boolean {\n return this.errorKind === ErrorKind.Uri;\n }\n\n /**\n * Check if this is a Compression error.\n */\n isCompression(): boolean {\n return this.errorKind === ErrorKind.Compression;\n }\n\n /**\n * Check if this is a PostQuantum error.\n */\n isPostQuantum(): boolean {\n return this.errorKind === ErrorKind.PostQuantum;\n }\n\n /**\n * Check if this is a LevelMismatch error.\n */\n isLevelMismatch(): boolean {\n return this.errorKind === ErrorKind.LevelMismatch;\n }\n\n /**\n * Check if this is an SshAgent error.\n */\n isSshAgent(): boolean {\n return this.errorKind === ErrorKind.SshAgent;\n }\n\n /**\n * Check if this is a Hex error.\n */\n isHex(): boolean {\n return this.errorKind === ErrorKind.Hex;\n }\n\n /**\n * Check if this is a Utf8 error.\n */\n isUtf8(): boolean {\n return this.errorKind === ErrorKind.Utf8;\n }\n\n /**\n * Check if this is an Env error.\n */\n isEnv(): boolean {\n return this.errorKind === ErrorKind.Env;\n }\n\n /**\n * Check if this is an SshAgentClient error.\n */\n isSshAgentClient(): boolean {\n return this.errorKind === ErrorKind.SshAgentClient;\n }\n\n /**\n * Check if this is a General error.\n */\n isGeneral(): boolean {\n return this.errorKind === ErrorKind.General;\n }\n}\n\n/**\n * Result type that can be either a success value or an Error.\n */\nexport type Result<T> = T | Error;\n\n/**\n * Type guard to check if a result is an Error.\n */\nexport function isError(result: unknown): result is Error {\n return result instanceof Error;\n}\n\n/**\n * Type guard to check if a result is a CryptoError.\n */\nexport function isCryptoError(result: unknown): result is CryptoError {\n return result instanceof CryptoError;\n}\n\n/**\n * Type guard to check if an error is a CryptoError of a specific kind.\n */\nexport function isCryptoErrorKind(result: unknown, kind: ErrorKind): result is CryptoError {\n return isCryptoError(result) && result.errorKind === kind;\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Utility functions for byte array conversions and comparisons.\n *\n * These functions provide cross-platform support for common byte manipulation\n * operations needed in cryptographic and encoding contexts.\n *\n * @packageDocumentation\n */\n\n/**\n * Convert a Uint8Array to a lowercase hexadecimal string.\n *\n * @param data - The byte array to convert\n * @returns A lowercase hex string representation (2 characters per byte)\n *\n * @example\n * ```typescript\n * const bytes = new Uint8Array([0xde, 0xad, 0xbe, 0xef]);\n * bytesToHex(bytes); // \"deadbeef\"\n * ```\n */\nexport function bytesToHex(data: Uint8Array): string {\n return Array.from(data)\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Convert a hexadecimal string to a Uint8Array.\n *\n * @param hex - A hex string (must have even length, case-insensitive)\n * @returns The decoded byte array\n * @throws {Error} If the hex string has odd length or contains invalid characters\n *\n * @example\n * ```typescript\n * hexToBytes(\"deadbeef\"); // Uint8Array([0xde, 0xad, 0xbe, 0xef])\n * hexToBytes(\"DEADBEEF\"); // Uint8Array([0xde, 0xad, 0xbe, 0xef])\n * hexToBytes(\"xyz\"); // throws Error: Invalid hex string\n * ```\n */\nexport function hexToBytes(hex: string): Uint8Array {\n if (hex.length % 2 !== 0) {\n throw new Error(`Hex string must have even length, got ${hex.length}`);\n }\n if (!/^[0-9A-Fa-f]*$/.test(hex)) {\n throw new Error(\"Invalid hex string: contains non-hexadecimal characters\");\n }\n const data = new Uint8Array(hex.length / 2);\n for (let i = 0; i < hex.length; i += 2) {\n data[i / 2] = parseInt(hex.substring(i, i + 2), 16);\n }\n return data;\n}\n\n/**\n * Convert a Uint8Array to a base64-encoded string.\n *\n * This function works in both browser and Node.js environments.\n * Uses btoa which is available in browsers and Node.js 16+.\n *\n * @param data - The byte array to encode\n * @returns A base64-encoded string\n *\n * @example\n * ```typescript\n * const bytes = new Uint8Array([72, 101, 108, 108, 111]); // \"Hello\"\n * toBase64(bytes); // \"SGVsbG8=\"\n * ```\n */\nexport function toBase64(data: Uint8Array): string {\n // Convert bytes to binary string without spread operator to avoid\n // call stack limits for large arrays (spread would fail at ~65k bytes)\n let binary = \"\";\n for (const byte of data) {\n binary += String.fromCharCode(byte);\n }\n return btoa(binary);\n}\n\n/**\n * Convert a base64-encoded string to a Uint8Array.\n *\n * This function works in both browser and Node.js environments.\n * Uses atob which is available in browsers and Node.js 16+.\n *\n * @param base64 - A base64-encoded string\n * @returns The decoded byte array\n *\n * @example\n * ```typescript\n * fromBase64(\"SGVsbG8=\"); // Uint8Array([72, 101, 108, 108, 111])\n * ```\n */\nexport function fromBase64(base64: string): Uint8Array {\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes;\n}\n\n/**\n * Compare two Uint8Arrays for equality using constant-time comparison.\n *\n * This function is designed to be resistant to timing attacks by always\n * comparing all bytes regardless of where a difference is found. The\n * comparison time depends only on the length of the arrays, not on where\n * they differ.\n *\n * **Security Note**: If the arrays have different lengths, this function\n * returns `false` immediately, which does leak length information. For\n * cryptographic uses where length should also be secret, ensure both\n * arrays are the same length before comparison.\n *\n * @param a - First byte array\n * @param b - Second byte array\n * @returns `true` if both arrays have the same length and identical contents\n *\n * @example\n * ```typescript\n * const key1 = new Uint8Array([1, 2, 3, 4]);\n * const key2 = new Uint8Array([1, 2, 3, 4]);\n * const key3 = new Uint8Array([1, 2, 3, 5]);\n *\n * bytesEqual(key1, key2); // true\n * bytesEqual(key1, key3); // false\n * ```\n */\nexport function bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n let result = 0;\n for (let i = 0; i < a.length; i++) {\n result |= a[i] ^ b[i];\n }\n return result === 0;\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * SHA-256 cryptographic digest (32 bytes)\n *\n * Ported from bc-components-rust/src/digest.rs\n *\n * A `Digest` represents the cryptographic hash of some data. In this\n * implementation, SHA-256 is used, which produces a 32-byte hash value.\n * Digests are used throughout the crate for data verification and as unique\n * identifiers derived from data.\n *\n * # CBOR Serialization\n *\n * `Digest` implements the CBOR tagged encoding interfaces, which means it can be\n * serialized to and deserialized from CBOR with a specific tag (TAG_DIGEST = 40001).\n *\n * # UR Serialization\n *\n * When serialized as a Uniform Resource (UR), a `Digest` is represented as a\n * binary blob with the type \"digest\".\n *\n * @example\n * ```typescript\n * import { Digest } from '@bcts/components';\n *\n * // Create a digest from a string\n * const data = new TextEncoder().encode(\"hello world\");\n * const digest = Digest.fromImage(data);\n *\n * // Validate that the digest matches the original data\n * console.log(digest.validate(data)); // true\n *\n * // Create a digest from a hex string\n * const hexString = \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\";\n * const digest2 = Digest.fromHex(hexString);\n *\n * // Retrieve the digest as hex\n * console.log(digest2.hex()); // b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\n * ```\n */\n\nimport { sha256, SHA256_SIZE } from \"@bcts/crypto\";\nimport {\n type Cbor,\n type Tag,\n type CborTaggedEncodable,\n type CborTaggedDecodable,\n toByteString,\n expectBytes,\n createTaggedCbor,\n validateTag,\n extractTaggedContent,\n decodeCbor,\n tagsForValues,\n} from \"@bcts/dcbor\";\nimport { DIGEST as TAG_DIGEST } from \"@bcts/tags\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { CryptoError } from \"./error.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"./utils.js\";\nimport type { DigestProvider } from \"./digest-provider.js\";\n\nexport class Digest\n implements DigestProvider, CborTaggedEncodable, CborTaggedDecodable<Digest>, UREncodable\n{\n static readonly DIGEST_SIZE = SHA256_SIZE;\n\n private readonly _data: Uint8Array;\n\n private constructor(data: Uint8Array) {\n if (data.length !== Digest.DIGEST_SIZE) {\n throw CryptoError.invalidSize(Digest.DIGEST_SIZE, data.length);\n }\n this._data = new Uint8Array(data);\n }\n\n /**\n * Get the digest data.\n */\n data(): Uint8Array {\n return this._data;\n }\n\n // ============================================================================\n // Static Factory Methods\n // ============================================================================\n\n /**\n * Create a Digest from a 32-byte array.\n */\n static fromData(data: Uint8Array): Digest {\n return new Digest(new Uint8Array(data));\n }\n\n /**\n * Create a Digest from data, validating the length.\n * Alias for fromData for compatibility with Rust API.\n */\n static fromDataRef(data: Uint8Array): Digest {\n return Digest.fromData(data);\n }\n\n /**\n * Create a Digest from hex string.\n *\n * @throws Error if the hex string is not exactly 64 characters.\n */\n static fromHex(hex: string): Digest {\n return new Digest(hexToBytes(hex));\n }\n\n /**\n * Compute SHA-256 digest of data (called \"image\" in Rust).\n *\n * @param image - The data to hash\n */\n static fromImage(image: Uint8Array): Digest {\n const hashData = sha256(image);\n return new Digest(new Uint8Array(hashData));\n }\n\n /**\n * Compute SHA-256 digest from multiple data parts.\n *\n * The parts are concatenated and then hashed.\n *\n * @param imageParts - Array of byte arrays to concatenate and hash\n */\n static fromImageParts(imageParts: Uint8Array[]): Digest {\n const totalLength = imageParts.reduce((sum, part) => sum + part.length, 0);\n const buf = new Uint8Array(totalLength);\n let offset = 0;\n for (const part of imageParts) {\n buf.set(part, offset);\n offset += part.length;\n }\n return Digest.fromImage(buf);\n }\n\n /**\n * Compute SHA-256 digest from an array of Digests.\n *\n * The digest bytes are concatenated and then hashed.\n *\n * @param digests - Array of Digests to combine\n */\n static fromDigests(digests: Digest[]): Digest {\n const buf = new Uint8Array(digests.length * Digest.DIGEST_SIZE);\n let offset = 0;\n for (const digest of digests) {\n buf.set(digest._data, offset);\n offset += Digest.DIGEST_SIZE;\n }\n return Digest.fromImage(buf);\n }\n\n /**\n * Compute SHA-256 digest of data (legacy alias for fromImage).\n * @deprecated Use fromImage instead\n */\n static hash(data: Uint8Array): Digest {\n return Digest.fromImage(data);\n }\n\n // ============================================================================\n // Instance Methods\n // ============================================================================\n\n /**\n * Get the raw digest bytes as a copy.\n */\n toData(): Uint8Array {\n return new Uint8Array(this._data);\n }\n\n /**\n * Get a reference to the raw digest bytes.\n */\n asBytes(): Uint8Array {\n return this._data;\n }\n\n /**\n * Get hex string representation.\n */\n hex(): string {\n return bytesToHex(this._data);\n }\n\n /**\n * Get hex string representation (alias for hex()).\n */\n toHex(): string {\n return this.hex();\n }\n\n /**\n * Get base64 representation.\n */\n toBase64(): string {\n return toBase64(this._data);\n }\n\n /**\n * Get the first four bytes of the digest as a hexadecimal string.\n * Useful for short descriptions.\n */\n shortDescription(): string {\n return bytesToHex(this._data.slice(0, 4));\n }\n\n /**\n * Validate the digest against the given image.\n *\n * The image is hashed with SHA-256 and compared to this digest.\n * @returns `true` if the digest matches the image.\n */\n validate(image: Uint8Array): boolean {\n return this.equals(Digest.fromImage(image));\n }\n\n /**\n * Compare with another Digest.\n */\n equals(other: Digest): boolean {\n if (this._data.length !== other._data.length) return false;\n for (let i = 0; i < this._data.length; i++) {\n if (this._data[i] !== other._data[i]) return false;\n }\n return true;\n }\n\n /**\n * Compare digests lexicographically.\n */\n compare(other: Digest): number {\n for (let i = 0; i < this._data.length; i++) {\n const a = this._data[i];\n const b = other._data[i];\n if (a < b) return -1;\n if (a > b) return 1;\n }\n return 0;\n }\n\n /**\n * Get string representation.\n */\n toString(): string {\n return `Digest(${this.hex()})`;\n }\n\n // ============================================================================\n // DigestProvider Implementation\n // ============================================================================\n\n /**\n * A Digest is its own digest provider - returns itself.\n */\n digest(): Digest {\n return this;\n }\n\n // ============================================================================\n // CBOR Serialization (CborTaggedEncodable)\n // ============================================================================\n\n /**\n * Returns the CBOR tags associated with Digest.\n */\n cborTags(): Tag[] {\n return tagsForValues([TAG_DIGEST.value]);\n }\n\n /**\n * Returns the untagged CBOR encoding (as a byte string).\n */\n untaggedCbor(): Cbor {\n return toByteString(this._data);\n }\n\n /**\n * Returns the tagged CBOR encoding.\n */\n taggedCbor(): Cbor {\n return createTaggedCbor(this);\n }\n\n /**\n * Returns the tagged value in CBOR binary representation.\n */\n taggedCborData(): Uint8Array {\n return this.taggedCbor().toData();\n }\n\n // ============================================================================\n // CBOR Deserialization (CborTaggedDecodable)\n // ============================================================================\n\n /**\n * Creates a Digest by decoding it from untagged CBOR.\n */\n fromUntaggedCbor(cbor: Cbor): Digest {\n const data = expectBytes(cbor);\n return Digest.fromData(data);\n }\n\n /**\n * Creates a Digest by decoding it from tagged CBOR.\n */\n fromTaggedCbor(cbor: Cbor): Digest {\n validateTag(cbor, this.cborTags());\n const content = extractTaggedContent(cbor);\n return this.fromUntaggedCbor(content);\n }\n\n /**\n * Static method to decode from tagged CBOR.\n */\n static fromTaggedCbor(cbor: Cbor): Digest {\n const instance = new Digest(new Uint8Array(Digest.DIGEST_SIZE));\n return instance.fromTaggedCbor(cbor);\n }\n\n /**\n * Static method to decode from tagged CBOR binary data.\n */\n static fromTaggedCborData(data: Uint8Array): Digest {\n const cbor = decodeCbor(data);\n return Digest.fromTaggedCbor(cbor);\n }\n\n /**\n * Static method to decode from untagged CBOR binary data.\n */\n static fromUntaggedCborData(data: Uint8Array): Digest {\n const cbor = decodeCbor(data);\n const bytes = expectBytes(cbor);\n return Digest.fromData(bytes);\n }\n\n // ============================================================================\n // UR Serialization (UREncodable)\n // ============================================================================\n\n /**\n * Returns the UR representation of the Digest.\n * Note: URs use untagged CBOR since the type is conveyed by the UR type itself.\n */\n ur(): UR {\n return UR.new(\"digest\", this.untaggedCbor());\n }\n\n /**\n * Returns the UR string representation.\n */\n urString(): string {\n return this.ur().string();\n }\n\n /**\n * Creates a Digest from a UR.\n */\n static fromUR(ur: UR): Digest {\n ur.checkType(\"digest\");\n const instance = new Digest(new Uint8Array(Digest.DIGEST_SIZE));\n return instance.fromUntaggedCbor(ur.cbor());\n }\n\n /**\n * Creates a Digest from a UR string.\n */\n static fromURString(urString: string): Digest {\n const ur = UR.fromURString(urString);\n return Digest.fromUR(ur);\n }\n\n // ============================================================================\n // Static Utility Methods\n // ============================================================================\n\n /**\n * Validate the given data against the digest, if any.\n *\n * Returns `true` if the digest is `undefined` or if the digest matches the\n * image's digest. Returns `false` if the digest does not match.\n */\n static validateOpt(image: Uint8Array, digest: Digest | undefined): boolean {\n if (digest === undefined) {\n return true;\n }\n return digest.validate(image);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAY,YAAL,yBAAA,WAAA;;AAEL,WAAA,iBAAA;;AAEA,WAAA,iBAAA;;AAEA,WAAA,kBAAA;;AAEA,WAAA,YAAA;;AAEA,WAAA,UAAA;;AAEA,WAAA,UAAA;;AAEA,WAAA,SAAA;;AAEA,WAAA,SAAA;;AAEA,WAAA,iBAAA;;AAEA,WAAA,iBAAA;;AAEA,WAAA,mBAAA;;AAEA,WAAA,cAAA;;AAEA,WAAA,SAAA;;AAEA,WAAA,UAAA;;AAEA,WAAA,SAAA;;AAEA,WAAA,oBAAA;;AAEA,WAAA,aAAA;;KACD;;;;;;;;;;AA2DD,IAAa,cAAb,MAAa,oBAAoB,MAAM;;CAErC;;CAGA;CAEA,YAAoB,SAAiB,WAAsB;AACzD,QAAM,QAAQ;AACd,OAAK,OA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