ecpair
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    ecpair

    Github CI

    NPM

    code style: prettier

    A library for managing SECP256k1 keypairs written in TypeScript with transpiled JavaScript committed to git.

    Example

    TypeScript

    import { Signer, SignerAsync, ECPairInterface, ECPair } from 'ecpair';
    import * as crypto from 'crypto';
    // You don't need to explicitly write ECPairInterface, but just to show
    // that ECPair implements the interface this example includes it.
    
    // From WIF
    const keyPair1: ECPairInterface = ECPair.fromWIF('KynD8ZKdViVo5W82oyxvE18BbG6nZPVQ8Td8hYbwU94RmyUALUik');
    // Random private key
    const keyPair2 = ECPair.fromPrivateKey(crypto.randomBytes(32));
    // OR (uses randombytes library, compatible with browser)
    const keyPair3 = ECPair.makeRandom();
    // OR use your own custom random buffer generator BE CAREFUL!!!!
    const customRandomBufferFunc = (size: number): Buffer => crypto.randomBytes(size);
    const keyPair4 = ECPair.makeRandom({ rng: customRandomBufferFunc });
    // From pubkey (33 or 65 byte DER format public key)
    const keyPair5 = ECPair.fromPublicKey(keyPair1.publicKey);
    
    // Pass a custom network
    const network = {}; // Your custom network object here
    ECPair.makeRandom({ network });
    ECPair.fromPrivateKey(crypto.randomBytes(32), { network });
    ECPair.fromPublicKey(keyPair1.publicKey, { network });
    // fromWIF will check the WIF version against the network you pass in
    // pass in multiple networks if you are not sure
    ECPair.fromWIF('wif key...', network);
    const network2 = {}; // Your custom network object here
    const network3 = {}; // Your custom network object here
    ECPair.fromWIF('wif key...', [network, network2, network3]);

    LICENSE MIT

    Written and tested by bitcoinjs-lib contributors since 2014.

    Install

    npm i ecpair

    DownloadsWeekly Downloads

    1,577

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    13 kB

    Total Files

    9

    Last publish

    Collaborators

    • junderw