@nostrify/react 0.2.10 → 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 +18 -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 +17 -10
  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,37 +1,41 @@
1
- import { NBrowserSigner, NConnectSigner, NSecSigner } from '@nostrify/nostrify';
2
- import { nip19 } from 'nostr-tools';
3
- /** Represents a Nostr user with authentication credentials. */
4
- export class NUser {
5
- method;
6
- pubkey;
7
- signer;
8
- constructor(
9
- /** The authentication method used for this user */
10
- method,
11
- /** The public key of the user in hex format. */
12
- pubkey,
13
- /** The signer that can sign events on behalf of this user. */
14
- signer) {
15
- this.method = method;
16
- this.pubkey = pubkey;
17
- this.signer = signer;
18
- }
19
- static fromNsecLogin(login) {
20
- const sk = nip19.decode(login.data.nsec);
21
- return new NUser(login.type, login.pubkey, new NSecSigner(sk.data));
22
- }
23
- static fromBunkerLogin(login, pool) {
24
- const clientSk = nip19.decode(login.data.clientNsec);
25
- const clientSigner = new NSecSigner(clientSk.data);
26
- return new NUser(login.type, login.pubkey, new NConnectSigner({
27
- relay: pool.group(login.data.relays),
28
- pubkey: login.pubkey,
29
- signer: clientSigner,
30
- timeout: 60_000,
31
- }));
32
- }
33
- static fromExtensionLogin(login) {
34
- return new NUser(login.type, login.pubkey, new NBrowserSigner());
35
- }
1
+ import { NBrowserSigner, NConnectSigner, NSecSigner } from "@nostrify/nostrify";
2
+ import { nip19 } from "nostr-tools";
3
+ class NUser {
4
+ constructor(method, pubkey, signer) {
5
+ this.method = method;
6
+ this.pubkey = pubkey;
7
+ this.signer = signer;
8
+ }
9
+ static fromNsecLogin(login) {
10
+ const sk = nip19.decode(login.data.nsec);
11
+ return new NUser(
12
+ login.type,
13
+ login.pubkey,
14
+ new NSecSigner(sk.data)
15
+ );
16
+ }
17
+ static fromBunkerLogin(login, pool) {
18
+ const clientSk = nip19.decode(login.data.clientNsec);
19
+ const clientSigner = new NSecSigner(clientSk.data);
20
+ return new NUser(
21
+ login.type,
22
+ login.pubkey,
23
+ new NConnectSigner({
24
+ relay: pool.group(login.data.relays),
25
+ pubkey: login.pubkey,
26
+ signer: clientSigner,
27
+ timeout: 6e4
28
+ })
29
+ );
30
+ }
31
+ static fromExtensionLogin(login) {
32
+ return new NUser(
33
+ login.type,
34
+ login.pubkey,
35
+ new NBrowserSigner()
36
+ );
37
+ }
36
38
  }
37
- //# sourceMappingURL=NUser.js.map
39
+ export {
40
+ NUser
41
+ };
@@ -1,5 +1,5 @@
1
1
  import { type Context } from 'react';
2
- import type { NLoginType } from './NLogin.js';
2
+ import type { NLoginType } from './NLogin.ts';
3
3
  /**
4
4
  * NostrLoginContextType defines the shape of the context that will be provided
5
5
  * to components that need access to the Nostr login state.
@@ -1,7 +1,5 @@
1
- import { createContext } from 'react';
2
- /**
3
- * NostrLoginContext is a React context that provides access to the Nostr login state and
4
- * a dispatch function to update the state.
5
- */
6
- export const NostrLoginContext = createContext(undefined);
7
- //# sourceMappingURL=NostrLoginContext.js.map
1
+ import { createContext } from "react";
2
+ const NostrLoginContext = createContext(void 0);
3
+ export {
4
+ NostrLoginContext
5
+ };
@@ -1,19 +1,17 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { NostrLoginContext } from './NostrLoginContext.js';
3
- import { useNostrLoginReducer } from './useNostrLoginReducer.js';
4
- /**
5
- * NostrLoginProvider is a React component that provides a context for managing Nostr logins.
6
- * It uses a reducer to handle the state of logins and stores them in localStorage.
7
- */
8
- export const NostrLoginProvider = ({ children, storageKey }) => {
9
- const [logins, dispatch] = useNostrLoginReducer(storageKey);
10
- const value = {
11
- logins,
12
- addLogin: (login) => dispatch({ type: 'login.add', login }),
13
- removeLogin: (id) => dispatch({ type: 'login.remove', id }),
14
- setLogin: (id) => dispatch({ type: 'login.set', id }),
15
- clearLogins: () => dispatch({ type: 'login.clear' }),
16
- };
17
- return jsx(NostrLoginContext.Provider, { value, children });
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { NostrLoginContext } from "./NostrLoginContext.js";
3
+ import { useNostrLoginReducer } from "./useNostrLoginReducer.js";
4
+ const NostrLoginProvider = ({ children, storageKey }) => {
5
+ const [logins, dispatch] = useNostrLoginReducer(storageKey);
6
+ const value = {
7
+ logins,
8
+ addLogin: (login) => dispatch({ type: "login.add", login }),
9
+ removeLogin: (id) => dispatch({ type: "login.remove", id }),
10
+ setLogin: (id) => dispatch({ type: "login.set", id }),
11
+ clearLogins: () => dispatch({ type: "login.clear" })
12
+ };
13
+ return jsx(NostrLoginContext.Provider, { value, children });
14
+ };
15
+ export {
16
+ NostrLoginProvider
18
17
  };
19
- //# sourceMappingURL=NostrLoginProvider.js.map
@@ -1,5 +1,5 @@
1
- export { NLogin, type NLoginType } from './NLogin.js';
2
- export { NostrLoginProvider } from './NostrLoginProvider.js';
3
- export { NUser } from './NUser.js';
4
- export { useNostrLogin } from './useNostrLogin.js';
1
+ export { NLogin, type NLoginType } from './NLogin.ts';
2
+ export { NostrLoginProvider } from './NostrLoginProvider.ts';
3
+ export { NUser } from './NUser.ts';
4
+ export { useNostrLogin } from './useNostrLogin.ts';
5
5
  //# sourceMappingURL=mod.d.ts.map
package/dist/login/mod.js CHANGED
@@ -1,5 +1,10 @@
1
- export { NLogin } from './NLogin.js';
2
- export { NostrLoginProvider } from './NostrLoginProvider.js';
3
- export { NUser } from './NUser.js';
4
- export { useNostrLogin } from './useNostrLogin.js';
5
- //# sourceMappingURL=mod.js.map
1
+ import { NLogin } from "./NLogin.js";
2
+ import { NostrLoginProvider } from "./NostrLoginProvider.js";
3
+ import { NUser } from "./NUser.js";
4
+ import { useNostrLogin } from "./useNostrLogin.js";
5
+ export {
6
+ NLogin,
7
+ NUser,
8
+ NostrLoginProvider,
9
+ useNostrLogin
10
+ };
@@ -1 +1,7 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../login/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmB,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../login/mod.ts"],
4
+ "sourcesContent": ["export { NLogin, type NLoginType } from './NLogin.ts';\nexport { NostrLoginProvider } from './NostrLoginProvider.ts';\nexport { NUser } from './NUser.ts';\nexport { useNostrLogin } from './useNostrLogin.ts';\n"],
5
+ "mappings": ";AAAA,SAAS,cAA+B;AACxC,SAAS,0BAA0B;AACnC,SAAS,aAAa;AACtB,SAAS,qBAAqB;",
6
+ "names": []
7
+ }
@@ -1,4 +1,4 @@
1
- import type { NLoginType } from './NLogin.js';
1
+ import type { NLoginType } from './NLogin.ts';
2
2
  export type NLoginAction = {
3
3
  type: 'login.add';
4
4
  login: NLoginType;
@@ -1,26 +1,28 @@
1
- export function nostrLoginReducer(state, action) {
2
- switch (action.type) {
3
- case 'login.add': {
4
- const filtered = state.filter((login) => login.id !== action.login.id);
5
- return action.set ? [action.login, ...filtered] : [...filtered, action.login];
6
- }
7
- case 'login.remove': {
8
- return state.filter((login) => login.id !== action.id);
9
- }
10
- case 'login.set': {
11
- const login = state.find((login) => login.id === action.id);
12
- if (!login) {
13
- return state;
14
- }
15
- const filtered = state.filter((login) => login.id !== action.id);
16
- return [login, ...filtered];
17
- }
18
- case 'login.clear': {
19
- return [];
20
- }
21
- default: {
22
- return state;
23
- }
1
+ function nostrLoginReducer(state, action) {
2
+ switch (action.type) {
3
+ case "login.add": {
4
+ const filtered = state.filter((login) => login.id !== action.login.id);
5
+ return action.set ? [action.login, ...filtered] : [...filtered, action.login];
24
6
  }
7
+ case "login.remove": {
8
+ return state.filter((login) => login.id !== action.id);
9
+ }
10
+ case "login.set": {
11
+ const login = state.find((login2) => login2.id === action.id);
12
+ if (!login) {
13
+ return state;
14
+ }
15
+ const filtered = state.filter((login2) => login2.id !== action.id);
16
+ return [login, ...filtered];
17
+ }
18
+ case "login.clear": {
19
+ return [];
20
+ }
21
+ default: {
22
+ return state;
23
+ }
24
+ }
25
25
  }
26
- //# sourceMappingURL=nostrLoginReducer.js.map
26
+ export {
27
+ nostrLoginReducer
28
+ };
@@ -1,3 +1,3 @@
1
- import { type NostrLoginContextType } from './NostrLoginContext.js';
1
+ import { type NostrLoginContextType } from './NostrLoginContext.ts';
2
2
  export declare function useNostrLogin(): NostrLoginContextType;
3
3
  //# sourceMappingURL=useNostrLogin.d.ts.map
@@ -1,10 +1,12 @@
1
- import { useContext } from 'react';
2
- import { NostrLoginContext } from './NostrLoginContext.js';
3
- export function useNostrLogin() {
4
- const context = useContext(NostrLoginContext);
5
- if (!context) {
6
- throw new Error('useNostrLogin must be used within a NostrLoginProvider');
7
- }
8
- return context;
1
+ import { useContext } from "react";
2
+ import { NostrLoginContext } from "./NostrLoginContext.js";
3
+ function useNostrLogin() {
4
+ const context = useContext(NostrLoginContext);
5
+ if (!context) {
6
+ throw new Error("useNostrLogin must be used within a NostrLoginProvider");
7
+ }
8
+ return context;
9
9
  }
10
- //# sourceMappingURL=useNostrLogin.js.map
10
+ export {
11
+ useNostrLogin
12
+ };
@@ -1,4 +1,4 @@
1
- import { type NLoginAction } from './nostrLoginReducer.js';
2
- import type { NLoginType } from './NLogin.js';
1
+ import { type NLoginAction } from './nostrLoginReducer.ts';
2
+ import type { NLoginType } from './NLogin.ts';
3
3
  export declare function useNostrLoginReducer(storageKey: string): [state: NLoginType[], dispatch: (action: NLoginAction) => void];
4
4
  //# sourceMappingURL=useNostrLoginReducer.d.ts.map
@@ -1,13 +1,15 @@
1
- import { useEffect, useReducer } from 'react';
2
- import { nostrLoginReducer } from './nostrLoginReducer.js';
3
- export function useNostrLoginReducer(storageKey) {
4
- const [state, dispatch] = useReducer(nostrLoginReducer, [], () => {
5
- const stored = localStorage.getItem(storageKey);
6
- return stored ? JSON.parse(stored) : [];
7
- });
8
- useEffect(() => {
9
- localStorage.setItem(storageKey, JSON.stringify(state));
10
- }, [state]);
11
- return [state, dispatch];
1
+ import { useEffect, useReducer } from "react";
2
+ import { nostrLoginReducer } from "./nostrLoginReducer.js";
3
+ function useNostrLoginReducer(storageKey) {
4
+ const [state, dispatch] = useReducer(nostrLoginReducer, [], () => {
5
+ const stored = localStorage.getItem(storageKey);
6
+ return stored ? JSON.parse(stored) : [];
7
+ });
8
+ useEffect(() => {
9
+ localStorage.setItem(storageKey, JSON.stringify(state));
10
+ }, [state]);
11
+ return [state, dispatch];
12
12
  }
13
- //# sourceMappingURL=useNostrLoginReducer.js.map
13
+ export {
14
+ useNostrLoginReducer
15
+ };
package/dist/mod.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- export { NostrContext, type NostrContextType } from './NostrContext.js';
2
- export { useNostr } from './useNostr.js';
1
+ export { NostrContext, type NostrContextType } from './NostrContext.ts';
2
+ export { useNostr } from './useNostr.ts';
3
+ export * from './login/mod.ts';
3
4
  //# sourceMappingURL=mod.d.ts.map
package/dist/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,cAAc,gBAAgB,CAAC"}
package/dist/mod.js CHANGED
@@ -1,3 +1,7 @@
1
- export { NostrContext } from './NostrContext.js';
2
- export { useNostr } from './useNostr.js';
3
- //# sourceMappingURL=mod.js.map
1
+ import { NostrContext } from "./NostrContext.js";
2
+ import { useNostr } from "./useNostr.js";
3
+ export * from "./login/mod.js";
4
+ export {
5
+ NostrContext,
6
+ useNostr
7
+ };
package/dist/mod.js.map CHANGED
@@ -1 +1,7 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../mod.ts"],
4
+ "sourcesContent": ["export { NostrContext, type NostrContextType } from './NostrContext.ts';\nexport { useNostr } from './useNostr.ts';\n"],
5
+ "mappings": ";AAAA,SAAS,oBAA2C;AACpD,SAAS,gBAAgB;",
6
+ "names": []
7
+ }