Skip to content

Commit

Permalink
some fine-tuning and tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ElliotFriend committed Sep 20, 2024
1 parent a18da01 commit f5652ed
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 36 deletions.
6 changes: 2 additions & 4 deletions src/contract/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,9 @@ function unionToJsonSchema(udt: xdr.ScSpecUdtUnionV0): any {
* Provides a ContractSpec class which can contains the XDR types defined by the contract.
* This allows the class to be used to convert between native and raw `xdr.ScVal`s.
*
* Constructs a new ContractSpec from an array of XDR spec entries.
*
* @memberof module:contract
* @class
* @param {xdr.ScSpecEntry[] | string[]} entries the XDR spec entries
* @throws {Error} if entries is invalid
*
Expand Down Expand Up @@ -470,9 +471,6 @@ export class Spec {
*/
public entries: xdr.ScSpecEntry[] = [];

/**
* Constructs a new ContractSpec from an array of XDR spec entries.
*/
constructor(entries: xdr.ScSpecEntry[] | string[]) {
if (entries.length === 0) {
throw new Error("Contract spec must have at least one entry");
Expand Down
44 changes: 21 additions & 23 deletions src/horizon/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import AxiosClient, {
* @default 60000
* @memberof module:Horizon.Server
*/
export const SUBMIT_TRANSACTION_TIMEOUT = 60 * 1000;
export const SUBMIT_TRANSACTION_TIMEOUT: number = 60 * 1000;

const STROOPS_IN_LUMEN = 10000000;

Expand All @@ -64,18 +64,18 @@ function getAmountInLumens(amt: BigNumber) {
/**
* Server handles the network connection to a [Horizon](https://developers.stellar.org/docs/data/horizon)
* instance and exposes an interface for requests to that instance.
*
* @class
* @alias module:Horizon.Server
* @memberof module:Horizon
*
* @param {string} serverURL Horizon Server URL (ex. `https://horizon-testnet.stellar.org`).
* @param {Options} [opts] Options object
* @param {module:Horizon.Server.Options} [opts] Options object
*/
export class HorizonServer {
/**
* serverURL Horizon Server URL (ex. `https://horizon-testnet.stellar.org`).
* Horizon Server URL (ex. `https://horizon-testnet.stellar.org`)
*
* TODO: Solve `URI(this.serverURL as any)`.
* @todo Solve `URI(this.serverURL as any)`.
*/
public readonly serverURL: URI;

Expand Down Expand Up @@ -128,22 +128,20 @@ export class HorizonServer {
* not when you build or submit the transaction! So give yourself enough time to get
* the transaction built and signed before submitting.
*
* Example:
*
* ```javascript
* @example
* const transaction = new StellarSdk.TransactionBuilder(accountId, {
* fee: await StellarSdk.Server.fetchBaseFee(),
* timebounds: await StellarSdk.Server.fetchTimebounds(100)
* fee: await StellarSdk.Server.fetchBaseFee(),
* timebounds: await StellarSdk.Server.fetchTimebounds(100)
* })
* .addOperation(operation)
* // normally we would need to call setTimeout here, but setting timebounds
* // earlier does the trick!
* .build();
* ```
* .addOperation(operation)
* // normally we would need to call setTimeout here, but setting timebounds
* // earlier does the trick!
* .build();
*
* @param {number} seconds Number of seconds past the current time to wait.
* @param {boolean} [_isRetry] True if this is a retry. Only set this internally!
* This is to avoid a scenario where Horizon is horking up the wrong date.
* @returns {Promise<HorizonServer.Timebounds>} Promise that resolves a `timebounds` object
* @returns {Promise<Timebounds>} Promise that resolves a `timebounds` object
* (with the shape `{ minTime: 0, maxTime: N }`) that you can set the `timebounds` option to.
*/
public async fetchTimebounds(
Expand Down Expand Up @@ -594,15 +592,15 @@ export class HorizonServer {
/**
* People on the Stellar network can make offers to buy or sell assets. This endpoint represents all the offers on the DEX.
*
* You can query all offers for account using the function `.accountId`:
* You can query all offers for account using the function `.accountId`.
*
* ```
* @example
* server.offers()
* .forAccount(accountId).call()
* .then(function(offers) {
* console.log(offers);
* });
* ```
* .forAccount(accountId).call()
* .then(function(offers) {
* console.log(offers);
* });
*
* @returns {OfferCallBuilder} New {@link OfferCallBuilder} object
*/
public offers(): OfferCallBuilder {
Expand Down
29 changes: 20 additions & 9 deletions src/webauth/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Stellar Web Authentication
* @module WebAuth
* @see {@link https://stellar.org/protocol-10 | SEP-10 Specification}
*/

import randomBytes from "randombytes";
import {
Account,
Expand All @@ -17,8 +23,6 @@ import { Utils } from "../utils";
import { InvalidChallengeError } from "./errors";
import { ServerApi } from "../horizon/server_api";

/** @module WebAuth */

/**
* Returns a valid {@link https://stellar.org/protocol/sep-10 | SEP-10}
* challenge transaction which you can use for Stellar Web Authentication.
Expand Down Expand Up @@ -137,12 +141,19 @@ export function buildChallengeTx(
}

/**
* @typedef {object} ChallengeTxParts A parsed and validated challenge transaction, and some of its constituent details.
* @property {Transaction} tx The challenge transaction.
* @property {string} clientAccountID The Stellar public key (master key) used to sign the Manage Data operation.
* @property {string} matchedHomeDomain The matched home domain.
* @property {string | null} [memo=null] The memo attached to the transaction, which will be null if not present
* A parsed and validated challenge transaction, and some of its constituent details.
* @memberof module:WebAuth
*/
export type ChallengeTxDetails = {
/** The challenge transaction. */
tx: Transaction;
/** The Stellar public key (master key) used to sign the Manage Data operation. */
clientAccountId: string;
/** The matched home domain. */
matchedHomeDomain: string;
/** The memo attached to the transaction, which will be null if not present */
memo?: string;
}

/**
* Reads a SEP-10 challenge transaction and returns the decoded transaction and
Expand All @@ -167,7 +178,7 @@ export function buildChallengeTx(
* @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.
* @returns {module:WebAuth~ChallengeTxParts} The actual transaction and the
* @returns {module:WebAuth.ChallengeTxDetails} The actual transaction and the
* Stellar public key (master key) used to sign the Manage Data operation,
* the matched home domain, and the memo attached to the transaction, which
* will be null if not present.
Expand Down Expand Up @@ -579,7 +590,7 @@ export function verifyChallengeTxSigners(
serverKP = Keypair.fromPublicKey(serverAccountID); // can throw 'Invalid Stellar public key'
} catch (err: any) {
throw new Error(
`Couldn't infer keypair from the provided 'serverAccountID': ${
`Couldn't infer keypair from the provided 'serverAccountID': ${
err.message}`,
);
}
Expand Down

0 comments on commit f5652ed

Please sign in to comment.