5 Commits

Author SHA1 Message Date
ef1a7b9dfa folex 2021-09-21 18:48:10 +03:00
c999fbc0ef add example README 2021-09-20 19:38:19 +03:00
3e064e5570 add missing files 2021-09-20 19:35:10 +03:00
83055549df add demo example with sign, issue and verify trust 2021-09-20 19:34:46 +03:00
07ce474ab5 ci: fix typos 2021-09-17 14:37:02 +03:00
11 changed files with 4182 additions and 8 deletions

View File

@ -93,7 +93,7 @@ jobs:
id: release
uses: softprops/action-gh-release@v1
with:
name: aqua-dht ${{ env.RELEASE_VERSION }}
name: trust-graph ${{ env.RELEASE_VERSION }}
tag_name: ${{ env.RELEASE_VERSION }}
files: |
trust-graph.tar.gz
@ -138,7 +138,7 @@ jobs:
- name: Calculate SHA256
run: |
du -hs aqua-dht.tar.gz
du -hs trust-graph.tar.gz
echo $(sha256sum trust-graph.tar.gz)
echo "SHA256=$(sha256sum trust-graph.tar.gz | awk '{ print $1 }')" >> $GITHUB_ENV

18
aqua/trust-graph-api.aqua Normal file
View File

@ -0,0 +1,18 @@
import "trust-graph.aqua"
import "@fluencelabs/aqua-lib/builtin.aqua"
func get_trust_metadata(node: string, issued_for_peer_id: string, expires_at_sec: u64, issued_at_sec: u64) -> GetTrustMetadataResult:
on node:
result <- TrustGraph.get_trust_metadata(issued_for_peer_id, expires_at_sec, issued_at_sec)
<- result
func issue_trust(node: string, issued_for_peer_id: string, expires_at_sec: u64, issued_at_sec: u64, signed_metadata: []u8) -> IssueTrustResult:
on node:
result <- TrustGraph.issue_trust(issued_for_peer_id, expires_at_sec, issued_at_sec, signed_metadata)
<- result
func verify_trust(node: string, trust: Trust, issuer_peer_id: string) -> VerifyTrustResult:
on node:
timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.verify_trust(trust, issuer_peer_id, timestamp_sec)
<- result

6
example/README.md Normal file
View File

@ -0,0 +1,6 @@
# Run example locally
1. Go to `local-network`
2. Run `docker compose up -d` to start Fluence node
3. Go back to `../example`
4. Run `npm run start`
2

View File

@ -1,3 +1,3 @@
import TrustGraph from "../../aqua/trust-graph.aqua"
import get_trust_metadata, issue_trust, verify_trust from "../../aqua/trust-graph-api.aqua"
export TrustGraph
export get_trust_metadata, issue_trust, verify_trust

View File

