@stellar/stellar-sdk 14.4.3 → 14.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/README.md +150 -0
  2. package/bin/stellar-js +4 -0
  3. package/dist/stellar-sdk-minimal.js +11450 -10315
  4. package/dist/stellar-sdk-minimal.min.js +1 -1
  5. package/dist/stellar-sdk-no-axios.js +7459 -6324
  6. package/dist/stellar-sdk-no-axios.min.js +1 -1
  7. package/dist/stellar-sdk-no-eventsource.js +11597 -10483
  8. package/dist/stellar-sdk-no-eventsource.min.js +1 -1
  9. package/dist/stellar-sdk.js +10647 -9533
  10. package/dist/stellar-sdk.min.js +1 -1
  11. package/lib/bindings/client.d.ts +30 -0
  12. package/lib/bindings/client.js +134 -0
  13. package/lib/bindings/config.d.ts +34 -0
  14. package/lib/bindings/config.js +83 -0
  15. package/lib/bindings/generator.d.ts +176 -0
  16. package/lib/bindings/generator.js +131 -0
  17. package/lib/bindings/index.d.ts +6 -0
  18. package/lib/bindings/index.js +75 -0
  19. package/lib/bindings/sac-spec.d.ts +1 -0
  20. package/lib/bindings/sac-spec.js +7 -0
  21. package/lib/bindings/types.d.ts +66 -0
  22. package/lib/bindings/types.js +184 -0
  23. package/lib/bindings/utils.d.ts +49 -0
  24. package/lib/bindings/utils.js +223 -0
  25. package/lib/bindings/wasm_fetcher.d.ts +25 -0
  26. package/lib/bindings/wasm_fetcher.js +225 -0
  27. package/lib/cli/index.d.ts +2 -0
  28. package/lib/cli/index.js +171 -0
  29. package/lib/cli/util.d.ts +55 -0
  30. package/lib/cli/util.js +254 -0
  31. package/lib/contract/client.js +2 -1
  32. package/lib/horizon/call_builder.js +30 -6
  33. package/lib/horizon/horizon_axios_client.js +1 -1
  34. package/lib/index.d.ts +1 -0
  35. package/lib/index.js +9 -1
  36. package/lib/minimal/bindings/client.d.ts +30 -0
  37. package/lib/minimal/bindings/client.js +134 -0
  38. package/lib/minimal/bindings/config.d.ts +34 -0
  39. package/lib/minimal/bindings/config.js +83 -0
  40. package/lib/minimal/bindings/generator.d.ts +176 -0
  41. package/lib/minimal/bindings/generator.js +131 -0
  42. package/lib/minimal/bindings/index.d.ts +6 -0
  43. package/lib/minimal/bindings/index.js +75 -0
  44. package/lib/minimal/bindings/sac-spec.d.ts +1 -0
  45. package/lib/minimal/bindings/sac-spec.js +7 -0
  46. package/lib/minimal/bindings/types.d.ts +66 -0
  47. package/lib/minimal/bindings/types.js +184 -0
  48. package/lib/minimal/bindings/utils.d.ts +49 -0
  49. package/lib/minimal/bindings/utils.js +223 -0
  50. package/lib/minimal/bindings/wasm_fetcher.d.ts +25 -0
  51. package/lib/minimal/bindings/wasm_fetcher.js +225 -0
  52. package/lib/minimal/cli/index.d.ts +2 -0
  53. package/lib/minimal/cli/index.js +171 -0
  54. package/lib/minimal/cli/util.d.ts +55 -0
  55. package/lib/minimal/cli/util.js +254 -0
  56. package/lib/minimal/contract/client.js +2 -1
  57. package/lib/minimal/horizon/call_builder.js +30 -6
  58. package/lib/minimal/horizon/horizon_axios_client.js +1 -1
  59. package/lib/minimal/index.d.ts +1 -0
  60. package/lib/minimal/index.js +9 -1
  61. package/lib/minimal/rpc/axios.js +1 -1
  62. package/lib/minimal/rpc/server.d.ts +35 -1
  63. package/lib/minimal/rpc/server.js +110 -43
  64. package/lib/minimal/stellartoml/index.d.ts +3 -0
  65. package/lib/no-axios/bindings/client.d.ts +30 -0
  66. package/lib/no-axios/bindings/client.js +134 -0
  67. package/lib/no-axios/bindings/config.d.ts +34 -0
  68. package/lib/no-axios/bindings/config.js +83 -0
  69. package/lib/no-axios/bindings/generator.d.ts +176 -0
  70. package/lib/no-axios/bindings/generator.js +131 -0
  71. package/lib/no-axios/bindings/index.d.ts +6 -0
  72. package/lib/no-axios/bindings/index.js +75 -0
  73. package/lib/no-axios/bindings/sac-spec.d.ts +1 -0
  74. package/lib/no-axios/bindings/sac-spec.js +7 -0
  75. package/lib/no-axios/bindings/types.d.ts +66 -0
  76. package/lib/no-axios/bindings/types.js +184 -0
  77. package/lib/no-axios/bindings/utils.d.ts +49 -0
  78. package/lib/no-axios/bindings/utils.js +223 -0
  79. package/lib/no-axios/bindings/wasm_fetcher.d.ts +25 -0
  80. package/lib/no-axios/bindings/wasm_fetcher.js +225 -0
  81. package/lib/no-axios/cli/index.d.ts +2 -0
  82. package/lib/no-axios/cli/index.js +171 -0
  83. package/lib/no-axios/cli/util.d.ts +55 -0
  84. package/lib/no-axios/cli/util.js +254 -0
  85. package/lib/no-axios/contract/client.js +2 -1
  86. package/lib/no-axios/horizon/call_builder.js +30 -6
  87. package/lib/no-axios/horizon/horizon_axios_client.js +1 -1
  88. package/lib/no-axios/index.d.ts +1 -0
  89. package/lib/no-axios/index.js +9 -1
  90. package/lib/no-axios/rpc/axios.js +1 -1
  91. package/lib/no-axios/rpc/server.d.ts +35 -1
  92. package/lib/no-axios/rpc/server.js +110 -43
  93. package/lib/no-axios/stellartoml/index.d.ts +3 -0
  94. package/lib/no-eventsource/bindings/client.d.ts +30 -0
  95. package/lib/no-eventsource/bindings/client.js +134 -0
  96. package/lib/no-eventsource/bindings/config.d.ts +34 -0
  97. package/lib/no-eventsource/bindings/config.js +83 -0
  98. package/lib/no-eventsource/bindings/generator.d.ts +176 -0
  99. package/lib/no-eventsource/bindings/generator.js +131 -0
  100. package/lib/no-eventsource/bindings/index.d.ts +6 -0
  101. package/lib/no-eventsource/bindings/index.js +75 -0
  102. package/lib/no-eventsource/bindings/sac-spec.d.ts +1 -0
  103. package/lib/no-eventsource/bindings/sac-spec.js +7 -0
  104. package/lib/no-eventsource/bindings/types.d.ts +66 -0
  105. package/lib/no-eventsource/bindings/types.js +184 -0
  106. package/lib/no-eventsource/bindings/utils.d.ts +49 -0
  107. package/lib/no-eventsource/bindings/utils.js +223 -0
  108. package/lib/no-eventsource/bindings/wasm_fetcher.d.ts +25 -0
  109. package/lib/no-eventsource/bindings/wasm_fetcher.js +225 -0
  110. package/lib/no-eventsource/cli/index.d.ts +2 -0
  111. package/lib/no-eventsource/cli/index.js +171 -0
  112. package/lib/no-eventsource/cli/util.d.ts +55 -0
  113. package/lib/no-eventsource/cli/util.js +254 -0
  114. package/lib/no-eventsource/contract/client.js +2 -1
  115. package/lib/no-eventsource/horizon/call_builder.js +30 -6
  116. package/lib/no-eventsource/horizon/horizon_axios_client.js +1 -1
  117. package/lib/no-eventsource/index.d.ts +1 -0
  118. package/lib/no-eventsource/index.js +9 -1
  119. package/lib/no-eventsource/rpc/axios.js +1 -1
  120. package/lib/no-eventsource/rpc/server.d.ts +35 -1
  121. package/lib/no-eventsource/rpc/server.js +110 -43
  122. package/lib/no-eventsource/stellartoml/index.d.ts +3 -0
  123. package/lib/rpc/axios.js +1 -1
  124. package/lib/rpc/server.d.ts +35 -1
  125. package/lib/rpc/server.js +110 -43
  126. package/lib/stellartoml/index.d.ts +3 -0
  127. package/package.json +10 -4
  128. package/CHANGELOG.md +0 -2023
