UNPKG

tink-crypto

Version:

A multi-language, cross-platform library that provides cryptographic APIs that are secure, easy to use correctly, and hard(er) to misuse.

70 lines (69 loc) 2.85 kB
/** * @license * Copyright 2020 Google LLC * SPDX-License-Identifier: Apache-2.0 */ /** * Supported elliptic curves. */ export declare enum CurveType { P256 = 1, P384 = 2, P521 = 3 } /** * Supported point format. */ export declare enum PointFormatType { UNCOMPRESSED = 1, COMPRESSED = 2, DO_NOT_USE_CRUNCHY_UNCOMPRESSED = 3 } /** * Supported ECDSA signature encoding. */ export declare enum EcdsaSignatureEncodingType { DER = 1, IEEE_P1363 = 2 } /** * Transform an ECDSA signature in DER encoding to IEEE P1363 encoding. * * @param der the ECDSA signature in DER encoding * @param ieeeLength the length of the ECDSA signature in IEEE * encoding. This is usually 2 * size of the elliptic curve field. * @return ECDSA signature in IEEE encoding */ export declare function ecdsaDer2Ieee(der: Uint8Array, ieeeLength: number): Uint8Array; /** * Transform an ECDSA signature in IEEE 1363 encoding to DER encoding. * * @param ieee the ECDSA signature in IEEE encoding * @return ECDSA signature in DER encoding */ export declare function ecdsaIeee2Der(ieee: Uint8Array): Uint8Array; /** * Validate that the ECDSA signature is in DER encoding, based on * https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki. * * @param sig an ECDSA siganture */ export declare function isValidDerEcdsaSignature(sig: Uint8Array): boolean; export declare function curveToString(curve: CurveType): string; export declare function curveFromString(curve: string): CurveType; /** Helper method for unit tests. */ export declare function formatFromString(format: string): PointFormatType; export declare function pointEncode(curve: string, format: PointFormatType, point: JsonWebKey): Uint8Array; /** Converts byte array to bigint. */ export declare function byteArrayToInteger(bytes: Uint8Array): bigint; /** Converts bigint to byte array. */ export declare function integerToByteArray(i: bigint): Uint8Array; export declare function pointDecode(curve: string, format: PointFormatType, point: Uint8Array): JsonWebKey; export declare function getJsonWebKey(curve: CurveType, x: Uint8Array, y: Uint8Array, d?: Uint8Array | null): JsonWebKey; export declare function fieldSizeInBytes(curve: CurveType): number; export declare function encodingSizeInBytes(curve: CurveType, pointFormat: PointFormatType): number; export declare function computeEcdhSharedSecret(privateKey: CryptoKey, publicKey: CryptoKey): Promise<Uint8Array>; export declare function generateKeyPair(algorithm: 'ECDH' | 'ECDSA', curve: string): Promise<CryptoKeyPair>; export declare function exportCryptoKey(cryptoKey: CryptoKey): Promise<JsonWebKey>; export declare function importPublicKey(algorithm: string, jwk: JsonWebKey): Promise<CryptoKey>; export declare function importPrivateKey(algorithm: string, jwk: JsonWebKey): Promise<CryptoKey>;