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


TypeScript ECPair.makeRandom方法代码示例

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


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

示例1: makeECPrivateKey

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

示例2:

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

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