Skip to content

Commit

Permalink
fix: added logs
Browse files Browse the repository at this point in the history
  • Loading branch information
David committed Mar 10, 2023
1 parent 19f7912 commit f033397
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ export class AwsKmsSigner extends ethers.Signer {
}

async getAddress(): Promise<string> {
console.log("getting Address");
if (this.ethereumAddress === undefined) {
console.log("ethAddress is undefined");
const key = await getPublicKey(this.kmsCredentials);
this.ethereumAddress = getEthereumAddress(key.PublicKey as Buffer);
console.log("received public key");
this.ethereumAddress = getEthereumAddress(Buffer.from(key.PublicKey));
}
return Promise.resolve(this.ethereumAddress);
}
Expand Down
7 changes: 7 additions & 0 deletions src/util/aws-kms-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,21 @@ export function getEthereumAddress(publicKey: Buffer): string {
// I used https://lapo.it/asn1js to figure out how to parse this
// and defined the schema in the EcdsaPubKey object
const res = EcdsaPubKey.decode(publicKey, "der");

console.log("decode success");
let pubKeyBuffer: Buffer = res.pubKey.data;

// The public key starts with a 0x04 prefix that needs to be removed
// more info: https://www.oreilly.com/library/view/mastering-ethereum/9781491971932/ch04.html
pubKeyBuffer = pubKeyBuffer.slice(1, pubKeyBuffer.length);
console.log("buffer slice success");

const address = ethers.utils.keccak256(pubKeyBuffer); // keccak256 hash of publicKey
console.log("keccak success");

const EthAddr = `0x${address.slice(-40)}`; // take last 20 bytes as ethereum adress

console.log("address slice success");
return EthAddr;
}

Expand Down

0 comments on commit f033397

Please sign in to comment.