@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
@@ -1,63 +1,65 @@
1
- import { z } from 'zod';
2
- import { N64 } from '../utils/N64.js';
3
- import { NIP98 } from '../NIP98.js';
4
- /** Upload files to nostr.build or another compatible server. */
5
- export class NostrBuildUploader {
6
- endpoint;
7
- signer;
8
- fetch;
9
- constructor(opts) {
10
- this.endpoint = opts?.endpoint ?? 'https://nostr.build/api/v2/upload/files';
11
- this.signer = opts?.signer;
12
- this.fetch = opts?.fetch ?? globalThis.fetch.bind(globalThis);
1
+ import { z } from "zod";
2
+ import { N64 } from "../utils/N64.js";
3
+ import { NIP98 } from "../NIP98.js";
4
+ class NostrBuildUploader {
5
+ endpoint;
6
+ signer;
7
+ fetch;
8
+ constructor(opts) {
9
+ this.endpoint = opts?.endpoint ?? "https://nostr.build/api/v2/upload/files";
10
+ this.signer = opts?.signer;
11
+ this.fetch = opts?.fetch ?? globalThis.fetch.bind(globalThis);
12
+ }
13
+ async upload(file, opts) {
14
+ const formData = new FormData();
15
+ formData.append("fileToUpload", file);
16
+ const request = new Request(this.endpoint, {
17
+ method: "POST",
18
+ body: formData,
19
+ signal: opts?.signal
20
+ });
21
+ if (this.signer) {
22
+ const t = await NIP98.template(request);
23
+ const event = await this.signer.signEvent(t);
24
+ request.headers.set("authorization", `Nostr ${N64.encodeEvent(event)}`);
13
25
  }
14
- async upload(file, opts) {
15
- const formData = new FormData();
16
- formData.append('fileToUpload', file);
17
- const request = new Request(this.endpoint, {
18
- method: 'POST',
19
- body: formData,
20
- signal: opts?.signal,
21
- });
22
- if (this.signer) {
23
- const t = await NIP98.template(request);
24
- const event = await this.signer.signEvent(t);
25
- request.headers.set('authorization', `Nostr ${N64.encodeEvent(event)}`);
26
- }
27
- const response = await this.fetch(request);
28
- const json = await response.json();
29
- const [data] = NostrBuildUploader.schema().parse(json).data;
30
- const tags = [
31
- ['url', data.url],
32
- ['m', data.mime],
33
- ['x', data.sha256],
34
- ['ox', data.original_sha256],
35
- ['size', data.size.toString()],
36
- ];
37
- if (data.dimensions) {
38
- tags.push(['dim', `${data.dimensions.width}x${data.dimensions.height}`]);
39
- }
40
- if (data.blurhash) {
41
- tags.push(['blurhash', data.blurhash]);
42
- }
43
- return tags;
26
+ const response = await this.fetch(request);
27
+ const json = await response.json();
28
+ console.log(json);
29
+ const [data] = NostrBuildUploader.schema().parse(json).data;
30
+ const tags = [
31
+ ["url", data.url],
32
+ ["m", data.mime],
33
+ ["x", data.sha256],
34
+ ["ox", data.original_sha256],
35
+ ["size", data.size.toString()]
36
+ ];
37
+ if (data.dimensions) {
38
+ tags.push(["dim", `${data.dimensions.width}x${data.dimensions.height}`]);
44
39
  }
45
- /** nostr.build API response schema. */
46
- static schema() {
47
- return z.object({
48
- data: z.object({
49
- url: z.string().url(),
50
- blurhash: z.string().optional().catch(undefined),
51
- sha256: z.string(),
52
- original_sha256: z.string(),
53
- mime: z.string(),
54
- size: z.number(),
55
- dimensions: z.object({
56
- width: z.number().positive(),
57
- height: z.number().positive(),
58
- }).optional().catch(undefined),
59
- }).array().min(1),
60
- });
40
+ if (data.blurhash) {
41
+ tags.push(["blurhash", data.blurhash]);
61
42
  }
43
+ return tags;
44
+ }
45
+ /** nostr.build API response schema. */
46
+ static schema() {
47
+ return z.object({
48
+ data: z.object({
49
+ url: z.string().url(),
50
+ blurhash: z.string().optional().catch(void 0),
51
+ sha256: z.string(),
52
+ original_sha256: z.string(),
53
+ mime: z.string(),
54
+ size: z.number(),
55
+ dimensions: z.object({
56
+ width: z.number().positive(),
57
+ height: z.number().positive()
58
+ }).optional().catch(void 0)
59
+ }).array().min(1)
60
+ });
61
+ }
62
62
  }
63
- //# sourceMappingURL=NostrBuildUploader.js.map
63
+ export {
64
+ NostrBuildUploader
65
+ };
@@ -1,3 +1,3 @@
1
- export { BlossomUploader } from './BlossomUploader.js';
2
- export { NostrBuildUploader } from './NostrBuildUploader.js';
1
+ export { BlossomUploader } from './BlossomUploader.ts';
2
+ export { NostrBuildUploader } from './NostrBuildUploader.ts';
3
3
  //# sourceMappingURL=mod.d.ts.map
@@ -1,3 +1,6 @@
1
- export { BlossomUploader } from './BlossomUploader.js';
2
- export { NostrBuildUploader } from './NostrBuildUploader.js';
3
- //# sourceMappingURL=mod.js.map
1
+ import { BlossomUploader } from "./BlossomUploader.js";
2
+ import { NostrBuildUploader } from "./NostrBuildUploader.js";
3
+ export {
4
+ BlossomUploader,
5
+ NostrBuildUploader
6
+ };
@@ -1 +1,7 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../uploaders/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../uploaders/mod.ts"],
4
+ "sourcesContent": ["export { BlossomUploader } from './BlossomUploader.ts';\nexport { NostrBuildUploader } from './NostrBuildUploader.ts';\n"],
5
+ "mappings": ";AAAA,SAAS,uBAAuB;AAChC,SAAS,0BAA0B;",
6
+ "names": []
7
+ }
@@ -3,8 +3,8 @@
3
3
  * Shares the properties of both a Circular Buffer and a Set.
4
4
  */
5
5
  export declare class CircularSet<T> {
6
- private capacity;
7
6
  private set;
7
+ private capacity;
8
8
  constructor(capacity: number);
9
9
  add(item: T): void;
10
10
  has(item: T): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"CircularSet.d.ts","sourceRoot":"","sources":["../../utils/CircularSet.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,WAAW,CAAC,CAAC;IAGZ,OAAO,CAAC,QAAQ;IAF5B,OAAO,CAAC,GAAG,CAAS;gBAEA,QAAQ,EAAE,MAAM;IAIpC,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAelB,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO;IAIrB,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC;CAGjC"}
1
+ {"version":3,"file":"CircularSet.d.ts","sourceRoot":"","sources":["../../utils/CircularSet.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,WAAW,CAAC,CAAC;IACxB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,QAAQ,CAAS;gBAEb,QAAQ,EAAE,MAAM;IAK5B,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAelB,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO;IAIrB,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC;CAGjC"}
@@ -1,31 +1,29 @@
1
- /**
2
- * Like a Circular Buffer, but the values are deduplicated.
3
- * Shares the properties of both a Circular Buffer and a Set.
4
- */
5
- export class CircularSet {
6
- capacity;
7
- set;
8
- constructor(capacity) {
9
- this.capacity = capacity;
10
- this.set = new Set();
1
+ class CircularSet {
2
+ set;
3
+ capacity;
4
+ constructor(capacity) {
5
+ this.set = /* @__PURE__ */ new Set();
6
+ this.capacity = capacity;
7
+ }
8
+ add(item) {
9
+ if (this.set.has(item)) {
10
+ return;
11
11
  }
12
- add(item) {
13
- if (this.set.has(item)) {
14
- return;
15
- }
16
- if (this.set.size >= this.capacity) {
17
- const oldest = this.set.values().next().value;
18
- if (oldest) {
19
- this.set.delete(oldest);
20
- }
21
- }
22
- this.set.add(item);
23
- }
24
- has(item) {
25
- return this.set.has(item);
26
- }
27
- [Symbol.iterator]() {
28
- return this.set.values();
12
+ if (this.set.size >= this.capacity) {
13
+ const oldest = this.set.values().next().value;
14
+ if (oldest) {
15
+ this.set.delete(oldest);
16
+ }
29
17
  }
18
+ this.set.add(item);
19
+ }
20
+ has(item) {
21
+ return this.set.has(item);
22
+ }
23
+ [Symbol.iterator]() {
24
+ return this.set.values();
25
+ }
30
26
  }
31
- //# sourceMappingURL=CircularSet.js.map
27
+ export {
28
+ CircularSet
29
+ };
@@ -1,62 +1,38 @@
1
- /**
2
- * Infinite async generator. Iterates messages pushed to it until closed.
3
- * Only one consumer is expected to use a Machina instance at a time.
4
- *
5
- * @example
6
- * ```ts
7
- * // Create the Machina instance
8
- * const machina = new Machina<string>();
9
- *
10
- * // Async generator loop
11
- * async function getMessages() {
12
- * for await (const msg of machina.stream()) {
13
- * console.log(msg);
14
- * }
15
- * }
16
- *
17
- * // Start the generator
18
- * getMessages();
19
- *
20
- * // Push messages to it
21
- * machina.push('hello!');
22
- * machina.push('whats up?');
23
- * machina.push('greetings');
24
- * ```
25
- */
26
- export class Machina {
27
- #queue = [];
28
- #resolve;
29
- #aborted = false;
30
- constructor(signal) {
31
- if (signal?.aborted) {
32
- this.abort();
33
- }
34
- else {
35
- signal?.addEventListener('abort', () => this.abort(), { once: true });
36
- }
1
+ class Machina {
2
+ #queue = [];
3
+ #resolve;
4
+ #aborted = false;
5
+ constructor(signal) {
6
+ if (signal?.aborted) {
7
+ this.abort();
8
+ } else {
9
+ signal?.addEventListener("abort", () => this.abort(), { once: true });
37
10
  }
38
- /** Get messages as an AsyncIterable. */
39
- async *[Symbol.asyncIterator]() {
40
- while (!this.#aborted) {
41
- if (this.#queue.length) {
42
- yield this.#queue.shift();
43
- continue;
44
- }
45
- await new Promise((_resolve) => {
46
- this.#resolve = _resolve;
47
- });
48
- }
49
- throw new DOMException('The signal has been aborted', 'AbortError');
50
- }
51
- /** Push a message into the Machina instance, making it available to the consumer of `stream()`. */
52
- push(data) {
53
- this.#queue.push(data);
54
- this.#resolve?.();
55
- }
56
- /** Stops streaming and throws an error to the consumer. */
57
- abort() {
58
- this.#aborted = true;
59
- this.#resolve?.();
11
+ }
12
+ /** Get messages as an AsyncIterable. */
13
+ async *[Symbol.asyncIterator]() {
14
+ while (!this.#aborted) {
15
+ if (this.#queue.length) {
16
+ yield this.#queue.shift();
17
+ continue;
18
+ }
19
+ await new Promise((_resolve) => {
20
+ this.#resolve = _resolve;
21
+ });
60
22
  }
23
+ throw new DOMException("The signal has been aborted", "AbortError");
24
+ }
25
+ /** Push a message into the Machina instance, making it available to the consumer of `stream()`. */
26
+ push(data) {
27
+ this.#queue.push(data);
28
+ this.#resolve?.();
29
+ }
30
+ /** Stops streaming and throws an error to the consumer. */
31
+ abort() {
32
+ this.#aborted = true;
33
+ this.#resolve?.();
34
+ }
61
35
  }
62
- //# sourceMappingURL=Machina.js.map
36
+ export {
37
+ Machina
38
+ };
@@ -1,4 +1,4 @@
1
- import { NostrEvent } from '@nostrify/types';
1
+ import type { NostrEvent } from '@nostrify/types';
2
2
  /** Nostr base64 helper utilities. */
3
3
  export declare class N64 {
4
4
  /** Encode an event as a base64 string. */
@@ -1 +1 @@
1
- {"version":3,"file":"N64.d.ts","sourceRoot":"","sources":["../../utils/N64.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAK7C,qCAAqC;AACrC,qBAAa,GAAG;IACd,0CAA0C;IAC1C,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM;IAI7C,+GAA+G;IAC/G,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU;CAS/C"}
1
+ {"version":3,"file":"N64.d.ts","sourceRoot":"","sources":["../../utils/N64.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAKlD,qCAAqC;AACrC,qBAAa,GAAG;IACd,0CAA0C;IAC1C,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM;IAI7C,+GAA+G;IAC/G,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU;CAS/C"}
package/dist/utils/N64.js CHANGED
@@ -1,19 +1,17 @@
1
- import { decodeBase64, encodeBase64 } from '@std/encoding/base64';
2
- import { NSchema as n } from '../NSchema.js';
3
- /** Nostr base64 helper utilities. */
4
- export class N64 {
5
- /** Encode an event as a base64 string. */
6
- static encodeEvent(event) {
7
- return encodeBase64(JSON.stringify(event));
8
- }
9
- /** Decode an event from a base64 string. Validates the event's structure but does not verify its signature. */
10
- static decodeEvent(base64) {
11
- const bytes = decodeBase64(base64);
12
- const text = new TextDecoder().decode(bytes);
13
- return n
14
- .json()
15
- .pipe(n.event())
16
- .parse(text);
17
- }
1
+ import { decodeBase64, encodeBase64 } from "@std/encoding/base64";
2
+ import { NSchema as n } from "../NSchema.js";
3
+ class N64 {
4
+ /** Encode an event as a base64 string. */
5
+ static encodeEvent(event) {
6
+ return encodeBase64(JSON.stringify(event));
7
+ }
8
+ /** Decode an event from a base64 string. Validates the event's structure but does not verify its signature. */
9
+ static decodeEvent(base64) {
10
+ const bytes = decodeBase64(base64);
11
+ const text = new TextDecoder().decode(bytes);
12
+ return n.json().pipe(n.event()).parse(text);
13
+ }
18
14
  }
19
- //# sourceMappingURL=N64.js.map
15
+ export {
16
+ N64
17
+ };
@@ -1,3 +1,3 @@
1
- export { Machina } from './Machina.js';
2
- export { N64 } from './N64.js';
1
+ export { Machina } from './Machina.ts';
2
+ export { N64 } from './N64.ts';
3
3
  //# sourceMappingURL=mod.d.ts.map
package/dist/utils/mod.js CHANGED
@@ -1,3 +1,6 @@
1
- export { Machina } from './Machina.js';
2
- export { N64 } from './N64.js';
3
- //# sourceMappingURL=mod.js.map
1
+ import { Machina } from "./Machina.js";
2
+ import { N64 } from "./N64.js";
3
+ export {
4
+ Machina,
5
+ N64
6
+ };
@@ -1 +1,7 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../utils/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../utils/mod.ts"],
4
+ "sourcesContent": ["export { Machina } from './Machina.ts';\nexport { N64 } from './N64.ts';\n"],
5
+ "mappings": ";AAAA,SAAS,eAAe;AACxB,SAAS,WAAW;",
6
+ "names": []
7
+ }
package/ln/LNURL.test.ts CHANGED
@@ -1,18 +1,20 @@
1
- import { assertEquals } from '@std/assert';
1
+ import { test } from "node:test";
2
+ import { deepStrictEqual } from "node:assert";
2
3
 
3
- import { LNURL } from './LNURL.ts';
4
+ import { LNURL } from "@nostrify/nostrify/ln";
4
5
 
5
6
  // deno-lint-ignore require-await
6
7
  const mockFetch: typeof globalThis.fetch = async (input, init) => {
7
8
  const { url } = new Request(input, init);
8
9
  switch (url) {
9
- case 'https://getalby.com/.well-known/lnurlp/alexgleason':
10
+ case "https://getalby.com/.well-known/lnurlp/alexgleason":
10
11
  return new Response(JSON.stringify({
11
- status: 'OK',
12
- tag: 'payRequest',
12
+ status: "OK",
13
+ tag: "payRequest",
13
14
  commentAllowed: 255,
14
- callback: 'https://getalby.com/lnurlp/alexgleason/callback',
15
- metadata: '[["text/identifier","alexgleason@getalby.com"],["text/plain","Sats for alexgleason"]]',
15
+ callback: "https://getalby.com/lnurlp/alexgleason/callback",
16
+ metadata:
17
+ '[["text/identifier","alexgleason@getalby.com"],["text/plain","Sats for alexgleason"]]',
16
18
  minSendable: 1000,
17
19
  maxSendable: 100000000,
18
20
  payerData: {
@@ -20,68 +22,84 @@ const mockFetch: typeof globalThis.fetch = async (input, init) => {
20
22
  email: { mandatory: false },
21
23
  pubkey: { mandatory: false },
22
24
  },
23
- nostrPubkey: '79f00d3f5a19ec806189fcab03c1be4ff81d18ee4f653c88fac41fe03570f432',
25
+ nostrPubkey:
26
+ "79f00d3f5a19ec806189fcab03c1be4ff81d18ee4f653c88fac41fe03570f432",
24
27
  allowsNostr: true,
25
28
  }));
26
- case 'https://getalby.com/lnurlp/alexgleason/callback?amount=1000&lnurl=lnurl1dp68gurn8ghj7em9w3skccne9e3k7mf09emk2mrv944kummhdchkcmn4wfk8qtmpd3jhsemvv4shxmmw5uhvxu':
29
+ case "https://getalby.com/lnurlp/alexgleason/callback?amount=1000&lnurl=lnurl1dp68gurn8ghj7em9w3skccne9e3k7mf09emk2mrv944kummhdchkcmn4wfk8qtmpd3jhsemvv4shxmmw5uhvxu":
27
30
  return new Response(JSON.stringify({
28
- status: 'OK',
29
- successAction: { tag: 'message', message: 'Thanks, sats received!' },
30
- verify: 'https://getalby.com/lnurlp/alexgleason/verify/sMgdHth68xnS5H1tJtL4kh3T',
31
+ status: "OK",
32
+ successAction: { tag: "message", message: "Thanks, sats received!" },
33
+ verify:
34
+ "https://getalby.com/lnurlp/alexgleason/verify/sMgdHth68xnS5H1tJtL4kh3T",
31
35
  routes: [],
32
36
  pr:
33
- 'lnbc10n1pj6a3pmpp54wsjl3nscygnfsf6uy08cnlf94t64a7cr0pt3t6nmdzm4kq8x6yshp5nf3ugrnz5d5fc5avnrzu8m9ae3e7p4v82cyhtf425dmtv8fn755qcqzzsxqyz5vqsp5m9d6yrj9mu5wwk3kxfdn4hwwmztdjqvdc3z5402gwdc6janx4ltq9qyyssq36wz68vj35pr39e8hkq0ldfauglqfsfyw9u0u4v4dmy7hvg20244jm69ja4g0cmwzxxgmzrqqsgeenxzmsqwhpfrzk7dvezd60u0qcqpd6nhs7',
37
+ "lnbc10n1pj6a3pmpp54wsjl3nscygnfsf6uy08cnlf94t64a7cr0pt3t6nmdzm4kq8x6yshp5nf3ugrnz5d5fc5avnrzu8m9ae3e7p4v82cyhtf425dmtv8fn755qcqzzsxqyz5vqsp5m9d6yrj9mu5wwk3kxfdn4hwwmztdjqvdc3z5402gwdc6janx4ltq9qyyssq36wz68vj35pr39e8hkq0ldfauglqfsfyw9u0u4v4dmy7hvg20244jm69ja4g0cmwzxxgmzrqqsgeenxzmsqwhpfrzk7dvezd60u0qcqpd6nhs7",
34
38
  }));
35
39
  default:
36
40
  throw new Error(`Unexpected URL: ${url}`);
37
41
  }
38
42
  };
39
43
 
40
- Deno.test('LNURL', async (t) => {
41
- await t.step('fromString', () => {
42
- const lnurl = LNURL.fromString(
43
- 'lnurl1dp68gurn8ghj7em9w3skccne9e3k7mf09emk2mrv944kummhdchkcmn4wfk8qtmpd3jhsemvv4shxmmw5uhvxu',
44
- );
45
- assertEquals(lnurl.url.toString(), 'https://getalby.com/.well-known/lnurlp/alexgleason');
46
- });
44
+ await test("LNURL.fromString", () => {
45
+ const lnurl = LNURL.fromString(
46
+ "lnurl1dp68gurn8ghj7em9w3skccne9e3k7mf09emk2mrv944kummhdchkcmn4wfk8qtmpd3jhsemvv4shxmmw5uhvxu",
47
+ );
48
+ deepStrictEqual(
49
+ lnurl.url.toString(),
50
+ "https://getalby.com/.well-known/lnurlp/alexgleason",
51
+ );
52
+ });
47
53
 
48
- await t.step('fromLightningAddress', () => {
49
- const lnurl = LNURL.fromLightningAddress('alexgleason@getalby.com');
50
- assertEquals(lnurl.url.toString(), 'https://getalby.com/.well-known/lnurlp/alexgleason');
51
- });
54
+ await test("LNURL.fromLightningAddress", () => {
55
+ const lnurl = LNURL.fromLightningAddress("alexgleason@getalby.com");
56
+ deepStrictEqual(
57
+ lnurl.url.toString(),
58
+ "https://getalby.com/.well-known/lnurlp/alexgleason",
59
+ );
60
+ });
52
61
 
53
- await t.step('toString', () => {
54
- const lnurl = new LNURL(new URL('https://getalby.com/.well-known/lnurlp/alexgleason'));
55
- assertEquals(
56
- lnurl.toString(),
57
- 'lnurl1dp68gurn8ghj7em9w3skccne9e3k7mf09emk2mrv944kummhdchkcmn4wfk8qtmpd3jhsemvv4shxmmw5uhvxu',
58
- );
59
- });
62
+ await test("LNURL.toString", () => {
63
+ const lnurl = new LNURL(
64
+ new URL("https://getalby.com/.well-known/lnurlp/alexgleason"),
65
+ );
66
+ deepStrictEqual(
67
+ lnurl.toString(),
68
+ "lnurl1dp68gurn8ghj7em9w3skccne9e3k7mf09emk2mrv944kummhdchkcmn4wfk8qtmpd3jhsemvv4shxmmw5uhvxu",
69
+ );
70
+ });
60
71
 
61
- await t.step('getDetails', async () => {
62
- const lnurl = new LNURL(new URL('https://getalby.com/.well-known/lnurlp/alexgleason'), { fetch: mockFetch });
63
- const details = await lnurl.getDetails();
72
+ await test("LNURL.getDetails", async () => {
73
+ const lnurl = new LNURL(
74
+ new URL("https://getalby.com/.well-known/lnurlp/alexgleason"),
75
+ { fetch: mockFetch },
76
+ );
77
+ const details = await lnurl.getDetails();
64
78
 
65
- assertEquals(details, {
66
- tag: 'payRequest',
67
- commentAllowed: 255,
68
- callback: 'https://getalby.com/lnurlp/alexgleason/callback',
69
- metadata: '[["text/identifier","alexgleason@getalby.com"],["text/plain","Sats for alexgleason"]]',
70
- minSendable: 1000,
71
- maxSendable: 100000000,
72
- nostrPubkey: '79f00d3f5a19ec806189fcab03c1be4ff81d18ee4f653c88fac41fe03570f432',
73
- allowsNostr: true,
74
- });
79
+ deepStrictEqual(details, {
80
+ tag: "payRequest",
81
+ commentAllowed: 255,
82
+ callback: "https://getalby.com/lnurlp/alexgleason/callback",
83
+ metadata:
84
+ '[["text/identifier","alexgleason@getalby.com"],["text/plain","Sats for alexgleason"]]',
85
+ minSendable: 1000,
86
+ maxSendable: 100000000,
87
+ nostrPubkey:
88
+ "79f00d3f5a19ec806189fcab03c1be4ff81d18ee4f653c88fac41fe03570f432",
89
+ allowsNostr: true,
75
90
  });
91
+ });
76
92
 
77
- await t.step('getInvoice', async () => {
78
- const lnurl = new LNURL(new URL('https://getalby.com/.well-known/lnurlp/alexgleason'), { fetch: mockFetch });
79
- const invoice = await lnurl.getInvoice({ amount: 1000 });
93
+ await test("LNURL.getInvoice", async () => {
94
+ const lnurl = new LNURL(
95
+ new URL("https://getalby.com/.well-known/lnurlp/alexgleason"),
96
+ { fetch: mockFetch },
97
+ );
98
+ const invoice = await lnurl.getInvoice({ amount: 1000 });
80
99
 
81
- assertEquals(invoice, {
82
- pr:
83
- 'lnbc10n1pj6a3pmpp54wsjl3nscygnfsf6uy08cnlf94t64a7cr0pt3t6nmdzm4kq8x6yshp5nf3ugrnz5d5fc5avnrzu8m9ae3e7p4v82cyhtf425dmtv8fn755qcqzzsxqyz5vqsp5m9d6yrj9mu5wwk3kxfdn4hwwmztdjqvdc3z5402gwdc6janx4ltq9qyyssq36wz68vj35pr39e8hkq0ldfauglqfsfyw9u0u4v4dmy7hvg20244jm69ja4g0cmwzxxgmzrqqsgeenxzmsqwhpfrzk7dvezd60u0qcqpd6nhs7',
84
- routes: [],
85
- });
100
+ deepStrictEqual(invoice, {
101
+ pr:
102
+ "lnbc10n1pj6a3pmpp54wsjl3nscygnfsf6uy08cnlf94t64a7cr0pt3t6nmdzm4kq8x6yshp5nf3ugrnz5d5fc5avnrzu8m9ae3e7p4v82cyhtf425dmtv8fn755qcqzzsxqyz5vqsp5m9d6yrj9mu5wwk3kxfdn4hwwmztdjqvdc3z5402gwdc6janx4ltq9qyyssq36wz68vj35pr39e8hkq0ldfauglqfsfyw9u0u4v4dmy7hvg20244jm69ja4g0cmwzxxgmzrqqsgeenxzmsqwhpfrzk7dvezd60u0qcqpd6nhs7",
103
+ routes: [],
86
104
  });
87
105
  });
package/ln/LNURL.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { NostrEvent } from "@nostrify/types";
2
- import { bech32 } from "@scure/base";
1
+ import type { NostrEvent } from '@nostrify/types';
2
+ import { bech32 } from '@scure/base';
3
3
 
4
- import { LNURLCallback } from "./types/LNURLCallback.js";
5
- import { LNURLDetails } from "./types/LNURLDetails.js";
4
+ import { LNURLCallback } from './types/LNURLCallback.ts';
5
+ import { LNURLDetails } from './types/LNURLDetails.ts';
6
6
 
7
- import { NSchema as n, z } from "../NSchema.js";
7
+ import { NSchema as n, z } from '../NSchema.ts';
8
8
 
9
9
  /**
10
10
  * Represents an LNURL, with methods to fetch details and generate invoices.
@@ -45,7 +45,7 @@ export class LNURL {
45
45
  20000,
46
46
  );
47
47
 
48
- if (prefix !== "lnurl") {
48
+ if (prefix !== 'lnurl') {
49
49
  throw new Error('Expected a bech32 string starting with "lnurl1"');
50
50
  }
51
51
 
@@ -69,7 +69,7 @@ export class LNURL {
69
69
  );
70
70
  }
71
71
 
72
- const [name, host] = ln.split("@");
72
+ const [name, host] = ln.split('@');
73
73
  const url = new URL(`/.well-known/lnurlp/${name}`, `https://${host}`);
74
74
 
75
75
  return new LNURL(url, opts);
@@ -79,7 +79,7 @@ export class LNURL {
79
79
  toString(): `lnurl1${string}` {
80
80
  const data = new TextEncoder().encode(this.url.toString());
81
81
  const words = bech32.toWords(data);
82
- return bech32.encode("lnurl", words, 20000);
82
+ return bech32.encode('lnurl', words, 20000);
83
83
  }
84
84
 
85
85
  /** Resolve an LNURL to its details. */
@@ -101,11 +101,11 @@ export class LNURL {
101
101
  const details = await this.getDetails(opts);
102
102
  const callback = new URL(details.callback);
103
103
 
104
- callback.searchParams.set("amount", opts.amount.toString());
105
- callback.searchParams.set("lnurl", this.toString());
104
+ callback.searchParams.set('amount', opts.amount.toString());
105
+ callback.searchParams.set('lnurl', this.toString());
106
106
 
107
107
  if (opts.nostr) {
108
- callback.searchParams.set("nostr", JSON.stringify(opts.nostr));
108
+ callback.searchParams.set('nostr', JSON.stringify(opts.nostr));
109
109
  }
110
110
 
111
111
  const response = await this.fetch(callback, opts);
@@ -124,13 +124,13 @@ export class LNURL {
124
124
  minSendable: z.number().positive().int(),
125
125
  metadata: z.string(),
126
126
  nostrPubkey: n.id().optional(),
127
- tag: z.literal("payRequest"),
127
+ tag: z.literal('payRequest'),
128
128
  }).superRefine((details, ctx) => {
129
129
  if (details.minSendable > details.maxSendable) {
130
130
  ctx.addIssue({
131
131
  code: z.ZodIssueCode.custom,
132
- message: "minSendable must be less than or equal to maxSendable",
133
- path: ["minSendable"],
132
+ message: 'minSendable must be less than or equal to maxSendable',
133
+ path: ['minSendable'],
134
134
  });
135
135
  }
136
136
  }) as z.ZodType<LNURLDetails>;
@@ -139,7 +139,7 @@ export class LNURL {
139
139
  /** LNURL callback schema. */
140
140
  static lnurlCallbackSchema(): z.ZodType<LNURLCallback> {
141
141
  return z.object({
142
- pr: n.bech32("lnbc"),
142
+ pr: n.bech32('lnbc'),
143
143
  routes: z.tuple([]),
144
144
  }) as unknown as z.ZodType<LNURLCallback>;
145
145
  }