@@ -27,7 +27,7 @@ export class AuxiliaryDataError extends Data.TaggedError("AuxiliaryDataError")<{
2727 * ? 0 => metadata ; transaction_metadata
2828 * ? 1 => [* native_script] ; native_scripts
2929 * ? 2 => [* plutus_v1_script] ; plutus_v1_scripts
30- * ? 3 => [* plutus_v2_script] ; plutus_v2_scripts
30+ * ? 3 => [* plutus_v2_script] ; plutus_v2_scripts
3131 * ? 4 => [* plutus_v3_script] ; plutus_v3_scripts
3232 * }
3333 *
@@ -45,161 +45,85 @@ export class AuxiliaryData extends Schema.Class<AuxiliaryData>("AuxiliaryData")(
4545} ) { }
4646
4747/**
48- * CBOR Schema representing auxiliary data as a Conway-tagged map.
49- * Conway era wraps auxiliary data in CBOR tag 259 (0x103).
48+ * Tagged CDDL schema for AuxiliaryData (#6.259 wrapping the struct).
5049 *
5150 * @since 2.0.0
5251 * @category schemas
5352 */
54- export const CDDLSchema = Schema . MapFromSelf ( {
55- key : CBOR . Integer ,
56- value : Schema . Union (
57- Metadata . CDDLSchema ,
58- Schema . Array ( NativeScripts . CDDLSchema ) ,
59- Schema . Array ( PlutusV1 . CDDLSchema ) ,
60- Schema . Array ( PlutusV2 . CDDLSchema ) ,
61- Schema . Array ( PlutusV3 . CDDLSchema )
62- )
63- } )
64-
65- /**
66- * Transform schema between AuxiliaryData class and Conway-tagged CBOR.
67- * Uses CBOR tag 259 to wrap auxiliary data for Conway era compatibility.
68- *
69- * @since 2.0.0
70- * @category schemas
71- */
72- export const FromConwayTagged = Schema . transformOrFail (
73- Schema . instanceOf ( CBOR . Tag ) ,
74- Schema . typeSchema ( AuxiliaryData ) ,
75- {
76- strict : true ,
77- encode : ( auxData : AuxiliaryData ) =>
78- Eff . gen ( function * ( ) {
79- // First encode to CDDL map
80- const cddlMap = yield * ParseResult . encode ( FromCDDL ) ( auxData )
81- // Then wrap in Conway tag (259)
82- return new CBOR . Tag ( { tag : 259 , value : cddlMap } )
83- } ) ,
84- decode : ( conwayTag : CBOR . Tag ) =>
85- Eff . gen ( function * ( ) {
86- // Extract the map from Conway tag and decode
87- const cddlMap = conwayTag . value as ReadonlyMap < bigint , any >
88- return yield * ParseResult . decode ( FromCDDL ) ( cddlMap )
89- } )
90- }
91- ) . annotations ( {
92- identifier : "AuxiliaryData.FromConwayTagged" ,
93- title : "AuxiliaryData from Conway tagged CBOR" ,
94- description : "Transforms Conway-tagged CBOR to AuxiliaryData"
95- } )
53+ export const CDDLSchema = CBOR . tag (
54+ 259 ,
55+ Schema . Struct ( {
56+ 0 : Schema . optional ( Metadata . CDDLSchema ) ,
57+ 1 : Schema . optional ( Schema . Array ( NativeScripts . CDDLSchema ) ) ,
58+ 2 : Schema . optional ( Schema . Array ( PlutusV1 . CDDLSchema ) ) ,
59+ 3 : Schema . optional ( Schema . Array ( PlutusV2 . CDDLSchema ) ) ,
60+ 4 : Schema . optional ( Schema . Array ( PlutusV3 . CDDLSchema ) )
61+ } )
62+ )
9663
9764/**
98- * Transform schema between CDDL map representation and AuxiliaryData class.
99- * Handles Conway-era map format with CBOR tag 259 wrapping.
65+ * Transform between tagged CDDL (tag 259) and AuxiliaryData class.
10066 *
10167 * @since 2.0.0
10268 * @category schemas
10369 */
10470export const FromCDDL = Schema . transformOrFail ( CDDLSchema , Schema . typeSchema ( AuxiliaryData ) , {
10571 strict : true ,
106- encode : ( toA : AuxiliaryData ) =>
72+ encode : ( toA ) =>
10773 Eff . gen ( function * ( ) {
108- const result = new Map < bigint , any > ( )
109-
110- // Map class properties to CDDL map keys
111- if ( toA . metadata !== undefined ) {
112- const encodedMetadata = yield * ParseResult . encode ( Metadata . FromCDDL ) ( toA . metadata )
113- result . set ( 0n , encodedMetadata )
114- }
115-
116- if ( toA . nativeScripts !== undefined ) {
117- const encodedNativeScripts = yield * Eff . all (
118- toA . nativeScripts . map ( ( s ) => ParseResult . encode ( NativeScripts . FromCDDL ) ( s ) )
119- )
120- result . set ( 1n , encodedNativeScripts )
121- }
122-
123- if ( toA . plutusV1Scripts !== undefined ) {
124- const encodedV1Scripts = yield * Eff . all (
125- toA . plutusV1Scripts . map ( ( s ) => ParseResult . encode ( PlutusV1 . FromCDDL ) ( s ) )
126- )
127- result . set ( 2n , encodedV1Scripts )
128- }
129-
130- if ( toA . plutusV2Scripts !== undefined ) {
131- const encodedV2Scripts = yield * Eff . all (
132- toA . plutusV2Scripts . map ( ( s ) => ParseResult . encode ( PlutusV2 . FromCDDL ) ( s ) )
133- )
134- result . set ( 3n , encodedV2Scripts )
135- }
136-
137- if ( toA . plutusV3Scripts !== undefined ) {
138- const encodedV3Scripts = yield * Eff . all (
139- toA . plutusV3Scripts . map ( ( s ) => ParseResult . encode ( PlutusV3 . FromCDDL ) ( s ) )
140- )
141- result . set ( 4n , encodedV3Scripts )
142- }
143-
144- return result
74+ const struct : Record < number , any > = { }
75+ if ( toA . metadata !== undefined ) struct [ 0 ] = yield * ParseResult . encode ( Metadata . FromCDDL ) ( toA . metadata )
76+ if ( toA . nativeScripts !== undefined )
77+ struct [ 1 ] = yield * Eff . all ( toA . nativeScripts . map ( ( s ) => ParseResult . encode ( NativeScripts . FromCDDL ) ( s ) ) )
78+ if ( toA . plutusV1Scripts !== undefined )
79+ struct [ 2 ] = yield * Eff . all ( toA . plutusV1Scripts . map ( ( s ) => ParseResult . encode ( PlutusV1 . FromCDDL ) ( s ) ) )
80+ if ( toA . plutusV2Scripts !== undefined )
81+ struct [ 3 ] = yield * Eff . all ( toA . plutusV2Scripts . map ( ( s ) => ParseResult . encode ( PlutusV2 . FromCDDL ) ( s ) ) )
82+ if ( toA . plutusV3Scripts !== undefined )
83+ struct [ 4 ] = yield * Eff . all ( toA . plutusV3Scripts . map ( ( s ) => ParseResult . encode ( PlutusV3 . FromCDDL ) ( s ) ) )
84+ return { value : struct , tag : 259 as const , _tag : "Tag" as const }
14585 } ) ,
146- decode : ( fromA ) =>
86+ decode : ( tagged ) =>
14787 Eff . gen ( function * ( ) {
148- // Extract values from CDDL map and convert to class properties
149- const metadataValue = fromA . get ( 0n ) as ReadonlyMap < bigint , any > | undefined
150- const metadata = metadataValue ? yield * ParseResult . decode ( Metadata . FromCDDL ) ( metadataValue ) : undefined
151-
152- const nativeScriptsArray = fromA . get ( 1n ) as ReadonlyArray < any > | undefined
153- const nativeScripts = nativeScriptsArray
154- ? yield * Eff . all ( nativeScriptsArray . map ( ( s ) => ParseResult . decode ( NativeScripts . FromCDDL ) ( s ) ) )
88+ const struct = tagged . value
89+ const metadata = struct [ 0 ] ? yield * ParseResult . decode ( Metadata . FromCDDL ) ( struct [ 0 ] ) : undefined
90+ const nativeScripts = struct [ 1 ]
91+ ? yield * Eff . all ( struct [ 1 ] . map ( ( s ) => ParseResult . decode ( NativeScripts . FromCDDL ) ( s ) ) )
15592 : undefined
156-
157- const plutusV1Array = fromA . get ( 2n ) as ReadonlyArray < any > | undefined
158- const plutusV1Scripts = plutusV1Array
159- ? yield * Eff . all ( plutusV1Array . map ( ( s ) => ParseResult . decode ( PlutusV1 . FromCDDL ) ( s ) ) )
93+ const plutusV1Scripts = struct [ 2 ]
94+ ? yield * Eff . all ( struct [ 2 ] . map ( ( s ) => ParseResult . decode ( PlutusV1 . FromCDDL ) ( s ) ) )
16095 : undefined
161-
162- const plutusV2Array = fromA . get ( 3n ) as ReadonlyArray < any > | undefined
163- const plutusV2Scripts = plutusV2Array
164- ? yield * Eff . all ( plutusV2Array . map ( ( s ) => ParseResult . decode ( PlutusV2 . FromCDDL ) ( s ) ) )
96+ const plutusV2Scripts = struct [ 3 ]
97+ ? yield * Eff . all ( struct [ 3 ] . map ( ( s ) => ParseResult . decode ( PlutusV2 . FromCDDL ) ( s ) ) )
16598 : undefined
166-
167- const plutusV3Array = fromA . get ( 4n ) as ReadonlyArray < any > | undefined
168- const plutusV3Scripts = plutusV3Array
169- ? yield * Eff . all ( plutusV3Array . map ( ( s ) => ParseResult . decode ( PlutusV3 . FromCDDL ) ( s ) ) )
99+ const plutusV3Scripts = struct [ 4 ]
100+ ? yield * Eff . all ( struct [ 4 ] . map ( ( s ) => ParseResult . decode ( PlutusV3 . FromCDDL ) ( s ) ) )
170101 : undefined
171-
172- return new AuxiliaryData ( {
173- metadata,
174- nativeScripts,
175- plutusV1Scripts,
176- plutusV2Scripts,
177- plutusV3Scripts,
178- } )
102+ return new AuxiliaryData ( { metadata, nativeScripts, plutusV1Scripts, plutusV2Scripts, plutusV3Scripts } )
179103 } )
180104} ) . annotations ( {
181105 identifier : "AuxiliaryData.FromCDDL" ,
182- title : "AuxiliaryData from CDDL" ,
183- description : "Transforms CDDL map representation to AuxiliaryData"
106+ title : "AuxiliaryData from tagged CDDL" ,
107+ description : "Transforms CBOR tag 259 CDDL structure to AuxiliaryData"
184108} )
185109
186110/**
187111 * CBOR bytes transformation schema for AuxiliaryData.
188- * Uses Conway tagged format for CML compatibility .
112+ * Transforms between CBOR bytes and AuxiliaryData using CDDL format .
189113 *
190114 * @since 2.0.0
191115 * @category schemas
192116 */
193117export const FromCBORBytes = ( options : CBOR . CodecOptions = CBOR . CML_DEFAULT_OPTIONS ) =>
194- Schema . compose ( CBOR . FromBytes ( options ) , FromConwayTagged ) . annotations ( {
118+ Schema . compose ( CBOR . FromBytes ( options ) , FromCDDL ) . annotations ( {
195119 identifier : "AuxiliaryData.FromCBORBytes" ,
196120 title : "AuxiliaryData from CBOR bytes" ,
197- description : "Decode AuxiliaryData from Conway-tagged CBOR-encoded bytes"
121+ description : "Decode AuxiliaryData from CBOR-encoded bytes (tag 259) "
198122 } )
199123
200124/**
201125 * CBOR hex transformation schema for AuxiliaryData.
202- * Uses Conway tagged format for CML compatibility .
126+ * Transforms between CBOR hex string and AuxiliaryData using CDDL format .
203127 *
204128 * @since 2.0.0
205129 * @category schemas
@@ -208,7 +132,7 @@ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTION
208132 Schema . compose ( Bytes . FromHex , FromCBORBytes ( options ) ) . annotations ( {
209133 identifier : "AuxiliaryData.FromCBORHex" ,
210134 title : "AuxiliaryData from CBOR hex" ,
211- description : "Decode AuxiliaryData from Conway-tagged CBOR-encoded hex string "
135+ description : "Decode AuxiliaryData from CBOR-encoded hex (tag 259) "
212136 } )
213137
214138/**
@@ -225,13 +149,14 @@ export const make = AuxiliaryData.make
225149 * @since 2.0.0
226150 * @category constructors
227151 */
228- export const empty = ( ) : AuxiliaryData => new AuxiliaryData ( {
229- metadata : undefined ,
230- nativeScripts : undefined ,
231- plutusV1Scripts : undefined ,
232- plutusV2Scripts : undefined ,
233- plutusV3Scripts : undefined
234- } )
152+ export const empty = ( ) : AuxiliaryData =>
153+ new AuxiliaryData ( {
154+ metadata : undefined ,
155+ nativeScripts : undefined ,
156+ plutusV1Scripts : undefined ,
157+ plutusV2Scripts : undefined ,
158+ plutusV3Scripts : undefined
159+ } )
235160
236161/**
237162 * Check if two AuxiliaryData instances are equal (deep comparison).
@@ -243,10 +168,10 @@ export const equals = (a: AuxiliaryData, b: AuxiliaryData): boolean => {
243168 if ( a . metadata && b . metadata ) {
244169 if ( ! Metadata . equals ( a . metadata , b . metadata ) ) return false
245170 } else if ( a . metadata || b . metadata ) return false
246-
171+
247172 const cmpArray = ( x ?: ReadonlyArray < any > , y ?: ReadonlyArray < any > ) =>
248173 x && y ? x . length === y . length && x . every ( ( v , i ) => v === y [ i ] ) : x === y
249-
174+
250175 if ( ! cmpArray ( a . nativeScripts , b . nativeScripts ) ) return false
251176 if ( ! cmpArray ( a . plutusV1Scripts , b . plutusV1Scripts ) ) return false
252177 if ( ! cmpArray ( a . plutusV2Scripts , b . plutusV2Scripts ) ) return false
0 commit comments