nostr-crypto-utils 0.4.12 → 0.4.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.
Files changed (114) hide show
  1. package/README.md +52 -2
  2. package/dist/browser/343.nostr-crypto-utils.min.js +1 -0
  3. package/dist/browser/419.nostr-crypto-utils.min.js +1 -0
  4. package/dist/browser/crypto.nostr-crypto-utils.min.js +1 -1
  5. package/dist/browser/main.nostr-crypto-utils.min.js +1 -0
  6. package/dist/browser/protocol.nostr-crypto-utils.min.js +1 -1
  7. package/dist/cjs/event/index.d.ts +7 -0
  8. package/dist/cjs/event/index.d.ts.map +1 -0
  9. package/dist/cjs/event/index.js +15 -0
  10. package/dist/cjs/event/index.js.map +1 -0
  11. package/dist/cjs/event/signing.d.ts +12 -0
  12. package/dist/cjs/event/signing.d.ts.map +1 -1
  13. package/dist/cjs/event/signing.js +29 -0
  14. package/dist/cjs/event/signing.js.map +1 -1
  15. package/dist/cjs/index.d.ts +11 -8
  16. package/dist/cjs/index.d.ts.map +1 -1
  17. package/dist/cjs/index.js +58 -56
  18. package/dist/cjs/index.js.map +1 -1
  19. package/dist/cjs/nips/nip-04.d.ts +1 -1
  20. package/dist/cjs/nips/nip-04.d.ts.map +1 -1
  21. package/dist/cjs/nips/nip-04.js +1 -0
  22. package/dist/cjs/nips/nip-04.js.map +1 -1
  23. package/dist/cjs/protocol/index.d.ts +9 -9
  24. package/dist/cjs/protocol/index.d.ts.map +1 -1
  25. package/dist/cjs/protocol/index.js +8 -9
  26. package/dist/cjs/protocol/index.js.map +1 -1
  27. package/dist/cjs/types/base.d.ts +45 -121
  28. package/dist/cjs/types/base.d.ts.map +1 -1
  29. package/dist/cjs/types/base.js +10 -28
  30. package/dist/cjs/types/base.js.map +1 -1
  31. package/dist/cjs/utils/encoding.d.ts +12 -0
  32. package/dist/cjs/utils/encoding.d.ts.map +1 -1
  33. package/dist/cjs/utils/encoding.js +18 -0
  34. package/dist/cjs/utils/encoding.js.map +1 -1
  35. package/dist/cjs/utils/integration.d.ts +14 -15
  36. package/dist/cjs/utils/integration.d.ts.map +1 -1
  37. package/dist/cjs/utils/integration.js +145 -98
  38. package/dist/cjs/utils/integration.js.map +1 -1
  39. package/dist/cjs/utils/logger.d.ts +17 -2
  40. package/dist/cjs/utils/logger.d.ts.map +1 -1
  41. package/dist/cjs/utils/logger.js +40 -3
  42. package/dist/cjs/utils/logger.js.map +1 -1
  43. package/dist/cjs/utils/validation.d.ts +6 -0
  44. package/dist/cjs/utils/validation.d.ts.map +1 -1
  45. package/dist/cjs/utils/validation.js +37 -0
  46. package/dist/cjs/utils/validation.js.map +1 -1
  47. package/dist/cjs/validation/keys.d.ts +7 -0
  48. package/dist/cjs/validation/keys.d.ts.map +1 -0
  49. package/dist/cjs/validation/keys.js +23 -0
  50. package/dist/cjs/validation/keys.js.map +1 -0
  51. package/dist/esm/event/index.d.ts +7 -0
  52. package/dist/esm/event/index.d.ts.map +1 -0
  53. package/dist/esm/event/index.js +7 -0
  54. package/dist/esm/event/index.js.map +1 -0
  55. package/dist/esm/event/signing.d.ts +12 -0
  56. package/dist/esm/event/signing.d.ts.map +1 -1
  57. package/dist/esm/event/signing.js +27 -0
  58. package/dist/esm/event/signing.js.map +1 -1
  59. package/dist/esm/index.d.ts +11 -8
  60. package/dist/esm/index.d.ts.map +1 -1
  61. package/dist/esm/index.js +16 -14
  62. package/dist/esm/index.js.map +1 -1
  63. package/dist/esm/nips/nip-04.d.ts +1 -1
  64. package/dist/esm/nips/nip-04.d.ts.map +1 -1
  65. package/dist/esm/nips/nip-04.js +1 -0
  66. package/dist/esm/nips/nip-04.js.map +1 -1
  67. package/dist/esm/protocol/index.d.ts +9 -9
  68. package/dist/esm/protocol/index.d.ts.map +1 -1
  69. package/dist/esm/protocol/index.js +8 -9
  70. package/dist/esm/protocol/index.js.map +1 -1
  71. package/dist/esm/types/base.d.ts +45 -121
  72. package/dist/esm/types/base.d.ts.map +1 -1
  73. package/dist/esm/types/base.js +10 -28
  74. package/dist/esm/types/base.js.map +1 -1
  75. package/dist/esm/utils/encoding.d.ts +12 -0
  76. package/dist/esm/utils/encoding.d.ts.map +1 -1
  77. package/dist/esm/utils/encoding.js +16 -0
  78. package/dist/esm/utils/encoding.js.map +1 -1
  79. package/dist/esm/utils/integration.d.ts +14 -15
  80. package/dist/esm/utils/integration.d.ts.map +1 -1
  81. package/dist/esm/utils/integration.js +136 -89
  82. package/dist/esm/utils/integration.js.map +1 -1
  83. package/dist/esm/utils/logger.d.ts +17 -2
  84. package/dist/esm/utils/logger.d.ts.map +1 -1
  85. package/dist/esm/utils/logger.js +38 -2
  86. package/dist/esm/utils/logger.js.map +1 -1
  87. package/dist/esm/utils/validation.d.ts +6 -0
  88. package/dist/esm/utils/validation.d.ts.map +1 -1
  89. package/dist/esm/utils/validation.js +36 -0
  90. package/dist/esm/utils/validation.js.map +1 -1
  91. package/dist/esm/validation/keys.d.ts +7 -0
  92. package/dist/esm/validation/keys.d.ts.map +1 -0
  93. package/dist/esm/validation/keys.js +20 -0
  94. package/dist/esm/validation/keys.js.map +1 -0
  95. package/package.json +1 -1
  96. package/src/__tests__/integration.test.ts +1 -1
  97. package/src/__tests__/types.test.ts +36 -242
  98. package/src/event/index.ts +7 -0
  99. package/src/event/signing.ts +29 -0
  100. package/src/index.ts +39 -47
  101. package/src/nips/nip-04.ts +2 -0
  102. package/src/protocol/index.ts +23 -14
  103. package/src/types/base.ts +58 -122
  104. package/src/utils/encoding.ts +18 -0
  105. package/src/utils/integration.ts +159 -107
  106. package/src/utils/logger.ts +46 -2
  107. package/src/utils/validation.ts +37 -0
  108. package/src/validation/keys.ts +19 -0
  109. package/dist/browser/551.nostr-crypto-utils.min.js +0 -1
  110. package/dist/browser/565.nostr-crypto-utils.min.js +0 -1
  111. package/dist/browser/69.nostr-crypto-utils.min.js +0 -1
  112. package/dist/browser/main-43dd7041.nostr-crypto-utils.min.js +0 -1
  113. package/dist/browser/main-7bd12dde.nostr-crypto-utils.min.js +0 -1
  114. package/dist/browser/main-d277ceb9.nostr-crypto-utils.min.js +0 -1
@@ -3,37 +3,36 @@ import {
3
3
  NostrFilter,
4
4
  NostrEventKind,
5
5
  SignedNostrEvent,
6
+ NostrMessageType,
6
7
  NostrMessage,
7
- NostrMessageType
8
- } from '../types/base.js';
9
- import { NostrMessageTuple } from '../types/messages.js';
10
- import { logger } from './logger.js';
8
+ UnsignedEvent
9
+ } from '../types/base';
11
10
 
12
11
  /**
13
12
  * Format event for relay transmission
14
13
  */
