Skip to content

Commit

Permalink
fixing formatting with Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Anderson-Juhasc authored and fiatjaf committed May 27, 2024
1 parent faa1a9d commit 4f1dc9e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
22 changes: 16 additions & 6 deletions nip06.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
privateKeyFromSeedWords,
accountFromSeedWords,
extendedKeysFromSeedWords,
accountFromExtendedKey
accountFromExtendedKey,
} from './nip06.ts'

test('generate private key from a mnemonic', async () => {
Expand Down Expand Up @@ -44,22 +44,32 @@ test('generate extended keys from mnemonic', () => {
const mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
const passphrase = ''
const extendedAccountIndex = 0
const { privateExtendedKey, publicExtendedKey } = extendedKeysFromSeedWords(mnemonic, passphrase, extendedAccountIndex)
const { privateExtendedKey, publicExtendedKey } = extendedKeysFromSeedWords(
mnemonic,
passphrase,
extendedAccountIndex,
)

expect(privateExtendedKey).toBe('xprv9z78fizET65qsCaRr1MSutTSGk1fcKfSt1sBqmuWShtkjRJJ4WCKcSnha6EmgNzFSsyom3MWtydHyPtJtSLZQUtictVQtM2vkPcguh6TQCH')
expect(publicExtendedKey).toBe('xpub6D6V5EX8HTe95getx2tTH2QApmrA1nPJFEnneAK813RjcDdSc3WaAF7BRNpTF7o7zXjVm3DD3VMX66jhQ7wLaZ9sS6NzyfiwfzqDZbxvpDN')
expect(privateExtendedKey).toBe(
'xprv9z78fizET65qsCaRr1MSutTSGk1fcKfSt1sBqmuWShtkjRJJ4WCKcSnha6EmgNzFSsyom3MWtydHyPtJtSLZQUtictVQtM2vkPcguh6TQCH',
)
expect(publicExtendedKey).toBe(
'xpub6D6V5EX8HTe95getx2tTH2QApmrA1nPJFEnneAK813RjcDdSc3WaAF7BRNpTF7o7zXjVm3DD3VMX66jhQ7wLaZ9sS6NzyfiwfzqDZbxvpDN',
)
})

test('generate account from extended private key', () => {
const xprv = 'xprv9z78fizET65qsCaRr1MSutTSGk1fcKfSt1sBqmuWShtkjRJJ4WCKcSnha6EmgNzFSsyom3MWtydHyPtJtSLZQUtictVQtM2vkPcguh6TQCH'
const xprv =
'xprv9z78fizET65qsCaRr1MSutTSGk1fcKfSt1sBqmuWShtkjRJJ4WCKcSnha6EmgNzFSsyom3MWtydHyPtJtSLZQUtictVQtM2vkPcguh6TQCH'
const { privateKey, publicKey } = accountFromExtendedKey(xprv)

expect(privateKey).toBe('5f29af3b9676180290e77a4efad265c4c2ff28a5302461f73597fda26bb25731')
expect(publicKey).toBe('e8bcf3823669444d0b49ad45d65088635d9fd8500a75b5f20b59abefa56a144f')
})

test('generate account from extended public key', () => {
const xpub = 'xpub6D6V5EX8HTe95getx2tTH2QApmrA1nPJFEnneAK813RjcDdSc3WaAF7BRNpTF7o7zXjVm3DD3VMX66jhQ7wLaZ9sS6NzyfiwfzqDZbxvpDN'
const xpub =
'xpub6D6V5EX8HTe95getx2tTH2QApmrA1nPJFEnneAK813RjcDdSc3WaAF7BRNpTF7o7zXjVm3DD3VMX66jhQ7wLaZ9sS6NzyfiwfzqDZbxvpDN'
const { publicKey } = accountFromExtendedKey(xpub)

expect(publicKey).toBe('e8bcf3823669444d0b49ad45d65088635d9fd8500a75b5f20b59abefa56a144f')
Expand Down
25 changes: 18 additions & 7 deletions nip06.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ export function privateKeyFromSeedWords(mnemonic: string, passphrase?: string, a
return bytesToHex(privateKey)
}

export function accountFromSeedWords(mnemonic: string, passphrase?: string, accountIndex = 0): {
privateKey: string,
publicKey: string,
export function accountFromSeedWords(
mnemonic: string,
passphrase?: string,
accountIndex = 0,
): {
privateKey: string
publicKey: string
} {
const root = HDKey.fromMasterSeed(mnemonicToSeedSync(mnemonic, passphrase))
const seed = root.derive(`${DERIVATION_PATH}/${accountIndex}'/0/0`)
Expand All @@ -26,8 +30,12 @@ export function accountFromSeedWords(mnemonic: string, passphrase?: string, acco
return { privateKey, publicKey }
}

export function extendedKeysFromSeedWords(mnemonic: string, passphrase?: string, extendedAccountIndex = 0): {
privateExtendedKey: string,
export function extendedKeysFromSeedWords(
mnemonic: string,
passphrase?: string,
extendedAccountIndex = 0,
): {
privateExtendedKey: string
publicExtendedKey: string
} {
let root = HDKey.fromMasterSeed(mnemonicToSeedSync(mnemonic, passphrase))
Expand All @@ -38,8 +46,11 @@ export function extendedKeysFromSeedWords(mnemonic: string, passphrase?: string,
return { privateExtendedKey, publicExtendedKey }
}

export function accountFromExtendedKey(base58key: string, accountIndex = 0): {
privateKey?: string,
export function accountFromExtendedKey(
base58key: string,
accountIndex = 0,
): {
privateKey?: string
publicKey: string
} {
let extendedKey = HDKey.fromExtendedKey(base58key)
Expand Down
2 changes: 1 addition & 1 deletion relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export class Relay extends AbstractRelay {
}
}

export type RelayRecord = Record<string, { read: boolean; write: boolean }>;
export type RelayRecord = Record<string, { read: boolean; write: boolean }>

export * from './abstract-relay.ts'

0 comments on commit 4f1dc9e

Please sign in to comment.