Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
confirmNumber_dice(input){
/* Equivalent of solidity hash function:
function confirm(bytes32 _s) public returns(uint256){
return uint256 (sha3(_s));
}
*/
let hash = '0x'+Eth.ABI.soliditySHA3(['bytes32'],[ input ]).toString('hex')
let confirm = bigInt(hash,16).divmod(65536).remainder.value
return confirm
}
confirmNumber_blackjack(input){
async function getStartPositionForEnd() {
try {
const head = await store.readHeadPosition()
// Edge case where start position is 0 (beginning of time) and the stream is empty.
if (head === '0') {
return BigInteger.zero
}
return BigInteger(head).plus(1)
} catch (error) {
logger.error(
'Unable to get stream information. Dropping subscription and disposing.',
error
)
await dropAndDispose()
return BigInteger(-1)
}
}
public run(abs_start, abs_end_param, update_cb) {
const that = this;
const CHUNK = bigInt(1000000);
that.CHUNKM = CHUNK.add(bigInt.minusOne);
const start = bigInt(abs_start);
const abs_end = bigInt(abs_end_param);
that.abs_end = abs_end;
that.start = start;
that.update_cb = update_cb;
return;
}
encode(integer: bigInteger.BigInteger): Uint8Array {
if (integer.isNegative()) {
throw new Error("uinteger shouldn't be negative");
}
if (integer.bitLength().greater(bigInteger(64))) {
throw new Error("integer is too big");
}
const buf = Buffer.alloc(10);
let tempInt = integer;
let i = 0;
while (tempInt.geq(bigInteger(0x80))) {
buf[i] = tempInt
.mod(0x80)
.or(0x80)
.toJSNumber();
tempInt = tempInt.shiftRight(7);
i += 1;
}
buf[i] = tempInt.toJSNumber();
return buf.slice(0, i + 1);
},
export function readSignedInt(hex: string): number {
const positive = (Buffer.from(hex.slice(0, 2), 'hex')[0] & 0x40) ? false : true;
//@ts-ignore
const arr = Buffer.from(hex, 'hex').map((v, i) => i === 0 ? v & 0x3f : v & 0x7f);
let n = bigInt.zero;
for (let i = arr.length - 1; i >= 0; i--) {
if (i === 0) {
n = n.or(arr[i]);
} else {
n = n.or(bigInt(arr[i]).shiftLeft(7 * i - 1));
}
}
return positive ? n.toJSNumber() : n.negate().toJSNumber();
}
static construct(n, b) {
if (typeof n === 'number'){
return bigInt.randBetween(bigInt.zero, bigInt(2).pow(n) );
} else if (typeof n === 'string' ) {
if (typeof b === 'number') {
this.n = bigInt(n, b);
}
this.n = bigInt(n);
} else
this.n = n;
return this.n;
}
function polymod(data) {
const GENERATOR = [0x98f2bc8e61, 0x79b76d99e2, 0xf33e5fb3c4, 0xae2eabe2a8, 0x1e4f43e470];
let checksum = bigInt(1);
for (let i = 0; i < data.length; ++i) {
const value = data[i];
const topBits = checksum.shiftRight(35);
checksum = checksum.and(0x07ffffffff).shiftLeft(5).xor(value);
for (let j = 0; j < GENERATOR.length; ++j) {
if (topBits.shiftRight(j).and(1).equals(1)) {
checksum = checksum.xor(GENERATOR[j]);
}
}
}
return checksum.xor(1);
}