@nostrify/nostrify 0.46.7 → 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 +8 -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 -3
  11. package/NIP05.test.ts +36 -44
  12. package/NIP05.ts +2 -2
  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 -14
  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 -117
  37. package/dist/NIP05.d.ts +1 -1
  38. package/dist/NIP05.d.ts.map +1 -1
  39. package/dist/NIP05.js +33 -33
  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 -208
  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 +5 -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 +46 -17
  117. package/test/mod.ts +4 -4
  118. package/tsconfig.json +5 -2
  119. package/uploaders/BlossomUploader.test.ts +39 -22
  120. package/uploaders/BlossomUploader.ts +2 -2
  121. package/uploaders/NostrBuildUploader.test.ts +36 -18
  122. package/uploaders/NostrBuildUploader.ts +4 -4
  123. package/uploaders/mod.ts +2 -2
  124. package/utils/CircularSet.test.ts +5 -4
  125. package/utils/CircularSet.ts +3 -1
  126. package/utils/Machina.test.ts +30 -19
  127. package/utils/N64.test.ts +12 -11
  128. package/utils/N64.ts +2 -2
  129. package/utils/mod.ts +2 -2
  130. package/dist/BunkerURI.js.map +0 -1
  131. package/dist/NBrowserSigner.js.map +0 -1
  132. package/dist/NCache.js.map +0 -1
  133. package/dist/NConnectSigner.js.map +0 -1
  134. package/dist/NIP05.js.map +0 -1
  135. package/dist/NIP50.js.map +0 -1
  136. package/dist/NIP98.js.map +0 -1
  137. package/dist/NKinds.js.map +0 -1
  138. package/dist/NPool.js.map +0 -1
  139. package/dist/NRelay1.js.map +0 -1
  140. package/dist/NSchema.js.map +0 -1
  141. package/dist/NSecSigner.js.map +0 -1
  142. package/dist/NSet.js.map +0 -1
  143. package/dist/RelayError.js.map +0 -1
  144. package/dist/ln/LNURL.js.map +0 -1
  145. package/dist/ln/types/LNURLCallback.js.map +0 -1
  146. package/dist/ln/types/LNURLDetails.js.map +0 -1
  147. package/dist/test/ErrorRelay.js.map +0 -1
  148. package/dist/test/MockRelay.js.map +0 -1
  149. package/dist/test/TestRelayServer.js.map +0 -1
  150. package/dist/uploaders/BlossomUploader.js.map +0 -1
  151. package/dist/uploaders/NostrBuildUploader.js.map +0 -1
  152. package/dist/utils/CircularSet.js.map +0 -1
  153. package/dist/utils/Machina.js.map +0 -1
  154. package/dist/utils/N64.js.map +0 -1
package/NIP05.test.ts CHANGED
@@ -1,67 +1,59 @@
1
- import { assertEquals, assertRejects } from '@std/assert';
2
- import { returnsNext, stub } from '@std/testing/mock';
1
+ import { test } from "node:test";
2
+ import { deepStrictEqual, rejects } from "node:assert";
3
+ import sinon from "sinon";
3
4
 
4
- import { NIP05 } from './NIP05.ts';
5
+ import { NIP05 } from "./NIP05.ts";
5
6
 
