From c24256849f717800d6ba5b31b507eefb161d926f Mon Sep 17 00:00:00 2001 From: William Swanson Date: Thu, 5 Sep 2024 12:09:02 -0700 Subject: [PATCH] Add types for server-returned key creation dates --- scripts/make-types.ts | 5 ++++- src/core/login/login-stash.ts | 7 ++++--- src/types/fake-types.ts | 7 ++++--- src/types/server-cleaners.ts | 10 +++++++++- src/types/server-types.ts | 9 ++++++++- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/scripts/make-types.ts b/scripts/make-types.ts index a9bae5e7d..22ccd3d6d 100755 --- a/scripts/make-types.ts +++ b/scripts/make-types.ts @@ -17,7 +17,10 @@ async function tsToFlow(code: string): Promise { .replace(/\bexport declare\b/g, 'declare export') .replace(/\binterface (\w+) {/g, 'type $1 = {') .replace(/\binterface (\w+)<([^>]+)> {/g, 'type $1<$2> = {') - .replace(/\binterface (\w+) extends (\w+) {/g, 'type $1 = {\n ...$2;') + .replace( + /\binterface (\w+) extends (\w+) {/g, + 'type $1 = {\n ...$Exact<$2>;' + ) .replace(/\bunknown\b/g, 'mixed') .replace(/\| undefined\b/g, '| void') .replace(/: undefined\b/g, ': void') diff --git a/src/core/login/login-stash.ts b/src/core/login/login-stash.ts index 9c50cb907..c32f837da 100644 --- a/src/core/login/login-stash.ts +++ b/src/core/login/login-stash.ts @@ -17,10 +17,11 @@ import { asBase32, asBase64, asEdgeBox, + asEdgeKeyBox, asEdgePendingVoucher, asEdgeSnrp } from '../../types/server-cleaners' -import { EdgeBox, EdgeSnrp } from '../../types/server-types' +import { EdgeBox, EdgeKeyBox, EdgeSnrp } from '../../types/server-types' import { EdgeLog, EdgePendingVoucher } from '../../types/types' import { verifyData } from '../../util/crypto/verify' import { base58 } from '../../util/encoding' @@ -66,7 +67,7 @@ export interface LoginStash { // Keys and assorted goodies: children?: LoginStash[] - keyBoxes?: EdgeBox[] + keyBoxes?: EdgeKeyBox[] mnemonicBox?: EdgeBox rootKeyBox?: EdgeBox syncKeyBox?: EdgeBox @@ -187,7 +188,7 @@ export const asLoginStash: Cleaner = asObject({ // Keys and assorted goodies: children: asOptional(asArray(raw => asLoginStash(raw))), - keyBoxes: asOptional(asArray(asEdgeBox)), + keyBoxes: asOptional(asArray(asEdgeKeyBox)), mnemonicBox: asOptional(asEdgeBox), rootKeyBox: asOptional(asEdgeBox), syncKeyBox: asOptional(asEdgeBox) diff --git a/src/types/fake-types.ts b/src/types/fake-types.ts index 7b4c29ed8..efba4024b 100644 --- a/src/types/fake-types.ts +++ b/src/types/fake-types.ts @@ -14,10 +14,11 @@ import { asBase32, asBase64, asEdgeBox, + asEdgeKeyBox, asEdgeSnrp, asRecovery2Auth } from './server-cleaners' -import type { EdgeBox, EdgeSnrp } from './server-types' +import type { EdgeBox, EdgeKeyBox, EdgeSnrp } from './server-types' export interface EdgeRepoDump { [key: string]: EdgeBox @@ -87,7 +88,7 @@ export interface EdgeLoginDump { // Resources: children: EdgeLoginDump[] - keyBoxes: EdgeBox[] + keyBoxes: EdgeKeyBox[] mnemonicBox?: EdgeBox rootKeyBox?: EdgeBox syncKeyBox?: EdgeBox @@ -168,7 +169,7 @@ export const asEdgeLoginDump: Cleaner = asObject({ userTextBox: asOptional(asEdgeBox), // Keys and assorted goodies: - keyBoxes: asOptional(asArray(asEdgeBox), () => []), + keyBoxes: asOptional(asArray(asEdgeKeyBox), () => []), mnemonicBox: asOptional(asEdgeBox), rootKeyBox: asOptional(asEdgeBox), syncKeyBox: asOptional(asEdgeBox), diff --git a/src/types/server-cleaners.ts b/src/types/server-cleaners.ts index bc8c64038..a04662153 100644 --- a/src/types/server-cleaners.ts +++ b/src/types/server-cleaners.ts @@ -30,6 +30,7 @@ import type { CreateKeysPayload, CreateLoginPayload, EdgeBox, + EdgeKeyBox, EdgeLobbyReply, EdgeLobbyRequest, EdgeSnrp, @@ -93,6 +94,13 @@ export const asEdgeBox: Cleaner = asObject({ iv_hex: asBase16 }) +export const asEdgeKeyBox: Cleaner = asObject({ + created: asDate, + data_base64: asBase64, + encryptionType: asNumber, + iv_hex: asBase16 +}) + export const asEdgeSnrp: Cleaner = asObject({ salt_hex: asBase16, n: asNumber, @@ -314,7 +322,7 @@ export const asLoginPayload: Cleaner = asObject({ pendingVouchers: asOptional(asArray(asEdgePendingVoucher), () => []), // Resources: - keyBoxes: asOptional(asArray(asEdgeBox)), + keyBoxes: asOptional(asArray(asEdgeKeyBox)), mnemonicBox: asOptional(asEdgeBox), rootKeyBox: asOptional(asEdgeBox), syncKeyBox: asOptional(asEdgeBox) diff --git a/src/types/server-types.ts b/src/types/server-types.ts index c2b2bf78a..3b4977d23 100644 --- a/src/types/server-types.ts +++ b/src/types/server-types.ts @@ -13,6 +13,13 @@ export interface EdgeBox { iv_hex: Uint8Array } +/** + * Encrypted wallet private keys include an optional creation date. + */ +export interface EdgeKeyBox extends EdgeBox { + created: Date +} + /** * Edge-format scrypt parameters. */ @@ -256,7 +263,7 @@ export interface LoginPayload { pendingVouchers: EdgePendingVoucher[] // Resources: - keyBoxes?: EdgeBox[] + keyBoxes?: EdgeKeyBox[] mnemonicBox?: EdgeBox rootKeyBox?: EdgeBox syncKeyBox?: EdgeBox