damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

Nip98HTTPAuth.swift (699B)


      1 //
      2 //  Nip98HTTPAuth.swift
      3 //  damus
      4 //
      5 //  Created by Fishcake on 2023/08/12.
      6 //
      7 
      8 import Foundation
      9 
     10 func create_nip98_signature (keypair: Keypair, method: String, url: URL) -> String? {
     11     let tags = [
     12         ["u", url.standardized.absoluteString], // Ensure that we standardise the URL before extracting string value.
     13         ["method", method]
     14     ]
     15     
     16     guard let ev = NostrEvent(content: "", keypair: keypair, kind: NostrKind.http_auth.rawValue, tags: tags) else {
     17          return nil
     18     }
     19 
     20     let json = event_to_json(ev: ev)
     21     let base64Header = base64_encode(Array(json.utf8))
     22     return "Nostr " + base64Header // The returned value should be used in Authorization HTTP header
     23 }