lib/contract_client/basic_node_signer.js

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.basicNodeSigner = void 0;
var _ = require("..");
/**
 * For use with {@link ContractClient} and {@link 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.
 */
const basicNodeSigner = (keypair, networkPassphrase) => ({
  signTransaction: async tx => {
    const t = _.TransactionBuilder.fromXDR(tx, networkPassphrase);
    t.sign(keypair);
    return t.toXDR();
  },
  signAuthEntry: async entryXdr => {
    return keypair.sign((0, _.hash)(Buffer.from(entryXdr, "base64"))).toString('base64');
  }
});
exports.basicNodeSigner = basicNodeSigner;