@@ -97,6 +97,48 @@ TEST(TWStoredKey, importPrivateKeyAes256) {
97
97
TWPrivateKeyDelete (privateKey3);
98
98
}
99
99
100
+ TEST (TWStoredKey, importPrivateKeyAes256Legacy) {
101
+ const auto privateKeyHex = " 28071bf4e2b0340db41b807ed8a5514139e5d6427ff9d58dbd22b7ed187103a4" ;
102
+ const auto privateKey = WRAPD (TWDataCreateWithHexString (WRAPS (TWStringCreateWithUTF8Bytes (privateKeyHex)).get ()));
103
+ const auto name = WRAPS (TWStringCreateWithUTF8Bytes (" name" ));
104
+ const auto passwordString = WRAPS (TWStringCreateWithUTF8Bytes (" password" ));
105
+ const auto password = WRAPD (TWDataCreateWithBytes (reinterpret_cast <const uint8_t *>(TWStringUTF8Bytes (passwordString.get ())), TWStringSize (passwordString.get ())));
106
+ const auto coin = TWCoinTypeBitcoin;
107
+ const auto key = WRAP (TWStoredKey, TWStoredKeyImportPrivateKeyWithEncryptionAndDerivation (privateKey.get (), name.get (), password.get (), coin, TWStoredKeyEncryptionAes256Ctr, TWDerivationBitcoinLegacy));
108
+ const auto privateKey2 = WRAPD (TWStoredKeyDecryptPrivateKey (key.get (), password.get ()));
109
+ EXPECT_EQ (hex (data (TWDataBytes (privateKey2.get ()), TWDataSize (privateKey2.get ()))), privateKeyHex);
110
+
111
+ const auto privateKey3 = TWStoredKeyPrivateKey (key.get (), coin, password.get ());
112
+ const auto pkData3 = WRAPD (TWPrivateKeyData (privateKey3));
113
+ EXPECT_EQ (hex (data (TWDataBytes (pkData3.get ()), TWDataSize (pkData3.get ()))), privateKeyHex);
114
+ TWPrivateKeyDelete (privateKey3);
115
+
116
+ const auto accountCoin = WRAP (TWAccount, TWStoredKeyAccount (key.get (),0 ));
117
+ const auto accountAddress = WRAPS (TWAccountAddress (accountCoin.get ()));
118
+ EXPECT_EQ (string (TWStringUTF8Bytes (accountAddress.get ())), " 1PeUvjuxyf31aJKX6kCXuaqxhmG78ZUdL1" );
119
+ }
120
+
121
+ TEST (TWStoredKey, importPrivateKeyAes256Taproot) {
122
+ const auto privateKeyHex = " 28071bf4e2b0340db41b807ed8a5514139e5d6427ff9d58dbd22b7ed187103a4" ;
123
+ const auto privateKey = WRAPD (TWDataCreateWithHexString (WRAPS (TWStringCreateWithUTF8Bytes (privateKeyHex)).get ()));
124
+ const auto name = WRAPS (TWStringCreateWithUTF8Bytes (" name" ));
125
+ const auto passwordString = WRAPS (TWStringCreateWithUTF8Bytes (" password" ));
126
+ const auto password = WRAPD (TWDataCreateWithBytes (reinterpret_cast <const uint8_t *>(TWStringUTF8Bytes (passwordString.get ())), TWStringSize (passwordString.get ())));
127
+ const auto coin = TWCoinTypeBitcoin;
128
+ const auto key = WRAP (TWStoredKey, TWStoredKeyImportPrivateKeyWithEncryptionAndDerivation (privateKey.get (), name.get (), password.get (), coin, TWStoredKeyEncryptionAes256Ctr, TWDerivationBitcoinSegwit));
129
+ const auto privateKey2 = WRAPD (TWStoredKeyDecryptPrivateKey (key.get (), password.get ()));
130
+ EXPECT_EQ (hex (data (TWDataBytes (privateKey2.get ()), TWDataSize (privateKey2.get ()))), privateKeyHex);
131
+
132
+ const auto privateKey3 = TWStoredKeyPrivateKey (key.get (), coin, password.get ());
133
+ const auto pkData3 = WRAPD (TWPrivateKeyData (privateKey3));
134
+ EXPECT_EQ (hex (data (TWDataBytes (pkData3.get ()), TWDataSize (pkData3.get ()))), privateKeyHex);
135
+ TWPrivateKeyDelete (privateKey3);
136
+
137
+ const auto accountCoin = WRAP (TWAccount, TWStoredKeyAccount (key.get (),0 ));
138
+ const auto accountAddress = WRAPS (TWAccountAddress (accountCoin.get ()));
139
+ EXPECT_EQ (string (TWStringUTF8Bytes (accountAddress.get ())), " bc1qlp5hssx3qstf3m0mt7fd6tzlh90ssm32u2llf4" );
140
+ }
141
+
100
142
TEST (TWStoredKey, importPrivateKeyHexButDecryptEncoded) {
101
143
const auto privateKeyHex = " 3a1076bf45ab87712ad64ccb3b10217737f7faacbf2872e88fdd9a537d8fe266" ;
102
144
const auto privateKey = WRAPD (TWDataCreateWithHexString (WRAPS (TWStringCreateWithUTF8Bytes (privateKeyHex)).get ()));
@@ -137,6 +179,30 @@ TEST(TWStoredKey, importPrivateKeyEncodedHex) {
137
179
TWPrivateKeyDelete (privateKey3);
138
180
}
139
181
182
+ TEST (TWStoredKey, importPrivateKeyEncodedHexLegacy) {
183
+ const auto privateKeyHex = " 28071bf4e2b0340db41b807ed8a5514139e5d6427ff9d58dbd22b7ed187103a4" ;
184
+ const auto privateKey = WRAPS (TWStringCreateWithUTF8Bytes (privateKeyHex));
185
+ const auto name = WRAPS (TWStringCreateWithUTF8Bytes (" name" ));
186
+ const auto passwordString = WRAPS (TWStringCreateWithUTF8Bytes (" password" ));
187
+ const auto password = WRAPD (TWDataCreateWithBytes (reinterpret_cast <const uint8_t *>(TWStringUTF8Bytes (passwordString.get ())), TWStringSize (passwordString.get ())));
188
+ const auto coin = TWCoinTypeBitcoin;
189
+ const auto key = WRAP (TWStoredKey, TWStoredKeyImportPrivateKeyEncodedWithEncryptionAndDerivation (privateKey.get (), name.get (), password.get (), coin, TWStoredKeyEncryptionAes128Ctr, TWDerivationBitcoinLegacy));
190
+ const auto privateKey2 = WRAPD (TWStoredKeyDecryptPrivateKey (key.get (), password.get ()));
191
+ EXPECT_EQ (hex (data (TWDataBytes (privateKey2.get ()), TWDataSize (privateKey2.get ()))), privateKeyHex);
192
+ EXPECT_TRUE (TWStoredKeyHasPrivateKeyEncoded (key.get ()));
193
+ const auto privateKey2Encoded = WRAPS (TWStoredKeyDecryptPrivateKeyEncoded (key.get (), password.get ()));
194
+ EXPECT_EQ (std::string (TWStringUTF8Bytes (privateKey2Encoded.get ())), privateKeyHex);
195
+
196
+ const auto privateKey3 = TWStoredKeyPrivateKey (key.get (), coin, password.get ());
197
+ const auto pkData3 = WRAPD (TWPrivateKeyData (privateKey3));
198
+ EXPECT_EQ (hex (data (TWDataBytes (pkData3.get ()), TWDataSize (pkData3.get ()))), privateKeyHex);
199
+ TWPrivateKeyDelete (privateKey3);
200
+
201
+ const auto accountCoin = WRAP (TWAccount, TWStoredKeyAccount (key.get (),0 ));
202
+ const auto accountAddress = WRAPS (TWAccountAddress (accountCoin.get ()));
203
+ EXPECT_EQ (string (TWStringUTF8Bytes (accountAddress.get ())), " 1PeUvjuxyf31aJKX6kCXuaqxhmG78ZUdL1" );
204
+ }
205
+
140
206
TEST (TWStoredKey, importPrivateKeyEncodedStellar) {
141
207
const auto privateKeyEncoded = " SAV76USXIJOBMEQXPANUOQM6F5LIOTLPDIDVRJBFFE2MDJXG24TAPUU7" ;
142
208
const auto decodedPrivateKeyHex = " 2bff5257425c161217781b47419e2f56874d6f1a0758a4252934c1a6e6d72607" ;
0 commit comments