createVC

How to call the API from an app

Identify Snap connects to your currently connected Metamask account by default. To learn how apps can connect to Identify Snap using a non-metamask(external) account, refer to this documentation.

Then, depending on whether you're trying to connect to a metamask account or a non-metamask account, you can call the snap API in the following way:

const snapId = `npm:@tuum-tech/identify`

const metamaskAddress = '0x2e5fF0267b678A0FAF9A9f5b0FBf7Ac9638B5b57'
const vcValue = {
  name: 'KP'
}
const options = {
  // If you want to auto save the generated VCs to multiple stores, you can pass an
  // array like so:
  // store: ['snap', 'googleDrive']
  store: ['snap']
}
const params = {
  metamaskAddress,
  vcKey: 'profile',
  vcValue: vcValue,
  credTypes: ['ProfileNamesCredential'],
  options
  /* 
    Uncomment the below line if you want to connect to a non-metamask account
  */
  // ...externalAccountParams
}

const handleCreateVCAPI = async () => {
  await window.ethereum.request({
    method: 'wallet_invokeSnap',
    params: {
      snapId,
      request: {
        method: 'createVC',
        params: params
      }
    }
  })
}

Notes:

  • There is no need to pass in options if you want to store the VC in the Metamask snap state as this is the default behavior however, for storing it in googleDrive, you will need to specify via this parameter. In order to use googleDrive , you first need to first configure your google account.

  • Each VC will automatically be of type VerifiableCredential by default but if you want to add additional credential types, you can define that with the credTypes parameter.

  • The key for the credentialSubject of the VC will be called vcData by default but if you want to define your own value for this key, you can pass it in the vcKey parameter.

  • Identify Snap currently supports generating VC using jwt proof format however, there are plans to support additional proof formats such as lds and EthereumEip712Signature2021 in the future.

How the API is handled between the app and snap

What the API does

  1. Retrieves the currently connected account and the blockchain network the user has selected on Metamask. If it's the first time, the account info is also saved in snap state.

  2. Generates a Verifiable Credential(VC) for the specified value based on the parameters defined. The expiration date is always set to 1 year in the future from the time of its issuance date. The proofformat for the VC will be jwt by default.

  3. Returns the newly generated VC back to the application.

Some example responses:

Creating a new VC for an EVM address: 0x2e5ff0267b678a0faf9a9f5b0fbf7ac9638b5b57

{
  "data": {
    "credentialSubject": {
      "profile": {
        "name": "KP"
      },
      "id": "did:pkh:eip155:1:0x2e5ff0267b678a0faf9a9f5b0fbf7ac9638b5b57"
    },
    "issuer": {
      "id": "did:pkh:eip155:1:0x2e5ff0267b678a0faf9a9f5b0fbf7ac9638b5b57"
    },
    "type": ["VerifiableCredential", "ProfileNamesCredential"],
    "@context": ["https://www.w3.org/2018/credentials/v1"],
    "issuanceDate": "2023-04-04T23:59:50.000Z",
    "expirationDate": "2024-04-04T23:59:50.000Z",
    "proof": {
      "type": "JwtProof2020",
      "jwt": "eyJhbGciOiJFUzI1NksiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjE3MTIyNzUxOTAsInZjIjp7IkBjb250ZXh0IjpbImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL3YxIl0sInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiLCJQcm9maWxlTmFtZXNDcmVkZW50aWFsIl0sImNyZWRlbnRpYWxTdWJqZWN0Ijp7InByb2ZpbGUiOnsibmFtZSI6IktQIn19fSwic3ViIjoiZGlkOnBraDplaXAxNTU6MToweDJlNWZmMDI2N2I2NzhhMGZhZjlhOWY1YjBmYmY3YWM5NjM4YjViNTciLCJuYmYiOjE2ODA2NTI3OTAsImlzcyI6ImRpZDpwa2g6ZWlwMTU1OjE6MHgyZTVmZjAyNjdiNjc4YTBmYWY5YTlmNWIwZmJmN2FjOTYzOGI1YjU3In0.VLbdkAt0YopmW8TpQqSxjurWvJMNnY91sm8qyfVDR5jVigzIXUDTl0obGiRH7PM4PZInUcOJHA7Wq3koBOym8g"
    }
  },
  "metadata": {
    "id": "17d03921-3a5e-4049-9ec9-78fbc3779194",
    "store": "snap"
  }
}

Creating a new VC for a hedera account id: 0x7d871f006d97498ea338268a956af94ab2e65cdd

{
  "data": {
    "issuer": {
      "id": "did:pkh:eip155:296:0x7d871f006d97498ea338268a956af94ab2e65cdd",
      "hederaAccountId": "0.0.15215"
    },
    "credentialSubject": {
      "profile": {
        "name": "KP"
      },
      "hederaAccountId": "0.0.15215",
      "id": "did:pkh:eip155:296:0x7d871f006d97498ea338268a956af94ab2e65cdd"
    },
    "type": ["VerifiableCredential", "ProfileNamesCredential"],
    "@context": ["https://www.w3.org/2018/credentials/v1"],
    "issuanceDate": "2023-04-05T00:04:12.000Z",
    "expirationDate": "2024-04-05T00:04:12.000Z",
    "proof": {
      "type": "JwtProof2020",
      "jwt": "eyJhbGciOiJFUzI1NksiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjE3MTIyNzU0NTIsInZjIjp7IkBjb250ZXh0IjpbImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL3YxIl0sInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiLCJQcm9maWxlTmFtZXNDcmVkZW50aWFsIl0sImNyZWRlbnRpYWxTdWJqZWN0Ijp7InByb2ZpbGUiOnsibmFtZSI6IktQIn0sImhlZGVyYUFjY291bnRJZCI6IjAuMC4xNTIxNSJ9fSwiaXNzdWVyIjp7ImhlZGVyYUFjY291bnRJZCI6IjAuMC4xNTIxNSJ9LCJzdWIiOiJkaWQ6cGtoOmVpcDE1NToyOTY6MHg3ZDg3MWYwMDZkOTc0OThlYTMzODI2OGE5NTZhZjk0YWIyZTY1Y2RkIiwibmJmIjoxNjgwNjUzMDUyLCJpc3MiOiJkaWQ6cGtoOmVpcDE1NToyOTY6MHg3ZDg3MWYwMDZkOTc0OThlYTMzODI2OGE5NTZhZjk0YWIyZTY1Y2RkIn0.aCwpILdvJ40D9V5o-p5cUfnJdLyvHuBgNNVqwsbngOjsIqPdIbNNQDZBidV2uU38vTBmtNjjf_W7Wg-Sk2WzlA"
    }
  },
  "metadata": {
    "id": "949c9dda-a8f2-4165-850d-57f03b1213f9",
    "store": "snap"
  }
}

Note: Even if the DID for this hedera account is based on its EVM address 0x7d871f006d97498ea338268a956af94ab2e65cdd, it has an additional field called hederaAccountId as part of the issuer and credentialSubject in the VC which is set to 0.0.15215.

How the API works

Live Demo on CodePen

Some things to keep in mind while interacting with the above demo
  • If you're getting any errors with the live demo, make sure you go through the FAQs section to learn about what you may be missing. You need to install Metamask in your browser for the live demo to work

  • Whenever there is a new version of the IdentifySnap, always make sure to first uninstall the old version of the snap from Metamask and only then try the above demo so it can install the latest version

To ease the integration of Identify Snap on an application, we have created a template web application that you can run locally and check out the code in its entirety to learn how you can integrate and interact with various APIs exposed by Identify Snap. Check out the full source code at template application github repository.

You can also check out the API reference to learn how each API works.

Last updated