@nostrify/react 0.2.11 → 0.2.12

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 (72) hide show
  1. package/.turbo/turbo-build.log +4 -5
  2. package/.turbo/turbo-setup.log +13 -0
  3. package/.turbo/turbo-test.log +13 -0
  4. package/CHANGELOG.md +9 -0
  5. package/dist/NostrContext.js +7 -7
  6. package/dist/example/test-helpers.js +32 -30
  7. package/dist/example/useAuthor.d.ts +1 -1
  8. package/dist/example/useAuthor.d.ts.map +1 -1
  9. package/dist/example/useAuthor.js +30 -26
  10. package/dist/example/useCurrentUser.d.ts +2 -5
  11. package/dist/example/useCurrentUser.d.ts.map +1 -1
  12. package/dist/example/useCurrentUser.js +40 -40
  13. package/dist/example/useLoginActions.d.ts.map +1 -1
  14. package/dist/example/useLoginActions.js +22 -20
  15. package/dist/example/useSocialFeed.d.ts +1 -1
  16. package/dist/example/useSocialFeed.d.ts.map +1 -1
  17. package/dist/example/useSocialFeed.js +14 -9
  18. package/dist/example/vite-env.d.js +0 -0
  19. package/dist/login/NLogin.d.ts +1 -1
  20. package/dist/login/NLogin.d.ts.map +1 -1
  21. package/dist/login/NLogin.js +69 -68
  22. package/dist/login/NUser.d.ts +3 -2
  23. package/dist/login/NUser.d.ts.map +1 -1
  24. package/dist/login/NUser.js +40 -36
  25. package/dist/login/NostrLoginContext.d.ts +1 -1
  26. package/dist/login/NostrLoginContext.js +5 -7
  27. package/dist/login/NostrLoginProvider.js +16 -18
  28. package/dist/login/mod.d.ts +4 -4
  29. package/dist/login/mod.js +10 -5
  30. package/dist/login/mod.js.map +7 -1
  31. package/dist/login/nostrLoginReducer.d.ts +1 -1
  32. package/dist/login/nostrLoginReducer.js +26 -24
  33. package/dist/login/useNostrLogin.d.ts +1 -1
  34. package/dist/login/useNostrLogin.js +11 -9
  35. package/dist/login/useNostrLoginReducer.d.ts +2 -2
  36. package/dist/login/useNostrLoginReducer.js +14 -12
  37. package/dist/mod.d.ts +3 -2
  38. package/dist/mod.d.ts.map +1 -1
  39. package/dist/mod.js +7 -3
  40. package/dist/mod.js.map +7 -1
  41. package/dist/tsconfig.tsbuildinfo +1 -1
  42. package/dist/useNostr.d.ts +1 -1
  43. package/dist/useNostr.js +11 -9
  44. package/example/useAuthor.ts +3 -2
  45. package/example/useCurrentUser.ts +2 -2
  46. package/example/useSocialFeed.ts +2 -2
  47. package/login/NLogin.ts +3 -1
  48. package/login/NUser.ts +4 -2
  49. package/login/NostrLoginContext.ts +1 -1
  50. package/login/NostrLoginProvider.ts +2 -2
  51. package/login/mod.ts +4 -4
  52. package/login/nostrLoginReducer.ts +1 -1
  53. package/login/useNostrLogin.ts +1 -1
  54. package/login/useNostrLoginReducer.ts +2 -2
  55. package/mod.ts +3 -2
  56. package/package.json +9 -7
  57. package/tsconfig.json +7 -1
  58. package/useNostr.ts +1 -1
  59. package/dist/NostrContext.js.map +0 -1
  60. package/dist/example/test-helpers.js.map +0 -1
  61. package/dist/example/useAuthor.js.map +0 -1
  62. package/dist/example/useCurrentUser.js.map +0 -1
  63. package/dist/example/useLoginActions.js.map +0 -1
  64. package/dist/example/useSocialFeed.js.map +0 -1
  65. package/dist/login/NLogin.js.map +0 -1
  66. package/dist/login/NUser.js.map +0 -1
  67. package/dist/login/NostrLoginContext.js.map +0 -1
  68. package/dist/login/NostrLoginProvider.js.map +0 -1
  69. package/dist/login/nostrLoginReducer.js.map +0 -1
  70. package/dist/login/useNostrLogin.js.map +0 -1
  71. package/dist/login/useNostrLoginReducer.js.map +0 -1
  72. package/dist/useNostr.js.map +0 -1
