@0xpolygonid/js-sdk 1.23.0 → 1.25.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.
Files changed (71) hide show
  1. package/dist/browser/esm/index.js +2573 -392
  2. package/dist/browser/esm/index.js.map +1 -1
  3. package/dist/browser/umd/index.js +2575 -390
  4. package/dist/browser/umd/index.js.map +1 -1
  5. package/dist/node/cjs/circuits/auth-v2.js +6 -0
  6. package/dist/node/cjs/credentials/credential-wallet.js +11 -78
  7. package/dist/node/cjs/credentials/index.js +1 -0
  8. package/dist/node/cjs/credentials/status/did-resolver-revocation.js +21 -0
  9. package/dist/node/cjs/iden3comm/handlers/contract-request.js +7 -1
  10. package/dist/node/cjs/iden3comm/handlers/fetch.js +32 -0
  11. package/dist/node/cjs/iden3comm/handlers/payment.js +30 -24
  12. package/dist/node/cjs/iden3comm/utils/contract-request.utils.js +59 -0
  13. package/dist/node/cjs/iden3comm/utils/index.js +1 -0
  14. package/dist/node/cjs/proof/proof-service.js +6 -0
  15. package/dist/node/cjs/storage/blockchain/abi/ERC20.json +1 -0
  16. package/dist/node/cjs/storage/blockchain/did-resolver-readonly-storage.js +72 -0
  17. package/dist/node/cjs/storage/blockchain/{erc20-permit-sig.js → erc20-helper.js} +14 -1
  18. package/dist/node/cjs/storage/blockchain/index.js +3 -1
  19. package/dist/node/cjs/storage/blockchain/onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter.js +245 -0
  20. package/dist/node/cjs/storage/blockchain/onchain-issuer.js +82 -0
  21. package/dist/node/cjs/storage/blockchain/onchain-zkp-verifier.js +90 -77
  22. package/dist/node/cjs/storage/interfaces/index.js +1 -0
  23. package/dist/node/cjs/storage/interfaces/onchain-issuer.js +2 -0
  24. package/dist/node/cjs/utils/did-helper.js +11 -6
  25. package/dist/node/cjs/verifiable/constants.js +2 -2
  26. package/dist/node/cjs/verifiable/credential.js +86 -0
  27. package/dist/node/esm/circuits/auth-v2.js +6 -0
  28. package/dist/node/esm/credentials/credential-wallet.js +12 -79
  29. package/dist/node/esm/credentials/index.js +1 -0
  30. package/dist/node/esm/credentials/status/did-resolver-revocation.js +17 -0
  31. package/dist/node/esm/iden3comm/handlers/contract-request.js +7 -1
  32. package/dist/node/esm/iden3comm/handlers/fetch.js +32 -0
  33. package/dist/node/esm/iden3comm/handlers/payment.js +30 -24
  34. package/dist/node/esm/iden3comm/utils/contract-request.utils.js +54 -0
  35. package/dist/node/esm/iden3comm/utils/index.js +1 -0
  36. package/dist/node/esm/proof/proof-service.js +6 -0
  37. package/dist/node/esm/storage/blockchain/abi/ERC20.json +1 -0
  38. package/dist/node/esm/storage/blockchain/did-resolver-readonly-storage.js +68 -0
  39. package/dist/node/esm/storage/blockchain/{erc20-permit-sig.js → erc20-helper.js} +14 -2
  40. package/dist/node/esm/storage/blockchain/index.js +3 -1
  41. package/dist/node/esm/storage/blockchain/onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter.js +241 -0
  42. package/dist/node/esm/storage/blockchain/onchain-issuer.js +78 -0
  43. package/dist/node/esm/storage/blockchain/onchain-zkp-verifier.js +92 -79
  44. package/dist/node/esm/storage/interfaces/index.js +1 -0
  45. package/dist/node/esm/storage/interfaces/onchain-issuer.js +1 -0
  46. package/dist/node/esm/utils/did-helper.js +11 -6
  47. package/dist/node/esm/verifiable/constants.js +2 -2
  48. package/dist/node/esm/verifiable/credential.js +88 -2
  49. package/dist/types/circuits/auth-v2.d.ts +3 -2
  50. package/dist/types/credentials/credential-wallet.d.ts +0 -6
  51. package/dist/types/credentials/index.d.ts +1 -0
  52. package/dist/types/credentials/models.d.ts +8 -0
  53. package/dist/types/credentials/status/did-resolver-revocation.d.ts +7 -0
  54. package/dist/types/iden3comm/handlers/fetch.d.ts +8 -0
  55. package/dist/types/iden3comm/handlers/payment.d.ts +7 -10
  56. package/dist/types/iden3comm/types/protocol/payment.d.ts +6 -5
  57. package/dist/types/iden3comm/utils/contract-request.utils.d.ts +20 -0
  58. package/dist/types/iden3comm/utils/index.d.ts +1 -0
  59. package/dist/types/proof/proof-service.d.ts +10 -0
  60. package/dist/types/storage/blockchain/did-resolver-readonly-storage.d.ts +16 -0
  61. package/dist/types/storage/blockchain/{erc20-permit-sig.d.ts → erc20-helper.d.ts} +8 -1
  62. package/dist/types/storage/blockchain/index.d.ts +3 -1
  63. package/dist/types/storage/blockchain/onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter.d.ts +66 -0
  64. package/dist/types/storage/blockchain/onchain-issuer.d.ts +40 -0
  65. package/dist/types/storage/blockchain/onchain-zkp-verifier.d.ts +13 -12
  66. package/dist/types/storage/entities/state.d.ts +2 -0
  67. package/dist/types/storage/interfaces/index.d.ts +1 -0
  68. package/dist/types/storage/interfaces/onchain-issuer.d.ts +12 -0
  69. package/dist/types/verifiable/constants.d.ts +2 -2
  70. package/dist/types/verifiable/credential.d.ts +15 -2
  71. package/package.json +3 -2
