v6 initial commit, maybe more to follow
This commit is contained in:
parent
7f91be86c0
commit
d6a32870bc
34 changed files with 16875 additions and 0 deletions
24
chain-util.js
Normal file
24
chain-util.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
const EC = require('elliptic').ec;
|
||||
const SHA256 = require('crypto-js/sha256');
|
||||
const uuidV1 = require('uuid/v1');
|
||||
const ec = new EC('secp256k1');
|
||||
|
||||
class ChainUtil {
|
||||
static genKeyPair() {
|
||||
return ec.genKeyPair();
|
||||
}
|
||||
|
||||
static id() {
|
||||
return uuidV1();
|
||||
}
|
||||
|
||||
static hash(data) {
|
||||
return SHA256(JSON.stringify(data)).toString();
|
||||
}
|
||||
|
||||
static verifySignature(publicKey, signature, dataHash) {
|
||||
return ec.keyFromPublic(publicKey, 'hex').verify(dataHash, signature);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ChainUtil;
|
Loading…
Add table
Add a link
Reference in a new issue