Skip to content

matteo-ms/polygonid-flutter-sdk

 
 

Repository files navigation

Polygon ID Flutter SDK

pub package build codecov license license

Description

This is a Flutter plugin for the Polygon ID SDK, which allows you to integrate Polygon ID identity system into your Flutter apps.

Installation

To use this plugin, add polygonid_flutter_sdk as a dependency in your pubspec.yaml file like this

dependencies:
  polygonid_flutter_sdk: ^x.y.z

This will get you the latest version.

If you want to test a specific branch of the repository, pull polygonid_flutter_sdk like this

dependencies:
  polygonid_flutter_sdk:
      git:
        url: ssh://[email protected]/iden3/polygonid-flutter-sdk.git
        ref: branchPathName

Environment

App side

You need to set the environment you are working on in the SDK.

You can either set the environment during initialization (with env parameter) or later with PolygonIdSdk.setEnv().

The environment object is EnvEntity with:

  final String blockchain; # The name of the blockchain (eg: polygon)
  final String network; # The network of the blockchain (eg: mumbai)
  final String web3Url; # URL of the blockchain (eg: https://polygon-mumbai.infura.io/v3/)
  final String web3RdpUrl; # RDP URL (eg: wss://polygon-mumbai.infura.io/v3/)
  final String web3ApiKey; # The API key of the web3 URL service (eg: YOUR-INFURA-API-KEY)
  final String idStateContract; # The ID state contract (eg: 0x134B1BE34911E39A8397ec6289782989729807a4)
  final String pushUrl; # The push notification URL (eg: https://push-staging.polygonid.com/api/v1)

An example of initialization:

import 'package:flutter/material.dart';
import 'package:polygonid_flutter_sdk/sdk/polygon_id_sdk.dart';

Future<void> main() async {
  await PolygonIdSdk.init(env: EnvEntity(
      blockchain: 'polygon',
      network: 'mumbai',
      web3Url: 'https://polygon-mumbai.infura.io/v3/',
      web3RdpUrl: 'wss://polygon-mumbai.infura.io/v3/',
      web3ApiKey: 'YOUR-INFURA-API-KEY',
      idStateContract: '0x134B1BE34911E39A8397ec6289782989729807a4',
      pushUrl: 'https://push-staging.polygonid.com/api/v1',
  ));
  runApp(const App());
}

Supported Environments

Environment Polygon Mumbai Polygon Main
blockchain polygon polygon
network mumbai main
web3Url https://polygon-mumbai.infura.io/v3/ https://polygon-mainnet.infura.io/v3/
web3RdpUrl wss://polygon-mumbai.infura.io/v3/ wss://polygon-mainnet.infura.io/v3/
idStateContract 0x134B1BE34911E39A8397ec6289782989729807a4 0x624ce98D2d27b20b8f8d521723Df8fC4db71D79D
pushUrl https://push-staging.polygonid.com/api/v1 https://push-staging.polygonid.com/api/v1

If you want to deploy your own State Contract, please check the contract documentation.

You can get the current env using PolygonIdSdk.getEnv().

Deploy and check

Deploy

  1. Clone this repository.
  2. Run build_runner to generate .g.dart files:
flutter pub run build_runner build --delete-conflicting-outputs

For iOS only:

  1. Add to your app's Podfile the following post_install code:
post_install do |installer|  
  installer.pods_project.targets.each do |target|
    ...
    end
    # polygonid-setup
      target.build_configurations.each do |config|
        cflags = config.build_settings['OTHER_CFLAGS'] || ['$(inherited)']
        cflags << '-fembed-bitcode'
        config.build_settings['OTHER_CFLAGS'] = cflags
        config.build_settings['SWIFT_VERSION'] = '5.0'
        config.build_settings['ENABLE_BITCODE'] = 'NO'
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0'
        config.build_settings['STRIP_STYLE'] = 'non-global'
      end
    if target.name == "Pods-Runner"
      puts "Updating #{target.name} OTHER_LDFLAGS"
      target.build_configurations.each do |config|
                      xcconfig_path = config.base_configuration_reference.real_path
                      xcconfig = File.read(xcconfig_path)
                      new_xcconfig = xcconfig.sub('OTHER_LDFLAGS = $(inherited)', 'OTHER_LDFLAGS = $(inherited) -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/librapidsnark.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_authV2.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryMTPV2.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQuerySigV2.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryMTPV2OnChain.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQuerySigV2OnChain.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libfr.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libgmp.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libpolygonid.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libbabyjubjub.a"')
                      File.open(xcconfig_path, "w") { |file| file << new_xcconfig }
         end
     end
  end
end

Usage

To integrate Polygon ID Flutter SDK into your Flutter app, follow these steps:

  1. Import the polygonid_flutter_sdk package:
import 'package:polygonid_flutter_sdk/sdk/polygon_id_sdk.dart';
  1. Initialize the Polygon ID Flutter SDK with your environment:
await PolygonIdSdk.init(env: EnvEntity(
      blockchain: 'polygon',
      network: 'mumbai',
      web3Url: 'https://polygon-mumbai.infura.io/v3/',
      web3RdpUrl: 'wss://polygon-mumbai.infura.io/v3/',
      web3ApiKey: 'YOUR-INFURA-API-KEY',
      idStateContract: '0x134B1BE34911E39A8397ec6289782989729807a4',
      pushUrl: 'https://push-staging.polygonid.com/api/v1',
  ));
  1. To be able to authenticate with issuers or verifiers, fetch credentials and generate proofs, you need to download the proof circuit files.
Stream<DownloadInfo> stream =
        await PolygonIdSdk.I.proof.initCircuitsDownloadAndGetInfoStream;

For more information on how to use the PolygonID Flutter SDK, please check the example app included in the repository and follow the Polygon ID Wallet SDK Documentation

Issues and Contributions

If you encounter any issues with this SDK, please file an issue. Contributions are also welcome - simply fork this repository, make your changes, and submit a pull request.

Resources

Notes

P.S. Using iOS simulator for testing wallet sdk is right now under maintenance and will be available soon.

About

Flutter Plugin to use the Polygon ID SDK

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Dart 70.3%
  • C 24.5%
  • Rust 2.5%
  • Objective-C 1.7%
  • Ruby 0.3%
  • Makefile 0.2%
  • Other 0.5%