Skip to content

Commit

Permalink
prettify and lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Dec 16, 2023
1 parent 0108e3b commit d16f3f7
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 24 deletions.
8 changes: 2 additions & 6 deletions nip06.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ test('generate private key from a mnemonic', async () => {
test('generate private key for account 1 from a mnemonic', async () => {
const mnemonic = 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong'
const privateKey = privateKeyFromSeedWords(mnemonic, undefined, 1)
expect(privateKey).toEqual(
'b5fc7f229de3fb5c189063e3b3fc6c921d8f4366cff5bd31c6f063493665eb2b'
)
expect(privateKey).toEqual('b5fc7f229de3fb5c189063e3b3fc6c921d8f4366cff5bd31c6f063493665eb2b')
})

test('generate private key from a mnemonic and passphrase', async () => {
Expand All @@ -25,7 +23,5 @@ test('generate private key for account 1 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 = privateKeyFromSeedWords(mnemonic, passphrase, 1)
expect(privateKey).toEqual(
'2e0f7bd9e3c3ebcdff1a90fb49c913477e7c055eba1a415d571b6a8c714c7135'
)
expect(privateKey).toEqual('2e0f7bd9e3c3ebcdff1a90fb49c913477e7c055eba1a415d571b6a8c714c7135')
})
6 changes: 1 addition & 5 deletions nip06.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import { wordlist } from '@scure/bip39/wordlists/english'
import { generateMnemonic, mnemonicToSeedSync, validateMnemonic } from '@scure/bip39'
import { HDKey } from '@scure/bip32'

export function privateKeyFromSeedWords(
mnemonic: string,
passphrase?: string,
accountIndex = 0
): string {
export function privateKeyFromSeedWords(mnemonic: string, passphrase?: string, accountIndex = 0): string {
let root = HDKey.fromMasterSeed(mnemonicToSeedSync(mnemonic, passphrase))
let privateKey = root.derive(`m/44'/1237'/${accountIndex}'/0/0`).privateKey
if (!privateKey) throw new Error('could not derive private key')
Expand Down
2 changes: 1 addition & 1 deletion nip19.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export function nprofileEncode(profile: ProfilePointer): `nprofile1${string}` {

export function neventEncode(event: EventPointer): `nevent1${string}` {
let kindArray
if (event.kind != undefined) {
if (event.kind !== undefined) {
kindArray = integerToUint8Array(event.kind)
}

Expand Down
2 changes: 1 addition & 1 deletion nip27.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface NostrURIMatch extends NostrURI {
}

/** Find and decode all NIP-21 URIs. */
export function * matchAll(content: string): Iterable<NostrURIMatch> {
export function* matchAll(content: string): Iterable<NostrURIMatch> {
const matches = content.matchAll(regex())

for (const match of matches) {
Expand Down
10 changes: 5 additions & 5 deletions nip30.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {matchAll, replaceAll} from './nip30.ts'
import { matchAll, replaceAll } from './nip30.ts'

test('matchAll', () => {
const result = matchAll('Hello :blobcat: :disputed: ::joy:joy:')
Expand All @@ -8,21 +8,21 @@ test('matchAll', () => {
name: 'blobcat',
shortcode: ':blobcat:',
start: 6,
end: 15
end: 15,
},
{
name: 'disputed',
shortcode: ':disputed:',
start: 16,
end: 26
}
end: 26,
},
])
})

test('replaceAll', () => {
const content = 'Hello :blobcat: :disputed: ::joy:joy:'

const result = replaceAll(content, ({name}) => {
const result = replaceAll(content, ({ name }) => {
return `<img src="https://ditto.pub/emoji/${name}.png" />`
})

Expand Down
9 changes: 3 additions & 6 deletions nip30.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface CustomEmojiMatch extends CustomEmoji {
}

/** Find all custom emoji shortcodes. */
export function * matchAll(content: string): Iterable<CustomEmojiMatch> {
export function* matchAll(content: string): Iterable<CustomEmojiMatch> {
const matches = content.matchAll(regex())

for (const match of matches) {
Expand All @@ -32,7 +32,7 @@ export function * matchAll(content: string): Iterable<CustomEmojiMatch> {
shortcode: shortcode as `:${string}:`,
name,
start: match.index!,
end: match.index! + shortcode.length
end: match.index! + shortcode.length,
}
} catch (_e) {
// do nothing
Expand All @@ -41,10 +41,7 @@ export function * matchAll(content: string): Iterable<CustomEmojiMatch> {
}

/** Replace all emoji shortcodes in the content. */
export function replaceAll(
content: string,
replacer: (match: CustomEmoji) => string
): string {
export function replaceAll(content: string, replacer: (match: CustomEmoji) => string): string {
return content.replaceAll(regex(), (shortcode, name) => {
return replacer({
shortcode: shortcode as `:${string}:`,
Expand Down

0 comments on commit d16f3f7

Please sign in to comment.