api里有ECDH封装,如何优雅地实现ECDSA?
indutny/elliptic 这个库有人用过吗
正好之前写过,本来打算写一个区块链玩玩,后来实在太懒没坚持下去。 就相对完整实现了钱包,其它都半实现,钱包实现的核心就是这个算法 https://github.com/zy445566/funcoin-core/blob/master/lib/Wallet.js
const ecEncodeName = "secp256k1"; const ec = new require("elliptic").ec(ecEncodeName); /** * sign */ sign(msg,encoding = 'hex') { let buffer = Buffer.from(ec.sign(msg, this.getPrivateKey(), {canonical: true}).toDER()); if (['latin1','base64','hex'].indexOf(encoding)>-1){return buffer.toString(encoding)} return buffer; } /** * verify */ verify(msg,signature,otherPublicKey,signatureEncoding='hex',otherPublicKeyEncoding='hex') { return ec.verify(msg, Buffer.from(signature,signatureEncoding), Buffer.from(otherPublicKey,otherPublicKeyEncoding)); }
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
indutny/elliptic 这个库有人用过吗
正好之前写过,本来打算写一个区块链玩玩,后来实在太懒没坚持下去。 就相对完整实现了钱包,其它都半实现,钱包实现的核心就是这个算法 https://github.com/zy445566/funcoin-core/blob/master/lib/Wallet.js