stacks-archive / stacks-transactions-js

The JavaScript library for generating Stacks 2.0 transactions
19 stars 17 forks source link

Helper functions for AddressFromPrivateKey and AddressFromPublicKey #82

Closed zone117x closed 4 years ago

zone117x commented 4 years ago

Description

Creating an address from a public or private key typically involved code like:

  function getAddressFromPrivateKey(privateKey: string): string {
    const addrVer = addressHashModeToVersion(
      AddressHashMode.SerializeP2PKH,
      TransactionVersion.Testnet
    );
    const pubKey = pubKeyfromPrivKey(privateKey);
    const addr = addressFromPublicKeys(addrVer, AddressHashMode.SerializeP2PKH, 1, [pubKey]);
    const addrString = addressToString(addr);
    return addrString;
  }

Helper functions are implemented so this can be done with:

getAddressFromPrivateKey(privateKey, TransactionVersion.Testnet);

For details refer to issue #123

Type of Change

Does this introduce a breaking change?

No

Are documentation updates required?

No

Provide context on how tests should be performed.

  1. Is testing required for this change?
  2. If it’s a bug fix, list steps to reproduce the bug
  3. Briefly mention affected code paths
  4. List other affected projects if possible
  5. Things to watch out for when testing

Checklist

codecov[bot] commented 4 years ago

Codecov Report

Merging #82 into master will increase coverage by 0.12%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #82      +/-   ##
==========================================
+ Coverage   84.86%   84.99%   +0.12%     
==========================================
  Files          26       26              
  Lines        1434     1446      +12     
  Branches      264      268       +4     
==========================================
+ Hits         1217     1229      +12     
  Misses        215      215              
  Partials        2        2              
Impacted Files Coverage Δ
src/keys.ts 96.00% <100.00%> (+0.76%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update cb5bd94...e1e61b1. Read the comment docs.