@@ -1,5 +1,4 @@
1
-
2
-
3
- > @nostrify/react@0.2.11 build /home/sid/repos/NSpec/packages/react
4
- > tsc -p tsconfig.json
5
-
1
+
2
+ > @nostrify/react@0.2.11 build /home/sid/repos/nostrify/packages/react
3
+ > tsc -p tsconfig.json && node ../../esbuild.config.js --package ./
4
+
@@ -0,0 +1,13 @@
1
+
2
+
3
+ > @nostrify/react@0.2.11 setup /home/sid/repos/nostrify/packages/react
4
+ > pnpm i
5
+
6
+ (node:1234100) [DEP0169] DeprecationWarning: `url.parse()` behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.
7
+ (Use `node --trace-deprecation ...` to show where the warning was created)
8
+ Scope: all 9 workspace projects
9
+ ../.. | Progress: resolved 1, reused 0, downloaded 0, added 0
10
+ ../.. | +1 +
11
+ ../.. | Progress: resolved 1, reused 0, downloaded 0, added 0
12
+ ../.. | Progress: resolved 1, reused 1, downloaded 0, added 0
13
+ ../.. | Progress: resolved 1, reused 1, downloaded 0, added 0, done
@@ -0,0 +1,13 @@
1
+
2
+
3
+ > @nostrify/react@0.2.11 test /home/sid/repos/nostrify/packages/react
4
+ > node --test "**/*.test.ts"
5
+
6
+ ℹ tests 0
7
+ ℹ suites 0
8
+ ℹ pass 0
9
+ ℹ fail 0
10
+ ℹ cancelled 0
11
+ ℹ skipped 0
12
+ ℹ todo 0
13
+ ℹ duration_ms 16.699058
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @nostrify/react
2
2
 
3
+ ## 0.2.12
4
+
5
+ ### Patch Changes
6
+
7
+ - Get tests passing in CI, use esbuild to build final JS files
8
+ - Updated dependencies
9
+ - @nostrify/nostrify@0.46.8
10
+ - @nostrify/types@0.36.4
11
+
3
12
  ## 0.2.11
4
13
 
5
14
  ### Patch Changes
