當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。