mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
added example for signing data
This commit is contained in:
parent
db5831b9c6
commit
80175a7128
1 changed files with 30 additions and 0 deletions
30
examples/companion_sign_data.js
Normal file
30
examples/companion_sign_data.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import TCPConnection from "../src/connection/tcp_connection.js";
|
||||
import NodeJSSerialConnection from "../src/connection/nodejs_serial_connection.js";
|
||||
import {BufferUtils} from "../src/index.js";
|
||||
|
||||
// create connection
|
||||
const connection = new TCPConnection("10.1.0.75", 5000);
|
||||
// const connection = new NodeJSSerialConnection("/dev/cu.usbmodem14401");
|
||||
|
||||
// wait until connected
|
||||
connection.on("connected", async () => {
|
||||
|
||||
// we are now connected
|
||||
console.log("Connected");
|
||||
|
||||
// sign data
|
||||
try {
|
||||
const signature = await connection.sign(Buffer.from("test"));
|
||||
const signatureHex = BufferUtils.bytesToHex(signature);
|
||||
console.log(signatureHex);
|
||||
} catch(e) {
|
||||
console.log("failed to sign", e);
|
||||
}
|
||||
|
||||
// disconnect
|
||||
await connection.close();
|
||||
|
||||
});
|
||||
|
||||
// connect to meshcore device
|
||||
await connection.connect();
|
||||
Loading…
Add table
Add a link
Reference in a new issue