# Configurations

Developers can develop wallet application using our web sdk. Install the `dcent-web-connector` from npm repository.

```shell
npm install dcent-web-connector
```

Developer can access api through `window.DcentWebConnector` object or `DcentWebConnector` object.

```javascript
const DcentWebConnector = require('dcent-web-connector')
```

### Requirement

* Must have a `D'CENT Biometric wallet`.\
  You can get it at D'CENT website : <https://dcentwallet.com/Shop>
* You need to install the lastest `D'CENT Bridge`.\
  D'CENT Bridge Download : <http://bridge.dcentwallet.com/download>
* D'CENT Biometric will be connected with your PC or Labtop using USB Cable(Micro USB 5-pin type).

## Basic structure

### Functions

All API functions return a `Promise`.\
When function processing is completed, it is resolved. If an error occurs, it is rejected.\
In either case, respond with a JSON object.

### Returned JSON object type

```json
{
    "header": {
        "version": "1.0",
        "request_from": "",
        "status": ""
    },
    "body": {
        "command" : "",
        "parameter" : {}
    }
}
```

### Common Errors

If D'CENT wallet isn't connected via USB, you'll get the following error:

```json
{
    "header": {
        "version": "1.0",
        "request_from": "ethereum",
        "status": "error"
    },
    "body": {
        "command": "transaction",
        "error": {
            "code": "user_cancel",
            "message": "user cancel"
        }
    }
}
```

When executing a function that requires user authentication, an error occurs if the user cancels the authentication. The following shows the user cancel error in the Ethereum signed Transaction.

```json
{
    "header": {
        "version": "1.0",
        "request_from": "dcent-web",
        "status": "error"
    },
    "body": {
        "error": {
            "code": "pop-up_closed",
            "message": "Pop-up windows has been closed"
        }
    }
}
```

If the bridge service popup window is closed while calling a function and waiting, the following error occurs:

```json
{
    "header": {
        "version": "1.0",
        "request_from": "wam",
        "status": "error"
    },
    "body": {
        "error": {
            "code": "no_device",
            "message": "D'CENT Biometric Wallet is not connected"
        }
    }
}
```

## Basic functions

### `DcentWebConnector` initialize

`dcent-web-connector` provides functions for using D'CENT Biometric Wallet.

```javascript
var result
try{
    result = await DcentWebConnector.info()
}catch(e){
    result = e
}
```

`info()` returns :

```json
{
    "header": {
        "version": "1.0",
        "request_from": "",
        "status": ""
    },
    "body": {
        "command" : "",
        "parameter" : {
            "version": "1.0.0",
            "isUsbAttached": "true | false"
        }
    }    
}
```

When the function is called from your web application, if D'CENT Bridge Service is not running as a pop-up, `dcent-web-connector` will automatically open a pop-up window and send a function request

### Set TimeOut Time

```json
  {
    "header": {
      "version": "1.0",
      "response_from": "dcent-web",
      "status": "error"
    },
    "body": {
      "error": {
        "code": "time_out",
        "message": "The function execution time has expired"
      }
    }
  }
```

All functions except setTimeOutMs function are called and then respond with `JSON Object` as below when timeout occurs.

```javascript
  try {
    await dcent.setTimeOutMs(60000) // 60 sec, The default value is 60 seconds.
  } catch (e) {
    console.log(e)    
  }
```

You can set the timeout time by calling `setTimeOutMs ()` as shown below.

Sets the maximum time the function will run. Once set the timeout Time, it is valid until the value is set again. The default value is 60 seconds.

### Close pop-up window

`dcent-web-connector` will automatically open a pop-up window and send a function request. After each request to device is ended, it is recommended to close popup for enhancing user experience.

```javascript
var result
try{
    result = await DcentWebConnector.info()    
}catch(e){
    result = e
}
// close pop-up window of D'CENT Bridge Service
DcentWebConnector.popupWindowClose()
```

### Set Device Connection Listener

Set listener for device connection state. Before processing a functions request, `dcent-web-connector` check the device connection state. If the state is changed, the device connection listener will be called.

```javascript
// device connection listener ( callback )
function connectionListener(state) {
    if (state === DcentWebConnector.state.CONNECTED) {
        console.log('DCENT is Connected');        
    } else if (state === DcentWebConnector.state.DISCONNECTED) {
        console.log('DCENT is Disconnected');  
    }
}
try {
    // set the device connection listener
    DcentWebConnector.setConnectionListener(connectionListener)
} catch(e) {    
}
```

### Address Path

All address path in the API should follow BIP44 rules.

```
m / purpose' / coin_type' / account' / change / address_index
```

### Coin Type

`DcentWebConnector.coinType` is defined in the source code below.

* <https://github.com/DcentWallet/dcent-web-connector/blob/master/src/type/dcent-web-type.js>

## APIs

### Wallet device and accounts info.

{% content-ref url="/pages/BV9L9qY1uRs9BslRCkDc" %}
[Device & Accounts Info.](/dcent-biometric-wallet-for-pc/dcent-web-connector/device-and-accounts-info..md)
{% endcontent-ref %}

### Address & XPUB

You can get an address or XPUB for a specific private key with the APIs below.

{% content-ref url="/pages/SCMgIvFM9O2W2LYiGHRV" %}
[Address & XPUB](/dcent-biometric-wallet-for-pc/dcent-web-connector/address-and-xpub.md)
{% endcontent-ref %}

### Ethereum & EVM compatible network

You can find the APIs to generate signature for Ethereum, EVM compatible network.

{% content-ref url="/pages/tW9YGkUwSMypBX7fGDdl" %}
[Ethereum & EVM compatible](/dcent-biometric-wallet-for-pc/dcent-web-connector/ethereum-and-evm-compatible.md)
{% endcontent-ref %}

### Klaytn

You can find the APIs to generate signature for Klaytn network.

{% content-ref url="/pages/2RiRXnmPLWbE3sf8NAyN" %}
[Klaytn](/dcent-biometric-wallet-for-pc/dcent-web-connector/klaytn.md)
{% endcontent-ref %}

### Bitcoin & Bitcoin compatible network

You can find the APIs to generate signature for Bitcoin and Bitcoin compatible network.

{% content-ref url="/pages/lBWOLtkMXIzkrutNS226" %}
[Bitcoin](/dcent-biometric-wallet-for-pc/dcent-web-connector/bitcoin.md)
{% endcontent-ref %}

### XRPL (XRP Ledger)

You can find the APIs to generate signature for XRPL transactions.

{% content-ref url="/pages/aOn7QfYmcDBgv3NBupA2" %}
[XRPL (XRP Ledger)](/dcent-biometric-wallet-for-pc/dcent-web-connector/xrpl-xrp-ledger.md)
{% endcontent-ref %}

### Hedera (HBAR & HTS)

You can find the APIs to generate signature for Hedera transactions.

{% content-ref url="/pages/YrZ2CNLZawbeeOaMsQRM" %}
[Hedera (HBAR & HTS)](/dcent-biometric-wallet-for-pc/dcent-web-connector/hedera-hbar-and-hts.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev-docs.dcentwallet.com/dcent-biometric-wallet-for-pc/dcent-web-connector/configurations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
