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


TypeScript blockstack.ecPairToAddress函数代码示例

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


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

示例1: checkAssociationToken

  checkAssociationToken(token: string, bearerAddress: string) {
    // a JWT can have an `associationToken` that was signed by one of the
    // whitelisted addresses on this server.  This method checks a given
    // associationToken and verifies that it authorizes the "outer"
    // JWT's address (`bearerAddress`)

    let associationToken: TokenType
    try {
      associationToken = decodeToken(token)
    } catch (e) {
      throw new ValidationError('Failed to decode association token in JWT')
    }

    // publicKey (the issuer of the association token)
    // will be the whitelisted address (i.e. the identity address)
    const publicKey = associationToken.payload.iss
    const childPublicKey = associationToken.payload.childToAssociate
    const expiresAt = associationToken.payload.exp

    if (! publicKey) {
      throw new ValidationError('Must provide `iss` claim in association JWT.')
    }

    if (! childPublicKey) {
      throw new ValidationError('Must provide `childToAssociate` claim in association JWT.')
    }

    if (! expiresAt) {
      throw new ValidationError('Must provide `exp` claim in association JWT.')
    }

    const verified = new TokenVerifier('ES256K', publicKey).verify(token)
    if (!verified) {
      throw new ValidationError('Failed to verify association JWT: invalid issuer')
    }

    if (expiresAt < (Date.now()/1000)) {
      throw new ValidationError(
        `Expired association token: expire time of ${expiresAt} (secs since epoch)`)
    }

    // the bearer of the association token must have authorized the bearer
    const childAddress = ecPairToAddress(pubkeyHexToECPair(childPublicKey))
    if (childAddress !== bearerAddress) {
      throw new ValidationError(
        `Association token child key ${childPublicKey} does not match ${bearerAddress}`)
    }

    const signerAddress = ecPairToAddress(pubkeyHexToECPair(publicKey))
    return signerAddress

  }
开发者ID:blockstack,项目名称:blockstack-registrar,代码行数:52,代码来源:authentication.ts

示例2: test

  test('handle request', (t) => {
    let fetch = FetchMock.sandbox()
    let { app, server } = makeHttpServer(config)
    server.authTimestampCache = new MockAuthTimestampCache()
    let sk = testPairs[1]
    let fileContents = sk.toWIF()
    let blob = Buffer.from(fileContents)

    let address = ecPairToAddress(sk)
    let path = `/store/${address}/helloWorld`
    let listPath = `/list-files/${address}`
    let prefix = ''
    let authorizationHeader = ''

    request(app).get('/hub_info/')
      .expect(200)
      .then((response) => {
        prefix = JSON.parse(response.text).read_url_prefix
        const challenge = JSON.parse(response.text).challenge_text
        const authPart = auth.V1Authentication.makeAuthPart(sk, challenge)
        return `bearer ${authPart}`
      })
      .then((authorization) => {
        authorizationHeader = authorization
        return request(app).post(path)
            .set('Content-Type', 'application/octet-stream')
            .set('Authorization', authorization)
            .send(blob)
            .expect(202)
      })
      .then((response) => {
        if (mockTest) {
          addMockFetches(fetch, prefix, dataMap)
        }

        let url = JSON.parse(response.text).publicURL
        t.ok(url, 'Must return URL')
        console.log(url)
        fetch(url)
          .then(resp => resp.text())
          .then(text => t.equal(text, fileContents, 'Contents returned must be correct'))
      })
      .catch((err: any) => t.false(true, `Unexpected err: ${err}`))
      .then(() => request(app).post(listPath)
            .set('Content-Type', 'application/json')
            .set('Authorization', authorizationHeader)
            .expect(202)
      )
      .then((filesResponse) => {
        const files = JSON.parse(filesResponse.text)
        t.equal(files.entries.length, 1, 'Should return one file')
        t.equal(files.entries[0], 'helloWorld', 'Should be helloworld')
        t.ok(files.hasOwnProperty('page'), 'Response is missing a page')
      })
      .then(() => {
        fetch.restore()
        t.end()
      })
  })
开发者ID:blockstack,项目名称:blockstack-registrar,代码行数:59,代码来源:testHttp.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: ecPairToAddress

 const testAddrs: string[] = testPairs.map(x => ecPairToAddress(x));
开发者ID:blockstack,项目名称:blockstack-registrar,代码行数:1,代码来源:common.ts


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