@gnolang/gnonative 1.2.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +6 -6
  2. package/android/libs/gnocore.aar +0 -0
  3. package/build/api/GnoNativeApi.d.ts +50 -0
  4. package/build/api/GnoNativeApi.d.ts.map +1 -0
  5. package/build/api/GnoNativeApi.js +261 -0
  6. package/build/api/GnoNativeApi.js.map +1 -0
  7. package/build/api/index.d.ts +3 -0
  8. package/build/api/index.d.ts.map +1 -0
  9. package/build/api/index.js +3 -0
  10. package/build/api/index.js.map +1 -0
  11. package/build/{hooks/use-gno.d.ts → api/types.d.ts} +18 -13
  12. package/build/api/types.d.ts.map +1 -0
  13. package/build/api/types.js +7 -0
  14. package/build/api/types.js.map +1 -0
  15. package/build/index.d.ts +1 -1
  16. package/build/index.d.ts.map +1 -1
  17. package/build/index.js +1 -1
  18. package/build/index.js.map +1 -1
  19. package/build/provider/gnonative-provider.d.ts +4 -35
  20. package/build/provider/gnonative-provider.d.ts.map +1 -1
  21. package/build/provider/gnonative-provider.js +5 -249
  22. package/build/provider/gnonative-provider.js.map +1 -1
  23. package/ios/Frameworks/GnoCore.xcframework/Info.plist +5 -5
  24. package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/GnoCore +0 -0
  25. package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/A/GnoCore +0 -0
  26. package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/Current/GnoCore +0 -0
  27. package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/GnoCore +0 -0
  28. package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/A/GnoCore +0 -0
  29. package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/Current/GnoCore +0 -0
  30. package/package.json +1 -1
  31. package/src/api/GnoNativeApi.ts +388 -0
  32. package/src/api/index.ts +2 -0
  33. package/src/api/types.ts +78 -0
  34. package/src/index.ts +2 -1
  35. package/src/provider/gnonative-provider.tsx +8 -428
  36. package/build/hooks/types.d.ts +0 -17
  37. package/build/hooks/types.d.ts.map +0 -1
  38. package/build/hooks/types.js +0 -2
  39. package/build/hooks/types.js.map +0 -1
  40. package/build/hooks/use-gno.d.ts.map +0 -1
  41. package/build/hooks/use-gno.js +0 -256
  42. package/build/hooks/use-gno.js.map +0 -1
  43. package/src/hooks/types.ts +0 -19
  44. package/src/hooks/use-gno.ts +0 -431
