Chia-Network / bls-signatures

BLS signatures in C++, using the blst library for BLS12-381
Apache License 2.0
292 stars 211 forks source link

Question: Can you help with understanding how to generate BLS signature #442

Closed 0xAxPx closed 6 months ago

0xAxPx commented 7 months ago

Dear Team

Can you navigate me where in bls-signature I can generate signature for my case: I have pk of validator decrypted from BLS

p.s. no sensitive info below it is just an example ......

const decrypt = (privateKey, msg) => {
    const ecdh = crypto.createECDH('prime256v1');
    ecdh.setPrivateKey(privateKey);
    const epk = msg.slice(0, 65)
    const message = msg.slice(65, msg.length - 32)
    const sharedSecret = ecdh.computeSecret(epk);
    const { encKey, macKey } = deriveKeys(sharedSecret, Buffer.alloc(0), 16)
    const tag = messageTag(macKey, message, Buffer.alloc(0))
    if (tag.toString('hex') !== msg.slice(msg.length - 32).toString('hex')) {
        throw new Error('tag mismatch')
    }
    return symDecrypt(encKey, message)

const bls = require('@rigidity/bls-signatures')
const client = crypto.createECDH('prime256v1');
client.setPrivateKey('9eddd40ef7e3aste57839d51f994022aabdce65f8b69a4dfre620595a592w2w', 'hex')
const validatorPrivateKey = decrypt(client.getPrivateKey(), Buffer.from('BNKZxVJ1m8aN0OOJUrNUnk7BljorUVcsxmNwBVDPBgWCWA+/78fQWEuvy3sNS5dmKoCjeD20qeb6Prr89OrgZYdjT+gE93g/g9ZTAznYVFEgGaiJeSvvsKVmcOyJwF240+21qGp+wsT4rjtD+F7HUvLQUEgZu+BD2/T8IOPYaKOXe68Fm4m75fqjxy8rR3YSQg==', 'base64'))
const vsk = bls.PrivateKey.fromBytes(validatorPrivateKey)
console.log(vsk.getG1().toHex()) //a01f0d326089900265e56786fbc75d596a15540f807b82589d1c9c11f87074f33f5b99d192030941f4a7b9a5a62ab40d91
github-actions[bot] commented 7 months ago

'This issue has been flagged as stale as there has been no activity on it in 14 days. If this issue is still affecting you and in need of review, please update it to keep it open.'

github-actions[bot] commented 6 months ago

'This issue was automatically closed because it has been flagged as stale and subsequently passed 7 days with no further activity.'