airgap-coin-lib
Version:
The airgap-coin-lib is a protocol agnostic library to prepare, sign and broadcast cryptocurrency transactions.
348 lines (347 loc) • 14.7 kB
TypeScript
/// <reference types="node" />
import { TezosTransactionResult } from './types/TezosTransactionResult';
import { TezosTransactionCursor } from './types/TezosTransactionCursor';
import BigNumber from '../../dependencies/src/bignumber.js-9.0.0/bignumber';
import { IAirGapSignedTransaction } from '../../interfaces/IAirGapSignedTransaction';
import { AirGapTransactionStatus, IAirGapTransaction } from '../../interfaces/IAirGapTransaction';
import { SignedTezosTransaction } from '../../serializer/schemas/definitions/signed-transaction-tezos';
import { UnsignedTezosTransaction } from '../../serializer/schemas/definitions/unsigned-transaction-tezos';
import { RawTezosTransaction } from '../../serializer/types';
import { ProtocolSymbols } from '../../utils/ProtocolSymbols';
import { DelegateeDetails, DelegationDetails, DelegatorDetails, ICoinDelegateProtocol } from '../ICoinDelegateProtocol';
import { CurrencyUnit, FeeDefaults } from '../ICoinProtocol';
import { ICoinSubProtocol } from '../ICoinSubProtocol';
import { NonExtendedProtocol } from '../NonExtendedProtocol';
import { TezosProtocolOptions } from './TezosProtocolOptions';
import { TezosRevealOperation } from './types/operations/Reveal';
import { TezosOperation } from './types/operations/TezosOperation';
import { TezosTransactionOperation } from './types/operations/Transaction';
import { TezosWrappedOperation } from './types/TezosWrappedOperation';
export interface TezosVotingInfo {
pkh: string;
rolls: number;
}
export interface BakerInfo {
balance: BigNumber;
delegatedBalance: BigNumber;
stakingBalance: BigNumber;
selfBond: BigNumber;
bakerCapacity: BigNumber;
bakerUsage: BigNumber;
}
export interface DelegationRewardInfo {
cycle: number;
reward: BigNumber;
deposit: BigNumber;
delegatedBalance: BigNumber;
stakingBalance: BigNumber;
totalRewards: BigNumber;
totalFees: BigNumber;
payout: Date;
}
export interface DelegationInfo {
isDelegated: boolean;
value?: string;
delegatedOpLevel?: number;
delegatedDate?: Date;
}
export declare enum TezosDelegatorAction {
DELEGATE = "delegate",
UNDELEGATE = "undelegate",
CHANGE_BAKER = "change_baker"
}
export interface TezosPayoutInfo {
delegator: string;
share: string;
payout: string;
balance: string;
}
export interface RunOperationBalanceUpdate {
kind: string;
contract: string;
change: string;
category: string;
delegate: string;
cycle?: number;
}
export interface RunOperationOperationBalanceUpdate {
kind: string;
contract: string;
change: string;
}
export interface RunOperationOperationResult {
status: string;
errors?: unknown;
balance_updates: RunOperationOperationBalanceUpdate[];
consumed_gas: string;
paid_storage_size_diff?: string;
originated_contracts?: string[];
allocated_destination_contract?: boolean;
}
interface RunOperationInternalOperationResult {
result?: {
errors?: unknown;
consumed_gas: string;
paid_storage_size_diff?: string;
originated_contracts?: string[];
allocated_destination_contract?: boolean;
};
parameters?: {
entrypoint: string;
value: unknown;
};
}
export interface RunOperationMetadata {
balance_updates: RunOperationBalanceUpdate[];
operation_result: RunOperationOperationResult;
internal_operation_results?: RunOperationInternalOperationResult[];
}
export declare enum TezosNetwork {
MAINNET = "mainnet",
DELPHINET = "delphinet"
}
export declare class TezosProtocol extends NonExtendedProtocol implements ICoinDelegateProtocol {
readonly options: TezosProtocolOptions;
symbol: string;
name: string;
marketSymbol: string;
feeSymbol: string;
decimals: number;
feeDecimals: number;
identifier: ProtocolSymbols;
get subProtocols(): ICoinSubProtocol[];
feeDefaults: FeeDefaults;
units: CurrencyUnit[];
supportsHD: boolean;
standardDerivationPath: string;
addressIsCaseSensitive: boolean;
addressValidationPattern: string;
addressPlaceholder: string;
minCycleDuration: number;
protected readonly transactionFee: BigNumber;
protected readonly originationSize: BigNumber;
protected readonly storageCostPerByte: BigNumber;
protected readonly revealFee: BigNumber;
protected readonly activationBurn: BigNumber;
protected readonly originationBurn: BigNumber;
protected readonly tezosPrefixes: {
tz1: Buffer;
tz2: Buffer;
tz3: Buffer;
kt: Buffer;
edpk: Buffer;
edsk: Buffer;
edsig: Buffer;
branch: Buffer;
};
get jsonRPCAPI(): string;
get baseApiUrl(): string;
get baseApiNetwork(): string;
readonly headers: {
'Content-Type': string;
apiKey: string;
};
constructor(options?: TezosProtocolOptions);
getBlockExplorerLinkForAddress(address: string): Promise<string>;
getBlockExplorerLinkForTxId(txId: string): Promise<string>;
getPublicKeyFromMnemonic(mnemonic: string, derivationPath: string, password?: string): Promise<string>;
getPrivateKeyFromMnemonic(mnemonic: string, derivationPath: string, password?: string): Promise<Buffer>;
/**
* Returns the PublicKey as String, derived from a supplied hex-string
* @param secret HEX-Secret from BIP39
* @param derivationPath DerivationPath for Key
*/
getPublicKeyFromHexSecret(secret: string, derivationPath: string): Promise<string>;
/**
* Returns the PrivateKey as Buffer, derived from a supplied hex-string
* @param secret HEX-Secret from BIP39
* @param derivationPath DerivationPath for Key
*/
getPrivateKeyFromHexSecret(secret: string, derivationPath: string): Promise<Buffer>;
getAddressFromPublicKey(publicKey: string): Promise<string>;
getAddressesFromPublicKey(publicKey: string): Promise<string[]>;
getTransactionsFromPublicKey(publicKey: string, limit: number, cursor?: TezosTransactionCursor): Promise<TezosTransactionResult>;
getTransactionsFromAddresses(addresses: string[], limit: number, cursor?: TezosTransactionCursor): Promise<TezosTransactionResult>;
signWithPrivateKey(privateKey: Buffer, transaction: RawTezosTransaction): Promise<IAirGapSignedTransaction>;
getTransactionDetails(unsignedTx: UnsignedTezosTransaction): Promise<IAirGapTransaction[]>;
getTransactionDetailsFromSigned(signedTx: SignedTezosTransaction): Promise<IAirGapTransaction[]>;
getAirGapTxFromWrappedOperations(wrappedOperations: TezosWrappedOperation): Promise<IAirGapTransaction[]>;
getBalanceOfAddresses(addresses: string[]): Promise<string>;
getBalanceOfPublicKey(publicKey: string): Promise<string>;
getBalanceOfPublicKeyForSubProtocols(publicKey: string, subProtocols: ICoinSubProtocol[]): Promise<string[]>;
getAvailableBalanceOfAddresses(addresses: string[]): Promise<string>;
estimateMaxTransactionValueFromPublicKey(publicKey: string, recipients: string[], fee?: string): Promise<string>;
estimateFeeDefaultsFromPublicKey(publicKey: string, recipients: string[], values: string[], data?: any): Promise<FeeDefaults>;
protected estimateFeeDefaultsForOperations(publicKey: string, operations: TezosOperation[]): Promise<FeeDefaults>;
prepareTransactionFromPublicKey(publicKey: string, recipients: string[], values: string[], fee: string, data?: {
addressIndex: number;
}): Promise<RawTezosTransaction>;
prepareTransactionsFromPublicKey(publicKey: string, recipients: string[], values: string[], fee: string, data?: {
addressIndex: number;
}, operationsPerGroup?: number): Promise<RawTezosTransaction[]>;
protected getTransactionOperationDetails(transactionOperation: TezosTransactionOperation): Promise<Partial<IAirGapTransaction>[]>;
private createTransactionOperations;
forgeAndWrapOperations(tezosWrappedOperation: TezosWrappedOperation): Promise<RawTezosTransaction>;
getDefaultDelegatee(): Promise<string>;
getCurrentDelegateesForPublicKey(publicKey: string): Promise<string[]>;
getCurrentDelegateesForAddress(address: string): Promise<string[]>;
getDelegateeDetails(address: string): Promise<DelegateeDetails>;
isPublicKeyDelegating(publicKey: string): Promise<boolean>;
isAddressDelegating(address: string): Promise<boolean>;
getDelegatorDetailsFromPublicKey(publicKey: string): Promise<DelegatorDetails>;
getDelegatorDetailsFromAddress(address: string): Promise<DelegatorDetails>;
getDelegationDetailsFromPublicKey(publicKey: string, delegatees: string[]): Promise<DelegationDetails>;
getDelegationDetailsFromAddress(address: string, delegatees: string[]): Promise<DelegationDetails>;
private getDelegatorDetails;
prepareDelegatorActionFromPublicKey(publicKey: string, type: TezosDelegatorAction, data?: any): Promise<RawTezosTransaction[]>;
prepareOperations(publicKey: string, operationRequests: TezosOperation[], overrideFees?: boolean): Promise<TezosWrappedOperation>;
estimateAndReplaceLimitsAndFee(tezosWrappedOperation: TezosWrappedOperation, overrideFees?: boolean): Promise<TezosWrappedOperation>;
getDelegationInfo(delegatedAddress: string, fetchExtraInfo?: boolean): Promise<DelegationInfo>;
bakerInfo(tzAddress: string | undefined): Promise<BakerInfo>;
getDelegationRewardsForAddress(address: string): Promise<DelegationRewardInfo[]>;
getDelegationRewards(bakerAddress: string, delegatorAddress?: string): Promise<DelegationRewardInfo[]>;
undelegate(publicKey: string): Promise<RawTezosTransaction>;
delegate(publicKey: string, delegate?: string | string[]): Promise<RawTezosTransaction>;
private getAmountUsedByPreviousOperations;
broadcastTransaction(rawTransaction: IAirGapSignedTransaction): Promise<string>;
protected checkAndRemovePrefixToHex(base58CheckEncodedPayload: string, tezosPrefix: Uint8Array): string;
unforgeSignedTezosWrappedOperation(hexString: string): Promise<TezosWrappedOperation>;
unforgeUnsignedTezosWrappedOperation(hexString: string): Promise<TezosWrappedOperation>;
forgeTezosOperation(tezosWrappedOperation: TezosWrappedOperation): Promise<string>;
createRevealOperation(counter: BigNumber, publicKey: string, address: string, fee?: string): Promise<TezosRevealOperation>;
getTezosVotingInfo(blockHash: string): Promise<TezosVotingInfo[]>;
fetchCurrentCycle(): Promise<number>;
private static readonly FIRST_005_CYCLE;
private static readonly FIRST_006_CYCLE;
private rewardCalculations;
calculateRewards(bakerAddress: string, cycle: number, currentCycle?: number, breakDownRewards?: boolean): Promise<TezosRewards>;
calculatePayouts(rewards: TezosRewards, offsetOrAddresses: number | string[], limit?: number): Promise<TezosPayoutInfo[]>;
calculatePayout(address: string, rewards: TezosRewards): Promise<TezosPayoutInfo>;
private calculatePayoutForAddresses;
private fetchBlockMetadata;
static readonly BLOCKS_PER_CYCLE: {
mainnet: number;
delphinet: number;
edonet: number;
};
private fetchBalances;
signMessage(message: string, keypair: {
privateKey: Buffer;
}): Promise<string>;
verifyMessage(message: string, signature: string, publicKey: string): Promise<boolean>;
getTransactionStatuses(transactionHashes: string[]): Promise<AirGapTransactionStatus[]>;
}
export interface TezosBakingRight {
level: number;
delegate: string;
priority: number;
}
export interface TezosBakingRewards {
totalBakingRewards: string;
rewardsDetails: {
level: number;
amount: string;
deposit: string;
fees?: string;
}[];
}
export interface TezosEndorsingRewards {
totalEndorsingRewards: string;
rewardsDetails: {
level: number;
amount: string;
deposit: string;
}[];
}
export interface TezosEndorsingRight {
level: number;
block_level?: number;
delegate: string;
number_of_slots: number;
}
export interface TezosRewardsCalculations {
protocol: TezosProtocol;
calculateRewards(bakerAddress: string, cycle: number, breakDownRewards: boolean, currentCycleIn?: number): Promise<TezosRewards>;
}
export interface TezosRewards {
baker: string;
stakingBalance: string;
bakingRewards: string;
bakingDeposits: string;
endorsingDeposits: string;
endorsingRewards: string;
fees: string;
deposit: string;
totalRewards: string;
cycle: number;
snapshotBlockLevel: number;
delegatedContracts: string[];
bakingRewardsDetails: {
level: number;
amount: string;
deposit: string;
fees?: string;
}[];
endorsingRewardsDetails: {
level: number;
amount: string;
deposit: string;
}[];
endorsingRightsCount: number;
}
export interface TezosBakerInfo {
balance: string;
frozen_balance: string;
frozen_balance_by_cycle: TezosFrozenBalance[];
staking_balance: string;
delegated_contracts: string[];
delegated_balance: string;
deactivated: boolean;
grace_period: number;
}
export interface TezosFrozenBalance {
cycle: number;
deposit: string;
fees: string;
rewards: string;
}
export interface TezosNodeConstants {
proof_of_work_nonce_size: number;
nonce_length: number;
max_revelations_per_block: number;
max_operation_data_length: number;
max_proposals_per_delegate: number;
preserved_cycles: number;
blocks_per_cycle: number;
blocks_per_commitment: number;
blocks_per_roll_snapshot: number;
blocks_per_voting_period: number;
time_between_blocks: number[];
endorsers_per_block: number;
hard_gas_limit_per_operation: string;
hard_gas_limit_per_block: string;
proof_of_work_threshold: number;
tokens_per_roll: string;
michelson_maximum_type_size: number;
seed_nonce_revelation_tip: string;
origination_size: number;
block_security_deposit: string;
endorsement_security_deposit: string;
cost_per_byte: string;
hard_storage_limit_per_operation: string;
test_chain_duration: string;
quorum_min: number;
quorum_max: number;
min_proposal_quorum: number;
initial_endorsers: number;
delay_per_missing_endorsement: string;
}
export interface TezosNodeConstantsV1 extends TezosNodeConstants {
block_reward: string;
endorsement_reward: string;
}
export interface TezosNodeConstantsV2 extends TezosNodeConstants {
baking_reward_per_endorsement: string[];
endorsement_reward: string[];
}
export {};