User protocol upgrade and js client lib. (#191)

* Unified js client lib for browser and nodejs.
* Client lib multiple connections support.
* Implemented server challenge response.
* Contract guid and version validation.
* Server key validation.
* User json message encoding improvements.
This commit is contained in:
Ravin Perera
2020-12-11 11:02:58 +05:30
committed by GitHub
parent b77a3fc924
commit f2ed9040c0
34 changed files with 1202 additions and 905 deletions

View File

@@ -1,4 +1,4 @@
const { HotPocketContract } = require("./hp-contract-lib");
const HotPocket = require("./hp-contract-lib");
const fs = require('fs');
// HP smart contract is defined as a function which takes HP ExecutionContext as an argument.
@@ -24,10 +24,7 @@ const echoContract = async (ctx) => {
const msg = buf.toString();
const output = (msg == "ts") ? fs.readFileSync("exects.txt").toString() : ("Echoing: " + msg);
// Stringify to escape JSON characters and remove surrounding double quotes.
const stringified = JSON.stringify(output);
await user.send(stringified.substr(1, stringified.length - 2));
await user.send(output);
resolve();
}));
@@ -53,5 +50,5 @@ const echoContract = async (ctx) => {
// }
}
const hpc = new HotPocketContract();
const hpc = new HotPocket.Contract();
hpc.init(echoContract);