Skip to content

Commit 085854b

Browse files
authored
Merge pull request element-hq#28626 from element-hq/t3chguy/web-friendly-buffers
Remove usages of Buffer so we don't need to ship the polyfill
2 parents ee24989 + 188f910 commit 085854b

File tree

17 files changed

+24
-34
lines changed

17 files changed

+24
-34
lines changed

.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ module.exports = {
4242
name: "setImmediate",
4343
message: "Use setTimeout instead.",
4444
},
45+
{
46+
name: "Buffer",
47+
message: "Buffer is not available in the web.",
48+
},
4549
],
4650

4751
"import/no-duplicates": ["error"],
@@ -255,6 +259,9 @@ module.exports = {
255259
additionalTestBlockFunctions: ["beforeAll", "beforeEach", "oldBackendOnly"],
256260
},
257261
],
262+
263+
// These are fine in tests
264+
"no-restricted-globals": "off",
258265
},
259266
},
260267
{

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@
216216
"babel-loader": "^9.0.0",
217217
"babel-plugin-jsx-remove-data-test-id": "^3.0.0",
218218
"blob-polyfill": "^9.0.0",
219-
"buffer": "^6.0.3",
220219
"chokidar": "^4.0.0",
221220
"concurrently": "^9.0.0",
222221
"copy-webpack-plugin": "^12.0.0",

playwright/e2e/crypto/device-verification.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ test.describe("Device verification", () => {
102102
// feed the QR code into the verification request.
103103
const qrData = await readQrCode(infoDialog);
104104
const verifier = await verificationRequest.evaluateHandle(
105-
(request, qrData) => request.scanQRCode(new Uint8Array(qrData)),
105+
(request, qrData) => request.scanQRCode(new Uint8ClampedArray(qrData)),
106106
[...qrData],
107107
);
108108

src/@types/png-chunks-extract.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ declare module "png-chunks-extract" {
1212
data: Uint8Array;
1313
}
1414

15-
function extractPngChunks(data: Uint8Array | Buffer): IChunk[];
15+
function extractPngChunks(data: Uint8Array): IChunk[];
1616

1717
export default extractPngChunks;
1818
}

src/DecryptionFailureTracker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
66
Please see LICENSE files in the repository root for full details.
77
*/
88

9-
import { ScalableBloomFilter } from "bloom-filters";
9+
import ScalableBloomFilter from "bloom-filters/dist/bloom/scalable-bloom-filter";
1010
import { HttpApiEvent, MatrixClient, MatrixEventEvent, MatrixEvent } from "matrix-js-sdk/src/matrix";
1111
import { Error as ErrorEvent } from "@matrix-org/analytics-events/types/typescript/Error";
1212
import { DecryptionFailureCode, CryptoEvent } from "matrix-js-sdk/src/crypto-api";

src/components/views/auth/LoginWithQR.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ interface IState {
3737
userCode?: string;
3838
checkCode?: string;
3939
failureReason?: FailureReason;
40-
lastScannedCode?: Buffer;
4140
}
4241

4342
export enum LoginWithQRFailureReason {
@@ -154,7 +153,7 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
154153
throw new Error("Rendezvous not found");
155154
}
156155

157-
if (!this.state.lastScannedCode && this.state.rendezvous?.checkCode !== checkCode) {
156+
if (this.state.rendezvous?.checkCode !== checkCode) {
158157
this.setState({ failureReason: LoginWithQRFailureReason.CheckCodeMismatch });
159158
return;
160159
}
@@ -201,7 +200,6 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
201200
failureReason: undefined,
202201
userCode: undefined,
203202
checkCode: undefined,
204-
lastScannedCode: undefined,
205203
mediaPermissionError: false,
206204
});
207205
}

src/components/views/elements/crypto/VerificationQRCode.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import QRCode from "../QRCode";
1212

1313
interface IProps {
1414
/** The data for the QR code. If `undefined`, a spinner is shown. */
15-
qrCodeBytes: undefined | Buffer;
15+
qrCodeBytes: undefined | Uint8ClampedArray;
1616
}
1717

1818
export default class VerificationQRCode extends React.PureComponent<IProps> {

src/components/views/right_panel/VerificationPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ interface IState {
4646
* We attempt to calculate this once the verification request transitions into the "Ready" phase. If the other
4747
* side cannot scan QR codes, it will remain `undefined`.
4848
*/
49-
qrCodeBytes: Buffer | undefined;
49+
qrCodeBytes: Uint8ClampedArray | undefined;
5050

5151
sasEvent: ShowSasCallbacks | null;
5252
emojiButtonClicked?: boolean;

src/stores/ThreepidInviteStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default class ThreepidInviteStore extends EventEmitter {
9999

100100
private generateIdOf(persisted: IPersistedThreepidInvite): string {
101101
// Use a consistent "hash" to form an ID.
102-
return base32.stringify(Buffer.from(JSON.stringify(persisted)));
102+
return base32.stringify(new TextEncoder().encode(JSON.stringify(persisted)));
103103
}
104104

105105
private translateInvite(persisted: IPersistedThreepidInvite): IThreepidInvite {

src/utils/WidgetUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ export default class WidgetUtils {
445445
// For compatibility with Jitsi, use base32 without padding.
446446
// More details here:
447447
// https://github.com/matrix-org/prosody-mod-auth-matrix-user-verification
448-
confId = base32.stringify(Buffer.from(roomId), { pad: false });
448+
confId = base32.stringify(new TextEncoder().encode(roomId), { pad: false });
449449
} else {
450450
// Create a random conference ID
451451
confId = `Jitsi${randomUppercaseString(1)}${randomLowercaseString(23)}`;

0 commit comments

Comments
 (0)