15
- export function formatEventForRelay(event: SignedNostrEvent): NostrMessageTuple {
14
+ export function formatEventForRelay(event: SignedNostrEvent): [string, SignedNostrEvent] {
16
15
  return ['EVENT', event];
17
16
  }
18
17
 
19
18
  /**
20
19
  * Format subscription for relay transmission
21
20
  */
22
- export function formatSubscriptionForRelay(subscription: { id: string; filters: NostrFilter[] }): NostrMessageTuple {
21
+ export function formatSubscriptionForRelay(subscription: { id: string; filters: NostrFilter[] }): [string, string, ...NostrFilter[]] {
23
22
  return ['REQ', subscription.id, ...subscription.filters];
24
23
  }
25
24
 
26
25
  /**
27
26
  * Format close message for relay transmission
28
27
  */
29
- export function formatCloseForRelay(subscriptionId: string): NostrMessageTuple {
28
+ export function formatCloseForRelay(subscriptionId: string): [string, string] {
30
29
  return ['CLOSE', subscriptionId];
31
30
  }
32
31
 
33
32
  /**
34
33
  * Format auth message for relay transmission
35
34
  */
36
- export function formatAuthForRelay(event: SignedNostrEvent): NostrMessageTuple {
35
+ export function formatAuthForRelay(event: SignedNostrEvent): [string, SignedNostrEvent] {
37
36
  return ['AUTH', event];
38
37
  }
39
38
 
@@ -42,89 +41,142 @@ export function formatAuthForRelay(event: SignedNostrEvent): NostrMessageTuple {
42
41
  */
43
42
  export function parseNostrMessage(message: string | unknown[]): NostrMessage {
44
43
  try {
45
- // Handle array input
44
+ let parsed: unknown[];
45
+
46
46
  if (Array.isArray(message)) {
47
- if (!message.length || typeof message[0] !== 'string') {
48
- throw new Error('Invalid relay message: first element not a string');
49
- }
50
- const [type, ...payload] = message;
51
- if (!['EVENT', 'NOTICE', 'OK', 'EOSE', 'REQ', 'CLOSE', 'AUTH'].includes(type)) {
52
- throw new Error(`Unknown message type: ${type}`);
47
+ parsed = message;
48
+ } else if (typeof message === 'string') {
49
+ // Try parsing as JSON first
50
+ try {
51
+ parsed = JSON.parse(message);
52
+ } catch {
53
+ // If message is a single word, it's invalid
54
+ if (!message.includes(',')) {
55
+ throw new Error('Invalid relay message: not an array');
56
+ }
57
+ // If JSON parsing fails, try comma-separated format
58
+ parsed = message.split(',');
53
59
  }
54
- return {
55
- type: type as NostrMessageType,
56
- payload: payload.length === 1 ? payload[0] : payload
57
- };
60
+ } else {
61
+ throw new Error('Invalid relay message: input must be string or array');
58
62
  }
59
63
 
60
- // Handle string input
61
- if (typeof message === 'string') {
62
- // Try parsing as JSON first
63
- try {
64
- const parsed = JSON.parse(message);
65
- if (!Array.isArray(parsed) || !parsed.length || typeof parsed[0] !== 'string') {
66
- throw new Error('Invalid relay message: first element not a string');
64
+ if (!Array.isArray(parsed)) {
65
+ throw new Error('Invalid relay message: not an array');
66
+ }
67
+
68
+ const [type, ...payload] = parsed;
69
+ if (typeof type !== 'string') {
70
+ throw new Error('Invalid relay message: first element not a string');
71
+ }
72
+
73
+ if (!Object.values(NostrMessageType).includes(type as NostrMessageType)) {
74
+ throw new Error(`Unknown message type: ${type}. Supported types are: ${Object.values(NostrMessageType).join(', ')}`);
75
+ }
76
+
77
+ const nostrMessage: NostrMessage = {
78
+ type: type as NostrMessageType,
79
+ payload: [] as string[] // Initialize with empty array
80
+ };
81
+
82
+ switch (type) {
83
+ case NostrMessageType.EVENT: {
84
+ if (payload.length < 1) {
85
+ throw new Error('EVENT message missing event data');
67
86
  }
68
- const [type, ...payload] = parsed;
69
- if (!['EVENT', 'NOTICE', 'OK', 'EOSE', 'REQ', 'CLOSE', 'AUTH'].includes(type)) {
70
- throw new Error(`Unknown message type: ${type}`);
87
+ const eventData = typeof payload[0] === 'string' && payload[0].startsWith('{')
88
+ ? JSON.parse(payload[0]) as SignedNostrEvent
89
+ : payload[0] as SignedNostrEvent;
90
+ nostrMessage.event = eventData;
91
+ nostrMessage.payload = eventData as unknown as string;
92
+ break;
93
+ }
94
+
95
+ case NostrMessageType.NOTICE:
96
+ if (payload.length < 1) {
97
+ throw new Error('NOTICE message missing message text');
71
98
  }
72
- return {
73
- type: type as NostrMessageType,
74
- payload: payload.length === 1 ? payload[0] : payload
75
- };
76
- } catch (jsonError) {
77
- // If JSON parsing fails, try comma-separated format
78
- if (message.includes(',')) {
79
- const [type, ...payload] = message.split(',');
80
- if (!type) {
81
- throw new Error('Invalid relay message: empty command');
82
- }
83
- if (!['EVENT', 'NOTICE', 'OK', 'EOSE', 'REQ', 'CLOSE', 'AUTH'].includes(type)) {
84
- throw new Error(`Unknown message type: ${type}`);
99
+ nostrMessage.payload = String(payload[0]);
100
+ break;
101
+
102
+ case NostrMessageType.OK:
103
+ if (payload.length < 1) {
104
+ throw new Error('OK message missing event ID');
105
+ }
106
+ // Convert "true" and "false" strings to actual booleans
107
+ nostrMessage.payload = payload.map(item => {
108
+ if (typeof item === 'string') {
109
+ if (item === 'true') return true;
110
+ if (item === 'false') return false;
111
+ return item;
85
112
  }
86
- return {
87
- type: type as NostrMessageType,
88
- payload: payload.length === 1 ? payload[0] : payload
89
- };
113
+ return String(item);
114
+ }) as (string | boolean)[];
115
+ break;
116
+
117
+ case NostrMessageType.REQ: {
118
+ if (payload.length < 2) {
119
+ throw new Error('REQ message missing subscription ID or filters');
90
120
  }
91
- throw new Error('Invalid relay message: not an array');
121
+ nostrMessage.subscriptionId = String(payload[0]);
122
+ const filters = payload.slice(1).map(filter =>
123
+ typeof filter === 'string' && filter.startsWith('{')
124
+ ? JSON.parse(filter)
125
+ : filter
126
+ ) as NostrFilter[];
127
+ nostrMessage.filters = filters;
128
+ nostrMessage.payload = [String(payload[0]), ...filters.map(f => JSON.stringify(f))];
129
+ break;
92
130
  }
131
+
132
+ case NostrMessageType.CLOSE:
133
+ if (payload.length < 1) {
134
+ throw new Error('CLOSE message missing subscription ID');
135
+ }
136
+ nostrMessage.subscriptionId = String(payload[0]);
137
+ nostrMessage.payload = String(payload[0]);
138
+ break;
139
+
140
+ case NostrMessageType.AUTH:
141
+ if (payload.length < 1) {
142
+ throw new Error('AUTH message missing challenge');
143
+ }
144
+ nostrMessage.message = String(payload[0]);
145
+ nostrMessage.payload = String(payload[0]);
146
+ break;
147
+
148
+ default:
149
+ throw new Error(`Unknown message type: ${type}`);
93
150
  }
94
151
 
95
- throw new Error('Invalid relay message: not a string or array');
96
- } catch (error) {
97
- logger.error('Failed to parse message:', error);
98
- throw error;
152
+ return nostrMessage;
153
+ } catch (error: unknown) {
154
+ throw new Error(`Failed to parse Nostr message: ${error instanceof Error ? error.message : String(error)}`);
99
155
  }
100
156
  }
101
157
 
102
158
  /**
103
159
  * Create a metadata event
104
160
  */
105
- export function createMetadataEvent(metadata: Record<string, string>): NostrEvent {
161
+ export function createMetadataEvent(metadata: Record<string, string>): UnsignedEvent {
106
162
  return {
107
163
  kind: NostrEventKind.SET_METADATA,
108
164
  content: JSON.stringify(metadata),
109
- tags: [],
110
165
  created_at: Math.floor(Date.now() / 1000),
111
- pubkey: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' // Placeholder hex pubkey
166
+ tags: [],
167
+ pubkey: '' // Required by UnsignedEvent interface
112
168
  };
113
169
  }
114
170
 
115
171
  /**
116
172
  * Create a text note event
117
173
  */
118
- export function createTextNoteEvent(content: string, replyTo?: string, mentions?: string[]): NostrEvent {
119
- const tags: string[][] = [];
120
-
121
- // Add reply tag if specified
174
+ export function createTextNoteEvent(content: string, replyTo?: string, mentions?: string[]): UnsignedEvent {
175
+ const tags = [];
122
176
  if (replyTo) {
123
177
  tags.push(['e', replyTo]);
124
178
  }
125
-
126
- // Add mention tags if specified
127
- if (mentions) {
179
+ if (mentions?.length) {
128
180
  mentions.forEach(pubkey => {
129
181
  tags.push(['p', pubkey]);
130
182
  });
@@ -133,29 +185,29 @@ export function createTextNoteEvent(content: string, replyTo?: string, mentions?
133
185
  return {
134
186
  kind: NostrEventKind.TEXT_NOTE,
135
187
  content,
136
- tags,
137
188
  created_at: Math.floor(Date.now() / 1000),
138
- pubkey: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' // Placeholder hex pubkey
189
+ tags,
190
+ pubkey: '' // Required by UnsignedEvent interface
139
191
  };
140
192
  }
141
193
 
142
194
  /**
143
195
  * Create a direct message event
144
196
  */
145
- export function createDirectMessageEvent(recipientPubkey: string, content: string): NostrEvent {
197
+ export function createDirectMessageEvent(recipientPubkey: string, content: string): UnsignedEvent {
146
198
  return {
147
199
  kind: NostrEventKind.ENCRYPTED_DIRECT_MESSAGE,
148
200
  content,
149
- tags: [['p', recipientPubkey]],
150
201
  created_at: Math.floor(Date.now() / 1000),
151
- pubkey: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' // Placeholder hex pubkey
202
+ tags: [['p', recipientPubkey]],
203
+ pubkey: '' // Required by UnsignedEvent interface
152
204
  };
153
205
  }
154
206
 
155
207
  /**
156
208
  * Create a channel message event
157
209
  */
158
- export function createChannelMessageEvent(channelId: string, content: string, replyTo?: string): NostrEvent {
210
+ export function createChannelMessageEvent(channelId: string, content: string, replyTo?: string): UnsignedEvent {
159
211
  const tags = [['e', channelId, '', 'root']];
160
212
  if (replyTo) {
161
213
  tags.push(['e', replyTo, '', 'reply']);
@@ -164,25 +216,18 @@ export function createChannelMessageEvent(channelId: string, content: string, re
164
216
  return {
165
217
  kind: NostrEventKind.CHANNEL_MESSAGE,
166
218
  content,
167
- tags,
168
219
  created_at: Math.floor(Date.now() / 1000),
169
- pubkey: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' // Placeholder hex pubkey
220
+ tags,
221
+ pubkey: '' // Required by UnsignedEvent interface
170
222
  };
171
223
  }
172
224
 
173
225
  /**
174
226
  * Extract referenced events from tags
175
227
  */
176
- export function extractReferencedEvents(event: unknown): unknown[] {
177
- if (typeof event !== 'object' || event === null || !Array.isArray((event as Record<string, unknown>).tags)) {
178
- return [];
179
- }
180
-
181
- const validEvent = event as Record<string, unknown>;
182
- const tags = validEvent.tags as unknown[][];
183
-
184
- return tags
185
- .filter(tag => Array.isArray(tag) && tag[0] === 'e' && typeof tag[1] === 'string')
228
+ export function extractReferencedEvents(event: NostrEvent): string[] {
229
+ return event.tags
230
+ .filter(tag => tag[0] === 'e')
186
231
  .map(tag => tag[1]);
187
232
  }
188
233
 
@@ -199,82 +244,89 @@ export function extractMentionedPubkeys(event: NostrEvent): string[] {
199
244
  * Create a filter for events of a specific kind
200
245
  */
201
246
  export function createKindFilter(kind: NostrEventKind, limit?: number): NostrFilter {
202
- return {
203
- kinds: [kind],
204
- limit: limit || 10
205
- };
247
+ const filter: NostrFilter = { kinds: [kind] };
248
+ if (limit) {
249
+ filter.limit = limit;
250
+ }
251
+ return filter;
206
252
  }
207
253
 
208
254
  /**
209
255
  * Create a filter for events by a specific author
210
256
  */
211
257
  export function createAuthorFilter(pubkey: string, kinds?: NostrEventKind[], limit?: number): NostrFilter {
212
- return {
213
- authors: [pubkey],
214
- kinds: kinds || [NostrEventKind.TEXT_NOTE],
215
- limit: limit || 10
216
- };
258
+ const filter: NostrFilter = { authors: [pubkey] };
259
+ if (kinds?.length) {
260
+ filter.kinds = kinds;
261
+ }
262
+ if (limit) {
263
+ filter.limit = limit;
264
+ }
265
+ return filter;
217
266
  }
218
267
 
219
268
  /**
220
269
  * Create a filter for replies to a specific event
221
270
  */
222
271
  export function createReplyFilter(eventId: string, limit?: number): NostrFilter {
223
- return {
224
- '#e': [eventId],
272
+ const filter: NostrFilter = {
225
273
  kinds: [NostrEventKind.TEXT_NOTE, NostrEventKind.CHANNEL_MESSAGE],
226
- limit: limit || 10
274
+ '#e': [eventId]
227
275
  };
276
+ if (limit) {
277
+ filter.limit = limit;
278
+ }
279
+ return filter;
228
280
  }
229
281
 
230
282
  /**
231
283
  * Creates a mock text note event for testing
232
284
  */
233
- export function createMockTextNote(content?: string): NostrEvent {
285
+ export function createMockTextNote(content = 'Hello, Nostr!'): UnsignedEvent {
234
286
  return {
235
287
  kind: NostrEventKind.TEXT_NOTE,
236
- content: content || 'Mock text note',
237
- tags: [],
288
+ content,
238
289
  created_at: Math.floor(Date.now() / 1000),
239
- pubkey: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
290
+ tags: [],
291
+ pubkey: '' // Required by UnsignedEvent interface
240
292
  };
241
293
  }
242
294
 
243
295
  /**
244
296
  * Creates a mock metadata event for testing
245
297
  */
246
- export function createMockMetadataEvent(metadata?: Record<string, string>): NostrEvent {
298
+ export function createMockMetadataEvent(metadata: Record<string, string> = {}): UnsignedEvent {
247
299
  return {
248
300
  kind: NostrEventKind.SET_METADATA,
249
- content: JSON.stringify(metadata || { name: 'Mock User' }),
250
- tags: [],
301
+ content: JSON.stringify(metadata),
251
302
  created_at: Math.floor(Date.now() / 1000),
252
- pubkey: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
303
+ tags: [],
304
+ pubkey: '' // Required by UnsignedEvent interface
253
305
  };
254
306
  }
255
307
 
256
308
  /**
257
309
  * Creates a mock direct message event for testing
258
310
  */
259
- export function createMockDirectMessage(content?: string): NostrEvent {
311
+ export function createMockDirectMessage(content = 'Hello!'): UnsignedEvent {
260
312
  return {
261
313
  kind: NostrEventKind.ENCRYPTED_DIRECT_MESSAGE,
262
- content: content || 'Mock DM',
263
- tags: [['p', '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef']],
314
+ content,
264
315
  created_at: Math.floor(Date.now() / 1000),
265
- pubkey: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
316
+ tags: [],
317
+ pubkey: '' // Required by UnsignedEvent interface
266
318
  };
267
319
  }
268
320
 
269
321
  /**
270
322
  * Creates a mock channel message event for testing
271
323
  */
272
- export function createMockChannelMessage(content?: string): NostrEvent {
324
+ export function createMockChannelMessage(content = 'Hello, channel!'): UnsignedEvent {
273
325
  return {
274
326
  kind: NostrEventKind.CHANNEL_MESSAGE,
275
- content: content || 'Mock channel message',
276
- tags: [['e', '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef', '', 'root']],
327
+ content,
277
328
  created_at: Math.floor(Date.now() / 1000),
278
- pubkey: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
329
+ tags: [],
330
+ pubkey: '' // Required by UnsignedEvent interface
279
331
  };
280
332
  }
@@ -3,15 +3,21 @@
3
3
  * @description Logger utility for the application
4
4
  */
5
5
 
6
+ enum LogLevel {
7
+ DEBUG,
8
+ INFO,
9
+ WARN,
10
+ ERROR
11
+ }
12
+
6
13
  import pino from 'pino';
7
14
 
8
15
  /**
9
16
  * Create a logger instance with consistent configuration
10
17
  * @param name - Component or module name for the logger
11
- * @param _options - Optional additional configuration
12
18
  * @returns Configured pino logger instance
13
19
  */
14
- export function createLogger(name: string, _options?: unknown): pino.Logger {
20
+ export function createLogger(name: string): pino.Logger {
15
21
  return pino({
16
22
  name,
17
23
  level: process.env.LOG_LEVEL || 'info',
@@ -78,5 +84,43 @@ export const logger: pino.Logger = pino({
78
84
  }
79
85
  });
80
86
 
87
+ export class CustomLogger {
88
+ private _level: LogLevel;
89
+
90
+ constructor(level: LogLevel = LogLevel.INFO) {
91
+ this._level = level;
92
+ }
93
+
94
+ setLevel(level: LogLevel): void {
95
+ this._level = level;
96
+ }
97
+
98
+ private _log(level: LogLevel, message: string, context?: Record<string, unknown>): void {
99
+ if (level >= this._level) {
100
+ const timestamp = new Date().toISOString();
101
+ const levelName = LogLevel[level];
102
+ const contextStr = context ? ` ${JSON.stringify(context)}` : '';
103
+ console.log(`[${timestamp}] ${levelName}: ${message}${contextStr}`);
104
+ }
105
+ }
106
+
107
+ debug(message: string, context?: Record<string, unknown>): void {
108
+ this._log(LogLevel.DEBUG, message, context);
109
+ }
110
+
111
+ info(message: string, context?: Record<string, unknown>): void {
112
+ this._log(LogLevel.INFO, message, context);
113
+ }
114
+
115
+ warn(message: string, context?: Record<string, unknown>): void {
116
+ this._log(LogLevel.WARN, message, context);
117
+ }
118
+
119
+ error(message: string | Error | unknown, context?: Record<string, unknown>): void {
120
+ const errorMessage = message instanceof Error ? message.message : String(message);
121
+ this._log(LogLevel.ERROR, errorMessage, context);
122
+ }
123
+ }
124
+
81
125
  // Re-export the Logger type for use in other files
82
126
  export type { Logger } from 'pino';
@@ -155,6 +155,43 @@ export function validateSignedEvent(event: SignedNostrEvent): ValidationResult {
155
155
  };
156
156
  }
157
157
 
158
+ /**
159
+ * Validates a public key hex string
160
+ * @param {string} pubkey - Public key to validate
161
+ * @returns {ValidationResult} Validation result
162
+ */
163
+ export function validatePublicKey(pubkey: string): ValidationResult {
164
+ try {
165
+ // Check if it's a valid hex string
166
+ if (!/^[0-9a-f]{64}$/i.test(pubkey)) {
167
+ return {
168
+ isValid: false,
169
+ error: 'Public key must be a 32-byte hex string'
170
+ };
171
+ }
172
+
173
+ // Try to convert to bytes
174
+ try {
175
+ hexToBytes(pubkey);
176
+ } catch (error) {
177
+ return {
178
+ isValid: false,
179
+ error: 'Invalid hex encoding'
180
+ };
181
+ }
182
+
183
+ return {
184
+ isValid: true,
185
+ error: undefined
186
+ };
187
+ } catch (error) {
188
+ return {
189
+ isValid: false,
190
+ error: error instanceof Error ? error.message : 'Unknown error validating public key'
191
+ };
192
+ }
193
+ }
194
+
158
195
  /**
159
196
  * Validates a filter object
160
197
  * @param filter - Filter to validate
@@ -0,0 +1,19 @@
1
+ import { validatePublicKey } from '../utils/validation';
2
+ import { logger } from '../utils/logger';
3
+
4
+ /**
5
+ * Validates a Nostr public key
6
+ * @param pubkey - Public key in hex format
7
+ * @returns True if public key is valid
8
+ */
9
+ export function isValidPublicKey(pubkey: string): boolean {
10
+ try {
11
+ if (typeof pubkey !== 'string') return false;
12
+
13
+ const result = validatePublicKey(pubkey);
14
+ return result.isValid;
15
+ } catch (error) {
16
+ logger.error({ error }, 'Failed to validate public key');
17
+ return false;
18
+ }
19
+ }
@@ -1 +0,0 @@
1
- "use strict";(this.webpackChunkNostrCryptoUtils=this.webpackChunkNostrCryptoUtils||[]).push([[551,565],{2343:(e,r)=>{const t="qpzry9x8gf2tvdw0s3jn54khce6mua7l",n={};for(let e=0;e<32;e++){const r=t.charAt(e);n[r]=e}function i(e){const r=e>>25;return(33554431&e)<<5^996825010&-(1&r)^642813549&-(r>>1&1)^513874426&-(r>>2&1)^1027748829&-(r>>3&1)^705979059&-(r>>4&1)}function c(e){let r=1;for(let t=0;t<e.length;++t){const n=e.charCodeAt(t);if(n<33||n>126)return"Invalid prefix ("+e+")";r=i(r)^n>>5}r=i(r);for(let t=0;t<e.length;++t){const n=e.charCodeAt(t);r=i(r)^31&n}return r}function o(e,r,t,n){let i=0,c=0;const o=(1<<t)-1,a=[];for(let n=0;n<e.length;++n)for(i=i<<r|e[n],c+=r;c>=t;)c-=t,a.push(i>>c&o);if(n)c>0&&a.push(i<<t-c&o);else{if(c>=r)return"Excess padding";if(i<<t-c&o)return"Non-zero padding"}return a}function a(e){return o(e,8,5,!0)}function s(e){const r=o(e,5,8,!1);if(Array.isArray(r))return r}function f(e){const r=o(e,5,8,!1);if(Array.isArray(r))return r;throw new Error(r)}function l(e){let r;function o(e,t){if(t=t||90,e.length<8)return e+" too short";if(e.length>t)return"Exceeds length limit";const o=e.toLowerCase(),a=e.toUpperCase();if(e!==o&&e!==a)return"Mixed-case string "+e;const s=(e=o).lastIndexOf("1");if(-1===s)return"No separator character for "+e;if(0===s)return"Missing prefix for "+e;const f=e.slice(0,s),l=e.slice(s+1);if(l.length<6)return"Data too short";let p=c(f);if("string"==typeof p)return p;const h=[];for(let e=0;e<l.length;++e){const r=l.charAt(e),t=n[r];if(void 0===t)return"Unknown character "+r;p=i(p)^t,e+6>=l.length||h.push(t)}return p!==r?"Invalid checksum for "+e:{prefix:f,words:h}}return r="bech32"===e?1:734539939,{decodeUnsafe:function(e,r){const t=o(e,r);if("object"==typeof t)return t},decode:function(e,r){const t=o(e,r);if("object"==typeof t)return t;throw new Error(t)},encode:function(e,n,o){if(o=o||90,e.length+7+n.length>o)throw new TypeError("Exceeds length limit");let a=c(e=e.toLowerCase());if("string"==typeof a)throw new Error(a);let s=e+"1";for(let e=0;e<n.length;++e){const r=n[e];if(r>>5)throw new Error("Non 5-bit word");a=i(a)^r,s+=t.charAt(r)}for(let e=0;e<6;++e)a=i(a);a^=r;for(let e=0;e<6;++e)s+=t.charAt(a>>5*(5-e)&31);return s},toWords:a,fromWordsUnsafe:s,fromWords:f}}l("bech32"),l("bech32m")},1565:(e,r,t)=>{r.randomBytes=r.rng=r.pseudoRandomBytes=r.prng=t(3209),r.createHash=r.Hash=t(7108),r.createHmac=r.Hmac=t(3507);var n=t(5715),i=Object.keys(n),c=["sha1","sha224","sha256","sha384","sha512","md5","rmd160"].concat(i);r.getHashes=function(){return c};var o=t(8396);r.pbkdf2=o.pbkdf2,r.pbkdf2Sync=o.pbkdf2Sync;var a=t(125);r.Cipher=a.Cipher,r.createCipher=a.createCipher,r.Cipheriv=a.Cipheriv,r.createCipheriv=a.createCipheriv,r.Decipher=a.Decipher,r.createDecipher=a.createDecipher,r.Decipheriv=a.Decipheriv,r.createDecipheriv=a.createDecipheriv,r.getCiphers=a.getCiphers,r.listCiphers=a.listCiphers;var s=t(5380);r.DiffieHellmanGroup=s.DiffieHellmanGroup,r.createDiffieHellmanGroup=s.createDiffieHellmanGroup,r.getDiffieHellman=s.getDiffieHellman,r.createDiffieHellman=s.createDiffieHellman,r.DiffieHellman=s.DiffieHellman;var f=t(20);r.createSign=f.createSign,r.Sign=f.Sign,r.createVerify=f.createVerify,r.Verify=f.Verify,r.createECDH=t(1324);var l=t(7168);r.publicEncrypt=l.publicEncrypt,r.privateEncrypt=l.privateEncrypt,r.publicDecrypt=l.publicDecrypt,r.privateDecrypt=l.privateDecrypt;var p=t(6983);r.randomFill=p.randomFill,r.randomFillSync=p.randomFillSync,r.createCredentials=function(){throw new Error("sorry, createCredentials is not implemented yet\nwe accept pull requests\nhttps://github.com/browserify/crypto-browserify")},r.constants={DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,NPN_ENABLED:1,ALPN_ENABLED:1,RSA_PKCS1_PADDING:1,RSA_SSLV23_PADDING:2,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6}}}]);
@@ -1 +0,0 @@
1
- "use strict";(this.webpackChunkNostrCryptoUtils=this.webpackChunkNostrCryptoUtils||[]).push([[565],{1565:(e,r,i)=>{r.randomBytes=r.rng=r.pseudoRandomBytes=r.prng=i(3209),r.createHash=r.Hash=i(7108),r.createHmac=r.Hmac=i(3507);var t=i(5715),a=Object.keys(t),c=["sha1","sha224","sha256","sha384","sha512","md5","rmd160"].concat(a);r.getHashes=function(){return c};var p=i(8396);r.pbkdf2=p.pbkdf2,r.pbkdf2Sync=p.pbkdf2Sync;var n=i(125);r.Cipher=n.Cipher,r.createCipher=n.createCipher,r.Cipheriv=n.Cipheriv,r.createCipheriv=n.createCipheriv,r.Decipher=n.Decipher,r.createDecipher=n.createDecipher,r.Decipheriv=n.Decipheriv,r.createDecipheriv=n.createDecipheriv,r.getCiphers=n.getCiphers,r.listCiphers=n.listCiphers;var D=i(5380);r.DiffieHellmanGroup=D.DiffieHellmanGroup,r.createDiffieHellmanGroup=D.createDiffieHellmanGroup,r.getDiffieHellman=D.getDiffieHellman,r.createDiffieHellman=D.createDiffieHellman,r.DiffieHellman=D.DiffieHellman;var l=i(20);r.createSign=l.createSign,r.Sign=l.Sign,r.createVerify=l.createVerify,r.Verify=l.Verify,r.createECDH=i(1324);var s=i(7168);r.publicEncrypt=s.publicEncrypt,r.privateEncrypt=s.privateEncrypt,r.publicDecrypt=s.publicDecrypt,r.privateDecrypt=s.privateDecrypt;var _=i(6983);r.randomFill=_.randomFill,r.randomFillSync=_.randomFillSync,r.createCredentials=function(){throw new Error("sorry, createCredentials is not implemented yet\nwe accept pull requests\nhttps://github.com/browserify/crypto-browserify")},r.constants={DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,NPN_ENABLED:1,ALPN_ENABLED:1,RSA_PKCS1_PADDING:1,RSA_SSLV23_PADDING:2,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6}}}]);
@@ -1 +0,0 @@
1
- (this.webpackChunkNostrCryptoUtils=this.webpackChunkNostrCryptoUtils||[]).push([[69],{295:(t,e,r)=>{var n=r(8287).Buffer;t.exports=function(t,e){for(var r=Math.min(t.length,e.length),i=new n(r),o=0;o<r;++o)i[o]=t[o]^e[o];return i}},6168:(t,e,r)=>{"use strict";var n=r(2861).Buffer,i=r(8310).Transform,o=r(3141).I;function s(t){i.call(this),this.hashMode="string"==typeof t,this.hashMode?this[t]=this._finalOrDigest:this.final=this._finalOrDigest,this._final&&(this.__final=this._final,this._final=null),this._decoder=null,this._encoding=null}r(6698)(s,i);var f="undefined"!=typeof Uint8Array,u="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof Uint8Array&&ArrayBuffer.isView&&(n.prototype instanceof Uint8Array||n.TYPED_ARRAY_SUPPORT);s.prototype.update=function(t,e,r){var i=function(t,e){if(t instanceof n)return t;if("string"==typeof t)return n.from(t,e);if(u&&ArrayBuffer.isView(t)){if(0===t.byteLength)return n.alloc(0);var r=n.from(t.buffer,t.byteOffset,t.byteLength);if(r.byteLength===t.byteLength)return r}if(f&&t instanceof Uint8Array)return n.from(t);if(n.isBuffer(t)&&t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t))return n.from(t);throw new TypeError('The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView.')}(t,e),o=this._update(i);return this.hashMode?this:(r&&(o=this._toString(o,r)),o)},s.prototype.setAutoPadding=function(){},s.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")},s.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")},s.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")},s.prototype._transform=function(t,e,r){var n;try{this.hashMode?this._update(t):this.push(this._update(t))}catch(t){n=t}finally{r(n)}},s.prototype._flush=function(t){var e;try{this.push(this.__final())}catch(t){e=t}t(e)},s.prototype._finalOrDigest=function(t){var e=this.__final()||n.alloc(0);return t&&(e=this._toString(e,t,!0)),e},s.prototype._toString=function(t,e,r){if(this._decoder||(this._decoder=new o(e),this._encoding=e),this._encoding!==e)throw new Error("can’t switch encodings");var n=this._decoder.write(t);return r&&(n+=this._decoder.end()),n},t.exports=s},5622:(t,e,r)=>{function n(t){return Object.prototype.toString.call(t)}e.isArray=function(t){return Array.isArray?Array.isArray(t):"[object Array]"===n(t)},e.isBoolean=function(t){return"boolean"==typeof t},e.isNull=function(t){return null===t},e.isNullOrUndefined=function(t){return null==t},e.isNumber=function(t){return"number"==typeof t},e.isString=function(t){return"string"==typeof t},e.isSymbol=function(t){return"symbol"==typeof t},e.isUndefined=function(t){return void 0===t},e.isRegExp=function(t){return"[object RegExp]"===n(t)},e.isObject=function(t){return"object"==typeof t&&null!==t},e.isDate=function(t){return"[object Date]"===n(t)},e.isError=function(t){return"[object Error]"===n(t)||t instanceof Error},e.isFunction=function(t){return"function"==typeof t},e.isPrimitive=function(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||void 0===t},e.isBuffer=r(8287).Buffer.isBuffer},1324:(t,e,r)=>{var n=r(8287).Buffer,i=r(6729),o=r(2801);t.exports=function(t){return new f(t)};var s={secp256k1:{name:"secp256k1",byteLength:32},secp224r1:{name:"p224",byteLength:28},prime256v1:{name:"p256",byteLength:32},prime192v1:{name:"p192",byteLength:24},ed25519:{name:"ed25519",byteLength:32},secp384r1:{name:"p384",byteLength:48},secp521r1:{name:"p521",byteLength:66}};function f(t){this.curveType=s[t],this.curveType||(this.curveType={name:t}),this.curve=new i.ec(this.curveType.name),this.keys=void 0}function u(t,e,r){Array.isArray(t)||(t=t.toArray());var i=new n(t);if(r&&i.length<r){var o=new n(r-i.length);o.fill(0),i=n.concat([o,i])}return e?i.toString(e):i}s.p224=s.secp224r1,s.p256=s.secp256r1=s.prime256v1,s.p192=s.secp192r1=s.prime192v1,s.p384=s.secp384r1,s.p521=s.secp521r1,f.prototype.generateKeys=function(t,e){return this.keys=this.curve.genKeyPair(),this.getPublicKey(t,e)},f.prototype.computeSecret=function(t,e,r){return e=e||"utf8",n.isBuffer(t)||(t=new n(t,e)),u(this.curve.keyFromPublic(t).getPublic().mul(this.keys.getPrivate()).getX(),r,this.curveType.byteLength)},f.prototype.getPublicKey=function(t,e){var r=this.keys.getPublic("compressed"===e,!0);return"hybrid"===e&&(r[r.length-1]%2?r[0]=7:r[0]=6),u(r,t)},f.prototype.getPrivateKey=function(t){return u(this.keys.getPrivate(),t)},f.prototype.setPublicKey=function(t,e){return e=e||"utf8",n.isBuffer(t)||(t=new n(t,e)),this.keys._importPublic(t),this},f.prototype.setPrivateKey=function(t,e){e=e||"utf8",n.isBuffer(t)||(t=new n(t,e));var r=new o(t);return r=r.toString(16),this.keys=this.curve.genKeyPair(),this.keys._importPrivate(r),this}},7108:(t,e,r)=>{"use strict";var n=r(6698),i=r(8276),o=r(6011),s=r(2802),f=r(6168);function u(t){f.call(this,"digest"),this._hash=t}n(u,f),u.prototype._update=function(t){this._hash.update(t)},u.prototype._final=function(){return this._hash.digest()},t.exports=function(t){return"md5"===(t=t.toLowerCase())?new i:"rmd160"===t||"ripemd160"===t?new o:new u(s(t))}},320:(t,e,r)=>{var n=r(8276);t.exports=function(t){return(new n).update(t).digest()}},3507:(t,e,r)=>{"use strict";var n=r(6698),i=r(1800),o=r(6168),s=r(2861).Buffer,f=r(320),u=r(6011),a=r(2802),p=s.alloc(128);function h(t,e){o.call(this,"digest"),"string"==typeof e&&(e=s.from(e));var r="sha512"===t||"sha384"===t?128:64;this._alg=t,this._key=e,e.length>r?e=("rmd160"===t?new u:a(t)).update(e).digest():e.length<r&&(e=s.concat([e,p],r));for(var n=this._ipad=s.allocUnsafe(r),i=this._opad=s.allocUnsafe(r),f=0;f<r;f++)n[f]=54^e[f],i[f]=92^e[f];this._hash="rmd160"===t?new u:a(t),this._hash.update(n)}n(h,o),h.prototype._update=function(t){this._hash.update(t)},h.prototype._final=function(){var t=this._hash.digest();return("rmd160"===this._alg?new u:a(this._alg)).update(this._opad).update(t).digest()},t.exports=function(t,e){return"rmd160"===(t=t.toLowerCase())||"ripemd160"===t?new h("rmd160",e):"md5"===t?new i(f,e):new h(t,e)}},1800:(t,e,r)=>{"use strict";var n=r(6698),i=r(2861).Buffer,o=r(6168),s=i.alloc(128),f=64;function u(t,e){o.call(this,"digest"),"string"==typeof e&&(e=i.from(e)),this._alg=t,this._key=e,e.length>f?e=t(e):e.length<f&&(e=i.concat([e,s],f));for(var r=this._ipad=i.allocUnsafe(f),n=this._opad=i.allocUnsafe(f),u=0;u<f;u++)r[u]=54^e[u],n[u]=92^e[u];this._hash=[r]}n(u,o),u.prototype._update=function(t){this._hash.push(t)},u.prototype._final=function(){var t=this._alg(i.concat(this._hash));return this._alg(i.concat([this._opad,t]))},t.exports=u},9560:(t,e,r)=>{"use strict";e.utils=r(7626),e.Cipher=r(2808),e.DES=r(2211),e.CBC=r(3389),e.EDE=r(5279)},3389:(t,e,r)=>{"use strict";var n=r(3349),i=r(6698),o={};function s(t){n.equal(t.length,8,"Invalid IV length"),this.iv=new Array(8);for(var e=0;e<this.iv.length;e++)this.iv[e]=t[e]}e.instantiate=function(t){function e(e){t.call(this,e),this._cbcInit()}i(e,t);for(var r=Object.keys(o),n=0;n<r.length;n++){var s=r[n];e.prototype[s]=o[s]}return e.create=function(t){return new e(t)},e},o._cbcInit=function(){var t=new s(this.options.iv);this._cbcState=t},o._update=function(t,e,r,n){var i=this._cbcState,o=this.constructor.super_.prototype,s=i.iv;if("encrypt"===this.type){for(var f=0;f<this.blockSize;f++)s[f]^=t[e+f];for(o._update.call(this,s,0,r,n),f=0;f<this.blockSize;f++)s[f]=r[n+f]}else{for(o._update.call(this,t,e,r,n),f=0;f<this.blockSize;f++)r[n+f]^=s[f];for(f=0;f<this.blockSize;f++)s[f]=t[e+f]}}},2808:(t,e,r)=>{"use strict";var n=r(3349);function i(t){this.options=t,this.type=this.options.type,this.blockSize=8,this._init(),this.buffer=new Array(this.blockSize),this.bufferOff=0,this.padding=!1!==t.padding}t.exports=i,i.prototype._init=function(){},i.prototype.update=function(t){return 0===t.length?[]:"decrypt"===this.type?this._updateDecrypt(t):this._updateEncrypt(t)},i.prototype._buffer=function(t,e){for(var r=Math.min(this.buffer.length-this.bufferOff,t.length-e),n=0;n<r;n++)this.buffer[this.bufferOff+n]=t[e+n];return this.bufferOff+=r,r},i.prototype._flushBuffer=function(t,e){return this._update(this.buffer,0,t,e),this.bufferOff=0,this.blockSize},i.prototype._updateEncrypt=function(t){var e=0,r=0,n=(this.bufferOff+t.length)/this.blockSize|0,i=new Array(n*this.blockSize);0!==this.bufferOff&&(e+=this._buffer(t,e),this.bufferOff===this.buffer.length&&(r+=this._flushBuffer(i,r)));for(var o=t.length-(t.length-e)%this.blockSize;e<o;e+=this.blockSize)this._update(t,e,i,r),r+=this.blockSize;for(;e<t.length;e++,this.bufferOff++)this.buffer[this.bufferOff]=t[e];return i},i.prototype._updateDecrypt=function(t){for(var e=0,r=0,n=Math.ceil((this.bufferOff+t.length)/this.blockSize)-1,i=new Array(n*this.blockSize);n>0;n--)e+=this._buffer(t,e),r+=this._flushBuffer(i,r);return e+=this._buffer(t,e),i},i.prototype.final=function(t){var e,r;return t&&(e=this.update(t)),r="encrypt"===this.type?this._finalEncrypt():this._finalDecrypt(),e?e.concat(r):r},i.prototype._pad=function(t,e){if(0===e)return!1;for(;e<t.length;)t[e++]=0;return!0},i.prototype._finalEncrypt=function(){if(!this._pad(this.buffer,this.bufferOff))return[];var t=new Array(this.blockSize);return this._update(this.buffer,0,t,0),t},i.prototype._unpad=function(t){return t},i.prototype._finalDecrypt=function(){n.equal(this.bufferOff,this.blockSize,"Not enough data to decrypt");var t=new Array(this.blockSize);return this._flushBuffer(t,0),this._unpad(t)}},2211:(t,e,r)=>{"use strict";var n=r(3349),i=r(6698),o=r(7626),s=r(2808);function f(){this.tmp=new Array(2),this.keys=null}function u(t){s.call(this,t);var e=new f;this._desState=e,this.deriveKeys(e,t.key)}i(u,s),t.exports=u,u.create=function(t){return new u(t)};var a=[1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1];u.prototype.deriveKeys=function(t,e){t.keys=new Array(32),n.equal(e.length,this.blockSize,"Invalid key length");var r=o.readUInt32BE(e,0),i=o.readUInt32BE(e,4);o.pc1(r,i,t.tmp,0),r=t.tmp[0],i=t.tmp[1];for(var s=0;s<t.keys.length;s+=2){var f=a[s>>>1];r=o.r28shl(r,f),i=o.r28shl(i,f),o.pc2(r,i,t.keys,s)}},u.prototype._update=function(t,e,r,n){var i=this._desState,s=o.readUInt32BE(t,e),f=o.readUInt32BE(t,e+4);o.ip(s,f,i.tmp,0),s=i.tmp[0],f=i.tmp[1],"encrypt"===this.type?this._encrypt(i,s,f,i.tmp,0):this._decrypt(i,s,f,i.tmp,0),s=i.tmp[0],f=i.tmp[1],o.writeUInt32BE(r,s,n),o.writeUInt32BE(r,f,n+4)},u.prototype._pad=function(t,e){if(!1===this.padding)return!1;for(var r=t.length-e,n=e;n<t.length;n++)t[n]=r;return!0},u.prototype._unpad=function(t){if(!1===this.padding)return t;for(var e=t[t.length-1],r=t.length-e;r<t.length;r++)n.equal(t[r],e);return t.slice(0,t.length-e)},u.prototype._encrypt=function(t,e,r,n,i){for(var s=e,f=r,u=0;u<t.keys.length;u+=2){var a=t.keys[u],p=t.keys[u+1];o.expand(f,t.tmp,0),a^=t.tmp[0],p^=t.tmp[1];var h=o.substitute(a,p),c=f;f=(s^o.permute(h))>>>0,s=c}o.rip(f,s,n,i)},u.prototype._decrypt=function(t,e,r,n,i){for(var s=r,f=e,u=t.keys.length-2;u>=0;u-=2){var a=t.keys[u],p=t.keys[u+1];o.expand(s,t.tmp,0),a^=t.tmp[0],p^=t.tmp[1];var h=o.substitute(a,p),c=s;s=(f^o.permute(h))>>>0,f=c}o.rip(s,f,n,i)}},5279:(t,e,r)=>{"use strict";var n=r(3349),i=r(6698),o=r(2808),s=r(2211);function f(t,e){n.equal(e.length,24,"Invalid key length");var r=e.slice(0,8),i=e.slice(8,16),o=e.slice(16,24);this.ciphers="encrypt"===t?[s.create({type:"encrypt",key:r}),s.create({type:"decrypt",key:i}),s.create({type:"encrypt",key:o})]:[s.create({type:"decrypt",key:o}),s.create({type:"encrypt",key:i}),s.create({type:"decrypt",key:r})]}function u(t){o.call(this,t);var e=new f(this.type,this.options.key);this._edeState=e}i(u,o),t.exports=u,u.create=function(t){return new u(t)},u.prototype._update=function(t,e,r,n){var i=this._edeState;i.ciphers[0]._update(t,e,r,n),i.ciphers[1]._update(r,n,r,n),i.ciphers[2]._update(r,n,r,n)},u.prototype._pad=s.prototype._pad,u.prototype._unpad=s.prototype._unpad},7626:(t,e)=>{"use strict";e.readUInt32BE=function(t,e){return(t[0+e]<<24|t[1+e]<<16|t[2+e]<<8|t[3+e])>>>0},e.writeUInt32BE=function(t,e,r){t[0+r]=e>>>24,t[1+r]=e>>>16&255,t[2+r]=e>>>8&255,t[3+r]=255&e},e.ip=function(t,e,r,n){for(var i=0,o=0,s=6;s>=0;s-=2){for(var f=0;f<=24;f+=8)i<<=1,i|=e>>>f+s&1;for(f=0;f<=24;f+=8)i<<=1,i|=t>>>f+s&1}for(s=6;s>=0;s-=2){for(f=1;f<=25;f+=8)o<<=1,o|=e>>>f+s&1;for(f=1;f<=25;f+=8)o<<=1,o|=t>>>f+s&1}r[n+0]=i>>>0,r[n+1]=o>>>0},e.rip=function(t,e,r,n){for(var i=0,o=0,s=0;s<4;s++)for(var f=24;f>=0;f-=8)i<<=1,i|=e>>>f+s&1,i<<=1,i|=t>>>f+s&1;for(s=4;s<8;s++)for(f=24;f>=0;f-=8)o<<=1,o|=e>>>f+s&1,o<<=1,o|=t>>>f+s&1;r[n+0]=i>>>0,r[n+1]=o>>>0},e.pc1=function(t,e,r,n){for(var i=0,o=0,s=7;s>=5;s--){for(var f=0;f<=24;f+=8)i<<=1,i|=e>>f+s&1;for(f=0;f<=24;f+=8)i<<=1,i|=t>>f+s&1}for(f=0;f<=24;f+=8)i<<=1,i|=e>>f+s&1;for(s=1;s<=3;s++){for(f=0;f<=24;f+=8)o<<=1,o|=e>>f+s&1;for(f=0;f<=24;f+=8)o<<=1,o|=t>>f+s&1}for(f=0;f<=24;f+=8)o<<=1,o|=t>>f+s&1;r[n+0]=i>>>0,r[n+1]=o>>>0},e.r28shl=function(t,e){return t<<e&268435455|t>>>28-e};var r=[14,11,17,4,27,23,25,0,13,22,7,18,5,9,16,24,2,20,12,21,1,8,15,26,15,4,25,19,9,1,26,16,5,11,23,8,12,7,17,0,22,3,10,14,6,20,27,24];e.pc2=function(t,e,n,i){for(var o=0,s=0,f=r.length>>>1,u=0;u<f;u++)o<<=1,o|=t>>>r[u]&1;for(u=f;u<r.length;u++)s<<=1,s|=e>>>r[u]&1;n[i+0]=o>>>0,n[i+1]=s>>>0},e.expand=function(t,e,r){var n=0,i=0;n=(1&t)<<5|t>>>27;for(var o=23;o>=15;o-=4)n<<=6,n|=t>>>o&63;for(o=11;o>=3;o-=4)i|=t>>>o&63,i<<=6;i|=(31&t)<<1|t>>>31,e[r+0]=n>>>0,e[r+1]=i>>>0};var n=[14,0,4,15,13,7,1,4,2,14,15,2,11,13,8,1,3,10,10,6,6,12,12,11,5,9,9,5,0,3,7,8,4,15,1,12,14,8,8,2,13,4,6,9,2,1,11,7,15,5,12,11,9,3,7,14,3,10,10,0,5,6,0,13,15,3,1,13,8,4,14,7,6,15,11,2,3,8,4,14,9,12,7,0,2,1,13,10,12,6,0,9,5,11,10,5,0,13,14,8,7,10,11,1,10,3,4,15,13,4,1,2,5,11,8,6,12,7,6,12,9,0,3,5,2,14,15,9,10,13,0,7,9,0,14,9,6,3,3,4,15,6,5,10,1,2,13,8,12,5,7,14,11,12,4,11,2,15,8,1,13,1,6,10,4,13,9,0,8,6,15,9,3,8,0,7,11,4,1,15,2,14,12,3,5,11,10,5,14,2,7,12,7,13,13,8,14,11,3,5,0,6,6,15,9,0,10,3,1,4,2,7,8,2,5,12,11,1,12,10,4,14,15,9,10,3,6,15,9,0,0,6,12,10,11,1,7,13,13,8,15,9,1,4,3,5,14,11,5,12,2,7,8,2,4,14,2,14,12,11,4,2,1,12,7,4,10,7,11,13,6,1,8,5,5,0,3,15,15,10,13,3,0,9,14,8,9,6,4,11,2,8,1,12,11,7,10,1,13,14,7,2,8,13,15,6,9,15,12,0,5,9,6,10,3,4,0,5,14,3,12,10,1,15,10,4,15,2,9,7,2,12,6,9,8,5,0,6,13,1,3,13,4,14,14,0,7,11,5,3,11,8,9,4,14,3,15,2,5,12,2,9,8,5,12,15,3,10,7,11,0,14,4,1,10,7,1,6,13,0,11,8,6,13,4,13,11,0,2,11,14,7,15,4,0,9,8,1,13,10,3,14,12,3,9,5,7,12,5,2,10,15,6,8,1,6,1,6,4,11,11,13,13,8,12,1,3,4,7,10,14,7,10,9,15,5,6,0,8,15,0,14,5,2,9,3,2,12,13,1,2,15,8,13,4,8,6,10,15,3,11,7,1,4,10,12,9,5,3,6,14,11,5,0,0,14,12,9,7,2,7,2,11,1,4,14,1,7,9,4,12,10,14,8,2,13,0,15,6,12,10,9,13,0,15,3,3,5,5,6,8,11];e.substitute=function(t,e){for(var r=0,i=0;i<4;i++)r<<=4,r|=n[64*i+(t>>>18-6*i&63)];for(i=0;i<4;i++)r<<=4,r|=n[256+64*i+(e>>>18-6*i&63)];return r>>>0};var i=[16,25,12,11,3,20,4,15,31,17,9,6,27,14,1,22,30,24,8,18,0,5,29,23,13,19,2,26,10,21,28,7];e.permute=function(t){for(var e=0,r=0;r<i.length;r++)e<<=1,e|=t>>>i[r]&1;return e>>>0},e.padSplit=function(t,e,r){for(var n=t.toString(2);n.length<e;)n="0"+n;for(var i=[],o=0;o<e;o+=r)i.push(n.slice(o,o+r));return i.join(" ")}}}]);
@@ -1 +0,0 @@
1
- (this.webpackChunkNostrCryptoUtils=this.webpackChunkNostrCryptoUtils||[]).push([[446],{8300:(t,i,e)=>{"use strict";var n=e(8510),r=e(3039),s=e(1565);new class{constructor(){this.cryptoInstance=null,this.initPromise=this.initialize()}async initialize(){this.cryptoInstance=await(async()=>{if("undefined"!=typeof window)return{};if(void 0!==e.g)return{};try{const t=await Promise.resolve().then(e.t.bind(e,1565,19));if(t.webcrypto)return t.webcrypto}catch{r.vF.debug("Node crypto not available, falling back to crypto-browserify")}return s})()}async ensureInitialized(){if(await this.initPromise,!this.cryptoInstance)throw new Error("Crypto implementation not initialized");return this.cryptoInstance}async getSubtle(){return(await this.ensureInitialized()).subtle}async getRandomValues(t){return(await this.ensureInitialized()).getRandomValues(t)}},n.ko.sign,n.ko.verify},5684:(t,i,e)=>{"use strict";e(3491),e(4710),e(8300),e(3983),e(965),e(8287).Buffer,e(8287).Buffer,e(8287).Buffer,e(1565).default,e(7916),e(3117)},8982:()=>{},7790:()=>{},1638:()=>{},2668:()=>{},7965:()=>{},6089:()=>{},9368:()=>{},4688:()=>{},1069:()=>{},3779:()=>{},7199:()=>{}}]);
@@ -1 +0,0 @@
1
- !function(E,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.NostrCryptoUtils=e():(E.NostrCryptoUtils=E.NostrCryptoUtils||{},E.NostrCryptoUtils["main-7bd12dde"]=e())}(this,(()=>(()=>{"use strict";var E,e,t,r={3983:(E,e,t)=>{t(6354)},6354:(E,e,t)=>{var r,T;!function(E){E[E.SET_METADATA=0]="SET_METADATA",E[E.TEXT_NOTE=1]="TEXT_NOTE",E[E.RECOMMEND_SERVER=2]="RECOMMEND_SERVER",E[E.CONTACTS=3]="CONTACTS",E[E.ENCRYPTED_DIRECT_MESSAGE=4]="ENCRYPTED_DIRECT_MESSAGE",E[E.EVENT_DELETION=5]="EVENT_DELETION",E[E.REACTION=7]="REACTION",E[E.CHANNEL_CREATE=40]="CHANNEL_CREATE",E[E.CHANNEL_METADATA=41]="CHANNEL_METADATA",E[E.CHANNEL_MESSAGE=42]="CHANNEL_MESSAGE",E[E.CHANNEL_HIDE_MESSAGE=43]="CHANNEL_HIDE_MESSAGE",E[E.CHANNEL_MUTE_USER=44]="CHANNEL_MUTE_USER",E[E.AUTH=22242]="AUTH",E[E.AUTH_RESPONSE=22243]="AUTH_RESPONSE"}(r||(r={})),function(E){E.EVENT="EVENT",E.REQ="REQ",E.CLOSE="CLOSE",E.NOTICE="NOTICE",E.EOSE="EOSE",E.OK="OK",E.AUTH="AUTH",E.ERROR="ERROR",E.COUNT="COUNT"}(T||(T={}))},3491:(E,e,t)=>{var r;t(6354),function(E){E[E.SET_METADATA=0]="SET_METADATA",E[E.TEXT_NOTE=1]="TEXT_NOTE",E[E.RECOMMEND_SERVER=2]="RECOMMEND_SERVER",E[E.CONTACT_LIST=3]="CONTACT_LIST",E[E.ENCRYPTED_DIRECT_MESSAGE=4]="ENCRYPTED_DIRECT_MESSAGE",E[E.DELETE=5]="DELETE",E[E.REPOST=6]="REPOST",E[E.REACTION=7]="REACTION",E[E.BADGE_AWARD=8]="BADGE_AWARD",E[E.CHANNEL_CREATE=40]="CHANNEL_CREATE",E[E.CHANNEL_METADATA=41]="CHANNEL_METADATA",E[E.CHANNEL_MESSAGE=42]="CHANNEL_MESSAGE",E[E.CHANNEL_HIDE_MESSAGE=43]="CHANNEL_HIDE_MESSAGE",E[E.CHANNEL_MUTE_USER=44]="CHANNEL_MUTE_USER",E[E.CHANNEL_RESERVE=45]="CHANNEL_RESERVE",E[E.REPORTING=1984]="REPORTING",E[E.ZAP_REQUEST=9734]="ZAP_REQUEST",E[E.ZAP=9735]="ZAP",E[E.MUTE_LIST=1e4]="MUTE_LIST",E[E.PIN_LIST=10001]="PIN_LIST",E[E.RELAY_LIST_METADATA=10002]="RELAY_LIST_METADATA",E[E.CLIENT_AUTH=22242]="CLIENT_AUTH",E[E.NOSTR_CONNECT=24133]="NOSTR_CONNECT",E[E.CATEGORIZED_PEOPLE=3e4]="CATEGORIZED_PEOPLE",E[E.CATEGORIZED_BOOKMARKS=30001]="CATEGORIZED_BOOKMARKS",E[E.PROFILE_BADGES=30008]="PROFILE_BADGES",E[E.BADGE_DEFINITION=30009]="BADGE_DEFINITION",E[E.LONG_FORM=30023]="LONG_FORM",E[E.APPLICATION_SPECIFIC=30078]="APPLICATION_SPECIFIC"}(r||(r={}))},3039:(E,e,t)=>{t.d(e,{vF:()=>A});var r=t(4874),T=t.n(r),o=t(5606);const A=T()({name:"nostr-crypto-utils",level:o.env.LOG_LEVEL||"info",transport:void 0,formatters:{level:E=>({level:E.toUpperCase()}),log:E=>{if(E&&"object"==typeof E&&"err"in E){const e={...E};if(e.err instanceof Error){const E=e.err;e.err={message:E.message,stack:E.stack,name:E.name}}return e}return E}}})},965:(E,e,t)=>{t(3491),t(3039)}},T={};function o(E){var e=T[E];if(void 0!==e)return e.exports;var t=T[E]={id:E,loaded:!1,exports:{}};return r[E].call(t.exports,t,t.exports,o),t.loaded=!0,t.exports}o.m=r,E=[],o.O=(e,t,r,T)=>{if(!t){var A=1/0;for(O=0;O<E.length;O++){for(var[t,r,T]=E[O],N=!0,_=0;_<t.length;_++)(!1&T||A>=T)&&Object.keys(o.O).every((E=>o.O[E](t[_])))?t.splice(_--,1):(N=!1,T<A&&(A=T));if(N){E.splice(O--,1);var n=r();void 0!==n&&(e=n)}}return e}T=T||0;for(var O=E.length;O>0&&E[O-1][2]>T;O--)E[O]=E[O-1];E[O]=[t,r,T]},o.n=E=>{var e=E&&E.__esModule?()=>E.default:()=>E;return o.d(e,{a:e}),e},t=Object.getPrototypeOf?E=>Object.getPrototypeOf(E):E=>E.__proto__,o.t=function(E,r){if(1&r&&(E=this(E)),8&r)return E;if("object"==typeof E&&E){if(4&r&&E.__esModule)return E;if(16&r&&"function"==typeof E.then)return E}var T=Object.create(null);o.r(T);var A={};e=e||[null,t({}),t([]),t(t)];for(var N=2&r&&E;"object"==typeof N&&!~e.indexOf(N);N=t(N))Object.getOwnPropertyNames(N).forEach((e=>A[e]=()=>E[e]));return A.default=()=>E,o.d(T,A),T},o.d=(E,e)=>{for(var t in e)o.o(e,t)&&!o.o(E,t)&&Object.defineProperty(E,t,{enumerable:!0,get:e[t]})},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(E){if("object"==typeof window)return window}}(),o.o=(E,e)=>Object.prototype.hasOwnProperty.call(E,e),o.r=E=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(E,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(E,"__esModule",{value:!0})},o.nmd=E=>(E.paths=[],E.children||(E.children=[]),E),(()=>{var E={208:0,967:0};o.O.j=e=>0===E[e];var e=(e,t)=>{var r,T,[A,N,_]=t,n=0;if(A.some((e=>0!==E[e]))){for(r in N)o.o(N,r)&&(o.m[r]=N[r]);if(_)var O=_(o)}for(e&&e(t);n<A.length;n++)T=A[n],o.o(E,T)&&E[T]&&E[T][0](),E[T]=0;return o.O(O)},t=this.webpackChunkNostrCryptoUtils=this.webpackChunkNostrCryptoUtils||[];t.forEach(e.bind(null,0)),t.push=e.bind(null,t.push.bind(t))})();var A=o.O(void 0,[851,344,404,156,503,636,69,801,995,473,26,128,54,490,430,657,158,761,510,705,774,985,509,802,310,829,890,551,668,446,682],(()=>o(5684)));return(A=o.O(A)).default})()));
@@ -1 +0,0 @@
1
- "use strict";(this.webpackChunkNostrCryptoUtils=this.webpackChunkNostrCryptoUtils||[]).push([[682],{3117:(t,i,e)=>{e(7916),e(3039),e(4710),e(8300),e(8287).Buffer},4710:(t,i,e)=>{var n=e(3039),r=e(1565);new class{constructor(){this.cryptoInstance=null,this.initPromise=this.initialize()}async initialize(){this.cryptoInstance=await(async()=>{if("undefined"!=typeof window)return{};if(void 0!==e.g)return{};try{const t=await Promise.resolve().then(e.t.bind(e,1565,19));if(t.webcrypto)return t.webcrypto}catch{n.vF.debug("Node crypto not available, falling back to crypto-browserify")}return r})()}async ensureInitialized(){if(await this.initPromise,!this.cryptoInstance)throw new Error("Crypto implementation not initialized");return this.cryptoInstance}async getSubtle(){return(await this.ensureInitialized()).subtle}async getRandomValues(t){return(await this.ensureInitialized()).getRandomValues(t)}}},7916:(t,i,e)=>{e(2343),e(8287)}}]);