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
26 changes: 2 additions & 24 deletions package-lock.json

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

10 changes: 2 additions & 8 deletions packages/wasm-utxo-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"private": true,
"scripts": {
"build": "webpack --mode production --progress --config ./webpack.config.js",
"typecheck": "tsc --noEmit",
"test": "echo \"Error: no test specified\"",
"dev": "webpack serve --mode development --progress --hot --config ./webpack.config.js",
"fmt": "prettier --write .",
Expand All @@ -21,19 +22,12 @@
"deploy": "gh-pages -d dist"
},
"dependencies": {
"@bitgo/utxo-lib": "^10.1.0",
"@bitgo/wasm-utxo": "*",
"assert": "^2.1.0",
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
"fp-ts": "^2.16.8",
"io-ts": "^2.2.21",
"io-ts-types": "^0.5.19",
"monocle-ts": "^2.3.13",
"newtype-ts": "^0.3.5",
"process": "^0.11.10",
"stream-browserify": "^3.0.0",
"vm-browserify": "^1.1.2"
"newtype-ts": "^0.3.5"
},
"devDependencies": {
"css-loader": "^7.1.2",
Expand Down
9 changes: 4 additions & 5 deletions packages/wasm-utxo-ui/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as utxolib from "@bitgo/utxo-lib";
import { Descriptor, Miniscript, ScriptContext } from "@bitgo/wasm-utxo";
import { address, CoinName, Descriptor, Miniscript, ScriptContext } from "@bitgo/wasm-utxo";

import "./style.css";

Expand Down Expand Up @@ -33,8 +32,8 @@ const elDescriptorAst = getElement("output-descriptor-ast", HTMLDivElement);
const elMiniscriptAst = getElement("output-miniscript-ast", HTMLDivElement);
const elStatus = getElement("status", HTMLElement);

function toAddress(scriptPubkeyBytes: Uint8Array, network: utxolib.Network) {
return utxolib.address.fromOutputScript(Buffer.from(scriptPubkeyBytes), network);
function toAddress(scriptPubkeyBytes: Uint8Array, coin: CoinName) {
return address.fromOutputScriptWithCoin(scriptPubkeyBytes, coin);
}

function setHtmlContent(el: HTMLElement, content: HTMLElement | undefined) {
Expand Down Expand Up @@ -137,7 +136,7 @@ function applyUpdateWith(
if (scriptPubkeyBytes) {
elScriptPubkeyBytes.value = toHex(scriptPubkeyBytes);
try {
elAddress.value = toAddress(scriptPubkeyBytes, utxolib.networks.bitcoin);
elAddress.value = toAddress(scriptPubkeyBytes, "btc");
} catch (e: any) {
elAddress.value = `error: ${e.message}`;
}
Expand Down
1 change: 1 addition & 0 deletions packages/wasm-utxo-ui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"composite": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
Expand Down
12 changes: 0 additions & 12 deletions packages/wasm-utxo-ui/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
Expand All @@ -23,13 +22,6 @@ module.exports = {
},
resolve: {
extensions: [".ts", ".js"],
fallback: {
buffer: require.resolve("buffer/"),
assert: require.resolve("assert/"),
stream: require.resolve("stream-browserify"),
crypto: require.resolve("crypto-browserify"),
vm: require.resolve("vm-browserify"),
},
},
output: {
filename: "bundle.js",
Expand All @@ -39,10 +31,6 @@ module.exports = {
new HtmlWebpackPlugin({
template: "./src/index.html",
}),
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
process: "process/browser",
}),
],
mode: "development",
experiments: {
Expand Down
5 changes: 3 additions & 2 deletions packages/wasm-utxo/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extension": ["js", "ts"],
"node-option": ["import=tsx"]
"extensions": ["ts", "tsx", "js", "jsx"],
"spec": ["test/**/*.ts"],
"node-option": ["import=tsx/esm", "experimental-wasm-modules"]
}
15 changes: 8 additions & 7 deletions packages/wasm-utxo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ define SHOW_WASM_SIZE
@find $(1) -name "*.wasm" -exec gzip -k {} \;
@find $(1) -name "*.wasm" -exec du -h {} \;
@find $(1) -name "*.wasm.gz" -exec du -h {} \;
@find $(1) -name "*.wasm.gz" -delete
endef

define BUILD
Expand All @@ -35,15 +36,15 @@ endef

.PHONY: js/wasm/
js/wasm/:
$(call BUILD,$@,nodejs)
$(call BUILD,$@,bundler)

.PHONY: dist/node/js/wasm/
dist/node/js/wasm/:
$(call BUILD,$@,nodejs)
.PHONY: dist/esm/wasm/
dist/esm/wasm/:
$(call BUILD,$@,bundler)

.PHONY: dist/browser/js/wasm/
dist/browser/js/wasm/:
$(call BUILD,$@,browser)
.PHONY: dist/cjs/wasm/
dist/cjs/wasm/:
$(call BUILD,$@,nodejs)

.PHONY: lint
lint:
Expand Down
48 changes: 48 additions & 0 deletions packages/wasm-utxo/bundler-test/test-cjs-import.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Test script to verify CommonJS compatibility
* Run with: node bundler-test/test-cjs-import.cjs
*/

console.log("Testing CommonJS require() compatibility...\n");

// Use standard CommonJS require
let wasmUtxo;
try {
wasmUtxo = require("../dist/cjs/index.js");
} catch (error) {
console.error("✗ require() failed:", error.message);
process.exit(1);
}

console.log("✓ require() successful from CJS context");
console.log("✓ Available exports:", Object.keys(wasmUtxo).join(", "));

// Test that we can access the main APIs
if (wasmUtxo.Descriptor) {
console.log("✓ Descriptor API available");
}
if (wasmUtxo.Psbt) {
console.log("✓ Psbt API available");
}
if (wasmUtxo.address) {
console.log("✓ address namespace available");
}
if (wasmUtxo.fixedScriptWallet) {
console.log("✓ fixedScriptWallet namespace available");
}

// Try to use the Descriptor API
try {
const descriptor = wasmUtxo.Descriptor.fromString(
"wpkh(xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL/0/*)",
"derivable",
);
console.log("✓ Descriptor.fromString() works");
console.log(" Descriptor type:", descriptor.descType());
} catch (err) {
console.log("✗ Descriptor test failed:", err.message);
process.exit(1);
}

console.log("\n✅ All CJS compatibility tests passed!");
console.log("\nCJS consumers can use standard require() with this package.");
35 changes: 35 additions & 0 deletions packages/wasm-utxo/bundler-test/test-esm-import.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Test script to verify ESM import works correctly
* Run with: node --experimental-wasm-modules bundler-test/test-esm-import.mjs
*/

import { Descriptor, Psbt, address, fixedScriptWallet } from "../dist/esm/index.js";

console.log("Testing ESM import...\n");

console.log("✓ ESM import successful");
console.log("✓ Descriptor API available");
console.log("✓ Psbt API available");
console.log("✓ address namespace available");
console.log("✓ fixedScriptWallet namespace available");

// Test that we can use the Descriptor API
try {
const descriptor = Descriptor.fromString(
"wpkh(xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL/0/*)",
"derivable",
);
console.log("✓ Descriptor.fromString() works");
console.log(" Descriptor type:", descriptor.descType());

// Test address derivation
const derived = descriptor.atDerivationIndex(0);
console.log("✓ Descriptor derivation works");
console.log(" Script pubkey length:", derived.scriptPubkey().length);
} catch (err) {
console.log("✗ Descriptor test failed:", err.message);
process.exit(1);
}

console.log("\n✅ All ESM tests passed!");
console.log("\nThis is the primary/recommended way to use this package.");
Loading