@lightsparkdev/lightspark-sdk 1.8.10 → 1.9.1

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.
@@ -0,0 +1,109 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ import { type Query, isObject } from "@lightsparkdev/core";
4
+ import type CurrencyAmount from "./CurrencyAmount.js";
5
+ import {
6
+ CurrencyAmountFromJson,
7
+ CurrencyAmountToJson,
8
+ } from "./CurrencyAmount.js";
9
+
10
+ /** This object represents a BOLT #12 offer (https://github.com/lightning/bolts/blob/master/12-offer-encoding.md) created by a Lightspark Node. **/
11
+ interface Offer {
12
+ /**
13
+ * The unique identifier of this entity across all Lightspark systems. Should be treated as an
14
+ * opaque string.
15
+ **/
16
+ id: string;
17
+
18
+ /** The date and time when the entity was first created. **/
19
+ createdAt: string;
20
+
21
+ /** The date and time when the entity was last updated. **/
22
+ updatedAt: string;
23
+
24
+ /** The details of the offer. **/
25
+ dataId: string;
26
+
27
+ /** The BOLT12 encoded offer. Starts with 'lno'. **/
28
+ encodedOffer: string;
29
+
30
+ /** The typename of the object **/
31
+ typename: string;
32
+
33
+ /** The amount of the offer. If null, the payer chooses the amount. **/
34
+ amount?: CurrencyAmount | undefined;
35
+
36
+ /** The description of the offer. **/
37
+ description?: string | undefined;
38
+ }
39
+
40
+ export const OfferFromJson = (obj: any): Offer => {
41
+ return {
42
+ id: obj["offer_id"],
43
+ createdAt: obj["offer_created_at"],
44
+ updatedAt: obj["offer_updated_at"],
45
+ dataId: obj["offer_data"].id,
46
+ encodedOffer: obj["offer_encoded_offer"],
47
+ typename: "Offer",
48
+ amount: !!obj["offer_amount"]
49
+ ? CurrencyAmountFromJson(obj["offer_amount"])
50
+ : undefined,
51
+ description: obj["offer_description"],
52
+ } as Offer;
53
+ };
54
+ export const OfferToJson = (obj: Offer): any => {
55
+ return {
56
+ __typename: "Offer",
57
+ offer_id: obj.id,
58
+ offer_created_at: obj.createdAt,
59
+ offer_updated_at: obj.updatedAt,
60
+ offer_data: { id: obj.dataId },
61
+ offer_encoded_offer: obj.encodedOffer,
62
+ offer_amount: obj.amount ? CurrencyAmountToJson(obj.amount) : undefined,
63
+ offer_description: obj.description,
64
+ };
65
+ };
66
+
67
+ export const FRAGMENT = `
68
+ fragment OfferFragment on Offer {
69
+ __typename
70
+ offer_id: id
71
+ offer_created_at: created_at
72
+ offer_updated_at: updated_at
73
+ offer_data: data {
74
+ id
75
+ }
76
+ offer_encoded_offer: encoded_offer
77
+ offer_amount: amount {
78
+ __typename
79
+ currency_amount_original_value: original_value
80
+ currency_amount_original_unit: original_unit
81
+ currency_amount_preferred_currency_unit: preferred_currency_unit
82
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
83
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
84
+ }
85
+ offer_description: description
86
+ }`;
87
+
88
+ export const getOfferQuery = (id: string): Query<Offer> => {
89
+ return {
90
+ queryPayload: `
91
+ query GetOffer($id: ID!) {
92
+ entity(id: $id) {
93
+ ... on Offer {
94
+ ...OfferFragment
95
+ }
96
+ }
97
+ }
98
+
99
+ ${FRAGMENT}
100
+ `,
101
+ variables: { id },
102
+ constructObject: (data: unknown) =>
103
+ isObject(data) && "entity" in data && isObject(data.entity)
104
+ ? OfferFromJson(data.entity)
105
+ : null,
106
+ };
107
+ };
108
+
109
+ export default Offer;
@@ -0,0 +1,118 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ import { type Query, isObject } from "@lightsparkdev/core";
4
+ import BitcoinNetwork from "./BitcoinNetwork.js";
5
+ import type CurrencyAmount from "./CurrencyAmount.js";
6
+ import {
7
+ CurrencyAmountFromJson,
8
+ CurrencyAmountToJson,
9
+ } from "./CurrencyAmount.js";
10
+
11
+ /**
12
+ * This object represents the data associated with a BOLT #12 offer. You can retrieve this object
13
+ * to receive the relevant data associated with a specific offer. *
14
+ */
15
+ interface OfferData {
16
+ /**
17
+ * The unique identifier of this entity across all Lightspark systems. Should be treated as an
18
+ * opaque string.
19
+ **/
20
+ id: string;
21
+
22
+ /** The date and time when the entity was first created. **/
23
+ createdAt: string;
24
+
25
+ /** The date and time when the entity was last updated. **/
26
+ updatedAt: string;
27
+
28
+ /** The Bech32 encoded offer. **/
29
+ encodedOffer: string;
30
+
31
+ /** The bitcoin networks supported by the offer. **/
32
+ bitcoinNetworks: BitcoinNetwork[];
33
+
34
+ /** The typename of the object **/
35
+ typename: string;
36
+
37
+ /**
38
+ * The requested amount in this invoice. If it is equal to 0, the sender should choose the
39
+ * amount to send.
40
+ **/
41
+ amount?: CurrencyAmount | undefined;
42
+
43
+ /** The date and time when this invoice will expire. **/
44
+ expiresAt?: string | undefined;
45
+ }
46
+
47
+ export const OfferDataFromJson = (obj: any): OfferData => {
48
+ return {
49
+ id: obj["offer_data_id"],
50
+ createdAt: obj["offer_data_created_at"],
51
+ updatedAt: obj["offer_data_updated_at"],
52
+ encodedOffer: obj["offer_data_encoded_offer"],
53
+ bitcoinNetworks: obj["offer_data_bitcoin_networks"].map(
54
+ (e) => BitcoinNetwork[e],
55
+ ),
56
+ typename: "OfferData",
57
+ amount: !!obj["offer_data_amount"]
58
+ ? CurrencyAmountFromJson(obj["offer_data_amount"])
59
+ : undefined,
60
+ expiresAt: obj["offer_data_expires_at"],
61
+ } as OfferData;
62
+ };
63
+ export const OfferDataToJson = (obj: OfferData): any => {
64
+ return {
65
+ __typename: "OfferData",
66
+ offer_data_id: obj.id,
67
+ offer_data_created_at: obj.createdAt,
68
+ offer_data_updated_at: obj.updatedAt,
69
+ offer_data_amount: obj.amount
70
+ ? CurrencyAmountToJson(obj.amount)
71
+ : undefined,
72
+ offer_data_encoded_offer: obj.encodedOffer,
73
+ offer_data_bitcoin_networks: obj.bitcoinNetworks,
74
+ offer_data_expires_at: obj.expiresAt,
75
+ };
76
+ };
77
+
78
+ export const FRAGMENT = `
79
+ fragment OfferDataFragment on OfferData {
80
+ __typename
81
+ offer_data_id: id
82
+ offer_data_created_at: created_at
83
+ offer_data_updated_at: updated_at
84
+ offer_data_amount: amount {
85
+ __typename
86
+ currency_amount_original_value: original_value
87
+ currency_amount_original_unit: original_unit
88
+ currency_amount_preferred_currency_unit: preferred_currency_unit
89
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
90
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
91
+ }
92
+ offer_data_encoded_offer: encoded_offer
93
+ offer_data_bitcoin_networks: bitcoin_networks
94
+ offer_data_expires_at: expires_at
95
+ }`;
96
+
97
+ export const getOfferDataQuery = (id: string): Query<OfferData> => {
98
+ return {
99
+ queryPayload: `
100
+ query GetOfferData($id: ID!) {
101
+ entity(id: $id) {
102
+ ... on OfferData {
103
+ ...OfferDataFragment
104
+ }
105
+ }
106
+ }
107
+
108
+ ${FRAGMENT}
109
+ `,
110
+ variables: { id },
111
+ constructObject: (data: unknown) =>
112
+ isObject(data) && "entity" in data && isObject(data.entity)
113
+ ? OfferDataFromJson(data.entity)
114
+ : null,
115
+ };
116
+ };
117
+
118
+ export default OfferData;
@@ -0,0 +1,53 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ interface PayOfferInput {
4
+ /** The ID of the node that will be sending the payment. **/
5
+ nodeId: string;
6
+
7
+ /** The Bech32 offer you want to pay (as defined by the BOLT12 standard). **/
8
+ encodedOffer: string;
9
+
10
+ /** The timeout in seconds that we will try to make the payment. **/
11
+ timeoutSecs: number;
12
+
13
+ /**
14
+ * The maximum amount of fees that you want to pay for this payment to be sent, expressed in
15
+ * msats. *
16
+ */
17
+ maximumFeesMsats: number;
18
+
19
+ /**
20
+ * The amount you will pay for this offer, expressed in msats. It should ONLY be set when the
21
+ * offer amount is zero.
22
+ **/
23
+ amountMsats?: number | undefined;
24
+
25
+ /**
26
+ * An idempotency key for this payment. If provided, it will be used to create a payment with
27
+ * the same idempotency key. If not provided, a new idempotency key will be generated.
28
+ **/
29
+ idempotencyKey?: string | undefined;
30
+ }
31
+
32
+ export const PayOfferInputFromJson = (obj: any): PayOfferInput => {
33
+ return {
34
+ nodeId: obj["pay_offer_input_node_id"],
35
+ encodedOffer: obj["pay_offer_input_encoded_offer"],
36
+ timeoutSecs: obj["pay_offer_input_timeout_secs"],
37
+ maximumFeesMsats: obj["pay_offer_input_maximum_fees_msats"],
38
+ amountMsats: obj["pay_offer_input_amount_msats"],
39
+ idempotencyKey: obj["pay_offer_input_idempotency_key"],
40
+ } as PayOfferInput;
41
+ };
42
+ export const PayOfferInputToJson = (obj: PayOfferInput): any => {
43
+ return {
44
+ pay_offer_input_node_id: obj.nodeId,
45
+ pay_offer_input_encoded_offer: obj.encodedOffer,
46
+ pay_offer_input_timeout_secs: obj.timeoutSecs,
47
+ pay_offer_input_maximum_fees_msats: obj.maximumFeesMsats,
48
+ pay_offer_input_amount_msats: obj.amountMsats,
49
+ pay_offer_input_idempotency_key: obj.idempotencyKey,
50
+ };
51
+ };
52
+
53
+ export default PayOfferInput;
@@ -0,0 +1,27 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ interface PayOfferOutput {
4
+ /** The payment that has been sent. **/
5
+ paymentId: string;
6
+ }
7
+
8
+ export const PayOfferOutputFromJson = (obj: any): PayOfferOutput => {
9
+ return {
10
+ paymentId: obj["pay_offer_output_payment"].id,
11
+ } as PayOfferOutput;
12
+ };
13
+ export const PayOfferOutputToJson = (obj: PayOfferOutput): any => {
14
+ return {
15
+ pay_offer_output_payment: { id: obj.paymentId },
16
+ };
17
+ };
18
+
19
+ export const FRAGMENT = `
20
+ fragment PayOfferOutputFragment on PayOfferOutput {
21
+ __typename
22
+ pay_offer_output_payment: payment {
23
+ id
24
+ }
25
+ }`;
26
+
27
+ export default PayOfferOutput;
@@ -0,0 +1,68 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ import PaymentFailureReason from "./PaymentFailureReason.js";
4
+
5
+ interface PayTestModeInvoiceInput {
6
+ /** The node from where you want to send the payment. **/
7
+ nodeId: string;
8
+
9
+ /** The invoice you want to pay (as defined by the BOLT11 standard). **/
10
+ encodedInvoice: string;
11
+
12
+ /** The timeout in seconds that we will try to make the payment. **/
13
+ timeoutSecs: number;
14
+
15
+ /**
16
+ * The maximum amount of fees that you want to pay for this payment to be sent, expressed in
17
+ * msats. *
18
+ */
19
+ maximumFeesMsats: number;
20
+
21
+ /** The failure reason to trigger for the payment. If not set, pay_invoice will be called. **/
22
+ failureReason?: PaymentFailureReason | undefined;
23
+
24
+ /**
25
+ * The amount you will pay for this invoice, expressed in msats. It should ONLY be set when the
26
+ * invoice amount is zero.
27
+ **/
28
+ amountMsats?: number | undefined;
29
+
30
+ /**
31
+ * The idempotency key of the request. The same result will be returned for the same
32
+ * idempotency key. *
33
+ */
34
+ idempotencyKey?: string | undefined;
35
+ }
36
+
37
+ export const PayTestModeInvoiceInputFromJson = (
38
+ obj: any,
39
+ ): PayTestModeInvoiceInput => {
40
+ return {
41
+ nodeId: obj["pay_test_mode_invoice_input_node_id"],
42
+ encodedInvoice: obj["pay_test_mode_invoice_input_encoded_invoice"],
43
+ timeoutSecs: obj["pay_test_mode_invoice_input_timeout_secs"],
44
+ maximumFeesMsats: obj["pay_test_mode_invoice_input_maximum_fees_msats"],
45
+ failureReason: !!obj["pay_test_mode_invoice_input_failure_reason"]
46
+ ? PaymentFailureReason[
47
+ obj["pay_test_mode_invoice_input_failure_reason"]
48
+ ] ?? PaymentFailureReason.FUTURE_VALUE
49
+ : null,
50
+ amountMsats: obj["pay_test_mode_invoice_input_amount_msats"],
51
+ idempotencyKey: obj["pay_test_mode_invoice_input_idempotency_key"],
52
+ } as PayTestModeInvoiceInput;
53
+ };
54
+ export const PayTestModeInvoiceInputToJson = (
55
+ obj: PayTestModeInvoiceInput,
56
+ ): any => {
57
+ return {
58
+ pay_test_mode_invoice_input_node_id: obj.nodeId,
59
+ pay_test_mode_invoice_input_encoded_invoice: obj.encodedInvoice,
60
+ pay_test_mode_invoice_input_timeout_secs: obj.timeoutSecs,
61
+ pay_test_mode_invoice_input_maximum_fees_msats: obj.maximumFeesMsats,
62
+ pay_test_mode_invoice_input_failure_reason: obj.failureReason,
63
+ pay_test_mode_invoice_input_amount_msats: obj.amountMsats,
64
+ pay_test_mode_invoice_input_idempotency_key: obj.idempotencyKey,
65
+ };
66
+ };
67
+
68
+ export default PayTestModeInvoiceInput;
@@ -10,8 +10,9 @@ import type InvoiceData from "./InvoiceData.js";
10
10
  import { NodeFromJson, NodeToJson } from "./Node.js";
