Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Support W3C Verifiable Claims Format #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions client/components/proof.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = class Proof extends Component {
return
}
IpfsID.proof.createProof(username, service, (err, proof) => {
proof.proof = JSON.parse(proof.proof)
// proof.proof = JSON.parse(proof.proof)
this.emit('updateProofText', JSON.stringify(proof, null, 2))
})
}
Expand Down Expand Up @@ -110,13 +110,14 @@ module.exports = class Proof extends Component {
class="_proof_tab_ w-90 center pv4 bg-near-white">
<table class="w-100 collapse pl4 mt0 ba b--black-10">
${proofsList.rows.map((item) => {
console.log(item)
return html`
<tr class="pv2 striped--light-gray">
<td><img src="img/eye.svg"
onclick=${this.viewProof.bind(this)}
data-hash="${item.doc.ipfsContentHash}"
class="h1 ph2" /></td>
<td class="f6">${item.doc.proof.message.username}@${item.doc.proof.message.service}</td><td class="ipfs-url fw1 f7 code"><a href="${item.doc.url}" target="_new">${item.doc.url}</a></td><td class="ipfs-url fw1 f7 code"><a target="_new" href="https://ipfs.io/ipfs/${item.doc.ipfsContentHash}" title="${item.doc.ipfsContentHash}">/ipfs/${item.doc.ipfsContentHash}</a></td>
<td class="f6">${item.doc.claim.username}@${item.doc.claim.service}</td><td class="ipfs-url fw1 f7 code"><a href="${item.doc.url}" target="_new">${item.doc.url}</a></td><td class="ipfs-url fw1 f7 code"><a target="_new" href="https://ipfs.io/ipfs/${item.doc.ipfsContentHash}" title="${item.doc.ipfsContentHash}">/ipfs/${item.doc.ipfsContentHash}</a></td>
</tr>`
})}
</table>
Expand Down
34 changes: 0 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ipfs-social-proof",
"version": "0.0.2",
"version": "0.0.3",
"description": "IPFS-based Identity & Social Proof",
"leadMaintainer": "David Dahl <[email protected]>",
"main": "src/index.js",
Expand Down Expand Up @@ -68,6 +68,7 @@
"pouchdb-upsert": "^2.2.0",
"text-encoding": "^0.6.4",
"url-parse": "^1.4.3",
"uuid": "^3.3.2",
"valid-url": "^1.0.9"
},
"contributors": [
Expand Down
9 changes: 9 additions & 0 deletions src/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ class Crypto {
})
}

pemEncodeSignature (signatureBytes) {
return forge.util.binary.base64.encode(signatureBytes)
}

pemDecodeSignature (pemSignature) {
return forge.util.binary.base64.decode(pemSignature)
}


get pubKeyDehydrated () {
// get a base64 encoded marshaled pub key
const pub = this.node._peerInfo.id._privKey.public
Expand Down
50 changes: 34 additions & 16 deletions src/proof.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const uuid = require('uuid/v1')

const RemoteProofs = require('./remote-proofs')
const {t2a, a2t } = require('./crypto')
const { log, error } = require('./log')
Expand Down Expand Up @@ -65,39 +67,55 @@ class Proof {
createProof (username, service, callback, expires=null) {
// Sign message, returning an Object with
// service, username, message, handle and signature
const SIGNATURE_TYPE = 'RsaSignature2018'
const ISSUER = 'https://github.com/IBM/ipfs-social-proof'
const that = this

if (!username || !service) {
throw new Error(ERR.ARG_REQ_USERNAME_SERVICE)
}
const ts = Date.now()

let message = {
let claim = JSON.stringify({
statement: `I am ${username} on ${service}`, // add URL here
username: username,
service: service
}

let proof = JSON.stringify({
message: message,
timestamp: ts,
expires: expires,
ipfsId: this.identity.peerId,
handle: this.identity.handle
// TODO: needs an ID like: "id": "did:example:ebfeb1f712ebc6f1c276e12ec21",
// Aparently tied to the url like: "https://example.com/examples/v1"
// Question: can this just be stored in IPFS and references via /ipfs/multihash?
})

this.crypto.sign(proof, (err, signature) => {
this.crypto.sign(claim, (err, signature) => {
if (err) { throw new Error(err) }

let assertion = {
let proof = {
issuanceDate: new Date().toISOString(),
creator: that.identity.peerId,
handle: that.identity.handle,
ipfsId: that.identity.peerId,
// signature: that.crypto.dehydrate(signature),
signatureValue: that.crypto.pemEncodeSignature(signature),
type: SIGNATURE_TYPE,
nonce: uuid(),
}

if (expires) {
proof.expirationDate = expires
}

let verifiableCredential = {
'@context': [
"https://w3.org/2018/credentials/v1"
],
id: uuid(), // TODO: Should be an url, perhaps an IPFS hash?
proof: proof,
signature: that.crypto.dehydrate(signature),
timestamp: ts,
publicKey: that.crypto.pubKeyDehydrated
type: ['VerifiableCredential'],
issuer: ISSUER,
issuanceDate: new Date().toISOString(),
publicKey: that.crypto.pubKeyPem,
claim: JSON.parse(claim),
}
if (callback) {
callback(err, assertion)
callback(err, verifiableCredential)
}
})
}
Expand Down