Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.0.1

* TODO: Describe initial release.


## 0.0.2

* add newchain support
Binary file modified android/libs/trustwalletcore.aar
Binary file not shown.
1 change: 1 addition & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:exported="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
Expand Down
2 changes: 1 addition & 1 deletion example/integration_test/bitcoin/bitcoin_address_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_trust_wallet_core/flutter_trust_wallet_core.dart';
import '../core/unit8list.dart';
import '../../lib/unit8list.dart';

void main() {
group('BitcoinAddress.isValid test', () {
Expand Down
2 changes: 1 addition & 1 deletion example/integration_test/core/base58_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:convert/convert.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_trust_wallet_core/flutter_trust_wallet_core.dart';
import 'unit8list.dart';
import '../../lib/unit8list.dart';

void main() {
test('Base58.base58Encode will equal', () {
Expand Down
2 changes: 1 addition & 1 deletion example/integration_test/core/private_key_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:convert/convert.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_trust_wallet_core/flutter_trust_wallet_core.dart';
import 'package:flutter_trust_wallet_core/trust_wallet_core_ffi.dart';
import 'unit8list.dart';
import '../../lib/unit8list.dart';

void main() {
group('PrivateKey.isValid will be true', () {
Expand Down
2 changes: 1 addition & 1 deletion example/integration_test/core/public_key.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_trust_wallet_core/flutter_trust_wallet_core.dart';
import 'package:flutter_trust_wallet_core/trust_wallet_core_ffi.dart';
import 'unit8list.dart';
import '../../lib/unit8list.dart';

void main() {
group('PublicKey.isValid test of TWPublicKeyTypeSECP256k1', () {
Expand Down
10 changes: 0 additions & 10 deletions example/integration_test/core/unit8list.dart

This file was deleted.

2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c

COCOAPODS: 1.11.3
COCOAPODS: 1.11.2
2 changes: 2 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
</dict>
</plist>
26 changes: 16 additions & 10 deletions example/lib/bitcoin_address_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,28 @@ import 'package:flutter_trust_wallet_core_example/base_example.dart';
class BitcoinAddressExample extends BaseExample {
final HDWallet wallet;

const BitcoinAddressExample(this.wallet, {Key? key}) : super('Bitcoin Address', key: key);
const BitcoinAddressExample(this.wallet, {Key? key})
: super('Bitcoin Address', key: key);

@override
_BitcoinAddressExampleState createState() => _BitcoinAddressExampleState();
}

class _BitcoinAddressExampleState extends BaseExampleState<BitcoinAddressExample> {
class _BitcoinAddressExampleState
extends BaseExampleState<BitcoinAddressExample> {
@override
void initState() {
super.initState();
int coin = TWCoinType.TWCoinTypeBitcoinTestnet;
int coin = TWCoinType.TWCoinTypeBitcoin;
final privakye2 = widget.wallet.getKey(coin, "m/44'/0'/0'/0/0");
logger.d(hex.encode(privakye2.data()));
final publicKey2 = privakye2.getPublicKeySecp256k1(true);
logger.d(widget.wallet.getExtendedPublicKey(TWPurpose.TWPurposeBIP44, coin, TWHDVersion.TWHDVersionTPUB));
logger.d(widget.wallet.getExtendedPublicKey(
TWPurpose.TWPurposeBIP44, coin, TWHDVersion.TWHDVersionTPUB));
final bitcoinAddress = BitcoinAddress.createWithPublicKey(publicKey2, coin);
logger.d(bitcoinAddress.description());
final segwitAddress = SegwitAddress.createWithPublicKey(HRP.Bitcoin, publicKey2);
final segwitAddress =
SegwitAddress.createWithPublicKey(HRP.Bitcoin, publicKey2);
logger.d(segwitAddress.description());
final address2 = AnyAddress.createWithPublicKey(publicKey2, 0);
logger.d("address2 = ${address2.description()}");
Expand All @@ -39,13 +43,15 @@ class _BitcoinAddressExampleState extends BaseExampleState<BitcoinAddressExample
final bitcoinAddress2 = BitcoinAddress.createWithData(data);
logger.d(bitcoinAddress2.description());


final bip84Privakey = widget.wallet.getKeyForCoin(TWCoinType.TWCoinTypeBitcoin);
final wif = WIF.encode(hex.encode(bip84Privakey.data()), TWCoinType.TWCoinTypeBitcoin);
final bip84Privakey =
widget.wallet.getKeyForCoin(TWCoinType.TWCoinTypeBitcoin);
final wif = WIF.encode(
hex.encode(bip84Privakey.data()), TWCoinType.TWCoinTypeBitcoin);
logger.d("bip84 origin privakey = ${hex.encode(bip84Privakey.data())}");
logger.d("bip84 wif privakey = $wif");

final keystore = StoredKey.importHDWallet(widget.wallet.mnemonic(), "wtf", "123", TWCoinType.TWCoinTypeBitcoin);
final keystore = StoredKey.importHDWallet(
widget.wallet.mnemonic(), "wtf", "123", TWCoinType.TWCoinTypeBitcoin);
logger.d("keystore json = ${keystore?.exportJson()}");
}
}
}
42 changes: 30 additions & 12 deletions example/lib/bitcoin_transaction_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ import 'package:fixnum/fixnum.dart' as $fixnum;
class BitcoinTransactionExample extends BaseExample {
final HDWallet wallet;

const BitcoinTransactionExample(this.wallet, {Key? key}) : super('Bitcoin Transaction', key: key);
const BitcoinTransactionExample(this.wallet, {Key? key})
: super('Bitcoin Transaction', key: key);

@override
_BitcoinTransactionExampleState createState() => _BitcoinTransactionExampleState();
_BitcoinTransactionExampleState createState() =>
_BitcoinTransactionExampleState();
}

class _BitcoinTransactionExampleState extends BaseExampleState<BitcoinTransactionExample> {
class _BitcoinTransactionExampleState
extends BaseExampleState<BitcoinTransactionExample> {
@override
void initState() {
super.initState();
int coin = TWCoinType.TWCoinTypeBitcoinTestnet;
int coin = TWCoinType.TWCoinTypeBitcoin;
final addressBtc = widget.wallet.getAddressForCoin(coin);
final toAddress = "tb1qks8l9haxjszn9r6yf2dm65ed3w6wmz85r379ms";
final changeAddress = "mvcJcHN3ZhELVVhncfjARUMtfRELwhGXgL";
Expand All @@ -35,34 +38,49 @@ class _BitcoinTransactionExampleState extends BaseExampleState<BitcoinTransactio
Bitcoin.UnspentTransaction(
amount: $fixnum.Int64.parseInt('20000'),
outPoint: Bitcoin.OutPoint(
hash: hex.decode('1b23757cdc023b3ac9f033522abb9f845815b65cce1e25411e8ad950899c0e71').reversed.toList(),
hash: hex
.decode(
'1b23757cdc023b3ac9f033522abb9f845815b65cce1e25411e8ad950899c0e71')
.reversed
.toList(),
index: 0,
sequence: 4294967295,
),
script: BitcoinScript.lockScriptForAddress(addressBtc, coin).data().toList(),
script: BitcoinScript.lockScriptForAddress(addressBtc, coin)
.data()
.toList(),
),
Bitcoin.UnspentTransaction(
amount: $fixnum.Int64.parseInt('20000'),
outPoint: Bitcoin.OutPoint(
hash: hex.decode('7611002ff116fad20ef12ad30010a07d5b25edf37209504dd42a6a4c5c27aa75').reversed.toList(),
hash: hex
.decode(
'7611002ff116fad20ef12ad30010a07d5b25edf37209504dd42a6a4c5c27aa75')
.reversed
.toList(),
index: 0,
sequence: 4294967295,
),
script: BitcoinScript.lockScriptForAddress(addressBtc, coin).data().toList(),
script: BitcoinScript.lockScriptForAddress(addressBtc, coin)
.data()
.toList(),
),
],
privateKey: [
secretPrivateKeyBtc.data().toList(),
],
);
final transactionPlan = Bitcoin.TransactionPlan.fromBuffer(AnySigner.signerPlan(signingInput.writeToBuffer(), coin).toList());
logger.d('availableAmount: ${transactionPlan.availableAmount} amount: ${transactionPlan.amount} fee: ${transactionPlan.fee} change: ${transactionPlan.change}');
print('availableAmount: ${transactionPlan.availableAmount} amount: ${transactionPlan.amount} fee: ${transactionPlan.fee} change: ${transactionPlan.change}');
final transactionPlan = Bitcoin.TransactionPlan.fromBuffer(
AnySigner.signerPlan(signingInput.writeToBuffer(), coin).toList());
logger.d(
'availableAmount: ${transactionPlan.availableAmount} amount: ${transactionPlan.amount} fee: ${transactionPlan.fee} change: ${transactionPlan.change}');
print(
'availableAmount: ${transactionPlan.availableAmount} amount: ${transactionPlan.amount} fee: ${transactionPlan.fee} change: ${transactionPlan.change}');
signingInput.plan = transactionPlan;
signingInput.amount = transactionPlan.amount;
final sign = AnySigner.sign(signingInput.writeToBuffer(), coin);
final signingOutput = Bitcoin.SigningOutput.fromBuffer(sign);
print(hex.encode(signingOutput.encoded));
logger.d(hex.encode(signingOutput.encoded));
}
}
}
38 changes: 35 additions & 3 deletions example/lib/ethereum_example.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
/*
* @Author: [email protected]
* @Date: 2022-05-11 10:37:19
* @LastEditors: [email protected]
* @LastEditTime: 2022-05-11 17:05:49
* @FilePath: /flutter_trust_wallet_core_lib_include/example/lib/ethereum_example.dart
* @Description:
*/
import 'dart:typed_data';

import 'package:convert/convert.dart';
import 'package:flutter/material.dart';
import 'package:flutter_trust_wallet_core/flutter_trust_wallet_core.dart';
import 'package:flutter_trust_wallet_core/trust_wallet_core_ffi.dart';
import 'package:flutter_trust_wallet_core_example/base_example.dart';
import 'package:flutter_trust_wallet_core/protobuf/Ethereum.pb.dart'
as Ethereum;

class EthereumExample extends BaseExample {
final HDWallet wallet;
Expand All @@ -28,10 +39,12 @@ class _EthereumExampleState extends BaseExampleState<EthereumExample> {
// logger.d("privateKeyhex0 = $privateKey0");
// logger.d("privateKeyhex1 = $privateKey1");
logger.d("seed = ${hex.encode(widget.wallet.seed())}");
final a = StoredKey.importPrivateKey(widget.wallet.getKeyForCoin(60).data(), "", "123", 60);
final a = StoredKey.importPrivateKey(
widget.wallet.getKeyForCoin(60).data(), "", "123", 60);
logger.d("keystore a = ${a?.exportJson()}");

final publicKey = widget.wallet.getKeyForCoin(60).getPublicKeySecp256k1(false);
final publicKey =
widget.wallet.getKeyForCoin(60).getPublicKeySecp256k1(false);
final anyAddress = AnyAddress.createWithPublicKey(publicKey, 60);

// logger.d("1 = ${AnyAddress.isValid("0xfaC5482fffe86d33c3b8ADB24F839F5e60aF99d4", DartTWCoinType.TWCoinTypeEthereum)}");
Expand All @@ -42,5 +55,24 @@ class _EthereumExampleState extends BaseExampleState<EthereumExample> {
final address = AnyAddress.createWithPublicKey(publicKey1, 0);

logger.d("keystore a = ${address.description()}");

Ethereum.SigningInput input = Ethereum.SigningInput(
chainId: [1007],
nonce: [100],
gasPrice: [100],
gasLimit: [100],
maxFeePerGas: [0],
maxInclusionFeePerGas: [0],
toAddress: "0xfaC5482fffe86d33c3b8ADB24F839F5e60aF99d4",
privateKey: privakye.data().toList(),
transaction: Ethereum.Transaction(
transfer: Ethereum.Transaction_Transfer(
amount: [0],
)));
logger.d("input = ${input}");
final output = Ethereum.SigningOutput.fromBuffer(
AnySigner.sign(input.writeToBuffer(), TWCoinType.TWCoinTypeEthereum)
.toList());
logger.d("output = ${hex.encode(output.encoded.toList())}");
}
}
}
10 changes: 9 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter_trust_wallet_core_example/bitcoin_transaction_example.da
import 'package:flutter_trust_wallet_core_example/ethereum_example.dart';
import 'package:flutter_trust_wallet_core_example/private_key_is_valid_example.dart';
import 'package:flutter_trust_wallet_core_example/tron_example.dart';
import 'package:flutter_trust_wallet_core_example/newchain_example.dart';

List<String> logs = [];

Expand Down Expand Up @@ -35,7 +36,8 @@ class _ExampleState extends State<Example> {
void initState() {
FlutterTrustWalletCore.init();
super.initState();
String mnemonic = "rent craft script crucial item someone dream federal notice page shrug pipe young hover duty"; // 有测试币的 tron地址
String mnemonic =
"rent craft script crucial item someone dream federal notice page shrug pipe young hover duty"; // 有测试币的 tron地址
wallet = HDWallet.createWithMnemonic(mnemonic);
}

Expand Down Expand Up @@ -95,6 +97,12 @@ class _ExampleState extends State<Example> {
return PrivateKeyIsValidExample(wallet);
},
),
_exampleItem(
name: 'NewChain',
builder: (_) {
return NewChainExample(wallet);
},
)
],
),
),
Expand Down
76 changes: 76 additions & 0 deletions example/lib/newchain_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* @Author: [email protected]
* @Date: 2022-05-11 09:57:24
* @LastEditors: [email protected]
* @LastEditTime: 2022-06-01 20:49:28
* @FilePath: /flutter_trust_wallet_core_lib_include/example/lib/newchain_example.dart
* @Description:
*/
import 'package:convert/convert.dart';
import 'package:flutter/material.dart';
import 'package:flutter_trust_wallet_core/flutter_trust_wallet_core.dart';
import 'package:flutter_trust_wallet_core/trust_wallet_core_ffi.dart';
import 'package:flutter_trust_wallet_core_example/base_example.dart';
import 'package:flutter_trust_wallet_core/protobuf/Ethereum.pb.dart'
as Ethereum;
import 'package:flutter_trust_wallet_core_example/unit8list.dart';

class NewChainExample extends BaseExample {
final HDWallet wallet;

const NewChainExample(this.wallet, {Key? key}) : super('NewChain', key: key);

@override
_NewChainExampleState createState() => _NewChainExampleState();
}

class _NewChainExampleState extends BaseExampleState<NewChainExample> {
@override
void initState() {
super.initState();
logger.d("address ${widget.wallet.getAddressForCoin(1642)}");
logger.d("mnemonic = ${widget.wallet.mnemonic()}");
print(widget.wallet.mnemonic());
String privateKeyhex = hex.encode(widget.wallet.getKeyForCoin(1642).data());
// String privateKey0 = hex.encode(widget.wallet.getDerivedKey(60,0,0,0).data());
// String privateKey1 = hex.encode(widget.wallet.getDerivedKey(60,0,0,1).data());
logger.d("privateKeyhex = $privateKeyhex");
// logger.d("privateKeyhex0 = $privateKey0");
// logger.d("privateKeyhex1 = $privateKey1");
logger.d("seed = ${hex.encode(widget.wallet.seed())}");
final a = StoredKey.importPrivateKey(
widget.wallet.getKeyForCoin(1642).data(), "", "123", 1642);
logger.d("keystore a = ${a?.exportJson()}");

final publicKey =
widget.wallet.getKeyForCoin(1642).getPublicKeySecp256k1(false);
final anyAddress = AnyAddress.createWithPublicKey(publicKey, 1642);

final privakye = widget.wallet.getKey(1642, "m/44'/1642'/0'/0/0");
final publicKey1 = privakye.getPublicKeySecp256k1(true);
final address = AnyAddress.createWithPublicKey(
publicKey1, TWCurve.TWPublicKeyTypeNIST256p1Extended);
print("address: ${address}");
print("privakye a = ${hex.encode(privakye.data())}");

Ethereum.SigningInput input = Ethereum.SigningInput(
chainId: Utils.number2Uint8List(1007),
nonce: Utils.number2Uint8List(1007),
gasPrice: Utils.number2Uint8List(50000000),
gasLimit: Utils.number2Uint8List(2394234),
maxFeePerGas: Utils.number2Uint8List(0),
maxInclusionFeePerGas: Utils.number2Uint8List(0),
toAddress: "0xfaC5482fffe86d33c3b8ADB24F839F5e60aF99d4",
privateKey: Utils.string2Uint8List(hex.encode(privakye.data())),
transaction: Ethereum.Transaction(
transfer: Ethereum.Transaction_Transfer(amount: [0], data: [0])));
logger.d("input = ${input}");
final res = Ethereum.SigningInput.fromBuffer(input.writeToBuffer());
print("res");
print(res);
final output = Ethereum.SigningOutput.fromBuffer(
AnySigner.sign(input.writeToBuffer(), TWCoinType.TWCoinTypeNewChain)
.toList());
print("output = ${hex.encode(output.encoded.toList())}");
}
}
Loading