Skip to content

Commit 20e9419

Browse files
Merge pull request #8 from no-witness-labs/fix/deploy-docs-4
fix/deploy docs 4
2 parents bd01272 + cc54466 commit 20e9419

File tree

125 files changed

+773
-537
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

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

docs/next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ module.exports = withNextra({
1111
images: {
1212
unoptimized: true
1313
},
14-
basePath: "/evolution-sdk",
14+
basePath: process.env.NODE_ENV === 'production' ? "/evolution-sdk" : "",
1515
})

docs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"start": "next start",
1010
"export": "next build",
1111
"copy-evolution-docs": "node scripts/copy-evolution-docs.mjs",
12-
"prebuild": "pnpm run copy-evolution-docs"
12+
"validate-codeblocks": "node scripts/validate-and-update-codeblocks.mjs",
13+
"prebuild": "pnpm run copy-evolution-docs && pnpm run validate-codeblocks"
1314
},
1415
"dependencies": {
1516
"next": "^14.0.0",

docs/pages/_meta.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"index": "Introduction",
33
"getting-started": "Getting Started",
4-
"api": "API Reference",
5-
"guides": "Guides"
4+
"examples": "Examples",
5+
"reference": "API Reference"
66
}

docs/pages/examples/Address.mdx

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.

docs/pages/examples/Data.mdx

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.

0 commit comments

Comments
 (0)