@wemush/wols 1.2.0 → 1.3.0

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 (98) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/README.md +204 -31
  3. package/dist/cjs/compact-url.d.ts +150 -0
  4. package/dist/cjs/compact-url.d.ts.map +1 -0
  5. package/dist/cjs/crypto/decrypt.d.ts +110 -0
  6. package/dist/cjs/crypto/decrypt.d.ts.map +1 -0
  7. package/dist/cjs/crypto/decrypt.js +519 -99
  8. package/dist/cjs/crypto/decrypt.js.map +1 -1
  9. package/dist/cjs/crypto/encrypt.d.ts +132 -0
  10. package/dist/cjs/crypto/encrypt.d.ts.map +1 -0
  11. package/dist/cjs/crypto/encrypt.js +281 -200
  12. package/dist/cjs/crypto/encrypt.js.map +1 -1
  13. package/dist/cjs/crypto/index.d.ts +12 -0
  14. package/dist/cjs/crypto/index.d.ts.map +1 -0
  15. package/dist/cjs/crypto/index.js +15 -2
  16. package/dist/cjs/crypto/index.js.map +1 -1
  17. package/dist/cjs/crypto/shared.d.ts +116 -0
  18. package/dist/cjs/crypto/shared.d.ts.map +1 -0
  19. package/dist/cjs/crypto/shared.js +238 -0
  20. package/dist/cjs/crypto/shared.js.map +1 -0
  21. package/dist/cjs/errors.d.ts +133 -0
  22. package/dist/cjs/errors.d.ts.map +1 -0
  23. package/dist/cjs/errors.js +39 -1
  24. package/dist/cjs/errors.js.map +1 -1
  25. package/dist/cjs/index.d.ts +29 -0
  26. package/dist/cjs/index.d.ts.map +1 -0
  27. package/dist/cjs/index.js +19 -4
  28. package/dist/cjs/index.js.map +1 -1
  29. package/dist/cjs/package.json +3 -0
  30. package/dist/cjs/parser.d.ts +30 -0
  31. package/dist/cjs/parser.d.ts.map +1 -0
  32. package/dist/cjs/qr/generate.d.ts +62 -0
  33. package/dist/cjs/qr/generate.d.ts.map +1 -0
  34. package/dist/cjs/qr/index.d.ts +10 -0
  35. package/dist/cjs/qr/index.d.ts.map +1 -0
  36. package/dist/cjs/specimen.d.ts +96 -0
  37. package/dist/cjs/specimen.d.ts.map +1 -0
  38. package/dist/cjs/specimen.js +84 -11
  39. package/dist/cjs/specimen.js.map +1 -1
  40. package/dist/cjs/types.d.ts +735 -0
  41. package/dist/cjs/types.d.ts.map +1 -0
  42. package/dist/cjs/types.js +65 -5
  43. package/dist/cjs/types.js.map +1 -1
  44. package/dist/cjs/utils/cuid.d.ts +46 -0
  45. package/dist/cjs/utils/cuid.d.ts.map +1 -0
  46. package/dist/cjs/utils/cuid.js +6 -4
  47. package/dist/cjs/utils/cuid.js.map +1 -1
  48. package/dist/cjs/utils/environment.d.ts +137 -0
  49. package/dist/cjs/utils/environment.d.ts.map +1 -0
  50. package/dist/cjs/utils/iso8601.d.ts +79 -0
  51. package/dist/cjs/utils/iso8601.d.ts.map +1 -0
  52. package/dist/cjs/utils/migration.d.ts +162 -0
  53. package/dist/cjs/utils/migration.d.ts.map +1 -0
  54. package/dist/cjs/validator.d.ts +25 -0
  55. package/dist/cjs/validator.d.ts.map +1 -0
  56. package/dist/cjs/validator.js +33 -22
  57. package/dist/cjs/validator.js.map +1 -1
  58. package/dist/esm/crypto/decrypt.js +515 -99
  59. package/dist/esm/crypto/decrypt.js.map +1 -1
  60. package/dist/esm/crypto/encrypt.js +277 -200
  61. package/dist/esm/crypto/encrypt.js.map +1 -1
  62. package/dist/esm/crypto/index.js +5 -3
  63. package/dist/esm/crypto/index.js.map +1 -1
  64. package/dist/esm/crypto/shared.js +222 -0
  65. package/dist/esm/crypto/shared.js.map +1 -0
  66. package/dist/esm/errors.js +37 -0
  67. package/dist/esm/errors.js.map +1 -1
  68. package/dist/esm/index.js +6 -6
  69. package/dist/esm/index.js.map +1 -1
  70. package/dist/esm/specimen.js +84 -12
  71. package/dist/esm/specimen.js.map +1 -1
  72. package/dist/esm/types.js +63 -4
  73. package/dist/esm/types.js.map +1 -1
  74. package/dist/esm/utils/cuid.js +6 -4
  75. package/dist/esm/utils/cuid.js.map +1 -1
  76. package/dist/esm/validator.js +34 -23
  77. package/dist/esm/validator.js.map +1 -1
  78. package/dist/types/crypto/decrypt.d.ts +93 -22
  79. package/dist/types/crypto/decrypt.d.ts.map +1 -1
  80. package/dist/types/crypto/encrypt.d.ts +106 -61
  81. package/dist/types/crypto/encrypt.d.ts.map +1 -1
  82. package/dist/types/crypto/index.d.ts +5 -3
  83. package/dist/types/crypto/index.d.ts.map +1 -1
  84. package/dist/types/crypto/shared.d.ts +116 -0
  85. package/dist/types/crypto/shared.d.ts.map +1 -0
  86. package/dist/types/errors.d.ts +31 -1
  87. package/dist/types/errors.d.ts.map +1 -1
  88. package/dist/types/index.d.ts +7 -7
  89. package/dist/types/index.d.ts.map +1 -1
  90. package/dist/types/specimen.d.ts +29 -4
  91. package/dist/types/specimen.d.ts.map +1 -1
  92. package/dist/types/types.d.ts +265 -40
  93. package/dist/types/types.d.ts.map +1 -1
  94. package/dist/types/utils/cuid.d.ts +5 -3
  95. package/dist/types/utils/cuid.d.ts.map +1 -1
  96. package/dist/types/validator.d.ts +1 -1
  97. package/dist/types/validator.d.ts.map +1 -1
  98. package/package.json +32 -14
