@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.
- package/.turbo/turbo-build.log +4 -5
- package/.turbo/turbo-setup.log +13 -0
- package/.turbo/turbo-test.log +13 -0
- package/CHANGELOG.md +18 -0
- package/dist/NostrContext.js +7 -7
- package/dist/example/test-helpers.js +32 -30
- package/dist/example/useAuthor.d.ts +1 -1
- package/dist/example/useAuthor.d.ts.map +1 -1
- package/dist/example/useAuthor.js +30 -26
- package/dist/example/useCurrentUser.d.ts +2 -5
- package/dist/example/useCurrentUser.d.ts.map +1 -1
- package/dist/example/useCurrentUser.js +40 -40
- package/dist/example/useLoginActions.d.ts.map +1 -1
- package/dist/example/useLoginActions.js +22 -20
- package/dist/example/useSocialFeed.d.ts +1 -1
- package/dist/example/useSocialFeed.d.ts.map +1 -1
- package/dist/example/useSocialFeed.js +14 -9
- package/dist/example/vite-env.d.js +0 -0
- package/dist/login/NLogin.d.ts +1 -1
- package/dist/login/NLogin.d.ts.map +1 -1
- package/dist/login/NLogin.js +69 -68
- package/dist/login/NUser.d.ts +3 -2
- package/dist/login/NUser.d.ts.map +1 -1
- package/dist/login/NUser.js +40 -36
- package/dist/login/NostrLoginContext.d.ts +1 -1
- package/dist/login/NostrLoginContext.js +5 -7
- package/dist/login/NostrLoginProvider.js +16 -18
- package/dist/login/mod.d.ts +4 -4
- package/dist/login/mod.js +10 -5
- package/dist/login/mod.js.map +7 -1
- package/dist/login/nostrLoginReducer.d.ts +1 -1
- package/dist/login/nostrLoginReducer.js +26 -24
- package/dist/login/useNostrLogin.d.ts +1 -1
- package/dist/login/useNostrLogin.js +11 -9
- package/dist/login/useNostrLoginReducer.d.ts +2 -2
- package/dist/login/useNostrLoginReducer.js +14 -12
- package/dist/mod.d.ts +3 -2
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +7 -3
- package/dist/mod.js.map +7 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/useNostr.d.ts +1 -1
- package/dist/useNostr.js +11 -9
- package/example/useAuthor.ts +3 -2
- package/example/useCurrentUser.ts +2 -2
- package/example/useSocialFeed.ts +2 -2
- package/login/NLogin.ts +3 -1
- package/login/NUser.ts +4 -2
- package/login/NostrLoginContext.ts +1 -1
- package/login/NostrLoginProvider.ts +2 -2
- package/login/mod.ts +4 -4
- package/login/nostrLoginReducer.ts +1 -1
- package/login/useNostrLogin.ts +1 -1
- package/login/useNostrLoginReducer.ts +2 -2
- package/mod.ts +3 -2
- package/package.json +17 -10
- package/tsconfig.json +7 -1
- package/useNostr.ts +1 -1
- package/dist/NostrContext.js.map +0 -1
- package/dist/example/test-helpers.js.map +0 -1
- package/dist/example/useAuthor.js.map +0 -1
- package/dist/example/useCurrentUser.js.map +0 -1
- package/dist/example/useLoginActions.js.map +0 -1
- package/dist/example/useSocialFeed.js.map +0 -1
- package/dist/login/NLogin.js.map +0 -1
- package/dist/login/NUser.js.map +0 -1
- package/dist/login/NostrLoginContext.js.map +0 -1
- package/dist/login/NostrLoginProvider.js.map +0 -1
- package/dist/login/nostrLoginReducer.js.map +0 -1
- package/dist/login/useNostrLogin.js.map +0 -1
- package/dist/login/useNostrLoginReducer.js.map +0 -1
- package/dist/useNostr.js.map +0 -1
package/dist/login/NUser.js
CHANGED
|
@@ -1,37 +1,41 @@
|
|
|
1
|
-
import { NBrowserSigner, NConnectSigner, NSecSigner } from
|
|
2
|
-
import { nip19 } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
method;
|
|
6
|
-
pubkey;
|
|
7
|
-
signer;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
39
|
+
export {
|
|
40
|
+
NUser
|
|
41
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Context } from 'react';
|
|
2
|
-
import type { NLoginType } from './NLogin.
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
2
|
-
import { NostrLoginContext } from
|
|
3
|
-
import { useNostrLoginReducer } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
package/dist/login/mod.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { NLogin, type NLoginType } from './NLogin.
|
|
2
|
-
export { NostrLoginProvider } from './NostrLoginProvider.
|
|
3
|
-
export { NUser } from './NUser.
|
|
4
|
-
export { useNostrLogin } from './useNostrLogin.
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
};
|
package/dist/login/mod.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
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,26 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
26
|
+
export {
|
|
27
|
+
nostrLoginReducer
|
|
28
|
+
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { useContext } from
|
|
2
|
-
import { NostrLoginContext } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
10
|
+
export {
|
|
11
|
+
useNostrLogin
|
|
12
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type NLoginAction } from './nostrLoginReducer.
|
|
2
|
-
import type { NLoginType } from './NLogin.
|
|
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
|
|
2
|
-
import { nostrLoginReducer } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
13
|
+
export {
|
|
14
|
+
useNostrLoginReducer
|
|
15
|
+
};
|
package/dist/mod.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { NostrContext, type NostrContextType } from './NostrContext.
|
|
2
|
-
export { useNostr } from './useNostr.
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
{
|
|
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
|
+
}
|