@xtr-dev/rondevu-client 0.9.2 → 0.10.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 (73) hide show
  1. package/dist/api.d.ts +147 -0
  2. package/dist/api.js +307 -0
  3. package/dist/bin.d.ts +35 -0
  4. package/dist/bin.js +35 -0
  5. package/dist/connection-manager.d.ts +104 -0
  6. package/dist/connection-manager.js +324 -0
  7. package/dist/connection.d.ts +112 -0
  8. package/dist/connection.js +194 -0
  9. package/dist/event-bus.d.ts +52 -0
  10. package/dist/event-bus.js +84 -0
  11. package/dist/index.d.ts +15 -11
  12. package/dist/index.js +9 -11
  13. package/dist/noop-signaler.d.ts +14 -0
  14. package/dist/noop-signaler.js +27 -0
  15. package/dist/rondevu-service.d.ts +81 -0
  16. package/dist/rondevu-service.js +131 -0
  17. package/dist/service-client.d.ts +94 -0
  18. package/dist/service-client.js +186 -0
  19. package/dist/service-host.d.ts +103 -0
  20. package/dist/service-host.js +186 -0
  21. package/dist/signaler.d.ts +25 -0
  22. package/dist/signaler.js +89 -0
  23. package/dist/types.d.ts +33 -0
  24. package/dist/types.js +2 -0
  25. package/dist/webrtc-context.d.ts +7 -0
  26. package/dist/webrtc-context.js +36 -0
  27. package/package.json +16 -2
  28. package/dist/auth.d.ts +0 -20
  29. package/dist/auth.js +0 -41
  30. package/dist/durable/channel.d.ts +0 -115
  31. package/dist/durable/channel.js +0 -301
  32. package/dist/durable/connection.d.ts +0 -125
  33. package/dist/durable/connection.js +0 -370
  34. package/dist/durable/reconnection.d.ts +0 -90
  35. package/dist/durable/reconnection.js +0 -127
  36. package/dist/durable/service.d.ts +0 -103
  37. package/dist/durable/service.js +0 -264
  38. package/dist/durable/types.d.ts +0 -149
  39. package/dist/durable/types.js +0 -28
  40. package/dist/event-emitter.d.ts +0 -54
  41. package/dist/event-emitter.js +0 -102
  42. package/dist/offer-pool.d.ts +0 -86
  43. package/dist/offer-pool.js +0 -145
  44. package/dist/offers.d.ts +0 -101
  45. package/dist/offers.js +0 -202
  46. package/dist/peer/answering-state.d.ts +0 -11
  47. package/dist/peer/answering-state.js +0 -39
  48. package/dist/peer/closed-state.d.ts +0 -8
  49. package/dist/peer/closed-state.js +0 -10
  50. package/dist/peer/connected-state.d.ts +0 -8
  51. package/dist/peer/connected-state.js +0 -11
  52. package/dist/peer/creating-offer-state.d.ts +0 -12
  53. package/dist/peer/creating-offer-state.js +0 -45
  54. package/dist/peer/exchanging-ice-state.d.ts +0 -17
  55. package/dist/peer/exchanging-ice-state.js +0 -64
  56. package/dist/peer/failed-state.d.ts +0 -10
  57. package/dist/peer/failed-state.js +0 -16
  58. package/dist/peer/idle-state.d.ts +0 -7
  59. package/dist/peer/idle-state.js +0 -14
  60. package/dist/peer/index.d.ts +0 -71
  61. package/dist/peer/index.js +0 -176
  62. package/dist/peer/state.d.ts +0 -23
  63. package/dist/peer/state.js +0 -63
  64. package/dist/peer/types.d.ts +0 -43
  65. package/dist/peer/types.js +0 -1
  66. package/dist/peer/waiting-for-answer-state.d.ts +0 -17
  67. package/dist/peer/waiting-for-answer-state.js +0 -60
  68. package/dist/rondevu.d.ts +0 -184
  69. package/dist/rondevu.js +0 -171
  70. package/dist/service-pool.d.ts +0 -123
  71. package/dist/service-pool.js +0 -488
  72. package/dist/usernames.d.ts +0 -79
  73. package/dist/usernames.js +0 -153
