Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
Sign and verify JWS (json web signature) with Ed25519 KeyPair

I want to sign a JWS (json web signature) with a private key generated through Ed25519 on a clients device. Then send this signature to my backend and verify it with the public key. To get familiar with the procedure I want to try to sign and verify a JWS in node js.
Both my private and public key are already generated and are available in base58. This is my current attempt at signing a JWT with an Ed25519 privateKey:

const { SignJWT } = require("jose/jwt/sign");
const bs50 = require("bs58");

async function main() {
  const publicBase58 = "A77GCUCZ7FAuXVMKtwwXyFhMa158XsaoGKHYNnJ1q3pv";
  const privateKeyBase58 = "BE1VM7rTRJReLsTLLG4JMNX5ozcp7qpmMuRht9zB1UjU";

  const publicKeyBuffer = bs50.decode(publicBase58);
  const privateKeyBuffer = bs50.decode(privateKeyBase58);

  const publicKey = new Uint8Array(publicKeyBuffer);
  const privateKey = new Uint8Array(privateKeyBuffer);

  const jwt = await new SignJWT({
    subject: "uuid",
  })
    .setProtectedHeader({ alg: "EdDSA" })
    .setExpirationTime("2h")
    .sign(privateKey);

  console.log(jwt);
}

Error: TypeError: Key must be one of type KeyObject or CryptoKey. Received an instance of Uint8Array

When trying to use the sign() function I get the error above because my privateKey is of type Uint8Array, the only accepted types are KeyObject or CryptoKey but I don't know how I can convert my Uint8Arrays into KeyObjects or CryptoKeys.

I got some code snippets from this answer

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need your keys in a format that Node.js recognizes. KeyObject create*Key APIs recognize and key is compatible with Ed25519 keys, i.e. assuming Node.js >= 16.1.0:

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda