diff --git a/package.json b/package.json index 65ba239..ff3441b 100644 --- a/package.json +++ b/package.json @@ -39,9 +39,8 @@ "benchmark": "node -r ./.babel-register test/benchmarks" }, "dependencies": { - "@chainsafe/bls-keygen": "^0.2.0", - "@chainsafe/eth2-bls-wasm": "^0.5.0", - "assert": "^1.4.1" + "@chainsafe/bls-keygen": "^0.3.0", + "@chainsafe/eth2-bls-wasm": "^0.5.0" }, "devDependencies": { "@babel/cli": "^7.8.4", @@ -78,5 +77,8 @@ "typescript": "^3.7.5", "webpack": "^4.30.0", "webpack-cli": "^3.3.2" + }, + "resolutions": { + "v8-profiler-next": "1.3.0" } } diff --git a/src/helpers/index.ts b/src/helpers/index.ts new file mode 100644 index 0000000..037b90c --- /dev/null +++ b/src/helpers/index.ts @@ -0,0 +1 @@ +export * from "./utils"; \ No newline at end of file diff --git a/src/helpers/utils.ts b/src/helpers/utils.ts index 7430d7d..1f768bc 100644 --- a/src/helpers/utils.ts +++ b/src/helpers/utils.ts @@ -1,17 +1,9 @@ -import assert from "assert"; import {PUBLIC_KEY_LENGTH, SIGNATURE_LENGTH} from "../constants"; -/** - * Pads byte array with zeroes on left side up to desired length. - * Throws if source is larger than desired result. - * @param source - * @param length - */ -export function padLeft(source: Uint8Array, length: number): Buffer { - assert(source.length <= length, "Given array must be smaller or equal to desired array size"); - const result = Buffer.alloc(length, 0); - result.set(source, length - source.length); - return result; +export function assert(condition: unknown, message = "Assertion failed"): asserts condition { + if(!condition) { + throw new Error(message) + } } export const EMPTY_PUBLIC_KEY = Buffer.alloc(PUBLIC_KEY_LENGTH); diff --git a/src/index.ts b/src/index.ts index b398620..6dfc0ac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ import {PrivateKey} from "./privateKey"; import {PublicKey} from "./publicKey"; import {Signature} from "./signature"; import {PUBLIC_KEY_LENGTH} from "./constants"; -import assert from "assert"; +import {assert} from "./helpers"; export {Keypair, PrivateKey, PublicKey, Signature}; diff --git a/src/privateKey.ts b/src/privateKey.ts index deb8029..dfce61e 100644 --- a/src/privateKey.ts +++ b/src/privateKey.ts @@ -1,5 +1,5 @@ import {SECRET_KEY_LENGTH} from "./constants"; -import assert from "assert"; +import {assert} from "./helpers"; import {SecretKeyType} from "@chainsafe/eth2-bls-wasm"; import {generateRandomSecretKey} from "@chainsafe/bls-keygen"; import {getContext} from "./context"; diff --git a/src/publicKey.ts b/src/publicKey.ts index c994489..725ed76 100644 --- a/src/publicKey.ts +++ b/src/publicKey.ts @@ -2,7 +2,7 @@ import {PrivateKey} from "./privateKey"; import {PublicKeyType} from "@chainsafe/eth2-bls-wasm"; import {getContext} from "./context"; import {PUBLIC_KEY_LENGTH} from "./constants"; -import assert from "assert"; +import {assert} from "./helpers"; import {Signature} from "./signature"; import {EMPTY_PUBLIC_KEY} from "./helpers/utils"; diff --git a/src/signature.ts b/src/signature.ts index 08c38e6..897c96b 100644 --- a/src/signature.ts +++ b/src/signature.ts @@ -1,4 +1,4 @@ -import assert from "assert"; +import {assert} from "./helpers"; import {FP_POINT_LENGTH} from "./constants"; import {SignatureType} from "@chainsafe/eth2-bls-wasm"; import {getContext} from "./context"; diff --git a/yarn.lock b/yarn.lock index 296f5d6..3c0a153 100644 --- a/yarn.lock +++ b/yarn.lock @@ -799,26 +799,25 @@ "@assemblyscript/loader" "^0.9.2" buffer "^5.4.3" -"@chainsafe/bls-hd-key@^0.1.0": - version "0.1.0" - resolved "https://registry.yarnpkg.com/@chainsafe/bls-hd-key/-/bls-hd-key-0.1.0.tgz#5e51de16801f4b4b421e418f0d1ef0692df0c585" - integrity sha512-VZj+Ml4YTPz+d/K2n9q/9bLlIJnTr/xdAC5w1eCvIFtcQrZCY1Zw+bCcXKX1q6sbZpO9xhyuoepJzJX9VkMPqw== +"@chainsafe/bls-hd-key@^0.2.0": + version "0.2.0" + resolved "https://registry.yarnpkg.com/@chainsafe/bls-hd-key/-/bls-hd-key-0.2.0.tgz#90aaf030150de64099e1fb27582b27bbe5ce5309" + integrity sha512-ps10jd99UWcm1qPo4spD/6hxFor9fsDgB0s2wJuFKqPdM2R+4LCowhv5kdGgGs3VIN1H8l+CgO08yC7X0WlBDQ== dependencies: assert "^2.0.0" bcrypto "^5.0.4" bn.js "^5.1.1" buffer "^5.4.3" -"@chainsafe/bls-keygen@^0.2.0": - version "0.2.0" - resolved "https://registry.yarnpkg.com/@chainsafe/bls-keygen/-/bls-keygen-0.2.0.tgz#2089da875caff4334723c5ee45495e366dc57a2e" - integrity sha512-IcgOJ1UTiHX3T1FnSqTdf4gtavjpINPtmAwLZFQUxSuLPOfmxPPVN/yhAIYw5xCh9/mWkaFQ/dFUk6ys+BkfGQ== +"@chainsafe/bls-keygen@^0.3.0": + version "0.3.0" + resolved "https://registry.yarnpkg.com/@chainsafe/bls-keygen/-/bls-keygen-0.3.0.tgz#d7472a945f6f49b5cb357241bfba2f5c12a635c5" + integrity sha512-5Iq6E5E987hyio74G1fXPYI3t9iVeHxRX1tDMpnCV9T82rPz061yFsMz3W3aXE26+k6+fcz0bsYX3ijOizkx+A== dependencies: - "@chainsafe/bls-hd-key" "^0.1.0" - assert "^2.0.0" - bcrypto "^5.0.4" + "@chainsafe/bls-hd-key" "^0.2.0" bip39 "^3.0.2" buffer "^5.4.3" + randombytes "^2.1.0" "@chainsafe/eth2-bls-wasm@^0.5.0": version "0.5.0" @@ -1339,7 +1338,7 @@ asn1.js@^4.0.0: inherits "^2.0.1" minimalistic-assert "^1.0.0" -assert@^1.1.1, assert@^1.4.1: +assert@^1.1.1: version "1.5.0" resolved "https://registry.yarnpkg.com/assert/-/assert-1.5.0.tgz#55c109aaf6e0aefdb3dc4b71240c70bf574b18eb" integrity sha512-EDsgawzwoun2CZkCgtxJbv392v4nbk9XDD06zI+kQYoBM/3RBWLlEyJARDOmhAAosBjWACEkKL6S+lIZtcAubA== @@ -4360,6 +4359,11 @@ nan@^2.12.1, nan@^2.14.0: resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c" integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg== +nan@^2.14.1: + version "2.14.2" + resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.2.tgz#f5376400695168f4cc694ac9393d0c9585eeea19" + integrity sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ== + nanomatch@^1.2.9: version "1.2.13" resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119" @@ -5062,7 +5066,7 @@ querystring@0.2.0: resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620" integrity sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA= -randombytes@^2.0.0, randombytes@^2.0.1, randombytes@^2.0.5: +randombytes@^2.0.0, randombytes@^2.0.1, randombytes@^2.0.5, randombytes@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.1.0.tgz#df6f84372f0270dc65cdf6291349ab7a473d4f2a" integrity sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ== @@ -6252,12 +6256,12 @@ v8-compile-cache@^2.0.3: resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.1.0.tgz#e14de37b31a6d194f5690d67efc4e7f6fc6ab30e" integrity sha512-usZBT3PW+LOjM25wbqIlZwPeJV+3OSz3M1k1Ws8snlW39dZyYL9lOGC5FgPVHfk0jKmjiDV8Z0mIbVQPiwFs7g== -v8-profiler-next@^1.1.1: - version "1.2.1" - resolved "https://registry.yarnpkg.com/v8-profiler-next/-/v8-profiler-next-1.2.1.tgz#4dad63273503f180cdec8bf80c458c61d78e49c7" - integrity sha512-5YyzfBycl5HA3dx7AnmRosxr7m77OzhCANGl7AkeciHFw03NThHSerCpPgD1bztRvnQhmYrp7sAnwdQm+WwCfQ== +v8-profiler-next@1.3.0, v8-profiler-next@^1.1.1: + version "1.3.0" + resolved "https://registry.yarnpkg.com/v8-profiler-next/-/v8-profiler-next-1.3.0.tgz#7b8b01c353a5e4675eadcd720957f84a2882c84c" + integrity sha512-UrG750R9s43a3vInsLFHBnL8EbkSJ8d/yovYRKLk1myDeW2xdcQgcEKzVzlxLNDgULgDoLALn02VSw8BTH8M3w== dependencies: - nan "^2.14.0" + nan "^2.14.1" validate-npm-package-license@^3.0.1: version "3.0.4"