admin管理员组

文章数量:1317906

I'd like to implement something like the two-man rule using elliptic curve cryptography in javascript.

Edit: I'm essentially looking for something like Bitcoin multisig.

So I need to take bine two public keys to get a bined key that requires both private keys to produce a signature. See .

How can I do this in node?

I'd like to implement something like the two-man rule using elliptic curve cryptography in javascript.

Edit: I'm essentially looking for something like Bitcoin multisig.

So I need to take bine two public keys to get a bined key that requires both private keys to produce a signature. See https://crypto.stackexchange./questions/25250/adding-two-public-keys.

How can I do this in node?

Share Improve this question edited Apr 13, 2017 at 12:48 CommunityBot 11 silver badge asked Jul 4, 2015 at 20:10 Luke BurnsLuke Burns 1,9293 gold badges24 silver badges31 bronze badges 3
  • 2 Something like this: github./wanderer/secp256k1-node but pletely in JS without the C? – Rahat Mahbub Commented Jul 11, 2015 at 7:31
  • Are you trying to do it in the browser or with node? – Breedly Commented Jul 14, 2015 at 0:53
  • Trying to do it in node. – Luke Burns Commented Jul 14, 2015 at 1:11
Add a ment  | 

1 Answer 1

Reset to default 9 +25

Since elliptic curve threshold cryptosystems have the property of adding keys, why not just do that?

I've attempted this using the elliptic module for node.js, just install it with npm and then try the following

var EC = require('elliptic').ec;
// we use the same preset of bitcoin, but should work with the other ones too
var ec = new EC('secp256k1');

// generate two (or more) starting keypairs
var key1 = ec.genKeyPair();
var key2 = ec.genKeyPair();

// sum the public... 
var sum = key1.getPublic().add(key2.getPublic());
// ...and private keys
var psum = key1.getPrivate().add(key2.getPrivate());

Since public keys are Point objects and private keys are BigNumber objects, you can just call the add() function on both of them. At this point, sum and psum hold your bined keys, but before using them to sign a message you'll need to create a KeyPair object (part of the elliptic module).

// generate two new random keypairs
var privateKeySum = ec.genKeyPair();
var publicKeySum = ec.genKeyPair();

// we don't care about their values
// so just import the sum of keys into them
privateKeySum._importPrivate(psum);
publicKeySum._importPublic(sum);

As you can see, to create a new keypair I just make new random ones and then use the _importPrivate() and _importPublic() functions to load the bined keys.

It's a bit hacky, I know, but it works.

A better solution would be to just export the KeyPair object from the module and create new ones with their constructor.

After this, just proceed as normal, like in the sample provided by the module's readme:

var msg = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
// Sign the message with our new bined private key
var signature = privateKeySum.sign(msg);

// Export DER encoded signature in Array
var derSign = signature.toDER();

// Verify signature using the bined public key, should return true
console.log(publicKeySum.verify(msg, derSign));

Using this, after the first generation, you can ask for the two (or more) public keys required to verify a message signature. If you treat the public keys as 'passwords', you can then check a signature against any message to verify that the two public keys are the original ones.

Also, this should work with multiple keys, but it will always require all of them to succeed.

本文标签: javascriptElliptic curve threshold cryptography in nodeStack Overflow