This repository has been archived on 2023-04-04. You can view files and clone it, but cannot push or open issues or pull requests.
webcrypto/packages/core/test/jwk_utils.spec.ts

51 lines
1.2 KiB
TypeScript

import * as core from "@peculiar/webcrypto-core";
import * as types from "@peculiar/webcrypto-types";
import * as assert from "assert";
import * as crypto from "crypto";
import { Convert } from "pvtsutils";
// crypto.webcrypto
const ctx = crypto.webcrypto ? context : context.skip;
ctx("JWK utils", () => {
it("format with odd removing", () => {
const jwk: types.JsonWebKey = {
n: "n value",
ext: true,
e: "e value",
};
const formattedJwk = core.JwkUtils.format(jwk, true);
assert.strictEqual(JSON.stringify(formattedJwk), JSON.stringify({
e: "e value",
n: "n value",
}));
});
it("format without removing", () => {
const jwk: types.JsonWebKey = {
n: "n value",
ext: true,
e: "e value",
};
const formattedJwk = core.JwkUtils.format(jwk, false);
assert.strictEqual(JSON.stringify(formattedJwk), JSON.stringify({
e: "e value",
ext: true,
n: "n value",
}));
});
it("thumbprint", async () => {
const digest = await core.JwkUtils.thumbprint("SHA-256", {
e: "e value",
n: "n value",
}, crypto.webcrypto as any);
assert.strictEqual(Convert.ToBase64(digest), "MkHJT3yHfy0O9t4OHK/331Pb3HNa4LRG62yPa4NNnSc=");
});
});