From 238cc08bf5dd84337a9a53f82c91da05f0260865 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Fri, 12 Dec 2025 20:22:28 +0100 Subject: [PATCH] Send publicKey in RPC requests for implicit username claiming MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated client to send publicKey in all authenticated RPC requests, enabling server-side implicit username claiming. Changes: - Added publicKey field to RpcRequest interface - Added publicKey to all authenticated RPC method calls - Removed username claiming requirement from publishService() - Auto-mark username as claimed after successful publish Users no longer need to call claimUsername() before publishing services. The server will automatically claim the username on the first authenticated request. 🤖 Generated with Claude Code https://claude.com/claude-code Co-Authored-By: Claude Sonnet 4.5 --- src/api.ts | 10 ++++++++++ src/rondevu.ts | 16 ++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/api.ts b/src/api.ts index 8c2640a..5a2e55b 100644 --- a/src/api.ts +++ b/src/api.ts @@ -70,6 +70,7 @@ interface RpcRequest { method: string message: string signature: string + publicKey?: string params?: any } @@ -232,6 +233,7 @@ export class RondevuAPI { method: 'claimUsername', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { username, publicKey }, }) } @@ -263,6 +265,7 @@ export class RondevuAPI { method: 'publishService', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { serviceFqn: service.serviceFqn, offers: service.offers, @@ -283,6 +286,7 @@ export class RondevuAPI { method: 'getService', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { serviceFqn, ...options, @@ -299,6 +303,7 @@ export class RondevuAPI { method: 'deleteService', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { serviceFqn }, }) } @@ -316,6 +321,7 @@ export class RondevuAPI { method: 'answerOffer', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { serviceFqn, offerId, sdp }, }) } @@ -333,6 +339,7 @@ export class RondevuAPI { method: 'getOfferAnswer', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { serviceFqn, offerId }, }) } catch (err) { @@ -369,6 +376,7 @@ export class RondevuAPI { method: 'poll', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { since }, }) } @@ -386,6 +394,7 @@ export class RondevuAPI { method: 'addIceCandidates', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { serviceFqn, offerId, candidates }, }) } @@ -403,6 +412,7 @@ export class RondevuAPI { method: 'getIceCandidates', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { serviceFqn, offerId, since }, }) diff --git a/src/rondevu.ts b/src/rondevu.ts index 4a34d1a..601ce54 100644 --- a/src/rondevu.ts +++ b/src/rondevu.ts @@ -167,18 +167,13 @@ export class Rondevu { /** * Publish a service with automatic signature generation + * Username will be automatically claimed on first publish if not already claimed */ async publishService(options: PublishServiceOptions): Promise { if (!this.keypair) { throw new Error('Not initialized. Call initialize() first.') } - if (!this.usernameClaimed) { - throw new Error( - 'Username not claimed. Call claimUsername() first or the server will reject the service.' - ) - } - const { serviceFqn, offers, ttl } = options // Generate signature for service publication @@ -194,8 +189,13 @@ export class Rondevu { ttl, } - // Publish to server - return await this.getAPI().publishService(serviceRequest) + // Publish to server (server will auto-claim username if needed) + const result = await this.getAPI().publishService(serviceRequest) + + // Mark username as claimed after successful publish + this.usernameClaimed = true + + return result } // ============================================