本文整理匯總了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
})