@vbyte/btc-dev 1.1.1 → 1.1.2
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/util.d.ts +5 -4
- package/dist/lib/tx/util.js +14 -12
- package/dist/main.cjs +17 -15
- package/dist/main.cjs.map +1 -1
- package/dist/module.mjs +17 -15
- 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/meta.d.ts +3 -3
- package/package.json +1 -1
- package/src/lib/tx/util.ts +21 -19
- package/src/types/meta.ts +3 -3
package/dist/types/meta.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import type { WitnessType, WitnessVersion } from './witness.js';
|
|
|
2
2
|
export type LocktimeData = LocktimeStamp | LocktimeHeight;
|
|
3
3
|
export type SequenceConfig = Partial<SequenceData>;
|
|
4
4
|
export type SequenceData = SequenceHeightLock | SequenceStampLock;
|
|
5
|
-
export type TxOutputType =
|
|
5
|
+
export type TxOutputType = 'p2pkh' | 'p2sh' | 'p2w-pkh' | 'p2w-sh' | 'p2tr' | 'opreturn';
|
|
6
6
|
export interface TxOutputInfo {
|
|
7
|
-
type: TxOutputType;
|
|
8
|
-
version: WitnessVersion;
|
|
7
|
+
type: TxOutputType | null;
|
|
8
|
+
version: WitnessVersion | null;
|
|
9
9
|
}
|
|
10
10
|
export interface TxInputInfo {
|
|
11
11
|
type: WitnessType;
|
package/package.json
CHANGED
package/src/lib/tx/util.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Buff }
|
|
1
|
+
import { Buff, Bytes } 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'
|
|
@@ -17,34 +17,36 @@ import type {
|
|
|
17
17
|
WitnessVersion
|
|
18
18
|
} from '@/types/index.js'
|
|
19
19
|
|
|
20
|
-
export function is_return_script (script :
|
|
21
|
-
|
|
20
|
+
export function is_return_script (script : Bytes) : boolean {
|
|
21
|
+
const bytes = Buff.bytes(script)
|
|
22
|
+
return bytes.at(0) === 0x6a
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
export function
|
|
25
|
+
export function get_vout_script_info (script : Bytes) : TxOutputInfo {
|
|
25
26
|
return {
|
|
26
|
-
type :
|
|
27
|
-
version :
|
|
27
|
+
type : get_vout_script_type(script),
|
|
28
|
+
version : get_vout_script_version(script)
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
export function
|
|
32
|
-
script :
|
|
33
|
-
) : TxOutputType {
|
|
32
|
+
export function get_vout_script_type (
|
|
33
|
+
script : Bytes
|
|
34
|
+
) : TxOutputType | null {
|
|
35
|
+
const hex = Buff.bytes(script).hex
|
|
34
36
|
for (const [ type, regex ] of Object.entries(LOCK_SCRIPT_REGEX)) {
|
|
35
|
-
if (regex.test(
|
|
37
|
+
if (regex.test(hex)) return type as TxOutputType
|
|
36
38
|
}
|
|
37
|
-
return
|
|
39
|
+
return null
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
export function
|
|
41
|
-
script :
|
|
42
|
-
) : WitnessVersion {
|
|
43
|
-
const
|
|
44
|
-
switch (
|
|
45
|
-
case
|
|
46
|
-
case
|
|
47
|
-
default
|
|
42
|
+
export function get_vout_script_version (
|
|
43
|
+
script : Bytes
|
|
44
|
+
) : WitnessVersion | null{
|
|
45
|
+
const version = Buff.bytes(script)
|
|
46
|
+
switch (version.at(0)) {
|
|
47
|
+
case 0x00 : return 0
|
|
48
|
+
case 0x51 : return 1
|
|
49
|
+
default : return null
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
52
|
|
package/src/types/meta.ts
CHANGED
|
@@ -3,11 +3,11 @@ import type{ WitnessType, WitnessVersion } from './witness.js'
|
|
|
3
3
|
export type LocktimeData = LocktimeStamp | LocktimeHeight
|
|
4
4
|
export type SequenceConfig = Partial<SequenceData>
|
|
5
5
|
export type SequenceData = SequenceHeightLock | SequenceStampLock
|
|
6
|
-
export type TxOutputType =
|
|
6
|
+
export type TxOutputType = 'p2pkh' | 'p2sh' | 'p2w-pkh' | 'p2w-sh' | 'p2tr' | 'opreturn'
|
|
7
7
|
|
|
8
8
|
export interface TxOutputInfo {
|
|
9
|
-
type : TxOutputType
|
|
10
|
-
version : WitnessVersion
|
|
9
|
+
type : TxOutputType | null
|
|
10
|
+
version : WitnessVersion | null
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export interface TxInputInfo {
|