How to use the cbor.encode 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 / jserver / TEST_VERSIONS / jamlib2.js View on Github external
console.log("Looking for.. [" + fentry + "].... " + cmsg["actname"]);
	if (fentry === undefined) {
		// send an REXEC-NAK message: {REXEC-NAK, ASY, ACTIVITY, actid, device_id, error_code}
		var nmsg = {"cmd": "REXEC-NAK", "opt": "ASY", "actname": "ACTIVITY", "actid": cmsg["actid"], "actarg": cmsg["actarg"], "args": ["NOT-FOUND"]};
		var encodemsg = cbor.encode(nmsg);
		sock.send(encodemsg);
		console.log("Sent the message..NOT-FOUND");
	}
	else
	{
		// create actid, select lease-value, put entry in the activity table
		// send [REXEC-ACK ASY ACTIVITY actid device_id lease-value (arg0) ]
		activityTable[cmsg["actid"]] = undefined;

		var nmsg = {"cmd": "REXEC-ACK", "opt": "ASY", "actname": "ACTIVITY", "actid": cmsg["actid"], "actarg": cmsg["actarg"], "args": []};
		var encodemsg = cbor.encode(nmsg);
		sock.send(encodemsg);

		// Run function
		var res = fentry.func.apply(this, cmsg["args"]);
		activityTable[cmsg["actid"]] = res;
		console.log("Execution complete.. results stored...");
	}
}
github citelab / JAMScript / lib / jserver / TEST_VERSIONS / jamlib-old.js View on Github external
var fentry = funcRegistry[cmsg["actname"]];
	console.log("Looking for.. [" + fentry + "].... " + cmsg["actname"]);
	if (fentry === undefined) {
		// send an REXEC-NAK message: {REXEC-NAK, SYN, ACTIVITY, actid, device_id, error_code}
		var nmsg = {"cmd": "REXEC-NAK", "opt": "SYN", "actname": "ACTIVITY", 
		"actid": cmsg["actid"], "actarg": cmsg["actarg"], "args": ["NOT-FOUND"]};
		var encodemsg = cbor.encode(nmsg);
		sock.send(encodemsg);
		console.log("Sent the message..NOT-FOUND");
	}
	else
	if (checkArgsType(cmsg["args"], fentry.mask) !== true) {
		// send an REXEC-NAK message: {REXEC-NAK, SYN, ACTIVITY, actid, device_id, error_code}
		var nmsg = {"cmd": "REXEC-NAK", "opt": "SYN", "actname": "ACTIVITY", 
		"actid": cmsg["actid"], "actarg": cmsg["actarg"], "args": ["ILLEGAL-PARAMS"]};
		var encodemsg = cbor.encode(nmsg);
		sock.send(encodemsg);
		console.log("Sent the message..ILLEGAL-PARAMS");
	}
	else
	{
		// create actid, select lease-value, put entry in the activity table
		// send [REXEC-ACK SYN ACTIVITY actid device_id lease-value (arg0) ]
		activityTable[cmsg["actid"]] = undefined;

		var nmsg = {"cmd": "REXEC-ACK", "opt": "SYN", "actname": "ACTIVITY", 
		"actid": cmsg["actid"], "actarg": cmsg["actarg"], "args": []};
		var encodemsg = cbor.encode(nmsg);
		sock.send(encodemsg);

		// Run function
		var res = fentry.func.apply(this, cmsg["args"]);
github elevenyellow / coinfy / src / api / coins / ADA.js View on Github external
const derivationPath = [HARDENED_THRESHOLD, childIndex]

        addressPayload = encryptDerivationPath(derivationPath, hdPassphrase)
        addressAttributes = new Map([[1, cbor.encode(addressPayload)]])
        derivedHdNode = deriveHdNode(parentHdNode, childIndex)
    }
    const addressRoot = getAddressRoot(derivedHdNode, addressPayload)

    const addressType = 0 // Public key address

    const addressData = [addressRoot, addressAttributes, addressType]

    const addressDataEncoded = cbor.encode(addressData)

    const address = base58.encode(
        cbor.encode([
            new cbor.Tagged(24, addressDataEncoded),
            crc32Unsigned(addressDataEncoded)
        ])
    )

    return {
        address,
        childIndex,
        hdNode: derivedHdNode
    }
}
github IoTKETI / Mobius / pxy_ws.js View on Github external
rsp_message['m2m:rsp'].pc[prop][prop2]['@'] = {rn : rsp_message['m2m:rsp'].pc[prop][prop2][prop3]};
                                    delete rsp_message['m2m:rsp'].pc[prop][prop2][prop3];
                                }
                            }
                        }
                    }
                }
            }
        }

        var bodyString = js2xmlparser.parse("m2m:rsp", rsp_message['m2m:rsp']);

        ws_conn.sendUTF(bodyString.toString());
    }
    else if (bodytype === 'cbor') { // 'cbor'
        bodyString = cbor.encode(rsp_message['m2m:rsp']).toString('hex');
        var bytearray = Buffer.from(bodyString, 'hex');
        ws_conn.send(bytearray);
    }
    else { // 'json'
        ws_conn.sendUTF(JSON.stringify(rsp_message['m2m:rsp']));
    }
}
github citelab / JAMScript / lib / jserver / TEST_VERSIONS / jamlib-old.js View on Github external
adminProcessor(rep, msg, function(obj) {
				var encode = cbor.encode(obj);
				rep.send(encode);
				console.log(obj);
			});
		} catch(err) {
github citelab / JAMScript / lib / jserver / OLD_VERSIONS / jserver-notworking.js View on Github external
function sendMsg(sock, obj) {
	console.log("Sending.." + obj["opt"]);

	console.log(obj);

	try {
		var encoded = cbor.encode(obj);
		sock.send(encoded);
	} catch (err) {
		console.log(err);
	}
	console.log("End sendMsg");
}
github Emurgo / tangata-manu / src / blockchain / utils.js View on Github external
outputs: outputs.map(out => {
      const [address, value] = out
      return { address: bs58.encode(cbor.encode(address)), value }
    }),
    witnesses: witnesses.map(w => {
github elevenyellow / coinfy / src / api / coins / ADA.js View on Github external
function hashBlake2b256(input) {
    return Buffer.from(blakejs.blake2b(cbor.encode(input), null, 32))
}
github citelab / JAMScript / lib / jserver / OLD_VERSIONS / jserver-notworking.js View on Github external
function sendPong(sock, msg, callback) {
	var src = msg["opt"];
	msg["cmd"] = "PONG";
	msg["opt"] = getMyType();

	var encoded = cbor.encode(msg);
    sock.send(encoded);
	callback(src, msg);
}
github vacuumlabs / adalite / transaction.js View on Github external
encodeCBOR(encoder) {
    return encoder.pushAny([
      this.type,
      new cbor.Tagged(24, cbor.encode([this.publicString, this.signature]))
    ]);
  }
}

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