mirror of
https://github.com/Yonle/bostr.git
synced 2025-03-17 21:32:43 +01:00
20 lines
530 B
JavaScript
20 lines
530 B
JavaScript
|
const { getEventHash, getSignature } = require("nostr-tools");
|
||
|
|
||
|
module.exports = (relay, pubkey, privkey, challenge) => {
|
||
|
if (!privkey) return;
|
||
|
let signed_challenge = {
|
||
|
pubkey,
|
||
|
created_at: Math.floor(Date.now() / 1000),
|
||
|
kind: 22242,
|
||
|
tags: [
|
||
|
["relay", relay.url],
|
||
|
["challenge", challenge]
|
||
|
],
|
||
|
content: ""
|
||
|
}
|
||
|
|
||
|
signed_challenge.id = getEventHash(signed_challenge);
|
||
|
signed_challenge.sig = getSignature(signed_challenge, privkey);
|
||
|
relay.send(JSON.stringify(["AUTH", signed_challenge]));
|
||
|
}
|