How to pass a swarm.key file to preSharedKey

Following @libp2p/pnet | libp2p on how to create a swarm.key programatically.

How can I use a previously created swarm key. I already got the key I need to pass it to

const node = await createLibp2p({
  // ...other options
  connectionProtector: preSharedKey({
    psk: swarmKey
  })
})

I’ve tried just reading the file with fs, but it doesn’t work. I cannot find any examples.

I needed to convert the key to Uint8 like so:

const fileBuffer = fs.readFileSync('swarm.key’);
const swarmKey = new Uint8Array(fileBuffer);

and the pass it:

  connectionProtector: preSharedKey({
    psk: swarmKey,
  }),