Skip to content

Merging fixes from master to stable #10677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions app/assets/v2/js/pages/change_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -1235,10 +1235,10 @@ if (document.getElementById('gc-hackathon-new-bounty')) {
project_length: bounty.project_length,
experience_level: bounty.experience_level,
never_expires: bounty.never_expires,
reserved_for_user: {
reserved_for_user: bounty.bounty_reserved_for_user ? {
text: bounty.bounty_reserved_for_user.handle,
avatar_url: bounty.bounty_reserved_for_user.avatar_url
},
} : { text: '', avatar_url: ''},
richDescriptionContent: bounty.custom_issue_description ? JSON.parse(bounty.custom_issue_description) : null,
richDescriptionText: bounty.custom_issue_description ? bounty.custom_issue_description : ''
},
Expand Down
95 changes: 52 additions & 43 deletions app/assets/v2/js/pages/profile-trust.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Vue.component('active-trust-manager', {
this.step = 3;
// store passport into state after verifying content to avoid displaying the scoring until ready
this.passport = this.rawPassport;
console.log('geri this.passport', this.passport);
console.log('this.passport', this.passport);
});
},
async passportActionHandlerSave() {
Expand Down Expand Up @@ -190,52 +190,61 @@ Vue.component('active-trust-manager', {
// enter loading
this.loading = true;

// check for a passport and then its validity
if (passport) {
// check if the stamps are unique to this user...
const stampHashes = await apiCall(`/api/v2/profile/${document.contxt.github_handle}/passport/stamp/check`, {
'did': this.did,
'stamp_hashes': passport.stamps.map((stamp) => {
return stamp.credential.credentialSubject.hash;
})
});
// reset errors
this.verificationError = undefined;

try {

// check for a passport and then its validity
if (passport) {
// check if the stamps are unique to this user...
const stampHashes = await apiCall(`/api/v2/profile/${document.contxt.github_handle}/passport/stamp/check`, {
'did': this.did,
'stamp_hashes': passport.stamps.map((stamp) => {
return stamp.credential.credentialSubject.hash;
})
});

// perform checks on issuer, expiry, owner, VC validity and stamp_hash validity
await Promise.all(passport.stamps.map(async(stamp) => {
if (stamp && Object.keys(stamp).length > 0) {
// set the service against provider and issuer
const serviceDictId = `${this.IAMIssuer}#${stamp.provider}`;
// validate the contents of the stamp collection
const expiryCheck = new Date(stamp.credential.expirationDate) > new Date();
const issuerCheck = stamp.credential.issuer === this.IAMIssuer;
const hashCheck = stampHashes.checks[stamp.credential.credentialSubject.hash] === true;
const providerCheck = stamp.provider === stamp.credential.credentialSubject.provider;
const ownerCheck = selectedAccount.toLowerCase() == stamp.credential.credentialSubject.id.replace('did:pkh:eip155:1:', '').toLowerCase();

// check exists and has valid expiry / issuer / hash / owner...
if (this.serviceDict[serviceDictId] && stamp.credential && expiryCheck && issuerCheck && hashCheck && providerCheck && ownerCheck) {
// verify with DIDKits verifyCredential()
const verified = JSON.parse(await this.DIDKit.verifyCredential(
JSON.stringify(stamp.credential),
`{"proofPurpose":"${stamp.credential.proof.proofPurpose}"}`
));

// if no errors then this is a valid VerifiableCredential issued by the known issuer and is unique to our store
this.serviceDict[serviceDictId].is_verified = verified.errors.length === 0;
// perform checks on issuer, expiry, owner, VC validity and stamp_hash validity
await Promise.all(passport.stamps.map(async(stamp) => {
if (stamp && Object.keys(stamp).length > 0) {
// set the service against provider and issuer
const serviceDictId = `${this.IAMIssuer}#${stamp.provider}`;
// validate the contents of the stamp collection
const expiryCheck = new Date(stamp.credential.expirationDate) > new Date();
const issuerCheck = stamp.credential.issuer === this.IAMIssuer;
const hashCheck = stampHashes.checks[stamp.credential.credentialSubject.hash] === true;
const providerCheck = stamp.provider === stamp.credential.credentialSubject.provider;
const ownerCheck = selectedAccount.toLowerCase() == stamp.credential.credentialSubject.id.replace('did:pkh:eip155:1:', '').toLowerCase();

// check exists and has valid expiry / issuer / hash / owner...
if (this.serviceDict[serviceDictId] && stamp.credential && expiryCheck && issuerCheck && hashCheck && providerCheck && ownerCheck) {
// verify with DIDKits verifyCredential()
const verified = JSON.parse(await this.DIDKit.verifyCredential(
JSON.stringify(stamp.credential),
`{"proofPurpose":"${stamp.credential.proof.proofPurpose}"}`
));

// if no errors then this is a valid VerifiableCredential issued by the known issuer and is unique to our store
this.serviceDict[serviceDictId].is_verified = verified.errors.length === 0;
}
// collect array of true/false to check validity of every issued stamp (if stamp isn't recognised then it should be ignored (always true))
return !this.serviceDict[serviceDictId] ? true : this.serviceDict[serviceDictId].is_verified;
}
// collect array of true/false to check validity of every issued stamp (if stamp isn't recognised then it should be ignored (always true))
return !this.serviceDict[serviceDictId] ? true : this.serviceDict[serviceDictId].is_verified;
}
}));
}));

// set the new trustBonus score
this.trustBonus = Math.min(150, this.services.reduce((total, service) => {
return (service.is_verified ? service.match_percent : 0) + total;
}, 50));
// set the new trustBonus score
this.trustBonus = Math.min(150, this.services.reduce((total, service) => {
return (service.is_verified ? service.match_percent : 0) + total;
}, 50));
}
} catch (error) {
console.error('Error checking passport: ', error);
this.verificationError = 'Oh, we had a technical error while scoring. Please give it another try.';
throw error;
} finally {
this.loading = false;
}

// stop loading
this.loading = false;
},
async savePassport() {
// enter loading
Expand Down
4 changes: 1 addition & 3 deletions app/dashboard/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
from proxy.views import proxy_view
from retail.emails import render_share_bounty

from .passport_reader import (
SCORER_SERVICE_WEIGHTS, TRUSTED_IAM_ISSUER, get_passport, get_stream_ids,
)
from .passport_reader import SCORER_SERVICE_WEIGHTS, TRUSTED_IAM_ISSUER, get_passport, get_stream_ids

logger = get_task_logger(__name__)

Expand Down
12 changes: 6 additions & 6 deletions app/dashboard/templates/bounty/details2.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@ <h4 id="title" class="font-title p-0 text-center text-lg-left">[[ bounty.title ]
</div>
</div>

<div v-if="bounty.contact_details && bounty.contact_details.length > 0" class="mt-3">
<div v-if="bounty.contact_details && bounty.contact_details.length > 0" class="row mt-3">
<span class="bounty-info-heading">{% trans "Contacts" %}</span>

<div id="bounty-info-row" class="row font-body bounty-info">
<div class="col-12 col-sm-4 col-md-2 d-flex mt-1 text-nowrap" v-for="contact in bounty.contact_details">
<span v-if="contact.type=='Discord'"><i class="fab fa-discord mr-1"></i>[[contact.value]]</span>
<span v-if="contact.type=='Email'"><i class="fal fa-envelope mr-1"></i>[[contact.value]]</span>
<span v-if="contact.type=='Telegram'"><i class="fab fa-telegram-plane mr-1"></i>[[contact.value]]</span>
<div id="bounty-info-row" class="d-flex flex-wrap font-body bounty-info">
<div class="d-flex mt-1 text-nowrap" v-for="contact in bounty.contact_details">
<span v-if="contact.type=='Discord'" class="mr-2"><i class="fab fa-discord mr-1"></i>[[contact.value]]</span>
<span v-if="contact.type=='Email'" class="mr-2"><i class="fal fa-envelope mr-1"></i>[[contact.value]]</span>
<span v-if="contact.type=='Telegram'" class="mr-2"><i class="fab fa-telegram-plane mr-1"></i>[[contact.value]]</span>
</div>
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions app/dashboard/templates/bounty/new_bounty_step_5.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ <h4 id="title" class="font-title p-0 text-center text-lg-left">[[ form.title ]]<
<div v-if="nonEmptyContactDetails && nonEmptyContactDetails.length > 0" class="mt-3">
<span class="bounty-info-heading">{% trans "Contacts" %}</span>

<div id="bounty-info-row" class="row font-body bounty-info">
<div class="col-12 col-sm-4 col-md-2 d-flex mt-1 text-nowrap" v-for="contact in nonEmptyContactDetails">
<span v-if="contact.type=='Discord'"><i class="fab fa-discord mr-1"></i>[[contact.value]]</span>
<span v-if="contact.type=='Email'"><i class="fal fa-envelope mr-1"></i>[[contact.value]]</span>
<span v-if="contact.type=='Telegram'"><i class="fab fa-telegram-plane mr-1"></i>[[contact.value]]</span>
<div id="bounty-info-row" class="d-flex flex-wrap font-body bounty-info">
<div class="d-flex mt-1 text-nowrap" v-for="contact in nonEmptyContactDetails">
<span v-if="contact.type=='Discord'" class="mr-2"><i class="fab fa-discord mr-1"></i>[[contact.value]]</span>
<span v-if="contact.type=='Email'" class="mr-2"><i class="fal fa-envelope mr-1"></i>[[contact.value]]</span>
<span v-if="contact.type=='Telegram'" class="mr-2"><i class="fab fa-telegram-plane mr-1"></i>[[contact.value]]</span>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3087,7 +3087,7 @@ def verify_passport(request, handle):
signer = w3.eth.account.recoverHash(message_hash, signature=signature)
sig_is_valid = address.lower() == signer.lower()

logger.error("TODO: Verify Passport - %s == %s", address, did)
logger.info("Verify Passport - %s == %s", address, did)

# invalid sig error
if not sig_is_valid:
Expand Down
11 changes: 6 additions & 5 deletions app/grants/management/commands/grants_cv.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
"""


import json
import time
from decimal import *

from django.conf import settings
from django.core.management.base import BaseCommand
from django.utils import timezone

import requests
from grants.models import Grant
import json

import time
from web3 import Web3
from decimal import *


class Command(BaseCommand):

Expand Down Expand Up @@ -145,4 +146,4 @@ def calculate_voting_power(grant):
grant.metadata['cv'] = json.dumps(grantVotingPower[grantId], cls=DecimalEncoder)
grant.save()
except Exception as e:
print("Error:", e)
print("Error:", e)
10 changes: 5 additions & 5 deletions app/grants/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,13 @@ def bsci_script(csv: str) -> tuple:
labels_by_evaluation)))

# Assign final `is_sybil` markings according to a priorization criteria
df.loc[labels_by_evaluation, 'is_sybil'] = df[labels_by_evaluation].evaluation_score
df.loc[labels_by_evaluation, 'is_sybil'] = df[labels_by_evaluation].evaluation_score > EVAL_THRESHOLD
df.loc[labels_by_evaluation, 'label'] = "Human Evaluation"

df.loc[labels_by_heuristic, 'is_sybil'] = df[labels_by_heuristic].heuristic_score
df.loc[labels_by_heuristic, 'is_sybil'] = df[labels_by_heuristic].heuristic_score > HEURISTIC_THRESHOLD
df.loc[labels_by_heuristic, 'label'] = "Heuristics"

df.loc[labels_by_prediction, 'is_sybil'] = df[labels_by_prediction].prediction_score
df.loc[labels_by_prediction, 'is_sybil'] = df[labels_by_prediction].prediction_score > ML_THRESHOLD
df.loc[labels_by_prediction, 'label'] = "ML Prediction"

# Generate dict records
Expand Down