Commit a2636518 authored by Mark Harding's avatar Mark Harding

(wip): marks bump

parent 5ee9358d
No related merge requests found
......@@ -8,6 +8,8 @@ T3 uses DID to build trust scores across your social world.
## Trust
Contract address: `0xf4e005be076ed34aed35f66565593bd0c4dca1e9`
There are two trust actions, Trust and Distrust. These actions are written to the blockchain. Trust is given to entities. Entities can consist of either a 'owner' or 'artifact'.
## Registering
......@@ -18,9 +20,9 @@ There are two trust actions, Trust and Distrust. These actions are written to th
## Traversing the Trust Tree
1) Pick an entry point (default is self)
2) Return all entites from the entry point
3) nth degree should have been provided by application.
1. Pick an entry point (default is self)
2. Return all entites from the entry point
3. nth degree should have been provided by application.
## Applications
......
......@@ -15,8 +15,12 @@
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"customWebpackConfig": {
"path": "./webpack.config.js",
"mergeStrategies": { "externals": "replace" }
},
"outputPath": "dist/t3",
"index": "src/index.html",
"main": "src/main.ts",
......@@ -28,7 +32,7 @@
"src/styles.scss",
"node_modules/material-design-icons/iconfont/material-icons.css"
],
"scripts": ["./node_modules/crypto-browserify/index.js"]
"scripts": []
},
"configurations": {
"production": {
......@@ -58,7 +62,7 @@
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"builder": "@angular-builders/custom-webpack:dev-server",
"options": {
"browserTarget": "t3:build"
},
......
This diff is collapsed.
......@@ -3,7 +3,7 @@
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"start": "ng serve --host=0.0.0.0 --disable-host-check",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
......@@ -21,9 +21,12 @@
"@angular/router": "~8.0.0",
"crypto-browserify": "^3.12.0",
"material-design-icons": "^3.0.1",
"ethr-did": "^1.1.0",
"rxjs": "~6.4.0",
"tslib": "^1.9.0",
"uport-connect": "^1.1.11",
"uport-transports": "^0.2.6",
"web3": "^1.2.1",
"zone.js": "~0.9.1"
},
"devDependencies": {
......
import { NgModule } from "@angular/core";
import { uPortVerificationService } from "./verification.service";
import { Web3Module } from "../web3/web3.module";
@NgModule({
imports: [Web3Module],
providers: [uPortVerificationService]
})
export class uPortModule {}
import { Injectable } from "@angular/core";
import { Injectable, Inject } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { SafeUrl, DomSanitizer } from "@angular/platform-browser";
import { Subject, interval, BehaviorSubject } from "rxjs";
import { Subject, interval, BehaviorSubject, Observable } from "rxjs";
import { first } from "rxjs/operators";
import { WEB3 } from "../web3/web3.module";
import Web3 from "web3";
import EthrDID from "ethr-did";
import * as TrustContract from "../web3/contracts/trust.contract";
import * as DIDContract from "../web3/contracts/did.contract";
import { transport, message, crypto } from "uport-transports";
declare const Connect: any;
const T3_SERVER_URI = "https://t3-backend.ngrok.io";
@Injectable()
export class uPortVerificationService {
qrImageUri$: Subject<SafeUrl> = new Subject();
uPortLink$: Subject<SafeUrl> = new Subject();
data$: BehaviorSubject<any> = new BehaviorSubject(null);
polling$: Observable<number> = interval(5000);
did$: BehaviorSubject<string> = new BehaviorSubject(null);
addingDelegate$: BehaviorSubject<boolean> = new BehaviorSubject(false);
constructor(private http: HttpClient, private sanitizer: DomSanitizer) {
constructor(
private http: HttpClient,
private sanitizer: DomSanitizer,
@Inject(WEB3) private web3
) {
this.start();
}
......@@ -22,7 +40,7 @@ export class uPortVerificationService {
}
async fetch(): Promise<void> {
const data = await this.http.get("http://localhost:8088/qr").toPromise();
const data = await this.http.get(T3_SERVER_URI + "/unlock").toPromise();
this.data$.next(data);
}
......@@ -31,13 +49,91 @@ export class uPortVerificationService {
*/
fetchQrImageUri(): void {
this.data$.subscribe((data: any) => {
if (!data) return;
this.qrImageUri$.next(
this.sanitizer.bypassSecurityTrustUrl(data.qrImageData)
);
});
}
fetchUPortLink(): void {
this.data$.subscribe((data: any) => {
if (!data) return;
const transportQR = transport.qr.send();
transportQR(data.requestToken);
});
}
startPolling() {
interval(1000).subscribe(async () => {});
const s = this.polling$.subscribe(async () => {
console.log("polling");
const data = await this.data$.pipe(first()).toPromise();
if (!data || !data.sessionId) {
console.log("no data");
return;
}
this.http
.post(T3_SERVER_URI + "/poll/unlock", {
sessionId: data.sessionId
})
.subscribe((data: any) => {
if (data.status === "ok") {
this.did$.next(data.profile.did);
transport.ui.close(); // close modal
this.addDelegate();
s.unsubscribe();
}
});
});
}
async addDelegate() {
console.log("getting currently set did");
const did = await this.did$.pipe(first()).toPromise();
const address = did.split(":")[2];
console.log(did, address);
const uport = new Connect("Minds T3");
const provider = uport.getProvider();
const web3 = new Web3(provider);
const contract = new web3.eth.Contract(
DIDContract.ABI,
DIDContract.ADDRESS
);
const tx1 = contract.methods
.addDelegate(
"0x6afd852ac0a9bf29e2841453531bba322908732e",
web3.utils.fromAscii("DID-JWT"),
address,
86400 * 365 // 1 year
)
.encodeABI();
console.log(await uport.requestPersonalSign(tx1, null, { from: address }));
// // contract.methods.issueTrustViaDelegate(address, address, 1);
// // console.log(tx1);
// const signed = await web3.eth.sendTransaction(
// {
// to: DIDContract.ADDRESS,
// from: address,
// data: tx1
// },
// address
// );
// console.log(contract, tx1, signed);
const tx = {
to: TrustContract.ADDRESS,
data: {}
};
//web3.sign;
// const ethrDid = new EthrDID({
// provider: web3.currentProvider,
// address: "0xd21b90f056c9e42957da86117f0aa6b821418da4"
// });
// this.addingDelegate$.next(true);
// await ethrDid.addDelegate(TrustContract.ADDRESS);
// this.addingDelegate$.next(false);
}
}
<img [src]="verificationService.qrImageUri$ | async" />
<div class="verification__unlock" *ngIf="!(verificationService.did$ | async)">
<p>
Please wait a moment for uPort modal to appear.
</p>
</div>
<div
class="verification__delegate"
*ngIf="
(verificationService.did$ | async) &&
(verificationService.addingDelegate$ | async)
"
>
<p>
Please wait a moment whilst we figure out the delegate flow. (This can take
up to 60 seconds, because IPFS is very, very, very, very slow).
</p>
</div>
import { Component } from '@angular/core';
import { uPortVerificationService } from '../uport/verification.service';
import { Component } from "@angular/core";
import { uPortVerificationService } from "../uport/verification.service";
declare const Connect: any;
@Component({
selector: 't3-verification',
templateUrl: './verification.component.html'
selector: "t3-verification",
templateUrl: "./verification.component.html"
})
export class T3VerificationComponent {
constructor(public verificationService: uPortVerificationService) {}
ngOnInit() {
this.verificationService.fetchQrImageUri();
this.verificationService.startPolling();
this.verificationService.fetchUPortLink();
this.verificationService.did$.subscribe(did => {
// if (did) alert("verified via uport");
});
}
}
/* You can add global styles to this file, and also import other style files */
#uport__modal-content img {
max-width: 60vw;
}
pragma solidity >=0.4.21 <0.6.0;
pragma experimental ABIEncoderV2;
import '../node_modules/ethr-did-registry/contracts/EthereumDIDRegistry.sol';
......@@ -12,7 +12,8 @@ contract Trust {
int8 score;
}
mapping(address => mapping(address => TrustScore)) public scores;
mapping(address => TrustScore[]) public scores;
// mapping(address => mapping(address => TrustScore)) public scores;
constructor(address didRegistryAddress) public {
didRegistry = EthereumDIDRegistry(didRegistryAddress);
......@@ -48,13 +49,23 @@ contract Trust {
score
);
scores[from][to] = _trustScore;
// scores[from][to] = _trustScore;
scores[from].push(_trustScore);
return true;
}
function getTrust(address from, address to) public view returns (int8) {
return scores[from][to].score;
for (uint index=0; index < scores[from].length; index++) {
if (scores[from][index].to == to) {
return scores[from][index].score;
}
}
return 0;
}
function getTrusts(address from) public view returns (TrustScore[]) {
return scores[from];
}
}
\ No newline at end of file
......@@ -54,4 +54,15 @@ contract("Trust", accounts => {
});
assert.equal(await trust.getTrust(accounts[1], accounts[3]), 1);
});
it("should return a list of users we issued trust on", async () => {
await trust.issueTrust(accounts[2], 1);
await trust.issueTrust(accounts[3], 1);
await trust.issueTrust(accounts[4], -1);
await trust.issueTrust(accounts[5], -1);
await trust.issueTrust(accounts[3], -1, { from: accounts[2] });
console.log(await trust.getTrusts(accounts[0]));
});
});
This diff is collapsed.
{
"dependencies": {
"did-jwt": "^3.0.0",
"did-resolver": "^1.0.0",
"ethereumjs-tx": "^2.1.1",
"ethr-did": "^1.1.0",
"express": "^4.17.1",
"ngrok": "^3.2.5",
"path": "^0.12.7",
"uport-credentials": "^1.2.2",
"uport-transports": "^0.2.6"
"uport-transports": "^0.2.6",
"web3": "^1.2.1"
}
}
......@@ -5,8 +5,10 @@ const decodeJWT = require("did-jwt").decodeJWT;
const { Credentials } = require("uport-credentials");
const transports = require("uport-transports").transport;
const message = require("uport-transports").message.util;
const fs = require("fs");
const identity = JSON.parse(fs.readFileSync("./identity.json"));
let endpoint = "";
let endpoint = "http://07b7a55f.ngrok.io";
const app = express();
app.use(bodyParser.json({ type: "*/*" }));
......@@ -20,20 +22,22 @@ app.use((req, res, next) => {
//setup Credentials object with newly created application identity.
const credentials = new Credentials({
appName: "Login Example",
did: "did:ethr:0x31486054a6ad2c0b685cd89ce0ba018e210d504e",
privateKey: "ef6a01d0d98ba08bd23ee8b0c650076c65d629560940de9935d0f46f00679e01"
...{ appName: "Minds t3" },
...identity
});
const authenticatedRequests = new Map();
/**
* Collect a QR code and return to the client
*/
app.get("/qr", async (req, res) => {
try {
const sessionId = Date.now();
const requestToken = await credentials.createDisclosureRequest({
requested: ["name"],
notifications: true,
callbackUrl: endpoint + "/callback"
callbackUrl: endpoint + "/callback?session=" + sessionId
});
console.log(decodeJWT(requestToken)); //log request token to console
const uri = message.paramsToQueryString(
......@@ -42,23 +46,64 @@ app.get("/qr", async (req, res) => {
);
const qr = transports.ui.getImageDataURI(uri);
res.send({
uri,
qrImageData: qr
token: requestToken,
qrImageData: qr,
url: uri,
sessionId
});
} catch (err) {}
});
app.post("/callback", async (req, res) => {
const jwt = req.body.access_token;
console.log(jwt);
const sessionId = req.query.session;
console.log(sessionId);
try {
const credentials = await credentials.authenticateDisclosureResponse(jwt);
console.log("[credentials]: ", credentials);
const profile = await credentials.authenticateDisclosureResponse(jwt);
console.log("SUCCESS");
console.log("[credentials]: ", profile);
authenticatedRequests.set(sessionId, profile);
res.send({
status: "success"
});
} catch (err) {
console.log(err);
res.send({
status: "error",
message: err.toString(),
jwt
});
}
});
app.post("/poll-auth", async (req, res) => {
const sessionId = req.body.session;
console.log("polling request received for " + sessionId);
const profile = authenticatedRequests.get(sessionId.toString());
console.log(profile);
if (profile) {
res.send({
status: "ok",
profile
});
} else {
res.send({
status: "error",
message: "Not yet authenticated"
});
}
});
// run the app server and tunneling service
const server = app.listen(8088, () => {});
const server = app.listen(8088, () => {
ngrok
.connect({
proto: "http",
subdomain: "t3-backend",
addr: 8088
})
.then(ngrokUrl => {
endpoint = ngrokUrl;
console.log(`Login Service running, open at ${endpoint}`);
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment