jsdoc.js


/**
 * @typedef {object} KeyPair
 *
 * @description KeyPair struct
 *
 * @property {Uint8Array} public	- Public key
 * @property {Uint8Array} secret	- Secret key
 */

/**
 * @class KeyManager
 *
 * @description Create and manage 25519 keys for use with 'hcs0' Holochain encoding
 *
 * @param {Buffer} seed			- Buffer to be used as seed for creating keys (optional)
 *
 * @prop {KeyPair} signing		- Signing keypair
 * @prop {KeyPair} encryption		- Encryption keypair
 *
 * @return {KeyManager} instance of KeyManager class
 */
class KeyManager {
    
    constructor ( seed ) {
    }

    /**
     * @static
     * @function digest
     * @memberof KeyManager
     *
     * @description Produce a SHA-256 digest
     *
     * @param {string} text		- Serialized message
     *
     * @return {Uint8Array} 64 byte result
     *
     * @example
     * const bytes = KeyManager.digest( "bla bla bla" );
     */
    static digest ( text ) {
    }

    /**
     * @static
     * @function encodeDigest
     * @memberof KeyManager
     *
     * @description Encode bytes with SHA2-256 multicodec
     *
     * @param {Uint8Array} byte_array	- Hash bytes
     *
     * @return {string} encoded hash
     *
     * @example
     * const bytes = KeyManager.digest( "bla bla bla" );
     * const hash = KeyManager.encodeDigest( bytes );
     */
    static encodeDigest ( byte_array ) {
    }

    /**
     * @static
     * @function encodeSignature
     * @memberof KeyManager
     *
     * @description Encode bytes with base64
     *
     * @param {Uint8Array} byte_array	- Hash bytes
     *
     * @return {string} encoded signature
     *
     * @example
     * const keys = new KeyManager();
     * const bytes = keys.sign( "bla bla bla" );
     * const signature = KeyManager.encodeSignature( bytes );
     */
    static encodeSignature ( byte_array ) {
    }

    /**
     * @static
     * @function deriveSeed
     * @memberof KeyManager
     *
     * @description Derive seed from email and password
     *
     * @param {string} email		- User email
     * @param {string} password		- User password
     *
     * @return {Uint8Array} seed
     *
     * @example
     * const seed = KeyManager.deriveSeed( "somebody@example.com", "Pa55w0rd!" );
     * const keys = new KeyManager( seed );
     */
    static deriveSeed ( email, password ) {
    }

    /**
     * @instance
     * @function agentId
     * @memberof KeyManager
     *
     * @description Get HCID (hcs0) encoded public key
     *
     * @return {string} agent ID
     *
     * @example
     * const keys = new KeyManager();
     * let agent_id = keys.agentId();
     */
    agentId () {
    }

    /**
     * @instance
     * @function sign
     * @memberof KeyManager
     *
     * @description Sign a message using private signing key
     *
     * @param {string} message		- Message to be signed
     *
     * @return {Uint8Array} signature byte array
     *
     * @example
     * const keys = new KeyManager();
     * let signature = keys.sign( message );
     */
    sign ( message ) {
    }
    
    /**
     * @instance
     * @function verify
     * @memberof KeyManager
     *
     * @description Verify a signed message against a given public key
     *
     * @param {string} message		- Message that was signed
     * @param {Uint8Array} signature	- Signature byte array
     * @param {Uint8Array} public_key	- Public key (defaults to self public key)
     *
     * @return {boolean} verification result
     *
     * @example
     * const keys = new KeyManager();
     * let genuine = keys.verify( message, signature );
     */
    verify ( message, signature, public_key = null ) {
    }
    
    /**
     * @instance
     * @function digestAndSign
     * @memberof KeyManager
     *
     * @description Digest the message and then sign the hash.  Returns unencoded digest and signature.
     *
     * @param {string} message		- Message that will be digested and signed
     *
     * @return {object} digest and signature
     *
     * @example
     * const keys = new KeyManager();
     * let pair = keys.digestAndSign( message );
     * console.log( pair.digest );
     * console.log( pair.signature );
     */
    digestAndSign ( message ) {
    }
    
    /**
     * @instance
     * @function digestAndSignEncoded
     * @memberof KeyManager
     *
     * @description Digest the message and then sign the hash.  Returns encoded digest and signature.
     *
     * @param {string} message		- Message that will be digested and signed
     *
     * @return {object} digest and signature
     *
     * @example
     * const keys = new KeyManager();
     * let pair = keys.digestAndSignEncoded( message );
     * console.log( pair.digest );
     * console.log( pair.signature );
     */
    digestAndSign ( message ) {
    }

    // NOT IMPLEMENTED YET
    // /**
    //  * @instance
    //  * @function encrypt
    //  * @memberof KeyManager
    //  *
    //  * @description Encrypt a message using private encryption key
    //  *
    //  * @return {Uint8Array} encrypted message
    //  *
    //  * @example
    //  * const keys = new KeyManager( seed );
    //  * let encrypted = keys.encrypt( message );
    //  */
    // encrypt () {
    // }
    
    // NOT IMPLEMENTED YET
    // /**
    //  * @instance
    //  * @function decrypt
    //  * @memberof KeyManager
    //  *
    //  * @description Decrypt a message using private encryption key
    //  *
    //  * @return {String} decrypted message
    //  *
    //  * @example
    //  * const keys = new KeyManager( seed );
    //  * let message = keys.decrypt( encrypted );
    //  */
    // decrypt () {
    // }
    
}


module.exports = {
    KeyManager,
};