# datum-fuse

> Facilitate communication between Datum approved Dapps and the Datum Id app

Latest version **0.0.5** (published 2018-12-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install datum-fuse
pnpm add datum-fuse
yarn add datum-fuse
bun add datum-fuse
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2018-12-07 |
| First published | 2018-11-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 327.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Hazlan Rozaimi |
| Maintainers | datumernest |
| Keywords | webpack, es6, starter, library, universal, umd, commonjs |

## Links

- npm: https://www.npmjs.com/package/datum-fuse
- npm.io page: https://npm.io/package/datum-fuse

## Dependencies (2)

- [uuid](https://npm.io/package/uuid.md) ^3.3.2
- [detect-node](https://npm.io/package/detect-node.md) ^2.0.4

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 0.0.5 (latest) — 2018-12-07
- 0.0.4 — 2018-12-05
- 0.0.3 — 2018-11-30
- 0.0.2 — 2018-11-21
- 0.0.1 — 2018-11-21

## README

# Datum Fuse

A tool to connect DApps with Datum ID

## Installation

Install the package with:

```bash
npm install datum-fuse --save
```

## Gettting Started

In order to use this package you must have a Datum Identity that you use as DApp Developer. This Datum Identity allows DApp users to encrypt data so that you, as developer, can decrypt the shared data using your Datum Identity. 
If you don't have a Datum Identity you can create one using the [Datum SDK](https://www.npmjs.com/package/datum-sdk).
Please make sure to initialize Datum SDK's `Datum` object with your keystore and then use the function calls detailed below to get the information required to use Datum Fuse!

You will need the following information to use **Datum Fuse**:


|      Item      |        Datum SDK Function        |Description|
|:--------------:|:--------------------------------:|:----------:|
|     Address    |     `datum.identity.address`     |The address of the Datum Identity (hashed public key)
|   Public Key   |  `datum.getIdentityPublicKey()`  |The Public Key 
| Encryption Public Key | `datum.getEncryptionPublicKey()` |The public key used for encryption purposes, note this is different from above's public key

Once you have the keys above, you can now create a new `Fuse` object in your project and initialize it with the keys.

```ecmascript 6
import Fuse from 'datum-fuse';

const address = '0xcba9e90b9fd0b9f28a7bf1c56c08bd8ec652ceb1';
const publicKey = '4d2709dd4415eaedadde3ca86242c951faa4dea5640d85cd639e7557e98706c118ca2ed20c67a2e898ddfc6776fcb6d8f8e736cf0016cd35e2812e7e7e571cd0';
const encryptionKey = '2e38e730f131992628f8be5c4443fe5b84733747bec841298281d14d9f0b0f15';

const fuse = new Fuse();

fuse.init(publicKey, encryptionKey, address);
```

## Usage

The following methods you can use to request or set via `Fuse`. All these tools are used to communicate via Datum ID to get the current
 user's information. When using `Fuse`, you will be responded back with a `JSON` object containing a root key named `payload`
  with all the response data within it.Please note that all responses from `Fuse` returns a promise, so be sure to resolve the
   promise!

#### `.requestWallet()`

This method is used to get the current user's address. To use this method, you can call it like this:

```ecmascript 6
const userAddress = await fuse.requestWallet();
```

##### Parameters

| Parameter | Description | Type | Required |
|:---------:|:-----------:|:----:|:--------:|
|     -     |      -      |   -  |    -     |

##### Result


| Response |         Description        |   Type   |
|:--------:|:--------------------------:|:--------:|
| `wallet` | The current user's address | `String` |

***

#### `.hasConsent()`

This method is used to check if the current user has a consent claim made with you (the DApp developer), with the given
parameters. To use this method, you can call it like this:

```ecmascript 6
const keynames = ['EMAIL', 'Birthday'];

const consent = await fuse.hasConsent(keynames);
```

##### Parameters

| Parameter | Description | Type | Required|
|:---------:|:-----------:|:----:|:-------:|
|`keynames` |An array of keys of storage items you would like to check.[*]()|   `[String]`  | ✅ |
|`onSubAccount` |A boolean statement that determines if claim is related to user's sub account|   `[String]`  | ❌ |

_*Please note that you can only view data you have been given access. It is highly suggested to only request data you have access to._

##### Result

|  Response |                                    Description                                   |    Type   |
|:---------:|:--------------------------------------------------------------------------------:|:---------:|
| `consent` | A `boolean` statement on whether the current user has consent with the developer | `boolean` |
|`storage`|An array containing information about each data, ordered by the order of the keys in `keynames` parameter.|`[String]`|
***

#### `.requestData()`

This method is used to create consent claims between the user and the DApp developer. On call of this method, Datum ID
will create a storage item for the user and a claim attached to the storage item. This claim will be shared with the user
and the developer. The developer will also have access to the storage item. To use this method, you can call it like this:

```ecmascript 6
const statement = 'I agree to the terms and conditions of this app';
const dataToUse = ['EMAIL'];
const keyname = ['email_claim'];

const call = await fuse.requestData(statement, dataToUse, keyname);
```

##### Parameters

|   Parameters   |                                            Description                                           |    Type    | Required |
|:--------------:|:------------------------------------------------------------------------------------------------:|:----------:|:--------:|
| `consentTerms` | A statement defining the consent terms and conditions between the developer and the current user |  `String`  | ✅ |
|   `dataToUse`  |                                An array of data objects to be used                               | `[String]` | ✅ |
|    `keyname`   |                           The key name of the claims that will be made                           |  `String`  | ✅ |

##### Result


|     Response    |                       Description                      |    Type    |
|:-----------------:|:------------------------------------------------------:|:----------:|
| `storageItemHash` | The hash address of the storage item created or shared |  `String`  |
|    `claimHash`    |          The hash address of the claim created         |  `String`  |
|      `data`       |               An array of request data                 | `[String]` |

Current we as Datum offer the following data objects for DApp developers to use. If you would like to make use of these data,
please feel free to use them by referring them in the `keyname` parameter (within the array). Please check out the table below
to see what kind of data you can use right off the bat:

|     Item     |                   Description                  | Key Name |
|:------------:|:----------------------------------------------:|:--------:|
|     Email    |              User's email address              |  `EMAIL` |
| Phone Number | User's phone number (including the country code) |  `PHONE` |

---

### `.get()`

This method is used to get whatever storage item you have access to. To call this method, you can call it like this:
```ecmascript 6
const key = 'EMAIL';

const get = await fuse.get(key);
```

##### Parameters

|   Parameters   |                 Description                    |    Type    | Required |
|:--------------:|:----------------------------------------:|:----------:|:---:|
| `key` | The key of the storage item you would like to get|  `String`  | ✅ |


##### Result

|     Response    |                       Description                      |    Type    |
|:-----------------:|:------------------------------------------------------:|:----------:|
| `value` | The value of the storage item |  `?`  |

---

### `.set()`

This method is used to set whatever storage item you have access to. Please keep in mind that you are only allowed to
set for all items you have access to **except for** Datum verified items*. To call this method, you can call it like this:

```ecmascript 6
const key = 'COLOR';
const value = 'Green';

const call = await fuse.set(key, value);
```

##### Parameters

|   Parameters   |                 Description                    |    Type    | Required |
|:--------------:|:----------------------------------------:|:----------:|:---:|
| `key` | The key of the storage item you would like to set |  `String`  | ✅ |
| `value` | The value of the storage item you would like to set |  `?`  | ✅ |

##### Result

|     Response    |                       Description                      |    Type    |
|:-----------------:|:------------------------------------------------------:|:----------:|
| `hash` | The hash address of the storage item |  `String`  |


*Please note that if your `key` has the same key name as any of the Datum verified keynames, this will cause this method to
throw an error.

|     Item     |                   Description                  | Key Name |
|:------------:|:----------------------------------------------:|:--------:|
|     Email    |              User's email address              |  `EMAIL` |
| Phone Number | User's phone number (including the country code) |  `PHONE` |

---

### `.signMessage()`

This method is used to sign a given key-value pair declared by the Dapp developer. A signed message will return signed by the
current user's identity. To use this method, you can call it like this:

```ecmascript 6
const key = 'Age';
const value = '30';

const sign = await fuse.signMessage(key, value); 
```

##### Parameters

|   Parameters   |                        Description                            |    Type    | Required|
|:--------------:|:---------------------------------------------------------------:|:----------:|:---:|
|`key`| The key of the item you would like to be signed by the user of the DApp |  `String`  | ✅ |
|`value`| The value of the item you would like to be signed by the user of the DApp |  `String`  | ✅ |

##### Result

|     Response    |              Description         |    Type    |
|:-----------------:|:---------------------:|:----------:|
|`r`| A random buffer of numbers |  `[UInt8Array]`  |
|`s`| A random buffer of numbers |  `[UInt8Array]`  |
|`v`| A random number | `Integer` |

---

### `.newIdentity`

This method is used to assign a new account for the current mobile user. This will generate a new set of public/private
keys for the user that he/she can use. To use this method, you can call it like this:

```ecmascript 6
const newIdentity = await fuse.newIdentity();
```

### Parameters

| Parameter | Description | Type | Required |
|:---------:|:-----------:|:----:|:---:|
|`secret`| _**Provided that the secret is correct**_, allows extra functionalities in this function |`?`| ❌ |

##### Result

|     Response    |              Description         |    Type    |
|:-----------------:|:---------------------:|:----------:|
|`address`| The address of the user's newly created identity |  `String`  |
|`publicKey`| The public key of the user's newly created identity |  `String`  |
|`encryptionKey`| The encryption public key of the user's newly created identity | `String` |

---

### `.share()`

This method is used to open the Share Dialog for both `iOS`|`Android`. To use this method,
you can call it like this:

```ecmascript 6
const title = 'Share Post';
const message = 'Block that chain';

const share = await fuse.share(title, message);
```
### Parameters

| Parameter | Description | Type | Required |
|:---------:|:-----------:|:----:|:---:|
|`title`| The title of the item you would like to share |`String`| ✅ |
|`message`| The message of the item you would like to share |`String`| ✅ |

##### Result

|     Response    |              Description         |    Type    |
|:-----------------:|:---------------------:|:----------:|
|`success`| A boolean statement that describes whether the share dialog opened or not |  `boolean`  |


***
## More Information

 - [Datum SDK](https://github.com/Datum/datum-sdk)
 - [Getting Started with Datum SDK](https://gettingstarted.datum.org/)

---
_Source: https://npm.io/package/datum-fuse · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
