Skip to content

Commit

Permalink
add sep-0006 examples & doc
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed Jul 23, 2021
1 parent fe49400 commit 27803fa
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [1.1.8] - 23.July.2021.
- add sep-0006 support
- add sep-0009 support
- add sep-0012 support

## [1.1.7] - 29.Jun.2021.
- update support for horizon > 2.5.1 (representation of "..._muxed_id" field values changed to string)

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,11 @@ print(response.memo);
| [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 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)|
| [SEP-0006: Deposit and Withdrawal API](documentation/sdk_examples/sep-0006-transfer.md) | In this examples you can see how to use the sdk to communicate with anchors.| [SEP-0006](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md)|
| [SEP-0010: Stellar Web Authentication](documentation/sdk_examples/sep-0010-webauth.md) | This example shows how to authenticate with any web service which requires a Stellar account ownership verification. | [SEP-0010](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md)|
| [SEP-0011: Txrep](documentation/sdk_examples/sep-0011-txrep.md) | This example shows how to to generate Txrep (human-readable low-level representation of Stellar transactions) from a transaction and how to create a transaction object from a Txrep string. | [SEP-0011](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0011.md)|
| [SEP-0012: KYC API](documentation/sdk_examples/sep-0012-kyc.md) | In this examples you can see how to use the sdk to send KYC data to anchors and other services. | [SEP-0012](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md)|


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

Expand Down
6 changes: 5 additions & 1 deletion documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ 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)|
| [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)|
| [SEP-0006: Deposit and Withdrawal API](sdk_examples/sep-0006-transfer.md) | In this examples you can see how to use the sdk to communicate with anchors.| [SEP-0006](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md)|
| [SEP-0010: Stellar Web Authentication](sdk_examples/sep-0010-webauth.md) | This example shows how to authenticate with any web service which requires a Stellar account ownership verification. | [SEP-0010](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md)|
| [SEP-0011: Txrep](sdk_examples/sep-0011-txrep.md) | This example shows how to to generate Txrep (human-readable low-level representation of Stellar transactions) from a transaction and how to create a transaction object from a Txrep string. | [SEP-0011](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0011.md)|
| [SEP-0012: KYC API](sdk_examples/sep-0012-kyc.md) | In this examples you can see how to use the sdk to send KYC data to anchors and other services. | [SEP-0012](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md)|


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

