@ckbfs/api
Version:
SDK for CKBFS protocol on CKB
118 lines (117 loc) • 4.21 kB
TypeScript
import { ccc, Transaction, Script, Signer } from "@ckb-ccc/core";
import { CKBFSDataType } from "./molecule";
import { NetworkType, ProtocolVersionType } from "./constants";
/**
* Utility functions for CKB transaction creation and handling
*/
/**
* Options for creating a CKBFS cell
*/
export interface CKBFSCellOptions {
contentType: string;
filename: string;
capacity?: bigint;
lock: Script;
network?: NetworkType;
version?: ProtocolVersionType;
useTypeID?: boolean;
}
/**
* Options for publishing a file to CKBFS
*/
export interface PublishOptions extends CKBFSCellOptions {
contentChunks: Uint8Array[];
feeRate?: number;
from?: Transaction;
}
/**
* Options for appending content to a CKBFS file
*/
export interface AppendOptions {
ckbfsCell: {
outPoint: {
txHash: string;
index: number;
};
data: CKBFSDataType;
type: Script;
lock: Script;
capacity: bigint;
};
contentChunks: Uint8Array[];
feeRate?: number;
network?: NetworkType;
version?: ProtocolVersionType;
from?: Transaction;
}
/**
* Ensures a string is prefixed with '0x'
* @param value The string to ensure is hex prefixed
* @returns A hex prefixed string
*/
export declare function ensureHexPrefix(value: string): `0x${string}`;
/**
* Creates a CKBFS cell
* @param options Options for creating the CKBFS cell
* @returns The created cell output
*/
export declare function createCKBFSCell(options: CKBFSCellOptions): {
lock: ccc.Script;
type: ccc.Script;
capacity: bigint;
};
/**
* Prepares a transaction for publishing a file to CKBFS without fee and change handling
* You will need to manually set the typeID if you did not provide inputs, or just check is return value emptyTypeID is true
* @param options Options for publishing the file
* @returns Promise resolving to the prepared transaction and the output index of CKBFS Cell
*/
export declare function preparePublishTransaction(options: PublishOptions): Promise<{
tx: Transaction;
outputIndex: number;
emptyTypeID: boolean;
}>;
/**
* Creates a transaction for publishing a file to CKBFS
* @param signer The signer to use for the transaction
* @param options Options for publishing the file
* @returns Promise resolving to the created transaction
*/
export declare function createPublishTransaction(signer: Signer, options: PublishOptions): Promise<Transaction>;
/**
* Prepares a transaction for appending content to a CKBFS file without fee and change handling
* @param options Options for appending content
* @returns Promise resolving to the prepared transaction and the output index of CKBFS Cell
*/
export declare function prepareAppendTransaction(options: AppendOptions): Promise<{
tx: Transaction;
outputIndex: number;
}>;
/**
* Creates a transaction for appending content to a CKBFS file
* @param signer The signer to use for the transaction
* @param options Options for appending content
* @returns Promise resolving to the created transaction
*/
export declare function createAppendTransaction(signer: Signer, options: AppendOptions): Promise<Transaction>;
/**
* Creates a transaction for appending content to a CKBFS file
* @param signer The signer to use for the transaction
* @param options Options for appending content
* @returns Promise resolving to the created transaction
*/
export declare function createAppendTransactionDry(signer: Signer, options: AppendOptions): Promise<Transaction>;
/**
* Creates a complete transaction for publishing a file to CKBFS
* @param signer The signer to use for the transaction
* @param options Options for publishing the file
* @returns Promise resolving to the signed transaction
*/
export declare function publishCKBFS(signer: Signer, options: PublishOptions): Promise<Transaction>;
/**
* Creates a complete transaction for appending content to a CKBFS file
* @param signer The signer to use for the transaction
* @param options Options for appending content
* @returns Promise resolving to the signed transaction
*/
export declare function appendCKBFS(signer: Signer, options: AppendOptions): Promise<Transaction>;