@whi/argon2-wasm 0.4.0 → 0.5.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 ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2020 Matthew Brisebois <matthew@webheroes.ca>
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,109 +1,113 @@
1
-
2
1
  # Argon2 Wasm
3
2
  ![](https://img.shields.io/npm/v/@whi/argon2-wasm/latest?style=flat-square)
4
3
 
5
- ## Usage
4
+ Wasm bindings for Argon2 with all inputs exposed — password, salt, `secret` (the
5
+ keyed input `K`, e.g. a pepper), and `associated_data` (`X`). Backed by the
6
+ RustCrypto [`argon2`](https://crates.io/crates/argon2) crate.
7
+
8
+ Output is a raw Argon2 hash, version `0x13` (v=19), fixed at 64 bytes. Inputs are
9
+ byte arrays (`Buffer` / `Uint8Array`).
10
+
11
+ ## Install
6
12
 
7
- ### Node examples
13
+ ```
14
+ npm install @whi/argon2-wasm
15
+ ```
16
+
17
+ ## Usage
8
18
 
9
- #### Hash only
19
+ ### Node (CommonJS)
10
20
 
11
21
  ```js
12
22
  const crypto = require('crypto');
13
23
  const { argon2, verify, HashType } = require('@whi/argon2-wasm');
14
24
 
15
- const password = Buffer.from("password");
16
- const salt = crypto.randomBytes( 64 );
17
- const pepper = crypto.randomBytes( 32 );
25
+ const password = Buffer.from("password");
26
+ const salt = crypto.randomBytes( 16 );
27
+ const secret = crypto.randomBytes( 8 ); // keyed input (K); [] for none
18
28
  const associated_data = new Uint8Array();
19
29
 
20
30
  const hash = Buffer.from( argon2(
21
31
  password,
22
32
  salt,
23
- pepper,
33
+ secret,
24
34
  associated_data,
25
35
  2, // iterations
26
36
  4, // parallelism
27
- 1 << 16, // memory_size
28
- HashType.Argon2id // hash type [ Argon2d, Argon2i, Argon2id ]
37
+ 1 << 8, // memory_size (KiB), must be >= 8 * parallelism
38
+ HashType.Argon2id, // Argon2d | Argon2i | Argon2id
29
39
  ));
30
40
 
31
41
  console.log( hash.toString('base64') );
32
- // nG5bVu8lDIwzi4pRJWYV9xglUiGH6rBESgbBP+Ol24aCZX81SmMJk2/gUl1OO8EGDjHeRPnqSYhunAlzekeTyQ==
33
42
 
34
43
  verify(
35
44
  hash,
36
45
  password,
37
46
  salt,
38
- pepper,
47
+ secret,
39
48
  associated_data,
40
- 2, // iterations
41
- 4, // parallelism
42
- 1 << 16, // memory_size
43
- HashType.Argon2id // hash type [ Argon2d, Argon2i, Argon2id ]
44
- ));
49
+ 2, 4, 1 << 8, HashType.Argon2id,
50
+ );
45
51
  // returns true
46
52
  ```
47
53
 
48
- #### Config encoded in result
54
+ ### Bundlers and Cloudflare Workers (ESM)
49
55
 
50
56
  ```js
51
- const crypto = require('crypto');
52
- const { argon2Encoded, verifyEncoded, HashType } = require('@whi/argon2-wasm');
57
+ import { argon2, verify, HashType } from '@whi/argon2-wasm';
58
+ ```
53
59
 
54
- const password = Buffer.from("password");
55
- const salt = crypto.randomBytes( 64 );
56
- const pepper = crypto.randomBytes( 32 );
57
- const associated_data = new Uint8Array();
60
+ The package ships both a CommonJS and an ESM build and its `exports` map selects
61
+ the right one automatically: `require` resolves to the CommonJS build for Node,
62
+ `import` resolves to the ESM build, which imports the wasm as a module (what
63
+ bundlers and Cloudflare Workers need).
58
64
 
59
- const encoded = Buffer.from( argon2Encoded(
60
- password,
61
- salt,
62
- pepper,
63
- associated_data,
64
- 2, // iterations
65
- 4, // parallelism
66
- 1 << 16, // memory_size
67
- HashType.Argon2id // hash type [ Argon2d, Argon2i, Argon2id ]
68
- ));
65
+ ## API
69
66
 
70
- console.log( hash.toString('base64') );
71
- // JGFyZ29uMmlkJHY9MTksbT02NTUzNix0PTIscD00LGtleWlkPUNrMGhBcXBYZDU1MFVLZExXbmdKRzU4am9PaFJTRXVoYll4MkhyN05vdWckenZsQkZWYSt0akN1Y1l2MTQ2eDREaDduZDN0dytsV0dPTzNodk1Pd2syaDZBT05CY1kxSEpqWUJma2g0VEs5cFRqZFdqWTJ5Z3kxSVNXM21Cd2JZc1EkZUxrS2had1M0dVhrYnA4K0JWdkxQVEZFR1Jyb0ZPOUdyekxtRXhUSEh3dw==
67
+ - **`argon2(password, salt, secret, associated_data, iterations, parallelism, memory_size, hash_type)`** → `Uint8Array`
72
68
 
73
- verifyEncoded( hash, password );
74
- // returns true
75
- ```
69
+ The raw 64-byte Argon2 hash.
76
70
 
77
- ### How to bundle wasm for the web
71
+ - **`verify(hash, password, salt, secret, associated_data, iterations, parallelism, memory_size, hash_type)`** → `boolean`
78
72
 
79
- #### `bootstrap.js`
80
- ```js
81
- import("./index.js")
82
- .then(m => Object.assign(window, m))
83
- .catch(e => console.error("Error importing `index.js`:", e));
84
- ```
73
+ Recomputes the hash from the given inputs and compares it to `hash`.
85
74
 
86
- #### `index.js`
87
- ```js
88
- const { argon2,
89
- verify } = require('@whi/argon2-wasm');
75
+ - **`HashType`** — enum: `Argon2d`, `Argon2i`, `Argon2id`.
90
76
 
91
- module.exports = {
92
- argon2,
93
- verify,
94
- };
95
- ```
77
+ `secret` is Argon2's keyed input `K`; pass an empty array for none. `memory_size`
78
+ is in KiB and must be at least `8 * parallelism`.
96
79
 
97
- #### `webpack.config.js`
98
- ```js
99
- module.exports = {
100
- target: "web",
80
+ ## Development
101
81
 
102
- entry: "./bootstrap.js",
82
+ Requirements: `rustup` (the channel and wasm32 target are pinned in
83
+ `rust-toolchain.toml`), `wasm-pack`, `node` + `npm`, and `jq`.
103
84
 
104
- // Assign 'module.exports' to the window variable
105
- output: {
106
- libraryTarget: "window",
107
- },
108
- };
109
85
  ```
86
+ make test # build the package and run the test suite
87
+ make pkg # build the publishable package into ./pkg
88
+ ```
89
+
90
+ ### Crypto invariant — read before changing the hashing dependency or parameters
91
+
92
+ The output bytes of `argon2()` are a frozen contract. Stored credentials are
93
+ verified by **recomputing** the hash and comparing (`verify()` in `src/lib.rs`),
94
+ so if the output for a given input ever changes, every existing stored credential
95
+ stops validating — a silent, account-wide breakage.
96
+
97
+ `tests/vectors/reference-vectors.json` pins that contract: a corpus of known-answer
98
+ vectors that `tests/unit/test_vectors.js` asserts the build reproduces byte-for-byte.
99
+ These are the canonical bytes stored credentials were created with — originally
100
+ produced by the [`argon2min`](https://github.com/FauxFaux/argon2min) crate that this
101
+ package used before, and reproduced exactly by the current RustCrypto `argon2`
102
+ backend (verified by a differential test during the migration).
103
+
104
+ Practical rules for a future change:
105
+
106
+ - Bumping the `argon2` crate, or any change to hashing: keep `make test` green. If
107
+ the vectors still pass, output is unchanged and the change is safe.
108
+ - **Never** regenerate `reference-vectors.json` to make a failing suite pass — that
109
+ rewrites the answers instead of the code and destroys the guarantee. The generator
110
+ (`tests/vectors/generate.cjs`) refuses to overwrite the file without `--force` for
111
+ exactly this reason.
112
+ - `--force` regeneration is only for a deliberate migration that re-hashes every
113
+ stored credential (e.g. moving to stronger Argon2 parameters) — not a routine bump.
package/argon2_wasm.d.ts CHANGED
@@ -1,51 +1,12 @@
1
1
  /* tslint:disable */
2
- /**
3
- * @param {Uint8Array} password
4
- * @param {Uint8Array} salt
5
- * @param {Uint8Array} secret
6
- * @param {Uint8Array} associated_data
7
- * @param {number} iterations
8
- * @param {number} parallelism
9
- * @param {number} memory_size
10
- * @param {number} hash_type
11
- * @returns {Uint8Array}
12
- */
13
- export function argon2(password: Uint8Array, salt: Uint8Array, secret: Uint8Array, associated_data: Uint8Array, iterations: number, parallelism: number, memory_size: number, hash_type: number): Uint8Array;
14
- /**
15
- * @param {Uint8Array} hash
16
- * @param {Uint8Array} password
17
- * @param {Uint8Array} salt
18
- * @param {Uint8Array} secret
19
- * @param {Uint8Array} associated_data
20
- * @param {number} iterations
21
- * @param {number} parallelism
22
- * @param {number} memory_size
23
- * @param {number} hash_type
24
- * @returns {boolean}
25
- */
26
- export function verify(hash: Uint8Array, password: Uint8Array, salt: Uint8Array, secret: Uint8Array, associated_data: Uint8Array, iterations: number, parallelism: number, memory_size: number, hash_type: number): boolean;
27
- /**
28
- * @param {Uint8Array} password
29
- * @param {Uint8Array} salt
30
- * @param {Uint8Array} secret
31
- * @param {Uint8Array} associated_data
32
- * @param {number} iterations
33
- * @param {number} parallelism
34
- * @param {number} memory_size
35
- * @param {number} hash_type
36
- * @returns {Uint8Array}
37
- */
38
- export function argon2Encoded(password: Uint8Array, salt: Uint8Array, secret: Uint8Array, associated_data: Uint8Array, iterations: number, parallelism: number, memory_size: number, hash_type: number): Uint8Array;
39
- /**
40
- * @param {Uint8Array} encoded
41
- * @param {Uint8Array} password
42
- * @returns {boolean}
43
- */
44
- export function verifyEncoded(encoded: Uint8Array, password: Uint8Array): boolean;
2
+ /* eslint-disable */
3
+
45
4
  export enum HashType {
46
- Argon2d,
47
- Argon2i,
48
- Argon2id,
5
+ Argon2d = 0,
6
+ Argon2i = 1,
7
+ Argon2id = 2,
49
8
  }
50
- /**
51
- */
9
+
10
+ export function argon2(password: Uint8Array, salt: Uint8Array, secret: Uint8Array, associated_data: Uint8Array, iterations: number, parallelism: number, memory_size: number, hash_type: number): Uint8Array;
11
+
12
+ export function verify(hash: Uint8Array, password: Uint8Array, salt: Uint8Array, secret: Uint8Array, associated_data: Uint8Array, iterations: number, parallelism: number, memory_size: number, hash_type: number): boolean;
package/argon2_wasm.js CHANGED
@@ -1,220 +1,9 @@
1
- import * as wasm from './argon2_wasm_bg.wasm';
2
-
3
- let cachegetUint8Memory = null;
4
- function getUint8Memory() {
5
- if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) {
6
- cachegetUint8Memory = new Uint8Array(wasm.memory.buffer);
7
- }
8
- return cachegetUint8Memory;
9
- }
10
-
11
- let WASM_VECTOR_LEN = 0;
12
-
13
- function passArray8ToWasm(arg) {
14
- const ptr = wasm.__wbindgen_malloc(arg.length * 1);
15
- getUint8Memory().set(arg, ptr / 1);
16
- WASM_VECTOR_LEN = arg.length;
17
- return ptr;
18
- }
19
-
20
- let cachegetInt32Memory = null;
21
- function getInt32Memory() {
22
- if (cachegetInt32Memory === null || cachegetInt32Memory.buffer !== wasm.memory.buffer) {
23
- cachegetInt32Memory = new Int32Array(wasm.memory.buffer);
24
- }
25
- return cachegetInt32Memory;
26
- }
27
-
28
- function getArrayU8FromWasm(ptr, len) {
29
- return getUint8Memory().subarray(ptr / 1, ptr / 1 + len);
30
- }
31
- /**
32
- * @param {Uint8Array} password
33
- * @param {Uint8Array} salt
34
- * @param {Uint8Array} secret
35
- * @param {Uint8Array} associated_data
36
- * @param {number} iterations
37
- * @param {number} parallelism
38
- * @param {number} memory_size
39
- * @param {number} hash_type
40
- * @returns {Uint8Array}
41
- */
42
- export function argon2(password, salt, secret, associated_data, iterations, parallelism, memory_size, hash_type) {
43
- const retptr = 8;
44
- const ret = wasm.argon2(retptr, passArray8ToWasm(password), WASM_VECTOR_LEN, passArray8ToWasm(salt), WASM_VECTOR_LEN, passArray8ToWasm(secret), WASM_VECTOR_LEN, passArray8ToWasm(associated_data), WASM_VECTOR_LEN, iterations, parallelism, memory_size, hash_type);
45
- const memi32 = getInt32Memory();
46
- const v0 = getArrayU8FromWasm(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1]).slice();
47
- wasm.__wbindgen_free(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1] * 1);
48
- return v0;
49
- }
50
-
51
- /**
52
- * @param {Uint8Array} hash
53
- * @param {Uint8Array} password
54
- * @param {Uint8Array} salt
55
- * @param {Uint8Array} secret
56
- * @param {Uint8Array} associated_data
57
- * @param {number} iterations
58
- * @param {number} parallelism
59
- * @param {number} memory_size
60
- * @param {number} hash_type
61
- * @returns {boolean}
62
- */
63
- export function verify(hash, password, salt, secret, associated_data, iterations, parallelism, memory_size, hash_type) {
64
- const ret = wasm.verify(passArray8ToWasm(hash), WASM_VECTOR_LEN, passArray8ToWasm(password), WASM_VECTOR_LEN, passArray8ToWasm(salt), WASM_VECTOR_LEN, passArray8ToWasm(secret), WASM_VECTOR_LEN, passArray8ToWasm(associated_data), WASM_VECTOR_LEN, iterations, parallelism, memory_size, hash_type);
65
- return ret !== 0;
66
- }
67
-
68
- /**
69
- * @param {Uint8Array} password
70
- * @param {Uint8Array} salt
71
- * @param {Uint8Array} secret
72
- * @param {Uint8Array} associated_data
73
- * @param {number} iterations
74
- * @param {number} parallelism
75
- * @param {number} memory_size
76
- * @param {number} hash_type
77
- * @returns {Uint8Array}
78
- */
79
- export function argon2Encoded(password, salt, secret, associated_data, iterations, parallelism, memory_size, hash_type) {
80
- const retptr = 8;
81
- const ret = wasm.argon2Encoded(retptr, passArray8ToWasm(password), WASM_VECTOR_LEN, passArray8ToWasm(salt), WASM_VECTOR_LEN, passArray8ToWasm(secret), WASM_VECTOR_LEN, passArray8ToWasm(associated_data), WASM_VECTOR_LEN, iterations, parallelism, memory_size, hash_type);
82
- const memi32 = getInt32Memory();
83
- const v0 = getArrayU8FromWasm(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1]).slice();
84
- wasm.__wbindgen_free(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1] * 1);
85
- return v0;
86
- }
87
-
88
- /**
89
- * @param {Uint8Array} encoded
90
- * @param {Uint8Array} password
91
- * @returns {boolean}
92
- */
93
- export function verifyEncoded(encoded, password) {
94
- const ret = wasm.verifyEncoded(passArray8ToWasm(encoded), WASM_VECTOR_LEN, passArray8ToWasm(password), WASM_VECTOR_LEN);
95
- return ret !== 0;
96
- }
97
-
98
- const heap = new Array(32);
99
-
100
- heap.fill(undefined);
101
-
102
- heap.push(undefined, null, true, false);
103
-
104
- function getObject(idx) { return heap[idx]; }
105
-
106
- let heap_next = heap.length;
107
-
108
- function dropObject(idx) {
109
- if (idx < 36) return;
110
- heap[idx] = heap_next;
111
- heap_next = idx;
112
- }
113
-
114
- function takeObject(idx) {
115
- const ret = getObject(idx);
116
- dropObject(idx);
117
- return ret;
118
- }
119
-
120
- function addHeapObject(obj) {
121
- if (heap_next === heap.length) heap.push(heap.length + 1);
122
- const idx = heap_next;
123
- heap_next = heap[idx];
124
-
125
- heap[idx] = obj;
126
- return idx;
127
- }
128
-
129
- let cachedTextEncoder = new TextEncoder('utf-8');
130
-
131
- const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
132
- ? function (arg, view) {
133
- return cachedTextEncoder.encodeInto(arg, view);
134
- }
135
- : function (arg, view) {
136
- const buf = cachedTextEncoder.encode(arg);
137
- view.set(buf);
138
- return {
139
- read: arg.length,
140
- written: buf.length
141
- };
142
- });
143
-
144
- function passStringToWasm(arg) {
145
-
146
- let len = arg.length;
147
- let ptr = wasm.__wbindgen_malloc(len);
148
-
149
- const mem = getUint8Memory();
150
-
151
- let offset = 0;
152
-
153
- for (; offset < len; offset++) {
154
- const code = arg.charCodeAt(offset);
155
- if (code > 0x7F) break;
156
- mem[ptr + offset] = code;
157
- }
158
-
159
- if (offset !== len) {
160
- if (offset !== 0) {
161
- arg = arg.slice(offset);
162
- }
163
- ptr = wasm.__wbindgen_realloc(ptr, len, len = offset + arg.length * 3);
164
- const view = getUint8Memory().subarray(ptr + offset, ptr + len);
165
- const ret = encodeString(arg, view);
166
-
167
- offset += ret.written;
168
- }
169
-
170
- WASM_VECTOR_LEN = offset;
171
- return ptr;
172
- }
173
-
174
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
175
-
176
- cachedTextDecoder.decode();
177
-
178
- function getStringFromWasm(ptr, len) {
179
- return cachedTextDecoder.decode(getUint8Memory().subarray(ptr, ptr + len));
180
- }
181
- /**
182
- */
183
- export const HashType = Object.freeze({ Argon2d:0,Argon2i:1,Argon2id:2, });
184
-
185
- export const __wbindgen_object_drop_ref = function(arg0) {
186
- takeObject(arg0);
187
- };
188
-
189
- export const __wbg_new_59cb74e423758ede = function() {
190
- const ret = new Error();
191
- return addHeapObject(ret);
192
- };
193
-
194
- export const __wbg_stack_558ba5917b466edd = function(arg0, arg1) {
195
- const ret = getObject(arg1).stack;
196
- const ret0 = passStringToWasm(ret);
197
- const ret1 = WASM_VECTOR_LEN;
198
- getInt32Memory()[arg0 / 4 + 0] = ret0;
199
- getInt32Memory()[arg0 / 4 + 1] = ret1;
200
- };
201
-
202
- export const __wbg_error_4bb6c2a97407129a = function(arg0, arg1) {
203
- const v0 = getStringFromWasm(arg0, arg1).slice();
204
- wasm.__wbindgen_free(arg0, arg1 * 1);
205
- console.error(v0);
206
- };
207
-
208
- export const __wbg_new_b523d83e932ae6ee = function(arg0, arg1) {
209
- const ret = new Error(getStringFromWasm(arg0, arg1));
210
- return addHeapObject(ret);
211
- };
212
-
213
- export const __wbindgen_throw = function(arg0, arg1) {
214
- throw new Error(getStringFromWasm(arg0, arg1));
215
- };
216
-
217
- export const __wbindgen_rethrow = function(arg0) {
218
- throw takeObject(arg0);
219
- };
220
-
1
+ /* @ts-self-types="./argon2_wasm.d.ts" */
2
+ import * as wasm from "./argon2_wasm_bg.wasm";
3
+ import { __wbg_set_wasm } from "./argon2_wasm_bg.js";
4
+
5
+ __wbg_set_wasm(wasm);
6
+ wasm.__wbindgen_start();
7
+ export {
8
+ HashType, argon2, verify
9
+ } from "./argon2_wasm_bg.js";
package/argon2_wasm_bg.js CHANGED
@@ -1,9 +1,214 @@
1
+ /**
2
+ * @enum {0 | 1 | 2}
3
+ */
4
+ export const HashType = Object.freeze({
5
+ Argon2d: 0, "0": "Argon2d",
6
+ Argon2i: 1, "1": "Argon2i",
7
+ Argon2id: 2, "2": "Argon2id",
8
+ });
1
9
 
