From 350965429297e253ef51b3ef72ca1cc7f3fae8c5 Mon Sep 17 00:00:00 2001 From: Kirill Bubochkin Date: Mon, 29 Aug 2022 22:15:19 +0200 Subject: [PATCH] feat: implement remaining methods for wallet lib (#395) --- .gitattributes | 4 +- .github/workflows/check_pr.yml | 4 +- packages/sms_wallet/CHANGELOG.md | 3 - packages/sms_wallet/Makefile | 8 - packages/sms_wallet/README.md | 15 - packages/sms_wallet/android/settings.gradle | 1 - .../main/java/com/solana/sms_wallet/Api.java | 459 ----- .../com/solana/sms_wallet/ScenarioProxy.kt | 120 -- .../example/lib/mobile_wallet/bloc.dart | 116 -- .../lib/mobile_wallet/bloc.freezed.dart | 661 -------- .../example/lib/mobile_wallet/state.dart | 15 - packages/sms_wallet/lib/src/scenario.dart | 163 -- packages/sms_wallet/pigeons/api.dart | 90 - .../.gitignore | 0 .../.metadata | 0 packages/solana_mobile_wallet/CHANGELOG.md | 3 + .../LICENSE | 0 packages/solana_mobile_wallet/Makefile | 8 + packages/solana_mobile_wallet/README.md | 5 + .../analysis_options.yaml | 0 .../android/.gitignore | 0 .../android/build.gradle | 2 +- .../android/settings.gradle | 1 + .../android/src/main/AndroidManifest.xml | 2 +- .../com/solana/solana_mobile_wallet/Api.java | 1049 ++++++++++++ .../solana_mobile_wallet/ScenarioProxy.kt | 180 ++ .../SolanaMobileWalletPlugin.kt} | 6 +- .../example/.gitignore | 0 .../example/Makefile | 0 .../example/README.md | 4 +- .../example/analysis_options.yaml | 0 .../example/android/.gitignore | 0 .../example/android/app/build.gradle | 2 +- .../android/app/src/debug/AndroidManifest.xml | 2 +- .../android/app/src/main/AndroidManifest.xml | 4 +- .../MainActivity.kt | 2 +- .../res/drawable-v21/launch_background.xml | 0 .../main/res/drawable/launch_background.xml | 0 .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin .../app/src/main/res/values-night/styles.xml | 0 .../app/src/main/res/values/styles.xml | 0 .../app/src/profile/AndroidManifest.xml | 2 +- .../example/android/build.gradle | 0 .../example/android/gradle.properties | 0 .../gradle/wrapper/gradle-wrapper.properties | 0 .../example/android/settings.gradle | 0 .../example/lib/main.dart | 15 +- .../example/lib/mobile_wallet/bloc.dart | 254 +++ .../lib/mobile_wallet/bloc.freezed.dart | 1249 ++++++++++++++ .../example/lib/mobile_wallet/state.dart | 29 + .../example/lib/screens/auth_screen.dart | 4 +- .../lib/screens/send_transactions_screen.dart | 57 + .../lib/screens/sign_payloads_screen.dart | 74 + .../sign_transactions_for_sending.dart | 75 + .../example/pubspec.lock | 14 +- .../example/pubspec.yaml | 8 +- .../lib/solana_mobile_wallet.dart} | 2 + .../lib/src/api.dart | 314 ++++ .../lib/src/auth_issuer_config.dart | 0 .../lib/src/auth_issuer_config.freezed.dart | 0 .../lib/src/auth_issuer_config.g.dart | 0 .../lib/src/requests/authorize.dart | 0 .../lib/src/requests/authorize.freezed.dart | 0 .../lib/src/requests/reauthorize.dart | 0 .../lib/src/requests/reauthorize.freezed.dart | 0 .../requests/sign_and_send_transactions.dart | 43 + .../sign_and_send_transactions.freezed.dart | 1057 ++++++++++++ .../lib/src/requests/sign_transactions.dart | 51 + .../requests/sign_transactions.freezed.dart | 1483 +++++++++++++++++ .../lib/src/scenario.dart | 275 +++ .../src/solana_mobile_wallet_platform.dart} | 4 +- .../lib/src/wallet_config.dart | 0 .../lib/src/wallet_config.freezed.dart | 0 .../lib/src/wallet_config.g.dart | 0 .../solana_mobile_wallet/pigeons/api.dart | 267 +++ .../pubspec.yaml | 10 +- 80 files changed, 6525 insertions(+), 1691 deletions(-) delete mode 100644 packages/sms_wallet/CHANGELOG.md delete mode 100644 packages/sms_wallet/Makefile delete mode 100644 packages/sms_wallet/README.md delete mode 100644 packages/sms_wallet/android/settings.gradle delete mode 100644 packages/sms_wallet/android/src/main/java/com/solana/sms_wallet/Api.java delete mode 100644 packages/sms_wallet/android/src/main/kotlin/com/solana/sms_wallet/ScenarioProxy.kt delete mode 100644 packages/sms_wallet/example/lib/mobile_wallet/bloc.dart delete mode 100644 packages/sms_wallet/example/lib/mobile_wallet/bloc.freezed.dart delete mode 100644 packages/sms_wallet/example/lib/mobile_wallet/state.dart delete mode 100644 packages/sms_wallet/lib/src/scenario.dart delete mode 100644 packages/sms_wallet/pigeons/api.dart rename packages/{sms_wallet => solana_mobile_wallet}/.gitignore (100%) rename packages/{sms_wallet => solana_mobile_wallet}/.metadata (100%) create mode 100644 packages/solana_mobile_wallet/CHANGELOG.md rename packages/{sms_wallet => solana_mobile_wallet}/LICENSE (100%) create mode 100644 packages/solana_mobile_wallet/Makefile create mode 100644 packages/solana_mobile_wallet/README.md rename packages/{sms_wallet => solana_mobile_wallet}/analysis_options.yaml (100%) rename packages/{sms_wallet => solana_mobile_wallet}/android/.gitignore (100%) rename packages/{sms_wallet => solana_mobile_wallet}/android/build.gradle (96%) create mode 100644 packages/solana_mobile_wallet/android/settings.gradle rename packages/{sms_wallet => solana_mobile_wallet}/android/src/main/AndroidManifest.xml (64%) create mode 100644 packages/solana_mobile_wallet/android/src/main/java/com/solana/solana_mobile_wallet/Api.java create mode 100644 packages/solana_mobile_wallet/android/src/main/kotlin/com/solana/solana_mobile_wallet/ScenarioProxy.kt rename packages/{sms_wallet/android/src/main/kotlin/com/solana/sms_wallet/SmsWalletPlugin.kt => solana_mobile_wallet/android/src/main/kotlin/com/solana/solana_mobile_wallet/SolanaMobileWalletPlugin.kt} (95%) rename packages/{sms_wallet => solana_mobile_wallet}/example/.gitignore (100%) rename packages/{sms_wallet => solana_mobile_wallet}/example/Makefile (100%) rename packages/{sms_wallet => solana_mobile_wallet}/example/README.md (85%) rename packages/{sms_wallet => solana_mobile_wallet}/example/analysis_options.yaml (100%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/.gitignore (100%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/app/build.gradle (97%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/app/src/debug/AndroidManifest.xml (87%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/app/src/main/AndroidManifest.xml (95%) rename packages/{sms_wallet/example/android/app/src/main/kotlin/com/solana/sms_wallet_example => solana_mobile_wallet/example/android/app/src/main/kotlin/com/solana/solana_mobile_wallet_example}/MainActivity.kt (66%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/app/src/main/res/drawable-v21/launch_background.xml (100%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/app/src/main/res/drawable/launch_background.xml (100%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png (100%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png (100%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png (100%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png (100%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png (100%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/app/src/main/res/values-night/styles.xml (100%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/app/src/main/res/values/styles.xml (100%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/app/src/profile/AndroidManifest.xml (87%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/build.gradle (100%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/gradle.properties (100%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/gradle/wrapper/gradle-wrapper.properties (100%) rename packages/{sms_wallet => solana_mobile_wallet}/example/android/settings.gradle (100%) rename packages/{sms_wallet => solana_mobile_wallet}/example/lib/main.dart (57%) create mode 100644 packages/solana_mobile_wallet/example/lib/mobile_wallet/bloc.dart create mode 100644 packages/solana_mobile_wallet/example/lib/mobile_wallet/bloc.freezed.dart create mode 100644 packages/solana_mobile_wallet/example/lib/mobile_wallet/state.dart rename packages/{sms_wallet => solana_mobile_wallet}/example/lib/screens/auth_screen.dart (94%) create mode 100644 packages/solana_mobile_wallet/example/lib/screens/send_transactions_screen.dart create mode 100644 packages/solana_mobile_wallet/example/lib/screens/sign_payloads_screen.dart create mode 100644 packages/solana_mobile_wallet/example/lib/screens/sign_transactions_for_sending.dart rename packages/{sms_wallet => solana_mobile_wallet}/example/pubspec.lock (99%) rename packages/{sms_wallet => solana_mobile_wallet}/example/pubspec.yaml (74%) rename packages/{sms_wallet/lib/sms_wallet.dart => solana_mobile_wallet/lib/solana_mobile_wallet.dart} (63%) rename packages/{sms_wallet => solana_mobile_wallet}/lib/src/api.dart (55%) rename packages/{sms_wallet => solana_mobile_wallet}/lib/src/auth_issuer_config.dart (100%) rename packages/{sms_wallet => solana_mobile_wallet}/lib/src/auth_issuer_config.freezed.dart (100%) rename packages/{sms_wallet => solana_mobile_wallet}/lib/src/auth_issuer_config.g.dart (100%) rename packages/{sms_wallet => solana_mobile_wallet}/lib/src/requests/authorize.dart (100%) rename packages/{sms_wallet => solana_mobile_wallet}/lib/src/requests/authorize.freezed.dart (100%) rename packages/{sms_wallet => solana_mobile_wallet}/lib/src/requests/reauthorize.dart (100%) rename packages/{sms_wallet => solana_mobile_wallet}/lib/src/requests/reauthorize.freezed.dart (100%) create mode 100644 packages/solana_mobile_wallet/lib/src/requests/sign_and_send_transactions.dart create mode 100644 packages/solana_mobile_wallet/lib/src/requests/sign_and_send_transactions.freezed.dart create mode 100644 packages/solana_mobile_wallet/lib/src/requests/sign_transactions.dart create mode 100644 packages/solana_mobile_wallet/lib/src/requests/sign_transactions.freezed.dart create mode 100644 packages/solana_mobile_wallet/lib/src/scenario.dart rename packages/{sms_wallet/lib/src/sms_wallet_platform.dart => solana_mobile_wallet/lib/src/solana_mobile_wallet_platform.dart} (84%) rename packages/{sms_wallet => solana_mobile_wallet}/lib/src/wallet_config.dart (100%) rename packages/{sms_wallet => solana_mobile_wallet}/lib/src/wallet_config.freezed.dart (100%) rename packages/{sms_wallet => solana_mobile_wallet}/lib/src/wallet_config.g.dart (100%) create mode 100644 packages/solana_mobile_wallet/pigeons/api.dart rename packages/{sms_wallet => solana_mobile_wallet}/pubspec.yaml (51%) diff --git a/.gitattributes b/.gitattributes index 140380bf1a..9057270c65 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,4 @@ *.g.dart linguist-generated=true *.freezed.dart linguist-generated=true -/packages/sms_wallet/android/src/main/java/com/solana/sms_wallet/Api.java linguist-generated=true -/packages/sms_wallet/lib/src/api.dart linguist-generated=true +/packages/solana_mobile_wallet/android/src/main/java/com/solana/solana_mobile_wallet/Api.java linguist-generated=true +/packages/solana_mobile_wallet/lib/src/api.dart linguist-generated=true diff --git a/.github/workflows/check_pr.yml b/.github/workflows/check_pr.yml index 18e428716a..686be3715d 100644 --- a/.github/workflows/check_pr.yml +++ b/.github/workflows/check_pr.yml @@ -106,11 +106,11 @@ jobs: with: flags: solana-${{ matrix.solanaVersion }} - sms_wallet: + solana_mobile_wallet: needs: [formatting] runs-on: ubuntu-latest env: - SCOPE: --scope="sms_wallet*" + SCOPE: --scope="solana_mobile_wallet*" steps: - uses: actions/checkout@v2 diff --git a/packages/sms_wallet/CHANGELOG.md b/packages/sms_wallet/CHANGELOG.md deleted file mode 100644 index 41cc7d8192..0000000000 --- a/packages/sms_wallet/CHANGELOG.md +++ /dev/null @@ -1,3 +0,0 @@ -## 0.0.1 - -* TODO: Describe initial release. diff --git a/packages/sms_wallet/Makefile b/packages/sms_wallet/Makefile deleted file mode 100644 index c5cddbf37c..0000000000 --- a/packages/sms_wallet/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -include ../../Makefile - -pigeon: - flutter pub run pigeon \ - --input pigeons/api.dart \ - --dart_out lib/src/api.dart \ - --java_out ./android/src/main/java/com/solana/sms_wallet/Api.java \ - --java_package "com.solana.sms_wallet" diff --git a/packages/sms_wallet/README.md b/packages/sms_wallet/README.md deleted file mode 100644 index 3b51d2db58..0000000000 --- a/packages/sms_wallet/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# sms_wallet - -A new Flutter plugin project. - -## Getting Started - -This project is a starting point for a Flutter -[plug-in package](https://flutter.dev/developing-packages/), -a specialized package that includes platform-specific implementation code for -Android and/or iOS. - -For help getting started with Flutter development, view the -[online documentation](https://flutter.dev/docs), which offers tutorials, -samples, guidance on mobile development, and a full API reference. - diff --git a/packages/sms_wallet/android/settings.gradle b/packages/sms_wallet/android/settings.gradle deleted file mode 100644 index 55a5df902a..0000000000 --- a/packages/sms_wallet/android/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'sms_wallet' diff --git a/packages/sms_wallet/android/src/main/java/com/solana/sms_wallet/Api.java b/packages/sms_wallet/android/src/main/java/com/solana/sms_wallet/Api.java deleted file mode 100644 index 91bf6ee1c8..0000000000 --- a/packages/sms_wallet/android/src/main/java/com/solana/sms_wallet/Api.java +++ /dev/null @@ -1,459 +0,0 @@ -// Autogenerated from Pigeon (v3.2.6), do not edit directly. -// See also: https://pub.dev/packages/pigeon - -package com.solana.sms_wallet; - -import android.util.Log; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import io.flutter.plugin.common.BasicMessageChannel; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugin.common.MessageCodec; -import io.flutter.plugin.common.StandardMessageCodec; -import java.io.ByteArrayOutputStream; -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.HashMap; - -/** Generated class from Pigeon. */ -@SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"}) -public class Api { - - /** Generated class from Pigeon that represents data sent in messages. */ - public static class AuthorizeRequestDto { - private @Nullable String identityName; - public @Nullable String getIdentityName() { return identityName; } - public void setIdentityName(@Nullable String setterArg) { - this.identityName = setterArg; - } - - private @Nullable String identityUri; - public @Nullable String getIdentityUri() { return identityUri; } - public void setIdentityUri(@Nullable String setterArg) { - this.identityUri = setterArg; - } - - private @Nullable String iconUri; - public @Nullable String getIconUri() { return iconUri; } - public void setIconUri(@Nullable String setterArg) { - this.iconUri = setterArg; - } - - public static final class Builder { - private @Nullable String identityName; - public @NonNull Builder setIdentityName(@Nullable String setterArg) { - this.identityName = setterArg; - return this; - } - private @Nullable String identityUri; - public @NonNull Builder setIdentityUri(@Nullable String setterArg) { - this.identityUri = setterArg; - return this; - } - private @Nullable String iconUri; - public @NonNull Builder setIconUri(@Nullable String setterArg) { - this.iconUri = setterArg; - return this; - } - public @NonNull AuthorizeRequestDto build() { - AuthorizeRequestDto pigeonReturn = new AuthorizeRequestDto(); - pigeonReturn.setIdentityName(identityName); - pigeonReturn.setIdentityUri(identityUri); - pigeonReturn.setIconUri(iconUri); - return pigeonReturn; - } - } - @NonNull Map toMap() { - Map toMapResult = new HashMap<>(); - toMapResult.put("identityName", identityName); - toMapResult.put("identityUri", identityUri); - toMapResult.put("iconUri", iconUri); - return toMapResult; - } - static @NonNull AuthorizeRequestDto fromMap(@NonNull Map map) { - AuthorizeRequestDto pigeonResult = new AuthorizeRequestDto(); - Object identityName = map.get("identityName"); - pigeonResult.setIdentityName((String)identityName); - Object identityUri = map.get("identityUri"); - pigeonResult.setIdentityUri((String)identityUri); - Object iconUri = map.get("iconUri"); - pigeonResult.setIconUri((String)iconUri); - return pigeonResult; - } - } - - /** Generated class from Pigeon that represents data sent in messages. */ - public static class AuthorizeResultDto { - private @NonNull byte[] publicKey; - public @NonNull byte[] getPublicKey() { return publicKey; } - public void setPublicKey(@NonNull byte[] setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"publicKey\" is null."); - } - this.publicKey = setterArg; - } - - private @Nullable String accountLabel; - public @Nullable String getAccountLabel() { return accountLabel; } - public void setAccountLabel(@Nullable String setterArg) { - this.accountLabel = setterArg; - } - - private @Nullable String walletUriBase; - public @Nullable String getWalletUriBase() { return walletUriBase; } - public void setWalletUriBase(@Nullable String setterArg) { - this.walletUriBase = setterArg; - } - - private @Nullable byte[] scope; - public @Nullable byte[] getScope() { return scope; } - public void setScope(@Nullable byte[] setterArg) { - this.scope = setterArg; - } - - /** Constructor is private to enforce null safety; use Builder. */ - private AuthorizeResultDto() {} - public static final class Builder { - private @Nullable byte[] publicKey; - public @NonNull Builder setPublicKey(@NonNull byte[] setterArg) { - this.publicKey = setterArg; - return this; - } - private @Nullable String accountLabel; - public @NonNull Builder setAccountLabel(@Nullable String setterArg) { - this.accountLabel = setterArg; - return this; - } - private @Nullable String walletUriBase; - public @NonNull Builder setWalletUriBase(@Nullable String setterArg) { - this.walletUriBase = setterArg; - return this; - } - private @Nullable byte[] scope; - public @NonNull Builder setScope(@Nullable byte[] setterArg) { - this.scope = setterArg; - return this; - } - public @NonNull AuthorizeResultDto build() { - AuthorizeResultDto pigeonReturn = new AuthorizeResultDto(); - pigeonReturn.setPublicKey(publicKey); - pigeonReturn.setAccountLabel(accountLabel); - pigeonReturn.setWalletUriBase(walletUriBase); - pigeonReturn.setScope(scope); - return pigeonReturn; - } - } - @NonNull Map toMap() { - Map toMapResult = new HashMap<>(); - toMapResult.put("publicKey", publicKey); - toMapResult.put("accountLabel", accountLabel); - toMapResult.put("walletUriBase", walletUriBase); - toMapResult.put("scope", scope); - return toMapResult; - } - static @NonNull AuthorizeResultDto fromMap(@NonNull Map map) { - AuthorizeResultDto pigeonResult = new AuthorizeResultDto(); - Object publicKey = map.get("publicKey"); - pigeonResult.setPublicKey((byte[])publicKey); - Object accountLabel = map.get("accountLabel"); - pigeonResult.setAccountLabel((String)accountLabel); - Object walletUriBase = map.get("walletUriBase"); - pigeonResult.setWalletUriBase((String)walletUriBase); - Object scope = map.get("scope"); - pigeonResult.setScope((byte[])scope); - return pigeonResult; - } - } - - /** Generated class from Pigeon that represents data sent in messages. */ - public static class ReauthorizeRequestDto { - private @Nullable String identityName; - public @Nullable String getIdentityName() { return identityName; } - public void setIdentityName(@Nullable String setterArg) { - this.identityName = setterArg; - } - - private @Nullable String identityUri; - public @Nullable String getIdentityUri() { return identityUri; } - public void setIdentityUri(@Nullable String setterArg) { - this.identityUri = setterArg; - } - - private @Nullable String iconRelativeUri; - public @Nullable String getIconRelativeUri() { return iconRelativeUri; } - public void setIconRelativeUri(@Nullable String setterArg) { - this.iconRelativeUri = setterArg; - } - - private @NonNull String cluster; - public @NonNull String getCluster() { return cluster; } - public void setCluster(@NonNull String setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"cluster\" is null."); - } - this.cluster = setterArg; - } - - private @NonNull byte[] authorizationScope; - public @NonNull byte[] getAuthorizationScope() { return authorizationScope; } - public void setAuthorizationScope(@NonNull byte[] setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"authorizationScope\" is null."); - } - this.authorizationScope = setterArg; - } - - /** Constructor is private to enforce null safety; use Builder. */ - private ReauthorizeRequestDto() {} - public static final class Builder { - private @Nullable String identityName; - public @NonNull Builder setIdentityName(@Nullable String setterArg) { - this.identityName = setterArg; - return this; - } - private @Nullable String identityUri; - public @NonNull Builder setIdentityUri(@Nullable String setterArg) { - this.identityUri = setterArg; - return this; - } - private @Nullable String iconRelativeUri; - public @NonNull Builder setIconRelativeUri(@Nullable String setterArg) { - this.iconRelativeUri = setterArg; - return this; - } - private @Nullable String cluster; - public @NonNull Builder setCluster(@NonNull String setterArg) { - this.cluster = setterArg; - return this; - } - private @Nullable byte[] authorizationScope; - public @NonNull Builder setAuthorizationScope(@NonNull byte[] setterArg) { - this.authorizationScope = setterArg; - return this; - } - public @NonNull ReauthorizeRequestDto build() { - ReauthorizeRequestDto pigeonReturn = new ReauthorizeRequestDto(); - pigeonReturn.setIdentityName(identityName); - pigeonReturn.setIdentityUri(identityUri); - pigeonReturn.setIconRelativeUri(iconRelativeUri); - pigeonReturn.setCluster(cluster); - pigeonReturn.setAuthorizationScope(authorizationScope); - return pigeonReturn; - } - } - @NonNull Map toMap() { - Map toMapResult = new HashMap<>(); - toMapResult.put("identityName", identityName); - toMapResult.put("identityUri", identityUri); - toMapResult.put("iconRelativeUri", iconRelativeUri); - toMapResult.put("cluster", cluster); - toMapResult.put("authorizationScope", authorizationScope); - return toMapResult; - } - static @NonNull ReauthorizeRequestDto fromMap(@NonNull Map map) { - ReauthorizeRequestDto pigeonResult = new ReauthorizeRequestDto(); - Object identityName = map.get("identityName"); - pigeonResult.setIdentityName((String)identityName); - Object identityUri = map.get("identityUri"); - pigeonResult.setIdentityUri((String)identityUri); - Object iconRelativeUri = map.get("iconRelativeUri"); - pigeonResult.setIconRelativeUri((String)iconRelativeUri); - Object cluster = map.get("cluster"); - pigeonResult.setCluster((String)cluster); - Object authorizationScope = map.get("authorizationScope"); - pigeonResult.setAuthorizationScope((byte[])authorizationScope); - return pigeonResult; - } - } - private static class ApiFlutterCodec extends StandardMessageCodec { - public static final ApiFlutterCodec INSTANCE = new ApiFlutterCodec(); - private ApiFlutterCodec() {} - @Override - protected Object readValueOfType(byte type, ByteBuffer buffer) { - switch (type) { - case (byte)128: - return AuthorizeRequestDto.fromMap((Map) readValue(buffer)); - - case (byte)129: - return AuthorizeResultDto.fromMap((Map) readValue(buffer)); - - case (byte)130: - return ReauthorizeRequestDto.fromMap((Map) readValue(buffer)); - - default: - return super.readValueOfType(type, buffer); - - } - } - @Override - protected void writeValue(ByteArrayOutputStream stream, Object value) { - if (value instanceof AuthorizeRequestDto) { - stream.write(128); - writeValue(stream, ((AuthorizeRequestDto) value).toMap()); - } else - if (value instanceof AuthorizeResultDto) { - stream.write(129); - writeValue(stream, ((AuthorizeResultDto) value).toMap()); - } else - if (value instanceof ReauthorizeRequestDto) { - stream.write(130); - writeValue(stream, ((ReauthorizeRequestDto) value).toMap()); - } else -{ - super.writeValue(stream, value); - } - } - } - - /** Generated class from Pigeon that represents Flutter messages that can be called from Java.*/ - public static class ApiFlutter { - private final BinaryMessenger binaryMessenger; - public ApiFlutter(BinaryMessenger argBinaryMessenger){ - this.binaryMessenger = argBinaryMessenger; - } - public interface Reply { - void reply(T reply); - } - static MessageCodec getCodec() { - return ApiFlutterCodec.INSTANCE; - } - - public void onScenarioReady(@NonNull Long idArg, Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.onScenarioReady", getCodec()); - channel.send(new ArrayList(Arrays.asList(idArg)), channelReply -> { - callback.reply(null); - }); - } - public void onScenarioServingClients(@NonNull Long idArg, Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.onScenarioServingClients", getCodec()); - channel.send(new ArrayList(Arrays.asList(idArg)), channelReply -> { - callback.reply(null); - }); - } - public void onScenarioServingComplete(@NonNull Long idArg, Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.onScenarioServingComplete", getCodec()); - channel.send(new ArrayList(Arrays.asList(idArg)), channelReply -> { - callback.reply(null); - }); - } - public void onScenarioComplete(@NonNull Long idArg, Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.onScenarioComplete", getCodec()); - channel.send(new ArrayList(Arrays.asList(idArg)), channelReply -> { - callback.reply(null); - }); - } - public void onScenarioError(@NonNull Long idArg, Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.onScenarioError", getCodec()); - channel.send(new ArrayList(Arrays.asList(idArg)), channelReply -> { - callback.reply(null); - }); - } - public void onScenarioTeardownComplete(@NonNull Long idArg, Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.onScenarioTeardownComplete", getCodec()); - channel.send(new ArrayList(Arrays.asList(idArg)), channelReply -> { - callback.reply(null); - }); - } - public void authorize(@NonNull AuthorizeRequestDto requestArg, @NonNull Long idArg, Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.authorize", getCodec()); - channel.send(new ArrayList(Arrays.asList(requestArg, idArg)), channelReply -> { - @SuppressWarnings("ConstantConditions") - AuthorizeResultDto output = (AuthorizeResultDto)channelReply; - callback.reply(output); - }); - } - public void reauthorize(@NonNull ReauthorizeRequestDto requestArg, @NonNull Long idArg, Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.reauthorize", getCodec()); - channel.send(new ArrayList(Arrays.asList(requestArg, idArg)), channelReply -> { - @SuppressWarnings("ConstantConditions") - Boolean output = (Boolean)channelReply; - callback.reply(output); - }); - } - } - private static class ApiHostCodec extends StandardMessageCodec { - public static final ApiHostCodec INSTANCE = new ApiHostCodec(); - private ApiHostCodec() {} - } - - /** Generated interface from Pigeon that represents a handler of messages from Flutter.*/ - public interface ApiHost { - void start(@NonNull Long id); - void close(@NonNull Long id); - - /** The codec used by ApiHost. */ - static MessageCodec getCodec() { - return ApiHostCodec.INSTANCE; - } - - /** Sets up an instance of `ApiHost` to handle messages through the `binaryMessenger`. */ - static void setup(BinaryMessenger binaryMessenger, ApiHost api) { - { - BasicMessageChannel channel = - new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiHost.start", getCodec()); - if (api != null) { - channel.setMessageHandler((message, reply) -> { - Map wrapped = new HashMap<>(); - try { - ArrayList args = (ArrayList)message; - Number idArg = (Number)args.get(0); - if (idArg == null) { - throw new NullPointerException("idArg unexpectedly null."); - } - api.start((idArg == null) ? null : idArg.longValue()); - wrapped.put("result", null); - } - catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiHost.close", getCodec()); - if (api != null) { - channel.setMessageHandler((message, reply) -> { - Map wrapped = new HashMap<>(); - try { - ArrayList args = (ArrayList)message; - Number idArg = (Number)args.get(0); - if (idArg == null) { - throw new NullPointerException("idArg unexpectedly null."); - } - api.close((idArg == null) ? null : idArg.longValue()); - wrapped.put("result", null); - } - catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } - private static Map wrapError(Throwable exception) { - Map errorMap = new HashMap<>(); - errorMap.put("message", exception.toString()); - errorMap.put("code", exception.getClass().getSimpleName()); - errorMap.put("details", "Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception)); - return errorMap; - } -} diff --git a/packages/sms_wallet/android/src/main/kotlin/com/solana/sms_wallet/ScenarioProxy.kt b/packages/sms_wallet/android/src/main/kotlin/com/solana/sms_wallet/ScenarioProxy.kt deleted file mode 100644 index 79c2e61b4d..0000000000 --- a/packages/sms_wallet/android/src/main/kotlin/com/solana/sms_wallet/ScenarioProxy.kt +++ /dev/null @@ -1,120 +0,0 @@ -package com.solana.sms_wallet - -import android.net.Uri -import android.os.Handler -import android.os.Looper -import com.solana.mobilewalletadapter.walletlib.scenario.* -import io.flutter.plugin.common.BinaryMessenger - -object ApiHost : Api.ApiHost { - private val scenarios = mutableMapOf() - - fun init(binaryMessenger: BinaryMessenger) { - Api.ApiHost.setup(binaryMessenger, this) - } - - fun register(id: Long, scenario: Scenario) { - scenarios[id] = scenario - } - - fun unregister(id: Long) { - scenarios.remove(id) - } - - override fun start(id: Long) { - scenarios[id]?.start() - } - - override fun close(id: Long) { - scenarios[id]?.close() - } -} - -class Callbacks( - private val id: Long, - binaryMessenger: BinaryMessenger, - private val onTeardownComplete: () -> Unit -) : Scenario.Callbacks { - private val api = Api.ApiFlutter(binaryMessenger) - - override fun onScenarioReady() { - Handler(Looper.getMainLooper()).post { api.onScenarioReady(id) {} } - } - - override fun onScenarioServingClients() { - Handler(Looper.getMainLooper()).post { api.onScenarioServingClients(id) {} } - } - - override fun onScenarioServingComplete() { - Handler(Looper.getMainLooper()).post { api.onScenarioServingComplete(id) {} } - } - - override fun onScenarioComplete() { - Handler(Looper.getMainLooper()).post { api.onScenarioComplete(id) {} } - } - - override fun onScenarioError() { - Handler(Looper.getMainLooper()).post { api.onScenarioError(id) {} } - } - - override fun onScenarioTeardownComplete() { - Handler(Looper.getMainLooper()).post { api.onScenarioTeardownComplete(id) {} } - onTeardownComplete() - } - - override fun onAuthorizeRequest(request: AuthorizeRequest) { - val dto = Api.AuthorizeRequestDto.Builder() - .setIconUri(request.iconRelativeUri?.toString()) - .setIdentityName(request.identityName) - .setIdentityUri(request.identityUri?.toString()) - .build() - - Handler(Looper.getMainLooper()).post { - api.authorize(dto, id) { result -> - if (result == null) { - request.completeWithDecline() - } else { - request.completeWithAuthorize( - result.publicKey, - result.accountLabel, - if (result.walletUriBase == null) null else Uri.parse(result.walletUriBase), - result.scope, - ) - } - } - } - } - - override fun onReauthorizeRequest(request: ReauthorizeRequest) { - val dto = Api.ReauthorizeRequestDto.Builder() - .setIdentityName(request.identityName) - .setIdentityUri(request.identityUri?.toString()) - .setIconRelativeUri(request.iconRelativeUri?.toString()) - .setCluster(request.cluster) - .setAuthorizationScope(request.authorizationScope) - .build() - - Handler(Looper.getMainLooper()).post { - api.reauthorize(dto, id) { result -> - if (result == true) { - request.completeWithReauthorize() - } else { - request.completeWithDecline() - } - } - } - } - - override fun onSignTransactionsRequest(request: SignTransactionsRequest) { - - } - - override fun onSignMessagesRequest(request: SignMessagesRequest) { - - } - - override fun onSignAndSendTransactionsRequest(request: SignAndSendTransactionsRequest) { - - } - -} \ No newline at end of file diff --git a/packages/sms_wallet/example/lib/mobile_wallet/bloc.dart b/packages/sms_wallet/example/lib/mobile_wallet/bloc.dart deleted file mode 100644 index e3537ad983..0000000000 --- a/packages/sms_wallet/example/lib/mobile_wallet/bloc.dart +++ /dev/null @@ -1,116 +0,0 @@ -import 'dart:async'; -import 'dart:convert'; -import 'dart:typed_data'; - -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:sms_wallet/sms_wallet.dart'; -import 'package:solana/solana.dart'; - -part 'bloc.freezed.dart'; - -part 'state.dart'; - -class MobileWalletBloc extends Cubit - implements ScenarioCallbacks { - MobileWalletBloc() : super(const MobileWalletState.none()) { - _init(); - } - - Scenario? _scenario; - Completer? _completer; - - Future _init() async { - _scenario = await Scenario.create( - walletConfig: const MobileWalletAdapterConfig( - supportsSignAndSendTransactions: true, - maxTransactionsPerSigningRequest: 10, - maxMessagesPerSigningRequest: 10, - ), - issuerConfig: const AuthIssuerConfig(name: 'example_wallet'), - callbacks: this, - ); - - _scenario?.start(); - } - - Future authorizeDapp({ - required bool isAuthorized, - required String scopeTag, - required String? qualifier, - }) async { - final request = - state.whenOrNull(remote: (r) => r)?.whenOrNull(authorizeDapp: (r) => r); - - if (request == null) return; - - if (isAuthorized) { - _completer?.complete( - AuthorizeResult( - publicKey: Uint8List.fromList( - (await Ed25519HDKeyPair.random()).publicKey.bytes, - ), - accountLabel: 'FlutterWallet', - walletUriBase: null, - scope: Uint8List.fromList( - utf8.encode([scopeTag, qualifier].whereType().join(',')), - ), - ), - ); - } else { - _completer?.complete(null); - } - } - - void _cancelCurrentRequest() { - _completer?.complete(null); - _completer = null; - } - - Future _createNewRequest() { - final c = Completer(); - _completer = c; - - return c.future; - } - - @override - Future onAuthorizeRequest(AuthorizeRequest request) { - _cancelCurrentRequest(); - - emit( - MobileWalletState.remote(RemoteRequest.authorizeDapp(request: request)), - ); - - return _createNewRequest(); - } - - @override - Future onReauthorizeRequest(ReauthorizeRequest request) async { - _cancelCurrentRequest(); - - return true; - } - - @override - void onScenarioComplete() {} - - @override - void onScenarioError() {} - - @override - void onScenarioReady() {} - - @override - void onScenarioServingClients() {} - - @override - void onScenarioServingComplete() { - _scenario?.close(); - } - - @override - void onScenarioTeardownComplete() { - emit(const MobileWalletState.sessionTerminated()); - } -} diff --git a/packages/sms_wallet/example/lib/mobile_wallet/bloc.freezed.dart b/packages/sms_wallet/example/lib/mobile_wallet/bloc.freezed.dart deleted file mode 100644 index e5c8909c7b..0000000000 --- a/packages/sms_wallet/example/lib/mobile_wallet/bloc.freezed.dart +++ /dev/null @@ -1,661 +0,0 @@ -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target - -part of 'bloc.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); - -/// @nodoc -mixin _$MobileWalletState { - @optionalTypeArgs - TResult when({ - required TResult Function() none, - required TResult Function() sessionTerminated, - required TResult Function(RemoteRequest request) remote, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult Function()? none, - TResult Function()? sessionTerminated, - TResult Function(RemoteRequest request)? remote, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? none, - TResult Function()? sessionTerminated, - TResult Function(RemoteRequest request)? remote, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(None value) none, - required TResult Function(SessionTerminated value) sessionTerminated, - required TResult Function(Remote value) remote, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult Function(None value)? none, - TResult Function(SessionTerminated value)? sessionTerminated, - TResult Function(Remote value)? remote, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(None value)? none, - TResult Function(SessionTerminated value)? sessionTerminated, - TResult Function(Remote value)? remote, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $MobileWalletStateCopyWith<$Res> { - factory $MobileWalletStateCopyWith( - MobileWalletState value, $Res Function(MobileWalletState) then) = - _$MobileWalletStateCopyWithImpl<$Res>; -} - -/// @nodoc -class _$MobileWalletStateCopyWithImpl<$Res> - implements $MobileWalletStateCopyWith<$Res> { - _$MobileWalletStateCopyWithImpl(this._value, this._then); - - final MobileWalletState _value; - // ignore: unused_field - final $Res Function(MobileWalletState) _then; -} - -/// @nodoc -abstract class _$$NoneCopyWith<$Res> { - factory _$$NoneCopyWith(_$None value, $Res Function(_$None) then) = - __$$NoneCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$NoneCopyWithImpl<$Res> extends _$MobileWalletStateCopyWithImpl<$Res> - implements _$$NoneCopyWith<$Res> { - __$$NoneCopyWithImpl(_$None _value, $Res Function(_$None) _then) - : super(_value, (v) => _then(v as _$None)); - - @override - _$None get _value => super._value as _$None; -} - -/// @nodoc - -class _$None implements None { - const _$None(); - - @override - String toString() { - return 'MobileWalletState.none()'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$None); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() none, - required TResult Function() sessionTerminated, - required TResult Function(RemoteRequest request) remote, - }) { - return none(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult Function()? none, - TResult Function()? sessionTerminated, - TResult Function(RemoteRequest request)? remote, - }) { - return none?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? none, - TResult Function()? sessionTerminated, - TResult Function(RemoteRequest request)? remote, - required TResult orElse(), - }) { - if (none != null) { - return none(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(None value) none, - required TResult Function(SessionTerminated value) sessionTerminated, - required TResult Function(Remote value) remote, - }) { - return none(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult Function(None value)? none, - TResult Function(SessionTerminated value)? sessionTerminated, - TResult Function(Remote value)? remote, - }) { - return none?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(None value)? none, - TResult Function(SessionTerminated value)? sessionTerminated, - TResult Function(Remote value)? remote, - required TResult orElse(), - }) { - if (none != null) { - return none(this); - } - return orElse(); - } -} - -abstract class None implements MobileWalletState { - const factory None() = _$None; -} - -/// @nodoc -abstract class _$$SessionTerminatedCopyWith<$Res> { - factory _$$SessionTerminatedCopyWith( - _$SessionTerminated value, $Res Function(_$SessionTerminated) then) = - __$$SessionTerminatedCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$SessionTerminatedCopyWithImpl<$Res> - extends _$MobileWalletStateCopyWithImpl<$Res> - implements _$$SessionTerminatedCopyWith<$Res> { - __$$SessionTerminatedCopyWithImpl( - _$SessionTerminated _value, $Res Function(_$SessionTerminated) _then) - : super(_value, (v) => _then(v as _$SessionTerminated)); - - @override - _$SessionTerminated get _value => super._value as _$SessionTerminated; -} - -/// @nodoc - -class _$SessionTerminated implements SessionTerminated { - const _$SessionTerminated(); - - @override - String toString() { - return 'MobileWalletState.sessionTerminated()'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$SessionTerminated); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() none, - required TResult Function() sessionTerminated, - required TResult Function(RemoteRequest request) remote, - }) { - return sessionTerminated(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult Function()? none, - TResult Function()? sessionTerminated, - TResult Function(RemoteRequest request)? remote, - }) { - return sessionTerminated?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? none, - TResult Function()? sessionTerminated, - TResult Function(RemoteRequest request)? remote, - required TResult orElse(), - }) { - if (sessionTerminated != null) { - return sessionTerminated(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(None value) none, - required TResult Function(SessionTerminated value) sessionTerminated, - required TResult Function(Remote value) remote, - }) { - return sessionTerminated(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult Function(None value)? none, - TResult Function(SessionTerminated value)? sessionTerminated, - TResult Function(Remote value)? remote, - }) { - return sessionTerminated?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(None value)? none, - TResult Function(SessionTerminated value)? sessionTerminated, - TResult Function(Remote value)? remote, - required TResult orElse(), - }) { - if (sessionTerminated != null) { - return sessionTerminated(this); - } - return orElse(); - } -} - -abstract class SessionTerminated implements MobileWalletState { - const factory SessionTerminated() = _$SessionTerminated; -} - -/// @nodoc -abstract class _$$RemoteCopyWith<$Res> { - factory _$$RemoteCopyWith(_$Remote value, $Res Function(_$Remote) then) = - __$$RemoteCopyWithImpl<$Res>; - $Res call({RemoteRequest request}); - - $RemoteRequestCopyWith<$Res> get request; -} - -/// @nodoc -class __$$RemoteCopyWithImpl<$Res> extends _$MobileWalletStateCopyWithImpl<$Res> - implements _$$RemoteCopyWith<$Res> { - __$$RemoteCopyWithImpl(_$Remote _value, $Res Function(_$Remote) _then) - : super(_value, (v) => _then(v as _$Remote)); - - @override - _$Remote get _value => super._value as _$Remote; - - @override - $Res call({ - Object? request = freezed, - }) { - return _then(_$Remote( - request == freezed - ? _value.request - : request // ignore: cast_nullable_to_non_nullable - as RemoteRequest, - )); - } - - @override - $RemoteRequestCopyWith<$Res> get request { - return $RemoteRequestCopyWith<$Res>(_value.request, (value) { - return _then(_value.copyWith(request: value)); - }); - } -} - -/// @nodoc - -class _$Remote implements Remote { - const _$Remote(this.request); - - @override - final RemoteRequest request; - - @override - String toString() { - return 'MobileWalletState.remote(request: $request)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$Remote && - const DeepCollectionEquality().equals(other.request, request)); - } - - @override - int get hashCode => - Object.hash(runtimeType, const DeepCollectionEquality().hash(request)); - - @JsonKey(ignore: true) - @override - _$$RemoteCopyWith<_$Remote> get copyWith => - __$$RemoteCopyWithImpl<_$Remote>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() none, - required TResult Function() sessionTerminated, - required TResult Function(RemoteRequest request) remote, - }) { - return remote(request); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult Function()? none, - TResult Function()? sessionTerminated, - TResult Function(RemoteRequest request)? remote, - }) { - return remote?.call(request); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? none, - TResult Function()? sessionTerminated, - TResult Function(RemoteRequest request)? remote, - required TResult orElse(), - }) { - if (remote != null) { - return remote(request); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(None value) none, - required TResult Function(SessionTerminated value) sessionTerminated, - required TResult Function(Remote value) remote, - }) { - return remote(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult Function(None value)? none, - TResult Function(SessionTerminated value)? sessionTerminated, - TResult Function(Remote value)? remote, - }) { - return remote?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(None value)? none, - TResult Function(SessionTerminated value)? sessionTerminated, - TResult Function(Remote value)? remote, - required TResult orElse(), - }) { - if (remote != null) { - return remote(this); - } - return orElse(); - } -} - -abstract class Remote implements MobileWalletState { - const factory Remote(final RemoteRequest request) = _$Remote; - - RemoteRequest get request; - @JsonKey(ignore: true) - _$$RemoteCopyWith<_$Remote> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -mixin _$RemoteRequest { - AuthorizeRequest get request => throw _privateConstructorUsedError; - @optionalTypeArgs - TResult when({ - required TResult Function(AuthorizeRequest request) authorizeDapp, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult Function(AuthorizeRequest request)? authorizeDapp, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(AuthorizeRequest request)? authorizeDapp, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(AuthorizeDapp value) authorizeDapp, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult Function(AuthorizeDapp value)? authorizeDapp, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(AuthorizeDapp value)? authorizeDapp, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - - @JsonKey(ignore: true) - $RemoteRequestCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $RemoteRequestCopyWith<$Res> { - factory $RemoteRequestCopyWith( - RemoteRequest value, $Res Function(RemoteRequest) then) = - _$RemoteRequestCopyWithImpl<$Res>; - $Res call({AuthorizeRequest request}); - - $AuthorizeRequestCopyWith<$Res> get request; -} - -/// @nodoc -class _$RemoteRequestCopyWithImpl<$Res> - implements $RemoteRequestCopyWith<$Res> { - _$RemoteRequestCopyWithImpl(this._value, this._then); - - final RemoteRequest _value; - // ignore: unused_field - final $Res Function(RemoteRequest) _then; - - @override - $Res call({ - Object? request = freezed, - }) { - return _then(_value.copyWith( - request: request == freezed - ? _value.request - : request // ignore: cast_nullable_to_non_nullable - as AuthorizeRequest, - )); - } - - @override - $AuthorizeRequestCopyWith<$Res> get request { - return $AuthorizeRequestCopyWith<$Res>(_value.request, (value) { - return _then(_value.copyWith(request: value)); - }); - } -} - -/// @nodoc -abstract class _$$AuthorizeDappCopyWith<$Res> - implements $RemoteRequestCopyWith<$Res> { - factory _$$AuthorizeDappCopyWith( - _$AuthorizeDapp value, $Res Function(_$AuthorizeDapp) then) = - __$$AuthorizeDappCopyWithImpl<$Res>; - @override - $Res call({AuthorizeRequest request}); - - @override - $AuthorizeRequestCopyWith<$Res> get request; -} - -/// @nodoc -class __$$AuthorizeDappCopyWithImpl<$Res> - extends _$RemoteRequestCopyWithImpl<$Res> - implements _$$AuthorizeDappCopyWith<$Res> { - __$$AuthorizeDappCopyWithImpl( - _$AuthorizeDapp _value, $Res Function(_$AuthorizeDapp) _then) - : super(_value, (v) => _then(v as _$AuthorizeDapp)); - - @override - _$AuthorizeDapp get _value => super._value as _$AuthorizeDapp; - - @override - $Res call({ - Object? request = freezed, - }) { - return _then(_$AuthorizeDapp( - request: request == freezed - ? _value.request - : request // ignore: cast_nullable_to_non_nullable - as AuthorizeRequest, - )); - } -} - -/// @nodoc - -class _$AuthorizeDapp implements AuthorizeDapp { - const _$AuthorizeDapp({required this.request}); - - @override - final AuthorizeRequest request; - - @override - String toString() { - return 'RemoteRequest.authorizeDapp(request: $request)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$AuthorizeDapp && - const DeepCollectionEquality().equals(other.request, request)); - } - - @override - int get hashCode => - Object.hash(runtimeType, const DeepCollectionEquality().hash(request)); - - @JsonKey(ignore: true) - @override - _$$AuthorizeDappCopyWith<_$AuthorizeDapp> get copyWith => - __$$AuthorizeDappCopyWithImpl<_$AuthorizeDapp>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(AuthorizeRequest request) authorizeDapp, - }) { - return authorizeDapp(request); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult Function(AuthorizeRequest request)? authorizeDapp, - }) { - return authorizeDapp?.call(request); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(AuthorizeRequest request)? authorizeDapp, - required TResult orElse(), - }) { - if (authorizeDapp != null) { - return authorizeDapp(request); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(AuthorizeDapp value) authorizeDapp, - }) { - return authorizeDapp(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult Function(AuthorizeDapp value)? authorizeDapp, - }) { - return authorizeDapp?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(AuthorizeDapp value)? authorizeDapp, - required TResult orElse(), - }) { - if (authorizeDapp != null) { - return authorizeDapp(this); - } - return orElse(); - } -} - -abstract class AuthorizeDapp implements RemoteRequest { - const factory AuthorizeDapp({required final AuthorizeRequest request}) = - _$AuthorizeDapp; - - @override - AuthorizeRequest get request; - @override - @JsonKey(ignore: true) - _$$AuthorizeDappCopyWith<_$AuthorizeDapp> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/packages/sms_wallet/example/lib/mobile_wallet/state.dart b/packages/sms_wallet/example/lib/mobile_wallet/state.dart deleted file mode 100644 index ec525b7e2c..0000000000 --- a/packages/sms_wallet/example/lib/mobile_wallet/state.dart +++ /dev/null @@ -1,15 +0,0 @@ -part of 'bloc.dart'; - -@freezed -class MobileWalletState with _$MobileWalletState { - const factory MobileWalletState.none() = None; - const factory MobileWalletState.sessionTerminated() = SessionTerminated; - const factory MobileWalletState.remote(RemoteRequest request) = Remote; -} - -@freezed -class RemoteRequest with _$RemoteRequest { - const factory RemoteRequest.authorizeDapp({ - required AuthorizeRequest request, - }) = AuthorizeDapp; -} diff --git a/packages/sms_wallet/lib/src/scenario.dart b/packages/sms_wallet/lib/src/scenario.dart deleted file mode 100644 index 0f7cd4aa04..0000000000 --- a/packages/sms_wallet/lib/src/scenario.dart +++ /dev/null @@ -1,163 +0,0 @@ -import 'dart:typed_data'; - -import 'package:sms_wallet/src/api.dart'; -import 'package:sms_wallet/src/auth_issuer_config.dart'; -import 'package:sms_wallet/src/requests/authorize.dart'; -import 'package:sms_wallet/src/requests/reauthorize.dart'; -import 'package:sms_wallet/src/sms_wallet_platform.dart'; -import 'package:sms_wallet/src/wallet_config.dart'; - -class Scenario { - Scenario._({ - required this.associationPublicKey, - required this.callbacks, - required this.id, - }); - - static Future create({ - required MobileWalletAdapterConfig walletConfig, - required AuthIssuerConfig issuerConfig, - required ScenarioCallbacks callbacks, - }) async { - final id = _nextId++; - final associationPublicKey = - await SmsWalletPlatform.instance.createScenario( - walletConfig: walletConfig, - issuerConfig: issuerConfig, - id: id, - ); - if (associationPublicKey == null) { - return null; - } - - final scenario = Scenario._( - associationPublicKey: associationPublicKey, - callbacks: callbacks, - id: id, - ); - - Api.instance.register(scenario); - - return scenario; - } - - static int _nextId = 1; - - final int id; - - final Uint8List associationPublicKey; - final ScenarioCallbacks callbacks; - final _host = ApiHost(); - - void start() { - _host.start(id); - } - - void close() { - _host.close(id); - } -} - -abstract class ScenarioCallbacks { - // Scenario state callbacks - void onScenarioReady(); - void onScenarioServingClients(); - void onScenarioServingComplete(); - void onScenarioComplete(); - void onScenarioError(); - void onScenarioTeardownComplete(); - - // Request callbacks - Future onAuthorizeRequest(AuthorizeRequest request); - Future onReauthorizeRequest(ReauthorizeRequest request); - // void onSignTransactionsRequest(SignTransactionsRequest request); - // void onSignMessagesRequest(SignMessagesRequest request); - // void onSignAndSendTransactionsRequest(SignAndSendTransactionsRequest request); -} - -class Api implements ApiFlutter { - Api._() { - ApiFlutter.setup(this); - } - - static final _instance = Api._(); - - static Api get instance => _instance; - - static final _scenarios = {}; - - void register(Scenario scenario) { - _scenarios[scenario.id] = scenario; - } - - void unregister(int id) { - _scenarios.remove(id); - } - - @override - Future authorize( - AuthorizeRequestDto request, - int id, - ) async { - final r = AuthorizeRequest( - identityName: request.identityName, - identityUri: Uri.tryParse(request.identityUri ?? ''), - iconUri: Uri.tryParse(request.iconUri ?? ''), - ); - final result = await _scenarios[id]?.callbacks.onAuthorizeRequest(r); - if (result == null) return null; - - return AuthorizeResultDto( - publicKey: result.publicKey, - accountLabel: result.accountLabel, - walletUriBase: result.walletUriBase?.toString(), - scope: result.scope, - ); - } - - @override - Future reauthorize(ReauthorizeRequestDto request, int id) async { - final r = ReauthorizeRequest( - identityName: request.identityName, - identityUri: Uri.tryParse(request.identityUri ?? ''), - iconRelativeUri: Uri.tryParse(request.iconRelativeUri ?? ''), - cluster: request.cluster, - authorizationScope: request.authorizationScope, - ); - - final result = await _scenarios[id]?.callbacks.onReauthorizeRequest(r); - - return result ?? false; - } - - @override - void onScenarioReady(int id) { - _scenarios[id]?.callbacks.onScenarioReady(); - } - - @override - void onScenarioComplete(int id) { - _scenarios[id]?.callbacks.onScenarioComplete(); - } - - @override - void onScenarioError(int id) { - _scenarios[id]?.callbacks.onScenarioError(); - } - - @override - void onScenarioServingClients(int id) { - _scenarios[id]?.callbacks.onScenarioServingClients(); - } - - @override - void onScenarioServingComplete(int id) { - _scenarios[id]?.callbacks.onScenarioServingComplete(); - } - - @override - void onScenarioTeardownComplete(int id) { - _scenarios[id]?.callbacks.onScenarioTeardownComplete(); - unregister(id); - } -} diff --git a/packages/sms_wallet/pigeons/api.dart b/packages/sms_wallet/pigeons/api.dart deleted file mode 100644 index c283960896..0000000000 --- a/packages/sms_wallet/pigeons/api.dart +++ /dev/null @@ -1,90 +0,0 @@ -import 'package:pigeon/pigeon.dart'; - -class AuthorizeRequestDto { - AuthorizeRequestDto({ - required this.identityName, - required this.identityUri, - required this.iconUri, - }); - - final String? identityName; - final String? identityUri; - final String? iconUri; -} - -class AuthorizeResultDto { - AuthorizeResultDto({ - required this.publicKey, - required this.accountLabel, - required this.walletUriBase, - required this.scope, - }); - - final Uint8List publicKey; - final String? accountLabel; - final String? walletUriBase; - final Uint8List? scope; -} - -abstract class BaseVerifiableIdentityRequestDto { - BaseVerifiableIdentityRequestDto({ - required this.identityName, - required this.identityUri, - required this.iconRelativeUri, - required this.cluster, - required this.authorizationScope, - }); - - final String? identityName; - final String? identityUri; - final String? iconRelativeUri; - final String cluster; - final Uint8List authorizationScope; -} - -class ReauthorizeRequestDto implements BaseVerifiableIdentityRequestDto { - ReauthorizeRequestDto({ - required this.identityUri, - required this.identityName, - required this.iconRelativeUri, - required this.cluster, - required this.authorizationScope, - }); - - @override - final String? identityName; - - @override - final String? identityUri; - - @override - final String? iconRelativeUri; - - @override - final String cluster; - - @override - final Uint8List authorizationScope; -} - -@FlutterApi() -abstract class ApiFlutter { - void onScenarioReady(int id); - void onScenarioServingClients(int id); - void onScenarioServingComplete(int id); - void onScenarioComplete(int id); - void onScenarioError(int id); - void onScenarioTeardownComplete(int id); - - @async - AuthorizeResultDto? authorize(AuthorizeRequestDto request, int id); - - @async - bool reauthorize(ReauthorizeRequestDto request, int id); -} - -@HostApi() -abstract class ApiHost { - void start(int id); - void close(int id); -} diff --git a/packages/sms_wallet/.gitignore b/packages/solana_mobile_wallet/.gitignore similarity index 100% rename from packages/sms_wallet/.gitignore rename to packages/solana_mobile_wallet/.gitignore diff --git a/packages/sms_wallet/.metadata b/packages/solana_mobile_wallet/.metadata similarity index 100% rename from packages/sms_wallet/.metadata rename to packages/solana_mobile_wallet/.metadata diff --git a/packages/solana_mobile_wallet/CHANGELOG.md b/packages/solana_mobile_wallet/CHANGELOG.md new file mode 100644 index 0000000000..339d42b247 --- /dev/null +++ b/packages/solana_mobile_wallet/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.0.1 + +- Initial release diff --git a/packages/sms_wallet/LICENSE b/packages/solana_mobile_wallet/LICENSE similarity index 100% rename from packages/sms_wallet/LICENSE rename to packages/solana_mobile_wallet/LICENSE diff --git a/packages/solana_mobile_wallet/Makefile b/packages/solana_mobile_wallet/Makefile new file mode 100644 index 0000000000..b6418d90b6 --- /dev/null +++ b/packages/solana_mobile_wallet/Makefile @@ -0,0 +1,8 @@ +include ../../Makefile + +pigeon: + flutter pub run pigeon \ + --input pigeons/api.dart \ + --dart_out lib/src/api.dart \ + --java_out ./android/src/main/java/com/solana/solana_mobile_wallet/Api.java \ + --java_package "com.solana.solana_mobile_wallet" diff --git a/packages/solana_mobile_wallet/README.md b/packages/solana_mobile_wallet/README.md new file mode 100644 index 0000000000..145da03984 --- /dev/null +++ b/packages/solana_mobile_wallet/README.md @@ -0,0 +1,5 @@ +# solana_mobile_wallet + +This is a reference implementation of the [Mobile Wallet Adapter specification][spec] for Flutter. + +[spec]: https://github.com/solana-mobile/mobile-wallet-adapter/blob/main/spec/spec.md diff --git a/packages/sms_wallet/analysis_options.yaml b/packages/solana_mobile_wallet/analysis_options.yaml similarity index 100% rename from packages/sms_wallet/analysis_options.yaml rename to packages/solana_mobile_wallet/analysis_options.yaml diff --git a/packages/sms_wallet/android/.gitignore b/packages/solana_mobile_wallet/android/.gitignore similarity index 100% rename from packages/sms_wallet/android/.gitignore rename to packages/solana_mobile_wallet/android/.gitignore diff --git a/packages/sms_wallet/android/build.gradle b/packages/solana_mobile_wallet/android/build.gradle similarity index 96% rename from packages/sms_wallet/android/build.gradle rename to packages/solana_mobile_wallet/android/build.gradle index 504be3cf0c..ff7758fe68 100644 --- a/packages/sms_wallet/android/build.gradle +++ b/packages/solana_mobile_wallet/android/build.gradle @@ -1,4 +1,4 @@ -group 'com.solana.sms_wallet' +group 'com.solana.solana_mobile_wallet' version '1.0-SNAPSHOT' buildscript { diff --git a/packages/solana_mobile_wallet/android/settings.gradle b/packages/solana_mobile_wallet/android/settings.gradle new file mode 100644 index 0000000000..ccecfeed72 --- /dev/null +++ b/packages/solana_mobile_wallet/android/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'solana_mobile_wallet' diff --git a/packages/sms_wallet/android/src/main/AndroidManifest.xml b/packages/solana_mobile_wallet/android/src/main/AndroidManifest.xml similarity index 64% rename from packages/sms_wallet/android/src/main/AndroidManifest.xml rename to packages/solana_mobile_wallet/android/src/main/AndroidManifest.xml index 7171876368..8a6b1513f2 100644 --- a/packages/sms_wallet/android/src/main/AndroidManifest.xml +++ b/packages/solana_mobile_wallet/android/src/main/AndroidManifest.xml @@ -1,3 +1,3 @@ + package="com.solana.solana_mobile_wallet"> diff --git a/packages/solana_mobile_wallet/android/src/main/java/com/solana/solana_mobile_wallet/Api.java b/packages/solana_mobile_wallet/android/src/main/java/com/solana/solana_mobile_wallet/Api.java new file mode 100644 index 0000000000..6f66c00221 --- /dev/null +++ b/packages/solana_mobile_wallet/android/src/main/java/com/solana/solana_mobile_wallet/Api.java @@ -0,0 +1,1049 @@ +// Autogenerated from Pigeon (v3.2.6), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +package com.solana.solana_mobile_wallet; + +import android.util.Log; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import io.flutter.plugin.common.BasicMessageChannel; +import io.flutter.plugin.common.BinaryMessenger; +import io.flutter.plugin.common.MessageCodec; +import io.flutter.plugin.common.StandardMessageCodec; +import java.io.ByteArrayOutputStream; +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.HashMap; + +/** Generated class from Pigeon. */ +@SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"}) +public class Api { + + public enum MobileWalletAdapterServerException { + requestDeclined(0), + invalidPayloads(1), + tooManyPayloads(2), + authorizationNotValid(3); + + private int index; + private MobileWalletAdapterServerException(final int index) { + this.index = index; + } + } + + /** Generated class from Pigeon that represents data sent in messages. */ + public static class AuthorizeRequestDto { + private @Nullable String identityName; + public @Nullable String getIdentityName() { return identityName; } + public void setIdentityName(@Nullable String setterArg) { + this.identityName = setterArg; + } + + private @Nullable String identityUri; + public @Nullable String getIdentityUri() { return identityUri; } + public void setIdentityUri(@Nullable String setterArg) { + this.identityUri = setterArg; + } + + private @Nullable String iconUri; + public @Nullable String getIconUri() { return iconUri; } + public void setIconUri(@Nullable String setterArg) { + this.iconUri = setterArg; + } + + public static final class Builder { + private @Nullable String identityName; + public @NonNull Builder setIdentityName(@Nullable String setterArg) { + this.identityName = setterArg; + return this; + } + private @Nullable String identityUri; + public @NonNull Builder setIdentityUri(@Nullable String setterArg) { + this.identityUri = setterArg; + return this; + } + private @Nullable String iconUri; + public @NonNull Builder setIconUri(@Nullable String setterArg) { + this.iconUri = setterArg; + return this; + } + public @NonNull AuthorizeRequestDto build() { + AuthorizeRequestDto pigeonReturn = new AuthorizeRequestDto(); + pigeonReturn.setIdentityName(identityName); + pigeonReturn.setIdentityUri(identityUri); + pigeonReturn.setIconUri(iconUri); + return pigeonReturn; + } + } + @NonNull Map toMap() { + Map toMapResult = new HashMap<>(); + toMapResult.put("identityName", identityName); + toMapResult.put("identityUri", identityUri); + toMapResult.put("iconUri", iconUri); + return toMapResult; + } + static @NonNull AuthorizeRequestDto fromMap(@NonNull Map map) { + AuthorizeRequestDto pigeonResult = new AuthorizeRequestDto(); + Object identityName = map.get("identityName"); + pigeonResult.setIdentityName((String)identityName); + Object identityUri = map.get("identityUri"); + pigeonResult.setIdentityUri((String)identityUri); + Object iconUri = map.get("iconUri"); + pigeonResult.setIconUri((String)iconUri); + return pigeonResult; + } + } + + /** Generated class from Pigeon that represents data sent in messages. */ + public static class AuthorizeResultDto { + private @NonNull byte[] publicKey; + public @NonNull byte[] getPublicKey() { return publicKey; } + public void setPublicKey(@NonNull byte[] setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"publicKey\" is null."); + } + this.publicKey = setterArg; + } + + private @Nullable String accountLabel; + public @Nullable String getAccountLabel() { return accountLabel; } + public void setAccountLabel(@Nullable String setterArg) { + this.accountLabel = setterArg; + } + + private @Nullable String walletUriBase; + public @Nullable String getWalletUriBase() { return walletUriBase; } + public void setWalletUriBase(@Nullable String setterArg) { + this.walletUriBase = setterArg; + } + + private @Nullable byte[] scope; + public @Nullable byte[] getScope() { return scope; } + public void setScope(@Nullable byte[] setterArg) { + this.scope = setterArg; + } + + /** Constructor is private to enforce null safety; use Builder. */ + private AuthorizeResultDto() {} + public static final class Builder { + private @Nullable byte[] publicKey; + public @NonNull Builder setPublicKey(@NonNull byte[] setterArg) { + this.publicKey = setterArg; + return this; + } + private @Nullable String accountLabel; + public @NonNull Builder setAccountLabel(@Nullable String setterArg) { + this.accountLabel = setterArg; + return this; + } + private @Nullable String walletUriBase; + public @NonNull Builder setWalletUriBase(@Nullable String setterArg) { + this.walletUriBase = setterArg; + return this; + } + private @Nullable byte[] scope; + public @NonNull Builder setScope(@Nullable byte[] setterArg) { + this.scope = setterArg; + return this; + } + public @NonNull AuthorizeResultDto build() { + AuthorizeResultDto pigeonReturn = new AuthorizeResultDto(); + pigeonReturn.setPublicKey(publicKey); + pigeonReturn.setAccountLabel(accountLabel); + pigeonReturn.setWalletUriBase(walletUriBase); + pigeonReturn.setScope(scope); + return pigeonReturn; + } + } + @NonNull Map toMap() { + Map toMapResult = new HashMap<>(); + toMapResult.put("publicKey", publicKey); + toMapResult.put("accountLabel", accountLabel); + toMapResult.put("walletUriBase", walletUriBase); + toMapResult.put("scope", scope); + return toMapResult; + } + static @NonNull AuthorizeResultDto fromMap(@NonNull Map map) { + AuthorizeResultDto pigeonResult = new AuthorizeResultDto(); + Object publicKey = map.get("publicKey"); + pigeonResult.setPublicKey((byte[])publicKey); + Object accountLabel = map.get("accountLabel"); + pigeonResult.setAccountLabel((String)accountLabel); + Object walletUriBase = map.get("walletUriBase"); + pigeonResult.setWalletUriBase((String)walletUriBase); + Object scope = map.get("scope"); + pigeonResult.setScope((byte[])scope); + return pigeonResult; + } + } + + /** Generated class from Pigeon that represents data sent in messages. */ + public static class ReauthorizeRequestDto { + private @Nullable String identityName; + public @Nullable String getIdentityName() { return identityName; } + public void setIdentityName(@Nullable String setterArg) { + this.identityName = setterArg; + } + + private @Nullable String identityUri; + public @Nullable String getIdentityUri() { return identityUri; } + public void setIdentityUri(@Nullable String setterArg) { + this.identityUri = setterArg; + } + + private @Nullable String iconRelativeUri; + public @Nullable String getIconRelativeUri() { return iconRelativeUri; } + public void setIconRelativeUri(@Nullable String setterArg) { + this.iconRelativeUri = setterArg; + } + + private @NonNull String cluster; + public @NonNull String getCluster() { return cluster; } + public void setCluster(@NonNull String setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"cluster\" is null."); + } + this.cluster = setterArg; + } + + private @NonNull byte[] authorizationScope; + public @NonNull byte[] getAuthorizationScope() { return authorizationScope; } + public void setAuthorizationScope(@NonNull byte[] setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"authorizationScope\" is null."); + } + this.authorizationScope = setterArg; + } + + /** Constructor is private to enforce null safety; use Builder. */ + private ReauthorizeRequestDto() {} + public static final class Builder { + private @Nullable String identityName; + public @NonNull Builder setIdentityName(@Nullable String setterArg) { + this.identityName = setterArg; + return this; + } + private @Nullable String identityUri; + public @NonNull Builder setIdentityUri(@Nullable String setterArg) { + this.identityUri = setterArg; + return this; + } + private @Nullable String iconRelativeUri; + public @NonNull Builder setIconRelativeUri(@Nullable String setterArg) { + this.iconRelativeUri = setterArg; + return this; + } + private @Nullable String cluster; + public @NonNull Builder setCluster(@NonNull String setterArg) { + this.cluster = setterArg; + return this; + } + private @Nullable byte[] authorizationScope; + public @NonNull Builder setAuthorizationScope(@NonNull byte[] setterArg) { + this.authorizationScope = setterArg; + return this; + } + public @NonNull ReauthorizeRequestDto build() { + ReauthorizeRequestDto pigeonReturn = new ReauthorizeRequestDto(); + pigeonReturn.setIdentityName(identityName); + pigeonReturn.setIdentityUri(identityUri); + pigeonReturn.setIconRelativeUri(iconRelativeUri); + pigeonReturn.setCluster(cluster); + pigeonReturn.setAuthorizationScope(authorizationScope); + return pigeonReturn; + } + } + @NonNull Map toMap() { + Map toMapResult = new HashMap<>(); + toMapResult.put("identityName", identityName); + toMapResult.put("identityUri", identityUri); + toMapResult.put("iconRelativeUri", iconRelativeUri); + toMapResult.put("cluster", cluster); + toMapResult.put("authorizationScope", authorizationScope); + return toMapResult; + } + static @NonNull ReauthorizeRequestDto fromMap(@NonNull Map map) { + ReauthorizeRequestDto pigeonResult = new ReauthorizeRequestDto(); + Object identityName = map.get("identityName"); + pigeonResult.setIdentityName((String)identityName); + Object identityUri = map.get("identityUri"); + pigeonResult.setIdentityUri((String)identityUri); + Object iconRelativeUri = map.get("iconRelativeUri"); + pigeonResult.setIconRelativeUri((String)iconRelativeUri); + Object cluster = map.get("cluster"); + pigeonResult.setCluster((String)cluster); + Object authorizationScope = map.get("authorizationScope"); + pigeonResult.setAuthorizationScope((byte[])authorizationScope); + return pigeonResult; + } + } + + /** Generated class from Pigeon that represents data sent in messages. */ + public static class SignedPayloadsResultDto { + private @Nullable List payloads; + public @Nullable List getPayloads() { return payloads; } + public void setPayloads(@Nullable List setterArg) { + this.payloads = setterArg; + } + + private @Nullable MobileWalletAdapterServerException error; + public @Nullable MobileWalletAdapterServerException getError() { return error; } + public void setError(@Nullable MobileWalletAdapterServerException setterArg) { + this.error = setterArg; + } + + private @Nullable List validPayloads; + public @Nullable List getValidPayloads() { return validPayloads; } + public void setValidPayloads(@Nullable List setterArg) { + this.validPayloads = setterArg; + } + + public static final class Builder { + private @Nullable List payloads; + public @NonNull Builder setPayloads(@Nullable List setterArg) { + this.payloads = setterArg; + return this; + } + private @Nullable MobileWalletAdapterServerException error; + public @NonNull Builder setError(@Nullable MobileWalletAdapterServerException setterArg) { + this.error = setterArg; + return this; + } + private @Nullable List validPayloads; + public @NonNull Builder setValidPayloads(@Nullable List setterArg) { + this.validPayloads = setterArg; + return this; + } + public @NonNull SignedPayloadsResultDto build() { + SignedPayloadsResultDto pigeonReturn = new SignedPayloadsResultDto(); + pigeonReturn.setPayloads(payloads); + pigeonReturn.setError(error); + pigeonReturn.setValidPayloads(validPayloads); + return pigeonReturn; + } + } + @NonNull Map toMap() { + Map toMapResult = new HashMap<>(); + toMapResult.put("payloads", payloads); + toMapResult.put("error", error == null ? null : error.index); + toMapResult.put("validPayloads", validPayloads); + return toMapResult; + } + static @NonNull SignedPayloadsResultDto fromMap(@NonNull Map map) { + SignedPayloadsResultDto pigeonResult = new SignedPayloadsResultDto(); + Object payloads = map.get("payloads"); + pigeonResult.setPayloads((List)payloads); + Object error = map.get("error"); + pigeonResult.setError(error == null ? null : MobileWalletAdapterServerException.values()[(int)error]); + Object validPayloads = map.get("validPayloads"); + pigeonResult.setValidPayloads((List)validPayloads); + return pigeonResult; + } + } + + /** Generated class from Pigeon that represents data sent in messages. */ + public static class SignTransactionsRequestDto { + private @NonNull List payloads; + public @NonNull List getPayloads() { return payloads; } + public void setPayloads(@NonNull List setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"payloads\" is null."); + } + this.payloads = setterArg; + } + + private @Nullable String identityName; + public @Nullable String getIdentityName() { return identityName; } + public void setIdentityName(@Nullable String setterArg) { + this.identityName = setterArg; + } + + private @Nullable String identityUri; + public @Nullable String getIdentityUri() { return identityUri; } + public void setIdentityUri(@Nullable String setterArg) { + this.identityUri = setterArg; + } + + private @Nullable String iconRelativeUri; + public @Nullable String getIconRelativeUri() { return iconRelativeUri; } + public void setIconRelativeUri(@Nullable String setterArg) { + this.iconRelativeUri = setterArg; + } + + private @NonNull String cluster; + public @NonNull String getCluster() { return cluster; } + public void setCluster(@NonNull String setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"cluster\" is null."); + } + this.cluster = setterArg; + } + + private @NonNull byte[] authorizationScope; + public @NonNull byte[] getAuthorizationScope() { return authorizationScope; } + public void setAuthorizationScope(@NonNull byte[] setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"authorizationScope\" is null."); + } + this.authorizationScope = setterArg; + } + + /** Constructor is private to enforce null safety; use Builder. */ + private SignTransactionsRequestDto() {} + public static final class Builder { + private @Nullable List payloads; + public @NonNull Builder setPayloads(@NonNull List setterArg) { + this.payloads = setterArg; + return this; + } + private @Nullable String identityName; + public @NonNull Builder setIdentityName(@Nullable String setterArg) { + this.identityName = setterArg; + return this; + } + private @Nullable String identityUri; + public @NonNull Builder setIdentityUri(@Nullable String setterArg) { + this.identityUri = setterArg; + return this; + } + private @Nullable String iconRelativeUri; + public @NonNull Builder setIconRelativeUri(@Nullable String setterArg) { + this.iconRelativeUri = setterArg; + return this; + } + private @Nullable String cluster; + public @NonNull Builder setCluster(@NonNull String setterArg) { + this.cluster = setterArg; + return this; + } + private @Nullable byte[] authorizationScope; + public @NonNull Builder setAuthorizationScope(@NonNull byte[] setterArg) { + this.authorizationScope = setterArg; + return this; + } + public @NonNull SignTransactionsRequestDto build() { + SignTransactionsRequestDto pigeonReturn = new SignTransactionsRequestDto(); + pigeonReturn.setPayloads(payloads); + pigeonReturn.setIdentityName(identityName); + pigeonReturn.setIdentityUri(identityUri); + pigeonReturn.setIconRelativeUri(iconRelativeUri); + pigeonReturn.setCluster(cluster); + pigeonReturn.setAuthorizationScope(authorizationScope); + return pigeonReturn; + } + } + @NonNull Map toMap() { + Map toMapResult = new HashMap<>(); + toMapResult.put("payloads", payloads); + toMapResult.put("identityName", identityName); + toMapResult.put("identityUri", identityUri); + toMapResult.put("iconRelativeUri", iconRelativeUri); + toMapResult.put("cluster", cluster); + toMapResult.put("authorizationScope", authorizationScope); + return toMapResult; + } + static @NonNull SignTransactionsRequestDto fromMap(@NonNull Map map) { + SignTransactionsRequestDto pigeonResult = new SignTransactionsRequestDto(); + Object payloads = map.get("payloads"); + pigeonResult.setPayloads((List)payloads); + Object identityName = map.get("identityName"); + pigeonResult.setIdentityName((String)identityName); + Object identityUri = map.get("identityUri"); + pigeonResult.setIdentityUri((String)identityUri); + Object iconRelativeUri = map.get("iconRelativeUri"); + pigeonResult.setIconRelativeUri((String)iconRelativeUri); + Object cluster = map.get("cluster"); + pigeonResult.setCluster((String)cluster); + Object authorizationScope = map.get("authorizationScope"); + pigeonResult.setAuthorizationScope((byte[])authorizationScope); + return pigeonResult; + } + } + + /** Generated class from Pigeon that represents data sent in messages. */ + public static class SignMessagesRequestDto { + private @NonNull List payloads; + public @NonNull List getPayloads() { return payloads; } + public void setPayloads(@NonNull List setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"payloads\" is null."); + } + this.payloads = setterArg; + } + + private @Nullable String identityName; + public @Nullable String getIdentityName() { return identityName; } + public void setIdentityName(@Nullable String setterArg) { + this.identityName = setterArg; + } + + private @Nullable String identityUri; + public @Nullable String getIdentityUri() { return identityUri; } + public void setIdentityUri(@Nullable String setterArg) { + this.identityUri = setterArg; + } + + private @Nullable String iconRelativeUri; + public @Nullable String getIconRelativeUri() { return iconRelativeUri; } + public void setIconRelativeUri(@Nullable String setterArg) { + this.iconRelativeUri = setterArg; + } + + private @NonNull String cluster; + public @NonNull String getCluster() { return cluster; } + public void setCluster(@NonNull String setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"cluster\" is null."); + } + this.cluster = setterArg; + } + + private @NonNull byte[] authorizationScope; + public @NonNull byte[] getAuthorizationScope() { return authorizationScope; } + public void setAuthorizationScope(@NonNull byte[] setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"authorizationScope\" is null."); + } + this.authorizationScope = setterArg; + } + + /** Constructor is private to enforce null safety; use Builder. */ + private SignMessagesRequestDto() {} + public static final class Builder { + private @Nullable List payloads; + public @NonNull Builder setPayloads(@NonNull List setterArg) { + this.payloads = setterArg; + return this; + } + private @Nullable String identityName; + public @NonNull Builder setIdentityName(@Nullable String setterArg) { + this.identityName = setterArg; + return this; + } + private @Nullable String identityUri; + public @NonNull Builder setIdentityUri(@Nullable String setterArg) { + this.identityUri = setterArg; + return this; + } + private @Nullable String iconRelativeUri; + public @NonNull Builder setIconRelativeUri(@Nullable String setterArg) { + this.iconRelativeUri = setterArg; + return this; + } + private @Nullable String cluster; + public @NonNull Builder setCluster(@NonNull String setterArg) { + this.cluster = setterArg; + return this; + } + private @Nullable byte[] authorizationScope; + public @NonNull Builder setAuthorizationScope(@NonNull byte[] setterArg) { + this.authorizationScope = setterArg; + return this; + } + public @NonNull SignMessagesRequestDto build() { + SignMessagesRequestDto pigeonReturn = new SignMessagesRequestDto(); + pigeonReturn.setPayloads(payloads); + pigeonReturn.setIdentityName(identityName); + pigeonReturn.setIdentityUri(identityUri); + pigeonReturn.setIconRelativeUri(iconRelativeUri); + pigeonReturn.setCluster(cluster); + pigeonReturn.setAuthorizationScope(authorizationScope); + return pigeonReturn; + } + } + @NonNull Map toMap() { + Map toMapResult = new HashMap<>(); + toMapResult.put("payloads", payloads); + toMapResult.put("identityName", identityName); + toMapResult.put("identityUri", identityUri); + toMapResult.put("iconRelativeUri", iconRelativeUri); + toMapResult.put("cluster", cluster); + toMapResult.put("authorizationScope", authorizationScope); + return toMapResult; + } + static @NonNull SignMessagesRequestDto fromMap(@NonNull Map map) { + SignMessagesRequestDto pigeonResult = new SignMessagesRequestDto(); + Object payloads = map.get("payloads"); + pigeonResult.setPayloads((List)payloads); + Object identityName = map.get("identityName"); + pigeonResult.setIdentityName((String)identityName); + Object identityUri = map.get("identityUri"); + pigeonResult.setIdentityUri((String)identityUri); + Object iconRelativeUri = map.get("iconRelativeUri"); + pigeonResult.setIconRelativeUri((String)iconRelativeUri); + Object cluster = map.get("cluster"); + pigeonResult.setCluster((String)cluster); + Object authorizationScope = map.get("authorizationScope"); + pigeonResult.setAuthorizationScope((byte[])authorizationScope); + return pigeonResult; + } + } + + /** Generated class from Pigeon that represents data sent in messages. */ + public static class SignAndSendTransactionsRequestDto { + private @Nullable Long minContextSlot; + public @Nullable Long getMinContextSlot() { return minContextSlot; } + public void setMinContextSlot(@Nullable Long setterArg) { + this.minContextSlot = setterArg; + } + + private @NonNull List transactions; + public @NonNull List getTransactions() { return transactions; } + public void setTransactions(@NonNull List setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"transactions\" is null."); + } + this.transactions = setterArg; + } + + private @NonNull byte[] publicKey; + public @NonNull byte[] getPublicKey() { return publicKey; } + public void setPublicKey(@NonNull byte[] setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"publicKey\" is null."); + } + this.publicKey = setterArg; + } + + private @Nullable String identityName; + public @Nullable String getIdentityName() { return identityName; } + public void setIdentityName(@Nullable String setterArg) { + this.identityName = setterArg; + } + + private @Nullable String identityUri; + public @Nullable String getIdentityUri() { return identityUri; } + public void setIdentityUri(@Nullable String setterArg) { + this.identityUri = setterArg; + } + + private @Nullable String iconRelativeUri; + public @Nullable String getIconRelativeUri() { return iconRelativeUri; } + public void setIconRelativeUri(@Nullable String setterArg) { + this.iconRelativeUri = setterArg; + } + + private @NonNull String cluster; + public @NonNull String getCluster() { return cluster; } + public void setCluster(@NonNull String setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"cluster\" is null."); + } + this.cluster = setterArg; + } + + private @NonNull byte[] authorizationScope; + public @NonNull byte[] getAuthorizationScope() { return authorizationScope; } + public void setAuthorizationScope(@NonNull byte[] setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"authorizationScope\" is null."); + } + this.authorizationScope = setterArg; + } + + /** Constructor is private to enforce null safety; use Builder. */ + private SignAndSendTransactionsRequestDto() {} + public static final class Builder { + private @Nullable Long minContextSlot; + public @NonNull Builder setMinContextSlot(@Nullable Long setterArg) { + this.minContextSlot = setterArg; + return this; + } + private @Nullable List transactions; + public @NonNull Builder setTransactions(@NonNull List setterArg) { + this.transactions = setterArg; + return this; + } + private @Nullable byte[] publicKey; + public @NonNull Builder setPublicKey(@NonNull byte[] setterArg) { + this.publicKey = setterArg; + return this; + } + private @Nullable String identityName; + public @NonNull Builder setIdentityName(@Nullable String setterArg) { + this.identityName = setterArg; + return this; + } + private @Nullable String identityUri; + public @NonNull Builder setIdentityUri(@Nullable String setterArg) { + this.identityUri = setterArg; + return this; + } + private @Nullable String iconRelativeUri; + public @NonNull Builder setIconRelativeUri(@Nullable String setterArg) { + this.iconRelativeUri = setterArg; + return this; + } + private @Nullable String cluster; + public @NonNull Builder setCluster(@NonNull String setterArg) { + this.cluster = setterArg; + return this; + } + private @Nullable byte[] authorizationScope; + public @NonNull Builder setAuthorizationScope(@NonNull byte[] setterArg) { + this.authorizationScope = setterArg; + return this; + } + public @NonNull SignAndSendTransactionsRequestDto build() { + SignAndSendTransactionsRequestDto pigeonReturn = new SignAndSendTransactionsRequestDto(); + pigeonReturn.setMinContextSlot(minContextSlot); + pigeonReturn.setTransactions(transactions); + pigeonReturn.setPublicKey(publicKey); + pigeonReturn.setIdentityName(identityName); + pigeonReturn.setIdentityUri(identityUri); + pigeonReturn.setIconRelativeUri(iconRelativeUri); + pigeonReturn.setCluster(cluster); + pigeonReturn.setAuthorizationScope(authorizationScope); + return pigeonReturn; + } + } + @NonNull Map toMap() { + Map toMapResult = new HashMap<>(); + toMapResult.put("minContextSlot", minContextSlot); + toMapResult.put("transactions", transactions); + toMapResult.put("publicKey", publicKey); + toMapResult.put("identityName", identityName); + toMapResult.put("identityUri", identityUri); + toMapResult.put("iconRelativeUri", iconRelativeUri); + toMapResult.put("cluster", cluster); + toMapResult.put("authorizationScope", authorizationScope); + return toMapResult; + } + static @NonNull SignAndSendTransactionsRequestDto fromMap(@NonNull Map map) { + SignAndSendTransactionsRequestDto pigeonResult = new SignAndSendTransactionsRequestDto(); + Object minContextSlot = map.get("minContextSlot"); + pigeonResult.setMinContextSlot((minContextSlot == null) ? null : ((minContextSlot instanceof Integer) ? (Integer)minContextSlot : (Long)minContextSlot)); + Object transactions = map.get("transactions"); + pigeonResult.setTransactions((List)transactions); + Object publicKey = map.get("publicKey"); + pigeonResult.setPublicKey((byte[])publicKey); + Object identityName = map.get("identityName"); + pigeonResult.setIdentityName((String)identityName); + Object identityUri = map.get("identityUri"); + pigeonResult.setIdentityUri((String)identityUri); + Object iconRelativeUri = map.get("iconRelativeUri"); + pigeonResult.setIconRelativeUri((String)iconRelativeUri); + Object cluster = map.get("cluster"); + pigeonResult.setCluster((String)cluster); + Object authorizationScope = map.get("authorizationScope"); + pigeonResult.setAuthorizationScope((byte[])authorizationScope); + return pigeonResult; + } + } + + /** Generated class from Pigeon that represents data sent in messages. */ + public static class SignaturesResultDto { + private @Nullable List signatures; + public @Nullable List getSignatures() { return signatures; } + public void setSignatures(@Nullable List setterArg) { + this.signatures = setterArg; + } + + private @Nullable MobileWalletAdapterServerException error; + public @Nullable MobileWalletAdapterServerException getError() { return error; } + public void setError(@Nullable MobileWalletAdapterServerException setterArg) { + this.error = setterArg; + } + + private @Nullable List validSignatures; + public @Nullable List getValidSignatures() { return validSignatures; } + public void setValidSignatures(@Nullable List setterArg) { + this.validSignatures = setterArg; + } + + public static final class Builder { + private @Nullable List signatures; + public @NonNull Builder setSignatures(@Nullable List setterArg) { + this.signatures = setterArg; + return this; + } + private @Nullable MobileWalletAdapterServerException error; + public @NonNull Builder setError(@Nullable MobileWalletAdapterServerException setterArg) { + this.error = setterArg; + return this; + } + private @Nullable List validSignatures; + public @NonNull Builder setValidSignatures(@Nullable List setterArg) { + this.validSignatures = setterArg; + return this; + } + public @NonNull SignaturesResultDto build() { + SignaturesResultDto pigeonReturn = new SignaturesResultDto(); + pigeonReturn.setSignatures(signatures); + pigeonReturn.setError(error); + pigeonReturn.setValidSignatures(validSignatures); + return pigeonReturn; + } + } + @NonNull Map toMap() { + Map toMapResult = new HashMap<>(); + toMapResult.put("signatures", signatures); + toMapResult.put("error", error == null ? null : error.index); + toMapResult.put("validSignatures", validSignatures); + return toMapResult; + } + static @NonNull SignaturesResultDto fromMap(@NonNull Map map) { + SignaturesResultDto pigeonResult = new SignaturesResultDto(); + Object signatures = map.get("signatures"); + pigeonResult.setSignatures((List)signatures); + Object error = map.get("error"); + pigeonResult.setError(error == null ? null : MobileWalletAdapterServerException.values()[(int)error]); + Object validSignatures = map.get("validSignatures"); + pigeonResult.setValidSignatures((List)validSignatures); + return pigeonResult; + } + } + private static class ApiFlutterCodec extends StandardMessageCodec { + public static final ApiFlutterCodec INSTANCE = new ApiFlutterCodec(); + private ApiFlutterCodec() {} + @Override + protected Object readValueOfType(byte type, ByteBuffer buffer) { + switch (type) { + case (byte)128: + return AuthorizeRequestDto.fromMap((Map) readValue(buffer)); + + case (byte)129: + return AuthorizeResultDto.fromMap((Map) readValue(buffer)); + + case (byte)130: + return ReauthorizeRequestDto.fromMap((Map) readValue(buffer)); + + case (byte)131: + return SignAndSendTransactionsRequestDto.fromMap((Map) readValue(buffer)); + + case (byte)132: + return SignMessagesRequestDto.fromMap((Map) readValue(buffer)); + + case (byte)133: + return SignTransactionsRequestDto.fromMap((Map) readValue(buffer)); + + case (byte)134: + return SignaturesResultDto.fromMap((Map) readValue(buffer)); + + case (byte)135: + return SignedPayloadsResultDto.fromMap((Map) readValue(buffer)); + + default: + return super.readValueOfType(type, buffer); + + } + } + @Override + protected void writeValue(ByteArrayOutputStream stream, Object value) { + if (value instanceof AuthorizeRequestDto) { + stream.write(128); + writeValue(stream, ((AuthorizeRequestDto) value).toMap()); + } else + if (value instanceof AuthorizeResultDto) { + stream.write(129); + writeValue(stream, ((AuthorizeResultDto) value).toMap()); + } else + if (value instanceof ReauthorizeRequestDto) { + stream.write(130); + writeValue(stream, ((ReauthorizeRequestDto) value).toMap()); + } else + if (value instanceof SignAndSendTransactionsRequestDto) { + stream.write(131); + writeValue(stream, ((SignAndSendTransactionsRequestDto) value).toMap()); + } else + if (value instanceof SignMessagesRequestDto) { + stream.write(132); + writeValue(stream, ((SignMessagesRequestDto) value).toMap()); + } else + if (value instanceof SignTransactionsRequestDto) { + stream.write(133); + writeValue(stream, ((SignTransactionsRequestDto) value).toMap()); + } else + if (value instanceof SignaturesResultDto) { + stream.write(134); + writeValue(stream, ((SignaturesResultDto) value).toMap()); + } else + if (value instanceof SignedPayloadsResultDto) { + stream.write(135); + writeValue(stream, ((SignedPayloadsResultDto) value).toMap()); + } else +{ + super.writeValue(stream, value); + } + } + } + + /** Generated class from Pigeon that represents Flutter messages that can be called from Java.*/ + public static class ApiFlutter { + private final BinaryMessenger binaryMessenger; + public ApiFlutter(BinaryMessenger argBinaryMessenger){ + this.binaryMessenger = argBinaryMessenger; + } + public interface Reply { + void reply(T reply); + } + static MessageCodec getCodec() { + return ApiFlutterCodec.INSTANCE; + } + + public void onScenarioReady(@NonNull Long idArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.onScenarioReady", getCodec()); + channel.send(new ArrayList(Arrays.asList(idArg)), channelReply -> { + callback.reply(null); + }); + } + public void onScenarioServingClients(@NonNull Long idArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.onScenarioServingClients", getCodec()); + channel.send(new ArrayList(Arrays.asList(idArg)), channelReply -> { + callback.reply(null); + }); + } + public void onScenarioServingComplete(@NonNull Long idArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.onScenarioServingComplete", getCodec()); + channel.send(new ArrayList(Arrays.asList(idArg)), channelReply -> { + callback.reply(null); + }); + } + public void onScenarioComplete(@NonNull Long idArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.onScenarioComplete", getCodec()); + channel.send(new ArrayList(Arrays.asList(idArg)), channelReply -> { + callback.reply(null); + }); + } + public void onScenarioError(@NonNull Long idArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.onScenarioError", getCodec()); + channel.send(new ArrayList(Arrays.asList(idArg)), channelReply -> { + callback.reply(null); + }); + } + public void onScenarioTeardownComplete(@NonNull Long idArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.onScenarioTeardownComplete", getCodec()); + channel.send(new ArrayList(Arrays.asList(idArg)), channelReply -> { + callback.reply(null); + }); + } + public void authorize(@NonNull AuthorizeRequestDto requestArg, @NonNull Long idArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.authorize", getCodec()); + channel.send(new ArrayList(Arrays.asList(requestArg, idArg)), channelReply -> { + @SuppressWarnings("ConstantConditions") + AuthorizeResultDto output = (AuthorizeResultDto)channelReply; + callback.reply(output); + }); + } + public void reauthorize(@NonNull ReauthorizeRequestDto requestArg, @NonNull Long idArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.reauthorize", getCodec()); + channel.send(new ArrayList(Arrays.asList(requestArg, idArg)), channelReply -> { + @SuppressWarnings("ConstantConditions") + Boolean output = (Boolean)channelReply; + callback.reply(output); + }); + } + public void signTransactions(@NonNull SignTransactionsRequestDto requestArg, @NonNull Long idArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.signTransactions", getCodec()); + channel.send(new ArrayList(Arrays.asList(requestArg, idArg)), channelReply -> { + @SuppressWarnings("ConstantConditions") + SignedPayloadsResultDto output = (SignedPayloadsResultDto)channelReply; + callback.reply(output); + }); + } + public void signMessages(@NonNull SignMessagesRequestDto requestArg, @NonNull Long idArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.signMessages", getCodec()); + channel.send(new ArrayList(Arrays.asList(requestArg, idArg)), channelReply -> { + @SuppressWarnings("ConstantConditions") + SignedPayloadsResultDto output = (SignedPayloadsResultDto)channelReply; + callback.reply(output); + }); + } + public void signAndSendTransactions(@NonNull SignAndSendTransactionsRequestDto requestArg, @NonNull Long idArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiFlutter.signAndSendTransactions", getCodec()); + channel.send(new ArrayList(Arrays.asList(requestArg, idArg)), channelReply -> { + @SuppressWarnings("ConstantConditions") + SignaturesResultDto output = (SignaturesResultDto)channelReply; + callback.reply(output); + }); + } + } + private static class ApiHostCodec extends StandardMessageCodec { + public static final ApiHostCodec INSTANCE = new ApiHostCodec(); + private ApiHostCodec() {} + } + + /** Generated interface from Pigeon that represents a handler of messages from Flutter.*/ + public interface ApiHost { + void start(@NonNull Long id); + void close(@NonNull Long id); + + /** The codec used by ApiHost. */ + static MessageCodec getCodec() { + return ApiHostCodec.INSTANCE; + } + + /** Sets up an instance of `ApiHost` to handle messages through the `binaryMessenger`. */ + static void setup(BinaryMessenger binaryMessenger, ApiHost api) { + { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiHost.start", getCodec()); + if (api != null) { + channel.setMessageHandler((message, reply) -> { + Map wrapped = new HashMap<>(); + try { + ArrayList args = (ArrayList)message; + Number idArg = (Number)args.get(0); + if (idArg == null) { + throw new NullPointerException("idArg unexpectedly null."); + } + api.start((idArg == null) ? null : idArg.longValue()); + wrapped.put("result", null); + } + catch (Error | RuntimeException exception) { + wrapped.put("error", wrapError(exception)); + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.ApiHost.close", getCodec()); + if (api != null) { + channel.setMessageHandler((message, reply) -> { + Map wrapped = new HashMap<>(); + try { + ArrayList args = (ArrayList)message; + Number idArg = (Number)args.get(0); + if (idArg == null) { + throw new NullPointerException("idArg unexpectedly null."); + } + api.close((idArg == null) ? null : idArg.longValue()); + wrapped.put("result", null); + } + catch (Error | RuntimeException exception) { + wrapped.put("error", wrapError(exception)); + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } + } + } + private static Map wrapError(Throwable exception) { + Map errorMap = new HashMap<>(); + errorMap.put("message", exception.toString()); + errorMap.put("code", exception.getClass().getSimpleName()); + errorMap.put("details", "Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception)); + return errorMap; + } +} diff --git a/packages/solana_mobile_wallet/android/src/main/kotlin/com/solana/solana_mobile_wallet/ScenarioProxy.kt b/packages/solana_mobile_wallet/android/src/main/kotlin/com/solana/solana_mobile_wallet/ScenarioProxy.kt new file mode 100644 index 0000000000..ddd697d0c5 --- /dev/null +++ b/packages/solana_mobile_wallet/android/src/main/kotlin/com/solana/solana_mobile_wallet/ScenarioProxy.kt @@ -0,0 +1,180 @@ +package com.solana.solana_mobile_wallet + +import android.net.Uri +import android.os.Handler +import android.os.Looper +import com.solana.mobilewalletadapter.walletlib.scenario.* +import io.flutter.plugin.common.BinaryMessenger +import java.lang.IllegalArgumentException + +object ApiHost : Api.ApiHost { + private val scenarios = mutableMapOf() + + fun init(binaryMessenger: BinaryMessenger) { + Api.ApiHost.setup(binaryMessenger, this) + } + + fun register(id: Long, scenario: Scenario) { + scenarios[id] = scenario + } + + fun unregister(id: Long) { + scenarios.remove(id) + } + + override fun start(id: Long) { + scenarios[id]?.start() + } + + override fun close(id: Long) { + scenarios[id]?.close() + } +} + +class Callbacks( + private val id: Long, + binaryMessenger: BinaryMessenger, + private val onTeardownComplete: () -> Unit +) : Scenario.Callbacks { + private val api = Api.ApiFlutter(binaryMessenger) + + override fun onScenarioReady() { + Handler(Looper.getMainLooper()).post { api.onScenarioReady(id) {} } + } + + override fun onScenarioServingClients() { + Handler(Looper.getMainLooper()).post { api.onScenarioServingClients(id) {} } + } + + override fun onScenarioServingComplete() { + Handler(Looper.getMainLooper()).post { api.onScenarioServingComplete(id) {} } + } + + override fun onScenarioComplete() { + Handler(Looper.getMainLooper()).post { api.onScenarioComplete(id) {} } + } + + override fun onScenarioError() { + Handler(Looper.getMainLooper()).post { api.onScenarioError(id) {} } + } + + override fun onScenarioTeardownComplete() { + Handler(Looper.getMainLooper()).post { api.onScenarioTeardownComplete(id) {} } + onTeardownComplete() + } + + override fun onAuthorizeRequest(request: AuthorizeRequest) { + val dto = Api.AuthorizeRequestDto.Builder() + .setIconUri(request.iconRelativeUri?.toString()) + .setIdentityName(request.identityName) + .setIdentityUri(request.identityUri?.toString()) + .build() + + Handler(Looper.getMainLooper()).post { + api.authorize(dto, id) { result -> + if (result == null) { + request.completeWithDecline() + } else { + request.completeWithAuthorize( + result.publicKey, + result.accountLabel, + if (result.walletUriBase == null) null else Uri.parse(result.walletUriBase), + result.scope, + ) + } + } + } + } + + override fun onReauthorizeRequest(request: ReauthorizeRequest) { + val dto = Api.ReauthorizeRequestDto.Builder() + .setIdentityName(request.identityName) + .setIdentityUri(request.identityUri?.toString()) + .setIconRelativeUri(request.iconRelativeUri?.toString()) + .setCluster(request.cluster) + .setAuthorizationScope(request.authorizationScope) + .build() + + Handler(Looper.getMainLooper()).post { + api.reauthorize(dto, id) { result -> + if (result == true) { + request.completeWithReauthorize() + } else { + request.completeWithDecline() + } + } + } + } + + override fun onSignTransactionsRequest(request: SignTransactionsRequest) { + val dto = Api.SignTransactionsRequestDto.Builder() + .setIdentityName(request.identityName) + .setIdentityUri(request.identityUri?.toString()) + .setIconRelativeUri(request.iconRelativeUri?.toString()) + .setCluster(request.cluster) + .setAuthorizationScope(request.authorizationScope) + .setPayloads(request.payloads.toList()) + .build() + + Handler(Looper.getMainLooper()).post { + api.signTransactions(dto, id) { + when (it.error) { + Api.MobileWalletAdapterServerException.requestDeclined -> request.completeWithDecline() + Api.MobileWalletAdapterServerException.invalidPayloads -> request.completeWithInvalidPayloads(it.validPayloads!!.toBooleanArray()) + Api.MobileWalletAdapterServerException.tooManyPayloads -> request.completeWithTooManyPayloads() + Api.MobileWalletAdapterServerException.authorizationNotValid -> request.completeWithAuthorizationNotValid() + null -> request.completeWithSignedPayloads(it.payloads!!.toTypedArray()) + } + } + } + } + + override fun onSignMessagesRequest(request: SignMessagesRequest) { + val dto = Api.SignMessagesRequestDto.Builder() + .setIdentityName(request.identityName) + .setIdentityUri(request.identityUri?.toString()) + .setIconRelativeUri(request.iconRelativeUri?.toString()) + .setCluster(request.cluster) + .setAuthorizationScope(request.authorizationScope) + .setPayloads(request.payloads.toList()) + .build() + + Handler(Looper.getMainLooper()).post { + api.signMessages(dto, id) { + when (it.error) { + Api.MobileWalletAdapterServerException.requestDeclined -> request.completeWithDecline() + Api.MobileWalletAdapterServerException.invalidPayloads -> request.completeWithInvalidPayloads(it.validPayloads!!.toBooleanArray()) + Api.MobileWalletAdapterServerException.tooManyPayloads -> request.completeWithTooManyPayloads() + Api.MobileWalletAdapterServerException.authorizationNotValid -> request.completeWithAuthorizationNotValid() + null -> request.completeWithSignedPayloads(it.payloads!!.toTypedArray()) + } + } + } + } + + override fun onSignAndSendTransactionsRequest(request: SignAndSendTransactionsRequest) { + val dto = Api.SignAndSendTransactionsRequestDto.Builder() + .setIdentityName(request.identityName) + .setIdentityUri(request.identityUri?.toString()) + .setIconRelativeUri(request.iconRelativeUri?.toString()) + .setCluster(request.cluster) + .setAuthorizationScope(request.authorizationScope) + .setTransactions(request.payloads.toList()) + .setMinContextSlot(request.minContextSlot?.toLong()) + .setPublicKey(request.publicKey) + .build() + + Handler(Looper.getMainLooper()).post { + api.signAndSendTransactions(dto, id) { + when (it.error) { + Api.MobileWalletAdapterServerException.requestDeclined -> request.completeWithDecline() + Api.MobileWalletAdapterServerException.invalidPayloads -> request.completeWithInvalidSignatures(it.validSignatures!!.toBooleanArray()) + Api.MobileWalletAdapterServerException.tooManyPayloads -> request.completeWithTooManyPayloads() + Api.MobileWalletAdapterServerException.authorizationNotValid -> request.completeWithAuthorizationNotValid() + null -> request.completeWithSignatures(it.signatures!!.toTypedArray()) + } + } + } + } + +} diff --git a/packages/sms_wallet/android/src/main/kotlin/com/solana/sms_wallet/SmsWalletPlugin.kt b/packages/solana_mobile_wallet/android/src/main/kotlin/com/solana/solana_mobile_wallet/SolanaMobileWalletPlugin.kt similarity index 95% rename from packages/sms_wallet/android/src/main/kotlin/com/solana/sms_wallet/SmsWalletPlugin.kt rename to packages/solana_mobile_wallet/android/src/main/kotlin/com/solana/solana_mobile_wallet/SolanaMobileWalletPlugin.kt index 5cb33cad68..035bd5e95a 100644 --- a/packages/sms_wallet/android/src/main/kotlin/com/solana/sms_wallet/SmsWalletPlugin.kt +++ b/packages/solana_mobile_wallet/android/src/main/kotlin/com/solana/solana_mobile_wallet/SolanaMobileWalletPlugin.kt @@ -1,4 +1,4 @@ -package com.solana.sms_wallet +package com.solana.solana_mobile_wallet import android.content.Context import android.content.Intent @@ -17,7 +17,7 @@ import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel.MethodCallHandler import io.flutter.plugin.common.MethodChannel.Result -class SmsWalletPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { +class SolanaMobileWalletPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { private lateinit var channel: MethodChannel private var intent: Intent? = null private lateinit var context: Context @@ -98,6 +98,6 @@ class SmsWalletPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { override fun onDetachedFromActivity() = Unit companion object { - private const val TAG = "SmsWalletPlugin" + private const val TAG = "SolanaMobileWalletPlugin" } } diff --git a/packages/sms_wallet/example/.gitignore b/packages/solana_mobile_wallet/example/.gitignore similarity index 100% rename from packages/sms_wallet/example/.gitignore rename to packages/solana_mobile_wallet/example/.gitignore diff --git a/packages/sms_wallet/example/Makefile b/packages/solana_mobile_wallet/example/Makefile similarity index 100% rename from packages/sms_wallet/example/Makefile rename to packages/solana_mobile_wallet/example/Makefile diff --git a/packages/sms_wallet/example/README.md b/packages/solana_mobile_wallet/example/README.md similarity index 85% rename from packages/sms_wallet/example/README.md rename to packages/solana_mobile_wallet/example/README.md index ff02ab542a..573e2c9755 100644 --- a/packages/sms_wallet/example/README.md +++ b/packages/solana_mobile_wallet/example/README.md @@ -1,6 +1,6 @@ -# sms_wallet_example +# solana_mobile_wallet_example -Demonstrates how to use the sms_wallet plugin. +Demonstrates how to use the solana_mobile_wallet plugin. ## Getting Started diff --git a/packages/sms_wallet/example/analysis_options.yaml b/packages/solana_mobile_wallet/example/analysis_options.yaml similarity index 100% rename from packages/sms_wallet/example/analysis_options.yaml rename to packages/solana_mobile_wallet/example/analysis_options.yaml diff --git a/packages/sms_wallet/example/android/.gitignore b/packages/solana_mobile_wallet/example/android/.gitignore similarity index 100% rename from packages/sms_wallet/example/android/.gitignore rename to packages/solana_mobile_wallet/example/android/.gitignore diff --git a/packages/sms_wallet/example/android/app/build.gradle b/packages/solana_mobile_wallet/example/android/app/build.gradle similarity index 97% rename from packages/sms_wallet/example/android/app/build.gradle rename to packages/solana_mobile_wallet/example/android/app/build.gradle index a92c2cf4a4..fdbc5d92b1 100644 --- a/packages/sms_wallet/example/android/app/build.gradle +++ b/packages/solana_mobile_wallet/example/android/app/build.gradle @@ -44,7 +44,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.solana.sms_wallet_example" + applicationId "com.solana.solana_mobile_wallet_example" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. minSdkVersion 23 diff --git a/packages/sms_wallet/example/android/app/src/debug/AndroidManifest.xml b/packages/solana_mobile_wallet/example/android/app/src/debug/AndroidManifest.xml similarity index 87% rename from packages/sms_wallet/example/android/app/src/debug/AndroidManifest.xml rename to packages/solana_mobile_wallet/example/android/app/src/debug/AndroidManifest.xml index 48936d375a..79b7751c7a 100644 --- a/packages/sms_wallet/example/android/app/src/debug/AndroidManifest.xml +++ b/packages/solana_mobile_wallet/example/android/app/src/debug/AndroidManifest.xml @@ -1,5 +1,5 @@ + package="com.solana.solana_mobile_wallet_example">