@gorbchain-xyz/chaindecode
Version:
GorbchainSDK V1.3+ - Complete Solana development toolkit with advanced cryptography, messaging, and collaboration features. Build secure applications with blockchain, DeFi, and end-to-end encryption.
154 lines (153 loc) • 5 kB
TypeScript
/**
* Shared Key Manager for transitioning between single and group encryption
* Manages shared encryption/decryption keys that can be distributed among group members
*/
import { EncryptionResult } from './types.js';
/**
* Shared encryption key that can be distributed to multiple recipients
*/
export interface SharedEncryptionKey {
/** Unique key identifier */
keyId: string;
/** The actual encryption key (encrypted per recipient) */
encryptedShares: Map<string, EncryptedKeyShare>;
/** Key metadata */
metadata: SharedKeyMetadata;
/** Current key holders */
holders: string[];
/** Key creation timestamp */
createdAt: number;
/** Key expiration (optional) */
expiresAt?: number;
}
/**
* Encrypted key share for a specific recipient
*/
export interface EncryptedKeyShare {
/** Recipient's public key */
recipientPublicKey: string;
/** Encrypted key data */
encryptedData: string;
/** Share-specific nonce */
nonce: string;
/** Share creation timestamp */
createdAt: number;
/** Who created this share */
createdBy: string;
/** Share permissions */
permissions: SharePermissions;
}
/**
* Permissions for a key share
*/
export interface SharePermissions {
/** Can use key to decrypt data */
canDecrypt: boolean;
/** Can use key to encrypt data */
canEncrypt: boolean;
/** Can share key with others */
canShare: boolean;
/** Can revoke their own access */
canRevoke: boolean;
/** Key usage expiration */
usageExpiresAt?: number;
}
/**
* Shared key metadata
*/
export interface SharedKeyMetadata {
/** Key name/description */
name: string;
/** Key purpose */
purpose: string;
/** Key creator */
creator: string;
/** Key algorithm used */
algorithm: string;
/** Key derivation method */
derivationMethod: string;
/** Custom properties */
properties: Record<string, any>;
}
/**
* Key transition request - converting single key to shared key
*/
export interface KeyTransitionRequest {
/** Original recipient public key */
originalRecipient: string;
/** New recipients to add */
newRecipients: {
publicKey: string;
permissions: SharePermissions;
}[];
/** Transition reason */
reason: string;
/** Authorizer private key */
authorizerPrivateKey: string | Uint8Array;
/** Authorizer public key */
authorizerPublicKey: string;
}
/**
* Manages shared encryption keys for flexible group encryption
*/
export declare class SharedKeyManager {
private sharedKeys;
private keyDerivationCache;
/**
* Create a new shared encryption key
*/
createSharedKey(keyMetadata: SharedKeyMetadata, initialRecipients: {
publicKey: string;
permissions: SharePermissions;
}[], creatorPrivateKey: string | Uint8Array): Promise<SharedEncryptionKey>;
/**
* Transition from single recipient encryption to shared key encryption
*/
transitionToSharedKey(originalEncryptionResult: EncryptionResult, transitionRequest: KeyTransitionRequest): Promise<{
sharedKey: SharedEncryptionKey;
reEncryptedData: EncryptionResult;
}>;
/**
* Add new recipients to an existing shared key
*/
addRecipientsToSharedKey(keyId: string, newRecipients: {
publicKey: string;
permissions: SharePermissions;
}[], authorizerPrivateKey: string | Uint8Array, authorizerPublicKey: string): Promise<SharedEncryptionKey>;
/**
* Remove recipients from a shared key
*/
removeRecipientsFromSharedKey(keyId: string, recipientsToRemove: string[], authorizerPrivateKey: string | Uint8Array, authorizerPublicKey: string, rotateKey?: boolean): Promise<SharedEncryptionKey>;
/**
* Encrypt data using a shared key
*/
encryptWithSharedKey(data: string | Uint8Array, keyId: string, senderPrivateKey: string | Uint8Array, senderPublicKey: string): Promise<EncryptionResult>;
/**
* Decrypt data encrypted with a shared key
*/
decryptWithSharedKey(encryptionResult: EncryptionResult, recipientPrivateKey: string | Uint8Array, recipientPublicKey: string): Promise<Uint8Array>;
/**
* List all shared keys
*/
listSharedKeys(): Array<{
keyId: string;
name: string;
holders: number;
createdAt: number;
}>;
/**
* Get detailed information about a shared key
*/
getSharedKeyInfo(keyId: string): SharedEncryptionKey | null;
/**
* Export a shared key (encrypted for backup)
*/
exportSharedKey(keyId: string, exporterPrivateKey: string | Uint8Array, exporterPublicKey: string, backupPassword: string): Promise<string>;
/**
* Import a shared key from backup
*/
importSharedKey(exportedData: string, backupPassword: string): Promise<SharedEncryptionKey>;
private createEncryptedKeyShare;
private decryptKeyShare;
private decryptWithOriginalKey;
}