@nostrify/nostrify 0.46.6 → 0.46.8

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 (154) hide show
  1. package/.turbo/turbo-build.log +28 -5
  2. package/.turbo/turbo-setup.log +13 -0
  3. package/.turbo/turbo-test.log +123 -0
  4. package/BunkerURI.test.ts +19 -14
  5. package/CHANGELOG.md +16 -0
  6. package/NBrowserSigner.test.ts +49 -34
  7. package/NCache.test.ts +14 -7
  8. package/NCache.ts +2 -2
  9. package/NConnectSigner.test.ts +48 -31
  10. package/NConnectSigner.ts +3 -4
  11. package/NIP05.test.ts +36 -44
  12. package/NIP05.ts +2 -3
  13. package/NIP50.test.ts +35 -34
  14. package/NIP98.test.ts +89 -76
  15. package/NIP98.ts +2 -2
  16. package/NKinds.test.ts +37 -36
  17. package/NPool.test.ts +35 -24
  18. package/NPool.ts +42 -23
  19. package/NRelay1.test.ts +100 -68
  20. package/NRelay1.ts +13 -6
  21. package/NSchema.test.ts +98 -56
  22. package/NSchema.ts +10 -15
  23. package/NSecSigner.test.ts +19 -10
  24. package/NSecSigner.ts +4 -3
  25. package/NSet.test.ts +123 -50
  26. package/NSet.ts +13 -6
  27. package/RelayError.test.ts +11 -10
  28. package/RelayError.ts +1 -1
  29. package/dist/BunkerURI.js +44 -44
  30. package/dist/NBrowserSigner.js +73 -83
  31. package/dist/NCache.d.ts +2 -2
  32. package/dist/NCache.d.ts.map +1 -1
  33. package/dist/NCache.js +35 -56
  34. package/dist/NConnectSigner.d.ts +1 -1
  35. package/dist/NConnectSigner.d.ts.map +1 -1
  36. package/dist/NConnectSigner.js +124 -118
  37. package/dist/NIP05.d.ts +1 -1
  38. package/dist/NIP05.d.ts.map +1 -1
  39. package/dist/NIP05.js +33 -34
  40. package/dist/NIP50.js +19 -20
  41. package/dist/NIP98.d.ts +1 -1
  42. package/dist/NIP98.d.ts.map +1 -1
  43. package/dist/NIP98.js +71 -64
  44. package/dist/NKinds.js +24 -22
  45. package/dist/NPool.d.ts +2 -2
  46. package/dist/NPool.d.ts.map +1 -1
  47. package/dist/NPool.js +143 -170
  48. package/dist/NRelay1.d.ts +5 -4
  49. package/dist/NRelay1.d.ts.map +1 -1
  50. package/dist/NRelay1.js +301 -315
  51. package/dist/NSchema.d.ts +1 -1
  52. package/dist/NSchema.d.ts.map +1 -1
  53. package/dist/NSchema.js +185 -209
  54. package/dist/NSecSigner.d.ts +1 -2
  55. package/dist/NSecSigner.d.ts.map +1 -1
  56. package/dist/NSecSigner.js +35 -46
  57. package/dist/NSet.d.ts +1 -1
  58. package/dist/NSet.d.ts.map +1 -1
  59. package/dist/NSet.js +138 -166
  60. package/dist/RelayError.d.ts +1 -1
  61. package/dist/RelayError.d.ts.map +1 -1
  62. package/dist/RelayError.js +18 -17
  63. package/dist/ln/LNURL.d.ts +4 -4
  64. package/dist/ln/LNURL.d.ts.map +1 -1
  65. package/dist/ln/LNURL.js +93 -93
  66. package/dist/ln/mod.d.ts +3 -3
  67. package/dist/ln/mod.js +4 -2
  68. package/dist/ln/mod.js.map +7 -1
  69. package/dist/ln/types/LNURLCallback.js +0 -2
  70. package/dist/ln/types/LNURLDetails.js +0 -2
  71. package/dist/mod.d.ts +14 -14
  72. package/dist/mod.js +30 -15
  73. package/dist/mod.js.map +7 -1
  74. package/dist/test/ErrorRelay.d.ts +1 -1
  75. package/dist/test/ErrorRelay.d.ts.map +1 -1
  76. package/dist/test/ErrorRelay.js +22 -21
  77. package/dist/test/MockRelay.d.ts +3 -3
  78. package/dist/test/MockRelay.d.ts.map +1 -1
  79. package/dist/test/MockRelay.js +56 -57
  80. package/dist/test/TestRelayServer.d.ts +6 -3
  81. package/dist/test/TestRelayServer.d.ts.map +1 -1
  82. package/dist/test/TestRelayServer.js +141 -122
  83. package/dist/test/mod.d.ts +3 -3
  84. package/dist/test/mod.d.ts.map +1 -1
  85. package/dist/test/mod.js +22 -19
  86. package/dist/test/mod.js.map +7 -1
  87. package/dist/tsconfig.tsbuildinfo +1 -1
  88. package/dist/uploaders/BlossomUploader.d.ts +1 -1
  89. package/dist/uploaders/BlossomUploader.d.ts.map +1 -1
  90. package/dist/uploaders/BlossomUploader.js +69 -66
  91. package/dist/uploaders/NostrBuildUploader.d.ts +1 -2
  92. package/dist/uploaders/NostrBuildUploader.d.ts.map +1 -1
  93. package/dist/uploaders/NostrBuildUploader.js +61 -59
  94. package/dist/uploaders/mod.d.ts +2 -2
  95. package/dist/uploaders/mod.js +6 -3
  96. package/dist/uploaders/mod.js.map +7 -1
  97. package/dist/utils/CircularSet.d.ts +1 -1
  98. package/dist/utils/CircularSet.d.ts.map +1 -1
  99. package/dist/utils/CircularSet.js +26 -28
  100. package/dist/utils/Machina.js +35 -59
  101. package/dist/utils/N64.d.ts +1 -1
  102. package/dist/utils/N64.d.ts.map +1 -1
  103. package/dist/utils/N64.js +16 -18
  104. package/dist/utils/mod.d.ts +2 -2
  105. package/dist/utils/mod.js +6 -3
  106. package/dist/utils/mod.js.map +7 -1
  107. package/ln/LNURL.test.ts +70 -52
  108. package/ln/LNURL.ts +15 -15
  109. package/ln/mod.ts +3 -3
  110. package/mod.ts +14 -14
  111. package/package.json +12 -3
  112. package/test/ErrorRelay.test.ts +11 -10
  113. package/test/ErrorRelay.ts +17 -5
  114. package/test/MockRelay.test.ts +15 -8
  115. package/test/MockRelay.ts +3 -3
  116. package/test/TestRelayServer.ts +47 -18
  117. package/test/mod.ts +4 -4
  118. package/tsconfig.json +5 -2
  119. package/uploaders/BlossomUploader.test.ts +39 -22
  120. package/uploaders/BlossomUploader.ts +2 -2
  121. package/uploaders/NostrBuildUploader.test.ts +36 -18
  122. package/uploaders/NostrBuildUploader.ts +4 -4
  123. package/uploaders/mod.ts +2 -2
  124. package/utils/CircularSet.test.ts +5 -4
  125. package/utils/CircularSet.ts +3 -1
  126. package/utils/Machina.test.ts +30 -19
  127. package/utils/N64.test.ts +12 -11
  128. package/utils/N64.ts +2 -2
  129. package/utils/mod.ts +2 -2
  130. package/dist/BunkerURI.js.map +0 -1
  131. package/dist/NBrowserSigner.js.map +0 -1
  132. package/dist/NCache.js.map +0 -1
  133. package/dist/NConnectSigner.js.map +0 -1
  134. package/dist/NIP05.js.map +0 -1
  135. package/dist/NIP50.js.map +0 -1
  136. package/dist/NIP98.js.map +0 -1
  137. package/dist/NKinds.js.map +0 -1
  138. package/dist/NPool.js.map +0 -1
  139. package/dist/NRelay1.js.map +0 -1
  140. package/dist/NSchema.js.map +0 -1
  141. package/dist/NSecSigner.js.map +0 -1
  142. package/dist/NSet.js.map +0 -1
  143. package/dist/RelayError.js.map +0 -1
  144. package/dist/ln/LNURL.js.map +0 -1
  145. package/dist/ln/types/LNURLCallback.js.map +0 -1
  146. package/dist/ln/types/LNURLDetails.js.map +0 -1
  147. package/dist/test/ErrorRelay.js.map +0 -1
  148. package/dist/test/MockRelay.js.map +0 -1
  149. package/dist/test/TestRelayServer.js.map +0 -1
  150. package/dist/uploaders/BlossomUploader.js.map +0 -1
  151. package/dist/uploaders/NostrBuildUploader.js.map +0 -1
  152. package/dist/utils/CircularSet.js.map +0 -1
  153. package/dist/utils/Machina.js.map +0 -1
  154. package/dist/utils/N64.js.map +0 -1
