Registering Identity and Public Key on Blockchain

This section will cover how to correctly register the public key along with the identity on the Integra blockchain in order to ensure that it works correctly as a public key lookup for encryption/decryption and verification of data authentication and provenance.

Public Key Registry Information

The Integra public key registry/lookup requires an integraId and a public key. The API call that will register the key and id to the blockchain will be the registerKey call and will not require tokens to register these calls. More will be explained about tokens and registering hashes later on the Token Details page. The body of the call takes two values, owner and keyValue. Owner is the IntegraId and keyValue is the public key created in the previous section Public and Private Key Pairs .

{
	"owner":"IntegraId",
	"keyValue":"-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCOtK3nW1bKNOYgjNcWrUZ/zPJ4
I4TiffWSqC15ylUI0X6SMFpzmM26AR8dxo/BhL3Zza4ztZMCVtpUU8CBxf1TTDTd
YtrnG3Jmdl/B+OF2cP3HXFdhBD2yJxs4O1meTEo1NHdeYWeypupslGrznuwhnIK9
mIRY7zEUxSONnApH5QIDAQAB
-----END PUBLIC KEY-----"
}

In order to check to ensure that the key was registered correctly, simply use the KeyForOwner API call passing in the integraId that was created. The result of the call should look similar to the below.

{
    "exists": true,
    "data": [{
        "Key": "e3e06369-a52d-410a-a0d6-d4596aeec3bb",
        "Record": {
            "$class": "com.integraledger.identityregistry.Key",
            "creationDate": "2022-01-17T19:44:19.887Z",
            "integraId": "e3e06369-a52d-410a-a0d6-d4596aeec3bb",
            "keyValue": "-----BEGIN RSA PUBLIC KEY-----\nMIICCgKCAgEA1IhRnbtGskqT1Lwv1RNYGge4RI0HJZTCeFFmyzBv15AEBph05Y4l\ndX4fWNNLDL1veG0EE3hHqzXfM/N3SojRfDgloEWJlVNISwahLtqVnV2/+k/jsdPS\nhbwoPREuh1o9RRIShcuC0z9Qpt5qnYDdVoNeiAxHIXRENbjPPFH8rBSau/e2Rirt\nCYr1zwZyorCI32XzmP1tPKs7+wlUryF9H6WgSiYY+PKe9C/SXXSngrF2LqPFis9M\nKozAUZsUp3D3aPEyUMym2tT0/Nr1946NWxpmq2JosdXtVWHcODtgx/qC/j7Azpgg\nAMSu1+kAF4Qt/4uLjq6Jw79STbDIzIO60W59goBe7H4B2IcXB5kNvQfsdaWPz3EL\nHnZBImbHVaFF/vIySueYRP9Rk8j1b67DhyedzowW2z9dcSxB49GXD4L+TZVvZ0A5\nFlz2Vp1uH1YCGaOhWI6KnbC9ezQyfAG6o93qYh+7+ONYFa8lUi1delRjrChMuf7x\nrdmhGWEhcMIRGfAf2Y0PrKjUz+hu6ZXLXeqAKsJxTF3zPiVdnWN7bYmEGWMRWhSN\nZqFBjQmZvuuU87py0OaX00SCvI/4v0usRldJr/iFaDecCAoPYyUEikv5YfXUoYoI\noP7bINutYGiQXsdDgvkpe5+Dr75Xs0L4QTNOgxaU0+HywVCNWcbDL88CAwEAAQ==\n-----END RSA PUBLIC KEY-----\n",
            "tokenAmount": 0,
            "transactionId": "a9bb2a2231d0b13b1b0184603f754e0c67c9e074075a400b874f5737abae72ab"
        }
    }]
}

Below is code for the end-to-end creation of an integraId and the public-private key pair from the previous steps along with the call to registerKey in Node.js.

//.env configuration variables
const isProd = process.env.APP_ENV === 'production';
const BLOCKCHAIN_API_URL = isProd ? 'https://integraledger.azure-api.net/api/v1.5' : 'https://productionapis.azure-api.net';

//This is the code to generate a new integraId
const integraId = uuidv1();
//This would be the code for getting the integraId from a web page
//const { integraId } = req.body;

const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
        modulusLength: 4096,
      });
const pubkeyString = publicKey.export({ type: 'pkcs1', format: 'pem' });
let privkeyString = privateKey.export({ type: 'pkcs1', format: 'pem' });

const response = await fetch(`${BLOCKCHAIN_API_URL}/registerKey`, {
  method: 'post',
  body: JSON.stringify({
  integraId: integraId,
  keyValue: pubkeyString,
  }),
  headers: {
    'Content-Type': 'application/json'
	},
});

The next section will cover the preferred means of storing the private key in a blockchain authenticated Integra Smart Identity Document.