@bitgo/wasm-utxo 1.17.0 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.d.ts +7 -2
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.js +35 -28
- package/dist/cjs/js/fixedScriptWallet/Dimensions.d.ts +65 -0
- package/dist/cjs/js/fixedScriptWallet/Dimensions.js +83 -0
- package/dist/cjs/js/fixedScriptWallet/index.d.ts +1 -0
- package/dist/cjs/js/fixedScriptWallet/index.js +3 -1
- package/dist/cjs/js/index.d.ts +1 -0
- package/dist/cjs/js/index.js +3 -1
- package/dist/cjs/js/transaction.d.ts +8 -0
- package/dist/cjs/js/transaction.js +10 -0
- package/dist/cjs/js/wasm/wasm_utxo.d.ts +72 -1
- package/dist/cjs/js/wasm/wasm_utxo.js +194 -1
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +43 -32
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.d.ts +7 -2
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.js +35 -28
- package/dist/esm/js/fixedScriptWallet/Dimensions.d.ts +65 -0
- package/dist/esm/js/fixedScriptWallet/Dimensions.js +79 -0
- package/dist/esm/js/fixedScriptWallet/index.d.ts +1 -0
- package/dist/esm/js/fixedScriptWallet/index.js +1 -0
- package/dist/esm/js/index.d.ts +1 -0
- package/dist/esm/js/index.js +1 -0
- package/dist/esm/js/transaction.d.ts +8 -0
- package/dist/esm/js/transaction.js +10 -0
- package/dist/esm/js/wasm/wasm_utxo.d.ts +72 -1
- package/dist/esm/js/wasm/wasm_utxo_bg.js +193 -1
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +43 -32
- package/package.json +1 -1
|
@@ -181,6 +181,10 @@ const WasmDashTransactionFinalization = (typeof FinalizationRegistry === 'undefi
|
|
|
181
181
|
? { register: () => {}, unregister: () => {} }
|
|
182
182
|
: new FinalizationRegistry(ptr => wasm.__wbg_wasmdashtransaction_free(ptr >>> 0, 1));
|
|
183
183
|
|
|
184
|
+
const WasmDimensionsFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
185
|
+
? { register: () => {}, unregister: () => {} }
|
|
186
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmdimensions_free(ptr >>> 0, 1));
|
|
187
|
+
|
|
184
188
|
const WasmECPairFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
185
189
|
? { register: () => {}, unregister: () => {} }
|
|
186
190
|
: new FinalizationRegistry(ptr => wasm.__wbg_wasmecpair_free(ptr >>> 0, 1));
|
|
@@ -639,7 +643,7 @@ class BitGoPsbt {
|
|
|
639
643
|
* Extract the final transaction from a finalized PSBT
|
|
640
644
|
*
|
|
641
645
|
* This method should be called after all inputs have been finalized.
|
|
642
|
-
* It extracts the fully signed transaction.
|
|
646
|
+
* It extracts the fully signed transaction with network-appropriate serialization.
|
|
643
647
|
*
|
|
644
648
|
* # Returns
|
|
645
649
|
* - `Ok(Vec<u8>)` containing the serialized transaction bytes
|
|
@@ -1735,6 +1739,181 @@ class WasmDashTransaction {
|
|
|
1735
1739
|
if (Symbol.dispose) WasmDashTransaction.prototype[Symbol.dispose] = WasmDashTransaction.prototype.free;
|
|
1736
1740
|
exports.WasmDashTransaction = WasmDashTransaction;
|
|
1737
1741
|
|
|
1742
|
+
/**
|
|
1743
|
+
* Dimensions for estimating transaction virtual size.
|
|
1744
|
+
*
|
|
1745
|
+
* Tracks weight internally with min/max bounds to handle ECDSA signature variance.
|
|
1746
|
+
* Schnorr signatures have no variance (always 64 bytes).
|
|
1747
|
+
*/
|
|
1748
|
+
class WasmDimensions {
|
|
1749
|
+
static __wrap(ptr) {
|
|
1750
|
+
ptr = ptr >>> 0;
|
|
1751
|
+
const obj = Object.create(WasmDimensions.prototype);
|
|
1752
|
+
obj.__wbg_ptr = ptr;
|
|
1753
|
+
WasmDimensionsFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
1754
|
+
return obj;
|
|
1755
|
+
}
|
|
1756
|
+
__destroy_into_raw() {
|
|
1757
|
+
const ptr = this.__wbg_ptr;
|
|
1758
|
+
this.__wbg_ptr = 0;
|
|
1759
|
+
WasmDimensionsFinalization.unregister(this);
|
|
1760
|
+
return ptr;
|
|
1761
|
+
}
|
|
1762
|
+
free() {
|
|
1763
|
+
const ptr = this.__destroy_into_raw();
|
|
1764
|
+
wasm.__wbg_wasmdimensions_free(ptr, 0);
|
|
1765
|
+
}
|
|
1766
|
+
/**
|
|
1767
|
+
* Create dimensions for a single input from chain code
|
|
1768
|
+
*
|
|
1769
|
+
* # Arguments
|
|
1770
|
+
* * `chain` - Chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
|
|
1771
|
+
* * `signer` - Optional signer key ("user", "backup", "bitgo")
|
|
1772
|
+
* * `cosigner` - Optional cosigner key ("user", "backup", "bitgo")
|
|
1773
|
+
* @param {number} chain
|
|
1774
|
+
* @param {string | null} [signer]
|
|
1775
|
+
* @param {string | null} [cosigner]
|
|
1776
|
+
* @returns {WasmDimensions}
|
|
1777
|
+
*/
|
|
1778
|
+
static from_input(chain, signer, cosigner) {
|
|
1779
|
+
try {
|
|
1780
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1781
|
+
var ptr0 = isLikeNone(signer) ? 0 : passStringToWasm0(signer, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1782
|
+
var len0 = WASM_VECTOR_LEN;
|
|
1783
|
+
var ptr1 = isLikeNone(cosigner) ? 0 : passStringToWasm0(cosigner, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1784
|
+
var len1 = WASM_VECTOR_LEN;
|
|
1785
|
+
wasm.wasmdimensions_from_input(retptr, chain, ptr0, len0, ptr1, len1);
|
|
1786
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1787
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1788
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1789
|
+
if (r2) {
|
|
1790
|
+
throw takeObject(r1);
|
|
1791
|
+
}
|
|
1792
|
+
return WasmDimensions.__wrap(r0);
|
|
1793
|
+
} finally {
|
|
1794
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
/**
|
|
1798
|
+
* Get total weight (min or max)
|
|
1799
|
+
*
|
|
1800
|
+
* # Arguments
|
|
1801
|
+
* * `size` - "min" or "max", defaults to "max"
|
|
1802
|
+
* @param {string | null} [size]
|
|
1803
|
+
* @returns {number}
|
|
1804
|
+
*/
|
|
1805
|
+
get_weight(size) {
|
|
1806
|
+
var ptr0 = isLikeNone(size) ? 0 : passStringToWasm0(size, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1807
|
+
var len0 = WASM_VECTOR_LEN;
|
|
1808
|
+
const ret = wasm.wasmdimensions_get_weight(this.__wbg_ptr, ptr0, len0);
|
|
1809
|
+
return ret >>> 0;
|
|
1810
|
+
}
|
|
1811
|
+
/**
|
|
1812
|
+
* Whether any inputs are segwit (affects overhead calculation)
|
|
1813
|
+
* @returns {boolean}
|
|
1814
|
+
*/
|
|
1815
|
+
has_segwit() {
|
|
1816
|
+
const ret = wasm.wasmdimensions_has_segwit(this.__wbg_ptr);
|
|
1817
|
+
return ret !== 0;
|
|
1818
|
+
}
|
|
1819
|
+
/**
|
|
1820
|
+
* Create dimensions for a single output from script bytes
|
|
1821
|
+
* @param {Uint8Array} script
|
|
1822
|
+
* @returns {WasmDimensions}
|
|
1823
|
+
*/
|
|
1824
|
+
static from_output_script(script) {
|
|
1825
|
+
const ptr0 = passArray8ToWasm0(script, wasm.__wbindgen_export);
|
|
1826
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1827
|
+
const ret = wasm.wasmdimensions_from_output_script(ptr0, len0);
|
|
1828
|
+
return WasmDimensions.__wrap(ret);
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* Create dimensions for a single input from script type string
|
|
1832
|
+
*
|
|
1833
|
+
* # Arguments
|
|
1834
|
+
* * `script_type` - One of: "p2sh", "p2shP2wsh", "p2wsh", "p2trLegacy",
|
|
1835
|
+
* "p2trMusig2KeyPath", "p2trMusig2ScriptPath", "p2shP2pk"
|
|
1836
|
+
* @param {string} script_type
|
|
1837
|
+
* @returns {WasmDimensions}
|
|
1838
|
+
*/
|
|
1839
|
+
static from_input_script_type(script_type) {
|
|
1840
|
+
try {
|
|
1841
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1842
|
+
const ptr0 = passStringToWasm0(script_type, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1843
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1844
|
+
wasm.wasmdimensions_from_input_script_type(retptr, ptr0, len0);
|
|
1845
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1846
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1847
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1848
|
+
if (r2) {
|
|
1849
|
+
throw takeObject(r1);
|
|
1850
|
+
}
|
|
1851
|
+
return WasmDimensions.__wrap(r0);
|
|
1852
|
+
} finally {
|
|
1853
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
/**
|
|
1857
|
+
* Combine with another Dimensions instance
|
|
1858
|
+
* @param {WasmDimensions} other
|
|
1859
|
+
* @returns {WasmDimensions}
|
|
1860
|
+
*/
|
|
1861
|
+
plus(other) {
|
|
1862
|
+
_assertClass(other, WasmDimensions);
|
|
1863
|
+
const ret = wasm.wasmdimensions_plus(this.__wbg_ptr, other.__wbg_ptr);
|
|
1864
|
+
return WasmDimensions.__wrap(ret);
|
|
1865
|
+
}
|
|
1866
|
+
/**
|
|
1867
|
+
* Create empty dimensions (zero weight)
|
|
1868
|
+
* @returns {WasmDimensions}
|
|
1869
|
+
*/
|
|
1870
|
+
static empty() {
|
|
1871
|
+
const ret = wasm.wasmdimensions_empty();
|
|
1872
|
+
return WasmDimensions.__wrap(ret);
|
|
1873
|
+
}
|
|
1874
|
+
/**
|
|
1875
|
+
* Create dimensions from a BitGoPsbt
|
|
1876
|
+
*
|
|
1877
|
+
* Parses PSBT inputs and outputs to compute weight bounds without
|
|
1878
|
+
* requiring wallet keys. Input types are detected from BIP32 derivation
|
|
1879
|
+
* paths stored in the PSBT.
|
|
1880
|
+
* @param {BitGoPsbt} psbt
|
|
1881
|
+
* @returns {WasmDimensions}
|
|
1882
|
+
*/
|
|
1883
|
+
static from_psbt(psbt) {
|
|
1884
|
+
try {
|
|
1885
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1886
|
+
_assertClass(psbt, BitGoPsbt);
|
|
1887
|
+
wasm.wasmdimensions_from_psbt(retptr, psbt.__wbg_ptr);
|
|
1888
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1889
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1890
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1891
|
+
if (r2) {
|
|
1892
|
+
throw takeObject(r1);
|
|
1893
|
+
}
|
|
1894
|
+
return WasmDimensions.__wrap(r0);
|
|
1895
|
+
} finally {
|
|
1896
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
/**
|
|
1900
|
+
* Get virtual size (min or max)
|
|
1901
|
+
*
|
|
1902
|
+
* # Arguments
|
|
1903
|
+
* * `size` - "min" or "max", defaults to "max"
|
|
1904
|
+
* @param {string | null} [size]
|
|
1905
|
+
* @returns {number}
|
|
1906
|
+
*/
|
|
1907
|
+
get_vsize(size) {
|
|
1908
|
+
var ptr0 = isLikeNone(size) ? 0 : passStringToWasm0(size, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1909
|
+
var len0 = WASM_VECTOR_LEN;
|
|
1910
|
+
const ret = wasm.wasmdimensions_get_vsize(this.__wbg_ptr, ptr0, len0);
|
|
1911
|
+
return ret >>> 0;
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
if (Symbol.dispose) WasmDimensions.prototype[Symbol.dispose] = WasmDimensions.prototype.free;
|
|
1915
|
+
exports.WasmDimensions = WasmDimensions;
|
|
1916
|
+
|
|
1738
1917
|
/**
|
|
1739
1918
|
* WASM wrapper for elliptic curve key pairs (always uses compressed keys)
|
|
1740
1919
|
*/
|
|
@@ -2258,6 +2437,20 @@ class WasmTransaction {
|
|
|
2258
2437
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
2259
2438
|
}
|
|
2260
2439
|
}
|
|
2440
|
+
/**
|
|
2441
|
+
* Get the virtual size of the transaction
|
|
2442
|
+
*
|
|
2443
|
+
* Virtual size is calculated as ceil(weight / 4), where weight accounts
|
|
2444
|
+
* for the segwit discount on witness data.
|
|
2445
|
+
*
|
|
2446
|
+
* # Returns
|
|
2447
|
+
* The virtual size in virtual bytes (vbytes)
|
|
2448
|
+
* @returns {number}
|
|
2449
|
+
*/
|
|
2450
|
+
get_vsize() {
|
|
2451
|
+
const ret = wasm.wasmtransaction_get_vsize(this.__wbg_ptr);
|
|
2452
|
+
return ret >>> 0;
|
|
2453
|
+
}
|
|
2261
2454
|
}
|
|
2262
2455
|
if (Symbol.dispose) WasmTransaction.prototype[Symbol.dispose] = WasmTransaction.prototype.free;
|
|
2263
2456
|
exports.WasmTransaction = WasmTransaction;
|
|
Binary file
|
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_utxolibcompatnamespace_free: (a: number, b: number) => void;
|
|
5
|
+
export const __wbg_wasmdashtransaction_free: (a: number, b: number) => void;
|
|
6
|
+
export const __wbg_wasmreplayprotection_free: (a: number, b: number) => void;
|
|
7
|
+
export const __wbg_wasmtransaction_free: (a: number, b: number) => void;
|
|
8
|
+
export const __wbg_wasmzcashtransaction_free: (a: number, b: number) => void;
|
|
4
9
|
export const __wbg_wrapdescriptor_free: (a: number, b: number) => void;
|
|
10
|
+
export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
|
|
11
|
+
export const __wbg_wrappsbt_free: (a: number, b: number) => void;
|
|
12
|
+
export const utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
13
|
+
export const utxolibcompatnamespace_to_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
14
|
+
export const wasmdashtransaction_from_bytes: (a: number, b: number, c: number) => void;
|
|
15
|
+
export const wasmdashtransaction_to_bytes: (a: number, b: number) => void;
|
|
16
|
+
export const wasmreplayprotection_from_addresses: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
17
|
+
export const wasmreplayprotection_from_output_scripts: (a: number, b: number) => number;
|
|
18
|
+
export const wasmreplayprotection_from_public_keys: (a: number, b: number, c: number) => void;
|
|
19
|
+
export const wasmtransaction_from_bytes: (a: number, b: number, c: number) => void;
|
|
20
|
+
export const wasmtransaction_get_vsize: (a: number) => number;
|
|
21
|
+
export const wasmtransaction_to_bytes: (a: number, b: number) => void;
|
|
22
|
+
export const wasmzcashtransaction_from_bytes: (a: number, b: number, c: number) => void;
|
|
23
|
+
export const wasmzcashtransaction_to_bytes: (a: number, b: number) => void;
|
|
5
24
|
export const wrapdescriptor_atDerivationIndex: (a: number, b: number, c: number) => void;
|
|
6
25
|
export const wrapdescriptor_descType: (a: number, b: number) => void;
|
|
7
26
|
export const wrapdescriptor_encode: (a: number, b: number) => void;
|
|
@@ -13,16 +32,27 @@ export const wrapdescriptor_node: (a: number, b: number) => void;
|
|
|
13
32
|
export const wrapdescriptor_scriptPubkey: (a: number, b: number) => void;
|
|
14
33
|
export const wrapdescriptor_toAsmString: (a: number, b: number) => void;
|
|
15
34
|
export const wrapdescriptor_toString: (a: number, b: number) => void;
|
|
35
|
+
export const wrapminiscript_encode: (a: number, b: number) => void;
|
|
36
|
+
export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
37
|
+
export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
38
|
+
export const wrapminiscript_node: (a: number, b: number) => void;
|
|
39
|
+
export const wrapminiscript_toAsmString: (a: number, b: number) => void;
|
|
40
|
+
export const wrapminiscript_toString: (a: number, b: number) => void;
|
|
41
|
+
export const wrappsbt_clone: (a: number) => number;
|
|
42
|
+
export const wrappsbt_deserialize: (a: number, b: number, c: number) => void;
|
|
43
|
+
export const wrappsbt_finalize: (a: number, b: number) => void;
|
|
44
|
+
export const wrappsbt_serialize: (a: number, b: number) => void;
|
|
45
|
+
export const wrappsbt_signWithPrv: (a: number, b: number, c: number, d: number) => void;
|
|
46
|
+
export const wrappsbt_signWithXprv: (a: number, b: number, c: number, d: number) => void;
|
|
47
|
+
export const wrappsbt_updateInputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
48
|
+
export const wrappsbt_updateOutputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
16
49
|
export const __wbg_addressnamespace_free: (a: number, b: number) => void;
|
|
17
50
|
export const __wbg_bitgopsbt_free: (a: number, b: number) => void;
|
|
18
51
|
export const __wbg_fixedscriptwalletnamespace_free: (a: number, b: number) => void;
|
|
19
52
|
export const __wbg_wasmbip32_free: (a: number, b: number) => void;
|
|
53
|
+
export const __wbg_wasmdimensions_free: (a: number, b: number) => void;
|
|
20
54
|
export const __wbg_wasmecpair_free: (a: number, b: number) => void;
|
|
21
|
-
export const __wbg_wasmreplayprotection_free: (a: number, b: number) => void;
|
|
22
55
|
export const __wbg_wasmrootwalletkeys_free: (a: number, b: number) => void;
|
|
23
|
-
export const __wbg_wasmtransaction_free: (a: number, b: number) => void;
|
|
24
|
-
export const __wbg_wasmzcashtransaction_free: (a: number, b: number) => void;
|
|
25
|
-
export const __wbg_wrappsbt_free: (a: number, b: number) => void;
|
|
26
56
|
export const addressnamespace_from_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
27
57
|
export const addressnamespace_to_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
28
58
|
export const bitgopsbt_add_input: (a: number, b: number, c: number, d: number, e: number, f: bigint, g: number, h: number, i: number, j: number, k: number) => void;
|
|
@@ -75,6 +105,15 @@ export const wasmbip32_private_key: (a: number) => number;
|
|
|
75
105
|
export const wasmbip32_public_key: (a: number) => number;
|
|
76
106
|
export const wasmbip32_to_base58: (a: number, b: number) => void;
|
|
77
107
|
export const wasmbip32_to_wif: (a: number, b: number) => void;
|
|
108
|
+
export const wasmdimensions_empty: () => number;
|
|
109
|
+
export const wasmdimensions_from_input: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
110
|
+
export const wasmdimensions_from_input_script_type: (a: number, b: number, c: number) => void;
|
|
111
|
+
export const wasmdimensions_from_output_script: (a: number, b: number) => number;
|
|
112
|
+
export const wasmdimensions_from_psbt: (a: number, b: number) => void;
|
|
113
|
+
export const wasmdimensions_get_vsize: (a: number, b: number, c: number) => number;
|
|
114
|
+
export const wasmdimensions_get_weight: (a: number, b: number, c: number) => number;
|
|
115
|
+
export const wasmdimensions_has_segwit: (a: number) => number;
|
|
116
|
+
export const wasmdimensions_plus: (a: number, b: number) => number;
|
|
78
117
|
export const wasmecpair_from_private_key: (a: number, b: number, c: number) => void;
|
|
79
118
|
export const wasmecpair_from_public_key: (a: number, b: number, c: number) => void;
|
|
80
119
|
export const wasmecpair_from_wif: (a: number, b: number, c: number) => void;
|
|
@@ -85,40 +124,12 @@ export const wasmecpair_public_key: (a: number) => number;
|
|
|
85
124
|
export const wasmecpair_to_wif: (a: number, b: number) => void;
|
|
86
125
|
export const wasmecpair_to_wif_mainnet: (a: number, b: number) => void;
|
|
87
126
|
export const wasmecpair_to_wif_testnet: (a: number, b: number) => void;
|
|
88
|
-
export const wasmreplayprotection_from_addresses: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
89
|
-
export const wasmreplayprotection_from_output_scripts: (a: number, b: number) => number;
|
|
90
|
-
export const wasmreplayprotection_from_public_keys: (a: number, b: number, c: number) => void;
|
|
91
127
|
export const wasmrootwalletkeys_backup_key: (a: number) => number;
|
|
92
128
|
export const wasmrootwalletkeys_bitgo_key: (a: number) => number;
|
|
93
129
|
export const wasmrootwalletkeys_new: (a: number, b: number, c: number, d: number) => void;
|
|
94
130
|
export const wasmrootwalletkeys_user_key: (a: number) => number;
|
|
95
131
|
export const wasmrootwalletkeys_with_derivation_prefixes: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
|
|
96
|
-
export const wasmtransaction_from_bytes: (a: number, b: number, c: number) => void;
|
|
97
|
-
export const wasmtransaction_to_bytes: (a: number, b: number) => void;
|
|
98
|
-
export const wasmzcashtransaction_from_bytes: (a: number, b: number, c: number) => void;
|
|
99
|
-
export const wasmzcashtransaction_to_bytes: (a: number, b: number) => void;
|
|
100
|
-
export const wrappsbt_clone: (a: number) => number;
|
|
101
|
-
export const wrappsbt_deserialize: (a: number, b: number, c: number) => void;
|
|
102
|
-
export const wrappsbt_finalize: (a: number, b: number) => void;
|
|
103
|
-
export const wrappsbt_serialize: (a: number, b: number) => void;
|
|
104
|
-
export const wrappsbt_signWithPrv: (a: number, b: number, c: number, d: number) => void;
|
|
105
|
-
export const wrappsbt_signWithXprv: (a: number, b: number, c: number, d: number) => void;
|
|
106
|
-
export const wrappsbt_updateInputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
107
|
-
export const wrappsbt_updateOutputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
108
132
|
export const wasmbip32_from_bip32_properties: (a: number, b: number) => void;
|
|
109
|
-
export const __wbg_utxolibcompatnamespace_free: (a: number, b: number) => void;
|
|
110
|
-
export const __wbg_wasmdashtransaction_free: (a: number, b: number) => void;
|
|
111
|
-
export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
|
|
112
|
-
export const utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
113
|
-
export const utxolibcompatnamespace_to_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
114
|
-
export const wasmdashtransaction_from_bytes: (a: number, b: number, c: number) => void;
|
|
115
|
-
export const wasmdashtransaction_to_bytes: (a: number, b: number) => void;
|
|
116
|
-
export const wrapminiscript_encode: (a: number, b: number) => void;
|
|
117
|
-
export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
118
|
-
export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
119
|
-
export const wrapminiscript_node: (a: number, b: number) => void;
|
|
120
|
-
export const wrapminiscript_toAsmString: (a: number, b: number) => void;
|
|
121
|
-
export const wrapminiscript_toString: (a: number, b: number) => void;
|
|
122
133
|
export const rustsecp256k1_v0_10_0_context_create: (a: number) => number;
|
|
123
134
|
export const rustsecp256k1_v0_10_0_context_destroy: (a: number) => void;
|
|
124
135
|
export const rustsecp256k1_v0_10_0_default_error_callback_fn: (a: number, b: number) => void;
|
|
@@ -86,8 +86,13 @@ export type AddWalletOutputOptions = {
|
|
|
86
86
|
value: bigint;
|
|
87
87
|
};
|
|
88
88
|
export declare class BitGoPsbt {
|
|
89
|
-
protected
|
|
90
|
-
protected constructor(
|
|
89
|
+
protected _wasm: WasmBitGoPsbt;
|
|
90
|
+
protected constructor(_wasm: WasmBitGoPsbt);
|
|
91
|
+
/**
|
|
92
|
+
* Get the underlying WASM instance
|
|
93
|
+
* @internal - for use by other wasm-utxo modules
|
|
94
|
+
*/
|
|
95
|
+
get wasm(): WasmBitGoPsbt;
|
|
91
96
|
/**
|
|
92
97
|
* Create an empty PSBT for the given network with wallet keys
|
|
93
98
|
*
|
|
@@ -4,9 +4,16 @@ import { ReplayProtection } from "./ReplayProtection.js";
|
|
|
4
4
|
import { BIP32 } from "../bip32.js";
|
|
5
5
|
import { ECPair } from "../ecpair.js";
|
|
6
6
|
export class BitGoPsbt {
|
|
7
|
-
|
|
8
|
-
constructor(
|
|
9
|
-
this.
|
|
7
|
+
_wasm;
|
|
8
|
+
constructor(_wasm) {
|
|
9
|
+
this._wasm = _wasm;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Get the underlying WASM instance
|
|
13
|
+
* @internal - for use by other wasm-utxo modules
|
|
14
|
+
*/
|
|
15
|
+
get wasm() {
|
|
16
|
+
return this._wasm;
|
|
10
17
|
}
|
|
11
18
|
/**
|
|
12
19
|
* Create an empty PSBT for the given network with wallet keys
|
|
@@ -32,8 +39,8 @@ export class BitGoPsbt {
|
|
|
32
39
|
*/
|
|
33
40
|
static createEmpty(network, walletKeys, options) {
|
|
34
41
|
const keys = RootWalletKeys.from(walletKeys);
|
|
35
|
-
const
|
|
36
|
-
return new BitGoPsbt(
|
|
42
|
+
const wasmPsbt = WasmBitGoPsbt.create_empty(network, keys.wasm, options?.version, options?.lockTime);
|
|
43
|
+
return new BitGoPsbt(wasmPsbt);
|
|
37
44
|
}
|
|
38
45
|
/**
|
|
39
46
|
* Deserialize a PSBT from bytes
|
|
@@ -65,7 +72,7 @@ export class BitGoPsbt {
|
|
|
65
72
|
* ```
|
|
66
73
|
*/
|
|
67
74
|
addInput(options, script) {
|
|
68
|
-
return this.
|
|
75
|
+
return this._wasm.add_input(options.txid, options.vout, options.value, script, options.sequence, options.prevTx);
|
|
69
76
|
}
|
|
70
77
|
/**
|
|
71
78
|
* Add an output to the PSBT
|
|
@@ -82,7 +89,7 @@ export class BitGoPsbt {
|
|
|
82
89
|
* ```
|
|
83
90
|
*/
|
|
84
91
|
addOutput(options) {
|
|
85
|
-
return this.
|
|
92
|
+
return this._wasm.add_output(options.script, options.value);
|
|
86
93
|
}
|
|
87
94
|
/**
|
|
88
95
|
* Add a wallet input with full PSBT metadata
|
|
@@ -125,7 +132,7 @@ export class BitGoPsbt {
|
|
|
125
132
|
*/
|
|
126
133
|
addWalletInput(inputOptions, walletKeys, walletOptions) {
|
|
127
134
|
const keys = RootWalletKeys.from(walletKeys);
|
|
128
|
-
return this.
|
|
135
|
+
return this._wasm.add_wallet_input(inputOptions.txid, inputOptions.vout, inputOptions.value, keys.wasm, walletOptions.scriptId.chain, walletOptions.scriptId.index, walletOptions.signPath?.signer, walletOptions.signPath?.cosigner, inputOptions.sequence, inputOptions.prevTx);
|
|
129
136
|
}
|
|
130
137
|
/**
|
|
131
138
|
* Add a wallet output with full PSBT metadata
|
|
@@ -159,7 +166,7 @@ export class BitGoPsbt {
|
|
|
159
166
|
*/
|
|
160
167
|
addWalletOutput(walletKeys, options) {
|
|
161
168
|
const keys = RootWalletKeys.from(walletKeys);
|
|
162
|
-
return this.
|
|
169
|
+
return this._wasm.add_wallet_output(options.chain, options.index, options.value, keys.wasm);
|
|
163
170
|
}
|
|
164
171
|
/**
|
|
165
172
|
* Add a replay protection input to the PSBT
|
|
@@ -182,28 +189,28 @@ export class BitGoPsbt {
|
|
|
182
189
|
*/
|
|
183
190
|
addReplayProtectionInput(inputOptions, key) {
|
|
184
191
|
const ecpair = ECPair.from(key);
|
|
185
|
-
return this.
|
|
192
|
+
return this._wasm.add_replay_protection_input(ecpair.wasm, inputOptions.txid, inputOptions.vout, inputOptions.value, inputOptions.sequence);
|
|
186
193
|
}
|
|
187
194
|
/**
|
|
188
195
|
* Get the unsigned transaction ID
|
|
189
196
|
* @returns The unsigned transaction ID
|
|
190
197
|
*/
|
|
191
198
|
unsignedTxid() {
|
|
192
|
-
return this.
|
|
199
|
+
return this._wasm.unsigned_txid();
|
|
193
200
|
}
|
|
194
201
|
/**
|
|
195
202
|
* Get the transaction version
|
|
196
203
|
* @returns The transaction version number
|
|
197
204
|
*/
|
|
198
205
|
get version() {
|
|
199
|
-
return this.
|
|
206
|
+
return this._wasm.version();
|
|
200
207
|
}
|
|
201
208
|
/**
|
|
202
209
|
* Get the transaction lock time
|
|
203
210
|
* @returns The transaction lock time
|
|
204
211
|
*/
|
|
205
212
|
get lockTime() {
|
|
206
|
-
return this.
|
|
213
|
+
return this._wasm.lock_time();
|
|
207
214
|
}
|
|
208
215
|
/**
|
|
209
216
|
* Parse transaction with wallet keys to identify wallet inputs/outputs
|
|
@@ -214,9 +221,9 @@ export class BitGoPsbt {
|
|
|
214
221
|
*/
|
|
215
222
|
parseTransactionWithWalletKeys(walletKeys, replayProtection, payGoPubkeys) {
|
|
216
223
|
const keys = RootWalletKeys.from(walletKeys);
|
|
217
|
-
const rp = ReplayProtection.from(replayProtection, this.
|
|
224
|
+
const rp = ReplayProtection.from(replayProtection, this._wasm.network());
|
|
218
225
|
const pubkeys = payGoPubkeys?.map((arg) => ECPair.from(arg).wasm);
|
|
219
|
-
return this.
|
|
226
|
+
return this._wasm.parse_transaction_with_wallet_keys(keys.wasm, rp.wasm, pubkeys);
|
|
220
227
|
}
|
|
221
228
|
/**
|
|
222
229
|
* Parse outputs with wallet keys to identify which outputs belong to a wallet
|
|
@@ -233,7 +240,7 @@ export class BitGoPsbt {
|
|
|
233
240
|
parseOutputsWithWalletKeys(walletKeys, payGoPubkeys) {
|
|
234
241
|
const keys = RootWalletKeys.from(walletKeys);
|
|
235
242
|
const pubkeys = payGoPubkeys?.map((arg) => ECPair.from(arg).wasm);
|
|
236
|
-
return this.
|
|
243
|
+
return this._wasm.parse_outputs_with_wallet_keys(keys.wasm, pubkeys);
|
|
237
244
|
}
|
|
238
245
|
/**
|
|
239
246
|
* Add a PayGo attestation to a PSBT output
|
|
@@ -247,7 +254,7 @@ export class BitGoPsbt {
|
|
|
247
254
|
* @throws Error if output index is out of bounds or entropy is not 64 bytes
|
|
248
255
|
*/
|
|
249
256
|
addPayGoAttestation(outputIndex, entropy, signature) {
|
|
250
|
-
this.
|
|
257
|
+
this._wasm.add_paygo_attestation(outputIndex, entropy, signature);
|
|
251
258
|
}
|
|
252
259
|
/**
|
|
253
260
|
* Verify if a valid signature exists for a given key at the specified input index.
|
|
@@ -288,11 +295,11 @@ export class BitGoPsbt {
|
|
|
288
295
|
// Try to parse as BIP32Arg first (string or BIP32 instance)
|
|
289
296
|
if (typeof key === "string" || ("derive" in key && typeof key.derive === "function")) {
|
|
290
297
|
const wasmKey = BIP32.from(key).wasm;
|
|
291
|
-
return this.
|
|
298
|
+
return this._wasm.verify_signature_with_xpub(inputIndex, wasmKey);
|
|
292
299
|
}
|
|
293
300
|
// Otherwise it's an ECPairArg (Uint8Array, ECPair, or WasmECPair)
|
|
294
301
|
const wasmECPair = ECPair.from(key).wasm;
|
|
295
|
-
return this.
|
|
302
|
+
return this._wasm.verify_signature_with_pub(inputIndex, wasmECPair);
|
|
296
303
|
}
|
|
297
304
|
/**
|
|
298
305
|
* Sign a single input with a private key
|
|
@@ -344,12 +351,12 @@ export class BitGoPsbt {
|
|
|
344
351
|
typeof key.derive === "function")) {
|
|
345
352
|
// It's a BIP32Arg
|
|
346
353
|
const wasmKey = BIP32.from(key);
|
|
347
|
-
this.
|
|
354
|
+
this._wasm.sign_with_xpriv(inputIndex, wasmKey.wasm);
|
|
348
355
|
}
|
|
349
356
|
else {
|
|
350
357
|
// It's an ECPairArg
|
|
351
358
|
const wasmKey = ECPair.from(key);
|
|
352
|
-
this.
|
|
359
|
+
this._wasm.sign_with_privkey(inputIndex, wasmKey.wasm);
|
|
353
360
|
}
|
|
354
361
|
}
|
|
355
362
|
/**
|
|
@@ -373,8 +380,8 @@ export class BitGoPsbt {
|
|
|
373
380
|
* @throws Error if the input is not a replay protection input, index is out of bounds, or scripts are invalid
|
|
374
381
|
*/
|
|
375
382
|
verifyReplayProtectionSignature(inputIndex, replayProtection) {
|
|
376
|
-
const rp = ReplayProtection.from(replayProtection, this.
|
|
377
|
-
return this.
|
|
383
|
+
const rp = ReplayProtection.from(replayProtection, this._wasm.network());
|
|
384
|
+
return this._wasm.verify_replay_protection_signature(inputIndex, rp.wasm);
|
|
378
385
|
}
|
|
379
386
|
/**
|
|
380
387
|
* Serialize the PSBT to bytes
|
|
@@ -382,7 +389,7 @@ export class BitGoPsbt {
|
|
|
382
389
|
* @returns The serialized PSBT as a byte array
|
|
383
390
|
*/
|
|
384
391
|
serialize() {
|
|
385
|
-
return this.
|
|
392
|
+
return this._wasm.serialize();
|
|
386
393
|
}
|
|
387
394
|
/**
|
|
388
395
|
* Generate and store MuSig2 nonces for all MuSig2 inputs
|
|
@@ -424,7 +431,7 @@ export class BitGoPsbt {
|
|
|
424
431
|
*/
|
|
425
432
|
generateMusig2Nonces(key, sessionId) {
|
|
426
433
|
const wasmKey = BIP32.from(key);
|
|
427
|
-
this.
|
|
434
|
+
this._wasm.generate_musig2_nonces(wasmKey.wasm, sessionId);
|
|
428
435
|
}
|
|
429
436
|
/**
|
|
430
437
|
* Combine/merge data from another PSBT into this one
|
|
@@ -446,7 +453,7 @@ export class BitGoPsbt {
|
|
|
446
453
|
* ```
|
|
447
454
|
*/
|
|
448
455
|
combineMusig2Nonces(sourcePsbt) {
|
|
449
|
-
this.
|
|
456
|
+
this._wasm.combine_musig2_nonces(sourcePsbt.wasm);
|
|
450
457
|
}
|
|
451
458
|
/**
|
|
452
459
|
* Finalize all inputs in the PSBT
|
|
@@ -454,7 +461,7 @@ export class BitGoPsbt {
|
|
|
454
461
|
* @throws Error if any input failed to finalize
|
|
455
462
|
*/
|
|
456
463
|
finalizeAllInputs() {
|
|
457
|
-
this.
|
|
464
|
+
this._wasm.finalize_all_inputs();
|
|
458
465
|
}
|
|
459
466
|
/**
|
|
460
467
|
* Extract the final transaction from a finalized PSBT
|
|
@@ -463,6 +470,6 @@ export class BitGoPsbt {
|
|
|
463
470
|
* @throws Error if the PSBT is not fully finalized or extraction fails
|
|
464
471
|
*/
|
|
465
472
|
extractTransaction() {
|
|
466
|
-
return this.
|
|
473
|
+
return this._wasm.extract_transaction();
|
|
467
474
|
}
|
|
468
475
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { BitGoPsbt, InputScriptType, SignPath } from "./BitGoPsbt.js";
|
|
2
|
+
import type { CoinName } from "../coinName.js";
|
|
3
|
+
type FromInputParams = {
|
|
4
|
+
chain: number;
|
|
5
|
+
signPath?: SignPath;
|
|
6
|
+
} | {
|
|
7
|
+
scriptType: InputScriptType;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Dimensions class for estimating transaction virtual size.
|
|
11
|
+
*
|
|
12
|
+
* Tracks weight internally with min/max bounds to handle ECDSA signature variance.
|
|
13
|
+
* Schnorr signatures have no variance (always 64 bytes).
|
|
14
|
+
*
|
|
15
|
+
* This is a thin wrapper over the WASM implementation.
|
|
16
|
+
*/
|
|
17
|
+
export declare class Dimensions {
|
|
18
|
+
private _wasm;
|
|
19
|
+
private constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Create empty dimensions (zero weight)
|
|
22
|
+
*/
|
|
23
|
+
static empty(): Dimensions;
|
|
24
|
+
/**
|
|
25
|
+
* Create dimensions from a BitGoPsbt
|
|
26
|
+
*
|
|
27
|
+
* Parses PSBT inputs and outputs to compute weight bounds without
|
|
28
|
+
* requiring wallet keys. Input types are detected from BIP32 derivation
|
|
29
|
+
* paths stored in the PSBT.
|
|
30
|
+
*/
|
|
31
|
+
static fromPsbt(psbt: BitGoPsbt): Dimensions;
|
|
32
|
+
/**
|
|
33
|
+
* Create dimensions for a single input
|
|
34
|
+
*
|
|
35
|
+
* @param params - Either `{ chain, signPath? }` or `{ scriptType }`
|
|
36
|
+
*/
|
|
37
|
+
static fromInput(params: FromInputParams): Dimensions;
|
|
38
|
+
/**
|
|
39
|
+
* Create dimensions for a single output from script bytes
|
|
40
|
+
*/
|
|
41
|
+
static fromOutput(script: Uint8Array): Dimensions;
|
|
42
|
+
/**
|
|
43
|
+
* Create dimensions for a single output from an address
|
|
44
|
+
*/
|
|
45
|
+
static fromOutput(address: string, network: CoinName): Dimensions;
|
|
46
|
+
/**
|
|
47
|
+
* Combine with another Dimensions instance
|
|
48
|
+
*/
|
|
49
|
+
plus(other: Dimensions): Dimensions;
|
|
50
|
+
/**
|
|
51
|
+
* Whether any inputs are segwit (affects overhead calculation)
|
|
52
|
+
*/
|
|
53
|
+
get hasSegwit(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Get total weight (min or max)
|
|
56
|
+
* @param size - "min" or "max", defaults to "max"
|
|
57
|
+
*/
|
|
58
|
+
getWeight(size?: "min" | "max"): number;
|
|
59
|
+
/**
|
|
60
|
+
* Get virtual size (min or max)
|
|
61
|
+
* @param size - "min" or "max", defaults to "max"
|
|
62
|
+
*/
|
|
63
|
+
getVSize(size?: "min" | "max"): number;
|
|
64
|
+
}
|
|
65
|
+
export {};
|