Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
input.witness.pushData(Buffer.alloc(8, 0x00));
input.witness.pushData(Buffer.alloc(8, 0x00));
input.witness.compile();
cb.inputs.push(input);
// Reward output.
const output = new Output();
output.address.fromPubkeyhash(Buffer.alloc(20, 0x00));
output.value = this.getReward();
cb.outputs.push(output);
// Setup coinbase flags (variable size).
input.witness.setData(0, this.coinbaseFlags);
input.witness.setData(1, random.randomBytes(8));
input.witness.compile();
// Setup output address (variable size).
output.address = this.address;
// Add any claims.
for (const claim of this.claims) {
const input = new Input();
input.witness.items.push(claim.blob);
cb.inputs.push(input);
let flags = 0;
if (claim.weak)
[2, 3],
[5, 7]
];
for (const [name, modulus] of moduli) {
for (const [g, h] of gh) {
const ver = new Goo(modulus, g, h, null);
for (const bits of sizes) {
const goo = new Goo(modulus, g, h, bits);
console.log('Generating 5 vectors for %s.', name);
console.log(' g=%d, h=%d, bits=%d', g, h, bits);
for (let i = 0; i < 5; i++) {
const msg = SHA256.digest(random.randomBytes(32));
const key = rsa.privateKeyGenerate(bits);
const s_prime = goo.generate();
const C1 = goo.challenge(s_prime, key);
const ct = goo.encrypt(s_prime, key);
const sig = goo.sign(msg, s_prime, key);
const result = ver.verify(msg, sig, C1);
assert.strictEqual(result, true);
vectors.push({
group: name,
groupBits: goo.bits,
g: g,
h: h,
bits: bits,
key: rsa.privateKeyExportJWK(key),
[x, y] = [y, x];
return Buffer.concat([x, y]);
}
console.log('Fuzzing with random bytes.');
for (let i = 0; i < 1000000; i++) {
let msg, sig, C1;
if (i % 100000 === 0)
console.log(' Iterations: %d', i);
switch (rand(4)) {
case 0:
msg = rng.randomBytes(32);
sig = rng.randomBytes(SIG_LENGTH);
C1 = rng.randomBytes(goo.size);
break;
case 1:
msg = rng.randomBytes(32);
sig = rng.randomBytes(SIG_LENGTH + 1);
C1 = rng.randomBytes(goo.size + 1);
break;
case 2:
msg = rng.randomBytes(32);
sig = rng.randomBytes(SIG_LENGTH - 1);
C1 = rng.randomBytes(goo.size - 1);
break;
case 3:
msg = rng.randomBytes(32);
sig = rng.randomBytes(SIG_LENGTH);
C1 = rng.randomBytes(goo.size);
break;
case 1:
msg = rng.randomBytes(32);
sig = rng.randomBytes(SIG_LENGTH + 1);
C1 = rng.randomBytes(goo.size + 1);
break;
case 2:
msg = rng.randomBytes(32);
sig = rng.randomBytes(SIG_LENGTH - 1);
C1 = rng.randomBytes(goo.size - 1);
break;
case 3:
msg = rng.randomBytes(32);
sig = rng.randomBytes(SIG_LENGTH);
C1 = rng.randomBytes(goo.size);
switch (rand(4)) {
case 0:
msg = Buffer.alloc(0);
break;
case 1:
sig = Buffer.alloc(0);
break;
case 2:
C1 = Buffer.alloc(0);
break;
case 3:
msg = Buffer.alloc(0);
sig = Buffer.alloc(0);
C1 = Buffer.alloc(0);
break;
}
function randomWitness(redeem) {
const size = rand(1, 100);
const witness = new Witness();
for (let i = 0; i < size; i++) {
const len = rand(0, 100);
witness.push(random.randomBytes(len));
}
if (redeem)
witness.push(redeem);
witness.compile();
return witness;
}
async _encrypt(passphrase, clean) {
if (this.encrypted)
throw new Error('Master key is already encrypted.');
if (!passphrase)
throw new Error('No passphrase provided.');
const raw = this.writeKey();
const iv = random.randomBytes(16);
this.stop();
const key = await this.derive(passphrase);
const data = aes.encipher(raw, key, iv);
this.key = null;
this.mnemonic = null;
this.encrypted = true;
this.iv = iv;
this.ciphertext = data;
if (!clean) {
cleanse(key);
return null;
}
function randomMultisig() {
const n = rand(1, 16);
const m = rand(1, n);
const keys = [];
for (let i = 0; i < n; i++) {
const len = rand(0, 2) === 0 ? 33 : 65;
keys.push(random.randomBytes(len));
}
return Script.fromMultisig(m, n, keys);
}
function randomWitnessPubkeyhash() {
return Script.fromProgram(0, random.randomBytes(20));
}
function randomOutputScript() {
const size = rand(1, 10000);
return Script.fromRaw(random.randomBytes(size));
}
getEntropy() {
if (!this.entropy)
this.entropy = random.randomBytes(this.bits / 8);
assert(this.bits / 8 === this.entropy.length);
return this.entropy;
}