当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript elliptic.ec类代码示例

本文整理汇总了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));
     }
 }
开发者ID:tera-insights,项目名称:tiFormEncrypt,代码行数:16,代码来源:EC.ts

示例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;
};
开发者ID:littycoin,项目名称:thorify,代码行数:13,代码来源:crypto.ts

示例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);
 }
开发者ID:bitpay,项目名称:bitcore,代码行数:14,代码来源:index.ts

示例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')
  })
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:15,代码来源:unitTestsEncryption.ts

示例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
 })
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:6,代码来源:unitTestsEncryption.ts


注:本文中的elliptic.ec类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。