Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@phase.dev/phase-node",
"version": "1.0.0",
"version": "2.0.0",
"description": "Node.js Server SDK for Phase",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
12 changes: 10 additions & 2 deletions src/utils/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ export const encryptString = async (plaintext: string, key: Uint8Array) => {
await _sodium.ready;
const sodium = _sodium;

return sodium.to_hex(await encryptRaw(sodium.from_string(plaintext), key));
return sodium.to_base64(
await encryptRaw(sodium.from_string(plaintext), key),
sodium.base64_variants.ORIGINAL
);
};

/**
Expand All @@ -85,7 +88,12 @@ export const decryptString = async (cipherText: string, key: Uint8Array) => {
await _sodium.ready;
const sodium = _sodium;

return sodium.to_string(await decryptRaw(sodium.from_hex(cipherText), key));
return sodium.to_string(
await decryptRaw(
sodium.from_base64(cipherText, sodium.base64_variants.ORIGINAL),
key
)
);
};

/**
Expand Down
4 changes: 3 additions & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ describe("Phase", () => {
expect(segments[4]).toBe(tag);
// Check if the one-time public key and ciphertext are valid hex strings
expect(segments[2]).toMatch(/^[0-9a-f]+$/);
expect(segments[3]).toMatch(/^[0-9a-f]+$/);
expect(segments[3]).toMatch(
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/
);
});

test("Check if Phase encrypt always produces ciphertexts (ph:*) of the same length for the same plaintext", async () => {
Expand Down
2 changes: 1 addition & 1 deletion version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const LIB_VERSION = "1.0.0";
export const LIB_VERSION = "2.0.0";