zkcloudworker 0.5.8 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. package/lib/ts/src/api/api.js +30 -7
  2. package/lib/ts/src/cloud/cloud.d.ts +16 -6
  3. package/lib/ts/src/cloud/index.d.ts +5 -0
  4. package/lib/ts/src/cloud/index.js +21 -0
  5. package/lib/ts/src/cloud/local.d.ts +7 -4
  6. package/lib/ts/src/cloud/local.js +15 -4
  7. package/lib/ts/src/config.d.ts +0 -1
  8. package/lib/ts/src/config.js +0 -1
  9. package/lib/ts/src/encryption/client.d.ts +19 -0
  10. package/lib/ts/src/encryption/client.js +155 -0
  11. package/lib/ts/src/encryption/connections.d.ts +1 -0
  12. package/lib/ts/src/encryption/connections.js +4 -0
  13. package/lib/ts/src/encryption/encryption.d.ts +3 -2
  14. package/lib/ts/src/encryption/encryption.js +2 -2
  15. package/lib/ts/src/encryption/index.d.ts +4 -0
  16. package/lib/ts/src/encryption/index.js +14 -0
  17. package/lib/ts/src/encryption/messages.d.ts +1 -0
  18. package/lib/ts/src/encryption/messages.js +27 -14
  19. package/lib/ts/src/index.d.ts +3 -12
  20. package/lib/ts/src/index.js +3 -12
  21. package/lib/ts/src/networks.d.ts +1 -0
  22. package/lib/ts/src/networks.js +2 -0
  23. package/lib/ts/src/{fee.js → utils/fee.js} +1 -1
  24. package/lib/ts/src/utils/fetch.js +1 -1
  25. package/lib/ts/src/utils/graphql.d.ts +11 -0
  26. package/lib/ts/src/utils/graphql.js +229 -0
  27. package/lib/ts/src/utils/index.d.ts +6 -0
  28. package/lib/ts/src/utils/index.js +22 -0
  29. package/lib/ts/src/{mina.d.ts → utils/mina.d.ts} +1 -1
  30. package/lib/ts/src/{mina.js → utils/mina.js} +1 -1
  31. package/lib/ts/tsconfig.tsbuildinfo +1 -1
  32. package/lib/web/src/api/api.js +30 -7
  33. package/lib/web/src/api/api.js.map +1 -1
  34. package/lib/web/src/cloud/cloud.d.ts +16 -6
  35. package/lib/web/src/cloud/cloud.js.map +1 -1
  36. package/lib/web/src/cloud/index.d.ts +5 -0
  37. package/lib/web/src/cloud/index.js +6 -0
  38. package/lib/web/src/cloud/index.js.map +1 -0
  39. package/lib/web/src/cloud/local.d.ts +7 -4
  40. package/lib/web/src/cloud/local.js +15 -4
  41. package/lib/web/src/cloud/local.js.map +1 -1
  42. package/lib/web/src/config.d.ts +0 -1
  43. package/lib/web/src/config.js +0 -1
  44. package/lib/web/src/config.js.map +1 -1
  45. package/lib/web/src/encryption/client.d.ts +19 -0
  46. package/lib/web/src/encryption/client.js +151 -0
  47. package/lib/web/src/encryption/client.js.map +1 -0
  48. package/lib/web/src/encryption/connections.d.ts +1 -0
  49. package/lib/web/src/encryption/connections.js +2 -0
  50. package/lib/web/src/encryption/connections.js.map +1 -0
  51. package/lib/web/src/encryption/encryption.d.ts +3 -2
  52. package/lib/web/src/encryption/encryption.js +4 -3
  53. package/lib/web/src/encryption/encryption.js.map +1 -1
  54. package/lib/web/src/encryption/index.d.ts +4 -0
  55. package/lib/web/src/encryption/index.js +5 -0
  56. package/lib/web/src/encryption/index.js.map +1 -0
  57. package/lib/web/src/encryption/messages.d.ts +1 -0
  58. package/lib/web/src/encryption/messages.js +23 -8
  59. package/lib/web/src/encryption/messages.js.map +1 -1
  60. package/lib/web/src/index.d.ts +3 -12
  61. package/lib/web/src/index.js +3 -12
  62. package/lib/web/src/index.js.map +1 -1
  63. package/lib/web/src/networks.d.ts +1 -0
  64. package/lib/web/src/networks.js +2 -0
  65. package/lib/web/src/networks.js.map +1 -1
  66. package/lib/web/src/{fee.js → utils/fee.js} +1 -1
  67. package/lib/web/src/utils/fee.js.map +1 -0
  68. package/lib/web/src/utils/fetch.js +1 -1
  69. package/lib/web/src/utils/fetch.js.map +1 -1
  70. package/lib/web/src/utils/graphql.d.ts +11 -0
  71. package/lib/web/src/utils/graphql.js +225 -0
  72. package/lib/web/src/utils/graphql.js.map +1 -0
  73. package/lib/web/src/utils/index.d.ts +6 -0
  74. package/lib/web/src/utils/index.js +7 -0
  75. package/lib/web/src/utils/index.js.map +1 -0
  76. package/lib/web/src/{mina.d.ts → utils/mina.d.ts} +1 -1
  77. package/lib/web/src/{mina.js → utils/mina.js} +1 -1
  78. package/lib/web/src/utils/mina.js.map +1 -0
  79. package/lib/web/tsconfig.web.tsbuildinfo +1 -1
  80. package/package.json +2 -2
  81. package/lib/ts/src/encryption/nats-client.d.ts +0 -1
  82. package/lib/ts/src/encryption/nats-client.js +0 -85
  83. package/lib/web/src/encryption/nats-client.d.ts +0 -1
  84. package/lib/web/src/encryption/nats-client.js +0 -79
  85. package/lib/web/src/encryption/nats-client.js.map +0 -1
  86. package/lib/web/src/fee.js.map +0 -1
  87. package/lib/web/src/mina.js.map +0 -1
  88. /package/lib/ts/src/{fee.d.ts → utils/fee.d.ts} +0 -0
  89. /package/lib/web/src/{fee.d.ts → utils/fee.d.ts} +0 -0
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.zkCloudWorkerClient = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const chalk_1 = __importDefault(require("chalk"));
9
- const mina_1 = require("../mina");
9
+ const mina_1 = require("../utils/mina");
10
10
  const local_1 = require("../cloud/local");
