@gnolang/gnonative 0.1.2
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.
- package/.eslintrc.js +5 -0
- package/.prettierrc.js +12 -0
- package/Makefile +62 -0
- package/README.md +118 -0
- package/android/build.gradle +93 -0
- package/android/libs/gnocore-sources.jar +0 -0
- package/android/libs/gnocore.aar +0 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/land/gno/gnonative/GnonativeModule.kt +150 -0
- package/android/src/main/java/land/gno/gnonative/GnonativeView.kt +7 -0
- package/android/src/main/java/land/gno/gnonative/GoBridgeError.kt +6 -0
- package/android/src/main/java/land/gno/gnonative/JavaPromiseBlock.kt +42 -0
- package/build/Gnonative.types.d.ts +7 -0
- package/build/Gnonative.types.d.ts.map +1 -0
- package/build/Gnonative.types.js +2 -0
- package/build/Gnonative.types.js.map +1 -0
- package/build/GnonativeModule.d.ts +3 -0
- package/build/GnonativeModule.d.ts.map +1 -0
- package/build/GnonativeModule.js +5 -0
- package/build/GnonativeModule.js.map +1 -0
- package/build/GnonativeModule.web.d.ts +7 -0
- package/build/GnonativeModule.web.d.ts.map +1 -0
- package/build/GnonativeModule.web.js +12 -0
- package/build/GnonativeModule.web.js.map +1 -0
- package/build/GnonativeView.d.ts +4 -0
- package/build/GnonativeView.d.ts.map +1 -0
- package/build/GnonativeView.js +7 -0
- package/build/GnonativeView.js.map +1 -0
- package/build/GnonativeView.web.d.ts +4 -0
- package/build/GnonativeView.web.d.ts.map +1 -0
- package/build/GnonativeView.web.js +7 -0
- package/build/GnonativeView.web.js.map +1 -0
- package/build/GoBridge.d.ts +12 -0
- package/build/GoBridge.d.ts.map +1 -0
- package/build/GoBridge.js +27 -0
- package/build/GoBridge.js.map +1 -0
- package/build/grpc/client.d.ts +4 -0
- package/build/grpc/client.d.ts.map +1 -0
- package/build/grpc/client.js +12 -0
- package/build/grpc/client.js.map +1 -0
- package/build/grpc/error.d.ts +15 -0
- package/build/grpc/error.d.ts.map +1 -0
- package/build/grpc/error.js +70 -0
- package/build/grpc/error.js.map +1 -0
- package/build/grpc/transport_native.d.ts +4 -0
- package/build/grpc/transport_native.d.ts.map +1 -0
- package/build/grpc/transport_native.js +140 -0
- package/build/grpc/transport_native.js.map +1 -0
- package/build/hooks/types.d.ts +17 -0
- package/build/hooks/types.d.ts.map +1 -0
- package/build/hooks/types.js +2 -0
- package/build/hooks/types.js.map +1 -0
- package/build/hooks/use-gno.d.ts +35 -0
- package/build/hooks/use-gno.d.ts.map +1 -0
- package/build/hooks/use-gno.js +248 -0
- package/build/hooks/use-gno.js.map +1 -0
- package/build/index.d.ts +9 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +13 -0
- package/build/index.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/Frameworks/GnoCore.xcframework/Info.plist +44 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/GnoCore +0 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Headers/GnoCore.h +13 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Headers/GnoGnonative.objc.h +93 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Headers/Universe.objc.h +29 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Headers/ref.h +35 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Modules/module.modulemap +8 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Resources/Info.plist +6 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/A/GnoCore +0 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/A/Headers/GnoCore.h +13 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/A/Headers/GnoGnonative.objc.h +93 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/A/Headers/Universe.objc.h +29 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/A/Headers/ref.h +35 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/A/Modules/module.modulemap +8 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/A/Resources/Info.plist +6 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/Current/GnoCore +0 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/Current/Headers/GnoCore.h +13 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/Current/Headers/GnoGnonative.objc.h +93 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/Current/Headers/Universe.objc.h +29 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/Current/Headers/ref.h +35 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/Current/Modules/module.modulemap +8 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/Current/Resources/Info.plist +6 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/GnoCore +0 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Headers/GnoCore.h +13 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Headers/GnoGnonative.objc.h +93 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Headers/Universe.objc.h +29 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Headers/ref.h +35 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Modules/module.modulemap +8 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Resources/Info.plist +6 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/A/GnoCore +0 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/A/Headers/GnoCore.h +13 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/A/Headers/GnoGnonative.objc.h +93 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/A/Headers/Universe.objc.h +29 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/A/Headers/ref.h +35 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/A/Modules/module.modulemap +8 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/A/Resources/Info.plist +6 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/Current/GnoCore +0 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/Current/Headers/GnoCore.h +13 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/Current/Headers/GnoGnonative.objc.h +93 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/Current/Headers/Universe.objc.h +29 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/Current/Headers/ref.h +35 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/Current/Modules/module.modulemap +8 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/Current/Resources/Info.plist +6 -0
- package/ios/GnoError.swift +31 -0
- package/ios/Gnonative.podspec +28 -0
- package/ios/GnonativeModule.swift +186 -0
- package/ios/GnonativeView.swift +7 -0
- package/ios/PromiseBlock.swift +45 -0
- package/package.json +50 -0
- package/src/Gnonative.types.ts +7 -0
- package/src/GnonativeModule.ts +5 -0
- package/src/GnonativeModule.web.ts +13 -0
- package/src/GnonativeView.tsx +11 -0
- package/src/GnonativeView.web.tsx +11 -0
- package/src/GoBridge.ts +44 -0
- package/src/grpc/client.ts +14 -0
- package/src/grpc/error.ts +89 -0
- package/src/grpc/transport_native.ts +197 -0
- package/src/hooks/types.ts +19 -0
- package/src/hooks/use-gno.ts +423 -0
- package/src/index.ts +20 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GoBridge.js","sourceRoot":"","sources":["../src/GoBridge.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAYhD,MAAM,QAAQ;IACZ,UAAU;QACR,OAAO,eAAe,CAAC,UAAU,EAAE,CAAC;IACtC,CAAC;IAED,WAAW;QACT,OAAO,eAAe,CAAC,WAAW,EAAE,CAAC;IACvC,CAAC;IAED,UAAU;QACR,OAAO,eAAe,CAAC,UAAU,EAAE,CAAC;IACtC,CAAC;IAED,gBAAgB,CAAC,MAAc,EAAE,WAAmB;QAClD,OAAO,eAAe,CAAC,gBAAgB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC/D,CAAC;IAED,kBAAkB,CAAC,MAAc,EAAE,WAAmB;QACpD,OAAO,eAAe,CAAC,kBAAkB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACjE,CAAC;IAED,mBAAmB,CAAC,EAAU;QAC5B,OAAO,eAAe,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,iBAAiB,CAAC,EAAU;QAC1B,OAAO,eAAe,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;IAC/C,CAAC;CACF;AAED,MAAM,QAAQ,GAAsB,IAAI,QAAQ,EAAE,CAAC;AACnD,OAAO,EAAE,QAAQ,IAAI,QAAQ,EAAE,CAAC","sourcesContent":["import GnonativeModule from './GnonativeModule';\n\nexport interface GoBridgeInterface {\n initBridge(): Promise<void>;\n closeBridge(): Promise<void>;\n getTcpPort(): Promise<number>;\n invokeGrpcMethod(method: string, jsonMessage: string): Promise<string>;\n createStreamClient(method: string, jsonMessage: string): Promise<string>;\n streamClientReceive(id: string): Promise<string>;\n closeStreamClient(id: string): Promise<void>;\n}\n\nclass GoBridge implements GoBridgeInterface {\n initBridge(): Promise<void> {\n return GnonativeModule.initBridge();\n }\n\n closeBridge(): Promise<void> {\n return GnonativeModule.closeBridge();\n }\n\n getTcpPort(): Promise<number> {\n return GnonativeModule.getTcpPort();\n }\n\n invokeGrpcMethod(method: string, jsonMessage: string): Promise<string> {\n return GnonativeModule.invokeGrpcMethod(method, jsonMessage);\n }\n\n createStreamClient(method: string, jsonMessage: string): Promise<string> {\n return GnonativeModule.createStreamClient(method, jsonMessage);\n }\n\n streamClientReceive(id: string): Promise<string> {\n return GnonativeModule.streamClientReceive(id);\n }\n\n closeStreamClient(id: string): Promise<void> {\n return GnonativeModule.closeStreamClient(id);\n }\n}\n\nconst goBridge: GoBridgeInterface = new GoBridge();\nexport { goBridge as GoBridge };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/grpc/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kDAAkD,CAAC;AACpF,OAAO,EAAuB,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKzE,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAAC,OAAO,gBAAgB,CAAC,CAOlF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GnoNativeService } from '@buf/gnolang_gnonative.connectrpc_es/rpc_connect';
|
|
2
|
+
import { createPromiseClient } from '@connectrpc/connect';
|
|
3
|
+
import { createNativeGrpcTransport } from './transport_native';
|
|
4
|
+
// Create a GnoNativeService client
|
|
5
|
+
export function createClient(_port) {
|
|
6
|
+
const transport = createNativeGrpcTransport({
|
|
7
|
+
baseUrl: '',
|
|
8
|
+
useBinaryFormat: false,
|
|
9
|
+
});
|
|
10
|
+
return createPromiseClient(GnoNativeService, transport);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/grpc/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kDAAkD,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAiB,MAAM,qBAAqB,CAAC;AAEzE,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,mCAAmC;AACnC,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,MAAM,SAAS,GAAG,yBAAyB,CAAC;QAC1C,OAAO,EAAE,EAAE;QACX,eAAe,EAAE,KAAK;KACvB,CAAC,CAAC;IAEH,OAAO,mBAAmB,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import { GnoNativeService } from '@buf/gnolang_gnonative.connectrpc_es/rpc_connect';\nimport { createPromiseClient, PromiseClient } from '@connectrpc/connect';\n\nimport { createNativeGrpcTransport } from './transport_native';\n\n// Create a GnoNativeService client\nexport function createClient(_port: number): PromiseClient<typeof GnoNativeService> {\n const transport = createNativeGrpcTransport({\n baseUrl: '',\n useBinaryFormat: false,\n });\n\n return createPromiseClient(GnoNativeService, transport);\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ErrCode } from '@buf/gnolang_gnonative.bufbuild_es/rpc_pb';
|
|
2
|
+
import { Code, ConnectError } from '@connectrpc/connect';
|
|
3
|
+
declare class GRPCError extends Error {
|
|
4
|
+
GrpcCode: Code;
|
|
5
|
+
error: ConnectError;
|
|
6
|
+
constructor(e: ConnectError | null | undefined);
|
|
7
|
+
private extractErrCode;
|
|
8
|
+
private errCodes;
|
|
9
|
+
errCode(): ErrCode;
|
|
10
|
+
grpcErrorCode(): Code;
|
|
11
|
+
toJSON(): any;
|
|
12
|
+
hasErrCode(error: ErrCode): boolean;
|
|
13
|
+
}
|
|
14
|
+
export { GRPCError };
|
|
15
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/grpc/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,2CAA2C,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEzD,cAAM,SAAU,SAAQ,KAAK;IACpB,QAAQ,EAAE,IAAI,CAAC;IAEf,KAAK,EAAE,YAAY,CAAC;gBAEf,CAAC,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS;IAc9C,OAAO,CAAC,cAAc;IAetB,OAAO,CAAC,QAAQ;IAmBT,OAAO,IAAI,OAAO;IAUlB,aAAa,IAAI,IAAI;IAIrB,MAAM,IAAI,GAAG;IAQb,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;CAQ3C;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ErrCode } from '@buf/gnolang_gnonative.bufbuild_es/rpc_pb';
|
|
2
|
+
import { Code, ConnectError } from '@connectrpc/connect';
|
|
3
|
+
class GRPCError extends Error {
|
|
4
|
+
GrpcCode;
|
|
5
|
+
error;
|
|
6
|
+
constructor(e) {
|
|
7
|
+
if (!e) {
|
|
8
|
+
// this should not happen, but should not break the app either.
|
|
9
|
+
// instead simply create a empty error and warn about this
|
|
10
|
+
console.warn(`GRPCError: (${e}) grpc error provided, empty error returned`);
|
|
11
|
+
e = new ConnectError('');
|
|
12
|
+
}
|
|
13
|
+
super(e.rawMessage);
|
|
14
|
+
this.error = e;
|
|
15
|
+
this.GrpcCode = e.code;
|
|
16
|
+
}
|
|
17
|
+
extractErrCode(match) {
|
|
18
|
+
if (match === null || match.length < 2) {
|
|
19
|
+
return ErrCode.Undefined;
|
|
20
|
+
}
|
|
21
|
+
const code = parseInt(match[1]);
|
|
22
|
+
if (typeof code !== 'number') {
|
|
23
|
+
return ErrCode.Undefined;
|
|
24
|
+
}
|
|
25
|
+
return code;
|
|
26
|
+
}
|
|
27
|
+
// errCodes parses the error message formatted like `ErrType(#ErrNumber): WrappedErrType(#WrappedErrNumber)`
|
|
28
|
+
// and returns the corresponding ErrCodes or [ErrCode.Undefined] if some errors occur.
|
|
29
|
+
errCodes() {
|
|
30
|
+
const errCodes = [];
|
|
31
|
+
if (this.message === '') {
|
|
32
|
+
return [ErrCode.Undefined];
|
|
33
|
+
}
|
|
34
|
+
const matches = this.message.matchAll(/\w+\(#(\d+)\)/g);
|
|
35
|
+
for (const match of matches) {
|
|
36
|
+
const code = this.extractErrCode(match);
|
|
37
|
+
errCodes.push(code);
|
|
38
|
+
}
|
|
39
|
+
return errCodes;
|
|
40
|
+
}
|
|
41
|
+
// errCode parses the error message formatted like `ErrType(#ErrNumber): WrappedErrType(#WrappedErrNumber)`
|
|
42
|
+
// and returns the corresponding parent ErrCode or ErrCode.Undefined if some errors occur.
|
|
43
|
+
errCode() {
|
|
44
|
+
if (this.message === '') {
|
|
45
|
+
return ErrCode.Undefined;
|
|
46
|
+
}
|
|
47
|
+
const match = this.message.match(/\w+\(#(\d+)\)/);
|
|
48
|
+
return this.extractErrCode(match);
|
|
49
|
+
}
|
|
50
|
+
grpcErrorCode() {
|
|
51
|
+
return this.GrpcCode;
|
|
52
|
+
}
|
|
53
|
+
toJSON() {
|
|
54
|
+
return {
|
|
55
|
+
message: this.message,
|
|
56
|
+
grpcErrorCode: Code[this.GrpcCode],
|
|
57
|
+
errorCode: ErrCode[this.errCode()],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
hasErrCode(error) {
|
|
61
|
+
for (const err of this.errCodes()) {
|
|
62
|
+
if (err === error) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export { GRPCError };
|
|
70
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/grpc/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,2CAA2C,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,SAAU,SAAQ,KAAK;IACpB,QAAQ,CAAO;IAEf,KAAK,CAAe;IAE3B,YAAY,CAAkC;QAC5C,IAAI,CAAC,CAAC,EAAE,CAAC;YACP,+DAA+D;YAC/D,0DAA0D;YAC1D,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,6CAA6C,CAAC,CAAC;YAC5E,CAAC,GAAG,IAAI,YAAY,CAAC,EAAE,CAAC,CAAC;QAC3B,CAAC;QAED,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QAEpB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC;IACzB,CAAC;IAEO,cAAc,CAAC,KAA8B;QACnD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvC,OAAO,OAAO,CAAC,SAAS,CAAC;QAC3B,CAAC;QAED,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,CA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M,GAAG,IAAI,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;YAClC,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC;gBAClB,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,OAAO,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import { ErrCode } from '@buf/gnolang_gnonative.bufbuild_es/rpc_pb';\nimport { Code, ConnectError } from '@connectrpc/connect';\n\nclass GRPCError extends Error {\n public GrpcCode: Code;\n\n public error: ConnectError;\n\n constructor(e: ConnectError | null | undefined) {\n if (!e) {\n // this should not happen, but should not break the app either.\n // instead simply create a empty error and warn about this\n console.warn(`GRPCError: (${e}) grpc error provided, empty error returned`);\n e = new ConnectError('');\n }\n\n super(e.rawMessage);\n\n this.error = e;\n this.GrpcCode = e.code;\n }\n\n private extractErrCode(match: RegExpMatchArray | null) {\n if (match === null || match.length < 2) {\n return ErrCode.Undefined;\n }\n\n const code = parseInt(match[1]);\n if (typeof code !== 'number') {\n return ErrCode.Undefined;\n }\n\n return code;\n }\n\n // errCodes parses the error message formatted like `ErrType(#ErrNumber): WrappedErrType(#WrappedErrNumber)`\n // and returns the corresponding ErrCodes or [ErrCode.Undefined] if some errors occur.\n private errCodes(): ErrCode[] {\n const errCodes: ErrCode[] = [];\n\n if (this.message === '') {\n return [ErrCode.Undefined];\n }\n\n const matches = this.message.matchAll(/\\w+\\(#(\\d+)\\)/g);\n\n for (const match of matches) {\n const code = this.extractErrCode(match);\n errCodes.push(code);\n }\n\n return errCodes;\n }\n\n // errCode parses the error message formatted like `ErrType(#ErrNumber): WrappedErrType(#WrappedErrNumber)`\n // and returns the corresponding parent ErrCode or ErrCode.Undefined if some errors occur.\n public errCode(): ErrCode {\n if (this.message === '') {\n return ErrCode.Undefined;\n }\n\n const match = this.message.match(/\\w+\\(#(\\d+)\\)/);\n\n return this.extractErrCode(match);\n }\n\n public grpcErrorCode(): Code {\n return this.GrpcCode;\n }\n\n public toJSON(): any {\n return {\n message: this.message,\n grpcErrorCode: Code[this.GrpcCode],\n errorCode: ErrCode[this.errCode()],\n };\n }\n\n public hasErrCode(error: ErrCode): boolean {\n for (const err of this.errCodes()) {\n if (err === error) {\n return true;\n }\n }\n return false;\n }\n}\n\nexport { GRPCError };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport_native.d.ts","sourceRoot":"","sources":["../../src/grpc/transport_native.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,SAAS,EAGV,MAAM,qBAAqB,CAAC;AAS7B,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAiBlE,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,uBAAuB,GAAG,SAAS,CAkKrF"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { MethodKind } from '@bufbuild/protobuf';
|
|
2
|
+
import { createContextValues } from '@connectrpc/connect';
|
|
3
|
+
import { createClientMethodSerializers, createMethodUrl, runStreamingCall, runUnaryCall, } from '@connectrpc/connect/protocol';
|
|
4
|
+
import { requestHeader } from '@connectrpc/connect/protocol-grpc-web';
|
|
5
|
+
import { CodedError } from 'expo-modules-core';
|
|
6
|
+
import { decode } from 'js-base64';
|
|
7
|
+
import { GoBridge } from '../GoBridge';
|
|
8
|
+
function base64ToBytes(base64) {
|
|
9
|
+
const binString = decode(base64);
|
|
10
|
+
const bytes = new Uint8Array(binString.length);
|
|
11
|
+
for (let i = 0; i < binString.length; i++) {
|
|
12
|
+
bytes[i] = binString.charCodeAt(i);
|
|
13
|
+
}
|
|
14
|
+
return bytes;
|
|
15
|
+
}
|
|
16
|
+
export function createNativeGrpcTransport(options) {
|
|
17
|
+
const useBinaryFormat = options.useBinaryFormat ?? true;
|
|
18
|
+
return {
|
|
19
|
+
async unary(service, method, signal, timeoutMs, header, message, contextValues) {
|
|
20
|
+
const { parse } = createClientMethodSerializers(method, useBinaryFormat, options.jsonOptions, options.binaryOptions);
|
|
21
|
+
return await runUnaryCall({
|
|
22
|
+
signal,
|
|
23
|
+
interceptors: options.interceptors,
|
|
24
|
+
req: {
|
|
25
|
+
stream: false,
|
|
26
|
+
service,
|
|
27
|
+
method,
|
|
28
|
+
url: createMethodUrl(options.baseUrl, service, method),
|
|
29
|
+
init: {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
mode: 'cors',
|
|
32
|
+
},
|
|
33
|
+
header: new Headers(),
|
|
34
|
+
contextValues: contextValues ?? createContextValues(),
|
|
35
|
+
message,
|
|
36
|
+
},
|
|
37
|
+
next: async (req) => {
|
|
38
|
+
try {
|
|
39
|
+
const res = await GoBridge.invokeGrpcMethod(req.method.name, req.message.toJsonString());
|
|
40
|
+
const header = new Headers();
|
|
41
|
+
const trailer = new Headers();
|
|
42
|
+
const data = base64ToBytes(res);
|
|
43
|
+
const message = parse(data);
|
|
44
|
+
return {
|
|
45
|
+
stream: false,
|
|
46
|
+
service,
|
|
47
|
+
method,
|
|
48
|
+
header,
|
|
49
|
+
message,
|
|
50
|
+
trailer,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
console.log('next: unary call error:', e);
|
|
55
|
+
throw e;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
async stream(service, method, signal, timeoutMs, header, input, contextValues) {
|
|
61
|
+
const { parse } = createClientMethodSerializers(method, useBinaryFormat, options.jsonOptions, options.binaryOptions);
|
|
62
|
+
async function createRequestBody(input) {
|
|
63
|
+
if (method.kind !== MethodKind.ServerStreaming) {
|
|
64
|
+
throw 'The fetch API does not support streaming request bodies';
|
|
65
|
+
}
|
|
66
|
+
const r = await input[Symbol.asyncIterator]().next();
|
|
67
|
+
if (r.done === true) {
|
|
68
|
+
throw 'missing request message';
|
|
69
|
+
}
|
|
70
|
+
return r.value.toJsonString();
|
|
71
|
+
}
|
|
72
|
+
return await runStreamingCall({
|
|
73
|
+
interceptors: options.interceptors,
|
|
74
|
+
timeoutMs,
|
|
75
|
+
signal,
|
|
76
|
+
req: {
|
|
77
|
+
stream: true,
|
|
78
|
+
service,
|
|
79
|
+
method,
|
|
80
|
+
url: createMethodUrl(options.baseUrl, service, method),
|
|
81
|
+
init: {
|
|
82
|
+
method: 'POST',
|
|
83
|
+
credentials: options.credentials ?? 'same-origin',
|
|
84
|
+
mode: 'cors',
|
|
85
|
+
},
|
|
86
|
+
header: requestHeader(useBinaryFormat, timeoutMs, header, false),
|
|
87
|
+
message: input,
|
|
88
|
+
contextValues: contextValues ?? createContextValues(),
|
|
89
|
+
},
|
|
90
|
+
next: async (req) => {
|
|
91
|
+
const header = new Headers();
|
|
92
|
+
const trailer = new Headers();
|
|
93
|
+
const body = await createRequestBody(req.message);
|
|
94
|
+
let streamId;
|
|
95
|
+
try {
|
|
96
|
+
streamId = await GoBridge.createStreamClient(req.method.name, body);
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
console.log('createStreamClient error:', e);
|
|
100
|
+
throw e;
|
|
101
|
+
}
|
|
102
|
+
const generator = {
|
|
103
|
+
async *[Symbol.asyncIterator]() {
|
|
104
|
+
for (;;) {
|
|
105
|
+
try {
|
|
106
|
+
const res = await GoBridge.streamClientReceive(streamId);
|
|
107
|
+
const data = base64ToBytes(res);
|
|
108
|
+
const message = parse(data);
|
|
109
|
+
yield message;
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
// close the stream
|
|
113
|
+
try {
|
|
114
|
+
await GoBridge.closeStreamClient(streamId);
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
console.log('closeStreamClient error:', e);
|
|
118
|
+
}
|
|
119
|
+
if (!(e instanceof CodedError && e.message === 'EOF')) {
|
|
120
|
+
console.log('streamClientReceive error:', e);
|
|
121
|
+
throw e;
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
const res = {
|
|
129
|
+
...req,
|
|
130
|
+
header,
|
|
131
|
+
trailer,
|
|
132
|
+
message: generator,
|
|
133
|
+
};
|
|
134
|
+
return res;
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=transport_native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport_native.js","sourceRoot":"","sources":["../../src/grpc/transport_native.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAQzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACL,6BAA6B,EAC7B,eAAe,EACf,gBAAgB,EAChB,YAAY,GACb,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,SAAS,aAAa,CAAC,MAAc;IACnC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAE/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,KAAK,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,OAAgC;IACxE,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,IAAI,CAAC;IACxD,O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C,YAAY,UAAU,IAAI,CAAC,CAAC,OAAO,KAAK,KAAK,CAAC,EAAE,CAAC;wCACtD,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,CAAC,CAAC,CAAC;wCAC7C,MAAM,CAAC,CAAC;oCACV,CAAC;oCACD,MAAM;gCACR,CAAC;4BACH,CAAC;wBACH,CAAC;qBACF,CAAC;oBAEF,MAAM,GAAG,GAAyB;wBAChC,GAAG,GAAG;wBACN,MAAM;wBACN,OAAO;wBACP,OAAO,EAAE,SAAS;qBACnB,CAAC;oBACF,OAAO,GAAG,CAAC;gBACb,CAAC;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { AnyMessage, MethodInfo, PartialMessage, ServiceType } from '@bufbuild/protobuf';\nimport { Message, MethodKind } from '@bufbuild/protobuf';\nimport type {\n ContextValues,\n StreamResponse,\n Transport,\n UnaryRequest,\n UnaryResponse,\n} from '@connectrpc/connect';\nimport { createContextValues } from '@connectrpc/connect';\nimport {\n createClientMethodSerializers,\n createMethodUrl,\n runStreamingCall,\n runUnaryCall,\n} from '@connectrpc/connect/protocol';\nimport { requestHeader } from '@connectrpc/connect/protocol-grpc-web';\nimport { GrpcWebTransportOptions } from '@connectrpc/connect-web';\nimport { CodedError } from 'expo-modules-core';\nimport { decode } from 'js-base64';\n\nimport { GoBridge } from '../GoBridge';\n\nfunction base64ToBytes(base64: string): Uint8Array {\n const binString = decode(base64);\n const bytes = new Uint8Array(binString.length);\n\n for (let i = 0; i < binString.length; i++) {\n bytes[i] = binString.charCodeAt(i);\n }\n\n return bytes;\n}\n\nexport function createNativeGrpcTransport(options: GrpcWebTransportOptions): Transport {\n const useBinaryFormat = options.useBinaryFormat ?? true;\n return {\n async unary<I extends Message<I> = AnyMessage, O extends Message<O> = AnyMessage>(\n service: ServiceType,\n method: MethodInfo<I, O>,\n signal: AbortSignal | undefined,\n timeoutMs: number | undefined,\n header: HeadersInit | undefined,\n message: PartialMessage<I>,\n contextValues?: ContextValues,\n ): Promise<UnaryResponse<I, O>> {\n const { parse } = createClientMethodSerializers(\n method,\n useBinaryFormat,\n options.jsonOptions,\n options.binaryOptions,\n );\n\n return await runUnaryCall<I, O>({\n signal,\n interceptors: options.interceptors,\n req: {\n stream: false,\n service,\n method,\n url: createMethodUrl(options.baseUrl, service, method),\n init: {\n method: 'POST',\n mode: 'cors',\n },\n header: new Headers(),\n contextValues: contextValues ?? createContextValues(),\n message,\n },\n next: async (req: UnaryRequest<I, O>): Promise<UnaryResponse<I, O>> => {\n try {\n const res = await GoBridge.invokeGrpcMethod(\n req.method.name,\n req.message.toJsonString(),\n );\n\n const header: Headers | undefined = new Headers();\n const trailer: Headers | undefined = new Headers();\n\n const data = base64ToBytes(res);\n const message = parse(data);\n\n return <UnaryResponse<I, O>>{\n stream: false,\n service,\n method,\n header,\n message,\n trailer,\n };\n } catch (e) {\n console.log('next: unary call error:', e);\n throw e;\n }\n },\n });\n },\n\n async stream<I extends Message<I> = AnyMessage, O extends Message<O> = AnyMessage>(\n service: ServiceType,\n method: MethodInfo<I, O>,\n signal: AbortSignal | undefined,\n timeoutMs: number | undefined,\n header: HeadersInit | undefined,\n input: AsyncIterable<PartialMessage<I>>,\n contextValues?: ContextValues,\n ): Promise<StreamResponse<I, O>> {\n const { parse } = createClientMethodSerializers(\n method,\n useBinaryFormat,\n options.jsonOptions,\n options.binaryOptions,\n );\n\n async function createRequestBody(input: AsyncIterable<I>): Promise<string> {\n if (method.kind !== MethodKind.ServerStreaming) {\n throw 'The fetch API does not support streaming request bodies';\n }\n\n const r = await input[Symbol.asyncIterator]().next();\n if (r.done === true) {\n throw 'missing request message';\n }\n\n return r.value.toJsonString();\n }\n\n return await runStreamingCall<I, O>({\n interceptors: options.interceptors,\n timeoutMs,\n signal,\n req: {\n stream: true,\n service,\n method,\n url: createMethodUrl(options.baseUrl, service, method),\n init: {\n method: 'POST',\n credentials: options.credentials ?? 'same-origin',\n mode: 'cors',\n },\n header: requestHeader(useBinaryFormat, timeoutMs, header, false),\n message: input,\n contextValues: contextValues ?? createContextValues(),\n },\n next: async req => {\n const header: Headers | undefined = new Headers();\n const trailer: Headers | undefined = new Headers();\n\n const body = await createRequestBody(req.message);\n\n let streamId: string;\n try {\n streamId = await GoBridge.createStreamClient(req.method.name, body);\n } catch (e) {\n console.log('createStreamClient error:', e);\n throw e;\n }\n\n const generator = {\n async *[Symbol.asyncIterator]() {\n for (; ;) {\n try {\n const res = await GoBridge.streamClientReceive(streamId);\n const data = base64ToBytes(res);\n const message = parse(data);\n yield message;\n } catch (e) {\n // close the stream\n try {\n await GoBridge.closeStreamClient(streamId);\n } catch (e) {\n console.log('closeStreamClient error:', e);\n }\n\n if (!(e instanceof CodedError && e.message === 'EOF')) {\n console.log('streamClientReceive error:', e);\n throw e;\n }\n break;\n }\n }\n },\n };\n\n const res: StreamResponse<I, O> = {\n ...req,\n header,\n trailer,\n message: generator,\n };\n return res;\n },\n });\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { KeyInfo } from '@buf/gnolang_gnonative.bufbuild_es/gnonativetypes_pb';
|
|
2
|
+
export type GnoConfig = {
|
|
3
|
+
Remote: string;
|
|
4
|
+
ChainID: string;
|
|
5
|
+
KeyName: string;
|
|
6
|
+
Password: string;
|
|
7
|
+
GasFee: string;
|
|
8
|
+
GasWanted: number;
|
|
9
|
+
Mnemonic: string;
|
|
10
|
+
};
|
|
11
|
+
export type NetworkMetainfo = {
|
|
12
|
+
chainId: string;
|
|
13
|
+
chainName: string;
|
|
14
|
+
gnoAddress: string;
|
|
15
|
+
};
|
|
16
|
+
export type GnoAccount = KeyInfo;
|
|
17
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/hooks/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sDAAsD,CAAC;AAE/E,MAAM,MAAM,SAAS,GAAG;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/hooks/types.ts"],"names":[],"mappings":"","sourcesContent":["import { KeyInfo } from '@buf/gnolang_gnonative.bufbuild_es/gnonativetypes_pb';\n\nexport type GnoConfig = {\n Remote: string;\n ChainID: string;\n KeyName: string;\n Password: string;\n GasFee: string;\n GasWanted: number;\n Mnemonic: string;\n};\n\nexport type NetworkMetainfo = {\n chainId: string;\n chainName: string;\n gnoAddress: string;\n};\n\nexport type GnoAccount = KeyInfo;\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CallResponse, DeleteAccountResponse, GetActiveAccountResponse, HelloStreamResponse, QueryAccountResponse, QueryResponse, SelectAccountResponse, SendResponse, SetChainIDResponse, SetPasswordResponse, SetRemoteResponse } from '@buf/gnolang_gnonative.bufbuild_es/gnonativetypes_pb';
|
|
2
|
+
import { GnoAccount } from './types';
|
|
3
|
+
export interface GnoResponse {
|
|
4
|
+
setRemote: (remote: string) => Promise<SetRemoteResponse>;
|
|
5
|
+
getRemote: () => Promise<string>;
|
|
6
|
+
setChainID: (chainId: string) => Promise<SetChainIDResponse>;
|
|
7
|
+
getChainID: () => Promise<string>;
|
|
8
|
+
createAccount: (nameOrBech32: string, mnemonic: string, password: string) => Promise<GnoAccount | undefined>;
|
|
9
|
+
generateRecoveryPhrase: () => Promise<string>;
|
|
10
|
+
listKeyInfo: () => Promise<GnoAccount[]>;
|
|
11
|
+
hasKeyByName: (name: string) => Promise<boolean>;
|
|
12
|
+
hasKeyByAddress: (address: Uint8Array) => Promise<boolean>;
|
|
13
|
+
hasKeyByNameOrAddress: (nameOrBech32: string) => Promise<boolean>;
|
|
14
|
+
getKeyInfoByName: (name: string) => Promise<GnoAccount | undefined>;
|
|
15
|
+
getKeyInfoByAddress: (address: Uint8Array) => Promise<GnoAccount | undefined>;
|
|
16
|
+
getKeyInfoByNameOrAddress: (nameOrBech32: string) => Promise<GnoAccount | undefined>;
|
|
17
|
+
selectAccount: (nameOrBech32: string) => Promise<SelectAccountResponse>;
|
|
18
|
+
setPassword: (password: string) => Promise<SetPasswordResponse>;
|
|
19
|
+
getActiveAccount: () => Promise<GetActiveAccountResponse>;
|
|
20
|
+
queryAccount: (address: Uint8Array) => Promise<QueryAccountResponse>;
|
|
21
|
+
deleteAccount: (nameOrBech32: string, password: string | undefined, skipPassword: boolean) => Promise<DeleteAccountResponse>;
|
|
22
|
+
query: (path: string, data: Uint8Array) => Promise<QueryResponse>;
|
|
23
|
+
render: (packagePath: string, args: string) => Promise<string>;
|
|
24
|
+
qEval: (packagePath: string, expression: string) => Promise<string>;
|
|
25
|
+
call: (packagePath: string, fnc: string, args: Array<string>, gasFee: string, gasWanted: number, send?: string, memo?: string) => Promise<AsyncIterable<CallResponse>>;
|
|
26
|
+
send: (toAddress: Uint8Array, send: string, gasFee: string, gasWanted: number, memo?: string) => Promise<AsyncIterable<SendResponse>>;
|
|
27
|
+
addressToBech32: (address: Uint8Array) => Promise<string>;
|
|
28
|
+
addressFromBech32: (bech32Address: string) => Promise<Uint8Array>;
|
|
29
|
+
closeBridge: () => Promise<void>;
|
|
30
|
+
initBridge: () => Promise<void>;
|
|
31
|
+
hello: (name: string) => Promise<string>;
|
|
32
|
+
helloStream: (name: string) => Promise<AsyncIterable<HelloStreamResponse>>;
|
|
33
|
+
}
|
|
34
|
+
export declare const useGno: () => GnoResponse;
|
|
35
|
+
//# sourceMappingURL=use-gno.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-gno.d.ts","sourceRoot":"","sources":["../../src/hooks/use-gno.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,YAAY,EAGZ,qBAAqB,EAGrB,wBAAwB,EAUxB,mBAAmB,EAMnB,oBAAoB,EAEpB,aAAa,EAGb,qBAAqB,EAErB,YAAY,EAEZ,kBAAkB,EAElB,mBAAmB,EAEnB,iBAAiB,EAClB,MAAM,sDAAsD,CAAC;AAI9D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAIrC,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC1D,SAAS,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IACjC,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC7D,UAAU,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,aAAa,EAAE,CACb,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,KACb,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IACrC,sBAAsB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9C,WAAW,EAAE,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IACzC,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACjD,eAAe,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3D,qBAAqB,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,O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,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,MAAM,KACV,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC;IAC1C,IAAI,EAAE,CACJ,SAAS,EAAE,UAAU,EACrB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,MAAM,KACV,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC;IAC1C,eAAe,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1D,iBAAiB,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAClE,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACzC,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,mBAAmB,CAAC,CAAC,CAAC;CAC5E;AAKD,eAAO,MAAM,MAAM,QAAO,WA4TzB,CAAC"}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { AddressFromBech32Request, AddressToBech32Request, CallRequest, CreateAccountRequest, DeleteAccountRequest, GenerateRecoveryPhraseRequest, GetActiveAccountRequest, GetChainIDRequest, GetKeyInfoByAddressRequest, GetKeyInfoByNameOrAddressRequest, GetKeyInfoByNameRequest, GetRemoteRequest, HasKeyByAddressRequest, HasKeyByNameOrAddressRequest, HasKeyByNameRequest, HelloRequest, ListKeyInfoRequest, MsgCall, MsgSend, QEvalRequest, QueryAccountRequest, QueryRequest, RenderRequest, SelectAccountRequest, SendRequest, SetChainIDRequest, SetPasswordRequest, SetRemoteRequest, } from '@buf/gnolang_gnonative.bufbuild_es/gnonativetypes_pb';
|
|
2
|
+
import { GoBridge } from '../GoBridge';
|
|
3
|
+
import * as Grpc from '../grpc/client';
|
|
4
|
+
let clientInstance = undefined;
|
|
5
|
+
let bridgeInstance = false;
|
|
6
|
+
export const useGno = () => {
|
|
7
|
+
const getClient = async () => {
|
|
8
|
+
if (!bridgeInstance) {
|
|
9
|
+
await initBridge();
|
|
10
|
+
}
|
|
11
|
+
if (clientInstance)
|
|
12
|
+
return clientInstance;
|
|
13
|
+
console.log('Creating GRPC client instance...');
|
|
14
|
+
const port = await GoBridge.getTcpPort();
|
|
15
|
+
clientInstance = Grpc.createClient(port);
|
|
16
|
+
console.log('Creating GRPC client instance... done.');
|
|
17
|
+
// Set the initial configuration where it's different from the default.
|
|
18
|
+
await clientInstance.setRemote(new SetRemoteRequest({ remote: 'gno.land:26657' }));
|
|
19
|
+
await clientInstance.setChainID(new SetChainIDRequest({ chainId: 'portal-loop' }));
|
|
20
|
+
return clientInstance;
|
|
21
|
+
};
|
|
22
|
+
const closeBridge = async () => {
|
|
23
|
+
if (bridgeInstance) {
|
|
24
|
+
console.log('Closing bridge...');
|
|
25
|
+
await GoBridge.closeBridge();
|
|
26
|
+
console.log('Bridge closed.');
|
|
27
|
+
bridgeInstance = false;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const initBridge = async () => {
|
|
31
|
+
if (!bridgeInstance) {
|
|
32
|
+
console.log('Initializing bridge...');
|
|
33
|
+
await GoBridge.initBridge();
|
|
34
|
+
console.log('Bridge initialized.');
|
|
35
|
+
bridgeInstance = true;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const setRemote = async (remote) => {
|
|
39
|
+
const client = await getClient();
|
|
40
|
+
const response = await client.setRemote(new SetRemoteRequest({ remote }));
|
|
41
|
+
return response;
|
|
42
|
+
};
|
|
43
|
+
const getRemote = async () => {
|
|
44
|
+
const client = await getClient();
|
|
45
|
+
const response = await client.getRemote(new GetRemoteRequest());
|
|
46
|
+
return response.remote;
|
|
47
|
+
};
|
|
48
|
+
const setChainID = async (chainId) => {
|
|
49
|
+
const client = await getClient();
|
|
50
|
+
const response = await client.setChainID(new SetChainIDRequest({ chainId }));
|
|
51
|
+
return response;
|
|
52
|
+
};
|
|
53
|
+
const getChainID = async () => {
|
|
54
|
+
const client = await getClient();
|
|
55
|
+
const response = await client.getChainID(new GetChainIDRequest());
|
|
56
|
+
return response.chainId;
|
|
57
|
+
};
|
|
58
|
+
const createAccount = async (nameOrBech32, mnemonic, password) => {
|
|
59
|
+
const client = await getClient();
|
|
60
|
+
const reponse = await client.createAccount(new CreateAccountRequest({
|
|
61
|
+
nameOrBech32,
|
|
62
|
+
mnemonic,
|
|
63
|
+
password,
|
|
64
|
+
}));
|
|
65
|
+
return reponse.key;
|
|
66
|
+
};
|
|
67
|
+
const generateRecoveryPhrase = async () => {
|
|
68
|
+
const client = await getClient();
|
|
69
|
+
const response = await client.generateRecoveryPhrase(new GenerateRecoveryPhraseRequest());
|
|
70
|
+
return response.phrase;
|
|
71
|
+
};
|
|
72
|
+
const hasKeyByName = async (name) => {
|
|
73
|
+
const client = await getClient();
|
|
74
|
+
const response = await client.hasKeyByName(new HasKeyByNameRequest({ name }));
|
|
75
|
+
return response.has;
|
|
76
|
+
};
|
|
77
|
+
const hasKeyByAddress = async (address) => {
|
|
78
|
+
const client = await getClient();
|
|
79
|
+
const response = await client.hasKeyByAddress(new HasKeyByAddressRequest({ address }));
|
|
80
|
+
return response.has;
|
|
81
|
+
};
|
|
82
|
+
const hasKeyByNameOrAddress = async (nameOrBech32) => {
|
|
83
|
+
const client = await getClient();
|
|
84
|
+
const response = await client.hasKeyByNameOrAddress(new HasKeyByNameOrAddressRequest({ nameOrBech32 }));
|
|
85
|
+
return response.has;
|
|
86
|
+
};
|
|
87
|
+
const getKeyInfoByName = async (name) => {
|
|
88
|
+
const client = await getClient();
|
|
89
|
+
const response = await client.getKeyInfoByName(new GetKeyInfoByNameRequest({ name }));
|
|
90
|
+
return response.key;
|
|
91
|
+
};
|
|
92
|
+
const getKeyInfoByAddress = async (address) => {
|
|
93
|
+
const client = await getClient();
|
|
94
|
+
const response = await client.getKeyInfoByAddress(new GetKeyInfoByAddressRequest({ address }));
|
|
95
|
+
return response.key;
|
|
96
|
+
};
|
|
97
|
+
const getKeyInfoByNameOrAddress = async (nameOrBech32) => {
|
|
98
|
+
const client = await getClient();
|
|
99
|
+
const response = await client.getKeyInfoByNameOrAddress(new GetKeyInfoByNameOrAddressRequest({ nameOrBech32 }));
|
|
100
|
+
return response.key;
|
|
101
|
+
};
|
|
102
|
+
const listKeyInfo = async () => {
|
|
103
|
+
const client = await getClient();
|
|
104
|
+
const response = await client.listKeyInfo(new ListKeyInfoRequest());
|
|
105
|
+
return response.keys;
|
|
106
|
+
};
|
|
107
|
+
const selectAccount = async (nameOrBech32) => {
|
|
108
|
+
const client = await getClient();
|
|
109
|
+
const response = await client.selectAccount(new SelectAccountRequest({
|
|
110
|
+
nameOrBech32,
|
|
111
|
+
}));
|
|
112
|
+
return response;
|
|
113
|
+
};
|
|
114
|
+
const setPassword = async (password) => {
|
|
115
|
+
const client = await getClient();
|
|
116
|
+
const response = await client.setPassword(new SetPasswordRequest({ password }));
|
|
117
|
+
return response;
|
|
118
|
+
};
|
|
119
|
+
const getActiveAccount = async () => {
|
|
120
|
+
const client = await getClient();
|
|
121
|
+
const response = await client.getActiveAccount(new GetActiveAccountRequest());
|
|
122
|
+
return response;
|
|
123
|
+
};
|
|
124
|
+
const queryAccount = async (address) => {
|
|
125
|
+
const client = await getClient();
|
|
126
|
+
const reponse = await client.queryAccount(new QueryAccountRequest({ address }));
|
|
127
|
+
return reponse;
|
|
128
|
+
};
|
|
129
|
+
const deleteAccount = async (nameOrBech32, password, skipPassword) => {
|
|
130
|
+
const client = await getClient();
|
|
131
|
+
const response = await client.deleteAccount(new DeleteAccountRequest({
|
|
132
|
+
nameOrBech32,
|
|
133
|
+
password,
|
|
134
|
+
skipPassword,
|
|
135
|
+
}));
|
|
136
|
+
return response;
|
|
137
|
+
};
|
|
138
|
+
const query = async (path, data) => {
|
|
139
|
+
const client = await getClient();
|
|
140
|
+
const reponse = await client.query(new QueryRequest({
|
|
141
|
+
path,
|
|
142
|
+
data,
|
|
143
|
+
}));
|
|
144
|
+
return reponse;
|
|
145
|
+
};
|
|
146
|
+
const render = async (packagePath, args) => {
|
|
147
|
+
const client = await getClient();
|
|
148
|
+
const reponse = await client.render(new RenderRequest({
|
|
149
|
+
packagePath,
|
|
150
|
+
args,
|
|
151
|
+
}));
|
|
152
|
+
return reponse.result;
|
|
153
|
+
};
|
|
154
|
+
const qEval = async (packagePath, expression) => {
|
|
155
|
+
const client = await getClient();
|
|
156
|
+
const reponse = await client.qEval(new QEvalRequest({
|
|
157
|
+
packagePath,
|
|
158
|
+
expression,
|
|
159
|
+
}));
|
|
160
|
+
return reponse.result;
|
|
161
|
+
};
|
|
162
|
+
const call = async (packagePath, fnc, args, gasFee, gasWanted, send, memo) => {
|
|
163
|
+
const client = await getClient();
|
|
164
|
+
const reponse = client.call(new CallRequest({
|
|
165
|
+
gasFee,
|
|
166
|
+
gasWanted: BigInt(gasWanted),
|
|
167
|
+
memo,
|
|
168
|
+
msgs: [
|
|
169
|
+
new MsgCall({
|
|
170
|
+
packagePath,
|
|
171
|
+
fnc,
|
|
172
|
+
args,
|
|
173
|
+
send,
|
|
174
|
+
}),
|
|
175
|
+
],
|
|
176
|
+
}));
|
|
177
|
+
return reponse;
|
|
178
|
+
};
|
|
179
|
+
const send = async (toAddress, send, gasFee, gasWanted, memo) => {
|
|
180
|
+
const client = await getClient();
|
|
181
|
+
const reponse = client.send(new SendRequest({
|
|
182
|
+
gasFee,
|
|
183
|
+
gasWanted: BigInt(gasWanted),
|
|
184
|
+
memo,
|
|
185
|
+
msgs: [
|
|
186
|
+
new MsgSend({
|
|
187
|
+
toAddress,
|
|
188
|
+
send,
|
|
189
|
+
}),
|
|
190
|
+
],
|
|
191
|
+
}));
|
|
192
|
+
return reponse;
|
|
193
|
+
};
|
|
194
|
+
const addressToBech32 = async (address) => {
|
|
195
|
+
const client = await getClient();
|
|
196
|
+
const response = await client.addressToBech32(new AddressToBech32Request({ address }));
|
|
197
|
+
return response.bech32Address;
|
|
198
|
+
};
|
|
199
|
+
const addressFromBech32 = async (bech32Address) => {
|
|
200
|
+
const client = await getClient();
|
|
201
|
+
const response = await client.addressFromBech32(new AddressFromBech32Request({ bech32Address }));
|
|
202
|
+
return response.address;
|
|
203
|
+
};
|
|
204
|
+
// debug
|
|
205
|
+
const hello = async (name) => {
|
|
206
|
+
const client = await getClient();
|
|
207
|
+
const response = await client.hello(new HelloRequest({ name }));
|
|
208
|
+
return response.greeting;
|
|
209
|
+
};
|
|
210
|
+
// debug
|
|
211
|
+
const helloStream = async (name) => {
|
|
212
|
+
const client = await getClient();
|
|
213
|
+
return client.helloStream(new HelloRequest({ name }));
|
|
214
|
+
};
|
|
215
|
+
return {
|
|
216
|
+
initBridge,
|
|
217
|
+
closeBridge,
|
|
218
|
+
setRemote,
|
|
219
|
+
getRemote,
|
|
220
|
+
setChainID,
|
|
221
|
+
getChainID,
|
|
222
|
+
createAccount,
|
|
223
|
+
generateRecoveryPhrase,
|
|
224
|
+
listKeyInfo,
|
|
225
|
+
hasKeyByName,
|
|
226
|
+
hasKeyByAddress,
|
|
227
|
+
hasKeyByNameOrAddress,
|
|
228
|
+
getKeyInfoByName,
|
|
229
|
+
getKeyInfoByAddress,
|
|
230
|
+
getKeyInfoByNameOrAddress,
|
|
231
|
+
selectAccount,
|
|
232
|
+
setPassword,
|
|
233
|
+
getActiveAccount,
|
|
234
|
+
queryAccount,
|
|
235
|
+
deleteAccount,
|
|
236
|
+
query,
|
|
237
|
+
render,
|
|
238
|
+
qEval,
|
|
239
|
+
call,
|
|
240
|
+
send,
|
|
241
|
+
addressToBech32,
|
|
242
|
+
addressFromBech32,
|
|
243
|
+
// debug
|
|
244
|
+
hello,
|
|
245
|
+
helloStream,
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
//# sourceMappingURL=use-gno.js.map
|