@stellar/typescript-wallet-sdk 4.0.0 → 4.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.
package/CHANGELOG.MD CHANGED
@@ -1,3 +1,16 @@
1
+ # Release notes - Typescript Wallet SDK - 4.0.1
2
+
3
+ ### Changed
4
+ * `Server.signChallengeTransaction`: validate the challenge with `WebAuth.readChallengeTx`, as `Sep10.sign` already does, and verify it was issued for `accountKp` before signing (#250)
5
+ * `Server.signChallengeTransaction`: validation failures now throw `ChallengeValidationFailedError` instead of `ChallengeTxnInvalidSignatureError` (#250)
6
+
7
+ ### Added
8
+ * Optional `homeDomain` on `SignChallengeTxnParams`, accepting a string or an array of strings for anchors serving multiple home domains. Defaults to `anchorDomain` (#250)
9
+ * `ChallengeTxnClientAccountMismatchError`, exported via `Exceptions` (#250)
10
+
11
+ ### Deprecated
12
+ * `ChallengeTxnInvalidSignatureError` is no longer thrown and will be removed in the next major release. Catch `ChallengeValidationFailedError` instead (#250)
13
+
1
14
  # Release notes - Typescript Wallet SDK - 4.0.0
2
15
 
3
16
  ### BREAKING CHANGES
package/lib/bundle.js CHANGED
@@ -2234,7 +2234,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
2234
2234
  return (mod && mod.__esModule) ? mod : { "default": mod };
2235
2235
  };
2236
2236
  Object.defineProperty(exports, "__esModule", ({ value: true }));
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;
2237
+ exports.Sep7LongMsgError = exports.Sep7InvalidUriError = exports.AuthHeaderClientDomainRequiredError = exports.AuthHeaderSigningKeypairRequiredError = exports.DomainSigningModifiedError = exports.DefaultSignerDomainAccountError = exports.SigningKeypairMissingSecretError = exports.InvalidJsonError = exports.UnknownAnchorTransactionError = exports.AllowHttpOnNonTestnetError = exports.ChallengeTxnClientAccountMismatchError = 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 = void 0;
2238
2239
  var axios_1 = __importDefault(__webpack_require__(/*! axios */ "../../node_modules/axios/dist/node/axios.cjs"));
2239
2240
  var Utils_1 = __webpack_require__(/*! ../Utils */ "./src/walletSdk/Utils/index.ts");
2240
2241
  var ServerRequestFailedError = /** @class */ (function (_super) {
@@ -2628,6 +2629,12 @@ var ChallengeTxnIncorrectSequenceError = /** @class */ (function (_super) {
2628
2629
  return ChallengeTxnIncorrectSequenceError;
2629
2630
  }(Error));
2630
2631
  exports.ChallengeTxnIncorrectSequenceError = ChallengeTxnIncorrectSequenceError;
2632
+ /**
2633
+ * @deprecated No longer thrown. `Server.signChallengeTransaction` now validates
2634
+ * challenges with `WebAuth.readChallengeTx` and reports every failure, including
2635
+ * an invalid server signature, as `ChallengeValidationFailedError`. This class
2636
+ * will be removed in the next major release.
2637
+ */
2631
2638
  var ChallengeTxnInvalidSignatureError = /** @class */ (function (_super) {
2632
2639
  __extends(ChallengeTxnInvalidSignatureError, _super);
2633
2640
  function ChallengeTxnInvalidSignatureError() {
@@ -2638,6 +2645,17 @@ var ChallengeTxnInvalidSignatureError = /** @class */ (function (_super) {
2638
2645
  return ChallengeTxnInvalidSignatureError;
2639
2646
  }(Error));
2640
2647
  exports.ChallengeTxnInvalidSignatureError = ChallengeTxnInvalidSignatureError;
2648
+ var ChallengeTxnClientAccountMismatchError = /** @class */ (function (_super) {
2649
+ __extends(ChallengeTxnClientAccountMismatchError, _super);
2650
+ function ChallengeTxnClientAccountMismatchError(expected, received) {
2651
+ var _this = _super.call(this, "Challenge transaction client account mismatch: expected \"".concat(expected, "\" ") +
2652
+ "but challenge was issued for \"".concat(received, "\"")) || this;
2653
+ Object.setPrototypeOf(_this, ChallengeTxnClientAccountMismatchError.prototype);
2654
+ return _this;
2655
+ }
2656
+ return ChallengeTxnClientAccountMismatchError;
2657
+ }(Error));
2658
+ exports.ChallengeTxnClientAccountMismatchError = ChallengeTxnClientAccountMismatchError;
2641
2659
  var AllowHttpOnNonTestnetError = /** @class */ (function (_super) {
2642
2660
  __extends(AllowHttpOnNonTestnetError, _super);
2643
2661
  function AllowHttpOnNonTestnetError() {
@@ -4454,33 +4472,59 @@ var Utils_1 = __webpack_require__(/*! ../Utils */ "./src/walletSdk/Utils/index.t
4454
4472
  var Exceptions_1 = __webpack_require__(/*! ../Exceptions */ "./src/walletSdk/Exceptions/index.ts");
4455
4473
  /**
4456
4474
  * Helper method for signing a SEP-10 challenge transaction if valid.
4475
+ *
4476
+ * The challenge is validated with `WebAuth.readChallengeTx` from
4477
+ * `@stellar/stellar-sdk` — the same validator used by `Sep10.sign()` — which
4478
+ * checks the full SEP-10 structure and binds the challenge to the expected
4479
+ * anchor: the transaction source must be the anchor's `SIGNING_KEY`, the
4480
+ * `<home domain> auth` operation must match the expected home domain, and any
4481
+ * `web_auth_domain` operation must match the host of the anchor's
4482
+ * `WEB_AUTH_ENDPOINT` (falling back to `anchorDomain` when the TOML omits it).
4483
+ * The client account the challenge was issued for is then checked against
4484
+ * `accountKp`, so this helper only signs challenges meant for it. Muxed client
4485
+ * accounts are supported: the comparison is made on the underlying `G...`
4486
+ * address, since that is the key that signs. The muxed id itself is not pinned
4487
+ * — a caller that needs to bind a specific subaccount should check the
4488
+ * challenge's client account itself.
4489
+ *
4457
4490
  * @param {SignChallengeTxnParams} params - The Authentication params.
4458
4491
  * @param {AccountKeypair} params.accountKp - Keypair for the Stellar account signing the transaction.
4459
4492
  * @param {string} [params.challengeTx] - The challenge transaction given by an anchor for authentication.
4460
4493
  * @param {string} [params.networkPassphrase] - The network passphrase for the network authenticating on.
4461
4494
  * @param {string} [params.anchorDomain] - Domain hosting stellar.toml file containing `SIGNING_KEY`.
4495
+ * @param {string|string[]} [params.homeDomain] - Expected home domain(s) of the challenge. Defaults to `anchorDomain`.
4462
4496
  * @returns {Promise<SignChallengeTxnResponse>} The signed transaction.
4463
4497
  */
4464
4498
  var signChallengeTransaction = function (_a) {
4465
- var accountKp = _a.accountKp, challengeTx = _a.challengeTx, networkPassphrase = _a.networkPassphrase, anchorDomain = _a.anchorDomain;
4499
+ var accountKp = _a.accountKp, challengeTx = _a.challengeTx, networkPassphrase = _a.networkPassphrase, anchorDomain = _a.anchorDomain, homeDomain = _a.homeDomain;
4466
4500
  return __awaiter(void 0, void 0, void 0, function () {
4467
- var tx, tomlResp, parsedToml, anchorKp, isValid;
4468
- return __generator(this, function (_b) {
4469
- switch (_b.label) {
4501
+ var parsedTx, tomlResp, _b, signingKey, webAuthEndpoint, tx, clientAccountID, webAuthDomain;
4502
+ var _c;
4503
+ return __generator(this, function (_d) {
4504
+ switch (_d.label) {
4470
4505
  case 0:
4471
- tx = stellar_sdk_1.TransactionBuilder.fromXDR(challengeTx, networkPassphrase);
4472
- if (parseInt(tx.sequence) !== 0) {
4506
+ parsedTx = stellar_sdk_1.TransactionBuilder.fromXDR(challengeTx, networkPassphrase);
4507
+ if (parseInt(parsedTx.sequence) !== 0) {
4473
4508
  throw new Exceptions_1.ChallengeTxnIncorrectSequenceError();
4474
4509
  }
4475
4510
  return [4 /*yield*/, stellar_sdk_1.StellarToml.Resolver.resolve(anchorDomain)];
4476
4511
  case 1:
4477
- tomlResp = _b.sent();
4478
- parsedToml = (0, Utils_1.parseToml)(tomlResp);
4479
- anchorKp = stellar_sdk_1.Keypair.fromPublicKey(parsedToml.signingKey);
4480
- isValid = tx.signatures.length &&
4481
- anchorKp.verify(tx.hash(), tx.signatures[0].signature());
4482
- if (!isValid) {
4483
- throw new Exceptions_1.ChallengeTxnInvalidSignatureError();
4512
+ tomlResp = _d.sent();
4513
+ _b = (0, Utils_1.parseToml)(tomlResp), signingKey = _b.signingKey, webAuthEndpoint = _b.webAuthEndpoint;
4514
+ try {
4515
+ webAuthDomain = webAuthEndpoint
4516
+ ? new URL(webAuthEndpoint).hostname
4517
+ : anchorDomain;
4518
+ (_c = stellar_sdk_1.WebAuth.readChallengeTx(challengeTx, signingKey, networkPassphrase, homeDomain !== null && homeDomain !== void 0 ? homeDomain : anchorDomain, webAuthDomain), tx = _c.tx, clientAccountID = _c.clientAccountID);
4519
+ }
4520
+ catch (e) {
4521
+ throw new Exceptions_1.ChallengeValidationFailedError(e instanceof Error ? e : new Error(String(e)));
4522
+ }
4523
+ // readChallengeTx returns the operation source verbatim, which is an `M...`
4524
+ // address for a muxed client account. accountKp.publicKey is always the
4525
+ // underlying `G...` key, so compare base addresses.
4526
+ if ((0, stellar_sdk_1.extractBaseAddress)(clientAccountID) !== accountKp.publicKey) {
4527
+ throw new Exceptions_1.ChallengeTxnClientAccountMismatchError(accountKp.publicKey, clientAccountID);
4484
4528
  }
4485
4529
  accountKp.sign(tx);
4486
4530
  return [2 /*return*/, {
@@ -54261,7 +54305,7 @@ function includes(array, value) {
54261
54305
  /***/ ((module) => {
54262
54306
 
54263
54307
  "use strict";
54264
- module.exports = JSON.parse('{"name":"@stellar/typescript-wallet-sdk","version":"4.0.0","engines":{"node":">=22"},"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","smol-toml":"^1.7.1","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":"16.2.0","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"}}');
54308
+ module.exports = JSON.parse('{"name":"@stellar/typescript-wallet-sdk","version":"4.0.1","engines":{"node":">=22"},"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","smol-toml":"^1.7.1","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":"16.2.0","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"}}');
54265
54309
 
54266
54310
  /***/ }),
54267
54311