Extract isArgon2idOptions

This commit is contained in:
Simon Warta
2020-07-28 13:16:08 +02:00
parent ef7d171a64
commit a1b86ade81
5 changed files with 15 additions and 7 deletions
+1
View File
@@ -8,6 +8,7 @@ export {
xchacha20NonceLength,
Argon2id,
Argon2idOptions,
isArgon2idOptions,
Ed25519,
Ed25519Keypair,
} from "./libsodium";
+9
View File
@@ -3,6 +3,7 @@
//
// libsodium.js API: https://gist.github.com/webmaster128/b2dbe6d54d36dd168c9fabf441b9b09c
import { isNonNullObject } from "@cosmjs/utils";
import sodium from "libsodium-wrappers";
export interface Argon2idOptions {
@@ -24,6 +25,14 @@ export interface Argon2idOptions {
readonly memLimitKib: number;
}
export function isArgon2idOptions(thing: unknown): thing is Argon2idOptions {
if (!isNonNullObject(thing)) return false;
if (typeof (thing as Argon2idOptions).outputLength !== "number") return false;
if (typeof (thing as Argon2idOptions).opsLimit !== "number") return false;
if (typeof (thing as Argon2idOptions).memLimitKib !== "number") return false;
return true;
}
export class Argon2id {
public static async execute(
password: string,