UNPKG

@phala/dstack-sdk

Version:

DStack SDK

34 lines 1.7 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.toViemAccount = toViemAccount; exports.toViemAccountSecure = toViemAccountSecure; const crypto_1 = __importDefault(require("crypto")); const accounts_1 = require("viem/accounts"); /** * @deprecated use toViemAccountSecure instead. This method has security concerns. * Current implementation uses raw key material without proper hashing. */ function toViemAccount(deriveKeyResponse) { console.warn('[DEPRECATED] toViemAccount: this method has security concerns. Please use toViemAccountSecure instead.'); // Restored original behavior: using first 32 bytes directly const hex = Array.from(deriveKeyResponse.asUint8Array(32)).map(b => b.toString(16).padStart(2, '0')).join(''); return (0, accounts_1.privateKeyToAccount)(`0x${hex}`); } /** * Creates a Viem account from DeriveKeyResponse using secure key derivation. * This method applies SHA256 hashing to the complete key material for enhanced security. */ function toViemAccountSecure(deriveKeyResponse) { try { // Get supported hash algorithm by `openssl list -digest-algorithms`, but it's not guaranteed to be supported by node.js const hex = crypto_1.default.createHash('sha256').update(deriveKeyResponse.asUint8Array()).digest('hex'); return (0, accounts_1.privateKeyToAccount)(`0x${hex}`); } catch (err) { throw new Error('toViemAccountSecure: missing sha256 support, please upgrade your openssl and node.js'); } } //# sourceMappingURL=viem.js.map