airsign-sdk-core
Version:
AirSign Protocol Core SDK - secure nearby crypto & data exchange
92 lines • 3.43 kB
TypeScript
/**
* Cryptographic operations for AirSign Protocol
*
* Provides X25519 ECDH key exchange, XChaCha20-Poly1305 AEAD encryption,
* and signature verification using libsodium and noble-crypto libraries.
*/
import { type EphemeralKeyPair, type SignatureScheme } from './types.js';
/**
* Generate an ephemeral X25519 keypair for ECDH key exchange
*
* @returns Promise resolving to a new ephemeral keypair
* @throws {AirSignError} If key generation fails
*/
export declare function generateEphemeralKeypair(): Promise<EphemeralKeyPair>;
/**
* Derive shared secret using X25519 ECDH
*
* @param ourPrivateKey - Our private key (Uint8Array)
* @param theirPublicKey - Their public key (base64 string)
* @returns Promise resolving to shared secret key
* @throws {AirSignError} If key derivation fails
*/
export declare function deriveSharedKey(ourPrivateKey: Uint8Array, theirPublicKey: string): Promise<Uint8Array>;
/**
* Encrypt a message using XChaCha20-Poly1305 AEAD
*
* @param key - 32-byte encryption key
* @param plaintext - Object to encrypt
* @returns Promise resolving to encrypted message with nonce
* @throws {AirSignError} If encryption fails
*/
export declare function encryptMessage(key: Uint8Array, plaintext: object): Promise<{
ciphertext: string;
nonce: string;
}>;
/**
* Decrypt a message using XChaCha20-Poly1305 AEAD
*
* @param key - 32-byte decryption key
* @param ciphertext - Base64 encoded ciphertext
* @param nonce - Base64 encoded nonce
* @returns Promise resolving to decrypted object
* @throws {AirSignError} If decryption fails
*/
export declare function decryptMessage(key: Uint8Array, ciphertext: string, nonce: string): Promise<object>;
/**
* Simple string encryption for testing and demos
*
* @param message - Plain text message to encrypt
* @param key - 32-byte encryption key
* @returns Base64 encoded encrypted message with embedded nonce
*/
export declare function encryptString(message: string, key: Uint8Array): Promise<string>;
/**
* Simple string decryption for testing and demos
*
* @param encryptedMessage - Base64 encoded encrypted message with embedded nonce
* @param key - 32-byte decryption key
* @returns Decrypted plain text message
*/
export declare function decryptString(encryptedMessage: string, key: Uint8Array): Promise<string>;
/**
* Hash a message envelope for signature verification
*
* @param envelope - Message envelope to hash
* @returns Promise resolving to SHA-256 hash
*/
export declare function hashMessageEnvelope(envelope: {
type: string;
id: string;
payload: string;
meta: object;
}): Promise<Uint8Array>;
/**
* Verify a sender signature on a message
*
* @param messageHash - Hash of the message to verify
* @param signatureHex - Hex-encoded signature
* @param publicKeyHex - Hex-encoded public key
* @param scheme - Signature scheme ('secp256k1' or 'ed25519')
* @returns Promise resolving to true if signature is valid
* @throws {AirSignError} If verification fails
*/
export declare function verifySenderSignature(_messageHash: Uint8Array, _signatureHex: string, _publicKeyHex: string, scheme: SignatureScheme): Promise<boolean>;
/**
* Securely clear sensitive data from memory
*
* @param data - Sensitive data to clear
*/
export declare function secureClear(data: Uint8Array): void;
export declare function bytesToHex(bytes: Uint8Array): string;
//# sourceMappingURL=crypto.d.ts.map