bitcoin-decoder 0.2.0 → 0.3.0

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/index.js CHANGED
@@ -78,8 +78,8 @@ function decodeArk(input) {
78
78
  network: getNetwork(input) || 'unknown'
79
79
  };
80
80
  }
81
- function decodeBip321(input) {
82
- const parsedDestinations = bip321(input);
81
+ async function decodeBip321(input) {
82
+ const parsedDestinations = await bip321(input);
83
83
  const first = parsedDestinations[0];
84
84
  if (!first) {
85
85
  throw new DecodeError(`No supported payment methods in BIP-321 URI: ${input}`, 'NO_PAYMENT_METHODS');
@@ -1,3 +1,3 @@
1
1
  import type { Input, ParsedDestination } from '../types';
2
- declare function bip321(input: Input): ParsedDestination[];
2
+ declare function bip321(input: Input): Promise<ParsedDestination[]>;
3
3
  export { bip321 };
@@ -3,6 +3,7 @@ import { ark } from './ark';
3
3
  import { bitcoin } from './bitcoin';
4
4
  import { bolt11 } from './bolt11';
5
5
  import { bolt12 } from './bolt12';
6
+ import { lightningAddress } from './lightning-address';
6
7
  const SATS_PER_BTC = 100_000_000;
7
8
  /** Priority order: Lightning (0) > Ark (1) > On-chain (2) */
8
9
  const PROTOCOL_PRIORITY = {
@@ -25,8 +26,11 @@ function getMetadata(result) {
25
26
  }
26
27
  return { amount, description };
27
28
  }
28
- function mapPaymentMethod(paymentMethod, metadata) {
29
+ async function mapPaymentMethod(paymentMethod, metadata) {
29
30
  if (paymentMethod.type === 'lightning') {
31
+ if (paymentMethod.value.includes('@')) {
32
+ return await lightningAddress(paymentMethod.value);
33
+ }
30
34
  return bolt11(paymentMethod.value);
31
35
  }
32
36
  if (paymentMethod.type === 'offer') {
@@ -38,19 +42,21 @@ function mapPaymentMethod(paymentMethod, metadata) {
38
42
  const parsed = bitcoin(paymentMethod.value);
39
43
  return { ...parsed, metadata };
40
44
  }
41
- function parse(result) {
45
+ async function parse(result) {
42
46
  const metadata = getMetadata(result);
43
- return result.paymentMethods
44
- .filter((method) => (method.valid || method.type === 'offer') &&
47
+ return await Promise.all(result.paymentMethods
48
+ .filter((method) => (method.valid ||
49
+ method.type === 'offer' ||
50
+ (method.type === 'lightning' && method.value.includes('@'))) &&
45
51
  isSupportedType(method.type))
46
52
  .sort((a, b) => PROTOCOL_PRIORITY[a.type] - PROTOCOL_PRIORITY[b.type])
47
- .map((method) => mapPaymentMethod(method, metadata));
53
+ .map((method) => mapPaymentMethod(method, metadata)));
48
54
  }
49
- function bip321(input) {
55
+ async function bip321(input) {
50
56
  const result = parseBIP321(input);
51
57
  if (!result.valid) {
52
58
  throw new Error(`Invalid BIP-321 URI: ${result.errors.join(', ')}`);
53
59
  }
54
- return parse(result);
60
+ return await parse(result);
55
61
  }
56
62
  export { bip321 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bitcoin-decoder",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Decode bitcoin QR codes, URIs, and raw strings",
5
5
  "type": "module",
6
6
  "exports": {