mirror of
https://github.com/zkitter/contracts.git
synced 2026-01-08 20:27:55 -05:00
initial commit
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.idea/
|
||||||
|
node_modules/
|
||||||
|
build/
|
||||||
60
contracts/AutismRegistrar.sol
Normal file
60
contracts/AutismRegistrar.sol
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
contract AutismRegistrar {
|
||||||
|
mapping(address => uint) public nonces;
|
||||||
|
|
||||||
|
event RecordUpdatedFor(address indexed account, bytes value, bytes proof, address relayer);
|
||||||
|
|
||||||
|
function updateFor(address account, bytes calldata value, bytes calldata proof) public {
|
||||||
|
uint nonce = nonces[account];
|
||||||
|
bytes32 msgHash = keccak256(abi.encodePacked(account, value, nonce));
|
||||||
|
bytes32 signedMsgHash = getEthSignedMessageHash(msgHash);
|
||||||
|
|
||||||
|
require(recoverSigner(signedMsgHash, proof) == account);
|
||||||
|
|
||||||
|
nonces[account] = nonce + 1;
|
||||||
|
|
||||||
|
emit RecordUpdatedFor(account, value, proof, msg.sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
function recoverSigner(bytes32 msgHash, bytes memory proof) public pure returns (address) {
|
||||||
|
(bytes32 r, bytes32 s, uint8 v) = splitSignature(proof);
|
||||||
|
return ecrecover(msgHash, v, r, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
function splitSignature(bytes memory sig) public pure returns (
|
||||||
|
bytes32 r,
|
||||||
|
bytes32 s,
|
||||||
|
uint8 v
|
||||||
|
) {
|
||||||
|
require(sig.length == 65, "invalid signature length");
|
||||||
|
|
||||||
|
assembly {
|
||||||
|
/*
|
||||||
|
First 32 bytes stores the length of the signature
|
||||||
|
|
||||||
|
add(sig, 32) = pointer of sig + 32
|
||||||
|
effectively, skips first 32 bytes of signature
|
||||||
|
|
||||||
|
mload(p) loads next 32 bytes starting at the memory address p into memory
|
||||||
|
*/
|
||||||
|
|
||||||
|
// first 32 bytes, after the length prefix
|
||||||
|
r := mload(add(sig, 32))
|
||||||
|
// second 32 bytes
|
||||||
|
s := mload(add(sig, 64))
|
||||||
|
// final byte (first byte of the next 32 bytes)
|
||||||
|
v := byte(0, mload(add(sig, 96)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// implicitly return (r, s, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getEthSignedMessageHash(bytes32 _messageHash) public pure returns (bytes32){
|
||||||
|
return
|
||||||
|
keccak256(
|
||||||
|
abi.encodePacked("\x19Ethereum Signed Message:\n32", _messageHash)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
8
migrations/1_initial_migration.js
Normal file
8
migrations/1_initial_migration.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
const Migrations = artifacts.require("AutismRegistrar");
|
||||||
|
|
||||||
|
module.exports = function (deployer) {
|
||||||
|
deployer.deploy(Migrations, {
|
||||||
|
// from: "0x5d432ce201d2c03234e314d4703559102Ebf365C",
|
||||||
|
from: "0x860C68abeEE0ecBd97729C7d1E09dA1e7EaD3C50",
|
||||||
|
});
|
||||||
|
};
|
||||||
4457
package-lock.json
generated
Normal file
4457
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
15
package.json
Normal file
15
package.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "contracts",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "truffle-config.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@truffle/hdwallet-provider": "^1.2.6",
|
||||||
|
"truffle-hdwallet-provider": "^1.0.17"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
||||||
131
truffle-config.js
Normal file
131
truffle-config.js
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
/**
|
||||||
|
* Use this file to configure your truffle project. It's seeded with some
|
||||||
|
* common settings for different networks and features like migrations,
|
||||||
|
* compilation and testing. Uncomment the ones you need or modify
|
||||||
|
* them to suit your project as necessary.
|
||||||
|
*
|
||||||
|
* More information about configuration can be found at:
|
||||||
|
*
|
||||||
|
* trufflesuite.com/docs/advanced/configuration
|
||||||
|
*
|
||||||
|
* To deploy via Infura you'll need a wallet provider (like @truffle/hdwallet-provider)
|
||||||
|
* to sign your transactions before they're sent to a remote public node. Infura accounts
|
||||||
|
* are available for free at: infura.io/register.
|
||||||
|
*
|
||||||
|
* You'll also need a mnemonic - the twelve word phrase the wallet uses to generate
|
||||||
|
* public/private key pairs. If you're publishing your code to GitHub make sure you load this
|
||||||
|
* phrase from a file you've .gitignored so it doesn't accidentally become public.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
const HDWalletProvider = require('@truffle/hdwallet-provider');
|
||||||
|
//
|
||||||
|
// const fs = require('fs');
|
||||||
|
// const mnemonic = fs.readFileSync(".secret").toString().trim();
|
||||||
|
console.log(process.env.PRIVATE_KEY);
|
||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* Networks define how you connect to your ethereum client and let you set the
|
||||||
|
* defaults web3 uses to send transactions. If you don't specify one truffle
|
||||||
|
* will spin up a development blockchain for you on port 9545 when you
|
||||||
|
* run `develop` or `test`. You can ask a truffle command to use a specific
|
||||||
|
* network from the command line, e.g
|
||||||
|
*
|
||||||
|
* $ truffle test --network <network-name>
|
||||||
|
*/
|
||||||
|
|
||||||
|
networks: {
|
||||||
|
// Useful for testing. The `development` name is special - truffle uses it by default
|
||||||
|
// if it's defined here and no other network is specified at the command line.
|
||||||
|
// You should run a client (like ganache-cli, geth or parity) in a separate terminal
|
||||||
|
// tab if you use this network and you must also set the `host`, `port` and `network_id`
|
||||||
|
// options below to some value.
|
||||||
|
//
|
||||||
|
development: {
|
||||||
|
host: "127.0.0.1", // Localhost (default: none)
|
||||||
|
port: 8545, // Standard Ethereum port (default: none)
|
||||||
|
network_id: "*", // Any network (default: none)
|
||||||
|
},
|
||||||
|
// Another network with more advanced options...
|
||||||
|
// advanced: {
|
||||||
|
// port: 8777, // Custom port
|
||||||
|
// network_id: 1342, // Custom network
|
||||||
|
// gas: 8500000, // Gas sent with each transaction (default: ~6700000)
|
||||||
|
// gasPrice: 20000000000, // 20 gwei (in wei) (default: 100 gwei)
|
||||||
|
// from: <address>, // Account to send txs from (default: accounts[0])
|
||||||
|
// websocket: true // Enable EventEmitter interface for web3 (default: false)
|
||||||
|
// },
|
||||||
|
|
||||||
|
arbitrum: {
|
||||||
|
provider: function() {
|
||||||
|
return new HDWalletProvider(
|
||||||
|
// throw-away seed for dev
|
||||||
|
process.env.PRIVATE_KEY,
|
||||||
|
`https://arbitrum-mainnet.infura.io/v3/28e5737b9034453d877f39dcf3f297b9`
|
||||||
|
);
|
||||||
|
},
|
||||||
|
network_id: 42161,
|
||||||
|
networkCheckTimeout: 1000000,
|
||||||
|
timeoutBlocks: 200
|
||||||
|
},
|
||||||
|
|
||||||
|
arbitrum_rinkeby: {
|
||||||
|
provider: function() {
|
||||||
|
return new HDWalletProvider(
|
||||||
|
// throw-away seed for dev
|
||||||
|
'maid side truck wood tuition engine onion extra frozen garbage car eager',
|
||||||
|
`https://arbitrum-rinkeby.infura.io/v3/28e5737b9034453d877f39dcf3f297b9`
|
||||||
|
);
|
||||||
|
},
|
||||||
|
network_id: 421611,
|
||||||
|
networkCheckTimeout: 10000000,
|
||||||
|
timeoutBlocks: 200
|
||||||
|
},
|
||||||
|
// Useful for deploying to a public network.
|
||||||
|
// NB: It's important to wrap the provider as a function.
|
||||||
|
// ropsten: {
|
||||||
|
// provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-PROJECT-ID`),
|
||||||
|
// network_id: 3, // Ropsten's id
|
||||||
|
// gas: 5500000, // Ropsten has a lower block limit than mainnet
|
||||||
|
// confirmations: 2, // # of confs to wait between deployments. (default: 0)
|
||||||
|
// timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
|
||||||
|
// skipDryRun: true // Skip dry run before migrations? (default: false for public nets )
|
||||||
|
// },
|
||||||
|
// Useful for private networks
|
||||||
|
// private: {
|
||||||
|
// provider: () => new HDWalletProvider(mnemonic, `https://network.io`),
|
||||||
|
// network_id: 2111, // This network is yours, in the cloud.
|
||||||
|
// production: true // Treats this network as if it was a public net. (default: false)
|
||||||
|
// }
|
||||||
|
},
|
||||||
|
|
||||||
|
// Set default mocha options here, use special reporters etc.
|
||||||
|
mocha: {
|
||||||
|
// timeout: 100000
|
||||||
|
},
|
||||||
|
|
||||||
|
// Configure your compilers
|
||||||
|
compilers: {
|
||||||
|
solc: {
|
||||||
|
version: "0.8.3", // Fetch exact version from solc-bin (default: truffle's version)
|
||||||
|
docker: false, // Use "0.5.1" you've installed locally with docker (default: false)
|
||||||
|
// settings: { // See the solidity docs for advice about optimization and evmVersion
|
||||||
|
// optimizer: {
|
||||||
|
// enabled: false,
|
||||||
|
// runs: 200
|
||||||
|
// },
|
||||||
|
// evmVersion: "byzantium"
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Truffle DB is currently disabled by default; to enable it, change enabled: false to enabled: true
|
||||||
|
//
|
||||||
|
// Note: if you migrated your contracts prior to enabling this field in your Truffle project and want
|
||||||
|
// those previously migrated contracts available in the .db directory, you will need to run the following:
|
||||||
|
// $ truffle migrate --reset --compile-all
|
||||||
|
|
||||||
|
db: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user