diff --git a/package.json b/package.json index 1ea56126b..fc00d605b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@docknetwork/sdk", - "version": "7.3.1", + "version": "7.3.2", "main": "index.js", "license": "MIT", "repository": { diff --git a/src/modules/accumulator.js b/src/modules/accumulator.js index f636b4db6..d3335ed94 100644 --- a/src/modules/accumulator.js +++ b/src/modules/accumulator.js @@ -374,10 +374,11 @@ export default class AccumulatorModule extends WithParamsAndPublicKeys { * Field `nonce` is the last accepted nonce by the chain, the next write to the accumulator should increment the nonce by 1. * Field `accumulated` contains the current accumulated value. * @param id - * @param withKeyAndParams + * @param withKeyAndParams - Fetch both keys and params. + * @param withKeyOnly - Fetch key only. This is useful when default params are used. * @returns {Promise<{created: *, lastModified: *}|null>} */ - async getAccumulator(id, withKeyAndParams = false) { + async getAccumulator(id, withKeyAndParams = false, withKeyOnly = false) { const resp = await this.api.query[this.moduleName].accumulators( id, ); @@ -400,8 +401,8 @@ export default class AccumulatorModule extends WithParamsAndPublicKeys { const keyId = common.keyRef[1].toNumber(); accumulatorObj.keyRef = [typedHexDIDFromSubstrate(this.api, owner), keyId]; - if (withKeyAndParams) { - const pk = await this.getPublicKeyByHexDid(owner, keyId, true); + if (withKeyAndParams || withKeyOnly) { + const pk = await this.getPublicKeyByHexDid(owner, keyId, withKeyAndParams); if (pk !== null) { accumulatorObj.publicKey = pk; } diff --git a/src/presentation.js b/src/presentation.js index 4a0a5c211..5ba4b9f8c 100644 --- a/src/presentation.js +++ b/src/presentation.js @@ -11,6 +11,7 @@ import { stringToU8a } from '@polkadot/util'; import { ensureArray } from './utils/type-helpers'; import Bls12381BBSSignatureDock2022 from './utils/vc/crypto/Bls12381BBSSignatureDock2022'; +import { DOCK_ANON_CREDENTIAL_ID } from './utils/vc/crypto/common/DockCryptoSignatureProof'; import { Bls12381BBSSigDockSigName, Bls12381PSSigDockSigName, @@ -165,8 +166,10 @@ export default class Presentation { ); } - return { + const w3cFormattedCredential = { ...credential.revealedAttributes, + // ID required for W£C formatted credentials, if not revealed used a static URI + id: credential.revealedAttributes.id || DOCK_ANON_CREDENTIAL_ID, '@context': JSON.parse(credential.revealedAttributes['@context']), type: JSON.parse(credential.revealedAttributes.type), credentialSchema: JSON.parse(credential.schema), @@ -192,6 +195,12 @@ export default class Presentation { bounds: credential.bounds, }, }; + + if (credential.status) { + w3cFormattedCredential.credentialStatus = credential.status; + } + + return w3cFormattedCredential; }); } } diff --git a/src/utils/revocation.js b/src/utils/revocation.js index a123c05b1..82160df18 100644 --- a/src/utils/revocation.js +++ b/src/utils/revocation.js @@ -17,6 +17,8 @@ export const RevRegIdByteSize = 32; // Each entry in revocation registry has byte size `RevEntryByteSize` export const RevEntryByteSize = 32; +const LD_SEC_TERM = 'https://ld.dock.io/security#'; + /** * Return `credentialStatus` according to W3C spec when the revocation status is checked on Dock * @param registryId - Revocation registry id @@ -76,14 +78,14 @@ export function getCredentialStatus(expanded) { * @param status * @returns {boolean} */ -export const isRegistryRevocationStatus = ({ [credentialTypeField]: type }) => type.includes(RevRegType) || type.includes(`/${RevRegType}`); +export const isRegistryRevocationStatus = ({ [credentialTypeField]: type }) => type.includes(RevRegType) || type.includes(`${LD_SEC_TERM}${RevRegType}`) || type.includes(`/${RevRegType}`); /** * Returns `true` if supplied status is a accumulator revocation status. * @param status * @returns {boolean} */ -export const isAccumulatorRevocationStatus = ({ [credentialTypeField]: type }) => type.includes(VB_ACCUMULATOR_22) || type.includes(`/${VB_ACCUMULATOR_22}`); +export const isAccumulatorRevocationStatus = ({ [credentialTypeField]: type }) => type.includes(VB_ACCUMULATOR_22) || type.includes(`${LD_SEC_TERM}${VB_ACCUMULATOR_22}`) || type.includes(`/${VB_ACCUMULATOR_22}`); /** * Checks if a credential status has a registry revocation. diff --git a/src/utils/vc/contexts/dock-bbs-v1.json b/src/utils/vc/contexts/dock-bbs-v1.json index 8e0a328e6..dab639bad 100644 --- a/src/utils/vc/contexts/dock-bbs-v1.json +++ b/src/utils/vc/contexts/dock-bbs-v1.json @@ -34,6 +34,22 @@ "@type": "@id", "@container": "@graph" }, + "DockVBAccumulator2022": { + "@id": "https://ld.dock.io/security#DockVBAccumulator2022", + "@context": { + "@version": 1.1, + "@protected": true, + "id": "@id", + "type": "@type", + "accumulated": "https://ld.dock.io/security#accumulated", + "revocationCheck": "https://ld.dock.io/security#revocationCheck", + "revocationId": "https://ld.dock.io/security#revocationId", + "extra": { + "@id": "https://ld.dock.io/security#extra", + "@context": {"@vocab": "https://ld.dock.io/security/extra"} + } + } + }, "Bls12381BBS+SignatureProofDock2022": { "@id": "https://ld.dock.io/security#Bls12381BBS+SignatureDock2022", "@context": { diff --git a/src/utils/vc/contexts/dock-bbs23-v1.json b/src/utils/vc/contexts/dock-bbs23-v1.json index e412645b9..89fa4889d 100644 --- a/src/utils/vc/contexts/dock-bbs23-v1.json +++ b/src/utils/vc/contexts/dock-bbs23-v1.json @@ -34,6 +34,22 @@ "@type": "@id", "@container": "@graph" }, + "DockVBAccumulator2022": { + "@id": "https://ld.dock.io/security#DockVBAccumulator2022", + "@context": { + "@version": 1.1, + "@protected": true, + "id": "@id", + "type": "@type", + "accumulated": "https://ld.dock.io/security#accumulated", + "revocationCheck": "https://ld.dock.io/security#revocationCheck", + "revocationId": "https://ld.dock.io/security#revocationId", + "extra": { + "@id": "https://ld.dock.io/security#extra", + "@context": {"@vocab": "https://ld.dock.io/security/extra"} + } + } + }, "Bls12381BBSSignatureProofDock2023": { "@id": "https://ld.dock.io/security#Bls12381BBSSignatureDock2023", "@context": { @@ -57,6 +73,7 @@ "unboundedPseudonyms": "https://ld.dock.io/security#unboundedPseudonyms", "attributeCiphertexts": "https://ld.dock.io/security#attributeCiphertexts", "attributeEqualities": "https://ld.dock.io/security#attributeEqualities", + "accumulated": "https://ld.dock.io/security#accumulated", "proofValue": "https://ld.dock.io/security#proofValue", "nonce": "https://ld.dock.io/security#nonce", "proofPurpose": { diff --git a/src/utils/vc/contexts/dock-ps-v1.json b/src/utils/vc/contexts/dock-ps-v1.json index 9213787ff..ade5639a5 100644 --- a/src/utils/vc/contexts/dock-ps-v1.json +++ b/src/utils/vc/contexts/dock-ps-v1.json @@ -34,6 +34,22 @@ "@type": "@id", "@container": "@graph" }, + "DockVBAccumulator2022": { + "@id": "https://ld.dock.io/security#DockVBAccumulator2022", + "@context": { + "@version": 1.1, + "@protected": true, + "id": "@id", + "type": "@type", + "accumulated": "https://ld.dock.io/security#accumulated", + "revocationCheck": "https://ld.dock.io/security#revocationCheck", + "revocationId": "https://ld.dock.io/security#revocationId", + "extra": { + "@id": "https://ld.dock.io/security#extra", + "@context": {"@vocab": "https://ld.dock.io/security/extra"} + } + } + }, "Bls12381PSSignatureProofDock2023": { "@id": "https://ld.dock.io/security#Bls12381PSSignatureDock2023", "@context": { @@ -57,6 +73,7 @@ "unboundedPseudonyms": "https://ld.dock.io/security#unboundedPseudonyms", "attributeCiphertexts": "https://ld.dock.io/security#attributeCiphertexts", "attributeEqualities": "https://ld.dock.io/security#attributeEqualities", + "accumulated": "https://ld.dock.io/security#accumulated", "proofValue": "https://ld.dock.io/security#proofValue", "nonce": "https://ld.dock.io/security#nonce", "proofPurpose": { diff --git a/src/utils/vc/crypto/common/DockCryptoSignatureProof.js b/src/utils/vc/crypto/common/DockCryptoSignatureProof.js index b33fe116d..47e7ff677 100644 --- a/src/utils/vc/crypto/common/DockCryptoSignatureProof.js +++ b/src/utils/vc/crypto/common/DockCryptoSignatureProof.js @@ -6,6 +6,8 @@ import CustomLinkedDataSignature from './CustomLinkedDataSignature'; const SUITE_CONTEXT_URL = 'https://www.w3.org/2018/credentials/v1'; +export const DOCK_ANON_CREDENTIAL_ID = 'dock:anonymous:credential'; + /** * Defines commons for the `@docknetwork/crypto-wasm-ts` signature proofs. */ @@ -63,7 +65,7 @@ export default withExtendedStaticProperties( expansionMap, }); - const presentationJSON = this.constructor.convertToPresentation({ + const presentationJSON = this.constructor.derivedToAnoncredsPresentation({ ...document, proof, }); @@ -79,8 +81,9 @@ export default withExtendedStaticProperties( circomOutputs, blindedAttributesCircomOutputs, } = this; - if (!recreatedPres.verify(pks, accumulatorPublicKeys, predicateParams, circomOutputs, blindedAttributesCircomOutputs)) { - throw new Error('Invalid signature'); + const res = recreatedPres.verify(pks, accumulatorPublicKeys, predicateParams, circomOutputs, blindedAttributesCircomOutputs); + if (!res.verified) { + throw new Error(`Invalid anoncreds presentation due to error: ${res.error}`); } return { verified: true, verificationMethod }; @@ -93,38 +96,49 @@ export default withExtendedStaticProperties( * Converts a derived proof credential to the native presentation format * @param document */ - static convertToPresentation(document) { + static derivedToAnoncredsPresentation(document) { const { '@context': context, type, credentialSchema, + credentialStatus, issuer: _issuer, issuanceDate: _issuanceDate, proof, ...revealedAttributes } = document; + // ID wasnt revealed but placeholder was used to conform to W3C spec, trim it + if (revealedAttributes.id === DOCK_ANON_CREDENTIAL_ID) { + delete revealedAttributes.id; + } + + // TODO: This is wrong. This won't work with presentation from 2 or more credentials + const c = { + sigType: proof.sigType, + version: proof.version, + bounds: proof.bounds, + schema: JSON.stringify(credentialSchema), + revealedAttributes: { + proof: { + type: this.sigName, + verificationMethod: proof.verificationMethod, + }, + '@context': JSON.stringify(context), + type: JSON.stringify(type), + ...revealedAttributes, + }, + }; + if (credentialStatus !== undefined) { + c.status = credentialStatus; + } return { version: proof.version, nonce: proof.nonce, context: proof.context, spec: { credentials: [ - { - sigType: proof.sigType, - version: proof.version, - bounds: proof.bounds, - schema: JSON.stringify(credentialSchema), - revealedAttributes: { - proof: { - type: this.sigName, - verificationMethod: proof.verificationMethod, - }, - '@context': JSON.stringify(context), - type: JSON.stringify(type), - ...revealedAttributes, - }, - }, + c, ], attributeEqualities: proof.attributeEqualities, boundedPseudonyms: proof.boundedPseudonyms, diff --git a/src/utils/vc/presentations.js b/src/utils/vc/presentations.js index 146a0e97d..4281f6a31 100644 --- a/src/utils/vc/presentations.js +++ b/src/utils/vc/presentations.js @@ -240,7 +240,7 @@ export async function signPresentation( }); const documentLoader = defaultDocumentLoader(resolver); - return jsigs.sign(presentation, { + const signed = await jsigs.sign(presentation, { purpose, documentLoader, domain, @@ -249,6 +249,16 @@ export async function signPresentation( suite, addSuiteContext, }); + + // Sometimes jsigs returns proof like [null, { proof }] + // check for that case here and if there's only 1 proof store object instead + if (Array.isArray(signed.proof)) { + const validProofs = signed.proof.filter((p) => !!p); + if (validProofs.length === 1) { + signed.proof = validProofs.pop(); + } + } + return signed; } export function isAnoncreds(presentation) { diff --git a/src/verifiable-presentation.js b/src/verifiable-presentation.js index 6cdf63488..b92b12c14 100644 --- a/src/verifiable-presentation.js +++ b/src/verifiable-presentation.js @@ -155,6 +155,15 @@ class VerifiablePresentation { return this; } + /** + * Add multiple Verifiable Credentials to this Presentation. Duplicates will be ignored. + * @param {Array} credentials - Verifiable Credential for the presentation + * @returns {VerifiablePresentation} + */ + addCredentials(credentials) { + credentials.forEach(this.addCredential.bind(this)); + } + /** * Define the JSON representation of a Verifiable Presentation. * @returns {object} @@ -186,8 +195,8 @@ class VerifiablePresentation { resolver, compactProof, ); - this.proof = signedVP.proof.pop(); this.context = signedVP['@context']; + this.proof = signedVP.proof; return this; } diff --git a/tests/create-presentation.js b/tests/create-presentation.js index e2e82b187..9de25bc33 100644 --- a/tests/create-presentation.js +++ b/tests/create-presentation.js @@ -1,6 +1,4 @@ -import { - DEFAULT_CONTEXT_V1_URL, -} from '../src/utils/vc/constants'; +import VerifiablePresentation from '../src/verifiable-presentation'; /** * Create an unsigned Verifiable Presentation @@ -9,22 +7,15 @@ import { * @param {string} [holder] - optional presentation holder url * @return {object} verifiable presentation. */ -export function createPresentation(verifiableCredential, id, holder = null) { - const presentation = { - '@context': [DEFAULT_CONTEXT_V1_URL], - type: ['VerifiablePresentation'], - }; - - if (verifiableCredential) { - const credentials = [].concat(verifiableCredential); - presentation.verifiableCredential = credentials; - } - if (id) { - presentation.id = id; +export function createPresentation(verifiableCredential, id = 'http://example.edu/presentation/2803', holder = null) { + const presentation = new VerifiablePresentation(id); + if (Array.isArray(verifiableCredential)) { + presentation.addCredentials(verifiableCredential); + } else { + presentation.addCredential(verifiableCredential); } if (holder) { - presentation.holder = holder; + presentation.setHolder(holder); } - - return presentation; + return presentation.toJSON(); } diff --git a/tests/integration/anoncreds/derived-credentials.test.js b/tests/integration/anoncreds/derived-credentials.test.js index e52d44add..dfe566a72 100644 --- a/tests/integration/anoncreds/derived-credentials.test.js +++ b/tests/integration/anoncreds/derived-credentials.test.js @@ -1,6 +1,15 @@ import { randomAsHex } from '@polkadot/util-crypto'; -import { stringToU8a, u8aToHex } from '@polkadot/util'; -import { initializeWasm, BoundCheckSnarkSetup } from '@docknetwork/crypto-wasm-ts'; +import b58 from 'bs58'; +import { hexToU8a, stringToU8a, u8aToHex } from '@polkadot/util'; +import { + initializeWasm, + BoundCheckSnarkSetup, + Accumulator, + PositiveAccumulator, + dockAccumulatorParams, AccumulatorPublicKey, deepClone, + Encoder, +} from '@docknetwork/crypto-wasm-ts'; +import { InMemoryState } from '@docknetwork/crypto-wasm-ts/lib/accumulator/in-memory-persistence'; import { DockAPI } from '../../../src'; import { FullNodeEndpoint, @@ -19,6 +28,7 @@ import { } from '../../../src/utils/vc'; import { DockResolver } from '../../../src/resolver'; import { createPresentation } from '../../create-presentation'; +import AccumulatorModule from '../../../src/modules/accumulator'; // TODO: move to fixtures const residentCardSchema = { @@ -73,7 +83,7 @@ describe.each(Schemes)('Derived Credentials', ({ VerKey, getModule, Context, - convertToPresentation, + derivedToAnoncredsPresentation, }) => { const dock = new DockAPI(); const resolver = new DockResolver(dock); @@ -83,6 +93,7 @@ describe.each(Schemes)('Derived Credentials', ({ let chainModule; let keypair; let didDocument; + let accumKeypair; const holder3DID = createNewDockDID(); // seed used for 3rd holder keys @@ -112,6 +123,10 @@ describe.each(Schemes)('Derived Credentials', ({ }, }; + const accumulatorId = randomAsHex(32); + const accumState = new InMemoryState(); + let accumMember; + beforeAll(async () => { await initializeWasm(); await dock.init({ @@ -152,6 +167,33 @@ describe.each(Schemes)('Derived Credentials', ({ holder3DID, new DidKeypair(dock.keyring.addFromUri(holder3KeySeed, null, 'sr25519'), 1), ); + + const params = dockAccumulatorParams(); + accumKeypair = Accumulator.generateKeypair(params); + const bytes1 = u8aToHex(accumKeypair.publicKey.bytes); + const accumPk = AccumulatorModule.prepareAddPublicKey(dock.api, bytes1); + await dock.accumulatorModule.addPublicKey( + accumPk, + did1, + pair1, + { didModule: dock.did }, + false, + ); + + const accumulator = PositiveAccumulator.initialize(params, accumKeypair.secretKey); + const members = []; + for (let i = 1; i < 100; i++) { + // Using default encoder since thats what the is used in credential by default. Ideally, the encoder specified in + // the particular schema should be used but for that is the default one + members.push(Encoder.defaultEncodeFunc()(i.toString())); + } + accumMember = '10'; + await accumulator.addBatch(members, accumKeypair.secretKey, accumState); + + const accumulated = u8aToHex(accumulator.accumulated); + await dock.accumulatorModule.addPositiveAccumulator(accumulatorId, accumulated, [did1, 1], did1, pair1, { didModule: dock.didModule }, false); + const queriedAccum = await dock.accumulatorModule.getAccumulator(accumulatorId, false); + expect(queriedAccum.accumulated).toEqual(u8aToHex(accumulator.accumulated)); }, 30000); async function createAndVerifyPresentation(credentials, verifyOptions = {}) { @@ -161,21 +203,22 @@ describe.each(Schemes)('Derived Credentials', ({ 'Sr25519VerificationKey2020', ); - const presId = randomAsHex(32); + const presId = `https://example.com/pres/${randomAsHex(32)}`; const chal = randomAsHex(32); const domain = 'test domain'; const presentation = createPresentation(credentials, presId); expect(presentation).toMatchObject( - expect.objectContaining({ + // NOTE: json parse+stringify to remove any undefined properties + expect.objectContaining(JSON.parse(JSON.stringify({ type: ['VerifiablePresentation'], verifiableCredential: credentials, id: presId, - }), + }))), ); - // Question: What is the point of this? Verifying this would require knowing the holder's public key which makes - // the holder linkable and defeats the purpose of BBS+ + // NOTE: typically for BBS+ presentations you shouldnt sign it by the holder, but we do it here just to make sure it works + // Verifying this would require knowing the holder's public key which makes the holder linkable and defeats the purpose of BBS+ const signedPres = await signPresentation( presentation, holderKey, @@ -290,7 +333,7 @@ describe.each(Schemes)('Derived Credentials', ({ // Question: What is the point of this? A single credential cant be converted to a presentation and a presentation // has other data that credential won't have - const reconstructedPres = convertToPresentation(credentials[0]); + const reconstructedPres = derivedToAnoncredsPresentation(credentials[0]); expect(reconstructedPres.proof).toBeDefined(); expect({ ...reconstructedPres, @@ -304,10 +347,92 @@ describe.each(Schemes)('Derived Credentials', ({ expect(credentialResult.verified).toBe(true); expect(credentialResult.error).toBe(undefined); + // Modify the credential after issuance, verification should fail + const modifiedCred = deepClone(credentials[0]); + modifiedCred.credentialSubject.lprNumber = 0xdeadbeef; + const credentialResult1 = await verifyCredential(modifiedCred, { + resolver, + }); + expect(credentialResult1.verified).toBe(false); + // Create a VP and verify it from this credential await createAndVerifyPresentation(credentials); }, 30000); + test(`For ${Name}, persist credential status when deriving`, async () => { + const encodedMember = Encoder.defaultEncodeFunc()(accumMember); + const queriedAccum = await dock.accumulatorModule.getAccumulator(accumulatorId, false, true); + const verifAccumulator = PositiveAccumulator.fromAccumulated(hexToU8a(queriedAccum.accumulated)); + + // Witness created for member 1 + const witness = await verifAccumulator.membershipWitness(encodedMember, accumKeypair.secretKey, accumState); + const accumPk = new AccumulatorPublicKey(hexToU8a(queriedAccum.publicKey.bytes)); + expect(verifAccumulator.verifyMembershipWitness(encodedMember, witness, accumPk, dockAccumulatorParams())).toEqual(true); + + const credentialStatus = { + id: `dock:accumulator:${accumulatorId}`, + type: 'DockVBAccumulator2022', + revocationCheck: 'membership', + revocationId: accumMember, + }; + + const issuerKey = getKeyDoc(did1, keypair, keypair.type, keypair.id); + const unsignedCred = { + ...credentialJSON, + credentialStatus, + issuer: did1, + }; + + const presentationOptions = { + nonce: stringToU8a('noncetest'), + context: 'my context', + }; + + // Create W3C credential + const credential = await issueCredential(issuerKey, unsignedCred); + expect(credential.id).toBeDefined(); + + // Begin to derive a credential from the above issued one + const presentationInstance = new Presentation(); + const idx = await presentationInstance.addCredentialToPresent( + credential, + { resolver }, + ); + presentationInstance.presBuilder.addAccumInfoForCredStatus(0, witness, hexToU8a(queriedAccum.accumulated), accumPk); + + // NOTE: revealing subject type because of JSON-LD processing for this certain credential + // you may not always need to do this depending on your JSON-LD contexts + await presentationInstance.addAttributeToReveal(idx, [ + 'credentialSubject.type.0', + ]); + await presentationInstance.addAttributeToReveal(idx, [ + 'credentialSubject.type.1', + ]); + + // Derive a W3C Verifiable Credential JSON from the above presentation + const credentials = await presentationInstance.deriveCredentials( + presentationOptions, + ); + + expect(credentials.length).toEqual(1); + expect(credentials[0].credentialStatus).toBeDefined(); + expect(credentials[0].credentialStatus).toEqual({ + ...credentialStatus, + revocationId: undefined, // Because revocation id is never revealed + accumulated: b58.encode(hexToU8a(queriedAccum.accumulated)), + extra: {}, + }); + + const accumulatorPublicKeys = new Map(); + accumulatorPublicKeys.set(0, accumPk); + + // Create a VP and verify it from this credential + await createAndVerifyPresentation(credentials, { + resolver, + accumulatorPublicKeys, + }); + }); + test('Holder creates a derived verifiable credential from a credential with range proofs', async () => { const provingKeyId = 'provingKeyId'; const pk = BoundCheckSnarkSetup(); @@ -395,7 +520,7 @@ describe.each(Schemes)('Derived Credentials', ({ }), ); - const reconstructedPres = convertToPresentation(credentials[0]); + const reconstructedPres = derivedToAnoncredsPresentation(credentials[0]); expect(reconstructedPres.proof).toBeDefined(); expect(reconstructedPres.spec.credentials[0].bounds).toEqual(credentials[0].proof.bounds); diff --git a/tests/integration/credential-revocation.test.js b/tests/integration/credential-revocation.test.js index b5cfa1dcd..3b65b0b11 100644 --- a/tests/integration/credential-revocation.test.js +++ b/tests/integration/credential-revocation.test.js @@ -119,7 +119,7 @@ describe('Credential revocation with issuer as the revocation authority', () => const holderKey = getKeyDoc(holderDID, dockAPI.keyring.addFromUri(holderSeed, null, 'ed25519'), 'Ed25519VerificationKey2018'); // Create presentation for unrevoked credential - const presId = randomAsHex(32); + const presId = `https://pres.com/${randomAsHex(32)}`; const chal = randomAsHex(32); const domain = 'test domain'; const presentation = createPresentation( diff --git a/tests/integration/issuing-and-presentation-with-2-subjects.test.js b/tests/integration/issuing-and-presentation-with-2-subjects.test.js index 6556c481c..8d3bb4f53 100644 --- a/tests/integration/issuing-and-presentation-with-2-subjects.test.js +++ b/tests/integration/issuing-and-presentation-with-2-subjects.test.js @@ -125,7 +125,7 @@ describe('Verifiable Credential issuance and presentation where the credential h test('Holder creates a verifiable presentation and verifier verifies it and does some other checks', async () => { const holderKey = getKeyDoc(subject1DID, dock.keyring.addFromUri(subject1Seed, null, 'ed25519'), 'Ed25519VerificationKey2018'); - const presId = randomAsHex(32); + const presId = `https://pres.com/${randomAsHex(32)}`; const challenge = randomAsHex(32); const domain = 'test domain'; diff --git a/tests/integration/presenting.test.js b/tests/integration/presenting.test.js index d9f51d64e..bda206a9f 100644 --- a/tests/integration/presenting.test.js +++ b/tests/integration/presenting.test.js @@ -116,7 +116,7 @@ describe('Verifiable Presentation where both issuer and holder have a Dock DID', }); expect(res).toBe(true); - const presId = randomAsHex(32); + const presId = `https://pres.com/${randomAsHex(32)}`; const chal = randomAsHex(32); const domain = 'test domain'; const presentation = createPresentation( @@ -186,7 +186,7 @@ describe('Verifiable Presentation where both issuer and holder have a Dock DID', }); expect(res1).toBe(true); - const presId = randomAsHex(32); + const presId = `https://pres.com/${randomAsHex(32)}`; const chal = randomAsHex(32); const domain = 'test domain'; diff --git a/tests/integration/private-status-list-credential.test.js b/tests/integration/private-status-list-credential.test.js index 793a40dc2..62fd371bc 100644 --- a/tests/integration/private-status-list-credential.test.js +++ b/tests/integration/private-status-list-credential.test.js @@ -164,7 +164,7 @@ describe('PrivateStatusList2021Credential', () => { ); // Create presentation for unsuspended credential - const presId = randomAsHex(32); + const presId = `https://pres.com/${randomAsHex(32)}`; const chal = randomAsHex(32); const domain = 'test domain'; const presentation = createPresentation(credential, presId); diff --git a/tests/integration/status-list-credential.test.js b/tests/integration/status-list-credential.test.js index f84b1be02..8c6ae458d 100644 --- a/tests/integration/status-list-credential.test.js +++ b/tests/integration/status-list-credential.test.js @@ -183,7 +183,7 @@ buildTest('StatusList2021Credential', () => { ); // Create presentation for unsuspended credential - const presId = randomAsHex(32); + const presId = `https://pres.com/${randomAsHex(32)}`; const chal = randomAsHex(32); const domain = 'test domain'; const presentation = createPresentation(credential, presId); diff --git a/tests/test-constants.js b/tests/test-constants.js index dc4d501ef..38355b5d6 100644 --- a/tests/test-constants.js +++ b/tests/test-constants.js @@ -94,8 +94,8 @@ export const BBS = { Signature: BBSSignature, KeyPair: BBSKeypair, CryptoKeyPair: Bls12381BBSKeyPairDock2023, - convertToPresentation: - Bls12381BBSSignatureProofDock2023.convertToPresentation.bind( + derivedToAnoncredsPresentation: + Bls12381BBSSignatureProofDock2023.derivedToAnoncredsPresentation.bind( Bls12381BBSSignatureProofDock2023, ), SigType: 'Bls12381BBSSignatureDock2023', @@ -117,8 +117,8 @@ export const BBSPlus = { Signature: BBSPlusSignatureG1, KeyPair: BBSPlusKeypairG2, CryptoKeyPair: Bls12381G2KeyPairDock2022, - convertToPresentation: - Bls12381BBSSignatureProofDock2022.convertToPresentation.bind( + derivedToAnoncredsPresentation: + Bls12381BBSSignatureProofDock2022.derivedToAnoncredsPresentation.bind( Bls12381BBSSignatureProofDock2022, ), Context: 'https://ld.dock.io/security/bbs/v1', @@ -140,8 +140,8 @@ export const PS = { Signature: PSSignature, KeyPair: PSKeypair, CryptoKeyPair: Bls12381PSKeyPairDock2023, - convertToPresentation: - Bls12381PSSignatureProofDock2023.convertToPresentation.bind( + derivedToAnoncredsPresentation: + Bls12381PSSignatureProofDock2023.derivedToAnoncredsPresentation.bind( Bls12381PSSignatureProofDock2023, ), SigType: 'Bls12381PSSignatureDock2023', diff --git a/tests/unit/issuing.test.js b/tests/unit/issuing.test.js index 010262921..1d4e93a62 100644 --- a/tests/unit/issuing.test.js +++ b/tests/unit/issuing.test.js @@ -7,7 +7,6 @@ import { verifyPresentation, signPresentation, } from '../../src/utils/vc/index'; -import { createPresentation } from '../create-presentation'; import VerifiableCredential from '../../src/verifiable-credential'; import VerifiablePresentation from '../../src/verifiable-presentation'; import testingKeys from '../test-keys'; @@ -142,15 +141,6 @@ testingKeys.forEach((testKey) => { presentationCredentials = [sampleIssuedCredential, sampleIssuedCredential]; }); - test('A proper verifiable presentation should be created from two valid sample credentials.', async () => { - const presentation = createPresentation( - presentationCredentials, - vpId, - vpHolder, - ); - expect(presentation).toMatchObject(getSamplePres(presentationCredentials)); - }, 30000); - test('A verifiable presentation should contain a proof once signed, and it should pass verification.', async () => { const signedVp = await signPresentation( getSamplePres(presentationCredentials),