Skip to content

Commit 1678790

Browse files
Merge pull request #100 from IntersectMBO/refactor/address-docs
refactor: address docs
2 parents 1182f5e + 06d6311 commit 1678790

File tree

9 files changed

+197
-133
lines changed

9 files changed

+197
-133
lines changed

docs/content/docs/addresses/address-types/pointer.mdx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,22 @@ Pointer Address = Payment Credential + Pointer (slot, txIndex, certIndex)
3939
| Adoption | Rare | Universal |
4040
| Recommended | ✗ No | • Yes |
4141

42-
## Parsing Pointer Addresses
42+
## Parsing Pointer Addresses (Legacy)
4343

44-
If you encounter a pointer address, you can parse it using the `AddressDetails` utility:
44+
> **Note**: `Core.Address` does not support pointer addresses as they are deprecated. Use `Core.AddressEras` for historical parsing.
45+
46+
If you encounter a pointer address in historical data, you can parse it using `AddressEras`:
4547

4648
```typescript twoslash
47-
import { AddressDetails } from "@evolution-sdk/evolution";
49+
import { Core } from "@evolution-sdk/evolution";
4850

49-
// Parse a pointer address from Bech32
50-
const details = AddressDetails.fromBech32("addr_test1gz...");
51+
// Parse a pointer address from Bech32 using AddressEras (legacy support)
52+
const address = Core.AddressEras.fromBech32("addr_test1gz2n8fvzgmyhnqlpnv2340v09943nr7pz5af2rwqrra8ncsm0tdz8");
5153

52-
if (details.type === "PointerAddress" && details.address._tag === "PointerAddress") {
53-
// Type narrowed to PointerAddress - now we can access pointer-specific properties
54-
console.log("Payment credential:", details.address.paymentCredential);
55-
console.log("Pointer:", details.address.pointer);
54+
if (address._tag === "PointerAddress") {
55+
// Type narrowed to PointerAddress - access pointer-specific properties
56+
console.log("Payment credential:", address.paymentCredential);
57+
console.log("Pointer:", address.pointer);
5658
}
5759
```
5860

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
---
2+
title: Address
3+
description: Working with Cardano addresses using Core.Address
4+
---
5+
6+
# Address
7+
8+
The Evolution SDK provides `Core.Address` for working with modern Cardano addresses. This module handles parsing, validation, inspection, and conversion between formats.
9+
10+
## Modern Address Types
11+
12+
Cardano primarily uses two address types today:
13+
14+
- **Base Address** - Payment + staking credentials (most common)
15+
- **Enterprise Address** - Payment credential only (no staking rewards)
16+
17+
Legacy formats (Byron, Pointer) exist for historical compatibility but are no longer used in practice.
18+
19+
## Basic Operations
20+
21+
### Parsing Addresses
22+
23+
```typescript twoslash
24+
import { Core } from "@evolution-sdk/evolution";
25+
26+
// Parse from Bech32 (most common format)
27+
const address = Core.Address.fromBech32(
28+
"addr1qx2kd28nq8ac5prwg32hhvudlwggpgfp8utlyqxu6wqgz62f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sy0f4qd"
29+
);
30+
31+
// Parse from hex
32+
const address2 = Core.Address.fromHex(
33+
"01195a6a8c607b8a0237109aab5e31b7c8828509fb17e4019cd381021a4f8a081b7bd1b0d35972c0e8eaba8e5c923c99d66a3bbe78ff23c5855"
34+
);
35+
```
36+
37+
### Converting Formats
38+
39+
```typescript twoslash
40+
import { Core } from "@evolution-sdk/evolution";
41+
42+
const address = Core.Address.fromBech32(
43+
"addr1qx2kd28nq8ac5prwg32hhvudlwggpgfp8utlyqxu6wqgz62f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sy0f4qd"
44+
);
45+
46+
// Convert to different formats
47+
const bech32 = Core.Address.toBech32(address); // "addr1qx2k..."
48+
const hex = Core.Address.toHex(address); // "01195a6a..."
49+
const bytes = Core.Address.toBytes(address); // Uint8Array
50+
```
51+
52+
### Validating User Input
53+
54+
```typescript twoslash
55+
import { Core } from "@evolution-sdk/evolution";
56+
57+
function validateAddress(input: string): Core.Address.Address | null {
58+
try {
59+
const address = Core.Address.fromBech32(input);
60+
61+
// Check network (0 = testnet, 1 = mainnet)
62+
if (address.networkId !== 1) {
63+
console.warn("Not a mainnet address");
64+
}
65+
66+
return address;
67+
} catch (error) {
68+
console.error("Invalid address:", error);
69+
return null;
70+
}
71+
}
72+
```
73+
74+
## Address Inspection
75+
76+
### Type Checking
77+
78+
```typescript twoslash
79+
import { Core } from "@evolution-sdk/evolution";
80+
81+
const address = Core.Address.fromBech32(
82+
"addr1qx2kd28nq8ac5prwg32hhvudlwggpgfp8utlyqxu6wqgz62f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sy0f4qd"
83+
);
84+
85+
// Check address type
86+
const details = Core.Address.getAddressDetails(Core.Address.toBech32(address));
87+
const isEnterprise = Core.Address.isEnterprise(address); // false
88+
const hasStaking = Core.Address.hasStakingCredential(address); // true
89+
90+
if (details?.type === "Base") {
91+
console.log("Base address with staking capability");
92+
} else if (isEnterprise) {
93+
console.log("Enterprise address - no staking rewards");
94+
}
95+
```
96+
97+
### Address Details
98+
99+
For comprehensive information about an address:
100+
101+
```typescript twoslash
102+
import { Core } from "@evolution-sdk/evolution";
103+
104+
const details = Core.Address.getAddressDetails(
105+
"addr1qx2kd28nq8ac5prwg32hhvudlwggpgfp8utlyqxu6wqgz62f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sy0f4qd"
106+
);
107+
108+
if (details) {
109+
console.log("Type:", details.type); // "Base"
110+
console.log("Network:", details.networkId); // 1 (mainnet)
111+
console.log("Bech32:", details.address.bech32); // Original Bech32 string
112+
console.log("Hex:", details.address.hex); // Hex representation
113+
}
114+
```
115+
116+
## Address Construction
117+
118+
For advanced use cases, you can construct addresses from credentials:
119+
120+
```typescript twoslash
121+
import { Core } from "@evolution-sdk/evolution";
122+
123+
// Create payment credential from key hash
124+
const paymentCred = new Core.KeyHash.KeyHash({
125+
hash: new Uint8Array(28) // 28-byte key hash
126+
});
127+
128+
// Create staking credential
129+
const stakeCred = new Core.KeyHash.KeyHash({
130+
hash: new Uint8Array(28) // 28-byte key hash
131+
});
132+
133+
// Construct base address directly
134+
const address = new Core.Address.Address({
135+
networkId: 1, // mainnet
136+
paymentCredential: paymentCred,
137+
stakingCredential: stakeCred
138+
});
139+
140+
const bech32 = Core.Address.toBech32(address);
141+
```
142+
143+
## Legacy Address Types
144+
145+
For historical compatibility, Evolution SDK supports legacy address formats via `Core.AddressEras`:
146+
147+
- **Byron addresses** - Legacy Byron-era format (no longer used)
148+
- **Pointer addresses** - Reference stake credentials via on-chain pointers (deprecated)
149+
150+
These are automatically handled when parsing existing UTXOs but should not be used for new addresses.
151+
152+
## Summary
153+
154+
| Function | Purpose |
155+
|----------|---------|
156+
| `fromBech32()` | Parse Bech32 address string |
157+
| `fromHex()` | Parse hex address string |
158+
| `toBech32()` | Convert to Bech32 string |
159+
| `toHex()` | Convert to hex string |
160+
| `isEnterprise()` | Check if enterprise address (no staking) |
161+
| `hasStakingCredential()` | Check if address has staking capability |
162+
| `getAddressDetails()` | Get comprehensive address information |
163+
164+
## Best Practices
165+
166+
1. **Use Base addresses** for most applications (enables staking rewards)
167+
2. **Validate network ID** to prevent testnet/mainnet mixups
168+
3. **Parse once, reuse** - avoid re-parsing the same address strings
169+
4. **Handle errors gracefully** when parsing user input
170+
171+
## Next Steps
172+
173+
- [Address Validation](/docs/addresses/validation) - Error handling and validation patterns
174+
- [Address Conversion](/docs/addresses/conversion) - Transform between formats
175+
- [Address Construction](/docs/addresses/construction) - Build addresses from credentials

