Skip to content

Commit

Permalink
Feature/v2 strict (#99)
Browse files Browse the repository at this point in the history
* fix circuits folder

* use undefined

* fix iden3comm folder

* fix schema-processor & proof folders

* fix tests & kms

* fix storage folder

* Format & fix credentials

* Fix rest

* Fix SES error

* Fix unit tests

* remove await in terminate

* FIx comments

* fix lint

* Fix optional changes

* Removed universal DID Resolver

---------

Co-authored-by: vbasiuk <[email protected]>
  • Loading branch information
Kolezhniuk and volodymyr-basiuk authored Jul 18, 2023
1 parent fff6dd9 commit 4fc2f6f
Show file tree
Hide file tree
Showing 55 changed files with 3,083 additions and 1,710 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"rules": {
"no-console": 1, // Means warning
"prettier/prettier": 2, // Means error
"@typescript-eslint/no-floating-promises": ["error"]
"@typescript-eslint/no-floating-promises": ["error"],
"@typescript-eslint/no-non-null-assertion": "off"
},
"ignorePatterns": ["dist", "node_modules"]
}
3,411 changes: 2,359 additions & 1,052 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"doc:build": "npm run doc:extract && npm run doc:documenter",
"doc:watch:website": "ts-node ./scripts/doc-watch.ts",
"tsc:declaration:watch": "tsc --watch --module commonjs --emitDeclarationOnly",
"test": "mocha",
"test": "env TS_NODE_COMPILER_OPTIONS='{\"strict\": false}' mocha",
"lint": "eslint --fix --ext .js,.ts src/** tests/**",
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
"deps:check": "madge --circular --extensions ts ./"
Expand All @@ -43,16 +43,18 @@
},
"homepage": "https://github.com/0xPolygonID/js-sdk#readme",
"devDependencies": {
"@4c/fetch-mock": "^8.0.0",
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
"@microsoft/api-documenter": "^7.20.1",
"@microsoft/api-extractor": "^7.34.4",
"@gr2m/fetch-mock": "^9.11.0-pull-request-644.1",
"@microsoft/api-documenter": "^7.8.20",
"@microsoft/api-extractor": "^7.9.0",
"@types/chai": "^4.3.4",
"@types/chai-as-promised": "^7.1.5",
"@types/jsonld": "^1.4.8",
"@types/elliptic": "^6.4.14",
"@types/jsonld": "^1.5.9",
"@types/mocha": "^10.0.1",
"@types/node": "^18.16.19",
"@types/uuid": "^9.0.2",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
Expand Down Expand Up @@ -86,7 +88,6 @@
"ethers": "^5.7.2",
"ffjavascript": "^0.2.57",
"idb-keyval": "^6.2.0",
"ipfs-http-client": "56.0.3",
"jsonld": "^8.1.1",
"multiformats": "^9.6.5",
"rfc4648": "^1.5.2",
Expand All @@ -108,5 +109,5 @@
},
"engines": {
"node": ">=18.16.0"
}
}
}
106 changes: 57 additions & 49 deletions src/circuits/atomic-query-mtp-v2-on-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@ import { byteDecoder, byteEncoder } from '../utils';
*/
export class AtomicQueryMTPV2OnChainInputs extends BaseConfig {
// auth
id: Id;
profileNonce: bigint;
claimSubjectProfileNonce: bigint;
id!: Id;
profileNonce!: bigint;
claimSubjectProfileNonce!: bigint;
// claim issued for user
claim: ClaimWithMTPProof;
skipClaimRevocationCheck: boolean;
requestID: bigint;
claim!: ClaimWithMTPProof;
skipClaimRevocationCheck!: boolean;
requestID!: bigint;

currentTimeStamp: number;
currentTimeStamp!: number;

authClaim: Claim;
authClaimIncMtp: Proof;
authClaimNonRevMtp: Proof;
treeState: TreeState;
authClaim!: Claim;
authClaimIncMtp!: Proof;
authClaimNonRevMtp!: Proof;
treeState!: TreeState;

gistProof: GISTProof;
gistProof!: GISTProof;

signature: Signature;
challenge: bigint;
signature!: Signature;
challenge!: bigint;

// query
query: Query;
query!: Query;

/**
* Validate inputs
Expand All @@ -60,7 +60,7 @@ export class AtomicQueryMTPV2OnChainInputs extends BaseConfig {
if (!this.authClaimNonRevMtp) {
throw new Error(CircuitError.EmptyAuthClaimNonRevProof);
}
if (!this.gistProof?.proof) {
if (!this.gistProof.proof) {
throw new Error(CircuitError.EmptyGISTProof);
}
if (!this.signature) {
Expand Down Expand Up @@ -88,29 +88,35 @@ export class AtomicQueryMTPV2OnChainInputs extends BaseConfig {
requestID: this.requestID.toString(),
userGenesisID: this.id.bigInt().toString(),
profileNonce: this.profileNonce.toString(),
claimSubjectProfileNonce: this.claimSubjectProfileNonce.toString(),
issuerID: this.claim.issuerID.bigInt().toString(),
issuerClaim: this.claim.claim.marshalJson(),
issuerClaimMtp: prepareSiblingsStr(this.claim.incProof.proof, this.getMTLevel()),
claimSubjectProfileNonce: this.claimSubjectProfileNonce?.toString(),
issuerID: this.claim.issuerID?.bigInt().toString(),
issuerClaim: this.claim.claim?.marshalJson(),
issuerClaimMtp:
this.claim.incProof?.proof &&
prepareSiblingsStr(this.claim.incProof.proof, this.getMTLevel()),
issuerClaimClaimsTreeRoot: this.claim.incProof?.treeState?.claimsRoot?.string(),
issuerClaimRevTreeRoot: this.claim.incProof?.treeState?.revocationRoot?.string(),
issuerClaimRootsTreeRoot: this.claim.incProof?.treeState?.rootOfRoots?.string(),
issuerClaimIdenState: this.claim.incProof?.treeState?.state?.string(),
issuerClaimNonRevMtp: prepareSiblingsStr(this.claim.nonRevProof?.proof, this.getMTLevel()),
issuerClaimNonRevMtp:
this.claim.nonRevProof?.proof &&
prepareSiblingsStr(this.claim.nonRevProof?.proof, this.getMTLevel()),
issuerClaimNonRevClaimsTreeRoot: this.claim.nonRevProof?.treeState?.claimsRoot?.string(),
issuerClaimNonRevRevTreeRoot: this.claim.nonRevProof?.treeState?.revocationRoot?.string(),
issuerClaimNonRevRootsTreeRoot: this.claim.nonRevProof?.treeState?.rootOfRoots?.string(),
issuerClaimNonRevState: this.claim.nonRevProof?.treeState?.state?.string(),
claimSchema: this.claim.claim.getSchemaHash().bigInt().toString(),
claimSchema: this.claim.claim?.getSchemaHash().bigInt().toString(),
claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaimMerklization()),
claimPathValue: valueProof.value.toString(),
operator: this.query.operator,
slotIndex: this.query.slotIndex,
timestamp: this.currentTimeStamp,
timestamp: this.currentTimeStamp ?? undefined,
isRevocationChecked: 1,
authClaim: this.authClaim?.marshalJson(),
authClaimIncMtp: prepareSiblingsStr(this.authClaimIncMtp, this.getMTLevel()),
authClaimNonRevMtp: prepareSiblingsStr(this.authClaimNonRevMtp, this.getMTLevel()),
authClaim: this.authClaim.marshalJson(),
authClaimIncMtp:
this.authClaimIncMtp && prepareSiblingsStr(this.authClaimIncMtp, this.getMTLevel()),
authClaimNonRevMtp:
this.authClaimNonRevMtp && prepareSiblingsStr(this.authClaimNonRevMtp, this.getMTLevel()),
challenge: this.challenge.toString(),
challengeSignatureR8x: this.signature.R8[0].toString(),
challengeSignatureR8y: this.signature.R8[1].toString(),
Expand All @@ -120,17 +126,18 @@ export class AtomicQueryMTPV2OnChainInputs extends BaseConfig {
userRootsTreeRoot: this.treeState.rootOfRoots?.string(),
userState: this.treeState.state?.string(),
gistRoot: this.gistProof.root?.string(),
gistMtp: prepareSiblingsStr(this.gistProof.proof, this.getMTLevelOnChain())
gistMtp: this.gistProof && prepareSiblingsStr(this.gistProof.proof, this.getMTLevelOnChain())
};

if (this.skipClaimRevocationCheck) {
s.isRevocationChecked = 0;
}

const nodeAuxNonRev = getNodeAuxValue(this.claim.nonRevProof.proof);
s.issuerClaimNonRevMtpAuxHi = nodeAuxNonRev.key.bigInt().toString();
s.issuerClaimNonRevMtpAuxHv = nodeAuxNonRev.value.bigInt().toString();
s.issuerClaimNonRevMtpNoAux = nodeAuxNonRev.noAux;
const nodeAuxNonRev =
this.claim.nonRevProof?.proof && getNodeAuxValue(this.claim.nonRevProof.proof);
s.issuerClaimNonRevMtpAuxHi = nodeAuxNonRev?.key.bigInt().toString();
s.issuerClaimNonRevMtpAuxHv = nodeAuxNonRev?.value.bigInt().toString();
s.issuerClaimNonRevMtpNoAux = nodeAuxNonRev?.noAux;

s.claimPathNotExists = existenceToInt(valueProof.mtp.existence);
const nodAuxJSONLD = getNodeAuxValue(valueProof.mtp);
Expand All @@ -139,15 +146,16 @@ export class AtomicQueryMTPV2OnChainInputs extends BaseConfig {
s.claimPathMtpAuxHv = nodAuxJSONLD.value.bigInt().toString();

s.claimPathKey = valueProof.path.toString();
const values = prepareCircuitArrayValues(this.query.values, this.getValueArrSize());
s.value = bigIntArrayToStringArray(values);
const values =
this.query.values && prepareCircuitArrayValues(this.query.values, this.getValueArrSize());
s.value = values && bigIntArrayToStringArray(values);

const nodeAuxAuth = getNodeAuxValue(this.authClaimNonRevMtp);
const nodeAuxAuth = this.authClaimNonRevMtp && getNodeAuxValue(this.authClaimNonRevMtp);
s.authClaimNonRevMtpAuxHi = nodeAuxAuth.key.string();
s.authClaimNonRevMtpAuxHv = nodeAuxAuth.value.string();
s.authClaimNonRevMtpNoAux = nodeAuxAuth.noAux;

const globalNodeAux = getNodeAuxValue(this.gistProof.proof);
const globalNodeAux = this.gistProof && getNodeAuxValue(this.gistProof.proof);
s.gistMtpAuxHi = globalNodeAux.key.string();
s.gistMtpAuxHv = globalNodeAux.value.string();
s.gistMtpNoAux = globalNodeAux.noAux;
Expand All @@ -163,7 +171,7 @@ interface atomicQueryMTPV2OnChainCircuitInputs {
profileNonce: string;
claimSubjectProfileNonce: string;
issuerID: string;
issuerClaim?: string[];
issuerClaim: string[];

issuerClaimMtp: string[];
issuerClaimClaimsTreeRoot: string;
Expand All @@ -188,8 +196,8 @@ interface atomicQueryMTPV2OnChainCircuitInputs {
claimPathMtp: string[];
claimPathMtpNoAux: string; // 1 if aux node is empty,
// 0 if non-empty or for inclusion proofs
claimPathMtpAuxHi?: string; // 0 for inclusion proof
claimPathMtpAuxHv?: string; // 0 for inclusion proof
claimPathMtpAuxHi: string; // 0 for inclusion proof
claimPathMtpAuxHv: string; // 0 for inclusion proof
claimPathKey: string; // hash of path in merklized json-ld document
claimPathValue: string; // value in this path in merklized json-ld document

Expand Down Expand Up @@ -236,17 +244,17 @@ interface atomicQueryMTPV2OnChainCircuitInputs {
* @extends {BaseConfig}
*/
export class AtomicQueryMTPV2OnChainPubSignals extends BaseConfig {
requestID?: bigint;
userID?: Id;
issuerID?: Id;
issuerClaimIdenState?: Hash;
issuerClaimNonRevState?: Hash;
timestamp: number;
merklized: number;
isRevocationChecked: number; // 0 revocation not check, // 1 for check revocation
circuitQueryHash: bigint;
challenge: bigint;
gistRoot: Hash;
requestID!: bigint;
userID!: Id;
issuerID!: Id;
issuerClaimIdenState!: Hash;
issuerClaimNonRevState!: Hash;
timestamp!: number;
merklized!: number;
isRevocationChecked!: number; // 0 revocation not check, // 1 for check revocation
circuitQueryHash!: bigint;
challenge!: bigint;
gistRoot!: Hash;

/**
*
Expand Down
79 changes: 42 additions & 37 deletions src/circuits/atomic-query-mtp-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ import { byteDecoder, byteEncoder } from '../utils';
*/
export class AtomicQueryMTPV2Inputs extends BaseConfig {
// auth
id: Id;
profileNonce: bigint;
claimSubjectProfileNonce: bigint;
id!: Id;
profileNonce!: bigint;
claimSubjectProfileNonce!: bigint;
// claim issued for user
claim: ClaimWithMTPProof;
skipClaimRevocationCheck: boolean;
requestID: bigint;
claim!: ClaimWithMTPProof;
skipClaimRevocationCheck!: boolean;
requestID!: bigint;

currentTimeStamp: number;
currentTimeStamp!: number;

// query
query: Query;
query!: Query;

/**
* Validate AtomicQueryMTPV2 inputs
Expand Down Expand Up @@ -62,38 +62,42 @@ export class AtomicQueryMTPV2Inputs extends BaseConfig {
const s: Partial<AtomicQueryMTPV2CircuitInputs> = {
requestID: this.requestID.toString(),
userGenesisID: this.id.bigInt().toString(),
profileNonce: this.profileNonce.toString(),
claimSubjectProfileNonce: this.claimSubjectProfileNonce.toString(),
profileNonce: this.profileNonce?.toString(),
claimSubjectProfileNonce: this.claimSubjectProfileNonce?.toString(),
issuerID: this.claim.issuerID?.bigInt().toString(),
issuerClaim: this.claim.claim.marshalJson(),
issuerClaimMtp: prepareSiblingsStr(this.claim.incProof.proof, this.getMTLevel()),
issuerClaimClaimsTreeRoot: this.claim.incProof.treeState?.claimsRoot.bigInt().toString(),
issuerClaimRevTreeRoot: this.claim.incProof.treeState?.revocationRoot.bigInt().toString(),
issuerClaimRootsTreeRoot: this.claim.incProof.treeState?.rootOfRoots.bigInt().toString(),
issuerClaimIdenState: this.claim.incProof.treeState?.state.bigInt().toString(),
issuerClaimNonRevMtp: prepareSiblingsStr(this.claim.nonRevProof.proof, this.getMTLevel()),
issuerClaimNonRevClaimsTreeRoot: this.claim.nonRevProof.treeState?.claimsRoot
.bigInt()
issuerClaim: this.claim.claim?.marshalJson(),
issuerClaimMtp:
this.claim.incProof?.proof &&
prepareSiblingsStr(this.claim.incProof.proof, this.getMTLevel()),
issuerClaimClaimsTreeRoot: this.claim.incProof?.treeState?.claimsRoot?.bigInt().toString(),
issuerClaimRevTreeRoot: this.claim.incProof?.treeState?.revocationRoot?.bigInt().toString(),
issuerClaimRootsTreeRoot: this.claim.incProof?.treeState?.rootOfRoots?.bigInt().toString(),
issuerClaimIdenState: this.claim.incProof?.treeState?.state?.bigInt().toString(),
issuerClaimNonRevMtp:
this.claim.nonRevProof?.proof &&
prepareSiblingsStr(this.claim.nonRevProof.proof, this.getMTLevel()),
issuerClaimNonRevClaimsTreeRoot: this.claim.nonRevProof?.treeState?.claimsRoot
?.bigInt()
.toString(),
issuerClaimNonRevRevTreeRoot: this.claim.nonRevProof.treeState?.revocationRoot
.bigInt()
issuerClaimNonRevRevTreeRoot: this.claim.nonRevProof?.treeState?.revocationRoot
?.bigInt()
.toString(),
issuerClaimNonRevRootsTreeRoot: this.claim.nonRevProof.treeState?.rootOfRoots
.bigInt()
issuerClaimNonRevRootsTreeRoot: this.claim.nonRevProof?.treeState?.rootOfRoots
?.bigInt()
.toString(),
issuerClaimNonRevState: this.claim.nonRevProof.treeState?.state.bigInt().toString(),
claimSchema: this.claim.claim.getSchemaHash().bigInt().toString(),
issuerClaimNonRevState: this.claim.nonRevProof?.treeState?.state?.bigInt().toString(),
claimSchema: this.claim.claim?.getSchemaHash().bigInt().toString(),
claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaimMerklization()),
claimPathValue: valueProof.value.toString(),
operator: this.query.operator,
slotIndex: this.query.slotIndex,
timestamp: this.currentTimeStamp
};

const nodeAux = getNodeAuxValue(this.claim.nonRevProof.proof);
s.issuerClaimNonRevMtpAuxHi = nodeAux.key.bigInt().toString();
s.issuerClaimNonRevMtpAuxHv = nodeAux.value.bigInt().toString();
s.issuerClaimNonRevMtpNoAux = nodeAux.noAux;
const nodeAux = getNodeAuxValue(this.claim.nonRevProof?.proof);
s.issuerClaimNonRevMtpAuxHi = nodeAux?.key.bigInt().toString();
s.issuerClaimNonRevMtpAuxHv = nodeAux?.value.bigInt().toString();
s.issuerClaimNonRevMtpNoAux = nodeAux?.noAux;

s.claimPathNotExists = existenceToInt(valueProof.mtp.existence);
const nodAuxJSONLD = getNodeAuxValue(valueProof.mtp);
Expand All @@ -109,7 +113,8 @@ export class AtomicQueryMTPV2Inputs extends BaseConfig {
s.isRevocationChecked = 1;
}

const values = prepareCircuitArrayValues(this.query.values, this.getValueArrSize());
const values =
this.query.values && prepareCircuitArrayValues(this.query.values, this.getValueArrSize());

s.value = bigIntArrayToStringArray(values);

Expand Down Expand Up @@ -167,17 +172,17 @@ export class AtomicQueryMTPV2PubSignals extends BaseConfig {
issuerID?: Id;
issuerClaimIdenState?: Hash;
issuerClaimNonRevState?: Hash;
claimSchema: SchemaHash;
slotIndex: number;
operator: number;
claimSchema?: SchemaHash;
slotIndex?: number;
operator?: number;
value: bigint[] = [];
timestamp: number;
merklized: number;
timestamp?: number;
merklized?: number;
claimPathKey?: bigint;
// 0 for inclusion, 1 for non-inclusion
claimPathNotExists: number;
claimPathNotExists?: number;
// 0 revocation not check, // 1 for check revocation
isRevocationChecked: number;
isRevocationChecked?: number;

/**
* PubSignalsUnmarshal unmarshal credentialAtomicQueryMTP.circom public signals array to AtomicQueryMTPPubSignals
Expand Down
Loading

0 comments on commit 4fc2f6f

Please sign in to comment.