11
11
  const config_1 = __importDefault(require("../config"));
12
12
  const { ZKCLOUDWORKER_AUTH, ZKCLOUDWORKER_API } = config_1.default;
@@ -50,17 +50,28 @@ class zkCloudWorkerClient {
50
50
  */
51
51
  async recursiveProof(data) {
52
52
  const result = await this.apiHub("recursiveProof", data);
53
- if (result.data === "error")
53
+ if (result.data === "error" ||
54
+ (typeof result.data === "string" && result.data.startsWith("error")))
54
55
  return {
55
56
  success: false,
56
57
  error: result.error,
57
58
  };
58
- else
59
+ else if (result.success === false || result.data?.success === false)
60
+ return {
61
+ success: false,
62
+ error: result.error ?? result.data?.error ?? "recursiveProof call failed",
63
+ };
64
+ else if (result.success === true && result.data?.success === true)
59
65
  return {
60
66
  success: result.success,
61
- jobId: result.data,
67
+ jobId: result.data.jobId,
62
68
  error: result.error,
63
69
  };
70
+ else
71
+ return {
72
+ success: false,
73
+ error: "recursiveProof call error",
74
+ };
64
75
  }
65
76
  /**
66
77
  * Starts a new job for the function call using serverless api call
@@ -91,11 +102,23 @@ class zkCloudWorkerClient {
91
102
  success: false,
92
103
  error: result.error ?? result.data?.error ?? "execute call failed",
93
104
  };
94
- else if (result.success === true && result.data?.success === true)
105
+ else if (result.success === true &&
106
+ data.mode === "sync" &&
107
+ result.data !== undefined)
108
+ return {
109
+ success: result.success,
110
+ jobId: undefined,
111
+ result: result.data,
112
+ error: result.error,
113
+ };
114
+ else if (result.success === true &&
115
+ data.mode !== "sync" &&
116
+ result.data?.success === true &&
117
+ result.data?.jobId !== undefined)
95
118
  return {
96
119
  success: result.success,
97
- jobId: data.mode === "sync" ? undefined : result.data.jobId,
98
- result: data.mode === "sync" ? result.data : undefined,
120
+ jobId: result.data.jobId,
121
+ result: undefined,
99
122
  error: result.error,
100
123
  };
101
124
  else
@@ -1,11 +1,19 @@
1
1
  /// <reference types="node" />
2
- import { Cache, PrivateKey, PublicKey, SmartContract } from "o1js";
2
+ import type { Cache } from "o1js";
3
3
  import { blockchain } from "../networks";
4
4
  import { JobData } from "./job";
5
5
  export interface DeployedSmartContract {
6
- address: PublicKey;
7
- contract: SmartContract;
6
+ address: string;
7
+ name: string;
8
8
  chain: blockchain;
9
+ verificationKey: {
10
+ hash: string;
11
+ data: string;
12
+ };
13
+ }
14
+ export interface DeployerKeyPair {
15
+ publicKey: string;
16
+ privateKey: string;
9
17
  }
10
18
  export interface CloudTransaction {
11
19
  txId: string;
@@ -41,9 +49,11 @@ export declare abstract class Cloud {
41
49
  isLocalCloud?: boolean;
42
50
  chain: blockchain;
43
51
  });
44
- abstract getDeployer(): Promise<PrivateKey | undefined>;
45
- abstract releaseDeployer(txsHashes: string[]): Promise<void>;
46
- abstract log(msg: string): void;
52
+ abstract getDeployer(): Promise<DeployerKeyPair | undefined>;
53
+ abstract releaseDeployer(params: {
54
+ publicKey: string;
55
+ txsHashes: string[];
56
+ }): Promise<void>;
47
57
  abstract getDataByKey(key: string): Promise<string | undefined>;
48
58
  abstract saveDataByKey(key: string, value: string | undefined): Promise<void>;
49
59
  abstract saveFile(filename: string, value: Buffer): Promise<void>;
@@ -0,0 +1,5 @@
1
+ export * from "./cloud";
2
+ export * from "./files";
3
+ export * from "./job";
4
+ export * from "./task";
5
+ export * from "./local";
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./cloud"), exports);
18
+ __exportStar(require("./files"), exports);
19
+ __exportStar(require("./job"), exports);
20
+ __exportStar(require("./task"), exports);
21
+ __exportStar(require("./local"), exports);
@@ -1,10 +1,10 @@
1
1
  /// <reference types="node" />
2
- import { Cache, PrivateKey } from "o1js";
2
+ import { Cache } from "o1js";
3
3
  import { Cloud, zkCloudWorker } from "./cloud";
4
4
  import { JobData } from "./job";
5
5
  import { TaskData } from "./task";
6
6
  import { blockchain } from "../networks";
7
- import { CloudTransaction } from "./cloud";
7
+ import { CloudTransaction, DeployerKeyPair } from "./cloud";
8
8
  import { ApiCommand } from "../api/api";
9
9
  export declare class LocalCloud extends Cloud {
10
10
  readonly localWorker: (cloud: Cloud) => Promise<zkCloudWorker>;
@@ -15,8 +15,11 @@ export declare class LocalCloud extends Cloud {
15
15
  stepId?: string;
16
16
  localWorker: (cloud: Cloud) => Promise<zkCloudWorker>;
17
17
  });
18
- getDeployer(): Promise<PrivateKey | undefined>;
19
- releaseDeployer(txsHashes: string[]): Promise<void>;
18
+ getDeployer(): Promise<DeployerKeyPair | undefined>;
19
+ releaseDeployer(params: {
20
+ publicKey: string;
21
+ txsHashes: string[];
22
+ }): Promise<void>;
20
23
  log(msg: string): Promise<void>;
21
24
  getDataByKey(key: string): Promise<string | undefined>;
22
25
  saveDataByKey(key: string, value: string | undefined): Promise<void>;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LocalStorage = exports.LocalCloud = void 0;
4
4
  const o1js_1 = require("o1js");
5
5
  const cloud_1 = require("./cloud");
6
- const mina_1 = require("../mina");
6
+ const mina_1 = require("../utils/mina");
7
7
  const files_1 = require("./files");
8
8
  class LocalCloud extends cloud_1.Cloud {
9
9
  constructor(params) {
@@ -28,10 +28,21 @@ class LocalCloud extends cloud_1.Cloud {
28
28
  }
29
29
  async getDeployer() {
30
30
  const deployer = process.env.DEPLOYER;
31
- return deployer === undefined ? undefined : o1js_1.PrivateKey.fromBase58(deployer);
31
+ try {
32
+ return deployer === undefined
33
+ ? undefined
34
+ : {
35
+ privateKey: deployer,
36
+ publicKey: o1js_1.PrivateKey.fromBase58(deployer).toPublicKey().toBase58(),
37
+ };
38
+ }
39
+ catch (error) {
40
+ console.error(`getDeployer: process.env.DEPLOYER has wrong encoding, should be base58 private key ("EKE...")`, error);
41
+ return undefined;
42
+ }
32
43
  }
33
- async releaseDeployer(txsHashes) {
34
- console.log("LocalCloud: releaseDeployer", txsHashes);
44
+ async releaseDeployer(params) {
45
+ console.log("LocalCloud: releaseDeployer", params);
35
46
  }
36
47
  async log(msg) {
37
48
  console.log("LocalCloud:", msg);
@@ -2,6 +2,5 @@ declare const config: {
2
2
  MINAFEE: string;
3
3
  ZKCLOUDWORKER_AUTH: string;
4
4
  ZKCLOUDWORKER_API: string;
5
- NATS_SERVER: string;
6
5
  };
7
6
  export default config;
@@ -4,6 +4,5 @@ const config = {
4
4
  MINAFEE: "200000000",
5
5
  ZKCLOUDWORKER_AUTH: "M6t4jtbBAFFXhLERHQWyEB9JA9xi4cWqmYduaCXtbrFjb7yaY7TyaXDunKDJNiUTBEcyUomNXJgC",
6
6
  ZKCLOUDWORKER_API: "https://cuq99yahhi.execute-api.eu-west-1.amazonaws.com/dev/zkcloudworker",
7
- NATS_SERVER: "nats.socialcap.dev:4222",
8
7
  };
9
8
  exports.default = config;
@@ -0,0 +1,19 @@
1
+ export interface INATSClient {
2
+ address: string;
3
+ secret: string;
4
+ callme: {
5
+ onOptions: (params: any) => void;
6
+ onReady: (params: any) => void;
7
+ onDone: (params: any) => void;
8
+ };
9
+ }
10
+ export declare function NATSClient(callme: {
11
+ onOptions: (params: any) => void;
12
+ onReady: (params: any) => void;
13
+ onDone: (params: any) => void;
14
+ }): Promise<INATSClient>;
15
+ export declare function listen(subject: string, callme: {
16
+ onOptions: (params: any) => void;
17
+ onReady: (params: any) => void;
18
+ onDone: (params: any) => void;
19
+ }): Promise<void>;
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listen = exports.NATSClient = void 0;
4
+ const o1js_1 = require("o1js");
5
+ const nats_1 = require("nats");
6
+ const o1js_2 = require("o1js");
7
+ const encryption_1 = require("./encryption");
8
+ const connections_1 = require("./connections");
9
+ async function NATSClient(callme) {
10
+ // create some client address, this will be done by
11
+ // the web API BEFORE calling a worker
12
+ const secret = o1js_1.PrivateKey.random();
13
+ let address = secret.toPublicKey().toBase58();
14
+ console.log("Client address ", address);
15
+ // now subscribe and listen in this Address
16
+ // we use the 'zkcw' prefix for zkCloudWorkers subscriptions
17
+ await listen(`zkcw:${address}`, callme);
18
+ return {
19
+ address: address,
20
+ secret: secret.toBase58(),
21
+ callme: callme,
22
+ };
23
+ }
24
+ exports.NATSClient = NATSClient;
25
+ async function listen(subject, callme) {
26
+ // Create a JSON codec for encoding and decoding messages
27
+ const codec = (0, nats_1.JSONCodec)();
28
+ const connection = await (0, nats_1.connect)({ servers: connections_1.NATS_SERVER });
29
+ // Subscribe to the subject
30
+ const subscription = connection.subscribe(subject);
31
+ console.log(`Subscribed to subject ${subject}`);
32
+ // Process messages received on the subscribed subject
33
+ (async () => {
34
+ // Error decoding message: Error: Could not encrypt message={}
35
+ // Error: Poseidon.Sponge(): bindings are not initialized, try calling `await initializeBindings()` first.
36
+ // This shouldn't have happened and indicates an internal bug.
37
+ await (0, o1js_2.initializeBindings)();
38
+ for await (const msg of subscription) {
39
+ try {
40
+ const data = codec.decode(msg.data);
41
+ //console.log(`Received message on subject ${subject}:`, data);
42
+ // Perform processing logic here
43
+ const { post, params } = data;
44
+ // console.log(`Post: `, post, params);
45
+ switch (post) {
46
+ case "options":
47
+ {
48
+ // the workers announces it is ready
49
+ // and we receive the worker's publicKey
50
+ let workerKey = params.key || "";
51
+ console.log("\nReceived 'options' message from worker");
52
+ console.log("Worker publicKey: ", workerKey);
53
+ let options = callme.onOptions(params);
54
+ console.log("options:", options);
55
+ // we will use its key to encrypt the message
56
+ const encryptedOptions = encryption_1.CipherText.encrypt(JSON.stringify(options), workerKey);
57
+ console.log("Encrypted options: ", encryptedOptions);
58
+ // we reply with the command we want the worker to execute
59
+ // and with the encrypted payload
60
+ msg.respond(codec.encode({
61
+ success: true,
62
+ data: {
63
+ command: "options",
64
+ encrypted: encryptedOptions,
65
+ },
66
+ error: undefined,
67
+ }));
68
+ }
69
+ break;
70
+ case "ready":
71
+ {
72
+ // the workers announces it is ready
73
+ // and we receive the worker's publicKey
74
+ let workerKey = params.key || "";
75
+ console.log("\nReceived 'ready' message from worker");
76
+ console.log("Worker publicKey: ", workerKey);
77
+ let payload = callme.onReady(params);
78
+ console.log("payload:", payload);
79
+ // we will use its key to encrypt the message
80
+ const encryptedPayload = encryption_1.CipherText.encrypt(JSON.stringify(payload), workerKey);
81
+ console.log("Encrypted payload: ", encryptedPayload);
82
+ // we reply with the command we want the worker to execute
83
+ // and with the encrypted payload
84
+ msg.respond(codec.encode({
85
+ success: true,
86
+ data: {
87
+ command: "execute",
88
+ encrypted: encryptedPayload,
89
+ },
90
+ error: undefined,
91
+ }));
92
+ }
93
+ break;
94
+ case "done":
95
+ {
96
+ let result = params.result || "";
97
+ console.log("\nReceived 'done' message from worker");
98
+ let done = callme.onDone(params);
99
+ console.log("done: ", done);
100
+ msg.respond(codec.encode({
101
+ success: true,
102
+ data: {
103
+ command: "close",
104
+ status: JSON.stringify(done),
105
+ },
106
+ error: undefined,
107
+ }));
108
+ // we want to insure that messages that are in flight
109
+ // get processed, so we are going to drain the
110
+ // connection. Drain is the same as close, but makes
111
+ // sure that all messages in flight get seen
112
+ // by the iterator. After calling drain on the connection
113
+ // the connection closes.
114
+ setTimeout(async () => {
115
+ await connection.drain();
116
+ }, 1000);
117
+ }
118
+ break;
119
+ }
120
+ }
121
+ catch (err) {
122
+ console.error("Error decoding message: ", err);
123
+ }
124
+ }
125
+ })();
126
+ }
127
+ exports.listen = listen;
128
+ /*
129
+ async function main(args: string[]) {
130
+ const nc = await connect({ servers: NATS_SERVER });
131
+
132
+ // create some client address, this will be done by
133
+ // the web API when calling a worker
134
+ const clientSecret = PrivateKey.random();
135
+ let clientAddress = clientSecret.toPublicKey().toBase58();
136
+ console.log("Client address ", clientAddress);
137
+
138
+ clientAddress = "B62qrYPDY555koJFAdNaUyw21WCNUgie9bmsBs2gCh6DSdhQmuN4qu6";
139
+
140
+ // now subscribe and listen in this Address
141
+ listen(nc, `zkcw:${clientAddress}`);
142
+
143
+ // we want to insure that messages that are in flight
144
+ // get processed, so we are going to drain the
145
+ // connection. Drain is the same as close, but makes
146
+ // sure that all messages in flight get seen
147
+ // by the iterator. After calling drain on the connection
148
+ // the connection closes.
149
+ //await nc.drain();
150
+ }
151
+
152
+ main(process.argv.slice(2)).catch((error) => {
153
+ console.error(error);
154
+ });
155
+ */
@@ -0,0 +1 @@
1
+ export declare const NATS_SERVER = "nats.socialcap.dev:4222";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NATS_SERVER = void 0;
4
+ exports.NATS_SERVER = "nats.socialcap.dev:4222";
@@ -1,9 +1,10 @@
1
1
  import { Field, Group } from "o1js";
2
- export interface CipherTextObject {
2
+ export { CipherText };
3
+ interface CipherTextObject {
3
4
  cipherText: Field[];
4
5
  publicKey: Group;
5
6
  }
6
- export declare class CipherText {
7
+ declare class CipherText {
7
8
  static stringify(cipherText: CipherTextObject): string;
8
9
  static parse(jsonStr: string): CipherTextObject;
9
10
  static encrypt(message: string, publicId: string): string;
@@ -16,8 +16,8 @@ class CipherText {
16
16
  static encrypt(message, publicId) {
17
17
  try {
18
18
  let fields = o1js_1.Encoding.stringToFields(message);
19
- let encrypted = o1js_1.Encryption.encrypt(fields, o1js_1.PublicKey.fromBase58(publicId));
20
- return CipherText.stringify(encrypted);
19
+ let encripted = o1js_1.Encryption.encrypt(fields, o1js_1.PublicKey.fromBase58(publicId));
20
+ return CipherText.stringify(encripted);
21
21
  }
22
22
  catch (err) {
23
23
  throw Error(`Could not encrypt message='${message}' using key='${publicId}'.` +
@@ -0,0 +1,4 @@
1
+ export { NATS_SERVER } from "./connections";
2
+ export { CipherText } from "./encryption";
3
+ export { NATSClient, listen } from "./client";
4
+ export { postReadyMessage, postDoneMessage, postOptionsMessage, } from "./messages";
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.postOptionsMessage = exports.postDoneMessage = exports.postReadyMessage = exports.listen = exports.NATSClient = exports.CipherText = exports.NATS_SERVER = void 0;
4
+ var connections_1 = require("./connections");
5
+ Object.defineProperty(exports, "NATS_SERVER", { enumerable: true, get: function () { return connections_1.NATS_SERVER; } });
6
+ var encryption_1 = require("./encryption");
7
+ Object.defineProperty(exports, "CipherText", { enumerable: true, get: function () { return encryption_1.CipherText; } });
8
+ var client_1 = require("./client");
9
+ Object.defineProperty(exports, "NATSClient", { enumerable: true, get: function () { return client_1.NATSClient; } });
10
+ Object.defineProperty(exports, "listen", { enumerable: true, get: function () { return client_1.listen; } });
11
+ var messages_1 = require("./messages");
12
+ Object.defineProperty(exports, "postReadyMessage", { enumerable: true, get: function () { return messages_1.postReadyMessage; } });
13
+ Object.defineProperty(exports, "postDoneMessage", { enumerable: true, get: function () { return messages_1.postDoneMessage; } });
14
+ Object.defineProperty(exports, "postOptionsMessage", { enumerable: true, get: function () { return messages_1.postOptionsMessage; } });
@@ -1,2 +1,3 @@
1
+ export declare function postOptionsMessage(clientAddress: string, workerAddress: string): Promise<any>;
1
2
  export declare function postReadyMessage(clientAddress: string, workerAddress: string): Promise<any>;
2
3
  export declare function postDoneMessage(clientAddress: string, encrypted: string): Promise<any>;
@@ -1,38 +1,51 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.postDoneMessage = exports.postReadyMessage = void 0;
3
+ exports.postDoneMessage = exports.postReadyMessage = exports.postOptionsMessage = void 0;
7
4
  const nats_1 = require("nats");
8
- const config_1 = __importDefault(require("../config"));
9
- const { NATS_SERVER } = config_1.default;
5
+ const connections_1 = require("./connections");
10
6
  const codec = (0, nats_1.JSONCodec)();
7
+ async function postOptionsMessage(clientAddress, workerAddress) {
8
+ // connect to the NATS server and send a 'ready' request
9
+ const nc = await (0, nats_1.connect)({ servers: connections_1.NATS_SERVER });
10
+ const msg = await nc.request(`zkcw:${clientAddress}`, codec.encode({
11
+ "post": "options",
12
+ "params": { "key": workerAddress }
13
+ }));
14
+ const response = codec.decode(msg.data);
15
+ console.log("Response: ", response);
16
+ // disconect and clean all pendings
17
+ await nc.drain();
18
+ return response;
19
+ }
20
+ exports.postOptionsMessage = postOptionsMessage;
21
+ ;
11
22
  async function postReadyMessage(clientAddress, workerAddress) {
12
23
  // connect to the NATS server and send a 'ready' request
13
- const nc = await (0, nats_1.connect)({ servers: NATS_SERVER });
24
+ const nc = await (0, nats_1.connect)({ servers: connections_1.NATS_SERVER });
14
25
  const msg = await nc.request(`zkcw:${clientAddress}`, codec.encode({
15
- post: "ready",
16
- params: { key: workerAddress },
26
+ "post": "ready",
27
+ "params": { "key": workerAddress }
17
28
  }));
18
29
  const response = codec.decode(msg.data);
19
30
  console.log("Response: ", response);
20
- // disconnect and clean all pending
31
+ // disconect and clean all pendings
21
32
  await nc.drain();
22
33
  return response;
23
34
  }
24
35
  exports.postReadyMessage = postReadyMessage;
36
+ ;
25
37
  async function postDoneMessage(clientAddress, encrypted) {
26
38
  // connect to the NATS server and send a 'ready' request
27
- const nc = await (0, nats_1.connect)({ servers: NATS_SERVER });
39
+ const nc = await (0, nats_1.connect)({ servers: connections_1.NATS_SERVER });
28
40
  const msg = await nc.request(`zkcw:${clientAddress}`, codec.encode({
29
- post: "done",
30
- params: { result: encrypted },
41
+ "post": "done",
42
+ "params": { "result": encrypted }
31
43
  }));
32
44
  const response = codec.decode(msg.data);
33
45
  console.log("Response: ", response);
34
- // disconnect and clean all pending
46
+ // disconect and clean all pendings
35
47
  await nc.drain();
36
48
  return response;
37
49
  }
38
50
  exports.postDoneMessage = postDoneMessage;
51
+ ;
@@ -1,14 +1,5 @@
1
1
  export * from "./api/api";
2
- export * from "./cloud/cloud";
3
- export * from "./cloud/local";
4
- export * from "./cloud/job";
5
- export * from "./cloud/task";
6
- export * from "./mina";
7
- export * from "./fee";
2
+ export * from "./cloud";
8
3
  export * from "./networks";
9
- export * from "./encryption/encryption";
10
- export * from "./encryption/nats-client";
11
- export * from "./encryption/messages";
12
- export * from "./utils/fields";
13
- export * from "./utils/base64";
14
- export * from "./utils/fetch";
4
+ export * from "./encryption";
5
+ export * from "./utils";
@@ -15,16 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./api/api"), exports);
18
- __exportStar(require("./cloud/cloud"), exports);
19
- __exportStar(require("./cloud/local"), exports);
20
- __exportStar(require("./cloud/job"), exports);
21
- __exportStar(require("./cloud/task"), exports);
22
- __exportStar(require("./mina"), exports);
23
- __exportStar(require("./fee"), exports);
18
+ __exportStar(require("./cloud"), exports);
24
19
  __exportStar(require("./networks"), exports);
25
- __exportStar(require("./encryption/encryption"), exports);
26
- __exportStar(require("./encryption/nats-client"), exports);
27
- __exportStar(require("./encryption/messages"), exports);
28
- __exportStar(require("./utils/fields"), exports);
29
- __exportStar(require("./utils/base64"), exports);
30
- __exportStar(require("./utils/fetch"), exports);
20
+ __exportStar(require("./encryption"), exports);
21
+ __exportStar(require("./utils"), exports);
@@ -8,6 +8,7 @@ interface MinaNetwork {
8
8
  accountManager?: string;
9
9
  explorerAccountUrl?: string;
10
10
  explorerTransactionUrl?: string;
11
+ faucet?: string;
11
12
  }
12
13
  declare const Mainnet: MinaNetwork;
13
14
  declare const Local: MinaNetwork;
@@ -26,6 +26,7 @@ const Devnet = {
26
26
  explorerTransactionUrl: "https://minascan.io/devnet/tx/",
27
27
  chainId: "devnet",
28
28
  name: "Devnet",
29
+ faucet: "https://faucet.minaprotocol.com",
29
30
  };
30
31
  exports.Devnet = Devnet;
31
32
  const Zeko = {
@@ -35,6 +36,7 @@ const Zeko = {
35
36
  explorerTransactionUrl: "https://zekoscan.io/devnet/tx/",
36
37
  chainId: "zeko",
37
38
  name: "Zeko",
39
+ faucet: "https://zeko.io/faucet",
38
40
  };
39
41
  exports.Zeko = Zeko;
40
42
  const Lightnet = {
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.fee = void 0;
7
7
  const o1js_1 = require("o1js");
8
- const config_1 = __importDefault(require("./config"));
8
+ const config_1 = __importDefault(require("../config"));
9
9
  async function fee() {
10
10
  //TODO: update after mainnet launch
11
11
  return o1js_1.UInt64.fromJSON(config_1.default.MINAFEE);
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkMinaZkappTransaction = exports.fetchMinaActions = exports.fetchMinaAccount = void 0;
4
4
  const o1js_1 = require("o1js");
5
- const mina_1 = require("../mina");
5
+ const mina_1 = require("./mina");
6
6
  async function fetchMinaAccount(params) {
7
7
  const { publicKey, tokenId, force } = params;
8
8
  const timeout = 1000 * 60 * 2; // 2 minutes
@@ -0,0 +1,11 @@
1
+ export declare const defaultToken = "wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf";
2
+ export declare function getBalanceFromGraphQL(params: {
3
+ publicKey: string;
4
+ tokenId?: string;
5
+ mina: string[];
6
+ }): Promise<bigint>;
7
+ export declare function getAccountFromGraphQL(params: {
8
+ publicKey: string;
9
+ tokenId?: string;
10
+ mina: string[];
11
+ }): Promise<any>;