Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BCJS

Hierarchy

  • BCJS

Index

Constructors

constructor

  • The BCJS constructor.

    Parameters

    • Optional authWindowHandler: AuthorizationHandler

      Setting this parameter is not needed in the browser, but is required for NodeJS. This is a function which must submit a device or wallet password to the daemon for use in the next call. See showAuthPopup and the popup for implementation ideas. A function of this type must be specified in the constructor of BCJS in node, but in the browser it is ignored/optional. The call you are expected to make can be found in the source of: https://localhost.bc-vault.com:1991/PasswordInput?channelID=1&channelPasswordType=global

      If the call was not successful, reject the promise. If it was, resolve it with no value.

      The preAuthReference object is passed from the preAuthWindowHandler called previously.

    • Optional preAuthWindowHandler: PreAuthorizationHandler

      This is a function which is called prior to authWindowHandler and prepares it for use. In the browser this function is used to prime a popup window.

      If the call was not successful, reject the promise. If it was, resolve it with a value you expect to be passed to authWindowHandler.

      This function is completely optional and can be left undefined.

    Returns BCJS

Properties

BCData

BCData: BCObject = ...

The current state of the daemon, updated either manually or on device connect/disconnect after calling startObjectPolling

authToken

authToken: string

Get/Set token to be used for device actions

authTokenExpireSeconds

authTokenExpireSeconds: number = 3600

How long each auth grant will last in seconds since the last request.

Optional authTokenMatchPath

authTokenMatchPath: undefined | string = ...

