@vbyte/btc-dev 1.1.4 → 1.1.6
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/address/api.d.ts +1 -1
- package/dist/lib/address/api.js +8 -8
- package/dist/lib/script/index.d.ts +1 -115
- package/dist/lib/script/index.js +1 -5
- package/dist/main.cjs +41 -12
- package/dist/main.cjs.map +1 -1
- package/dist/module.mjs +41 -12
- package/dist/module.mjs.map +1 -1
- package/dist/package.json +1 -1
- package/dist/script.js +8 -8
- package/dist/script.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/address/api.ts +13 -13
- package/src/lib/script/index.ts +5 -13
package/package.json
CHANGED
package/src/lib/address/api.ts
CHANGED
|
@@ -12,36 +12,36 @@ import { P2WSH } from './p2wsh.js'
|
|
|
12
12
|
import type { AddressInfo, ChainNetwork } from '@/types/index.js'
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Get the address for a given locking script.
|
|
16
16
|
*
|
|
17
|
-
* @param
|
|
18
|
-
* @
|
|
17
|
+
* @param script - The locking script.
|
|
18
|
+
* @param network - The network to use.
|
|
19
|
+
* @returns The address.
|
|
19
20
|
*/
|
|
20
|
-
export function
|
|
21
|
+
export function get_address (
|
|
21
22
|
script : Bytes,
|
|
22
23
|
network : ChainNetwork = 'main'
|
|
23
24
|
) : string {
|
|
24
25
|
// Convert the script into bytes.
|
|
25
26
|
const bytes = Buff.bytes(script)
|
|
26
27
|
// Get the address configuration.
|
|
27
|
-
const type
|
|
28
|
+
const type = get_lock_script_type(bytes)
|
|
28
29
|
// If the script type is not recognized, throw an error.
|
|
29
|
-
if (type === null) throw new Error('
|
|
30
|
+
if (type === null) throw new Error('unknown locking script: ' + bytes.hex)
|
|
30
31
|
// Create the address based on the script type.
|
|
31
32
|
switch (type) {
|
|
32
33
|
case LOCK_SCRIPT_TYPE.P2PKH:
|
|
33
|
-
return P2PKH.
|
|
34
|
+
return P2PKH.encode_address(script, network)
|
|
34
35
|
case LOCK_SCRIPT_TYPE.P2SH:
|
|
35
|
-
return P2SH.
|
|
36
|
+
return P2SH.encode_address(script, network)
|
|
36
37
|
case LOCK_SCRIPT_TYPE.P2WPKH:
|
|
37
|
-
return P2WPKH.
|
|
38
|
+
return P2WPKH.encode_address(script, network)
|
|
38
39
|
case LOCK_SCRIPT_TYPE.P2WSH:
|
|
39
|
-
return P2WSH.
|
|
40
|
+
return P2WSH.encode_address(script, network)
|
|
40
41
|
case LOCK_SCRIPT_TYPE.P2TR:
|
|
41
|
-
return P2TR.
|
|
42
|
+
return P2TR.encode_address(script, network)
|
|
42
43
|
default:
|
|
43
|
-
|
|
44
|
-
throw new Error('unrecognized script type: ' + type)
|
|
44
|
+
throw new Error('unknown script type: ' + type)
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
package/src/lib/script/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { OPCODE_MAP } from './words.js'
|
|
2
1
|
import { encode_script } from './encode.js'
|
|
3
2
|
|
|
4
3
|
import {
|
|
@@ -7,22 +6,15 @@ import {
|
|
|
7
6
|
parse_script
|
|
8
7
|
} from './decode.js'
|
|
9
8
|
|
|
10
|
-
import {
|
|
11
|
-
parse_script_pubkeys,
|
|
12
|
-
prefix_script_size
|
|
13
|
-
} from './util.js'
|
|
14
|
-
|
|
15
9
|
export * from './decode.js'
|
|
16
10
|
export * from './encode.js'
|
|
11
|
+
export * from './lock.js'
|
|
17
12
|
export * from './util.js'
|
|
18
13
|
export * from './words.js'
|
|
19
14
|
|
|
20
15
|
export namespace ScriptUtil {
|
|
21
|
-
export const
|
|
22
|
-
export const
|
|
23
|
-
export const
|
|
24
|
-
export const
|
|
25
|
-
export const is_valid = is_valid_script
|
|
26
|
-
export const get_pubkeys = parse_script_pubkeys
|
|
27
|
-
export const OPCODES = OPCODE_MAP
|
|
16
|
+
export const parse = parse_script
|
|
17
|
+
export const decode = decode_script
|
|
18
|
+
export const encode = encode_script
|
|
19
|
+
export const is_valid = is_valid_script
|
|
28
20
|
}
|