Back

Version 26

2/14/2024
// SPDX-License-Identifier: 0-BSD
import { shake128, shake256 } from "npm:@noble/hashes/sha3";
import * as jose from "npm:jose";
import ky from "npm:ky";
import { base16 } from "npm:multiformats/bases/base16";

type HashAlgorithm = "shake128" | "shake256";

// aspe:keyoxide.org:TOICV3SYXNJP7E4P5AOK5DHW44
const asp = await fetchASP("TOICV3SYXNJP7E4P5AOK5DHW44");
console.log(processASP(asp, "shake128", 10 * 4 * 4));
console.log(processASP(asp, "shake128", 12 * 4 * 4));
console.log(processASP(asp, "shake128", 14 * 4 * 4));

function processASP(asp: string, alg: HashAlgorithm = "shake128", d = 160) {
let collisionResistance;
if (alg === "shake128") collisionResistance = Math.min(d / 2, 128);
else if (alg === "shake256") collisionResistance = Math.min(d / 2, 256);
const jwk = extractJWK(asp);
const fingerprint = calculateFingerprint(jwk, alg, d);
return {
algorithm: `${alg}; dkLen=${d / 8} (bytes); d=${d} (bits)`,
collisionResistance,
uri: `aspe:${fingerprint}`,
uriWithAuthority: `aspe://keyoxide.org/${fingerprint}`,
fingerprint,
fingerprintLength: fingerprint.length,
formattedFingerprint: formatFingerprint(fingerprint),
keyId: getKeyId(fingerprint),
};
}

function getKeyId(fingerprint: string) {
return formatFingerprint(fingerprint)
.split(" ")
.slice(0, 4)
Updated: March 6, 2024