Skip to content

CBOR

Decode and encode CBOR and MessagePack, inspect security payloads, and import or export row files from SQL

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/cbor/index.md to help me query CBOR with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Fan a 3-item CBOR Sequence into one row per item.

Example output Β· captured
Connector release
v0.8.0
Engine
2.0.1
VGI protocol
3.4.0
SELECT idx, value FROM cbor.main.seq_decode(from_hex('010203')) ORDER BY idx
Result
idx value
0 1
1 2
2 3

Quick start

Choose where to run CBOR, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the release directly

Downloads the latest release for your platform and caches it locally.

ATTACH 'cbor' AS cbor (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-cbor'
);

3. Run a query

query.sql
SELECT idx, value FROM cbor.main.seq_decode(from_hex('010203')) ORDER BY idx
More example queries β†’
Technical details
Verified connector release
v0.8.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the release directly

Uses the verified release each time you attach the connector.

ATTACH 'cbor' AS cbor (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/[email protected]'
);

Overview

CBOR (RFC 8949) / MessagePack decode & encode plus tag-aware COSE / CWT / WebAuthn structural decode and bulk COPY import/export for SQL.

Catalog

Everything cbor exposes once attached β€” read straight from the worker's released build.

cbor 1 schema
main 1 view Β· 26 functions

CBOR / MessagePack / COSE / CWT / WebAuthn codec functions and bulk COPY formats.

Schema examples (10)
Examples (10)

Render a CBOR array blob as JSON text.

SELECT cbor.main.to_json(from_hex('83010203')) AS json;

Show a tag-1 epoch timestamp in human-readable diagnostic (EDN) notation.

SELECT cbor.main.diagnostic(from_hex('c11a514b67b0')) AS edn;

Encode a JSON array into deterministic CBOR and hex it.

SELECT to_hex(cbor.main.from_json('[1,2,3]')) AS hex;

Check that an untrusted blob is well-formed CBOR.

SELECT (cbor.main.well_formed(from_hex('83010203'))).ok AS ok;
6 more examples

Pull the issuer claim out of a bare CWT claim set.

SELECT (cbor.main.cwt_claims(from_hex('a10169636f61703a2f2f6173'))).iss AS iss;

Fan a 3-item CBOR Sequence into one row per item.

SELECT idx, value
FROM cbor.main.seq_decode(from_hex('010203'))
ORDER BY idx;
Result
idx value
0 1
1 2
2 3

Inventory COSE_Sign1-signed CWTs: the signing algorithm from each token's COSE header beside the subject and expiry from the claim set it signs, soonest expiry first.

SELECT (cbor.main.cwt_claims(t.token)).sub AS subject,
  (cbor.main.cose_headers(t.token)).alg AS alg,
  (cbor.main.cwt_claims(t.token)).exp AS expires
FROM (VALUES (from_hex('d28443a10126a104426b31582aa3017668747470733a2f2f6973737565722e6578616d706c6502696465766963652d3432041a6955b90044deadbeef')), (from_hex('d28443a10127a104426b325828a3017568747470733a2f2f6f746865722e6578616d706c6502686465766963652d37041a6553f10044deadbeef'))) AS t(token)
ORDER BY expires;

Migrate MessagePack frames to deterministic CBOR for byte-level dedupe: transcode each frame to CBOR, canonicalize it, and group by the canonical bytes. Frames 1 and 2 differ only in map key order, so they share one canonical encoding.

SELECT to_hex(cbor.main.canonical(cbor.main.msgpack_to_cbor(f.frame))) AS canonical_cbor,
  list(f.id ORDER BY f.id) AS frame_ids
FROM (VALUES (1, from_hex('82a16201a16102')), (2, from_hex('82a16102a16201')), (3, from_hex('82a16103a16201'))) AS f(id, frame)
GROUP BY canonical_cbor
ORDER BY canonical_cbor;

Screen inbound blobs for deterministic encoding: classify malformed ones by failure kind, and flag well-formed ones whose map keys are not in canonical order (blob 2 is out of order, blob 3 is truncated).

SELECT b.id, (cbor.main.well_formed(b.blob)).kind AS problem,
  cbor.main.canonical(b.blob) = b.blob AS is_canonical
FROM (VALUES (1, from_hex('a2616101616202')), (2, from_hex('a2616202616101')), (3, from_hex('a2616101'))) AS b(id, blob)
ORDER BY b.id;

Shred each enrollment's attestation object and join its algorithm name to the COSE registry to recover the numeric COSEAlgorithmIdentifier, checked against a relying-party allow-list of -7 (ES256) and -257 (RS256); the undecodable enrollment contributes no row.

