-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add txn build, sign, and submission features
- Implemented txn construction with customizable parameters. - Integrated signing (JVM and Android). - Added txn submission. - Enhanced error handling and validation.
- Loading branch information
Showing
41 changed files
with
1,213 additions
and
41 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
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
45 changes: 45 additions & 0 deletions
45
lib/src/androidJvmMain/kotlin/xyz/mcxross/kaptos/core/crypto/Platform.androidJvm.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,45 @@ | ||
/* | ||
* Copyright 2024 McXross | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package xyz.mcxross.kaptos.core.crypto | ||
|
||
import io.ktor.util.reflect.* | ||
import xyz.mcxross.bcs.Bcs | ||
import xyz.mcxross.kaptos.model.AnyRawTransaction | ||
import xyz.mcxross.kaptos.transaction.builder.deriveTransactionType | ||
import xyz.mcxross.kaptos.transaction.instances.RawTransaction | ||
import xyz.mcxross.kaptos.util.RAW_TRANSACTION_SALT | ||
|
||
actual fun generateSigningMessage(transaction: AnyRawTransaction): ByteArray { | ||
val rawTxn = deriveTransactionType(transaction) | ||
val hash = org.bouncycastle.jcajce.provider.digest.SHA3.Digest256() | ||
|
||
if (transaction.instanceOf(RawTransaction::class)) { | ||
hash.update(RAW_TRANSACTION_SALT.encodeToByteArray()) | ||
} | ||
|
||
val body = Bcs.encodeToByteArray<RawTransaction>(rawTxn as RawTransaction) | ||
|
||
return hash.digest() + body | ||
} | ||
|
||
actual fun sign(message: ByteArray, privateKey: ByteArray): ByteArray { | ||
val signer = org.bouncycastle.crypto.signers.Ed25519Signer() | ||
val privateKeyParameters = | ||
org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters(privateKey, 0) | ||
signer.init(true, privateKeyParameters) | ||
signer.update(message, 0, message.size) | ||
return signer.generateSignature() | ||
} |
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
49 changes: 49 additions & 0 deletions
49
lib/src/commonMain/kotlin/xyz/mcxross/kaptos/api/txsubmission/Build.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,49 @@ | ||
/* | ||
* Copyright 2024 McXross | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package xyz.mcxross.kaptos.api.txsubmission | ||
|
||
import xyz.mcxross.kaptos.internal.generateTransaction | ||
import xyz.mcxross.kaptos.model.* | ||
|
||
/** A class to handle all `Build` transaction operations */ | ||
class Build(val config: AptosConfig) { | ||
|
||
/** | ||
* Build a simple transaction | ||
* | ||
* @param sender The sender account address | ||
* @param data The transaction data | ||
* @param options optional. Optional transaction configurations | ||
* @param withFeePayer optional. Whether there is a fee payer for the transaction | ||
* @returns [SimpleTransaction] | ||
*/ | ||
suspend fun simple( | ||
sender: AccountAddressInput, | ||
data: InputGenerateTransactionPayloadData, | ||
options: InputGenerateTransactionOptions? = null, | ||
withFeePayer: Boolean = false, | ||
): SimpleTransaction { | ||
val singleSignerRawTransactionData = | ||
InputGenerateSingleSignerRawTransactionData( | ||
sender = sender, | ||
data = data, | ||
options = options, | ||
withFeePayer = withFeePayer, | ||
secondarySignerAddresses = null, | ||
) | ||
return generateTransaction(config, singleSignerRawTransactionData) as SimpleTransaction | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
lib/src/commonMain/kotlin/xyz/mcxross/kaptos/api/txsubmission/Submit.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,42 @@ | ||
/* | ||
* Copyright 2024 McXross | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package xyz.mcxross.kaptos.api.txsubmission | ||
|
||
import xyz.mcxross.kaptos.internal.submitTransaction | ||
import xyz.mcxross.kaptos.model.* | ||
import xyz.mcxross.kaptos.transaction.authenticatior.AccountAuthenticator | ||
|
||
class Submit(private val aptosConfig: AptosConfig) { | ||
|
||
/** | ||
* Submit a simple transaction | ||
* | ||
* @param transaction An instance of a raw transaction | ||
* @param senderAuthenticator optional. The sender account authenticator | ||
* @param feePayerAuthenticator optional. The fee payer account authenticator if it is a fee payer | ||
* transaction | ||
* @returns PendingTransactionResponse | ||
*/ | ||
suspend fun simple( | ||
transaction: AnyRawTransaction, | ||
senderAuthenticator: AccountAuthenticator, | ||
feePayerAuthenticator: AccountAuthenticator? = null, | ||
): Option<PendingTransactionResponse> = | ||
submitTransaction( | ||
aptosConfig = aptosConfig, | ||
InputSubmitTransactionData(transaction, senderAuthenticator, feePayerAuthenticator), | ||
) | ||
} |
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
Oops, something went wrong.