prettify and lint.

This commit is contained in:
fiatjaf 2023-12-16 12:39:24 -03:00
parent 0108e3b605
commit d16f3f77c3
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
6 changed files with 13 additions and 24 deletions

View File

@ -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 () => {
@ -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')
})

View File

@ -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')

View File

@ -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)
}

View File

@ -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) {

View File

@ -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:')
@ -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" />`
})

View File

@ -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) {
@ -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
@ -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}:`,