Skip to content

Issue credential

Important

Before you Issue Credential please ensure you initialised issuer, and have created identity.

Sample Credential Schema

{
    credentialSchema:
      "https://redbellynetwork.github.io/did-schema/passport/credential/PassportCredential-v1.json",
    type: "PassportCredential",
    credentialSubject: {
      id: holderDID,
      name: "james testeleven",
      passportNumber: "E55173628",
      nationality: "AUS",
      birthDate: 19600101,
      customerReference: "2fcecbfc-a926-cf72-6182-4f475da27b28",
      expiryDate: 20250101,
      publicAddress: "0x9e125dB4B5Af7DBe334aA9653b2829b6F07e0391",
    },
    revocationOpts: {
      type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
      id: `${process.env.RHS_URL}`,
    },
  }

Sample Holder's DID

The following Holder's DID is added above in credentialSubject where holderDID is the DID of the holder requesting credentials generated.

{
  "message": "did successfully created",
  "did": {
    "method": "iden3",
    "id": "polygon:mumbai:x5fEEnyoRGR6dTCWMwJ87gUBRTRWYPiLJkyEHYCv6",
    "idStrings": [
      "polygon",
      "mumbai",
      "x5fEEnyoRGR6dTCWMwJ87gUBRTRWYPiLJkyEHYCv6"
    ],
    "params": [],
    "path": "",
    "pathSegments": [],
    "query": "",
    "fragment": ""
  },
  "did_String": "did:iden3:polygon:mumbai:x5fEEnyoRGR6dTCWMwJ87gUBRTRWYPiLJkyEHYCv6"
}

Issue Credential

Issues credential for the given Credential Schema and issuerDid signed with Baby Jub Jub key pair.

const credential = await identityWallet.issueCredential(
  issuerDid,
  credentialSchema
);

Sample Verifiable Credential

{
  "message": "OK",
  "credential": {
    "id": "urn:951481e8-e5f5-48c3-b185-b3f9e6263ac2",
    "@context": [
      "https://www.w3.org/2018/credentials/v1",
      "https://schema.iden3.io/core/jsonld/iden3proofs.jsonld",
      "https://redbellynetwork.github.io/did-schema/passport/credential/v1.jsonld"
    ],
    "type": ["VerifiableCredential", "PassportCredential"],
    "credentialSubject": {
      "id": "did:iden3:polygon:mumbai:x3LXBvzJR4vwV4kHvwSrkBP9PRNYpiLwwTisVEKrZ",
      "name": "james testeleven",
      "passportNumber": "E55173628",
      "nationality": "AUS",
      "birthDate": 19600101,
      "customerReference": "2fcecbfc-a926-cf72-6182-4f475da27b28",
      "expiryDate": 20250101,
      "publicAddress": "0x9e125dB4B5Af7DBe334aA9653b2829b6F07e0391",
      "type": "PassportCredential"
    },
    "issuer": "did:iden3:polygon:mumbai:wznFQLNCwNgrcysagm7M1WZ1iv2ZgZqwYK8dZMZ1k",
    "issuanceDate": "2024-01-31T08:32:25.358Z",
    "credentialSchema": {
      "id": "https://redbellynetwork.github.io/did-schema/passport/credential/PassportCredential-v1.json",
      "type": "JsonSchema2023"
    },
    "credentialStatus": {
      "id": "http://localhost:8080/node?state=d00c36de5b7818e102b47c534fd97c125d88796826b064115acfd74e397ab00f",
      "type": "Iden3ReverseSparseMerkleTreeProof",
      "revocationNonce": 1940
    },
    "proof": [
      {
        "issuerData": {
          "id": "did:iden3:polygon:mumbai:wznFQLNCwNgrcysagm7M1WZ1iv2ZgZqwYK8dZMZ1k",
          "state": {
            "rootOfRoots": "0000000000000000000000000000000000000000000000000000000000000000",
            "revocationTreeRoot": "0000000000000000000000000000000000000000000000000000000000000000",
            "claimsTreeRoot": "8299309aaa4def73548235a717ec3b2fc8b91efbdba958aacaefbcccdbeb011c",
            "value": "d00c36de5b7818e102b47c534fd97c125d88796826b064115acfd74e397ab00f"
          },
          "mtp": {
            "existence": true,
            "siblings": []
          },
          "authCoreClaim": "cca3371a6cb1b715004407e325bd993c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000789a607710ebfa952cde0c650dedec522311e2ae3821a9c7471ef3d41fda5e0bbdf80c621861243963cf45ec8aa5024c18ed0e8188b72ad25c0029e284512c180000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
          "credentialStatus": {
            "id": "http://localhost:8080/node?state=d00c36de5b7818e102b47c534fd97c125d88796826b064115acfd74e397ab00f",
            "type": "Iden3ReverseSparseMerkleTreeProof",
            "revocationNonce": 0
          }
        },
        "type": "BJJSignature2021",
        "coreClaim": "cca3371a6cb1b715004407e325bd993c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000789a607710ebfa952cde0c650dedec522311e2ae3821a9c7471ef3d41fda5e0bbdf80c621861243963cf45ec8aa5024c18ed0e8188b72ad25c0029e284512c180000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
        "signature": "signature"
      },
      {
        "issuerData": {
          "id": "did:iden3:polygon:mumbai:wznFQLNCwNgrcysagm7M1WZ1iv2ZgZqwYK8dZMZ1k",
          "state": {
            "claimsTreeRoot": "edf712698b5c2b42e9923129f74bea6c62cbc02f283839231543c70566ea4d13",
            "revocationTreeRoot": "0000000000000000000000000000000000000000000000000000000000000000",
            "rootOfRoots": "df9330f8306c7b8e68195648ae120b7b01b1bbfdd238dddada02e0d78a3ec724",
            "value": "48eca96ed3813815860a42c7b2674574aa019be5c2f5db4b1b6c75ade7e15a14",
            "txId": "0xf276904e0a34b1fc43bc51a3a7d29bafec0502b12a6e6f16b928dadbb214724d"
          }
        },
        "type": "Iden3SparseMerkleTreeProof",
        "coreClaim": "coreClaim",
        "mtp": {
          "existence": true,
          "siblings": [
            "0",
            "12668154443577484692186593348211170053898334608718851465299950935342343821698"
          ]
        }
      }
    ]
  }
}

Store Credential

Saves the generated credential to the Issuer's wallet.

await credentialWallet.save(credential);

Add Credential to the Issuer's Merkle Tree

const resp = await identityWallet.addCredentialsToMerkleTree(
  [credential],
  issuerDid
);

Publish State

Submits the new state to the RHS for this particular Issuer.

await identityWallet.publishStateToRHS(issuerDid, rhsUrl);

Update State Contract

Creates a signer and submits the transaction (i.e. new state) to the state contract.

const ethSigner = new ethers.Wallet(
  walletKey,
  (dataStorage.states as EthStateStorage).provider
);

const txId = await proofService.transitState(
  issuerDid,
  resp.oldTreeState,
  isOldStateGenesis, // true for first tranaction and then false
  dataStorage.states,
  ethSigner
);

Create Sparse Merkle Tree and Save

const credsWithIden3MTPProof =
  await identityWallet.generateIden3SparseMerkleTreeProof(
    issuerDid,
    resp.credentials,
    txId
  );

await credentialWallet.saveAll(credsWithIden3MTPProof);

Next Steps

After generating the credential the Issuer shares is it with the Holder. Holder further chooses to save the issued credential and generate proof here.