@vbyte/btc-dev 1.1.2 → 1.1.3
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/lib/signer/sign.js +2 -2
- package/dist/lib/tx/util.d.ts +3 -3
- package/dist/lib/tx/util.js +15 -8
- package/dist/main.cjs +4125 -4309
- package/dist/main.cjs.map +1 -1
- package/dist/module.mjs +4125 -4309
- package/dist/module.mjs.map +1 -1
- package/dist/package.json +2 -2
- package/dist/schema/taproot.d.ts +5 -15
- package/dist/schema/tx.d.ts +44 -262
- package/dist/script.js +8 -9
- package/dist/script.js.map +1 -1
- package/package.json +2 -2
- package/src/lib/signer/sign.ts +2 -2
- package/src/lib/tx/util.ts +38 -23
package/dist/lib/signer/sign.js
CHANGED
|
@@ -7,14 +7,14 @@ import { hash_taproot_tx } from '../../lib/sighash/taproot.js';
|
|
|
7
7
|
export function sign_segwit_tx(seckey, txdata, options) {
|
|
8
8
|
const tx = parse_tx(txdata);
|
|
9
9
|
const msg = hash_segwit_tx(tx, options);
|
|
10
|
-
const sig = ECC.
|
|
10
|
+
const sig = ECC.sign_ecdsa(seckey, msg).hex;
|
|
11
11
|
const flag = format_sigflag(options.sigflag ?? SIGHASH_DEFAULT);
|
|
12
12
|
return sig + flag;
|
|
13
13
|
}
|
|
14
14
|
export function sign_taproot_tx(seckey, txdata, options) {
|
|
15
15
|
const tx = parse_tx(txdata);
|
|
16
16
|
const msg = hash_taproot_tx(tx, options);
|
|
17
|
-
const sig = ECC.
|
|
17
|
+
const sig = ECC.sign_bip340(seckey, msg).hex;
|
|
18
18
|
const flag = format_sigflag(options.sigflag ?? 0);
|
|
19
19
|
return sig + flag;
|
|
20
20
|
}
|
package/dist/lib/tx/util.d.ts
CHANGED
|
@@ -4,9 +4,9 @@ export declare function is_return_script(script: Bytes): boolean;
|
|
|
4
4
|
export declare function get_vout_script_info(script: Bytes): TxOutputInfo;
|
|
5
5
|
export declare function get_vout_script_type(script: Bytes): TxOutputType | null;
|
|
6
6
|
export declare function get_vout_script_version(script: Bytes): WitnessVersion | null;
|
|
7
|
-
export declare function get_txid(txdata: TxData): string;
|
|
8
|
-
export declare function get_txhash(txdata: TxData): string;
|
|
9
|
-
export declare function get_tx_value(txdata: TxData): TxValue;
|
|
7
|
+
export declare function get_txid(txdata: string | Uint8Array | TxData): string;
|
|
8
|
+
export declare function get_txhash(txdata: string | Uint8Array | TxData): string;
|
|
9
|
+
export declare function get_tx_value(txdata: string | Uint8Array | TxData): TxValue;
|
|
10
10
|
export declare function get_prevouts(txdata: TxData): TxOutput[];
|
|
11
11
|
export declare function normalize_sequence(sequence?: number | string | null): number;
|
|
12
12
|
export declare function normalize_value(value: number | bigint): bigint;
|
package/dist/lib/tx/util.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Test } from '@vbyte/micro-lib';
|
|
|
3
3
|
import { Assert } from '@vbyte/micro-lib/assert';
|
|
4
4
|
import { hash256 } from '@vbyte/micro-lib/hash';
|
|
5
5
|
import { encode_tx } from './encode.js';
|
|
6
|
+
import { parse_tx } from './parse.js';
|
|
6
7
|
import { assert_tx_template } from './validate.js';
|
|
7
8
|
import { DEFAULT, LOCK_SCRIPT_REGEX } from '../../const.js';
|
|
8
9
|
export function is_return_script(script) {
|
|
@@ -32,18 +33,24 @@ export function get_vout_script_version(script) {
|
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
export function get_txid(txdata) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
if (typeof txdata === 'object') {
|
|
37
|
+
assert_tx_template(txdata);
|
|
38
|
+
txdata = encode_tx(txdata, false);
|
|
39
|
+
}
|
|
40
|
+
return hash256(txdata).reverse().hex;
|
|
38
41
|
}
|
|
39
42
|
export function get_txhash(txdata) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
if (typeof txdata === 'object') {
|
|
44
|
+
assert_tx_template(txdata);
|
|
45
|
+
txdata = encode_tx(txdata, true);
|
|
46
|
+
}
|
|
47
|
+
return hash256(txdata).reverse().hex;
|
|
43
48
|
}
|
|
44
49
|
export function get_tx_value(txdata) {
|
|
45
|
-
const
|
|
46
|
-
|
|
50
|
+
const tx = parse_tx(txdata);
|
|
51
|
+
assert_tx_template(tx);
|
|
52
|
+
const vin = tx.vin.reduce((acc, txin) => acc + (txin.prevout?.value ?? 0n), 0n);
|
|
53
|
+
const vout = tx.vout.reduce((acc, txout) => acc + txout.value, 0n);
|
|
47
54
|
const fees = (vin > vout) ? (vin - vout) : 0n;
|
|
48
55
|
return { fees, vin, vout };
|
|
49
56
|
}
|