From 62bbdc20c0922507139c024cb8c95978d3348da0 Mon Sep 17 00:00:00 2001 From: Lucas Barrena Date: Sat, 21 Oct 2023 14:26:12 -0300 Subject: [PATCH] Test uses z32 --- test/helpers/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/helpers/index.js b/test/helpers/index.js index a9ba45f..2a061f1 100644 --- a/test/helpers/index.js +++ b/test/helpers/index.js @@ -7,6 +7,7 @@ const { spawn } = require('child_process') const createTestnet = require('hyperdht/testnet') const DHT = require('hyperdht') const Keychain = require('keypear') +const HypercoreId = require('hypercore-id-encoding') const BIN_KEYGEN = path.join(__dirname, '..', '..', 'bin/keygen.js') const BIN_SERVER = path.join(__dirname, '..', '..', 'bin/server.js') @@ -109,15 +110,15 @@ function spawnCopy (t, source, target, { clientkey }) { function keygen (keyfile) { const seed = Keychain.seed() fs.mkdirSync(path.dirname(keyfile), { recursive: true }) - fs.writeFileSync(keyfile, seed.toString('hex') + '\n', { flag: 'wx' }) + fs.writeFileSync(keyfile, HypercoreId.encode(seed) + '\n', { flag: 'wx' }) return DHT.keyPair(seed) } function addAuthorizedPeer (firewall, keyfile) { - const seed = Buffer.from(fs.readFileSync(keyfile, 'utf8'), 'hex') + const seed = HypercoreId.decode(fs.readFileSync(keyfile, 'utf8').trim()) const keyPair = DHT.keyPair(seed) if (!fs.existsSync(firewall)) fs.writeFileSync(firewall, '# \n', { flag: 'wx' }) - fs.appendFileSync(firewall, keyPair.publicKey.toString('hex') + '\n') + fs.appendFileSync(firewall, HypercoreId.encode(keyPair.publicKey) + '\n') } async function useTestnet (t) {