Merge pull request #3 from 3lLobo/totp2fa

TotpAuth deployed to Optimism 
This commit is contained in:
3lLobo
2022-09-18 19:07:21 +02:00
committed by GitHub
7 changed files with 101 additions and 38 deletions

View File

@@ -2,33 +2,52 @@
![crib](https://user-images.githubusercontent.com/25290565/190274993-05c12f02-aa56-4041-af27-67ffda79bcf1.jpg)
Till now, all we got issa first draft of the TOTP Authenticator.
We proudly present the TotpAuthenticator.
One step closer to zero trust and one step away from web2.
You can now use 2FA authentication for your business contacts your web-applications or even your IOTs without a centralized database storing your keys and authenticating users. The Blocqchain takes over!
## Cyborg Run 🏃‍♂️
Try running some of the following tasks:
Yarn, remix and hardhat:
```shell
npx hardhat help
npx hardhat test
GAS_REPORT=true npx hardhat test
npx hardhat node
npx hardhat run scripts/deploy.ts
yarn hardhat node
yarn remixd -s . --remix-ide https://remix.ethereum.org
yarn hardhat test
```
## Hashing
## hashing
Changes:
- contract tested
- logic fixed
- Readme updated
How to calculate and submit hash:
convert TOTP (eg.`123456`) to bytes/hex with ethers. Padding left!!!
convert TOTP (eg. `123456`) to bytes/hex with ethers. Padding left!!!
Then sha256 it and insert `0x` at the start.
That's it, now it should match the sha256 on-chain.
[sha256](https://it-tools.tech/hash-text)
[bytes32](https://web3-type-converter.onbrn.com/)
## Optimism
A blocqchain with free lunch, I mean, free gas! How could we not choose for Optimism?
Contract TotpAuthenticator deployed to Optimism Goerli:
```bash
0xAdF1c645E2bb8C0057537263db6Ae6ECa7085966
# Deployment transaction hash
0x846528416731ddd42e37b8f2dc9fbac24aaf105ebe23d53707a680fc99d68ce0
```
Owner wallet:
```sh
0x369551E7c1D29756e18BA4Ed7f85f2E6663e1e8d
```
[Testnet Explorer](https://blockscout.com/optimism/goerli)
[Faucets](https://optimismfaucet.xyz/)

View File

@@ -28,6 +28,7 @@ contract TotpAuthenticator is Ownable {
// Maps a requestId to a address and its response.
mapping(uint256 => mapping(address => AuthData)) public responses;
// Maps requestId to completes authentication
// TODO: make this private and create a function to get this value, which initially checks if the requested Id is below the current counter. Otherwise collisions can happen after reset.
mapping(uint256 => Authentication) public completedAuth;
// Events to index with theGraph in order to notify both parties
@@ -120,7 +121,8 @@ contract TotpAuthenticator is Ownable {
// Reset the contract by deleting all data
function resetAuthenticator() public onlyOwner {
// TODO: delete everything
requestCounter = 0;
// TODO: create zero AuthResponse and set the responses[_requestId] = zeroAuthResponse each time a request is initalized.
// How do we empty the mappings?
emit EventResetContract(block.timestamp);
}

View File

@@ -3,6 +3,20 @@ import '@nomicfoundation/hardhat-toolbox'
const config: HardhatUserConfig = {
solidity: '0.8.17',
networks: {
// for testnet
'optimism-goerli': {
url: 'https://goerli.optimism.io',
// accounts: [privateKey1, ]
},
// for the local dev environment
'optimism-local': {
url: 'http://localhost:8545',
accounts: [
'0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d',
],
},
},
}
export default config

View File

@@ -19,7 +19,7 @@ async function main() {
}
async function testTotp() {
const Totp = await ethers.getContractFactory("TotpAuthenticator")
const Totp = await ethers.getContractFactory('TotpAuthenticator')
const totp = await Totp.deploy()
await totp.deployed()

View File

@@ -1,21 +0,0 @@
import { time, loadFixture } from '@nomicfoundation/hardhat-network-helpers'
import { anyValue } from '@nomicfoundation/hardhat-chai-matchers/withArgs'
import { expect } from 'chai'
import { ethers } from 'hardhat'
describe('TotpAuthenticator', () => {
async function deployTotp() {
const Totp = await ethers.getContractFactory("TotpAuthenticator")
const totp = await Totp.deploy()
await totp.deployed()
console.log(`Totp successfully deployed to ${totp.address}`)
return totp
}
deployTotp()
}
)

View File

@@ -0,0 +1,49 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.22 <0.9.0;
// This import is automatically injected by Remix
import "remix_tests.sol";
// This import is required to use custom transaction context
// Although it may fail compilation in 'Solidity Compiler' plugin
// But it will work fine in 'Solidity Unit Testing' plugin
import "remix_accounts.sol";
import "../contracts/TotpAuthenticator.sol";
// File name has to end with '_test.sol', this file can contain more than one testSuite contracts
contract testSuite {
/// 'beforeAll' runs before all other tests
/// More special functions are: 'beforeEach', 'beforeAll', 'afterEach' & 'afterAll'
function beforeAll() public {
// <instantiate contract>
Assert.equal(uint(1), uint(1), "1 should be equal to 1");
}
function checkSuccess() public {
// Use 'Assert' methods: https://remix-ide.readthedocs.io/en/latest/assert_library.html
Assert.ok(2 == 2, 'should be true');
Assert.greaterThan(uint(2), uint(1), "2 should be greater than to 1");
Assert.lesserThan(uint(2), uint(3), "2 should be lesser than to 3");
}
function checkSuccess2() public pure returns (bool) {
// Use the return value (true or false) to test the contract
return true;
}
function checkFailure() public {
Assert.notEqual(uint(1), uint(1), "1 should not be equal to 1");
}
/// Custom Transaction Context: https://remix-ide.readthedocs.io/en/latest/unittesting.html#customization
/// #sender: account-1
/// #value: 100
function checkSenderAndValue() public payable {
// account index varies 0-9, value is in wei
Assert.equal(msg.sender, TestsAccounts.getAccount(1), "Invalid sender");
Assert.equal(msg.value, 100, "Invalid value");
}
}