Hi guys, thank you for your feedback!
In the meantime the beta phase of the Flutter SDK is finished and I added implementation for SEP-0001 stellar.toml, SEP-0002 Federation and SEP-0005 Key derivation
stellar.toml (SEP-0001)
The data can be parsed from a string or loaded and parsed from a given domain.
From string
To parse the data from a string you can use the default constructor of the StellarToml
class.
String toml = '''
# Sample stellar.toml
VERSION="2.0.0"
# ...
''';
StellarToml stellarToml = StellarToml(toml);
GeneralInformation generalInformation = stellarToml.generalInformation;
print(generalInformation.version);
After parsing, the StellarToml
class provides: generalInformation
, documentation
, pointsOfContact
, currencies
and validators
From domain
To load and parse the data from a domain you can use the fromDomain constructor of the StellarToml class. It automatically composes the needed url. In the following example the data is loaded from: https://soneso.com/.well-known/stellar.toml - only the domain "soneso.com" has to be provided:
StellarToml stellarToml = await StellarToml.fromDomain("soneso.com");
GeneralInformation generalInformation = stellarToml.generalInformation;
//...
Linked currency
Alternately to specifying a specific currency in it's content, stellar.toml
can link out to a separate TOML file for a given currency by specifying toml="https://DOMAIN/.well-known/CURRENCY.toml"
as the currency's only field.
VERSION="2.0.0"
#...
[[CURRENCIES]]
toml="https://soneso.com/.well-known/TESTC.toml"
#...
To load the data of this currency, you can use the static method: StellarToml.currencyFromUrl(String toml)
- as shown in the example below:
StellarToml stellarToml = await StellarToml.fromDomain("soneso.com");
List<Currency> currencies = stellarToml.currencies;
for (Currency currency in currencies) {
if (currency.toml != null) {
Currency linkedCurrency = await StellarToml.currencyFromUrl(currency.toml);
print(linkedCurrency.code);
}
}
Federation (SEP-0002)
Resolving a stellar address
To resolve a stellar address like for example bob*soneso.com
we can use the static method Federation.resolveStellarAddress
as shown below:
FederationResponse response = await Federation.resolveStellarAddress("bob*soneso.com");
print(response.stellarAddress);
// bob*soneso.com
print(response.accountId);
// GBVPKXWMAB3FIUJB6T7LF66DABKKA2ZHRHDOQZ25GBAEFZVHTBPJNOJI
print(response.memoType);
// text
print(response.memo);
// hello memo text
Resolving a stellar account id
To resolve a stellar account id like for example GBVPKXWMAB3FIUJB6T7LF66DABKKA2ZHRHDOQZ25GBAEFZVHTBPJNOJI
we can use the static method Federation.resolveStellarAccountId
. We need to provide the account id and the federation server url as parameters:
FederationResponse response = await Federation.resolveStellarAccountId("GBVPKXWMAB3FIUJB6T7LF66DABKKA2ZHRHDOQZ25GBAEFZVHTBPJNOJI", "https://stellarid.io/federation/");
print(response.stellarAddress);
// bob*soneso.com
print(response.accountId);
// GBVPKXWMAB3FIUJB6T7LF66DABKKA2ZHRHDOQZ25GBAEFZVHTBPJNOJI
print(response.memoType);
// text
print(response.memo);
// hello memo text
Resolving a stellar transaction id
To resolve a stellar transaction id like for example c1b368c00e9852351361e07cc58c54277e7a6366580044ab152b8db9cd8ec52a
we can use the static method Federation.resolveStellarTransactionId
. We need to provide the transaction id and the federation server url as parameters:
// Returns the federation record of the sender of the transaction if known by the server
FederationResponse response = await Federation.resolveStellarTransactionId("c1b368c00e9852351361e07cc58c54277e7a6366580044ab152b8db9cd8ec52a", "https://stellarid.io/federation/");
Resolving a forward
Used for forwarding the payment on to a different network or different financial institution. Here we can use the static method Federation.resolveForward
. We need to provide the needed query parameters as Map<String, String>
and the federation server url:
FederationResponse response = await Federation.resolveForward({
"forward_type": "bank_account",
"swift": "BOPBPHMM",
"acct": "2382376"
}, "https://stellarid.io/federation/");
// resulting request url:
// https://stellarid.io/federation/?type=forward&forward_type=bank_account&swift=BOPBPHMM&acct=2382376
Key Derivation Methods for Stellar Key (SEP-0005)
Methods for key derivation for Stellar are described in SEP-005. This improves key storage and moving keys between wallets and apps.
In the following examples you can see how to generate 12 or 24 words mnemonics for different languages using the Flutter SDK, how to generate key pairs from a mnemonic (with and without BIP 39 passphrase) and how to generate key pairs from a BIP 39 seed.
Generate mnemonic
String mnemonic = Wallet.generate12WordsMnemonic();
print(mnemonic);
// twice news void fiction lamp chaos few code rate donkey supreme primary
mnemonic = Wallet.generate24WordsMnemonic();
print(mnemonic);
// mango debris lumber vivid bar risk prosper verify photo put ridge sell range pet indoor lava sister around panther brush twice cattle sauce romance
Default language is english.
Generate other language mnemonic
String frenchMnemonic = Wallet.generate12WordsMnemonic(language: LANGUAGE_FRENCH);
print(frenchMnemonic);
// pouvoir aménager lagune alliage bermuda taxer dogme avancer espadon sucre bermuda aboyer
String koreanMnemonic = Wallet.generate24WordsMnemonic(language: LANGUAGE_KOREAN);
print(koreanMnemonic);
// 합리적 채널 침대 달걀 기념 정성 세종대왕 한식 불안 독창적 착각 체계 순서 학급 평화 마약 냉면 멀리 남매 초반 치약 여권 지방 물음
Supported languages are:
- english
- french
- spanish
- italian
- korean
- japanese
- simplified chinese
- traditional chinese
Generate key pairs from mnemonic
Wallet wallet = Wallet.from("shell green recycle learn purchase able oxygen right echo claim hill again hidden evidence nice decade panic enemy cake version say furnace garment glue");
KeyPair keyPair0 = wallet.getKeyPair(index: 0);
print("${keyPair0.accountId} : ${keyPair0.secretSeed}");
// GCVSEBHB6CTMEHUHIUY4DDFMWQ7PJTHFZGOK2JUD5EG2ARNVS6S22E3K : SATLGMF3SP2V47SJLBFVKZZJQARDOBDQ7DNSSPUV7NLQNPN3QB7M74XH
KeyPair keyPair1 = wallet.getKeyPair(index: 1);
print("${keyPair1.accountId} : ${keyPair1.secretSeed}");
// GBPHPX7SZKYEDV5CVOA5JOJE2RHJJDCJMRWMV4KBOIE5VSDJ6VAESR2W : SCAYXPIDEUVDGDTKF4NGVMN7HCZOTZJ43E62EEYKVUYXEE7HMU4DFQA6
Generate key pairs from mnemonic of other language
Wallet wallet = Wallet.from("절차 튀김 건강 평가 테스트 민족 몹시 어른 주민 형제 발레 만점 산길 물고기 방면 여학생 결국 수명 애정 정치 관심 상자 축하 고무신",
language: LANGUAGE_KOREAN);
KeyPair keyPair0 = wallet.getKeyPair(index: 0);
print("${keyPair0.accountId} : ${keyPair0.secretSeed}");
// GCITEFHNYX3ZCD6XQXPWPZGGS2KTYE4C6RPDUIYOW33PC3PU3PGU667E : SB6KJ2HFH32PXSRATDPSV65DNYCN2XA6RVHKSFI3NSGU5YRSDLB56M76
KeyPair keyPair1 = wallet.getKeyPair(index: 1);
print("${keyPair1.accountId} : ${keyPair1.secretSeed}");
// GB6LTLB32AFIZL5DPOLHYRVZNHGFBBWGJ5DZCVHMBEW3U4DOXHTX3UQV : SBJJXYH3HPBZ2BDJ5NBE3EJLYDPMVBGG7ZZIYGEED2EKWMNKLCVFPAY7
Generate key pairs from mnemonic with BIP 39 passphrase
Wallet wallet = Wallet.from("cable spray genius state float twenty onion head street palace net private method loan turn phrase state blanket interest dry amazing dress blast tube",
passphrase: "p4ssphr4se");
KeyPair keyPair0 = wallet.getKeyPair(index: 0);
print("${keyPair0.accountId} : ${keyPair0.secretSeed}");
// GDAHPZ2NSYIIHZXM56Y36SBVTV5QKFIZGYMMBHOU53ETUSWTP62B63EQ : SAFWTGXVS7ELMNCXELFWCFZOPMHUZ5LXNBGUVRCY3FHLFPXK4QPXYP2X
KeyPair keyPair1 = wallet.getKeyPair(index: 1);
print("${keyPair1.accountId} : ${keyPair1.secretSeed}");
// GDY47CJARRHHL66JH3RJURDYXAMIQ5DMXZLP3TDAUJ6IN2GUOFX4OJOC : SBQPDFUGLMWJYEYXFRM5TQX3AX2BR47WKI4FDS7EJQUSEUUVY72MZPJF
Generate key pairs from BIP 39 seed
Wallet wallet = Wallet.fromBip39HexSeed("e4a5a632e70943ae7f07659df1332160937fad82587216a4c64315a0fb39497ee4a01f76ddab4cba68147977f3a147b6ad584c41808e8238a07f6cc4b582f186");
KeyPair keyPair0 = wallet.getKeyPair(index: 0);
print("${keyPair0.accountId} : ${keyPair0.secretSeed}");
// GDRXE2BQUC3AZNPVFSCEZ76NJ3WWL25FYFK6RGZGIEKWE4SOOHSUJUJ6 : SBGWSG6BTNCKCOB3DIFBGCVMUPQFYPA2G4O34RMTB343OYPXU5DJDVMN
KeyPair keyPair1 = wallet.getKeyPair(index: 1);
print("${keyPair1.accountId} : ${keyPair1.secretSeed}");
// GBAW5XGWORWVFE2XTJYDTLDHXTY2Q2MO73HYCGB3XMFMQ562Q2W2GJQX : SCEPFFWGAG5P2VX5DHIYK3XEMZYLTYWIPWYEKXFHSK25RVMIUNJ7CTIS
If you want to learn more about the open source Flutter SDK please take a look at our Github repository.
I look forward to your feedback and suggestions for improvement.