@zlattice/lattice-js
Version:
Lattice blockchain TypeScript SDK with dual module support (CJS + ESM)
63 lines • 2.17 kB
TypeScript
import { type Curve } from "../common/constants.js";
import type { KeyPair } from "../common/index.js";
/**
* Create a new crypto service instance based on the curve
*
* @param curve The curve, like `Curves.Secp256k1` or `Curves.Sm2p256v1`
* @returns The crypto service
*/
export declare function createCrypto(curve: Curve): CryptoService;
export type EncodeFunc = () => Buffer;
export interface CryptoService {
/**
* Generate a key pair
* @returns The key pair
*/
generateKeyPair(): KeyPair;
/**
* Compress the public key
* @param publicKey - The public key
* @returns The compressed public key
*/
compressPublicKey(publicKey: Buffer | string): Buffer;
/**
* Convert the public key to the lattice address
* @param publicKey - The uncompressed public key, the length is 64
* @returns The lattice address, like `zltc_o2Vb5bf6G8vpvXeanMWrLMJs3E7vq8La8`
*/
publicKeyToAddress(publicKey: Buffer | string): string;
/**
* Get the public key from the private key
* @param privateKey - The private key, the length is 32 bytes
* @returns The public key, the length is 65 bytes
*/
getPublicKeyFromPrivateKey(privateKey: string, compressed?: boolean): string;
/**
* Hash the data
* @param data - The data to hash
* @returns The hash bytes
*/
hash(data: Buffer): Buffer;
/**
* Encode the hash
* @param encodeFunc - The encode function
* @returns The encoded hash
*/
encodeHash(encodeFunc: EncodeFunc): Buffer;
/**
* Sign the data
* @param data - The data to sign
* @param privateKey - The private key, the length is 32 bytes
* @returns The signature
*/
sign(data: Buffer, privateKey: string): string;
/**
* Verify the signature
* @param data - The data to verify
* @param signature - The signature
* @param uncompressedPublicKey - The uncompressed public key, the length is 65 bytes
* @returns The result of the verification
*/
verify(data: Buffer, signature: string, uncompressedPublicKey: string): boolean;
}
//# sourceMappingURL=crypto.d.ts.map