Skip to content

Commit 8915adb

Browse files
committed
docs: add bitcoin network and guide
1 parent fe6044e commit 8915adb

File tree

14 files changed

+236
-4
lines changed

14 files changed

+236
-4
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ Then an authz example website will be created and users can take a look how sign
246246

247247
---
248248

249+
### Bitcoin Network
250+
251+
| Feature | Package |
252+
| ---------------- | ------------------------------------------------------ |
253+
| **Transactions** | [@interchainjs/bitcoin](https://docs.hyperweb.io/interchain-js/networks/bitcoin) |
254+
255+
---
256+
249257
## Interchain JavaScript Stack ⚛️
250258

251259
A unified toolkit for building applications and smart contracts in the Interchain ecosystem

docs/advanced/_meta.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"migration-from-cosmjs": "Migration from CosmJS",
55
"signer": "Signer",
66
"tutorial": "Tutorial",
7-
"wallet": "Wallet"
8-
}
7+
"wallet": "Wallet",
8+
"add-network": "Add a Network"
9+
}

docs/advanced/add-network.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Adding a New Network
2+
3+
This guide outlines the basic steps to integrate a new blockchain network with InterchainJS. A network package exposes signers and account utilities that follow the interfaces defined in `@interchainjs/types`.
4+
5+
1. **Create a new package** under `networks/` with its own `package.json`, `tsconfig.json` and `src` folder. Export your signers and accounts from an `index.ts` file.
6+
2. **Implement signers** that perform the necessary cryptographic signing. Signers typically wrap private keys or wallet providers and expose methods like `sign` or `send`.
7+
3. **Provide account helpers** to derive addresses from public keys. Reuse hashing and encoding utilities from `@interchainjs/crypto` and `@interchainjs/encoding`.
8+
4. **Document your network** in `docs/networks/` so users can install and use it.
9+
10+
Existing networks such as [Cosmos](./../networks/cosmos/index.mdx) and [Ethereum](./../networks/ethereum/index.mdx) can serve as references for structuring your package.

docs/index.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ Then an authz example website will be created and users can take a look how sign
246246

247247
---
248248

249+
### Bitcoin Network
250+
251+
| Feature | Package |
252+
| ---------------- | ------------------------------------------------------ |
253+
| **Transactions** | [@interchainjs/bitcoin](https://docs.hyperweb.io/interchain-js/networks/bitcoin) |
254+
255+
---
256+
249257
## Interchain JavaScript Stack ⚛️
250258

251259
A unified toolkit for building applications and smart contracts in the Interchain ecosystem

docs/networks/_meta.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"cosmos": "Cosmos",
33
"ethereum": "Ethereum",
4-
"injective": "Injective"
5-
}
4+
"injective": "Injective",
5+
"bitcoin": "Bitcoin"
6+
}

docs/networks/bitcoin/_meta.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"index": "Overview"
3+
}

docs/networks/bitcoin/index.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# @interchainjs/bitcoin
2+
3+
Transaction signing and account utilities for the Bitcoin network.
4+
5+
## Usage
6+
7+
```sh
8+
npm install @interchainjs/bitcoin
9+
```
10+
11+
```ts
12+
import { SignerFromPrivateKey } from '@interchainjs/bitcoin'
13+
14+
const signer = new SignerFromPrivateKey(privateKeyHex)
15+
const address = signer.getAddress()
16+
```
17+
18+
## Implementations
19+
20+
- **SignerFromPrivateKey** from `@interchainjs/bitcoin/signers/SignerFromPrivateKey`
21+
- **BitcoinAccount** from `@interchainjs/bitcoin/accounts/bitcoin-account`
22+
23+
## Credits
24+
25+
🛠 Built by Hyperweb (formerly Cosmology) — if you like our tools, please check out and contribute to [our github ⚛️](https://github.com/hyperweb-io)
26+
27+
## Disclaimer
28+
29+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
30+
31+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.

networks/bitcoin/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# @interchainjs/bitcoin
2+
3+
Transaction signing and account utilities for the Bitcoin network.
4+
5+
## Usage
6+
7+
```sh
8+
npm install @interchainjs/bitcoin
9+
```
10+
11+
```ts
12+
import { SignerFromPrivateKey } from '@interchainjs/bitcoin'
13+
14+
const signer = new SignerFromPrivateKey(privateKeyHex)
15+
const address = signer.getAddress()
16+
```
17+
18+
## Implementations
19+
20+
- **SignerFromPrivateKey** from `@interchainjs/bitcoin/signers/SignerFromPrivateKey`
21+
- **BitcoinAccount** from `@interchainjs/bitcoin/accounts/bitcoin-account`
22+
23+
## Credits
24+
25+
🛠 Built by Hyperweb (formerly Cosmology) — if you like our tools, please check out and contribute to [our github ⚛️](https://github.com/hyperweb-io)
26+
27+
## Disclaimer
28+
29+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
30+
31+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
32+

networks/bitcoin/package.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "@interchainjs/bitcoin",
3+
"version": "1.11.11",
4+
"description": "Bitcoin signing utilities",
5+
"main": "index.js",
6+
"module": "esm/index.js",
7+
"types": "index.d.ts",
8+
"author": "Hyperweb <[email protected]>",
9+
"homepage": "https://github.com/hyperweb-io/interchainjs",
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/hyperweb-io/interchainjs"
13+
},
14+
"license": "MIT",
15+
"publishConfig": {
16+
"access": "public",
17+
"directory": "dist"
18+
},
19+
"scripts": {
20+
"copy": "copyfiles -f ../../LICENSE-MIT ../../LICENSE-Apache README.md package.json dist",
21+
"clean": "rimraf dist/**",
22+
"prepare": "npm run build",
23+
"build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
24+
"build:dev": "npm run clean; tsc --declarationMap; tsc -p tsconfig.esm.json; npm run copy",
25+
"lint": "eslint . --fix"
26+
},
27+
"dependencies": {
28+
"@interchainjs/auth": "1.11.11",
29+
"@interchainjs/crypto": "1.11.11",
30+
"@interchainjs/types": "1.11.11",
31+
"@interchainjs/utils": "1.11.11"
32+
}
33+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { AccountBase } from '@interchainjs/types/account';
2+
import { sha256, ripemd160 } from '@interchainjs/crypto';
3+
import { toBech32 } from '@interchainjs/encoding';
4+
5+
export class BitcoinAccount extends AccountBase {
6+
getAddressByPubKey(): string {
7+
const pub = this.auth.getPublicKey(true);
8+
const hash160 = ripemd160(sha256(pub.value));
9+
const data = new Uint8Array(1 + hash160.length);
10+
data[0] = 0x00; // witness version 0
11+
data.set(hash160, 1);
12+
return toBech32(this.prefix, data);
13+
}
14+
}

0 commit comments

Comments
 (0)