Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function accumulatorToBN(accumulator, numLimbs) {
const shift = 256;
let newBN = (new BN(accumulator[0].toString(16), 16))
for (let i = 1; i < numLimbs; i++) {
newBN.iushln(shift);
const limb = (new BN(accumulator[i].toString(16), 16))
newBN.iadd(limb);
}
return newBN;
}
function newBigNumber(value) {
var hex = new BigNumber(value).toString(16);
return new BN(hex, 16);
}
value: function(extra) {
var value = new BN(utils.randomHexString(seed + '-numberValue-' + extra, 1, size / 8).substring(2), 16);
if (sign) {
var signBit = (new BN(1)).shln(size - 1);
if (!signBit.and(value).isZero()) {
value = value.maskn(size - 1).mul(new BN(-1));
}
}
if (value.isNeg()) {
return '-0x' + value.toString('hex').substring(1);
}
return '0x' + value.toString('hex');
}
}
function hrpToSat (hrpString, outputString) {
let millisatoshisBN = hrpToMillisat(hrpString, false)
if (!millisatoshisBN.mod(new BN(1000, 10)).eq(new BN(0, 10))) {
throw new Error('Amount is outside of valid range')
}
let result = millisatoshisBN.div(new BN(1000, 10))
return outputString ? result.toString() : result
}
function hrpToSat (hrpString, outputString) {
let millisatoshisBN = hrpToMillisat(hrpString, false)
if (!millisatoshisBN.mod(new BN(1000, 10)).eq(new BN(0, 10))) {
throw new Error('Amount is outside of valid range')
}
let result = millisatoshisBN.div(new BN(1000, 10))
return outputString ? result.toString() : result
}
function satToHrp (satoshis) {
if (!satoshis.toString().match(/^\d+$/)) {
throw new Error('satoshis must be an integer')
}
let millisatoshisBN = new BN(satoshis, 10)
return millisatToHrp(millisatoshisBN.mul(new BN(1000, 10)))
}
hexToGroupScalar(hex, canBeZero = false) {
const hexBN = new BN(hex.slice(2), 16);
if (!hexBN.lt(bn128.curve.n)) {
this.errors.push(errors.codes.SCALAR_TOO_BIG);
}
if (!canBeZero && hexBN.eq(ZERO_BN)) {
this.errors.push(errors.codes.SCALAR_IS_ZERO);
}
return hexBN.toRed(bn128.groupReduction);
}
}
constructor(ctx) {
this.zero = new BN(0);
this.one = new BN(1);
this.n = new BN('14fef784d91e20718aee8ef1', 16);
this.nSquare = this.n.mul(this.n);
this.red = BN.red(this.n);
this.redSquare = BN.red(this.nSquare);
this.g = this.n.add(this.one).toRed(this.redSquare);
this.log = ctx.logger || console;
}
const toBN = number => {
try {
if (typeof number === 'number' && number > 0) {
const numStr = Number(number).toLocaleString('fullwide', { useGrouping: false });
return new BN(numStr, 10);
}
return numberToBN(number);
} catch (error) {
throw new Error(`${error} Given value: "${number}"`);
}
};
function getHexPayload(from, amount) {
let paddedAddress = new BN(from, 16).toString(16, 64);
let paddedAmount = new BN(amount, 16).toString(16, 64);
return paddedAddress + paddedAmount;
}