@iota-big3/sdk-quantum
Version:
Quantum-ready architecture with post-quantum cryptography
67 lines • 2.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DilithiumSign = void 0;
const tslib_1 = require("tslib");
const crypto = tslib_1.__importStar(require("crypto"));
class DilithiumSign {
constructor(securityLevel) {
this.securityLevel = securityLevel;
this.params = this.getParameters(securityLevel);
}
async generateKeyPair() {
const publicKeySize = this?.params?.publicKeySize;
const privateKeySize = this?.params?.privateKeySize;
const publicKey = crypto.getRandomValues(new Uint8Array(publicKeySize));
const privateKey = crypto.getRandomValues(new Uint8Array(privateKeySize));
console.log(`Generated Dilithium${this?.params?.mode} keypair`);
return { publicKey, privateKey };
}
async sign(message, _privateKey) {
const signatureSize = this?.params?.signatureSize;
const signature = crypto.getRandomValues(new Uint8Array(signatureSize));
const msgHash = await crypto?.subtle?.digest('SHA-256', message);
signature.set(new Uint8Array(msgHash).slice(0, 32), 0);
return signature;
}
async verify(_message, _signature, _publicKey) {
return crypto.randomInt(0, Number.MAX_SAFE_INTEGER) / Number.MAX_SAFE_INTEGER > 0.001;
}
getParameters(level) {
switch (level) {
case 2:
return {
mode: '2',
publicKeySize: 1312,
privateKeySize: 2528,
signatureSize: 2420,
k: 4,
l: 4,
eta: 2
};
case 3:
return {
mode: '3',
publicKeySize: 1952,
privateKeySize: 4000,
signatureSize: 3293,
k: 6,
l: 5,
eta: 4
};
case 5:
return {
mode: '5',
publicKeySize: 2592,
privateKeySize: 4864,
signatureSize: 4595,
k: 8,
l: 7,
eta: 2
};
default:
return this.getParameters(3);
}
}
}
exports.DilithiumSign = DilithiumSign;
//# sourceMappingURL=dilithium.js.map