churchkey
Reference for io.churchkey cryptographic key library. TRIGGER when: code imports from io.churchkey, or user needs to parse/export cryptographic keys in PEM, JWK, OpenSSH, or SSH2 formats, or work with RSA/DSA/EC keys across formats. DO NOT TRIGGER when: working with raw JCA/JCE key classes or unrelated crypto libraries.
What this skill does
# Churchkey - Cryptographic Key Library
Java library for parsing and exporting cryptographic keys across multiple formats.
Format-agnostic: pass key bytes and it auto-detects format, parses, and returns a standardized `Key` object.
**Location:** `~/work/tomitribe/churchkey`
## Maven Coordinates
```xml
<groupId>io.churchkey</groupId>
<artifactId>churchkey</artifactId>
<version>1.23-SNAPSHOT</version> <!-- dev; latest release: 1.21 -->
```
## Supported Formats
| Format | Enum | Notes |
|----------|---------------------|------------------------------------------|
| PEM | `Key.Format.PEM` | PKCS1, PKCS8, X.509, OpenSSL EC |
| JWK | `Key.Format.JWK` | RFC 7517, includes JWK Sets |
| OpenSSH | `Key.Format.OPENSSH`| ssh-rsa, ssh-dss, ecdsa-sha2-* |
| SSH2 | `Key.Format.SSH2` | RFC 4716 |
## Supported Algorithms
`Key.Algorithm` enum: `RSA`, `DSA`, `EC`, `OCT`
EC supports 100+ curves (NIST P-256/384/521, secp256k1, Brainpool, binary, etc.)
via `Curve` enum. Resolve by name: `Curve.resolve("P-256")`.
## Key Types
`Key.Type` enum: `PUBLIC`, `PRIVATE`, `SECRET`
## Core API
### Keys.java (Factory - primary entry point)
```java
// Decode - auto-detects format
Key Keys.decode(String contents)
Key Keys.decode(byte[] bytes)
Key Keys.decode(File file)
List<Key> Keys.decodeSet(String contents)
List<Key> Keys.decodeSet(byte[] bytes)
// Wrap JCE keys
Key Keys.of(java.security.Key key)
Key Keys.of(KeyPair pair)
// Encode
byte[] Keys.encode(Key key)
byte[] Keys.encode(Key key, Key.Format format)
byte[] Keys.encodeSet(List<Key> keys, Key.Format format)
```
### Key.java (Main wrapper)
```java
// Getters
java.security.Key getKey()
Key.Type getType() // PUBLIC, PRIVATE, SECRET
Key.Algorithm getAlgorithm() // RSA, DSA, EC, OCT
Key.Format getFormat() // PEM, JWK, OPENSSH, SSH2
Key getPublicKey() // Extract public from private
// Attributes (JWK metadata like kid, use, alg)
String getAttribute(String name)
Map<String,String> getAttributes()
boolean hasAttribute(String name)
// Convenience encode methods
byte[] encode(Key.Format format)
String toJwk()
String toJwks()
String toPem()
String toOpenSsh()
String toSsh2()
```
### Key Component Builders
```java
// RSA
Rsa.Public.builder().modulus(n).publicExponent(e).build().toKey()
Rsa.Private.builder().modulus(n).publicExponent(e).privateExponent(d)
.primeP(p).primeQ(q).primeExponentP(dp).primeExponentQ(dq)
.crtCoefficient(qi).build().toKey()
// DSA
Dsa.Public.builder().y(y).p(p).q(q).g(g).build().toKey()
Dsa.Private.builder().x(x).y(y).p(p).q(q).g(g).build().toKey()
// EC
Ecdsa.Public.builder().curve(Curve).x(x).y(y).build().toKey()
Ecdsa.Private.builder().curve(Curve).x(x).y(y).d(d).build().toKey()
```
## Usage Examples
```java
// Parse any key format
Key key = Keys.decode(pemString);
key.getType(); // PUBLIC
key.getAlgorithm(); // RSA
// Cast to JCE type
RSAPublicKey rsa = (RSAPublicKey) key.getKey();
// Convert PEM -> JWK
String jwk = Keys.decode(pemBytes).toJwk();
// Extract public key from private
Key pub = Keys.decode(privateKeyPem).getPublicKey();
// Wrap a generated KeyPair
KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
Key key = Keys.of(gen.generateKeyPair());
String openssh = key.toOpenSsh();
// JWK Set
List<Key> keys = Keys.decodeSet(jwksJson);
byte[] jwks = Keys.encodeSet(keys, Key.Format.JWK);
// Attributes
key.getAttributes().put("kid", "my-key-id");
key.getAttributes().put("use", "sig");
```
## Exceptions
- `InvalidJwkException` / `InvalidJwksException`
- `InvalidPublicKeySpecException` / `InvalidPrivateKeySpecException`
- `UnsupportedAlgorithmException` / `UnsupportedCurveException`
- `UnsupportedKtyAlgorithmException` / `MissingKtyException`
## Build
- Java 8+ target
- Dependencies shaded (nanojson, tomitribe-util) to avoid conflicts
- Package: `io.churchkey`
Related in Web3
xaut-trade
IncludedBuy or sell XAUT (Tether Gold) on Ethereum. Supports market orders (Uniswap V3) and limit orders (UniswapX). Wallet modes: Foundry keystore or WDK. Delegates non-XAUT intents to registered skills (e.g. Polymarket prediction markets, Hyperliquid trading). Triggers: buy XAUT, XAUT trade, swap USDT for XAUT, sell XAUT, swap XAUT for USDT, limit order, limit buy XAUT, limit sell XAUT, check limit order, cancel limit order, XAUT when, create wallet, setup wallet, polymarket, prediction market, bet on, odds on, hyperliquid, perp, perpetual, long, short, open long, open short, close position, leverage.
qfc-openclaw-skill
IncludedQFC blockchain interaction — wallet, faucet, chain queries, staking, epoch & finality, AI inference
gate-dex-trade
IncludedExecutes on-chain token swaps via Gate DEX. Use when user wants to swap, buy, sell, exchange, or convert tokens, or bridge cross-chain. Covers full swap flow: price quotes, transaction build, signing, and submission. Do NOT use for read-only data lookups or wallet account management.
hunch
IncludedDiscover, bet on, track, and settle Hunch prediction markets in natural language. Trigger when a user wants to bet, take a position, or get odds on a crypto outcome — token market-cap milestones and flips, launchpad races (Bankr vs pump.fun volume / #1-days / launches over a cap), token head-to-head outperformance, mcap strike-ladders, and up/down price rounds. Also trigger on "what can I bet on about $TOKEN", "odds on …", "take YES/NO on …", "show my Hunch bets", "did my market resolve". Settles in USDC on Base via x402 (≤ $10 / bet); every bet returns an on-chain proof.
opensea
IncludedQuery NFT data, trade on the Seaport marketplace, and swap ERC20 tokens across Ethereum, Base, Arbitrum, Optimism, Polygon, and more.
polymarket
IncludedTrade on Polymarket prediction markets (CLOB V2) from a Privy EOA wallet. Search markets, place/cancel orders, manage positions. No private key handling. Use when the user wants to bet on event outcomes (e.g. "buy YES at 0.65 on the ceasefire market", "what are my open positions", "close my Trump bet").