SELECT e.user_name, w.fmt, w.alg, r.id AS alg_id,
  r.id IN (-7, -257) AS alg_allowed
FROM (VALUES ('alice', from_hex('a363666d74667061636b65646761747453746d74a363616c67266373696742dead637835638143300100686175746844617461588700000000000000000000000000000000000000000000000000000000000000004100000007111111111111111111111111111111110003cafe01a5010203262001215820aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa225820bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb')), ('bob', from_hex('00'))) AS e(user_name, att_obj),
     LATERAL cbor.main.webauthn_attestation(e.att_obj) AS w
JOIN cbor.main.cose_registry AS r ON r.registry = 'alg' AND r.name = w.alg
ORDER BY e.user_name;
Views
cose_registry 2 examples3 cols

IANA COSE registry (algorithms, key types, and curves) as a browsable lookup table: the numeric-label β†’ name mapping the COSE / COSE_Key decoders apply.

Columns
registry VARCHAR
Which IANA COSE registry the row belongs to: 'alg', 'kty', or 'crv'.
id INTEGER
The signed numeric COSE label (algorithm ids are typically negative, e.g. -7 for ES256).
name VARCHAR
The standard IANA name for the label (e.g. ES256, EdDSA, EC2, P-256).
Examples (2)

The COSE signature algorithms this worker recognizes, by id.

SELECT id, name
FROM cbor.main.cose_registry
WHERE registry = 'alg'
ORDER BY id;

Reverse a COSE algorithm name to its numeric label.

SELECT id
FROM cbor.main.cose_registry
WHERE registry = 'alg' AND name = 'ES256';
Link
Scalar functions
canonical (blob ANY, mode VARCHAR) +1 overload 2 examples

Re-encode CBOR into a deterministic core form (RFC 8949 Β§4.2.1)

Arguments
blob ANY
A CBOR-encoded BLOB to canonicalize.
mode VARCHAR
Which deterministic key ordering to apply: RFC 8949 Β§4.2.1 core, or CTAP2. Β· default "core"
Overloads
canonical(blob ANY) β†’ BLOBcanonical(blob ANY, mode VARCHAR) β†’ BLOB
ReturnsBLOB
Examples (2)

Canonicalize a map with CTAP2 ordering.

SELECT to_hex(cbor.main.canonical(from_hex('a2616201616101'), 'ctap2')) AS h;

Screen inbound blobs for deterministic encoding: classify malformed ones by failure kind, and flag well-formed ones whose map keys are not in canonical order (blob 2 is out of order, blob 3 is truncated).

SELECT b.id, (cbor.main.well_formed(b.blob)).kind AS problem,
  cbor.main.canonical(b.blob) = b.blob AS is_canonical
FROM (VALUES (1, from_hex('a2616101616202')), (2, from_hex('a2616202616101')), (3, from_hex('a2616101'))) AS b(id, blob)
ORDER BY b.id;
Link
cose_decode (blob ANY) 1 example

Structurally decode a COSE message (no crypto): tag, type, headers, payload, sig

Arguments
blob ANY
A COSE (RFC 9052) message BLOB β€” tagged (18/98/16/96/17/97/61) or a bare array.
ReturnsSTRUCT of 7 fields
STRUCT 7 fields
  • tagUBIGINT
  • msg_typeVARCHAR
  • protectedSTRUCT
    STRUCT 7 fields
    • algVARCHAR
    • critVARCHAR
    • content_typeVARCHAR
    • kidBLOB
    • ivBLOB
    • x5chainBLOB[]
    • x5tSTRUCT
      STRUCT 2 fields
      • hash_algVARCHAR
      • thumbprintBLOB
  • unprotectedSTRUCT
    STRUCT 7 fields
    • algVARCHAR
    • critVARCHAR
    • content_typeVARCHAR
    • kidBLOB
    • ivBLOB
    • x5chainBLOB[]
    • x5tSTRUCT
      STRUCT 2 fields
      • hash_algVARCHAR
      • thumbprintBLOB
  • payloadBLOB
  • signatureBLOB
  • recipientsVARCHAR
Example

Decode a real Ed25519-signed COSE_Sign1 (tag 18): message type, the EdDSA algorithm from its protected header, the kid from its unprotected header, and the payload text.

SELECT d.msg_type, d.protected.alg AS alg, decode(d.unprotected.kid) AS kid,
  decode(d.payload) AS payload
FROM (SELECT cbor.main.cose_decode(from_hex('d28443a10127a104426b3154546869732069732074686520636f6e74656e742e5840a2e8c26b43ae0f2656be31e71de37bd81c3d09254512828cc93efc791c3da942a622a3a93bfe3ecc3f65e210f0260f23c9bd4a1e15f820407735a0503920a203')) AS d) AS t;
Link
cose_headers (blob ANY) 1 example

