npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bitcoin-connect

v0.4.2

Published

Derive Bitcoin Taproot address, from an Ethereum signature. For example, a signature generated by your Injected Web3 wallet through the `personal_sign` RPC call. Useful for Bitcoin Ordinals.

Downloads

8

Readme

bitcoin-connect

Derive Bitcoin Taproot address, from an Ethereum signature. For example, a signature generated by your Injected Web3 wallet through the personal_sign RPC call. Useful for Bitcoin Ordinals.

For demo check out the hosted API and UI on https://bitcoin-connect.deno.dev.

Tweets about it:

  • https://twitter.com/wgw_eth/status/1644576875845496833
  • https://twitter.com/wgw_eth/status/1644557972889018369

Install

npm install bitcoin-connect

For Deno, use the npm protocol, eg. npm:bitcoin-connect.

It's recommended though, to use the https://esm.sh/bitcoin-connect because some of the bitcoin libraries that are used my not be resolved properly. I'll definitely make smaller ESM-only alternatives in the future.

Table of Contents

image

As a library

Check the test.js for an example. More better test suite and docs - soon.

Basically, there are few steps:

  1. Trigger a sign request to some Injected web browser wallet, like Metamask
  2. Pass that signature string to the exported method.
  3. It returns the bip32 root, taproot child, the signature, and a taproot address.
  4. Show the taproot address to your user. It can be used for Bitcoin Ordinals.

Basic "server-side" example

import { generateTaprootAddressFromSignature } from "bitcoin-connect";

const result = generateTaprootAddressFromSignature("0xSignature here");

console.log(result);
console.log(result.taprootAddress);

This is also useful as a Serverless function, which I'll deploy soon.

It's also useful if you want to generate the same wallet address as the one that Generative.xyz's website is generating for your Ethereum Address.

I follow how they are doing it, but externalized it so there's no UI or React things. If you can generate Ethereum signature in some other way, we include their message for convenience on TAPROOT_MESSAGE export.

For example,

import {
  TAPROOT_MESSAGE,
  generateTaprootAddressFromSignature,
} from "bitcoin-connect";

const signature = requestEthereumPersonalSign(TAPROOT_MESSAGE);
const { taprootAddress } = generateTaprootAddressFromSignature(signature);

// you should get the same address as the one when you connect your wallet
// to the generative.xyz site by clicking Wallet there.
console.log(taprootAddress);

API Usage

The API generates you a bitcoin taproot address, given an Ethereum/Web3 signature.

It accepts both POST and GET requests to the root domain, e.g. /.

Try this https://bitcoin-connect.deno.dev/?signature=0x849cdb2c6ab66269d95e219ab99d12762c6caad49f6b0fa569289935c21179242747640b69be801f8660b17cba85bb37e8897be01830c6442b95fd6bc69038991b

That's my actual Bitcoin taproot wallet (that can be used on https://generative.xyz), generated from my Ethereum address (0xA20c...5002 / wgw.eth). You can verify that at https://etherscan.io/verifySig/16514

You can also pass the signature to a POST request body

// generate this signature somehow,
// eg. using `personal_sign` of Metamask, or another (Injected browser) wallet
const sig = `0x849cdb2c6ab66269d95e219ab99d12762c6caad49f6b0fa569289935c21179242747640b69be801f8660b17cba85bb37e8897be01830c6442b95fd6bc69038991b`;

const res = await fetch("https://bitcoin-connect.deno.dev", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({ signature: sig }),
});

const { error, data } = await res.json();
const { address, signature, message } = data;

constole.log({ error, address, signature, message });

or a GET request example

const sig = `0x849cdb2c6ab66269d95e219ab99d12762c6caad49f6b0fa569289935c21179242747640b69be801f8660b17cba85bb37e8897be01830c6442b95fd6bc69038991b`;

const res = await fetch("https://bitcoin-connect.deno.dev/?signature" + sig);
const { error, data } = await res.json();
const { address, signature, message } = data;

constole.log({ error, address, signature, message });

(for more check the source code in api/index.ts)

For development

yarn dev

# or from the `api` folder
# deno run -A --watch index.ts

For production

yarn deploy

# or from the `api` folder
# deployctl deploy --project=bitcoin-connect index.ts

UI usage

TODO: More docs on the site, explaining everything and the API

As an example, you can check the api/index.html to see how Metamask/web3 wallet signing is implemented in 30 lines of code. No need for libraries, no need for MEGABYTES of stuff on the client side. Ethereum Web3 is so awful it's mind-blowing.