@wormhole-foundation/sdk-sui
Version:
SDK for Sui chains, used in conjunction with @wormhole-foundation/sdk
55 lines • 2.03 kB
JavaScript
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
import { SuiPlatform } from "./platform.js";
export async function getSuiSigner(rpc, privateKey) {
const [, chain] = await SuiPlatform.chainFromRpc(rpc);
return new SuiSigner(chain, rpc, Ed25519Keypair.deriveKeypair(privateKey, "m/44'/784'/0'/0'/0'"));
}
// SuiSigner implements SignOnlySender
export class SuiSigner {
_chain;
_client;
_signer;
_debug;
constructor(_chain, _client, _signer, _debug) {
this._chain = _chain;
this._client = _client;
this._signer = _signer;
this._debug = _debug;
}
chain() {
return this._chain;
}
address() {
return this._signer.toSuiAddress();
}
async signAndSend(txns) {
const txids = [];
for (const tx of txns) {
const { description, transaction } = tx;
if (this._debug)
console.log(`Signing ${description} for ${this.address()}`);
try {
const result = await this._client.signAndExecuteTransaction({
transaction,
signer: this._signer,
});
txids.push(result.digest);
}
catch (e) {
// If the transaction fails on Sui, its often in a dryrun, but im currently
// too lazy to write a typeguard to make this safe
//const stuff = (e as Error).cause as DryRunTransactionBlockResponse;
//const { input, effects } = stuff;
//if (input.transaction.kind === "ProgrammableTransaction") {
// console.error("ProgrammableTransaction");
// console.error("Txs\n", input.transaction.transactions);
// console.error("Inputs\n", input.transaction.inputs);
//}
//console.error("Effects\n", effects);
throw e;
}
}
return txids;
}
}
//# sourceMappingURL=signer.js.map