mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-03-15 15:30:49 +00:00
Use aqua wasm from package (#978)
This commit is contained in:
parent
abf19810dc
commit
95be4bbd6d
57
README.md
57
README.md
@ -26,60 +26,3 @@ Establish connections to predefined nodes.
|
|||||||
let client1 = await Fluence.connect("/dns4/134.209.186.43/tcp/9003/ws/p2p/12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb", peerId1);
|
let client1 = await Fluence.connect("/dns4/134.209.186.43/tcp/9003/ws/p2p/12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb", peerId1);
|
||||||
let client2 = await Fluence.connect("/ip4/134.209.186.43/tcp/9002/ws/p2p/12D3KooWHk9BjDQBUqnavciRPhAYFvqKBe4ZiPPvde7vDaqgn5er", peerId2);
|
let client2 = await Fluence.connect("/ip4/134.209.186.43/tcp/9002/ws/p2p/12D3KooWHk9BjDQBUqnavciRPhAYFvqKBe4ZiPPvde7vDaqgn5er", peerId2);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Become a provider
|
|
||||||
|
|
||||||
Create a new unique name to provide by the first client that will calculate the sum of two numbers.
|
|
||||||
```typescript
|
|
||||||
let name = "sum-calculator-" + genUUID();
|
|
||||||
|
|
||||||
await cl1.provideName(name, async (req) => {
|
|
||||||
let message = {msgId: req.arguments.msgId, result: req.arguments.one + req.arguments.two};
|
|
||||||
|
|
||||||
await cl1.sendCall(req.reply_to, message);
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## Become a provider
|
|
||||||
|
|
||||||
To declare that you're available on some token (unique name), you can become a provider of that token. For example, below you become a provider of a name `sum-calculator-1234...` so you can share that name with other people, and they can call you by that.
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
let req = {one: 12, two: 23, msgId: msgId};
|
|
||||||
|
|
||||||
let response = await client2.callProvider(name, req);
|
|
||||||
|
|
||||||
let result = response.result;
|
|
||||||
console.log(`calculation result is: ${result}`);
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Register Service
|
|
||||||
Will register service that will combine multiple modules around one serviceId
|
|
||||||
```
|
|
||||||
let serviceId = await cl2.createService(peerAddr, ["ipfs_node.wasm", "curl.wasm"]);
|
|
||||||
console.log(serviceId);
|
|
||||||
```
|
|
||||||
|
|
||||||
## Call Service
|
|
||||||
|
|
||||||
```
|
|
||||||
// peerAddr – address of the node that runs this service
|
|
||||||
// "get_address" – function to call
|
|
||||||
// { some_arg: "1" } – arguments passed to the function
|
|
||||||
// "ipfs_node.wasm" – name of the module to find function in
|
|
||||||
|
|
||||||
let resp = await cl2.service(peerAddr, serviceId, "ipfs_node.wasm", {some_arg: "1"}, "get_address")
|
|
||||||
console.log(resp)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Discover Services
|
|
||||||
|
|
||||||
```
|
|
||||||
// get available modules on node (to get info about connected node should use the method without arguments)
|
|
||||||
let modules = cl1.getAvailableModules(peerAddr);
|
|
||||||
|
|
||||||
// get interfaces of existing services
|
|
||||||
let interfaces = await cl2.getActiveInterfaces(peerAddr);
|
|
||||||
```
|
|
||||||
|
65
package-lock.json
generated
65
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "fluence",
|
"name": "fluence",
|
||||||
"version": "0.7.54",
|
"version": "0.7.68",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -24,6 +24,11 @@
|
|||||||
"strict-event-emitter-types": "^2.0.0"
|
"strict-event-emitter-types": "^2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@fluencelabs/aquamarine-stepper": {
|
||||||
|
"version": "0.0.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/@fluencelabs/aquamarine-stepper/-/aquamarine-stepper-0.0.9.tgz",
|
||||||
|
"integrity": "sha512-DzxaYuzg0zgmDdr63de72b7K0UZPRCiZ93PTxt4BpksSLdP7LNsGHSCjh6FCQpFRQEqSb5S5hFI4nEJmBzRU3Q=="
|
||||||
|
},
|
||||||
"@sinonjs/commons": {
|
"@sinonjs/commons": {
|
||||||
"version": "1.7.2",
|
"version": "1.7.2",
|
||||||
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.7.2.tgz",
|
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.7.2.tgz",
|
||||||
@ -185,17 +190,6 @@
|
|||||||
"source-map": "^0.6.1"
|
"source-map": "^0.6.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@wasm-tool/wasm-pack-plugin": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@wasm-tool/wasm-pack-plugin/-/wasm-pack-plugin-1.0.1.tgz",
|
|
||||||
"integrity": "sha512-QPGoweQl6kgQMLMLboVMwUZiJ/OBoia0VaaWr6YoFGGx7tj7aG/+4HNK5Yu8RQGNFFdVnz2SWjRaGpALoZOhiQ==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"chalk": "^2.4.1",
|
|
||||||
"command-exists": "^1.2.7",
|
|
||||||
"watchpack": "^1.6.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"@webassemblyjs/ast": {
|
"@webassemblyjs/ast": {
|
||||||
"version": "1.9.0",
|
"version": "1.9.0",
|
||||||
"resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.9.0.tgz",
|
"resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.9.0.tgz",
|
||||||
@ -1270,12 +1264,6 @@
|
|||||||
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
|
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"command-exists": {
|
|
||||||
"version": "1.2.9",
|
|
||||||
"resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz",
|
|
||||||
"integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"commander": {
|
"commander": {
|
||||||
"version": "2.20.3",
|
"version": "2.20.3",
|
||||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
|
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
|
||||||
@ -4276,9 +4264,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"libp2p-gossipsub": {
|
"libp2p-gossipsub": {
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"resolved": "https://registry.npmjs.org/libp2p-gossipsub/-/libp2p-gossipsub-0.4.6.tgz",
|
"resolved": "https://registry.npmjs.org/libp2p-gossipsub/-/libp2p-gossipsub-0.4.7.tgz",
|
||||||
"integrity": "sha512-ViGAeWwQWmXCQxg7ya5PmtLexDVpzrFjIETFhFceMGHAUI/vv8kXhLmze7SNpIhKnWx33VfxUJfQmsiKVYWjbw==",
|
"integrity": "sha512-TW5uC3afNpDSp9Dm2K9zPa9Lfjjgm5UAVQPC1gWEm7VINBGZ/az54088UAL+S4RPMg9xykJX6Cn0wk07Wd0r5A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"buffer": "^5.6.0",
|
"buffer": "^5.6.0",
|
||||||
@ -4456,22 +4444,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"libp2p-tcp": {
|
|
||||||
"version": "0.14.6",
|
|
||||||
"resolved": "https://registry.npmjs.org/libp2p-tcp/-/libp2p-tcp-0.14.6.tgz",
|
|
||||||
"integrity": "sha512-DeOdaH5QGVMKZflJmZq3dSWROxzD/YU1MFDxfi+DT4JVMcxfVMd+SpVEPMyk2wyA28H4AdGIRsH78yPjlFIyZQ==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"abortable-iterator": "^3.0.0",
|
|
||||||
"class-is": "^1.1.0",
|
|
||||||
"debug": "^4.1.1",
|
|
||||||
"err-code": "^2.0.0",
|
|
||||||
"libp2p-utils": "^0.1.2",
|
|
||||||
"mafmt": "^7.1.0",
|
|
||||||
"multiaddr": "^7.5.0",
|
|
||||||
"stream-to-it": "^0.2.2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"multiaddr": {
|
"multiaddr": {
|
||||||
"version": "7.5.0",
|
"version": "7.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/multiaddr/-/multiaddr-7.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/multiaddr/-/multiaddr-7.5.0.tgz",
|
||||||
@ -4519,19 +4491,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"stream-to-it": {
|
|
||||||
"version": "0.2.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/stream-to-it/-/stream-to-it-0.2.2.tgz",
|
|
||||||
"integrity": "sha512-waULBmQpVdr6TkDzci6t1P7dIaSZ0bHC1TaPXDUeJC5PpSK7U3T0H0Zeo/LWUnd6mnhXOmGGDKAkjUCHw5IOng==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"get-iterator": "^1.0.2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"streaming-iterables": {
|
"streaming-iterables": {
|
||||||
"version": "5.0.2",
|
"version": "5.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/streaming-iterables/-/streaming-iterables-5.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/streaming-iterables/-/streaming-iterables-5.0.3.tgz",
|
||||||
"integrity": "sha512-9z5iBWe9WXzdT0X1JT9fVC0mCcVxWt5yzZMBUIgjZnt2k23+UQF8Ac6kiI8DnlYZJn5iysvxKl3uGzlijMQ+/g==",
|
"integrity": "sha512-1AgrKjHTvaaK+iA+N3BuTXQWVb7Adyb6+v8yIW3SCTwlBVYEbm76mF8Mf0/IVo+DOk7hoeELOURBKTCMhe/qow==",
|
||||||
"dev": true
|
"dev": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4594,8 +4557,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"libp2p-ts": {
|
"libp2p-ts": {
|
||||||
"version": "git+https://github.com/ChainSafe/libp2p-ts.git#1306a2248294a89ca576ff4a7fc2c348169265c4",
|
"version": "git+https://github.com/ChainSafe/libp2p-ts.git#fca072c9764436ef71f974a211bb1befae432575",
|
||||||
"from": "git+https://github.com/ChainSafe/libp2p-ts.git",
|
"from": "git+https://github.com/ChainSafe/libp2p-ts.git#fca072c9764436ef71f974a211bb1befae432575",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@chainsafe/discv5": "^0.3.1",
|
"@chainsafe/discv5": "^0.3.1",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "fluence",
|
"name": "fluence",
|
||||||
"version": "0.7.66",
|
"version": "0.7.68",
|
||||||
"description": "the browser js-libp2p client for the Fluence network",
|
"description": "the browser js-libp2p client for the Fluence network",
|
||||||
"main": "./dist/fluence.js",
|
"main": "./dist/fluence.js",
|
||||||
"typings": "./dist/fluence.d.ts",
|
"typings": "./dist/fluence.d.ts",
|
||||||
@ -8,14 +8,14 @@
|
|||||||
"test": "mocha -r ts-node/register src/**/*.spec.ts",
|
"test": "mocha -r ts-node/register src/**/*.spec.ts",
|
||||||
"test-ts": "ts-mocha -p tsconfig.json src/**/*.spec.ts",
|
"test-ts": "ts-mocha -p tsconfig.json src/**/*.spec.ts",
|
||||||
"package:build": "NODE_ENV=production webpack && npm run package",
|
"package:build": "NODE_ENV=production webpack && npm run package",
|
||||||
"package": "tsc && rsync -r src/aqua dist --exclude src/aqua/wasmBs64.ts",
|
"package": "tsc",
|
||||||
"compile": "tsc",
|
|
||||||
"start": "webpack-dev-server -p",
|
"start": "webpack-dev-server -p",
|
||||||
"build": "webpack"
|
"build": "webpack"
|
||||||
},
|
},
|
||||||
"author": "Fluence Labs",
|
"author": "Fluence Labs",
|
||||||
"license": "Apache 2.0",
|
"license": "Apache 2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@fluencelabs/aquamarine-stepper": "0.0.9",
|
||||||
"async": "3.2.0",
|
"async": "3.2.0",
|
||||||
"base64-js": "1.3.1",
|
"base64-js": "1.3.1",
|
||||||
"bs58": "4.0.1",
|
"bs58": "4.0.1",
|
||||||
@ -39,7 +39,7 @@
|
|||||||
"assert": "2.0.0",
|
"assert": "2.0.0",
|
||||||
"chai": "4.2.0",
|
"chai": "4.2.0",
|
||||||
"clean-webpack-plugin": "3.0.0",
|
"clean-webpack-plugin": "3.0.0",
|
||||||
"libp2p-ts": "https://github.com/ChainSafe/libp2p-ts.git",
|
"libp2p-ts": "https://github.com/ChainSafe/libp2p-ts.git#fca072c9764436ef71f974a211bb1befae432575",
|
||||||
"mocha": "7.2.0",
|
"mocha": "7.2.0",
|
||||||
"ts-loader": "7.0.5",
|
"ts-loader": "7.0.5",
|
||||||
"ts-mocha": "7.0.0",
|
"ts-mocha": "7.0.0",
|
||||||
@ -47,7 +47,6 @@
|
|||||||
"webpack": "4.43.0",
|
"webpack": "4.43.0",
|
||||||
"webpack-cli": "3.3.11",
|
"webpack-cli": "3.3.11",
|
||||||
"webpack-dev-server": "3.11.0",
|
"webpack-dev-server": "3.11.0",
|
||||||
"@wasm-tool/wasm-pack-plugin": "1.0.1",
|
|
||||||
"html-webpack-plugin": "^3.2.0",
|
"html-webpack-plugin": "^3.2.0",
|
||||||
"text-encoding": "^0.7.0"
|
"text-encoding": "^0.7.0"
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
@ -14,7 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {wasmBs64} from "./aqua/wasmBs64";
|
|
||||||
import {toByteArray} from "base64-js";
|
import {toByteArray} from "base64-js";
|
||||||
import * as aqua from "./aqua"
|
import * as aqua from "./aqua"
|
||||||
|
|
||||||
@ -22,6 +21,7 @@ import {service} from "./service";
|
|||||||
import {getInt32Memory0, getStringFromWasm0, passStringToWasm0, WASM_VECTOR_LEN} from "./aqua";
|
import {getInt32Memory0, getStringFromWasm0, passStringToWasm0, WASM_VECTOR_LEN} from "./aqua";
|
||||||
import PeerId from "peer-id";
|
import PeerId from "peer-id";
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
|
import {wasmBs64} from "@fluencelabs/aquamarine-stepper";
|
||||||
|
|
||||||
export type Stepper = (init_user_id: string, script: string, prev_data: string, data: string) => string
|
export type Stepper = (init_user_id: string, script: string, prev_data: string, data: string) => string
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin");
|
|
||||||
|
|
||||||
const production = (process.env.NODE_ENV === 'production');
|
const production = (process.env.NODE_ENV === 'production');
|
||||||
|
|
||||||
@ -30,11 +29,6 @@ const config = {
|
|||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new HtmlWebpackPlugin(),
|
new HtmlWebpackPlugin(),
|
||||||
new WasmPackPlugin({
|
|
||||||
// TODO use another path somehow
|
|
||||||
crateDirectory: path.resolve(__dirname, "../../../aquamarine/stepper"),
|
|
||||||
outDir:path.resolve(__dirname, "./pkg")
|
|
||||||
}),
|
|
||||||
new webpack.ProvidePlugin({
|
new webpack.ProvidePlugin({
|
||||||
TextDecoder: ['text-encoding', 'TextDecoder'],
|
TextDecoder: ['text-encoding', 'TextDecoder'],
|
||||||
TextEncoder: ['text-encoding', 'TextEncoder']
|
TextEncoder: ['text-encoding', 'TextEncoder']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user