ecash-agora
Version:
Library for interacting with the eCash Agora protocol
72 lines • 3.14 kB
TypeScript
import { Ecc, Script, SLP_TOKEN_TYPE_NFT1_CHILD, TxOutput, UnsignedTxInput } from 'ecash-lib';
import { Wallet } from 'ecash-wallet';
import { AgoraBroadcastParams } from './broadcast.js';
/**
* Agora offer that has to be accepted in "one shot", i.e. all or nothing.
* This is useful for offers that offer exactly 1 token, especially NFTs.
*
* The covenant is reasonably simple, see
* https://read.cash/@pein/bch-covenants-with-spedn-4a980ed3 for an explanation of the
* covenant mechanism, but uses two optimizations:
* 1. It uses ANYONECANPAY as sighash for the "accept" path, which makes the sighash
* preimage start with `1000....00000`, which can be created with
* `OP_1 68 OP_NUM2BIN`, saving around 64 bytes.
* 2. It uses OP_CODESEPARATOR before the OP_CHECKSIG, which cuts out the entire script
* code, leaving only the OP_CHECKSIG behind. The scriptCode part in the BIP143
* sighash now just becomes `01ac`, which is both easier to deal with in the OP_SPLIT
* and also saves 100 bytes or so (depending on the enforced outputs).
**/
export declare class AgoraOneshot {
static COVENANT_VARIANT: string;
enforcedOutputs: TxOutput[];
cancelPk: Uint8Array;
constructor({ enforcedOutputs, cancelPk, }: {
enforcedOutputs: TxOutput[];
cancelPk: Uint8Array;
});
/** Build the Script enforcing the Agora offer covenant. */
script(): Script;
static fromRedeemScript(redeemScript: Script, opreturnScript: Script): AgoraOneshot;
adScript(): Script;
askedSats(): bigint;
/**
* Build and broadcast a chained transaction to list an SLP NFT token.
* This creates an "ad prep" transaction followed by the actual offer transaction.
*
* @param params - Parameters for listing the NFT
* @returns Promise resolving to broadcast result
* @throws Error if token type is not SLP NFT
*/
list(params: {
/**
* An initialized Wallet from ecash-wallet.
* This wallet must hold the NFT token to be listed.
*/
wallet: Wallet;
/**
* Token ID of the NFT to list (in big-endian hex).
*/
tokenId: string;
/**
* Token type - must be SLP_TOKEN_TYPE_NFT1_CHILD.
*/
tokenType: typeof SLP_TOKEN_TYPE_NFT1_CHILD;
/**
* Dust amount to use for the token output.
*/
dustSats?: bigint;
/**
* Fee per kB to use when building the tx.
*/
feePerKb?: bigint;
} & AgoraBroadcastParams): Promise<{
success: boolean;
broadcasted: string[];
unbroadcasted?: string[];
errors?: string[];
}>;
}
export declare const AgoraOneshotSignatory: (covenantSk: Uint8Array, covenantPk: Uint8Array, numEnforcedOutputs: number) => (ecc: Ecc, input: UnsignedTxInput) => Script;
export declare const AgoraOneshotCancelSignatory: (cancelSk: Uint8Array) => (ecc: Ecc, input: UnsignedTxInput) => Script;
export declare const AgoraOneshotAdSignatory: (cancelSk: Uint8Array) => (ecc: Ecc, input: UnsignedTxInput) => Script;
//# sourceMappingURL=oneshot.d.ts.map