Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface IWalletProvider

Hierarchy

  • IWalletProvider

Index

Methods

addRedeemScript

  • addRedeemScript(redeemScript: string, dAppId?: undefined | string): Promise<void>
  • Adds the redeem script into the wallet.

    Example

    await provider.addRedeemScript(
      "03424f587e064249..."
    )

    Parameters

    • redeemScript: string

      The redeem script you want to add.

    • Optional dAppId: undefined | string

      The DApp ID. If no dAppId is set the default DApp ID will be set.

    Returns Promise<void>

createSignedTx

  • createSignedTx(outputs: Output[], dAppId?: undefined | string): Promise<string>
  • Create a signed transaction with specified outputs. The provider will not add any outputs.

    Example

    const txid = await provider.advancedSend([
      {
        lockScript: "76a91467b2e55ada06c869547e93288a4cf7377211f1f088ac",
        amount: 10000
      }
    ])
    console.log(txid)
    > "9591fdf10b16d4de6f65bcc49aadadc21d7a3a9169a13815e59011b426fe494f"

    Parameters

    • outputs: Output[]

      The Array of TransactionOutput objects.

    • Optional dAppId: undefined | string

      The DApp ID. If no dAppId is set the default DApp ID will be set.

    Returns Promise<string>

    The signed raw transaction in serialized transaction format encoded as hex. The provider should throw an error when the transaction is not generated.

getAddressIndex

  • getAddressIndex(change: number, dAppId?: undefined | string): Promise<number>
  • Returns the current wallet address index.

    Example

    const addrIdx = await provider.getAddressIndex(
      1,
      "53212266f7994100e442f6dff10fbdb50a93121d25c196ce0597517d35d42e68"
    )
    console.log(addrIdx)
    > 3

    Parameters

    • change: number

      The BIP44 change path.

    • Optional dAppId: undefined | string

      The DApp ID. If no dAppId is set the default DApp ID will be set.

    Returns Promise<number>

    The current wallet address index.

getAddresses

  • getAddresses(changeType: number, size: number, startIndex?: undefined | number, dAppId?: undefined | string): Promise<string[]>
  • Returns the wallet address list. Address format is CashAddr.

    Example

    const addresses = await provider.getAddresses(
      0,
      2,
      3,
      "53212266f7994100e442f6dff10fbdb50a93121d25c196ce0597517d35d42e68"
    )
    console.log(addresses)
    > ["bitcoincash:qrsy0xwugcajsqa...", "bitcoincash:qrsfpepw3egqq4k..."]

    Parameters

    • changeType: number
    • size: number

      The number of addresses you want.

    • Optional startIndex: undefined | number

      The BIP44 address_index path.

    • Optional dAppId: undefined | string

      The DApp ID. If no dAppId is set the default DApp ID will be set.

    Returns Promise<string[]>

    The wallet address list.

getFeePerByte

  • getFeePerByte(): Promise<number>
  • Returns the transaction fee per byte.

    Example

    const fee = await provider.getFeePerByte()
    console.log(fee)
    > 1

    Returns Promise<number>

    Transaction fee per byte in satoshi.

getNetworkMagic

  • getNetworkMagic(): Promise<number>
  • Returns the current network.

    Example

    const network = await provider.getNetwork()
    console.log(network)
    > 3823236072

    Returns Promise<number>

    Network magic bytes

getProtocolVersion

  • getProtocolVersion(): Promise<number>
  • Returns the bitcoin protocol version.

    Example

    const version = await provider.getProtocolVersion()
    console.log(version)
    > 70015

    Returns Promise<number>

    The protocol version.

getRedeemScripts

  • getRedeemScripts(dAppId?: undefined | string): Promise<string[]>
  • Returns the stored redeem scripts related to the DApp ID.

    Example

    const redeemScripts = await provider.getRedeemScripts(
      "53212266f7994100e442f6dff10fbdb50a93121d25c196ce0597517d35d42e68"
    )
    console.log(redeemScripts)
    > ["03424f587e06424954424f5887", "789787a72c21452a1c98ff"]

    Parameters

    • Optional dAppId: undefined | string

      The DApp ID. If no dAppId is set the default DApp ID will be set.

    Returns Promise<string[]>

    The list of redeem scripts stored.

getSpendableUtxos

  • getSpendableUtxos(dAppId?: undefined | string): Promise<Utxo[]>
  • Returns the transaction outputs which addresses are spendable.

    Example

    const utxos = await provider.getSpendableUtxos(
      "53212266f7994100e442f6dff10fbdb50a93121d25c196ce0597517d35d42e68"
    )
    console.log(utxos)
    > [
        {
          'txId' : '115e8f72f39fad874cfab0deed11a80f24f967a84079fb56ddf53ea02e308986',
          'outputIndex' : 0,
          'address' : 'bitcoincash:qrsy0xwugcajsqa99c9nf05pz7ndckj55ctlsztu2p',
          'script' : '76a91447862fe165e6121af80d5dde1ecb478ed170565b88ac',
          'satoshis' : 50000
        }
      ]

    Parameters

    • Optional dAppId: undefined | string

      The DApp ID.

    Returns Promise<Utxo[]>

    The unspent transaction output object list.

getUnspendableUtxos

  • getUnspendableUtxos(dAppId: string): Promise<Utxo[]>
  • Returns the unspent transaction outputs belonging to the DApp which addresses are unspendable.

    Example

    const utxos = await provider.getUnspendableUtxos(
      "53212266f7994100e442f6dff10fbdb50a93121d25c196ce0597517d35d42e68"
    )
    console.log(utxos)
    > [
        {
          'txId' : '115e8f72f39fad874cfab0deed11a80f24f967a84079fb56ddf53ea02e308986',
          'outputIndex' : 0,
          'address' : 'bitcoincash:qrsy0xwugcajsqa99c9nf05pz7ndckj55ctlsztu2p',
          'script' : '76a91447862fe165e6121af80d5dde1ecb478ed170565b88ac',
          'satoshis' : 50000
        }
      ]

    Parameters

    • dAppId: string

      The DApp ID.

    Returns Promise<Utxo[]>

    The unspent transaction output object list. If the addresses of the DApp are spendable, returns an empty array.

getVersion

  • getVersion(): Promise<string>
  • Returns the current provider interface version.

    Example

    const version = await provider.getVersion()
    console.log(version)
    > "0.0.1"

    Returns Promise<string>

    The current provider interface version

sign

  • sign(address: string, dataToSign: string): Promise<string>
  • Signs a message with the private key of an address.

    Example

    const result = await provider.sign(
      "bchtest:qq28xgrzkdyeg5vf7tp2s3mvx8u95zes5cf7wpwgux",
      "af4c61ddcc5e8a2d..." // second argument is SHA1("hello")
    )
    console.log(result)
    > "30440220227e0973..."

    Parameters

    • address: string

      A P2PKH address whose private key belongs to the provider.

    • dataToSign: string

      Data to sign in hex format.

    Returns Promise<string>

    The signed data. Bitcoin signatures are serialized in the DER format over the wire. The provider should throw an error when

    • private key for the address is missing
    • the user does not allow to sign
    • etc...

Generated using TypeDoc