nostr-double-ratchet 0.0.12 → 0.0.13

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/src/Invite.ts CHANGED
@@ -18,10 +18,10 @@ import { hexToBytes, bytesToHex } from "@noble/hashes/utils";
18
18
  */
19
19
  export class Invite {
20
20
  constructor(
21
- public inviterSessionPublicKey: string,
21
+ public inviterEphemeralPublicKey: string,
22
22
  public linkSecret: string,
23
23
  public inviter: string,
24
- public inviterSessionPrivateKey?: Uint8Array,
24
+ public inviterEphemeralPrivateKey?: Uint8Array,
25
25
  public label?: string,
26
26
  public maxUses?: number,
27
27
  public usedBy: string[] = [],
@@ -31,14 +31,14 @@ export class Invite {
31
31
  if (!inviter) {
32
32
  throw new Error("Inviter public key is required");
33
33
  }
34
- const inviterSessionPrivateKey = generateSecretKey();
35
- const inviterSessionPublicKey = getPublicKey(inviterSessionPrivateKey);
34
+ const inviterEphemeralPrivateKey = generateSecretKey();
35
+ const inviterEphemeralPublicKey = getPublicKey(inviterEphemeralPrivateKey);
36
36
  const linkSecret = bytesToHex(generateSecretKey());
37
37
  return new Invite(
38
- inviterSessionPublicKey,
38
+ inviterEphemeralPublicKey,
39
39
  linkSecret,
40
40
  inviter,
41
- inviterSessionPrivateKey,
41
+ inviterEphemeralPrivateKey,
42
42
  label,
43
43
  maxUses
44
44
  );
@@ -59,13 +59,13 @@ export class Invite {
59
59
  throw new Error("Invite data in URL hash is not valid JSON: " + err);
60
60
  }
61
61
 
62
- const { inviter, sessionKey, linkSecret } = data;
63
- if (!inviter || !sessionKey || !linkSecret) {
64
- throw new Error("Missing required fields (inviter, sessionKey, linkSecret) in invite data.");
62
+ const { inviter, ephemeralKey, linkSecret } = data;
63
+ if (!inviter || !ephemeralKey || !linkSecret) {
64
+ throw new Error("Missing required fields (inviter, ephemeralKey, linkSecret) in invite data.");
65
65
  }
66
66
 
67
67
  return new Invite(
68
- sessionKey,
68
+ ephemeralKey,
69
69
  linkSecret,
70
70
  inviter
71
71
  );
@@ -74,10 +74,10 @@ export class Invite {
74
74
  static deserialize(json: string): Invite {
75
75
  const data = JSON.parse(json);
76
76
  return new Invite(
77
- data.inviterSessionPublicKey,
77
+ data.inviterEphemeralPublicKey,
78
78
  data.linkSecret,
79
79
  data.inviter,
80
- data.inviterSessionPrivateKey ? new Uint8Array(data.inviterSessionPrivateKey) : undefined,
80
+ data.inviterEphemeralPrivateKey ? new Uint8Array(data.inviterEphemeralPrivateKey) : undefined,
81
81
  data.label,
82
82
  data.maxUses,
83
83
  data.usedBy
@@ -92,16 +92,16 @@ export class Invite {
92
92
  throw new Error("Event signature is invalid");
93
93
  }
94
94
  const { tags } = event;
95
- const inviterSessionPublicKey = tags.find(([key]) => key === 'sessionKey')?.[1];
95
+ const inviterEphemeralPublicKey = tags.find(([key]) => key === 'ephemeralKey')?.[1];
96
96
  const linkSecret = tags.find(([key]) => key === 'linkSecret')?.[1];
97
97
  const inviter = event.pubkey;
98
98
 
99
- if (!inviterSessionPublicKey || !linkSecret) {
99
+ if (!inviterEphemeralPublicKey || !linkSecret) {
100
100
  throw new Error("Invalid invite event: missing session key or link secret");
101
101
  }
102
102
 
103
103
  return new Invite(
104
- inviterSessionPublicKey,
104
+ inviterEphemeralPublicKey,
105
105
  linkSecret,
106
106
  inviter
107
107
  );
@@ -136,10 +136,10 @@ export class Invite {
136
136
  */
137
137
  serialize(): string {
138
138
  return JSON.stringify({
139
- inviterSessionPublicKey: this.inviterSessionPublicKey,
139
+ inviterEphemeralPublicKey: this.inviterEphemeralPublicKey,
140
140
  linkSecret: this.linkSecret,
141
141
  inviter: this.inviter,
142
- inviterSessionPrivateKey: this.inviterSessionPrivateKey ? Array.from(this.inviterSessionPrivateKey) : undefined,
142
+ inviterEphemeralPrivateKey: this.inviterEphemeralPrivateKey ? Array.from(this.inviterEphemeralPrivateKey) : undefined,
143
143
  label: this.label,
144
144
  maxUses: this.maxUses,
145
145
  usedBy: this.usedBy,
@@ -152,7 +152,7 @@ export class Invite {
152
152
  getUrl(root = "https://iris.to") {
153
153
  const data = {
154
154
  inviter: this.inviter,
155
- sessionKey: this.inviterSessionPublicKey,
155
+ ephemeralKey: this.inviterEphemeralPublicKey,
156
156
  linkSecret: this.linkSecret
157
157
  };
158
158
  const url = new URL(root);
@@ -167,7 +167,7 @@ export class Invite {
167
167
  pubkey: this.inviter,
168
168
  content: "",
169
169
  created_at: Math.floor(Date.now() / 1000),
170
- tags: [['sessionKey', this.inviterSessionPublicKey], ['linkSecret', this.linkSecret], ['d', 'nostr-double-ratchet/invite']],
170
+ tags: [['ephemeralKey', this.inviterEphemeralPublicKey], ['linkSecret', this.linkSecret], ['d', 'nostr-double-ratchet/invite']],
171
171
  };
172
172
  }
173
173
 
@@ -193,10 +193,10 @@ export class Invite {
193
193
  ): Promise<{ session: Session, event: VerifiedEvent }> {
194
194
  const inviteeSessionKey = generateSecretKey();
195
195
  const inviteeSessionPublicKey = getPublicKey(inviteeSessionKey);
196
- const inviterPublicKey = this.inviter || this.inviterSessionPublicKey;
196
+ const inviterPublicKey = this.inviter || this.inviterEphemeralPublicKey;
197
197
 
198
198
  const sharedSecret = hexToBytes(this.linkSecret);
199
- const session = Session.init(nostrSubscribe, this.inviterSessionPublicKey, inviteeSessionKey, true, sharedSecret, undefined);
199
+ const session = Session.init(nostrSubscribe, this.inviterEphemeralPublicKey, inviteeSessionKey, true, sharedSecret, undefined);
200
200
 
201
201
  // Create a random keypair for the envelope sender
202
202
  const randomSenderKey = generateSecretKey();
@@ -216,22 +216,22 @@ export class Invite {
216
216
  const envelope = {
217
217
  kind: MESSAGE_EVENT_KIND,
218
218
  pubkey: randomSenderPublicKey,
219
- content: nip44.encrypt(JSON.stringify(innerEvent), getConversationKey(randomSenderKey, this.inviterSessionPublicKey)),
219
+ content: nip44.encrypt(JSON.stringify(innerEvent), getConversationKey(randomSenderKey, this.inviterEphemeralPublicKey)),
220
220
  created_at: Math.floor(Date.now() / 1000),
221
- tags: [['p', this.inviterSessionPublicKey]],
221
+ tags: [['p', this.inviterEphemeralPublicKey]],
222
222
  };
223
223
 
224
224
  return { session, event: finalizeEvent(envelope, randomSenderKey) };
225
225
  }
226
226
 
227
227
  listen(inviterSecretKey: Uint8Array | DecryptFunction, nostrSubscribe: NostrSubscribe, onSession: (session: Session, identity?: string) => void): Unsubscribe {
228
- if (!this.inviterSessionPrivateKey) {
228
+ if (!this.inviterEphemeralPrivateKey) {
229
229
  throw new Error("Inviter session key is not available");
230
230
  }
231
231
 
232
232
  const filter = {
233
233
  kinds: [MESSAGE_EVENT_KIND],
234
- '#p': [this.inviterSessionPublicKey],
234
+ '#p': [this.inviterEphemeralPublicKey],
235
235
  };
236
236
 
237
237
  return nostrSubscribe(filter, async (event) => {
@@ -241,7 +241,7 @@ export class Invite {
241
241
  return;
242
242
  }
243
243
 
244
- const decrypted = await nip44.decrypt(event.content, getConversationKey(this.inviterSessionPrivateKey!, event.pubkey));
244
+ const decrypted = await nip44.decrypt(event.content, getConversationKey(this.inviterEphemeralPrivateKey!, event.pubkey));
245
245
  const innerEvent = JSON.parse(decrypted);
246
246
 
247
247
  if (!innerEvent.tags || !innerEvent.tags.some(([key, value]: [string, string]) => key === 'secret' && value === this.linkSecret)) {
@@ -260,7 +260,7 @@ export class Invite {
260
260
  const sharedSecret = hexToBytes(this.linkSecret);
261
261
 
262
262
  const name = event.id;
263
- const session = Session.init(nostrSubscribe, inviteeSessionPublicKey, this.inviterSessionPrivateKey!, false, sharedSecret, name);
263
+ const session = Session.init(nostrSubscribe, inviteeSessionPublicKey, this.inviterEphemeralPrivateKey!, false, sharedSecret, name);
264
264
 
265
265
  onSession(session, inviteeIdentity);
266
266
  } catch (error) {
File without changes