Skip to content

Commit

Permalink
Update from tangem/wallet-core@63e861e (4.1.20-tangem2)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangem committed Dec 6, 2024
1 parent 954aa90 commit 1592391
Show file tree
Hide file tree
Showing 65 changed files with 240,371 additions and 256,858 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ struct TWAnySigner;
/// \return The serialized data of a `SigningOutput` proto object. (e.g. TW.Bitcoin.Proto.SigningOutput).
extern TWData *_Nonnull TWAnySignerSign(TWData *_Nonnull input, enum TWCoinType coin);

// TANGEM
extern TWData *_Nonnull TWAnySignerSignExternally(TWData *_Nonnull input, enum TWCoinType coin, TWData *_Nonnull publicKey, TWData *_Nonnull (*_Nonnull externalSigner)(TWData *_Nonnull));

/// Signs a transaction specified by the JSON representation of signing input, coin type and a private key, returning the JSON representation of the signing output.
///
/// \param json JSON representation of a signing input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ TWString *_Nonnull TWBase58EncodeNoCheck(TWData *_Nonnull data);
/// Decodes a Base58 string, checking the checksum. Returns null if the string is not a valid Base58 string.
///
/// \param string The Base58 string to decode.
/// \return the decoded data, empty if the string is not a valid Base58 string with checksum.
/// \return the decoded data, null if the string is not a valid Base58 string with checksum.
TW_EXPORT_STATIC_METHOD
TWData *_Nullable TWBase58Decode(TWString *_Nonnull string);

/// Decodes a Base58 string, w/o checking the checksum. Returns null if the string is not a valid Base58 string.
///
/// \param string The Base58 string to decode.
/// \return the decoded data, empty if the string is not a valid Base58 string without checksum.
/// \return the decoded data, null if the string is not a valid Base58 string without checksum.
TW_EXPORT_STATIC_METHOD
TWData *_Nullable TWBase58DecodeNoCheck(TWString *_Nonnull string);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.

#pragma once

#include "TWBase.h"
#include "TWData.h"
#include "TWString.h"

TW_EXTERN_C_BEGIN

/// Bech32 encode / decode functions
TW_EXPORT_STRUCT
struct TWBech32;

/// Encodes data as a Bech32 string.
///
/// \param hrp The human-readable part.
/// \param data The data part.
/// \return the encoded Bech32 string.
TW_EXPORT_STATIC_METHOD
TWString *_Nonnull TWBech32Encode(TWString* _Nonnull hrp, TWData *_Nonnull data);

/// Decodes a Bech32 string. Returns null if the string is not a valid Bech32 string.
///
/// \param string The Bech32 string to decode.
/// \return the decoded data, null if the string is not a valid Bech32 string. Note that the human-readable part is not returned.
TW_EXPORT_STATIC_METHOD
TWData *_Nullable TWBech32Decode(TWString *_Nonnull string);

/// Encodes data as a Bech32m string.
///
/// \param hrp The human-readable part.
/// \param data The data part.
/// \return the encoded Bech32m string.
TW_EXPORT_STATIC_METHOD
TWString *_Nonnull TWBech32EncodeM(TWString* _Nonnull hrp, TWData *_Nonnull data);

/// Decodes a Bech32m string. Returns null if the string is not a valid Bech32m string.
///
/// \param string The Bech32m string to decode.
/// \return the decoded data, null if the string is not a valid Bech32m string. Note that the human-readable part is not returned.
TW_EXPORT_STATIC_METHOD
TWData *_Nullable TWBech32DecodeM(TWString *_Nonnull string);