11
11
 
12
12
  /**
13
- * This object is an interface of a payment request on the Lightning Network (i.e., a Lightning
14
- * Invoice). It contains data related to parsing the payment details of a Lightning Invoice. *
13
+ * This object is an interface of a payment request on the Lightning Network (i.e., Invoice or
14
+ * Bolt12Invoice). It contains data related to parsing the payment details of a Lightning Invoice.
15
+ * *
15
16
  */
16
17
  interface PaymentRequestData {
17
18
  encodedPaymentRequest: string;
@@ -47,6 +47,8 @@ export { default as CreateInvoiceOutput } from "./CreateInvoiceOutput.js";
47
47
  export { default as CreateLnurlInvoiceInput } from "./CreateLnurlInvoiceInput.js";
48
48
  export { default as CreateNodeWalletAddressInput } from "./CreateNodeWalletAddressInput.js";
49
49
  export { default as CreateNodeWalletAddressOutput } from "./CreateNodeWalletAddressOutput.js";
50
+ export { default as CreateOfferInput } from "./CreateOfferInput.js";
51
+ export { default as CreateOfferOutput } from "./CreateOfferOutput.js";
50
52
  export { default as CreateTestModeInvoiceInput } from "./CreateTestModeInvoiceInput.js";
51
53
  export { default as CreateTestModeInvoiceOutput } from "./CreateTestModeInvoiceOutput.js";
52
54
  export { default as CreateTestModePaymentInput } from "./CreateTestModePaymentInput.js";
@@ -55,6 +57,7 @@ export { default as CreateUmaInvitationInput } from "./CreateUmaInvitationInput.
55
57
  export { default as CreateUmaInvitationOutput } from "./CreateUmaInvitationOutput.js";
56
58
  export { default as CreateUmaInvoiceInput } from "./CreateUmaInvoiceInput.js";
57
59
  export { default as CurrencyAmount } from "./CurrencyAmount.js";
60
+ export { default as CurrencyAmountInput } from "./CurrencyAmountInput.js";
58
61
  export { default as CurrencyUnit } from "./CurrencyUnit.js";
59
62
  export { default as DailyLiquidityForecast } from "./DailyLiquidityForecast.js";
60
63
  export { default as DeclineToSignMessagesInput } from "./DeclineToSignMessagesInput.js";
@@ -116,6 +119,8 @@ export { default as Node, getNodeQuery } from "./Node.js";
116
119
  export { default as NodeAddress } from "./NodeAddress.js";
117
120
  export { default as NodeAddressType } from "./NodeAddressType.js";
118
121
  export { default as NodeToAddressesConnection } from "./NodeToAddressesConnection.js";
122
+ export { default as Offer, getOfferQuery } from "./Offer.js";
123
+ export { default as OfferData, getOfferDataQuery } from "./OfferData.js";
119
124
  export { default as OnChainFeeTarget } from "./OnChainFeeTarget.js";
120
125
  export {
121
126
  default as OnChainTransaction,
@@ -143,6 +148,9 @@ export {
143
148
  } from "./PaymentRequest.js";
144
149
  export { default as PaymentRequestData } from "./PaymentRequestData.js";
145
150
  export { default as PaymentRequestStatus } from "./PaymentRequestStatus.js";
151
+ export { default as PayOfferInput } from "./PayOfferInput.js";
152
+ export { default as PayOfferOutput } from "./PayOfferOutput.js";
153
+ export { default as PayTestModeInvoiceInput } from "./PayTestModeInvoiceInput.js";
146
154
  export { default as PayUmaInvoiceInput } from "./PayUmaInvoiceInput.js";
147
155
  export { default as Permission } from "./Permission.js";
148
156
  export { default as PostTransactionData } from "./PostTransactionData.js";