UNPKG

@phala/dstack-sdk

Version:
23 lines (20 loc) 810 B
import { sha256 } from '@noble/hashes/sha256'; import { Keypair } from '@solana/web3.js'; // src/solana.ts function toKeypair(keyResponse) { if (keyResponse.__name__ === "GetTlsKeyResponse") { console.warn("toKeypair: Please don't use `deriveKey` method to get key, use `getKey` instead."); const bytes = keyResponse.asUint8Array(32); return Keypair.fromSeed(bytes); } return Keypair.fromSeed(keyResponse.key); } function toKeypairSecure(keyResponse) { if (keyResponse.__name__ === "GetTlsKeyResponse") { console.warn("toKeypairSecure: Please don't use `deriveKey` method to get key, use `getKey` instead."); const buf = sha256(keyResponse.asUint8Array()); return Keypair.fromSeed(buf); } return Keypair.fromSeed(keyResponse.key); } export { toKeypair, toKeypairSecure };