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

TypeScript jsontokens.SECP256K1Client类代码示例

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

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



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

示例1: signProfileToken

export function signProfileToken(profile: any,
                                 privateKey: string,
                                 subject?: any,
                                 issuer?: any,
                                 signingAlgorithm = 'ES256K',
                                 issuedAt = new Date(),
                                 expiresAt = nextYear()) {
  if (signingAlgorithm !== 'ES256K') {
    throw new Error('Signing algorithm not supported')
  }

  const publicKey = SECP256K1Client.derivePublicKey(privateKey)

  if (!subject) {
    subject = { publicKey }
  }

  if (!issuer) {
    issuer = { publicKey }
  }

  const tokenSigner = new TokenSigner(signingAlgorithm, privateKey)

  const payload = {
    jti: makeUUID4(),
    iat: issuedAt.toISOString(),
    exp: expiresAt.toISOString(),
    subject,
    issuer,
    claim: profile
  }

  return tokenSigner.sign(payload)
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:34,代码来源:profileTokens.ts


示例2: makeCoreSessionRequest

export function makeCoreSessionRequest(appDomain: string,
                                       appMethods: Array<string>,
                                       appPrivateKey: string,
                                       blockchainID: string = null,
                                       thisDevice: string = null) {
  if (thisDevice === null) {
    thisDevice = '.default'
  }

  const appPublicKey = SECP256K1Client.derivePublicKey(appPrivateKey)
  const appPublicKeys = [{
    public_key: appPublicKey,
    device_id: thisDevice
  }]

  const authBody = {
    version: 1,
    blockchain_id: blockchainID,
    app_private_key: appPrivateKey,
    app_domain: appDomain,
    methods: appMethods,
    app_public_keys: appPublicKeys,
    device_id: thisDevice
  }

  // make token
  const tokenSigner = new TokenSigner('ES256k', appPrivateKey)
  const token = tokenSigner.sign(authBody)

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


示例3: makeAuthResponse

export function makeAuthResponse(privateKey: string,
                                 profile: {} = {},
                                 username: string = null,
                                 metadata: AuthMetadata,
                                 coreToken: string = null,
                                 appPrivateKey: string = null,
                                 expiresAt: number = nextMonth().getTime(),
                                 transitPublicKey: string = null,
                                 hubUrl: string = null,
                                 blockstackAPIUrl: string = null,
                                 associationToken: string = null): string {
  /* Convert the private key to a public key to an issuer */
  const publicKey = SECP256K1Client.derivePublicKey(privateKey)
  const address = publicKeyToAddress(publicKey)

  /* See if we should encrypt with the transit key */
  let privateKeyPayload = appPrivateKey
  let coreTokenPayload = coreToken
  let additionalProperties = {}
  if (appPrivateKey !== undefined && appPrivateKey !== null) {
    Logger.info(`blockstack.js: generating v${VERSION} auth response`)
    if (transitPublicKey !== undefined && transitPublicKey !== null) {
      privateKeyPayload = encryptPrivateKey(transitPublicKey, appPrivateKey)
      if (coreToken !== undefined && coreToken !== null) {
        coreTokenPayload = encryptPrivateKey(transitPublicKey, coreToken)
      }
    }
    additionalProperties = {
      email: metadata.email ? metadata.email : null,
      profile_url: metadata.profileUrl ? metadata.profileUrl : null,
      hubUrl,
      blockstackAPIUrl,
      associationToken,
      version: VERSION
    }
  } else {
    Logger.info('blockstack.js: generating legacy auth response')
  }

  /* Create the payload */
  const payload = Object.assign({}, {
    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: makeDIDFromAddress(address),
    private_key: privateKeyPayload,
    public_keys: [publicKey],
    profile,
    username,
    core_token: coreTokenPayload
  }, additionalProperties)

  /* Sign and return the token */
  const tokenSigner = new TokenSigner('ES256k', privateKey)
  return tokenSigner.sign(payload)
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:56,代码来源:authMessages.ts


示例4: 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


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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript jsontokens.TokenSigner类代码示例发布时间:2022-05-25
下一篇:
TypeScript jsontokens.decodeToken函数代码示例发布时间: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