TW_EXTERN_C_END

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -191,26 +191,6 @@ struct TWBitcoinScript* _Nonnull TWBitcoinScriptBuildPayToWitnessPubkeyHash(TWDa
TW_EXPORT_STATIC_METHOD
struct TWBitcoinScript* _Nonnull TWBitcoinScriptBuildPayToWitnessScriptHash(TWData* _Nonnull scriptHash);

/// Builds the Ordinals inscripton for BRC20 transfer.
///
/// \param ticker ticker of the brc20
/// \param amount uint64 transfer amount
/// \param pubkey Non-null pointer to a pubkey
/// \note Must be deleted with \TWBitcoinScriptDelete
/// \return A pointer to the built script
TW_EXPORT_STATIC_METHOD
TWData* _Nonnull TWBitcoinScriptBuildBRC20InscribeTransfer(TWString* _Nonnull ticker, TWString* _Nonnull amount, TWData* _Nonnull pubkey);

/// Builds the Ordinals inscripton for NFT construction.
///
/// \param mimeType the MIME type of the payload
/// \param payload the payload to inscribe
/// \param pubkey Non-null pointer to a pubkey
/// \note Must be deleted with \TWBitcoinScriptDelete
/// \return A pointer to the built script
TW_EXPORT_STATIC_METHOD
TWData* _Nonnull TWBitcoinScriptBuildOrdinalNftInscription(TWString* _Nonnull mimeType, TWData* _Nonnull payload, TWData* _Nonnull pubkey);

/// Builds a appropriate lock script for the given address..
///
/// \param address Non-null pointer to an address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ enum TWBlockchain {
TWBlockchainInternetComputer = 52,
TWBlockchainNativeEvmos = 53, // Cosmos
TWBlockchainNativeInjective = 54, // Cosmos
TWBlockchainBitcoinCash = 55,
TWBlockchainPactus = 56,
};

