Source

lib/contract/basic_node_signer.js

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.basicNodeSigner = void 0;
var _stellarBase = require("@stellar/stellar-base");
/**
 * For use with {@link Client} and {@link module:contract.AssembledTransaction}.
 * Implements `signTransaction` and `signAuthEntry` with signatures expected by
 * those classes. This is useful for testing and maybe some simple Node
 * applications. Feel free to use this as a starting point for your own
 * Wallet/TransactionSigner implementation.
 *
 * @memberof module:contract
 *
 * @param {Keypair} keypair {@link Keypair} to use to sign the transaction or auth entry
 * @param {string} networkPassphrase passphrase of network to sign for
 */
const basicNodeSigner = (keypair, networkPassphrase) => ({
  // eslint-disable-next-line require-await
  signTransaction: async (xdr, opts) => {
    const t = _stellarBase.TransactionBuilder.fromXDR(xdr, opts?.networkPassphrase || networkPassphrase);
    t.sign(keypair);
    return {
      signedTxXdr: t.toXDR(),
      signerAddress: keypair.publicKey()
    };
  },
  // eslint-disable-next-line require-await
  signAuthEntry: async authEntry => {
    const signedAuthEntry = keypair.sign((0, _stellarBase.hash)(Buffer.from(authEntry, "base64"))).toString("base64");
    return {
      signedAuthEntry,
      signerAddress: keypair.publicKey()
    };
  }
});
exports.basicNodeSigner = basicNodeSigner;