feat: near kms integration #464
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NEAR KMS Integration
Start dstack-kms CVM with near-kms that derives KMS root key from NEAR MPC.
1. How KMS Works After NEAR Integration
Architecture Overview
The dstack KMS now supports two blockchain backends for authorization:
Ethereum/Base/Phala KMS (existing)
DstackKms.sol,DstackApp.sol)NEAR KMS (new)
near-dstack-kms,near-dstack-app)NEAR KMS Flow
Bootstrapping (Key Generation)
With MPC (Recommended):
Without MPC (Fallback):
App Key Provisioning
App Contract Deployment
NEAR-specific pattern:
{app_id}.{kms_contract_id}register_app()that:Key Differences from Ethereum
2. What Has Been Implemented in This PR
Core Integration Components
✅ 1. auth-near Webhook Service
Location:
dstack/kms/auth-near/is_kms_allowed,is_app_allowed)✅ 2. KMS Configuration Updates
Files Modified:
dstack/kms/src/config.rs: AddedAuthApi::Nearvariantdstack/kms/src/main_service/upgrade_authority.rs: NEAR auth handlersdstack/kms/kms.toml: NEAR configuration examplesConfiguration:
✅ 3. NEAR Client Module
Location:
dstack/kms/src/near_client.rsget_kms_info(),is_kms_allowed(),view_function()✅ 4. MPC Key Derivation (NEAR-specific)
Location:
dstack/kms/src/mpc_derivation.rs,dstack/kms/src/near_mpc_client.rsFeatures:
blstrscrate)NearMpcClientInMemorySignerKey Derivation Flow:
request_kms_root_key()with TDX attestation✅ 5. Bootstrap Integration
Location:
dstack/kms/src/onboard_service.rs✅ 6. CLI Tools for App Deployment
Location:
dstack/kms/auth-near/cli.tsNew Commands:
bun run app:deploy- Deploy app contract via KMSregister_app()bun run app:add-hash- Add compose hash to app contractbun run app:remove-hash- Remove compose hash from app contractFeatures:
Usage Example:
✅ 7. Docker Compose Integration
File:
dstack/kms/dstack-app/docker-compose.yamlauth-nearservice✅ 8. Documentation Updates
Files Created/Updated:
dstack/kms/auth-near/README.md- Complete usage guide with CLI documentationdstack/kms/README.md- Updated with NEAR KMS integration detailsdstack/kms/NEAR_INTEGRATION_SUMMARY.md- Comprehensive integration summaryImplementation Highlights
Deterministic Key Derivation
Backward Compatibility
Security Features
Files Summary
Created Files
dstack/kms/auth-near/index.ts- Webhook servicedstack/kms/auth-near/cli.ts- CLI tools for app deploymentdstack/kms/auth-near/package.json- Package configurationdstack/kms/auth-near/README.md- Documentationdstack/kms/src/near_client.rs- NEAR RPC clientdstack/kms/src/mpc_derivation.rs- MPC key derivation logicdstack/kms/src/near_mpc_client.rs- NEAR MPC contract clientdstack/kms/src/near_kms_client.rs- NEAR KMS contract clientModified Files
dstack/kms/src/config.rs- Added NEAR auth API configurationdstack/kms/src/onboard_service.rs- Added MPC key derivationdstack/kms/src/main_service/upgrade_authority.rs- NEAR auth handlersdstack/kms/src/main.rs- Added NEAR client modulesdstack/kms/Cargo.toml- Added BLS12-381 and NEAR dependenciesdstack/kms/kms.toml- Added NEAR configuration examplesdstack/kms/dstack-app/docker-compose.yaml- Added auth-near servicedstack/kms/README.md- Updated with NEAR integrationTesting Status
Next Steps
Summary
This PR adds complete NEAR Protocol support to dstack KMS, enabling: