Skip to content

Commit 29fcaf7

Browse files
committed
Update to 2.6.5
1 parent d0ef894 commit 29fcaf7

29 files changed

+361
-79
lines changed

TrustWalletCore.xcodeproj/project.pbxproj

Lines changed: 24 additions & 0 deletions
Large diffs are not rendered by default.

wallet-core/build/ios/libCore.a

-114 KB
Binary file not shown.
47 KB
Binary file not shown.

wallet-core/build/ios/libprotobuf.a

6.05 KB
Binary file not shown.

wallet-core/include/TrustWalletCore/TWAnySigner.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ extern TWString *_Nonnull TWAnySignerSignJSON(TWString *_Nonnull json, TWData *_
2323

2424
extern bool TWAnySignerSupportsJSON(enum TWCoinType coin);
2525

26-
/// Encodes serialized SigningInput data to raw platform/coin specific bytes
27-
/// Example: EthereumSigningInput will be encoded as raw RLP bytes which can be sent over JSONRPC (eth_sendRawTransaction)
28-
extern TWData *_Nonnull TWAnySignerEncode(TWData *_Nonnull input, enum TWCoinType coin);
29-
30-
/// Decodes raw platform/coin specific bytes to representable json data
31-
/// Example: Ethereum RLP bytes will be decoded into same json returned from JSONRPC (eth_getTransactionByHash)
32-
extern TWData *_Nonnull TWAnySignerDecode(TWData *_Nonnull input, enum TWCoinType coin);
33-
3426
/// Plan a transaction (for UTXO chains).
3527
extern TWData *_Nonnull TWAnySignerPlan(TWData *_Nonnull input, enum TWCoinType coin);
3628

wallet-core/include/TrustWalletCore/TWBlockchain.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ TW_EXPORT_ENUM(uint32_t)
1414
enum TWBlockchain {
1515
TWBlockchainBitcoin = 0,
1616
TWBlockchainEthereum = 1,
17-
TWBlockchainWanchain = 2,
1817
TWBlockchainVechain = 3,
1918
TWBlockchainTron = 4,
2019
TWBlockchainIcon = 5,

wallet-core/include/TrustWalletCore/TWCoinType.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ enum TWCoinType {
8585
TWCoinTypeSmartChainLegacy = 10000714,
8686
TWCoinTypeSmartChain = 20000714,
8787
TWCoinTypeOasis = 474,
88+
TWCoinTypePolygon = 966,
8889
};
8990

9091
/// Returns the blockchain for a coin type.
@@ -109,21 +110,21 @@ enum TWHDVersion TWCoinTypeXprvVersion(enum TWCoinType coin);
109110

110111
/// Validates an address string.
111112
TW_EXPORT_METHOD
112-
bool TWCoinTypeValidate(enum TWCoinType coin, TWString *_Nonnull address);
113+
bool TWCoinTypeValidate(enum TWCoinType coin, TWString* _Nonnull address);
113114

114115
/// Returns the default derivation path for a particular coin.
115116
TW_EXPORT_METHOD
116-
TWString *_Nonnull TWCoinTypeDerivationPath(enum TWCoinType coin);
117+
TWString* _Nonnull TWCoinTypeDerivationPath(enum TWCoinType coin);
117118

118119
/// Derives the address for a particular coin from the private key.
119120
TW_EXPORT_METHOD
120-
TWString *_Nonnull TWCoinTypeDeriveAddress(enum TWCoinType coin,
121-
struct TWPrivateKey *_Nonnull privateKey);
121+
TWString* _Nonnull TWCoinTypeDeriveAddress(enum TWCoinType coin,
122+
struct TWPrivateKey* _Nonnull privateKey);
122123

123124
/// Derives the address for a particular coin from the public key.
124125
TW_EXPORT_METHOD
125-
TWString *_Nonnull TWCoinTypeDeriveAddressFromPublicKey(enum TWCoinType coin,
126-
struct TWPublicKey *_Nonnull publicKey);
126+
TWString* _Nonnull TWCoinTypeDeriveAddressFromPublicKey(enum TWCoinType coin,
127+
struct TWPublicKey* _Nonnull publicKey);
127128

128129
/// HRP for this coin type
129130
TW_EXPORT_PROPERTY
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright © 2017-2020 Trust Wallet.
2+
//
3+
// This file is part of Trust. The full Trust copyright notice, including
4+
// terms governing use, modification, and redistribution, is contained in the
5+
// file LICENSE at the root of the source code distribution tree.
6+
//
7+
// This is a GENERATED FILE, changes made here WILL BE LOST.
8+
9+
#pragma once
10+
11+
#include "TWData.h"
12+

wallet-core/include/TrustWalletCore/TWEthereumChainID.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ enum TWEthereumChainID {
2222
TWEthereumChainIDThunderToken = 108,
2323
TWEthereumChainIDTomoChain = 88,
2424
TWEthereumChainIDBinanceSmartChain = 56,
25+
TWEthereumChainIDMatic = 137,
26+
TWEthereumChainIDWanchain = 888,
2527
};
2628

2729
TW_EXTERN_C_END

wallet-core/include/TrustWalletCore/TWHDWallet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2017-2020 Trust Wallet.
1+
// Copyright © 2017-2021 Trust Wallet.
22
//
33
// This file is part of Trust. The full Trust copyright notice, including
44
// terms governing use, modification, and redistribution, is contained in the
@@ -21,7 +21,7 @@ TW_EXTERN_C_BEGIN
2121
TW_EXPORT_CLASS
2222
struct TWHDWallet;
2323

24-
/// Determines if a mnemonic phrase is valid.
24+
/// Deprecated; use TWMnemonicIsValid(). Determines if a mnemonic phrase is valid.
2525
TW_EXPORT_STATIC_METHOD
2626
bool TWHDWalletIsValid(TWString *_Nonnull mnemonic);
2727

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright © 2017-2021 Trust Wallet.
2+
//
3+
// This file is part of Trust. The full Trust copyright notice, including
4+
// terms governing use, modification, and redistribution, is contained in the
5+
// file LICENSE at the root of the source code distribution tree.
6+
7+
#pragma once
8+
9+
#include "TWBase.h"
10+
#include "TWString.h"
11+
12+
TW_EXTERN_C_BEGIN
13+
14+
TW_EXPORT_CLASS
15+
struct TWMnemonic;
16+
17+
/// Determines whether a mnemonic phrase is valid.
18+
TW_EXPORT_STATIC_METHOD
19+
bool TWMnemonicIsValid(TWString *_Nonnull mnemonic);
20+
21+
/// Determines whether word is a valid menemonic word.
22+
TW_EXPORT_STATIC_METHOD
23+
bool TWMnemonicIsValidWord(TWString *_Nonnull word);
24+
25+
/// Return BIP39 English words that match the given prefix. A single string is returned, with space-separated list of words.
26+
TW_EXPORT_STATIC_METHOD
27+
TWString* _Nonnull TWMnemonicSuggest(TWString *_Nonnull prefix);
28+
29+
TW_EXTERN_C_END

wallet-core/include/TrustWalletCore/TWPrivateKey.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ struct TWPublicKey *_Nonnull TWPrivateKeyGetPublicKeyEd25519Extended(struct TWPr
6060
TW_EXPORT_METHOD
6161
struct TWPublicKey *_Nonnull TWPrivateKeyGetPublicKeyCurve25519(struct TWPrivateKey *_Nonnull pk);
6262

63+
/// Computes an EC Diffie-Hellman secret in constant time
64+
/// Supported curves: secp256k1
65+
TW_EXPORT_METHOD
66+
TWData *_Nullable TWPrivateKeyGetSharedKey(const struct TWPrivateKey *_Nonnull pk, const struct TWPublicKey *_Nonnull publicKey, enum TWCurve curve);
67+
6368
/// Signs a digest using ECDSA and given curve.
6469
TW_EXPORT_METHOD
6570
TWData *_Nullable TWPrivateKeySign(struct TWPrivateKey *_Nonnull pk, TWData *_Nonnull digest, enum TWCurve curve);

wallet-core/include/TrustWalletCore/TWString.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ size_t TWStringSize(TWString *_Nonnull string);
3434
/// Returns the byte at the provided index.
3535
char TWStringGet(TWString *_Nonnull string, size_t index);
3636

37-
/// Returns the raw pointer to the string's UTF8 bytes.
37+
/// Returns the raw pointer to the string's UTF8 bytes (null-terminated).
3838
const char *_Nonnull TWStringUTF8Bytes(TWString *_Nonnull string);
3939

4040
/// Deletes a string created with a `TWStringCreate*` method. After delete it must not be used (can segfault)!

wallet-core/swift/Sources/AnySigner.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,6 @@ public final class AnySigner {
4141
return TWStringNSString(TWAnySignerSignJSON(jsonString, keyData, TWCoinType(rawValue: coin.rawValue)))
4242
}
4343

44-
public static func encode(input: SigningInput, coin: CoinType) -> Data {
45-
do {
46-
return nativeEncode(data: try input.serializedData(), coin: coin)
47-
} catch let error {
48-
fatalError(error.localizedDescription)
49-
}
50-
}
51-
52-
public static func nativeEncode(data: Data, coin: CoinType) -> Data {
53-
let inputData = TWDataCreateWithNSData(data)
54-
defer {
55-
TWDataDelete(inputData)
56-
}
57-
return TWDataNSData(TWAnySignerEncode(inputData, TWCoinType(rawValue: coin.rawValue)))
58-
}
59-
60-
public static func decode(data: Data, coin: CoinType) -> Data {
61-
let inputData = TWDataCreateWithNSData(data)
62-
defer {
63-
TWDataDelete(inputData)
64-
}
65-
return TWDataNSData(TWAnySignerDecode(inputData, TWCoinType(rawValue: coin.rawValue)))
66-
}
67-
6844
public static func plan<TransactionPlan: Message>(input: SigningInput, coin: CoinType) -> TransactionPlan {
6945
do {
7046
let outputData = nativePlan(data: try input.serializedData(), coin: coin)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright © 2017-2021 Trust Wallet.
2+
//
3+
// This file is part of Trust. The full Trust copyright notice, including
4+
// terms governing use, modification, and redistribution, is contained in the
5+
// file LICENSE at the root of the source code distribution tree.
6+
7+
import Foundation
8+
9+
public extension Mnemonic {
10+
typealias ValidationResult = (word: String, index: Int)
11+
12+
/// Returns mnemonic validation result, an array of wrong word and index tuple
13+
static func validate(mnemonic: [String]) -> [ValidationResult] {
14+
mnemonic.enumerated().compactMap { (index, word) -> ValidationResult? in
15+
if isValidWord(word: word) {
16+
return nil
17+
}
18+
return (word, index)
19+
}
20+
}
21+
22+
/// Returns matched suggestion in a native array
23+
static func search(prefix: String) -> [String] {
24+
return suggest(prefix: prefix).split(separator: " ").map { String($0) }
25+
}
26+
}

wallet-core/swift/Sources/Generated/Enums/Blockchain.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
public enum Blockchain: UInt32, CaseIterable {
1111
case bitcoin = 0
1212
case ethereum = 1
13-
case wanchain = 2
1413
case vechain = 3
1514
case tron = 4
1615
case icon = 5

wallet-core/swift/Sources/Generated/Enums/CoinType.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,5 @@ public enum CoinType: UInt32, CaseIterable {
7171
case smartChainLegacy = 10000714
7272
case smartChain = 20000714
7373
case oasis = 474
74+
case polygon = 966
7475
}

wallet-core/swift/Sources/Generated/Enums/EthereumChainID.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ public enum EthereumChainID: UInt32, CaseIterable {
1717
case thunderToken = 108
1818
case tomoChain = 88
1919
case binanceSmartChain = 56
20+
case matic = 137
21+
case wanchain = 888
2022
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright © 2017-2020 Trust Wallet.
2+
//
3+
// This file is part of Trust. The full Trust copyright notice, including
4+
// terms governing use, modification, and redistribution, is contained in the
5+
// file LICENSE at the root of the source code distribution tree.
6+
//
7+
// This is a GENERATED FILE, changes made here WILL BE LOST.
8+
//
9+
10+
import Foundation
11+
12+
public final class Mnemonic {
13+
14+
public static func isValid(mnemonic: String) -> Bool {
15+
let mnemonicString = TWStringCreateWithNSString(mnemonic)
16+
defer {
17+
TWStringDelete(mnemonicString)
18+
}
19+
return TWMnemonicIsValid(mnemonicString)
20+
}
21+
22+
public static func isValidWord(word: String) -> Bool {
23+
let wordString = TWStringCreateWithNSString(word)
24+
defer {
25+
TWStringDelete(wordString)
26+
}
27+
return TWMnemonicIsValidWord(wordString)
28+
}
29+
30+
public static func suggest(prefix: String) -> String {
31+
let prefixString = TWStringCreateWithNSString(prefix)
32+
defer {
33+
TWStringDelete(prefixString)
34+
}
35+
return TWStringNSString(TWMnemonicSuggest(prefixString))
36+
}
37+
38+
let rawValue: OpaquePointer
39+
40+
init(rawValue: OpaquePointer) {
41+
self.rawValue = rawValue
42+
}
43+
44+
45+
}

wallet-core/swift/Sources/Generated/PrivateKey.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ public final class PrivateKey {
7979
return PublicKey(rawValue: TWPrivateKeyGetPublicKeyCurve25519(rawValue))
8080
}
8181

82+
public func getSharedKey(publicKey: PublicKey, curve: Curve) -> Data? {
83+
guard let result = TWPrivateKeyGetSharedKey(rawValue, publicKey.rawValue, TWCurve(rawValue: curve.rawValue)) else {
84+
return nil
85+
}
86+
return TWDataNSData(result)
87+
}
88+
8289
public func sign(digest: Data, curve: Curve) -> Data? {
8390
let digestData = TWDataCreateWithNSData(digest)
8491
defer {

wallet-core/swift/Sources/Generated/Protobuf/Bitcoin.pb.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ public struct TW_Bitcoin_Proto_TransactionPlan {
246246
/// Zcash branch id
247247
public var branchID: Data = Data()
248248

249-
/// Optional error message
250-
public var error: String = String()
249+
/// Optional error
250+
public var error: TW_Common_Proto_SigningError = .ok
251251

252252
public var unknownFields = SwiftProtobuf.UnknownStorage()
253253

@@ -276,8 +276,8 @@ public struct TW_Bitcoin_Proto_SigningOutput {
276276
/// Transaction id
277277
public var transactionID: String = String()
278278

279-
/// Optional error message
280-
public var error: String = String()
279+
/// Optional error
280+
public var error: TW_Common_Proto_SigningError = .ok
281281

282282
public var unknownFields = SwiftProtobuf.UnknownStorage()
283283

@@ -678,7 +678,7 @@ extension TW_Bitcoin_Proto_TransactionPlan: SwiftProtobuf.Message, SwiftProtobuf
678678
case 4: try { try decoder.decodeSingularInt64Field(value: &self.change) }()
679679
case 5: try { try decoder.decodeRepeatedMessageField(value: &self.utxos) }()
680680
case 6: try { try decoder.decodeSingularBytesField(value: &self.branchID) }()
681-
case 7: try { try decoder.decodeSingularStringField(value: &self.error) }()
681+
case 7: try { try decoder.decodeSingularEnumField(value: &self.error) }()
682682
default: break
683683
}
684684
}
@@ -703,8 +703,8 @@ extension TW_Bitcoin_Proto_TransactionPlan: SwiftProtobuf.Message, SwiftProtobuf
703703
if !self.branchID.isEmpty {
704704
try visitor.visitSingularBytesField(value: self.branchID, fieldNumber: 6)
705705
}
706-
if !self.error.isEmpty {
707-
try visitor.visitSingularStringField(value: self.error, fieldNumber: 7)
706+
if self.error != .ok {
707+
try visitor.visitSingularEnumField(value: self.error, fieldNumber: 7)
708708
}
709709
try unknownFields.traverse(visitor: &visitor)
710710
}
@@ -740,7 +740,7 @@ extension TW_Bitcoin_Proto_SigningOutput: SwiftProtobuf.Message, SwiftProtobuf._
740740
case 1: try { try decoder.decodeSingularMessageField(value: &self._transaction) }()
741741
case 2: try { try decoder.decodeSingularBytesField(value: &self.encoded) }()
742742
case 3: try { try decoder.decodeSingularStringField(value: &self.transactionID) }()
743-
case 4: try { try decoder.decodeSingularStringField(value: &self.error) }()
743+
case 4: try { try decoder.decodeSingularEnumField(value: &self.error) }()
744744
default: break
745745
}
746746
}
@@ -756,8 +756,8 @@ extension TW_Bitcoin_Proto_SigningOutput: SwiftProtobuf.Message, SwiftProtobuf._
756756
if !self.transactionID.isEmpty {
757757
try visitor.visitSingularStringField(value: self.transactionID, fieldNumber: 3)
758758
}
759-
if !self.error.isEmpty {
760-
try visitor.visitSingularStringField(value: self.error, fieldNumber: 4)
759+
if self.error != .ok {
760+
try visitor.visitSingularEnumField(value: self.error, fieldNumber: 4)
761761
}
762762
try unknownFields.traverse(visitor: &visitor)
763763
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright © 2017-2020 Trust Wallet.
2+
//
3+
// This file is part of Trust. The full Trust copyright notice, including
4+
// terms governing use, modification, and redistribution, is contained in the
5+
// file LICENSE at the root of the source code distribution tree.
6+

0 commit comments

Comments
 (0)