1646654355
Core Client Library built on the EVER OS GraphQL API for Everscale DApp development
Core Client Library is written in Rust that can be dynamically linked. It provides all heavy-computation components and functions, such as TON Virtual Machine, TON Transaction Executor, ABI-related functions, boc-related functions, crypto functions.
The decision to create the Rust library was made after a period of time using pure JavaScript to implement these use cases.
We ended up with very slow work of pure JavaScript and decided to move all this to Rust library and link it to Javascript as a compiled binary including a wasm module for browser applications.
Also this approach provided an opportunity to easily create bindings for any programming language and platform, thus, to make it possible to develop distributed applications (DApps) for any possible use-cases, such as: mobile DApps, web DApps, server-side DApps, enterprise DApp etc.
Client Library exposes all the functionality through a few of exported functions. All interaction with library is performed using JSON-RPC like protocol.
Library works over GraphQL API of EVER OS DApp Server. So, it can be used to interact directly with EVER OS Clouds.
Binding is a thin client library written on the specific language that acts like a bridge between a client library and an application code written on that language.
Supported platforms: Node.js, Web, React-Native for IOS/Android
Repository: JavaScript SDK
The simplest way is to use library in then Rust applications because of the native Rust library interface. The Rust interface is clear and well documented.
But what if you are required to use library in languages others than Rust?
You have some options:
json_interface
which provides access to library functions through JSON-RPC interface. This interface exports several extern "C" functions. So you can build a dynamic or static link library and link it to your application as any other external libraries. The JSON Interface is fully "C" compliant. You can find description in section JSON Interface.If you choose using JSON Interface please read this document JSON Interface.
Here you can find directions how to use json_interface
and write your own binding.
Soft Breaking is API changes that include only new optional fields in the existing structures. This changes are fully backward compatible for JSON Interface.
But in Rust such changes can produce some problems with an old client code.
Look at the example below:
foo
and the corresponding params structure:#[derive(Default)]
struct ParamsOfFoo {
pub foo: String,
}
pub fn foo(params: ParamsOfFoo)
foo(ParamsOfFoo {
foo: "foo".into(),
});
ParamsOfFoo
:#[derive(Default)]
struct ParamsOfFoo {
pub foo: String,
pub bar: Option<String>,
}
From the perspective of JSON-interface it isn't breaking change because the new parameter is optional. But code snippet (2) will produce Rust compilation error.
foo(ParamsOfFoo {
foo: "foo".into(),
..Default::default(),
});
For all Ton Client API structures Default
trait is implemented.
The best way to build client libraries is to use build scripts from this repo.
Note: The scripts are written in JavaScript so you have to install Node.js (v.10 or newer) to run them. Also make sure you have the latest version of Rust installed.
To build a binary for a specific target (or binding), navigate to the relevant folder and run node build.js
.
The resulting binaries are placed to bin
folder in the gz-compressed format.
Note that the build script generates binaries compatible with the platform used to run the script. For example, if you run it on Mac OS, you get binaries targeted at Darwin (macOS) platform.
Note: You need latest version of rust. Upgrade it with rustup update
command. Check version with rustc --version
, it should be above or equal to 1.47.0
.
Rebuild api.json
:
cd toncli
cargo run api -o ../tools
Rebuild docs
:
cd tools
npm i
tsc
node index docs -o ../docs
Rebuild modules.ts
:
cd tools
npm i
tsc
node index binding -l ts -o ../../ton-client-js/packages/core/src
To run test suite use standard Rust test command
cargo test
SDK tests need EVER OS API endpoint to run on. Such an API is exposed by a DApp Server which runs in real networks and by local blockchain TON OS SE.
TON OS SE is used by default with address http://localhost
and port 80. If you launch it on another port you need to specify it explicitly like this: http://localhost:port
. If you have TON OS SE running on another address or you need to run tests on a real Everscale network use the following environment variables to override the default parameters
TON_USE_SE: true/false - flag defining if tests run against TON OS SE or a real network (DApp Server)
TON_NETWORK_ADDRESS - Dapp server or TON OS SE addresses separated by comma.
TON_GIVER_SECRET - Giver secret key. If not defined, default TON OS SE giver keys are used
TON_GIVER_ADDRESS - Address of the giver to use for prepaying accounts before deploying test contracts. If not defined, the address is calculated using `GiverV2.tvc` and configured public key
Instead of building library yourself, you can download the latest precompiled binaries from TON Labs SDK Binaries Store.
Platform | Major | Download links |
---|---|---|
Win32 | 0 | ton_client.lib , ton_client.dll |
1 | ton_client.lib , ton_client.dll | |
macOS | 0 | libton_client.dylib |
1 | (x86_64)libton_client.dylib | |
1 | (aarch64)libton_client.dylib | |
Linux | 0 | libton_client.so |
1 | libton_client.so |
If you want an older version of library (e.g. 0.25.0
for macOS), you need to choose a link to your platform from the list above and replace 0
with a version: https://binaries.tonlabs.io/tonclient_0_25_0_darwin.gz
Downloaded archive is gzipped file
JavaScript SDK Types and Methods (API Reference)
Core Types and Methods (API Reference)
Download Details:
Author: tonlabs
Source Code: https://github.com/tonlabs/TON-SDK
License: Apache-2.0 License
#rust #blockchain #ton #dapp #graphql
1602560783
In this article, we’ll discuss how to use jQuery Ajax for ASP.NET Core MVC CRUD Operations using Bootstrap Modal. With jQuery Ajax, we can make HTTP request to controller action methods without reloading the entire page, like a single page application.
To demonstrate CRUD operations – insert, update, delete and retrieve, the project will be dealing with details of a normal bank transaction. GitHub repository for this demo project : https://bit.ly/33KTJAu.
Sub-topics discussed :
In Visual Studio 2019, Go to File > New > Project (Ctrl + Shift + N).
From new project window, Select Asp.Net Core Web Application_._
Once you provide the project name and location. Select Web Application(Model-View-Controller) and uncheck HTTPS Configuration. Above steps will create a brand new ASP.NET Core MVC project.
Let’s create a database for this application using Entity Framework Core. For that we’ve to install corresponding NuGet Packages. Right click on project from solution explorer, select Manage NuGet Packages_,_ From browse tab, install following 3 packages.
Now let’s define DB model class file – /Models/TransactionModel.cs.
public class TransactionModel
{
[Key]
public int TransactionId { get; set; }
[Column(TypeName ="nvarchar(12)")]
[DisplayName("Account Number")]
[Required(ErrorMessage ="This Field is required.")]
[MaxLength(12,ErrorMessage ="Maximum 12 characters only")]
public string AccountNumber { get; set; }
[Column(TypeName ="nvarchar(100)")]
[DisplayName("Beneficiary Name")]
[Required(ErrorMessage = "This Field is required.")]
public string BeneficiaryName { get; set; }
[Column(TypeName ="nvarchar(100)")]
[DisplayName("Bank Name")]
[Required(ErrorMessage = "This Field is required.")]
public string BankName { get; set; }
[Column(TypeName ="nvarchar(11)")]
[DisplayName("SWIFT Code")]
[Required(ErrorMessage = "This Field is required.")]
[MaxLength(11)]
public string SWIFTCode { get; set; }
[DisplayName("Amount")]
[Required(ErrorMessage = "This Field is required.")]
public int Amount { get; set; }
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime Date { get; set; }
}
C#Copy
Here we’ve defined model properties for the transaction with proper validation. Now let’s define DbContextclass for EF Core.
#asp.net core article #asp.net core #add loading spinner in asp.net core #asp.net core crud without reloading #asp.net core jquery ajax form #asp.net core modal dialog #asp.net core mvc crud using jquery ajax #asp.net core mvc with jquery and ajax #asp.net core popup window #bootstrap modal popup in asp.net core mvc. bootstrap modal popup in asp.net core #delete and viewall in asp.net core #jquery ajax - insert #jquery ajax form post #modal popup dialog in asp.net core #no direct access action method #update #validation in modal popup
1646654355
Core Client Library built on the EVER OS GraphQL API for Everscale DApp development
Core Client Library is written in Rust that can be dynamically linked. It provides all heavy-computation components and functions, such as TON Virtual Machine, TON Transaction Executor, ABI-related functions, boc-related functions, crypto functions.
The decision to create the Rust library was made after a period of time using pure JavaScript to implement these use cases.
We ended up with very slow work of pure JavaScript and decided to move all this to Rust library and link it to Javascript as a compiled binary including a wasm module for browser applications.
Also this approach provided an opportunity to easily create bindings for any programming language and platform, thus, to make it possible to develop distributed applications (DApps) for any possible use-cases, such as: mobile DApps, web DApps, server-side DApps, enterprise DApp etc.
Client Library exposes all the functionality through a few of exported functions. All interaction with library is performed using JSON-RPC like protocol.
Library works over GraphQL API of EVER OS DApp Server. So, it can be used to interact directly with EVER OS Clouds.
Binding is a thin client library written on the specific language that acts like a bridge between a client library and an application code written on that language.
Supported platforms: Node.js, Web, React-Native for IOS/Android
Repository: JavaScript SDK
The simplest way is to use library in then Rust applications because of the native Rust library interface. The Rust interface is clear and well documented.
But what if you are required to use library in languages others than Rust?
You have some options:
json_interface
which provides access to library functions through JSON-RPC interface. This interface exports several extern "C" functions. So you can build a dynamic or static link library and link it to your application as any other external libraries. The JSON Interface is fully "C" compliant. You can find description in section JSON Interface.If you choose using JSON Interface please read this document JSON Interface.
Here you can find directions how to use json_interface
and write your own binding.
Soft Breaking is API changes that include only new optional fields in the existing structures. This changes are fully backward compatible for JSON Interface.
But in Rust such changes can produce some problems with an old client code.
Look at the example below:
foo
and the corresponding params structure:#[derive(Default)]
struct ParamsOfFoo {
pub foo: String,
}
pub fn foo(params: ParamsOfFoo)
foo(ParamsOfFoo {
foo: "foo".into(),
});
ParamsOfFoo
:#[derive(Default)]
struct ParamsOfFoo {
pub foo: String,
pub bar: Option<String>,
}
From the perspective of JSON-interface it isn't breaking change because the new parameter is optional. But code snippet (2) will produce Rust compilation error.
foo(ParamsOfFoo {
foo: "foo".into(),
..Default::default(),
});
For all Ton Client API structures Default
trait is implemented.
The best way to build client libraries is to use build scripts from this repo.
Note: The scripts are written in JavaScript so you have to install Node.js (v.10 or newer) to run them. Also make sure you have the latest version of Rust installed.
To build a binary for a specific target (or binding), navigate to the relevant folder and run node build.js
.
The resulting binaries are placed to bin
folder in the gz-compressed format.
Note that the build script generates binaries compatible with the platform used to run the script. For example, if you run it on Mac OS, you get binaries targeted at Darwin (macOS) platform.
Note: You need latest version of rust. Upgrade it with rustup update
command. Check version with rustc --version
, it should be above or equal to 1.47.0
.
Rebuild api.json
:
cd toncli
cargo run api -o ../tools
Rebuild docs
:
cd tools
npm i
tsc
node index docs -o ../docs
Rebuild modules.ts
:
cd tools
npm i
tsc
node index binding -l ts -o ../../ton-client-js/packages/core/src
To run test suite use standard Rust test command
cargo test
SDK tests need EVER OS API endpoint to run on. Such an API is exposed by a DApp Server which runs in real networks and by local blockchain TON OS SE.
TON OS SE is used by default with address http://localhost
and port 80. If you launch it on another port you need to specify it explicitly like this: http://localhost:port
. If you have TON OS SE running on another address or you need to run tests on a real Everscale network use the following environment variables to override the default parameters
TON_USE_SE: true/false - flag defining if tests run against TON OS SE or a real network (DApp Server)
TON_NETWORK_ADDRESS - Dapp server or TON OS SE addresses separated by comma.
TON_GIVER_SECRET - Giver secret key. If not defined, default TON OS SE giver keys are used
TON_GIVER_ADDRESS - Address of the giver to use for prepaying accounts before deploying test contracts. If not defined, the address is calculated using `GiverV2.tvc` and configured public key
Instead of building library yourself, you can download the latest precompiled binaries from TON Labs SDK Binaries Store.
Platform | Major | Download links |
---|---|---|
Win32 | 0 | ton_client.lib , ton_client.dll |
1 | ton_client.lib , ton_client.dll | |
macOS | 0 | libton_client.dylib |
1 | (x86_64)libton_client.dylib | |
1 | (aarch64)libton_client.dylib | |
Linux | 0 | libton_client.so |
1 | libton_client.so |
If you want an older version of library (e.g. 0.25.0
for macOS), you need to choose a link to your platform from the list above and replace 0
with a version: https://binaries.tonlabs.io/tonclient_0_25_0_darwin.gz
Downloaded archive is gzipped file
JavaScript SDK Types and Methods (API Reference)
Core Types and Methods (API Reference)
Download Details:
Author: tonlabs
Source Code: https://github.com/tonlabs/TON-SDK
License: Apache-2.0 License
#rust #blockchain #ton #dapp #graphql
1595396220
As more and more data is exposed via APIs either as API-first companies or for the explosion of single page apps/JAMStack, API security can no longer be an afterthought. The hard part about APIs is that it provides direct access to large amounts of data while bypassing browser precautions. Instead of worrying about SQL injection and XSS issues, you should be concerned about the bad actor who was able to paginate through all your customer records and their data.
Typical prevention mechanisms like Captchas and browser fingerprinting won’t work since APIs by design need to handle a very large number of API accesses even by a single customer. So where do you start? The first thing is to put yourself in the shoes of a hacker and then instrument your APIs to detect and block common attacks along with unknown unknowns for zero-day exploits. Some of these are on the OWASP Security API list, but not all.
Most APIs provide access to resources that are lists of entities such as /users
or /widgets
. A client such as a browser would typically filter and paginate through this list to limit the number items returned to a client like so:
First Call: GET /items?skip=0&take=10
Second Call: GET /items?skip=10&take=10
However, if that entity has any PII or other information, then a hacker could scrape that endpoint to get a dump of all entities in your database. This could be most dangerous if those entities accidently exposed PII or other sensitive information, but could also be dangerous in providing competitors or others with adoption and usage stats for your business or provide scammers with a way to get large email lists. See how Venmo data was scraped
A naive protection mechanism would be to check the take count and throw an error if greater than 100 or 1000. The problem with this is two-fold:
skip = 0
while True: response = requests.post('https://api.acmeinc.com/widgets?take=10&skip=' + skip), headers={'Authorization': 'Bearer' + ' ' + sys.argv[1]}) print("Fetched 10 items") sleep(randint(100,1000)) skip += 10
To secure against pagination attacks, you should track how many items of a single resource are accessed within a certain time period for each user or API key rather than just at the request level. By tracking API resource access at the user level, you can block a user or API key once they hit a threshold such as “touched 1,000,000 items in a one hour period”. This is dependent on your API use case and can even be dependent on their subscription with you. Like a Captcha, this can slow down the speed that a hacker can exploit your API, like a Captcha if they have to create a new user account manually to create a new API key.
Most APIs are protected by some sort of API key or JWT (JSON Web Token). This provides a natural way to track and protect your API as API security tools can detect abnormal API behavior and block access to an API key automatically. However, hackers will want to outsmart these mechanisms by generating and using a large pool of API keys from a large number of users just like a web hacker would use a large pool of IP addresses to circumvent DDoS protection.
The easiest way to secure against these types of attacks is by requiring a human to sign up for your service and generate API keys. Bot traffic can be prevented with things like Captcha and 2-Factor Authentication. Unless there is a legitimate business case, new users who sign up for your service should not have the ability to generate API keys programmatically. Instead, only trusted customers should have the ability to generate API keys programmatically. Go one step further and ensure any anomaly detection for abnormal behavior is done at the user and account level, not just for each API key.
APIs are used in a way that increases the probability credentials are leaked:
If a key is exposed due to user error, one may think you as the API provider has any blame. However, security is all about reducing surface area and risk. Treat your customer data as if it’s your own and help them by adding guards that prevent accidental key exposure.
The easiest way to prevent key exposure is by leveraging two tokens rather than one. A refresh token is stored as an environment variable and can only be used to generate short lived access tokens. Unlike the refresh token, these short lived tokens can access the resources, but are time limited such as in hours or days.
The customer will store the refresh token with other API keys. Then your SDK will generate access tokens on SDK init or when the last access token expires. If a CURL command gets pasted into a GitHub issue, then a hacker would need to use it within hours reducing the attack vector (unless it was the actual refresh token which is low probability)
APIs open up entirely new business models where customers can access your API platform programmatically. However, this can make DDoS protection tricky. Most DDoS protection is designed to absorb and reject a large number of requests from bad actors during DDoS attacks but still need to let the good ones through. This requires fingerprinting the HTTP requests to check against what looks like bot traffic. This is much harder for API products as all traffic looks like bot traffic and is not coming from a browser where things like cookies are present.
The magical part about APIs is almost every access requires an API Key. If a request doesn’t have an API key, you can automatically reject it which is lightweight on your servers (Ensure authentication is short circuited very early before later middleware like request JSON parsing). So then how do you handle authenticated requests? The easiest is to leverage rate limit counters for each API key such as to handle X requests per minute and reject those above the threshold with a 429 HTTP response.
There are a variety of algorithms to do this such as leaky bucket and fixed window counters.
APIs are no different than web servers when it comes to good server hygiene. Data can be leaked due to misconfigured SSL certificate or allowing non-HTTPS traffic. For modern applications, there is very little reason to accept non-HTTPS requests, but a customer could mistakenly issue a non HTTP request from their application or CURL exposing the API key. APIs do not have the protection of a browser so things like HSTS or redirect to HTTPS offer no protection.
Test your SSL implementation over at Qualys SSL Test or similar tool. You should also block all non-HTTP requests which can be done within your load balancer. You should also remove any HTTP headers scrub any error messages that leak implementation details. If your API is used only by your own apps or can only be accessed server-side, then review Authoritative guide to Cross-Origin Resource Sharing for REST APIs
APIs provide access to dynamic data that’s scoped to each API key. Any caching implementation should have the ability to scope to an API key to prevent cross-pollution. Even if you don’t cache anything in your infrastructure, you could expose your customers to security holes. If a customer with a proxy server was using multiple API keys such as one for development and one for production, then they could see cross-pollinated data.
#api management #api security #api best practices #api providers #security analytics #api management policies #api access tokens #api access #api security risks #api access keys
1601381326
We’ve conducted some initial research into the public APIs of the ASX100 because we regularly have conversations about what others are doing with their APIs and what best practices look like. Being able to point to good local examples and explain what is happening in Australia is a key part of this conversation.
The method used for this initial research was to obtain a list of the ASX100 (as of 18 September 2020). Then work through each company looking at the following:
With regards to how the APIs are shared:
#api #api-development #api-analytics #apis #api-integration #api-testing #api-security #api-gateway
1604399880
I’ve been working with Restful APIs for some time now and one thing that I love to do is to talk about APIs.
So, today I will show you how to build an API using the API-First approach and Design First with OpenAPI Specification.
First thing first, if you don’t know what’s an API-First approach means, it would be nice you stop reading this and check the blog post that I wrote to the Farfetchs blog where I explain everything that you need to know to start an API using API-First.
Before you get your hands dirty, let’s prepare the ground and understand the use case that will be developed.
If you desire to reproduce the examples that will be shown here, you will need some of those items below.
To keep easy to understand, let’s use the Todo List App, it is a very common concept beyond the software development community.
#api #rest-api #openai #api-first-development #api-design #apis #restful-apis #restful-api