-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CORE-16983 / CORE-16967 Atomic Swap with Facade #4691
Closed
Closed
Changes from 13 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
26df684
Jackson serializers and deserializers for DigitalSignatureAndMetadat…
szymonsztuka d8d8cc0
Remove unnecessary comment
szymonsztuka 0526ce0
Merge branch 'release/interop/syntax' into interop/jmac/CORE-16983
jmacmahonr3 1c50caa
initial draft pr
jmacmahonr3 36c9a16
Now adding test cordapp
jmacmahonr3 0a0c3db
Update to serializer
jmacmahonr3 a310103
Add new serializers and deserializers to main Jackson service (for now).
szymonsztuka 559529c
1. Create unit test to recreate: java.lang.ClassCastException: class …
szymonsztuka 0aba6eb
Serializing and deserializing Proof Of action solved.
szymonsztuka 953f17c
Key creation from bytes solved.
szymonsztuka b671b25
Remove test class is the extended version is now in the other module.
szymonsztuka 6f3ee6f
Test flow (unrealistic one) to check signature verification.
szymonsztuka 96c5ec3
Update api version to a temporary build, add TODOs
szymonsztuka 3f3a606
Merge branch 'release/interop/syntax' into interop/jmac/CORE-16983
szymonsztuka 27bb137
Remove unnecessary function with "default" parameter.
szymonsztuka 004a0aa
Remove unnecessary function with "default" parameter use by tests only.
szymonsztuka 8693ed0
Facade Specification doesn't require new serializers, only producing …
szymonsztuka 255f084
FacadeRequestSerializer / FacadeResponseSerializer don't need the exp…
szymonsztuka 2ffecc0
Remove unused change in a dependency.
szymonsztuka dbe4cc9
Verify Signature via RPC flow call.
szymonsztuka cb8296d
Merge branch 'release/interop/syntax' into interop/jmac/CORE-16983
szymonsztuka b773212
Update LockState and Contract to use DigitalSignatureAndMetadata.
szymonsztuka ed56413
Enable serialisation of PublicKey.
szymonsztuka f14fd93
Query to check owned states.
szymonsztuka 527170a
Swap - part on the transaction draft side.
szymonsztuka b766e4d
Merge branch 'release/interop/syntax' into interop/jmac/CORE-16983
szymonsztuka f60bf11
Fix compilation issues after merge from syntax branch.
szymonsztuka 0f034be
Swap - part on transaction with a lock side.
szymonsztuka 69c2ac9
Swap - facade method lock with a generic asset ID instead of a more s…
szymonsztuka f6afa48
DTOs returned by Query Flows.
szymonsztuka 913ae14
Move new additions to UtxoLedgerTest for now into interop test.
szymonsztuka 99a77ae
Test signature proof generation by a notary.
szymonsztuka ad15cc2
Test signature proof generation by a notary.
szymonsztuka 579395c
Merge branch 'szymon/interop/add-signing-utxo-derived-test' into inte…
szymonsztuka fc85ece
Merge branch 'release/interop/syntax' into interop/jmac/CORE-16983
szymonsztuka f10cfe6
Updates after merge from syntax.
szymonsztuka 3fbb794
Updates after merge from syntax.
szymonsztuka c0e931a
Updates after merge from syntax.
szymonsztuka cc62a4b
Merge branch 'release/interop/syntax' into interop/jmac/CORE-16983
szymonsztuka 86a1e95
Remove dependency on implementation library by Json Service, use serv…
szymonsztuka 288018f
Separate service
szymonsztuka 192f7a1
Separate service
szymonsztuka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
295 changes: 295 additions & 0 deletions
295
.../main/kotlin/net/corda/flow/application/services/impl/interop/ProofOfActionSerializers.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,295 @@ | ||
@file:Suppress("WildcardImport") | ||
package net.corda.flow.application.services.impl.interop | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator | ||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.core.JsonToken | ||
import com.fasterxml.jackson.databind.* | ||
import com.fasterxml.jackson.databind.module.SimpleModule | ||
import net.corda.base.internal.ByteSequence | ||
import net.corda.base.internal.OpaqueBytes | ||
import net.corda.crypto.cipher.suite.SignatureSpecImpl | ||
import net.corda.crypto.core.DigitalSignatureWithKeyId | ||
import net.corda.crypto.core.SecureHashImpl | ||
import net.corda.crypto.core.parseSecureHash | ||
import net.corda.crypto.merkle.impl.IndexedMerkleLeafImpl | ||
import net.corda.crypto.merkle.impl.MerkleProofImpl | ||
import net.corda.v5.application.crypto.DigitalSignatureAndMetadata | ||
import net.corda.v5.application.crypto.DigitalSignatureMetadata | ||
import net.corda.v5.crypto.DigitalSignature | ||
import net.corda.v5.crypto.SecureHash | ||
import net.corda.v5.crypto.SignatureSpec | ||
import net.corda.v5.crypto.merkle.IndexedMerkleLeaf | ||
import net.corda.v5.crypto.merkle.MerkleProof | ||
import net.corda.v5.crypto.merkle.MerkleProofType | ||
import java.lang.RuntimeException | ||
import java.time.Instant | ||
|
||
object ProofOfActionSerialisationModule { | ||
val module = SimpleModule().apply { | ||
addSerializer(MerkleProof::class.java, MerkleProofSerializer()) | ||
addDeserializer(MerkleProof::class.java, MerkleProofDeserializer()) | ||
addSerializer(SignatureSpec::class.java, SignatureSpecSerializer()) | ||
addDeserializer(SignatureSpec::class.java, SignatureSpecDeserializer()) | ||
addSerializer(DigitalSignatureMetadata::class.java, DigitalSignatureMetadataSerializer()) | ||
addDeserializer(DigitalSignatureMetadata::class.java, DigitalSignatureMetadataDeserializer()) | ||
addSerializer(DigitalSignature.WithKeyId::class.java, DigitalSignatureWithKeyIdSerializer()) | ||
addSerializer(DigitalSignatureWithKeyId::class.java, DigitalSignatureWithKeyIdSerializer()) | ||
addDeserializer(DigitalSignature.WithKeyId::class.java, DigitalSignatureWithKeyIdDeserializer()) | ||
addSerializer(DigitalSignatureAndMetadata::class.java, DigitalSignatureAndMetadataSerializer()) | ||
addDeserializer(DigitalSignatureAndMetadata::class.java, DigitalSignatureAndMetadataDeserializer()) | ||
addSerializer(IndexedMerkleLeaf::class.java, IndexedMerkleLeafSerializer()) | ||
addDeserializer(IndexedMerkleLeaf::class.java, IndexedMerkleLeafDeserializer()) | ||
addSerializer(OpaqueBytes::class.java, OpaqueBytesSerializer()) | ||
addDeserializer(OpaqueBytes::class.java, OpaqueBytesDeserializer()) | ||
addSerializer(ByteSequence::class.java, ByteSequenceSerializer()) | ||
addDeserializer(ByteSequence::class.java, ByteSequenceDeserializer()) | ||
addSerializer(SecureHash::class.java, SecureHashSerializer()) | ||
addSerializer(SecureHashImpl::class.java, SecureHashSerializer()) | ||
addDeserializer(SecureHash::class.java, SecureHashDeserializer()) | ||
addSerializer(IndexedMerkleLeaf::class.java, IndexedMerkleLeafSerializer()) | ||
addSerializer(IndexedMerkleLeafImpl::class.java, IndexedMerkleLeafSerializer()) | ||
addDeserializer(IndexedMerkleLeaf::class.java, IndexedMerkleLeafDeserializer()) | ||
} | ||
} | ||
|
||
class IndexedMerkleLeafSerializer : JsonSerializer<IndexedMerkleLeaf>() { | ||
override fun serialize( | ||
leaf: IndexedMerkleLeaf, | ||
gen: JsonGenerator, | ||
serializers: SerializerProvider | ||
) { | ||
gen.writeStartObject() | ||
gen.writeObjectField("index", leaf.getIndex()) | ||
gen.writeObjectField("nonce", leaf.getNonce()) | ||
gen.writeObjectField("leafData", leaf.getLeafData()) | ||
gen.writeEndObject() | ||
} | ||
} | ||
|
||
class IndexedMerkleLeafDeserializer : JsonDeserializer<IndexedMerkleLeaf>() { | ||
override fun deserialize( | ||
parser: JsonParser, | ||
ctxt: DeserializationContext | ||
): IndexedMerkleLeafImpl { | ||
val node: JsonNode = parser.codec.readTree(parser) | ||
val index = node.get("index").asInt() | ||
val nonce = if (node.has("nonce")) node.get("nonce").binaryValue() else null | ||
val leafData = node.get("leafData").binaryValue() | ||
|
||
return IndexedMerkleLeafImpl(index, nonce, leafData) | ||
} | ||
} | ||
|
||
class MerkleProofSerializer : JsonSerializer<MerkleProof>() { | ||
override fun serialize( | ||
merkleProof: MerkleProof, | ||
generator: JsonGenerator, | ||
provider: SerializerProvider | ||
) { | ||
generator.writeStartObject() | ||
generator.writeStringField("proofType", merkleProof.getProofType().name) | ||
generator.writeNumberField("treeSize", merkleProof.getTreeSize()) | ||
generator.writeArrayFieldStart("leaves") | ||
for (leaf in merkleProof.leaves) { | ||
generator.writeObject(leaf) | ||
} | ||
generator.writeEndArray() | ||
generator.writeArrayFieldStart("hashes") | ||
for (hash in merkleProof.hashes) { | ||
generator.writeObject(hash) | ||
} | ||
generator.writeEndArray() | ||
generator.writeEndObject() | ||
} | ||
} | ||
|
||
class MerkleProofDeserializer : JsonDeserializer<MerkleProof>() { | ||
override fun deserialize( | ||
parser: JsonParser, | ||
ctxt: DeserializationContext | ||
): MerkleProof { | ||
val node: JsonNode = parser.codec.readTree(parser) | ||
val proofType = MerkleProofType.valueOf(node.get("proofType").asText()) | ||
val treeSize = node.get("treeSize").asInt() | ||
val leavesNode = node.get("leaves") | ||
val leaves = mutableListOf<IndexedMerkleLeaf>() | ||
for (leafNode in leavesNode) { | ||
val leaf = parser.codec.treeToValue(leafNode, IndexedMerkleLeaf::class.java) | ||
leaves.add(leaf) | ||
} | ||
val hashesNode = node.get("hashes") | ||
val hashes = mutableListOf<SecureHash>() | ||
for (hashNode in hashesNode) { | ||
val hash = parser.codec.treeToValue(hashNode, SecureHash::class.java) | ||
hashes.add(hash) | ||
} | ||
return MerkleProofImpl(proofType, treeSize, leaves, hashes) | ||
} | ||
} | ||
|
||
class SignatureSpecSerializer : JsonSerializer<SignatureSpec>() { | ||
override fun serialize( | ||
spec: SignatureSpec, | ||
generator: JsonGenerator, | ||
provider: SerializerProvider | ||
) { | ||
generator.writeString(spec.getSignatureName()) | ||
} | ||
} | ||
|
||
class SignatureSpecDeserializer : JsonDeserializer<SignatureSpec>() { | ||
override fun deserialize( | ||
parser: JsonParser, | ||
ctxt: DeserializationContext | ||
): SignatureSpec { | ||
val signatureName = parser.text | ||
return SignatureSpecImpl(signatureName) | ||
} | ||
} | ||
|
||
|
||
class DigitalSignatureMetadataSerializer : JsonSerializer<DigitalSignatureMetadata>() { | ||
override fun serialize( | ||
metadata: DigitalSignatureMetadata, | ||
generator: JsonGenerator, | ||
provider: SerializerProvider | ||
) { | ||
generator.writeStartObject() | ||
generator.writeStringField("timestamp", metadata.timestamp.toString()) | ||
generator.writeObjectField("signatureSpec", metadata.signatureSpec) | ||
generator.writeObjectField("properties", metadata.properties) | ||
generator.writeEndObject() | ||
} | ||
} | ||
|
||
class DigitalSignatureMetadataDeserializer : JsonDeserializer<DigitalSignatureMetadata>() { | ||
override fun deserialize( | ||
parser: JsonParser, | ||
ctxt: DeserializationContext | ||
): DigitalSignatureMetadata { | ||
val node = parser.codec.readTree(parser) as JsonNode | ||
val timestamp = Instant.parse(node.get("timestamp").asText()) | ||
val signatureSpec = parser.codec.treeToValue(node.get("signatureSpec"), SignatureSpec::class.java) | ||
@Suppress("unchecked_cast") | ||
val properties = parser.codec.treeToValue(node.get("properties"), Map::class.java).toMutableMap() as MutableMap<String, String> | ||
return DigitalSignatureMetadata(timestamp, signatureSpec, properties) | ||
} | ||
} | ||
|
||
class DigitalSignatureAndMetadataSerializer : JsonSerializer<DigitalSignatureAndMetadata>() { | ||
override fun serialize( | ||
signatureAndMetadata: DigitalSignatureAndMetadata, | ||
generator: JsonGenerator, | ||
provider: SerializerProvider | ||
) { | ||
generator.writeStartObject() | ||
generator.writeObjectField("signature", signatureAndMetadata.signature) | ||
generator.writeObjectField("metadata", signatureAndMetadata.metadata) | ||
generator.writeObjectField("proof", signatureAndMetadata.proof) | ||
generator.writeEndObject() | ||
} | ||
} | ||
|
||
class OpaqueBytesSerializer : JsonSerializer<OpaqueBytes>() { | ||
override fun serialize( | ||
opaqueBytes: OpaqueBytes, | ||
generator: JsonGenerator, | ||
provider: SerializerProvider | ||
) { | ||
generator.writeBinary(opaqueBytes.getBytes()) | ||
} | ||
} | ||
|
||
class OpaqueBytesDeserializer : JsonDeserializer<OpaqueBytes>() { | ||
override fun deserialize( | ||
parser: JsonParser, | ||
ctxt: DeserializationContext | ||
): OpaqueBytes { | ||
val bytes = parser.getBinaryValue() | ||
return OpaqueBytes(bytes) | ||
} | ||
} | ||
|
||
class DigitalSignatureAndMetadataDeserializer : JsonDeserializer<DigitalSignatureAndMetadata>() { | ||
override fun deserialize( | ||
parser: JsonParser, | ||
ctxt: DeserializationContext | ||
): DigitalSignatureAndMetadata { | ||
val node = parser.codec.readTree(parser) as JsonNode | ||
val signature = parser.codec.treeToValue(node.get("signature"), DigitalSignature.WithKeyId::class.java) | ||
val metadata = parser.codec.treeToValue(node.get("metadata"), DigitalSignatureMetadata::class.java) | ||
val proof = parser.codec.treeToValue(node.get("proof"), MerkleProof::class.java) | ||
return DigitalSignatureAndMetadata(signature, metadata, proof) | ||
} | ||
} | ||
|
||
class ByteSequenceSerializer : JsonSerializer<ByteSequence>() { | ||
override fun serialize( | ||
byteSequence: ByteSequence, | ||
generator: JsonGenerator, | ||
provider: SerializerProvider | ||
) { | ||
generator.writeBinary(byteSequence.getBytes()) | ||
} | ||
} | ||
|
||
class ByteSequenceDeserializer : JsonDeserializer<ByteSequence>() { | ||
override fun deserialize( | ||
parser: JsonParser, | ||
ctxt: DeserializationContext | ||
): ByteSequence { | ||
val bytes = parser.getBinaryValue() | ||
return OpaqueBytes(bytes) | ||
} | ||
} | ||
|
||
class DigitalSignatureWithKeyIdSerializer : JsonSerializer<DigitalSignature.WithKeyId>() { | ||
override fun serialize( | ||
signature: DigitalSignature.WithKeyId?, | ||
generator: JsonGenerator?, | ||
provider: SerializerProvider | ||
) { | ||
generator!!.writeStartObject() | ||
generator.writeObjectField("by", signature!!.by) | ||
generator.writeFieldName("bytes") | ||
generator.writeBinary(signature.bytes) | ||
generator.writeEndObject() | ||
} | ||
} | ||
|
||
class DigitalSignatureWithKeyIdDeserializer : JsonDeserializer<DigitalSignature.WithKeyId>() { | ||
override fun deserialize( | ||
parser: JsonParser, | ||
ctxt: DeserializationContext | ||
): DigitalSignature.WithKeyId { | ||
val node = parser.codec.readTree(parser) as JsonNode | ||
val by = parser.codec.treeToValue(node.get("by"), SecureHash::class.java) | ||
val bytes = node.get("bytes").binaryValue() | ||
return DigitalSignatureWithKeyId(by, bytes) | ||
} | ||
} | ||
|
||
class SecureHashSerializer : JsonSerializer<SecureHash>() { | ||
override fun serialize( | ||
secureHash: SecureHash, | ||
generator: JsonGenerator, | ||
provider: SerializerProvider | ||
) { | ||
generator.writeString(secureHash.toString()) | ||
} | ||
} | ||
|
||
@Suppress("TooGenericExceptionThrown") | ||
class SecureHashDeserializer : JsonDeserializer<SecureHash>() { | ||
override fun deserialize( | ||
parser: JsonParser, | ||
ctxt: DeserializationContext | ||
): SecureHash { | ||
if (parser.currentToken == JsonToken.VALUE_STRING) { | ||
return parseSecureHash(parser.text) | ||
} | ||
|
||
throw RuntimeException("Expected a string for SecureHash") | ||
} | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on
-impl
looks a bit suspicious.Dependencies should be injected via OSGi.
Although probably some direct constructors are not available via OSGi.