Skip to content

Commit

Permalink
add sep-005 examples
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed Jul 16, 2020
1 parent 653f650 commit 361fe2a
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [1.0.3] - 16.Jul.2020.
- SEP-0005 implementation:
- Key Derivation Methods for Stellar Keys
- Update documentation
- Add tests and examples

## [1.0.2] - 14.Jul.2020.
- SEP-0002 implementation - Federation
- update documentation
Expand Down
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The Soneso open source Stellar SDK for Flutter is build with Dart and provides A
1. Add the dependency to your pubspec.yaml file:
```
dependencies:
stellar_flutter_sdk: ^1.0.2
stellar_flutter_sdk: ^1.0.3
```
2. Install it (command line or IDE):
```
Expand Down Expand Up @@ -77,6 +77,33 @@ print("${keyPair.secretSeed}");
// SAV76USXIJOBMEQXPANUOQM6F5LIOTLPDIDVRJBFFE2MDJXG24TAPUU7
```

#### Deterministic generation

The Stellar Ecosystem Proposal [SEP-005](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md) describes methods for key derivation for Stellar Accounts. This improves key storage and moving keys between wallets and apps.

##### Generate mnemonic

```dart
String 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
```

##### Generate key pairs
```dart
Wallet wallet = Wallet.from("mango debris lumber vivid bar risk prosper verify photo put ridge sell range pet indoor lava sister around panther brush twice cattle sauce romance");
KeyPair keyPair0 = wallet.getKeyPair(index: 0);
print("${keyPair0.accountId} : ${keyPair0.secretSeed}");
// GBYTVBTOVXBIT23X4YUEE32QBAAA537OAF553FWABUAZHT3FNPN3FUGG : SBEQZ4XGS434POXNQYUXQYFV6JYUHV56U2MNMUZBBBLBGR5X6PUUCYO5
KeyPair keyPair1 = wallet.getKeyPair(index: 1);
print("${keyPair1.accountId} : ${keyPair1.secretSeed}");
// GD5JFZ6U4TBKLWOVGAJQZ4CWRHNVXIFF65BBXZG6UEQE74RUXWAKQVQN : SD3IXULYMZKB6ML7AJW4OLAXKN6U3BYDUMOZLKUZTCCGZXUFXAS7NKIO
```

Supported languages are: english, french, spanish, italian, korean, japanese, simplified chinese and traditional chinese. Find more details in our [SEP-005 examples](documentation/sdk_examples/sep-0005-key-derivation.md).

### 2. Create an account
After the key pair generation, you have already got the address, but it is not activated until someone transfers at least 1 lumen into it.

Expand Down Expand Up @@ -268,7 +295,8 @@ print(response.memo);
| [Fee bump transaction](documentation/sdk_examples/fee_bump.md) | Fee bump transactions allow an arbitrary account to pay the fee for a transaction.| [Fee bump transactions](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0015.md)|
| [Muxed accounts](documentation/sdk_examples/muxed_account_payment.md) | In this example we will see how to use a muxed account in a payment operation.| [First-class multiplexed accounts](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0027.md)|
| [SEP-0001: stellar.toml](documentation/sdk_examples/sep-0001-toml.md) | In this example you can find out how to obtain data about an organization’s Stellar integration.| [SEP-0001](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0001.md)|
| [SEP-0002: Federation](documentation/sdk_examples/sep-0002-federation.md) | This examples shows how to resolve a stellar address, a stellar account id, a transaction id and a forward by using the federation protocol. | [SEP-0002](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0002.md)|
| [SEP-0002: Federation](documentation/sdk_examples/sep-0002-federation.md) | This example shows how to resolve a stellar address, a stellar account id, a transaction id and a forward by using the federation protocol. | [SEP-0002](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0002.md)|
| [SEP-0005: Key derivation](documentation/sdk_examples/sep-0005-key-derivation.md) | In this 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. | [SEP-0005](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md)|

