applesauce-signers 0.0.0-next-20250610175335 → 0.0.0-next-20250718170433
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/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/interface.d.ts +15 -0
- package/dist/interface.js +1 -0
- package/dist/nip-07.d.ts +10 -14
- package/dist/signers/__tests__/nostr-connect-signer.test.js +18 -61
- package/dist/signers/amber-clipboard-signer.d.ts +6 -6
- package/dist/signers/extension-signer.d.ts +9 -16
- package/dist/signers/extension-signer.js +9 -20
- package/dist/signers/nostr-connect-signer.d.ts +6 -6
- package/dist/signers/password-signer.d.ts +10 -6
- package/dist/signers/password-signer.js +24 -3
- package/dist/signers/readonly-signer.d.ts +14 -13
- package/dist/signers/readonly-signer.js +11 -10
- package/dist/signers/serial-port-signer.d.ts +4 -4
- package/dist/signers/simple-signer.d.ts +4 -1
- package/dist/signers/simple-signer.js +5 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EventTemplate, NostrEvent } from "nostr-tools";
|
|
2
|
+
export type ISigner = {
|
|
3
|
+
getPublicKey: () => Promise<string>;
|
|
4
|
+
signEvent: (template: EventTemplate) => Promise<NostrEvent>;
|
|
5
|
+
nip04?: {
|
|
6
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
7
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
8
|
+
};
|
|
9
|
+
nip44?: {
|
|
10
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
11
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/** @deprecated Use ISigner instead */
|
|
15
|
+
export type Nip07Interface = ISigner;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/nip-07.d.ts
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import { EventTemplate, NostrEvent } from "nostr-tools";
|
|
2
|
-
export type
|
|
3
|
-
getPublicKey: () => Promise<string
|
|
4
|
-
signEvent: (template: EventTemplate) => Promise<NostrEvent
|
|
5
|
-
getRelays?: () => Record<string, {
|
|
6
|
-
read: boolean;
|
|
7
|
-
write: boolean;
|
|
8
|
-
}> | Promise<Record<string, {
|
|
9
|
-
read: boolean;
|
|
10
|
-
write: boolean;
|
|
11
|
-
}>>;
|
|
2
|
+
export type ISigner = {
|
|
3
|
+
getPublicKey: () => Promise<string>;
|
|
4
|
+
signEvent: (template: EventTemplate) => Promise<NostrEvent>;
|
|
12
5
|
nip04?: {
|
|
13
|
-
encrypt: (pubkey: string, plaintext: string) => Promise<string
|
|
14
|
-
decrypt: (pubkey: string, ciphertext: string) => Promise<string
|
|
6
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
7
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
15
8
|
};
|
|
16
9
|
nip44?: {
|
|
17
|
-
encrypt: (pubkey: string, plaintext: string) => Promise<string
|
|
18
|
-
decrypt: (pubkey: string, ciphertext: string) => Promise<string
|
|
10
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
11
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
19
12
|
};
|
|
20
13
|
};
|
|
14
|
+
|
|
15
|
+
/** @deprecated Use ISigner instead */
|
|
16
|
+
export type Nip07Interface = ISigner;
|
|
@@ -1,66 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
2
|
import { NostrConnectSigner } from "../nostr-connect-signer.js";
|
|
3
3
|
import { SimpleSigner } from "../simple-signer.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
subscriptionMethod,
|
|
22
|
-
publishMethod,
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
describe("connection", () => {
|
|
26
|
-
it("should call subscription method with filters", async () => {
|
|
27
|
-
signer.connect();
|
|
28
|
-
expect(subscriptionMethod).toHaveBeenCalledWith(relays, [{ "#p": [await client.getPublicKey()], kinds: [24133] }]);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
describe("open", () => {
|
|
32
|
-
it("should call subscription method with filters", async () => {
|
|
33
|
-
signer.open();
|
|
34
|
-
expect(subscriptionMethod).toHaveBeenCalledWith(relays, [{ "#p": [await client.getPublicKey()], kinds: [24133] }]);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
describe("waitForSigner", () => {
|
|
38
|
-
it("should accept an abort signal", async () => {
|
|
39
|
-
const signer = new NostrConnectSigner({
|
|
40
|
-
relays: ["wss://relay.signer.com"],
|
|
41
|
-
signer: client,
|
|
42
|
-
subscriptionMethod,
|
|
43
|
-
publishMethod,
|
|
4
|
+
describe("NostrConnectSigner", () => {
|
|
5
|
+
describe("connection", () => {
|
|
6
|
+
it("should call subscription method with filters", async () => {
|
|
7
|
+
const relays = ["wss://relay.signer.com"];
|
|
8
|
+
const subscription = vi.fn().mockReturnValue({ subscribe: vi.fn() });
|
|
9
|
+
const publish = vi.fn(async () => { });
|
|
10
|
+
const client = new SimpleSigner();
|
|
11
|
+
const remote = new SimpleSigner();
|
|
12
|
+
const signer = new NostrConnectSigner({
|
|
13
|
+
relays,
|
|
14
|
+
remote: await remote.getPublicKey(),
|
|
15
|
+
signer: client,
|
|
16
|
+
subscriptionMethod: subscription,
|
|
17
|
+
publishMethod: publish,
|
|
18
|
+
});
|
|
19
|
+
signer.connect();
|
|
20
|
+
expect(subscription).toHaveBeenCalledWith(relays, [{ "#p": [await client.getPublicKey()], kinds: [24133] }]);
|
|
44
21
|
});
|
|
45
|
-
const controller = new AbortController();
|
|
46
|
-
const p = signer.waitForSigner(controller.signal);
|
|
47
|
-
setTimeout(() => {
|
|
48
|
-
controller.abort();
|
|
49
|
-
}, 10);
|
|
50
|
-
await expect(p).rejects.toThrow("Aborted");
|
|
51
|
-
expect(signer.listening).toBe(false);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
describe("close", () => {
|
|
55
|
-
it("should close the connection", async () => {
|
|
56
|
-
await signer.open();
|
|
57
|
-
expect(req.subscribe).toHaveBeenCalled();
|
|
58
|
-
await signer.close();
|
|
59
|
-
expect(observable.unsubscribe).toHaveBeenCalled();
|
|
60
|
-
});
|
|
61
|
-
it("it should cancel waiting for signer promie", async () => {
|
|
62
|
-
const p = signer.waitForSigner();
|
|
63
|
-
await signer.close();
|
|
64
|
-
await expect(p).rejects.toThrow("Closed");
|
|
65
22
|
});
|
|
66
23
|
});
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { EventTemplate, VerifiedEvent, verifyEvent } from "nostr-tools";
|
|
2
|
-
import {
|
|
2
|
+
import { ISigner } from "../interface.js";
|
|
3
3
|
/**
|
|
4
4
|
* A Signer for [amber](https://github.com/greenart7c3/Amber) clipboard API
|
|
5
5
|
* @see https://github.com/greenart7c3/Amber/blob/master/docs/web-apps.md
|
|
6
6
|
*/
|
|
7
|
-
export declare class AmberClipboardSigner implements
|
|
7
|
+
export declare class AmberClipboardSigner implements ISigner {
|
|
8
8
|
/** If the signer is supported on this platform */
|
|
9
9
|
static SUPPORTED: false | (() => Promise<string>);
|
|
10
10
|
private pendingRequest;
|
|
11
11
|
pubkey?: string;
|
|
12
12
|
verifyEvent: typeof verifyEvent;
|
|
13
13
|
nip04: {
|
|
14
|
-
encrypt: (pubkey: string, plaintext: string) => Promise<string
|
|
15
|
-
decrypt: (pubkey: string, ciphertext: string) => Promise<string
|
|
14
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
15
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
16
16
|
};
|
|
17
17
|
nip44: {
|
|
18
|
-
encrypt: (pubkey: string, plaintext: string) => Promise<string
|
|
19
|
-
decrypt: (pubkey: string, ciphertext: string) => Promise<string
|
|
18
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
19
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
20
20
|
};
|
|
21
21
|
constructor();
|
|
22
22
|
private onVisibilityChange;
|
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
import { EventTemplate } from "nostr-tools";
|
|
2
|
-
import {
|
|
1
|
+
import { EventTemplate, VerifiedEvent } from "nostr-tools";
|
|
2
|
+
import { ISigner } from "../interface.js";
|
|
3
3
|
/** AN error that is throw when the window.nostr extension is missing */
|
|
4
4
|
export declare class ExtensionMissingError extends Error {
|
|
5
5
|
}
|
|
6
6
|
/** A signer that is a proxy for window.nostr */
|
|
7
|
-
export declare class ExtensionSigner implements
|
|
7
|
+
export declare class ExtensionSigner implements ISigner {
|
|
8
8
|
get nip04(): {
|
|
9
|
-
encrypt: (pubkey: string, plaintext: string) => Promise<string
|
|
10
|
-
decrypt: (pubkey: string, ciphertext: string) => Promise<string
|
|
9
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
10
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
11
11
|
} | undefined;
|
|
12
12
|
get nip44(): {
|
|
13
|
-
encrypt: (pubkey: string, plaintext: string) => Promise<string
|
|
14
|
-
decrypt: (pubkey: string, ciphertext: string) => Promise<string
|
|
13
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
14
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
15
15
|
} | undefined;
|
|
16
16
|
protected pubkey: string | undefined;
|
|
17
|
-
getPublicKey():
|
|
18
|
-
|
|
19
|
-
read: boolean;
|
|
20
|
-
write: boolean;
|
|
21
|
-
}> | Promise<Record<string, {
|
|
22
|
-
read: boolean;
|
|
23
|
-
write: boolean;
|
|
24
|
-
}>>;
|
|
25
|
-
signEvent(template: EventTemplate): import("nostr-tools").Event | Promise<import("nostr-tools").Event>;
|
|
17
|
+
getPublicKey(): Promise<string>;
|
|
18
|
+
signEvent(template: EventTemplate): Promise<VerifiedEvent>;
|
|
26
19
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { verifyEvent } from "nostr-tools";
|
|
1
2
|
/** AN error that is throw when the window.nostr extension is missing */
|
|
2
3
|
export class ExtensionMissingError extends Error {
|
|
3
4
|
}
|
|
@@ -10,32 +11,20 @@ export class ExtensionSigner {
|
|
|
10
11
|
return window.nostr?.nip44;
|
|
11
12
|
}
|
|
12
13
|
pubkey = undefined;
|
|
13
|
-
getPublicKey() {
|
|
14
|
+
async getPublicKey() {
|
|
14
15
|
if (!window.nostr)
|
|
15
16
|
throw new ExtensionMissingError("Signer extension missing");
|
|
16
17
|
if (this.pubkey)
|
|
17
18
|
return this.pubkey;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return p.then((pubkey) => {
|
|
21
|
-
this.pubkey = pubkey;
|
|
22
|
-
return pubkey;
|
|
23
|
-
});
|
|
24
|
-
else {
|
|
25
|
-
this.pubkey = p;
|
|
26
|
-
return p;
|
|
27
|
-
}
|
|
19
|
+
this.pubkey = await window.nostr.getPublicKey();
|
|
20
|
+
return this.pubkey;
|
|
28
21
|
}
|
|
29
|
-
|
|
22
|
+
async signEvent(template) {
|
|
30
23
|
if (!window.nostr)
|
|
31
24
|
throw new ExtensionMissingError("Signer extension missing");
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
signEvent(template) {
|
|
37
|
-
if (!window.nostr)
|
|
38
|
-
throw new ExtensionMissingError("Signer extension missing");
|
|
39
|
-
return window.nostr.signEvent(template);
|
|
25
|
+
const event = await window.nostr.signEvent(template);
|
|
26
|
+
if (!verifyEvent(event))
|
|
27
|
+
throw new Error("Extension returned an invalid event");
|
|
28
|
+
return event;
|
|
40
29
|
}
|
|
41
30
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventTemplate, Filter, NostrEvent, verifyEvent } from "nostr-tools";
|
|
2
|
-
import {
|
|
2
|
+
import { ISigner, SimpleSigner } from "applesauce-signers";
|
|
3
3
|
import { Deferred } from "applesauce-core/promise";
|
|
4
4
|
export declare function isErrorResponse(response: any): response is NostrConnectErrorResponse;
|
|
5
5
|
export declare enum Permission {
|
|
@@ -92,7 +92,7 @@ export type NostrConnectAppMetadata = {
|
|
|
92
92
|
url?: string | URL;
|
|
93
93
|
permissions?: string[];
|
|
94
94
|
};
|
|
95
|
-
export declare class NostrConnectSigner implements
|
|
95
|
+
export declare class NostrConnectSigner implements ISigner {
|
|
96
96
|
/** A method that is called when an event needs to be published */
|
|
97
97
|
protected publishMethod: NostrPublishMethod;
|
|
98
98
|
/** The active nostr subscription */
|
|
@@ -118,12 +118,12 @@ export declare class NostrConnectSigner implements Nip07Interface {
|
|
|
118
118
|
/** A secret used when initiating a connection from the client side */
|
|
119
119
|
protected clientSecret: string;
|
|
120
120
|
nip04?: {
|
|
121
|
-
encrypt: (pubkey: string, plaintext: string) => Promise<string
|
|
122
|
-
decrypt: (pubkey: string, ciphertext: string) => Promise<string
|
|
121
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
122
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
123
123
|
} | undefined;
|
|
124
124
|
nip44?: {
|
|
125
|
-
encrypt: (pubkey: string, plaintext: string) => Promise<string
|
|
126
|
-
decrypt: (pubkey: string, ciphertext: string) => Promise<string
|
|
125
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
126
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
127
127
|
} | undefined;
|
|
128
128
|
/** A fallback method to use for subscriptionMethod if none is pass in when creating the signer */
|
|
129
129
|
static subscriptionMethod: NostrSubscriptionMethod | undefined;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { EventTemplate } from "nostr-tools";
|
|
2
2
|
import { Deferred } from "applesauce-core/promise";
|
|
3
|
-
import {
|
|
3
|
+
import { ISigner } from "../interface.js";
|
|
4
4
|
/** A NIP-49 (Private Key Encryption) signer */
|
|
5
|
-
export declare class PasswordSigner implements
|
|
5
|
+
export declare class PasswordSigner implements ISigner {
|
|
6
6
|
key: Uint8Array | null;
|
|
7
7
|
ncryptsec?: string;
|
|
8
8
|
nip04: {
|
|
9
|
-
encrypt: (pubkey: string, plaintext: string) => Promise<string
|
|
10
|
-
decrypt: (pubkey: string, ciphertext: string) => Promise<string
|
|
9
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
10
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
11
11
|
};
|
|
12
12
|
nip44: {
|
|
13
|
-
encrypt: (pubkey: string, plaintext: string) => Promise<string
|
|
14
|
-
decrypt: (pubkey: string, ciphertext: string) => Promise<string
|
|
13
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
14
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
15
15
|
};
|
|
16
16
|
get unlocked(): boolean;
|
|
17
17
|
constructor();
|
|
@@ -31,4 +31,8 @@ export declare class PasswordSigner implements Nip07Interface {
|
|
|
31
31
|
nip04Decrypt(pubkey: string, ciphertext: string): Promise<string>;
|
|
32
32
|
nip44Encrypt(pubkey: string, plaintext: string): Promise<string>;
|
|
33
33
|
nip44Decrypt(pubkey: string, ciphertext: string): Promise<string>;
|
|
34
|
+
/** Creates a PasswordSigner from a hex private key or NIP-19 nsec and password */
|
|
35
|
+
static fromPrivateKey(privateKey: Uint8Array | string, password: string): Promise<PasswordSigner>;
|
|
36
|
+
/** Creates a PasswordSigner from a ncryptsec and unlocks it with the provided password */
|
|
37
|
+
static fromNcryptsec(ncryptsec: string, password?: string): Promise<PasswordSigner>;
|
|
34
38
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { finalizeEvent, getPublicKey, nip04, nip44 } from "nostr-tools";
|
|
2
2
|
import { encrypt, decrypt } from "nostr-tools/nip49";
|
|
3
3
|
import { createDefer } from "applesauce-core/promise";
|
|
4
|
+
import { normalizeToSecretKey } from "applesauce-core/helpers";
|
|
4
5
|
/** A NIP-49 (Private Key Encryption) signer */
|
|
5
6
|
export class PasswordSigner {
|
|
6
7
|
key = null;
|
|
@@ -51,9 +52,14 @@ export class PasswordSigner {
|
|
|
51
52
|
if (this.key)
|
|
52
53
|
return;
|
|
53
54
|
if (this.ncryptsec) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
try {
|
|
56
|
+
this.key = decrypt(this.ncryptsec, password);
|
|
57
|
+
if (!this.key)
|
|
58
|
+
throw new Error("Failed to decrypt key");
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throw new Error("failed to decrypt key: " + (error instanceof Error ? error.message : String(error)));
|
|
62
|
+
}
|
|
57
63
|
}
|
|
58
64
|
else
|
|
59
65
|
throw new Error("Missing ncryptsec");
|
|
@@ -89,4 +95,19 @@ export class PasswordSigner {
|
|
|
89
95
|
await this.requestUnlock();
|
|
90
96
|
return nip44.v2.decrypt(ciphertext, nip44.v2.utils.getConversationKey(this.key, pubkey));
|
|
91
97
|
}
|
|
98
|
+
/** Creates a PasswordSigner from a hex private key or NIP-19 nsec and password */
|
|
99
|
+
static async fromPrivateKey(privateKey, password) {
|
|
100
|
+
const signer = new PasswordSigner();
|
|
101
|
+
signer.key = normalizeToSecretKey(privateKey);
|
|
102
|
+
await signer.setPassword(password);
|
|
103
|
+
return signer;
|
|
104
|
+
}
|
|
105
|
+
/** Creates a PasswordSigner from a ncryptsec and unlocks it with the provided password */
|
|
106
|
+
static async fromNcryptsec(ncryptsec, password) {
|
|
107
|
+
const signer = new PasswordSigner();
|
|
108
|
+
signer.ncryptsec = ncryptsec;
|
|
109
|
+
if (password)
|
|
110
|
+
await signer.unlock(password);
|
|
111
|
+
return signer;
|
|
112
|
+
}
|
|
92
113
|
}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { VerifiedEvent } from "nostr-tools";
|
|
2
|
-
import {
|
|
2
|
+
import { ISigner } from "../interface.js";
|
|
3
3
|
/** A signer that only implements getPublicKey and throws on ever other method */
|
|
4
|
-
export declare class ReadonlySigner implements
|
|
4
|
+
export declare class ReadonlySigner implements ISigner {
|
|
5
5
|
private pubkey;
|
|
6
6
|
nip04: {
|
|
7
|
-
encrypt: (pubkey: string, plaintext: string) => Promise<string
|
|
8
|
-
decrypt: (pubkey: string, ciphertext: string) => Promise<string
|
|
7
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
8
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
9
9
|
};
|
|
10
10
|
nip44: {
|
|
11
|
-
encrypt: (pubkey: string, plaintext: string) => Promise<string
|
|
12
|
-
decrypt: (pubkey: string, ciphertext: string) => Promise<string
|
|
11
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
12
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
13
13
|
};
|
|
14
14
|
constructor(pubkey: string);
|
|
15
|
-
getPublicKey(): string
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
getPublicKey(): Promise<string>;
|
|
16
|
+
signEvent(): Promise<VerifiedEvent>;
|
|
17
|
+
nip04Encrypt(): Promise<string>;
|
|
18
|
+
nip04Decrypt(): Promise<string>;
|
|
19
|
+
nip44Encrypt(): Promise<string>;
|
|
20
|
+
nip44Decrypt(): Promise<string>;
|
|
21
|
+
/** Creates a ReadonlySigner from a hex public key or NIP-19 npub */
|
|
22
|
+
static fromPubkey(pubkey: string): ReadonlySigner;
|
|
22
23
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isHexKey } from "applesauce-core/helpers";
|
|
1
|
+
import { isHexKey, normalizeToPubkey } from "applesauce-core/helpers";
|
|
2
2
|
/** A signer that only implements getPublicKey and throws on ever other method */
|
|
3
3
|
export class ReadonlySigner {
|
|
4
4
|
pubkey;
|
|
@@ -17,25 +17,26 @@ export class ReadonlySigner {
|
|
|
17
17
|
decrypt: this.nip44Decrypt.bind(this),
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
getPublicKey() {
|
|
20
|
+
async getPublicKey() {
|
|
21
21
|
return this.pubkey;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
return {};
|
|
25
|
-
}
|
|
26
|
-
signEvent() {
|
|
23
|
+
async signEvent() {
|
|
27
24
|
throw new Error("Cant sign events with readonly");
|
|
28
25
|
}
|
|
29
|
-
nip04Encrypt() {
|
|
26
|
+
async nip04Encrypt() {
|
|
30
27
|
throw new Error("Cant encrypt with readonly");
|
|
31
28
|
}
|
|
32
|
-
nip04Decrypt() {
|
|
29
|
+
async nip04Decrypt() {
|
|
33
30
|
throw new Error("Cant decrypt with readonly");
|
|
34
31
|
}
|
|
35
|
-
nip44Encrypt() {
|
|
32
|
+
async nip44Encrypt() {
|
|
36
33
|
throw new Error("Cant encrypt with readonly");
|
|
37
34
|
}
|
|
38
|
-
nip44Decrypt() {
|
|
35
|
+
async nip44Decrypt() {
|
|
39
36
|
throw new Error("Cant decrypt with readonly");
|
|
40
37
|
}
|
|
38
|
+
/** Creates a ReadonlySigner from a hex public key or NIP-19 npub */
|
|
39
|
+
static fromPubkey(pubkey) {
|
|
40
|
+
return new ReadonlySigner(normalizeToPubkey(pubkey));
|
|
41
|
+
}
|
|
41
42
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Deferred } from "applesauce-core/promise";
|
|
2
2
|
import { EventTemplate, verifyEvent } from "nostr-tools";
|
|
3
|
-
import {
|
|
3
|
+
import { ISigner } from "../interface.js";
|
|
4
4
|
type Callback = () => void;
|
|
5
5
|
type DeviceOpts = {
|
|
6
6
|
onConnect?: Callback;
|
|
@@ -9,15 +9,15 @@ type DeviceOpts = {
|
|
|
9
9
|
onDone?: Callback;
|
|
10
10
|
};
|
|
11
11
|
/** A signer that works with [nostr-signing-device](https://github.com/lnbits/nostr-signing-device) */
|
|
12
|
-
export declare class SerialPortSigner implements
|
|
12
|
+
export declare class SerialPortSigner implements ISigner {
|
|
13
13
|
protected log: import("debug").Debugger;
|
|
14
14
|
protected writer: WritableStreamDefaultWriter<string> | null;
|
|
15
15
|
pubkey?: string;
|
|
16
16
|
get isConnected(): boolean;
|
|
17
17
|
verifyEvent: typeof verifyEvent;
|
|
18
18
|
nip04: {
|
|
19
|
-
encrypt: (pubkey: string, plaintext: string) => Promise<string
|
|
20
|
-
decrypt: (pubkey: string, ciphertext: string) => Promise<string
|
|
19
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
20
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
21
21
|
};
|
|
22
22
|
constructor();
|
|
23
23
|
protected lastCommand: Deferred<string> | null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EventTemplate } from "nostr-tools";
|
|
2
|
+
import { ISigner } from "../interface.js";
|
|
2
3
|
/** A Simple NIP-07 signer class */
|
|
3
|
-
export declare class SimpleSigner {
|
|
4
|
+
export declare class SimpleSigner implements ISigner {
|
|
4
5
|
key: Uint8Array;
|
|
5
6
|
constructor(key?: Uint8Array);
|
|
6
7
|
getPublicKey(): Promise<string>;
|
|
@@ -13,4 +14,6 @@ export declare class SimpleSigner {
|
|
|
13
14
|
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
14
15
|
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
15
16
|
};
|
|
17
|
+
/** Creates a SimpleSigner from a hex private key or NIP-19 nsec */
|
|
18
|
+
static fromKey(privateKey: Uint8Array | string): SimpleSigner;
|
|
16
19
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { normalizeToSecretKey } from "applesauce-core/helpers";
|
|
1
2
|
import { finalizeEvent, generateSecretKey, getPublicKey, nip04, nip44 } from "nostr-tools";
|
|
2
3
|
/** A Simple NIP-07 signer class */
|
|
3
4
|
export class SimpleSigner {
|
|
@@ -19,4 +20,8 @@ export class SimpleSigner {
|
|
|
19
20
|
encrypt: async (pubkey, plaintext) => nip44.v2.encrypt(plaintext, nip44.v2.utils.getConversationKey(this.key, pubkey)),
|
|
20
21
|
decrypt: async (pubkey, ciphertext) => nip44.v2.decrypt(ciphertext, nip44.v2.utils.getConversationKey(this.key, pubkey)),
|
|
21
22
|
};
|
|
23
|
+
/** Creates a SimpleSigner from a hex private key or NIP-19 nsec */
|
|
24
|
+
static fromKey(privateKey) {
|
|
25
|
+
return new SimpleSigner(normalizeToSecretKey(privateKey));
|
|
26
|
+
}
|
|
22
27
|
}
|
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-20250718170433",
|
|
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": "
|
|
39
|
+
"applesauce-core": "^2.0.0",
|
|
40
40
|
"debug": "^4.4.0",
|
|
41
41
|
"nanoid": "^5.0.9",
|
|
42
42
|
"nostr-tools": "^2.13"
|