@@ -12,7 +12,7 @@ var _api = require("./api");
12
12
  var _transaction = require("./transaction");
13
13
  var _parsers = require("./parsers");
14
14
  var _utils = require("../utils");
15
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t9 in e) "default" !== _t9 && {}.hasOwnProperty.call(e, _t9) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t9)) && (i.get || i.set) ? o(f, _t9, i) : f[_t9] = e[_t9]); return f; })(e, t); }
15
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t1 in e) "default" !== _t1 && {}.hasOwnProperty.call(e, _t1) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t1)) && (i.get || i.set) ? o(f, _t1, i) : f[_t1] = e[_t1]); return f; })(e, t); }
16
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
17
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
18
18
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -899,15 +899,82 @@ var RpcServer = exports.RpcServer = function () {
899
899
  return requestAirdrop;
900
900
  }())
901
901
  }, {
902
- key: "getFeeStats",
902
+ key: "fundAddress",
903
903
  value: (function () {
904
- var _getFeeStats = _asyncToGenerator(_regenerator().m(function _callee24() {
904
+ var _fundAddress = _asyncToGenerator(_regenerator().m(function _callee24(address, friendbotUrl) {
905
+ var response, txResponse, _error$response2, _error$response$data$, _error$response$data, _t8, _t9;
905
906
  return _regenerator().w(function (_context24) {
906
- while (1) switch (_context24.n) {
907
+ while (1) switch (_context24.p = _context24.n) {
907
908
  case 0:
908
- return _context24.a(2, jsonrpc.postObject(this.httpClient, this.serverURL.toString(), "getFeeStats"));
909
+ if (!(!_stellarBase.StrKey.isValidEd25519PublicKey(address) && !_stellarBase.StrKey.isValidContract(address))) {
910
+ _context24.n = 1;
911
+ break;
912
+ }
913
+ throw new Error("Invalid address: ".concat(address, ". Expected a Stellar account (G...) or contract (C...) address."));
914
+ case 1:
915
+ _t8 = friendbotUrl;
916
+ if (_t8) {
917
+ _context24.n = 3;
918
+ break;
919
+ }
920
+ _context24.n = 2;
921
+ return this.getNetwork();
922
+ case 2:
923
+ _t8 = _context24.v.friendbotUrl;
924
+ case 3:
925
+ friendbotUrl = _t8;
926
+ if (friendbotUrl) {
927
+ _context24.n = 4;
928
+ break;
929
+ }
930
+ throw new Error("No friendbot URL configured for current network");
931
+ case 4:
932
+ _context24.p = 4;
933
+ _context24.n = 5;
934
+ return this.httpClient.post("".concat(friendbotUrl, "?addr=").concat(encodeURIComponent(address)));
935
+ case 5:
936
+ response = _context24.v;
937
+ _context24.n = 6;
938
+ return this.getTransaction(response.data.hash);
939
+ case 6:
940
+ txResponse = _context24.v;
941
+ if (!(txResponse.status !== _api.Api.GetTransactionStatus.SUCCESS)) {
942
+ _context24.n = 7;
943
+ break;
944
+ }
945
+ throw new Error("Funding address ".concat(address, " failed: transaction status ").concat(txResponse.status));
946
+ case 7:
947
+ return _context24.a(2, txResponse);
948
+ case 8:
949
+ _context24.p = 8;
950
+ _t9 = _context24.v;
951
+ if (!(((_error$response2 = _t9.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.status) === 400)) {
952
+ _context24.n = 9;
953
+ break;
954
+ }
955
+ throw new Error((_error$response$data$ = (_error$response$data = _t9.response.data) === null || _error$response$data === void 0 ? void 0 : _error$response$data.detail) !== null && _error$response$data$ !== void 0 ? _error$response$data$ : "Bad Request");
956
+ case 9:
957
+ throw _t9;
958
+ case 10:
959
+ return _context24.a(2);
909
960
  }
910
- }, _callee24, this);
961
+ }, _callee24, this, [[4, 8]]);
962
+ }));
963
+ function fundAddress(_x31, _x32) {
964
+ return _fundAddress.apply(this, arguments);
965
+ }
966
+ return fundAddress;
967
+ }())
968
+ }, {
969
+ key: "getFeeStats",
970
+ value: (function () {
971
+ var _getFeeStats = _asyncToGenerator(_regenerator().m(function _callee25() {
972
+ return _regenerator().w(function (_context25) {
973
+ while (1) switch (_context25.n) {
974
+ case 0:
975
+ return _context25.a(2, jsonrpc.postObject(this.httpClient, this.serverURL.toString(), "getFeeStats"));
976
+ }
977
+ }, _callee25, this);
911
978
  }));
912
979
  function getFeeStats() {
913
980
  return _getFeeStats.apply(this, arguments);
@@ -917,13 +984,13 @@ var RpcServer = exports.RpcServer = function () {
917
984
  }, {
918
985
  key: "getVersionInfo",
919
986
  value: (function () {
920
- var _getVersionInfo = _asyncToGenerator(_regenerator().m(function _callee25() {
921
- return _regenerator().w(function (_context25) {
922
- while (1) switch (_context25.n) {
987
+ var _getVersionInfo = _asyncToGenerator(_regenerator().m(function _callee26() {
988
+ return _regenerator().w(function (_context26) {
989
+ while (1) switch (_context26.n) {
923
990
  case 0:
924
- return _context25.a(2, jsonrpc.postObject(this.httpClient, this.serverURL.toString(), "getVersionInfo"));
991
+ return _context26.a(2, jsonrpc.postObject(this.httpClient, this.serverURL.toString(), "getVersionInfo"));
925
992
  }
926
- }, _callee25, this);
993
+ }, _callee26, this);
927
994
  }));
928
995
  function getVersionInfo() {
929
996
  return _getVersionInfo.apply(this, arguments);
@@ -933,34 +1000,34 @@ var RpcServer = exports.RpcServer = function () {
933
1000
  }, {
934
1001
  key: "getSACBalance",
935
1002
  value: (function () {
936
- var _getSACBalance = _asyncToGenerator(_regenerator().m(function _callee26(address, sac, networkPassphrase) {
937
- var addressString, passphrase, sacId, key, ledgerKey, response, _response$entries$2, lastModifiedLedgerSeq, liveUntilLedgerSeq, val, entry, _t8;
938
- return _regenerator().w(function (_context26) {
939
- while (1) switch (_context26.n) {
1003
+ var _getSACBalance = _asyncToGenerator(_regenerator().m(function _callee27(address, sac, networkPassphrase) {
1004
+ var addressString, passphrase, sacId, key, ledgerKey, response, _response$entries$2, lastModifiedLedgerSeq, liveUntilLedgerSeq, val, entry, _t0;
1005
+ return _regenerator().w(function (_context27) {
1006
+ while (1) switch (_context27.n) {
940
1007
  case 0:
941
1008
  addressString = address instanceof _stellarBase.Address ? address.toString() : address;
942
1009
  if (_stellarBase.StrKey.isValidContract(addressString)) {
943
- _context26.n = 1;
1010
+ _context27.n = 1;
944
1011
  break;
945
1012
  }
946
1013
  throw new TypeError("expected contract ID, got ".concat(addressString));
947
1014
  case 1:
948
1015
  if (!(networkPassphrase !== null && networkPassphrase !== void 0)) {
949
- _context26.n = 2;
1016
+ _context27.n = 2;
950
1017
  break;
951
1018
  }
952
- _t8 = networkPassphrase;
953
- _context26.n = 4;
1019
+ _t0 = networkPassphrase;
1020
+ _context27.n = 4;
954
1021
  break;
955
1022
  case 2:
956
- _context26.n = 3;
1023
+ _context27.n = 3;
957
1024
  return this.getNetwork().then(function (n) {
958
1025
  return n.passphrase;
959
1026
  });
960
1027
  case 3:
961
- _t8 = _context26.v;
1028
+ _t0 = _context27.v;
962
1029
  case 4:
963
- passphrase = _t8;
1030
+ passphrase = _t0;
964
1031
  sacId = sac.contractId(passphrase);
965
1032
  key = (0, _stellarBase.nativeToScVal)(["Balance", addressString], {
966
1033
  type: ["symbol", "address"]
@@ -970,29 +1037,29 @@ var RpcServer = exports.RpcServer = function () {
970
1037
  durability: _stellarBase.xdr.ContractDataDurability.persistent(),
971
1038
  key: key
972
1039
  }));
973
- _context26.n = 5;
1040
+ _context27.n = 5;
974
1041
  return this.getLedgerEntries(ledgerKey);
975
1042
  case 5:
976
- response = _context26.v;
1043
+ response = _context27.v;
977
1044
  if (!(response.entries.length === 0)) {
978
- _context26.n = 6;
1045
+ _context27.n = 6;
979
1046
  break;
980
1047
  }
981
- return _context26.a(2, {
1048
+ return _context27.a(2, {
982
1049
  latestLedger: response.latestLedger
983
1050
  });
984
1051
  case 6:
985
1052
  _response$entries$2 = response.entries[0], lastModifiedLedgerSeq = _response$entries$2.lastModifiedLedgerSeq, liveUntilLedgerSeq = _response$entries$2.liveUntilLedgerSeq, val = _response$entries$2.val;
986
1053
  if (!(val.switch().value !== _stellarBase.xdr.LedgerEntryType.contractData().value)) {
987
- _context26.n = 7;
1054
+ _context27.n = 7;
988
1055
  break;
989
1056
  }
990
- return _context26.a(2, {
1057
+ return _context27.a(2, {
991
1058
  latestLedger: response.latestLedger
992
1059
  });
993
1060
  case 7:
994
1061
  entry = (0, _stellarBase.scValToNative)(val.contractData().val());
995
- return _context26.a(2, {
1062
+ return _context27.a(2, {
996
1063
  latestLedger: response.latestLedger,
997
1064
  balanceEntry: {
998
1065
  liveUntilLedgerSeq: liveUntilLedgerSeq,
@@ -1003,9 +1070,9 @@ var RpcServer = exports.RpcServer = function () {
1003
1070
  }
1004
1071
  });
1005
1072
  }
1006
- }, _callee26, this);
1073
+ }, _callee27, this);
1007
1074
  }));
1008
- function getSACBalance(_x31, _x32, _x33) {
1075
+ function getSACBalance(_x33, _x34, _x35) {
1009
1076
  return _getSACBalance.apply(this, arguments);
1010
1077
  }
1011
1078
  return getSACBalance;
@@ -1013,11 +1080,11 @@ var RpcServer = exports.RpcServer = function () {
1013
1080
  }, {
1014
1081
  key: "getLedgers",
1015
1082
  value: (function () {
1016
- var _getLedgers2 = _asyncToGenerator(_regenerator().m(function _callee27(request) {
1017
- return _regenerator().w(function (_context27) {
1018
- while (1) switch (_context27.n) {
1083
+ var _getLedgers2 = _asyncToGenerator(_regenerator().m(function _callee28(request) {
1084
+ return _regenerator().w(function (_context28) {
1085
+ while (1) switch (_context28.n) {
1019
1086
  case 0:
1020
- return _context27.a(2, this._getLedgers(request).then(function (raw) {
1087
+ return _context28.a(2, this._getLedgers(request).then(function (raw) {
1021
1088
  var result = {
1022
1089
  ledgers: (raw.ledgers || []).map(_parsers.parseRawLedger),
1023
1090
  latestLedger: raw.latestLedger,
@@ -1029,9 +1096,9 @@ var RpcServer = exports.RpcServer = function () {
1029
1096
  return result;
1030
1097
  }));
1031
1098
  }
1032
- }, _callee27, this);
1099
+ }, _callee28, this);
1033
1100
  }));
1034
- function getLedgers(_x34) {
1101
+ function getLedgers(_x36) {
1035
1102
  return _getLedgers2.apply(this, arguments);
1036
1103
  }
1037
1104
  return getLedgers;
@@ -1039,15 +1106,15 @@ var RpcServer = exports.RpcServer = function () {
1039
1106
  }, {
1040
1107
  key: "_getLedgers",
1041
1108
  value: function () {
1042
- var _getLedgers3 = _asyncToGenerator(_regenerator().m(function _callee28(request) {
1043
- return _regenerator().w(function (_context28) {
1044
- while (1) switch (_context28.n) {
1109
+ var _getLedgers3 = _asyncToGenerator(_regenerator().m(function _callee29(request) {
1110
+ return _regenerator().w(function (_context29) {
1111
+ while (1) switch (_context29.n) {
1045
1112
  case 0:
1046
- return _context28.a(2, jsonrpc.postObject(this.httpClient, this.serverURL.toString(), "getLedgers", request));
1113
+ return _context29.a(2, jsonrpc.postObject(this.httpClient, this.serverURL.toString(), "getLedgers", request));
1047
1114
  }
1048
- }, _callee28, this);
1115
+ }, _callee29, this);
1049
1116
  }));
1050
- function _getLedgers(_x35) {
1117
+ function _getLedgers(_x37) {
1051
1118
  return _getLedgers3.apply(this, arguments);
1052
1119
  }
1053
1120
  return _getLedgers;
@@ -41,6 +41,7 @@ export declare namespace Api {
41
41
  }
42
42
  type Url = string;
43
43
  type PublicKey = string;
44
+ type ContractId = string;
44
45
  type ISODateTime = string;
45
46
  interface Documentation {
46
47
  ORG_NAME?: string;
@@ -117,6 +118,8 @@ export declare namespace Api {
117
118
  TRANSFER_SERVER?: Url;
118
119
  KYC_SERVER?: Url;
119
120
  WEB_AUTH_ENDPOINT?: Url;
121
+ WEB_AUTH_FOR_CONTRACTS_ENDPOINT?: Url;
122
+ WEB_AUTH_CONTRACT_ID?: ContractId;
120
123
  FEDERATION_SERVER?: Url;
121
124
  SIGNING_KEY?: PublicKey;
122
125
  HORIZON_URL?: Url;
@@ -0,0 +1,30 @@
1
+ import { Spec } from "../contract";
2
+ /**
3
+ * Generates TypeScript client class for contract methods
4
+ */
5
+ export declare class ClientGenerator {
6
+ private spec;
7
+ constructor(spec: Spec);
8
+ /**
9
+ * Generate client class
10
+ */
11
+ generate(): string;
12
+ private generateImports;
13
+ /**
14
+ * Generate interface method signature
15
+ */
16
+ private generateInterfaceMethod;
17
+ private generateFromJSONMethod;
18
+ /**
19
+ * Generate deploy method
20
+ */
21
+ private generateDeployMethod;
22
+ /**
23
+ * Format method parameters
24
+ */
25
+ private formatMethodParameters;
26
+ /**
27
+ * Format constructor parameters
28
+ */
29
+ private formatConstructorParameters;
30
+ }
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ClientGenerator = void 0;
7
+ var _utils = require("./utils");
8
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
9
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
10
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
11
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
13
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
14
+ var ClientGenerator = exports.ClientGenerator = function () {
15
+ function ClientGenerator(spec) {
16
+ _classCallCheck(this, ClientGenerator);
17
+ this.spec = spec;
18
+ }
19
+ return _createClass(ClientGenerator, [{
20
+ key: "generate",
21
+ value: function generate() {
22
+ var _this = this;
23
+ var deployMethod = "";
24
+ try {
25
+ var constructorFunc = this.spec.getFunc("__constructor");
26
+ deployMethod = this.generateDeployMethod(constructorFunc);
27
+ } catch (_unused) {
28
+ deployMethod = this.generateDeployMethod(undefined);
29
+ }
30
+ var interfaceMethods = this.spec.funcs().filter(function (func) {
31
+ return func.name().toString() !== "__constructor";
32
+ }).map(function (func) {
33
+ return _this.generateInterfaceMethod(func);
34
+ }).join("\n");
35
+ var imports = this.generateImports();
36
+ var specEntries = this.spec.entries.map(function (entry) {
37
+ return "\"".concat(entry.toXDR("base64"), "\"");
38
+ });
39
+ var fromJSON = this.spec.funcs().filter(function (func) {
40
+ return func.name().toString() !== "__constructor";
41
+ }).map(function (func) {
42
+ return _this.generateFromJSONMethod(func);
43
+ }).join(",");
44
+ return "".concat(imports, "\n\nexport interface Client {\n").concat(interfaceMethods, "\n}\n\nexport class Client extends ContractClient {\n constructor(public readonly options: ContractClientOptions) {\n super(\n new Spec([").concat(specEntries.join(", "), "]),\n options\n );\n }\n\n ").concat(deployMethod, "\n public readonly fromJSON = {\n ").concat(fromJSON, "\n };\n}");
45
+ }
46
+ }, {
47
+ key: "generateImports",
48
+ value: function generateImports() {
49
+ var imports = (0, _utils.generateTypeImports)(this.spec.funcs().flatMap(function (func) {
50
+ var inputs = func.inputs();
51
+ var outputs = func.outputs();
52
+ var defs = inputs.map(function (input) {
53
+ return input.type();
54
+ }).concat(outputs);
55
+ return defs;
56
+ }));
57
+ return (0, _utils.formatImports)(imports, {
58
+ includeTypeFileImports: true,
59
+ additionalStellarContractImports: ["Spec", "AssembledTransaction", "Client as ContractClient", "ClientOptions as ContractClientOptions", "MethodOptions"]
60
+ });
61
+ }
62
+ }, {
63
+ key: "generateInterfaceMethod",
64
+ value: function generateInterfaceMethod(func) {
65
+ var name = (0, _utils.sanitizeIdentifier)(func.name().toString());
66
+ var inputs = func.inputs().map(function (input) {
67
+ return {
68
+ name: input.name().toString(),
69
+ type: (0, _utils.parseTypeFromTypeDef)(input.type(), true)
70
+ };
71
+ });
72
+ var outputType = func.outputs().length > 0 ? (0, _utils.parseTypeFromTypeDef)(func.outputs()[0]) : "void";
73
+ var docs = (0, _utils.formatJSDocComment)(func.doc().toString(), 2);
74
+ var params = this.formatMethodParameters(inputs);
75
+ return "".concat(docs, " ").concat(name, "(").concat(params, "): Promise<AssembledTransaction<").concat(outputType, ">>;");
76
+ }
77
+ }, {
78
+ key: "generateFromJSONMethod",
79
+ value: function generateFromJSONMethod(func) {
80
+ var name = func.name().toString();
81
+ var outputType = func.outputs().length > 0 ? (0, _utils.parseTypeFromTypeDef)(func.outputs()[0]) : "void";
82
+ return " ".concat(name, " : this.txFromJSON<").concat(outputType, ">");
83
+ }
84
+ }, {
85
+ key: "generateDeployMethod",
86
+ value: function generateDeployMethod(constructorFunc) {
87
+ if (!constructorFunc) {
88
+ var _params = this.formatConstructorParameters([]);
89
+ return " static deploy<T = Client>(".concat(_params, "): Promise<AssembledTransaction<T>> {\n return ContractClient.deploy(null, options);\n }");
90
+ }
91
+ var inputs = constructorFunc.inputs().map(function (input) {
92
+ return {
93
+ name: input.name().toString(),
94
+ type: (0, _utils.parseTypeFromTypeDef)(input.type(), true)
95
+ };
96
+ });
97
+ var params = this.formatConstructorParameters(inputs);
98
+ var inputsDestructure = inputs.length > 0 ? "{ ".concat(inputs.map(function (i) {
99
+ return i.name;
100
+ }).join(", "), " }, ") : "";
101
+ return " static deploy<T = Client>(".concat(params, "): Promise<AssembledTransaction<T>> {\n return ContractClient.deploy(").concat(inputsDestructure, "options);\n }");
102
+ }
103
+ }, {
104
+ key: "formatMethodParameters",
105
+ value: function formatMethodParameters(inputs) {
106
+ var params = [];
107
+ if (inputs.length > 0) {
108
+ var inputsParam = "{ ".concat(inputs.map(function (i) {
109
+ return "".concat(i.name, ": ").concat(i.type);
110
+ }).join("; "), " }");
111
+ params.push("{ ".concat(inputs.map(function (i) {
112
+ return i.name;
113
+ }).join(", "), " }: ").concat(inputsParam));
114
+ }
115
+ params.push("options?: MethodOptions");
116
+ return params.join(", ");
117
+ }
118
+ }, {
119
+ key: "formatConstructorParameters",
120
+ value: function formatConstructorParameters(inputs) {
121
+ var params = [];
122
+ if (inputs.length > 0) {
123
+ var inputsParam = "{ ".concat(inputs.map(function (i) {
124
+ return "".concat(i.name, ": ").concat(i.type);
125
+ }).join("; "), " }");
126
+ params.push("{ ".concat(inputs.map(function (i) {
127
+ return i.name;
128
+ }).join(", "), " }: ").concat(inputsParam));
129
+ }
130
+ params.push('options: MethodOptions & Omit<ContractClientOptions, \'contractId\'> & { wasmHash: Buffer | string; salt?: Buffer | Uint8Array; format?: "hex" | "base64"; address?: string; }');
131
+ return params.join(", ");
132
+ }
133
+ }]);
134
+ }();
@@ -0,0 +1,34 @@
1
+ export interface ConfigGenerateOptions {
2
+ contractName: string;
3
+ }
4
+ export interface Configs {
5
+ packageJson: string;
6
+ tsConfig: string;
7
+ gitignore: string;
8
+ readme: string;
9
+ }
10
+ /**
11
+ * Generates a complete TypeScript project structure with contract bindings
12
+ */
13
+ export declare class ConfigGenerator {
14
+ /**
15
+ * Generate the complete TypeScript project
16
+ */
17
+ generate(options: ConfigGenerateOptions): Configs;
18
+ /**
19
+ * Generate package.json
20
+ */
21
+ private generatePackageJson;
22
+ /**
23
+ * Generate tsconfig.json
24
+ */
25
+ private generateTsConfig;
26
+ /**
27
+ * Generate .gitignore
28
+ */
29
+ private generateGitignore;
30
+ /**
31
+ * Generate README.md
32
+ */
33
+ private generateReadme;
34
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ConfigGenerator = void 0;
7
+ var _package = _interopRequireDefault(require("../../package.json"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
10
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
11
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
12
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
14
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
+ var ConfigGenerator = exports.ConfigGenerator = function () {
16
+ function ConfigGenerator() {
17
+ _classCallCheck(this, ConfigGenerator);
18
+ }
19
+ return _createClass(ConfigGenerator, [{
20
+ key: "generate",
21
+ value: function generate(options) {
22
+ var contractName = options.contractName;
23
+ return {
24
+ packageJson: this.generatePackageJson(contractName),
25
+ tsConfig: this.generateTsConfig(),
26
+ gitignore: this.generateGitignore(),
27
+ readme: this.generateReadme(contractName)
28
+ };
29
+ }
30
+ }, {
31
+ key: "generatePackageJson",
32
+ value: function generatePackageJson(contractName) {
33
+ var generatedPackageJson = {
34
+ name: contractName.toLowerCase().replace(/[^a-z0-9-]/g, "-"),
35
+ version: "0.0.1",
36
+ description: "Generated TypeScript bindings for ".concat(contractName, " Stellar contract"),
37
+ type: "module",
38
+ main: "dist/index.js",
39
+ types: "dist/index.d.ts",
40
+ scripts: {
41
+ build: "tsc"
42
+ },
43
+ dependencies: {
44
+ "@stellar/stellar-sdk": "^".concat(_package.default.version),
45
+ buffer: "6.0.3"
46
+ },
47
+ devDependencies: {
48
+ typescript: "^5.6.3"
49
+ }
50
+ };
51
+ return JSON.stringify(generatedPackageJson, null, 2);
52
+ }
53
+ }, {
54
+ key: "generateTsConfig",
55
+ value: function generateTsConfig() {
56
+ var tsConfig = {
57
+ compilerOptions: {
58
+ target: "ESNext",
59
+ module: "NodeNext",
60
+ moduleResolution: "nodenext",
61
+ declaration: true,
62
+ outDir: "./dist",
63
+ strictNullChecks: true,
64
+ skipLibCheck: true
65
+ },
66
+ include: ["src/*"]
67
+ };
68
+ return JSON.stringify(tsConfig, null, 2);
69
+ }
70
+ }, {
71
+ key: "generateGitignore",
72
+ value: function generateGitignore() {
73
+ var gitignore = ["# Dependencies", "node_modules/", "", "# Build outputs", "dist/", "*.tgz", "", "# IDE", ".vscode/", ".idea/", "", "# OS", ".DS_Store", "Thumbs.db", "", "# Logs", "*.log", "npm-debug.log*", "", "# Runtime data", "*.pid", "*.seed"].join("\n");
74
+ return gitignore;
75
+ }
76
+ }, {
77
+ key: "generateReadme",
78
+ value: function generateReadme(contractName) {
79
+ var readme = ["# ".concat(contractName, " Contract Bindings"), "", "TypeScript bindings for the ".concat(contractName, " Stellar smart contract."), "", "## Installation", "", "```bash", "npm install", "```", "", "## Build", "", "```bash", "npm run build", "```", "", "## Usage", "", "```typescript", 'import { Client } from "./src";', "", "const client = new Client({", ' contractId: "YOUR_CONTRACT_ID",', ' rpcUrl: "https://soroban-testnet.stellar.org:443",', ' networkPassphrase: "Test SDF Network ; September 2015",', "});", "", "// Call contract methods", "// const result = await client.methodName();", "```", "", "## Generated Files", "", "- `src/index.ts` - Entry point exporting the Client", "- `src/types.ts` - Type definitions for contract structs, enums, and unions", "- `src/contract.ts` - Client implementation", "- `tsconfig.json` - TypeScript configuration", "- `package.json` - NPM package configuration", "", "This package was generated using the Js-Stellar-SDK contract binding generator."].join("\n");
80
+ return readme;
81
+ }
82
+ }]);
83
+ }();