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.
261
285
* @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.
262
286
* @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().
287
+
* @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().
263
288
* @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'.
364
391
* @param {string[]} signers The signers public keys. This list should contain the public keys for all signers that have signed the transaction.
365
392
* @param {string|string[]} [homeDomains] The home domain(s) that should be included in the first Manage Data operation's string key. Required in readChallengeTx().
393
+
* @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().
366
394
* @returns {string[]} The list of signers public keys that have signed the transaction, excluding the server account ID.
367
395
* @example
368
396
*
@@ -400,13 +428,15 @@ export namespace Utils {
400
428
networkPassphrase: string,
401
429
signers: string[],
402
430
homeDomains: string|string[],
431
+
webAuthDomain: string,
403
432
): string[]{
404
433
// Read the transaction which validates its structure.
405
434
const{ tx }=readChallengeTx(
406
435
challengeTx,
407
436
serverAccountID,
408
437
networkPassphrase,
409
438
homeDomains,
439
+
webAuthDomain,
410
440
);
411
441
412
442
// Ensure the server account ID is an address and not a seed.
0 commit comments