mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2024-12-22 22:49:28 -07:00
Fix minor bug, allow not setting up
This commit is contained in:
parent
2a29832110
commit
3c1302c150
1 changed files with 6 additions and 5 deletions
|
@ -54,16 +54,16 @@ module.exports.fn = async (data, opts) => {
|
||||||
|
|
||||||
const fetchPromise = new Promise((resolve, reject) => {
|
const fetchPromise = new Promise((resolve, reject) => {
|
||||||
(async () => {
|
(async () => {
|
||||||
|
let isConfigured = false
|
||||||
try {
|
try {
|
||||||
validator.isURL(opts.claims.activitypub.url)
|
validator.isURL(opts.claims.activitypub.url)
|
||||||
|
isConfigured = true
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(`ActivityPub fetcher was not set up properly (${err.message})`)
|
console.log(`ActivityPub fetcher was not set up (${err.message})`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare the signature
|
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
const { host, pathname, search } = new URL(data.url)
|
const { host, pathname, search } = new URL(data.url)
|
||||||
const signedString = `(request-target): get ${pathname}${search}\nhost: ${host}\ndate: ${now.toUTCString()}`
|
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
host,
|
host,
|
||||||
|
@ -71,12 +71,13 @@ module.exports.fn = async (data, opts) => {
|
||||||
accept: 'application/activity+json'
|
accept: 'application/activity+json'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jsEnv.isNode) {
|
if (isConfigured && jsEnv.isNode) {
|
||||||
// Generate the signature
|
// Generate the signature
|
||||||
|
const signedString = `(request-target): get ${pathname}${search}\nhost: ${host}\ndate: ${now.toUTCString()}`
|
||||||
const sign = crypto.createSign('SHA256')
|
const sign = crypto.createSign('SHA256')
|
||||||
sign.write(signedString)
|
sign.write(signedString)
|
||||||
sign.end()
|
sign.end()
|
||||||
const signatureSig = sign.sign(opts.claims.activitypub.privateKey, 'base64')
|
const signatureSig = sign.sign(opts.claims.activitypub.privateKey.replace(/\\n/g, '\n'), 'base64')
|
||||||
headers.signature = `keyId="${opts.claims.activitypub.url}#main-key",headers="(request-target) host date",signature="${signatureSig}",algorithm="rsa-sha256"`
|
headers.signature = `keyId="${opts.claims.activitypub.url}#main-key",headers="(request-target) host date",signature="${signatureSig}",algorithm="rsa-sha256"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue