update mods
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {execCommand} from "https://global.hatter.ink/script/get/@18/deno-commons-mod.ts";
|
||||
import {execCommand, getKeyRingPassword,} from "https://global.hatter.ink/script/get/@47/deno-commons-mod.ts";
|
||||
import {encodeHex} from "jsr:@std/encoding/hex";
|
||||
|
||||
// example output
|
||||
@@ -18,20 +18,37 @@ interface CardPivEcSignOutput {
|
||||
slot: string;
|
||||
}
|
||||
|
||||
interface SignPivOptions {
|
||||
pin?: string;
|
||||
service?: string;
|
||||
user?: string;
|
||||
}
|
||||
|
||||
export async function signPivString(
|
||||
slot: string,
|
||||
message: string,
|
||||
options?: SignPivOptions,
|
||||
): Promise<CardPivEcSignOutput> {
|
||||
return await signPiv(slot, await sha256AndHexMessage(message), options);
|
||||
}
|
||||
|
||||
export async function signPiv(
|
||||
slot: string,
|
||||
digestSha256Hex: string,
|
||||
options?: SignPivOptions,
|
||||
): Promise<CardPivEcSignOutput> {
|
||||
const processOutput = await execCommand("card-cli", [
|
||||
"piv-ecsign",
|
||||
"-s",
|
||||
slot,
|
||||
"-x",
|
||||
digestSha256Hex,
|
||||
"--json",
|
||||
]);
|
||||
processOutput.assertSuccess();
|
||||
return JSON.parse(processOutput.stdout) as CardPivEcSignOutput;
|
||||
if (!options?.pin && options?.user) {
|
||||
options.pin = await getKeyRingPassword(
|
||||
options.service,
|
||||
options.user,
|
||||
);
|
||||
}
|
||||
const args = ["piv-ecsign", "-s", slot, "-x", digestSha256Hex, "--json"];
|
||||
if (options?.pin) {
|
||||
args.push(...["--pin", options?.pin]);
|
||||
}
|
||||
return (await execCommand("card-cli", args))
|
||||
.assertSuccess().stdoutAsJson() as CardPivEcSignOutput;
|
||||
}
|
||||
|
||||
export async function sha256AndHexMessage(message: string): Promise<string> {
|
||||
|
||||
Reference in New Issue
Block a user