2
2
AddressFromBech32Request ,
3
3
AddressToBech32Request ,
4
4
AddressFromMnemonicRequest ,
5
+ BroadcastTxCommitResponse ,
5
6
CallRequest ,
6
7
CallResponse ,
7
8
CreateAccountRequest ,
@@ -18,11 +19,13 @@ import {
18
19
GetKeyInfoByNameRequest ,
19
20
GetRemoteRequest ,
20
21
HasKeyByAddressRequest ,
22
+ HasKeyByNameOrAddressRequest ,
21
23
HasKeyByNameRequest ,
22
24
HelloRequest ,
23
25
HelloStreamResponse ,
24
26
KeyInfo ,
25
27
ListKeyInfoRequest ,
28
+ MakeTxResponse ,
26
29
MsgCall ,
27
30
MsgSend ,
28
31
QEvalRequest ,
@@ -43,6 +46,7 @@ import {
43
46
SetPasswordResponse ,
44
47
SetRemoteRequest ,
45
48
SetRemoteResponse ,
49
+ SignTxResponse ,
46
50
UpdatePasswordRequest ,
47
51
UpdatePasswordResponse ,
48
52
} from '@buf/gnolang_gnonative.bufbuild_es/gnonativetypes_pb' ;
@@ -81,7 +85,9 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
81
85
82
86
try {
83
87
await this . clientInstance . setRemote ( new SetRemoteRequest ( { remote : this . config . remote } ) ) ;
84
- await this . clientInstance . setChainID ( new SetChainIDRequest ( { chainId : this . config . chain_id } ) ) ;
88
+ await this . clientInstance . setChainID (
89
+ new SetChainIDRequest ( { chainId : this . config . chain_id } ) ,
90
+ ) ;
85
91
console . log ( '✅ GnoNative bridge initialized.' ) ;
86
92
if ( this . config . start_gnokey_mobile_service ) {
87
93
await this . startGnokeyMobileService ( ) ;
@@ -113,31 +119,46 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
113
119
}
114
120
115
121
async setRemote ( remote : string ) : Promise < SetRemoteResponse > {
116
- const client = await this . #getClient( ) ;
117
- const response = await client . setRemote ( new SetRemoteRequest ( { remote } ) ) ;
122
+ const client = this . #getClient( ) ;
123
+ const response = client . setRemote ( new SetRemoteRequest ( { remote } ) ) ;
118
124
return response ;
119
125
}
120
126
121
127
async getRemote ( ) : Promise < string > {
122
- const client = await this . #getClient( ) ;
128
+ const client = this . #getClient( ) ;
123
129
const response = await client . getRemote ( new GetRemoteRequest ( ) ) ;
124
130
return response . remote ;
125
131
}
126
132
133
+ async signTx (
134
+ txJson : string ,
135
+ address : Uint8Array ,
136
+ accountNumber : bigint = BigInt ( 0 ) ,
137
+ sequenceNumber : bigint = BigInt ( 0 ) ,
138
+ ) : Promise < SignTxResponse > {
139
+ const client = this . #getClient( ) ;
140
+ const response = client . signTx ( { txJson, address, accountNumber, sequenceNumber } ) ;
141
+ return response ;
142
+ }
143
+
127
144
async setChainID ( chainId : string ) : Promise < SetChainIDResponse > {
128
- const client = await this . #getClient( ) ;
129
- const response = await client . setChainID ( new SetChainIDRequest ( { chainId } ) ) ;
145
+ const client = this . #getClient( ) ;
146
+ const response = client . setChainID ( new SetChainIDRequest ( { chainId } ) ) ;
130
147
return response ;
131
148
}
132
149
133
150
async getChainID ( ) {
134
- const client = await this . #getClient( ) ;
151
+ const client = this . #getClient( ) ;
135
152
const response = await client . getChainID ( new GetChainIDRequest ( ) ) ;
136
153
return response . chainId ;
137
154
}
138
155
139
- async createAccount ( nameOrBech32 : string , mnemonic : string , password : string ) : Promise < KeyInfo | undefined > {
140
- const client = await this . #getClient( ) ;
156
+ async createAccount (
157
+ nameOrBech32 : string ,
158
+ mnemonic : string ,
159
+ password : string ,
160
+ ) : Promise < KeyInfo | undefined > {
161
+ const client = this . #getClient( ) ;
141
162
const reponse = await client . createAccount (
142
163
new CreateAccountRequest ( {
143
164
nameOrBech32,
@@ -149,56 +170,88 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
149
170
}
150
171
151
172
async generateRecoveryPhrase ( ) {
152
- const client = await this . #getClient( ) ;
173
+ const client = this . #getClient( ) ;
153
174
const response = await client . generateRecoveryPhrase ( new GenerateRecoveryPhraseRequest ( ) ) ;
154
175
return response . phrase ;
155
176
}
156
177
157
178
async hasKeyByName ( name : string ) {
158
- const client = await this . #getClient( ) ;
179
+ const client = this . #getClient( ) ;
159
180
const response = await client . hasKeyByName ( new HasKeyByNameRequest ( { name } ) ) ;
160
181
return response . has ;
161
182
}
162
183
163
184
async hasKeyByAddress ( address : Uint8Array ) {
164
- const client = await this . #getClient( ) ;
185
+ const client = this . #getClient( ) ;
165
186
const response = await client . hasKeyByAddress ( new HasKeyByAddressRequest ( { address } ) ) ;
166
187
return response . has ;
167
188
}
168
189
169
190
async hasKeyByNameOrAddress ( nameOrBech32 : string ) {
170
- const client = await this . #getClient( ) ;
171
- const response = await client . hasKeyByNameOrAddress ( new HasKeyByNameOrAddressRequest ( { nameOrBech32 } ) ) ;
191
+ const client = this . #getClient( ) ;
192
+ const response = await client . hasKeyByNameOrAddress (
193
+ new HasKeyByNameOrAddressRequest ( { nameOrBech32 } ) ,
194
+ ) ;
172
195
return response . has ;
173
196
}
174
197
175
198
async getKeyInfoByName ( name : string ) : Promise < KeyInfo | undefined > {
176
- const client = await this . #getClient( ) ;
199
+ const client = this . #getClient( ) ;
177
200
const response = await client . getKeyInfoByName ( new GetKeyInfoByNameRequest ( { name } ) ) ;
178
201
return response . key ;
179
202
}
180
203
181
204
async getKeyInfoByAddress ( address : Uint8Array ) : Promise < KeyInfo | undefined > {
182
- const client = await this . #getClient( ) ;
205
+ const client = this . #getClient( ) ;
183
206
const response = await client . getKeyInfoByAddress ( new GetKeyInfoByAddressRequest ( { address } ) ) ;
184
207
return response . key ;
185
208
}
186
209
187
210
async getKeyInfoByNameOrAddress ( nameOrBech32 : string ) : Promise < KeyInfo | undefined > {
188
- const client = await this . #getClient( ) ;
189
- const response = await client . getKeyInfoByNameOrAddress ( new GetKeyInfoByNameOrAddressRequest ( { nameOrBech32 } ) ) ;
211
+ const client = this . #getClient( ) ;
212
+ const response = await client . getKeyInfoByNameOrAddress (
213
+ new GetKeyInfoByNameOrAddressRequest ( { nameOrBech32 } ) ,
214
+ ) ;
190
215
return response . key ;
191
216
}
192
217
193
218
async listKeyInfo ( ) : Promise < KeyInfo [ ] > {
194
- const client = await this . #getClient( ) ;
219
+ const client = this . #getClient( ) ;
195
220
const response = await client . listKeyInfo ( new ListKeyInfoRequest ( ) ) ;
196
221
return response . keys ;
197
222
}
198
223
224
+ async makeCallTx (
225
+ packagePath : string ,
226
+ fnc : string ,
227
+ args : string [ ] ,
228
+ gasFee : string ,
229
+ gasWanted : bigint ,
230
+ callerAddress ?: Uint8Array ,
231
+ send ?: string ,
232
+ memo ?: string ,
233
+ ) : Promise < MakeTxResponse > {
234
+ const client = this . #getClient( ) ;
235
+ const reponse = client . makeCallTx ( {
236
+ gasFee,
237
+ gasWanted,
238
+ memo,
239
+ callerAddress,
240
+ msgs : [
241
+ {
242
+ packagePath,
243
+ fnc,
244
+ args,
245
+ send,
246
+ } ,
247
+ ] ,
248
+ } ) ;
249
+ return reponse ;
250
+ }
251
+
199
252
async selectAccount ( nameOrBech32 : string ) : Promise < SelectAccountResponse > {
200
- const client = await this . #getClient( ) ;
201
- const response = await client . selectAccount (
253
+ const client = this . #getClient( ) ;
254
+ const response = client . selectAccount (
202
255
new SelectAccountRequest ( {
203
256
nameOrBech32,
204
257
} ) ,
@@ -207,8 +260,8 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
207
260
}
208
261
209
262
async activateAccount ( nameOrBech32 : string ) : Promise < ActivateAccountResponse > {
210
- const client = await this . #getClient( ) ;
211
- const response = await client . activateAccount (
263
+ const client = this . #getClient( ) ;
264
+ const response = client . activateAccount (
212
265
new ActivateAccountRequest ( {
213
266
nameOrBech32,
214
267
} ) ,
@@ -228,38 +281,45 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
228
281
}
229
282
230
283
async setPassword ( password : string , address ?: Uint8Array ) : Promise < SetPasswordResponse > {
231
- const client = await this . #getClient( ) ;
232
- const response = await client . setPassword ( new SetPasswordRequest ( { password, address } ) ) ;
284
+ const client = this . #getClient( ) ;
285
+ const response = client . setPassword ( new SetPasswordRequest ( { password, address } ) ) ;
233
286
return response ;
234
287
}
235
288
236
- async updatePassword ( newPassword : string , address ?: Uint8Array ) : Promise < UpdatePasswordResponse > {
237
- const client = await this . #getClient( ) ;
238
- const response = await client . updatePassword ( new UpdatePasswordRequest ( { newPassword, address } ) ) ;
289
+ async updatePassword (
290
+ newPassword : string ,
291
+ addresses : Uint8Array [ ] ,
292
+ ) : Promise < UpdatePasswordResponse > {
293
+ const client = this . #getClient( ) ;
294
+ const response = client . updatePassword ( new UpdatePasswordRequest ( { newPassword, addresses } ) ) ;
239
295
return response ;
240
296
}
241
297
242
298
async getActiveAccount ( ) : Promise < GetActiveAccountResponse > {
243
- const client = await this . #getClient( ) ;
244
- const response = await client . getActiveAccount ( new GetActiveAccountRequest ( ) ) ;
299
+ const client = this . #getClient( ) ;
300
+ const response = client . getActiveAccount ( new GetActiveAccountRequest ( ) ) ;
245
301
return response ;
246
302
}
247
303
248
304
async getActivatedAccount ( ) : Promise < GetActivatedAccountResponse > {
249
- const client = await this . #getClient( ) ;
250
- const response = await client . getActivatedAccount ( new GetActivatedAccountRequest ( ) ) ;
305
+ const client = this . #getClient( ) ;
306
+ const response = client . getActivatedAccount ( new GetActivatedAccountRequest ( ) ) ;
251
307
return response ;
252
308
}
253
309
254
310
async queryAccount ( address : Uint8Array ) : Promise < QueryAccountResponse > {
255
- const client = await this . #getClient( ) ;
256
- const reponse = await client . queryAccount ( new QueryAccountRequest ( { address } ) ) ;
311
+ const client = this . #getClient( ) ;
312
+ const reponse = client . queryAccount ( new QueryAccountRequest ( { address } ) ) ;
257
313
return reponse ;
258
314
}
259
315
260
- async deleteAccount ( nameOrBech32 : string , password : string | undefined , skipPassword : boolean ) : Promise < DeleteAccountResponse > {
261
- const client = await this . #getClient( ) ;
262
- const response = await client . deleteAccount (
316
+ async deleteAccount (
317
+ nameOrBech32 : string ,
318
+ password : string | undefined ,
319
+ skipPassword : boolean ,
320
+ ) : Promise < DeleteAccountResponse > {
321
+ const client = this . #getClient( ) ;
322
+ const response = client . deleteAccount (
263
323
new DeleteAccountRequest ( {
264
324
nameOrBech32,
265
325
password,
@@ -270,8 +330,8 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
270
330
}
271
331
272
332
async query ( path : string , data : Uint8Array ) : Promise < QueryResponse > {
273
- const client = await this . #getClient( ) ;
274
- const reponse = await client . query (
333
+ const client = this . #getClient( ) ;
334
+ const reponse = client . query (
275
335
new QueryRequest ( {
276
336
path,
277
337
data,
@@ -281,7 +341,7 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
281
341
}
282
342
283
343
async render ( packagePath : string , args : string ) {
284
- const client = await this . #getClient( ) ;
344
+ const client = this . #getClient( ) ;
285
345
const reponse = await client . render (
286
346
new RenderRequest ( {
287
347
packagePath,
@@ -292,7 +352,7 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
292
352
}
293
353
294
354
async qEval ( packagePath : string , expression : string ) {
295
- const client = await this . #getClient( ) ;
355
+ const client = this . #getClient( ) ;
296
356
const reponse = await client . qEval (
297
357
new QEvalRequest ( {
298
358
packagePath,
@@ -307,16 +367,16 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
307
367
fnc : string ,
308
368
args : string [ ] ,
309
369
gasFee : string ,
310
- gasWanted : number ,
370
+ gasWanted : bigint ,
311
371
callerAddress ?: Uint8Array ,
312
372
send ?: string ,
313
373
memo ?: string ,
314
374
) : Promise < AsyncIterable < CallResponse > > {
315
- const client = await this . #getClient( ) ;
375
+ const client = this . #getClient( ) ;
316
376
const reponse = client . call (
317
377
new CallRequest ( {
318
378
gasFee,
319
- gasWanted : BigInt ( gasWanted ) ,
379
+ gasWanted,
320
380
memo,
321
381
callerAddress,
322
382
msgs : [
@@ -336,15 +396,15 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
336
396
toAddress : Uint8Array ,
337
397
send : string ,
338
398
gasFee : string ,
339
- gasWanted : number ,
399
+ gasWanted : bigint ,
340
400
callerAddress ?: Uint8Array ,
341
401
memo ?: string ,
342
402
) : Promise < AsyncIterable < SendResponse > > {
343
- const client = await this . #getClient( ) ;
403
+ const client = this . #getClient( ) ;
344
404
const reponse = client . send (
345
405
new SendRequest ( {
346
406
gasFee,
347
- gasWanted : BigInt ( gasWanted ) ,
407
+ gasWanted,
348
408
memo,
349
409
callerAddress,
350
410
msgs : [
@@ -359,33 +419,41 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
359
419
}
360
420
361
421
async addressToBech32 ( address : Uint8Array ) {
362
- const client = await this . #getClient( ) ;
422
+ const client = this . #getClient( ) ;
363
423
const response = await client . addressToBech32 ( new AddressToBech32Request ( { address } ) ) ;
364
424
return response . bech32Address ;
365
425
}
366
426
367
427
async addressFromMnemonic ( mnemonic : string ) {
368
- const client = await this . #getClient( ) ;
428
+ const client = this . #getClient( ) ;
369
429
const response = await client . addressFromMnemonic ( new AddressFromMnemonicRequest ( { mnemonic } ) ) ;
370
430
return response . address ;
371
431
}
372
432
373
433
async addressFromBech32 ( bech32Address : string ) {
374
- const client = await this . #getClient( ) ;
375
- const response = await client . addressFromBech32 ( new AddressFromBech32Request ( { bech32Address } ) ) ;
434
+ const client = this . #getClient( ) ;
435
+ const response = await client . addressFromBech32 (
436
+ new AddressFromBech32Request ( { bech32Address } ) ,
437
+ ) ;
376
438
return response . address ;
377
439
}
378
440
441
+ async broadcastTxCommit ( signedTxJson : string ) : Promise < AsyncIterable < BroadcastTxCommitResponse > > {
442
+ const client = this . #getClient( ) ;
443
+ const response = client . broadcastTxCommit ( { signedTxJson } ) ;
444
+ return response ;
445
+ }
446
+
379
447
// // debug
380
448
async hello ( name : string ) {
381
- const client = await this . #getClient( ) ;
449
+ const client = this . #getClient( ) ;
382
450
const response = await client . hello ( new HelloRequest ( { name } ) ) ;
383
451
return response . greeting ;
384
452
}
385
453
386
454
// // debug
387
455
async helloStream ( name : string ) : Promise < AsyncIterable < HelloStreamResponse > > {
388
- const client = await this . #getClient( ) ;
456
+ const client = this . #getClient( ) ;
389
457
return client . helloStream ( new HelloRequest ( { name } ) ) ;
390
458
}
391
459
0 commit comments