How to use the long.fromBytesLE function in long

To help you get started, we’ve selected a few long examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github iov-one / iov-core / packages / iov-lisk / src / derivation.ts View on Github external
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;
  }
github iov-one / iov-core / packages / iov-rise / src / serialization.ts View on Github external
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;
}
github co3moz / knightonline-js / src / core / utils / unit.js View on Github external
queue.prototype.long = function () {
  return long.fromBytesLE(this.skip(8)).toNumber();
}
github gd-com / utils / src / get / get_var / integer.js View on Github external
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
}
github ontio / ontology-ts-sdk / src / utils.ts View on Github external
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);
}
github GMOD / cram-js / src / cramFile / slice / decodeRecord.js View on Github external
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)
github gd-com / utils / src / get / get_64.js View on Github external
async function get64 (buffer, offset = 0) {
  return {
    value: Long.fromBytesLE(buffer.slice(offset)).toString(),
    length: 8
  }
}
github gridgain / gridgain / modules / platforms / nodejs / lib / internal / MessageBuffer.js View on Github external
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;
    }
github gd-com / utils / src / get / get_u64.js View on Github external
async function getU64 (buffer, offset = 0) {
  return {
    value: Long.fromBytesLE(buffer.slice(offset), true).toString(),
    length: 8
  }
}