Hi! I’m developing an API in node + express who uses ckBtc minter and ledger canisters. This method get_blocks
its called with 2 parameters and, from this, I receive an array of transactions.
This transactions, if are of type ‘Transfer’ have a from and a to values. I’m trying to get the “principal id” from this values, and I tried 2 ways but both fails. Both ways return to me the same address in all petitions. I try this ways:
Principal from blob:
const blobToPrincipal(values: number[]) => {
const uint8Array = new Uint8Array(32);
for (const key in values) {
uint8Array[key] = values[key];
}
return Principal.from(uint8Array).toText();
}
values
send from params in this function are the received in the response:
this way return me always the same Principal ID:
deffl-liaaa-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa-aaa
And with this another way, making an Identity and then obtaining the principal:
private getAddressFromUint8(values: Uint8Array): string {
const uint8Array = new Uint8Array(32);
for (const key in values) {
uint8Array[key] = values[key];
}
const identity = Ed25519KeyIdentity.fromSecretKey(uint8Array);
const principal = identity.getPrincipal();
console.log(principal.toText());
return principal.toText();
}
and the Principal ID obtained is this:
535yc-uxytb-gfk7h-tny7p-vjkoe-i4krp-3qmcl-uqfgr-cpgej-yqtjq-rqe
I’m doing all this to make a sort of webhook, to search in my DB if the TO
Principal ID value is one of my users and, if it is, notify them. This is running in a cronjob every 2 minutes.
Any idea of where Im making the mistake? Or a better way to do this? Is the only thing I need to finish my API. All the transfers, Principals are working, I only need to notify users when they received a deposit.