Skip to content

feat: transient storage, PII encryption, k6 load testing, webhook signatures#486

Open
shaaibu7 wants to merge 4 commits into
Smartdevs17:mainfrom
shaaibu7:feat/subtrackr-enhancements
Open

feat: transient storage, PII encryption, k6 load testing, webhook signatures#486
shaaibu7 wants to merge 4 commits into
Smartdevs17:mainfrom
shaaibu7:feat/subtrackr-enhancements

Conversation

@shaaibu7
Copy link
Copy Markdown
Contributor

Summary

Implements four issues across the Soroban contracts, the React Native app, and CI tooling.

Closes #174
Closes #436
Closes #192
Closes #177


1. Transient storage refactor (gas optimization)

Moves short-lived contract state out of persistent/instance storage into auto-expiring transient (temporary) storage:

  • charge_subscription: transient TmpChargeNonce guard (1-ledger TTL) preventing a duplicate charge within the same ledger close (charge state machine state).
  • request_transfer/accept_transfer: pending transfer offers now use TmpPendingTransfer (7-day TTL) instead of instance storage, so unaccepted offers auto-expire and stop accruing rent (pending operations + temporary authorization).
  • preview_proration: previewed amount cached in TmpProrationScratch (intermediate calculation).
  • New contracts/subscription/STORAGE.md documenting storage-type selection criteria, access-pattern analysis, data-consistency rules and gas benchmarking.

2. PII encryption at rest (GDPR)

  • New contracts/security Soroban contract: hash-CTR stream cipher (SHA-256 keystream) with encrypt-and-MAC integrity, encrypt_data/decrypt_data, versioned keys with rotate_key (old versions retained for decryption), access-control list, and export_encrypted for data export.
  • New app/services/encryptionService.ts mirroring the contract algorithm (pure-JS SHA-256), with a PII field registry, record-level encrypt/decrypt, versioned key store, rotation, and a pluggable access controller.
  • contracts/security/README.md covering algorithm, key management, rotation, access control and edge cases (key loss, performance).

3. k6 load testing

  • Per-endpoint custom metrics (latency/errors/requests, tagged) for bottleneck attribution.
  • Report generation (reports/summary.{json,md,html} + stdout) with a slowest-first per-endpoint breakdown.
  • Performance baseline (baseline.json) + regression comparison embedded in the report.
  • Per-endpoint latency/error thresholds in config/options.js (CI gate).
  • Contract load scenario; CI load-test job now runs a scenario matrix (subscription/billing/contract), fails on threshold breach, and uploads the report as an artifact.
  • npm scripts per scenario; SCALABILITY.md bottleneck guide and load-tests/README.md.

4. Webhook delivery signatures

The webhook contract module, store (src/store/webhookStore.ts) and management UI (src/screens/WebhookSettingsScreen.tsx, wired into AppNavigator) already existed; the unmet criterion was signature verification, which was a hardcoded 'sample-signature'.

  • New src/utils/webhookSignature.ts: pure-JS HMAC-SHA256 signing/verification (sha256=<hex> convention), constant-time verify, payload serialization, secret generation.
  • Deliveries are now signed with the webhook secret; a signing secret is auto-generated at registration when none is supplied.

Notes

  • Per request, tests were not added in this PR.
  • The subscription crate has pre-existing compile errors (undeclared modules revenue/proration/etc.) unrelated to these changes; the transient-storage changes add no new errors and the types/security crates compile cleanly.

shaaibu7 added 4 commits May 31, 2026 15:52
…e & proration

Move short-lived contract state out of persistent/instance storage into
auto-expiring transient (temporary) storage for gas optimization:

- charge_subscription: add a transient TmpChargeNonce guard (1-ledger TTL)
  that prevents a duplicate charge within the same ledger close
- request_transfer/accept_transfer: pending transfer offers now use
  TmpPendingTransfer transient storage with a 7-day TTL instead of
  instance storage, so unaccepted offers auto-expire and stop accruing rent
- preview_proration: cache the previewed prorated amount in
  TmpProrationScratch (TTL = one billing interval) as intermediate state
- types: append TmpPendingTransfer storage key (version 7)
- document storage-type selection criteria, access-pattern analysis,
  data-consistency rules and gas benchmarking in contracts/subscription/STORAGE.md
Add a new subtrackr-security Soroban contract plus a matching client service
that encrypt subscriber PII, with interoperable ciphertext formats.

Contract (contracts/security):
- hash-CTR stream cipher (SHA-256 keystream) with encrypt-and-MAC integrity,
  since Soroban exposes no native symmetric cipher
- encrypt_data / decrypt_data with self-describing EncryptedData envelope
  (key version + per-record nonce + MAC)
- versioned keys with rotate_key: old versions retained for decrypting
  historical records, deactivated for new encryptions
- access-control list (grant_access/revoke_access/is_authorized) gating
  both encryption and decryption; admin implicitly authorized
- export_encrypted re-encrypts records under the current key for data export
- registered in the contracts workspace

Client (app/services/encryptionService.ts):
- mirrors the contract algorithm (pure-JS SHA-256) so formats interoperate
- PII_FIELDS registry, record-level encrypt/decrypt helpers
- versioned key store (AsyncStorage) with rotation, pluggable AccessController
- exportEncrypted for GDPR data export

Docs: contracts/security/README.md covering algorithm, key management,
rotation, access control and edge cases (key loss, performance).
… CI matrix

Build out automated load testing on top of the existing k6 scenarios:

- Per-endpoint custom metrics (endpoint_latency/errors/requests, tagged) so
  reports attribute latency and errors to a specific operation
- Report generation (utils/summary.js handleSummary): writes
  reports/summary.{json,md,html} plus a stdout summary with a slowest-first
  per-endpoint breakdown for bottleneck identification
- Performance baseline (baseline.json) + comparison (utils/baseline.js) that
  flags metrics exceeding baseline beyond a tolerance, embedded in the report
- Per-endpoint latency + error thresholds in config/options.js (CI gate)
- contract load scenario wired into run.js (execute_payment + charge_subscription)
- CI load-test job runs a scenario matrix (subscription/billing/contract),
  fails on threshold breach, and uploads the report as an artifact
- npm scripts per scenario; SCALABILITY.md bottleneck guide; load-tests/README.md
- gitignore generated reports but keep the directory
The webhook contract module, RN management UI (src/screens/WebhookSettingsScreen,
wired into AppNavigator) and store (src/store/webhookStore) already exist; the
one unmet acceptance criterion was signature verification for security, which
was stubbed as a hardcoded 'sample-signature'.

- add src/utils/webhookSignature.ts: pure-JS HMAC-SHA256 signing/verification
  (sha256=<hex> convention, à la Stripe/GitHub), constant-time verify, payload
  serialization, and secret generation
- sign each delivery payload with the webhook secret in sendTestEvent instead
  of the placeholder signature
- auto-generate a signing secret at registration when none is supplied, so
  every webhook's deliveries are verifiable

Note: the issue listed app/stores/webhookStore.ts and
app/screens/WebhookSettingsScreen.tsx, but the feature is already implemented
under src/; enhanced the existing wired implementation rather than adding
unwired duplicates.
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 31, 2026

@shaaibu7 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant