Skip to content

Commit ecc8a1f

Browse files
committed
v1
1 parent a0ca7d9 commit ecc8a1f

18 files changed

+5663
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

dist/index.d.mts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare function emojiSequenceToSeed(mnemonic: string): string;
2+
3+
declare function generateSequence(bits?: number): string;
4+
5+
export { emojiSequenceToSeed, generateSequence };

dist/index.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare function emojiSequenceToSeed(mnemonic: string): string;
2+
3+
declare function generateSequence(bits?: number): string;
4+
5+
export { emojiSequenceToSeed, generateSequence };

dist/index.js

+77
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.mjs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// src/seed-generation/generate-seed.ts
2+
import * as crypto from "crypto";
3+
function normalize(str) {
4+
return (str || "").normalize("NFKD");
5+
}
6+
function emojiSequenceToSeed(mnemonic) {
7+
const mnemonicBuffer = Uint8Array.from(Buffer.from(normalize(mnemonic), "utf8"));
8+
const salt = "emojiseed";
9+
return crypto.pbkdf2Sync(mnemonicBuffer, salt, 2048, 64, "sha512").toString("hex");
10+
}
11+
12+
// src/sequence-creation/generate-emoji-sequence.ts
13+
import * as crypto2 from "crypto";
14+
import emojis from "emoji.json/emoji-compact.json";
15+
var EMOJI_LIST = emojis;
16+
function generateEntropy(bits) {
17+
return crypto2.randomBytes(bits / 8);
18+
}
19+
function entropyToMnemonic(entropy) {
20+
const entropyBits = Array.from(entropy).map((byte) => byte.toString(2).padStart(8, "0")).join("");
21+
const checksumBits = crypto2.createHash("sha256").update(entropy).digest().toString("hex").slice(0, entropy.length / 4).split("").map((hex) => parseInt(hex, 16).toString(2).padStart(4, "0")).join("");
22+
const bits = entropyBits + checksumBits;
23+
const mnemonic = [];
24+
for (let i = 0; i < bits.length; i += 11) {
25+
const idx = parseInt(bits.slice(i, i + 11), 2);
26+
mnemonic.push(EMOJI_LIST[idx % EMOJI_LIST.length]);
27+
}
28+
return mnemonic.join(" ");
29+
}
30+
function generateSequence(bits = 32) {
31+
const entropy = generateEntropy(bits);
32+
const mnemonic = entropyToMnemonic(entropy);
33+
return mnemonic;
34+
}
35+
export {
36+
emojiSequenceToSeed,
37+
generateSequence
38+
};
39+
//# sourceMappingURL=index.mjs.map

dist/index.mjs.map

+1
Original file line numberDiff line numberDiff line change

jest.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
preset: "ts-jest",
3+
testEnvironment: "node",
4+
};

0 commit comments

Comments
 (0)