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:
parent
f010a61608
commit
9e6d6f1c39
3 changed files with 26 additions and 21 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "skate-spots",
|
||||
"private": true,
|
||||
"version": "1.0.32",
|
||||
"version": "1.0.33",
|
||||
"type": "module",
|
||||
"homepage": "https://skate-spots.com",
|
||||
"scripts": {
|
||||
|
|
@ -83,7 +83,7 @@
|
|||
"leaflet.markercluster": "^1.5.3",
|
||||
"lucide-react": "^0.462.0",
|
||||
"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",
|
||||
"npubcash-sdk": "^0.2.0",
|
||||
"qrcode": "^1.5.4",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
- Plugin uses native Android intents directly — no nostrsigner: URL, no intent: URL, no encoding issues
|
||||
- This is how Coracle and other proper Capacitor apps do it
|
||||
- Requires: npm run android:build && cap sync android (plugin needs native sync)
|
||||
- Switched to coracle-social/nostr-signer-capacitor-plugin (same fork Coracle uses in production)
|
||||
- Fixed API calls to match Coracle fork: setPackageName(string) and getPublicKey(packageName)
|
||||
- Requires: npm install && npx cap sync android after git pull
|
||||
|
|
|
|||
|
|
@ -35,28 +35,34 @@ export const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLog
|
|||
|
||||
const isAndroid = /Android/i.test(navigator.userAgent);
|
||||
|
||||
const AMBER_PACKAGE = 'com.greenart7c3.nostrsigner';
|
||||
|
||||
const handleAmberLogin = async () => {
|
||||
setAmberStep('loading');
|
||||
setAmberError('');
|
||||
try {
|
||||
// Use the Capacitor plugin for native intent-based NIP-55 communication.
|
||||
// This is the correct approach for Capacitor APKs — it uses Android intents
|
||||
// directly, not URL schemes from JavaScript (which don't work reliably).
|
||||
const { default: NostrSignerPlugin } = await import('nostr-signer-capacitor-plugin');
|
||||
|
||||
// Set Amber's package name
|
||||
await NostrSignerPlugin.setPackageName({ packageName: 'com.greenart7c3.nostrsigner' });
|
||||
|
||||
// Use the Capacitor plugin for native Android intent-based NIP-55.
|
||||
// We use Coracle's fork API (github:coracle-social/nostr-signer-capacitor-plugin)
|
||||
// which is the battle-tested version used in production by Coracle.
|
||||
//
|
||||
// API (Coracle fork — different from chebizarro's npm version):
|
||||
// setPackageName(packageName: string): Promise<void>
|
||||
// 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
|
||||
const { installed } = await NostrSignerPlugin.isExternalSignerInstalled();
|
||||
const { installed } = await NostrSignerPlugin.isExternalSignerInstalled(AMBER_PACKAGE);
|
||||
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
|
||||
const { npub } = await NostrSignerPlugin.getPublicKey();
|
||||
|
||||
// Convert npub to hex pubkey
|
||||
// Request pubkey — opens Amber natively, user approves, promise resolves
|
||||
const { npub } = await NostrSignerPlugin.getPublicKey(AMBER_PACKAGE);
|
||||
|
||||
// Convert npub → hex pubkey
|
||||
const { nip19 } = await import('nostr-tools');
|
||||
const decoded = nip19.decode(npub);
|
||||
if (decoded.type !== 'npub') throw new Error('Invalid pubkey from Amber');
|
||||
|
|
|
|||
Loading…
Reference in a new issue