@abraca/dabra 2.90.0 → 2.91.0

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 (71) hide show
  1. package/package.json +5 -11
  2. package/src/AbracadabraBaseProvider.ts +0 -963
  3. package/src/AbracadabraClient.ts +0 -1960
  4. package/src/AbracadabraProvider.ts +0 -915
  5. package/src/AbracadabraWS.ts +0 -695
  6. package/src/BackgroundSyncManager.ts +0 -856
  7. package/src/BackgroundSyncPersistence.ts +0 -140
  8. package/src/ChatClient.ts +0 -314
  9. package/src/CloseEvents.ts +0 -49
  10. package/src/ContentManager.ts +0 -246
  11. package/src/CoverReconcile.ts +0 -168
  12. package/src/CryptoIdentityKeystore.ts +0 -754
  13. package/src/DeviceRegistrationService.ts +0 -257
  14. package/src/DocConverters.ts +0 -1859
  15. package/src/DocKeyManager.ts +0 -163
  16. package/src/DocTypes.ts +0 -628
  17. package/src/DocUtils.ts +0 -251
  18. package/src/DocumentCache.ts +0 -210
  19. package/src/DocumentManager.ts +0 -410
  20. package/src/E2EAbracadabraProvider.ts +0 -426
  21. package/src/E2EOfflineStore.ts +0 -55
  22. package/src/EncryptedChatClient.ts +0 -173
  23. package/src/EncryptedY.ts +0 -145
  24. package/src/EventEmitter.ts +0 -59
  25. package/src/FileBlobStore.ts +0 -569
  26. package/src/IdentityDoc.ts +0 -711
  27. package/src/IncomingMessage.ts +0 -63
  28. package/src/MessageReceiver.ts +0 -151
  29. package/src/MessageSender.ts +0 -22
  30. package/src/MetaManager.ts +0 -194
  31. package/src/MnemonicKeyDerivation.ts +0 -171
  32. package/src/NodeConnect.ts +0 -63
  33. package/src/NodeIdentity.ts +0 -378
  34. package/src/NotificationsClient.ts +0 -207
  35. package/src/OfflineStore.ts +0 -294
  36. package/src/OutgoingMessage.ts +0 -25
  37. package/src/OutgoingMessages/AuthenticationMessage.ts +0 -23
  38. package/src/OutgoingMessages/AwarenessMessage.ts +0 -41
  39. package/src/OutgoingMessages/CloseMessage.ts +0 -17
  40. package/src/OutgoingMessages/QueryAwarenessMessage.ts +0 -17
  41. package/src/OutgoingMessages/StatelessMessage.ts +0 -18
  42. package/src/OutgoingMessages/SubdocMessage.ts +0 -35
  43. package/src/OutgoingMessages/SyncStepOneMessage.ts +0 -25
  44. package/src/OutgoingMessages/SyncStepTwoMessage.ts +0 -25
  45. package/src/OutgoingMessages/UpdateMessage.ts +0 -20
  46. package/src/QueryClient.ts +0 -209
  47. package/src/RpcClient.ts +0 -659
  48. package/src/SchemaTypes.ts +0 -179
  49. package/src/SearchIndex.ts +0 -250
  50. package/src/ServerRegistry.ts +0 -220
  51. package/src/ServerReset.ts +0 -222
  52. package/src/TokenManager.ts +0 -337
  53. package/src/TreeManager.ts +0 -894
  54. package/src/TreeTimestamps.ts +0 -101
  55. package/src/auth.ts +0 -62
  56. package/src/awarenessStatesToArray.ts +0 -10
  57. package/src/index.ts +0 -219
  58. package/src/messageRecord.ts +0 -121
  59. package/src/sync/BroadcastChannelSync.ts +0 -235
  60. package/src/types.ts +0 -790
  61. package/src/webrtc/AbracadabraWebRTC.ts +0 -683
  62. package/src/webrtc/DataChannelRouter.ts +0 -179
  63. package/src/webrtc/DevicePairingChannel.ts +0 -496
  64. package/src/webrtc/E2EEChannel.ts +0 -195
  65. package/src/webrtc/FileTransferChannel.ts +0 -367
  66. package/src/webrtc/ManualSignaling.ts +0 -204
  67. package/src/webrtc/PeerConnection.ts +0 -133
  68. package/src/webrtc/SignalingSocket.ts +0 -378
  69. package/src/webrtc/YjsDataChannel.ts +0 -203
  70. package/src/webrtc/index.ts +0 -26
  71. package/src/webrtc/types.ts +0 -177
