-
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.
Merge pull request #142 from avianlabs/guillermo/allow-for-half-secre…
…t-keys allow for half secret keys
- Loading branch information
Showing
8 changed files
with
58 additions
and
20 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
24 changes: 24 additions & 0 deletions
24
tweetnacl-multiplatform/src/commonTest/kotlin/net/avianlabs/solana/tweetnacl/Ed25519Test.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,24 @@ | ||
package net.avianlabs.solana.tweetnacl | ||
|
||
import net.avianlabs.solana.tweetnacl.ed25519.Ed25519Keypair | ||
import net.avianlabs.solana.tweetnacl.vendor.decodeBase58 | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class Ed25519Test { | ||
private val secretKey = | ||
"ftqmzZS6Va5xuyCdks47WZd1D8FpXZaPGqL3JE39814pReiEuTAvJpr8PxkUxm9wHKHTsfN8TGk44hhoEdQDYrD".decodeBase58() | ||
|
||
@Test | ||
fun test_chopping_and_restoring() { | ||
val chopped = secretKey.take(32).toByteArray() | ||
|
||
val restored = Ed25519Keypair.fromSecretKeyBytes(chopped).secretKey | ||
|
||
@OptIn(ExperimentalStdlibApi::class) | ||
assertEquals( | ||
secretKey.toHexString(), | ||
restored.toHexString(), | ||
) | ||
} | ||
} |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
tweetnacl-multiplatform/src/nativeInterop/cinterop/TweetNaCl.def
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,2 +1,2 @@ | ||
--- | ||
extern int is_on_curve(const unsigned char *); | ||
extern int is_on_curve(const unsigned char *); |
19 changes: 19 additions & 0 deletions
19
tweetnacl-multiplatform/src/nativeMain/kotlin/net/avianlabs/solana/tweetnacl/ByteArray.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,19 @@ | ||
@file:OptIn(ExperimentalForeignApi::class) | ||
|
||
package net.avianlabs.solana.tweetnacl | ||
|
||
import kotlinx.cinterop.CPointer | ||
import kotlinx.cinterop.ExperimentalForeignApi | ||
import kotlinx.cinterop.UByteVar | ||
import kotlinx.cinterop.get | ||
|
||
internal fun CPointer<UByteVar>.toByteArray(length: Int): ByteArray { | ||
val nativeBytes = this | ||
val bytes = ByteArray(length) | ||
var index = 0 | ||
while (index < length) { | ||
bytes[index] = nativeBytes[index].toByte() | ||
++index | ||
} | ||
return bytes | ||
} |
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