-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
13 changed files
with
1,695 additions
and
993 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
collectCoverage: true, | ||
coverageDirectory: "coverage", | ||
coverageProvider: "v8", | ||
testTimeout: 30000, | ||
}; |
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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { default as PrivateKey } from "./PrivateKey"; | ||
export { default as PublicKey } from "./PublicKey"; | ||
export { PrivateKey } from "./PrivateKey"; | ||
export { PublicKey } from "./PublicKey"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { HttpsProxyAgent } from "https-proxy-agent"; | ||
import fetch, { RequestInit } from "node-fetch"; | ||
|
||
import { PrivateKey, decrypt, encrypt, utils } from "../src/index"; | ||
|
||
const decodeHex = utils.decodeHex; | ||
|
||
const PYTHON_BACKEND = "https://eciespydemo-1-d5397785.deta.app/"; | ||
const TEXT = "helloworld🌍"; | ||
|
||
describe("test encrypt and decrypt against python version", () => { | ||
it("tests encrypt", async () => { | ||
const sk = new PrivateKey(); | ||
const res = await eciesApi(PYTHON_BACKEND, { | ||
data: TEXT, | ||
pub: sk.publicKey.toHex(), | ||
}); | ||
const decrypted = decrypt(sk.toHex(), decodeHex(await res.text())); | ||
expect(decrypted.toString()).toEqual(TEXT); | ||
}); | ||
|
||
it("tests decrypt", async () => { | ||
const sk = new PrivateKey(); | ||
const encrypted = encrypt(sk.publicKey.toHex(), Buffer.from(TEXT)); | ||
const res = await eciesApi(PYTHON_BACKEND, { | ||
data: encrypted.toString("hex"), | ||
prv: sk.toHex(), | ||
}); | ||
expect(TEXT).toEqual(await res.text()); | ||
}); | ||
}); | ||
|
||
async function eciesApi( | ||
url: string, | ||
body: { data: string; pub?: string; prv?: string } | ||
) { | ||
const config: RequestInit = { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}, | ||
}; | ||
if (process.env.http_proxy !== undefined) { | ||
config.agent = new HttpsProxyAgent(`${process.env.http_proxy}`); | ||
} | ||
|
||
return await fetch(url, { | ||
...config, | ||
body: new URLSearchParams(body), | ||
}); | ||
} |
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
Oops, something went wrong.