2
- const path = require('path').join(__dirname, 'argon2_wasm_bg.wasm');
3
- const bytes = require('fs').readFileSync(path);
4
- let imports = {};
5
- imports['./argon2_wasm.js'] = require('./argon2_wasm_node.js');
10
+ /**
11
+ * @param {Uint8Array} password
12
+ * @param {Uint8Array} salt
13
+ * @param {Uint8Array} secret
14
+ * @param {Uint8Array} associated_data
15
+ * @param {number} iterations
16
+ * @param {number} parallelism
17
+ * @param {number} memory_size
18
+ * @param {number} hash_type
19
+ * @returns {Uint8Array}
20
+ */
21
+ export function argon2(password, salt, secret, associated_data, iterations, parallelism, memory_size, hash_type) {
22
+ const ptr0 = passArray8ToWasm0(password, wasm.__wbindgen_malloc);
23
+ const len0 = WASM_VECTOR_LEN;
24
+ const ptr1 = passArray8ToWasm0(salt, wasm.__wbindgen_malloc);
25
+ const len1 = WASM_VECTOR_LEN;
26
+ const ptr2 = passArray8ToWasm0(secret, wasm.__wbindgen_malloc);
27
+ const len2 = WASM_VECTOR_LEN;
28
+ const ptr3 = passArray8ToWasm0(associated_data, wasm.__wbindgen_malloc);
29
+ const len3 = WASM_VECTOR_LEN;
30
+ const ret = wasm.argon2(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, iterations, parallelism, memory_size, hash_type);
31
+ if (ret[3]) {
32
+ throw takeFromExternrefTable0(ret[2]);
33
+ }
34
+ var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
35
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
36
+ return v5;
37
+ }
6
38
 
