From 0d77013aab69b2c847b89f79f8ab4744be5b3ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20L=C3=B3pez=20Guevara?= Date: Tue, 28 Feb 2023 12:19:10 -0300 Subject: [PATCH] =?UTF-8?q?chore(dx):=20add=20format=20script=20?= =?UTF-8?q?=F0=9F=92=85=20(#128)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.js | 2 +- justfile | 3 +++ nip06.test.js | 8 ++++++-- nip06.ts | 5 ++++- package.json | 4 +++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/build.js b/build.js index de51316..1b2dce6 100755 --- a/build.js +++ b/build.js @@ -17,7 +17,7 @@ esbuild packages: 'external' }) .then(() => { - const packageJson = JSON.stringify({ type: 'module' }) + const packageJson = JSON.stringify({type: 'module'}) fs.writeFileSync(`${__dirname}/lib/esm/package.json`, packageJson, 'utf8') console.log('esm build success.') diff --git a/justfile b/justfile index 509adc6..9ba1f1f 100644 --- a/justfile +++ b/justfile @@ -18,3 +18,6 @@ emit-types: publish: build emit-types npm publish + +format: + prettier --plugin-search-dir . --write . \ No newline at end of file diff --git a/nip06.test.js b/nip06.test.js index 1e28412..643e705 100644 --- a/nip06.test.js +++ b/nip06.test.js @@ -4,12 +4,16 @@ const {nip06} = require('./lib/nostr.cjs') test('generate private key from a mnemonic', async () => { const mnemonic = 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong' const privateKey = nip06.privateKeyFromSeedWords(mnemonic) - expect(privateKey).toEqual('c26cf31d8ba425b555ca27d00ca71b5008004f2f662470f8c8131822ec129fe2') + expect(privateKey).toEqual( + 'c26cf31d8ba425b555ca27d00ca71b5008004f2f662470f8c8131822ec129fe2' + ) }) test('generate private key from a mnemonic and passphrase', async () => { const mnemonic = 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong' const passphrase = '123' const privateKey = nip06.privateKeyFromSeedWords(mnemonic, passphrase) - expect(privateKey).toEqual('55a22b8203273d0aaf24c22c8fbe99608e70c524b17265641074281c8b978ae4') + expect(privateKey).toEqual( + '55a22b8203273d0aaf24c22c8fbe99608e70c524b17265641074281c8b978ae4' + ) }) diff --git a/nip06.ts b/nip06.ts index 037cb9e..6d37860 100644 --- a/nip06.ts +++ b/nip06.ts @@ -7,7 +7,10 @@ import { } from '@scure/bip39' import {HDKey} from '@scure/bip32' -export function privateKeyFromSeedWords(mnemonic: string, passphrase?: string): string { +export function privateKeyFromSeedWords( + mnemonic: string, + passphrase?: string +): string { let root = HDKey.fromMasterSeed(mnemonicToSeedSync(mnemonic, passphrase)) let privateKey = root.derive(`m/44'/1237'/0'/0/0`).privateKey if (!privateKey) throw new Error('could not derive private key') diff --git a/package.json b/package.json index 041565e..71b86ba 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "type": "git", "url": "https://github.com/nbd-wtf/nostr-tools.git" }, - "files": ["./lib/**/*"], + "files": [ + "./lib/**/*" + ], "types": "./lib/index.d.ts", "main": "lib/nostr.cjs.js", "module": "lib/esm/nostr.mjs",