@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vbyte/btc-dev",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Batteries-included toolset for plebian bitcoin development",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -12,36 +12,36 @@ import { P2WSH } from './p2wsh.js'
12
12
  import type { AddressInfo, ChainNetwork } from '@/types/index.js'
13
13
 
14
14
  /**
15
- * Parse an address into its data and script.
15
+ * Get the address for a given locking script.
16
16
  *
17
- * @param address - The address to parse.
18
- * @returns The address data and script.
17
+ * @param script - The locking script.
18
+ * @param network - The network to use.
19
+ * @returns The address.
19
20
  */
20
- export function create_address (
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 = get_lock_script_type(bytes)
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('unrecognized script type: ' + bytes.hex)
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.create_address(script, network)
34
+ return P2PKH.encode_address(script, network)
34
35
  case LOCK_SCRIPT_TYPE.P2SH:
35
- return P2SH.create_address(script, network)
36
+ return P2SH.encode_address(script, network)
36
37
  case LOCK_SCRIPT_TYPE.P2WPKH:
37
- return P2WPKH.create_address(script, network)
38
+ return P2WPKH.encode_address(script, network)
38
39
  case LOCK_SCRIPT_TYPE.P2WSH:
39
- return P2WSH.create_address(script, network)
40
+ return P2WSH.encode_address(script, network)
40
41
  case LOCK_SCRIPT_TYPE.P2TR:
41
- return P2TR.create_address(script, network)
42
+ return P2TR.encode_address(script, network)
42
43
  default:
43
- // If the script type is not recognized, throw an error.
44
- throw new Error('unrecognized script type: ' + type)
44
+ throw new Error('unknown script type: ' + type)
45
45
  }
46
46
  }
47
47
 
@@ -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 prefix_size = prefix_script_size
22
- export const parse = parse_script
23
- export const decode = decode_script
24
- export const encode = encode_script
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
  }