@@ -62,6 +62,7 @@ import 'package:blockchain_utils/bip/address/encoder.dart';
6262import 'package:blockchain_utils/bip/address/exception/exception.dart' ;
6363import 'package:blockchain_utils/bip/bip/bip32/bip32_key_data.dart' ;
6464import 'package:blockchain_utils/bip/bip/bip32/bip32_path.dart' ;
65+ import 'package:blockchain_utils/cbor/extention/extenton.dart' ;
6566import 'package:blockchain_utils/crypto/quick_crypto.dart' ;
6667import 'package:blockchain_utils/cbor/core/cbor.dart' ;
6768import 'package:blockchain_utils/cbor/types/bytes.dart' ;
@@ -144,17 +145,17 @@ class ADAByronAddrConst {
144145class _AdaByronAddrHdPath {
145146 static Bip32Path decrypt (List <int > hdPathEncBytes, List <int > hdPathKeyBytes) {
146147 final plainTextBytes = QuickCrypto .chaCha20Poly1305Decrypt (
147- key: hdPathKeyBytes,
148- nonce: ADAByronAddrConst .chacha20Poly1305Nonce,
149- assocData: ADAByronAddrConst .chacha20Poly1305AssocData,
150- cipherText: hdPathEncBytes,
151- );
148+ key: hdPathKeyBytes,
149+ nonce: ADAByronAddrConst .chacha20Poly1305Nonce,
150+ assocData: ADAByronAddrConst .chacha20Poly1305AssocData,
151+ cipherText: hdPathEncBytes);
152152 final decode = CborObject .fromCbor (plainTextBytes);
153153 if (decode is ! CborListValue ) {
154154 throw const AddressConverterException ("invalid bip32 path" );
155155 }
156+
156157 final paths = decode.value
157- .map ((e) => Bip32KeyIndex (e is String ? int .parse (e) : e as int ))
158+ .map ((e) => Bip32KeyIndex (IntUtils .parse (e.value) ))
158159 .toList ();
159160 return Bip32Path (elems: paths, isAbsolute: true );
160161 }
@@ -164,7 +165,9 @@ class _AdaByronAddrHdPath {
164165 key: hdPathKeyBytes,
165166 nonce: ADAByronAddrConst .chacha20Poly1305Nonce,
166167 assocData: ADAByronAddrConst .chacha20Poly1305AssocData,
167- plainText: CborListValue .dynamicLength (hdPath.toList ()).encode (),
168+ plainText: CborListValue .inDefinite (
169+ hdPath.toList ().map ((e) => CborIntValue (e)).toList ())
170+ .encode (),
168171 );
169172 return result;
170173 }
@@ -199,16 +202,18 @@ class ADAByronAddrAttrs {
199202 hdPathEncBytes: hdPath, networkMagic: networkMagic);
200203 }
201204
202- Map < int , List < int > > toJson () {
203- final attrs = < int , List < int > > {};
205+ CborMapValue < CborIntValue , CborBytesValue > toJson () {
206+ final attrs = < CborIntValue , CborBytesValue > {};
204207 if (hdPathEncBytes != null ) {
205- attrs[1 ] = CborBytesValue (hdPathEncBytes! ).encode ();
208+ attrs[CborIntValue (1 )] =
209+ CborBytesValue (CborBytesValue (hdPathEncBytes! ).encode ());
206210 }
207211 if (networkMagic != null &&
208212 networkMagic != ADANetwork .mainnet.protocolMagic) {
209- attrs[2 ] = CborIntValue (networkMagic! ).encode ();
213+ attrs[CborIntValue (2 )] =
214+ CborBytesValue (CborIntValue (networkMagic! ).encode ());
210215 }
211- return attrs;
216+ return CborMapValue . definite ( attrs) ;
212217 }
213218}
214219
@@ -231,10 +236,12 @@ class _AdaByronAddrRoot {
231236 }
232237
233238 List <int > serialize () {
234- return CborListValue . fixedLength ([
239+ return CborListValue < CborObject >. definite ([
235240 CborIntValue (type.value),
236- CborListValue .fixedLength (
237- [spendingData.type.value, spendingData.keyBytes]),
241+ CborListValue <CborObject >.definite ([
242+ CborIntValue (spendingData.type.value),
243+ CborBytesValue (spendingData.keyBytes)
244+ ]),
238245 attrs.toJson (),
239246 ]).encode ();
240247 }
@@ -265,13 +272,13 @@ class ADAByronAddrPayload {
265272
266273 return ADAByronAddrPayload (
267274 rootHashBytes: cborBytes.value,
268- attrs: ADAByronAddrAttrs .fromCbor (addrPayload.value[1 ]),
269- type: ADAByronAddrTypes .fromCbor (addrPayload.value[2 ]),
275+ attrs: ADAByronAddrAttrs .fromCbor (addrPayload.value[1 ]. cast () ),
276+ type: ADAByronAddrTypes .fromCbor (addrPayload.value[2 ]. cast () ),
270277 );
271278 }
272279
273280 List <int > serialize () {
274- return CborListValue . fixedLength ([
281+ return CborListValue < CborObject >. definite ([
275282 CborBytesValue (rootHashBytes),
276283 attrs.toJson (),
277284 CborIntValue (type.value)
@@ -327,8 +334,9 @@ class ADAByronAddr {
327334
328335 CborObject toCbor () {
329336 final payloadBytes = payload.serialize ();
330- return CborListValue .fixedLength ([
331- CborTagValue (payloadBytes, [ADAByronAddrConst .payloadTag]),
337+ return CborListValue <CborObject >.definite ([
338+ CborTagValue (
339+ CborBytesValue (payloadBytes), [ADAByronAddrConst .payloadTag]),
332340 CborIntValue (Crc32 .quickIntDigest (payloadBytes)),
333341 ]);
334342 }
0 commit comments