-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
132 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
bun run $1 | ||
deno run --allow-read $1 | ||
node $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "tests-browser", | ||
"description": "Test browser compatibility", | ||
"private": true, | ||
"version": "0.1.0", | ||
"scripts": { | ||
"test": "vitest" | ||
}, | ||
"dependencies": { | ||
"@ecies/ciphers": "file:.." | ||
}, | ||
"devDependencies": { | ||
"@vitest/browser": "^2.1.4", | ||
"playwright": "^1.48.2", | ||
"vitest": "^2.1.4" | ||
}, | ||
"packageManager": "pnpm@9.12.3+sha512.cce0f9de9c5a7c95bef944169cc5dfe8741abfb145078c0d508b868056848a87c81e626246cb60967cbd7fd29a6c062ef73ff840d96b3c86c40ac92cf4a813ee" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { aes256cbc, aes256gcm } from "@ecies/ciphers/aes"; | ||
import { xchacha20 } from "@ecies/ciphers/chacha"; | ||
import { randomBytes } from "@noble/ciphers/webcrypto"; | ||
|
||
import { describe, expect, it } from "vitest"; | ||
|
||
const TEXT = "hello browser🌍!"; | ||
const encoder = new TextEncoder(); | ||
const data = encoder.encode(TEXT); | ||
|
||
describe("test random", () => { | ||
function checkCipher( | ||
callback: typeof aes256gcm | typeof aes256cbc | typeof xchacha20, | ||
key: Uint8Array, | ||
nonce: Uint8Array, | ||
aad?: Uint8Array | ||
) { | ||
const cipher = callback(key, nonce, aad); | ||
expect(cipher.decrypt(cipher.encrypt(data))).toStrictEqual(data); | ||
} | ||
|
||
it("tests aes gcm", () => { | ||
checkCipher(aes256gcm, randomBytes(32), randomBytes(16), randomBytes(8)); | ||
checkCipher(aes256gcm, randomBytes(32), randomBytes(12), randomBytes(8)); | ||
}); | ||
|
||
it("tests aes cbc", () => { | ||
const key = randomBytes(); | ||
const nonce = randomBytes(16); | ||
checkCipher(aes256cbc, key, nonce); | ||
}); | ||
|
||
it("tests xchacha20", () => { | ||
const key = randomBytes(); | ||
const nonce = randomBytes(24); | ||
const aad = randomBytes(8); | ||
checkCipher(xchacha20, key, nonce, aad); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { configDefaults, defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
exclude: [...configDefaults.exclude, "tests-browser/**"], | ||
coverage: { | ||
include: ["src/**"], | ||
enabled: true, | ||
provider: "v8", | ||
}, | ||
}, | ||
}); |