pg_cardano

A suite of Cardano-related tools

Overview

PackageVersionCategoryLicenseLanguage
pg_cardano1.1.1FEATMITRust
IDExtensionBinLibLoadCreateTrustRelocSchema
2920pg_cardanoNoYesNoYesNoNo-
Relatedage hll rum pg_graphql pg_jsonschema jsquery pg_hint_plan hypopg

PG18 fix by https://github.com/Vonng/pg_cardano

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.1.11817161514pg_cardano-
RPMPIGSTY1.1.11817161514pg_cardano_$v-
DEBPIGSTY1.1.11817161514postgresql-$v-pg-cardano-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
PIGSTY 1.1.1
PIGSTY 1.1.1
PIGSTY 1.1.1
PIGSTY 1.1.1
PIGSTY 1.1.1
u22.x86_64
PIGSTY 1.1.1
PIGSTY 1.1.1
PIGSTY 1.1.1
PIGSTY 1.1.1
PIGSTY 1.1.1
u22.aarch64
PIGSTY 1.1.1
PIGSTY 1.1.1
PIGSTY 1.1.1
PIGSTY 1.1.1
PIGSTY 1.1.1
u24.x86_64
PIGSTY 1.1.1
PIGSTY 1.1.1
PIGSTY 1.1.1
PIGSTY 1.1.1
PIGSTY 1.1.1
u24.aarch64
PIGSTY 1.1.1
PIGSTY 1.1.1
PIGSTY 1.1.1
PIGSTY 1.1.1
PIGSTY 1.1.1

Build

You can build the RPM / DEB packages for pg_cardano using pig build:

pig build pkg pg_cardano         # build RPM / DEB packages

Install

You can install pg_cardano directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_cardano;          # Install for current active PG version
pig ext install -y pg_cardano -v 18  # PG 18
pig ext install -y pg_cardano -v 17  # PG 17
pig ext install -y pg_cardano -v 16  # PG 16
pig ext install -y pg_cardano -v 15  # PG 15
pig ext install -y pg_cardano -v 14  # PG 14
dnf install -y pg_cardano_18       # PG 18
dnf install -y pg_cardano_17       # PG 17
dnf install -y pg_cardano_16       # PG 16
dnf install -y pg_cardano_15       # PG 15
dnf install -y pg_cardano_14       # PG 14
apt install -y postgresql-18-pg-cardano   # PG 18
apt install -y postgresql-17-pg-cardano   # PG 17
apt install -y postgresql-16-pg-cardano   # PG 16
apt install -y postgresql-15-pg-cardano   # PG 15
apt install -y postgresql-14-pg-cardano   # PG 14

Create Extension:

CREATE EXTENSION pg_cardano;

Usage

pg_cardano: Cardano blockchain data types and cryptographic functions for PostgreSQL

The pg_cardano extension provides cryptographic and utility functions for working with Cardano blockchain data in PostgreSQL, including Base58, Bech32, CBOR, Blake2b, Ed25519, and Shelley address utilities.

CREATE EXTENSION pg_cardano;

Base58 Encoding/Decoding

SELECT cardano.base58_encode('Cardano'::bytea);
-- '3Z6ioYHE3x'

SELECT cardano.base58_decode('3Z6ioYHE3x');
-- '\x43617264616e6f'

Bech32 Encoding/Decoding

SELECT cardano.bech32_encode('ada', 'is amazing'::bytea);
-- 'ada1d9ejqctdv9axjmn8dypl4d'

SELECT cardano.bech32_decode_prefix('ada1d9ejqctdv9axjmn8dypl4d');
-- 'ada'

SELECT cardano.bech32_decode_data('ada1d9ejqctdv9axjmn8dypl4d');
-- '\x697320616d617a696e67'

CBOR Encoding/Decoding

Simple CBOR (lightweight, sufficient for most Cardano tasks):

SELECT cardano.cbor_decode_jsonb('\xa3636164616b...'::bytea);
SELECT cardano.cbor_encode_jsonb('{"ada": "is amazing!", "bytes": "\\xdeadbeef"}'::jsonb);

Extended CBOR (full support, no limitations):

SELECT cardano.cbor_decode_jsonb_ext('\xa3636164616b...'::bytea);
SELECT cardano.cbor_encode_jsonb_ext('{"type":"map","value":[...]}'::jsonb);

Blake2b Hashing

SELECT cardano.blake2b_hash('Cardano is amazing!'::bytea, 32);
-- '\x2244d5c9699fa93b...'

Ed25519 Signing and Verification

SELECT cardano.ed25519_sign_message(
    '\x43D68AEC...'::bytea,       -- signing key
    'Cardano is amazing!'::bytea   -- message
);

SELECT cardano.ed25519_verify_signature(
    '\x432753BD...'::bytea,        -- verification key
    'Cardano is amazing!'::bytea,  -- message
    '\x74265f96...'::bytea         -- signature
);
-- true

dRep View ID Builders (CIP-105/CIP-129)

SELECT cardano.tools_drep_id_encode_cip105('\x28111ae1...'::bytea, FALSE);
-- 'drep_vkh19qg34ctllr7lh48nnj4akfc978qzqzuwzkgsdu6r3zc42lnl6a0'

SELECT cardano.tools_drep_id_encode_cip129('\x28111ae1...'::bytea, TRUE);
-- 'drep1yv5pzxhp0lu0m7757ww2hke8qhcuqgqt3c2ezphngwytz4gj324g7'

Shelley Address Utilities

-- Build a base address
SELECT cardano.tools_shelley_address_build(
    '\x7415251f...'::bytea, FALSE,  -- payment cred, is_script
    '\x7c3ae2f2...'::bytea, FALSE,  -- stake cred, is_script
    0                                -- network id
);

-- Extract payment/stake credentials
SELECT cardano.tools_shelley_addr_extract_payment_cred('addr_test1qp6p2fgl...');
SELECT cardano.tools_shelley_addr_extract_stake_cred('addr_test1qp6p2fgl...');

-- Get address type
SELECT cardano.tools_shelley_addr_get_type('addr_test1vp6p2fgl...');
-- 'PMT_KEY:NONE'

Asset Name Conversion

SELECT cardano.tools_read_asset_name('hello'::bytea);
-- 'hello' (valid UTF-8 returned as string)

SELECT cardano.tools_read_asset_name('\xdeadbeef'::bytea);
-- 'deadbeef' (non-UTF-8 returned as hex)

CIP-88 Pool Key Registration Verification

SELECT cardano.tools_verify_cip88_pool_key_registration('\xa119...'::bytea);
-- true

Last Modified 2026-03-12: add pg extension catalog (95749bf)