@nostrify/nostrify 0.49.0 → 0.49.2
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 +3 -3
- package/.turbo/turbo-test.log +113 -112
- package/.turbo/turbo-typecheck.log +1 -1
- package/CHANGELOG.md +12 -0
- package/NSchema.ts +50 -84
- package/dist/NSchema.d.ts +189 -23
- package/dist/NSchema.d.ts.map +1 -1
- package/dist/NSchema.js +11 -11
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @nostrify/nostrify@0.
|
|
2
|
+
> @nostrify/nostrify@0.49.1 build /home/alex/Projects/nostrify/packages/nostrify
|
|
3
3
|
> npx tsc -p tsconfig.json && node ../../esbuild.config.js --package ./
|
|
4
4
|
|
|
5
5
|
npm warn Unknown env config "verify-deps-before-run". This will stop working in the next major version of npm.
|
|
@@ -7,7 +7,7 @@ npm warn Unknown env config "_jsr-registry". This will stop working in the next
|
|
|
7
7
|
Building with esbuild...
|
|
8
8
|
|
|
9
9
|
dist/NRelay1.js 8.9kb
|
|
10
|
-
dist/NSchema.js 5.
|
|
10
|
+
dist/NSchema.js 5.7kb
|
|
11
11
|
dist/NPool.js 5.4kb
|
|
12
12
|
dist/test/TestRelayServer.js 4.4kb
|
|
13
13
|
dist/NSet.js 4.1kb
|
|
@@ -28,5 +28,5 @@ Building with esbuild...
|
|
|
28
28
|
dist/test/mod.js 701b
|
|
29
29
|
...and 11 more output files...
|
|
30
30
|
|
|
31
|
-
⚡ Done in
|
|
31
|
+
⚡ Done in 15ms
|
|
32
32
|
Done!
|
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,112 +1,113 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
✔ BunkerURI
|
|
7
|
-
✔
|
|
8
|
-
✔ NBrowserSigner -
|
|
9
|
-
✔ NBrowserSigner
|
|
10
|
-
✔ NBrowserSigner.
|
|
11
|
-
✔ NBrowserSigner.
|
|
12
|
-
✔ NBrowserSigner -
|
|
13
|
-
✔ NBrowserSigner - missing
|
|
14
|
-
✔ NBrowserSigner -
|
|
15
|
-
✔
|
|
16
|
-
✔
|
|
17
|
-
✔ NConnectSigner.signEvent with
|
|
18
|
-
✔
|
|
19
|
-
✔ NIP05.lookup
|
|
20
|
-
✔ NIP05.lookup with invalid
|
|
21
|
-
✔
|
|
22
|
-
✔ NIP50.parseInput
|
|
23
|
-
✔
|
|
24
|
-
✔ NIP98.template
|
|
25
|
-
✔ NIP98.
|
|
26
|
-
✔ NIP98.verify
|
|
27
|
-
✔ NIP98.verify fails with missing
|
|
28
|
-
✔ NIP98.verify fails with
|
|
29
|
-
✔ NIP98.verify fails with invalid
|
|
30
|
-
✔ NIP98.verify fails with
|
|
31
|
-
✔ NIP98.verify fails with wrong
|
|
32
|
-
✔ NIP98.verify fails with wrong request
|
|
33
|
-
✔ NIP98.verify fails with
|
|
34
|
-
✔ NIP98.verify fails with
|
|
35
|
-
✔
|
|
36
|
-
✔ NIP98Client.fetch -
|
|
37
|
-
✔ NIP98Client.fetch -
|
|
38
|
-
✔ NIP98Client.fetch - with
|
|
39
|
-
✔ NIP98Client.fetch -
|
|
40
|
-
✔ NIP98Client.fetch -
|
|
41
|
-
✔ NIP98Client.fetch -
|
|
42
|
-
✔ NIP98Client.fetch -
|
|
43
|
-
✔
|
|
44
|
-
✔
|
|
45
|
-
✔ NPool.
|
|
46
|
-
✔ NPool.
|
|
47
|
-
✔ NPool.
|
|
48
|
-
✔ NPool.query with eoseTimeout
|
|
49
|
-
✔
|
|
50
|
-
✔ NRelay1.query
|
|
51
|
-
✔ NRelay1.
|
|
52
|
-
✔ NRelay1.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
✔ websocket
|
|
57
|
-
✔ websocket
|
|
58
|
-
✔
|
|
59
|
-
✔ NRelay1
|
|
60
|
-
✔ NRelay1
|
|
61
|
-
✔
|
|
62
|
-
✔ n.
|
|
63
|
-
✔ n.
|
|
64
|
-
✔ n.
|
|
65
|
-
✔ n.
|
|
66
|
-
✔
|
|
67
|
-
✔ NSecSigner
|
|
68
|
-
✔
|
|
69
|
-
✔ NSet
|
|
70
|
-
✔ NSet.add (
|
|
71
|
-
✔ NSet.add (
|
|
72
|
-
✔
|
|
73
|
-
✔
|
|
74
|
-
✔
|
|
75
|
-
✔ LNURL.
|
|
76
|
-
✔ LNURL.
|
|
77
|
-
✔ LNURL.
|
|
78
|
-
✔ LNURL.
|
|
79
|
-
✔
|
|
80
|
-
✔
|
|
81
|
-
✔
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
✔
|
|
85
|
-
✔
|
|
86
|
-
✔
|
|
87
|
-
✔
|
|
88
|
-
✔
|
|
89
|
-
✔
|
|
90
|
-
✔
|
|
91
|
-
✔ N64
|
|
92
|
-
✔ N64.
|
|
93
|
-
|
|
94
|
-
ℹ
|
|
95
|
-
ℹ
|
|
96
|
-
ℹ
|
|
97
|
-
ℹ
|
|
98
|
-
ℹ
|
|
99
|
-
ℹ
|
|
100
|
-
ℹ
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
at
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @nostrify/nostrify@0.49.1 test /home/alex/Projects/nostrify/packages/nostrify
|
|
4
|
+
> node --test "**/*.test.ts"
|
|
5
|
+
|
|
6
|
+
[32m✔ BunkerURI [90m(2.855929ms)[39m[39m
|
|
7
|
+
[32m✔ BunkerURI.fromJSON [90m(0.647302ms)[39m[39m
|
|
8
|
+
[32m✔ NBrowserSigner - without extension [90m(5.614283ms)[39m[39m
|
|
9
|
+
[32m✔ NBrowserSigner - with extension polyfill [90m(162.64428ms)[39m[39m
|
|
10
|
+
[32m✔ NBrowserSigner.nip44 - with extension polyfill [90m(35.751206ms)[39m[39m
|
|
11
|
+
[32m✔ NBrowserSigner.nip04 - with extension polyfill [90m(24.897688ms)[39m[39m
|
|
12
|
+
[32m✔ NBrowserSigner.getRelays - with extension polyfill [90m(1.639964ms)[39m[39m
|
|
13
|
+
[32m✔ NBrowserSigner - missing nip44 support [90m(0.681486ms)[39m[39m
|
|
14
|
+
[32m✔ NBrowserSigner - missing nip04 support [90m(0.334181ms)[39m[39m
|
|
15
|
+
[32m✔ NBrowserSigner - feature detection [90m(2.345656ms)[39m[39m
|
|
16
|
+
[32m✔ NCache [90m(4.846063ms)[39m[39m
|
|
17
|
+
[32m✔ NConnectSigner.signEvent with nip04 encryption [90m(284.998411ms)[39m[39m
|
|
18
|
+
[32m✔ NConnectSigner.signEvent with nip44 encryption [90m(79.574293ms)[39m[39m
|
|
19
|
+
[32m✔ NIP05.lookup [90m(94.266524ms)[39m[39m
|
|
20
|
+
[32m✔ NIP05.lookup with invalid values but valid profile pointer [90m(6.109077ms)[39m[39m
|
|
21
|
+
[32m✔ NIP05.lookup with invalid document [90m(7.362813ms)[39m[39m
|
|
22
|
+
[32m✔ NIP50.parseInput [90m(6.692668ms)[39m[39m
|
|
23
|
+
[32m✔ NIP50.parseInput with negated token [90m(0.459908ms)[39m[39m
|
|
24
|
+
[32m✔ NIP98.template [90m(7.800118ms)[39m[39m
|
|
25
|
+
[32m✔ NIP98.template with payload [90m(57.504461ms)[39m[39m
|
|
26
|
+
[32m✔ NIP98.verify [90m(167.402989ms)[39m[39m
|
|
27
|
+
[32m✔ NIP98.verify fails with missing header [90m(1.462579ms)[39m[39m
|
|
28
|
+
[32m✔ NIP98.verify fails with missing token [90m(1.026357ms)[39m[39m
|
|
29
|
+
[32m✔ NIP98.verify fails with invalid token [90m(1.318398ms)[39m[39m
|
|
30
|
+
[32m✔ NIP98.verify fails with invalid event [90m(15.517318ms)[39m[39m
|
|
31
|
+
[32m✔ NIP98.verify fails with wrong event kind [90m(15.461533ms)[39m[39m
|
|
32
|
+
[32m✔ NIP98.verify fails with wrong request URL [90m(12.774894ms)[39m[39m
|
|
33
|
+
[32m✔ NIP98.verify fails with wrong request method [90m(15.755518ms)[39m[39m
|
|
34
|
+
[32m✔ NIP98.verify fails with expired event [90m(11.549622ms)[39m[39m
|
|
35
|
+
[32m✔ NIP98.verify fails with invalid payload [90m(25.108065ms)[39m[39m
|
|
36
|
+
[32m✔ NIP98Client.fetch - basic GET request [90m(152.34065ms)[39m[39m
|
|
37
|
+
[32m✔ NIP98Client.fetch - POST request with body [90m(48.046766ms)[39m[39m
|
|
38
|
+
[32m✔ NIP98Client.fetch - with Request object input [90m(22.539248ms)[39m[39m
|
|
39
|
+
[32m✔ NIP98Client.fetch - with URL object input [90m(14.907818ms)[39m[39m
|
|
40
|
+
[32m✔ NIP98Client.fetch - uses default fetch when not provided [90m(11.87691ms)[39m[39m
|
|
41
|
+
[32m✔ NIP98Client.fetch - preserves existing headers [90m(16.091842ms)[39m[39m
|
|
42
|
+
[32m✔ NIP98Client.fetch - event can be verified with NIP98.verify [90m(20.434596ms)[39m[39m
|
|
43
|
+
[32m✔ NIP98Client.fetch - handles different HTTP methods [90m(54.082414ms)[39m[39m
|
|
44
|
+
[32m✔ NKinds [90m(5.032997ms)[39m[39m
|
|
45
|
+
[32m✔ NPool.query [90m(378.702333ms)[39m[39m
|
|
46
|
+
[32m✔ NPool.req [90m(77.556426ms)[39m[39m
|
|
47
|
+
[32m✔ NPool.event [90m(32.572729ms)[39m[39m
|
|
48
|
+
[32m✔ NPool.query with eoseTimeout [90m(559.204759ms)[39m[39m
|
|
49
|
+
[32m✔ NPool.query with eoseTimeout disabled [90m(519.68897ms)[39m[39m
|
|
50
|
+
[32m✔ NRelay1.query [90m(226.319484ms)[39m[39m
|
|
51
|
+
[32m✔ NRelay1.query mismatched filter [90m(27.633319ms)[39m[39m
|
|
52
|
+
[32m✔ NRelay1.req [90m(66.241496ms)[39m[39m
|
|
53
|
+
[32m✔ NRelay1.event [90m(12.452346ms)[39m[39m
|
|
54
|
+
[90m﹣ NRelay1 backoff [90m(0.21217ms)[39m # SKIP[39m
|
|
55
|
+
▶ NRelay1 idleTimeout
|
|
56
|
+
[32m✔ websocket opens [90m(2.256778ms)[39m[39m
|
|
57
|
+
[32m✔ websocket closes after idleTimeout [90m(150.482082ms)[39m[39m
|
|
58
|
+
[32m✔ websocket wakes up during activity [90m(17.379211ms)[39m[39m
|
|
59
|
+
[32m✔ NRelay1 idleTimeout [90m(173.173788ms)[39m[39m
|
|
60
|
+
[32m✔ NRelay1.count rejects when the server sends CLOSED [90m(7.752588ms)[39m[39m
|
|
61
|
+
[32m✔ NRelay1 closes when it receives a binary message [90m(5.304398ms)[39m[39m
|
|
62
|
+
[32m✔ n.id [90m(11.977479ms)[39m[39m
|
|
63
|
+
[32m✔ n.bech32 [90m(4.31372ms)[39m[39m
|
|
64
|
+
[32m✔ n.filter [90m(83.609146ms)[39m[39m
|
|
65
|
+
[32m✔ n.event [90m(39.732538ms)[39m[39m
|
|
66
|
+
[32m✔ n.metadata [90m(67.78575ms)[39m[39m
|
|
67
|
+
[32m✔ NSecSigner [90m(134.833466ms)[39m[39m
|
|
68
|
+
[32m✔ NSecSigner.nip44 [90m(39.725124ms)[39m[39m
|
|
69
|
+
[32m✔ NSet [90m(26.167433ms)[39m[39m
|
|
70
|
+
[32m✔ NSet.add (replaceable) [90m(0.555688ms)[39m[39m
|
|
71
|
+
[32m✔ NSet.add (parameterized) [90m(0.859632ms)[39m[39m
|
|
72
|
+
[32m✔ NSet.add (deletion) [90m(0.659384ms)[39m[39m
|
|
73
|
+
[32m✔ Construct a RelayError from the reason message [90m(2.48014ms)[39m[39m
|
|
74
|
+
[32m✔ Throw a new RelayError if the OK message is false [90m(0.480627ms)[39m[39m
|
|
75
|
+
[32m✔ LNURL.fromString [90m(7.853168ms)[39m[39m
|
|
76
|
+
[32m✔ LNURL.fromLightningAddress [90m(1.565174ms)[39m[39m
|
|
77
|
+
[32m✔ LNURL.toString [90m(1.207389ms)[39m[39m
|
|
78
|
+
[32m✔ LNURL.getDetails [90m(61.890516ms)[39m[39m
|
|
79
|
+
[32m✔ LNURL.getInvoice [90m(12.594574ms)[39m[39m
|
|
80
|
+
[32m✔ ErrorRelay [90m(89.704386ms)[39m[39m
|
|
81
|
+
[32m✔ MockRelay [90m(5.643569ms)[39m[39m
|
|
82
|
+
[32m✔ BlossomUploader.upload [90m(685.760126ms)[39m[39m
|
|
83
|
+
[31m✖ NostrBuildUploader.upload [90m(25.389164ms)[39m[39m
|
|
84
|
+
[32m✔ CircularSet [90m(2.759166ms)[39m[39m
|
|
85
|
+
[32m✔ push, iterate, & close [90m(103.744176ms)[39m[39m
|
|
86
|
+
[32m✔ close & reopen [90m(0.695512ms)[39m[39m
|
|
87
|
+
[32m✔ aborts with signal [90m(51.384223ms)[39m[39m
|
|
88
|
+
[32m✔ already aborted signal in constructor [90m(0.622785ms)[39m[39m
|
|
89
|
+
[32m✔ push after abort [90m(0.654174ms)[39m[39m
|
|
90
|
+
[32m✔ multiple messages in queue [90m(0.316858ms)[39m[39m
|
|
91
|
+
[32m✔ N64 [90m(18.170805ms)[39m[39m
|
|
92
|
+
[32m✔ N64.encodeEvent [90m(0.414843ms)[39m[39m
|
|
93
|
+
[32m✔ N64.decodeEvent [90m(4.505341ms)[39m[39m
|
|
94
|
+
[34mℹ tests 87[39m
|
|
95
|
+
[34mℹ suites 0[39m
|
|
96
|
+
[34mℹ pass 85[39m
|
|
97
|
+
[34mℹ fail 1[39m
|
|
98
|
+
[34mℹ cancelled 0[39m
|
|
99
|
+
[34mℹ skipped 1[39m
|
|
100
|
+
[34mℹ todo 0[39m
|
|
101
|
+
[34mℹ duration_ms 3425.548766[39m
|
|
102
|
+
|
|
103
|
+
[31m✖ failing tests:[39m
|
|
104
|
+
|
|
105
|
+
test at uploaders/NostrBuildUploader.test.ts:12:7
|
|
106
|
+
[31m✖ NostrBuildUploader.upload [90m(25.389164ms)[39m[39m
|
|
107
|
+
Error: nostr.build with default uploader requires a secret key to be configured
|
|
108
|
+
at TestContext.<anonymous> [90m(file:///home/alex/Projects/nostrify/packages/nostrify/[39muploaders/NostrBuildUploader.test.ts:25:13[90m)[39m
|
|
109
|
+
[90m at process.processTicksAndRejections (node:internal/process/task_queues:104:5)[39m
|
|
110
|
+
[90m at async Test.run (node:internal/test_runner/test:1102:7)[39m
|
|
111
|
+
[90m at async startSubtestAfterBootstrap (node:internal/test_runner/harness:358:3)[39m
|
|
112
|
+
at async [90mfile:///home/alex/Projects/nostrify/packages/nostrify/[39muploaders/NostrBuildUploader.test.ts:12:1
|
|
113
|
+
[41m[30m ELIFECYCLE [39m[49m [31mTest failed. See above for more details.[39m
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @nostrify/nostrify@0.
|
|
2
|
+
> @nostrify/nostrify@0.49.1 typecheck /home/alex/Projects/nostrify/packages/nostrify
|
|
3
3
|
> npx tsc --noEmit
|
|
4
4
|
|
|
5
5
|
npm warn Unknown env config "verify-deps-before-run". This will stop working in the next major version of npm.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.49.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Simplify NSchema by removing explicit zod type annotations and leveraging type inference
|
|
8
|
+
|
|
9
|
+
## 0.49.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Upgrade zod dependency from v3 to v4
|
|
14
|
+
|
|
3
15
|
## 0.49.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/NSchema.ts
CHANGED
|
@@ -1,26 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
NostrClientAUTH,
|
|
5
|
-
NostrClientCLOSE,
|
|
6
|
-
NostrClientCOUNT,
|
|
7
|
-
NostrClientEVENT,
|
|
8
|
-
NostrClientMsg,
|
|
9
|
-
NostrClientREQ,
|
|
10
|
-
NostrConnectRequest,
|
|
11
|
-
NostrConnectResponse,
|
|
12
|
-
NostrEvent,
|
|
13
|
-
NostrFilter,
|
|
14
|
-
NostrMetadata,
|
|
15
|
-
NostrRelayAUTH,
|
|
16
|
-
NostrRelayCLOSED,
|
|
17
|
-
NostrRelayCOUNT,
|
|
18
|
-
NostrRelayEOSE,
|
|
19
|
-
NostrRelayEVENT,
|
|
20
|
-
NostrRelayMsg,
|
|
21
|
-
NostrRelayNOTICE,
|
|
22
|
-
NostrRelayOK,
|
|
23
|
-
} from "@nostrify/types";
|
|
3
|
+
import type { NostrFilter } from "@nostrify/types";
|
|
24
4
|
|
|
25
5
|
/**
|
|
26
6
|
* A suite of [zod](https://github.com/colinhacks/zod) schemas for Nostr.
|
|
@@ -36,12 +16,12 @@ import type {
|
|
|
36
16
|
*/
|
|
37
17
|
class NSchema {
|
|
38
18
|
/** Schema to validate Nostr hex IDs such as event IDs and pubkeys. */
|
|
39
|
-
static id()
|
|
19
|
+
static id() {
|
|
40
20
|
return z.string().regex(/^[0-9a-f]{64}$/);
|
|
41
21
|
}
|
|
42
22
|
|
|
43
23
|
/** Nostr event schema. */
|
|
44
|
-
static event()
|
|
24
|
+
static event() {
|
|
45
25
|
return z.object({
|
|
46
26
|
id: NSchema.id(),
|
|
47
27
|
kind: z.number().int().nonnegative(),
|
|
@@ -58,12 +38,12 @@ class NSchema {
|
|
|
58
38
|
content: true,
|
|
59
39
|
created_at: true,
|
|
60
40
|
sig: true,
|
|
61
|
-
})
|
|
41
|
+
});
|
|
62
42
|
}
|
|
63
43
|
|
|
64
44
|
/** Nostr filter schema. */
|
|
65
|
-
static filter()
|
|
66
|
-
return z.
|
|
45
|
+
static filter() {
|
|
46
|
+
return z.looseObject({
|
|
67
47
|
kinds: z.number().int().nonnegative().array().optional(),
|
|
68
48
|
ids: NSchema.id().array().optional(),
|
|
69
49
|
authors: NSchema.id().array().optional(),
|
|
@@ -72,7 +52,6 @@ class NSchema {
|
|
|
72
52
|
limit: z.number().int().nonnegative().optional(),
|
|
73
53
|
search: z.string().optional(),
|
|
74
54
|
})
|
|
75
|
-
.passthrough()
|
|
76
55
|
.transform((value) => {
|
|
77
56
|
const keys = [
|
|
78
57
|
"kinds",
|
|
@@ -89,129 +68,116 @@ class NSchema {
|
|
|
89
68
|
}
|
|
90
69
|
return acc;
|
|
91
70
|
}, {} as Record<string, unknown>) as NostrFilter;
|
|
92
|
-
})
|
|
71
|
+
});
|
|
93
72
|
}
|
|
94
73
|
|
|
95
74
|
/**
|
|
96
75
|
* Bech32 string.
|
|
97
76
|
* @see https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#bech32
|
|
98
77
|
*/
|
|
99
|
-
static bech32<P extends string>(prefix?: P)
|
|
78
|
+
static bech32<P extends string>(prefix?: P) {
|
|
100
79
|
return z
|
|
101
80
|
.string()
|
|
102
81
|
.regex(/^[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}$/)
|
|
103
82
|
.refine((value) =>
|
|
104
83
|
prefix ? value.startsWith(`${prefix}1`) : true
|
|
105
|
-
)
|
|
84
|
+
);
|
|
106
85
|
}
|
|
107
86
|
|
|
108
87
|
/** WebSocket URL starting with `ws://` or `wss://`. */
|
|
109
|
-
static relayUrl()
|
|
88
|
+
static relayUrl() {
|
|
110
89
|
return z
|
|
111
|
-
.string()
|
|
112
90
|
.url()
|
|
113
|
-
.regex(/^wss?:\/\//)
|
|
91
|
+
.regex(/^wss?:\/\//);
|
|
114
92
|
}
|
|
115
93
|
|
|
116
94
|
/** NIP-01 `EVENT` message from client to relay. */
|
|
117
|
-
static clientEVENT()
|
|
95
|
+
static clientEVENT() {
|
|
118
96
|
return z.tuple([
|
|
119
97
|
z.literal("EVENT"),
|
|
120
98
|
NSchema.event(),
|
|
121
|
-
])
|
|
122
|
-
NostrClientEVENT
|
|
123
|
-
>;
|
|
99
|
+
]);
|
|
124
100
|
}
|
|
125
101
|
|
|
126
102
|
/** NIP-01 `REQ` message from client to relay. */
|
|
127
|
-
static clientREQ()
|
|
103
|
+
static clientREQ() {
|
|
128
104
|
return z.tuple([z.literal("REQ"), z.string()]).rest(NSchema.filter());
|
|
129
105
|
}
|
|
130
106
|
|
|
131
107
|
/** NIP-45 `COUNT` message from client to relay. */
|
|
132
|
-
static clientCOUNT()
|
|
108
|
+
static clientCOUNT() {
|
|
133
109
|
return z.tuple([z.literal("COUNT"), z.string()]).rest(NSchema.filter());
|
|
134
110
|
}
|
|
135
111
|
|
|
136
112
|
/** NIP-01 `CLOSE` message from client to relay. */
|
|
137
|
-
static clientCLOSE()
|
|
138
|
-
return z.tuple([z.literal("CLOSE"), z.string()])
|
|
139
|
-
NostrClientCLOSE
|
|
140
|
-
>;
|
|
113
|
+
static clientCLOSE() {
|
|
114
|
+
return z.tuple([z.literal("CLOSE"), z.string()]);
|
|
141
115
|
}
|
|
142
116
|
|
|
143
117
|
/** NIP-42 `AUTH` message from client to relay. */
|
|
144
|
-
static clientAUTH()
|
|
118
|
+
static clientAUTH() {
|
|
145
119
|
return z.tuple([
|
|
146
120
|
z.literal("AUTH"),
|
|
147
121
|
NSchema.event(),
|
|
148
|
-
])
|
|
149
|
-
NostrClientAUTH
|
|
150
|
-
>;
|
|
122
|
+
]);
|
|
151
123
|
}
|
|
152
124
|
|
|
153
125
|
/** NIP-01 message from client to relay. */
|
|
154
|
-
static clientMsg()
|
|
126
|
+
static clientMsg() {
|
|
155
127
|
return z.union([
|
|
156
128
|
NSchema.clientEVENT(),
|
|
157
129
|
NSchema.clientREQ(),
|
|
158
130
|
NSchema.clientCOUNT(),
|
|
159
131
|
NSchema.clientCLOSE(),
|
|
160
132
|
NSchema.clientAUTH(),
|
|
161
|
-
])
|
|
133
|
+
]);
|
|
162
134
|
}
|
|
163
135
|
|
|
164
136
|
/** NIP-01 `EVENT` message from relay to client. */
|
|
165
|
-
static relayEVENT()
|
|
137
|
+
static relayEVENT() {
|
|
166
138
|
return z.tuple([
|
|
167
139
|
z.literal("EVENT"),
|
|
168
140
|
z.string(),
|
|
169
141
|
NSchema.event(),
|
|
170
|
-
])
|
|
142
|
+
]);
|
|
171
143
|
}
|
|
172
144
|
|
|
173
145
|
/** NIP-01 `OK` message from relay to client. */
|
|
174
|
-
static relayOK()
|
|
146
|
+
static relayOK() {
|
|
175
147
|
return z.tuple([
|
|
176
148
|
z.literal("OK"),
|
|
177
149
|
NSchema.id(),
|
|
178
150
|
z.boolean(),
|
|
179
151
|
z.string(),
|
|
180
|
-
])
|
|
152
|
+
]);
|
|
181
153
|
}
|
|
182
154
|
|
|
183
155
|
/** NIP-01 `EOSE` message from relay to client. */
|
|
184
|
-
static relayEOSE()
|
|
185
|
-
return z.tuple([z.literal("EOSE"), z.string()])
|
|
186
|
-
NostrRelayEOSE
|
|
187
|
-
>;
|
|
156
|
+
static relayEOSE() {
|
|
157
|
+
return z.tuple([z.literal("EOSE"), z.string()]);
|
|
188
158
|
}
|
|
189
159
|
|
|
190
160
|
/** NIP-01 `NOTICE` message from relay to client. */
|
|
191
|
-
static relayNOTICE()
|
|
192
|
-
return z.tuple([z.literal("NOTICE"), z.string()])
|
|
193
|
-
NostrRelayNOTICE
|
|
194
|
-
>;
|
|
161
|
+
static relayNOTICE() {
|
|
162
|
+
return z.tuple([z.literal("NOTICE"), z.string()]);
|
|
195
163
|
}
|
|
196
164
|
|
|
197
165
|
/** NIP-01 `CLOSED` message from relay to client. */
|
|
198
|
-
static relayCLOSED()
|
|
166
|
+
static relayCLOSED() {
|
|
199
167
|
return z.tuple([
|
|
200
168
|
z.literal("CLOSED"),
|
|
201
169
|
z.string(),
|
|
202
170
|
z.string(),
|
|
203
|
-
])
|
|
171
|
+
]);
|
|
204
172
|
}
|
|
205
173
|
|
|
206
174
|
/** NIP-42 `AUTH` message from relay to client. */
|
|
207
|
-
static relayAUTH()
|
|
208
|
-
return z.tuple([z.literal("AUTH"), z.string()])
|
|
209
|
-
NostrRelayAUTH
|
|
210
|
-
>;
|
|
175
|
+
static relayAUTH() {
|
|
176
|
+
return z.tuple([z.literal("AUTH"), z.string()]);
|
|
211
177
|
}
|
|
212
178
|
|
|
213
179
|
/** NIP-45 `COUNT` message from relay to client. */
|
|
214
|
-
static relayCOUNT()
|
|
180
|
+
static relayCOUNT() {
|
|
215
181
|
return z.tuple([
|
|
216
182
|
z.literal("COUNT"),
|
|
217
183
|
z.string(),
|
|
@@ -219,11 +185,11 @@ class NSchema {
|
|
|
219
185
|
count: z.number().int().nonnegative(),
|
|
220
186
|
approximate: z.boolean().optional(),
|
|
221
187
|
}),
|
|
222
|
-
])
|
|
188
|
+
]);
|
|
223
189
|
}
|
|
224
190
|
|
|
225
191
|
/** NIP-01 message from relay to client. */
|
|
226
|
-
static relayMsg()
|
|
192
|
+
static relayMsg() {
|
|
227
193
|
return z.union([
|
|
228
194
|
NSchema.relayEVENT(),
|
|
229
195
|
NSchema.relayOK(),
|
|
@@ -236,37 +202,37 @@ class NSchema {
|
|
|
236
202
|
}
|
|
237
203
|
|
|
238
204
|
/** Kind 0 content schema. */
|
|
239
|
-
static metadata()
|
|
240
|
-
return z.
|
|
205
|
+
static metadata() {
|
|
206
|
+
return z.looseObject({
|
|
241
207
|
about: z.string().optional().catch(undefined),
|
|
242
|
-
banner: z.
|
|
208
|
+
banner: z.url().optional().catch(undefined),
|
|
243
209
|
bot: z.boolean().optional().catch(undefined),
|
|
244
210
|
display_name: z.string().optional().catch(undefined),
|
|
245
211
|
lud06: NSchema.bech32("lnurl").optional().catch(undefined),
|
|
246
|
-
lud16: z.
|
|
212
|
+
lud16: z.email().optional().catch(undefined),
|
|
247
213
|
name: z.string().optional().catch(undefined),
|
|
248
|
-
nip05: z.
|
|
249
|
-
picture: z.
|
|
250
|
-
website: z.
|
|
251
|
-
})
|
|
214
|
+
nip05: z.email().optional().catch(undefined),
|
|
215
|
+
picture: z.url().optional().catch(undefined),
|
|
216
|
+
website: z.url().optional().catch(undefined),
|
|
217
|
+
});
|
|
252
218
|
}
|
|
253
219
|
|
|
254
220
|
/** NIP-46 request content schema. */
|
|
255
|
-
static connectRequest()
|
|
221
|
+
static connectRequest() {
|
|
256
222
|
return z.object({
|
|
257
223
|
id: z.string(),
|
|
258
224
|
method: z.string(),
|
|
259
225
|
params: z.string().array(),
|
|
260
|
-
})
|
|
226
|
+
});
|
|
261
227
|
}
|
|
262
228
|
|
|
263
229
|
/** NIP-46 response content schema. */
|
|
264
|
-
static connectResponse()
|
|
230
|
+
static connectResponse() {
|
|
265
231
|
return z.object({
|
|
266
232
|
id: z.string(),
|
|
267
233
|
result: z.string(),
|
|
268
234
|
error: z.string().optional(),
|
|
269
|
-
})
|
|
235
|
+
});
|
|
270
236
|
}
|
|
271
237
|
|
|
272
238
|
/**
|
|
@@ -276,11 +242,11 @@ class NSchema {
|
|
|
276
242
|
* const event = NSchema.json().pipe(NSchema.event()).parse(data);
|
|
277
243
|
* ```
|
|
278
244
|
*/
|
|
279
|
-
static json()
|
|
245
|
+
static json() {
|
|
280
246
|
return z.string().transform((value, ctx) => {
|
|
281
247
|
try {
|
|
282
248
|
return JSON.parse(value) as unknown;
|
|
283
|
-
} catch
|
|
249
|
+
} catch {
|
|
284
250
|
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "Invalid JSON" });
|
|
285
251
|
return z.NEVER;
|
|
286
252
|
}
|