NIP-39: validate github
This commit is contained in:
parent
5539e5cf89
commit
be7c981c14
1
index.ts
1
index.ts
|
@ -9,6 +9,7 @@ export * as nip05 from './nip05'
|
|||
export * as nip06 from './nip06'
|
||||
export * as nip19 from './nip19'
|
||||
export * as nip26 from './nip26'
|
||||
export * as nip39 from './nip39'
|
||||
export * as nip57 from './nip57'
|
||||
|
||||
export * as fj from './fakejson'
|
||||
|
|
|
@ -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)
|
||||
})
|
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue