Skip to content

Instantly share code, notes, and snippets.

@hoonsubin
Last active April 13, 2021 19:11
Show Gist options
  • Select an option

  • Save hoonsubin/ab4dea2a96c0c8c3675ccc930026ae06 to your computer and use it in GitHub Desktop.

Select an option

Save hoonsubin/ab4dea2a96c0c8c3675ccc930026ae06 to your computer and use it in GitHub Desktop.

Revisions

  1. hoonsubin renamed this gist Apr 13, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. hoonsubin renamed this gist Mar 3, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. hoonsubin created this gist Aug 31, 2020.
    20 changes: 20 additions & 0 deletions generatePlmAddress
    Original 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;
    }