• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript bitcoinjs-lib.ECPair类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: verifyProfileToken

export function verifyProfileToken(token: string, publicKeyOrAddress: string) {
  const decodedToken = decodeToken(token)
  const payload = decodedToken.payload

  // Inspect and verify the subject
  if (payload.hasOwnProperty('subject')) {
    if (!payload.subject.hasOwnProperty('publicKey')) {
      throw new Error('Token doesn\'t have a subject public key')
    }
  } else {
    throw new Error('Token doesn\'t have a subject')
  }

  // Inspect and verify the issuer
  if (payload.hasOwnProperty('issuer')) {
    if (!payload.issuer.hasOwnProperty('publicKey')) {
      throw new Error('Token doesn\'t have an issuer public key')
    }
  } else {
    throw new Error('Token doesn\'t have an issuer')
  }

  // Inspect and verify the claim
  if (!payload.hasOwnProperty('claim')) {
    throw new Error('Token doesn\'t have a claim')
  }

  const issuerPublicKey = payload.issuer.publicKey
  const publicKeyBuffer = Buffer.from(issuerPublicKey, 'hex')

  const compressedKeyPair =  ECPair.fromPublicKey(publicKeyBuffer, { compressed: true })
  const compressedAddress = ecPairToAddress(compressedKeyPair)
  const uncompressedKeyPair = ECPair.fromPublicKey(publicKeyBuffer, { compressed: false })
  const uncompressedAddress = ecPairToAddress(uncompressedKeyPair)

  if (publicKeyOrAddress === issuerPublicKey) {
    // pass
  } else if (publicKeyOrAddress === compressedAddress) {
    // pass
  } else if (publicKeyOrAddress === uncompressedAddress) {
    // pass
  } else {
    throw new Error('Token issuer public key does not match the verifying value')
  }

  const tokenVerifier = new TokenVerifier(decodedToken.header.alg, issuerPublicKey)
  if (!tokenVerifier) {
    throw new Error('Invalid token verifier')
  }

  const tokenVerified = tokenVerifier.verify(token)
  if (!tokenVerified) {
    throw new Error('Token verification failed')
  }

  return decodedToken
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:57,代码来源:profileTokens.ts


示例2: hexStringToECPair

export function hexStringToECPair(skHex: string) {
  const ecPairOptions = {
    network: config.network.layer1,
    compressed: true
  }

  if (skHex.length === 66) {
    if (skHex.slice(64) !== '01') {
      throw new Error('Improperly formatted private-key hex string. 66-length hex usually '
                      + 'indicates compressed key, but last byte must be == 1')
    }
    return ECPair.fromPrivateKey(Buffer.from(skHex.slice(0, 64), 'hex'), ecPairOptions)
  } else if (skHex.length === 64) {
    ecPairOptions.compressed = false
    return ECPair.fromPrivateKey(Buffer.from(skHex, 'hex'), ecPairOptions)
  } else {
    throw new Error('Improperly formatted private-key hex string: length should be 64 or 66.')
  }
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:19,代码来源:utils.ts


示例3: getBucketUrl

export async function getBucketUrl(gaiaHubUrl: string, appPrivateKey: string): Promise<string> {
  const challengeSigner = bitcoin.ECPair.fromPrivateKey(Buffer.from(appPrivateKey, 'hex'))
  const response = await fetch(`${gaiaHubUrl}/hub_info`)
  const responseText = await response.text()
  const responseJSON = JSON.parse(responseText)
  const readURL = responseJSON.read_url_prefix
  const address = ecPairToAddress(challengeSigner)
  const bucketUrl = `${readURL}${address}/`
  return bucketUrl
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:10,代码来源:hub.ts


示例4: pubkeyHexToECPair

function pubkeyHexToECPair (pubkeyHex: string) {
  const pkBuff = Buffer.from(pubkeyHex, 'hex')
  return bitcoin.ECPair.fromPublicKey(pkBuff)
}
开发者ID:blockstack,项目名称:blockstack-registrar,代码行数:4,代码来源:authentication.ts


示例5: getNodePrivateKey

/**
 * 
 * @ignore
 */
function getNodePrivateKey(node: BIP32): string {
  return ecPairToHexString(ECPair.fromPrivateKey(node.privateKey))
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:7,代码来源:wallet.ts


示例6:

 const testPairs: ECPair[] = [...Array(count)].map(_ => ECPair.makeRandom());
开发者ID:blockstack,项目名称:blockstack-registrar,代码行数:1,代码来源:common.ts


示例7: getPublicKeyFromPrivate

export function getPublicKeyFromPrivate(privateKey: string) {
  const keyPair = ECPair.fromPrivateKey(Buffer.from(privateKey, 'hex'))
  return keyPair.publicKey.toString('hex')
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:4,代码来源:keys.ts


示例8: makeECPrivateKey

export function makeECPrivateKey() {
  const keyPair = ECPair.makeRandom({ rng: getEntropy })
  return keyPair.privateKey.toString('hex')
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:4,代码来源:keys.ts


示例9: testSchemas

function testSchemas() {
  const keyPair = ECPair.makeRandom({ rng: getEntropy })
  const privateKey = keyPair.privateKey.toString('hex')
  const publicKey = keyPair.publicKey.toString('hex')

  test('Profile', (t) => {
    t.plan(5)

    const profileObject = new Profile(sampleProfiles.naval)
    t.ok(profileObject, 'Profile object should have been created')

    const validationResults = Profile.validateSchema(sampleProfiles.naval)
    t.ok(validationResults.valid, 'Profile should be valid')

    const profileJson = profileObject.toJSON()
    t.ok(profileJson, 'Profile JSON should have been created')

    const tokenRecords = profileObject.toToken(privateKey)
    t.ok(tokenRecords, 'Profile tokens should have been created')

    const profileObject2 = Profile.fromToken(tokenRecords, publicKey)
    t.ok(profileObject2, 'Profile should have been reconstructed from tokens')
  })

  test('Person', (t) => {
    t.plan(18)

    const personObject = new Person(sampleProfiles.naval)
    t.ok(personObject, 'Person object should have been created')

    const validationResults = Person.validateSchema(sampleProfiles.naval, true)
    t.ok(validationResults.valid, 'Person profile should be valid')

    const token = personObject.toToken(privateKey)
    const tokenRecords = [wrapProfileToken(token)]
    t.ok(tokenRecords, 'Person profile tokens should have been created')

    const profileObject2 = Person.fromToken(tokenRecords[0].token, publicKey)
    t.ok(profileObject2, 'Person profile should have been reconstructed from tokens')

    const name = personObject.name()
    t.ok(name, 'Name should have been returned')
    t.equal(name, 'Naval Ravikant', 'Name should match the expected value')

    const givenName = personObject.givenName()
    t.ok(givenName, 'Given name should have been returned')
    t.equal(givenName, 'Naval', 'Given name should match the expected value')

    const familyName = personObject.familyName()
    t.ok(familyName, 'Family name should have been returned')
    t.equal(familyName, 'Ravikant', 'Family name should match the expected value')

    const description = personObject.description()
    t.ok(description, 'Avatar URL should have been returned')

    const avatarUrl = personObject.avatarUrl()
    t.ok(avatarUrl, 'Avatar URL should have been returned')

    const verifiedAccounts = personObject.verifiedAccounts([])
    t.ok(verifiedAccounts, 'Verified accounts should have been returned')
    t.equal(verifiedAccounts.length, 0, 'Verified accounts should match the expected value')

    const address = personObject.address()
    t.ok(address, 'Address should have been returned')

    const birthDate = personObject.birthDate()
    t.ok(birthDate, 'Birth date should have been returned')

    const connections = personObject.connections()
    t.ok(connections, 'Connections should have been returned')

    const organizations = personObject.organizations()
    t.ok(organizations, 'Organizations should have been returned')
  })

  test('legacyFormat', (t) => {
    t.plan(3)

    const profileObject = Person.fromLegacyFormat(sampleProfiles.navalLegacy)
    t.ok(profileObject, 'Profile object should have been created from legacy formatted profile')

    const validationResults = Person.validateSchema(profileObject.toJSON(), true)
    t.ok(validationResults, 'Profile should be in a valid format')

    t.deepEqual(profileObject.toJSON(),
                sampleProfiles.navalLegacyConvert,
                'Parsed Legacy profile should match expectations.')
  })

  test('resolveZoneFileToPerson', (t) => {
    t.plan(2)

    const zoneFile = '$ORIGIN ryan.id\n$TTL 3600\n_http._tcp IN URI 10 1 "https://blockstack.s3.amazonaws.com/ryan.id"\n'
    const ownerAddress = '19MoWG8u88L6t766j7Vne21Mg4wHsCQ7vk'
    FetchMock.get(sampleTokenFiles.ryan.url, sampleTokenFiles.ryan.body)

    resolveZoneFileToPerson(zoneFile, ownerAddress, (profile) => {
      t.ok(profile, 'Profile was extracted')
      t.equal(profile.name,
              'Ryan Shea', 'The profile was recovered with the expected value of the name field')
//.........这里部分代码省略.........
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:101,代码来源:unitTestsProfiles.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript bitcoinjs-lib.address类代码示例发布时间:2022-05-25
下一篇:
TypeScript bitauth.sign函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap