@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.
- package/LICENSE +54 -31
- package/README.md +373 -324
- package/dist/alphabet.d.ts +5 -17
- package/dist/alphabet.d.ts.map +1 -1
- package/dist/alphabet.js +146 -112
- package/dist/alphabet.js.map +1 -1
- package/dist/base64url-name.d.ts +7 -0
- package/dist/base64url-name.d.ts.map +1 -0
- package/dist/base64url-name.js +8 -0
- package/dist/base64url-name.js.map +1 -0
- package/dist/errors.d.ts +50 -9
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +145 -63
- package/dist/errors.js.map +1 -1
- package/dist/feistel.js +29 -95
- package/dist/feistel.js.map +1 -1
- package/dist/generation-options.js +20 -0
- package/dist/generation-options.js.map +1 -0
- package/dist/index.d.ts +22 -10
- package/dist/index.js +21 -9
- package/dist/instant.js +83 -0
- package/dist/instant.js.map +1 -0
- package/dist/mask-handle.d.ts +16 -0
- package/dist/mask-handle.d.ts.map +1 -0
- package/dist/mask-handle.js +60 -0
- package/dist/mask-handle.js.map +1 -0
- package/dist/mask.d.ts +27 -0
- package/dist/mask.d.ts.map +1 -0
- package/dist/mask.js +151 -95
- package/dist/mask.js.map +1 -1
- package/dist/masking-codec-protocol.js +23 -0
- package/dist/masking-codec-protocol.js.map +1 -0
- package/dist/masking-codec-types.d.ts +245 -0
- package/dist/masking-codec-types.d.ts.map +1 -0
- package/dist/masking-codec.d.ts +19 -0
- package/dist/masking-codec.d.ts.map +1 -0
- package/dist/masking-codec.js +391 -0
- package/dist/masking-codec.js.map +1 -0
- package/dist/migration.js +114 -51
- package/dist/migration.js.map +1 -1
- package/dist/node/runtime.js +39 -0
- package/dist/node/runtime.js.map +1 -0
- package/dist/payload.d.ts +7 -0
- package/dist/payload.d.ts.map +1 -0
- package/dist/payload.js +118 -0
- package/dist/payload.js.map +1 -0
- package/dist/runtime/pool.js +21 -46
- package/dist/runtime/pool.js.map +1 -1
- package/dist/runtime/portable.js +27 -0
- package/dist/runtime/portable.js.map +1 -0
- package/dist/sentinel.js +10 -0
- package/dist/sentinel.js.map +1 -0
- package/dist/siphash.js +20 -99
- package/dist/siphash.js.map +1 -1
- package/dist/slug.d.ts +169 -0
- package/dist/slug.d.ts.map +1 -0
- package/dist/slug.js +268 -0
- package/dist/slug.js.map +1 -0
- package/dist/timestamp.d.ts +19 -0
- package/dist/timestamp.d.ts.map +1 -0
- package/dist/timestamp.js +44 -0
- package/dist/timestamp.js.map +1 -0
- package/dist/types.d.ts +480 -200
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/uuid-value-protocol.js +46 -0
- package/dist/uuid-value-protocol.js.map +1 -0
- package/dist/uuid-value.d.ts +17 -0
- package/dist/uuid-value.d.ts.map +1 -0
- package/dist/uuid-value.js +127 -0
- package/dist/uuid-value.js.map +1 -0
- package/dist/uuid.d.ts +51 -64
- package/dist/uuid.d.ts.map +1 -1
- package/dist/uuid.js +203 -199
- package/dist/uuid.js.map +1 -1
- package/dist/v4-slug.d.ts +16 -0
- package/dist/v4-slug.d.ts.map +1 -0
- package/dist/v4-slug.js +16 -0
- package/dist/v4-slug.js.map +1 -0
- package/dist/v4.d.ts +42 -0
- package/dist/v4.d.ts.map +1 -0
- package/dist/v4.js +85 -0
- package/dist/v4.js.map +1 -0
- package/dist/v7-bounds.d.ts +36 -0
- package/dist/v7-bounds.d.ts.map +1 -0
- package/dist/v7-bounds.js +49 -0
- package/dist/v7-bounds.js.map +1 -0
- package/dist/v7-generator-input.js +75 -0
- package/dist/v7-generator-input.js.map +1 -0
- package/dist/v7-generator.d.ts +43 -0
- package/dist/v7-generator.d.ts.map +1 -0
- package/dist/v7-generator.js +105 -0
- package/dist/v7-generator.js.map +1 -0
- package/dist/v7-keyless.d.ts +46 -0
- package/dist/v7-keyless.d.ts.map +1 -0
- package/dist/v7-keyless.js +106 -0
- package/dist/v7-keyless.js.map +1 -0
- package/dist/v7-payload.js +54 -0
- package/dist/v7-payload.js.map +1 -0
- package/dist/v7-slug.d.ts +46 -0
- package/dist/v7-slug.d.ts.map +1 -0
- package/dist/v7-slug.js +127 -0
- package/dist/v7-slug.js.map +1 -0
- package/dist/v7-timestamp.js +9 -0
- package/dist/v7-timestamp.js.map +1 -0
- package/dist/v7-value-options.js +28 -0
- package/dist/v7-value-options.js.map +1 -0
- package/dist/v7-value.d.ts +23 -0
- package/dist/v7-value.d.ts.map +1 -0
- package/dist/v7-value.js +31 -0
- package/dist/v7-value.js.map +1 -0
- package/dist/v7.js +127 -171
- package/dist/v7.js.map +1 -1
- package/package.json +15 -8
- package/src/alphabet.ts +456 -27
- package/src/base64url-name.ts +5 -0
- package/src/errors.ts +373 -37
- package/src/feistel.ts +69 -56
- package/src/generation-options.ts +48 -0
- package/src/index.ts +134 -80
- package/src/instant.ts +196 -0
- package/src/keyless.ts +7 -134
- package/src/mask-handle.ts +141 -0
- package/src/mask.ts +354 -129
- package/src/masking-codec-protocol.ts +29 -0
- package/src/masking-codec-types.ts +380 -0
- package/src/masking-codec.ts +923 -0
- package/src/migration.ts +195 -42
- package/src/payload.ts +321 -0
- package/src/runtime/bun.ts +30 -49
- package/src/runtime/node.ts +43 -24
- package/src/runtime/pool.ts +49 -21
- package/src/runtime/portable.ts +68 -0
- package/src/runtime/types.ts +23 -35
- package/src/sentinel.ts +13 -0
- package/src/siphash.ts +5 -4
- package/src/slug.ts +884 -0
- package/src/timestamp.ts +122 -0
- package/src/types.ts +759 -205
- package/src/uuid-value-protocol.ts +77 -0
- package/src/uuid-value.ts +341 -0
- package/src/uuid.ts +514 -234
- package/src/v4-slug.ts +27 -0
- package/src/v4.ts +234 -0
- package/src/v7-bounds.ts +171 -0
- package/src/v7-generator-input.ts +169 -0
- package/src/v7-generator.ts +245 -0
- package/src/v7-keyless.ts +354 -0
- package/src/v7-payload.ts +121 -0
- package/src/v7-slug.ts +293 -0
- package/src/v7-timestamp.ts +21 -0
- package/src/v7-value-options.ts +62 -0
- package/src/v7-value.ts +54 -0
- package/src/v7.ts +377 -200
- package/dist/base64url.d.ts +0 -20
- package/dist/base64url.d.ts.map +0 -1
- package/dist/base64url.js +0 -33
- package/dist/base64url.js.map +0 -1
- package/dist/codec.d.ts +0 -17
- package/dist/codec.d.ts.map +0 -1
- package/dist/codec.js +0 -192
- package/dist/codec.js.map +0 -1
- package/dist/keyless.d.ts +0 -31
- package/dist/keyless.d.ts.map +0 -1
- package/dist/keyless.js +0 -93
- package/dist/keyless.js.map +0 -1
- package/dist/legacy-mask.js +0 -55
- package/dist/legacy-mask.js.map +0 -1
- package/dist/node/alphabet.js +0 -130
- package/dist/node/base64url.js +0 -31
- package/dist/node/codec.js +0 -190
- package/dist/node/errors.js +0 -78
- package/dist/node/feistel.js +0 -103
- package/dist/node/index.js +0 -10
- package/dist/node/keyless.js +0 -91
- package/dist/node/legacy-mask.js +0 -53
- package/dist/node/mask.js +0 -106
- package/dist/node/migration.js +0 -64
- package/dist/node/runtime/node.js +0 -33
- package/dist/node/runtime/pool.js +0 -53
- package/dist/node/schema.js +0 -214
- package/dist/node/siphash.js +0 -106
- package/dist/node/uuid.js +0 -226
- package/dist/node/v7.js +0 -185
- package/dist/node/yield.js +0 -20
- package/dist/runtime/web.js +0 -39
- package/dist/runtime/web.js.map +0 -1
- package/dist/schema.d.ts +0 -20
- package/dist/schema.d.ts.map +0 -1
- package/dist/schema.js +0 -216
- package/dist/schema.js.map +0 -1
- package/dist/v7.d.ts +0 -12
- package/dist/v7.d.ts.map +0 -1
- package/dist/yield.js +0 -22
- package/dist/yield.js.map +0 -1
- package/src/base64url.ts +0 -41
- package/src/codec.ts +0 -320
- package/src/legacy-mask.ts +0 -25
- package/src/runtime/web.ts +0 -48
- package/src/schema.ts +0 -300
- package/src/yield.ts +0 -22
package/dist/instant.js
ADDED
|
@@ -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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;AACjC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// @anizoptera/uuid-slug 0.5.0 | https://github.com/Anizoptera/uuid-slug#readme
|
|
3
|
+
import { UuidSlugError } from "./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,GAA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B,OAAO,IAAIT,EAAcC,GAAcT,GAA6B,EAClE,OAAOiB,EACT,CAAC;GACH,IAAMC,IAAW,UAAUJ,GAAQG,CAAK;GACxC,IAAI,kBAAgBC,CAAQ,GAC1B,OAAO,IAAIV,EAAcC,GAAcT,GAA6B,EAClE,OAAOkB,EACT,CAAC;GACH,IAAIA,EAAS,MAAM,GAAM,MAAUC,MAASJ,EAAMC,EAAM,GACtD,OAAO,IAAIR,EACTC,GACA,gBAAgBI,EAAgB,yCAClC;EACJ;EACA,OAAO,iCAAiBA,IAAkB,GAAO,GAAQ,MAAc;GACrE,IAAMI,IAAQ,UAAUV,MAAcN,IAAiBE,IAAOW,GAAQT,CAAK;GAC3E,IAAI,kBAAgBY,CAAK,GAAG,OAAOA;GACnC,EAAO,IAAIA,CAAK;EAElB,CAAC;CACH,SAASG,GAAO;EACd,OAAO,IAAIZ,EAAcC,GAAcT,GAA6B,EAClE,SACF,CAAC;CACH;AACF"}
|
package/dist/mask.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// @anizoptera/uuid-slug 0.5.0 | https://github.com/Anizoptera/uuid-slug#readme
|
|
3
|
+
import { UuidSlugError } 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
|
-
import { UuidSlugError } from "./errors.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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
|
-
|
|
9
|
-
|
|
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
|
-
|
|
12
|
-
return;
|
|
13
|
-
|
|
14
|
-
return
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
for (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
138
|
+
return n.length = 0, /* @__PURE__ */ roundKeys(yield* cooperativeChain(y, _, o, r, t), yield* cooperativeChain(y, v, o, r, t));
|
|
95
139
|
}
|
|
96
|
-
function
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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 {
|
|
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":[
|
|
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,iBA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nB,IAAMI,IAAU,QAAQ;IAExB,OADAF,EAAM,OAAOE,CAAO,GACbA;GACT;GACA,IAAMC,IAAOH,EAAM,KAAK;GACxB,IAAIG,EAAK,MACP,OAAO,YAAY,OAAOA,EAAK,KAAK,IAChC,6BAAarB,EAAU,iBAAiBqB,EAAK,KAAK,IAClDA,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"}
|