-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllms.txt
More file actions
63 lines (43 loc) · 1.89 KB
/
Copy pathllms.txt
File metadata and controls
63 lines (43 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# @forgesworn/shamir-core
> GF(256) Shamir's Secret Sharing for TypeScript. Zero runtime dependencies.
## What It Does
Splits a secret (any Uint8Array) into n shares where any threshold-sized subset can reconstruct the original. Uses Shamir's Secret Sharing over GF(256) with Lagrange interpolation.
## Install
npm install @forgesworn/shamir-core
## API
### splitSecret(secret: Uint8Array, threshold: number, shares: number): ShamirShare[]
Split a secret into shares. threshold must be in [2, 255]. shares must be in [threshold, 255].
```typescript
import { splitSecret } from '@forgesworn/shamir-core';
const shares = splitSecret(new Uint8Array([1, 2, 3]), 2, 3);
// shares[0] = { id: 1, threshold: 2, data: Uint8Array }
```
### reconstructSecret(shares: ShamirShare[], threshold: number): Uint8Array
Reconstruct from at least threshold shares. Uses first threshold shares only.
```typescript
import { reconstructSecret } from '@forgesworn/shamir-core';
const secret = reconstructSecret([shares[0], shares[2]], 2);
```
### ShamirShare
```typescript
interface ShamirShare {
id: number; // 1-255 (GF(256) evaluation point)
threshold: number; // 2-255 (minimum shares to reconstruct)
data: Uint8Array; // same length as original secret
}
```
### Errors
- ShamirError (base)
- ShamirValidationError extends ShamirError (bad inputs)
- ShamirCryptoError extends ShamirError (internal crypto)
## Key Properties
- Zero runtime dependencies (only Web Crypto for randomness)
- GF(256) with log/exp table lookup (same irreducible polynomial as AES: 0x11b)
- Polynomial coefficients zeroed after use
- Share IDs are 1-indexed (1-255), not 0-indexed
- No secret length limit
- Threshold metadata on shares is validated during reconstruction
- Node.js >= 18, browsers, Deno, Bun
## Related Packages
- @forgesworn/shamir-words: BIP-39 word encoding for shares
- dominion-protocol: epoch-based encrypted access control