js-crypto-ec
Version:
Universal Module for Elliptic Curve Cryptography (ECDSA and ECDH) in JavaScript
44 lines (43 loc) • 2.48 kB
TypeScript
/**
* nodeapi.js
*/
import { HashTypes, JsonWebKeyPair, SignatureFormat } from './typedef';
/**
* Generate elliptic curve cryptography public/private key pair. Generated keys are in JWK.
* @param {String} namedCurve - Name of curve like 'P-256'.
* @param {Object} nodeCrypto - NodeCrypto object.
* @return {Promise<{publicKey: JsonWebKey, privateKey: JsonWebKey}>} - The generated keys.
* @throws {Error} - Throws if NotPublic/PrivateKeyForECCKeyGenNode
*/
export declare const generateKey: (namedCurve: NamedCurve, nodeCrypto: any) => Promise<JsonWebKeyPair>;
/**
* Sign message with ECDSA.
* @param {Uint8Array} msg - Byte array of message to be signed.
* @param {JsonWebKey} privateJwk - Private key object in JWK format.
* @param {String} hash - Name of hash algorithm used in singing, like 'SHA-256'.
* @param {String} signatureFormat - Signature format, 'raw' or 'der'
* @param {Object} nodeCrypto - NodeCrypto object.
* @return {Promise<Uint8Array>} - Output signature byte array in raw or der format.
* @throws {Error} - Throws if NotPrivateKeyForECCSignNode.
*/
export declare const sign: (msg: Uint8Array, privateJwk: JsonWebKey, hash: HashTypes, signatureFormat: SignatureFormat, nodeCrypto: any) => Promise<Uint8Array>;
/**
* Verify signature with ECDSA.
* @param {Uint8Array} msg - Byte array of message that have been signed.
* @param {Uint8Array} signature - Byte array of signature for the given message.
* @param {JsonWebKey} publicJwk - Public key object in JWK format.
* @param {String} hash - Name of hash algorithm used in singing, like 'SHA-256'.
* @param {String} signatureFormat - Signature format,'raw' or 'der'.
* @param {Object} nodeCrypto - NodeCrypto object.
* @return {Promise<boolean>} - The result of verification.
* @throws {Error} - Throws if NotPublicKeyForEccVerifyNode.
*/
export declare const verify: (msg: Uint8Array, signature: Uint8Array, publicJwk: JsonWebKey, hash: HashTypes, signatureFormat: SignatureFormat, nodeCrypto: any) => Promise<any>;
/**
* Key Derivation for ECDH, Elliptic Curve Diffie-Hellman Key Exchange.
* @param {JsonWebKey} publicJwk - Remote public key object in JWK format.
* @param {JsonWebKey} privateJwk - Local (my) private key object in JWK format.
* @param {Object} nodeCrypto - NodeCrypto object.
* @return {Uint8Array} - The derived master secret via ECDH.
*/
export declare const deriveSecret: (publicJwk: JsonWebKey, privateJwk: JsonWebKey, nodeCrypto: any) => Uint8Array;