@bsv/sdk
Version:
BSV Blockchain Software Development Kit
130 lines • 7.84 kB
TypeScript
import { PrivateKey, PublicKey, SymmetricKey, Point } from '../primitives/index.js';
import { WalletProtocol, PubKeyHex } from './Wallet.interfaces.js';
export type Counterparty = PublicKey | PubKeyHex | 'self' | 'anyone';
export interface KeyDeriverApi {
/**
* The root key from which all other keys are derived.
*/
rootKey: PrivateKey;
/**
* The identity of this key deriver which is normally the public key associated with the `rootKey`
*/
identityKey: string;
/**
* Derives a public key based on protocol ID, key ID, and counterparty.
* @param {WalletProtocol} protocolID - The protocol ID including a security level and protocol name.
* @param {string} keyID - The key identifier.
* @param {Counterparty} counterparty - The counterparty's public key or a predefined value ('self' or 'anyone').
* @param {boolean} [forSelf=false] - Optional. false if undefined. Whether deriving for self.
* @returns {PublicKey} - The derived public key.
*/
derivePublicKey: (protocolID: WalletProtocol, keyID: string, counterparty: Counterparty, forSelf?: boolean) => PublicKey;
/**
* Derives a private key based on protocol ID, key ID, and counterparty.
* @param {WalletProtocol} protocolID - The protocol ID including a security level and protocol name.
* @param {string} keyID - The key identifier.
* @param {Counterparty} counterparty - The counterparty's public key or a predefined value ('self' or 'anyone').
* @returns {PrivateKey} - The derived private key.
*/
derivePrivateKey: (protocolID: WalletProtocol, keyID: string, counterparty: Counterparty) => PrivateKey;
/**
* Derives a symmetric key based on protocol ID, key ID, and counterparty.
* Note: Symmetric keys should not be derivable by everyone due to security risks.
* @param {WalletProtocol} protocolID - The protocol ID including a security level and protocol name.
* @param {string} keyID - The key identifier.
* @param {Counterparty} counterparty - The counterparty's public key or a predefined value ('self' or 'anyone').
* @returns {SymmetricKey} - The derived symmetric key.
*/
deriveSymmetricKey: (protocolID: WalletProtocol, keyID: string, counterparty: Counterparty) => SymmetricKey;
/**
* Reveals the shared secret between the root key and the counterparty.
* Note: This should not be used for 'self'.
* @param {Counterparty} counterparty - The counterparty's public key or a predefined value ('self' or 'anyone').
* @returns {number[]} - The shared secret as a number array.
* @throws {Error} - Throws an error if attempting to reveal a shared secret for 'self'.
*/
revealCounterpartySecret: (counterparty: Counterparty) => number[];
/**
* Reveals the specific key association for a given protocol ID, key ID, and counterparty.
* @param {Counterparty} counterparty - The counterparty's public key or a predefined value ('self' or 'anyone').
* @param {WalletProtocol} protocolID - The protocol ID including a security level and protocol name.
* @param {string} keyID - The key identifier.
* @returns {number[]} - The specific key association as a number array.
*/
revealSpecificSecret: (counterparty: Counterparty, protocolID: WalletProtocol, keyID: string) => number[];
}
/**
* Class responsible for deriving various types of keys using a root private key.
* It supports deriving public and private keys, symmetric keys, and revealing key linkages.
*/
export declare class KeyDeriver implements KeyDeriverApi {
private readonly cacheSharedSecret?;
private readonly retrieveCachedSharedSecret?;
rootKey: PrivateKey;
identityKey: string;
private readonly anyone;
/**
* Initializes the KeyDeriver instance with a root private key.
* @param {PrivateKey | 'anyone'} rootKey - The root private key or the string 'anyone'.
*/
constructor(rootKey: PrivateKey | 'anyone', cacheSharedSecret?: ((priv: PrivateKey, pub: Point, point: Point) => void), retrieveCachedSharedSecret?: ((priv: PrivateKey, pub: Point) => (Point | undefined)));
/**
* Derives a public key based on protocol ID, key ID, and counterparty.
* @param {WalletProtocol} protocolID - The protocol ID including a security level and protocol name.
* @param {string} keyID - The key identifier.
* @param {Counterparty} counterparty - The counterparty's public key or a predefined value ('self' or 'anyone').
* @param {boolean} [forSelf=false] - Whether deriving for self.
* @returns {PublicKey} - The derived public key.
*/
derivePublicKey(protocolID: WalletProtocol, keyID: string, counterparty: Counterparty, forSelf?: boolean): PublicKey;
/**
* Derives a private key based on protocol ID, key ID, and counterparty.
* @param {WalletProtocol} protocolID - The protocol ID including a security level and protocol name.
* @param {string} keyID - The key identifier.
* @param {Counterparty} counterparty - The counterparty's public key or a predefined value ('self' or 'anyone').
* @returns {PrivateKey} - The derived private key.
*/
derivePrivateKey(protocolID: WalletProtocol, keyID: string, counterparty: Counterparty): PrivateKey;
/**
* Derives a symmetric key based on protocol ID, key ID, and counterparty.
* Note: Symmetric keys should not be derivable by everyone due to security risks.
* @param {WalletProtocol} protocolID - The protocol ID including a security level and protocol name.
* @param {string} keyID - The key identifier.
* @param {Counterparty} counterparty - The counterparty's public key or a predefined value ('self' or 'anyone').
* @returns {SymmetricKey} - The derived symmetric key.
*/
deriveSymmetricKey(protocolID: WalletProtocol, keyID: string, counterparty: Counterparty): SymmetricKey;
/**
* Reveals the shared secret between the root key and the counterparty.
* Note: This should not be used for 'self'.
* @param {Counterparty} counterparty - The counterparty's public key or a predefined value ('self' or 'anyone').
* @returns {number[]} - The shared secret as a number array.
* @throws {Error} - Throws an error if attempting to reveal a shared secret for 'self'.
*/
revealCounterpartySecret(counterparty: Counterparty): number[];
/**
* Reveals the specific key association for a given protocol ID, key ID, and counterparty.
* @param {Counterparty} counterparty - The counterparty's public key or a predefined value ('self' or 'anyone').
* @param {WalletProtocol} protocolID - The protocol ID including a security level and protocol name.
* @param {string} keyID - The key identifier.
* @returns {number[]} - The specific key association as a number array.
*/
revealSpecificSecret(counterparty: Counterparty, protocolID: WalletProtocol, keyID: string): number[];
/**
* Normalizes the counterparty to a public key.
* @param {Counterparty} counterparty - The counterparty's public key or a predefined value ('self' or 'anyone').
* @returns {PublicKey} - The normalized counterparty public key.
* @throws {Error} - Throws an error if the counterparty is invalid.
*/
private normalizeCounterparty;
/**
* Computes the invoice number based on the protocol ID and key ID.
* @param {WalletProtocol} protocolID - The protocol ID including a security level and protocol name.
* @param {string} keyID - The key identifier.
* @returns {string} - The computed invoice number.
* @throws {Error} - Throws an error if protocol ID or key ID are invalid.
*/
private computeInvoiceNumber;
}
export default KeyDeriver;
//# sourceMappingURL=KeyDeriver.d.ts.map