-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchain-util.js
35 lines (28 loc) · 839 Bytes
/
chain-util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//elliptic module use to generate key ,unique Hash
//Bitcoin use: secp256k1 algo SEC: is standard of efficient cryptography p for prime and 256 bits Key component to generate curve is a prime number of 256bit
const EC=require('elliptic').ec;
const ec=EC('secp256k1');
const uuidV1=require('uuid/v1');
const SHA256 = require('crypto-js/sha256');
class ChainUtil
{
static genKeyPair()
{
return ec.genKeyPair();
//generate public and private key
}
static id()
{
//generate unique id for transaction
return uuidV1();
}
static hash(data)
{
return SHA256(JSON.stringify(data)).toString();
}
static verifySignatur(publicKey,signatue,dataHash)
{
return ec.keyFromPublic(publicKey,'hex').verify(dataHash,signatue);
}
}
module.exports=ChainUtil;