@vbyte/btc-dev 1.1.1 → 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 +8 -7
- package/dist/lib/tx/util.js +29 -20
- package/dist/main.cjs +4129 -4311
- package/dist/main.cjs.map +1 -1
- package/dist/module.mjs +4129 -4311
- 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/dist/types/meta.d.ts +3 -3
- package/package.json +2 -2
- package/src/lib/signer/sign.ts +2 -2
- package/src/lib/tx/util.ts +53 -36
- package/src/types/meta.ts +3 -3
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
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { Bytes } from '@vbyte/buff';
|
|
1
2
|
import type { TxData, TxOutput, TxOutputInfo, TxOutputTemplate, TxOutputType, TxValue, WitnessVersion } from '../../types/index.js';
|
|
2
|
-
export declare function is_return_script(script:
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function get_txid(txdata: TxData): string;
|
|
7
|
-
export declare function get_txhash(txdata: TxData): string;
|
|
8
|
-
export declare function get_tx_value(txdata: TxData): TxValue;
|
|
3
|
+
export declare function is_return_script(script: Bytes): boolean;
|
|
4
|
+
export declare function get_vout_script_info(script: Bytes): TxOutputInfo;
|
|
5
|
+
export declare function get_vout_script_type(script: Bytes): TxOutputType | null;
|
|
6
|
+
export declare function get_vout_script_version(script: Bytes): WitnessVersion | null;
|
|
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;
|
|
9
10
|
export declare function get_prevouts(txdata: TxData): TxOutput[];
|
|
10
11
|
export declare function normalize_sequence(sequence?: number | string | null): number;
|
|
11
12
|
export declare function normalize_value(value: number | bigint): bigint;
|
package/dist/lib/tx/util.js
CHANGED
|
@@ -3,45 +3,54 @@ 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) {
|
|
9
|
-
|
|
10
|
+
const bytes = Buff.bytes(script);
|
|
11
|
+
return bytes.at(0) === 0x6a;
|
|
10
12
|
}
|
|
11
|
-
export function
|
|
13
|
+
export function get_vout_script_info(script) {
|
|
12
14
|
return {
|
|
13
|
-
type:
|
|
14
|
-
version:
|
|
15
|
+
type: get_vout_script_type(script),
|
|
16
|
+
version: get_vout_script_version(script)
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
|
-
export function
|
|
19
|
+
export function get_vout_script_type(script) {
|
|
20
|
+
const hex = Buff.bytes(script).hex;
|
|
18
21
|
for (const [type, regex] of Object.entries(LOCK_SCRIPT_REGEX)) {
|
|
19
|
-
if (regex.test(
|
|
22
|
+
if (regex.test(hex))
|
|
20
23
|
return type;
|
|
21
24
|
}
|
|
22
|
-
return
|
|
25
|
+
return null;
|
|
23
26
|
}
|
|
24
|
-
export function
|
|
25
|
-
const
|
|
26
|
-
switch (
|
|
27
|
-
case
|
|
28
|
-
case
|
|
27
|
+
export function get_vout_script_version(script) {
|
|
28
|
+
const version = Buff.bytes(script);
|
|
29
|
+
switch (version.at(0)) {
|
|
30
|
+
case 0x00: return 0;
|
|
31
|
+
case 0x51: return 1;
|
|
29
32
|
default: return null;
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
export function get_txid(txdata) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
if (typeof txdata === 'object') {
|
|
37
|
+
assert_tx_template(txdata);
|
|
38
|
+
txdata = encode_tx(txdata, false);
|
|
39
|
+
}
|
|
40
|
+
return hash256(txdata).reverse().hex;
|
|
36
41
|
}
|
|
37
42
|
export function get_txhash(txdata) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
if (typeof txdata === 'object') {
|
|
44
|
+
assert_tx_template(txdata);
|
|
45
|
+
txdata = encode_tx(txdata, true);
|
|
46
|
+
}
|
|
47
|
+
return hash256(txdata).reverse().hex;
|
|
41
48
|
}
|
|
42
49
|
export function get_tx_value(txdata) {
|
|
43
|
-
const
|
|
44
|
-
|
|
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);
|
|
45
54
|
const fees = (vin > vout) ? (vin - vout) : 0n;
|
|
46
55
|
return { fees, vin, vout };
|
|
47
56
|
}
|