edge-core-js
Advanced tools
Comparing version 1.7.0 to 1.8.0
# edge-core-js | ||
## Unreleased | ||
## 1.8.0 (2023-10-02) | ||
- added: Export cleaners for server types and testing data types. | ||
- deprecated: `EdgeContext.listRecoveryQuestionChoices`. The GUI provides its own localized strings now. | ||
## v1.7.0 (2023-09-12) | ||
@@ -4,0 +11,0 @@ |
@@ -215,6 +215,2 @@ function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }import { bridgifyObject, onMethod, watchMethod } from 'yaob' | ||
async listRecoveryQuestionChoices() { | ||
return await listRecoveryQuestionChoices(ai) | ||
}, | ||
async requestEdgeLogin( | ||
@@ -275,2 +271,7 @@ opts | ||
ai.props.dispatch({ type: 'CHANGE_LOG_SETTINGS', payload: newSettings }) | ||
}, | ||
/** @deprecated The GUI provides its own localized strings now. */ | ||
async listRecoveryQuestionChoices() { | ||
return await listRecoveryQuestionChoices(ai) | ||
} | ||
@@ -277,0 +278,0 @@ } |
@@ -8,3 +8,2 @@ | ||
import { verifyData } from '../../util/crypto/verify' | ||
@@ -26,9 +25,2 @@ | ||
/** | ||
@@ -83,17 +75,13 @@ * Emulates the Airbitz login server database. | ||
setupFakeUser(user) { | ||
const setupLogin = (dump) => { | ||
const { children, ...rest } = dump | ||
this.insertLogin(rest) | ||
for (const child of children) { | ||
child.parentId = dump.loginId | ||
setupLogin(child) | ||
} | ||
setupLogin(dump) { | ||
const { children, ...rest } = dump | ||
this.insertLogin(rest) | ||
for (const child of children) { | ||
child.parentId = dump.loginId | ||
this.setupLogin(child) | ||
} | ||
setupLogin(user.server) | ||
} | ||
// Create fake repos: | ||
for (const syncKey of Object.keys(user.repos)) { | ||
this.repos[syncKey] = { ...user.repos[syncKey] } | ||
} | ||
setupRepo(syncKey, repo) { | ||
this.repos[syncKey] = repo | ||
} | ||
@@ -100,0 +88,0 @@ |
@@ -1,2 +0,2 @@ | ||
function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }import { uncleaner } from 'cleaners' | ||
function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } | ||
@@ -6,9 +6,8 @@ | ||
import { | ||
asOtpErrorPayload, | ||
asPasswordErrorPayload | ||
wasLoginResponseBody, | ||
wasOtpErrorPayload, | ||
wasPasswordErrorPayload | ||
} from '../../types/server-cleaners' | ||
const wasOtpErrorPayload = uncleaner(asOtpErrorPayload) | ||
const wasPasswordErrorPayload = uncleaner(asPasswordErrorPayload) | ||
@@ -20,3 +19,2 @@ | ||
export const statusCodes = { | ||
@@ -109,2 +107,20 @@ success: { | ||
export function cleanRequest( | ||
cleaner, | ||
raw | ||
) { | ||
try { | ||
const clean = cleaner(raw) | ||
return [clean, { status: 200 }] | ||
} catch (error) { | ||
return [ | ||
undefined, | ||
statusResponse( | ||
statusCodes.invalidRequest, | ||
`Invalid request: ${String(error)}` | ||
) | ||
] | ||
} | ||
} | ||
/** | ||
@@ -118,7 +134,7 @@ * Construct an HttpResponse object with a JSON body. | ||
const { status = 200, headers = {} } = opts | ||
return Promise.resolve({ | ||
return { | ||
status, | ||
headers: { 'content-type': 'application/json', ...headers }, | ||
body: JSON.stringify(body) | ||
}) | ||
} | ||
} | ||
@@ -134,3 +150,6 @@ | ||
const { code, httpStatus } = statusCode | ||
const body = { status_code: code, message } | ||
const body = wasLoginResponseBody({ | ||
status_code: code, | ||
message | ||
}) | ||
return jsonResponse(body, { status: httpStatus }) | ||
@@ -148,3 +167,7 @@ } | ||
const { code, httpStatus } = statusCode | ||
const body = { status_code: code, message, results: payload } | ||
const body = wasLoginResponseBody({ | ||
status_code: code, | ||
message, | ||
results: payload | ||
}) | ||
return jsonResponse(body, { status: httpStatus }) | ||
@@ -151,0 +174,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { asMaybe, asObject, uncleaner } from 'cleaners' | ||
import { asMaybe, asObject } from 'cleaners' | ||
import { | ||
@@ -11,3 +11,7 @@ | ||
import { | ||
wasEdgeRepoDump | ||
} from '../../types/fake-types' | ||
import { | ||
@@ -28,9 +32,9 @@ asChangeOtpPayload, | ||
asEdgeLobbyRequest, | ||
asLobbyPayload, | ||
asLoginPayload, | ||
asLoginRequestBody, | ||
asMessagesPayload, | ||
asOtpResetPayload, | ||
asRecovery2InfoPayload, | ||
asUsernameInfoPayload | ||
wasLobbyPayload, | ||
wasLoginPayload, | ||
wasMessagesPayload, | ||
wasOtpResetPayload, | ||
wasRecovery2InfoPayload, | ||
wasUsernameInfoPayload | ||
} from '../../types/server-cleaners' | ||
@@ -47,3 +51,2 @@ | ||
makeLoginPayload, | ||
@@ -53,2 +56,3 @@ makePendingVouchers | ||
import { | ||
cleanRequest, | ||
jsonResponse, | ||
@@ -62,8 +66,2 @@ otpErrorResponse, | ||
const wasLobbyPayload = uncleaner(asLobbyPayload) | ||
const wasLoginPayload = uncleaner(asLoginPayload) | ||
const wasMessagesPayload = uncleaner(asMessagesPayload) | ||
const wasOtpResetPayload = uncleaner(asOtpResetPayload) | ||
const wasRecovery2InfoPayload = uncleaner(asRecovery2InfoPayload) | ||
const wasUsernameInfoPayload = uncleaner(asUsernameInfoPayload) | ||
@@ -87,3 +85,2 @@ | ||
// Authentication middleware: ---------------------------------------------- | ||
@@ -95,4 +92,4 @@ | ||
const { json } = request | ||
const body = asMaybe(asLoginRequestBody)(json) | ||
if (body == null) return await statusResponse(statusCodes.invalidRequest) | ||
const [body, bodyError] = cleanRequest(asLoginRequestBody, json) | ||
if (body == null) return bodyError | ||
return await server({ ...request, body, payload: body.data }) | ||
@@ -250,4 +247,6 @@ } | ||
} | ||
const { passwordAuthSnrp = userIdSnrp } = login | ||
return payloadResponse(wasUsernameInfoPayload({ passwordAuthSnrp })) | ||
const { loginId, passwordAuthSnrp = userIdSnrp } = login | ||
return payloadResponse( | ||
wasUsernameInfoPayload({ loginId, passwordAuthSnrp }) | ||
) | ||
} | ||
@@ -269,16 +268,12 @@ if (recovery2Id != null && recovery2Auth == null) { | ||
function createLogin( | ||
request, | ||
login | ||
) { | ||
function createLogin(request, login) { | ||
const { db, json } = request | ||
const date = new Date() | ||
const body = asMaybe(asLoginRequestBody)(json) | ||
if (body == null) return statusResponse(statusCodes.invalidRequest) | ||
const clean = asMaybe(asCreateLoginPayload)(body.data) | ||
const secret = asMaybe(asChangeSecretPayload)(clean) | ||
if (clean == null || secret == null) { | ||
return statusResponse(statusCodes.invalidRequest) | ||
} | ||
const [body, bodyError] = cleanRequest(asLoginRequestBody, json) | ||
if (body == null) return bodyError | ||
const [clean, cleanError] = cleanRequest(asCreateLoginPayload, body.data) | ||
if (clean == null) return cleanError | ||
const [secret, secretError] = cleanRequest(asChangeSecretPayload, body.data) | ||
if (secret == null) return secretError | ||
@@ -291,4 +286,6 @@ // Do not re-create accounts: | ||
// Set up repos: | ||
const emptyKeys = { newSyncKeys: [], keyBoxes: [] } | ||
const keys = asMaybe(asCreateKeysPayload, emptyKeys)(clean) | ||
const keys = asMaybe(asCreateKeysPayload, () => ({ | ||
newSyncKeys: [], | ||
keyBoxes: [] | ||
}))(body.data) | ||
for (const syncKey of keys.newSyncKeys) { | ||
@@ -308,7 +305,7 @@ db.repos[syncKey] = {} | ||
// Optional fields: | ||
...asMaybe(asChangeOtpPayload)(clean), | ||
...asMaybe(asChangePasswordPayload)(clean), | ||
...asMaybe(asChangePin2Payload)(clean), | ||
...asMaybe(asChangeRecovery2Payload)(clean), | ||
...asMaybe(asChangeUsernamePayload)(clean) | ||
...asMaybe(asChangeOtpPayload)(body.data), | ||
...asMaybe(asChangePasswordPayload)(body.data), | ||
...asMaybe(asChangePin2Payload)(body.data), | ||
...asMaybe(asChangeRecovery2Payload)(body.data), | ||
...asMaybe(asChangeUsernamePayload)(body.data) | ||
} | ||
@@ -338,4 +335,4 @@ | ||
const { db, login, payload } = request | ||
const clean = asMaybe(asCreateKeysPayload)(payload) | ||
if (clean == null) return statusResponse(statusCodes.invalidRequest) | ||
const [clean, cleanError] = cleanRequest(asCreateKeysPayload, payload) | ||
if (clean == null) return cleanError | ||
@@ -353,4 +350,4 @@ // Set up repos: | ||
const { login, payload } = request | ||
const clean = asMaybe(asChangeOtpPayload)(payload) | ||
if (clean == null) return statusResponse(statusCodes.invalidRequest) | ||
const [clean, cleanError] = cleanRequest(asChangeOtpPayload, payload) | ||
if (clean == null) return cleanError | ||
@@ -418,4 +415,4 @@ login.otpKey = clean.otpKey | ||
const { login, payload } = request | ||
const clean = asMaybe(asChangePasswordPayload)(payload) | ||
if (clean == null) return statusResponse(statusCodes.invalidRequest) | ||
const [clean, cleanError] = cleanRequest(asChangePasswordPayload, payload) | ||
if (clean == null) return cleanError | ||
@@ -444,4 +441,4 @@ login.passwordAuth = clean.passwordAuth | ||
const { login, payload } = request | ||
const clean = asMaybe(asChangePin2Payload)(payload) | ||
if (clean == null) return statusResponse(statusCodes.invalidRequest) | ||
const [clean, cleanError] = cleanRequest(asChangePin2Payload, payload) | ||
if (clean == null) return cleanError | ||
@@ -470,4 +467,4 @@ login.pin2Auth = clean.pin2Auth | ||
const { login, payload } = request | ||
const clean = asMaybe(asChangeRecovery2Payload)(payload) | ||
if (clean == null) return statusResponse(statusCodes.invalidRequest) | ||
const [clean, cleanError] = cleanRequest(asChangeRecovery2Payload, payload) | ||
if (clean == null) return cleanError | ||
@@ -485,4 +482,4 @@ login.question2Box = clean.question2Box | ||
const { db, login, payload } = request | ||
const clean = asMaybe(asChangeSecretPayload)(payload) | ||
if (clean == null) return statusResponse(statusCodes.invalidRequest) | ||
const [clean, cleanError] = cleanRequest(asChangeSecretPayload, payload) | ||
if (clean == null) return cleanError | ||
@@ -513,3 +510,3 @@ // Do a quick sanity check: | ||
if (login.passwordAuth != null && cleanPassword == null) { | ||
return await statusResponse( | ||
return statusResponse( | ||
statusCodes.invalidRequest, | ||
@@ -520,9 +517,6 @@ 'Missing password payload' | ||
if (login.pin2Auth != null && cleanPin2 == null) { | ||
return await statusResponse( | ||
statusCodes.invalidRequest, | ||
'Missing pin2Id payload' | ||
) | ||
return statusResponse(statusCodes.invalidRequest, 'Missing pin2Id payload') | ||
} | ||
if (login.recovery2Auth != null && cleanRecovery2 == null) { | ||
return await statusResponse( | ||
return statusResponse( | ||
statusCodes.invalidRequest, | ||
@@ -533,3 +527,3 @@ 'Missing recovery2Id payload' | ||
if (login.parentBox == null && cleanUsername == null) { | ||
return await statusResponse( | ||
return statusResponse( | ||
statusCodes.invalidRequest, | ||
@@ -552,10 +546,7 @@ 'Missing username payload' | ||
if (login.pin2Auth == null) { | ||
return await statusResponse( | ||
statusCodes.invalidRequest, | ||
'Login lacks pin2' | ||
) | ||
return statusResponse(statusCodes.invalidRequest, 'Login lacks pin2') | ||
} | ||
const existing = await db.getLoginByPin2Id(cleanPin2.pin2Id) | ||
const existing = db.getLoginByPin2Id(cleanPin2.pin2Id) | ||
if (existing != null) { | ||
return await statusResponse(statusCodes.conflict) | ||
return statusResponse(statusCodes.conflict) | ||
} | ||
@@ -568,10 +559,7 @@ login.pin2Id = cleanPin2.pin2Id | ||
if (login.recovery2Auth == null) { | ||
return await statusResponse( | ||
statusCodes.invalidRequest, | ||
'Login lacks recovery2' | ||
) | ||
return statusResponse(statusCodes.invalidRequest, 'Login lacks recovery2') | ||
} | ||
const existing = await db.getLoginByRecovery2Id(cleanRecovery2.recovery2Id) | ||
const existing = db.getLoginByRecovery2Id(cleanRecovery2.recovery2Id) | ||
if (existing != null) { | ||
return await statusResponse(statusCodes.conflict) | ||
return statusResponse(statusCodes.conflict) | ||
} | ||
@@ -584,3 +572,3 @@ login.recovery2Id = cleanRecovery2.recovery2Id | ||
if (login.parentBox != null) { | ||
return await statusResponse( | ||
return statusResponse( | ||
statusCodes.invalidRequest, | ||
@@ -590,5 +578,5 @@ 'Only top-level logins can have usernames' | ||
} | ||
const existing = await db.getLoginByUserId(cleanUsername.userId) | ||
const existing = db.getLoginByUserId(cleanUsername.userId) | ||
if (existing != null) { | ||
return await statusResponse(statusCodes.conflict) | ||
return statusResponse(statusCodes.conflict) | ||
} | ||
@@ -599,3 +587,3 @@ login.userId = cleanUsername.userId | ||
return await payloadResponse(wasLoginPayload(makeLoginPayload(db, login))) | ||
return payloadResponse(wasLoginPayload(makeLoginPayload(db, login))) | ||
}) | ||
@@ -605,4 +593,4 @@ | ||
const { db, login, payload } = request | ||
const clean = asMaybe(asChangeVouchersPayload)(payload) | ||
if (clean == null) return await statusResponse(statusCodes.invalidRequest) | ||
const [clean, cleanError] = cleanRequest(asChangeVouchersPayload, payload) | ||
if (clean == null) return cleanError | ||
const { approvedVouchers = [], rejectedVouchers = [] } = clean | ||
@@ -621,5 +609,3 @@ | ||
return await payloadResponse( | ||
wasLoginPayload(await makeLoginPayload(db, login)) | ||
) | ||
return payloadResponse(wasLoginPayload(makeLoginPayload(db, login))) | ||
}) | ||
@@ -655,6 +641,6 @@ | ||
const body = asMaybe(asLoginRequestBody)(json) | ||
if (body == null) return statusResponse(statusCodes.invalidRequest) | ||
const clean = asMaybe(asEdgeLobbyRequest)(body.data) | ||
if (clean == null) return statusResponse(statusCodes.invalidRequest) | ||
const [body, bodyError] = cleanRequest(asLoginRequestBody, json) | ||
if (body == null) return bodyError | ||
const [clean, cleanError] = cleanRequest(asEdgeLobbyRequest, body.data) | ||
if (clean == null) return cleanError | ||
@@ -672,6 +658,6 @@ const { timeout = 600 } = clean | ||
const body = asMaybe(asLoginRequestBody)(json) | ||
if (body == null) return statusResponse(statusCodes.invalidRequest) | ||
const clean = asMaybe(asEdgeLobbyReply)(body.data) | ||
if (clean == null) return statusResponse(statusCodes.invalidRequest) | ||
const [body, bodyError] = cleanRequest(asLoginRequestBody, json) | ||
if (body == null) return bodyError | ||
const [clean, cleanError] = cleanRequest(asEdgeLobbyReply, body.data) | ||
if (clean == null) return cleanError | ||
@@ -697,7 +683,7 @@ lobby.replies.push(clean) | ||
const { db, json } = request | ||
const clean = asMaybe(asLoginRequestBody)(json) | ||
if (clean == null || clean.loginIds == null) { | ||
return statusResponse(statusCodes.invalidRequest) | ||
} | ||
const [clean, cleanError] = cleanRequest(asLoginRequestBody, json) | ||
if (clean == null) return cleanError | ||
const { loginIds } = clean | ||
if (loginIds == null) return statusResponse(statusCodes.invalidRequest) | ||
@@ -740,3 +726,3 @@ const out = [] | ||
const { repo } = request | ||
return jsonResponse({ changes: repo }) | ||
return jsonResponse({ changes: wasEdgeRepoDump(repo) }) | ||
}) | ||
@@ -751,3 +737,3 @@ | ||
return jsonResponse({ | ||
changes: repo, | ||
changes: wasEdgeRepoDump(repo), | ||
hash: '1111111111111111111111111111111111111111' | ||
@@ -754,0 +740,0 @@ }) |
@@ -1,2 +0,1 @@ | ||
import { uncleaner } from 'cleaners' | ||
import { makeMemoryDisklet } from 'disklet' | ||
@@ -7,7 +6,9 @@ import { base16, base64 } from 'rfc4648' | ||
import { fixUsername } from '../../client-side' | ||
import { | ||
asFakeUser, | ||
asFakeUsers, | ||
asLoginDump, | ||
asEdgeLoginDump, | ||
asEdgeRepoDump, | ||
wasEdgeLoginDump, | ||
wasEdgeRepoDump | ||
} from '../../types/fake-types' | ||
@@ -28,3 +29,3 @@ import { asLoginPayload } from '../../types/server-cleaners' | ||
import { applyLoginPayload } from '../login/login' | ||
import { asLoginStash } from '../login/login-stash' | ||
import { wasLoginStash } from '../login/login-stash' | ||
@@ -36,9 +37,9 @@ import { makeContext } from '../root' | ||
const wasLoginStash = uncleaner(asLoginStash) | ||
const wasLoginDump = uncleaner(asLoginDump) | ||
const wasFakeUser = uncleaner(asFakeUser) | ||
async function saveLogin(io, user) { | ||
const { lastLogin, server } = user | ||
const loginId = base64.parse(user.loginId) | ||
const loginKey = base64.parse(user.loginKey) | ||
const username = | ||
user.username == null ? undefined : fixUsername(user.username) | ||
async function saveUser(io, user) { | ||
const { lastLogin, loginId, loginKey, repos, server, username } = user | ||
// Save the stash: | ||
@@ -54,3 +55,5 @@ const stash = applyLoginPayload( | ||
loginKey, | ||
asLoginPayload(wasLoginDump(server)) | ||
// The correct cleaner is `asEdgeLoginDump`, | ||
// but the format is close enough that the other cleaner kinda fits: | ||
asLoginPayload(server) | ||
) | ||
@@ -61,13 +64,14 @@ const path = `logins/${base58.stringify(loginId)}.json` | ||
.catch(() => {}) | ||
} | ||
// Save the repos: | ||
await Promise.all( | ||
Object.keys(repos).map(async syncKey => { | ||
const paths = makeRepoPaths(io, base16.parse(syncKey), new Uint8Array(0)) | ||
await saveChanges(paths.dataDisklet, user.repos[syncKey]) | ||
await paths.baseDisklet.setText( | ||
'status.json', | ||
JSON.stringify({ lastSync: 1, lastHash: null }) | ||
) | ||
}) | ||
async function saveRepo( | ||
io, | ||
syncKey, | ||
repo | ||
) { | ||
const paths = makeRepoPaths(io, base16.parse(syncKey), new Uint8Array(0)) | ||
await saveChanges(paths.dataDisklet, repo) | ||
await paths.baseDisklet.setText( | ||
'status.json', | ||
JSON.stringify({ lastSync: 1, lastHash: null }) | ||
) | ||
@@ -89,4 +93,8 @@ } | ||
// Populate the fake database: | ||
const cleanUsers = asFakeUsers(users) | ||
for (const user of cleanUsers) fakeDb.setupFakeUser(user) | ||
for (const user of users) { | ||
fakeDb.setupLogin(asEdgeLoginDump(user.server)) | ||
for (const syncKey of Object.keys(user.repos)) { | ||
fakeDb.setupRepo(syncKey, asEdgeRepoDump(user.repos[syncKey])) | ||
} | ||
} | ||
@@ -124,5 +132,8 @@ const contexts = [] | ||
if (!cleanDevice) { | ||
await Promise.all( | ||
cleanUsers.map(async user => await saveUser(fakeIo, user)) | ||
) | ||
for (const user of users) { | ||
await saveLogin(fakeIo, user) | ||
for (const syncKey of Object.keys(user.repos)) { | ||
await saveRepo(fakeIo, syncKey, asEdgeRepoDump(user.repos[syncKey])) | ||
} | ||
} | ||
} | ||
@@ -162,12 +173,14 @@ | ||
const repos = {} | ||
for (const syncKey of syncKeys) repos[syncKey] = fakeDb.repos[syncKey] | ||
for (const syncKey of syncKeys) { | ||
repos[syncKey] = wasEdgeRepoDump(fakeDb.repos[syncKey]) | ||
} | ||
return wasFakeUser({ | ||
return { | ||
lastLogin: account.lastLogin, | ||
loginId, | ||
loginKey, | ||
loginId: base64.stringify(loginId), | ||
loginKey: base64.stringify(loginKey), | ||
repos, | ||
server: fakeDb.dumpLogin(login), | ||
server: wasEdgeLoginDump(fakeDb.dumpLogin(login)), | ||
username: account.username | ||
}) | ||
} | ||
} | ||
@@ -174,0 +187,0 @@ } |
@@ -1,5 +0,3 @@ | ||
function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }import { uncleaner } from 'cleaners' | ||
function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }import { wasCreateLoginPayload } from '../../types/server-cleaners' | ||
import { asCreateLoginPayload } from '../../types/server-cleaners' | ||
import { | ||
@@ -22,3 +20,2 @@ asMaybeUsernameError, | ||
const wasCreateLoginPayload = uncleaner(asCreateLoginPayload) | ||
@@ -31,3 +28,2 @@ | ||
/** | ||
@@ -34,0 +30,0 @@ * Determines whether or not a username is available. |
import { base16, base64 } from 'rfc4648' | ||
import { wasCreateKeysPayload } from '../../types/server-cleaners' | ||
@@ -24,4 +25,4 @@ | ||
import { wasEdgeWalletInfo } from './login-types' | ||
/** | ||
@@ -86,3 +87,7 @@ * Returns the first keyInfo with a matching type. | ||
const keyBoxes = keyInfos.map(info => | ||
encrypt(io, utf8.parse(JSON.stringify(info)), login.loginKey) | ||
encrypt( | ||
io, | ||
utf8.parse(JSON.stringify(wasEdgeWalletInfo(info))), | ||
login.loginKey | ||
) | ||
) | ||
@@ -99,3 +104,3 @@ const newSyncKeys = [] | ||
serverPath: '/v2/login/keys', | ||
server: { keyBoxes, newSyncKeys }, | ||
server: wasCreateKeysPayload({ keyBoxes, newSyncKeys }), | ||
stash: { keyBoxes }, | ||
@@ -102,0 +107,0 @@ login: { keyInfos }, |
@@ -1,2 +0,1 @@ | ||
import { uncleaner } from 'cleaners' | ||
import elliptic from 'elliptic' | ||
@@ -6,5 +5,5 @@ import { makeEvents, } from 'yavent' | ||
import { | ||
asEdgeLobbyReply, | ||
asEdgeLobbyRequest, | ||
asLobbyPayload | ||
asLobbyPayload, | ||
wasEdgeLobbyReply, | ||
wasEdgeLobbyRequest | ||
} from '../../types/server-cleaners' | ||
@@ -24,4 +23,2 @@ | ||
const wasEdgeLobbyReply = uncleaner(asEdgeLobbyReply) | ||
const wasEdgeLobbyRequest = uncleaner(asEdgeLobbyRequest) | ||
@@ -43,3 +40,2 @@ | ||
/** | ||
@@ -46,0 +42,0 @@ * Derives a shared secret from the given secret key and public key. |
@@ -1,7 +0,7 @@ | ||
import { asMaybe, uncleaner } from 'cleaners' | ||
import { asMaybe } from 'cleaners' | ||
import { | ||
asChallengeErrorPayload, | ||
asLoginRequestBody, | ||
asLoginResponseBody | ||
asLoginResponseBody, | ||
wasLoginRequestBody | ||
} from '../../types/server-cleaners' | ||
@@ -21,4 +21,2 @@ | ||
const wasLoginRequestBody = uncleaner(asLoginRequestBody) | ||
export function parseReply(json) { | ||
@@ -25,0 +23,0 @@ const clean = asLoginResponseBody(json) |
@@ -1,4 +0,2 @@ | ||
import { uncleaner } from 'cleaners' | ||
import { asChangeSecretPayload } from '../../types/server-cleaners' | ||
import { wasChangeSecretPayload } from '../../types/server-cleaners' | ||
import { encrypt } from '../../util/crypto/crypto' | ||
@@ -8,4 +6,2 @@ | ||
const wasChangeSecretPayload = uncleaner(asChangeSecretPayload) | ||
export function makeSecretKit( | ||
@@ -12,0 +8,0 @@ ai, |
@@ -140,3 +140,3 @@ import { | ||
export const asUsername = raw => fixUsername(asString(raw)) | ||
const asUsername = raw => fixUsername(asString(raw)) | ||
@@ -195,2 +195,3 @@ export const asLoginStash = asObject({ | ||
}) | ||
const wasLoginStash = uncleaner(asLoginStash) | ||
export const wasLoginStash = uncleaner(asLoginStash) |
@@ -0,1 +1,2 @@ | ||
import { asObject, asString, uncleaner } from 'cleaners' | ||
@@ -8,2 +9,4 @@ | ||
// Login data decrypted into memory. | ||
@@ -75,1 +78,9 @@ | ||
export const asEdgeWalletInfo = asObject({ | ||
id: asString, | ||
keys: (raw) => raw, | ||
type: asString | ||
}) | ||
export const wasEdgeWalletInfo = uncleaner(asEdgeWalletInfo) |
@@ -1,5 +0,3 @@ | ||
function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }import { uncleaner } from 'cleaners' | ||
import { asChangeUsernamePayload } from '../../types/server-cleaners' | ||
function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } | ||
import { wasChangeUsernamePayload } from '../../types/server-cleaners' | ||
import { encrypt } from '../../util/crypto/crypto' | ||
@@ -15,4 +13,2 @@ import { utf8 } from '../../util/encoding' | ||
const wasChangeUsernamePayload = uncleaner(asChangeUsernamePayload) | ||
export async function changeUsername( | ||
@@ -19,0 +15,0 @@ ai, |
@@ -30,3 +30,3 @@ function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }/** | ||
import { saveStash } from './login-stash' | ||
import { asEdgeWalletInfo, } from './login-types' | ||
import { getLoginOtp, getStashOtp } from './otp' | ||
@@ -281,3 +281,5 @@ | ||
// Keys: | ||
const keyInfos = keyBoxes.map(box => JSON.parse(decryptText(box, loginKey))) | ||
const keyInfos = keyBoxes.map(box => | ||
asEdgeWalletInfo(JSON.parse(decryptText(box, loginKey))) | ||
) | ||
login.keyInfos = mergeKeyInfos([...legacyKeys, ...keyInfos]).map(walletInfo => | ||
@@ -284,0 +286,0 @@ fixWalletInfo(walletInfo) |
@@ -1,7 +0,6 @@ | ||
import { uncleaner } from 'cleaners' | ||
import { base32 } from 'rfc4648' | ||
import { | ||
asChangeOtpPayload, | ||
asOtpResetPayload | ||
asOtpResetPayload, | ||
wasChangeOtpPayload | ||
} from '../../types/server-cleaners' | ||
@@ -17,4 +16,2 @@ | ||
const wasChangeOtpPayload = uncleaner(asChangeOtpPayload) | ||
/** | ||
@@ -21,0 +18,0 @@ * Gets the current OTP for a logged-in account. |
@@ -1,5 +0,3 @@ | ||
import { uncleaner } from 'cleaners' | ||
import { wasChangePasswordPayload } from '../../types/server-cleaners' | ||
import { asChangePasswordPayload } from '../../types/server-cleaners' | ||
import { decrypt, encrypt } from '../../util/crypto/crypto' | ||
@@ -13,3 +11,2 @@ | ||
const wasChangePasswordPayload = uncleaner(asChangePasswordPayload) | ||
const passwordAuthSnrp = userIdSnrp | ||
@@ -16,0 +13,0 @@ |
@@ -1,6 +0,4 @@ | ||
function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }import { uncleaner } from 'cleaners' | ||
import { | ||
asChangePin2IdPayload, | ||
asChangePin2Payload | ||
function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }import { | ||
wasChangePin2IdPayload, | ||
wasChangePin2Payload | ||
} from '../../types/server-cleaners' | ||
@@ -20,5 +18,2 @@ | ||
const wasChangePin2IdPayload = uncleaner(asChangePin2IdPayload) | ||
const wasChangePin2Payload = uncleaner(asChangePin2Payload) | ||
function makePin2Id( | ||
@@ -25,0 +20,0 @@ pin2Key, |
@@ -1,8 +0,8 @@ | ||
import { uncleaner } from 'cleaners' | ||
import { asArray, asString, uncleaner } from 'cleaners' | ||
import { | ||
asChangeRecovery2IdPayload, | ||
asChangeRecovery2Payload, | ||
asQuestionChoicesPayload, | ||
asRecovery2InfoPayload | ||
asRecovery2InfoPayload, | ||
wasChangeRecovery2IdPayload, | ||
wasChangeRecovery2Payload | ||
} from '../../types/server-cleaners' | ||
@@ -22,5 +22,2 @@ | ||
const wasChangeRecovery2IdPayload = uncleaner(asChangeRecovery2IdPayload) | ||
const wasChangeRecovery2Payload = uncleaner(asChangeRecovery2Payload) | ||
function makeRecovery2Id( | ||
@@ -98,3 +95,3 @@ recovery2Key, | ||
// Decrypt the questions: | ||
return JSON.parse(decryptText(question2Box, recovery2Key)) | ||
return asQuestions(JSON.parse(decryptText(question2Box, recovery2Key))) | ||
} | ||
@@ -180,3 +177,3 @@ | ||
io, | ||
utf8.parse(JSON.stringify(questions)), | ||
utf8.parse(JSON.stringify(wasQuestions(questions))), | ||
recovery2Key | ||
@@ -213,1 +210,4 @@ ) | ||
} | ||
const asQuestions = asArray(asString) | ||
const wasQuestions = uncleaner(asQuestions) |
@@ -1,6 +0,4 @@ | ||
import { uncleaner } from 'cleaners' | ||
import { | ||
asChangeVouchersPayload, | ||
asLoginPayload | ||
asLoginPayload, | ||
wasChangeVouchersPayload | ||
} from '../../types/server-cleaners' | ||
@@ -15,4 +13,2 @@ | ||
const wasChangeVouchersPayload = uncleaner(asChangeVouchersPayload) | ||
/** | ||
@@ -19,0 +15,0 @@ * Approves or rejects vouchers on the server. |
import { bridgifyObject } from 'yaob' | ||
import { asEdgeBox } from '../../types/server-cleaners' | ||
import { asEdgeBox, wasEdgeBox } from '../../types/server-cleaners' | ||
@@ -38,3 +38,3 @@ import { decrypt, decryptText, encrypt } from '../../util/crypto/crypto' | ||
path, | ||
JSON.stringify(encrypt(io, Uint8Array.from(data), dataKey)) | ||
JSON.stringify(wasEdgeBox(encrypt(io, Uint8Array.from(data), dataKey))) | ||
) | ||
@@ -41,0 +41,0 @@ }, |
@@ -1,6 +0,9 @@ | ||
import { mergeDisklets, navigateDisklet } from 'disklet' | ||
function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }import { mergeDisklets, navigateDisklet } from 'disklet' | ||
import { base16, base64 } from 'rfc4648' | ||
import { asEdgeBox, wasEdgeBox } from '../../types/server-cleaners' | ||
import { sha256 } from '../../util/crypto/hashes' | ||
@@ -18,2 +21,6 @@ import { base58 } from '../../util/encoding' | ||
export function makeLocalDisklet(io, walletId) { | ||
@@ -79,5 +86,5 @@ return navigateDisklet( | ||
Object.keys(changes).map(path => { | ||
const json = changes[path] | ||
return json != null | ||
? disklet.setText(path, JSON.stringify(json)) | ||
const box = changes[path] | ||
return box != null | ||
? disklet.setText(path, JSON.stringify(wasEdgeBox(box))) | ||
: disklet.delete(path) | ||
@@ -105,3 +112,3 @@ }) | ||
path, | ||
json: JSON.parse(await changesDisklet.getText(path)) | ||
box: asEdgeBox(JSON.parse(await changesDisklet.getText(path))) | ||
})) | ||
@@ -124,3 +131,3 @@ ) | ||
for (const change of ourChanges) { | ||
changes[change.path] = change.json | ||
changes[change.path] = wasEdgeBox(change.box) | ||
} | ||
@@ -131,3 +138,8 @@ return syncClient.updateRepo(syncKeyEncoded, status.lastHash, { changes }) | ||
// Make the request: | ||
const { changes = {}, hash } = reply | ||
const { hash } = reply | ||
const changes = {} | ||
for (const path of Object.keys(_nullishCoalesce(reply.changes, () => ( {})))) { | ||
const json = reply.changes[path] | ||
changes[path] = json == null ? null : asEdgeBox(json) | ||
} | ||
@@ -134,0 +146,0 @@ // Save the incoming changes into our `data` folder: |
@@ -12,5 +12,5 @@ // @flow | ||
asValue, | ||
uncleaner, | ||
} from "cleaners"; | ||
import { asUsername } from "../core/login/login-stash"; | ||
import { | ||
@@ -25,3 +25,7 @@ asBase32, | ||
export type VoucherDump = { | ||
export type EdgeRepoDump = { | ||
[key: string]: EdgeBox; | ||
} | ||
export type EdgeVoucherDump = { | ||
// Identity: | ||
@@ -43,3 +47,3 @@ loginId: Uint8Array; | ||
export type LoginDump = { | ||
export type EdgeLoginDump = { | ||
// Identity: | ||
@@ -90,3 +94,3 @@ appId: string; | ||
// Resources: | ||
children: LoginDump[]; | ||
children: EdgeLoginDump[]; | ||
keyBoxes: EdgeBox[]; | ||
@@ -96,3 +100,3 @@ mnemonicBox?: EdgeBox; | ||
syncKeyBox?: EdgeBox; | ||
vouchers: VoucherDump[]; | ||
vouchers: EdgeVoucherDump[]; | ||
@@ -105,12 +109,5 @@ // Obsolete: | ||
export type FakeUser = { | ||
lastLogin?: Date; | ||
loginId: Uint8Array; | ||
loginKey: Uint8Array; | ||
repos: { [repo: string]: { [path: string]: EdgeBox } }; | ||
server: LoginDump; | ||
username?: string; | ||
} | ||
export const asEdgeRepoDump: Cleaner<EdgeRepoDump> = asObject(asEdgeBox); | ||
export const asVoucherDump: Cleaner<VoucherDump> = asObject({ | ||
export const asEdgeVoucherDump: Cleaner<EdgeVoucherDump> = asObject({ | ||
// Identity: | ||
@@ -132,6 +129,6 @@ loginId: asBase64, | ||
export const asLoginDump: Cleaner<LoginDump> = asObject({ | ||
export const asEdgeLoginDump: Cleaner<EdgeLoginDump> = asObject({ | ||
// Identity: | ||
appId: asString, | ||
created: (raw) => (raw == null ? new Date() : asDate(raw)), | ||
created: asOptional(asDate, () => new Date()), | ||
loginId: asBase64, | ||
@@ -141,3 +138,3 @@ | ||
children: asOptional( | ||
asArray((raw) => asLoginDump(raw)), | ||
asArray((raw) => asEdgeLoginDump(raw)), | ||
() => [], | ||
@@ -188,3 +185,3 @@ ), | ||
syncKeyBox: asOptional(asEdgeBox), | ||
vouchers: asOptional(asArray(asVoucherDump), () => []), | ||
vouchers: asOptional(asArray(asEdgeVoucherDump), () => []), | ||
@@ -197,16 +194,3 @@ // Obsolete: | ||
export const asFakeUser: Cleaner<FakeUser> = asObject({ | ||
lastLogin: asOptional(asDateObject), | ||
loginId: asBase64, | ||
loginKey: asBase64, | ||
repos: asObject(asObject(asEdgeBox)), | ||
server: asLoginDump, | ||
username: asOptional(asUsername), | ||
}); | ||
export const asFakeUsers = asArray<FakeUser>(asFakeUser); | ||
function asDateObject(raw: mixed): Date { | ||
if (raw instanceof Date) return raw; | ||
throw new TypeError("Expecting a Date"); | ||
} | ||
export const wasEdgeLoginDump = uncleaner<EdgeLoginDump>(asEdgeLoginDump); | ||
export const wasEdgeRepoDump = uncleaner<EdgeRepoDump>(asEdgeRepoDump); |
@@ -15,2 +15,3 @@ // @flow | ||
asValue, | ||
uncleaner, | ||
} from "cleaners"; | ||
@@ -87,2 +88,3 @@ import { base16, base32, base64 } from "rfc4648"; | ||
/** @deprecated The GUI provides its own localized strings now. */ | ||
const asEdgeRecoveryQuestionChoice: Cleaner<EdgeRecoveryQuestionChoice> = | ||
@@ -101,4 +103,4 @@ asObject({ | ||
encryptionType: asNumber, | ||
data_base64: asString, | ||
iv_hex: asString, | ||
data_base64: asBase64, | ||
iv_hex: asBase16, | ||
}); | ||
@@ -179,3 +181,3 @@ | ||
// What of response is this (success or failure)?: | ||
// What type of response is this (success or failure)?: | ||
status_code: asNumber, | ||
@@ -258,3 +260,3 @@ message: asString, | ||
parentBox: asOptional(asEdgeBox), | ||
}).withRest; | ||
}); | ||
@@ -352,2 +354,3 @@ // --------------------------------------------------------------------- | ||
/** @deprecated The GUI provides its own localized strings now. */ | ||
export const asQuestionChoicesPayload: Cleaner<QuestionChoicesPayload> = | ||
@@ -361,2 +364,4 @@ asArray(asEdgeRecoveryQuestionChoice); | ||
export const asUsernameInfoPayload: Cleaner<UsernameInfoPayload> = asObject({ | ||
loginId: asBase64, | ||
// Password login: | ||
@@ -370,1 +375,71 @@ passwordAuthSnrp: asOptional(asEdgeSnrp), | ||
}); | ||
// --------------------------------------------------------------------- | ||
// uncleaners | ||
// --------------------------------------------------------------------- | ||
// Common types: | ||
export const wasEdgeBox = uncleaner<EdgeBox>(asEdgeBox); | ||
export const wasEdgeLobbyReply = uncleaner<EdgeLobbyReply>(asEdgeLobbyReply); | ||
export const wasEdgeLobbyRequest = | ||
uncleaner<EdgeLobbyRequest>(asEdgeLobbyRequest); | ||
// Top-level request / response bodies: | ||
export const wasLoginRequestBody = | ||
uncleaner<LoginRequestBody>(asLoginRequestBody); | ||
export const wasLoginResponseBody = | ||
uncleaner<LoginResponseBody>(asLoginResponseBody); | ||
// Request payloads: | ||
export const wasChangeOtpPayload = | ||
uncleaner<ChangeOtpPayload>(asChangeOtpPayload); | ||
export const wasChangePasswordPayload = uncleaner<ChangePasswordPayload>( | ||
asChangePasswordPayload, | ||
); | ||
export const wasChangePin2IdPayload = uncleaner<ChangePin2IdPayload>( | ||
asChangePin2IdPayload, | ||
); | ||
export const wasChangePin2Payload = | ||
uncleaner<ChangePin2Payload>(asChangePin2Payload); | ||
export const wasChangeRecovery2IdPayload = uncleaner<ChangeRecovery2IdPayload>( | ||
asChangeRecovery2IdPayload, | ||
); | ||
export const wasChangeRecovery2Payload = uncleaner<ChangeRecovery2Payload>( | ||
asChangeRecovery2Payload, | ||
); | ||
export const wasChangeSecretPayload = uncleaner<ChangeSecretPayload>( | ||
asChangeSecretPayload, | ||
); | ||
export const wasChangeUsernamePayload = uncleaner<ChangeUsernamePayload>( | ||
asChangeUsernamePayload, | ||
); | ||
export const wasChangeVouchersPayload = uncleaner<ChangeVouchersPayload>( | ||
asChangeVouchersPayload, | ||
); | ||
export const wasCreateKeysPayload = | ||
uncleaner<CreateKeysPayload>(asCreateKeysPayload); | ||
export const wasCreateLoginPayload = | ||
uncleaner<CreateLoginPayload>(asCreateLoginPayload); | ||
// Response payloads: | ||
export const wasChallengeErrorPayload = uncleaner<ChallengeErrorPayload>( | ||
asChallengeErrorPayload, | ||
); | ||
export const wasLobbyPayload = uncleaner<LobbyPayload>(asLobbyPayload); | ||
export const wasLoginPayload = uncleaner<LoginPayload>(asLoginPayload); | ||
export const wasMessagesPayload = uncleaner<MessagesPayload>(asMessagesPayload); | ||
export const wasOtpErrorPayload = uncleaner<OtpErrorPayload>(asOtpErrorPayload); | ||
export const wasOtpResetPayload = uncleaner<OtpResetPayload>(asOtpResetPayload); | ||
export const wasPasswordErrorPayload = uncleaner<PasswordErrorPayload>( | ||
asPasswordErrorPayload, | ||
); | ||
/** @deprecated The GUI provides its own localized strings now. */ | ||
export const wasQuestionChoicesPayload = uncleaner<QuestionChoicesPayload>( | ||
asQuestionChoicesPayload, | ||
); | ||
export const wasRecovery2InfoPayload = uncleaner<Recovery2InfoPayload>( | ||
asRecovery2InfoPayload, | ||
); | ||
export const wasUsernameInfoPayload = uncleaner<UsernameInfoPayload>( | ||
asUsernameInfoPayload, | ||
); |
@@ -14,4 +14,4 @@ // @flow | ||
encryptionType: number; | ||
data_base64: string; | ||
iv_hex: string; | ||
data_base64: Uint8Array; | ||
iv_hex: Uint8Array; | ||
} | ||
@@ -306,2 +306,3 @@ | ||
* A list of recovery questions the user can pick from. | ||
* @deprecated The GUI provides its own localized strings now. | ||
*/ | ||
@@ -321,2 +322,4 @@ export type QuestionChoicesPayload = EdgeRecoveryQuestionChoice[]; | ||
export type UsernameInfoPayload = { | ||
loginId: Uint8Array; | ||
// Password login: | ||
@@ -323,0 +326,0 @@ passwordAuthSnrp?: EdgeSnrp; |
@@ -13,2 +13,5 @@ // @flow | ||
export * from "./error"; | ||
export * from "./fake-types"; | ||
export * from "./server-cleaners"; | ||
export * from "./server-types"; | ||
@@ -1612,2 +1615,3 @@ // --------------------------------------------------------------------- | ||
/** @deprecated The GUI provides its own localized strings now. */ | ||
export type EdgeRecoveryQuestionChoice = { | ||
@@ -1750,2 +1754,3 @@ category: "address" | "must" | "numeric" | "recovery2" | "string"; | ||
) => Promise<string[]>; | ||
/** @deprecated The GUI provides its own localized strings now. */ | ||
+listRecoveryQuestionChoices: () => Promise< | ||
@@ -1816,8 +1821,10 @@ EdgeRecoveryQuestionChoice[] | ||
export type EdgeFakeUser = { | ||
username: string; | ||
username?: string; | ||
lastLogin?: Date; | ||
loginId: string; // base64 | ||
loginKey: string; // base64 | ||
repos: { [repo: string]: { [path: string]: any /* asEdgeBox */ } }; | ||
server: any; // asLoginDump | ||
repos: { | ||
[syncKey: string]: mixed; // Cleaned with asEdgeRepoDump | ||
}; | ||
server: mixed; // Cleaned with asEdgeLoginDump | ||
} | ||
@@ -1824,0 +1831,0 @@ |
@@ -1,2 +0,3 @@ | ||
const _jsxFileName = "src/react-native.tsx";import { makeReactNativeDisklet } from 'disklet' | ||
const _jsxFileName = "src/react-native.tsx";import { asObject, asString } from 'cleaners' | ||
import { makeReactNativeDisklet } from 'disklet' | ||
import * as React from 'react' | ||
@@ -78,3 +79,3 @@ import { base64 } from 'rfc4648' | ||
await onLoad(context) | ||
}, __self: this, __source: {fileName: _jsxFileName, lineNumber: 54}} | ||
}, __self: this, __source: {fileName: _jsxFileName, lineNumber: 55}} | ||
) | ||
@@ -114,3 +115,3 @@ ) | ||
await onLoad(fakeWorld) | ||
}, __self: this, __source: {fileName: _jsxFileName, lineNumber: 100}} | ||
}, __self: this, __source: {fileName: _jsxFileName, lineNumber: 101}} | ||
) | ||
@@ -133,2 +134,8 @@ ) | ||
/** Just the parts of LoginStash that `fetchLoginMessages` needs. */ | ||
const asUsernameStash = asObject({ | ||
loginId: asString, | ||
username: asString | ||
}) | ||
/** | ||
@@ -152,4 +159,3 @@ * Fetches any login-related messages for all the users on this device. | ||
try { | ||
const { username, loginId } = JSON.parse(text) | ||
if (loginId == null || username == null) continue | ||
const { username, loginId } = asUsernameStash(JSON.parse(text)) | ||
loginMap[loginId] = username | ||
@@ -156,0 +162,0 @@ } catch (error) {} |
@@ -9,6 +9,6 @@ | ||
asString, | ||
asValue | ||
asValue, | ||
uncleaner | ||
} from 'cleaners' | ||
import { asUsername } from '../core/login/login-stash' | ||
import { | ||
@@ -103,8 +103,5 @@ asBase32, | ||
export const asEdgeRepoDump = asObject(asEdgeBox) | ||
export const asVoucherDump = asObject({ | ||
export const asEdgeVoucherDump = asObject({ | ||
// Identity: | ||
@@ -126,6 +123,6 @@ loginId: asBase64, | ||
export const asLoginDump = asObject({ | ||
export const asEdgeLoginDump = asObject({ | ||
// Identity: | ||
appId: asString, | ||
created: raw => (raw == null ? new Date() : asDate(raw)), | ||
created: asOptional(asDate, () => new Date()), | ||
loginId: asBase64, | ||
@@ -135,3 +132,3 @@ | ||
children: asOptional( | ||
asArray(raw => asLoginDump(raw)), | ||
asArray(raw => asEdgeLoginDump(raw)), | ||
() => [] | ||
@@ -182,3 +179,3 @@ ), | ||
syncKeyBox: asOptional(asEdgeBox), | ||
vouchers: asOptional(asArray(asVoucherDump), () => []), | ||
vouchers: asOptional(asArray(asEdgeVoucherDump), () => []), | ||
@@ -191,16 +188,3 @@ // Obsolete: | ||
export const asFakeUser = asObject({ | ||
lastLogin: asOptional(asDateObject), | ||
loginId: asBase64, | ||
loginKey: asBase64, | ||
repos: asObject(asObject(asEdgeBox)), | ||
server: asLoginDump, | ||
username: asOptional(asUsername) | ||
}) | ||
export const asFakeUsers = asArray(asFakeUser) | ||
function asDateObject(raw) { | ||
if (raw instanceof Date) return raw | ||
throw new TypeError('Expecting a Date') | ||
} | ||
export const wasEdgeLoginDump = uncleaner(asEdgeLoginDump) | ||
export const wasEdgeRepoDump = uncleaner(asEdgeRepoDump) |
@@ -12,3 +12,4 @@ | ||
asUnknown, | ||
asValue | ||
asValue, | ||
uncleaner | ||
} from 'cleaners' | ||
@@ -85,2 +86,3 @@ import { base16, base32, base64 } from 'rfc4648' | ||
/** @deprecated The GUI provides its own localized strings now. */ | ||
const asEdgeRecoveryQuestionChoice = | ||
@@ -99,4 +101,4 @@ asObject({ | ||
encryptionType: asNumber, | ||
data_base64: asString, | ||
iv_hex: asString | ||
data_base64: asBase64, | ||
iv_hex: asBase16 | ||
}) | ||
@@ -177,3 +179,3 @@ | ||
// What of response is this (success or failure)?: | ||
// What type of response is this (success or failure)?: | ||
status_code: asNumber, | ||
@@ -256,3 +258,3 @@ message: asString | ||
parentBox: asOptional(asEdgeBox) | ||
}).withRest | ||
}) | ||
@@ -350,2 +352,3 @@ // --------------------------------------------------------------------- | ||
/** @deprecated The GUI provides its own localized strings now. */ | ||
export const asQuestionChoicesPayload = | ||
@@ -359,2 +362,4 @@ asArray(asEdgeRecoveryQuestionChoice) | ||
export const asUsernameInfoPayload = asObject({ | ||
loginId: asBase64, | ||
// Password login: | ||
@@ -368,1 +373,71 @@ passwordAuthSnrp: asOptional(asEdgeSnrp), | ||
}) | ||
// --------------------------------------------------------------------- | ||
// uncleaners | ||
// --------------------------------------------------------------------- | ||
// Common types: | ||
export const wasEdgeBox = uncleaner(asEdgeBox) | ||
export const wasEdgeLobbyReply = uncleaner(asEdgeLobbyReply) | ||
export const wasEdgeLobbyRequest = | ||
uncleaner(asEdgeLobbyRequest) | ||
// Top-level request / response bodies: | ||
export const wasLoginRequestBody = | ||
uncleaner(asLoginRequestBody) | ||
export const wasLoginResponseBody = | ||
uncleaner(asLoginResponseBody) | ||
// Request payloads: | ||
export const wasChangeOtpPayload = | ||
uncleaner(asChangeOtpPayload) | ||
export const wasChangePasswordPayload = uncleaner( | ||
asChangePasswordPayload | ||
) | ||
export const wasChangePin2IdPayload = uncleaner( | ||
asChangePin2IdPayload | ||
) | ||
export const wasChangePin2Payload = | ||
uncleaner(asChangePin2Payload) | ||
export const wasChangeRecovery2IdPayload = uncleaner( | ||
asChangeRecovery2IdPayload | ||
) | ||
export const wasChangeRecovery2Payload = uncleaner( | ||
asChangeRecovery2Payload | ||
) | ||
export const wasChangeSecretPayload = uncleaner( | ||
asChangeSecretPayload | ||
) | ||
export const wasChangeUsernamePayload = uncleaner( | ||
asChangeUsernamePayload | ||
) | ||
export const wasChangeVouchersPayload = uncleaner( | ||
asChangeVouchersPayload | ||
) | ||
export const wasCreateKeysPayload = | ||
uncleaner(asCreateKeysPayload) | ||
export const wasCreateLoginPayload = | ||
uncleaner(asCreateLoginPayload) | ||
// Response payloads: | ||
export const wasChallengeErrorPayload = uncleaner( | ||
asChallengeErrorPayload | ||
) | ||
export const wasLobbyPayload = uncleaner(asLobbyPayload) | ||
export const wasLoginPayload = uncleaner(asLoginPayload) | ||
export const wasMessagesPayload = uncleaner(asMessagesPayload) | ||
export const wasOtpErrorPayload = uncleaner(asOtpErrorPayload) | ||
export const wasOtpResetPayload = uncleaner(asOtpResetPayload) | ||
export const wasPasswordErrorPayload = uncleaner( | ||
asPasswordErrorPayload | ||
) | ||
/** @deprecated The GUI provides its own localized strings now. */ | ||
export const wasQuestionChoicesPayload = uncleaner( | ||
asQuestionChoicesPayload | ||
) | ||
export const wasRecovery2InfoPayload = uncleaner( | ||
asRecovery2InfoPayload | ||
) | ||
export const wasUsernameInfoPayload = uncleaner( | ||
asUsernameInfoPayload | ||
) |
@@ -325,1 +325,4 @@ | ||
@@ -11,2 +11,5 @@ | ||
export * from './error' | ||
export * from './fake-types' | ||
export * from './server-cleaners' | ||
export * from './server-types' | ||
@@ -1833,1 +1836,5 @@ // --------------------------------------------------------------------- | ||
import aesjs from 'aes-js' | ||
import { base16, base64 } from 'rfc4648' | ||
@@ -33,4 +32,4 @@ | ||
} | ||
const iv = base16.parse(box.iv_hex) | ||
const ciphertext = base64.parse(box.data_base64) | ||
const iv = box.iv_hex | ||
const ciphertext = box.data_base64 | ||
@@ -119,4 +118,4 @@ // Decrypt: | ||
encryptionType: 0, | ||
iv_hex: base16.stringify(iv), | ||
data_base64: base64.stringify(ciphertext) | ||
iv_hex: iv, | ||
data_base64: ciphertext | ||
} | ||
@@ -123,0 +122,0 @@ } |
{ | ||
"name": "edge-core-js", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "Edge account & wallet management library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -9,6 +9,6 @@ import type { Cleaner } from 'cleaners' | ||
asString, | ||
asValue | ||
asValue, | ||
uncleaner | ||
} from 'cleaners' | ||
import { asUsername } from '../core/login/login-stash' | ||
import { | ||
@@ -23,3 +23,7 @@ asBase32, | ||
export interface VoucherDump { | ||
export interface EdgeRepoDump { | ||
[key: string]: EdgeBox | ||
} | ||
export interface EdgeVoucherDump { | ||
// Identity: | ||
@@ -41,3 +45,3 @@ loginId: Uint8Array | ||
export interface LoginDump { | ||
export interface EdgeLoginDump { | ||
// Identity: | ||
@@ -88,3 +92,3 @@ appId: string | ||
// Resources: | ||
children: LoginDump[] | ||
children: EdgeLoginDump[] | ||
keyBoxes: EdgeBox[] | ||
@@ -94,3 +98,3 @@ mnemonicBox?: EdgeBox | ||
syncKeyBox?: EdgeBox | ||
vouchers: VoucherDump[] | ||
vouchers: EdgeVoucherDump[] | ||
@@ -103,12 +107,5 @@ // Obsolete: | ||
export interface FakeUser { | ||
lastLogin?: Date | ||
loginId: Uint8Array | ||
loginKey: Uint8Array | ||
repos: { [repo: string]: { [path: string]: EdgeBox } } | ||
server: LoginDump | ||
username?: string | ||
} | ||
export const asEdgeRepoDump: Cleaner<EdgeRepoDump> = asObject(asEdgeBox) | ||
export const asVoucherDump: Cleaner<VoucherDump> = asObject({ | ||
export const asEdgeVoucherDump: Cleaner<EdgeVoucherDump> = asObject({ | ||
// Identity: | ||
@@ -130,6 +127,6 @@ loginId: asBase64, | ||
export const asLoginDump: Cleaner<LoginDump> = asObject({ | ||
export const asEdgeLoginDump: Cleaner<EdgeLoginDump> = asObject({ | ||
// Identity: | ||
appId: asString, | ||
created: raw => (raw == null ? new Date() : asDate(raw)), | ||
created: asOptional(asDate, () => new Date()), | ||
loginId: asBase64, | ||
@@ -139,3 +136,3 @@ | ||
children: asOptional( | ||
asArray(raw => asLoginDump(raw)), | ||
asArray(raw => asEdgeLoginDump(raw)), | ||
() => [] | ||
@@ -186,3 +183,3 @@ ), | ||
syncKeyBox: asOptional(asEdgeBox), | ||
vouchers: asOptional(asArray(asVoucherDump), () => []), | ||
vouchers: asOptional(asArray(asEdgeVoucherDump), () => []), | ||
@@ -195,16 +192,3 @@ // Obsolete: | ||
export const asFakeUser: Cleaner<FakeUser> = asObject({ | ||
lastLogin: asOptional(asDateObject), | ||
loginId: asBase64, | ||
loginKey: asBase64, | ||
repos: asObject(asObject(asEdgeBox)), | ||
server: asLoginDump, | ||
username: asOptional(asUsername) | ||
}) | ||
export const asFakeUsers = asArray<FakeUser>(asFakeUser) | ||
function asDateObject(raw: unknown): Date { | ||
if (raw instanceof Date) return raw | ||
throw new TypeError('Expecting a Date') | ||
} | ||
export const wasEdgeLoginDump = uncleaner<EdgeLoginDump>(asEdgeLoginDump) | ||
export const wasEdgeRepoDump = uncleaner<EdgeRepoDump>(asEdgeRepoDump) |
@@ -12,3 +12,4 @@ import type { Cleaner } from 'cleaners' | ||
asUnknown, | ||
asValue | ||
asValue, | ||
uncleaner | ||
} from 'cleaners' | ||
@@ -85,2 +86,3 @@ import { base16, base32, base64 } from 'rfc4648' | ||
/** @deprecated The GUI provides its own localized strings now. */ | ||
const asEdgeRecoveryQuestionChoice: Cleaner<EdgeRecoveryQuestionChoice> = | ||
@@ -99,4 +101,4 @@ asObject({ | ||
encryptionType: asNumber, | ||
data_base64: asString, | ||
iv_hex: asString | ||
data_base64: asBase64, | ||
iv_hex: asBase16 | ||
}) | ||
@@ -177,3 +179,3 @@ | ||
// What of response is this (success or failure)?: | ||
// What type of response is this (success or failure)?: | ||
status_code: asNumber, | ||
@@ -256,3 +258,3 @@ message: asString | ||
parentBox: asOptional(asEdgeBox) | ||
}).withRest | ||
}) | ||
@@ -350,2 +352,3 @@ // --------------------------------------------------------------------- | ||
/** @deprecated The GUI provides its own localized strings now. */ | ||
export const asQuestionChoicesPayload: Cleaner<QuestionChoicesPayload> = | ||
@@ -359,2 +362,4 @@ asArray(asEdgeRecoveryQuestionChoice) | ||
export const asUsernameInfoPayload: Cleaner<UsernameInfoPayload> = asObject({ | ||
loginId: asBase64, | ||
// Password login: | ||
@@ -368,1 +373,71 @@ passwordAuthSnrp: asOptional(asEdgeSnrp), | ||
}) | ||
// --------------------------------------------------------------------- | ||
// uncleaners | ||
// --------------------------------------------------------------------- | ||
// Common types: | ||
export const wasEdgeBox = uncleaner<EdgeBox>(asEdgeBox) | ||
export const wasEdgeLobbyReply = uncleaner<EdgeLobbyReply>(asEdgeLobbyReply) | ||
export const wasEdgeLobbyRequest = | ||
uncleaner<EdgeLobbyRequest>(asEdgeLobbyRequest) | ||
// Top-level request / response bodies: | ||
export const wasLoginRequestBody = | ||
uncleaner<LoginRequestBody>(asLoginRequestBody) | ||
export const wasLoginResponseBody = | ||
uncleaner<LoginResponseBody>(asLoginResponseBody) | ||
// Request payloads: | ||
export const wasChangeOtpPayload = | ||
uncleaner<ChangeOtpPayload>(asChangeOtpPayload) | ||
export const wasChangePasswordPayload = uncleaner<ChangePasswordPayload>( | ||
asChangePasswordPayload | ||
) | ||
export const wasChangePin2IdPayload = uncleaner<ChangePin2IdPayload>( | ||
asChangePin2IdPayload | ||
) | ||
export const wasChangePin2Payload = | ||
uncleaner<ChangePin2Payload>(asChangePin2Payload) | ||
export const wasChangeRecovery2IdPayload = uncleaner<ChangeRecovery2IdPayload>( | ||
asChangeRecovery2IdPayload | ||
) | ||
export const wasChangeRecovery2Payload = uncleaner<ChangeRecovery2Payload>( | ||
asChangeRecovery2Payload | ||
) | ||
export const wasChangeSecretPayload = uncleaner<ChangeSecretPayload>( | ||
asChangeSecretPayload | ||
) | ||
export const wasChangeUsernamePayload = uncleaner<ChangeUsernamePayload>( | ||
asChangeUsernamePayload | ||
) | ||
export const wasChangeVouchersPayload = uncleaner<ChangeVouchersPayload>( | ||
asChangeVouchersPayload | ||
) | ||
export const wasCreateKeysPayload = | ||
uncleaner<CreateKeysPayload>(asCreateKeysPayload) | ||
export const wasCreateLoginPayload = | ||
uncleaner<CreateLoginPayload>(asCreateLoginPayload) | ||
// Response payloads: | ||
export const wasChallengeErrorPayload = uncleaner<ChallengeErrorPayload>( | ||
asChallengeErrorPayload | ||
) | ||
export const wasLobbyPayload = uncleaner<LobbyPayload>(asLobbyPayload) | ||
export const wasLoginPayload = uncleaner<LoginPayload>(asLoginPayload) | ||
export const wasMessagesPayload = uncleaner<MessagesPayload>(asMessagesPayload) | ||
export const wasOtpErrorPayload = uncleaner<OtpErrorPayload>(asOtpErrorPayload) | ||
export const wasOtpResetPayload = uncleaner<OtpResetPayload>(asOtpResetPayload) | ||
export const wasPasswordErrorPayload = uncleaner<PasswordErrorPayload>( | ||
asPasswordErrorPayload | ||
) | ||
/** @deprecated The GUI provides its own localized strings now. */ | ||
export const wasQuestionChoicesPayload = uncleaner<QuestionChoicesPayload>( | ||
asQuestionChoicesPayload | ||
) | ||
export const wasRecovery2InfoPayload = uncleaner<Recovery2InfoPayload>( | ||
asRecovery2InfoPayload | ||
) | ||
export const wasUsernameInfoPayload = uncleaner<UsernameInfoPayload>( | ||
asUsernameInfoPayload | ||
) |
@@ -12,4 +12,4 @@ import type { EdgePendingVoucher, EdgeRecoveryQuestionChoice } from './types' | ||
encryptionType: number | ||
data_base64: string | ||
iv_hex: string | ||
data_base64: Uint8Array | ||
iv_hex: Uint8Array | ||
} | ||
@@ -304,2 +304,3 @@ | ||
* A list of recovery questions the user can pick from. | ||
* @deprecated The GUI provides its own localized strings now. | ||
*/ | ||
@@ -319,2 +320,4 @@ export type QuestionChoicesPayload = EdgeRecoveryQuestionChoice[] | ||
export interface UsernameInfoPayload { | ||
loginId: Uint8Array | ||
// Password login: | ||
@@ -321,0 +324,0 @@ passwordAuthSnrp?: EdgeSnrp |
@@ -11,2 +11,5 @@ import type { Disklet } from 'disklet' | ||
export * from './error' | ||
export * from './fake-types' | ||
export * from './server-cleaners' | ||
export * from './server-types' | ||
@@ -1604,2 +1607,3 @@ // --------------------------------------------------------------------- | ||
/** @deprecated The GUI provides its own localized strings now. */ | ||
export interface EdgeRecoveryQuestionChoice { | ||
@@ -1742,2 +1746,3 @@ category: 'address' | 'must' | 'numeric' | 'recovery2' | 'string' | ||
) => Promise<string[]> | ||
/** @deprecated The GUI provides its own localized strings now. */ | ||
readonly listRecoveryQuestionChoices: () => Promise< | ||
@@ -1808,8 +1813,10 @@ EdgeRecoveryQuestionChoice[] | ||
export interface EdgeFakeUser { | ||
username: string | ||
username?: string | ||
lastLogin?: Date | ||
loginId: string // base64 | ||
loginKey: string // base64 | ||
repos: { [repo: string]: { [path: string]: any /* asEdgeBox */ } } | ||
server: any // asLoginDump | ||
repos: { | ||
[syncKey: string]: unknown // Cleaned with asEdgeRepoDump | ||
} | ||
server: unknown // Cleaned with asEdgeLoginDump | ||
} | ||
@@ -1816,0 +1823,0 @@ |
223
types.js
@@ -39,2 +39,4 @@ 'use strict'; | ||
}); | ||
/** @deprecated The GUI provides its own localized strings now. */ | ||
const asEdgeRecoveryQuestionChoice = cleaners.asObject({ | ||
@@ -52,4 +54,4 @@ min_length: cleaners.asNumber, | ||
encryptionType: cleaners.asNumber, | ||
data_base64: cleaners.asString, | ||
iv_hex: cleaners.asString | ||
data_base64: asBase64, | ||
iv_hex: asBase16 | ||
}); | ||
@@ -83,3 +85,3 @@ const asEdgeSnrp = cleaners.asObject({ | ||
cleaners.asObject({ | ||
const asLoginRequestBody = cleaners.asObject({ | ||
// The request payload: | ||
@@ -118,6 +120,6 @@ data: cleaners.asUnknown, | ||
cleaners.asObject({ | ||
const asLoginResponseBody = cleaners.asObject({ | ||
// The response payload: | ||
results: cleaners.asOptional(cleaners.asUnknown), | ||
// What of response is this (success or failure)?: | ||
// What type of response is this (success or failure)?: | ||
status_code: cleaners.asNumber, | ||
@@ -131,3 +133,3 @@ message: cleaners.asString | ||
cleaners.asObject({ | ||
const asChangeOtpPayload = cleaners.asObject({ | ||
otpTimeout: cleaners.asOptional(cleaners.asNumber, 7 * 24 * 60 * 60), | ||
@@ -137,3 +139,3 @@ // seconds | ||
}); | ||
cleaners.asObject({ | ||
const asChangePasswordPayload = cleaners.asObject({ | ||
passwordAuth: asBase64, | ||
@@ -145,6 +147,6 @@ passwordAuthBox: asEdgeBox, | ||
}); | ||
cleaners.asObject({ | ||
const asChangePin2IdPayload = cleaners.asObject({ | ||
pin2Id: asBase64 | ||
}); | ||
cleaners.asObject({ | ||
const asChangePin2Payload = cleaners.asObject({ | ||
pin2Id: cleaners.asOptional(asBase64), | ||
@@ -156,6 +158,6 @@ pin2Auth: cleaners.asOptional(asBase64), | ||
}); | ||
cleaners.asObject({ | ||
const asChangeRecovery2IdPayload = cleaners.asObject({ | ||
recovery2Id: asBase64 | ||
}); | ||
cleaners.asObject({ | ||
const asChangeRecovery2Payload = cleaners.asObject({ | ||
recovery2Id: asBase64, | ||
@@ -167,23 +169,23 @@ recovery2Auth: asRecovery2Auth, | ||
}); | ||
cleaners.asObject({ | ||
const asChangeSecretPayload = cleaners.asObject({ | ||
loginAuthBox: asEdgeBox, | ||
loginAuth: asBase64 | ||
}); | ||
cleaners.asObject({ | ||
const asChangeUsernamePayload = cleaners.asObject({ | ||
userId: asBase64, | ||
userTextBox: asEdgeBox | ||
}); | ||
cleaners.asObject({ | ||
const asChangeVouchersPayload = cleaners.asObject({ | ||
approvedVouchers: cleaners.asOptional(cleaners.asArray(cleaners.asString)), | ||
rejectedVouchers: cleaners.asOptional(cleaners.asArray(cleaners.asString)) | ||
}); | ||
cleaners.asObject({ | ||
const asCreateKeysPayload = cleaners.asObject({ | ||
keyBoxes: cleaners.asArray(asEdgeBox), | ||
newSyncKeys: cleaners.asOptional(cleaners.asArray(cleaners.asString), () => []) | ||
}); | ||
cleaners.asObject({ | ||
const asCreateLoginPayload = cleaners.asObject({ | ||
appId: cleaners.asString, | ||
loginId: asBase64, | ||
parentBox: cleaners.asOptional(asEdgeBox) | ||
}).withRest; | ||
}); | ||
@@ -194,7 +196,7 @@ // --------------------------------------------------------------------- | ||
cleaners.asObject({ | ||
const asChallengeErrorPayload = cleaners.asObject({ | ||
challengeId: cleaners.asString, | ||
challengeUri: cleaners.asString | ||
}); | ||
cleaners.asObject({ | ||
const asLobbyPayload = cleaners.asObject({ | ||
request: asEdgeLobbyRequest, | ||
@@ -241,3 +243,3 @@ replies: cleaners.asArray(asEdgeLobbyReply) | ||
}); | ||
cleaners.asArray(cleaners.asObject({ | ||
const asMessagesPayload = cleaners.asArray(cleaners.asObject({ | ||
loginId: asBase64, | ||
@@ -257,3 +259,3 @@ otpResetPending: cleaners.asOptional(cleaners.asBoolean, false), | ||
}); | ||
cleaners.asObject({ | ||
const asOtpResetPayload = cleaners.asObject({ | ||
otpResetDate: cleaners.asDate | ||
@@ -264,7 +266,10 @@ }); | ||
}); | ||
cleaners.asArray(asEdgeRecoveryQuestionChoice); | ||
cleaners.asObject({ | ||
/** @deprecated The GUI provides its own localized strings now. */ | ||
const asQuestionChoicesPayload = cleaners.asArray(asEdgeRecoveryQuestionChoice); | ||
const asRecovery2InfoPayload = cleaners.asObject({ | ||
question2Box: asEdgeBox | ||
}); | ||
cleaners.asObject({ | ||
const asUsernameInfoPayload = cleaners.asObject({ | ||
loginId: asBase64, | ||
// Password login: | ||
@@ -278,2 +283,41 @@ passwordAuthSnrp: cleaners.asOptional(asEdgeSnrp), | ||
// --------------------------------------------------------------------- | ||
// uncleaners | ||
// --------------------------------------------------------------------- | ||
// Common types: | ||
const wasEdgeBox = cleaners.uncleaner(asEdgeBox); | ||
const wasEdgeLobbyReply = cleaners.uncleaner(asEdgeLobbyReply); | ||
const wasEdgeLobbyRequest = cleaners.uncleaner(asEdgeLobbyRequest); | ||
// Top-level request / response bodies: | ||
const wasLoginRequestBody = cleaners.uncleaner(asLoginRequestBody); | ||
const wasLoginResponseBody = cleaners.uncleaner(asLoginResponseBody); | ||
// Request payloads: | ||
const wasChangeOtpPayload = cleaners.uncleaner(asChangeOtpPayload); | ||
const wasChangePasswordPayload = cleaners.uncleaner(asChangePasswordPayload); | ||
const wasChangePin2IdPayload = cleaners.uncleaner(asChangePin2IdPayload); | ||
const wasChangePin2Payload = cleaners.uncleaner(asChangePin2Payload); | ||
const wasChangeRecovery2IdPayload = cleaners.uncleaner(asChangeRecovery2IdPayload); | ||
const wasChangeRecovery2Payload = cleaners.uncleaner(asChangeRecovery2Payload); | ||
const wasChangeSecretPayload = cleaners.uncleaner(asChangeSecretPayload); | ||
const wasChangeUsernamePayload = cleaners.uncleaner(asChangeUsernamePayload); | ||
const wasChangeVouchersPayload = cleaners.uncleaner(asChangeVouchersPayload); | ||
const wasCreateKeysPayload = cleaners.uncleaner(asCreateKeysPayload); | ||
const wasCreateLoginPayload = cleaners.uncleaner(asCreateLoginPayload); | ||
// Response payloads: | ||
const wasChallengeErrorPayload = cleaners.uncleaner(asChallengeErrorPayload); | ||
const wasLobbyPayload = cleaners.uncleaner(asLobbyPayload); | ||
const wasLoginPayload = cleaners.uncleaner(asLoginPayload); | ||
const wasMessagesPayload = cleaners.uncleaner(asMessagesPayload); | ||
const wasOtpErrorPayload = cleaners.uncleaner(asOtpErrorPayload); | ||
const wasOtpResetPayload = cleaners.uncleaner(asOtpResetPayload); | ||
const wasPasswordErrorPayload = cleaners.uncleaner(asPasswordErrorPayload); | ||
/** @deprecated The GUI provides its own localized strings now. */ | ||
const wasQuestionChoicesPayload = cleaners.uncleaner(asQuestionChoicesPayload); | ||
const wasRecovery2InfoPayload = cleaners.uncleaner(asRecovery2InfoPayload); | ||
const wasUsernameInfoPayload = cleaners.uncleaner(asUsernameInfoPayload); | ||
/** | ||
@@ -773,2 +817,70 @@ * Translates a currency code to a tokenId, | ||
const asEdgeRepoDump = cleaners.asObject(asEdgeBox); | ||
const asEdgeVoucherDump = cleaners.asObject({ | ||
// Identity: | ||
loginId: asBase64, | ||
voucherAuth: asBase64, | ||
voucherId: cleaners.asString, | ||
// Login capability: | ||
created: cleaners.asDate, | ||
activates: cleaners.asDate, | ||
// Automatically becomes approved on this date | ||
status: cleaners.asValue('pending', 'approved', 'rejected'), | ||
// Information about the login: | ||
ip: cleaners.asString, | ||
ipDescription: cleaners.asString, | ||
deviceDescription: cleaners.asOptional(cleaners.asString) | ||
}); | ||
const asEdgeLoginDump = cleaners.asObject({ | ||
// Identity: | ||
appId: cleaners.asString, | ||
created: cleaners.asOptional(cleaners.asDate, () => new Date()), | ||
loginId: asBase64, | ||
// Nested logins: | ||
children: cleaners.asOptional(cleaners.asArray(raw => asEdgeLoginDump(raw)), () => []), | ||
parentBox: cleaners.asOptional(asEdgeBox), | ||
parentId: () => undefined, | ||
// 2-factor login: | ||
otpKey: cleaners.asOptional(asBase32), | ||
otpResetAuth: cleaners.asOptional(cleaners.asString), | ||
otpResetDate: cleaners.asOptional(cleaners.asDate), | ||
otpTimeout: cleaners.asOptional(cleaners.asNumber), | ||
// Password login: | ||
passwordAuth: cleaners.asOptional(asBase64), | ||
passwordAuthBox: cleaners.asOptional(asEdgeBox), | ||
passwordAuthSnrp: cleaners.asOptional(asEdgeSnrp), | ||
passwordBox: cleaners.asOptional(asEdgeBox), | ||
passwordKeySnrp: cleaners.asOptional(asEdgeSnrp), | ||
// PIN v2 login: | ||
pin2Id: cleaners.asOptional(asBase64), | ||
pin2Auth: cleaners.asOptional(asBase64), | ||
pin2Box: cleaners.asOptional(asEdgeBox), | ||
pin2KeyBox: cleaners.asOptional(asEdgeBox), | ||
pin2TextBox: cleaners.asOptional(asEdgeBox), | ||
// Recovery v2 login: | ||
recovery2Id: cleaners.asOptional(asBase64), | ||
recovery2Auth: cleaners.asOptional(asRecovery2Auth), | ||
question2Box: cleaners.asOptional(asEdgeBox), | ||
recovery2Box: cleaners.asOptional(asEdgeBox), | ||
recovery2KeyBox: cleaners.asOptional(asEdgeBox), | ||
// Secret-key login: | ||
loginAuth: cleaners.asOptional(asBase64), | ||
loginAuthBox: cleaners.asOptional(asEdgeBox), | ||
// Username: | ||
userId: cleaners.asOptional(asBase64), | ||
userTextBox: cleaners.asOptional(asEdgeBox), | ||
// Keys and assorted goodies: | ||
keyBoxes: cleaners.asOptional(cleaners.asArray(asEdgeBox), () => []), | ||
mnemonicBox: cleaners.asOptional(asEdgeBox), | ||
rootKeyBox: cleaners.asOptional(asEdgeBox), | ||
syncKeyBox: cleaners.asOptional(asEdgeBox), | ||
vouchers: cleaners.asOptional(cleaners.asArray(asEdgeVoucherDump), () => []), | ||
// Obsolete: | ||
pinBox: cleaners.asOptional(asEdgeBox), | ||
pinId: cleaners.asOptional(cleaners.asString), | ||
pinKeyBox: cleaners.asOptional(asEdgeBox) | ||
}); | ||
const wasEdgeLoginDump = cleaners.uncleaner(asEdgeLoginDump); | ||
const wasEdgeRepoDump = cleaners.uncleaner(asEdgeRepoDump); | ||
exports.ChallengeError = ChallengeError; | ||
@@ -790,2 +902,29 @@ exports.DustSpendError = DustSpendError; | ||
exports.UsernameError = UsernameError; | ||
exports.asBase16 = asBase16; | ||
exports.asBase32 = asBase32; | ||
exports.asBase64 = asBase64; | ||
exports.asChallengeErrorPayload = asChallengeErrorPayload; | ||
exports.asChangeOtpPayload = asChangeOtpPayload; | ||
exports.asChangePasswordPayload = asChangePasswordPayload; | ||
exports.asChangePin2IdPayload = asChangePin2IdPayload; | ||
exports.asChangePin2Payload = asChangePin2Payload; | ||
exports.asChangeRecovery2IdPayload = asChangeRecovery2IdPayload; | ||
exports.asChangeRecovery2Payload = asChangeRecovery2Payload; | ||
exports.asChangeSecretPayload = asChangeSecretPayload; | ||
exports.asChangeUsernamePayload = asChangeUsernamePayload; | ||
exports.asChangeVouchersPayload = asChangeVouchersPayload; | ||
exports.asCreateKeysPayload = asCreateKeysPayload; | ||
exports.asCreateLoginPayload = asCreateLoginPayload; | ||
exports.asEdgeBox = asEdgeBox; | ||
exports.asEdgeLobbyReply = asEdgeLobbyReply; | ||
exports.asEdgeLobbyRequest = asEdgeLobbyRequest; | ||
exports.asEdgeLoginDump = asEdgeLoginDump; | ||
exports.asEdgePendingVoucher = asEdgePendingVoucher; | ||
exports.asEdgeRepoDump = asEdgeRepoDump; | ||
exports.asEdgeSnrp = asEdgeSnrp; | ||
exports.asEdgeVoucherDump = asEdgeVoucherDump; | ||
exports.asLobbyPayload = asLobbyPayload; | ||
exports.asLoginPayload = asLoginPayload; | ||
exports.asLoginRequestBody = asLoginRequestBody; | ||
exports.asLoginResponseBody = asLoginResponseBody; | ||
exports.asMaybeChallengeError = asMaybeChallengeError; | ||
@@ -807,1 +946,37 @@ exports.asMaybeDustSpendError = asMaybeDustSpendError; | ||
exports.asMaybeUsernameError = asMaybeUsernameError; | ||
exports.asMessagesPayload = asMessagesPayload; | ||
exports.asOtpErrorPayload = asOtpErrorPayload; | ||
exports.asOtpResetPayload = asOtpResetPayload; | ||
exports.asPasswordErrorPayload = asPasswordErrorPayload; | ||
exports.asQuestionChoicesPayload = asQuestionChoicesPayload; | ||
exports.asRecovery2Auth = asRecovery2Auth; | ||
exports.asRecovery2InfoPayload = asRecovery2InfoPayload; | ||
exports.asUsernameInfoPayload = asUsernameInfoPayload; | ||
exports.wasChallengeErrorPayload = wasChallengeErrorPayload; | ||
exports.wasChangeOtpPayload = wasChangeOtpPayload; | ||
exports.wasChangePasswordPayload = wasChangePasswordPayload; | ||
exports.wasChangePin2IdPayload = wasChangePin2IdPayload; | ||
exports.wasChangePin2Payload = wasChangePin2Payload; | ||
exports.wasChangeRecovery2IdPayload = wasChangeRecovery2IdPayload; | ||
exports.wasChangeRecovery2Payload = wasChangeRecovery2Payload; | ||
exports.wasChangeSecretPayload = wasChangeSecretPayload; | ||
exports.wasChangeUsernamePayload = wasChangeUsernamePayload; | ||
exports.wasChangeVouchersPayload = wasChangeVouchersPayload; | ||
exports.wasCreateKeysPayload = wasCreateKeysPayload; | ||
exports.wasCreateLoginPayload = wasCreateLoginPayload; | ||
exports.wasEdgeBox = wasEdgeBox; | ||
exports.wasEdgeLobbyReply = wasEdgeLobbyReply; | ||
exports.wasEdgeLobbyRequest = wasEdgeLobbyRequest; | ||
exports.wasEdgeLoginDump = wasEdgeLoginDump; | ||
exports.wasEdgeRepoDump = wasEdgeRepoDump; | ||
exports.wasLobbyPayload = wasLobbyPayload; | ||
exports.wasLoginPayload = wasLoginPayload; | ||
exports.wasLoginRequestBody = wasLoginRequestBody; | ||
exports.wasLoginResponseBody = wasLoginResponseBody; | ||
exports.wasMessagesPayload = wasMessagesPayload; | ||
exports.wasOtpErrorPayload = wasOtpErrorPayload; | ||
exports.wasOtpResetPayload = wasOtpResetPayload; | ||
exports.wasPasswordErrorPayload = wasPasswordErrorPayload; | ||
exports.wasQuestionChoicesPayload = wasQuestionChoicesPayload; | ||
exports.wasRecovery2InfoPayload = wasRecovery2InfoPayload; | ||
exports.wasUsernameInfoPayload = wasUsernameInfoPayload; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
3444176
33598