@vbyte/btc-dev 1.0.7 → 1.0.9
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 +9 -9
- package/dist/class/tx.js +11 -18
- package/dist/class/txin.d.ts +3 -3
- package/dist/class/txin.js +1 -10
- package/dist/class/txout.d.ts +3 -3
- package/dist/class/txout.js +1 -7
- 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 +15 -45
- package/dist/main.cjs.map +1 -1
- package/dist/module.mjs +15 -45
- 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/index.d.ts +0 -1
- package/dist/types/index.js +0 -1
- package/dist/types/meta.d.ts +24 -0
- package/dist/types/txdata.d.ts +1 -11
- package/dist/types/witness.d.ts +1 -0
- package/package.json +1 -1
- package/src/class/tx.ts +15 -21
- package/src/class/txin.ts +3 -15
- package/src/class/txout.ts +3 -9
- package/src/class/witness.ts +2 -12
- package/src/lib/witness/parse.ts +2 -1
- package/src/types/index.ts +0 -1
- package/src/types/meta.ts +30 -0
- package/src/types/txdata.ts +2 -15
- package/src/types/witness.ts +1 -0
- package/dist/types/class.d.ts +0 -56
- package/dist/types/class.js +0 -1
- package/src/types/class.ts +0 -63
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
package/dist/types/meta.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
import type { WitnessType, WitnessVersion } from './witness.js';
|
|
1
2
|
export type LocktimeData = LocktimeStamp | LocktimeHeight;
|
|
2
3
|
export type SequenceConfig = Partial<SequenceData>;
|
|
3
4
|
export type SequenceData = SequenceHeightLock | SequenceStampLock;
|
|
5
|
+
export type TxOutputType = WitnessType | 'p2pkh' | 'p2sh' | 'opreturn';
|
|
6
|
+
export interface TxOutputInfo {
|
|
7
|
+
type: TxOutputType;
|
|
8
|
+
version: WitnessVersion;
|
|
9
|
+
}
|
|
10
|
+
export interface TxInputInfo {
|
|
11
|
+
type: WitnessType;
|
|
12
|
+
version: WitnessVersion;
|
|
13
|
+
}
|
|
4
14
|
export interface LocktimeStamp {
|
|
5
15
|
type: 'timelock';
|
|
6
16
|
stamp: number;
|
|
@@ -17,6 +27,20 @@ export interface SequenceHeightLock {
|
|
|
17
27
|
height: number;
|
|
18
28
|
mode: 'height';
|
|
19
29
|
}
|
|
30
|
+
export interface LocktimeField {
|
|
31
|
+
hex: string;
|
|
32
|
+
data: LocktimeData | null;
|
|
33
|
+
value: number;
|
|
34
|
+
}
|
|
35
|
+
export interface SequenceField {
|
|
36
|
+
hex: string;
|
|
37
|
+
data: SequenceData | null;
|
|
38
|
+
value: number;
|
|
39
|
+
}
|
|
40
|
+
export interface ScriptField {
|
|
41
|
+
asm: string[];
|
|
42
|
+
hex: string;
|
|
43
|
+
}
|
|
20
44
|
export interface InscriptionData {
|
|
21
45
|
content?: string;
|
|
22
46
|
delegate?: string;
|
package/dist/types/txdata.d.ts
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import type { WitnessType, WitnessVersion } from './witness.js';
|
|
2
1
|
export type TxInput = TxCoinbaseInput | TxSpendInput | TxVirtualInput;
|
|
3
|
-
export type TxOutputType = WitnessType | 'p2pkh' | 'p2sh' | 'opreturn';
|
|
4
|
-
export interface TxOutputInfo {
|
|
5
|
-
type: TxOutputType;
|
|
6
|
-
version: WitnessVersion;
|
|
7
|
-
}
|
|
8
|
-
export interface TxInputInfo {
|
|
9
|
-
type: WitnessType;
|
|
10
|
-
version: WitnessVersion;
|
|
11
|
-
}
|
|
12
2
|
export interface TxOutpoint {
|
|
13
3
|
txid: string;
|
|
14
4
|
vout: number;
|
|
@@ -56,8 +46,8 @@ export interface TxData {
|
|
|
56
46
|
export interface TxSize {
|
|
57
47
|
base: number;
|
|
58
48
|
total: number;
|
|
59
|
-
weight: number;
|
|
60
49
|
vsize: number;
|
|
50
|
+
weight: number;
|
|
61
51
|
}
|
|
62
52
|
export interface TxValue {
|
|
63
53
|
fees: bigint;
|
package/dist/types/witness.d.ts
CHANGED
package/package.json
CHANGED
package/src/class/tx.ts
CHANGED
|
@@ -13,16 +13,17 @@ 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
|
-
TransactionData,
|
|
22
|
-
TxInput,
|
|
23
23
|
TxOutput,
|
|
24
24
|
TxSize,
|
|
25
|
-
TxValue
|
|
25
|
+
TxValue,
|
|
26
|
+
TxInputTemplate
|
|
26
27
|
} from '@/types/index.js'
|
|
27
28
|
|
|
28
29
|
export class Transaction {
|
|
@@ -36,7 +37,7 @@ export class Transaction {
|
|
|
36
37
|
private _vin : TransactionInput[]
|
|
37
38
|
private _vout : TransactionOutput[]
|
|
38
39
|
|
|
39
|
-
constructor (txdata : string | TxData | TxTemplate) {
|
|
40
|
+
constructor (txdata : string | TxData | TxTemplate = {}) {
|
|
40
41
|
this._tx = (typeof txdata !== 'string')
|
|
41
42
|
? parse_tx(txdata)
|
|
42
43
|
: decode_tx(txdata)
|
|
@@ -48,19 +49,8 @@ export class Transaction {
|
|
|
48
49
|
this._vout = this._tx.vout.map(txout => new TransactionOutput(txout))
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
get data () :
|
|
52
|
-
return
|
|
53
|
-
hash : this.hash,
|
|
54
|
-
locktime : this.locktime,
|
|
55
|
-
return : this.return,
|
|
56
|
-
size : this.size,
|
|
57
|
-
spends : this.spends,
|
|
58
|
-
txid : this.txid,
|
|
59
|
-
value : this.value,
|
|
60
|
-
version : this.version,
|
|
61
|
-
vin : this.vin.map(txin => txin.data),
|
|
62
|
-
vout : this.vout.map(txout => txout.data)
|
|
63
|
-
}
|
|
52
|
+
get data () : TxData {
|
|
53
|
+
return this._tx
|
|
64
54
|
}
|
|
65
55
|
|
|
66
56
|
get hash () : string {
|
|
@@ -109,18 +99,21 @@ export class Transaction {
|
|
|
109
99
|
return this._vout
|
|
110
100
|
}
|
|
111
101
|
|
|
112
|
-
add_vin (
|
|
102
|
+
add_vin (tx_input : TxInputTemplate) {
|
|
103
|
+
const txin = create_tx_input(tx_input)
|
|
113
104
|
this._tx.vin.push(txin)
|
|
114
105
|
this._update_vin()
|
|
115
106
|
}
|
|
116
107
|
|
|
117
|
-
add_vout (
|
|
108
|
+
add_vout (tx_output : TxOutput) {
|
|
109
|
+
const txout = create_tx_output(tx_output)
|
|
118
110
|
this._tx.vout.push(txout)
|
|
119
111
|
this._update_vout()
|
|
120
112
|
}
|
|
121
113
|
|
|
122
|
-
insert_vin (index : number,
|
|
114
|
+
insert_vin (index : number, tx_input : TxInputTemplate) {
|
|
123
115
|
Assert.ok(index >= 0 && index <= this._tx.vin.length, 'input goes out of bounds')
|
|
116
|
+
const txin = create_tx_input(tx_input)
|
|
124
117
|
if (index === this._tx.vin.length) {
|
|
125
118
|
this._tx.vin.push(txin)
|
|
126
119
|
} else {
|
|
@@ -129,8 +122,9 @@ export class Transaction {
|
|
|
129
122
|
this._update_vin()
|
|
130
123
|
}
|
|
131
124
|
|
|
132
|
-
insert_vout (index : number,
|
|
125
|
+
insert_vout (index : number, tx_output : TxOutput) {
|
|
133
126
|
Assert.ok(index >= 0 && index <= this._tx.vout.length, 'output goes out of bounds')
|
|
127
|
+
const txout = create_tx_output(tx_output)
|
|
134
128
|
if (index === this._tx.vout.length) {
|
|
135
129
|
this._tx.vout.push(txout)
|
|
136
130
|
} else {
|
package/src/class/txin.ts
CHANGED
|
@@ -8,10 +8,7 @@ import {
|
|
|
8
8
|
get_txin_size,
|
|
9
9
|
} from '@/lib/tx/index.js'
|
|
10
10
|
|
|
11
|
-
import type {
|
|
12
|
-
TxInput,
|
|
13
|
-
TransactionInputData
|
|
14
|
-
} from '@/types/index.js'
|
|
11
|
+
import type { TxInput } from '@/types/index.js'
|
|
15
12
|
|
|
16
13
|
export class TransactionInput {
|
|
17
14
|
|
|
@@ -25,17 +22,8 @@ export class TransactionInput {
|
|
|
25
22
|
return this._txin.coinbase
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
get data () :
|
|
29
|
-
return
|
|
30
|
-
coinbase : this.coinbase,
|
|
31
|
-
prevout : this.prevout?.data ?? null,
|
|
32
|
-
script_sig : this.script_sig,
|
|
33
|
-
sequence : this.sequence,
|
|
34
|
-
size : this.size,
|
|
35
|
-
txid : this.txid,
|
|
36
|
-
vout : this.vout,
|
|
37
|
-
witness : this.witness?.data ?? null
|
|
38
|
-
}
|
|
25
|
+
get data () : TxInput {
|
|
26
|
+
return this._txin
|
|
39
27
|
}
|
|
40
28
|
|
|
41
29
|
get has_prevout () : boolean {
|
package/src/class/txout.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
get_vout_version
|
|
7
7
|
} from '@/lib/tx/index.js'
|
|
8
8
|
|
|
9
|
-
import type { TxOutput
|
|
9
|
+
import type { TxOutput } from '@/types/index.js'
|
|
10
10
|
|
|
11
11
|
export class TransactionOutput {
|
|
12
12
|
|
|
@@ -16,14 +16,8 @@ export class TransactionOutput {
|
|
|
16
16
|
this._txout = txout
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
get data () :
|
|
20
|
-
return
|
|
21
|
-
script_pk : this.script_pk,
|
|
22
|
-
size : this.size,
|
|
23
|
-
type : this.type,
|
|
24
|
-
value : this.value,
|
|
25
|
-
version : this.version
|
|
26
|
-
}
|
|
19
|
+
get data () : TxOutput {
|
|
20
|
+
return this._txout
|
|
27
21
|
}
|
|
28
22
|
|
|
29
23
|
get script_pk () {
|
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/index.ts
CHANGED
package/src/types/meta.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
|
+
import type{ WitnessType, WitnessVersion } from './witness.js'
|
|
2
|
+
|
|
1
3
|
export type LocktimeData = LocktimeStamp | LocktimeHeight
|
|
2
4
|
export type SequenceConfig = Partial<SequenceData>
|
|
3
5
|
export type SequenceData = SequenceHeightLock | SequenceStampLock
|
|
6
|
+
export type TxOutputType = WitnessType | 'p2pkh' | 'p2sh' | 'opreturn'
|
|
7
|
+
|
|
8
|
+
export interface TxOutputInfo {
|
|
9
|
+
type : TxOutputType
|
|
10
|
+
version : WitnessVersion
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface TxInputInfo {
|
|
14
|
+
type : WitnessType
|
|
15
|
+
version : WitnessVersion
|
|
16
|
+
}
|
|
4
17
|
|
|
5
18
|
export interface LocktimeStamp {
|
|
6
19
|
type : 'timelock' // Discriminator for timelock type
|
|
@@ -24,6 +37,23 @@ export interface SequenceHeightLock {
|
|
|
24
37
|
mode : 'height' // Discriminator for heightlock mode.
|
|
25
38
|
}
|
|
26
39
|
|
|
40
|
+
export interface LocktimeField {
|
|
41
|
+
hex : string
|
|
42
|
+
data : LocktimeData | null
|
|
43
|
+
value : number
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface SequenceField {
|
|
47
|
+
hex : string
|
|
48
|
+
data : SequenceData | null
|
|
49
|
+
value : number
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface ScriptField {
|
|
53
|
+
asm : string[]
|
|
54
|
+
hex : string
|
|
55
|
+
}
|
|
56
|
+
|
|
27
57
|
export interface InscriptionData {
|
|
28
58
|
content ?: string
|
|
29
59
|
delegate ?: string
|
package/src/types/txdata.ts
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export type TxInput = TxCoinbaseInput | TxSpendInput | TxVirtualInput
|
|
4
|
-
export type TxOutputType = WitnessType | 'p2pkh' | 'p2sh' | 'opreturn'
|
|
5
|
-
|
|
6
|
-
export interface TxOutputInfo {
|
|
7
|
-
type : TxOutputType
|
|
8
|
-
version : WitnessVersion
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface TxInputInfo {
|
|
12
|
-
type : WitnessType
|
|
13
|
-
version : WitnessVersion
|
|
14
|
-
}
|
|
1
|
+
export type TxInput = TxCoinbaseInput | TxSpendInput | TxVirtualInput
|
|
15
2
|
|
|
16
3
|
export interface TxOutpoint {
|
|
17
4
|
txid : string
|
|
@@ -68,8 +55,8 @@ export interface TxData {
|
|
|
68
55
|
export interface TxSize {
|
|
69
56
|
base : number
|
|
70
57
|
total : number
|
|
71
|
-
weight : number
|
|
72
58
|
vsize : number
|
|
59
|
+
weight : number
|
|
73
60
|
}
|
|
74
61
|
|
|
75
62
|
export interface TxValue {
|
package/src/types/witness.ts
CHANGED
package/dist/types/class.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { LocktimeData, SequenceData } from './meta.js';
|
|
2
|
-
import type { TxOutput, TxOutputType, TxSize, TxValue } from './txdata.js';
|
|
3
|
-
import type { WitnessSize, WitnessType, WitnessVersion } from './witness.js';
|
|
4
|
-
export interface LocktimeField {
|
|
5
|
-
hex: string;
|
|
6
|
-
data: LocktimeData | null;
|
|
7
|
-
value: number;
|
|
8
|
-
}
|
|
9
|
-
export interface SequenceField {
|
|
10
|
-
hex: string;
|
|
11
|
-
data: SequenceData | null;
|
|
12
|
-
value: number;
|
|
13
|
-
}
|
|
14
|
-
export interface ScriptField {
|
|
15
|
-
asm: string[];
|
|
16
|
-
hex: string;
|
|
17
|
-
}
|
|
18
|
-
export interface TransactionData {
|
|
19
|
-
hash: string;
|
|
20
|
-
locktime: LocktimeField;
|
|
21
|
-
return: TxOutput | null;
|
|
22
|
-
size: TxSize;
|
|
23
|
-
spends: TransactionOutputData[];
|
|
24
|
-
txid: string;
|
|
25
|
-
value: TxValue;
|
|
26
|
-
version: number;
|
|
27
|
-
vin: TransactionInputData[];
|
|
28
|
-
vout: TransactionOutputData[];
|
|
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
|
-
export interface TransactionInputData {
|
|
41
|
-
coinbase?: string | null;
|
|
42
|
-
prevout?: TransactionOutputData | null;
|
|
43
|
-
script_sig?: ScriptField | null;
|
|
44
|
-
sequence: SequenceField;
|
|
45
|
-
size: number;
|
|
46
|
-
txid: string;
|
|
47
|
-
vout: number;
|
|
48
|
-
witness?: WitnessField | null;
|
|
49
|
-
}
|
|
50
|
-
export interface TransactionOutputData {
|
|
51
|
-
script_pk: ScriptField;
|
|
52
|
-
size: number;
|
|
53
|
-
type: TxOutputType;
|
|
54
|
-
value: bigint;
|
|
55
|
-
version: WitnessVersion | null;
|
|
56
|
-
}
|
package/dist/types/class.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/types/class.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { LocktimeData, SequenceData } from './meta.js'
|
|
2
|
-
import type { TxOutput, TxOutputType, TxSize, TxValue } from './txdata.js'
|
|
3
|
-
import type { WitnessSize, WitnessType, WitnessVersion } from './witness.js'
|
|
4
|
-
|
|
5
|
-
export interface LocktimeField {
|
|
6
|
-
hex : string
|
|
7
|
-
data : LocktimeData | null
|
|
8
|
-
value : number
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface SequenceField {
|
|
12
|
-
hex : string
|
|
13
|
-
data : SequenceData | null
|
|
14
|
-
value : number
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface ScriptField {
|
|
18
|
-
asm : string[]
|
|
19
|
-
hex : string
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface TransactionData {
|
|
23
|
-
hash : string
|
|
24
|
-
locktime : LocktimeField
|
|
25
|
-
return : TxOutput | null
|
|
26
|
-
size : TxSize
|
|
27
|
-
spends : TransactionOutputData[]
|
|
28
|
-
txid : string
|
|
29
|
-
value : TxValue
|
|
30
|
-
version : number
|
|
31
|
-
vin : TransactionInputData[]
|
|
32
|
-
vout : TransactionOutputData[]
|
|
33
|
-
}
|
|
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
|
-
export interface TransactionInputData {
|
|
47
|
-
coinbase? : string | null
|
|
48
|
-
prevout? : TransactionOutputData | null
|
|
49
|
-
script_sig? : ScriptField | null
|
|
50
|
-
sequence : SequenceField
|
|
51
|
-
size : number
|
|
52
|
-
txid : string
|
|
53
|
-
vout : number
|
|
54
|
-
witness? : WitnessField | null
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface TransactionOutputData {
|
|
58
|
-
script_pk : ScriptField
|
|
59
|
-
size : number
|
|
60
|
-
type : TxOutputType
|
|
61
|
-
value : bigint
|
|
62
|
-
version : WitnessVersion | null
|
|
63
|
-
}
|