Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
bb.writeInt(transaction.timestamp);
bb.append(transaction.senderPublicKey, "hex");
bb.writeLong(transaction.fee);
if(transaction.vendorFieldHex){
bb.writeByte(transaction.vendorFieldHex.length/2);
bb.append(transaction.vendorFieldHex, "hex");
}
else {
bb.writeByte(0x00);
}
switch (transaction.type) {
case 0: // Transfer
bb.writeLong(transaction.amount);
bb.writeInt(transaction.expiration);
bb.append(bs58check.decode(transaction.recipientId));
break;
case 1: // Signature
bb.append(transaction.asset.signature.publicKey,"hex");
break;
case 2: // Delegate
var delegateBytes = new Buffer(transaction.asset.delegate.username, "utf8");
bb.writeByte(delegateBytes.length/2);
bb.append(delegateBytes,"hex");
break;
case 3: // Vote
var voteBytes = transaction.asset.votes.map(function(vote){
return (vote[0] == "+" ? "01" : "00") + vote.slice(1);
}).join("");
function getAddress (d, compressed) {
var Q = curve.G.multiply(d).getEncoded(compressed)
var hash = hash160(Q)
var payload = Buffer.allocUnsafe(21)
payload.writeUInt8(0x00, 0) // XXX TODO FIXME bitcoin only??? damn you BIP38
hash.copy(payload, 1)
return bs58check.encode(payload)
}
function fromBase58Check(address) {
const payload = bs58check.decode(address);
// TODO: 4.0.0, move to "toOutputScript"
if (payload.length < 21)
throw new TypeError(address + ' is too short');
if (payload.length > 21)
throw new TypeError(address + ' is too long');
const version = payload.readUInt8(0);
const hash = payload.slice(1);
return { version, hash };
}
exports.fromBase58Check = fromBase58Check;
function fromBase58Check(address) {
const payload = bs58check.decode(address);
// TODO: 4.0.0, move to "toOutputScript"
if (payload.length < 21) throw new TypeError(address + ' is too short');
if (payload.length > 21) throw new TypeError(address + ' is too long');
const version = payload.readUInt8(0);
const hash = payload.slice(1);
return { version, hash };
}
exports.fromBase58Check = fromBase58Check;
function getAddress(publicKey, version){
var pubKeyRegex = /^[0-9A-Fa-f]{66}$/;
if(!version){
version = networkVersion;
}
if (!pubKeyRegex.test(publicKey))
throw "publicKey is invalid";
var buffer = crypto_utils.ripemd160(new Buffer(publicKey, "hex"));
var payload = new Buffer(21);
payload.writeUInt8(version, 0);
buffer.copy(payload, 1);
return bs58check.encode(payload);
}
if (transaction.vendorField) {
const vf = Buffer.from(transaction.vendorField, 'utf8')
bb.writeByte(vf.length)
bb.append(vf)
} else if (transaction.vendorFieldHex) {
bb.writeByte(transaction.vendorFieldHex.length / 2)
bb.append(transaction.vendorFieldHex, 'hex')
} else {
bb.writeByte(0x00)
}
if (transaction.type === TRANSACTION_TYPES.TRANSFER) {
bb.writeUInt64(+new Bignum(transaction.amount).toFixed())
bb.writeUInt32(transaction.expiration || 0)
bb.append(bs58check.decode(transaction.recipientId))
} else if (transaction.type === TRANSACTION_TYPES.VOTE) {
const voteBytes = transaction.asset.votes
.map(vote => (vote[0] === '+' ? '01' : '00') + vote.slice(1))
.join('')
bb.writeByte(transaction.asset.votes.length)
bb.append(voteBytes, 'hex')
} else if (transaction.type === TRANSACTION_TYPES.SECOND_SIGNATURE) {
bb.append(transaction.asset.signature.publicKey, 'hex')
} else if (transaction.type === TRANSACTION_TYPES.DELEGATE_REGISTRATION) {
const delegateBytes = Buffer.from(
transaction.asset.delegate.username,
'utf8',
)
bb.writeByte(delegateBytes.length)
bb.append(delegateBytes, 'hex')
} else if (transaction.type === TRANSACTION_TYPES.MULTI_SIGNATURE) {
get: function () {
return bs58check.encode(serialize(this, this.versions.public, this.publicKey))
}
})
function toBase58Check(hash, version) {
typeforce(types.tuple(types.Hash160bit, types.UInt8), arguments);
const payload = Buffer.allocUnsafe(21);
payload.writeUInt8(version, 0);
hash.copy(payload, 1);
return bs58check.encode(payload);
}
exports.toBase58Check = toBase58Check;
lazy.prop(o, 'address', () => {
if (!o.hash) return;
const payload = Buffer.allocUnsafe(21);
payload.writeUInt8(o.network!.scriptHash, 0);
o.hash.copy(payload, 1);
return bs58check.encode(payload);
});
lazy.prop(o, 'hash', () => {
lazy.prop(o, 'address', () => {
if (!o.hash) return;
const payload = Buffer.allocUnsafe(21);
payload.writeUInt8(network.pubKeyHash, 0);
o.hash.copy(payload, 1);
return bs58check.encode(payload);
});
lazy.prop(o, 'hash', () => {