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