@vbyte/btc-dev 1.1.6 → 1.1.7
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/tx/decode.js +2 -3
- package/dist/lib/tx/util.d.ts +2 -0
- package/dist/lib/tx/util.js +21 -3
- package/dist/main.cjs +5976 -5695
- package/dist/main.cjs.map +1 -1
- package/dist/module.mjs +5976 -5695
- package/dist/module.mjs.map +1 -1
- package/dist/package.json +10 -10
- package/dist/schema/base.d.ts +40 -0
- package/dist/schema/base.js +42 -0
- package/dist/schema/taproot.js +1 -1
- package/dist/schema/tx.js +1 -1
- package/dist/script.js +8 -9
- package/dist/script.js.map +1 -1
- package/package.json +10 -10
- package/src/lib/tx/decode.ts +3 -3
- package/src/lib/tx/util.ts +28 -4
- package/src/schema/base.ts +57 -0
- package/src/schema/taproot.ts +1 -1
- package/src/schema/tx.ts +1 -1
package/dist/lib/tx/decode.js
CHANGED
|
@@ -6,9 +6,8 @@ export function decode_tx(txdata, use_segwit = true) {
|
|
|
6
6
|
Assert.is_bytes(txdata, 'txdata must be hex or bytes');
|
|
7
7
|
const stream = new Stream(txdata);
|
|
8
8
|
const version = read_version(stream);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
: false;
|
|
9
|
+
let has_witness = check_witness_flag(stream);
|
|
10
|
+
has_witness = (use_segwit) ? has_witness : false;
|
|
12
11
|
const vin = read_inputs(stream);
|
|
13
12
|
const vout = read_outputs(stream);
|
|
14
13
|
if (has_witness) {
|
package/dist/lib/tx/util.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Buff } from '@vbyte/buff';
|
|
1
2
|
import type { TxData, TxOutput, TxOutputTemplate, TxValue } from '../../types/index.js';
|
|
3
|
+
export declare function transcode_tx(txdata: string | Uint8Array, use_segwit?: boolean): Buff;
|
|
2
4
|
export declare function get_txid(txdata: string | Uint8Array | TxData): string;
|
|
3
5
|
export declare function get_txhash(txdata: string | Uint8Array | TxData): string;
|
|
4
6
|
export declare function get_tx_value(txdata: string | Uint8Array | TxData): TxValue;
|
package/dist/lib/tx/util.js
CHANGED
|
@@ -2,16 +2,34 @@ import { Buff } from '@vbyte/buff';
|
|
|
2
2
|
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
|
+
import { decode_tx } from './decode.js';
|
|
5
6
|
import { encode_tx } from './encode.js';
|
|
6
7
|
import { parse_tx } from './parse.js';
|
|
7
8
|
import { assert_tx_template } from './validate.js';
|
|
8
9
|
import { DEFAULT } from '../../const.js';
|
|
10
|
+
export function transcode_tx(txdata, use_segwit = true) {
|
|
11
|
+
console.log('txdata:', txdata);
|
|
12
|
+
const decoded = decode_tx(txdata);
|
|
13
|
+
console.log('decoded:', decoded);
|
|
14
|
+
return encode_tx(decoded, use_segwit);
|
|
15
|
+
}
|
|
9
16
|
export function get_txid(txdata) {
|
|
10
|
-
|
|
17
|
+
let buffer;
|
|
18
|
+
if (txdata instanceof Uint8Array) {
|
|
19
|
+
buffer = transcode_tx(txdata, false);
|
|
20
|
+
}
|
|
21
|
+
else if (typeof txdata === 'object') {
|
|
11
22
|
assert_tx_template(txdata);
|
|
12
|
-
|
|
23
|
+
buffer = encode_tx(txdata, false);
|
|
13
24
|
}
|
|
14
|
-
|
|
25
|
+
else if (typeof txdata === 'string') {
|
|
26
|
+
Assert.is_hex(txdata);
|
|
27
|
+
buffer = transcode_tx(txdata, false);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw new TypeError('invalid txdata type: ' + typeof txdata);
|
|
31
|
+
}
|
|
32
|
+
return hash256(buffer).reverse().hex;
|
|
15
33
|
}
|
|
16
34
|
export function get_txhash(txdata) {
|
|
17
35
|
if (typeof txdata === 'object') {
|