mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
NIP-39: validate github
This commit is contained in:
1
index.ts
1
index.ts
@@ -9,6 +9,7 @@ export * as nip05 from './nip05'
|
|||||||
export * as nip06 from './nip06'
|
export * as nip06 from './nip06'
|
||||||
export * as nip19 from './nip19'
|
export * as nip19 from './nip19'
|
||||||
export * as nip26 from './nip26'
|
export * as nip26 from './nip26'
|
||||||
|
export * as nip39 from './nip39'
|
||||||
export * as nip57 from './nip57'
|
export * as nip57 from './nip57'
|
||||||
|
|
||||||
export * as fj from './fakejson'
|
export * as fj from './fakejson'
|
||||||
|
|||||||
15
nip39.test.js
Normal file
15
nip39.test.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
/* eslint-env jest */
|
||||||
|
|
||||||
|
const fetch = require('node-fetch')
|
||||||
|
const {nip39} = require('./lib/nostr.cjs.js')
|
||||||
|
|
||||||
|
test('validate github claim', async () => {
|
||||||
|
nip39.useFetchImplementation(fetch)
|
||||||
|
|
||||||
|
let result = await nip39.validateGithub(
|
||||||
|
'npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z',
|
||||||
|
'vitorpamplona',
|
||||||
|
'cf19e2d1d7f8dac6348ad37b35ec8421'
|
||||||
|
)
|
||||||
|
expect(result).toBe(true)
|
||||||
|
})
|
||||||
27
nip39.ts
Normal file
27
nip39.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
var _fetch: any
|
||||||
|
|
||||||
|
try {
|
||||||
|
_fetch = fetch
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
export function useFetchImplementation(fetchImplementation: any) {
|
||||||
|
_fetch = fetchImplementation
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function validateGithub(
|
||||||
|
pubkey: string,
|
||||||
|
username: string,
|
||||||
|
proof: string
|
||||||
|
): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
let res = await (
|
||||||
|
await _fetch(`https://gist.github.com/${username}/${proof}/raw`)
|
||||||
|
).text()
|
||||||
|
return (
|
||||||
|
res ===
|
||||||
|
`Verifying that I control the following Nostr public key: ${pubkey}`
|
||||||
|
)
|
||||||
|
} catch (_) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user