8000 BIP-39/SLIP-39: Import from GH to auto-generate word lists by sectore · Pull Request #2 · sectore/wordlist · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

BIP-39/SLIP-39: Import from GH to auto-generate word lists #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md) word list
# [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md) | [SLIP-39](https://github.com/satoshilabs/slips/blob/master/slip-0039.md) word lists

Explore [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md) word lists in 10 languages. Filter words or search for word positions.
Explore [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md) word lists in 10 languages or [SLIP-39](https://github.com/satoshilabs/slips/blob/master/slip-0039.md) in English. Filter words or search for word positions.

## Live
## Live

https://bip39.bitcoinbeachtravemuende.de

Expand Down Expand Up @@ -32,6 +32,17 @@ bun run preview --open
bun run tests
```

## Import wordlists

Word lists have been imported from original sources of [`BIP-39`](https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md) and [`SLIP-39`](https://github.com/satoshilabs/slips/blob/master/slip-0039.md) located at GitHub.

Run following script to re-import those word lists.

```bash
bun run import:bip39
bun run import:slip39
```

## Built with

- [TypeScript](https://www.typescriptlang.org/)
Expand Down
Binary file modified bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 28 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
{
"name": "bip39-word-list",
"name": "bip39-slip39-wordlist",
"version": "0.0.1",
"devDependencies": {
"@effect/platform": "^0.58.2",
"@effect/platform-browser": "^0.37.2",
"@sveltejs/adapter-auto": "^3.0.0",
"@effect/platform": "^0.59.2",
"@effect/platform-bun": "^0.39.2",
"@effect/platform-browser": "^0.38.3",
"@sveltejs/adapter-auto": "^3.2.2",
"@sveltejs/adapter-static": "^3.0.2",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@types/eslint": "^8.56.7",
"@sveltejs/kit": "^2.5.18",
"@sveltejs/vite-plugin-svelte": "^3.1.1",
"@types/eslint": "^8.56.10",
"autoprefixer": "^10.4.19",
"bip39": "^3.1.0",
"bun-types": "^1.1.13",
"daisyui": "^4.12.2",
"effect": "^3.3.4",
"eslint": "^9.0.0",
"bun-types": "^1.1.20",
"daisyui": "^4.12.10",
"effect": "^3.5.6",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.36.0",
"globals": "^15.0.0",
"eslint-plugin-svelte": "^2.43.0",
"globals": "^15.8.0",
"jsdom": "^24.1.0",
"lucide-svelte": "^0.395.0",
"postcss": "^8.4.38",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"prettier-plugin-tailwindcss": "^0.6.4",
"svelte": "^5.0.0-next.158",
"svelte-check": "^3.6.0",
"postcss": "^8.4.39",
"prettier": "^3.3.3",
"prettier-plugin-svelte": "^3.2.6",
"prettier-plugin-tailwindcss": "^0.6.5",
"svelte": "^5.0.0-next.192",
"svelte-check": "^3.8.4",
"svelte-typewrite": "^2.0.0",
"tailwindcss": "^3.4.4",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"typescript-eslint": "^8.0.0-alpha.20",
"vite": "^5.0.3",
"tailwindcss": "^3.4.6",
"tslib": "^2.6.3",
"typescript": "^5.5.3",
"typescript-eslint": "^8.0.0-alpha.45",
"vite": "^5.3.4",
"vitest": "^1.6.0"
},
"private": true,
Expand All @@ -43,7 +43,9 @@
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"test": "vitest --run",
"lint": "prettier --check . && eslint .",
"format": "prettier --write ."
"format": "prettier --write .",
"import:bip39": "bun ./scripts/import-bip39.ts",
"import:slip39": "bun ./scripts/import-slip39.ts"
},
"type": "module"
}
29 changes: 29 additions & 0 deletions scripts/import-bip39.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Effect, Layer, pipe, Array as A } from 'effect';
import { BunRuntime } from '@effect/platform-bun';
import * as NodeFileSystem from '@effect/platform-node-shared/NodeFileSystem';
import { Config, program } from './import-wordlist';
import { GITHUB_URLS, RAW_GITHUB_URLS } from '../src/lib/const';
import { languages, WordListType } from '../src/lib/types';

const type: WordListType = 'bip39';

pipe(
languages,
A.map((lang) =>
Layer.succeed(
Config,
Config.of({
get: Effect.succeed({
type,
lang,
github_raw: new URL(RAW_GITHUB_URLS[type][lang]),
github_url: new URL(GITHUB_URLS[type][lang]),
pathToSave: `./src/lib/wordlists/bip39-${lang}.ts`
})
})
)
),
A.map((configL) => program.pipe(Effect.provide(Layer.merge(NodeFileSystem.layer, configL)))),
Effect.all,
BunRuntime.runMain
);
25 changes: 25 additions & 0 deletions scripts/import-slip39.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Effect, Layer } from 'effect';
import { BunRuntime } from '@effect/platform-bun';
import * as NodeFileSystem from '@effect/platform-node-shared/NodeFileSystem';
import { Config, program } from './import-wordlist';
import { GITHUB_URLS, RAW_GITHUB_URLS } from '../src/lib/const';
import { WordListType } from '../src/lib/types';

const type: WordListType = 'slip39';
// EN available only
const lang = 'en';

const ConfigLayer = Layer.succeed(
Config,
Config.of({
get: Effect.succeed({
type,
lang,
github_raw: new URL(RAW_GITHUB_URLS[type][lang]),
github_url: new URL(GITHUB_URLS[type][lang]),
pathToSave: `./src/lib/wordlists/slip39-${lang}.ts`
})
})
);

program.pipe(Effect.provide(Layer.merge(NodeFileSystem.layer, ConfigLayer)), BunRuntime.runMain);
93 changes: 93 additions & 0 deletions scripts/import-wordlist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Effect as E, pipe, String as S, Array as A, Context } from 'effect';
import { FileSystem } from '@effect/platform';
import { HttpClientRequest, HttpClient, HttpClientResponse } from '@effect/platform';
import prettier from 'prettier';
import { LANG, WordListType } from '../src/lib/types';

export class Config extends Context.Tag('Config')<
Config,
{
readonly get: E.Effect<{
readonly type: WordListType;
readonly lang: LANG;
readonly github_url: URL;
readonly github_raw: URL;
readonly pathToSave: string;
}>;
}
>() {}

const fetchWordlist = (raw_url: URL) =>
HttpClientRequest.get(raw_url).pipe(HttpClient.fetch, HttpClientResponse.text);

const parseWordlist = ({
result,
type,
url,
lang
}: {
result: string;
type: WordListType;
url: URL;
lang: LANG;
}): string =>
pipe(
result,
S.split(/\n/g),
A.map(S.trim),
A.filter(S.isNonEmpty),
(wordlist) => `
/**
* ${type} word list (${lang.toUpperCase()})
*
* @source ${url.toString()}
*
* Don't edit!
*/
const wordlist:string[] = [${pipe(
wordlist,
A.map((s) => `'${s}'`),
A.join(',')
)}]

export default wordlist
`
);

const formatWordlist = (wordlist: string, path: string) =>
E.gen(function* (_) {
yield* _(E.logInfo('Formatting ...'));
const formatted = yield* _(
E.promise(() =>
prettier.format(wordlist, {
filepath: path,
parser: 'typescript',
singleQuote: true,
trailingComma: 'none'
})
)
);
return formatted;
});

const writeWordlist = (wordlist: string, path: string) =>
E.gen(function* (_) {
yield* _(E.log(`Writing to ${path}`));
const fs = yield* _(FileSystem.FileSystem);
yield* _(fs.writeFileString(path, wordlist));
});

export const program = E.gen(function* (_) {
const config = yield* _(Config);
const { type, pathToSave, github_raw, github_url, lang } = yield* config.get;
yield* _(
E.log(
`\n~~~~~~~(${type.toUpperCase()}/${lang.toUpperCase()})~~~~~~~\nFetching word list from ${github_raw.toString()}`
)
);
const result = yield* _(fetchWordlist(github_raw));
const wordlist = parseWordlist({ result, type, url: github_url, lang });
const formatted = yield* _(formatWordlist(wordlist, pathToSave));
yield* _(writeWordlist(formatted, pathToSave));
yield* _(E.log(`DONE!`));
});
10 changes: 6 additions & 4 deletions src/Header.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts">
import { page } from '$app/stores';
import { AlignJustify, LayoutGrid, Moon, Repeat2, Sun } from 'lucide-svelte';
import store, { PATHS as P, lang, type LANG } from '$lib/store.svelte';
import store, { PATHS as P } from '$lib/store.svelte';
import { languages, type LANG } from '$lib/types';
import T from '$lib/theme.svelte';

const isPath = (path: string) => $page.url.pathname === path;
Expand Down Expand Up @@ -68,13 +69,14 @@
<div class="mt-5 flex flex-col items-center justify-center gap-1 text-gray-500 dark:text-gray-400">
{@render headline('flex md:hidden pt-10')}
<p class="text-xs uppercase">
{lang.length} languages
{languages.length} languages
</p>
<select
class="select select-ghost btn-sm select-xs bg-gray-200 text-gray-600 dark:bg-gray-600 dark:text-gray-400"
Event & { currentTarget: HTMLSelectElement }) => store.selectedLang = e.currentTarget.value as LANG}
Event & { currentTarget: HTMLSelectElement }) =>
(store.selectedLang = e.currentTarget.value as LANG)}
>
{#each lang as l (l)}
{#each languages as l (l)}
<option class="text-gray-600 dark:text-gray-400" selected={store.selectedLang === l} value={l}
>{l.toUpperCase()}</option
>
Expand Down
62 changes: 62 additions & 0 deletions src/lib/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type { LANG, WordListType } from './types';

const bip39Url = (file: string) => `https://github.com/bitcoin/bips/blob/master/bip-0039/${file}`;

type WordListUrls = Record<LANG, string>;

export const GITHUB_URLS: Record<WordListType, WordListUrls> = {
bip39: {
'zh-Hans': bip39Url('chinese_simplified.txt'),
'zh-Hant': bip39Url('chinese_traditional.txt'),
cz: bip39Url('czech.txt'),
en: bip39Url('english.txt'),
es: bip39Url('spanish.txt'),
fr: bip39Url('french.txt'),
it: bip39Url('italian.txt'),
jp: bip39Url('japanese.txt'),
kr: bip39Url('korean.txt'),
pt: bip39Url('portuguese.txt')
},
slip39: {
en: 'https://github.com/satoshilabs/slips/blob/master/slip-0039/wordlist.txt',
cz: '',
es: '',
fr: '',
it: '',
jp: '',
kr: '',
pt: '',
'zh-Hans': '',
'zh-Hant': ''
}
};

const bip39RawUrl = (file: string) =>
`https://raw.githubusercontent.com/bitcoin/bips/master/bip-0039/${file} `;

export const RAW_GITHUB_URLS: Record<WordListType, WordListUrls> = {
bip39: {
'zh-Hans': bip39RawUrl('chinese_simplified.txt'),
'zh-Hant': bip39RawUrl('chinese_traditional.txt'),
cz: bip39RawUrl('czech.txt'),
en: bip39RawUrl('english.txt'),
es: bip39RawUrl('spanish.txt'),
fr: bip39RawUrl('french.txt'),
it: bip39RawUrl('italian.txt'),
jp: bip39RawUrl('japanese.txt'),
kr: bip39RawUrl('korean.txt'),
pt: bip39RawUrl('portuguese.txt')
},
slip39: {
en: 'https://raw.githubusercontent.com/satoshilabs/slips/master/slip-0039/wordlist.txt',
cz: '',
es: '',
fr: '',
it: '',
jp: '',
kr: '',
pt: '',
'zh-Hans': '',
'zh-Hant': ''
}
};
Loading
Loading
0