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


TypeScript SECP256K1Client.derivePublicKey方法代码示例

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


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

示例1: test

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

    const entropy = getEntropy(32)
    t.ok(entropy, 'Entropy should have been created')

    const privateKey = makeECPrivateKey()
    t.ok(privateKey, 'Private key should have been created')
    t.equal(typeof privateKey, 'string', 'Private key should be a string')

    const publicKey = SECP256K1Client.derivePublicKey(privateKey)

    const address = publicKeyToAddress(publicKey)
    t.ok(address, 'Address should have been created')
    t.equal(typeof address, 'string', 'Address should be a string')
  })
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:16,代码来源:unitTestsUtils.ts

示例2: makeAuthRequest

export function makeAuthRequest(
  transitPrivateKey?: string,
  redirectURI?: string, 
  manifestURI?: string, 
  scopes: string[] = DEFAULT_SCOPE,
  appDomain?: string,
  expiresAt: number = nextMonth().getTime(),
  extraParams: any = {}
): string {
  if (!transitPrivateKey) {
    transitPrivateKey = new UserSession().generateAndStoreTransitKey()
  }

  const getWindowOrigin = (paramName: string) => {
    const origin = typeof window !== 'undefined' && window.location && window.location.origin
    if (!origin) {
      const errMsg = `\`makeAuthRequest\` called without the \`${paramName}\` param specified but`
        + ' the default value uses `window.location.origin` which is not available in this environment'
      Logger.error(errMsg)
      throw new Error(errMsg)
    }
    return origin
  }
  
  if (!redirectURI) {
    redirectURI = `${getWindowOrigin('redirectURI')}/`
  }
  if (!manifestURI) {
    manifestURI = `${getWindowOrigin('manifestURI')}/manifest.json`
  }
  if (!appDomain) {
    appDomain = getWindowOrigin('appDomain')
  }

  /* Create the payload */
  const payload = Object.assign({}, extraParams, {
    jti: makeUUID4(),
    iat: Math.floor(new Date().getTime() / 1000), // JWT times are in seconds
    exp: Math.floor(expiresAt / 1000), // JWT times are in seconds
    iss: null,
    public_keys: [],
    domain_name: appDomain,
    manifest_uri: manifestURI,
    redirect_uri: redirectURI,
    version: VERSION,
    do_not_include_profile: true,
    supports_hub_url: true,
    scopes
  })

  Logger.info(`blockstack.js: generating v${VERSION} auth request`)

  /* Convert the private key to a public key to an issuer */
  const publicKey = SECP256K1Client.derivePublicKey(transitPrivateKey)
  payload.public_keys = [publicKey]
  const address = publicKeyToAddress(publicKey)
  payload.iss = makeDIDFromAddress(address)

  /* Sign and return the token */
  const tokenSigner = new TokenSigner('ES256k', transitPrivateKey)
  const token = tokenSigner.sign(payload)

  return token
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:64,代码来源:authMessages.ts


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