Compare commits

...

24 Commits

Author SHA1 Message Date
d0c6c62ca4 chore: release master (#96) 2023-05-08 18:21:23 +04:00
b6df3fe548 feat: dummy change for release (#95) 2023-05-08 17:08:41 +03:00
a747b9cc75 feat(builtin-package): use new blueprint (#94) 2023-05-08 16:48:39 +03:00
d567848cba chore: release master (#92) 2023-05-03 16:58:12 +04:00
9b942eacca feat(keypair): Make KeyFormat more convenient (#91)
* feat(keypair): Make `KeyFormat` more convenient

1. Make `KeyFormat` implement `Debug`, `Clone` and `Eq`.
2. Add `KeyPair::key_format(&self) -> KeyFormat` method.
2023-05-03 02:48:42 +07:00
c85fb16de3 chore: Fix build script (#90)
Fix build script
2023-04-18 16:42:51 +03:00
97ce5bbac7 chore(release-please): Fix publishing (#89)
Fix typo
2023-04-18 11:24:24 +03:00
864b7f5c13 chore: release master (#83) 2023-04-13 16:11:54 +03:00
da38a41ba7 fix(deps): Add trust-graph to workspace and bump sqlite-wasm version (#87)
* Add trust-graph to workspace

* Bump sqlite lite version

* Fix link
2023-04-13 15:03:08 +03:00
7493eed216 chore: skip cargo-workspace merge in release-please (#86)
Fix
2023-04-13 13:59:44 +03:00
e9399b7d0c chore: Move trust-graph to subdir (#85)
* Fix?

* Move trust-grap to subdir

* fix quickcheck update

* fix fmt

* fix service tests

* use marine 0.9.1

---------

Co-authored-by: Maria Kuklina <maria@fluence.one>
Co-authored-by: Valery Antopol <valery.antopol@gmail.com>
2023-04-13 13:55:35 +03:00
81eb924476 chore: Try workaround for release-please merge issue (#84) 2023-04-12 17:06:28 +03:00
fe902acc50 update aqua-lib (#81) 2023-04-12 15:22:47 +02:00
f5994b33d1 chore: Use setup-marine action (#78) 2023-03-20 12:19:48 +04:00
554bb60256 chore: release master (#63)
* chore: release master

* chore: bump fluence-keypair to 0.10.0 manually

---------

Co-authored-by: folex <0xdxdy@gmail.com>
2023-03-15 19:34:08 -03:00
080503dcfa feat(deps)!: update libp2p to 0.39.1 and other deps (#77)
Co-authored-by: folex <0xdxdy@gmail.com>
2023-03-15 19:17:21 -03:00
757145fffc chore: Add release-please, renovate (#61) 2023-01-30 15:32:57 +04:00
8e58f56190 chore: Update CI and fix clippy warnings [fixes FLU-251] (#62)
* Add release-please and renovate

* Update ci

* Revert "Add release-please and renovate"

This reverts commit a37a4e2a59.

* Allow unnecessary_lazy_evaluations
2023-01-30 18:43:16 +08:00
664552d4f9 chore: update cargo dependencies (#55) 2023-01-30 14:42:12 +04:00
c717e4dc73 chore(fluence-keypair): increment fluence-keypair version to 0.9.0 (#60)
* Increment version

* Increment version

* Increment version
2023-01-27 17:09:12 +03:00
015422efcc Update libp2p-core to 0.38 (#51) 2023-01-27 16:43:47 +03:00
0c1398b377 Create bin dir (#59) 2023-01-27 01:11:55 +04:00
bc638ddda3 chore(ci): remove jq install step (#58) 2023-01-26 23:08:24 +02:00
8cf640c9b5 chore(ci): make release with older marine (#57) 2023-01-27 01:04:05 +04:00
50 changed files with 4397 additions and 4543 deletions

3
.github/actionlint.yaml vendored Normal file
View File

@ -0,0 +1,3 @@
self-hosted-runner:
labels:
- builder

View File

@ -1,14 +0,0 @@
#!/bin/bash
set -o pipefail -o errexit -o nounset
set -x
MARINE_RELEASE="https://api.github.com/repos/fluencelabs/marine/releases/latest"
OUT_DIR=~/.bin
# get metadata about release
curl -s -H "Accept: application/vnd.github.v3+json" $MARINE_RELEASE |
# extract url and name for asset with name "marine"
# also append $OUT_DIR to each name so file is saved to $OUT_DIR
jq -r ".assets | .[] | select(.name == \"marine\") | \"\(.browser_download_url) $OUT_DIR/\(.name)\"" |
# download assets
xargs -n2 bash -c 'curl -L $0 -o $1 && chmod +x $1'

36
.github/release-please/config.json vendored Normal file
View File

@ -0,0 +1,36 @@
{
"boostrap-sha": "015422efcce41530a6cd84a25091598bc459d2e6",
"release-type": "rust",
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"plugins": [
{
"type": "cargo-workspace",
"merge": false
},
{
"type": "linked-versions",
"groupName": "trust-graph, wasm and api",
"components": [
"trust-graph",
"trust-graph-api",
"trust-graph-wasm"
]
}
],
"packages": {
"trust-graph": {
"component": "trust-graph"
},
"aqua": {
"release-type": "node",
"component": "trust-graph-api"
},
"service": {
"component": "trust-graph-wasm"
},
"keypair": {
"component": "keypair"
}
}
}

6
.github/release-please/manifest.json vendored Normal file
View File

@ -0,0 +1,6 @@
{
"trust-graph": "0.4.3",
"aqua": "0.4.3",
"service": "0.4.3",
"keypair": "0.10.1"
}

38
.github/renovate.json vendored Normal file
View File

@ -0,0 +1,38 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base",
":semanticCommitTypeAll(chore)"
],
"enabledManagers": ["cargo", "npm", "github-actions", "pip_requirements"],
"rangeStrategy": "pin",
"schedule": "every weekend",
"packageRules": [
{
"matchManagers": ["cargo", "npm"],
"matchPackagePatterns": [
"@fluencelabs/.*",
"fluence-.*",
"marine-.*"
],
"semanticCommitType": "fix",
"semanticCommitScope": "deps",
"schedule": "at any time"
},
{
"matchDepTypes": ["devDependencies"],
"prPriority": -1,
"semanticCommitType": "chore",
"semanticCommitScope": "deps"
},
{
"matchUpdateTypes": ["major"],
"prConcurrentLimit": 1
},
{
"matchManagers": ["github-actions"],
"groupName": "all github-actions",
"prPriority": -1
}
]
}

View File

@ -1,6 +0,0 @@
{
"template": "## Changes since ${{FROM_TAG}}\n\n${{CHANGELOG}}\n\n${{UNCATEGORIZED}}",
"pr_template": "- #${{NUMBER}} ${{TITLE}}",
"empty_template": "## No changes since ${{FROM_TAG}}",
"sort": "DESC"
}

35
.github/workflows/lint.yml vendored Normal file
View File

@ -0,0 +1,35 @@
name: lint
on:
pull_request:
types:
- opened
- edited
- synchronize
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
jobs:
pr:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
reviewdog:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Lint actions
uses: reviewdog/action-actionlint@v1
env:
SHELLCHECK_OPTS: "-e SC2086 -e SC2207 -e SC2128"
with:
reporter: github-pr-check
fail_on_error: true

View File

@ -1,133 +1,192 @@
name: "publish-release"
name: "release"
on:
push:
tags:
- "v*"
branches:
- "master"
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
jobs:
release:
name: "Publish"
runs-on: builder
release-please:
runs-on: ubuntu-latest
outputs:
releases-created: ${{ steps.release.outputs['releases_created'] }}
trust-graph-api-release-created: ${{ steps.release.outputs['aqua--release_created'] }}
trust-graph-release-created: ${{ steps.release.outputs['trust-graph--release_created'] }}
trust-graph-tag-name: ${{ steps.release.outputs['trust-graph--tag_name'] }}
steps:
### Setup
- name: Checkout repository
- name: Run release-please
id: release
uses: google-github-actions/release-please-action@v3
with:
token: ${{ secrets.FLUENCEBOT_RELEASE_PLEASE_PAT }}
command: manifest
config-file: .github/release-please/config.json
manifest-file: .github/release-please/manifest.json
- name: Show output from release-please
if: steps.release.outputs.releases_created
env:
RELEASE_PLEASE_OUTPUT: ${{ toJSON(steps.release.outputs) }}
run: echo "${RELEASE_PLEASE_OUTPUT}" | jq
publish:
runs-on: builder
needs: release-please
if: needs.release-please.outputs.releases-created
permissions:
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- uses: actions/setup-node@v3
- name: Import secrets
uses: hashicorp/vault-action@v2.4.3
with:
node-version: "15"
registry-url: "https://registry.npmjs.org"
cache: npm
cache-dependency-path: "aqua/package-lock.json"
url: https://vault.fluence.dev
path: jwt/github
role: ci
method: jwt
jwtGithubAudience: "https://github.com/fluencelabs"
jwtTtl: 300
exportToken: false
secrets: |
kv/npmjs/fluencebot token | NODE_AUTH_TOKEN ;
kv/crates.io/fluencebot token | CARGO_REGISTRY_TOKEN
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install Marine
- name: Setup marine
uses: fluencelabs/setup-marine@v1
- name: Build
run: ./build.sh
working-directory: service
- name: Install cargo-workspaces
uses: baptiste0928/cargo-install@v1.3.0
with:
crate: marine
crate: cargo-workspaces
- name: Build trust-graph
working-directory: ./service
run: ./build.sh
- name: Check Aqua compiles
working-directory: ./aqua
- name: Publish to crates.io
run: |
npm i
npm run build
cargo ws publish \
--no-git-commit \
--allow-dirty \
--from-git \
--skip-published \
--yes
- name: Create distribution package
run: |
./builtin-package/package.sh
- name: Build Changelog
id: changelog
uses: mikepenz/release-changelog-builder-action@v1
- name: Setup node
uses: actions/setup-node@v3
with:
configuration: ".github/workflows/changelog_config.json"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
node-version: "16"
registry-url: "https://registry.npmjs.org"
cache-dependency-path: "aqua/package-lock.json"
cache: "npm"
### Publish
- name: Release to GitHub
id: release
- run: npm i
working-directory: aqua
- run: npm run build
working-directory: aqua
- name: Publish to NPM registry
if: needs.release-please.outputs.trust-graph-api-release-created
run: npm publish --access public
working-directory: aqua
- name: Install ipfs
uses: nahsi/setup-ipfs@v1
- name: Create builtin distribution package
if: needs.release-please.outputs.trust-graph-release-created
run: ./builtin-package/package.sh
- name: Calculate SHA256
if: needs.release-please.outputs.trust-graph-release-created
id: sha
run: |
# Calculate sha256
du -hs trust-graph.tar.gz
sha256sum trust-graph.tar.gz
sha=($(sha256sum trust-graph.tar.gz))
echo "sha256=${sha}" >> $GITHUB_OUTPUT
- name: Upload trust-graph package
if: needs.release-please.outputs.trust-graph-release-created
uses: softprops/action-gh-release@v1
with:
name: trust-graph ${{ env.RELEASE_VERSION }}
tag_name: ${{ env.RELEASE_VERSION }}
files: |
./trust-graph.tar.gz
body: ${{steps.changelog.outputs.changelog}}
draft: false
prerelease: false
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
### Publish Aqua API
- name: Publish Aqua API to NPM
run: |
npm version ${{ env.RELEASE_VERSION }}
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
working-directory: ./aqua
## Update node-distro repo
- name: Calculate SHA256
run: |
du -hs trust-graph.tar.gz
echo $(sha256sum trust-graph.tar.gz)
echo "SHA256=$(sha256sum trust-graph.tar.gz | awk '{ print $1 }')" >> $GITHUB_ENV
- name: Get tar.gz URL
id: package-url
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
try {
let assets = await github.repos.listReleaseAssets({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: "${{ steps.release.outputs.id }}",
});
console.dir(assets);
let package = assets.data.find((a) => a.name === 'trust-graph.tar.gz');
let url = package.browser_download_url;
console.log("URL: " + url);
return url;
} catch (e) {
console.log("Err: " + e);
throw e;
}
files: trust-graph.tar.gz
tag_name: ${{ needs.release-please.outputs.trust-graph-tag-name }}
- name: Update version in node-distro repo
if: needs.release-please.outputs.trust-graph-release-created
uses: benc-uk/workflow-dispatch@v1
with:
workflow: update_service
repo: fluencelabs/node-distro
ref: 'main'
ref: "main"
token: ${{ secrets.PERSONAL_TOKEN }}
inputs: '{
"name": "trust-graph",
"version": "${{ env.RELEASE_VERSION }}",
"url": "${{ steps.package-url.outputs.result }}",
"sha256": "${{ env.SHA256 }}"
"version": "${{ needs.release-please.outputs.version }}",
"url": "https://github.com/fluencelabs/trust-graph/releases/download/${{ needs.release-please.outputs.trust-graph-tag-name }}/trust-graph.tar.gz",
"sha256": "${{ steps.sha.outputs.sha256 }}"
}'
- name: Log notice
uses: actions/github-script@v4
slack:
if: always()
name: "Notify"
runs-on: ubuntu-latest
needs:
- release-please
- publish
permissions:
contents: read
id-token: write
steps:
- uses: lwhiteley/dependent-jobs-result-check@v1
id: status
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
console.dir(core);
core.info("trust-graph was updated to ${{ env.RELEASE_VERSION }} in node-distro repo");
statuses: failure
dependencies: ${{ toJSON(needs) }}
- name: Log output
run: |
echo "statuses:" "${{ steps.status.outputs.statuses }}"
echo "jobs:" "${{ steps.status.outputs.jobs }}"
echo "found any?:" "${{ steps.status.outputs.found }}"
- name: Import secrets
uses: hashicorp/vault-action@v2.4.3
with:
url: https://vault.fluence.dev
path: jwt/github
role: ci
method: jwt
jwtGithubAudience: "https://github.com/fluencelabs"
jwtTtl: 300
exportToken: false
secrets: |
kv/slack/release-please webhook | SLACK_WEBHOOK_URL
- uses: ravsamhq/notify-slack-action@v2
if: steps.status.outputs.found == 'true'
with:
status: "failure"
notification_title: "*{workflow}* has {status_message}"
message_format: "${{ steps.status.outputs.jobs }} {status_message} in <{repo_url}|{repo}>"
footer: "<{run_url}>"

35
.github/workflows/run-tests.yml vendored Normal file
View File

@ -0,0 +1,35 @@
name: Run tests
on:
pull_request:
paths-ignore:
- "**.md"
push:
branches:
- "master"
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
jobs:
trust-graph:
uses: ./.github/workflows/tests.yml
lints:
name: lints
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Setup rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

View File

@ -1,89 +0,0 @@
name: Rust CI
on:
push:
workflow_dispatch:
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
jobs:
check:
name: cargo nextest
runs-on: builder
defaults:
run:
working-directory: service
shell: bash
steps:
- name: Checkout sources
uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- run: mkdir -p ~/.bin
- run: echo "~/.bin" >> $GITHUB_PATH
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
- name: Add wasm32-wasi target
run: rustup target add wasm32-wasi
- name: Download jq
run: |
curl -L https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 -o ~/.bin/jq
chmod +x ~/.bin/jq
- name: Download marine
run: bash $GITHUB_WORKSPACE/.github/download_marine.sh
- name: Build
run: ./build.sh
- run: cargo install --locked cargo-nextest --version 0.9.22
- run: cargo nextest run --release --all-features --no-fail-fast --retries 10 --test-threads 10
lints:
name: Lints
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: rustfmt, clippy
- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: -Z unstable-options --all
continue-on-error: true # do not fail for now

View File

@ -1,25 +0,0 @@
name: "tag"
on:
workflow_dispatch:
jobs:
tag:
name: "Tag"
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v2
- name: Get branch
run: |
BRANCH=${GITHUB_REF#refs/*/}
SANITIZED=$(echo "$BRANCH" | sed -e 's/[^a-zA-Z0-9-]/-/g')
echo "BRANCH=$SANITIZED" >> $GITHUB_ENV
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@v5.5
with:
append_to_pre_release_tag: ${{ env.BRANCH }}
github_token: ${{ secrets.PERSONAL_TOKEN }}

71
.github/workflows/tests.yml vendored Normal file
View File

@ -0,0 +1,71 @@
name: Run tests with workflow_call
on:
workflow_call:
jobs:
trust-graph:
name: "cargo nextest"
runs-on: builder
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Setup marine
uses: fluencelabs/setup-marine@v1
- name: Build
working-directory: ./service
run: ./build.sh
- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: -Z unstable-options --all
- name: Install cargo-nextest
uses: baptiste0928/cargo-install@v1.3.0
with:
crate: cargo-nextest
version: 0.9.22
- name: Run cargo nextest
env:
NEXTEST_RETRIES: 10
NEXTEST_TEST_THREADS: 10
run: cargo nextest run --release --all-features --no-fail-fast
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: "16"
registry-url: "https://registry.npmjs.org"
cache-dependency-path: "aqua/package-lock.json"
cache: "npm"
- run: npm i
working-directory: aqua
- run: npm run build
working-directory: aqua
- name: Install ipfs
uses: nahsi/setup-ipfs@v1
- name: Create distribution package
run: ./builtin-package/package.sh
- name: Upload trust-graph
uses: actions/upload-artifact@v3
with:
name: trust-graph
path: trust-graph.tar.gz

3032
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +1,9 @@
[package]
name = "trust-graph"
version = "0.3.0"
authors = ["Fluence Labs"]
edition = "2018"
description = "trust graph"
license = "Apache-2.0"
repository = "https://github.com/fluencelabs/trust-graph"
[dependencies]
serde = { version = "1.0.118", features = ["derive"] }
fluence-keypair = { path = "./keypair", version = "0.8.1" }
serde_json = "1.0.58"
bs58 = "0.3.1"
failure = "0.1.6"
log = "0.4.11"
ref-cast = "1.0.2"
derivative = "2.1.1"
signature = "1.3.0"
serde_with = "1.6.0"
thiserror = "1.0.23"
sha2 = "0.9.5"
rand = "0.7.0"
nonempty = "0.7.0"
[workspace]
members = [
"trust-graph",
"keypair",
"service"
]
[workspace.dependencies]
libp2p-core = { version = "0.36", default-features = false, features = [ "secp256k1", "rsa" ] }
libp2p-identity = { version = "0.1.0", default-features = false, features = ["peerid", "rsa", "ed25519", "secp256k1", "multihash"] }

23
aqua/CHANGELOG.md Normal file
View File

@ -0,0 +1,23 @@
# Changelog
## [0.4.3](https://github.com/fluencelabs/trust-graph/compare/trust-graph-api-v0.4.1...trust-graph-api-v0.4.3) (2023-05-08)
### Miscellaneous Chores
* **trust-graph-api:** Synchronize trust-graph, wasm and api versions
## [0.4.1](https://github.com/fluencelabs/trust-graph/compare/trust-graph-api-v0.4.0...trust-graph-api-v0.4.1) (2023-04-13)
### Bug Fixes
* **deps:** update aqua to 0.10.3 ([fe902ac](https://github.com/fluencelabs/trust-graph/commit/fe902acc50a6b4c6bf97c487f3e47ae0f5ef8a95))
* **deps:** update aqua-lib to 0.7.0 ([fe902ac](https://github.com/fluencelabs/trust-graph/commit/fe902acc50a6b4c6bf97c487f3e47ae0f5ef8a95))
## [0.4.0](https://github.com/fluencelabs/trust-graph/compare/trust-graph-api-v0.3.2...trust-graph-api-v0.4.0) (2023-03-15)
### Miscellaneous Chores
* **trust-graph-api:** Synchronize trust-graph, wasm and api versions

4780
aqua/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,12 @@
{
"name": "@fluencelabs/trust-graph",
"version": "0.2.2",
"version": "0.4.3",
"description": "Aqua Trust Graph API library",
"files": [
"*.aqua"
],
"dependencies": {
"@fluencelabs/aqua-lib": "^0.5.2"
"@fluencelabs/aqua-lib": "^0.7.0"
},
"scripts": {
"generate-aqua": "../service/build.sh",
@ -31,6 +31,6 @@
},
"homepage": "https://github.com/fluencelabs/trust-graph#readme",
"devDependencies": {
"@fluencelabs/aqua": "^0.7.4-322"
"@fluencelabs/aqua": "^0.10.3"
}
}

View File

@ -1,7 +0,0 @@
{
"name": "trust-graph",
"dependencies": [
"name:sqlite3",
"name:trust-graph"
]
}

View File

@ -3,20 +3,39 @@ set -o pipefail -o nounset -o errexit
# set current working directory to script directory to run script from everywhere
cd "$(dirname "$0")"
SCRIPT_DIR="$(pwd)"
PACKAGE_DIR="$(pwd)/../package"
(
rm -f $PACKAGE_DIR/*
mkdir -p $PACKAGE_DIR
)
(
echo "*** copy wasm files ***"
cd ../service
cp artifacts/*.wasm "$SCRIPT_DIR"
cp artifacts/*.wasm "$PACKAGE_DIR"
)
(
echo "*** copy on_start script ***"
cp on_start.json "$PACKAGE_DIR"
cp on_start.air "$PACKAGE_DIR"
)
TRUST_GRAPH_CID=$(ipfs add -q --only-hash --cid-version=1 --chunker=size-262144 $PACKAGE_DIR/trust-graph.wasm)
SQLITE_CID=$(ipfs add -q --only-hash --cid-version=1 --chunker=size-262144 $PACKAGE_DIR/sqlite3.wasm)
mv $PACKAGE_DIR/trust-graph.wasm "$PACKAGE_DIR"/"$TRUST_GRAPH_CID".wasm
mv $PACKAGE_DIR/sqlite3.wasm "$PACKAGE_DIR"/"$SQLITE_CID".wasm
cp trust-graph_config.json "$PACKAGE_DIR"/"$TRUST_GRAPH_CID"_config.json
cp sqlite3_config.json "$PACKAGE_DIR"/"$SQLITE_CID"_config.json
# write blueprint.json
echo "{}" | jq --arg trust_graph_cid "$TRUST_GRAPH_CID" --arg sqlite_cid "$SQLITE_CID" '{"name": "trust-graph", "dependencies":[{"/":$sqlite_cid},{"/":$trust_graph_cid}]}' > "$PACKAGE_DIR/blueprint.json"
(
echo "*** create builtin distribution package ***"
cd ..
mv builtin-package trust-graph
tar --exclude="package.sh" -f trust-graph.tar.gz -zcv ./trust-graph
mv trust-graph builtin-package
cd $PACKAGE_DIR
(tar cf - * | gzip) > ../trust-graph.tar.gz
)
echo "*** done ***"

View File

@ -4,6 +4,25 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.10.1](https://github.com/fluencelabs/trust-graph/compare/keypair-v0.10.0...keypair-v0.10.1) (2023-05-02)
### Features
* **keypair:** Make `KeyFormat` more convenient ([#91](https://github.com/fluencelabs/trust-graph/issues/91)) ([9b942ea](https://github.com/fluencelabs/trust-graph/commit/9b942eacca49d0468b4d7512667102363a6c9aa3))
## [0.10.0](https://github.com/fluencelabs/trust-graph/compare/keypair-v0.9.0...keypair-v0.10.0) (2023-03-15)
### ⚠ BREAKING CHANGES
* **deps:** update libp2p to 0.39.1 and other deps ([#77](https://github.com/fluencelabs/trust-graph/issues/77))
### Features
* **deps:** update libp2p to 0.39.1 and other deps ([#77](https://github.com/fluencelabs/trust-graph/issues/77)) ([080503d](https://github.com/fluencelabs/trust-graph/commit/080503dcfa2ecf8d09167ff9fe7f750fadf49035))
* **keypair:** add KeyPair::from_secret_key ([#50](https://github.com/fluencelabs/trust-graph/issues/50)) ([a6ce8d9](https://github.com/fluencelabs/trust-graph/commit/a6ce8d9eee20e1ea24eb27c38ac6df6d878292ae))
## [Unreleased]
## [0.8.1] - 2022-10-06

View File

@ -1,33 +1,30 @@
[package]
name = "fluence-keypair"
version = "0.8.1"
version = "0.10.1"
authors = ["Fluence Labs"]
edition = "2018"
edition = "2021"
description = "identity"
license = "Apache-2.0"
repository = "https://github.com/fluencelabs/trust-graph"
[dependencies]
serde = { version = "1.0.118", features = ["derive"] }
serde_json = "1.0.58"
bs58 = "0.3.1"
bs58 = "0.4.0"
ed25519-dalek = { version = "1.0.1", features = ["serde", "std"] }
rand = "0.7.0"
signature = "1.3.0"
ed25519 = "1.0.3"
serde_with = "1.6.0"
rand = "0.8.5"
thiserror = "1.0.23"
lazy_static = "1.2"
libsecp256k1 = "0.7.1"
asn1_der = "0.6.1"
sha2 = "0.9.1"
sha2 = "0.10.6"
zeroize = "1"
serde_bytes = "0.11"
libp2p-core = { workspace = true }
eyre = "0.6.5"
libp2p-identity = { workspace = true, default-features = false, features = ["peerid", "rsa", "ed25519", "secp256k1", "multihash"] }
multihash = { version = "0.18.0", features = ["identity"] }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
ring = { version = "0.16.9", features = ["alloc", "std"], default-features = false }
[dev-dependencies]
quickcheck = "0.9.0"
quickcheck = "1.0.3"

View File

@ -26,7 +26,7 @@ use crate::public_key::PublicKey;
use crate::rsa;
use crate::secp256k1;
use crate::signature::Signature;
use libp2p_core::PeerId;
use libp2p_identity::PeerId;
use std::convert::TryFrom;
use std::str::FromStr;
@ -48,6 +48,7 @@ use std::str::FromStr;
/// ```
///
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum KeyFormat {
Ed25519,
#[cfg(not(target_arch = "wasm32"))]
@ -168,6 +169,18 @@ impl KeyPair {
}
}
/// Get the key format of this keypair.
pub fn key_format(&self) -> KeyFormat {
use KeyPair::*;
match self {
Ed25519(_) => KeyFormat::Ed25519,
#[cfg(not(target_arch = "wasm32"))]
Rsa(_) => KeyFormat::Rsa,
Secp256k1(_) => KeyFormat::Secp256k1,
}
}
/// Get the public key of this keypair.
pub fn public(&self) -> PublicKey {
use KeyPair::*;
@ -235,16 +248,17 @@ impl KeyPair {
}
}
impl From<libp2p_core::identity::Keypair> for KeyPair {
fn from(key: libp2p_core::identity::Keypair) -> Self {
use libp2p_core::identity::Keypair::*;
impl From<libp2p_identity::Keypair> for KeyPair {
fn from(key: libp2p_identity::Keypair) -> Self {
use libp2p_identity::Keypair::*;
#[allow(deprecated)] //TODO: fix it later
match key {
Ed25519(kp) => KeyPair::Ed25519(ed25519::Keypair::decode(&mut kp.encode()).unwrap()),
#[cfg(not(target_arch = "wasm32"))]
// safety: these Keypair structures are identical
Rsa(kp) => KeyPair::Rsa(unsafe {
std::mem::transmute::<libp2p_core::identity::rsa::Keypair, rsa::Keypair>(kp)
std::mem::transmute::<libp2p_identity::rsa::Keypair, rsa::Keypair>(kp)
}),
Secp256k1(kp) => KeyPair::Secp256k1(secp256k1::Keypair::from(
secp256k1::SecretKey::from_bytes(kp.secret().to_bytes()).unwrap(),
@ -253,23 +267,24 @@ impl From<libp2p_core::identity::Keypair> for KeyPair {
}
}
impl From<KeyPair> for libp2p_core::identity::Keypair {
impl From<KeyPair> for libp2p_identity::Keypair {
fn from(key: KeyPair) -> Self {
use libp2p_core::identity;
use libp2p_core::identity::Keypair;
use libp2p_identity::Keypair;
use KeyPair::*;
#[allow(deprecated)] //TODO: fix it later
match key {
Ed25519(kp) => Keypair::Ed25519(
identity::ed25519::Keypair::decode(kp.encode().to_vec().as_mut_slice()).unwrap(),
libp2p_identity::ed25519::Keypair::decode(kp.encode().to_vec().as_mut_slice())
.unwrap(),
),
#[cfg(not(target_arch = "wasm32"))]
// safety: these Keypair structures are identical
Rsa(kp) => Keypair::Rsa(unsafe {
std::mem::transmute::<rsa::Keypair, libp2p_core::identity::rsa::Keypair>(kp)
std::mem::transmute::<rsa::Keypair, libp2p_identity::rsa::Keypair>(kp)
}),
Secp256k1(kp) => Keypair::Secp256k1(identity::secp256k1::Keypair::from(
identity::secp256k1::SecretKey::from_bytes(kp.secret().to_bytes()).unwrap(),
Secp256k1(kp) => Keypair::Secp256k1(libp2p_identity::secp256k1::Keypair::from(
libp2p_identity::secp256k1::SecretKey::from_bytes(kp.secret().to_bytes()).unwrap(),
)),
}
}

View File

@ -41,7 +41,7 @@ pub use key_pair::KeyFormat;
pub use key_pair::KeyPair;
pub mod peerid_serializer {
use libp2p_core::PeerId;
use libp2p_identity::PeerId;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::str::FromStr;
@ -58,7 +58,7 @@ pub mod peerid_serializer {
{
let str = String::deserialize(deserializer)?;
PeerId::from_str(&str).map_err(|e| {
serde::de::Error::custom(format!("peer id deserialization failed for {:?}", e))
serde::de::Error::custom(format!("peer id deserialization failed for {e:?}"))
})
}
}

View File

@ -21,7 +21,7 @@ use crate::secp256k1;
use crate::signature::Signature;
use crate::key_pair::KeyFormat;
use libp2p_core::PeerId;
use libp2p_identity::PeerId;
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;
@ -124,10 +124,11 @@ impl PublicKey {
}
}
impl From<libp2p_core::identity::PublicKey> for PublicKey {
fn from(key: libp2p_core::identity::PublicKey) -> Self {
use libp2p_core::identity::PublicKey::*;
impl From<libp2p_identity::PublicKey> for PublicKey {
fn from(key: libp2p_identity::PublicKey) -> Self {
use libp2p_identity::PublicKey::*;
#[allow(deprecated)] //TODO: fix it later
match key {
Ed25519(key) => {
PublicKey::Ed25519(ed25519::PublicKey::decode(&key.encode()[..]).unwrap())
@ -141,10 +142,9 @@ impl From<libp2p_core::identity::PublicKey> for PublicKey {
}
}
impl From<PublicKey> for libp2p_core::identity::PublicKey {
impl From<PublicKey> for libp2p_identity::PublicKey {
fn from(key: PublicKey) -> Self {
use libp2p_core::identity as libp2p_identity;
#[allow(deprecated)] //TODO: fix it later
match key {
PublicKey::Ed25519(key) => libp2p_identity::PublicKey::Ed25519(
libp2p_identity::ed25519::PublicKey::decode(&key.encode()[..]).unwrap(),
@ -160,10 +160,10 @@ impl From<PublicKey> for libp2p_core::identity::PublicKey {
}
}
impl TryFrom<libp2p_core::PeerId> for PublicKey {
impl TryFrom<PeerId> for PublicKey {
type Error = DecodingError;
fn try_from(peer_id: libp2p_core::PeerId) -> Result<Self, Self::Error> {
fn try_from(peer_id: PeerId) -> Result<Self, Self::Error> {
Ok(as_public_key(&peer_id)
.ok_or_else(|| DecodingError::PublicKeyNotInlined(peer_id.to_base58()))?
.into())
@ -171,14 +171,12 @@ impl TryFrom<libp2p_core::PeerId> for PublicKey {
}
/// Convert PeerId to libp2p's PublicKey
fn as_public_key(peer_id: &PeerId) -> Option<libp2p_core::PublicKey> {
use libp2p_core::multihash;
fn as_public_key(peer_id: &PeerId) -> Option<libp2p_identity::PublicKey> {
let mhash = peer_id.as_ref();
match multihash::Code::try_from(mhash.code()) {
Ok(multihash::Code::Identity) => {
libp2p_core::PublicKey::from_protobuf_encoding(mhash.digest()).ok()
libp2p_identity::PublicKey::from_protobuf_encoding(mhash.digest()).ok()
}
_ => None,
}
@ -209,8 +207,8 @@ mod tests {
fn public_key_peer_id_conversions() {
let kp = KeyPair::generate_secp256k1();
let fluence_pk = kp.public();
let libp2p_pk: libp2p_core::PublicKey = fluence_pk.clone().into();
let peer_id = PeerId::from_public_key(libp2p_pk);
let libp2p_pk: libp2p_identity::PublicKey = fluence_pk.clone().into();
let peer_id = PeerId::from_public_key(&libp2p_pk);
let fluence_pk_converted = PublicKey::try_from(peer_id).unwrap();
assert_eq!(fluence_pk, fluence_pk_converted);

View File

@ -127,7 +127,7 @@ impl fmt::Debug for PublicKey {
let mut hex = String::with_capacity(bytes.len() * 2);
for byte in bytes {
write!(hex, "{:02x}", byte).expect("Can't fail on writing to string");
write!(hex, "{byte:02x}").expect("Can't fail on writing to string");
}
f.debug_struct("PublicKey").field("pkcs1", &hex).finish()
@ -234,7 +234,6 @@ pub struct Signature(pub Vec<u8>);
mod tests {
use super::*;
use quickcheck::*;
use rand::seq::SliceRandom;
use std::fmt;
const KEY1: &'static [u8] = include_bytes!("test/rsa-2048.pk8");
@ -251,8 +250,8 @@ mod tests {
}
impl Arbitrary for SomeKeypair {
fn arbitrary<G: Gen>(g: &mut G) -> SomeKeypair {
let mut key = [KEY1, KEY2, KEY3].choose(g).unwrap().to_vec();
fn arbitrary(g: &mut Gen) -> SomeKeypair {
let mut key = g.choose(&[KEY1, KEY2, KEY3]).unwrap().to_vec();
SomeKeypair(Keypair::from_pkcs8(&mut key).unwrap())
}
}

View File

@ -122,7 +122,7 @@ impl SecretKey {
// TODO: Stricter parsing.
let der_obj = der.as_mut();
let obj: Vec<DerObject> =
FromDerObject::deserialize((&*der_obj).iter()).map_err(|_| DecodingError::Secp256k1)?;
FromDerObject::deserialize((*der_obj).iter()).map_err(|_| DecodingError::Secp256k1)?;
der_obj.zeroize();
let sk_obj = obj.into_iter().nth(1).ok_or(DecodingError::Secp256k1)?;
let mut sk_bytes: Vec<u8> =

View File

@ -1,3 +1,4 @@
[toolchain]
channel = "nightly-2022-12-06"
targets = [ "x86_64-apple-darwin", "wasm32-wasi", "wasm32-unknown-unknown", "x86_64-unknown-linux-gnu" ]
components = [ "rustfmt", "clippy" ]

View File

@ -4,6 +4,59 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* The following workspace dependencies were updated
* dependencies
* trust-graph bumped from 0.4.1 to 0.4.2
* fluence-keypair bumped from 0.10.0 to 0.10.1
## [0.4.3](https://github.com/fluencelabs/trust-graph/compare/trust-graph-wasm-v0.4.2...trust-graph-wasm-v0.4.3) (2023-05-08)
### Miscellaneous Chores
* **trust-graph-wasm:** Synchronize trust-graph, wasm and api versions
### Dependencies
* The following workspace dependencies were updated
* dependencies
* trust-graph bumped from 0.4.2 to 0.4.3
## [0.4.1](https://github.com/fluencelabs/trust-graph/compare/trust-graph-wasm-v0.4.0...trust-graph-wasm-v0.4.1) (2023-04-13)
### Bug Fixes
* **deps:** Add trust-graph to workspace and bump sqlite-wasm version ([#87](https://github.com/fluencelabs/trust-graph/issues/87)) ([da38a41](https://github.com/fluencelabs/trust-graph/commit/da38a41ba727a14774a71bba6612b1bf1f498db9))
### Dependencies
* The following workspace dependencies were updated
* dependencies
* trust-graph bumped from 0.4.0 to 0.4.1
## [0.4.0](https://github.com/fluencelabs/trust-graph/compare/trust-graph-wasm-v0.3.2...trust-graph-wasm-v0.4.0) (2023-03-15)
### ⚠ BREAKING CHANGES
* **deps:** update libp2p to 0.39.1 and other deps ([#77](https://github.com/fluencelabs/trust-graph/issues/77))
### Features
* **deps:** update libp2p to 0.39.1 and other deps ([#77](https://github.com/fluencelabs/trust-graph/issues/77)) ([080503d](https://github.com/fluencelabs/trust-graph/commit/080503dcfa2ecf8d09167ff9fe7f750fadf49035))
* **keypair:** add KeyPair::from_secret_key ([#50](https://github.com/fluencelabs/trust-graph/issues/50)) ([a6ce8d9](https://github.com/fluencelabs/trust-graph/commit/a6ce8d9eee20e1ea24eb27c38ac6df6d878292ae))
### Dependencies
* The following workspace dependencies were updated
* dependencies
* trust-graph bumped from 0.3.0 to 0.4.0
* fluence-keypair bumped from 0.9.0 to 0.10.0
## [Unreleased]
## [0.3.1] - 2022-10-06

View File

@ -1,8 +1,8 @@
[package]
name = "trust-graph-wasm"
version = "0.3.1"
version = "0.4.3"
authors = ["Fluence Labs"]
edition = "2018"
edition = "2021"
description = "trust graph wasm"
license = "Apache-2.0"
publish = false
@ -12,28 +12,25 @@ name = "trust-graph"
path = "src/main.rs"
[dependencies]
trust-graph = { version = "0.3.0", path = "../." }
fluence-keypair = { version = "0.8.1", path = "../keypair" }
marine-rs-sdk = { version = "0.6.14", features = ["logger"] }
marine-sqlite-connector = "0.5.2"
trust-graph = { version = "0.4.3", path = "../trust-graph" }
fluence-keypair = { version = "0.10.1", path = "../keypair" }
marine-rs-sdk = { version = "0.7.1", features = ["logger"] }
marine-sqlite-connector = "0.8.0"
libp2p-core = { workspace = true }
libp2p-identity = { workspace = true }
log = "0.4.8"
anyhow = "1.0.31"
boolinator = "2.4.0"
once_cell = "1.4.1"
parking_lot = "0.11.1"
serde_json = "1.0"
bs58 = "0.3.1"
rmp-serde = "0.15.0"
bs58 = "0.4.0"
rmp-serde = "1.1.1"
bincode = "1.3.1"
serde_bencode = "^0.2.3"
thiserror = "1.0.23"
[dev-dependencies]
marine-rs-sdk-test = "0.4.0"
rusqlite = "0.26.1"
marine-rs-sdk-test = "0.9.1"
rusqlite = "0.28.0"
[build-dependencies]
marine-rs-sdk-test = "0.4.0"
marine-rs-sdk-test = "0.9.1"

View File

@ -5,12 +5,10 @@ modules_dir = "artifacts/"
logger_enabled = true
[module.wasi]
preopened_files = ["/tmp"]
mapped_dirs = { "tmp" = "/tmp" }
mapped_dirs = { "/tmp" = "data" }
[[module]]
name = "trust-graph"
logger_enabled = true
[module.wasi]
preopened_files = ["/tmp"]
mapped_dirs = { "tmp" = "/tmp" }
mapped_dirs = { "/tmp" = "data" }

View File

@ -13,7 +13,7 @@ mkdir -p artifacts
cp ../target/wasm32-wasi/release/trust-graph.wasm artifacts/
# download SQLite 3 to use in tests
curl -L https://github.com/fluencelabs/sqlite/releases/download/v0.15.0_w/sqlite3.wasm -o artifacts/sqlite3.wasm
curl -sS -L https://github.com/fluencelabs/sqlite/releases/download/sqlite-wasm-v0.18.1/sqlite3.wasm -o artifacts/sqlite3.wasm
# # generate Aqua bindings
# marine aqua artifacts/trust-graph.wasm -s TrustGraph -i trust-graph > ../aqua/trust-graph.aqua
# generate Aqua bindings
marine aqua artifacts/trust-graph.wasm -s TrustGraph -i trust-graph > ../aqua/trust-graph.aqua

View File

@ -1,7 +1,7 @@
use crate::dto::DtoConversionError::PeerIdDecodeError;
use fluence_keypair::error::DecodingError;
use fluence_keypair::{KeyFormat, PublicKey, Signature};
use libp2p_core::PeerId;
use libp2p_identity::PeerId;
use marine_rs_sdk::marine;
use std::convert::TryFrom;
use std::str::FromStr;
@ -78,7 +78,7 @@ impl TryFrom<Trust> for trust_graph::Trust {
fn try_from(t: Trust) -> Result<Self, Self::Error> {
let issued_for = PublicKey::try_from(
PeerId::from_str(&t.issued_for).map_err(|e| PeerIdDecodeError(format!("{:?}", e)))?,
PeerId::from_str(&t.issued_for).map_err(|e| PeerIdDecodeError(format!("{e:?}")))?,
)
.map_err(|e| DtoConversionError::PeerIdDecodeError(e.to_string()))?;
let signature = bs58::decode(&t.signature).into_vec()?;
@ -132,11 +132,11 @@ impl TryFrom<Revocation> for trust_graph::Revocation {
fn try_from(r: Revocation) -> Result<Self, Self::Error> {
let revoked_pk = PublicKey::try_from(
PeerId::from_str(&r.revoked_peer_id)
.map_err(|e| PeerIdDecodeError(format!("{:?}", e)))?,
.map_err(|e| PeerIdDecodeError(format!("{e:?}")))?,
)
.map_err(|e| DtoConversionError::PeerIdDecodeError(e.to_string()))?;
let revoked_by_pk = PublicKey::try_from(
PeerId::from_str(&r.revoked_by).map_err(|e| PeerIdDecodeError(format!("{:?}", e)))?,
PeerId::from_str(&r.revoked_by).map_err(|e| PeerIdDecodeError(format!("{e:?}")))?,
)
.map_err(|e| DtoConversionError::PeerIdDecodeError(e.to_string()))?;
let signature = bs58::decode(&r.signature).into_vec()?;

View File

@ -13,31 +13,10 @@ mod results;
mod service_api;
mod storage_impl;
mod tests;
/*
_initialize function that calls __wasm_call_ctors is required to mitigade memory leak
that is described in https://github.com/WebAssembly/wasi-libc/issues/298
In short, without this code rust wraps every export function
with __wasm_call_ctors/__wasm_call_dtors calls. This causes memory leaks. When compiler sees
an explicit call to __wasm_call_ctors in _initialize function, it disables export wrapping.
TODO: remove when updating to marine-rs-sdk with fix
*/
extern "C" {
pub fn __wasm_call_ctors();
}
#[no_mangle]
fn _initialize() {
unsafe {
__wasm_call_ctors();
}
}
//------------------------------
pub static TRUSTED_TIMESTAMP: (&str, &str) = ("peer", "timestamp_sec");
pub fn main() {
_initialize(); // As __wasm_call_ctors still does necessary work, we call it at the start of the module
WasmLoggerBuilder::new()
.with_log_level(log::LevelFilter::Trace)
.build()

View File

@ -18,7 +18,7 @@ use crate::error::ServiceError::*;
use crate::storage_impl::{SQLiteStorage, DB_PATH};
use crate::TRUSTED_TIMESTAMP;
use fluence_keypair::PublicKey;
use libp2p_core::PeerId;
use libp2p_identity::PeerId;
use marine_rs_sdk::CallParameters;
use std::cell::RefCell;
use std::convert::TryFrom;
@ -27,6 +27,7 @@ use std::str::FromStr;
use trust_graph::TrustGraph;
/// Check timestamps are generated on the current host with builtin ("peer" "timestamp_sec")
#[allow(clippy::unnecessary_lazy_evaluations)]
pub(crate) fn check_timestamp_tetraplets(
call_parameters: &CallParameters,
arg_number: usize,
@ -41,12 +42,12 @@ pub(crate) fn check_timestamp_tetraplets(
(TRUSTED_TIMESTAMP.eq(&(&tetraplet.service_id, &tetraplet.function_name))
&& tetraplet.peer_pk == call_parameters.host_id)
.then(|| ())
.ok_or_else(|| InvalidTimestampTetraplet(format!("{:?}", tetraplet)))
.ok_or_else(|| InvalidTimestampTetraplet(format!("{tetraplet:?}")))
}
fn parse_peer_id(peer_id: String) -> Result<PeerId, ServiceError> {
libp2p_core::PeerId::from_str(&peer_id)
.map_err(|e| ServiceError::PeerIdParseError(format!("{:?}", e)))
libp2p_identity::PeerId::from_str(&peer_id)
.map_err(|e| ServiceError::PeerIdParseError(format!("{e:?}")))
}
thread_local!(static INSTANCE: RefCell<TrustGraph<SQLiteStorage>> = RefCell::new(TrustGraph::new(

View File

@ -17,7 +17,7 @@ impl From<Result<(), ServiceError>> for InsertResult {
},
Err(e) => InsertResult {
success: false,
error: format!("{}", e),
error: format!("{e}"),
},
}
}
@ -44,7 +44,7 @@ impl From<Result<(u32, String), ServiceError>> for WeightResult {
success: false,
weight: 0u32,
peer_id: "".to_string(),
error: format!("{}", e),
error: format!("{e}"),
},
}
}
@ -68,7 +68,7 @@ impl From<Result<Vec<Certificate>, ServiceError>> for AllCertsResult {
Err(e) => AllCertsResult {
success: false,
certificates: vec![],
error: format!("{}", e),
error: format!("{e}"),
},
}
}
@ -89,7 +89,7 @@ impl From<Result<(), ServiceError>> for SetRootResult {
},
Err(e) => SetRootResult {
success: false,
error: format!("{}", e),
error: format!("{e}"),
},
}
}
@ -112,7 +112,7 @@ impl From<Result<Vec<u8>, ServiceError>> for GetTrustBytesResult {
},
Err(e) => GetTrustBytesResult {
success: false,
error: format!("{}", e),
error: format!("{e}"),
result: vec![],
},
}
@ -136,7 +136,7 @@ impl From<Result<Trust, ServiceError>> for IssueTrustResult {
},
Err(e) => IssueTrustResult {
success: false,
error: format!("{}", e),
error: format!("{e}"),
trust: Trust::default(),
},
}
@ -158,7 +158,7 @@ impl From<Result<(), ServiceError>> for VerifyTrustResult {
},
Err(e) => VerifyTrustResult {
success: false,
error: format!("{}", e),
error: format!("{e}"),
},
}
}
@ -181,7 +181,7 @@ impl From<Result<u32, ServiceError>> for AddTrustResult {
},
Err(e) => AddTrustResult {
success: false,
error: format!("{}", e),
error: format!("{e}"),
weight: u32::default(),
},
}
@ -205,7 +205,7 @@ impl From<Result<Vec<u8>, ServiceError>> for GetRevokeBytesResult {
},
Err(e) => GetRevokeBytesResult {
success: false,
error: format!("{}", e),
error: format!("{e}"),
result: vec![],
},
}
@ -229,7 +229,7 @@ impl From<Result<Revocation, ServiceError>> for IssueRevocationResult {
},
Err(e) => IssueRevocationResult {
success: false,
error: format!("{}", e),
error: format!("{e}"),
revocation: Revocation::default(),
},
}
@ -251,7 +251,7 @@ impl From<Result<(), ServiceError>> for RevokeResult {
},
Err(e) => RevokeResult {
success: false,
error: format!("{}", e),
error: format!("{e}"),
},
}
}
@ -275,7 +275,7 @@ impl From<Result<Vec<Revocation>, ServiceError>> for ExportRevocationsResult {
Err(e) => ExportRevocationsResult {
success: false,
revocations: vec![],
error: format!("{}", e),
error: format!("{e}"),
},
}
}

View File

@ -100,7 +100,7 @@ impl SQLiteStorage {
.cursor();
cursor.bind(&[
Value::String(format!("{}", issued_for)),
Value::String(format!("{issued_for}")),
Value::Integer(relation_type),
])?;
let mut relations: Vec<TrustRelation> = vec![];
@ -206,8 +206,8 @@ impl Storage for SQLiteStorage {
.cursor();
cursor.bind(&[
Value::String(format!("{}", issued_by)),
Value::String(format!("{}", issued_for)),
Value::String(format!("{issued_by}")),
Value::String(format!("{issued_for}")),
])?;
if let Some(row) = cursor.next()? {
@ -281,7 +281,7 @@ impl Storage for SQLiteStorage {
.prepare("SELECT public_key, weight_factor FROM roots WHERE public_key = ?")?
.cursor();
cursor.bind(&[Value::String(format!("{}", pk))])?;
cursor.bind(&[Value::String(format!("{pk}"))])?;
if let Some(row) = cursor.next()? {
let w = u32::try_from(row[1].as_integer().ok_or(WeightFactorConversionDB)?)
@ -304,7 +304,7 @@ impl Storage for SQLiteStorage {
.cursor();
cursor.bind(&[
Value::String(format!("{}", pk)),
Value::String(format!("{pk}")),
Value::Integer(i64::from(weight_factor)),
])?;

View File

@ -18,18 +18,18 @@
mod service_tests {
marine_rs_sdk_test::include_test_env!("/marine_test_env.rs");
use crate::error::ServiceError;
use crate::storage_impl::DB_PATH;
use crate::TRUSTED_TIMESTAMP;
use fluence_keypair::KeyPair;
use libp2p_core::PeerId;
use libp2p_identity::PeerId;
use marine_rs_sdk::{CallParameters, SecurityTetraplet};
use marine_test_env::trust_graph::{Certificate, Revocation, ServiceInterface, Trust};
use rusqlite::Connection;
use std::collections::HashMap;
use std::time::{SystemTime, UNIX_EPOCH};
static HOST_ID: &str = "some_host_id";
static TEST_DB_PATH: &str = "data/trust-graph.sqlite";
struct Auth {
issuer: PeerId,
trust: Trust,
@ -55,12 +55,7 @@ mod service_tests {
}
fn clear_env() {
let connection = Connection::open(DB_PATH).unwrap();
connection
.execute("DELETE FROM trust_relations", [])
.unwrap();
connection.execute("DELETE FROM roots", []).unwrap();
std::fs::remove_file(TEST_DB_PATH).unwrap_or_default();
}
fn get_correct_timestamp_cp(arg_number: usize) -> CallParameters {
@ -445,32 +440,32 @@ mod service_tests {
let mut trust_graph = marine_test_env::trust_graph::ServiceInterface::new();
clear_env();
let peerA_kp = KeyPair::generate_ed25519();
let peer_a_kp = KeyPair::generate_ed25519();
let mut cur_time = 100u64;
add_root_with_trust(&mut trust_graph, &peerA_kp, cur_time, cur_time + 9999, 10);
add_root_with_trust(&mut trust_graph, &peer_a_kp, cur_time, cur_time + 9999, 10);
let peerB_kp = KeyPair::generate_ed25519();
let peer_b_kp = KeyPair::generate_ed25519();
add_trust(
&mut trust_graph,
&peerA_kp,
&peerB_kp.get_peer_id(),
&peer_a_kp,
&peer_b_kp.get_peer_id(),
cur_time,
cur_time + 99999,
);
let weight = get_weight(&mut trust_graph, peerB_kp.get_peer_id(), cur_time);
let weight = get_weight(&mut trust_graph, peer_b_kp.get_peer_id(), cur_time);
assert_ne!(weight, 0u32);
cur_time += 1;
// A revokes B and cancels trust
revoke(
&mut trust_graph,
&peerA_kp,
&peerB_kp.get_peer_id(),
&peer_a_kp,
&peer_b_kp.get_peer_id(),
cur_time,
);
let weight = get_weight(&mut trust_graph, peerB_kp.get_peer_id(), cur_time);
let weight = get_weight(&mut trust_graph, peer_b_kp.get_peer_id(), cur_time);
assert_eq!(weight, 0u32);
}

43
trust-graph/CHANGELOG.md Normal file
View File

@ -0,0 +1,43 @@
# Changelog
* The following workspace dependencies were updated
* dependencies
* fluence-keypair bumped from 0.10.0 to 0.10.1
## [0.4.3](https://github.com/fluencelabs/trust-graph/compare/trust-graph-v0.4.2...trust-graph-v0.4.3) (2023-05-08)
### Features
* dummy change for release ([#95](https://github.com/fluencelabs/trust-graph/issues/95)) ([b6df3fe](https://github.com/fluencelabs/trust-graph/commit/b6df3fe5484b0adcad0c88abe170317a837142b3))
## [0.4.1](https://github.com/fluencelabs/trust-graph/compare/trust-graph-v0.4.0...trust-graph-v0.4.1) (2023-04-13)
### Miscellaneous Chores
* **trust-graph:** Synchronize trust-graph, wasm and api versions
## [0.4.0](https://github.com/fluencelabs/trust-graph/compare/trust-graph-v0.3.2...trust-graph-v0.4.0) (2023-03-15)
### ⚠ BREAKING CHANGES
* **deps:** update libp2p to 0.39.1 and other deps ([#77](https://github.com/fluencelabs/trust-graph/issues/77))
### Features
* **deps:** update libp2p to 0.39.1 and other deps ([#77](https://github.com/fluencelabs/trust-graph/issues/77)) ([080503d](https://github.com/fluencelabs/trust-graph/commit/080503dcfa2ecf8d09167ff9fe7f750fadf49035))
* **keypair:** add KeyPair::from_secret_key ([#50](https://github.com/fluencelabs/trust-graph/issues/50)) ([a6ce8d9](https://github.com/fluencelabs/trust-graph/commit/a6ce8d9eee20e1ea24eb27c38ac6df6d878292ae))
### Bug Fixes
* **deps:** Update libp2p-core to 0.38 ([#51](https://github.com/fluencelabs/trust-graph/issues/51)) ([015422e](https://github.com/fluencelabs/trust-graph/commit/015422efcce41530a6cd84a25091598bc459d2e6))
### Dependencies
* The following workspace dependencies were updated
* dependencies
* fluence-keypair bumped from 0.9.0 to 0.10.0

22
trust-graph/Cargo.toml Normal file
View File

@ -0,0 +1,22 @@
[package]
name = "trust-graph"
version = "0.4.3"
authors = ["Fluence Labs"]
edition = "2021"
description = "trust graph"
license = "Apache-2.0"
repository = "https://github.com/fluencelabs/trust-graph"
[dependencies]
serde = { version = "1.0.118", features = ["derive"] }
fluence-keypair = { path = "../keypair", version = "0.10.1" }
bs58 = "0.4.0"
failure = "0.1.6"
log = "0.4.11"
ref-cast = "1.0.2"
derivative = "2.1.1"
thiserror = "1.0.23"
sha2 = "0.10.6"
nonempty = "0.8.1"
rand = "0.8.5"

View File

@ -160,8 +160,8 @@ impl Certificate {
) -> Result<Self, CertificateError> {
if expires_at.lt(&issued_at) {
return Err(ExpirationError {
expires_at: format!("{:?}", expires_at),
issued_at: format!("{:?}", issued_at),
expires_at: format!("{expires_at:?}"),
issued_at: format!("{issued_at:?}"),
});
}

View File

@ -35,7 +35,7 @@ mod single {
{
let str = String::deserialize(deserializer)?;
Certificate::from_str(&str)
.map_err(|e| Error::custom(format!("certificate deserialization failed for {:?}", e)))
.map_err(|e| Error::custom(format!("certificate deserialization failed for {e:?}")))
}
}
@ -63,7 +63,7 @@ pub mod vec {
v.into_iter()
.map(|e| {
Certificate::from_str(&e).map_err(|e| {
Error::custom(format!("certificate deserialization failed for {:?}", e))
Error::custom(format!("certificate deserialization failed for {e:?}"))
})
})
.collect()

View File

@ -5,6 +5,6 @@ pub fn current_time() -> Duration {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs() as u64,
.as_secs(),
)
}

View File

@ -120,10 +120,10 @@ impl<'de> serde::Deserialize<'de> for PublicKeyHashable {
{
bs58::decode(s)
.into_vec()
.map_err(|err| Error::custom(format!("Invalid string '{}': {}", s, err)))
.map_err(|err| Error::custom(format!("Invalid string '{s}': {err}")))
.and_then(|v| self.visit_bytes(v.as_slice()))
.map_err(|err: E| {
Error::custom(format!("Parsed string '{}' as base58, but {}", s, err))
Error::custom(format!("Parsed string '{s}' as base58, but {err}"))
})
}
@ -132,7 +132,7 @@ impl<'de> serde::Deserialize<'de> for PublicKeyHashable {
E: Error,
{
let pk = PublicKey::decode(b)
.map_err(|err| Error::custom(format!("Invalid bytes {:?}: {}", b, err)))?;
.map_err(|err| Error::custom(format!("Invalid bytes {b:?}: {err}")))?;
Ok(PublicKeyHashable::from(pk))
}
}

View File

@ -75,7 +75,7 @@ impl Revocation {
let pk_bytes = &pk.encode();
metadata.push(pk_bytes.len() as u8);
metadata.extend(pk_bytes);
metadata.extend_from_slice(&(revoked_at.as_secs() as u64).to_le_bytes());
metadata.extend_from_slice(&revoked_at.as_secs().to_le_bytes());
sha2::Sha256::digest(&metadata).to_vec()
}

View File

@ -144,8 +144,8 @@ impl Trust {
pub fn signature_bytes(pk: &PublicKey, expires_at: Duration, issued_at: Duration) -> Vec<u8> {
let pk_encoded = pk.encode();
let expires_at_encoded: [u8; EXPIRATION_LEN] = (expires_at.as_secs() as u64).to_le_bytes();
let issued_at_encoded: [u8; ISSUED_LEN] = (issued_at.as_secs() as u64).to_le_bytes();
let expires_at_encoded: [u8; EXPIRATION_LEN] = expires_at.as_secs().to_le_bytes();
let issued_at_encoded: [u8; ISSUED_LEN] = issued_at.as_secs().to_le_bytes();
let mut metadata = Vec::new();
metadata.extend(pk_encoded);
@ -165,8 +165,8 @@ impl Trust {
vec.append(&mut issued_for);
vec.push(signature.len() as u8);
vec.append(&mut signature);
vec.extend_from_slice(&(self.expires_at.as_secs() as u64).to_le_bytes());
vec.extend_from_slice(&(self.issued_at.as_secs() as u64).to_le_bytes());
vec.extend_from_slice(&self.expires_at.as_secs().to_le_bytes());
vec.extend_from_slice(&self.issued_at.as_secs().to_le_bytes());
vec
}
@ -260,13 +260,10 @@ impl ToString for Trust {
fn to_string(&self) -> String {
let issued_for = bs58::encode(self.issued_for.encode()).into_string();
let signature = bs58::encode(self.signature.encode()).into_string();
let expires_at = (self.expires_at.as_secs() as u64).to_string();
let issued_at = (self.issued_at.as_secs() as u64).to_string();
let expires_at = self.expires_at.as_secs().to_string();
let issued_at = self.issued_at.as_secs().to_string();
format!(
"{}\n{}\n{}\n{}",
issued_for, signature, expires_at, issued_at
)
format!("{issued_for}\n{signature}\n{expires_at}\n{issued_at}")
}
}

View File

@ -90,7 +90,7 @@ impl<T: StorageError + 'static> From<T> for TrustGraphError {
impl From<TrustGraphError> for String {
fn from(err: TrustGraphError) -> Self {
format!("{}", err)
format!("{err}")
}
}
@ -374,8 +374,7 @@ where
// Certificate with one trust means nothing, gotta be a bug. Checking for it here.
debug_assert!(
c.chain.len() > 1,
"certificate with chain of len 1 arose: {:#?}",
c
"certificate with chain of len 1 arose: {c:#?}",
);
c.chain.len() > 1
})