@@ -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,
@@ -1,7 +1,7 @@
1
1
  import { Hash, Proof } from '@iden3/js-merkletree';
2
2
  import { Claim, Id } from '@iden3/js-iden3-core';
3
3
  import { GISTProof, TreeState } from './models';
4
- import { BaseConfig } from './common';
4
+ import { BaseConfig, IStateInfoPubSignals, StatesInfo } from './common';
5
5
  import { Signature } from '@iden3/js-crypto';
6
6
  /**
7
7
  * Auth v2 circuit representation
@@ -30,7 +30,7 @@ export declare class AuthV2Inputs extends BaseConfig {
30
30
  * @public
31
31
  * @class AuthV2PubSignals
32
32
  */
33
- export declare class AuthV2PubSignals {
33
+ export declare class AuthV2PubSignals implements IStateInfoPubSignals {
34
34
  userID: Id;
35
35
  challenge: bigint;
36
36
  GISTRoot: Hash;
@@ -41,4 +41,5 @@ export declare class AuthV2PubSignals {
41
41
  * @returns AuthV2PubSignals
42
42
  */
43
43
  pubSignalsUnmarshal(data: Uint8Array): AuthV2PubSignals;
44
+ getStatesInfo(): StatesInfo;
44
45
  }
@@ -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
@@ -2,7 +2,6 @@ import { BasicMessage, IPackageManager, PackerParams } from '../types';
2
2
  import { DID } from '@iden3/js-iden3-core';
3
3
  import { AbstractMessageHandler, BasicHandlerOptions, IProtocolMessageHandler } from './message-handler';
4
4
  import { Iden3PaymentRailsERC20RequestV1, Iden3PaymentRailsRequestV1, MultiChainPaymentConfig, PaymentMessage, PaymentRequestInfo, PaymentRequestMessage, PaymentRequestTypeUnion, PaymentTypeUnion } from '../types/protocol/payment';
5
- import { PaymentFeatures, PaymentRequestDataType, SupportedCurrencies } from '../../verifiable';
6
5
  import { Signer } from 'ethers';
7
6
  import { Resolvable } from 'did-resolver';
8
7
  /** @beta PaymentRequestCreationOptions represents payment-request creation options */
@@ -34,20 +33,18 @@ export type PaymentRailsInfo = {
34
33
  context: string;
35
34
  }[];
36
35
  description?: string;
37
- chains: PaymentRailsChainInfo[];
36
+ options: PaymentRailsOptionInfo[];
38
37
  };
39
38
  /**
40
39
  * @beta
41
- * PaymentRailsChainInfo represents chain info for payment rails
40
+ * PaymentRailsOptionInfo represents option info for payment rails
42
41
  */
43
- export type PaymentRailsChainInfo = {
44
- nonce: bigint;
45
- amount: bigint;
46
- currency: SupportedCurrencies | string;
42
+ export type PaymentRailsOptionInfo = {
43
+ optionId: string;
47
44
  chainId: string;
48
- expirationDate?: string;
49
- features?: PaymentFeatures[];
50
- type: PaymentRequestDataType.Iden3PaymentRailsRequestV1 | PaymentRequestDataType.Iden3PaymentRailsERC20RequestV1;
45
+ nonce: bigint;
46
+ amount: string;
47
+ expirationDate?: Date;
51
48
  };
52
49
  /**
53
50
  * @beta
@@ -36,7 +36,6 @@ export type Iden3PaymentRailsRequestV1 = {
36
36
  '@context': string | (string | object)[];
37
37
  recipient: string;
38
38
  amount: string;
39
- currency: SupportedCurrencies | string;
40
39
  expirationDate: string;
41
40
  nonce: string;
42
41
  metadata: string;
@@ -106,11 +105,13 @@ export type Iden3PaymentRailsERC20V1 = {
106
105
  /** @beta MultiChainPaymentConfig is struct that represents payments contracts information for different chains */
107
106
  export type MultiChainPaymentConfig = {
108
107
  chainId: string;
109
- paymentContract: string;
108
+ paymentRails: string;
110
109
  recipient: string;
111
- erc20TokenAddressArr: {
112
- symbol: string;
113
- address: string;
110
+ options: {
111
+ id: string;
112
+ type: PaymentRequestDataType.Iden3PaymentRailsRequestV1 | PaymentRequestDataType.Iden3PaymentRailsERC20RequestV1;
113
+ contractAddress?: string;
114
+ features?: PaymentFeatures[];
114
115
  }[];
115
116
  };
116
117
  /**
@@ -0,0 +1,20 @@
1
+ import { CircuitId } from '../../circuits';
2
+ import { DID } from '@iden3/js-iden3-core';
3
+ import { IProofService } from '../../proof';
4
+ import { ZeroKnowledgeProofResponse } from '../types';
5
+ /**
6
+ * @beta
7
+ * Retrieves the request ID from circuit string.
8
+ * CircuitId.AuthV2 - 940499666
9
+ * @returns The request ID.
10
+ */
11
+ export declare function calculateRequestIdForCircuit(circuitId: CircuitId): number;
12
+ /**
13
+ * Prepares the zero-knowledge proof response for the AuthV2 circuit.
14
+ * @beta
15
+ * @param address - The address associated with the request.
16
+ * @param senderDid - The sender's decentralized identifier (DID).
17
+ * @param proofService - The proof service used to generate the proof.
18
+ * @returns A promise that resolves to an array of ZeroKnowledgeProofResponse objects.
19
+ */
20
+ export declare function prepareAuthV2ZeroKnowledgeResponse(address: string, senderDid: DID, proofService: IProofService): Promise<ZeroKnowledgeProofResponse[]>;
@@ -1,4 +1,5 @@
1
1
  export * from './envelope';
2
2
  export * from './message';
3
3
  export * from './did';
4
+ export * from './contract-request.utils';
4
5
  export * from './accept-profile';
@@ -73,6 +73,14 @@ export interface IProofService {
73
73
  * @returns `Promise<Uint8Array>`
74
74
  */
75
75
  generateAuthV2Inputs(hash: Uint8Array, did: DID, circuitId: CircuitId): Promise<Uint8Array>;
76
+ /**
77
+ * generates auth inputs
78
+ *
79
+ * @param {Uint8Array} hash - challenge that will be signed
80
+ * @param {DID} did - identity that will generate a proof
81
+ * @returns `Promise<ZKProof>`
82
+ */
83
+ generateAuthV2Proof(hash: Uint8Array, did: DID): Promise<ZKProof>;
76
84
  /**
77
85
  * state verification function
78
86
  *
@@ -138,6 +146,8 @@ export declare class ProofService implements IProofService {
138
146
  private loadLdContext;
139
147
  /** {@inheritdoc IProofService.generateAuthV2Inputs} */
140
148
  generateAuthV2Inputs(hash: Uint8Array, did: DID, circuitId: CircuitId): Promise<Uint8Array>;
149
+ /** {@inheritdoc IProofService.generateAuthV2Proof} */
150
+ generateAuthV2Proof(challenge: Uint8Array, did: DID): Promise<ZKProof>;
141
151
  verifyState(circuitId: string, pubSignals: string[], opts?: StateVerificationOpts): Promise<boolean>;
142
152
  findCredentialByProofQuery(did: DID, query: ProofQuery): Promise<{
143
153
  cred: W3CCredential;
@@ -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>;
@@ -1,4 +1,6 @@
1
1
  export * from './state';
2
2
  export * from './onchain-zkp-verifier';
3
3
  export * from './onchain-revocation';
4
- export * from './erc20-permit-sig';
4
+ export * from './onchain-issuer';
5
+ export * from './did-resolver-readonly-storage';
6
+ export * from './erc20-helper';
@@ -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 {};
@@ -2,6 +2,7 @@ import { Signer } from 'ethers';
2
2
  import { EthConnectionConfig } from './state';
3
3
  import { IOnChainZKPVerifier } from '../interfaces/onchain-zkp-verifier';
4
4
  import { ContractInvokeTransactionData, JsonDocumentObjectValue, ZeroKnowledgeProofResponse } from '../../iden3comm';
5
+ import { GlobalStateUpdate } from '../entities/state';
5
6
  /**
6
7
  * Supported function signature for SubmitZKPResponse
7
8
  */
@@ -33,11 +34,8 @@ export declare class OnChainZKPVerifier implements IOnChainZKPVerifier {
33
34
  /**
34
35
  * supported circuits
35
36
  */
36
- private readonly _supportedCircuits;
37
- /**
38
- * abi coder to encode/decode structures to solidity bytes
39
- */
40
- private readonly _abiCoder;
37
+ private static readonly _supportedCircuits;
38
+ private static readonly _supportedCircuitsPubSignalsMap;
41
39
  /**
42
40
  *
43
41
  * Creates an instance of OnChainZKPVerifier.
@@ -45,6 +43,7 @@ export declare class OnChainZKPVerifier implements IOnChainZKPVerifier {
45
43
  * @param {EthConnectionConfig[]} - array of ETH configs
46
44
  */
47
45
  constructor(_configs: EthConnectionConfig[], _opts?: OnChainZKPVerifierOptions | undefined);
46
+ static prepareTxArgsSubmitV1(txData: ContractInvokeTransactionData, zkProofResponse: ZeroKnowledgeProofResponse): Promise<JsonDocumentObjectValue[]>;
48
47
  /**
49
48
  * {@inheritDoc IOnChainZKPVerifier.prepareTxArgsSubmitV1}
50
49
  */
@@ -57,12 +56,14 @@ export declare class OnChainZKPVerifier implements IOnChainZKPVerifier {
57
56
  * {@inheritDoc IOnChainZKPVerifier.submitZKPResponseV2}
58
57
  */
59
58
  submitZKPResponseV2(ethSigner: Signer, txData: ContractInvokeTransactionData, zkProofResponses: ZeroKnowledgeProofResponse[]): Promise<Map<string, ZeroKnowledgeProofResponse[]>>;
59
+ private static getCrossChainResolvers;
60
+ static prepareTxArgsSubmitV2(resolverUrl: string, txData: ContractInvokeTransactionData, zkProofResponses: ZeroKnowledgeProofResponse[]): Promise<JsonDocumentObjectValue[]>;
60
61
  prepareTxArgsSubmitV2(txData: ContractInvokeTransactionData, zkProofResponses: ZeroKnowledgeProofResponse[]): Promise<JsonDocumentObjectValue[]>;
61
- private packZkpProof;
62
- private packCrossChainProofs;
63
- private packGlobalStateMsg;
64
- private packIdentityStateMsg;
65
- private packMetadatas;
66
- private getOnChainGistRootStatePubSignals;
67
- private resolveDidDocumentEip712MessageAndSignature;
62
+ private static packZkpProof;
63
+ private static packCrossChainProofs;
64
+ static packGlobalStateMsg(msg: GlobalStateUpdate): string;
65
+ private static packIdentityStateMsg;
66
+ private static packMetadatas;
67
+ private static getOnChainGistRootStatePubSignals;
68
+ private static resolveDidDocumentEip712MessageAndSignature;
68
69
  }
@@ -1,3 +1,4 @@
1
+ import { ProofJSON } from '@iden3/js-merkletree';
1
2
  /**
2
3
  * state information of identity from chain.
3
4
  *
@@ -42,6 +43,7 @@ export interface RootInfo {
42
43
  replacedAtTimestamp: bigint;
43
44
  createdAtBlock: bigint;
44
45
  replacedAtBlock: bigint;
46
+ proof?: ProofJSON;
45
47
  }
46
48
  /**
47
49
  * identity state message
@@ -7,3 +7,4 @@ export * from './data-source';
7
7
  export * from './circuits';
8
8
  export * from './onchain-zkp-verifier';
9
9
  export * from './onchain-revocation';
10
+ export * from './onchain-issuer';
@@ -0,0 +1,12 @@
1
+ import { DID } from '@iden3/js-iden3-core';
2
+ import { W3CCredential } from '../../verifiable';
3
+ /**
4
+ * Interface that allows the processing of the on-chain issuer
5
+ *
6
+ * @beta
7
+ * @interface IOnchainIssuer
8
+ */
9
+ export interface IOnchainIssuer {
10
+ getCredential(issuerDID: DID, userDID: DID, credentialId: bigint): Promise<W3CCredential>;
11
+ getUserCredentialIds(issuerDID: DID, userDID: DID): Promise<bigint[]>;
12
+ }
@@ -117,6 +117,7 @@ export declare enum SupportedPaymentProofType {
117
117
  /**
118
118
  * Media types for Payment supported currencies
119
119
  * @beta
120
+ * @deprecated
120
121
  * @enum {string}
121
122
  */
122
123
  export declare enum SupportedCurrencies {
@@ -124,8 +125,7 @@ export declare enum SupportedCurrencies {
124
125
  ETH_WEI = "ETHWEI",
125
126
  ETH_GWEI = "ETHGWEI",
126
127
  MATIC = "MATIC",
127
- USDT = "USDT",
128
- USDC = "USDC"
128
+ POL = "POL"
129
129
  }
130
130
  /**
131
131
  * Supported features for payment-request
@@ -1,8 +1,8 @@
1
1
  import { BJJSignatureProof2021, Iden3SparseMerkleTreeProof, CredentialStatus, RefreshService, DisplayMethod } from './proof';
2
- import { Claim } from '@iden3/js-iden3-core';
2
+ import { Claim, DID } from '@iden3/js-iden3-core';
3
3
  import { Proof } from '@iden3/js-merkletree';
4
4
  import { Merklizer, Options } from '@iden3/js-jsonld-merklization';
5
- import { CredentialStatusResolverRegistry } from '../credentials';
5
+ import { CredentialRequest, CredentialStatusResolverRegistry } from '../credentials';
6
6
  import { ProofType } from './constants';
7
7
  import { CoreClaimCreationOptions } from './core-utils';
8
8
  import { JsonDocumentObject } from '../iden3comm';
@@ -26,6 +26,19 @@ export declare class W3CCredential {
26
26
  issuer: string;
27
27
  credentialSchema: CredentialSchema;
28
28
  proof?: object | unknown[];
29
+ /**
30
+ *
31
+ * @param issuer - DID of the issuer
32
+ * @param request - Credential request
33
+ * @returns - W3C Credential
34
+ */
35
+ static fromCredentialRequest(issuer: DID, request: CredentialRequest): W3CCredential;
36
+ /**
37
+ * Builds credential status
38
+ * @param {CredentialRequest} request
39
+ * @returns `CredentialStatus`
40
+ */
41
+ private static buildCredentialStatus;
29
42
  toJSON(): this & {
30
43
  proof: any;
31
44
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xpolygonid/js-sdk",
3
- "version": "1.23.0",
3
+ "version": "1.25.1",
4
4
  "description": "SDK to work with Polygon ID",
5
5
  "main": "dist/node/cjs/index.js",
6
6
  "module": "dist/node/esm/index.js",
@@ -79,7 +79,7 @@
79
79
  "eslint-config-prettier": "^8.8.0",
80
80
  "eslint-plugin-prettier": "^4.2.1",
81
81
  "mocha": "10.2.0",
82
- "nock": "^14.0.0-beta.15",
82
+ "nock": "^14.0.0-beta.16",
83
83
  "prettier": "^2.7.1",
84
84
  "rimraf": "^5.0.5",
85
85
  "rollup": "^4.14.3",
@@ -98,6 +98,7 @@
98
98
  "snarkjs": "0.7.4"
99
99
  },
100
100
  "dependencies": {
101
+ "@iden3/onchain-non-merklized-issuer-base-abi": "^0.0.3",
101
102
  "@noble/curves": "^1.4.0",
102
103
  "ajv": "8.12.0",
103
104
  "ajv-formats": "2.1.1",