vaultkeeper 0.3.0 → 0.4.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/dist/index.cjs +85 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -1
- package/dist/index.d.ts +88 -1
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1016,6 +1016,50 @@ function createSecretAccessor(secretValue) {
|
|
|
1016
1016
|
return proxy;
|
|
1017
1017
|
}
|
|
1018
1018
|
|
|
1019
|
+
// src/access/sign-util.ts
|
|
1020
|
+
var ALLOWED_ALGORITHMS = /* @__PURE__ */ new Set(["sha256", "sha384", "sha512"]);
|
|
1021
|
+
function resolveAlgorithmForKey(key, override) {
|
|
1022
|
+
const keyType = key.asymmetricKeyType;
|
|
1023
|
+
if (keyType === "ed25519" || keyType === "ed448") {
|
|
1024
|
+
return { signAlg: null, label: keyType };
|
|
1025
|
+
}
|
|
1026
|
+
const alg = override ?? "sha256";
|
|
1027
|
+
if (!ALLOWED_ALGORITHMS.has(alg)) {
|
|
1028
|
+
throw new VaultError(
|
|
1029
|
+
`Unsupported signing algorithm '${alg}'. Allowed: ${[...ALLOWED_ALGORITHMS].join(", ")}`
|
|
1030
|
+
);
|
|
1031
|
+
}
|
|
1032
|
+
return { signAlg: alg, label: alg };
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
// src/access/delegated-sign.ts
|
|
1036
|
+
function delegatedSign(secretPem, request) {
|
|
1037
|
+
const key = crypto4__namespace.createPrivateKey(secretPem);
|
|
1038
|
+
const { signAlg, label } = resolveAlgorithmForKey(key, request.algorithm);
|
|
1039
|
+
const data = Buffer.isBuffer(request.data) ? request.data : Buffer.from(request.data);
|
|
1040
|
+
const signature = crypto4__namespace.sign(signAlg, data, key);
|
|
1041
|
+
return {
|
|
1042
|
+
signature: signature.toString("base64"),
|
|
1043
|
+
algorithm: label
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
function delegatedVerify(request) {
|
|
1047
|
+
let key;
|
|
1048
|
+
try {
|
|
1049
|
+
key = crypto4__namespace.createPublicKey(request.publicKey);
|
|
1050
|
+
} catch {
|
|
1051
|
+
return false;
|
|
1052
|
+
}
|
|
1053
|
+
const { signAlg } = resolveAlgorithmForKey(key, request.algorithm);
|
|
1054
|
+
const sig = Buffer.from(request.signature, "base64");
|
|
1055
|
+
try {
|
|
1056
|
+
const data = Buffer.isBuffer(request.data) ? request.data : Buffer.from(request.data);
|
|
1057
|
+
return crypto4__namespace.verify(signAlg, data, key, sig);
|
|
1058
|
+
} catch {
|
|
1059
|
+
return false;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1019
1063
|
// src/doctor/checks.ts
|
|
1020
1064
|
function parseVersion(raw) {
|
|
1021
1065
|
const match = /(\d+)\.(\d+)\.(\d+)/.exec(raw);
|
|
@@ -1373,6 +1417,47 @@ var VaultKeeper = class _VaultKeeper {
|
|
|
1373
1417
|
const claims = validateCapabilityToken(token);
|
|
1374
1418
|
return createSecretAccessor(claims.val);
|
|
1375
1419
|
}
|
|
1420
|
+
/**
|
|
1421
|
+
* Sign data using the private key embedded in a capability token.
|
|
1422
|
+
*
|
|
1423
|
+
* The signing key is extracted from the token's encrypted claims, used
|
|
1424
|
+
* for a single `crypto.sign()` call, and never exposed to the caller.
|
|
1425
|
+
* The algorithm is auto-detected from the key type unless overridden
|
|
1426
|
+
* in the request.
|
|
1427
|
+
*
|
|
1428
|
+
* @param token - A `CapabilityToken` obtained from `authorize()`.
|
|
1429
|
+
* @param request - The data to sign and optional algorithm override.
|
|
1430
|
+
* @returns The base64-encoded signature and algorithm label, together
|
|
1431
|
+
* with the vault metadata (`vaultResponse`).
|
|
1432
|
+
* @throws {VaultError} If `token` is invalid or was not created by this
|
|
1433
|
+
* vault instance.
|
|
1434
|
+
*/
|
|
1435
|
+
async sign(token, request) {
|
|
1436
|
+
const claims = validateCapabilityToken(token);
|
|
1437
|
+
const result = delegatedSign(claims.val, request);
|
|
1438
|
+
await Promise.resolve();
|
|
1439
|
+
return {
|
|
1440
|
+
result,
|
|
1441
|
+
vaultResponse: { keyStatus: "current" }
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Verify a signature using a public key.
|
|
1446
|
+
*
|
|
1447
|
+
* This is a static method — no VaultKeeper instance, secrets, or
|
|
1448
|
+
* capability tokens are required. It is safe to call from CI or any
|
|
1449
|
+
* context that has access to public key material.
|
|
1450
|
+
*
|
|
1451
|
+
* Never throws. Returns `false` for invalid key material, malformed
|
|
1452
|
+
* signatures, or any verification failure.
|
|
1453
|
+
*
|
|
1454
|
+
* @param request - The data, signature, public key, and optional
|
|
1455
|
+
* algorithm override.
|
|
1456
|
+
* @returns `true` if the signature is valid, `false` otherwise.
|
|
1457
|
+
*/
|
|
1458
|
+
static verify(request) {
|
|
1459
|
+
return delegatedVerify(request);
|
|
1460
|
+
}
|
|
1376
1461
|
/**
|
|
1377
1462
|
* Rotate the current encryption key.
|
|
1378
1463
|
*
|