1
- import * as bech32 from "bech32 " ;
1
+ import { bech32 } from "@scure/base " ;
2
2
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 = bech32 . encode ( prefix , data , limit ) ;
5
5
return address ;
6
6
}
7
7
8
8
export function fromBech32 (
9
9
address : string ,
10
10
limit = Infinity ,
11
11
) : { readonly prefix : string ; readonly data : Uint8Array } {
12
- const decodedAddress = bech32 . decode ( address , limit ) ;
12
+ const decodedAddress = bech32 . decode ( address as `${ string } 1${ string } ` , limit ) ;
13
13
return {
14
14
prefix : decodedAddress . prefix ,
15
15
data : new Uint8Array ( bech32 . fromWords ( decodedAddress . words ) ) ,
@@ -22,7 +22,7 @@ export function fromBech32(
22
22
* The input is validated along the way, which makes this significantly safer than
23
23
* using `address.toLowerCase()`.
24
24
*/
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 } ` ) ;
27
27
return toBech32 ( prefix , data ) ;
28
28
}
0 commit comments