nostr-double-ratchet 0.0.1 → 0.0.3

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/README.md CHANGED
@@ -1,4 +1,7 @@
1
- * WIP: Double ratchet on nostr
2
- * currently only single DH ratchet (but it already provides forward & backward secrecy)
3
- * invite links for securely exchanging session keys. don't use your long-term key for initiating a session.
4
- * check out [tests](./tests/) for usage
1
+ * Double ratchet on nostr
2
+ - [x] 1-on-1 channel
3
+ - [ ] group channel
4
+ * Invite links for securely exchanging session keys. don't use your long-term key for initiating a session.
5
+ * Breaking changes are likely
6
+ * Stable version on [NPM](https://www.npmjs.com/package/nostr-double-ratchet)
7
+ * check out [tests](./tests/) for usage
package/dist/Channel.d.ts CHANGED
@@ -1,24 +1,32 @@
1
1
  import { VerifiedEvent } from "nostr-tools";
2
- import { ChannelState, Unsubscribe, NostrSubscribe, MessageCallback, KeyPair, Sender, KeyType } from "./types";
2
+ import { ChannelState, Unsubscribe, NostrSubscribe, MessageCallback } from "./types";
3
+ /**
4
+ * Similar to Signal's "Double Ratchet with header encryption"
5
+ * https://signal.org/docs/specifications/doubleratchet/
6
+ */
3
7
  export declare class Channel {
4
8
  private nostrSubscribe;
5
9
  state: ChannelState;
6
- nostrUnsubscribe: Unsubscribe | undefined;
7
- nostrNextUnsubscribe: Unsubscribe | undefined;
8
- currentInternalSubscriptionId: number;
9
- internalSubscriptions: Map<number, MessageCallback>;
10
+ private nostrUnsubscribe?;
11
+ private nostrNextUnsubscribe?;
12
+ private internalSubscriptions;
13
+ private currentInternalSubscriptionId;
10
14
  name: string;
11
15
  constructor(nostrSubscribe: NostrSubscribe, state: ChannelState);
12
16
  /**
13
- * To preserve forward secrecy, do not use long-term keys for channel initialization. Use e.g. InviteLink to exchange session keys.
17
+ * @param sharedSecret optional, but useful to keep the first chain of messages secure. Unlike the Nostr keys, it can be forgotten after the 1st message in the chain.
18
+ * @param isInitiator determines which chain key is used for sending vs receiving
14
19
  */
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;
20
+ static init(nostrSubscribe: NostrSubscribe, theirNostrPublicKey: string, ourCurrentPrivateKey: Uint8Array, sharedSecret?: Uint8Array, name?: string, isInitiator?: boolean): Channel;
22
21
  send(data: string): VerifiedEvent;
22
+ onMessage(callback: MessageCallback): Unsubscribe;
23
+ private ratchetEncrypt;
24
+ private ratchetDecrypt;
25
+ private ratchetStep;
26
+ private skipMessageKeys;
27
+ private trySkippedMessageKeys;
28
+ private decryptHeader;
29
+ private handleNostrEvent;
30
+ private subscribeToNostrEvents;
23
31
  }
24
32
  //# sourceMappingURL=Channel.d.ts.map
@@ -1 +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,0BA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