pqbox 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +380 -2
- package/dist/generated/pqbox_wasm.d.ts +214 -0
- package/dist/generated/pqbox_wasm.js +921 -0
- package/dist/generated/wasm-bytes.d.ts +2 -0
- package/dist/generated/wasm-bytes.js +2 -0
- package/dist/index.d.ts +141 -0
- package/dist/index.js +205 -0
- package/package.json +44 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/** Every suite, by name. */
|
|
2
|
+
export declare const SUITES: readonly ["xwing", "pqbox-max", "pqbox-paranoid"];
|
|
3
|
+
/** A cipher suite name. `xwing` is for compatibility only; `pqbox-max` is the default. */
|
|
4
|
+
export type Suite = (typeof SUITES)[number];
|
|
5
|
+
/** The default suite: ML-KEM-1024 + ECDH P-384, ML-DSA-87 + ECDSA P-384. */
|
|
6
|
+
export declare const DEFAULT_SUITE: Suite;
|
|
7
|
+
/** AEAD algorithm names. */
|
|
8
|
+
export type AeadAlgorithm = "xchacha20poly1305" | "aes256gcm";
|
|
9
|
+
/** Hash algorithm names. */
|
|
10
|
+
export type HashAlgorithm = "sha256" | "sha3-256" | "blake3";
|
|
11
|
+
/** Machine-readable error codes (the Rust `Error::code()` values). */
|
|
12
|
+
export type ErrorCode = "BadMagic" | "UnsupportedVersion" | "UnknownKind" | "UnknownSuite" | "SuiteNotEnabled" | "SuiteNotAllowed" | "SuiteMismatch" | "WrongKind" | "InvalidLength" | "InvalidKey" | "Decrypt" | "BadSignature" | "InvalidParams" | "InvalidPasswordHash" | "PasswordMismatch" | "Internal";
|
|
13
|
+
/** Every error raised by pqbox. `code` is stable; `message` is for humans. */
|
|
14
|
+
export declare class PqboxError extends Error {
|
|
15
|
+
readonly code: ErrorCode;
|
|
16
|
+
constructor(code: ErrorCode, message: string);
|
|
17
|
+
}
|
|
18
|
+
/** Largest HKDF-SHA-256 output, in bytes (255 blocks of 32). */
|
|
19
|
+
export declare const HKDF_MAX_LENGTH = 8160;
|
|
20
|
+
/** The `allowSuites` option of the functions that read pqbox objects. */
|
|
21
|
+
export interface SuiteOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Suites accepted in addition to `pqbox-max`, which is always accepted. By default only
|
|
24
|
+
* `pqbox-max` objects are read; `xwing` and `pqbox-paranoid` must be listed here.
|
|
25
|
+
*/
|
|
26
|
+
allowSuites?: readonly Suite[];
|
|
27
|
+
}
|
|
28
|
+
/** A key pair: both halves serialized with the `PQB` header. */
|
|
29
|
+
export interface KeyPair {
|
|
30
|
+
publicKey: Uint8Array;
|
|
31
|
+
secretKey: Uint8Array;
|
|
32
|
+
}
|
|
33
|
+
/** The result of a KEM encapsulation. */
|
|
34
|
+
export interface Encapsulation {
|
|
35
|
+
ciphertext: Uint8Array;
|
|
36
|
+
sharedSecret: Uint8Array;
|
|
37
|
+
}
|
|
38
|
+
/** The library version. */
|
|
39
|
+
export declare function version(): string;
|
|
40
|
+
/** Generates a KEM key pair (`pqbox-paranoid` takes seconds: Classic McEliece key generation). */
|
|
41
|
+
export declare function kemKeygen(suite?: Suite): KeyPair;
|
|
42
|
+
/** Encapsulates a fresh 32-byte shared secret to a KEM public key. */
|
|
43
|
+
export declare function kemEncapsulate(publicKey: Uint8Array, options?: SuiteOptions): Encapsulation;
|
|
44
|
+
/** Recovers the shared secret from a KEM ciphertext. */
|
|
45
|
+
export declare function kemDecapsulate(secretKey: Uint8Array, ciphertext: Uint8Array, options?: SuiteOptions): Uint8Array;
|
|
46
|
+
/** Generates a composite signing key pair. */
|
|
47
|
+
export declare function signKeygen(suite?: Suite): KeyPair;
|
|
48
|
+
/** Signs a message with every component of the key's suite. */
|
|
49
|
+
export declare function sign(secretKey: Uint8Array, message: Uint8Array, options?: SuiteOptions): Uint8Array;
|
|
50
|
+
/**
|
|
51
|
+
* Verifies a composite signature. Returns `false` when any component fails; throws
|
|
52
|
+
* `PqboxError` for malformed input, a suite mismatch or a suite that is not allowed. Signatures
|
|
53
|
+
* are strongly unforgeable: the ECDSA P-384 half must be low-S.
|
|
54
|
+
*/
|
|
55
|
+
export declare function verify(publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array, options?: SuiteOptions): boolean;
|
|
56
|
+
/** Seals a message to a KEM public key (anonymous sender). */
|
|
57
|
+
export declare function seal(publicKey: Uint8Array, plaintext: Uint8Array, options?: SuiteOptions): Uint8Array;
|
|
58
|
+
/** Opens a sealed box with the recipient's KEM secret key. */
|
|
59
|
+
export declare function open(secretKey: Uint8Array, sealed: Uint8Array, options?: SuiteOptions): Uint8Array;
|
|
60
|
+
/** A fresh random 32-byte AEAD key. */
|
|
61
|
+
export declare function generateKey(): Uint8Array;
|
|
62
|
+
/** Options of {@link encrypt}. */
|
|
63
|
+
export interface EncryptOptions {
|
|
64
|
+
aad?: Uint8Array;
|
|
65
|
+
algorithm?: AeadAlgorithm;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Authenticated encryption with a random nonce (XChaCha20-Poly1305 by default).
|
|
69
|
+
*
|
|
70
|
+
* With `aes256gcm` the nonce is 96 random bits: encrypt at most about 2^32 messages under one key
|
|
71
|
+
* (NIST SP 800-38D), then rotate it. XChaCha20-Poly1305 has a 192-bit nonce and no practical
|
|
72
|
+
* limit; prefer it for long-lived keys.
|
|
73
|
+
*/
|
|
74
|
+
export declare function encrypt(key: Uint8Array, plaintext: Uint8Array, options?: EncryptOptions): Uint8Array;
|
|
75
|
+
/** Options of {@link decrypt}. */
|
|
76
|
+
export interface DecryptOptions {
|
|
77
|
+
aad?: Uint8Array;
|
|
78
|
+
}
|
|
79
|
+
/** Decrypts the output of {@link encrypt}; the algorithm is read from the header. */
|
|
80
|
+
export declare function decrypt(key: Uint8Array, data: Uint8Array, options?: DecryptOptions): Uint8Array;
|
|
81
|
+
/** Options of {@link hkdfSha256}. */
|
|
82
|
+
export interface HkdfOptions {
|
|
83
|
+
salt?: Uint8Array;
|
|
84
|
+
info?: Uint8Array;
|
|
85
|
+
/**
|
|
86
|
+
* Output length in bytes: an integer from 0 to {@link HKDF_MAX_LENGTH} (8160), 32 by default.
|
|
87
|
+
* Anything else throws `PqboxError` (`InvalidParams`) before any memory is allocated.
|
|
88
|
+
*/
|
|
89
|
+
length?: number;
|
|
90
|
+
}
|
|
91
|
+
/** HKDF-SHA-256 (RFC 5869). */
|
|
92
|
+
export declare function hkdfSha256(ikm: Uint8Array, options?: HkdfOptions): Uint8Array;
|
|
93
|
+
/** HMAC-SHA-256. */
|
|
94
|
+
export declare function hmacSha256(key: Uint8Array, message: Uint8Array): Uint8Array;
|
|
95
|
+
/** Checks an HMAC-SHA-256 tag in constant time. */
|
|
96
|
+
export declare function hmacSha256Verify(key: Uint8Array, message: Uint8Array, tag: Uint8Array): boolean;
|
|
97
|
+
/** SHA-256. */
|
|
98
|
+
export declare function sha256(data: Uint8Array): Uint8Array;
|
|
99
|
+
/** SHA3-256. */
|
|
100
|
+
export declare function sha3_256(data: Uint8Array): Uint8Array;
|
|
101
|
+
/** BLAKE3 (32-byte output). */
|
|
102
|
+
export declare function blake3(data: Uint8Array): Uint8Array;
|
|
103
|
+
/** Hashes with a named algorithm (SHA-256 by default). */
|
|
104
|
+
export declare function hash(data: Uint8Array, algorithm?: HashAlgorithm): Uint8Array;
|
|
105
|
+
/**
|
|
106
|
+
* Default upper bounds on the Argon2id costs {@link passwordHash} and {@link passwordVerify}
|
|
107
|
+
* accept: 256 MiB (in KiB), 10 passes, 8 lanes. A PHC string's costs come from whoever wrote it,
|
|
108
|
+
* so they are checked before any memory is allocated.
|
|
109
|
+
*/
|
|
110
|
+
export declare const PASSWORD_LIMITS: Readonly<{
|
|
111
|
+
maxMCost: 262144;
|
|
112
|
+
maxTCost: 10;
|
|
113
|
+
maxPCost: 8;
|
|
114
|
+
}>;
|
|
115
|
+
/** Argon2id costs. Defaults: 64 MiB, 3 passes, 1 lane; at most 256 MiB, 10 passes, 8 lanes. */
|
|
116
|
+
export interface PasswordHashOptions {
|
|
117
|
+
/** Memory in KiB. */
|
|
118
|
+
mCost?: number;
|
|
119
|
+
tCost?: number;
|
|
120
|
+
pCost?: number;
|
|
121
|
+
}
|
|
122
|
+
/** Hashes a password with Argon2id; returns a PHC string. Strings are UTF-8 encoded. */
|
|
123
|
+
export declare function passwordHash(password: string | Uint8Array, options?: PasswordHashOptions): string;
|
|
124
|
+
/**
|
|
125
|
+
* Cost limits of {@link passwordVerify}, {@link PASSWORD_LIMITS} by default. Raise them only for
|
|
126
|
+
* PHC strings from a trusted source: at the limits, one verification uses 256 MiB and about a
|
|
127
|
+
* second of CPU.
|
|
128
|
+
*/
|
|
129
|
+
export interface PasswordVerifyOptions {
|
|
130
|
+
/** Largest memory cost accepted, in KiB. */
|
|
131
|
+
maxMCost?: number;
|
|
132
|
+
/** Largest number of passes accepted. */
|
|
133
|
+
maxTCost?: number;
|
|
134
|
+
/** Largest number of lanes accepted. */
|
|
135
|
+
maxPCost?: number;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Checks a password against a PHC string: `false` on mismatch, throws `PqboxError`
|
|
139
|
+
* (`InvalidPasswordHash`) for an invalid string or one whose costs exceed the limits.
|
|
140
|
+
*/
|
|
141
|
+
export declare function passwordVerify(password: string | Uint8Array, phc: string, options?: PasswordVerifyOptions): boolean;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pqbox: a post-quantum crypto toolkit compiled from Rust to WebAssembly.
|
|
3
|
+
*
|
|
4
|
+
* Every function is synchronous: the WebAssembly module is embedded and instantiated when this
|
|
5
|
+
* module is imported. Binary values are `Uint8Array`s; serialized keys, ciphertexts, signatures
|
|
6
|
+
* and sealed boxes carry pqbox's versioned `PQB` header and are interchangeable with the Rust
|
|
7
|
+
* crate, the Python package and the CLI.
|
|
8
|
+
*
|
|
9
|
+
* Suite policy: the functions that read keys, ciphertexts, signatures or sealed boxes accept
|
|
10
|
+
* `pqbox-max` objects only, unless other suites are listed in their `allowSuites` option; anything
|
|
11
|
+
* else throws a `PqboxError` with code `SuiteNotAllowed`. `xwing` is for compatibility;
|
|
12
|
+
* `pqbox-paranoid` relies on SLH-DSA from a release-candidate crate and is experimental.
|
|
13
|
+
*
|
|
14
|
+
* Secrets handed to or returned by JavaScript live in the JavaScript heap, which cannot be wiped
|
|
15
|
+
* reliably; see THREAT_MODEL.md.
|
|
16
|
+
*/
|
|
17
|
+
import * as wasm from "./generated/pqbox_wasm.js";
|
|
18
|
+
import wasmBase64 from "./generated/wasm-bytes.js";
|
|
19
|
+
function decodeBase64(b64) {
|
|
20
|
+
const bin = atob(b64);
|
|
21
|
+
const out = new Uint8Array(bin.length);
|
|
22
|
+
for (let i = 0; i < bin.length; i++)
|
|
23
|
+
out[i] = bin.charCodeAt(i);
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
wasm.initSync({ module: decodeBase64(wasmBase64) });
|
|
27
|
+
/** Every suite, by name. */
|
|
28
|
+
export const SUITES = ["xwing", "pqbox-max", "pqbox-paranoid"];
|
|
29
|
+
/** The default suite: ML-KEM-1024 + ECDH P-384, ML-DSA-87 + ECDSA P-384. */
|
|
30
|
+
export const DEFAULT_SUITE = "pqbox-max";
|
|
31
|
+
/** Every error raised by pqbox. `code` is stable; `message` is for humans. */
|
|
32
|
+
export class PqboxError extends Error {
|
|
33
|
+
code;
|
|
34
|
+
constructor(code, message) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = "PqboxError";
|
|
37
|
+
this.code = code;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function call(f) {
|
|
41
|
+
try {
|
|
42
|
+
return f();
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
if (e instanceof PqboxError)
|
|
46
|
+
throw e;
|
|
47
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
48
|
+
const sep = msg.indexOf(": ");
|
|
49
|
+
const code = (sep > 0 ? msg.slice(0, sep) : "Internal");
|
|
50
|
+
throw new PqboxError(code, sep > 0 ? msg.slice(sep + 2) : msg);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** Largest HKDF-SHA-256 output, in bytes (255 blocks of 32). */
|
|
54
|
+
export const HKDF_MAX_LENGTH = 8160;
|
|
55
|
+
/**
|
|
56
|
+
* Checks that a numeric option is an integer in `0..=max` before it reaches WebAssembly, where a
|
|
57
|
+
* negative or fractional number would otherwise be converted to a huge unsigned integer.
|
|
58
|
+
*/
|
|
59
|
+
function intOption(value, fallback, max, what) {
|
|
60
|
+
const v = value ?? fallback;
|
|
61
|
+
if (typeof v !== "number" || !Number.isInteger(v) || v < 0 || v > max) {
|
|
62
|
+
throw new PqboxError("InvalidParams", `invalid parameter: ${what}`);
|
|
63
|
+
}
|
|
64
|
+
return v;
|
|
65
|
+
}
|
|
66
|
+
const utf8 = new TextEncoder();
|
|
67
|
+
/**
|
|
68
|
+
* Runs `f` on the bytes of a password. A string is UTF-8 encoded into a temporary buffer that is
|
|
69
|
+
* overwritten with zeros afterwards (a caller's `Uint8Array` is left alone).
|
|
70
|
+
*/
|
|
71
|
+
function withPassword(password, f) {
|
|
72
|
+
if (typeof password !== "string")
|
|
73
|
+
return f(password);
|
|
74
|
+
const pw = utf8.encode(password);
|
|
75
|
+
try {
|
|
76
|
+
return f(pw);
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
pw.fill(0);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function allowed(options) {
|
|
83
|
+
const list = options.allowSuites ?? [];
|
|
84
|
+
if (!Array.isArray(list) || !list.every((s) => typeof s === "string")) {
|
|
85
|
+
throw new PqboxError("InvalidParams", "invalid parameter: allowSuites must be an array of suite names");
|
|
86
|
+
}
|
|
87
|
+
return [...list];
|
|
88
|
+
}
|
|
89
|
+
/** The library version. */
|
|
90
|
+
export function version() {
|
|
91
|
+
return wasm.version();
|
|
92
|
+
}
|
|
93
|
+
/** Generates a KEM key pair (`pqbox-paranoid` takes seconds: Classic McEliece key generation). */
|
|
94
|
+
export function kemKeygen(suite = DEFAULT_SUITE) {
|
|
95
|
+
return call(() => wasm.kemKeygen(suite));
|
|
96
|
+
}
|
|
97
|
+
/** Encapsulates a fresh 32-byte shared secret to a KEM public key. */
|
|
98
|
+
export function kemEncapsulate(publicKey, options = {}) {
|
|
99
|
+
const allow = allowed(options);
|
|
100
|
+
return call(() => wasm.kemEncapsulate(publicKey, allow));
|
|
101
|
+
}
|
|
102
|
+
/** Recovers the shared secret from a KEM ciphertext. */
|
|
103
|
+
export function kemDecapsulate(secretKey, ciphertext, options = {}) {
|
|
104
|
+
const allow = allowed(options);
|
|
105
|
+
return call(() => wasm.kemDecapsulate(secretKey, ciphertext, allow));
|
|
106
|
+
}
|
|
107
|
+
/** Generates a composite signing key pair. */
|
|
108
|
+
export function signKeygen(suite = DEFAULT_SUITE) {
|
|
109
|
+
return call(() => wasm.signKeygen(suite));
|
|
110
|
+
}
|
|
111
|
+
/** Signs a message with every component of the key's suite. */
|
|
112
|
+
export function sign(secretKey, message, options = {}) {
|
|
113
|
+
const allow = allowed(options);
|
|
114
|
+
return call(() => wasm.sign(secretKey, message, allow));
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Verifies a composite signature. Returns `false` when any component fails; throws
|
|
118
|
+
* `PqboxError` for malformed input, a suite mismatch or a suite that is not allowed. Signatures
|
|
119
|
+
* are strongly unforgeable: the ECDSA P-384 half must be low-S.
|
|
120
|
+
*/
|
|
121
|
+
export function verify(publicKey, message, signature, options = {}) {
|
|
122
|
+
const allow = allowed(options);
|
|
123
|
+
return call(() => wasm.verify(publicKey, message, signature, allow));
|
|
124
|
+
}
|
|
125
|
+
/** Seals a message to a KEM public key (anonymous sender). */
|
|
126
|
+
export function seal(publicKey, plaintext, options = {}) {
|
|
127
|
+
const allow = allowed(options);
|
|
128
|
+
return call(() => wasm.seal(publicKey, plaintext, allow));
|
|
129
|
+
}
|
|
130
|
+
/** Opens a sealed box with the recipient's KEM secret key. */
|
|
131
|
+
export function open(secretKey, sealed, options = {}) {
|
|
132
|
+
const allow = allowed(options);
|
|
133
|
+
return call(() => wasm.open(secretKey, sealed, allow));
|
|
134
|
+
}
|
|
135
|
+
/** A fresh random 32-byte AEAD key. */
|
|
136
|
+
export function generateKey() {
|
|
137
|
+
return wasm.generateKey();
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Authenticated encryption with a random nonce (XChaCha20-Poly1305 by default).
|
|
141
|
+
*
|
|
142
|
+
* With `aes256gcm` the nonce is 96 random bits: encrypt at most about 2^32 messages under one key
|
|
143
|
+
* (NIST SP 800-38D), then rotate it. XChaCha20-Poly1305 has a 192-bit nonce and no practical
|
|
144
|
+
* limit; prefer it for long-lived keys.
|
|
145
|
+
*/
|
|
146
|
+
export function encrypt(key, plaintext, options = {}) {
|
|
147
|
+
return call(() => wasm.encrypt(key, plaintext, options.aad ?? new Uint8Array(), options.algorithm ?? "xchacha20poly1305"));
|
|
148
|
+
}
|
|
149
|
+
/** Decrypts the output of {@link encrypt}; the algorithm is read from the header. */
|
|
150
|
+
export function decrypt(key, data, options = {}) {
|
|
151
|
+
return call(() => wasm.decrypt(key, data, options.aad ?? new Uint8Array()));
|
|
152
|
+
}
|
|
153
|
+
/** HKDF-SHA-256 (RFC 5869). */
|
|
154
|
+
export function hkdfSha256(ikm, options = {}) {
|
|
155
|
+
const length = intOption(options.length, 32, HKDF_MAX_LENGTH, "HKDF output too long");
|
|
156
|
+
return call(() => wasm.hkdfSha256(ikm, options.salt ?? new Uint8Array(), options.info ?? new Uint8Array(), length));
|
|
157
|
+
}
|
|
158
|
+
/** HMAC-SHA-256. */
|
|
159
|
+
export function hmacSha256(key, message) {
|
|
160
|
+
return call(() => wasm.hmacSha256(key, message));
|
|
161
|
+
}
|
|
162
|
+
/** Checks an HMAC-SHA-256 tag in constant time. */
|
|
163
|
+
export function hmacSha256Verify(key, message, tag) {
|
|
164
|
+
return wasm.hmacSha256Verify(key, message, tag);
|
|
165
|
+
}
|
|
166
|
+
/** SHA-256. */
|
|
167
|
+
export function sha256(data) {
|
|
168
|
+
return wasm.sha256(data);
|
|
169
|
+
}
|
|
170
|
+
/** SHA3-256. */
|
|
171
|
+
export function sha3_256(data) {
|
|
172
|
+
return wasm.sha3_256(data);
|
|
173
|
+
}
|
|
174
|
+
/** BLAKE3 (32-byte output). */
|
|
175
|
+
export function blake3(data) {
|
|
176
|
+
return wasm.blake3(data);
|
|
177
|
+
}
|
|
178
|
+
/** Hashes with a named algorithm (SHA-256 by default). */
|
|
179
|
+
export function hash(data, algorithm = "sha256") {
|
|
180
|
+
return call(() => wasm.hash(data, algorithm));
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Default upper bounds on the Argon2id costs {@link passwordHash} and {@link passwordVerify}
|
|
184
|
+
* accept: 256 MiB (in KiB), 10 passes, 8 lanes. A PHC string's costs come from whoever wrote it,
|
|
185
|
+
* so they are checked before any memory is allocated.
|
|
186
|
+
*/
|
|
187
|
+
export const PASSWORD_LIMITS = Object.freeze({ maxMCost: 262144, maxTCost: 10, maxPCost: 8 });
|
|
188
|
+
const U32_MAX = 0xffffffff;
|
|
189
|
+
/** Hashes a password with Argon2id; returns a PHC string. Strings are UTF-8 encoded. */
|
|
190
|
+
export function passwordHash(password, options = {}) {
|
|
191
|
+
const m = intOption(options.mCost, 65536, U32_MAX, "Argon2 m_cost out of range");
|
|
192
|
+
const t = intOption(options.tCost, 3, U32_MAX, "Argon2 t_cost out of range");
|
|
193
|
+
const p = intOption(options.pCost, 1, U32_MAX, "Argon2 p_cost out of range");
|
|
194
|
+
return call(() => withPassword(password, (pw) => wasm.passwordHash(pw, m, t, p)));
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Checks a password against a PHC string: `false` on mismatch, throws `PqboxError`
|
|
198
|
+
* (`InvalidPasswordHash`) for an invalid string or one whose costs exceed the limits.
|
|
199
|
+
*/
|
|
200
|
+
export function passwordVerify(password, phc, options = {}) {
|
|
201
|
+
const m = intOption(options.maxMCost, PASSWORD_LIMITS.maxMCost, U32_MAX, "Argon2 maxMCost out of range");
|
|
202
|
+
const t = intOption(options.maxTCost, PASSWORD_LIMITS.maxTCost, U32_MAX, "Argon2 maxTCost out of range");
|
|
203
|
+
const p = intOption(options.maxPCost, PASSWORD_LIMITS.maxPCost, U32_MAX, "Argon2 maxPCost out of range");
|
|
204
|
+
return call(() => withPassword(password, (pw) => wasm.passwordVerify(pw, phc, m, t, p)));
|
|
205
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pqbox",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Post-quantum crypto toolkit (ML-KEM, ML-DSA, SLH-DSA, Classic McEliece hybrids, sealed boxes, AEAD, KDF, hashing, Argon2id) compiled from Rust to WebAssembly",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "maxgfr",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/maxgfr/pqbox.git",
|
|
10
|
+
"directory": "packages/pqbox-js"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/maxgfr/pqbox#readme",
|
|
13
|
+
"keywords": ["post-quantum", "crypto", "ml-kem", "ml-dsa", "slh-dsa", "x-wing", "sealed-box", "wasm"],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=20"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build:wasm": "node scripts/build-wasm.mjs",
|
|
32
|
+
"build": "npm run build:wasm && tsc -p tsconfig.build.json && node scripts/copy-generated.mjs",
|
|
33
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
34
|
+
"prepack": "node scripts/copy-docs.mjs",
|
|
35
|
+
"test": "vitest run"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public",
|
|
39
|
+
"provenance": true
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "20.19.43",
|
|
43
|
+
"typescript": "5.9.3",
|
|
44
|
+
"vitest": "4.1.12"
|
|
45
|
+
}
|
|
46
|
+
}
|