Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion crates/web-client/js/__tests__/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ describe("resolveAuthScheme", () => {
expect(resolveAuthScheme("falcon", wasm)).toBe(2);
});

it("passes through the WASM ECDSA auth scheme numeric value", () => {
expect(resolveAuthScheme(wasm.AuthScheme.AuthEcdsaK256Keccak, wasm)).toBe(
1
);
});

it("passes through the WASM falcon auth scheme numeric value", () => {
expect(resolveAuthScheme(wasm.AuthScheme.AuthRpoFalcon512, wasm)).toBe(2);
});

it("defaults to falcon for null", () => {
expect(resolveAuthScheme(null, wasm)).toBe(2);
});
Expand All @@ -239,7 +249,7 @@ describe("resolveAuthScheme", () => {

it("throws for unknown scheme", () => {
expect(() => resolveAuthScheme("rsa", wasm)).toThrow(
'Unknown auth scheme: "rsa"'
'Unknown auth scheme: "rsa". Expected "falcon", "ecdsa", or a WASM AuthScheme enum value.'
);
});
});
Expand Down
11 changes: 9 additions & 2 deletions crates/web-client/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
StorageResult,
wordToBigInt,
} from "./storageView.js";
import { resolveAuthScheme } from "./utils.js";
export * from "../Cargo.toml";

export const AccountType = Object.freeze({
Expand All @@ -27,6 +28,8 @@ export const AccountType = Object.freeze({
export const AuthScheme = Object.freeze({
Falcon: "falcon",
ECDSA: "ecdsa",
AuthRpoFalcon512: 2,
AuthEcdsaK256Keccak: 1,
});

export const NoteVisibility = Object.freeze({
Expand Down Expand Up @@ -803,8 +806,10 @@ class WebClient {

async newWallet(storageMode, authSchemeId, seed) {
return this._serializeWasmCall(async () => {
const wasm = await getWasmOrThrow();
const authScheme = resolveAuthScheme(authSchemeId, wasm);
const wasmWebClient = await this.getWasmWebClient();
return await wasmWebClient.newWallet(storageMode, authSchemeId, seed);
return await wasmWebClient.newWallet(storageMode, authScheme, seed);
});
}

Expand All @@ -818,6 +823,8 @@ class WebClient {
authSchemeId
) {
return this._serializeWasmCall(async () => {
const wasm = await getWasmOrThrow();
const authScheme = resolveAuthScheme(authSchemeId, wasm);
const wasmWebClient = await this.getWasmWebClient();
return await wasmWebClient.newFaucet(
storageMode,
Expand All @@ -826,7 +833,7 @@ class WebClient {
tokenSymbol,
decimals,
maxSupply,
authSchemeId
authScheme
);
});
}
Expand Down
2 changes: 2 additions & 0 deletions crates/web-client/js/node-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export const AccountType = Object.freeze({
export const AuthScheme = Object.freeze({
Falcon: "falcon",
ECDSA: "ecdsa",
AuthRpoFalcon512: 2,
AuthEcdsaK256Keccak: 1,
});

export const NoteVisibility = Object.freeze({
Expand Down
3 changes: 3 additions & 0 deletions crates/web-client/js/types/api-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ export declare const MidenArrays: MidenArrayConstructors;
/**
* User-friendly auth scheme constants for MidenClient options.
* Use `AuthScheme.Falcon` or `AuthScheme.ECDSA` instead of raw strings.
* The numeric aliases match the WASM AuthScheme enum for low-level clients.
*/
export declare const AuthScheme: {
readonly Falcon: "falcon";
readonly ECDSA: "ecdsa";
readonly AuthRpoFalcon512: 2;
readonly AuthEcdsaK256Keccak: 1;
};

/**
Expand Down
14 changes: 9 additions & 5 deletions crates/web-client/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,25 @@ export function resolveStorageMode(mode, wasm) {
}

/**
* Resolves an auth scheme string to a WASM AuthScheme enum value.
* Resolves an auth scheme selector to a WASM AuthScheme enum value.
*
* @param {string | undefined} scheme - "falcon" or "ecdsa". Defaults to "falcon".
* @param {string | number | undefined} scheme - "falcon", "ecdsa", or a WASM AuthScheme enum value. Defaults to "falcon".
* @param {object} wasm - The WASM module.
* @returns {number} The AuthScheme enum value.
*/
export function resolveAuthScheme(scheme, wasm) {
if (scheme === "ecdsa") {
if (scheme === "ecdsa" || scheme === wasm.AuthScheme.AuthEcdsaK256Keccak) {
return wasm.AuthScheme.AuthEcdsaK256Keccak;
}
if (scheme === "falcon" || scheme == null) {
if (
scheme === "falcon" ||
scheme === wasm.AuthScheme.AuthRpoFalcon512 ||
scheme == null
) {
return wasm.AuthScheme.AuthRpoFalcon512;
}
throw new Error(
`Unknown auth scheme: "${scheme}". Expected "falcon" or "ecdsa".`
`Unknown auth scheme: "${scheme}". Expected "falcon", "ecdsa", or a WASM AuthScheme enum value.`
);
}

Expand Down