@nostrify/nostrify 0.48.1 → 0.48.3

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 (41) hide show
  1. package/.turbo/turbo-build.log +32 -32
  2. package/.turbo/turbo-typecheck.log +6 -0
  3. package/CHANGELOG.md +16 -0
  4. package/dist/tsconfig.tsbuildinfo +1 -1
  5. package/dist/uploaders/NostrBuildUploader.d.ts +1 -1
  6. package/dist/uploaders/NostrBuildUploader.d.ts.map +1 -1
  7. package/package.json +6 -2
  8. package/uploaders/NostrBuildUploader.ts +1 -1
  9. package/.turbo/turbo-setup.log +0 -13
  10. package/.turbo/turbo-test.log +0 -99
  11. package/dist/BunkerURI.ts +0 -58
  12. package/dist/NBrowserSigner.ts +0 -100
  13. package/dist/NCache.ts +0 -73
  14. package/dist/NConnectSigner.ts +0 -188
  15. package/dist/NIP05.ts +0 -51
  16. package/dist/NIP50.ts +0 -24
  17. package/dist/NIP98.ts +0 -111
  18. package/dist/NIP98Client.ts +0 -36
  19. package/dist/NKinds.ts +0 -26
  20. package/dist/NPool.ts +0 -243
  21. package/dist/NRelay1.ts +0 -447
  22. package/dist/NSchema.ts +0 -291
  23. package/dist/NSecSigner.ts +0 -62
  24. package/dist/NSet.ts +0 -210
  25. package/dist/RelayError.ts +0 -22
  26. package/dist/ln/LNURL.ts +0 -146
  27. package/dist/ln/mod.ts +0 -4
  28. package/dist/ln/types/LNURLCallback.ts +0 -7
  29. package/dist/ln/types/LNURLDetails.ts +0 -19
  30. package/dist/mod.ts +0 -17
  31. package/dist/test/ErrorRelay.ts +0 -52
  32. package/dist/test/MockRelay.ts +0 -92
  33. package/dist/test/TestRelayServer.ts +0 -185
  34. package/dist/test/mod.ts +0 -28
  35. package/dist/uploaders/BlossomUploader.ts +0 -100
  36. package/dist/uploaders/NostrBuildUploader.ts +0 -89
  37. package/dist/uploaders/mod.ts +0 -2
  38. package/dist/utils/CircularSet.ts +0 -36
  39. package/dist/utils/Machina.ts +0 -66
  40. package/dist/utils/N64.ts +0 -23
  41. package/dist/utils/mod.ts +0 -2
