Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1995 committed Aug 8, 2023
1 parent dd5c6e2 commit 5624bd8
Show file tree
Hide file tree
Showing 9 changed files with 4,690 additions and 3,688 deletions.
11 changes: 0 additions & 11 deletions .eslintrc

This file was deleted.

13 changes: 13 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require("@rushstack/eslint-patch/modern-module-resolution");

module.exports = {
root: true,
extends: ["@toruslabs/eslint-config-typescript"],
parser: "@typescript-eslint/parser",
ignorePatterns: ["*.config.js", ".eslintrc.js"],
parserOptions: {
sourceType: "module",
ecmaVersion: 11,
project: "./tsconfig.json",
},
};
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
>=18.x
5 changes: 1 addition & 4 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
module.exports = {
"presets": ["@babel/env", "@babel/typescript"],
"plugins": ["@babel/plugin-proposal-object-rest-spread", "@babel/plugin-proposal-class-properties", "@babel/transform-runtime"]
}
module.exports = require("@toruslabs/config/babel.config");
8,292 changes: 4,654 additions & 3,638 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 14 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,20 @@
},
"homepage": "https://github.com/torusresearch/eccrypto",
"devDependencies": {
"@babel/cli": "^7.21.5",
"@babel/core": "^7.21.5",
"@babel/plugin-transform-runtime": "^7.21.4",
"@babel/preset-env": "^7.21.5",
"@babel/runtime": "^7.21.5",
"@toruslabs/eslint-config-typescript": "^2.0.0",
"eslint-plugin-chai-expect": "^3.0.0",
"@toruslabs/torus-scripts": "^4.0.0",
"@babel/cli": "^7.22.10",
"@babel/core": "^7.22.10",
"@babel/plugin-transform-runtime": "^7.22.10",
"@babel/preset-env": "^7.22.10",
"@babel/runtime": "^7.22.10",
"@toruslabs/config": "^2.0.1",
"@toruslabs/eslint-config-typescript": "^3.0.0",
"@toruslabs/torus-scripts": "^5.0.1",
"@types/elliptic": "^6.4.14",
"browserify": "^17.0.0",
"buffer-equal": "^1.0.1",
"chai": "^4.3.7",
"eslint": "^8.39.0",
"eslint": "^8.46.0",
"eslint-plugin-chai-expect": "^3.0.0",
"karma": "^6.4.2",
"karma-browserify": "^8.1.0",
"karma-chrome-launcher": "^3.2.0",
Expand All @@ -62,13 +63,14 @@
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"karma-safari-launcher": "^1.0.0",
"mocha": "^10.2.0"
"mocha": "^10.2.0",
"typescript": "^5.1.6"
},
"dependencies": {
"elliptic": "^6.5.4"
},
"engines": {
"node": ">=16.18.1",
"npm": ">=8.x"
"node": ">=18.x",
"npm": ">=9.x"
}
}
8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import nodeCrypto from "crypto";
import { ec as EC } from "elliptic";

const ec = new EC("secp256k1");
const browserCrypto = global.crypto || global.msCrypto || {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const browserCrypto = global.crypto || (global as any).msCrypto || {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const subtle = browserCrypto.subtle || (browserCrypto as any).webkitSubtle;

const EC_GROUP_ORDER = Buffer.from("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", "hex");
Expand Down Expand Up @@ -122,7 +124,7 @@ async function hmacSha256Sign(key: Buffer, msg: Buffer): Promise<Buffer> {
const result = hmac.digest();
return result;
}
async function hmacSha256Verify(key, msg, sig) {
async function hmacSha256Verify(key: Buffer, msg: Buffer, sig: Buffer): Promise<boolean> {
const expectedSig = await hmacSha256Sign(key, msg);
return equalConstTime(expectedSig, sig);
}
Expand Down Expand Up @@ -267,7 +269,7 @@ export const decrypt = async function (privateKey: Buffer, opts: Ecies, _padding
const encryptionKey = hash.slice(0, 32);
const macKey = hash.slice(32);
const dataToMac = Buffer.concat([opts.iv, opts.ephemPublicKey, opts.ciphertext]);
const macGood = await hmacSha256Verify(macKey, dataToMac, opts.mac);
const macGood = await hmacSha256Verify(Buffer.from(macKey), dataToMac, opts.mac);
if (!macGood && padding === false) {
return decrypt(privateKey, opts, true);
} else if (!macGood && padding === true) {
Expand Down
2 changes: 1 addition & 1 deletion torus.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
// cjs: false,
analyzerMode: "disabled",
};
20 changes: 1 addition & 19 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
{
"compilerOptions": {
"rootDir": ".",
"moduleResolution": "node",
"strict": false,
"module": "es6",
"target": "es6",
"lib": ["ES2020", "DOM"],
"sourceMap": true,
"esModuleInterop": true,
"noImplicitThis": true,
"declaration": true,
"declarationDir": "./types",
"outDir": "./dist",
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"resolveJsonModule": true
},
"include": ["src", "test"],
"exclude": ["node_modules", "dist"]
"extends": "@toruslabs/config/tsconfig.default.json"
}

0 comments on commit 5624bd8

Please sign in to comment.