Last active
April 13, 2021 19:11
-
-
Save hoonsubin/ab4dea2a96c0c8c3675ccc930026ae06 to your computer and use it in GitHub Desktop.
Revisions
-
hoonsubin renamed this gist
Apr 13, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
hoonsubin renamed this gist
Mar 3, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
hoonsubin created this gist
Aug 31, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ /** * generates a Plasm public address with the given ethereum public key * @param ethPubKey an compressed ECDSA public key. With or without the 0x prefix */ export function generatePlmAddress(publicKey: string) { // converts a given hex string into Uint8Array const toByteArray = (hexString: string) => { const result = []; for (let i = 0; i < hexString.length; i += 2) { result.push(parseInt(hexString.substr(i, 2), 16)); } return new Uint8Array(result); }; // hash to blake2 const plasmPubKey = polkadotUtilCrypto.blake2AsU8a(toByteArray(publicKey.replace('0x', '')), 256); // encode address const plasmAddress = polkadotUtilCrypto.encodeAddress(plasmPubKey, 5); return plasmAddress; }