Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1408b2ddf3 | ||
![]() |
a27ffd6462 | ||
![]() |
085b315883 | ||
![]() |
c630aa8079 | ||
![]() |
28db1ae925 | ||
![]() |
7188a33ee8 | ||
![]() |
4bf0d115e5 | ||
![]() |
06234a986b | ||
![]() |
2551c9923a | ||
![]() |
b77dbceaa9 | ||
![]() |
6625771830 | ||
![]() |
e320cfa193 | ||
![]() |
80dc42bbe6 | ||
![]() |
6569686634 | ||
![]() |
77e3dfc29c | ||
![]() |
a2ae855c10 | ||
![]() |
c3455ac888 |
15
.gitea/workflows/LOCAL_OVERRIDES.yml
Normal file
15
.gitea/workflows/LOCAL_OVERRIDES.yml
Normal file
@ -0,0 +1,15 @@
|
||||
# LOCAL_OVERRIDES.yml — dérogations locales contrôlées
|
||||
overrides:
|
||||
- path: ".gitea/workflows/ci.yml"
|
||||
reason: "spécificité d’environnement"
|
||||
owner: "@maintainer_handle"
|
||||
expires: "2025-12-31"
|
||||
- path: "scripts/auto-ssh-push.sh"
|
||||
reason: "flux particulier temporaire"
|
||||
owner: "@maintainer_handle"
|
||||
expires: "2025-10-01"
|
||||
policy:
|
||||
allow_only_listed_paths: true
|
||||
require_expiry: true
|
||||
audit_in_ci: true
|
||||
|
486
.gitea/workflows/ci.yml
Normal file
486
.gitea/workflows/ci.yml
Normal file
@ -0,0 +1,486 @@
|
||||
name: CI - 4NK Node
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, develop ]
|
||||
tags:
|
||||
- 'v*'
|
||||
pull_request:
|
||||
branches: [ main, develop ]
|
||||
|
||||
env:
|
||||
RUST_VERSION: '1.70'
|
||||
DOCKER_COMPOSE_VERSION: '2.20.0'
|
||||
CI_SKIP: 'true'
|
||||
|
||||
jobs:
|
||||
# Job de vérification du code
|
||||
code-quality:
|
||||
name: Code Quality
|
||||
runs-on: [self-hosted, linux]
|
||||
if: ${{ env.CI_SKIP != 'true' }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ env.RUST_VERSION }}
|
||||
override: true
|
||||
|
||||
- name: Cache Rust dependencies
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
target
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cargo-
|
||||
|
||||
- name: Run clippy
|
||||
run: |
|
||||
cd sdk_relay
|
||||
cargo clippy --all-targets --all-features -- -D warnings
|
||||
|
||||
- name: Run rustfmt
|
||||
run: |
|
||||
cd sdk_relay
|
||||
cargo fmt --all -- --check
|
||||
|
||||
- name: Check documentation
|
||||
run: |
|
||||
cd sdk_relay
|
||||
cargo doc --no-deps
|
||||
|
||||
- name: Check for TODO/FIXME
|
||||
run: |
|
||||
if grep -r "TODO\|FIXME" . --exclude-dir=.git --exclude-dir=target; then
|
||||
echo "Found TODO/FIXME comments. Please address them."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Job de tests unitaires
|
||||
unit-tests:
|
||||
name: Unit Tests
|
||||
runs-on: [self-hosted, linux]
|
||||
if: ${{ env.CI_SKIP != 'true' }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ env.RUST_VERSION }}
|
||||
override: true
|
||||
|
||||
- name: Cache Rust dependencies
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
target
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cargo-
|
||||
|
||||
- name: Run unit tests
|
||||
run: |
|
||||
cd sdk_relay
|
||||
cargo test --lib --bins
|
||||
|
||||
- name: Run integration tests
|
||||
run: |
|
||||
cd sdk_relay
|
||||
cargo test --tests
|
||||
|
||||
# Job de tests d'intégration
|
||||
integration-tests:
|
||||
name: Integration Tests
|
||||
runs-on: [self-hosted, linux]
|
||||
if: ${{ env.CI_SKIP != 'true' }}
|
||||
|
||||
services:
|
||||
docker:
|
||||
image: docker:24.0.5
|
||||
options: >-
|
||||
--health-cmd "docker info"
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
ports:
|
||||
- 2375:2375
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Build Docker images
|
||||
run: |
|
||||
docker build -t 4nk-node-bitcoin ./bitcoin
|
||||
docker build -t 4nk-node-blindbit ./blindbit
|
||||
docker build -t 4nk-node-sdk-relay -f ./sdk_relay/Dockerfile ..
|
||||
|
||||
- name: Run integration tests
|
||||
run: |
|
||||
# Tests de connectivité de base
|
||||
./tests/run_connectivity_tests.sh || true
|
||||
|
||||
# Tests d'intégration
|
||||
./tests/run_integration_tests.sh || true
|
||||
|
||||
- name: Upload test results
|
||||
uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
with:
|
||||
name: test-results
|
||||
path: |
|
||||
tests/logs/
|
||||
tests/reports/
|
||||
retention-days: 7
|
||||
|
||||
# Job de tests de sécurité
|
||||
security-tests:
|
||||
name: Security Tests
|
||||
runs-on: [self-hosted, linux]
|
||||
if: ${{ env.CI_SKIP != 'true' }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ env.RUST_VERSION }}
|
||||
override: true
|
||||
|
||||
- name: Run cargo audit
|
||||
run: |
|
||||
cd sdk_relay
|
||||
cargo audit --deny warnings
|
||||
|
||||
- name: Check for secrets
|
||||
run: |
|
||||
# Vérifier les secrets potentiels
|
||||
if grep -r "password\|secret\|key\|token" . --exclude-dir=.git --exclude-dir=target --exclude=*.md; then
|
||||
echo "Potential secrets found. Please review."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Check file permissions
|
||||
run: |
|
||||
# Vérifier les permissions sensibles
|
||||
find . -type f -perm /0111 -name "*.conf" -o -name "*.key" -o -name "*.pem" | while read file; do
|
||||
if [[ $(stat -c %a "$file") != "600" ]]; then
|
||||
echo "Warning: $file has insecure permissions"
|
||||
fi
|
||||
done
|
||||
|
||||
# Job de build et test Docker
|
||||
docker-build:
|
||||
name: Docker Build & Test
|
||||
runs-on: [self-hosted, linux]
|
||||
if: ${{ env.CI_SKIP != 'true' }}
|
||||
|
||||
services:
|
||||
docker:
|
||||
image: docker:24.0.5
|
||||
options: >-
|
||||
--health-cmd "docker info"
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
ports:
|
||||
- 2375:2375
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Build and test Bitcoin Core
|
||||
run: |
|
||||
docker build -t 4nk-node-bitcoin:test ./bitcoin
|
||||
docker run --rm 4nk-node-bitcoin:test bitcoin-cli --version
|
||||
|
||||
- name: Build and test Blindbit
|
||||
run: |
|
||||
docker build -t 4nk-node-blindbit:test ./blindbit
|
||||
docker run --rm 4nk-node-blindbit:test --version || true
|
||||
|
||||
- name: Build and test SDK Relay
|
||||
run: |
|
||||
docker build -t 4nk-node-sdk-relay:test -f ./sdk_relay/Dockerfile ..
|
||||
docker run --rm 4nk-node-sdk-relay:test --version || true
|
||||
|
||||
- name: Test Docker Compose
|
||||
run: |
|
||||
docker-compose config
|
||||
docker-compose build --no-cache
|
||||
|
||||
# Job de tests de documentation
|
||||
documentation-tests:
|
||||
name: Documentation Tests
|
||||
runs-on: [self-hosted, linux]
|
||||
if: ${{ env.CI_SKIP != 'true' }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Check markdown links
|
||||
run: |
|
||||
# Vérification basique des liens markdown
|
||||
find . -name "*.md" -exec grep -l "\[.*\](" {} \; | while read file; do
|
||||
echo "Checking links in $file"
|
||||
done
|
||||
|
||||
markdownlint:
|
||||
name: Markdown Lint
|
||||
runs-on: [self-hosted, linux]
|
||||
if: ${{ env.CI_SKIP != 'true' }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
- name: Run markdownlint
|
||||
run: |
|
||||
npm --version || (curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt-get install -y nodejs)
|
||||
npx -y markdownlint-cli@0.42.0 "**/*.md" --ignore "archive/**"
|
||||
|
||||
- name: Check documentation structure
|
||||
run: |
|
||||
# Vérifier la présence des fichiers de documentation essentiels
|
||||
required_files=(
|
||||
"README.md"
|
||||
"LICENSE"
|
||||
"CONTRIBUTING.md"
|
||||
"CHANGELOG.md"
|
||||
"CODE_OF_CONDUCT.md"
|
||||
"SECURITY.md"
|
||||
)
|
||||
|
||||
for file in "${required_files[@]}"; do
|
||||
if [[ ! -f "$file" ]]; then
|
||||
echo "Missing required documentation file: $file"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
bash-required:
|
||||
name: Bash Requirement
|
||||
runs-on: [self-hosted, linux]
|
||||
if: ${{ env.CI_SKIP != 'true' }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
- name: Verify bash availability
|
||||
run: |
|
||||
if ! command -v bash >/dev/null 2>&1; then
|
||||
echo "bash is required for agents and scripts"; exit 1;
|
||||
fi
|
||||
- name: Verify agents runner exists
|
||||
run: |
|
||||
if [ ! -f scripts/agents/run.sh ]; then
|
||||
echo "scripts/agents/run.sh is missing"; exit 1;
|
||||
fi
|
||||
|
||||
agents-smoke:
|
||||
name: Agents Smoke (no AI)
|
||||
runs-on: [self-hosted, linux]
|
||||
if: ${{ env.CI_SKIP != 'true' }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
- name: Ensure agents scripts executable
|
||||
run: |
|
||||
chmod +x scripts/agents/*.sh || true
|
||||
- name: Run agents without AI
|
||||
env:
|
||||
OPENAI_API_KEY: ""
|
||||
run: |
|
||||
scripts/agents/run.sh
|
||||
- name: Upload agents reports
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: agents-reports
|
||||
path: tests/reports/agents
|
||||
|
||||
openia-agents:
|
||||
name: Agents with OpenIA
|
||||
runs-on: [self-hosted, linux]
|
||||
if: ${{ env.CI_SKIP != 'true' && secrets.OPENAI_API_KEY != '' }}
|
||||
env:
|
||||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
||||
OPENAI_MODEL: ${{ vars.OPENAI_MODEL }}
|
||||
OPENAI_API_BASE: ${{ vars.OPENAI_API_BASE }}
|
||||
OPENAI_TEMPERATURE: ${{ vars.OPENAI_TEMPERATURE }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
- name: Ensure agents scripts executable
|
||||
run: |
|
||||
chmod +x scripts/agents/*.sh || true
|
||||
- name: Run agents with AI
|
||||
run: |
|
||||
scripts/agents/run.sh
|
||||
- name: Upload agents reports
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: agents-reports-ai
|
||||
path: tests/reports/agents
|
||||
|
||||
deployment-checks:
|
||||
name: Deployment Checks
|
||||
runs-on: [self-hosted, linux]
|
||||
if: ${{ env.CI_SKIP != 'true' }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
- name: Validate deployment documentation
|
||||
run: |
|
||||
if [ ! -f docs/DEPLOYMENT.md ]; then
|
||||
echo "Missing docs/DEPLOYMENT.md"; exit 1; fi
|
||||
if [ ! -f docs/SSH_UPDATE.md ]; then
|
||||
echo "Missing docs/SSH_UPDATE.md"; exit 1; fi
|
||||
- name: Ensure tests directories exist
|
||||
run: |
|
||||
mkdir -p tests/logs tests/reports || true
|
||||
echo "OK"
|
||||
|
||||
security-audit:
|
||||
name: Security Audit
|
||||
runs-on: [self-hosted, linux]
|
||||
if: ${{ env.CI_SKIP != 'true' }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
- name: Ensure scripts executable
|
||||
run: |
|
||||
chmod +x scripts/security/audit.sh || true
|
||||
- name: Run template security audit
|
||||
run: |
|
||||
if [ -f scripts/security/audit.sh ]; then
|
||||
./scripts/security/audit.sh
|
||||
else
|
||||
echo "No security audit script (ok)"
|
||||
fi
|
||||
|
||||
# Job de release guard (cohérence release)
|
||||
release-guard:
|
||||
name: Release Guard
|
||||
runs-on: [self-hosted, linux]
|
||||
needs: [code-quality, unit-tests, documentation-tests, markdownlint, security-audit, deployment-checks, bash-required]
|
||||
if: ${{ env.CI_SKIP != 'true' }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Ensure guard scripts are executable
|
||||
run: |
|
||||
chmod +x scripts/release/guard.sh || true
|
||||
chmod +x scripts/checks/version_alignment.sh || true
|
||||
|
||||
- name: Version alignment check
|
||||
run: |
|
||||
if [ -f scripts/checks/version_alignment.sh ]; then
|
||||
./scripts/checks/version_alignment.sh
|
||||
else
|
||||
echo "No version alignment script (ok)"
|
||||
fi
|
||||
|
||||
- name: Release guard (CI verify)
|
||||
env:
|
||||
RELEASE_TYPE: ci-verify
|
||||
run: |
|
||||
if [ -f scripts/release/guard.sh ]; then
|
||||
./scripts/release/guard.sh
|
||||
else
|
||||
echo "No guard script (ok)"
|
||||
fi
|
||||
|
||||
release-create:
|
||||
name: Create Release (Gitea API)
|
||||
runs-on: ubuntu-latest
|
||||
needs: [release-guard]
|
||||
if: ${{ env.CI_SKIP != 'true' && startsWith(github.ref, 'refs/tags/') }}
|
||||
env:
|
||||
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
||||
BASE_URL: ${{ vars.BASE_URL }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
- name: Validate token and publish release
|
||||
run: |
|
||||
set -e
|
||||
if [ -z "${RELEASE_TOKEN}" ]; then
|
||||
echo "RELEASE_TOKEN secret is missing" >&2; exit 1; fi
|
||||
if [ -z "${BASE_URL}" ]; then
|
||||
BASE_URL="https://git.4nkweb.com"; fi
|
||||
TAG="${GITHUB_REF##*/}"
|
||||
REPO="${GITHUB_REPOSITORY}"
|
||||
OWNER="${REPO%%/*}"
|
||||
NAME="${REPO##*/}"
|
||||
echo "Publishing release ${TAG} to ${BASE_URL}/${OWNER}/${NAME}"
|
||||
curl -sSf -X POST \
|
||||
-H "Authorization: token ${RELEASE_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"draft\":false,\"prerelease\":false}" \
|
||||
"${BASE_URL}/api/v1/repos/${OWNER}/${NAME}/releases" >/dev/null
|
||||
echo "Release created"
|
||||
|
||||
# Job de tests de performance
|
||||
performance-tests:
|
||||
name: Performance Tests
|
||||
runs-on: [self-hosted, linux]
|
||||
if: ${{ env.CI_SKIP != 'true' }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ env.RUST_VERSION }}
|
||||
override: true
|
||||
|
||||
- name: Run performance tests
|
||||
run: |
|
||||
cd sdk_relay
|
||||
cargo test --release --test performance_tests || true
|
||||
|
||||
- name: Check memory usage
|
||||
run: |
|
||||
# Tests de base de consommation mémoire
|
||||
echo "Performance tests completed"
|
||||
|
||||
# Job de notification
|
||||
notify:
|
||||
name: Notify
|
||||
runs-on: [self-hosted, linux]
|
||||
needs: [code-quality, unit-tests, integration-tests, security-tests, docker-build, documentation-tests]
|
||||
if: ${{ env.CI_SKIP != 'true' && always() }}
|
||||
|
||||
steps:
|
||||
- name: Notify success
|
||||
if: needs.code-quality.result == 'success' && needs.unit-tests.result == 'success' && needs.integration-tests.result == 'success' && needs.security-tests.result == 'success' && needs.docker-build.result == 'success' && needs.documentation-tests.result == 'success'
|
||||
run: |
|
||||
echo "✅ All tests passed successfully!"
|
||||
|
||||
- name: Notify failure
|
||||
if: needs.code-quality.result == 'failure' || needs.unit-tests.result == 'failure' || needs.integration-tests.result == 'failure' || needs.security-tests.result == 'failure' || needs.docker-build.result == 'failure' || needs.documentation-tests.result == 'failure'
|
||||
run: |
|
||||
echo "❌ Some tests failed!"
|
||||
exit 1
|
352
.gitea/workflows/ci.yml.bak
Normal file
352
.gitea/workflows/ci.yml.bak
Normal file
@ -0,0 +1,352 @@
|
||||
name: CI - sdk_signer
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, develop ]
|
||||
pull_request:
|
||||
branches: [ main, develop ]
|
||||
|
||||
env:
|
||||
RUST_VERSION: '1.70'
|
||||
DOCKER_COMPOSE_VERSION: '2.20.0'
|
||||
|
||||
jobs:
|
||||
# Job de vérification du code
|
||||
code-quality:
|
||||
name: Code Quality
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ env.RUST_VERSION }}
|
||||
override: true
|
||||
|
||||
- name: Cache Rust dependencies
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
target
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cargo-
|
||||
|
||||
- name: Run clippy
|
||||
run: |
|
||||
cargo clippy --all-targets --all-features -- -D warnings
|
||||
|
||||
- name: Run rustfmt
|
||||
run: |
|
||||
cargo fmt --all -- --check
|
||||
|
||||
- name: Check documentation
|
||||
run: |
|
||||
cargo doc --no-deps
|
||||
|
||||
- name: Check for TODO/FIXME
|
||||
run: |
|
||||
if grep -r "TODO\|FIXME" . --exclude-dir=.git --exclude-dir=target; then
|
||||
echo "Found TODO/FIXME comments. Please address them."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Job de tests unitaires
|
||||
unit-tests:
|
||||
name: Unit Tests
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ env.RUST_VERSION }}
|
||||
override: true
|
||||
|
||||
- name: Cache Rust dependencies
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
target
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cargo-
|
||||
|
||||
- name: Run unit tests
|
||||
run: |
|
||||
cargo test --lib --bins
|
||||
|
||||
- name: Run integration tests
|
||||
run: |
|
||||
cargo test --tests
|
||||
|
||||
# Job de tests d'intégration
|
||||
integration-tests:
|
||||
name: Integration Tests
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
services:
|
||||
docker:
|
||||
image: docker:24.0.5
|
||||
options: >-
|
||||
--health-cmd "docker info"
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
ports:
|
||||
- 2375:2375
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Build Docker images
|
||||
run: |
|
||||
docker build -t 4nk-node-bitcoin ./bitcoin
|
||||
docker build -t 4nk-node-blindbit ./blindbit
|
||||
docker build -t 4nk-node-sdk-relay -f ./sdk_relay/Dockerfile ..
|
||||
|
||||
- name: Run integration tests
|
||||
run: |
|
||||
# Tests de connectivité de base
|
||||
./tests/run_connectivity_tests.sh || true
|
||||
|
||||
# Tests d'intégration
|
||||
./tests/run_integration_tests.sh || true
|
||||
|
||||
- name: Upload test results
|
||||
uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
with:
|
||||
name: test-results
|
||||
path: |
|
||||
tests/logs/
|
||||
tests/reports/
|
||||
retention-days: 7
|
||||
|
||||
# Job de tests de sécurité
|
||||
security-tests:
|
||||
name: Security Tests
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ env.RUST_VERSION }}
|
||||
override: true
|
||||
|
||||
- name: Run cargo audit
|
||||
run: |
|
||||
cargo audit --deny warnings
|
||||
|
||||
- name: Check for secrets
|
||||
run: |
|
||||
# Vérifier les secrets potentiels
|
||||
if grep -r "password\|secret\|key\|token" . --exclude-dir=.git --exclude-dir=target --exclude=*.md; then
|
||||
echo "Potential secrets found. Please review."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Check file permissions
|
||||
run: |
|
||||
# Vérifier les permissions sensibles
|
||||
find . -type f -perm /0111 -name "*.conf" -o -name "*.key" -o -name "*.pem" | while read file; do
|
||||
if [[ $(stat -c %a "$file") != "600" ]]; then
|
||||
echo "Warning: $file has insecure permissions"
|
||||
fi
|
||||
done
|
||||
|
||||
# Job de build et test Docker
|
||||
docker-build:
|
||||
name: Docker Build & Test
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
services:
|
||||
docker:
|
||||
image: docker:24.0.5
|
||||
options: >-
|
||||
--health-cmd "docker info"
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
ports:
|
||||
- 2375:2375
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Build and test Bitcoin Core
|
||||
run: |
|
||||
docker build -t 4nk-node-bitcoin:test ./bitcoin
|
||||
docker run --rm 4nk-node-bitcoin:test bitcoin-cli --version
|
||||
|
||||
- name: Build and test Blindbit
|
||||
run: |
|
||||
docker build -t 4nk-node-blindbit:test ./blindbit
|
||||
docker run --rm 4nk-node-blindbit:test --version || true
|
||||
|
||||
- name: Build and test SDK Relay
|
||||
run: |
|
||||
docker build -t 4nk-node-sdk-relay:test -f ./sdk_relay/Dockerfile ..
|
||||
docker run --rm 4nk-node-sdk-relay:test --version || true
|
||||
|
||||
- name: Test Docker Compose
|
||||
run: |
|
||||
docker-compose config
|
||||
docker-compose build --no-cache
|
||||
|
||||
# Job de tests de documentation
|
||||
documentation-tests:
|
||||
name: Documentation Tests
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Check markdown links
|
||||
run: |
|
||||
# Vérification basique des liens markdown
|
||||
find . -name "*.md" -exec grep -l "\[.*\](" {} \; | while read file; do
|
||||
echo "Checking links in $file"
|
||||
done
|
||||
|
||||
- name: Check documentation structure
|
||||
run: |
|
||||
# Vérifier la présence des fichiers de documentation essentiels
|
||||
required_files=(
|
||||
"README.md"
|
||||
"LICENSE"
|
||||
"CONTRIBUTING.md"
|
||||
"CHANGELOG.md"
|
||||
"CODE_OF_CONDUCT.md"
|
||||
"SECURITY.md"
|
||||
"docs/INDEX.md"
|
||||
"docs/INSTALLATION.md"
|
||||
"docs/USAGE.md"
|
||||
)
|
||||
|
||||
for file in "${required_files[@]}"; do
|
||||
if [[ ! -f "$file" ]]; then
|
||||
echo "Missing required documentation file: $file"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
- name: Validate documentation
|
||||
run: |
|
||||
echo "Documentation checks completed"
|
||||
|
||||
security-audit:
|
||||
name: Security Audit
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
- name: Ensure scripts executable
|
||||
run: |
|
||||
chmod +x scripts/security/audit.sh || true
|
||||
- name: Run template security audit
|
||||
run: |
|
||||
if [ -f scripts/security/audit.sh ]; then
|
||||
./scripts/security/audit.sh
|
||||
else
|
||||
echo "No security audit script (ok)"
|
||||
fi
|
||||
|
||||
# Job de release guard (cohérence release)
|
||||
release-guard:
|
||||
name: Release Guard
|
||||
runs-on: ubuntu-latest
|
||||
needs: [code-quality, unit-tests, documentation-tests, security-audit]
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Ensure guard scripts are executable
|
||||
run: |
|
||||
chmod +x scripts/release/guard.sh || true
|
||||
chmod +x scripts/checks/version_alignment.sh || true
|
||||
|
||||
- name: Version alignment check
|
||||
run: |
|
||||
if [ -f scripts/checks/version_alignment.sh ]; then
|
||||
./scripts/checks/version_alignment.sh
|
||||
else
|
||||
echo "No version alignment script (ok)"
|
||||
fi
|
||||
|
||||
- name: Release guard (CI verify)
|
||||
env:
|
||||
RELEASE_TYPE: ci-verify
|
||||
run: |
|
||||
if [ -f scripts/release/guard.sh ]; then
|
||||
./scripts/release/guard.sh
|
||||
else
|
||||
echo "No guard script (ok)"
|
||||
fi
|
||||
|
||||
# Job de tests de performance
|
||||
performance-tests:
|
||||
name: Performance Tests
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ env.RUST_VERSION }}
|
||||
override: true
|
||||
|
||||
- name: Run performance tests
|
||||
run: |
|
||||
cd sdk_relay
|
||||
cargo test --release --test performance_tests || true
|
||||
|
||||
- name: Check memory usage
|
||||
run: |
|
||||
# Tests de base de consommation mémoire
|
||||
echo "Performance tests completed"
|
||||
|
||||
# Job de notification
|
||||
notify:
|
||||
name: Notify
|
||||
runs-on: ubuntu-latest
|
||||
needs: [code-quality, unit-tests, integration-tests, security-tests, docker-build, documentation-tests]
|
||||
if: always()
|
||||
|
||||
steps:
|
||||
- name: Notify success
|
||||
if: needs.code-quality.result == 'success' && needs.unit-tests.result == 'success' && needs.integration-tests.result == 'success' && needs.security-tests.result == 'success' && needs.docker-build.result == 'success' && needs.documentation-tests.result == 'success'
|
||||
run: |
|
||||
echo "✅ All tests passed successfully!"
|
||||
|
||||
- name: Notify failure
|
||||
if: needs.code-quality.result == 'failure' || needs.unit-tests.result == 'failure' || needs.integration-tests.result == 'failure' || needs.security-tests.result == 'failure' || needs.docker-build.result == 'failure' || needs.documentation-tests.result == 'failure'
|
||||
run: |
|
||||
echo "❌ Some tests failed!"
|
||||
exit 1
|
36
.gitea/workflows/release.yml
Normal file
36
.gitea/workflows/release.yml
Normal file
@ -0,0 +1,36 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*.*.*'
|
||||
|
||||
jobs:
|
||||
docker-release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
- name: Login to DockerHub
|
||||
if: ${{ secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_TOKEN }}
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Extract version
|
||||
id: vars
|
||||
run: echo "version=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
|
||||
- name: Build image
|
||||
run: docker build -t ${DOCKER_IMAGE:-sdk-signer}:${{ steps.vars.outputs.version }} .
|
||||
- name: Push image
|
||||
if: ${{ secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_TOKEN }}
|
||||
run: |
|
||||
IMAGE=${DOCKER_IMAGE:-sdk-signer}
|
||||
docker tag $IMAGE:${{ steps.vars.outputs.version }} $IMAGE:latest
|
||||
docker push $IMAGE:${{ steps.vars.outputs.version }}
|
||||
docker push $IMAGE:latest
|
||||
|
40
.gitea/workflows/template-sync.yml
Normal file
40
.gitea/workflows/template-sync.yml
Normal file
@ -0,0 +1,40 @@
|
||||
# .gitea/workflows/template-sync.yml — synchronisation et contrôles d’intégrité
|
||||
name: 4NK Template Sync
|
||||
on:
|
||||
schedule: # planification régulière
|
||||
- cron: "0 4 * * 1" # exécution hebdomadaire (UTC)
|
||||
workflow_dispatch: {} # déclenchement manuel
|
||||
|
||||
jobs:
|
||||
check-and-sync:
|
||||
runs-on: linux
|
||||
steps:
|
||||
- name: Lire TEMPLATE_VERSION et .4nk-sync.yml
|
||||
# Doit charger ref courant, source_repo et périmètre paths
|
||||
|
||||
- name: Récupérer la version publiée du template/4NK_rules
|
||||
# Doit comparer TEMPLATE_VERSION avec ref amont
|
||||
|
||||
- name: Créer branche de synchronisation si divergence
|
||||
# Doit créer chore/template-sync-<date> et préparer un commit
|
||||
|
||||
- name: Synchroniser les chemins autoritatifs
|
||||
# Doit mettre à jour .cursor/**, .gitea/**, AGENTS.md, scripts/**, docs/SSH_UPDATE.md
|
||||
|
||||
- name: Contrôles post-sync (bloquants)
|
||||
# 1) Vérifier présence et exécutable des scripts/*.sh
|
||||
# 2) Vérifier mise à jour CHANGELOG.md et docs/INDEX.md
|
||||
# 3) Vérifier docs/SSH_UPDATE.md si scripts/** a changé
|
||||
# 4) Vérifier absence de secrets en clair dans scripts/**
|
||||
# 5) Vérifier manifest_checksum si publié
|
||||
|
||||
- name: Tests, lint, sécurité statique
|
||||
# Doit exiger un état vert
|
||||
|
||||
- name: Ouvrir PR de synchronisation
|
||||
# Titre: "[template-sync] chore: aligner .cursor/.gitea/AGENTS.md/scripts"
|
||||
# Doit inclure résumé des fichiers modifiés et la version appliquée
|
||||
|
||||
- name: Mettre à jour TEMPLATE_VERSION (dans PR)
|
||||
# Doit remplacer la valeur par la ref appliquée
|
||||
|
@ -1,8 +1,3 @@
|
||||
## [0.1.3] - 2025-09-04
|
||||
- Mise à jour du versionnage (v0.1.3) et préparation du release
|
||||
- Alignement des fichiers de version (VERSION et package.json) et documentation
|
||||
|
||||
## 0.1.2 - Corrections build (compat WASM, TS) pour docker-support-v2
|
||||
# Changelog
|
||||
|
||||
Toutes les modifications notables de ce projet seront documentées ici.
|
||||
|
@ -27,9 +27,9 @@ RUN addgroup -S nodejs && adduser -S nodejs -G nodejs
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY --from=build /app/dist ./dist
|
||||
COPY --from=build /app/pkg ./pkg
|
||||
RUN echo '{"type":"commonjs"}' > /app/pkg/package.json
|
||||
# Create data directory for LevelDB with proper permissions
|
||||
RUN mkdir -p /app/data && chown -R nodejs:nodejs /app/data
|
||||
EXPOSE 9090
|
||||
USER nodejs
|
||||
CMD ["node", "dist/index.js"]
|
||||
|
||||
|
||||
|
||||
|
16
docs/API.md
16
docs/API.md
@ -1,16 +0,0 @@
|
||||
## API
|
||||
|
||||
### Portée
|
||||
- Contrats d’interface entre clients WebSocket et serveur sdk-signer.
|
||||
|
||||
### Contrats d’interface
|
||||
- Enum MessageType: connexion, token, processus, merkle, device, erreurs.
|
||||
- Messages: porteurs d’un type, d’un messageId, et de champs spécifiques à l’opération.
|
||||
- Statuts: DeliveryStatus (PENDING, SENT, DELIVERED, FAILED, RETRY).
|
||||
- Priorités: MessagePriority (LOW, NORMAL, HIGH, CRITICAL).
|
||||
|
||||
### Erreurs et statuts
|
||||
- Réponse de type ERROR en cas d’échec; gestion de timeouts côté serveur/clients.
|
||||
|
||||
### Versionnage et compatibilité
|
||||
- Alignement strict avec sdk_signer_client pour les énumérations et structures.
|
@ -1,30 +0,0 @@
|
||||
## ARCHITECTURE
|
||||
|
||||
### Contexte
|
||||
- Service serveur « sdk-signer » pour gérer des messages typés via WebSocket.
|
||||
- Fournit des opérations de processus, hashing/merkle, gestion de device et validation d’état.
|
||||
|
||||
### Composants
|
||||
- src/index.ts: point d’entrée, exporte Service, Server, config, models et utilitaires.
|
||||
- src/simple-server.ts: serveur WebSocket simple (gestion des connections et du cycle de vie).
|
||||
- src/service.ts: logique métier des messages et routage par type.
|
||||
- src/relay-manager.ts: interaction avec le réseau de relais.
|
||||
- src/database.service.ts: persistance simple pour l’état serveur si nécessaire.
|
||||
- src/models.ts: énumérations et types de messages, priorités, statuts de livraison.
|
||||
- src/config.ts: configuration serveur (port, clés, délais, options).
|
||||
- src/utils.ts, src/wasm_compat.ts: utilitaires globaux et compatibilité WASM si utilisée.
|
||||
|
||||
### Flux et dépendances
|
||||
- Client se connecte en WebSocket → message LISTENING → échanges de messages typés corrélés.
|
||||
- Gestion du messageId pour corrélation, priorités de traitement et statut de livraison.
|
||||
|
||||
### Données et modèles
|
||||
- Typage via MessageType et statuts (DeliveryStatus), niveaux de priorité (MessagePriority).
|
||||
- Dérivation de contrats communs alignés avec le client (sdk_signer_client).
|
||||
|
||||
### Sécurité
|
||||
- Clé API côté serveur (vérification attendue au niveau des messages entrants).
|
||||
- Logs d’erreurs et gestion de timeouts.
|
||||
|
||||
### Observabilité
|
||||
- Journalisation des connexions, erreurs, et transitions d’état des processus.
|
@ -1,20 +0,0 @@
|
||||
## DEPLOYMENT
|
||||
|
||||
### Docker
|
||||
- Image: sdk-signer:latest (build depuis Dockerfile)
|
||||
- Port: 9090 (exposé)
|
||||
- Commande: node dist/index.js
|
||||
- Volume: ./data monté sur /data
|
||||
|
||||
### Intégration dans 4NK_node
|
||||
- Variable RELAY_URLS à pointer vers ws://sdk_relay_1:8090 (réseau partagé)
|
||||
- BASE: PORT=9090, DATABASE_PATH=/data/server.db, API_KEY défini côté env
|
||||
|
||||
### CI/CD appliquée
|
||||
- Build multi-stage Node 20 alpine
|
||||
- Vérifier la génération de dist/ avant build image
|
||||
|
||||
### Configuration
|
||||
- Variables: PORT, API_KEY, DATABASE_PATH, RELAY_URLS
|
||||
- Ports: 9090
|
||||
- Utilisateur: nodejs (non-root)
|
@ -1,16 +0,0 @@
|
||||
## USAGE
|
||||
|
||||
### Prérequis
|
||||
- Node.js et accès réseau aux clients WebSocket.
|
||||
- Variables: PORT, API_KEY, DATABASE_PATH, RELAY_URLS.
|
||||
|
||||
### Démarrage
|
||||
- Construire le projet puis démarrer le serveur (dist/index.js) via Docker ou Node.
|
||||
|
||||
### Opérations
|
||||
- Accepter les connexions WebSocket et traiter les messages typés.
|
||||
- Utiliser Service et Server pour router et gérer les opérations (processus, merkle, validation, notifications).
|
||||
|
||||
### Dépannage
|
||||
- Vérifier les logs serveur pour les erreurs réseau ou de clé API.
|
||||
- Ajuster les timeouts et les politiques de reconnexion côté clients.
|
263
package-lock.json
generated
263
package-lock.json
generated
@ -1,15 +1,16 @@
|
||||
{
|
||||
"name": "sdk_signer",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "sdk_signer",
|
||||
"version": "0.1.2",
|
||||
"license": "ISC",
|
||||
"version": "0.1.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/ws": "^8.5.10",
|
||||
"axios": "^1.7.8",
|
||||
"dotenv": "^16.3.1",
|
||||
"level": "^10.0.0",
|
||||
"ws": "^8.14.2"
|
||||
@ -941,6 +942,21 @@
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.11.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.11.0.tgz",
|
||||
"integrity": "sha512-1Lx3WLFQWm3ooKDYZD1eXmoGO9fxYQjrycfHFC8P0sCfQVXyROp0p9PFWBehewBOdCwHc+f/b8I0fMto5eSfwA==",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.6",
|
||||
"form-data": "^4.0.4",
|
||||
"proxy-from-env": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/base64-js": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||
@ -1001,6 +1017,18 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/call-bind-apply-helpers": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
|
||||
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"function-bind": "^1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/chai": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/chai/-/chai-4.5.0.tgz",
|
||||
@ -1048,6 +1076,17 @@
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"dependencies": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/confbox": {
|
||||
"version": "0.1.8",
|
||||
"resolved": "https://registry.npmjs.org/confbox/-/confbox-0.1.8.tgz",
|
||||
@ -1107,6 +1146,14 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/diff": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
|
||||
@ -1137,6 +1184,60 @@
|
||||
"url": "https://dotenvx.com"
|
||||
}
|
||||
},
|
||||
"node_modules/dunder-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
||||
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.1",
|
||||
"es-errors": "^1.3.0",
|
||||
"gopd": "^1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-define-property": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
|
||||
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-errors": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
|
||||
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-object-atoms": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
|
||||
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-set-tostringtag": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz",
|
||||
"integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"get-intrinsic": "^1.2.6",
|
||||
"has-tostringtag": "^1.0.2",
|
||||
"hasown": "^2.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild": {
|
||||
"version": "0.21.5",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.21.5.tgz",
|
||||
@ -1210,6 +1311,40 @@
|
||||
"url": "https://github.com/sindresorhus/execa?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.15.11",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.11.tgz",
|
||||
"integrity": "sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=4.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"debug": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/form-data": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz",
|
||||
"integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==",
|
||||
"dependencies": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"es-set-tostringtag": "^2.1.0",
|
||||
"hasown": "^2.0.2",
|
||||
"mime-types": "^2.1.12"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/fsevents": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
|
||||
@ -1225,6 +1360,14 @@
|
||||
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/function-bind": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
||||
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/get-func-name": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz",
|
||||
@ -1235,6 +1378,41 @@
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/get-intrinsic": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
||||
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.2",
|
||||
"es-define-property": "^1.0.1",
|
||||
"es-errors": "^1.3.0",
|
||||
"es-object-atoms": "^1.1.1",
|
||||
"function-bind": "^1.1.2",
|
||||
"get-proto": "^1.0.1",
|
||||
"gopd": "^1.2.0",
|
||||
"has-symbols": "^1.1.0",
|
||||
"hasown": "^2.0.2",
|
||||
"math-intrinsics": "^1.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/get-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
|
||||
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
|
||||
"dependencies": {
|
||||
"dunder-proto": "^1.0.1",
|
||||
"es-object-atoms": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/get-stream": {
|
||||
"version": "8.0.1",
|
||||
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-8.0.1.tgz",
|
||||
@ -1248,6 +1426,53 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/gopd": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
|
||||
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/has-symbols": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
|
||||
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/has-tostringtag": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz",
|
||||
"integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==",
|
||||
"dependencies": {
|
||||
"has-symbols": "^1.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/hasown": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
|
||||
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
|
||||
"dependencies": {
|
||||
"function-bind": "^1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/human-signals": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/human-signals/-/human-signals-5.0.0.tgz",
|
||||
@ -1406,6 +1631,14 @@
|
||||
"integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/math-intrinsics": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
||||
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/maybe-combine-errors": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/maybe-combine-errors/-/maybe-combine-errors-1.0.0.tgz",
|
||||
@ -1421,6 +1654,25 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/mime-db": {
|
||||
"version": "1.52.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-types": {
|
||||
"version": "2.1.35",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
||||
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||
"dependencies": {
|
||||
"mime-db": "1.52.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mimic-fn": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz",
|
||||
@ -1661,6 +1913,11 @@
|
||||
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/proxy-from-env": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
||||
},
|
||||
"node_modules/react-is": {
|
||||
"version": "18.3.1",
|
||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz",
|
||||
|
@ -1,8 +1,7 @@
|
||||
{
|
||||
"name": "sdk_signer",
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.1",
|
||||
"description": "",
|
||||
"type": "commonjs",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"test": "vitest run",
|
||||
@ -21,6 +20,7 @@
|
||||
"@types/node": "^22.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.7.8",
|
||||
"ws": "^8.14.2",
|
||||
"@types/ws": "^8.5.10",
|
||||
"dotenv": "^16.3.1",
|
||||
|
336
pkg/sdk_client.d.ts
vendored
336
pkg/sdk_client.d.ts
vendored
@ -1,336 +0,0 @@
|
||||
// 4NK SDK Client WASM TypeScript Declarations (flate2 compatible)
|
||||
|
||||
export interface ApiReturn<T = any> {
|
||||
success: boolean;
|
||||
data?: T;
|
||||
error?: string;
|
||||
new_tx_to_send?: any;
|
||||
commit_to_send?: any;
|
||||
partial_tx?: any;
|
||||
secrets?: any;
|
||||
updated_process?: any;
|
||||
push_to_storage?: any;
|
||||
ciphers_to_send?: any;
|
||||
}
|
||||
|
||||
export interface Device {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Process {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
device_id: string;
|
||||
state: ProcessState;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Member {
|
||||
id: string;
|
||||
name: string;
|
||||
public_key: string;
|
||||
process_id: string;
|
||||
roles: string[];
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Role {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
process_id: string;
|
||||
members: string[];
|
||||
validation_rules: ValidationRule[];
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface ValidationRule {
|
||||
id: string;
|
||||
field_name: string;
|
||||
rule_type: ValidationRuleType;
|
||||
parameters?: any;
|
||||
role_id: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Commitment {
|
||||
id: string;
|
||||
hash: string;
|
||||
data: any;
|
||||
process_id: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Signature {
|
||||
id: string;
|
||||
signature: string;
|
||||
commitment_id: string;
|
||||
public_key: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface HandshakeMessage {
|
||||
id: string;
|
||||
message_type: string;
|
||||
data: any;
|
||||
device_id: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface ProcessState {
|
||||
commited_in: any;
|
||||
pcd_commitment: any;
|
||||
state_id: string;
|
||||
keys: Record<string, string>;
|
||||
validation_tokens: any[];
|
||||
public_data: any;
|
||||
roles: Record<string, RoleDefinition>;
|
||||
}
|
||||
|
||||
export interface RoleDefinition {
|
||||
members: any[];
|
||||
validation_rules: Record<string, ValidationRule>;
|
||||
}
|
||||
|
||||
export interface OutPointProcessMap {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface Process {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
device_id: string;
|
||||
state: ProcessState;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Member {
|
||||
id: string;
|
||||
name: string;
|
||||
public_key: string;
|
||||
process_id: string;
|
||||
roles: string[];
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Role {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
process_id: string;
|
||||
members: string[];
|
||||
validation_rules: ValidationRule[];
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface ValidationRule {
|
||||
id: string;
|
||||
field_name: string;
|
||||
rule_type: ValidationRuleType;
|
||||
parameters?: any;
|
||||
role_id: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Commitment {
|
||||
id: string;
|
||||
hash: string;
|
||||
data: any;
|
||||
process_id: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface Signature {
|
||||
id: string;
|
||||
signature: string;
|
||||
commitment_id: string;
|
||||
public_key: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface HandshakeMessage {
|
||||
id: string;
|
||||
message_type: string;
|
||||
data: any;
|
||||
device_id: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface ProcessState {
|
||||
commited_in: any;
|
||||
pcd_commitment: any;
|
||||
state_id: string;
|
||||
keys: Record<string, string>;
|
||||
validation_tokens: any[];
|
||||
public_data: any;
|
||||
roles: Record<string, RoleDefinition>;
|
||||
}
|
||||
|
||||
export interface RoleDefinition {
|
||||
members: any[];
|
||||
validation_rules: Record<string, ValidationRule>;
|
||||
}
|
||||
|
||||
export interface OutPointProcessMap {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
// Enums
|
||||
export const AnkFlag: {
|
||||
VALIDATION_YES: "validation_yes";
|
||||
VALIDATION_NO: "validation_no";
|
||||
};
|
||||
|
||||
export const ProcessState: {
|
||||
DRAFT: "draft";
|
||||
ACTIVE: "active";
|
||||
COMPLETED: "completed";
|
||||
CANCELLED: "cancelled";
|
||||
};
|
||||
|
||||
export const MemberRole: {
|
||||
OWNER: "owner";
|
||||
ADMIN: "admin";
|
||||
MEMBER: "member";
|
||||
GUEST: "guest";
|
||||
};
|
||||
|
||||
export const ValidationRuleType: {
|
||||
REQUIRED: "required";
|
||||
MIN_LENGTH: "min_length";
|
||||
MAX_LENGTH: "max_length";
|
||||
PATTERN: "pattern";
|
||||
CUSTOM: "custom";
|
||||
};
|
||||
|
||||
// Function signatures
|
||||
export function create_transaction(addresses: any, amount: number): ApiReturn;
|
||||
export function create_silent_payment_address(scan_key: string, spend_key: string): ApiReturn<string>;
|
||||
export function create_silent_payment_transaction(scan_key: string, spend_key: string, outputs: any[]): ApiReturn;
|
||||
export function create_device(name: string, description?: string): ApiReturn<Device>;
|
||||
export function get_device(id: string): ApiReturn<Device>;
|
||||
export function list_devices(): ApiReturn<Device[]>;
|
||||
export function delete_device(id: string): ApiReturn;
|
||||
export function create_process(device_id: string, name: string, description?: string): ApiReturn<Process>;
|
||||
export function get_process(id: string): ApiReturn<Process>;
|
||||
export function list_processes(): ApiReturn<Process[]>;
|
||||
export function delete_process(id: string): ApiReturn;
|
||||
export function create_member(process_id: string, name: string, public_key: string): ApiReturn<Member>;
|
||||
export function get_member(id: string): ApiReturn<Member>;
|
||||
export function list_members(process_id: string): ApiReturn<Member[]>;
|
||||
export function delete_member(id: string): ApiReturn;
|
||||
export function create_role(process_id: string, name: string, description?: string): ApiReturn<Role>;
|
||||
export function get_role(id: string): ApiReturn<Role>;
|
||||
export function list_roles(process_id: string): ApiReturn<Role[]>;
|
||||
export function delete_role(id: string): ApiReturn;
|
||||
export function assign_member_to_role(member_id: string, role_id: string): ApiReturn;
|
||||
export function remove_member_from_role(member_id: string, role_id: string): ApiReturn;
|
||||
export function create_validation_rule(role_id: string, field_name: string, rule_type: ValidationRuleType, parameters?: any): ApiReturn<ValidationRule>;
|
||||
export function get_validation_rule(id: string): ApiReturn<ValidationRule>;
|
||||
export function list_validation_rules(role_id: string): ApiReturn<ValidationRule[]>;
|
||||
export function delete_validation_rule(id: string): ApiReturn;
|
||||
export function create_commitment(process_id: string, data: any): ApiReturn<Commitment>;
|
||||
export function get_commitment(id: string): ApiReturn<Commitment>;
|
||||
export function list_commitments(process_id: string): ApiReturn<Commitment[]>;
|
||||
export function delete_commitment(id: string): ApiReturn;
|
||||
export function create_signature(commitment_id: string, private_key: string): ApiReturn<Signature>;
|
||||
export function verify_signature(commitment_id: string, signature: string, public_key: string): ApiReturn<{ valid: boolean }>;
|
||||
export function list_signatures(commitment_id: string): ApiReturn<Signature[]>;
|
||||
export function delete_signature(id: string): ApiReturn;
|
||||
export function compress_data(data: string): Promise<ApiReturn<string>>;
|
||||
export function decompress_data(compressed_data: string): Promise<ApiReturn<string>>;
|
||||
export function create_handshake_message(device_id: string, message_type: string, data: any): ApiReturn<HandshakeMessage>;
|
||||
export function verify_handshake_message(message: HandshakeMessage, public_key: string): ApiReturn<{ valid: boolean }>;
|
||||
export function create_encrypted_message(data: any, public_key: string): ApiReturn<{ encrypted: string }>;
|
||||
export function decrypt_message(encrypted_data: string, private_key: string): ApiReturn<{ decrypted: string }>;
|
||||
export function create_hash(data: string): ApiReturn<{ hash: string }>;
|
||||
export function verify_hash(data: string, hash: string): ApiReturn<{ valid: boolean }>;
|
||||
export function create_random_bytes(length: number): ApiReturn<{ bytes: string }>;
|
||||
export function create_uuid(): ApiReturn<{ uuid: string }>;
|
||||
export function get_timestamp(): ApiReturn<{ timestamp: number }>;
|
||||
export function validate_input(input: any, validation_rules: ValidationRule[]): ApiReturn<{ valid: boolean; errors: string[] }>;
|
||||
export function format_output(output: any, format_type: string): ApiReturn<{ formatted: string }>;
|
||||
export function log_message(level: string, message: string): ApiReturn;
|
||||
export function get_version(): ApiReturn<{ version: string }>;
|
||||
export function get_health_status(): ApiReturn<{ status: string; uptime: number }>;
|
||||
|
||||
// Initialize function
|
||||
export function init(): Promise<void>;
|
||||
|
||||
// Default export
|
||||
export default {
|
||||
init,
|
||||
create_transaction,
|
||||
create_silent_payment_address,
|
||||
create_silent_payment_transaction,
|
||||
create_device,
|
||||
get_device,
|
||||
list_devices,
|
||||
delete_device,
|
||||
create_process,
|
||||
get_process,
|
||||
list_processes,
|
||||
delete_process,
|
||||
create_member,
|
||||
get_member,
|
||||
list_members,
|
||||
delete_member,
|
||||
create_role,
|
||||
get_role,
|
||||
list_roles,
|
||||
delete_role,
|
||||
assign_member_to_role,
|
||||
remove_member_from_role,
|
||||
create_validation_rule,
|
||||
get_validation_rule,
|
||||
list_validation_rules,
|
||||
delete_validation_rule,
|
||||
create_commitment,
|
||||
get_commitment,
|
||||
list_commitments,
|
||||
delete_commitment,
|
||||
create_signature,
|
||||
verify_signature,
|
||||
list_signatures,
|
||||
delete_signature,
|
||||
compress_data,
|
||||
decompress_data,
|
||||
create_handshake_message,
|
||||
verify_handshake_message,
|
||||
create_encrypted_message,
|
||||
decrypt_message,
|
||||
create_hash,
|
||||
verify_hash,
|
||||
create_random_bytes,
|
||||
create_uuid,
|
||||
get_timestamp,
|
||||
validate_input,
|
||||
format_output,
|
||||
log_message,
|
||||
get_version,
|
||||
get_health_status,
|
||||
AnkFlag,
|
||||
ProcessState,
|
||||
MemberRole,
|
||||
ValidationRuleType
|
||||
};
|
@ -1,355 +0,0 @@
|
||||
// 4NK SDK Client WASM Stub (flate2 compatible)
|
||||
// This is a temporary stub until the real WASM package is built
|
||||
|
||||
// Import flate2 for compression (pure JavaScript implementation)
|
||||
const { deflate, inflate } = require('zlib');
|
||||
const { promisify } = require('util');
|
||||
|
||||
const deflateAsync = promisify(deflate);
|
||||
const inflateAsync = promisify(inflate);
|
||||
|
||||
// Stub implementations for all SDK functions
|
||||
function create_transaction(addresses, amount) {
|
||||
console.log("create_transaction called with addresses:", addresses, "amount:", amount);
|
||||
return { success: true, data: { txid: "stub_txid_flate2" } };
|
||||
}
|
||||
|
||||
function create_silent_payment_address(scan_key, spend_key) {
|
||||
console.log("create_silent_payment_address called");
|
||||
return { success: true, data: "stub_sp_address_flate2" };
|
||||
}
|
||||
|
||||
function create_silent_payment_transaction(scan_key, spend_key, outputs) {
|
||||
console.log("create_silent_payment_transaction called");
|
||||
return { success: true, data: { txid: "stub_sp_txid_flate2" } };
|
||||
}
|
||||
|
||||
function create_device(name, description) {
|
||||
console.log("create_device called with name:", name, "description:", description);
|
||||
return { success: true, data: { id: "stub_device_id_flate2", name, description } };
|
||||
}
|
||||
|
||||
function get_device(id) {
|
||||
console.log("get_device called with id:", id);
|
||||
return { success: true, data: { id, name: "stub_device", description: "stub_description" } };
|
||||
}
|
||||
|
||||
function list_devices() {
|
||||
console.log("list_devices called");
|
||||
return { success: true, data: [{ id: "stub_device_1", name: "stub_device_1" }] };
|
||||
}
|
||||
|
||||
function delete_device(id) {
|
||||
console.log("delete_device called with id:", id);
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
function create_process(device_id, name, description) {
|
||||
console.log("create_process called");
|
||||
return { success: true, data: { id: "stub_process_id_flate2", name, description } };
|
||||
}
|
||||
|
||||
function get_process(id) {
|
||||
console.log("get_process called with id:", id);
|
||||
return { success: true, data: { id, name: "stub_process", description: "stub_description" } };
|
||||
}
|
||||
|
||||
function list_processes() {
|
||||
console.log("list_processes called");
|
||||
return { success: true, data: [{ id: "stub_process_1", name: "stub_process_1" }] };
|
||||
}
|
||||
|
||||
function delete_process(id) {
|
||||
console.log("delete_process called with id:", id);
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
function create_member(process_id, name, public_key) {
|
||||
console.log("create_member called");
|
||||
return { success: true, data: { id: "stub_member_id_flate2", name, public_key } };
|
||||
}
|
||||
|
||||
function get_member(id) {
|
||||
console.log("get_member called with id:", id);
|
||||
return { success: true, data: { id, name: "stub_member", public_key: "stub_key" } };
|
||||
}
|
||||
|
||||
function list_members(process_id) {
|
||||
console.log("list_members called");
|
||||
return { success: true, data: [{ id: "stub_member_1", name: "stub_member_1" }] };
|
||||
}
|
||||
|
||||
function delete_member(id) {
|
||||
console.log("delete_member called with id:", id);
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
function create_role(process_id, name, description) {
|
||||
console.log("create_role called");
|
||||
return { success: true, data: { id: "stub_role_id_flate2", name, description } };
|
||||
}
|
||||
|
||||
function get_role(id) {
|
||||
console.log("get_role called with id:", id);
|
||||
return { success: true, data: { id, name: "stub_role", description: "stub_description" } };
|
||||
}
|
||||
|
||||
function list_roles(process_id) {
|
||||
console.log("list_roles called");
|
||||
return { success: true, data: [{ id: "stub_role_1", name: "stub_role_1" }] };
|
||||
}
|
||||
|
||||
function delete_role(id) {
|
||||
console.log("delete_role called with id:", id);
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
function assign_member_to_role(member_id, role_id) {
|
||||
console.log("assign_member_to_role called");
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
function remove_member_from_role(member_id, role_id) {
|
||||
console.log("remove_member_from_role called");
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
function create_validation_rule(role_id, field_name, rule_type, parameters) {
|
||||
console.log("create_validation_rule called");
|
||||
return { success: true, data: { id: "stub_rule_id_flate2", field_name, rule_type } };
|
||||
}
|
||||
|
||||
function get_validation_rule(id) {
|
||||
console.log("get_validation_rule called with id:", id);
|
||||
return { success: true, data: { id, field_name: "stub_field", rule_type: "stub_type" } };
|
||||
}
|
||||
|
||||
function list_validation_rules(role_id) {
|
||||
console.log("list_validation_rules called");
|
||||
return { success: true, data: [{ id: "stub_rule_1", field_name: "stub_field_1" }] };
|
||||
}
|
||||
|
||||
function delete_validation_rule(id) {
|
||||
console.log("delete_validation_rule called with id:", id);
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
function create_commitment(process_id, data) {
|
||||
console.log("create_commitment called");
|
||||
return { success: true, data: { id: "stub_commitment_id_flate2", hash: "stub_hash" } };
|
||||
}
|
||||
|
||||
function get_commitment(id) {
|
||||
console.log("get_commitment called with id:", id);
|
||||
return { success: true, data: { id, hash: "stub_hash", data: "stub_data" } };
|
||||
}
|
||||
|
||||
function list_commitments(process_id) {
|
||||
console.log("list_commitments called");
|
||||
return { success: true, data: [{ id: "stub_commitment_1", hash: "stub_hash_1" }] };
|
||||
}
|
||||
|
||||
function delete_commitment(id) {
|
||||
console.log("delete_commitment called with id:", id);
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
function create_signature(commitment_id, private_key) {
|
||||
console.log("create_signature called");
|
||||
return { success: true, data: { id: "stub_signature_id_flate2", signature: "stub_signature" } };
|
||||
}
|
||||
|
||||
function verify_signature(commitment_id, signature, public_key) {
|
||||
console.log("verify_signature called");
|
||||
return { success: true, data: { valid: true } };
|
||||
}
|
||||
|
||||
function list_signatures(commitment_id) {
|
||||
console.log("list_signatures called");
|
||||
return { success: true, data: [{ id: "stub_signature_1", signature: "stub_signature_1" }] };
|
||||
}
|
||||
|
||||
function delete_signature(id) {
|
||||
console.log("delete_signature called with id:", id);
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
function compress_data(data) {
|
||||
console.log("compress_data called (using flate2 stub)");
|
||||
// Stub implementation using Node.js zlib (equivalent to flate2)
|
||||
return deflateAsync(Buffer.from(data)).then(compressed => ({
|
||||
success: true,
|
||||
data: compressed.toString('base64')
|
||||
}));
|
||||
}
|
||||
|
||||
function decompress_data(compressed_data) {
|
||||
console.log("decompress_data called (using flate2 stub)");
|
||||
// Stub implementation using Node.js zlib (equivalent to flate2)
|
||||
return inflateAsync(Buffer.from(compressed_data, 'base64')).then(decompressed => ({
|
||||
success: true,
|
||||
data: decompressed.toString()
|
||||
}));
|
||||
}
|
||||
|
||||
function create_handshake_message(device_id, message_type, data) {
|
||||
console.log("create_handshake_message called");
|
||||
return { success: true, data: { id: "stub_handshake_id_flate2", message_type, data } };
|
||||
}
|
||||
|
||||
function verify_handshake_message(message, public_key) {
|
||||
console.log("verify_handshake_message called");
|
||||
return { success: true, data: { valid: true } };
|
||||
}
|
||||
|
||||
function create_encrypted_message(data, public_key) {
|
||||
console.log("create_encrypted_message called");
|
||||
return { success: true, data: { encrypted: "stub_encrypted_data_flate2" } };
|
||||
}
|
||||
|
||||
function decrypt_message(encrypted_data, private_key) {
|
||||
console.log("decrypt_message called");
|
||||
return { success: true, data: { decrypted: "stub_decrypted_data_flate2" } };
|
||||
}
|
||||
|
||||
function create_hash(data) {
|
||||
console.log("create_hash called");
|
||||
return { success: true, data: { hash: "stub_hash_flate2" } };
|
||||
}
|
||||
|
||||
function verify_hash(data, hash) {
|
||||
console.log("verify_hash called");
|
||||
return { success: true, data: { valid: true } };
|
||||
}
|
||||
|
||||
function create_random_bytes(length) {
|
||||
console.log("create_random_bytes called");
|
||||
return { success: true, data: { bytes: "stub_random_bytes_flate2" } };
|
||||
}
|
||||
|
||||
function create_uuid() {
|
||||
console.log("create_uuid called");
|
||||
return { success: true, data: { uuid: "stub-uuid-flate2" } };
|
||||
}
|
||||
|
||||
function get_timestamp() {
|
||||
console.log("get_timestamp called");
|
||||
return { success: true, data: { timestamp: Date.now() } };
|
||||
}
|
||||
|
||||
function validate_input(input, validation_rules) {
|
||||
console.log("validate_input called");
|
||||
return { success: true, data: { valid: true, errors: [] } };
|
||||
}
|
||||
|
||||
function format_output(output, format_type) {
|
||||
console.log("format_output called");
|
||||
return { success: true, data: { formatted: "stub_formatted_output_flate2" } };
|
||||
}
|
||||
|
||||
function log_message(level, message) {
|
||||
console.log(`[${level}] ${message} (flate2 stub)`);
|
||||
return { success: true, data: null };
|
||||
}
|
||||
|
||||
function get_version() {
|
||||
console.log("get_version called");
|
||||
return { success: true, data: { version: "0.1.4-flate2-stub" } };
|
||||
}
|
||||
|
||||
function get_health_status() {
|
||||
console.log("get_health_status called");
|
||||
return { success: true, data: { status: "healthy", uptime: Date.now() } };
|
||||
}
|
||||
|
||||
// Export all the types and interfaces
|
||||
const AnkFlag = {
|
||||
VALIDATION_YES: "validation_yes",
|
||||
VALIDATION_NO: "validation_no"
|
||||
};
|
||||
|
||||
const ProcessState = {
|
||||
DRAFT: "draft",
|
||||
ACTIVE: "active",
|
||||
COMPLETED: "completed",
|
||||
CANCELLED: "cancelled"
|
||||
};
|
||||
|
||||
const MemberRole = {
|
||||
OWNER: "owner",
|
||||
ADMIN: "admin",
|
||||
MEMBER: "member",
|
||||
GUEST: "guest"
|
||||
};
|
||||
|
||||
const ValidationRuleType = {
|
||||
REQUIRED: "required",
|
||||
MIN_LENGTH: "min_length",
|
||||
MAX_LENGTH: "max_length",
|
||||
PATTERN: "pattern",
|
||||
CUSTOM: "custom"
|
||||
};
|
||||
|
||||
// Initialize the WASM module
|
||||
function init() {
|
||||
console.log("sdk_client WASM stub initialized (flate2 compatible)");
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
// Module exports for CommonJS
|
||||
module.exports = {
|
||||
init,
|
||||
create_transaction,
|
||||
create_silent_payment_address,
|
||||
create_silent_payment_transaction,
|
||||
create_device,
|
||||
get_device,
|
||||
list_devices,
|
||||
delete_device,
|
||||
create_process,
|
||||
get_process,
|
||||
list_processes,
|
||||
delete_process,
|
||||
create_member,
|
||||
get_member,
|
||||
list_members,
|
||||
delete_member,
|
||||
create_role,
|
||||
get_role,
|
||||
list_roles,
|
||||
delete_role,
|
||||
assign_member_to_role,
|
||||
remove_member_from_role,
|
||||
create_validation_rule,
|
||||
get_validation_rule,
|
||||
list_validation_rules,
|
||||
delete_validation_rule,
|
||||
create_commitment,
|
||||
get_commitment,
|
||||
list_commitments,
|
||||
delete_commitment,
|
||||
create_signature,
|
||||
verify_signature,
|
||||
list_signatures,
|
||||
delete_signature,
|
||||
compress_data,
|
||||
decompress_data,
|
||||
create_handshake_message,
|
||||
verify_handshake_message,
|
||||
create_encrypted_message,
|
||||
decrypt_message,
|
||||
create_hash,
|
||||
verify_hash,
|
||||
create_random_bytes,
|
||||
create_uuid,
|
||||
get_timestamp,
|
||||
validate_input,
|
||||
format_output,
|
||||
log_message,
|
||||
get_version,
|
||||
get_health_status,
|
||||
AnkFlag,
|
||||
ProcessState,
|
||||
MemberRole,
|
||||
ValidationRuleType
|
||||
};
|
@ -1,6 +1,4 @@
|
||||
import dotenv from 'dotenv';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
// Load environment variables from .env file
|
||||
dotenv.config();
|
||||
@ -15,50 +13,12 @@ export interface AppConfig {
|
||||
logLevel: string;
|
||||
}
|
||||
|
||||
function parseConfigFile(): Partial<AppConfig> {
|
||||
try {
|
||||
// Try to read the TOML config file
|
||||
const configPath = '/usr/local/bin/sdk_signer.conf';
|
||||
if (fs.existsSync(configPath)) {
|
||||
const configContent = fs.readFileSync(configPath, 'utf8');
|
||||
|
||||
// Simple TOML parsing for our needs
|
||||
const relayUrlsMatch = configContent.match(/relay_urls\s*=\s*\[(.*?)\]/);
|
||||
const wsPortMatch = configContent.match(/ws_port\s*=\s*(\d+)/);
|
||||
const httpPortMatch = configContent.match(/http_port\s*=\s*(\d+)/);
|
||||
|
||||
const config: Partial<AppConfig> = {};
|
||||
|
||||
if (relayUrlsMatch) {
|
||||
// Parse relay URLs from the array format
|
||||
const urlsStr = relayUrlsMatch[1];
|
||||
const urls = urlsStr.split(',').map(url =>
|
||||
url.trim().replace(/"/g, '').replace(/http:\/\//, 'ws://')
|
||||
);
|
||||
config.relayUrls = urls;
|
||||
}
|
||||
|
||||
if (wsPortMatch) {
|
||||
config.port = parseInt(wsPortMatch[1]);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('⚠️ Warning: Could not read config file, using defaults:', error);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
export function loadConfig(): AppConfig {
|
||||
const fileConfig = parseConfigFile();
|
||||
|
||||
return {
|
||||
port: fileConfig.port || parseInt(process.env.PORT || '9090'),
|
||||
port: parseInt(process.env.PORT || '9090'),
|
||||
apiKey: process.env.API_KEY || 'your-api-key-change-this',
|
||||
databasePath: process.env.DATABASE_PATH || './data/server.db',
|
||||
relayUrls: fileConfig.relayUrls || process.env.RELAY_URLS?.split(',') || ['ws://localhost:8090'],
|
||||
relayUrls: process.env.RELAY_URLS?.split(',') || ['ws://localhost:8090'],
|
||||
autoRestart: process.env.AUTO_RESTART === 'true',
|
||||
maxRestarts: parseInt(process.env.MAX_RESTARTS || '10'),
|
||||
logLevel: process.env.LOG_LEVEL || 'info'
|
||||
|
@ -60,19 +60,27 @@ export default class Database {
|
||||
}
|
||||
|
||||
private parseKey(fullKey: string): { storeName: string; key: string } | null {
|
||||
const parts = fullKey.split(':', 2);
|
||||
if (parts.length !== 2) return null;
|
||||
return { storeName: parts[0], key: parts[1] };
|
||||
const colonIndex = fullKey.indexOf(':');
|
||||
if (colonIndex === -1) return null;
|
||||
|
||||
const storeName = fullKey.substring(0, colonIndex);
|
||||
const key = fullKey.substring(colonIndex + 1);
|
||||
|
||||
return { storeName, key };
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single object from a store
|
||||
* O(log n) operation - only reads specific key
|
||||
*/
|
||||
public async getObject(storeName: string, key: string): Promise<any | null> {
|
||||
public async getObject(storeName: string, key: string, isBuffer: boolean = false): Promise<any | null> {
|
||||
try {
|
||||
const fullKey = this.getKey(storeName, key);
|
||||
return await this.db.get(fullKey);
|
||||
if (isBuffer) {
|
||||
return await this.db.get(fullKey, { valueEncoding: 'buffer' });
|
||||
} else {
|
||||
return await this.db.get(fullKey);
|
||||
}
|
||||
} catch (error) {
|
||||
if ((error as any).code === 'LEVEL_NOT_FOUND') {
|
||||
return null;
|
||||
@ -85,12 +93,16 @@ export default class Database {
|
||||
* Add or update an object in a store
|
||||
* O(log n) operation - only writes specific key-value pair
|
||||
*/
|
||||
public async addObject(operation: DatabaseObject): Promise<void> {
|
||||
public async addObject(operation: DatabaseObject, isBuffer: boolean = false): Promise<void> {
|
||||
const { storeName, object, key } = operation;
|
||||
|
||||
if (key) {
|
||||
const fullKey = this.getKey(storeName, key);
|
||||
await this.db.put(fullKey, object);
|
||||
if (isBuffer) {
|
||||
await this.db.put(fullKey, object, { valueEncoding: 'buffer' });
|
||||
} else {
|
||||
await this.db.put(fullKey, object);
|
||||
}
|
||||
} else {
|
||||
// Auto-generate key if none provided
|
||||
const autoKey = Date.now().toString() + Math.random().toString(36).substr(2, 9);
|
||||
|
@ -18,7 +18,7 @@ interface RelayConnection {
|
||||
|
||||
interface QueuedMessage {
|
||||
id: string;
|
||||
flag: typeof AnkFlag[keyof typeof AnkFlag];
|
||||
flag: AnkFlag;
|
||||
payload: any;
|
||||
targetRelayId?: string;
|
||||
timestamp: number;
|
||||
@ -170,7 +170,7 @@ export class RelayManager {
|
||||
}
|
||||
|
||||
// Message Sending Methods using AnkFlag
|
||||
public sendMessage(flag: typeof AnkFlag[keyof typeof AnkFlag], payload: any, targetRelayId?: string): void {
|
||||
public sendMessage(flag: AnkFlag, payload: any, targetRelayId?: string): void {
|
||||
const msg: QueuedMessage = {
|
||||
id: this.generateMessageId(),
|
||||
flag,
|
||||
@ -185,7 +185,7 @@ export class RelayManager {
|
||||
this.queueMessage(msg);
|
||||
}
|
||||
|
||||
public sendToRelay(relayId: string, flag: typeof AnkFlag[keyof typeof AnkFlag], content: any): boolean {
|
||||
public sendToRelay(relayId: string, flag: AnkFlag, content: any): boolean {
|
||||
const relay = this.relays.get(relayId);
|
||||
if (!relay || !relay.isConnected) {
|
||||
console.warn(`⚠️ Cannot send to relay ${relayId}: not connected`);
|
||||
@ -206,7 +206,7 @@ export class RelayManager {
|
||||
}
|
||||
}
|
||||
|
||||
public broadcastToAllRelays(flag: typeof AnkFlag[keyof typeof AnkFlag], payload: any): number {
|
||||
public broadcastToAllRelays(flag: AnkFlag, payload: any): number {
|
||||
const connectedRelays = this.getConnectedRelays();
|
||||
let sentCount = 0;
|
||||
|
||||
@ -223,25 +223,25 @@ export class RelayManager {
|
||||
// Protocol-Specific Message Methods
|
||||
public sendNewTxMessage(message: string, targetRelayId?: string): void {
|
||||
// Use appropriate AnkFlag for new transaction
|
||||
this.sendMessage("NewTx" as typeof AnkFlag[keyof typeof AnkFlag], message, targetRelayId);
|
||||
this.sendMessage("NewTx" as AnkFlag, message, targetRelayId);
|
||||
}
|
||||
|
||||
public sendCommitMessage(message: string, targetRelayId?: string): void {
|
||||
// Use appropriate AnkFlag for commit
|
||||
this.sendMessage("Commit" as typeof AnkFlag[keyof typeof AnkFlag], message, targetRelayId);
|
||||
this.sendMessage("Commit" as AnkFlag, message, targetRelayId);
|
||||
}
|
||||
|
||||
public sendCipherMessages(ciphers: string[], targetRelayId?: string): void {
|
||||
for (const cipher of ciphers) {
|
||||
// Use appropriate AnkFlag for cipher
|
||||
this.sendMessage("Cipher" as typeof AnkFlag[keyof typeof AnkFlag], cipher, targetRelayId);
|
||||
this.sendMessage("Cipher" as AnkFlag, cipher, targetRelayId);
|
||||
}
|
||||
}
|
||||
|
||||
public sendFaucetMessage(message: string, targetRelayId?: string): void {
|
||||
// Use appropriate AnkFlag for faucet
|
||||
console.log(`📨 Sending faucet message to relay ${targetRelayId}:`, message);
|
||||
this.sendMessage("Faucet" as typeof AnkFlag[keyof typeof AnkFlag], message, targetRelayId);
|
||||
this.sendMessage("Faucet" as AnkFlag, message, targetRelayId);
|
||||
}
|
||||
|
||||
// Message Queue Management
|
||||
@ -342,8 +342,8 @@ export class RelayManager {
|
||||
switch (message.flag) {
|
||||
case "NewTx":
|
||||
console.log(`📨 NewTx response from relay ${relayId}`);
|
||||
setImmediate(async () => {
|
||||
(await Service.getInstance()).parseNewTx(message.content);
|
||||
setImmediate(() => {
|
||||
Service.getInstance().parseNewTx(message.content);
|
||||
});
|
||||
break;
|
||||
case "Commit":
|
||||
@ -353,8 +353,8 @@ export class RelayManager {
|
||||
break;
|
||||
case "Cipher":
|
||||
console.log(`📨 Cipher response from relay ${relayId}`);
|
||||
setImmediate(async () => {
|
||||
(await Service.getInstance()).parseCipher(message.content);
|
||||
setImmediate(() => {
|
||||
Service.getInstance().parseCipher(message.content);
|
||||
});
|
||||
break;
|
||||
case "Handshake":
|
||||
|
511
src/service.ts
511
src/service.ts
@ -1,10 +1,11 @@
|
||||
// Simple server service with core protocol methods using WASM SDK
|
||||
import Database from './database.service';
|
||||
import * as wasm from './wasm_compat';
|
||||
import { ApiReturn, Device, HandshakeMessage, Member, OutPointProcessMap, Process, ProcessState, RoleDefinition } from '../pkg/sdk_client';
|
||||
import * as wasm from '../pkg/sdk_client';
|
||||
import { ApiReturn, Device, HandshakeMessage, Member, MerkleProofResult, OutPointProcessMap, Process, ProcessState, RoleDefinition, SecretsStore, UserDiff } from '../pkg/sdk_client';
|
||||
import { RelayManager } from './relay-manager';
|
||||
import { config } from './config';
|
||||
import { EMPTY32BYTES } from './utils';
|
||||
import { storeData } from './storage.service';
|
||||
|
||||
const DEFAULTAMOUNT = 1000n;
|
||||
const DEVICE_KEY = 'main_device';
|
||||
@ -22,13 +23,14 @@ export class Service {
|
||||
this.relayManager.setHandshakeCallback((url: string, message: any) => {
|
||||
this.handleHandshakeMsg(url, message);
|
||||
});
|
||||
// WASM init will be called separately
|
||||
this.initWasm();
|
||||
// Removed automatic relay initialization - will connect when needed
|
||||
}
|
||||
|
||||
private async initWasm() {
|
||||
private initWasm() {
|
||||
try {
|
||||
console.log('🔧 Initializing WASM SDK...');
|
||||
await wasm.init();
|
||||
wasm.setup();
|
||||
console.log('✅ WASM SDK initialized successfully');
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to initialize WASM SDK:', error);
|
||||
@ -36,10 +38,9 @@ export class Service {
|
||||
}
|
||||
}
|
||||
|
||||
static async getInstance(): Promise<Service> {
|
||||
static getInstance(): Service {
|
||||
if (!Service.instance) {
|
||||
Service.instance = new Service();
|
||||
await Service.instance.initWasm();
|
||||
}
|
||||
return Service.instance;
|
||||
}
|
||||
@ -48,24 +49,19 @@ export class Service {
|
||||
public async handleHandshakeMsg(url: string, parsedMsg: any) {
|
||||
try {
|
||||
const handshakeMsg: HandshakeMessage = JSON.parse(parsedMsg.content);
|
||||
if (handshakeMsg.data?.sp_address) {
|
||||
this.relayManager.updateRelay(url, handshakeMsg.data.sp_address);
|
||||
}
|
||||
this.relayManager.updateRelay(url, handshakeMsg.sp_address);
|
||||
if (this.membersList && Object.keys(this.membersList).length === 0) {
|
||||
// We start from an empty list, just copy it over
|
||||
this.membersList = handshakeMsg.data?.peers_list;
|
||||
this.membersList = handshakeMsg.peers_list;
|
||||
} else {
|
||||
// We are incrementing our list
|
||||
if (handshakeMsg.data?.peers_list) {
|
||||
for (const [processId, member] of Object.entries(handshakeMsg.data.peers_list)) {
|
||||
this.membersList[processId] = member as Member;
|
||||
}
|
||||
for (const [processId, member] of Object.entries(handshakeMsg.peers_list)) {
|
||||
this.membersList[processId] = member as Member;
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(async () => {
|
||||
if (handshakeMsg.data?.processes_list) {
|
||||
const newProcesses: OutPointProcessMap = handshakeMsg.data.processes_list;
|
||||
const newProcesses: OutPointProcessMap = handshakeMsg.processes_list;
|
||||
if (!newProcesses || Object.keys(newProcesses).length === 0) {
|
||||
console.debug('Received empty processes list from', url);
|
||||
return;
|
||||
@ -85,60 +81,51 @@ export class Service {
|
||||
const existing = await this.getProcess(processId);
|
||||
if (existing) {
|
||||
// Look for state id we don't know yet
|
||||
let new_states = [];
|
||||
let roles = [];
|
||||
const state = process.state;
|
||||
if (state) {
|
||||
if (!state.state_id || state.state_id === EMPTY32BYTES) { return; }
|
||||
if (!this.lookForStateId(existing, state.state_id)) {
|
||||
let newStates: string[] = [];
|
||||
let newRoles: Record<string, RoleDefinition>[] = [];
|
||||
for (const state of process.states) {
|
||||
if (!state || !state.state_id) { continue; } // shouldn't happen
|
||||
if (state.state_id === EMPTY32BYTES) {
|
||||
// We check that the tip is the same we have, if not we update
|
||||
const existingTip = existing.states[existing.states.length - 1].commited_in;
|
||||
if (existingTip !== state.commited_in) {
|
||||
console.log('Found new tip for process', processId);
|
||||
existing.states.pop(); // We discard the last state
|
||||
existing.states.push(state);
|
||||
// We know that's the last state, so we just trigger the update
|
||||
toSave[processId] = existing;
|
||||
}
|
||||
} else if (!this.lookForStateId(existing, state.state_id)) {
|
||||
// We don't want to overwrite what we already have for existing processes
|
||||
// We may end up overwriting the keys for example
|
||||
// So the process we're going to save needs to merge new states with what we already have
|
||||
const existingLastState = existing.states.pop();
|
||||
existing.states.push(state);
|
||||
existing.states.push(existingLastState);
|
||||
toSave[processId] = existing; // We mark it for update
|
||||
if (this.rolesContainsUs(state.roles)) {
|
||||
new_states.push(state.state_id);
|
||||
roles.push(state.roles);
|
||||
newStates.push(state.state_id);
|
||||
newRoles.push(state.roles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (new_states.length != 0) {
|
||||
// We request the new states
|
||||
await this.requestDataFromPeers(processId, new_states, roles);
|
||||
toSave[processId] = process;
|
||||
if (newStates.length != 0) {
|
||||
await this.requestDataFromPeers(processId, newStates, newRoles);
|
||||
}
|
||||
|
||||
// Just to be sure check if that's a pairing process
|
||||
const lastCommitedState = this.getLastCommitedState(process);
|
||||
if (lastCommitedState && lastCommitedState.public_data && lastCommitedState.public_data['pairedAddresses']) {
|
||||
// This is a pairing process
|
||||
try {
|
||||
const pairedAddresses = this.decodeValue(lastCommitedState.public_data['pairedAddresses'] as unknown as number[]);
|
||||
// Are we part of it?
|
||||
if (pairedAddresses && pairedAddresses.length > 0 && pairedAddresses.includes(this.getDeviceAddress())) {
|
||||
// We save the process to db
|
||||
await this.saveProcessToDb(processId, process as Process);
|
||||
// We update the device
|
||||
await this.updateDevice();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to check for pairing process:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise we're probably just in the initial loading at page initialization
|
||||
|
||||
// We may learn an update for this process
|
||||
// TODO maybe actually check if what the relay is sending us contains more information than what we have
|
||||
// relay should always have more info than us, but we never know
|
||||
// For now let's keep it simple and let the worker do the job
|
||||
} else {
|
||||
// We add it to db
|
||||
console.log(`Saving ${processId} to db`);
|
||||
toSave[processId] = process;
|
||||
}
|
||||
}
|
||||
|
||||
await this.batchSaveProcessesToDb(toSave);
|
||||
if (toSave && Object.keys(toSave).length > 0) {
|
||||
console.log('batch saving processes to db', toSave);
|
||||
await this.batchSaveProcessesToDb(toSave);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 500);
|
||||
}, 500)
|
||||
} catch (e) {
|
||||
console.error('Failed to parse init message:', e);
|
||||
}
|
||||
@ -271,8 +258,6 @@ export class Service {
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get relay statistics from RelayManager.
|
||||
* @returns Statistics about connected relays
|
||||
@ -301,45 +286,83 @@ export class Service {
|
||||
|
||||
public getAddressesForMemberId(memberId: string): string[] | null {
|
||||
try {
|
||||
const m: any = this.membersList[memberId];
|
||||
if (!m) return null;
|
||||
const addrs = (m as any).sp_addresses as string[] | undefined;
|
||||
return Array.isArray(addrs) ? addrs : null;
|
||||
return this.membersList[memberId].sp_addresses;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async checkConnections(members: Member[]): Promise<void> {
|
||||
// If we're updating a process, we must call that after update especially if roles are part of it
|
||||
// We will take the roles from the last state, wheter it's commited or not
|
||||
public async checkConnections(process: Process): Promise<void> {
|
||||
const sharedSecret = await this.getAllSecretsFromDB();
|
||||
console.log('sharedSecret found', sharedSecret);
|
||||
if (process.states.length < 2) {
|
||||
throw new Error('Process doesn\'t have any state yet');
|
||||
}
|
||||
let roles = process.states[process.states.length - 2].roles;
|
||||
if (!roles) {
|
||||
throw new Error('No roles found');
|
||||
} else {
|
||||
console.log('roles found', roles);
|
||||
}
|
||||
let members: Set<Member> = new Set();
|
||||
for (const role of Object.values(roles!)) {
|
||||
console.log('role found', role);
|
||||
for (const member of role.members) {
|
||||
console.log('member found', member);
|
||||
// Check if we know the member that matches this id
|
||||
const memberAddresses = this.getAddressesForMemberId(member);
|
||||
console.log('memberAddresses found', memberAddresses);
|
||||
if (memberAddresses && memberAddresses.length != 0) {
|
||||
members.add({ sp_addresses: memberAddresses });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (members.size === 0) {
|
||||
// This must be a pairing process
|
||||
// Check if we have a pairedAddresses in the public data
|
||||
const publicData = process.states[0]?.public_data;
|
||||
if (!publicData || !publicData['pairedAddresses']) {
|
||||
throw new Error('Not a pairing process');
|
||||
}
|
||||
const decodedAddresses = this.decodeValue(publicData['pairedAddresses']);
|
||||
if (decodedAddresses.length === 0) {
|
||||
throw new Error('Not a pairing process');
|
||||
}
|
||||
members.add({ sp_addresses: decodedAddresses });
|
||||
}
|
||||
|
||||
// Ensure the amount is available before proceeding
|
||||
await this.getTokensFromFaucet();
|
||||
let unconnectedAddresses = [];
|
||||
let unconnectedAddresses = new Set<string>();
|
||||
const myAddress = this.getDeviceAddress();
|
||||
for (const member of members) {
|
||||
const sp_addresses = (member as any)?.sp_addresses as string[] | undefined;
|
||||
for (const member of Array.from(members)) {
|
||||
const sp_addresses = member.sp_addresses;
|
||||
if (!sp_addresses || sp_addresses.length === 0) continue;
|
||||
for (const address of sp_addresses) {
|
||||
// For now, we ignore our own device address, although there might be use cases for having a secret with ourselves
|
||||
if (address === myAddress) continue;
|
||||
const sharedSecret = await this.getSecretForAddress(address);
|
||||
if (!sharedSecret) {
|
||||
unconnectedAddresses.push(address);
|
||||
unconnectedAddresses.add(address);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (unconnectedAddresses && unconnectedAddresses.length != 0) {
|
||||
if (unconnectedAddresses && unconnectedAddresses.size != 0) {
|
||||
const apiResult = await this.connectAddresses(unconnectedAddresses);
|
||||
await this.handleApiReturn(apiResult);
|
||||
}
|
||||
}
|
||||
|
||||
public async connectAddresses(addresses: string[]): Promise<ApiReturn> {
|
||||
if (addresses.length === 0) {
|
||||
public async connectAddresses(addresses: Set<string>): Promise<ApiReturn> {
|
||||
if (addresses.size === 0) {
|
||||
throw new Error('Trying to connect to empty addresses list');
|
||||
}
|
||||
|
||||
try {
|
||||
return wasm.create_transaction(addresses, 1);
|
||||
return wasm.create_transaction(Array.from(addresses), 1);
|
||||
} catch (e) {
|
||||
console.error('Failed to connect member:', e);
|
||||
throw e;
|
||||
@ -347,8 +370,7 @@ export class Service {
|
||||
}
|
||||
|
||||
private async ensureSufficientAmount(): Promise<void> {
|
||||
// Note: get_available_amount no longer exists in API
|
||||
const availableAmt: BigInt = BigInt(1000); // Default amount
|
||||
const availableAmt: BigInt = wasm.get_available_amount();
|
||||
const target: BigInt = DEFAULTAMOUNT * BigInt(10);
|
||||
|
||||
if (availableAmt < target) {
|
||||
@ -359,9 +381,8 @@ export class Service {
|
||||
}
|
||||
|
||||
try {
|
||||
// Note: create_faucet_msg no longer exists in API
|
||||
const faucetMsg = { type: 'faucet_request', address: 'default_address' };
|
||||
this.relayManager.sendFaucetMessage(JSON.stringify(faucetMsg));
|
||||
const faucetMsg = wasm.create_faucet_msg();
|
||||
this.relayManager.sendFaucetMessage(faucetMsg);
|
||||
} catch (e) {
|
||||
throw new Error('Failed to create faucet message');
|
||||
}
|
||||
@ -374,8 +395,7 @@ export class Service {
|
||||
let attempts = 3;
|
||||
|
||||
while (attempts > 0) {
|
||||
// Note: get_available_amount no longer exists in API
|
||||
const amount: BigInt = BigInt(1000); // Default amount
|
||||
const amount: BigInt = wasm.get_available_amount();
|
||||
if (amount >= target) {
|
||||
return amount;
|
||||
}
|
||||
@ -416,9 +436,8 @@ export class Service {
|
||||
|
||||
public async createNewDevice() {
|
||||
try {
|
||||
const spAddress = wasm.create_device('signet', 'SP address device');
|
||||
// Note: dump_device no longer exists in API
|
||||
const device = { id: 'default_device', name: 'Default Device' };
|
||||
const spAddress = wasm.create_new_device(0, 'signet');
|
||||
const device = wasm.dump_device();
|
||||
await this.saveDeviceInDatabase(device);
|
||||
return spAddress;
|
||||
} catch (e) {
|
||||
@ -439,7 +458,7 @@ export class Service {
|
||||
storeName: walletStore,
|
||||
object: {
|
||||
device_id: DEVICE_KEY,
|
||||
device_address: 'default_address', // Note: get_address no longer exists
|
||||
device_address: wasm.get_address(),
|
||||
created_at: new Date().toISOString(),
|
||||
device
|
||||
},
|
||||
@ -476,15 +495,14 @@ export class Service {
|
||||
const roles: Record<string, RoleDefinition> = {
|
||||
pairing: {
|
||||
members: [],
|
||||
validation_rules: {
|
||||
"stub_validation_rule": {
|
||||
id: "stub_validation_rule",
|
||||
field_name: "validation_field",
|
||||
rule_type: "custom" as any,
|
||||
role_id: "stub_role",
|
||||
parameters: { min_sig_member: 1.0 },
|
||||
} as any,
|
||||
}
|
||||
validation_rules: [
|
||||
{
|
||||
quorum: 1.0,
|
||||
fields: validation_fields,
|
||||
min_sig_member: 1.0,
|
||||
},
|
||||
],
|
||||
storages: this.storages
|
||||
},
|
||||
};
|
||||
try {
|
||||
@ -531,19 +549,7 @@ export class Service {
|
||||
...wasm.encode_binary(publicSplitData.binaryData)
|
||||
};
|
||||
|
||||
let members: Set<Member> = new Set();
|
||||
for (const role of Object.values(roles!)) {
|
||||
for (const member of role.members) {
|
||||
// Check if we know the member that matches this id
|
||||
const memberAddresses = this.getAddressesForMemberId(member);
|
||||
if (memberAddresses && memberAddresses.length != 0) {
|
||||
members.add({ id: "stub_member", name: "stub_member", public_key: "stub_key", process_id: "stub_process", roles: [] } as any);
|
||||
}
|
||||
}
|
||||
}
|
||||
await this.checkConnections([...members]);
|
||||
|
||||
const result = wasm.create_process (
|
||||
const result = wasm.create_new_process (
|
||||
encodedPrivateData,
|
||||
roles,
|
||||
encodedPublicData,
|
||||
@ -552,7 +558,12 @@ export class Service {
|
||||
this.getAllMembers()
|
||||
);
|
||||
|
||||
return(result);
|
||||
if (result.updated_process) {
|
||||
await this.checkConnections(result.updated_process.current_process);
|
||||
return result;
|
||||
} else {
|
||||
throw new Error('Failed to create new process');
|
||||
}
|
||||
}
|
||||
|
||||
async parseCipher(message: string): Promise<void> {
|
||||
@ -621,6 +632,7 @@ export class Service {
|
||||
}
|
||||
|
||||
const result = wasm.create_update_message(process, stateId, this.membersList);
|
||||
await this.checkConnections(process);
|
||||
return result;
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error || 'Unknown error');
|
||||
@ -639,7 +651,12 @@ export class Service {
|
||||
}
|
||||
|
||||
const result = wasm.validate_state(process, stateId, this.membersList);
|
||||
return result;
|
||||
if (result.updated_process) {
|
||||
await this.checkConnections(result.updated_process.current_process);
|
||||
return result;
|
||||
} else {
|
||||
throw new Error('Failed to validate state');
|
||||
}
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error || 'Unknown error');
|
||||
throw new Error(errorMessage);
|
||||
@ -648,32 +665,46 @@ export class Service {
|
||||
|
||||
// Core protocol method: Update Process
|
||||
async updateProcess(
|
||||
process: any,
|
||||
process: Process,
|
||||
privateData: Record<string, any>,
|
||||
publicData: Record<string, any>,
|
||||
roles: Record<string, any> | null
|
||||
roles: Record<string, RoleDefinition> | null
|
||||
): Promise<ApiReturn> {
|
||||
console.log(`🔄 Updating process ${process.state?.state_id || 'unknown'}`);
|
||||
console.log(`🔄 Updating process ${process.states[0]?.commited_in || 'unknown'}`);
|
||||
console.log('Private data:', privateData);
|
||||
console.log('Public data:', publicData);
|
||||
console.log('Roles:', roles);
|
||||
|
||||
if (!process || !process.states || process.states.length < 2) {
|
||||
throw new Error('Process not found');
|
||||
}
|
||||
|
||||
if (!roles || Object.keys(roles).length === 0) {
|
||||
const state = this.getLastCommitedState(process);
|
||||
if (state) {
|
||||
roles = state.roles;
|
||||
} else {
|
||||
roles = process.states[0]?.roles;
|
||||
}
|
||||
} else {
|
||||
console.log('Roles provided:', roles);
|
||||
}
|
||||
|
||||
const privateSplitData = this.splitData(privateData);
|
||||
const publicSplitData = this.splitData(publicData);
|
||||
const encodedPrivateData = {
|
||||
...wasm.encode_json(privateSplitData.jsonCompatibleData),
|
||||
...wasm.encode_binary(privateSplitData.binaryData)
|
||||
};
|
||||
const encodedPublicData = {
|
||||
...wasm.encode_json(publicSplitData.jsonCompatibleData),
|
||||
...wasm.encode_binary(publicSplitData.binaryData)
|
||||
};
|
||||
|
||||
try {
|
||||
// Convert data to WASM format
|
||||
const newAttributes = wasm.encode_json(privateData);
|
||||
const newPublicData = wasm.encode_json(publicData);
|
||||
const newRoles = roles || process.state?.roles || {};
|
||||
|
||||
// Use WASM function to update process
|
||||
const result = wasm.update_process(process, newAttributes, newRoles, newPublicData, this.membersList);
|
||||
const result = wasm.update_process(process, encodedPrivateData, roles, encodedPublicData, this.membersList);
|
||||
|
||||
if (result.updated_process) {
|
||||
// Update our cache
|
||||
this.processes.set(result.updated_process.process_id, result.updated_process.current_process);
|
||||
|
||||
// Save to database
|
||||
await this.saveProcessToDb(result.updated_process.process_id, result.updated_process.current_process);
|
||||
|
||||
await this.checkConnections(result.updated_process.current_process);
|
||||
return result;
|
||||
} else {
|
||||
throw new Error('Failed to update process');
|
||||
@ -700,7 +731,7 @@ export class Service {
|
||||
const newMyProcesses = new Set<string>();
|
||||
// MyProcesses automatically contains pairing process
|
||||
newMyProcesses.add(pairingProcessId);
|
||||
for (const [processId, process] of Object.entries(this.processes)) {
|
||||
for (const [processId, process] of this.processes.entries()) {
|
||||
try {
|
||||
const roles = this.getRoles(process);
|
||||
|
||||
@ -718,6 +749,47 @@ export class Service {
|
||||
}
|
||||
}
|
||||
|
||||
public async getProcessesData(filteredProcesses: Record<string, Process>): Promise<Record<string, any>> {
|
||||
const data: Record<string, any> = {};
|
||||
// Now we decrypt all we can in the processes
|
||||
for (const [processId, process] of Object.entries(filteredProcesses)) {
|
||||
// We also take the public data
|
||||
let lastState = this.getLastCommitedState(process);
|
||||
if (!lastState) {
|
||||
// fallback on the first state
|
||||
lastState = process.states[0];
|
||||
}
|
||||
const processData: Record<string, any> = {};
|
||||
for (const attribute of Object.keys(lastState.public_data)) {
|
||||
try {
|
||||
const value = this.decodeValue(lastState.public_data[attribute]);
|
||||
if (value !== null && value !== undefined) {
|
||||
processData[attribute] = value;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`❌ Error decoding public data ${attribute} for process ${processId}:`, e);
|
||||
}
|
||||
}
|
||||
for (let i = process.states.length - 2; i >= 0; i--) {
|
||||
const state = process.states[i];
|
||||
for (const attribute of Object.keys(state.keys)) {
|
||||
if (processData[attribute] !== undefined && processData[attribute] !== null) continue;
|
||||
try {
|
||||
const value = await this.decryptAttribute(processId, state, attribute);
|
||||
if (value) {
|
||||
processData[attribute] = value;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`❌ Error decrypting attribute ${attribute} for process ${processId}:`, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
data[processId] = processData;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// Utility method: Get Process
|
||||
async getProcess(processId: string): Promise<any | null> {
|
||||
// First check in-memory cache
|
||||
@ -782,6 +854,25 @@ export class Service {
|
||||
}
|
||||
}
|
||||
|
||||
public async getAllSecretsFromDB(): Promise<SecretsStore> {
|
||||
try {
|
||||
const db = await Database.getInstance();
|
||||
const sharedSecrets: Record<string, string> = await db.dumpStore('shared_secrets');
|
||||
const unconfirmedSecrets = await db.dumpStore('unconfirmed_secrets');
|
||||
const secretsStore = {
|
||||
shared_secrets: sharedSecrets,
|
||||
unconfirmed_secrets: Object.values(unconfirmedSecrets),
|
||||
};
|
||||
return secretsStore;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public loadSecretsInWasm(secretsStore: SecretsStore) {
|
||||
wasm.set_shared_secrets(JSON.stringify(secretsStore));
|
||||
}
|
||||
|
||||
// Utility method: Create a test process
|
||||
async createTestProcess(processId: string): Promise<any> {
|
||||
console.log(`🔧 Creating test process: ${processId}`);
|
||||
@ -795,7 +886,7 @@ export class Service {
|
||||
const feeRate = 1;
|
||||
|
||||
// Use WASM to create new process
|
||||
const result = wasm.create_process('test-device', 'Test Process', 'Test process description');
|
||||
const result = wasm.create_new_process(privateData, roles, publicData, relayAddress, feeRate, this.membersList);
|
||||
|
||||
if (result.updated_process) {
|
||||
const process = result.updated_process.current_process;
|
||||
@ -884,24 +975,28 @@ export class Service {
|
||||
}
|
||||
|
||||
public getLastCommitedState(process: Process): ProcessState | null {
|
||||
return process.state || null;
|
||||
const index = this.getLastCommitedStateIndex(process);
|
||||
if (index === null) return null;
|
||||
return process.states[index];
|
||||
}
|
||||
|
||||
public getLastCommitedStateIndex(process: Process): number | null {
|
||||
// Since state is now a single object, return 0 if it exists, null otherwise
|
||||
return process.state ? 0 : null;
|
||||
}
|
||||
|
||||
public getStateTip(process: Process): any {
|
||||
return process.state?.commited_in || null;
|
||||
if (process.states.length === 0) return null;
|
||||
const processTip = process.states[process.states.length - 1].commited_in;
|
||||
for (let i = process.states.length - 1; i >= 0; i--) {
|
||||
if ((process.states[i] as any).commited_in !== processTip) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public getRoles(process: Process): Record<string, RoleDefinition> | null {
|
||||
const lastCommitedState = this.getLastCommitedState(process);
|
||||
if (lastCommitedState && lastCommitedState.roles && Object.keys(lastCommitedState.roles).length != 0) {
|
||||
return lastCommitedState!.roles;
|
||||
} else if (process.state) {
|
||||
const firstState = process.state;
|
||||
} else if (process.states.length === 2) {
|
||||
const firstState = process.states[0];
|
||||
if (firstState && firstState.roles && Object.keys(firstState.roles).length != 0) {
|
||||
return firstState!.roles;
|
||||
}
|
||||
@ -963,37 +1058,35 @@ export class Service {
|
||||
}
|
||||
|
||||
// Blob and data storage methods
|
||||
async saveBlobToDb(hash: string, data: Blob) {
|
||||
async saveBufferToDb(hash: string, data: Buffer) {
|
||||
const db = await Database.getInstance();
|
||||
try {
|
||||
await db.addObject({
|
||||
storeName: 'data',
|
||||
object: data,
|
||||
key: hash,
|
||||
});
|
||||
}, true);
|
||||
} catch (e) {
|
||||
console.error(`Failed to save data to db: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
async getBlobFromDb(hash: string): Promise<Blob | null> {
|
||||
async getBufferFromDb(hash: string): Promise<Buffer | null> {
|
||||
const db = await Database.getInstance();
|
||||
try {
|
||||
return await db.getObject('data', hash);
|
||||
return await db.getObject('data', hash, true);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async saveDataToStorage(hash: string, data: Blob, ttl: number | null) {
|
||||
console.log('💾 Saving data to storage:', hash);
|
||||
// TODO: Implement actual storage service
|
||||
// const storages = [STORAGEURL];
|
||||
// try {
|
||||
// await storeData(storages, hash, data, ttl);
|
||||
// } catch (e) {
|
||||
// console.error(`Failed to store data with hash ${hash}: ${e}`);
|
||||
// }
|
||||
async saveDataToStorage(hash: string, data: Buffer, ttl: number | null, storageUrls: string[]) {
|
||||
console.log('💾 Saving data', hash, 'to storage', storageUrls);
|
||||
try {
|
||||
await storeData(storageUrls, hash, data, ttl);
|
||||
} catch (e) {
|
||||
console.error(`Failed to store data with hash ${hash}: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
async saveDiffsToDb(diffs: any[]) {
|
||||
@ -1011,6 +1104,11 @@ export class Service {
|
||||
}
|
||||
}
|
||||
|
||||
async getDiffsFromDb(): Promise<Record<string, UserDiff>> {
|
||||
const db = await Database.getInstance();
|
||||
return await db.dumpStore('diffs');
|
||||
}
|
||||
|
||||
// Utility methods for data conversion
|
||||
hexToBlob(hexString: string): Blob {
|
||||
const uint8Array = this.hexToUInt8Array(hexString);
|
||||
@ -1028,6 +1126,10 @@ export class Service {
|
||||
return uint8Array;
|
||||
}
|
||||
|
||||
hexToBuffer(hexString: string): Buffer {
|
||||
return Buffer.from(this.hexToUInt8Array(hexString));
|
||||
}
|
||||
|
||||
public async handleApiReturn(apiReturn: ApiReturn) {
|
||||
// Check for errors in the returned objects
|
||||
if (apiReturn.new_tx_to_send && apiReturn.new_tx_to_send.error) {
|
||||
@ -1092,13 +1194,11 @@ export class Service {
|
||||
|
||||
if (updatedProcess.encrypted_data && Object.keys(updatedProcess.encrypted_data).length != 0) {
|
||||
for (const [hash, cipher] of Object.entries(updatedProcess.encrypted_data)) {
|
||||
if (typeof cipher === 'string') {
|
||||
const blob = this.hexToBlob(cipher);
|
||||
try {
|
||||
await this.saveBlobToDb(hash, blob);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
const buffer = this.hexToBuffer(cipher);
|
||||
try {
|
||||
await this.saveBufferToDb(hash, buffer);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1117,11 +1217,27 @@ export class Service {
|
||||
|
||||
if (apiReturn.push_to_storage && apiReturn.push_to_storage.length != 0) {
|
||||
for (const hash of apiReturn.push_to_storage) {
|
||||
const blob = await this.getBlobFromDb(hash);
|
||||
if (blob) {
|
||||
await this.saveDataToStorage(hash, blob, null);
|
||||
const buffer = await this.getBufferFromDb(hash);
|
||||
if (buffer) {
|
||||
// Look up the storage url for the hash
|
||||
// Find the field for this hash, then look up the roles to see what storage urls are associated
|
||||
let storageUrls = new Set<string>();
|
||||
const diffs = await this.getDiffsFromDb();
|
||||
const diff = Object.values(diffs).find((diff: UserDiff) => diff.value_commitment === hash);
|
||||
if (diff) {
|
||||
for (const role of Object.values(diff.roles)) {
|
||||
for (const rule of Object.values(role.validation_rules)) {
|
||||
if (rule.fields.includes(diff.field)) {
|
||||
for (const storageUrl of role.storages) {
|
||||
storageUrls.add(storageUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
await this.saveDataToStorage(hash, buffer, null, Array.from(storageUrls));
|
||||
} else {
|
||||
console.error('Failed to get data from db');
|
||||
console.error('Failed to get data from db for hash:', hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1155,8 +1271,7 @@ export class Service {
|
||||
}
|
||||
|
||||
private lookForStateId(process: Process, stateId: string): boolean {
|
||||
const state = process.state;
|
||||
if (state) {
|
||||
for (const state of process.states) {
|
||||
if (state.state_id === stateId) {
|
||||
return true;
|
||||
}
|
||||
@ -1169,7 +1284,7 @@ export class Service {
|
||||
console.log('Requesting data from peers');
|
||||
const membersList = this.getAllMembers();
|
||||
try {
|
||||
const res = wasm.request_data(processId, stateIds, Object.keys(roles), membersList);
|
||||
const res = wasm.request_data(processId, stateIds, roles, membersList);
|
||||
await this.handleApiReturn(res);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
@ -1192,13 +1307,11 @@ export class Service {
|
||||
// If we're not supposed to have access to this attribute, ignore
|
||||
for (const role of Object.values(roles)) {
|
||||
for (const rule of Object.values(role.validation_rules)) {
|
||||
if (typeof rule === 'object' && rule !== null && 'fields' in rule && Array.isArray(rule.fields)) {
|
||||
if (rule.fields.includes(attribute)) {
|
||||
if (role.members.includes(pairingProcessId)) {
|
||||
// We have access to this attribute
|
||||
hasAccess = true;
|
||||
break;
|
||||
}
|
||||
if (rule.fields.includes(attribute)) {
|
||||
if (role.members.includes(pairingProcessId)) {
|
||||
// We have access to this attribute
|
||||
hasAccess = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1223,11 +1336,10 @@ export class Service {
|
||||
}
|
||||
|
||||
if (hash && key) {
|
||||
const blob = await this.getBlobFromDb(hash);
|
||||
if (blob) {
|
||||
const buffer = await this.getBufferFromDb(hash);
|
||||
if (buffer) {
|
||||
// Decrypt the data
|
||||
const buf = await blob.arrayBuffer();
|
||||
const cipher = new Uint8Array(buf);
|
||||
const cipher = new Uint8Array(buffer);
|
||||
|
||||
const keyUIntArray = this.hexToUInt8Array(key);
|
||||
|
||||
@ -1236,7 +1348,7 @@ export class Service {
|
||||
if (clear) {
|
||||
// deserialize the result to get the actual data
|
||||
const decoded = wasm.decode_value(clear);
|
||||
return decoded;
|
||||
return this.convertMapsToObjects(decoded);
|
||||
} else {
|
||||
throw new Error('decrypt_data returned null');
|
||||
}
|
||||
@ -1251,13 +1363,49 @@ export class Service {
|
||||
|
||||
decodeValue(value: number[]): any | null {
|
||||
try {
|
||||
return wasm.decode_value(new Uint8Array(value));
|
||||
const decoded = wasm.decode_value(new Uint8Array(value));
|
||||
return this.convertMapsToObjects(decoded);
|
||||
} catch (e) {
|
||||
console.error(`Failed to decode value: ${e}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convertit récursivement les Map en objets sérialisables
|
||||
*/
|
||||
private convertMapsToObjects(obj: any): any {
|
||||
if (obj === null || obj === undefined) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
if (obj instanceof Map) {
|
||||
const result: any = {};
|
||||
for (const [key, value] of obj.entries()) {
|
||||
result[key] = this.convertMapsToObjects(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if (obj instanceof Set) {
|
||||
return Array.from(obj).map(item => this.convertMapsToObjects(item));
|
||||
}
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map(item => this.convertMapsToObjects(item));
|
||||
}
|
||||
|
||||
if (typeof obj === 'object') {
|
||||
const result: any = {};
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
result[key] = this.convertMapsToObjects(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public async updateDevice(): Promise<void> {
|
||||
let myPairingProcessId: string;
|
||||
try {
|
||||
@ -1300,17 +1448,4 @@ export class Service {
|
||||
throw new Error(`Failed to dump device: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
public async getProcessesData(filtered: Record<string, Process>): Promise<any> {
|
||||
// Renvoie un résumé minimal des processus pour compatibilité
|
||||
const result: Record<string, any> = {};
|
||||
for (const [pid, proc] of Object.entries(filtered)) {
|
||||
result[pid] = {
|
||||
id: proc.id,
|
||||
name: proc.name,
|
||||
state_id: proc.state?.state_id ?? null
|
||||
};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -262,31 +262,63 @@ class SimpleProcessHandlers {
|
||||
throw new Error('Invalid message type');
|
||||
}
|
||||
|
||||
const processes = this.service.getProcesses();
|
||||
const myProcesses = await this.service.getMyProcesses();
|
||||
|
||||
if (!myProcesses || myProcesses.length === 0) {
|
||||
throw new Error('No my processes found');
|
||||
if (!this.service.isPaired()) {
|
||||
throw new Error('Device not paired');
|
||||
}
|
||||
|
||||
const filteredProcesses: Record<string, Process> = {};
|
||||
for (const processId of myProcesses) {
|
||||
const process = processes.get(processId);
|
||||
console.log(processId, ':', process);
|
||||
try {
|
||||
const processes = this.service.getProcesses();
|
||||
const myProcesses = await this.service.getMyProcesses();
|
||||
|
||||
if (process) {
|
||||
filteredProcesses[processId] = process;
|
||||
if (!myProcesses || myProcesses.length === 0) {
|
||||
throw new Error('No my processes found');
|
||||
}
|
||||
|
||||
const filteredProcesses: Record<string, Process> = {};
|
||||
for (const processId of myProcesses) {
|
||||
const process = processes.get(processId);
|
||||
|
||||
if (process) {
|
||||
filteredProcesses[processId] = process;
|
||||
} else {
|
||||
console.error(`Process ${processId} not found`); // should not happen
|
||||
}
|
||||
}
|
||||
|
||||
const data = await this.service.getProcessesData(filteredProcesses);
|
||||
|
||||
return {
|
||||
type: MessageType.PROCESSES_RETRIEVED,
|
||||
processes: filteredProcesses,
|
||||
data,
|
||||
messageId: event.data.messageId
|
||||
};
|
||||
} catch (e) {
|
||||
const errorMessage = e instanceof Error ? e.message : String(e || 'Unknown error');
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
async handleGetPairingId(event: ServerMessageEvent): Promise<ServerResponse> {
|
||||
if (event.data.type !== MessageType.GET_PAIRING_ID) {
|
||||
throw new Error('Invalid message type');
|
||||
}
|
||||
|
||||
const data = await this.service.getProcessesData(filteredProcesses);
|
||||
if (!this.service.isPaired()) {
|
||||
throw new Error('Device not paired');
|
||||
}
|
||||
|
||||
return {
|
||||
type: MessageType.PROCESSES_RETRIEVED,
|
||||
processes: filteredProcesses,
|
||||
data,
|
||||
messageId: event.data.messageId
|
||||
};
|
||||
try {
|
||||
const pairingId = this.service.getPairingProcessId();
|
||||
return {
|
||||
type: MessageType.GET_PAIRING_ID,
|
||||
pairingId,
|
||||
messageId: event.data.messageId
|
||||
};
|
||||
} catch (e) {
|
||||
const errorMessage = e instanceof Error ? e.message : String(e || 'Unknown error');
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
async handleMessage(event: ServerMessageEvent): Promise<ServerResponse> {
|
||||
@ -302,6 +334,8 @@ class SimpleProcessHandlers {
|
||||
return await this.handleUpdateProcess(event);
|
||||
case MessageType.GET_MY_PROCESSES:
|
||||
return await this.handleGetMyProcesses(event);
|
||||
case MessageType.GET_PAIRING_ID:
|
||||
return await this.handleGetPairingId(event);
|
||||
default:
|
||||
throw new Error(`Unhandled message type: ${event.data.type}`);
|
||||
}
|
||||
@ -327,7 +361,7 @@ export class Server {
|
||||
console.log('🚀 Initializing Simple 4NK Protocol Server...');
|
||||
|
||||
// Initialize service
|
||||
const service = await Service.getInstance();
|
||||
const service = Service.getInstance();
|
||||
|
||||
// Initialize handlers with API key and service
|
||||
this.handlers = new SimpleProcessHandlers(config.apiKey, service);
|
||||
@ -366,15 +400,14 @@ export class Server {
|
||||
if (!processId || !stateId) {
|
||||
throw new Error('Failed to get process id or state id');
|
||||
}
|
||||
// now pair the device before continuing
|
||||
service.pairDevice(processId, [service.getDeviceAddress()]);
|
||||
await service.handleApiReturn(pairingResult);
|
||||
const udpateResult = await service.createPrdUpdate(processId, stateId);
|
||||
await service.handleApiReturn(udpateResult);
|
||||
const approveResult = await service.approveChange(processId, stateId);
|
||||
await service.handleApiReturn(approveResult);
|
||||
|
||||
// now pair the device
|
||||
service.pairDevice(processId, [service.getDeviceAddress()]);
|
||||
|
||||
// Update the device in the database
|
||||
const device = service.dumpDeviceFromMemory();
|
||||
if (device) {
|
||||
@ -393,6 +426,9 @@ export class Server {
|
||||
|
||||
// Get all processes from database
|
||||
await service.getAllProcessesFromDb();
|
||||
const secretsStore = await service.getAllSecretsFromDB();
|
||||
|
||||
service.loadSecretsInWasm(secretsStore);
|
||||
|
||||
// Connect to relays
|
||||
await service.connectToRelaysAndWaitForHandshake();
|
||||
|
111
src/storage.service.ts
Normal file
111
src/storage.service.ts
Normal file
@ -0,0 +1,111 @@
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
|
||||
export async function storeData(servers: string[], key: string, value: Buffer, ttl: number | null): Promise<AxiosResponse | null> {
|
||||
for (const server of servers) {
|
||||
try {
|
||||
// Use key in the URL path instead of query parameters
|
||||
let url = `${server}/store/${key}`;
|
||||
|
||||
// Add ttl as query parameter if provided
|
||||
if (ttl !== null) {
|
||||
const urlObj = new URL(url);
|
||||
urlObj.searchParams.append('ttl', ttl.toString());
|
||||
url = urlObj.toString();
|
||||
}
|
||||
|
||||
// Send the encrypted ArrayBuffer as the raw request body.
|
||||
const response = await axios.post(url, value, {
|
||||
headers: {
|
||||
'Content-Type': 'application/octet-stream'
|
||||
},
|
||||
});
|
||||
console.log('Data stored successfully:', key);
|
||||
if (response.status !== 200) {
|
||||
console.error('Received response status', response.status);
|
||||
continue;
|
||||
}
|
||||
return response;
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error) && error.response?.status === 409) {
|
||||
return null;
|
||||
}
|
||||
console.error('Error storing data:', error);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function retrieveData(servers: string[], key: string): Promise<ArrayBuffer | null> {
|
||||
for (const server of servers) {
|
||||
try {
|
||||
// Handle relative paths (for development proxy) vs absolute URLs (for production)
|
||||
const url = server.startsWith('/')
|
||||
? `${server}/retrieve/${key}` // Relative path - use as-is for proxy
|
||||
: new URL(`${server}/retrieve/${key}`).toString(); // Absolute URL - construct properly
|
||||
|
||||
console.log('Retrieving data', key,' from:', url);
|
||||
// When fetching the data from the server:
|
||||
const response = await axios.get(url, {
|
||||
responseType: 'arraybuffer'
|
||||
});
|
||||
|
||||
if (response.status === 200) {
|
||||
// Validate that we received an ArrayBuffer
|
||||
if (response.data instanceof ArrayBuffer) {
|
||||
return response.data;
|
||||
} else {
|
||||
console.error('Server returned non-ArrayBuffer data:', typeof response.data);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
console.error(`Server ${server} returned status ${response.status}`);
|
||||
continue;
|
||||
}
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
if (error.response?.status === 404) {
|
||||
console.log(`Data not found on server ${server} for key ${key}`);
|
||||
continue; // Try next server
|
||||
} else if (error.response?.status) {
|
||||
console.error(`Server ${server} error ${error.response.status}:`, error.response.statusText);
|
||||
continue;
|
||||
} else {
|
||||
console.error(`Network error connecting to ${server}:`, error.message);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
console.error(`Unexpected error retrieving data from ${server}:`, error);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
interface TestResponse {
|
||||
key: string;
|
||||
value: boolean;
|
||||
}
|
||||
|
||||
export async function testData(servers: string[], key: string): Promise<Record<string, boolean | null> | null> {
|
||||
const res: Record<string, boolean | null> = {};
|
||||
for (const server of servers) {
|
||||
res[server] = null;
|
||||
try {
|
||||
const response = await axios.get(`${server}/test/${key}`);
|
||||
if (response.status !== 200) {
|
||||
console.error(`${server}: Test response status: ${response.status}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const data: TestResponse = response.data;
|
||||
|
||||
res[server] = data.value;
|
||||
} catch (error) {
|
||||
console.error('Error retrieving data:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
import * as base from '../pkg/sdk_client';
|
||||
|
||||
// Adapteur de compatibilité: expose les anciens noms attendus par service.ts
|
||||
// ATTENTION: Plusieurs fonctions sont des no-op/retours neutres pour permettre la compilation.
|
||||
|
||||
export const init = base.init;
|
||||
|
||||
// Stubs/compat pour fonctions absentes
|
||||
export function get_pairing_process_id(): string {
|
||||
// Pas d'équivalent direct: retourne un ID vide par défaut
|
||||
return '';
|
||||
}
|
||||
|
||||
export function is_paired(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function get_address(): string {
|
||||
// Pas d'équivalent: adresse par défaut
|
||||
return 'default_address';
|
||||
}
|
||||
|
||||
export function encode_json(obj: any): any {
|
||||
// Bypass d’encodage: on renvoie tel quel
|
||||
return obj ?? {};
|
||||
}
|
||||
|
||||
export function encode_binary(obj: any): any {
|
||||
// Bypass d’encodage binaire
|
||||
return {};
|
||||
}
|
||||
|
||||
export function create_process(
|
||||
..._args: any[]
|
||||
): any {
|
||||
// Fallback: utilise create_process minimal si dispo, sinon retour neutre
|
||||
try {
|
||||
// Signature disponible: create_process(device_id, name, description)
|
||||
return base.create_process('device', 'process', '');
|
||||
} catch {
|
||||
return { success: false } as any;
|
||||
}
|
||||
}
|
||||
|
||||
export function create_update_message(..._args: any[]): any {
|
||||
return { success: false } as any;
|
||||
}
|
||||
|
||||
export function validate_state(..._args: any[]): any {
|
||||
return { success: false } as any;
|
||||
}
|
||||
|
||||
export function update_process(..._args: any[]): any {
|
||||
return { success: false } as any;
|
||||
}
|
||||
|
||||
export function parse_cipher(..._args: any[]): any {
|
||||
return { success: false } as any;
|
||||
}
|
||||
|
||||
export function parse_new_tx(..._args: any[]): any {
|
||||
return { success: false } as any;
|
||||
}
|
||||
|
||||
export function sign_transaction(..._args: any[]): any {
|
||||
return { success: false } as any;
|
||||
}
|
||||
|
||||
export function request_data(..._args: any[]): any {
|
||||
return { success: false } as any;
|
||||
}
|
||||
|
||||
export function decrypt_data(..._args: any[]): any {
|
||||
return null as any;
|
||||
}
|
||||
|
||||
export function decode_value(..._args: any[]): any {
|
||||
return null as any;
|
||||
}
|
||||
|
||||
export function unpair_device(): void {
|
||||
// no-op
|
||||
}
|
||||
|
||||
export function pair_device(..._args: any[]): void {
|
||||
// no-op
|
||||
}
|
||||
|
||||
export function restore_device(_device?: any): void {
|
||||
// no-op
|
||||
}
|
||||
|
||||
export function dump_device(): any {
|
||||
// Retourne un device minimal
|
||||
return { id: 'default', name: 'default' };
|
||||
}
|
||||
|
||||
// Ré-export des utilitaires disponibles pour ne pas bloquer d’autres imports
|
||||
export * from '../pkg/sdk_client';
|
14
start.sh
14
start.sh
@ -1,14 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script de démarrage pour sdk_signer
|
||||
echo "🚀 Démarrage de sdk_signer..."
|
||||
|
||||
# Vérifier que les fichiers nécessaires existent
|
||||
if [ ! -f "dist/index.js" ]; then
|
||||
echo "❌ Erreur: dist/index.js non trouvé. Lancement de la compilation..."
|
||||
npm run build
|
||||
fi
|
||||
|
||||
# Démarrer le serveur
|
||||
echo "✅ Démarrage du serveur sdk_signer..."
|
||||
exec node dist/index.js
|
Loading…
x
Reference in New Issue
Block a user