Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions .changeset/cbor-encoding-preservation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@evolution-sdk/evolution": patch
---

Add CBOR encoding preservation for bit-perfect round-trip fidelity and redesign Redeemers as a discriminated union (RedeemerMap + RedeemerArray)
328 changes: 328 additions & 0 deletions .specs/cbor-encoding-preservation.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/evolution/src/Anchor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const FromCDDL = Schema.transform(CDDLSchema, Schema.typeSchema(Anchor),
* @since 2.0.0
* @category schemas
*/
export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS) =>
Schema.compose(
CBOR.FromBytes(options), // Uint8Array → CBOR
FromCDDL // CBOR → Anchor
Expand All @@ -90,7 +90,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI
* @since 2.0.0
* @category schemas
*/
export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS) =>
Schema.compose(
Schema.Uint8ArrayFromHex, // string → Uint8Array
FromCBORBytes(options) // Uint8Array → Anchor
Expand Down
12 changes: 6 additions & 6 deletions packages/evolution/src/Assets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(Ass
* @since 2.0.0
* @category schemas
*/
export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS) =>
Schema.compose(
CBOR.FromBytes(options), // Uint8Array → CBOR
FromCDDL // CBOR → Assets
Expand All @@ -729,7 +729,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI
* @since 2.0.0
* @category schemas
*/
export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS) =>
Schema.compose(
Schema.Uint8ArrayFromHex, // string → Uint8Array
FromCBORBytes(options) // Uint8Array → Assets
Expand All @@ -756,7 +756,7 @@ export const arbitrary: FastCheck.Arbitrary<Assets> = FastCheck.oneof(
* @since 2.0.0
* @category decoding
*/
export const fromCBORBytes = (bytes: Uint8Array, options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
export const fromCBORBytes = (bytes: Uint8Array, options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS) =>
Schema.decodeSync(FromCBORBytes(options))(bytes)

/**
Expand All @@ -765,7 +765,7 @@ export const fromCBORBytes = (bytes: Uint8Array, options: CBOR.CodecOptions = CB
* @since 2.0.0
* @category decoding
*/
export const fromCBORHex = (hex: string, options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
export const fromCBORHex = (hex: string, options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS) =>
Schema.decodeSync(FromCBORHex(options))(hex)

/**
Expand All @@ -774,7 +774,7 @@ export const fromCBORHex = (hex: string, options: CBOR.CodecOptions = CBOR.CML_D
* @since 2.0.0
* @category encoding
*/
export const toCBORBytes = (data: Assets, options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
export const toCBORBytes = (data: Assets, options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS) =>
Schema.encodeSync(FromCBORBytes(options))(data)

/**
Expand All @@ -783,5 +783,5 @@ export const toCBORBytes = (data: Assets, options: CBOR.CodecOptions = CBOR.CML_
* @since 2.0.0
* @category encoding
*/
export const toCBORHex = (data: Assets, options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
export const toCBORHex = (data: Assets, options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS) =>
Schema.encodeSync(FromCBORHex(options))(data)
12 changes: 6 additions & 6 deletions packages/evolution/src/AuxiliaryData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ export const FromCDDL = Schema.transformOrFail(AnyEraCDDL, Schema.typeSchema(Aux
* @since 2.0.0
* @category schemas
*/
export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS) =>
Schema.compose(CBOR.FromBytes(options), FromCDDL).annotations({
identifier: "AuxiliaryData.FromCBORBytes",
title: "AuxiliaryData from CBOR bytes",
Expand All @@ -495,7 +495,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI
* @since 2.0.0
* @category schemas
*/
export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS) =>
Schema.compose(Schema.Uint8ArrayFromHex, FromCBORBytes(options)).annotations({
identifier: "AuxiliaryData.FromCBORHex",
title: "AuxiliaryData from CBOR hex",
Expand Down Expand Up @@ -609,7 +609,7 @@ export const arbitrary: FastCheck.Arbitrary<AuxiliaryData> = FastCheck.oneof(
* @since 2.0.0
* @category parsing
*/
export const fromCBORBytes = (bytes: Uint8Array, options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
export const fromCBORBytes = (bytes: Uint8Array, options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS) =>
Schema.decodeSync(FromCBORBytes(options))(bytes)

/**
Expand All @@ -618,7 +618,7 @@ export const fromCBORBytes = (bytes: Uint8Array, options: CBOR.CodecOptions = CB
* @since 2.0.0
* @category parsing
*/
export const fromCBORHex = (hex: string, options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
export const fromCBORHex = (hex: string, options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS) =>
Schema.decodeSync(FromCBORHex(options))(hex)

/**
Expand All @@ -627,7 +627,7 @@ export const fromCBORHex = (hex: string, options: CBOR.CodecOptions = CBOR.CML_D
* @since 2.0.0
* @category encoding
*/
export const toCBORBytes = (data: AuxiliaryData, options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
export const toCBORBytes = (data: AuxiliaryData, options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS) =>
Schema.encodeSync(FromCBORBytes(options))(data)

/**
Expand All @@ -636,5 +636,5 @@ export const toCBORBytes = (data: AuxiliaryData, options: CBOR.CodecOptions = CB
* @since 2.0.0
* @category encoding
*/
export const toCBORHex = (data: AuxiliaryData, options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
export const toCBORHex = (data: AuxiliaryData, options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS) =>
Schema.encodeSync(FromCBORHex(options))(data)
16 changes: 8 additions & 8 deletions packages/evolution/src/BootstrapWitness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(Boo
* @since 2.0.0
* @category schemas
*/
export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS) =>
Schema.compose(
CBOR.FromBytes(options), // Uint8Array → CBOR
FromCDDL // CBOR → BootstrapWitness
Expand All @@ -151,7 +151,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI
* @since 2.0.0
* @category schemas
*/
export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS) =>
Schema.compose(
Schema.Uint8ArrayFromHex, // string → Uint8Array
FromCBORBytes(options) // Uint8Array → BootstrapWitness
Expand All @@ -169,7 +169,7 @@ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTION
*/
export const fromCBORBytes = (
bytes: Uint8Array,
options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS
options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS
): BootstrapWitness => Schema.decodeSync(FromCBORBytes(options))(bytes)

/**
Expand All @@ -178,7 +178,7 @@ export const fromCBORBytes = (
* @since 2.0.0
* @category parsing
*/
export const fromCBORHex = (hex: string, options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS): BootstrapWitness =>
export const fromCBORHex = (hex: string, options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS): BootstrapWitness =>
Schema.decodeSync(FromCBORHex(options))(hex)

/**
Expand All @@ -189,7 +189,7 @@ export const fromCBORHex = (hex: string, options: CBOR.CodecOptions = CBOR.CML_D
*/
export const toCBORBytes = (
witness: BootstrapWitness,
options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS
options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS
): Uint8Array => Schema.encodeSync(FromCBORBytes(options))(witness)

/**
Expand All @@ -198,7 +198,7 @@ export const toCBORBytes = (
* @since 2.0.0
* @category encoding
*/
export const toCBORHex = (witness: BootstrapWitness, options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS): string =>
export const toCBORHex = (witness: BootstrapWitness, options: CBOR.CodecOptions = CBOR.PRESERVE_OPTIONS): string =>
Schema.encodeSync(FromCBORHex(options))(witness)

/**
Expand All @@ -210,9 +210,9 @@ export const arbitrary: FastCheck.Arbitrary<BootstrapWitness> = FastCheck.record
FastCheck.uint8Array({ minLength: 1, maxLength: 64 }).map((path) => {
const m = new Map<bigint, Uint8Array>()
// Byron AddrAttributes: key 1 holds derivation_path; value is CBOR-encoded bytes
const inner = CBOR.internalEncodeSync(path, CBOR.CML_DEFAULT_OPTIONS)
const inner = CBOR.internalEncodeSync(path, CBOR.PRESERVE_OPTIONS)
m.set(1n, inner)
return CBOR.internalEncodeSync(m, CBOR.CML_DEFAULT_OPTIONS)
return CBOR.internalEncodeSync(m, CBOR.PRESERVE_OPTIONS)
})
),
chainCode: FastCheck.uint8Array({ minLength: 32, maxLength: 32 }),
Expand Down
Loading
Loading