@planq-network/encrypted-backup
Version:
Libraries for implemented password encrypted account backups
309 lines • 11.8 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NO_QUOTA_ALFAJORES_CONFIG = exports.E2E_TESTING_ALFAJORES_CONFIG = exports.PASSWORD_HARDENING_ALFAJORES_CONFIG = exports.NO_QUOTA_MAINNET_CONFIG = exports.E2E_TESTING_MAINNET_CONFIG = exports.PASSWORD_HARDENING_MAINNET_CONFIG = exports.PIN_HARDENING_ALFAJORES_CONFIG = exports.PIN_HARDENING_MAINNET_CONFIG = exports.EnvironmentIdentifier = exports.ComputationalHardeningFunction = void 0;
var circuit_breaker_1 = require("@planq-network/identity/lib/odis/circuit-breaker");
var query_1 = require("@planq-network/identity/lib/odis/query");
var sign_typed_data_utils_1 = require("@planq-network/utils/lib/sign-typed-data-utils");
var ComputationalHardeningFunction;
(function (ComputationalHardeningFunction) {
ComputationalHardeningFunction["PBKDF"] = "pbkdf2_sha256";
ComputationalHardeningFunction["SCRYPT"] = "scrypt";
})(ComputationalHardeningFunction = exports.ComputationalHardeningFunction || (exports.ComputationalHardeningFunction = {}));
/**
* ODIS SequentialDelayDomain rate limit configured to be appropriate for hardening a 6-digit PIN.
*
* @remarks Because PINs have very little entropy, the total number of guesses is very restricted.
* * On the first day, the client has 10 attempts. 5 within 10s. 5 more over roughly 45 minutes.
* * On the second day, the client has 5 attempts over roughly 2 minutes.
* * On the third day, the client has 3 attempts over roughly 40 seconds.
* * On the fourth day, the client has 2 attempts over roughly 10 seconds.
* * Overall, the client has 20 attempts over 4 days. All further attempts will be denied.
*/
var PIN_HARDENING_RATE_LIMIT = [
// First stage is setup, as the user will need to make a single query to create their backup.
{
delay: 0,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(1),
repetitions: sign_typed_data_utils_1.noNumber,
},
// On the first day, the client has 10 attempts. 5 within 10s. 5 more over roughly 45 minutes.
{
delay: 0,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(3),
repetitions: sign_typed_data_utils_1.noNumber,
},
{
delay: 10,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(2),
repetitions: sign_typed_data_utils_1.noNumber,
},
{
delay: 30,
resetTimer: (0, sign_typed_data_utils_1.defined)(false),
batchSize: (0, sign_typed_data_utils_1.defined)(1),
repetitions: sign_typed_data_utils_1.noNumber,
},
{
delay: 60,
resetTimer: (0, sign_typed_data_utils_1.defined)(false),
batchSize: (0, sign_typed_data_utils_1.defined)(1),
repetitions: sign_typed_data_utils_1.noNumber,
},
{
delay: 300,
resetTimer: (0, sign_typed_data_utils_1.defined)(false),
batchSize: (0, sign_typed_data_utils_1.defined)(1),
repetitions: sign_typed_data_utils_1.noNumber,
},
{
delay: 900,
resetTimer: (0, sign_typed_data_utils_1.defined)(false),
batchSize: (0, sign_typed_data_utils_1.defined)(1),
repetitions: sign_typed_data_utils_1.noNumber,
},
{
delay: 1800,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(1),
repetitions: sign_typed_data_utils_1.noNumber,
},
// On the second day, the client has 5 attempts over roughly 2 minutes.
{
delay: 86400,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(2),
repetitions: sign_typed_data_utils_1.noNumber,
},
{
delay: 10,
resetTimer: (0, sign_typed_data_utils_1.defined)(false),
batchSize: (0, sign_typed_data_utils_1.defined)(1),
repetitions: sign_typed_data_utils_1.noNumber,
},
{
delay: 30,
resetTimer: (0, sign_typed_data_utils_1.defined)(false),
batchSize: (0, sign_typed_data_utils_1.defined)(1),
repetitions: sign_typed_data_utils_1.noNumber,
},
{
delay: 60,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(1),
repetitions: sign_typed_data_utils_1.noNumber,
},
// On the third day, the client has 3 attempts over roughly 40 seconds.
{
delay: 86400,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(1),
repetitions: sign_typed_data_utils_1.noNumber,
},
{
delay: 10,
resetTimer: (0, sign_typed_data_utils_1.defined)(false),
batchSize: (0, sign_typed_data_utils_1.defined)(1),
repetitions: sign_typed_data_utils_1.noNumber,
},
{
delay: 30,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(1),
repetitions: sign_typed_data_utils_1.noNumber,
},
// On the fourth day, the client has 2 attempts over roughly 10 seconds.
{
delay: 86400,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(1),
repetitions: sign_typed_data_utils_1.noNumber,
},
{
delay: 10,
resetTimer: (0, sign_typed_data_utils_1.defined)(false),
batchSize: (0, sign_typed_data_utils_1.defined)(1),
repetitions: sign_typed_data_utils_1.noNumber,
},
];
/**
* ODIS SequentialDelayDomain rate limit configured to be appropriate for hardening a password.
*
* @remarks Because passwords have moderate entropy, the total number of guesses is restricted.
* * The user initially gets 5 attempts without delay.
* * Then the user gets two attempts every 5 seconds for up to 20 attempts.
* * Then the user gets two attempts every 30 seconds for up to 20 attempts.
* * Then the user gets two attempts every 5 minutes for up to 20 attempts.
* * Then the user gets two attempts every hour for up to 20 attempts.
* * Then the user gets two attempts every day for up to 20 attempts.
*/
var PASSWORD_HARDENING_RATE_LIMIT = [
// First stage is setup, as the user will need to make a single query to create their backup.
{
delay: 0,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(1),
repetitions: sign_typed_data_utils_1.noNumber,
},
// After the first 5 attempts, the user has 100 attempts with the delays increasing every 20.
{
delay: 0,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(5),
repetitions: sign_typed_data_utils_1.noNumber,
},
{
delay: 5,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(2),
repetitions: (0, sign_typed_data_utils_1.defined)(10),
},
{
delay: 30,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(2),
repetitions: (0, sign_typed_data_utils_1.defined)(10),
},
{
delay: 300,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(2),
repetitions: (0, sign_typed_data_utils_1.defined)(10),
},
{
delay: 3600,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(2),
repetitions: (0, sign_typed_data_utils_1.defined)(10),
},
{
delay: 86400,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(2),
repetitions: (0, sign_typed_data_utils_1.defined)(10),
},
];
/**
* ODIS SequentialDelayDomain rate limit configured for e2e testing where no rate limit should be applied.
*
* @remarks This should only be used testing purposes
*/
var E2E_TESTING_RATE_LIMIT = [
{
delay: 0,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(1000000000),
repetitions: (0, sign_typed_data_utils_1.defined)(1000000000),
},
];
/**
* ODIS SequentialDelayDomain rate limit configured for e2e testing where the user should have no quota.
*
* @remarks This should only be used testing purposes
*/
var NO_QUOTA_RATE_LIMIT = [
{
delay: 0,
resetTimer: (0, sign_typed_data_utils_1.defined)(true),
batchSize: (0, sign_typed_data_utils_1.defined)(0),
repetitions: (0, sign_typed_data_utils_1.defined)(0),
},
];
var EnvironmentIdentifier;
(function (EnvironmentIdentifier) {
EnvironmentIdentifier["MAINNET"] = "MAINNET";
EnvironmentIdentifier["ALFAJORES"] = "ALFAJORES";
})(EnvironmentIdentifier = exports.EnvironmentIdentifier || (exports.EnvironmentIdentifier = {}));
exports.PIN_HARDENING_MAINNET_CONFIG = {
odis: {
rateLimit: PIN_HARDENING_RATE_LIMIT,
environment: query_1.ODIS_MAINNET_CONTEXT_DOMAINS,
},
circuitBreaker: {
environment: circuit_breaker_1.VALORA_MAINNET_CIRCUIT_BREAKER_ENVIRONMENT,
},
};
exports.PIN_HARDENING_ALFAJORES_CONFIG = {
odis: {
rateLimit: PIN_HARDENING_RATE_LIMIT,
environment: query_1.ODIS_ALFAJORES_CONTEXT_DOMAINS,
},
circuitBreaker: {
environment: circuit_breaker_1.VALORA_ALFAJORES_CIRCUIT_BREAKER_ENVIRONMENT,
},
};
exports.PASSWORD_HARDENING_MAINNET_CONFIG = {
odis: {
rateLimit: PASSWORD_HARDENING_RATE_LIMIT,
environment: query_1.ODIS_MAINNET_CONTEXT_DOMAINS,
},
computational: {
function: ComputationalHardeningFunction.SCRYPT,
cost: 32768,
blockSize: 8,
parallelization: 1,
},
};
exports.E2E_TESTING_MAINNET_CONFIG = {
odis: {
rateLimit: E2E_TESTING_RATE_LIMIT,
environment: query_1.ODIS_MAINNET_CONTEXT_DOMAINS,
},
computational: {
function: ComputationalHardeningFunction.SCRYPT,
cost: 32768,
blockSize: 8,
parallelization: 1,
},
};
exports.NO_QUOTA_MAINNET_CONFIG = {
odis: {
rateLimit: NO_QUOTA_RATE_LIMIT,
environment: query_1.ODIS_MAINNET_CONTEXT_DOMAINS,
},
computational: {
function: ComputationalHardeningFunction.SCRYPT,
cost: 32768,
blockSize: 8,
parallelization: 1,
},
};
exports.PASSWORD_HARDENING_ALFAJORES_CONFIG = {
odis: {
rateLimit: PASSWORD_HARDENING_RATE_LIMIT,
environment: query_1.ODIS_ALFAJORES_CONTEXT_DOMAINS,
},
computational: {
function: ComputationalHardeningFunction.SCRYPT,
cost: 32768,
blockSize: 8,
parallelization: 1,
},
};
exports.E2E_TESTING_ALFAJORES_CONFIG = {
odis: {
rateLimit: E2E_TESTING_RATE_LIMIT,
environment: query_1.ODIS_ALFAJORES_CONTEXT_DOMAINS,
},
computational: {
function: ComputationalHardeningFunction.SCRYPT,
cost: 32768,
blockSize: 8,
parallelization: 1,
},
};
exports.NO_QUOTA_ALFAJORES_CONFIG = {
odis: {
rateLimit: NO_QUOTA_RATE_LIMIT,
environment: query_1.ODIS_ALFAJORES_CONTEXT_DOMAINS,
},
computational: {
function: ComputationalHardeningFunction.SCRYPT,
cost: 32768,
blockSize: 8,
parallelization: 1,
},
};
//# sourceMappingURL=config.js.map