Source

lib/contract/basic_node_signer.js

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.basicNodeSigner = void 0;
  6. var _stellarBase = require("@stellar/stellar-base");
  7. /**
  8. * For use with {@link Client} and {@link module:contract.AssembledTransaction}.
  9. * Implements `signTransaction` and `signAuthEntry` with signatures expected by
  10. * those classes. This is useful for testing and maybe some simple Node
  11. * applications. Feel free to use this as a starting point for your own
  12. * Wallet/TransactionSigner implementation.
  13. *
  14. * @memberof module:contract
  15. *
  16. * @param {Keypair} keypair {@link Keypair} to use to sign the transaction or auth entry
  17. * @param {string} networkPassphrase passphrase of network to sign for
  18. */
  19. const basicNodeSigner = (keypair, networkPassphrase) => ({
  20. // eslint-disable-next-line require-await
  21. signTransaction: async (xdr, opts) => {
  22. const t = _stellarBase.TransactionBuilder.fromXDR(xdr, opts?.networkPassphrase || networkPassphrase);
  23. t.sign(keypair);
  24. return {
  25. signedTxXdr: t.toXDR(),
  26. signerAddress: keypair.publicKey()
  27. };
  28. },
  29. // eslint-disable-next-line require-await
  30. signAuthEntry: async authEntry => {
  31. const signedAuthEntry = keypair.sign((0, _stellarBase.hash)(Buffer.from(authEntry, "base64"))).toString("base64");
  32. return {
  33. signedAuthEntry,
  34. signerAddress: keypair.publicKey()
  35. };
  36. }
  37. });
  38. exports.basicNodeSigner = basicNodeSigner;