@phala/dstack-sdk
Version:
dstack SDK
46 lines • 2.18 kB
JavaScript
;
// SPDX-FileCopyrightText: © 2025 Phala Network <dstack@phala.network>
//
// SPDX-License-Identifier: Apache-2.0
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(keyResponse) {
// Keep legacy behavior for GetTlsKeyResponse, but with warning.
if (keyResponse.__name__ === 'GetTlsKeyResponse') {
console.warn('toKeypair: Please don\'t use `deriveKey` method to get key, use `getKey` instead.');
// Restored original behavior: using first 32 bytes directly
const bytes = keyResponse.asUint8Array(32);
return web3_js_1.Keypair.fromSeed(bytes);
}
return web3_js_1.Keypair.fromSeed(keyResponse.key);
}
/**
* 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(keyResponse) {
// Keep legacy behavior for GetTlsKeyResponse, but with warning.
if (keyResponse.__name__ === 'GetTlsKeyResponse') {
try {
console.warn('toKeypairSecure: Please don\'t use `deriveKey` method to get key, use `getKey` instead.');
// 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(keyResponse.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');
}
}
return web3_js_1.Keypair.fromSeed(keyResponse.key);
}
//# sourceMappingURL=solana.js.map