Profile

Class Name Profile
Extends Logger
Source profile.ts
Examples profile.spec.ts

A users profile is its personal storage for - contacts - encryption keys exchanged with contacts - an own public key for exchanging keys with new contacts - bookmarked ÐAPPs - created contracts

This data is stored as an IPLD Graphs per type and stored in a users profile contract. These graphs are independant from each other and have to be saved separately.

This contract is a DataContract and can be created via the factory at profile.factory.evan and looked up at the global profile index profile.evan. The creation process and landmap looks like this:

https://user-images.githubusercontent.com/1394421/38298221-1938d006-37f7-11e8-9a84-abfd311c97f0.png

Basic Usage

// the bookmark we want to store
const sampleDesc = {
  title: 'sampleTest',
  description: 'desc',
  img: 'img',
  primaryColor: '#FFFFFF',
};

// create new profile, set private key and keyexchange partial key
await profile.createProfile(keyExchange.getDiffieHellmanKeys());

// add a bookmark
await profile.addDappBookmark('sample1.test', sampleDesc);

// store tree to contract
await profile.storeForAccount(profile.treeLabels.bookmarkedDapps);

constructor

new Profile(options);

Creates a new Profile instance.

Parameters

  1. options - ProfileOptions: options for Profile constructor
    • accountId - string: account, that is the profile owner
    • contractLoader - ContractLoader: ContractLoader instance
    • dataContract - DataContract: DataContract instance
    • executor - Executor: Executor instance
    • ipld - Ipld: Ipld instance
    • nameResolver - NameResolver: NameResolver instance
    • defaultCryptoAlgo - string (optional): crypto algorith name from CryptoProvider, defaults to aes
    • log - Function (optional): function to use for logging: (message, level) => {...}
    • logLevel - LogLevel (optional): messages with this level will be logged with log
    • logLog - LogLogInterface (optional): container for collecting log messages
    • logLogLevel - LogLevel (optional): messages with this level will be pushed to logLog
    • trees - object (optional): precached profile data, defaults to {}

Returns

Profile instance

Example

const profile = new Profile({
  accountId: accounts[0],
  contractLoader,
  dataContract,
  executor,
  ipld,
  nameResolver,
});

createProfile

profile.createProfile(keys)

Create new profile, store it to profile index initialize addressBook and publicKey.

Parameters

  1. keys - any: diffie hell man keys for account, created by KeyExchange
    • privateKey - Buffer: private key for key exchange
    • publicKey - Buffer: combination of shared secret and own private key

Returns

Promise returns void: resolved when done

Example

await profile.createProfile(keyExchange.getDiffieHellmanKeys());

exists

profile.exists();

Check if a profile has been stored for current account.

Parameters

  1. options - object: The options used for calling

Returns

Promise returns void: true if a contract was registered, false if not

Example

console.log(await profile.exists());
// Output:
// true

getContactKnownState

profile.getContactKnownState(accountId);

Check, known state for given account.

Parameters

  1. accountId - string: account id of a contact

Returns

Promise returns void: true if known account

Example

  console.log(await profile.getContactKnownState(accountId));
// Output:
// true

setContactKnownState

profile.setContactKnownState(accountId, contactKnown);

Store given state for this account.

Parameters

  1. accountId - string: account id of a contact
  2. contactKnown - boolean: true if known, false if not

Returns

Promise returns void: resolved when done

Example

// mark accountId as a known contact
profile.setContactKnownState(accountId, true);

loadForAccount

profile.loadForAccount([tree]);

Load profile for given account from global profile contract, if a tree is given, load that tree from ipld as well.

Parameters

  1. tree - string (optional): tree to load (‘bookmarkedDapps’, ‘contracts’, …), profile.treeLabels properties can be passed as arguments

Returns

Promise returns void: resolved when done

Example

await profile.loadForAccount(profile.treeLabels.contracts);

storeForAccount

profile.storeForAccount(tree);

Stores profile tree or given hash to global profile contract.

Parameters

  1. tree - string: tree to store (‘bookmarkedDapps’, ‘contracts’, …)
  2. ipldHash - string (optional): store this hash instead of the current tree for account

Returns

