-
Notifications
You must be signed in to change notification settings - Fork 0
feat: improve txmetadata features #22
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
Changes from 9 commits
5d514d9
69a2bd3
3c5810f
7362d3d
b590753
4176624
b2f5a97
b922d77
29d7618
c2a6020
c66b9aa
a19feeb
5325fcb
9f05f37
9a24687
bc2010c
149c339
b5e505e
68bf870
6c3d28c
b35c9cd
24c4ca4
e53e4a5
9965ca9
04bd06b
8229fc3
ba3b391
2579d9a
6a714ae
62d56d4
08ff507
102b200
46fd025
5ee49e9
dc20aec
d9739e7
17bd342
b43ab11
9fdae81
53679cc
436c5a3
53fd75e
29dfa72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,13 +14,19 @@ import org.bouncycastle.crypto.params.KeyParameter | |
| import org.dashj.platform.dpp.document.Document | ||
| import org.dashj.platform.dpp.util.Cbor | ||
| import org.dashj.platform.sdk.platform.AbstractDocument | ||
| import org.dashj.platform.wallet.TxMetadataItem | ||
| import org.dashj.platform.wallet.WalletUtils.TxMetadataBatch | ||
|
|
||
| class TxMetadataDocument(document: Document) : AbstractDocument(document) { | ||
|
|
||
| companion object { | ||
| // 2^16 + 2 | ||
| val childNumber = ChildNumber(2 shl 15 + 1, true) | ||
| const val MAX_ENCRYPTED_SIZE = 4096 - 32 // leave room for a partially filled block and the IV | ||
|
|
||
|
Comment on lines
21
to
26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Operator precedence bug in child number expression.
Apply: - // 2^16 + 2
- val childNumber = ChildNumber(2 shl 15 + 1, true)
+ // 2^16 + 2 = 65538
+ val childNumber = ChildNumber((1 shl 16) + 2, true)Also fix the same expression in tests (BlockchainIdentityTest.kt Lines 172–173). 🤖 Prompt for AI Agents |
||
| const val VERSION_UNKNOWN = -1 | ||
| const val VERSION_CBOR = 0 | ||
| const val VERSION_PROTOBUF = 1 | ||
| } | ||
|
|
||
| val keyIndex: Int | ||
|
|
@@ -29,6 +35,8 @@ class TxMetadataDocument(document: Document) : AbstractDocument(document) { | |
| get() = (document.data["encryptionKeyIndex"] as Long).toInt() | ||
| val encryptedMetadata: ByteArray | ||
| get() = getFieldByteArray("encryptedMetadata")!! | ||
| var txMetadataVersion = VERSION_UNKNOWN | ||
| private set | ||
|
|
||
| override fun equals(other: Any?): Boolean { | ||
| if (this === other) return true | ||
|
|
@@ -53,9 +61,20 @@ class TxMetadataDocument(document: Document) : AbstractDocument(document) { | |
| val iv = encryptedMetadata.copyOfRange(0, 16) | ||
| val encryptedData = encryptedMetadata.copyOfRange(16, encryptedMetadata.size) | ||
| val decryptedData = cipher.decrypt(EncryptedData(iv, encryptedData), keyParameter) | ||
| // use Cbor.decodeList | ||
| val list = Cbor.decodeList(decryptedData) | ||
| // use .map to convert to List<TxMetadataItem> | ||
| return list.map { TxMetadataItem(it as Map<String, Any?>) } | ||
| val version = decryptedData.copyOfRange(0, 1)[0].toInt() and 0xFF | ||
| return when (version) { | ||
| VERSION_CBOR -> { | ||
| val list = Cbor.decodeList(decryptedData) | ||
| this.txMetadataVersion = VERSION_CBOR | ||
| // use .map to convert to List<TxMetadataItem> | ||
| list.map { TxMetadataItem(it as Map<String, Any?>) } | ||
| } | ||
HashEngineering marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| VERSION_PROTOBUF -> { | ||
| val batch = TxMetadataBatch.parser().parseFrom(decryptedData, 1, decryptedData.size - 1) | ||
| txMetadataVersion = VERSION_PROTOBUF | ||
| batch.itemsList.map { TxMetadataItem(it) } | ||
| } | ||
HashEngineering marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| else -> error("") | ||
| } | ||
HashEngineering marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.