1- import { OpKind , ParamsWithKind , TezosToolkit } from '@taquito/taquito' ;
1+ import { OpKind , ParamsWithKind , TezosToolkit } from '@taquito/taquito'
22import { InMemorySigner } from '@taquito/signer'
33
44import { Wallet } from 'ethers/'
5- import { PvmKind , ScriptedContracts } from '@taquito/rpc' ;
5+ import { PvmKind , ScriptedContracts } from '@taquito/rpc'
66import { PartialTezosOperation , TezosOperationType } from '@airgap/beacon-types'
7- import { TEZOS_CHAINS } from '@/data/TezosData' ;
7+ import { TEZOS_CHAINS } from '@/data/TezosData'
88
99/**
1010 * Constants
@@ -58,27 +58,35 @@ export default class TezosLib {
5858 curve : curve ?? DEFAULT_CURVE
5959 }
6060
61- const signer = InMemorySigner . fromMnemonic ( params ) ;
61+ const signer = InMemorySigner . fromMnemonic ( params )
6262
6363 // we have wallets for multiple networks
6464 // later we will determine the chain from the request
65- const toolkits : Record < string , TezosToolkit > = { } ;
65+ const toolkits : Record < string , TezosToolkit > = { }
6666 for ( const chainKey in TEZOS_CHAINS ) {
67- const chain = TEZOS_CHAINS [ chainKey ] ;
68- const toolkit = new TezosToolkit ( chain . rpc ) ;
69-
70- toolkit . setSignerProvider ( signer ) ;
71- toolkits [ chainKey ] = toolkit ;
67+ const chain = TEZOS_CHAINS [ chainKey ]
68+ const toolkit = new TezosToolkit ( chain . rpc )
69+
70+ toolkit . setSignerProvider ( signer )
71+ toolkits [ chainKey ] = toolkit
7272 }
73- const toolkit = toolkits [ 'tezos:mainnet' ] ;
74- const secretKey = await toolkit . signer . secretKey ( ) ;
75- const publicKey = await toolkit . signer . publicKey ( ) ;
76- const address = await toolkit . signer . publicKeyHash ( ) ;
73+ const toolkit = toolkits [ 'tezos:mainnet' ]
74+ const secretKey = await toolkit . signer . secretKey ( )
75+ const publicKey = await toolkit . signer . publicKey ( )
76+ const address = await toolkit . signer . publicKeyHash ( )
7777
7878 if ( ! secretKey ) {
79- throw new Error ( " Failed to generate secret key" ) ;
79+ throw new Error ( ' Failed to generate secret key' )
8080 }
81- return new TezosLib ( toolkits , params . mnemonic , signer , secretKey , publicKey , address , params . curve )
81+ return new TezosLib (
82+ toolkits ,
83+ params . mnemonic ,
84+ signer ,
85+ secretKey ,
86+ publicKey ,
87+ address ,
88+ params . curve
89+ )
8290 }
8391
8492 public getMnemonic ( ) {
@@ -103,23 +111,23 @@ export default class TezosLib {
103111 return {
104112 kind : OpKind . ACTIVATION ,
105113 pkh : op . pkh ,
106- secret : op . secret ,
107- } ;
114+ secret : op . secret
115+ }
108116 case TezosOperationType . DELEGATION :
109117 return {
110118 kind : OpKind . DELEGATION ,
111- source : op . source ?? " source not provided" ,
119+ source : op . source ?? ' source not provided' ,
112120 delegate : op . delegate ,
113121 fee : op . fee ? Number ( op . fee ) : undefined ,
114122 gasLimit : op . gas_limit ? Number ( op . gas_limit ) : undefined ,
115- storageLimit : op . storage_limit ? Number ( op . storage_limit ) : undefined ,
116- } ;
123+ storageLimit : op . storage_limit ? Number ( op . storage_limit ) : undefined
124+ }
117125 case TezosOperationType . FAILING_NOOP :
118126 return {
119127 kind : OpKind . FAILING_NOOP ,
120128 arbitrary : op . arbitrary ,
121- basedOnBlock : 'head' ,
122- } ;
129+ basedOnBlock : 'head'
130+ }
123131 case TezosOperationType . INCREASE_PAID_STORAGE :
124132 return {
125133 kind : OpKind . INCREASE_PAID_STORAGE ,
@@ -128,10 +136,10 @@ export default class TezosLib {
128136 gasLimit : op . gas_limit ? Number ( op . gas_limit ) : undefined ,
129137 storageLimit : op . storage_limit ? Number ( op . storage_limit ) : undefined ,
130138 amount : Number ( op . amount ) ,
131- destination : op . destination ,
132- } ;
139+ destination : op . destination
140+ }
133141 case TezosOperationType . ORIGINATION :
134- let script : ScriptedContracts = op . script as unknown as ScriptedContracts ;
142+ let script : ScriptedContracts = op . script as unknown as ScriptedContracts
135143 return {
136144 kind : OpKind . ORIGINATION ,
137145 balance : Number ( op . balance ) ,
@@ -140,29 +148,29 @@ export default class TezosLib {
140148 delegate : op . delegate ,
141149 fee : op . fee ? Number ( op . fee ) : undefined ,
142150 gasLimit : op . gas_limit ? Number ( op . gas_limit ) : undefined ,
143- storageLimit : op . storage_limit ? Number ( op . storage_limit ) : undefined ,
144- } ;
151+ storageLimit : op . storage_limit ? Number ( op . storage_limit ) : undefined
152+ }
145153 case TezosOperationType . REGISTER_GLOBAL_CONSTANT :
146154 return {
147155 kind : OpKind . REGISTER_GLOBAL_CONSTANT ,
148156 source : op . source ,
149157 fee : op . fee ? Number ( op . fee ) : undefined ,
150158 gasLimit : op . gas_limit ? Number ( op . gas_limit ) : undefined ,
151159 storageLimit : op . storage_limit ? Number ( op . storage_limit ) : undefined ,
152- value : op . value ,
153- } ;
160+ value : op . value
161+ }
154162 case TezosOperationType . SMART_ROLLUP_ADD_MESSAGES :
155163 return {
156164 kind : OpKind . SMART_ROLLUP_ADD_MESSAGES ,
157165 source : op . source ,
158166 fee : op . fee ? Number ( op . fee ) : undefined ,
159167 gasLimit : op . gas_limit ? Number ( op . gas_limit ) : undefined ,
160168 storageLimit : op . storage_limit ? Number ( op . storage_limit ) : undefined ,
161- message : op . message ,
162- } ;
169+ message : op . message
170+ }
163171 case TezosOperationType . SMART_ROLLUP_ORIGINATE :
164172 if ( ! Object . values ( PvmKind ) . includes ( op . pvm_kind ) ) {
165- throw new Error ( `Invalid PvmKind: ${ op . pvm_kind } ` ) ;
173+ throw new Error ( `Invalid PvmKind: ${ op . pvm_kind } ` )
166174 }
167175 return {
168176 kind : OpKind . SMART_ROLLUP_ORIGINATE ,
@@ -172,8 +180,8 @@ export default class TezosLib {
172180 storageLimit : op . storage_limit ? Number ( op . storage_limit ) : undefined ,
173181 pvmKind : op . pvm_kind ,
174182 kernel : op . kernel ,
175- parametersType : op . parameters_ty ,
176- } ;
183+ parametersType : op . parameters_ty
184+ }
177185 case TezosOperationType . SMART_ROLLUP_EXECUTE_OUTBOX_MESSAGE :
178186 return {
179187 kind : OpKind . SMART_ROLLUP_EXECUTE_OUTBOX_MESSAGE ,
@@ -183,8 +191,8 @@ export default class TezosLib {
183191 storageLimit : op . storage_limit ? Number ( op . storage_limit ) : undefined ,
184192 rollup : op . rollup ,
185193 cementedCommitment : op . cemented_commitment ,
186- outputProof : op . output_proof ,
187- } ;
194+ outputProof : op . output_proof
195+ }
188196 case TezosOperationType . TRANSACTION :
189197 return {
190198 kind : OpKind . TRANSACTION ,
@@ -195,8 +203,8 @@ export default class TezosLib {
195203 fee : op . fee ? Number ( op . fee ) : undefined ,
196204 gasLimit : op . gas_limit ? Number ( op . gas_limit ) : undefined ,
197205 storageLimit : op . storage_limit ? Number ( op . storage_limit ) : undefined ,
198- parameter : op . parameters ,
199- } ;
206+ parameter : op . parameters
207+ }
200208 case TezosOperationType . TRANSFER_TICKET :
201209 return {
202210 kind : OpKind . TRANSFER_TICKET ,
@@ -209,51 +217,51 @@ export default class TezosLib {
209217 ticketTicketer : op . ticket_ticketer ,
210218 ticketAmount : Number ( op . ticket_amount ) ,
211219 destination : op . destination ,
212- entrypoint : op . entrypoint ,
213- } ;
220+ entrypoint : op . entrypoint
221+ }
214222 case TezosOperationType . UPDATE_CONSENSUS_KEY :
215223 return {
216224 kind : OpKind . UPDATE_CONSENSUS_KEY ,
217225 source : op . source ,
218226 fee : op . fee ? Number ( op . fee ) : undefined ,
219227 gasLimit : op . gas_limit ? Number ( op . gas_limit ) : undefined ,
220228 storageLimit : op . storage_limit ? Number ( op . storage_limit ) : undefined ,
221- pk : op . pk ,
222- } ;
229+ pk : op . pk
230+ }
223231 default :
224- throw new Error ( `Operation kind cannot be converted to ParamsWithKind: ${ op . kind } ` ) ;
232+ throw new Error ( `Operation kind cannot be converted to ParamsWithKind: ${ op . kind } ` )
225233 }
226234 }
227235
228236 public async signTransaction ( transaction : any , chainId : string ) {
229237 // Map the transactions and prepare the batch
230- console . log ( `Wallet: handling transaction: ` , transaction ) ;
238+ console . log ( `Wallet: handling transaction: ` , transaction )
231239 const batchTransactions : ParamsWithKind [ ] = transaction . map ( ( tx : PartialTezosOperation ) => {
232240 if ( tx . kind === TezosOperationType . DELEGATION && ! tx . source ) {
233- tx . source = this . address ;
241+ tx . source = this . address
234242 }
235- const op : ParamsWithKind = this . convertToPartialParamsWithKind ( tx ) ;
236- return op ;
237- } ) ;
243+ const op : ParamsWithKind = this . convertToPartialParamsWithKind ( tx )
244+ return op
245+ } )
238246
239- const toolkit = this . toolkits [ chainId ] ;
247+ const toolkit = this . toolkits [ chainId ]
240248 if ( ! toolkit ) {
241- throw new Error ( `Toolkit not found for chainId: ${ chainId } ` ) ;
242- }
249+ throw new Error ( `Toolkit not found for chainId: ${ chainId } ` )
250+ }
243251
244252 // Prepare the batch
245- console . log ( `Wallet: prepared batchTransactions ` , batchTransactions ) ;
246- const batch = toolkit . contract . batch ( batchTransactions ) ;
253+ console . log ( `Wallet: prepared batchTransactions ` , batchTransactions )
254+ const batch = toolkit . contract . batch ( batchTransactions )
247255
248256 // Send the batch and wait for the operation hash
249- console . log ( `Wallet: sending batch ` , batch ) ;
250- const operation = await batch . send ( ) ;
257+ console . log ( `Wallet: sending batch ` , batch )
258+ const operation = await batch . send ( )
251259
252260 // Wait for confirmation
253- await operation . confirmation ( ) ;
261+ await operation . confirmation ( )
254262
255- console . log ( 'Wallet: operation confirmed:' , operation ) ;
256- return operation . hash ;
263+ console . log ( 'Wallet: operation confirmed:' , operation )
264+ return operation . hash
257265 }
258266
259267 public async signPayload ( payload : any ) {
0 commit comments