Additional examples can be found in the [tests](https://github.com/Soneso/stellar_flutter_sdk/blob/master/test/).

Expand Down
2 changes: 1 addition & 1 deletion documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The Soneso open source Stellar SDK for Flutter is build with Dart and provides A
| [Muxed accounts](sdk_examples/muxed_account_payment.md) | In this example we will see how to use a muxed account in a payment operation.| [First-class multiplexed accounts](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0027.md)|
| [SEP-0001: stellar.toml](sdk_examples/sep-0001-toml.md) | In this example you can find out how to obtain data about an organization’s Stellar integration.| [SEP-0001](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0001.md)|
| [SEP-0002: Federation](sdk_examples/sep-0002-federation.md) | This examples shows how to resolve a stellar address, a stellar account id, a transaction id and a forward by using the federation protocol. | [SEP-0002](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0002.md)|

| [SEP-0005: Key derivation](sdk_examples/sep-0005-key-derivation.md) | In this 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. | [SEP-0005](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md)|

More examples and use cases can be found in the [test classes](../test).

Expand Down
1 change: 1 addition & 0 deletions documentation/sdk_examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ The [Soneso open source Stellar SDK for Flutter](https://github.com/Soneso/stell
| [Muxed accounts](muxed_account_payment.md) | In this example we will see how to use a muxed account in a payment operation.| [First-class multiplexed accounts](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0027.md)|
| [SEP-0001: stellar.toml](sep-0001-toml.md) | In this example you can find out how to obtain data about an organization’s Stellar integration.| [SEP-0001](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0001.md)|
| [SEP-0002: Federation](sep-0002-federation.md) | This examples shows how to resolve a stellar address, a stellar account id, a transaction id and a forward by using the federation protocol. | [SEP-0002](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0002.md)|
| [SEP-0005: Key derivation](sdk_examples/sep-0005-key-derivation.md) | In this 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. | [SEP-0005](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md)|

98 changes: 98 additions & 0 deletions documentation/sdk_examples/sep-0005-key-derivation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@

### SEP-0005 - Key Derivation Methods for Stellar Keys

Methods for key derivation for Stellar are described in [SEP-005](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md). 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

```dart
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

```dart
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

```dart
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

```dart
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

```dart
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

```dart
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
```
2 changes: 1 addition & 1 deletion lib/src/stellar_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import 'requests/trades_request_builder.dart';

/// Main class of the flutter stellar sdk.
class StellarSDK {
static const versionNumber = "1.0.2";
static const versionNumber = "1.0.3";

static final StellarSDK PUBLIC =
new StellarSDK("https://horizon.stellar.org");
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: stellar_flutter_sdk
description: A stellar blockchain sdk that query's horizon, build, signs and submits transactions to the stellar netweok.
version: 1.0.2
version: 1.0.3
homepage: https://github.com/Soneso/stellar_flutter_sdk

environment:
Expand Down
50 changes: 50 additions & 0 deletions test/examples_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1619,4 +1619,54 @@ void main() {
print(response.memoType);
print(response.memo);
});

test('sep 0005 - key derivation ', () async {
String mnemonic = Wallet.generate12WordsMnemonic();
print(mnemonic);

mnemonic = Wallet.generate24WordsMnemonic();
print(mnemonic);

String frenchMnemonic =
Wallet.generate12WordsMnemonic(language: LANGUAGE_FRENCH);
print(frenchMnemonic);

String koreanMnemonic =
Wallet.generate24WordsMnemonic(language: LANGUAGE_KOREAN);
print(koreanMnemonic);

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}");

KeyPair keyPair1 = wallet.getKeyPair(index: 1);
print("${keyPair1.accountId} : ${keyPair1.secretSeed}");

wallet = Wallet.from(
"절차 튀김 건강 평가 테스트 민족 몹시 어른 주민 형제 발레 만점 산길 물고기 방면 여학생 결국 수명 애정 정치 관심 상자 축하 고무신",
language: LANGUAGE_KOREAN);
keyPair0 = wallet.getKeyPair(index: 0);
print("${keyPair0.accountId} : ${keyPair0.secretSeed}");

keyPair1 = wallet.getKeyPair(index: 1);
print("${keyPair1.accountId} : ${keyPair1.secretSeed}");

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");

keyPair0 = wallet.getKeyPair(index: 0);
print("${keyPair0.accountId} : ${keyPair0.secretSeed}");
keyPair1 = wallet.getKeyPair(index: 1);
print("${keyPair1.accountId} : ${keyPair1.secretSeed}");

wallet = Wallet.fromBip39HexSeed(
"e4a5a632e70943ae7f07659df1332160937fad82587216a4c64315a0fb39497ee4a01f76ddab4cba68147977f3a147b6ad584c41808e8238a07f6cc4b582f186");
keyPair0 = wallet.getKeyPair(index: 0);
print("${keyPair0.accountId} : ${keyPair0.secretSeed}");
keyPair1 = wallet.getKeyPair(index: 1);
print("${keyPair1.accountId} : ${keyPair1.secretSeed}");
});
}

0 comments on commit 361fe2a

Please sign in to comment.