Skip to content

Commit

Permalink
Update protocol and add SendDataRequest nonce (#400)
Browse files Browse the repository at this point in the history
* Update protocol and add SendDataRequest nonce

* Create tasty-baboons-knock.md
  • Loading branch information
lukasIO authored Jan 28, 2025
1 parent 92dce85 commit a8702d4
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-baboons-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-server-sdk": patch
---

Update protocol and add SendDataRequest nonce
2 changes: 1 addition & 1 deletion packages/livekit-server-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"dependencies": {
"@bufbuild/protobuf": "^1.7.2",
"@livekit/protocol": "^1.30.0",
"@livekit/protocol": "^1.32.1",
"camelcase-keys": "^9.0.0",
"jose": "^5.1.2"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/livekit-server-sdk/src/RoomServiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import { ServiceBase } from './ServiceBase.js';
import type { Rpc } from './TwirpRPC.js';
import { TwirpRpc, livekitPackage } from './TwirpRPC.js';
import { getRandomBytes } from './crypto/uuid.js';

/**
* Options for when creating a room
Expand Down Expand Up @@ -383,6 +384,7 @@ export class RoomServiceClient extends ServiceBase {
if (!Array.isArray(options) && options.destinationIdentities) {
req.destinationIdentities = options.destinationIdentities;
}
req.nonce = await getRandomBytes(16);
await this.rpc.request(
svc,
'SendData',
Expand Down
2 changes: 1 addition & 1 deletion packages/livekit-server-sdk/src/WebhookReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import type { BinaryReadOptions, JsonReadOptions, JsonValue } from '@bufbuild/protobuf';
import { WebhookEvent as ProtoWebhookEvent } from '@livekit/protocol';
import { TokenVerifier } from './AccessToken.js';
import { digest } from './digest.js';
import { digest } from './crypto/digest.js';

export const authorizeHeader = 'Authorize';

Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions packages/livekit-server-sdk/src/crypto/uuid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

// Use the Web Crypto API if available, otherwise fallback to Node.js crypto
export async function getRandomBytes(size: number = 16): Promise<Uint8Array> {
if (globalThis.crypto) {
return crypto.getRandomValues(new Uint8Array(size));
} else {
const nodeCrypto = await import('node:crypto');
return nodeCrypto.getRandomValues(new Uint8Array(size));
}
}
11 changes: 9 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a8702d4

Please sign in to comment.