We will be sunsetting Advisor during Jan, 2026 and will instead be providing information in Snyk Security DB.

You can begin to take advantage of Snyk Security DB today for a unified, package-centric experience.

How to use the @nimiq/core/dist/node.SerialBuffer function in @nimiq/core

To help you get started, we’ve selected a few @nimiq/core 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 hector-nimiq / nimeth-atomicswap / src / nim.js View on Github external
function generateHtlcTransaction(sender, recipient, hash, value, timeout) {
  const hashAlgo = Nimiq.Hash.Algorithm.SHA256
  const hashCount = 1
  value = Nimiq.Policy.coinsToSatoshis(value)
  timeout = $.blockchain.height + timeout
  const bufferSize = sender.serializedSize
    + recipient.serializedSize
    + /* hashAlgo */ 1
    + hash.byteLength
    + /* hashCount */ 1
    + /* timeout */ 4;
  const buffer = new Nimiq.SerialBuffer(bufferSize);
  sender.serialize(buffer);
  recipient.serialize(buffer);
  buffer.writeUint8(hashAlgo);
  buffer.write(hash);
  buffer.writeUint8(hashCount);
  buffer.writeUint32(timeout);

  recipient = Nimiq.Address.CONTRACT_CREATION;
  const recipientType = Nimiq.Account.Type.HTLC;
  const flags = Nimiq.Transaction.Flag.CONTRACT_CREATION;
  return new Nimiq.ExtendedTransaction(sender, Nimiq.Account.Type.BASIC, recipient, recipientType,
    value, 0, $.blockchain.height + 1, flags, buffer);
}
github hector-nimiq / nimeth-atomicswap / src / nim.js View on Github external
async function resolveHTLC(address, recipient, hashRoot, preImage) {
  address = Nimiq.Address.fromString(address)
  recipient = Nimiq.Address.fromString(recipient)
  const account = await $.consensus.getAccount(address)
  const tx = new Nimiq.ExtendedTransaction(
    address, Nimiq.Account.Type.HTLC,
    recipient, Nimiq.Account.Type.BASIC,
    account.balance, 0,
    $.blockchain.height + 1,
    Nimiq.Transaction.Flag.NONE, new Uint8Array(0))
  const sig = Nimiq.Signature.create($.wallet.keyPair.privateKey, $.wallet.publicKey, tx.serializeContent())
  const sigProof = new Nimiq.SignatureProof($.wallet.publicKey, new Nimiq.MerklePath([]), sig)
  tx.proof = new Nimiq.SerialBuffer(3 + 2 * Nimiq.Hash.SIZE.get(Nimiq.Hash.Algorithm.SHA256) + sigProof.serializedSize)
  tx.proof.writeUint8(Nimiq.HashedTimeLockedContract.ProofType.REGULAR_TRANSFER)
  tx.proof.writeUint8(Nimiq.Hash.Algorithm.SHA256)
  tx.proof.writeUint8(1)
  Nimiq.Hash.fromHex(hashRoot.slice(2)).serialize(tx.proof)
  Nimiq.Hash.fromHex(preImage.slice(2)).serialize(tx.proof)
  sigProof.serialize(tx.proof)
  await sendTransaction(tx)
}
github hector-nimiq / nimeth-atomicswap / src / nim.js View on Github external
async function refundHTLC(address, recipient) {
  address = Nimiq.Address.fromString(address)
  recipient = Nimiq.Address.fromString(recipient)
  const account = await $.consensus.getAccount(address)
  const tx = new Nimiq.ExtendedTransaction(
    address, Nimiq.Account.Type.HTLC,
    recipient, Nimiq.Account.Type.BASIC,
    account.balance, 0,
    $.blockchain.height + 1,
    Nimiq.Transaction.Flag.NONE, new Uint8Array(0))
  const sig = Nimiq.Signature.create($.wallet.keyPair.privateKey, $.wallet.publicKey, tx.serializeContent())
  const sigProof = new Nimiq.SignatureProof($.wallet.publicKey, new Nimiq.MerklePath([]), sig)
  tx.proof = new Nimiq.SerialBuffer(1 + sigProof.serializedSize)
  tx.proof.writeUint8(Nimiq.HashedTimeLockedContract.ProofType.TIMEOUT_RESOLVE)
  sigProof.serialize(tx.proof)
  await waitForBlock(account.timeout)
  await sendTransaction(tx)
}