Skip to content

Commit

Permalink
Add types for server-returned key creation dates
Browse files Browse the repository at this point in the history
  • Loading branch information
swansontec committed Sep 6, 2024
1 parent 57b50d6 commit c242568
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
5 changes: 4 additions & 1 deletion scripts/make-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ async function tsToFlow(code: string): Promise<string> {
.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')
Expand Down
7 changes: 4 additions & 3 deletions src/core/login/login-stash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -66,7 +67,7 @@ export interface LoginStash {

// Keys and assorted goodies:
children?: LoginStash[]
keyBoxes?: EdgeBox[]
keyBoxes?: EdgeKeyBox[]
mnemonicBox?: EdgeBox
rootKeyBox?: EdgeBox
syncKeyBox?: EdgeBox
Expand Down Expand Up @@ -187,7 +188,7 @@ export const asLoginStash: Cleaner<LoginStash> = 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)
Expand Down
7 changes: 4 additions & 3 deletions src/types/fake-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -87,7 +88,7 @@ export interface EdgeLoginDump {

// Resources:
children: EdgeLoginDump[]
keyBoxes: EdgeBox[]
keyBoxes: EdgeKeyBox[]
mnemonicBox?: EdgeBox
rootKeyBox?: EdgeBox
syncKeyBox?: EdgeBox
Expand Down Expand Up @@ -168,7 +169,7 @@ export const asEdgeLoginDump: Cleaner<EdgeLoginDump> = 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),
Expand Down
10 changes: 9 additions & 1 deletion src/types/server-cleaners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import type {
CreateKeysPayload,
CreateLoginPayload,
EdgeBox,
EdgeKeyBox,
EdgeLobbyReply,
EdgeLobbyRequest,
EdgeSnrp,
Expand Down Expand Up @@ -93,6 +94,13 @@ export const asEdgeBox: Cleaner<EdgeBox> = asObject({
iv_hex: asBase16
})

export const asEdgeKeyBox: Cleaner<EdgeKeyBox> = asObject({
created: asDate,
data_base64: asBase64,
encryptionType: asNumber,
iv_hex: asBase16
})

export const asEdgeSnrp: Cleaner<EdgeSnrp> = asObject({
salt_hex: asBase16,
n: asNumber,
Expand Down Expand Up @@ -314,7 +322,7 @@ export const asLoginPayload: Cleaner<LoginPayload> = asObject({
pendingVouchers: asOptional(asArray(asEdgePendingVoucher), () => []),

// Resources:
keyBoxes: asOptional(asArray(asEdgeBox)),
keyBoxes: asOptional(asArray(asEdgeKeyBox)),
mnemonicBox: asOptional(asEdgeBox),
rootKeyBox: asOptional(asEdgeBox),
syncKeyBox: asOptional(asEdgeBox)
Expand Down
9 changes: 8 additions & 1 deletion src/types/server-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -256,7 +263,7 @@ export interface LoginPayload {
pendingVouchers: EdgePendingVoucher[]

// Resources:
keyBoxes?: EdgeBox[]
keyBoxes?: EdgeKeyBox[]
mnemonicBox?: EdgeBox
rootKeyBox?: EdgeBox
syncKeyBox?: EdgeBox
Expand Down

0 comments on commit c242568

Please sign in to comment.