Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
selectedArg = Buffer.from(selectedArg, 'hex');
} else if (Buffer.isBuffer(selectedArg)) {
// Force adding a 0x00 into the data since that's how it will be encoded in OP_RETURN field
if (selectedArg.length === 0) {
selectedArg = Buffer.from('00', 'hex');
}
} else {
throw new Error('invalid argument type should be Buffer or a hex string: ' + selectedArg);
}
usedArgs.push(selectedArg);
}
if (!usedArgs || !usedArgs.length) {
throw new Error('insufficient index args');
}
const bufferWriter = new bsv.encoding.BufferWriter();
for (const field of usedArgs) {
let bf = field;
if (!Buffer.isBuffer(field)) {
bf = new bsv.encoding.BufferReader(field);
bf = bf.buf;
}
console.log('bf', bf);
bufferWriter.write(bf);
}
const appData = bufferWriter.toBuffer();
const signature = bsv.Message(appData).sign(bsv.PrivateKey(payload.key))
const verified = bsv.Message(appData).verify(payload.address, signature);
if (!verified) {
throw new Error('signArguments - Signature verification failure: ' + signature);
}
selectedArg = Buffer.from('00', 'hex');
}
} else {
throw new Error('invalid argument type should be Buffer or a hex string: ' + selectedArg);
}
usedArgs.push(selectedArg);
}
if (!usedArgs || !usedArgs.length) {
throw new Error('insufficient index args');
}
const bufferWriter = new bsv.encoding.BufferWriter();
for (const field of usedArgs) {
let bf = field;
if (!Buffer.isBuffer(field)) {
bf = new bsv.encoding.BufferReader(field);
bf = bf.buf;
}
console.log('bf', bf);
bufferWriter.write(bf);
}
const appData = bufferWriter.toBuffer();
const signature = bsv.Message(appData).sign(bsv.PrivateKey(payload.key))
const verified = bsv.Message(appData).verify(payload.address, signature);
if (!verified) {
throw new Error('signArguments - Signature verification failure: ' + signature);
}
return signature;
}
'use strict';
var bsv = require('bsv');
var $ = bsv.util.preconditions;
var Buffer = require('buffer').Buffer;
var reverse = require('buffer-reverse');
var BufferReader = bsv.encoding.BufferReader;
var BufferWriter = bsv.encoding.BufferWriter;
var _ = bsv.deps._;
/**
* A constructor for inventory related Bitcoin messages such as
* "getdata", "inv" and "notfound".
* @param {Object} obj
* @param {Number} obj.type - Inventory.TYPE
* @param {Buffer} obj.hash - The hash for the inventory
* @constructor
*/
function Inventory(obj) {
this.type = obj.type;
if (!Buffer.isBuffer(obj.hash)) {
throw new TypeError('Unexpected hash, expected to be a buffer');
}
this.hash = obj.hash;
'use strict';
var bsv = require('bsv');
var $ = bsv.util.preconditions;
var Buffer = require('buffer').Buffer;
var reverse = require('buffer-reverse');
var BufferReader = bsv.encoding.BufferReader;
var BufferWriter = bsv.encoding.BufferWriter;
var _ = bsv.deps._;
/**
* A constructor for inventory related Bitcoin messages such as
* "getdata", "inv" and "notfound".
* @param {Object} obj
* @param {Number} obj.type - Inventory.TYPE
* @param {Buffer} obj.hash - The hash for the inventory
* @constructor
*/
function Inventory(obj) {
this.type = obj.type;
if (!Buffer.isBuffer(obj.hash)) {
throw new TypeError('Unexpected hash, expected to be a buffer');
}