This file contains 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
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 |
This file contains 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.5.0; | |
import "https://github.com/OpenZeppelin/openzeppelin-sdk/blob/v2.5.0/packages/lib/contracts/Initializable.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/token/ERC721/ERC721.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/token/ERC721/ERC721Enumerable.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/token/ERC721/ERC721Metadata.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/token/ERC721/ERC721MetadataMintable.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/token/ERC721/ERC721Pausable.sol"; | |
This file contains 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 { 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({ |
This file contains 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
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')); |
This file contains 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
async function calcEthSig(plaintext) { | |
let signature = await sign(plaintext, keyId); | |
if (signature.Signature == undefined) { | |
throw new Error('Signature is undefined.'); | |
} | |
console.log("encoded sig: " + signature.Signature.toString('hex')); | |
let decoded = EcdsaSigAsnParse.decode(signature.Signature, 'der'); | |
let r : BN = decoded.r; | |
let s : BN = decoded.s; |
This file contains 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
function recoverPubKeyFromSig(sig: Buffer, r : BN, s : BN, v: number) { | |
console.log("Recovering public key with sig " + sig.toString('hex') + " r: " + r.toString(16) + " s: " + s.toString(16)); | |
let rBuffer = r.toBuffer(); | |
let sBuffer = s.toBuffer(); | |
let pubKey = ethutil.ecrecover(sig, v, rBuffer, sBuffer); | |
let addrBuf = ethutil.pubToAddress(pubKey); | |
var RecoveredEthAddr = ethutil.bufferToHex(addrBuf); | |
console.log( "Recovered ethereum address: " + RecoveredEthAddr); | |
return RecoveredEthAddr; | |
} |
This file contains 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 web3 = new Web3(new Web3.providers.HttpProvider("https://kovan.infura.io/v3/<your key>")); | |
let pubKey = await getPublicKey(keyId); | |
let ethAddr = getEthereumAddress((pubKey.PublicKey as Buffer)); | |
let ethAddrHash = ethutil.keccak(Buffer.from(ethAddr)); | |
// signing the 1st time | |
// we're signing the hash of our ethereum address | |
let sig = await findEthereumSig(ethAddrHash); | |
let recoveredPubAddr = findRightKey(ethAddrHash, sig.r, sig.s, ethAddr); |
This file contains 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 { KMS } from 'aws-sdk'; | |
const kms = new KMS({ | |
accessKeyId: '<access_key_id>', | |
secretAccessKey: '<access_secret>', | |
region: 'us-east-1', | |
apiVersion: '2014-11-01', | |
}); | |
kms.getPublicKey({ | |
KeyId: '<KMS key id>' | |
}); |
This file contains 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 EcdsaPubKey = asn1.define('EcdsaPubKey', function(this: any) { | |
// https://tools.ietf.org/html/rfc5480#section-2 | |
this.seq().obj( | |
this.key('algo').seq().obj( | |
this.key('algorithm').objid(), | |
this.key('parameters').objid(), | |
), | |
this.key('pubKey').bitstr() // <-- this is what we want | |
); | |
}); |
This file contains 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
async function sign(msgHash, keyId) { | |
const params : KMS.SignRequest = { | |
KeyId: keyId, | |
Message: msgHash, | |
SigningAlgorithm: 'ECDSA_SHA_256', | |
MessageType: 'DIGEST' | |
}; | |
return kms.sign(params).promise(); | |
} |
OlderNewer