本文整理汇总了TypeScript中elliptic.ec.keyFromPrivate方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ec.keyFromPrivate方法的具体用法?TypeScript ec.keyFromPrivate怎么用?TypeScript ec.keyFromPrivate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elliptic.ec
的用法示例。
在下文中一共展示了ec.keyFromPrivate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
/**
* Passing an external key will import it, otherwise a keypair will
* be generated.
*/
constructor(ext?: string) {
if (ext) {
const keyParts = ext.split("|");
const d = Base64.decode(keyParts[2]);
this.keyPair = elliptic.keyFromPrivate(Buffer.from(d));
} else {
// Generate our own key since we have a good PRNG
const d = new Uint8Array(32);
crypto.getRandomValues(d);
this.keyPair = elliptic.keyFromPrivate(Buffer.from(d));
}
}
示例2: function
export const sign = function(hash: Buffer, privateKey: Buffer): string {
const signature = secp256k1.keyFromPrivate(privateKey).sign(hash, { canonical: true });
return "0x" + Buffer.concat([signature.r.toBuffer(), signature.s.toBuffer(), Buffer.from([signature.recoveryParam])]).toString("hex"); /* tslint:disable:max-line-length */
};
示例3: getHexFromBN
const results = evilHexes.map((hex) => {
const ephemeralSK = ecurve.keyFromPrivate(hex)
const ephemeralPK = ephemeralSK.getPublic()
const sharedSecret = ephemeralSK.derive(ephemeralPK)
return getHexFromBN(sharedSecret).length === 64
})