TLDR: is it ok to use authClient.getIdentity().getPrincipal()._arr
as derivation path to generate a unique bitcoin address for each authenticated user?
The aim is to modify the get_p2pkh_address() function in the basic_bitcoin example (examples/motoko/basic_bitcoin at master · dfinity/examples · GitHub) so that the derivation path is unique to each authenticated user (so that the function returns a unique bitcoin address for each user):
/// Returns the P2PKH address of this canister at a specific derivation path.
public func get_p2pkh_address() : async BitcoinAddress {
await BitcoinWallet.get_p2pkh_address(NETWORK, KEY_NAME, DERIVATION_PATH);
};
The derivation path is of this form:
// The derivation path to use for ECDSA secp256k1.
let DERIVATION_PATH : [[Nat8]] = [];
I’m logging the authClient and derivatives this way:
async function handleAuthenticated(authClient) {
console.log("authClient is: ", authClient);
const identity = await authClient.getIdentity();
console.log("identity is: ", identity);
const agent = new HttpAgent({ identity });
console.log("agent is: ", agent);
const principal = await authClient.getIdentity().getPrincipal().toText()
console.log("principal is: ", principal);
}
And I’m seeing:
The question is, which entry in those responses can I use to set as DERIVATION_PATH, so that
-
each authenticated user will have a unique derivation path, and
-
such DERIVATION_PATH will be compatible in form and size with the one used by the get_p2pkh_address() function?
In particular: no two users should produce the same derivation path, and the same derivation path should be produced by the same user at all times.
if there is a smarter way of achieving the mapping
unique authenticated user → unique canister-controlled bitcoin address,
interested too.
I also need to do a mapping
unique authenticated user → unique canister-controlled IC address,
so if the same piece of data from the user could be used to also be used to produce this second mapping, it would be ideal.