@@ -1,7 +1,7 @@
1
- import { createContext } from 'react';
2
- /**
3
- * React context for Nostr functionality.
4
- * Use this with useContext or the useNostr hook to access Nostr features.
5
- */
6
- export const NostrContext = createContext(undefined);
7
- //# sourceMappingURL=NostrContext.js.map
1
+ import { createContext } from "react";
2
+ const NostrContext = createContext(
3
+ void 0
4
+ );
5
+ export {
6
+ NostrContext
7
+ };
@@ -1,31 +1,33 @@
1
- import { PropertySymbol, Window } from 'happy-dom';
2
- export function polyfillDOM() {
3
- const window = new Window();
4
- const document = window.document;
5
- const browserWindow = document[PropertySymbol.window];
6
- const setInnerHTML = (html) => document.documentElement.innerHTML = html;
7
- const cancelAsync = () => window.happyDOM.abort();
8
- Object.assign(globalThis, {
9
- window,
10
- document,
11
- HTMLElement: browserWindow.HTMLElement,
12
- Element: browserWindow.Element,
13
- Node: browserWindow.Node,
14
- navigator: browserWindow.navigator,
15
- DocumentFragment: browserWindow.DocumentFragment,
16
- DocumentType: browserWindow.DocumentType,
17
- SVGElement: browserWindow.SVGElement,
18
- Text: browserWindow.Text,
19
- requestAnimationFrame: browserWindow.requestAnimationFrame,
20
- cancelAnimationFrame: browserWindow.cancelAnimationFrame,
21
- setTimeout: browserWindow.setTimeout,
22
- clearTimeout: browserWindow.clearTimeout,
23
- setInterval: browserWindow.setInterval,
24
- clearInterval: browserWindow.clearInterval,
25
- queueMicrotask: browserWindow.queueMicrotask,
26
- AbortController: browserWindow.AbortController,
27
- cancelAsync,
28
- setInnerHTML,
29
- });
1
+ import { PropertySymbol, Window } from "happy-dom";
2
+ function polyfillDOM() {
3
+ const window = new Window();
4
+ const document = window.document;
5
+ const browserWindow = document[PropertySymbol.window];
6
+ const setInnerHTML = (html) => document.documentElement.innerHTML = html;
7
+ const cancelAsync = () => window.happyDOM.abort();
8
+ Object.assign(globalThis, {
9
+ window,
10
+ document,
11
+ HTMLElement: browserWindow.HTMLElement,
12
+ Element: browserWindow.Element,
13
+ Node: browserWindow.Node,
14
+ navigator: browserWindow.navigator,
15
+ DocumentFragment: browserWindow.DocumentFragment,
16
+ DocumentType: browserWindow.DocumentType,
17
+ SVGElement: browserWindow.SVGElement,
18
+ Text: browserWindow.Text,
19
+ requestAnimationFrame: browserWindow.requestAnimationFrame,
20
+ cancelAnimationFrame: browserWindow.cancelAnimationFrame,
21
+ setTimeout: browserWindow.setTimeout,
22
+ clearTimeout: browserWindow.clearTimeout,
23
+ setInterval: browserWindow.setInterval,
24
+ clearInterval: browserWindow.clearInterval,
25
+ queueMicrotask: browserWindow.queueMicrotask,
26
+ AbortController: browserWindow.AbortController,
27
+ cancelAsync,
28
+ setInnerHTML
29
+ });
30
30
  }
31
- //# sourceMappingURL=test-helpers.js.map
31
+ export {
32
+ polyfillDOM
33
+ };
@@ -1,4 +1,4 @@
1
- import { type NostrEvent, type NostrMetadata } from '@nostrify/nostrify';
1
+ import type { NostrEvent, NostrMetadata } from '@nostrify/types';
2
2
  export declare function useAuthor(pubkey: string | undefined): NostrMetadata & {
3
3
  event?: NostrEvent;
4
4
  };
@@ -1 +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"}
1
+ {"version":3,"file":"useAuthor.d.ts","sourceRoot":"","sources":["../../example/useAuthor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAKjE,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,aAAa,GAAG;IAAE,KAAK,CAAC,EAAE,UAAU,CAAA;CAAE,CA6BxC"}
@@ -1,27 +1,31 @@
1
- import { NSchema as n } from '@nostrify/nostrify';
2
- import { useSuspenseQuery } from '@tanstack/react-query';
3
- import { useNostr } from '../useNostr.js';
4
- export function useAuthor(pubkey) {
5
- const { nostr } = useNostr();
6
- const { data } = useSuspenseQuery({
7
- queryKey: ['author', pubkey ?? ''],
8
- queryFn: async ({ signal }) => {
9
- if (!pubkey) {
10
- return {};
11
- }
12
- const [event] = await nostr.query([{ kinds: [0], authors: [pubkey], limit: 1 }], { signal: AbortSignal.any([signal, AbortSignal.timeout(500)]) });
13
- if (!event) {
14
- return {};
15
- }
16
- try {
17
- const metadata = n.json().pipe(n.metadata()).parse(event.content);
18
- return { ...metadata, event };
19
- }
20
- catch {
21
- return { event };
22
- }
23
- },
24
- });
25
- return data;
1
+ import { NSchema as n } from "@nostrify/nostrify";
2
+ import { useSuspenseQuery } from "@tanstack/react-query";
3
+ import { useNostr } from "../useNostr.js";
4
+ function useAuthor(pubkey) {
5
+ const { nostr } = useNostr();
6
+ const { data } = useSuspenseQuery({
7
+ queryKey: ["author", pubkey ?? ""],
8
+ queryFn: async ({ signal }) => {
9
+ if (!pubkey) {
10
+ return {};
11
+ }
12
+ const [event] = await nostr.query(
13
+ [{ kinds: [0], authors: [pubkey], limit: 1 }],
14
+ { signal: AbortSignal.any([signal, AbortSignal.timeout(500)]) }
15
+ );
16
+ if (!event) {
17
+ return {};
18
+ }
19
+ try {
20
+ const metadata = n.json().pipe(n.metadata()).parse(event.content);
21
+ return { ...metadata, event };
22
+ } catch {
23
+ return { event };
24
+ }
25
+ }
26
+ });
27
+ return data;
26
28
  }
27
- //# sourceMappingURL=useAuthor.js.map
29
+ export {
30
+ useAuthor
31
+ };
@@ -1,9 +1,6 @@
1
- import { NUser } from '@nostrify/react/login';
2
1
  export declare function useCurrentUser(): {
3
- user: NUser;
2
+ user: any;
4
3
  users: NUser[];
5
- metadata: import("@nostrify/types").NostrMetadata & {
6
- event?: import("@nostrify/types").NostrEvent;
7
- };
4
+ metadata: any;
8
5
  };
9
6
  //# sourceMappingURL=useCurrentUser.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"useCurrentUser.d.ts","sourceRoot":"","sources":["../../example/useCurrentUser.ts"],"names":[],"mappings":"AAMA,wBAAgB,cAAc;;;;EAyC7B"}
@@ -1,42 +1,42 @@
1
- import { NUser, useNostrLogin } from '@nostrify/react/login';
2
- import { useMemo } from 'react';
3
- import { useAuthor } from './useAuthor.js';
4
- import { useNostr } from '../useNostr.js';
5
- export function useCurrentUser() {
6
- const { nostr } = useNostr();
7
- const { logins } = useNostrLogin();
8
- function loginToUser(login) {
9
- switch (login.type) {
10
- case 'nsec':
11
- return NUser.fromNsecLogin(login);
12
- case 'bunker':
13
- return NUser.fromBunkerLogin(login, nostr);
14
- case 'extension':
15
- return NUser.fromExtensionLogin(login);
16
- default:
17
- // Learn how to define other login types: https://nostrify.dev/react/logins#custom-login-types
18
- throw new Error(`Unsupported login type: ${login.type}`);
19
- }
1
+ import { NUser, useNostrLogin } from "@nostrify/react/login";
2
+ import { useMemo } from "react";
3
+ import { useAuthor } from "./useAuthor.js";
4
+ import { useNostr } from "../useNostr.js";
5
+ function useCurrentUser() {
6
+ const { nostr } = useNostr();
7
+ const { logins } = useNostrLogin();
8
+ function loginToUser(login) {
9
+ switch (login.type) {
10
+ case "nsec":
11
+ return NUser.fromNsecLogin(login);
12
+ case "bunker":
13
+ return NUser.fromBunkerLogin(login, nostr);
14
+ case "extension":
15
+ return NUser.fromExtensionLogin(login);
16
+ default:
17
+ throw new Error(`Unsupported login type: ${login.type}`);
20
18
  }
21
- const users = useMemo(() => {
22
- const users = [];
23
- for (const login of logins) {
24
- try {
25
- const user = loginToUser(login);
26
- users.push(user);
27
- }
28
- catch (error) {
29
- console.warn('Skipped invalid login', login.id, error);
30
- }
31
- }
32
- return users;
33
- }, [logins, nostr]);
34
- const user = users[0];
35
- const metadata = useAuthor(user?.pubkey);
36
- return {
37
- user,
38
- users,
39
- metadata,
40
- };
19
+ }
20
+ const users = useMemo(() => {
21
+ const users2 = [];
22
+ for (const login of logins) {
23
+ try {
24
+ const user2 = loginToUser(login);
25
+ users2.push(user2);
26
+ } catch (error) {
27
+ console.warn("Skipped invalid login", login.id, error);
28
+ }
29
+ }
30
+ return users2;
31
+ }, [logins, nostr]);
32
+ const user = users[0];
33
+ const metadata = useAuthor(user?.pubkey);
34
+ return {
35
+ user,
36
+ users,
37
+ metadata
38
+ };
41
39
  }
42
- //# sourceMappingURL=useCurrentUser.js.map
40
+ export {
41
+ useCurrentUser
42
+ };
@@ -1 +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"}
1
+ {"version":3,"file":"useLoginActions.d.ts","sourceRoot":"","sources":["../../example/useLoginActions.ts"],"names":[],"mappings":"AAGA,wBAAgB,eAAe;eAKhB,MAAM,GAAG,IAAI;gBAIN,MAAM,GAAG,QAAQ,IAAI,CAAC;iBAIrB,QAAQ,IAAI,CAAC;EAKnC"}
@@ -1,21 +1,23 @@
1
- import { useNostr } from '@nostrify/react';
2
- import { NLogin, useNostrLogin } from '@nostrify/react/login';
3
- export function useLoginActions() {
4
- const { nostr } = useNostr();
5
- const { addLogin } = useNostrLogin();
6
- return {
7
- nsec(nsec) {
8
- const login = NLogin.fromNsec(nsec);
9
- addLogin(login);
10
- },
11
- async bunker(uri) {
12
- const login = await NLogin.fromBunker(uri, nostr);
13
- addLogin(login);
14
- },
15
- async extension() {
16
- const login = await NLogin.fromExtension();
17
- addLogin(login);
18
- },
19
- };
1
+ import { useNostr } from "@nostrify/react";
2
+ import { NLogin, useNostrLogin } from "@nostrify/react/login";
3
+ function useLoginActions() {
4
+ const { nostr } = useNostr();
5
+ const { addLogin } = useNostrLogin();
6
+ return {
7
+ nsec(nsec) {
8
+ const login = NLogin.fromNsec(nsec);
9
+ addLogin(login);
10
+ },
11
+ async bunker(uri) {
12
+ const login = await NLogin.fromBunker(uri, nostr);
13
+ addLogin(login);
14
+ },
15
+ async extension() {
16
+ const login = await NLogin.fromExtension();
17
+ addLogin(login);
18
+ }
19
+ };
20
20
  }
21
- //# sourceMappingURL=useLoginActions.js.map
21
+ export {
22
+ useLoginActions
23
+ };
@@ -1,4 +1,4 @@
1
1
  import { type UseSuspenseQueryResult } from '@tanstack/react-query';
2
- import type { NostrEvent } from '@nostrify/nostrify';
2
+ import type { NostrEvent } from '@nostrify/types';
3
3
  export declare function useSocialFeed(): UseSuspenseQueryResult<NostrEvent[]>;
4
4
  //# sourceMappingURL=useSocialFeed.d.ts.map
@@ -1 +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"}
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,iBAAiB,CAAC;AAElD,wBAAgB,aAAa,IAAI,sBAAsB,CAAC,UAAU,EAAE,CAAC,CAWpE"}
@@ -1,10 +1,15 @@
1
- import { useSuspenseQuery } from '@tanstack/react-query';
2
- import { useNostr } from '../useNostr.js';
3
- export function useSocialFeed() {
4
- const { nostr } = useNostr();
5
- return useSuspenseQuery({
6
- queryKey: ['social-feed'],
7
- queryFn: () => nostr.query([{ kinds: [1], limit: 5 }], { signal: AbortSignal.timeout(5000) }),
8
- });
1
+ import { useSuspenseQuery } from "@tanstack/react-query";
2
+ import { useNostr } from "../useNostr.js";
3
+ function useSocialFeed() {
4
+ const { nostr } = useNostr();
5
+ return useSuspenseQuery({
6
+ queryKey: ["social-feed"],
7
+ queryFn: () => nostr.query(
8
+ [{ kinds: [1], limit: 5 }],
9
+ { signal: AbortSignal.timeout(5e3) }
10
+ )
11
+ });
9
12
  }
10
- //# sourceMappingURL=useSocialFeed.js.map
13
+ export {
14
+ useSocialFeed
15
+ };
File without changes
@@ -1,4 +1,4 @@
1
- import { type NPool } from '@nostrify/nostrify';
1
+ import type { NPool } from '@nostrify/nostrify';
2
2
  /** An object represeting any supported Nostr login credentials. */
3
3
  export type NLoginType = NLoginNsec | NLoginBunker | NLoginExtension | NLoginOther;
4
4
  /** Nostr login with nsec. */
@@ -1 +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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,72 +1,73 @@
1
- import { BunkerURI, NConnectSigner, NSecSigner } from '@nostrify/nostrify';
2
- import { generateSecretKey, getPublicKey, nip19 } from 'nostr-tools';
3
- /** Class representing Nostr login credentials. */
4
- export class NLogin {
5
- id;
6
- type;
7
- pubkey;
8
- createdAt;
9
- data;
10
- constructor(type, pubkey, data) {
11
- this.id = `${type}:${pubkey}`;
12
- this.type = type;
13
- this.pubkey = pubkey;
14
- this.createdAt = new Date().toISOString();
15
- this.data = data;
1
+ import { BunkerURI, NConnectSigner, NSecSigner } from "@nostrify/nostrify";
2
+ import { generateSecretKey, getPublicKey, nip19 } from "nostr-tools";
3
+ class NLogin {
4
+ id;
5
+ type;
6
+ pubkey;
7
+ createdAt;
8
+ data;
9
+ constructor(type, pubkey, data) {
10
+ this.id = `${type}:${pubkey}`;
11
+ this.type = type;
12
+ this.pubkey = pubkey;
13
+ this.createdAt = (/* @__PURE__ */ new Date()).toISOString();
14
+ this.data = data;
15
+ }
16
+ /** Create a login object from an nsec. */
17
+ static fromNsec(nsec) {
18
+ const decoded = nip19.decode(nsec);
19
+ if (decoded.type !== "nsec") {
20
+ throw new Error("Invalid nsec");
16
21
  }
17
- /** Create a login object from an nsec. */
18
- static fromNsec(nsec) {
19
- const decoded = nip19.decode(nsec);
20
- if (decoded.type !== 'nsec') {
21
- throw new Error('Invalid nsec');
22
- }
23
- const sk = decoded.data;
24
- const pubkey = getPublicKey(sk);
25
- return new NLogin('nsec', pubkey, {
26
- nsec: nip19.nsecEncode(sk),
27
- });
22
+ const sk = decoded.data;
23
+ const pubkey = getPublicKey(sk);
24
+ return new NLogin("nsec", pubkey, {
25
+ nsec: nip19.nsecEncode(sk)
26
+ });
27
+ }
28
+ /** Create a login object from a bunker URI. */
29
+ static async fromBunker(uri, pool) {
30
+ const { pubkey: bunkerPubkey, secret, relays } = new BunkerURI(uri);
31
+ if (!relays.length) {
32
+ throw new Error("No relay provided");
28
33
  }
29
- /** Create a login object from a bunker URI. */
30
- static async fromBunker(uri, pool) {
31
- const { pubkey: bunkerPubkey, secret, relays } = new BunkerURI(uri);
32
- if (!relays.length) {
33
- throw new Error('No relay provided');
34
- }
35
- const sk = generateSecretKey();
36
- const nsec = nip19.nsecEncode(sk);
37
- const clientSigner = new NSecSigner(sk);
38
- const signer = new NConnectSigner({
39
- relay: pool.group(relays),
40
- pubkey: bunkerPubkey,
41
- signer: clientSigner,
42
- timeout: 60_000,
43
- });
44
- await signer.connect(secret);
45
- const pubkey = await signer.getPublicKey();
46
- return new NLogin('bunker', pubkey, {
47
- bunkerPubkey,
48
- clientNsec: nsec,
49
- relays,
50
- });
51
- }
52
- /** Create a login object from a browser extension. */
53
- static async fromExtension() {
54
- const windowSigner = globalThis.nostr;
55
- if (!windowSigner) {
56
- throw new Error('Nostr extension is not available');
57
- }
58
- const pubkey = await windowSigner.getPublicKey();
59
- return new NLogin('extension', pubkey, null);
60
- }
61
- /** Convert to a JSON-serializable object. */
62
- toJSON() {
63
- return {
64
- id: this.id,
65
- type: this.type,
66
- pubkey: this.pubkey,
67
- createdAt: this.createdAt,
68
- data: this.data,
69
- };
34
+ const sk = generateSecretKey();
35
+ const nsec = nip19.nsecEncode(sk);
36
+ const clientSigner = new NSecSigner(sk);
37
+ const signer = new NConnectSigner({
38
+ relay: pool.group(relays),
39
+ pubkey: bunkerPubkey,
40
+ signer: clientSigner,
41
+ timeout: 6e4
42
+ });
43
+ await signer.connect(secret);
44
+ const pubkey = await signer.getPublicKey();
45
+ return new NLogin("bunker", pubkey, {
46
+ bunkerPubkey,
47
+ clientNsec: nsec,
48
+ relays
49
+ });
50
+ }
51
+ /** Create a login object from a browser extension. */
52
+ static async fromExtension() {
53
+ const windowSigner = globalThis.nostr;
54
+ if (!windowSigner) {
55
+ throw new Error("Nostr extension is not available");
70
56
  }
57
+ const pubkey = await windowSigner.getPublicKey();
58
+ return new NLogin("extension", pubkey, null);
59
+ }
60
+ /** Convert to a JSON-serializable object. */
61
+ toJSON() {
62
+ return {
63
+ id: this.id,
64
+ type: this.type,
65
+ pubkey: this.pubkey,
66
+ createdAt: this.createdAt,
67
+ data: this.data
68
+ };
69
+ }
71
70
  }
72
- //# sourceMappingURL=NLogin.js.map
71
+ export {
72
+ NLogin
73
+ };
@@ -1,5 +1,6 @@
1
- import { type NostrSigner, type NPool } from '@nostrify/nostrify';
2
- import type { NLoginBunker, NLoginExtension, NLoginNsec } from './NLogin.js';
1
+ import type { NPool } from '@nostrify/nostrify';
2
+ import type { NostrSigner } from '@nostrify/types';
3
+ import type { NLoginBunker, NLoginExtension, NLoginNsec } from './NLogin.ts';
3
4
  /** Represents a Nostr user with authentication credentials. */
4
5
  export declare class NUser {
5
6
  /** The authentication method used for this user */
@@ -1 +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,aAAa,CAAC;AAE7E,+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;IAm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