Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ coroutines = "1.6.4"
google-gson = "2.8.9"
hoplite = "2.7.0"
jjwt = "0.12.5"
java-stellar-sdk = "1.0.0"
java-stellar-sdk = "2.0.0"
dokka = "1.6.10"
kotlin = "1.8.20"
kotlinx-json = "1.5.0"
Expand Down
22 changes: 22 additions & 0 deletions wallet-sdk/src/main/kotlin/org/stellar/walletsdk/Wallet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import org.stellar.walletsdk.json.defaultJson
import org.stellar.walletsdk.recovery.Recovery
import org.stellar.walletsdk.recovery.RecoveryServer
import org.stellar.walletsdk.recovery.RecoveryServerKey
import org.stellar.walletsdk.uri.Sep7
import org.stellar.walletsdk.uri.Sep7Base

/**
* Wallet SDK main entry point. It provides methods to build wallet applications on the Stellar
Expand Down Expand Up @@ -50,6 +52,26 @@ class Wallet(
return Recovery(cfg, stellar(), getClient(httpClientConfig), servers)
}

/**
* Access SEP-7 URI functionality for creating and parsing Stellar URIs.
*
* @return Sep7 object providing SEP-7 utilities
*/
fun uri(): Sep7 {
return Sep7
}

/**
* Parse a SEP-7 URI string into the appropriate Sep7 object.
*
* @param uriString The SEP-7 URI string to parse
* @return Sep7Base instance (either Sep7Pay or Sep7Tx)
* @throws org.stellar.walletsdk.uri.Sep7InvalidUriError if the URI is invalid
*/
fun parseSep7Uri(uriString: String): Sep7Base {
return Sep7.parseUri(uriString)
}

override fun close() {
clients.forEach { it.close() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ abstract class CommonTransactionBuilder<T>(protected val sourceAddress: String)
"$sourceAddress, signerAddress = $signerAddress, signerWeight = $signerWeight"
}

val signer = Signer.ed25519PublicKey(signerAddress.keyPair)
val signerKey = SignerKey.fromEd25519PublicKey(signerAddress.keyPair.accountId)

SetOptionsOperation.builder()
.sourceAccount(sourceAddress)
.signer(signer)
.signer(signerKey)
.signerWeight(signerWeight)
.build()
}
Expand Down
15 changes: 15 additions & 0 deletions wallet-sdk/src/main/kotlin/org/stellar/walletsdk/toml/Data.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ data class TomlInfo(
} else {
null
},
sep7 =
if (uriRequestSigningKey != null) {
Sep7(uriRequestSigningKey)
} else {
null
},
sep10 =
if (hasAuth) {
Sep10(webAuthEndpoint.toString(), signingKey.toString())
Expand Down Expand Up @@ -165,6 +171,7 @@ data class InfoCurrency(

data class InfoServices(
val sep6: Sep6?,
val sep7: Sep7?,
val sep10: Sep10?,
val sep12: Sep12?,
val sep24: Sep24?,
Expand All @@ -181,6 +188,14 @@ data class InfoServices(
*/
data class Sep6(val transferServer: String, val anchorQuoteServer: String?)

/**
* [SEP-7](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0007.md): URI
* scheme for Stellar transactions and operations.
*
* @property signingKey Stellar public address of the URI request signing key
*/
data class Sep7(val signingKey: String)

/**
* [SEP-10](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md): Stellar
* web authentication.
Expand Down
72 changes: 72 additions & 0 deletions wallet-sdk/src/main/kotlin/org/stellar/walletsdk/uri/Sep7.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.stellar.walletsdk.uri

/**
* SEP-7 URI Support
*
* This package provides support for SEP-7 (URI Scheme to facilitate delegated signing).
* @see [SEP-0007](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0007.md)
*
* Main components:
* - [Sep7Pay]
* - Represents payment operations
* - [Sep7Tx]
* - Represents transaction operations
* - [Sep7Parser]
* - Utilities for parsing and validating SEP-7 URIs
*
* Example usage:
* ```kotlin
* // Create a payment URI
* val payUri = Sep7Pay.forDestination("GACCOUNT...")
* .amount("100")
* .assetCode("USDC")
* .callback("https://myapp.com/callback")
*
* // Parse a URI
* val uri = Sep7Parser.parseSep7Uri("web+stellar:pay?destination=G...")
* when (uri) {
* is Sep7Pay -> handlePayment(uri)
* is Sep7Tx -> handleTransaction(uri)
* }
*
* // Validate a URI
* val validation = Sep7Parser.isValidSep7Uri(uriString)
* if (!validation.result) {
* println("Invalid URI: ${validation.reason}")
* }
* ```
*/
object Sep7 {
/**
* Parse a SEP-7 URI string into the appropriate Sep7 object
* @param uriString The URI string to parse
* @return Sep7Pay or Sep7Tx instance
* @throws Sep7InvalidUriError if the URI is invalid
*/
@JvmStatic fun parseUri(uriString: String): Sep7Base = Sep7Parser.parseSep7Uri(uriString)

/**
* Check if a URI string is a valid SEP-7 URI
* @param uriString The URI string to validate
* @return Validation result with success status and optional error reason
*/
@JvmStatic
fun isValidUri(uriString: String): IsValidSep7UriResult = Sep7Parser.isValidSep7Uri(uriString)

/**
* Create a new payment URI
* @param destination The destination Stellar address
* @return Sep7Pay instance
*/
@JvmStatic
fun createPaymentUri(destination: String): Sep7Pay = Sep7Pay.forDestination(destination)

/**
* Create a new transaction URI
* @param transaction The transaction to encode
* @return Sep7Tx instance
*/
@JvmStatic
fun createTransactionUri(transaction: org.stellar.sdk.Transaction): Sep7Tx =
Sep7Tx.forTransaction(transaction)
}
Loading