7
- const wasmModule = new WebAssembly.Module(bytes);
8
- const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
9
- module.exports = wasmInstance.exports;
39
+ /**
40
+ * @param {Uint8Array} hash
41
+ * @param {Uint8Array} password
42
+ * @param {Uint8Array} salt
43
+ * @param {Uint8Array} secret
44
+ * @param {Uint8Array} associated_data
45
+ * @param {number} iterations
46
+ * @param {number} parallelism
47
+ * @param {number} memory_size
48
+ * @param {number} hash_type
49
+ * @returns {boolean}
50
+ */
51
+ export function verify(hash, password, salt, secret, associated_data, iterations, parallelism, memory_size, hash_type) {
52
+ const ptr0 = passArray8ToWasm0(hash, wasm.__wbindgen_malloc);
53
+ const len0 = WASM_VECTOR_LEN;
54
+ const ptr1 = passArray8ToWasm0(password, wasm.__wbindgen_malloc);
55
+ const len1 = WASM_VECTOR_LEN;
56
+ const ptr2 = passArray8ToWasm0(salt, wasm.__wbindgen_malloc);
57
+ const len2 = WASM_VECTOR_LEN;
58
+ const ptr3 = passArray8ToWasm0(secret, wasm.__wbindgen_malloc);
59
+ const len3 = WASM_VECTOR_LEN;
60
+ const ptr4 = passArray8ToWasm0(associated_data, wasm.__wbindgen_malloc);
61
+ const len4 = WASM_VECTOR_LEN;
62
+ const ret = wasm.verify(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, iterations, parallelism, memory_size, hash_type);
63
+ if (ret[2]) {
64
+ throw takeFromExternrefTable0(ret[1]);
65
+ }
66
+ return ret[0] !== 0;
67
+ }
68
+ export function __wbg___wbindgen_throw_5d9e815e6fdf150f(arg0, arg1) {
69
+ throw new Error(getStringFromWasm0(arg0, arg1));
70
+ }
71
+ export function __wbg_error_5d74afee9818baeb(arg0, arg1) {
72
+ let deferred0_0;
73
+ let deferred0_1;
74
+ try {
75
+ deferred0_0 = arg0;
76
+ deferred0_1 = arg1;
77
+ console.error(getStringFromWasm0(arg0, arg1));
78
+ } finally {
79
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
80
+ }
81
+ }
82
+ export function __wbg_new_88d73322198219db() {
83
+ const ret = new Error();
84
+ return ret;
85
+ }
86
+ export function __wbg_new_a32a1ab6c6655abe(arg0, arg1) {
87
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
88
+ return ret;
89
+ }
90
+ export function __wbg_stack_b956c8d3aa8afd04(arg0, arg1) {
91
+ const ret = arg1.stack;
92
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
93
+ const len1 = WASM_VECTOR_LEN;
94
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
95
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
96
+ }
97
+ export function __wbindgen_init_externref_table() {
98
+ const table = wasm.__wbindgen_externrefs;
99
+ const offset = table.grow(4);
100
+ table.set(0, undefined);
101
+ table.set(offset + 0, undefined);
102
+ table.set(offset + 1, null);
103
+ table.set(offset + 2, true);
104
+ table.set(offset + 3, false);
105
+ }
106
+ function getArrayU8FromWasm0(ptr, len) {
107
+ ptr = ptr >>> 0;
108
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
109
+ }
110
+
111
+ let cachedDataViewMemory0 = null;
112
+ function getDataViewMemory0() {
113
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
114
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
115
+ }
116
+ return cachedDataViewMemory0;
117
+ }
118
+
119
+ function getStringFromWasm0(ptr, len) {
120
+ return decodeText(ptr >>> 0, len);
121
+ }
122
+
123
+ let cachedUint8ArrayMemory0 = null;
124
+ function getUint8ArrayMemory0() {
125
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
126
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
127
+ }
128
+ return cachedUint8ArrayMemory0;
129
+ }
130
+
131
+ function passArray8ToWasm0(arg, malloc) {
132
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
133
+ getUint8ArrayMemory0().set(arg, ptr / 1);
134
+ WASM_VECTOR_LEN = arg.length;
135
+ return ptr;
136
+ }
137
+
138
+ function passStringToWasm0(arg, malloc, realloc) {
139
+ if (realloc === undefined) {
140
+ const buf = cachedTextEncoder.encode(arg);
141
+ const ptr = malloc(buf.length, 1) >>> 0;
142
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
143
+ WASM_VECTOR_LEN = buf.length;
144
+ return ptr;
145
+ }
146
+
147
+ let len = arg.length;
148
+ let ptr = malloc(len, 1) >>> 0;
149
+
150
+ const mem = getUint8ArrayMemory0();
151
+
152
+ let offset = 0;
153
+
154
+ for (; offset < len; offset++) {
155
+ const code = arg.charCodeAt(offset);
156
+ if (code > 0x7F) break;
157
+ mem[ptr + offset] = code;
158
+ }
159
+ if (offset !== len) {
160
+ if (offset !== 0) {
161
+ arg = arg.slice(offset);
162
+ }
163
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
164
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
165
+ const ret = cachedTextEncoder.encodeInto(arg, view);
166
+
167
+ offset += ret.written;
168
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
169
+ }
170
+
171
+ WASM_VECTOR_LEN = offset;
172
+ return ptr;
173
+ }
174
+
175
+ function takeFromExternrefTable0(idx) {
176
+ const value = wasm.__wbindgen_externrefs.get(idx);
177
+ wasm.__externref_table_dealloc(idx);
178
+ return value;
179
+ }
180
+
181
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
182
+ cachedTextDecoder.decode();
183
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
184
+ let numBytesDecoded = 0;
185
+ function decodeText(ptr, len) {
186
+ numBytesDecoded += len;
187
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
188
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
189
+ cachedTextDecoder.decode();
190
+ numBytesDecoded = len;
191
+ }
192
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
193
+ }
194
+
195
+ const cachedTextEncoder = new TextEncoder();
196
+
197
+ if (!('encodeInto' in cachedTextEncoder)) {
198
+ cachedTextEncoder.encodeInto = function (arg, view) {
199
+ const buf = cachedTextEncoder.encode(arg);
200
+ view.set(buf);
201
+ return {
202
+ read: arg.length,
203
+ written: buf.length
204
+ };
205
+ };
206
+ }
207
+
208
+ let WASM_VECTOR_LEN = 0;
209
+
210
+
211
+ let wasm;
212
+ export function __wbg_set_wasm(val) {
213
+ wasm = val;
214
+ }
Binary file
@@ -0,0 +1,222 @@
1
+ /* @ts-self-types="./argon2_wasm.d.ts" */
2
+
3
+ /**
4
+ * @enum {0 | 1 | 2}
5
+ */
6
+ const HashType = Object.freeze({
7
+ Argon2d: 0, "0": "Argon2d",
8
+ Argon2i: 1, "1": "Argon2i",
9
+ Argon2id: 2, "2": "Argon2id",
10
+ });
11
+ exports.HashType = HashType;
12
+
13
+ /**
14
+ * @param {Uint8Array} password
15
+ * @param {Uint8Array} salt
16
+ * @param {Uint8Array} secret
17
+ * @param {Uint8Array} associated_data
18
+ * @param {number} iterations
19
+ * @param {number} parallelism
20
+ * @param {number} memory_size
21
+ * @param {number} hash_type
22
+ * @returns {Uint8Array}
23
+ */
24
+ function argon2(password, salt, secret, associated_data, iterations, parallelism, memory_size, hash_type) {
25
+ const ptr0 = passArray8ToWasm0(password, wasm.__wbindgen_malloc);
26
+ const len0 = WASM_VECTOR_LEN;
27
+ const ptr1 = passArray8ToWasm0(salt, wasm.__wbindgen_malloc);
28
+ const len1 = WASM_VECTOR_LEN;
29
+ const ptr2 = passArray8ToWasm0(secret, wasm.__wbindgen_malloc);
30
+ const len2 = WASM_VECTOR_LEN;
31
+ const ptr3 = passArray8ToWasm0(associated_data, wasm.__wbindgen_malloc);
32
+ const len3 = WASM_VECTOR_LEN;
33
+ const ret = wasm.argon2(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, iterations, parallelism, memory_size, hash_type);
34
+ if (ret[3]) {
35
+ throw takeFromExternrefTable0(ret[2]);
36
+ }
37
+ var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
38
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
39
+ return v5;
40
+ }
41
+ exports.argon2 = argon2;
42
+
43
+ /**
44
+ * @param {Uint8Array} hash
45
+ * @param {Uint8Array} password
46
+ * @param {Uint8Array} salt
47
+ * @param {Uint8Array} secret
48
+ * @param {Uint8Array} associated_data
49
+ * @param {number} iterations
50
+ * @param {number} parallelism
51
+ * @param {number} memory_size
52
+ * @param {number} hash_type
53
+ * @returns {boolean}
54
+ */
55
+ function verify(hash, password, salt, secret, associated_data, iterations, parallelism, memory_size, hash_type) {
56
+ const ptr0 = passArray8ToWasm0(hash, wasm.__wbindgen_malloc);
57
+ const len0 = WASM_VECTOR_LEN;
58
+ const ptr1 = passArray8ToWasm0(password, wasm.__wbindgen_malloc);
59
+ const len1 = WASM_VECTOR_LEN;
60
+ const ptr2 = passArray8ToWasm0(salt, wasm.__wbindgen_malloc);
61
+ const len2 = WASM_VECTOR_LEN;
62
+ const ptr3 = passArray8ToWasm0(secret, wasm.__wbindgen_malloc);
63
+ const len3 = WASM_VECTOR_LEN;
64
+ const ptr4 = passArray8ToWasm0(associated_data, wasm.__wbindgen_malloc);
65
+ const len4 = WASM_VECTOR_LEN;
66
+ const ret = wasm.verify(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, iterations, parallelism, memory_size, hash_type);
67
+ if (ret[2]) {
68
+ throw takeFromExternrefTable0(ret[1]);
69
+ }
70
+ return ret[0] !== 0;
71
+ }
72
+ exports.verify = verify;
73
+ function __wbg_get_imports() {
74
+ const import0 = {
75
+ __proto__: null,
76
+ __wbg___wbindgen_throw_5d9e815e6fdf150f: function(arg0, arg1) {
77
+ throw new Error(getStringFromWasm0(arg0, arg1));
78
+ },
79
+ __wbg_error_5d74afee9818baeb: function(arg0, arg1) {
80
+ let deferred0_0;
81
+ let deferred0_1;
82
+ try {
83
+ deferred0_0 = arg0;
84
+ deferred0_1 = arg1;
85
+ console.error(getStringFromWasm0(arg0, arg1));
86
+ } finally {
87
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
88
+ }
89
+ },
90
+ __wbg_new_88d73322198219db: function() {
91
+ const ret = new Error();
92
+ return ret;
93
+ },
94
+ __wbg_new_a32a1ab6c6655abe: function(arg0, arg1) {
95
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
96
+ return ret;
97
+ },
98
+ __wbg_stack_b956c8d3aa8afd04: function(arg0, arg1) {
99
+ const ret = arg1.stack;
100
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
101
+ const len1 = WASM_VECTOR_LEN;
102
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
103
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
104
+ },
105
+ __wbindgen_init_externref_table: function() {
106
+ const table = wasm.__wbindgen_externrefs;
107
+ const offset = table.grow(4);
108
+ table.set(0, undefined);
109
+ table.set(offset + 0, undefined);
110
+ table.set(offset + 1, null);
111
+ table.set(offset + 2, true);
112
+ table.set(offset + 3, false);
113
+ },
114
+ };
115
+ return {
116
+ __proto__: null,
117
+ "./argon2_wasm_bg.js": import0,
118
+ };
119
+ }
120
+
121
+ function getArrayU8FromWasm0(ptr, len) {
122
+ ptr = ptr >>> 0;
123
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
124
+ }
125
+
126
+ let cachedDataViewMemory0 = null;
127
+ function getDataViewMemory0() {
128
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
129
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
130
+ }
131
+ return cachedDataViewMemory0;
132
+ }
133
+
134
+ function getStringFromWasm0(ptr, len) {
135
+ return decodeText(ptr >>> 0, len);
136
+ }
137
+
138
+ let cachedUint8ArrayMemory0 = null;
139
+ function getUint8ArrayMemory0() {
140
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
141
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
142
+ }
143
+ return cachedUint8ArrayMemory0;
144
+ }
145
+
146
+ function passArray8ToWasm0(arg, malloc) {
147
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
148
+ getUint8ArrayMemory0().set(arg, ptr / 1);
149
+ WASM_VECTOR_LEN = arg.length;
150
+ return ptr;
151
+ }
152
+
153
+ function passStringToWasm0(arg, malloc, realloc) {
154
+ if (realloc === undefined) {
155
+ const buf = cachedTextEncoder.encode(arg);
156
+ const ptr = malloc(buf.length, 1) >>> 0;
157
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
158
+ WASM_VECTOR_LEN = buf.length;
159
+ return ptr;
160
+ }
161
+
162
+ let len = arg.length;
163
+ let ptr = malloc(len, 1) >>> 0;
164
+
165
+ const mem = getUint8ArrayMemory0();
166
+
167
+ let offset = 0;
168
+
169
+ for (; offset < len; offset++) {
170
+ const code = arg.charCodeAt(offset);
171
+ if (code > 0x7F) break;
172
+ mem[ptr + offset] = code;
173
+ }
174
+ if (offset !== len) {
175
+ if (offset !== 0) {
176
+ arg = arg.slice(offset);
177
+ }
178
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
179
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
180
+ const ret = cachedTextEncoder.encodeInto(arg, view);
181
+
182
+ offset += ret.written;
183
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
184
+ }
185
+
186
+ WASM_VECTOR_LEN = offset;
187
+ return ptr;
188
+ }
189
+
190
+ function takeFromExternrefTable0(idx) {
191
+ const value = wasm.__wbindgen_externrefs.get(idx);
192
+ wasm.__externref_table_dealloc(idx);
193
+ return value;
194
+ }
195
+
196
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
197
+ cachedTextDecoder.decode();
198
+ function decodeText(ptr, len) {
199
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
200
+ }
201
+
202
+ const cachedTextEncoder = new TextEncoder();
203
+
204
+ if (!('encodeInto' in cachedTextEncoder)) {
205
+ cachedTextEncoder.encodeInto = function (arg, view) {
206
+ const buf = cachedTextEncoder.encode(arg);
207
+ view.set(buf);
208
+ return {
209
+ read: arg.length,
210
+ written: buf.length
211
+ };
212
+ };
213
+ }
214
+
215
+ let WASM_VECTOR_LEN = 0;
216
+
217
+ const wasmPath = `${__dirname}/argon2_wasm_bg.wasm`;
218
+ const wasmBytes = require('fs').readFileSync(wasmPath);
219
+ const wasmModule = new WebAssembly.Module(wasmBytes);
220
+ let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
221
+ let wasm = wasmInstance.exports;
222
+ wasm.__wbindgen_start();
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@whi/argon2-wasm",
3
+ "type": "module",
3
4
  "collaborators": [
4
5
  "matthew@webheroes.ca"
5
6
  ],
