@phala/dstack-sdk
Version:
DStack SDK
34 lines • 1.57 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.toKeypair = toKeypair;
exports.toKeypairSecure = toKeypairSecure;
const crypto_1 = __importDefault(require("crypto"));
const web3_js_1 = require("@solana/web3.js");
/**
* @deprecated use toKeypairSecure instead. This method has security concerns.
* Current implementation uses raw key material without proper hashing.
*/
function toKeypair(deriveKeyResponse) {
console.warn('[DEPRECATED] toKeypair: this method has security concerns. Please use toKeypairSecure instead.');
// Restored original behavior: using first 32 bytes directly
const bytes = deriveKeyResponse.asUint8Array(32);
return web3_js_1.Keypair.fromSeed(bytes);
}
/**
* Creates a Solana Keypair from DeriveKeyResponse using secure key derivation.
* This method applies SHA256 hashing to the complete key material for enhanced security.
*/
function toKeypairSecure(deriveKeyResponse) {
try {
// Get supported hash algorithm by `openssl list -digest-algorithms`, but it's not guaranteed to be supported by node.js
const buf = crypto_1.default.createHash('sha256').update(deriveKeyResponse.asUint8Array()).digest();
return web3_js_1.Keypair.fromSeed(buf);
}
catch (err) {
throw new Error('toKeypairSecure: missing sha256 support, please upgrade your openssl and node.js');
}
}
//# sourceMappingURL=solana.js.map