Return the merged (protected over unprotected) COSE header STRUCT

Arguments
blob ANY
A COSE message BLOB.
ReturnsSTRUCT of 7 fields
STRUCT 7 fields
  • algVARCHAR
  • critVARCHAR
  • content_typeVARCHAR
  • kidBLOB
  • ivBLOB
  • x5chainBLOB[]
  • x5tSTRUCT
    STRUCT 2 fields
    • hash_algVARCHAR
    • thumbprintBLOB
Example

The algorithm name and key id from a real COSE_Sign1's merged headers (alg from the protected header, kid from the unprotected one).

SELECT h.alg, decode(h.kid) AS kid
FROM (SELECT cbor.main.cose_headers(from_hex('d28443a10127a104426b3154546869732069732074686520636f6e74656e742e5840a2e8c26b43ae0f2656be31e71de37bd81c3d09254512828cc93efc791c3da942a622a3a93bfe3ecc3f65e210f0260f23c9bd4a1e15f820407735a0503920a203')) AS h) AS t;
Link
cose_key (blob ANY) 1 example

Decode a COSE_Key into STRUCT(kty, kid, alg, crv, x, y, n, e)

Arguments
blob ANY
A COSE_Key (RFC 9052 Β§7) BLOB β€” e.g. a WebAuthn credentialPublicKey.
ReturnsSTRUCT of 8 fields
STRUCT 8 fields
  • ktyVARCHAR
  • kidBLOB
  • algVARCHAR
  • crvVARCHAR
  • xBLOB
  • yBLOB
  • nBLOB
  • eBLOB
Example

Key type of an EC2 / ES256 / P-256 COSE_Key.

SELECT (cbor.main.cose_key(from_hex('a3010203262001'))).kty AS kty;
Link
cose_payload (blob ANY) 1 example

Return the raw inner payload bytes of a COSE message

Arguments
blob ANY
A COSE message BLOB.
ReturnsBLOB
Example

Recover the signed payload of a real COSE_Sign1: its length and its text.

SELECT octet_length(p) AS n, decode(p) AS text
FROM (SELECT cbor.main.cose_payload(from_hex('d28443a10127a104426b3154546869732069732074686520636f6e74656e742e5840a2e8c26b43ae0f2656be31e71de37bd81c3d09254512828cc93efc791c3da942a622a3a93bfe3ecc3f65e210f0260f23c9bd4a1e15f820407735a0503920a203')) AS p) AS t;
Link
cose_x5chain (blob ANY) 1 example

Return the COSE x5chain DER certificate list (the vgi-x509 join key)

Arguments
blob ANY
A COSE message BLOB carrying an x5chain (label 33).
ReturnsBLOB[]
Example

Count the certificates in a COSE_Sign1's x5chain header and the size of the DER leaf certificate (a self-signed Ed25519 certificate).

SELECT len(cbor.main.cose_x5chain(m)) AS n_certs,
  octet_length(cbor.main.cose_x5chain(m)[1]) AS leaf_der_bytes
FROM (VALUES (from_hex('d28458eca20127182158e53081e2308195a003020102020101300506032b6570301b3119301706035504030c107667692d63626f72206578616d706c65301e170d3236303130313030303030305a170d3335313233303030303030305a301b3119301706035504030c107667692d63626f72206578616d706c65302a300506032b657003210088e359964555effc0bd60a0b4ae9aa1f106653e04bdced74176f747950dce53e300506032b65700341006bea80cb772e805ceea989e40422573f2e3094b3de1dccdcc55bd2ad74e513b804e5413e9283f59c86246e869013c8dd8cd42cc5b9e7b0c0e3bbb91dbd3dbb07a11822822f582063e60470a0c9f72fb314c8e9153c36a9f8a82eb9de55b6df3e6acd6fd9d2a8a454546869732069732074686520636f6e74656e742e5840af6e0122dd643ed73cc603af0562cb048ba06c72321317931b177202cf221057182714671a4aeaf3fb34aff397e966221853f3894adef01d3ec74f5c4afc1e03'))) AS t(m);
Link
cose_x5t (blob ANY) 1 example

Return the COSE x5t certificate thumbprint as a hex string (the vgi-x509 join key)

Arguments
blob ANY
A COSE message BLOB carrying an x5t (label 34) thumbprint.
ReturnsVARCHAR
Example

Read the SHA-256 x5t thumbprint of a COSE_Sign1 that also carries its signing certificate in x5chain, and confirm it is the SHA-256 of that DER certificate.

SELECT cbor.main.cose_x5t(m) AS x5t,
  cbor.main.cose_x5t(m) = sha256(cbor.main.cose_x5chain(m)[1]) AS matches_leaf
