Browse Source

Add debugging for NIP-98 auth in cashu mint

main
woikos 2 weeks ago
parent
commit
8424f0ca44
No known key found for this signature in database
  1. 14
      app/handle-cashu.go
  2. 2
      app/web/dist/bundle.js
  3. 2
      app/web/dist/bundle.js.map
  4. 21
      app/web/src/api.js

14
app/handle-cashu.go

@ -6,7 +6,6 @@ import ( @@ -6,7 +6,6 @@ import (
"net/http"
"time"
"lol.mleku.dev/chk"
"lol.mleku.dev/log"
"git.mleku.dev/mleku/nostr/httpauth"
@ -35,13 +34,24 @@ type CashuMintResponse struct { @@ -35,13 +34,24 @@ type CashuMintResponse struct {
func (s *Server) handleCashuMint(w http.ResponseWriter, r *http.Request) {
// Check if Cashu is enabled
if s.CashuIssuer == nil {
log.W.F("Cashu mint request but issuer not initialized")
http.Error(w, "Cashu tokens not enabled", http.StatusNotImplemented)
return
}
// Require NIP-98 authentication
valid, pubkey, err := httpauth.CheckAuth(r)
if chk.E(err) || !valid {
if err != nil {
authHeader := r.Header.Get("Authorization")
if len(authHeader) > 100 {
authHeader = authHeader[:100] + "..."
}
log.W.F("Cashu mint NIP-98 auth error: %v (valid=%v, authHeader=%q)", err, valid, authHeader)
http.Error(w, "NIP-98 authentication required", http.StatusUnauthorized)
return
}
if !valid {
log.W.F("Cashu mint NIP-98 auth invalid signature")
http.Error(w, "NIP-98 authentication required", http.StatusUnauthorized)
return
}

2
app/web/dist/bundle.js vendored

File diff suppressed because one or more lines are too long

2
app/web/dist/bundle.js.map vendored

File diff suppressed because one or more lines are too long

21
app/web/src/api.js

@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
*/
export async function createNIP98Auth(signer, pubkey, method, url) {
if (!signer || !pubkey) {
console.log("No signer or pubkey available");
console.log("createNIP98Auth: No signer or pubkey available", { hasSigner: !!signer, hasPubkey: !!pubkey });
return null;
}
@ -23,17 +23,30 @@ export async function createNIP98Auth(signer, pubkey, method, url) { @@ -23,17 +23,30 @@ export async function createNIP98Auth(signer, pubkey, method, url) {
created_at: Math.floor(Date.now() / 1000),
tags: [
["u", url],
["method", method],
["method", method.toUpperCase()],
],
content: "",
};
console.log("createNIP98Auth: Signing event for", method, url);
// Sign using the signer
const signedEvent = await signer.signEvent(authEvent);
console.log("createNIP98Auth: Signed event:", {
id: signedEvent.id,
pubkey: signedEvent.pubkey,
kind: signedEvent.kind,
created_at: signedEvent.created_at,
tags: signedEvent.tags,
hasSig: !!signedEvent.sig
});
// Use URL-safe base64 encoding (replace + with -, / with _)
return btoa(JSON.stringify(signedEvent)).replace(/\+/g, '-').replace(/\//g, '_');
const json = JSON.stringify(signedEvent);
const base64 = btoa(json).replace(/\+/g, '-').replace(/\//g, '_');
return base64;
} catch (error) {
console.error("Error creating NIP-98 auth:", error);
console.error("createNIP98Auth: Error:", error);
return null;
}
}

Loading…
Cancel
Save