diff --git a/index.html b/index.html index 927f62e..9f9d248 100644 --- a/index.html +++ b/index.html @@ -80,7 +80,40 @@
+{ + // set the context, which establishes the special terms we will be using. + "@context": [ + "https://www.w3.org/ns/credentials/v2", + "https://www.w3.org/ns/credentials/examples/v2" + ], + // specify the identifier for the presentation + "id": "http://example.edu/presentations/1872", + // the presentation type, which declare what data to expect in the presentation + "type": "VerifiablePresentation", + // when the presentation was issued + "validFrom": "2010-01-01T19:23:24Z", + // credentials in the presentation + "verifiableCredential": [ + { + "@context": "https://www.w3.org/ns/credentials/v2", + "id": "data:application/vc-ld+cose;base64url,UXpWalYuLi5STWpV", + "type": "EnvelopedVerifiableCredential" + }, + { + "@context": "https://www.w3.org/ns/credentials/v2", + "id": "data:application/vc-ld+jwt;eyVjV...RMjU", + "type": "EnvelopedVerifiableCredential" + }, + { + "@context": "https://www.w3.org/ns/credentials/v2", + "id": "data:application/vc-ld+sd-jwt;eyVjV...RMjU", + "type": "EnvelopedVerifiableCredential" + } + ] +} +
+ data-hash-format="openssl dgst -sha256">
+ data-hash-format="sri sha2-256">
+ data-hash-format="sri sha2-384">
+ data-hash-format="multihash sha2-256 base16">
+ data-hash-format="multihash sha2-256 base58btc">
+ data-hash-format="multihash sha2-256">
+ data-hash-format="multihash sha2-384">
+ data-hash-format="multihash sha3-256">
+ data-hash-format="multihash sha3-384">
${JSON.stringify(verifiableCredentialProof, null, 2) - .match(/.{1,75}/g).join('\n')}`; + .match(/.{1,75}/g).join('\n')}`; } catch(e) { console.error( 'respec-vc error: Failed to attach proof to Verifiable Credential.', diff --git a/src/cose.js b/src/cose.js index bb21a49..0c3a9d7 100644 --- a/src/cose.js +++ b/src/cose.js @@ -11,15 +11,11 @@ function buf2hex(buffer) { const getCredential = async ( privateKey, byteSigner, - messageType, messageJson, ) => { - let oldMessageType = (messageType === 'application/vc+cose') - ? 'application/vc+ld+json+cose' : 'application/vp+ld+json+cose'; - return issuer({ alg: privateKey.alg, - type: oldMessageType, + type: 'application/vc+ld+json+cose', signer: byteSigner, }).issue({ claimset: new TextEncoder().encode(JSON.stringify(messageJson, null, 2)), @@ -29,7 +25,6 @@ const getCredential = async ( const getPresentation = async ( privateKey, byteSigner, - messageType, message, ) => { const disclosures = (message.verifiableCredential || []).map(enveloped => { @@ -45,11 +40,9 @@ const getPresentation = async ( credential: content, }; }); - let oldMessageType = (messageType === 'application/vc+cose') - ? 'application/vc+ld+json+cose' : 'application/vp+ld+json+cose'; return holder({ alg: privateKey.alg, - type: oldMessageType, + type: 'application/vp+ld+json+cose', }).issue({ signer: byteSigner, presentation: message, @@ -73,11 +66,11 @@ const getBinaryMessage = async (privateKey, messageType, messageJson) => { }, }; switch(messageType) { - case 'application/vc+cose': { - return getCredential(privateKey, byteSigner, messageType, messageJson); + case 'application/vc-ld+cose': { + return getCredential(privateKey, byteSigner, messageJson); } - case 'application/vp+cose': { - return getPresentation(privateKey, byteSigner, messageType, messageJson); + case 'application/vp-ld+cose': { + return getPresentation(privateKey, byteSigner, messageJson); } default: { throw new Error('Unknown message type'); @@ -89,7 +82,7 @@ export const getCoseExample = async (privateKey, messageJson) => { const type = Array.isArray(messageJson.type) ? messageJson.type : [messageJson.type]; const messageType = type.includes('VerifiableCredential') ? - 'application/vc+cose' : 'application/vp+cose'; + 'application/vc-ld+cose' : 'application/vp-ld+cose'; const message = await getBinaryMessage(privateKey, messageType, messageJson); const messageHex = buf2hex(message); const messageBuffer = Buffer.from(messageHex, 'hex'); diff --git a/src/jose.js b/src/jose.js index b4401f0..c12ce1a 100644 --- a/src/jose.js +++ b/src/jose.js @@ -10,14 +10,11 @@ import * as jose from 'jose'; const getCredential = async ( privateKey, byteSigner, - messageType, messageJson ) => { - let oldMessageType = (messageType === 'application/vc+jwt') - ? 'application/vc+ld+json+jwt' : 'application/vp+ld+json+jwt'; return issuer({ alg: privateKey.alg, - type: oldMessageType, + type: 'application/vc+ld+json+jwt', signer: byteSigner, }).issue({ claimset: new TextEncoder().encode(JSON.stringify(messageJson, null, 2)), @@ -27,7 +24,6 @@ const getCredential = async ( const getPresentation = async ( privateKey, byteSigner, - messageType, message ) => { const disclosures = (message.verifiableCredential || []).map(enveloped => { @@ -44,7 +40,7 @@ const getPresentation = async ( }); return holder({ alg: privateKey.alg, - type: messageType, + type: 'application/vp+ld+json+jwt', }).issue({ signer: byteSigner, presentation: message, @@ -75,11 +71,11 @@ const getBinaryMessage = async (privateKey, messageType, messageJson) => { }, }; switch(messageType) { - case 'application/vc+jwt': { - return getCredential(privateKey, byteSigner, messageType, messageJson); + case 'application/vc-ld+jwt': { + return getCredential(privateKey, byteSigner, messageJson); } - case 'application/vp+jwt': { - return getPresentation(privateKey, byteSigner, messageType, messageJson); + case 'application/vp-ld+jwt': { + return getPresentation(privateKey, byteSigner, messageJson); } default: { throw new Error('Unknown message type'); @@ -91,7 +87,7 @@ export const getJoseExample = async (privateKey, messageJson) => { const type = Array.isArray(messageJson.type) ? messageJson.type : [messageJson.type]; const messageType = type.includes('VerifiableCredential') ? - 'application/vc+jwt' : 'application/vp+jwt'; + 'application/vc-ld+jwt' : 'application/vp-ld+jwt'; const message = await getBinaryMessage(privateKey, messageType, messageJson); const messageEncoded = new TextDecoder().decode(message); const decodedHeader = jose.decodeProtectedHeader(messageEncoded); diff --git a/src/sd-jwt.js b/src/sd-jwt.js index 82c8d40..daee9ca 100644 --- a/src/sd-jwt.js +++ b/src/sd-jwt.js @@ -74,33 +74,16 @@ export const generateIssuerClaims = example => { .replace(/type:/g, '!sd type:'); }; -const getCredential = async ( - privateKey, - byteSigner, - messageType, - messageJson, -) => { - let oldMessageType = (messageType === 'application/vc+sd-jwt') - ? 'application/vc+ld+json+sd-jwt' : 'application/vp+ld+json+sd-jwt'; - - return issuer({ - alg: privateKey.alg, - type: oldMessageType, - signer: byteSigner, - }).issue({ - claimset: new TextEncoder().encode(generateIssuerClaims(messageJson)), - }); -}; - -const getPresentation = async ( - privateKey, - byteSigner, - messageType, - messageJson, -) => { - const mediaType = 'application/vc+sd-jwt'; - return getCredential(privateKey, byteSigner, mediaType, messageJson); -}; +const getCredential = + async (privateKey, byteSigner, messageJson) => { + return issuer({ + alg: privateKey.alg, + type: 'application/vc+ld+json+sd-jwt', + signer: byteSigner, + }).issue({ + claimset: new TextEncoder().encode(generateIssuerClaims(messageJson)), + }); + }; export const getBinaryMessage = async ( privateKey, @@ -119,11 +102,11 @@ export const getBinaryMessage = async ( }, }; switch(messageType) { - case 'application/vc+sd-jwt': { - return getCredential(privateKey, byteSigner, messageType, messageJson); + case 'application/vc-ld+sd-jwt': { + return getCredential(privateKey, byteSigner, messageJson); } - case 'application/vp+sd-jwt': { - return getPresentation(privateKey, byteSigner, messageType, messageJson); + case 'application/vp-ld+sd-jwt': { + return getCredential(privateKey, byteSigner, messageJson); } default: { throw new Error('Unknown message type'); @@ -140,7 +123,7 @@ export const getSdJwtExample = async ( const type = Array.isArray(messageJson.type) ? messageJson.type : [messageJson.type]; const messageType = type.includes('VerifiableCredential') ? - 'application/vc+sd-jwt' : 'application/vp+sd-jwt'; + 'application/vc-ld+sd-jwt' : 'application/vp-ld+sd-jwt'; const binaryMessage = await getBinaryMessage(privateKey, messageType, messageJson); const message = new TextDecoder().decode(binaryMessage);