Damus Purple: Add npub authentication for account management API calls
Testing --------- PASS Device: iPhone 15 Pro simulator iOS: 17.2 Damus: This commit damus-api: 626fb9665d8d6c576dd635d5224869cd9b69d190 Server: Ubuntu 22.04 (VM) Setup: 1. On the server, delete the `mdb` database files to start from scratch 2. In iOS, reinstall the app if necessary to make sure there are no in-app purchases 3. Enable subscriptions support via developer settings with localhost test mode and restart app 4. Start server with mock parameters (Run `npm run dev`) Steps: 1. Open top bar and click on "Purple" 2. Purple screen should appear and show both benefits and the purchase options. PASS 3. Click on "monthly". An Apple screen to confirm purchase should appear. PASS 4. Welcome screen with animation should appear. PASS 5. Click continue and restart app (Due to known issue tracked at damus-io#1814) 6. Post something 7. Gold star should appear beside your name 8. Look at the server logs. There should be some requests to create the account (POST), to send the receipt (POST), and to get account status 9. Go to purple view. There should be some information about the subscription, as well as a "manage" button. PASS 10. Click on "manage" button. An iOS sheet should appear allow the user to unsubscribe or manage their subscription to Damus Purple. Closes: https://github.com/damus-io/damus/issues/1809 Signed-off-by: Daniel D’Aquino <daniel@daquino.me> Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
4703ed80a7
commit
5ca5420ce2
41
damus/Nostr/NIP98AuthenticatedRequest.swift
Normal file
41
damus/Nostr/NIP98AuthenticatedRequest.swift
Normal file
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// NIP98AuthenticatedRequest.swift
|
||||
// damus
|
||||
//
|
||||
// Created by Daniel D’Aquino on 2023-12-15.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum HTTPMethod: String {
|
||||
case get = "GET"
|
||||
case post = "POST"
|
||||
case put = "PUT"
|
||||
case delete = "DELETE"
|
||||
}
|
||||
|
||||
func make_nip98_authenticated_request(method: HTTPMethod, url: URL, payload: Data, auth_keypair: Keypair) async throws -> (data: Data, response: URLResponse) {
|
||||
var request = URLRequest(url: url)
|
||||
request.httpMethod = method.rawValue
|
||||
request.httpBody = payload
|
||||
|
||||
let payload_hash = sha256(payload)
|
||||
let payload_hash_hex = payload_hash.map({ String(format: "%02hhx", $0) }).joined()
|
||||
|
||||
let auth_note = NdbNote(
|
||||
content: "",
|
||||
keypair: auth_keypair,
|
||||
kind: 27235,
|
||||
tags: [
|
||||
["u", url.absoluteString],
|
||||
["method", method.rawValue],
|
||||
["payload", payload_hash_hex]
|
||||
],
|
||||
createdAt: UInt32(Date().timeIntervalSince1970)
|
||||
)
|
||||
let auth_note_json_data: Data = try JSONEncoder().encode(auth_note)
|
||||
let auth_note_base64: String = base64_encode(auth_note_json_data.bytes)
|
||||
|
||||
request.setValue("Nostr " + auth_note_base64, forHTTPHeaderField: "Authorization")
|
||||
return try await URLSession.shared.data(for: request)
|
||||
}
|
||||
Reference in New Issue
Block a user