shamir-mnemonic-ts 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +96 -28
  2. package/package.json +6 -2
package/README.md CHANGED
@@ -1,25 +1,32 @@
1
1
  # Shamir Mnemonic TypeScript
2
2
 
3
- TypeScript implementation of SLIP-0039 Shamir Secret Sharing for mnemonic seed phrases.
3
+ TypeScript implementation of [SLIP-0039](https://github.com/satoshilabs/slips/blob/master/slip-0039.md) Shamir Secret Sharing for mnemonic seed phrases.
4
4
 
5
5
  This is a complete conversion of the Python [python-shamir-mnemonic](https://github.com/trezor/python-shamir-mnemonic/tree/master) reference implementation to TypeScript for Node.js.
6
6
 
7
- ## Specification
7
+ **Zero runtime dependencies.** This library does not depend on any third-party packages.
8
8
 
9
- See [https://github.com/satoshilabs/slips/blob/master/slip-0039.md](https://github.com/satoshilabs/slips/blob/master/slip-0039.md) for full specification.
9
+ ## Features
10
10
 
11
- ## Installation
11
+ - **SLIP-0039 compliant** — Binary-compatible with the standard mnemonic format
12
+ - **Group sharing** — Split a secret across multiple groups (e.g. 2-of-3 groups, each with its own member threshold)
13
+ - **Passphrase protection** — Optional encryption of the master secret (printable ASCII only)
14
+ - **Extendable backups** — Support for iteration exponent to strengthen passphrase derivation
15
+ - **Low-level API** — `splitEms` / `recoverEms` for working with encrypted master secrets, plus `encrypt` / `decrypt` and `decodeMnemonics`
16
+ - **Interactive recovery** — `RecoveryState` for step-by-step mnemonic entry and progress tracking
12
17
 
13
- ### From npm (for users)
18
+ ## Requirements
14
19
 
15
- ```bash
16
- npm install shamir-mnemonic-ts
17
- ```
20
+ - **Node.js** >= 14.0.0
18
21
 
19
- ## Building
22
+ ## Specification
23
+
24
+ See [SLIP-0039](https://github.com/satoshilabs/slips/blob/master/slip-0039.md) for the full specification.
25
+
26
+ ## Installation
20
27
 
21
28
  ```bash
22
- npm run build
29
+ npm install shamir-mnemonic-ts
23
30
  ```
24
31
 
25
32
  ## Testing
@@ -31,41 +38,102 @@ npm run test:vectors
31
38
 
32
39
  ## Usage
33
40
 
41
+ ### Basic: split and recover
42
+
34
43
  ```typescript
35
44
  import * as shamir from 'shamir-mnemonic-ts';
36
45
 
37
- // Generate mnemonic shares
38
46
  const masterSecret = Buffer.from('your-secret-here');
39
47
  const mnemonics = shamir.generateMnemonics(
40
- 1, // group threshold
41
- [[3, 5]], // (member threshold, member count) for each group
42
- masterSecret,
43
- Buffer.from('passphrase', 'utf8')
48
+ 1, // group threshold (1 group required)
49
+ [[3, 5]], // (member threshold, member count): 3 of 5 shares per group
50
+ masterSecret
44
51
  );
45
52
 
46
- // Recover master secret
53
+ // Recover with any 3 of 5 shares
54
+ const recovered = shamir.combineMnemonics(mnemonics[0].slice(0, 3));
55
+ ```
56
+
57
+ ### With passphrase
58
+
59
+ ```typescript
60
+ import * as shamir from 'shamir-mnemonic-ts';
61
+
62
+ const masterSecret = Buffer.from('your-secret-here');
63
+ const passphrase = Buffer.from('my passphrase', 'utf8');
64
+ const mnemonics = shamir.generateMnemonics(
65
+ 1,
66
+ [[3, 5]],
67
+ masterSecret,
68
+ passphrase
69
+ )[0];
70
+
47
71
  const recovered = shamir.combineMnemonics(
48
- mnemonics[0].slice(0, 3), // any 3 of 5 shares
49
- Buffer.from('passphrase', 'utf8')
72
+ mnemonics.slice(0, 3),
73
+ passphrase
74
+ );
75
+ ```
76
+
77
+ ### Group sharing (e.g. 2-of-3 groups)
78
+
79
+ ```typescript
80
+ import * as shamir from 'shamir-mnemonic-ts';
81
+
82
+ const masterSecret = Buffer.from('your-secret-here');
83
+ // 2 groups required; each group has (member threshold, member count)
84
+ const mnemonics = shamir.generateMnemonics(
85
+ 2, // group threshold
86
+ [[3, 5], [2, 3], [1, 1]], // group 0: 3-of-5, group 1: 2-of-3, group 2: 1-of-1
87
+ masterSecret
50
88
  );
89
+
90
+ // Recover with any 2 groups (e.g. 3 from group 0 + 2 from group 1)
91
+ const subset = [
92
+ ...mnemonics[0].slice(0, 3),
93
+ ...mnemonics[1].slice(0, 2),
94
+ ];
95
+ const recovered = shamir.combineMnemonics(subset);
51
96
  ```
52
97
 
53
- ## Structure
98
+ ### Interactive recovery with `RecoveryState`
99
+
100
+ ```typescript
101
+ import * as shamir from 'shamir-mnemonic-ts';
102
+
103
+ const state = new shamir.RecoveryState();
104
+ const passphrase = Buffer.from('my passphrase', 'utf8');
105
+
106
+ // Add mnemonics one by one (e.g. from user input)
107
+ function addMnemonic(mnemonic: string) {
108
+ const groups = shamir.decodeMnemonics([mnemonic]);
109
+ for (const group of groups.values()) {
110
+ for (const share of group) state.addShare(share);
111
+ }
112
+ }
113
+ addMnemonic('academic academic academic ...'); // first share
114
+ addMnemonic('academic academic academic ...'); // second share
115
+ // ...
116
+
117
+ state.groupStatus(0); // [entered, threshold] for group 0
118
+ state.groupPrefix(0); // first words of group 0
119
+ state.isComplete(); // true when enough shares to recover
120
+
121
+ const recovered = state.recover(passphrase);
122
+ ```
54
123
 
55
- - `src/constants.ts` - SLIP-0039 constants
56
- - `src/utils.ts` - Utility functions and error classes
57
- - `src/wordlist.ts` - Wordlist management
58
- - `src/rs1024.ts` - RS1024 checksum implementation
59
- - `src/cipher.ts` - Feistel cipher for encryption/decryption
60
- - `src/share.ts` - Share encoding/decoding
61
- - `src/shamir.ts` - Core Shamir secret sharing algorithms
62
- - `src/recovery.ts` - Interactive recovery state management
63
- - `src/index.ts` - Public API exports
64
124
 
65
125
  ## Compatibility
66
126
 
67
127
  This implementation is binary-compatible with the SLIP-0039 standard and produces/consumes the standard mnemonic format.
68
128
 
129
+ ## Security
130
+
131
+ To report a vulnerability, see [SECURITY.md](SECURITY.md).
132
+
133
+ ## Contributing
134
+
135
+ See [CONTRIBUTING.md](CONTRIBUTING.md).
136
+
69
137
  ## License
70
138
 
71
139
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shamir-mnemonic-ts",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "TypeScript implementation of SLIP-0039 Shamir Secret Sharing for mnemonic seed phrases",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,7 +31,11 @@
31
31
  "slip-0039",
32
32
  "cryptography"
33
33
  ],
34
- "author": "FRAG-MENT",
34
+ "author": {
35
+ "name": "FRAG-MENT",
36
+ "email": "contact@frag-ment.io",
37
+ "url": "https://frag-ment.io"
38
+ },
35
39
  "license": "MIT",
36
40
  "repository": {
37
41
  "type": "git",