-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 #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: #1809 Signed-off-by: Daniel D’Aquino <[email protected]> Signed-off-by: William Casarin <[email protected]>
- Loading branch information
1 parent
4703ed8
commit 5ca5420
Showing
4 changed files
with
95 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters