bool is_owned;
} LDKOutPoint;
+
+
/**
* When on-chain outputs are created by rust-lightning (which our counterparty is not able to
* claim at any point in the future) an event is generated which you must track and be able to
* outpoint describing which txid and output index is available, the full output which exists at
* that txid/index, and any keys or other information required to sign.
*/
-typedef enum LDKSpendableOutputDescriptor_Tag {
- /**
- * An output to a script which was provided via KeysInterface directly, either from
- * `get_destination_script()` or `get_shutdown_pubkey()`, thus you should already know how to
- * spend it. No secret keys are provided as rust-lightning was never given any key.
- * These may include outputs from a transaction punishing our counterparty or claiming an HTLC
- * on-chain using the payment preimage or after it has timed out.
- */
- LDKSpendableOutputDescriptor_StaticOutput,
- /**
- * An output to a P2WSH script which can be spent with a single signature after a CSV delay.
- *
- * The witness in the spending input should be:
- * <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
- *
- * Note that the nSequence field in the spending input must be set to to_self_delay
- * (which means the transaction is not broadcastable until at least to_self_delay
- * blocks after the outpoint confirms).
- *
- * These are generally the result of a \"revocable\" output to us, spendable only by us unless
- * it is an output from an old state which we broadcast (which should never happen).
- *
- * To derive the delayed_payment key which is used to sign for this input, you must pass the
- * holder delayed_payment_base_key (ie the private key which corresponds to the pubkey in
- * ChannelKeys::pubkeys().delayed_payment_basepoint) and the provided per_commitment_point to
- * chan_utils::derive_private_key. The public key can be generated without the secret key
- * using chan_utils::derive_public_key and only the delayed_payment_basepoint which appears in
- * ChannelKeys::pubkeys().
- *
- * To derive the revocation_pubkey provided here (which is used in the witness
- * script generation), you must pass the counterparty revocation_basepoint (which appears in the
- * call to ChannelKeys::ready_channel) and the provided per_commitment point
- * to chan_utils::derive_public_revocation_key.
- *
- * The witness script which is hashed and included in the output script_pubkey may be
- * regenerated by passing the revocation_pubkey (derived as above), our delayed_payment pubkey
- * (derived as above), and the to_self_delay contained here to
- * chan_utils::get_revokeable_redeemscript.
- */
- LDKSpendableOutputDescriptor_DynamicOutputP2WSH,
- /**
- * An output to a P2WPKH, spendable exclusively by our payment key (ie the private key which
- * corresponds to the public key in ChannelKeys::pubkeys().payment_point).
- * The witness in the spending input, is, thus, simply:
- * <BIP 143 signature> <payment key>
- *
- * These are generally the result of our counterparty having broadcast the current state,
- * allowing us to claim the non-HTLC-encumbered outputs immediately.
- */
- LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment,
+typedef struct MUST_USE_STRUCT LDKSpendableOutputDescriptor {
/**
- * Must be last for serialization purposes
+ * Nearly everywhere, inner must be non-null, however in places where
+ * the Rust equivalent takes an Option, it may be set to null to indicate None.
*/
- LDKSpendableOutputDescriptor_Sentinel,
-} LDKSpendableOutputDescriptor_Tag;
-
-typedef struct LDKSpendableOutputDescriptor_LDKStaticOutput_Body {
- struct LDKOutPoint outpoint;
- struct LDKTxOut output;
-} LDKSpendableOutputDescriptor_LDKStaticOutput_Body;
-
-typedef struct LDKSpendableOutputDescriptor_LDKDynamicOutputP2WSH_Body {
- struct LDKOutPoint outpoint;
- struct LDKPublicKey per_commitment_point;
- uint16_t to_self_delay;
- struct LDKTxOut output;
- struct LDKPublicKey revocation_pubkey;
- struct LDKThirtyTwoBytes channel_keys_id;
- uint64_t channel_value_satoshis;
-} LDKSpendableOutputDescriptor_LDKDynamicOutputP2WSH_Body;
-
-typedef struct LDKSpendableOutputDescriptor_LDKStaticOutputCounterpartyPayment_Body {
- struct LDKOutPoint outpoint;
- struct LDKTxOut output;
- struct LDKThirtyTwoBytes channel_keys_id;
- uint64_t channel_value_satoshis;
-} LDKSpendableOutputDescriptor_LDKStaticOutputCounterpartyPayment_Body;
-
-typedef struct MUST_USE_STRUCT LDKSpendableOutputDescriptor {
- LDKSpendableOutputDescriptor_Tag tag;
- union {
- LDKSpendableOutputDescriptor_LDKStaticOutput_Body static_output;
- LDKSpendableOutputDescriptor_LDKDynamicOutputP2WSH_Body dynamic_output_p2wsh;
- LDKSpendableOutputDescriptor_LDKStaticOutputCounterpartyPayment_Body static_output_counterparty_payment;
- };
+ LDKnativeSpendableOutputDescriptor *inner;
+ bool is_owned;
} LDKSpendableOutputDescriptor;
typedef struct LDKCVec_SpendableOutputDescriptorZ {
* In any case, ChannelMonitor or fallback watchtowers are always going to be trusted
* to act, as liveness and breach reply correctness are always going to be hard requirements
* of LN security model, orthogonal of key management issues.
- *
- * If you're implementing a custom signer, you almost certainly want to implement
- * Readable/Writable to serialize out a unique reference to this set of keys so
- * that you can serialize the full ChannelManager object.
- *
*/
typedef struct LDKChannelKeys {
void *this_arg;
* May be called more than once for the same index.
*
* Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
- * TODO: return a Result so we can signal a validation error
*/
struct LDKThirtyTwoBytes (*release_commitment_secret)(const void *this_arg, uint64_t idx);
/**
bool result_ok;
} LDKCResult_SpendableOutputDescriptorDecodeErrorZ;
+typedef struct LDKCVec_CVec_u8ZZ {
+ struct LDKCVec_u8Z *data;
+ uintptr_t datalen;
+} LDKCVec_CVec_u8ZZ;
+
+typedef union LDKCResult_CVec_CVec_u8ZZNoneZPtr {
+ struct LDKCVec_CVec_u8ZZ *result;
+ /**
+ * Note that this value is always NULL, as there are no contents in the Err variant
+ */
+ void *err;
+} LDKCResult_CVec_CVec_u8ZZNoneZPtr;
+
+typedef struct LDKCResult_CVec_CVec_u8ZZNoneZ {
+ union LDKCResult_CVec_CVec_u8ZZNoneZPtr contents;
+ bool result_ok;
+} LDKCResult_CVec_CVec_u8ZZNoneZ;
+
/**
bool result_ok;
} LDKCResult_InMemoryChannelKeysDecodeErrorZ;
+typedef struct LDKCVec_TxOutZ {
+ struct LDKTxOut *data;
+ uintptr_t datalen;
+} LDKCVec_TxOutZ;
+
+typedef union LDKCResult_TransactionNoneZPtr {
+ struct LDKTransaction *result;
+ /**
+ * Note that this value is always NULL, as there are no contents in the Err variant
+ */
+ void *err;
+} LDKCResult_TransactionNoneZPtr;
+
+typedef struct LDKCResult_TransactionNoneZ {
+ union LDKCResult_TransactionNoneZPtr contents;
+ bool result_ok;
+} LDKCResult_TransactionNoneZ;
+
/**
+/**
+ * Information about a spendable output to a P2WSH script. See
+ * SpendableOutputDescriptor::DelayedPaymentOutput for more details on how to spend this.
+ */
+typedef struct MUST_USE_STRUCT LDKDelayedPaymentOutputDescriptor {
+ /**
+ * Nearly everywhere, inner must be non-null, however in places where
+ * the Rust equivalent takes an Option, it may be set to null to indicate None.
+ */
+ LDKnativeDelayedPaymentOutputDescriptor *inner;
+ bool is_owned;
+} LDKDelayedPaymentOutputDescriptor;
+
+
+
+/**
+ * Information about a spendable output to our \"payment key\". See
+ * SpendableOutputDescriptor::StaticPaymentOutput for more details on how to spend this.
+ */
+typedef struct MUST_USE_STRUCT LDKStaticPaymentOutputDescriptor {
+ /**
+ * Nearly everywhere, inner must be non-null, however in places where
+ * the Rust equivalent takes an Option, it may be set to null to indicate None.
+ */
+ LDKnativeStaticPaymentOutputDescriptor *inner;
+ bool is_owned;
+} LDKStaticPaymentOutputDescriptor;
+
+
+
/**
* Simple KeysInterface implementor that takes a 32-byte seed for use as a BIP 32 extended key
* and derives keys from that.
extern const uint64_t CLOSED_CHANNEL_UPDATE_ID;
+extern const uintptr_t REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH;
+
void Transaction_free(struct LDKTransaction _res);
void TxOut_free(struct LDKTxOut _res);
struct LDKCResult_ChannelKeysDecodeErrorZ CResult_ChannelKeysDecodeErrorZ_clone(const struct LDKCResult_ChannelKeysDecodeErrorZ *NONNULL_PTR orig);
+void CVec_CVec_u8ZZ_free(struct LDKCVec_CVec_u8ZZ _res);
+
+struct LDKCResult_CVec_CVec_u8ZZNoneZ CResult_CVec_CVec_u8ZZNoneZ_ok(struct LDKCVec_CVec_u8ZZ o);
+
+struct LDKCResult_CVec_CVec_u8ZZNoneZ CResult_CVec_CVec_u8ZZNoneZ_err(void);
+
+void CResult_CVec_CVec_u8ZZNoneZ_free(struct LDKCResult_CVec_CVec_u8ZZNoneZ _res);
+
+struct LDKCResult_CVec_CVec_u8ZZNoneZ CResult_CVec_CVec_u8ZZNoneZ_clone(const struct LDKCResult_CVec_CVec_u8ZZNoneZ *NONNULL_PTR orig);
+
struct LDKCResult_InMemoryChannelKeysDecodeErrorZ CResult_InMemoryChannelKeysDecodeErrorZ_ok(struct LDKInMemoryChannelKeys o);
struct LDKCResult_InMemoryChannelKeysDecodeErrorZ CResult_InMemoryChannelKeysDecodeErrorZ_err(struct LDKDecodeError e);
struct LDKCResult_InMemoryChannelKeysDecodeErrorZ CResult_InMemoryChannelKeysDecodeErrorZ_clone(const struct LDKCResult_InMemoryChannelKeysDecodeErrorZ *NONNULL_PTR orig);
+void CVec_TxOutZ_free(struct LDKCVec_TxOutZ _res);
+
+struct LDKCResult_TransactionNoneZ CResult_TransactionNoneZ_ok(struct LDKTransaction o);
+
+struct LDKCResult_TransactionNoneZ CResult_TransactionNoneZ_err(void);
+
+void CResult_TransactionNoneZ_free(struct LDKCResult_TransactionNoneZ _res);
+
void CVec_RouteHopZ_free(struct LDKCVec_RouteHopZ _res);
void CVec_CVec_RouteHopZZ_free(struct LDKCVec_CVec_RouteHopZZ _res);
struct LDKCResult_OutPointDecodeErrorZ OutPoint_read(struct LDKu8slice ser);
+void DelayedPaymentOutputDescriptor_free(struct LDKDelayedPaymentOutputDescriptor this_ptr);
+
+/**
+ * The outpoint which is spendable
+ */
+struct LDKOutPoint DelayedPaymentOutputDescriptor_get_outpoint(const struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr);
+
+/**
+ * The outpoint which is spendable
+ */
+void DelayedPaymentOutputDescriptor_set_outpoint(struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr, struct LDKOutPoint val);
+
+/**
+ * Per commitment point to derive delayed_payment_key by key holder
+ */
+struct LDKPublicKey DelayedPaymentOutputDescriptor_get_per_commitment_point(const struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr);
+
+/**
+ * Per commitment point to derive delayed_payment_key by key holder
+ */
+void DelayedPaymentOutputDescriptor_set_per_commitment_point(struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr, struct LDKPublicKey val);
+
+/**
+ * The nSequence value which must be set in the spending input to satisfy the OP_CSV in
+ * the witness_script.
+ */
+uint16_t DelayedPaymentOutputDescriptor_get_to_self_delay(const struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr);
+
+/**
+ * The nSequence value which must be set in the spending input to satisfy the OP_CSV in
+ * the witness_script.
+ */
+void DelayedPaymentOutputDescriptor_set_to_self_delay(struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr, uint16_t val);
+
+/**
+ * The output which is referenced by the given outpoint
+ */
+void DelayedPaymentOutputDescriptor_set_output(struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr, struct LDKTxOut val);
+
+/**
+ * The revocation point specific to the commitment transaction which was broadcast. Used to
+ * derive the witnessScript for this output.
+ */
+struct LDKPublicKey DelayedPaymentOutputDescriptor_get_revocation_pubkey(const struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr);
+
+/**
+ * The revocation point specific to the commitment transaction which was broadcast. Used to
+ * derive the witnessScript for this output.
+ */
+void DelayedPaymentOutputDescriptor_set_revocation_pubkey(struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr, struct LDKPublicKey val);
+
+/**
+ * Arbitrary identification information returned by a call to
+ * `ChannelKeys::channel_keys_id()`. This may be useful in re-deriving keys used in
+ * the channel to spend the output.
+ */
+const uint8_t (*DelayedPaymentOutputDescriptor_get_channel_keys_id(const struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr))[32];
+
+/**
+ * Arbitrary identification information returned by a call to
+ * `ChannelKeys::channel_keys_id()`. This may be useful in re-deriving keys used in
+ * the channel to spend the output.
+ */
+void DelayedPaymentOutputDescriptor_set_channel_keys_id(struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val);
+
+/**
+ * The value of the channel which this output originated from, possibly indirectly.
+ */
+uint64_t DelayedPaymentOutputDescriptor_get_channel_value_satoshis(const struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr);
+
+/**
+ * The value of the channel which this output originated from, possibly indirectly.
+ */
+void DelayedPaymentOutputDescriptor_set_channel_value_satoshis(struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr, uint64_t val);
+
+MUST_USE_RES struct LDKDelayedPaymentOutputDescriptor DelayedPaymentOutputDescriptor_new(struct LDKOutPoint outpoint_arg, struct LDKPublicKey per_commitment_point_arg, uint16_t to_self_delay_arg, struct LDKTxOut output_arg, struct LDKPublicKey revocation_pubkey_arg, struct LDKThirtyTwoBytes channel_keys_id_arg, uint64_t channel_value_satoshis_arg);
+
+struct LDKDelayedPaymentOutputDescriptor DelayedPaymentOutputDescriptor_clone(const struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR orig);
+
+void StaticPaymentOutputDescriptor_free(struct LDKStaticPaymentOutputDescriptor this_ptr);
+
+/**
+ * The outpoint which is spendable
+ */
+struct LDKOutPoint StaticPaymentOutputDescriptor_get_outpoint(const struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR this_ptr);
+
+/**
+ * The outpoint which is spendable
+ */
+void StaticPaymentOutputDescriptor_set_outpoint(struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR this_ptr, struct LDKOutPoint val);
+
+/**
+ * The output which is referenced by the given outpoint
+ */
+void StaticPaymentOutputDescriptor_set_output(struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR this_ptr, struct LDKTxOut val);
+
+/**
+ * Arbitrary identification information returned by a call to
+ * `ChannelKeys::channel_keys_id()`. This may be useful in re-deriving keys used in
+ * the channel to spend the output.
+ */
+const uint8_t (*StaticPaymentOutputDescriptor_get_channel_keys_id(const struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR this_ptr))[32];
+
+/**
+ * Arbitrary identification information returned by a call to
+ * `ChannelKeys::channel_keys_id()`. This may be useful in re-deriving keys used in
+ * the channel to spend the output.
+ */
+void StaticPaymentOutputDescriptor_set_channel_keys_id(struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val);
+
+/**
+ * The value of the channel which this transactions spends.
+ */
+uint64_t StaticPaymentOutputDescriptor_get_channel_value_satoshis(const struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR this_ptr);
+
+/**
+ * The value of the channel which this transactions spends.
+ */
+void StaticPaymentOutputDescriptor_set_channel_value_satoshis(struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR this_ptr, uint64_t val);
+
+MUST_USE_RES struct LDKStaticPaymentOutputDescriptor StaticPaymentOutputDescriptor_new(struct LDKOutPoint outpoint_arg, struct LDKTxOut output_arg, struct LDKThirtyTwoBytes channel_keys_id_arg, uint64_t channel_value_satoshis_arg);
+
+struct LDKStaticPaymentOutputDescriptor StaticPaymentOutputDescriptor_clone(const struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR orig);
+
void SpendableOutputDescriptor_free(struct LDKSpendableOutputDescriptor this_ptr);
struct LDKSpendableOutputDescriptor SpendableOutputDescriptor_clone(const struct LDKSpendableOutputDescriptor *NONNULL_PTR orig);
*/
MUST_USE_RES struct LDKChannelTransactionParameters InMemoryChannelKeys_get_channel_parameters(const struct LDKInMemoryChannelKeys *NONNULL_PTR this_arg);
+/**
+ * Sign the single input of spend_tx at index `input_idx` which spends the output
+ * described by descriptor, returning the witness stack for the input.
+ *
+ * Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
+ * or is not spending the outpoint described by `descriptor.outpoint`.
+ */
+MUST_USE_RES struct LDKCResult_CVec_CVec_u8ZZNoneZ InMemoryChannelKeys_sign_counterparty_payment_input(const struct LDKInMemoryChannelKeys *NONNULL_PTR this_arg, struct LDKTransaction spend_tx, uintptr_t input_idx, const struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR descriptor);
+
+/**
+ * Sign the single input of spend_tx at index `input_idx` which spends the output
+ * described by descriptor, returning the witness stack for the input.
+ *
+ * Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
+ * is not spending the outpoint described by `descriptor.outpoint`, or does not have a
+ * sequence set to `descriptor.to_self_delay`.
+ */
+MUST_USE_RES struct LDKCResult_CVec_CVec_u8ZZNoneZ InMemoryChannelKeys_sign_dynamic_p2wsh_input(const struct LDKInMemoryChannelKeys *NONNULL_PTR this_arg, struct LDKTransaction spend_tx, uintptr_t input_idx, const struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR descriptor);
+
struct LDKChannelKeys InMemoryChannelKeys_as_ChannelKeys(const struct LDKInMemoryChannelKeys *NONNULL_PTR this_arg);
struct LDKCVec_u8Z InMemoryChannelKeys_write(const struct LDKInMemoryChannelKeys *NONNULL_PTR obj);
* versions. Once the library is more fully supported, the docs will be updated to include a
* detailed description of the guarantee.
*/
-MUST_USE_RES struct LDKKeysManager KeysManager_new(const uint8_t (*seed)[32], enum LDKNetwork network, uint64_t starting_time_secs, uint32_t starting_time_nanos);
+MUST_USE_RES struct LDKKeysManager KeysManager_new(const uint8_t (*seed)[32], uint64_t starting_time_secs, uint32_t starting_time_nanos);
/**
* Derive an old set of ChannelKeys for per-channel secrets based on a key derivation
*/
MUST_USE_RES struct LDKInMemoryChannelKeys KeysManager_derive_channel_keys(const struct LDKKeysManager *NONNULL_PTR this_arg, uint64_t channel_value_satoshis, const uint8_t (*params)[32]);
+/**
+ * Creates a Transaction which spends the given descriptors to the given outputs, plus an
+ * output to the given change destination (if sufficient change value remains). The
+ * transaction will have a feerate, at least, of the given value.
+ *
+ * Returns `Err(())` if the output value is greater than the input value minus required fee or
+ * if a descriptor was duplicated.
+ *
+ * We do not enforce that outputs meet the dust limit or that any output scripts are standard.
+ *
+ * May panic if the `SpendableOutputDescriptor`s were not generated by Channels which used
+ * this KeysManager or one of the `InMemoryChannelKeys` created by this KeysManager.
+ */
+MUST_USE_RES struct LDKCResult_TransactionNoneZ KeysManager_spend_spendable_outputs(const struct LDKKeysManager *NONNULL_PTR this_arg, struct LDKCVec_SpendableOutputDescriptorZ descriptors, struct LDKCVec_TxOutZ outputs, struct LDKCVec_u8Z change_destination_script, uint32_t feerate_sat_per_1000_weight);
+
struct LDKKeysInterface KeysManager_as_KeysInterface(const struct LDKKeysManager *NONNULL_PTR this_arg);
void ChannelManager_free(struct LDKChannelManager this_ptr);