Skip to content

Commit

Permalink
Merge pull request #16 from bucko13/caravan-descriptors
Browse files Browse the repository at this point in the history
Caravan descriptors
  • Loading branch information
bucko13 authored Feb 23, 2024
2 parents 572e8cd + de755b2 commit e590ba8
Show file tree
Hide file tree
Showing 37 changed files with 3,750 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-seas-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@caravan/descriptors": patch
---

Add new package for encoding and decoding descriptors using bdk with wasm bindings.
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
node-version: ["20.x"]
# To use Turborepo Remote Caching
# To use Turborepo Remote Caching, set the following environment variables for the job.
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
Expand All @@ -22,8 +22,16 @@ jobs:
with:
node-version: 20

- name: Install wasm-pack
uses: jetli/[email protected]
with:
# Optional version of wasm-pack to install(eg. 'v0.9.1', 'latest')
version: 'latest'

- name: Install Dependencies
run: npm install


- name: Run tests
run: npm run ci
run: |
npx turbo run ci
6 changes: 6 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ jobs:
with:
node-version: 20

- name: Install wasm-pack
uses: jetli/[email protected]
with:
# Optional version of wasm-pack to install(eg. 'v0.9.1', 'latest')
version: 'latest'

- name: Install dependencies
run: npm install

Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ jobs:
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Install wasm-pack
uses: jetli/[email protected]
with:
# Optional version of wasm-pack to install(eg. 'v0.9.1', 'latest')
version: 'latest'

- name: Install Dependencies
run: npm install

Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ yarn-error.log*
.DS_Store
*.pem

**/target
.rustup
.cargo

.vscode
11 changes: 4 additions & 7 deletions apps/coordinator/src/components/Wallet/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,7 @@ class CreateWallet extends React.Component {
type="file"
/>

<Button
color="primary"
variant="contained"
component="span"
style={{ marginTop: "20px" }}
>
<Button color="primary" variant="contained" component="span">
Import Wallet Configuration
</Button>
</label>
Expand Down Expand Up @@ -542,7 +537,9 @@ class CreateWallet extends React.Component {
<Box>
<Grid container spacing={3}>
<Grid item xs={12}>
{this.renderWalletImporter()}
<Grid container style={{ marginTop: "10px" }} spacing={3}>
<Grid item>{this.renderWalletImporter()}</Grid>
</Grid>
</Grid>
<Grid item md={configuring ? 8 : 12}>
{this.renderExtendedPublicKeyImporters()}
Expand Down
71 changes: 71 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/caravan-bitcoin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts",
"dev": "npm run build -- --watch",
"lint": "eslint src/ --ext .ts",
"ci": "npm run test",
"test": "jest src",
"test:watch": "jest --watch src"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/caravan-clients/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts",
"dev": "npm run build -- --watch",
"lint": "eslint src",
"ci": "npm run lint && npm run test",
"test": "jest src",
"test:watch": "jest --watch src"
},
Expand Down
12 changes: 6 additions & 6 deletions packages/caravan-clients/src/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Network, satoshisToBitcoins } from "@caravan/bitcoin";
import { BlockchainClient, ClientType, ClientBase } from "./client";
import { BlockchainClient, ClientType, ClientBase, UTXO } from "./client";
import * as bitcoind from "./bitcoind";
import BigNumber from "bignumber.js";

Expand Down Expand Up @@ -481,9 +481,9 @@ describe("BlockchainClient", () => {
.mockResolvedValue(mockTransactionResult);

// Mock the response from the Get method
const mockUtxos = [
{ txid: "txid1", vout: 0, value: 100, status: "confirmed" },
{ txid: "txid2", vout: 1, value: 200, status: "confirmed" },
const mockUtxos: UTXO[] = [
{ txid: "txid1", vout: 0, value: 100, status: {confirmed: true, block_time: 21} },
{ txid: "txid2", vout: 1, value: 200, status: {confirmed: true, block_time: 42} },
];
const mockGet = jest.fn().mockResolvedValue(mockUtxos);

Expand All @@ -504,8 +504,8 @@ describe("BlockchainClient", () => {
// Verify the returned result
expect(result.utxos).toEqual(
await Promise.all(
mockUtxos.map((utxo: any) => blockchainClient.formatUtxo(utxo)),
),
mockUtxos.map((utxo: UTXO) => blockchainClient.formatUtxo(utxo))
)
);
expect(result.balanceSats).toEqual(new BigNumber(300));
expect(result.addressKnown).toBe(true);
Expand Down
2 changes: 1 addition & 1 deletion packages/caravan-clients/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "./bitcoind";
import BigNumber from "bignumber.js";

interface UTXO {
export interface UTXO {
txid: string;
vout: number;
value: number;
Expand Down
10 changes: 10 additions & 0 deletions packages/caravan-descriptors/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
root: true,
extends: [
"@caravan/eslint-config/library.js"
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
},
};
4 changes: 4 additions & 0 deletions packages/caravan-descriptors/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tabWidth": 2,
"useTabs": false
}
58 changes: 58 additions & 0 deletions packages/caravan-descriptors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Caravan Descriptors

## Installation

1. clone
2. install [rust toolchain](https://www.rust-lang.org/tools/install) and `cargo install wasm-pack`
3. npm install in the main directory
4. cd to the caravan-rs directory and `wasm-pack build -t nodejs` to build the `pkg/` directory (not clear yet if nodejs is the right target or how to make it more flexible)
1. You might need to install llvm/clang
2. Will also need to setup paths to build libsecp

```
export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
# for older homebrew installs
# export PATH="/usr/local/opt/llvm/bin:$PATH"
export CC=/opt/homebrew/opt/llvm/bin/clang
export AR=/opt/homebrew/opt/llvm/bin/llvm-ar
```

## Usage
You can use npm scripts from the main directory to do all building

```shell
$ npm run build
```
This will cd into the rust directory, build packages for web and node
targets, and then build the artifacts for the js library to be packaged
and used.

```shell
$ npm run test
```
This will run the TypeScript tests only.


### Web
You'll need to make sure that the web environment this is used in
supports wasm. For example, if you're using in a vite.js project
you'll need the `vite-plugin-wasm` plugin.

Also note that all functions exported are async and need to be awaited
since they will load up the wasm modules to be used (this way consumers
of the library don't have to worry about loading up the modules themselves)


## API
NOTE: This is subject to change as this is still very much alpha

The two main functions available for import are:

### encodeDescriptors
Takes a config for a multisig wallet and encodes it into
the two corresponding descriptors

### decodeDescriptors
Take two descriptors and convert them into a multisig wallet
config object. This will make it possible to determine and parse the wallet type
(e.g. P2SH) and the key origins.
Loading

0 comments on commit e590ba8

Please sign in to comment.