@@ -14,6 +14,8 @@ import {
1414} from '@emurgo/cardano-serialization-lib-nodejs' ;
1515import { KeyPair } from './keyPair' ;
1616import { bech32 } from 'bech32' ;
17+ import base58 from 'bs58' ;
18+ import cbor from 'cbor' ;
1719
1820export const MIN_ADA_FOR_ONE_ASSET = '1500000' ;
1921export const VOTE_ALWAYS_ABSTAIN = 'always-abstain' ;
@@ -149,26 +151,43 @@ export class Utils implements BaseUtils {
149151 const POINTER_ADDR_LEN = 52 ;
150152 const VALIDATOR_ADDR_LEN = 56 ;
151153
152- // test if this is a bech32 address first
153- if ( new RegExp ( bech32PrefixList . join ( '|' ) ) . test ( address ) ) {
154+ //Check for Shelley-era (Bech32) addresses
155+ if ( new RegExp ( `^( ${ bech32PrefixList . join ( '|' ) } )` ) . test ( address ) ) {
154156 try {
155157 const decodedBech = bech32 . decode ( address , 108 ) ;
156158 const wordLength = decodedBech . words . length ;
157- if ( ! bech32PrefixList . includes ( decodedBech . prefix ) ) {
158- return false ;
159+ if (
160+ bech32PrefixList . includes ( decodedBech . prefix ) &&
161+ ( wordLength === BASE_ADDR_LEN ||
162+ wordLength === REWARD_AND_ENTERPRISE_ADDR_LEN ||
163+ wordLength === POINTER_ADDR_LEN )
164+ ) {
165+ return true ;
159166 }
160- return (
161- wordLength === BASE_ADDR_LEN ||
162- wordLength === REWARD_AND_ENTERPRISE_ADDR_LEN ||
163- wordLength === POINTER_ADDR_LEN
164- ) ;
165- } catch ( err ) {
166- return false ;
167+ } catch ( e ) {
168+ console . log ( `Address: ${ address } failed Bech32 test with error: ${ e } ` ) ;
167169 }
168- } else {
169- // maybe this is a validator address
170- return new RegExp ( `^(?!pool)[a-z0-9]\{${ VALIDATOR_ADDR_LEN } \}$` ) . test ( address ) ;
171170 }
171+
172+ //Check for Validator addresses
173+ if ( new RegExp ( `^(?!pool)[a-z0-9]{${ VALIDATOR_ADDR_LEN } }$` ) . test ( address ) ) {
174+ return true ;
175+ }
176+
177+ //Check for Byron-era (Base58 + CBOR)
178+ try {
179+ const decodedBase58 = base58 . decode ( address ) ;
180+
181+ const cborData = cbor . decodeFirstSync ( decodedBase58 ) ;
182+
183+ if ( Array . isArray ( cborData ) && cborData . length >= 3 ) {
184+ return true ;
185+ }
186+ } catch ( e ) {
187+ console . log ( `Address: ${ address } failed Base58 + CBOR test with error: ${ e } ` ) ;
188+ }
189+
190+ return false ;
172191 }
173192
174193 /** @inheritdoc */
0 commit comments