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
4 changes: 2 additions & 2 deletions packages/wasm-utxo/cli/src/parse/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bitcoin::consensus::Decodable;
use bitcoin::hashes::Hash;
use bitcoin::psbt::Psbt;
use bitcoin::{Network, ScriptBuf, Transaction};
use wasm_utxo::bitgo_psbt::{
use wasm_utxo::fixed_script_wallet::bitgo_psbt::{
p2tr_musig2_input::{Musig2PartialSig, Musig2Participants, Musig2PubNonce},
BitGoKeyValue, ProprietaryKeySubtype, BITGO,
};
Expand Down Expand Up @@ -56,7 +56,7 @@ fn musig2_participants_to_node(participants: &Musig2Participants) -> Node {

let mut participants_node = Node::new("participant_pub_keys", Primitive::U64(2));
for (i, pub_key) in participants.participant_pub_keys.iter().enumerate() {
let pub_key_vec: Vec<u8> = pub_key.to_bytes().to_vec();
let pub_key_vec: Vec<u8> = pub_key.to_bytes().as_slice().to_vec();
participants_node.add_child(Node::new(
format!("participant_{}", i),
Primitive::Buffer(pub_key_vec),
Expand Down
67 changes: 66 additions & 1 deletion packages/wasm-utxo/js/fixedScriptWallet.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { FixedScriptWalletNamespace } from "./wasm/wasm_utxo";
import type { UtxolibNetwork, UtxolibRootWalletKeys } from "./utxolibCompat";
import type { UtxolibName, UtxolibNetwork, UtxolibRootWalletKeys } from "./utxolibCompat";
import type { CoinName } from "./coinName";
import { Triple } from "./triple";
import { AddressFormat } from "./address";

export type NetworkName = UtxolibName | CoinName;

export type WalletKeys =
/** Just an xpub triple, will assume default derivation prefixes */
| Triple<string>
Expand Down Expand Up @@ -42,3 +45,65 @@ export function address(
): string {
return FixedScriptWalletNamespace.address(keys, chain, index, network, addressFormat);
}

type ReplayProtection =
| {
outputScripts: Uint8Array[];
}
| {
addresses: string[];
};

export type ScriptId = { chain: number; index: number };

export type ParsedInput = {
address?: string;
script: Uint8Array;
value: bigint;
scriptId: ScriptId | undefined;
};

export type ParsedOutput = {
address?: string;
script: Uint8Array;
value: bigint;
scriptId?: ScriptId;
};

export type ParsedTransaction = {
inputs: ParsedInput[];
outputs: ParsedOutput[];
spendAmount: bigint;
minerFee: bigint;
virtualSize: number;
};

import { BitGoPsbt as WasmBitGoPsbt } from "./wasm/wasm_utxo";

export class BitGoPsbt {
private constructor(private wasm: WasmBitGoPsbt) {}

/**
* Deserialize a PSBT from bytes
* @param bytes - The PSBT bytes
* @param network - The network to use for deserialization (either utxolib name like "bitcoin" or coin name like "btc")
* @returns A BitGoPsbt instance
*/
static fromBytes(bytes: Uint8Array, network: NetworkName): BitGoPsbt {
const wasm = WasmBitGoPsbt.fromBytes(bytes, network);
return new BitGoPsbt(wasm);
}

/**
* Parse transaction with wallet keys to identify wallet inputs/outputs
* @param walletKeys - The wallet keys to use for identification
* @param replayProtection - Scripts that are allowed as inputs without wallet validation
* @returns Parsed transaction information
*/
parseTransactionWithWalletKeys(
walletKeys: WalletKeys,
replayProtection: ReplayProtection,
): ParsedTransaction {
return this.wasm.parseTransactionWithWalletKeys(walletKeys, replayProtection);
}
}
23 changes: 23 additions & 0 deletions packages/wasm-utxo/js/utxolibCompat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@ import type { AddressFormat } from "./address";
import { Triple } from "./triple";
import { UtxolibCompatNamespace } from "./wasm/wasm_utxo";

export type UtxolibName =
| "bitcoin"
| "testnet"
| "bitcoinTestnet4"
| "bitcoinPublicSignet"
| "bitcoinBitGoSignet"
| "bitcoincash"
| "bitcoincashTestnet"
| "ecash"
| "ecashTest"
| "bitcoingold"
| "bitcoingoldTestnet"
| "bitcoinsv"
| "bitcoinsvTestnet"
| "dash"
| "dashTest"
| "dogecoin"
| "dogecoinTest"
| "litecoin"
| "litecoinTest"
| "zcash"
| "zcashTest";

export type BIP32Interface = {
network: {
bip32: {
Expand Down
Loading