anonyma 1.1.0 → 1.2.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/CHANGELOG.md +131 -2
- package/README.md +125 -7
- package/dist/ai/index.cjs +31 -20
- package/dist/ai/index.cjs.map +1 -1
- package/dist/ai/index.d.cts +5 -5
- package/dist/ai/index.d.ts +5 -5
- package/dist/ai/index.js +24 -13
- package/dist/ai/index.js.map +1 -1
- package/dist/audit/index.cjs +14 -14
- package/dist/audit/index.d.cts +2 -2
- package/dist/audit/index.d.ts +2 -2
- package/dist/audit/index.js +9 -9
- package/dist/{chunk-YMLR375Z.js → chunk-264R3VFP.js} +4 -3
- package/dist/chunk-264R3VFP.js.map +1 -0
- package/dist/{chunk-ISL5B4LU.cjs → chunk-32U3DM7M.cjs} +11 -11
- package/dist/{chunk-ISL5B4LU.cjs.map → chunk-32U3DM7M.cjs.map} +1 -1
- package/dist/{chunk-26IHMQHL.cjs → chunk-42ZZZUMO.cjs} +245 -85
- package/dist/chunk-42ZZZUMO.cjs.map +1 -0
- package/dist/chunk-4BYN6GVK.js +213 -0
- package/dist/chunk-4BYN6GVK.js.map +1 -0
- package/dist/{chunk-JKW36IPT.js → chunk-A2OMTO3L.js} +4 -4
- package/dist/{chunk-JKW36IPT.js.map → chunk-A2OMTO3L.js.map} +1 -1
- package/dist/{chunk-TW7PM3UJ.cjs → chunk-AITKBKQX.cjs} +2 -2
- package/dist/{chunk-TW7PM3UJ.cjs.map → chunk-AITKBKQX.cjs.map} +1 -1
- package/dist/{chunk-G4AN7FND.js → chunk-BWE4O2ES.js} +23 -9
- package/dist/chunk-BWE4O2ES.js.map +1 -0
- package/dist/{chunk-GS3FRH4K.js → chunk-CMJXIEBA.js} +2 -2
- package/dist/chunk-CMJXIEBA.js.map +1 -0
- package/dist/{chunk-GYMG5OI3.cjs → chunk-ESVFPMG4.cjs} +2 -2
- package/dist/{chunk-GYMG5OI3.cjs.map → chunk-ESVFPMG4.cjs.map} +1 -1
- package/dist/{chunk-2YG7R4KJ.cjs → chunk-EUNLKSYP.cjs} +5 -5
- package/dist/{chunk-2YG7R4KJ.cjs.map → chunk-EUNLKSYP.cjs.map} +1 -1
- package/dist/{chunk-S7NH6CHY.cjs → chunk-F3BYJFUM.cjs} +5 -3
- package/dist/chunk-F3BYJFUM.cjs.map +1 -0
- package/dist/{chunk-IJAMLYOT.cjs → chunk-HDHQXVUM.cjs} +50 -36
- package/dist/chunk-HDHQXVUM.cjs.map +1 -0
- package/dist/{chunk-OGNLB2KA.js → chunk-HFAIBE3T.js} +3 -3
- package/dist/{chunk-OGNLB2KA.js.map → chunk-HFAIBE3T.js.map} +1 -1
- package/dist/{chunk-PKHZ7CVI.js → chunk-IBDFBUFZ.js} +2 -2
- package/dist/chunk-IBDFBUFZ.js.map +1 -0
- package/dist/{chunk-3CY6ATKS.cjs → chunk-JBH2EFFF.cjs} +36 -36
- package/dist/{chunk-3CY6ATKS.cjs.map → chunk-JBH2EFFF.cjs.map} +1 -1
- package/dist/chunk-JPU7KQZX.cjs +82 -0
- package/dist/{chunk-CRXRJZEV.cjs.map → chunk-JPU7KQZX.cjs.map} +1 -1
- package/dist/{chunk-E3PICZYI.js → chunk-KHT23UVV.js} +3 -3
- package/dist/{chunk-E3PICZYI.js.map → chunk-KHT23UVV.js.map} +1 -1
- package/dist/{chunk-2ZZHLCEJ.js → chunk-LAZIR73I.js} +18 -87
- package/dist/chunk-LAZIR73I.js.map +1 -0
- package/dist/{chunk-FB56NAAH.cjs → chunk-NO4ZCIM6.cjs} +19 -92
- package/dist/chunk-NO4ZCIM6.cjs.map +1 -0
- package/dist/{chunk-S4BJ2ADB.cjs → chunk-PCU6AG7H.cjs} +4 -4
- package/dist/{chunk-S4BJ2ADB.cjs.map → chunk-PCU6AG7H.cjs.map} +1 -1
- package/dist/{chunk-W6RBCHYF.js → chunk-PSZHBY5V.js} +235 -75
- package/dist/chunk-PSZHBY5V.js.map +1 -0
- package/dist/{chunk-6LDAIJBL.js → chunk-QBBJR7DZ.js} +2 -2
- package/dist/{chunk-6LDAIJBL.js.map → chunk-QBBJR7DZ.js.map} +1 -1
- package/dist/{chunk-3D5ZCJ7R.js → chunk-QHQ2AU45.js} +3 -3
- package/dist/{chunk-3D5ZCJ7R.js.map → chunk-QHQ2AU45.js.map} +1 -1
- package/dist/{chunk-IHEIYZPL.cjs → chunk-RJX27YEX.cjs} +2 -2
- package/dist/chunk-RJX27YEX.cjs.map +1 -0
- package/dist/{chunk-QYD4F6T7.cjs → chunk-ROXNQKOA.cjs} +2 -2
- package/dist/{chunk-QYD4F6T7.cjs.map → chunk-ROXNQKOA.cjs.map} +1 -1
- package/dist/chunk-SHEXFU6T.js +107 -0
- package/dist/chunk-SHEXFU6T.js.map +1 -0
- package/dist/chunk-T2KIN6VL.cjs +218 -0
- package/dist/chunk-T2KIN6VL.cjs.map +1 -0
- package/dist/{chunk-RCW5IPPR.js → chunk-UCT6HDUD.js} +3 -3
- package/dist/{chunk-RCW5IPPR.js.map → chunk-UCT6HDUD.js.map} +1 -1
- package/dist/chunk-UN74SYHV.cjs +115 -0
- package/dist/chunk-UN74SYHV.cjs.map +1 -0
- package/dist/{chunk-F7O2FA3F.cjs → chunk-VAO3Y3HZ.cjs} +7 -6
- package/dist/chunk-VAO3Y3HZ.cjs.map +1 -0
- package/dist/{chunk-BBJPQPGP.js → chunk-VE3OSDM7.js} +5 -3
- package/dist/chunk-VE3OSDM7.js.map +1 -0
- package/dist/{chunk-7HK2V5Q4.js → chunk-X7IVXKDE.js} +3 -3
- package/dist/{chunk-7HK2V5Q4.js.map → chunk-X7IVXKDE.js.map} +1 -1
- package/dist/{chunk-UA3EOFBS.cjs → chunk-XVCVIUZS.cjs} +8 -8
- package/dist/{chunk-UA3EOFBS.cjs.map → chunk-XVCVIUZS.cjs.map} +1 -1
- package/dist/{chunk-SIHPDZXA.js → chunk-YSTC7WRF.js} +2 -2
- package/dist/{chunk-SIHPDZXA.js.map → chunk-YSTC7WRF.js.map} +1 -1
- package/dist/compliance/index.cjs +15 -15
- package/dist/compliance/index.d.cts +4 -4
- package/dist/compliance/index.d.ts +4 -4
- package/dist/compliance/index.js +5 -5
- package/dist/crypto.cjs +4 -4
- package/dist/crypto.d.cts +1 -1
- package/dist/crypto.d.ts +1 -1
- package/dist/crypto.js +2 -2
- package/dist/detectors/index.cjs +38 -38
- package/dist/detectors/index.d.cts +1 -1
- package/dist/detectors/index.d.ts +1 -1
- package/dist/detectors/index.js +3 -3
- package/dist/engine/index.cjs +70 -70
- package/dist/engine/index.d.cts +3 -3
- package/dist/engine/index.d.ts +3 -3
- package/dist/engine/index.js +8 -8
- package/dist/hash-P2VGKVFP.cjs +14 -0
- package/dist/{hash-2PSYNDMM.cjs.map → hash-P2VGKVFP.cjs.map} +1 -1
- package/dist/hash-T6YJG3DU.js +5 -0
- package/dist/{hash-CELLDNKN.js.map → hash-T6YJG3DU.js.map} +1 -1
- package/dist/index.cjs +44 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -5
- package/dist/index.d.ts +23 -5
- package/dist/index.js +11 -9
- package/dist/index.js.map +1 -1
- package/dist/{json-s8ny-RCo.d.cts → json-BXN577tt.d.cts} +3 -2
- package/dist/{json-CKDvlRtl.d.ts → json-BudrzkOQ.d.ts} +3 -2
- package/dist/mcp/index.cjs +29 -28
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.js +14 -13
- package/dist/mcp/index.js.map +1 -1
- package/dist/middleware/express.cjs +11 -11
- package/dist/middleware/express.d.cts +3 -3
- package/dist/middleware/express.d.ts +3 -3
- package/dist/middleware/express.js +10 -10
- package/dist/middleware/hono.cjs +11 -11
- package/dist/middleware/hono.d.cts +3 -3
- package/dist/middleware/hono.d.ts +3 -3
- package/dist/middleware/hono.js +10 -10
- package/dist/middleware/index.cjs +11 -11
- package/dist/middleware/index.d.cts +3 -3
- package/dist/middleware/index.d.ts +3 -3
- package/dist/middleware/index.js +10 -10
- package/dist/schemas.cjs +47 -47
- package/dist/schemas.cjs.map +1 -1
- package/dist/schemas.d.cts +2 -2
- package/dist/schemas.d.ts +2 -2
- package/dist/schemas.js +2 -2
- package/dist/schemas.js.map +1 -1
- package/dist/{session-BdRftyZ5.d.cts → session-CPXEQ2uC.d.cts} +18 -5
- package/dist/{session-Cs2zlNQp.d.ts → session-D3WMN6fE.d.ts} +18 -5
- package/dist/stream.cjs +10 -8
- package/dist/stream.cjs.map +1 -1
- package/dist/stream.d.cts +1 -1
- package/dist/stream.d.ts +1 -1
- package/dist/stream.js +7 -5
- package/dist/stream.js.map +1 -1
- package/dist/{types-Dtht33aq.d.ts → types-B3VjDuP8.d.cts} +2 -282
- package/dist/{types--tPm_AjY.d.ts → types-DHAVKfzT.d.ts} +2 -2
- package/dist/types-LZHFEgx5.d.cts +1083 -0
- package/dist/types-LZHFEgx5.d.ts +1083 -0
- package/dist/{types-0BJH_wqc.d.cts → types-vmONSbz4.d.cts} +2 -2
- package/dist/{types-CPUhjvl8.d.cts → types-yZHnS7yv.d.ts} +2 -282
- package/dist/validators.cjs +10 -10
- package/dist/validators.js +1 -1
- package/dist/vault/index.cjs +65 -46
- package/dist/vault/index.cjs.map +1 -1
- package/dist/vault/index.d.cts +98 -5
- package/dist/vault/index.d.ts +98 -5
- package/dist/vault/index.js +11 -5
- package/dist/vault/index.js.map +1 -1
- package/package.json +16 -7
- package/dist/chunk-26IHMQHL.cjs.map +0 -1
- package/dist/chunk-2ZZHLCEJ.js.map +0 -1
- package/dist/chunk-BBJPQPGP.js.map +0 -1
- package/dist/chunk-CRXRJZEV.cjs +0 -82
- package/dist/chunk-F7O2FA3F.cjs.map +0 -1
- package/dist/chunk-FB56NAAH.cjs.map +0 -1
- package/dist/chunk-G4AN7FND.js.map +0 -1
- package/dist/chunk-GS3FRH4K.js.map +0 -1
- package/dist/chunk-IHEIYZPL.cjs.map +0 -1
- package/dist/chunk-IJAMLYOT.cjs.map +0 -1
- package/dist/chunk-PKHZ7CVI.js.map +0 -1
- package/dist/chunk-S7NH6CHY.cjs.map +0 -1
- package/dist/chunk-W6RBCHYF.js.map +0 -1
- package/dist/chunk-YMLR375Z.js.map +0 -1
- package/dist/hash-2PSYNDMM.cjs +0 -14
- package/dist/hash-CELLDNKN.js +0 -5
- package/dist/types-EJTj_BKY.d.cts +0 -584
- package/dist/types-EJTj_BKY.d.ts +0 -584
package/dist/vault/index.cjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunk2NNMJ55L_cjs = require('../chunk-2NNMJ55L.cjs');
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
4
|
+
var chunkROXNQKOA_cjs = require('../chunk-ROXNQKOA.cjs');
|
|
5
|
+
var chunkNO4ZCIM6_cjs = require('../chunk-NO4ZCIM6.cjs');
|
|
6
|
+
var chunkT2KIN6VL_cjs = require('../chunk-T2KIN6VL.cjs');
|
|
7
|
+
var chunkUN74SYHV_cjs = require('../chunk-UN74SYHV.cjs');
|
|
8
|
+
var chunkAITKBKQX_cjs = require('../chunk-AITKBKQX.cjs');
|
|
7
9
|
var chunkWLJN7GIS_cjs = require('../chunk-WLJN7GIS.cjs');
|
|
8
10
|
|
|
9
11
|
// src/vault/keyring.ts
|
|
@@ -29,7 +31,7 @@ async function importBase(crypto, id, material, salt, iterations) {
|
|
|
29
31
|
}
|
|
30
32
|
const passphraseKey = await crypto.subtle.importKey(
|
|
31
33
|
"raw",
|
|
32
|
-
|
|
34
|
+
chunkROXNQKOA_cjs.utf8(material.passphrase),
|
|
33
35
|
"PBKDF2",
|
|
34
36
|
false,
|
|
35
37
|
["deriveBits"]
|
|
@@ -39,6 +41,7 @@ async function importBase(crypto, id, material, salt, iterations) {
|
|
|
39
41
|
name: "PBKDF2",
|
|
40
42
|
hash: "SHA-256",
|
|
41
43
|
salt,
|
|
44
|
+
/* v8 ignore next -- resolveIterations() gives every passphrase a count */
|
|
42
45
|
iterations: iterations ?? DEFAULT_PBKDF2_ITERATIONS
|
|
43
46
|
},
|
|
44
47
|
passphraseKey,
|
|
@@ -66,22 +69,22 @@ function resolveIterations(id, material, fromManifest) {
|
|
|
66
69
|
return iterations;
|
|
67
70
|
}
|
|
68
71
|
async function generateKeyMaterial() {
|
|
69
|
-
return { kind: "raw", bytes:
|
|
72
|
+
return { kind: "raw", bytes: chunkROXNQKOA_cjs.randomBytes(await chunkAITKBKQX_cjs.webCrypto(), MIN_RAW_BYTES) };
|
|
70
73
|
}
|
|
71
74
|
async function createKeyRing(options) {
|
|
72
75
|
const { namespace, keys, manifest } = options;
|
|
73
76
|
const now = options.now ?? Date.now;
|
|
74
|
-
if (typeof namespace !== "string" || namespace.length === 0 || !
|
|
77
|
+
if (typeof namespace !== "string" || namespace.length === 0 || !chunkROXNQKOA_cjs.isWellFormed(namespace)) {
|
|
75
78
|
throw new chunkWLJN7GIS_cjs.KeyManagementError("the namespace must be a non-empty, well-formed string");
|
|
76
79
|
}
|
|
77
|
-
const crypto = await
|
|
80
|
+
const crypto = await chunkAITKBKQX_cjs.webCrypto();
|
|
78
81
|
const versions = /* @__PURE__ */ new Map();
|
|
79
82
|
const derived = /* @__PURE__ */ new Map();
|
|
80
83
|
let active;
|
|
81
84
|
let mac = "";
|
|
82
85
|
const supplied = /* @__PURE__ */ new Map();
|
|
83
86
|
for (const { id, material } of keys) {
|
|
84
|
-
if (!
|
|
87
|
+
if (!chunkUN74SYHV_cjs.isKeyId(id)) {
|
|
85
88
|
throw new chunkWLJN7GIS_cjs.KeyManagementError("key identifiers are 1-16 characters of A-Z, a-z and 0-9");
|
|
86
89
|
}
|
|
87
90
|
if (supplied.has(id)) throw new chunkWLJN7GIS_cjs.KeyManagementError("the identifier is used more than once", id);
|
|
@@ -97,7 +100,7 @@ async function createKeyRing(options) {
|
|
|
97
100
|
for (const info of infos) {
|
|
98
101
|
const material = supplied.get(info.id);
|
|
99
102
|
supplied.delete(info.id);
|
|
100
|
-
const salt =
|
|
103
|
+
const salt = chunkROXNQKOA_cjs.fromBase64Url(info.salt) ?? new Uint8Array(0);
|
|
101
104
|
if (info.state === "destroyed") {
|
|
102
105
|
versions.set(info.id, { ...info, salt, iterations: info.iterations, base: void 0 });
|
|
103
106
|
continue;
|
|
@@ -127,8 +130,8 @@ async function createKeyRing(options) {
|
|
|
127
130
|
);
|
|
128
131
|
}
|
|
129
132
|
active = manifest.activeKeyId;
|
|
130
|
-
const expected =
|
|
131
|
-
const genuine = expected !== void 0 && await crypto.subtle.verify("HMAC", await macKey(), expected,
|
|
133
|
+
const expected = chunkROXNQKOA_cjs.fromBase64Url(typeof manifest.mac === "string" ? manifest.mac : "");
|
|
134
|
+
const genuine = expected !== void 0 && await crypto.subtle.verify("HMAC", await macKey(), expected, chunkROXNQKOA_cjs.utf8(macInput()));
|
|
132
135
|
if (!genuine) {
|
|
133
136
|
throw new chunkWLJN7GIS_cjs.KeyManagementError(
|
|
134
137
|
"the manifest failed authentication: it was edited, or the key material is not the one it was created with"
|
|
@@ -149,17 +152,17 @@ async function createKeyRing(options) {
|
|
|
149
152
|
version.state === "active",
|
|
150
153
|
version.createdAt,
|
|
151
154
|
version.kdf,
|
|
152
|
-
|
|
155
|
+
chunkROXNQKOA_cjs.toBase64Url(version.salt),
|
|
153
156
|
version.iterations ?? null
|
|
154
157
|
])
|
|
155
158
|
]);
|
|
156
159
|
}
|
|
157
160
|
async function sign() {
|
|
158
|
-
const signature = await crypto.subtle.sign("HMAC", await macKey(),
|
|
159
|
-
return
|
|
161
|
+
const signature = await crypto.subtle.sign("HMAC", await macKey(), chunkROXNQKOA_cjs.utf8(macInput()));
|
|
162
|
+
return chunkROXNQKOA_cjs.toBase64Url(new Uint8Array(signature));
|
|
160
163
|
}
|
|
161
164
|
async function add(id, material) {
|
|
162
|
-
const salt =
|
|
165
|
+
const salt = chunkROXNQKOA_cjs.randomBytes(crypto, SALT_BYTES);
|
|
163
166
|
const iterations = resolveIterations(id, material);
|
|
164
167
|
const base = await importBase(crypto, id, material, salt, iterations);
|
|
165
168
|
const previous = active === void 0 ? void 0 : versions.get(active);
|
|
@@ -185,7 +188,7 @@ async function createKeyRing(options) {
|
|
|
185
188
|
state: version.state,
|
|
186
189
|
createdAt: version.createdAt,
|
|
187
190
|
kdf: version.kdf,
|
|
188
|
-
salt:
|
|
191
|
+
salt: chunkROXNQKOA_cjs.toBase64Url(version.salt),
|
|
189
192
|
...version.iterations !== void 0 ? { iterations: version.iterations } : {}
|
|
190
193
|
});
|
|
191
194
|
}
|
|
@@ -193,7 +196,7 @@ async function createKeyRing(options) {
|
|
|
193
196
|
const version = versions.get(keyId);
|
|
194
197
|
if (version === void 0) {
|
|
195
198
|
return Promise.reject(
|
|
196
|
-
new chunkWLJN7GIS_cjs.KeyManagementError("unknown key version",
|
|
199
|
+
new chunkWLJN7GIS_cjs.KeyManagementError("unknown key version", chunkUN74SYHV_cjs.isKeyId(keyId) ? keyId : void 0)
|
|
197
200
|
);
|
|
198
201
|
}
|
|
199
202
|
const base = version.base;
|
|
@@ -208,7 +211,7 @@ async function createKeyRing(options) {
|
|
|
208
211
|
name: "HKDF",
|
|
209
212
|
hash: "SHA-256",
|
|
210
213
|
salt: version.salt,
|
|
211
|
-
info:
|
|
214
|
+
info: chunkROXNQKOA_cjs.utf8(`anonyma/v1/${purpose}\0${namespace}`)
|
|
212
215
|
},
|
|
213
216
|
base,
|
|
214
217
|
purpose === "token-seal" ? { name: "AES-GCM", length: 256 } : { name: "HMAC", hash: "SHA-256", length: 256 },
|
|
@@ -223,7 +226,7 @@ async function createKeyRing(options) {
|
|
|
223
226
|
let rotations = Promise.resolve();
|
|
224
227
|
function rotate(version) {
|
|
225
228
|
const { id, material } = version;
|
|
226
|
-
if (!
|
|
229
|
+
if (!chunkUN74SYHV_cjs.isKeyId(id)) {
|
|
227
230
|
return Promise.reject(
|
|
228
231
|
new chunkWLJN7GIS_cjs.KeyManagementError("key identifiers are 1-16 characters of A-Z, a-z and 0-9")
|
|
229
232
|
);
|
|
@@ -246,7 +249,7 @@ async function createKeyRing(options) {
|
|
|
246
249
|
function destroy(keyId) {
|
|
247
250
|
const version = versions.get(keyId);
|
|
248
251
|
if (version === void 0) {
|
|
249
|
-
throw new chunkWLJN7GIS_cjs.KeyManagementError("unknown key version",
|
|
252
|
+
throw new chunkWLJN7GIS_cjs.KeyManagementError("unknown key version", chunkUN74SYHV_cjs.isKeyId(keyId) ? keyId : void 0);
|
|
250
253
|
}
|
|
251
254
|
if (version.state === "active") {
|
|
252
255
|
throw new chunkWLJN7GIS_cjs.KeyManagementError(
|
|
@@ -289,8 +292,8 @@ function readManifest(manifest, namespace) {
|
|
|
289
292
|
if (typeof entry !== "object" || entry === null) throw malformed;
|
|
290
293
|
const info = entry;
|
|
291
294
|
const { id, state, createdAt, kdf, salt, iterations } = info;
|
|
292
|
-
const saltBytes = typeof salt === "string" ?
|
|
293
|
-
if (!
|
|
295
|
+
const saltBytes = typeof salt === "string" ? chunkROXNQKOA_cjs.fromBase64Url(salt) : void 0;
|
|
296
|
+
if (!chunkUN74SYHV_cjs.isKeyId(id) || seen.has(id) || !STATES.has(state) || typeof createdAt !== "number" || !Number.isFinite(createdAt) || kdf !== "hkdf" && kdf !== "pbkdf2-hkdf" || saltBytes === void 0 || saltBytes.length < MIN_SALT_BYTES || (kdf === "hkdf" ? iterations !== void 0 : typeof iterations !== "number")) {
|
|
294
297
|
throw malformed;
|
|
295
298
|
}
|
|
296
299
|
seen.add(id);
|
|
@@ -307,32 +310,32 @@ function readManifest(manifest, namespace) {
|
|
|
307
310
|
var IV_BYTES = 12;
|
|
308
311
|
var TAG_BYTES = 16;
|
|
309
312
|
async function macOf(crypto, key, category, value) {
|
|
310
|
-
const input =
|
|
313
|
+
const input = chunkROXNQKOA_cjs.concatBytes(chunkROXNQKOA_cjs.encodeText(category), new Uint8Array(1), chunkROXNQKOA_cjs.encodeText(value));
|
|
311
314
|
return new Uint8Array(await crypto.subtle.sign("HMAC", key, input));
|
|
312
315
|
}
|
|
313
|
-
async function seal(crypto, key, value, additionalData, iv =
|
|
316
|
+
async function seal(crypto, key, value, additionalData, iv = chunkROXNQKOA_cjs.randomBytes(crypto, IV_BYTES)) {
|
|
314
317
|
const sealed = await crypto.subtle.encrypt(
|
|
315
|
-
{ name: "AES-GCM", iv, additionalData:
|
|
318
|
+
{ name: "AES-GCM", iv, additionalData: chunkROXNQKOA_cjs.utf8(additionalData), tagLength: TAG_BYTES * 8 },
|
|
316
319
|
key,
|
|
317
|
-
|
|
320
|
+
chunkROXNQKOA_cjs.encodeText(value)
|
|
318
321
|
);
|
|
319
|
-
return
|
|
322
|
+
return chunkROXNQKOA_cjs.toBase64Url(chunkROXNQKOA_cjs.concatBytes(iv, new Uint8Array(sealed)));
|
|
320
323
|
}
|
|
321
324
|
async function unseal(crypto, key, sealed, additionalData) {
|
|
322
|
-
const bytes =
|
|
325
|
+
const bytes = chunkROXNQKOA_cjs.fromBase64Url(sealed);
|
|
323
326
|
if (bytes === void 0 || bytes.length < IV_BYTES + TAG_BYTES) return void 0;
|
|
324
327
|
try {
|
|
325
328
|
const plain = await crypto.subtle.decrypt(
|
|
326
329
|
{
|
|
327
330
|
name: "AES-GCM",
|
|
328
331
|
iv: bytes.subarray(0, IV_BYTES),
|
|
329
|
-
additionalData:
|
|
332
|
+
additionalData: chunkROXNQKOA_cjs.utf8(additionalData),
|
|
330
333
|
tagLength: TAG_BYTES * 8
|
|
331
334
|
},
|
|
332
335
|
key,
|
|
333
336
|
bytes.subarray(IV_BYTES)
|
|
334
337
|
);
|
|
335
|
-
return
|
|
338
|
+
return chunkROXNQKOA_cjs.decodeText(new Uint8Array(plain));
|
|
336
339
|
} catch {
|
|
337
340
|
return void 0;
|
|
338
341
|
}
|
|
@@ -342,7 +345,7 @@ async function unseal(crypto, key, sealed, additionalData) {
|
|
|
342
345
|
var MAX_ATTEMPTS = 5;
|
|
343
346
|
async function subjectTagOf(keyring, keyId, subject) {
|
|
344
347
|
const key = await keyring.deriveKey(keyId, "subject-tag");
|
|
345
|
-
return
|
|
348
|
+
return chunkROXNQKOA_cjs.toBase64Url(await macOf(await chunkAITKBKQX_cjs.webCrypto(), key, "subject", subject));
|
|
346
349
|
}
|
|
347
350
|
function subjectContext(token) {
|
|
348
351
|
return `${token}\0subject`;
|
|
@@ -356,18 +359,18 @@ function createKeyedTokenizer(options) {
|
|
|
356
359
|
if (!Number.isInteger(idLength) || idLength < 8 || idLength > 26) {
|
|
357
360
|
throw new chunkWLJN7GIS_cjs.ValidationError("idLength", "must be an integer between 8 and 26");
|
|
358
361
|
}
|
|
359
|
-
if (idKeyId !== void 0 && !
|
|
362
|
+
if (idKeyId !== void 0 && !chunkUN74SYHV_cjs.isKeyId(idKeyId)) {
|
|
360
363
|
throw new chunkWLJN7GIS_cjs.ValidationError("idKeyId", "is not a valid key version identifier");
|
|
361
364
|
}
|
|
362
365
|
if (ttlMs !== void 0 && !(ttlMs > 0)) {
|
|
363
366
|
throw new chunkWLJN7GIS_cjs.ValidationError("ttlMs", "must be a positive number");
|
|
364
367
|
}
|
|
365
|
-
const prefixOf =
|
|
366
|
-
const tokenSource = `\\[${
|
|
368
|
+
const prefixOf = chunkUN74SYHV_cjs.prefixResolver(options.prefixes);
|
|
369
|
+
const tokenSource = `\\[${chunkUN74SYHV_cjs.PREFIX_SOURCE}_${chunkUN74SYHV_cjs.KEY_ID_SOURCE}_[0-9A-HJKMNP-TV-Z]{${String(idLength)}}\\]`;
|
|
367
370
|
const wholeToken = new RegExp(`^${tokenSource}$`);
|
|
368
371
|
async function tokenize(value, context) {
|
|
369
372
|
if (typeof value !== "string") throw new chunkWLJN7GIS_cjs.ValidationError("value", "must be a string");
|
|
370
|
-
const crypto = await
|
|
373
|
+
const crypto = await chunkAITKBKQX_cjs.webCrypto();
|
|
371
374
|
const keyId = idKeyId ?? keyring.activeKeyId();
|
|
372
375
|
const mac = await macOf(
|
|
373
376
|
crypto,
|
|
@@ -375,9 +378,9 @@ function createKeyedTokenizer(options) {
|
|
|
375
378
|
context.category,
|
|
376
379
|
value
|
|
377
380
|
);
|
|
378
|
-
const token = `[${prefixOf(context.category)}_${keyId}_${
|
|
381
|
+
const token = `[${prefixOf(context.category)}_${keyId}_${chunkROXNQKOA_cjs.toBase32(mac, idLength)}]`;
|
|
379
382
|
if (vault === void 0) return token;
|
|
380
|
-
const check =
|
|
383
|
+
const check = chunkROXNQKOA_cjs.toBase64Url(mac);
|
|
381
384
|
for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
|
|
382
385
|
let existing = await vault.get(token);
|
|
383
386
|
if (existing === void 0) {
|
|
@@ -455,7 +458,7 @@ function createKeyedTokenizer(options) {
|
|
|
455
458
|
} catch {
|
|
456
459
|
return void 0;
|
|
457
460
|
}
|
|
458
|
-
return unseal(await
|
|
461
|
+
return unseal(await chunkAITKBKQX_cjs.webCrypto(), key, record.sealed, valueContext(record));
|
|
459
462
|
}
|
|
460
463
|
async function forgetToken(token) {
|
|
461
464
|
return vault === void 0 ? false : vault.delete(token);
|
|
@@ -493,7 +496,11 @@ function createKeyedTokenizer(options) {
|
|
|
493
496
|
method: "vault-delete",
|
|
494
497
|
erased,
|
|
495
498
|
keyIds: Object.freeze([...keyIds].sort()),
|
|
496
|
-
|
|
499
|
+
// The active version cannot be destroyed, so it always has a tag.
|
|
500
|
+
...activeTag !== void 0 ? { subjectTag: activeTag } : (
|
|
501
|
+
/* v8 ignore next */
|
|
502
|
+
{}
|
|
503
|
+
),
|
|
497
504
|
completedAt: now()
|
|
498
505
|
});
|
|
499
506
|
}
|
|
@@ -516,15 +523,15 @@ function createSealedTokenizer(options) {
|
|
|
516
523
|
if (!Number.isInteger(maxValueBytes) || maxValueBytes < 1) {
|
|
517
524
|
throw new chunkWLJN7GIS_cjs.ValidationError("maxValueBytes", "must be a positive integer");
|
|
518
525
|
}
|
|
519
|
-
const prefixOf =
|
|
520
|
-
const tokenSource = `\\[(${
|
|
526
|
+
const prefixOf = chunkUN74SYHV_cjs.prefixResolver(options.prefixes);
|
|
527
|
+
const tokenSource = `\\[(${chunkUN74SYHV_cjs.PREFIX_SOURCE})_(${chunkUN74SYHV_cjs.KEY_ID_SOURCE})\\.([A-Za-z0-9_-]{38,})\\]`;
|
|
521
528
|
const wholeToken = new RegExp(`^${tokenSource}$`);
|
|
522
529
|
async function tokenize(value, context) {
|
|
523
530
|
if (typeof value !== "string") throw new chunkWLJN7GIS_cjs.ValidationError("value", "must be a string");
|
|
524
|
-
if (
|
|
531
|
+
if (chunkROXNQKOA_cjs.encodeText(value).length > maxValueBytes) {
|
|
525
532
|
throw new chunkWLJN7GIS_cjs.ValidationError("value", "is longer than maxValueBytes and cannot be sealed");
|
|
526
533
|
}
|
|
527
|
-
const crypto = await
|
|
534
|
+
const crypto = await chunkAITKBKQX_cjs.webCrypto();
|
|
528
535
|
const keyId = keyring.activeKeyId();
|
|
529
536
|
const header = `${prefixOf(context.category)}_${keyId}`;
|
|
530
537
|
const mac = await macOf(crypto, await keyring.deriveKey(keyId, "token-id"), header, value);
|
|
@@ -550,7 +557,7 @@ function createSealedTokenizer(options) {
|
|
|
550
557
|
} catch {
|
|
551
558
|
return void 0;
|
|
552
559
|
}
|
|
553
|
-
return unseal(await
|
|
560
|
+
return unseal(await chunkAITKBKQX_cjs.webCrypto(), key, sealed, `${prefix}_${keyId}`);
|
|
554
561
|
}
|
|
555
562
|
return Object.freeze({
|
|
556
563
|
scheme: "sealed",
|
|
@@ -597,7 +604,7 @@ function createMemoryVault(records = []) {
|
|
|
597
604
|
|
|
598
605
|
// src/vault/rotation.ts
|
|
599
606
|
async function rewrapVault(vault, keyring) {
|
|
600
|
-
const crypto = await
|
|
607
|
+
const crypto = await chunkAITKBKQX_cjs.webCrypto();
|
|
601
608
|
const active = keyring.activeKeyId();
|
|
602
609
|
const activeKey = await keyring.deriveKey(active, "token-seal");
|
|
603
610
|
const stale = [];
|
|
@@ -675,7 +682,19 @@ Object.defineProperty(exports, "tokenizeWith", {
|
|
|
675
682
|
});
|
|
676
683
|
Object.defineProperty(exports, "createSessionTokenizer", {
|
|
677
684
|
enumerable: true,
|
|
678
|
-
get: function () { return
|
|
685
|
+
get: function () { return chunkNO4ZCIM6_cjs.createSessionTokenizer; }
|
|
686
|
+
});
|
|
687
|
+
Object.defineProperty(exports, "InMemoryVault", {
|
|
688
|
+
enumerable: true,
|
|
689
|
+
get: function () { return chunkT2KIN6VL_cjs.InMemoryVault; }
|
|
690
|
+
});
|
|
691
|
+
Object.defineProperty(exports, "createVaultTokenizer", {
|
|
692
|
+
enumerable: true,
|
|
693
|
+
get: function () { return chunkT2KIN6VL_cjs.createVaultTokenizer; }
|
|
694
|
+
});
|
|
695
|
+
Object.defineProperty(exports, "restore", {
|
|
696
|
+
enumerable: true,
|
|
697
|
+
get: function () { return chunkT2KIN6VL_cjs.restore; }
|
|
679
698
|
});
|
|
680
699
|
exports.createKeyRing = createKeyRing;
|
|
681
700
|
exports.createKeyedTokenizer = createKeyedTokenizer;
|