Skip to content

Instantly share code, notes, and snippets.

View Perseverance's full-sized avatar
🪄

George Spasov Perseverance

🪄
View GitHub Profile
@Perseverance
Perseverance / RelayerSimple.js
Last active October 2, 2018 14:20
Relayer execution - simple version
async execute(identityAddress, serviceContractAddress, value, data, signedDataHash) {
const identityContract = new ethers.Contract(identityAddress, IIdentityContract.abi, connection.wallet);
const transaction = await identityContract.execute(serviceContractAddress, value, data, signedDataHash);
return transaction.hash
}
pragma solidity ^0.4.24;
import "./IIdentityContract.sol";
import "./ECTools.sol";
import "../Proxy/SharedStorage.sol";
contract IdentityContract is IIdentityContract, SharedStorage {
uint256 public nonce;
pragma solidity ^0.4.24;
import "./IIdentityContract.sol";
import "./ECTools.sol";
import "../Proxy/SharedStorage.sol";
contract IdentityContract is IIdentityContract, SharedStorage {
uint256 public nonce;
pragma solidity ^0.4.24;
contract IdentityContract is IIdentityContract, SharedStorage {
function getSigner(bytes32 raw, bytes sig) public view returns(address signer) {
return ECTools.prefixedRecover(raw, sig);
}
modifier onlyValidSignature(address target, uint256 value, bytes data, bytes dataHashSignature) {
bytes32 dataHash = keccak256(abi.encodePacked(data, value, target));
address signer = getSigner(dataHash, dataHashSignature);
@Perseverance
Perseverance / Identity.sol
Last active October 2, 2018 14:06
Execute method of the Identity Proxy
function getSigner(bytes32 raw, bytes sig) public view returns(address signer) {
return ECTools.prefixedRecover(raw, sig);
}
modifier onlyValidSignature(address target, uint256 value, bytes data, bytes dataHashSignature) {
bytes32 dataHash = keccak256(abi.encodePacked(data, value, target, nonce));
address signer = getSigner(dataHash, dataHashSignature);
require(isSigner[signer]);
emit LogActionAuthorised(nonce, signer);
_;
declare var require: any;
function MetamaskSigner(web3, provider) {
this.provider = provider;
this.getAddress = function () {
return web3.eth.accounts[0];
};
Object.defineProperty(this, 'address', {
const ethers = require('ethers');
const providers = ethers.providers;
const Wallet = ethers.Wallet;
const utils = ethers.utils;
const contractABI = require('../build/contracts/ECToolsTest.json').abi;
var provider;
(async function () {
@Perseverance
Perseverance / ECTools.sol
Last active September 27, 2018 17:39
ECTools.sol
pragma solidity ^0.4.18;
library ECTools {
/**
* @dev Recover signer address from a message by using his signature
* @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address.
* @param sig bytes signature
*/
function recover(bytes32 hash, bytes sig) public pure returns (address) {
@Perseverance
Perseverance / metamask.js
Created April 10, 2018 12:37
Ethers.js Metamask Provider and Wallet
function MetamaskSigner(web3, provider) {
this.provider = provider;
this.getAddress = function () {
return web3.eth.accounts[0];
}
Object.defineProperty(this, 'address', {
get: function () {
if (web3.eth.accounts.length == 0) {
struct CatchedPoke {
uint caughtTime;
uint playerArrayIndex;
}
mapping(bytes32=>CatchedPoke) pokeLookupTable;
function addPoke(uint pokeId) {
bytes32 key = keccak256(msg.sender, pokeId);
CatchedPoke poke = pokeLookupTable[key];