TW_EXTERN_C_END
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ enum TWCoinType {
TWCoinTypeMoonriver = 10001285,
TWCoinTypeMoonbeam = 10001284,
TWCoinTypeKavaEvm = 10002222,
TWCoinTypeKlaytn = 10008217,
TWCoinTypeKaia = 10008217,
TWCoinTypeMeter = 18000,
TWCoinTypeOKXChain = 996,
TWCoinTypeStratis = 105105,
Expand Down Expand Up @@ -186,6 +186,7 @@ enum TWCoinType {
TWCoinTypeBlast = 81457,
TWCoinTypeBounceBit = 6001,
TWCoinTypeZkLinkNova = 810180,
TWCoinTypePactus = 21888,
// end_of_tw_coin_type_marker_do_not_modify
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.

#pragma once

#include "TWBase.h"
#include "TWCryptoBoxPublicKey.h"
#include "TWCryptoBoxSecretKey.h"
#include "TWData.h"
#include "TWString.h"

TW_EXTERN_C_BEGIN

/// `crypto_box` encryption algorithms.
TW_EXPORT_STRUCT
struct TWCryptoBox;

/// Encrypts message using `my_secret` and `other_pubkey`.
/// The output will have a randomly generated nonce prepended to it.
/// The output will be Overhead + 24 bytes longer than the original.
///
/// \param mySecret *non-null* pointer to my secret key.
/// \param otherPubkey *non-null* pointer to other's public key.
/// \param message *non-null* pointer to the message to be encrypted.
/// \return *nullable* pointer to the encrypted message with randomly generated nonce prepended to it.
TW_EXPORT_STATIC_METHOD
TWData* _Nonnull TWCryptoBoxEncryptEasy(struct TWCryptoBoxSecretKey* _Nonnull mySecret, struct TWCryptoBoxPublicKey* _Nonnull otherPubkey, TWData* _Nonnull message);

/// Decrypts box produced by `TWCryptoBoxEncryptEasy`.
/// We assume a 24-byte nonce is prepended to the encrypted text in box.
///
/// \param mySecret *non-null* pointer to my secret key.
/// \param otherPubkey *non-null* pointer to other's public key.
/// \param encrypted *non-null* pointer to the encrypted message with nonce prepended to it.
/// \return *nullable* pointer to the decrypted message.
TW_EXPORT_STATIC_METHOD
TWData* _Nullable TWCryptoBoxDecryptEasy(struct TWCryptoBoxSecretKey* _Nonnull mySecret, struct TWCryptoBoxPublicKey* _Nonnull otherPubkey, TWData* _Nonnull encrypted);

TW_EXTERN_C_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.

#pragma once

#include "TWBase.h"
#include "TWData.h"
#include "TWString.h"

TW_EXTERN_C_BEGIN

/// Public key used in `crypto_box` cryptography.
TW_EXPORT_CLASS
struct TWCryptoBoxPublicKey;

/// Determines if the given public key is valid or not.
///
/// \param data *non-null* byte array.
/// \return true if the public key is valid, false otherwise.
TW_EXPORT_STATIC_METHOD
bool TWCryptoBoxPublicKeyIsValid(TWData* _Nonnull data);

/// Create a `crypto_box` public key with the given block of data.
///
/// \param data *non-null* byte array. Expected to have 32 bytes.
/// \note Should be deleted with \tw_crypto_box_public_key_delete.
/// \return Nullable pointer to Public Key.
TW_EXPORT_STATIC_METHOD
struct TWCryptoBoxPublicKey* _Nullable TWCryptoBoxPublicKeyCreateWithData(TWData* _Nonnull data);

/// Delete the given public key.
///
/// \param publicKey *non-null* pointer to public key.
TW_EXPORT_METHOD
void TWCryptoBoxPublicKeyDelete(struct TWCryptoBoxPublicKey* _Nonnull publicKey);

/// Returns the raw data of the given public-key.
///
/// \param publicKey *non-null* pointer to a public key.
/// \return C-compatible result with a C-compatible byte array.
TW_EXPORT_PROPERTY
TWData* _Nonnull TWCryptoBoxPublicKeyData(struct TWCryptoBoxPublicKey* _Nonnull publicKey);

TW_EXTERN_C_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.

#pragma once

#include "TWBase.h"
#include "TWCryptoBoxPublicKey.h"
#include "TWData.h"
#include "TWString.h"

TW_EXTERN_C_BEGIN

/// Secret key used in `crypto_box` cryptography.
TW_EXPORT_CLASS
struct TWCryptoBoxSecretKey;

/// Determines if the given secret key is valid or not.
///
/// \param data *non-null* byte array.
/// \return true if the secret key is valid, false otherwise.
TW_EXPORT_STATIC_METHOD
bool TWCryptoBoxSecretKeyIsValid(TWData* _Nonnull data);

/// Create a random secret key.
///
/// \note Should be deleted with \tw_crypto_box_secret_key_delete.
/// \return *non-null* pointer to Secret Key.
TW_EXPORT_STATIC_METHOD
struct TWCryptoBoxSecretKey* _Nonnull TWCryptoBoxSecretKeyCreate();

/// Create a `crypto_box` secret key with the given block of data.
///
/// \param data *non-null* byte array. Expected to have 32 bytes.
/// \note Should be deleted with \tw_crypto_box_secret_key_delete.
/// \return Nullable pointer to Secret Key.
TW_EXPORT_STATIC_METHOD
struct TWCryptoBoxSecretKey* _Nullable TWCryptoBoxSecretKeyCreateWithData(TWData* _Nonnull data);

/// Delete the given secret `key`.
///
/// \param key *non-null* pointer to secret key.
TW_EXPORT_METHOD
void TWCryptoBoxSecretKeyDelete(struct TWCryptoBoxSecretKey* _Nonnull key);

/// Returns the public key associated with the given `key`.
///
/// \param key *non-null* pointer to the private key.
/// \return *non-null* pointer to the corresponding public key.
TW_EXPORT_METHOD
struct TWCryptoBoxPublicKey* _Nonnull TWCryptoBoxSecretKeyGetPublicKey(struct TWCryptoBoxSecretKey* _Nonnull key);

/// Returns the raw data of the given secret-key.
///
/// \param secretKey *non-null* pointer to a secret key.
/// \return C-compatible result with a C-compatible byte array.
TW_EXPORT_PROPERTY
TWData* _Nonnull TWCryptoBoxSecretKeyData(struct TWCryptoBoxSecretKey* _Nonnull secretKey);

TW_EXTERN_C_END
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
TW_EXTERN_C_BEGIN

/// Non-default coin address derivation names (default, unnamed derivations are not included).
/// Note the enum variant must be sync with `TWDerivation` enum in Rust:
/// https://github.com/trustwallet/wallet-core/blob/master/rust/tw_coin_registry/src/tw_derivation.rs
TW_EXPORT_ENUM()
enum TWDerivation {
TWDerivationDefault = 0, // default, for any coin
Expand All @@ -21,6 +23,9 @@ enum TWDerivation {
TWDerivationBitcoinTestnet = 4,
TWDerivationLitecoinLegacy = 5,
TWDerivationSolanaSolana = 6,
TWDerivationStratisSegwit = 7,
TWDerivationBitcoinTaproot = 8,
// end_of_derivation_enum - USED TO GENERATE CODE
};

TW_EXTERN_C_END
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ enum TWEthereumChainID {
TWEthereumChainIDRonin = 2020,
TWEthereumChainIDKavaevm = 2222,
TWEthereumChainIDIotexevm = 4689,
TWEthereumChainIDKlaytn = 8217,
TWEthereumChainIDKaia = 8217,
TWEthereumChainIDAvalanchec = 43114,
TWEthereumChainIDEvmos = 9001,
TWEthereumChainIDArbitrumnova = 42170,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ enum TWHRP {
TWHRPHarmony /* "one" */,
TWHRPCardano /* "addr" */,
TWHRPQtum /* "qc" */,
TWHRPPactus /* "pc" */,
TWHRPStratis /* "strax" */,
TWHRPNativeInjective /* "inj" */,
TWHRPOsmosis /* "osmo" */,
Expand Down Expand Up @@ -107,6 +108,7 @@ static const char *_Nonnull HRP_BITCOINDIAMOND = "bcd";
static const char *_Nonnull HRP_HARMONY = "one";
static const char *_Nonnull HRP_CARDANO = "addr";
static const char *_Nonnull HRP_QTUM = "qc";
static const char *_Nonnull HRP_PACTUS = "pc";
static const char *_Nonnull HRP_STRATIS = "strax";
static const char *_Nonnull HRP_NATIVEINJECTIVE = "inj";
static const char *_Nonnull HRP_OSMOSIS = "osmo";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.

#pragma once

#include "TWBase.h"
#include "TWPrivateKey.h"
#include "TWString.h"

TW_EXTERN_C_BEGIN

/// Represents a message signer to sign custom messages for any blockchain.
TW_EXPORT_CLASS
struct TWMessageSigner;

/// Signs an arbitrary message to prove ownership of an address for off-chain services.
///
/// \param coin The given coin type to sign the message for.
/// \param input The serialized data of a `MessageSigningInput` proto object, (e.g. `TW.Solana.Proto.MessageSigningInput`).
/// \return The serialized data of a `MessageSigningOutput` proto object, (e.g. `TW.Solana.Proto.MessageSigningOutput`).
TW_EXPORT_STATIC_METHOD
TWData* _Nullable TWMessageSignerSign(enum TWCoinType coin, TWData* _Nonnull input);

/// Verifies a signature for a message.
///
/// \param coin The given coin type to sign the message for.
/// \param input The serialized data of a verifying input (e.g. TW.Ethereum.Proto.MessageVerifyingInput).
/// \return whether the signature is valid.
TW_EXPORT_STATIC_METHOD
bool TWMessageSignerVerify(enum TWCoinType coin, TWData* _Nonnull input);

TW_EXTERN_C_END
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum TWPurpose {
TWPurposeBIP44 = 44,
TWPurposeBIP49 = 49, // Derivation scheme for P2WPKH-nested-in-P2SH
TWPurposeBIP84 = 84, // Derivation scheme for P2WPKH
TWPurposeBIP86 = 86, // Derivation scheme for P2TR
TWPurposeBIP1852 = 1852, // Derivation scheme used by Cardano-Shelley
};

Expand Down
Loading

0 comments on commit 1592391

Please sign in to comment.