The path to match the auth-token against. This is a security feature and allows you to fine tune access. Default is: undefined (don't check the full path, note: specifying this may require you to allow https://www.w3.org/TR/referrer-policy/#referrer-policy-origin-when-cross-origin on your webpage depending on which browsers you target)

authTokenUseCookies

authTokenUseCookies: boolean = true

Use cookies for session management. If set to false no cookies will be set and the session will be lost when 'authToken' is unloaded. It will need to be manually specified. It will be automatically refreshed if a request fails due to a token error.

isPolling

isPolling: boolean = false

Is BCData object polling already taking place?

logLevel

logLevel: LogLevel = ...

Set Logging verbosity

Methods

AddBCDataChangedListener

CopyWalletToType

  • CopyWalletToType(device: number, oldType: WalletType, newType: WalletType, publicAddress: string): Promise<boolean>
  • Copies a wallet private key to another walletType (in case of a fork etc.)

    Example (es3)

    bc.CopyWalletToType(1,"BitCoin1","BcCash01","1271DpdZ7iM6sXRasvjAQ6Hg2zw8bS3ADc").then(console.log)
    // => "true"
    

    Example (es6 (node and most browsers))

    await bc.CopyWalletToType(1,"BitCoin1","BcCash01","1271DpdZ7iM6sXRasvjAQ6Hg2zw8bS3ADc")
    // => true
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Parameters

    • device: number

      DeviceID obtained from getDevices

    • oldType: WalletType
    • newType: WalletType

      WalletType obtained from getActiveWalletTypes or getSupportedWalletTypes

    • publicAddress: string

      publicAddress obtained from getWalletsOfType

    Returns Promise<boolean>

    true if operation was successful, otherwise will throw

DisplayAddressOnDevice

  • DisplayAddressOnDevice(device: number, type: WalletType, publicAddress: string): Promise<boolean>
  • Displays address on device for verification

    deprecated

    You should not use this function as it is not supported on newer firmwares.

    Example (es3)

    bc.DisplayAddressOnDevice(1,"BitCoin1","1271DpdZ7iM6sXRasvjAQ6Hg2zw8bS3ADc").then(console.log)
    // => "true"
    

    Example (es6 (node and most browsers))

    await bc.DisplayAddressOnDevice(1,"BitCoin1","1271DpdZ7iM6sXRasvjAQ6Hg2zw8bS3ADc")
    // => true
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Parameters

    • device: number

      DeviceID obtained from getDevices

    • type: WalletType

      WalletType obtained from getActiveWalletTypes or getSupportedWalletTypes

    • publicAddress: string

      publicAddress obtained from getWalletsOfType

    Returns Promise<boolean>

    true if display was successful, otherwise will throw

EnterGlobalPin

  • EnterGlobalPin(device: number, passwordType?: PasswordType): Promise<void>
  • Prompt the user to unlock the device

    Example (es3)

    bc.EnterGlobalPin(1).then(console.log)
    

    Example (es6 (node and most browsers))

    await bc.EnterGlobalPin(1)
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Parameters

    • device: number

      DeviceID obtained from getDevices

    • passwordType: PasswordType = ...

    Returns Promise<void>

GenerateTransaction

  • Generates a new transaction on the device

    Example (es3)

    var trxOptions = {from:"1271DpdZ7iM6sXRasvjAQ6Hg2zw8bS3ADc",to:"1271DpdZ7iM6sXRasvjAQ6Hg2zw8bS3ADc",feeCount:0,feePrice:"50000",amount:"500000000"};
    bc.GenerateTransaction(1,"BitCoin1",trxOptions).then(console.log)
    // generates a transaction of type bitCoinCash which uses 0.00050000 BCH as fee and sends 5 BCH back to the same address
    

    Example (es6 (node and most browsers))

    var trxOptions = {from:"1271DpdZ7iM6sXRasvjAQ6Hg2zw8bS3ADc",to:"1271DpdZ7iM6sXRasvjAQ6Hg2zw8bS3ADc",feeCount:0,feePrice:"50000",amount:"500000000"};
    await bc.GenerateTransaction(1,"BitCoin1",trxOptions)
    // generates a transaction of type bitCoinCash which uses 0.00050000 BCH as fee and sends 5 BCH back to the same address
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Parameters

    • device: number

      DeviceID obtained from getDevices

    • type: WalletType

      WalletType obtained from getActiveWalletTypes or getSupportedWalletTypes

    • data: TransactionData

      Transaction data object

    • Optional broadcast: boolean

      Whether to broadcast the transaction to the blockchain automatically

    Returns Promise<string>

    The raw transaction hex prefixed with '0x' if operation was successful, otherwise will throw

GenerateWallet

  • GenerateWallet(device: number, type: WalletType): Promise<string>
  • Generates a new wallet on the device

    Example (es3)

    bc.GenerateWallet(1,"BitCoin1").then(console.log)
    // => "true"
    

    Example (es6 (node and most browsers))

    await bc.GenerateWallet(1,"BitCoin1")
    // => true
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Parameters

    • device: number

      DeviceID obtained from getDevices

    • type: WalletType

      WalletType obtained from getActiveWalletTypes or getSupportedWalletTypes

    Returns Promise<string>

    the public key of the new wallet

SignData

  • SignData(device: number, type: WalletType, publicAddress: string, data: string): Promise<string>
  • Signs data on the device

    Example (es3)

    bc.SignData(1,bc.WalletType.ethereum,"0x9283099a29556fcf8fff5b2cea2d4f67cb7a7a8b","0x4920616d20627574206120737461636b2065786368616e676520706f7374").then(console.log)
    // => "0x..."
    

    Example (es6 (node and most browsers))

    await bc.SignData(1,bc.WalletType.ethereum,"0x9283099a29556fcf8fff5b2cea2d4f67cb7a7a8b","0x4920616d20627574206120737461636b2065786368616e676520706f7374")
    // => "0x..."
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Parameters

    • device: number

      DeviceID obtained from getDevices

    • type: WalletType

      WalletType obtained from getActiveWalletTypes or getSupportedWalletTypes

    • publicAddress: string

      publicAddress obtained from getWalletsOfType

    • data: string

      Message data as a hex string prefixed with 0x

    Returns Promise<string>

    The raw signed message hex prefixed with '0x' if operation was successful, otherwise will throw

getActiveWalletTypes

  • getActiveWalletTypes(device: number): Promise<WalletType[]>
  • Gets a list of WalletTypes that are actually used on a specific device(have at least one wallet)

    Example (es3)

    bc.getActiveWalletTypes(1).then(console.log)
    // => ["BitCoin1","Ethereum"]
    

    Example (es6 (node and most browsers))

    console.log(await bc.getActiveWalletTypes(1))
    // => ["BitCoin1","Ethereum"]
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Parameters

    • device: number

      DeviceID obtained from getDevices

    Returns Promise<WalletType[]>

    An array containing requested data

getAvailableSpace

  • getAvailableSpace(device: number): Promise<SpaceObject>
  • Gets the available space on a specific device

    Example (es3)

    bc.getAvailableSpace(1).then(console.log)
    // => {"available":4294967295,"complete":4294967295}
    

    Example (es6 (node and most browsers))

    console.log(await bc.getAvailableSpace(1))
    // => {"available":4294967295,"complete":4294967295}
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Parameters

    • device: number

      DeviceID obtained from getDevices

    Returns Promise<SpaceObject>

    An object containing requested data, all numbers are in BYTES

getBatchWalletDetails

  • Gets the requested data about wallets stored on the device. Details to query can be specified through the final parameter, which is set to query all details by default. Anything not queried will be filled with the empty value of that type, ie '' for strings and 0 for numbers.

    Example (es3)

    bc.getBatchWalletDetails(1,"BitCoin1").then(console.log)
    // => an array of type WalletBatchDataResponse
    

    Example (es6 (node and most browsers))

    console.log(await bc.getBatchWalletDetails(1,"BitCoin1"))
    // => an array of type WalletBatchDataResponse
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Parameters

    • device: number

      DeviceID obtained from getDevices

    • walletTypes: WalletType[]

      WalletTypes obtained from getActiveWalletTypes or getSupportedWalletTypes

    • walletDetails: WalletDetailsQuery = ...

      Query details flags, can be combined with binary OR

    Returns Promise<WalletBatchDataResponse[]>

    An array containing requested data

getDeviceUID

  • getDeviceUID(device: number): Promise<string>
  • Gets an ID unique to each device. Will not persist device wipes and will change according to the HTTP Origin. This ID will persist reboots and requires global-pin authorization.

    Example (es3)

    bc.getDeviceUID(1).then(console.log)
    // => "0x9d8e1b33b93d7c27fb4fc17857e22fb529937947152ca7af441095949b20ba02"
    

    Example (es6 (node and most browsers))

    console.log(await bc.getDeviceUID(1))
    // => "0x9d8e1b33b93d7c27fb4fc17857e22fb529937947152ca7af441095949b20ba02"
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Parameters

    • device: number

      DeviceID obtained from getDevices

    Returns Promise<string>

    The unique ID

getDevices

  • getDevices(): Promise<number[]>
  • Gets the currently connected devices.

    Example (es3)

    bc.getDevices().then(console.log)
    // => [1,2]
    

    Example (es6 (node and most browsers))

    console.log(await bc.getDevices())
    // => [1,2]
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Returns Promise<number[]>

    An array of Device IDs of currently connected devices

getFirmwareVersion

  • Gets the firmware version of a specific device.

    Example (es3)

    bc.getFirmwareVersion(1).then(console.log)
    // => {"major":1,"minor":0,"revision":1,"date":{"day":17,"month":10,"year":2017},"apiVersion":{"major":1,"minor":0}}
    

    Example (es6 (node and most browsers))

    console.log(await bc.getFirmwareVersion(1))
    // => {"major":1,"minor":0,"revision":1,"date":{"day":17,"month":10,"year":2017},"apiVersion":{"major":1,"minor":0}}
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Parameters

    • device: number

      DeviceID obtained from getDevices

    Returns Promise<VersionObject>

    An object containing requested data

getIsAddressValid

  • getIsAddressValid(device: number, type: WalletType, publicAddress: string): Promise<boolean>
  • Check if address is valid for a specific WalletType

    Example (es3)

    bc.getIsAddressValid(1,"BitCoin1","1271DpdZ7iM6sXRasvjAQ6Hg2zw8bS3ADc").then(console.log)
    // => "true"
    

    Example (es6 (node and most browsers))

    await bc.getIsAddressValid(1,"BitCoin1","1271DpdZ7iM6sXRasvjAQ6Hg2zw8bS3ADc")
    // => true
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Parameters

    • device: number

      DeviceID obtained from getDevices

    • type: WalletType

      WalletType obtained from getActiveWalletTypes or getSupportedWalletTypes

    • publicAddress: string

      publicAddress obtained from getWalletsOfType

    Returns Promise<boolean>

    true if address is valid

getSupportedWalletTypes

  • getSupportedWalletTypes(device: number): Promise<WalletType[]>
  • Gets the supported WalletTypes on a specific device

    Example (es3)

    bc.getSupportedWalletTypes("BitCoin1").then(console.log)
    // => [  "BitCoin1",  "BcCash01",  "Ethereum",  "LiteCoi1",  "Dash0001", ...]
    

    Example (es6 (node and most browsers))

    console.log(await bc.getSupportedWalletTypes(1))
    // => [  "BitCoin1",  "BcCash01",  "Ethereum",  "LiteCoi1",  "Dash0001", ...]
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Parameters

    • device: number

      DeviceID obtained from getDevices

    Returns Promise<WalletType[]>

    An array containing requested data

getWalletBalance

  • getWalletBalance(type: WalletType, sourcePublicID: string): Promise<string>
  • Gets the balance in currency-specific minimum units for the specified wallet from a web-service.

    Example (es3)

    bc.getWalletBalance("BitCoin1","1PekCrsopzENYBa82YpmmBtJcsNgu4PqEV").then(console.log)
    // => {"errorCode": 36864,"data": "0"}
    

    Example (es6 (node and most browsers))

    console.log(await bc.getWalletBalance("BitCoin1","1PekCrsopzENYBa82YpmmBtJcsNgu4PqEV"))
    // => {"errorCode": 36864,"data": "0"}
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Parameters

    Returns Promise<string>

    An object containing requested data

getWalletTypeInfo

  • Returns WalletTypeInfo(name, ticker, etc...) for a specified WalletType if it exists

    Example (es3)

    console.log(JSON.stringify(bc.getWalletTypeInfo(1)));
    // => {"type":"BcCash01","name":"Bitcoin Cash","ticker":"BCH"}
    

    Example (es6 (node and most browsers))

    console.log(JSON.stringify(bc.getWalletTypeInfo(1)));
    // => {"type":"BcCash01","name":"Bitcoin Cash","ticker":"BCH"}
    

    Parameters

    • id: string

    Returns undefined | WalletTypeInfo

getWalletUserData

  • getWalletUserData(device: number, type: WalletType, publicAddress: string, shouldParseHex?: boolean): Promise<string>
  • deprecated

    since 1.3.2, use getBatchWalletDetails instead Gets the user data associated with a publicAddress on this device

    Example (es3)

    bc.getWalletUserData(1,"BitCoin1","1271DpdZ7iM6sXRasvjAQ6Hg2zw8bS3ADc",true).then(console.log)
    // => "This is my mining wallet!"
    

    Example (es6 (node and most browsers))

    console.log(await bc.getWalletUserData(1,"BitCoin1","1271DpdZ7iM6sXRasvjAQ6Hg2zw8bS3ADc",true))
    // => "This is my mining wallet!"
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Parameters

    • device: number

      DeviceID obtained from getDevices

    • type: WalletType

      WalletType obtained from getActiveWalletTypes or getSupportedWalletTypes

    • publicAddress: string

      publicAddress obtained from getWalletsOfType

    • shouldParseHex: boolean = true

    Returns Promise<string>

    The UserData

getWalletsOfType

  • getWalletsOfType(device: number, type: WalletType): Promise<string[]>
  • deprecated

    since 1.3.2, use getBatchWalletDetails instead Gets an array(string) of public keys of a specific WalletTypes on a device

    Example (es5 (old browsers))

    bc.getWalletsOfType(1,"BitCoin1").then(console.log)
    // => ["1271DpdZ7iM6sXRasvjAQ6Hg2zw8bS3ADc"]
    

    Example (es6 (node and most browsers))

    console.log(await bc.getWalletsOfType(1,"BitCoin1"))
    // => ["1271DpdZ7iM6sXRasvjAQ6Hg2zw8bS3ADc"]
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Parameters

    • device: number

      DeviceID obtained from getDevices

    • type: WalletType

      WalletType obtained from getActiveWalletTypes or getSupportedWalletTypes

    Returns Promise<string[]>

    An array containing requested data

startObjectPolling

  • startObjectPolling(deviceInterval?: number): void
  • Starts polling daemon for changes and updates BCData object

    Example (es3)

    bc.startObjectPolling(150);
    //=> bc.BCData will now be updated if the getDevices array changes
    

    Example (es6 (node and most browsers))

    bc.startObjectPolling(150);
    //=> bc.BCData will now be updated if the getDevices array changes
    
    throws

    Will throw "Already polling" if polling is already taking place.

    Parameters

    • deviceInterval: number = 150

      how many milliseconds to wait between getDevices pings to daemon

    Returns void

stopObjectPolling

  • stopObjectPolling(): void
  • Stops polling daemon for changes

    Example (es3)

    bc.startObjectPolling(150);
    bc.stopObjectPolling();
    //=> bc.BCData will now not be updated if the getDevices array changes
    

    Example (es6 (node and most browsers))

    bc.startObjectPolling(150);
    bc.stopObjectPolling();
    //=> bc.BCData will now not be updated if the getDevices array changes
    

    Returns void

triggerManualUpdate

  • triggerManualUpdate(fullUpdate?: boolean): Promise<void>
  • Triggers a manual update to BCData.

    Example (es3)

    console.log(JSON.stringify(bc.BCData));//Old
    bc.triggerManualUpdate().then(function(){
    console.log(JSON.stringify(bc.BCData));//Updated
    });
    

    Example (es6 (node and most browsers))

    console.log(JSON.stringify(bc.BCData));//Old
    await bc.triggerManualUpdate();
    console.log(JSON.stringify(bc.BCData));//Updated
    
    throws

    Will throw a DaemonError if the status code of the request was rejected by the server for any reason

    throws

    Will throw an AxiosError if the request itself failed or if status code != 200

    Parameters

    • fullUpdate: boolean = true

      Force an update or only update data if a new device connects or disconnects.

    Returns Promise<void>

web3_GetAccounts

  • web3_GetAccounts(cb: (err?: any, res?: any) => void): Promise<void>
  • Parameters

    • cb: (err?: any, res?: any) => void
        • (err?: any, res?: any): void
        • Parameters

          • Optional err: any
          • Optional res: any

          Returns void

    Returns Promise<void>

web3_signPersonalMessage

  • web3_signPersonalMessage(msgParams: any, cb: (err?: any, res?: any) => void): Promise<void>
  • Parameters

    • msgParams: any
    • cb: (err?: any, res?: any) => void
        • (err?: any, res?: any): void
        • Parameters

          • Optional err: any
          • Optional res: any

          Returns void

    Returns Promise<void>

web3_signTransaction

  • web3_signTransaction(txParams: any, cb: (err?: any, res?: any) => void): Promise<void>
  • Parameters

    • txParams: any
    • cb: (err?: any, res?: any) => void
        • (err?: any, res?: any): void
        • Parameters

          • Optional err: any
          • Optional res: any

          Returns void

    Returns Promise<void>

Generated using TypeDoc