(keyResponse: GetTlsKeyResponse | GetKeyResponse)
| 26 | * This method applies SHA256 hashing to the complete key material for enhanced security. |
| 27 | */ |
| 28 | export 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 | } |
no test coverage detected