Skip to content

Commit

Permalink
Merge pull request #364 from docknetwork/test/backwards-compat-bbs
Browse files Browse the repository at this point in the history
Add default version for schema
  • Loading branch information
cykoder authored Sep 26, 2023
2 parents 5aaa427 + bb79dc4 commit 40adf2d
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 21 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"no-return-await": "off",
"no-bitwise": ["error", { "allow": ["~"] }],
"no-plusplus": "off",
"no-restricted-properties": "off",
"max-len": "off",
"no-console": "off",
"no-else-return": "off",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
},
"dependencies": {
"@digitalbazaar/vc-status-list": "^4.0.0",
"@docknetwork/crypto-wasm-ts": "^0.42.0",
"@docknetwork/crypto-wasm-ts": "0.44.0",
"@docknetwork/node-types": "^0.16.0",
"@juanelas/base64": "^1.0.5",
"@polkadot/api": "9.7.1",
Expand Down
2 changes: 0 additions & 2 deletions src/modules/did/did.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,6 @@ class DIDModule {
}
if (this.api.query.offchainSignatures != null) {
const resp = await this.api.query.offchainSignatures.publicKeys.multi(queryKeys);

let currentIter = 0;
for (let r of resp) {
// The gaps in `keyId` might correspond to removed keys
Expand Down Expand Up @@ -885,7 +884,6 @@ class DIDModule {
}
} else {
const resp = await this.api.query.bbsPlus.bbsPlusKeys.multi(queryKeys);

let currentIter = 0;
for (const r of resp) {
// The gaps in `keyId` might correspond to removed keys
Expand Down
18 changes: 15 additions & 3 deletions src/utils/vc/crypto/common/DockCryptoSignature.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,15 @@ export default withExtendedStaticProperties(
let credSchema;
if (document.credentialSchema) {
credSchema = CredentialSchema.fromJSON({
parsingOptions: DEFAULT_PARSING_OPTS,
// Passing all the default parsing options. Ideally `document.credentialSchema` should contain these
parsingOptions: {
useDefaults: false,
defaultMinimumInteger: -((2 ** 32) - 1),
defaultMinimumDate: -((2 ** 44) - 1),
defaultDecimalPlaces: 0,
},
...document.credentialSchema,
});

// TODO: support documentloader for schemas here so we can use dock chain schemas
// requires that the presentation wrapper passes a documentloader to this method
// const loadedSchema = (await documentLoader(document.credentialSchema.id)).document;
Expand All @@ -133,7 +138,14 @@ export default withExtendedStaticProperties(
if (!credSchema) {
credSchema = new CredentialSchema(
CredentialSchema.essential(),
DEFAULT_PARSING_OPTS,
// Passing old parsing options and version
{
useDefaults: false,
defaultMinimumInteger: -((2 ** 32) - 1),
defaultDecimalPlaces: 0,
},
false,
{ version: '0.0.1' },
);
}

Expand Down
43 changes: 43 additions & 0 deletions tests/data/static-bbs-cred-610.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
{
"dk": "https://ld.dock.io/credentials#",
"BasicCredential": "dk:BasicCredential",
"name": "dk:name"
}
],
"id": "https://creds-staging.dock.io/be2b56a51e0ec8aa2ee5e92a0267a82bff6cc11a5f2275cfc8b014f3b9422a21",
"type": [
"VerifiableCredential",
"BasicCredential"
],
"credentialSubject": {
"id": "mysnjid",
"name": "sbj name"
},
"issuanceDate": "2023-09-25T18:27:27.053Z",
"issuer": {
"name": "newdid",
"id": "did:dock:5GZn9zQTggPWijzgnoV8sZ5a74rFqC8qrz2ncp7GggeGCtKd"
},
"name": "static bbs plus test",
"proof": {
"@context": [
{
"sec": "https://w3id.org/security#",
"proof": {
"@id": "sec:proof",
"@type": "@id",
"@container": "@graph"
}
},
"https://ld.dock.io/security/bbs/v1"
],
"type": "Bls12381BBS+SignatureDock2022",
"created": "2023-09-25T18:28:13Z",
"verificationMethod": "did:dock:5GZn9zQTggPWijzgnoV8sZ5a74rFqC8qrz2ncp7GggeGCtKd#keys-2",
"proofPurpose": "assertionMethod",
"proofValue": "zToVRuY4HPCWvXjKCcNFvc3FsxYGMzjSvsfBNS41XHWuAbq9G583kqNhLueELxYCdcL5KSNSr9ABA7JopkyNhoxuB9VaLjXhsn5V7ZxEmAu4W1XpKEXMSoae9MLtRRNDdDpPusihQe7uhM9FhuAEkuBnnp"
}
}
42 changes: 42 additions & 0 deletions tests/data/static-bbs-cred-630.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
{
"dk": "https://ld.dock.io/credentials#",
"BasicCredential": "dk:BasicCredential",
"name": "dk:name"
}
],
"id": "https://creds-staging.dock.io/0985a64f2910e74c48e4066fa683e4cdd9c54d021f6b83a9fd8cb56db9c460e3",
"type": [
"VerifiableCredential",
"BasicCredential"
],
"credentialSubject": {
"name": "basic bbs static"
},
"issuanceDate": "2023-09-22T20:59:25.847Z",
"issuer": {
"name": "newdid",
"id": "did:dock:5GZn9zQTggPWijzgnoV8sZ5a74rFqC8qrz2ncp7GggeGCtKd"
},
"name": "basic bbs static",
"proof": {
"@context": [
{
"sec": "https://w3id.org/security#",
"proof": {
"@id": "sec:proof",
"@type": "@id",
"@container": "@graph"
}
},
"https://ld.dock.io/security/bbs/v1"
],
"type": "Bls12381BBS+SignatureDock2022",
"created": "2023-09-22T20:59:55Z",
"verificationMethod": "did:dock:5GZn9zQTggPWijzgnoV8sZ5a74rFqC8qrz2ncp7GggeGCtKd#keys-2",
"proofPurpose": "assertionMethod",
"proofValue": "zaEUvk9cmVeVrHueiKMKPwxtV3zab2fRiVkGmah74rFnyXbQtYBtyrGs4zmVTs2jrrWQzeHsgNjf4H1MYMqVjvQmKCfnw4PPjMXS2p8gYQiwm8XaJJwSjT94p1af1ygHrbkpjQmMafPf3gfVqRbyvULW2G"
}
}
33 changes: 33 additions & 0 deletions tests/data/static-did-dock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"@context": [
"https://www.w3.org/ns/did/v1"
],
"id": "did:dock:5GZn9zQTggPWijzgnoV8sZ5a74rFqC8qrz2ncp7GggeGCtKd",
"controller": [
"did:dock:5GZn9zQTggPWijzgnoV8sZ5a74rFqC8qrz2ncp7GggeGCtKd"
],
"publicKey": [
{
"id": "did:dock:5GZn9zQTggPWijzgnoV8sZ5a74rFqC8qrz2ncp7GggeGCtKd#keys-1",
"type": "Ed25519VerificationKey2018",
"controller": "did:dock:5GZn9zQTggPWijzgnoV8sZ5a74rFqC8qrz2ncp7GggeGCtKd",
"publicKeyBase58": "D74srRGhLCCWK9GEE7m1EXKtUVsAXu4DC6kZ7qPEt7JE"
},
{
"id": "did:dock:5GZn9zQTggPWijzgnoV8sZ5a74rFqC8qrz2ncp7GggeGCtKd#keys-2",
"type": "Bls12381G2VerificationKeyDock2022",
"controller": "did:dock:5GZn9zQTggPWijzgnoV8sZ5a74rFqC8qrz2ncp7GggeGCtKd",
"publicKeyBase58": "zqgSKjTri2v5dvKsMi2FY1p2FFVcUd4kRGi4QxQgHyr1g9V7JH42bsvLkfZNqWvS5MhisgwToWseGvifV7TvtMZJzWAopTVrWejpviWejBA1JY8xxpqvVPAwvArrj3Dr1Ng"
}
],
"authentication": [
"did:dock:5GZn9zQTggPWijzgnoV8sZ5a74rFqC8qrz2ncp7GggeGCtKd#keys-1"
],
"assertionMethod": [
"did:dock:5GZn9zQTggPWijzgnoV8sZ5a74rFqC8qrz2ncp7GggeGCtKd#keys-1",
"did:dock:5GZn9zQTggPWijzgnoV8sZ5a74rFqC8qrz2ncp7GggeGCtKd#keys-2"
],
"capabilityInvocation": [
"did:dock:5GZn9zQTggPWijzgnoV8sZ5a74rFqC8qrz2ncp7GggeGCtKd#keys-1"
]
}
3 changes: 2 additions & 1 deletion tests/integration/anoncreds/issuing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ for (const {
lprNumber: 1234,
},
};

describe(`${Name} Module`, () => {
const dock = new DockAPI();
const resolver = new DockResolver(dock);
Expand Down Expand Up @@ -160,7 +161,7 @@ for (const {
expect(resultWithSchema).toMatchObject(
expect.objectContaining(getProofMatcherDoc()),
);
}, 30000);
}, 30000);

test(`Can issue+verify a ${Name} credential with default schema`, async () => {
const issuerKey = getKeyDoc(did1, keypair, keypair.type, keypair.id);
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/static-bbs.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { verifyCredential } from '../../src/utils/vc/index';
import defaultDocumentLoader from '../../src/utils/vc/document-loader';
import didDocument from '../data/static-did-dock.json';
import staticCred610 from '../data/static-bbs-cred-610.json';
// import staticCred630 from '../data/static-bbs-cred-630.json'; // TODO: add a credential from 6.3.0

const loadDocumentDefault = defaultDocumentLoader(null);

async function documentLoader(doc) {
if (doc.startsWith(staticCred610.issuer.id)) {
return {
contextUrl: null,
documentUrl: doc,
document: didDocument,
};
}

return loadDocumentDefault(doc);
}

describe('Static BBS+ Credential Verification (backwards compatibility)', () => {
test('verifies BBS+ credential from SDK 6.1.0', async () => {
const result = await verifyCredential(staticCred610, {
documentLoader,
});
console.error(JSON.stringify(result, null, 2));
expect(result.verified).toBe(true);
});

// test('verifies BBS+ credential from SDK 6.3.0', async () => {
// const result = await verifyCredential(staticCred630, {
// documentLoader,
// });
// console.error(JSON.stringify(result, null, 2));
// expect(result.verified).toBe(true);
// });
});
37 changes: 23 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2481,10 +2481,10 @@
jsonld "^5.2.0"
jsonld-signatures "^9.3.0"

"@docknetwork/crypto-wasm-ts@^0.42.0":
version "0.42.0"
resolved "https://registry.yarnpkg.com/@docknetwork/crypto-wasm-ts/-/crypto-wasm-ts-0.42.0.tgz#4edd11e315b8ed62b5d470eed9de8d7a6332117c"
integrity sha512-M5dp6WiX5OS9AzUv7TaWAU/dDg7GlWHx3e3BbvquQV1qgklDlkqpgdM2O2rWYdQMCgyAEcGwFMtD2dyF8e8xyQ==
"@docknetwork/crypto-wasm-ts@0.44.0":
version "0.44.0"
resolved "https://registry.yarnpkg.com/@docknetwork/crypto-wasm-ts/-/crypto-wasm-ts-0.44.0.tgz#38bbee2182e613111ce167362bd07bb32ca0ada5"
integrity sha512-xF53RZVWlVbngTnnOqsX6lH4U99A4TdtK/XxOonDSN4EXuGlqRD2vsqhXBne9Bk0B0ingbr9Gkp0PEk3w2DGMw==
dependencies:
"@docknetwork/crypto-wasm" "0.21.0"
"@types/flat" "^5.0.2"
Expand All @@ -2494,6 +2494,7 @@
json-pointer "^0.6.2"
lodash "^4.17.21"
lzutf8 "0.6.3"
semver "^7.5.4"

"@docknetwork/[email protected]", "@docknetwork/crypto-wasm@^0.21.0":
version "0.21.0"
Expand Down Expand Up @@ -3979,9 +3980,9 @@
integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==

"@types/flat@^5.0.2":
version "5.0.2"
resolved "https://registry.yarnpkg.com/@types/flat/-/flat-5.0.2.tgz#642a51a037d1f52fda082312b0e4566dc09a9f8f"
integrity sha512-3zsplnP2djeps5P9OyarTxwRpMLoe5Ash8aL9iprw0JxB+FAHjY+ifn4yZUuW4/9hqtnmor6uvjSRzJhiVbrEQ==
version "5.0.3"
resolved "https://registry.yarnpkg.com/@types/flat/-/flat-5.0.3.tgz#1f8045859a7e0955acf2a50e8c2979899e7b1801"
integrity sha512-uG/4x6EXYbq4VDsBJLNDHQAQmtRPg3x4tAXcBspxlnEknz8NiJxnHoxSiJKGNExiS00q4mJNvuEBgVA3jsDIdQ==

"@types/fs-extra@^8.0.1":
version "8.1.2"
Expand Down Expand Up @@ -4068,9 +4069,9 @@
integrity sha512-HZQYqbiFVWufzCwexrvh694SOim8z2d+xJl5UNamcvQFejLY/2YUtzXHYi3cHdI7PMlS8ejH2slRAOJQ32aNbA==

"@types/lodash@^4.14.195":
version "4.14.197"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.197.tgz#e95c5ddcc814ec3e84c891910a01e0c8a378c54b"
integrity sha512-BMVOiWs0uNxHVlHBgzTIqJYmj+PgCo4euloGF+5m4okL3rEYzM2EEv78mw8zWSMM57dM7kVIgJ2QDvwHSoCI5g==
version "4.14.199"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.199.tgz#c3edb5650149d847a277a8961a7ad360c474e9bf"
integrity sha512-Vrjz5N5Ia4SEzWWgIVwnHNEnb1UE1XMkvY5DGXrAeOGE9imk0hgTHh5GyDjLDJi9OTCn9oo9dXH1uToK1VRfrg==

"@types/long@^4.0.1":
version "4.0.2"
Expand Down Expand Up @@ -10643,14 +10644,15 @@ readable-stream@^3.4.0, readable-stream@^3.6.0:
util-deprecate "^1.0.1"

readable-stream@^4.0.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-4.2.0.tgz#a7ef523d3b39e4962b0db1a1af22777b10eeca46"
integrity sha512-gJrBHsaI3lgBoGMW/jHZsQ/o/TIWiu5ENCJG1BB7fuCKzpFM8GaS2UoBVt9NO+oI+3FcrBNbUkl3ilDe09aY4A==
version "4.4.2"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-4.4.2.tgz#e6aced27ad3b9d726d8308515b9a1b98dc1b9d13"
integrity sha512-Lk/fICSyIhodxy1IDK2HazkeGjSmezAWX2egdtJnYhtzKEsBPJowlI6F6LPb5tqIQILrMbx22S5o3GuJavPusA==
dependencies:
abort-controller "^3.0.0"
buffer "^6.0.3"
events "^3.3.0"
process "^0.11.10"
string_decoder "^1.3.0"

readable-web-to-node-stream@^3.0.2:
version "3.0.2"
Expand Down Expand Up @@ -11195,6 +11197,13 @@ semver@^7.3.2, semver@^7.3.5:
dependencies:
lru-cache "^6.0.0"

semver@^7.5.4:
version "7.5.4"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"
integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==
dependencies:
lru-cache "^6.0.0"

[email protected]:
version "0.18.0"
resolved "https://registry.yarnpkg.com/send/-/send-0.18.0.tgz#670167cc654b05f5aa4a767f9113bb371bc706be"
Expand Down Expand Up @@ -11704,7 +11713,7 @@ string.prototype.trimstart@^1.0.6:
define-properties "^1.1.4"
es-abstract "^1.20.4"

string_decoder@^1.1.1:
string_decoder@^1.1.1, string_decoder@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e"
integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==
Expand Down

0 comments on commit 40adf2d

Please sign in to comment.