1- import * as bech32 from "bech32 " ;
1+ import { bech32 } from "@scure/base " ;
22
3- export function toBech32 ( prefix : string , data : Uint8Array , limit ?: number ) : string {
4- const address = bech32 . encode ( prefix , bech32 . toWords ( data ) , limit ) ;
3+ export function toBech32 ( prefix : string , data : Uint8Array , limit ?: number ) : `${ string } 1${ string } ` {
4+ const address : `${ typeof prefix } 1${ string } ` = bech32 . encode ( prefix , bech32 . toWords ( data ) , limit ) ;
55 return address ;
66}
77
88export function fromBech32 (
99 address : string ,
1010 limit = Infinity ,
1111) : { readonly prefix : string ; readonly data : Uint8Array } {
12- const decodedAddress = bech32 . decode ( address , limit ) ;
12+ const decodedAddress = bech32 . decode ( address as `${ string } 1${ string } ` , limit ) ;
1313 return {
1414 prefix : decodedAddress . prefix ,
1515 data : new Uint8Array ( bech32 . fromWords ( decodedAddress . words ) ) ,
@@ -22,7 +22,7 @@ export function fromBech32(
2222 * The input is validated along the way, which makes this significantly safer than
2323 * using `address.toLowerCase()`.
2424 */
25- export function normalizeBech32 ( address : string ) : string {
26- const { prefix, data } = fromBech32 ( address ) ;
25+ export function normalizeBech32 ( address : string ) : `${ string } 1${ string } ` {
26+ const { prefix, data } = fromBech32 ( address . toLowerCase ( ) as `${ string } 1${ string } ` ) ;
2727 return toBech32 ( prefix , data ) ;
2828}
0 commit comments