Code samples

Code sample

This is an example of implementing PoK logic using Node.JS with Typescript.

Creating an asset

async function createAsset(apiKey, payload) {
  const result = await axios.post(`${appConfig.NOTARDEC_URL}/assets`, payload, {
    headers: {
      'X-API-KEY': apiKey,
    },
  });
  return result.data;
}

const pendingArtifact = await createAsset(config.API_KEY, {
  name: ARTIFACT_NAME,
  author: ARTIFACT_AUTHOR
});
Response schema
{
  "value": {
    "id": "string",
    "author": "string",
    "name": "string",
    "description": "string",
    "language": "string",
    "jurisdiction": "string",
    "unitOfMeasure": "string",
    "sparkFactor": "string",
    "sparkFactorModifier": "string",
    "assetClass": "string",
    "createdOn": "string",
    "updatedOn": "string",
    "blockchainHash": "string",
    "documentDbHash": "string",
    "transactionId": "string",
    "assetLinkIds": [
      "string"
    ],
    "customDefinitionItems": [
      {
        "key": "string",
        "type": "string",
        "value": "string",
        "name": "string",
        "sectionsPath": "string",
        "sectionsPathNames": "string"
      }
    ]
  },
  "meta": {
    "size": 0,
    "page": 0
  },
  "error": {
    "code": "string",
    "message": "string"
  }
}

Getting the asset

async function getAsset(apiKey, assetId, details = true) {
  let url = `${appConfig.NOTARDEC_URL}/assets/${assetId}`;
  if (details) {
    url = `${appConfig.NOTARDEC_URL}/assets/${assetId}?details=true`;
  }
  const result = await axios.get(url, {
    headers: {
      'X-API-KEY': apiKey,
    },
  });
  return result.data;
}
const artifact = await getAsset(config.API_KEY, config.ARTIFACT_ID, true);
Response schema
{
  "value": {
    "id": "string",
    "author": "string",
    "name": "string",
    "description": "string",
    "language": "string",
    "jurisdiction": "string",
    "unitOfMeasure": "string",
    "sparkFactor": "string",
    "sparkFactorModifier": "string",
    "assetClass": "string",
    "createdOn": "string",
    "updatedOn": "string",
    "blockchainHash": "string",
    "documentDbHash": "string",
    "transactionId": "string",
    "assetLinkIds": [
      "string"
    ],
    "customDefinitionItems": [
      {
        "key": "string",
        "type": "string",
        "value": "string",
        "name": "string",
        "sectionsPath": "string",
        "sectionsPathNames": "string"
      }
    ]
  },
  "meta": {
    "size": 0,
    "page": 0
  },
  "error": {
    "code": "string",
    "message": "string"
  }
}

Linking the assets

async function linkAssets(apiKey, assetId, payload) {
  const result = await axios.post(`${appConfig.NOTARDEC_URL}/assets/${assetId}/links`, payload, {
    headers: {
      'X-API-KEY': apiKey,
    },
  });
  return result.data;
}
const payload = {
  targetAssetIds: [config.LINK_ARTIFACT_ID]
}
const transaction = await linkAssets(config.API_KEY, config.ARTIFACT_ID, payload)
Response schema
{
  "value": {
    "id": "string",
    "state": "string"
  },
  "meta": {
    "size": 0,
    "page": 0
  },
  "error": {
    "code": "string",
    "message": "string"
  }
}

Creating a PoK

  async function createPok(apiKey, payload) {
  const result = await axios.post(`${appConfig.NOTARDEC_URL}/pok`, payload, {
    headers: {
      'X-API-KEY': apiKey,
    },
  });
  return result.data;
}
const pok = await createPok(config.API_KEY, { address: config.ARTIFACT_AUTHOR});
Response schema
{
  "I": "string",
  "C": "string",
  "T": "string"
}

Responding the PoK

import { Wallet } from 'ethers';
async function respondPok(apiKey, payload) {
  const result = await axios.post(`${appConfig.NOTARDEC_URL}/pok/respond`, payload, {
    headers: {
      'X-API-KEY': apiKey,
    },
  });
  return result.data;
}
const wallet = new Wallet(config.PRIVATE_KEY);
const signature = await wallet.signMessage(pokData.CHALLENGE); // CHALLENGE is the field "C" in Creating a PoK response
const sign = await respondPok(config.API_KEY, {
  address: config.ARTIFACT_AUTHOR,
  signature: signature,
  challengeId: pokData.CHALLENGE_ID
})
Response

To get a PoK result, you must subscribe to Notardec WS. The response to the request will come via WebSockets and will look like this:

'{"challengeId": "string", "result": "boolean", "address": "address"}'