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


TypeScript secp256k1.publicKeyCreate方法代码示例

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


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

示例1: getAddressFromPrivateKey

  /**
   * get the public address of an account using its private key
   * @param {string} privateKey - the private key of the account
   * @returns {string} public address of the account
   */
  getAddressFromPrivateKey(privateKey): string {
    if (typeof(privateKey) == 'string') privateKey = new Buffer(privateKey, 'hex')

    let pubKey = secp256k1.publicKeyCreate(privateKey, true)
    let pubKeyHash = sha256.digest(pubKey) // sha256 hash of the public key
    let address = pubKeyHash.toString('hex', 12) // rightmost 160 bits/20 bytes of the hash

    return address
  }
开发者ID:JohanSweden,项目名称:Zilliqa-Wallet,代码行数:14,代码来源:zilliqa.service.ts

示例2: sendPayment

  /**
   * create a new transaction
   * @param {Object} payment - the details of the transaction
   * @param {string} payment.to - address to which transaction is sent to
   * @param {number} payment.amount - number of zils sent
   * @param {number} payment.gasPrice - gas price for this transaction
   * @param {number} payment.gasLimit - gas limit for this transaction
   * @returns {Promise} Promise object containing the newly created transaction id
   */
  sendPayment(payment: any): Promise<any> {
    this.startLoading()
    var deferred = new $.Deferred()

    let pubKey = secp256k1.publicKeyCreate(new Buffer(this.userWallet.privateKey, 'hex'), true)

    let txn = {
      version: 0,
      nonce: this.userWallet.nonce + 1,
      to: payment.address,
      amount: payment.amount,
      pubKey: pubKey.toString('hex'),
      gasPrice: payment.gasPrice,
      gasLimit: payment.gasLimit
    }

    var msg = this.intToByteArray(txn.version, 8).join('') +
              this.intToByteArray(txn.nonce, 64).join('') +
              txn.to +
              txn.pubKey +
              this.intToByteArray(txn.amount, 64).join('')

    let sig = this.zlib.schnorr.sign(new Buffer(msg, 'hex'), new Buffer(this.userWallet.privateKey, 'hex'), pubKey)
    let r = sig.r.toString('hex')
    let s = sig.s.toString('hex')
    while (r.length < 64) {
      r = '0' + r
    }
    while (s.length < 64) {
      s = '0' + s
    }
    txn['signature'] = r + s

    let that = this
    this.node.createTransaction(txn, function(err, data) {
      if (err || data.error) {
        deferred.reject(err)
      } else {
        deferred.resolve({
          txId: data.result
        })
      }
      that.endLoading()
    })

    return deferred.promise()
  }
开发者ID:JohanSweden,项目名称:Zilliqa-Wallet,代码行数:56,代码来源:zilliqa.service.ts


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