prettify and lint.
This commit is contained in:
parent
0108e3b605
commit
d16f3f77c3
|
@ -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')
|
||||
})
|
||||
|
|
6
nip06.ts
6
nip06.ts
|
@ -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')
|
||||
|
|
2
nip19.ts
2
nip19.ts
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -8,14 +8,14 @@ test('matchAll', () => {
|
|||
name: 'blobcat',
|
||||
shortcode: ':blobcat:',
|
||||
start: 6,
|
||||
end: 15
|
||||
end: 15,
|
||||
},
|
||||
{
|
||||
name: 'disputed',
|
||||
shortcode: ':disputed:',
|
||||
start: 16,
|
||||
end: 26
|
||||
}
|
||||
end: 26,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
|
|
7
nip30.ts
7
nip30.ts
|
@ -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}:`,
|
||||
|
|
Loading…
Reference in New Issue