@@ -1,431 +0,0 @@
1
- import {
2
- AddressFromBech32Request,
3
- AddressToBech32Request,
4
- CallRequest,
5
- CallResponse,
6
- CreateAccountRequest,
7
- DeleteAccountRequest,
8
- DeleteAccountResponse,
9
- GenerateRecoveryPhraseRequest,
10
- GetActiveAccountRequest,
11
- GetActiveAccountResponse,
12
- GetChainIDRequest,
13
- GetKeyInfoByAddressRequest,
14
- GetKeyInfoByNameOrAddressRequest,
15
- GetKeyInfoByNameRequest,
16
- GetRemoteRequest,
17
- HasKeyByAddressRequest,
18
- HasKeyByNameOrAddressRequest,
19
- HasKeyByNameRequest,
20
- HelloRequest,
21
- HelloStreamResponse,
22
- ListKeyInfoRequest,
23
- MsgCall,
24
- MsgSend,
25
- QEvalRequest,
26
- QueryAccountRequest,
27
- QueryAccountResponse,
28
- QueryRequest,
29
- QueryResponse,
30
- RenderRequest,
31
- SelectAccountRequest,
32
- SelectAccountResponse,
33
- SendRequest,
34
- SendResponse,
35
- SetChainIDRequest,
36
- SetChainIDResponse,
37
- SetPasswordRequest,
38
- SetPasswordResponse,
39
- SetRemoteRequest,
40
- SetRemoteResponse,
41
- } from '@buf/gnolang_gnonative.bufbuild_es/gnonativetypes_pb';
42
- import { GnoNativeService } from '@buf/gnolang_gnonative.connectrpc_es/rpc_connect';
43
- import { PromiseClient } from '@connectrpc/connect';
44
-
45
- import { GnoAccount } from './types';
46
- import { GoBridge } from '../GoBridge';
47
- import * as Grpc from '../grpc/client';
48
-
49
- export interface GnoResponse {
50
- setRemote: (remote: string) => Promise<SetRemoteResponse>;
51
- getRemote: () => Promise<string>;
52
- setChainID: (chainId: string) => Promise<SetChainIDResponse>;
53
- getChainID: () => Promise<string>;
54
- createAccount: (
55
- nameOrBech32: string,
56
- mnemonic: string,
57
- password: string,
58
- ) => Promise<GnoAccount | undefined>;
59
- generateRecoveryPhrase: () => Promise<string>;
60
- listKeyInfo: () => Promise<GnoAccount[]>;
61
- hasKeyByName: (name: string) => Promise<boolean>;
62
- hasKeyByAddress: (address: Uint8Array) => Promise<boolean>;
63
- hasKeyByNameOrAddress: (nameOrBech32: string) => Promise<boolean>;
64
- getKeyInfoByName: (name: string) => Promise<GnoAccount | undefined>;
65
- getKeyInfoByAddress: (address: Uint8Array) => Promise<GnoAccount | undefined>;
66
- getKeyInfoByNameOrAddress: (nameOrBech32: string) => Promise<GnoAccount | undefined>;
67
- selectAccount: (nameOrBech32: string) => Promise<SelectAccountResponse>;
68
- setPassword: (password: string) => Promise<SetPasswordResponse>;
69
- getActiveAccount: () => Promise<GetActiveAccountResponse>;
70
- queryAccount: (address: Uint8Array) => Promise<QueryAccountResponse>;
71
- deleteAccount: (
72
- nameOrBech32: string,
73
- password: string | undefined,
74
- skipPassword: boolean,
75
- ) => Promise<DeleteAccountResponse>;
76
- query: (path: string, data: Uint8Array) => Promise<QueryResponse>;
77
- render: (packagePath: string, args: string) => Promise<string>;
78
- qEval: (packagePath: string, expression: string) => Promise<string>;
79
- call: (
80
- packagePath: string,
81
- fnc: string,
82
- args: Array<string>,
83
- gasFee: string,
84
- gasWanted: number,
85
- send?: string,
86
- memo?: string,
87
- ) => Promise<AsyncIterable<CallResponse>>;
88
- send: (
89
- toAddress: Uint8Array,
90
- send: string,
91
- gasFee: string,
92
- gasWanted: number,
93
- memo?: string,
94
- ) => Promise<AsyncIterable<SendResponse>>;
95
- addressToBech32: (address: Uint8Array) => Promise<string>;
96
- addressFromBech32: (bech32Address: string) => Promise<Uint8Array>;
97
- closeBridge: () => Promise<void>;
98
- initBridge: () => Promise<void>;
99
- // debug
100
- hello: (name: string) => Promise<string>;
101
- helloStream: (name: string) => Promise<AsyncIterable<HelloStreamResponse>>;
102
- }
103
-
104
- enum Status {
105
- Stopped,
106
- Starting,
107
- Started,
108
- }
109
-
110
- let clientInstance: PromiseClient<typeof GnoNativeService> | undefined = undefined;
111
- let bridgeStatus: Status = Status.Stopped;
112
-
113
- export const useGno = (): GnoResponse => {
114
- const getClient = async () => {
115
- if (bridgeStatus === Status.Stopped) {
116
- await initBridge();
117
- }
118
-
119
- if (clientInstance) return clientInstance;
120
-
121
- console.log('Creating GRPC client instance...');
122
-
123
- const port = await GoBridge.getTcpPort();
124
- clientInstance = Grpc.createClient(port);
125
-
126
- console.log('Creating GRPC client instance... done.');
127
-
128
- // Set the initial configuration where it's different from the default.
129
- await clientInstance.setRemote(new SetRemoteRequest({ remote: 'gno.land:26657' }));
130
- await clientInstance.setChainID(new SetChainIDRequest({ chainId: 'portal-loop' }));
131
-
132
- return clientInstance;
133
- };
134
-
135
- const closeBridge = async () => {
136
- if (bridgeStatus !== Status.Stopped) {
137
- console.log('Closing bridge...');
138
- await GoBridge.closeBridge();
139
- console.log('Bridge closed.');
140
- bridgeStatus = Status.Stopped;
141
- clientInstance = undefined;
142
- }
143
- };
144
-
145
- const initBridge = async () => {
146
- if (bridgeStatus === Status.Stopped) {
147
- console.log('Initializing bridge...');
148
- bridgeStatus = Status.Starting;
149
- await GoBridge.initBridge();
150
- console.log('Bridge initialized.');
151
- bridgeStatus = Status.Started;
152
- }
153
- };
154
-
155
- const setRemote = async (remote: string) => {
156
- const client = await getClient();
157
- const response = await client.setRemote(new SetRemoteRequest({ remote }));
158
- return response;
159
- };
160
-
161
- const getRemote = async () => {
162
- const client = await getClient();
163
- const response = await client.getRemote(new GetRemoteRequest());
164
- return response.remote;
165
- };
166
-
167
- const setChainID = async (chainId: string) => {
168
- const client = await getClient();
169
- const response = await client.setChainID(new SetChainIDRequest({ chainId }));
170
- return response;
171
- };
172
-
173
- const getChainID = async () => {
174
- const client = await getClient();
175
- const response = await client.getChainID(new GetChainIDRequest());
176
- return response.chainId;
177
- };
178
-
179
- const createAccount = async (nameOrBech32: string, mnemonic: string, password: string) => {
180
- const client = await getClient();
181
- const reponse = await client.createAccount(
182
- new CreateAccountRequest({
183
- nameOrBech32,
184
- mnemonic,
185
- password,
186
- }),
187
- );
188
- return reponse.key;
189
- };
190
-
191
- const generateRecoveryPhrase = async () => {
192
- const client = await getClient();
193
- const response = await client.generateRecoveryPhrase(new GenerateRecoveryPhraseRequest());
194
- return response.phrase;
195
- };
196
-
197
- const hasKeyByName = async (name: string) => {
198
- const client = await getClient();
199
- const response = await client.hasKeyByName(new HasKeyByNameRequest({ name }));
200
- return response.has;
201
- };
202
-
203
- const hasKeyByAddress = async (address: Uint8Array) => {
204
- const client = await getClient();
205
- const response = await client.hasKeyByAddress(new HasKeyByAddressRequest({ address }));
206
- return response.has;
207
- };
208
-
209
- const hasKeyByNameOrAddress = async (nameOrBech32: string) => {
210
- const client = await getClient();
211
- const response = await client.hasKeyByNameOrAddress(
212
- new HasKeyByNameOrAddressRequest({ nameOrBech32 }),
213
- );
214
- return response.has;
215
- };
216
-
217
- const getKeyInfoByName = async (name: string) => {
218
- const client = await getClient();
219
- const response = await client.getKeyInfoByName(new GetKeyInfoByNameRequest({ name }));
220
- return response.key;
221
- };
222
-
223
- const getKeyInfoByAddress = async (address: Uint8Array) => {
224
- const client = await getClient();
225
- const response = await client.getKeyInfoByAddress(new GetKeyInfoByAddressRequest({ address }));
226
- return response.key;
227
- };
228
-
229
- const getKeyInfoByNameOrAddress = async (nameOrBech32: string) => {
230
- const client = await getClient();
231
- const response = await client.getKeyInfoByNameOrAddress(
232
- new GetKeyInfoByNameOrAddressRequest({ nameOrBech32 }),
233
- );
234
- return response.key;
235
- };
236
-
237
- const listKeyInfo = async () => {
238
- const client = await getClient();
239
- const response = await client.listKeyInfo(new ListKeyInfoRequest());
240
- return response.keys;
241
- };
242
-
243
- const selectAccount = async (nameOrBech32: string) => {
244
- const client = await getClient();
245
- const response = await client.selectAccount(
246
- new SelectAccountRequest({
247
- nameOrBech32,
248
- }),
249
- );
250
- return response;
251
- };
252
-
253
- const setPassword = async (password: string) => {
254
- const client = await getClient();
255
- const response = await client.setPassword(new SetPasswordRequest({ password }));
256
- return response;
257
- };
258
-
259
- const getActiveAccount = async () => {
260
- const client = await getClient();
261
- const response = await client.getActiveAccount(new GetActiveAccountRequest());
262
- return response;
263
- };
264
-
265
- const queryAccount = async (address: Uint8Array) => {
266
- const client = await getClient();
267
- const reponse = await client.queryAccount(new QueryAccountRequest({ address }));
268
- return reponse;
269
- };
270
-
271
- const deleteAccount = async (
272
- nameOrBech32: string,
273
- password: string | undefined,
274
- skipPassword: boolean,
275
- ) => {
276
- const client = await getClient();
277
- const response = await client.deleteAccount(
278
- new DeleteAccountRequest({
279
- nameOrBech32,
280
- password,
281
- skipPassword,
282
- }),
283
- );
284
- return response;
285
- };
286
-
287
- const query = async (path: string, data: Uint8Array) => {
288
- const client = await getClient();
289
- const reponse = await client.query(
290
- new QueryRequest({
291
- path,
292
- data,
293
- }),
294
- );
295
- return reponse;
296
- };
297
-
298
- const render = async (packagePath: string, args: string) => {
299
- const client = await getClient();
300
- const reponse = await client.render(
301
- new RenderRequest({
302
- packagePath,
303
- args,
304
- }),
305
- );
306
- return reponse.result;
307
- };
308
-
309
- const qEval = async (packagePath: string, expression: string) => {
310
- const client = await getClient();
311
- const reponse = await client.qEval(
312
- new QEvalRequest({
313
- packagePath,
314
- expression,
315
- }),
316
- );
317
- return reponse.result;
318
- };
319
-
320
- const call = async (
321
- packagePath: string,
322
- fnc: string,
323
- args: Array<string>,
324
- gasFee: string,
325
- gasWanted: number,
326
- send?: string,
327
- memo?: string,
328
- ) => {
329
- const client = await getClient();
330
- const reponse = client.call(
331
- new CallRequest({
332
- gasFee,
333
- gasWanted: BigInt(gasWanted),
334
- memo,
335
- msgs: [
336
- new MsgCall({
337
- packagePath,
338
- fnc,
339
- args,
340
- send,
341
- }),
342
- ],
343
- }),
344
- );
345
- return reponse;
346
- };
347
-
348
- const send = async (
349
- toAddress: Uint8Array,
350
- send: string,
351
- gasFee: string,
352
- gasWanted: number,
353
- memo?: string,
354
- ) => {
355
- const client = await getClient();
356
- const reponse = client.send(
357
- new SendRequest({
358
- gasFee,
359
- gasWanted: BigInt(gasWanted),
360
- memo,
361
- msgs: [
362
- new MsgSend({
363
- toAddress,
364
- send,
365
- }),
366
- ],
367
- }),
368
- );
369
- return reponse;
370
- };
371
-
372
- const addressToBech32 = async (address: Uint8Array) => {
373
- const client = await getClient();
374
- const response = await client.addressToBech32(new AddressToBech32Request({ address }));
375
- return response.bech32Address;
376
- };
377
-
378
- const addressFromBech32 = async (bech32Address: string) => {
379
- const client = await getClient();
380
- const response = await client.addressFromBech32(
381
- new AddressFromBech32Request({ bech32Address }),
382
- );
383
- return response.address;
384
- };
385
-
386
- // debug
387
- const hello = async (name: string) => {
388
- const client = await getClient();
389
- const response = await client.hello(new HelloRequest({ name }));
390
- return response.greeting;
391
- };
392
-
393
- // debug
394
- const helloStream = async (name: string) => {
395
- const client = await getClient();
396
- return client.helloStream(new HelloRequest({ name }));
397
- };
398
-
399
- return {
400
- initBridge,
401
- closeBridge,
402
- setRemote,
403
- getRemote,
404
- setChainID,
405
- getChainID,
406
- createAccount,
407
- generateRecoveryPhrase,
408
- listKeyInfo,
409
- hasKeyByName,
410
- hasKeyByAddress,
411
- hasKeyByNameOrAddress,
412
- getKeyInfoByName,
413
- getKeyInfoByAddress,
414
- getKeyInfoByNameOrAddress,
415
- selectAccount,
416
- setPassword,
417
- getActiveAccount,
418
- queryAccount,
419
- deleteAccount,
420
- query,
421
- render,
422
- qEval,
423
- call,
424
- send,
425
- addressToBech32,
426
- addressFromBech32,
427
- // debug
428
- hello,
429
- helloStream,
430
- };
431
- };