MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / toKeypairSecure

Function toKeypairSecure

sdk/js/src/solana.ts:28–41  ·  view source on GitHub ↗
(keyResponse: GetTlsKeyResponse | GetKeyResponse)

Source from the content-addressed store, hash-verified

26 * This method applies SHA256 hashing to the complete key material for enhanced security.
27 */
28export function toKeypairSecure(keyResponse: GetTlsKeyResponse | GetKeyResponse) {
29 // Keep legacy behavior for GetTlsKeyResponse, but with warning.
30 if (keyResponse.__name__ === 'GetTlsKeyResponse') {
31 try {
32 console.warn('toKeypairSecure: Please don\'t use `deriveKey` method to get key, use `getKey` instead.')
33 // Get supported hash algorithm by `openssl list -digest-algorithms`, but it's not guaranteed to be supported by node.js
34 const buf = crypto.createHash('sha256').update(keyResponse.asUint8Array()).digest()
35 return Keypair.fromSeed(buf)
36 } catch (err) {
37 throw new Error('toKeypairSecure: missing sha256 support, please upgrade your openssl and node.js')
38 }
39 }
40 return Keypair.fromSeed(keyResponse.key)
41}

Callers 2

solana.test.tsFile · 0.90
mainFunction · 0.85

Calls 2

digestMethod · 0.45
asUint8ArrayMethod · 0.45

Tested by

no test coverage detected