11import * as Nip55 from "expo-nip55" ;
22import { NDKEncryptionScheme , NDKSigner , NDKUser , NostrEvent } from "@nostr-dev-kit/ndk" ;
33
4+ export interface Permission {
5+ type : string ;
6+ kind ?: number ;
7+ checked ?: boolean ;
8+ }
9+
410export class NDKNip55Signer implements NDKSigner {
511 private _pubkey : string ;
612 private _user ?: NDKUser ;
@@ -9,18 +15,26 @@ export class NDKNip55Signer implements NDKSigner {
915 constructor ( packageName : string ) {
1016 this . packageName = packageName ;
1117 }
12-
18+
1319 /**
1420 * Blocks until the signer is ready and returns the associated NDKUser.
1521 * @returns A promise that resolves to the NDKUser instance.
1622 */
1723 async blockUntilReady ( ) : Promise < NDKUser > {
1824 if ( this . _user ) return this . _user ;
19-
25+
2026 await Nip55 . setPackageName ( this . packageName ) ;
21-
22- const data = await Nip55 . getPublicKey ( ) ;
23- if ( ! data ) throw new Error ( 'No signer available found' ) ;
27+
28+ const perms : Permission [ ] = [
29+ { type : "sign_event" , kind : 22242 } ,
30+ { type : "nip04_encrypt" } ,
31+ { type : "nip04_decrypt" } ,
32+ { type : "nip44_encrypt" } ,
33+ { type : "nip44_decrypt" } ,
34+ ] ;
35+
36+ const data = await Nip55 . getPublicKey ( this . packageName , perms ) ;
37+ if ( ! data ) throw new Error ( "No signer available found" ) ;
2438
2539 this . _user = new NDKUser ( { npub : data . npub } ) ;
2640 this . _pubkey = this . _user . pubkey ;
@@ -40,14 +54,23 @@ export class NDKNip55Signer implements NDKSigner {
4054 */
4155 async sign ( event : NostrEvent ) : Promise < string > {
4256 console . log ( 'NIP-55 SIGNER SIGNING' , event )
43- const result = await Nip55 . signEvent (
44- this . packageName ,
45- JSON . stringify ( event ) ,
46- event . id ,
47- this . _pubkey
57+
58+ let result : { signature : string }
59+
60+ try {
61+ result = await Nip55 . signEvent (
62+ this . packageName ,
63+ JSON . stringify ( event ) ,
64+ event . id ,
65+ this . _pubkey
4866 )
4967 console . log ( 'NIP-55 SIGNER SIGNED' , result )
50- return result . signature ;
68+ } catch ( error ) {
69+ console . error ( "Error sign failed:" , error ) ;
70+ throw error ;
71+ }
72+
73+ return result . signature ;
5174 }
5275
5376 /**
0 commit comments