1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-28 02:23:25 +00:00

[PM-31406] fix: TypeScript 5.9 type compatibility fixes for fido2 & platform-owned code (#19188)

* fix: TypeScript 5.9 type compatibility fixes for platform-owned code

Add explicit `as BufferSource` casts and `Uint8Array` wrapping to satisfy
stricter type checking in TypeScript 5.9. Non-functional changes.

* Fix fido2 issues

* Fix another type error

* Fix another type error
This commit is contained in:
Bernd Schoolmann
2026-02-27 10:59:52 +01:00
committed by GitHub
parent 81f1c6a1c6
commit dc772c22f7
14 changed files with 103 additions and 94 deletions

View File

@@ -27,9 +27,11 @@ export class WebauthnUtils {
residentKey: keyOptions.authenticatorSelection?.residentKey,
userVerification: keyOptions.authenticatorSelection?.userVerification,
},
challenge: Fido2Utils.bufferToString(keyOptions.challenge),
challenge: Fido2Utils.arrayToString(
Fido2Utils.bufferSourceToUint8Array(keyOptions.challenge),
),
excludeCredentials: keyOptions.excludeCredentials?.map((credential) => ({
id: Fido2Utils.bufferToString(credential.id),
id: Fido2Utils.arrayToString(Fido2Utils.bufferSourceToUint8Array(credential.id)),
transports: credential.transports,
type: credential.type,
})),
@@ -48,7 +50,7 @@ export class WebauthnUtils {
name: keyOptions.rp.name,
},
user: {
id: Fido2Utils.bufferToString(keyOptions.user.id),
id: Fido2Utils.arrayToString(Fido2Utils.bufferSourceToUint8Array(keyOptions.user.id)),
displayName: keyOptions.user.displayName,
name: keyOptions.user.name,
},
@@ -60,19 +62,19 @@ export class WebauthnUtils {
static mapCredentialRegistrationResult(result: CreateCredentialResult): PublicKeyCredential {
const credential = {
id: result.credentialId,
rawId: Fido2Utils.stringToBuffer(result.credentialId),
rawId: Fido2Utils.stringToArray(result.credentialId).buffer,
type: "public-key",
authenticatorAttachment: "platform",
response: {
clientDataJSON: Fido2Utils.stringToBuffer(result.clientDataJSON),
attestationObject: Fido2Utils.stringToBuffer(result.attestationObject),
clientDataJSON: Fido2Utils.stringToArray(result.clientDataJSON).buffer,
attestationObject: Fido2Utils.stringToArray(result.attestationObject).buffer,
getAuthenticatorData(): ArrayBuffer {
return Fido2Utils.stringToBuffer(result.authData);
return Fido2Utils.stringToArray(result.authData).buffer;
},
getPublicKey(): ArrayBuffer {
return Fido2Utils.stringToBuffer(result.publicKey);
return Fido2Utils.stringToArray(result.publicKey).buffer;
},
getPublicKeyAlgorithm(): number {
@@ -110,8 +112,12 @@ export class WebauthnUtils {
return {
allowedCredentialIds:
keyOptions.allowCredentials?.map((c) => Fido2Utils.bufferToString(c.id)) ?? [],
challenge: Fido2Utils.bufferToString(keyOptions.challenge),
keyOptions.allowCredentials?.map((c) =>
Fido2Utils.arrayToString(Fido2Utils.bufferSourceToUint8Array(c.id)),
) ?? [],
challenge: Fido2Utils.arrayToString(
Fido2Utils.bufferSourceToUint8Array(keyOptions.challenge),
),
rpId: keyOptions.rpId,
userVerification: keyOptions.userVerification,
timeout: keyOptions.timeout,
@@ -123,13 +129,13 @@ export class WebauthnUtils {
static mapCredentialAssertResult(result: AssertCredentialResult): PublicKeyCredential {
const credential = {
id: result.credentialId,
rawId: Fido2Utils.stringToBuffer(result.credentialId),
rawId: Fido2Utils.stringToArray(result.credentialId).buffer,
type: "public-key",
response: {
authenticatorData: Fido2Utils.stringToBuffer(result.authenticatorData),
clientDataJSON: Fido2Utils.stringToBuffer(result.clientDataJSON),
signature: Fido2Utils.stringToBuffer(result.signature),
userHandle: Fido2Utils.stringToBuffer(result.userHandle),
authenticatorData: Fido2Utils.stringToArray(result.authenticatorData).buffer,
clientDataJSON: Fido2Utils.stringToArray(result.clientDataJSON).buffer,
signature: Fido2Utils.stringToArray(result.signature).buffer,
userHandle: Fido2Utils.stringToArray(result.userHandle).buffer,
} as AuthenticatorAssertionResponse,
getClientExtensionResults: () => ({}),
authenticatorAttachment: "platform",

View File

@@ -165,9 +165,7 @@ export class Fido2CreateComponent implements OnInit, OnDestroy {
return;
}
const userHandle = Fido2Utils.bufferToString(
new Uint8Array(lastRegistrationRequest.userHandle),
);
const userHandle = Fido2Utils.arrayToString(new Uint8Array(lastRegistrationRequest.userHandle));
this.ciphers$ = combineLatest([
this.accountService.activeAccount$.pipe(map((a) => a?.id)),

View File

@@ -380,13 +380,13 @@ export class DesktopAutofillService implements OnDestroy {
if ("credentialId" in request) {
allowedCredentials = [
{
id: new Uint8Array(request.credentialId).buffer,
id: new Uint8Array(request.credentialId),
type: "public-key" as const,
},
];
} else {
allowedCredentials = request.allowedCredentials.map((credentialId) => ({
id: new Uint8Array(credentialId).buffer,
id: new Uint8Array(credentialId),
type: "public-key" as const,
}));
}

View File

@@ -68,7 +68,7 @@ export class Fido2AuthenticatorError extends Error {
}
export interface PublicKeyCredentialDescriptor {
id: ArrayBuffer;
id: Uint8Array<ArrayBuffer>;
transports?: ("ble" | "hybrid" | "internal" | "nfc" | "usb")[];
type: "public-key";
}
@@ -89,7 +89,7 @@ export interface Fido2AuthenticatorMakeCredentialsParams {
};
/** The user accounts PublicKeyCredentialUserEntity, containing the user handle given by the Relying Party. */
userEntity: {
id: BufferSource;
id: Uint8Array<ArrayBuffer>;
name?: string;
displayName?: string;
icon?: string;
@@ -120,10 +120,10 @@ export interface Fido2AuthenticatorMakeCredentialsParams {
}
export interface Fido2AuthenticatorMakeCredentialResult {
credentialId: BufferSource;
attestationObject: BufferSource;
authData: BufferSource;
publicKey: BufferSource;
credentialId: Uint8Array<ArrayBuffer>;
attestationObject: Uint8Array<ArrayBuffer>;
authData: Uint8Array<ArrayBuffer>;
publicKey: Uint8Array<ArrayBuffer>;
publicKeyAlgorithm: number;
}
@@ -153,9 +153,9 @@ export interface Fido2AuthenticatorGetAssertionParams {
export interface Fido2AuthenticatorGetAssertionResult {
selectedCredential: {
id: ArrayBuffer;
userHandle?: ArrayBuffer;
id: Uint8Array<ArrayBuffer>;
userHandle?: Uint8Array<ArrayBuffer>;
};
authenticatorData: ArrayBuffer;
signature: ArrayBuffer;
authenticatorData: Uint8Array<ArrayBuffer>;
signature: Uint8Array<ArrayBuffer>;
}

View File

@@ -9,7 +9,7 @@ describe("credential-id-utils", () => {
new Uint8Array([
0x08, 0xd7, 0x0b, 0x74, 0xe9, 0xf5, 0x45, 0x22, 0xa4, 0x25, 0xe5, 0xdc, 0xd4, 0x01, 0x07,
0xe7,
]).buffer,
]),
);
});
@@ -20,7 +20,7 @@ describe("credential-id-utils", () => {
new Uint8Array([
0x08, 0xd7, 0x0b, 0x74, 0xe9, 0xf5, 0x45, 0x22, 0xa4, 0x25, 0xe5, 0xdc, 0xd4, 0x01, 0x07,
0xe7,
]).buffer,
]),
);
});

View File

@@ -3,13 +3,13 @@
import { Fido2Utils } from "./fido2-utils";
import { guidToRawFormat } from "./guid-utils";
export function parseCredentialId(encodedCredentialId: string): ArrayBuffer {
export function parseCredentialId(encodedCredentialId: string): Uint8Array<ArrayBuffer> {
try {
if (encodedCredentialId.startsWith("b64.")) {
return Fido2Utils.stringToBuffer(encodedCredentialId.slice(4));
return Fido2Utils.stringToArray(encodedCredentialId.slice(4));
}
return guidToRawFormat(encodedCredentialId).buffer;
return guidToRawFormat(encodedCredentialId);
} catch {
return undefined;
}
@@ -18,16 +18,16 @@ export function parseCredentialId(encodedCredentialId: string): ArrayBuffer {
/**
* Compares two credential IDs for equality.
*/
export function compareCredentialIds(a: ArrayBuffer, b: ArrayBuffer): boolean {
export function compareCredentialIds(
a: Uint8Array<ArrayBuffer>,
b: Uint8Array<ArrayBuffer>,
): boolean {
if (a.byteLength !== b.byteLength) {
return false;
}
const viewA = new Uint8Array(a);
const viewB = new Uint8Array(b);
for (let i = 0; i < viewA.length; i++) {
if (viewA[i] !== viewB[i]) {
for (let i = 0; i < a.length; i++) {
if (a[i] !== b[i]) {
return false;
}
}

View File

@@ -246,7 +246,7 @@ describe("FidoAuthenticatorService", () => {
expect(userInterfaceSession.confirmNewCredential).toHaveBeenCalledWith({
credentialName: params.rpEntity.name,
userName: params.userEntity.name,
userHandle: Fido2Utils.bufferToString(params.userEntity.id),
userHandle: Fido2Utils.arrayToString(params.userEntity.id),
userVerification,
rpId: params.rpEntity.id,
} as NewCredentialParams);
@@ -278,7 +278,7 @@ describe("FidoAuthenticatorService", () => {
keyCurve: "P-256",
rpId: params.rpEntity.id,
rpName: params.rpEntity.name,
userHandle: Fido2Utils.bufferToString(params.userEntity.id),
userHandle: Fido2Utils.arrayToString(params.userEntity.id),
userName: params.userEntity.name,
counter: 0,
userDisplayName: params.userEntity.displayName,
@@ -669,8 +669,8 @@ describe("FidoAuthenticatorService", () => {
const init = async () => {
keyPair = await createKeyPair();
credentialIds = [Utils.newGuid(), Utils.newGuid()];
const keyValue = Fido2Utils.bufferToString(
await crypto.subtle.exportKey("pkcs8", keyPair.privateKey),
const keyValue = Fido2Utils.arrayToString(
new Uint8Array(await crypto.subtle.exportKey("pkcs8", keyPair.privateKey)),
);
ciphers = credentialIds.map((id) =>
createCipherView(
@@ -735,7 +735,7 @@ describe("FidoAuthenticatorService", () => {
expect(result.selectedCredential.id).toEqual(parseCredentialId(selectedCredentialId));
expect(result.selectedCredential.userHandle).toEqual(
Fido2Utils.stringToBuffer(fido2Credentials[0].userHandle),
Fido2Utils.stringToArray(fido2Credentials[0].userHandle),
);
expect(rpIdHash).toEqual(
new Uint8Array([
@@ -772,7 +772,7 @@ describe("FidoAuthenticatorService", () => {
const counter = result.authenticatorData.slice(33, 37);
expect(counter).toEqual(new Uint8Array([0, 0, 0x23, 0x29])); // double check that the counter doesn't change
const signature = Fido2Utils.bufferToString(result.signature);
const signature = Fido2Utils.arrayToString(result.signature);
if (signatures.has(signature)) {
throw new Error("Found duplicate signature");
}
@@ -847,7 +847,7 @@ function createCipherView(
fido2CredentialView.rpId = fido2Credential.rpId ?? RpId;
fido2CredentialView.counter = fido2Credential.counter ?? 0;
fido2CredentialView.userHandle =
fido2Credential.userHandle ?? Fido2Utils.bufferToString(randomBytes(16));
fido2Credential.userHandle ?? Fido2Utils.arrayToString(randomBytes(16));
fido2CredentialView.userName = fido2Credential.userName;
fido2CredentialView.keyAlgorithm = fido2Credential.keyAlgorithm ?? "ECDSA";
fido2CredentialView.keyCurve = fido2Credential.keyCurve ?? "P-256";
@@ -867,7 +867,7 @@ async function createClientDataHash() {
const clientData = encoder.encode(
JSON.stringify({
type: "webauthn.create",
challenge: Fido2Utils.bufferToString(randomBytes(16)),
challenge: Fido2Utils.arrayToString(randomBytes(16)),
origin: RpId,
crossOrigin: false,
}),

View File

@@ -127,11 +127,11 @@ export class Fido2AuthenticatorService<
let keyPair: CryptoKeyPair;
let userVerified = false;
let credentialId: string;
let pubKeyDer: ArrayBuffer;
let pubKeyDer: Uint8Array<ArrayBuffer>;
const response = await userInterfaceSession.confirmNewCredential({
credentialName: params.rpEntity.name,
userName: params.userEntity.name,
userHandle: Fido2Utils.bufferToString(params.userEntity.id),
userHandle: Fido2Utils.arrayToString(params.userEntity.id),
userVerification: params.requireUserVerification,
rpId: params.rpEntity.id,
});
@@ -147,7 +147,7 @@ export class Fido2AuthenticatorService<
try {
keyPair = await createKeyPair();
pubKeyDer = await crypto.subtle.exportKey("spki", keyPair.publicKey);
pubKeyDer = new Uint8Array(await crypto.subtle.exportKey("spki", keyPair.publicKey));
const activeUserId = await firstValueFrom(
this.accountService.activeAccount$.pipe(getUserId),
);
@@ -349,7 +349,7 @@ export class Fido2AuthenticatorService<
authenticatorData,
selectedCredential: {
id: parseCredentialId(selectedCredentialId),
userHandle: Fido2Utils.stringToBuffer(selectedFido2Credential.userHandle),
userHandle: Fido2Utils.stringToArray(selectedFido2Credential.userHandle),
},
signature,
};
@@ -487,15 +487,15 @@ async function createKeyView(
throw new Fido2AuthenticatorError(Fido2AuthenticatorErrorCode.Unknown);
}
const pkcs8Key = await crypto.subtle.exportKey("pkcs8", keyValue);
const pkcs8Key = new Uint8Array(await crypto.subtle.exportKey("pkcs8", keyValue));
const fido2Credential = new Fido2CredentialView();
fido2Credential.credentialId = Utils.newGuid();
fido2Credential.keyType = "public-key";
fido2Credential.keyAlgorithm = "ECDSA";
fido2Credential.keyCurve = "P-256";
fido2Credential.keyValue = Fido2Utils.bufferToString(pkcs8Key);
fido2Credential.keyValue = Fido2Utils.arrayToString(pkcs8Key);
fido2Credential.rpId = params.rpEntity.id;
fido2Credential.userHandle = Fido2Utils.bufferToString(params.userEntity.id);
fido2Credential.userHandle = Fido2Utils.arrayToString(params.userEntity.id);
fido2Credential.userName = params.userEntity.name;
fido2Credential.counter = 0;
fido2Credential.rpName = params.rpEntity.name;
@@ -509,7 +509,7 @@ async function createKeyView(
async function getPrivateKeyFromFido2Credential(
fido2Credential: Fido2CredentialView,
): Promise<CryptoKey> {
const keyBuffer = Fido2Utils.stringToBuffer(fido2Credential.keyValue);
const keyBuffer = Fido2Utils.stringToArray(fido2Credential.keyValue);
return await crypto.subtle.importKey(
"pkcs8",
new Uint8Array(keyBuffer),
@@ -535,7 +535,10 @@ async function generateAuthData(params: AuthDataParams) {
const authData: Array<number> = [];
const rpIdHash = new Uint8Array(
await crypto.subtle.digest({ name: "SHA-256" }, Utils.fromByteStringToArray(params.rpId)),
await crypto.subtle.digest(
{ name: "SHA-256" },
Utils.fromByteStringToArray(params.rpId) as BufferSource,
),
);
authData.push(...rpIdHash);

View File

@@ -572,9 +572,9 @@ describe("FidoAuthenticatorService", () => {
describe("assert non-discoverable credential", () => {
it("should call authenticator.assertCredential", async () => {
const allowedCredentialIds = [
Fido2Utils.bufferToString(guidToRawFormat(Utils.newGuid())),
Fido2Utils.bufferToString(guidToRawFormat(Utils.newGuid())),
Fido2Utils.bufferToString(Utils.fromByteStringToArray("not-a-guid")),
Fido2Utils.arrayToString(guidToRawFormat(Utils.newGuid())),
Fido2Utils.arrayToString(guidToRawFormat(Utils.newGuid())),
Fido2Utils.arrayToString(Utils.fromByteStringToArray("not-a-guid")),
];
const params = createParams({
userVerification: "required",
@@ -590,13 +590,13 @@ describe("FidoAuthenticatorService", () => {
rpId: RpId,
allowCredentialDescriptorList: [
expect.objectContaining({
id: Fido2Utils.stringToBuffer(allowedCredentialIds[0]),
id: Fido2Utils.stringToArray(allowedCredentialIds[0]),
}),
expect.objectContaining({
id: Fido2Utils.stringToBuffer(allowedCredentialIds[1]),
id: Fido2Utils.stringToArray(allowedCredentialIds[1]),
}),
expect.objectContaining({
id: Fido2Utils.stringToBuffer(allowedCredentialIds[2]),
id: Fido2Utils.stringToArray(allowedCredentialIds[2]),
}),
],
}),
@@ -688,7 +688,7 @@ describe("FidoAuthenticatorService", () => {
function createParams(params: Partial<AssertCredentialParams> = {}): AssertCredentialParams {
return {
allowedCredentialIds: params.allowedCredentialIds ?? [],
challenge: params.challenge ?? Fido2Utils.bufferToString(randomBytes(16)),
challenge: params.challenge ?? Fido2Utils.arrayToString(randomBytes(16)),
origin: params.origin ?? Origin,
rpId: params.rpId ?? RpId,
timeout: params.timeout,

View File

@@ -130,7 +130,7 @@ export class Fido2ClientService<
throw new DOMException("Invalid 'sameOriginWithAncestors' value", "NotAllowedError");
}
const userId = Fido2Utils.stringToBuffer(params.user.id);
const userId = Fido2Utils.stringToArray(params.user.id);
if (userId.byteLength < 1 || userId.byteLength > 64) {
this.logService?.warning(
`[Fido2Client] Invalid 'user.id' length: ${params.user.id} (${userId.byteLength})`,
@@ -195,7 +195,7 @@ export class Fido2ClientService<
const makeCredentialParams = mapToMakeCredentialParams({
params,
credTypesAndPubKeyAlgs,
clientDataHash,
clientDataHash: new Uint8Array(clientDataHash),
});
// Set timeout before invoking authenticator
@@ -255,11 +255,11 @@ export class Fido2ClientService<
timeoutSubscription?.unsubscribe();
return {
credentialId: Fido2Utils.bufferToString(makeCredentialResult.credentialId),
attestationObject: Fido2Utils.bufferToString(makeCredentialResult.attestationObject),
authData: Fido2Utils.bufferToString(makeCredentialResult.authData),
clientDataJSON: Fido2Utils.bufferToString(clientDataJSONBytes),
publicKey: Fido2Utils.bufferToString(makeCredentialResult.publicKey),
credentialId: Fido2Utils.arrayToString(makeCredentialResult.credentialId),
attestationObject: Fido2Utils.arrayToString(makeCredentialResult.attestationObject),
authData: Fido2Utils.arrayToString(makeCredentialResult.authData),
clientDataJSON: Fido2Utils.arrayToString(clientDataJSONBytes),
publicKey: Fido2Utils.arrayToString(makeCredentialResult.publicKey),
publicKeyAlgorithm: makeCredentialResult.publicKeyAlgorithm,
transports: ["internal", "hybrid"],
extensions: { credProps },
@@ -383,7 +383,7 @@ export class Fido2ClientService<
params: AssertCredentialParams,
tab: ParentWindowReference,
abortController: AbortController,
clientDataJSONBytes: Uint8Array,
clientDataJSONBytes: Uint8Array<ArrayBuffer>,
): Promise<AssertCredentialResult> {
let getAssertionResult;
let assumeUserPresence = false;
@@ -414,7 +414,7 @@ export class Fido2ClientService<
}
params.allowedCredentialIds = [
Fido2Utils.bufferToString(guidToRawFormat(requestResult.credentialId)),
Fido2Utils.arrayToString(guidToRawFormat(requestResult.credentialId)),
];
assumeUserPresence = true;
@@ -441,17 +441,17 @@ export class Fido2ClientService<
private generateAssertCredentialResult(
getAssertionResult: Fido2AuthenticatorGetAssertionResult,
clientDataJSONBytes: Uint8Array,
clientDataJSONBytes: Uint8Array<ArrayBuffer>,
): AssertCredentialResult {
return {
authenticatorData: Fido2Utils.bufferToString(getAssertionResult.authenticatorData),
clientDataJSON: Fido2Utils.bufferToString(clientDataJSONBytes),
credentialId: Fido2Utils.bufferToString(getAssertionResult.selectedCredential.id),
authenticatorData: Fido2Utils.arrayToString(getAssertionResult.authenticatorData),
clientDataJSON: Fido2Utils.arrayToString(clientDataJSONBytes),
credentialId: Fido2Utils.arrayToString(getAssertionResult.selectedCredential.id),
userHandle:
getAssertionResult.selectedCredential.userHandle !== undefined
? Fido2Utils.bufferToString(getAssertionResult.selectedCredential.userHandle)
? Fido2Utils.arrayToString(getAssertionResult.selectedCredential.userHandle)
: undefined,
signature: Fido2Utils.bufferToString(getAssertionResult.signature),
signature: Fido2Utils.arrayToString(getAssertionResult.signature),
};
}
@@ -489,11 +489,11 @@ function mapToMakeCredentialParams({
}: {
params: CreateCredentialParams;
credTypesAndPubKeyAlgs: PublicKeyCredentialParam[];
clientDataHash: ArrayBuffer;
clientDataHash: Uint8Array<ArrayBuffer>;
}): Fido2AuthenticatorMakeCredentialsParams {
const excludeCredentialDescriptorList: PublicKeyCredentialDescriptor[] =
params.excludeCredentials?.map((credential) => ({
id: Fido2Utils.stringToBuffer(credential.id),
id: Fido2Utils.stringToArray(credential.id),
transports: credential.transports,
type: credential.type,
})) ?? [];
@@ -525,7 +525,7 @@ function mapToMakeCredentialParams({
name: params.rp.name,
},
userEntity: {
id: Fido2Utils.stringToBuffer(params.user.id),
id: Fido2Utils.stringToArray(params.user.id),
displayName: params.user.displayName,
name: params.user.name,
},
@@ -547,7 +547,7 @@ function mapToGetAssertionParams({
}): Fido2AuthenticatorGetAssertionParams {
const allowCredentialDescriptorList: PublicKeyCredentialDescriptor[] =
params.allowedCredentialIds.map((id) => ({
id: Fido2Utils.stringToBuffer(id),
id: Fido2Utils.stringToArray(id),
type: "public-key",
}));

View File

@@ -42,18 +42,18 @@ export class Fido2Utils {
};
}
static bufferToString(bufferSource: BufferSource): string {
return Fido2Utils.fromBufferToB64(Fido2Utils.bufferSourceToUint8Array(bufferSource))
static arrayToString(array: Uint8Array<ArrayBuffer>): string {
return Fido2Utils.fromBufferToB64(Fido2Utils.bufferSourceToUint8Array(array))
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=/g, "");
}
static stringToBuffer(str: string): ArrayBuffer {
return Fido2Utils.fromB64ToArray(Fido2Utils.fromUrlB64ToB64(str)).buffer;
static stringToArray(str: string): Uint8Array<ArrayBuffer> {
return Fido2Utils.fromB64ToArray(Fido2Utils.fromUrlB64ToB64(str));
}
static bufferSourceToUint8Array(bufferSource: BufferSource): Uint8Array {
static bufferSourceToUint8Array(bufferSource: BufferSource): Uint8Array<ArrayBuffer> {
if (Fido2Utils.isArrayBuffer(bufferSource)) {
return new Uint8Array(bufferSource);
} else {
@@ -70,7 +70,7 @@ export class Fido2Utils {
return b64Str.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
}
static fromBufferToB64(buffer: ArrayBuffer): string {
static fromBufferToB64(buffer: Uint8Array | ArrayBuffer): string {
if (buffer == null) {
return null;
}
@@ -83,7 +83,7 @@ export class Fido2Utils {
return globalThis.btoa(binary);
}
static fromB64ToArray(str: string): Uint8Array {
static fromB64ToArray(str: string): Uint8Array<ArrayBuffer> {
if (str == null) {
return null;
}

View File

@@ -31,7 +31,7 @@ export class AzureFileUploadService {
});
const request = new Request(url, {
body: data.buffer,
body: data.buffer as BodyInit,
cache: "no-store",
method: "PUT",
headers: headers,

View File

@@ -10,7 +10,9 @@ export class BitwardenFileUploadService {
const fd = new FormData();
if (Utils.isBrowser) {
const blob = new Blob([encryptedFileData.buffer], { type: "application/octet-stream" });
const blob = new Blob([encryptedFileData.buffer as BlobPart], {
type: "application/octet-stream",
});
fd.append("data", blob, encryptedFileName);
} else if (Utils.isNode) {
fd.append(

View File

@@ -154,7 +154,7 @@ export class DefaultWebAuthnPrfUnlockService implements WebAuthnPrfUnlockService
allowCredentials: credentials.map(({ credentialId, transports }) => {
// The credential ID is already base64url encoded from login storage
// We need to decode it to ArrayBuffer for WebAuthn
const decodedId = Fido2Utils.stringToBuffer(credentialId);
const decodedId = Fido2Utils.stringToArray(credentialId);
return {
type: "public-key",
id: decodedId,