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


TypeScript bitcoinjs-lib.crypto类代码示例

本文整理汇总了TypeScript中bitcoinjs-lib.crypto的典型用法代码示例。如果您正苦于以下问题:TypeScript crypto类的具体用法?TypeScript crypto怎么用?TypeScript crypto使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了crypto类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: makeLegacyAuthToken

/**
 * 
 * @param challengeText 
 * @param signerKeyHex 
 * 
 * @ignore
 */
function makeLegacyAuthToken(challengeText: string, signerKeyHex: string): string {
  // only sign specific legacy auth challenges.
  let parsedChallenge
  try {
    parsedChallenge = JSON.parse(challengeText)
  } catch (err) {
    throw new Error('Failed in parsing legacy challenge text from the gaia hub.')
  }
  if (parsedChallenge[0] === 'gaiahub'
      && parsedChallenge[3] === 'blockstack_storage_please_sign') {
    const signer = hexStringToECPair(signerKeyHex
                                     + (signerKeyHex.length === 64 ? '01' : ''))
    const digest = bitcoin.crypto.sha256(Buffer.from(challengeText))

    const signatureBuffer = signer.sign(digest)
    const signatureWithHash = bitcoin.script.signature.encode(
      signatureBuffer, bitcoin.Transaction.SIGHASH_NONE)
    
    // We only want the DER encoding so remove the sighash version byte at the end.
    // See: https://github.com/bitcoinjs/bitcoinjs-lib/issues/1241#issuecomment-428062912
    const signature = signatureWithHash.toString('hex').slice(0, -2)
    
    const publickey = getPublicKeyFromPrivate(signerKeyHex)
    const token = Buffer.from(JSON.stringify(
      { publickey, signature }
    )).toString('base64')
    return token
  } else {
    throw new Error('Failed to connect to legacy gaia hub. If you operate this hub, please update.')
  }
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:38,代码来源:hub.ts

示例2: makeAuthPart

  static makeAuthPart(secretKey: bitcoin.ECPair, challengeText: string) {
    const publickey = secretKey.publicKey.toString('hex')
    const digest = bitcoin.crypto.sha256(Buffer.from(challengeText))
    const signatureBuffer = secretKey.sign(digest)
    const signatureWithHash = bitcoin.script.signature.encode(signatureBuffer, bitcoin.Transaction.SIGHASH_NONE)
    
    // We only want the DER encoding so remove the sighash version byte at the end.
    // See: https://github.com/bitcoinjs/bitcoinjs-lib/issues/1241#issuecomment-428062912
    const signature = signatureWithHash.toString('hex').slice(0, -2)

    const authObj = { publickey, signature }

    return Buffer.from(JSON.stringify(authObj)).toString('base64')
  }
开发者ID:blockstack,项目名称:blockstack-registrar,代码行数:14,代码来源:authentication.ts

示例3: isAuthenticationValid

  isAuthenticationValid(address: string, challengeTexts: Array<string>,
                        options? : {}) { //  eslint-disable-line @typescript-eslint/no-unused-vars
    if (ecPairToAddress(this.publickey) !== address) {
      throw new ValidationError('Address not allowed to write on this path')
    }

    for (const challengeText of challengeTexts) {
      const digest = bitcoin.crypto.sha256(Buffer.from(challengeText))
      const valid = (this.publickey.verify(digest, Buffer.from(this.signature, 'hex')) === true)

      if (valid) {
        return address
      }
    }
    logger.debug(`Failed to validate with challenge text: ${JSON.stringify(challengeTexts)}`)
    throw new ValidationError('Invalid signature or expired authentication token.')
  }
开发者ID:blockstack,项目名称:blockstack-registrar,代码行数:17,代码来源:authentication.ts

示例4: publicKeyToAddress

export function publicKeyToAddress(publicKey: string) {
  const publicKeyBuffer = Buffer.from(publicKey, 'hex')
  const publicKeyHash160 = bcrypto.hash160(publicKeyBuffer)
  const address = baddress.toBase58Check(publicKeyHash160, 0x00)
  return address
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:6,代码来源:keys.ts

示例5: ecPairToAddress

export function ecPairToAddress(keyPair: ECPair) {
  return address.toBase58Check(crypto.hash160(keyPair.publicKey), keyPair.network.pubKeyHash)
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:3,代码来源:utils.ts


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