Skip to content

Commit

Permalink
make imports more es friendly. provide default export
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcallister0210 committed Feb 1, 2025
1 parent 674eeb4 commit c981990
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/cognito-srp-helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Buffer } from "buffer/"; // use the browser compatible buffer library
import { Buffer } from "buffer/index.js"; // use the browser compatible buffer library
import CryptoJS from "crypto-js";
import { BigInteger } from "jsbn";

Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Buffer } from "buffer/"; // use the browser compatible buffer library
import { Buffer } from "buffer/index.js"; // use the browser compatible buffer library
import { BigInteger } from "jsbn";

import { hexHash, padHex } from "./utils";
Expand Down
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import * as CognitoSrpHelper from "./cognito-srp-helper";
import * as Errors from "./errors";
import * as Types from "./types";

export * from "./cognito-srp-helper";
export * from "./errors";
export * from "./types";

export default {
...CognitoSrpHelper,
...Errors,
...Types,
};
10 changes: 5 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { Buffer } from "buffer/"; // use the browser compatible buffer library
import { lib, SHA256 } from "crypto-js";
import { Buffer } from "buffer/index.js"; // use the browser compatible buffer library
import CryptoJS from "crypto-js";
import { BigInteger } from "jsbn";

import { HEX_TO_SHORT } from "./constants";
Expand All @@ -16,8 +16,8 @@ import { HEX_TO_SHORT } from "./constants";
* @returns Hex-encoded hash.
*/
export const hash = (buf: Buffer | string): string => {
const str = buf instanceof Buffer ? lib.WordArray.create(buf) : buf;
const hashHex = SHA256(str).toString();
const str = buf instanceof Buffer ? CryptoJS.lib.WordArray.create(buf) : buf;
const hashHex = CryptoJS.SHA256(str).toString();
const completeHash = new Array(64 - hashHex.length).join("0") + hashHex;

return completeHash;
Expand Down Expand Up @@ -118,7 +118,7 @@ export const padHex = (bigInt: BigInteger): string => {
* @returns Fixed-length sequence of random bytes
*/
export const randomBytes = (nBytes: number): Buffer => {
const bytes = Buffer.from(lib.WordArray.random(nBytes).toString(), "hex");
const bytes = Buffer.from(CryptoJS.lib.WordArray.random(nBytes).toString(), "hex");

return bytes;
};
Expand Down

0 comments on commit c981990

Please sign in to comment.