@vbyte/btc-dev 1.1.5 → 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.5",
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