Relationship between PrincipalId and AccountIdentifier

Hello!

Given a PrincipalId: is there a way to find / construct a valid “default” AccountIdentifier for it?

Also: given an AccountIdentifier and a PrincipalId: is t possible to check that the former is controlled (i.e. funds can be spent) by the latter?

There’s a tool to convert a principal to its default account id here:
https://k7gat-daaaa-aaaae-qaahq-cai.ic0.app/docs/

The principal will convert to the account id it owns, so for the default account just converting it and seeing if the account ids match is your check. But you can also have sub accounts (the default account id is just the sub account set to 0) and for these you’d need to know the sub account name to generate its id, since you can’t go the other way (from account id to principal).

Some great detail on all of this is in these two links, including how to derive the ids yourself:
https://github.com/dfinity/ic/blob/master/rs/rosetta-api/docs/modules/rosetta-api/pages/ledger.adoc#accounts 3
And:
https://fxa77-fiaaa-aaaae-aaana-cai.raw.ic0.app/wrongzoo

4 Likes

Thank you for your reply – very useful!