Calling decodeFile(process.env.HOME+"/.config/dfx/identity/default/identity.pem")
prints a different identity than dfx identity get-principal
.
What’s wrong in my TypeScript code?
import fs from 'fs';
import { Secp256k1KeyIdentity } from '@dfinity/identity-secp256k1';
import sha256 from "sha256";
export function decodeFile(fileName) {
const rawKey = fs.readFileSync(fileName);
const rawBuffer = Uint8Array.from(rawKey).buffer;
const p = sha256(rawBuffer, { asBytes: true }) as Array<number>;
const privKey = Uint8Array.from(p);
const identity = Secp256k1KeyIdentity.fromSecretKey(privKey);
console.log('====================', identity.getPrincipal().toText());
return identity
}
Also,
$ dfx identity list
anonymous
default *