How to use the cbor.decodeFirstSync function in cbor

To help you get started, we’ve selected a few cbor 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 citelab / JAMScript / lib / jamserver / jamdatastream.js View on Github external
var dest = datastream.datasource.getDestination();

        if (e) {
            datastream.isBusy = false;
            throw e;
        } else {
            if (response === undefined) {
                let hasData = datastream.hasData;
                datastream.isBusy = false;
                if( hasData )
                    datastream.request_value_refresh();
                return;
            }

            for (var i = 0; i < response.length; i++) {
                var dval = cbor.decodeFirstSync(response[i]);
                var log = dval.value;
                var timestamp = dval.timestamp;

                // try {
                //     log = cbor.decodeFirstSync(log);
                //     // if (debug) console.log(log);
                // } catch(e) {
                //     console.log("WARN! Error decoding data.. ", log)
                // }
                // }

                //console.log("Before log transform:", log);

                entry = {
                    log: datastream.transformer(log, datastream),
                    time_stamp: timestamp
github hyperledger / sawtooth-core / sdk / examples / intkey_javascript / integer_key_handler.js View on Github external
const _applySet = (context, address, name, value) => (possibleAddressValues) => {
  let stateValueRep = possibleAddressValues[address]

  let stateValue
  if (stateValueRep && stateValueRep.length > 0) {
    stateValue = cbor.decodeFirstSync(stateValueRep)
    if (stateValue[name]) {
      throw new InvalidTransaction(
        `Verb is "set" but Name already in state, Name: ${name} Value: ${stateValue[name]}`)
    }
  }

  // 'set' passes checks so store it in the state
  if (!stateValue) {
    stateValue = {}
  }

  stateValue[name] = value

  return _setEntry(context, address, stateValue)
}
github smartcontractkit / chainlink / evm-test-helpers / src / helpers.ts View on Github external
export function decodeDietCBOR(hexstr: string) {
  const buf = hexToBuf(hexstr)

  return cbor.decodeFirstSync(addCBORMapDelimiters(buf))
}
github ethereum / source-verify / monitor.js View on Github external
let cborDecode = function(bytecode)
{
    let cborLength = bytecode[bytecode.length - 2] * 0x100 + bytecode[bytecode.length - 1]
    return cbor.decodeFirstSync(new Buffer(bytecode.slice(bytecode.length - 2 - cborLength, -2)))
}
github ethereum / source-verify / injector.js View on Github external
let cborDecode = function(bytecode)
{
    let cborLength = bytecode[bytecode.length - 2] * 0x100 + bytecode[bytecode.length - 1]
    return cbor.decodeFirstSync(new Buffer(bytecode.slice(bytecode.length - 2 - cborLength, -2)))
}
github smartcontractkit / chainlink / evm / v0.5 / src / helpers.ts View on Github external
export function decodeDietCBOR(hexstr: string) {
  const buf = hexToBuf(hexstr)

  return cbor.decodeFirstSync(addCBORMapDelimiters(buf))
}
github smartcontractkit / chainlink / evm / src / helpers.ts View on Github external
export const decodeDietCBOR = (data: any): any => {
  return cbor.decodeFirstSync(autoAddMapDelimiters(data))
}
github hyperledger / sawtooth-core / sdk / examples / intkey_javascript / integer_key_handler.js View on Github external
const _applyOperator = (verb, op) => (context, address, name, value) => (possibleAddressValues) => {
  let stateValueRep = possibleAddressValues[address]
  if (!stateValueRep || stateValueRep.length === 0) {
    throw new InvalidTransaction(`Verb is ${verb} but Name is not in state`)
  }

  let stateValue = cbor.decodeFirstSync(stateValueRep)
  if (stateValue[name] == null || stateValue[name] == undefined) {
    throw new InvalidTransaction(`Verb is ${verb} but Name is not in state`)
  }

  const result = op(stateValue[name], value)

  if (result < MIN_VALUE) {
    throw new InvalidTransaction(
      `Verb is ${verb}, but result would be less than ${MIN_VALUE}`)
  }

  if (result > MAX_VALUE) {
    throw new InvalidTransaction(
      `Verb is ${verb}, but result would be greater than ${MAX_VALUE}`)
  }

cbor

Encode and parse data in the Concise Binary Object Representation (CBOR) data format (RFC8949).

MIT
Latest version published 3 months ago

Package Health Score

78 / 100
Full package analysis