Skip to content

Commit

Permalink
update js-sdk to v1.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Mar 26, 2024
1 parent 9ba89be commit 4d1592a
Show file tree
Hide file tree
Showing 8 changed files with 599 additions and 1,602 deletions.
511 changes: 232 additions & 279 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"@iden3/js-crypto": "1.0.3",
"@0xpolygonid/js-sdk": "1.9.0",
"@0xpolygonid/js-sdk": "1.9.3",
"@iden3/js-iden3-core": "1.2.1",
"@iden3/js-jsonld-merklization": "1.1.2",
"@iden3/js-jwz": "1.3.0",
Expand Down
19 changes: 15 additions & 4 deletions src/circuits/atomicMtpV2.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { getDateFromUnixTimestamp } from '@iden3/js-iden3-core';
import { Resolvers } from '@lib/state/resolver';
import { checkQueryRequest, ClaimOutputs, Query } from '@lib/circuits/query';
import { checkQueryV2Circuits, ClaimOutputs, Query } from '@lib/circuits/query';
import { PubSignalsVerifier, VerifyOpts } from '@lib/circuits/registry';
import { IDOwnershipPubSignals } from '@lib/circuits/ownershipVerifier';
import { checkIssuerNonRevState, checkUserState, getResolverByID } from '@lib/circuits/common';
import { DocumentLoader } from '@iden3/js-jsonld-merklization';
import { AtomicQueryMTPV2PubSignals, BaseConfig, byteEncoder } from '@0xpolygonid/js-sdk';
import {
AtomicQueryMTPV2PubSignals,
BaseConfig,
byteEncoder,
CircuitId
} from '@0xpolygonid/js-sdk';

const valuesSize = 64;
const defaultProofVerifyOpts = 1 * 60 * 60 * 1000; // 1 hour
Expand Down Expand Up @@ -52,7 +57,14 @@ export class AtomicQueryMTPV2PubSignalsVerifier
valueArraySize: valuesSize,
isRevocationChecked: this.pubSignals.isRevocationChecked
};
await checkQueryRequest(query, outs, schemaLoader, verifiablePresentation, false, opts);
await checkQueryV2Circuits(
CircuitId.AtomicQueryMTPV2,
query,
outs,
schemaLoader,
opts,
verifiablePresentation
);

return this.pubSignals;
}
Expand All @@ -79,7 +91,6 @@ export class AtomicQueryMTPV2PubSignalsVerifier
if (opts?.acceptedStateTransitionDelay) {
acceptedStateTransitionDelay = opts.acceptedStateTransitionDelay;
}

if (!issuerNonRevStateResolved.latest) {
const timeDiff =
Date.now() -
Expand Down
19 changes: 16 additions & 3 deletions src/circuits/atomicSigV2.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { PubSignalsVerifier, VerifyOpts } from '@lib/circuits/registry';
import { checkQueryRequest, ClaimOutputs, Query } from '@lib/circuits/query';
import { checkQueryV2Circuits, ClaimOutputs, Query } from '@lib/circuits/query';
import { Resolvers } from '@lib/state/resolver';
import { IDOwnershipPubSignals } from '@lib/circuits/ownershipVerifier';
import { checkIssuerNonRevState, checkUserState, getResolverByID } from '@lib/circuits/common';
import { getDateFromUnixTimestamp } from '@iden3/js-iden3-core';
import { DocumentLoader } from '@iden3/js-jsonld-merklization';
import { AtomicQuerySigV2PubSignals, BaseConfig, byteEncoder } from '@0xpolygonid/js-sdk';
import {
AtomicQuerySigV2PubSignals,
BaseConfig,
byteEncoder,
CircuitId
} from '@0xpolygonid/js-sdk';

const valuesSize = 64;
const defaultProofVerifyOpts = 1 * 60 * 60 * 1000; // 1 hour
Expand Down Expand Up @@ -45,7 +50,15 @@ export class AtomicQuerySigV2PubSignalsVerifier
valueArraySize: valuesSize,
isRevocationChecked: this.pubSignals.isRevocationChecked
};
await checkQueryRequest(query, outs, schemaLoader, verifiablePresentation, false, opts);

