Sign upload auth

This commit is contained in:
Jonathan Staab 2023-08-24 13:22:43 -07:00
parent f49c7caca5
commit 625718fbf9
2 changed files with 10 additions and 7 deletions

View File

@ -173,8 +173,7 @@ export class Builder {
createLabel = (payload: EventOpts) => buildEvent(1985, payload)
createNip98AuthHeader = (tags: string[][]) =>
`Nostr ${btoa(JSON.stringify(buildEvent(27235, {tags})))}`
nip98Auth = (tags: string[][]) => buildEvent(27235, {tags})
initialize(engine: Engine) {
this.engine = engine

View File

@ -7,7 +7,7 @@
import Spinner from "src/partials/Spinner.svelte"
import Anchor from "src/partials/Anchor.svelte"
import {listenForFile, stripExifData, blobToFile} from "src/util/html"
import {Builder} from "src/app/engine"
import {Builder, Outbox} from "src/app/engine"
export let icon = null
export let value = null
@ -41,14 +41,18 @@
body.append("file[]", file)
}
const event = Outbox.prep(
Builder.nip98Auth([
["u", url],
["method", "POST"],
])
)
const result = await Fetch.fetchJson(url, {
body,
method: "POST",
headers: {
Authorization: Builder.createNip98AuthHeader([
["u", url],
["method", "POST"],
]),
Authorization: `Nostr ${btoa(JSON.stringify(event))}`,
},
})