applesauce-signers 0.0.0-next-20251030142514 → 0.0.0-next-20251203172109
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/nostr-connect.js +2 -2
- package/dist/interop.d.ts +2 -1
- package/dist/signers/amber-clipboard-signer.d.ts +1 -1
- package/dist/signers/amber-clipboard-signer.js +3 -4
- package/dist/signers/extension-signer.d.ts +1 -1
- package/dist/signers/extension-signer.js +1 -1
- package/dist/signers/nostr-connect-provider.d.ts +1 -1
- package/dist/signers/nostr-connect-provider.js +1 -1
- package/dist/signers/nostr-connect-signer.d.ts +3 -3
- package/dist/signers/nostr-connect-signer.js +2 -1
- package/dist/signers/password-signer.d.ts +2 -2
- package/dist/signers/password-signer.js +7 -6
- package/dist/signers/private-key-signer.d.ts +2 -2
- package/dist/signers/private-key-signer.js +3 -2
- package/dist/signers/readonly-signer.d.ts +1 -1
- package/dist/signers/serial-port-signer.d.ts +2 -2
- package/dist/signers/serial-port-signer.js +15 -8
- package/package.json +3 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { setHiddenContentEncryptionMethod } from "applesauce-core/helpers";
|
|
1
|
+
import { setHiddenContentEncryptionMethod } from "applesauce-core/helpers/hidden-content";
|
|
2
2
|
import { isHexKey } from "applesauce-core/helpers/string";
|
|
3
|
-
import { kinds } from "
|
|
3
|
+
import { kinds } from "applesauce-core/helpers/event";
|
|
4
4
|
// Set encryption types for nostr connect events
|
|
5
5
|
setHiddenContentEncryptionMethod(kinds.NostrConnect, "nip44");
|
|
6
6
|
export function isErrorResponse(response) {
|
package/dist/interop.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { EventTemplate,
|
|
1
|
+
import { EventTemplate, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { Filter } from "applesauce-core/helpers/filter";
|
|
2
3
|
import { ObservableInput } from "rxjs";
|
|
3
4
|
export type ISigner = {
|
|
4
5
|
getPublicKey: () => Promise<string>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventTemplate, VerifiedEvent, verifyEvent } from "
|
|
1
|
+
import { EventTemplate, VerifiedEvent, verifyEvent } from "applesauce-core/helpers/event";
|
|
2
2
|
import { ISigner } from "../interop.js";
|
|
3
3
|
/**
|
|
4
4
|
* A Signer for [amber](https://github.com/greenart7c3/Amber) clipboard API
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { decodeProfilePointer, isHex, isHexKey } from "applesauce-core/helpers";
|
|
2
|
+
import { getEventHash, verifyEvent } from "applesauce-core/helpers/event";
|
|
3
3
|
import { createDefer } from "applesauce-core/promise";
|
|
4
4
|
/**
|
|
5
5
|
* A Signer for [amber](https://github.com/greenart7c3/Amber) clipboard API
|
|
@@ -78,8 +78,7 @@ export class AmberClipboardSigner {
|
|
|
78
78
|
return result;
|
|
79
79
|
}
|
|
80
80
|
else if (result.startsWith("npub") || result.startsWith("nprofile")) {
|
|
81
|
-
const
|
|
82
|
-
const pubkey = getPubkeyFromDecodeResult(decode);
|
|
81
|
+
const pubkey = decodeProfilePointer(result)?.pubkey;
|
|
83
82
|
if (!pubkey)
|
|
84
83
|
throw new Error("Expected npub from clipboard");
|
|
85
84
|
this.pubkey = pubkey;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventTemplate, VerifiedEvent } from "
|
|
1
|
+
import { EventTemplate, VerifiedEvent } from "applesauce-core/helpers/event";
|
|
2
2
|
import { ISigner } from "../interop.js";
|
|
3
3
|
/** AN error that is throw when the window.nostr extension is missing */
|
|
4
4
|
export declare class ExtensionMissingError extends Error {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { verifyEvent } from "nostr-tools";
|
|
2
1
|
import { isHexKey } from "applesauce-core/helpers";
|
|
2
|
+
import { verifyEvent } from "applesauce-core/helpers/event";
|
|
3
3
|
/** AN error that is throw when the window.nostr extension is missing */
|
|
4
4
|
export class ExtensionMissingError extends Error {
|
|
5
5
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventTemplate, NostrEvent } from "
|
|
1
|
+
import { EventTemplate, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
2
|
import { Subscription } from "rxjs";
|
|
3
3
|
import { ConnectRequestParams, ConnectResponseResults, NostrConnectMethod, NostrConnectResponse, NostrConnectURI } from "../helpers/nostr-connect.js";
|
|
4
4
|
import { ISigner, NostrConnectionMethodsOptions, NostrPool, NostrPublishMethod, NostrSubscriptionMethod } from "../interop.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { logger } from "applesauce-core";
|
|
2
2
|
import { getEncryptedContentEncryptionMethods, getHiddenContent, isEvent, unixNow, unlockHiddenContent, } from "applesauce-core/helpers";
|
|
3
|
+
import { kinds, verifyEvent } from "applesauce-core/helpers/event";
|
|
3
4
|
import { createDefer } from "applesauce-core/promise";
|
|
4
5
|
import { nanoid } from "nanoid";
|
|
5
|
-
import { kinds, verifyEvent } from "nostr-tools";
|
|
6
6
|
import { filter, from, repeat, retry } from "rxjs";
|
|
7
7
|
import { isNIP04 } from "../helpers/encryption.js";
|
|
8
8
|
import { createBunkerURI, NostrConnectMethod, parseNostrConnectURI, } from "../helpers/nostr-connect.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { EventTemplate, NostrEvent, verifyEvent } from "applesauce-core/helpers/event";
|
|
1
2
|
import { Deferred } from "applesauce-core/promise";
|
|
2
3
|
import { ISigner, NostrConnectionMethodsOptions, NostrPool, NostrPublishMethod, NostrSubscriptionMethod, PrivateKeySigner } from "applesauce-signers";
|
|
3
|
-
import { EventTemplate, NostrEvent, verifyEvent } from "nostr-tools";
|
|
4
4
|
import { Subscription } from "rxjs";
|
|
5
5
|
import { BunkerURI, NostrConnectAppMetadata } from "../helpers/nostr-connect.js";
|
|
6
6
|
export type NostrConnectSignerOptions = NostrConnectionMethodsOptions & {
|
|
@@ -67,7 +67,7 @@ export declare class NostrConnectSigner implements ISigner {
|
|
|
67
67
|
protected auths: Set<string>;
|
|
68
68
|
/** Call this method with incoming events */
|
|
69
69
|
handleEvent(event: NostrEvent): Promise<void>;
|
|
70
|
-
protected createRequestEvent(content: string, target?: string | undefined, kind?: number): Promise<import("nostr-tools").VerifiedEvent>;
|
|
70
|
+
protected createRequestEvent(content: string, target?: string | undefined, kind?: number): Promise<import("nostr-tools/core").VerifiedEvent>;
|
|
71
71
|
private makeRequest;
|
|
72
72
|
/** Connect to remote signer */
|
|
73
73
|
connect(secret?: string | undefined, permissions?: string[]): Promise<string>;
|
|
@@ -83,7 +83,7 @@ export declare class NostrConnectSigner implements ISigner {
|
|
|
83
83
|
/** Request to sign an event */
|
|
84
84
|
signEvent(template: EventTemplate & {
|
|
85
85
|
pubkey?: string;
|
|
86
|
-
}): Promise<import("nostr-tools").VerifiedEvent>;
|
|
86
|
+
}): Promise<import("nostr-tools/core").VerifiedEvent>;
|
|
87
87
|
nip04Encrypt(pubkey: string, plaintext: string): Promise<string>;
|
|
88
88
|
nip04Decrypt(pubkey: string, ciphertext: string): Promise<string>;
|
|
89
89
|
nip44Encrypt(pubkey: string, plaintext: string): Promise<string>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { logger } from "applesauce-core";
|
|
2
2
|
import { getHiddenContent, isHexKey, unixNow } from "applesauce-core/helpers";
|
|
3
|
+
import { kinds, verifyEvent } from "applesauce-core/helpers/event";
|
|
4
|
+
import { getPublicKey } from "applesauce-core/helpers/keys";
|
|
3
5
|
import { createDefer } from "applesauce-core/promise";
|
|
4
6
|
import { PrivateKeySigner, getConnectionMethods, } from "applesauce-signers";
|
|
5
7
|
import { nanoid } from "nanoid";
|
|
6
|
-
import { getPublicKey, kinds, verifyEvent } from "nostr-tools";
|
|
7
8
|
import { filter, from, repeat, retry } from "rxjs";
|
|
8
9
|
import { isNIP04 } from "../helpers/encryption.js";
|
|
9
10
|
import { NostrConnectMethod, buildSigningPermissions, createNostrConnectURI, parseBunkerURI, } from "../helpers/nostr-connect.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventTemplate } from "
|
|
1
|
+
import { EventTemplate } from "applesauce-core/helpers/event";
|
|
2
2
|
import { Deferred } from "applesauce-core/promise";
|
|
3
3
|
import { ISigner } from "../interop.js";
|
|
4
4
|
/** A NIP-49 (Private Key Encryption) signer */
|
|
@@ -26,7 +26,7 @@ export declare class PasswordSigner implements ISigner {
|
|
|
26
26
|
/** Locks the signer by removing the unencrypted key from memory */
|
|
27
27
|
lock(): void;
|
|
28
28
|
getPublicKey(): Promise<string>;
|
|
29
|
-
signEvent(event: EventTemplate): Promise<import("nostr-tools").VerifiedEvent>;
|
|
29
|
+
signEvent(event: EventTemplate): Promise<import("nostr-tools/core").VerifiedEvent>;
|
|
30
30
|
nip04Encrypt(pubkey: string, plaintext: string): Promise<string>;
|
|
31
31
|
nip04Decrypt(pubkey: string, ciphertext: string): Promise<string>;
|
|
32
32
|
nip44Encrypt(pubkey: string, plaintext: string): Promise<string>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { finalizeEvent, getPublicKey, nip04, nip44 } from "nostr-tools";
|
|
2
|
-
import { encrypt, decrypt } from "nostr-tools/nip49";
|
|
3
|
-
import { createDefer } from "applesauce-core/promise";
|
|
4
1
|
import { normalizeToSecretKey } from "applesauce-core/helpers";
|
|
2
|
+
import { nip04, nip44 } from "applesauce-core/helpers/encryption";
|
|
3
|
+
import { finalizeEvent } from "applesauce-core/helpers/event";
|
|
4
|
+
import { decryptSecretKey, encryptSecretKey, getPublicKey } from "applesauce-core/helpers/keys";
|
|
5
|
+
import { createDefer } from "applesauce-core/promise";
|
|
5
6
|
/** A NIP-49 (Private Key Encryption) signer */
|
|
6
7
|
export class PasswordSigner {
|
|
7
8
|
key = null;
|
|
@@ -35,12 +36,12 @@ export class PasswordSigner {
|
|
|
35
36
|
async setPassword(password) {
|
|
36
37
|
if (!this.key)
|
|
37
38
|
throw new Error("Cant set password until unlocked");
|
|
38
|
-
this.ncryptsec =
|
|
39
|
+
this.ncryptsec = encryptSecretKey(this.key, password);
|
|
39
40
|
}
|
|
40
41
|
/** Tests if the provided password is correct by decrypting the ncryptsec */
|
|
41
42
|
async testPassword(password) {
|
|
42
43
|
if (this.ncryptsec) {
|
|
43
|
-
const key =
|
|
44
|
+
const key = decryptSecretKey(this.ncryptsec, password);
|
|
44
45
|
if (!key)
|
|
45
46
|
throw new Error("Failed to decrypt key");
|
|
46
47
|
}
|
|
@@ -53,7 +54,7 @@ export class PasswordSigner {
|
|
|
53
54
|
return;
|
|
54
55
|
if (this.ncryptsec) {
|
|
55
56
|
try {
|
|
56
|
-
this.key =
|
|
57
|
+
this.key = decryptSecretKey(this.ncryptsec, password);
|
|
57
58
|
if (!this.key)
|
|
58
59
|
throw new Error("Failed to decrypt key");
|
|
59
60
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { EventTemplate } from "
|
|
1
|
+
import { EventTemplate } from "applesauce-core/helpers/event";
|
|
2
2
|
import { ISigner } from "../interop.js";
|
|
3
3
|
/** A Simple signer that holds the private key in memory */
|
|
4
4
|
export declare class PrivateKeySigner implements ISigner {
|
|
5
5
|
key: Uint8Array;
|
|
6
6
|
constructor(key?: Uint8Array);
|
|
7
7
|
getPublicKey(): Promise<string>;
|
|
8
|
-
signEvent(event: EventTemplate): Promise<import("nostr-tools").VerifiedEvent>;
|
|
8
|
+
signEvent(event: EventTemplate): Promise<import("nostr-tools/core").VerifiedEvent>;
|
|
9
9
|
nip04: {
|
|
10
10
|
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
11
11
|
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { normalizeToSecretKey } from "applesauce-core/helpers";
|
|
2
|
-
import {
|
|
1
|
+
import { finalizeEvent, normalizeToSecretKey } from "applesauce-core/helpers";
|
|
2
|
+
import { nip04, nip44 } from "applesauce-core/helpers/encryption";
|
|
3
|
+
import { generateSecretKey, getPublicKey } from "applesauce-core/helpers/keys";
|
|
3
4
|
/** A Simple signer that holds the private key in memory */
|
|
4
5
|
export class PrivateKeySigner {
|
|
5
6
|
key;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VerifiedEvent } from "
|
|
1
|
+
import { VerifiedEvent } from "applesauce-core/helpers/event";
|
|
2
2
|
import { ISigner } from "../interop.js";
|
|
3
3
|
/** A signer that only implements getPublicKey and throws on ever other method */
|
|
4
4
|
export declare class ReadonlySigner implements ISigner {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { EventTemplate, verifyEvent } from "applesauce-core/helpers/event";
|
|
1
2
|
import { Deferred } from "applesauce-core/promise";
|
|
2
|
-
import { EventTemplate, verifyEvent } from "nostr-tools";
|
|
3
3
|
import { ISigner } from "../interop.js";
|
|
4
4
|
type Callback = () => void;
|
|
5
5
|
type DeviceOpts = {
|
|
@@ -41,7 +41,7 @@ export declare class SerialPortSigner implements ISigner {
|
|
|
41
41
|
/** Requires the device to sign an event */
|
|
42
42
|
signEvent(draft: EventTemplate & {
|
|
43
43
|
pubkey?: string;
|
|
44
|
-
}): Promise<import("nostr-tools").VerifiedEvent>;
|
|
44
|
+
}): Promise<import("nostr-tools/core").VerifiedEvent>;
|
|
45
45
|
/** Pings to device to see if the connection is open */
|
|
46
46
|
ping(): void;
|
|
47
47
|
static SUPPORTED: boolean;
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
/// <reference types="@types/dom-serial" />
|
|
2
|
-
import { bytesToHex, hexToBytes, randomBytes } from "@noble/hashes/utils";
|
|
3
2
|
import { Point } from "@noble/secp256k1";
|
|
4
|
-
import { base64 } from "@scure/base";
|
|
5
3
|
import { logger } from "applesauce-core";
|
|
4
|
+
import { bytesToHex, getEventHash, hexToBytes, verifyEvent, } from "applesauce-core/helpers/event";
|
|
6
5
|
import { createDefer } from "applesauce-core/promise";
|
|
7
|
-
import { getEventHash, verifyEvent } from "nostr-tools";
|
|
8
6
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
9
7
|
function xOnlyToXY(p) {
|
|
10
8
|
return Point.fromHex(p).toHex().substring(2);
|
|
11
9
|
}
|
|
12
10
|
const utf8Decoder = new TextDecoder("utf-8");
|
|
13
11
|
const utf8Encoder = new TextEncoder();
|
|
12
|
+
// Helper functions for base64 encoding/decoding using built-in browser APIs
|
|
13
|
+
function base64Encode(uint8Array) {
|
|
14
|
+
return btoa(String.fromCharCode(...uint8Array));
|
|
15
|
+
}
|
|
16
|
+
function base64Decode(base64) {
|
|
17
|
+
return new Uint8Array(atob(base64)
|
|
18
|
+
.split("")
|
|
19
|
+
.map((c) => c.charCodeAt(0)));
|
|
20
|
+
}
|
|
14
21
|
/** A signer that works with [nostr-signing-device](https://github.com/lnbits/nostr-signing-device) */
|
|
15
22
|
export class SerialPortSigner {
|
|
16
23
|
log = logger.extend("SerialPortSigner");
|
|
@@ -167,13 +174,13 @@ export class SerialPortSigner {
|
|
|
167
174
|
async nip04Encrypt(pubkey, text) {
|
|
168
175
|
const sharedSecretStr = await this.callMethodOnDevice(SerialPortSigner.METHOD_SHARED_SECRET, [xOnlyToXY(pubkey)]);
|
|
169
176
|
const sharedSecret = hexToBytes(sharedSecretStr);
|
|
170
|
-
let iv = Uint8Array.from(
|
|
177
|
+
let iv = Uint8Array.from(window.crypto.getRandomValues(new Uint8Array(16)));
|
|
171
178
|
let plaintext = utf8Encoder.encode(text);
|
|
172
179
|
// @ts-ignore
|
|
173
180
|
let cryptoKey = await crypto.subtle.importKey("raw", sharedSecret, { name: "AES-CBC" }, false, ["encrypt"]);
|
|
174
181
|
let ciphertext = await crypto.subtle.encrypt({ name: "AES-CBC", iv }, cryptoKey, plaintext);
|
|
175
|
-
let ctb64 =
|
|
176
|
-
let ivb64 =
|
|
182
|
+
let ctb64 = base64Encode(new Uint8Array(ciphertext));
|
|
183
|
+
let ivb64 = base64Encode(new Uint8Array(iv.buffer));
|
|
177
184
|
return `${ctb64}?iv=${ivb64}`;
|
|
178
185
|
}
|
|
179
186
|
async nip04Decrypt(pubkey, data) {
|
|
@@ -182,8 +189,8 @@ export class SerialPortSigner {
|
|
|
182
189
|
const sharedSecret = hexToBytes(sharedSecretStr);
|
|
183
190
|
// @ts-ignore
|
|
184
191
|
let cryptoKey = await crypto.subtle.importKey("raw", sharedSecret, { name: "AES-CBC" }, false, ["decrypt"]);
|
|
185
|
-
let ciphertext =
|
|
186
|
-
let iv =
|
|
192
|
+
let ciphertext = base64Decode(ctb64);
|
|
193
|
+
let iv = base64Decode(ivb64);
|
|
187
194
|
// @ts-ignore
|
|
188
195
|
let plaintext = await crypto.subtle.decrypt({ name: "AES-CBC", iv }, cryptoKey, ciphertext);
|
|
189
196
|
let text = utf8Decoder.decode(plaintext);
|
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-20251203172109",
|
|
4
4
|
"description": "Signer classes for applesauce",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -44,13 +44,10 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@noble/hashes": "^1.7.1",
|
|
48
47
|
"@noble/secp256k1": "^1.7.1",
|
|
49
|
-
"
|
|
50
|
-
"applesauce-core": "0.0.0-next-20251030142514",
|
|
48
|
+
"applesauce-core": "0.0.0-next-20251203172109",
|
|
51
49
|
"debug": "^4.4.0",
|
|
52
50
|
"nanoid": "^5.0.9",
|
|
53
|
-
"nostr-tools": "~2.17",
|
|
54
51
|
"rxjs": "^7.8.2"
|
|
55
52
|
},
|
|
56
53
|
"devDependencies": {
|
|
@@ -58,7 +55,7 @@
|
|
|
58
55
|
"@types/dom-serial": "^1.0.6",
|
|
59
56
|
"rimraf": "^6.0.1",
|
|
60
57
|
"typescript": "^5.8.3",
|
|
61
|
-
"vitest": "^
|
|
58
|
+
"vitest": "^4.0.15",
|
|
62
59
|
"vitest-websocket-mock": "^0.5.0"
|
|
63
60
|
},
|
|
64
61
|
"funding": {
|