Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public static pubkeyToAddress(pubkey: PubkeyBundle): Address {
if (pubkey.algo !== Algorithm.Ed25519 || pubkey.data.length !== 32) {
throw new Error("Not a valid ed25519 public key");
}
const suffix = constants.addressSuffix;
// https://github.com/prolina-foundation/snapshot-validator/blob/35621c7/src/lisk.cpp#L26
const hash = new Sha256(pubkey.data).digest();
const firstEightBytes = Array.from(hash.slice(0, 8));
const addressString = Long.fromBytesLE(firstEightBytes, true).toString(10) + suffix;
return addressString as Address;
}
export function transactionId(
unsigned: UnsignedTransaction,
creationTime: ReadonlyDate,
primarySignature: FullSignature,
): TransactionIdBytes {
const serialized = Serialization.serializeTransaction(
unsigned,
creationTime,
constants.transactionSerializationOptions,
);
const hash = new Sha256(serialized).update(primarySignature.signature).digest();
const idString = Long.fromBytesLE(Array.from(hash.slice(0, 8)), true).toString(10);
return Encoding.toAscii(idString) as TransactionIdBytes;
}
queue.prototype.long = function () {
return long.fromBytesLE(this.skip(8)).toNumber();
}
async function decode (genericDecoder, buf, flag = 0) {
let result = null
if (flag === 1) {
result = {
value: Long.fromBytesLE(buf.slice(0)).toNumber(),
length: 8
}
} else {
result = {
value: buf.readInt32LE(0),
length: 4
}
}
return result
}
export function bigIntFromBytes(bytes: string): Long {
const buff = Buffer.from(bytes, 'hex');
let data = Array.from(buff.subarray(0));
const b = data[data.length - 1];
if (b >> 7 === 1) {
data = data.concat(Array(8 - data.length).fill(255));
}
return Long.fromBytesLE(data);
}
function parseTagData(tagType, buffer) {
if (!buffer.readInt32LE) buffer = Buffer.from(buffer)
if (tagType === 'Z') return readNullTerminatedStringFromBuffer(buffer)
if (tagType === 'A') return String.fromCharCode(buffer[0])
if (tagType === 'I') {
const val = Long.fromBytesLE(buffer)
if (
val.greaterThan(Number.MAX_SAFE_INTEGER) ||
val.lessThan(Number.MIN_SAFE_INTEGER)
)
throw new CramUnimplementedError('integer overflow')
return val.toNumber()
}
if (tagType === 'i') return buffer.readInt32LE(0)
if (tagType === 's') return buffer.readInt16LE(0)
if (tagType === 'S') return buffer.readUInt16LE(0)
if (tagType === 'c') return buffer.readInt8(0)
if (tagType === 'C') return buffer.readUInt8(0)
if (tagType === 'f') return buffer.readFloatLE(0)
if (tagType === 'H') {
const hex = readNullTerminatedStringFromBuffer(buffer)
return Number.parseInt(hex.replace(/^0x/, ''), 16)
async function get64 (buffer, offset = 0) {
return {
value: Long.fromBytesLE(buffer.slice(offset)).toString(),
length: 8
}
}
readLong() {
const size = BinaryUtils.getSize(BinaryUtils.TYPE_CODE.LONG)
this._ensureSize(size);
const value = Long.fromBytesLE([...this._buffer.slice(this._position, this._position + size)]);
this._position += size;
return value;
}
async function getU64 (buffer, offset = 0) {
return {
value: Long.fromBytesLE(buffer.slice(offset), true).toString(),
length: 8
}
}