casper-js-sdk
Version:
SDK to interact with the Casper blockchain
205 lines (204 loc) • 8.64 kB
TypeScript
import { Hash } from './key';
import { PublicKey, PrivateKey } from './keypair';
import { Duration, Timestamp } from './Time';
import { Approval, Transaction } from './Transaction';
import { ExecutableDeployItem } from './ExecutableDeployItem';
import { CLValue } from './clvalue';
/**
* Represents the header of a deploy in the blockchain.
* The header contains metadata such as the account initiating the deploy, the body hash, gas price, timestamp, TTL, and dependencies.
*/
export declare class DeployHeader {
/**
* The public key of the account initiating the deploy.
* This key is used to verify the identity of the account making the deploy request.
*/
account?: PublicKey;
/**
* The hash of the body of the deploy, which is used to verify the contents of the deploy.
* The body contains the session logic and payment logic of the deploy.
*/
bodyHash?: Hash;
/**
* The name of the blockchain chain that the deploy is associated with.
* This helps prevent the deploy from being accidentally or maliciously included in a different chain.
*/
chainName: string;
/**
* A list of other deploys that must be executed before this one.
* This ensures dependencies are executed in the correct order.
*/
dependencies: Hash[];
/**
* The price of gas for executing the deploy.
* Gas is used to pay for the computational resources required to process the deploy.
*/
gasPrice: number;
/**
* The timestamp when the deploy was created.
* This timestamp is used to determine the deploy's position in time.
*/
timestamp: Timestamp;
/**
* The time-to-live (TTL) for the deploy, after which it will expire if not executed.
* The default TTL is 30 minutes.
*/
ttl: Duration;
/**
* Constructs a `DeployHeader` instance with the specified parameters.
* @param chainName The name of the blockchain chain.
* @param dependencies A list of deploys that must be executed before this one.
* @param gasPrice The gas price for the deploy.
* @param timestamp The timestamp when the deploy is created.
* @param ttl The TTL for the deploy.
* @param account The public key of the account initiating the deploy (optional).
* @param bodyHash The hash of the body of the deploy (optional).
*/
constructor(chainName?: string, dependencies?: Hash[], gasPrice?: number, timestamp?: Timestamp, ttl?: Duration, account?: PublicKey, bodyHash?: Hash);
/**
* Converts the deploy header to a byte array for transmission or storage.
* @returns A `Uint8Array` representing the deploy header in byte format.
*/
toBytes(): Uint8Array;
/**
* Returns a default `DeployHeader` instance with default values.
* @returns A `DeployHeader` instance with default values.
*/
static default(): DeployHeader;
}
/**
* Represents a deploy in the blockchain, including the header, payment, session, and approvals.
* A `Deploy` object is used to package the logic for executing a contract, payment, or transfer on the blockchain.
*/
export declare class Deploy {
/**
* A list of approvals, including signatures from accounts that have approved the deploy.
*/
approvals: Approval[];
/**
* The unique hash that identifies this deploy. This hash is used to verify the integrity of the deploy.
*/
hash: Hash;
/**
* The header of the deploy, which contains metadata such as the account, gas price, timestamp, and TTL.
*/
header: DeployHeader;
/**
* The executable item representing the payment logic of the deploy.
*/
payment: ExecutableDeployItem;
/**
* The executable item representing the session logic of the deploy.
*/
session: ExecutableDeployItem;
/**
* Constructs a `Deploy` object.
*
* @param hash The deploy hash identifying this deploy.
* @param header The deploy header containing metadata.
* @param payment The executable deploy item representing the payment logic.
* @param session The executable deploy item representing the session logic.
* @param approvals An array of signatures and accounts who have approved this deploy.
*/
constructor(hash: Hash, header: DeployHeader, payment: ExecutableDeployItem, session: ExecutableDeployItem, approvals: Approval[]);
/**
* Validates the deploy by checking its body hash, deploy hash, and approval signatures.
*
* @returns `true` if the deploy is valid, otherwise throws an error.
*/
validate(): boolean;
/**
* Signs the deploy with a given private key and adds the signature to the approvals list.
*
* @param keys The private key used to sign the deploy.
*/
sign(keys: PrivateKey): void;
/**
* Converts the deploy object into a byte array for transmission or storage.
*
* @returns A `Uint8Array` representing the deploy in byte format.
*/
toBytes(): Uint8Array;
/**
* Sets an already generated signature for the deploy.
*
* @param deploy The deploy instance.
* @param signature The Ed25519 or Secp256K1 signature.
* @param publicKey The public key used to generate the signature.
* @returns A new `Deploy` instance with the added signature.
*/
static setSignature(deploy: Deploy, signature: Uint8Array, publicKey: PublicKey): Deploy;
/**
* Creates a new `Deploy` instance with the provided parameters.
*
* @param hash The deploy hash identifying this deploy.
* @param header The deploy header.
* @param payment The executable deploy item for the payment logic.
* @param session The executable deploy item for the session logic.
* @param approvals An array of approvals for the deploy.
* @returns A new `Deploy` object.
*/
static createNew(hash: Hash, header: DeployHeader, payment: ExecutableDeployItem, session: ExecutableDeployItem, approvals?: Approval[]): Deploy;
/**
* Adds a runtime argument to a `Deploy` object
* @param deploy The `Deploy` object for which to add the runtime argument
* @param name The name of the runtime argument
* @param value The value of the runtime argument
* @returns The original `Deploy` with the additional runtime argument
* @remarks Will fail if the `Deploy` has already been signed
*/
static addArgToDeploy(deploy: Deploy, name: string, value: CLValue): Deploy;
/**
* Creates a `Deploy` instance from the deploy header and session/payment logic.
*
* @param deployHeader The deploy header.
* @param payment The payment logic of the deploy.
* @param session The session logic of the deploy.
* @returns A new `Deploy` object.
*/
static makeDeploy(deployHeader: DeployHeader, payment: ExecutableDeployItem, session: ExecutableDeployItem): Deploy;
/**
* Converts the `Deploy` into a `Transaction` object.
* This method creates a transaction based on the deploy, including its payment and session logic.
*
* @param deploy The deploy object.
* @returns A new `Transaction` object created from the deploy.
*/
static newTransactionFromDeploy(deploy: Deploy): Transaction;
/**
* Converts a JSON representation of a deploy to a `Deploy` object.
*
* @param json The JSON representation of a `Deploy`.
* @returns A `Deploy` object if successful, or throws an error if parsing fails.
*/
static fromJSON(json: any): Deploy;
/**
* Converts the `Deploy` object into a JSON representation.
*
* @param deploy The deploy object to convert to JSON.
* @returns A JSON representation of the deploy.
*/
static toJSON: (deploy: Deploy) => import("typedjson").JsonTypes;
/**
* Identifies whether this `Deploy` represents a transfer of CSPR.
*
* @returns `true` if the deploy is a transfer, otherwise `false`.
*/
isTransfer(): boolean;
/**
* Identifies whether this `Deploy` represents a standard payment, like a gas payment.
*
* @returns `true` if the deploy is a standard payment, otherwise `false`.
*/
isStandardPayment(): boolean;
/**
* Gets the byte-size of a deploy
* @param deploy The `Deploy` for which to calculate the size
* @returns The size of the `Deploy` in its serialized representation
*/
static getDeploySizeInBytes: (deploy: Deploy) => number;
}
/**
* Default TTL value used for deploys (30 minutes).
*/
export declare const DEFAULT_DEPLOY_TTL = 1800000;