Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/codeblocks/pages.examples.Address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import assert from "assert"
import { Address } from "@evolution-sdk/evolution"

const hexAddress = "60ba1d6b6283c219a0530e3682c316215d55819cf97bbf26552c6f8530"
const expectedBech32 = "addr_test1vzap66mzs0ppngznpcmg9scky9w4tqvul9am7fj493hc2vq4ry02m"

// Decode from hex
const address = Address.Codec.Decode.hex(hexAddress)

// Encode to bech32
const actualBech32 = Address.Codec.Encode.bech32(address)

// Verify the conversion is correct
assert(actualBech32 === expectedBech32)
75 changes: 75 additions & 0 deletions docs/codeblocks/pages.examples.Data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import assert from "assert"
import { Data } from "@evolution-sdk/evolution"

// Create a complex nested data structure with:
// - Constructor with index 1 containing multiple fields
// - Nested constructors with different indices
// - A Map with mixed key-value pairs
// - An array of numbers
const nestedUnsortedData = new Data.Constr({
index: 1n,
fields: [
// Nested constructor: 121_0([123_0([])])
new Data.Constr({
index: 0n,
fields: [
new Data.Constr({
index: 2n,
fields: []
})
]
}),
// Map with unsorted keys (will be sorted in canonical mode)
new Map<Data.Data, Data.Data>([
["deadbeef01", new Data.Constr({ index: 0n, fields: [] })],
["beef", 19n],
["deadbeef03", new Data.Constr({ index: 1n, fields: [] })]
]),
// Array of numbers
[10n, 5n, 2n, 3n, 1n, 4n]
]
})

// Encode using default codec (indefinite-length encoding)
const cborHex = Data.Codec().Encode.cborHex(nestedUnsortedData)
// Output: d87a9fd8799fd87b80ffbf45deadbeef01d8798042beef1345deadbeef03d87a80ff9f0a0502030104ffff

// CBOR diagnostic notation (indefinite-length):
// 122_0([_
// 121_0([_ 123_0([])]),
// {_
// h'deadbeef01': 121_0([]),
// h'beef': 19,
// h'deadbeef03': 122_0([]),
// },
// [_ 10, 5, 2, 3, 1, 4],
// ])
// Visualize at: https://cbor.nemo157.com/

const decodedData = Data.Codec().Decode.cborHex(cborHex)

// Create a canonical codec for deterministic encoding
// This ensures consistent output and sorted map keys
const canonicalCodec = Data.Codec({
options: {
mode: "canonical"
}
})

// Encode using canonical mode (definite-length, sorted keys)
const canonicalCborHex = canonicalCodec.Encode.cborHex(nestedUnsortedData)
// Output: d87a83d87981d87b80a342beef1345deadbeef01d8798045deadbeef03d87a80860a0502030104

// CBOR diagnostic notation (canonical/definite-length):
// 122_0([
// 121_0([123_0([])]),
// {
// h'beef': 19, ← Keys are now sorted
// h'deadbeef01': 121_0([]),
// h'deadbeef03': 122_0([]),
// },
// [10, 5, 2, 3, 1, 4], ← Definite-length array
// ])

// Verify that decoding works correctly
assert.deepStrictEqual(decodedData, nestedUnsortedData, "Decoded data should match original")
30 changes: 30 additions & 0 deletions docs/codeblocks/pages.index.quickstart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import assert from "assert"
import { Data } from "@evolution-sdk/evolution"

// Create a sample data structure with constructor index 0
// and a Map containing key-value pairs
const sampleData = new Data.Constr({
index: 0n,
fields: [
new Map([
["deadbeef", 42n],
["cafe", 100n],
["beef", 20n]
])
]
})

// Encode the data to CBOR hex format
const cborHex = Data.Codec().Encode.cborHex(sampleData)
console.log("CBOR Hex:", cborHex)
// Output: d8799fbf44deadbeef182a42cafe186442beef14ffff

// CBOR diagnostic notation: 121_0([_ {_ h'deadbeef': 42_0, h'cafe': 100_0, h'beef': 20}])
// Visualize at: https://cbor.nemo157.com/

// Decode the CBOR hex back to data structure
const decodedData = Data.Codec().Decode.cborHex(cborHex)