Expand Down
Binary file modified documentation/sdk_api_doc.zip
Binary file not shown.
2 changes: 2 additions & 0 deletions documentation/sdk_examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ The [Soneso open source Stellar SDK for Flutter](https://github.com/Soneso/stell
| [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](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)|
| [SEP-0006: Deposit and Withdrawal API](sep-0006-transfer.md) | In this examples you can see how to use the sdk to communicate with anchors.| [SEP-0006](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md)|
| [SEP-0011: Txrep](sep-0011-txrep.md) | This example shows how to to generate Txrep (human-readable low-level representation of Stellar transactions) from a transaction and how to create a transaction object from a Txrep string. | [SEP-0011](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0011.md)|
| [SEP-0012: KYC API](sep-0012-kyc.md) | In this examples you can see how to use the sdk to send KYC data to anchors and other services. | [SEP-0012](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md)|

163 changes: 163 additions & 0 deletions documentation/sdk_examples/sep-0006-transfer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@

### SEP-0006 - TransferServerService

Helps clients to interact with anchors in a standard way defined by [SEP-0006: Deposit and Withdrawal API](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md).



### Create a TransferServerService instance

**By providing the domain hosting the stellar.toml file**

```dart
final transferService = await TransferServerService.fromDomain("place.domain.com");
```

This will automatically load and parse the stellar.toml file. It will then create the TransferServerService instance by using the transfer server url provided in the stellar.toml file.

**Or by providing the service url**

Alternatively one can create a TransferServerService instance by providing the transfer server url directly via the constructor:

```dart
final transferService = TransferServerService("http://api.stellar-anchor.org/transfer");
```



### Info

This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md#info)) allows an anchor to communicate basic info about what their TRANSFER_SERVER supports to wallets and clients. With the flutter sdk you can use the ```info``` method of your ```TransferServerService``` instance to get the info:

```dart
// uses the jwt token received from stellar web auth - sep-0010
InfoResponse response = await transferService.info("en", jwtToken);
print(response.feeInfo.enabled);
```



### Deposit

This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md#deposit)) is used when a user sends an external token (BTC via Bitcoin, USD via bank transfer, etc...) to an address held by an anchor. With the flutter sdk you can use the ```deposit``` method of your ```TransferServerService``` instance to get the deposit information:

```dart
DepositRequest request = DepositRequest();
request.jwt = jwtToken; // jwt token received from stellar web auth - sep-0010
request.assetCode = "BTC";
request.account = accountId; // The stellar account ID of the user that wants to deposit.
// ...
try {
DepositResponse response = await transferService.deposit(request);
print(response.how);
print(response.feeFixed);
} on CustomerInformationNeededException catch (e) {
print(e.response.fields);
} on CustomerInformationStatusException catch (e) {
print(e.response.status);
} // ...
```



### Withdraw

This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md#withdraw)) is used when a user redeems an asset currently on the Stellar network for it's equivalent off-chain asset via the Anchor. For instance, a user redeeming their NGNT in exchange for fiat NGN. With the flutter sdk you can use the ```withdraw``` method of your ```TransferServerService``` instance to get the withdrawal information:

```dart
WithdrawRequest request = WithdrawRequest();
request.jwt = jwtToken; // jwt token received from stellar web auth - sep-0010
request.assetCode = "NGNT";
request.amount = "129.01";
// ...
try {
WithdrawResponse response = await transferService.withdraw(request);
print(response.accountId);
print(response.feeFixed);
} on CustomerInformationNeededException catch (e) {
print(e.response.fields);
} on CustomerInformationStatusException catch (e) {
print(e.response.status);
} // ...
```



### Fee

This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md#fee)) allows an anchor to report the fee that would be charged for a given deposit or withdraw operation. With the flutter sdk you can use the ```fee``` method of your ```TransferServerService``` instance to get the info if supported by the anchor:

```dart
FeeRequest request = FeeRequest();
request.jwt = jwtToken; // jwt token received from stellar web auth - sep-0010
request.operation = "deposit";
request.assetCode = "NGN";
request.amount = 123.09;
// ...
FeeResponse response = await transferService.fee(request);
print(response.fee);
```



### Transaction History

From this endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md#transaction-history)) wallets can receive the status of deposits and withdrawals while they process and a history of past transactions with the anchor. With the flutter sdk you can use the ```transactions``` method of your ```TransferServerService``` instance to get the transactions:

```dart
AnchorTransactionsRequest request = AnchorTransactionsRequest();
request.jwt = jwtToken; // jwt token received from stellar web auth - sep-0010
request.account = "GCTTGO5ABSTHABXWL2FMHPZ2XFOZDXJYJN5CKFRKXMPAAWZW3Y3JZ3JK";
request.assetCode = "XLM";
AnchorTransactionsResponse response = await transferService.transactions(request);
print(response.transactions.length);
print(response.transactions.first.id);
// ...
```



### Single Historical Transaction

This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md#single-historical-transaction)) enables clients to query/validate a specific transaction at an anchor. With the flutter sdk you can use the ```transaction``` method of your ```TransferServerService``` instance to get the data:

```dart
AnchorTransactionRequest request = AnchorTransactionRequest();
request.jwt = jwtToken; // jwt token received from stellar web auth - sep-0010
request.id = "82fhs729f63dh0v4";
AnchorTransactionResponse response = await transferService.transaction(request);
print(response.transaction.kind);
print(response.transaction.status);
// ...
```



### Update Transaction

This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md#update)) is used when the anchor requests more info via the pending_transaction_info_update status. With the flutter sdk you can use the ```patchTransaction``` method of your ```TransferServerService``` instance to update the data:

```dart
PatchTransactionRequest request = PatchTransactionRequest();
request.jwt = jwtToken; // jwt token received from stellar web auth - sep-0010
request.id = "82fhs729f63dh0v4";
request.fields = {};
request.fields["dest"] = "12345678901234";
request.fields["dest_extra"] = "021000021";
http.Response response = await transferService.patchTransaction(request);
print(response.status);
// ...
```



### Further readings

For more info, see also the class documentation of ```TransferServerService``` and the sdk's sep-0006 test cases.

21 changes: 14 additions & 7 deletions documentation/sdk_examples/sep-0012-kyc.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Helps clients to upload KYC (or other) information to anchors and other services
**By providing the domain hosting the stellar.toml file**

```dart
final kycService = await KYCService.fromDomain("kyc.domain.com");
final kycService = await KYCService.fromDomain("place.domain.com");
```

This will automatically load and parse the stellar.toml file. It will then create the KYCService instance by using the kyc server url provided in the stellar.toml file. If no kyc server url is provided, than it will use the transfer server url to create the instance.
Expand All @@ -33,7 +33,7 @@ This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob
1. Fetch the fields the server requires in order to register a new customer via a PUT /customer request or
2. Check the status of a customer that may already be registered

With the flutter sdk you can use the ```getCustomerInfo``` of your ```KYCService``` instance to get the info:
With the flutter sdk you can use the ```getCustomerInfo``` method of your ```KYCService``` instance to get the info:

```dart
GetCustomerInfoRequest request = new GetCustomerInfoRequest();
Expand All @@ -48,7 +48,7 @@ print(response.status);

### Upload customer info to an anchor

This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md#customer-put)) allows clients to upload customer information to an anchor in an authenticated and idempotent fashion. With the flutter sdk you can use the ```putCustomerInfo``` of your ```KYCService``` instance to upload the data:
This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md#customer-put)) allows clients to upload customer information to an anchor in an authenticated and idempotent fashion. With the flutter sdk you can use the ```putCustomerInfo``` method of your ```KYCService``` instance to upload the data:

```dart
NaturalPersonKYCFields kycFields = new NaturalPersonKYCFields();
Expand All @@ -70,7 +70,7 @@ print(response.id);

### Customer verification

This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md#customer-put-verification)) allows servers to accept data values, usually confirmation codes, that verify a previously provided customer data field, such as mobile_number or email_address. With the flutter sdk you can use the ```putCustomerVerification``` of your ```KYCService``` instance to send the data values:
This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md#customer-put-verification)) allows servers to accept data values, usually confirmation codes, that verify a previously provided customer data field, such as mobile_number or email_address. With the flutter sdk you can use the ```putCustomerVerification``` method of your ```KYCService``` instance to send the data values:

```dart
PutCustomerVerificationRequest request = new PutCustomerVerificationRequest();
Expand All @@ -89,7 +89,7 @@ print(response.status);

### Delete customer

This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md#customer-delete)) allows clients to delete all personal information that the anchor has stored about a given customer. With the flutter sdk you can use the ```deleteCustomer``` of your ```KYCService``` instance to delete the data:
This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md#customer-delete)) allows clients to delete all personal information that the anchor has stored about a given customer. With the flutter sdk you can use the ```deleteCustomer``` method of your ```KYCService``` instance to delete the data:

```dart
http.Response response = await kycService.deleteCustomer(accountId, null, null, jwtToken);
Expand All @@ -100,7 +100,7 @@ print(response.status);

### Customer callback url

This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md#customer-callback-put)) allows the wallet to provide a callback URL to the anchor. Whenever the user's status field changes, the anchor will issue a POST request to the callback URL. With the flutter sdk you can use the ```putCustomerCallback``` of your ```KYCService``` instance to set the callback url:
This endpoint (described [here](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md#customer-callback-put)) allows the wallet to provide a callback URL to the anchor. Whenever the user's status field changes, the anchor will issue a POST request to the callback URL. With the flutter sdk you can use the ```putCustomerCallback``` method of your ```KYCService``` instance to set the callback url:

```dart
PutCustomerCallbackRequest request = PutCustomerCallbackRequest();
Expand All @@ -109,4 +109,11 @@ request.url = "https://qxd-wallet.com/ccup";
http.Response response = await kycService.putCustomerCallback(request);
print(response.status);
```
```



### Further readings

For more info, see also the class documentation of ```KYCService``` and the sdk's sep-0012 test cases.

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 network.
version: 1.1.7
version: 1.1.8
homepage: https://github.com/Soneso/stellar_flutter_sdk

environment:
Expand Down

0 comments on commit 27803fa

Please sign in to comment.