@@ -2,7 +2,7 @@
2
2
  * WOLS TypeScript Library - Core Types
3
3
  *
4
4
  * This module defines all the core types, interfaces, and enums
5
- * for the WeMush Open Labeling Standard (WOLS) v1.2.0.
5
+ * for the WeMush Open Labeling Standard (WOLS) v1.3.0.
6
6
  *
7
7
  * @packageDocumentation
8
8
  * @module @wemush/wols
@@ -10,7 +10,7 @@
10
10
  /**
11
11
  * WOLS specification version implemented by this library.
12
12
  */
13
- export declare const WOLS_VERSION = "1.2.0";
13
+ export declare const WOLS_VERSION = "1.3.0";
14
14
  /**
15
15
  * JSON-LD context URL for WOLS specimens.
16
16
  */
@@ -40,11 +40,22 @@ export type SpecimenType = 'CULTURE' | 'SPAWN' | 'SUBSTRATE' | 'FRUITING' | 'HAR
40
40
  * Array of valid specimen types for validation.
41
41
  */
42
42
  export declare const SPECIMEN_TYPES: readonly SpecimenType[];
43
+ /**
44
+ * Reserved type alias with special handling (WOLS v1.3.0).
45
+ *
46
+ * `PRIMORDIA` is a GrowthStage, not a SpecimenType. When it is supplied as a
47
+ * type, it resolves to `FRUITING` and `createSpecimen()` sets
48
+ * `stage: 'PRIMORDIA'` unless a stage was supplied.
49
+ *
50
+ * @since 1.3.0
51
+ */
52
+ export declare const PRIMORDIA_TYPE_ALIAS = "PRIMORDIA";
43
53
  /**
44
54
  * Register a custom type alias.
45
55
  *
46
56
  * @param alias - The alias string (case-insensitive, stored uppercase)
47
57
  * @param wolsType - The canonical WOLS SpecimenType
58
+ * @throws Error if `alias` is the reserved `PRIMORDIA` alias
48
59
  *
49
60
  * @example
50
61
  * ```typescript
@@ -65,8 +76,41 @@ export declare function registerTypeAlias(alias: string, wolsType: SpecimenType)
65
76
  * resolveTypeAlias('CULTURE') // Returns 'CULTURE'
66
77
  * resolveTypeAlias('unknown') // Returns 'unknown'
67
78
  * ```
79
+ *
80
+ * @remarks Maps the type only. `PRIMORDIA` resolves to `FRUITING` here and
81
+ * the PRIMORDIA stage is lost; use {@link resolveTypeAndStage} when building
82
+ * a specimen from user input.
68
83
  */