FROM (VALUES (from_hex('d28458eca20127182158e53081e2308195a003020102020101300506032b6570301b3119301706035504030c107667692d63626f72206578616d706c65301e170d3236303130313030303030305a170d3335313233303030303030305a301b3119301706035504030c107667692d63626f72206578616d706c65302a300506032b657003210088e359964555effc0bd60a0b4ae9aa1f106653e04bdced74176f747950dce53e300506032b65700341006bea80cb772e805ceea989e40422573f2e3094b3de1dccdcc55bd2ad74e513b804e5413e9283f59c86246e869013c8dd8cd42cc5b9e7b0c0e3bbb91dbd3dbb07a11822822f582063e60470a0c9f72fb314c8e9153c36a9f8a82eb9de55b6df3e6acd6fd9d2a8a454546869732069732074686520636f6e74656e742e5840af6e0122dd643ed73cc603af0562cb048ba06c72321317931b177202cf221057182714671a4aeaf3fb34aff397e966221853f3894adef01d3ec74f5c4afc1e03'))) AS t(m);
Link
cwt_claims (blob ANY) 2 examples

Decode a CWT claim set: STRUCT(iss, sub, aud, exp, nbf, iat, cti, extra)

Arguments
blob ANY
A CWT (RFC 8392) token BLOB, or a COSE message / tag-61 envelope wrapping one.
ReturnsSTRUCT of 8 fields
STRUCT 8 fields
  • issVARCHAR
  • subVARCHAR
  • audVARCHAR
  • expTIMESTAMP WITH TIME ZONE
  • nbfTIMESTAMP WITH TIME ZONE
  • iatTIMESTAMP WITH TIME ZONE
  • ctiBLOB
  • extraVARCHAR
Examples (2)

Issuer of a bare CWT claim set {1:'coap://as'}.

SELECT (cbor.main.cwt_claims(from_hex('a10169636f61703a2f2f6173'))).iss AS iss;

Inventory COSE_Sign1-signed CWTs: the signing algorithm from each token's COSE header beside the subject and expiry from the claim set it signs, soonest expiry first.

SELECT (cbor.main.cwt_claims(t.token)).sub AS subject,
  (cbor.main.cose_headers(t.token)).alg AS alg,
  (cbor.main.cwt_claims(t.token)).exp AS expires
FROM (VALUES (from_hex('d28443a10126a104426b31582aa3017668747470733a2f2f6973737565722e6578616d706c6502696465766963652d3432041a6955b90044deadbeef')), (from_hex('d28443a10127a104426b325828a3017568747470733a2f2f6f746865722e6578616d706c6502686465766963652d37041a6553f10044deadbeef'))) AS t(token)
ORDER BY expires;
Link
decode (blob ANY, mode VARCHAR) +1 overload 1 example

Decode a CBOR blob to its richest form (JSON in v1)

Arguments
blob ANY
A CBOR-encoded BLOB to decode.
mode VARCHAR
Decode mode. All currently produce JSON text (see the function note). Β· default "auto"
Overloads
decode(blob ANY) β†’ VARCHARdecode(blob ANY, mode VARCHAR) β†’ VARCHAR
ReturnsVARCHAR
Example

Decode the CBOR map {"a":1} forcing JSON mode.

SELECT cbor.main.decode(from_hex('a1616101'), 'json') AS d;
Link
diagnostic (blob ANY) 1 example

Render a CBOR blob in RFC 8949 Extended Diagnostic Notation (EDN)

Arguments
blob ANY
A CBOR-encoded BLOB to render in diagnostic notation.
ReturnsVARCHAR
Example

Diagnostic notation for [1,2,3].

SELECT cbor.main.diagnostic(from_hex('83010203')) AS edn;
Link
encode (value ANY, mode VARCHAR) +1 overload 1 example

Encode a DuckDB value as CBOR (shortest form)

Arguments
value ANY
The DuckDB value to encode as CBOR.
mode VARCHAR
How to encode: plain shortest-form, or a deterministic canonical ordering. Β· default "shortest"
Overloads
encode(value ANY) β†’ BLOBencode(value ANY, mode VARCHAR) β†’ BLOB
ReturnsBLOB
Example

Encode a struct to canonical-core CBOR.

SELECT to_hex(cbor.main.encode({'a': 1, 'b': 2}, 'canonical_core')) AS h;
Link
from_json (json ANY) 1 example

Encode a JSON string as core-deterministic CBOR

Arguments
json ANY
The JSON text to encode as CBOR.
ReturnsBLOB
Example

Encode a JSON array to CBOR and hex it.

SELECT to_hex(cbor.main.from_json('[1,2,3]')) AS h;
Link
is_valid (blob ANY) 1 example

