taler-util: import hash-wasm only when building for Node

This commit is contained in:
Iván Ávalos 2023-07-02 23:01:47 -06:00
parent ef51ba983f
commit e0f32dc899
No known key found for this signature in database
GPG Key ID: AC47C0E4F348CE33
5 changed files with 59 additions and 10 deletions

View File

@ -49,6 +49,10 @@
"node": "./lib/http-impl.node.js", "node": "./lib/http-impl.node.js",
"qtart": "./lib/http-impl.qtart.js", "qtart": "./lib/http-impl.qtart.js",
"default": "./lib/http-impl.missing.js" "default": "./lib/http-impl.missing.js"
},
"#argon2-impl": {
"node": "./lib/argon2-impl.node.js",
"default": "/lib/argon2-impl.missing.js"
} }
}, },
"scripts": { "scripts": {

View File

@ -0,0 +1,10 @@
export async function HashArgon2idImpl(
password: Uint8Array,
salt: Uint8Array,
iterations: number,
memorySize: number,
hashLength: number,
): Promise<Uint8Array> {
throw new Error("Method not implemented.");
}

View File

@ -0,0 +1,19 @@
import { argon2id } from "hash-wasm";
export async function HashArgon2idImpl(
password: Uint8Array,
salt: Uint8Array,
iterations: number,
memorySize: number,
hashLength: number,
): Promise<Uint8Array> {
return await argon2id({
password: password,
salt: salt,
iterations: iterations,
memorySize: memorySize,
hashLength: hashLength,
parallelism: 1,
outputType: "binary",
});
}

View File

@ -0,0 +1,18 @@
import * as impl from "#argon2-impl";
export async function hashArgon2id(
password: Uint8Array,
salt: Uint8Array,
iterations: number,
memorySize: number,
hashLength: number,
): Promise<Uint8Array> {
return await impl.HashArgon2idImpl(
password,
salt,
iterations,
memorySize,
hashLength,
);
}

View File

@ -24,7 +24,7 @@
import * as nacl from "./nacl-fast.js"; import * as nacl from "./nacl-fast.js";
import { hmacSha256, hmacSha512 } from "./kdf.js"; import { hmacSha256, hmacSha512 } from "./kdf.js";
import bigint from "big-integer"; import bigint from "big-integer";
import { argon2id } from "hash-wasm"; import * as argon2 from "./argon2.js";
import { import {
CoinEnvelope, CoinEnvelope,
CoinPublicKeyString, CoinPublicKeyString,
@ -277,15 +277,13 @@ export async function hashArgon2id(
hashLength, hashLength,
); );
} }
return await argon2id({ return await argon2.hashArgon2id(
password: password, password,
salt: salt, salt,
iterations: iterations, iterations,
memorySize: memorySize, memorySize,
hashLength: hashLength, hashLength,
parallelism: 1, );
outputType: "binary",
});
} }
export function eddsaGetPublic(eddsaPriv: Uint8Array): Uint8Array { export function eddsaGetPublic(eddsaPriv: Uint8Array): Uint8Array {