From 585e57fada561d42635b6271b7f10ea63ca56a72 Mon Sep 17 00:00:00 2001 From: vmidyllic <74898029+vmidyllic@users.noreply.github.com> Date: Tue, 10 Oct 2023 15:59:29 +0300 Subject: [PATCH] add cache loader (#75) --- package-lock.json | 12 ++++++------ package.json | 4 ++-- src/auth/auth.ts | 7 ++++--- src/types-sdk.ts | 16 ++++++++-------- test/auth.test.ts | 12 ++++++------ test/query.test.ts | 5 ++--- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2c80de9..881f127 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "@iden3/js-iden3-auth", - "version": "1.0.2", + "version": "1.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@iden3/js-iden3-auth", - "version": "1.0.2", + "version": "1.0.3", "license": "AGPL-3.0", "dependencies": { - "@0xpolygonid/js-sdk": "1.1.0", + "@0xpolygonid/js-sdk": "1.2.2", "@iden3/eslint-config": "https://github.com/iden3/eslint-config", "@iden3/js-iden3-core": "1.0.2", "@iden3/js-jsonld-merklization": "1.0.2", @@ -49,9 +49,9 @@ } }, "node_modules/@0xpolygonid/js-sdk": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@0xpolygonid/js-sdk/-/js-sdk-1.1.0.tgz", - "integrity": "sha512-nG7zYR4f5MAvywUIuxC7GEuISu54/9LqTZY43L5ObhhZai7jkohuGBmp4fU1o58aGLTZGKD4ggJCnqpDuBINyQ==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/@0xpolygonid/js-sdk/-/js-sdk-1.2.2.tgz", + "integrity": "sha512-vGnk3HrZSwe6+qZQuHKJCKgQZ1+Dy4EeBdaIDg9wnv2INr1AgY6ias/wGDX0Cr4wfkGrrPemQi8ztLFz82trdA==", "dependencies": { "@iden3/js-crypto": "1.0.1", "@iden3/js-iden3-core": "1.0.2", diff --git a/package.json b/package.json index e60d344..df8b68a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@iden3/js-iden3-auth", - "version": "1.0.2", + "version": "1.0.3", "description": "iden3-auth implementation in JavaScript", "main": "dist/cjs/index.js", "source": "./src/index.ts", @@ -34,7 +34,7 @@ "url": "https://github.com/iden3/js-iden3-auth" }, "dependencies": { - "@0xpolygonid/js-sdk": "1.1.0", + "@0xpolygonid/js-sdk": "1.2.2", "@iden3/eslint-config": "https://github.com/iden3/eslint-config", "@iden3/js-iden3-core": "1.0.2", "@iden3/js-jsonld-merklization": "1.0.2", diff --git a/src/auth/auth.ts b/src/auth/auth.ts index 911f581..cd2bc43 100644 --- a/src/auth/auth.ts +++ b/src/auth/auth.ts @@ -21,10 +21,11 @@ import { NativeProver, IZKProver, FSCircuitStorage, - ICircuitStorage + ICircuitStorage, + cacheLoader } from '@0xpolygonid/js-sdk'; import { Resolvable } from 'did-resolver'; -import { Options, getDocumentLoader, DocumentLoader } from '@iden3/js-jsonld-merklization'; +import { Options, DocumentLoader } from '@iden3/js-jsonld-merklization'; import path from 'path'; /** @@ -132,7 +133,7 @@ export class Verifier { */ static async newVerifier(params: VerifierParams): Promise { if (!params.suite) { - const documentLoader = getDocumentLoader(params as Options); + const documentLoader = (params as Options).documentLoader ?? cacheLoader(params as Options); const dirname = params?.circuitsDir ?? path.join(process.cwd(), 'circuits'); const circuitStorage = new FSCircuitStorage({ dirname }); params.suite = { diff --git a/src/types-sdk.ts b/src/types-sdk.ts index 9784efd..991ce74 100644 --- a/src/types-sdk.ts +++ b/src/types-sdk.ts @@ -1,8 +1,8 @@ -export { - AuthorizationRequestMessage, - AuthorizationResponseMessage, - CredentialsOfferMessage, - ZeroKnowledgeProofRequest, - ZeroKnowledgeProofResponse, - PROTOCOL_CONSTANTS -} from '@0xpolygonid/js-sdk'; \ No newline at end of file +export { + AuthorizationRequestMessage, + AuthorizationResponseMessage, + CredentialsOfferMessage, + ZeroKnowledgeProofRequest, + ZeroKnowledgeProofResponse, + PROTOCOL_CONSTANTS +} from '@0xpolygonid/js-sdk'; diff --git a/test/auth.test.ts b/test/auth.test.ts index 3eadb2a..cc875d6 100644 --- a/test/auth.test.ts +++ b/test/auth.test.ts @@ -9,7 +9,8 @@ import { PROTOCOL_CONSTANTS, PackageManager, ZeroKnowledgeProofRequest, - ZeroKnowledgeProofResponse + ZeroKnowledgeProofResponse, + cacheLoader } from '@0xpolygonid/js-sdk'; import { IStateResolver, ResolvedState, Resolvers } from '@lib/state/resolver'; import { AuthPubSignalsV2 } from '@lib/circuits/authV2'; @@ -20,7 +21,7 @@ import { } from '@lib/auth/auth'; import { Circuits, VerifyOpts } from '@lib/circuits/registry'; import { DIDResolutionResult } from 'did-resolver'; -import { DocumentLoader, getDocumentLoader } from '@iden3/js-jsonld-merklization'; +import { DocumentLoader } from '@iden3/js-jsonld-merklization'; import path from 'path'; describe('auth tests', () => { @@ -28,7 +29,7 @@ describe('auth tests', () => { if (!connectionString) { connectionString = 'https://ipfs.io'; } - const schemaLoader: DocumentLoader = getDocumentLoader({ + const schemaLoader: DocumentLoader = cacheLoader({ ipfsNodeURL: connectionString }); const exampleDidDoc = { @@ -493,7 +494,7 @@ describe('auth tests', () => { const verifier = await Verifier.newVerifier({ stateResolver: resolvers, circuitsDir: path.join(__dirname, './testdata'), - documentLoader: schemaLoader + ipfsNodeURL: connectionString }); const token = @@ -538,8 +539,7 @@ describe('auth tests', () => { const verifier = await Verifier.newVerifier({ stateResolver: resolvers, - circuitsDir: path.join(__dirname, './testdata'), - documentLoader: schemaLoader + circuitsDir: path.join(__dirname, './testdata') }); request.id = '28494007-9c49-4f1a-9694-7700c08865bf'; request.thid = '7f38a193-0918-4a48-9fac-36adfdb8b542'; // because it's used in the response diff --git a/test/query.test.ts b/test/query.test.ts index 676f492..f6edd33 100644 --- a/test/query.test.ts +++ b/test/query.test.ts @@ -1,9 +1,8 @@ import { checkQueryRequest, ClaimOutputs, Query } from '@lib/circuits/query'; import { getUnixTimestamp, Id, SchemaHash } from '@iden3/js-iden3-core'; -import { getDocumentLoader } from '@iden3/js-jsonld-merklization'; -import { byteEncoder, createSchemaHash } from '@0xpolygonid/js-sdk'; +import { byteEncoder, cacheLoader, createSchemaHash } from '@0xpolygonid/js-sdk'; -const defaultLoader = getDocumentLoader(); +const defaultLoader = cacheLoader(); const vpEmployee = JSON.parse(`{ "@type": "VerifiablePresentation", "@context": [