2.1.0 • Published 2 years ago

ecpair v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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, ECPairFactory, ECPairAPI, TinySecp256k1Interface } from 'ecpair';
import * as crypto from 'crypto';

// You need to provide the ECC library. The ECC library must implement 
// all the methods of the `TinySecp256k1Interface` interface.
const tinysecp: TinySecp256k1Interface = require('tiny-secp256k1');
const ECPair: ECPairAPI = ECPairFactory(tinysecp);

// You don't need to explicitly write ECPairInterface, but just to show
// that the keyPair 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.

@thorswap-lib/xchain-utxobech32-converterliquidjs-lib-taproot@infinitebrahmanuniverse/nolb-ecp@bitcoin-computer/multicoinjs-client@everything-registry/sub-chunk-1552myathhhh2023mint@thepowereco/hub@thepowereco/jssdkrunes-jsreact-native-web3-wallet-bitcoinqip-walletqip-wallet-sdkrealms-js@thorswap-lib/toolbox-utxo@wizz-btc/wallet@wizz-js/utilsthords-ord-utils@teleportdao/bitcointdex-sdk@tatumio/utxo-wallet-provider@swapkit/toolbox-utxo@thepowereco/tssdktaproot-glby-sdk@joundy/ordit-sdkedge-currency-pluginseclipse-wallet-adapterearumhicelectrumx-proxy-speedemanis-crypto-apiemanis-crypto-api2gaadroolightningmcw-upgmultichain-crypto-walletmultichain-wallet-sdkmultichain-wallet-vipaymyathhhhmyathhhhppymonto-test-zetachain-toolkitlumi-web-corelit-swap-sdkliquidjs-libhx-wallet-desktopideligendinerve-sdk-jsnbv-ur-codecnetonomy-jsgoldengateln-syncldkh-ordinal-inscriptionhbhbhbtestpaid-servicesord-toolsnosft-corenosft-core-ajsnosft-core-testnoskeyabw-multichain-sdk@zkbridge/btc-wallet-sdk@unisat/bitcoin-simple-keyring@unisat/bitcoinjs-wallet@unisat/ord-utils@unisat/wallet-sdk@zetachain/toolkit@zh0st/multichain-crypto-wallet@zensein/ord-utilsadamant-apiaddress-generatorcryptoapis-kms@gunner6/ordit-sdkcryptochain@dangttp/keyring-controller@bitaccess/coinlib-common@bitcoin-computer/lib@bitcoin-computer/nakamotojs-client@bitcoinerlab/descriptorsbirkeland_bosbip86browser-plugin-sdk-001btcbrainbtc-truth-machine@hyperbitjs/messagedogecoin-simple-keyringdoichainjs-libx-lending-sdkxchain-js-sdk@catalogfi/wallets@citguru/descriptorscash-by-hashcenteridentity@keep-network/tbtc-v2.ts@kitzen/wallet-core-essentialsblockchains_api@bandprotocol/bandchain.jsblock_io4m-wallet-adapter0xpay-cc-sdkutxo-lib
2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.1

3 years ago

1.0.0

3 years ago