@anizoptera/uuid-slug 0.3.0 → 0.5.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 (202) hide show
  1. package/LICENSE +54 -31
  2. package/README.md +373 -324
  3. package/dist/alphabet.d.ts +5 -17
  4. package/dist/alphabet.d.ts.map +1 -1
  5. package/dist/alphabet.js +146 -112
  6. package/dist/alphabet.js.map +1 -1
  7. package/dist/base64url-name.d.ts +7 -0
  8. package/dist/base64url-name.d.ts.map +1 -0
  9. package/dist/base64url-name.js +8 -0
  10. package/dist/base64url-name.js.map +1 -0
  11. package/dist/errors.d.ts +50 -9
  12. package/dist/errors.d.ts.map +1 -1
  13. package/dist/errors.js +145 -63
  14. package/dist/errors.js.map +1 -1
  15. package/dist/feistel.js +29 -95
  16. package/dist/feistel.js.map +1 -1
  17. package/dist/generation-options.js +20 -0
  18. package/dist/generation-options.js.map +1 -0
  19. package/dist/index.d.ts +22 -10
  20. package/dist/index.js +21 -9
  21. package/dist/instant.js +83 -0
  22. package/dist/instant.js.map +1 -0
  23. package/dist/mask-handle.d.ts +16 -0
  24. package/dist/mask-handle.d.ts.map +1 -0
  25. package/dist/mask-handle.js +60 -0
  26. package/dist/mask-handle.js.map +1 -0
  27. package/dist/mask.d.ts +27 -0
  28. package/dist/mask.d.ts.map +1 -0
  29. package/dist/mask.js +151 -95
  30. package/dist/mask.js.map +1 -1
  31. package/dist/masking-codec-protocol.js +23 -0
  32. package/dist/masking-codec-protocol.js.map +1 -0
  33. package/dist/masking-codec-types.d.ts +245 -0
  34. package/dist/masking-codec-types.d.ts.map +1 -0
  35. package/dist/masking-codec.d.ts +19 -0
  36. package/dist/masking-codec.d.ts.map +1 -0
  37. package/dist/masking-codec.js +391 -0
  38. package/dist/masking-codec.js.map +1 -0
  39. package/dist/migration.js +114 -51
  40. package/dist/migration.js.map +1 -1
  41. package/dist/node/runtime.js +39 -0
  42. package/dist/node/runtime.js.map +1 -0
  43. package/dist/payload.d.ts +7 -0
  44. package/dist/payload.d.ts.map +1 -0
  45. package/dist/payload.js +118 -0
  46. package/dist/payload.js.map +1 -0
  47. package/dist/runtime/pool.js +21 -46
  48. package/dist/runtime/pool.js.map +1 -1
  49. package/dist/runtime/portable.js +27 -0
  50. package/dist/runtime/portable.js.map +1 -0
  51. package/dist/sentinel.js +10 -0
  52. package/dist/sentinel.js.map +1 -0
  53. package/dist/siphash.js +20 -99
  54. package/dist/siphash.js.map +1 -1
  55. package/dist/slug.d.ts +169 -0
  56. package/dist/slug.d.ts.map +1 -0
  57. package/dist/slug.js +268 -0
  58. package/dist/slug.js.map +1 -0
  59. package/dist/timestamp.d.ts +19 -0
  60. package/dist/timestamp.d.ts.map +1 -0
  61. package/dist/timestamp.js +44 -0
  62. package/dist/timestamp.js.map +1 -0
  63. package/dist/types.d.ts +480 -200
  64. package/dist/types.d.ts.map +1 -1
  65. package/dist/types.js +8 -0
  66. package/dist/types.js.map +1 -0
  67. package/dist/uuid-value-protocol.js +46 -0
  68. package/dist/uuid-value-protocol.js.map +1 -0
  69. package/dist/uuid-value.d.ts +17 -0
  70. package/dist/uuid-value.d.ts.map +1 -0
  71. package/dist/uuid-value.js +127 -0
  72. package/dist/uuid-value.js.map +1 -0
  73. package/dist/uuid.d.ts +51 -64
  74. package/dist/uuid.d.ts.map +1 -1
  75. package/dist/uuid.js +203 -199
  76. package/dist/uuid.js.map +1 -1
  77. package/dist/v4-slug.d.ts +16 -0
  78. package/dist/v4-slug.d.ts.map +1 -0
  79. package/dist/v4-slug.js +16 -0
  80. package/dist/v4-slug.js.map +1 -0
  81. package/dist/v4.d.ts +42 -0
  82. package/dist/v4.d.ts.map +1 -0
  83. package/dist/v4.js +85 -0
  84. package/dist/v4.js.map +1 -0
  85. package/dist/v7-bounds.d.ts +36 -0
  86. package/dist/v7-bounds.d.ts.map +1 -0
  87. package/dist/v7-bounds.js +49 -0
  88. package/dist/v7-bounds.js.map +1 -0
  89. package/dist/v7-generator-input.js +75 -0
  90. package/dist/v7-generator-input.js.map +1 -0
  91. package/dist/v7-generator.d.ts +43 -0
  92. package/dist/v7-generator.d.ts.map +1 -0
  93. package/dist/v7-generator.js +105 -0
  94. package/dist/v7-generator.js.map +1 -0
  95. package/dist/v7-keyless.d.ts +46 -0
  96. package/dist/v7-keyless.d.ts.map +1 -0
  97. package/dist/v7-keyless.js +106 -0
  98. package/dist/v7-keyless.js.map +1 -0
  99. package/dist/v7-payload.js +54 -0
  100. package/dist/v7-payload.js.map +1 -0
  101. package/dist/v7-slug.d.ts +46 -0
  102. package/dist/v7-slug.d.ts.map +1 -0
  103. package/dist/v7-slug.js +127 -0
  104. package/dist/v7-slug.js.map +1 -0
  105. package/dist/v7-timestamp.js +9 -0
  106. package/dist/v7-timestamp.js.map +1 -0
  107. package/dist/v7-value-options.js +28 -0
  108. package/dist/v7-value-options.js.map +1 -0
  109. package/dist/v7-value.d.ts +23 -0
  110. package/dist/v7-value.d.ts.map +1 -0
  111. package/dist/v7-value.js +31 -0
  112. package/dist/v7-value.js.map +1 -0
  113. package/dist/v7.js +127 -171
  114. package/dist/v7.js.map +1 -1
  115. package/package.json +15 -8
  116. package/src/alphabet.ts +456 -27
  117. package/src/base64url-name.ts +5 -0
  118. package/src/errors.ts +373 -37
  119. package/src/feistel.ts +69 -56
  120. package/src/generation-options.ts +48 -0
  121. package/src/index.ts +134 -80
  122. package/src/instant.ts +196 -0
  123. package/src/keyless.ts +7 -134
  124. package/src/mask-handle.ts +141 -0
  125. package/src/mask.ts +354 -129
  126. package/src/masking-codec-protocol.ts +29 -0
  127. package/src/masking-codec-types.ts +380 -0
  128. package/src/masking-codec.ts +923 -0
  129. package/src/migration.ts +195 -42
  130. package/src/payload.ts +321 -0
  131. package/src/runtime/bun.ts +30 -49
  132. package/src/runtime/node.ts +43 -24
  133. package/src/runtime/pool.ts +49 -21
  134. package/src/runtime/portable.ts +68 -0
  135. package/src/runtime/types.ts +23 -35
  136. package/src/sentinel.ts +13 -0
  137. package/src/siphash.ts +5 -4
  138. package/src/slug.ts +884 -0
  139. package/src/timestamp.ts +122 -0
  140. package/src/types.ts +759 -205
  141. package/src/uuid-value-protocol.ts +77 -0
  142. package/src/uuid-value.ts +341 -0
  143. package/src/uuid.ts +514 -234
  144. package/src/v4-slug.ts +27 -0
  145. package/src/v4.ts +234 -0
  146. package/src/v7-bounds.ts +171 -0
  147. package/src/v7-generator-input.ts +169 -0
  148. package/src/v7-generator.ts +245 -0
  149. package/src/v7-keyless.ts +354 -0
  150. package/src/v7-payload.ts +121 -0
  151. package/src/v7-slug.ts +293 -0
  152. package/src/v7-timestamp.ts +21 -0
  153. package/src/v7-value-options.ts +62 -0
  154. package/src/v7-value.ts +54 -0
  155. package/src/v7.ts +377 -200
  156. package/dist/base64url.d.ts +0 -20
  157. package/dist/base64url.d.ts.map +0 -1
  158. package/dist/base64url.js +0 -33
  159. package/dist/base64url.js.map +0 -1
  160. package/dist/codec.d.ts +0 -17
  161. package/dist/codec.d.ts.map +0 -1
  162. package/dist/codec.js +0 -192
  163. package/dist/codec.js.map +0 -1
  164. package/dist/keyless.d.ts +0 -31
  165. package/dist/keyless.d.ts.map +0 -1
  166. package/dist/keyless.js +0 -93
  167. package/dist/keyless.js.map +0 -1
  168. package/dist/legacy-mask.js +0 -55
  169. package/dist/legacy-mask.js.map +0 -1
  170. package/dist/node/alphabet.js +0 -130
  171. package/dist/node/base64url.js +0 -31
  172. package/dist/node/codec.js +0 -190
  173. package/dist/node/errors.js +0 -78
  174. package/dist/node/feistel.js +0 -103
  175. package/dist/node/index.js +0 -10
  176. package/dist/node/keyless.js +0 -91
  177. package/dist/node/legacy-mask.js +0 -53
  178. package/dist/node/mask.js +0 -106
  179. package/dist/node/migration.js +0 -64
  180. package/dist/node/runtime/node.js +0 -33
  181. package/dist/node/runtime/pool.js +0 -53
  182. package/dist/node/schema.js +0 -214
  183. package/dist/node/siphash.js +0 -106
  184. package/dist/node/uuid.js +0 -226
  185. package/dist/node/v7.js +0 -185
  186. package/dist/node/yield.js +0 -20
  187. package/dist/runtime/web.js +0 -39
  188. package/dist/runtime/web.js.map +0 -1
  189. package/dist/schema.d.ts +0 -20
  190. package/dist/schema.d.ts.map +0 -1
  191. package/dist/schema.js +0 -216
  192. package/dist/schema.js.map +0 -1
  193. package/dist/v7.d.ts +0 -12
  194. package/dist/v7.d.ts.map +0 -1
  195. package/dist/yield.js +0 -22
  196. package/dist/yield.js.map +0 -1
  197. package/src/base64url.ts +0 -41
  198. package/src/codec.ts +0 -320
  199. package/src/legacy-mask.ts +0 -25
  200. package/src/runtime/web.ts +0 -48
  201. package/src/schema.ts +0 -300
  202. package/src/yield.ts +0 -22