Promise returns void: resolved when done

Example

await profile.storeForAccount(profile.treeLabels.contracts);

loadFromIpld

profile.loadFromIpld(tree, ipldIpfsHash);

Load profile from ipfs via ipld dag via ipfs file hash.

Parameters

  1. tree - string: tree to load (‘bookmarkedDapps’, ‘contracts’, …)
  2. ipldIpfsHash - string: ipfs file hash that points to a file with ipld a hash

Returns

Promise returns Profile: this profile

Example

await profile.loadFromIpld(profile.treeLabels.contracts, ipldIpfsHash);

storeToIpld

profile.storeToIpld(tree);

Store profile in ipfs as an ipfs file that points to a ipld dag.

Parameters

  1. tree - string: tree to store (‘bookmarkedDapps’, ‘contracts’, …)

Returns

Promise returns string: hash of the ipfs file

Example

const storedHash = await profile.storeToIpld(profile.treeLabels.contracts);

= addressBook =

addContactKey

profile.addContactKey(address, context, key);

Add a key for a contact to bookmarks.

Parameters

  1. address - string: account key of the contact
  2. context - string: store key for this context, can be a contract, bc, etc.
  3. key - string: communication key to store

Returns

Promise returns void: resolved when done

Example

await profile.addContactKey(accounts[0], 'context a', 'key 0x01_a');

addProfileKey

profile.addProfileKey(address, key, value);

Add a profile value to an account.

Parameters

  1. address - string: account key of the contact
  2. key - string: store key for the account like alias, etc.
  3. value - string: value of the profile key

Returns

Promise returns void: resolved when done

Example

await profile.addProfileKey(accounts[0], 'email', 'sample@example.org');
await profile.addProfileKey(accounts[0], 'alias', 'Sample Example');

getAddressBookAddress

profile.getAddressBookAddress(address);

Function description

Parameters

  1. address - string: contact address

Returns

Promise returns any: bookmark info

Example

await profile.getAddressBookAddress(accounts[0]);

getAddressBook

profile.getAddressBook();

Get the whole addressBook.

Parameters

(none)

Returns

any: entire address book

Example

await profile.getAddressBook();

getContactKey

profile.getContactKey(address, context);

Get a communication key for a contact from bookmarks.

Parameters

  1. address - string`: account key of the contact
  2. context - string`: store key for this context, can be a contract, bc, etc.

Returns

Promise returns void: matching key

Example

await profile.getContactKey(accounts[0], 'exampleContext');

getProfileKey

profile.getProfileKey(address, key);

Get a key from an address in the address book.

Parameters

  1. address - string: address to look up
  2. key - string: type of key to get

Returns

Promise returns any: key

Example

const alias = await profile.getProfileKey(accountId, 'alias');

removeContact

profile.removeContact(address);

Remove a contact from bookmarkedDapps.

Parameters

  1. address - string: account key of the contact

Returns

Promise returns void: resolved when done

Example

await profile.removeContact(address);

= bookmarkedDapps =

addDappBookmark

profile.addDappBookmark(address, description);

Add a bookmark for a dapp.

Parameters

  1. address - string: ENS name or contract address (if no ENS name is set)
  2. description - DappBookmark: description for bookmark

Returns

Promise returns void: resolved when done

Example

const bookmark = {
  "name": "taskboard",
  "description": "Create todos and manage updates.",
  "i18n": {
    "description": {
      "de": "Erstelle Aufgaben und überwache Änderungen",
      "en": "Create todos and manage updates"
    },
    "name": {
      "de": "Task Board",
      "en": "Task Board"
    }
  },
  "imgSquare": "...",
  "standalone": true,
  "primaryColor": "#e87e23",
  "secondaryColor": "#fffaf5",
};
await profile.addDappBookmark('sampletaskboard.evan', bookmark);

getDappBookmark

profile.getDappBookmark(address);

Get a bookmark for a given address if any.

Parameters

  1. address - string: ENS name or contract address (if no ENS name is set)

Returns

Promise returns any: bookmark info

Example

await profile.getDappBookmark('sample1.evan');

getBookmarkDefinition

profile.getBookmarkDefinition();