Return true iff the blob is exactly one well-formed CBOR item (RFC 8949 Β§1.2)

Arguments
blob ANY
A BLOB to test for CBOR well-formedness.
ReturnsBOOLEAN
Example

A valid item vs trailing garbage.

SELECT cbor.main.is_valid(from_hex('01')) AS ok,
  cbor.main.is_valid(from_hex('01ff')) AS bad;
Link
msgpack_decode (blob ANY) 1 example

Decode a MessagePack blob to its richest form (JSON in v1)

Arguments
blob ANY
A MessagePack-encoded BLOB to decode.
ReturnsVARCHAR
Example

Decode a msgpack map to JSON.

SELECT cbor.main.msgpack_decode(from_hex('81a16101')) AS d;
Link
msgpack_encode (value ANY) 1 example

Encode a DuckDB value as MessagePack

Arguments
value ANY
The DuckDB value to encode as MessagePack.
ReturnsBLOB
Example

Encode a list to MessagePack.

SELECT to_hex(cbor.main.msgpack_encode([1,2,3])) AS h;
Link
msgpack_to_cbor (blob ANY) 2 examples

Transcode a MessagePack blob to CBOR bytes (the cross-format op)

Arguments
blob ANY
A MessagePack-encoded BLOB to transcode to CBOR.
ReturnsBLOB
Examples (2)

Transcode msgpack [1,2,3] to CBOR and hex it.

SELECT to_hex(cbor.main.msgpack_to_cbor(from_hex('93010203'))) AS h;

Migrate MessagePack frames to deterministic CBOR for byte-level dedupe: transcode each frame to CBOR, canonicalize it, and group by the canonical bytes. Frames 1 and 2 differ only in map key order, so they share one canonical encoding.

SELECT to_hex(cbor.main.canonical(cbor.main.msgpack_to_cbor(f.frame))) AS canonical_cbor,
  list(f.id ORDER BY f.id) AS frame_ids
FROM (VALUES (1, from_hex('82a16201a16102')), (2, from_hex('82a16102a16201')), (3, from_hex('82a16103a16201'))) AS f(id, frame)
GROUP BY canonical_cbor
ORDER BY canonical_cbor;
Link
msgpack_to_json (blob ANY) 1 example

Render a MessagePack blob as JSON (ext types as {ext_type,data}; ts ext β†’ instant)

Arguments
blob ANY
A MessagePack-encoded BLOB to render as JSON.
ReturnsVARCHAR
Example

Decode the msgpack array [1,2,3] to JSON.

SELECT cbor.main.msgpack_to_json(from_hex('93010203')) AS j;
Link
tags (blob ANY) 1 example

List every CBOR semantic tag with its path and value (RFC 8949 Β§3.4)

Arguments
blob ANY
A CBOR-encoded BLOB to walk for semantic tags.
ReturnsSTRUCT(tag UBIGINT, path VARCHAR, "value" VARCHAR)[]
Example

The single tag-1 epoch timestamp in 1(1363896240).

SELECT (cbor.main.tags(from_hex('c11a514b67b0'))[1]).tag AS tag;
Link
to_json (blob ANY) 1 example

Render a CBOR blob as canonical JSON text (byte strings as base64url)

Arguments
blob ANY
The CBOR-encoded bytes to render as JSON.
ReturnsVARCHAR
Example

Decode the CBOR array [1,2,3] to JSON.

SELECT cbor.main.to_json(from_hex('83010203')) AS j;
Link
untag (blob ANY, tag UBIGINT) 1 example

Return the value(s) under a CBOR semantic tag as a JSON array

Arguments
blob ANY
A CBOR-encoded BLOB to search for `tag`.
tag UBIGINT
The semantic tag number to extract (e.g. 0, 1, 2, 32).
ReturnsVARCHAR
Example

Pull the value under tag 1 (epoch time).

SELECT cbor.main.untag(from_hex('c11a514b67b0'), 1) AS v;
Link
webauthn_authdata (blob ANY) 1 example

Parse WebAuthn authenticatorData into a typed STRUCT (flags, AAGUID, cred key, …)

Arguments
blob ANY
A WebAuthn authenticatorData BLOB (the fixed rpIdHash/flags/signCount[+attested] layout).
ReturnsSTRUCT of 12 fields
STRUCT 12 fields
  • rp_id_hashBLOB
  • upBOOLEAN
  • uvBOOLEAN
  • beBOOLEAN
  • bsBOOLEAN
  • atBOOLEAN
  • edBOOLEAN
  • sign_countUINTEGER
  • aaguidVARCHAR
  • cred_idBLOB
  • cred_public_keySTRUCT
    STRUCT 8 fields
    • ktyVARCHAR
    • kidBLOB
    • algVARCHAR
    • crvVARCHAR
    • xBLOB
    • yBLOB
    • nBLOB
    • eBLOB
  • extensionsVARCHAR