@ -13,3 +13,53 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { get_trust_metadata, issue_trust, verify_trust } from "./generated/export";
import { Fluence, KeyPair } from "@fluencelabs/fluence";
import { Node } from "@fluencelabs/fluence-network-environment";
const bs58 = require('bs58');
let local: Node[] = [
{
peerId: "12D3KooWHBG9oaVx4i3vi6c1rSBUm7MLBmyGmmbHoZ23pmjDCnvK",
multiaddr:
"/ip4/127.0.0.1/tcp/9990/ws/p2p/12D3KooWHBG9oaVx4i3vi6c1rSBUm7MLBmyGmmbHoZ23pmjDCnvK",
},
{
peerId: "12D3KooWRABanQHUn28dxavN9ZS1zZghqoZVAYtFpoN7FdtoGTFv",
multiaddr:
"/ip4/127.0.0.1/tcp/9991/ws/p2p/12D3KooWRABanQHUn28dxavN9ZS1zZghqoZVAYtFpoN7FdtoGTFv",
},
];
async function main(environment: Node[]) {
let mgmt_keypair = await KeyPair.fromBytes(bs58.decode("/tmp/fluence/builtins_secret_key.ed25519:/.fluence/v1/builtins_secret_key.ed25519"));
await Fluence.start({ connectTo: environment[0] , KeyPair: mgmt_keypair});
console.log(
"📗 created a fluence peer %s with relay %s",
Fluence.getStatus().peerId,
Fluence.getStatus().relayPeerId
);
let trust_metadata = await get_trust_metadata(local[0].peerId, local[1].peerId, 99999999999, 0);
const issuer_kp = await KeyPair.fromBytes(bs58.decode("29Apzfedhw2Jxh94Jj4rNSmavQ1TkNe8ALYRA7bMegobwp423aLrURxLk32WtXgXHDqoSz7GAT9fQfoMhVd1e5Ww"));
console.log("Issuer peer id: %", issuer_kp.Libp2pPeerId.toB58String());
const signed_metadata = await issuer_kp.Libp2pPeerId.privKey.sign(Uint8Array.from(trust_metadata.result));
let trust = await issue_trust(local[0].peerId, local[1].peerId, 99999999999, 0, Array.from(signed_metadata));
console.log("Trust %s", trust.trust);
let result = await verify_trust(local[0].peerId, trust.trust, local[0].peerId);
console.log("Verify trust result: %s", result);
return;
}
let environment: Node[];
environment = local;
console.log("📘 Will connect to local nodes");
main(environment)
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

4040
example/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

26
example/package.json Normal file
View File

@ -0,0 +1,26 @@
{
"name": "trust-graph-aqua-example",
"version": "1.0.0",
"description": "A simple example of how to use trust-graph in TS",
"main": "index.js",
"scripts": {
"compile-aqua": "aqua -i aqua -o generated",
"prebuild": "npm run compile-aqua",
"build": "tsc",
"start": "node dist/index.js",
"prestart": "npm run build"
},
"author": "Fluence Labs",
"license": "MIT",
"dependencies": {
"@fluencelabs/aqua": "0.3.1-228",
"@fluencelabs/aqua-lib": "0.1.14",
"@fluencelabs/fluence": "^0.12.1",
"@fluencelabs/fluence-network-environment": "^1.0.10",
"@fluencelabs/trust-graph": "file:../aqua",
"bs58": "^4.0.1"
},
"devDependencies": {
"typescript": "^4.4.3"
}
}

View File

@ -0,0 +1 @@
5FwE32bDcphFzuMca7Y2qW1gdR64fTBYoRNvD4MLE1hecDGhCMQGKn8aseMr5wRo4Xo2CRFdrEAawUNLYkgQD78K

View File

