# How to create valid Principal Id for mocking via CLI?

**URL:** <https://forum.dfinity.org/t/how-to-create-valid-principal-id-for-mocking-via-cli/7904>\
**Category:** Developers\
**Tags:** Discussing\
**Created:** [October 14, 2021, 10:08am UTC](https://forum.dfinity.org/t/how-to-create-valid-principal-id-for-mocking-via-cli/7904 "2021-10-14T10:08:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![heldrida](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/heldrida/32/2302_2.png) [@heldrida](https://forum.dfinity.org/u/heldrida)\
**Post date:** [October 14, 2021, 10:08am UTC](https://forum.dfinity.org/t/how-to-create-valid-principal-id-for-mocking-via-cli/7904/1 "2021-10-14T10:08:52Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![levi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/levi/32/22608_2.png) [@levi](https://forum.dfinity.org/u/levi)\
**Post date:** [October 14, 2021, 1:41pm UTC](https://forum.dfinity.org/t/how-to-create-valid-principal-id-for-mocking-via-cli/7904/2 "2021-10-14T13:41:37Z")

</div>

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](https://github.com/levifeldman/ic_tools_dart/blob/da877f124ec170dcd49365bd0c61b045065edd72/lib/src/ic_tools.dart#L44) to get the bytes of the principal , and then [this function](https://github.com/levifeldman/ic_tools_dart/blob/da877f124ec170dcd49365bd0c61b045065edd72/lib/src/ic_tools.dart#L533) to turn those principal-bytes into a principal-text.

---

<div class="post-metadata">

**Author:** ![heldrida](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/heldrida/32/2302_2.png) [@heldrida](https://forum.dfinity.org/u/heldrida)\
**Post date:** [October 14, 2021, 2:29pm UTC](https://forum.dfinity.org/t/how-to-create-valid-principal-id-for-mocking-via-cli/7904/3 "2021-10-14T14:29:40Z")

</div>

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

```auto
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

---

<div class="post-metadata">

**Author:** ![levi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/levi/32/22608_2.png) [@levi](https://forum.dfinity.org/u/levi)\
**Post date:** [October 14, 2021, 3:00pm UTC](https://forum.dfinity.org/t/how-to-create-valid-principal-id-for-mocking-via-cli/7904/4 "2021-10-14T15:00:03Z")

</div>

> [@heldrida](#):
>
> Should be enough to generate random identities for testing!

Yes that should do it
