@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.
- package/.turbo/turbo-build.log +28 -5
- package/.turbo/turbo-setup.log +13 -0
- package/.turbo/turbo-test.log +123 -0
- package/BunkerURI.test.ts +19 -14
- package/CHANGELOG.md +16 -0
- package/NBrowserSigner.test.ts +49 -34
- package/NCache.test.ts +14 -7
- package/NCache.ts +2 -2
- package/NConnectSigner.test.ts +48 -31
- package/NConnectSigner.ts +3 -4
- package/NIP05.test.ts +36 -44
- package/NIP05.ts +2 -3
- package/NIP50.test.ts +35 -34
- package/NIP98.test.ts +89 -76
- package/NIP98.ts +2 -2
- package/NKinds.test.ts +37 -36
- package/NPool.test.ts +35 -24
- package/NPool.ts +42 -23
- package/NRelay1.test.ts +100 -68
- package/NRelay1.ts +13 -6
- package/NSchema.test.ts +98 -56
- package/NSchema.ts +10 -15
- package/NSecSigner.test.ts +19 -10
- package/NSecSigner.ts +4 -3
- package/NSet.test.ts +123 -50
- package/NSet.ts +13 -6
- package/RelayError.test.ts +11 -10
- package/RelayError.ts +1 -1
- package/dist/BunkerURI.js +44 -44
- package/dist/NBrowserSigner.js +73 -83
- package/dist/NCache.d.ts +2 -2
- package/dist/NCache.d.ts.map +1 -1
- package/dist/NCache.js +35 -56
- package/dist/NConnectSigner.d.ts +1 -1
- package/dist/NConnectSigner.d.ts.map +1 -1
- package/dist/NConnectSigner.js +124 -118
- package/dist/NIP05.d.ts +1 -1
- package/dist/NIP05.d.ts.map +1 -1
- package/dist/NIP05.js +33 -34
- package/dist/NIP50.js +19 -20
- package/dist/NIP98.d.ts +1 -1
- package/dist/NIP98.d.ts.map +1 -1
- package/dist/NIP98.js +71 -64
- package/dist/NKinds.js +24 -22
- package/dist/NPool.d.ts +2 -2
- package/dist/NPool.d.ts.map +1 -1
- package/dist/NPool.js +143 -170
- package/dist/NRelay1.d.ts +5 -4
- package/dist/NRelay1.d.ts.map +1 -1
- package/dist/NRelay1.js +301 -315
- package/dist/NSchema.d.ts +1 -1
- package/dist/NSchema.d.ts.map +1 -1
- package/dist/NSchema.js +185 -209
- package/dist/NSecSigner.d.ts +1 -2
- package/dist/NSecSigner.d.ts.map +1 -1
- package/dist/NSecSigner.js +35 -46
- package/dist/NSet.d.ts +1 -1
- package/dist/NSet.d.ts.map +1 -1
- package/dist/NSet.js +138 -166
- package/dist/RelayError.d.ts +1 -1
- package/dist/RelayError.d.ts.map +1 -1
- package/dist/RelayError.js +18 -17
- package/dist/ln/LNURL.d.ts +4 -4
- package/dist/ln/LNURL.d.ts.map +1 -1
- package/dist/ln/LNURL.js +93 -93
- package/dist/ln/mod.d.ts +3 -3
- package/dist/ln/mod.js +4 -2
- package/dist/ln/mod.js.map +7 -1
- package/dist/ln/types/LNURLCallback.js +0 -2
- package/dist/ln/types/LNURLDetails.js +0 -2
- package/dist/mod.d.ts +14 -14
- package/dist/mod.js +30 -15
- package/dist/mod.js.map +7 -1
- package/dist/test/ErrorRelay.d.ts +1 -1
- package/dist/test/ErrorRelay.d.ts.map +1 -1
- package/dist/test/ErrorRelay.js +22 -21
- package/dist/test/MockRelay.d.ts +3 -3
- package/dist/test/MockRelay.d.ts.map +1 -1
- package/dist/test/MockRelay.js +56 -57
- package/dist/test/TestRelayServer.d.ts +6 -3
- package/dist/test/TestRelayServer.d.ts.map +1 -1
- package/dist/test/TestRelayServer.js +141 -122
- package/dist/test/mod.d.ts +3 -3
- package/dist/test/mod.d.ts.map +1 -1
- package/dist/test/mod.js +22 -19
- package/dist/test/mod.js.map +7 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/uploaders/BlossomUploader.d.ts +1 -1
- package/dist/uploaders/BlossomUploader.d.ts.map +1 -1
- package/dist/uploaders/BlossomUploader.js +69 -66
- package/dist/uploaders/NostrBuildUploader.d.ts +1 -2
- package/dist/uploaders/NostrBuildUploader.d.ts.map +1 -1
- package/dist/uploaders/NostrBuildUploader.js +61 -59
- package/dist/uploaders/mod.d.ts +2 -2
- package/dist/uploaders/mod.js +6 -3
- package/dist/uploaders/mod.js.map +7 -1
- package/dist/utils/CircularSet.d.ts +1 -1
- package/dist/utils/CircularSet.d.ts.map +1 -1
- package/dist/utils/CircularSet.js +26 -28
- package/dist/utils/Machina.js +35 -59
- package/dist/utils/N64.d.ts +1 -1
- package/dist/utils/N64.d.ts.map +1 -1
- package/dist/utils/N64.js +16 -18
- package/dist/utils/mod.d.ts +2 -2
- package/dist/utils/mod.js +6 -3
- package/dist/utils/mod.js.map +7 -1
- package/ln/LNURL.test.ts +70 -52
- package/ln/LNURL.ts +15 -15
- package/ln/mod.ts +3 -3
- package/mod.ts +14 -14
- package/package.json +12 -3
- package/test/ErrorRelay.test.ts +11 -10
- package/test/ErrorRelay.ts +17 -5
- package/test/MockRelay.test.ts +15 -8
- package/test/MockRelay.ts +3 -3
- package/test/TestRelayServer.ts +47 -18
- package/test/mod.ts +4 -4
- package/tsconfig.json +5 -2
- package/uploaders/BlossomUploader.test.ts +39 -22
- package/uploaders/BlossomUploader.ts +2 -2
- package/uploaders/NostrBuildUploader.test.ts +36 -18
- package/uploaders/NostrBuildUploader.ts +4 -4
- package/uploaders/mod.ts +2 -2
- package/utils/CircularSet.test.ts +5 -4
- package/utils/CircularSet.ts +3 -1
- package/utils/Machina.test.ts +30 -19
- package/utils/N64.test.ts +12 -11
- package/utils/N64.ts +2 -2
- package/utils/mod.ts +2 -2
- package/dist/BunkerURI.js.map +0 -1
- package/dist/NBrowserSigner.js.map +0 -1
- package/dist/NCache.js.map +0 -1
- package/dist/NConnectSigner.js.map +0 -1
- package/dist/NIP05.js.map +0 -1
- package/dist/NIP50.js.map +0 -1
- package/dist/NIP98.js.map +0 -1
- package/dist/NKinds.js.map +0 -1
- package/dist/NPool.js.map +0 -1
- package/dist/NRelay1.js.map +0 -1
- package/dist/NSchema.js.map +0 -1
- package/dist/NSecSigner.js.map +0 -1
- package/dist/NSet.js.map +0 -1
- package/dist/RelayError.js.map +0 -1
- package/dist/ln/LNURL.js.map +0 -1
- package/dist/ln/types/LNURLCallback.js.map +0 -1
- package/dist/ln/types/LNURLDetails.js.map +0 -1
- package/dist/test/ErrorRelay.js.map +0 -1
- package/dist/test/MockRelay.js.map +0 -1
- package/dist/test/TestRelayServer.js.map +0 -1
- package/dist/uploaders/BlossomUploader.js.map +0 -1
- package/dist/uploaders/NostrBuildUploader.js.map +0 -1
- package/dist/utils/CircularSet.js.map +0 -1
- package/dist/utils/Machina.js.map +0 -1
- 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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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 {
|
|
171
|
-
|
|
141
|
+
export {
|
|
142
|
+
NSet
|
|
143
|
+
};
|
package/dist/RelayError.d.ts
CHANGED
package/dist/RelayError.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelayError.d.ts","sourceRoot":"","sources":["../RelayError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
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"}
|
package/dist/RelayError.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
18
|
+
export {
|
|
19
|
+
RelayError
|
|
20
|
+
};
|
package/dist/ln/LNURL.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { NostrEvent } from
|
|
2
|
-
import { LNURLCallback } from
|
|
3
|
-
import { LNURLDetails } from
|
|
4
|
-
import { z } from
|
|
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
|
*/
|
package/dist/ln/LNURL.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LNURL.d.ts","sourceRoot":"","sources":["../../ln/LNURL.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"LNURL.d.ts","sourceRoot":"","sources":["../../ln/LNURL.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,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,IAAI,CAAC,EAAE;QACL,+CAA+C;QAC/C,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;KAChC;IAMH;;;OAGG;IACH,MAAM,CAAC,UAAU,CACf,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE;QAAE,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;KAAE,GACxC,KAAK;IAoBR;;;OAGG;IACH,MAAM,CAAC,oBAAoB,CACzB,EAAE,EAAE,MAAM,EACV,IAAI,CAAC,EAAE;QAAE,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;KAAE,GACxC,KAAK;IAaR,uEAAuE;IACvE,QAAQ,IAAI,SAAS,MAAM,EAAE;IAM7B,uCAAuC;IACjC,UAAU,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,CAAC;IAMxE,iDAAiD;IAC3C,UAAU,CAAC,IAAI,EAAE;QACrB,mDAAmD;QACnD,MAAM,EAAE,MAAM,CAAC;QACf,4CAA4C;QAC5C,KAAK,CAAC,EAAE,UAAU,CAAC;QACnB,mCAAmC;QACnC,MAAM,CAAC,EAAE,WAAW,CAAC;KACtB,GAAG,OAAO,CAAC,aAAa,CAAC;IAiB1B,6BAA6B;IAC7B,MAAM,CAAC,kBAAkB,IAAI,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IAqBpD,6BAA6B;IAC7B,MAAM,CAAC,mBAAmB,IAAI,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;CAMvD"}
|
package/dist/ln/LNURL.js
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
1
1
|
import { bech32 } from "@scure/base";
|
|
2
2
|
import { NSchema as n, z } from "../NSchema.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
fetch;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
99
|
+
export {
|
|
100
|
+
LNURL
|
|
101
|
+
};
|
package/dist/ln/mod.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { LNURL } from './LNURL.
|
|
2
|
-
export type { LNURLCallback } from './types/LNURLCallback.
|
|
3
|
-
export type { LNURLDetails } from './types/LNURLDetails.
|
|
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
package/dist/ln/mod.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
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
|
+
}
|
package/dist/mod.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export { BunkerURI } from './BunkerURI.
|
|
2
|
-
export { NBrowserSigner } from './NBrowserSigner.
|
|
3
|
-
export { NCache } from './NCache.
|
|
4
|
-
export { NConnectSigner, type NConnectSignerOpts } from './NConnectSigner.
|
|
5
|
-
export { NIP05 } from './NIP05.
|
|
6
|
-
export { NIP50 } from './NIP50.
|
|
7
|
-
export { NIP98 } from './NIP98.
|
|
8
|
-
export { NKinds } from './NKinds.
|
|
9
|
-
export { NPool, type NPoolOpts } from './NPool.
|
|
10
|
-
export { NRelay1, type NRelay1Opts } from './NRelay1.
|
|
11
|
-
export { NSchema } from './NSchema.
|
|
12
|
-
export { NSecSigner } from './NSecSigner.
|
|
13
|
-
export { NSet } from './NSet.
|
|
14
|
-
export { RelayError } from './RelayError.
|
|
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
|