Skip to content

Instantly share code, notes, and snippets.

@vongohren
Last active May 7, 2021 11:12
Show Gist options
  • Save vongohren/92753c7dc8e8be7ed219c2d184c624aa to your computer and use it in GitHub Desktop.
Save vongohren/92753c7dc8e8be7ed219c2d184c624aa to your computer and use it in GitHub Desktop.
const {
BbsBlsSignature2020,
BbsBlsSignatureProof2020,
deriveProof
} = require("@mattrglobal/jsonld-signatures-bbs");
const { extendContextLoader, sign, verify, purposes } = require("jsonld-signatures");
const { resolver } = require('@transmute/did-key.js');
const { documentLoaders } = require("jsonld");
const document = {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/citizenship/v1",
"https://w3id.org/security/bbs/v1"
],
"id": "https://issuer.oidp.uscis.gov/credentials/83627465",
"type": ["VerifiableCredential", "PermanentResidentCard"],
"issuer": "did:example:489398593",
"identifier": "83627465",
"name": "Permanent Resident Card",
"description": "Government of Example Permanent Resident Card.",
"issuanceDate": "2019-12-03T12:19:52Z",
"expirationDate": "2029-12-03T12:19:52Z",
"credentialSubject": {
"id": "did:example:b34ca6cd37bbf23",
"type": ["PermanentResident", "Person"],
"givenName": "JOHN",
"familyName": "SMITH",
"gender": "Male",
"image": "data:image/png;base64,iVBORw0KGgokJggg==",
"residentSince": "2015-01-01",
"lprCategory": "C09",
"lprNumber": "999-999-999",
"commuterClassification": "C1",
"birthCountry": "Bahamas",
"birthDate": "1958-07-17"
}
}
const { Bls12381G2KeyPair } = require('@transmute/did-key-bls12381')
const main = async () => {
const keyPair = await Bls12381G2KeyPair.generate()
document.issuer = keyPair.controller
console.log(keyPair)
const didDoc = await resolver.resolve(keyPair.controller)
console.log(didDoc)
const docLoader = (url) => {
console.log(url)
if(url === keyPair.id) {
console.log("DOING KEY PAIR NOW")
return {
contextUrl: null, // this is for a context via a link header
document: didDoc, // this is the actual document that was loaded
documentUrl: `${keyPair.controller}` // this is the actual context URL after redirects
};
}
return documentLoaders.node()(url);
}
const documentLoader = extendContextLoader(docLoader);
const signedDocument = await sign(document, {
suite: new BbsBlsSignature2020({ key: keyPair }),
purpose: new purposes.AssertionProofPurpose(),
documentLoader
});
console.log(signedDocument)
let verified = await verify(signedDocument, {
suite: new BbsBlsSignature2020(),
purpose: new purposes.AssertionProofPurpose(),
documentLoader
});
console.log(verified);
console.log(verified.results[0].error)
console.log(verified.results[0].error.details.frame)
}
main()
{
"name": "diwala-did-testing",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@decentralized-identity/ion-tools": "^0.0.8",
"@mattrglobal/bbs-signatures": "^0.5.0",
"@mattrglobal/jsonld-signatures-bbs": "^0.9.0",
"@mattrglobal/node-bbs-signatures": "^0.11.0",
"@transmute/did-key-bls12381": "^0.2.1-unstable.42",
"@transmute/did-key.js": "^0.2.1-unstable.42",
"jsonld": "^5.2.0",
"jsonld-document-loader": "^1.2.0"
},
"scripts": {
"start": "node index.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment