commit 1dd2618d2046474a5e9e322ae07be8ae8d13aaf7
parent b8a3d14385c88bdc9847351bd5dc0e9177ce4063
Author: Jared Tobin <jared@jtobin.io>
Date: Fri, 26 Jun 2020 11:23:53 +0400
co: throw on null input
Resolves #33.
Various functions could hang if a null value was entered, converted to
BN, and looped over.
Diffstat:
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/internal/co.js b/src/internal/co.js
@@ -83,8 +83,12 @@ const end = (a, b, c) =>
* @param {String} hex
* @return {String}
*/
-const hex2patp = (hex) =>
- patp(new BN(hex, 'hex'))
+const hex2patp = (hex) => {
+ if (hex === null) {
+ throw new Error('hex2patp: null input')
+ }
+ return patp(new BN(hex, 'hex'))
+}
/**
* Convert a @p-encoded string to a hex-encoded string.
@@ -417,6 +421,9 @@ const eqPatq = (p, q) => {
* @return {String}
*/
const patp = (arg) => {
+ if (arg === null) {
+ throw new Error('patp: null input')
+ }
const n = new BN(arg)
const sxz = ob.fein(n)