Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/common/src/platform/abstractions/sdk/sdk.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function asUuid<T extends Uuid>(uuid: string): T {
/**
* Converts a UUID to the string representation.
*/
export function uuidToString<T extends Uuid>(uuid: T): string {
export function uuidAsString<T extends Uuid>(uuid: T): string {
return uuid as unknown as string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { Environment, EnvironmentService } from "../../abstractions/environment.
import { PlatformUtilsService } from "../../abstractions/platform-utils.service";
import { SdkClientFactory } from "../../abstractions/sdk/sdk-client-factory";
import { SdkLoadService } from "../../abstractions/sdk/sdk-load.service";
import { SdkService, UserNotLoggedInError } from "../../abstractions/sdk/sdk.service";
import { asUuid, SdkService, UserNotLoggedInError } from "../../abstractions/sdk/sdk.service";
import { compareValues } from "../../misc/compare-values";
import { Rc } from "../../misc/reference-counting/rc";
import { EncryptedString } from "../../models/domain/enc-string";
Expand Down Expand Up @@ -200,7 +200,7 @@ export class DefaultSdkService implements SdkService {
orgKeys: Record<OrganizationId, EncryptedOrganizationKeyData> | null,
) {
await client.crypto().initialize_user_crypto({
userId,
userId: asUuid(userId),
email: account.email,
method: { decryptedKey: { decrypted_user_key: userKey.keyB64 } },
kdfParams:
Expand All @@ -224,7 +224,7 @@ export class DefaultSdkService implements SdkService {
organizationKeys: new Map(
Object.entries(orgKeys ?? {})
.filter(([_, v]) => v.type === "organization")
.map(([k, v]) => [k, v.key]),
.map(([k, v]) => [asUuid(k), v.key]),
),
});
}
Expand Down
9 changes: 5 additions & 4 deletions libs/common/src/vault/models/domain/cipher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Jsonify } from "type-fest";

import { Cipher as SdkCipher } from "@bitwarden/sdk-internal";

import { asUuid } from "../../../platform/abstractions/sdk/sdk.service";
import { Decryptable } from "../../../platform/interfaces/decryptable.interface";
import { Utils } from "../../../platform/misc/utils";
import Domain from "../../../platform/models/domain/domain-base";
Expand Down Expand Up @@ -340,10 +341,10 @@ export class Cipher extends Domain implements Decryptable<CipherView> {
*/
toSdkCipher(): SdkCipher {
const sdkCipher: SdkCipher = {
id: this.id,
organizationId: this.organizationId,
folderId: this.folderId,
collectionIds: this.collectionIds || [],
id: asUuid(this.id),
organizationId: asUuid(this.organizationId),
folderId: asUuid(this.folderId),
collectionIds: (this.collectionIds || []).map((s) => asUuid(s)),
key: this.key?.toJSON(),
name: this.name.toJSON(),
notes: this.notes?.toJSON(),
Expand Down
8 changes: 4 additions & 4 deletions libs/common/src/vault/models/view/cipher.view.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ describe("CipherView", () => {
jest.spyOn(FieldView, "fromSdkFieldView").mockImplementation(mockFromSdk);

sdkCipherView = {
id: "id",
organizationId: "orgId",
folderId: "folderId",
collectionIds: ["collectionId"],
id: "id" as any,
organizationId: "orgId" as any,
folderId: "folderId" as any,
collectionIds: ["collectionId" as any],
Comment on lines +127 to +130
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should probably be actual UUIDs.

key: undefined,
name: "name",
notes: undefined,
Expand Down
9 changes: 5 additions & 4 deletions libs/common/src/vault/models/view/cipher.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { CipherView as SdkCipherView } from "@bitwarden/sdk-internal";

import { View } from "../../../models/view/view";
import { uuidAsString } from "../../../platform/abstractions/sdk/sdk.service";
import { InitializerMetadata } from "../../../platform/interfaces/initializer-metadata.interface";
import { InitializerKey } from "../../../platform/services/cryptography/initializer-key";
import { DeepJsonify } from "../../../types/deep-jsonify";
Expand Down Expand Up @@ -234,9 +235,9 @@ export class CipherView implements View, InitializerMetadata {
}

const cipherView = new CipherView();
cipherView.id = obj.id ?? null;
cipherView.organizationId = obj.organizationId ?? null;
cipherView.folderId = obj.folderId ?? null;
cipherView.id = uuidAsString(obj.id) ?? null;
cipherView.organizationId = uuidAsString(obj.organizationId) ?? null;
cipherView.folderId = uuidAsString(obj.folderId) ?? null;
cipherView.name = obj.name;
cipherView.notes = obj.notes ?? null;
cipherView.type = obj.type;
Expand All @@ -260,7 +261,7 @@ export class CipherView implements View, InitializerMetadata {
cipherView.fields = obj.fields?.map((f) => FieldView.fromSdkFieldView(f)) ?? null;
cipherView.passwordHistory =
obj.passwordHistory?.map((ph) => PasswordHistoryView.fromSdkPasswordHistoryView(ph)) ?? null;
cipherView.collectionIds = obj.collectionIds ?? null;
cipherView.collectionIds = (obj.collectionIds ?? null)?.map((id) => uuidAsString(id));
cipherView.revisionDate = obj.revisionDate == null ? null : new Date(obj.revisionDate);
cipherView.creationDate = obj.creationDate == null ? null : new Date(obj.creationDate);
cipherView.deletedDate = obj.deletedDate == null ? null : new Date(obj.deletedDate);
Expand Down
Loading