Skip to content

Commit 0bb37cb

Browse files
authored
chore: Remove unused gnokey-mobile gRPC communication (#194)
gnokey-mobile PR gnolang/gnokey-mobile#35 removed the unused gRPC server, since we now use deep links. Importantly, the code to call functions like `gnoNativeService.ClientSignTx` are removed. So we can remove these functions in gnonative. * In the `GnoNativeService` interface and `gnoNativeService` type, remove `ClientGetRemote`, `ClientListKeyInfo` and `ClientSignTx` which were only used by the Gnokey Mobile gRPC server. * In the `Config` and `gnoNativeService` structs, remove `useGnokeyMobile` flag and the code in api.go which does special handling for this flag. * In bridge.go and the related Swift and Kotlin files, remove support for `StartGnokeyMobileService`. This allows us to remove the dependency on `github.com/gnolang/gnokey-mobile/service`, so remove it from go.mod. * Run `make regenerate` which updates files in api/gen/go, including changes for the new buf version. This PR was tested by running `make npm.pack` in the expo folder, installing this package in gnokey-mobile, then testing with dsocial on Android and iOS simulators. (Note that examples/js/react-native/hello has a copies of files from the expo folder. These are out-of-date for recent changes in the API, including this PR. We will do a future PR to update the hello example.) --------- Signed-off-by: Jeff Thompson <[email protected]>
1 parent e4c8952 commit 0bb37cb

File tree

13 files changed

+262
-544
lines changed

13 files changed

+262
-544
lines changed

api/gen/go/gnonativetypes.pb.go

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

api/gen/go/rpc.pb.go

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

expo/android/src/main/java/land/gno/gnonative/GnonativeModule.kt

-13
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,6 @@ class GnonativeModule : Module() {
8888
}
8989
}
9090