69
84
  export declare function resolveTypeAlias(typeOrAlias: string): SpecimenType | string;
85
+ /**
86
+ * Resolve a supplied specimen type (canonical or alias, any case) together
87
+ * with its stage, applying the reserved `PRIMORDIA` rule (WOLS v1.3.0).
88
+ *
89
+ * This is the single source of truth used by `createSpecimen()` and
90
+ * `serializeSpecimen()`. `resolveTypeAlias()` and `mapToWolsType()` map the
91
+ * type only; integrations that map a type and then build a specimen
92
+ * themselves should use this function so the `PRIMORDIA` stage is not lost.
93
+ *
94
+ * - `PRIMORDIA` resolves to `FRUITING`, and `stage` becomes `'PRIMORDIA'`
95
+ * only when no stage was supplied (a supplied stage is never overridden).
96
+ * `primordia` is `true` so callers can warn.
97
+ * - Other aliases resolve the type and leave `stage` unchanged.
98
+ * - Unknown types return `null`.
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * resolveTypeAndStage('primordia') // { type: 'FRUITING', stage: 'PRIMORDIA', primordia: true }
103
+ * resolveTypeAndStage('PRIMORDIA', 'FRUITING') // { type: 'FRUITING', stage: 'FRUITING', primordia: true }
104
+ * resolveTypeAndStage('LC') // { type: 'CULTURE', stage: undefined, primordia: false }
105
+ * ```
106
+ *
107
+ * @since 1.3.0
108
+ */
109
+ export declare function resolveTypeAndStage(type: string, stage?: GrowthStage): {
110
+ type: SpecimenType;
111
+ stage: GrowthStage | undefined;
112
+ primordia: boolean;
113
+ } | null;
70
114
  /**
71
115
  * Get all registered type aliases.
72
116
  *
@@ -97,6 +141,10 @@ export declare const WOLS_TO_PLATFORM_MAP: Readonly<Record<SpecimenType, readonl
97
141
  * mapToWolsType('Unknown Type') // Returns null
98
142
  * ```
99
143
  *
144
+ * @remarks Maps the type only. `PRIMORDIA` maps to `FRUITING` and the
145
+ * PRIMORDIA stage is lost; use {@link resolveTypeAndStage} when building a
146
+ * specimen from user input.
147
+ *
100
148
  * @since 1.2.0
101
149
  */
102
150
  export declare function mapToWolsType(platformType: string): SpecimenType | null;
@@ -223,15 +271,27 @@ export interface Strain {
223
271
  name: string;
224
272
  /** Filial generation (e.g., "F1", "F2", "P") */
225
273
  generation?: string;
226
- /** Subculture/clone count (1, 2, 3...) */
274
+ /**
275
+ * Culture-to-culture subculture count. The original culture is `0`.
276
+ * Expansion to grain or substrate does not increment it.
277
+ */
227
278
  clonalGeneration?: number;
279
+ /**
280
+ * Total transfers of any kind from the original culture of this strain
281
+ * (subculture, culture to grain, grain to grain, grain to substrate).
282
+ * The original culture is `0`. Non-negative integer; SHOULD be at least
283
+ * `clonalGeneration` when both are present.
284
+ *
285
+ * @since 1.3.0
286
+ */
287
+ transferDepth?: number;
228
288
  /** Parent specimen ID reference */
229
289
  lineage?: string;
230
290
  /** Origin: "spore", "tissue", "agar", "liquid" */
231
291
  source?: string;
232
292
  }
233
293
  /**
234
- * Primary specimen entity following WOLS v1.1.0 JSON-LD schema.
294
+ * Primary specimen entity following the WOLS v1.3.0 JSON-LD schema.
235
295
  */
