applesauce-core 0.0.0-next-20250806165639 → 0.0.0-next-20250808173123
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/encrypted-content.d.ts +16 -10
- package/dist/helpers/encrypted-content.js +9 -3
- package/dist/helpers/hidden-content.d.ts +3 -3
- package/dist/helpers/hidden-content.js +2 -2
- package/dist/helpers/hidden-tags.d.ts +5 -10
- package/dist/helpers/hidden-tags.js +3 -3
- package/package.json +1 -1
|
@@ -10,18 +10,24 @@ export interface EncryptedContentSigner {
|
|
|
10
10
|
decrypt: (pubkey: string, ciphertext: string) => Promise<string> | string;
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export declare function setEncryptedContentEncryptionMethod(kind: number, method: "nip04" | "nip44"): number;
|
|
17
|
-
/** Returns either nip04 or nip44 encryption methods depending on event kind */
|
|
18
|
-
export declare function getEncryptedContentEncryptionMethods(kind: number, signer: EncryptedContentSigner): {
|
|
13
|
+
export type EncryptionMethod = "nip04" | "nip44";
|
|
14
|
+
/** A pair of encryption methods for encrypting and decrypting event content */
|
|
15
|
+
export interface EncryptionMethods {
|
|
19
16
|
encrypt: (pubkey: string, plaintext: string) => Promise<string> | string;
|
|
20
17
|
decrypt: (pubkey: string, ciphertext: string) => Promise<string> | string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
}
|
|
19
|
+
/** Various event kinds that can have encrypted content and which encryption method they use */
|
|
20
|
+
export declare const EventContentEncryptionMethod: Record<number, EncryptionMethod>;
|
|
21
|
+
/** Sets the encryption method that is used for the contents of a specific event kind */
|
|
22
|
+
export declare function setEncryptedContentEncryptionMethod(kind: number, method: EncryptionMethod): number;
|
|
23
|
+
/**
|
|
24
|
+
* Returns either nip04 or nip44 encryption methods depending on event kind
|
|
25
|
+
* @param kind The event kind to get the encryption method for
|
|
26
|
+
* @param signer The signer to use to get the encryption methods
|
|
27
|
+
* @param override The encryption method to use instead of the default
|
|
28
|
+
* @returns The encryption methods for the event kind
|
|
29
|
+
*/
|
|
30
|
+
export declare function getEncryptedContentEncryptionMethods(kind: number, signer: EncryptedContentSigner, override?: EncryptionMethod): EncryptionMethods;
|
|
25
31
|
/** Checks if an event can have encrypted content */
|
|
26
32
|
export declare function canHaveEncryptedContent(kind: number): boolean;
|
|
27
33
|
/** Checks if an event has encrypted content */
|
|
@@ -13,9 +13,15 @@ export function setEncryptedContentEncryptionMethod(kind, method) {
|
|
|
13
13
|
EventContentEncryptionMethod[kind] = method;
|
|
14
14
|
return kind;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Returns either nip04 or nip44 encryption methods depending on event kind
|
|
18
|
+
* @param kind The event kind to get the encryption method for
|
|
19
|
+
* @param signer The signer to use to get the encryption methods
|
|
20
|
+
* @param override The encryption method to use instead of the default
|
|
21
|
+
* @returns The encryption methods for the event kind
|
|
22
|
+
*/
|
|
23
|
+
export function getEncryptedContentEncryptionMethods(kind, signer, override) {
|
|
24
|
+
const method = override ?? EventContentEncryptionMethod[kind];
|
|
19
25
|
if (!method)
|
|
20
26
|
throw new Error(`Event kind ${kind} does not support encrypted content`);
|
|
21
27
|
const encryption = signer[method];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EncryptedContentSigner, getEncryptedContentEncryptionMethods } from "./encrypted-content.js";
|
|
1
|
+
import { EncryptedContentSigner, EncryptionMethod, getEncryptedContentEncryptionMethods } from "./encrypted-content.js";
|
|
2
2
|
export declare const HiddenContentSymbol: symbol;
|
|
3
3
|
export interface HiddenContentSigner extends EncryptedContentSigner {
|
|
4
4
|
}
|
|
@@ -6,7 +6,7 @@ export declare const getHiddenContentEncryptionMethods: typeof getEncryptedConte
|
|
|
6
6
|
/** Various event kinds that can have hidden content */
|
|
7
7
|
export declare const HiddenContentKinds: Set<number>;
|
|
8
8
|
/** Sets the encryption method for hidden content on a kind */
|
|
9
|
-
export declare function setHiddenContentEncryptionMethod(kind: number, method:
|
|
9
|
+
export declare function setHiddenContentEncryptionMethod(kind: number, method: EncryptionMethod): number;
|
|
10
10
|
/** Checks if an event can have hidden content */
|
|
11
11
|
export declare function canHaveHiddenContent(kind: number): boolean;
|
|
12
12
|
/** Checks if an event has hidden content */
|
|
@@ -31,7 +31,7 @@ export declare function unlockHiddenContent<T extends {
|
|
|
31
31
|
kind: number;
|
|
32
32
|
pubkey: string;
|
|
33
33
|
content: string;
|
|
34
|
-
}>(event: T, signer: EncryptedContentSigner): Promise<string>;
|
|
34
|
+
}>(event: T, signer: EncryptedContentSigner, override?: EncryptionMethod): Promise<string>;
|
|
35
35
|
/**
|
|
36
36
|
* Sets the hidden content on an event and updates it if its part of an event store
|
|
37
37
|
* @throws
|
|
@@ -34,10 +34,10 @@ export function getHiddenContent(event) {
|
|
|
34
34
|
* @param signer A signer to use to decrypt the content
|
|
35
35
|
* @throws
|
|
36
36
|
*/
|
|
37
|
-
export async function unlockHiddenContent(event, signer) {
|
|
37
|
+
export async function unlockHiddenContent(event, signer, override) {
|
|
38
38
|
if (!canHaveHiddenContent(event.kind))
|
|
39
39
|
throw new Error("Event kind does not support hidden content");
|
|
40
|
-
const encryption = getEncryptedContentEncryptionMethods(event.kind, signer);
|
|
40
|
+
const encryption = getEncryptedContentEncryptionMethods(event.kind, signer, override);
|
|
41
41
|
const plaintext = await encryption.decrypt(event.pubkey, event.content);
|
|
42
42
|
setHiddenContentCache(event, plaintext);
|
|
43
43
|
return plaintext;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { HiddenContentSigner } from "./hidden-content.js";
|
|
2
|
+
import { EncryptionMethod } from "./encrypted-content.js";
|
|
2
3
|
export declare const HiddenTagsSymbol: unique symbol;
|
|
3
4
|
/** Various event kinds that can have hidden tags */
|
|
4
5
|
export declare const HiddenTagsKinds: Set<number>;
|
|
5
6
|
/** Checks if an event can have hidden tags */
|
|
6
7
|
export declare function canHaveHiddenTags(kind: number): boolean;
|
|
7
8
|
/** Sets the type of encryption to use for hidden tags on a kind */
|
|
8
|
-
export declare function setHiddenTagsEncryptionMethod(kind: number, method:
|
|
9
|
+
export declare function setHiddenTagsEncryptionMethod(kind: number, method: EncryptionMethod): number;
|
|
9
10
|
/** Checks if an event has hidden tags */
|
|
10
11
|
export declare function hasHiddenTags<T extends {
|
|
11
12
|
kind: number;
|
|
@@ -19,25 +20,19 @@ export declare function getHiddenTags<T extends {
|
|
|
19
20
|
/** Checks if the hidden tags are locked */
|
|
20
21
|
export declare function isHiddenTagsLocked<T extends object>(event: T): boolean;
|
|
21
22
|
/** Returns either nip04 or nip44 encryption method depending on list kind */
|
|
22
|
-
export declare function getHiddenTagsEncryptionMethods(kind: number, signer: HiddenContentSigner):
|
|
23
|
-
encrypt: (pubkey: string, plaintext: string) => Promise<string> | string;
|
|
24
|
-
decrypt: (pubkey: string, ciphertext: string) => Promise<string> | string;
|
|
25
|
-
} | {
|
|
26
|
-
encrypt: (pubkey: string, plaintext: string) => Promise<string> | string;
|
|
27
|
-
decrypt: (pubkey: string, ciphertext: string) => Promise<string> | string;
|
|
28
|
-
};
|
|
23
|
+
export declare function getHiddenTagsEncryptionMethods(kind: number, signer: HiddenContentSigner): import("./encrypted-content.js").EncryptionMethods;
|
|
29
24
|
/**
|
|
30
25
|
* Decrypts the private list
|
|
31
26
|
* @param event The list event to decrypt
|
|
32
27
|
* @param signer A signer to use to decrypt the tags
|
|
33
|
-
* @param
|
|
28
|
+
* @param override The encryption method to use instead of the default
|
|
34
29
|
* @throws
|
|
35
30
|
*/
|
|
36
31
|
export declare function unlockHiddenTags<T extends {
|
|
37
32
|
kind: number;
|
|
38
33
|
pubkey: string;
|
|
39
34
|
content: string;
|
|
40
|
-
}>(event: T, signer: HiddenContentSigner): Promise<string[][]>;
|
|
35
|
+
}>(event: T, signer: HiddenContentSigner, override?: EncryptionMethod): Promise<string[][]>;
|
|
41
36
|
/**
|
|
42
37
|
* Sets the hidden tags on an event and updates it if its part of an event store
|
|
43
38
|
* @throws
|
|
@@ -58,15 +58,15 @@ export function getHiddenTagsEncryptionMethods(kind, signer) {
|
|
|
58
58
|
* Decrypts the private list
|
|
59
59
|
* @param event The list event to decrypt
|
|
60
60
|
* @param signer A signer to use to decrypt the tags
|
|
61
|
-
* @param
|
|
61
|
+
* @param override The encryption method to use instead of the default
|
|
62
62
|
* @throws
|
|
63
63
|
*/
|
|
64
|
-
export async function unlockHiddenTags(event, signer) {
|
|
64
|
+
export async function unlockHiddenTags(event, signer, override) {
|
|
65
65
|
if (!canHaveHiddenTags(event.kind))
|
|
66
66
|
throw new Error("Event kind does not support hidden tags");
|
|
67
67
|
// unlock hidden content is needed
|
|
68
68
|
if (isHiddenContentLocked(event))
|
|
69
|
-
await unlockHiddenContent(event, signer);
|
|
69
|
+
await unlockHiddenContent(event, signer, override);
|
|
70
70
|
return getHiddenTags(event);
|
|
71
71
|
}
|
|
72
72
|
/**
|