diff --git a/docs/components/search.tsx b/docs/components/search.tsx index c52648ad..efe0690b 100644 --- a/docs/components/search.tsx +++ b/docs/components/search.tsx @@ -28,15 +28,15 @@ export default function DefaultSearchDialog(props: SharedProps) { // the site lives under a subpath (e.g. /evolution-sdk). Set // NEXT_PUBLIC_BASE_PATH=/evolution-sdk in CI so the client requests the // correct static search JSON. Falls back to empty string for local dev. - const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? '' - const normalizedBase = basePath.endsWith('/') && basePath.length > 1 ? basePath.slice(0, -1) : basePath + const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? "" + const normalizedBase = basePath.endsWith("/") && basePath.length > 1 ? basePath.slice(0, -1) : basePath const apiFrom = `${normalizedBase}/api/search` const { search, setSearch, query } = useDocsSearch({ type: "static", initOrama, locale, - from: apiFrom, + from: apiFrom }) return ( diff --git a/docs/content/docs/modules/Data.mdx b/docs/content/docs/modules/Data.mdx index 6400232b..1f1569d2 100644 --- a/docs/content/docs/modules/Data.mdx +++ b/docs/content/docs/modules/Data.mdx @@ -66,6 +66,7 @@ parent: Modules - [ByteArray (type alias)](#bytearray-type-alias) - [CDDLSchema](#cddlschema) - [Int (type alias)](#int-type-alias) + - [equals](#equals) --- @@ -742,3 +743,14 @@ export declare const CDDLSchema: Schema.Schema ```ts export type Int = typeof IntSchema.Type ``` + +## equals + +Deep structural equality for Plutus Data values. +Handles maps, lists, ints, bytes, and constrs. + +**Signature** + +```ts +export declare const equals: (a: Data, b: Data) => boolean +``` diff --git a/docs/content/docs/modules/DatumOption.mdx b/docs/content/docs/modules/DatumOption.mdx index 61283605..6c9094ff 100644 --- a/docs/content/docs/modules/DatumOption.mdx +++ b/docs/content/docs/modules/DatumOption.mdx @@ -34,7 +34,6 @@ parent: Modules - [DatumHash (class)](#datumhash-class) - [toString (method)](#tostring-method) - [[Symbol.for("nodejs.util.inspect.custom")] (method)](#symbolfornodejsutilinspectcustom-method) - - [DatumOptionCDDLSchema](#datumoptioncddlschema) - [DatumOptionSchema](#datumoptionschema) - [FromCBORBytes](#fromcborbytes-1) - [FromCBORHex](#fromcborhex-1) @@ -45,6 +44,7 @@ parent: Modules - [testing](#testing) - [arbitrary](#arbitrary) - [utils](#utils) + - [CDDLSchema](#cddlschema) - [DatumHashFromBytes](#datumhashfrombytes) - [datumHashArbitrary](#datumhasharbitrary) - [inlineDatumArbitrary](#inlinedatumarbitrary) @@ -243,36 +243,6 @@ toString(): string [Symbol.for("nodejs.util.inspect.custom")](): string ``` -## DatumOptionCDDLSchema - -CDDL schema for DatumOption. -datum_option = [0, Bytes32] / [1, #6.24(bytes)] - -Where: - -- [0, Bytes32] represents a datum hash (tag 0 with 32-byte hash) -- [1, #6.24(bytes)] represents inline data (tag 1 with CBOR tag 24 containing plutus data as bytes) - -**Signature** - -```ts -export declare const DatumOptionCDDLSchema: Schema.transformOrFail< - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2< - Schema.Literal<[1n]>, - Schema.TaggedStruct<"Tag", { tag: Schema.Literal<[24]>; value: typeof Schema.Uint8ArrayFromSelf }> - > - ] - >, - Schema.SchemaClass, - never -> -``` - -Added in v2.0.0 - ## DatumOptionSchema Schema for DatumOption representing optional datum information in transaction outputs. @@ -366,6 +336,12 @@ Added in v2.0.0 ## FromCDDL CDDL schema for DatumOption. +datum_option = [0, Bytes32] / [1, #6.24(bytes)] + +Where: + +- [0, Bytes32] represents a datum hash (tag 0 with 32-byte hash) +- [1, #6.24(bytes)] represents inline data (tag 1 with CBOR tag 24 containing plutus data as bytes) **Signature** @@ -432,6 +408,22 @@ Added in v2.0.0 # utils +## CDDLSchema + +**Signature** + +```ts +export declare const CDDLSchema: Schema.Union< + [ + Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, + Schema.Tuple2< + Schema.Literal<[1n]>, + Schema.TaggedStruct<"Tag", { tag: Schema.Literal<[24]>; value: typeof Schema.Uint8ArrayFromSelf }> + > + ] +> +``` + ## DatumHashFromBytes **Signature** diff --git a/docs/content/docs/modules/KeyHash.mdx b/docs/content/docs/modules/KeyHash.mdx index 58abdaf8..ea19a233 100644 --- a/docs/content/docs/modules/KeyHash.mdx +++ b/docs/content/docs/modules/KeyHash.mdx @@ -10,11 +10,17 @@ parent: Modules

Table of contents

+- [arbitrary](#arbitrary) + - [arbitrary](#arbitrary-1) - [constructors](#constructors) + - [fromPrivateKey](#fromprivatekey) + - [fromVKey](#fromvkey) - [make](#make) -- [effect](#effect) +- [either](#either) - [Either (namespace)](#either-namespace) -- [encoding](#encoding) +- [encoding/decoding](#encodingdecoding) + - [fromBytes](#frombytes) + - [fromHex](#fromhex) - [toBytes](#tobytes) - [toHex](#tohex) - [equality](#equality) @@ -25,25 +31,55 @@ parent: Modules - [KeyHash (class)](#keyhash-class) - [toJSON (method)](#tojson-method) - [toString (method)](#tostring-method) -- [parsing](#parsing) - - [fromBytes](#frombytes) - - [fromHex](#fromhex) -- [schemas](#schemas) +- [transformer](#transformer) - [FromBytes](#frombytes-1) - [FromHex](#fromhex-1) -- [testing](#testing) - - [arbitrary](#arbitrary) -- [utils](#utils) - - [fromPrivateKey](#fromprivatekey) - - [fromVKey](#fromvkey) --- +# arbitrary + +## arbitrary + +FastCheck arbitrary for generating random KeyHash instances. + +**Signature** + +```ts +export declare const arbitrary: FastCheck.Arbitrary +``` + +Added in v2.0.0 + # constructors +## fromPrivateKey + +Create a KeyHash from a PrivateKey + +**Signature** + +```ts +export declare const fromPrivateKey: (privateKey: PrivateKey) => KeyHash +``` + +Added in v2.0.0 + +## fromVKey + +Create a KeyHash from a VKey + +**Signature** + +```ts +export declare const fromVKey: (vkey: VKey.VKey) => KeyHash +``` + +Added in v2.0.0 + ## make -Smart constructor for KeyHash that validates and applies branding. +Smart constructor for KeyHash **Signature** @@ -53,15 +89,39 @@ export declare const make: (props: { readonly hash: any }, options?: Schema.Make Added in v2.0.0 -# effect +# either ## Either (namespace) -Effect-based error handling variants for functions that can fail. +Either-based error handling variants for functions that can fail. Added in v2.0.0 -# encoding +# encoding/decoding + +## fromBytes + +Decode a KeyHash from raw bytes. + +**Signature** + +```ts +export declare const fromBytes: (input: any) => KeyHash +``` + +Added in v2.0.0 + +## fromHex + +Decode a KeyHash from a hex string. + +**Signature** + +```ts +export declare const fromHex: (input: string) => KeyHash +``` + +Added in v2.0.0 ## toBytes @@ -119,16 +179,14 @@ Added in v2.0.0 ## KeyHash (class) -KeyHash as a TaggedClass (breaking change from branded hex string). +KeyHash + +CDDL: ``` addr_keyhash = hash28 ``` -Follows CIP-0019 binary representation. - -Stores raw 28-byte value for performance. - **Signature** ```ts @@ -153,35 +211,7 @@ toJSON(): string toString(): string ``` -# parsing - -## fromBytes - -Parse a KeyHash from raw bytes. -Expects exactly 28 bytes. - -**Signature** - -```ts -export declare const fromBytes: (input: any) => KeyHash -``` - -Added in v2.0.0 - -## fromHex - -Parse a KeyHash from a hex string. -Expects exactly 56 hex characters (28 bytes). - -**Signature** - -```ts -export declare const fromHex: (input: string) => KeyHash -``` - -Added in v2.0.0 - -# schemas +# transformer ## FromBytes @@ -209,42 +239,3 @@ export declare const FromHex: Schema.transform< ``` Added in v2.0.0 - -# testing - -## arbitrary - -FastCheck arbitrary for generating random KeyHash instances. -Used for property-based testing to generate valid test data. - -**Signature** - -```ts -export declare const arbitrary: FastCheck.Arbitrary -``` - -Added in v2.0.0 - -# utils - -## fromPrivateKey - -Create a KeyHash from a PrivateKey (sync version that throws KeyHashError). -All errors are normalized to KeyHashError with contextual information. - -**Signature** - -```ts -export declare const fromPrivateKey: (privateKey: PrivateKey) => KeyHash -``` - -## fromVKey - -Create a KeyHash from a VKey (sync version that throws KeyHashError). -All errors are normalized to KeyHashError with contextual information. - -**Signature** - -```ts -export declare const fromVKey: (vkey: VKey.VKey) => KeyHash -``` diff --git a/docs/content/docs/modules/ScriptRef.mdx b/docs/content/docs/modules/ScriptRef.mdx index 4b2432c0..3df6e505 100644 --- a/docs/content/docs/modules/ScriptRef.mdx +++ b/docs/content/docs/modules/ScriptRef.mdx @@ -39,6 +39,8 @@ parent: Modules - [ScriptRef (class)](#scriptref-class) - [toJSON (method)](#tojson-method) - [toString (method)](#tostring-method) +- [utils](#utils) + - [CDDLSchema](#cddlschema) --- @@ -344,3 +346,16 @@ toJSON(): string ```ts toString(): string ``` + +# utils + +## CDDLSchema + +**Signature** + +```ts +export declare const CDDLSchema: Schema.TaggedStruct< + "Tag", + { tag: Schema.Literal<[24]>; value: typeof Schema.Uint8ArrayFromSelf } +> +``` diff --git a/docs/content/docs/modules/TransactionBody.mdx b/docs/content/docs/modules/TransactionBody.mdx index 62679d48..a0083ed4 100644 --- a/docs/content/docs/modules/TransactionBody.mdx +++ b/docs/content/docs/modules/TransactionBody.mdx @@ -27,11 +27,12 @@ parent: Modules - [fromCBORBytes](#fromcborbytes) - [fromCBORHex](#fromcborhex) - [schemas](#schemas) + - [CDDLSchema](#cddlschema) - [FromCBORBytes](#fromcborbytes-1) - [FromCBORHex](#fromcborhex-1) - [utils](#utils) - - [CDDLSchema](#cddlschema) - [FromCDDL](#fromcddl) + - [equals](#equals) - [isTransactionBody](#istransactionbody) - [make](#make) @@ -73,7 +74,7 @@ Default options use CML_DEFAULT_OPTIONS for CDDL/CML parity. **Signature** ```ts -export declare const toCBORBytes: (input: unknown, options?: CBOR.CodecOptions) => Uint8Array +export declare const toCBORBytes: (input: TransactionBody, options?: CBOR.CodecOptions) => Uint8Array ``` Added in v2.0.0 @@ -86,7 +87,7 @@ Default options use CML_DEFAULT_OPTIONS for CDDL/CML parity. **Signature** ```ts -export declare const toCBORHex: (input: unknown, options?: CBOR.CodecOptions) => string +export declare const toCBORHex: (input: TransactionBody, options?: CBOR.CodecOptions) => string ``` Added in v2.0.0 @@ -170,7 +171,7 @@ Default options use CML_DEFAULT_OPTIONS for CDDL/CML parity. **Signature** ```ts -export declare const fromCBORBytes: (bytes: Uint8Array, options?: CBOR.CodecOptions) => unknown +export declare const fromCBORBytes: (bytes: Uint8Array, options?: CBOR.CodecOptions) => TransactionBody ``` Added in v2.0.0 @@ -183,13 +184,28 @@ Default options use CML_DEFAULT_OPTIONS for CDDL/CML parity. **Signature** ```ts -export declare const fromCBORHex: (hex: string, options?: CBOR.CodecOptions) => unknown +export declare const fromCBORHex: (hex: string, options?: CBOR.CodecOptions) => TransactionBody ``` Added in v2.0.0 # schemas +## CDDLSchema + +CDDL schema for TransactionBody struct structure. + +**Signature** + +```ts +export declare const CDDLSchema: Schema.MapFromSelf< + typeof Schema.BigIntFromSelf, + Schema.Schema +> +``` + +Added in v2.0.0 + ## FromCBORBytes CBOR bytes transformation schema for TransactionBody. @@ -239,800 +255,24 @@ Added in v2.0.0 # utils -## CDDLSchema +## FromCDDL **Signature** ```ts -export declare const CDDLSchema: Schema.Union< - [ - Schema.Struct<{ - 0: Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[258]> - value: Schema.Array$> - } - > - 1: Schema.Array$< - Schema.Union< - [ - Schema.Tuple< - [ - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - typeof Schema.BigIntFromSelf, - Schema.Tuple2< - typeof Schema.BigIntFromSelf, - Schema.SchemaClass< - ReadonlyMap>, - ReadonlyMap>, - never - > - > - ] - >, - Schema.Element - ] - >, - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }> - ] - > - > - 2: typeof Schema.BigIntFromSelf - 3: Schema.optional - 4: Schema.optional< - Schema.Array$< - Schema.Union< - [ - Schema.Tuple2< - Schema.Literal<[0n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf> - >, - Schema.Tuple2< - Schema.Literal<[1n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf> - >, - Schema.Tuple< - [ - Schema.Literal<[2n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.Uint8ArrayFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[3n]>, - typeof Schema.Uint8ArrayFromSelf, - typeof Schema.Uint8ArrayFromSelf, - typeof Schema.BigIntFromSelf, - typeof Schema.BigIntFromSelf, - Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[30]> - value: Schema.Tuple2 - } - >, - typeof Schema.Uint8ArrayFromSelf, - Schema.Array$, - Schema.Array$< - Schema.SchemaClass< - | readonly [0n, bigint | null, any, any] - | readonly [1n, bigint | null, string] - | readonly [2n, string], - | readonly [0n, bigint | null, any, any] - | readonly [1n, bigint | null, string] - | readonly [2n, string], - never - > - >, - Schema.NullOr> - ] - >, - Schema.Tuple<[Schema.Literal<[4n]>, typeof Schema.Uint8ArrayFromSelf, typeof Schema.BigIntFromSelf]>, - Schema.Tuple< - [ - Schema.Literal<[7n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[8n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[9n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple<[Schema.Literal<[2n]>]>, - Schema.Tuple<[Schema.Literal<[3n]>]> - ] - > - ] - >, - Schema.Tuple< - [ - Schema.Literal<[10n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple<[Schema.Literal<[2n]>]>, - Schema.Tuple<[Schema.Literal<[3n]>]> - ] - > - ] - >, - Schema.Tuple< - [ - Schema.Literal<[11n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.Uint8ArrayFromSelf, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[12n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple<[Schema.Literal<[2n]>]>, - Schema.Tuple<[Schema.Literal<[3n]>]> - ] - >, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[13n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple<[Schema.Literal<[2n]>]>, - Schema.Tuple<[Schema.Literal<[3n]>]> - ] - >, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[14n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf> - ] - >, - Schema.Tuple< - [ - Schema.Literal<[15n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.NullishOr> - ] - >, - Schema.Tuple< - [ - Schema.Literal<[16n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.BigIntFromSelf, - Schema.NullishOr> - ] - >, - Schema.Tuple< - [ - Schema.Literal<[17n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[18n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.NullishOr> - ] - > - ] - > - > - > - 5: Schema.optional> - 7: Schema.optional - 8: Schema.optional - 9: Schema.optional< - Schema.SchemaClass< - ReadonlyMap>, - ReadonlyMap>, - never - > - > - 11: Schema.optional - 13: Schema.optional< - Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[258]> - value: Schema.Array$> - } - > - > - 14: Schema.optional> - 15: Schema.optional - 16: Schema.optional< - Schema.Union< - [ - Schema.Tuple< - [ - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - typeof Schema.BigIntFromSelf, - Schema.Tuple2< - typeof Schema.BigIntFromSelf, - Schema.SchemaClass< - ReadonlyMap>, - ReadonlyMap>, - never - > - > - ] - >, - Schema.Element - ] - >, - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }> - ] - > - > - 17: Schema.optional - 18: Schema.optional< - Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[258]> - value: Schema.Array$> - } - > - > - 19: Schema.optional< - Schema.SchemaClass< - ReadonlyMap< - readonly [0n, any] | readonly [1n, any] | readonly [2n, any] | readonly [3n, any] | readonly [4n, any], - ReadonlyMap - >, - ReadonlyMap< - readonly [0n, any] | readonly [1n, any] | readonly [2n, any] | readonly [3n, any] | readonly [4n, any], - ReadonlyMap - >, - never - > - > - 20: Schema.optional< - Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[258]> - value: Schema.Array$< - Schema.Tuple< - [ - typeof Schema.BigIntFromSelf, - typeof Schema.Uint8ArrayFromSelf, - Schema.SchemaClass< - | readonly [0n, readonly [any, bigint] | null, ReadonlyMap, any] - | readonly [1n, readonly [any, bigint] | null, readonly [bigint, bigint]] - | readonly [2n, ReadonlyMap, any] - | readonly [3n, readonly [any, bigint] | null] - | readonly [ - 4n, - readonly [any, bigint] | null, - ( - | readonly (readonly [0n | 1n, any])[] - | { - readonly _tag: "Tag" - readonly tag: 258 - readonly value: readonly (readonly [0n | 1n, any])[] - } - ), - ReadonlyMap, - { readonly _tag: "Tag"; readonly tag: 30; readonly value: readonly [bigint, bigint] } - ] - | readonly [5n, readonly [any, bigint] | null, readonly [readonly [string, any], any]] - | readonly [6n], - | readonly [0n, readonly [any, bigint] | null, ReadonlyMap, any] - | readonly [1n, readonly [any, bigint] | null, readonly [bigint, bigint]] - | readonly [2n, ReadonlyMap, any] - | readonly [3n, readonly [any, bigint] | null] - | readonly [ - 4n, - readonly [any, bigint] | null, - ( - | readonly (readonly [0n | 1n, any])[] - | { - readonly _tag: "Tag" - readonly tag: 258 - readonly value: readonly (readonly [0n | 1n, any])[] - } - ), - ReadonlyMap, - { readonly _tag: "Tag"; readonly tag: 30; readonly value: readonly [bigint, bigint] } - ] - | readonly [5n, readonly [any, bigint] | null, readonly [readonly [string, any], any]] - | readonly [6n], - never - >, - Schema.NullOr> - ] - > - > - } - > - > - 21: Schema.optional - 22: Schema.optional - }>, - Schema.MapFromSelf> - ] +export declare const FromCDDL: Schema.transformOrFail< + Schema.MapFromSelf>, + Schema.SchemaClass, + never > ``` -## FromCDDL +## equals **Signature** ```ts -export declare const FromCDDL: Schema.transformOrFail< - Schema.Union< - [ - Schema.Struct<{ - 0: Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[258]> - value: Schema.Array$> - } - > - 1: Schema.Array$< - Schema.Union< - [ - Schema.Tuple< - [ - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - typeof Schema.BigIntFromSelf, - Schema.Tuple2< - typeof Schema.BigIntFromSelf, - Schema.SchemaClass< - ReadonlyMap>, - ReadonlyMap>, - never - > - > - ] - >, - Schema.Element - ] - >, - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }> - ] - > - > - 2: typeof Schema.BigIntFromSelf - 3: Schema.optional - 4: Schema.optional< - Schema.Array$< - Schema.Union< - [ - Schema.Tuple2< - Schema.Literal<[0n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf> - >, - Schema.Tuple2< - Schema.Literal<[1n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf> - >, - Schema.Tuple< - [ - Schema.Literal<[2n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.Uint8ArrayFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[3n]>, - typeof Schema.Uint8ArrayFromSelf, - typeof Schema.Uint8ArrayFromSelf, - typeof Schema.BigIntFromSelf, - typeof Schema.BigIntFromSelf, - Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[30]> - value: Schema.Tuple2 - } - >, - typeof Schema.Uint8ArrayFromSelf, - Schema.Array$, - Schema.Array$< - Schema.SchemaClass< - | readonly [0n, bigint | null, any, any] - | readonly [1n, bigint | null, string] - | readonly [2n, string], - | readonly [0n, bigint | null, any, any] - | readonly [1n, bigint | null, string] - | readonly [2n, string], - never - > - >, - Schema.NullOr> - ] - >, - Schema.Tuple<[Schema.Literal<[4n]>, typeof Schema.Uint8ArrayFromSelf, typeof Schema.BigIntFromSelf]>, - Schema.Tuple< - [ - Schema.Literal<[7n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[8n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[9n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple<[Schema.Literal<[2n]>]>, - Schema.Tuple<[Schema.Literal<[3n]>]> - ] - > - ] - >, - Schema.Tuple< - [ - Schema.Literal<[10n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple<[Schema.Literal<[2n]>]>, - Schema.Tuple<[Schema.Literal<[3n]>]> - ] - > - ] - >, - Schema.Tuple< - [ - Schema.Literal<[11n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.Uint8ArrayFromSelf, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[12n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple<[Schema.Literal<[2n]>]>, - Schema.Tuple<[Schema.Literal<[3n]>]> - ] - >, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[13n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple<[Schema.Literal<[2n]>]>, - Schema.Tuple<[Schema.Literal<[3n]>]> - ] - >, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[14n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf> - ] - >, - Schema.Tuple< - [ - Schema.Literal<[15n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.NullishOr> - ] - >, - Schema.Tuple< - [ - Schema.Literal<[16n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.BigIntFromSelf, - Schema.NullishOr> - ] - >, - Schema.Tuple< - [ - Schema.Literal<[17n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[18n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.NullishOr> - ] - > - ] - > - > - > - 5: Schema.optional> - 7: Schema.optional - 8: Schema.optional - 9: Schema.optional< - Schema.SchemaClass< - ReadonlyMap>, - ReadonlyMap>, - never - > - > - 11: Schema.optional - 13: Schema.optional< - Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[258]> - value: Schema.Array$> - } - > - > - 14: Schema.optional> - 15: Schema.optional - 16: Schema.optional< - Schema.Union< - [ - Schema.Tuple< - [ - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - typeof Schema.BigIntFromSelf, - Schema.Tuple2< - typeof Schema.BigIntFromSelf, - Schema.SchemaClass< - ReadonlyMap>, - ReadonlyMap>, - never - > - > - ] - >, - Schema.Element - ] - >, - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }> - ] - > - > - 17: Schema.optional - 18: Schema.optional< - Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[258]> - value: Schema.Array$> - } - > - > - 19: Schema.optional< - Schema.SchemaClass< - ReadonlyMap< - readonly [0n, any] | readonly [1n, any] | readonly [2n, any] | readonly [3n, any] | readonly [4n, any], - ReadonlyMap - >, - ReadonlyMap< - readonly [0n, any] | readonly [1n, any] | readonly [2n, any] | readonly [3n, any] | readonly [4n, any], - ReadonlyMap - >, - never - > - > - 20: Schema.optional< - Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[258]> - value: Schema.Array$< - Schema.Tuple< - [ - typeof Schema.BigIntFromSelf, - typeof Schema.Uint8ArrayFromSelf, - Schema.SchemaClass< - | readonly [0n, readonly [any, bigint] | null, ReadonlyMap, any] - | readonly [1n, readonly [any, bigint] | null, readonly [bigint, bigint]] - | readonly [2n, ReadonlyMap, any] - | readonly [3n, readonly [any, bigint] | null] - | readonly [ - 4n, - readonly [any, bigint] | null, - ( - | readonly (readonly [0n | 1n, any])[] - | { - readonly _tag: "Tag" - readonly tag: 258 - readonly value: readonly (readonly [0n | 1n, any])[] - } - ), - ReadonlyMap, - { readonly _tag: "Tag"; readonly tag: 30; readonly value: readonly [bigint, bigint] } - ] - | readonly [5n, readonly [any, bigint] | null, readonly [readonly [string, any], any]] - | readonly [6n], - | readonly [0n, readonly [any, bigint] | null, ReadonlyMap, any] - | readonly [1n, readonly [any, bigint] | null, readonly [bigint, bigint]] - | readonly [2n, ReadonlyMap, any] - | readonly [3n, readonly [any, bigint] | null] - | readonly [ - 4n, - readonly [any, bigint] | null, - ( - | readonly (readonly [0n | 1n, any])[] - | { - readonly _tag: "Tag" - readonly tag: 258 - readonly value: readonly (readonly [0n | 1n, any])[] - } - ), - ReadonlyMap, - { readonly _tag: "Tag"; readonly tag: 30; readonly value: readonly [bigint, bigint] } - ] - | readonly [5n, readonly [any, bigint] | null, readonly [readonly [string, any], any]] - | readonly [6n], - never - >, - Schema.NullOr> - ] - > - > - } - > - > - 21: Schema.optional - 22: Schema.optional - }>, - Schema.MapFromSelf> - ] - >, - Schema.SchemaClass, - never -> +export declare const equals: (self: TransactionBody, that: TransactionBody) => boolean ``` ## isTransactionBody diff --git a/docs/content/docs/modules/TransactionOutput.mdx b/docs/content/docs/modules/TransactionOutput.mdx index 01ce4381..db88a92c 100644 --- a/docs/content/docs/modules/TransactionOutput.mdx +++ b/docs/content/docs/modules/TransactionOutput.mdx @@ -12,8 +12,8 @@ parent: Modules - [Either](#either) - [Either (namespace)](#either-namespace) -- [FastCheck](#fastcheck) - - [arbitrary](#arbitrary) +- [arbitrary](#arbitrary) + - [arbitrary](#arbitrary-1) - [constructors](#constructors) - [makeBabbage](#makebabbage) - [makeShelley](#makeshelley) @@ -25,6 +25,8 @@ parent: Modules - [toCBORHex](#tocborhex) - [equality](#equality) - [equals](#equals) +- [errors](#errors) + - [TransactionOutputError (class)](#transactionoutputerror-class) - [model](#model) - [BabbageTransactionOutput (class)](#babbagetransactionoutput-class) - [toString (method)](#tostring-method) @@ -33,17 +35,18 @@ parent: Modules - [toString (method)](#tostring-method-1) - [[Symbol.for("nodejs.util.inspect.custom")] (method)](#symbolfornodejsutilinspectcustom-method-1) - [schemas](#schemas) + - [TransactionOutput](#transactionoutput) +- [transformation](#transformation) - [FromBabbageTransactionOutputCDDLSchema](#frombabbagetransactionoutputcddlschema) + - [FromShelleyTransactionOutputCDDLSchema](#fromshelleytransactionoutputcddlschema) +- [transformer](#transformer) - [FromCBORBytes](#fromcborbytes-1) - [FromCBORHex](#fromcborhex-1) - [FromCDDL](#fromcddl) - - [FromShelleyTransactionOutputCDDLSchema](#fromshelleytransactionoutputcddlschema) - - [TransactionOutput](#transactionoutput) - [utils](#utils) - [CDDLSchema](#cddlschema) - [ShelleyTransactionOutputCDDL](#shelleytransactionoutputcddl) - [TransactionOutput (type alias)](#transactionoutput-type-alias) - - [TransactionOutputError (class)](#transactionoutputerror-class) --- @@ -55,7 +58,7 @@ Either namespace containing schema decode and encode operations. Added in v2.0.0 -# FastCheck +# arbitrary ## arbitrary @@ -77,10 +80,13 @@ Create a Babbage transaction output. ```ts export declare const makeBabbage: ( - address: Address.Address, - amount: Value.Value, - datumOption?: DatumOption.DatumOption, - scriptRef?: ScriptRef.ScriptRef + props: { + readonly address: RewardAccount | BaseAddress | EnterpriseAddress | PointerAddress | ByronAddress + readonly amount: Value.OnlyCoin | Value.WithAssets + readonly datumOption?: DatumOption.DatumHash | DatumOption.InlineDatum | undefined + readonly scriptRef?: ScriptRef.ScriptRef | undefined + }, + options?: Schema.MakeOptions | undefined ) => BabbageTransactionOutput ``` @@ -94,9 +100,12 @@ Create a Shelley transaction output. ```ts export declare const makeShelley: ( - address: Address.Address, - amount: Value.Value, - datumHash?: DatumOption.DatumHash + props: { + readonly address: RewardAccount | BaseAddress | EnterpriseAddress | PointerAddress | ByronAddress + readonly amount: Value.OnlyCoin | Value.WithAssets + readonly datumHash?: DatumOption.DatumHash | undefined + }, + options?: Schema.MakeOptions | undefined ) => ShelleyTransactionOutput ``` @@ -180,14 +189,30 @@ export declare const equals: (a: TransactionOutput, b: TransactionOutput) => boo Added in v2.0.0 +# errors + +## TransactionOutputError (class) + +Error class for TransactionOutput related operations. + +**Signature** + +```ts +export declare class TransactionOutputError +``` + +Added in v2.0.0 + # model ## BabbageTransactionOutput (class) Babbage-era transaction output format +CDDL: + ``` -CDDL: babbage_transaction_output = +babbage_transaction_output = {0 : address, 1 : value, ? 2 : datum_option, ? 3 : script_ref} ``` @@ -219,8 +244,10 @@ toString(): string Shelley-era transaction output format +CDDL: + ``` -CDDL: shelley_transaction_output = [address, amount : value, ? Bytes32] +shelley_transaction_output = [address, amount : value, ? Bytes32] ``` **Signature** @@ -249,40 +276,35 @@ toString(): string # schemas -## FromBabbageTransactionOutputCDDLSchema +## TransactionOutput -CDDL schema for Babbage transaction outputs +Union type for transaction outputs + +CDDL: ``` -CDDL: babbage_transaction_output = {0 : address, 1 : value, ? 2 : datum_option, ? 3 : script_ref} +transaction_output = shelley_transaction_output / babbage_transaction_output ``` **Signature** +```ts +export declare const TransactionOutput: Schema.Union<[typeof ShelleyTransactionOutput, typeof BabbageTransactionOutput]> +``` + +Added in v2.0.0 + +# transformation + +## FromBabbageTransactionOutputCDDLSchema + +CDDL schema for Babbage transaction outputs + +**Signature** + ```ts export declare const FromBabbageTransactionOutputCDDLSchema: Schema.transformOrFail< - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }>, + Schema.MapFromSelf>, Schema.SchemaClass, never > @@ -290,10 +312,45 @@ export declare const FromBabbageTransactionOutputCDDLSchema: Schema.transformOrF Added in v2.0.0 +## FromShelleyTransactionOutputCDDLSchema + +CDDL schema for Shelley transaction outputs + +**Signature** + +```ts +export declare const FromShelleyTransactionOutputCDDLSchema: Schema.transformOrFail< + Schema.Tuple< + [ + typeof Schema.Uint8ArrayFromSelf, + Schema.Union< + [ + typeof Schema.BigIntFromSelf, + Schema.Tuple2< + typeof Schema.BigIntFromSelf, + Schema.SchemaClass< + ReadonlyMap>, + ReadonlyMap>, + never + > + > + ] + >, + Schema.Element + ] + >, + Schema.SchemaClass, + never +> +``` + +Added in v2.0.0 + +# transformer + ## FromCBORBytes CBOR bytes transformation schema for TransactionOutput. -Transforms between CBOR bytes and TransactionOutput. **Signature** @@ -332,28 +389,7 @@ export declare const FromCBORBytes: ( never >, Schema.transformOrFail< - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }>, + Schema.MapFromSelf>, Schema.SchemaClass, never > @@ -367,7 +403,6 @@ Added in v2.0.0 ## FromCBORHex CBOR hex transformation schema for TransactionOutput. -Transforms between CBOR hex string and TransactionOutput. **Signature** @@ -408,28 +443,7 @@ export declare const FromCBORHex: ( never >, Schema.transformOrFail< - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }>, + Schema.MapFromSelf>, Schema.SchemaClass, never > @@ -445,12 +459,6 @@ Added in v2.0.0 CDDL schema for transaction outputs -``` -CDDL: transaction_output = shelley_transaction_output / babbage_transaction_output -shelley_transaction_output = [address, amount : value, ? Bytes32] -babbage_transaction_output = {0 : address, 1 : value, ? 2 : datum_option, ? 3 : script_ref} -``` - **Signature** ```ts @@ -480,28 +488,7 @@ export declare const FromCDDL: Schema.Union< never >, Schema.transformOrFail< - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }>, + Schema.MapFromSelf>, Schema.SchemaClass, never > @@ -511,60 +498,6 @@ export declare const FromCDDL: Schema.Union< Added in v2.0.0 -## FromShelleyTransactionOutputCDDLSchema - -CDDL schema for Shelley transaction outputs - -``` -CDDL: shelley_transaction_output = [address, amount : value, ? Bytes32] -``` - -**Signature** - -```ts -export declare const FromShelleyTransactionOutputCDDLSchema: Schema.transformOrFail< - Schema.Tuple< - [ - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - typeof Schema.BigIntFromSelf, - Schema.Tuple2< - typeof Schema.BigIntFromSelf, - Schema.SchemaClass< - ReadonlyMap>, - ReadonlyMap>, - never - > - > - ] - >, - Schema.Element - ] - >, - Schema.SchemaClass, - never -> -``` - -Added in v2.0.0 - -## TransactionOutput - -Union type for transaction outputs - -``` -CDDL: transaction_output = shelley_transaction_output / babbage_transaction_output -``` - -**Signature** - -```ts -export declare const TransactionOutput: Schema.Union<[typeof ShelleyTransactionOutput, typeof BabbageTransactionOutput]> -``` - -Added in v2.0.0 - # utils ## CDDLSchema @@ -593,28 +526,7 @@ export declare const CDDLSchema: Schema.Union< Schema.Element ] >, - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }> + Schema.MapFromSelf> ] > ``` @@ -652,11 +564,3 @@ export declare const ShelleyTransactionOutputCDDL: Schema.Tuple< ```ts export type TransactionOutput = typeof TransactionOutput.Type ``` - -## TransactionOutputError (class) - -**Signature** - -```ts -export declare class TransactionOutputError -``` diff --git a/docs/next-env.d.ts b/docs/next-env.d.ts index 830fb594..d39ca300 100644 --- a/docs/next-env.d.ts +++ b/docs/next-env.d.ts @@ -1,6 +1,6 @@ /// /// -/// +/// // NOTE: This file should not be edited // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. diff --git a/packages/evolution/docs/modules/Data.ts.md b/packages/evolution/docs/modules/Data.ts.md index b5723f07..3e4af195 100644 --- a/packages/evolution/docs/modules/Data.ts.md +++ b/packages/evolution/docs/modules/Data.ts.md @@ -66,6 +66,7 @@ parent: Modules - [ByteArray (type alias)](#bytearray-type-alias) - [CDDLSchema](#cddlschema) - [Int (type alias)](#int-type-alias) + - [equals](#equals) --- @@ -742,3 +743,14 @@ export declare const CDDLSchema: Schema.Schema ```ts export type Int = typeof IntSchema.Type ``` + +## equals + +Deep structural equality for Plutus Data values. +Handles maps, lists, ints, bytes, and constrs. + +**Signature** + +```ts +export declare const equals: (a: Data, b: Data) => boolean +``` diff --git a/packages/evolution/docs/modules/DatumOption.ts.md b/packages/evolution/docs/modules/DatumOption.ts.md index 85069035..0da29c2c 100644 --- a/packages/evolution/docs/modules/DatumOption.ts.md +++ b/packages/evolution/docs/modules/DatumOption.ts.md @@ -34,7 +34,6 @@ parent: Modules - [DatumHash (class)](#datumhash-class) - [toString (method)](#tostring-method) - [[Symbol.for("nodejs.util.inspect.custom")] (method)](#symbolfornodejsutilinspectcustom-method) - - [DatumOptionCDDLSchema](#datumoptioncddlschema) - [DatumOptionSchema](#datumoptionschema) - [FromCBORBytes](#fromcborbytes-1) - [FromCBORHex](#fromcborhex-1) @@ -45,6 +44,7 @@ parent: Modules - [testing](#testing) - [arbitrary](#arbitrary) - [utils](#utils) + - [CDDLSchema](#cddlschema) - [DatumHashFromBytes](#datumhashfrombytes) - [datumHashArbitrary](#datumhasharbitrary) - [inlineDatumArbitrary](#inlinedatumarbitrary) @@ -243,36 +243,6 @@ toString(): string [Symbol.for("nodejs.util.inspect.custom")](): string ``` -## DatumOptionCDDLSchema - -CDDL schema for DatumOption. -datum_option = [0, Bytes32] / [1, #6.24(bytes)] - -Where: - -- [0, Bytes32] represents a datum hash (tag 0 with 32-byte hash) -- [1, #6.24(bytes)] represents inline data (tag 1 with CBOR tag 24 containing plutus data as bytes) - -**Signature** - -```ts -export declare const DatumOptionCDDLSchema: Schema.transformOrFail< - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2< - Schema.Literal<[1n]>, - Schema.TaggedStruct<"Tag", { tag: Schema.Literal<[24]>; value: typeof Schema.Uint8ArrayFromSelf }> - > - ] - >, - Schema.SchemaClass, - never -> -``` - -Added in v2.0.0 - ## DatumOptionSchema Schema for DatumOption representing optional datum information in transaction outputs. @@ -366,6 +336,12 @@ Added in v2.0.0 ## FromCDDL CDDL schema for DatumOption. +datum_option = [0, Bytes32] / [1, #6.24(bytes)] + +Where: + +- [0, Bytes32] represents a datum hash (tag 0 with 32-byte hash) +- [1, #6.24(bytes)] represents inline data (tag 1 with CBOR tag 24 containing plutus data as bytes) **Signature** @@ -432,6 +408,22 @@ Added in v2.0.0 # utils +## CDDLSchema + +**Signature** + +```ts +export declare const CDDLSchema: Schema.Union< + [ + Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, + Schema.Tuple2< + Schema.Literal<[1n]>, + Schema.TaggedStruct<"Tag", { tag: Schema.Literal<[24]>; value: typeof Schema.Uint8ArrayFromSelf }> + > + ] +> +``` + ## DatumHashFromBytes **Signature** diff --git a/packages/evolution/docs/modules/KeyHash.ts.md b/packages/evolution/docs/modules/KeyHash.ts.md index fb96780d..7336fb30 100644 --- a/packages/evolution/docs/modules/KeyHash.ts.md +++ b/packages/evolution/docs/modules/KeyHash.ts.md @@ -10,11 +10,17 @@ parent: Modules

Table of contents

+- [arbitrary](#arbitrary) + - [arbitrary](#arbitrary-1) - [constructors](#constructors) + - [fromPrivateKey](#fromprivatekey) + - [fromVKey](#fromvkey) - [make](#make) -- [effect](#effect) +- [either](#either) - [Either (namespace)](#either-namespace) -- [encoding](#encoding) +- [encoding/decoding](#encodingdecoding) + - [fromBytes](#frombytes) + - [fromHex](#fromhex) - [toBytes](#tobytes) - [toHex](#tohex) - [equality](#equality) @@ -25,25 +31,55 @@ parent: Modules - [KeyHash (class)](#keyhash-class) - [toJSON (method)](#tojson-method) - [toString (method)](#tostring-method) -- [parsing](#parsing) - - [fromBytes](#frombytes) - - [fromHex](#fromhex) -- [schemas](#schemas) +- [transformer](#transformer) - [FromBytes](#frombytes-1) - [FromHex](#fromhex-1) -- [testing](#testing) - - [arbitrary](#arbitrary) -- [utils](#utils) - - [fromPrivateKey](#fromprivatekey) - - [fromVKey](#fromvkey) --- +# arbitrary + +## arbitrary + +FastCheck arbitrary for generating random KeyHash instances. + +**Signature** + +```ts +export declare const arbitrary: FastCheck.Arbitrary +``` + +Added in v2.0.0 + # constructors +## fromPrivateKey + +Create a KeyHash from a PrivateKey + +**Signature** + +```ts +export declare const fromPrivateKey: (privateKey: PrivateKey) => KeyHash +``` + +Added in v2.0.0 + +## fromVKey + +Create a KeyHash from a VKey + +**Signature** + +```ts +export declare const fromVKey: (vkey: VKey.VKey) => KeyHash +``` + +Added in v2.0.0 + ## make -Smart constructor for KeyHash that validates and applies branding. +Smart constructor for KeyHash **Signature** @@ -53,15 +89,39 @@ export declare const make: (props: { readonly hash: any }, options?: Schema.Make Added in v2.0.0 -# effect +# either ## Either (namespace) -Effect-based error handling variants for functions that can fail. +Either-based error handling variants for functions that can fail. Added in v2.0.0 -# encoding +# encoding/decoding + +## fromBytes + +Decode a KeyHash from raw bytes. + +**Signature** + +```ts +export declare const fromBytes: (input: any) => KeyHash +``` + +Added in v2.0.0 + +## fromHex + +Decode a KeyHash from a hex string. + +**Signature** + +```ts +export declare const fromHex: (input: string) => KeyHash +``` + +Added in v2.0.0 ## toBytes @@ -119,16 +179,14 @@ Added in v2.0.0 ## KeyHash (class) -KeyHash as a TaggedClass (breaking change from branded hex string). +KeyHash + +CDDL: ``` addr_keyhash = hash28 ``` -Follows CIP-0019 binary representation. - -Stores raw 28-byte value for performance. - **Signature** ```ts @@ -153,35 +211,7 @@ toJSON(): string toString(): string ``` -# parsing - -## fromBytes - -Parse a KeyHash from raw bytes. -Expects exactly 28 bytes. - -**Signature** - -```ts -export declare const fromBytes: (input: any) => KeyHash -``` - -Added in v2.0.0 - -## fromHex - -Parse a KeyHash from a hex string. -Expects exactly 56 hex characters (28 bytes). - -**Signature** - -```ts -export declare const fromHex: (input: string) => KeyHash -``` - -Added in v2.0.0 - -# schemas +# transformer ## FromBytes @@ -209,42 +239,3 @@ export declare const FromHex: Schema.transform< ``` Added in v2.0.0 - -# testing - -## arbitrary - -FastCheck arbitrary for generating random KeyHash instances. -Used for property-based testing to generate valid test data. - -**Signature** - -```ts -export declare const arbitrary: FastCheck.Arbitrary -``` - -Added in v2.0.0 - -# utils - -## fromPrivateKey - -Create a KeyHash from a PrivateKey (sync version that throws KeyHashError). -All errors are normalized to KeyHashError with contextual information. - -**Signature** - -```ts -export declare const fromPrivateKey: (privateKey: PrivateKey) => KeyHash -``` - -## fromVKey - -Create a KeyHash from a VKey (sync version that throws KeyHashError). -All errors are normalized to KeyHashError with contextual information. - -**Signature** - -```ts -export declare const fromVKey: (vkey: VKey.VKey) => KeyHash -``` diff --git a/packages/evolution/docs/modules/ScriptRef.ts.md b/packages/evolution/docs/modules/ScriptRef.ts.md index 92a88abe..8b546d5e 100644 --- a/packages/evolution/docs/modules/ScriptRef.ts.md +++ b/packages/evolution/docs/modules/ScriptRef.ts.md @@ -39,6 +39,8 @@ parent: Modules - [ScriptRef (class)](#scriptref-class) - [toJSON (method)](#tojson-method) - [toString (method)](#tostring-method) +- [utils](#utils) + - [CDDLSchema](#cddlschema) --- @@ -344,3 +346,16 @@ toJSON(): string ```ts toString(): string ``` + +# utils + +## CDDLSchema + +**Signature** + +```ts +export declare const CDDLSchema: Schema.TaggedStruct< + "Tag", + { tag: Schema.Literal<[24]>; value: typeof Schema.Uint8ArrayFromSelf } +> +``` diff --git a/packages/evolution/docs/modules/TransactionBody.ts.md b/packages/evolution/docs/modules/TransactionBody.ts.md index 02129f31..da8d3ff3 100644 --- a/packages/evolution/docs/modules/TransactionBody.ts.md +++ b/packages/evolution/docs/modules/TransactionBody.ts.md @@ -27,11 +27,12 @@ parent: Modules - [fromCBORBytes](#fromcborbytes) - [fromCBORHex](#fromcborhex) - [schemas](#schemas) + - [CDDLSchema](#cddlschema) - [FromCBORBytes](#fromcborbytes-1) - [FromCBORHex](#fromcborhex-1) - [utils](#utils) - - [CDDLSchema](#cddlschema) - [FromCDDL](#fromcddl) + - [equals](#equals) - [isTransactionBody](#istransactionbody) - [make](#make) @@ -73,7 +74,7 @@ Default options use CML_DEFAULT_OPTIONS for CDDL/CML parity. **Signature** ```ts -export declare const toCBORBytes: (input: unknown, options?: CBOR.CodecOptions) => Uint8Array +export declare const toCBORBytes: (input: TransactionBody, options?: CBOR.CodecOptions) => Uint8Array ``` Added in v2.0.0 @@ -86,7 +87,7 @@ Default options use CML_DEFAULT_OPTIONS for CDDL/CML parity. **Signature** ```ts -export declare const toCBORHex: (input: unknown, options?: CBOR.CodecOptions) => string +export declare const toCBORHex: (input: TransactionBody, options?: CBOR.CodecOptions) => string ``` Added in v2.0.0 @@ -170,7 +171,7 @@ Default options use CML_DEFAULT_OPTIONS for CDDL/CML parity. **Signature** ```ts -export declare const fromCBORBytes: (bytes: Uint8Array, options?: CBOR.CodecOptions) => unknown +export declare const fromCBORBytes: (bytes: Uint8Array, options?: CBOR.CodecOptions) => TransactionBody ``` Added in v2.0.0 @@ -183,13 +184,28 @@ Default options use CML_DEFAULT_OPTIONS for CDDL/CML parity. **Signature** ```ts -export declare const fromCBORHex: (hex: string, options?: CBOR.CodecOptions) => unknown +export declare const fromCBORHex: (hex: string, options?: CBOR.CodecOptions) => TransactionBody ``` Added in v2.0.0 # schemas +## CDDLSchema + +CDDL schema for TransactionBody struct structure. + +**Signature** + +```ts +export declare const CDDLSchema: Schema.MapFromSelf< + typeof Schema.BigIntFromSelf, + Schema.Schema +> +``` + +Added in v2.0.0 + ## FromCBORBytes CBOR bytes transformation schema for TransactionBody. @@ -239,800 +255,24 @@ Added in v2.0.0 # utils -## CDDLSchema +## FromCDDL **Signature** ```ts -export declare const CDDLSchema: Schema.Union< - [ - Schema.Struct<{ - 0: Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[258]> - value: Schema.Array$> - } - > - 1: Schema.Array$< - Schema.Union< - [ - Schema.Tuple< - [ - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - typeof Schema.BigIntFromSelf, - Schema.Tuple2< - typeof Schema.BigIntFromSelf, - Schema.SchemaClass< - ReadonlyMap>, - ReadonlyMap>, - never - > - > - ] - >, - Schema.Element - ] - >, - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }> - ] - > - > - 2: typeof Schema.BigIntFromSelf - 3: Schema.optional - 4: Schema.optional< - Schema.Array$< - Schema.Union< - [ - Schema.Tuple2< - Schema.Literal<[0n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf> - >, - Schema.Tuple2< - Schema.Literal<[1n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf> - >, - Schema.Tuple< - [ - Schema.Literal<[2n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.Uint8ArrayFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[3n]>, - typeof Schema.Uint8ArrayFromSelf, - typeof Schema.Uint8ArrayFromSelf, - typeof Schema.BigIntFromSelf, - typeof Schema.BigIntFromSelf, - Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[30]> - value: Schema.Tuple2 - } - >, - typeof Schema.Uint8ArrayFromSelf, - Schema.Array$, - Schema.Array$< - Schema.SchemaClass< - | readonly [0n, bigint | null, any, any] - | readonly [1n, bigint | null, string] - | readonly [2n, string], - | readonly [0n, bigint | null, any, any] - | readonly [1n, bigint | null, string] - | readonly [2n, string], - never - > - >, - Schema.NullOr> - ] - >, - Schema.Tuple<[Schema.Literal<[4n]>, typeof Schema.Uint8ArrayFromSelf, typeof Schema.BigIntFromSelf]>, - Schema.Tuple< - [ - Schema.Literal<[7n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[8n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[9n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple<[Schema.Literal<[2n]>]>, - Schema.Tuple<[Schema.Literal<[3n]>]> - ] - > - ] - >, - Schema.Tuple< - [ - Schema.Literal<[10n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple<[Schema.Literal<[2n]>]>, - Schema.Tuple<[Schema.Literal<[3n]>]> - ] - > - ] - >, - Schema.Tuple< - [ - Schema.Literal<[11n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.Uint8ArrayFromSelf, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[12n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple<[Schema.Literal<[2n]>]>, - Schema.Tuple<[Schema.Literal<[3n]>]> - ] - >, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[13n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple<[Schema.Literal<[2n]>]>, - Schema.Tuple<[Schema.Literal<[3n]>]> - ] - >, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[14n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf> - ] - >, - Schema.Tuple< - [ - Schema.Literal<[15n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.NullishOr> - ] - >, - Schema.Tuple< - [ - Schema.Literal<[16n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.BigIntFromSelf, - Schema.NullishOr> - ] - >, - Schema.Tuple< - [ - Schema.Literal<[17n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[18n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.NullishOr> - ] - > - ] - > - > - > - 5: Schema.optional> - 7: Schema.optional - 8: Schema.optional - 9: Schema.optional< - Schema.SchemaClass< - ReadonlyMap>, - ReadonlyMap>, - never - > - > - 11: Schema.optional - 13: Schema.optional< - Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[258]> - value: Schema.Array$> - } - > - > - 14: Schema.optional> - 15: Schema.optional - 16: Schema.optional< - Schema.Union< - [ - Schema.Tuple< - [ - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - typeof Schema.BigIntFromSelf, - Schema.Tuple2< - typeof Schema.BigIntFromSelf, - Schema.SchemaClass< - ReadonlyMap>, - ReadonlyMap>, - never - > - > - ] - >, - Schema.Element - ] - >, - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }> - ] - > - > - 17: Schema.optional - 18: Schema.optional< - Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[258]> - value: Schema.Array$> - } - > - > - 19: Schema.optional< - Schema.SchemaClass< - ReadonlyMap< - readonly [0n, any] | readonly [1n, any] | readonly [2n, any] | readonly [3n, any] | readonly [4n, any], - ReadonlyMap - >, - ReadonlyMap< - readonly [0n, any] | readonly [1n, any] | readonly [2n, any] | readonly [3n, any] | readonly [4n, any], - ReadonlyMap - >, - never - > - > - 20: Schema.optional< - Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[258]> - value: Schema.Array$< - Schema.Tuple< - [ - typeof Schema.BigIntFromSelf, - typeof Schema.Uint8ArrayFromSelf, - Schema.SchemaClass< - | readonly [0n, readonly [any, bigint] | null, ReadonlyMap, any] - | readonly [1n, readonly [any, bigint] | null, readonly [bigint, bigint]] - | readonly [2n, ReadonlyMap, any] - | readonly [3n, readonly [any, bigint] | null] - | readonly [ - 4n, - readonly [any, bigint] | null, - ( - | readonly (readonly [0n | 1n, any])[] - | { - readonly _tag: "Tag" - readonly tag: 258 - readonly value: readonly (readonly [0n | 1n, any])[] - } - ), - ReadonlyMap, - { readonly _tag: "Tag"; readonly tag: 30; readonly value: readonly [bigint, bigint] } - ] - | readonly [5n, readonly [any, bigint] | null, readonly [readonly [string, any], any]] - | readonly [6n], - | readonly [0n, readonly [any, bigint] | null, ReadonlyMap, any] - | readonly [1n, readonly [any, bigint] | null, readonly [bigint, bigint]] - | readonly [2n, ReadonlyMap, any] - | readonly [3n, readonly [any, bigint] | null] - | readonly [ - 4n, - readonly [any, bigint] | null, - ( - | readonly (readonly [0n | 1n, any])[] - | { - readonly _tag: "Tag" - readonly tag: 258 - readonly value: readonly (readonly [0n | 1n, any])[] - } - ), - ReadonlyMap, - { readonly _tag: "Tag"; readonly tag: 30; readonly value: readonly [bigint, bigint] } - ] - | readonly [5n, readonly [any, bigint] | null, readonly [readonly [string, any], any]] - | readonly [6n], - never - >, - Schema.NullOr> - ] - > - > - } - > - > - 21: Schema.optional - 22: Schema.optional - }>, - Schema.MapFromSelf> - ] +export declare const FromCDDL: Schema.transformOrFail< + Schema.MapFromSelf>, + Schema.SchemaClass, + never > ``` -## FromCDDL +## equals **Signature** ```ts -export declare const FromCDDL: Schema.transformOrFail< - Schema.Union< - [ - Schema.Struct<{ - 0: Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[258]> - value: Schema.Array$> - } - > - 1: Schema.Array$< - Schema.Union< - [ - Schema.Tuple< - [ - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - typeof Schema.BigIntFromSelf, - Schema.Tuple2< - typeof Schema.BigIntFromSelf, - Schema.SchemaClass< - ReadonlyMap>, - ReadonlyMap>, - never - > - > - ] - >, - Schema.Element - ] - >, - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }> - ] - > - > - 2: typeof Schema.BigIntFromSelf - 3: Schema.optional - 4: Schema.optional< - Schema.Array$< - Schema.Union< - [ - Schema.Tuple2< - Schema.Literal<[0n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf> - >, - Schema.Tuple2< - Schema.Literal<[1n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf> - >, - Schema.Tuple< - [ - Schema.Literal<[2n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.Uint8ArrayFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[3n]>, - typeof Schema.Uint8ArrayFromSelf, - typeof Schema.Uint8ArrayFromSelf, - typeof Schema.BigIntFromSelf, - typeof Schema.BigIntFromSelf, - Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[30]> - value: Schema.Tuple2 - } - >, - typeof Schema.Uint8ArrayFromSelf, - Schema.Array$, - Schema.Array$< - Schema.SchemaClass< - | readonly [0n, bigint | null, any, any] - | readonly [1n, bigint | null, string] - | readonly [2n, string], - | readonly [0n, bigint | null, any, any] - | readonly [1n, bigint | null, string] - | readonly [2n, string], - never - > - >, - Schema.NullOr> - ] - >, - Schema.Tuple<[Schema.Literal<[4n]>, typeof Schema.Uint8ArrayFromSelf, typeof Schema.BigIntFromSelf]>, - Schema.Tuple< - [ - Schema.Literal<[7n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[8n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[9n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple<[Schema.Literal<[2n]>]>, - Schema.Tuple<[Schema.Literal<[3n]>]> - ] - > - ] - >, - Schema.Tuple< - [ - Schema.Literal<[10n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple<[Schema.Literal<[2n]>]>, - Schema.Tuple<[Schema.Literal<[3n]>]> - ] - > - ] - >, - Schema.Tuple< - [ - Schema.Literal<[11n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.Uint8ArrayFromSelf, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[12n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple<[Schema.Literal<[2n]>]>, - Schema.Tuple<[Schema.Literal<[3n]>]> - ] - >, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[13n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple<[Schema.Literal<[2n]>]>, - Schema.Tuple<[Schema.Literal<[3n]>]> - ] - >, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[14n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf> - ] - >, - Schema.Tuple< - [ - Schema.Literal<[15n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.NullishOr> - ] - >, - Schema.Tuple< - [ - Schema.Literal<[16n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.BigIntFromSelf, - Schema.NullishOr> - ] - >, - Schema.Tuple< - [ - Schema.Literal<[17n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - typeof Schema.BigIntFromSelf - ] - >, - Schema.Tuple< - [ - Schema.Literal<[18n]>, - Schema.Tuple2, typeof Schema.Uint8ArrayFromSelf>, - Schema.NullishOr> - ] - > - ] - > - > - > - 5: Schema.optional> - 7: Schema.optional - 8: Schema.optional - 9: Schema.optional< - Schema.SchemaClass< - ReadonlyMap>, - ReadonlyMap>, - never - > - > - 11: Schema.optional - 13: Schema.optional< - Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[258]> - value: Schema.Array$> - } - > - > - 14: Schema.optional> - 15: Schema.optional - 16: Schema.optional< - Schema.Union< - [ - Schema.Tuple< - [ - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - typeof Schema.BigIntFromSelf, - Schema.Tuple2< - typeof Schema.BigIntFromSelf, - Schema.SchemaClass< - ReadonlyMap>, - ReadonlyMap>, - never - > - > - ] - >, - Schema.Element - ] - >, - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }> - ] - > - > - 17: Schema.optional - 18: Schema.optional< - Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[258]> - value: Schema.Array$> - } - > - > - 19: Schema.optional< - Schema.SchemaClass< - ReadonlyMap< - readonly [0n, any] | readonly [1n, any] | readonly [2n, any] | readonly [3n, any] | readonly [4n, any], - ReadonlyMap - >, - ReadonlyMap< - readonly [0n, any] | readonly [1n, any] | readonly [2n, any] | readonly [3n, any] | readonly [4n, any], - ReadonlyMap - >, - never - > - > - 20: Schema.optional< - Schema.TaggedStruct< - "Tag", - { - tag: Schema.Literal<[258]> - value: Schema.Array$< - Schema.Tuple< - [ - typeof Schema.BigIntFromSelf, - typeof Schema.Uint8ArrayFromSelf, - Schema.SchemaClass< - | readonly [0n, readonly [any, bigint] | null, ReadonlyMap, any] - | readonly [1n, readonly [any, bigint] | null, readonly [bigint, bigint]] - | readonly [2n, ReadonlyMap, any] - | readonly [3n, readonly [any, bigint] | null] - | readonly [ - 4n, - readonly [any, bigint] | null, - ( - | readonly (readonly [0n | 1n, any])[] - | { - readonly _tag: "Tag" - readonly tag: 258 - readonly value: readonly (readonly [0n | 1n, any])[] - } - ), - ReadonlyMap, - { readonly _tag: "Tag"; readonly tag: 30; readonly value: readonly [bigint, bigint] } - ] - | readonly [5n, readonly [any, bigint] | null, readonly [readonly [string, any], any]] - | readonly [6n], - | readonly [0n, readonly [any, bigint] | null, ReadonlyMap, any] - | readonly [1n, readonly [any, bigint] | null, readonly [bigint, bigint]] - | readonly [2n, ReadonlyMap, any] - | readonly [3n, readonly [any, bigint] | null] - | readonly [ - 4n, - readonly [any, bigint] | null, - ( - | readonly (readonly [0n | 1n, any])[] - | { - readonly _tag: "Tag" - readonly tag: 258 - readonly value: readonly (readonly [0n | 1n, any])[] - } - ), - ReadonlyMap, - { readonly _tag: "Tag"; readonly tag: 30; readonly value: readonly [bigint, bigint] } - ] - | readonly [5n, readonly [any, bigint] | null, readonly [readonly [string, any], any]] - | readonly [6n], - never - >, - Schema.NullOr> - ] - > - > - } - > - > - 21: Schema.optional - 22: Schema.optional - }>, - Schema.MapFromSelf> - ] - >, - Schema.SchemaClass, - never -> +export declare const equals: (self: TransactionBody, that: TransactionBody) => boolean ``` ## isTransactionBody diff --git a/packages/evolution/docs/modules/TransactionOutput.ts.md b/packages/evolution/docs/modules/TransactionOutput.ts.md index ed6fb274..752fe68d 100644 --- a/packages/evolution/docs/modules/TransactionOutput.ts.md +++ b/packages/evolution/docs/modules/TransactionOutput.ts.md @@ -12,8 +12,8 @@ parent: Modules - [Either](#either) - [Either (namespace)](#either-namespace) -- [FastCheck](#fastcheck) - - [arbitrary](#arbitrary) +- [arbitrary](#arbitrary) + - [arbitrary](#arbitrary-1) - [constructors](#constructors) - [makeBabbage](#makebabbage) - [makeShelley](#makeshelley) @@ -25,6 +25,8 @@ parent: Modules - [toCBORHex](#tocborhex) - [equality](#equality) - [equals](#equals) +- [errors](#errors) + - [TransactionOutputError (class)](#transactionoutputerror-class) - [model](#model) - [BabbageTransactionOutput (class)](#babbagetransactionoutput-class) - [toString (method)](#tostring-method) @@ -33,17 +35,18 @@ parent: Modules - [toString (method)](#tostring-method-1) - [[Symbol.for("nodejs.util.inspect.custom")] (method)](#symbolfornodejsutilinspectcustom-method-1) - [schemas](#schemas) + - [TransactionOutput](#transactionoutput) +- [transformation](#transformation) - [FromBabbageTransactionOutputCDDLSchema](#frombabbagetransactionoutputcddlschema) + - [FromShelleyTransactionOutputCDDLSchema](#fromshelleytransactionoutputcddlschema) +- [transformer](#transformer) - [FromCBORBytes](#fromcborbytes-1) - [FromCBORHex](#fromcborhex-1) - [FromCDDL](#fromcddl) - - [FromShelleyTransactionOutputCDDLSchema](#fromshelleytransactionoutputcddlschema) - - [TransactionOutput](#transactionoutput) - [utils](#utils) - [CDDLSchema](#cddlschema) - [ShelleyTransactionOutputCDDL](#shelleytransactionoutputcddl) - [TransactionOutput (type alias)](#transactionoutput-type-alias) - - [TransactionOutputError (class)](#transactionoutputerror-class) --- @@ -55,7 +58,7 @@ Either namespace containing schema decode and encode operations. Added in v2.0.0 -# FastCheck +# arbitrary ## arbitrary @@ -77,10 +80,13 @@ Create a Babbage transaction output. ```ts export declare const makeBabbage: ( - address: Address.Address, - amount: Value.Value, - datumOption?: DatumOption.DatumOption, - scriptRef?: ScriptRef.ScriptRef + props: { + readonly address: RewardAccount | BaseAddress | EnterpriseAddress | PointerAddress | ByronAddress + readonly amount: Value.OnlyCoin | Value.WithAssets + readonly datumOption?: DatumOption.DatumHash | DatumOption.InlineDatum | undefined + readonly scriptRef?: ScriptRef.ScriptRef | undefined + }, + options?: Schema.MakeOptions | undefined ) => BabbageTransactionOutput ``` @@ -94,9 +100,12 @@ Create a Shelley transaction output. ```ts export declare const makeShelley: ( - address: Address.Address, - amount: Value.Value, - datumHash?: DatumOption.DatumHash + props: { + readonly address: RewardAccount | BaseAddress | EnterpriseAddress | PointerAddress | ByronAddress + readonly amount: Value.OnlyCoin | Value.WithAssets + readonly datumHash?: DatumOption.DatumHash | undefined + }, + options?: Schema.MakeOptions | undefined ) => ShelleyTransactionOutput ``` @@ -180,14 +189,30 @@ export declare const equals: (a: TransactionOutput, b: TransactionOutput) => boo Added in v2.0.0 +# errors + +## TransactionOutputError (class) + +Error class for TransactionOutput related operations. + +**Signature** + +```ts +export declare class TransactionOutputError +``` + +Added in v2.0.0 + # model ## BabbageTransactionOutput (class) Babbage-era transaction output format +CDDL: + ``` -CDDL: babbage_transaction_output = +babbage_transaction_output = {0 : address, 1 : value, ? 2 : datum_option, ? 3 : script_ref} ``` @@ -219,8 +244,10 @@ toString(): string Shelley-era transaction output format +CDDL: + ``` -CDDL: shelley_transaction_output = [address, amount : value, ? Bytes32] +shelley_transaction_output = [address, amount : value, ? Bytes32] ``` **Signature** @@ -249,40 +276,35 @@ toString(): string # schemas -## FromBabbageTransactionOutputCDDLSchema +## TransactionOutput -CDDL schema for Babbage transaction outputs +Union type for transaction outputs + +CDDL: ``` -CDDL: babbage_transaction_output = {0 : address, 1 : value, ? 2 : datum_option, ? 3 : script_ref} +transaction_output = shelley_transaction_output / babbage_transaction_output ``` **Signature** +```ts +export declare const TransactionOutput: Schema.Union<[typeof ShelleyTransactionOutput, typeof BabbageTransactionOutput]> +``` + +Added in v2.0.0 + +# transformation + +## FromBabbageTransactionOutputCDDLSchema + +CDDL schema for Babbage transaction outputs + +**Signature** + ```ts export declare const FromBabbageTransactionOutputCDDLSchema: Schema.transformOrFail< - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }>, + Schema.MapFromSelf>, Schema.SchemaClass, never > @@ -290,10 +312,45 @@ export declare const FromBabbageTransactionOutputCDDLSchema: Schema.transformOrF Added in v2.0.0 +## FromShelleyTransactionOutputCDDLSchema + +CDDL schema for Shelley transaction outputs + +**Signature** + +```ts +export declare const FromShelleyTransactionOutputCDDLSchema: Schema.transformOrFail< + Schema.Tuple< + [ + typeof Schema.Uint8ArrayFromSelf, + Schema.Union< + [ + typeof Schema.BigIntFromSelf, + Schema.Tuple2< + typeof Schema.BigIntFromSelf, + Schema.SchemaClass< + ReadonlyMap>, + ReadonlyMap>, + never + > + > + ] + >, + Schema.Element + ] + >, + Schema.SchemaClass, + never +> +``` + +Added in v2.0.0 + +# transformer + ## FromCBORBytes CBOR bytes transformation schema for TransactionOutput. -Transforms between CBOR bytes and TransactionOutput. **Signature** @@ -332,28 +389,7 @@ export declare const FromCBORBytes: ( never >, Schema.transformOrFail< - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }>, + Schema.MapFromSelf>, Schema.SchemaClass, never > @@ -367,7 +403,6 @@ Added in v2.0.0 ## FromCBORHex CBOR hex transformation schema for TransactionOutput. -Transforms between CBOR hex string and TransactionOutput. **Signature** @@ -408,28 +443,7 @@ export declare const FromCBORHex: ( never >, Schema.transformOrFail< - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }>, + Schema.MapFromSelf>, Schema.SchemaClass, never > @@ -445,12 +459,6 @@ Added in v2.0.0 CDDL schema for transaction outputs -``` -CDDL: transaction_output = shelley_transaction_output / babbage_transaction_output -shelley_transaction_output = [address, amount : value, ? Bytes32] -babbage_transaction_output = {0 : address, 1 : value, ? 2 : datum_option, ? 3 : script_ref} -``` - **Signature** ```ts @@ -480,28 +488,7 @@ export declare const FromCDDL: Schema.Union< never >, Schema.transformOrFail< - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }>, + Schema.MapFromSelf>, Schema.SchemaClass, never > @@ -511,60 +498,6 @@ export declare const FromCDDL: Schema.Union< Added in v2.0.0 -## FromShelleyTransactionOutputCDDLSchema - -CDDL schema for Shelley transaction outputs - -``` -CDDL: shelley_transaction_output = [address, amount : value, ? Bytes32] -``` - -**Signature** - -```ts -export declare const FromShelleyTransactionOutputCDDLSchema: Schema.transformOrFail< - Schema.Tuple< - [ - typeof Schema.Uint8ArrayFromSelf, - Schema.Union< - [ - typeof Schema.BigIntFromSelf, - Schema.Tuple2< - typeof Schema.BigIntFromSelf, - Schema.SchemaClass< - ReadonlyMap>, - ReadonlyMap>, - never - > - > - ] - >, - Schema.Element - ] - >, - Schema.SchemaClass, - never -> -``` - -Added in v2.0.0 - -## TransactionOutput - -Union type for transaction outputs - -``` -CDDL: transaction_output = shelley_transaction_output / babbage_transaction_output -``` - -**Signature** - -```ts -export declare const TransactionOutput: Schema.Union<[typeof ShelleyTransactionOutput, typeof BabbageTransactionOutput]> -``` - -Added in v2.0.0 - # utils ## CDDLSchema @@ -593,28 +526,7 @@ export declare const CDDLSchema: Schema.Union< Schema.Element ] >, - Schema.Struct<{ - 0: typeof Schema.Uint8ArrayFromSelf - 1: Schema.SchemaClass< - bigint | readonly [bigint, ReadonlyMap>], - bigint | readonly [bigint, ReadonlyMap>], - never - > - 2: Schema.optional< - Schema.SchemaClass< - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - readonly [0n, any] | readonly [1n, { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }], - never - > - > - 3: Schema.optional< - Schema.SchemaClass< - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - { readonly _tag: "Tag"; readonly tag: 24; readonly value: any }, - never - > - > - }> + Schema.MapFromSelf> ] > ``` @@ -652,11 +564,3 @@ export declare const ShelleyTransactionOutputCDDL: Schema.Tuple< ```ts export type TransactionOutput = typeof TransactionOutput.Type ``` - -## TransactionOutputError (class) - -**Signature** - -```ts -export declare class TransactionOutputError -``` diff --git a/packages/evolution/src/AuxiliaryData.ts b/packages/evolution/src/AuxiliaryData.ts index a4c516cb..2cc40a3a 100644 --- a/packages/evolution/src/AuxiliaryData.ts +++ b/packages/evolution/src/AuxiliaryData.ts @@ -112,12 +112,9 @@ export type AuxiliaryData = Schema.Schema.Type // Conway (current) CDDL form: tagged map with numeric keys export const CDDLSchema = CBOR.tag( 259, - Schema.Struct({ - 0: Schema.optional(Metadata.CDDLSchema), - 1: Schema.optional(Schema.Array(NativeScripts.CDDLSchema)), - 2: Schema.optional(Schema.Array(PlutusV1.CDDLSchema)), - 3: Schema.optional(Schema.Array(PlutusV2.CDDLSchema)), - 4: Schema.optional(Schema.Array(PlutusV3.CDDLSchema)) + Schema.MapFromSelf({ + key: CBOR.Integer, + value: CBOR.CBORSchema }) ) @@ -146,59 +143,63 @@ export const FromCDDL = Schema.transformOrFail(AnyEraCDDL, Schema.typeSchema(Aux // Always encode as Conway format (tag 259) for compatibility switch (auxData._tag) { case "ConwayAuxiliaryData": { - const struct: Record = {} + // const struct: Record = {} + const map = new Map() if (auxData.metadata !== undefined) - struct[0] = yield* ParseResult.encodeEither(Metadata.FromCDDL)(auxData.metadata) + map.set(0n, yield* ParseResult.encodeEither(Metadata.FromCDDL)(auxData.metadata)) if (auxData.nativeScripts !== undefined) { const scripts = [] for (const s of auxData.nativeScripts) { scripts.push(yield* ParseResult.encodeEither(NativeScripts.FromCDDL)(s)) } - struct[1] = scripts + map.set(1n, scripts) } if (auxData.plutusV1Scripts !== undefined) { const scripts = [] for (const s of auxData.plutusV1Scripts) { scripts.push(yield* ParseResult.encodeEither(PlutusV1.FromCDDL)(s)) } - struct[2] = scripts + map.set(2n, scripts) } if (auxData.plutusV2Scripts !== undefined) { const scripts = [] for (const s of auxData.plutusV2Scripts) { scripts.push(yield* ParseResult.encodeEither(PlutusV2.FromCDDL)(s)) } - struct[3] = scripts + map.set(3n, scripts) } if (auxData.plutusV3Scripts !== undefined) { const scripts = [] for (const s of auxData.plutusV3Scripts) { scripts.push(yield* ParseResult.encodeEither(PlutusV3.FromCDDL)(s)) } - struct[4] = scripts + map.set(4n, scripts) } - return { value: struct, tag: 259 as const, _tag: "Tag" as const } + return { value: map, tag: 259 as const, _tag: "Tag" as const } } case "ShelleyMAAuxiliaryData": { - // Convert to Conway format for encoding - const struct: Record = {} - if (auxData.metadata !== undefined) - struct[0] = yield* ParseResult.encodeEither(Metadata.FromCDDL)(auxData.metadata) - if (auxData.nativeScripts !== undefined) { - const scripts = [] - for (const s of auxData.nativeScripts) { - scripts.push(yield* ParseResult.encodeEither(NativeScripts.FromCDDL)(s)) + // Encode ShelleyMA strictly as a 2-element array [metadataMap, nativeScriptList] + // Use empty map/array when values are absent to avoid CBOR specials and match CML decoding. + const encodedMetadata = + auxData.metadata !== undefined + ? new Map(yield* ParseResult.encodeEither(Metadata.FromCDDL)(auxData.metadata)) + : new Map() + const encodedScripts: Array = (() => { + const list = auxData.nativeScripts ?? [] + const scripts: Array = [] + for (const s of list) { + scripts.push(ParseResult.encodeEither(NativeScripts.FromCDDL)(s).pipe(E.getOrThrow)) } - struct[1] = scripts - } - return { value: struct, tag: 259 as const, _tag: "Tag" as const } + return scripts + })() + return [encodedMetadata, encodedScripts] } case "ShelleyAuxiliaryData": { - // Convert to Conway format for encoding - const struct: Record = {} - if (auxData.metadata !== undefined) - struct[0] = yield* ParseResult.encodeEither(Metadata.FromCDDL)(auxData.metadata) - return { value: struct, tag: 259 as const, _tag: "Tag" as const } + // Encode Shelley era as plain metadata map (no tag) + { + const m = yield* ParseResult.encodeEither(Metadata.FromCDDL)(auxData.metadata) + return new Map(m) + } } } }), @@ -207,35 +208,25 @@ export const FromCDDL = Schema.transformOrFail(AnyEraCDDL, Schema.typeSchema(Aux // Conway tag(259) if (CBOR.isTag(input) && input.tag === 259) { const struct = input.value - const metadata = struct[0] ? yield* ParseResult.decodeEither(Metadata.FromCDDL)(struct[0]) : undefined - let nativeScripts: Array | undefined = undefined - if (struct[1]) { - nativeScripts = [] - for (const s of struct[1]) { - nativeScripts.push(yield* ParseResult.decodeEither(NativeScripts.FromCDDL)(s)) - } - } - let plutusV1Scripts: Array | undefined = undefined - if (struct[2]) { - plutusV1Scripts = [] - for (const s of struct[2]) { - plutusV1Scripts.push(yield* ParseResult.decodeEither(PlutusV1.FromCDDL)(s)) - } - } - let plutusV2Scripts: Array | undefined = undefined - if (struct[3]) { - plutusV2Scripts = [] - for (const s of struct[3]) { - plutusV2Scripts.push(yield* ParseResult.decodeEither(PlutusV2.FromCDDL)(s)) - } - } - let plutusV3Scripts: Array | undefined = undefined - if (struct[4]) { - plutusV3Scripts = [] - for (const s of struct[4]) { - plutusV3Scripts.push(yield* ParseResult.decodeEither(PlutusV3.FromCDDL)(s)) - } - } + const meta = struct.get(0n) + const metadata = meta ? yield* ParseResult.decodeUnknownEither(Metadata.FromCDDL)(meta) : undefined + + const nScripts = struct.get(1n) + const nativeScripts = nScripts + ? yield* ParseResult.decodeUnknownEither(Schema.Array(NativeScripts.FromCDDL))(nScripts) + : undefined + const rawPlutusV1 = struct.get(2n) + const plutusV1Scripts = rawPlutusV1 + ? yield* ParseResult.decodeUnknownEither(Schema.Array(PlutusV1.FromCDDL))(rawPlutusV1) + : undefined + const rawPlutusV2 = struct.get(3n) + const plutusV2Scripts = rawPlutusV2 + ? yield* ParseResult.decodeUnknownEither(Schema.Array(PlutusV2.FromCDDL))(rawPlutusV2) + : undefined + const rawPlutusV3 = struct.get(4n) + const plutusV3Scripts = rawPlutusV3 + ? yield* ParseResult.decodeUnknownEither(Schema.Array(PlutusV3.FromCDDL))(rawPlutusV3) + : undefined return new ConwayAuxiliaryData({ metadata, nativeScripts, @@ -252,12 +243,18 @@ export const FromCDDL = Schema.transformOrFail(AnyEraCDDL, Schema.typeSchema(Aux let nativeScripts: Array | undefined if (arr.length >= 1 && arr[0] !== undefined) { - metadata = yield* ParseResult.decodeEither(Metadata.FromCDDL)(arr[0]) + const m = yield* ParseResult.decodeEither(Metadata.FromCDDL)(arr[0]) + metadata = m.size === 0 ? undefined : m } if (arr.length >= 2 && arr[1] !== undefined) { - nativeScripts = [] - for (const s of arr[1] as ReadonlyArray) { - nativeScripts.push(yield* ParseResult.decodeEither(NativeScripts.FromCDDL)(s)) + const raw = arr[1] as ReadonlyArray + if (Array.isArray(raw) && raw.length === 0) { + nativeScripts = undefined + } else { + nativeScripts = [] + for (const s of raw) { + nativeScripts.push(yield* ParseResult.decodeEither(NativeScripts.FromCDDL)(s)) + } } } return new ShelleyMAAuxiliaryData({ metadata, nativeScripts }) @@ -364,8 +361,13 @@ export const equals = (a: AuxiliaryData, b: AuxiliaryData): boolean => { // Different eras are never equal if (a._tag !== b._tag) return false - const cmpArray = (x?: ReadonlyArray, y?: ReadonlyArray) => - x && y ? x.length === y.length && x.every((v, i) => v === y[i]) : x === y + const arrEq = (x?: ReadonlyArray, y?: ReadonlyArray, cmp: (a: T, b: T) => boolean = (u, v) => u === v) => { + if (x === undefined && y === undefined) return true + if (x === undefined || y === undefined) return false + if (x.length !== y.length) return false + for (let i = 0; i < x.length; i++) if (!cmp(x[i], y[i])) return false + return true + } // Compare metadata if both have it if (a.metadata && b.metadata) { @@ -374,15 +376,15 @@ export const equals = (a: AuxiliaryData, b: AuxiliaryData): boolean => { // Conway-specific comparisons if (a._tag === "ConwayAuxiliaryData" && b._tag === "ConwayAuxiliaryData") { - if (!cmpArray(a.nativeScripts, b.nativeScripts)) return false - if (!cmpArray(a.plutusV1Scripts, b.plutusV1Scripts)) return false - if (!cmpArray(a.plutusV2Scripts, b.plutusV2Scripts)) return false - if (!cmpArray(a.plutusV3Scripts, b.plutusV3Scripts)) return false + if (!arrEq(a.nativeScripts as any, b.nativeScripts as any, NativeScripts.equals)) return false + if (!arrEq(a.plutusV1Scripts as any, b.plutusV1Scripts as any, PlutusV1.equals)) return false + if (!arrEq(a.plutusV2Scripts as any, b.plutusV2Scripts as any, PlutusV2.equals)) return false + if (!arrEq(a.plutusV3Scripts as any, b.plutusV3Scripts as any, PlutusV3.equals)) return false } // ShelleyMA-specific comparisons if (a._tag === "ShelleyMAAuxiliaryData" && b._tag === "ShelleyMAAuxiliaryData") { - if (!cmpArray(a.nativeScripts, b.nativeScripts)) return false + if (!arrEq(a.nativeScripts as any, b.nativeScripts as any, NativeScripts.equals)) return false } // Shelley has only metadata, already compared above @@ -404,13 +406,22 @@ export const conwayArbitrary: FastCheck.Arbitrary = FastChe plutusV3Scripts: FastCheck.option(FastCheck.array(PlutusV3.arbitrary, { maxLength: 3 }), { nil: undefined }) }).map((r) => new ConwayAuxiliaryData(r)) -// Provide a convenient constructor alias for tests using `new AuxiliaryData.AuxiliaryData({...})` -;(AuxiliaryData as any).AuxiliaryData = ConwayAuxiliaryData - export const shelleyMAArbitrary: FastCheck.Arbitrary = FastCheck.record({ metadata: FastCheck.option(Metadata.arbitrary, { nil: undefined }), nativeScripts: FastCheck.option(FastCheck.array(NativeScripts.arbitrary, { maxLength: 3 }), { nil: undefined }) -}).map((r) => new ShelleyMAAuxiliaryData(r)) +}) + .filter((r) => { + const hasMeta = r.metadata !== undefined + // Disallow both undefined and scripts-only (since encoder omits scripts without metadata) + return hasMeta + }) + .map( + (r) => + new ShelleyMAAuxiliaryData({ + metadata: r.metadata && r.metadata.size > 0 ? r.metadata : undefined, + nativeScripts: r.nativeScripts && r.nativeScripts.length > 0 ? r.nativeScripts : undefined + }) + ) export const shelleyArbitrary: FastCheck.Arbitrary = Metadata.arbitrary.map( (metadata) => new ShelleyAuxiliaryData({ metadata }) diff --git a/packages/evolution/src/Certificate.ts b/packages/evolution/src/Certificate.ts index 0a44fbf4..060f8ec1 100644 --- a/packages/evolution/src/Certificate.ts +++ b/packages/evolution/src/Certificate.ts @@ -695,6 +695,12 @@ export const equals = (a: Certificate, b: Certificate): boolean => { Credential.equals(a.stakeCredential, b.stakeCredential) && PoolKeyHash.equals(a.poolKeyHash, b.poolKeyHash) ) + case "PoolRegistration": + return ( + b._tag === "PoolRegistration" && + // Delegate to PoolParams.equals for deep comparison + PoolParams.equals(a.poolParams, (b as any).poolParams) + ) case "PoolRetirement": return ( b._tag === "PoolRetirement" && @@ -715,6 +721,70 @@ export const equals = (a: Certificate, b: Certificate): boolean => { Credential.equals(a.stakeCredential, b.stakeCredential) && DRep.equals(a.drep, b.drep) ) + case "StakeVoteDelegCert": + return ( + b._tag === "StakeVoteDelegCert" && + Credential.equals(a.stakeCredential, b.stakeCredential) && + PoolKeyHash.equals(a.poolKeyHash, b.poolKeyHash) && + DRep.equals(a.drep, b.drep) + ) + case "StakeRegDelegCert": + return ( + b._tag === "StakeRegDelegCert" && + Credential.equals(a.stakeCredential, b.stakeCredential) && + PoolKeyHash.equals(a.poolKeyHash, b.poolKeyHash) && + Coin.equals(a.coin, b.coin) + ) + case "VoteRegDelegCert": + return ( + b._tag === "VoteRegDelegCert" && + Credential.equals(a.stakeCredential, b.stakeCredential) && + DRep.equals(a.drep, b.drep) && + Coin.equals(a.coin, b.coin) + ) + case "StakeVoteRegDelegCert": + return ( + b._tag === "StakeVoteRegDelegCert" && + Credential.equals(a.stakeCredential, b.stakeCredential) && + PoolKeyHash.equals(a.poolKeyHash, b.poolKeyHash) && + DRep.equals(a.drep, b.drep) && + Coin.equals(a.coin, b.coin) + ) + case "AuthCommitteeHotCert": + return ( + b._tag === "AuthCommitteeHotCert" && + Credential.equals(a.committeeColdCredential, b.committeeColdCredential) && + Credential.equals(a.committeeHotCredential, b.committeeHotCredential) + ) + case "ResignCommitteeColdCert": + return ( + b._tag === "ResignCommitteeColdCert" && + Credential.equals(a.committeeColdCredential, b.committeeColdCredential) && + // anchor may be null/undefined + ((a.anchor === undefined && b.anchor === undefined) || + (a.anchor !== undefined && b.anchor !== undefined && Anchor.equals(a.anchor as any, b.anchor as any))) + ) + case "RegDrepCert": + return ( + b._tag === "RegDrepCert" && + Credential.equals(a.drepCredential, b.drepCredential) && + Coin.equals(a.coin, b.coin) && + ((a.anchor === undefined && b.anchor === undefined) || + (a.anchor !== undefined && b.anchor !== undefined && Anchor.equals(a.anchor as any, b.anchor as any))) + ) + case "UnregDrepCert": + return ( + b._tag === "UnregDrepCert" && + Credential.equals(a.drepCredential, b.drepCredential) && + Coin.equals(a.coin, b.coin) + ) + case "UpdateDrepCert": + return ( + b._tag === "UpdateDrepCert" && + Credential.equals(a.drepCredential, b.drepCredential) && + ((a.anchor === undefined && b.anchor === undefined) || + (a.anchor !== undefined && b.anchor !== undefined && Anchor.equals(a.anchor as any, b.anchor as any))) + ) // Add other cases as needed default: return false diff --git a/packages/evolution/src/Data.ts b/packages/evolution/src/Data.ts index fc563f63..f938413a 100644 --- a/packages/evolution/src/Data.ts +++ b/packages/evolution/src/Data.ts @@ -685,6 +685,46 @@ export const cborValueToPlutusData = (cborValue: CBOR.CBOR): Data => { }) } +/** + * Deep structural equality for Plutus Data values. + * Handles maps, lists, ints, bytes, and constrs. + */ +export const equals = (a: Data, b: Data): boolean => { + if (typeof a === "bigint" || typeof b === "bigint") return a === b + + if (typeof a === "string" || typeof b === "string") return a === b + + // Arrays (Lists) + if (Array.isArray(a) && Array.isArray(b)) { + if (a.length !== b.length) return false + for (let i = 0; i < a.length; i++) if (!equals(a[i] as Data, b[i] as Data)) return false + return true + } + + // Constr + if (a instanceof Constr && b instanceof Constr) { + if (a.index !== b.index) return false + if (a.fields.length !== b.fields.length) return false + for (let i = 0; i < a.fields.length; i++) if (!equals(a.fields[i] as Data, b.fields[i] as Data)) return false + return true + } + + // Map + if (a instanceof Map && b instanceof Map) { + if (a.size !== b.size) return false + const aEntries = Array.from(a.entries()) + for (const [ak, av] of aEntries) { + // find equivalent key in b + const match = Array.from(b.entries()).find(([bk]) => equals(ak as Data, bk as Data)) + if (!match) return false + if (!equals(av as Data, match[1] as Data)) return false + } + return true + } + + return false +} + export const CDDLSchema = CBOR.CBORSchema /** diff --git a/packages/evolution/src/DatumOption.ts b/packages/evolution/src/DatumOption.ts index 5c6edf6f..595c57ec 100644 --- a/packages/evolution/src/DatumOption.ts +++ b/packages/evolution/src/DatumOption.ts @@ -132,7 +132,7 @@ export const equals = (a: DatumOption, b: DatumOption): boolean => { return Bytes32.equals(a.hash, b.hash) } if (a._tag === "InlineDatum" && b._tag === "InlineDatum") { - return a.data === b.data + return PlutusData.equals(a.data, b.data) } return false } @@ -150,6 +150,11 @@ export const inlineDatumArbitrary = PlutusData.arbitrary.map((data) => new Inlin */ export const arbitrary = FastCheck.oneof(datumHashArbitrary, inlineDatumArbitrary) +export const CDDLSchema = Schema.Union( + Schema.Tuple(Schema.Literal(0n), CBOR.ByteArray), // [0, Bytes32] + Schema.Tuple(Schema.Literal(1n), CBOR.tag(24, Schema.Uint8ArrayFromSelf)) // [1, tag(24, bytes)] - PlutusData as bytes in tag 24 +) + /** * CDDL schema for DatumOption. * datum_option = [0, Bytes32] / [1, #6.24(bytes)] @@ -161,66 +166,49 @@ export const arbitrary = FastCheck.oneof(datumHashArbitrary, inlineDatumArbitrar * @since 2.0.0 * @category schemas */ -export const DatumOptionCDDLSchema = Schema.transformOrFail( - Schema.Union( - Schema.Tuple(Schema.Literal(0n), CBOR.ByteArray), // [0, Bytes32] - Schema.Tuple(Schema.Literal(1n), CBOR.tag(24, Schema.Uint8ArrayFromSelf)) // [1, tag(24, bytes)] - PlutusData as bytes in tag 24 - ), - Schema.typeSchema(DatumOptionSchema), - { - strict: true, - encode: (toA) => - E.gen(function* () { - const result = - toA._tag === "DatumHash" - ? ([0n, toA.hash] as const) // Encode as [0, Bytes32] - : ([1n, { _tag: "Tag" as const, tag: 24 as const, value: PlutusData.toCBORBytes(toA.data) }] as const) // Encode as [1, tag(24, bytes)] - return yield* E.right(result) - }), - decode: ([tag, value], _, ast) => - E.gen(function* () { - if (tag === 0n) { - // Decode as DatumHash - return yield* E.right(new DatumHash({ hash: value }, { disableValidation: true })) - } else if (tag === 1n) { - // Decode as InlineDatum - value is now a CBOR tag 24 wrapper containing bytes - const taggedValue = value as { _tag: "Tag"; tag: number; value: Uint8Array } - if (taggedValue._tag !== "Tag" || taggedValue.tag !== 24) { - return yield* E.left( - new ParseResult.Type( - ast, - [tag, value], - `Invalid InlineDatum format: expected tag 24, got ${taggedValue._tag} with tag ${taggedValue.tag}` - ) - ) - } - return yield* E.right( - new InlineDatum( - { - data: PlutusData.fromCBORBytes(taggedValue.value) - }, - { disableValidation: true } +export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(DatumOptionSchema), { + strict: true, + encode: (toA) => + E.gen(function* () { + const result = + toA._tag === "DatumHash" + ? ([0n, toA.hash] as const) // Encode as [0, Bytes32] + : ([1n, { _tag: "Tag" as const, tag: 24 as const, value: PlutusData.toCBORBytes(toA.data) }] as const) // Encode as [1, tag(24, bytes)] + return yield* E.right(result) + }), + decode: ([tag, value], _, ast) => + E.gen(function* () { + if (tag === 0n) { + // Decode as DatumHash + return yield* E.right(new DatumHash({ hash: value }, { disableValidation: true })) + } else if (tag === 1n) { + // Decode as InlineDatum - value is now a CBOR tag 24 wrapper containing bytes + const taggedValue = value as { _tag: "Tag"; tag: number; value: Uint8Array } + if (taggedValue._tag !== "Tag" || taggedValue.tag !== 24) { + return yield* E.left( + new ParseResult.Type( + ast, + [tag, value], + `Invalid InlineDatum format: expected tag 24, got ${taggedValue._tag} with tag ${taggedValue.tag}` ) ) } - return yield* E.left( - new ParseResult.Type(ast, [tag, value], `Invalid DatumOption tag: ${tag}. Expected 0 or 1.`) + return yield* E.right( + new InlineDatum( + { + data: PlutusData.fromCBORBytes(taggedValue.value) + }, + { disableValidation: true } + ) ) - }) - } -).annotations({ + } + return yield* E.left(new ParseResult.Type(ast, [tag, value], `Invalid DatumOption tag: ${tag}. Expected 0 or 1.`)) + }) +}).annotations({ identifier: "DatumOption.DatumOptionCDDLSchema", description: "Transforms CBOR structure to DatumOption" }) -/** - * CDDL schema for DatumOption. - * - * @since 2.0.0 - * @category schemas - */ -export const FromCDDL = DatumOptionCDDLSchema - /** * CBOR bytes transformation schema for DatumOption. * Transforms between Uint8Array and DatumOption using CBOR encoding. @@ -231,7 +219,7 @@ export const FromCDDL = DatumOptionCDDLSchema export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( CBOR.FromBytes(options), // Uint8Array → CBOR - DatumOptionCDDLSchema // CBOR → DatumOption + FromCDDL // CBOR → DatumOption ).annotations({ identifier: "DatumOption.FromCBORBytes", description: "Transforms CBOR bytes to DatumOption" diff --git a/packages/evolution/src/KeyHash.ts b/packages/evolution/src/KeyHash.ts index ae2ec440..26370c4d 100644 --- a/packages/evolution/src/KeyHash.ts +++ b/packages/evolution/src/KeyHash.ts @@ -19,13 +19,12 @@ export class KeyHashError extends Data.TaggedError("KeyHashError")<{ }> {} /** - * KeyHash as a TaggedClass (breaking change from branded hex string). + * KeyHash + * + * CDDL: * ``` * addr_keyhash = hash28 * ``` - * Follows CIP-0019 binary representation. - * - * Stores raw 28-byte value for performance. * * @since 2.0.0 * @category model @@ -46,7 +45,7 @@ export class KeyHash extends Schema.TaggedClass()("KeyHash", { * Schema transformer from bytes to KeyHash. * * @since 2.0.0 - * @category schemas + * @category transformer */ export const FromBytes = Schema.transform(Hash28.BytesSchema, KeyHash, { strict: true, @@ -60,7 +59,7 @@ export const FromBytes = Schema.transform(Hash28.BytesSchema, KeyHash, { * Schema transformer from hex string to KeyHash. * * @since 2.0.0 - * @category schemas + * @category transformer */ export const FromHex = Schema.compose( Bytes.FromHex, // string -> Uint8Array @@ -70,7 +69,7 @@ export const FromHex = Schema.compose( }) /** - * Smart constructor for KeyHash that validates and applies branding. + * Smart constructor for KeyHash * * @since 2.0.0 * @category constructors @@ -86,33 +85,30 @@ export const make = (...args: ConstructorParameters) => new KeyH export const equals = (a: KeyHash, b: KeyHash): boolean => Bytes.equals(a.hash, b.hash) // ============================================================================ -// Parsing Functions +// Decoding Functions // ============================================================================ /** - * Parse a KeyHash from raw bytes. - * Expects exactly 28 bytes. + * Decode a KeyHash from raw bytes. * * @since 2.0.0 - * @category parsing + * @category encoding/decoding */ export const fromBytes = Function.makeDecodeSync(FromBytes, KeyHashError, "KeyHash.fromBytes") /** - * Parse a KeyHash from a hex string. - * Expects exactly 56 hex characters (28 bytes). + * Decode a KeyHash from a hex string. * * @since 2.0.0 - * @category parsing + * @category encoding/decoding */ export const fromHex = Function.makeDecodeSync(FromHex, KeyHashError, "KeyHash.fromHex") /** * FastCheck arbitrary for generating random KeyHash instances. - * Used for property-based testing to generate valid test data. * * @since 2.0.0 - * @category testing + * @category arbitrary */ export const arbitrary: FastCheck.Arbitrary = FastCheck.uint8Array({ minLength: 28, maxLength: 28 }).map( (bytes) => make({ hash: bytes }, { disableValidation: true }) @@ -126,7 +122,7 @@ export const arbitrary: FastCheck.Arbitrary = FastCheck.uint8Array({ mi * Convert a KeyHash to raw bytes. * * @since 2.0.0 - * @category encoding + * @category encoding/decoding */ export const toBytes = (keyhash: KeyHash): Uint8Array => new Uint8Array(keyhash.hash) // Return a copy of the underlying bytes @@ -134,44 +130,44 @@ export const toBytes = (keyhash: KeyHash): Uint8Array => new Uint8Array(keyhash. * Convert a KeyHash to a hex string. * * @since 2.0.0 - * @category encoding + * @category encoding/decoding */ export const toHex = (keyhash: KeyHash): string => Bytes.toHex(keyhash.hash) -// ============================================================================ -// Cryptographic Operations (throwing) -// ============================================================================ - /** - * Create a KeyHash from a PrivateKey (sync version that throws KeyHashError). - * All errors are normalized to KeyHashError with contextual information. + * Create a KeyHash from a PrivateKey + * + * @since 2.0.0 + * @category constructors */ export const fromPrivateKey = (privateKey: PrivateKey): KeyHash => { const vkey = VKey.fromPrivateKey(privateKey) - const publicKeyBytes = VKey.toBytes(vkey) + const publicKeyBytes = vkey.bytes const keyHashBytes = blake2b(publicKeyBytes, { dkLen: 28 }) - return KeyHash.make({ hash: keyHashBytes }) + return KeyHash.make({ hash: keyHashBytes }, { disableValidation: true }) } /** - * Create a KeyHash from a VKey (sync version that throws KeyHashError). - * All errors are normalized to KeyHashError with contextual information. + * Create a KeyHash from a VKey + * + * @since 2.0.0 + * @category constructors */ export const fromVKey = (vkey: VKey.VKey): KeyHash => { - const publicKeyBytes = VKey.toBytes(vkey) + const publicKeyBytes = vkey.bytes const keyHashBytes = blake2b(publicKeyBytes, { dkLen: 28 }) - return KeyHash.make({ hash: keyHashBytes }) + return KeyHash.make({ hash: keyHashBytes }, { disableValidation: true }) } // ============================================================================ -// Effect Namespace - Effect-based Error Handling +// Either Namespace - Either-based Error Handling // ============================================================================ /** - * Effect-based error handling variants for functions that can fail. + * Either-based error handling variants for functions that can fail. * * @since 2.0.0 - * @category effect + * @category either */ export namespace Either { export const fromBytes = Function.makeDecodeEither(FromBytes, KeyHashError) diff --git a/packages/evolution/src/Mint.ts b/packages/evolution/src/Mint.ts index ff0db3f5..7073564f 100644 --- a/packages/evolution/src/Mint.ts +++ b/packages/evolution/src/Mint.ts @@ -1,4 +1,4 @@ -import { Data, Effect as Eff, Equal, FastCheck, ParseResult, Schema } from "effect" +import { Data, Effect as Eff, FastCheck, ParseResult, Schema } from "effect" import * as AssetName from "./AssetName.js" import * as Bytes from "./Bytes.js" @@ -217,7 +217,38 @@ export const policyCount = (mint: Mint): number => mint.size * @since 2.0.0 * @category equality */ -export const equals = (self: Mint, that: Mint): boolean => Equal.equals(self, that) +export const equals = (self: Mint, that: Mint): boolean => { + if (self.size !== that.size) return false + + for (const [policyId, assetMap] of self.entries()) { + // find matching policyId in `that` + let foundPolicy = false + for (const [otherPolicyId, otherAssetMap] of that.entries()) { + if (PolicyId.equals(policyId, otherPolicyId)) { + foundPolicy = true + + // compare inner asset maps + if (assetMap.size !== otherAssetMap.size) return false + + for (const [assetName, amount] of assetMap.entries()) { + let foundAsset = false + for (const [otherAssetName, otherAmount] of otherAssetMap.entries()) { + if (AssetName.equals(assetName, otherAssetName) && amount === otherAmount) { + foundAsset = true + break + } + } + if (!foundAsset) return false + } + + break + } + } + if (!foundPolicy) return false + } + + return true +} export const CDDLSchema = Schema.MapFromSelf({ key: CBOR.ByteArray, // Policy ID as 28-byte Uint8Array diff --git a/packages/evolution/src/MultiAsset.ts b/packages/evolution/src/MultiAsset.ts index 9505a09d..9cdf2065 100644 --- a/packages/evolution/src/MultiAsset.ts +++ b/packages/evolution/src/MultiAsset.ts @@ -199,21 +199,25 @@ export const getAssetsByPolicy = (multiAsset: MultiAsset, policyId: PolicyId.Pol export const equals = (a: MultiAsset, b: MultiAsset): boolean => a.size === b.size && Array.from(a.keys()).every((policyId) => { + // find corresponding policy key in `b` by value (PolicyId.equals) + const bPolicyKey = Array.from(b.keys()).find((k) => PolicyId.equals(k, policyId)) const aAssets = a.get(policyId) - const bAssets = b.get(policyId) + const bAssets = bPolicyKey === undefined ? undefined : b.get(bPolicyKey) if ((aAssets === undefined) !== (bAssets === undefined)) return false if (aAssets === undefined) return true if (bAssets === undefined) return false - return ( - aAssets.size === bAssets.size && - Array.from(aAssets.keys()).every((assetName) => { - const aAmount = aAssets.get(assetName) - const bAmount = bAssets.get(assetName) - return aAmount === bAmount - }) - ) + if (aAssets.size !== bAssets.size) return false + + // compare assetName keys by value (AssetName.equals) + return Array.from(aAssets.keys()).every((assetName) => { + const bAssetKey = Array.from(bAssets.keys()).find((k) => AssetName.equals(k, assetName)) + if (bAssetKey === undefined) return false + const aAmount = aAssets.get(assetName) + const bAmount = bAssets.get(bAssetKey) + return aAmount === bAmount + }) }) /** @@ -251,8 +255,16 @@ export const arbitrary: FastCheck.Arbitrary = FastCheck.uniqueArray( return FastCheck.array(assetsForPolicy(), { minLength: policies.length, maxLength: policies.length }).map( (assetMaps) => { - const entries = policies.map((policy, idx) => [policy, assetMaps[idx]] as const) - return make(new Map(entries)) + // Build a properly typed Map + const result = new Map>() + for (let i = 0; i < policies.length; i++) { + const policy = policies[i]! + const assetMap = assetMaps[i]! + // assetMap is generated to be a Map + result.set(policy, assetMap as Map) + } + + return make(result) } ) }) diff --git a/packages/evolution/src/NativeScripts.ts b/packages/evolution/src/NativeScripts.ts index edd1ce0e..b49f8c00 100644 --- a/packages/evolution/src/NativeScripts.ts +++ b/packages/evolution/src/NativeScripts.ts @@ -361,6 +361,39 @@ const nativeArbitrary = (depth: number): FastCheck.Arbitrary => { export const arbitrary: FastCheck.Arbitrary = nativeArbitrary(2) +/** + * Deep structural equality for Native scripts. + * Compares shape, values and recurses into nested scripts. + */ +export const equals = (a: Native, b: Native): boolean => { + if (a.type !== b.type) return false + switch (a.type) { + case "sig": + return a.keyHash === (b as any).keyHash + case "before": + return a.slot === (b as any).slot + case "after": + return a.slot === (b as any).slot + case "all": + case "any": { + const as = a.scripts + const bs = (b as any).scripts as ReadonlyArray + if (as.length !== bs.length) return false + for (let i = 0; i < as.length; i++) if (!equals(as[i], bs[i])) return false + return true + } + case "atLeast": { + const bs = b as any + if (a.required !== bs.required) return false + const as = a.scripts + const bscripts = bs.scripts as ReadonlyArray + if (as.length !== bscripts.length) return false + for (let i = 0; i < as.length; i++) if (!equals(as[i], bscripts[i])) return false + return true + } + } +} + /** * CBOR bytes transformation schema for Native. * Transforms between CBOR bytes and Native using CBOR encoding. diff --git a/packages/evolution/src/PointerAddress.ts b/packages/evolution/src/PointerAddress.ts index b8ed8554..7080faf7 100644 --- a/packages/evolution/src/PointerAddress.ts +++ b/packages/evolution/src/PointerAddress.ts @@ -99,7 +99,12 @@ export const decodeVariableLength: ( bytesRead++ // Big-endian base-128 accumulate - number = (number << 7) | (b & 0x7f) + // Use arithmetic multiplication instead of bitwise shift to avoid + // 32-bit signed integer overflow caused by JS bitwise operators. + // (number << 7) coerces to a 32-bit signed int which can become + // negative for large values; using multiplication keeps the + // full JS Number precision for large varints. + number = number * 128 + (b & 0x7f) if ((b & 0x80) === 0) { const value = yield* ParseResult.decode(Natural.Natural)(number) diff --git a/packages/evolution/src/PoolParams.ts b/packages/evolution/src/PoolParams.ts index 2b3ee1a9..475d57a4 100644 --- a/packages/evolution/src/PoolParams.ts +++ b/packages/evolution/src/PoolParams.ts @@ -196,20 +196,50 @@ export const FromHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) = * @since 2.0.0 * @category equality */ -export const equals = (a: PoolParams, b: PoolParams): boolean => - PoolKeyHash.equals(a.operator, b.operator) && - VrfKeyHash.equals(a.vrfKeyhash, b.vrfKeyhash) && - a.pledge === b.pledge && - a.cost === b.cost && - UnitInterval.equals(a.margin, b.margin) && - a.rewardAccount.networkId === b.rewardAccount.networkId && - a.rewardAccount.stakeCredential._tag === b.rewardAccount.stakeCredential._tag && - a.poolOwners.length === b.poolOwners.length && - a.poolOwners.every((owner, index) => KeyHash.equals(owner, b.poolOwners[index])) && - a.relays.length === b.relays.length && - // Note: Relay equality comparison would need to be implemented - ((a.poolMetadata === undefined && b.poolMetadata === undefined) || - (a.poolMetadata !== undefined && b.poolMetadata !== undefined && a.poolMetadata.url === b.poolMetadata.url)) +export const equals = (a: PoolParams, b: PoolParams): boolean => { + if (!PoolKeyHash.equals(a.operator, b.operator)) return false + + if (!VrfKeyHash.equals(a.vrfKeyhash, b.vrfKeyhash)) return false + + if (a.pledge !== b.pledge) return false + + if (a.cost !== b.cost) return false + + if (!UnitInterval.equals(a.margin, b.margin)) return false + + // compare reward accounts structurally + if (!RewardAccount.equals(a.rewardAccount, b.rewardAccount)) return false + + if (a.poolOwners.length !== b.poolOwners.length) return false + + for (let i = 0; i < a.poolOwners.length; i++) { + if (!KeyHash.equals(a.poolOwners[i], b.poolOwners[i])) return false + } + + if (a.relays.length !== b.relays.length) return false + + for (let i = 0; i < a.relays.length; i++) { + // Relay.equals exists and performs structural equality + if (!Relay.equals(a.relays[i], b.relays[i])) return false + } + + if (a.poolMetadata === undefined && b.poolMetadata === undefined) return true + + if (a.poolMetadata !== undefined && b.poolMetadata !== undefined) { + // Prefer structural PoolMetadata.equals when available + if (typeof (PoolMetadata as any).equals === "function") { + return (PoolMetadata as any).equals(a.poolMetadata, b.poolMetadata) + } + + // Fallback to url equality + if (a.poolMetadata.url !== b.poolMetadata.url) return false + + return true + } + + // One side has poolMetadata while the other doesn't + return false +} /** * Create a PoolParams instance with validation. diff --git a/packages/evolution/src/ScriptRef.ts b/packages/evolution/src/ScriptRef.ts index ffc6cf84..3540d6c7 100644 --- a/packages/evolution/src/ScriptRef.ts +++ b/packages/evolution/src/ScriptRef.ts @@ -68,6 +68,8 @@ export const FromHex = Schema.compose( identifier: "ScriptRef.FromHex" }) +export const CDDLSchema = CBOR.tag(24, Schema.Uint8ArrayFromSelf) + /** * CDDL schema for ScriptRef following the Conway specification. * @@ -80,7 +82,7 @@ export const FromHex = Schema.compose( * @since 2.0.0 * @category schemas */ -export const FromCDDL = Schema.transformOrFail(CBOR.tag(24, Schema.Uint8ArrayFromSelf), ScriptRef, { +export const FromCDDL = Schema.transformOrFail(CDDLSchema, ScriptRef, { strict: true, encode: (_, __, ___, toA) => Effect.succeed({ diff --git a/packages/evolution/src/TransactionBody.ts b/packages/evolution/src/TransactionBody.ts index b39f46af..7d952142 100644 --- a/packages/evolution/src/TransactionBody.ts +++ b/packages/evolution/src/TransactionBody.ts @@ -142,53 +142,26 @@ const decodeAuxiliaryDataHash = ParseResult.decodeEither(AuxiliaryDataHash.Bytes const decodeScriptDataHash = ParseResult.decodeEither(ScriptDataHash.FromBytes) const decodeKeyHash = ParseResult.decodeEither(KeyHash.FromBytes) +const decodeInputs = ParseResult.decodeUnknownEither(CBOR.tag(258, Schema.Array(TransactionInput.FromCDDL))) + /** * CDDL schema for TransactionBody struct structure. * - * Maps the TransactionBody fields to their CDDL spec. - * Uses Struct with proper CBOR tags for sets (tag 258) - * * @since 2.0.0 * @category schemas */ -// Accept both Struct (object with numeric keys) and Map -const CDDLAStruct = Schema.Struct({ - 0: CBOR.tag(258, Schema.Array(TransactionInput.CDDLSchema)), // set - required - 1: Schema.Array(TransactionOutput.CDDLSchema), // [* transaction_output] - required - 2: CBOR.Integer, // coin (fee) - required - 3: Schema.optional(CBOR.Integer), // slot_no (ttl) - optional - 4: Schema.optional(Schema.Array(Certificate.CDDLSchema)), // certificates - optional - 5: Schema.optional(Withdrawals.CDDLSchema), // withdrawals - optional - 7: Schema.optional(CBOR.ByteArray), // auxiliary_data_hash - optional - 8: Schema.optional(CBOR.Integer), // slot_no (validity_interval_start) - optional - 9: Schema.optional(Schema.encodedSchema(Mint.CDDLSchema)), // mint - optional - 11: Schema.optional(CBOR.ByteArray), // script_data_hash - optional - 13: Schema.optional(CBOR.tag(258, Schema.Array(TransactionInput.CDDLSchema))), // nonempty_set (collateral_inputs) - optional - 14: Schema.optional(Schema.Array(CBOR.ByteArray)), // required_signers - optional - 15: Schema.optional(CBOR.Integer), // network_id - optional - 16: Schema.optional(TransactionOutput.CDDLSchema), // transaction_output (collateral_return) - optional - 17: Schema.optional(CBOR.Integer), // coin (total_collateral) - optional - 18: Schema.optional(CBOR.tag(258, Schema.Array(TransactionInput.CDDLSchema))), // nonempty_set (reference_inputs) - optional - 19: Schema.optional(Schema.encodedSchema(VotingProcedures.CDDLSchema)), // voting_procedures - optional - 20: Schema.optional(CBOR.tag(258, Schema.Array(ProposalProcedure.CDDLSchema))), // proposal_procedures (nonempty_set) - optional - 21: Schema.optional(CBOR.Integer), // coin (current_treasury_value) - optional - 22: Schema.optional(CBOR.Integer) // positive_coin (donation) - optional -}) - -const CDDLMap = Schema.MapFromSelf({ +export const CDDLSchema = Schema.MapFromSelf({ key: CBOR.Integer, value: CBOR.CBORSchema }) -export const CDDLSchema = Schema.Union(CDDLAStruct, CDDLMap) - type CDDLSchema = typeof CDDLSchema.Type export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(TransactionBody), { strict: true, encode: (toA) => E.gen(function* () { - const record = {} as any + const record = new Map() // Required fields // 0: inputs - always tagged as set @@ -197,7 +170,7 @@ export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(Tra for (let i = 0; i < inputsLen; i++) { inputsArr[i] = yield* encodeTxInput(toA.inputs[i]) } - record[0] = CBOR.Tag.make({ tag: 258, value: inputsArr }, { disableValidation: true }) + record.set(0n, CBOR.Tag.make({ tag: 258, value: inputsArr }, { disableValidation: true })) // 1: outputs const outputsLen = toA.outputs.length @@ -205,13 +178,13 @@ export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(Tra for (let i = 0; i < outputsLen; i++) { outputsArr[i] = yield* encodeTxOutput(toA.outputs[i]) } - record[1] = outputsArr + record.set(1n, outputsArr) // 2: fee - record[2] = toA.fee + record.set(2n, toA.fee) // Optional fields (assign directly when present) - if (toA.ttl !== undefined) record[3] = toA.ttl + if (toA.ttl !== undefined) record.set(3n, toA.ttl) if (toA.certificates) { const len = toA.certificates.length @@ -219,7 +192,7 @@ export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(Tra for (let i = 0; i < len; i++) { arr[i] = yield* encodeCertificate(toA.certificates[i]) } - record[4] = arr + record.set(4n, arr) } if (toA.withdrawals) { @@ -228,16 +201,16 @@ export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(Tra const accountBytes = yield* encodeRewardAccountBytes(rewardAccount) map.set(accountBytes, coin) } - record[5] = map + record.set(5n, map) } - if (toA.auxiliaryDataHash) record[7] = toA.auxiliaryDataHash.bytes + if (toA.auxiliaryDataHash) record.set(7n, toA.auxiliaryDataHash.bytes) - if (toA.validityIntervalStart !== undefined) record[8] = toA.validityIntervalStart + if (toA.validityIntervalStart !== undefined) record.set(8n, toA.validityIntervalStart) - if (toA.mint) record[9] = yield* encodeMint(toA.mint) + if (toA.mint) record.set(9n, yield* encodeMint(toA.mint)) - if (toA.scriptDataHash) record[11] = toA.scriptDataHash.hash + if (toA.scriptDataHash) record.set(11n, toA.scriptDataHash.hash) if (toA.collateralInputs) { const len = toA.collateralInputs.length @@ -245,20 +218,23 @@ export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(Tra for (let i = 0; i < len; i++) { arr[i] = yield* encodeTxInput(toA.collateralInputs[i]) } - record[13] = CBOR.Tag.make({ tag: 258, value: arr }, { disableValidation: true }) + record.set(13n, CBOR.Tag.make({ tag: 258, value: arr }, { disableValidation: true })) } if (toA.requiredSigners) { - record[14] = toA.requiredSigners.map((signer) => signer.hash) + record.set( + 14n, + toA.requiredSigners.map((signer) => signer.hash) + ) } - if (toA.networkId !== undefined) record[15] = BigInt(toA.networkId) + if (toA.networkId !== undefined) record.set(15n, BigInt(toA.networkId)) if (toA.collateralReturn) { - record[16] = yield* encodeTxOutput(toA.collateralReturn) + record.set(16n, yield* encodeTxOutput(toA.collateralReturn)) } - if (toA.totalCollateral !== undefined) record[17] = toA.totalCollateral + if (toA.totalCollateral !== undefined) record.set(17n, toA.totalCollateral) if (toA.referenceInputs) { const len = toA.referenceInputs.length @@ -266,10 +242,10 @@ export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(Tra for (let i = 0; i < len; i++) { arr[i] = yield* encodeTxInput(toA.referenceInputs[i]) } - record[18] = CBOR.Tag.make({ tag: 258, value: arr }, { disableValidation: true }) + record.set(18n, CBOR.Tag.make({ tag: 258, value: arr }, { disableValidation: true })) } - if (toA.votingProcedures) record[19] = yield* encodeVotingProcedures(toA.votingProcedures) + if (toA.votingProcedures) record.set(19n, yield* encodeVotingProcedures(toA.votingProcedures)) if (toA.proposalProcedures && toA.proposalProcedures.procedures.length > 0) { const len = toA.proposalProcedures.procedures.length @@ -277,41 +253,41 @@ export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(Tra for (let i = 0; i < len; i++) { arr[i] = yield* encodeProposalProcedure(toA.proposalProcedures.procedures[i]) } - record[20] = CBOR.Tag.make({ tag: 258, value: arr }, { disableValidation: true }) + record.set(20n, CBOR.Tag.make({ tag: 258, value: arr }, { disableValidation: true })) } - if (toA.currentTreasuryValue !== undefined) record[21] = toA.currentTreasuryValue + if (toA.currentTreasuryValue !== undefined) record.set(21n, toA.currentTreasuryValue) - if (toA.donation !== undefined) record[22] = toA.donation + if (toA.donation !== undefined) record.set(22n, toA.donation) return record as CDDLSchema }), decode: (fromA) => E.gen(function* () { - // Helpers to read from Map or Struct - const isMap = (v: any): v is ReadonlyMap => v instanceof Map - const getKey = (src: any, key: number) => (isMap(src) ? src.get(BigInt(key)) : (src as any)[key]) // Required fields - access via helper - const inputsTag = getKey(fromA as any, 0) // CBOR.Tag 258 - const inputsArray = inputsTag.value - const inputsLen = inputsArray.length - const inputs = new Array(inputsLen) - for (let i = 0; i < inputsLen; i++) { - inputs[i] = yield* decodeTxInput(inputsArray[i]) - } - - const outputsArray = getKey(fromA as any, 1) + const inputsTag = fromA.get(0n) + const decodedInputs = yield* decodeInputs(inputsTag) + const inputs = decodedInputs.value + + // const inputsArray = inputsTag.value + // const inputsLen = inputsArray.length + // const inputs = new Array(inputsLen) + // for (let i = 0; i < inputsLen; i++) { + // inputs[i] = yield* decodeTxInput(inputsArray[i]) + // } + + const outputsArray = fromA.get(1n) as Array const outputsLen = outputsArray.length const outputs = new Array(outputsLen) for (let i = 0; i < outputsLen; i++) { outputs[i] = yield* decodeTxOutput(outputsArray[i]) } - const fee = getKey(fromA as any, 2) + const fee = fromA.get(2n) as bigint // Optional fields - access as record properties - const ttl = getKey(fromA as any, 3) + const ttl = fromA.get(3n) as bigint | undefined - const certificatesArray = getKey(fromA as any, 4) + const certificatesArray = fromA.get(4n) as Array let certificates: NonEmptyArray | undefined if (certificatesArray) { const len = certificatesArray.length @@ -323,12 +299,10 @@ export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(Tra } let withdrawals: Withdrawals.Withdrawals | undefined - const withdrawalsMap = getKey(fromA as any, 5) + const withdrawalsMap = fromA.get(5n) as typeof Withdrawals.CDDLSchema.Type | undefined if (withdrawalsMap) { const decodedWithdrawals = new Map() - const entriesIter: Iterable<[Uint8Array, bigint]> = isMap(withdrawalsMap) - ? (withdrawalsMap as ReadonlyMap).entries() - : Object.entries(withdrawalsMap as Record).map(([k, v]) => [Bytes.fromHex(k), v as bigint]) + const entriesIter = (withdrawalsMap as ReadonlyMap).entries() for (const [accountBytes, coinAmount] of entriesIter) { const rewardAccount = yield* decodeRewardAccountBytes(accountBytes) decodedWithdrawals.set(rewardAccount, coinAmount) @@ -336,17 +310,23 @@ export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(Tra withdrawals = new Withdrawals.Withdrawals({ withdrawals: decodedWithdrawals }) } - const auxiliaryDataHashBytes = getKey(fromA as any, 7) + const auxiliaryDataHashBytes = fromA.get(7n) as Uint8Array | undefined const auxiliaryDataHash = auxiliaryDataHashBytes ? yield* decodeAuxiliaryDataHash(auxiliaryDataHashBytes) : undefined - const validityIntervalStart = getKey(fromA as any, 8) - const mintData = getKey(fromA as any, 9) + const validityIntervalStart = fromA.get(8n) as bigint | undefined + const mintData = fromA.get(9n) as typeof Mint.CDDLSchema.Type | undefined const mint = mintData ? yield* decodeMint(mintData) : undefined - const scriptDataHashBytes = getKey(fromA as any, 11) + const scriptDataHashBytes = fromA.get(11n) as Uint8Array | undefined const scriptDataHash = scriptDataHashBytes ? yield* decodeScriptDataHash(scriptDataHashBytes) : undefined - const collateralInputsTag = getKey(fromA as any, 13) // CBOR.Tag 258 + const collateralInputsTag = fromA.get(13n) as + | { + _tag: "Tag" + tag: 258 + value: ReadonlyArray + } + | undefined const collateralInputsArray = collateralInputsTag ? collateralInputsTag.value : undefined let collateralInputs: NonEmptyArray | undefined if (collateralInputsArray) { @@ -358,7 +338,7 @@ export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(Tra collateralInputs = arr as NonEmptyArray } - const requiredSignersArray = getKey(fromA as any, 14) + const requiredSignersArray = fromA.get(14n) as ReadonlyArray | undefined let requiredSigners: NonEmptyArray | undefined if (requiredSignersArray) { const len = requiredSignersArray.length @@ -368,13 +348,19 @@ export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(Tra } requiredSigners = arr as NonEmptyArray } - const networkIdBigInt = getKey(fromA as any, 15) - const networkId = networkIdBigInt ? NetworkId.make(Number(networkIdBigInt)) : undefined - const collateralReturnData = getKey(fromA as any, 16) + const networkIdBigInt = fromA.get(15n) as bigint | undefined + const networkId = networkIdBigInt !== undefined ? NetworkId.make(Number(networkIdBigInt)) : undefined + const collateralReturnData = fromA.get(16n) as typeof TransactionOutput.CDDLSchema.Type | undefined const collateralReturn = collateralReturnData ? yield* decodeTxOutput(collateralReturnData) : undefined - const totalCollateral = getKey(fromA as any, 17) - - const referenceInputsTag = getKey(fromA as any, 18) // CBOR.Tag 258 + const totalCollateral = fromA.get(17n) as Coin.Coin | undefined + + const referenceInputsTag = fromA.get(18n) as + | { + _tag: "Tag" + tag: 258 + value: ReadonlyArray + } + | undefined const referenceInputsArray = referenceInputsTag ? referenceInputsTag.value : undefined let referenceInputs: NonEmptyArray | undefined if (referenceInputsArray) { @@ -385,9 +371,15 @@ export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(Tra } referenceInputs = arr as NonEmptyArray } - const votingProceduresData = getKey(fromA as any, 19) + const votingProceduresData = fromA.get(19n) as typeof VotingProcedures.CDDLSchema.Type | undefined const votingProcedures = votingProceduresData ? yield* decodeVotingProcedures(votingProceduresData) : undefined - const proposalProceduresTag = getKey(fromA as any, 20) + const proposalProceduresTag = fromA.get(20n) as + | { + _tag: "Tag" + tag: 258 + value: ReadonlyArray + } + | undefined const proposalProceduresArray = proposalProceduresTag ? (proposalProceduresTag.value as ReadonlyArray) : undefined @@ -396,8 +388,8 @@ export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(Tra procedures: yield* E.all(proposalProceduresArray.map((pp) => decodeProposalProcedure(pp))) }) : undefined - const currentTreasuryValue = getKey(fromA as any, 21) - const donation = getKey(fromA as any, 22) + const currentTreasuryValue = fromA.get(21n) as Coin.Coin | undefined + const donation = fromA.get(22n) as Coin.Coin | undefined return new TransactionBody( { @@ -469,10 +461,9 @@ export const isTransactionBody = Schema.is(TransactionBody) * @category parsing */ export const fromCBORBytes = Function.makeCBORDecodeSync( - FromCDDL as any, + FromCDDL, TransactionBodyError, "TransactionBody.fromCBORBytes", - CBOR.CML_DEFAULT_OPTIONS ) /** @@ -483,10 +474,9 @@ export const fromCBORBytes = Function.makeCBORDecodeSync( * @category parsing */ export const fromCBORHex = Function.makeCBORDecodeHexSync( - FromCDDL as any, + FromCDDL, TransactionBodyError, "TransactionBody.fromCBORHex", - CBOR.CML_DEFAULT_OPTIONS ) // ============================================================================ @@ -501,10 +491,9 @@ export const fromCBORHex = Function.makeCBORDecodeHexSync( * @category encoding */ export const toCBORBytes = Function.makeCBOREncodeSync( - FromCDDL as any, + FromCDDL, TransactionBodyError, "TransactionBody.toCBORBytes", - CBOR.CML_DEFAULT_OPTIONS ) /** @@ -515,10 +504,9 @@ export const toCBORBytes = Function.makeCBOREncodeSync( * @category encoding */ export const toCBORHex = Function.makeCBOREncodeHexSync( - FromCDDL as any, + FromCDDL, TransactionBodyError, "TransactionBody.toCBORHex", - CBOR.CML_DEFAULT_OPTIONS ) // ============================================================================ @@ -532,26 +520,10 @@ export const toCBORHex = Function.makeCBOREncodeHexSync( * @category either */ export namespace Either { - export const fromCBORBytes = Function.makeCBORDecodeEither( - FromCDDL as any, - TransactionBodyError, - CBOR.CML_DEFAULT_OPTIONS - ) - export const fromCBORHex = Function.makeCBORDecodeHexEither( - FromCDDL as any, - TransactionBodyError, - CBOR.CML_DEFAULT_OPTIONS - ) - export const toCBORBytes = Function.makeCBOREncodeEither( - FromCDDL as any, - TransactionBodyError, - CBOR.CML_DEFAULT_OPTIONS - ) - export const toCBORHex = Function.makeCBOREncodeHexEither( - FromCDDL as any, - TransactionBodyError, - CBOR.CML_DEFAULT_OPTIONS - ) + export const fromCBORBytes = Function.makeCBORDecodeEither(FromCDDL, TransactionBodyError, CBOR.CML_DEFAULT_OPTIONS) + export const fromCBORHex = Function.makeCBORDecodeHexEither(FromCDDL, TransactionBodyError, CBOR.CML_DEFAULT_OPTIONS) + export const toCBORBytes = Function.makeCBOREncodeEither(FromCDDL, TransactionBodyError, CBOR.CML_DEFAULT_OPTIONS) + export const toCBORHex = Function.makeCBOREncodeHexEither(FromCDDL, TransactionBodyError, CBOR.CML_DEFAULT_OPTIONS) } // ============================================================================ @@ -693,3 +665,65 @@ export const arbitrary: FastCheck.Arbitrary = donation: props.donation }) }) + +export const equals = (self: TransactionBody, that: TransactionBody): boolean => { + // quick identity + if (self === that) return true + + // helper for optional fields: both undefined => equal, one undefined => not equal, otherwise use provided comparator + const optionalEquals = (x: T | undefined, y: T | undefined, cmp: (u: T, v: T) => boolean): boolean => { + if (x === undefined && y === undefined) return true + if (x === undefined || y === undefined) return false + return cmp(x, y) + } + + // compare arrays elementwise using provided comparator + const arrayEquals = (a: ReadonlyArray, b: ReadonlyArray, cmp: (u: T, v: T) => boolean): boolean => { + if (a.length !== b.length) return false + for (let i = 0; i < a.length; i++) { + if (!cmp(a[i], b[i])) return false + } + return true + } + + // required fields + if (!arrayEquals(self.inputs, that.inputs, TransactionInput.equals)) return false + if (!arrayEquals(self.outputs, that.outputs, TransactionOutput.equals)) return false + if (!Coin.equals(self.fee, that.fee)) return false + + // optional primitives + if (self.ttl !== that.ttl) return false + if (self.validityIntervalStart !== that.validityIntervalStart) return false + + // optional complex fields + if ( + !optionalEquals( + self.certificates, + that.certificates, + (a, b) => a.length === b.length && a.every((v, i) => Certificate.equals(v, b[i])) + ) + ) + return false + if (!optionalEquals(self.withdrawals, that.withdrawals, Withdrawals.equals)) return false + if (!optionalEquals(self.auxiliaryDataHash, that.auxiliaryDataHash, (a, b) => Bytes.equals(a.bytes, b.bytes))) + return false + if (!optionalEquals(self.mint, that.mint, Mint.equals)) return false + if (!optionalEquals(self.scriptDataHash, that.scriptDataHash, ScriptDataHash.equals)) return false + if ( + !optionalEquals(self.collateralInputs, that.collateralInputs, (a, b) => arrayEquals(a, b, TransactionInput.equals)) + ) + return false + if (!optionalEquals(self.requiredSigners, that.requiredSigners, (a, b) => arrayEquals(a, b, KeyHash.equals))) + return false + if (!optionalEquals(self.networkId, that.networkId, NetworkId.equals)) return false + if (!optionalEquals(self.collateralReturn, that.collateralReturn, TransactionOutput.equals)) return false + if (!optionalEquals(self.totalCollateral, that.totalCollateral, Coin.equals)) return false + if (!optionalEquals(self.referenceInputs, that.referenceInputs, (a, b) => arrayEquals(a, b, TransactionInput.equals))) + return false + if (!optionalEquals(self.votingProcedures, that.votingProcedures, VotingProcedures.equals)) return false + if (!optionalEquals(self.proposalProcedures, that.proposalProcedures, ProposalProcedures.equals)) return false + if (!optionalEquals(self.currentTreasuryValue, that.currentTreasuryValue, Coin.equals)) return false + if (!optionalEquals(self.donation, that.donation, PositiveCoin.equals)) return false + + return true +} diff --git a/packages/evolution/src/TransactionMetadatum.ts b/packages/evolution/src/TransactionMetadatum.ts index a2f9a3d3..17846b2d 100644 --- a/packages/evolution/src/TransactionMetadatum.ts +++ b/packages/evolution/src/TransactionMetadatum.ts @@ -250,7 +250,7 @@ const int64Arbitrary = FastCheck.bigInt({ min: I64_MIN, max: I64_MAX }) export const arbitrary: FastCheck.Arbitrary = FastCheck.oneof( FastCheck.string().map((value) => new TextMetadatum({ value })), int64Arbitrary.map((value) => new IntMetadatum({ value })), - FastCheck.uint8Array({ maxLength: 10 }).map((value) => new BytesMetadatum({ value })), + FastCheck.uint8Array({ minLength: 1, maxLength: 10 }).map((value) => new BytesMetadatum({ value })), FastCheck.array( FastCheck.oneof( FastCheck.string().map((value) => new TextMetadatum({ value })), diff --git a/packages/evolution/src/TransactionOutput.ts b/packages/evolution/src/TransactionOutput.ts index 4d8d9434..cd6e2579 100644 --- a/packages/evolution/src/TransactionOutput.ts +++ b/packages/evolution/src/TransactionOutput.ts @@ -8,6 +8,12 @@ import * as Function from "./Function.js" import * as ScriptRef from "./ScriptRef.js" import * as Value from "./Value.js" +/** + * Error class for TransactionOutput related operations. + * + * @since 2.0.0 + * @category errors + */ export class TransactionOutputError extends Data.TaggedError("TransactionOutputError")<{ message?: string cause?: unknown @@ -15,36 +21,21 @@ export class TransactionOutputError extends Data.TaggedError("TransactionOutputE // Pre-bind frequently used ParseResult helpers for hot paths const encAddress = ParseResult.encodeEither(Address.FromBytes) -const decAddress = ParseResult.decodeEither(Address.FromBytes) +const decAddress = ParseResult.decodeUnknownEither(Address.FromBytes) const encValue = ParseResult.encodeEither(Value.FromCDDL) -const decValue = ParseResult.decodeEither(Value.FromCDDL) -const encDatumOption = ParseResult.encodeEither(DatumOption.DatumOptionCDDLSchema) -const decDatumOption = ParseResult.decodeEither(DatumOption.DatumOptionCDDLSchema) +const decValue = ParseResult.decodeUnknownEither(Value.FromCDDL) +const encDatumOption = ParseResult.encodeEither(DatumOption.FromCDDL) +const decDatumOption = ParseResult.decodeUnknownEither(DatumOption.FromCDDL) const decDatumHash = ParseResult.decodeEither(DatumOption.DatumHashFromBytes) const encScriptRef = ParseResult.encodeEither(ScriptRef.FromCDDL) -const decScriptRef = ParseResult.decodeEither(ScriptRef.FromCDDL) - -/** - * TransactionOutput types based on Conway CDDL specification - * - * ``` - * CDDL: transaction_output = shelley_transaction_output / babbage_transaction_output - * - * shelley_transaction_output = [address, amount : value, ? Bytes32] - * - * babbage_transaction_output = - * {0 : address, 1 : value, ? 2 : datum_option, ? 3 : script_ref} - * ``` - * - * @since 2.0.0 - * @category model - */ +const decScriptRef = ParseResult.decodeUnknownEither(ScriptRef.FromCDDL) /** * Shelley-era transaction output format * + * CDDL: * ``` - * CDDL: shelley_transaction_output = [address, amount : value, ? Bytes32] + * shelley_transaction_output = [address, amount : value, ? Bytes32] * ``` * * @since 2.0.0 @@ -72,8 +63,9 @@ export class ShelleyTransactionOutput extends Schema.TaggedClass E.gen(function* () { + const outputMap = new Map() const addressBytes = yield* encAddress(toI.address) const valueBytes = yield* encValue(toI.amount) - // Prepare optional fields const datumOptionBytes = toI.datumOption !== undefined ? yield* encDatumOption(toI.datumOption) : undefined - const scriptRefBytes = toI.scriptRef !== undefined ? yield* encScriptRef(toI.scriptRef) : undefined // Build result object with conditional properties - return { - 0: addressBytes, - 1: valueBytes, - ...(datumOptionBytes !== undefined && { 2: datumOptionBytes }), - ...(scriptRefBytes !== undefined && { 3: scriptRefBytes }) + outputMap.set(0n, addressBytes) + outputMap.set(1n, valueBytes) + if (datumOptionBytes !== undefined) { + outputMap.set(2n, datumOptionBytes) + } + if (scriptRefBytes !== undefined) { + outputMap.set(3n, scriptRefBytes) } + return outputMap }), decode: (fromI) => E.gen(function* () { - const addressBytes = fromI[0] - const valueBytes = fromI[1] - const datumOptionBytes = fromI[2] - const scriptRefBytes = fromI[3] - - if (addressBytes === undefined || valueBytes === undefined) { - // The input should match the BabbageTransactionOutput CDDL struct (keys 0 and 1 are required) - return yield* E.left(new ParseResult.Type(BabbageTransactionOutputCDDL.ast, fromI)) - } + // Assume `fromI` is a CBOR Map and read keys directly. + const addressBytes = fromI.get(0n) + const valueBytes = fromI.get(1n) + const datumOptionBytes = fromI.get(2n) + const scriptRefBytes = fromI.get(3n) const address = yield* decAddress(addressBytes) const amount = yield* decValue(valueBytes) - let datumOption: DatumOption.DatumOption | undefined - if (datumOptionBytes !== undefined) { - datumOption = yield* decDatumOption(datumOptionBytes) - } + const datumOption = datumOptionBytes !== undefined ? yield* decDatumOption(datumOptionBytes) : undefined - let scriptRef: ScriptRef.ScriptRef | undefined - if (scriptRefBytes !== undefined) { - scriptRef = yield* decScriptRef(scriptRefBytes) - } + const scriptRef = scriptRefBytes !== undefined ? yield* decScriptRef(scriptRefBytes) : undefined return new BabbageTransactionOutput( { @@ -253,23 +232,16 @@ export const CDDLSchema = Schema.Union(ShelleyTransactionOutputCDDL, BabbageTran /** * CDDL schema for transaction outputs * - * ``` - * CDDL: transaction_output = shelley_transaction_output / babbage_transaction_output - * shelley_transaction_output = [address, amount : value, ? Bytes32] - * babbage_transaction_output = {0 : address, 1 : value, ? 2 : datum_option, ? 3 : script_ref} - * ``` - * * @since 2.0.0 - * @category schemas + * @category transformer */ export const FromCDDL = Schema.Union(FromShelleyTransactionOutputCDDLSchema, FromBabbageTransactionOutputCDDLSchema) /** * CBOR bytes transformation schema for TransactionOutput. - * Transforms between CBOR bytes and TransactionOutput. * * @since 2.0.0 - * @category schemas + * @category transformer */ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( @@ -283,10 +255,9 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI /** * CBOR hex transformation schema for TransactionOutput. - * Transforms between CBOR hex string and TransactionOutput. * * @since 2.0.0 - * @category schemas + * @category transformer */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( @@ -307,14 +278,26 @@ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTION export const equals = (a: TransactionOutput, b: TransactionOutput): boolean => { if (a._tag !== b._tag) return false + // helper for optional fields: both undefined => equal, one undefined => not equal, otherwise use provided comparator + const optionalEquals = (x: T | undefined, y: T | undefined, cmp: (u: T, v: T) => boolean): boolean => { + if (x === undefined && y === undefined) return true + if (x === undefined || y === undefined) return false + return cmp(x, y) + } + if (a._tag === "ShelleyTransactionOutput" && b._tag === "ShelleyTransactionOutput") { - return a.address === b.address && a.amount === b.amount && a.datumHash === b.datumHash + const addrEq = Address.equals(a.address, b.address) + const amountEq = Value.equals(a.amount, b.amount) + const datumEq = optionalEquals(a.datumHash, b.datumHash, DatumOption.equals) + return addrEq && amountEq && datumEq } if (a._tag === "BabbageTransactionOutput" && b._tag === "BabbageTransactionOutput") { - return ( - a.address === b.address && a.amount === b.amount && a.datumOption === b.datumOption && a.scriptRef === b.scriptRef - ) + const addrEq = Address.equals(a.address, b.address) + const amountEq = Value.equals(a.amount, b.amount) + const datumEq = optionalEquals(a.datumOption, b.datumOption, DatumOption.equals) + const scriptEq = optionalEquals(a.scriptRef, b.scriptRef, ScriptRef.equals) + return addrEq && amountEq && datumEq && scriptEq } return false @@ -326,11 +309,8 @@ export const equals = (a: TransactionOutput, b: TransactionOutput): boolean => { * @since 2.0.0 * @category constructors */ -export const makeShelley = ( - address: Address.Address, - amount: Value.Value, - datumHash?: DatumOption.DatumHash -): ShelleyTransactionOutput => new ShelleyTransactionOutput({ address, amount, datumHash }) +export const makeShelley = (...args: ConstructorParameters) => + new ShelleyTransactionOutput(...args) /** * Create a Babbage transaction output. @@ -338,16 +318,12 @@ export const makeShelley = ( * @since 2.0.0 * @category constructors */ -export const makeBabbage = ( - address: Address.Address, - amount: Value.Value, - datumOption?: DatumOption.DatumOption, - scriptRef?: ScriptRef.ScriptRef -): BabbageTransactionOutput => new BabbageTransactionOutput({ address, amount, datumOption, scriptRef }) +export const makeBabbage = (...args: ConstructorParameters) => + new BabbageTransactionOutput(...args) /** * @since 2.0.0 - * @category FastCheck + * @category arbitrary */ export const arbitrary = (): FastCheck.Arbitrary => FastCheck.oneof( @@ -367,46 +343,6 @@ export const arbitrary = (): FastCheck.Arbitrary => }).map((props) => new BabbageTransactionOutput(props)) ) -/** - * Either namespace containing schema decode and encode operations. - * - * @since 2.0.0 - * @category Either - */ -export namespace Either { - /** - * Parse a TransactionOutput from CBOR bytes using Either error handling. - * - * @since 2.0.0 - * @category parsing - */ - export const fromCBORBytes = Function.makeCBORDecodeEither(FromCDDL, TransactionOutputError) - - /** - * Parse a TransactionOutput from CBOR hex using Either error handling. - * - * @since 2.0.0 - * @category parsing - */ - export const fromCBORHex = Function.makeCBORDecodeHexEither(FromCDDL, TransactionOutputError) - - /** - * Convert a TransactionOutput to CBOR bytes using Either error handling. - * - * @since 2.0.0 - * @category encoding - */ - export const toCBORBytes = Function.makeCBOREncodeEither(FromCDDL, TransactionOutputError) - - /** - * Convert a TransactionOutput to CBOR hex using Either error handling. - * - * @since 2.0.0 - * @category encoding - */ - export const toCBORHex = Function.makeCBOREncodeHexEither(FromCDDL, TransactionOutputError) -} - /** * Convert TransactionOutput to CBOR bytes (unsafe). * @@ -450,3 +386,43 @@ export const fromCBORHex = Function.makeCBORDecodeHexSync( TransactionOutputError, "TransactionOutput.fromCBORHex" ) + +/** + * Either namespace containing schema decode and encode operations. + * + * @since 2.0.0 + * @category Either + */ +export namespace Either { + /** + * Parse a TransactionOutput from CBOR bytes using Either error handling. + * + * @since 2.0.0 + * @category parsing + */ + export const fromCBORBytes = Function.makeCBORDecodeEither(FromCDDL, TransactionOutputError) + + /** + * Parse a TransactionOutput from CBOR hex using Either error handling. + * + * @since 2.0.0 + * @category parsing + */ + export const fromCBORHex = Function.makeCBORDecodeHexEither(FromCDDL, TransactionOutputError) + + /** + * Convert a TransactionOutput to CBOR bytes using Either error handling. + * + * @since 2.0.0 + * @category encoding + */ + export const toCBORBytes = Function.makeCBOREncodeEither(FromCDDL, TransactionOutputError) + + /** + * Convert a TransactionOutput to CBOR hex using Either error handling. + * + * @since 2.0.0 + * @category encoding + */ + export const toCBORHex = Function.makeCBOREncodeHexEither(FromCDDL, TransactionOutputError) +} diff --git a/packages/evolution/src/Withdrawals.ts b/packages/evolution/src/Withdrawals.ts index c1137b44..7c179442 100644 --- a/packages/evolution/src/Withdrawals.ts +++ b/packages/evolution/src/Withdrawals.ts @@ -113,9 +113,17 @@ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTION export const equals = (self: Withdrawals, that: Withdrawals): boolean => { if (self.withdrawals.size !== that.withdrawals.size) return false + // Map keys are RewardAccount instances which may be different object + // identities after decoding; compare keys structurally using RewardAccount.equals for (const [account, coin] of self.withdrawals) { - const otherCoin = that.withdrawals.get(account) - if (!otherCoin || !Coin.equals(coin, otherCoin)) return false + let found = false + for (const [otherAccount, otherCoin] of that.withdrawals) { + if (RewardAccount.equals(account, otherAccount) && Coin.equals(coin, otherCoin)) { + found = true + break + } + } + if (!found) return false } return true diff --git a/packages/evolution/test/AuxiliaryData.CML.test.ts b/packages/evolution/test/AuxiliaryData.CML.test.ts index f04d1800..7234875d 100644 --- a/packages/evolution/test/AuxiliaryData.CML.test.ts +++ b/packages/evolution/test/AuxiliaryData.CML.test.ts @@ -1,4 +1,5 @@ import * as CML from "@dcspark/cardano-multiplatform-lib-nodejs" +import { FastCheck } from "effect" import { describe, expect, it } from "vitest" import * as AuxiliaryData from "../src/AuxiliaryData.js" @@ -97,4 +98,61 @@ describe("AuxiliaryData CML Compatibility", () => { expect(evolutionCbor).toBe(cmlCbor) }) + + it("property: Evolution SDK CBOR matches CML CBOR for any generated AuxiliaryData", () => { + FastCheck.assert( + FastCheck.property(AuxiliaryData.arbitrary, (evolutionAuxData) => { + // Evolution → CBOR hex + const evolutionCbor = AuxiliaryData.toCBORHex(evolutionAuxData) + + // CBOR hex → CML (ensures parity) + const cmlAux = CML.AuxiliaryData.from_cbor_hex(evolutionCbor) + const cmlCbor = cmlAux.to_cbor_hex() + + // Evolution and CML CBOR must match + expect(evolutionCbor).toBe(cmlCbor) + + const decoded = AuxiliaryData.fromCBORHex(cmlCbor) + expect(AuxiliaryData.equals(decoded, evolutionAuxData)).toBe(true) + }) + ) + }) + + it("property: ShelleyMAAuxiliaryData ", () => { + FastCheck.assert( + FastCheck.property(AuxiliaryData.shelleyMAArbitrary, (evolutionAuxData) => { + // Evolution → CBOR hex + const evolutionCbor = AuxiliaryData.toCBORHex(evolutionAuxData) + + // CBOR hex → CML (ensures parity) + const cmlAux = CML.ShelleyMAFormatAuxData.from_cbor_hex(evolutionCbor) + const cmlCbor = cmlAux.to_cbor_hex() + + // Evolution and CML CBOR must match + expect(evolutionCbor).toBe(cmlCbor) + + const decoded = AuxiliaryData.fromCBORHex(cmlCbor) + expect(AuxiliaryData.equals(decoded, evolutionAuxData)).toBe(true) + }) + ) + }) + + it("property: ShelleyAuxiliaryData", () => { + FastCheck.assert( + FastCheck.property(AuxiliaryData.shelleyArbitrary, (evolutionAuxData) => { + // Evolution → CBOR hex + const evolutionCbor = AuxiliaryData.toCBORHex(evolutionAuxData) + + // CBOR hex → CML (ensures parity) + const cmlAux = CML.AuxiliaryData.from_cbor_hex(evolutionCbor) + const cmlCbor = cmlAux.to_cbor_hex() + + // Evolution and CML CBOR must match + expect(evolutionCbor).toBe(cmlCbor) + + const decoded = AuxiliaryData.fromCBORHex(cmlCbor) + expect(AuxiliaryData.equals(decoded, evolutionAuxData)).toBe(true) + }) + ) + }) }) diff --git a/packages/evolution/test/MultiAsset.equals.test.ts b/packages/evolution/test/MultiAsset.equals.test.ts new file mode 100644 index 00000000..899fb98b --- /dev/null +++ b/packages/evolution/test/MultiAsset.equals.test.ts @@ -0,0 +1,16 @@ +import { FastCheck } from "effect" +import { describe, expect, it } from "vitest" + +import * as MultiAsset from "../src/MultiAsset.js" + +describe("MultiAsset property tests", () => { + it("round-trips via CBOR and preserves equality", () => { + FastCheck.assert( + FastCheck.property(MultiAsset.arbitrary, (ma) => { + const hex = MultiAsset.toCBORHex(ma) + const decoded = MultiAsset.fromCBORHex(hex) + expect(MultiAsset.equals(ma, decoded)).toBe(true) + }) + ) + }) +}) diff --git a/packages/evolution/test/TransactionBody.CML.test.ts b/packages/evolution/test/TransactionBody.CML.test.ts index 427d3275..969f708b 100644 --- a/packages/evolution/test/TransactionBody.CML.test.ts +++ b/packages/evolution/test/TransactionBody.CML.test.ts @@ -2,6 +2,7 @@ import * as CML from "@dcspark/cardano-multiplatform-lib-nodejs" import { FastCheck } from "effect" import { describe, expect, it } from "vitest" +// diagnoseTransactionBody is optional during lint/type-check; load only on failure import * as Coin from "../src/Coin.js" import * as NetworkId from "../src/NetworkId.js" import * as TransactionBody from "../src/TransactionBody.js" @@ -316,19 +317,16 @@ describe("TransactionBody CML Compatibility", () => { FastCheck.property(TransactionBody.arbitrary, (evolutionTxBody) => { // Step 1: Evolution → CBOR hex const evolutionCbor = TransactionBody.toCBORHex(evolutionTxBody) - // Step 2: CBOR hex → CML (validates our CBOR is CML-compatible) const cmlTxBody = CML.TransactionBody.from_cbor_hex(evolutionCbor) // Step 3: CML → CBOR hex const cmlCbor = cmlTxBody.to_cbor_hex() // Step 4: Verify identical CBOR encoding expect(evolutionCbor).toBe(cmlCbor) - - // Skip round-trip for now - focus on CBOR compatibility first - // const decodedEvolution = TransactionBody.fromCBORHex(cmlCbor) - // expect(decodedEvolution).toEqual(evolutionTxBody) - }), - { numRuns: 10, seed: 43 } // Smaller runs, different seed to avoid the failing case + // round trip + const decodedEvolution = TransactionBody.fromCBORHex(cmlCbor) + expect(TransactionBody.equals(decodedEvolution, evolutionTxBody)).toBe(true) + }) ) }) }) diff --git a/packages/evolution/test/TransactionOutput.CML.test.ts b/packages/evolution/test/TransactionOutput.CML.test.ts index 1107384b..819d4dea 100644 --- a/packages/evolution/test/TransactionOutput.CML.test.ts +++ b/packages/evolution/test/TransactionOutput.CML.test.ts @@ -12,8 +12,10 @@ describe("TransactionOutput CML Compatibility", () => { const cmlOut = CML.TransactionOutput.from_cbor_hex(evCbor) const cmlCbor = cmlOut.to_cbor_hex() expect(evCbor).toBe(cmlCbor) - }), - { numRuns: 10, seed: 123 } + + const evFromCml = TransactionOutput.fromCBORHex(evCbor) + expect(TransactionOutput.equals(evOut, evFromCml)).toBe(true) + }) ) }) })