@portable-profiles/profiles
v0.0.13
Published
Javascript library to manage portable profiles
Downloads
14
Readme
Portable Profiles
This javascript library lets you create and manage profiles for Paladin, the decentralized social network.
Basic usage
import { Profile, Fields, Visibility } from '@portable-profiles/profiles';
const profile = new Profile();
profile.initialize();
profile.setField(Fields.Nickname, 'Alice', Visibility.Public);
profile.setField(Fields.Email, '[email protected]', Visibility.Private);
profile.sign();
const { json, privateKey } = profile.pack();
This will create a profile (complete with its keychain), and sign the profile using the generated private key. The data
can then be persisted to a user's machine.
The profile can be loaded back into memory with the constructor on Profile
.
const data = // get the data from the file system
const profile = new Profile(data);
To share the profile with someone else, first use filterFor
; it will strip out confidential information from the profile, such as the profile's private key.
import { Visibility } from '@portable-profiles/profiles';
const toShare = profile.filterFor(Visibility.Public);
const dataToShare = profile.getProfile();
Add friends and encrypt data for them only:
import { Profile, Fields, Visibility, forFriends } from '@portable-profiles/profiles';
const alice = new Profile();
alice.setField(Fields.Nickname, 'Alice', Visibility.Public);
alice.sign();
const bob = new Profile();
bob.addFriend(alice);
bob.setField(Fields.Nickname, 'Bob', Visibility.Public);
bob.setField(Fields.Email, '[email protected]', forFriends([ alice.toFriend() ]));
console.log(bob.getField(Fields.Email, alice));
// Result: [email protected]