How to use the bsv.Script function in bsv

To help you get started, we’ve selected a few bsv 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 unwriter / datapay / index.js View on Github external
var _script = function(options) {
  var s = null;
  if (options.data) {
    if (Array.isArray(options.data)) {
      s = new bitcoin.Script();
      if (options.safe) {
        s.add(bitcoin.Opcode.OP_FALSE);
      }
      // Add op_return
      s.add(bitcoin.Opcode.OP_RETURN);
      options.data.forEach(function(item) {
        // add push data
        if (item.constructor.name === 'ArrayBuffer') {
          let buffer = _Buffer.Buffer.from(item)
          s.add(buffer)
        } else if (item.constructor.name === 'Buffer') {
          s.add(item)
        } else if (typeof item === 'string') {
          if (/^0x/i.test(item)) {
            // ex: 0x6d02
            s.add(Buffer.from(item.slice(2), "hex"))
github libitx / proxypay / src / proxy-payment.js View on Github external
_buildScript(data) {
    const script = new bsv.Script()
    script.add(bsv.Opcode.OP_RETURN)
    data.forEach(item => {
      // Hex string
      if (typeof item === 'string' && /^0x/i.test(item)) {
        script.add(_Buffer.from(item.slice(2), 'hex'))
      // Opcode number
      } else if (typeof item === 'number' || item === null) {
        script.add(item || 0)
      // Opcode
      } else if (typeof item === 'object' && item.hasOwnProperty('op')) {
        script.add({ opcodenum: item.op })
      // All else
      } else {
        script.add(_Buffer.from(item))
      }
    })
github libitx / preserve-cli / lib / commands / deploy.js View on Github external
.then(utxos => {
        const tx      = new bsv.Transaction().change(process.env.ADDRESS),
              script  = new bsv.Script();
        let   fee     = 0;

        // Add OP_RETURN output
        script.add(bsv.Opcode.OP_RETURN);
        data.forEach(item => {
          // Hex string
          if (typeof item === 'string' && /^0x/i.test(item)) {
            script.add(Buffer.from(item.slice(2), 'hex'))
          // Opcode number
          } else if (typeof item === 'number') {
            script.add(item)
          // Opcode
          } else if (typeof item === 'object' && item.hasOwnProperty('op')) {
            script.add({ opcodenum: item.op })
          // All else
          } else {
github libitx / proxypay / src / proxy-payment.js View on Github external
_buildOutput(attrs) {
    let script;
    if (attrs.script) {
      script = attrs.script
    } else if (attrs.data) {
      script = this._buildScript(attrs.data)
    } else {
      script = bsv.Script(bsv.Address(attrs.to))
    }

    return new bsv.Transaction.Output({
      script,
      satoshis: attrs.satoshis || 0
    })
  }