@@ -1,99 +0,0 @@
1
-
2
-
3
- > @nostrify/nostrify@0.48.0 test /home/sid/repos/nostrify/packages/nostrify
4
- > node --test "**/*.test.ts"
5
-
6
- ✔ BunkerURI (8.032428ms)
7
- ✔ BunkerURI.fromJSON (1.011522ms)
8
- ✔ NBrowserSigner - without extension (10.371695ms)
9
- ✔ NBrowserSigner - with extension polyfill (329.050343ms)
10
- ✔ NBrowserSigner.nip44 - with extension polyfill (188.734388ms)
11
- ✔ NBrowserSigner.nip04 - with extension polyfill (70.232955ms)
12
- ✔ NBrowserSigner.getRelays - with extension polyfill (2.229952ms)
13
- ✔ NBrowserSigner - missing nip44 support (5.683803ms)
14
- ✔ NBrowserSigner - missing nip04 support (0.456198ms)
15
- ✔ NBrowserSigner - feature detection (4.388092ms)
16
- ✔ NCache (28.041794ms)
17
- ✔ NConnectSigner.signEvent with nip04 encryption (357.348402ms)
18
- ✔ NConnectSigner.signEvent with nip44 encryption (179.341911ms)
19
- ✔ NIP05.lookup (110.840506ms)
20
- ✔ NIP05.lookup with invalid values but valid profile pointer (6.688672ms)
21
- ✔ NIP05.lookup with invalid document (6.384854ms)
22
- ✔ NIP50.parseInput (5.363623ms)
23
- ✔ NIP50.parseInput with negated token (0.425237ms)
24
- ✔ NIP98.template (26.510529ms)
25
- ✔ NIP98.template with payload (57.914746ms)
26
- ✔ NIP98.verify (172.889905ms)
27
- ✔ NIP98.verify fails with missing header (2.182248ms)
28
- ✔ NIP98.verify fails with missing token (1.647725ms)
29
- ✔ NIP98.verify fails with invalid token (1.945311ms)
30
- ✔ NIP98.verify fails with invalid event (49.451318ms)
31
- ✔ NIP98.verify fails with wrong event kind (70.598745ms)
32
- ✔ NIP98.verify fails with wrong request URL (86.043572ms)
33
- ✔ NIP98.verify fails with wrong request method (52.311711ms)
34
- ✔ NIP98.verify fails with expired event (70.877534ms)
35
- ✔ NIP98.verify fails with invalid payload (235.890385ms)
36
- ✔ NIP98Client.fetch - basic GET request (204.607488ms)
37
- ✔ NIP98Client.fetch - POST request with body (224.461879ms)
38
- ✔ NIP98Client.fetch - with Request object input (110.155447ms)
39
- ✔ NIP98Client.fetch - with URL object input (69.82442ms)
40
- ✔ NIP98Client.fetch - uses default fetch when not provided (43.370412ms)
41
- ✔ NIP98Client.fetch - preserves existing headers (75.087655ms)
42
- ✔ NIP98Client.fetch - event can be verified with NIP98.verify (76.739559ms)
43
- ✔ NIP98Client.fetch - handles different HTTP methods (226.588206ms)
44
- ✔ NKinds (15.675591ms)
45
- ✔ NPool.query (635.444667ms)
46
- ✔ NPool.req (107.060121ms)
47
- ✔ NPool.event (66.952535ms)
48
- ✔ NRelay1.query (538.03435ms)
49
- ✔ NRelay1.query mismatched filter (133.455243ms)
50
- ✔ NRelay1.req (141.418776ms)
51
- ✔ NRelay1.event (32.63963ms)
52
- ﹣ NRelay1 backoff (1.106008ms) # SKIP
53
- ▶ NRelay1 idleTimeout
54
- ✔ websocket opens (13.835447ms)
55
- ✔ websocket closes after idleTimeout (150.566912ms)
56
- ✔ websocket wakes up during activity (27.121071ms)
57
- ✔ NRelay1 idleTimeout (204.19181ms)
58
- ✔ NRelay1.count rejects when the server sends CLOSED (16.828862ms)
59
- ✔ NRelay1 closes when it receives a binary message (11.148585ms)
60
- ✔ n.id (8.094721ms)
61
- ✔ n.bech32 (5.484882ms)
62
- ✔ n.filter (18.52384ms)
63
- ✔ n.event (4.463901ms)
64
- ✔ n.metadata (24.462155ms)
65
- ✔ NSecSigner (219.082425ms)
66
- ✔ NSecSigner.nip44 (37.591612ms)
67
- ✔ NSet (24.542373ms)
68
- ✔ NSet.add (replaceable) (0.656583ms)
69
- ✔ NSet.add (parameterized) (1.209522ms)
70
- ✔ NSet.add (deletion) (0.555925ms)
71
- ✔ Construct a RelayError from the reason message (2.598397ms)
72
- ✔ Throw a new RelayError if the OK message is false (0.892217ms)
73
- ✔ LNURL.fromString (21.686509ms)
74
- ✔ LNURL.fromLightningAddress (6.521633ms)
75
- ✔ LNURL.toString (2.187929ms)
76
- ✔ LNURL.getDetails (149.682932ms)
77
- ✔ LNURL.getInvoice (7.231692ms)
78
- ✔ ErrorRelay (189.467472ms)
79
- ✔ MockRelay (4.420616ms)
80
- ﹣ BlossomUploader.upload (1.337574ms) # SKIP
81
- ﹣ NostrBuildUploader.upload (2.212377ms) # SKIP
82
- ✔ CircularSet (14.732834ms)
83
- ✔ push, iterate, & close (109.180767ms)
84
- ✔ close & reopen (0.918119ms)
85
- ✔ aborts with signal (53.398331ms)
86
- ✔ already aborted signal in constructor (0.819754ms)
87
- ✔ push after abort (1.01538ms)
88
- ✔ multiple messages in queue (0.693816ms)
89
- ✔ N64 (13.23745ms)
90
- ✔ N64.encodeEvent (0.744977ms)
91
- ✔ N64.decodeEvent (1.885313ms)
92
- ℹ tests 85
93
- ℹ suites 0
94
- ℹ pass 82
95
- ℹ fail 0
96
- ℹ cancelled 0
97
- ℹ skipped 3
98
- ℹ todo 0
99
- ℹ duration_ms 2367.358539
package/dist/BunkerURI.ts DELETED
@@ -1,58 +0,0 @@
1
- /** Construct a [NIP-46](https://github.com/nostr-protocol/nips/blob/master/46.md) bunker URI. */
2
- export class BunkerURI {
3
- /** Remote signer pubkey. */
4
- pubkey: string;
5
- /** Relay URLs on which the client is listening for responses from the remote-signer. */
6
- relays: string[];
7
- /** A short random string that the remote-signer should return as the `result` field of its response. */
8
- secret?: string;
9
-
10
- constructor(uri: string) {
11
- const url = new URL(uri);
12
- const params = new URLSearchParams(url.search);
13
-
14
- // https://github.com/denoland/deno/issues/26440
15
- const pubkey = url.hostname || url.pathname.slice(2);
16
- const relays = params.getAll('relay');
17
- const secret = params.get('secret') ?? undefined;
18
-
19
- if (!pubkey) {
20
- throw new Error('Invalid bunker URI');
21
- }
22
-
23
- this.pubkey = pubkey;
24
- this.relays = relays;
25
- this.secret = secret;
26
- }
27
-
28
- /** Convert into a `bunker://` URI string. */
29
- get href(): string {
30
- return this.toString();
31
- }
32
-
33
- /** Convert into a `bunker://` URI string. */
34
- toString(): string {
35
- return BunkerURI.toString(this);
36
- }
37
-
38
- /** Convert a bunker data object into a `BunkerURI` instance. */
39
- static fromJSON(data: { pubkey: string; relays: string[]; secret?: string }): BunkerURI {
40
- const uri = BunkerURI.toString(data);
41
- return new BunkerURI(uri);
42
- }
43
-
44
- /** Convert a bunker data object into a bunker URI string. */
45
- private static toString(data: { pubkey: string; relays: string[]; secret?: string }): string {
46
- const search = new URLSearchParams();
47
-
48
- for (const relay of data.relays) {
49
- search.append('relay', relay);
50
- }
51
-
52
- if (data.secret) {
53
- search.set('secret', data.secret);
54
- }
55
-
56
- return `bunker://${data.pubkey}?${search.toString()}`;
57
- }
58
- }
@@ -1,100 +0,0 @@
1
- import type { NostrEvent, NostrSigner } from '@nostrify/types';
2
-
3
- /**
4
- * NIP-07-compatible signer that proxies to browser extension, normalizing behavior across different implementations.
5
- *
6
- * This signer delegates all operations to the browser's `window.nostr` object,
7
- * which is typically provided by browser extensions like Alby, nos2x, etc.
8
- *
9
- * Usage:
10
- *
11
- * ```ts
12
- * const signer = new NBrowserSigner();
13
- * const pubkey = await signer.getPublicKey();
14
- * const event = await signer.signEvent({ kind: 1, content: 'Hello, world!', tags: [], created_at: 0 });
15
- * ```
16
- */
17
- export class NBrowserSigner implements NostrSigner {
18
- private get nostr(): NostrSigner {
19
- const nostr = (globalThis as { nostr?: NostrSigner }).nostr;
20
- if (!nostr) {
21
- throw new Error('Browser extension not available');
22
- }
23
- return nostr;
24
- }
25
-
26
- async getPublicKey(): Promise<string> {
27
- const pubkey = await this.nostr.getPublicKey();
28
- if (typeof pubkey !== 'string') {
29
- throw new Error(`Nostr public key retrieval failed: expected string, got ${JSON.stringify(pubkey)}`);
30
- }
31
- return pubkey;
32
- }
33
-
34
- async signEvent(event: Omit<NostrEvent, 'id' | 'pubkey' | 'sig'>): Promise<NostrEvent> {
35
- const signed = await this.nostr.signEvent(event);
36
- if (typeof signed !== 'object' || !signed.id || !signed.pubkey || !signed.sig) {
37
- throw new Error(
38
- `Nostr event signing failed: expected object with id, pubkey, and sig, got ${JSON.stringify(signed)}`,
39
- );
40
- }
41
- return signed;
42
- }
43
-
44
- async getRelays(): Promise<Record<string, { read: boolean; write: boolean }>> {
45
- if (!this.nostr.getRelays) {
46
- return {};
47
- }
48
- const relays = await this.nostr.getRelays();
49
- if (typeof relays !== 'object' || relays === null) {
50
- throw new Error(`Nostr getRelays failed: expected object, got ${JSON.stringify(relays)}`);
51
- }
52
- return this.nostr.getRelays();
53
- }
54
-
55
- get nip04(): NostrSigner['nip04'] {
56
- const nostr = this.nostr;
57
- if (!nostr.nip04) {
58
- return undefined;
59
- }
60
- return {
61
- encrypt: async (pubkey: string, plaintext: string): Promise<string> => {
62
- const encrypted = await nostr.nip04!.encrypt(pubkey, plaintext);
63
- if (typeof encrypted !== 'string') {
64
- throw new Error(`NIP-04 encryption failed: expected string result, got ${JSON.stringify(encrypted)}`);
65
- }
66
- return encrypted;
67
- },
68
- decrypt: async (pubkey: string, ciphertext: string): Promise<string> => {
69
- const decrypted = await nostr.nip04!.decrypt(pubkey, ciphertext);
70
- if (typeof decrypted !== 'string') {
71
- throw new Error(`NIP-04 decryption failed: expected string result, got ${JSON.stringify(decrypted)}`);
72
- }
73
- return decrypted;
74
- },
75
- };
76
- }
77
-
78
- get nip44(): NostrSigner['nip44'] {
79
- const nostr = this.nostr;
80
- if (!nostr.nip44) {
81
- return undefined;
82
- }
83
- return {
84
- encrypt: async (pubkey: string, plaintext: string): Promise<string> => {
85
- const encrypted = await nostr.nip44!.encrypt(pubkey, plaintext);
86
- if (typeof encrypted !== 'string') {
87
- throw new Error(`NIP-44 encryption failed: expected string result, got ${JSON.stringify(encrypted)}`);
88
- }
89
- return encrypted;
90
- },
91
- decrypt: async (pubkey: string, ciphertext: string): Promise<string> => {
92
- const decrypted = await nostr.nip44!.decrypt(pubkey, ciphertext);
93
- if (typeof decrypted !== 'string') {
94
- throw new Error(`NIP-44 decryption failed: expected string result, got ${JSON.stringify(decrypted)}`);
95
- }
96
- return decrypted;
97
- },
98
- };
99
- }
100
- }
package/dist/NCache.ts DELETED
@@ -1,73 +0,0 @@
1
- // deno-lint-ignore-file require-await
2
-
3
- import type { NostrEvent, NostrFilter, NostrRelayCOUNT, NStore } from '@nostrify/types';
4
- import { LRUCache } from 'lru-cache';
5
- import { matchFilters } from 'nostr-tools';
6
-
7
- import { NSet } from './NSet.ts';
8
-
9
- /**
10
- * Nostr LRU cache based on [`npm:lru-cache`](https://www.npmjs.com/package/lru-cache).
11
- * It implements both `NStore` and `NSet` interfaces.
12
- *
13
- * ```ts
14
- * // Accepts the options of `npm:lru-cache`:
15
- * const cache = new NCache({ max: 1000 });
16
- *
17
- * // Events can be added like a regular `Set`:
18
- * cache.add(event1);
19
- * cache.add(event2);
20
- *
21
- * // Can be queried like `NStore`:
22
- * const events = await cache.query([{ kinds: [1] }]);
23
- *
24
- * // Can be iterated like `NSet`:
25
- * for (const event of cache) {
26
- * console.log(event);
27
- * }
28
- * ```
29
- */
30
- class NCache extends NSet implements NStore {
31
- constructor(
32
- ...args: ConstructorParameters<typeof LRUCache<string, NostrEvent>>
33
- ) {
34
- super(new LRUCache<string, NostrEvent>(...args) as Map<string, NostrEvent>);
35
- }
36
-
37
- async event(event: NostrEvent): Promise<void> {
38
- this.add(event);
39
- }
40
-
41
- async query(filters: NostrFilter[]): Promise<NostrEvent[]> {
42
- const events: NostrEvent[] = [];
43
-
44
- for (const event of this) {
45
- if (matchFilters(filters, event)) {
46
- this.cache.get(event.id);
47
- events.push(event);
48
- }
49
- }
50
-
51
- return events;
52
- }
53
-
54
- async remove(filters: NostrFilter[]): Promise<void> {
55
- for (const event of this) {
56
- if (matchFilters(filters, event)) {
57
- this.delete(event);
58
- }
59
- }
60
- }
61
-
62
- async count(filters: NostrFilter[]): Promise<NostrRelayCOUNT[2]> {
63
- const events = await this.query(filters);
64
- return {
65
- count: events.length,
66
- approximate: false,
67
- };
68
- }
69
-
70
- override [Symbol.toStringTag] = 'NCache';
71
- }
72
-
73
- export { NCache };
@@ -1,188 +0,0 @@
1
- // deno-lint-ignore-file require-await
2
-
3
- import { z } from 'zod';
4
-
5
- import type { NostrConnectRequest, NostrConnectResponse, NostrEvent, NostrSigner, NRelay } from '@nostrify/types';
6
-
7
- import { NSchema as n } from './NSchema.ts';
8
-
9
- /** Options for `NConnectSigner`. */
10
- export interface NConnectSignerOpts {
11
- /** Relay to facilitate connection. */
12
- relay: NRelay;
13
- /** Remote pubkey to sign as. */
14
- pubkey: string;
15
- /** Local signer to sign the request events. */
16
- signer: NostrSigner;
17
- /** Timeout for requests. */
18
- timeout?: number;
19
- /** Encryption to use when encrypting local messages. Decryption is automatic. */
20
- encryption?: 'nip04' | 'nip44';
21
- }
22
-
23
- /** [NIP-46](https://github.com/nostr-protocol/nips/blob/master/46.md) remote signer through a relay. */
24
- export class NConnectSigner implements NostrSigner {
25
- private relay: NRelay;
26
- private pubkey: string;
27
- private signer: NostrSigner;
28
- private timeout?: number;
29
- private encryption: 'nip04' | 'nip44';
30
-
31
- constructor(
32
- { relay, pubkey, signer, timeout, encryption = 'nip44' }: NConnectSignerOpts,
33
- ) {
34
- this.relay = relay;
35
- this.pubkey = pubkey;
36
- this.signer = signer;
37
- this.timeout = timeout;
38
- this.encryption = encryption;
39
- }
40
-
41
- async getPublicKey(): Promise<string> {
42
- return this.cmd('get_public_key', []);
43
- }
44
-
45
- async signEvent(
46
- event: Omit<NostrEvent, 'id' | 'pubkey' | 'sig'>,
47
- ): Promise<NostrEvent> {
48
- const result = await this.cmd('sign_event', [JSON.stringify(event)]);
49
- return n.json().pipe(n.event()).parse(result);
50
- }
51
-
52
- async getRelays(): Promise<
53
- Record<string, { read: boolean; write: boolean }>
54
- > {
55
- const result = await this.cmd('get_relays', []);
56
-
57
- return n
58
- .json()
59
- .pipe(
60
- z.record(
61
- z.string(),
62
- z.object({ read: z.boolean(), write: z.boolean() }),
63
- ),
64
- )
65
- .parse(result) as Record<string, { read: boolean; write: boolean }>; // FIXME: hack!
66
- }
67
-
68
- readonly nip04 = {
69
- encrypt: async (pubkey: string, plaintext: string): Promise<string> => {
70
- return this.cmd('nip04_encrypt', [pubkey, plaintext]);
71
- },
72
-
73
- decrypt: async (pubkey: string, ciphertext: string): Promise<string> => {
74
- return this.cmd('nip04_decrypt', [pubkey, ciphertext]);
75
- },
76
- };
77
-
78
- readonly nip44 = {
79
- encrypt: async (pubkey: string, plaintext: string): Promise<string> => {
80
- return this.cmd('nip44_encrypt', [pubkey, plaintext]);
81
- },
82
-
83
- decrypt: async (pubkey: string, ciphertext: string): Promise<string> => {
84
- return this.cmd('nip44_decrypt', [pubkey, ciphertext]);
85
- },
86
- };
87
-
88
- /** Send a `connect` command to the relay. It should respond with `ack`. */
89
- async connect(secret?: string): Promise<string> {
90
- const params: string[] = [this.pubkey];
91
-
92
- if (secret) {
93
- params.push(secret);
94
- }
95
-
96
- return this.cmd('connect', params);
97
- }
98
-
99
- /** Send a `ping` command to the signer. It should respond with `pong`. */
100
- async ping(): Promise<string> {
101
- return this.cmd('ping', []);
102
- }
103
-
104
- /** High-level RPC method. Returns the string result, or throws on error. */
105
- private async cmd(method: string, params: string[]): Promise<string> {
106
- const signal = typeof this.timeout === 'number' ? AbortSignal.timeout(this.timeout) : undefined;
107
-
108
- const { result, error } = await this.send(
109
- { id: crypto.randomUUID(), method, params },
110
- { signal },
111
- );
112
-
113
- if (error) {
114
- throw new Error(error);
115
- }
116
-
117
- return result;
118
- }
119
-
120
- /** Low-level send method. Deals directly with connect request/response. */
121
- private async send(
122
- request: NostrConnectRequest,
123
- opts: { signal?: AbortSignal } = {},
124
- ): Promise<NostrConnectResponse> {
125
- const { signal } = opts;
126
-
127
- const event = await this.signer.signEvent({
128
- kind: 24133,
129
- content: await this.encrypt(this.pubkey, JSON.stringify(request)),
130
- created_at: Math.floor(Date.now() / 1000),
131
- tags: [['p', this.pubkey]],
132
- });
133
-
134
- const local = await this.signer.getPublicKey();
135
-
136
- const req = this.relay.req(
137
- [{ kinds: [24133], authors: [this.pubkey], '#p': [local] }],
138
- { signal },
139
- );
140
-
141
- // Ensure the REQ is opened before sending the EVENT
142
- const promise = new Promise<NostrConnectResponse>((resolve, reject) => {
143
- (async () => {
144
- try {
145
- for await (const msg of req) {
146
- if (msg[0] === 'CLOSED') throw new Error('Subscription closed');
147
- if (msg[0] === 'EVENT') {
148
- const event = msg[2];
149
- const decrypted = await this.decrypt(this.pubkey, event.content);
150
- const response = n.json().pipe(n.connectResponse()).parse(
151
- decrypted,
152
- );
153
- if (response.id === request.id) {
154
- resolve(response);
155
- return;
156
- }
157
- }
158
- }
159
- } catch (error) {
160
- reject(error);
161
- }
162
- })();
163
- });
164
-
165
- await this.relay.event(event, { signal });
166
- return promise;
167
- }
168
-
169
- /** Local encrypt depending on settings. */
170
- private async encrypt(pubkey: string, plaintext: string): Promise<string> {
171
- switch (this.encryption) {
172
- case 'nip04':
173
- return this.signer.nip04!.encrypt(pubkey, plaintext);
174
- case 'nip44':
175
- return this.signer.nip44!.encrypt(pubkey, plaintext);
176
- }
177
- }
178
-
179
- /** Local decrypt depending on settings. */
180
- private async decrypt(pubkey: string, ciphertext: string): Promise<string> {
181
- switch (this.encryption) {
182
- case 'nip04':
183
- return this.signer.nip04!.decrypt(pubkey, ciphertext);
184
- case 'nip44':
185
- return this.signer.nip44!.decrypt(pubkey, ciphertext);
186
- }
187
- }
188
- }
package/dist/NIP05.ts DELETED
@@ -1,51 +0,0 @@
1
- import type { NProfilePointer } from "@nostrify/types";
2
-
3
- import { NSchema as n, z } from "./NSchema.ts";
4
-
5
- interface LookupOpts {
6
- fetch?: typeof fetch;
7
- signal?: AbortSignal;
8
- }
9
-
10
- export class NIP05 {
11
- /** NIP-05 value regex. */
12
- static regex(): RegExp {
13
- return /^(?:([\w.+-]+)@)?([\w.-]+)$/;
14
- }
15
-
16
- /** Nostr pubkey with relays object. */
17
- private static profilePointerSchema(): z.ZodType<NProfilePointer> {
18
- return z.object({
19
- pubkey: n.id(),
20
- relays: n.relayUrl().array().optional(),
21
- }) as z.ZodType<NProfilePointer>;
22
- }
23
-
24
- /** Resolve NIP-05 name to a profile pointer. */
25
- static async lookup(
26
- nip05: string,
27
- opts?: LookupOpts,
28
- ): Promise<NProfilePointer> {
29
- const { fetch = globalThis.fetch.bind(globalThis), signal } = opts ?? {};
30
-
31
- const match = nip05.match(NIP05.regex());
32
- if (!match) throw new Error(`NIP-05: invalid name ${nip05}`);
33
-
34
- const [_, name = "_", domain] = match;
35
-
36
- const url = new URL("/.well-known/nostr.json", `https://${domain}/`);
37
- url.searchParams.set("name", name);
38
-
39
- const response = await fetch(url, { signal });
40
- const json = await response.json();
41
-
42
- try {
43
- const pubkey = json.names[name];
44
- const relays = json.relays?.[pubkey];
45
-
46
- return NIP05.profilePointerSchema().parse({ pubkey, relays });
47
- } catch {
48
- throw new Error(`NIP-05: no match for ${nip05}`);
49
- }
50
- }
51
- }
package/dist/NIP50.ts DELETED
@@ -1,24 +0,0 @@
1
- type SearchToken = string | { key: string; value: string };
2
-
3
- /** [NIP-50](https://github.com/nostr-protocol/nips/blob/master/50.md) search functionality. */
4
- export class NIP50 {
5
- static parseInput(input: string): SearchToken[] {
6
- const regex = /(\B-\w+:[^\s"]+)|(\b\w+:[^\s"]+)|(".*?")|(\S+)/g;
7
-
8
- const tokens: SearchToken[] = [];
9
- let match: RegExpExecArray | null;
10
-
11
- while ((match = regex.exec(input)) !== null) {
12
- if (match[1] || match[2]) {
13
- const [key, ...values] = (match[1] || match[2]).split(':');
14
- tokens.push({ key, value: values.join(':') });
15
- } else if (match[3]) {
16
- tokens.push(match[3].replace(/"/g, ''));
17
- } else if (match[4]) {
18
- tokens.push(match[4]);
19
- }
20
- }
21
-
22
- return tokens;
23
- }
24
- }