UNPKG

thebigguy-contract

Version:

A library to generate P2SH scripts and create spend transactions for permissionless share-based distribution of UTXOs

49 lines 2.5 kB
import { Ecc, Script } from 'ecash-lib'; export declare const SCRIPT_NOPAY: Script; /** * A party is a combination of a receiving address with its permille share of the input value. */ export interface Party { address: string; share: number; } /** * Constructs a P2SH script that validates the transaction outputs to ensure * that each `party` receives it's assigned share of the input value (after * removing the transaction fee). * * The script expects the following pushes to the stack as inputs: * * - Serialized `prevouts`: to ensure that the script is only being used for * the first input * - Serialized `outputs`: to validate shares * - Schnorr signature for the preimage: to validate the preimage * - The BIP 143 preimage split into multiple pushes: All elements are pushed * separately except `nLocktime` and `sighash` which are pushed together, * because they are not needed * * The script supports multiple paths based solely on the input value. * * - If the value is bigger than 2147483647 (`0x7fffffff`) then the outputs * must be a 50/50 split with the receiver being the same P2SH script. Any * odd amount must have the extra sat on the second output. * - If the value is smaller than `fee + 1000` then a single empty `OP_RETURN` * is expected. Note that this will be the case even if additional standard * inputs are used, because only the value of the first input is considered. * - For the other cases the outputs must match the parties, in order, and have * the expected value of `floor(value - fee / 1000) * share`, or be ommited * if the value would be smaller thant the dust value of 546 sats. * * @param ecc An instance of `ecash-lib`'s ECC implementation for reusability * @param prvKey The private key that will be used to sign transactions * @param fee The value that will be discounted from the input value to pay for fees * @param parties The list of parties included in the script to validate the transaction outputs * * @returns A locking script that can be used to derive the P2SH address or * added to an unlocking script. */ export declare function createScript(ecc: Ecc, prvKey: Uint8Array, fee: number, parties: Party[]): Script; export declare function quotient(numerator: number, divisor: number): number; export declare function minUnitForShare(share: number): number; export declare function minUnitForAllShares(parties: Party[]): number; //# sourceMappingURL=script.d.ts.map