@xtr-dev/rondevu-client 0.18.10 → 0.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +92 -117
  2. package/dist/api/batcher.d.ts +83 -0
  3. package/dist/api/batcher.js +155 -0
  4. package/dist/api/client.d.ts +198 -0
  5. package/dist/api/client.js +400 -0
  6. package/dist/{answerer-connection.d.ts → connections/answerer.d.ts} +25 -8
  7. package/dist/{answerer-connection.js → connections/answerer.js} +70 -48
  8. package/dist/{connection.d.ts → connections/base.d.ts} +30 -7
  9. package/dist/{connection.js → connections/base.js} +65 -14
  10. package/dist/connections/config.d.ts +51 -0
  11. package/dist/{connection-config.js → connections/config.js} +20 -0
  12. package/dist/{connection-events.d.ts → connections/events.d.ts} +6 -6
  13. package/dist/connections/offerer.d.ts +108 -0
  14. package/dist/connections/offerer.js +306 -0
  15. package/dist/core/ice-config.d.ts +35 -0
  16. package/dist/core/ice-config.js +111 -0
  17. package/dist/core/index.d.ts +22 -0
  18. package/dist/core/index.js +22 -0
  19. package/dist/core/offer-pool.d.ts +113 -0
  20. package/dist/core/offer-pool.js +281 -0
  21. package/dist/core/peer.d.ts +155 -0
  22. package/dist/core/peer.js +252 -0
  23. package/dist/core/polling-manager.d.ts +71 -0
  24. package/dist/core/polling-manager.js +122 -0
  25. package/dist/core/rondevu-errors.d.ts +59 -0
  26. package/dist/core/rondevu-errors.js +75 -0
  27. package/dist/core/rondevu-types.d.ts +125 -0
  28. package/dist/core/rondevu-types.js +6 -0
  29. package/dist/core/rondevu.d.ts +296 -0
  30. package/dist/core/rondevu.js +472 -0
  31. package/dist/crypto/adapter.d.ts +53 -0
  32. package/dist/crypto/node.d.ts +57 -0
  33. package/dist/crypto/node.js +149 -0
  34. package/dist/crypto/web.d.ts +38 -0
  35. package/dist/crypto/web.js +129 -0
  36. package/dist/utils/async-lock.d.ts +42 -0
  37. package/dist/utils/async-lock.js +75 -0
  38. package/dist/{message-buffer.d.ts → utils/message-buffer.d.ts} +1 -1
  39. package/dist/{message-buffer.js → utils/message-buffer.js} +4 -4
  40. package/dist/webrtc/adapter.d.ts +22 -0
  41. package/dist/webrtc/adapter.js +5 -0
  42. package/dist/webrtc/browser.d.ts +12 -0
  43. package/dist/webrtc/browser.js +15 -0
  44. package/dist/webrtc/node.d.ts +32 -0
  45. package/dist/webrtc/node.js +32 -0
  46. package/package.json +20 -9
  47. package/dist/api.d.ts +0 -146
  48. package/dist/api.js +0 -279
  49. package/dist/connection-config.d.ts +0 -21
  50. package/dist/crypto-adapter.d.ts +0 -37
  51. package/dist/index.d.ts +0 -13
  52. package/dist/index.js +0 -10
  53. package/dist/node-crypto-adapter.d.ts +0 -35
  54. package/dist/node-crypto-adapter.js +0 -78
  55. package/dist/offerer-connection.d.ts +0 -54
  56. package/dist/offerer-connection.js +0 -177
  57. package/dist/rondevu-signaler.d.ts +0 -112
  58. package/dist/rondevu-signaler.js +0 -401
  59. package/dist/rondevu.d.ts +0 -407
  60. package/dist/rondevu.js +0 -847
  61. package/dist/rpc-batcher.d.ts +0 -61
  62. package/dist/rpc-batcher.js +0 -111
  63. package/dist/web-crypto-adapter.d.ts +0 -16
  64. package/dist/web-crypto-adapter.js +0 -52
  65. /package/dist/{connection-events.js → connections/events.js} +0 -0
  66. /package/dist/{types.d.ts → core/types.d.ts} +0 -0
  67. /package/dist/{types.js → core/types.js} +0 -0
  68. /package/dist/{crypto-adapter.js → crypto/adapter.js} +0 -0
  69. /package/dist/{exponential-backoff.d.ts → utils/exponential-backoff.d.ts} +0 -0
  70. /package/dist/{exponential-backoff.js → utils/exponential-backoff.js} +0 -0
