This Capacitor plugin allows your application to interact with Nostr signer apps on the Android platform using intents, following the NIP-55 and NIP-07 specifications. It also provides web support by interacting with window.nostr
for browser environments.
npm install nostr-signer-capacitor-plugin
npx cap sync
import NostrSigner from 'nostr-signer-capacitor-plugin';
Before using the plugin on Android, you need to set the package name of the external signer app.
await NostrSigner.setPackageName({ packageName: 'com.example.signer' });
const { installed } = await NostrSigner.isExternalSignerInstalled();
if (!installed) {
console.log('External signer app is not installed.');
}
try {
const { npub } = await NostrSigner.getPublicKey();
console.log('Public Key:', npub);
} catch (error) {
console.error('Error getting public key:', error);
}
const event = {
kind: 1,
content: 'Hello, Nostr!',
tags: [],
created_at: Math.floor(Date.now() / 1000),
};
try {
const { event: signedEventJson } = await NostrSigner.signEvent({
eventJson: JSON.stringify(event),
});
const signedEvent = JSON.parse(signedEventJson);
console.log('Signed Event:', signedEvent);
} catch (error) {
console.error('Error signing event:', error);
}
try {
const { result: encryptedText } = await NostrSigner.nip04Encrypt({
pubKey: 'recipient_public_key',
plainText: 'Secret message',
});
console.log('Encrypted Text:', encryptedText);
} catch (error) {
console.error('Error encrypting message:', error);
}
try {
const { result: decryptedText } = await NostrSigner.nip04Decrypt({
pubKey: 'sender_public_key',
encryptedText: 'encrypted_text',
});
console.log('Decrypted Text:', decryptedText);
} catch (error) {
console.error('Error decrypting message:', error);
}
try {
const { result: encryptedText } = await NostrSigner.nip44Encrypt({
pubKey: 'recipient_public_key',
plainText: 'Secret message',
});
console.log('Encrypted Text (NIP-44):', encryptedText);
} catch (error) {
console.error('Error encrypting message (NIP-44):', error);
}
try {
const { result: decryptedText } = await NostrSigner.nip44Decrypt({
pubKey: 'sender_public_key',
encryptedText: 'encrypted_text',
});
console.log('Decrypted Text (NIP-44):', decryptedText);
} catch (error) {
console.error('Error decrypting message (NIP-44):', error);
}
try {
const { result: decryptedEventJson } = await NostrSigner.decryptZapEvent({
eventJson: JSON.stringify(encryptedEvent),
});
const decryptedEvent = JSON.parse(decryptedEventJson);
console.log('Decrypted Zap Event:', decryptedEvent);
} catch (error) {
console.error('Error decrypting zap event:', error);
}
{ packageName: string; }
| An object containing the package name string. |
--------------------
### isExternalSignerInstalled()
```typescript
isExternalSignerInstalled() => Promise<{ installed: boolean; }>
```
Checks if the external Nostr signer app is installed on the device.
**Returns:** Promise<{ installed: boolean; }>
An object indicating whether the signer app is installed.
--------------------
### getPublicKey()
```typescript
getPublicKey() => Promise<{ npub: string; }>
```
Requests the public key from the Nostr signer app or extension.
**Returns:** Promise<{ npub: string; }>
An object containing the public key in npub format.
--------------------
### signEvent(...)
```typescript
signEvent(options: { eventJson: string; }) => Promise<{ event: string; }>
```
Requests the signer app to sign a Nostr event.
| Param | Type | Description |
| ------------- | ----------------------------------- | --------------------------------- |
| **`options`** | { eventJson: string; }
| An object containing the event in JSON string format. |
**Returns:** Promise<{ event: string; }>
An object containing the signed event in JSON string format.
--------------------
### nip04Encrypt(...)
```typescript
nip04Encrypt(options: { plainText: string; pubKey: string; }) => Promise<{ result: string; }>
```
Encrypts a message using NIP-04 encryption.
| Param | Type | Description |
| ------------- | ----------------------------------------------------- | ------------------------------------------- |
| **`options`** | { plainText: string; pubKey: string; }
| An object containing the plaintext and the recipient's public key. |
**Returns:** Promise<{ result: string; }>
An object containing the encrypted text.
--------------------
### nip04Decrypt(...)
```typescript
nip04Decrypt(options: { encryptedText: string; pubKey: string; }) => Promise<{ result: string; }>
```
Decrypts a message using NIP-04 decryption.
| Param | Type | Description |
| ------------- | ------------------------------------------------------- | ------------------------------------------- |
| **`options`** | { encryptedText: string; pubKey: string; }
| An object containing the encrypted text and the sender's public key. |
**Returns:** Promise<{ result: string; }>
An object containing the decrypted plaintext.
--------------------
### nip44Encrypt(...)
```typescript
nip44Encrypt(options: { plainText: string; pubKey: string; }) => Promise<{ result: string; }>
```
Encrypts a message using NIP-44 encryption.
| Param | Type | Description |
| ------------- | ----------------------------------------------------- | ------------------------------------------- |
| **`options`** | { plainText: string; pubKey: string; }
| An object containing the plaintext and the recipient's public key. |
**Returns:** Promise<{ result: string; }>
An object containing the encrypted text.
--------------------
### nip44Decrypt(...)
```typescript
nip44Decrypt(options: { encryptedText: string; pubKey: string; }) => Promise<{ result: string; }>
```
Decrypts a message using NIP-44 decryption.
| Param | Type | Description |
| ------------- | ------------------------------------------------------- | ------------------------------------------- |
| **`options`** | { encryptedText: string; pubKey: string; }
| An object containing the encrypted text and the sender's public key. |
**Returns:** Promise<{ result: string; }>
An object containing the decrypted plaintext.
--------------------
### decryptZapEvent(...)
```typescript
decryptZapEvent(options: { eventJson: string; }) => Promise<{ result: string; }>
```
Decrypts a zap event.
| Param | Type | Description |
| ------------- | ----------------------------------- | --------------------------------- |
| **`options`** | { eventJson: string; }
| An object containing the encrypted zap event in JSON string format. |
**Returns:** Promise<{ result: string; }>
An object containing the decrypted zap event in JSON string format.
--------------------
window.nostr
to interact with Nostr browser extensions as per NIP-07.