Skip to content

Commit 9f060db

Browse files
committed
Tell the login server when duplicate keys are OK
1 parent d324c60 commit 9f060db

File tree

6 files changed

+11
-3
lines changed

6 files changed

+11
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- fixed: Allow duplicate sync keys when performing a wallet split, in case a previous failed attempt left a repo behind.
56
- fixed: Do not lose wallet import history when doing a split-archive-split.
67

78
## 2.38.3 (2026-01-06)

src/core/fake/fake-server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ function createLogin(request: ApiRequest, login?: DbLogin): HttpResponse {
275275

276276
// Set up repos:
277277
const keys = asMaybe(asCreateKeysPayload, () => ({
278+
allowExisting: false,
278279
newSyncKeys: [],
279280
keyBoxes: []
280281
}))(body.data)

src/core/login/keys.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,15 @@ export function makeKeyInfo(
6767

6868
/**
6969
* Assembles all the resources needed to attach new keys to the account.
70+
* @param allowExisting True if the sync keys were derived deterministically,
71+
* which implies that duplicate sync keys on the server are not errors,
72+
* but leftovers from an earlier failed splitting attempt.
7073
*/
7174
export function makeKeysKit(
7275
ai: ApiInput,
7376
sessionKey: SessionKey,
74-
keyInfos: EdgeWalletInfo[]
77+
keyInfos: EdgeWalletInfo[],
78+
allowExisting: boolean = false
7579
): LoginKit {
7680
// For crash errors:
7781
ai.props.log.breadcrumb('makeKeysKit', {})
@@ -95,7 +99,7 @@ export function makeKeysKit(
9599

96100
return {
97101
loginId: sessionKey.loginId,
98-
server: wasCreateKeysPayload({ keyBoxes, newSyncKeys }),
102+
server: wasCreateKeysPayload({ allowExisting, keyBoxes, newSyncKeys }),
99103
serverPath: '/v2/login/keys',
100104
stash: { keyBoxes }
101105
}

src/core/login/splitting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export async function splitWalletInfo(
157157
}
158158

159159
// Add the keys to the login:
160-
const kit = makeKeysKit(ai, sessionKey, [newWalletInfo])
160+
const kit = makeKeysKit(ai, sessionKey, [newWalletInfo], true)
161161
await applyKit(ai, sessionKey, kit)
162162

163163
// Try to copy metadata on a best-effort basis.

src/types/server-cleaners.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ export const asChangeVouchersPayload: Cleaner<ChangeVouchersPayload> = asObject(
245245
)
246246

247247
export const asCreateKeysPayload: Cleaner<CreateKeysPayload> = asObject({
248+
allowExisting: asOptional(asBoolean, false),
248249
keyBoxes: asArray(asEdgeBox),
249250
newSyncKeys: asOptional(asArray(asString), () => [])
250251
})

src/types/server-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export interface ChangeVouchersPayload {
168168
}
169169

170170
export interface CreateKeysPayload {
171+
allowExisting: boolean
171172
keyBoxes: EdgeBox[]
172173
newSyncKeys: string[]
173174
}

0 commit comments

Comments
 (0)