bitcoinpqc
Version:
NodeJS TypeScript bindings for Bitcoin PQC library
105 lines (104 loc) • 3.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.KeyPair = exports.Signature = exports.SecretKey = exports.PublicKey = exports.PqcError = exports.ErrorCode = exports.Algorithm = void 0;
/**
* Bitcoin PQC algorithm identifiers
*/
var Algorithm;
(function (Algorithm) {
/** BIP-340 Schnorr + X-Only - Elliptic Curve Digital Signature Algorithm */
Algorithm[Algorithm["SECP256K1_SCHNORR"] = 0] = "SECP256K1_SCHNORR";
/** FN-DSA-512 (FALCON) - Fast Fourier lattice-based signature scheme */
Algorithm[Algorithm["FN_DSA_512"] = 1] = "FN_DSA_512";
/** ML-DSA-44 (CRYSTALS-Dilithium) - Lattice-based signature scheme */
Algorithm[Algorithm["ML_DSA_44"] = 2] = "ML_DSA_44";
/** SLH-DSA-Shake-128s (SPHINCS+) - Hash-based signature scheme */
Algorithm[Algorithm["SLH_DSA_SHAKE_128S"] = 3] = "SLH_DSA_SHAKE_128S";
})(Algorithm || (exports.Algorithm = Algorithm = {}));
/**
* Error types for PQC operations
*/
var ErrorCode;
(function (ErrorCode) {
/** Operation completed successfully */
ErrorCode[ErrorCode["OK"] = 0] = "OK";
/** Invalid arguments provided */
ErrorCode[ErrorCode["BAD_ARGUMENT"] = -1] = "BAD_ARGUMENT";
/** Invalid key provided */
ErrorCode[ErrorCode["BAD_KEY"] = -2] = "BAD_KEY";
/** Invalid signature provided */
ErrorCode[ErrorCode["BAD_SIGNATURE"] = -3] = "BAD_SIGNATURE";
/** Algorithm not implemented */
ErrorCode[ErrorCode["NOT_IMPLEMENTED"] = -4] = "NOT_IMPLEMENTED";
})(ErrorCode || (exports.ErrorCode = ErrorCode = {}));
/**
* Error class for PQC operations
*/
class PqcError extends Error {
constructor(code, message) {
// Use a default message if none provided
const defaultMessage = (() => {
switch (code) {
case ErrorCode.BAD_ARGUMENT:
return "Invalid arguments provided";
case ErrorCode.BAD_KEY:
return "Invalid key provided";
case ErrorCode.BAD_SIGNATURE:
return "Invalid signature provided";
case ErrorCode.NOT_IMPLEMENTED:
return "Algorithm not implemented";
default:
return `Unexpected error code: ${code}`;
}
})();
super(message || defaultMessage);
this.code = code;
this.name = "PqcError";
// For better stack traces in Node.js
Error.captureStackTrace(this, PqcError);
}
}
exports.PqcError = PqcError;
/**
* Public key wrapper
*/
class PublicKey {
constructor(algorithm, bytes) {
this.algorithm = algorithm;
this.bytes = bytes;
}
}
exports.PublicKey = PublicKey;
/**
* Secret key wrapper
*/
class SecretKey {
constructor(algorithm, bytes) {
this.algorithm = algorithm;
this.bytes = bytes;
}
}
exports.SecretKey = SecretKey;
/**
* Signature wrapper
*/
class Signature {
constructor(algorithm, bytes) {
this.algorithm = algorithm;
this.bytes = bytes;
}
}
exports.Signature = Signature;
/**
* Key pair containing both public and secret keys
*/
class KeyPair {
constructor(publicKey, secretKey) {
if (publicKey.algorithm !== secretKey.algorithm) {
throw new PqcError(ErrorCode.BAD_ARGUMENT, "Public and secret key algorithms must match");
}
this.publicKey = publicKey;
this.secretKey = secretKey;
}
}
exports.KeyPair = KeyPair;