js-crypto-ec
Version:
Universal Module for Elliptic Curve Cryptography (ECDSA and ECDH) in JavaScript
41 lines (40 loc) • 2.33 kB
TypeScript
/**
* webapi.js
*/
import { JsonWebKeyPair, CurveTypes, HashTypes, 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} webCrypto - WebCryptoSubtle object.
* @return {Promise<{publicKey: JsonWebKey, privateKey: JsonWebKey}>} - The generated keys.
*/
export declare const generateKey: (namedCurve: CurveTypes, webCrypto: 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} webCrypto - WebCryptoSubtle object.
* @return {Promise<Uint8Array>} - Output signature byte array in raw or der format.
*/
export declare const sign: (msg: Uint8Array, privateJwk: JsonWebKey, hash: HashTypes, signatureFormat: SignatureFormat, webCrypto: 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} webCrypto - WebCryptoSubtle object.
* @return {Promise<boolean>} - The result of verification.
*/
export declare const verify: (msg: Uint8Array, signature: Uint8Array, publicJwk: JsonWebKey, hash: HashTypes, signatureFormat: SignatureFormat, webCrypto: 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} webCrypto - WebCryptoSubtle object.
* @return {Promise<Uint8Array>} - The derived master secret via ECDH.
*/
export declare const deriveSecret: (publicJwk: JsonWebKey, privateJwk: JsonWebKey, webCrypto: any) => Promise<Uint8Array>;