本文整理汇总了TypeScript中elliptic.ec类的典型用法代码示例。如果您正苦于以下问题:TypeScript ec类的具体用法?TypeScript ec怎么用?TypeScript ec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ec类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 recover = function(hash: Buffer, sig: Buffer): string {
const recovery = sig[64];
const signature = {
r: sig.slice(0, 32),
s: sig.slice(32, 64),
};
const ecPublicKey = secp256k1.recoverPubKey(hash, signature, recovery);
const publicKey = "0x" + ecPublicKey.encode("hex", false).slice(2);
const publicHash = EthLib.hash.keccak256(publicKey);
const address = EthLib.account.toChecksum("0x" + publicHash.slice(-40));
return address;
};
示例3: addressFromPublicKeyBuffer
addressFromPublicKeyBuffer(pubKey: Buffer): string {
const ecKey = secp.keyFromPublic(pubKey);
const x = ecKey
.getPublic()
.getX()
.toBuffer();
const y = ecKey
.getPublic()
.getY()
.toBuffer();
const paddedBuffer = Buffer.concat([this.padTo32(x), this.padTo32(y)]);
const address = `0x${pubToAddress(paddedBuffer).toString('hex')}`;
return toChecksumAddress(address);
}
示例4: test
test('bn-padded-to-64-bytes', (t) => {
t.plan(1)
const ecurve = new elliptic.ec('secp256k1')
const evilHexes = ['ba40f85b152bea8c3812da187bcfcfb0dc6e15f9e27cb073633b1c787b19472f',
'e346010f923f768138152d0bad063999ff1da5361a81e6e6f9106241692a0076']
const results = evilHexes.map((hex) => {
const ephemeralSK = ecurve.keyFromPrivate(hex)
const ephemeralPK = ephemeralSK.getPublic()
const sharedSecret = ephemeralSK.derive(ephemeralPK)
return getHexFromBN(sharedSecret).length === 64
})
t.true(results.every(x => x), 'Evil hexes must all generate 64-len hex strings')
})
示例5: 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
})