-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
40 additions
and
26 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
7 changes: 7 additions & 0 deletions
7
solana-kotlin/src/iosMain/kotlin/net/avianlabs/solana/domain/core/Transaction.ios.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,7 @@ | ||
package net.avianlabs.solana.domain.core | ||
|
||
import kotlinx.cinterop.* | ||
import net.avianlabs.solana.tweetnacl.ed25519.toNSData | ||
import platform.Foundation.NSData | ||
|
||
public fun Transaction.serializeData(): NSData = serialize().toNSData() |
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
28 changes: 28 additions & 0 deletions
28
...acl-multiplatform/src/iosMain/kotlin/net/avianlabs/solana/tweetnacl/ed25519/NSData.ios.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,28 @@ | ||
@file:OptIn( | ||
ExperimentalForeignApi::class, | ||
BetaInteropApi::class, | ||
) | ||
|
||
package net.avianlabs.solana.tweetnacl.ed25519 | ||
|
||
import kotlinx.cinterop.* | ||
import platform.Foundation.NSData | ||
import platform.Foundation.create | ||
import platform.posix.memcpy | ||
|
||
public fun NSData.toKotlinByteArray(): ByteArray = ByteArray(length.toInt()).apply { | ||
usePinned { pinned: Pinned<ByteArray> -> | ||
memcpy( | ||
__dst = pinned.addressOf(0), | ||
__src = this@toKotlinByteArray.bytes, | ||
__n = this@toKotlinByteArray.length, | ||
) | ||
} | ||
} | ||
|
||
public fun ByteArray.toNSData(): NSData = memScoped { | ||
NSData.create( | ||
bytes = allocArrayOf(this@toNSData), | ||
length = size.toULong(), | ||
) | ||
} |
24 changes: 2 additions & 22 deletions
24
...-multiplatform/src/iosMain/kotlin/net/avianlabs/solana/tweetnacl/ed25519/PublicKey.ios.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 |
---|---|---|
@@ -1,31 +1,11 @@ | ||
@file:OptIn( | ||
ExperimentalForeignApi::class, | ||
BetaInteropApi::class, | ||
) | ||
|
||
package net.avianlabs.solana.tweetnacl.ed25519 | ||
|
||
import kotlinx.cinterop.* | ||
import platform.Foundation.NSData | ||
import platform.Foundation.create | ||
import platform.posix.memcpy | ||
|
||
public fun PublicKey(data: NSData): PublicKey = PublicKey( | ||
bytes = ByteArray(data.length.toInt()).apply { | ||
usePinned { pinned -> | ||
memcpy( | ||
__dst = pinned.addressOf(0), | ||
__src = data.bytes, | ||
__n = data.length, | ||
) | ||
} | ||
} | ||
bytes = data.toKotlinByteArray(), | ||
) | ||
|
||
public val PublicKey.data: NSData | ||
get() = memScoped { | ||
NSData.create( | ||
bytes = allocArrayOf(bytes), | ||
length = bytes.size.toULong(), | ||
) | ||
} | ||
get() = bytes.toNSData() |