-
-
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
10 changed files
with
1,771 additions
and
10 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,15 @@ | ||
# eciesjs-example | ||
|
||
Run `pnpm install` first | ||
|
||
## Basic usage | ||
|
||
Run `node index.js` | ||
|
||
## Check import | ||
|
||
Run `node import.js` | ||
|
||
## Browser | ||
|
||
Run `pnpm dev` |
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 { bytesToHex } from "@noble/ciphers/utils"; | ||
import { PrivateKey, decrypt, encrypt } from "eciesjs"; | ||
import './style.css'; | ||
|
||
|
||
const sk = new PrivateKey(); | ||
const encoder = new TextEncoder(); | ||
const decoder = new TextDecoder(); | ||
|
||
export function setup(encryptedElement, textElement, decryptedElement) { | ||
const text = "hello eciesjs🔒" | ||
let encrypted; | ||
|
||
encryptedElement.innerHTML = `click me to encrypt` | ||
textElement.innerHTML = text | ||
decryptedElement.innerHTML = `click me to decrypt` | ||
|
||
const _encrypt = () => { | ||
encrypted = encrypt(sk.publicKey.toHex(), encoder.encode(text)) | ||
encryptedElement.innerHTML = `encrypted:` | ||
textElement.innerHTML = `${bytesToHex(encrypted)}` | ||
decryptedElement.innerHTML = `click me to decrypt` | ||
} | ||
const _decrypt = () => { | ||
encryptedElement.innerHTML = `click me to encrypt` | ||
if (encrypted) { | ||
textElement.innerHTML = `${decoder.decode(decrypt(sk.secret, encrypted))}` | ||
decryptedElement.innerHTML = `decrypted:` | ||
encrypted = undefined | ||
} else { | ||
textElement.innerHTML = "click encrypt button first" | ||
} | ||
} | ||
encryptedElement.addEventListener('click', () => _encrypt()) | ||
decryptedElement.addEventListener('click', () => _decrypt()) | ||
} | ||
|
||
|
||
document.querySelector('#app').innerHTML = ` | ||
<div> | ||
<h1>Hello eciesjs!</h1> | ||
<div class="card"> | ||
<button id="encrypted" type="button"></button> | ||
<button id="decrypted" type="button"></button> | ||
</div> | ||
<p id="text"></p> | ||
</div> | ||
` | ||
|
||
setup(document.querySelector('#encrypted'), document.querySelector('#text'), | ||
document.querySelector('#decrypted')) |
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,93 @@ | ||
:root { | ||
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; | ||
line-height: 1.5; | ||
font-weight: 400; | ||
|
||
color-scheme: light dark; | ||
color: rgba(255, 255, 255, 0.87); | ||
background-color: #242424; | ||
|
||
font-synthesis: none; | ||
text-rendering: optimizeLegibility; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
} | ||
|
||
a { | ||
font-weight: 500; | ||
color: #646cff; | ||
text-decoration: inherit; | ||
} | ||
|
||
a:hover { | ||
color: #535bf2; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
display: flex; | ||
place-items: center; | ||
min-width: 320px; | ||
min-height: 100vh; | ||
} | ||
|
||
h1 { | ||
font-size: 3.2em; | ||
line-height: 1.1; | ||
} | ||
|
||
p { | ||
padding: 2em; | ||
word-break: break-all; | ||
} | ||
|
||
#app { | ||
max-width: 1280px; | ||
margin: 0 auto; | ||
padding: 2rem; | ||
text-align: center; | ||
} | ||
|
||
.card { | ||
padding: 2em; | ||
} | ||
|
||
.read-the-docs { | ||
color: #888; | ||
} | ||
|
||
button { | ||
border-radius: 8px; | ||
border: 1px solid transparent; | ||
padding: 0.6em 1.2em; | ||
font-size: 1em; | ||
font-weight: 500; | ||
font-family: inherit; | ||
background-color: #1a1a1a; | ||
cursor: pointer; | ||
transition: border-color 0.25s; | ||
} | ||
|
||
button:hover { | ||
border-color: #646cff; | ||
} | ||
|
||
button:focus, | ||
button:focus-visible { | ||
outline: 4px auto -webkit-focus-ring-color; | ||
} | ||
|
||
@media (prefers-color-scheme: light) { | ||
:root { | ||
color: #213547; | ||
background-color: #ffffff; | ||
} | ||
|
||
a:hover { | ||
color: #747bff; | ||
} | ||
|
||
button { | ||
background-color: #f9f9f9; | ||
} | ||
} |
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 @@ | ||
import { ECIES_CONFIG, utils } from "eciesjs"; | ||
import config from "eciesjs/config"; | ||
import consts from "eciesjs/consts"; | ||
|
||
console.log("ECIES_CONFIG:", ECIES_CONFIG) | ||
console.log("config:", config) | ||
console.log("consts:", consts) | ||
console.log("utils:", utils) |
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,15 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Eciesjs App</title> | ||
</head> | ||
|
||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/browser/script.js"></script> | ||
</body> | ||
|
||
</html> |
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,6 @@ | ||
import { PrivateKey, decrypt, encrypt } from "eciesjs"; | ||
|
||
const sk = new PrivateKey() | ||
const data = Buffer.from('hello world🌍') | ||
const decrypted = decrypt(sk.secret, encrypt(sk.publicKey.toHex(), data)) | ||
console.log(Buffer.from(decrypted).toString()) |
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,22 @@ | ||
{ | ||
"name": "eciesjs-example", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"eciesjs": "file:.." | ||
}, | ||
"devDependencies": { | ||
"vite": "^5.4.8", | ||
"vite-plugin-node-polyfills": "^0.22.0" | ||
} | ||
} |
Oops, something went wrong.