shamir-mnemonic-ts 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/cipher.d.ts +3 -0
- package/dist/cipher.d.ts.map +1 -0
- package/dist/cipher.js +91 -0
- package/dist/cipher.js.map +1 -0
- package/dist/constants.d.ts +41 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +45 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/recovery.d.ts +18 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +126 -0
- package/dist/recovery.js.map +1 -0
- package/dist/rs1024.d.ts +5 -0
- package/dist/rs1024.d.ts.map +1 -0
- package/dist/rs1024.js +50 -0
- package/dist/rs1024.js.map +1 -0
- package/dist/shamir.d.ts +36 -0
- package/dist/shamir.d.ts.map +1 -0
- package/dist/shamir.js +448 -0
- package/dist/shamir.js.map +1 -0
- package/dist/share.d.ts +39 -0
- package/dist/share.d.ts.map +1 -0
- package/dist/share.js +194 -0
- package/dist/share.js.map +1 -0
- package/dist/src/cipher.js +90 -0
- package/dist/src/constants.js +44 -0
- package/dist/src/index.js +22 -0
- package/dist/src/recovery.js +127 -0
- package/dist/src/rs1024.js +55 -0
- package/dist/src/shamir.js +486 -0
- package/dist/src/share.js +196 -0
- package/dist/src/utils.js +97 -0
- package/dist/src/wordlist.js +136 -0
- package/dist/test-manual.js +78 -0
- package/dist/utils.d.ts +7 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +39 -0
- package/dist/utils.js.map +1 -0
- package/dist/wordlist.d.ts +4 -0
- package/dist/wordlist.d.ts.map +1 -0
- package/dist/wordlist.js +1069 -0
- package/dist/wordlist.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
18
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
19
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
20
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
21
|
+
function step(op) {
|
|
22
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
23
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
24
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
25
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
26
|
+
switch (op[0]) {
|
|
27
|
+
case 0: case 1: t = op; break;
|
|
28
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
29
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
30
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
31
|
+
default:
|
|
32
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
33
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
34
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
35
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
36
|
+
if (t[2]) _.ops.pop();
|
|
37
|
+
_.trys.pop(); continue;
|
|
38
|
+
}
|
|
39
|
+
op = body.call(thisArg, _);
|
|
40
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
41
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.MnemonicError = void 0;
|
|
46
|
+
exports.bitsToBytes = bitsToBytes;
|
|
47
|
+
exports.bitsToWords = bitsToWords;
|
|
48
|
+
exports.intToIndices = intToIndices;
|
|
49
|
+
var MnemonicError = /** @class */ (function (_super) {
|
|
50
|
+
__extends(MnemonicError, _super);
|
|
51
|
+
function MnemonicError(message) {
|
|
52
|
+
var _this = _super.call(this, message) || this;
|
|
53
|
+
_this.name = 'MnemonicError';
|
|
54
|
+
return _this;
|
|
55
|
+
}
|
|
56
|
+
return MnemonicError;
|
|
57
|
+
}(Error));
|
|
58
|
+
exports.MnemonicError = MnemonicError;
|
|
59
|
+
function _roundBits(n, radixBits) {
|
|
60
|
+
/** Get the number of `radixBits`-sized digits required to store a `n`-bit value. */
|
|
61
|
+
return Math.ceil(n / radixBits);
|
|
62
|
+
}
|
|
63
|
+
function bitsToBytes(n) {
|
|
64
|
+
/** Round up bit count to whole bytes. */
|
|
65
|
+
return _roundBits(n, 8);
|
|
66
|
+
}
|
|
67
|
+
function bitsToWords(n) {
|
|
68
|
+
/** Round up bit count to a multiple of word size. */
|
|
69
|
+
// Import constants here to handle circular dependency
|
|
70
|
+
// This will work as long as calls to bitsToWords only happen *after* RADIX_BITS are declared
|
|
71
|
+
var RADIX_BITS = require('./constants').RADIX_BITS;
|
|
72
|
+
if (!RADIX_BITS) {
|
|
73
|
+
throw new Error('Declare RADIX_BITS *before* calling this');
|
|
74
|
+
}
|
|
75
|
+
return _roundBits(n, RADIX_BITS);
|
|
76
|
+
}
|
|
77
|
+
function intToIndices(value, length, radixBits) {
|
|
78
|
+
var mask, i;
|
|
79
|
+
return __generator(this, function (_a) {
|
|
80
|
+
switch (_a.label) {
|
|
81
|
+
case 0:
|
|
82
|
+
mask = (1 << radixBits) - 1;
|
|
83
|
+
i = length - 1;
|
|
84
|
+
_a.label = 1;
|
|
85
|
+
case 1:
|
|
86
|
+
if (!(i >= 0)) return [3 /*break*/, 4];
|
|
87
|
+
return [4 /*yield*/, (value >> (i * radixBits)) & mask];
|
|
88
|
+
case 2:
|
|
89
|
+
_a.sent();
|
|
90
|
+
_a.label = 3;
|
|
91
|
+
case 3:
|
|
92
|
+
i--;
|
|
93
|
+
return [3 /*break*/, 1];
|
|
94
|
+
case 4: return [2 /*return*/];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
36
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
37
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
38
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
39
|
+
function step(op) {
|
|
40
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
41
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
42
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
43
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
44
|
+
switch (op[0]) {
|
|
45
|
+
case 0: case 1: t = op; break;
|
|
46
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
47
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
48
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
49
|
+
default:
|
|
50
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
51
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
52
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
53
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
54
|
+
if (t[2]) _.ops.pop();
|
|
55
|
+
_.trys.pop(); continue;
|
|
56
|
+
}
|
|
57
|
+
op = body.call(thisArg, _);
|
|
58
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
59
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
63
|
+
exports.wordsFromIndices = wordsFromIndices;
|
|
64
|
+
exports.mnemonicFromIndices = mnemonicFromIndices;
|
|
65
|
+
exports.mnemonicToIndices = mnemonicToIndices;
|
|
66
|
+
var fs = __importStar(require("fs"));
|
|
67
|
+
var path = __importStar(require("path"));
|
|
68
|
+
var constants_1 = require("./constants");
|
|
69
|
+
var utils_1 = require("./utils");
|
|
70
|
+
function _loadWordlist() {
|
|
71
|
+
// Try multiple possible paths for wordlist.txt
|
|
72
|
+
var wordlistPath = path.join(__dirname, 'wordlist.txt');
|
|
73
|
+
if (!fs.existsSync(wordlistPath)) {
|
|
74
|
+
// Fallback: try parent directory (for compiled output)
|
|
75
|
+
wordlistPath = path.join(__dirname, '..', 'src', 'wordlist.txt');
|
|
76
|
+
}
|
|
77
|
+
if (!fs.existsSync(wordlistPath)) {
|
|
78
|
+
// Another fallback: try current directory
|
|
79
|
+
wordlistPath = path.join(process.cwd(), 'src', 'wordlist.txt');
|
|
80
|
+
}
|
|
81
|
+
var wordlistContent = fs.readFileSync(wordlistPath, 'utf8');
|
|
82
|
+
var wordlist = wordlistContent
|
|
83
|
+
.split('\n')
|
|
84
|
+
.map(function (word) { return word.trim(); })
|
|
85
|
+
.filter(function (word) { return word.length > 0; });
|
|
86
|
+
if (wordlist.length !== constants_1.RADIX) {
|
|
87
|
+
throw new Error("The wordlist should contain ".concat(constants_1.RADIX, " words, but it contains ").concat(wordlist.length, " words."));
|
|
88
|
+
}
|
|
89
|
+
var wordIndexMap = new Map();
|
|
90
|
+
wordlist.forEach(function (word, index) {
|
|
91
|
+
wordIndexMap.set(word, index);
|
|
92
|
+
});
|
|
93
|
+
return [wordlist, wordIndexMap];
|
|
94
|
+
}
|
|
95
|
+
var _a = _loadWordlist(), WORDLIST = _a[0], WORD_INDEX_MAP = _a[1];
|
|
96
|
+
function wordsFromIndices(indices) {
|
|
97
|
+
var _i, indices_1, i;
|
|
98
|
+
return __generator(this, function (_a) {
|
|
99
|
+
switch (_a.label) {
|
|
100
|
+
case 0:
|
|
101
|
+
_i = 0, indices_1 = indices;
|
|
102
|
+
_a.label = 1;
|
|
103
|
+
case 1:
|
|
104
|
+
if (!(_i < indices_1.length)) return [3 /*break*/, 4];
|
|
105
|
+
i = indices_1[_i];
|
|
106
|
+
return [4 /*yield*/, WORDLIST[i]];
|
|
107
|
+
case 2:
|
|
108
|
+
_a.sent();
|
|
109
|
+
_a.label = 3;
|
|
110
|
+
case 3:
|
|
111
|
+
_i++;
|
|
112
|
+
return [3 /*break*/, 1];
|
|
113
|
+
case 4: return [2 /*return*/];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function mnemonicFromIndices(indices) {
|
|
118
|
+
return Array.from(wordsFromIndices(indices)).join(' ');
|
|
119
|
+
}
|
|
120
|
+
function mnemonicToIndices(mnemonic) {
|
|
121
|
+
try {
|
|
122
|
+
return mnemonic.split(/\s+/).map(function (word) {
|
|
123
|
+
var index = WORD_INDEX_MAP.get(word.toLowerCase());
|
|
124
|
+
if (index === undefined) {
|
|
125
|
+
throw new utils_1.MnemonicError("Invalid mnemonic word ".concat(word, "."));
|
|
126
|
+
}
|
|
127
|
+
return index;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (error instanceof utils_1.MnemonicError) {
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
throw new utils_1.MnemonicError("Invalid mnemonic word.");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
var crypto = __importStar(require("crypto"));
|
|
37
|
+
var shamir = __importStar(require("./index"));
|
|
38
|
+
// Exemple 1 : Partage basique sans passphrase
|
|
39
|
+
console.log('=== Test 1 : Partage basique ===');
|
|
40
|
+
var masterSecret = Buffer.from('ABCDEFGHIJKLMNOP', 'utf8');
|
|
41
|
+
var mnemonics = shamir.generateMnemonics(1, // group threshold (1 groupe requis)
|
|
42
|
+
[[3, 5]], // (member threshold, member count) = 3 sur 5 parts nécessaires
|
|
43
|
+
masterSecret);
|
|
44
|
+
console.log('Mnemonics générés:');
|
|
45
|
+
mnemonics[0].forEach(function (mnemonic, index) {
|
|
46
|
+
console.log(" Part ".concat(index + 1, ": ").concat(mnemonic));
|
|
47
|
+
});
|
|
48
|
+
// Récupération avec 3 parts (minimum requis)
|
|
49
|
+
var recovered1 = shamir.combineMnemonics(mnemonics[0].slice(0, 3));
|
|
50
|
+
console.log('\nSecret récupéré (avec parts 1-3):', recovered1.toString('utf8'));
|
|
51
|
+
console.log('Égal au secret original?', recovered1.equals(masterSecret));
|
|
52
|
+
// Récupération avec 3 autres parts
|
|
53
|
+
var recovered2 = shamir.combineMnemonics(mnemonics[0].slice(2, 5));
|
|
54
|
+
console.log('\nSecret récupéré (avec parts 3-5):', recovered2.toString('utf8'));
|
|
55
|
+
console.log('Égal au secret original?', recovered2.equals(masterSecret));
|
|
56
|
+
// Exemple 2 : Avec passphrase
|
|
57
|
+
console.log('\n=== Test 2 : Avec passphrase ===');
|
|
58
|
+
var passphrase = Buffer.from('mon-mot-de-passe', 'utf8');
|
|
59
|
+
var mnemonicsWithPass = shamir.generateMnemonics(1, [[3, 5]], masterSecret, passphrase);
|
|
60
|
+
console.log('Mnemonics avec passphrase:');
|
|
61
|
+
mnemonicsWithPass[0].slice(0, 3).forEach(function (mnemonic, index) {
|
|
62
|
+
console.log(" Part ".concat(index + 1, ": ").concat(mnemonic));
|
|
63
|
+
});
|
|
64
|
+
var recoveredWithPass = shamir.combineMnemonics(mnemonicsWithPass[0].slice(0, 3), passphrase);
|
|
65
|
+
console.log('\nSecret récupéré avec passphrase:', recoveredWithPass.toString('utf8'));
|
|
66
|
+
console.log('Égal au secret original?', recoveredWithPass.equals(masterSecret));
|
|
67
|
+
// Exemple 3 : Secret aléatoire
|
|
68
|
+
console.log('\n=== Test 3 : Secret aléatoire ===');
|
|
69
|
+
var randomSecret = crypto.randomBytes(16);
|
|
70
|
+
var randomMnemonics = shamir.generateMnemonics(1, [[2, 3]], randomSecret)[0];
|
|
71
|
+
console.log('Secret aléatoire (hex):', randomSecret.toString('hex'));
|
|
72
|
+
console.log('Mnemonics:');
|
|
73
|
+
randomMnemonics.forEach(function (mnemonic, index) {
|
|
74
|
+
console.log(" Part ".concat(index + 1, ": ").concat(mnemonic));
|
|
75
|
+
});
|
|
76
|
+
var recoveredRandom = shamir.combineMnemonics(randomMnemonics.slice(0, 2));
|
|
77
|
+
console.log('\nSecret récupéré (hex):', recoveredRandom.toString('hex'));
|
|
78
|
+
console.log('Égal au secret original?', recoveredRandom.equals(randomSecret));
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class MnemonicError extends Error {
|
|
2
|
+
constructor(message?: string);
|
|
3
|
+
}
|
|
4
|
+
export declare function bitsToBytes(n: number): number;
|
|
5
|
+
export declare function bitsToWords(n: number): number;
|
|
6
|
+
export declare function intToIndices(value: number, length: number, radixBits: number): Generator<number>;
|
|
7
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,CAAC,EAAE,MAAM;CAI7B;AAOD,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAG7C;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAW7C;AAED,wBAAiB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAMjG"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MnemonicError = void 0;
|
|
4
|
+
exports.bitsToBytes = bitsToBytes;
|
|
5
|
+
exports.bitsToWords = bitsToWords;
|
|
6
|
+
exports.intToIndices = intToIndices;
|
|
7
|
+
class MnemonicError extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'MnemonicError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.MnemonicError = MnemonicError;
|
|
14
|
+
function _roundBits(n, radixBits) {
|
|
15
|
+
/** Get the number of `radixBits`-sized digits required to store a `n`-bit value. */
|
|
16
|
+
return Math.ceil(n / radixBits);
|
|
17
|
+
}
|
|
18
|
+
function bitsToBytes(n) {
|
|
19
|
+
/** Round up bit count to whole bytes. */
|
|
20
|
+
return _roundBits(n, 8);
|
|
21
|
+
}
|
|
22
|
+
function bitsToWords(n) {
|
|
23
|
+
/** Round up bit count to a multiple of word size. */
|
|
24
|
+
// Import constants here to handle circular dependency
|
|
25
|
+
// This will work as long as calls to bitsToWords only happen *after* RADIX_BITS are declared
|
|
26
|
+
const { RADIX_BITS } = require('./constants');
|
|
27
|
+
if (!RADIX_BITS) {
|
|
28
|
+
throw new Error('Declare RADIX_BITS *before* calling this');
|
|
29
|
+
}
|
|
30
|
+
return _roundBits(n, RADIX_BITS);
|
|
31
|
+
}
|
|
32
|
+
function* intToIndices(value, length, radixBits) {
|
|
33
|
+
/** Convert an integer value to indices in big endian order. */
|
|
34
|
+
const mask = (1 << radixBits) - 1;
|
|
35
|
+
for (let i = length - 1; i >= 0; i--) {
|
|
36
|
+
yield (value >> (i * radixBits)) & mask;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAYA,kCAGC;AAED,kCAWC;AAED,oCAMC;AApCD,MAAa,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AALD,sCAKC;AAED,SAAS,UAAU,CAAC,CAAS,EAAE,SAAiB;IAC9C,oFAAoF;IACpF,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,SAAgB,WAAW,CAAC,CAAS;IACnC,yCAAyC;IACzC,OAAO,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1B,CAAC;AAED,SAAgB,WAAW,CAAC,CAAS;IACnC,qDAAqD;IACrD,sDAAsD;IACtD,6FAA6F;IAC7F,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAE9C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;AACnC,CAAC;AAED,QAAe,CAAC,CAAC,YAAY,CAAC,KAAa,EAAE,MAAc,EAAE,SAAiB;IAC5E,+DAA+D;IAC/D,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC;IAC1C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function wordsFromIndices(indices: Iterable<number>): Generator<string>;
|
|
2
|
+
export declare function mnemonicFromIndices(indices: Iterable<number>): string;
|
|
3
|
+
export declare function mnemonicToIndices(mnemonic: string): number[];
|
|
4
|
+
//# sourceMappingURL=wordlist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wordlist.d.ts","sourceRoot":"","sources":["../src/wordlist.ts"],"names":[],"mappings":"AAohCA,wBAAiB,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,CAI9E;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,CAErE;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAe5D"}
|