@aptos-labs/ts-sdk
Version:
Aptos TypeScript SDK
242 lines (239 loc) • 10.5 kB
text/typescript
import { AptosConfig } from '../api/aptosConfig.mjs';
import { MoveVector, MoveOption, MoveString } from '../bcs/serializable/moveStructs.mjs';
import { Bool, U8, U16, U32, U64, U128, U256 } from '../bcs/serializable/movePrimitives.mjs';
import { FixedBytes } from '../bcs/serializable/fixedBytes.mjs';
import { AccountAddress, AccountAddressInput } from '../core/accountAddress.mjs';
import { AnyNumber, MoveFunctionId, HexInput, MoveFunctionGenericTypeParam } from '../types/index.mjs';
import { P as PublicKey } from '../publicKey-B3XRNhHO.mjs';
import { RawTransaction, MultiAgentRawTransaction, FeePayerRawTransaction } from './instances/rawTransaction.mjs';
import { AccountAuthenticator } from './authenticator/account.mjs';
import { TransactionPayloadEntryFunction, TransactionPayloadScript, TransactionPayloadMultiSig } from './instances/transactionPayload.mjs';
import { SimpleTransaction } from './instances/simpleTransaction.mjs';
import { MultiAgentTransaction } from './instances/multiAgentTransaction.mjs';
import { TypeTag } from './typeTag/index.mjs';
import '../utils/apiEndpoints.mjs';
import '../utils/const.mjs';
import '../types/indexer.mjs';
import '../types/generated/operations.mjs';
import '../types/generated/types.mjs';
import '../bcs/serializer.mjs';
import '../core/hex.mjs';
import '../core/common.mjs';
import '../bcs/deserializer.mjs';
import './instances/transactionArgument.mjs';
import '../core/crypto/signature.mjs';
import './instances/chainId.mjs';
import './instances/identifier.mjs';
import './instances/moduleId.mjs';
import '../core/crypto/ed25519.mjs';
import '../core/crypto/privateKey.mjs';
import '../core/crypto/multiEd25519.mjs';
import '../core/crypto/multiKey.mjs';
import '../core/crypto/singleKey.mjs';
/**
* Entry function arguments to be used when building a raw transaction using remote ABI
*/
type SimpleEntryFunctionArgumentTypes = boolean | number | bigint | string | null | undefined | Uint8Array | ArrayBuffer | Array<SimpleEntryFunctionArgumentTypes | EntryFunctionArgumentTypes>;
/**
* Entry function arguments to be used when building a raw transaction using BCS serialized arguments
*/
type EntryFunctionArgumentTypes = Bool | U8 | U16 | U32 | U64 | U128 | U256 | AccountAddress | MoveVector<EntryFunctionArgumentTypes> | MoveOption<EntryFunctionArgumentTypes> | MoveString | FixedBytes;
/**
* Script function arguments to be used when building a raw transaction using BCS serialized arguments
*/
type ScriptFunctionArgumentTypes = Bool | U8 | U16 | U32 | U64 | U128 | U256 | AccountAddress | MoveVector<U8> | MoveString | FixedBytes;
/**
* Type that holds all raw transaction instances Aptos SDK supports
*/
type AnyRawTransactionInstance = RawTransaction | MultiAgentRawTransaction | FeePayerRawTransaction;
/**
* Optional options to set when generating a transaction
*/
type InputGenerateTransactionOptions = {
maxGasAmount?: number;
gasUnitPrice?: number;
expireTimestamp?: number;
accountSequenceNumber?: AnyNumber;
};
/**
* The generated transaction payload type that was produces from `generateTransactionPayload()` function.
*/
type AnyTransactionPayloadInstance = TransactionPayloadEntryFunction | TransactionPayloadScript | TransactionPayloadMultiSig;
/**
* Unified type for the data needed to generate a transaction payload of types:
* Entry Function | Script | Multi Sig
*/
type InputGenerateTransactionPayloadData = InputEntryFunctionData | InputScriptData | InputMultiSigData;
type InputGenerateTransactionPayloadDataWithRemoteABI = InputScriptData | InputEntryFunctionDataWithRemoteABI | InputMultiSigDataWithRemoteABI;
/**
* The data needed to generate an Entry Function payload
*/
type InputEntryFunctionData = {
function: MoveFunctionId;
typeArguments?: Array<TypeTag | string>;
functionArguments: Array<EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes>;
abi?: EntryFunctionABI;
};
type InputGenerateTransactionPayloadDataWithABI = InputEntryFunctionDataWithABI | InputMultiSigDataWithABI;
type InputEntryFunctionDataWithABI = Omit<InputEntryFunctionData, "abi"> & {
abi: EntryFunctionABI;
};
type InputMultiSigDataWithABI = {
multisigAddress: AccountAddressInput;
} & InputEntryFunctionDataWithABI;
type InputEntryFunctionDataWithRemoteABI = InputEntryFunctionData & {
aptosConfig: AptosConfig;
};
/**
* The data needed to generate a Multi Sig payload
*/
type InputMultiSigData = {
multisigAddress: AccountAddressInput;
} & InputEntryFunctionData;
/**
* The data needed to generate a Multi Sig payload
*/
type InputMultiSigDataWithRemoteABI = {
multisigAddress: AccountAddressInput;
} & InputEntryFunctionDataWithRemoteABI;
/**
* The data needed to generate a Script payload
*/
type InputScriptData = {
bytecode: HexInput;
typeArguments?: Array<TypeTag>;
functionArguments: Array<ScriptFunctionArgumentTypes>;
};
/**
* The data needed to generate a View Function payload
*/
type InputViewFunctionData = {
function: MoveFunctionId;
typeArguments?: Array<TypeTag | string>;
functionArguments?: Array<EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes>;
abi?: ViewFunctionABI;
};
/**
* Data needed to generate a view function payload and fetch the remote ABI
*/
type InputViewFunctionDataWithRemoteABI = InputViewFunctionData & {
aptosConfig: AptosConfig;
};
/**
* Data needed to generate a view function, with an already fetched ABI
*/
type InputViewFunctionDataWithABI = InputViewFunctionData & {
abi: ViewFunctionABI;
};
/**
* Data need for a generic function ABI, both view and entry
*/
type FunctionABI = {
typeParameters: Array<MoveFunctionGenericTypeParam>;
parameters: Array<TypeTag>;
};
/**
* Interface of an Entry function's ABI.
*
* This is used to provide type checking and simple input conversion on ABI based transaction submission.
*/
type EntryFunctionABI = FunctionABI & {
signers?: number;
};
/**
* Interface of an View function's ABI.
*
* This is used to provide type checking and simple input conversion on ABI based transaction submission.
*/
type ViewFunctionABI = FunctionABI & {
returnTypes: Array<TypeTag>;
};
/**
* Interface of the arguments to generate a single signer transaction.
* Used to provide to `generateTransaction()` method in the transaction builder flow
*/
interface InputGenerateSingleSignerRawTransactionArgs {
aptosConfig: AptosConfig;
sender: AccountAddressInput;
payload: AnyTransactionPayloadInstance;
options?: InputGenerateTransactionOptions;
feePayerAddress?: AccountAddressInput;
}
/**
* Interface of the arguments to generate a multi-agent transaction.
* Used to provide to `generateTransaction()` method in the transaction builder flow
*/
interface InputGenerateMultiAgentRawTransactionArgs {
aptosConfig: AptosConfig;
sender: AccountAddressInput;
payload: AnyTransactionPayloadInstance;
secondarySignerAddresses: AccountAddressInput[];
options?: InputGenerateTransactionOptions;
feePayerAddress?: AccountAddressInput;
}
/**
* Unified type that holds all the interfaces to generate different transaction types
*/
type InputGenerateRawTransactionArgs = InputGenerateSingleSignerRawTransactionArgs | InputGenerateMultiAgentRawTransactionArgs;
/**
* Unified type that holds all the return interfaces when generating different transaction types
*/
type AnyRawTransaction = SimpleTransaction | MultiAgentTransaction;
type InputSimulateTransactionData = {
/**
* The transaction to simulate, probably generated by `generateTransaction()`
*/
transaction: AnyRawTransaction;
/**
* For a single signer transaction
*/
signerPublicKey: PublicKey;
/**
* For a fee payer or multi-agent transaction that requires additional signers in
*/
secondarySignersPublicKeys?: Array<PublicKey>;
/**
* For a fee payer transaction (aka Sponsored Transaction)
*/
feePayerPublicKey?: PublicKey;
options?: InputSimulateTransactionOptions;
};
type InputSimulateTransactionOptions = {
estimateGasUnitPrice?: boolean;
estimateMaxGasAmount?: boolean;
estimatePrioritizedGasUnitPrice?: boolean;
};
/**
* Interface that holds the user data input when generating a single signer transaction
*/
interface InputGenerateSingleSignerRawTransactionData {
sender: AccountAddressInput;
data: InputGenerateTransactionPayloadData;
options?: InputGenerateTransactionOptions;
withFeePayer?: boolean;
secondarySignerAddresses?: undefined;
}
/**
* Interface that holds the user data input when generating a multi-agent transaction
*/
interface InputGenerateMultiAgentRawTransactionData {
sender: AccountAddressInput;
data: InputGenerateTransactionPayloadData;
secondarySignerAddresses: AccountAddressInput[];
options?: InputGenerateTransactionOptions;
withFeePayer?: boolean;
}
/**
* Unified type that holds all the user data input interfaces when generating different transaction types
*/
type InputGenerateTransactionData = InputGenerateSingleSignerRawTransactionData | InputGenerateMultiAgentRawTransactionData;
/**
* Interface that holds the user data input when submitting a transaction
*/
interface InputSubmitTransactionData {
transaction: AnyRawTransaction;
senderAuthenticator: AccountAuthenticator;
feePayerAuthenticator?: AccountAuthenticator;
additionalSignersAuthenticators?: Array<AccountAuthenticator>;
}
export type { AnyRawTransaction, AnyRawTransactionInstance, AnyTransactionPayloadInstance, EntryFunctionABI, EntryFunctionArgumentTypes, FunctionABI, InputEntryFunctionData, InputEntryFunctionDataWithABI, InputEntryFunctionDataWithRemoteABI, InputGenerateMultiAgentRawTransactionArgs, InputGenerateMultiAgentRawTransactionData, InputGenerateRawTransactionArgs, InputGenerateSingleSignerRawTransactionArgs, InputGenerateSingleSignerRawTransactionData, InputGenerateTransactionData, InputGenerateTransactionOptions, InputGenerateTransactionPayloadData, InputGenerateTransactionPayloadDataWithABI, InputGenerateTransactionPayloadDataWithRemoteABI, InputMultiSigData, InputMultiSigDataWithABI, InputMultiSigDataWithRemoteABI, InputScriptData, InputSimulateTransactionData, InputSimulateTransactionOptions, InputSubmitTransactionData, InputViewFunctionData, InputViewFunctionDataWithABI, InputViewFunctionDataWithRemoteABI, ScriptFunctionArgumentTypes, SimpleEntryFunctionArgumentTypes, ViewFunctionABI };