Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Merge calcSalt into authBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonLewis committed Feb 28, 2024
1 parent dd569c6 commit 4c59a71
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
24 changes: 24 additions & 0 deletions src/authBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,30 @@ export const calcNonce = (args: typeDataArgs) => {
return utils.hexlify(utils.concat([nonceA, nonceB]));
};

// @Note Crypto.subtle is only available in localhost or secure contexts (HTTPS).
function getCrypto() {
try {
return window.crypto;
} catch {
return crypto;
}
}

export async function calcSalt(password: string, salt = "salt", iterations = 1e7) {
const crypto = getCrypto();
const textEncoder = new TextEncoder();
const passwordBuffer = textEncoder.encode(password);
const importedKey = await crypto.subtle.importKey("raw", passwordBuffer, "PBKDF2", false, ["deriveBits"]);

const saltBuffer = textEncoder.encode(salt);
const params = { name: "PBKDF2", hash: "SHA-256", salt: saltBuffer, iterations };
const derivation = await crypto.subtle.deriveBits(params, importedKey, 256);

return Array.from(new Uint8Array(derivation))
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
}

export function calcGuardianId(subHash: string, guardian: string) {
return utils.keccak256(utils.defaultAbiCoder.encode(["bytes32", "address"], [subHash, guardian]));
}
Expand Down
23 changes: 0 additions & 23 deletions src/calcSalt.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export * from "./jwt";
export * from "./jwtProvider";
export * from "./jwkProvider";
export * from "./userOp";
export * from "./calcSalt";
export * from "./account-utils";
export * from "./utils";
export * from "./circuit-helpers";
Expand Down

0 comments on commit 4c59a71

Please sign in to comment.