Skip to content

Instantly share code, notes, and snippets.

View nakov's full-sized avatar
🎯
Focused on the global SoftUni expansion: https://softuni.org

Svetlin Nakov nakov

🎯
Focused on the global SoftUni expansion: https://softuni.org
View GitHub Profile
@nakov
nakov / mnemonic-ethers-js-example.js
Created April 11, 2018 10:01
Encrypt / Decrypt Mnemonic words as JSON
(async function() {
let defaultDerivePath = "m/44'/60'/0'/0/0";
let hdnode = require('ethers/wallet/hdnode');
let ss = require('ethers/wallet/secret-storage');
//let words = 'verb position snow palace gift limb citizen alpha stay sphere swear proof';
let words = 'tiger guilt skill adjust worry rival roof bicycle raven mail cherry strong body afford again praise upper wolf dry joke web bargain sea hint';
let entropy = hdnode.mnemonicToEntropy(words);
{
"version":3,
"id":"14ed6caf-0b69-4348-85e6-6ea0b15352cd",
"address":"9ab14321b263d5c1a7715098a1a31510cb828409",
"Crypto":{
"ciphertext":"838cc6626170166b2ec15911e496b603da6c08de8ef188d9f0ef27fd84d0c572",
"cipherparams":{
"iv":"f6ed0a488d596de27adf087f9c9e6946"
},
"cipher":"aes-128-ctr",
@nakov
nakov / UTC--2018-05-13T16-42-44.0Z--cf4aa487dece1b7bd0b5c1495222931f02fab1f3.json
Last active May 13, 2018 16:49
HD wallet, exported as UTC / JSON using Ethers.js
{
"address": "cf4aa487dece1b7bd0b5c1495222931f02fab1f3",
"id": "c24815ed-b06c-481f-bf0c-9747b18aac2d",
"version": 3,
"Crypto": {
"cipher": "aes-128-ctr",
"cipherparams": {
"iv": "b5e531fc4a67e6665e5e0d4a500ef738"
},
"ciphertext": "8174066d494c46be31c59ef7fec1c6815c412e3762da68e76f7df263e6afee55",
There is a simple way to check the last events in GitHub from certain user, including all his "git push" events:
https://api.github.com/users/{user}/events
Exmaple: https://api.github.com/users/nakov/events
@nakov
nakov / HD-wallet-create-new.js
Created November 4, 2018 20:39
Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018) - JavaScript Code Examples
let ethers = require('ethers');
let rnd256Bits = ethers.utils.randomBytes(256 / 8);
let mnemonics = ethers.HDNode.entropyToMnemonic(rnd256Bits);
let hdWallet = ethers.HDNode.fromMnemonic(mnemonics);
console.log("Wallet mnemonics:", mnemonics);
for (let index=0; index<5; index++) {
let key = hdWallet.derivePath(`m/44'/60'/0'/0/${index}'`);
console.log(`Private key #${index}: ${key.privateKey}`);
@nakov
nakov / AES-256-CTR-Argon2-HMAC-SHA256-example.js
Last active November 9, 2023 02:32
Cryptography for JavaScript Developers: Hashes, HMAC, PBKDF2, Scrypt, Argon2, AES-256-CTR, ECDSA, EdDSA, secp256k1, Ed25519
const aes = require("aes-js");
const argon2 = require("argon2");
const crypto = require("crypto");
const cryptoJS = require("crypto-js");
// Encrypt using AES-256-CTR-Argon2-HMAC-SHA-256
async function aes256ctrEncrypt(plaintext, password) {
let argon2salt = crypto.randomBytes(16); // 128-bit salt for argon2
let argon2Settings = { type: argon2.argon2di, raw: true,
timeCost: 8, memoryCost: 2 ** 15, parallelism: 2,
@nakov
nakov / gitbook-build.cmd
Last active August 1, 2019 14:47
GitBook-CLI Build & Deploy Scripts
npm install -g gitbook-cli
npm install -g serve
call gitbook install
call gitbook build . --log=debug --debug
start serve _book
start "" http://127.0.0.1:5000
pause
@nakov
nakov / repl.it-code-runner.js
Created August 1, 2019 15:41
GitBook Plugins
gitbook.events.bind("page.change", function() {
let runCodeLinks = $("p:contains('Run the above code example:') a");
for (let link of runCodeLinks) {
if (typeof(link.href) == "string" && link.href.startsWith("https://repl.it/")) {
// A repl.it link is found --> check for code box above it
let codeBox = $(link).parent().prev();
if (codeBox.is("pre")) {
// A code box is found just before the code link --> inject the [Run] button
let runButton = $("<a href='#' class='run-code-button' style='float:right'>Run</a>");
let loadingBox = $("<span class='run-code-loading' style='float:right;display:none'>Loading …</span>");
@nakov
nakov / select-replace.sql
Last active November 25, 2019 10:14
MySQL Find / Replace in the Database via SQL commands
SELECT REPLACE(post_title, " ", " ") FROM wp_posts
@nakov
nakov / kinvey-example.html
Created December 8, 2019 16:02
Kinvey Example - 12/2019
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script src="kinvey-example.js"></script>
</head>
<body>
<a id='buttonLoad' href='#'>[Load]</a>