Skip to content

Commit

Permalink
Use Enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethella committed May 22, 2023
1 parent bb836d3 commit 563342b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/@magic-sdk/provider/src/modules/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ export class UserModule extends BaseModule {
}

public encryptWithPrivateKey(message: string, opts = {}) {
const requestPayload = createJsonRpcRequestPayload('magic_auth_encrypt_v1', [{ message }]);
const requestPayload = createJsonRpcRequestPayload(MagicPayloadMethod.EncryptV1, [{ message }]);
return this.request<string>(requestPayload);
}

public decryptWithPrivateKey(cipherText: string, opts = {}) {
const requestPayload = createJsonRpcRequestPayload('magic_auth_decrypt_v1', [{ cipherText }]);
const requestPayload = createJsonRpcRequestPayload(MagicPayloadMethod.DecryptV1, [{ cipherText }]);
return this.request<string>(requestPayload);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import browserEnv from '@ikscodes/browser-env';
import { MagicPayloadMethod } from '@magic-sdk/types';
import { createMagicSDK } from '../../../factories';

beforeEach(() => {
browserEnv.restore();
});

test('Encrypt `magic_auth_encrypt_v1`', async () => {
test('Construct Encrypt Request with `magic_auth_encrypt_v1`', async () => {
const magic = createMagicSDK();
magic.user.request = jest.fn();

Expand All @@ -14,11 +15,11 @@ test('Encrypt `magic_auth_encrypt_v1`', async () => {
magic.user.encryptWithPrivateKey(message);

const requestPayload = magic.user.request.mock.calls[0][0];
expect(requestPayload.method).toBe('magic_auth_encrypt_v1');
expect(requestPayload.method).toBe(MagicPayloadMethod.EncryptV1);
expect(requestPayload.params).toEqual([{ message }]);
});

test('Decrypt `magic_auth_decrypt_v1`', async () => {
test('Construct Decrypt Request with `magic_auth_decrypt_v1`', async () => {
const magic = createMagicSDK();
magic.user.request = jest.fn();

Expand All @@ -27,6 +28,6 @@ test('Decrypt `magic_auth_decrypt_v1`', async () => {
magic.user.decryptWithPrivateKey(cipherText);

const requestPayload = magic.user.request.mock.calls[0][0];
expect(requestPayload.method).toBe('magic_auth_decrypt_v1');
expect(requestPayload.method).toBe(MagicPayloadMethod.DecryptV1);
expect(requestPayload.params).toEqual([{ cipherText }]);
});
2 changes: 2 additions & 0 deletions packages/@magic-sdk/types/src/core/json-rpc-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,6 @@ export enum MagicPayloadMethod {
MagicBoxHeartBeat = 'magic_box_heart_beat',
AutoConnect = 'mc_auto_connect',
Login = 'mc_login',
EncryptV1 = 'magic_auth_encrypt_V1',
DecryptV1 = 'magic_auth_decrypt_V1',
}

0 comments on commit 563342b

Please sign in to comment.