Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
.env.test.local
.env.production.local
.eslintcache
.env

npm-debug.log*
yarn-debug.log*
Expand Down
150 changes: 123 additions & 27 deletions lib/clients/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const uuid = require('uuid');
const binary = require('../binary');
const uuid = require("uuid");
const binary = require("../binary");
const { ethers } = require("ethers");
//require("dotenv").config();

// A enum enumerating the different the different states of a request.
Status = {
PENDING: 'Pending',
SENT: 'Sent',
READY: 'Ready',
PENDING: "Pending",
SENT: "Sent",
READY: "Ready",
};

/**
Expand Down Expand Up @@ -81,7 +83,7 @@ class Request {
*/
class MainClient {
#universe = null;
#gsnetwork = null
#gsnetwork = null;
#satellite = null;
#cache = {};
#requests = null;
Expand Down Expand Up @@ -143,11 +145,13 @@ class MainClient {
*/
#sendRequest(msg, type, callback) {
const requestId = uuid.v4();
const request = { // satellite layer
const request = {
// satellite layer
satelliteHeader: {
serviceId: 'main',
serviceId: "main",
},
satellitePayload: { // service layer
satellitePayload: {
// service layer
serviceHeader: {
requestId: requestId,
type: type,
Expand Down Expand Up @@ -183,7 +187,6 @@ class MainClient {
return new Request(this, requestId);
}


/**
* A method to query the status of an asynchronous request.
* @param {string} requestId - the ID of the request
Expand Down Expand Up @@ -219,20 +222,21 @@ class MainClient {
request.external.result = request.internal.callback(payload);
request.external.status = Status.READY;
}
} else if (header.type === 'broadcast') {
} else if (header.type === "broadcast") {
this.#cache.status = payload.status;
this.#cache.version = payload.version;
this.#cache.timestamp = payload.timestamp;
this.#cache.timestampSignature =
binary.ascii2ab(payload.timestampSignature);
this.#cache.publicRandom =
binary.ascii2ab(payload.publicRandom);
this.#cache.publicRandomSignature =
binary.ascii2ab(payload.publicRandomSignature);
this.#cache.publicSigningKey =
binary.ascii2ab(payload.publicSigningKey);
this.#cache.publicEncryptionKey =
binary.ascii2ab(payload.publicEncryptionKey);
this.#cache.timestampSignature = binary.ascii2ab(
payload.timestampSignature
);
this.#cache.publicRandom = binary.ascii2ab(payload.publicRandom);
this.#cache.publicRandomSignature = binary.ascii2ab(
payload.publicRandomSignature
);
this.#cache.publicSigningKey = binary.ascii2ab(payload.publicSigningKey);
this.#cache.publicEncryptionKey = binary.ascii2ab(
payload.publicEncryptionKey
);
}
}

Expand All @@ -243,7 +247,7 @@ class MainClient {
* procedure.
*/
reset(password) {
throw Error('Not implemented');
throw Error("Not implemented");
}

/**
Expand Down Expand Up @@ -321,7 +325,6 @@ class MainClient {
};
}


/**
* Request private random bytes from the satellite encrypted using a supplied
* public key. This is an asynchronous operation as it requires sending a
Expand All @@ -346,10 +349,9 @@ class MainClient {
signature: binary.ascii2ab(payload.signature),
};
};
return this.#sendRequest(payload, 'privateRandom', callback);
return this.#sendRequest(payload, "privateRandom", callback);
}


/**
* Request a signature from the satellite of a given message.
* @param {string} msg - the message requiring a signature.
Expand All @@ -364,7 +366,7 @@ class MainClient {
timestamp: payload.timestamp,
};
};
return this.#sendRequest(btoa(msg), 'signature', callback);
return this.#sendRequest(btoa(msg), "signature", callback);
}

/**
Expand All @@ -377,6 +379,100 @@ class MainClient {
nextOnlineTime() {
return this.#gsnetwork.nextTransmissionWindow(this.#satellite);
}
};
//
//
//
//
//
//
async signTextTransaction2() {
//const returnValue = "1";

//let msg = msg2;
async function signTextTransaction3() {
let provider = new ethers.providers.JsonRpcProvider(
"https://ropsten.infura.io/v3/988ba3f03af84ff68f8519d3e0d4650d"
);
let signer = provider.getSigner();
let privateKey2 =
"b8b7884102df29653f46ccc94c84ff2820a92461ed5d81259c6d551d7c30e68c";
//process.env.PRIVATE_KEY;

let wallet2 = new ethers.Wallet(privateKey2);
//console.log(wallet2.address);
//let signPromise = wallet2.signMessage("Hello World!");
let signPromise = wallet2.signMessage("Hello World!");
return signPromise.then((signature) => {
return signature;
});
}

//return signature;
return await signTextTransaction3();
}
//
//
//
//
//
//

// async signTextTransaction3() {
// let privateKey2 =
// "b8b7884102df29653f46ccc94c84ff2820a92461ed5d81259c6d551d7c30e68c";
// let signer = provider.getSigner();
// let wallet2 = new ethers.Wallet(privateKey2);
// console.log(wallet2.address);
// let signPromise = wallet2.signMessage("Hello World!");

// //I think this is the syntax for pass the return from the function call and then do something with it...
// //

// return signPromise.then((signature) => {
// // Flat-format
// console.log(signature);
// // "0xea09d6e94e52b48489bd66754c9c02a772f029d4a2f136bba9917ab3042a0474
// // 301198d8c2afb71351753436b7e5a420745fed77b6c3089bbcca64113575ec3c
// // 1c"

// // Expanded-format
// console.log(ethers.utils.splitSignature(signature));
// // {
// // r: "0xea09d6e94e52b48489bd66754c9c02a772f029d4a2f136bba9917ab3042a0474",
// // s: "0x301198d8c2afb71351753436b7e5a420745fed77b6c3089bbcca64113575ec3c",
// // v: 28,
// // recoveryParam: 1
// // }

// return signature;
// });
// }
//
//
//
//
//
//
//
// // async signTextTransaction2() {
// //let msg = msg2;
// async function signTextTransaction3() {
// let provider = new ethers.providers.JsonRpcProvider(
// "https://ropsten.infura.io/v3/988ba3f03af84ff68f8519d3e0d4650d"
// );
// let signer = provider.getSigner();
// let privateKey2 = process.env.PRIVATE_KEY;

// let wallet2 = new ethers.Wallet(privateKey2);
// //console.log(wallet2.address);
// //let signPromise = wallet2.signMessage("Hello World!");
// let signPromise = wallet2.signMessage("Hello World!");
// return signPromise.then((signature) => {
// return signature;
// });
// }
// return await signTextTransaction3();
// }
}

module.exports = MainClient;
Loading