How to create valid Principal Id for mocking via CLI?

Hi,

Any tips on how to create a valid Principal Id (as text) for mocking via CLI? One of the requirements is to have random principal ids for testing or generating any number of mock data.

Thanks!

1 Like

Hi , first thing is to create an ed25519-key-pair (or valid other signature scheme), then get the public-key of that key-pair as a DER-encoded-public-key, then use the logic in this function to get the bytes of the principal , and then this function to turn those principal-bytes into a principal-text.

Glad I’ve asked after your hints realised that doing something like:

import { Ed25519KeyIdentity } from '@dfinity/identity';

const identity = Ed25519KeyIdentity.generate();
identity.getPrincipal();

Should be enough to generate random identities for testing! I’ll try that and call it as a script in the process.

Thanks @levi

3 Likes

Yes that should do it