@nostrify/react 0.2.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 (92) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/LICENSE +21 -0
  3. package/NostrContext.ts +17 -0
  4. package/README.md +82 -0
  5. package/dist/NostrContext.d.ts +13 -0
  6. package/dist/NostrContext.d.ts.map +1 -0
  7. package/dist/NostrContext.js +10 -0
  8. package/dist/NostrContext.js.map +1 -0
  9. package/dist/example/test-helpers.d.ts +2 -0
  10. package/dist/example/test-helpers.d.ts.map +1 -0
  11. package/dist/example/test-helpers.js +34 -0
  12. package/dist/example/test-helpers.js.map +1 -0
  13. package/dist/example/useAuthor.d.ts +5 -0
  14. package/dist/example/useAuthor.d.ts.map +1 -0
  15. package/dist/example/useAuthor.js +30 -0
  16. package/dist/example/useAuthor.js.map +1 -0
  17. package/dist/example/useCurrentUser.d.ts +9 -0
  18. package/dist/example/useCurrentUser.d.ts.map +1 -0
  19. package/dist/example/useCurrentUser.js +45 -0
  20. package/dist/example/useCurrentUser.js.map +1 -0
  21. package/dist/example/useLoginActions.d.ts +6 -0
  22. package/dist/example/useLoginActions.d.ts.map +1 -0
  23. package/dist/example/useLoginActions.js +24 -0
  24. package/dist/example/useLoginActions.js.map +1 -0
  25. package/dist/example/useSocialFeed.d.ts +4 -0
  26. package/dist/example/useSocialFeed.d.ts.map +1 -0
  27. package/dist/example/useSocialFeed.js +13 -0
  28. package/dist/example/useSocialFeed.js.map +1 -0
  29. package/dist/login/NLogin.d.ts +46 -0
  30. package/dist/login/NLogin.d.ts.map +1 -0
  31. package/dist/login/NLogin.js +76 -0
  32. package/dist/login/NLogin.js.map +1 -0
  33. package/dist/login/NUser.d.ts +22 -0
  34. package/dist/login/NUser.d.ts.map +1 -0
  35. package/dist/login/NUser.js +41 -0
  36. package/dist/login/NUser.js.map +1 -0
  37. package/dist/login/NostrLoginContext.d.ts +24 -0
  38. package/dist/login/NostrLoginContext.d.ts.map +1 -0
  39. package/dist/login/NostrLoginContext.js +10 -0
  40. package/dist/login/NostrLoginContext.js.map +1 -0
  41. package/dist/login/NostrLoginProvider.d.ts +15 -0
  42. package/dist/login/NostrLoginProvider.d.ts.map +1 -0
  43. package/dist/login/NostrLoginProvider.js +23 -0
  44. package/dist/login/NostrLoginProvider.js.map +1 -0
  45. package/dist/login/mod.d.ts +5 -0
  46. package/dist/login/mod.d.ts.map +1 -0
  47. package/dist/login/mod.js +12 -0
  48. package/dist/login/mod.js.map +1 -0
  49. package/dist/login/nostrLoginReducer.d.ts +16 -0
  50. package/dist/login/nostrLoginReducer.d.ts.map +1 -0
  51. package/dist/login/nostrLoginReducer.js +29 -0
  52. package/dist/login/nostrLoginReducer.js.map +1 -0
  53. package/dist/login/useNostrLogin.d.ts +3 -0
  54. package/dist/login/useNostrLogin.d.ts.map +1 -0
  55. package/dist/login/useNostrLogin.js +13 -0
  56. package/dist/login/useNostrLogin.js.map +1 -0
  57. package/dist/login/useNostrLoginReducer.d.ts +4 -0
  58. package/dist/login/useNostrLoginReducer.d.ts.map +1 -0
  59. package/dist/login/useNostrLoginReducer.js +16 -0
  60. package/dist/login/useNostrLoginReducer.js.map +1 -0
  61. package/dist/mod.d.ts +3 -0
  62. package/dist/mod.d.ts.map +1 -0
  63. package/dist/mod.js +8 -0
  64. package/dist/mod.js.map +1 -0
  65. package/dist/tsconfig.tsbuildinfo +1 -0
  66. package/dist/useNostr.d.ts +3 -0
  67. package/dist/useNostr.d.ts.map +1 -0
  68. package/dist/useNostr.js +13 -0
  69. package/dist/useNostr.js.map +1 -0
  70. package/example/App.tsx +71 -0
  71. package/example/NostrProvider.tsx +36 -0
  72. package/example/index.html +12 -0
  73. package/example/main.tsx +31 -0
  74. package/example/test-helpers.ts +33 -0
  75. package/example/useAuthor.ts +37 -0
  76. package/example/useCurrentUser.ts +48 -0
  77. package/example/useLoginActions.ts +22 -0
  78. package/example/useSocialFeed.ts +18 -0
  79. package/example/vite-env.d.ts +1 -0
  80. package/example/vite.config.mts +8 -0
  81. package/login/NLogin.ts +120 -0
  82. package/login/NUser.ts +56 -0
  83. package/login/NostrLoginContext.ts +28 -0
  84. package/login/NostrLoginProvider.ts +34 -0
  85. package/login/mod.ts +4 -0
  86. package/login/nostrLoginReducer.ts +42 -0
  87. package/login/useNostrLogin.ts +13 -0
  88. package/login/useNostrLoginReducer.ts +20 -0
  89. package/mod.ts +2 -0
  90. package/package.json +27 -0
  91. package/tsconfig.json +14 -0
  92. package/useNostr.ts +13 -0