package/dist/NSet.js CHANGED
@@ -1,171 +1,143 @@
1
- /**
2
- * Nostr event implementation of the `Set` interface.
3
- *
4
- * NSet is an implementation of the theory that a Nostr Storage is actually just a Set.
5
- * Events are Nostr's only data type, and they are immutable, making the Set interface ideal.
6
- *
7
- * ```ts
8
- * const events = new NSet();
9
- *
10
- * // Events can be added like a regular `Set`:
11
- * events.add(event1);
12
- * events.add(event2);
13
- *
14
- * // Can be iterated:
15
- * for (const event of events) {
16
- * if (matchFilters(filters, event)) {
17
- * console.log(event);
18
- * }
19
- * }
20
- * ```
21
- *
22
- * `NSet` will handle kind `5` deletions, removing events from the set.
23
- * Replaceable (and parameterized) events will keep only the newest version.
24
- * However, verification of `id` and `sig` is NOT performed.
25
- *
26
- * Any `Map` instance can be passed into `new NSet()`, making it compatible with
27
- * [lru-cache](https://www.npmjs.com/package/lru-cache), among others.
28
- */
29
1
  class NSet {
30
- cache;
31
- constructor(map) {
32
- this.cache = map ?? new Map();
33
- }
34
- get size() {
35
- return this.cache.size;
36
- }
37
- add(event) {
38
- this.#processDeletions(event);
39
- for (const e of this) {
40
- if (NSet.deletes(e, event) || NSet.replaces(e, event)) {
41
- return this;
42
- }
43
- else if (NSet.replaces(event, e)) {
44
- this.delete(e);
45
- }
46
- }
47
- this.cache.set(event.id, event);
2
+ cache;
3
+ constructor(map) {
4
+ this.cache = map ?? /* @__PURE__ */ new Map();
5
+ }
6
+ get size() {
7
+ return this.cache.size;
8
+ }
9
+ add(event) {
10
+ this.#processDeletions(event);
11
+ for (const e of this) {
12
+ if (NSet.deletes(e, event) || NSet.replaces(e, event)) {
48
13
  return this;
49
- }
50
- #processDeletions(event) {
51
- if (event.kind === 5) {
52
- for (const tag of event.tags) {
53
- if (tag[0] === 'e') {
54
- const e = this.cache.get(tag[1]);
55
- if (e && e.pubkey === event.pubkey) {
56
- this.delete(e);
57
- }
58
- }
59
- }
14
+ } else if (NSet.replaces(event, e)) {
15
+ this.delete(e);
16
+ }
17
+ }
18
+ this.cache.set(event.id, event);
19
+ return this;
20
+ }
21
+ #processDeletions(event) {
22
+ if (event.kind === 5) {
23
+ for (const tag of event.tags) {
24
+ if (tag[0] === "e") {
25
+ const e = this.cache.get(tag[1]);
26
+ if (e && e.pubkey === event.pubkey) {
27
+ this.delete(e);
28
+ }
60
29
  }
61
- }
62
- clear() {
63
- this.cache.clear();
64
- }
65
- delete(event) {
66
- return this.cache.delete(event.id);
67
- }
68
- forEach(callbackfn, thisArg) {
69
- return this.cache.forEach((event, _id) => callbackfn(event, event, this), thisArg);
70
- }
71
- has(event) {
72
- return this.cache.has(event.id);
73
- }
74
- *entries() {
75
- for (const event of this.values()) {
76
- yield [event, event];
77
- }
78
- }
79
- keys() {
80
- return this.values();
81
- }
82
- *values() {
83
- for (const event of NSet.sortEvents([...this.cache.values()])) {
84
- yield event;
30
+ }
31
+ }
32
+ }
33
+ clear() {
34
+ this.cache.clear();
35
+ }
36
+ delete(event) {
37
+ return this.cache.delete(event.id);
38
+ }
39
+ forEach(callbackfn, thisArg) {
40
+ return this.cache.forEach(
41
+ (event, _id) => callbackfn(event, event, this),
42
+ thisArg
43
+ );
44
+ }
45
+ has(event) {
46
+ return this.cache.has(event.id);
47
+ }
48
+ *entries() {
49
+ for (const event of this.values()) {
50
+ yield [event, event];
51
+ }
52
+ }
53
+ keys() {
54
+ return this.values();
55
+ }
56
+ *values() {
57
+ for (const event of NSet.sortEvents([...this.cache.values()])) {
58
+ yield event;
59
+ }
60
+ }
61
+ [Symbol.iterator]() {
62
+ return this.values();
63
+ }
64
+ [Symbol.toStringTag] = "NSet";
65
+ /** Event kind is **replaceable**, which means that, for each combination of `pubkey` and `kind`, only the latest event is expected to (SHOULD) be stored by relays, older versions are expected to be discarded. */
66
+ static isReplaceable(kind) {
67
+ return [0, 3].includes(kind) || 1e4 <= kind && kind < 2e4;
68
+ }
69
+ /** Event kind is **parameterized replaceable**, which means that, for each combination of `pubkey`, `kind` and the `d` tag, only the latest event is expected to be stored by relays, older versions are expected to be discarded. */
70
+ static isAddressable(kind) {
71
+ return 3e4 <= kind && kind < 4e4;
72
+ }
73
+ /**
74
+ * Returns true if `event` replaces `target`.
75
+ *
76
+ * Both events must be replaceable, belong to the same kind and pubkey (and `d` tag, for parameterized events), and the `event` must be newer than the `target`.
77
+ */
78
+ static replaces(event, target) {
79
+ const { kind, pubkey } = event;
80
+ if (NSet.isReplaceable(kind)) {
81
+ return kind === target.kind && pubkey === target.pubkey && NSet.sortEvents([event, target])[0] === event;
82
+ }
83
+ if (NSet.isAddressable(kind)) {
84
+ const d1 = event.tags.find(([name]) => name === "d")?.[1] || "";
85
+ const d2 = target.tags.find(([name]) => name === "d")?.[1] || "";
86
+ return kind === target.kind && pubkey === target.pubkey && NSet.sortEvents([event, target])[0] === event && d1 === d2;
87
+ }
88
+ return false;
89
+ }
90
+ /**
91
+ * Returns true if the `event` deletes`target`.
92
+ *
93
+ * `event` must be a kind `5` event, and both events must share the same `pubkey`.
94
+ */
95
+ static deletes(event, target) {
96
+ const { kind, pubkey, tags } = event;
97
+ if (kind === 5 && pubkey === target.pubkey) {
98
+ for (const [name, value] of tags) {
99
+ if (name === "e" && value === target.id) {
100
+ return true;
85
101
  }
86
- }
87
- [Symbol.iterator]() {
88
- return this.values();
89
- }
90
- [Symbol.toStringTag] = 'NSet';
91
- /** Event kind is **replaceable**, which means that, for each combination of `pubkey` and `kind`, only the latest event is expected to (SHOULD) be stored by relays, older versions are expected to be discarded. */
92
- static isReplaceable(kind) {
93
- return [0, 3].includes(kind) || (10000 <= kind && kind < 20000);
94
- }
95
- /** Event kind is **parameterized replaceable**, which means that, for each combination of `pubkey`, `kind` and the `d` tag, only the latest event is expected to be stored by relays, older versions are expected to be discarded. */
96
- static isAddressable(kind) {
97
- return 30000 <= kind && kind < 40000;
98
- }
99
- /**
100
- * Returns true if `event` replaces `target`.
101
- *
102
- * Both events must be replaceable, belong to the same kind and pubkey (and `d` tag, for parameterized events), and the `event` must be newer than the `target`.
103
- */
104
- static replaces(event, target) {
105
- const { kind, pubkey } = event;
106
- if (NSet.isReplaceable(kind)) {
107
- return kind === target.kind && pubkey === target.pubkey && NSet.sortEvents([event, target])[0] === event;
108
- }
109
- if (NSet.isAddressable(kind)) {
110
- const d1 = event.tags.find(([name]) => name === 'd')?.[1] || '';
111
- const d2 = target.tags.find(([name]) => name === 'd')?.[1] || '';
112
- return kind === target.kind &&
113
- pubkey === target.pubkey &&
114
- NSet.sortEvents([event, target])[0] === event &&
115
- d1 === d2;
116
- }
117
- return false;
118
- }
119
- /**
120
- * Returns true if the `event` deletes`target`.
121
- *
122
- * `event` must be a kind `5` event, and both events must share the same `pubkey`.
123
- */
124
- static deletes(event, target) {
125
- const { kind, pubkey, tags } = event;
126
- if (kind === 5 && pubkey === target.pubkey) {
127
- for (const [name, value] of tags) {
128
- if (name === 'e' && value === target.id) {
129
- return true;
130
- }
131
- }
132
- }
133
- return false;
134
- }
135
- /**
136
- * Sort events in reverse-chronological order by the `created_at` timestamp,
137
- * and then by the event `id` (lexicographically) in case of ties.
138
- * This mutates the array.
139
- */
140
- static sortEvents(events) {
141
- return events.sort((a, b) => {
142
- if (a.created_at !== b.created_at) {
143
- return b.created_at - a.created_at;
144
- }
145
- return a.id.localeCompare(b.id);
146
- });
147
- }
148
- union(_other) {
149
- throw new Error('Method not implemented.');
150
- }
151
- intersection(_other) {
152
- throw new Error('Method not implemented.');
153
- }
154
- difference(_other) {
155
- throw new Error('Method not implemented.');
156
- }
157
- symmetricDifference(_other) {
158
- throw new Error('Method not implemented.');
159
- }
160
- isSubsetOf(_other) {
161
- throw new Error('Method not implemented.');
162
- }
163
- isSupersetOf(_other) {
164
- throw new Error('Method not implemented.');
165
- }
166
- isDisjointFrom(_other) {
167
- throw new Error('Method not implemented.');
168
- }
102
+ }
103
+ }
104
+ return false;
105
+ }
106
+ /**
107
+ * Sort events in reverse-chronological order by the `created_at` timestamp,
108
+ * and then by the event `id` (lexicographically) in case of ties.
109
+ * This mutates the array.
110
+ */
111
+ static sortEvents(events) {
112
+ return events.sort((a, b) => {
113
+ if (a.created_at !== b.created_at) {
114
+ return b.created_at - a.created_at;
115
+ }
116
+ return a.id.localeCompare(b.id);
117
+ });
118
+ }
119
+ union(_other) {
120
+ throw new Error("Method not implemented.");
121
+ }
122
+ intersection(_other) {
123
+ throw new Error("Method not implemented.");
124
+ }
125
+ difference(_other) {
126
+ throw new Error("Method not implemented.");
127
+ }
128
+ symmetricDifference(_other) {
129
+ throw new Error("Method not implemented.");
130
+ }
131
+ isSubsetOf(_other) {
132
+ throw new Error("Method not implemented.");
133
+ }
134
+ isSupersetOf(_other) {
135
+ throw new Error("Method not implemented.");
136
+ }
137
+ isDisjointFrom(_other) {
138
+ throw new Error("Method not implemented.");
139
+ }
169
140
  }
