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 / Cert.sol
Created February 16, 2018 12:32
Document Registry - Infura API
pragma solidity ^0.4.18;
contract Cert {
mapping (string => bool) private certificateHashes;
address contractOwner = msg.sender;
function add(string hash) public {
require (msg.sender == contractOwner);
certificateHashes[hash] = true;
}
@nakov
nakov / transactionSigner.js
Created March 7, 2018 10:32
Sign a transaction in JS
const CryptoJS = require("crypto-js");
const EC = require('elliptic').ec;
const secp256k1 = new EC('secp256k1');
function signData(data, privKey) {
let keyPair = secp256k1.keyFromPrivate(privKey);
let signature = keyPair.sign(data);
return [signature.r.toString(16), signature.s.toString(16)];
}
@nakov
nakov / compress-ec-key.py
Created March 7, 2018 13:08
Compress / decompress elliptic curve public key in Pyhton
from pycoin.ecdsa import CurveFp, Point
from nummaster.basic import sqrtmod
def compress_key_pair(key_pair):
return (key_pair.x(), key_pair.y() % 2)
def uncompress_key(curve, compressed_key):
x, is_odd = compressed_key
p, a, b = curve.p(), curve.a(), curve.b()
y = sqrtmod(pow(x, 3, p) + a * x + b, p)
@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 / CryptoUtils.js
Last active November 16, 2018 22:26
JS Crypto Utils - secp256k1 EC cryptography and blockchain functions
const CryptoJS = require("crypto-js");
const EC = require('elliptic').ec;
const secp256k1 = new EC('secp256k1');
function publicKeyToAddress(pubKey) {
let address = CryptoJS.RIPEMD160(pubKey).toString();
return address;
}
function privateKeyToPublicKey(privKey) {
@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>");