Skip to content

Commit

Permalink
feat: dart auth providers (#405)
Browse files Browse the repository at this point in the history
* feat: structure

* feat: working project scoped token

* feat: example

* chore: revert import order change

* chore: removed unused dotenv

* fix: simplify Environment

* fix: improve environment lookup

* fix: make constructor private so only Environment class can make new instance

* fix: revert environments as public

* feat: dart consumer auth provider (#407)

* fix: simplify Environment

* fix: improve environment lookup

* fix: make constructor private so only Environment class can make new instance

* fix: revert environments as public

* fix: env names and consumer url tests

---------

Co-authored-by: Earl Grant Reyes <earl.r@affinidi.com>
Co-authored-by: Carlos Rincon <“carlos.r@affinidi.com”>

* fix: add consumerCisUrl

* feat: iota and improved examples with dotenv

* feat: token refresh

* feat: add JS wallet service from Vault

* fix: remove redundant Consumer base URL

* feat: initial implementation of Consumer Auth Provider

* feat: add temporary Token provider

* feat: add fetchConsumerCisUrl test

* fix: use seed instead of mnemonic

* fix: updated implementation using encryptedSeed

* fix: remove unused code

* fix: update implementation to use encryptedSeed

* fix: move wallet material to constructor

* fix: rename environment types for consistency

* fix: extract common endpoints

* fix: rename package to affinidi_tdk_consumer_auth_provider

* fix: rename package folder to consumer_auth_provider

* fix: removed old file

* fix: refactor

* fix: rename packages correctly

* feat: dart auth provider tests (#439)

* feat: dart auth provider tests

* feat: encrypted key tests

* chore: test group name

* chore: use mock vars

* fix: type and var fixes

---------

Co-authored-by: Carlos Rincon <“carlos.r@affinidi.com”>

* fix: add check for existing token

* chore: gitignored fvmrc

* feat: add check for expiration

* fix: env in integration test

* fix: update integration test

* feat: decrypt encrypted seed (#463)

* fix: add test decryption

* fix: add seed decryption

* fix: use correct environment

---------

Co-authored-by: Earl Grant Reyes <earl.r@affinidi.com>

* chore: remove leftover file

* feat: add script to generate dart code

* fix: move decryptSeed into the CryptographyService

* feat: move AesCbcEncryptionService to affinidi_cryptography_service

* chore: dart integration tests (#468)

* feat: integration tests

* chore: consumer auth provider integration tests

* fix: private vars

* chore: ignore pubspec.lock

* chore: ignore pubspec.lock

* docs: updated readme

---------

Co-authored-by: Carlos Rincon <“carlos.r@affinidi.com”>

* fix: refresh token on all verification failures

* feat: add dart docs

* chore: remove API section

* fix: fix Dart code generation

* chore: test signed commit

* feat: add consumer abstraction

* chore: add VDM as example

* feat: workspace (#488)

Co-authored-by: Carlos Rincon <“carlos.r@affinidi.com”>

* chore: change to TDK

* chore: updated package descriptions

* chore: move docs from base implementation

* fix: initiate tokenProvider from constructor

* feat: add CryptographyService abstraction

* feat: add abstraction, docs, joined cryptography in one service

---------

Co-authored-by: Carlos Rincon <“carlos.r@affinidi.com”>
Co-authored-by: Earl Grant Reyes <earl.r@affinidi.com>
Co-authored-by: hpelitebook745G2 <ambiguous.exe4585@gmail.com>
Co-authored-by: hpelitebook745G2 <27658429+hpelitebook745G2@users.noreply.github.com>
  • Loading branch information
5 people authored Jan 21, 2025
1 parent 69d6bf0 commit b0287b3
Show file tree
Hide file tree
Showing 73 changed files with 3,420 additions and 20 deletions.
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,15 @@ testem.log
Thumbs.db

.nx
.vscode
.vscode

# Created by `dart pub`
.dart_tool/

# Avoid committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock

# env files
.env*
!.env.example
54 changes: 35 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Affinidi Trust Development Kit (Affinidi TDK)

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

[![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#contributors-)

<!-- ALL-CONTRIBUTORS-BADGE:END -->

The Affinidi Trust Development Kit (Affinidi TDK) is a modern interface that allows you to easily manage and integrate [Affinidi Elements](https://www.affinidi.com/product/affinidi-elements) and [Frameworks](https://www.affinidi.com/developer#lota-framework) into your application. It minimises dependencies and enables developers seamless entry into the [Affinidi Trust Network (ATN)](https://www.affinidi.com/get-started).
Expand All @@ -17,25 +20,38 @@ Each module has its own README that you can check to better understand how to in

## Available modules

The Affinidi TDK offers the following modules and support to programming languages:



| | TypeScript | Python | Dart | PHP |
|----------- |-----------------------|-----------------------|----------------------|---------------------|
|**Packages** | | | |
|[auth-provider](packages/auth-provider/) | 🟢 | 🟢 | 🔴 | [🟢 Link](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/AuthProvider) |
|[common](packages/common/) | 🟢 | 🟢 | 🔴 | [🟢 Link](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Common) |
|**Packages** | | | |
|credential-issuance-client | [🟢 Link](clients/typescript/credential-issuance-client/) | [🟢 Link](clients/python/credential_issuance_client/) | [🟡 Link](clients/dart/credential_issuance_client/) | [🟢 Link](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/CredentialIssuanceClient) |
|credential-verification-client | [🟢 Link](clients/typescript/credential-verification-client/) | [🟢 Link](clients/python/credential_verification_client/) | [🟡 Link](clients/dart/credential_verification_client/) | [🟢 Link](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/CredentialVerificationClient) |
|iam-client | [🟢 Link](clients/typescript/iam-client/) | [🟢 Link](clients/python/iam_client/) | [🟡 Link](clients/dart/iam_client/) | [🟢 Link](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/IamClient) |
|iota-client | [🟢 Link](clients/typescript/iota-client/) | [🟢 Link](clients/python/iota_client/) | [🟡 Link](clients/dart/iota_client/) | [🟢 Link](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/IotaClient) |
|login-configuration-client | [🟢 Link](clients/typescript/login-configuration-client/) | [🟢 Link](clients/python/login_configuration_client/) | [🟡 Link](clients/dart/login_configuration_client/) | [🟢 Link](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/LoginConfigurationClient) |
|wallets-client | [🟢 Link](clients/typescript/wallets-client/) | [🟢 Link](clients/python/wallets_client/) | [🟡 Link](clients/dart/wallets_client/) | [🟢 Link](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/WalletsClient) |
|**Libraries** | | | |
|[iota-browser](libs/iota-browser/) | 🟢 | 🔴 | 🔴 | 🔴 |
|[iota-core](libs/iota-core/) | 🟢 | 🟢 | 🔴 | 🔴 |
The Affinidi TDK offers several modules depending on the type of application you are using and the programming language.

### For vault applications

If you are building a vault application that manages user's data, you will be interested in the following packages:

| | TypeScript | Dart |
| ------------------------- | -------------------------------------------------------- | -------------------------------------------------- |
| **Packages** | | |
| consumer-auth-provider | 🔴 | [🟡 Link](packages/dart/consumer_auth_provider/) |
| **Clients** | | |
| vault-data-manager-client | [🟡 Link](clients/typescript/vault-data-manager-client/) | [🟡 Link](clients/dart/vault_data_manager_client/) |

### For issuer/verifier applications

If you are building a site that issues or requests data from the user vaults you will be interested in the following packages:

| | TypeScript | Python | Dart | PHP |
| ------------------------------ | ------------------------------------------------------------- | --------------------------------------------------------- | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| **Packages** | | | |
| auth-provider | [🟢 Link](packages/jsii/auth-provider/) | 🟢 | [🟡 Link](packages/dart/auth_provider/) | [🟢 Link](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/AuthProvider) |
| common | [🟢 Link](packages/jsii/common/) | 🟢 | 🔴 | [🟢 Link](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Common) |
| **Clients** | | | |
| credential-issuance-client | [🟢 Link](clients/typescript/credential-issuance-client/) | [🟢 Link](clients/python/credential_issuance_client/) | [🟡 Link](clients/dart/credential_issuance_client/) | [🟢 Link](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/CredentialIssuanceClient) |
| credential-verification-client | [🟢 Link](clients/typescript/credential-verification-client/) | [🟢 Link](clients/python/credential_verification_client/) | [🟡 Link](clients/dart/credential_verification_client/) | [🟢 Link](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/CredentialVerificationClient) |
| iam-client | [🟢 Link](clients/typescript/iam-client/) | [🟢 Link](clients/python/iam_client/) | [🟡 Link](clients/dart/iam_client/) | [🟢 Link](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/IamClient) |
| iota-client | [🟢 Link](clients/typescript/iota-client/) | [🟢 Link](clients/python/iota_client/) | [🟡 Link](clients/dart/iota_client/) | [🟢 Link](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/IotaClient) |
| login-configuration-client | [🟢 Link](clients/typescript/login-configuration-client/) | [🟢 Link](clients/python/login_configuration_client/) | [🟡 Link](clients/dart/login_configuration_client/) | [🟢 Link](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/LoginConfigurationClient) |
| wallets-client | [🟢 Link](clients/typescript/wallets-client/) | [🟢 Link](clients/python/wallets_client/) | [🟡 Link](clients/dart/wallets_client/) | [🟢 Link](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/WalletsClient) |
| **Libraries** | | | |
| iota-browser | [🟢 Link](libs/iota-browser/) | 🔴 | 🔴 | 🔴 |
| iota-core | [🟢 Link](libs/iota-core/) | 🟢 | 🔴 | 🔴 |

<br />
🟢 Supported <br />
Expand Down
1 change: 1 addition & 0 deletions packages/dart/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.fvmrc
10 changes: 10 additions & 0 deletions packages/dart/auth_provider/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Personal access token
PROJECT_ID=""
TOKEN_ID=""
PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"
PASSPHRASE="" # Optional. Required if private key is encrypted
KEY_ID="" # Optional. Required if token's key id is different from token id

# Iota (Websocket)
IOTA_CONFIG_ID=""
DID="" # Usually obtained at runtime from the registered user
11 changes: 11 additions & 0 deletions packages/dart/auth_provider/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

# Avoid committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock

# env files
.env*
!.env.example
3 changes: 3 additions & 0 deletions packages/dart/auth_provider/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

- Initial version.
39 changes: 39 additions & 0 deletions packages/dart/auth_provider/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->

TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.

## Features

TODO: List what your package can do. Maybe include images, gifs, or videos.

## Getting started

TODO: List prerequisites and provide or point to information on how to
start using the package.

## Usage

TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.

```dart
const like = 'sample';
```

## Additional information

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
30 changes: 30 additions & 0 deletions packages/dart/auth_provider/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
33 changes: 33 additions & 0 deletions packages/dart/auth_provider/example/iota_token.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:dotenv/dotenv.dart';

void main() async {
var env = DotEnv()..load();
if (!env.isEveryDefined(
['PROJECT_ID', 'TOKEN_ID', 'PRIVATE_KEY', 'IOTA_CONFIG_ID', 'DID'])) {
print(
'Missing environment variables. Please provide PROJECT_ID, TOKEN_ID, PRIVATE_KEY, DID');
return;
}
// Workaround for dotenv multiline limitations
final privateKey = env['PRIVATE_KEY']!.replaceAll('\\n', '\n');

final provider = AuthProvider(
projectId: env['PROJECT_ID']!,
tokenId: env['TOKEN_ID']!,
privateKey: privateKey,
// Optional parameters
keyId: env['KEY_ID'],
passphrase: env['PASSPHRASE'],
);

try {
// Fetch iota token (websocket). Did is usually obtained at runtime from the registered user
final iotaToken = provider.createIotaToken(
iotaConfigId: env['IOTA_CONFIG_ID']!, did: env['DID']!);
print('Successfully obtained iota token:');
print(iotaToken);
} catch (e) {
print('Error obtaining token: $e');
}
}
31 changes: 31 additions & 0 deletions packages/dart/auth_provider/example/project_scoped_token.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:dotenv/dotenv.dart';

void main() async {
final env = DotEnv(includePlatformEnvironment: true)..load();
if (!env.isEveryDefined(['PROJECT_ID', 'TOKEN_ID', 'PRIVATE_KEY'])) {
print(
'Missing environment variables. Please provide PROJECT_ID, TOKEN_ID, PRIVATE_KEY');
return;
}
// Workaround for dotenv multiline limitations
final privateKey = env['PRIVATE_KEY']!.replaceAll('\\n', '\n');

final provider = AuthProvider(
projectId: env['PROJECT_ID']!,
tokenId: env['TOKEN_ID']!,
privateKey: privateKey,
// Optional parameters
keyId: env['KEY_ID'],
passphrase: env['PASSPHRASE'],
);

try {
// Fetch project scoped token
final projectScopedToken = await provider.fetchProjectScopedToken();
print('Successfully obtained project scoped token:');
print(projectScopedToken);
} catch (e) {
print('Error obtaining token: $e');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// Support for doing something awesome.
///
/// More dartdocs go here.
library;

export 'src/auth_provider.dart';

// TODO: Export any libraries intended for clients of this package.
Loading

0 comments on commit b0287b3

Please sign in to comment.