Example

User-present flag and sign count of a minimal authData (no attested cred).

SELECT (cbor.main.webauthn_authdata(from_hex('00000000000000000000000000000000000000000000000000000000000000000100000005'))).sign_count AS sc;
Link
well_formed (blob ANY) 1 example

Diagnose CBOR well-formedness: STRUCT(ok BOOL, error VARCHAR, kind VARCHAR)

Arguments
blob ANY
A BLOB to diagnose for CBOR well-formedness.
ReturnsSTRUCT(ok BOOLEAN, "error" VARCHAR, kind VARCHAR)
Example

Diagnose a truncated blob: the array [1,2,3] with its last item cut off.

SELECT (cbor.main.well_formed(from_hex('830102'))).ok AS ok,
  (cbor.main.well_formed(from_hex('830102'))).kind AS kind;
Link
Table functions
cbor_copy (ignore_errors := BOOLEAN, row_format := VARCHAR) +1 overload 2 examples
Named arguments
ignore_errors := BOOLEAN
Skip incompatible rows with warnings. On a decode error, discard that file's unreadable remainder and continue with the next source (default false). Source-open failures still fail the COPY.
row_format := VARCHAR
How each row is framed as one item: 'map' (default) keys it by column name; 'array' writes the values positionally in column order.
Overloads
cbor_copy(ignore_errors BOOLEAN, row_format VARCHAR)cbor_copy(canonical VARCHAR, row_format VARCHAR)
Returns columns
id INTEGER
The item's value for the `id` column β€” by key name under `row_format 'map'`, by position under `row_format 'array'`.
name VARCHAR
The item's value for the `name` column. A nested value lands as its JSON text.
seen TIMESTAMP
The item's value for the `seen` column, read from an epoch instant. A key absent from the item reads as `NULL`.
Returns columns Β· depends on the arguments
Read direction β€” columns mirror the COPY target
id INTEGER
The item's value for the `id` column β€” by key name under `row_format 'map'`, by position under `row_format 'array'`.
name VARCHAR
The item's value for the `name` column. A nested value lands as its JSON text.
seen TIMESTAMP
The item's value for the `seen` column, read from an epoch instant. A key absent from the item reads as `NULL`.
Examples (2)

Export query results to a CBOR row file, one item per row.

COPY (SELECT 1 AS id, 'alpha' AS name) TO 'events.cbor' (FORMAT 'cbor.cbor');

Export positionally (each row an array in column order) for a more compact file.

COPY (SELECT 1 AS id, 'alpha' AS name) TO 'events_array.cbor' (FORMAT 'cbor.cbor', row_format 'array');
Link
msgpack_copy (ignore_errors := BOOLEAN, row_format := VARCHAR) +1 overload 2 examples
Named arguments
ignore_errors := BOOLEAN
Skip incompatible rows with warnings. On a decode error, discard that file's unreadable remainder and continue with the next source (default false). Source-open failures still fail the COPY.
row_format := VARCHAR
How each row is framed as one item: 'map' (default) keys it by column name; 'array' writes the values positionally in column order.
Overloads
msgpack_copy(ignore_errors BOOLEAN, row_format VARCHAR)msgpack_copy(row_format VARCHAR)
Returns columns
id INTEGER
The item's value for the `id` column β€” by key name under `row_format 'map'`, by position under `row_format 'array'`.
name VARCHAR
The item's value for the `name` column. A nested value lands as its JSON text.
seen TIMESTAMP
The item's value for the `seen` column, read from an epoch instant. A key absent from the item reads as `NULL`.
Returns columns Β· depends on the arguments
Read direction β€” columns mirror the COPY target
id INTEGER
The item's value for the `id` column β€” by key name under `row_format 'map'`, by position under `row_format 'array'`.
name VARCHAR
The item's value for the `name` column. A nested value lands as its JSON text.
seen TIMESTAMP
The item's value for the `seen` column, read from an epoch instant. A key absent from the item reads as `NULL`.
Examples (2)

Export query results to a MessagePack row file, one item per row.

COPY (SELECT 1 AS id, 'alpha' AS name) TO 'events.msgpack' (FORMAT 'cbor.msgpack');

Export positionally (each row an array in column order) for a more compact file.

COPY (SELECT 1 AS id, 'alpha' AS name) TO 'events_array.msgpack' (FORMAT 'cbor.msgpack', row_format 'array');
Link
seq_decode (blob BLOB) 2 examples

Decode a CBOR Sequence (RFC 8742) into one row per item

