-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/Derricks-DApps/ETH-Online i…
…nto main
- Loading branch information
Showing
14 changed files
with
764 additions
and
62 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,21 @@ | ||
# 🏗 ETH ONLINE 2023 | ||
<img src = "..." atl="logo" hieght="50" width="50"/> <span style="color:skyblue; | ||
<span style="color:skyblue; | ||
font-weight: bold; | ||
font-size: 20px; | ||
font-family: Verdana"> | ||
[Project Name] | ||
BTree | ||
</span> | ||
<br/> | ||
<img src = "/Users/derrick/DewdLabs/eth-online/packages/nextjs/public/assets/logo.png" atl="logo" hieght="50" width="100"/> | ||
|
||
Governance and issuing service for Barcodes as an alternative to GS1. Gives Busnisesses a global database to share product information. | ||
|
||
## Create Barcodes (TBD) | ||
|
||
Lorem ipsum | ||
|
||
## Purchase Barcode (TBD) | ||
|
||
Lorem ipsum | ||
|
||
## Swap Barcodes (TBD) | ||
|
||
If a company wants to give ownership of their product to another company the barcode can be swapped to them. | ||
|
||
# DAO | ||
|
||
## Delete Barcodes (TBD) | ||
|
||
Lorem ipsum | ||
|
||
## Update Barcodes (TBD) | ||
Governance and issuing service for Barcodes as an alternative to GS1. Gives Busnisesses a global database to share product information. | ||
|
||
Lorem ipsum | ||
Contract Address - Scroll | ||
|
||
## Contributions | ||
3ca0db318371455e967791d71deaa48d | ||
|
||
Improvements submitted to project as we integrated them into our project. | ||
|
||
Live | ||
|
||
https://barcodes-psi.vercel.app/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,6 @@ | |
}, | ||
"devDependencies": { | ||
"@types/react": "^18.2.28", | ||
"husky": "~8.0.3", | ||
"lint-staged": "~13.2.2" | ||
}, | ||
"packageManager": "[email protected]", | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import fetch from 'node-fetch' | ||
import { ProofClient, ProofService } from '@nextdotid/sdk' | ||
import { EthereumAddress } from 'wallet.ts' | ||
import { createKeyPiar, sign } from './keypair' | ||
|
||
async function main() { | ||
const persona = createKeyPiar() | ||
const wallet = createKeyPiar() | ||
const { address } = EthereumAddress.from(Buffer.from(wallet.publicKey)) | ||
const publicKey = '0x' + persona.publicKey.toString('hex') | ||
|
||
console.log('Wallet Address:', address) | ||
console.log('Persona Public Key:', publicKey) | ||
|
||
const service = new ProofService({ | ||
client: ProofClient.development(fetch as unknown as typeof global.fetch), | ||
platform: 'ethereum', | ||
identity: address, | ||
public_key: publicKey, | ||
}) | ||
|
||
// health check | ||
await service.health() | ||
|
||
// create proof | ||
const proof = await service.createProof({ | ||
async onExtra(payload) { | ||
return { | ||
signature: await sign(payload, persona.privateKey), | ||
wallet_signature: await sign(payload, wallet.privateKey), | ||
} | ||
}, | ||
}) | ||
|
||
// verify the proof | ||
await proof.verify() | ||
|
||
// query all bindings | ||
const bindings = await service.allExistedBinding() | ||
|
||
console.log(JSON.stringify(bindings)) | ||
} | ||
|
||
main() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { KVClient, KVService } from '@nextdotid/sdk' | ||
import fetch from 'node-fetch' | ||
import { EthereumAddress } from 'wallet.ts' | ||
import { createKeyPiar, sign } from './keypair' | ||
|
||
async function main() { | ||
const persona = createKeyPiar() | ||
const { address } = EthereumAddress.from(Buffer.from(persona.publicKey)) | ||
const publicKey = '0x' + persona.publicKey.toString('hex') | ||
|
||
console.log('Persona Address:', address) | ||
console.log('Persona Public Key:', publicKey) | ||
|
||
const service = new KVService({ | ||
client: KVClient.development(fetch as unknown as typeof global.fetch), | ||
platform: 'ethereum', | ||
identity: address, | ||
persona: publicKey, | ||
}) | ||
|
||
const patch = { | ||
['pluginId']: 'example data', | ||
} | ||
|
||
// set with proof | ||
await service.set(patch, { | ||
onSignature(payload) { | ||
return sign(payload, persona.privateKey) | ||
}, | ||
}) | ||
|
||
// get all proofs | ||
const { proofs } = await service.get() | ||
|
||
console.log(proofs) | ||
} | ||
|
||
main() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { randomBytes } from 'crypto' | ||
import { HDKey } from 'wallet.ts' | ||
import { ecsign, toRpcSig, keccakFromString } from 'ethereumjs-util' | ||
|
||
export function createKeyPiar() { | ||
const seed = randomBytes(66) | ||
return HDKey.parseMasterSeed(seed).derive('') | ||
} | ||
|
||
export async function sign(message: string, privateKey: Buffer | null) { | ||
if (privateKey === null) throw new Error('Failed to sign.') | ||
message = `\x19Ethereum Signed Message:\n${message.length}${message}` | ||
const messageHash = keccakFromString(message, 256) | ||
const signature = ecsign(messageHash, privateKey) | ||
const signed = toRpcSig(signature.v, signature.r, signature.s).slice(2) | ||
return Buffer.from(signed, 'hex').toString('base64') | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
contract BarcodeDAO { | ||
// Structure to represent a proposal | ||
struct Proposal { | ||
uint256 id; | ||
string barcode; | ||
address proposer; | ||
uint256 forVotes; | ||
uint256 againstVotes; | ||
bool executed; | ||
} | ||
|
||
// Mapping to store the proposals | ||
mapping(uint256 => Proposal) public proposals; | ||
uint256 public proposalCount; | ||
|
||
// Mapping to store the votes for each proposal | ||
mapping(address => mapping(uint256 => bool)) public votes; | ||
|
||
// Minimum quorum required for a proposal to be executed | ||
uint256 public quorum; | ||
// Minimum approval required for a proposal to be executed | ||
uint256 public approvalThreshold; | ||
|
||
constructor(uint256 _quorum, uint256 _threshold) { | ||
quorum = _quorum; | ||
approvalThreshold = _threshold; | ||
} | ||
|
||
// Event to log when a new proposal is created | ||
event ProposalCreated(uint256 indexed proposalId, string barcode, address proposer); | ||
// Event to log when a proposal is voted on | ||
event Voted(uint256 indexed proposalId, address voter, bool inSupport); | ||
// Event to log when a proposal is executed | ||
event ProposalExecuted(uint256 indexed proposalId); | ||
|
||
// Function to create a new proposal | ||
function propose(string memory _barcode) external { | ||
require(bytes(_barcode).length > 0, "Barcode cannot be empty"); | ||
uint256 proposalId = proposalCount; | ||
proposals[proposalId] = Proposal({ | ||
id: proposalId, | ||
barcode: _barcode, | ||
proposer: msg.sender, | ||
forVotes: 0, | ||
againstVotes: 0, | ||
executed: false | ||
}); | ||
proposalCount++; | ||
|
||
emit ProposalCreated(proposalId, _barcode, msg.sender); | ||
} | ||
|
||
// Function to vote for or against a proposal | ||
function vote(uint256 proposalId, bool support) external { | ||
require(proposalId < proposalCount, "Invalid proposal ID"); | ||
require(!votes[msg.sender][proposalId], "Already voted"); | ||
|
||
Proposal storage proposal = proposals[proposalId]; | ||
require(!proposal.executed, "Proposal already executed"); | ||
|
||
if (support) { | ||
proposal.forVotes += 1; | ||
} else { | ||
proposal.againstVotes += 1; | ||
} | ||
|
||
votes[msg.sender][proposalId] = true; | ||
emit Voted(proposalId, msg.sender, support); | ||
} | ||
|
||
// Function to execute a proposal if conditions are met | ||
function execute(uint256 proposalId) external { | ||
require(proposalId < proposalCount, "Invalid proposal ID"); | ||
|
||
Proposal storage proposal = proposals[proposalId]; | ||
require(!proposal.executed, "Proposal already executed"); | ||
|
||
uint256 totalVotes = proposal.forVotes + proposal.againstVotes; | ||
require(totalVotes >= quorum, "Quorum not reached"); | ||
|
||
if (proposal.forVotes * 100 > totalVotes * approvalThreshold) { | ||
// More than approvalThreshold % of votes are in favor | ||
// Execute the proposal | ||
proposal.executed = true; | ||
emit ProposalExecuted(proposalId); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.