@@ -0,0 +1,5 @@
1
+
2
+
3
+ > @nostrify/react@0.2.8 build /home/sid/repos/NSpec/packages/react
4
+ > tsc -p tsconfig.json
5
+
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Alex Gleason
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,17 @@
1
+ import { type Context, createContext } from 'react';
2
+
3
+ import type { NPool } from '@nostrify/nostrify';
4
+
5
+ /** The shape of the Nostr context provided by NostrProvider. */
6
+ export interface NostrContextType {
7
+ /** The Nostr relay pool for querying and publishing events */
8
+ nostr: NPool;
9
+ }
10
+
11
+ /**
12
+ * React context for Nostr functionality.
13
+ * Use this with useContext or the useNostr hook to access Nostr features.
14
+ */
15
+ export const NostrContext: Context<NostrContextType | undefined> = createContext<NostrContextType | undefined>(
16
+ undefined,
17
+ );
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # @nostrify/react
2
+
3
+ React components and hooks for Nostrify, a comprehensive Nostr framework.
4
+
5
+ ## Installation
6
+
7
+ ::: code-group
8
+
9
+ ```sh [npm]
10
+ npx jsr add @nostrify/react
11
+ ```
12
+
13
+ ```sh [Deno]
14
+ deno add jsr:@nostrify/react
15
+ ```
16
+
17
+ ```sh [yarn]
18
+ yarn add jsr:@nostrify/react
19
+ ```
20
+
21
+ ```sh [pnpm]
22
+ pnpm add jsr:@nostrify/react
23
+ ```
24
+
25
+ ```sh [Bun]
26
+ bunx jsr add @nostrify/react
27
+ ```
28
+
29
+ :::
30
+
31
+ ## Usage
32
+
33
+ ### NostrContext Provider
34
+
35
+ ```tsx
36
+ import { NostrContext } from '@nostrify/react';
37
+ import { NRelay1 } from '@nostrify/nostrify';
38
+
39
+ function App() {
40
+ return (
41
+ <NostrContext.Provider
42
+ value={{
43
+ relay: new NRelay1('wss://relay.example.com'),
44
+ }}
45
+ >
46
+ <YourApp />
47
+ </NostrContext.Provider>
48
+ );
49
+ }
50
+ ```
51
+
52
+ ### Login Provider
53
+
54
+ ```tsx
55
+ import { NostrLoginProvider } from '@nostrify/react/login';
56
+
57
+ function App() {
58
+ return (
59
+ <NostrLoginProvider storageKey='nostrify-logins'>
60
+ <YourApp />
61
+ </NostrLoginProvider>
62
+ );
63
+ }
64
+ ```
65
+
66
+ ### Using Hooks
67
+
68
+ ```tsx
69
+ import { useNostr } from '@nostrify/react';
70
+ import { useNostrLogin } from '@nostrify/react/login';
71
+
72
+ function YourComponent() {
73
+ const { relay } = useNostr();
74
+ const { logins, addLogin, removeLogin } = useNostrLogin();
75
+
76
+ // Your component logic here
77
+ }
78
+ ```
79
+
80
+ ## Developer Notes
81
+
82
+ This package uses a preprocess script to compile TSX files to JavaScript for Node.js compatibility.
@@ -0,0 +1,13 @@
1
+ import { type Context } from 'react';
2
+ import type { NPool } from '@nostrify/nostrify';
3
+ /** The shape of the Nostr context provided by NostrProvider. */
4
+ export interface NostrContextType {
5
+ /** The Nostr relay pool for querying and publishing events */
6
+ nostr: NPool;
7
+ }
8
+ /**
9
+ * React context for Nostr functionality.
10
+ * Use this with useContext or the useNostr hook to access Nostr features.
11
+ */
12
+ export declare const NostrContext: Context<NostrContextType | undefined>;
13
+ //# sourceMappingURL=NostrContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NostrContext.d.ts","sourceRoot":"","sources":["../NostrContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,OAAO,CAAC;AAEpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,gEAAgE;AAChE,MAAM,WAAW,gBAAgB;IAC/B,8DAA8D;IAC9D,KAAK,EAAE,KAAK,CAAC;CACd;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAE9D,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NostrContext = void 0;
4
+ const react_1 = require("react");
5
+ /**
6
+ * React context for Nostr functionality.
7
+ * Use this with useContext or the useNostr hook to access Nostr features.
8
+ */
9
+ exports.NostrContext = (0, react_1.createContext)(undefined);
10
+ //# sourceMappingURL=NostrContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NostrContext.js","sourceRoot":"","sources":["../NostrContext.ts"],"names":[],"mappings":";;;AAAA,iCAAoD;AAUpD;;;GAGG;AACU,QAAA,YAAY,GAA0C,IAAA,qBAAa,EAC9E,SAAS,CACV,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function polyfillDOM(): void;
2
+ //# sourceMappingURL=test-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["../../example/test-helpers.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,IAAI,IAAI,CA8BlC"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.polyfillDOM = polyfillDOM;
4
+ const happy_dom_1 = require("happy-dom");
5
+ function polyfillDOM() {
6
+ const window = new happy_dom_1.Window();
7
+ const document = window.document;
8
+ const browserWindow = document[happy_dom_1.PropertySymbol.window];
9
+ const setInnerHTML = (html) => document.documentElement.innerHTML = html;
10
+ const cancelAsync = () => window.happyDOM.abort();
11
+ Object.assign(globalThis, {
12
+ window,
13
+ document,
14
+ HTMLElement: browserWindow.HTMLElement,
15
+ Element: browserWindow.Element,
16
+ Node: browserWindow.Node,
17
+ navigator: browserWindow.navigator,
18
+ DocumentFragment: browserWindow.DocumentFragment,
19
+ DocumentType: browserWindow.DocumentType,
20
+ SVGElement: browserWindow.SVGElement,
21
+ Text: browserWindow.Text,
22
+ requestAnimationFrame: browserWindow.requestAnimationFrame,
23
+ cancelAnimationFrame: browserWindow.cancelAnimationFrame,
24
+ setTimeout: browserWindow.setTimeout,
25
+ clearTimeout: browserWindow.clearTimeout,
26
+ setInterval: browserWindow.setInterval,
27
+ clearInterval: browserWindow.clearInterval,
28
+ queueMicrotask: browserWindow.queueMicrotask,
29
+ AbortController: browserWindow.AbortController,
30
+ cancelAsync,
31
+ setInnerHTML,
32
+ });
33
+ }
34
+ //# sourceMappingURL=test-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-helpers.js","sourceRoot":"","sources":["../../example/test-helpers.ts"],"names":[],"mappings":";;AAEA,kCA8BC;AAhCD,yCAAmD;AAEnD,SAAgB,WAAW;IACzB,MAAM,MAAM,GAAG,IAAI,kBAAM,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IACjC,MAAM,aAAa,GAAG,QAAQ,CAAC,0BAAc,CAAC,MAAM,CAAC,CAAC;IAEtD,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC,SAAS,GAAG,IAAI,CAAC;IACjF,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAElD,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE;QACxB,MAAM;QACN,QAAQ;QACR,WAAW,EAAE,aAAa,CAAC,WAAW;QACtC,OAAO,EAAE,aAAa,CAAC,OAAO;QAC9B,IAAI,EAAE,aAAa,CAAC,IAAI;QACxB,SAAS,EAAE,aAAa,CAAC,SAAS;QAClC,gBAAgB,EAAE,aAAa,CAAC,gBAAgB;QAChD,YAAY,EAAE,aAAa,CAAC,YAAY;QACxC,UAAU,EAAE,aAAa,CAAC,UAAU;QACpC,IAAI,EAAE,aAAa,CAAC,IAAI;QACxB,qBAAqB,EAAE,aAAa,CAAC,qBAAqB;QAC1D,oBAAoB,EAAE,aAAa,CAAC,oBAAoB;QACxD,UAAU,EAAE,aAAa,CAAC,UAAU;QACpC,YAAY,EAAE,aAAa,CAAC,YAAY;QACxC,WAAW,EAAE,aAAa,CAAC,WAAW;QACtC,aAAa,EAAE,aAAa,CAAC,aAAa;QAC1C,cAAc,EAAE,aAAa,CAAC,cAAc;QAC5C,eAAe,EAAE,aAAa,CAAC,eAAe;QAC9C,WAAW;QACX,YAAY;KACb,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type NostrEvent, type NostrMetadata } from '@nostrify/nostrify';
2
+ export declare function useAuthor(pubkey: string | undefined): NostrMetadata & {
3
+ event?: NostrEvent;
4
+ };
5
+ //# sourceMappingURL=useAuthor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuthor.d.ts","sourceRoot":"","sources":["../../example/useAuthor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,aAAa,EAAgB,MAAM,oBAAoB,CAAC;AAKvF,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,aAAa,GAAG;IAAE,KAAK,CAAC,EAAE,UAAU,CAAA;CAAE,CA6BxC"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAuthor = useAuthor;
4
+ const nostrify_1 = require("@nostrify/nostrify");
5
+ const react_query_1 = require("@tanstack/react-query");
6
+ const useNostr_1 = require("../useNostr");
7
+ function useAuthor(pubkey) {
8
+ const { nostr } = (0, useNostr_1.useNostr)();
9
+ const { data } = (0, react_query_1.useSuspenseQuery)({
10
+ queryKey: ['author', pubkey ?? ''],
11
+ queryFn: async ({ signal }) => {
12
+ if (!pubkey) {
13
+ return {};
14
+ }
15
+ const [event] = await nostr.query([{ kinds: [0], authors: [pubkey], limit: 1 }], { signal: AbortSignal.any([signal, AbortSignal.timeout(500)]) });
16
+ if (!event) {
17
+ return {};
18
+ }
19
+ try {
20
+ const metadata = nostrify_1.NSchema.json().pipe(nostrify_1.NSchema.metadata()).parse(event.content);
21
+ return { ...metadata, event };
22
+ }
23
+ catch {
24
+ return { event };
25
+ }
26
+ },
27
+ });
28
+ return data;
29
+ }
30
+ //# sourceMappingURL=useAuthor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuthor.js","sourceRoot":"","sources":["../../example/useAuthor.ts"],"names":[],"mappings":";;AAKA,8BA+BC;AApCD,iDAAuF;AACvF,uDAAyD;AAEzD,0CAAuC;AAEvC,SAAgB,SAAS,CACvB,MAA0B;IAE1B,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,mBAAQ,GAAE,CAAC;IAE7B,MAAM,EAAE,IAAI,EAAE,GAAG,IAAA,8BAAgB,EAAyC;QACxE,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE,CAAC;QAClC,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;YAC5B,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,EAAE,CAAC;YACZ,CAAC;YAED,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,KAAK,CAAC,KAAK,CAC/B,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,MAAO,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAC9C,EAAE,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAChE,CAAC;YAEF,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,OAAO,EAAE,CAAC;YACZ,CAAC;YAED,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,kBAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,kBAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBAClE,OAAO,EAAE,GAAG,QAAQ,EAAE,KAAK,EAAE,CAAC;YAChC,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,EAAE,KAAK,EAAE,CAAC;YACnB,CAAC;QACH,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { NUser } from '@nostrify/react/login';
2
+ export declare function useCurrentUser(): {
3
+ user: NUser;
4
+ users: NUser[];
5
+ metadata: import("@nostrify/types").NostrMetadata & {
6
+ event?: import("@nostrify/types").NostrEvent;
7
+ };
8
+ };
9
+ //# sourceMappingURL=useCurrentUser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCurrentUser.d.ts","sourceRoot":"","sources":["../../example/useCurrentUser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,EAAiB,MAAM,uBAAuB,CAAC;AAM9E,wBAAgB,cAAc;;;;;;EAyC7B"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useCurrentUser = useCurrentUser;
4
+ const login_1 = require("@nostrify/react/login");
5
+ const react_1 = require("react");
6
+ const useAuthor_1 = require("./useAuthor");
7
+ const useNostr_1 = require("../useNostr");
8
+ function useCurrentUser() {
9
+ const { nostr } = (0, useNostr_1.useNostr)();
10
+ const { logins } = (0, login_1.useNostrLogin)();
11
+ function loginToUser(login) {
12
+ switch (login.type) {
13
+ case 'nsec':
14
+ return login_1.NUser.fromNsecLogin(login);
15
+ case 'bunker':
16
+ return login_1.NUser.fromBunkerLogin(login, nostr);
17
+ case 'extension':
18
+ return login_1.NUser.fromExtensionLogin(login);
19
+ default:
20
+ // Learn how to define other login types: https://nostrify.dev/react/logins#custom-login-types
21
+ throw new Error(`Unsupported login type: ${login.type}`);
22
+ }
23
+ }
24
+ const users = (0, react_1.useMemo)(() => {
25
+ const users = [];
26
+ for (const login of logins) {
27
+ try {
28
+ const user = loginToUser(login);
29
+ users.push(user);
30
+ }
31
+ catch (error) {
32
+ console.warn('Skipped invalid login', login.id, error);
33
+ }
34
+ }
35
+ return users;
36
+ }, [logins, nostr]);
37
+ const user = users[0];
38
+ const metadata = (0, useAuthor_1.useAuthor)(user?.pubkey);
39
+ return {
40
+ user,
41
+ users,
42
+ metadata,
43
+ };
44
+ }
45
+ //# sourceMappingURL=useCurrentUser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCurrentUser.js","sourceRoot":"","sources":["../../example/useCurrentUser.ts"],"names":[],"mappings":";;AAMA,wCAyCC;AA/CD,iDAA8E;AAC9E,i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C,CAAC;IAEzC,OAAO;QACL,IAAI;QACJ,KAAK;QACL,QAAQ;KACT,CAAC;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare function useLoginActions(): {
2
+ nsec(nsec: string): void;
3
+ bunker(uri: string): Promise<void>;
4
+ extension(): Promise<void>;
5
+ };
6
+ //# sourceMappingURL=useLoginActions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLoginActions.d.ts","sourceRoot":"","sources":["../../example/useLoginActions.ts"],"names":[],"mappings":"AAGA,wBAAgB,eAAe;eAKhB,MAAM,GAAG,IAAI;gBAIN,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;iBAIrB,OAAO,CAAC,IAAI,CAAC;EAKnC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useLoginActions = useLoginActions;
4
+ const react_1 = require("@nostrify/react");
5
+ const login_1 = require("@nostrify/react/login");
6
+ function useLoginActions() {
7
+ const { nostr } = (0, react_1.useNostr)();
8
+ const { addLogin } = (0, login_1.useNostrLogin)();
9
+ return {
10
+ nsec(nsec) {
11
+ const login = login_1.NLogin.fromNsec(nsec);
12
+ addLogin(login);
13
+ },
14
+ async bunker(uri) {
15
+ const login = await login_1.NLogin.fromBunker(uri, nostr);
16
+ addLogin(login);
17
+ },
18
+ async extension() {
19
+ const login = await login_1.NLogin.fromExtension();
20
+ addLogin(login);
21
+ },
22
+ };
23
+ }
24
+ //# sourceMappingURL=useLoginActions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLoginActions.js","sourceRoot":"","sources":["../../example/useLoginActions.ts"],"names":[],"mappings":";;AAGA,0CAkBC;AArBD,2CAA2C;AAC3C,iDAA8D;AAE9D,SAAgB,eAAe;IAC7B,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,gBAAQ,GAAE,CAAC;IAC7B,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAA,qBAAa,GAAE,CAAC;IAErC,OAAO;QACL,IAAI,CAAC,IAAY;YACf,MAAM,KAAK,GAAG,cAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACpC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,GAAW;YACtB,MAAM,KAAK,GAAG,MAAM,cAAM,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAClD,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;QACD,KAAK,CAAC,SAAS;YACb,MAAM,KAAK,GAAG,MAAM,cAAM,CAAC,aAAa,EAAE,CAAC;YAC3C,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type UseSuspenseQueryResult } from '@tanstack/react-query';
2
+ import type { NostrEvent } from '@nostrify/nostrify';
3
+ export declare function useSocialFeed(): UseSuspenseQueryResult<NostrEvent[]>;
4
+ //# sourceMappingURL=useSocialFeed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSocialFeed.d.ts","sourceRoot":"","sources":["../../example/useSocialFeed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAItF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,wBAAgB,aAAa,IAAI,sBAAsB,CAAC,UAAU,EAAE,CAAC,CAWpE"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSocialFeed = useSocialFeed;
4
+ const react_query_1 = require("@tanstack/react-query");
5
+ const useNostr_1 = require("../useNostr");
6
+ function useSocialFeed() {
7
+ const { nostr } = (0, useNostr_1.useNostr)();
8
+ return (0, react_query_1.useSuspenseQuery)({
9
+ queryKey: ['social-feed'],
10
+ queryFn: () => nostr.query([{ kinds: [1], limit: 5 }], { signal: AbortSignal.timeout(5000) }),
11
+ });
12
+ }
13
+ //# sourceMappingURL=useSocialFeed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSocialFeed.js","sourceRoot":"","sources":["../../example/useSocialFeed.ts"],"names":[],"mappings":";;AAMA,sCAWC;AAjBD,uDAAsF;AAEtF,0CAAuC;AAIvC,SAAgB,aAAa;IAC3B,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,mBAAQ,GAAE,CAAC;IAE7B,OAAO,IAAA,8BAAgB,EAAC;QACtB,QAAQ,EAAE,CAAC,aAAa,CAAC;QACzB,OAAO,EAAE,GAAG,EAAE,CACZ,KAAK,CAAC,KAAK,CACT,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAC1B,EAAE,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CACtC;KACJ,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { type NPool } from '@nostrify/nostrify';
2
+ /** An object represeting any supported Nostr login credentials. */
3
+ export type NLoginType = NLoginNsec | NLoginBunker | NLoginExtension | NLoginOther;
4
+ /** Nostr login with nsec. */
5
+ export type NLoginNsec = NLoginBase<'nsec', {
6
+ nsec: `nsec1${string}`;
7
+ }>;
8
+ /** NIP-46 (aka remote signer) login. */
9
+ export type NLoginBunker = NLoginBase<'bunker', {
10
+ bunkerPubkey: string;
11
+ clientNsec: `nsec1${string}`;
12
+ relays: string[];
13
+ }>;
14
+ /** NIP-07 (browser extension) login. */
15
+ export type NLoginExtension = NLoginBase<'extension', null>;
16
+ /** Additional login types created by the library user. */
17
+ export type NLoginOther = NLoginBase<`x-${string}`, {
18
+ [key: string]: unknown;
19
+ }>;
20
+ /** Base properties shared by Nostr login objects. */
21
+ interface NLoginBase<T extends string, D> {
22
+ id: string;
23
+ type: T;
24
+ pubkey: string;
25
+ createdAt: string;
26
+ data: D;
27
+ }
28
+ /** Class representing Nostr login credentials. */
29
+ export declare class NLogin<T extends string, D> implements NLoginBase<T, D> {
30
+ id: string;
31
+ type: T;
32
+ pubkey: string;
33
+ createdAt: string;
34
+ data: D;
35
+ constructor(type: T, pubkey: string, data: D);
36
+ /** Create a login object from an nsec. */
37
+ static fromNsec(nsec: string): NLoginNsec;
38
+ /** Create a login object from a bunker URI. */
39
+ static fromBunker(uri: string, pool: NPool): Promise<NLoginBunker>;
40
+ /** Create a login object from a browser extension. */
41
+ static fromExtension(): Promise<NLoginExtension>;
42
+ /** Convert to a JSON-serializable object. */
43
+ toJSON(): NLoginBase<T, D>;
44
+ }
45
+ export {};
46
+ //# sourceMappingURL=NLogin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NLogin.d.ts","sourceRoot":"","sources":["../../login/NLogin.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+C,KAAK,KAAK,EAAc,MAAM,oBAAoB,CAAC;AAGzG,mEAAmE;AACnE,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,YAAY,GAAG,eAAe,GAAG,WAAW,CAAC;AAEnF,6BAA6B;AAC7B,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,EAAE;IAC1C,IAAI,EAAE,QAAQ,MAAM,EAAE,CAAC;CACxB,CAAC,CAAC;AAEH,wCAAwC;AACxC,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,QAAQ,EAAE;IAC9C,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,QAAQ,MAAM,EAAE,CAAC;IAC7B,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC,CAAC;AAEH,wCAAwC;AACxC,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AAE5D,0DAA0D;AAC1D,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,KAAK,MAAM,EAAE,EAAE;IAClD,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC,CAAC;AAEH,qDAAqD;AACrD,UAAU,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,CAAC,CAAC;CACT;AAED,kDAAkD;AAClD,qBAAa,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,CAAE,YAAW,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;IAC3D,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,CAAC,CAAC;gBAEH,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAQ5C,0CAA0C;IAC1C,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU;IAezC,+CAA+C;WAClC,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC,YAAY,CAAC;IA4BxE,sDAAsD;WACzC,aAAa,IAAI,OAAO,CAAC,eAAe,CAAC;IAYtD,6CAA6C;IAC7C,MAAM,IAAI,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;CAS3B"}
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NLogin = void 0;
4
+ const nostrify_1 = require("@nostrify/nostrify");
5
+ const nostr_tools_1 = require("nostr-tools");
6
+ /** Class representing Nostr login credentials. */
7
+ class NLogin {
8
+ id;
9
+ type;
10
+ pubkey;
11
+ createdAt;
12
+ data;
13
+ constructor(type, pubkey, data) {
14
+ this.id = `${type}:${pubkey}`;
15
+ this.type = type;
16
+ this.pubkey = pubkey;
17
+ this.createdAt = new Date().toISOString();
18
+ this.data = data;
19
+ }
20
+ /** Create a login object from an nsec. */
21
+ static fromNsec(nsec) {
22
+ const decoded = nostr_tools_1.nip19.decode(nsec);
23
+ if (decoded.type !== 'nsec') {
24
+ throw new Error('Invalid nsec');
25
+ }
26
+ const sk = decoded.data;
27
+ const pubkey = (0, nostr_tools_1.getPublicKey)(sk);
28
+ return new NLogin('nsec', pubkey, {
29
+ nsec: nostr_tools_1.nip19.nsecEncode(sk),
30
+ });
31
+ }
32
+ /** Create a login object from a bunker URI. */
33
+ static async fromBunker(uri, pool) {
34
+ const { pubkey: bunkerPubkey, secret, relays } = new nostrify_1.BunkerURI(uri);
35
+ if (!relays.length) {
36
+ throw new Error('No relay provided');
37
+ }
38
+ const sk = (0, nostr_tools_1.generateSecretKey)();
39
+ const nsec = nostr_tools_1.nip19.nsecEncode(sk);
40
+ const clientSigner = new nostrify_1.NSecSigner(sk);
41
+ const signer = new nostrify_1.NConnectSigner({
42
+ relay: pool.group(relays),
43
+ pubkey: bunkerPubkey,
44
+ signer: clientSigner,
45
+ timeout: 60_000,
46
+ });
47
+ await signer.connect(secret);
48
+ const pubkey = await signer.getPublicKey();
49
+ return new NLogin('bunker', pubkey, {
50
+ bunkerPubkey,
51
+ clientNsec: nsec,
52
+ relays,
53
+ });
54
+ }
55
+ /** Create a login object from a browser extension. */
56
+ static async fromExtension() {
57
+ const windowSigner = globalThis.nostr;
58
+ if (!windowSigner) {
59
+ throw new Error('Nostr extension is not available');
60
+ }
61
+ const pubkey = await windowSigner.getPublicKey();
62
+ return new NLogin('extension', pubkey, null);
63
+ }
64
+ /** Convert to a JSON-serializable object. */
65
+ toJSON() {
66
+ return {
67
+ id: this.id,
68
+ type: this.type,
69
+ pubkey: this.pubkey,
70
+ createdAt: this.createdAt,
71
+ data: this.data,
72
+ };
73
+ }
74
+ }
75
+ exports.NLogin = NLogin;
76
+ //# sourceMappingURL=NLogin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NLogin.js","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CAAC,IAAI;SAChB,CAAC;IACJ,CAAC;CACF;AAnFD,wBAmFC"}
@@ -0,0 +1,22 @@
1
+ import { type NostrSigner, type NPool } from '@nostrify/nostrify';
2
+ import type { NLoginBunker, NLoginExtension, NLoginNsec } from './NLogin';
3
+ /** Represents a Nostr user with authentication credentials. */
4
+ export declare class NUser {
5
+ /** The authentication method used for this user */
6
+ readonly method: 'nsec' | 'bunker' | 'extension' | `x-${string}`;
7
+ /** The public key of the user in hex format. */
8
+ readonly pubkey: string;
9
+ /** The signer that can sign events on behalf of this user. */
10
+ readonly signer: NostrSigner;
11
+ constructor(
12
+ /** The authentication method used for this user */
13
+ method: 'nsec' | 'bunker' | 'extension' | `x-${string}`,
14
+ /** The public key of the user in hex format. */
15
+ pubkey: string,
16
+ /** The signer that can sign events on behalf of this user. */
17
+ signer: NostrSigner);
18
+ static fromNsecLogin(login: NLoginNsec): NUser;
19
+ static fromBunkerLogin(login: NLoginBunker, pool: NPool): NUser;
20
+ static fromExtensionLogin(login: NLoginExtension): NUser;
21
+ }
22
+ //# sourceMappingURL=NUser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NUser.d.ts","sourceRoot":"","sources":["../../login/NUser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,WAAW,EAAE,KAAK,KAAK,EAAc,MAAM,oBAAoB,CAAC;AAG9G,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE1E,+DAA+D;AAC/D,qBAAa,KAAK;IAEd,mDAAmD;IACnD,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,KAAK,MAAM,EAAE;IAChE,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,8DAA8D;IAC9D,QAAQ,CAAC,MAAM,EAAE,WAAW;;IAL5B,mDAAmD;IAC1C,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,KAAK,MAAM,EAAE;IAChE,gDAAgD;IACvC,MAAM,EAAE,MAAM;IACvB,8DAA8D;IACrD,MAAM,EAAE,WAAW;IAG9B,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK;IAa9C,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,GAAG,KAAK;IAmB/D,MAAM,CAAC,kBAAkB,CAAC,KAAK,EAAE,eAAe,GAAG,KAAK;CAOzD"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NUser = void 0;
4
+ const nostrify_1 = require("@nostrify/nostrify");
5
+ const nostr_tools_1 = require("nostr-tools");
6
+ /** Represents a Nostr user with authentication credentials. */
7
+ class NUser {
8
+ method;
9
+ pubkey;
10
+ signer;
11
+ constructor(
12
+ /** The authentication method used for this user */
13
+ method,
14
+ /** The public key of the user in hex format. */
15
+ pubkey,
16
+ /** The signer that can sign events on behalf of this user. */
17
+ signer) {
18
+ this.method = method;
19
+ this.pubkey = pubkey;
20
+ this.signer = signer;
21
+ }
22
+ static fromNsecLogin(login) {
23
+ const sk = nostr_tools_1.nip19.decode(login.data.nsec);
24
+ return new NUser(login.type, login.pubkey, new nostrify_1.NSecSigner(sk.data));
25
+ }
26
+ static fromBunkerLogin(login, pool) {
27
+ const clientSk = nostr_tools_1.nip19.decode(login.data.clientNsec);
28
+ const clientSigner = new nostrify_1.NSecSigner(clientSk.data);
29
+ return new NUser(login.type, login.pubkey, new nostrify_1.NConnectSigner({
30
+ relay: pool.group(login.data.relays),
31
+ pubkey: login.pubkey,
32
+ signer: clientSigner,
33
+ timeout: 60_000,
34
+ }));
35
+ }
36
+ static fromExtensionLogin(login) {
37
+ return new NUser(login.type, login.pubkey, new nostrify_1.NBrowserSigner());
38
+ }
39
+ }
40
+ exports.NUser = NUser;
41
+ //# sourceMappingURL=NUser.js.map
@@ -0,0 +1 @@
1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,MAAM,EACZ,IAAI,yBAAc,EAAE,CACrB,CAAC;IACJ,CAAC;CACF;AAjDD,sBAiDC"}
@@ -0,0 +1,24 @@
1
+ import { type Context } from 'react';
2
+ import type { NLoginType } from './NLogin';
3
+ /**
4
+ * NostrLoginContextType defines the shape of the context that will be provided
5
+ * to components that need access to the Nostr login state.
6
+ */
7
+ export type NostrLoginContextType = {
8
+ /** The list of Nostr logins. */
9
+ logins: readonly NLoginType[];
10
+ /** Dispatch an action to add a login to the state. */
11
+ addLogin: (login: NLoginType) => void;
12
+ /** Dispatch an action to remove a login from the state. */
13
+ removeLogin: (loginId: string) => void;
14
+ /** Dispatch an action to set the user's current login (by moving it to the top of the state). */
15
+ setLogin: (loginId: string) => void;
16
+ /** Dispatch an action to clear the login state. */
17
+ clearLogins: () => void;
18
+ };
19
+ /**
20
+ * NostrLoginContext is a React context that provides access to the Nostr login state and
21
+ * a dispatch function to update the state.
22
+ */
23
+ export declare const NostrLoginContext: Context<NostrLoginContextType | undefined>;
24
+ //# sourceMappingURL=NostrLoginContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NostrLoginContext.d.ts","sourceRoot":"","sources":["../../login/NostrLoginContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,OAAO,CAAC;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,gCAAgC;IAChC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC;IAC9B,sDAAsD;IACtD,QAAQ,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IACtC,2DAA2D;IAC3D,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,iGAAiG;IACjG,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,mDAAmD;IACnD,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAE7D,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NostrLoginContext = void 0;
4
+ const react_1 = require("react");
5
+ /**
6
+ * NostrLoginContext is a React context that provides access to the Nostr login state and
7
+ * a dispatch function to update the state.
8
+ */
9
+ exports.NostrLoginContext = (0, react_1.createContext)(undefined);
10
+ //# sourceMappingURL=NostrLoginContext.js.map