fix: switch to Coracle's nostr-signer-capacitor-plugin fork + correct API

The chebizarro npm version has a different API to the Coracle fork that
Welshman/Coracle actually use in production. Now using:

  github:coracle-social/nostr-signer-capacitor-plugin#main

Correct API (from Welshman nip55.js source):
  NostrSignerPlugin.setPackageName(packageName: string)  // string not object
  NostrSignerPlugin.getPublicKey(packageName?: string)   // packageName as arg
  NostrSignerPlugin.isExternalSignerInstalled(packageName?)

Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
This commit is contained in:
shakespeare.diy 2026-07-08 12:11:18 +07:00
parent f010a61608
commit 9e6d6f1c39
3 changed files with 26 additions and 21 deletions

View file

@ -1,7 +1,7 @@
{ {
"name": "skate-spots", "name": "skate-spots",
"private": true, "private": true,
"version": "1.0.32", "version": "1.0.33",
"type": "module", "type": "module",
"homepage": "https://skate-spots.com", "homepage": "https://skate-spots.com",
"scripts": { "scripts": {
@ -83,7 +83,7 @@
"leaflet.markercluster": "^1.5.3", "leaflet.markercluster": "^1.5.3",
"lucide-react": "^0.462.0", "lucide-react": "^0.462.0",
"ngeohash": "^0.6.3", "ngeohash": "^0.6.3",
"nostr-signer-capacitor-plugin": "^0.0.5", "nostr-signer-capacitor-plugin": "github:coracle-social/nostr-signer-capacitor-plugin#main",
"nostr-tools": "^2.13.0", "nostr-tools": "^2.13.0",
"npubcash-sdk": "^0.2.0", "npubcash-sdk": "^0.2.0",
"qrcode": "^1.5.4", "qrcode": "^1.5.4",

View file

@ -1,6 +1,5 @@
v1.0.32 — Amber login via native Capacitor plugin v1.0.33 — Amber login via Coracle's Capacitor plugin (correct fork + correct API)
- Replaced all URL-scheme hacks with nostr-signer-capacitor-plugin - Switched to coracle-social/nostr-signer-capacitor-plugin (same fork Coracle uses in production)
- Plugin uses native Android intents directly — no nostrsigner: URL, no intent: URL, no encoding issues - Fixed API calls to match Coracle fork: setPackageName(string) and getPublicKey(packageName)
- This is how Coracle and other proper Capacitor apps do it - Requires: npm install && npx cap sync android after git pull
- Requires: npm run android:build && cap sync android (plugin needs native sync)

View file

@ -35,28 +35,34 @@ export const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLog
const isAndroid = /Android/i.test(navigator.userAgent); const isAndroid = /Android/i.test(navigator.userAgent);
const AMBER_PACKAGE = 'com.greenart7c3.nostrsigner';
const handleAmberLogin = async () => { const handleAmberLogin = async () => {
setAmberStep('loading'); setAmberStep('loading');
setAmberError(''); setAmberError('');
try { try {
// Use the Capacitor plugin for native intent-based NIP-55 communication. // Use the Capacitor plugin for native Android intent-based NIP-55.
// This is the correct approach for Capacitor APKs — it uses Android intents // We use Coracle's fork API (github:coracle-social/nostr-signer-capacitor-plugin)
// directly, not URL schemes from JavaScript (which don't work reliably). // which is the battle-tested version used in production by Coracle.
const { default: NostrSignerPlugin } = await import('nostr-signer-capacitor-plugin'); //
// API (Coracle fork — different from chebizarro's npm version):
// Set Amber's package name // setPackageName(packageName: string): Promise<void>
await NostrSignerPlugin.setPackageName({ packageName: 'com.greenart7c3.nostrsigner' }); // getPublicKey(packageName?: string): Promise<{ npub: string; package: string }>
const { NostrSignerPlugin } = await import('nostr-signer-capacitor-plugin');
// Set package name first (Coracle fork takes string, not object)
await NostrSignerPlugin.setPackageName(AMBER_PACKAGE);
// Check Amber is installed // Check Amber is installed
const { installed } = await NostrSignerPlugin.isExternalSignerInstalled(); const { installed } = await NostrSignerPlugin.isExternalSignerInstalled(AMBER_PACKAGE);
if (!installed) { if (!installed) {
throw new Error('Amber is not installed. Install it from Zapstore or F-Droid.'); throw new Error('Amber is not installed. Get it from Zapstore or F-Droid.');
} }
// Request pubkey — opens Amber, user approves, returns npub // Request pubkey — opens Amber natively, user approves, promise resolves
const { npub } = await NostrSignerPlugin.getPublicKey(); const { npub } = await NostrSignerPlugin.getPublicKey(AMBER_PACKAGE);
// Convert npub to hex pubkey // Convert npub → hex pubkey
const { nip19 } = await import('nostr-tools'); const { nip19 } = await import('nostr-tools');
const decoded = nip19.decode(npub); const decoded = nip19.decode(npub);
if (decoded.type !== 'npub') throw new Error('Invalid pubkey from Amber'); if (decoded.type !== 'npub') throw new Error('Invalid pubkey from Amber');