6
7
  "description": "Argon2 wasm bindings with all inputs exposed",
7
- "version": "0.4.0",
8
+ "version": "0.5.0",
9
+ "license": "ISC",
8
10
  "repository": {
9
11
  "type": "git",
10
12
  "url": "https://github.com/mjbrisebois/argon2-wasm"
@@ -12,11 +14,22 @@
12
14
  "files": [
13
15
  "argon2_wasm_bg.wasm",
14
16
  "argon2_wasm.js",
17
+ "argon2_wasm_bg.js",
15
18
  "argon2_wasm.d.ts",
16
- "argon2_wasm_bg.js"
19
+ "argon2_wasm_node.cjs"
17
20
  ],
18
- "module": "argon2_wasm.js",
21
+ "main": "argon2_wasm_node.cjs",
19
22
  "types": "argon2_wasm.d.ts",
20
- "sideEffects": "false",
21
- "main": "argon2_wasm_node.js"
23
+ "sideEffects": [
24
+ "./argon2_wasm.js",
25
+ "./snippets/*"
26
+ ],
27
+ "module": "argon2_wasm.js",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./argon2_wasm.d.ts",
31
+ "import": "./argon2_wasm.js",
32
+ "require": "./argon2_wasm_node.cjs"
33
+ }
34
+ }
22
35
  }
