mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-03 07:57:22 +00:00
Upgrade @nostrify/react to 0.6.6 to enforce the nostrconnect handshake secret
0.6.6 enforces the nostrconnect handshake secret. Previously a signer could answer the connect request with result: "ack" and skip proving it could decrypt the secret, so any relay-connected party who saw the nostrconnect URI could claim the session and become the user's signer. The 0.6.6 NostrLoginProvider now resolves stored logins on a microtask (rendering a null fallback until storage resolves) rather than synchronously. Component/hook tests render and query immediately, so they observed an empty tree. Mock @nostrify/react/login in the test setup with a synchronous provider and matching useNostrLogin hook, passing every other export (NLogin, NUser, the connect helpers) through from the real module untouched.
This commit is contained in:
1 parent
d3cceb56ee
commit
90d02c42d6
3 files changed
+91
-16
No files matched your search
Generated
+14
-14
@@ -21,8 +21,8 @@
|
||||
"@isomorphic-git/lightning-fs": "^4.6.2",
|
||||
"@modelcontextprotocol/sdk": "^1.22.0",
|
||||
"@mozilla/readability": "^0.6.0",
|
||||
"@nostrify/nostrify": "^0.51.1",
|
||||
"@nostrify/react": "^0.4.1",
|
||||
"@nostrify/nostrify": "^0.54.1",
|
||||
"@nostrify/react": "^0.6.6",
|
||||
"@opensecret/react": "^1.5.4",
|
||||
"@plausible-analytics/tracker": "^0.4.4",
|
||||
"@radix-ui/react-accordion": "^1.2.0",
|
||||
@@ -3293,11 +3293,11 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@nostrify/nostrify": {
|
||||
"version": "0.51.1",
|
||||
"resolved": "https://registry.npmjs.org/@nostrify/nostrify/-/nostrify-0.51.1.tgz",
|
||||
"integrity": "sha512-oPJhUiO1TlV5sGYizqAP4GvLijib34Uwh48wxlFimR/2MoCuSmab4AppcztGPNwxQoTKkJbLJwsSpl42V+WIXA==",
|
||||
"version": "0.54.1",
|
||||
"resolved": "https://registry.npmjs.org/@nostrify/nostrify/-/nostrify-0.54.1.tgz",
|
||||
"integrity": "sha512-/iMRPBZdz+74pPXKHbQ7RsMwQtEXbJ/M21iNp1kbAMMvRh30hFjdV3ROU93rxGIDsOMSOpzeXXWT4Z+gXZW8Bg==",
|
||||
"dependencies": {
|
||||
"@nostrify/types": "0.36.9",
|
||||
"@nostrify/types": "0.37.0",
|
||||
"@scure/base": "^2.0.0",
|
||||
"@smithy/util-base64": "^4.3.0",
|
||||
"@smithy/util-hex-encoding": "^4.2.0",
|
||||
@@ -3334,12 +3334,12 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@nostrify/react": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@nostrify/react/-/react-0.4.1.tgz",
|
||||
"integrity": "sha512-2JXxEl4e6FIFhbi96Dwv2knu5qAACYulo1a0oVell/aS8KCWsBTPd1+v0EUra0yqiUA3Q1nVLrk8mx7kQYH/yQ==",
|
||||
"version": "0.6.6",
|
||||
"resolved": "https://registry.npmjs.org/@nostrify/react/-/react-0.6.6.tgz",
|
||||
"integrity": "sha512-WTWTT3dtw0BF5bZsFgOob9S3J9rWKOsPQ2LLKDsDhx3PxbjIFKSVqSQLw7jiN6LoVGom9OuVOG/PB6p9hAWDjQ==",
|
||||
"dependencies": {
|
||||
"@nostrify/nostrify": "0.51.1",
|
||||
"@nostrify/types": "0.36.9"
|
||||
"@nostrify/nostrify": "0.54.1",
|
||||
"@nostrify/types": "0.37.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@tanstack/react-query": "^5.69.0",
|
||||
@@ -3349,9 +3349,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@nostrify/types": {
|
||||
"version": "0.36.9",
|
||||
"resolved": "https://registry.npmjs.org/@nostrify/types/-/types-0.36.9.tgz",
|
||||
"integrity": "sha512-tMx/r0W+QoVRRgs8d6ltaSgrftasOXuFsi33kW8WirswCy2b3UR1tqRgc0iBU9zRa9XR0nlej/wJZW+6wUFi+Q=="
|
||||
"version": "0.37.0",
|
||||
"resolved": "https://registry.npmjs.org/@nostrify/types/-/types-0.37.0.tgz",
|
||||
"integrity": "sha512-P0AKR+qcNeBBTA5UDnJM6SxLAQbgud2+ZcdVyheoP37XGQvi7rUncQUDKwebG+Ui5kswp/IPEmvqNtCMQpwRoA=="
|
||||
},
|
||||
"node_modules/@opensecret/react": {
|
||||
"version": "1.5.4",
|
||||
|
||||
+2
-2
@@ -34,8 +34,8 @@
|
||||
"@isomorphic-git/lightning-fs": "^4.6.2",
|
||||
"@modelcontextprotocol/sdk": "^1.22.0",
|
||||
"@mozilla/readability": "^0.6.0",
|
||||
"@nostrify/nostrify": "^0.51.1",
|
||||
"@nostrify/react": "^0.4.1",
|
||||
"@nostrify/nostrify": "^0.54.1",
|
||||
"@nostrify/react": "^0.6.6",
|
||||
"@opensecret/react": "^1.5.4",
|
||||
"@plausible-analytics/tracker": "^0.4.4",
|
||||
"@radix-ui/react-accordion": "^1.2.0",
|
||||
|
||||
@@ -34,6 +34,81 @@ class LocalStorageMock implements Storage {
|
||||
|
||||
global.localStorage = new LocalStorageMock();
|
||||
|
||||
// The @nostrify/react 0.6.6 NostrLoginProvider resolves stored logins on a
|
||||
// microtask: it renders a null `fallback` on the first synchronous paint and
|
||||
// only mounts its children once storage resolves. Component/hook tests render
|
||||
// synchronously and query immediately, so they'd observe an empty tree (this is
|
||||
// the sole cause of the render breakage introduced by the upgrade). Replace the
|
||||
// provider — and the hook that reads its context — with a synchronous
|
||||
// equivalent for tests, importing everything else (NLogin.nostrconnect and the
|
||||
// connect helpers, whose handshake enforcement is the point of the upgrade;
|
||||
// NUser) from the real module untouched.
|
||||
vi.mock('@nostrify/react/login', async (importActual) => {
|
||||
const actual = await importActual<typeof import('@nostrify/react/login')>();
|
||||
const { createContext, useContext, useReducer, useEffect, createElement } = await import('react');
|
||||
|
||||
const NostrLoginContext = createContext<unknown>(undefined);
|
||||
|
||||
type Login = { id: string };
|
||||
type LoginAction =
|
||||
| { type: 'login.add'; login: Login; set?: boolean }
|
||||
| { type: 'login.remove'; id: string }
|
||||
| { type: 'login.set'; id: string }
|
||||
| { type: 'login.clear' };
|
||||
|
||||
function reducer(state: Login[], action: LoginAction): Login[] {
|
||||
switch (action.type) {
|
||||
case 'login.add': {
|
||||
const filtered = state.filter((l) => l.id !== action.login.id);
|
||||
return action.set ? [action.login, ...filtered] : [...filtered, action.login];
|
||||
}
|
||||
case 'login.remove':
|
||||
return state.filter((l) => l.id !== action.id);
|
||||
case 'login.set': {
|
||||
const login = state.find((l) => l.id === action.id);
|
||||
if (!login) return state;
|
||||
return [login, ...state.filter((l) => l.id !== action.id)];
|
||||
}
|
||||
case 'login.clear':
|
||||
return [];
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
const NostrLoginProvider = ({ children, storageKey, storage = localStorage }: {
|
||||
children: React.ReactNode;
|
||||
storageKey: string;
|
||||
storage?: Storage;
|
||||
}) => {
|
||||
const [state, dispatch] = useReducer(reducer, undefined, (): Login[] => {
|
||||
const stored = storage.getItem(storageKey);
|
||||
return typeof stored === 'string' ? (JSON.parse(stored) as Login[]) : [];
|
||||
});
|
||||
useEffect(() => {
|
||||
storage.setItem(storageKey, JSON.stringify(state));
|
||||
}, [state, storageKey, storage]);
|
||||
const value = {
|
||||
logins: state,
|
||||
addLogin: (login: Login) => dispatch({ type: 'login.add', login }),
|
||||
removeLogin: (id: string) => dispatch({ type: 'login.remove', id }),
|
||||
setLogin: (id: string) => dispatch({ type: 'login.set', id }),
|
||||
clearLogins: () => dispatch({ type: 'login.clear' }),
|
||||
};
|
||||
return createElement(NostrLoginContext.Provider, { value }, children);
|
||||
};
|
||||
|
||||
function useNostrLogin() {
|
||||
const context = useContext(NostrLoginContext);
|
||||
if (!context) {
|
||||
throw new Error('useNostrLogin must be used within a NostrLoginProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
return { ...actual, NostrLoginProvider, useNostrLogin };
|
||||
});
|
||||
|
||||
// Mock CSS imports
|
||||
vi.mock('*.css', () => ({}));
|
||||
vi.mock('*.scss', () => ({}));
|
||||
|
||||
Reference in new issue
Block a user