91-
AsyncFunction("startGnokeyMobileService") { promise: Promise ->
92-
try {
93-
bridgeGnoNative?.let {
94-
bridgeGnoNative!!.startGnokeyMobileService()
95-
promise.resolve(true)
96-
} ?: run {
97-
throw GoBridgeNotStartedError()
98-
}
99-
} catch (err: CodedException) {
100-
promise.reject(err)
101-
}
102-
}
103-
10491
AsyncFunction("invokeGrpcMethod") { method: String, jsonMessage: String, promise: Promise ->
10592
try {
10693
bridgeGnoNative?.let {

expo/ios/GnonativeModule.swift

-12
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,6 @@ public class GnonativeModule: Module {
9292
}
9393
}
9494

95-
AsyncFunction("startGnokeyMobileService") { (promise: Promise) in
96-
do {
97-
guard let service = self.bridge else {
98-
throw GnoError(.notStarted)
99-
}
100-
try service.startGnokeyMobileService()
101-
promise.resolve(true)
102-
} catch let error {
103-
promise.reject(error)
104-
}
105-
}
106-
10795
AsyncFunction("closeBridge") { (promise: Promise) in
10896
do {
10997
guard let service = self.bridge else {

expo/src/GoBridge.ts

-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export interface GoBridgeInterface {
44
initBridge(): Promise<void>;
55
closeBridge(): Promise<void>;
66
getTcpPort(): Promise<number>;
7-
startGnokeyMobileService(): Promise<void>;
87
invokeGrpcMethod(method: string, jsonMessage: string): Promise<string>;
98
createStreamClient(method: string, jsonMessage: string): Promise<string>;
109
streamClientReceive(id: string): Promise<string>;
@@ -24,10 +23,6 @@ class GoBridge implements GoBridgeInterface {
2423
return GnonativeModule.getTcpPort();
2524
}
2625

27-
startGnokeyMobileService(): Promise<void> {
28-
return GnonativeModule.startGnokeyMobileService();
29-
}
30-
3126
invokeGrpcMethod(method: string, jsonMessage: string): Promise<string> {
3227
return GnonativeModule.invokeGrpcMethod(method, jsonMessage);
3328
}

expo/src/api/GnoNativeApi.ts

-7
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
8686
new SetChainIDRequest({ chainId: this.config.chain_id }),
8787
);
8888
console.log('✅ GnoNative bridge initialized.');
89-
if (this.config.start_gnokey_mobile_service) {
90-
await this.startGnokeyMobileService();
91-
console.log('✅ Gnokey Mobile service started.');
92-
}
9389
return true;
9490
} catch (error) {
9591
console.error(error);
@@ -472,9 +468,6 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
472468
getTcpPort(): Promise<number> {
473469
return GoBridge.getTcpPort();
474470
}
475-
startGnokeyMobileService(): Promise<void> {
476-
return GoBridge.startGnokeyMobileService();
477-
}
478471
invokeGrpcMethod(method: string, jsonMessage: string): Promise<string> {
479472
return GoBridge.invokeGrpcMethod(method, jsonMessage);
480473
}

expo/src/api/types.ts

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ export enum BridgeStatus {
2727
export interface Config {
2828
remote: string;
2929
chain_id: string;
30-
// If true, initBridge also starts a Gnokey Mobile service. (Only needed for the Gnokey Mobile app.)
31-
start_gnokey_mobile_service?: boolean;
3230
}
3331

3432
export interface GnoKeyApi {

framework/service/bridge.go

-32
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/peterbourgon/unixtransport"
1414
"go.uber.org/multierr"
1515

16-
gnokey_mobile_service "github.com/gnolang/gnokey-mobile/service"
1716
api_gen "github.com/gnolang/gnonative/api/gen/go"
1817
"github.com/gnolang/gnonative/api/gen/go/_goconnect"
1918
"github.com/gnolang/gnonative/service"
@@ -24,7 +23,6 @@ type BridgeConfig struct {
2423
TmpDir string
2524
UseTcpListener bool
2625
DisableUdsListener bool
27-
UseGnokeyMobile bool
2826
}
2927

3028
func NewBridgeConfig() *BridgeConfig {
@@ -40,8 +38,6 @@ type Bridge struct {
4038

4139
serviceServer service.GnoNativeService
4240

43-
gnokeyMobileService gnokey_mobile_service.GnokeyMobileService
44-
4541
ServiceClient
4642
}
4743

@@ -81,10 +77,6 @@ func NewBridge(config *BridgeConfig) (*Bridge, error) {
8177
svcOpts = append(svcOpts, service.WithDisableUdsListener())
8278
}
8379

84-
if config.UseGnokeyMobile {
85-
svcOpts = append(svcOpts, service.WithUseGnokeyMobile())
86-
}
87-
8880
serviceServer, err := service.NewGnoNativeService(svcOpts...)
8981
if err != nil {
9082
return nil, errors.Wrap(err, "unable to create bridge service")
@@ -160,28 +152,6 @@ func (b *Bridge) GetTcpAddr() string {
160152
return b.serviceServer.GetTcpAddr()
161153
}
162154

163-
// Start the Gnokey Mobile service and save it in gnokeyMobileService. This will be closed in Close().
164-
// If the gnonative serviceServer is not started, do nothing.
165-
// If gnokeyMobileService is already started, do nothing.
166-
func (b *Bridge) StartGnokeyMobileService() error {
167-
if b.serviceServer == nil {
168-
return nil
169-
}
170-
if b.gnokeyMobileService != nil {
171-
// Already started
172-
return nil
173-
}
174-
175-
// Use the default options
176-
gnokeyMobileService, err := gnokey_mobile_service.NewGnokeyMobileService(b.serviceServer)
177-
if err != nil {
178-
return err
179-
}
180-
181-
b.gnokeyMobileService = gnokeyMobileService
182-
return nil
183-
}
184-
185155
func (b *Bridge) Close() error {
186156
var errs error
187157

@@ -207,8 +177,6 @@ func (b *Bridge) Close() error {
207177
errs = multierr.Append(errs, err)
208178
}
209179

210-
// TODO: Close b.gnokeyMobileService
211-
212180
cancel()
213181
}
214182

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ require (
99
connectrpc.com/grpchealth v1.3.0
1010
connectrpc.com/grpcreflect v1.2.0
1111
github.com/gnolang/gno v0.0.0-20241029141810-12bd8da50dc1
12-
github.com/gnolang/gnokey-mobile v0.0.0-20241030095249-f1dc64684f11
1312
github.com/oklog/run v1.1.0
1413
github.com/peterbourgon/ff/v3 v3.4.0
1514
github.com/peterbourgon/unixtransport v0.0.3

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo
6161
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
6262
github.com/gnolang/gno v0.0.0-20241029141810-12bd8da50dc1 h1:MCnDuYOD9MCO5AVN0eHXs9jrLWdHq5P5rYxR1xtQ4XI=
6363
github.com/gnolang/gno v0.0.0-20241029141810-12bd8da50dc1/go.mod h1:vmnj2WrqRU9/FsHcRSXQdXzQPYYaYns/kYa+x+C0v14=
64-
github.com/gnolang/gnokey-mobile v0.0.0-20241030095249-f1dc64684f11 h1:+vcuV5AEjgMJnRwTq/PodMDWl0Zhg6KkIN7FTFC6Ad0=
65-
github.com/gnolang/gnokey-mobile v0.0.0-20241030095249-f1dc64684f11/go.mod h1:VDPyDoL7KOpjlhwmM8gO8aBwo04KbM23RbubKOGFDz8=
6664
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216 h1:GKvsK3oLWG9B1GL7WP/VqwM6C92j5tIvB844oggL9Lk=
6765
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216/go.mod h1:xJhtEL7ahjM1WJipt89gel8tHzfIl/LyMY+lCYh38d8=
6866
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=

service/api.go

+2-78
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,7 @@ func (s *gnoNativeService) SetRemote(ctx context.Context, req *connect.Request[a
3636
}
3737

3838
func (s *gnoNativeService) GetRemote(ctx context.Context, req *connect.Request[api_gen.GetRemoteRequest]) (*connect.Response[api_gen.GetRemoteResponse], error) {
39-
if s.useGnokeyMobile {
40-
// Always get the remote from the Gnokey Mobile service
41-
res, err := s.gnokeyMobileClient.GetRemote(context.Background(), req)
42-
if err != nil {
43-
return nil, err
44-
}
45-
46-
return connect.NewResponse(res.Msg), nil
47-
}
48-
49-
return connect.NewResponse(&api_gen.GetRemoteResponse{Remote: s.ClientGetRemote()}), nil
50-
}
51-
52-
func (s *gnoNativeService) ClientGetRemote() string {
53-
return s.remote
39+
return connect.NewResponse(&api_gen.GetRemoteResponse{Remote: s.remote}), nil
5440
}
5541

5642
func (s *gnoNativeService) SetChainID(ctx context.Context, req *connect.Request[api_gen.SetChainIDRequest]) (*connect.Response[api_gen.SetChainIDResponse], error) {
@@ -91,17 +77,7 @@ func ConvertKeyInfo(key crypto_keys.Info) (*api_gen.KeyInfo, error) {
9177
func (s *gnoNativeService) ListKeyInfo(ctx context.Context, req *connect.Request[api_gen.ListKeyInfoRequest]) (*connect.Response[api_gen.ListKeyInfoResponse], error) {
9278
s.logger.Debug("ListKeyInfo called")
9379

94-
if s.useGnokeyMobile {
95-
// Always get the list of keys from the Gnokey Mobile service
96-
res, err := s.gnokeyMobileClient.ListKeyInfo(context.Background(), req)
97-
if err != nil {
98-
return nil, err
99-
}
100-
101-
return connect.NewResponse(res.Msg), nil
102-
}
103-
104-
keys, err := s.ClientListKeyInfo()
80+
keys, err := s.keybase.List()
10581
if err != nil {
10682
return nil, err
10783
}
@@ -120,10 +96,6 @@ func (s *gnoNativeService) ListKeyInfo(ctx context.Context, req *connect.Request
12096
return connect.NewResponse(&api_gen.ListKeyInfoResponse{Keys: formatedKeys}), nil
12197
}
12298

123-
func (s *gnoNativeService) ClientListKeyInfo() ([]crypto_keys.Info, error) {
124-
return s.keybase.List()
125-
}
126-
12799
func (s *gnoNativeService) HasKeyByName(ctx context.Context, req *connect.Request[api_gen.HasKeyByNameRequest]) (*connect.Response[api_gen.HasKeyByNameResponse], error) {
128100
s.logger.Debug("HasKeyByName called")
129101

@@ -444,54 +416,6 @@ func (s *gnoNativeService) Call(ctx context.Context, req *connect.Request[api_ge
444416
return err
445417
}
446418

447-
if s.useGnokeyMobile {
448-
tx, err := gnoclient.NewCallTx(*cfg, msgs...)
449-
if err != nil {
450-
return err
451-
}
452-
txJSON, err := amino.MarshalJSON(tx)
453-
if err != nil {
454-
return err
455-
}
456-
457-
// Use Gnokey Mobile to sign.
458-
// Note that req.Msg.CallerAddress must be set to the desired signer. The app can get the
459-
// address using ListKeyInfo.
460-
signedTxJSON, err := s.gnokeyMobileClient.SignTx(
461-
context.Background(),
462-
connect.NewRequest(&api_gen.SignTxRequest{
463-
TxJson: string(txJSON),
464-
Address: req.Msg.CallerAddress,
465-
}),
466-
)
467-
if err != nil {
468-
return err
469-
}
470-
signedTx := &std.Tx{}
471-
if err := amino.UnmarshalJSON([]byte(signedTxJSON.Msg.SignedTxJson), signedTx); err != nil {
472-
return err
473-
}
474-
475-
// Now broadcast
476-
c, err := s.getClient(nil)
477-
if err != nil {
478-
return getGrpcError(err)
479-
}
480-
bres, err := c.BroadcastTxCommit(signedTx)
481-
if err != nil {
482-
return getGrpcError(err)
483-
}
484-
485-
if err := stream.Send(&api_gen.CallResponse{
486-
Result: bres.DeliverTx.Data,
487-
}); err != nil {
488-
s.logger.Error("Call stream.Send returned error", zap.Error(err))
489-
return err
490-
}
491-
492-
return nil
493-
}
494-
495419
signer, err := s.getSigner(req.Msg.CallerAddress)
496420
if err != nil {
497421
return err

service/config.go

-11
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ type Config struct {
2424
UdsPath string
2525
UseTcpListener bool
2626
DisableUdsListener bool
27-
UseGnokeyMobile bool
2827
}
2928

3029
type GnoNativeOption func(cfg *Config) error
@@ -328,16 +327,6 @@ var WithDisableUdsListener = func() GnoNativeOption {
328327
}
329328
}
330329

331-
// --- Gnokey Mobile options ---
332-
333-
// WithUseGnokeyMobile sets the gRPC service to use Gnokey Mobile for key-based operations.
334-
var WithUseGnokeyMobile = func() GnoNativeOption {
335-
return func(cfg *Config) error {
336-
cfg.UseGnokeyMobile = true
337-
return nil
338-
}
339-
}
340-
341330
// --- Fallback options ---
342331

343332
var defaults = []FallBackOption{

0 commit comments

Comments
 (0)