Arguments
blob BLOB
A CBOR Sequence (RFC 8742) β€” zero or more concatenated CBOR items.
Returns columns
idx BIGINT
Zero-based position of the item within the CBOR sequence.
value VARCHAR
The decoded item rendered as JSON text.
Examples (2)

Decode the 3-item CBOR sequence 01 02 03 into rows.

SELECT idx, value
FROM cbor.main.seq_decode(from_hex('010203'))
ORDER BY idx;
Result
idx value
0 1
1 2
2 3

Fan every row's sequence out beside its own id, as a correlated join.

SELECT t.id, s.idx, s.value
FROM (SELECT 1 AS id, from_hex('010203') AS b) t,
     cbor.main.seq_decode(t.b) s
ORDER BY t.id, s.idx;
Link
webauthn_attestation (att_obj BLOB) 2 examples

Decode a WebAuthn attestation object into typed columns

Arguments
att_obj BLOB
A CTAP2 / WebAuthn attestation object ({fmt, attStmt, authData}). A per-row input column: use it on a literal, a column, or under a correlated LATERAL join.
Returns columns
fmt VARCHAR
Attestation statement format (packed, fido-u2f, tpm, android-key, android-safetynet, apple, none).
aaguid VARCHAR
Authenticator AAGUID as a canonical UUID.
sign_count UINTEGER
Signature counter from the authenticator data.
rp_id_hash BLOB
SHA-256 of the Relying Party ID.
up BOOLEAN
User-present flag.
uv BOOLEAN
User-verified flag.
cred_id BLOB
Credential ID of the attested credential.
alg VARCHAR
COSE signature algorithm name (e.g. ES256).
sig BLOB
Attestation signature bytes.
x5c BLOB[]
Attestation certificate chain (DER); the join key to vgi-x509.
att_stmt VARCHAR
The full format-specific attestation statement rendered as JSON text.
Examples (2)

Shred a packed CTAP2 attestation object into one typed row.

SELECT fmt, aaguid, sign_count, alg
FROM cbor.main.webauthn_attestation(from_hex('a363666d74667061636b65646761747453746d74a363616c67266373696742dead637835638143300100686175746844617461588700000000000000000000000000000000000000000000000000000000000000004100000007111111111111111111111111111111110003cafe01a5010203262001215820aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa225820bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'));

Shred each enrollment's attestation object and join its algorithm name to the COSE registry to recover the numeric COSEAlgorithmIdentifier, checked against a relying-party allow-list of -7 (ES256) and -257 (RS256); the undecodable enrollment contributes no row.

SELECT e.user_name, w.fmt, w.alg, r.id AS alg_id,
  r.id IN (-7, -257) AS alg_allowed
FROM (VALUES ('alice', from_hex('a363666d74667061636b65646761747453746d74a363616c67266373696742dead637835638143300100686175746844617461588700000000000000000000000000000000000000000000000000000000000000004100000007111111111111111111111111111111110003cafe01a5010203262001215820aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa225820bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb')), ('bob', from_hex('00'))) AS e(user_name, att_obj),
     LATERAL cbor.main.webauthn_attestation(e.att_obj) AS w
JOIN cbor.main.cose_registry AS r ON r.registry = 'alg' AND r.name = w.alg
ORDER BY e.user_name;
Link

COPY formats

Attaching cbor also registers 2 file formats for DuckDB's own COPY statement, so you can load files into local tables and write query results out to files without a function call. The FORMAT name starts with the ATTACH alias β€” cbor with the Quick start above; use yours if you attach it under another name.

FORMAT 'cbor.cbor'

COPY … FROM Β· import COPY … TO Β· export

CBOR Row Files (COPY FROM / TO). Load a CBOR row file (CBOR Sequence (RFC 8742)) into the COPY target table

copy.sql
-- Export query results to a CBOR row file, one item per row.
COPY (SELECT 1 AS id, 'alpha' AS name) TO 'events.cbor' (FORMAT 'cbor.cbor')
copy.sql
-- Export positionally (each row an array in column order) for a more compact file.
COPY (SELECT 1 AS id, 'alpha' AS name) TO 'events_array.cbor' (FORMAT 'cbor.cbor', row_format 'array')

Options

Pass these inside the COPY statement's parentheses, after FORMAT. Unknown options are rejected.

row_formatVARCHAR
How each row is framed as one item: 'map' (default) keys it by column name; 'array' writes the values positionally in column order.
ignore_errorsBOOLEAN
Skip incompatible rows with warnings. On a decode error, discard that file's unreadable remainder and continue with the next source (default false). Source-open failures still fail the COPY.
canonicalVARCHAR
Deterministic map-key ordering to apply: 'core' (RFC 8949 Β§4.2.1) or 'ctap2'. Unset keeps ciborium's shortest-form output with keys in column order.
Full reference