@@ -0,0 +1,83 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // @anizoptera/uuid-slug 0.5.0 | https://github.com/Anizoptera/uuid-slug#readme
3
+ import { INVALID_TIMESTAMP as e, UuidSlugError as t, stringInput as n } from "./errors.js";
4
+ import { MAX_UUID_V7_UNIX_MS as r } from "./v7-timestamp.js";
5
+ //#region src/instant.ts
6
+ const i = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(?:[Zz]|([+-])(\d{2}):(\d{2}))$/, a = BigInt(r), o = 1000000n, s = 4096, invalidInstant = (n) => new t(e, "UUIDv7 instant must be a finite Unix-millisecond value, a valid Date, zoned ISO timestamp text, or a supported epoch timestamp object.", n === void 0 ? void 0 : { cause: n });
7
+ function readUnixMilliseconds(e) {
8
+ if (typeof e == "number") {
9
+ if (!Number.isFinite(e) || e < 0 || e >= 281474976710656) return invalidInstant();
10
+ let t = Math.floor(e);
11
+ return {
12
+ unixMs: t,
13
+ fractionBucket12: Math.min(4095, Math.floor((e - t) * s))
14
+ };
15
+ }
16
+ return typeof e != "bigint" || e < 0n || e > a ? invalidInstant() : {
17
+ unixMs: Number(e),
18
+ fractionBucket12: 0
19
+ };
20
+ }
21
+ function readEpochNanoseconds(e) {
22
+ if (typeof e != "bigint" || e < 0n) return invalidInstant();
23
+ let t = e / o;
24
+ return t > a ? invalidInstant() : {
25
+ unixMs: Number(t),
26
+ fractionBucket12: Number(e % o * BigInt(s) / o)
27
+ };
28
+ }
29
+ function readDecimalFraction(e) {
30
+ let t = Number(e.slice(0, 3).padEnd(3, "0")), n = e.slice(3, 15).padEnd(12, "0");
31
+ return {
32
+ wholeMilliseconds: t,
33
+ fractionBucket12: Math.floor(Number(n) * s / 0xe8d4a51000)
34
+ };
35
+ }
36
+ function readZonedTimestamp(e) {
37
+ let t = i.exec(e);
38
+ if (t === null) return invalidInstant();
39
+ let [n, r, a, o, s, c] = t.slice(1, 7).map(Number), l = t[7] ?? "", u = t[8], d = Number(t[9] ?? 0), f = Number(t[10] ?? 0);
40
+ if (r < 1 || r > 12 || a < 1 || o > 23 || s > 59 || c > 59 || d > 23 || f > 59 || u === "-" && d === 0 && f === 0) return invalidInstant();
41
+ let p = /* @__PURE__ */ new Date(0);
42
+ if (p.setUTCFullYear(n, r - 1, a), p.setUTCHours(o, s, c, 0), p.getUTCFullYear() !== n || p.getUTCMonth() !== r - 1 || p.getUTCDate() !== a || p.getUTCHours() !== o || p.getUTCMinutes() !== s || p.getUTCSeconds() !== c) return invalidInstant();
43
+ let m = readDecimalFraction(l), h = (d * 60 + f) * 6e4, g = p.getTime() + m.wholeMilliseconds + (u === "+" ? -h : u === "-" ? h : 0);
44
+ return g < 0 || g > 0xffffffffffff ? invalidInstant() : {
45
+ unixMs: g,
46
+ fractionBucket12: m.fractionBucket12
47
+ };
48
+ }
49
+ function readUuidV7Instant(e) {
50
+ if (typeof e == "number" || typeof e == "bigint") return readUnixMilliseconds(e);
51
+ if (typeof e == "string") return readZonedTimestamp(e);
52
+ if (typeof e != "object" || !e) return invalidInstant();
53
+ let t;
54
+ try {
55
+ return readUnixMilliseconds(Date.prototype.getTime.call(e));
56
+ } catch (e) {
57
+ t = e;
58
+ }
59
+ let r = /* @__PURE__ */ n(e);
60
+ if (r !== void 0) return readZonedTimestamp(r);
61
+ try {
62
+ let t = e, n = t.epochMilliseconds, r = t.epochNanoseconds, i = t.seconds, a = t.nanoseconds;
63
+ if ((i !== void 0 || a !== void 0) && (n !== void 0 || r !== void 0)) return invalidInstant();
64
+ if (r !== void 0) {
65
+ let e = readEpochNanoseconds(r);
66
+ if (e instanceof Error || n === void 0) return e;
67
+ let t = readUnixMilliseconds(n);
68
+ return t instanceof Error || t.unixMs !== e.unixMs || t.fractionBucket12 !== e.fractionBucket12 && (t.fractionBucket12 !== 0 || typeof n == "number" && !Number.isInteger(n)) ? invalidInstant() : e;
69
+ }
70
+ if (n !== void 0) return readUnixMilliseconds(n);
71
+ if (i !== void 0) {
72
+ let e = a ?? 0;
73
+ return typeof i != "bigint" && (typeof i != "number" || !Number.isSafeInteger(i)) || typeof e != "bigint" && (typeof e != "number" || !Number.isSafeInteger(e)) || e < 0 || e > 999999999 ? invalidInstant() : readEpochNanoseconds(BigInt(i) * 1000000000n + BigInt(e));
74
+ }
75
+ } catch (e) {
76
+ return invalidInstant(e);
77
+ }
78
+ return invalidInstant(t);
79
+ }
80
+ //#endregion
81
+ export { readUuidV7Instant };
82
+
83
+ //# sourceMappingURL=instant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instant.js","names":["ZONED_TIMESTAMP","MAX_UUID_V7_UNIX_MS_BIGINT","MAX_UUID_V7_UNIX_MS","NANOS_PER_MILLISECOND","FRACTION_BUCKETS","UuidSlugError","INVALID_TIMESTAMP","cause","value","unixMs","wholeMilliseconds","fractionDigits","subMillisecondDigits","match","instant","year","month","day","hour","minute","second","offsetSign","offsetHour","offsetMinute","local","fraction","offset","dateCause","timestamp","source","epochMilliseconds","epochNanoseconds","seconds","nanoseconds","normalized","stated","resolvedNanoseconds"],"sources":["../src/instant.ts"],"mappings":";;;;;AAMA,MAEMA,IACJ,4GACIC,IAA6B,OAAOC,CAAmB,GACvDC,IAAwB,UAExBC,IAAmB,MAYnB,kBAAkB,MACtB,IAAIC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./errors.js";
4
+ import { CustomUuidV7MaskOptions, UuidV7Mask } from "./types.js";
5
+ //#region src/mask-handle.d.ts
6
+ /**
7
+ * Build an immutable mask from reversible 16-byte callbacks. Each callback receives isolated bytes,
8
+ * so returning the same array is safe. Invalid results and thrown values return `UuidSlugError`.
9
+ * The caller must ensure `unmask(mask(bytes))` restores every possible 16-byte input.
10
+ *
11
+ * @param options - Diagnostic label and mutually inverse 16-byte transforms.
12
+ * @returns The validated mask, or `UuidSlugError` for an invalid contract or callback result.
13
+ */
14
+ export declare function createCustomUuidV7Mask(options: CustomUuidV7MaskOptions): UuidV7Mask | UuidSlugError;
15
+ //#endregion
16
+ //# sourceMappingURL=mask-handle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mask-handle.d.ts","names":[],"sources":["../src/mask-handle.ts"],"mappings":";;;;;;;;;;;;;wBAuFgB,uBACd,SAAS,0BACR,aAAa"}
@@ -0,0 +1,60 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // @anizoptera/uuid-slug 0.5.0 | https://github.com/Anizoptera/uuid-slug#readme
3
+ import { INVALID_MASK as e, UuidSlugError as t, findUnknownOption as n, isUint8Array as r, isUuidSlugError as i, stringInput as a } from "./errors.js";
4
+ //#region src/mask-handle.ts
5
+ const o = Symbol.for("@anizoptera/uuid-slug/mask/1"), s = "Custom mask construction failed.", c = "mask", l = {
6
+ diagnosticLabel: !0,
7
+ [c]: !0,
8
+ unmask: !0
9
+ };
10
+ /*#__NO_SIDE_EFFECTS__*/
11
+ function createMaskHandle(e, t) {
12
+ let n = { diagnosticLabel: e };
13
+ return Object.defineProperty(n, o, { value: Object.freeze({
14
+ version: 1,
15
+ mix: t
16
+ }) }), Object.freeze(n);
17
+ }
18
+ function maskProtocol(e) {
19
+ if (typeof e != "object" || !e) return;
20
+ let t = e[o];
21
+ return t?.version === 1 && typeof t.mix == "function" ? t : void 0;
22
+ }
23
+ function isMaskHandle(e) {
24
+ return maskProtocol(e) !== void 0;
25
+ }
26
+ function applyMask(n, r, i, a) {
27
+ let o = maskProtocol(n);
28
+ return o ? o.mix(r, i, a) : new t(e, "Mask handle is invalid or incompatible.");
29
+ }
30
+ function runCustom(n, a) {
31
+ let o = n(a.slice());
32
+ return /* @__PURE__ */ i(o) ? o : !/* @__PURE__ */ r(o) || o.length !== 16 ? new t(e, "A custom mask transform must return exactly 16 bytes.") : o;
33
+ }
34
+ function createCustomUuidV7Mask(r) {
35
+ try {
36
+ if (typeof r != "object" || !r || Array.isArray(r)) return new t(e, "Custom mask options must be an object.");
37
+ let o = /* @__PURE__ */ n(r, l);
38
+ if (o !== void 0) return new t(e, `Unknown custom mask option: ${o}.`);
39
+ let { mask: u, unmask: d } = r, f = /* @__PURE__ */ a(r.diagnosticLabel);
40
+ if (typeof f != "string" || typeof u != "function" || typeof d != "function") return new t(e, "A custom UUIDv7 mask requires a string diagnosticLabel plus mask and unmask functions.");
41
+ for (let n of [/* @__PURE__ */ new Uint8Array(16), Uint8Array.from({ length: 16 }, (e, t) => t * 17)]) {
42
+ let r = runCustom(u, n);
43
+ if (/* @__PURE__ */ i(r)) return new t(e, s, { cause: r });
44
+ let a = runCustom(d, r);
45
+ if (/* @__PURE__ */ i(a)) return new t(e, s, { cause: a });
46
+ if (a.some((e, t) => e !== n[t])) return new t(e, `UUIDv7 mask "${f}" does not unmask its own masked output.`);
47
+ }
48
+ return /* @__PURE__ */ createMaskHandle(f, (e, t, n) => {
49
+ let r = runCustom(n === c ? u : d, e);
50
+ if (/* @__PURE__ */ i(r)) return r;
51
+ t.set(r);
52
+ });
53
+ } catch (n) {
54
+ return new t(e, s, { cause: n });
55
+ }
56
+ }
57
+ //#endregion
58
+ export { applyMask, createCustomUuidV7Mask, createMaskHandle, isMaskHandle };
59
+
60
+ //# sourceMappingURL=mask-handle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mask-handle.js","names":["MASK_PROTOCOL","CUSTOM_MASK_FAILURE_MESSAGE","MASK_DIRECTION","CUSTOM_MASK_OPTIONS","mask","protocol","input","output","direction","UuidSlugError","INVALID_MASK","transform","options","unknown","diagnosticLabel","unmask","probe","index","mixed","restored","byte","cause"],"sources":["../src/mask-handle.ts"],"mappings":";;;;AAYA,MAAMA,IAAgB,OAAO,IAAI,8BAA8B,GACzDC,IAA8B,oCAC9BC,IAAiB,QACjBC,IAAsB;CAC1B,iBAAiB;EAChBD,IAAiB;CAClB,QAAQ;AACV;;AAkBA,SAAgB,iBAAiB,GAAyB,GAAsC;CAC9F,IAAME,IAAO,EAAE,mBAAgB;CAI/B,OAHA,OAAO,eAAeA,GAAMJ,GAAe,EACzC,OAAO,OAAO,OAAqB;EAAE,SAAS;EAAG;CAAI,CAAC,EACxD,CAAC,GACM,OAAO,OAAOI,CAAI;AAC3B;AAEA,SAAS,aAAa,GAA4C;CAChE,IAAI,OAAOA,KAAS,aAAYA,GAAe;CAC/C,IAAMC,IAAYD,EAA6BJ;CAC/C,OAAOK,GAAU,YAAY,KAAK,OAAOA,EAAS,OAAQ,aAAaA,IAAW,KAAA;AACpF;AAEA,SAAgB,aAAa,GAAmC;CAC9D,OAAO,aAAaD,CAAkB,MAAM,KAAA;AAC9C;AAEA,SAAgB,UACd,GACA,GACA,GACA,GAC2B;CAC3B,IAAMC,IAAW,aAAaD,CAAI;CAElC,OADKC,IACEA,EAAS,IAAIC,GAAOC,GAAQC,CAAS,IADtB,IAAIC,EAAcC,GAAc,yCAAyC;AAEjG;AAEA,SAAS,UACP,GACA,GAC4B;CAG5B,IAAMH,IAASI,EAAUL,EAAM,MAAM,CAAC;CAItC,OAHI,kBAAgBC,CAAM,IAAUA,IAChC,CAAC,kBAAaA,CAAM,KAAKA,EAAO,WAAW,KACtC,IAAIE,EAAcC,GAAc,uDAAuD,IACzFH;AACT;AAUA,SAAgB,uBACd,GAC4B;CAC5B,IAAI;EACF,IAAI,OAAOK,KAAY,aAAYA,KAAoB,MAAM,QAAQA,CAAO,GAC1E,OAAO,IAAIH,EAAcC,GAAc,wCAA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uidSlugError } from "./errors.js";
4
+ import { AsyncUuidV7MaskOptions, UuidV7Mask, UuidV7MaskOptions } from "./types.js";
5
+ //#region src/mask.d.ts
6
+ /**
7
+ * Derive an immutable mask from a secret seed of at least 16 bytes. The seed and iteration count
8
+ * define the wire format; retain the old mask in `previousMasks` before changing either. Invalid
9
+ * options return `invalid_mask`.
10
+ *
11
+ * @param options - Stable secret seed, optional diagnostic label, and derivation work factor.
12
+ * @returns The mask, or `UuidSlugError` when an option or seed is invalid.
13
+ */
14
+ export declare function deriveUuidV7Mask(options: UuidV7MaskOptions): UuidV7Mask | UuidSlugError;
15
+ /**
16
+ * Derive the same mask without monopolizing the host task. Later mutation of a byte seed does not
17
+ * affect the result. Cancellation returns `aborted` with `signal.reason` as its cause; invalid
18
+ * options return `invalid_mask`. Construct once and reuse the result.
19
+ *
20
+ * @param options - Synchronous mask options plus an optional cancellation signal.
21
+ * @returns A promise for the mask or an expected construction error.
22
+ */
23
+ export declare function deriveUuidV7MaskAsync(options: AsyncUuidV7MaskOptions): Promise<UuidV7Mask | UuidSlugError>;
24
+ /** Public-key mask for deterministic tests and examples. Never use it to hide production IDs. */
25
+ export declare const UUID_V7_TEST_MASK: UuidV7Mask;
26
+ //#endregion
27
+ //# sourceMappingURL=mask.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mask.d.ts","names":[],"sources":["../src/mask.ts"],"mappings":";;;;;;;;;;;;;wBAuLgB,iBAAiB,SAAS,oBAAoB,aAAa;;;;;;;;;wBA6IrD,sBACpB,SAAS,yBACR,QAAQ,aAAa;;qBAmDX,mBAAmB"}
package/dist/mask.js CHANGED
@@ -1,108 +1,164 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- // @anizoptera/uuid-slug 0.3.0 | https://github.com/Anizoptera/uuid-slug#readme
3
- import { UuidSlugError } from "./errors.js";
4
- import { BASE64URL, decodeInto, encode, spareBits } from "./alphabet.js";
5
- import { formatUuid } from "./uuid.js";
6
- import { mix32, read32 } from "./feistel.js";
2
+ // @anizoptera/uuid-slug 0.5.0 | https://github.com/Anizoptera/uuid-slug#readme
3
+ import { ABORTED as e, INVALID_MASK as t, UuidSlugError as n, findUnknownOption as r, isUint8Array as i, stringInput as a } from "./errors.js";
4
+ import { feistel16 as o } from "./feistel.js";
5
+ import { createMaskHandle as s } from "./mask-handle.js";
6
+ import { halfSipHash as c } from "./siphash.js";
7
+ import { encodeUtf8 as l } from "#runtime";
7
8
  //#region src/mask.ts
