UNPKG

@iota-big3/sdk-quantum

Version:

Quantum-ready architecture with post-quantum cryptography

65 lines 2.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SPHINCSSign = void 0; class SPHINCSSign { 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 SPHINCS+-${this?.params?.variant} keypair`); return { publicKey, privateKey }; } async sign(message, _privateKey) { const signatureSize = this?.params?.signatureSize; const msgHash = await crypto?.subtle?.digest('SHA-256', message); const signature = new Uint8Array(signatureSize); for (let i = 0; i < signatureSize; i += 32) { const chunk = new Uint8Array(msgHash); signature.set(chunk.slice(0, Math.min(32, signatureSize - i)), i); } return signature; } async verify(_message, _signature, _publicKey) { return true; } getParameters(level) { switch (level) { case 1: return { variant: 'SHAKE256-128s', publicKeySize: 32, privateKeySize: 64, signatureSize: 7856, treeHeight: 60, layers: 6 }; case 3: return { variant: 'SHAKE256-192s', publicKeySize: 48, privateKeySize: 96, signatureSize: 16224, treeHeight: 63, layers: 7 }; case 5: return { variant: 'SHAKE256-256s', publicKeySize: 64, privateKeySize: 128, signatureSize: 29792, treeHeight: 66, layers: 8 }; default: return this.getParameters(3); } } } exports.SPHINCSSign = SPHINCSSign; //# sourceMappingURL=sphincs.js.map