@vbyte/btc-dev 1.0.7 → 1.0.8
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/class/tx.d.ts +6 -6
- package/dist/class/tx.js +10 -6
- package/dist/class/witness.d.ts +3 -3
- package/dist/class/witness.js +1 -10
- package/dist/lib/witness/parse.js +2 -1
- package/dist/main.cjs +12 -16
- package/dist/main.cjs.map +1 -1
- package/dist/module.mjs +12 -16
- package/dist/module.mjs.map +1 -1
- package/dist/package.json +1 -1
- package/dist/script.js +1 -1
- package/dist/script.js.map +1 -1
- package/dist/types/class.d.ts +2 -12
- package/dist/types/witness.d.ts +1 -0
- package/package.json +1 -1
- package/src/class/tx.ts +13 -7
- package/src/class/witness.ts +2 -12
- package/src/lib/witness/parse.ts +2 -1
- package/src/types/class.ts +2 -13
- package/src/types/witness.ts +1 -0
package/dist/types/class.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LocktimeData, SequenceData } from './meta.js';
|
|
2
2
|
import type { TxOutput, TxOutputType, TxSize, TxValue } from './txdata.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { WitnessData, WitnessVersion } from './witness.js';
|
|
4
4
|
export interface LocktimeField {
|
|
5
5
|
hex: string;
|
|
6
6
|
data: LocktimeData | null;
|
|
@@ -27,16 +27,6 @@ export interface TransactionData {
|
|
|
27
27
|
vin: TransactionInputData[];
|
|
28
28
|
vout: TransactionOutputData[];
|
|
29
29
|
}
|
|
30
|
-
export interface WitnessField {
|
|
31
|
-
annex: string | null;
|
|
32
|
-
cblock: string | null;
|
|
33
|
-
params: string[];
|
|
34
|
-
script: ScriptField | null;
|
|
35
|
-
size: WitnessSize;
|
|
36
|
-
stack: string[];
|
|
37
|
-
type: WitnessType;
|
|
38
|
-
version: WitnessVersion;
|
|
39
|
-
}
|
|
40
30
|
export interface TransactionInputData {
|
|
41
31
|
coinbase?: string | null;
|
|
42
32
|
prevout?: TransactionOutputData | null;
|
|
@@ -45,7 +35,7 @@ export interface TransactionInputData {
|
|
|
45
35
|
size: number;
|
|
46
36
|
txid: string;
|
|
47
37
|
vout: number;
|
|
48
|
-
witness?:
|
|
38
|
+
witness?: WitnessData | null;
|
|
49
39
|
}
|
|
50
40
|
export interface TransactionOutputData {
|
|
51
41
|
script_pk: ScriptField;
|
package/dist/types/witness.d.ts
CHANGED
package/package.json
CHANGED
package/src/class/tx.ts
CHANGED
|
@@ -13,16 +13,18 @@ import {
|
|
|
13
13
|
get_tx_value,
|
|
14
14
|
get_txhash,
|
|
15
15
|
encode_tx_locktime,
|
|
16
|
+
create_tx_input,
|
|
17
|
+
create_tx_output,
|
|
16
18
|
} from '@/lib/tx/index.js'
|
|
17
19
|
|
|
18
20
|
import type {
|
|
19
21
|
TxData,
|
|
20
22
|
TxTemplate,
|
|
21
23
|
TransactionData,
|
|
22
|
-
TxInput,
|
|
23
24
|
TxOutput,
|
|
24
25
|
TxSize,
|
|
25
|
-
TxValue
|
|
26
|
+
TxValue,
|
|
27
|
+
TxInputTemplate
|
|
26
28
|
} from '@/types/index.js'
|
|
27
29
|
|
|
28
30
|
export class Transaction {
|
|
@@ -36,7 +38,7 @@ export class Transaction {
|
|
|
36
38
|
private _vin : TransactionInput[]
|
|
37
39
|
private _vout : TransactionOutput[]
|
|
38
40
|
|
|
39
|
-
constructor (txdata : string | TxData | TxTemplate) {
|
|
41
|
+
constructor (txdata : string | TxData | TxTemplate = {}) {
|
|
40
42
|
this._tx = (typeof txdata !== 'string')
|
|
41
43
|
? parse_tx(txdata)
|
|
42
44
|
: decode_tx(txdata)
|
|
@@ -109,18 +111,21 @@ export class Transaction {
|
|
|
109
111
|
return this._vout
|
|
110
112
|
}
|
|
111
113
|
|
|
112
|
-
add_vin (
|
|
114
|
+
add_vin (tx_input : TxInputTemplate) {
|
|
115
|
+
const txin = create_tx_input(tx_input)
|
|
113
116
|
this._tx.vin.push(txin)
|
|
114
117
|
this._update_vin()
|
|
115
118
|
}
|
|
116
119
|
|
|
117
|
-
add_vout (
|
|
120
|
+
add_vout (tx_output : TxOutput) {
|
|
121
|
+
const txout = create_tx_output(tx_output)
|
|
118
122
|
this._tx.vout.push(txout)
|
|
119
123
|
this._update_vout()
|
|
120
124
|
}
|
|
121
125
|
|
|
122
|
-
insert_vin (index : number,
|
|
126
|
+
insert_vin (index : number, tx_input : TxInputTemplate) {
|
|
123
127
|
Assert.ok(index >= 0 && index <= this._tx.vin.length, 'input goes out of bounds')
|
|
128
|
+
const txin = create_tx_input(tx_input)
|
|
124
129
|
if (index === this._tx.vin.length) {
|
|
125
130
|
this._tx.vin.push(txin)
|
|
126
131
|
} else {
|
|
@@ -129,8 +134,9 @@ export class Transaction {
|
|
|
129
134
|
this._update_vin()
|
|
130
135
|
}
|
|
131
136
|
|
|
132
|
-
insert_vout (index : number,
|
|
137
|
+
insert_vout (index : number, tx_output : TxOutput) {
|
|
133
138
|
Assert.ok(index >= 0 && index <= this._tx.vout.length, 'output goes out of bounds')
|
|
139
|
+
const txout = create_tx_output(tx_output)
|
|
134
140
|
if (index === this._tx.vout.length) {
|
|
135
141
|
this._tx.vout.push(txout)
|
|
136
142
|
} else {
|
package/src/class/witness.ts
CHANGED
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
|
|
10
10
|
import type {
|
|
11
11
|
ScriptField,
|
|
12
|
-
WitnessField,
|
|
13
12
|
WitnessData,
|
|
14
13
|
WitnessSize,
|
|
15
14
|
WitnessType
|
|
@@ -36,17 +35,8 @@ export class TransactionWitness {
|
|
|
36
35
|
return this._data.cblock
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
get data () :
|
|
40
|
-
return
|
|
41
|
-
annex : this.annex,
|
|
42
|
-
cblock : this.cblock,
|
|
43
|
-
params : this.params,
|
|
44
|
-
script : this.script,
|
|
45
|
-
size : this.size,
|
|
46
|
-
stack : this.stack,
|
|
47
|
-
type : this.type,
|
|
48
|
-
version : this.version
|
|
49
|
-
}
|
|
38
|
+
get data () : WitnessData {
|
|
39
|
+
return this._data
|
|
50
40
|
}
|
|
51
41
|
|
|
52
42
|
get params () : string[] {
|
package/src/lib/witness/parse.ts
CHANGED
|
@@ -12,6 +12,7 @@ export function parse_witness (
|
|
|
12
12
|
) : WitnessData {
|
|
13
13
|
// Parse the witness data.
|
|
14
14
|
const elems = witness.map(e => Buff.bytes(e))
|
|
15
|
+
const stack = witness.map(e => Buff.bytes(e).hex)
|
|
15
16
|
const annex = parse_annex_data(elems)
|
|
16
17
|
if (annex !== null) elems.pop()
|
|
17
18
|
const cblock = parse_cblock_data(elems)
|
|
@@ -21,7 +22,7 @@ export function parse_witness (
|
|
|
21
22
|
const script = parse_witness_script(elems, type)
|
|
22
23
|
if (script !== null) elems.pop()
|
|
23
24
|
const params = elems.map(e => e.hex)
|
|
24
|
-
return { annex, cblock, params, script, type, version }
|
|
25
|
+
return { annex, cblock, params, script, stack, type, version }
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
function parse_annex_data (
|
package/src/types/class.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LocktimeData, SequenceData } from './meta.js'
|
|
2
2
|
import type { TxOutput, TxOutputType, TxSize, TxValue } from './txdata.js'
|
|
3
|
-
import type {
|
|
3
|
+
import type { WitnessData, WitnessVersion } from './witness.js'
|
|
4
4
|
|
|
5
5
|
export interface LocktimeField {
|
|
6
6
|
hex : string
|
|
@@ -32,17 +32,6 @@ export interface TransactionData {
|
|
|
32
32
|
vout : TransactionOutputData[]
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export interface WitnessField {
|
|
36
|
-
annex : string | null
|
|
37
|
-
cblock : string | null
|
|
38
|
-
params : string[]
|
|
39
|
-
script : ScriptField | null
|
|
40
|
-
size : WitnessSize
|
|
41
|
-
stack : string[]
|
|
42
|
-
type : WitnessType
|
|
43
|
-
version : WitnessVersion
|
|
44
|
-
}
|
|
45
|
-
|
|
46
35
|
export interface TransactionInputData {
|
|
47
36
|
coinbase? : string | null
|
|
48
37
|
prevout? : TransactionOutputData | null
|
|
@@ -51,7 +40,7 @@ export interface TransactionInputData {
|
|
|
51
40
|
size : number
|
|
52
41
|
txid : string
|
|
53
42
|
vout : number
|
|
54
|
-
witness? :
|
|
43
|
+
witness? : WitnessData | null
|
|
55
44
|
}
|
|
56
45
|
|
|
57
46
|
export interface TransactionOutputData {
|