8
- /** Custom callbacks can fail after construction; preserve their cause in the public error contract. */
9
- function applyMix(schema, input, output, forward) {
9
+ const u = "Mask construction failed.", d = "seed", f = {
10
+ keyDerivationIterations: !0,
11
+ diagnosticLabel: !0,
12
+ [d]: !0
13
+ }, p = {
14
+ ...f,
15
+ signal: !0
16
+ }, m = 1 << 24, h = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1, g = 4096;
17
+ /*#__NO_SIDE_EFFECTS__*/
18
+ function canViewSeedWords(e) {
19
+ return h && !(e.byteOffset & 3) && !(e.length & 3);
20
+ }
21
+ const _ = 1097297011, v = 1114074227, y = 1684632949;
22
+ function seedBytes(e) {
23
+ return typeof e == "string" ? l(e) : new Uint8Array(e);
24
+ }
25
+ function validateOptions(e, o) {
26
+ if (typeof e != "object" || !e) return new n(t, "Mask options must contain a string or Uint8Array seed.");
27
+ let s = e, c = /* @__PURE__ */ r(s, o);
28
+ if (c !== void 0) return new n(t, `Unknown mask option: ${c}.`);
29
+ let l = s.seed, u = typeof l == "string" || /* @__PURE__ */ i(l) ? l : /* @__PURE__ */ a(l);
30
+ if (u === void 0) return new n(t, "Mask seed must be a string or Uint8Array.");
31
+ let d = s.diagnosticLabel, f = /* @__PURE__ */ a(d === void 0 ? "seeded" : d);
32
+ if (f === void 0) return new n(t, "Mask diagnosticLabel must be a string.");
33
+ let p = s.keyDerivationIterations, m = validatedIterations(p === void 0 ? 1 : p);
34
+ return typeof m == "number" ? {
35
+ diagnosticLabel: f,
36
+ iterations: m,
37
+ seed: u
38
+ } : m;
39
+ }
40
+ /*#__NO_SIDE_EFFECTS__*/
41
+ function seedWords(e) {
42
+ if (e.length >= g && /* @__PURE__ */ canViewSeedWords(e)) return new Int32Array(e.buffer, e.byteOffset, e.length >>> 2);
43
+ let t = new Int32Array(Math.ceil(e.length / 4) + 1);
44
+ return writeSeedWords(e, t), t;
45
+ }
46
+ function writeSeedWords(e, t, n = 0, r = 0, i = e.length) {
47
+ for (let a = r; a < i; a += 1) {
48
+ let r = n + a;
49
+ t[r >>> 2] = t[r >>> 2] | e[a] << (r & 3) * 8;
50
+ }
51
+ }
52
+ /*#__NO_SIDE_EFFECTS__*/
53
+ function chain(e, t, n, r, i) {
54
+ let a = /* @__PURE__ */ new Int32Array(2);
55
+ c(e, t, n, r, a);
56
+ for (let e = 1; e < i; e += 1) c(a[0], a[1], n, r, a);
57
+ return a;
58
+ }
59
+ /*#__NO_SIDE_EFFECTS__*/
60
+ function derivedKeys(e, t) {
61
+ let n = /* @__PURE__ */ seedWords(e);
62
+ return /* @__PURE__ */ roundKeys(/* @__PURE__ */ chain(y, _, n, e.length, t), /* @__PURE__ */ chain(y, v, n, e.length, t));
63
+ }
64
+ /*#__NO_SIDE_EFFECTS__*/
65
+ function roundKeys(e, t) {
66
+ let n = /* @__PURE__ */ new Int32Array(8), r = /* @__PURE__ */ new Int32Array(1), i = /* @__PURE__ */ new Int32Array(2), a = /* @__PURE__ */ new Int32Array(2);
67
+ for (let o = 0; o < 8; o += 2) r[0] = o, c(e[0], e[1], r, 4, i), c(t[0], t[1], r, 4, a), n[o] = i[0] ^ a[0], n[o + 1] = i[1] ^ a[1];
68
+ return n;
69
+ }
70
+ /*#__NO_SIDE_EFFECTS__*/
71
+ function feistelMask(e, t, n) {
72
+ return /* @__PURE__ */ maskFromKeys(e, /* @__PURE__ */ derivedKeys(t, n));
73
+ }
74
+ /*#__NO_SIDE_EFFECTS__*/
75
+ function maskFromKeys(e, t) {
76
+ return /* @__PURE__ */ s(e, (e, n, r) => {
77
+ o(e, 0, t, r, n, 0);
78
+ });
79
+ }
80
+ function deriveUuidV7Mask(e) {
10
81
  try {
11
- schema.mix(input, output, forward);
12
- return;
13
- } catch (cause) {
14
- return new UuidSlugError("invalid_mask_schema", `Mask schema "${schema.id}" failed ${forward ? "encoding" : "decoding"}.`, { cause });
82
+ let t = validateOptions(e, f);
83
+ if (!(d in t)) return t;
84
+ let n = seedBytes(t.seed);
85
+ return /* @__PURE__ */ invalidSeedLength(n.length) ?? /* @__PURE__ */ feistelMask(t.diagnosticLabel, n, t.iterations);
86
+ } catch (e) {
87
+ return new n(t, u, { cause: e });
15
88
  }
16
89
  }
17
- /**
18
- * The check must fail a wrong key with probability 2^-width, which holds only if the function
19
- * spreads its input across its whole output — so this is an avalanche mixer, not a sum. Measured
20
- * over 100,000 draws: uniform to chi-squared/df 0.999 across all 65,536 buckets of its top 16 bits.
21
- *
22
- * Taken from the TOP so that widening the check never renumbers the bits below it.
23
- */
24
- function tagFor(bytes, width) {
25
- let acc = 0;
26
- for (let offset = 0; offset < 16; offset += 4) acc = mix32(acc ^ read32(bytes, offset));
27
- return acc >>> 32 - width;
28
- }
29
- /**
30
- * The 12 check bits a UUIDv7 can hold inside the block, because it spends them on nothing: bits
31
- * 0-3 in byte 6's version nibble, 4-5 in byte 8's variant bits, 6-11 in byte 0's top six — the
32
- * high end of the 48-bit timestamp, zero for every instant before 2109. The rest of the check
33
- * rides outside the block, in whatever the encoding has spare.
34
- *
35
- * Claiming byte 0 is why encoding must REFUSE an instant at or past 2^42 ms rather than truncate.
36
- */
37
- function injectTag(bytes, tag) {
38
- bytes[6] = (tag & 15) << 4 | (bytes[6] ?? 0) & 15;
39
- bytes[8] = (tag & 48) << 2 | (bytes[8] ?? 0) & 63;
40
- bytes[0] = (tag >>> 6 & 63) << 2 | (bytes[0] ?? 0) & 3;
41
- }
42
- function extractTag(bytes) {
43
- return (bytes[6] ?? 0) >>> 4 | (bytes[8] ?? 0) >>> 6 << 4 | (bytes[0] ?? 0) >>> 2 << 6;
44
- }
45
- /** Puts back the constants the tag displaced, so the block equals the UUID the caller handed in. */
46
- function restoreV7(bytes) {
47
- bytes[6] = (bytes[6] ?? 0) & 15 | 112;
48
- bytes[8] = (bytes[8] ?? 0) & 63 | 128;
49
- bytes[0] = (bytes[0] ?? 0) & 3;
50
- }
51
- /** The 12 check bits that fit inside the block; the rest ride in the encoding's spare bits. */
52
- const INNER_TAG_BITS = 12;
53
- /**
54
- * A masked slug is always 22 base64url characters (Art's ruling, 2026-08-12), so the outer half of
55
- * the check is a constant 4 bits. Derived rather than written as `4` because the derivation IS the
56
- * rule — the check is whatever the encoding has left over, never a number somebody chose.
57
- */
58
- const OUTER_TAG_BITS = spareBits(BASE64URL, 16);
59
- const TAG_BITS = INNER_TAG_BITS + OUTER_TAG_BITS;
60
- function uuidV7BytesToMaskedSlug(raw, schema) {
61
- if ((raw[0] ?? 0) > 3) return new UuidSlugError("invalid_timestamp", "Masking requires a UUIDv7 timestamped before 2^42 ms (year 2109); its top six bits carry the check.");
62
- const tag = tagFor(raw, TAG_BITS);
63
- const tagged = new Uint8Array(raw);
64
- injectTag(tagged, tag >>> OUTER_TAG_BITS);
65
- const mixed = /* @__PURE__ */ new Uint8Array(16);
66
- const failed = applyMix(schema, tagged, mixed, true);
67
- if (failed) return failed;
68
- return encode(mixed, BASE64URL, tag & (1 << OUTER_TAG_BITS) - 1, OUTER_TAG_BITS);
69
- }
70
- function decodeMaskedSlug(slug, schema, previous = []) {
71
- const mixed = /* @__PURE__ */ new Uint8Array(16);
72
- const outerTag = decodeInto(slug, BASE64URL, mixed, 0, 16, OUTER_TAG_BITS);
73
- if (outerTag instanceof Error) return outerTag;
74
- const primary = unmix(previous.length ? mixed.slice() : mixed, outerTag, schema);
75
- if (primary && !(primary instanceof Error)) return primary;
76
- for (const older of previous) {
77
- const decoded = unmix(mixed.slice(), outerTag, older);
78
- if (decoded && !(decoded instanceof Error)) return decoded;
90
+ /*#__NO_SIDE_EFFECTS__*/
91
+ function invalidSeedLength(e) {
92
+ if (e < 16) return new n(t, `Mask seed must be at least 16 bytes, got ${e}. Generate one with \`openssl rand -base64 32\` rather than choosing it; a guessable seed hides nothing however long it is.`);
93
+ }
94
+ function validatedIterations(e) {
95
+ return typeof e != "number" || !Number.isInteger(e) || e < 1 || e > m ? new n(t, `Mask keyDerivationIterations must be a whole number in 1..${m}, got ${String(e)}.`) : e;
96
+ }
97
+ const b = 4096, x = globalThis, S = x.setImmediate?.bind(x);
98
+ function yieldToHost() {
99
+ return S ? new Promise((e) => S(e)) : new Promise((e) => {
100
+ let t = new MessageChannel();
101
+ t.port1.onmessage = () => {
102
+ t.port1.close(), t.port2.close(), e();
103
+ }, t.port2.postMessage(null);
104
+ });
105
+ }
106
+ function* cooperativeChain(e, t, n, r, i) {
107
+ let a = /* @__PURE__ */ new Int32Array(2);
108
+ a[0] = e, a[1] = t;
109
+ let o = Math.max(1, Math.floor(b / (r + 4))), s = 0;
110
+ for (let e = 0; e < i; e += 1) {
111
+ let e;
112
+ do
113
+ e = c(a[0], a[1], n, r, a, e, b / 4), e && (yield);
114
+ while (e);
115
+ s += 1, s >= o && (s = 0, yield);
79
116
  }
80
- return primary ?? new UuidSlugError("invalid_uuid_slug", "Masked UUID slug failed schema validation.");
81
- }
82
- /** Append distinct UUIDs directly to the result, before another callback can mutate their bytes. */
83
- function decodeMaskedCandidates(mixed, outerTag, schemas, firstOnly = false, candidates = []) {
84
- for (const schema of schemas) {
85
- const decoded = unmix(mixed.slice(), outerTag, schema);
86
- if (decoded instanceof Error) return decoded;
87
- if (decoded) {
88
- const uuid = formatUuid(decoded);
89
- if (uuid instanceof Error) return uuid;
90
- if (!candidates.includes(uuid)) candidates.push(uuid);
91
- if (firstOnly) break;
117
+ return a;
118
+ }
119
+ function* cooperativeKeys(e, t) {
120
+ let n = [], r = 0;
121
+ if (typeof e == "string") for (let t = 0; t < e.length;) {
122
+ let i = Math.min(e.length, t + b), a = e.charCodeAt(i - 1), o = e.charCodeAt(i);
123
+ i < e.length && a >= 55296 && a <= 56319 && o >= 56320 && o <= 57343 && --i;
124
+ let s = l(e.slice(t, i));
125
+ n.push(s), r += s.length, t = i, yield;
126
+ }
127
+ else n.push(e), r = e.length;
128
+ let i = /* @__PURE__ */ invalidSeedLength(r);
129
+ if (i) return i;
130
+ let a = typeof e != "string" && e.length >= g && /* @__PURE__ */ canViewSeedWords(e), o = a ? new Int32Array(e.buffer, e.byteOffset, e.length >>> 2) : new Int32Array(Math.ceil(r / 4) + 1);
131
+ if (!a) {
132
+ let e = 0;
133
+ for (let t of n) {
134
+ for (let n = 0; n < t.length; n += b) writeSeedWords(t, o, e, n, Math.min(t.length, n + b)), yield;
135
+ e += t.length;
92
136
  }
93
137
  }
94
- return candidates;
138
+ return n.length = 0, /* @__PURE__ */ roundKeys(yield* cooperativeChain(y, _, o, r, t), yield* cooperativeChain(y, v, o, r, t));
95
139
  }
96
- function unmix(mixed, outerTag, schema) {
97
- const unmixed = /* @__PURE__ */ new Uint8Array(16);
98
- const failed = applyMix(schema, mixed, unmixed, false);
99
- if (failed) return failed;
100
- const foundTag = extractTag(unmixed) << OUTER_TAG_BITS | outerTag;
101
- restoreV7(unmixed);
102
- if (tagFor(unmixed, TAG_BITS) !== foundTag) return void 0;
103
- return unmixed;
140
+ async function deriveUuidV7MaskAsync(r) {
141
+ try {
142
+ let t = r?.signal, aborted = () => new n(e, "Mask construction was aborted.", { cause: t?.reason });
143
+ if (t?.aborted) return aborted();
144
+ let i = validateOptions(r, p);
145
+ if (!(d in i)) return i;
146
+ let a = cooperativeKeys(typeof i.seed == "string" ? i.seed : new Uint8Array(i.seed), i.iterations), o = performance.now() + 2;
147
+ for (;;) {
148
+ if (t?.aborted) {
149
+ let e = aborted();
150
+ return a.return(e), e;
151
+ }
152
+ let e = a.next();
153
+ if (e.done) return ArrayBuffer.isView(e.value) ? /* @__PURE__ */ maskFromKeys(i.diagnosticLabel, e.value) : e.value;
154
+ performance.now() >= o && (await yieldToHost(), o = performance.now() + 2);
155
+ }
156
+ } catch (e) {
157
+ return new n(t, u, { cause: e });
158
+ }
104
159
  }
160
+ const C = /*#__PURE__*/ feistelMask("default", /*#__PURE__*/ seedBytes("anizoptera.uuid-slug.default-mask.v1"), 1);
105
161
  //#endregion
106
- export { decodeMaskedCandidates, decodeMaskedSlug, uuidV7BytesToMaskedSlug };
162
+ export { C as UUID_V7_TEST_MASK, deriveUuidV7Mask, deriveUuidV7MaskAsync };
107
163
 
108
164
  //# sourceMappingURL=mask.js.map
package/dist/mask.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mask.js","names":[],"sources":["../src/mask.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport { BASE64URL, decodeInto, encode, spareBits } from \"./alphabet\";\nimport { UuidSlugError } from \"./errors\";\nimport { mix32, read32 } from \"./feistel\";\nimport { formatUuid } from \"./uuid\";\nimport type { MaskSchema, MaskedUuidV7Slug, UuidString } from \"./types\";\n\n/** Custom callbacks can fail after construction; preserve their cause in the public error contract. */\nfunction applyMix(\n schema: MaskSchema,\n input: Uint8Array,\n output: Uint8Array,\n forward: boolean,\n): UuidSlugError | undefined {\n try {\n schema.mix(input, output, forward);\n return undefined;\n } catch (cause) {\n return new UuidSlugError(\n \"invalid_mask_schema\",\n `Mask schema \"${schema.id}\" failed ${forward ? \"encoding\" : \"decoding\"}.`,\n { cause },\n );\n }\n}\n\n/**\n * The check must fail a wrong key with probability 2^-width, which holds only if the function\n * spreads its input across its whole output — so this is an avalanche mixer, not a sum. Measured\n * over 100,000 draws: uniform to chi-squared/df 0.999 across all 65,536 buckets of its top 16 bits.\n *\n * Taken from the TOP so that widening the check never renumbers the bits below it.\n */\nfunction tagFor(bytes: Uint8Array, width: number) {\n let acc = 0;\n for (let offset = 0; offset < 16; offset += 4) acc = mix32(acc ^ read32(bytes, offset));\n return acc >>> (32 - width);\n}\n\n/**\n * The 12 check bits a UUIDv7 can hold inside the block, because it spends them on nothing: bits\n * 0-3 in byte 6's version nibble, 4-5 in byte 8's variant bits, 6-11 in byte 0's top six — the\n * high end of the 48-bit timestamp, zero for every instant before 2109. The rest of the check\n * rides outside the block, in whatever the encoding has spare.\n *\n * Claiming byte 0 is why encoding must REFUSE an instant at or past 2^42 ms rather than truncate.\n */\nfunction injectTag(bytes: Uint8Array, tag: number) {\n bytes[6] = ((tag & 0x0f) << 4) | ((bytes[6] ?? 0) & 0x0f);\n bytes[8] = ((tag & 0x30) << 2) | ((bytes[8] ?? 0) & 0x3f);\n bytes[0] = (((tag >>> 6) & 0x3f) << 2) | ((bytes[0] ?? 0) & 0x03);\n}\n\nfunction extractTag(bytes: Uint8Array) {\n return ((bytes[6] ?? 0) >>> 4) | (((bytes[8] ?? 0) >>> 6) << 4) | (((bytes[0] ?? 0) >>> 2) << 6);\n}\n\n/** Puts back the constants the tag displaced, so the block equals the UUID the caller handed in. */\nfunction restoreV7(bytes: Uint8Array) {\n bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x70;\n bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80;\n bytes[0] = (bytes[0] ?? 0) & 0x03;\n}\n\n/** The 12 check bits that fit inside the block; the rest ride in the encoding's spare bits. */\nconst INNER_TAG_BITS = 12;\n\n/**\n * A masked slug is always 22 base64url characters (Art's ruling, 2026-08-12), so the outer half of\n * the check is a constant 4 bits. Derived rather than written as `4` because the derivation IS the\n * rule — the check is whatever the encoding has left over, never a number somebody chose.\n */\nconst OUTER_TAG_BITS = spareBits(BASE64URL, 16);\nconst TAG_BITS = INNER_TAG_BITS + OUTER_TAG_BITS;\n\nexport function uuidV7BytesToMaskedSlug(\n raw: Uint8Array,\n schema: MaskSchema,\n): UuidSlugError | MaskedUuidV7Slug {\n // Truncating instead would make encoding non-injective — two UUIDs would share one slug, and no\n // decoder could ever tell which was meant. Refusing is the only recoverable answer.\n if ((raw[0] ?? 0) > 0x03)\n return new UuidSlugError(\n \"invalid_timestamp\",\n \"Masking requires a UUIDv7 timestamped before 2^42 ms (year 2109); its top six bits carry the check.\",\n );\n const tag = tagFor(raw, TAG_BITS);\n const tagged = new Uint8Array(raw);\n injectTag(tagged, tag >>> OUTER_TAG_BITS);\n const mixed = new Uint8Array(16);\n const failed = applyMix(schema, tagged, mixed, true);\n if (failed) return failed;\n return encode(mixed, BASE64URL, tag & ((1 << OUTER_TAG_BITS) - 1), OUTER_TAG_BITS);\n}\n\nexport function decodeMaskedSlug(\n slug: string,\n schema: MaskSchema,\n previous: readonly MaskSchema[] = [],\n): UuidSlugError | Uint8Array {\n const mixed = new Uint8Array(16);\n const outerTag = decodeInto(slug, BASE64URL, mixed, 0, 16, OUTER_TAG_BITS);\n if (outerTag instanceof Error) return outerTag;\n // A callback may mutate or retain its input. Each attempted key must receive fresh original\n // ciphertext, as it would when decoding the text again; only the text validation is shared.\n const primary = unmix(previous.length ? mixed.slice() : mixed, outerTag, schema);\n if (primary && !(primary instanceof Error)) return primary;\n for (const older of previous) {\n const decoded = unmix(mixed.slice(), outerTag, older);\n if (decoded && !(decoded instanceof Error)) return decoded;\n }\n // A key mismatch is ordinary rotation control flow. Allocate its diagnostic only if no key\n // succeeds, while keeping the primary callback's error and cause when that was the failure.\n return (\n primary ?? new UuidSlugError(\"invalid_uuid_slug\", \"Masked UUID slug failed schema validation.\")\n );\n}\n\n/** Append distinct UUIDs directly to the result, before another callback can mutate their bytes. */\nexport function decodeMaskedCandidates(\n mixed: Uint8Array,\n outerTag: number,\n schemas: readonly MaskSchema[],\n firstOnly = false,\n candidates: UuidString[] = [],\n): UuidSlugError | UuidString[] {\n for (const schema of schemas) {\n // Custom callbacks may mutate their input; no key may alter what the next one sees.\n const decoded = unmix(mixed.slice(), outerTag, schema);\n // A failed callback means the candidate list is incomplete, not that its key mismatched.\n if (decoded instanceof Error) return decoded;\n if (decoded) {\n const uuid = formatUuid(decoded);\n if (uuid instanceof Error) return uuid;\n if (!candidates.includes(uuid)) candidates.push(uuid);\n if (firstOnly) break;\n }\n }\n return candidates;\n}\n\nfunction unmix(\n mixed: Uint8Array,\n outerTag: number,\n schema: MaskSchema,\n): UuidSlugError | Uint8Array | undefined {\n const unmixed = new Uint8Array(16);\n const failed = applyMix(schema, mixed, unmixed, false);\n if (failed) return failed;\n // Both halves come out of the same decryption, so a wrong key garbles the observed check as\n // thoroughly as the payload: the tag needs no key of its own to tell keys apart.\n const foundTag = (extractTag(unmixed) << OUTER_TAG_BITS) | outerTag;\n restoreV7(unmixed);\n if (tagFor(unmixed, TAG_BITS) !== foundTag) return undefined;\n return unmixed;\n}\n"],"mappings":";;;;;;;;AASA,SAAS,SACP,QACA,OACA,QACA,SAC2B;CAC3B,IAAI;EACF,OAAO,IAAI,OAAO,QAAQ,OAAO;EACjC;CACF,SAAS,OAAO;EACd,OAAO,IAAI,cACT,uBACA,gBAAgB,OAAO,GAAG,WAAW,UAAU,aAAa,WAAW,IACvE,EAAE,MAAM,CACV;CACF;AACF;;;;;;;;AASA,SAAS,OAAO,OAAmB,OAAe;CAChD,IAAI,MAAM;CACV,KAAK,IAAI,SAAS,GAAG,SAAS,IAAI,UAAU,GAAG,MAAM,MAAM,MAAM,OAAO,OAAO,MAAM,CAAC;CACtF,OAAO,QAAS,KAAK;AACvB;;;;;;;;;AAUA,SAAS,UAAU,OAAmB,KAAa;CACjD,MAAM,MAAO,MAAM,OAAS,KAAO,MAAM,MAAM,KAAK;CACpD,MAAM,MAAO,MAAM,OAAS,KAAO,MAAM,MAAM,KAAK;CACpD,MAAM,MAAQ,QAAQ,IAAK,OAAS,KAAO,MAAM,MAAM,KAAK;AAC9D;AAEA,SAAS,WAAW,OAAmB;CACrC,QAAS,MAAM,MAAM,OAAO,KAAQ,MAAM,MAAM,OAAO,KAAM,KAAQ,MAAM,MAAM,OAAO,KAAM;AAChG;;AAGA,SAAS,UAAU,OAAmB;CACpC,MAAM,MAAO,MAAM,MAAM,KAAK,KAAQ;CACtC,MAAM,MAAO,MAAM,MAAM,KAAK,KAAQ;CACtC,MAAM,MAAM,MAA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AAI,gBAAgB,OAAO,OAAO;GAClC,IAAI,CAAC,WAAW,SAAS,IAAI,GAAG,WAAW,KAAK,IAAI;GACpD,IAAI,WAAW;EACjB;CACF;CACA,OAAO;AACT;AAEA,SAAS,MACP,OACA,UACA,QACwC;CACxC,MAAM,0BAAU,IAAI,WAAW,EAAE;CACjC,MAAM,SAAS,SAAS,QAAQ,OAAO,SAAS,KAAK;CACrD,IAAI,QAAQ,OAAO;CAGnB,MAAM,WAAY,WAAW,OAAO,KAAK,iBAAkB;CAC3D,UAAU,OAAO;CACjB,IAAI,OAAO,SAAS,QAAQ,MAAM,UAAU,OAAO,KAAA;CACnD,OAAO;AACT"}
1
+ {"version":3,"file":"mask.js","names":["MASK_CONSTRUCTION_FAILURE_MESSAGE","SEED_PROPERTY","MASK_OPTIONS","ASYNC_MASK_OPTIONS","MAX_KEY_ITERATIONS","LITTLE_ENDIAN","SEED_WORD_VIEW_MIN_BYTES","seed","CHAIN_A_KEY1","CHAIN_B_KEY1","CHAIN_KEY0","encodeUtf8","options","UuidSlugError","INVALID_MASK","input","unknown","accepted","givenSeed","givenLabel","normalizedLabel","givenIterations","iterations","words","index","start","end","absolute","offset","out","key0","key1","length","i","keys","fromA","fromB","word","halfSipHash","chainA","chainB","diagnosticLabel","direction","output","validated","cause","CHUNK_BYTES","host","immediate","resolve","channel","hashesPerChunk","sinceCheckpoint","continuation","chunks","last","next","bytes","short","viewBytes","signal","ABORTED","steps","deadline","failure","step","UUID_V7_TEST_MASK"],"sources":["../src/mask.ts"],"mappings":";;;;;;;;AAiBA,MAAMA,IAAoC,6BACpCC,IAAgB,QAChBC,IAAe;CACnB,yBAAyB;CACzB,iBAAiB;EAChBD,IAAgB;AACnB,GACME,IAAqB;CACzB,GAAGD;CACH,QAAQ;AACV,GAMME,IAAqB,KAAK,IAG1BC,IAAgB,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,GACnEC,IAA2B;;AA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ClDA,EAAK;GACX,AAAI,YAAY,IAAI,KAAKF,MAEvB,MAAM,YAAY,GAClB,IAAW,YAAY,IAAI,IAAI;EAEnC;CACF,SAASlB,GAAO;EACd,OAAO,IAAIhC,EAAcC,GAAcd,GAAmC,EAAE,SAAM,CAAC;CACrF;AACF;AAUA,MAOakE,IAA8C,0BACzD,WACc,wBAAU,sCAAY,GACpC,CACF"}
@@ -0,0 +1,23 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // @anizoptera/uuid-slug 0.5.0 | https://github.com/Anizoptera/uuid-slug#readme
3
+ //#region src/masking-codec-protocol.ts
4
+ var ReturnCodec = class {
5
+ constructor(e) {
6
+ return e;
7
+ }
8
+ }, PackageMaskingCodec = class extends ReturnCodec {
9
+ #e = !0;
10
+ static is(e) {
11
+ return typeof e == "object" && !!e && #e in e && e.#e;
12
+ }
13
+ };
14
+ function registerMaskingCodec(e) {
15
+ return new PackageMaskingCodec(e);
16
+ }
17
+ function isLocalMaskingCodec(e) {
18
+ return PackageMaskingCodec.is(e);
19
+ }
20
+ //#endregion
21
+ export { isLocalMaskingCodec, registerMaskingCodec };
22
+
23
+ //# sourceMappingURL=masking-codec-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"masking-codec-protocol.js","names":["codec","#local"],"sources":["../src/masking-codec-protocol.ts"],"mappings":";;;AAQA,IAAM,cAAN,MAAkB;CAChB,YAAY,GAAe;EACzB,OAAOA;CACT;AACF,GAEM,sBAAN,cAAkC,YAAY;CAC5C,KAAkB;CAElB,OAAO,GAAG,GAAwB;EAChC,OAAO,OAAOA,KAAU,cAAYA,KAAkB,MAAUA,KAASA,EAAMC;CACjF;AACF;AAEA,SAAgB,qBAA2C,GAAqB;CAC9E,OAAO,IAAI,oBAAoBD,CAAK;AACtC;AAEA,SAAgB,oBAAoB,GAAwB;CAC1D,OAAO,oBAAoB,GAAGA,CAAK;AACrC"}