-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from synonymdev/custom-keys-manager
Custom keys manager
- Loading branch information
Showing
18 changed files
with
518 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
engine-strict=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
lib/android/src/main/java/com/reactnativeldk/classes/CustomKeysManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.reactnativeldk.classes | ||
|
||
import org.ldk.structs.KeysManager | ||
import org.ldk.structs.Option_u32Z | ||
import org.ldk.structs.Result_CVec_u8ZNoneZ | ||
import org.ldk.structs.Result_ShutdownScriptInvalidShutdownScriptZ | ||
import org.ldk.structs.Result_ShutdownScriptNoneZ | ||
import org.ldk.structs.Result_TransactionNoneZ | ||
import org.ldk.structs.Result_WriteableEcdsaChannelSignerDecodeErrorZ | ||
import org.ldk.structs.ShutdownScript | ||
import org.ldk.structs.SignerProvider | ||
import org.ldk.structs.SignerProvider.SignerProviderInterface | ||
import org.ldk.structs.SpendableOutputDescriptor | ||
import org.ldk.structs.TxOut | ||
import org.ldk.structs.WriteableEcdsaChannelSigner | ||
import org.ldk.util.UInt128 | ||
import org.ldk.util.WitnessVersion | ||
|
||
class CustomKeysManager( | ||
seed: ByteArray, | ||
startingTimeSecs: Long, | ||
startingTimeNanos: Int, | ||
val destinationScriptPublicKey: ByteArray, | ||
val witnessProgram: ByteArray, | ||
val witnessProgramVersion: Byte | ||
) { | ||
val inner: KeysManager = KeysManager.of(seed, startingTimeSecs, startingTimeNanos) | ||
val signerProvider = CustomSignerProvider() | ||
|
||
init { | ||
signerProvider.customKeysManager = this | ||
} | ||
|
||
fun spend_spendable_outputs( | ||
descriptors: Array<SpendableOutputDescriptor>, | ||
outputs: Array<TxOut>, | ||
changeDestinationScript: ByteArray, | ||
feerateSatPer1000Weight: Int, | ||
locktime: Option_u32Z | ||
): Result_TransactionNoneZ { | ||
val onlyNonStatic: Array<SpendableOutputDescriptor> = descriptors.filter { | ||
it as? SpendableOutputDescriptor.StaticOutput == null | ||
}.toTypedArray() | ||
|
||
return inner.spend_spendable_outputs( | ||
onlyNonStatic, | ||
outputs, | ||
changeDestinationScript, | ||
feerateSatPer1000Weight, | ||
locktime | ||
) | ||
} | ||
} | ||
|
||
class CustomSignerProvider : SignerProviderInterface { | ||
lateinit var customKeysManager: CustomKeysManager | ||
|
||
override fun get_destination_script(): Result_CVec_u8ZNoneZ { | ||
return Result_CVec_u8ZNoneZ.ok(customKeysManager.destinationScriptPublicKey) | ||
} | ||
|
||
override fun get_shutdown_scriptpubkey(): Result_ShutdownScriptNoneZ { | ||
val res = ShutdownScript.new_witness_program( | ||
WitnessVersion(customKeysManager.witnessProgramVersion), | ||
customKeysManager.witnessProgram | ||
) | ||
|
||
return if (res.is_ok) { | ||
Result_ShutdownScriptNoneZ.ok((res as Result_ShutdownScriptInvalidShutdownScriptZ.Result_ShutdownScriptInvalidShutdownScriptZ_OK).res) | ||
} else { | ||
Result_ShutdownScriptNoneZ.err() | ||
} | ||
} | ||
|
||
override fun derive_channel_signer( | ||
channel_value_satoshis: Long, | ||
channel_keys_id: ByteArray? | ||
): WriteableEcdsaChannelSigner { | ||
return customKeysManager.inner.as_SignerProvider().derive_channel_signer(channel_value_satoshis, channel_keys_id) | ||
} | ||
|
||
override fun generate_channel_keys_id(p0: Boolean, p1: Long, p2: UInt128?): ByteArray { | ||
return customKeysManager.inner.as_SignerProvider().generate_channel_keys_id(p0, p1, p2) | ||
} | ||
|
||
override fun read_chan_signer(p0: ByteArray?): Result_WriteableEcdsaChannelSignerDecodeErrorZ { | ||
return customKeysManager.inner.as_SignerProvider().read_chan_signer(p0!!) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.