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

Function toViemAccountSecure

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

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 toViemAccountSecure(keyResponse: GetKeyResponse | GetTlsKeyResponse) {
29 // Keep legacy behavior for GetTlsKeyResponse, but with warning.
30 if (keyResponse.__name__ === 'GetTlsKeyResponse') {
31 console.warn('toViemAccountSecure: Please don\'t use `deriveKey` method to get key, use `getKey` instead.')
32 try {
33 // Get supported hash algorithm by `openssl list -digest-algorithms`, but it's not guaranteed to be supported by node.js
34 const hex = crypto.createHash('sha256').update(keyResponse.asUint8Array()).digest('hex')
35 return privateKeyToAccount(`0x${hex}`)
36 } catch (err) {
37 throw new Error('toViemAccountSecure: missing sha256 support, please upgrade your openssl and node.js')
38 }
39 }
40 const hex = Array.from(keyResponse.key).map(b => b.toString(16).padStart(2, '0')).join('')
41 return privateKeyToAccount(`0x${hex}`)
42}

Callers 2

viem.test.tsFile · 0.90
mainFunction · 0.85

Calls 3

digestMethod · 0.45
asUint8ArrayMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected