nostr-double-ratchet 0.0.1

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.
@@ -0,0 +1,24 @@
1
+ import { VerifiedEvent } from "nostr-tools";
2
+ import { ChannelState, Unsubscribe, NostrSubscribe, MessageCallback, KeyPair, Sender, KeyType } from "./types";
3
+ export declare class Channel {
4
+ private nostrSubscribe;
5
+ state: ChannelState;
6
+ nostrUnsubscribe: Unsubscribe | undefined;
7
+ nostrNextUnsubscribe: Unsubscribe | undefined;
8
+ currentInternalSubscriptionId: number;
9
+ internalSubscriptions: Map<number, MessageCallback>;
10
+ name: string;
11
+ constructor(nostrSubscribe: NostrSubscribe, state: ChannelState);
12
+ /**
13
+ * To preserve forward secrecy, do not use long-term keys for channel initialization. Use e.g. InviteLink to exchange session keys.
14
+ */
15
+ static init(nostrSubscribe: NostrSubscribe, theirCurrentNostrPublicKey: string, ourCurrentPrivateKey: Uint8Array, name?: string): Channel;
16
+ updateTheirCurrentNostrPublicKey(theirNewPublicKey: string): void;
17
+ private rotateOurCurrentNostrKey;
18
+ getNostrSenderKeypair(sender: Sender, keyType: KeyType): KeyPair;
19
+ private nostrSubscribeNext;
20
+ private subscribeToNostrEvents;
21
+ onMessage(callback: MessageCallback): Unsubscribe;
22
+ send(data: string): VerifiedEvent;
23
+ }
24
+ //# sourceMappingURL=Channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Channel.d.ts","sourceRoot":"","sources":["../src/Channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyD,aAAa,EAAE,MAAM,aAAa,CAAC;AAEnG,OAAO,EACL,YAAY,EAEZ,WAAW,EACX,cAAc,EACd,eAAe,EAEf,OAAO,EACP,MAAM,EACN,OAAO,EACR,MAAM,SAAS,CAAC;AAGjB,qBAAa,OAAO;IAON,OAAO,CAAC,cAAc;IAAyB,KAAK,EAAE,YAAY;IAN9E,gBAAgB,EAAE,WAAW,GAAG,SAAS,CAAA;IACzC,oBAAoB,EAAE,WAAW,GAAG,SAAS,CAAA;IAC7C,6BAA6B,SAAI;IACjC,qBAAqB,+BAAqC;IAC1D,IAAI,SAA6C;gBAE7B,cAAc,EAAE,cAAc,EAAS,KAAK,EAAE,YAAY;IAI9E;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,cAAc,EAAE,0BAA0B,EAAE,MAAM,EAAE,oBAAoB,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO;IAoBzI,gCAAgC,CAAC,iBAAiB,EAAE,MAAM;IAU1D,OAAO,CAAC,wBAAwB;IAShC,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO;IAchE,OAAO,CAAC,kBAAkB;IAiB1B,OAAO,CAAC,sBAAsB;IAiB9B,SAAS,CAAC,QAAQ,EAAE,eAAe,GAAG,WAAW;IAOjD,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa;CAmBlC"}
@@ -0,0 +1,51 @@
1
+ import { VerifiedEvent } from "nostr-tools";
2
+ import { NostrSubscribe, Unsubscribe } from "./types";
3
+ import { Channel } from "./Channel";
4
+ import { EncryptFunction, DecryptFunction } from "./types";
5
+ /**
6
+ * Invite link is a safe way to exchange session keys and initiate secret channels.
7
+ *
8
+ * Even if inviter's or invitee's long-term private key (identity key) and the shared secret (link) is compromised,
9
+ * forward secrecy is preserved as long as the session keys are not compromised.
10
+ *
11
+ * Shared secret Nostr channel: inviter listens to it and invitees can write to it. Outside observers don't know who are communicating over it.
12
+ * It is vulnerable to spam, so the link should only be given to trusted invitees or used with a reasonable maxUses limit.
13
+ *
14
+ * Also make sure to keep the session key safe.
15
+ */
16
+ export declare class InviteLink {
17
+ inviterSessionPublicKey: string;
18
+ linkSecret: string;
19
+ inviter: string;
20
+ inviterSessionPrivateKey?: Uint8Array | undefined;
21
+ label?: string | undefined;
22
+ maxUses?: number | undefined;
23
+ usedBy: string[];
24
+ constructor(inviterSessionPublicKey: string, linkSecret: string, inviter: string, inviterSessionPrivateKey?: Uint8Array | undefined, label?: string | undefined, maxUses?: number | undefined, usedBy?: string[]);
25
+ static createNew(inviter: string, label?: string, maxUses?: number): InviteLink;
26
+ static fromUrl(url: string): InviteLink;
27
+ static deserialize(json: string): InviteLink;
28
+ serialize(): string;
29
+ getUrl(root?: string): string;
30
+ /**
31
+ * Accepts the invite and creates a new channel with the inviter.
32
+ *
33
+ * @param inviteeSecretKey - The invitee's secret key or a signing function
34
+ * @param nostrSubscribe - A function to subscribe to Nostr events
35
+ * @returns An object containing the new channel and an event to be published
36
+ *
37
+ * 1. Inner event: No signature, content encrypted with DH(inviter, invitee).
38
+ * Purpose: Authenticate invitee. Contains invitee session key.
39
+ * 2. Envelope: No signature, content encrypted with DH(inviter, random key).
40
+ * Purpose: Contains inner event. Hides invitee from others who might have the shared Nostr key.
41
+
42
+ * Note: You need to publish the returned event on Nostr using NDK or another Nostr system of your choice,
43
+ * so the inviter can create the channel on their side.
44
+ */
45
+ acceptInvite(nostrSubscribe: NostrSubscribe, inviteePublicKey: string, inviteeSecretKey: Uint8Array | EncryptFunction): Promise<{
46
+ channel: Channel;
47
+ event: VerifiedEvent;
48
+ }>;
49
+ listen(inviterSecretKey: Uint8Array | DecryptFunction, nostrSubscribe: NostrSubscribe, onChannel: (channel: Channel, identity?: string) => void): Unsubscribe;
50
+ }
51
+ //# sourceMappingURL=InviteLink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InviteLink.d.ts","sourceRoot":"","sources":["../src/InviteLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyD,aAAa,EAAS,MAAM,aAAa,CAAC;AAE1G,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE3D;;;;;;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5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}