Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c34e757
refactor: :fire: support for sadaiv id
aditipolkam May 9, 2023
0039116
Merge remote branch new-features into new-features
aditipolkam May 9, 2023
2ea2e92
feat: :sparkles: add functions for new structure
aditipolkam May 17, 2023
ebeb3c6
refactor: :fire: contracts with diff logic and write tests
aditipolkam May 20, 2023
03a1a66
refactor: :fire: modify contracts and add backup test
aditipolkam May 20, 2023
7a96384
feat: :clown_face: add owner mapping
aditipolkam May 20, 2023
d1bdd2a
fix: :bug: add new owner function
aditipolkam May 22, 2023
572cb97
refactor: :rotating_light: add deploy script and modify backup contract
aditipolkam May 22, 2023
8d44d6c
docs: :bulb: add comments to describe functions
aditipolkam May 22, 2023
33212c1
fix: :bug: uid for build mapping and add timestamp
aditipolkam May 23, 2023
025084e
feat: :zap: add onlyOwner modifier for adding providers
aditipolkam May 24, 2023
fa11422
perf: :ambulance: emit build hash identifier
aditipolkam May 24, 2023
7ec7f1e
fix: :bug: check if address regsitered before updates
aditipolkam May 24, 2023
7688e06
modify: 🛠️contract for forked repo struct
aditipolkam May 25, 2023
08774bc
removed need of signatures in contracts
tusharojha May 28, 2023
0a16656
upgraded contract with solving infinite gas issue
tusharojha May 29, 2023
5b9602a
fixed bug in contract addProvider
tusharojha May 30, 2023
8eff20a
add scripts
aditipolkam May 31, 2023
b874787
Merge branch 'new-features' of https://github.com/sadaiv-ci/contracts…
aditipolkam May 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint",
"editor.formatOnPaste": false, // required
"editor.formatOnType": false, // required
"editor.formatOnSave": true, // optional
"editor.formatOnSaveMode": "file", // required to format on save
"files.autoSave": "onFocusChange", // optional but recommended
"vs-code-prettier-eslint.prettierLast": "false",
"[solidity]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
} // set as "true" to run 'prettier' last not first
}
3 changes: 3 additions & 0 deletions address.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Deployed Sadaiv verifier contract to: 0xd4E90ed4Da0a05c4552Db27511D467dB2c29C650
Deployed Sadaiv Id contract to: 0x1e30A35CdeF1eB258EA7731A44F3AA255AC31Da5
Deployed Sadaiv Backup contract to: 0xBFdD75A2098A177AD44A15480Ec20d650d981884
57 changes: 0 additions & 57 deletions contracts/Sadaiv.sol

This file was deleted.

66 changes: 66 additions & 0 deletions contracts/SadaivBackup.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

contract SadaivBackup {
mapping(address => bool) public owners;

constructor() {
owners[msg.sender] = true;
}

modifier onlyOwner() {
require(owners[msg.sender], "Not authorized!");
_;
}

function makeOwner(address _address) public onlyOwner {
owners[_address] = true;
}

function checkIfOwner(address _address) public view returns (bool) {
return owners[_address];
}

struct Build {
string branch;
string commitMessage;
string commitHash;
string timestamp;
uint256 contributorGithubId;
string backupCid;
string changesCid; //future scope
}

struct Repository {
uint256 id;
string name;
string fullname;
string description;
uint256 ownerGithubId;
uint256 size;
bool forked;
string defaultBranch;
string timestamp;
string[] topics;
string[] languages;
}

mapping(uint256 => Repository) public userRepos; //repoId => repo
mapping(uint256 => mapping(bytes32 => Build)) public repoBuilds; //repoId => hash(barnch+commitHash) => build

event NewBuild(Repository repository, Build build, bytes32 buildhash);

function createNewBuild(
Repository memory _repo,
Build memory _build
) public onlyOwner {
userRepos[_repo.id] = _repo;
bytes32 buildhash = keccak256(
abi.encodePacked(
string(abi.encodePacked(_build.branch, _build.commitHash))
)
);
repoBuilds[_repo.id][buildhash] = _build;
emit NewBuild(_repo, _build, buildhash);
}
}
97 changes: 97 additions & 0 deletions contracts/SadaivId.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/Counters.sol";

interface VerifySignatureInterface {
function verifySignature(
address _signer,
string memory _message,
bytes memory signature
) external returns (bool);
}

