@@ -2249,17 +2249,26 @@ class BlockchainIdentity {
22492249 return " assetlocktx=$txid &pk=$wif &du=${currentUsername!! } &islock=${cftx.confidence.instantSendlock.toStringHex()} "
22502250 }
22512251
2252- // Transaction Metadata Methods
22532252 @Throws(KeyCrypterException ::class )
2254- fun publishTxMetaData (txMetadataItems : List <TxMetadataItem >, keyParameter : KeyParameter ? , keyIndex : Int , version : Int ) {
2253+ fun createTxMetadata (txMetadataItems : List <TxMetadataItem >, keyParameter : KeyParameter ? , encryptionKeyIndex : Int , version : Int ): List < Document > {
22552254 if (! platform.hasApp(" wallet-utils" )) {
2256- return
2255+ return arrayListOf ()
22572256 }
2258- val encryptionKeyIndex = 0
2259- val encryptionKey = privateKeyAtPath(keyIndex, TxMetadataDocument .childNumber, encryptionKeyIndex, KeyType .ECDSA_SECP256K1 , keyParameter)
2257+ val encryptionIdentityPublicKey = identity!! .getFirstPublicKey(Purpose .ENCRYPTION , SecurityLevel .MEDIUM )
2258+ ? : identity!! .getFirstPublicKey(Purpose .AUTHENTICATION , SecurityLevel .HIGH )
2259+ ? : error(" can't find a authentication public key with HIGH security level or encryption key" )
2260+ val keyIndex = encryptionIdentityPublicKey.id
2261+ val encryptionKey = privateKeyAtPath(
2262+ keyIndex,
2263+ TxMetadataDocument .childNumber,
2264+ encryptionKeyIndex,
2265+ KeyType .ECDSA_SECP256K1 ,
2266+ keyParameter
2267+ )
22602268
22612269 var lastItem: TxMetadataItem ? = null
22622270 var currentIndex = 0
2271+ val result = arrayListOf<Document >()
22632272 log.info(" publish ${txMetadataItems.size} by breaking it up into pieces" )
22642273 while (currentIndex < txMetadataItems.size) {
22652274 var estimatedDocSize = 0
@@ -2291,16 +2300,33 @@ class BlockchainIdentity {
22912300 allEncryptedData[0 ] = version.toByte()
22922301 encryptedData.initialisationVector.copyInto(allEncryptedData, 1 )
22932302 encryptedData.encryptedBytes.copyInto(allEncryptedData, encryptedData.initialisationVector.size + 1 )
2294- txMetadata.create (
2303+ val txMetadataDocument = txMetadata.createDocument (
22952304 keyIndex,
22962305 encryptionKeyIndex,
22972306 allEncryptedData,
22982307 identity!! ,
2299- KeyIndexPurpose .AUTHENTICATION .ordinal,
2300- WalletSignerCallback (wallet!! , keyParameter)
23012308 )
2309+ result.add(txMetadataDocument)
23022310 currentMetadataItems.clear()
23032311 }
2312+ return result
2313+ }
2314+
2315+ // Transaction Metadata Methods
2316+ @Throws(KeyCrypterException ::class )
2317+ fun publishTxMetaData (txMetadataItems : List <TxMetadataItem >, keyParameter : KeyParameter ? , encryptionKeyIndex : Int , version : Int ) {
2318+ if (! platform.hasApp(" wallet-utils" )) {
2319+ return
2320+ }
2321+ val documentsToPublish = createTxMetadata(txMetadataItems, keyParameter, encryptionKeyIndex, version)
2322+ val txMetadata = TxMetadata (platform)
2323+ documentsToPublish.forEach { txMetadataDocument ->
2324+ txMetadata.publish(
2325+ txMetadataDocument,
2326+ identity!! ,
2327+ WalletSignerCallback (wallet!! , keyParameter)
2328+ )
2329+ }
23042330 }
23052331
23062332 fun getTxMetaData (createdAfter : Long = -1, keyParameter : KeyParameter ? ): Map <TxMetadataDocument , List <TxMetadataItem >> {
@@ -2319,6 +2345,7 @@ class BlockchainIdentity {
23192345
23202346 @Throws(KeyCrypterException ::class )
23212347 fun decryptTxMetadata (txMetadataDocument : TxMetadataDocument , keyParameter : KeyParameter ? ): List <TxMetadataItem > {
2348+ checkArgument(wallet!! .isEncrypted == (keyParameter != null ), " isEncrypted must match keyParameter" )
23222349 val cipher = KeyCrypterAESCBC ()
23232350 val encryptionKey = privateKeyAtPath(
23242351 txMetadataDocument.keyIndex,
0 commit comments