I have stored data on sawtooth in protobuf format at an address (address made from public key and transaction family).
Get request was made on
http://rest-api:8008/state/
to get data in the format
{
"data": "CkIwM2FjNjA3MTUzZmRlMzJhNzhiNDFlMzkxN2QwZDlkZmJmMmM2NjZmOWFhZGMzMWRiNTNjODZhNzFkNDMyNmZkNGUSBnNlbGxlchoROTc4LTAtNTc2LTUyMzk1LTAiETgxOS02OTAtNzk4Nng1MTE5Kg0xLTk4MTAtMTE0NS01",
"head": "bea2911b4d84b897300fc4a9eb6b56b7ddc59c88c115dab6c09935d658b57cf229b538a3cb3d407647211c8847e46db07f9cff65af2835dfc7732be9b443fae3",
"link": "http://192.168.1.13:8008/state/318c9fa678220444fb9b209a57c849320a7f61c984e5b8a6a56880030728bdb530a5d0?head=bea2911b4d84b7c7300fc4a9eb6b56b7ddc59c88c115dab6c09935d658b57cf229b538a3cb3d407647211c8847e46db07f9cff65af2835dfc7732be9b443fae3"
}
I posted Account data on the sawtooth-rest-api, if the details are correct(checked by processor), Account with additional "Public Key" is inserted onto the blockchain. This is the account protobuf class, which was serialized before it was inserted onto the blockchain.
message Account {
string public_key = 1;
string user_type = 2;
string adhaar_number = 3;
string phone_number = 4;
string pan_card_number = 5;
}
transaction = Account()
transaction.ParseFromString( base64.b64decode(data.encode()))
THat just gave a number 129.
Update:
The account data serialization output is
b'\nB033c10fa02a3b602f008e7837a48d4492f5105417111404c4404b49f51222d30c1\x12$60405711-dd32-47c1-a914-3e19ee5177b1\x1a\x06seller"
\x11978-1-61207-456-6*\x10+64(0)19727879362\r0-609-80129-5'
when I base64 encoded it, it gives exactly the same string which i got from sawtooth api under the data key.
but somehow transaction.ParseFromString gives just an integer of 3 digits, Couldnt get the account back.
Sorry I figured this out:
After
account=transaction.ParseFromString(<serializedBytes>)
The account details can be accessed like normal class variables.
account.public_key
account.adhaar_number
If my understanding is correct, you retrieve data vis-a-vis the REST API /state/xxxx or /state?address=xxxx.
When data is put on the chain in a TransactionProcessor via setState or similar call, it does a base64 encoding first.
You will need to do a base64 decode and then ParseFromString on that result.
Related
Hello there I have setup successfully inbound webhook with strongGrid in net core 3.1.
The endpoint gets called and I want to parse value inside the attachment which is csv file.
The code I am using is following
var parser = new WebhookParser();
var inboundEmail = await parser.ParseInboundEmailWebhookAsync(Request.Body).ConfigureAwait(false);
await _emailSender.SendEmailAsyncWithSendGrid("info#mydomain.com", "ParseWebhook1", inboundEmail.Attachments.First().Data.ToString());
Please note I am sending an email as I don t know how to debug webhook with sendgrid as I am not aware of any cli.
but this line apparently is not what I am looking for
inboundEmail.Attachments.First().Data.ToString()
I am getting this on my email
Id = a3e6a543-2aee-4ffe-a36a-a53k95921998, Tag = HttpMultipartParser.MultipartFormDataParser.ParseStreamAsync, Length = 530 bytes
the csv I need to parse has 3 fields Sku productname and quantity I'd like to get sku values.
Any help would be appreciated.
The .Data property contains a Stream and invoking ToString on a stream object does not return its content. The proper way to read the content of a stream in C# is something like this:
var streamReader = new StreamReader(inboundEmail.Attachments.First().Data);
var attachmentContent = await streamReader.ReadToEndAsync().ConfigureAwait(false);
As far as parsing the CSV, there are literally thousands of projects on GitHub and hundreds on NuGet with the keyword 'CSV'. I'm sure one of them will fit your needs.
I am trying to implement server side verification for IAP's in my flutter app. I am using the package
https://pub.dev/packages/in_app_purchase
version: ^0.3.4+8
And I am confused how I get the data to verify my purchase for android and IOS. In the documentation they say
"or verify the data using your own server with
serverVerificationData."
This string seems to return some kind of encoded string. How do I then extract the needed data from this string? I tried base64Decode() since the localVerificationData is base64Encoded but this did not work.
Android needs a package name, purchase id and purchaseToken. And Ios needs a object receipt-data. I am confused on how I am to get that data from the serverVerificationData string.
I am currently implementing android first.
The the localVerificationData documentation says
The data used for local verification.
If the source is IAPSource.AppStore, this data is a based64 encoded
string. The structure of the payload is defined using ASN.1. If the
source is IAPSource.GooglePlay, this data is a JSON String.
So the serverVerificationData must be different from the localVerificationData then since it doesn't look like JSON at all. I am also not sure if it is safe to post the serverVerificationData here since it may contain sensitive information.
This is a string similar to the one I got on android only I changed all the letters, numbers etc. So it's just about the format
zdfdzcdshxvbxmgbafdxvdzt.JK-GR58OHRPOGFEFHEGVEACBEIFDAPDH_EFHEWFEHFHPEGVERBWBASZWDAWODPAWD-HDSWCGOEWFP-EFPEQFHPEDHEWYIFEWFUWEFDASCNAQWFDefphFEQUIWEFpofgewpfFEWHFPWEF
In the repo they show that they call the _verifyPurchase(purchase); which has no implementation in the example.
https://github.com/flutter/plugins/tree/master/packages/in_app_purchase#listening-to-purchase-updates
https://github.com/flutter/plugins/blob/5a183ac54a515be096d01f3a35546c5d89a30dca/packages/in_app_purchase/example/lib/main.dart#L350
And they say you should always verify
https://github.com/flutter/plugins/blob/5a183ac54a515be096d01f3a35546c5d89a30dca/packages/in_app_purchase/example/lib/main.dart#L328
This is my current code
Future<dynamic> verifyAndroid(PurchaseDetails details) async {
DatabaseService databaseService = Get.find<DatabaseService>();
String verificationData = details.verificationData.serverVerificationData;
// zdfdzcdshxvbxmgbafdxvdzt.JK-GR58OHRPOGFEFHEGVEACBEIFDAPDH_EFHEWFEHFHPEGVERBWBASZWDAWODPAWD-HDSWCGOEWFP-EFPEQFHPEDHEWYIFEWFUWEFDASCNAQWFDefphFEQUIWEFpofgewpfFEWHFPWEF
String packageName = ''; //get from verificationData
String productId = ''; //get from verificationData
String purchaseToken = ''; //get from verificationData
final response = await databaseService.verifyInAppPurchaseAndroid(packageName, productId, purchaseToken);
return response;
}
It turned out that the data was in the detail.verificationData.localVerificationData instead of the detail.verificationData.serverVerificationData and detail.verificationData.serverVerificationData is the purchase token on Android.
Objective: I am trying to integrate creator-form-data with google-sheet using google-sheet-api-v4.
I am able to create an empty sheet(data params being empty ) at google spreadsheets.
but i don't know ,how to create sheet with data-params , to either-
(1) assign title ,to spreadsheet , or
(2) write any data, to spreadsheet
error received : using deluge to perform task no. ( 1 ), the error thrown is :
Invalid JSON payload received. Unexpected token
Note:
(1)Oauth credentials are checked and correct,
google access token is also valid, confirming via
Google-oauth-playground
(2) i am able to assign title and data from google-try-api-platform,but no success from deluge side.
google-sheet-try-api
The issue is solved now ,in postUrl the post-data to be posted , must be converted from json to string (params=data.toString(); ).
I had sent post-data in json format thats the mistake I made.
Below is correct sample code for deluge:
append_data = {"values":{{thisDate,thisQuantity}}};
final_append_data = append_data.toString();
response = postUrl(append_data_sheet_url,final_append_data,mymap,false);
Note: variable "final_append_data" is converted to string.
I'm sending members of my site emails after an event so they can rate and tip their teachers. Is there a way to create some unique key and include this in the email link back to my site so they can rate and tip without having to login back in? If so what's the best way to do this? Is there something in Asp.Net identity?
It looks like Uber might be doing this with their tip link below but I'm not sure.
https://gratitude.uber.com/tips/trip/33879346-bba8-406a-82a8-2afcda9aa3e7
Add the users to a database and then send the link with their UserId as a query string:
www.mysite.co.uk/survey?id=4546
Create a controller called surveycontroller with a parameter to capture the id and direct to the survey html page.
Check this article
The .net Framwork provides RNGCryptoServiceProvider class which
Implements a cryptographic Random Number Generator (RNG) using the
implementation provided by the cryptographic service provider (CSP).
This class is usually used to generate random numbers. Although I can
use this class to generate unique number in some sense but it is also
not collision less. Moreover while generating key we can make key more
complicated by making it as alpha numeric rather than numeric only.
So, I used this class along with some character masking to generate
unique key of fixed length. Below is code sample:
private string GetUniqueKey() { int maxSize = 8 ; int minSize = 5 ; char[] chars = new char[62]; string a; a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; chars = a.ToCharArray(); int size = maxSize ; byte[] data = new byte[1]; RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider(); crypto.GetNonZeroBytes(data) ; size = maxSize ; data = new byte[size]; crypto.GetNonZeroBytes(data); StringBuilder result = new StringBuilder(size) ; foreach(byte b in data ) { result.Append(chars[__b % (chars.Length - )>); } <span class="code-keyword">return result.ToString(); }
As you mentioned in comments there might be security issues, you can use blow method to avoid them:
check for user last ip address loged in with to know this is actually the user opening the link
check for user cookies
create block list for subspecies bruteForce attack
make the generated key disabled and enable it after all above security passed
use captcha verification to avoid BruteForce or non human access your page
I've had success creating objects with POST and Content-Type application/xml
I've also had success querying using Content-Type application/x-www-form-urlencoded with a blank request body which returns all of the object type depending on which URI I specify.
I can also get the same to work with something like PageNum=1&ResultsPerPage=1 in the request body and I have figured out how to incorporate that into the signature so I get a valid response.
However no matter how I format it, I cannot get anything other than a 401 response when I try to use a filter (something basic like Filter=FAMILYNAME :EQUALS: Doe). I've read over the OAuth Core 1.0 Revision A specifications on how all parameter names and values are escaped using the [RFC3986] percent-encoding. However I feel like I'm missing a step or formatting incorrectly. I've seen inconsistent information in my searching through Intuit's forums on what exactly is the proper format.
Any help on this would be greatly appreciated. I've been struggling with this for a good week now.
The response I get when trying to use a filter is:
HTTP Status 401 - message=Exception authenticating OAuth; errorCode=003200; statusCode=401
----Update----
I'm am seeing the same error when I try to use filters with the New IPP Developer Tools - IPP API Explorer. I'm using the IDS V2 QBO API Explorer. I'm able to use that tool to do a retrieve all Post and the response shows all of my customers, but when I try to use a filter I get :
Server Error
401 - Unauthorized: Access is denied due to invalid credentials.
You do not have permission to view this directory or page using the credentials that you supplied.
Any Ideas? If I'm getting the same error from the API Explorer tool, it makes me think the problem is something else entirely.
----Final Update----
I have finally had success with filters and I believe I have figure out what my problem was. I was always suspicious that I was able to get queries with pagination like "PageNum=1&ResultsPerPage=1" to work, but could not get something like "Filter=FAMILYNAME :EQUALS: Doe". I suspected there problem was with the white space in the filter format. What threw me off tracking this down earlier was that I could not get the filters to work in the IDS V2 QBO API Explorer. That made me suspect there was something else going on. I decided to ignore the API Explorer all together and focus on why I could get it to work the one way but no the other.
I believe my problem came down to improper encoding of the Filter's value in the signature. That explains the 401 invalid signature errors I was getting.
"Filter=Name :EQUALS: Doe" becomes "Filter=Name%20%3AEQUALS%20%3ADoe" after normalization.
Percent-Encoding that should give "Filter%3DName%2520%253AEQUALS%2520%253ADoe".
In essence you have to "double" encode the blank space and the colons, but not the equal sign. I tried many permutations of doing the encoding, but believe my mistake was that I was either not "double" encoding, or when I was double encoding I was including the '=' sign. Either way breaks your signature. Thanks for everyone's input.
I believe my problem came down to improper encoding of the Filter's value in the signature. That explains the 401 invalid signature errors I was getting.
I used an online tool to take me through the steps in properly signing an Oauth request. While going through those steps I realized my problem was with the steps where you normalize the request parameters and then percent-encode them. I was including the '=' of the filter in the normalization step, which breaks your signature. The tool I used can be found at:
http://hueniverse.com/2008/10/beginners-guide-to-oauth-part-iv-signing-requests/
Thanks for everyone's input.
Do you get a 401 with the same request in the API Explorer?
http://ippblog.intuit.com/blog/2013/01/new-ipp-developer-tool-api-explorer.html
Also, are you using the static base URL or retrieving it at runtime?
https://ipp.developer.intuit.com/0010_Intuit_Partner_Platform/0050_Data_Services/0400_QuickBooks_Online/0100_Calling_Data_Services/0010_Getting_the_Base_URL
If you are using the static base URL, try switching to the runtime base URL to see if you still get the error.
peterl answered one of my questions on here that may also answer yours. I had been trying to put the Filters in the body when they should have gone into the header. Here was peterl's code sample for getting all unpaid invoices (open balance greater than 0.00) for a particular customer.
http://pastebin.com/raw.php?i=7VUB6whp
public List<Intuit.Ipp.Data.Qbo.Invoice> GetQboUnpaidInvoices(DataServices dataServices, int startPage, int resultsPerPage, IdType CustomerId)
{
StringBuilder requestXML = new StringBuilder();
StringBuilder responseXML = new StringBuilder();
var requestBody = String.Format("PageNum={0}&ResultsPerPage={1}&Filter=OpenBalance :GreaterThan: 0.00 :AND: CustomerId :EQUALS: {2}", startPage, resultsPerPage, CustomerId.Value);
HttpWebRequest httpWebRequest = WebRequest.Create(dataServices.ServiceContext.BaseUrl + "invoices/v2/" + dataServices.ServiceContext.RealmId) as HttpWebRequest;
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.Headers.Add("Authorization", GetDevDefinedOAuthHeader(httpWebRequest, requestBody));
requestXML.Append(requestBody);
UTF8Encoding encoding = new UTF8Encoding();
byte[] content = encoding.GetBytes(requestXML.ToString());
using (var stream = httpWebRequest.GetRequestStream())
{
stream.Write(content, 0, content.Length);
}
HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
using (Stream data = httpWebResponse.GetResponseStream())
{
Intuit.Ipp.Data.Qbo.SearchResults searchResults = (Intuit.Ipp.Data.Qbo.SearchResults)dataServices.ServiceContext.Serializer.Deserialize<Intuit.Ipp.Data.Qbo.SearchResults>(new StreamReader(data).ReadToEnd());
return ((Intuit.Ipp.Data.Qbo.Invoices)searchResults.CdmCollections).Invoice.ToList();
}
}
protected string GetDevDefinedOAuthHeader(HttpWebRequest webRequest, string requestBody)
{
OAuthConsumerContext consumerContext = new OAuthConsumerContext
{
ConsumerKey = consumerKey,
ConsumerSecret = consumerSecret,
SignatureMethod = SignatureMethod.HmacSha1,
UseHeaderForOAuthParameters = true
};
consumerContext.UseHeaderForOAuthParameters = true;
//URIs not used - we already have Oauth tokens
OAuthSession oSession = new OAuthSession(consumerContext, "https://www.example.com",
"https://www.example.com",
"https://www.example.com");
oSession.AccessToken = new TokenBase
{
Token = accessToken,
ConsumerKey = consumerKey,
TokenSecret = accessTokenSecret
};
IConsumerRequest consumerRequest = oSession.Request();
consumerRequest = ConsumerRequestExtensions.ForMethod(consumerRequest, webRequest.Method);
consumerRequest = ConsumerRequestExtensions.ForUri(consumerRequest, webRequest.RequestUri);
if (webRequest.Headers.Count > 0)
{
ConsumerRequestExtensions.AlterContext(consumerRequest, context => context.Headers = webRequest.Headers);
if (webRequest.Headers[HttpRequestHeader.ContentType] == "application/x-www-form-urlencoded")
{
Dictionary<string, string> formParameters = new Dictionary<string, string>();
foreach (string formParameter in requestBody.Split('&'))
{
formParameters.Add(formParameter.Split('=')[0], formParameter.Split('=')[1]);
}
consumerRequest = consumerRequest.WithFormParameters(formParameters);
}
}
consumerRequest = consumerRequest.SignWithToken();
return consumerRequest.Context.GenerateOAuthParametersForHeader();
}
You can also see my original Question Here on StackOverflow: Query for All Invoices With Open Balances using QuickBooks Online (QBO) Intuit Partner Platform (IPP) DevKit.