-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.js
30 lines (27 loc) · 889 Bytes
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// SPDX-FileCopyrightText: 2024 the cable.js authors
//
// SPDX-License-Identifier: LGPL-3.0-or-later
const b4a = require("b4a")
// takes the json structure produced by generateKeypair and returns a serialized string representation
// where the buffers have been correctly serialized as hex strings
function serializeKeypair(kp) {
const json = {
publicKey: b4a.toString(kp.publicKey, "hex"),
secretKey: b4a.toString(kp.secretKey, "hex"),
}
return JSON.stringify(json)
}
// takes the json string representation returned by serializeKeypair and converts
// into the structure produced by generateKeypair()
function deserializeKeypair(input) {
const json = JSON.parse(input)
const kp = {
publicKey: b4a.from(json.publicKey, "hex"),
secretKey: b4a.from(json.secretKey, "hex"),
}
return kp
}
module.exports = {
serializeKeypair,
deserializeKeypair
}