aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorAdrien Hopkins <[email protected]>2025-10-02 10:01:12 -0500
committerAdrien Hopkins <[email protected]>2025-10-02 10:01:12 -0500
commit8f161a474d7dba438289d5dbe93684325560f85f (patch)
tree52b35c09831cddbb321fd095d5e4bb4ac87ca796 /src/lib
parentc6b94b9ac035bf7cc27aa441d1675cb15a1f2fd3 (diff)
downloadcoinos-ui-8f161a474d7dba438289d5dbe93684325560f85f.tar.gz
coinos-ui-8f161a474d7dba438289d5dbe93684325560f85f.zip
Send copy of messages to sender
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/nip17.ts18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/lib/nip17.ts b/src/lib/nip17.ts
index 495f897e..6cb8f9e3 100644
--- a/src/lib/nip17.ts
+++ b/src/lib/nip17.ts
@@ -7,17 +7,23 @@ const randomTimestamp = () => Math.floor(
Date.now() / 1000 - Math.random() * TWO_DAYS);
// Create a NIP-17 message using a provided sender secret key.
-export const createNIP17MessageSK = (text: string, senderSK: Uint8Array, receiverPK: string) => {
+// If wrapPK is specified and different than receiverPK,
+// the message will be gift-wrapped to wrapPK
+// but the rumour will be sent to receiverPK.
+export const createNIP17MessageSK = (text: string, senderSK: Uint8Array, receiverPK: string, wrapPK: string = null) => {
const rumour = createRumour(text, getPublicKey(senderSK), receiverPK);
- const sealed = sealRumourSK(rumour, senderSK, receiverPK);
- return giftWrap(sealed, receiverPK);
+ const sealed = sealRumourSK(rumour, senderSK, wrapPK || receiverPK);
+ return giftWrap(sealed, wrapPK || receiverPK);
}
// Create a NIP-17 message using NIP-07, requiring no sender secret key.
-export const createNIP17MessageNIP07 = async (text: string, senderPK: string, receiverPK: string) => {
+// If wrapPK is specified and different than receiverPK,
+// the message will be gift-wrapped to wrapPK
+// but the rumour will be sent to receiverPK.
+export const createNIP17MessageNIP07 = async (text: string, senderPK: string, receiverPK: string, wrapPK: string = null) => {
const rumour = createRumour(text, senderPK, receiverPK);
- const sealed = await sealRumourNip07(rumour, receiverPK);
- return giftWrap(sealed, receiverPK);
+ const sealed = await sealRumourNip07(rumour, wrapPK || receiverPK);
+ return giftWrap(sealed, wrapPK || receiverPK);
}
const createRumour = (text: string, senderPK: string, receiverPK: string) => {