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:
// 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);
new Profile(options);
Creates a new Profile instance.
options
-ProfileOptions
: options for Profile constructoraccountId
-string
: account, that is the profile ownercontractLoader
-ContractLoader
_:ContractLoader
_ instancedataContract
-DataContract
_:DataContract
_ instanceexecutor
-Executor
_:Executor
_ instanceipld
-Ipld
_:Ipld
_ instancenameResolver
-NameResolver
_:NameResolver
_ instancedefaultCryptoAlgo
-string
(optional): crypto algorith name fromCryptoProvider
, defaults toaes
log
-Function
(optional): function to use for logging:(message, level) => {...}
logLevel
-LogLevel
_ (optional): messages with this level will be logged withlog
logLog
-LogLogInterface
_ (optional): container for collecting log messageslogLogLevel
-LogLevel
_ (optional): messages with this level will be pushed tologLog
trees
-object
(optional): precached profile data, defaults to{}
Profile
instance
const profile = new Profile({
accountId: accounts[0],
contractLoader,
dataContract,
executor,
ipld,
nameResolver,
});
profile.createProfile(keys)
Create new profile, store it to profile index initialize addressBook and publicKey.
keys
-any
: diffie hell man keys for account, created byKeyExchange
_privateKey
-Buffer
: private key for key exchangepublicKey
-Buffer
: combination of shared secret and own private key
Promise
returns void
: resolved when done
await profile.createProfile(keyExchange.getDiffieHellmanKeys());
profile.exists();
Check if a profile has been stored for current account.
options
-object
: The options used for calling
Promise
returns void
: true if a contract was registered, false if not
console.log(await profile.exists());
// Output:
// true
profile.getContactKnownState(accountId);
Check, known state for given account.
accountId
-string
: account id of a contact
Promise
returns void
: true if known account
console.log(await profile.getContactKnownState(accountId));
// Output: // true
profile.setContactKnownState(accountId, contactKnown);
Store given state for this account.
accountId
-string
: account id of a contactcontactKnown
-boolean
: true if known, false if not
Promise
returns void
: resolved when done
// mark accountId as a known contact
profile.setContactKnownState(accountId, true);
profile.loadForAccount([tree]);
Load profile for given account from global profile contract, if a tree is given, load that tree from ipld as well.
tree
-string
(optional): tree to load ('bookmarkedDapps', 'contracts', ...), profile.treeLabels properties can be passed as arguments
Promise
returns void
: resolved when done
await profile.loadForAccount(profile.treeLabels.contracts);
profile.storeForAccount(tree);
Stores profile tree or given hash to global profile contract.
tree
-string
: tree to store ('bookmarkedDapps', 'contracts', ...)ipldHash
-string
(optional): store this hash instead of the current tree for account
Promise
returns void
: resolved when done
await profile.storeForAccount(profile.treeLabels.contracts);
profile.loadFromIpld(tree, ipldIpfsHash);
Load profile from ipfs via ipld dag via ipfs file hash.
tree
-string
: tree to load ('bookmarkedDapps', 'contracts', ...)ipldIpfsHash
-string
: ipfs file hash that points to a file with ipld a hash
Promise
returns Profile
: this profile
await profile.loadFromIpld(profile.treeLabels.contracts, ipldIpfsHash);
profile.storeToIpld(tree);
Store profile in ipfs as an ipfs file that points to a ipld dag.
tree
-string
: tree to store ('bookmarkedDapps', 'contracts', ...)
Promise
returns string
: hash of the ipfs file
const storedHash = await profile.storeToIpld(profile.treeLabels.contracts);
profile.addContactKey(address, context, key);
Add a key for a contact to bookmarks.
address
-string
: account key of the contactcontext
-string
: store key for this context, can be a contract, bc, etc.key
-string
: communication key to store
Promise
returns void
: resolved when done
await profile.addContactKey(accounts[0], 'context a', 'key 0x01_a');
profile.addProfileKey(address, key, value);
Add a profile value to an account.
address
-string
: account key of the contactkey
-string
: store key for the account like alias, etc.value
-string
: value of the profile key
Promise
returns void
: resolved when done
await profile.addProfileKey(accounts[0], 'email', 'sample@example.org');
await profile.addProfileKey(accounts[0], 'alias', 'Sample Example');
profile.getAddressBookAddress(address);
Function description
address
-string
: contact address
Promise
returns any
: bookmark info
await profile.getAddressBookAddress(accounts[0]);
profile.getAddressBook();
Get the whole addressBook.
(none)
any
: entire address book
await profile.getAddressBook();
profile.getContactKey(address, context);
Get a communication key for a contact from bookmarks.
address
-string
`: account key of the contactcontext
-string
`: store key for this context, can be a contract, bc, etc.
Promise
returns void
: matching key
await profile.getContactKey(accounts[0], 'exampleContext');
profile.getProfileKey(address, key);
Get a key from an address in the address book.
address
-string
: address to look upkey
-string
: type of key to get
Promise
returns any
: key
const alias = await profile.getProfileKey(accountId, 'alias');
profile.removeContact(address);
Remove a contact from bookmarkedDapps.
address
-string
: account key of the contact
Promise
returns void
: resolved when done
await profile.removeContact(address);
profile.addDappBookmark(address, description);
Add a bookmark for a dapp.
address
-string
: ENS name or contract address (if no ENS name is set)description
-DappBookmark
: description for bookmark
Promise
returns void
: resolved when done
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);
profile.getDappBookmark(address);
Get a bookmark for a given address if any.
address
-string
: ENS name or contract address (if no ENS name is set)
Promise
returns any
: bookmark info
await profile.getDappBookmark('sample1.evan');
profile.getBookmarkDefinition();
Get all bookmarks for profile.
(none)
Promise
returns any
: all bookmarks for profile
await profile.getBookmarkDefinitions();
profile.removeDappBookmark(address);
Remove a dapp bookmark from the bookmarkedDapps.
address
-string
: address of the bookmark to remove
Promise
returns void
: resolved when done
await profile.removeDappBookmark(address);
profile.setDappBookmarks(bookmarks);
Set bookmarks with given value.
bookmarks
-any
: The options used for calling
Promise
returns void
: resolved when done
const bookmarks = await profile.getBookmarkDefinitions();
// update bookmarks
// ...
await profile.setDappBookmarks(bookmarks);
profile.addContract(address, data);
Add a contract to the current profile.
address
-string
: contract addressdata
-any
: bookmark metadata
Promise
returns void
: resolved when done
await profile.addContract('0x...', contractDescription);
profile.getContracts();
Get all contracts for the current profile.
(none)
Promise
returns any
: contracts info
await profile.getContracts();
profile.getContract(address);
Get a specific contract entry for a given address.
address
-string
: contact address
Promise
returns any
: bookmark info
await profile.getContract('testbc.evan');
profile.addBcContract(bc, address, data)
Add a contract (task contract etc. ) to a business center scope of the current profile
bc
-string
: business center ens address or contract addressaddress
-string
: contact addressdata
-any
: bookmark metadata
Promise
returns void
: resolved when done
await profile.addBcContract('testbc.evan', '0x...', contractDescription);
profile.getBcContract(bc, address);
Get a specific contract entry for a given address.
bcc
-string
: business center ens address or contract addressaddress
-string
: contact address
Promise
returns any
: bookmark info
await profile.getBcContract('testbc.evan', '0x...');
profile.getBcContracts(bc, address);
Get all contracts grouped under a business center.
bcc
-string
: business center ens address or contract address
Promise
returns any
: bookmark info
await profile.getBcContracts('testbc.evan');
profile.removeBcContract(address, data);
removes a contract (task contract etc. ) from a business center scope of the current profile
bc
-string
: business center ens address or contract addressaddress
-any
: contact address
Promise
returns void
: resolved when done
await profile.removeBcContract('testbc.evan', '0x');
profile.addPublicKey(key);
Add a key for a contact to bookmarks.
key
-string
: public Diffie Hellman key part to store
Promise
returns void
: resolved when done
await profile.addPublicKey('...');
profile.getPublicKey();
Get public key of profiles.
(none)
Promise
returns any
: public key
const key = await profile.getPublicKey();
profile.loadActiveVerifications();
Load all verificationss that should be displayed for this profile within the ui.
(none)
Promise
returns Array<string>
: array of topics of verificationss that should be displayed (e.g. [ '/company/tuev', '/test/1234' ] )
const topics = await bcc.profile.loadActiveVerifications();
profile.setActiveVerifications(bookmarks);
Save an array of active verificationss to the profile.
bookmarks
-Array<string>
: bookmarks to set
Promise
returns void
: resolved when saving is done
await bcc.profile.setActiveVerifications([ '/company/tuev', '/test/1234' ]);
profile.setTemplates(templates);
Save set of templates to profile.
templates
-any
: entire collections of templates to store in profile
Promise
returns void
: resolved when done
await profile.setTemplates({ customMetadata: {} });
profile.getTemplates();
Get entire set of templates from profile.
Promise
returns any
: all templates from profile
const templates = await profile.getTemplates();