Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function convertToInternalPubKey(rawPubKey: string, type: string): InternalPubKey {
const res: InternalPubKey = {
type: type,
value: ByteBuffer.fromHex(rawPubKey).toString('base64')
};
return res;
}
// convert raw sig to internal sig format
static fromHex(hex) {
const buffer = new ByteBuffer.fromHex(hex);
return new Privatekey(buffer);
}
this.getBytes = function (trs) {
return ByteBuffer.fromHex(trs.asset.storage.content).toBuffer();
};
fromHex(hex) {
var b = ByteBuffer.fromHex(hex, ByteBuffer.LITTLE_ENDIAN);
return this.fromByteBuffer(b);
}
_.forEach(this.outputs, output => {
let ser_buf = output.serialize();
let ser_out = $.hexToBytes(ser_buf.toHex(0, ser_buf.capacity()));
data.push(ser_out);
});
const hex = $.bytesToHex(_.flatten(data));
const hash = shajs("sha256")
.update(
shajs("sha256")
.update(hex, "hex")
.digest("hex"),
"hex"
)
.digest("hex");
const buffer = new ByteBuffer.fromHex(hash);
return buffer;
}
}
static fromBase58(base58addr) {
const address_data = addr.fromBase58Check(base58addr);
const hash = new ByteBuffer.fromHex(address_data.hash.toString("hex"));
const type = Address.versions[address_data.version]["type"];
const network = Address.versions[address_data.version]["network"];
return new Address(type, hash, network);
}
var buffer = ByteBuffer.fromHex(msg.new_reset_public_key);
encodedMsg.new_reset_public_key = getByteArray(buffer);
}
if ('new_transaction_public_key' in msg) {
var buffer = ByteBuffer.fromHex(msg.new_transaction_public_key);
encodedMsg.new_transaction_public_key = getByteArray(buffer);
}
if ('new_app_public_key' in msg) {
var buffer = ByteBuffer.fromHex(msg.new_app_public_key);
encodedMsg.new_app_public_key = getByteArray(buffer);
}
if ('validator_public_key' in msg) {
var buffer = ByteBuffer.fromHex(msg.validator_public_key);
encodedMsg.validator_public_key = getByteArray(buffer);
}
return encodedMsg;
}
export function encodeTx(
msgs: StdMsg[],
rawPubKey: string[],
rawSigDER: string[],
maxFeeInCoin: number
): string {
var sigs: StdSignature[] = [];
for (var _i = 0; _i < rawPubKey.length; _i++) {
const stdSig: StdSignature = {
pub_key: convertToInternalPubKey(rawPubKey[_i], _TYPE.PubKeySecp256k1),
signature: ByteBuffer.fromHex(rawSigDER[_i]).toString('base64')
};
sigs.push(stdSig);
}
const stdTx: StdTx = {
msg: msgs,
signatures: sigs,
fee: getFee(maxFeeInCoin)
};
const authStdTx: StdMsg = {
type: 'auth/StdTx',
value: number2StringInObject(stdTx)
};
const jsonStr = JSON.stringify(authStdTx);
return ByteBuffer.btoa(jsonStr);
p2shHash() {
const sha256 = shajs("sha256")
.update(this.body.toHex(0, this.body.capacity()), "hex")
.digest("hex");
const ripe = new ripemd160().update(sha256, "hex").digest("hex");
return new ByteBuffer.fromHex(ripe);
}
_.forEach(this.inputs, input => {
let txid = $.hexToBytes(input.txid).reverse();
let vout = $.numToBytes(input.out, 4);
data.push(txid);
data.push(vout);
});
const hex = $.bytesToHex(_.flatten(data));
const hash = shajs("sha256")
.update(
shajs("sha256")
.update(hex, "hex")
.digest("hex"),
"hex"
)
.digest("hex");
const buffer = new ByteBuffer.fromHex(hash);
return buffer;
}