6
- Deno.test('NIP05.lookup', async () => {
7
- const { default: nostrJson } = await import('../../fixtures/nostr.json', { with: { type: 'json' } });
7
+ await test("NIP05.lookup", async () => {
8
+ const { default: nostrJson } = await import("../../fixtures/nostr.json", {
9
+ with: { type: "json" },
10
+ });
8
11
 
9
- const fetch = stub(
10
- globalThis,
11
- 'fetch',
12
- returnsNext([
13
- Promise.resolve(new Response(JSON.stringify(nostrJson))),
14
- ]),
15
- );
12
+ const fetchStub = sinon.stub(globalThis, "fetch");
13
+ fetchStub.resolves(new Response(JSON.stringify(nostrJson)));
16
14
 
17
- const result = await NIP05.lookup('alex_at_gleasonator.com@mostr.pub', { fetch });
15
+ const result = await NIP05.lookup("alex_at_gleasonator.com@mostr.pub", {
16
+ fetch: fetchStub,
17
+ });
18
18
 
19
19
  const expected = {
20
- pubkey: '79c2cae114ea28a981e7559b4fe7854a473521a8d22a66bbab9fa248eb820ff6',
21
- relays: ['wss://relay.mostr.pub'],
20
+ pubkey: "79c2cae114ea28a981e7559b4fe7854a473521a8d22a66bbab9fa248eb820ff6",
21
+ relays: ["wss://relay.mostr.pub"],
22
22
  };
23
23
 
24
- assertEquals(result, expected);
25
- fetch.restore();
24
+ deepStrictEqual(result, expected);
25
+ fetchStub.restore();
26
26
  });
27
27
 
28
28
  // https://github.com/nostrability/nostrability/issues/143#issuecomment-2565772246
29
- Deno.test('NIP05.lookup with invalid values but valid profile pointer', async () => {
30
- const { default: nostrJson } = await import('../../fixtures/lncal.json', { with: { type: 'json' } });
29
+ await test("NIP05.lookup with invalid values but valid profile pointer", async () => {
30
+ const { default: nostrJson } = await import("../../fixtures/lncal.json", {
31
+ with: { type: "json" },
32
+ });
31
33
 
32
- const fetch = stub(
33
- globalThis,
34
- 'fetch',
35
- returnsNext([
36
- Promise.resolve(new Response(JSON.stringify(nostrJson))),
37
- ]),
38
- );
34
+ const fetchStub = sinon.stub(globalThis, "fetch");
35
+ fetchStub.resolves(new Response(JSON.stringify(nostrJson)));
39
36
 
40
- const result = await NIP05.lookup('elsat@lncal.com', { fetch });
37
+ const result = await NIP05.lookup("elsat@lncal.com", { fetch: fetchStub });
41
38
 
42
39
  const expected = {
43
- pubkey: '17538dc2a62769d09443f18c37cbe358fab5bbf981173542aa7c5ff171ed77c4',
40
+ pubkey: "17538dc2a62769d09443f18c37cbe358fab5bbf981173542aa7c5ff171ed77c4",
44
41
  relays: undefined,
45
42
  };
46
43
 
47
- assertEquals(result, expected);
48
- fetch.restore();
44
+ deepStrictEqual(result, expected);
45
+ fetchStub.restore();
49
46
  });
50
47
 
51
- Deno.test('NIP05.lookup with invalid document', () => {
52
- const fetch = stub(
53
- globalThis,
54
- 'fetch',
55
- returnsNext([
56
- Promise.resolve(new Response(JSON.stringify({ names: 'yolo' }))),
57
- Promise.resolve(new Response(JSON.stringify({}))),
58
- Promise.resolve(new Response(JSON.stringify([]))),
59
- ]),
60
- );
48
+ await test("NIP05.lookup with invalid document", () => {
49
+ const fetchStub = sinon.stub(globalThis, "fetch");
50
+ fetchStub.onCall(0).resolves(new Response(JSON.stringify({ names: "yolo" })));
51
+ fetchStub.onCall(1).resolves(new Response(JSON.stringify({})));
52
+ fetchStub.onCall(2).resolves(new Response(JSON.stringify([])));
61
53
 
62
- assertRejects(() => NIP05.lookup('alex@gleasonator.dev', { fetch }));
63
- assertRejects(() => NIP05.lookup('alex@gleasonator.dev', { fetch }));
64
- assertRejects(() => NIP05.lookup('alex@gleasonator.dev', { fetch }));
54
+ rejects(() => NIP05.lookup("alex@gleasonator.dev", { fetch: fetchStub }));
55
+ rejects(() => NIP05.lookup("alex@gleasonator.dev", { fetch: fetchStub }));
56
+ rejects(() => NIP05.lookup("alex@gleasonator.dev", { fetch: fetchStub }));
65
57
 
66
- fetch.restore();
58
+ fetchStub.restore();
67
59
  });
package/NIP05.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { NProfilePointer } from '@nostrify/types';
1
+ import type { NProfilePointer } from '@nostrify/types';
2
2
 
3
- import { NSchema as n, z } from './NSchema.js';
3
+ import { NSchema as n, z } from './NSchema.ts';
4
4
 
5
5
  interface LookupOpts {
6
6
  fetch?: typeof fetch;
package/NIP50.test.ts CHANGED
@@ -1,58 +1,59 @@
1
- import { assertEquals } from '@std/assert';
1
+ import { test } from "node:test";
2
+ import { deepStrictEqual } from "node:assert";
2
3
 
3
- import { NIP50 } from './NIP50.ts';
4
+ import { NIP50 } from "./NIP50.ts";
4
5
 
5
- Deno.test('NIP50.parseInput', () => {
6
- assertEquals(NIP50.parseInput(''), []);
7
- assertEquals(NIP50.parseInput(' '), []);
8
- assertEquals(NIP50.parseInput('hello'), ['hello']);
9
- assertEquals(NIP50.parseInput('hello world'), ['hello', 'world']);
10
- assertEquals(NIP50.parseInput('hello "world"'), ['hello', 'world']);
6
+ await test("NIP50.parseInput", () => {
7
+ deepStrictEqual(NIP50.parseInput(""), []);
8
+ deepStrictEqual(NIP50.parseInput(" "), []);
9
+ deepStrictEqual(NIP50.parseInput("hello"), ["hello"]);
10
+ deepStrictEqual(NIP50.parseInput("hello world"), ["hello", "world"]);
11
+ deepStrictEqual(NIP50.parseInput('hello "world"'), ["hello", "world"]);
11
12
 
12
- assertEquals(
13
+ deepStrictEqual(
13
14
  NIP50.parseInput('hello "world" "hello world"'),
14
- ['hello', 'world', 'hello world'],
15
+ ["hello", "world", "hello world"],
15
16
  );
16
17
 
17
- assertEquals(
18
- NIP50.parseInput('domain:gleasonator.dev'),
19
- [{ key: 'domain', value: 'gleasonator.dev' }],
18
+ deepStrictEqual(
19
+ NIP50.parseInput("domain:gleasonator.dev"),
20
+ [{ key: "domain", value: "gleasonator.dev" }],
20
21
  );
21
22
 
22
- assertEquals(
23
- NIP50.parseInput('domain: yolo'),
24
- ['domain:', 'yolo'],
23
+ deepStrictEqual(
24
+ NIP50.parseInput("domain: yolo"),
25
+ ["domain:", "yolo"],
25
26
  );
26
27
 
27
- assertEquals(
28
- NIP50.parseInput('domain:localhost:8000'),
29
- [{ key: 'domain', value: 'localhost:8000' }],
28
+ deepStrictEqual(
29
+ NIP50.parseInput("domain:localhost:8000"),
30
+ [{ key: "domain", value: "localhost:8000" }],
30
31
  );
31
32
 
32
- assertEquals(
33
+ deepStrictEqual(
33
34
  NIP50.parseInput('name:John "New York" age:30 hobbies:programming'),
34
35
  [
35
- { key: 'name', value: 'John' },
36
- 'New York',
37
- { key: 'age', value: '30' },
38
- { key: 'hobbies', value: 'programming' },
36
+ { key: "name", value: "John" },
37
+ "New York",
38
+ { key: "age", value: "30" },
39
+ { key: "hobbies", value: "programming" },
39
40
  ],
40
41
  );
41
42
  });
42
43
 
43
- Deno.test('NIP50.parseInput with negated token', () => {
44
- assertEquals(
45
- NIP50.parseInput('-reply:true'),
46
- [{ key: '-reply', value: 'true' }],
44
+ await test("NIP50.parseInput with negated token", () => {
45
+ deepStrictEqual(
46
+ NIP50.parseInput("-reply:true"),
47
+ [{ key: "-reply", value: "true" }],
47
48
  );
48
49
 
49
- assertEquals(
50
- NIP50.parseInput('hello -reply:true'),
51
- ['hello', { key: '-reply', value: 'true' }],
50
+ deepStrictEqual(
51
+ NIP50.parseInput("hello -reply:true"),
52
+ ["hello", { key: "-reply", value: "true" }],
52
53
  );
53
54
 
54
- assertEquals(
55
- NIP50.parseInput('-media:true -reply:true'),
56
- [{ key: '-media', value: 'true' }, { key: '-reply', value: 'true' }],
55
+ deepStrictEqual(
56
+ NIP50.parseInput("-media:true -reply:true"),
57
+ [{ key: "-media", value: "true" }, { key: "-reply", value: "true" }],
57
58
  );
58
59
  });
package/NIP98.test.ts CHANGED
@@ -1,181 +1,194 @@
1
- import { assertEquals, assertRejects } from '@std/assert';
2
- import { generateSecretKey } from 'nostr-tools';
3
- import { ZodError } from 'zod';
1
+ import { test } from "node:test";
2
+ import { deepStrictEqual, rejects } from "node:assert";
3
+ import { generateSecretKey } from "nostr-tools";
4
+ import { ZodError } from "zod";
4
5
 
5
- import { NIP98 } from './NIP98.ts';
6
- import { NSecSigner } from './NSecSigner.ts';
7
- import { N64 } from './utils/mod.ts';
6
+ import { NIP98 } from "./NIP98.ts";
7
+ import { NSecSigner } from "./NSecSigner.ts";
8
+ import { N64 } from "./utils/mod.ts";
8
9
 
9
- Deno.test('NIP98.template', async () => {
10
- const request = new Request('https://example.com');
10
+ await test("NIP98.template", async () => {
11
+ const request = new Request("https://example.com");
11
12
  const event = await NIP98.template(request);
12
13
 
13
- assertEquals(event.kind, 27235);
14
- assertEquals(event.tags, [
15
- ['method', 'GET'],
16
- ['u', 'https://example.com/'],
14
+ deepStrictEqual(event.kind, 27235);
15
+ deepStrictEqual(event.tags, [
16
+ ["method", "GET"],
17
+ ["u", "https://example.com/"],
17
18
  ]);
18
19
  });
19
20
 
20
- Deno.test('NIP98.template with payload', async () => {
21
- const request = new Request('https://example.com', {
22
- method: 'POST',
23
- body: 'Hello, world!',
21
+ await test("NIP98.template with payload", async () => {
22
+ const request = new Request("https://example.com", {
23
+ method: "POST",
24
+ body: "Hello, world!",
24
25
  });
25
26
  const event = await NIP98.template(request);
26
27
 
27
- assertEquals(event.kind, 27235);
28
- assertEquals(event.tags, [
29
- ['method', 'POST'],
30
- ['u', 'https://example.com/'],
31
- ['payload', '315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3'],
28
+ deepStrictEqual(event.kind, 27235);
29
+ deepStrictEqual(event.tags, [
30
+ ["method", "POST"],
31
+ ["u", "https://example.com/"],
32
+ [
33
+ "payload",
34
+ "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3",
35
+ ],
32
36
  ]);
33
37
  });
34
38
 
35
- Deno.test('NIP98.verify', async () => {
39
+ await test("NIP98.verify", async () => {
36
40
  const signer = new NSecSigner(generateSecretKey());
37
- const request = new Request('https://example.com');
41
+ const request = new Request("https://example.com");
38
42
 
39
43
  const t = await NIP98.template(request);
40
44
  const event = await signer.signEvent(t);
41
45
 
42
- request.headers.set('authorization', `Nostr ${N64.encodeEvent(event)}`);
46
+ request.headers.set("authorization", `Nostr ${N64.encodeEvent(event)}`);
43
47
 
44
48
  const proof = await NIP98.verify(request);
45
49
 
46
- assertEquals(proof, event);
47
- assertEquals(proof.pubkey, await signer.getPublicKey());
50
+ deepStrictEqual(proof, event);
51
+ deepStrictEqual(proof.pubkey, await signer.getPublicKey());
48
52
  });
49
53
 
50
- Deno.test('NIP98.verify fails with missing header', async () => {
51
- const request = new Request('https://example.com');
54
+ await test("NIP98.verify fails with missing header", async () => {
55
+ const request = new Request("https://example.com");
52
56
 
53
- await assertRejects(
57
+ await rejects(
54
58
  () => NIP98.verify(request),
55
59
  Error,
56
- 'Missing Nostr authorization header',
60
+ "Missing Nostr authorization header",
57
61
  );
58
62
  });
59
63
 
60
- Deno.test('NIP98.verify fails with missing token', async () => {
61
- const request = new Request('https://example.com');
62
- request.headers.set('authorization', 'Nostr');
64
+ await test("NIP98.verify fails with missing token", async () => {
65
+ const request = new Request("https://example.com");
66
+ request.headers.set("authorization", "Nostr");
63
67
 
64
- await assertRejects(
68
+ await rejects(
65
69
  () => NIP98.verify(request),
66
70
  Error,
67
- 'Missing Nostr authorization token',
71
+ "Missing Nostr authorization token",
68
72
  );
69
73
  });
70
74
 
71
- Deno.test('NIP98.verify fails with invalid token', async () => {
72
- const request = new Request('https://example.com');
73
- request.headers.set('authorization', 'Nostr invalid');
75
+ await test("NIP98.verify fails with invalid token", async () => {
76
+ const request = new Request("https://example.com");
77
+ request.headers.set("authorization", "Nostr invalid");
74
78
 
75
- await assertRejects(
79
+ await rejects(
76
80
  () => NIP98.verify(request),
77
81
  ZodError,
78
82
  );
79
83
  });
80
84
 
81
- Deno.test('NIP98.verify fails with invalid event', async () => {
85
+ await test("NIP98.verify fails with invalid event", async () => {
82
86
  const signer = new NSecSigner(generateSecretKey());
83
- const request = new Request('https://example.com');
87
+ const request = new Request("https://example.com");
84
88
 
85
89
  const t = await NIP98.template(request);
86
90
  const event = await signer.signEvent(t);
87
91
 
88
- event.sig = 'invalid';
92
+ event.sig = "invalid";
89
93
 
90
- request.headers.set('authorization', `Nostr ${N64.encodeEvent(event)}`);
94
+ request.headers.set("authorization", `Nostr ${N64.encodeEvent(event)}`);
91
95
 
92
- await assertRejects(
96
+ await rejects(
93
97
  () => NIP98.verify(request),
94
98
  Error,
95
- 'Event signature is invalid',
99
+ "Event signature is invalid",
96
100
  );
97
101
  });
98
102
 
99
- Deno.test('NIP98.verify fails with wrong event kind', async () => {
103
+ await test("NIP98.verify fails with wrong event kind", async () => {
100
104
  const signer = new NSecSigner(generateSecretKey());
101
- const request = new Request('https://example.com');
105
+ const request = new Request("https://example.com");
102
106
 
103
107
  const t = await NIP98.template(request);
104
108
  const event = await signer.signEvent({ ...t, kind: 1 });
105
109
 
106
- request.headers.set('authorization', `Nostr ${N64.encodeEvent(event)}`);
110
+ request.headers.set("authorization", `Nostr ${N64.encodeEvent(event)}`);
107
111
 
108
- await assertRejects(
112
+ await rejects(
109
113
  () => NIP98.verify(request),
110
114
  Error,
111
- 'Event must be kind 27235',
115
+ "Event must be kind 27235",
112
116
  );
113
117
  });
114
118
 
115
- Deno.test('NIP98.verify fails with wrong request URL', async () => {
119
+ await test("NIP98.verify fails with wrong request URL", async () => {
116
120
  const signer = new NSecSigner(generateSecretKey());
117
- const request = new Request('https://example.com');
121
+ const request = new Request("https://example.com");
118
122
 
119
123
  const t = await NIP98.template(request);
120
- const event = await signer.signEvent({ ...t, tags: [['u', 'https://example.org/']] });
124
+ const event = await signer.signEvent({
125
+ ...t,
126
+ tags: [["u", "https://example.org/"]],
127
+ });
121
128
 
122
- request.headers.set('authorization', `Nostr ${N64.encodeEvent(event)}`);
129
+ request.headers.set("authorization", `Nostr ${N64.encodeEvent(event)}`);
123
130
 
124
- await assertRejects(
131
+ await rejects(
125
132
  () => NIP98.verify(request),
126
133
  Error,
127
- 'Event URL does not match request URL',
134
+ "Event URL does not match request URL",
128
135
  );
129
136
  });
130
137
 
131
- Deno.test('NIP98.verify fails with wrong request method', async () => {
138
+ await test("NIP98.verify fails with wrong request method", async () => {
132
139
  const signer = new NSecSigner(generateSecretKey());
133
- const request = new Request('https://example.com');
140
+ const request = new Request("https://example.com");
134
141
 
135
142
  const t = await NIP98.template(request);
136
- const event = await signer.signEvent({ ...t, tags: [['u', 'https://example.com/'], ['method', 'POST']] });
143
+ const event = await signer.signEvent({
144
+ ...t,
145
+ tags: [["u", "https://example.com/"], ["method", "POST"]],
146
+ });
137
147
 
138
- request.headers.set('authorization', `Nostr ${N64.encodeEvent(event)}`);
148
+ request.headers.set("authorization", `Nostr ${N64.encodeEvent(event)}`);
139
149
 
140
- await assertRejects(
150
+ await rejects(
141
151
  () => NIP98.verify(request),
142
152
  Error,
143
- 'Event method does not match HTTP request method',
153
+ "Event method does not match HTTP request method",
144
154
  );
145
155
  });
146
156
 
147
- Deno.test('NIP98.verify fails with expired event', async () => {
157
+ await test("NIP98.verify fails with expired event", async () => {
148
158
  const signer = new NSecSigner(generateSecretKey());
149
- const request = new Request('https://example.com');
159
+ const request = new Request("https://example.com");
150
160
 
151
161
  const t = await NIP98.template(request);
152
162
  const event = await signer.signEvent({ ...t, created_at: 0 });
153
163
 
154
- request.headers.set('authorization', `Nostr ${N64.encodeEvent(event)}`);
164
+ request.headers.set("authorization", `Nostr ${N64.encodeEvent(event)}`);
155
165
 
156
- await assertRejects(
166
+ await rejects(
157
167
  () => NIP98.verify(request),
158
168
  Error,
159
- 'Event expired',
169
+ "Event expired",
160
170
  );
161
171
  });
162
172
 
163
- Deno.test('NIP98.verify fails with invalid payload', async () => {
173
+ await test("NIP98.verify fails with invalid payload", async () => {
164
174
  const signer = new NSecSigner(generateSecretKey());
165
- const request = new Request('https://example.com', {
166
- method: 'POST',
167
- body: 'Hello, world!',
175
+ const request = new Request("https://example.com", {
176
+ method: "POST",
177
+ body: "Hello, world!",
168
178
  });
169
179
 
170
180
  const t = await NIP98.template(request);
171
- const tags = t.tags.filter(([name]) => name !== 'payload');
172
- const event = await signer.signEvent({ ...t, tags: [...tags, ['payload', 'invalid']] });
181
+ const tags = t.tags.filter(([name]) => name !== "payload");
182
+ const event = await signer.signEvent({
183
+ ...t,
184
+ tags: [...tags, ["payload", "invalid"]],
185
+ });
173
186
 
174
- request.headers.set('authorization', `Nostr ${N64.encodeEvent(event)}`);
187
+ request.headers.set("authorization", `Nostr ${N64.encodeEvent(event)}`);
175
188
 
176
- await assertRejects(
189
+ await rejects(
177
190
  () => NIP98.verify(request),
178
191
  Error,
179
- 'Event payload does not match request body',
192
+ "Event payload does not match request body",
180
193
  );
181
194
  });
package/NIP98.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { NostrEvent } from '@nostrify/types';
1
+ import type { NostrEvent } from '@nostrify/types';
2
2
  import { encodeHex } from '@std/encoding/hex';
3
3
  import { verifyEvent as _verifyEvent } from 'nostr-tools';
4
4
 
5
- import { N64 } from './utils/N64.js';
5
+ import { N64 } from './utils/N64.ts';
6
6
 
7
7
  /** [NIP-98](https://github.com/nostr-protocol/nips/blob/master/98.md) HTTP auth. */
8
8
  export class NIP98 {
package/NKinds.test.ts CHANGED
@@ -1,42 +1,43 @@
1
- import { assertEquals } from '@std/assert';
1
+ import { test } from "node:test";
2
+ import { deepStrictEqual } from "node:assert";
2
3
 
3
- import { NKinds } from './NKinds.ts';
4
+ import { NKinds } from "./NKinds.ts";
4
5
 
5
- Deno.test('NKinds', () => {
6
- assertEquals(NKinds.regular(1000), true);
7
- assertEquals(NKinds.regular(10000), false);
8
- assertEquals(NKinds.regular(0), false);
9
- assertEquals(NKinds.regular(44), true);
10
- assertEquals(NKinds.regular(45), false);
11
- assertEquals(NKinds.regular(100000), false);
6
+ await test("NKinds", () => {
7
+ deepStrictEqual(NKinds.regular(1000), true);
8
+ deepStrictEqual(NKinds.regular(10000), false);
9
+ deepStrictEqual(NKinds.regular(0), false);
10
+ deepStrictEqual(NKinds.regular(44), true);
11
+ deepStrictEqual(NKinds.regular(45), false);
12
+ deepStrictEqual(NKinds.regular(100000), false);
12
13
 
13
- assertEquals(NKinds.replaceable(1000), false);
14
- assertEquals(NKinds.replaceable(10000), true);
15
- assertEquals(NKinds.replaceable(0), true);
16
- assertEquals(NKinds.replaceable(3), true);
17
- assertEquals(NKinds.replaceable(44), false);
18
- assertEquals(NKinds.replaceable(45), false);
19
- assertEquals(NKinds.replaceable(100000), false);
14
+ deepStrictEqual(NKinds.replaceable(1000), false);
15
+ deepStrictEqual(NKinds.replaceable(10000), true);
16
+ deepStrictEqual(NKinds.replaceable(0), true);
17
+ deepStrictEqual(NKinds.replaceable(3), true);
18
+ deepStrictEqual(NKinds.replaceable(44), false);
19
+ deepStrictEqual(NKinds.replaceable(45), false);
20
+ deepStrictEqual(NKinds.replaceable(100000), false);
20
21
 
21
- assertEquals(NKinds.ephemeral(1000), false);
22
- assertEquals(NKinds.ephemeral(10000), false);
23
- assertEquals(NKinds.ephemeral(0), false);
24
- assertEquals(NKinds.ephemeral(3), false);
25
- assertEquals(NKinds.ephemeral(44), false);
26
- assertEquals(NKinds.ephemeral(45), false);
27
- assertEquals(NKinds.ephemeral(20000), true);
28
- assertEquals(NKinds.ephemeral(30000), false);
29
- assertEquals(NKinds.ephemeral(40000), false);
30
- assertEquals(NKinds.ephemeral(100000), false);
22
+ deepStrictEqual(NKinds.ephemeral(1000), false);
23
+ deepStrictEqual(NKinds.ephemeral(10000), false);
24
+ deepStrictEqual(NKinds.ephemeral(0), false);
25
+ deepStrictEqual(NKinds.ephemeral(3), false);
26
+ deepStrictEqual(NKinds.ephemeral(44), false);
27
+ deepStrictEqual(NKinds.ephemeral(45), false);
28
+ deepStrictEqual(NKinds.ephemeral(20000), true);
29
+ deepStrictEqual(NKinds.ephemeral(30000), false);
30
+ deepStrictEqual(NKinds.ephemeral(40000), false);
31
+ deepStrictEqual(NKinds.ephemeral(100000), false);
31
32
 
32
- assertEquals(NKinds.addressable(1000), false);
33
- assertEquals(NKinds.addressable(10000), false);
34
- assertEquals(NKinds.addressable(0), false);
35
- assertEquals(NKinds.addressable(3), false);
36
- assertEquals(NKinds.addressable(44), false);
37
- assertEquals(NKinds.addressable(45), false);
38
- assertEquals(NKinds.addressable(20000), false);
39
- assertEquals(NKinds.addressable(30000), true);
40
- assertEquals(NKinds.addressable(40000), false);
41
- assertEquals(NKinds.addressable(100000), false);
33
+ deepStrictEqual(NKinds.addressable(1000), false);
34
+ deepStrictEqual(NKinds.addressable(10000), false);
35
+ deepStrictEqual(NKinds.addressable(0), false);
36
+ deepStrictEqual(NKinds.addressable(3), false);
37
+ deepStrictEqual(NKinds.addressable(44), false);
38
+ deepStrictEqual(NKinds.addressable(45), false);
39
+ deepStrictEqual(NKinds.addressable(20000), false);
40
+ deepStrictEqual(NKinds.addressable(30000), true);
41
+ deepStrictEqual(NKinds.addressable(40000), false);
42
+ deepStrictEqual(NKinds.addressable(100000), false);
42
43
  });