Skip to content

Commit

Permalink
add sep-0007 documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed Jul 28, 2022
1 parent aa0b47d commit 95555ea
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.3.4] - 28.July.2022.
- add SEP-0007 implementation

## [1.3.3] - 09.Mai.2022.
- protocol 19 support

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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.3.3
stellar_flutter_sdk: ^1.3.4
```
2. Install it (command line or IDE):
```
Expand Down Expand Up @@ -295,6 +295,7 @@ print(response.memo);
| [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-0007: URI Scheme to facilitate delegated signing](documentation/sdk_examples/sep-0007-urischeme.md) | In this examples you can see how to use the sdk to support SEP-0007 in your wallet.| [SEP-0007](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0007.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)|
Expand All @@ -312,6 +313,7 @@ You can find additional documentation including the API documentation in the [do
- [SEP-0002 (Federation)](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0002.md)
- [SEP-0005 (Key derivation)](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)
- [SEP-0007: URI Scheme to facilitate delegated signing](documentation/sdk_examples/sep-0007-urischeme.md)
- [SEP-0010 (Stellar Web Authentication)](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md)
- [SEP-0011 (Txrep)](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0011.md)
- [SEP-0012: KYC API](documentation/sdk_examples/sep-0012-kyc.md)
Expand Down
1 change: 1 addition & 0 deletions documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ The Soneso open source Stellar SDK for Flutter is build with Dart and provides A
| [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-0007: URI Scheme to facilitate delegated signing](sdk_examples/sep-0007-urischeme.md) | In this examples you can see how to use the sdk to support SEP-0007 in your wallet.| [SEP-0007](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0007.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)|
Expand Down
172 changes: 172 additions & 0 deletions documentation/sdk_examples/sep-0007-urischeme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@

### SEP-0007 - URI Scheme to facilitate delegated signing



URI Scheme to facilitate delegated signing is described in [SEP-0007](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0007.md). This Stellar Ecosystem Proposal introduces a URI Scheme that can be used to generate a URI that will serve as a request to sign a transaction. The URI (request) will typically be signed by the user’s trusted wallet where she stores her secret key(s).

This SDK provides utility features to facilitate the implementation of SEP-0007 in a Flutter Wallet. These features are implemented in the [URIScheme](https://github.com/Soneso/stellar_flutter_sdk/blob/master/lib/src/sep/0007/URIScheme.dart) class and are described below.

**Generate a transaction uri**

```dart
String generateSignTransactionURI(String transactionEnvelopeXdrBase64,
{String? replace,
String? callback,
String? publicKey,
String? chain,
String? message,
String? networkPassphrase,
String? originDomain,
String? signature})
```
This function can be used to generate a URIScheme compliant URL to serve as a request to sign a transaction.

Example:

```dart
AccountResponse sourceAccount = await sdk.accounts.account(accountId);
SetOptionsOperationBuilder setOp = SetOptionsOperationBuilder();
setOp.setSourceAccount(accountId);
setOp.setHomeDomain("www.soneso.com");
Transaction transaction =
TransactionBuilder(sourceAccount).addOperation(setOp.build()).build();
URIScheme uriScheme = URIScheme();
String url =
uriScheme.generateSignTransactionURI(transaction.toEnvelopeXdrBase64());
print(url);
// web+stellar:tx?xdr=AAAAAgAAAADNQvJCahsRijRFXMHgyGXdar95Wya9ONBFmFGORBZkWAAAAGQABwWpAAAAKwAAAAAAAAAAAAAAAQAAAAEAAAAAzULyQmobEYo0RVzB4Mhl3Wq%2FeVsmvTjQRZhRjkQWZFgAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAOd3d3LnNvbmVzby5jb20AAAAAAAAAAAAAAAAAAA%3D%3D
```

**Generate a pay operation uri**

```dart
String generatePayOperationURI(String destinationAccountId,
{String? amount,
String? assetCode,
String? assetIssuer,
String? memo,
String? memoType,
String? callback,
String? message,
String? networkPassphrase,
String? originDomain,
String? signature})
```

This function can be used to generate a URIScheme compliant URL to serve as a request to pay a specific address with a specific asset, regardless of the source asset used by the payer.

Example:

```dart
URIScheme uriScheme = URIScheme();
String url = uriScheme.generatePayOperationURI(accountId,
amount: "123.21",
assetCode: "ANA",
assetIssuer:
"GC4HC3AXQDNAMURMHVGMLFGLQELEQBCE4GI7IOKEAWAKBXY7SXXWBTLV");
print(url);
//web+stellar:pay?destination=GDGUF4SCNINRDCRUIVOMDYGIMXOWVP3ZLMTL2OGQIWMFDDSECZSFQMQV&amount=123.21&asset_code=ANA&asset_issuer=GC4HC3AXQDNAMURMHVGMLFGLQELEQBCE4GI7IOKEAWAKBXY7SXXWBTLV
```

**Check if URI Scheme is valid**
```dart
Future<bool> checkUIRSchemeIsValid(String url) async
```
Checks if the received SEP-0007 URL is valid; signature and domain must be present and correct for the signer's keypair.
Returns true if valid, otherwise throws the corresponding URISchemeError.

Example:

```dart
URIScheme uriScheme = URIScheme();
await uriScheme.checkUIRSchemeIsValid(url).then((response) {
// success
}).catchError((error) async {
if (error is URISchemeError &&
error.type == URISchemeError.tomlSignatureMissing){
// handle error
}
});
```

Possible URISchemeErrors are:

```dart
static const int invalidSignature = 0;
static const int invalidOriginDomain = 1;
static const int missingOriginDomain = 2;
static const int missingSignature = 3;
static const int tomlNotFoundOrInvalid = 4;
static const int tomlSignatureMissing = 5;
```

**Sign URI**

```dart
String signURI(String url, KeyPair signerKeypair)
```
Signs the URIScheme compliant SEP-0007 url with the signer's key pair. Returns the signed url having the signature parameter attached.
Be careful with this function, you should validate the url and ask the user for permission before using this function.

Example:

```dart
print(url);
// web+stellar:tx?xdr=AAAAAgAAAADNQvJCahsRijRFXMHgyGXdar95Wya9ONBFmFGORBZkWAAAAGQABwWpAAAAKwAAAAAAAAAAAAAAAQAAAAEAAAAAzULyQmobEYo0RVzB4Mhl3Wq%2FeVsmvTjQRZhRjkQWZFgAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAOd3d3LnNvbmVzby5jb20AAAAAAAAAAAAAAAAAAA%3D%3D&origin_domain=place.domain.com
URIScheme uriScheme = URIScheme();
url = uriScheme.signURI(url, signerKeyPair);
print(url);
// web+stellar:tx?xdr=AAAAAgAAAADNQvJCahsRijRFXMHgyGXdar95Wya9ONBFmFGORBZkWAAAAGQABwWpAAAAKwAAAAAAAAAAAAAAAQAAAAEAAAAAzULyQmobEYo0RVzB4Mhl3Wq%2FeVsmvTjQRZhRjkQWZFgAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAOd3d3LnNvbmVzby5jb20AAAAAAAAAAAAAAAAAAA%3D%3D&origin_domain=place.domain.com&signature=bIZ53bPKkNe0OoNK8PGLTnzHS%2FBCMzXTvwv1mc4DWc0XC4%2Bp197AmUB%2FIPL1UZAega7cLYv7%2F%2FaflB7CLGqZCw%3D%3D
```

**Sign and submit transaction**

```dart
Future<SubmitUriSchemeTransactionResponse> signAndSubmitTransaction(
String url, KeyPair signerKeyPair,
{Network? network}) async
```
Signs the given transaction and submits it to the callback url if available, otherwise it submits it to the stellar network.
Be careful with this function, you should validate the url and ask the user for permission before using this function.

Example:

```dart
URIScheme uriScheme = URIScheme();
SubmitUriSchemeTransactionResponse response = await uriScheme
.signAndSubmitTransaction(url, signerKeyPair, network: Network.TESTNET);
```

```SubmitUriSchemeTransactionResponse``` has two members: ```submitTransactionResponse``` and ```response```. ```submitTransactionResponse``` is filled if the transaction has been send to the stellar network. ```response``` is filled if the transaction has been sent to the callback.

```dart
class SubmitUriSchemeTransactionResponse {
SubmitTransactionResponse?
submitTransactionResponse; // if submitted to stellar
http.Response? response; // if submitted to callback
SubmitUriSchemeTransactionResponse(
this.submitTransactionResponse, this.response);
}
```

**Get parameter value**

```dart
String? getParameterValue(String name, String url)
```

Utility function that returns the value of the given url parameter from the specified SEP-0007 url.


**More examples**

You can find more examples in the [SEP-0007 Test Cases](https://github.com/Soneso/stellar_flutter_sdk/blob/master/test/sep0007_test.dart)
2 changes: 1 addition & 1 deletion lib/src/stellar_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import 'requests/liquidity_pools_request_builder.dart';

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

static final StellarSDK PUBLIC = StellarSDK("https://horizon.stellar.org");
static final StellarSDK TESTNET =
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 network.
version: 1.3.3
version: 1.3.4
homepage: https://github.com/Soneso/stellar_flutter_sdk

environment:
Expand Down

0 comments on commit 95555ea

Please sign in to comment.