package/dist/usernames.js DELETED
@@ -1,153 +0,0 @@
1
- import * as ed25519 from '@noble/ed25519';
2
- // Set SHA-512 hash function for ed25519 (required in @noble/ed25519 v3+)
3
- // Uses built-in WebCrypto API which only provides async digest
4
- // We use the async ed25519 functions (signAsync, verifyAsync, getPublicKeyAsync)
5
- ed25519.hashes.sha512Async = async (message) => {
6
- return new Uint8Array(await crypto.subtle.digest('SHA-512', message));
7
- };
8
- /**
9
- * Convert Uint8Array to base64 string
10
- */
11
- function bytesToBase64(bytes) {
12
- const binString = Array.from(bytes, (byte) => String.fromCodePoint(byte)).join('');
13
- return btoa(binString);
14
- }
15
- /**
16
- * Convert base64 string to Uint8Array
17
- */
18
- function base64ToBytes(base64) {
19
- const binString = atob(base64);
20
- return Uint8Array.from(binString, (char) => char.codePointAt(0));
21
- }
22
- /**
23
- * Rondevu Username API
24
- * Handles username claiming with Ed25519 cryptographic proof
25
- */
26
- export class RondevuUsername {
27
- constructor(baseUrl) {
28
- this.baseUrl = baseUrl;
29
- }
30
- /**
31
- * Generates an Ed25519 keypair for username claiming
32
- */
33
- async generateKeypair() {
34
- const privateKey = ed25519.utils.randomSecretKey();
35
- const publicKey = await ed25519.getPublicKeyAsync(privateKey);
36
- return {
37
- publicKey: bytesToBase64(publicKey),
38
- privateKey: bytesToBase64(privateKey)
39
- };
40
- }
41
- /**
42
- * Signs a message with an Ed25519 private key
43
- */
44
- async signMessage(message, privateKeyBase64) {
45
- const privateKey = base64ToBytes(privateKeyBase64);
46
- const encoder = new TextEncoder();
47
- const messageBytes = encoder.encode(message);
48
- const signature = await ed25519.signAsync(messageBytes, privateKey);
49
- return bytesToBase64(signature);
50
- }
51
- /**
52
- * Claims a username
53
- * Generates a new keypair if one is not provided
54
- */
55
- async claimUsername(username, existingKeypair) {
56
- // Generate or use existing keypair
57
- const keypair = existingKeypair || await this.generateKeypair();
58
- // Create signed message
59
- const timestamp = Date.now();
60
- const message = `claim:${username}:${timestamp}`;
61
- const signature = await this.signMessage(message, keypair.privateKey);
62
- // Send claim request
63
- const response = await fetch(`${this.baseUrl}/usernames/claim`, {
64
- method: 'POST',
65
- headers: { 'Content-Type': 'application/json' },
66
- body: JSON.stringify({
67
- username,
68
- publicKey: keypair.publicKey,
69
- signature,
70
- message
71
- })
72
- });
73
- if (!response.ok) {
74
- const error = await response.json();
75
- throw new Error(error.error || 'Failed to claim username');
76
- }
77
- const data = await response.json();
78
- return {
79
- username: data.username,
80
- publicKey: keypair.publicKey,
81
- privateKey: keypair.privateKey,
82
- claimedAt: data.claimedAt,
83
- expiresAt: data.expiresAt
84
- };
85
- }
86
- /**
87
- * Checks if a username is available
88
- */
89
- async checkUsername(username) {
90
- const response = await fetch(`${this.baseUrl}/usernames/${username}`);
91
- if (!response.ok) {
92
- throw new Error('Failed to check username');
93
- }
94
- const data = await response.json();
95
- return {
96
- username: data.username,
97
- available: data.available,
98
- claimedAt: data.claimedAt,
99
- expiresAt: data.expiresAt,
100
- publicKey: data.publicKey
101
- };
102
- }
103
- /**
104
- * Helper: Save keypair to localStorage
105
- * WARNING: This stores the private key in localStorage which is not the most secure
106
- * For production use, consider using IndexedDB with encryption or hardware security modules
107
- */
108
- saveKeypairToStorage(username, publicKey, privateKey) {
109
- const data = { username, publicKey, privateKey, savedAt: Date.now() };
110
- localStorage.setItem(`rondevu:keypair:${username}`, JSON.stringify(data));
111
- }
112
- /**
113
- * Helper: Load keypair from localStorage
114
- */
115
- loadKeypairFromStorage(username) {
116
- const stored = localStorage.getItem(`rondevu:keypair:${username}`);
117
- if (!stored)
118
- return null;
119
- try {
120
- const data = JSON.parse(stored);
121
- return { publicKey: data.publicKey, privateKey: data.privateKey };
122
- }
123
- catch {
124
- return null;
125
- }
126
- }
127
- /**
128
- * Helper: Delete keypair from localStorage
129
- */
130
- deleteKeypairFromStorage(username) {
131
- localStorage.removeItem(`rondevu:keypair:${username}`);
132
- }
133
- /**
134
- * Export keypair as JSON string (for backup)
135
- */
136
- exportKeypair(publicKey, privateKey) {
137
- return JSON.stringify({
138
- publicKey,
139
- privateKey,
140
- exportedAt: Date.now()
141
- });
142
- }
143
- /**
144
- * Import keypair from JSON string
145
- */
146
- importKeypair(json) {
147
- const data = JSON.parse(json);
148
- if (!data.publicKey || !data.privateKey) {
149
- throw new Error('Invalid keypair format');
150
- }
151
- return { publicKey: data.publicKey, privateKey: data.privateKey };
152
- }
153
- }