@@ -1,195 +0,0 @@
1
- /**
2
- * E2EEChannel
3
- *
4
- * Per-peer end-to-end encryption for WebRTC data channels using
5
- * X25519 ECDH key agreement + HKDF-SHA256 + AES-256-GCM.
6
- *
7
- * Leverages the same cryptographic primitives as `DocKeyManager` and
8
- * `CryptoIdentityKeystore` but applied to data channel messages rather
9
- * than stored document keys.
10
- *
11
- * Key agreement flow:
12
- * 1. Both peers exchange Ed25519 public keys via the `key-exchange` data channel
13
- * 2. Convert Ed25519 → X25519 (Montgomery form)
14
- * 3. Run X25519 ECDH to derive a shared secret
15
- * 4. HKDF-SHA256(sharedSecret, salt, info) → 32-byte AES-256-GCM session key
16
- * 5. All subsequent data channel messages are encrypted with this key
17
- *
18
- * Message wire format: [12-byte nonce || AES-256-GCM ciphertext]
19
- *
20
- * Dependencies: @noble/curves (already in the project for CryptoIdentityKeystore)
21
- */
22
-
23
- import { x25519, ed25519 as nobleEd25519 } from "@noble/curves/ed25519.js";
24
- import { hkdf } from "@noble/hashes/hkdf.js";
25
- import { sha256 } from "@noble/hashes/sha2.js";
26
- import EventEmitter from "../EventEmitter.ts";
27
-
28
- const HKDF_INFO = new TextEncoder().encode("abracadabra-webrtc-e2ee-v1");
29
- const NONCE_BYTES = 12;
30
-
31
- export interface E2EEIdentity {
32
- /** Raw 32-byte Ed25519 public key. */
33
- publicKey: Uint8Array;
34
- /** Raw 32-byte X25519 private key. Caller must wipe after E2EEChannel.destroy(). */
35
- x25519PrivateKey: Uint8Array;
36
- }
37
-
38
- export class E2EEChannel extends EventEmitter {
39
- private sessionKey: CryptoKey | null = null;
40
- private remotePublicKey: Uint8Array | null = null;
41
- private _isEstablished = false;
42
-
43
- constructor(
44
- private readonly identity: E2EEIdentity,
45
- private readonly docId: string,
46
- ) {
47
- super();
48
- }
49
-
50
- get isEstablished(): boolean {
51
- return this._isEstablished;
52
- }
53
-
54
- /**
55
- * Process a key-exchange message from the remote peer.
56
- * Called when the `key-exchange` data channel receives a message.
57
- *
58
- * The message is the remote peer's raw 32-byte Ed25519 public key.
59
- * After receiving it, ECDH is computed and the session key derived.
60
- */
61
- async handleKeyExchange(remoteEdPubKey: Uint8Array): Promise<void> {
62
- if (remoteEdPubKey.length !== 32) {
63
- this.emit("error", new Error("Invalid remote public key length"));
64
- return;
65
- }
66
-
67
- this.remotePublicKey = remoteEdPubKey;
68
-
69
- // Convert remote Ed25519 public key to X25519 (Montgomery form).
70
- const remoteX25519Pub = nobleEd25519.utils.toMontgomery(remoteEdPubKey);
71
-
72
- // X25519 ECDH: compute shared secret.
73
- const sharedSecret = x25519.getSharedSecret(
74
- this.identity.x25519PrivateKey,
75
- remoteX25519Pub,
76
- );
77
-
78
- // Deterministic salt: docId + sorted public keys (ensures both peers derive the same key).
79
- const localPub = this.identity.publicKey;
80
- const remotePub = remoteEdPubKey;
81
- const [first, second] = this.sortKeys(localPub, remotePub);
82
- const saltParts = [
83
- new TextEncoder().encode(this.docId),
84
- first,
85
- second,
86
- ];
87
- const salt = new Uint8Array(
88
- saltParts.reduce((acc, p) => acc + p.length, 0),
89
- );
90
- let offset = 0;
91
- for (const part of saltParts) {
92
- salt.set(part, offset);
93
- offset += part.length;
94
- }
95
-
96
- // HKDF-SHA256 → 32-byte AES key.
97
- const keyBytes = hkdf(sha256, sharedSecret, salt, HKDF_INFO, 32);
98
-
99
- this.sessionKey = await crypto.subtle.importKey(
100
- "raw",
101
- keyBytes as BufferSource,
102
- { name: "AES-GCM" },
103
- false,
104
- ["encrypt", "decrypt"],
105
- );
106
-
107
- this._isEstablished = true;
108
- this.emit("established", { remotePublicKey: remoteEdPubKey });
109
- }
110
-
111
- /**
112
- * Returns the local Ed25519 public key to send to the remote peer
113
- * via the `key-exchange` data channel.
114
- */
115
- getKeyExchangeMessage(): Uint8Array {
116
- return this.identity.publicKey;
117
- }
118
-
119
- /**
120
- * Encrypt a message for sending over a data channel.
121
- * Returns `[12-byte nonce || AES-256-GCM ciphertext]`.
122
- *
123
- * @throws if the session key has not been established yet.
124
- */
125
- async encrypt(plaintext: Uint8Array): Promise<Uint8Array> {
126
- if (!this.sessionKey) {
127
- throw new Error("E2EE session key not established");
128
- }
129
-
130
- const nonce = crypto.getRandomValues(new Uint8Array(NONCE_BYTES));
131
- const ciphertext = new Uint8Array(
132
- await crypto.subtle.encrypt(
133
- { name: "AES-GCM", iv: nonce as BufferSource },
134
- this.sessionKey,
135
- plaintext as BufferSource,
136
- ),
137
- );
138
-
139
- // Wire format: [nonce(12) || ciphertext].
140
- const result = new Uint8Array(NONCE_BYTES + ciphertext.length);
141
- result.set(nonce, 0);
142
- result.set(ciphertext, NONCE_BYTES);
143
- return result;
144
- }
145
-
146
- /**
147
- * Decrypt a message received from a data channel.
148
- * Expects `[12-byte nonce || AES-256-GCM ciphertext]`.
149
- *
150
- * @throws if the session key has not been established or decryption fails.
151
- */
152
- async decrypt(data: Uint8Array): Promise<Uint8Array> {
153
- if (!this.sessionKey) {
154
- throw new Error("E2EE session key not established");
155
- }
156
-
157
- if (data.length < NONCE_BYTES + 16) {
158
- // Minimum: nonce + AES-GCM tag (16 bytes).
159
- throw new Error("E2EE ciphertext too short");
160
- }
161
-
162
- const nonce = data.slice(0, NONCE_BYTES);
163
- const ciphertext = data.slice(NONCE_BYTES);
164
-
165
- const plaintext = await crypto.subtle.decrypt(
166
- { name: "AES-GCM", iv: nonce },
167
- this.sessionKey,
168
- ciphertext,
169
- );
170
-
171
- return new Uint8Array(plaintext);
172
- }
173
-
174
- /** Destroy the session key and wipe sensitive material. */
175
- destroy(): void {
176
- this.sessionKey = null;
177
- this.remotePublicKey = null;
178
- this._isEstablished = false;
179
- this.removeAllListeners();
180
- }
181
-
182
- // ── Private ──────────────────────────────────────────────────────────────
183
-
184
- /** Sort two keys lexicographically so both peers produce the same order. */
185
- private sortKeys(
186
- a: Uint8Array,
187
- b: Uint8Array,
188
- ): [Uint8Array, Uint8Array] {
189
- for (let i = 0; i < Math.min(a.length, b.length); i++) {
190
- if (a[i] < b[i]) return [a, b];
191
- if (a[i] > b[i]) return [b, a];
192
- }
193
- return a.length <= b.length ? [a, b] : [b, a];
194
- }
195
- }
@@ -1,367 +0,0 @@
1
- import EventEmitter from "../EventEmitter.ts";
2
- import { DataChannelRouter } from "./DataChannelRouter.ts";
3
- import {
4
- CHANNEL_NAMES,
5
- FILE_MSG,
6
- DEFAULT_FILE_CHUNK_SIZE,
7
- TRANSFER_ID_BYTES,
8
- SHA256_BYTES,
9
- type FileTransferMeta,
10
- type FileTransferStatus,
11
- } from "./types.ts";
12
-
13
- /**
14
- * Handle for tracking a file transfer in progress.
15
- */
16
- export class FileTransferHandle extends EventEmitter {
17
- public readonly transferId: string;
18
- public progress = 0;
19
- public status: FileTransferStatus = "pending";
20
-
21
- private abortController = new AbortController();
22
-
23
- constructor(transferId: string) {
24
- super();
25
- this.transferId = transferId;
26
- }
27
-
28
- cancel(): void {
29
- this.status = "cancelled";
30
- this.abortController.abort();
31
- this.emit("cancelled");
32
- }
33
-
34
- get signal(): AbortSignal {
35
- return this.abortController.signal;
36
- }
37
-
38
- /** @internal */
39
- _setProgress(p: number): void {
40
- this.progress = p;
41
- this.emit("progress", p);
42
- }
43
-
44
- /** @internal */
45
- _setStatus(s: FileTransferStatus): void {
46
- this.status = s;
47
- }
48
-
49
- /** @internal — public alias for the protected emit so the parent
50
- * `FileTransferChannel` (a different class instance) can dispatch events
51
- * on this handle. Protected access is by-class, not by-hierarchy. */
52
- _emit(event: string, ...args: unknown[]): void {
53
- this.emit(event, ...args);
54
- }
55
- }
56
-
57
- interface ReceiveState {
58
- meta: FileTransferMeta;
59
- chunks: (Uint8Array | null)[];
60
- receivedCount: number;
61
- }
62
-
63
- /**
64
- * Chunked binary file transfer over a dedicated WebRTC data channel.
65
- */
66
- export class FileTransferChannel extends EventEmitter {
67
- private receives = new Map<string, ReceiveState>();
68
- private chunkSize: number;
69
- private channelMessageHandler: ((data: { name: string; data: any }) => void) | null = null;
70
-
71
- constructor(
72
- private readonly router: DataChannelRouter,
73
- chunkSize?: number,
74
- ) {
75
- super();
76
- this.chunkSize = chunkSize ?? DEFAULT_FILE_CHUNK_SIZE;
77
-
78
- this.channelMessageHandler = ({ name, data }: { name: string; data: any }) => {
79
- if (name === CHANNEL_NAMES.FILE_TRANSFER) {
80
- this.handleMessage(data);
81
- }
82
- };
83
- this.router.on("channelMessage", this.channelMessageHandler);
84
- }
85
-
86
- /** Send a file to a peer. Returns a handle for tracking progress. */
87
- async send(
88
- file: File | Blob,
89
- filename: string,
90
- ): Promise<FileTransferHandle> {
91
- const transferId = generateTransferId();
92
- const handle = new FileTransferHandle(transferId);
93
- const transferIdBytes = hexToBytes(transferId);
94
-
95
- const totalSize = file.size;
96
- const totalChunks = Math.ceil(totalSize / this.chunkSize);
97
- const mimeType =
98
- file instanceof File ? file.type : "application/octet-stream";
99
-
100
- const meta: FileTransferMeta = {
101
- transferId,
102
- filename,
103
- mimeType,
104
- totalSize,
105
- chunkSize: this.chunkSize,
106
- totalChunks,
107
- };
108
-
109
- const channel = this.router.getChannel(CHANNEL_NAMES.FILE_TRANSFER);
110
- if (!channel || channel.readyState !== "open") {
111
- handle._setStatus("error");
112
- handle._emit("error", new Error("File transfer channel not open"));
113
- return handle;
114
- }
115
-
116
- // Send start message.
117
- const startMsg = new Uint8Array(
118
- 1 + new TextEncoder().encode(JSON.stringify(meta)).length,
119
- );
120
- startMsg[0] = FILE_MSG.START;
121
- startMsg.set(new TextEncoder().encode(JSON.stringify(meta)), 1);
122
- channel.send(startMsg);
123
-
124
- handle._setStatus("sending");
125
-
126
- // Read and send chunks.
127
- const arrayBuffer = await file.arrayBuffer();
128
- const fileBytes = new Uint8Array(arrayBuffer);
129
-
130
- // SHA-256 for integrity check.
131
- const hashBuffer = await crypto.subtle.digest("SHA-256", fileBytes);
132
- const hashBytes = new Uint8Array(hashBuffer);
133
-
134
- for (let i = 0; i < totalChunks; i++) {
135
- if (handle.signal.aborted) {
136
- // Send cancel.
137
- const cancelMsg = new Uint8Array(1 + TRANSFER_ID_BYTES);
138
- cancelMsg[0] = FILE_MSG.CANCEL;
139
- cancelMsg.set(transferIdBytes, 1);
140
- channel.send(cancelMsg);
141
- return handle;
142
- }
143
-
144
- const offset = i * this.chunkSize;
145
- const chunk = fileBytes.slice(
146
- offset,
147
- Math.min(offset + this.chunkSize, totalSize),
148
- );
149
-
150
- // [type(1)] [transferId(16)] [chunkIndex(4)] [chunk data]
151
- const msg = new Uint8Array(
152
- 1 + TRANSFER_ID_BYTES + 4 + chunk.length,
153
- );
154
- msg[0] = FILE_MSG.CHUNK;
155
- msg.set(transferIdBytes, 1);
156
- new DataView(msg.buffer).setUint32(
157
- 1 + TRANSFER_ID_BYTES,
158
- i,
159
- false,
160
- );
161
- msg.set(chunk, 1 + TRANSFER_ID_BYTES + 4);
162
-
163
- // Wait for bufferedAmount to drop before sending more chunks
164
- // to avoid overwhelming the data channel.
165
- while (channel.bufferedAmount > this.chunkSize * 4) {
166
- await new Promise<void>((resolve) => setTimeout(resolve, 10));
167
- if (handle.signal.aborted) return handle;
168
- }
169
-
170
- channel.send(msg);
171
- handle._setProgress((i + 1) / totalChunks);
172
- }
173
-
174
- // Send complete message.
175
- const completeMsg = new Uint8Array(
176
- 1 + TRANSFER_ID_BYTES + SHA256_BYTES,
177
- );
178
- completeMsg[0] = FILE_MSG.COMPLETE;
179
- completeMsg.set(transferIdBytes, 1);
180
- completeMsg.set(hashBytes, 1 + TRANSFER_ID_BYTES);
181
- channel.send(completeMsg);
182
-
183
- handle._setStatus("complete");
184
- handle._emit("complete");
185
-
186
- return handle;
187
- }
188
-
189
- private handleMessage(data: ArrayBuffer | Uint8Array): void {
190
- const buf = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
191
- if (buf.length < 1) return;
192
-
193
- const type = buf[0];
194
-
195
- switch (type) {
196
- case FILE_MSG.START:
197
- this.handleStart(buf);
198
- break;
199
- case FILE_MSG.CHUNK:
200
- this.handleChunk(buf);
201
- break;
202
- case FILE_MSG.COMPLETE:
203
- this.handleComplete(buf);
204
- break;
205
- case FILE_MSG.CANCEL:
206
- this.handleCancel(buf);
207
- break;
208
- }
209
- }
210
-
211
- private handleStart(buf: Uint8Array): void {
212
- const json = new TextDecoder().decode(buf.slice(1));
213
- let meta: FileTransferMeta;
214
- try {
215
- meta = JSON.parse(json);
216
- } catch {
217
- this.emit("receiveError", { transferId: "unknown", error: "Malformed START message: invalid JSON" });
218
- return;
219
- }
220
-
221
- this.receives.set(meta.transferId, {
222
- meta,
223
- chunks: new Array(meta.totalChunks).fill(null),
224
- receivedCount: 0,
225
- });
226
-
227
- this.emit("receiveStart", meta);
228
- }
229
-
230
- private handleChunk(buf: Uint8Array): void {
231
- if (buf.length < 1 + TRANSFER_ID_BYTES + 4) return;
232
-
233
- const transferId = bytesToHex(
234
- buf.slice(1, 1 + TRANSFER_ID_BYTES),
235
- );
236
- const chunkIndex = new DataView(buf.buffer, buf.byteOffset).getUint32(
237
- 1 + TRANSFER_ID_BYTES,
238
- false,
239
- );
240
- const chunkData = buf.slice(1 + TRANSFER_ID_BYTES + 4);
241
-
242
- const state = this.receives.get(transferId);
243
- if (!state) return;
244
-
245
- if (chunkIndex < state.chunks.length && !state.chunks[chunkIndex]) {
246
- state.chunks[chunkIndex] = chunkData;
247
- state.receivedCount++;
248
-
249
- const progress = state.receivedCount / state.meta.totalChunks;
250
- this.emit("receiveProgress", {
251
- transferId,
252
- received: state.receivedCount,
253
- total: state.meta.totalChunks,
254
- progress,
255
- });
256
- }
257
- }
258
-
259
- private async handleComplete(buf: Uint8Array): Promise<void> {
260
- if (buf.length < 1 + TRANSFER_ID_BYTES + SHA256_BYTES) return;
261
-
262
- const transferId = bytesToHex(
263
- buf.slice(1, 1 + TRANSFER_ID_BYTES),
264
- );
265
- const expectedHash = buf.slice(1 + TRANSFER_ID_BYTES, 1 + TRANSFER_ID_BYTES + SHA256_BYTES);
266
-
267
- const state = this.receives.get(transferId);
268
- if (!state) return;
269
-
270
- // Assemble the file.
271
- const totalSize = state.meta.totalSize;
272
- const assembled = new Uint8Array(totalSize);
273
- let offset = 0;
274
-
275
- for (let i = 0; i < state.chunks.length; i++) {
276
- const chunk = state.chunks[i];
277
- if (!chunk) {
278
- this.emit("receiveError", {
279
- transferId,
280
- error: `Missing chunk ${i}`,
281
- });
282
- this.receives.delete(transferId);
283
- return;
284
- }
285
- assembled.set(chunk, offset);
286
- offset += chunk.length;
287
- }
288
-
289
- // Verify SHA-256 integrity.
290
- const actualHashBuffer = await crypto.subtle.digest(
291
- "SHA-256",
292
- assembled,
293
- );
294
- const actualHash = new Uint8Array(actualHashBuffer);
295
-
296
- if (!constantTimeEqual(expectedHash, actualHash)) {
297
- this.emit("receiveError", {
298
- transferId,
299
- error: "SHA-256 integrity check failed",
300
- });
301
- this.receives.delete(transferId);
302
- return;
303
- }
304
-
305
- const blob = new Blob([assembled], { type: state.meta.mimeType });
306
-
307
- this.emit("receiveComplete", {
308
- transferId,
309
- blob,
310
- filename: state.meta.filename,
311
- mimeType: state.meta.mimeType,
312
- size: state.meta.totalSize,
313
- });
314
-
315
- this.receives.delete(transferId);
316
- }
317
-
318
- private handleCancel(buf: Uint8Array): void {
319
- if (buf.length < 1 + TRANSFER_ID_BYTES) return;
320
-
321
- const transferId = bytesToHex(
322
- buf.slice(1, 1 + TRANSFER_ID_BYTES),
323
- );
324
- this.receives.delete(transferId);
325
- this.emit("receiveCancelled", { transferId });
326
- }
327
-
328
- destroy(): void {
329
- if (this.channelMessageHandler) {
330
- this.router.off("channelMessage", this.channelMessageHandler);
331
- this.channelMessageHandler = null;
332
- }
333
- this.receives.clear();
334
- this.removeAllListeners();
335
- }
336
- }
337
-
338
- // ── Utilities ───────────────────────────────────────────────────────────────
339
-
340
- function generateTransferId(): string {
341
- const bytes = new Uint8Array(TRANSFER_ID_BYTES);
342
- crypto.getRandomValues(bytes);
343
- return bytesToHex(bytes);
344
- }
345
-
346
- function bytesToHex(bytes: Uint8Array): string {
347
- return Array.from(bytes)
348
- .map((b) => b.toString(16).padStart(2, "0"))
349
- .join("");
350
- }
351
-
352
- function hexToBytes(hex: string): Uint8Array {
353
- const bytes = new Uint8Array(hex.length / 2);
354
- for (let i = 0; i < hex.length; i += 2) {
355
- bytes[i / 2] = parseInt(hex.slice(i, i + 2), 16);
356
- }
357
- return bytes;
358
- }
359
-
360
- function constantTimeEqual(a: Uint8Array, b: Uint8Array): boolean {
361
- if (a.length !== b.length) return false;
362
- let result = 0;
363
- for (let i = 0; i < a.length; i++) {
364
- result |= a[i] ^ b[i];
365
- }
366
- return result === 0;
367
- }