@stellar/typescript-wallet-sdk 3.0.0 → 3.0.1

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.
@@ -1858,9 +1858,9 @@ var Sep10 = /** @class */ (function () {
1858
1858
  Sep10.prototype.sign = function (_a) {
1859
1859
  var accountKp = _a.accountKp, challengeResponse = _a.challengeResponse, walletSigner = _a.walletSigner;
1860
1860
  return __awaiter(this, void 0, void 0, function () {
1861
- var networkPassphrase, webAuthDomain, transaction, _i, _b, op;
1862
- return __generator(this, function (_c) {
1863
- switch (_c.label) {
1861
+ var networkPassphrase, webAuthDomain, transaction, hasClientDomain, originalHash, returned;
1862
+ return __generator(this, function (_b) {
1863
+ switch (_b.label) {
1864
1864
  case 0:
1865
1865
  networkPassphrase = this.cfg.stellar.network;
1866
1866
  if (challengeResponse.network_passphrase &&
@@ -1875,24 +1875,26 @@ var Sep10 = /** @class */ (function () {
1875
1875
  throw new Exceptions_1.ChallengeValidationFailedError(e instanceof Error ? e : new Error(String(e)));
1876
1876
  }
1877
1877
  transaction = stellar_sdk_1.TransactionBuilder.fromXDR(challengeResponse.transaction, networkPassphrase);
1878
- _i = 0, _b = transaction.operations;
1879
- _c.label = 1;
1880
- case 1:
1881
- if (!(_i < _b.length)) return [3 /*break*/, 4];
1882
- op = _b[_i];
1883
- if (!(op.type === "manageData" && op.name === "client_domain")) return [3 /*break*/, 3];
1878
+ hasClientDomain = transaction.operations.some(function (op) { return op.type === "manageData" && op.name === "client_domain"; });
1879
+ if (!hasClientDomain) return [3 /*break*/, 2];
1880
+ originalHash = transaction.hash();
1884
1881
  return [4 /*yield*/, walletSigner.signWithDomainAccount({
1885
1882
  transactionXDR: challengeResponse.transaction,
1886
1883
  networkPassphrase: networkPassphrase,
1887
1884
  accountKp: accountKp,
1888
1885
  })];
1886
+ case 1:
1887
+ returned = _b.sent();
1888
+ // Transaction.hash() covers the envelope body but excludes signatures, so
1889
+ // a domain signer that only appends its signature preserves the hash. Any
1890
+ // change to the operations, source account, memo, or other body fields
1891
+ // changes the hash and is rejected here.
1892
+ if (!returned.hash().equals(originalHash)) {
1893
+ throw new Exceptions_1.DomainSigningModifiedError();
1894
+ }
1895
+ transaction = returned;
1896
+ _b.label = 2;
1889
1897
  case 2:
1890
- transaction = _c.sent();
1891
- _c.label = 3;
1892
- case 3:
1893
- _i++;
1894
- return [3 /*break*/, 1];
1895
- case 4:
1896
1898
  walletSigner.signWithClientAccount({ transaction: transaction, accountKp: accountKp });
1897
1899
  return [2 /*return*/, transaction];
1898
1900
  }
@@ -2233,7 +2235,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
2233
2235
  return (mod && mod.__esModule) ? mod : { "default": mod };
2234
2236
  };
2235
2237
  Object.defineProperty(exports, "__esModule", ({ value: true }));
2236
- exports.Sep7UriTypeNotSupportedError = exports.Sep7LongMsgError = exports.Sep7InvalidUriError = exports.AuthHeaderClientDomainRequiredError = exports.AuthHeaderSigningKeypairRequiredError = exports.DefaultSignerDomainAccountError = exports.SigningKeypairMissingSecretError = exports.InvalidJsonError = exports.UnknownAnchorTransactionError = exports.AllowHttpOnNonTestnetError = exports.ChallengeTxnInvalidSignatureError = exports.ChallengeTxnIncorrectSequenceError = exports.NetworkPassphraseMismatchError = exports.ChallengeValidationFailedError = exports.MissingSigningKeyError = exports.Sep38PriceOnlyOneAmountError = exports.NoAccountAndNoSponsorError = exports.DeviceKeyEqualsMasterKeyError = exports.NoAccountSignersError = exports.UnableToDeduceKeyError = exports.NoDeviceKeyForAccountError = exports.LostSignerKeyNotFound = exports.NotAllSignaturesFetchedError = exports.RecoveryIdentityNotFoundError = exports.RecoveryServerNotFoundError = exports.KYCServerNotFoundError = exports.CustomerNotFoundError = exports.Sep9InfoRequiredError = exports.WithdrawalTxMemoError = exports.PathPayOnlyOneAmountError = exports.WithdrawalTxMissingMemoError = exports.WithdrawalTxMissingDestinationError = exports.WithdrawalTxNotPendingUserTransferStartError = exports.OperationsLimitExceededError = exports.SignerRequiredError = exports.TransactionSubmitWithFeeIncreaseFailedError = exports.ExpiredTokenError = exports.InvalidTokenError = exports.MissingTokenError = exports.InsufficientStartingBalanceError = exports.TransactionSubmitFailedError = exports.AccountDoesNotExistError = exports.InvalidTransactionsResponseError = exports.InvalidTransactionResponseError = exports.MissingTransactionIdError = exports.ClientDomainWithMemoError = exports.InvalidMemoError = exports.AssetNotSupportedError = exports.ServerRequestFailedError = void 0;
2238
+ exports.Sep7UriTypeNotSupportedError = exports.Sep7LongMsgError = exports.Sep7InvalidUriError = exports.AuthHeaderClientDomainRequiredError = exports.AuthHeaderSigningKeypairRequiredError = exports.DomainSigningModifiedError = exports.DefaultSignerDomainAccountError = exports.SigningKeypairMissingSecretError = exports.InvalidJsonError = exports.UnknownAnchorTransactionError = exports.AllowHttpOnNonTestnetError = exports.ChallengeTxnInvalidSignatureError = exports.ChallengeTxnIncorrectSequenceError = exports.NetworkPassphraseMismatchError = exports.ChallengeValidationFailedError = exports.MissingSigningKeyError = exports.Sep38PriceOnlyOneAmountError = exports.NoAccountAndNoSponsorError = exports.DeviceKeyEqualsMasterKeyError = exports.NoAccountSignersError = exports.UnableToDeduceKeyError = exports.NoDeviceKeyForAccountError = exports.LostSignerKeyNotFound = exports.NotAllSignaturesFetchedError = exports.RecoveryIdentityNotFoundError = exports.RecoveryServerNotFoundError = exports.KYCServerNotFoundError = exports.CustomerNotFoundError = exports.Sep9InfoRequiredError = exports.WithdrawalTxMemoError = exports.PathPayOnlyOneAmountError = exports.WithdrawalTxMissingMemoError = exports.WithdrawalTxMissingDestinationError = exports.WithdrawalTxNotPendingUserTransferStartError = exports.OperationsLimitExceededError = exports.SignerRequiredError = exports.TransactionSubmitWithFeeIncreaseFailedError = exports.ExpiredTokenError = exports.InvalidTokenError = exports.MissingTokenError = exports.InsufficientStartingBalanceError = exports.TransactionSubmitFailedError = exports.AccountDoesNotExistError = exports.InvalidTransactionsResponseError = exports.InvalidTransactionResponseError = exports.MissingTransactionIdError = exports.ClientDomainWithMemoError = exports.InvalidMemoError = exports.AssetNotSupportedError = exports.ServerRequestFailedError = void 0;
2237
2239
  var axios_1 = __importDefault(__webpack_require__(/*! axios */ "../../node_modules/axios/dist/browser/axios.cjs"));
2238
2240
  var Utils_1 = __webpack_require__(/*! ../Utils */ "./src/walletSdk/Utils/index.ts");
2239
2241
  var ServerRequestFailedError = /** @class */ (function (_super) {
@@ -2687,6 +2689,16 @@ var DefaultSignerDomainAccountError = /** @class */ (function (_super) {
2687
2689
  return DefaultSignerDomainAccountError;
2688
2690
  }(Error));
2689
2691
  exports.DefaultSignerDomainAccountError = DefaultSignerDomainAccountError;
2692
+ var DomainSigningModifiedError = /** @class */ (function (_super) {
2693
+ __extends(DomainSigningModifiedError, _super);
2694
+ function DomainSigningModifiedError() {
2695
+ var _this = _super.call(this, "Domain signer returned a transaction whose body differs from the original challenge. Only the client_domain signature should be added.") || this;
2696
+ Object.setPrototypeOf(_this, DomainSigningModifiedError.prototype);
2697
+ return _this;
2698
+ }
2699
+ return DomainSigningModifiedError;
2700
+ }(Error));
2701
+ exports.DomainSigningModifiedError = DomainSigningModifiedError;
2690
2702
  var AuthHeaderSigningKeypairRequiredError = /** @class */ (function (_super) {
2691
2703
  __extends(AuthHeaderSigningKeypairRequiredError, _super);
2692
2704
  function AuthHeaderSigningKeypairRequiredError() {
@@ -3014,6 +3026,12 @@ var TransactionBuilder_1 = __webpack_require__(/*! ./Transaction/TransactionBuil
3014
3026
  var Exceptions_1 = __webpack_require__(/*! ../Exceptions */ "./src/walletSdk/Exceptions/index.ts");
3015
3027
  var getResultCode_1 = __webpack_require__(/*! ../Utils/getResultCode */ "./src/walletSdk/Utils/getResultCode.ts");
3016
3028
  var Account_1 = __webpack_require__(/*! ./Account */ "./src/walletSdk/Horizon/Account.ts");
3029
+ var SUBMIT_504_MAX_RETRIES = 5;
3030
+ var SUBMIT_504_BASE_DELAY_MS = 1000;
3031
+ var SUBMIT_504_MAX_DELAY_MS = 30000;
3032
+ var sleep = function (ms) {
3033
+ return new Promise(function (resolve) { return setTimeout(resolve, ms); });
3034
+ };
3017
3035
  /**
3018
3036
  * Interaction with the Stellar Network.
3019
3037
  * Do not create this object directly, use the Wallet class.
@@ -3090,37 +3108,63 @@ var Stellar = /** @class */ (function () {
3090
3108
  return stellar_sdk_1.TransactionBuilder.buildFeeBumpTransaction(feeAddress.keypair, (baseFee || this.cfg.stellar.baseFee).toString(), transaction, transaction.networkPassphrase);
3091
3109
  };
3092
3110
  /**
3093
- * Submits a signed transaction to the server. If the submission fails with status
3094
- * 504 indicating a timeout error, it will automatically retry.
3111
+ * Submits a signed transaction to Horizon.
3112
+ *
3113
+ * On HTTP 504 (timeout), retries with exponential backoff up to
3114
+ * {@link SUBMIT_504_MAX_RETRIES} times. Any non-504 error is rethrown
3115
+ * immediately without retrying.
3116
+ *
3095
3117
  * @param {Transaction|FeeBumpTransaction} signedTransaction - The signed transaction to submit.
3096
- * @returns {boolean} `true` if the transaction was successfully submitted.
3097
- * @throws {TransactionSubmitFailedError} If the transaction submission fails.
3118
+ * @returns {boolean} `true` if Horizon confirmed the submission as successful.
3119
+ * @throws {TransactionSubmitFailedError} If Horizon responded with a non-successful
3120
+ * submission result (the transaction reached Horizon but was rejected).
3121
+ * @throws The underlying 504 error if every retry attempt timed out. In this
3122
+ * case the transaction's on-chain status is **indeterminate** — Horizon may
3123
+ * have ingested it on the final attempt without responding in time. Callers
3124
+ * should poll the transaction hash to determine the actual outcome rather
3125
+ * than resubmit blindly; resubmitting a signed transaction with the same
3126
+ * sequence number will fail with `tx_bad_seq` once the original lands.
3098
3127
  */
3099
3128
  Stellar.prototype.submitTransaction = function (signedTransaction) {
3129
+ var _a;
3100
3130
  return __awaiter(this, void 0, void 0, function () {
3101
- var response, e_2;
3102
- return __generator(this, function (_a) {
3103
- switch (_a.label) {
3131
+ var lastError, attempt, response, e_2, cappedDelay, half;
3132
+ return __generator(this, function (_b) {
3133
+ switch (_b.label) {
3104
3134
  case 0:
3105
- _a.trys.push([0, 2, , 5]);
3106
- return [4 /*yield*/, this.server.submitTransaction(signedTransaction)];
3135
+ attempt = 0;
3136
+ _b.label = 1;
3107
3137
  case 1:
3108
- response = _a.sent();
3138
+ if (!(attempt <= SUBMIT_504_MAX_RETRIES)) return [3 /*break*/, 7];
3139
+ _b.label = 2;
3140
+ case 2:
3141
+ _b.trys.push([2, 4, , 6]);
3142
+ return [4 /*yield*/, this.server.submitTransaction(signedTransaction)];
3143
+ case 3:
3144
+ response = _b.sent();
3109
3145
  if (!response.successful) {
3110
3146
  throw new Exceptions_1.TransactionSubmitFailedError(response);
3111
3147
  }
3112
3148
  return [2 /*return*/, true];
3113
- case 2:
3114
- e_2 = _a.sent();
3115
- if (!(e_2.response.status === 504)) return [3 /*break*/, 4];
3116
- return [4 /*yield*/, this.submitTransaction(signedTransaction)];
3117
- case 3:
3118
- // in case of 504, keep retrying this tx until submission succeeds or we get a different error
3119
- // https://developers.stellar.org/api/errors/http-status-codes/horizon-specific/timeout
3120
- // https://developers.stellar.org/docs/encyclopedia/error-handling#timeouts
3121
- return [2 /*return*/, _a.sent()];
3122
- case 4: throw e_2;
3123
- case 5: return [2 /*return*/];
3149
+ case 4:
3150
+ e_2 = _b.sent();
3151
+ if (((_a = e_2 === null || e_2 === void 0 ? void 0 : e_2.response) === null || _a === void 0 ? void 0 : _a.status) !== 504) {
3152
+ throw e_2;
3153
+ }
3154
+ lastError = e_2;
3155
+ if (attempt === SUBMIT_504_MAX_RETRIES) {
3156
+ return [3 /*break*/, 7];
3157
+ }
3158
+ cappedDelay = Math.min(SUBMIT_504_BASE_DELAY_MS * Math.pow(2, attempt), SUBMIT_504_MAX_DELAY_MS);
3159
+ half = cappedDelay / 2;
3160
+ return [4 /*yield*/, sleep(half + Math.random() * half)];
3161
+ case 5:
3162
+ _b.sent();
3163
+ return [3 /*break*/, 6];
3164
+ case 6:
3165
+ attempt++;
3166
+ return [3 /*break*/, 1];
3167
+ case 7: throw lastError;
3124
3168
  }
3125
3169
  });
3126
3170
  });
@@ -3192,6 +3236,7 @@ var Stellar = /** @class */ (function () {
3192
3236
  signerFunction: signerFunction,
3193
3237
  baseFee: newFee,
3194
3238
  memo: memo,
3239
+ maxFee: maxFee,
3195
3240
  })];
3196
3241
  }
3197
3242
  throw e_3;
@@ -56464,7 +56509,7 @@ function decode(arr) {
56464
56509
  /***/ ((module) => {
56465
56510
 
56466
56511
  "use strict";
56467
- module.exports = JSON.parse('{"name":"@stellar/typescript-wallet-sdk","version":"3.0.0","engines":{"node":">=20"},"browser":"./lib/bundle_browser.js","main":"./lib/bundle.js","types":"./lib/index.d.ts","license":"Apache-2.0","private":false,"devDependencies":{"@babel/preset-env":"^7.20.2","@babel/preset-typescript":"^7.23.3","@stellar/prettier-config":"^1.0.1","@stellar/tsconfig":"^1.0.2","@types/jest":"^29.4.0","@types/lodash":"^4.14.194","@types/sinon":"^10.0.15","@typescript-eslint/eslint-plugin":"^6.7.5","@typescript-eslint/parser":"^6.7.5","babel-jest":"^29.4.1","crypto-browserify":"^3.12.0","dotenv":"^16.3.1","eslint":"^8.51.0","eslint-config-prettier":"^9.0.0","eslint-plugin-jsdoc":"^46.8.2","express":"^4.19.2","husky":"^8.0.0","jest":"^29.4.1","lint-staged":"^14.0.1","npm-run-all":"^4.1.5","playwright":"^1.43.1","prettier":"^2.0.5","pretty-quick":"^2.0.1","process":"^0.11.10","sinon":"^15.1.0","stream-browserify":"^3.0.0","ts-jest":"^29.0.5","ts-loader":"^9.4.2","ts-node":"^10.9.1","tslib":"^2.5.0","typescript":"^5.0.4","webpack":"^5.83.1","webpack-cli":"^5.1.1"},"dependencies":{"@stablelib/base64":"^2.0.0","@stablelib/utf8":"^2.0.0","@stellar/stellar-sdk":"15.0.1","axios":"^1.4.0","base64url":"^3.0.1","https-browserify":"^1.0.0","jws":"^4.0.0","lodash":"^4.17.21","query-string":"^7.1.3","stream-http":"^3.2.0","tweetnacl":"^1.0.3","url":"^0.11.0","util":"^0.12.5","utility-types":"^3.10.0","vm-browserify":"^1.1.2"},"scripts":{"test":"jest --watchAll","test:ci":"jest --ci","test:e2e:ci":"jest --config jest.e2e.config.js --ci","test:recovery:ci":"jest --config jest.integration.config.js recovery.test.ts --ci","test:anchorplatform:ci":"yarn jest --config jest.integration.config.js anchorplatform.test.ts --ci","build:web":"webpack --config webpack.config.js","build:node":"webpack --env NODE=true --config webpack.config.js","build":"run-p build:web build:node","example:sep10Server":"ts-node examples/sep10/sep10Server.ts","example:sep10Wallet":"ts-node examples/sep10/sep10Wallet.ts","example:sep24":"ts-node examples/sep24/sep24.ts","example:sep12":"ts-node examples/sep12/sep12.ts"}}');
56512
+ module.exports = JSON.parse('{"name":"@stellar/typescript-wallet-sdk","version":"3.0.1","engines":{"node":">=20"},"browser":"./lib/bundle_browser.js","main":"./lib/bundle.js","types":"./lib/index.d.ts","license":"Apache-2.0","private":false,"devDependencies":{"@babel/preset-env":"^7.20.2","@babel/preset-typescript":"^7.23.3","@stellar/prettier-config":"^1.0.1","@stellar/tsconfig":"^1.0.2","@types/jest":"^29.4.0","@types/lodash":"^4.14.194","@types/sinon":"^10.0.15","@typescript-eslint/eslint-plugin":"^6.7.5","@typescript-eslint/parser":"^6.7.5","babel-jest":"^29.4.1","crypto-browserify":"^3.12.0","dotenv":"^16.3.1","eslint":"^8.51.0","eslint-config-prettier":"^9.0.0","eslint-plugin-jsdoc":"^46.8.2","express":"^4.19.2","husky":"^8.0.0","jest":"^29.4.1","lint-staged":"^14.0.1","npm-run-all":"^4.1.5","playwright":"^1.43.1","prettier":"^2.0.5","pretty-quick":"^2.0.1","process":"^0.11.10","sinon":"^15.1.0","stream-browserify":"^3.0.0","ts-jest":"^29.0.5","ts-loader":"^9.4.2","ts-node":"^10.9.1","tslib":"^2.5.0","typescript":"^5.0.4","webpack":"^5.83.1","webpack-cli":"^5.1.1"},"dependencies":{"@stablelib/base64":"^2.0.0","@stablelib/utf8":"^2.0.0","@stellar/stellar-sdk":"15.0.1","axios":"^1.4.0","base64url":"^3.0.1","https-browserify":"^1.0.0","jws":"^4.0.0","lodash":"^4.17.21","query-string":"^7.1.3","stream-http":"^3.2.0","tweetnacl":"^1.0.3","url":"^0.11.0","util":"^0.12.5","utility-types":"^3.10.0","vm-browserify":"^1.1.2"},"scripts":{"test":"jest --watchAll","test:ci":"jest --ci","test:e2e:ci":"jest --config jest.e2e.config.js --ci","test:recovery:ci":"jest --config jest.integration.config.js recovery.test.ts --ci","test:anchorplatform:ci":"yarn jest --config jest.integration.config.js anchorplatform.test.ts --ci","build:web":"webpack --config webpack.config.js","build:node":"webpack --env NODE=true --config webpack.config.js","build":"run-p build:web build:node","example:sep10Server":"ts-node examples/sep10/sep10Server.ts","example:sep10Wallet":"ts-node examples/sep10/sep10Wallet.ts","example:sep24":"ts-node examples/sep24/sep24.ts","example:sep12":"ts-node examples/sep12/sep12.ts"}}');
56468
56513
 
56469
56514
  /***/ }),
56470
56515