Documentation for the new JS SDK API (#19)

This commit is contained in:
Pavel 2021-09-08 10:20:32 +03:00 committed by GitHub
parent 59d59d1c92
commit 90111033a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 1029 additions and 24 deletions

View File

@ -1,26 +1,33 @@
# Table of contents
* [Introduction](README.md)
* [Thinking In Aquamarine](p2p.md)
* [Concepts](concepts.md)
* [Quick Start](quick-start/README.md)
* [1. Browser-to-Browser](quick-start/1.-browser-to-browser-1.md)
* [2. Hosted Services](quick-start/2.-hosted-services.md)
* [3. Browser-to-Service](quick-start/3.-browser-to-service.md)
* [Aquamarine](knowledge_aquamarine/README.md)
* [Aqua](knowledge_aquamarine/hll.md)
* [Marine](knowledge_aquamarine/marine/README.md)
* [Marine CLI](knowledge_aquamarine/marine/marine-cli.md)
* [Marine REPL](knowledge_aquamarine/marine/marine-repl.md)
* [Marine Rust SDK](knowledge_aquamarine/marine/marine-rs-sdk.md)
* [Tools](knowledge_tools.md)
* [Node](node.md)
* [Security](knowledge_security.md)
* [Tutorials](tutorials_tutorials/README.md)
* [Setting Up Your Environment](tutorials_tutorials/recipes_setting_up.md)
* [Deploy A Local Fluence Node](tutorials_tutorials/tutorial_run_local_node.md)
* [cUrl As A Service](tutorials_tutorials/curl-as-a-service.md)
* [Add Your Own Builtins](tutorials_tutorials/add-your-own-builtin.md)
* [Building a Frontend with JS-SDK](tutorials_tutorials/building-a-frontend-with-js-sdk.md)
* [Research, Papers And References](research-papers-and-references.md)
- [Introduction](README.md)
- [Thinking In Aquamarine](p2p.md)
- [Concepts](concepts.md)
- [Quick Start](quick-start/README.md)
- [1. Browser-to-Browser](quick-start/1.-browser-to-browser-1.md)
- [2. Hosted Services](quick-start/2.-hosted-services.md)
- [3. Browser-to-Service](quick-start/3.-browser-to-service.md)
- [Aquamarine](knowledge_aquamarine/README.md)
- [Aqua](knowledge_aquamarine/hll.md)
- [Marine](knowledge_aquamarine/marine/README.md)
- [Marine CLI](knowledge_aquamarine/marine/marine-cli.md)
- [Marine REPL](knowledge_aquamarine/marine/marine-repl.md)
- [Marine Rust SDK](knowledge_aquamarine/marine/marine-rs-sdk.md)
- [Tools](knowledge_tools.md)
- [Node](node.md)
- [JS SDK](js-sdk/readme.md)
- [Concepts](js-sdk/1_concepts.md)
- [Basics](js-sdk/2_basics.md)
- [In-depth](js-sdk/3_basics.md)
- [Running app in nodejs](js-sdk/4_run_in_node.md)
- [Running app in browser](js-sdk/5_run_in_browser.md)
- [Api reference](js-sdk/6_reference/modules.md)
- [Changelog](js-sdk/changelog.md)
- [Security](knowledge_security.md)
- [Tutorials](tutorials_tutorials/README.md)
- [Setting Up Your Environment](tutorials_tutorials/recipes_setting_up.md)
- [Deploy A Local Fluence Node](tutorials_tutorials/tutorial_run_local_node.md)
- [cUrl As A Service](tutorials_tutorials/curl-as-a-service.md)
- [Add Your Own Builtins](tutorials_tutorials/add-your-own-builtin.md)
- [Building a Frontend with JS-SDK](tutorials_tutorials/building-a-frontend-with-js-sdk.md)
- [Research, Papers And References](research-papers-and-references.md)

37
js-sdk/1_concepts.md Normal file
View File

@ -0,0 +1,37 @@
# Basic concepts
The main export of the `@fluencelabs/fluence` package is the `FluencePeer` class. This class implements the Fluence protocol for javascript-based environments. It provides all the necessary features to communicate with Fluence network namely:
1. Connectivity with one or many Fluence Node which allows sending particles to and receiving from other Peers
2. The Peer Id identifying the node in the network
3. Aqua VM which allows the execution of air scripts inside particles
4. A set of builtin functions required by Fluence protocol
5. Support for the typescript code which is generated by Aqua compiler
Even though the js-based implementation closely resembles [node](node.md) there are some considerable differences to the latter.
`FluencePeer` does not host services composed of wasm modules. Instead it allows to register service call handlers directly in javascript. The Aqua language compiler creates a typed helpers for that task. Using Aqua compiler is strontly advised when working with JS SDK.
Due to the limitations of browser-based environment `FluencePeer` cannot be discovered by it's Peer Id on it's own. To overcome this `FluencePeer` must use an existing node which will act as a `relay`. When a peer is connected through a relay it is considered to be `client`. The `FluencePeer` routes all it's particle through it's relay thus taking advantage of the peer discovery implemented on the node. A particle sent to the connected client must be routed through it's relay.
The js-based peer does not implement the full set of builtin functions due the limitations described previously. E.g there is no builtins implementation for _kad_ or _srv_ services. However _op_ service is fully implemented. For the full descriptions of implemented builtins refer to [Api reference](js-sdk/6_reference/modules.md)
In contrast with the node implementation `FluencePeer` can initiate new particles execution. Aqua compiler generates executable functions from `func` definitions in aqua code.
# Creating applications with Aqua language
The official way to write applications for Fluence is using Aqua programming language. Aqua compiler emits TypeScript or JavaScript which in turn can be called from a js-based environemt. The compiler outputs code for the following entities:
1. Exported `func` declarations are turned into callable async functiokns
2. Exported `service` declarations are turned into functions which register callback handler in a typed manner
To learn more about Aqua see [aqua book](https://doc.fluence.dev/aqua-book/)
The building block of the application are:
- Aqua code for peer-to-peer communication
- Compiler cli package for aqua to (java)typescript compilation
- Initialization of the `FluencePeer`
- Application specific code (java)typescript in the framework of your choice
In the next section we see it in action

143
js-sdk/2_basics.md Normal file
View File

@ -0,0 +1,143 @@
# Intro
In this section we will show you how JS SDK can be used to create a hello world application with Fluence stack.
# Aqua code
Let's start with the aqua code first:
```
service HelloWorld("hello-world"):
hello(str: string)
func sayHello():
HelloWorld.hello("Hello, world!")
```
This file has two definitions. The first one is a service named `HelloWorld`. A Service interfaces functions executable on a peer. We will register a handler for this interface in our typescript application. The second definition is the function `sayHello`. The only thing the function is doing is calling the `hello` method of `HelloWorld` service located on the current peer. We will shouw you how to call this function from the typescript application.
# Installing dependencies
Initialze an empty npm package:
```bash
npm init
```
We will need these two packages for the application runtime
```bash
npm install @fluencelabs/fluence @fluencelabs/fluence-network-environment
```
The first one is the SDK itself and the second is a maintained list of Fluence networks and nodes to connect to.
Aqua compiler cli has to be installed, but is not needed at runtime.
**Warning: the package requires java to be installed \(it will call "java -jar ... "\)**
```bash
npm install --save-dev @fluencelabs/aqua-cli
```
Also we might want to have aqua source files automatically recompiled on every save. We will take advantage of chokidar for that:
```bash
npm install --save-dev @fluencelabs/chokidar-cli
```
And last, but no least we will need TypeScript
```
npm install --save-dev typescript
npx tsc --init
```
# Setting up aqua compiler
Let's put aqua described earlier into `aqua/hello-world.aqua` file. You probably want to keep the generated TypeScript in the same directory with other typescript files, usually `src`. Let's create the `src/_aqua` directory for that.
The overall project structure looks like this:
```text
┣ aqua
┃ ┗ hello-world.aqua
┣ src
┃ ┣ _aqua
┃ ┃ ┗ hello-world.ts
┃ ┗ index.ts
┣ package-lock.json
┣ package.json
┗ tsconfig.json
```
The Aqua compiler can be run with `npm`:
```bash
npx aqua-cli -i ./aqua/ -o ./src/_aqua
```
We recommend to store this logic inside a script in `packages.json` file:
```json
{
...
"scripts": {
...
"compile-aqua": "aqua-cli -i ./aqua/ -o ./src/_aqua", // (1)
"watch-aqua": "chokidar \"**/*.aqua\" -c \"npm run compile-aqua\"" // (2)
},
...
}
```
`compile-aqua` (1) runs the compilation once, producing `src/_aqua/hello-world.ts` in our case
`watch-aqua` (2) starts watching for any changes in .aqua files recompiling them on the fly
# Using the compiled code in our application
Using the code generated by the compiler is as easy as calling a function. The compiler generates all the boilerplate needed to send a particle into the network and wraps it into a single call. It also generate a function for service callback registration. Note that all the type information and therefore type checking and code completion facilities are there!
Let's see how use generated code in our application. `index.ts`:
```typescript
import { FluencePeer } from "@fluencelabs/fluence";
import { registerHelloWorld, sayHello } from "./_aqua/hello-world"; // (1)
async function main() {
await FluencePeer.default.init(); // (2)
registerHelloWorld({
// (3)
hello: async (str) => {
console.log(str);
},
});
await sayHello(); // (4)
await FluencePeer.default.uninit(); // (5)
}
main();
```
(1) Aqua compiler provides functions which can be directly imported like any normal typescript function.
(2) `FluencePeer` has to be initialized before running any application in Fluence Network. A peer represents the identity in the network, so most of the time you will only need a single peer per application. JS SDK provides a default instance which is accesible via `default` propery of the class. `init` method accepts a parameters object which will be covered in the next section. By default the peer is not get connected to the network and will only be able to execute air on the local machine only. Please keep in mind that the init function is asyncrhounous
For every exported `service XXX` definition in aqua code, the compiler provides a `registerXXX` counterpart. These funtions provide a type-safe way of registering callback handlers for the services. The callbacks are executed when the appropriate service is called in aqua on the current peer. The handlers take form of the object where keys are the name of functions and the values are async functions used as the corresponding callbacks. For example in (3) we are registering handler for `hello` function which outputs it's parameter to the console
For every exported `func XXX` definition in aqua code, the compiler provides an async function which can be directly called from typescripyt. In (4) we are calling the `sayHello` function with no arguments. Note that every function is asyncrhonous.
(5) You should call `uninit` method of `FluencePeer` when it is no longer needed. As a rule of thumb all the peers should be uninitilized before destroying the application.
Let's try running the example:
```bash
node -r ts-node/register src/index.ts
```
If everything has been done correctly yuo should see `Hello, world!` in the console.
The next secion will cover in-depth and advanced usage JS SDK

335
js-sdk/3_in_depth.md Normal file
View File

@ -0,0 +1,335 @@
# Intro
In this section we will cover the JS SDK in-depth.
# FluencePeer class
The overall workflow with the `FluencePeer` is the following:
1. Create an instance of the peer
2. Initializing the peer
3. Using the peer in the application
4. Uninitializing the peer
To create a new peer simple instantiate the `FluencePeer` class:
```typescript
const peer = new FluencePeer();
```
The constructor simply creates a new object and does not initialize any workflow. The `init` function starts the Aqua VM, initializes the default call service handlers and (optionally) connect to the Fluence network. The function takes an optional object specifying additonal peer configuration. On option you will be using a lot is `connectTo`. It tells the peer to connect to a relay. For example:
```typescript
await peer.init({
connectTo: krasnodar[0],
});
```
connects the first node of the Kranodar network. You can find the officially maintained list networks in the `@fluencelabs/fluence-network-environment` package. The full list of supported options is described in the [API reference](js-sdk/6_reference/modules.md)
Most of the time a single peer is enough for the whole application. For these use cases`FluncePeer` class contains the default instance which can be accessed with the corresponding property:
```typescript
await FluencePeer.default.init();
```
The peer by itself does not do any useful work. You should take advantage of functions generated by the Aqua compiler. You can use them both with a single peer or in muliple peers scenario. If you are using the default peer for your application you don't need to explicitly pass it: the compiled functions will use the `default` instance in that case (see "Using multiple peers in one applicaton")
To uninitialize the peer simply call `uninit` method. It will disconnect from the network and stop the Aqua vm,
```typescript
await peer.unint();
```
# Using multiple peers in one applicaton
In most cases using a single peer is enough. However sometimes you might need to run multiple peers inside the same JS environment. When using a single peer you should initialize the `FluencePeer.default` and call Aqua compiler-generated functions without passing any peer. For example:
```typescript
import { FluencePeer } from "@fluencelabs/fluence";
import {
registerSomeService,
someCallableFunction,
} from "./_aqua/someFunction";
async function main() {
await FluencePeer.default.init({
connectTo: relay,
});
// ... more application logic
registerSomeService({
handler: async (str) => {
console.log(str);
},
});
await someCallableFunction(arg1, arg2, arg3);
await FluencePeer.default.uninit();
}
// ... more application logic
```
If your application needs several peers, you should create a separate `FluncePeer` instance for each of them. The generated functions accept the peer as the first argument. For example:
```typescript
import { FluencePeer } from "@fluencelabs/fluence";
import {
registerSomeService,
someCallableFunction,
} from "./_aqua/someFunction";
async function main() {
const peer1 = new FluencePeer();
const peer2 = new FluencePeer();
// Don't forget to initialize peers
await peer1.init({
connectTo: relay,
});
await peer2.init({
connectTo: relay,
});
// ... more application logic
// Pass the peer as the first agument
// ||
// \/
registerSomeService(peer1, {
handler: async (str) => {
console.log("Called service on peer 1: " str);
},
});
// Pass the peer as the first agument
// ||
// \/
registerSomeService(peer2, {
handler: async (str) => {
console.log("Called service on peer 2: " str);
},
});
// Pass the peer as the first agument
// ||
// \/
await someCallableFunction(peer1, arg1, arg2, arg3);
await peer1.uninit();
await peer2.uninit();
}
// ... more application logic
```
It is possible to combine usage of the default peer with another one. Pay close attention to which peer you are calling the functions against.
```typescript
// Registering handler for the default peer
registerSomeService({
handler: async (str) => {
console.log("Called agains the default peer: " str);
},
});
// Pay close attention to this
// ||
// \/
registerSomeService(someOthePeer, {
handler: async (str) => {
console.log("Called against the peer named someOtherPeer: " str);
},
});
```
# Understanding the Aqua compiler output
Aqua compiler emits TypeScript or JavaScript which in turn can be called from a js-based environemt. The compiler outputs code for the following entities:
1. Exported `func` declarations are turned into callable async functioks
2. Exported `service` declarations are turned into functions which register callback handler in a typed manner
3. For every exported `service` the compiler generated it's interface under the name `{serviceName}Def`
## Function definitions
For every exported function definition in aqua the compiler generated two overloads. One accepting the `FluencePeer` instance as the first argument, and one without it. Otherwise arguments are the same and correspond to the arguments of aqua functions. The last argument is always an optional config object with the following properties:
- `ttl`: Optional parameter which specify TTL (time to live) of particle with execution logic for the function
The return type is always a promise of the aqua function return type. If the function does not return anything, the return type will be `Promise<void>`.
Consider the following example:
```
func myFunc(arg0: string, arg1: string):
-- implementation
```
The compiler will generate the following overloads:
```typescript
export async function myFunc(
arg0: string,
arg1: string,
config?: { ttl?: number }
): Promise<void>;
export async function callMeBack(
peer: FluencePeer,
arg0: string,
arg1: string,
config?: { ttl?: number }
): Promise<void>;
```
## Service definitions
For every exported `service` declaration the compiler will generate two entities: service interface under the name `{serviceName}Def` and a function named `register{serviceName}` with several overloads. First let's describe the most complete one using the following example:
```typescript
export interface ServiceNameDef {
//... service function definitions
}
export function registerStringExtra(
peer: FluencePeer,
serviceId: string,
service: ServiceNameDef
): void;
```
- `peer` - the Fluence Peer instance where the handler should be registered. The peer can be ommited. In that case the `FluencePeer.default` will be used instead
- `serviceId` - the name of the service id. If the service was defined with the default service id in aqua code, this argument can be ommited.
- `service` - the handler for the service.
Depending on whether or not the services was defined with the default id the number of overloads will be different. In the case it **is defined**, there would be four overloads:
```typescript
// (1)
export function registerStringExtra(
//
service: ServiceNameDef
): void;
// (2)
export function registerStringExtra(
serviceId: string,
service: ServiceNameDef
): void;
// (3)
export function registerStringExtra(
peer: FluencePeer,
service: ServiceNameDef
): void;
// (4)
export function registerStringExtra(
peer: FluencePeer,
serviceId: string,
service: ServiceNameDef
): void;
```
1. Uses `FluencePeer.default` and the default id taken from aqua definition
2. Uses `FluencePeer.default` and specifies the service id explicitly
3. The default id is taken from aqua definition. The peer is specified explicitly
4. Specifying both peer and the service id.
If the default id **is not defined** in aqua code the overloads will exclude ones without service id:
```typescript
// (1)
export function registerStringExtra(
serviceId: string,
service: ServiceNameDef
): void;
// (2)
export function registerStringExtra(
peer: FluencePeer,
serviceId: string,
service: ServiceNameDef
): void;
```
1. Uses `FluencePeer.default` and specifies the service id explicitly
2. Specifying both peer and the service id.
## Service interface
The service interface type follows closely the definition in aqua code. It has the form of the object which keys correspond to the names of service members and the values are functions of the type translated from aqua definition (see Type convertion). For example, for the following aqua definition:
```
service Calc("calc"):
add(n: f32)
subtract(n: f32)
multiply(n: f32)
divide(n: f32)
reset()
getResult() -> f32
```
The typescript interface will be:
```typescript
export interface CalcDef {
add: (n: number, callParams: CallParams<"n">) => void;
subtract: (n: number, callParams: CallParams<"n">) => void;
multiply: (n: number, callParams: CallParams<"n">) => void;
divide: (n: number, callParams: CallParams<"n">) => void;
reset: (callParams: CallParams<null>) => void;
getResult: (callParams: CallParams<null>) => number;
}
```
`CallParams` will be described later in the section
## Type convertion
Basic types convertion is pretty much straightforward:
- `string` is converted to `string` in typescript
- `bool` is converted to `boolean` in typescript
- All number types (`u8`, `u16`, `u32`, `u64`, `s8`, `s16`, `s32`, `s64`, `f32`, `f64`) are converted to `number` in typescript
Arrow types translate to functions in typescript which have their arguments translated to typescript types. In addition to arguments defined in aqua, typescript counterparts have an additional argument for call params. For the majority of use cases this parameter is not needed and can be ommited.
The type convertion works the same way for `service` and `func` definitions. For example a `func` with a callback might look like this:
```
func callMeBack(callback: string, i32 -> ()):
callback("hello, world", 42)
```
The type for `callback` argument will be:
```typescript
callback: (arg0: string, arg1: number, callParams: CallParams<'arg0' | 'arg1'>) => void,
```
For the service definitions arguments are named (see calc example above)
## Call params and tetraplets
Each service call is accompanied by additional information specific to Fluence Protocol. Including `initPeerId` - the peer which initiated the particle execution, particle signature and most importantly security tetraplets. All this data is contained inside the last `callParams` argument in every generated function definition. These data is passed to the handler on each function call can be used in the application.
Tetraplets have the form of:
```typescript
{
argName0: SecurityTetraplet[],
argName1: SecurityTetraplet[],
// ...
}
```
To learn more about tetraplets and application security see [Security](knowledge_security.md)
To see full specification of `CallParms` type see [Api reference](js-sdk/6_reference/modules.md)

View File

@ -0,0 +1 @@
You can use the JS SDK with any framework (or even without it). Just follow the steps from the previous sections. FluentPad is an example application written in React: https://github.com/fluencelabs/fluent-pad

124
js-sdk/5_run_in_node.md Normal file
View File

@ -0,0 +1,124 @@
# Intro
JS SDK makes it easy to run applications in NodeJS environment. You can take full advantage of the javascript ecosystem and at the save time expose service to the Fluence Network. That makes is an excellent choice for quick prototyping of applications for Fluence Stack.
# Calc app example
Lets implement a very simple app which simulates a desk calculator. The calculator has internal memory and implements the following set of operations:
- Add a number
- Subtract a number
- Multiply by a number
- Divide by a number
- Get the current memory state
- Reset the memory state to 0.0
First, let's write the service definition in aqua:
```
-- service definition
service Calc("calc"):
add(n: f32)
subtract(n: f32)
multiply(n: f32)
divide(n: f32)
reset()
getResult() -> f32
```
Now write the implementation for this service in typescript:
```typescript
import { FluencePeer } from "@fluencelabs/fluence";
import { krasnodar } from "@fluencelabs/fluence-network-environment";
import { registerCalc, CalcDef, demoCalculation } from "./_aqua/calc";
class Calc implements CalcDef {
private _state: number = 0;
add(n: number) {
this._state += n;
}
subtract(n: number) {
this._state -= n;
}
multiply(n: number) {
this._state *= n;
}
divide(n: number) {
this._state /= n;
}
reset() {
this._state = 0;
}
getResult() {
return this._state;
}
}
const keypress = async () => {
process.stdin.setRawMode(true);
return new Promise<void>((resolve) =>
process.stdin.once("data", () => {
process.stdin.setRawMode(false);
resolve();
})
);
};
async function main() {
await FluencePeer.default.init({
connectTo: krasnodar[0],
});
registerCalc(new Calc());
console.log("application started");
console.log("peer id is: ", FluencePeer.default.connectionInfo.selfPeerId);
console.log(
"relay is: ",
FluencePeer.default.connectionInfo.connectedRelays[0]
);
console.log("press any key to continue");
await keypress();
await FluencePeer.default.uninit();
}
main();
```
As you can see all the service logic has been implemented in typescript. You have full power of npm at your disposal.
Now try running the application:
```bash
> node -r ts-node/register src/index.ts
application started
peer id is: 12D3KooWLBkw4Tz8bRoSriy5WEpHyWfU11jEK3b5yCa7FBRDRWH3
relay is: 12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e
press any key to continue
```
And the service can be called from aqua. For example:
```bash
const peer ?= "12D3KooWLBkw4Tz8bRoSriy5WEpHyWfU11jEK3b5yCa7FBRDRWH3"
const relay ?= "12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e"
func demoCalculation() -> f32:
on peer via relay
Calc.add(10)
Calc.multiply(5)
Calc.subtract(8)
Calc.divide(6)
res <- Calc.getResult()
<- res
```

View File

@ -0,0 +1,128 @@
# Class: FluencePeer
This class implements the Fluence protocol for javascript-based environments.
It provides all the necessary features to communicate with Fluence network
## Table of contents
### Constructors
- [constructor](js-sdk/6_reference/classes/FluencePeer.md#constructor)
### Accessors
- [connectionInfo](js-sdk/6_reference/classes/FluencePeer.md#connectioninfo)
- [internals](js-sdk/6_reference/classes/FluencePeer.md#internals)
- [default](js-sdk/6_reference/classes/FluencePeer.md#default)
### Methods
- [init](js-sdk/6_reference/classes/FluencePeer.md#init)
- [uninit](js-sdk/6_reference/classes/FluencePeer.md#uninit)
## Constructors
### constructor
**new FluencePeer**()
Creates a new Fluence Peer instance. Does not start the workflows.
In order to work with the Peer it has to be initialized with the `init` method
#### Defined in
[internal/FluencePeer.ts:111](https://github.com/fluencelabs/fluence-js/blob/480d630/src/internal/FluencePeer.ts#L111)
## Accessors
### connectionInfo
`get` **connectionInfo**(): `ConnectionInfo`
Get the information about Fluence Peer connections
#### Returns
`ConnectionInfo`
#### Defined in
[internal/FluencePeer.ts:116](https://github.com/fluencelabs/fluence-js/blob/480d630/src/internal/FluencePeer.ts#L116)
___
### internals
`get` **internals**(): `Object`
Does not intended to be used manually. Subject to change
#### Returns
`Object`
| Name | Type |
| :------ | :------ |
| `callServiceHandler` | `CallServiceHandler` |
| `initiateFlow` | (`request`: `RequestFlow`) => `Promise`<`void`\> |
#### Defined in
[internal/FluencePeer.ts:190](https://github.com/fluencelabs/fluence-js/blob/480d630/src/internal/FluencePeer.ts#L190)
___
### default
`Static` `get` **default**(): [`FluencePeer`](js-sdk/6_reference/classes/FluencePeer.md)
Get the default Fluence peer instance. The default peer is used automatically in all the functions generated
by the Aqua compiler if not specified otherwise.
#### Returns
[`FluencePeer`](js-sdk/6_reference/classes/FluencePeer.md)
#### Defined in
[internal/FluencePeer.ts:181](https://github.com/fluencelabs/fluence-js/blob/480d630/src/internal/FluencePeer.ts#L181)
## Methods
### init
**init**(`config?`): `Promise`<`void`\>
Initializes the peer: starts the Aqua VM, initializes the default call service handlers
and (optionally) connect to the Fluence network
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `config?` | `PeerConfig` | object specifying peer configuration |
#### Returns
`Promise`<`void`\>
#### Defined in
[internal/FluencePeer.ts:130](https://github.com/fluencelabs/fluence-js/blob/480d630/src/internal/FluencePeer.ts#L130)
___
### uninit
**uninit**(): `Promise`<`void`\>
Uninitializes the peer: stops all the underltying workflows, stops the Aqua VM
and disconnects from the Fluence network
#### Returns
`Promise`<`void`\>
#### Defined in
[internal/FluencePeer.ts:172](https://github.com/fluencelabs/fluence-js/blob/480d630/src/internal/FluencePeer.ts#L172)

View File

@ -0,0 +1,92 @@
# Interface: CallParams<ArgName\>
Additional information about a service call
## Type parameters
| Name | Type |
| :------ | :------ |
| `ArgName` | extends `string` \| ``null`` |
## Table of contents
### Properties
- [initPeerId](js-sdk/6_reference/interfaces/CallParams.md#initpeerid)
- [particleId](js-sdk/6_reference/interfaces/CallParams.md#particleid)
- [signature](js-sdk/6_reference/interfaces/CallParams.md#signature)
- [tetraplets](js-sdk/6_reference/interfaces/CallParams.md#tetraplets)
- [timeStamp](js-sdk/6_reference/interfaces/CallParams.md#timestamp)
- [ttl](js-sdk/6_reference/interfaces/CallParams.md#ttl)
## Properties
### initPeerId
**initPeerId**: `string`
The peer id which created the particle
#### Defined in
[internal/commonTypes.ts:36](https://github.com/fluencelabs/fluence-js/blob/480d630/src/internal/commonTypes.ts#L36)
___
### particleId
**particleId**: `string`
The identifier of particle which triggered the call
#### Defined in
[internal/commonTypes.ts:31](https://github.com/fluencelabs/fluence-js/blob/480d630/src/internal/commonTypes.ts#L31)
___
### signature
**signature**: `string`
Particle's signature
#### Defined in
[internal/commonTypes.ts:51](https://github.com/fluencelabs/fluence-js/blob/480d630/src/internal/commonTypes.ts#L51)
___
### tetraplets
**tetraplets**: { [key in string]: SecurityTetraplet[]}
Security tetraplets
#### Defined in
[internal/commonTypes.ts:56](https://github.com/fluencelabs/fluence-js/blob/480d630/src/internal/commonTypes.ts#L56)
___
### timeStamp
**timeStamp**: `number`
Particle's timestamp when it was created
#### Defined in
[internal/commonTypes.ts:41](https://github.com/fluencelabs/fluence-js/blob/480d630/src/internal/commonTypes.ts#L41)
___
### ttl
**ttl**: `number`
Time to live in milliseconds. The time after the particle should be expired
#### Defined in
[internal/commonTypes.ts:46](https://github.com/fluencelabs/fluence-js/blob/480d630/src/internal/commonTypes.ts#L46)

View File

@ -0,0 +1,134 @@
# @fluencelabs/fluence
## Table of contents
### Classes
- [FluencePeer](js-sdk/6_reference/classes/FluencePeer.md)
### Interfaces
- [CallParams](js-sdk/6_reference/interfaces/CallParams.md)
### Type aliases
- [AvmLoglevel](js-sdk/6_reference/modules.md#avmloglevel)
- [PeerIdB58](js-sdk/6_reference/modules.md#peeridb58)
### Functions
- [peerIdFromEd25519SK](js-sdk/6_reference/modules.md#peeridfromed25519sk)
- [peerIdToEd25519SK](js-sdk/6_reference/modules.md#peeridtoed25519sk)
- [randomPeerId](js-sdk/6_reference/modules.md#randompeerid)
- [setLogLevel](js-sdk/6_reference/modules.md#setloglevel)
## Type aliases
### AvmLoglevel
Ƭ **AvmLoglevel**: `LogLevel`
Enum representing the log level used in Aqua VM.
Possible values: 'info', 'trace', 'debug', 'info', 'warn', 'error', 'off';
#### Defined in
[internal/FluencePeer.ts:35](https://github.com/fluencelabs/fluence-js/blob/480d630/src/internal/FluencePeer.ts#L35)
___
### PeerIdB58
Ƭ **PeerIdB58**: `string`
Peer ID's id as a base58 string (multihash/CIDv0).
#### Defined in
[internal/commonTypes.ts:22](https://github.com/fluencelabs/fluence-js/blob/480d630/src/internal/commonTypes.ts#L22)
## Functions
### peerIdFromEd25519SK
`Const` **peerIdFromEd25519SK**(`sk`): `Promise`<`PeerId`\>
Generates a new peer id from base64 string contatining the 32 byte Ed25519S secret key
#### Parameters
| Name | Type |
| :------ | :------ |
| `sk` | `string` |
#### Returns
`Promise`<`PeerId`\>
- Promise with the created Peer Id
#### Defined in
[internal/peerIdUtils.ts:26](https://github.com/fluencelabs/fluence-js/blob/480d630/src/internal/peerIdUtils.ts#L26)
___
### peerIdToEd25519SK
`Const` **peerIdToEd25519SK**(`peerId`): `string`
Converts peer id into base64 string contatining the 32 byte Ed25519S secret key
#### Parameters
| Name | Type |
| :------ | :------ |
| `peerId` | `PeerId` |
#### Returns
`string`
- base64 of Ed25519S secret key
#### Defined in
[internal/peerIdUtils.ts:45](https://github.com/fluencelabs/fluence-js/blob/480d630/src/internal/peerIdUtils.ts#L45)
___
### randomPeerId
`Const` **randomPeerId**(): `Promise`<`PeerId`\>
Generates a new peer id with random private key
#### Returns
`Promise`<`PeerId`\>
- Promise with the created Peer Id
#### Defined in
[internal/peerIdUtils.ts:59](https://github.com/fluencelabs/fluence-js/blob/480d630/src/internal/peerIdUtils.ts#L59)
___
### setLogLevel
`Const` **setLogLevel**(`level`): `void`
#### Parameters
| Name | Type |
| :------ | :------ |
| `level` | `LogLevelDesc` |
#### Returns
`void`
#### Defined in
[index.ts:23](https://github.com/fluencelabs/fluence-js/blob/480d630/src/index.ts#L23)

1
js-sdk/changelog.md Normal file
View File

@ -0,0 +1 @@
Similar to what we have in aqua book

3
js-sdk/readme.md Normal file
View File

@ -0,0 +1,3 @@
JS SDK provides the implementation of the Fluence Protocol which can be hosted in js-based environment. Currently node.js 14+ and majority of the modern browsers are tested.
The JS SDK is just a library wich can be used with any framework of your choice (or even without frameworks).