@@ -1,61 +0,0 @@
1
- /**
2
- * RPC Batcher - Throttles and batches RPC requests to reduce HTTP overhead
3
- */
4
- export interface BatcherOptions {
5
- /**
6
- * Maximum number of requests to batch together
7
- * Default: 10
8
- */
9
- maxBatchSize?: number;
10
- /**
11
- * Maximum time to wait before sending a batch (ms)
12
- * Default: 50ms
13
- */
14
- maxWaitTime?: number;
15
- /**
16
- * Minimum time between batches (ms)
17
- * Default: 10ms
18
- */
19
- throttleInterval?: number;
20
- }
21
- /**
22
- * Batches and throttles RPC requests to optimize network usage
23
- *
24
- * @example
25
- * ```typescript
26
- * const batcher = new RpcBatcher(
27
- * (requests) => api.rpcBatch(requests),
28
- * { maxBatchSize: 10, maxWaitTime: 50 }
29
- * )
30
- *
31
- * // These will be batched together if called within maxWaitTime
32
- * const result1 = await batcher.add(request1)
33
- * const result2 = await batcher.add(request2)
34
- * const result3 = await batcher.add(request3)
35
- * ```
36
- */
37
- export declare class RpcBatcher {
38
- private queue;
39
- private batchTimeout;
40
- private lastBatchTime;
41
- private options;
42
- private sendBatch;
43
- constructor(sendBatch: (requests: any[]) => Promise<any[]>, options?: BatcherOptions);
44
- /**
45
- * Add an RPC request to the batch queue
46
- * Returns a promise that resolves when the request completes
47
- */
48
- add(request: any): Promise<any>;
49
- /**
50
- * Flush the queue immediately
51
- */
52
- flush(): Promise<void>;
53
- /**
54
- * Get current queue size
55
- */
56
- getQueueSize(): number;
57
- /**
58
- * Clear the queue without sending
59
- */
60
- clear(): void;
61
- }
@@ -1,111 +0,0 @@
1
- /**
2
- * RPC Batcher - Throttles and batches RPC requests to reduce HTTP overhead
3
- */
4
- /**
5
- * Batches and throttles RPC requests to optimize network usage
6
- *
7
- * @example
8
- * ```typescript
9
- * const batcher = new RpcBatcher(
10
- * (requests) => api.rpcBatch(requests),
11
- * { maxBatchSize: 10, maxWaitTime: 50 }
12
- * )
13
- *
14
- * // These will be batched together if called within maxWaitTime
15
- * const result1 = await batcher.add(request1)
16
- * const result2 = await batcher.add(request2)
17
- * const result3 = await batcher.add(request3)
18
- * ```
19
- */
20
- export class RpcBatcher {
21
- constructor(sendBatch, options) {
22
- this.queue = [];
23
- this.batchTimeout = null;
24
- this.lastBatchTime = 0;
25
- this.sendBatch = sendBatch;
26
- this.options = {
27
- maxBatchSize: options?.maxBatchSize ?? 10,
28
- maxWaitTime: options?.maxWaitTime ?? 50,
29
- throttleInterval: options?.throttleInterval ?? 10,
30
- };
31
- }
32
- /**
33
- * Add an RPC request to the batch queue
34
- * Returns a promise that resolves when the request completes
35
- */
36
- async add(request) {
37
- return new Promise((resolve, reject) => {
38
- this.queue.push({ request, resolve, reject });
39
- // Send immediately if batch is full
40
- if (this.queue.length >= this.options.maxBatchSize) {
41
- this.flush();
42
- return;
43
- }
44
- // Schedule batch if not already scheduled
45
- if (!this.batchTimeout) {
46
- this.batchTimeout = setTimeout(() => {
47
- this.flush();
48
- }, this.options.maxWaitTime);
49
- }
50
- });
51
- }
52
- /**
53
- * Flush the queue immediately
54
- */
55
- async flush() {
56
- // Clear timeout if set
57
- if (this.batchTimeout) {
58
- clearTimeout(this.batchTimeout);
59
- this.batchTimeout = null;
60
- }
61
- // Nothing to flush
62
- if (this.queue.length === 0) {
63
- return;
64
- }
65
- // Throttle: wait if we sent a batch too recently
66
- const now = Date.now();
67
- const timeSinceLastBatch = now - this.lastBatchTime;
68
- if (timeSinceLastBatch < this.options.throttleInterval) {
69
- const waitTime = this.options.throttleInterval - timeSinceLastBatch;
70
- await new Promise(resolve => setTimeout(resolve, waitTime));
71
- }
72
- // Extract requests from queue
73
- const batch = this.queue.splice(0, this.options.maxBatchSize);
74
- const requests = batch.map(item => item.request);
75
- this.lastBatchTime = Date.now();
76
- try {
77
- // Send batch request
78
- const results = await this.sendBatch(requests);
79
- // Resolve individual promises
80
- for (let i = 0; i < batch.length; i++) {
81
- batch[i].resolve(results[i]);
82
- }
83
- }
84
- catch (error) {
85
- // Reject all promises in batch
86
- for (const item of batch) {
87
- item.reject(error);
88
- }
89
- }
90
- }
91
- /**
92
- * Get current queue size
93
- */
94
- getQueueSize() {
95
- return this.queue.length;
96
- }
97
- /**
98
- * Clear the queue without sending
99
- */
100
- clear() {
101
- if (this.batchTimeout) {
102
- clearTimeout(this.batchTimeout);
103
- this.batchTimeout = null;
104
- }
105
- // Reject all pending requests
106
- for (const item of this.queue) {
107
- item.reject(new Error('Batch queue cleared'));
108
- }
109
- this.queue = [];
110
- }
111
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * Web Crypto adapter for browser environments
3
- */
4
- import { CryptoAdapter, Keypair } from './crypto-adapter.js';
5
- /**
6
- * Web Crypto implementation using browser APIs
7
- * Uses btoa/atob for base64 encoding and crypto.getRandomValues for random bytes
8
- */
9
- export declare class WebCryptoAdapter implements CryptoAdapter {
10
- generateKeypair(): Promise<Keypair>;
11
- signMessage(message: string, privateKeyBase64: string): Promise<string>;
12
- verifySignature(message: string, signatureBase64: string, publicKeyBase64: string): Promise<boolean>;
13
- bytesToBase64(bytes: Uint8Array): string;
14
- base64ToBytes(base64: string): Uint8Array;
15
- randomBytes(length: number): Uint8Array;
16
- }
@@ -1,52 +0,0 @@
1
- /**
2
- * Web Crypto adapter for browser environments
3
- */
4
- import * as ed25519 from '@noble/ed25519';
5
- // Set SHA-512 hash function for ed25519 (required in @noble/ed25519 v3+)
6
- ed25519.hashes.sha512Async = async (message) => {
7
- return new Uint8Array(await crypto.subtle.digest('SHA-512', message));
8
- };
9
- /**
10
- * Web Crypto implementation using browser APIs
11
- * Uses btoa/atob for base64 encoding and crypto.getRandomValues for random bytes
12
- */
13
- export class WebCryptoAdapter {
14
- async generateKeypair() {
15
- const privateKey = ed25519.utils.randomSecretKey();
16
- const publicKey = await ed25519.getPublicKeyAsync(privateKey);
17
- return {
18
- publicKey: this.bytesToBase64(publicKey),
19
- privateKey: this.bytesToBase64(privateKey),
20
- };
21
- }
22
- async signMessage(message, privateKeyBase64) {
23
- const privateKey = this.base64ToBytes(privateKeyBase64);
24
- const encoder = new TextEncoder();
25
- const messageBytes = encoder.encode(message);
26
- const signature = await ed25519.signAsync(messageBytes, privateKey);
27
- return this.bytesToBase64(signature);
28
- }
29
- async verifySignature(message, signatureBase64, publicKeyBase64) {
30
- try {
31
- const signature = this.base64ToBytes(signatureBase64);
32
- const publicKey = this.base64ToBytes(publicKeyBase64);
33
- const encoder = new TextEncoder();
34
- const messageBytes = encoder.encode(message);
35
- return await ed25519.verifyAsync(signature, messageBytes, publicKey);
36
- }
37
- catch {
38
- return false;
39
- }
40
- }
41
- bytesToBase64(bytes) {
42
- const binString = Array.from(bytes, byte => String.fromCodePoint(byte)).join('');
43
- return btoa(binString);
44
- }
45
- base64ToBytes(base64) {
46
- const binString = atob(base64);
47
- return Uint8Array.from(binString, char => char.codePointAt(0));
48
- }
49
- randomBytes(length) {
50
- return crypto.getRandomValues(new Uint8Array(length));
51
- }
52
- }
File without changes
File without changes
File without changes