Skip to content

Commit

Permalink
Merge pull request #99 from metaplex-foundation/martini/base64-nowrap
Browse files Browse the repository at this point in the history
Fix Base64 newline/wrapping
  • Loading branch information
ajamaica authored Feb 6, 2023
2 parents 3deab25 + 7702976 commit 3b92537
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ suspend fun Connection.sendTransaction(serializedTransaction: String): Result<St
get(SendTransactionRequest(serializedTransaction, transactionOptions), String.serializer())

suspend fun Connection.sendTransaction(transaction: Transaction): Result<String> =
sendTransaction(Base64.encodeToString(transaction.serialize(), Base64.DEFAULT))
sendTransaction(Base64.encodeToString(transaction.serialize(), Base64.NO_WRAP))
//endregion

// Inlines let us hide the serialization complexity while still providing full control
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ suspend fun Transaction.signAndSend(connection: Connection, payer: IdentityDrive
return Result.failure(it)
}

val serializedTxn = Base64.encodeToString(signedTxn.serialize(), Base64.DEFAULT)
val serializedTxn = Base64.encodeToString(signedTxn.serialize(), Base64.NO_WRAP)

// sign and send transaction
return connection.get(
Expand All @@ -78,7 +78,7 @@ suspend fun Transaction.signAndSend(connection: Connection, signers: List<Accoun
sign(signers)

// send transaction
return connection.sendTransaction(Base64.encodeToString(serialize(), Base64.DEFAULT))
return connection.sendTransaction(Base64.encodeToString(serialize(), Base64.NO_WRAP))
}

suspend fun Transaction.signSendAndConfirm(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ object ByteArrayAsBase64JsonArraySerializer: KSerializer<ByteArray> {

override fun serialize(encoder: Encoder, value: ByteArray) =
encoder.encodeSerializableValue(delegateSerializer, listOf(
Base64.encodeToString(value, Base64.DEFAULT), "base64"
Base64.encodeToString(value, Base64.NO_WRAP), "base64"
))

override fun deserialize(decoder: Decoder): ByteArray {
decoder.decodeSerializableValue(delegateSerializer).apply {
if (contains("base64")) first { it != "base64" }.apply {
return Base64.decode(this, Base64.DEFAULT)
return Base64.decode(this, Base64.NO_WRAP)
}
else throw(SerializationException("Not Base64"))
}
Expand Down

0 comments on commit 3b92537

Please sign in to comment.