0.0.5 • Published 5 years ago

datum-fuse v0.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

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:

ItemDatum SDK FunctionDescription
Addressdatum.identity.addressThe address of the Datum Identity (hashed public key)
Public Keydatum.getIdentityPublicKey()The Public Key
Encryption Public Keydatum.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
ParameterDescriptionTypeRequired
----
Result
ResponseDescriptionType
walletThe current user's addressString

.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
ParameterDescriptionTypeRequired
keynamesAn array of keys of storage items you would like to check.*[String]
onSubAccountA 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
ResponseDescriptionType
consentA boolean statement on whether the current user has consent with the developerboolean
storageAn 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
ParametersDescriptionTypeRequired
consentTermsA statement defining the consent terms and conditions between the developer and the current userString
dataToUseAn array of data objects to be used[String]
keynameThe key name of the claims that will be madeString
Result
ResponseDescriptionType
storageItemHashThe hash address of the storage item created or sharedString
claimHashThe hash address of the claim createdString
dataAn 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:

ItemDescriptionKey Name
EmailUser's email addressEMAIL
Phone NumberUser'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
ParametersDescriptionTypeRequired
keyThe key of the storage item you would like to getString
Result
ResponseDescriptionType
valueThe 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
ParametersDescriptionTypeRequired
keyThe key of the storage item you would like to setString
valueThe value of the storage item you would like to set?
Result
ResponseDescriptionType
hashThe hash address of the storage itemString

*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.

ItemDescriptionKey Name
EmailUser's email addressEMAIL
Phone NumberUser'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
ParametersDescriptionTypeRequired
keyThe key of the item you would like to be signed by the user of the DAppString
valueThe value of the item you would like to be signed by the user of the DAppString
Result
ResponseDescriptionType
rA random buffer of numbers[UInt8Array]
sA random buffer of numbers[UInt8Array]
vA random numberInteger

.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

ParameterDescriptionTypeRequired
secretProvided that the secret is correct, allows extra functionalities in this function?
Result
ResponseDescriptionType
addressThe address of the user's newly created identityString
publicKeyThe public key of the user's newly created identityString
encryptionKeyThe encryption public key of the user's newly created identityString

.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

ParameterDescriptionTypeRequired
titleThe title of the item you would like to shareString
messageThe message of the item you would like to shareString
Result
ResponseDescriptionType
successA boolean statement that describes whether the share dialog opened or notboolean

More Information