Skip to content

Commit 2995cf1

Browse files
Merge pull request #14 from no-witness-labs/feat/update-mdx-1
docs: update mdx
2 parents 6a4a7c2 + 36fa182 commit 2995cf1

File tree

9 files changed

+113
-506
lines changed

9 files changed

+113
-506
lines changed

docs/pages/getting-started/_meta.json

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Address
2+
3+
Address module provides functionality for working with address types in Cardano.
4+
5+
## Address Example
6+
7+
```typescript
8+
import { Address } from "@evolution-sdk/evolution"
9+
10+
const hexAddress = "60ba1d6b6283c219a0530e3682c316215d55819cf97bbf26552c6f8530"
11+
const expectedBech32 = "addr_test1vzap66mzs0ppngznpcmg9scky9w4tqvul9am7fj493hc2vq4ry02m"
12+
13+
// Decode from hex
14+
const address = Address.Codec.Decode.hex(hexAddress)
15+
16+
// Encode to bech32
17+
const actualBech32 = Address.Codec.Encode.bech32(address)
18+
19+
// Verify the conversion is correct
20+
assert(actualBech32 === expectedBech32)
21+
22+
```
23+
24+
## API Reference
25+
26+
For detailed API documentation, see the generated TypeDoc documentation.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Data
2+
3+
Data module provides functionality for working with data types in Cardano.
4+
5+
## Data Example
6+
7+
```typescript
8+
import { Data } from "@evolution-sdk/evolution"
9+
10+
// Create a complex nested data structure with:
11+
// - Constructor with index 1 containing multiple fields
12+
// - Nested constructors with different indices
13+
// - A Map with mixed key-value pairs
14+
// - An array of numbers
15+
const nestedUnsortedData = new Data.Constr({
16+
index: 1n,
17+
fields: [
18+
// Nested constructor: 121_0([123_0([])])
19+
new Data.Constr({
20+
index: 0n,
21+
fields: [
22+
new Data.Constr({
23+
index: 2n,
24+
fields: []
25+
})
26+
]
27+
}),
28+
// Map with unsorted keys (will be sorted in canonical mode)
29+
new Map<Data.Data, Data.Data>([
30+
["deadbeef01", new Data.Constr({ index: 0n, fields: [] })],
31+
["beef", 19n],
32+
["deadbeef03", new Data.Constr({ index: 1n, fields: [] })]
33+
]),
34+
// Array of numbers
35+
[10n, 5n, 2n, 3n, 1n, 4n]
36+
]
37+
})
38+
39+
// Encode using default codec (indefinite-length encoding)
40+
const cborHex = Data.Codec().Encode.cborHex(nestedUnsortedData)
41+
// Output: d87a9fd8799fd87b80ffbf45deadbeef01d8798042beef1345deadbeef03d87a80ff9f0a0502030104ffff
42+
43+
// CBOR diagnostic notation (indefinite-length):
44+
// 122_0([_
45+
// 121_0([_ 123_0([])]),
46+
// {_
47+
// h'deadbeef01': 121_0([]),
48+
// h'beef': 19,
49+
// h'deadbeef03': 122_0([]),
50+
// },
51+
// [_ 10, 5, 2, 3, 1, 4],
52+
// ])
53+
// Visualize at: https://cbor.nemo157.com/
54+
55+
const decodedData = Data.Codec().Decode.cborHex(cborHex)
56+
57+
// Create a canonical codec for deterministic encoding
58+
// This ensures consistent output and sorted map keys
59+
const canonicalCodec = Data.Codec({
60+
options: {
61+
mode: "canonical"
62+
}
63+
})
64+
65+
// Encode using canonical mode (definite-length, sorted keys)
66+
const canonicalCborHex = canonicalCodec.Encode.cborHex(nestedUnsortedData)
67+
// Output: d87a83d87981d87b80a342beef1345deadbeef01d8798045deadbeef03d87a80860a0502030104
68+
69+
// CBOR diagnostic notation (canonical/definite-length):
70+
// 122_0([
71+
// 121_0([123_0([])]),
72+
// {
73+
// h'beef': 19, ← Keys are now sorted
74+
// h'deadbeef01': 121_0([]),
75+
// h'deadbeef03': 122_0([]),
76+
// },
77+
// [10, 5, 2, 3, 1, 4], ← Definite-length array
78+
// ])
79+
80+
// Verify that decoding works correctly
81+
assert.deepStrictEqual(decodedData, nestedUnsortedData, "Decoded data should match original")
82+
83+
```
84+
85+
## API Reference
86+
87+
For detailed API documentation, see the generated TypeDoc documentation.

docs/pages/getting-started/examples.mdx

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

0 commit comments

Comments
 (0)