contract SadaivId {
mapping(address => bool) public owners;
VerifySignatureInterface public verifySignatureContract;
using Counters for Counters.Counter;
Counters.Counter public sadaivId;

constructor(address verifyContractAddress) {
owners[msg.sender] = true;
verifySignatureContract = VerifySignatureInterface(verifyContractAddress);
}

modifier onlyOwner() {
require(owners[msg.sender], "Not authorized!");
_;
}

function makeOwner(address _address) public onlyOwner {
owners[_address] = true;
}

function checkIfOwner(address _address) public view returns (bool) {
return owners[_address];
}

mapping(uint256 => mapping(uint256 => bool)) public sadaivIdToGithubId;
mapping(address => uint256) public SCWAddressToSadaivId;
mapping(uint256 => string) public contributorData; //sadaiv id to contributor data cid

event NewUser(uint256 sadaivId, address scwAddress);
event NewProfileChange(uint256 sadaivId, string cid);
event NewProvider(uint256 sadaivId, uint256 provider);

//register new user(with scw address) if not already registered
function registerUser(
string memory message,
bytes memory signature,
address signer
) public returns (uint256) {
require(
verifySignatureContract.verifySignature(signer, message, signature),
"Address not authorized!"
);
require(SCWAddressToSadaivId[signer] == 0, "Address already registered.");
sadaivId.increment();
SCWAddressToSadaivId[signer] = sadaivId.current();
emit NewUser(sadaivId.current(), signer);
return sadaivId.current();
}

//function to add github account ids for a sadaiv userid
function addProviders(
string memory message,
bytes memory signature,
address signer,
uint256 _newId
) public onlyOwner {
require(
verifySignatureContract.verifySignature(signer, message, signature),
"Address not authorized!"
);
uint256 _sadaivId = SCWAddressToSadaivId[signer];
require(
!sadaivIdToGithubId[_sadaivId][_newId],
"Provider already registered."
);
sadaivIdToGithubId[_sadaivId][_newId] = true;
emit NewProvider(_sadaivId, _newId);
}

//change the contributor data cid
function changeContributorData(
string memory message,
bytes memory signature,
address signer,
string memory cid
) public {
require(
verifySignatureContract.verifySignature(signer, message, signature),
"Address not authorized!"
);
uint256 _sadaivId = SCWAddressToSadaivId[signer];
contributorData[_sadaivId] = cid;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle check if the profile doesn't exist?

If some random address try to update, _sadaivId would be zero. so pls add this check and write test for it.

emit NewProfileChange(_sadaivId, cid);
}
}
51 changes: 51 additions & 0 deletions contracts/VerifySignature.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

contract VerifySignature {
function getMessageHash(
string memory _message
) public pure returns (bytes32) {
return keccak256(abi.encodePacked(_message));
}

function getEthSignedMessageHash(
bytes32 _messageHash
) public pure returns (bytes32) {
return
keccak256(
abi.encodePacked("\x19Ethereum Signed Message:\n32", _messageHash)
);
}

function verifySignature(
address _signer,
string memory _message,
bytes memory signature
) public pure returns (bool) {
bytes32 messageHash = getMessageHash(_message);
bytes32 ethSignedMessageHash = getEthSignedMessageHash(messageHash);

return recoverSigner(ethSignedMessageHash, signature) == _signer;
}

function recoverSigner(
bytes32 _ethSignedMessageHash,
bytes memory _signature
) public pure returns (address) {
(bytes32 r, bytes32 s, uint8 v) = splitSignature(_signature);

return ecrecover(_ethSignedMessageHash, 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 {
r := mload(add(sig, 32))
s := mload(add(sig, 64))
v := byte(0, mload(add(sig, 96)))
}
}
}
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"@types/mocha": "^9.1.1",
"@types/node": "^12.20.55",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"@typescript-eslint/parser": "^5.0.1",
"chai": "^4.3.7",
"dotenv": "^10.0.0",
"eslint": "^7.32.0",
"eslint": "^8.7.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.26.0",
Expand All @@ -24,12 +24,15 @@
"ethers": "^5.7.2",
"hardhat": "^2.12.3",
"hardhat-gas-reporter": "^1.0.9",
"prettier": "^2.8.0",
"prettier": "^2.5.1",
"prettier-plugin-solidity": "^1.0.0",
"solhint": "^3.3.7",
"solidity-coverage": "^0.7.22",
"ts-node": "^10.9.1",
"typechain": "^5.2.0",
"typescript": "^4.9.3"
"typescript": "^4.4.4"
},
"dependencies": {
"@openzeppelin/contracts": "^4.8.3"
}
}
38 changes: 38 additions & 0 deletions scripts/backup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const hre = require("hardhat");

async function main() {
const address = "0x5FbDB2315678afecb367f032d93F642f64180aa3";
const backupContractFactory = await hre.ethers.getContractFactory("SadaivBackup");
const backupContract = await backupContractFactory.attach(address);

const repository = {
name: 'Repo1',
fullname: 'Fullname1',
description: 'Description1',
ownerGithubId: 12345,
size: 100,
defaultBranch: 'main',
topics: ['topic1', 'topic2'],
language: 'Solidity',
};

const build = {
branch: 'branch1',
commitMessage: 'Commit Message1',
contributorGithubId: 67890,
cid: 'CID123',
changesCid: 'CID456',
};

const repoId = 1;
const commitHash = 'CommitHash123';

let txn = await backupContract.createNewBuild(repository, build, repoId, commitHash);
await txn.wait();
console.log("Backed up");
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
Loading