Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/wasm-utxo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ edition = "2021"
[lib]
crate-type = ["cdylib"]

[lints.clippy]
all = "warn"

[dependencies]
wasm-bindgen = "0.2"
js-sys = "0.3"
Expand Down
12 changes: 6 additions & 6 deletions packages/wasm-utxo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ that help verify and co-sign transactions built by the BitGo Wallet Platform API

This project is under active development.

| Feature | Bitcoin | BitcoinCash | BitcoinGold | Dash | Doge | Litecoin | Zcash |
| --------------------------------------- | -------------- | ----------- | ----------- | ------- | ------- | -------- | ------- |
| Descriptor Wallet: Address Support | ✅ Complete | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 |
| Descriptor Wallet: Transaction Support | ✅ Complete | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 |
| FixedScript Wallet: Address Generation | 🏗️ In Progress | ⏳ TODO | ⏳ TODO | ⏳ TODO | ⏳ TODO | ⏳ TODO | ⏳ TODO |
| FixedScript Wallet: Transaction Support | ⏳ TODO | ⏳ TODO | ⏳ TODO | ⏳ TODO | ⏳ TODO | ⏳ TODO | ⏳ TODO |
| Feature | Bitcoin | BitcoinCash | BitcoinGold | Dash | Doge | Litecoin | Zcash |
| --------------------------------------- | ----------- | ----------- | ----------- | ----------- | ----------- | ----------- | ----------- |
| Descriptor Wallet: Address Support | ✅ Complete | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 |
| Descriptor Wallet: Transaction Support | ✅ Complete | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 |
| FixedScript Wallet: Address Generation | ✅ Complete | ✅ Complete | ✅ Complete | ✅ Complete | ✅ Complete | ✅ Complete | ✅ Complete |
| FixedScript Wallet: Transaction Support | ⏳ TODO | ⏳ TODO | ⏳ TODO | ⏳ TODO | ⏳ TODO | ⏳ TODO | ⏳ TODO |

## Building

Expand Down
56 changes: 56 additions & 0 deletions packages/wasm-utxo/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,36 @@ export type DescriptorPkType = "derivable" | "definite" | "string";

export type ScriptContext = "tap" | "segwitv0" | "legacy";

export type AddressFormat = "default" | "cashaddr";

export type SignPsbtResult = {
[inputIndex: number]: [pubkey: string][];
};

// BitGo coin names (from Network::from_coin_name in src/networks.rs)
export type CoinName =
| "btc"
| "tbtc"
| "tbtc4"
| "tbtcsig"
| "tbtcbgsig"
| "bch"
| "tbch"
| "bcha"
| "tbcha"
| "btg"
| "tbtg"
| "bsv"
| "tbsv"
| "dash"
| "tdash"
| "doge"
| "tdoge"
| "ltc"
| "tltc"
| "zec"
| "tzec";

declare module "./wasm/wasm_utxo" {
interface WrapDescriptor {
/** These are not the same types of nodes as in the ast module */
Expand All @@ -37,16 +63,46 @@ declare module "./wasm/wasm_utxo" {
signWithXprv(this: WrapPsbt, xprv: string): SignPsbtResult;
signWithPrv(this: WrapPsbt, prv: Uint8Array): SignPsbtResult;
}

interface Address {
/**
* Convert output script to address string
* @param script - The output script as a byte array
* @param network - The utxolib Network object from JavaScript
* @param format - Optional address format: "default" or "cashaddr" (only applicable for Bitcoin Cash and eCash)
*/
fromOutputScript(script: Uint8Array, network: any, format?: AddressFormat): string;
/**
* Convert address string to output script
* @param address - The address string
* @param network - The utxolib Network object from JavaScript
* @param format - Optional address format (currently unused for decoding as all formats are accepted)
*/
toOutputScript(address: string, network: any, format?: AddressFormat): Uint8Array;
}
}

import { Address as WasmAddress } from "./wasm/wasm_utxo";

export { WrapDescriptor as Descriptor } from "./wasm/wasm_utxo";
export { WrapMiniscript as Miniscript } from "./wasm/wasm_utxo";
export { WrapPsbt as Psbt } from "./wasm/wasm_utxo";
export { FixedScriptWallet } from "./wasm/wasm_utxo";

export namespace utxolibCompat {
export const Address = WasmAddress;
}

export function toOutputScriptWithCoin(address: string, coin: CoinName): Uint8Array {
return wasm.toOutputScriptWithCoin(address, coin);
}

export function fromOutputScriptWithCoin(
script: Uint8Array,
coin: CoinName,
format?: AddressFormat,
): string {
return wasm.fromOutputScriptWithCoin(script, coin, format);
}

export * as ast from "./ast";
4 changes: 2 additions & 2 deletions packages/wasm-utxo/src/address/cashaddr.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Cashaddr encoding/decoding module for Bitcoin Cash and eCash.
//!
//! Implements the cashaddr checksum algorithm as defined in:
//! - Spec: https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/cashaddr.md
//! - Reference implementation: https://github.com/Bitcoin-ABC/bitcoin-abc/blob/master/src/cashaddr.cpp
//! - Spec: <https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/cashaddr.md>
//! - Reference implementation: <https://github.com/Bitcoin-ABC/bitcoin-abc/blob/master/src/cashaddr.cpp>
//!
//! This implementation directly follows the official specification and passes all test vectors.
//!
Expand Down
15 changes: 10 additions & 5 deletions packages/wasm-utxo/src/address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@
mod base58check;
mod bech32;
pub mod cashaddr;
pub mod networks;
pub mod utxolib_compat;

pub use base58check::Base58CheckCodec;
pub use bech32::Bech32Codec;
pub use cashaddr::CashAddrCodec;
pub use networks::{
from_output_script_with_coin, from_output_script_with_network, to_output_script_with_coin,
to_output_script_with_network,
};

use crate::bitcoin::{Script, ScriptBuf};
use std::fmt;
Expand Down Expand Up @@ -172,11 +177,6 @@ pub fn from_output_script(script: &Script, codec: &dyn AddressCodec) -> Result<S
codec.encode(script)
}

/// Convert address string to output script (convenience wrapper)
pub fn to_output_script(address: &str, codec: &dyn AddressCodec) -> Result<ScriptBuf> {
codec.decode(address)
}

/// Try multiple codecs to decode an address
pub fn to_output_script_try_codecs(
address: &str,
Expand All @@ -200,6 +200,11 @@ mod tests {
use crate::bitcoin::hashes::Hash;
use crate::bitcoin::PubkeyHash;

/// Convert address string to output script (convenience wrapper)
pub fn to_output_script(address: &str, codec: &dyn AddressCodec) -> Result<ScriptBuf> {
codec.decode(address)
}

#[test]
fn test_base58_roundtrip() {
let hash = hex::decode("1e231c7f9b3415daaa53ee5a7e12e120f00ec212").unwrap();
Expand Down
Loading