add function to create nip98 http authorization header
Closes: https://github.com/damus-io/damus/pull/1471 Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
1432087edf
commit
9104ddb051
23
damus/Nostr/Nip98HTTPAuth.swift
Normal file
23
damus/Nostr/Nip98HTTPAuth.swift
Normal file
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Nip98HTTPAuth.swift
|
||||
// damus
|
||||
//
|
||||
// Created by Fishcake on 2023/08/12.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
func create_nip98_signature (keypair: Keypair, method: String, url: URL) -> String? {
|
||||
let tags = [
|
||||
["u", url.standardized.absoluteString], // Ensure that we standardise the URL before extracting string value.
|
||||
["method", method]
|
||||
]
|
||||
|
||||
guard let ev = NostrEvent(content: "", keypair: keypair, kind: NostrKind.http_auth.rawValue, tags: tags) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let json = event_to_json(ev: ev)
|
||||
let base64Header = base64_encode(Array(json.utf8))
|
||||
return "Nostr " + base64Header // The returned value should be used in Authorization HTTP header
|
||||
}
|
||||
Reference in New Issue
Block a user