Files
einundzwanzig-app/resources/views/auth/mobile-nostr-launch.blade.php
T
HolgerHatGarKeineNode 4fa4a84b7d Launch the Nostr signer via an intent:// URL with extras
Amber v6.2.0 rejects a plain nostrsigner: navigation as malformed: it
reads the signer parameters from intent extras, which a window.location
navigation cannot set. An intent:// URL lets the launcher pass the event
as the data URI plus type/returnType/appName/callbackUrl as S.* extras,
so Amber accepts the request and shows its sign dialog. The query is also
kept on the data URI for the EXTRA_APPLICATION_ID web flow.

Note: on the emulator with Amber v6.2.0 the post-approval callback did
not always fire (Amber returns via setResult when callingPackage != null);
needs verification on a real device.
2026-06-11 23:28:32 +02:00

54 lines
2.6 KiB
PHP

<!DOCTYPE html>
<html lang="de" class="dark">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ __('Anmeldung mit Nostr') }} Einundzwanzig</title>
<style>
body { margin: 0; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
background: #09090b; color: #fafafa; font-family: ui-sans-serif, system-ui, sans-serif; }
.card { text-align: center; padding: 2rem; max-width: 22rem; }
h1 { font-size: 1.25rem; margin: 0 0 .5rem; }
p { color: #a1a1aa; line-height: 1.5; }
button.launch { margin-top: 1.5rem; width: 100%; padding: 1rem 1.25rem; border: 0; border-radius: .75rem;
background: #f7931a; color: #09090b; font-weight: 600; font-size: 1.05rem; cursor: pointer; }
</style>
</head>
<body>
<div class="card">
<h1>{{ __('Anmeldung mit Nostr') }}</h1>
<p>{{ __('Tippe auf den Button, um die Anmeldung mit deinem Nostr-Signer (z. B. Amber) zu signieren.') }}</p>
{{-- Must be launched from a user gesture (browsers only dispatch the
external-app intent on user activation). --}}
<button class="launch" onclick="launchSigner()">{{ __('Mit Amber signieren') }}</button>
</div>
<script>
// Amber (v6.2+) reads the signer parameters from intent EXTRAS, not
// from the URI query, unless the browser sets EXTRA_APPLICATION_ID —
// which Chrome does NOT do for a plain nostrsigner: navigation. An
// intent:// URL lets us pass the event as the data URI AND the
// parameters as extras (S.* entries), so Amber's app-to-app flow
// accepts it. The query is also kept on the data URI as a fallback
// for the web flow.
function launchSigner() {
const event = {
kind: 22242,
created_at: Math.floor(Date.now() / 1000),
content: '',
tags: [['challenge', @js($k1)]],
};
const eventEnc = encodeURIComponent(JSON.stringify(event));
const callbackUrl = @js($callbackUrl);
const query = 'compressionType=none&returnType=event&type=sign_event'
+ '&appName=Einundzwanzig&callbackUrl=' + encodeURIComponent(callbackUrl);
window.location.href = 'intent:' + eventEnc + '?' + query
+ '#Intent;scheme=nostrsigner;category=android.intent.category.BROWSABLE'
+ ';S.type=sign_event;S.returnType=event;S.appName=Einundzwanzig'
+ ';S.callbackUrl=' + callbackUrl
+ ';end';
}
</script>
</body>
</html>