Last active
November 26, 2022 00:03
-
-
Save mafintosh/63af4513181513d375b3751b9740e870 to your computer and use it in GitHub Desktop.
Showcasing bundled prebuilds with different runtimes
This file contains hidden or 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
var electron = require('electron') | |
electron.app.on('ready', function () { | |
var win = new electron.BrowserWindow({ | |
width: 800, | |
height: 600 | |
}) | |
win.loadURL('file://' + __dirname + '/index.html') | |
win.toggleDevTools() | |
}) |
This file contains hidden or 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
<html> | |
<head> | |
</head> | |
<body> | |
<script> | |
require('./index.js') | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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
console.log('Requiring sodium-native, a native module') | |
var sodium = require('sodium-native') | |
var message = new Buffer('Hello, World!') | |
var key = new Buffer(sodium.crypto_secretbox_KEYBYTES) | |
var nonce = new Buffer(sodium.crypto_secretbox_NONCEBYTES) | |
var cipher = new Buffer(sodium.crypto_secretbox_MACBYTES + message.length) | |
sodium.randombytes_buf(key) | |
sodium.randombytes_buf(nonce) | |
sodium.crypto_secretbox_easy(cipher, message, nonce, key) | |
console.log('Encrypted message: ' + cipher.toString('hex')) | |
var plainText = new Buffer(cipher.length - sodium.crypto_secretbox_MACBYTES) | |
sodium.crypto_secretbox_open_easy(plainText, cipher, nonce, key) | |
console.log('Decrypted message: ' + plainText.toString()) |
This file contains hidden or 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
{ | |
"name": "prebuild-example", | |
"version": "0.0.0", | |
"description": "Example that show cases bundled prebuilds", | |
"dependencies": { | |
"electron": "^1.4.15", | |
"sodium-native": "^1.3.0" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"node": "node index.js", | |
"electron": "electron index.js", | |
"electron-renderer": "electron app.js" | |
}, | |
"author": "Mathias Buus", | |
"license": "MIT" | |
} |
This file contains hidden or 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
# run it with node | |
npm run node | |
# run it with electron | |
npm run electron | |
# run it inside the electron render process | |
npm run electron-renderer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment