@wormhole-foundation/sdk-sui
Version:
SDK for Sui chains, used in conjunction with @wormhole-foundation/sdk
60 lines • 2.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SuiSigner = exports.getSuiSigner = void 0;
const ed25519_1 = require("@mysten/sui/keypairs/ed25519");
const platform_js_1 = require("./platform.js");
async function getSuiSigner(rpc, privateKey) {
const [, chain] = await platform_js_1.SuiPlatform.chainFromRpc(rpc);
return new SuiSigner(chain, rpc, ed25519_1.Ed25519Keypair.deriveKeypair(privateKey, "m/44'/784'/0'/0'/0'"));
}
exports.getSuiSigner = getSuiSigner;
// SuiSigner implements SignOnlySender
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;
}
}
exports.SuiSigner = SuiSigner;
//# sourceMappingURL=signer.js.map