Skip to content

Commit

Permalink
Merge pull request #426 from docknetwork/feat/pass-parsing-opts-blank…
Browse files Browse the repository at this point in the history
…-schema
  • Loading branch information
cykoder authored May 1, 2024
2 parents 1100c3c + 3152edc commit 86dc4e4
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/sdk",
"version": "8.1.4",
"version": "8.1.5",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/vc/crypto/common/DockCryptoSignature.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export default withExtendedStaticProperties(
let credSchema;
if (document.credentialSchema) {
// schema object exists but no ID means the SDK is signalling for the suite to generate a schema
credSchema = new CredentialSchema(CredentialSchema.essential());
credSchema = new CredentialSchema(CredentialSchema.essential(), document.credentialSchema.parsingOptions);
} else {
// Else, no schema was found so just use the essentials and v0.0.1 schema version
// NOTE: version is important here and MUST be 0.0.1 otherwise it will invalidate BBS+ credentials
Expand Down
72 changes: 71 additions & 1 deletion tests/integration/anoncreds/issuing.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { randomAsHex } from '@polkadot/util-crypto';
import { u8aToHex } from '@polkadot/util';
import { CredentialBuilder, CredentialSchema, initializeWasm } from '@docknetwork/crypto-wasm-ts';
import { DefaultSchemaParsingOpts, CredentialBuilder, CredentialSchema, initializeWasm } from '@docknetwork/crypto-wasm-ts';
import { DockAPI } from '../../../src';
import { createNewDockDID, DidKeypair } from '../../../src/utils/did';
import { DockResolver } from '../../../src/resolver';
Expand Down Expand Up @@ -238,6 +238,76 @@ describe.each(Schemes)('Issuance', ({
);
}, 30000);

test(`Can issue+verify a ${Name} credential with blank schema and custom parsingOptions`, async () => {
const parsingOptions = {
...DefaultSchemaParsingOpts,
defaultDecimalPlaces: 5,
useDefaults: true,
};

const issuerKey = getKeyDoc(did1, keypair, keypair.type, keypair.id);
const unsignedCred = {
...credentialJSON,
issuer: did1,
};

unsignedCred.credentialSchema = {
id: '',
type: 'JsonSchemaValidator2018',
parsingOptions,
};

const credential = await issueCredential(issuerKey, unsignedCred);

// Ensure schema was now defined, added by crypto-wasm-ts
expect(credential.credentialSchema).toBeDefined();
expect(credential.credentialSchema).toMatchObject({
parsingOptions,
version: CredentialSchema.VERSION,
});

const result = await verifyCredential(credential, { resolver });
expect(result).toMatchObject(
expect.objectContaining(getProofMatcherDoc()),
);
}, 30000);

test(`Can issue+verify a ${Name} credential with embedded schema and custom parsingOptions`, async () => {
const parsingOptions = {
...DefaultSchemaParsingOpts,
defaultDecimalPlaces: 5,
useDefaults: true,
};

const issuerKey = getKeyDoc(did1, keypair, keypair.type, keypair.id);
const unsignedCred = {
...credentialJSON,
credentialSchema: {
id: credentialJSON.credentialSchema.id,
type: 'JsonSchemaValidator2018',
parsingOptions,
},
issuer: did1,
};

expect(unsignedCred.credentialSchema.id).toBeDefined();
expect(unsignedCred.credentialSchema.id).not.toEqual('');

const credential = await issueCredential(issuerKey, unsignedCred);

// Ensure schema was now defined, added by crypto-wasm-ts
expect(credential.credentialSchema).toBeDefined();
expect(credential.credentialSchema).toMatchObject({
parsingOptions,
version: CredentialSchema.VERSION,
});

const result = await verifyCredential(credential, { resolver });
expect(result).toMatchObject(
expect.objectContaining(getProofMatcherDoc()),
);
}, 30000);

afterAll(async () => {
await dock.disconnect();
}, 10000);
Expand Down

0 comments on commit 86dc4e4

Please sign in to comment.