Skip to content

Commit 85ace8b

Browse files
authored
Merge pull request #292 from Dstack-TEE/feat-sdk-python
Update dstack python SDK.
2 parents c7fa72d + 0f4a92a commit 85ace8b

26 files changed

+5111
-1148
lines changed

sdk/js/test-outputs.js

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#!/usr/bin/env node
2+
// SPDX-FileCopyrightText: © 2025 Phala Network <dstack@phala.network>
3+
//
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
const { DstackClient, TappdClient, getComposeHash, verifyEnvEncryptPublicKey } = require('./dist/node/index.js');
7+
const { toViemAccount, toViemAccountSecure } = require('./dist/node/viem.js');
8+
const { toKeypair, toKeypairSecure } = require('./dist/node/solana.js');
9+
10+
async function main() {
11+
console.log("=== JS SDK Output Test ===");
12+
13+
try {
14+
// Test client get_key
15+
const client = new DstackClient();
16+
console.log("\n1. Testing DstackClient.getKey()");
17+
18+
const testPaths = [
19+
{ path: "test/wallet", purpose: "ethereum" },
20+
{ path: "test/signing", purpose: "solana" },
21+
{ path: "user/alice", purpose: "mainnet" }
22+
];
23+
24+
for (const { path, purpose } of testPaths) {
25+
const keyResult = await client.getKey(path, purpose);
26+
console.log(`getKey('${path}', '${purpose}'):`);
27+
console.log(` key: ${Buffer.from(keyResult.key).toString('hex')}`);
28+
console.log(` signature_chain length: ${keyResult.signature_chain.length}`);
29+
console.log(` signature_chain[0]: ${Buffer.from(keyResult.signature_chain[0]).toString('hex')}`);
30+
}
31+
32+
// Test viem integration
33+
console.log("\n2. Testing Viem Integration");
34+
const ethKey = await client.getKey("eth/test", "wallet");
35+
36+
console.log("\n2.1 toViemAccount (legacy):");
37+
try {
38+
const account = toViemAccount(ethKey);
39+
console.log(` address: ${account.address}`);
40+
console.log(` type: ${account.type}`);
41+
} catch (error) {
42+
console.log(` error: ${error.message}`);
43+
}
44+
45+
console.log("\n2.2 toViemAccountSecure:");
46+
try {
47+
const accountSecure = toViemAccountSecure(ethKey);
48+
console.log(` address: ${accountSecure.address}`);
49+
console.log(` type: ${accountSecure.type}`);
50+
} catch (error) {
51+
console.log(` error: ${error.message}`);
52+
}
53+
54+
// Test solana integration
55+
console.log("\n3. Testing Solana Integration");
56+
const solKey = await client.getKey("sol/test", "wallet");
57+
58+
console.log("\n3.1 toKeypair (legacy):");
59+
try {
60+
const keypair = toKeypair(solKey);
61+
console.log(` publicKey: ${keypair.publicKey.toString()}`);
62+
console.log(` secretKey length: ${keypair.secretKey.length}`);
63+
console.log(` secretKey (first 32 bytes): ${Buffer.from(keypair.secretKey.slice(0, 32)).toString('hex')}`);
64+
} catch (error) {
65+
console.log(` error: ${error.message}`);
66+
}
67+
68+
console.log("\n3.2 toKeypairSecure:");
69+
try {
70+
const keypairSecure = toKeypairSecure(solKey);
71+
console.log(` publicKey: ${keypairSecure.publicKey.toString()}`);
72+
console.log(` secretKey length: ${keypairSecure.secretKey.length}`);
73+
console.log(` secretKey (first 32 bytes): ${Buffer.from(keypairSecure.secretKey.slice(0, 32)).toString('hex')}`);
74+
} catch (error) {
75+
console.log(` error: ${error.message}`);
76+
}
77+
78+
// Test TappdClient (deprecated)
79+
console.log("\n4. Testing TappdClient (deprecated)");
80+
try {
81+
const tappdClient = new TappdClient();
82+
console.log("\n4.1 TappdClient.getKey():");
83+
const tappdKey = await tappdClient.getKey("test/wallet", "ethereum");
84+
console.log(` key: ${Buffer.from(tappdKey.key).toString('hex')}`);
85+
console.log(` signature_chain length: ${tappdKey.signature_chain.length}`);
86+
87+
console.log("\n4.2 TappdClient.tdxQuote():");
88+
const tappdQuote = await tappdClient.tdxQuote("test-data", "raw");
89+
console.log(` quote length: ${tappdQuote.quote.length}`);
90+
console.log(` event_log length: ${tappdQuote.event_log.length}`);
91+
console.log(` rtmrs count: ${tappdQuote.replayRtmrs().length}`);
92+
} catch (error) {
93+
console.log(` error: ${error.message}`);
94+
}
95+
96+
// Test quotes
97+
console.log("\n5. Testing Quote Methods");
98+
console.log("\n5.1 DstackClient.getQuote():");
99+
const dstackQuote = await client.getQuote("test-data-for-quote");
100+
console.log(` quote length: ${dstackQuote.quote.length}`);
101+
console.log(` event_log length: ${dstackQuote.event_log.length}`);
102+
console.log(` rtmrs count: ${dstackQuote.replayRtmrs().length}`);
103+
104+
// Test getComposeHash
105+
console.log("\n6. Testing getComposeHash");
106+
const testComposes = [
107+
{
108+
manifest_version: 1,
109+
name: "test-app",
110+
runner: "docker-compose",
111+
docker_compose_file: "services:\\n app:\\n image: test\\n ports:\\n - 8080:8080"
112+
},
113+
{
114+
manifest_version: 1,
115+
name: "another-app",
116+
runner: "docker-compose",
117+
docker_compose_file: "services:\\n web:\\n build: .\\n environment:\\n - NODE_ENV=production"
118+
}
119+
];
120+
121+
testComposes.forEach((compose, index) => {
122+
const hash = getComposeHash(compose);
123+
console.log(`compose ${index + 1}: ${hash}`);
124+
console.log(` name: ${compose.name}`);
125+
console.log(` runner: ${compose.runner}`);
126+
});
127+
128+
// Test verifyEnvEncryptPublicKey
129+
console.log("\n7. Testing verifyEnvEncryptPublicKey");
130+
const testCases = [
131+
{
132+
publicKey: Buffer.from('e33a1832c6562067ff8f844a61e51ad051f1180b66ec2551fb0251735f3ee90a', 'hex'),
133+
signature: Buffer.from('8542c49081fbf4e03f62034f13fbf70630bdf256a53032e38465a27c36fd6bed7a5e7111652004aef37f7fd92fbfc1285212c4ae6a6154203a48f5e16cad2cef00', 'hex'),
134+
appId: '0000000000000000000000000000000000000000'
135+
},
136+
{
137+
publicKey: Buffer.from('deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef', 'hex'),
138+
signature: Buffer.from('0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 'hex'),
139+
appId: 'invalid-app-id'
140+
}
141+
];
142+
143+
testCases.forEach((testCase, index) => {
144+
try {
145+
const result = verifyEnvEncryptPublicKey(testCase.publicKey, testCase.signature, testCase.appId);
146+
console.log(`test case ${index + 1}: ${result ? Buffer.from(result).toString('hex') : 'null'}`);
147+
} catch (error) {
148+
console.log(`test case ${index + 1}: error - ${error.message}`);
149+
}
150+
});
151+
152+
} catch (error) {
153+
console.error("Error:", error.message);
154+
process.exit(1);
155+
}
156+
}
157+
158+
main().catch(console.error);

sdk/python/Makefile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# SPDX-FileCopyrightText: © 2025 Phala Network <dstack@phala.network>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
.PHONY: install lint format type-check type-check-tests test check-all verify
6+
7+
# Install dependencies including linting tools
8+
install:
9+
pdm install -G lint
10+
11+
# Run all formatters (using PDM scripts)
12+
format:
13+
pdm run fmt
14+
15+
# Alias for format
16+
fmt: format
17+
18+
# Run linting tools (using PDM scripts)
19+
lint:
20+
pdm run lint
21+
22+
# Run type checking only
23+
type-check:
24+
pdm run mypy src/
25+
26+
# Run type checking on tests specifically
27+
type-check-tests:
28+
pdm run mypy tests/test_mypy_check.py tests/test_typing.py
29+
30+
# Run tests
31+
test:
32+
@if [ -z "$$DSTACK_SIMULATOR_ENDPOINT" ]; then \
33+
echo "error: DSTACK_SIMULATOR_ENDPOINT environment variable is not set"; \
34+
exit 1; \
35+
fi
36+
@if [ -z "$$TAPPD_SIMULATOR_ENDPOINT" ]; then \
37+
echo "error: TAPPD_SIMULATOR_ENDPOINT environment variable is not set"; \
38+
exit 1; \
39+
fi
40+
@if [[ "$$DSTACK_SIMULATOR_ENDPOINT" == /* ]] && [ ! -e "$$DSTACK_SIMULATOR_ENDPOINT" ]; then \
41+
echo "error: dstack socket file $$DSTACK_SIMULATOR_ENDPOINT does not exist"; \
42+
exit 1; \
43+
fi
44+
@if [[ "$$TAPPD_SIMULATOR_ENDPOINT" == /* ]] && [ ! -e "$$TAPPD_SIMULATOR_ENDPOINT" ]; then \
45+
echo "error: tappd socket file $$TAPPD_SIMULATOR_ENDPOINT does not exist"; \
46+
exit 1; \
47+
fi
48+
pdm run test
49+
50+
# Run all checks (format, lint, skip test)
51+
check-all:
52+
pdm run fmt
53+
pdm run lint
54+
55+
# Check code without fixing (for CI)
56+
check:
57+
pdm run check
58+
59+
# Run verification without formatting (skip test)
60+
verify:
61+
pdm run check

0 commit comments

Comments
 (0)