@@ -1,194 +0,0 @@
1
- let wasm;
2
- const { TextDecoder } = require(String.raw`util`);
3
-
4
- let cachegetUint8Memory = null;
5
- function getUint8Memory() {
6
- if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) {
7
- cachegetUint8Memory = new Uint8Array(wasm.memory.buffer);
8
- }
9
- return cachegetUint8Memory;
10
- }
11
-
12
- let WASM_VECTOR_LEN = 0;
13
-
14
- function passArray8ToWasm(arg) {
15
- const ptr = wasm.__wbindgen_malloc(arg.length * 1);
16
- getUint8Memory().set(arg, ptr / 1);
17
- WASM_VECTOR_LEN = arg.length;
18
- return ptr;
19
- }
20
-
21
- let cachegetInt32Memory = null;
22
- function getInt32Memory() {
23
- if (cachegetInt32Memory === null || cachegetInt32Memory.buffer !== wasm.memory.buffer) {
24
- cachegetInt32Memory = new Int32Array(wasm.memory.buffer);
25
- }
26
- return cachegetInt32Memory;
27
- }
28
-
29
- function getArrayU8FromWasm(ptr, len) {
30
- return getUint8Memory().subarray(ptr / 1, ptr / 1 + len);
31
- }
32
- /**
33
- * @param {Uint8Array} password
34
- * @param {Uint8Array} salt
35
- * @param {Uint8Array} secret
36
- * @param {Uint8Array} associated_data
37
- * @param {number} iterations
38
- * @param {number} parallelism
39
- * @param {number} memory_size
40
- * @param {number} hash_type
41
- * @returns {Uint8Array}
42
- */
43
- module.exports.argon2 = function(password, salt, secret, associated_data, iterations, parallelism, memory_size, hash_type) {
44
- const retptr = 8;
45
- const ret = wasm.argon2(retptr, passArray8ToWasm(password), WASM_VECTOR_LEN, passArray8ToWasm(salt), WASM_VECTOR_LEN, passArray8ToWasm(secret), WASM_VECTOR_LEN, passArray8ToWasm(associated_data), WASM_VECTOR_LEN, iterations, parallelism, memory_size, hash_type);
46
- const memi32 = getInt32Memory();
47
- const v0 = getArrayU8FromWasm(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1]).slice();
48
- wasm.__wbindgen_free(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1] * 1);
49
- return v0;
50
- };
51
-
52
- /**
53
- * @param {Uint8Array} hash
54
- * @param {Uint8Array} password
55
- * @param {Uint8Array} salt
56
- * @param {Uint8Array} secret
57
- * @param {Uint8Array} associated_data
58
- * @param {number} iterations
59
- * @param {number} parallelism
60
- * @param {number} memory_size
61
- * @param {number} hash_type
62
- * @returns {boolean}
63
- */
64
- module.exports.verify = function(hash, password, salt, secret, associated_data, iterations, parallelism, memory_size, hash_type) {
65
- const ret = wasm.verify(passArray8ToWasm(hash), WASM_VECTOR_LEN, passArray8ToWasm(password), WASM_VECTOR_LEN, passArray8ToWasm(salt), WASM_VECTOR_LEN, passArray8ToWasm(secret), WASM_VECTOR_LEN, passArray8ToWasm(associated_data), WASM_VECTOR_LEN, iterations, parallelism, memory_size, hash_type);
66
- return ret !== 0;
67
- };
68
-
69
- /**
70
- * @param {Uint8Array} password
71
- * @param {Uint8Array} salt
72
- * @param {Uint8Array} secret
73
- * @param {Uint8Array} associated_data
74
- * @param {number} iterations
75
- * @param {number} parallelism
76
- * @param {number} memory_size
77
- * @param {number} hash_type
78
- * @returns {Uint8Array}
79
- */
80
- module.exports.argon2Encoded = function(password, salt, secret, associated_data, iterations, parallelism, memory_size, hash_type) {
81
- const retptr = 8;
82
- const ret = wasm.argon2Encoded(retptr, passArray8ToWasm(password), WASM_VECTOR_LEN, passArray8ToWasm(salt), WASM_VECTOR_LEN, passArray8ToWasm(secret), WASM_VECTOR_LEN, passArray8ToWasm(associated_data), WASM_VECTOR_LEN, iterations, parallelism, memory_size, hash_type);
83
- const memi32 = getInt32Memory();
84
- const v0 = getArrayU8FromWasm(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1]).slice();
85
- wasm.__wbindgen_free(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1] * 1);
86
- return v0;
87
- };
88
-
89
- /**
90
- * @param {Uint8Array} encoded
91
- * @param {Uint8Array} password
92
- * @returns {boolean}
93
- */
94
- module.exports.verifyEncoded = function(encoded, password) {
95
- const ret = wasm.verifyEncoded(passArray8ToWasm(encoded), WASM_VECTOR_LEN, passArray8ToWasm(password), WASM_VECTOR_LEN);
96
- return ret !== 0;
97
- };
98
-
99
- const heap = new Array(32);
100
-
101
- heap.fill(undefined);
102
-
103
- heap.push(undefined, null, true, false);
104
-
105
- function getObject(idx) { return heap[idx]; }
106
-
107
- let heap_next = heap.length;
108
-
109
- function dropObject(idx) {
110
- if (idx < 36) return;
111
- heap[idx] = heap_next;
112
- heap_next = idx;
113
- }
114
-
115
- function takeObject(idx) {
116
- const ret = getObject(idx);
117
- dropObject(idx);
118
- return ret;
119
- }
120
-
121
- function addHeapObject(obj) {
122
- if (heap_next === heap.length) heap.push(heap.length + 1);
123
- const idx = heap_next;
124
- heap_next = heap[idx];
125
-
126
- heap[idx] = obj;
127
- return idx;
128
- }
129
-
130
- let cachegetNodeBufferMemory = null;
131
- function getNodeBufferMemory() {
132
- if (cachegetNodeBufferMemory === null || cachegetNodeBufferMemory.buffer !== wasm.memory.buffer) {
133
- cachegetNodeBufferMemory = Buffer.from(wasm.memory.buffer);
134
- }
135
- return cachegetNodeBufferMemory;
136
- }
137
-
138
- function passStringToWasm(arg) {
139
-
140
- const len = Buffer.byteLength(arg);
141
- const ptr = wasm.__wbindgen_malloc(len);
142
- getNodeBufferMemory().write(arg, ptr, len);
143
- WASM_VECTOR_LEN = len;
144
- return ptr;
145
- }
146
-
147
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
148
-
149
- cachedTextDecoder.decode();
150
-
151
- function getStringFromWasm(ptr, len) {
152
- return cachedTextDecoder.decode(getUint8Memory().subarray(ptr, ptr + len));
153
- }
154
- /**
155
- */
156
- module.exports.HashType = Object.freeze({ Argon2d:0,Argon2i:1,Argon2id:2, });
157
-
158
- module.exports.__wbindgen_object_drop_ref = function(arg0) {
159
- takeObject(arg0);
160
- };
161
-
162
- module.exports.__wbg_new_59cb74e423758ede = function() {
163
- const ret = new Error();
164
- return addHeapObject(ret);
165
- };
166
-
167
- module.exports.__wbg_stack_558ba5917b466edd = function(arg0, arg1) {
168
- const ret = getObject(arg1).stack;
169
- const ret0 = passStringToWasm(ret);
170
- const ret1 = WASM_VECTOR_LEN;
171
- getInt32Memory()[arg0 / 4 + 0] = ret0;
172
- getInt32Memory()[arg0 / 4 + 1] = ret1;
173
- };
174
-
175
- module.exports.__wbg_error_4bb6c2a97407129a = function(arg0, arg1) {
176
- const v0 = getStringFromWasm(arg0, arg1).slice();
177
- wasm.__wbindgen_free(arg0, arg1 * 1);
178
- console.error(v0);
179
- };
180
-
181
- module.exports.__wbg_new_b523d83e932ae6ee = function(arg0, arg1) {
182
- const ret = new Error(getStringFromWasm(arg0, arg1));
183
- return addHeapObject(ret);
184
- };
185
-
186
- module.exports.__wbindgen_throw = function(arg0, arg1) {
187
- throw new Error(getStringFromWasm(arg0, arg1));
188
- };
189
-
190
- module.exports.__wbindgen_rethrow = function(arg0) {
191
- throw takeObject(arg0);
192
- };
193
- wasm = require('./argon2_wasm_bg');
194
-