2using System.Collections.Generic;
3using System.Threading.Tasks;
17 : base(
"/ValidateContract")
21 public override bool HandlesSubPaths =>
false;
22 public override bool UserSessions =>
true;
33 if (!(Obj is Dictionary<string, object> RequestObj) ||
34 !RequestObj.TryGetValue(
"ContractId", out Obj) || !(Obj is
string ContractId) ||
35 !RequestObj.TryGetValue(
"Purpose", out Obj) || !(Obj is
string Purpose) ||
36 !RequestObj.TryGetValue(
"Password", out Obj) || !(Obj is
string Password) ||
37 !RequestObj.TryGetValue(
"TabID", out Obj) || !(Obj is
string TabID))
42 if (ContractId.IndexOf(
'@') < 0)
48 Dictionary<string, object> ResponseObj;
53 ResponseObj = await this.Encode(
Contract);
57 string PetitionId = Guid.NewGuid().ToString();
59 Purpose = Purpose.Trim();
60 if (
string.IsNullOrEmpty(Purpose))
61 Purpose =
"Validating Contract through web interface at " +
Gateway.
Domain;
67 {
"PetitionId", e.PetitionId },
68 {
"PetitionResponse", e.Response },
69 {
"Contract", await this.Encode(e.RequestedContract) },
70 {
"Declined", e.RequestedContract is
null && !(e.Message is
null) },
71 {
"Timeout", e.Message is
null }
73 }, TimeSpan.FromMinutes(5)))
75 throw new ForbiddenException(
"Unable to sign petition. Either password is incorrect, or no legal identity assigned to broker.");
78 ResponseObj =
new Dictionary<string, object>()
82 {
"PetitionId", PetitionId },
83 {
"Message",
"The information has been petitioned from the owner. If the owner accepts to share the information, it will be displayed here when it arrives." }
87 await Response.
Return(ResponseObj);
96 List<Dictionary<string, object>> List =
new List<Dictionary<string, object>>();
97 Dictionary<string, object> ResponseObj =
new Dictionary<string, object>()
99 {
"ContractId", Contract.ContractId },
100 {
"ContractIdUri", Contract.ContractIdUriString },
101 {
"Petition",
false },
102 {
"Provider", Contract.Provider },
104 {
"ValidationStatus", Status.ToString() },
105 {
"Visibility", Contract.Visibility },
106 {
"Created", Contract.Created },
107 {
"Updated", Contract.Updated },
108 {
"From", Contract.From },
109 {
"To", Contract.To },
110 {
"SignAfter", Contract.SignAfter },
111 {
"SignBefore", Contract.SignBefore },
115 {
"TemplateId", Contract.TemplateId },
116 {
"TemplateIdUri", Contract.TemplateIdUriString },
117 {
"CanActAsTemplate", Contract.CanActAsTemplate },
119 {
"DefaultLanguage", Contract.DefaultLanguage },
123 {
"ForMachinesLocalName", Contract.ForMachinesLocalName },
124 {
"ForMachinesNamespace", Contract.ForMachinesNamespace },
132 List.Add(
new Dictionary<string, object>()
134 {
"Name", Role.Name },
135 {
"MinCount", Role.MinCount },
136 {
"MaxCount", Role.MaxCount },
137 {
"CanRevoke", Role.CanRevoke },
142 ResponseObj[
"Roles"] = List.ToArray();
150 List.Add(
new Dictionary<string, object>()
152 {
"LegalId", Part.LegalId },
153 {
"LegalIdUri", Part.LegalIdUriString },
154 {
"Role", Part.Role }
158 ResponseObj[
"Parts"] = List.ToArray();
166 List.Add(
new Dictionary<string, object>()
168 {
"Name", Parameter.Name },
169 {
"Value", Parameter.ObjectValue },
174 ResponseObj[
"Parameters"] = List.ToArray();
182 List.Add(
new Dictionary<string, object>()
184 {
"BareJid", ClientSignature.BareJid },
186 {
"LegalId", ClientSignature.LegalId },
187 {
"LegalIdUri", ClientSignature.LegalIdUriString },
188 {
"Role", ClientSignature.Role },
189 {
"Timestamp", ClientSignature.Timestamp },
190 {
"Transferable", ClientSignature.Transferable }
194 ResponseObj[
"ClientSignatures"] = List.ToArray();
202 List.Add(
new Dictionary<string, object>()
204 {
"BareJid", ClientSignature.BareJid },
206 {
"LegalId", ClientSignature.LegalId },
207 {
"LegalIdUri", ClientSignature.LegalIdUriString },
208 {
"Role", ClientSignature.Role },
209 {
"Timestamp", ClientSignature.Timestamp },
210 {
"Transferable", ClientSignature.Transferable }
214 ResponseObj[
"ClientSignatures"] = List.ToArray();
222 List.Add(
new Dictionary<string, object>()
224 {
"Id", Attachment.Id },
225 {
"ContentType", Attachment.ContentType },
226 {
"FileName", Attachment.FileName },
227 {
"Url", Attachment.Url },
229 {
"Timestamp", Attachment.Timestamp },
233 ResponseObj[
"Attachments"] = List.ToArray();
237 ResponseObj[
"ServerSignature"] =
new Dictionary<string, object>()
240 {
"Timestamp", Contract.ServerSignature.Timestamp }
248 List<Dictionary<string, object>> List =
new List<Dictionary<string, object>>();
252 List.Add(
new Dictionary<string, object>()
254 {
"Language", Localization.Language },
260 return List.ToArray();
static string GetBody(string Html)
Extracts the contents of the BODY element in a HTML string.
Helps with common JSON-related tasks.
static string Encode(string s)
Encodes a string for inclusion in JSON.
Helps with common XML-related tasks.
static string PrettyXml(string Xml)
Reformats XML to make it easier to read.
The ClientEvents class allows applications to push information asynchronously to web clients connecte...
static Task< int > PushEvent(string[] TabIDs, string Type, object Data)
Puses an event to a set of Tabs, given their Tab IDs.
Static class managing the runtime environment of the IoT Gateway.
static CaseInsensitiveString Domain
Domain name.
static IUser AssertUserAuthenticated(HttpRequest Request, string Privilege)
Makes sure a request is being made from a session with a successful user login.
static Task< bool > PetitionContract(string ContractId, string PetitionId, string Purpose, EventHandlerAsync< ContractPetitionResponseEventArgs > Callback, TimeSpan Timeout)
Petitions information about a smart contract from its owner.
static ContractsClient ContractsClient
XMPP Contracts Client, if such a compoent is available on the XMPP broker.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
The server understood the request, but is refusing to fulfill it. Authorization will not help and the...
Represents an HTTP request.
bool HasData
If the request has data.
async Task< object > DecodeDataAsync()
Decodes data sent in request.
Represets a response of an HTTP client request.
async Task Return(object Object)
Returns an object to the client. This method can only be called once per response,...
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
The server is currently unable to handle the request due to a temporary overloading or maintenance of...
Contains a reference to an attachment assigned to a legal object.
byte[] Signature
Binary signature of the attachment, generated by an approved legal identity of the account-holder....
Represents a digital signature on a contract.
Contains the definition of a contract
byte[] ContentSchemaDigest
The hash digest of the schema used to validate the machine-readable contents (ForMachines) of the sma...
Security.HashFunction ContentSchemaHashFunction
Hash function of the schema used to validate the machine-readable contents (ForMachines) of the smart...
Parameter[] Parameters
Defined parameters for the smart contract.
Duration? ArchiveRequired
Requied time to archive a signed smart contract, after it becomes obsolete.
ClientSignature[] ClientSignatures
Client signatures of the contract.
HumanReadableText[] ForHumans
Human-readable contents of the contract.
Attachment[] Attachments
Attachments assigned to the legal identity.
Duration? ArchiveOptional
Optional time to archive a signed smart contract, after it becomes obsolete, and after its required a...
XmlElement ForMachines
Machine-readable contents of the contract.
Role[] Roles
Roles defined in the smart contract.
ContractParts PartsMode
How parts are defined in the smart contract.
ContractState State
Contract state
Part[] Parts
Defined parts for the smart contract.
Duration? Duration
Duration of the contract. Is counted from the time it is signed by the required parties.
ServerSignature ServerSignature
Server signature attesting to the validity of the contents of the contract.
Task< IdentityStatus > ValidateAsync(LegalIdentity Identity)
Validates a legal identity.
Task< Contract > GetContractAsync(string ContractId)
Gets a contract
override async Task< HumanReadableElement > IsWellDefined()
Checks if the element is well-defined.
Class representing human-readable text.
async Task< string > GenerateHTML(Contract Contract)
Generates HTML for the human-readable text.
HumanReadableText[] Descriptions
Discriptions of the object, in different languages.
Abstract base class for contractual parameters
Class defining a part in a contract
byte[] DigitalSignature
Digital Signature
bool AllowsPOST
If the POST method is allowed.
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
POST Interface for HTTP resources.
ContractStatus
Validation Status of smart contract
override string ToString()