@@ -10,13 +10,15 @@ import ECPairFactory, { ECPairInterface } from "ecpair"
1010import {
1111 Account ,
1212 AddressFormats ,
13- addressNameToType , DerivationIndex ,
13+ addressNameToType ,
14+ DerivationIndex ,
1415 getAccountDataFromHdNode ,
1516 getAddressesFromPublicKey ,
1617 getAllAccountsFromHdNode ,
1718 getNetwork ,
1819 mintFromCollection ,
19- publishCollection , SigningMessageOptions ,
20+ publishCollection ,
21+ SigningMessageOptions ,
2022 tweakSigner
2123} from ".."
2224import { Network } from "../config/types"
@@ -37,7 +39,16 @@ export class Ordit {
3739 selectedAddressType : AddressFormats | undefined
3840 selectedAddress : string | undefined
3941
40- constructor ( { wif, seed, privateKey, bip39, network = "testnet" , type = "legacy" , account = 0 , addressIndex = 0 } : WalletOptions ) {
42+ constructor ( {
43+ wif,
44+ seed,
45+ privateKey,
46+ bip39,
47+ network = "testnet" ,
48+ type = "legacy" ,
49+ account = 0 ,
50+ addressIndex = 0
51+ } : WalletOptions ) {
4152 this . #network = network
4253 const networkObj = getNetwork ( network )
4354 const format = addressNameToType [ type ]
@@ -102,8 +113,12 @@ export class Ordit {
102113 if ( ! this . #initialized || ! this . allAddresses . length ) {
103114 throw new OrditSDKError ( "Wallet not fully initialized." )
104115 }
105- return this . allAddresses . find ( ( address ) => address . format === type && address . derivationPath . account === derivationIndex . accountIndex
106- && address . derivationPath . addressIndex === derivationIndex . addressIndex ) ;
116+ return this . allAddresses . find (
117+ ( address ) =>
118+ address . format === type &&
119+ address . derivationPath . account === derivationIndex . accountIndex &&
120+ address . derivationPath . addressIndex === derivationIndex . addressIndex
121+ )
107122 }
108123
109124 getAllAddresses ( ) {
@@ -114,17 +129,20 @@ export class Ordit {
114129 return this . allAddresses
115130 }
116131
117- setDefaultAddress ( type : AddressFormats , { accountIndex = 0 , addressIndex = 0 } : DerivationIndex ) {
132+ setDefaultAddress (
133+ type : AddressFormats ,
134+ { accountIndex, addressIndex } : DerivationIndex = { accountIndex : 0 , addressIndex : 0 }
135+ ) {
118136 if ( this . selectedAddressType === type ) return
119- let addressToSelect : Account ;
137+ let addressToSelect : Account
120138
121139 const account = this . getAddressByType ( type , { accountIndex, addressIndex } ) as Account
122140 if ( ! account ) {
123- addressToSelect = this . generateAddress ( type , accountIndex , addressIndex ) ;
141+ addressToSelect = this . generateAddress ( type , accountIndex , addressIndex )
124142 // Push to current list of addresses
125- this . allAddresses . push ( addressToSelect ) ;
143+ this . allAddresses . push ( addressToSelect )
126144 } else {
127- addressToSelect = account ;
145+ addressToSelect = account
128146 }
129147
130148 if ( ! addressToSelect )
@@ -237,9 +255,12 @@ export class Ordit {
237255
238256 signMessage ( message : string , type ?: AddressFormats , opts ?: SigningMessageOptions ) {
239257 const addressType = type || this . selectedAddressType
240- const accountIndexToSign : number = opts ?. accountIndex === undefined ? 0 : opts ?. accountIndex ;
241- const addressIndexToSign : number = opts ?. addressIndex === undefined ? 0 : opts ?. addressIndex ;
242- const node = this . getAddressByType ( addressType ! , { accountIndex : accountIndexToSign , addressIndex : addressIndexToSign } ) as Account
258+ const accountIndexToSign : number = opts ?. accountIndex === undefined ? 0 : opts ?. accountIndex
259+ const addressIndexToSign : number = opts ?. addressIndex === undefined ? 0 : opts ?. addressIndex
260+ const node = this . getAddressByType ( addressType ! , {
261+ accountIndex : accountIndexToSign ,
262+ addressIndex : addressIndexToSign
263+ } ) as Account
243264 const signature = AddressUtils . isP2PKH ( node . address ! )
244265 ? sign ( message , node . child . privateKey ! )
245266 : Signer . sign ( node . child . toWIF ( ) , node . address ! , message , getNetwork ( this . #network) )
@@ -270,8 +291,8 @@ export type WalletOptions = {
270291 bip39 ?: string
271292 network ?: Network
272293 type ?: AddressFormats
273- account ?: number ;
274- addressIndex ?: number ;
294+ account ?: number
295+ addressIndex ?: number
275296}
276297
277298export type Address = ReturnType < typeof getAddressesFromPublicKey > [ 0 ]
0 commit comments