-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
completing API for kleros verifications
- Loading branch information
1 parent
46852ca
commit 25ce210
Showing
13 changed files
with
707 additions
and
6,423 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 |
---|---|---|
|
@@ -37,10 +37,10 @@ | |
"axios": "^0.27.2", | ||
"csv-parse": "^5.3.0", | ||
"ethereum-checksum-address": "^0.0.8", | ||
"ethers": "^5.7.2", | ||
"jsonschema": "^1.4.1", | ||
"shelljs": "^0.8.5", | ||
"uuid": "^8.3.2", | ||
"web3": "^1.8.0" | ||
"uuid": "^8.3.2" | ||
}, | ||
"packageManager": "[email protected]", | ||
"repository": { | ||
|
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
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,26 +1,18 @@ | ||
export interface Verification { | ||
verified: boolean; | ||
type: VerificationType; | ||
timestamp: number; | ||
proof: VerificationProof; | ||
} | ||
|
||
type VerificationProof = AdminVerificationProof | KlerosTCRVerificationProof | Map3TCRVerificationProof | Map3MapsTcrVerificationProof; | ||
type VerificationProof = AdminVerificationProof | TCRVerificationProof; | ||
|
||
interface AdminVerificationProof { | ||
signature: string; | ||
} | ||
|
||
interface KlerosTCRVerificationProof { | ||
ipfsUri: string; | ||
} | ||
|
||
interface Map3TCRVerificationProof { | ||
ipfsUri: string; | ||
interface TCRVerificationProof { | ||
resolutionTxHash: string; | ||
chainId: number; | ||
} | ||
|
||
interface Map3MapsTcrVerificationProof extends Map3TCRVerificationProof { } | ||
|
||
export type VerificationType = 'ADMIN' | 'KLEROS_TCR' | 'MAP3_TCR' | 'MAP3_MAPS_TCR'; |
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
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
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
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
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
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,5 +1,4 @@ | ||
export interface TcrCheckResult { | ||
inTcr: boolean, | ||
ipfsUri: string, | ||
resolutionTxHash: string | ||
resolutionTxHash: string | ||
} |
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,14 @@ | ||
import test from "ava"; | ||
import { attemptTcrVerificationForAsset } from "./verifications"; | ||
|
||
const USDC_ON_ETH = 'ethereum:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'; | ||
|
||
test("Check if USDC is is set as verified on Kleros TCR", async (t) => { | ||
try { | ||
const result = await attemptTcrVerificationForAsset('ethereum', USDC_ON_ETH); | ||
|
||
t.true(result.verified); | ||
} catch (err) { | ||
t.fail(err.message); | ||
} | ||
}); |
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,56 +1,71 @@ | ||
import { AssetMap } from "../model/AssetMap"; | ||
import { Verification } from "../model/Verification"; | ||
import { checkIfAssetInKlerosTCR } from "./tcrs/kleros-tcr"; | ||
|
||
export interface VerificationAttemptResult { | ||
verified: boolean; | ||
verification: Verification; | ||
verifications: Verification[]; | ||
} | ||
|
||
export function setAdminVerificationForAsset(signature: string, networkCode: string, address?: string): Verification { | ||
export async function setAdminVerificationForAsset(signature: string, networkCode: string, address?: string): Promise<VerificationAttemptResult> { | ||
// TODO; signature operation | ||
return { | ||
verified: true, | ||
type: 'ADMIN', | ||
timestamp: Date.now() / 1000, | ||
proof: { | ||
signature: '0x' | ||
} | ||
verified: false, | ||
verifications: [] | ||
} | ||
} | ||
|
||
export function setAdminVerificationForMap(signature: string, map: AssetMap): Verification { | ||
export async function setAdminVerificationForMap(signature: string, map: AssetMap): Promise<VerificationAttemptResult> { | ||
|
||
// TODO; signature operation | ||
return { | ||
verified: true, | ||
type: 'ADMIN', | ||
timestamp: Date.now() / 1000, | ||
proof: { | ||
signature: '0x' | ||
} | ||
verified: false, | ||
verifications: [] | ||
} | ||
} | ||
|
||
export function attemptTcrVerificationForAsset(networkCode: string, address?: string): Verification { | ||
export async function attemptTcrVerificationForAsset(networkCode: string, address?: string): Promise<VerificationAttemptResult> { | ||
// If ethereum, check the kleros tcr and map3 tcr to see if its verified and produce the verification. Otherwise just the map3tcr | ||
return { | ||
verified: true, | ||
type: 'KLEROS_TCR', | ||
timestamp: Date.now() / 1000, | ||
proof: { | ||
ipfsUri: 'ipfs://QmWJ7CpY6hJkLjyYQ2zEeY2YJZ9XgZK1n8JWd7vP6oKJjK' | ||
|
||
if(networkCode !== 'ethereum' || !address) { | ||
throw new Error(`Invalid network code or address for TCR verification`); | ||
} | ||
|
||
try { | ||
const klerosTcrResult = await checkIfAssetInKlerosTCR(address); | ||
|
||
if(!klerosTcrResult.inTcr) { | ||
return { | ||
verified: false, | ||
verifications: [] | ||
} | ||
} | ||
|
||
return { | ||
verified: true, | ||
verifications: [{ | ||
verified: true, | ||
type: 'KLEROS_TCR', | ||
proof: { | ||
resolutionTxHash: klerosTcrResult.resolutionTxHash, | ||
chainId: 1 | ||
} | ||
}] | ||
} | ||
|
||
} catch (err) { | ||
console.error(err); | ||
return { | ||
verified: false, | ||
verifications: [] | ||
} | ||
} | ||
} | ||
|
||
export function attemptTcrVerificationForMap(map: AssetMap): Verification { | ||
export async function attemptTcrVerificationForMap(map: AssetMap): Promise<VerificationAttemptResult> { | ||
// Check the map3 maps tcr to see if its verified and produce the verification | ||
return { | ||
verified: true, | ||
type: 'KLEROS_TCR', | ||
timestamp: Date.now() / 1000, | ||
proof: { | ||
ipfsUri: 'ipfs://QmWJ7CpY6hJkLjyYQ2zEeY2YJZ9XgZK1n8JWd7vP6oKJjK' | ||
} | ||
verified: false, | ||
verifications: [] | ||
} | ||
} |
Oops, something went wrong.