You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/utils.ts
+32-2
Original file line number
Diff line number
Diff line change
@@ -29,11 +29,12 @@ export namespace Utils {
29
29
* @param {string} homeDomain The fully qualified domain name of the service requiring authentication
30
30
* @param {number} [timeout=300] Challenge duration (default to 5 minutes).
31
31
* @param {string} networkPassphrase The network passphrase. If you pass this argument then timeout is required.
32
+
* @param {string} webAuthDomain The fully qualified domain name of the service issuing the challenge.
32
33
* @example
33
34
* import { Utils, Keypair, Networks } from 'stellar-sdk'
34
35
*
35
36
* let serverKeyPair = Keypair.fromSecret("server-secret")
36
-
* let challenge = Utils.buildChallengeTx(serverKeyPair, "client-stellar-account-id", "SDF", 300, Networks.TESTNET)
37
+
* let challenge = Utils.buildChallengeTx(serverKeyPair, "client-stellar-account-id", "stellar.org", 300, Networks.TESTNET)
37
38
* @returns {string} A base64 encoded string of the raw TransactionEnvelope xdr struct for the transaction.
38
39
*/
39
40
exportfunctionbuildChallengeTx(
@@ -42,6 +43,7 @@ export namespace Utils {
42
43
homeDomain: string,
43
44
timeout: number=300,
44
45
networkPassphrase: string,
46
+
webAuthDomain: string,
45
47
): string{
46
48
if(clientAccountID.startsWith("M")){
47
49
throwError(
@@ -74,6 +76,13 @@ export namespace Utils {
74
76
source: clientAccountID,
75
77
}),
76
78
)
79
+
.addOperation(
80
+
Operation.manageData({
81
+
name: "web_auth_domain",
82
+
value: webAuthDomain,
83
+
source: account.accountId(),
84
+
}),
85
+
)
77
86
.build();
78
87
79
88
transaction.sign(serverKeypair);
@@ -103,13 +112,15 @@ export namespace Utils {
103
112
* @param {string} serverAccountID The server's stellar account (public key).
104
113
* @param {string} networkPassphrase The network passphrase, e.g.: 'Test SDF Network ; September 2015'.
105
114
* @param {string|string[]} [homeDomains] The home domain that is expected to be included in the first Manage Data operation's string key. If an array is provided, one of the domain names in the array must match.
115
+
* @param {string} webAuthDomain The home domain that is expected to be included as the value of the Manage Data operation with the 'web_auth_domain' key. If no such operation is included, this parameter is not used.
106
116
* @returns {Transaction|string|string} The actual transaction and the stellar public key (master key) used to sign the Manage Data operation, and matched home domain.
* @param {number} threshold The required signatures threshold for verifying this transaction.
267
291
* @param {ServerApi.AccountRecordSigners[]} signerSummary a map of all authorized signers to their weights. It's used to validate if the transaction signatures have met the given threshold.
268
292
* @param {string|string[]} [homeDomains] The home domain(s) that should be included in the first Manage Data operation's string key. Required in verifyChallengeTxSigners() => readChallengeTx().
293
+
* @param {string} webAuthDomain The home domain that is expected to be included as the value of the Manage Data operation with the 'web_auth_domain' key, if present. Used in verifyChallengeTxSigners() => readChallengeTx().
269
294
* @returns {string[]} The list of signers public keys that have signed the transaction, excluding the server account ID, given that the threshold was met.
* @param {string} networkPassphrase The network passphrase, e.g.: 'Test SDF Network ; September 2015'.
370
397
* @param {string[]} signers The signers public keys. This list should contain the public keys for all signers that have signed the transaction.
371
398
* @param {string|string[]} [homeDomains] The home domain(s) that should be included in the first Manage Data operation's string key. Required in readChallengeTx().
399
+
* @param {string} webAuthDomain The home domain that is expected to be included as the value of the Manage Data operation with the 'web_auth_domain' key, if present. Used in readChallengeTx().
372
400
* @returns {string[]} The list of signers public keys that have signed the transaction, excluding the server account ID.
373
401
* @example
374
402
*
@@ -406,13 +434,15 @@ export namespace Utils {
406
434
networkPassphrase: string,
407
435
signers: string[],
408
436
homeDomains: string|string[],
437
+
webAuthDomain: string,
409
438
): string[]{
410
439
// Read the transaction which validates its structure.
411
440
const{ tx }=readChallengeTx(
412
441
challengeTx,
413
442
serverAccountID,
414
443
networkPassphrase,
415
444
homeDomains,
445
+
webAuthDomain,
416
446
);
417
447
418
448
// Ensure the server account ID is an address and not a seed.
0 commit comments