docs/content/docs/addresses/conversion.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,4 @@ try {
111111

112112
- **[Address Validation](/docs/addresses/validation)** - Verify address correctness and handle errors
113113
- **[Address Types](/docs/addresses/address-types)** - Overview of all Cardano address types
114-
- **[Core Concepts](/docs/addresses/core-concepts)** - Understanding the two-layer architecture
114+
- **[Core.Address](/docs/addresses/address)** - Parse, validate, and convert addresses

docs/content/docs/addresses/core-concepts.mdx

Lines changed: 0 additions & 100 deletions
This file was deleted.

docs/content/docs/addresses/index.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ description: Working with Cardano addresses in Evolution SDK
55

66
# Address Overview
77

8-
Cardano addresses identify where funds can be sent and who controls them. The Evolution SDK provides a **simplified Address API** that works with payment credentials and optional staking credentials, abstracting away the complexity of different address types.
8+
Cardano addresses identify where funds can be sent and who controls them. The Evolution SDK provides `Core.Address` for working with payment credentials and optional staking credentials, handling the complexity of different address formats.
99

10-
## The Simplified Address Model
10+
## The Core Address Model
1111

12-
Instead of dealing with multiple address types (BaseAddress, EnterpriseAddress, etc.), Evolution SDK uses a unified `Address` structure:
12+
Instead of dealing with multiple address types (BaseAddress, EnterpriseAddress, etc.), Evolution SDK uses a unified `Core.Address` structure:
1313

1414
```typescript
1515
Address = Payment Credential + Optional Staking Credential
@@ -104,7 +104,7 @@ const paymentOnlyAddress = new Core.Address.Address({
104104
const bech32String = Core.Address.toBech32(stakingAddress)
105105
```
106106

107-
[Learn about credentials and address internals ](/docs/addresses/core-concepts)
107+
[Learn about the Core.Address module ](/docs/addresses/address)
108108

109109
## When to Use Each Pattern
110110

@@ -169,7 +169,7 @@ const address = new Core.Address.Address({
169169
Spend UTXOs Delegate & earn rewards
170170
```
171171

172-
### Without Staking (Simplified Pattern)
172+
### Without Staking (Basic Pattern)
173173

174174
```
175175
┌──────────────────────────┐
@@ -197,9 +197,9 @@ Addresses use different Bech32 prefixes based on network:
197197
198198
## Understanding Address Eras
199199

200-
While the simplified `Address` API covers most use cases, Cardano's ledger specification defines several specific address types. These are called **Address Eras**:
200+
While `Core.Address` covers most use cases, Cardano's ledger specification defines several specific address types. These are called **Address Eras**:
201201

202-
| Era Type | Simplified Equivalent | When to Learn More |
202+
| Era Type | Core.Address Equivalent | When to Learn More |
203203
|----------|----------------------|-------------------|
204204
| **Base** | Address with staking credential | Standard addresses |
205205
| **Enterprise** | Address without staking credential | Exchange/contract addresses |
@@ -253,7 +253,7 @@ Verify address format and network:
253253
## Next Steps
254254

255255
**Core Concepts:**
256-
- [Credentials & Address Internals](/docs/addresses/core-concepts) - Deep dive into how addresses work
256+
- [Core.Address](/docs/addresses/address) - How to parse, validate, and convert addresses
257257
- [Address Types](/docs/addresses/address-types) - Comprehensive coverage of all address types
258258

259259
**Advanced Patterns:**

docs/content/docs/addresses/meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"title": "Addresses",
33
"pages": [
44
"index",
5-
"core-concepts",
5+
"address",
66
"address-types",
77
"franken",
88
"construction",

docs/content/docs/addresses/validation.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,4 @@ function validateMany(addresses: string[]): {
145145

146146
- **[Address Conversion](/docs/addresses/conversion)** - Transform between Bech32, hex, and byte formats
147147
- **[Address Types](/docs/addresses/address-types)** - Overview of all Cardano address types
148-
- **[Core Concepts](/docs/addresses/core-concepts)** - Understanding the two-layer architecture
148+
- **[Core.Address](/docs/addresses/address)** - Parse, validate, and convert addresses

packages/evolution/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
export * as Blueprint from "./blueprint/index.js"
22
export * as Core from "./core/index.js"
33
export * as Plutus from "./core/plutus/index.js"
4-
export * as Address from "./sdk/Address.js"
5-
export * as AddressDetails from "./sdk/AddressDetails.js"
64
export * from "./sdk/client/Client.js"
75
export { createClient } from "./sdk/client/ClientImpl.js"
86
export { runEffect } from "./utils/effect-runtime.js"

0 commit comments

Comments
 (0)