Skip to content

Instantly share code, notes, and snippets.

@rjchow
Created April 27, 2018 12:55
Show Gist options
  • Save rjchow/eaebeb9a84299aa29a03c2c3c9dad1c5 to your computer and use it in GitHub Desktop.
Save rjchow/eaebeb9a84299aa29a03c2c3c9dad1c5 to your computer and use it in GitHub Desktop.
Uport attestation push bug
/**
This file to be used in the tutorials folder of uport-js repo
Replace PUBLIC_URL with your machine's publicly accessible URL
Run using `node bug_demo.js`
Expected behaviour: The uPort mobile app should show first show a dialog for login then
a dialog displaying an attestation received
Actual behaviour: The uPort mobbile app shows an empty white dialog after the login dialog.
*/
var express = require("express");
var uport = require("../lib/index.js");
var jsontokens = require("jsontokens");
var bodyParser = require("body-parser");
var mnid = require("mnid");
var PUBLIC_URL = "https://d15d9c72.ngrok.io/callback";
var signer = uport.SimpleSigner(
"8508376b07cac93ad4871cea6b3d455b58e4ef44d00b6f2cc1338620bbb2a307"
);
var credentials = new uport.Credentials({
appName: "Bug Demo",
address: "2ous7nUuzrJ77Q7U2ngtCsLWpyFPQKtP6Ch",
signer: signer,
networks: {
"0x3": {
registry: "0x41566e3a081f5032bdcad470adb797635ddfe1f0",
rpcUrl: "https://ropsten.infura.io"
}
}
});
var app = express();
app.use(bodyParser.json({ type: "*/*" }));
app.get("/", function(req, res) {
credentials
.createRequest({
network_id: "0x3",
notifications: true,
callbackUrl: PUBLIC_URL,
})
.then(function(requestToken) {
var uri =
"me.uport:me?requestToken=" + requestToken + "%26callback_type=post";
var qrurl =
"http://chart.apis.google.com/chart?cht=qr&chs=400x400&chl=" + uri;
var mobileUrl =
"https://id.uport.me/me?requestToken=" +
requestToken +
"&callback_type=post";
console.log(uri);
res.send(
"<div><img src=" +
qrurl +
"></img></div><div><a href=" +
mobileUrl +
">Click here if on mobile</a></div>"
);
});
});
app.post("/callback", function(req, res) {
var jwt = req.body.access_token;
console.log(jwt);
var ethAddress;
var pushToken;
var user;
credentials
.receive(jwt)
.then(function(creds) {
console.log("creds", creds);
if (creds.address) {
user = creds;
console.log("uPort profile retrieved");
} else {
console.log("Verification failed.");
}
})
.then(() => {
return credentials.attest({
sub: credentials.address,
claim: {
"CREDS": "TRUE"
}
});
})
.then(att => {
console.log("attesting", att, user.pushToken)
return credentials.push(user.pushToken, user.publicEncKey, {url: `me.uport:add?attestation=${att}`, message: "wat"})
console.log(jsontokens.decodeToken(att))
})
.then(console.log)
.catch(console.log);
});
var server = app.listen(8081, function() {
console.log("Tutorial app running...");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment