askexperts
Version:
AskExperts SDK: build and use AI experts - ask them questions and pay with bitcoin on an open protocol
94 lines (93 loc) • 3.78 kB
TypeScript
/**
* Encryption utilities for NIP-173
* Supports both "none" and "nip44" encryption types
*/
import { EncryptionMethod } from './types.js';
export declare const ENCRYPTION_NONE = "none";
export declare const ENCRYPTION_NIP44 = "nip44";
export declare const MAX_PAYLOAD_SIZE_NIP44_BIN: number;
export declare const MAX_PAYLOAD_SIZE_NIP44: number;
/**
* Error thrown when encryption or decryption fails
*/
export declare class EncryptionError extends Error {
constructor(message: string);
}
/**
* Encryption interface for NIP-173
* Defines methods for encrypting and decrypting data
* Can be implemented to support custom encryption methods
*/
export interface Encryption {
/**
* Returns the limit of chunks size allowed to
* be passed as input
*/
maxChunkSize(type: EncryptionMethod): Promise<number | undefined>;
/**
* Encrypts data using the specified encryption method
*
* @param data - The data to encrypt as string or Uint8Array
* @param type - The encryption method
* @param senderPrivkey - Sender's private key (for nip44)
* @param recipientPubkey - Recipient's public key (for nip44)
* @returns Encrypted data as string
*/
encrypt(data: string | Uint8Array, type: EncryptionMethod, senderPrivkey?: Uint8Array, recipientPubkey?: string): Promise<string>;
/**
* Decrypts data using the specified encryption method
*
* @param data - The encrypted data as string
* @param type - The encryption method
* @param binary - Whether to return binary data instead of string
* @param recipientPrivkey - Recipient's private key (for nip44)
* @param senderPubkey - Sender's public key (for nip44)
* @returns Decrypted data as string or Uint8Array (if binary)
*/
decrypt(data: string, type: EncryptionMethod, binary: boolean, recipientPrivkey?: Uint8Array, senderPubkey?: string): Promise<string | Uint8Array>;
/**
* Returns a list of supported encryption methods
*
* @returns Array of supported encryption method names
*/
list(): string[];
}
/**
* Default implementation of the Encryption interface
* Provides built-in support for 'none' and 'nip44' encryption methods
*/
export declare class DefaultEncryption implements Encryption {
maxChunkSize(type: EncryptionMethod): Promise<number | undefined>;
/**
* Encrypts data using the specified encryption method
*
* @param data - The data to encrypt as string or Uint8Array
* @param type - The encryption method
* @param senderPrivkey - Sender's private key (for nip44)
* @param recipientPubkey - Recipient's public key (for nip44)
* @returns Encrypted data as string
*/
encrypt(data: string | Uint8Array, type: EncryptionMethod, senderPrivkey?: Uint8Array, recipientPubkey?: string): Promise<string>;
/**
* Decrypts data using the specified encryption method
*
* @param data - The encrypted data as string
* @param type - The encryption method
* @param binary - Whether to return binary data instead of string
* @param recipientPrivkey - Recipient's private key (for nip44)
* @param senderPubkey - Sender's public key (for nip44)
* @returns Decrypted data as string or Uint8Array (if binary)
*/
decrypt(data: string, type: EncryptionMethod, binary: boolean, recipientPrivkey?: Uint8Array, senderPubkey?: string): Promise<string | Uint8Array>;
/**
* Returns a list of supported encryption methods
*
* @returns Array of supported encryption method names
*/
list(): string[];
}
/**
* Returns the default encryption instance
* Creates a new instance if one doesn't exist
*/
export declare function getEncryption(): DefaultEncryption;