@stellar/typescript-wallet-sdk 3.0.0-beta.1776280959813 → 3.0.0-beta.1779920488639
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.
- package/CHANGELOG.MD +1 -1
- package/lib/bundle.js +68 -34
- package/lib/bundle.js.map +1 -1
- package/lib/bundle_browser.js +68 -34
- package/lib/bundle_browser.js.map +1 -1
- package/lib/walletSdk/Exceptions/index.d.ts +3 -0
- package/package.json +1 -1
- package/src/walletSdk/Auth/index.ts +21 -8
- package/src/walletSdk/Exceptions/index.ts +9 -0
- package/src/walletSdk/Horizon/Stellar.ts +32 -12
- package/test/auth.test.ts +104 -1
- package/test/stellar.test.ts +121 -1
package/CHANGELOG.MD
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
### BREAKING CHANGES
|
|
4
4
|
* Upgraded `@stellar/stellar-sdk` from `14.5.0` to `15.0.1` — Protocol 26 support
|
|
5
|
-
* XDR integer construction now throws on overflow/underflow (upstream change)
|
|
6
5
|
* `TransactionBase.networkPassphrase` setter now throws to enforce immutability (upstream change)
|
|
6
|
+
* XDR integer strict validation: i64/u64 `fromString()` throws on overflow/underflow, i32/u32 throws at XDR serialization (upstream change)
|
|
7
7
|
|
|
8
8
|
# Release notes - Typescript Wallet SDK - 2.0.0
|
|
9
9
|
|
package/lib/bundle.js
CHANGED
|
@@ -1857,9 +1857,9 @@ var Sep10 = /** @class */ (function () {
|
|
|
1857
1857
|
Sep10.prototype.sign = function (_a) {
|
|
1858
1858
|
var accountKp = _a.accountKp, challengeResponse = _a.challengeResponse, walletSigner = _a.walletSigner;
|
|
1859
1859
|
return __awaiter(this, void 0, void 0, function () {
|
|
1860
|
-
var networkPassphrase, webAuthDomain, transaction,
|
|
1861
|
-
return __generator(this, function (
|
|
1862
|
-
switch (
|
|
1860
|
+
var networkPassphrase, webAuthDomain, transaction, hasClientDomain, originalHash, returned;
|
|
1861
|
+
return __generator(this, function (_b) {
|
|
1862
|
+
switch (_b.label) {
|
|
1863
1863
|
case 0:
|
|
1864
1864
|
networkPassphrase = this.cfg.stellar.network;
|
|
1865
1865
|
if (challengeResponse.network_passphrase &&
|
|
@@ -1874,24 +1874,26 @@ var Sep10 = /** @class */ (function () {
|
|
|
1874
1874
|
throw new Exceptions_1.ChallengeValidationFailedError(e instanceof Error ? e : new Error(String(e)));
|
|
1875
1875
|
}
|
|
1876
1876
|
transaction = stellar_sdk_1.TransactionBuilder.fromXDR(challengeResponse.transaction, networkPassphrase);
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
if (!(_i < _b.length)) return [3 /*break*/, 4];
|
|
1881
|
-
op = _b[_i];
|
|
1882
|
-
if (!(op.type === "manageData" && op.name === "client_domain")) return [3 /*break*/, 3];
|
|
1877
|
+
hasClientDomain = transaction.operations.some(function (op) { return op.type === "manageData" && op.name === "client_domain"; });
|
|
1878
|
+
if (!hasClientDomain) return [3 /*break*/, 2];
|
|
1879
|
+
originalHash = transaction.hash();
|
|
1883
1880
|
return [4 /*yield*/, walletSigner.signWithDomainAccount({
|
|
1884
1881
|
transactionXDR: challengeResponse.transaction,
|
|
1885
1882
|
networkPassphrase: networkPassphrase,
|
|
1886
1883
|
accountKp: accountKp,
|
|
1887
1884
|
})];
|
|
1885
|
+
case 1:
|
|
1886
|
+
returned = _b.sent();
|
|
1887
|
+
// Transaction.hash() covers the envelope body but excludes signatures, so
|
|
1888
|
+
// a domain signer that only appends its signature preserves the hash. Any
|
|
1889
|
+
// change to the operations, source account, memo, or other body fields
|
|
1890
|
+
// changes the hash and is rejected here.
|
|
1891
|
+
if (!returned.hash().equals(originalHash)) {
|
|
1892
|
+
throw new Exceptions_1.DomainSigningModifiedError();
|
|
1893
|
+
}
|
|
1894
|
+
transaction = returned;
|
|
1895
|
+
_b.label = 2;
|
|
1888
1896
|
case 2:
|
|
1889
|
-
transaction = _c.sent();
|
|
1890
|
-
_c.label = 3;
|
|
1891
|
-
case 3:
|
|
1892
|
-
_i++;
|
|
1893
|
-
return [3 /*break*/, 1];
|
|
1894
|
-
case 4:
|
|
1895
1897
|
walletSigner.signWithClientAccount({ transaction: transaction, accountKp: accountKp });
|
|
1896
1898
|
return [2 /*return*/, transaction];
|
|
1897
1899
|
}
|
|
@@ -2232,7 +2234,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
2232
2234
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
2233
2235
|
};
|
|
2234
2236
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
2235
|
-
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;
|
|
2237
|
+
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;
|
|
2236
2238
|
var axios_1 = __importDefault(__webpack_require__(/*! axios */ "../../node_modules/axios/dist/node/axios.cjs"));
|
|
2237
2239
|
var Utils_1 = __webpack_require__(/*! ../Utils */ "./src/walletSdk/Utils/index.ts");
|
|
2238
2240
|
var ServerRequestFailedError = /** @class */ (function (_super) {
|
|
@@ -2686,6 +2688,16 @@ var DefaultSignerDomainAccountError = /** @class */ (function (_super) {
|
|
|
2686
2688
|
return DefaultSignerDomainAccountError;
|
|
2687
2689
|
}(Error));
|
|
2688
2690
|
exports.DefaultSignerDomainAccountError = DefaultSignerDomainAccountError;
|
|
2691
|
+
var DomainSigningModifiedError = /** @class */ (function (_super) {
|
|
2692
|
+
__extends(DomainSigningModifiedError, _super);
|
|
2693
|
+
function DomainSigningModifiedError() {
|
|
2694
|
+
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;
|
|
2695
|
+
Object.setPrototypeOf(_this, DomainSigningModifiedError.prototype);
|
|
2696
|
+
return _this;
|
|
2697
|
+
}
|
|
2698
|
+
return DomainSigningModifiedError;
|
|
2699
|
+
}(Error));
|
|
2700
|
+
exports.DomainSigningModifiedError = DomainSigningModifiedError;
|
|
2689
2701
|
var AuthHeaderSigningKeypairRequiredError = /** @class */ (function (_super) {
|
|
2690
2702
|
__extends(AuthHeaderSigningKeypairRequiredError, _super);
|
|
2691
2703
|
function AuthHeaderSigningKeypairRequiredError() {
|
|
@@ -3013,6 +3025,12 @@ var TransactionBuilder_1 = __webpack_require__(/*! ./Transaction/TransactionBuil
|
|
|
3013
3025
|
var Exceptions_1 = __webpack_require__(/*! ../Exceptions */ "./src/walletSdk/Exceptions/index.ts");
|
|
3014
3026
|
var getResultCode_1 = __webpack_require__(/*! ../Utils/getResultCode */ "./src/walletSdk/Utils/getResultCode.ts");
|
|
3015
3027
|
var Account_1 = __webpack_require__(/*! ./Account */ "./src/walletSdk/Horizon/Account.ts");
|
|
3028
|
+
var SUBMIT_504_MAX_RETRIES = 5;
|
|
3029
|
+
var SUBMIT_504_BASE_DELAY_MS = 1000;
|
|
3030
|
+
var SUBMIT_504_MAX_DELAY_MS = 30000;
|
|
3031
|
+
var sleep = function (ms) {
|
|
3032
|
+
return new Promise(function (resolve) { return setTimeout(resolve, ms); });
|
|
3033
|
+
};
|
|
3016
3034
|
/**
|
|
3017
3035
|
* Interaction with the Stellar Network.
|
|
3018
3036
|
* Do not create this object directly, use the Wallet class.
|
|
@@ -3096,30 +3114,45 @@ var Stellar = /** @class */ (function () {
|
|
|
3096
3114
|
* @throws {TransactionSubmitFailedError} If the transaction submission fails.
|
|
3097
3115
|
*/
|
|
3098
3116
|
Stellar.prototype.submitTransaction = function (signedTransaction) {
|
|
3117
|
+
var _a;
|
|
3099
3118
|
return __awaiter(this, void 0, void 0, function () {
|
|
3100
|
-
var response, e_2;
|
|
3101
|
-
return __generator(this, function (
|
|
3102
|
-
switch (
|
|
3119
|
+
var lastError, attempt, response, e_2, cappedDelay, jitter;
|
|
3120
|
+
return __generator(this, function (_b) {
|
|
3121
|
+
switch (_b.label) {
|
|
3103
3122
|
case 0:
|
|
3104
|
-
|
|
3105
|
-
|
|
3123
|
+
attempt = 0;
|
|
3124
|
+
_b.label = 1;
|
|
3106
3125
|
case 1:
|
|
3107
|
-
|
|
3126
|
+
if (!(attempt <= SUBMIT_504_MAX_RETRIES)) return [3 /*break*/, 7];
|
|
3127
|
+
_b.label = 2;
|
|
3128
|
+
case 2:
|
|
3129
|
+
_b.trys.push([2, 4, , 6]);
|
|
3130
|
+
return [4 /*yield*/, this.server.submitTransaction(signedTransaction)];
|
|
3131
|
+
case 3:
|
|
3132
|
+
response = _b.sent();
|
|
3108
3133
|
if (!response.successful) {
|
|
3109
3134
|
throw new Exceptions_1.TransactionSubmitFailedError(response);
|
|
3110
3135
|
}
|
|
3111
3136
|
return [2 /*return*/, true];
|
|
3112
|
-
case
|
|
3113
|
-
e_2 =
|
|
3114
|
-
if (
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3137
|
+
case 4:
|
|
3138
|
+
e_2 = _b.sent();
|
|
3139
|
+
if (((_a = e_2 === null || e_2 === void 0 ? void 0 : e_2.response) === null || _a === void 0 ? void 0 : _a.status) !== 504) {
|
|
3140
|
+
throw e_2;
|
|
3141
|
+
}
|
|
3142
|
+
lastError = e_2;
|
|
3143
|
+
if (attempt === SUBMIT_504_MAX_RETRIES) {
|
|
3144
|
+
return [3 /*break*/, 7];
|
|
3145
|
+
}
|
|
3146
|
+
cappedDelay = Math.min(SUBMIT_504_BASE_DELAY_MS * Math.pow(2, attempt), SUBMIT_504_MAX_DELAY_MS);
|
|
3147
|
+
jitter = Math.random() * (cappedDelay / 2);
|
|
3148
|
+
return [4 /*yield*/, sleep(cappedDelay + jitter)];
|
|
3149
|
+
case 5:
|
|
3150
|
+
_b.sent();
|
|
3151
|
+
return [3 /*break*/, 6];
|
|
3152
|
+
case 6:
|
|
3153
|
+
attempt++;
|
|
3154
|
+
return [3 /*break*/, 1];
|
|
3155
|
+
case 7: throw lastError;
|
|
3123
3156
|
}
|
|
3124
3157
|
});
|
|
3125
3158
|
});
|
|
@@ -3180,7 +3213,7 @@ var Stellar = /** @class */ (function () {
|
|
|
3180
3213
|
resultCode = (0, getResultCode_1.getResultCode)(e_3);
|
|
3181
3214
|
if (resultCode === "tx_too_late") {
|
|
3182
3215
|
newFee = parseInt(transaction.fee) + baseFeeIncrease;
|
|
3183
|
-
if (maxFee && newFee > maxFee) {
|
|
3216
|
+
if (maxFee !== undefined && newFee > maxFee) {
|
|
3184
3217
|
throw new Exceptions_1.TransactionSubmitWithFeeIncreaseFailedError(maxFee, e_3);
|
|
3185
3218
|
}
|
|
3186
3219
|
return [2 /*return*/, this.submitWithFeeIncrease({
|
|
@@ -3191,6 +3224,7 @@ var Stellar = /** @class */ (function () {
|
|
|
3191
3224
|
signerFunction: signerFunction,
|
|
3192
3225
|
baseFee: newFee,
|
|
3193
3226
|
memo: memo,
|
|
3227
|
+
maxFee: maxFee,
|
|
3194
3228
|
})];
|
|
3195
3229
|
}
|
|
3196
3230
|
throw e_3;
|