@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.
- package/.turbo/turbo-build.log +4 -5
- package/.turbo/turbo-setup.log +13 -0
- package/.turbo/turbo-test.log +13 -0
- package/CHANGELOG.md +9 -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 +9 -7
- 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/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
>
|
|
4
|
-
|
|
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 [96m1[39m, reused [96m0[39m, downloaded [96m0[39m, added [96m0[39m
|
|
10
|
+
[1A../.. | [32m+1[39m [32m+[39m[0K
|
|
11
|
+
../.. | Progress: resolved [96m1[39m, reused [96m0[39m, downloaded [96m0[39m, added [96m0[39m
|
|
12
|
+
[1A../.. | Progress: resolved [96m1[39m, reused [96m1[39m, downloaded [96m0[39m, added [96m0[39m
|
|
13
|
+
[1A../.. | Progress: resolved [96m1[39m, reused [96m1[39m, downloaded [96m0[39m, added [96m0[39m, done
|
package/CHANGELOG.md
CHANGED
package/dist/NostrContext.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createContext } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
31
|
+
export {
|
|
32
|
+
polyfillDOM
|
|
33
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthor.d.ts","sourceRoot":"","sources":["../../example/useAuthor.ts"],"names":[],"mappings":"
|
|
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
|
|
2
|
-
import { useSuspenseQuery } from
|
|
3
|
-
import { useNostr } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
29
|
+
export {
|
|
30
|
+
useAuthor
|
|
31
|
+
};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { NUser } from '@nostrify/react/login';
|
|
2
1
|
export declare function useCurrentUser(): {
|
|
3
|
-
user:
|
|
2
|
+
user: any;
|
|
4
3
|
users: NUser[];
|
|
5
|
-
metadata:
|
|
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":"
|
|
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
|
|
2
|
-
import { useMemo } from
|
|
3
|
-
import { useAuthor } from
|
|
4
|
-
import { useNostr } from
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
|
2
|
-
import { NLogin, useNostrLogin } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
21
|
+
export {
|
|
22
|
+
useLoginActions
|
|
23
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type UseSuspenseQueryResult } from '@tanstack/react-query';
|
|
2
|
-
import type { NostrEvent } from '@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,
|
|
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
|
|
2
|
-
import { useNostr } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
13
|
+
export {
|
|
14
|
+
useSocialFeed
|
|
15
|
+
};
|
|
File without changes
|
package/dist/login/NLogin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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":"
|
|
1
|
+
{"version":3,"file":"NLogin.d.ts","sourceRoot":"","sources":["../../login/NLogin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAIhD,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"}
|
package/dist/login/NLogin.js
CHANGED
|
@@ -1,72 +1,73 @@
|
|
|
1
|
-
import { BunkerURI, NConnectSigner, NSecSigner } from
|
|
2
|
-
import { generateSecretKey, getPublicKey, nip19 } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
71
|
+
export {
|
|
72
|
+
NLogin
|
|
73
|
+
};
|
package/dist/login/NUser.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
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":"
|
|
1
|
+
{"version":3,"file":"NUser.d.ts","sourceRoot":"","sources":["../../login/NUser.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,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;IAmB/D,MAAM,CAAC,kBAAkB,CAAC,KAAK,EAAE,eAAe,GAAG,KAAK;CAOzD"}
|