diff --git a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/aptos/TestAptosSigner.kt b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/aptos/TestAptosSigner.kt index e536821658b..b0a0a285182 100644 --- a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/aptos/TestAptosSigner.kt +++ b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/aptos/TestAptosSigner.kt @@ -69,6 +69,59 @@ class TestAptosSigner { ) } + @Test + fun AptosTransactionBlindSigningWithABI() { + // Successfully broadcasted: https://explorer.aptoslabs.com/txn/0x4eb6a65b1453e3f224d92b07aa8bf51eaa8b3f5bb5172cf28ebe62b527ae1010/payload?network=mainnet + val key = + "5d996aa76b3212142792d9130796cd2e11e3c445a93118c08414df4f66bc60ec".toHexBytesInByteString() + + val payloadJson = """ + { + "function": "0x9770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da3::controller::deposit", + "type_arguments": [ + "0x1::aptos_coin::AptosCoin" + ], + "arguments": [ + "0x4d61696e204163636f756e74", + "10000000", + false + ], + "type": "entry_function_payload" + } + """.trimIndent() + val signingInput = Aptos.SigningInput.newBuilder() + .setChainId(1) + .setExpirationTimestampSecs(3664390082) + .setGasUnitPrice(100) + .setMaxGasAmount(100011) + .setSender("0x07968dab936c1bad187c60ce4082f307d030d780e91e694ae03aef16aba73f30") + .setSequenceNumber(66) + .setAnyEncoded(payloadJson) + .setPrivateKey(key) + .setAbi(""" + [ + "vector", + "u64", + "bool" + ] + """.trimIndent()) + .build() + + val result = AnySigner.sign(signingInput, CoinType.APTOS, Aptos.SigningOutput.parser()) + assertEquals( + Numeric.cleanHexPrefix(Numeric.toHexString(result.rawTxn.toByteArray())), + "07968dab936c1bad187c60ce4082f307d030d780e91e694ae03aef16aba73f304200000000000000029770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da30a636f6e74726f6c6c6572076465706f736974010700000000000000000000000000000000000000000000000000000000000000010a6170746f735f636f696e094170746f73436f696e00030d0c4d61696e204163636f756e740880969800000000000100ab860100000000006400000000000000c2276ada0000000001" + ) + assertEquals( + Numeric.cleanHexPrefix(Numeric.toHexString(result.authenticator.signature.toByteArray())), + "9f9a5a075b643ed7f2f8c6afb492dc384ad0b9600645ece7394e0060b14d440c9103bd00cc50f22c473c21ff3a7f0475d8600b19c83184b71722f0d3f8472903" + ) + assertEquals( + Numeric.cleanHexPrefix(Numeric.toHexString(result.encoded.toByteArray())), + "07968dab936c1bad187c60ce4082f307d030d780e91e694ae03aef16aba73f304200000000000000029770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da30a636f6e74726f6c6c6572076465706f736974010700000000000000000000000000000000000000000000000000000000000000010a6170746f735f636f696e094170746f73436f696e00030d0c4d61696e204163636f756e740880969800000000000100ab860100000000006400000000000000c2276ada00000000010020ea526ba1710343d953461ff68641f1b7df5f23b9042ffa2d2a798d3adb3f3d6c409f9a5a075b643ed7f2f8c6afb492dc384ad0b9600645ece7394e0060b14d440c9103bd00cc50f22c473c21ff3a7f0475d8600b19c83184b71722f0d3f8472903" + ) + } + @Test fun AptosTransactionSigning() { // Successfully broadcasted https://explorer.aptoslabs.com/txn/0xb4d62afd3862116e060dd6ad9848ccb50c2bc177799819f1d29c059ae2042467?network=devnet diff --git a/swift/Tests/Blockchains/AptosTests.swift b/swift/Tests/Blockchains/AptosTests.swift index 335b02aad87..c3974349295 100644 --- a/swift/Tests/Blockchains/AptosTests.swift +++ b/swift/Tests/Blockchains/AptosTests.swift @@ -53,6 +53,49 @@ class AptosTests: XCTestCase { XCTAssertEqual(output.authenticator.signature.hexString, expectedSignature) XCTAssertEqual(output.encoded.hexString, expectedSignedTx) } + + func testBlindSignWithABI() { + // Successfully broadcasted: https://explorer.aptoslabs.com/txn/0x4eb6a65b1453e3f224d92b07aa8bf51eaa8b3f5bb5172cf28ebe62b527ae1010/payload?network=mainnet + let payloadJson = """ + { + "function": "0x9770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da3::controller::deposit", + "type_arguments": [ + "0x1::aptos_coin::AptosCoin" + ], + "arguments": [ + "0x4d61696e204163636f756e74", + "10000000", + false + ], + "type": "entry_function_payload" + } + """ + let privateKeyData = Data(hexString: "5d996aa76b3212142792d9130796cd2e11e3c445a93118c08414df4f66bc60ec")! + let input = AptosSigningInput.with { + $0.chainID = 1 + $0.anyEncoded = payloadJson + $0.expirationTimestampSecs = 3664390082 + $0.gasUnitPrice = 100 + $0.maxGasAmount = 100011 + $0.sequenceNumber = 66 + $0.sender = "0x07968dab936c1bad187c60ce4082f307d030d780e91e694ae03aef16aba73f30" + $0.privateKey = privateKeyData + $0.abi = """ + [ + "vector", + "u64", + "bool" + ] + """ + } + let output: AptosSigningOutput = AnySigner.sign(input: input, coin: .aptos) + let expectedRawTx = "07968dab936c1bad187c60ce4082f307d030d780e91e694ae03aef16aba73f304200000000000000029770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da30a636f6e74726f6c6c6572076465706f736974010700000000000000000000000000000000000000000000000000000000000000010a6170746f735f636f696e094170746f73436f696e00030d0c4d61696e204163636f756e740880969800000000000100ab860100000000006400000000000000c2276ada0000000001" + let expectedSignature = "9f9a5a075b643ed7f2f8c6afb492dc384ad0b9600645ece7394e0060b14d440c9103bd00cc50f22c473c21ff3a7f0475d8600b19c83184b71722f0d3f8472903" + let expectedSignedTx = "07968dab936c1bad187c60ce4082f307d030d780e91e694ae03aef16aba73f304200000000000000029770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da30a636f6e74726f6c6c6572076465706f736974010700000000000000000000000000000000000000000000000000000000000000010a6170746f735f636f696e094170746f73436f696e00030d0c4d61696e204163636f756e740880969800000000000100ab860100000000006400000000000000c2276ada00000000010020ea526ba1710343d953461ff68641f1b7df5f23b9042ffa2d2a798d3adb3f3d6c409f9a5a075b643ed7f2f8c6afb492dc384ad0b9600645ece7394e0060b14d440c9103bd00cc50f22c473c21ff3a7f0475d8600b19c83184b71722f0d3f8472903" + XCTAssertEqual(output.rawTxn.hexString, expectedRawTx) + XCTAssertEqual(output.authenticator.signature.hexString, expectedSignature) + XCTAssertEqual(output.encoded.hexString, expectedSignedTx) + } func testSign() { // Successfully broadcasted https://explorer.aptoslabs.com/txn/0xb4d62afd3862116e060dd6ad9848ccb50c2bc177799819f1d29c059ae2042467?network=devnet diff --git a/tests/chains/Aptos/TWAnySignerTests.cpp b/tests/chains/Aptos/TWAnySignerTests.cpp index dce9c2f3d72..9eb3d629993 100644 --- a/tests/chains/Aptos/TWAnySignerTests.cpp +++ b/tests/chains/Aptos/TWAnySignerTests.cpp @@ -57,4 +57,41 @@ TEST(TWAnySignerAptos, TxSign) { assertJSONEqual(expectedJson, parsedJson); } +TEST(TWAnySignerAptos, TxSignWithABI) { + // Successfully broadcasted https://explorer.aptoslabs.com/txn/0x4eb6a65b1453e3f224d92b07aa8bf51eaa8b3f5bb5172cf28ebe62b527ae1010/payload?network=mainnet + Proto::SigningInput input; + input.set_sender("0x07968dab936c1bad187c60ce4082f307d030d780e91e694ae03aef16aba73f30"); + input.set_sequence_number(66); + input.set_max_gas_amount(100011); + input.set_gas_unit_price(100); + input.set_expiration_timestamp_secs(3664390082); + input.set_chain_id(1); + input.set_any_encoded(R"( + { + "function": "0x9770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da3::controller::deposit", + "type_arguments": [ + "0x1::aptos_coin::AptosCoin" + ], + "arguments": [ + "0x4d61696e204163636f756e74", + "10000000", + false + ], + "type": "entry_function_payload" + } + )"); + input.set_abi(R"([ + "vector", + "u64", + "bool" + ])"); + auto privateKey = PrivateKey(parse_hex("5d996aa76b3212142792d9130796cd2e11e3c445a93118c08414df4f66bc60ec")); + input.set_private_key(privateKey.bytes.data(), privateKey.bytes.size()); + Proto::SigningOutput output; + ANY_SIGN(input, TWCoinTypeAptos); + ASSERT_EQ(hex(output.raw_txn()), "07968dab936c1bad187c60ce4082f307d030d780e91e694ae03aef16aba73f304200000000000000029770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da30a636f6e74726f6c6c6572076465706f736974010700000000000000000000000000000000000000000000000000000000000000010a6170746f735f636f696e094170746f73436f696e00030d0c4d61696e204163636f756e740880969800000000000100ab860100000000006400000000000000c2276ada0000000001"); + ASSERT_EQ(hex(output.authenticator().signature()), "9f9a5a075b643ed7f2f8c6afb492dc384ad0b9600645ece7394e0060b14d440c9103bd00cc50f22c473c21ff3a7f0475d8600b19c83184b71722f0d3f8472903"); + ASSERT_EQ(hex(output.encoded()), "07968dab936c1bad187c60ce4082f307d030d780e91e694ae03aef16aba73f304200000000000000029770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da30a636f6e74726f6c6c6572076465706f736974010700000000000000000000000000000000000000000000000000000000000000010a6170746f735f636f696e094170746f73436f696e00030d0c4d61696e204163636f756e740880969800000000000100ab860100000000006400000000000000c2276ada00000000010020ea526ba1710343d953461ff68641f1b7df5f23b9042ffa2d2a798d3adb3f3d6c409f9a5a075b643ed7f2f8c6afb492dc384ad0b9600645ece7394e0060b14d440c9103bd00cc50f22c473c21ff3a7f0475d8600b19c83184b71722f0d3f8472903"); +} + } // namespace TW::Aptos::tests