How to use bufio - 10 common examples

To help you get started, we’ve selected a few bufio 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 handshake-org / hsd / test / util / common.js View on Github external
function serializeUndo(items) {
  const bw = bio.write();

  for (const item of items) {
    bw.writeI64(item.value);
    bw.writeVarBytes(item.script.encode());
  }

  return bw.render();
}
github handshake-org / hsd / lib / primitives / tx.js View on Github external
signature(index, prev, value, key, type) {
    if (type == null)
      type = hashType.ALL;

    const hash = this.signatureHash(index, prev, value, type);
    const sig = secp256k1.sign(hash, key);
    const bw = bio.write(65);

    bw.writeBytes(sig);
    bw.writeU8(type);

    return bw.render();
  }
github handshake-org / hsd / lib / net / bip150.js View on Github external
static address(key) {
    const bw = bio.write(27);
    bw.writeU8(0x0f);
    bw.writeU16BE(0xff01);
    bw.writeBytes(hash160.digest(key));
    bw.writeChecksum(hash256.digest);
    return base58.encode(bw.render());
  }
}
github handshake-org / hsd / lib / wallet / wallet.js View on Github external
getToken(nonce) {
    if (!this.master.key)
      throw new Error('Cannot derive token.');

    const key = this.master.key.derive(44, true);

    const bw = bio.write(36);
    bw.writeBytes(key.privateKey);
    bw.writeU32(nonce);

    return hash256.digest(bw.render());
  }
github handshake-org / hsd / lib / wallet / wallet.js View on Github external
getToken(nonce) {
    if (!this.master.key)
      throw new Error('Cannot derive token.');

    const key = this.master.key.derive(44, true);

    const bw = bio.write(36);
    bw.writeBytes(key.privateKey);
    bw.writeU32(nonce);

    return blake2b.digest(bw.render());
  }
github handshake-org / hsd / lib / wallet / masterkey.js View on Github external
writeKey() {
    const bw = bio.write(this.keySize());

    bw.writeBytes(this.key.chainCode);
    bw.writeBytes(this.key.privateKey);

    if (this.mnemonic) {
      bw.writeU8(1);
      this.mnemonic.write(bw);
    } else {
      bw.writeU8(0);
    }

    return bw.render();
  }
github handshake-org / hsd / lib / script / opcode.js View on Github external
encode() {
    const size = this.getSize();
    return this.write(bio.write(size)).render();
  }
github handshake-org / faucet-tool / lib / mnemonic.js View on Github external
toRaw(writer) {
    const size = this.getSize();
    return this.toWriter(bio.write(size)).render();
  }
github handshake-org / hsd / migrate / chaindb2to3.js View on Github external
function entryToRaw(entry, main) {
  const bw = bio.write(116 + 1);

  bw.writeU32(entry.version);
  bw.writeHash(entry.prevBlock);
  bw.writeHash(entry.merkleRoot);
  bw.writeU32(entry.time);
  bw.writeU32(entry.bits);
  bw.writeU32(entry.nonce);
  bw.writeU32(entry.height);
  bw.writeBytes(entry.chainwork.toArrayLike(Buffer, 'le', 32));
  bw.writeU8(main ? 1 : 0);

  return bw.render();
}
github handshake-org / hsd / lib / primitives / abstractblock.js View on Github external
toHead() {
    const size = this.sizeHead();
    return this.writeHead(bio.write(size)).render();
  }

bufio

Buffer and serialization utilities for javascript

MIT
Latest version published 2 months ago

Package Health Score

75 / 100
Full package analysis

Popular bufio functions