GhostShardManager
Implements Shamir Secret Sharing for wallet seed backup. Splits the seed into multiple shards with a configurable threshold for reconstruction.
Import
import { GhostShardManager } from '@knight-shield/core';
Constructor
const manager = new GhostShardManager(totalShares?, threshold?);
// Defaults: totalShares = 5, threshold = 3
Methods
splitSeed(seedHex): Promise<Shard[]>
Splits a hex-encoded seed into shards using Shamir's algorithm.
const shards = await manager.splitSeed(seedHex);
// Returns 5 Shard objects
Each shard contains:
interface Shard {
shardId: string; // UUID v4
shardData: Uint8Array; // Raw shard bytes
storageType: ShardStorageType; // Assigned storage location
hash: string; // SHA-256 hash for verification
}
reconstructSeed(shards): Promise<string>
Reconstructs the original seed from a subset of shards. Requires at least threshold (default: 3) shards.
const seed = await manager.reconstructSeed([shard1, shard2, shard3]);
// Returns the original hex seed
assignStorage(shardId, storageType): void
Assigns a storage location to a shard.
manager.assignStorage(shard.shardId, 'usb');
manager.assignStorage(shard.shardId, 'pwd_mgr');
Available storage types: 'did', 'usb', 'pwd_mgr', 'email', 'cloud', 'device'.
getShards(): Shard[]
Returns all current shards.
const shards = manager.getShards();
verifyShard(shard): Promise<boolean>
Verifies a shard by recomputing its SHA-256 hash and comparing with the stored hash.
const isValid = await manager.verifyShard(shard);
clear(): void
Securely wipes all shard data from memory. Each shard's Uint8Array is filled with zeros before the array is cleared.
manager.clear();
// All shardData arrays are zeroed out
Shamir Parameters
| Parameter | Default | Description |
|---|---|---|
totalShares | 5 | Total number of shards generated |
threshold | 3 | Minimum shards needed to reconstruct |
The underlying implementation uses secrets.js-34r7h for cryptographically secure share generation.
Storage Type Encoding
For on-chain registration, storage types are encoded as integers:
const SHARD_STORAGE_TYPE_MAP = {
did: 1,
usb: 2,
pwd_mgr: 3,
email: 4,
cloud: 5,
device: 6,
};