await checkQueryV2Circuits(
CircuitId.AtomicQuerySigV2,
query,
outs,
schemaLoader,
opts,
verifiablePresentation
);

return this.pubSignals;
}
Expand Down
81 changes: 77 additions & 4 deletions src/circuits/atomicV3.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { PubSignalsVerifier, VerifyOpts } from '@lib/circuits/registry';
import { checkQueryRequest, ClaimOutputs, Query } from '@lib/circuits/query';
import { ClaimOutputs, Query } from '@lib/circuits/query';
import { Resolvers } from '@lib/state/resolver';
import { IDOwnershipPubSignals } from '@lib/circuits/ownershipVerifier';
import { checkIssuerNonRevState, checkUserState, getResolverByID } from '@lib/circuits/common';
import { DID, getDateFromUnixTimestamp } from '@iden3/js-iden3-core';
import { DocumentLoader } from '@iden3/js-jsonld-merklization';
import { DocumentLoader, getDocumentLoader } from '@iden3/js-jsonld-merklization';
import {
AtomicQueryV3PubSignals,
BaseConfig,
byteEncoder,
checkQueryRequest,
CircuitId,
JSONObject,
ProofType
Operators,
parseQueriesMetadata,
ProofType,
validateDisclosureNativeSDSupport,
validateEmptyCredentialSubjectNoopNativeSupport,
validateOperators,
verifyFieldValueInclusionNativeExistsSupport
} from '@0xpolygonid/js-sdk';
import { JsonLd } from 'jsonld/jsonld-spec';

const valuesSize = 64;
const defaultProofVerifyOpts = 1 * 60 * 60 * 1000; // 1 hour
Expand Down Expand Up @@ -56,7 +65,71 @@ export class AtomicQueryV3PubSignalsVerifier
isRevocationChecked: this.pubSignals.isRevocationChecked,
operatorOutput: this.pubSignals.operatorOutput
};
await checkQueryRequest(query, outs, schemaLoader, verifiablePresentation, true, opts);

if (!query.type) {
throw new Error(`proof query type is undefined`);
}

const loader = schemaLoader ?? getDocumentLoader();

// validate schema
let context: JsonLd;
try {
context = (await loader(query.context ?? '')).document;
} catch (e) {
throw new Error(`can't load schema for request query`);
}

const queriesMetadata = await parseQueriesMetadata(
query.type,
JSON.stringify(context),
query.credentialSubject as JSONObject,
{
documentLoader: loader
}
);

await checkQueryRequest(
query,
queriesMetadata,
context,
outs,
CircuitId.AtomicQueryV3,
loader,
opts
);

const queryMetadata = queriesMetadata[0]; // only one query is supported

// validate selective disclosure
if (queryMetadata.operator === Operators.SD) {
try {
await validateDisclosureNativeSDSupport(
queryMetadata,
outs,
verifiablePresentation,
loader
);
} catch (e) {
throw new Error(`failed to validate selective disclosure: ${(e as Error).message}`);
}
} else if (!queryMetadata.fieldName && queryMetadata.operator == Operators.NOOP) {
try {
await validateEmptyCredentialSubjectNoopNativeSupport(outs);
} catch (e: unknown) {
throw new Error(`failed to validate operators: ${(e as Error).message}`);
}
} else {
try {
await validateOperators(queryMetadata, outs);
} catch (e) {
throw new Error(`failed to validate operators: ${(e as Error).message}`);
}
}

// verify field inclusion / non-inclusion

verifyFieldValueInclusionNativeExistsSupport(outs, queryMetadata);

const { proofType, verifierID, nullifier, nullifierSessionID, linkID } = this.pubSignals;

Expand Down
Loading

0 comments on commit 4d1592a

Please sign in to comment.