import { HDWallet } from "@tonsprotocol/hdwallet";
new HDWallet()
import { HDWallet } from "@tonsprotocol/hdwallet";
new HDWallet(
{
pwd:"helloworld", // Optional
path:123, //Optional . default 1
}
)
interface objKP {
naclKp: {
publicKey: Uint8Array;
secretKey: Uint8Array;
};
evmKp: {
address: string;
privateKey: string;
};
solKp: {
address: string;
privateKey: string;
};
tonKp: any;
}
HDWallet.fromPrivateKey(
{
sk:"2Lte2V623NW7pafsAbpzGTQQ8y6Kbnzwop39RyybkPFessboN92d2pUfZi4Xi8KkFccqmC1zyRZ6wfRY2EKgqDu6",
pwd:"1234",
path:16
}
)
HDWallet.fromPrivateKey(
{
sk:"2dnv6i5vLQFRFFQKpyVhxvijQHE7orgReQJVJ12PboKw",
}
)
You can check the source code for details .
private fromPk(sec:string,path:number,pwd?:string) {
let rawKey : Buffer;
if(pwd)
{
rawKey = Buffer.from(bs58.decode(
decryptByDES(sec,pwd)
))
}else{
rawKey = Buffer.from(
bs58.decode(sec)
);
}
const master = hd.hdkey.fromMasterSeed(
Buffer.from(
bs58.decode(sec))
)
;
const derive = master.deriveChild(path);
const evmWallet = derive.getWallet();
const naclKp = nacl.sign.keyPair.fromSeed(
Uint8Array.from(evmWallet.getPrivateKey())
);
return {
naclKp: naclKp,
evmKp: {
address: evmWallet.getAddressString(),
privateKey: evmWallet.getPrivateKeyString(),
},
solKp: {
address: bs58.encode(naclKp.publicKey),
privateKey: bs58.encode(naclKp.secretKey),
},
tonKp: ton.getTonWalletV4KeyPair(Buffer.from(naclKp.secretKey), 0),
} as objKP;
}