236
296
  export interface Specimen {
237
297
  /** JSON-LD context URL */
@@ -274,7 +334,11 @@ export interface Specimen {
274
334
  * Type accepts aliases (e.g., 'LIQUID_CULTURE' -> 'CULTURE') via resolveTypeAlias().
275
335
  */
276
336
  export interface SpecimenInput {
277
- /** Cultivation stage type (accepts aliases like 'LIQUID_CULTURE' -> 'CULTURE') */
337
+ /**
338
+ * Cultivation stage type. Accepts aliases case-insensitively
339
+ * (e.g. 'LIQUID_CULTURE' -> 'CULTURE'). `PRIMORDIA` resolves to `FRUITING`
340
+ * and sets `stage: 'PRIMORDIA'` when no stage is supplied (v1.3.0).
341
+ */
278
342
  type: SpecimenType | string;
279
343
  /** Scientific species name */
280
344
  species: string;
@@ -282,6 +346,13 @@ export interface SpecimenInput {
282
346
  strain?: string | Strain;
283
347
  /** Current growth stage */
284
348
  stage?: GrowthStage;
349
+ /**
350
+ * Creation timestamp (ISO 8601 string, or a Date converted with toISOString()).
351
+ * Omitted from the specimen when not supplied.
352
+ *
353
+ * @since 1.3.0
354
+ */
355
+ created?: string | Date;
285
356
  /** Batch identifier */
286
357
  batch?: string;
287
358
  /** Organization ID */
@@ -296,11 +367,23 @@ export interface SpecimenInput {
296
367
  */
297
368
  _meta?: SpecimenMeta;
298
369
  }
370
+ /**
371
+ * Options for createSpecimen().
372
+ *
373
+ * @since 1.3.0
374
+ */
375
+ export interface CreateSpecimenOptions {
376
+ /**
377
+ * Receives non-fatal warnings raised while creating the specimen, such as
378
+ * `PRIMORDIA` supplied as a type. When omitted, warnings go to console.warn.
379
+ */
380
+ onWarning?: (warning: ValidationWarning) => void;
381
+ }
299
382
  /**
300
383
  * Import error types for use in ParseResult.
301
384
  * Circular dependency avoided by using forward reference.
302
385
  */
303
- import type { WolsError } from './errors.js';
386
+ import type { WolsDecryptionError, WolsError } from './errors.js';
304
387
  /**
305
388
  * Parse result discriminated union.
306
389
  * @template T The type of data on success
@@ -352,7 +435,7 @@ export interface ValidationResult {
352
435
  *
353
436
  * @since 1.2.0
354
437
  */
355
- export type IdValidationMode = 'strict' | 'ulid' | 'uuid' | 'any';
438
+ export type IdValidationMode = 'any' | 'strict' | 'ulid' | 'uuid';
356
439
  /**
357
440
  * Custom ID validator function signature.
358
441
  *
@@ -368,14 +451,15 @@ export interface ValidationOptions {
368
451
  /** Validation strictness level */
369
452
  level?: 'strict' | 'lenient';
370
453
  /**
371
- * ID format validation mode.
454
+ * ID format validation mode. Every mode requires the `wemush:` prefix.
372
455
  *
373
- * - 'strict': ID must match `wemush:[a-z0-9]+` (default)
374
- * - 'ulid': ID must be a valid ULID after wemush: prefix
375
- * - 'uuid': ID must be a valid UUID v4 after wemush: prefix
376
- * - 'any': Any non-empty string after wemush: prefix
456
+ * - 'any': any non-empty suffix after `wemush:` (default; required by WOLS)
457
+ * - 'strict': opt-in CUID-style check, suffix must match `[a-z0-9]+`
458
+ * - 'ulid': opt-in check, suffix must be a valid ULID
459
+ * - 'uuid': opt-in check, suffix must be a valid UUID
377
460
  *
378
461
  * @since 1.2.0
462
+ * @since 1.3.0 Default changed from 'strict' to 'any'
379
463
  */
380
464
  idMode?: IdValidationMode;
381
465
  /**
@@ -431,70 +515,211 @@ export interface QRCodeOptions {
431
515
  light?: string;
432
516
  };
433
517
  }
518
+ /**
519
+ * Key derivation function recorded in an encrypted label (WOLS v1.3.0).
520
+ *
521
+ * - 'pbkdf2': key derived from a passphrase with PBKDF2-HMAC-SHA256 and a per-label salt
522
+ * - 'raw': a 32-byte AES-256 key shared out of band
523
+ *
524
+ * @since 1.3.0
525
+ */
526
+ export type EncryptionKdf = 'pbkdf2' | 'raw';
527
+ /**
528
+ * Raw AES-256 key material: 32 bytes, or an AES-GCM CryptoKey of length 256.
529
+ * Selects `kdf=raw`.
530
+ *
531
+ * @since 1.3.0
532
+ */
533
+ export type RawEncryptionKey = Uint8Array | ArrayBuffer | CryptoKey;
434
534
  /**
435
535
  * Encryption options.
436
536
  *
537
+ * A passphrase string selects `kdf=pbkdf2` (fresh random 16-byte salt per label).
538
+ * Raw key bytes or a CryptoKey select `kdf=raw`.
539
+ *
437
540
  * @since 1.2.0 Added `iterations` option for configurable PBKDF2 strength
541
+ * @since 1.3.0 Raw key bytes accepted; per-label random salt; minimum 100,000 iterations
438
542
  */
439
543
  export interface EncryptionOptions {
440
- /** CryptoKey or password string for PBKDF2 */
441
- key: CryptoKey | string;
442
- /** Fields to encrypt (partial encryption) */
443
- fields?: string[];
544
+ /** Passphrase (kdf=pbkdf2) or raw 32-byte key / AES-GCM CryptoKey (kdf=raw) */
545
+ key: string | RawEncryptionKey;
444
546
  /**
445
- * PBKDF2 iteration count for password-based key derivation.
547
+ * Fields to encrypt in place instead of the whole specimen.
446
548
  *
447
- * Higher values increase security but slow down encryption/decryption.
448
- * Ignored when `key` is a CryptoKey (already derived).
549
+ * @deprecated Use {@link encryptFields} (typed result). Kept for 1.2.x
550
+ * compatibility; the result is the specimen with those fields replaced,
551
+ * not an {@link EncryptedSpecimen} wrapper.
552
+ */
553
+ fields?: string[];
554
+ /**
555
+ * PBKDF2 iteration count for passphrase keys. Ignored for raw keys.
449
556
  *
450
- * - Default: 100000 (100k)
451
- * - Minimum: 10000 (10k) - lower values will throw an error
452
- * - Recommended: 100000-600000 depending on performance requirements
557
+ * - Default: 600,000 (WOLS 1.3.0)
558
+ * - Allowed when generating: 100,000 to 10,000,000; other values throw
453
559
  *
454
560
  * @since 1.2.0
455
561
  */
456
562
  iterations?: number;
457
563
  }
458
564
  /**
459
- * Encrypted specimen wrapper.
565
+ * Options for `encryptFields()` (field-level encryption).
566
+ *
567
+ * @since 1.3.0
568
+ */
569
+ export interface FieldEncryptionOptions<K extends keyof Specimen = keyof Specimen> {
570
+ /** Passphrase (kdf=pbkdf2) or raw 32-byte key / AES-GCM CryptoKey (kdf=raw) */
571
+ key: string | RawEncryptionKey;
572
+ /**
573
+ * Names of specimen fields to encrypt. Each must be present on the specimen.
574
+ * `@context`, `@type`, `id`, `version`, `type` and `species` identify the
575
+ * label and cannot be encrypted.
576
+ */
577
+ fields: readonly K[];
578
+ /** PBKDF2 iteration count for passphrase keys (default 600,000; 100,000 to 10,000,000) */
579
+ iterations?: number;
580
+ }
581
+ /**
582
+ * Field-level encrypted value (WOLS v1.3.0). Replaces the value of an
583
+ * encrypted field inside an embedded label. The plaintext is the UTF-8 JSON
584
+ * serialization of the original field value.
585
+ *
586
+ * @since 1.3.0
587
+ */
588
+ export interface EncryptedField {
589
+ encrypted: true;
590
+ algorithm: 'AES-256-GCM';
591
+ /** Ciphertext with the 16-byte GCM tag appended, base64url without padding */
592
+ payload: string;
593
+ /** 12-byte IV, base64url without padding */
594
+ iv: string;
595
+ kdf: EncryptionKdf;
596
+ /** PBKDF2 salt, base64url without padding (kdf=pbkdf2 only) */
597
+ salt?: string;
598
+ /** PBKDF2 iteration count (kdf=pbkdf2 only) */
599
+ iterations?: number;
600
+ }
601
+ /**
602
+ * A specimen in which some field values have been replaced by
603
+ * {@link EncryptedField} objects (output of `encryptFields()`).
604
+ *
605
+ * Each encrypted value is bound to its label and field by AES-GCM additional
606
+ * data (`"{id}\n{field}"`, WOLS 1.3.0), so a value moved to another field or
607
+ * copied into another label fails authentication.
608
+ *
609
+ * @since 1.3.0
610
+ */
611
+ export type FieldEncryptedSpecimen = {
612
+ [K in keyof Specimen]: Specimen[K] | EncryptedField;
613
+ };
614
+ /**
615
+ * Precise result of `encryptFields(specimen, { fields })`: the named fields
616
+ * are {@link EncryptedField}s and every other field keeps its cleartext type.
617
+ * Assignable to {@link FieldEncryptedSpecimen}.
618
+ *
619
+ * @since 1.3.0
620
+ */
621
+ export type FieldEncryptedSpecimenOf<K extends keyof Specimen> = Omit<Specimen, K> & {
622
+ [P in K]-?: EncryptedField;
623
+ };
624
+ /**
625
+ * Encrypted specimen.
626
+ *
627
+ * Objects produced by v1.3.0 always carry `kdf`, `id` and `url`; `url` is the
628
+ * `wemush://v1/encrypted/{id}?e=&iv=&kdf=...` wire format to put in a QR code.
629
+ * Objects without `kdf` are legacy (pre-1.3.0) and decrypt only with
630
+ * `allowLegacy: true`.
460
631
  *
461
632
  * @since 1.2.0 Added `cryptoVersion` and `iterations` fields for migration support
633
+ * @since 1.3.0 Added `kdf`, `salt`, `id`, `url` and `signature`
462
634
  */
463
635
  export interface EncryptedSpecimen {
464
636
  /** Flag indicating this is encrypted */
465
637
  encrypted: true;
466
- /** Base64url encoded ciphertext */
638
+ /** Ciphertext with the 16-byte GCM tag appended, base64url without padding */
467
639
  payload: string;
468
- /** Base64url encoded initialization vector */
640
+ /** 12-byte IV, base64url without padding */
469
641
  iv: string;
470
642
  /** Encryption algorithm used */
471
643
  algorithm: 'AES-256-GCM';
472
- /** Authentication tag (for GCM) */
473
- tag?: string;
474
644
  /**
475
- * Crypto schema version for forward-compatible migrations.
476
- * Allows future versions to change key derivation while maintaining
477
- * backward compatibility for decryption.
478
- *
479
- * @since 1.2.0
645
+ * Key derivation function. Absent only on legacy (pre-1.3.0) payloads.
646
+ * @since 1.3.0
480
647
  */
481
- cryptoVersion?: 'v1';
648
+ kdf?: EncryptionKdf;
482
649
  /**
483
- * PBKDF2 iteration count used during encryption.
484
- * Stored in payload for self-describing decryption (no need to guess).
485
- * If absent, defaults to 100000 for backward compatibility.
486
- *
487
- * @since 1.2.0
650
+ * PBKDF2 salt, base64url without padding (kdf=pbkdf2 only).
651
+ * @since 1.3.0
488
652
  */
653
+ salt?: string;
654
+ /** PBKDF2 iteration count (kdf=pbkdf2, or legacy payloads) */
489
655
  iterations?: number;
656
+ /**
657
+ * Full specimen ID (`wemush:...`). Cleartext; must match the decrypted specimen.
658
+ * @since 1.3.0
659
+ */
660
+ id?: string;
661
+ /**
662
+ * Encrypted-format URL for QR encoding.
663
+ * @since 1.3.0
664
+ */
665
+ url?: string;
666
+ /**
667
+ * Detached `sig` parameter from an encrypted URL. Preserved, not verified.
668
+ * @since 1.3.0
669
+ */
670
+ signature?: string;
671
+ /** @deprecated Unused; the GCM tag is appended to `payload`. Removed in 2.0. */
672
+ tag?: string;
673
+ /** @deprecated Legacy (pre-1.3.0) crypto schema marker. Removed in 2.0. */
674
+ cryptoVersion?: 'v1';
490
675
  }
491
676
  /**
492
677
  * Decryption options.
678
+ *
679
+ * @since 1.3.0 Raw key bytes accepted; `allowLegacy` added
493
680
  */
494
681
  export interface DecryptionOptions {
495
- /** CryptoKey or password string for PBKDF2 */
496
- key: CryptoKey | string;
682
+ /** Passphrase (kdf=pbkdf2) or raw 32-byte key / AES-GCM CryptoKey (kdf=raw) */
683
+ key: string | RawEncryptionKey;
684
+ /**
685
+ * Decrypt legacy payloads that have no `kdf` (pre-1.3.0, fixed library salt).
686
+ * Off by default. Legacy payloads are never generated.
687
+ *
688
+ * @since 1.3.0
689
+ */
690
+ allowLegacy?: boolean;
691
+ /**
692
+ * Largest PBKDF2 iteration count accepted from a label. The count comes
693
+ * from the (untrusted) label, so this bounds the CPU an attacker-supplied
694
+ * label can cost. Labels above it fail with `excessive-iterations`.
695
+ *
696
+ * - Default and maximum: 10,000,000 (WOLS 1.3.0). It may be set lower,
697
+ * never higher. `decryptFields` applies it to the label's total.
698
+ *
699
+ * @since 1.3.0
700
+ */
701
+ maxIterations?: number;
497
702
  }
703
+ /**
704
+ * Category of a decryption failure, available as `error.reason` on
705
+ * {@link WolsDecryptionError} (and as `error.details.reason`).
706
+ *
707
+ * @since 1.3.0
708
+ */
709
+ export type DecryptionFailureReason = 'invalid-url' | 'invalid-encoding' | 'missing-parameter' | 'invalid-parameter' | 'unexpected-parameter' | 'unsupported-kdf' | 'insufficient-iterations' | 'excessive-iterations' | 'invalid-key' | 'legacy-format' | 'authentication-failed' | 'invalid-plaintext' | 'id-mismatch' | 'identifying-field' | 'unsupported-environment';
710
+ /**
711
+ * Result of a decryption call: like {@link ParseResult}, but a failure always
712
+ * carries a {@link WolsDecryptionError} with a typed `reason`.
713
+ *
714
+ * @since 1.3.0
715
+ */
716
+ export type DecryptResult<T> = {
717
+ success: true;
718
+ data: T;
719
+ } | {
720
+ success: false;
721
+ error: WolsDecryptionError;
722
+ };
498
723
  /**
499
724
  * Type guard to check if a value is a valid SpecimenType.
500
725
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH;;GAEG;AACH,eAAO,MAAM,YAAY,UAAU,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,YAAY,+BAA+B,CAAC;AAMzD;;;GAGG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC;AAEtD;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAErD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU,CAEnD;AAMD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,OAAO,GAAG,WAAW,GAAG,UAAU,GAAG,SAAS,CAAC;AAEtF;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,YAAY,EAMxC,CAAC;AA0CX;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,GAAG,IAAI,CAE7E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,YAAY,GAAG,MAAM,CAW3E;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,CAElE;AAMD;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC,CAMlF,CAAC;AAEF;;;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IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAC/B,aAAa,GACb,kBAAkB,GAClB,mBAAmB,GACnB,mBAAmB,GACnB,sBAAsB,GACtB,iBAAiB,GACjB,yBAAyB,GACzB,sBAAsB,GACtB,aAAa,GACb,eAAe,GACf,uBAAuB,GACvB,mBAAmB,GACnB,aAAa,GACb,mBAAmB,GACnB,yBAAyB,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IACvB;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAC1B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,mBAAmB,CAAA;CAAE,CAAC;AAMnD;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAOxD"}
@@ -35,10 +35,12 @@ export declare function createId(length?: number): string;
35
35
  */
36
36
  export declare function createSpecimenId(): string;
37
37
  /**
38
- * Validate a specimen ID format.
38
+ * Validate a specimen ID: the `wemush:` prefix followed by any non-empty suffix
39
+ * (WOLS v1.3.0). Pass `strict: true` for the CUID-style `wemush:[a-z0-9]+` check.
39
40
  *
40
41
  * @param id - The ID to validate
41
- * @returns true if the ID matches the expected format
42
+ * @param strict - Require a lowercase alphanumeric suffix
43
+ * @returns true if the ID is valid
42
44
  */
43
- export declare function isValidSpecimenId(id: string): boolean;
45
+ export declare function isValidSpecimenId(id: string, strict?: boolean): boolean;
44
46
  //# sourceMappingURL=cuid.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cuid.d.ts","sourceRoot":"","sources":["../../../src/utils/cuid.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAuGH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,MAAM,GAAE,MAAuB,GAAG,MAAM,CAiBhE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAErD"}
1
+ {"version":3,"file":"cuid.d.ts","sourceRoot":"","sources":["../../../src/utils/cuid.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAuGH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,MAAM,GAAE,MAAuB,GAAG,MAAM,CAiBhE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,OAAO,CAErE"}
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import { type Specimen, type ValidationOptions, type ValidationResult } from './types.js';
9
9
  /**
10
- * Validate a specimen object against the WOLS v1.1.0 schema.
10
+ * Validate a specimen object against the WOLS v1.3.0 schema.
11
11
  *
12
12
  * @param specimen - The specimen object to validate
13
13
  * @param options - Validation options
@@ -1 +1 @@
1
- {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAGL,KAAK,QAAQ,EAGb,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EAGtB,MAAM,YAAY,CAAC;AAkepB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,QAAQ,GAAG,OAAO,EAC5B,OAAO,GAAE,iBAAsB,GAC9B,gBAAgB,CAgDlB"}
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAIL,KAAK,QAAQ,EAGb,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EAGtB,MAAM,YAAY,CAAC;AA4fpB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,QAAQ,GAAG,OAAO,EAC5B,OAAO,GAAE,iBAAsB,GAC9B,gBAAgB,CAgDlB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wemush/wols",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Official WOLS (WeMush Open Labeling Standard) library for specimen labeling and traceability",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -8,19 +8,34 @@
8
8
  "types": "./dist/types/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
- "import": "./dist/esm/index.js",
12
- "require": "./dist/cjs/index.js",
13
- "types": "./dist/types/index.d.ts"
11
+ "import": {
12
+ "types": "./dist/types/index.d.ts",
13
+ "default": "./dist/esm/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/cjs/index.d.ts",
17
+ "default": "./dist/cjs/index.js"
18
+ }
14
19
  },
15
20
  "./qr": {
16
- "import": "./dist/esm/qr/index.js",
17
- "require": "./dist/cjs/qr/index.js",
18
- "types": "./dist/types/qr/index.d.ts"
21
+ "import": {
22
+ "types": "./dist/types/qr/index.d.ts",
23
+ "default": "./dist/esm/qr/index.js"
24
+ },
25
+ "require": {
26
+ "types": "./dist/cjs/qr/index.d.ts",
27
+ "default": "./dist/cjs/qr/index.js"
28
+ }
19
29
  },
20
30
  "./crypto": {
21
- "import": "./dist/esm/crypto/index.js",
22
- "require": "./dist/cjs/crypto/index.js",
23
- "types": "./dist/types/crypto/index.d.ts"
31
+ "import": {
32
+ "types": "./dist/types/crypto/index.d.ts",
33
+ "default": "./dist/esm/crypto/index.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/cjs/crypto/index.d.ts",
37
+ "default": "./dist/cjs/crypto/index.js"
38
+ }
24
39
  }
25
40
  },
26
41
  "files": [
@@ -32,18 +47,21 @@
32
47
  "scripts": {
33
48
  "build": "npm run build:esm && npm run build:cjs && npm run build:types",
34
49
  "build:esm": "tsc -p tsconfig.esm.json",
35
- "build:cjs": "tsc -p tsconfig.cjs.json",
50
+ "build:cjs": "tsc -p tsconfig.cjs.json && node scripts/write-cjs-package.mjs",
36
51
  "build:types": "tsc -p tsconfig.types.json",
37
52
  "test": "vitest run",
38
53
  "test:watch": "vitest",
39
54
  "test:coverage": "vitest run --coverage",
55
+ "test:conformance": "vitest run tests/conformance",
56
+ "conformance:update": "node scripts/update-conformance-vectors.mjs",
40
57
  "lint": "eslint src --ext .ts",
41
58
  "lint:fix": "eslint src --ext .ts --fix",
42
59
  "format": "prettier --write \"src/**/*.ts\"",
43
60
  "typecheck": "tsc --noEmit",
44
61
  "bench": "vitest bench",
45
- "prepublishOnly": "npm run build && npm test",
46
- "clean": "rm -rf dist"
62
+ "prepublishOnly": "npm run build && npm test && npm run test:package",
63
+ "clean": "rm -rf dist",
64
+ "test:package": "node scripts/smoke-package.mjs"
47
65
  },
48
66
  "keywords": [
49
67
  "wols",
@@ -68,7 +86,7 @@
68
86
  },
69
87
  "homepage": "https://wemush.com/open-standard",
70
88
  "engines": {
71
- "node": ">=18.0.0"
89
+ "node": ">=20.0.0"
72
90
  },
73
91
  "peerDependencies": {
74
92
  "qrcode": ""