Stateful hash-based signatures: LMS and XMSS
pki.shbs.verify
pki.shbs.verify(publicKey, message, signature) -> boolean
Verify an HSS (Hierarchical Signature System) signature over message under publicKey, the wire form RFC 9802 (X.509) and RFC 9708 (CMS) carry for id-alg-hss-lms-hashsig. The public key and signature are the raw HSS octet blobs the certificate / CMS parsers already surface (no ASN.1 wrapping). Every level of the hierarchy must verify: a single failing level yields false. Returns true for a valid signature, false for a well-formed signature that does not verify; a malformed blob (bad length, unknown or unapproved typecode, truncation, a typecode disagreeing between the key and the signature) throws a typed ShbsError. Verification only: this module never signs.
Example
async function example() {
// throws: shbs/bad-public-key -- an Ed25519 key is not an HSS public key, and
// the verifier fails closed on the wrong key type rather than returning true
var pair = await pki.key.generate("Ed25519");
var der = await pki.x509.sign({ subject: "example.com", subjectPublicKey: await pki.key.export(pair.publicKey),
notBefore: new Date("2026-01-01T00:00:00Z"), notAfter: new Date("2036-01-01T00:00:00Z") },
{ key: await pki.key.export(pair.privateKey) });
var cert = pki.schema.x509.parse(der);
var ok = pki.shbs.verify(cert.subjectPublicKeyInfo.publicKey.bytes,
cert.tbsBytes, cert.signatureValue.bytes);
}
example();
References
- spec RFC 8554 sec. 6
- spec RFC 9802
- spec RFC 9708
pki.shbs.verifyLms
pki.shbs.verifyLms(publicKey, message, signature) -> boolean
Verify a single-tree LMS (Leighton-Micali Signature) over message: the component an HSS hierarchy composes at each level, and a standalone algorithm in its own right. Same verdict contract as pki.shbs.verify: true / false for a well-formed signature, a typed ShbsError for a malformed blob.
Example
// throws: shbs/unsupported-parameter-set -- lmsPublicKey / lmsSignature are raw
// LMS blobs (an HSS level, or a bare LMS-signed artifact); arbitrary bytes carry
// no recognized LMS typecode, so the verifier refuses them instead of returning
var bytes = Buffer.alloc(64);
var ok = pki.shbs.verifyLms(bytes, bytes, bytes);
References
- spec RFC 8554 sec. 5