release: WRNexusJS 0.4.0
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
sha256,
|
||||
hmacSign,
|
||||
hmacVerify,
|
||||
createKeyring,
|
||||
} from "../src/index.ts";
|
||||
|
||||
test("sha256 is stable and hex-encoded", async () => {
|
||||
@@ -56,3 +57,20 @@ test("deriveKey is deterministic for the same password+salt", async () => {
|
||||
// usable as an encryption key
|
||||
expect(await decrypt(await encrypt("x", k1), k1)).toBe("x");
|
||||
});
|
||||
|
||||
test("keyrings reject duplicate keys and return defensive copies", () => {
|
||||
expect(() =>
|
||||
createKeyring([
|
||||
{ id: "one", secret: "secret-one", active: true },
|
||||
{ id: "one", secret: "secret-two" },
|
||||
]),
|
||||
).toThrow("DUPLICATE");
|
||||
|
||||
const keyring = createKeyring([
|
||||
{ id: "one", secret: "secret-one", active: true },
|
||||
{ id: "two", secret: "secret-two" },
|
||||
]);
|
||||
const active = keyring.active();
|
||||
active.secret = "changed";
|
||||
expect(keyring.active().secret).toBe("secret-one");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user