@@ -14,7 +14,7 @@ function getDefaultChainCodes(): number[] {
1414 ) ;
1515}
1616
17- type AddressProperties = {
17+ type FixedScriptAddressProperties = {
1818 chain : utxolib . bitgo . ChainCode ;
1919 index : number ;
2020 type : utxolib . bitgo . outputScripts . ScriptType ;
@@ -30,7 +30,7 @@ type AddressProperties = {
3030 address : string ;
3131} ;
3232
33- const placeholders = {
33+ const fixedScriptPlaceholders = {
3434 '%c' : 'chain' ,
3535 '%i' : 'index' ,
3636 '%p' : 'userPath' ,
@@ -47,18 +47,22 @@ const placeholders = {
4747 '%a' : 'address' ,
4848} as const ;
4949
50- export function getAddressPlaceholderDescription ( ) : string {
51- return Object . entries ( placeholders )
50+ export function getAsPlaceholderDescription ( v : Record < string , string > ) : string {
51+ return Object . entries ( v )
5252 . map ( ( [ placeholder , prop ] ) => `${ placeholder } -> ${ prop } ` )
5353 . join ( '\n' ) ;
5454}
5555
56+ export function getFixedScriptAddressPlaceholderDescription ( ) : string {
57+ return getAsPlaceholderDescription ( fixedScriptPlaceholders ) ;
58+ }
59+
5660function getAddressProperties (
5761 keys : utxolib . bitgo . RootWalletKeys ,
5862 chain : utxolib . bitgo . ChainCode ,
5963 index : number ,
6064 network : utxolib . Network
61- ) : AddressProperties {
65+ ) : FixedScriptAddressProperties {
6266 const [ userPath , backupPath , bitgoPath ] = keys . triple . map ( ( k ) => keys . getDerivationPath ( k , chain , index ) ) ;
6367 const scripts = utxolib . bitgo . getWalletOutputScripts ( keys , chain , index ) ;
6468 const [ userKey , backupKey , bitgoKey ] = keys . triple . map ( ( k ) => k . derivePath ( userPath ) . publicKey . toString ( 'hex' ) ) ;
@@ -80,23 +84,31 @@ function getAddressProperties(
8084 } ;
8185}
8286
83- export function formatAddressTree ( props : AddressProperties ) : string {
87+ export function formatAddressTree ( props : FixedScriptAddressProperties ) : string {
8488 const parser = new Parser ( ) ;
8589 return formatTree ( parseUnknown ( parser , 'address' , props ) ) ;
8690}
8791
88- export function formatAddressWithFormatString ( props : AddressProperties , format : string ) : string {
92+ export function formatAddressWithFormatString (
93+ props : Record < string , unknown > ,
94+ placeholders : Record < string , string > ,
95+ format : string
96+ ) : string {
8997 // replace all patterns with a % prefix from format string with the corresponding property
9098 // e.g. %p0 -> userPath, %k1 -> backupKey, etc.
9199 return format . replace ( / % [ a - z 0 - 9 ] + / gi, ( match ) => {
92100 if ( match in placeholders ) {
93- const prop = placeholders [ match as keyof typeof placeholders ] ;
101+ const prop = placeholders [ match ] ;
94102 return String ( props [ prop ] ) ;
95103 }
96104 return match ;
97105 } ) ;
98106}
99107
108+ export function formatFixedScriptAddress ( props : FixedScriptAddressProperties , format : string ) : string {
109+ return formatAddressWithFormatString ( props , fixedScriptPlaceholders , format ) ;
110+ }
111+
100112export function getRange ( start : number , end : number ) : number [ ] {
101113 return Array . from ( { length : end - start + 1 } , ( _ , i ) => start + i ) ;
102114}
@@ -111,14 +123,14 @@ export function parseIndexRange(ranges: string[]): number[] {
111123 } ) ;
112124}
113125
114- export function * generateAddress (
126+ export function * generateFixedScriptAddress (
115127 argv : KeyOptions & {
116128 network ?: utxolib . Network ;
117129 chain ?: number [ ] ;
118130 format : string ;
119131 index : number [ ] ;
120132 }
121- ) : Generator < AddressProperties > {
133+ ) : Generator < FixedScriptAddressProperties > {
122134 const rootXpubs = getRootWalletKeys ( argv ) ;
123135 const chains = argv . chain ?? getDefaultChainCodes ( ) ;
124136 for ( const i of argv . index ) {
0 commit comments