applesauce-signers 0.0.0-next-20250609213928 → 0.0.0-next-20250610194602
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/helpers/encryption.d.ts +1 -1
- package/dist/helpers/encryption.js +1 -6
- package/dist/signers/password-signer.d.ts +4 -0
- package/dist/signers/password-signer.js +16 -0
- package/dist/signers/readonly-signer.d.ts +2 -0
- package/dist/signers/readonly-signer.js +7 -0
- package/dist/signers/simple-signer.d.ts +2 -0
- package/dist/signers/simple-signer.js +5 -0
- package/package.json +2 -2
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* Checks if a string is encrypted with NIP-04 or NIP-44
|
|
3
3
|
* @see https://github.com/nostr-protocol/nips/pull/1248#issuecomment-2437731316
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export { isNIP04Encrypted as isNIP04 } from "applesauce-core/helpers/encryption";
|
|
@@ -2,9 +2,4 @@
|
|
|
2
2
|
* Checks if a string is encrypted with NIP-04 or NIP-44
|
|
3
3
|
* @see https://github.com/nostr-protocol/nips/pull/1248#issuecomment-2437731316
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
6
|
-
const l = ciphertext.length;
|
|
7
|
-
if (l < 28)
|
|
8
|
-
return false;
|
|
9
|
-
return (ciphertext[l - 28] == "?" && ciphertext[l - 27] == "i" && ciphertext[l - 26] == "v" && ciphertext[l - 25] == "=");
|
|
10
|
-
}
|
|
5
|
+
export { isNIP04Encrypted as isNIP04 } from "applesauce-core/helpers/encryption";
|
|
@@ -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;
|
|
@@ -89,4 +90,19 @@ export class PasswordSigner {
|
|
|
89
90
|
await this.requestUnlock();
|
|
90
91
|
return nip44.v2.decrypt(ciphertext, nip44.v2.utils.getConversationKey(this.key, pubkey));
|
|
91
92
|
}
|
|
93
|
+
/** Creates a PasswordSigner from a hex private key or NIP-19 nsec and password */
|
|
94
|
+
static async fromPrivateKey(privateKey, password) {
|
|
95
|
+
const signer = new PasswordSigner();
|
|
96
|
+
signer.key = normalizeToSecretKey(privateKey);
|
|
97
|
+
await signer.setPassword(password);
|
|
98
|
+
return signer;
|
|
99
|
+
}
|
|
100
|
+
/** Creates a PasswordSigner from a ncryptsec and unlocks it with the provided password */
|
|
101
|
+
static async fromNcryptsec(ncryptsec, password) {
|
|
102
|
+
const signer = new PasswordSigner();
|
|
103
|
+
signer.ncryptsec = ncryptsec;
|
|
104
|
+
if (password)
|
|
105
|
+
await signer.unlock(password);
|
|
106
|
+
return signer;
|
|
107
|
+
}
|
|
92
108
|
}
|
|
@@ -19,4 +19,6 @@ export declare class ReadonlySigner implements Nip07Interface {
|
|
|
19
19
|
nip04Decrypt(): string;
|
|
20
20
|
nip44Encrypt(): string;
|
|
21
21
|
nip44Decrypt(): string;
|
|
22
|
+
/** Creates a ReadonlySigner from a hex public key or NIP-19 npub */
|
|
23
|
+
static fromPubkey(pubkey: string): ReadonlySigner;
|
|
22
24
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isHexKey, normalizeToPubkey } from "applesauce-core/helpers";
|
|
1
2
|
/** A signer that only implements getPublicKey and throws on ever other method */
|
|
2
3
|
export class ReadonlySigner {
|
|
3
4
|
pubkey;
|
|
@@ -5,6 +6,8 @@ export class ReadonlySigner {
|
|
|
5
6
|
nip44;
|
|
6
7
|
constructor(pubkey) {
|
|
7
8
|
this.pubkey = pubkey;
|
|
9
|
+
if (!isHexKey(pubkey))
|
|
10
|
+
throw new Error("Invalid public key");
|
|
8
11
|
this.nip04 = {
|
|
9
12
|
encrypt: this.nip04Encrypt.bind(this),
|
|
10
13
|
decrypt: this.nip04Decrypt.bind(this),
|
|
@@ -35,4 +38,8 @@ export class ReadonlySigner {
|
|
|
35
38
|
nip44Decrypt() {
|
|
36
39
|
throw new Error("Cant decrypt with readonly");
|
|
37
40
|
}
|
|
41
|
+
/** Creates a ReadonlySigner from a hex public key or NIP-19 npub */
|
|
42
|
+
static fromPubkey(pubkey) {
|
|
43
|
+
return new ReadonlySigner(normalizeToPubkey(pubkey));
|
|
44
|
+
}
|
|
38
45
|
}
|
|
@@ -13,4 +13,6 @@ export declare class SimpleSigner {
|
|
|
13
13
|
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
14
14
|
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
15
15
|
};
|
|
16
|
+
/** Creates a SimpleSigner from a hex private key or NIP-19 nsec */
|
|
17
|
+
static fromKey(privateKey: Uint8Array | string): SimpleSigner;
|
|
16
18
|
}
|
|
@@ -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-20250610194602",
|
|
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-20250610194602",
|
|
40
40
|
"debug": "^4.4.0",
|
|
41
41
|
"nanoid": "^5.0.9",
|
|
42
42
|
"nostr-tools": "^2.13"
|