WIP WIP WIP crypto

This commit is contained in:
Philipp Heckel 2022-07-08 08:16:03 -04:00
parent 67da1e4922
commit e5dc2242c4
7 changed files with 3497 additions and 12 deletions

3442
examples/publish-js/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,6 @@
{
"dependencies": {
"browserify": "^17.0.0",
"jose": "^4.8.3"
}
}

View file

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Publish to ntfy.sh</title>
</head>
<body>
<input id="password" placeholder="Topic password"/>
<button onclick="publish()">Publish encrypted message</button>
</body>
<script async src="https://unpkg.com/jose@4.8.3/dist/browser/jwe/compact/encrypt.js" type="module"></script>
<script async src="publish-encrypted.js" type="module"></script>
</html>

View file

@ -0,0 +1,7 @@
import * as jose from 'jose'
async function publish() {
const jwe = await new jose.CompactEncrypt(new TextEncoder().encode('Secret message from JS!'))
.setProtectedHeader({ alg: 'dir', enc: 'A256GCM' })
.encrypt(publicKey)
}

View file

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Publish to ntfy.sh</title>
</head>
<body>
<button onclick="publish()">Publish</button>
</body>
<script>
function publish() {
fetch('https://ntfy.sh/mytopic', {
method: 'POST', // PUT works too
body: 'Backup successful 😀'
});
}
</script>
</html>