Get all bookmarks for profile.

Parameters

(none)

Returns

Promise returns any: all bookmarks for profile

Example

await profile.getBookmarkDefinitions();

removeDappBookmark

profile.removeDappBookmark(address);

Remove a dapp bookmark from the bookmarkedDapps.

Parameters

  1. address - string: address of the bookmark to remove

Returns

Promise returns void: resolved when done

Example

await profile.removeDappBookmark(address);

setDappBookmarks

profile.setDappBookmarks(bookmarks);

Set bookmarks with given value.

Parameters

  1. bookmarks - any: The options used for calling

Returns

Promise returns void: resolved when done

Example

const bookmarks = await profile.getBookmarkDefinitions();
// update bookmarks
// ...
await profile.setDappBookmarks(bookmarks);

= contracts =

addContract

profile.addContract(address, data);

Add a contract to the current profile.

Parameters

  1. address - string: contract address
  2. data - any: bookmark metadata

Returns

Promise returns void: resolved when done

Example

await profile.addContract('0x...', contractDescription);

getContracts

profile.getContracts();

Get all contracts for the current profile.

Parameters

(none)

Returns

Promise returns any: contracts info

Example

await profile.getContracts();

getContract

profile.getContract(address);

Get a specific contract entry for a given address.

Parameters

  1. address - string: contact address

Returns

Promise returns any: bookmark info

Example

await profile.getContract('testbc.evan');

addBcContract

profile.addBcContract(bc, address, data)

Add a contract (task contract etc. ) to a business center scope of the current profile

Parameters

  1. bc - string: business center ens address or contract address
  2. address - string: contact address
  3. data - any: bookmark metadata

Returns

Promise returns void: resolved when done

Example

await profile.addBcContract('testbc.evan', '0x...', contractDescription);

getBcContract

profile.getBcContract(bc, address);

Get a specific contract entry for a given address.

Parameters

  1. bcc - string: business center ens address or contract address
  2. address - string: contact address

Returns

Promise returns any: bookmark info

Example

await profile.getBcContract('testbc.evan', '0x...');

getBcContracts

profile.getBcContracts(bc, address);

Get all contracts grouped under a business center.

Parameters

  1. bcc - string: business center ens address or contract address

Returns

Promise returns any: bookmark info

Example

await profile.getBcContracts('testbc.evan');

removeContract

profile.removeBcContract(address, data);

removes a contract (task contract etc. ) from a business center scope of the current profile

Parameters

  1. bc - string: business center ens address or contract address
  2. address - any: contact address

Returns

Promise returns void: resolved when done

Example

await profile.removeBcContract('testbc.evan', '0x');

= publicKey =

addPublicKey

profile.addPublicKey(key);

Add a key for a contact to bookmarks.

Parameters

  1. key - string: public Diffie Hellman key part to store

Returns

Promise returns void: resolved when done

Example

await profile.addPublicKey('...');

getPublicKey

profile.getPublicKey();

Get public key of profiles.

Parameters

(none)

Returns

Promise returns any: public key

Example

const key = await profile.getPublicKey();

loadActiveVerifications

profile.loadActiveVerifications();

Load all verificationss that should be displayed for this profile within the ui.

Parameters

(none)

Returns

Promise returns Array<string>: array of topics of verificationss that should be displayed (e.g. [ ‘/company/tuev’, ‘/test/1234’ ] )

Example

const topics = await bcc.profile.loadActiveVerifications();

setActiveVerifications

profile.setActiveVerifications(bookmarks);

Save an array of active verificationss to the profile.

Parameters

  1. bookmarks - Array<string>: bookmarks to set

Returns

Promise returns void: resolved when saving is done

Example

await bcc.profile.setActiveVerifications([ '/company/tuev', '/test/1234' ]);

setTemplates

profile.setTemplates(templates);

Save set of templates to profile.

Parameters

  1. templates - any: entire collections of templates to store in profile

Returns

Promise returns void: resolved when done

Example

await profile.setTemplates({ customMetadata: {} });

getTemplates

profile.getTemplates();

Get entire set of templates from profile.

Returns

Promise returns any: all templates from profile

Example

const templates = await profile.getTemplates();