0.4.1 • Published 6 years ago

muport-core v0.4.1

Weekly downloads
5
License
Apache-2.0
Repository
github
Last release
6 years ago

µPort core

CircleCI codecov

This library is intended to be used to create, update, and recover µPort identities, as well as using the identity to sign and encrypt data.

Usage

Simply install using npm

$ npm install muport-core

and then import into your project

const MuPort = require('muport-core')

MuPort

Primary object for interacting with a µPort identity. MuPort enables creation and updating of µPort identities. It also provides functionality to sign claims and help other identities recover.

Kind: global class

new MuPort(serializeState, opts)

Instantiates a µPort identity from its serialized state.

ParamTypeDescription
serializeStateStringthe serialized state of a µPort identity
optsObjectoptional parameters
opts.ipfsConfObjectconfiguration options for ipfs-mini
opts.rpcProviderUrlStringrpc url to a custom ethereum node

muPort.helpRecover(did) ⇒ Promise.<String, Error>

Help another identity recover. Returns a decrypted share if the current identity is a delegate returns undefined otherwise

Kind: instance method of MuPort
Returns: Promise.<String, Error> - a share that the recovering identity can use

ParamTypeDescription
didStringthe did of the identity that should be recovered

muPort.getDid() ⇒ String

The DID is the identifier of the identity. This is a unique string that can be used to look up information about the identity.

Kind: instance method of MuPort
Returns: String - the DID

muPort.getDidDocument() ⇒ Object

The DID Document is a json object that contains information such as public keys

Kind: instance method of MuPort
Returns: Object - the DID Document

muPort.getRecoveryDelegateDids() ⇒ Array.<String>

The recovery delegates that can help this identity recover

Kind: instance method of MuPort
Returns: Array.<String> - an array containing the DIDs of the delegates

muPort.updateIdentity(publicProfile, delegateDids) ⇒ Promise.<Object, Error>

This function is used to update the publicProfile and/or the recoveryNetwork of the identity. The returned object has three properties; address an ethereum address, costInEther a number, and finishUpdate a function. In order to complete the update of the delegates you have to send costInEther ether to the address on mainnet (or other network if you are using a custom config). Once that is done the finishUpdate function can be called. This function sends a transaction to the network that updates the identity. The function will throw an error if there is to little ether in the address. Both publicProfile and delegateDids are optional and you may pass null if you don't wish to update one of them.

Kind: instance method of MuPort
Returns: Promise.<Object, Error> - an object with the data needed to finalize the update

ParamTypeDescription
publicProfileObjecta new public profile for the identity
delegateDidsArray.<String>an array containing the 3 DIDs of the new delegates

muPort.signJWT() ⇒ Promise.<String, Error>

Signs the given payload (claim) and return a promis with the JWT.

Kind: instance method of MuPort
Returns: Promise.<String, Error> - a promise that resolves to a JWT

muPort.verifyJWT(jwt, audience) ⇒ Promise.<Object, Error>

Verifies a JWT.

Kind: instance method of MuPort
Returns: Promise.<Object, Error> - a promise that resolves to the decoded JWT

ParamTypeDefaultDescription
jwtStringthe JWT to verify
audienceStringthis.didthe audience, defaults to did of current identity

muPort.encrypt(msg, toPublic, nonce) ⇒ Object

Asymmetrically encrypt a message

Kind: instance method of MuPort
Returns: Object - an object containing the nonce and the ciphertext

ParamTypeDescription
msgStringthe message to encrypt
toPublicStringthe public key to encrypt to, encoded as a base64 string
nonceString(optional) the nonce, encoded as a base64 string

muPort.decrypt(ciphertext, fromPublic, nonce, toBuffer) ⇒ String | Buffer

Decrypt an asymmetrically encrypted message

Kind: instance method of MuPort
Returns: String | Buffer - the decrypted message

ParamTypeDescription
ciphertextStringthe ciphertext to decrypt, encoded as a base64 string
fromPublicStringthe public key of the entity that encrypted the msg, encoded as a base64 string
nonceStringthe nonce, encoded as a base64 string
toBufferBooleana boolean deciding whether to

muPort.symEncrypt(msg, nonce) ⇒ Object

Symmetrically encrypt a message

Kind: instance method of MuPort
Returns: Object - an object containing the nonce and the ciphertext

ParamTypeDescription
msgStringthe message to encrypt
nonceString(optional) the nonce, encoded as a base64 string

muPort.symDecrypt(ciphertext, nonce, toBuffer) ⇒ String | Buffer

Decrypt a symmetrically encrypted message

Kind: instance method of MuPort
Returns: String | Buffer - the decrypted message

ParamTypeDescription
ciphertextStringthe ciphertext to decrypt, encoded as a base64 string
nonceStringthe nonce, encoded as a base64 string
toBufferBooleana boolean deciding whether to

muPort.serializeState() ⇒ String

Serialize the state of the current identity to be able to reconstruct it later.

Kind: instance method of MuPort
Returns: String - the serialized state

MuPort.newIdentity(publicProfile, delegateDids, opts) ⇒ Promise.<MuPort, Error>

Creates a new µPort identity.

Kind: static method of MuPort
Returns: Promise.<MuPort, Error> - a promise that resolves to an instance of the MuPort class

ParamTypeDescription
publicProfileObjecta public profile for the new identity
delegateDidsArray.<String>three DIDs that can be used to recover the identity at a later point (optional)
optsObjectoptional parameters
opts.externalMgmtKeyStringan ethereum address to be used as an external managementKey
opts.ipfsConfObjectconfiguration options for ipfs-mini
opts.rpcProviderUrlStringrpc url to a custom ethereum node

MuPort.recoverIdentity(did, shares, opts) ⇒ Promise.<MuPort, Error>

Recovers a µPort identity.

Kind: static method of MuPort
Returns: Promise.<MuPort, Error> - a promise that resolves to an instance of the MuPort class

ParamTypeDescription
didStringthe DID of the identity to be recovered
sharesArray.<String>atleast two shares that your delegates helped recover
optsObjectoptional parameters
opts.ipfsConfObjectconfiguration options for ipfs-mini
opts.rpcProviderUrlStringrpc url to a custom ethereum node

MuPort.resolveIdentityDocument(did, opts) ⇒ Promise.<Object, Error>

Resovles the identity document for the given DID.

Kind: static method of MuPort
Returns: Promise.<Object, Error> - a promise that resolves to the identity document

ParamTypeDescription
didStringthe DID of the identity
optsObjectoptional parameters
opts.ipfsConfObjectconfiguration options for ipfs-mini
opts.rpcProviderUrlStringrpc url to a custom ethereum node