@mblaney/holster-browser 2.0.2 → 2.1.0
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/package.json +3 -3
- package/src/baseStyleOverrides.js +10 -0
- package/src/components/Login.jsx +2 -6
- package/src/components/SearchAppBar.jsx +1 -1
- package/src/components/__tests__/Login.test.jsx +16 -24
- package/src/components/__tests__/LoginCodes.test.jsx +5 -7
- package/src/components/__tests__/UpdatePassword.test.jsx +1 -3
- package/src/hooks/__tests__/useAccountSync.test.js +12 -22
- package/src/hooks/useAccountSync.js +15 -24
- package/src/index.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mblaney/holster-browser",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "React components for holster applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@emotion/react": ">=11.0.0",
|
|
25
25
|
"@emotion/styled": ">=11.0.0",
|
|
26
|
-
"@mblaney/holster": ">=2.
|
|
26
|
+
"@mblaney/holster": ">=2.3.0",
|
|
27
27
|
"@mui/icons-material": ">=5.0.0",
|
|
28
28
|
"@mui/material": ">=5.0.0",
|
|
29
29
|
"react": ">=18.0.0"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"test": "vitest --run"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@mblaney/holster": "^2.
|
|
35
|
+
"@mblaney/holster": "^2.3.0",
|
|
36
36
|
"@testing-library/jest-dom": "^5.17.0",
|
|
37
37
|
"@testing-library/react": "^14.0.0",
|
|
38
38
|
"@testing-library/user-event": "^13.5.0",
|
package/src/components/Login.jsx
CHANGED
|
@@ -26,15 +26,11 @@ const Login = ({user, host}) => {
|
|
|
26
26
|
if (!user.is) return
|
|
27
27
|
|
|
28
28
|
setMessage("Credentials verified, looking up account...")
|
|
29
|
-
const code = await
|
|
30
|
-
user.get([host, "map"]).next("account:" + user.is.pub, res)
|
|
31
|
-
})
|
|
29
|
+
const code = await user.get([host, "map"]).next("account:" + user.is.pub)
|
|
32
30
|
if (!code) return
|
|
33
31
|
|
|
34
32
|
setMessage("Account found, verifying details...")
|
|
35
|
-
const account = await
|
|
36
|
-
user.get([host, "accounts"]).next(code, res)
|
|
37
|
-
})
|
|
33
|
+
const account = await user.get([host, "accounts"]).next(code)
|
|
38
34
|
if (!account) return
|
|
39
35
|
|
|
40
36
|
if (account.pub !== user.is.pub) {
|
|
@@ -234,7 +234,7 @@ const SearchAppBar = ({
|
|
|
234
234
|
collapsed={collapsed}
|
|
235
235
|
inputRef={searchInputRef}
|
|
236
236
|
placeholder="Search…"
|
|
237
|
-
inputProps={{"aria-label": "search"}}
|
|
237
|
+
inputProps={{"aria-label": "search", enterKeyHint: "search"}}
|
|
238
238
|
value={searchValue}
|
|
239
239
|
onChange={e => setSearchValue(e.target.value)}
|
|
240
240
|
onKeyDown={e => {
|
|
@@ -20,18 +20,14 @@ async function createHostedAccount({
|
|
|
20
20
|
await new Promise(resolve => user.auth(username, password, resolve))
|
|
21
21
|
const host = user.is.pub
|
|
22
22
|
|
|
23
|
-
await
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.get([host, "accounts"])
|
|
32
|
-
.next(accountCode)
|
|
33
|
-
.put({pub: host, name: accountName}, resolve)
|
|
34
|
-
})
|
|
23
|
+
await user
|
|
24
|
+
.get([host, "map"])
|
|
25
|
+
.next("account:" + host)
|
|
26
|
+
.put(accountCode)
|
|
27
|
+
await user
|
|
28
|
+
.get([host, "accounts"])
|
|
29
|
+
.next(accountCode)
|
|
30
|
+
.put({pub: host, name: accountName})
|
|
35
31
|
|
|
36
32
|
user.leave()
|
|
37
33
|
return {holster, user, host, username, password, accountCode, accountName}
|
|
@@ -155,18 +151,14 @@ describe("Login Component", () => {
|
|
|
155
151
|
const host = user.is.pub
|
|
156
152
|
const stalePub = "some-other-pub.some-other-epub"
|
|
157
153
|
|
|
158
|
-
await
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
.get([host, "accounts"])
|
|
167
|
-
.next("acc1")
|
|
168
|
-
.put({pub: stalePub, name: "Alice"}, resolve)
|
|
169
|
-
})
|
|
154
|
+
await user
|
|
155
|
+
.get([host, "map"])
|
|
156
|
+
.next("account:" + host)
|
|
157
|
+
.put("acc1")
|
|
158
|
+
await user
|
|
159
|
+
.get([host, "accounts"])
|
|
160
|
+
.next("acc1")
|
|
161
|
+
.put({pub: stalePub, name: "Alice"})
|
|
170
162
|
user.leave()
|
|
171
163
|
|
|
172
164
|
render(<Login user={user} host={host} />)
|
|
@@ -12,13 +12,11 @@ import LoginCodes from "../LoginCodes.jsx"
|
|
|
12
12
|
async function shareCode(user, code, key, value) {
|
|
13
13
|
const secret = await user.SEA.secret({epub: user.is.epub}, user.is)
|
|
14
14
|
const enc = value === null ? null : await user.SEA.encrypt(value, secret)
|
|
15
|
-
await
|
|
16
|
-
user
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.put({[key]: enc}, resolve)
|
|
21
|
-
})
|
|
15
|
+
await user
|
|
16
|
+
.get([user.is.pub, "shared"])
|
|
17
|
+
.next("login_codes")
|
|
18
|
+
.next(code)
|
|
19
|
+
.put({[key]: enc})
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
describe("LoginCodes Component", () => {
|
|
@@ -109,9 +109,7 @@ describe("UpdatePassword Component", () => {
|
|
|
109
109
|
)
|
|
110
110
|
|
|
111
111
|
await waitFor(async () => {
|
|
112
|
-
const publicData = await
|
|
113
|
-
user.get("public", resolve)
|
|
114
|
-
})
|
|
112
|
+
const publicData = await user.get("public")
|
|
115
113
|
expect(publicData?.favoriteColor).toBe("blue")
|
|
116
114
|
})
|
|
117
115
|
|
|
@@ -21,47 +21,37 @@ describe("useAccountSync", () => {
|
|
|
21
21
|
|
|
22
22
|
// The host's own record of this contact's account, already migrated to
|
|
23
23
|
// the new key.
|
|
24
|
-
await
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
.put({pub: newAccount.pub}, resolve)
|
|
29
|
-
})
|
|
24
|
+
await user
|
|
25
|
+
.get([host, "accounts"])
|
|
26
|
+
.next(contactCode)
|
|
27
|
+
.put({pub: newAccount.pub})
|
|
30
28
|
|
|
31
29
|
// This user's own previously-recorded (now stale) copy of the contact.
|
|
32
|
-
await
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
.put({pub: oldAccount.pub}, resolve)
|
|
38
|
-
})
|
|
30
|
+
await user
|
|
31
|
+
.get("public")
|
|
32
|
+
.next("contacts")
|
|
33
|
+
.next(contactCode)
|
|
34
|
+
.put({pub: oldAccount.pub})
|
|
39
35
|
|
|
40
36
|
// Something previously shared with the contact, encrypted for their old
|
|
41
37
|
// key.
|
|
42
38
|
const oldSecret = await holster.SEA.secret(oldAccount, user.is)
|
|
43
39
|
const oldEnc = await holster.SEA.encrypt("secret data", oldSecret)
|
|
44
|
-
await
|
|
45
|
-
user.get("shared").next(contactCode).put({someKey: oldEnc}, resolve)
|
|
46
|
-
})
|
|
40
|
+
await user.get("shared").next(contactCode).put({someKey: oldEnc})
|
|
47
41
|
|
|
48
42
|
renderHook(() => useAccountSync(holster, user, host, code))
|
|
49
43
|
|
|
50
44
|
const newSecret = await holster.SEA.secret(newAccount, user.is)
|
|
51
45
|
|
|
52
46
|
await waitFor(async () => {
|
|
53
|
-
const shared = await
|
|
54
|
-
user.get("shared").next(contactCode, resolve)
|
|
55
|
-
})
|
|
47
|
+
const shared = await user.get("shared").next(contactCode)
|
|
56
48
|
expect(shared?.someKey).toBeTruthy()
|
|
57
49
|
expect(await holster.SEA.decrypt(shared.someKey, newSecret)).toBe(
|
|
58
50
|
"secret data",
|
|
59
51
|
)
|
|
60
52
|
})
|
|
61
53
|
|
|
62
|
-
const shared = await
|
|
63
|
-
user.get("shared").next(contactCode, resolve)
|
|
64
|
-
})
|
|
54
|
+
const shared = await user.get("shared").next(contactCode)
|
|
65
55
|
expect(await holster.SEA.decrypt(shared.someKey, oldSecret)).toBe(null)
|
|
66
56
|
})
|
|
67
57
|
})
|
|
@@ -12,9 +12,7 @@ export function useAccountSync(holster, user, host, code) {
|
|
|
12
12
|
setAccountsReady(true)
|
|
13
13
|
|
|
14
14
|
// Check accounts against the users list of contacts.
|
|
15
|
-
const c = await
|
|
16
|
-
user.get("public").next("contacts", res)
|
|
17
|
-
})
|
|
15
|
+
const c = await user.get("public").next("contacts")
|
|
18
16
|
if (!c) return
|
|
19
17
|
|
|
20
18
|
for (const [accountCode, account] of Object.entries(accounts)) {
|
|
@@ -39,34 +37,26 @@ export function useAccountSync(holster, user, host, code) {
|
|
|
39
37
|
// If the public key has changed for this contact then store their
|
|
40
38
|
// new account details and re-share encrypted data with them to
|
|
41
39
|
// help restore their account.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
})
|
|
49
|
-
if (err) console.error(err)
|
|
40
|
+
await user
|
|
41
|
+
.get("public")
|
|
42
|
+
.next("contacts")
|
|
43
|
+
.next(contactCode)
|
|
44
|
+
.put(check)
|
|
45
|
+
.catch(err => console.error(err))
|
|
50
46
|
|
|
51
|
-
const oldEpub = await
|
|
52
|
-
user.get([contact.pub, "epub"], res)
|
|
53
|
-
})
|
|
47
|
+
const oldEpub = await user.get([contact.pub, "epub"])
|
|
54
48
|
if (!oldEpub) {
|
|
55
49
|
console.error("User not found for old public key")
|
|
56
50
|
break
|
|
57
51
|
}
|
|
58
52
|
|
|
59
|
-
const epub = await
|
|
60
|
-
user.get([check.pub, "epub"], res)
|
|
61
|
-
})
|
|
53
|
+
const epub = await user.get([check.pub, "epub"])
|
|
62
54
|
if (!epub) {
|
|
63
55
|
console.error("User not found for new public key")
|
|
64
56
|
break
|
|
65
57
|
}
|
|
66
58
|
|
|
67
|
-
const shared = await
|
|
68
|
-
user.get("shared").next(contactCode, res)
|
|
69
|
-
})
|
|
59
|
+
const shared = await user.get("shared").next(contactCode)
|
|
70
60
|
if (!shared) break
|
|
71
61
|
|
|
72
62
|
const oldSecret = await holster.SEA.secret({epub: oldEpub}, user.is)
|
|
@@ -80,10 +70,11 @@ export function useAccountSync(holster, user, host, code) {
|
|
|
80
70
|
update[key] = enc
|
|
81
71
|
}
|
|
82
72
|
if (Object.keys(update).length !== 0) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
73
|
+
await user
|
|
74
|
+
.get("shared")
|
|
75
|
+
.next(contactCode)
|
|
76
|
+
.put(update)
|
|
77
|
+
.catch(err => console.error(err))
|
|
87
78
|
}
|
|
88
79
|
}
|
|
89
80
|
// Add the new contact if we referred them.
|
package/src/index.js
CHANGED
|
@@ -10,3 +10,4 @@ export {default as Settings} from "./components/Settings.jsx"
|
|
|
10
10
|
export {default as UpdatePassword} from "./components/UpdatePassword.jsx"
|
|
11
11
|
export {default as ValidateEmail} from "./components/ValidateEmail.jsx"
|
|
12
12
|
export {useAccountSync} from "./hooks/useAccountSync.js"
|
|
13
|
+
export {baseStyleOverrides} from "./baseStyleOverrides.js"
|