@0xpolygonid/js-sdk 1.23.0 → 1.24.1
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 +3103 -358
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +3106 -356
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/credentials/credential-wallet.js +11 -78
- package/dist/node/cjs/credentials/index.js +1 -0
- package/dist/node/cjs/credentials/status/did-resolver-revocation.js +21 -0
- package/dist/node/cjs/iden3comm/handlers/fetch.js +32 -0
- package/dist/node/cjs/iden3comm/handlers/payment.js +38 -13
- package/dist/node/cjs/storage/blockchain/abi/ERC20.json +1 -0
- package/dist/node/cjs/storage/blockchain/did-resolver-readonly-storage.js +72 -0
- package/dist/node/cjs/storage/blockchain/{erc20-permit-sig.js → erc20-helper.js} +14 -1
- package/dist/node/cjs/storage/blockchain/index.js +3 -1
- package/dist/node/cjs/storage/blockchain/onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter.js +245 -0
- package/dist/node/cjs/storage/blockchain/onchain-issuer.js +82 -0
- package/dist/node/cjs/storage/blockchain/onchain-zkp-verifier.js +38 -34
- package/dist/node/cjs/storage/interfaces/index.js +1 -0
- package/dist/node/cjs/storage/interfaces/onchain-issuer.js +2 -0
- package/dist/node/cjs/utils/did-helper.js +3 -3
- package/dist/node/cjs/verifiable/constants.js +1 -0
- package/dist/node/cjs/verifiable/credential.js +86 -0
- package/dist/node/esm/credentials/credential-wallet.js +12 -79
- package/dist/node/esm/credentials/index.js +1 -0
- package/dist/node/esm/credentials/status/did-resolver-revocation.js +17 -0
- package/dist/node/esm/iden3comm/handlers/fetch.js +32 -0
- package/dist/node/esm/iden3comm/handlers/payment.js +38 -14
- package/dist/node/esm/storage/blockchain/abi/ERC20.json +1 -0
- package/dist/node/esm/storage/blockchain/did-resolver-readonly-storage.js +68 -0
- package/dist/node/esm/storage/blockchain/{erc20-permit-sig.js → erc20-helper.js} +14 -2
- package/dist/node/esm/storage/blockchain/index.js +3 -1
- package/dist/node/esm/storage/blockchain/onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter.js +241 -0
- package/dist/node/esm/storage/blockchain/onchain-issuer.js +78 -0
- package/dist/node/esm/storage/blockchain/onchain-zkp-verifier.js +38 -34
- package/dist/node/esm/storage/interfaces/index.js +1 -0
- package/dist/node/esm/storage/interfaces/onchain-issuer.js +1 -0
- package/dist/node/esm/utils/did-helper.js +3 -3
- package/dist/node/esm/verifiable/constants.js +1 -0
- package/dist/node/esm/verifiable/credential.js +88 -2
- package/dist/types/credentials/credential-wallet.d.ts +0 -6
- package/dist/types/credentials/index.d.ts +1 -0
- package/dist/types/credentials/models.d.ts +8 -0
- package/dist/types/credentials/status/did-resolver-revocation.d.ts +7 -0
- package/dist/types/iden3comm/handlers/fetch.d.ts +8 -0
- package/dist/types/iden3comm/handlers/payment.d.ts +3 -2
- package/dist/types/storage/blockchain/did-resolver-readonly-storage.d.ts +16 -0
- package/dist/types/storage/blockchain/{erc20-permit-sig.d.ts → erc20-helper.d.ts} +8 -1
- package/dist/types/storage/blockchain/index.d.ts +3 -1
- package/dist/types/storage/blockchain/onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter.d.ts +66 -0
- package/dist/types/storage/blockchain/onchain-issuer.d.ts +40 -0
- package/dist/types/storage/blockchain/onchain-zkp-verifier.d.ts +11 -12
- package/dist/types/storage/entities/state.d.ts +2 -0
- package/dist/types/storage/interfaces/index.d.ts +1 -0
- package/dist/types/storage/interfaces/onchain-issuer.d.ts +12 -0
- package/dist/types/verifiable/constants.d.ts +1 -0
- package/dist/types/verifiable/credential.d.ts +15 -2
- package/package.json +3 -2
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { DID, Id, chainIDfromDID } from '@iden3/js-iden3-core';
|
|
2
|
+
import { Contract, ethers } from 'ethers';
|
|
3
|
+
import { INonMerklizedIssuerABI as abi } from '@iden3/onchain-non-merklized-issuer-base-abi';
|
|
4
|
+
import { OnchainNonMerklizedIssuerAdapter } from './onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter';
|
|
5
|
+
/**
|
|
6
|
+
* Represents an adapter for interacting with on-chain issuers.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
* @beta
|
|
10
|
+
* @class OnchainIssuer
|
|
11
|
+
*/
|
|
12
|
+
export class OnchainIssuer {
|
|
13
|
+
/**
|
|
14
|
+
* Initializes an instance of `Adapter`.
|
|
15
|
+
* @param config The configuration for the Ethereum connection.
|
|
16
|
+
* @param merklizationOptions Optional settings for merklization.
|
|
17
|
+
*/
|
|
18
|
+
constructor(config, options) {
|
|
19
|
+
this._ethConnectionConfig = config;
|
|
20
|
+
this._onchainIssuerOptions = options;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves a credential from the on-chain issuer.
|
|
24
|
+
* @param issuerDID The issuer's core.DID.
|
|
25
|
+
* @param userId The user's core.Id.
|
|
26
|
+
* @param credentialId The unique identifier of the credential.
|
|
27
|
+
*/
|
|
28
|
+
async getCredential(issuerDID, userDID, credentialId) {
|
|
29
|
+
const { contract, connection } = this.getContractConnection(issuerDID);
|
|
30
|
+
const response = await contract.getCredentialAdapterVersion();
|
|
31
|
+
switch (response) {
|
|
32
|
+
case '0.0.1': {
|
|
33
|
+
const adapter = new OnchainNonMerklizedIssuerAdapter(connection, issuerDID, {
|
|
34
|
+
merklizationOptions: this._onchainIssuerOptions?.merklizationOptions
|
|
35
|
+
});
|
|
36
|
+
await adapter.isInterfaceSupported();
|
|
37
|
+
const { credentialData, coreClaimBigInts, credentialSubjectFields } = await adapter.getCredential(DID.idFromDID(userDID), credentialId);
|
|
38
|
+
return await adapter.convertOnChainInfoToW3CCredential(credentialData, coreClaimBigInts, credentialSubjectFields);
|
|
39
|
+
}
|
|
40
|
+
default:
|
|
41
|
+
throw new Error(`Unsupported adapter version ${response}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Retrieves the credential identifiers for a user from the on-chain issuer.
|
|
46
|
+
* @param issuerDID The issuer's core.DID.
|
|
47
|
+
* @param userId The user's core.Id.
|
|
48
|
+
*/
|
|
49
|
+
async getUserCredentialIds(issuerDID, userDID) {
|
|
50
|
+
const { contract, connection } = this.getContractConnection(issuerDID);
|
|
51
|
+
const response = await contract.getCredentialAdapterVersion();
|
|
52
|
+
switch (response) {
|
|
53
|
+
case '0.0.1': {
|
|
54
|
+
const adapter = new OnchainNonMerklizedIssuerAdapter(connection, issuerDID, {
|
|
55
|
+
merklizationOptions: this._onchainIssuerOptions?.merklizationOptions
|
|
56
|
+
});
|
|
57
|
+
await adapter.isInterfaceSupported();
|
|
58
|
+
return await adapter.getUserCredentialsIds(DID.idFromDID(userDID));
|
|
59
|
+
}
|
|
60
|
+
default:
|
|
61
|
+
throw new Error(`Unsupported adapter version ${response}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
getContractConnection(did) {
|
|
65
|
+
const issuerId = DID.idFromDID(did);
|
|
66
|
+
const chainId = chainIDfromDID(did);
|
|
67
|
+
const contractAddress = ethers.getAddress(ethers.hexlify(Id.ethAddressFromId(issuerId)));
|
|
68
|
+
const connection = this._ethConnectionConfig.find((c) => c.chainId === chainId);
|
|
69
|
+
if (!connection) {
|
|
70
|
+
throw new Error(`No connection found for chain ID ${chainId}`);
|
|
71
|
+
}
|
|
72
|
+
if (!connection.url) {
|
|
73
|
+
throw new Error(`No URL found for chain ID ${chainId}`);
|
|
74
|
+
}
|
|
75
|
+
const contract = new Contract(contractAddress, abi, new ethers.JsonRpcProvider(connection.url));
|
|
76
|
+
return { contract, connection };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -37,23 +37,8 @@ export class OnChainZKPVerifier {
|
|
|
37
37
|
constructor(_configs, _opts) {
|
|
38
38
|
this._configs = _configs;
|
|
39
39
|
this._opts = _opts;
|
|
40
|
-
/**
|
|
41
|
-
* supported circuits
|
|
42
|
-
*/
|
|
43
|
-
this._supportedCircuits = [
|
|
44
|
-
CircuitId.AtomicQueryMTPV2OnChain,
|
|
45
|
-
CircuitId.AtomicQuerySigV2OnChain,
|
|
46
|
-
CircuitId.AtomicQueryV3OnChain
|
|
47
|
-
];
|
|
48
|
-
/**
|
|
49
|
-
* abi coder to encode/decode structures to solidity bytes
|
|
50
|
-
*/
|
|
51
|
-
this._abiCoder = new ethers.AbiCoder();
|
|
52
40
|
}
|
|
53
|
-
|
|
54
|
-
* {@inheritDoc IOnChainZKPVerifier.prepareTxArgsSubmitV1}
|
|
55
|
-
*/
|
|
56
|
-
async prepareTxArgsSubmitV1(txData, zkProofResponse) {
|
|
41
|
+
static async prepareTxArgsSubmitV1(txData, zkProofResponse) {
|
|
57
42
|
if (txData.method_id.replace('0x', '') !== FunctionSignatures.SubmitZKPResponseV1) {
|
|
58
43
|
throw new Error(`prepareTxArgsSubmitV1 function doesn't implement requested method id. Only '0x${FunctionSignatures.SubmitZKPResponseV1}' is supported.`);
|
|
59
44
|
}
|
|
@@ -71,6 +56,12 @@ export class OnChainZKPVerifier {
|
|
|
71
56
|
];
|
|
72
57
|
return payload;
|
|
73
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* {@inheritDoc IOnChainZKPVerifier.prepareTxArgsSubmitV1}
|
|
61
|
+
*/
|
|
62
|
+
async prepareTxArgsSubmitV1(txData, zkProofResponse) {
|
|
63
|
+
return OnChainZKPVerifier.prepareTxArgsSubmitV1(txData, zkProofResponse);
|
|
64
|
+
}
|
|
74
65
|
/**
|
|
75
66
|
* {@inheritDoc IOnChainZKPVerifier.submitZKPResponse}
|
|
76
67
|
*/
|
|
@@ -160,13 +151,10 @@ export class OnChainZKPVerifier {
|
|
|
160
151
|
const { txnHash } = await transactionService.sendTransactionRequest(ethSigner, request);
|
|
161
152
|
return new Map().set(txnHash, zkProofResponses);
|
|
162
153
|
}
|
|
163
|
-
async prepareTxArgsSubmitV2(txData, zkProofResponses) {
|
|
154
|
+
static async prepareTxArgsSubmitV2(resolverUrl, txData, zkProofResponses) {
|
|
164
155
|
if (txData.method_id.replace('0x', '') !== FunctionSignatures.SubmitZKPResponseV2) {
|
|
165
156
|
throw new Error(`submit cross chain doesn't implement requested method id. Only '0x${FunctionSignatures.SubmitZKPResponseV2}' is supported.`);
|
|
166
157
|
}
|
|
167
|
-
if (!this._opts?.didResolverUrl) {
|
|
168
|
-
throw new Error(`did resolver url required for crosschain verification`);
|
|
169
|
-
}
|
|
170
158
|
const gistUpdateArr = [];
|
|
171
159
|
const stateUpdateArr = [];
|
|
172
160
|
const payload = [];
|
|
@@ -191,7 +179,9 @@ export class OnChainZKPVerifier {
|
|
|
191
179
|
continue;
|
|
192
180
|
}
|
|
193
181
|
gistUpdateResolutionsPending.push(JSON.stringify(gist));
|
|
194
|
-
gistUpdateResolutions.push(this.resolveDidDocumentEip712MessageAndSignature(DID.parseFromId(gist.id),
|
|
182
|
+
gistUpdateResolutions.push(this.resolveDidDocumentEip712MessageAndSignature(DID.parseFromId(gist.id), resolverUrl, {
|
|
183
|
+
gist: gist.root
|
|
184
|
+
}));
|
|
195
185
|
}
|
|
196
186
|
const stateUpdateResolutions = [];
|
|
197
187
|
for (const state of stateInfo.states) {
|
|
@@ -200,7 +190,7 @@ export class OnChainZKPVerifier {
|
|
|
200
190
|
continue;
|
|
201
191
|
}
|
|
202
192
|
stateUpdateResolutionsPending.push(JSON.stringify(state));
|
|
203
|
-
stateUpdateResolutions.push(this.resolveDidDocumentEip712MessageAndSignature(DID.parseFromId(state.id),
|
|
193
|
+
stateUpdateResolutions.push(this.resolveDidDocumentEip712MessageAndSignature(DID.parseFromId(state.id), resolverUrl, {
|
|
204
194
|
state: state.state
|
|
205
195
|
}));
|
|
206
196
|
}
|
|
@@ -234,10 +224,16 @@ export class OnChainZKPVerifier {
|
|
|
234
224
|
const crossChainProofs = this.packCrossChainProofs(gistUpdateArr, stateUpdateArr);
|
|
235
225
|
return [payload, crossChainProofs];
|
|
236
226
|
}
|
|
237
|
-
|
|
238
|
-
|
|
227
|
+
async prepareTxArgsSubmitV2(txData, zkProofResponses) {
|
|
228
|
+
if (!this._opts?.didResolverUrl) {
|
|
229
|
+
throw new Error(`did resolver url required for crosschain verification`);
|
|
230
|
+
}
|
|
231
|
+
return OnChainZKPVerifier.prepareTxArgsSubmitV2(this._opts.didResolverUrl, txData, zkProofResponses);
|
|
232
|
+
}
|
|
233
|
+
static packZkpProof(inputs, a, b, c) {
|
|
234
|
+
return new ethers.AbiCoder().encode(['uint256[] inputs', 'uint256[2]', 'uint256[2][2]', 'uint256[2]'], [inputs, a, b, c]);
|
|
239
235
|
}
|
|
240
|
-
packCrossChainProofs(gistUpdateArr, stateUpdateArr) {
|
|
236
|
+
static packCrossChainProofs(gistUpdateArr, stateUpdateArr) {
|
|
241
237
|
const proofs = [];
|
|
242
238
|
for (const globalStateUpdate of gistUpdateArr) {
|
|
243
239
|
proofs.push({
|
|
@@ -251,10 +247,10 @@ export class OnChainZKPVerifier {
|
|
|
251
247
|
proof: this.packIdentityStateMsg(stateUpdate)
|
|
252
248
|
});
|
|
253
249
|
}
|
|
254
|
-
return
|
|
250
|
+
return new ethers.AbiCoder().encode(['tuple(' + 'string proofType,' + 'bytes proof' + ')[]'], [proofs]);
|
|
255
251
|
}
|
|
256
|
-
packGlobalStateMsg(msg) {
|
|
257
|
-
return
|
|
252
|
+
static packGlobalStateMsg(msg) {
|
|
253
|
+
return new ethers.AbiCoder().encode([
|
|
258
254
|
'tuple(' +
|
|
259
255
|
'tuple(' +
|
|
260
256
|
'uint256 timestamp,' +
|
|
@@ -266,8 +262,8 @@ export class OnChainZKPVerifier {
|
|
|
266
262
|
')'
|
|
267
263
|
], [msg]);
|
|
268
264
|
}
|
|
269
|
-
packIdentityStateMsg(msg) {
|
|
270
|
-
return
|
|
265
|
+
static packIdentityStateMsg(msg) {
|
|
266
|
+
return new ethers.AbiCoder().encode([
|
|
271
267
|
'tuple(' +
|
|
272
268
|
'tuple(' +
|
|
273
269
|
'uint256 timestamp,' +
|
|
@@ -279,10 +275,10 @@ export class OnChainZKPVerifier {
|
|
|
279
275
|
')'
|
|
280
276
|
], [msg]);
|
|
281
277
|
}
|
|
282
|
-
packMetadatas(metas) {
|
|
283
|
-
return
|
|
278
|
+
static packMetadatas(metas) {
|
|
279
|
+
return new ethers.AbiCoder().encode(['tuple(' + 'string key,' + 'bytes value' + ')[]'], [metas]);
|
|
284
280
|
}
|
|
285
|
-
getOnChainGistRootStatePubSignals(onChainCircuitId, inputs) {
|
|
281
|
+
static getOnChainGistRootStatePubSignals(onChainCircuitId, inputs) {
|
|
286
282
|
let atomicQueryPubSignals;
|
|
287
283
|
switch (onChainCircuitId) {
|
|
288
284
|
case CircuitId.AtomicQueryMTPV2OnChain:
|
|
@@ -299,7 +295,7 @@ export class OnChainZKPVerifier {
|
|
|
299
295
|
atomicQueryPubSignals.pubSignalsUnmarshal(encodedInputs);
|
|
300
296
|
return atomicQueryPubSignals.getStatesInfo();
|
|
301
297
|
}
|
|
302
|
-
async resolveDidDocumentEip712MessageAndSignature(did, resolverUrl, opts) {
|
|
298
|
+
static async resolveDidDocumentEip712MessageAndSignature(did, resolverUrl, opts) {
|
|
303
299
|
const didDoc = await resolveDidDocument(did, resolverUrl, {
|
|
304
300
|
...opts,
|
|
305
301
|
signature: DIDDocumentSignature.EthereumEip712Signature2021
|
|
@@ -332,3 +328,11 @@ export class OnChainZKPVerifier {
|
|
|
332
328
|
};
|
|
333
329
|
}
|
|
334
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* supported circuits
|
|
333
|
+
*/
|
|
334
|
+
OnChainZKPVerifier._supportedCircuits = [
|
|
335
|
+
CircuitId.AtomicQueryMTPV2OnChain,
|
|
336
|
+
CircuitId.AtomicQuerySigV2OnChain,
|
|
337
|
+
CircuitId.AtomicQueryV3OnChain
|
|
338
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -65,7 +65,7 @@ export const validateDIDDocumentAuth = async (did, resolverURL, state) => {
|
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
export const resolveDIDDocumentAuth = async (did, resolveURL, state) => {
|
|
68
|
-
let url = `${resolveURL}/${did.string()
|
|
68
|
+
let url = `${resolveURL}/${encodeURIComponent(did.string())}`;
|
|
69
69
|
if (state) {
|
|
70
70
|
url += `?state=${state.hex()}`;
|
|
71
71
|
}
|
|
@@ -81,11 +81,11 @@ function emptyStateDID(did) {
|
|
|
81
81
|
return emptyDID;
|
|
82
82
|
}
|
|
83
83
|
export const resolveDidDocument = async (did, resolverUrl, opts) => {
|
|
84
|
-
let didString = did.string()
|
|
84
|
+
let didString = encodeURIComponent(did.string());
|
|
85
85
|
// for gist resolve we have to `hide` user did (look into resolver implementation)
|
|
86
86
|
const isGistRequest = opts?.gist && !opts.state;
|
|
87
87
|
if (isGistRequest) {
|
|
88
|
-
didString = emptyStateDID(did).string();
|
|
88
|
+
didString = encodeURIComponent(emptyStateDID(did).string());
|
|
89
89
|
}
|
|
90
90
|
let url = `${resolverUrl}/1.0/identifiers/${didString}`;
|
|
91
91
|
if (opts?.signature) {
|
|
@@ -154,6 +154,7 @@ export var SupportedCurrencies;
|
|
|
154
154
|
SupportedCurrencies["ETH_WEI"] = "ETHWEI";
|
|
155
155
|
SupportedCurrencies["ETH_GWEI"] = "ETHGWEI";
|
|
156
156
|
SupportedCurrencies["MATIC"] = "MATIC";
|
|
157
|
+
SupportedCurrencies["POL"] = "POL";
|
|
157
158
|
SupportedCurrencies["USDT"] = "USDT";
|
|
158
159
|
SupportedCurrencies["USDC"] = "USDC";
|
|
159
160
|
})(SupportedCurrencies || (SupportedCurrencies = {}));
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { BJJSignatureProof2021, Iden3SparseMerkleTreeProof } from './proof';
|
|
3
|
-
import { Claim, DID, MerklizedRootPosition as MerklizedRootPositionCore, IdPosition, ClaimOptions } from '@iden3/js-iden3-core';
|
|
3
|
+
import { Claim, DID, MerklizedRootPosition as MerklizedRootPositionCore, IdPosition, ClaimOptions, getChainId } from '@iden3/js-iden3-core';
|
|
4
4
|
import { Hash, rootFromProof, verifyProof } from '@iden3/js-merkletree';
|
|
5
5
|
import { Merklizer } from '@iden3/js-jsonld-merklization';
|
|
6
6
|
import { PublicKey, poseidon } from '@iden3/js-crypto';
|
|
7
7
|
import { getUserDIDFromCredential } from '../credentials/utils';
|
|
8
8
|
import { byteEncoder, validateDIDDocumentAuth } from '../utils';
|
|
9
|
-
import { MerklizedRootPosition, ProofType, SubjectPosition } from './constants';
|
|
9
|
+
import { CredentialStatusType, MerklizedRootPosition, ProofType, SubjectPosition, VerifiableConstants } from './constants';
|
|
10
10
|
import { calculateCoreSchemaHash, findCredentialType, parseCoreClaimSlots } from './core-utils';
|
|
11
11
|
import * as jsonld from 'jsonld/lib';
|
|
12
12
|
import * as ldcontext from 'jsonld/lib/context';
|
|
@@ -25,6 +25,92 @@ export class W3CCredential {
|
|
|
25
25
|
this.credentialSubject = {};
|
|
26
26
|
this.issuer = '';
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @param issuer - DID of the issuer
|
|
31
|
+
* @param request - Credential request
|
|
32
|
+
* @returns - W3C Credential
|
|
33
|
+
*/
|
|
34
|
+
static fromCredentialRequest(issuer, request) {
|
|
35
|
+
if (!request.id) {
|
|
36
|
+
throw new Error('Credential id is required');
|
|
37
|
+
}
|
|
38
|
+
if (!request.context) {
|
|
39
|
+
throw new Error('Credential context is required');
|
|
40
|
+
}
|
|
41
|
+
const context = [
|
|
42
|
+
VerifiableConstants.JSONLD_SCHEMA.W3C_CREDENTIAL_2018,
|
|
43
|
+
VerifiableConstants.JSONLD_SCHEMA.IDEN3_CREDENTIAL,
|
|
44
|
+
...request.context
|
|
45
|
+
];
|
|
46
|
+
const credentialType = [
|
|
47
|
+
VerifiableConstants.CREDENTIAL_TYPE.W3C_VERIFIABLE_CREDENTIAL,
|
|
48
|
+
request.type
|
|
49
|
+
];
|
|
50
|
+
const credentialSubject = request.credentialSubject;
|
|
51
|
+
credentialSubject['type'] = request.type;
|
|
52
|
+
const cr = new W3CCredential();
|
|
53
|
+
cr.id = request.id;
|
|
54
|
+
cr['@context'] = context;
|
|
55
|
+
cr.type = credentialType;
|
|
56
|
+
cr.credentialSubject = credentialSubject;
|
|
57
|
+
cr.issuer = issuer.string();
|
|
58
|
+
cr.credentialSchema = {
|
|
59
|
+
id: request.credentialSchema,
|
|
60
|
+
type: VerifiableConstants.JSON_SCHEMA_VALIDATOR
|
|
61
|
+
};
|
|
62
|
+
cr.credentialStatus = W3CCredential.buildCredentialStatus(request, issuer);
|
|
63
|
+
request.expiration && (cr.expirationDate = new Date(request.expiration).toISOString());
|
|
64
|
+
request.refreshService && (cr.refreshService = request.refreshService);
|
|
65
|
+
request.displayMethod && (cr.displayMethod = request.displayMethod);
|
|
66
|
+
request.issuanceDate && (cr.issuanceDate = new Date(request.issuanceDate).toISOString());
|
|
67
|
+
return cr;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Builds credential status
|
|
71
|
+
* @param {CredentialRequest} request
|
|
72
|
+
* @returns `CredentialStatus`
|
|
73
|
+
*/
|
|
74
|
+
static buildCredentialStatus(request, issuer) {
|
|
75
|
+
const credentialStatus = {
|
|
76
|
+
id: request.revocationOpts.id,
|
|
77
|
+
type: request.revocationOpts.type,
|
|
78
|
+
revocationNonce: request.revocationOpts.nonce
|
|
79
|
+
};
|
|
80
|
+
switch (request.revocationOpts.type) {
|
|
81
|
+
case CredentialStatusType.SparseMerkleTreeProof:
|
|
82
|
+
return {
|
|
83
|
+
...credentialStatus,
|
|
84
|
+
id: `${credentialStatus.id.replace(/\/$/, '')}/${credentialStatus.revocationNonce}`
|
|
85
|
+
};
|
|
86
|
+
case CredentialStatusType.Iden3ReverseSparseMerkleTreeProof:
|
|
87
|
+
return {
|
|
88
|
+
...credentialStatus,
|
|
89
|
+
id: request.revocationOpts.issuerState
|
|
90
|
+
? `${credentialStatus.id.replace(/\/$/, '')}/node?state=${request.revocationOpts.issuerState}`
|
|
91
|
+
: `${credentialStatus.id.replace(/\/$/, '')}`
|
|
92
|
+
};
|
|
93
|
+
case CredentialStatusType.Iden3OnchainSparseMerkleTreeProof2023: {
|
|
94
|
+
const issuerId = DID.idFromDID(issuer);
|
|
95
|
+
const chainId = getChainId(DID.blockchainFromId(issuerId), DID.networkIdFromId(issuerId));
|
|
96
|
+
const searchParams = [
|
|
97
|
+
['revocationNonce', request.revocationOpts.nonce?.toString() || ''],
|
|
98
|
+
['contractAddress', `${chainId}:${request.revocationOpts.id}`],
|
|
99
|
+
['state', request.revocationOpts.issuerState || '']
|
|
100
|
+
]
|
|
101
|
+
.filter(([, value]) => Boolean(value))
|
|
102
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
103
|
+
.join('&');
|
|
104
|
+
return {
|
|
105
|
+
...credentialStatus,
|
|
106
|
+
// `[did]:[methodid]:[chain]:[network]:[id]/credentialStatus?(revocationNonce=value)&[contractAddress=[chainID]:[contractAddress]]&(state=issuerState)`
|
|
107
|
+
id: `${issuer.string()}/credentialStatus?${searchParams}`
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
default:
|
|
111
|
+
return credentialStatus;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
28
114
|
toJSON() {
|
|
29
115
|
return {
|
|
30
116
|
...this,
|
|
@@ -160,12 +160,6 @@ export declare class CredentialWallet implements ICredentialWallet {
|
|
|
160
160
|
* {@inheritDoc ICredentialWallet.createCredential}
|
|
161
161
|
*/
|
|
162
162
|
createCredential: (issuer: DID, request: CredentialRequest, schema: JSONSchema) => W3CCredential;
|
|
163
|
-
/**
|
|
164
|
-
* Builds credential status
|
|
165
|
-
* @param {CredentialRequest} request
|
|
166
|
-
* @returns `CredentialStatus`
|
|
167
|
-
*/
|
|
168
|
-
private buildCredentialStatus;
|
|
169
163
|
/**
|
|
170
164
|
* {@inheritDoc ICredentialWallet.findById}
|
|
171
165
|
*/
|
|
@@ -4,6 +4,7 @@ export * from './status/sparse-merkle-tree';
|
|
|
4
4
|
export * from './status/resolver';
|
|
5
5
|
export * from './status/agent-revocation';
|
|
6
6
|
export * from './status/credential-status-publisher';
|
|
7
|
+
export * from './status/did-resolver-revocation';
|
|
7
8
|
export * from './credential-wallet';
|
|
8
9
|
export * from './rhs';
|
|
9
10
|
export * from './utils';
|
|
@@ -15,6 +15,10 @@ export type PublishMode = 'sync' | 'async' | 'callback';
|
|
|
15
15
|
* @interface CredentialRequest
|
|
16
16
|
*/
|
|
17
17
|
export interface CredentialRequest {
|
|
18
|
+
/**
|
|
19
|
+
* Credential ID
|
|
20
|
+
*/
|
|
21
|
+
id?: string;
|
|
18
22
|
/**
|
|
19
23
|
* JSON credential schema
|
|
20
24
|
*/
|
|
@@ -55,6 +59,10 @@ export interface CredentialRequest {
|
|
|
55
59
|
* merklizedRootPosition (index / value / none)
|
|
56
60
|
*/
|
|
57
61
|
merklizedRootPosition?: MerklizedRootPosition;
|
|
62
|
+
/**
|
|
63
|
+
* issuance Date
|
|
64
|
+
*/
|
|
65
|
+
issuanceDate?: number;
|
|
58
66
|
/**
|
|
59
67
|
* Revocation options
|
|
60
68
|
*
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CredentialStatus, RevocationStatus } from '../../verifiable';
|
|
2
|
+
import { CredentialStatusResolveOptions, CredentialStatusResolver } from './resolver';
|
|
3
|
+
export declare class DidDocumentCredentialStatusResolver implements CredentialStatusResolver {
|
|
4
|
+
private readonly didResolverUrl;
|
|
5
|
+
constructor(didResolverUrl: string);
|
|
6
|
+
resolve(credentialStatus: CredentialStatus, opts?: CredentialStatusResolveOptions | undefined): Promise<RevocationStatus>;
|
|
7
|
+
}
|
|
@@ -3,6 +3,7 @@ import { BasicMessage, IPackageManager, JWSPackerParams } from '../types';
|
|
|
3
3
|
import { W3CCredential } from '../../verifiable';
|
|
4
4
|
import { ICredentialWallet } from '../../credentials';
|
|
5
5
|
import { AbstractMessageHandler, BasicHandlerOptions, IProtocolMessageHandler } from './message-handler';
|
|
6
|
+
import { IOnchainIssuer } from '../../storage';
|
|
6
7
|
/**
|
|
7
8
|
*
|
|
8
9
|
* Options to pass to fetch handler
|
|
@@ -91,8 +92,10 @@ export declare class FetchHandler extends AbstractMessageHandler implements IFet
|
|
|
91
92
|
*/
|
|
92
93
|
constructor(_packerMgr: IPackageManager, opts?: {
|
|
93
94
|
credentialWallet: ICredentialWallet;
|
|
95
|
+
onchainIssuer?: IOnchainIssuer | undefined;
|
|
94
96
|
} | undefined);
|
|
95
97
|
handle(message: BasicMessage, ctx: FetchMessageHandlerOptions): Promise<BasicMessage | null>;
|
|
98
|
+
private handleOnchainOfferMessage;
|
|
96
99
|
private handleOfferMessage;
|
|
97
100
|
/**
|
|
98
101
|
* Handles only messages with credentials/1.0/offer type
|
|
@@ -104,6 +107,11 @@ export declare class FetchHandler extends AbstractMessageHandler implements IFet
|
|
|
104
107
|
* @returns `Promise<W3CCredential[]>`
|
|
105
108
|
*/
|
|
106
109
|
handleCredentialOffer(offer: Uint8Array, opts?: FetchHandlerOptions): Promise<W3CCredential[]>;
|
|
110
|
+
/**
|
|
111
|
+
* Handles only messages with credentials/1.0/onchain-offer type
|
|
112
|
+
* @beta
|
|
113
|
+
*/
|
|
114
|
+
handleOnchainOffer(offer: Uint8Array): Promise<W3CCredential[]>;
|
|
107
115
|
private handleFetchRequest;
|
|
108
116
|
/**
|
|
109
117
|
* @inheritdoc IFetchHandler#handleCredentialFetchRequest
|
|
@@ -24,6 +24,7 @@ export type PaymentCreationOptions = {
|
|
|
24
24
|
*/
|
|
25
25
|
export declare function createPaymentRequest(sender: DID, receiver: DID, agent: string, payments: PaymentRequestInfo[], opts?: PaymentRequestCreationOptions): PaymentRequestMessage;
|
|
26
26
|
export declare function verifyEIP712TypedData(data: Iden3PaymentRailsRequestV1 | Iden3PaymentRailsERC20RequestV1, resolver: Resolvable): Promise<string>;
|
|
27
|
+
export declare function convertPaymentAmount(amount: string, currency: SupportedCurrencies): Promise<bigint>;
|
|
27
28
|
/**
|
|
28
29
|
* @beta
|
|
29
30
|
* PaymentRailsInfo represents payment info for payment rails
|
|
@@ -42,10 +43,10 @@ export type PaymentRailsInfo = {
|
|
|
42
43
|
*/
|
|
43
44
|
export type PaymentRailsChainInfo = {
|
|
44
45
|
nonce: bigint;
|
|
45
|
-
amount:
|
|
46
|
+
amount: string;
|
|
46
47
|
currency: SupportedCurrencies | string;
|
|
47
48
|
chainId: string;
|
|
48
|
-
expirationDate?:
|
|
49
|
+
expirationDate?: Date;
|
|
49
50
|
features?: PaymentFeatures[];
|
|
50
51
|
type: PaymentRequestDataType.Iden3PaymentRailsRequestV1 | PaymentRequestDataType.Iden3PaymentRailsERC20RequestV1;
|
|
51
52
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RootInfo, StateInfo, StateProof } from '../entities';
|
|
2
|
+
import { IStateStorage } from '../interfaces';
|
|
3
|
+
import { JsonRpcProvider } from 'ethers';
|
|
4
|
+
export declare class DidResolverStateReadonlyStorage implements IStateStorage {
|
|
5
|
+
private readonly resolverUrl;
|
|
6
|
+
constructor(resolverUrl: string);
|
|
7
|
+
getLatestStateById(id: bigint): Promise<StateInfo>;
|
|
8
|
+
getStateInfoByIdAndState(id: bigint, state: bigint): Promise<StateInfo>;
|
|
9
|
+
getGISTProof(id: bigint): Promise<StateProof>;
|
|
10
|
+
getGISTRootInfo(root: bigint, userId: bigint): Promise<RootInfo>;
|
|
11
|
+
getRpcProvider(): JsonRpcProvider;
|
|
12
|
+
publishState(): Promise<string>;
|
|
13
|
+
publishStateGeneric(): Promise<string>;
|
|
14
|
+
private getStateInfo;
|
|
15
|
+
private getIden3StateInfo2023;
|
|
16
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Signer } from 'ethers';
|
|
1
|
+
import { Signer, ethers } from 'ethers';
|
|
2
2
|
/**
|
|
3
3
|
* @beta
|
|
4
4
|
* getPermitSignature is a function to create EIP712 Permit signature
|
|
@@ -10,3 +10,10 @@ import { Signer } from 'ethers';
|
|
|
10
10
|
* @returns {Promise<PaymentRequestMessage>}
|
|
11
11
|
*/
|
|
12
12
|
export declare function getPermitSignature(signer: Signer, tokenAddress: string, spender: string, value: bigint, deadline: number): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* @beta
|
|
15
|
+
* getERC20Decimals is a function to retrieve the number of decimals of an ERC20 token
|
|
16
|
+
* @param {string} tokenAddress - Token address
|
|
17
|
+
* @param {ethers.ContractRunner} runner - Contract runner
|
|
18
|
+
*/
|
|
19
|
+
export declare function getERC20Decimals(tokenAddress: string, runner: ethers.ContractRunner): Promise<number>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { DID, Id } from '@iden3/js-iden3-core';
|
|
2
|
+
import { INonMerklizedIssuer } from '@iden3/onchain-non-merklized-issuer-base-abi';
|
|
3
|
+
import { W3CCredential } from '../../../../../../verifiable';
|
|
4
|
+
import { Options } from '@iden3/js-jsonld-merklization';
|
|
5
|
+
import { EthConnectionConfig } from '../../../../state';
|
|
6
|
+
/**
|
|
7
|
+
* `OnchainNonMerklizedIssuerAdapter` provides functionality to interact with a non-merklized on-chain credential issuer.
|
|
8
|
+
* This adapter enables interface detection, credential retrieval, and conversion to the W3C Verifiable Credential format.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
* @beta
|
|
12
|
+
* @class OnchainNonMerklizedIssuerAdapter
|
|
13
|
+
*/
|
|
14
|
+
export declare class OnchainNonMerklizedIssuerAdapter {
|
|
15
|
+
private readonly _contract;
|
|
16
|
+
private readonly _contractAddress;
|
|
17
|
+
private readonly _chainId;
|
|
18
|
+
private readonly _issuerDid;
|
|
19
|
+
private readonly _merklizationOptions?;
|
|
20
|
+
/**
|
|
21
|
+
* Initializes an instance of `OnchainNonMerklizedIssuerAdapter`.
|
|
22
|
+
*
|
|
23
|
+
* @param ethConnectionConfig The configuration for the Ethereum connection.
|
|
24
|
+
* @param issuerDid The decentralized identifier (DID) of the issuer.
|
|
25
|
+
* @param merklizationOptions Optional settings for merklization.
|
|
26
|
+
*/
|
|
27
|
+
constructor(ethConnectionConfig: EthConnectionConfig, issuerDid: DID, options?: {
|
|
28
|
+
merklizationOptions?: Options;
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* Checks if the contract supports required interfaces.
|
|
32
|
+
* Throws an error if any required interface is unsupported.
|
|
33
|
+
*
|
|
34
|
+
* @throws Error - If required interfaces are not supported.
|
|
35
|
+
*/
|
|
36
|
+
isInterfaceSupported(): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves a credential from the on-chain non-merklized contract.
|
|
39
|
+
* @param userId The user's core.Id.
|
|
40
|
+
* @param credentialId The unique identifier of the credential.
|
|
41
|
+
*/
|
|
42
|
+
getCredential(userId: Id, credentialId: bigint): Promise<{
|
|
43
|
+
credentialData: INonMerklizedIssuer.CredentialDataStructOutput;
|
|
44
|
+
coreClaimBigInts: bigint[];
|
|
45
|
+
credentialSubjectFields: INonMerklizedIssuer.SubjectFieldStructOutput[];
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves the credential IDs of a user.
|
|
49
|
+
* @param userId The user's core.Id.
|
|
50
|
+
* @returns An array of credential IDs.
|
|
51
|
+
*/
|
|
52
|
+
getUserCredentialsIds(userId: Id): Promise<bigint[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Converts on-chain credential to a verifiable credential.
|
|
55
|
+
*
|
|
56
|
+
* @param credentialData Data structure of the credential from the contract.
|
|
57
|
+
* @param coreClaimBigInts Claim data in bigint format.
|
|
58
|
+
* @param credentialSubjectFields Subject fields of the credential.
|
|
59
|
+
*/
|
|
60
|
+
convertOnChainInfoToW3CCredential(credentialData: INonMerklizedIssuer.CredentialDataStructOutput, coreClaimBigInts: bigint[], credentialSubjectFields: INonMerklizedIssuer.SubjectFieldStructOutput[]): Promise<W3CCredential>;
|
|
61
|
+
private credentialId;
|
|
62
|
+
private convertCredentialSubject;
|
|
63
|
+
private existenceProof;
|
|
64
|
+
private validateSourceValue;
|
|
65
|
+
private convertDisplayMethod;
|
|
66
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DID } from '@iden3/js-iden3-core';
|
|
2
|
+
import { Options } from '@iden3/js-jsonld-merklization';
|
|
3
|
+
import { W3CCredential } from '../../verifiable';
|
|
4
|
+
import { EthConnectionConfig } from './state';
|
|
5
|
+
import { IOnchainIssuer } from '../interfaces/onchain-issuer';
|
|
6
|
+
interface OnchainIssuerOptions {
|
|
7
|
+
merklizationOptions?: Options;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Represents an adapter for interacting with on-chain issuers.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
* @beta
|
|
14
|
+
* @class OnchainIssuer
|
|
15
|
+
*/
|
|
16
|
+
export declare class OnchainIssuer implements IOnchainIssuer {
|
|
17
|
+
private readonly _ethConnectionConfig;
|
|
18
|
+
private readonly _onchainIssuerOptions?;
|
|
19
|
+
/**
|
|
20
|
+
* Initializes an instance of `Adapter`.
|
|
21
|
+
* @param config The configuration for the Ethereum connection.
|
|
22
|
+
* @param merklizationOptions Optional settings for merklization.
|
|
23
|
+
*/
|
|
24
|
+
constructor(config: EthConnectionConfig[], options?: OnchainIssuerOptions);
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves a credential from the on-chain issuer.
|
|
27
|
+
* @param issuerDID The issuer's core.DID.
|
|
28
|
+
* @param userId The user's core.Id.
|
|
29
|
+
* @param credentialId The unique identifier of the credential.
|
|
30
|
+
*/
|
|
31
|
+
getCredential(issuerDID: DID, userDID: DID, credentialId: bigint): Promise<W3CCredential>;
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves the credential identifiers for a user from the on-chain issuer.
|
|
34
|
+
* @param issuerDID The issuer's core.DID.
|
|
35
|
+
* @param userId The user's core.Id.
|
|
36
|
+
*/
|
|
37
|
+
getUserCredentialIds(issuerDID: DID, userDID: DID): Promise<bigint[]>;
|
|
38
|
+
private getContractConnection;
|
|
39
|
+
}
|
|
40
|
+
export {};
|