Skip to content

Instantly share code, notes, and snippets.

View lucashenning's full-sized avatar
🌴
Miami

Lucas H. lucashenning

🌴
Miami
View GitHub Profile
@lucashenning
lucashenning / getEthereumAddress.ts
Last active November 2, 2020 16:48
Get Ethereum Address from ASN1 DER encoded public key
function getEthereumAddress(publicKey: Buffer): string {
console.log("Encoded Pub Key: " + publicKey.toString('hex'));
// The public key is ASN1 encoded in a format according to
// https://tools.ietf.org/html/rfc5480#section-2
// I used https://lapo.it/asn1js to figure out how to parse this
// and defined the schema in the EcdsaPubKey object
let res = EcdsaPubKey.decode(publicKey, 'der');
let pubKeyBuffer : Buffer = res.pubKey.data;
console.log("Pub Key Buffer: " + pubKeyBuffer.toString('hex'));
@lucashenning
lucashenning / aws-kms-eth-sign.ts
Created November 2, 2020 13:51
AWS KMS based Ethereum transaction signing
import { KMS } from 'aws-sdk';
import { keccak256 } from 'js-sha3';
import * as ethutil from 'ethereumjs-util';
import Web3 from 'web3';
import * as asn1 from 'asn1.js';
import BN from 'bn.js';
import { Transaction, TxData } from 'ethereumjs-tx';
import { TransactionReceipt } from 'web3-core/types';
const kms = new KMS({
@lucashenning
lucashenning / gist:2fd70013254868c40788f83aa041463b
Last active November 15, 2018 17:17
send ethereum transaction
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_sendTransaction","params”:[{ "from": "0xe0e30a6de5ad46c2dd0b8064da49cc65e40adf4e", "to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567", "gas": "0x76c0", "gasPrice": "0x9184e72a000", "value": "0x9184e72a", "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"}],”id":1}' 172.31.34.23:8545