170
- export { NSet };
171
- //# sourceMappingURL=NSet.js.map
141
+ export {
142
+ NSet
143
+ };
@@ -1,4 +1,4 @@
1
- import { NostrRelayOK } from '@nostrify/nostrify';
1
+ import type { NostrRelayOK } from '@nostrify/types';
2
2
  /** NIP-01 command line result. */
3
3
  export declare class RelayError extends Error {
4
4
  constructor(prefix: string, message: string);
@@ -1 +1 @@
1
- {"version":3,"file":"RelayError.d.ts","sourceRoot":"","sources":["../RelayError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,kCAAkC;AAClC,qBAAa,UAAW,SAAQ,KAAK;gBACvB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAI3C,sDAAsD;IACtD,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU;IAK7C,yDAAyD;IACzD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI;CAMvC"}
1
+ {"version":3,"file":"RelayError.d.ts","sourceRoot":"","sources":["../RelayError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,kCAAkC;AAClC,qBAAa,UAAW,SAAQ,KAAK;gBACvB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAI3C,sDAAsD;IACtD,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU;IAK7C,yDAAyD;IACzD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI;CAMvC"}
@@ -1,19 +1,20 @@
1
- /** NIP-01 command line result. */
2
- export class RelayError extends Error {
3
- constructor(prefix, message) {
4
- super(`${prefix}: ${message}`);
5
- }
6
- /** Construct a RelayError from the reason message. */
7
- static fromReason(reason) {
8
- const [prefix, ...rest] = reason.split(': ');
9
- return new RelayError(prefix, rest.join(': '));
10
- }
11
- /** Throw a new RelayError if the OK message is false. */
12
- static assert(msg) {
13
- const [, , ok, reason] = msg;
14
- if (!ok) {
15
- throw RelayError.fromReason(reason);
16
- }
1
+ class RelayError extends Error {
2
+ constructor(prefix, message) {
3
+ super(`${prefix}: ${message}`);
4
+ }
5
+ /** Construct a RelayError from the reason message. */
6
+ static fromReason(reason) {
7
+ const [prefix, ...rest] = reason.split(": ");
8
+ return new RelayError(prefix, rest.join(": "));
9
+ }
10
+ /** Throw a new RelayError if the OK message is false. */
11
+ static assert(msg) {
12
+ const [, , ok, reason] = msg;
13
+ if (!ok) {
14
+ throw RelayError.fromReason(reason);
17
15
  }
16
+ }
18
17
  }
19
- //# sourceMappingURL=RelayError.js.map
18
+ export {
19
+ RelayError
20
+ };
@@ -1,7 +1,7 @@
1
- import { NostrEvent } from "@nostrify/types";
2
- import { LNURLCallback } from "./types/LNURLCallback.js";
3
- import { LNURLDetails } from "./types/LNURLDetails.js";
4
- import { z } from "../NSchema.js";
1
+ import type { NostrEvent } from '@nostrify/types';
2
+ import { LNURLCallback } from './types/LNURLCallback.ts';
3
+ import { LNURLDetails } from './types/LNURLDetails.ts';
4
+ import { z } from '../NSchema.ts';
5
5
  /**
6
6
  * Represents an LNURL, with methods to fetch details and generate invoices.
7
7
  */
@@ -1 +1 @@
1
- {"version":3,"file":"LNURL.d.ts","sourceRoot":"","sources":["../../ln/LNURL.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAAgB,CAAC,EAAE,MAAM,eAAe,CAAC;AAEhD;;GAEG;AACH,qBAAa,KAAK;IAChB,0CAA0C;IAC1C,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,+CAA+C;IAC/C,OAAO,CAAC,KAAK,CAA0B;;IAGrC,0CAA0C;IAC1C,GAAG,EAAE,GAAG;IACR,mCAAmC;IACnC,I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-1,101 +1,101 @@
1
1
  import { bech32 } from "@scure/base";
2
2
  import { NSchema as n, z } from "../NSchema.js";
3
- /**
4
- * Represents an LNURL, with methods to fetch details and generate invoices.
5
- */
6
- export class LNURL {
7
- /** Underlying HTTP(s) URL of the user. */
8
- url;
9
- /** Fetch function to use for HTTP requests. */
10
- fetch;
11
- constructor(
12
- /** Underlying HTTP(s) URL of the user. */
13
- url,
14
- /** Options for the LNURL class. */
15
- opts) {
16
- this.url = url;
17
- this.fetch = opts?.fetch ?? globalThis.fetch.bind(globalThis);
3
+ class LNURL {
4
+ /** Underlying HTTP(s) URL of the user. */
5
+ url;
6
+ /** Fetch function to use for HTTP requests. */
7
+ fetch;
8
+ constructor(url, opts) {
9
+ this.url = url;
10
+ this.fetch = opts?.fetch ?? globalThis.fetch.bind(globalThis);
11
+ }
12
+ /**
13
+ * Create an LNURL object from a bech32 `lnurl1...` string.
14
+ * Throws if the value is not a valid lnurl.
15
+ */
16
+ static fromString(value, opts) {
17
+ if (!n.bech32().safeParse(value).success) {
18
+ throw new Error('Expected a bech32 string starting with "lnurl1"');
18
19
  }
19
- /**
20
- * Create an LNURL object from a bech32 `lnurl1...` string.
21
- * Throws if the value is not a valid lnurl.
22
- */
23
- static fromString(value, opts) {
24
- if (!n.bech32().safeParse(value).success) {
25
- throw new Error('Expected a bech32 string starting with "lnurl1"');
26
- }
27
- const { prefix, words } = bech32.decode(value, 20000);
28
- if (prefix !== "lnurl") {
29
- throw new Error('Expected a bech32 string starting with "lnurl1"');
30
- }
31
- const data = bech32.fromWords(words);
32
- const url = new URL(new TextDecoder().decode(data));
33
- return new LNURL(url, opts);
20
+ const { prefix, words } = bech32.decode(
21
+ value,
22
+ 2e4
23
+ );
24
+ if (prefix !== "lnurl") {
25
+ throw new Error('Expected a bech32 string starting with "lnurl1"');
34
26
  }
35
- /**
36
- * Create an LNURL object from a lightning address (email-like format).
37
- * Throws if the value is not a valid lightning address.
38
- */
39
- static fromLightningAddress(ln, opts) {
40
- if (!z.string().email().safeParse(ln).success) {
41
- throw new Error('Expected a lightning address in email-like format (eg "example@getalby.com")');
42
- }
43
- const [name, host] = ln.split("@");
44
- const url = new URL(`/.well-known/lnurlp/${name}`, `https://${host}`);
45
- return new LNURL(url, opts);
27
+ const data = bech32.fromWords(words);
28
+ const url = new URL(new TextDecoder().decode(data));
29
+ return new LNURL(url, opts);
30
+ }
31
+ /**
32
+ * Create an LNURL object from a lightning address (email-like format).
33
+ * Throws if the value is not a valid lightning address.
34
+ */
35
+ static fromLightningAddress(ln, opts) {
36
+ if (!z.string().email().safeParse(ln).success) {
37
+ throw new Error(
38
+ 'Expected a lightning address in email-like format (eg "example@getalby.com")'
39
+ );
46
40
  }
47
- /** Returns the LNURL object as a bech32-encoded `lnurl1...` string. */
48
- toString() {
49
- const data = new TextEncoder().encode(this.url.toString());
50
- const words = bech32.toWords(data);
51
- return bech32.encode("lnurl", words, 20000);
41
+ const [name, host] = ln.split("@");
42
+ const url = new URL(`/.well-known/lnurlp/${name}`, `https://${host}`);
43
+ return new LNURL(url, opts);
44
+ }
45
+ /** Returns the LNURL object as a bech32-encoded `lnurl1...` string. */
46
+ toString() {
47
+ const data = new TextEncoder().encode(this.url.toString());
48
+ const words = bech32.toWords(data);
49
+ return bech32.encode("lnurl", words, 2e4);
50
+ }
51
+ /** Resolve an LNURL to its details. */
52
+ async getDetails(opts) {
53
+ const response = await this.fetch(this.url, opts);
54
+ const json = await response.json();
55
+ return LNURL.lnurlDetailsSchema().parse(json);
56
+ }
57
+ /** Generate an LNURL invoice from the params. */
58
+ async getInvoice(opts) {
59
+ const details = await this.getDetails(opts);
60
+ const callback = new URL(details.callback);
61
+ callback.searchParams.set("amount", opts.amount.toString());
62
+ callback.searchParams.set("lnurl", this.toString());
63
+ if (opts.nostr) {
64
+ callback.searchParams.set("nostr", JSON.stringify(opts.nostr));
52
65
  }
53
- /** Resolve an LNURL to its details. */
54
- async getDetails(opts) {
55
- const response = await this.fetch(this.url, opts);
56
- const json = await response.json();
57
- return LNURL.lnurlDetailsSchema().parse(json);
58
- }
59
- /** Generate an LNURL invoice from the params. */
60
- async getInvoice(opts) {
61
- const details = await this.getDetails(opts);
62
- const callback = new URL(details.callback);
63
- callback.searchParams.set("amount", opts.amount.toString());
64
- callback.searchParams.set("lnurl", this.toString());
65
- if (opts.nostr) {
66
- callback.searchParams.set("nostr", JSON.stringify(opts.nostr));
67
- }
68
- const response = await this.fetch(callback, opts);
69
- const json = await response.json();
70
- return LNURL.lnurlCallbackSchema().parse(json);
71
- }
72
- /** LNURL response schema. */
73
- static lnurlDetailsSchema() {
74
- return z.object({
75
- allowsNostr: z.boolean().optional(),
76
- callback: z.string().url(),
77
- commentAllowed: z.number().nonnegative().int().optional(),
78
- maxSendable: z.number().positive().int(),
79
- minSendable: z.number().positive().int(),
80
- metadata: z.string(),
81
- nostrPubkey: n.id().optional(),
82
- tag: z.literal("payRequest"),
83
- }).superRefine((details, ctx) => {
84
- if (details.minSendable > details.maxSendable) {
85
- ctx.addIssue({
86
- code: z.ZodIssueCode.custom,
87
- message: "minSendable must be less than or equal to maxSendable",
88
- path: ["minSendable"],
89
- });
90
- }
66
+ const response = await this.fetch(callback, opts);
67
+ const json = await response.json();
68
+ return LNURL.lnurlCallbackSchema().parse(json);
69
+ }
70
+ /** LNURL response schema. */
71
+ static lnurlDetailsSchema() {
72
+ return z.object({
73
+ allowsNostr: z.boolean().optional(),
74
+ callback: z.string().url(),
75
+ commentAllowed: z.number().nonnegative().int().optional(),
76
+ maxSendable: z.number().positive().int(),
77
+ minSendable: z.number().positive().int(),
78
+ metadata: z.string(),
79
+ nostrPubkey: n.id().optional(),
80
+ tag: z.literal("payRequest")
81
+ }).superRefine((details, ctx) => {
82
+ if (details.minSendable > details.maxSendable) {
83
+ ctx.addIssue({
84
+ code: z.ZodIssueCode.custom,
85
+ message: "minSendable must be less than or equal to maxSendable",
86
+ path: ["minSendable"]
91
87
  });
92
- }
93
- /** LNURL callback schema. */
94
- static lnurlCallbackSchema() {
95
- return z.object({
96
- pr: n.bech32("lnbc"),
97
- routes: z.tuple([]),
98
- });
99
- }
88
+ }
89
+ });
90
+ }
91
+ /** LNURL callback schema. */
92
+ static lnurlCallbackSchema() {
93
+ return z.object({
94
+ pr: n.bech32("lnbc"),
95
+ routes: z.tuple([])
96
+ });
97
+ }
100
98
  }
101
- //# sourceMappingURL=LNURL.js.map
99
+ export {
100
+ LNURL
101
+ };
package/dist/ln/mod.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { LNURL } from './LNURL.js';
2
- export type { LNURLCallback } from './types/LNURLCallback.js';
3
- export type { LNURLDetails } from './types/LNURLDetails.js';
1
+ export { LNURL } from './LNURL.ts';
2
+ export type { LNURLCallback } from './types/LNURLCallback.ts';
3
+ export type { LNURLDetails } from './types/LNURLDetails.ts';
4
4
  //# sourceMappingURL=mod.d.ts.map
package/dist/ln/mod.js CHANGED
@@ -1,2 +1,4 @@
1
- export { LNURL } from './LNURL.js';
2
- //# sourceMappingURL=mod.js.map
1
+ import { LNURL } from "./LNURL.js";
2
+ export {
3
+ LNURL
4
+ };
@@ -1 +1,7 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../ln/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../ln/mod.ts"],
4
+ "sourcesContent": ["export { LNURL } from './LNURL.ts';\n\nexport type { LNURLCallback } from './types/LNURLCallback.ts';\nexport type { LNURLDetails } from './types/LNURLDetails.ts';\n"],
5
+ "mappings": ";AAAA,SAAS,aAAa;",
6
+ "names": []
7
+ }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=LNURLCallback.js.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=LNURLDetails.js.map
package/dist/mod.d.ts CHANGED
@@ -1,16 +1,16 @@
1
- export { BunkerURI } from './BunkerURI.js';
2
- export { NBrowserSigner } from './NBrowserSigner.js';
3
- export { NCache } from './NCache.js';
4
- export { NConnectSigner, type NConnectSignerOpts } from './NConnectSigner.js';
5
- export { NIP05 } from './NIP05.js';
6
- export { NIP50 } from './NIP50.js';
7
- export { NIP98 } from './NIP98.js';
8
- export { NKinds } from './NKinds.js';
9
- export { NPool, type NPoolOpts } from './NPool.js';
10
- export { NRelay1, type NRelay1Opts } from './NRelay1.js';
11
- export { NSchema } from './NSchema.js';
12
- export { NSecSigner } from './NSecSigner.js';
13
- export { NSet } from './NSet.js';
14
- export { RelayError } from './RelayError.js';
1
+ export { BunkerURI } from './BunkerURI.ts';
2
+ export { NBrowserSigner } from './NBrowserSigner.ts';
3
+ export { NCache } from './NCache.ts';
4
+ export { NConnectSigner, type NConnectSignerOpts } from './NConnectSigner.ts';
5
+ export { NIP05 } from './NIP05.ts';
6
+ export { NIP50 } from './NIP50.ts';
7
+ export { NIP98 } from './NIP98.ts';
8
+ export { NKinds } from './NKinds.ts';
9
+ export { NPool, type NPoolOpts } from './NPool.ts';
10
+ export { NRelay1, type NRelay1Opts } from './NRelay1.ts';
11
+ export { NSchema } from './NSchema.ts';
12
+ export { NSecSigner } from './NSecSigner.ts';
13
+ export { NSet } from './NSet.ts';
14
+ export { RelayError } from './RelayError.ts';
15
15
  export type * from '@nostrify/types';
16
16
  //# sourceMappingURL=mod.d.ts.map