applesauce-signers 0.0.0-next-20250428164231 → 0.0.0-next-20250429163257
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,5 +1,101 @@
|
|
|
1
1
|
# applesauce-signer
|
|
2
2
|
|
|
3
|
-
A collection of signer classes for applesauce
|
|
3
|
+
A collection of signer classes for applesauce that are compatible with the [NIP-07](https://github.com/nostr-protocol/nips/blob/master/07.md) API.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
For detailed documentation and API reference, see:
|
|
8
|
+
|
|
9
|
+
- [Signers Documentation](https://hzrd149.github.io/applesauce/signers/signers.html)
|
|
10
|
+
- [Nostr Connect Documentation](https://hzrd149.github.io/applesauce/signers/nostr-connect.html)
|
|
11
|
+
- [API Reference](https://hzrd149.github.io/applesauce/typedoc/modules/applesauce_signers.html)
|
|
12
|
+
|
|
13
|
+
## Available Signers
|
|
14
|
+
|
|
15
|
+
### Password Signer (NIP-49)
|
|
16
|
+
|
|
17
|
+
A secure signer that encrypts private keys using [NIP-49](https://github.com/nostr-protocol/nips/blob/master/49.md).
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
// Create a new password signer
|
|
21
|
+
const signer = new PasswordSigner();
|
|
22
|
+
|
|
23
|
+
// Set up with a new key and password
|
|
24
|
+
const randomBytes = new Uint8Array(64);
|
|
25
|
+
window.crypto.getRandomValues(randomBytes);
|
|
26
|
+
|
|
27
|
+
signer.key = randomBytes;
|
|
28
|
+
signer.setPassword("your-password");
|
|
29
|
+
|
|
30
|
+
// Unlock the signer when needed
|
|
31
|
+
await signer.unlock("your-password");
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Simple Signer
|
|
35
|
+
|
|
36
|
+
A basic signer that holds the secret key in memory with NIP-04 and NIP-44 encryption support.
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
// Create new signer with random key
|
|
40
|
+
const signer = new SimpleSigner();
|
|
41
|
+
|
|
42
|
+
// Or import existing key
|
|
43
|
+
const key = new Uint8Array(32);
|
|
44
|
+
window.crypto.getRandomValues(key);
|
|
45
|
+
const signer = new SimpleSigner(key);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Nostr Connect Signer (NIP-46)
|
|
49
|
+
|
|
50
|
+
A client-side implementation for remote signing using [NIP-46](https://github.com/nostr-protocol/nips/blob/master/46.md).
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// First, set up the required relay communication methods
|
|
54
|
+
import { Observable } from "rxjs";
|
|
55
|
+
|
|
56
|
+
// Define subscription method for receiving events
|
|
57
|
+
const subscriptionMethod = (filters, relays) => {
|
|
58
|
+
return new Observable((observer) => {
|
|
59
|
+
// Create subscription to relays
|
|
60
|
+
const cleanup = subscribeToRelays(relays, filters, (event) => {
|
|
61
|
+
observer.next(event);
|
|
62
|
+
});
|
|
63
|
+
return () => cleanup();
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// Define publish method for sending events
|
|
68
|
+
const publishMethod = async (event, relays) => {
|
|
69
|
+
for (const relay of relays) await publishToRelay(relay, event);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// You can set these methods globally at app initialization
|
|
73
|
+
NostrConnectSigner.subscriptionMethod = subscriptionMethod;
|
|
74
|
+
NostrConnectSigner.publishMethod = publishMethod;
|
|
75
|
+
|
|
76
|
+
// Now create and use the signer
|
|
77
|
+
const signer = new NostrConnectSigner({
|
|
78
|
+
remote: "<remote signer pubkey>",
|
|
79
|
+
relays: ["wss://relay.example.com"],
|
|
80
|
+
// Or pass methods directly to the constructor
|
|
81
|
+
subscriptionMethod,
|
|
82
|
+
publishMethod,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Create a connection URI for your app
|
|
86
|
+
const uri = signer.getNostrConnectURI({
|
|
87
|
+
name: "My App",
|
|
88
|
+
url: "https://example.com",
|
|
89
|
+
permissions: NostrConnectSigner.buildSigningPermissions([0, 1, 3]),
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Connect using bunker URI
|
|
93
|
+
const bunkerSigner = await NostrConnectSigner.fromBunkerURI("bunker://...your-uri-here...", {
|
|
94
|
+
permissions: NostrConnectSigner.buildSigningPermissions([0, 1, 3]),
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Other Signers
|
|
99
|
+
|
|
100
|
+
- **Serial Port Signer**: For hardware signing devices (Chrome browsers only)
|
|
101
|
+
- **Amber Clipboard Signer**: Integration with Amber wallet's web API
|
|
@@ -82,8 +82,8 @@ interface Observer<T> {
|
|
|
82
82
|
type Subscribable<T extends unknown> = {
|
|
83
83
|
subscribe: (observer: Partial<Observer<T>>) => Unsubscribable;
|
|
84
84
|
};
|
|
85
|
-
export type NostrSubscriptionMethod = (
|
|
86
|
-
export type NostrPublishMethod = (
|
|
85
|
+
export type NostrSubscriptionMethod = (relays: string[], filters: Filter[]) => Subscribable<NostrEvent>;
|
|
86
|
+
export type NostrPublishMethod = (relays: string[], event: NostrEvent) => void | Promise<void>;
|
|
87
87
|
export type NostrConnectAppMetadata = {
|
|
88
88
|
name?: string;
|
|
89
89
|
image?: string;
|
|
@@ -97,12 +97,12 @@ export class NostrConnectSigner {
|
|
|
97
97
|
this.subscriptionOpen = true;
|
|
98
98
|
const pubkey = await this.signer.getPublicKey();
|
|
99
99
|
// Setup subscription
|
|
100
|
-
this.req = this.subscriptionMethod([
|
|
100
|
+
this.req = this.subscriptionMethod(this.relays, [
|
|
101
101
|
{
|
|
102
102
|
kinds: [kinds.NostrConnect],
|
|
103
103
|
"#p": [pubkey],
|
|
104
104
|
},
|
|
105
|
-
]
|
|
105
|
+
]).subscribe({
|
|
106
106
|
next: (event) => this.handleEvent(event),
|
|
107
107
|
});
|
|
108
108
|
this.log("Opened", this.relays);
|
|
@@ -188,7 +188,7 @@ export class NostrConnectSigner {
|
|
|
188
188
|
this.log(`Sending request ${id} (${method}) ${JSON.stringify(params)}`);
|
|
189
189
|
const p = createDefer();
|
|
190
190
|
this.requests.set(id, p);
|
|
191
|
-
await this.publishMethod?.(
|
|
191
|
+
await this.publishMethod?.(this.relays, event);
|
|
192
192
|
return p;
|
|
193
193
|
}
|
|
194
194
|
/** Connect to remote signer */
|
|
@@ -17,7 +17,7 @@ describe("NostrConnectSigner", () => {
|
|
|
17
17
|
publishMethod: publish,
|
|
18
18
|
});
|
|
19
19
|
signer.connect();
|
|
20
|
-
expect(subscription).toHaveBeenCalledWith([{ "#p": [await client.getPublicKey()], kinds: [24133] }]
|
|
20
|
+
expect(subscription).toHaveBeenCalledWith(relays, [{ "#p": [await client.getPublicKey()], kinds: [24133] }]);
|
|
21
21
|
});
|
|
22
22
|
});
|
|
23
23
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-signers",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20250429163257",
|
|
4
4
|
"description": "Signer classes for applesauce",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@noble/hashes": "^1.7.1",
|
|
37
37
|
"@noble/secp256k1": "^1.7.1",
|
|
38
38
|
"@scure/base": "^1.2.4",
|
|
39
|
-
"applesauce-core": "0.0.0-next-
|
|
39
|
+
"applesauce-core": "0.0.0-next-20250429163257",
|
|
40
40
|
"debug": "^4.4.0",
|
|
41
41
|
"nanoid": "^5.0.9",
|
|
42
42
|
"nostr-tools": "^2.10.4"
|