chore(dx): add format script 💅 (#128)
This commit is contained in:
parent
4c415280aa
commit
0d77013aab
2
build.js
2
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.')
|
||||
|
|
3
justfile
3
justfile
|
@ -18,3 +18,6 @@ emit-types:
|
|||
publish: build
|
||||
emit-types
|
||||
npm publish
|
||||
|
||||
format:
|
||||
prettier --plugin-search-dir . --write .
|
|
@ -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'
|
||||
)
|
||||
})
|
||||
|
|
5
nip06.ts
5
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')
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue