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
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; | |
} |
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
blockchain.config.name = "regtest" | |
peer { | |
discovery = { | |
# if peer discovery is off | |
# the peer window will show | |
# only what retrieved by active | |
# peer [true/false] |
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
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)]; | |
} |
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
def modular_sqrt(a, p): | |
def legendre_symbol(a, p): | |
""" Compute the Legendre symbol a|p using | |
Euler's criterion. p is a prime, a is | |
relatively prime to p (if p divides | |
a, then a|p = 0) | |
Returns 1 if a has a square root modulo | |
p, -1 otherwise. |
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
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) |
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
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) { |
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
let elliptic = require('elliptic'); | |
let sha3 = require('js-sha3'); | |
let ec = new elliptic.ec('secp256k1'); | |
// let keyPair = ec.genKeyPair(); | |
let keyPair = ec.keyFromPrivate("97ddae0f3a25b92268175400149d65d6887b9cefaf28ea2c078e05cdc15a3c0a"); | |
let privKey = keyPair.getPrivate("hex"); | |
let pubKey = keyPair.getPublic(); | |
console.log(`Private key: ${privKey}`); | |
console.log("Public key :", pubKey.encode("hex").substr(2)); |
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
import eth_keys, eth_utils, binascii, os | |
# privKey = eth_keys.keys.PrivateKey(os.urandom(32)) | |
privKey = eth_keys.keys.PrivateKey(binascii.unhexlify( | |
'97ddae0f3a25b92268175400149d65d6887b9cefaf28ea2c078e05cdc15a3c0a')) | |
pubKey = privKey.public_key | |
pubKeyCompressed = '0' + str(2 + int(pubKey) % 2) + str(pubKey)[2:66] | |
address = pubKey.to_checksum_address() | |
print('Private key (64 hex digits):', privKey) | |
print('Public key (plain, 128 hex digits):', pubKey) |
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
import org.bouncycastle.util.encoders.Hex; | |
import org.web3j.crypto.*; | |
import java.math.BigInteger; | |
public class ECCExample { | |
public static String compressPubKey(BigInteger pubKey) { | |
String pubKeyYPrefix = pubKey.testBit(0) ? "03" : "02"; | |
String pubKeyHex = pubKey.toString(16); | |
String pubKeyX = pubKeyHex.substring(0, 64); |
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
using System; | |
using System.Text; | |
using Nethereum.Hex.HexConvertors.Extensions; | |
using Nethereum.Signer; | |
using Nethereum.Util; | |
using Nethereum.Signer.Crypto; | |
class ECDSASecp256k1Example | |
{ | |
static void Main() |