2using System.Globalization;
3using System.Reflection;
40 public ContractOrchestratorService()
44 public override Task Load(
bool IsResuming, CancellationToken CancellationToken)
46 if (this.
BeginLoad(IsResuming, CancellationToken))
48 ServiceRef.XmppService.ConnectionStateChanged += this.Contracts_ConnectionStateChanged;
49 ServiceRef.XmppService.PetitionForPeerReviewIdReceived += this.Contracts_PetitionForPeerReviewIdReceived;
50 ServiceRef.XmppService.PetitionForIdentityReceived += this.Contracts_PetitionForIdentityReceived;
51 ServiceRef.XmppService.PetitionForSignatureReceived += this.Contracts_PetitionForSignatureReceived;
52 ServiceRef.XmppService.PetitionedIdentityResponseReceived += this.Contracts_PetitionedIdentityResponseReceived;
53 ServiceRef.XmppService.PetitionedPeerReviewIdResponseReceived += this.Contracts_PetitionedPeerReviewResponseReceived;
54 ServiceRef.XmppService.SignaturePetitionResponseReceived += this.Contracts_SignaturePetitionResponseReceived;
55 ServiceRef.XmppService.ContractProposalReceived += this.Contracts_ContractProposalRecieved;
60 return Task.CompletedTask;
63 public override Task Unload()
67 ServiceRef.XmppService.ConnectionStateChanged -= this.Contracts_ConnectionStateChanged;
68 ServiceRef.XmppService.PetitionForPeerReviewIdReceived -= this.Contracts_PetitionForPeerReviewIdReceived;
69 ServiceRef.XmppService.PetitionForIdentityReceived -= this.Contracts_PetitionForIdentityReceived;
70 ServiceRef.XmppService.PetitionForSignatureReceived -= this.Contracts_PetitionForSignatureReceived;
72 ServiceRef.XmppService.PetitionedIdentityResponseReceived -= this.Contracts_PetitionedIdentityResponseReceived;
73 ServiceRef.XmppService.PetitionedPeerReviewIdResponseReceived -= this.Contracts_PetitionedPeerReviewResponseReceived;
74 ServiceRef.XmppService.SignaturePetitionResponseReceived -= this.Contracts_SignaturePetitionResponseReceived;
75 ServiceRef.XmppService.ContractProposalReceived -= this.Contracts_ContractProposalRecieved;
80 return Task.CompletedTask;
83 #region Event Handlers
91 if (Identity?.Properties is not
null)
165 if (!Succeeded || LegalId is
null)
171 if (Identity is
null)
174 new KeyValuePair<string, object?>(
"Type", this.GetType().Name),
175 new KeyValuePair<string, object?>(
"Method", nameof(Contracts_PetitionForIdentityReceived)));
193 if (Identity is not
null)
201 await this.MarkPetitionNotificationConsumedAsync(Intent);
222 if (!Succeeded || LegalId is
null)
228 if (Identity is
null)
231 new KeyValuePair<string, object?>(
"Type", this.GetType().Name),
232 new KeyValuePair<string, object?>(
"Method", nameof(Contracts_PetitionForSignatureReceived)));
249 if (Identity is not
null)
254 await this.MarkPetitionNotificationConsumedAsync(Intent);
270 if (!e.
Response || Identity is
null)
291 if (ReviewedIdentity is
null)
305 if (ReviewerIdentity is
null)
310 StringBuilder Xml =
new();
311 ReviewedIdentity.
Serialize(Xml,
true,
true,
true,
true,
true,
true,
true);
312 string s = Xml.ToString();
313 byte[] Data = Encoding.UTF8.GetBytes(s);
326 if (!Result.HasValue || !Result.Value)
378 Presentation = NotificationPresentation.StoreOnly
381 Intent.
Extras[
"petitionId"] = e.PetitionId ??
string.Empty;
382 Intent.
Extras[
"requestedIdentityId"] = e.RequestedIdentityId ??
string.Empty;
401 Presentation = NotificationPresentation.StoreOnly
404 byte[] ContentToSign = e.ContentToSign ?? Array.Empty<
byte>();
405 string ContentToSignBase64 = Convert.ToBase64String(ContentToSign);
406 string Purpose = e.Purpose ??
string.Empty;
409 Intent.
Extras[
"signatoryId"] = e.SignatoryIdentityId ??
string.Empty;
410 Intent.
Extras[
"petitionId"] = e.PetitionId ??
string.Empty;
411 Intent.
Extras[
"requestorIdentityId"] = RequestorIdentityId;
412 Intent.
Extras[
"purpose"] = Purpose;
413 Intent.
Extras[
"contentToSign"] = ContentToSignBase64;
432 private static string ToBareJid(
string Jid)
434 if (
string.IsNullOrWhiteSpace(Jid))
437 int SlashIndex = Jid.IndexOf(
'/');
438 return SlashIndex > -1 ? Jid.Substring(0, SlashIndex) : Jid;
449 await Task.Delay(500);
451 await Task.Delay(500);
462 private async Task Contracts_ConnectionStateChanged(
object _,
XmppState NewState)
497 protected static async Task ReDownloadLegalIdentity()
525 if (Identity is not
null)
527 MainThread.BeginInvokeOnMainThread(async () =>
532 string? UserMessage =
null;
533 bool GotoRegistrationPage =
false;
537 UserMessage = ServiceRef.Localizer[nameof(AppResources.YourLegalIdentityHasBeenCompromised)];
538 await ServiceRef.TagProfile.CompromiseLegalIdentity(Identity);
539 GotoRegistrationPage = true;
543 UserMessage = ServiceRef.Localizer[nameof(AppResources.YourLegalIdentityHasBeenObsoleted)];
544 await ServiceRef.TagProfile.RevokeLegalIdentity(Identity);
545 GotoRegistrationPage = true;
549 bool HasPrivateKeys = false;
552 HasPrivateKeys = await ServiceRef.XmppService.HasPrivateKey(Identity.Id);
578 File.WriteAllText(Path.Combine(ServiceRef.StorageService.DataFolder,
"Start.txt"),
579 DateTime.Now.AddHours(1).Ticks.ToString(CultureInfo.InvariantCulture));
586 await
App.StopAsync();
593 if (GotoRegistrationPage)
598 if (!
string.IsNullOrWhiteSpace(UserMessage))
603 MainThread.BeginInvokeOnMainThread(async () =>
624 public async Task OpenLegalIdentity(
string LegalId,
string Purpose)
631 throw new TimeoutException();
634 MainThread.BeginInvokeOnMainThread(async () =>
645 MainThread.BeginInvokeOnMainThread(async () =>
656 catch (TimeoutException)
679 public async Task<LegalIdentity?> TryGetLegalIdentity(
string LegalId,
string Purpose)
691 if (!
string.IsNullOrEmpty(Purpose))
708 public async Task OpenContract(
string ContractId,
string Purpose, Dictionary<CaseInsensitiveString, object>? ParameterValues)
714 ContractReference Ref = await
Database.FindFirstDeleteRest<ContractReference>(
728 MainThread.BeginInvokeOnMainThread(async () =>
736 ContractId = Contract.ContractId
749 ParameterValues ??= [];
755 NewContractNavigationArgs e =
new(
Contract, ParameterValues);
761 ViewContractNavigationArgs e =
new(
Contract,
false);
773 MainThread.BeginInvokeOnMainThread(async () =>
796 public async Task TagSignature(
string Request)
798 int i = Request.IndexOf(
',');
803 string JID =
System.Web.HttpUtility.UrlDecode(Request[..i]);
804 string Key = Request[(i + 1)..];
826 StringBuilder Xml =
new();
828 Xml.Append(
"<ql xmlns='https://tagroot.io/schema/Signature' key='");
830 Xml.Append(
"' legalId='");
849 if (!e.
Response || Identity is
null)
Represents an instance of the Neuro-Access app.
Machine-readable names in contracts.
const string PaymentInstructionsNamespace
Namespace for payment instructions
const string Petitions
Petitions channel
static readonly TimeSpan XmppConnect
XMPP Connect timeout
XMPP Protocol Properties.
const string PersonalNumber
Personal number
const string OrgAddress2
Organization Address line 2
const string DeviceId
Device ID
const string Country
Country
const string OrgArea
Organization Area
const string Region
Region
const string OrgRegion
Organization Region
const string Nationality
Nationality
const string ZipCode
Zip Code
const string FullName
Full name
const string BirthYear
Birth Year
const string OrgCity
Organization City
const string OrgRole
Organization Role
const string Phone
Phone number
const string EMail
e-Mail address
const string OrgZipCode
Organization Zip Code
const string MiddleNames
Middle names
const string BirthDay
Birth Day
const string OrgCountry
Organization Country
const string OrgDepartment
Organization Department
const string Address2
Address line 2
const string Jid
Jabber ID
const string OrgAddress
Organization Address line 1
const string Address
Address line 1
const string LastNames
Last names
const string OrgNumber
Organization number
const string BirthMonth
Birth Month
const string FirstName
First name
const string Gender
Gender
const string OrgName
Organization name
A set of never changing property constants and helpful values.
A strongly-typed resource class, for looking up localized strings, etc.
static string YourLegalIdentity
Looks up a localized string similar to Your identity.
static string NotificationPetitionSignatureBody
Looks up a localized string similar to A new signature request is waiting..
static string AppNotConnected
Looks up a localized string similar to App is not connected to the network..
static string APetitionHasBeenSentToTheOwner
Looks up a localized string similar to A petition has been sent to the owner of the identity....
static string NotificationPetitionIdentityBody
Looks up a localized string similar to A new identity request is waiting..
static string APeerYouRequestedToReviewHasBeenRejectedDueToSignatureError
Looks up a localized string similar to A peer review you requested has been rejected,...
static string NotificationPetitionIdentityTitle
Looks up a localized string similar to Identity request from {0}.
static string Repair
Looks up a localized string similar to Repair.
static string PeerReviewRejected
Looks up a localized string similar to Peer review rejected.
static string PleaseTryAgain
Looks up a localized string similar to Please Try Again.
static string NotCompletedOnboardingError
Looks up a localized string similar to It looks like you haven’t completed the onboarding process yet...
static string Continue
Looks up a localized string similar to Continue.
static string SignaturePetitionDenied
Looks up a localized string similar to The signature petition was denied..
static string PeerReviewAccepted
Looks up a localized string similar to Peer review accepted.
static string PetitionSent
Looks up a localized string similar to Petition sent.
static string WarningTitle
Looks up a localized string similar to Warning.
static string Ok
Looks up a localized string similar to OK.
static string PetitionToViewLegalIdentityWasDenied
Looks up a localized string similar to Petition to view identity was denied..
static string LegalIdNotApproved
Looks up a localized string similar to ID not approved..
static string SomethingWentWrong
Looks up a localized string similar to Something went wrong.
static string APeerYouRequestedToReviewHasRejected
Looks up a localized string similar to A peer you requested to review your application,...
static string NotificationPetitionSignatureTitle
Looks up a localized string similar to Signature request from {0}.
static string InvalidTagSignatureId
Looks up a localized string similar to Invalid TAG Signature URI..
static string Message
Looks up a localized string similar to Message.
static string APetitionHasBeenSentToTheContract
Looks up a localized string similar to A petition has been sent to the parts of the contract....
static string ErrorTitle
Looks up a localized string similar to An error has occurred.
static string APeerReviewYouhaveRequestedHasBeenAccepted
Looks up a localized string similar to A peer review you requested has been accepted....
static string UnableToGetAccessToYourPrivateKeys
Looks up a localized string similar to The application was unable to get access to the private keys o...
bool BeginLoad(bool IsResuming, CancellationToken CancellationToken)
Sets the IsLoading flag if the service isn't already loading.
void EndLoad(bool isLoaded)
Sets the IsLoading and IsLoaded flags and fires an event representing the current load state of the s...
bool IsResuming
If App is resuming service.
bool BeginUnload()
Sets the IsLoading flag if the service isn't already unloading.
void EndUnload()
Sets the IsLoading and IsLoaded flags and fires an event representing the current load state of the s...
Notification event for identity petitions.
Platform-neutral intent describing how to route a notification.
Dictionary< string, string > Extras
Gets or sets extra data used for routing.
Base class that references services in the app.
static IServiceProvider Provider
The service provider for the app. This is set before the app is started, and will be used to resolve ...
static ILogService LogService
Log service.
static INetworkService NetworkService
Network service.
static IUiService UiService
Service serializing and managing UI-related tasks.
static INavigationService NavigationService
The navigation service for navigating between pages.
static ITagProfile TagProfile
TAG Profile service.
static IReportingStringLocalizer Localizer
Localization service
static IXmppService XmppService
The XMPP service for XMPP communication.
A page that allows the user to create a new contract.
A page that displays a specific contract.
A page to display when the user wants to view an identity.
Navigation arguments for onboarding flow. Scenario determines dynamic starting step.
A page to display when the user is asked to petition an identity.
A page to display when the user is asked to review an identity application.
Holds navigation parameters specific to views displaying a petition of a signature.
A page to display when the user is asked to petition a signature.
Event arguments for callback methods to token creation attributes queries.
string TrustProviderId
Legal ID used by the trust provider to sign contracts.
string Currency
Default currency used by the broker
decimal Commission
Minimum commission (in %) expected by the trust provider, in order to sign contract.
const string NamespaceNeuroFeatures
Namespace for Neuro-Features.
Helps with common XML-related tasks.
static string Encode(string s)
Encodes a string for use in XML.
Contains the definition of a contract
DateTime Updated
When the contract was last updated
ContractParts PartsMode
How parts are defined in the smart contract.
ContractState State
Contract state
string ContractId
Contract identity
string ForMachinesNamespace
Namespace used by the root node of the machine-readable contents of the contract (ForMachines).
Event arguments for smart contract proposals
string ContractId
ID of proposed contract.
string MessageText
Optional message to present to recipient.
string Role
Proposed role in proposed contract.
Event arguments for legal identity petitions
string RequestedIdentityId
Requested identity ID
Event arguments for legal identity petition responses
LegalIdentity RequestedIdentity
Requested identity, if accepted, null if rejected.
bool Response
If accepted (true) or rejected (false).
LegalIdentity RequestorIdentity
Legal Identity of requesting entity.
string RequestorFullJid
Full JID of requestor.
string PetitionId
Petition ID
Event arguments for digital signature petitions
string SignatoryIdentityId
Legal identity of petitioned signatory.
byte[] ContentToSign
Content to sign.
Event arguments for signature petition responses
byte[] Signature
Digital Signature petitioned, if accepted by recipient.
bool Response
If accepted (true) or rejected (false).
LegalIdentity RequestedIdentity
Requested identity, if accepted, null if rejected.
IdentityState State
Current state of identity
string Id
ID of the legal identity
void Serialize(StringBuilder Xml, bool IncludeNamespace, bool IncludeIdAttribute, bool IncludeClientSignature, bool IncludeAttachments, bool IncludeStatus, bool IncludeServerSignature, bool IncludeAttachmentReferences)
Serializes the identity to XML
Property[] Properties
Properties detailing the legal identity.
string Name
Name of property
Abstract base class of signatures
string FromBareJID
Bare JID of resource sending the message.
The requesting entity does not possess the necessary permissions to perform an action that only certa...
Represents a case-insensitive string.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static async Task Update(object Object)
Updates an object in the database.
static async Task Insert(object Object)
Inserts an object into the default collection of the database.
This filter selects objects that have a named field equal to a given value.
Orchestrates operations on contracts upon receiving certain events, like approving or rejecting other...
Interface for the redesigned notification service.
Task GoToAsync(string Route)
Navigates to the specified route and pushes the page onto the navigation stack.
BaseContentPage? CurrentPage
Gets the current visible view.
Task DisplayException(Exception Exception, string? Title=null)
Displays an alert/message box to the user.
Task< bool > DisplayAlert(string Title, string Message, string? Accept=null, string? Cancel=null)
Displays an alert/message box to the user.
NotificationAction
Actions that can be routed from notifications.
NotificationSource
Describes the source producing a notification.
BackMethod
Navigation Back Method
IdentityState
Lists recognized legal identity states.
SignWith
Options on what keys to use when signing data.
ContractParts
How the parts of the contract are defined.
ContractState
Recognized contract states
XmppState
State of XMPP connection.