Bulk import and export of CBOR row files. The file is a CBOR Sequence (RFC 8742) β€” one item per row, no container header β€” so it appends, streams, and round-trips between the two directions. The FORMAT identifier is scoped by the ATTACH alias:

COPY (<query>) TO '<path>' (FORMAT '<alias>.cbor');
COPY <table> FROM '<path>' (FORMAT '<alias>.cbor');

row_format 'map' (the default) keys each row by column name; row_format 'array' is positional. On read, ignore_errors true skips unusable rows with warnings. A decode error discards that file's unreadable remainder and continues with the next source; source-open failures still fail the COPY. Writes preserve source order. On write, canonical 'core' (RFC 8949 Β§4.2.1) or canonical 'ctap2' orders map keys deterministically, so the same rows always produce byte-identical output.

Paths are opened by the worker process, so they resolve against its filesystem and working directory rather than the client's β€” a containerized or remote worker needs a shared location, and absolute paths.

FORMAT 'cbor.msgpack'

COPY … FROM Β· import COPY … TO Β· export

MessagePack Row Files (COPY FROM / TO). Load a MessagePack row file (concatenated MessagePack items) into the COPY target table

copy.sql
-- Export query results to a MessagePack row file, one item per row.
COPY (SELECT 1 AS id, 'alpha' AS name) TO 'events.msgpack' (FORMAT 'cbor.msgpack')
copy.sql
-- Export positionally (each row an array in column order) for a more compact file.
COPY (SELECT 1 AS id, 'alpha' AS name) TO 'events_array.msgpack' (FORMAT 'cbor.msgpack', row_format 'array')

Options

Pass these inside the COPY statement's parentheses, after FORMAT. Unknown options are rejected.

row_formatVARCHAR
How each row is framed as one item: 'map' (default) keys it by column name; 'array' writes the values positionally in column order.
ignore_errorsBOOLEAN
Skip incompatible rows with warnings. On a decode error, discard that file's unreadable remainder and continue with the next source (default false). Source-open failures still fail the COPY.
Full reference

Bulk import and export of MessagePack row files. The file is a concatenated MessagePack items β€” one item per row, no container header β€” so it appends, streams, and round-trips between the two directions. The FORMAT identifier is scoped by the ATTACH alias:

COPY (<query>) TO '<path>' (FORMAT '<alias>.msgpack');
COPY <table> FROM '<path>' (FORMAT '<alias>.msgpack');

row_format 'map' (the default) keys each row by column name; row_format 'array' is positional. On read, ignore_errors true skips unusable rows with warnings. A decode error discards that file's unreadable remainder and continues with the next source; source-open failures still fail the COPY. Writes preserve source order.

Paths are opened by the worker process, so they resolve against its filesystem and working directory rather than the client's β€” a containerized or remote worker needs a shared location, and absolute paths.

Try these queries

Decode the CBOR array [1,2,3] to JSON.

SELECT cbor.main.to_json(from_hex('83010203')) AS j;

Uses to_json

Round-trip a JSON array through deterministic CBOR.

SELECT to_hex(cbor.main.from_json('[1,2,3]')) AS h;

Uses from_json

Structurally decode a COSE_Sign1 and read its algorithm name.

SELECT (cbor.main.cose_headers(from_hex('d28443a10126a04044deadbeef'))).alg AS alg;

Uses cose_headers

Show a tag-1 epoch timestamp in human-readable diagnostic (EDN) notation.

SELECT cbor.main.diagnostic(from_hex('c11a514b67b0')) AS edn

Uses diagnostic

Check that an untrusted blob is well-formed CBOR.

SELECT (cbor.main.well_formed(from_hex('83010203'))).ok AS ok

Uses well_formed

Pull the issuer claim out of a bare CWT claim set.

SELECT (cbor.main.cwt_claims(from_hex('a10169636f61703a2f2f6173'))).iss AS iss

Uses cwt_claims

33 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • I have a CBOR-encoded value stored as the hex string '83010203'. Convert the raw CBOR bytes into their JSON text representation.
  • Encode the JSON array [1,2,3] as CBOR bytes and return the result as an uppercase hex string.
  • This hex string is a CBOR-encoded map: 'a1616101'. Decode it to its JSON representation.
  • Take the structured value {'a': 1, 'b': 2}, serialize it to CBOR bytes, and then render those bytes back to JSON to confirm the round-trip.
  • This is a MessagePack-encoded value stored as hex '93010203'. Render it as JSON text.
  • Decode the MessagePack map with hex '81a16101' into its JSON representation.

CBOR is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.