docs: Remove docblocks for Identity. Document Identity properties and functions.

This commit is contained in:
Hayden Young 2023-06-19 02:24:52 +01:00
parent 4fa3b0c115
commit 59d8bdc90a
2 changed files with 28 additions and 29 deletions

View File

@ -67,7 +67,7 @@ const Identities = async ({ keystore, path, storage, ipfs } = {}) => {
* Creates an identity, adding it to storage. * Creates an identity, adding it to storage.
* @param {Object} options Various options for configuring a new identity. * @param {Object} options Various options for configuring a new identity.
* @param {string} [options.type=publickey] The type of provider to use for generating an identity. * @param {string} [options.type=publickey] The type of provider to use for generating an identity.
* @return {Identity} An instance of identity. * @return {module:Identities~Identity} An instance of identity.
* @memberof module:Identities~Identities * @memberof module:Identities~Identities
* @instance * @instance
*/ */
@ -96,7 +96,7 @@ const Identities = async ({ keystore, path, storage, ipfs } = {}) => {
/** /**
* Verifies an identity using the identity's provider. * Verifies an identity using the identity's provider.
* @param {Identity} identity The identity to verify. * @param {module:Identities~Identity} identity The identity to verify.
* @return {boolean} True the identity is valid, false otherwise. * @return {boolean} True the identity is valid, false otherwise.
* @memberof module:Identities~Identities * @memberof module:Identities~Identities
*/ */
@ -129,10 +129,11 @@ const Identities = async ({ keystore, path, storage, ipfs } = {}) => {
/** /**
* Signs data using an identity. * Signs data using an identity.
* @param {Identity} identity The identity to use for signing. * @param {module:Identities~Identity} identity The identity to use for
* signing.
* @param {string} data The data to sign. * @param {string} data The data to sign.
* @return {string} The signed data. * @return {string} The signed data.
* @throws Private signing key not fund from KeyStore when no signing key can * @throws Private signing key not found from KeyStore when no signing key can
* be retrieved. * be retrieved.
* @memberof module:Identities~Identities * @memberof module:Identities~Identities
* @instance * @instance
@ -147,6 +148,16 @@ const Identities = async ({ keystore, path, storage, ipfs } = {}) => {
return await signMessage(signingKey, data) return await signMessage(signingKey, data)
} }
/**
* Verifies data using a valid signature and publicKey.
* @param {string} signature A signature.
* @param {string} publicKey A public key.
* @param {string} data The data to be verified.
* @return {boolean} True if the the data is signed by the publicKey, false
* otherwise.
* @memberof module:Identities~Identities
* @instance
*/
const verify = async (signature, publicKey, data) => { const verify = async (signature, publicKey, data) => {
return await verifyMessage(signature, publicKey, data) return await verifyMessage(signature, publicKey, data)
} }

View File

@ -1,8 +1,3 @@
/**
* @module Identity
* @description
* An identity.
*/
import * as Block from 'multiformats/block' import * as Block from 'multiformats/block'
import * as dagCbor from '@ipld/dag-cbor' import * as dagCbor from '@ipld/dag-cbor'
import { sha256 } from 'multiformats/hashes/sha2' import { sha256 } from 'multiformats/hashes/sha2'
@ -12,27 +7,20 @@ const codec = dagCbor
const hasher = sha256 const hasher = sha256
const hashStringEncoding = base58btc const hashStringEncoding = base58btc
/**
* Creates an instance of Identity.
* @function
* @param {Object} params One or more parameters for configuring an Identity.
* @param {string} params.id A unique identitifer for the identity.
* @param {string} params.publicKey A public key.
* @param {Object} params.signatures A signed identity id and public key.
* @param {string} params.type The type of identity provider.
* @param {function} params.sign A sign function.
* @param {function} params.verify A verify function.
* @return {module:Identity~Identity} An instance of Identity.
* @throws Identity id is required if id is not provided.
* @throws Invalid public key if publicKey is not provided.
* @throws Signatures object is required if signature is not provided.
* @throws Signature of id is required if signature's id is not provided.
* @throws Signature of publicKey+id is required if signature's publicKey+id is
* not provided.
* @throws Identity type is required if type is not provided.
* @instance
*/
const Identity = async ({ id, publicKey, signatures, type, sign, verify } = {}) => { const Identity = async ({ id, publicKey, signatures, type, sign, verify } = {}) => {
/**
* @namespace module:Identities~Identity
* @description The Identity instance. Returned by
* [Identities.createIdentity()]{@link module:Identities~Identities#createIdentity}.
*
* Available Identity instance properties and functions are:
* - **id:** A unique identifer for the identity.
* - **publicKey:** A public key.
* - **signatures:** A signed identity id and public key.
* - **type:** The type of identity provider.
* - **sign:** A sign function.
* - **verify:** A verify function.
*/
if (id == null) throw new Error('Identity id is required') if (id == null) throw new Error('Identity id is required')
if (publicKey == null) throw new Error('Invalid public key') if (publicKey == null) throw new Error('Invalid public key')
if (signatures == null) throw new Error('Signatures object is required') if (signatures == null) throw new Error('Signatures object is required')