Datum Fuse
A tool to connect DApps with Datum ID
Installation
Install the package with:
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.
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.
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:
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:
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:
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:
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:
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:
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:
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:
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