zkcloudworker 0.14.2 → 0.14.3
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/lib/ts/src/mina/index.d.ts +0 -1
- package/lib/ts/src/mina/index.js +1 -1
- package/lib/ts/tsconfig.tsbuildinfo +1 -1
- package/lib/web/src/mina/index.d.ts +0 -1
- package/lib/web/src/mina/index.js +1 -1
- package/lib/web/src/mina/index.js.map +1 -1
- package/lib/web/tsconfig.web.tsbuildinfo +1 -1
- package/package.json +2 -3
- package/lib/ts/src/mina/encryption/client.d.ts +0 -19
- package/lib/ts/src/mina/encryption/client.js +0 -154
- package/lib/ts/src/mina/encryption/connections.d.ts +0 -1
- package/lib/ts/src/mina/encryption/connections.js +0 -4
- package/lib/ts/src/mina/encryption/encryption.d.ts +0 -13
- package/lib/ts/src/mina/encryption/encryption.js +0 -41
- package/lib/ts/src/mina/encryption/index.d.ts +0 -4
- package/lib/ts/src/mina/encryption/index.js +0 -14
- package/lib/ts/src/mina/encryption/messages.d.ts +0 -3
- package/lib/ts/src/mina/encryption/messages.js +0 -50
- package/lib/web/src/mina/encryption/client.d.ts +0 -19
- package/lib/web/src/mina/encryption/client.js +0 -151
- package/lib/web/src/mina/encryption/client.js.map +0 -1
- package/lib/web/src/mina/encryption/connections.d.ts +0 -1
- package/lib/web/src/mina/encryption/connections.js +0 -2
- package/lib/web/src/mina/encryption/connections.js.map +0 -1
- package/lib/web/src/mina/encryption/encryption.d.ts +0 -13
- package/lib/web/src/mina/encryption/encryption.js +0 -39
- package/lib/web/src/mina/encryption/encryption.js.map +0 -1
- package/lib/web/src/mina/encryption/index.d.ts +0 -4
- package/lib/web/src/mina/encryption/index.js +0 -5
- package/lib/web/src/mina/encryption/index.js.map +0 -1
- package/lib/web/src/mina/encryption/messages.d.ts +0 -3
- package/lib/web/src/mina/encryption/messages.js +0 -46
- package/lib/web/src/mina/encryption/messages.js.map +0 -1
@@ -1,41 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.CipherText = void 0;
|
4
|
-
const o1js_1 = require("o1js");
|
5
|
-
class CipherText {
|
6
|
-
static stringify(cipherText) {
|
7
|
-
return JSON.stringify(cipherText);
|
8
|
-
}
|
9
|
-
static parse(jsonStr) {
|
10
|
-
let obj = JSON.parse(jsonStr);
|
11
|
-
return {
|
12
|
-
publicKey: new o1js_1.Group(obj.publicKey),
|
13
|
-
cipherText: (obj.cipherText || []).map((t) => (0, o1js_1.Field)(t)),
|
14
|
-
};
|
15
|
-
}
|
16
|
-
static encrypt(message, publicId) {
|
17
|
-
try {
|
18
|
-
let fields = o1js_1.Encoding.stringToFields(message);
|
19
|
-
let encripted = o1js_1.Encryption.encrypt(fields, o1js_1.PublicKey.fromBase58(publicId));
|
20
|
-
return CipherText.stringify(encripted);
|
21
|
-
}
|
22
|
-
catch (err) {
|
23
|
-
throw Error(`Could not encrypt message='${message}' using key='${publicId}'.` +
|
24
|
-
` Error ${err}`);
|
25
|
-
}
|
26
|
-
}
|
27
|
-
static decrypt(cipherText, privateKey) {
|
28
|
-
try {
|
29
|
-
let fields = o1js_1.Encryption.decrypt(CipherText.parse(cipherText), o1js_1.PrivateKey.fromBase58(privateKey));
|
30
|
-
let decrypted = o1js_1.Encoding.stringFromFields(fields);
|
31
|
-
return decrypted;
|
32
|
-
}
|
33
|
-
catch (err) {
|
34
|
-
throw Error(`Could not decrypt cipher='${cipherText}'.` + ` Error ${err}`);
|
35
|
-
}
|
36
|
-
}
|
37
|
-
static async initialize() {
|
38
|
-
await (0, o1js_1.initializeBindings)();
|
39
|
-
}
|
40
|
-
}
|
41
|
-
exports.CipherText = CipherText;
|
@@ -1,14 +0,0 @@
|
|
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,3 +0,0 @@
|
|
1
|
-
export declare function postOptionsMessage(clientAddress: string, workerAddress: string): Promise<any>;
|
2
|
-
export declare function postReadyMessage(clientAddress: string, workerAddress: string): Promise<any>;
|
3
|
-
export declare function postDoneMessage(clientAddress: string, encrypted: string): Promise<any>;
|
@@ -1,50 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.postOptionsMessage = postOptionsMessage;
|
4
|
-
exports.postReadyMessage = postReadyMessage;
|
5
|
-
exports.postDoneMessage = postDoneMessage;
|
6
|
-
const nats_1 = require("nats");
|
7
|
-
const connections_1 = require("./connections");
|
8
|
-
const codec = (0, nats_1.JSONCodec)();
|
9
|
-
async function postOptionsMessage(clientAddress, workerAddress) {
|
10
|
-
// connect to the NATS server and send a 'ready' request
|
11
|
-
const nc = await (0, nats_1.connect)({ servers: connections_1.NATS_SERVER });
|
12
|
-
const msg = await nc.request(`zkcw:${clientAddress}`, codec.encode({
|
13
|
-
"post": "options",
|
14
|
-
"params": { "key": workerAddress }
|
15
|
-
}));
|
16
|
-
const response = codec.decode(msg.data);
|
17
|
-
console.log("Response: ", response);
|
18
|
-
// disconect and clean all pendings
|
19
|
-
await nc.drain();
|
20
|
-
return response;
|
21
|
-
}
|
22
|
-
;
|
23
|
-
async function postReadyMessage(clientAddress, workerAddress) {
|
24
|
-
// connect to the NATS server and send a 'ready' request
|
25
|
-
const nc = await (0, nats_1.connect)({ servers: connections_1.NATS_SERVER });
|
26
|
-
const msg = await nc.request(`zkcw:${clientAddress}`, codec.encode({
|
27
|
-
"post": "ready",
|
28
|
-
"params": { "key": workerAddress }
|
29
|
-
}));
|
30
|
-
const response = codec.decode(msg.data);
|
31
|
-
console.log("Response: ", response);
|
32
|
-
// disconect and clean all pendings
|
33
|
-
await nc.drain();
|
34
|
-
return response;
|
35
|
-
}
|
36
|
-
;
|
37
|
-
async function postDoneMessage(clientAddress, encrypted) {
|
38
|
-
// connect to the NATS server and send a 'ready' request
|
39
|
-
const nc = await (0, nats_1.connect)({ servers: connections_1.NATS_SERVER });
|
40
|
-
const msg = await nc.request(`zkcw:${clientAddress}`, codec.encode({
|
41
|
-
"post": "done",
|
42
|
-
"params": { "result": encrypted }
|
43
|
-
}));
|
44
|
-
const response = codec.decode(msg.data);
|
45
|
-
console.log("Response: ", response);
|
46
|
-
// disconect and clean all pendings
|
47
|
-
await nc.drain();
|
48
|
-
return response;
|
49
|
-
}
|
50
|
-
;
|
@@ -1,19 +0,0 @@
|
|
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>;
|
@@ -1,151 +0,0 @@
|
|
1
|
-
import { PrivateKey } from "o1js";
|
2
|
-
import { connect, JSONCodec } from "nats";
|
3
|
-
import { initializeBindings } from "o1js";
|
4
|
-
import { CipherText } from "./encryption";
|
5
|
-
import { NATS_SERVER } from "./connections";
|
6
|
-
export async function NATSClient(callme) {
|
7
|
-
// create some client address, this will be done by
|
8
|
-
// the web API BEFORE calling a worker
|
9
|
-
const secret = PrivateKey.random();
|
10
|
-
let address = secret.toPublicKey().toBase58();
|
11
|
-
console.log("Client address ", address);
|
12
|
-
// now subscribe and listen in this Address
|
13
|
-
// we use the 'zkcw' prefix for zkCloudWorkers subscriptions
|
14
|
-
await listen(`zkcw:${address}`, callme);
|
15
|
-
return {
|
16
|
-
address: address,
|
17
|
-
secret: secret.toBase58(),
|
18
|
-
callme: callme,
|
19
|
-
};
|
20
|
-
}
|
21
|
-
export async function listen(subject, callme) {
|
22
|
-
// Create a JSON codec for encoding and decoding messages
|
23
|
-
const codec = JSONCodec();
|
24
|
-
const connection = await connect({ servers: NATS_SERVER });
|
25
|
-
// Subscribe to the subject
|
26
|
-
const subscription = connection.subscribe(subject);
|
27
|
-
console.log(`Subscribed to subject ${subject}`);
|
28
|
-
// Process messages received on the subscribed subject
|
29
|
-
(async () => {
|
30
|
-
// Error decoding message: Error: Could not encrypt message={}
|
31
|
-
// Error: Poseidon.Sponge(): bindings are not initialized, try calling `await initializeBindings()` first.
|
32
|
-
// This shouldn't have happened and indicates an internal bug.
|
33
|
-
await initializeBindings();
|
34
|
-
for await (const msg of subscription) {
|
35
|
-
try {
|
36
|
-
const data = codec.decode(msg.data);
|
37
|
-
//console.log(`Received message on subject ${subject}:`, data);
|
38
|
-
// Perform processing logic here
|
39
|
-
const { post, params } = data;
|
40
|
-
// console.log(`Post: `, post, params);
|
41
|
-
switch (post) {
|
42
|
-
case "options":
|
43
|
-
{
|
44
|
-
// the workers announces it is ready
|
45
|
-
// and we receive the worker's publicKey
|
46
|
-
let workerKey = params.key || "";
|
47
|
-
console.log("\nReceived 'options' message from worker");
|
48
|
-
console.log("Worker publicKey: ", workerKey);
|
49
|
-
let options = callme.onOptions(params);
|
50
|
-
console.log("options:", options);
|
51
|
-
// we will use its key to encrypt the message
|
52
|
-
const encryptedOptions = CipherText.encrypt(JSON.stringify(options), workerKey);
|
53
|
-
console.log("Encrypted options: ", encryptedOptions);
|
54
|
-
// we reply with the command we want the worker to execute
|
55
|
-
// and with the encrypted payload
|
56
|
-
msg.respond(codec.encode({
|
57
|
-
success: true,
|
58
|
-
data: {
|
59
|
-
command: "options",
|
60
|
-
encrypted: encryptedOptions,
|
61
|
-
},
|
62
|
-
error: undefined,
|
63
|
-
}));
|
64
|
-
}
|
65
|
-
break;
|
66
|
-
case "ready":
|
67
|
-
{
|
68
|
-
// the workers announces it is ready
|
69
|
-
// and we receive the worker's publicKey
|
70
|
-
let workerKey = params.key || "";
|
71
|
-
console.log("\nReceived 'ready' message from worker");
|
72
|
-
console.log("Worker publicKey: ", workerKey);
|
73
|
-
let payload = callme.onReady(params);
|
74
|
-
console.log("payload:", payload);
|
75
|
-
// we will use its key to encrypt the message
|
76
|
-
const encryptedPayload = CipherText.encrypt(JSON.stringify(payload), workerKey);
|
77
|
-
console.log("Encrypted payload: ", encryptedPayload);
|
78
|
-
// we reply with the command we want the worker to execute
|
79
|
-
// and with the encrypted payload
|
80
|
-
msg.respond(codec.encode({
|
81
|
-
success: true,
|
82
|
-
data: {
|
83
|
-
command: "execute",
|
84
|
-
encrypted: encryptedPayload,
|
85
|
-
},
|
86
|
-
error: undefined,
|
87
|
-
}));
|
88
|
-
}
|
89
|
-
break;
|
90
|
-
case "done":
|
91
|
-
{
|
92
|
-
let result = params.result || "";
|
93
|
-
console.log("\nReceived 'done' message from worker");
|
94
|
-
let done = callme.onDone(params);
|
95
|
-
console.log("done: ", done);
|
96
|
-
msg.respond(codec.encode({
|
97
|
-
success: true,
|
98
|
-
data: {
|
99
|
-
command: "close",
|
100
|
-
status: JSON.stringify(done),
|
101
|
-
},
|
102
|
-
error: undefined,
|
103
|
-
}));
|
104
|
-
// we want to insure that messages that are in flight
|
105
|
-
// get processed, so we are going to drain the
|
106
|
-
// connection. Drain is the same as close, but makes
|
107
|
-
// sure that all messages in flight get seen
|
108
|
-
// by the iterator. After calling drain on the connection
|
109
|
-
// the connection closes.
|
110
|
-
setTimeout(async () => {
|
111
|
-
await connection.drain();
|
112
|
-
}, 1000);
|
113
|
-
}
|
114
|
-
break;
|
115
|
-
}
|
116
|
-
}
|
117
|
-
catch (err) {
|
118
|
-
console.error("Error decoding message: ", err);
|
119
|
-
}
|
120
|
-
}
|
121
|
-
})();
|
122
|
-
}
|
123
|
-
/*
|
124
|
-
async function main(args: string[]) {
|
125
|
-
const nc = await connect({ servers: NATS_SERVER });
|
126
|
-
|
127
|
-
// create some client address, this will be done by
|
128
|
-
// the web API when calling a worker
|
129
|
-
const clientSecret = PrivateKey.random();
|
130
|
-
let clientAddress = clientSecret.toPublicKey().toBase58();
|
131
|
-
console.log("Client address ", clientAddress);
|
132
|
-
|
133
|
-
clientAddress = "B62qrYPDY555koJFAdNaUyw21WCNUgie9bmsBs2gCh6DSdhQmuN4qu6";
|
134
|
-
|
135
|
-
// now subscribe and listen in this Address
|
136
|
-
listen(nc, `zkcw:${clientAddress}`);
|
137
|
-
|
138
|
-
// we want to insure that messages that are in flight
|
139
|
-
// get processed, so we are going to drain the
|
140
|
-
// connection. Drain is the same as close, but makes
|
141
|
-
// sure that all messages in flight get seen
|
142
|
-
// by the iterator. After calling drain on the connection
|
143
|
-
// the connection closes.
|
144
|
-
//await nc.drain();
|
145
|
-
}
|
146
|
-
|
147
|
-
main(process.argv.slice(2)).catch((error) => {
|
148
|
-
console.error(error);
|
149
|
-
});
|
150
|
-
*/
|
151
|
-
//# sourceMappingURL=client.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../../../src/mina/encryption/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAY5C,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAIhC;IACC,mDAAmD;IACnD,sCAAsC;IACtC,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;IACnC,IAAI,OAAO,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;IAExC,2CAA2C;IAC3C,4DAA4D;IAC5D,MAAM,MAAM,CAAC,QAAQ,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC;IAExC,OAAO;QACL,OAAO,EAAE,OAAO;QAChB,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE;QACzB,MAAM,EAAE,MAAM;KACf,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,OAAe,EACf,MAIC;IAED,yDAAyD;IACzD,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;IAE1B,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;IAE3D,2BAA2B;IAC3B,MAAM,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACnD,OAAO,CAAC,GAAG,CAAC,yBAAyB,OAAO,EAAE,CAAC,CAAC;IAEhD,sDAAsD;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AAM,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;iCAC7B;gCACD,KAAK,EAAE,SAAS;6BACjB,CAAC,CACH,CAAC;4BAEF,qDAAqD;4BACrD,8CAA8C;4BAC9C,oDAAoD;4BACpD,4CAA4C;4BAC5C,yDAAyD;4BACzD,yBAAyB;4BACzB,UAAU,CAAC,KAAK,IAAI,EAAE;gCACpB,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;4BAC3B,CAAC,EAAE,IAAI,CAAC,CAAC;wBACX,CAAC;wBACD,MAAM;gBACV,CAAC;YACH,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,GAAG,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;IACH,CAAC,CAAC,EAAE,CAAC;AACP,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2BE"}
|
@@ -1 +0,0 @@
|
|
1
|
-
export declare const NATS_SERVER = "nats.socialcap.dev:4222";
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"connections.js","sourceRoot":"","sources":["../../../../../../src/mina/encryption/connections.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,yBAAyB,CAAC"}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import { Field, Group } from "o1js";
|
2
|
-
export { CipherText };
|
3
|
-
interface CipherTextObject {
|
4
|
-
cipherText: Field[];
|
5
|
-
publicKey: Group;
|
6
|
-
}
|
7
|
-
declare class CipherText {
|
8
|
-
static stringify(cipherText: CipherTextObject): string;
|
9
|
-
static parse(jsonStr: string): CipherTextObject;
|
10
|
-
static encrypt(message: string, publicId: string): string;
|
11
|
-
static decrypt(cipherText: string, privateKey: string): string;
|
12
|
-
static initialize(): Promise<void>;
|
13
|
-
}
|
@@ -1,39 +0,0 @@
|
|
1
|
-
import { Field, PublicKey, PrivateKey, Encoding, Group, Encryption, initializeBindings, } from "o1js";
|
2
|
-
export { CipherText };
|
3
|
-
class CipherText {
|
4
|
-
static stringify(cipherText) {
|
5
|
-
return JSON.stringify(cipherText);
|
6
|
-
}
|
7
|
-
static parse(jsonStr) {
|
8
|
-
let obj = JSON.parse(jsonStr);
|
9
|
-
return {
|
10
|
-
publicKey: new Group(obj.publicKey),
|
11
|
-
cipherText: (obj.cipherText || []).map((t) => Field(t)),
|
12
|
-
};
|
13
|
-
}
|
14
|
-
static encrypt(message, publicId) {
|
15
|
-
try {
|
16
|
-
let fields = Encoding.stringToFields(message);
|
17
|
-
let encripted = Encryption.encrypt(fields, PublicKey.fromBase58(publicId));
|
18
|
-
return CipherText.stringify(encripted);
|
19
|
-
}
|
20
|
-
catch (err) {
|
21
|
-
throw Error(`Could not encrypt message='${message}' using key='${publicId}'.` +
|
22
|
-
` Error ${err}`);
|
23
|
-
}
|
24
|
-
}
|
25
|
-
static decrypt(cipherText, privateKey) {
|
26
|
-
try {
|
27
|
-
let fields = Encryption.decrypt(CipherText.parse(cipherText), PrivateKey.fromBase58(privateKey));
|
28
|
-
let decrypted = Encoding.stringFromFields(fields);
|
29
|
-
return decrypted;
|
30
|
-
}
|
31
|
-
catch (err) {
|
32
|
-
throw Error(`Could not decrypt cipher='${cipherText}'.` + ` Error ${err}`);
|
33
|
-
}
|
34
|
-
}
|
35
|
-
static async initialize() {
|
36
|
-
await initializeBindings();
|
37
|
-
}
|
38
|
-
}
|
39
|
-
//# sourceMappingURL=encryption.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"encryption.js","sourceRoot":"","sources":["../../../../../../src/mina/encryption/encryption.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,KAAK,EACL,UAAU,EACV,kBAAkB,GACnB,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,UAAU,EAAE,CAAC;AAOtB,MAAM,UAAU;IACd,MAAM,CAAC,SAAS,CAAC,UAA4B;QAC3C,OAAO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,GAAG,UAAU,GAAG,EAAE,CAC9D,CAAC;QACJ,CAAC;IACH,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,UAAU;QACrB,MAAM,kBAAkB,EAAE,CAAC;IAC7B,CAAC;CACF"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/mina/encryption/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
|
@@ -1,3 +0,0 @@
|
|
1
|
-
export declare function postOptionsMessage(clientAddress: string, workerAddress: string): Promise<any>;
|
2
|
-
export declare function postReadyMessage(clientAddress: string, workerAddress: string): Promise<any>;
|
3
|
-
export declare function postDoneMessage(clientAddress: string, encrypted: string): Promise<any>;
|
@@ -1,46 +0,0 @@
|
|
1
|
-
import { connect, JSONCodec } from "nats";
|
2
|
-
import { NATS_SERVER } from "./connections";
|
3
|
-
const codec = JSONCodec();
|
4
|
-
export async function postOptionsMessage(clientAddress, workerAddress) {
|
5
|
-
// connect to the NATS server and send a 'ready' request
|
6
|
-
const nc = await connect({ servers: NATS_SERVER });
|
7
|
-
const msg = await nc.request(`zkcw:${clientAddress}`, codec.encode({
|
8
|
-
"post": "options",
|
9
|
-
"params": { "key": workerAddress }
|
10
|
-
}));
|
11
|
-
const response = codec.decode(msg.data);
|
12
|
-
console.log("Response: ", response);
|
13
|
-
// disconect and clean all pendings
|
14
|
-
await nc.drain();
|
15
|
-
return response;
|
16
|
-
}
|
17
|
-
;
|
18
|
-
export async function postReadyMessage(clientAddress, workerAddress) {
|
19
|
-
// connect to the NATS server and send a 'ready' request
|
20
|
-
const nc = await connect({ servers: NATS_SERVER });
|
21
|
-
const msg = await nc.request(`zkcw:${clientAddress}`, codec.encode({
|
22
|
-
"post": "ready",
|
23
|
-
"params": { "key": workerAddress }
|
24
|
-
}));
|
25
|
-
const response = codec.decode(msg.data);
|
26
|
-
console.log("Response: ", response);
|
27
|
-
// disconect and clean all pendings
|
28
|
-
await nc.drain();
|
29
|
-
return response;
|
30
|
-
}
|
31
|
-
;
|
32
|
-
export async function postDoneMessage(clientAddress, encrypted) {
|
33
|
-
// connect to the NATS server and send a 'ready' request
|
34
|
-
const nc = await connect({ servers: NATS_SERVER });
|
35
|
-
const msg = await nc.request(`zkcw:${clientAddress}`, codec.encode({
|
36
|
-
"post": "done",
|
37
|
-
"params": { "result": encrypted }
|
38
|
-
}));
|
39
|
-
const response = codec.decode(msg.data);
|
40
|
-
console.log("Response: ", response);
|
41
|
-
// disconect and clean all pendings
|
42
|
-
await nc.drain();
|
43
|
-
return response;
|
44
|
-
}
|
45
|
-
;
|
46
|
-
//# sourceMappingURL=messages.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../../../../src/mina/encryption/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;AAE1B,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,aAAqB,EACrB,aAAqB;IAErB,wDAAwD;IACxD,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;IACnD,MAAM,GAAG,GAAQ,MAAM,EAAE,CAAC,OAAO,CAC/B,QAAQ,aAAa,EAAE,EACvB,KAAK,CAAC,MAAM,CAAC;QACX,MAAM,EAAE,SAAS;QACjB,QAAQ,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE;KACnC,C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