@ -1,13 +1,13 @@
# management secret key is NAB5rGwT4qOEB+6nLQawkTfCOV2eiFSjgQK8bfEdZXY=
# management base58 or base64 secret key is NAB5rGwT4qOEB+6nLQawkTfCOV2eiFSjgQK8bfEdZXY=
services:
fluence-0: # /ip4/127.0.0.1/tcp/9990/ws/p2p/12D3KooWHBG9oaVx4i3vi6c1rSBUm7MLBmyGmmbHoZ23pmjDCnvK
command: -f ed25519 -k 29Apzfedhw2Jxh94Jj4rNSmavQ1TkNe8ALYRA7bMegobwp423aLrURxLk32WtXgXHDqoSz7GAT9fQfoMhVd1e5Ww -m 12D3KooWFRgVmb1uWcmCbmJqLr8tBQghL6ysSpK2VyE2VZbaQ6wy -t 7770 -w 9990 --bootstraps /dns4/fluence-1/tcp/7771 /dns4/fluence-2/tcp/7772
command: -f ed25519 -k 29Apzfedhw2Jxh94Jj4rNSmavQ1TkNe8ALYRA7bMegobwp423aLrURxLk32WtXgXHDqoSz7GAT9fQfoMhVd1e5Ww -m 12D3KooWFRgVmb1uWcmCbmJqLr8tBQghL6ysSpK2VyE2VZbaQ6wy -t 7770 -w 9990 # --bootstraps /dns4/fluence-1/tcp/7771 /dns4/fluence-2/tcp/7772
container_name: fluence-0
environment:
RUST_BACKTRACE: full
RUST_LOG: info,network=trace,aquamarine=info,aquamarine::actor=info,tokio_threadpool=info,tokio_reactor=info,mio=info,tokio_io=info,soketto=info,yamux=info,multistream_select=info,libp2p_secio=info,libp2p_websocket::framed=info,libp2p_ping=info,libp2p_core::upgrade::apply=info,libp2p_kad::kbucket=info,cranelift_codegen=info,wasmer_wasi=info,async_io=info,polling=info,wasmer_interface_types_fl=info,cranelift_codegen=info,wasmer_wasi=info,async_io=info,polling=info,wasmer_interface_types_fl=info,particle_server::behaviour::identify=info,libp2p_mplex=info,libp2p_identify=info,walrus=info,particle_protocol::libp2p_protocol::upgrade=info,kademlia::behaviour=info
WASM_LOG: info
image: fluencelabs/node:latest
image: fluencelabs/node:tg_test
ports:
- 7770:7770 # tcp
- 9990:9990 # ws
@ -18,6 +18,7 @@ services:
volumes:
- fluence-0:/.fluence
- data-0:/config
- ./builtins_secret_key.ed25519:/.fluence/v1/builtins_secret_key.ed25519
networks:
- fluence
@ -73,4 +74,4 @@ volumes:
# data-2:
networks:
fluence:
fluence: null

31
local-network/fluence.yml Normal file
View File

@ -0,0 +1,31 @@
version: "3.8"
services:
fluence-0: # /ip4/127.0.0.1/tcp/9990/ws/p2p/12D3KooWHBG9oaVx4i3vi6c1rSBUm7MLBmyGmmbHoZ23pmjDCnvK
command: -m 12D3KooWFRgVmb1uWcmCbmJqLr8tBQghL6ysSpK2VyE2VZbaQ6wy -t 7770 -w 9990 # --bootstraps /dns4/fluence-1/tcp/7771 /dns4/fluence-2/tcp/7772
container_name: fluence-0
environment:
RUST_BACKTRACE: full
RUST_LOG: info,network=trace,aquamarine=info,aquamarine::actor=info,tokio_threadpool=info,tokio_reactor=info,mio=info,tokio_io=info,soketto=info,yamux=info,multistream_select=info,libp2p_secio=info,libp2p_websocket::framed=info,libp2p_ping=info,libp2p_core::upgrade::apply=info,libp2p_kad::kbucket=info,cranelift_codegen=info,wasmer_wasi=info,async_io=info,polling=info,wasmer_interface_types_fl=info,cranelift_codegen=info,wasmer_wasi=info,async_io=info,polling=info,wasmer_interface_types_fl=info,particle_server::behaviour::identify=info,libp2p_mplex=info,libp2p_identify=info,walrus=info,particle_protocol::libp2p_protocol::upgrade=info,kademlia::behaviour=info
WASM_LOG: info
image: fluencelabs/node:tg_test
ports:
- 7770:7770 # tcp
- 9990:9990 # ws
- 5000:5001 # ipfs rpc
- 4000:4001 # ipfs swarm
- 18080:18080 # /metrics
restart: always
volumes:
- fluence-0:/.fluence
- data-0:/config
- ./secret_key.ed25519:/.fluence/v1/secret_key.ed25519
- ./builtins_secret_key.ed25519:/.fluence/v1/builtins_secret_key.ed25519
networks:
- fluence
volumes:
fluence-0:
data-0:
networks:
fluence: null

View File

@ -0,0 +1 @@
3eRPuC6vrSzYER2j2SvuYNAifdioxswJtUgdchmMPn4cYBQKmqqWTPg3Dkici8vRPRzpEJ4FPUQShzd4tBJunzoF