// Verify round-trip encoding/decoding works correctly
assert.deepEqual(sampleData, decodedData)
console.log("✅ Round-trip encoding/decoding successful!")
2 changes: 1 addition & 1 deletion docs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ module.exports = withNextra({
images: {
unoptimized: true
},
basePath: "/evolution-sdk",
basePath: process.env.NODE_ENV === 'production' ? "/evolution-sdk" : "",
})
3 changes: 2 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"start": "next start",
"export": "next build",
"copy-evolution-docs": "node scripts/copy-evolution-docs.mjs",
"prebuild": "pnpm run copy-evolution-docs"
"validate-codeblocks": "node scripts/validate-and-update-codeblocks.mjs",
"prebuild": "pnpm run copy-evolution-docs && pnpm run validate-codeblocks"
},
"dependencies": {
"next": "^14.0.0",
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/_meta.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"index": "Introduction",
"getting-started": "Getting Started",
"api": "API Reference",
"guides": "Guides"
"examples": "Examples",
"reference": "API Reference"
}
26 changes: 26 additions & 0 deletions docs/pages/examples/Address.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Address

Address module provides functionality for working with address types in Cardano.

## Address Example

```typescript
import { Address } from "@evolution-sdk/evolution"

const hexAddress = "60ba1d6b6283c219a0530e3682c316215d55819cf97bbf26552c6f8530"
const expectedBech32 = "addr_test1vzap66mzs0ppngznpcmg9scky9w4tqvul9am7fj493hc2vq4ry02m"

// Decode from hex
const address = Address.Codec.Decode.hex(hexAddress)

// Encode to bech32
const actualBech32 = Address.Codec.Encode.bech32(address)

// Verify the conversion is correct
assert(actualBech32 === expectedBech32)

```

## API Reference

For detailed API documentation, see the generated TypeDoc documentation.
87 changes: 87 additions & 0 deletions docs/pages/examples/Data.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Data

Data module provides functionality for working with data types in Cardano.

## Data Example

```typescript
import { Data } from "@evolution-sdk/evolution"

// Create a complex nested data structure with:
// - Constructor with index 1 containing multiple fields
// - Nested constructors with different indices
// - A Map with mixed key-value pairs
// - An array of numbers
const nestedUnsortedData = new Data.Constr({
index: 1n,
fields: [
// Nested constructor: 121_0([123_0([])])
new Data.Constr({
index: 0n,
fields: [
new Data.Constr({
index: 2n,
fields: []
})
]
}),
// Map with unsorted keys (will be sorted in canonical mode)
new Map<Data.Data, Data.Data>([
["deadbeef01", new Data.Constr({ index: 0n, fields: [] })],
["beef", 19n],
["deadbeef03", new Data.Constr({ index: 1n, fields: [] })]
]),
// Array of numbers
[10n, 5n, 2n, 3n, 1n, 4n]
]
})

// Encode using default codec (indefinite-length encoding)
const cborHex = Data.Codec().Encode.cborHex(nestedUnsortedData)
// Output: d87a9fd8799fd87b80ffbf45deadbeef01d8798042beef1345deadbeef03d87a80ff9f0a0502030104ffff

// CBOR diagnostic notation (indefinite-length):
// 122_0([_
// 121_0([_ 123_0([])]),
// {_
// h'deadbeef01': 121_0([]),
// h'beef': 19,
// h'deadbeef03': 122_0([]),
// },
// [_ 10, 5, 2, 3, 1, 4],
// ])
// Visualize at: https://cbor.nemo157.com/

const decodedData = Data.Codec().Decode.cborHex(cborHex)

// Create a canonical codec for deterministic encoding
// This ensures consistent output and sorted map keys
const canonicalCodec = Data.Codec({
options: {
mode: "canonical"
}
})

// Encode using canonical mode (definite-length, sorted keys)
const canonicalCborHex = canonicalCodec.Encode.cborHex(nestedUnsortedData)
// Output: d87a83d87981d87b80a342beef1345deadbeef01d8798045deadbeef03d87a80860a0502030104

// CBOR diagnostic notation (canonical/definite-length):
// 122_0([
// 121_0([123_0([])]),
// {
// h'beef': 19, ← Keys are now sorted
// h'deadbeef01': 121_0([]),
// h'deadbeef03': 122_0([]),
// },
// [10, 5, 2, 3, 1, 4], ← Definite-length array
// ])

// Verify that decoding works correctly
assert.deepStrictEqual(decodedData, nestedUnsortedData, "Decoded data should match original")

```

## API Reference

For detailed API documentation, see the generated TypeDoc documentation.
Loading