From b2d42fa7767600ac63212eba415e4249d7e4c781 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Fri, 5 Dec 2025 19:19:05 +0100 Subject: [PATCH] fix: use async ed25519 functions (signAsync, getPublicKeyAsync) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sync ed25519 functions (sign, getPublicKey) require hashes.sha512, but WebCrypto only provides async digest. Switch to using the async ed25519 API which works with hashes.sha512Async. This fixes the "hashes.sha512 not set" error. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- package.json | 2 +- src/usernames.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index b5e4987..046de54 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xtr-dev/rondevu-client", - "version": "0.8.2", + "version": "0.8.3", "description": "TypeScript client for Rondevu DNS-like WebRTC with username claiming and service discovery", "type": "module", "main": "dist/index.js", diff --git a/src/usernames.ts b/src/usernames.ts index 97d74a6..543fdf3 100644 --- a/src/usernames.ts +++ b/src/usernames.ts @@ -1,7 +1,8 @@ import * as ed25519 from '@noble/ed25519'; // Set SHA-512 hash function for ed25519 (required in @noble/ed25519 v3+) -// Uses built-in WebCrypto API +// Uses built-in WebCrypto API which only provides async digest +// We use the async ed25519 functions (signAsync, verifyAsync, getPublicKeyAsync) ed25519.hashes.sha512Async = async (message: Uint8Array) => { return new Uint8Array(await crypto.subtle.digest('SHA-512', message as BufferSource)); }; @@ -58,7 +59,7 @@ export class RondevuUsername { */ async generateKeypair(): Promise<{ publicKey: string; privateKey: string }> { const privateKey = ed25519.utils.randomSecretKey(); - const publicKey = await ed25519.getPublicKey(privateKey); + const publicKey = await ed25519.getPublicKeyAsync(privateKey); return { publicKey: bytesToBase64(publicKey), @@ -74,7 +75,7 @@ export class RondevuUsername { const encoder = new TextEncoder(); const messageBytes = encoder.encode(message); - const signature = await ed25519.sign(messageBytes, privateKey); + const signature = await ed25519.signAsync(messageBytes, privateKey); return bytesToBase64(signature); }