@dfinity/agent
Version:
JavaScript and TypeScript library to interact with the Internet Computer
52 lines • 2.43 kB
TypeScript
import { type HttpAgentRequestTransformFn, type HttpHeaderField, type Nonce } from './types.ts';
export declare const JSON_KEY_EXPIRY = "__expiry__";
export type JsonnableExpiry = {
[JSON_KEY_EXPIRY]: string;
};
export declare class Expiry {
private readonly __expiry__;
readonly _isExpiry = true;
private constructor();
/**
* Creates an Expiry object from a delta in milliseconds.
* If the delta is less than 90 seconds, the expiry is rounded down to the nearest second.
* Otherwise, the expiry is rounded down to the nearest minute.
* @param deltaInMs The milliseconds to add to the current time.
* @param clockDriftMs The milliseconds to add to the current time, typically the clock drift between IC network clock and the client's clock. Defaults to `0` if not provided.
* @returns {Expiry} The constructed Expiry object.
*/
static fromDeltaInMilliseconds(deltaInMs: number, clockDriftMs?: number): Expiry;
toBigInt(): bigint;
toHash(): Uint8Array;
toString(): string;
/**
* Serializes to JSON
* @returns {JsonnableExpiry} a JSON object with a single key, {@link JSON_KEY_EXPIRY}, whose value is the expiry as a string
*/
toJSON(): JsonnableExpiry;
/**
* Deserializes a {@link JsonnableExpiry} object from a JSON string.
* @param input The JSON string to deserialize.
* @returns {Expiry} The deserialized Expiry object.
*/
static fromJSON(input: string): Expiry;
static isExpiry(other: unknown): other is Expiry;
}
/**
* Create a Nonce transform, which takes a function that returns a Buffer, and adds it
* as the nonce to every call requests.
* @param nonceFn A function that returns a buffer. By default uses a semi-random method.
*/
export declare function makeNonceTransform(nonceFn?: () => Nonce): HttpAgentRequestTransformFn;
/**
* Create a transform that adds a delay (by default 5 minutes) to the expiry.
* @param delayInMilliseconds The delay to add to the call time, in milliseconds.
*/
export declare function makeExpiryTransform(delayInMilliseconds: number): HttpAgentRequestTransformFn;
/**
* Maps the default fetch headers field to the serializable HttpHeaderField.
* @param headers Fetch definition of the headers type
* @returns array of header fields
*/
export declare function httpHeadersTransform(headers: Headers): HttpHeaderField[];
//# sourceMappingURL=transforms.d.ts.map