Skip to content

Commit

Permalink
connectPlatform some more
Browse files Browse the repository at this point in the history
  • Loading branch information
brianwphamSF committed Dec 6, 2023
1 parent e16c436 commit 607ce00
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions keeperapi/src/__tests__/crypto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {browserPlatform} from "../browser/platform"
import {publicKey, privateKey} from "./ecies-test-vectors";
import {TextEncoder, TextDecoder} from 'util';
import type {Platform} from "../platform";
import {connectPlatform} from "../platform";
import {connectPlatform, platform} from "../platform";

Object.assign(global, {TextDecoder, TextEncoder})

Expand All @@ -23,43 +23,43 @@ Object.defineProperty(global.self, 'crypto', {
describe('crypto test', () => {
it('node API encrypts a message under EC and then decrypts it (test key pair)', async () => {
connectPlatform(nodePlatform)
await ecEncryptionTest(nodePlatform, publicKey, privateKey)
await ecEncryptionTest(publicKey, privateKey)
})
it('node API encrypts a message under EC and then decrypts it (generated key pair)', async () => {
const kp = await nodePlatform.generateECKeyPair()
connectPlatform(nodePlatform)
await ecEncryptionTest(nodePlatform, kp.publicKey, kp.privateKey)
const kp = await platform.generateECKeyPair()
await ecEncryptionTest(kp.publicKey, kp.privateKey)
})
it('browser API encrypts a message under EC and then decrypts it (test key pair)', async () => {
connectPlatform(browserPlatform)
await ecEncryptionTest(browserPlatform, publicKey, privateKey)
await ecEncryptionTest(publicKey, privateKey)
})
it('browser API encrypts a message under EC and then decrypts it (generated key pair)', async () => {
const kp = await browserPlatform.generateECKeyPair()
connectPlatform(browserPlatform)
await ecEncryptionTest(browserPlatform, kp.publicKey, kp.privateKey)
const kp = await platform.generateECKeyPair()
await ecEncryptionTest(kp.publicKey, kp.privateKey)
})
it('node API encrypts a message with HKDF under EC and then decrypts it (test key pair)', async () => {
connectPlatform(nodePlatform)
await ecWithHkdfEncryptionTest(nodePlatform, publicKey, privateKey)
await ecWithHkdfEncryptionTest(publicKey, privateKey)
})
it('node API encrypts a message with HKDF under EC and then decrypts it (generated key pair)', async () => {
const kp = await nodePlatform.generateECKeyPair()
connectPlatform(nodePlatform)
await ecWithHkdfEncryptionTest(nodePlatform, kp.publicKey, kp.privateKey)
const kp = await platform.generateECKeyPair()
await ecWithHkdfEncryptionTest(kp.publicKey, kp.privateKey)
})
it('browser API encrypts a message with HKDF under EC and then decrypts it (test key pair)', async () => {
connectPlatform(browserPlatform)
await ecWithHkdfEncryptionTest(browserPlatform, publicKey, privateKey)
await ecWithHkdfEncryptionTest(publicKey, privateKey)
})
it('browser API encrypts a message with HKDF under EC and then decrypts it (generated key pair)', async () => {
const kp = await browserPlatform.generateECKeyPair()
connectPlatform(browserPlatform)
await ecWithHkdfEncryptionTest(browserPlatform, kp.publicKey, kp.privateKey)
const kp = await platform.generateECKeyPair()
await ecWithHkdfEncryptionTest(kp.publicKey, kp.privateKey)
})
})

async function ecEncryptionTest(platform: Platform, publicKey: Uint8Array, privateKey: Uint8Array) {
async function ecEncryptionTest(publicKey: Uint8Array, privateKey: Uint8Array) {
const message = 'test'
const cipher = await platform.publicEncryptEC(platform.stringToBytes(message), publicKey, Buffer.from([]))
expect(cipher).toBeTruthy()
Expand All @@ -68,7 +68,7 @@ async function ecEncryptionTest(platform: Platform, publicKey: Uint8Array, priva
expect(decryptedMsg).toEqual(message)
}

async function ecWithHkdfEncryptionTest(platform: Platform, publicKey: Uint8Array, privateKey: Uint8Array) {
async function ecWithHkdfEncryptionTest(publicKey: Uint8Array, privateKey: Uint8Array) {
const message = 'test'
const cipher = await platform.publicEncryptECWithHKDF(message, publicKey, Buffer.from([]))
expect(cipher).toBeTruthy()
Expand Down

0 comments on commit 607ce00

Please sign in to comment.