Skip to content

Commit 80175a7

Browse files
committed
added example for signing data
1 parent db5831b commit 80175a7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

examples/companion_sign_data.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import TCPConnection from "../src/connection/tcp_connection.js";
2+
import NodeJSSerialConnection from "../src/connection/nodejs_serial_connection.js";
3+
import {BufferUtils} from "../src/index.js";
4+
5+
// create connection
6+
const connection = new TCPConnection("10.1.0.75", 5000);
7+
// const connection = new NodeJSSerialConnection("/dev/cu.usbmodem14401");
8+
9+
// wait until connected
10+
connection.on("connected", async () => {
11+
12+
// we are now connected
13+
console.log("Connected");
14+
15+
// sign data
16+
try {
17+
const signature = await connection.sign(Buffer.from("test"));
18+
const signatureHex = BufferUtils.bytesToHex(signature);
19+
console.log(signatureHex);
20+
} catch(e) {
21+
console.log("failed to sign", e);
22+
}
23+
24+
// disconnect
25+
await connection.close();
26+
27+
});
28+
29+
// connect to meshcore device
30+
await connection.connect();

0 commit comments

Comments
 (0)