How to use the @liquality/crypto.sha256 function in @liquality/crypto

To help you get started, we’ve selected a few @liquality/crypto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github liquality / chainabstractionlayer / packages / bitcoin-node-wallet-provider / lib / BitcoinNodeWalletProvider.js View on Github external
async generateSecret (message) {
    const secretAddressLabel = 'secretAddress'
    let address
    try {
      const labelAddresses = await this._rpc.jsonrpc('getaddressesbylabel', secretAddressLabel)
      address = Object.keys(labelAddresses)[0]
    } catch (e) { // Label does not exist
      address = await this.getNewAddress('legacy', secretAddressLabel) // Signing only possible with legacy addresses
    }
    const signedMessage = await this.signMessage(message, address)
    const secret = sha256(signedMessage)
    return secret
  }
}
github liquality / chainabstractionlayer / packages / bitcoin-collateral-provider / lib / BitcoinCollateralProvider.js View on Github external
async multisigSendCollateral (refundableTxHash, seizableTxHash, borrowerPubKey, lenderPubKey, secretHashA1, secretA2, secretHashB2, secretB3, loanExpiration, biddingExpiration, seizureExpiration, borrowerSignatures, lenderSignatures, to) {
    const secretHashA2 = sha256(secretA2)
    const secretHashB3 = sha256(secretB3)

    const refundableScript = this.createRefundableCollateralScript(borrowerPubKey, lenderPubKey, secretHashA2, secretHashB2, secretHashB3, loanExpiration, biddingExpiration)
    const seizableScript = this.createSeizableCollateralScript(borrowerPubKey, lenderPubKey, secretHashA1, secretHashA2, secretHashB2, secretHashB3, loanExpiration, biddingExpiration, seizureExpiration)

    const refundableResult = await this._multisigSendCollateral(refundableTxHash, refundableScript, secretA2, secretB3, loanExpiration, borrowerSignatures.refundableSignature, lenderSignatures.refundableSignature, to)
    const seizableResult = await this._multisigSendCollateral(seizableTxHash, seizableScript, secretA2, secretB3, loanExpiration, borrowerSignatures.seizableSignature, lenderSignatures.seizableSignature, to)

    return { refundableResult, seizableResult }
  }
github liquality / chainabstractionlayer / packages / bitcoin-collateral-provider / lib / BitcoinCollateralProvider.js View on Github external
async multisigSendCollateral (refundableTxHash, seizableTxHash, borrowerPubKey, lenderPubKey, secretHashA1, secretA2, secretHashB2, secretB3, loanExpiration, biddingExpiration, seizureExpiration, borrowerSignatures, lenderSignatures, to) {
    const secretHashA2 = sha256(secretA2)
    const secretHashB3 = sha256(secretB3)

    const refundableScript = this.createRefundableCollateralScript(borrowerPubKey, lenderPubKey, secretHashA2, secretHashB2, secretHashB3, loanExpiration, biddingExpiration)
    const seizableScript = this.createSeizableCollateralScript(borrowerPubKey, lenderPubKey, secretHashA1, secretHashA2, secretHashB2, secretHashB3, loanExpiration, biddingExpiration, seizureExpiration)

    const refundableResult = await this._multisigSendCollateral(refundableTxHash, refundableScript, secretA2, secretB3, loanExpiration, borrowerSignatures.refundableSignature, lenderSignatures.refundableSignature, to)
    const seizableResult = await this._multisigSendCollateral(seizableTxHash, seizableScript, secretA2, secretB3, loanExpiration, borrowerSignatures.seizableSignature, lenderSignatures.seizableSignature, to)

    return { refundableResult, seizableResult }
  }
github liquality / chainabstractionlayer / packages / client / lib / Swap.js View on Github external
async generateSecret (message) {
    try {
      return this.client.getMethod('generateSecret')(message)
    } catch (e) {
      if (!(e instanceof UnimplementedMethodError)) throw e
    }
    const address = (await this.client.getMethod('getAddresses')())[0]
    const signedMessage = await this.client.getMethod('signMessage')(message, address)
    const secret = sha256(signedMessage)
    return secret
  }
github liquality / chainabstractionlayer / packages / bitcoin-collateral-provider / lib / BitcoinCollateralProvider.js View on Github external
async seizeCollateral (seizableTxHash, borrowerPubKey, lenderPubKey, secretA1, secretHashA2, secretHashB2, secretHashB3, loanExpiration, biddingExpiration, seizureExpiration) {
    const secretHashA1 = sha256(secretA1)

    const seizableScript = this.createSeizableCollateralScript(borrowerPubKey, lenderPubKey, secretHashA1, secretHashA2, secretHashB2, secretHashB3, loanExpiration, biddingExpiration, seizureExpiration)

    return this._refundCollateral(seizableTxHash, seizableScript, borrowerPubKey, lenderPubKey, secretA1, secretHashB2, loanExpiration, biddingExpiration, seizureExpiration, true, 'seizurePeriod')
  }
github liquality / chainabstractionlayer / packages / bitcoin-collateral-provider / lib / BitcoinCollateralProvider.js View on Github external
async refundCollateral (refundableTxHash, seizableTxHash, borrowerPubKey, lenderPubKey, secretHashA1, secretHashA2, secretB2, secretHashB3, loanExpiration, biddingExpiration, seizureExpiration) {
    const secretHashB2 = sha256(secretB2)

    const refundableScript = this.createRefundableCollateralScript(borrowerPubKey, lenderPubKey, secretHashA2, secretHashB2, secretHashB3, loanExpiration, biddingExpiration)
    const seizableScript = this.createSeizableCollateralScript(borrowerPubKey, lenderPubKey, secretHashA1, secretHashA2, secretHashB2, secretHashB3, loanExpiration, biddingExpiration, seizureExpiration)

    const refundableResult = await this._refundCollateral(refundableTxHash, refundableScript, borrowerPubKey, lenderPubKey, secretHashA1, secretB2, loanExpiration, biddingExpiration, seizureExpiration, false, 'loanPeriod')
    const seizableResult = await this._refundCollateral(seizableTxHash, seizableScript, borrowerPubKey, lenderPubKey, secretHashA1, secretB2, loanExpiration, biddingExpiration, seizureExpiration, true, 'loanPeriod')

    return { refundableResult, seizableResult }
  }
github liquality / chainabstractionlayer / packages / ethereum-js-wallet-provider / lib / EthereumJsWalletProvider.js View on Github external
async signMessage (message) {
    const derivationPath = this._derivationPath + '0/0'
    const hdKey = await this.hdKey(derivationPath)
    const msgHash = sha256(message)
    const hex = Buffer.from(msgHash, 'hex')

    const { v, r, s } = ethUtil.ecsign(hex, hdKey._privateKey)

    return { v, r: r.toString('hex'), s: s.toString('hex') }
  }

@liquality/crypto

[![Build Status](https://travis-ci.com/liquality/chainabstractionlayer.svg?branch=master)](https://travis-ci.com/liquality/chainabstractionlayer) [![Coverage Status](https://coveralls.io/repos/github/liquality/chainabstractionlayer/badge.svg?branch=master

MIT
Latest version published 3 years ago

Package Health Score

52 / 100
Full package analysis