@0xpolygonid/js-sdk 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/esm/index.js +1685 -468
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +1706 -473
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/circuits/atomic-query-mtp-v2-on-chain.js +1 -1
- package/dist/node/cjs/circuits/atomic-query-mtp-v2.js +1 -1
- package/dist/node/cjs/circuits/atomic-query-sig-v2-on-chain.js +2 -2
- package/dist/node/cjs/circuits/atomic-query-sig-v2.js +11 -14
- package/dist/node/cjs/circuits/atomic-query-v3-on-chain.js +320 -0
- package/dist/node/cjs/circuits/atomic-query-v3.js +275 -0
- package/dist/node/cjs/circuits/common.js +5 -7
- package/dist/node/cjs/circuits/comparer.js +57 -2
- package/dist/node/cjs/circuits/index.js +4 -0
- package/dist/node/cjs/circuits/linked-multi-query.js +128 -0
- package/dist/node/cjs/circuits/linked-nullifier.js +57 -0
- package/dist/node/cjs/circuits/models.js +25 -1
- package/dist/node/cjs/credentials/credential-wallet.js +2 -10
- package/dist/node/cjs/credentials/index.js +1 -0
- package/dist/node/cjs/credentials/utils.js +23 -0
- package/dist/node/cjs/iden3comm/handlers/auth.js +49 -8
- package/dist/node/cjs/iden3comm/handlers/contract-request.js +20 -8
- package/dist/node/cjs/proof/common.js +104 -1
- package/dist/node/cjs/proof/inputs-generator.js +393 -0
- package/dist/node/cjs/proof/proof-service.js +105 -372
- package/dist/node/cjs/schema-processor/json/parser.js +7 -0
- package/dist/node/cjs/schema-processor/json/validator.js +1 -0
- package/dist/node/cjs/storage/filters/jsonQuery.js +73 -8
- package/dist/node/cjs/utils/did-helper.js +14 -0
- package/dist/node/cjs/utils/index.js +2 -0
- package/dist/node/cjs/utils/object.js +42 -0
- package/dist/node/cjs/verifiable/presentation.js +34 -33
- package/dist/node/cjs/verifiable/proof.js +2 -0
- package/dist/node/esm/circuits/atomic-query-mtp-v2-on-chain.js +1 -1
- package/dist/node/esm/circuits/atomic-query-mtp-v2.js +1 -1
- package/dist/node/esm/circuits/atomic-query-sig-v2-on-chain.js +2 -2
- package/dist/node/esm/circuits/atomic-query-sig-v2.js +11 -14
- package/dist/node/esm/circuits/atomic-query-v3-on-chain.js +315 -0
- package/dist/node/esm/circuits/atomic-query-v3.js +270 -0
- package/dist/node/esm/circuits/common.js +4 -6
- package/dist/node/esm/circuits/comparer.js +55 -1
- package/dist/node/esm/circuits/index.js +4 -0
- package/dist/node/esm/circuits/linked-multi-query.js +123 -0
- package/dist/node/esm/circuits/linked-nullifier.js +52 -0
- package/dist/node/esm/circuits/models.js +25 -1
- package/dist/node/esm/credentials/credential-wallet.js +2 -10
- package/dist/node/esm/credentials/index.js +1 -0
- package/dist/node/esm/credentials/utils.js +19 -0
- package/dist/node/esm/iden3comm/handlers/auth.js +50 -9
- package/dist/node/esm/iden3comm/handlers/contract-request.js +20 -8
- package/dist/node/esm/proof/common.js +101 -2
- package/dist/node/esm/proof/inputs-generator.js +389 -0
- package/dist/node/esm/proof/proof-service.js +111 -377
- package/dist/node/esm/schema-processor/json/parser.js +7 -0
- package/dist/node/esm/schema-processor/json/validator.js +1 -0
- package/dist/node/esm/storage/filters/jsonQuery.js +74 -9
- package/dist/node/esm/utils/did-helper.js +10 -0
- package/dist/node/esm/utils/index.js +2 -0
- package/dist/node/esm/utils/object.js +38 -0
- package/dist/node/esm/verifiable/presentation.js +30 -29
- package/dist/node/esm/verifiable/proof.js +2 -0
- package/dist/types/circuits/atomic-query-mtp-v2.d.ts +13 -13
- package/dist/types/circuits/atomic-query-v3-on-chain.d.ts +142 -0
- package/dist/types/circuits/atomic-query-v3.d.ts +120 -0
- package/dist/types/circuits/common.d.ts +4 -4
- package/dist/types/circuits/comparer.d.ts +33 -1
- package/dist/types/circuits/index.d.ts +4 -0
- package/dist/types/circuits/linked-multi-query.d.ts +38 -0
- package/dist/types/circuits/linked-nullifier.d.ts +37 -0
- package/dist/types/circuits/models.d.ts +20 -2
- package/dist/types/credentials/index.d.ts +1 -0
- package/dist/types/credentials/utils.d.ts +12 -0
- package/dist/types/iden3comm/types/packer.d.ts +1 -2
- package/dist/types/iden3comm/types/protocol/auth.d.ts +1 -0
- package/dist/types/proof/common.d.ts +34 -3
- package/dist/types/proof/inputs-generator.d.ts +46 -0
- package/dist/types/proof/proof-service.d.ts +14 -25
- package/dist/types/schema-processor/json/parser.d.ts +1 -0
- package/dist/types/storage/filters/jsonQuery.d.ts +1 -1
- package/dist/types/utils/did-helper.d.ts +6 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/object.d.ts +12 -0
- package/dist/types/verifiable/presentation.d.ts +6 -10
- package/package.json +3 -3
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import { DID, Id, getUnixTimestamp } from '@iden3/js-iden3-core';
|
|
2
|
+
import { ProofType } from '../verifiable';
|
|
3
|
+
import { AtomicQueryMTPV2Inputs, AtomicQueryMTPV2OnChainInputs, AtomicQuerySigV2Inputs, AtomicQuerySigV2OnChainInputs, AtomicQueryV3Inputs, AtomicQueryV3OnChainInputs, CircuitClaim, CircuitId, LinkedMultiQueryInputs, LinkedNullifierInputs, Operators } from '../circuits';
|
|
4
|
+
import { toClaimNonRevStatus, toGISTProof } from './common';
|
|
5
|
+
import { getUserDIDFromCredential } from '../credentials';
|
|
6
|
+
const circuitValidator = {
|
|
7
|
+
[CircuitId.AtomicQueryMTPV2]: { maxQueriesCount: 1 },
|
|
8
|
+
[CircuitId.AtomicQueryMTPV2OnChain]: { maxQueriesCount: 1 },
|
|
9
|
+
[CircuitId.AtomicQuerySigV2]: { maxQueriesCount: 1 },
|
|
10
|
+
[CircuitId.AtomicQuerySigV2OnChain]: { maxQueriesCount: 1 },
|
|
11
|
+
[CircuitId.AtomicQueryV3]: { maxQueriesCount: 1 },
|
|
12
|
+
[CircuitId.AtomicQueryV3OnChain]: { maxQueriesCount: 1 },
|
|
13
|
+
[CircuitId.AuthV2]: { maxQueriesCount: 0 },
|
|
14
|
+
[CircuitId.StateTransition]: { maxQueriesCount: 0 },
|
|
15
|
+
[CircuitId.LinkedNullifier]: { maxQueriesCount: 1 },
|
|
16
|
+
[CircuitId.LinkedMultiQuery10]: { maxQueriesCount: 10 }
|
|
17
|
+
};
|
|
18
|
+
export class InputGenerator {
|
|
19
|
+
constructor(_identityWallet, _credentialWallet, _stateStorage) {
|
|
20
|
+
this._identityWallet = _identityWallet;
|
|
21
|
+
this._credentialWallet = _credentialWallet;
|
|
22
|
+
this._stateStorage = _stateStorage;
|
|
23
|
+
this.credentialAtomicQueryMTPV2PrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
|
|
24
|
+
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
25
|
+
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
26
|
+
const circuitInputs = new AtomicQueryMTPV2Inputs();
|
|
27
|
+
circuitInputs.id = DID.idFromDID(identifier);
|
|
28
|
+
circuitInputs.requestID = BigInt(proofReq.id);
|
|
29
|
+
const query = circuitQueries[0];
|
|
30
|
+
query.operator = query.operator === Operators.SD ? Operators.EQ : query.operator;
|
|
31
|
+
circuitInputs.query = query;
|
|
32
|
+
circuitInputs.claim = {
|
|
33
|
+
issuerID: circuitClaimData.issuerId,
|
|
34
|
+
claim: circuitClaimData.claim,
|
|
35
|
+
incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState },
|
|
36
|
+
nonRevProof: circuitClaimData.nonRevProof
|
|
37
|
+
};
|
|
38
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
39
|
+
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
40
|
+
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
41
|
+
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
42
|
+
return circuitInputs.inputsMarshal();
|
|
43
|
+
};
|
|
44
|
+
this.credentialAtomicQueryMTPV2OnChainPrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
|
|
45
|
+
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
46
|
+
const authInfo = await this.prepareAuthBJJCredential(identifier);
|
|
47
|
+
const authClaimData = await this.newCircuitClaimData({
|
|
48
|
+
credential: authInfo.credential,
|
|
49
|
+
credentialCoreClaim: authInfo.coreClaim
|
|
50
|
+
});
|
|
51
|
+
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
52
|
+
const circuitInputs = new AtomicQueryMTPV2OnChainInputs();
|
|
53
|
+
const id = DID.idFromDID(identifier);
|
|
54
|
+
circuitInputs.id = DID.idFromDID(identifier);
|
|
55
|
+
circuitInputs.requestID = BigInt(proofReq.id);
|
|
56
|
+
const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
|
|
57
|
+
const gistProof = toGISTProof(stateProof);
|
|
58
|
+
circuitInputs.gistProof = gistProof;
|
|
59
|
+
if (authClaimData?.treeState) {
|
|
60
|
+
circuitInputs.treeState = {
|
|
61
|
+
state: authClaimData?.treeState?.state,
|
|
62
|
+
claimsRoot: authClaimData?.treeState?.claimsRoot,
|
|
63
|
+
revocationRoot: authClaimData?.treeState?.revocationRoot,
|
|
64
|
+
rootOfRoots: authClaimData?.treeState?.rootOfRoots
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
circuitInputs.authClaim = authClaimData.claim;
|
|
68
|
+
circuitInputs.authClaimIncMtp = authClaimData.proof;
|
|
69
|
+
circuitInputs.authClaimNonRevMtp = authInfo.nonRevProof.proof;
|
|
70
|
+
if (!params.challenge) {
|
|
71
|
+
throw new Error('challenge must be provided for onchain circuits');
|
|
72
|
+
}
|
|
73
|
+
const signature = await this._identityWallet.signChallenge(params.challenge, authInfo.credential);
|
|
74
|
+
circuitInputs.signature = signature;
|
|
75
|
+
circuitInputs.challenge = params.challenge;
|
|
76
|
+
const query = circuitQueries[0];
|
|
77
|
+
query.operator = query.operator === Operators.SD ? Operators.EQ : query.operator;
|
|
78
|
+
circuitInputs.query = query;
|
|
79
|
+
circuitInputs.claim = {
|
|
80
|
+
issuerID: circuitClaimData.issuerId,
|
|
81
|
+
claim: circuitClaimData.claim,
|
|
82
|
+
incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState },
|
|
83
|
+
nonRevProof: circuitClaimData.nonRevProof
|
|
84
|
+
};
|
|
85
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
86
|
+
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
87
|
+
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
88
|
+
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
89
|
+
return circuitInputs.inputsMarshal();
|
|
90
|
+
};
|
|
91
|
+
this.credentialAtomicQuerySigV2PrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
|
|
92
|
+
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
93
|
+
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
94
|
+
const circuitInputs = new AtomicQuerySigV2Inputs();
|
|
95
|
+
circuitInputs.id = DID.idFromDID(identifier);
|
|
96
|
+
circuitInputs.claim = {
|
|
97
|
+
issuerID: circuitClaimData?.issuerId,
|
|
98
|
+
signatureProof: circuitClaimData.signatureProof,
|
|
99
|
+
claim: circuitClaimData.claim,
|
|
100
|
+
nonRevProof: circuitClaimData.nonRevProof
|
|
101
|
+
};
|
|
102
|
+
circuitInputs.requestID = BigInt(proofReq.id);
|
|
103
|
+
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
104
|
+
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
105
|
+
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
106
|
+
const query = circuitQueries[0];
|
|
107
|
+
query.operator = query.operator === Operators.SD ? Operators.EQ : query.operator;
|
|
108
|
+
circuitInputs.query = query;
|
|
109
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
110
|
+
return circuitInputs.inputsMarshal();
|
|
111
|
+
};
|
|
112
|
+
this.credentialAtomicQuerySigV2OnChainPrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
|
|
113
|
+
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
114
|
+
const authInfo = await this.prepareAuthBJJCredential(identifier);
|
|
115
|
+
const authClaimData = await this.newCircuitClaimData({
|
|
116
|
+
credential: authInfo.credential,
|
|
117
|
+
credentialCoreClaim: authInfo.coreClaim
|
|
118
|
+
});
|
|
119
|
+
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
120
|
+
const circuitInputs = new AtomicQuerySigV2OnChainInputs();
|
|
121
|
+
const id = DID.idFromDID(identifier);
|
|
122
|
+
circuitInputs.id = id;
|
|
123
|
+
circuitInputs.claim = {
|
|
124
|
+
issuerID: circuitClaimData.issuerId,
|
|
125
|
+
signatureProof: circuitClaimData.signatureProof,
|
|
126
|
+
claim: circuitClaimData.claim,
|
|
127
|
+
nonRevProof: circuitClaimData.nonRevProof
|
|
128
|
+
};
|
|
129
|
+
circuitInputs.requestID = BigInt(proofReq.id);
|
|
130
|
+
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
131
|
+
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
132
|
+
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
133
|
+
const query = circuitQueries[0];
|
|
134
|
+
query.operator = query.operator === Operators.SD ? Operators.EQ : query.operator;
|
|
135
|
+
circuitInputs.query = query;
|
|
136
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
137
|
+
if (authClaimData.treeState) {
|
|
138
|
+
circuitInputs.treeState = {
|
|
139
|
+
state: authClaimData.treeState?.state,
|
|
140
|
+
claimsRoot: authClaimData.treeState?.claimsRoot,
|
|
141
|
+
revocationRoot: authClaimData.treeState?.revocationRoot,
|
|
142
|
+
rootOfRoots: authClaimData.treeState?.rootOfRoots
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
|
|
146
|
+
const gistProof = toGISTProof(stateProof);
|
|
147
|
+
circuitInputs.gistProof = gistProof;
|
|
148
|
+
circuitInputs.authClaim = authClaimData.claim;
|
|
149
|
+
circuitInputs.authClaimIncMtp = authClaimData.proof;
|
|
150
|
+
circuitInputs.authClaimNonRevMtp = authInfo.nonRevProof.proof;
|
|
151
|
+
if (!params.challenge) {
|
|
152
|
+
throw new Error('challenge must be provided for onchain circuits');
|
|
153
|
+
}
|
|
154
|
+
const signature = await this._identityWallet.signChallenge(params.challenge, authInfo.credential);
|
|
155
|
+
circuitInputs.signature = signature;
|
|
156
|
+
circuitInputs.challenge = params.challenge;
|
|
157
|
+
return circuitInputs.inputsMarshal();
|
|
158
|
+
};
|
|
159
|
+
this.credentialAtomicQueryV3PrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
|
|
160
|
+
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
161
|
+
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
162
|
+
let proofType;
|
|
163
|
+
switch (proofReq.query.proofType) {
|
|
164
|
+
case ProofType.BJJSignature:
|
|
165
|
+
proofType = ProofType.BJJSignature;
|
|
166
|
+
break;
|
|
167
|
+
case ProofType.Iden3SparseMerkleTreeProof:
|
|
168
|
+
proofType = ProofType.Iden3SparseMerkleTreeProof;
|
|
169
|
+
break;
|
|
170
|
+
default:
|
|
171
|
+
if (circuitClaimData.proof) {
|
|
172
|
+
proofType = ProofType.Iden3SparseMerkleTreeProof;
|
|
173
|
+
}
|
|
174
|
+
else if (circuitClaimData.signatureProof) {
|
|
175
|
+
proofType = ProofType.BJJSignature;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
throw Error('claim has no MTP or signature proof');
|
|
179
|
+
}
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
const circuitInputs = new AtomicQueryV3Inputs();
|
|
183
|
+
circuitInputs.id = DID.idFromDID(identifier);
|
|
184
|
+
circuitInputs.claim = {
|
|
185
|
+
issuerID: circuitClaimData?.issuerId,
|
|
186
|
+
signatureProof: circuitClaimData.signatureProof,
|
|
187
|
+
claim: circuitClaimData.claim,
|
|
188
|
+
nonRevProof: circuitClaimData.nonRevProof,
|
|
189
|
+
incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState }
|
|
190
|
+
};
|
|
191
|
+
circuitInputs.requestID = BigInt(proofReq.id);
|
|
192
|
+
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
193
|
+
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
194
|
+
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
195
|
+
const query = circuitQueries[0];
|
|
196
|
+
query.values = query.operator === Operators.SD ? new Array(64).fill(0) : query.values;
|
|
197
|
+
circuitInputs.query = query;
|
|
198
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
199
|
+
circuitInputs.proofType = proofType;
|
|
200
|
+
circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
|
|
201
|
+
circuitInputs.verifierID = params.verifierDid ? DID.idFromDID(params.verifierDid) : undefined;
|
|
202
|
+
circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionId
|
|
203
|
+
? BigInt(proofReq.params?.nullifierSessionId?.toString())
|
|
204
|
+
: BigInt(0);
|
|
205
|
+
return circuitInputs.inputsMarshal();
|
|
206
|
+
};
|
|
207
|
+
this.credentialAtomicQueryV3OnChainPrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
|
|
208
|
+
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
209
|
+
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
210
|
+
let proofType;
|
|
211
|
+
switch (proofReq.query.proofType) {
|
|
212
|
+
case ProofType.BJJSignature:
|
|
213
|
+
proofType = ProofType.BJJSignature;
|
|
214
|
+
break;
|
|
215
|
+
case ProofType.Iden3SparseMerkleTreeProof:
|
|
216
|
+
proofType = ProofType.Iden3SparseMerkleTreeProof;
|
|
217
|
+
break;
|
|
218
|
+
default:
|
|
219
|
+
if (circuitClaimData.proof) {
|
|
220
|
+
proofType = ProofType.Iden3SparseMerkleTreeProof;
|
|
221
|
+
}
|
|
222
|
+
else if (circuitClaimData.signatureProof) {
|
|
223
|
+
proofType = ProofType.BJJSignature;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
throw Error('claim has no MTP or signature proof');
|
|
227
|
+
}
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
const circuitInputs = new AtomicQueryV3OnChainInputs();
|
|
231
|
+
circuitInputs.id = DID.idFromDID(identifier);
|
|
232
|
+
circuitInputs.claim = {
|
|
233
|
+
issuerID: circuitClaimData?.issuerId,
|
|
234
|
+
signatureProof: circuitClaimData.signatureProof,
|
|
235
|
+
claim: circuitClaimData.claim,
|
|
236
|
+
nonRevProof: circuitClaimData.nonRevProof,
|
|
237
|
+
incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState }
|
|
238
|
+
};
|
|
239
|
+
circuitInputs.requestID = BigInt(proofReq.id);
|
|
240
|
+
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
241
|
+
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
242
|
+
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
243
|
+
const query = circuitQueries[0];
|
|
244
|
+
query.values = query.operator === Operators.SD ? new Array(64).fill(0) : query.values;
|
|
245
|
+
circuitInputs.query = query;
|
|
246
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
|
|
247
|
+
circuitInputs.proofType = proofType;
|
|
248
|
+
circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
|
|
249
|
+
circuitInputs.verifierID = params.verifierDid ? DID.idFromDID(params.verifierDid) : undefined;
|
|
250
|
+
circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionID
|
|
251
|
+
? BigInt(proofReq.params?.nullifierSessionID?.toString())
|
|
252
|
+
: BigInt(0);
|
|
253
|
+
let isEthIdentity = true;
|
|
254
|
+
try {
|
|
255
|
+
Id.ethAddressFromId(circuitInputs.id);
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
isEthIdentity = false;
|
|
259
|
+
}
|
|
260
|
+
circuitInputs.authEnabled = isEthIdentity ? 0 : 1;
|
|
261
|
+
circuitInputs.challenge = BigInt(params.challenge ?? 0);
|
|
262
|
+
const { nonce: authProfileNonce, genesisDID } = await this._identityWallet.getGenesisDIDMetadata(identifier);
|
|
263
|
+
const id = DID.idFromDID(genesisDID);
|
|
264
|
+
const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
|
|
265
|
+
const gistProof = toGISTProof(stateProof);
|
|
266
|
+
circuitInputs.gistProof = gistProof;
|
|
267
|
+
// auth inputs
|
|
268
|
+
if (circuitInputs.authEnabled === 1) {
|
|
269
|
+
const authPrepared = await this.prepareAuthBJJCredential(genesisDID);
|
|
270
|
+
const authClaimData = await this.newCircuitClaimData({
|
|
271
|
+
credential: authPrepared.credential,
|
|
272
|
+
credentialCoreClaim: authPrepared.coreClaim
|
|
273
|
+
});
|
|
274
|
+
const signature = await this._identityWallet.signChallenge(circuitInputs.challenge, authPrepared.credential);
|
|
275
|
+
circuitInputs.profileNonce = BigInt(authProfileNonce);
|
|
276
|
+
circuitInputs.authClaim = authClaimData.claim;
|
|
277
|
+
circuitInputs.authClaimIncMtp = authClaimData.proof;
|
|
278
|
+
circuitInputs.authClaimNonRevMtp = authPrepared.nonRevProof.proof;
|
|
279
|
+
circuitInputs.treeState = authClaimData.treeState;
|
|
280
|
+
circuitInputs.signature = signature;
|
|
281
|
+
}
|
|
282
|
+
return circuitInputs.inputsMarshal();
|
|
283
|
+
};
|
|
284
|
+
this.linkedNullifierPrepareInputs = async ({ preparedCredential, identifier, proofReq, params }) => {
|
|
285
|
+
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
286
|
+
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
287
|
+
const circuitInputs = new LinkedNullifierInputs();
|
|
288
|
+
circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
|
|
289
|
+
circuitInputs.issuerClaim = circuitClaimData.claim;
|
|
290
|
+
circuitInputs.id = DID.idFromDID(identifier);
|
|
291
|
+
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
292
|
+
circuitInputs.verifierID = params.verifierDid ? DID.idFromDID(params.verifierDid) : undefined;
|
|
293
|
+
circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionID
|
|
294
|
+
? BigInt(proofReq.params?.nullifierSessionID?.toString())
|
|
295
|
+
: BigInt(0);
|
|
296
|
+
return circuitInputs.inputsMarshal();
|
|
297
|
+
};
|
|
298
|
+
this.linkedMultiQuery10PrepareInputs = async ({ preparedCredential, proofReq, params, circuitQueries }) => {
|
|
299
|
+
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
300
|
+
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
301
|
+
const circuitInputs = new LinkedMultiQueryInputs();
|
|
302
|
+
circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
|
|
303
|
+
circuitInputs.claim = circuitClaimData.claim;
|
|
304
|
+
circuitInputs.query = circuitQueries;
|
|
305
|
+
circuitInputs.queryLength = circuitValidator[proofReq.circuitId].maxQueriesCount;
|
|
306
|
+
return circuitInputs.inputsMarshal();
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
async generateInputs(ctx) {
|
|
310
|
+
const { circuitId } = ctx.proofReq;
|
|
311
|
+
const fnName = `${circuitId.split('-')[0]}PrepareInputs`;
|
|
312
|
+
const queriesLength = ctx.circuitQueries.length;
|
|
313
|
+
if (queriesLength > circuitValidator[circuitId].maxQueriesCount) {
|
|
314
|
+
throw new Error(`circuit ${circuitId} supports only ${circuitValidator[circuitId].maxQueriesCount} queries`);
|
|
315
|
+
}
|
|
316
|
+
const fn = this[fnName];
|
|
317
|
+
if (!fn) {
|
|
318
|
+
throw new Error(`inputs generator for ${circuitId} not found`);
|
|
319
|
+
}
|
|
320
|
+
return fn(ctx);
|
|
321
|
+
}
|
|
322
|
+
async newCircuitClaimData(preparedCredential) {
|
|
323
|
+
const smtProof = preparedCredential.credential.getIden3SparseMerkleTreeProof();
|
|
324
|
+
const circuitClaim = new CircuitClaim();
|
|
325
|
+
circuitClaim.claim = preparedCredential.credentialCoreClaim;
|
|
326
|
+
circuitClaim.issuerId = DID.idFromDID(DID.parse(preparedCredential.credential.issuer));
|
|
327
|
+
if (smtProof) {
|
|
328
|
+
circuitClaim.proof = smtProof.mtp;
|
|
329
|
+
circuitClaim.treeState = {
|
|
330
|
+
state: smtProof.issuerData.state.value,
|
|
331
|
+
claimsRoot: smtProof.issuerData.state.claimsTreeRoot,
|
|
332
|
+
revocationRoot: smtProof.issuerData.state.revocationTreeRoot,
|
|
333
|
+
rootOfRoots: smtProof.issuerData.state.rootOfRoots
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
const sigProof = preparedCredential.credential.getBJJSignature2021Proof();
|
|
337
|
+
if (sigProof) {
|
|
338
|
+
const issuerDID = sigProof.issuerData.id;
|
|
339
|
+
const userDID = getUserDIDFromCredential(issuerDID, preparedCredential.credential);
|
|
340
|
+
const { credentialStatus, mtp, authCoreClaim } = sigProof.issuerData;
|
|
341
|
+
if (!credentialStatus) {
|
|
342
|
+
throw new Error("can't check the validity of issuer auth claim: no credential status in proof");
|
|
343
|
+
}
|
|
344
|
+
if (!mtp) {
|
|
345
|
+
throw new Error('issuer auth credential must have a mtp proof');
|
|
346
|
+
}
|
|
347
|
+
if (!authCoreClaim) {
|
|
348
|
+
throw new Error('issuer auth credential must have a core claim proof');
|
|
349
|
+
}
|
|
350
|
+
const opts = {
|
|
351
|
+
issuerGenesisState: sigProof.issuerData.state,
|
|
352
|
+
issuerDID,
|
|
353
|
+
userDID
|
|
354
|
+
};
|
|
355
|
+
const rs = await this._credentialWallet.getRevocationStatus(credentialStatus, opts);
|
|
356
|
+
const issuerAuthNonRevProof = toClaimNonRevStatus(rs);
|
|
357
|
+
circuitClaim.signatureProof = {
|
|
358
|
+
signature: sigProof.signature,
|
|
359
|
+
issuerAuthIncProof: {
|
|
360
|
+
proof: sigProof.issuerData.mtp,
|
|
361
|
+
treeState: {
|
|
362
|
+
state: sigProof.issuerData.state.value,
|
|
363
|
+
claimsRoot: sigProof.issuerData.state.claimsTreeRoot,
|
|
364
|
+
revocationRoot: sigProof.issuerData.state.revocationTreeRoot,
|
|
365
|
+
rootOfRoots: sigProof.issuerData.state.rootOfRoots
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
issuerAuthClaim: sigProof.issuerData.authCoreClaim,
|
|
369
|
+
issuerAuthNonRevProof
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
return circuitClaim;
|
|
373
|
+
}
|
|
374
|
+
async prepareAuthBJJCredential(did, treeStateInfo) {
|
|
375
|
+
const authCredential = await this._credentialWallet.getAuthBJJCredential(did);
|
|
376
|
+
const incProof = await this._identityWallet.generateCredentialMtp(did, authCredential, treeStateInfo);
|
|
377
|
+
const nonRevProof = await this._identityWallet.generateNonRevocationMtp(did, authCredential, treeStateInfo);
|
|
378
|
+
const authCoreClaim = authCredential.getCoreClaimFromProof(ProofType.Iden3SparseMerkleTreeProof);
|
|
379
|
+
if (!authCoreClaim) {
|
|
380
|
+
throw new Error('auth core claim is not defined for auth bjj credential');
|
|
381
|
+
}
|
|
382
|
+
return {
|
|
383
|
+
credential: authCredential,
|
|
384
|
+
incProof,
|
|
385
|
+
nonRevProof,
|
|
386
|
+
coreClaim: authCoreClaim
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
}
|