Skip to content

Commit ff1fda7

Browse files
authored
feat: Update expo to use any activated account (#173)
PR #172 update the API to support using any activated account. We need to update the expo provider to the same API. This PR has 3 commits: 1. Update go.mod to use the latest gnokey-mobile following changes in PR gnolang/gnokey-mobile#9 2. In expo, npm install the latest gnolang_gnonative.bufbuild_es and connectrpc_es to access the new API 3. Update expo/src/api/GnoNativeApi.ts to match the new API to use any activated account, specified by address. Note that the address parameters are optional for temporary backwards compatibility. When dSocial and Gnokey Mobile are updated to use the new API and specify the address, we will do a PR to require the address parameter, and to remove the deprecated `selectAccount` and `getActiveAccount`. --------- Signed-off-by: Jeff Thompson <[email protected]>
1 parent 1a678ad commit ff1fda7

File tree

5 files changed

+46
-14
lines changed

5 files changed

+46
-14
lines changed

expo/package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

expo/src/api/GnoNativeApi.ts

+28-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
GenerateRecoveryPhraseRequest,
1111
GetActiveAccountRequest,
1212
GetActiveAccountResponse,
13+
GetActivatedAccountRequest,
14+
GetActivatedAccountResponse,
1315
GetChainIDRequest,
1416
GetKeyInfoByAddressRequest,
1517
GetKeyInfoByNameOrAddressRequest,
@@ -32,6 +34,8 @@ import {
3234
RenderRequest,
3335
SelectAccountRequest,
3436
SelectAccountResponse,
37+
ActivateAccountRequest,
38+
ActivateAccountResponse,
3539
SendRequest,
3640
SendResponse,
3741
SetChainIDRequest,
@@ -213,6 +217,16 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
213217
return response;
214218
}
215219

220+
async activateAccount(nameOrBech32: string): Promise<ActivateAccountResponse> {
221+
const client = await this.#getClient();
222+
const response = await client.activateAccount(
223+
new ActivateAccountRequest({
224+
nameOrBech32,
225+
}),
226+
);
227+
return response;
228+
}
229+
216230
async getClient(): Promise<PromiseClient<typeof GnoNativeService>> {
217231
if (!this.clientInstance) {
218232
throw new Error('GoBridge client instance not initialized.');
@@ -224,15 +238,15 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
224238
return this.clientInstance !== undefined;
225239
}
226240

227-
async setPassword(password: string): Promise<SetPasswordResponse> {
241+
async setPassword(password: string, address?: Uint8Array): Promise<SetPasswordResponse> {
228242
const client = await this.#getClient();
229-
const response = await client.setPassword(new SetPasswordRequest({ password }));
243+
const response = await client.setPassword(new SetPasswordRequest({ password, address }));
230244
return response;
231245
}
232246

233-
async updatePassword(newPassword: string): Promise<UpdatePasswordResponse> {
247+
async updatePassword(newPassword: string, address?: Uint8Array): Promise<UpdatePasswordResponse> {
234248
const client = await this.#getClient();
235-
const response = await client.updatePassword(new UpdatePasswordRequest({ newPassword }));
249+
const response = await client.updatePassword(new UpdatePasswordRequest({ newPassword, address }));
236250
return response;
237251
}
238252

@@ -242,6 +256,12 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
242256
return response;
243257
}
244258

259+
async getActivatedAccount(): Promise<GetActivatedAccountResponse> {
260+
const client = await this.#getClient();
261+
const response = await client.getActivatedAccount(new GetActivatedAccountRequest());
262+
return response;
263+
}
264+
245265
async queryAccount(address: Uint8Array): Promise<QueryAccountResponse> {
246266
const client = await this.#getClient();
247267
const reponse = await client.queryAccount(new QueryAccountRequest({ address }));
@@ -303,6 +323,7 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
303323
args: string[],
304324
gasFee: string,
305325
gasWanted: number,
326+
callerAddress?: Uint8Array,
306327
send?: string,
307328
memo?: string,
308329
): Promise<AsyncIterable<CallResponse>> {
@@ -312,6 +333,7 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
312333
gasFee,
313334
gasWanted: BigInt(gasWanted),
314335
memo,
336+
callerAddress,
315337
msgs: [
316338
new MsgCall({
317339
packagePath,
@@ -330,6 +352,7 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
330352
send: string,
331353
gasFee: string,
332354
gasWanted: number,
355+
callerAddress?: Uint8Array,
333356
memo?: string,
334357
): Promise<AsyncIterable<SendResponse>> {
335358
const client = await this.#getClient();
@@ -338,6 +361,7 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
338361
gasFee,
339362
gasWanted: BigInt(gasWanted),
340363
memo,
364+
callerAddress,
341365
msgs: [
342366
new MsgSend({
343367
toAddress,

expo/src/api/types.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import {
22
CallResponse,
33
DeleteAccountResponse,
44
GetActiveAccountResponse,
5+
GetActivatedAccountResponse,
56
HelloStreamResponse,
67
QueryAccountResponse,
78
QueryResponse,
89
SelectAccountResponse,
10+
ActivateAccountResponse,
911
SendResponse,
1012
SetChainIDResponse,
1113
SetPasswordResponse,
@@ -46,9 +48,11 @@ export interface GnoKeyApi {
4648
getKeyInfoByAddress: (address: Uint8Array) => Promise<KeyInfo | undefined>;
4749
getKeyInfoByNameOrAddress: (nameOrBech32: string) => Promise<KeyInfo | undefined>;
4850
selectAccount: (nameOrBech32: string) => Promise<SelectAccountResponse>;
49-
setPassword: (password: string) => Promise<SetPasswordResponse>;
50-
updatePassword: (password: string) => Promise<UpdatePasswordResponse>;
51+
activateAccount: (nameOrBech32: string) => Promise<ActivateAccountResponse>;
52+
setPassword: (password: string, address?: Uint8Array) => Promise<SetPasswordResponse>;
53+
updatePassword: (password: string, address?: Uint8Array) => Promise<UpdatePasswordResponse>;
5154
getActiveAccount: () => Promise<GetActiveAccountResponse>;
55+
getActivatedAccount: () => Promise<GetActivatedAccountResponse>;
5256
queryAccount: (address: Uint8Array) => Promise<QueryAccountResponse>;
5357
deleteAccount: (
5458
nameOrBech32: string,
@@ -64,6 +68,7 @@ export interface GnoKeyApi {
6468
args: string[],
6569
gasFee: string,
6670
gasWanted: number,
71+
callerAddress?: Uint8Array,
6772
send?: string,
6873
memo?: string,
6974
) => Promise<AsyncIterable<CallResponse>>;
@@ -72,6 +77,7 @@ export interface GnoKeyApi {
7277
send: string,
7378
gasFee: string,
7479
gasWanted: number,
80+
callerAddress?: Uint8Array,
7581
memo?: string,
7682
) => Promise<AsyncIterable<SendResponse>>;
7783
addressToBech32: (address: Uint8Array) => Promise<string>;

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
connectrpc.com/grpchealth v1.3.0
1010
connectrpc.com/grpcreflect v1.2.0
1111
github.com/gnolang/gno v0.1.2-0.20240826090356-651f5aac3706
12-
github.com/gnolang/gnokey-mobile v0.0.0-20240814140149-eb333b936c7c
12+
github.com/gnolang/gnokey-mobile v0.0.0-20240903152400-9942eff89ef6
1313
github.com/oklog/run v1.1.0
1414
github.com/peterbourgon/ff/v3 v3.4.0
1515
github.com/peterbourgon/unixtransport v0.0.3

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ github.com/gnolang/gno v0.1.2-0.20240826090356-651f5aac3706 h1:0kpoNeuErRec3JOt3
6161
github.com/gnolang/gno v0.1.2-0.20240826090356-651f5aac3706/go.mod h1:dBaL1Au2MNLol+3FXdCv+IKLJnMKtTmIt778zsKjVu0=
6262
github.com/gnolang/gnokey-mobile v0.0.0-20240814140149-eb333b936c7c h1:rL7dVjWOpdQxmbsh69HrgAklolhydTZmPvgo6BpgdhE=
6363
github.com/gnolang/gnokey-mobile v0.0.0-20240814140149-eb333b936c7c/go.mod h1:2NrHp15t6QXGNDruOpw6/xN6z50kquVvZs6uxvUNhsQ=
64+
github.com/gnolang/gnokey-mobile v0.0.0-20240903152400-9942eff89ef6 h1:D4dctoTOCk30fbMebwgDYRhcemXrcK7vqjl6MFPUIfc=
65+
github.com/gnolang/gnokey-mobile v0.0.0-20240903152400-9942eff89ef6/go.mod h1:fD0uCByVS8JKxQbSPOvJxO0s7vdfh1BBXBcv8d+ApDk=
6466
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216 h1:GKvsK3oLWG9B1GL7WP/VqwM6C92j5tIvB844oggL9Lk=
6567
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216/go.mod h1:xJhtEL7ahjM1WJipt89gel8tHzfIl/LyMY+lCYh38d8=
6668
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=

0 commit comments

Comments
 (0)