fiber-types 0.8.1

Core domain types for the Fiber Network
Documentation
import blockchain;

array Uint16 [byte; 2];
array EcdsaSignature [byte; 64];
array PubNonce [byte; 66]; // PubNonce used by musig2 crate.
option PubNonceOpt (PubNonce);
array Pubkey [byte; 33];
option Uint64Opt (Uint64);
option Uint128Opt (Uint128);
option CustomRecordsOpt (CustomRecords);

table CustomRecordDataPair {
    key:    Uint32,
    value:  Bytes,
}

vector CustomRecordData <CustomRecordDataPair>;

table CustomRecords {
    data: CustomRecordData,
}

table Init {
    features: Bytes,
    chain_hash: Byte32,
}

table OpenChannel {
    chain_hash:                  Byte32,
    channel_id:                  Byte32,
    funding_udt_type_script:     ScriptOpt,
    funding_amount:              Uint128,
    shutdown_script:             Script,
    reserved_ckb_amount:         Uint64,
    funding_fee_rate:            Uint64,
    commitment_fee_rate:         Uint64,
    max_tlc_value_in_flight:     Uint128,
    max_tlc_number_in_flight:    Uint64,
    commitment_delay_epoch:      Uint64,
    funding_pubkey:              Pubkey,
    tlc_basepoint:               Pubkey,
    first_per_commitment_point:  Pubkey,
    second_per_commitment_point: Pubkey,
    channel_announcement_nonce:  PubNonceOpt,
    next_commitment_nonce:       PubNonce,
    next_revocation_nonce:       PubNonce,
    channel_flags:               byte,
}

table AcceptChannel {
    channel_id:                  Byte32,
    funding_amount:              Uint128,
    shutdown_script:             Script,
    reserved_ckb_amount:         Uint64,
    max_tlc_value_in_flight:     Uint128,
    max_tlc_number_in_flight:    Uint64,
    funding_pubkey:              Pubkey,
    tlc_basepoint:               Pubkey,
    first_per_commitment_point:  Pubkey,
    second_per_commitment_point: Pubkey,
    channel_announcement_nonce:  PubNonceOpt,
    next_commitment_nonce:       PubNonce,
    next_revocation_nonce:       PubNonce,
}

struct CommitmentSigned {
    channel_id:                       Byte32,
    funding_tx_partial_signature:     Byte32,
    next_commitment_nonce:            PubNonce,
}

table TxSignatures {
    channel_id: Byte32,
    witnesses:  BytesVec,
}

struct ChannelReady {
    channel_id: Byte32,
}

table TxUpdate {
    channel_id: Byte32,
    tx:         Transaction,
}

struct TxComplete {
    channel_id:                       Byte32,
    next_commitment_nonce:            PubNonce,
}

table TxAbort {
    channel_id: Byte32,
    message:    Bytes,
}

table TxInitRBF {
    channel_id: Byte32,
    fee_rate:   Uint64,
}

table TxAckRBF {
    channel_id: Byte32,
}

table Shutdown {
    channel_id:   Byte32,
    fee_rate:     Uint64,
    close_script: Script,
}

struct ClosingSigned {
    channel_id:         Byte32,
    partial_signature:  Byte32,
}

struct UpdateTlcInfo {
    channel_id: Byte32,
    timestamp: Uint64,
    channel_flags: Uint32,
    tlc_expiry_delta: Uint64,
    tlc_minimum_value: Uint128,
    tlc_fee_proportional_millionths: Uint128,
}

table AddTlc {
    channel_id:     Byte32,
    tlc_id:         Uint64,
    amount:         Uint128,
    payment_hash:   Byte32,
    expiry:         Uint64,
    hash_algorithm: byte,
    // This is the packet each hops need to decrypt and determine
    // which nodes to forward (or accept the tlc if it is the final node).
    onion_packet:   Bytes,
}

struct RevokeAndAck {
    channel_id:                         Byte32,
    revocation_partial_signature:       Byte32,
    next_per_commitment_point:          Pubkey,
    next_revocation_nonce:              PubNonce,
}

struct RemoveTlcFulfill {
    payment_preimage:   Byte32,
}

table TlcErrPacket {
    onion_packet:        Bytes,
}

union RemoveTlcReason {
    RemoveTlcFulfill,
    TlcErrPacket,
}

table RemoveTlc {
    channel_id:         Byte32,
    tlc_id:             Uint64,
    reason:             RemoveTlcReason,
}

table ReestablishChannel {
    channel_id: Byte32,
    local_commitment_number: Uint64,
    remote_commitment_number: Uint64,
}

table AnnouncementSignatures {
    channel_id: Byte32,
    channel_outpoint: OutPoint,
    node_signature: EcdsaSignature,
    partial_signature: Byte32,
}

union UdtDep {
    UdtCellDep,
    Script,
}

table UdtCellDep {
    out_point: OutPoint,
    dep_type: byte,
}

table UdtScript {
    code_hash: Byte32,
    hash_type: byte,
    args: Bytes,
}

vector UdtCellDeps <UdtDep>;

table UdtArgInfo {
    name: Bytes,
    script: UdtScript,
    auto_accept_amount: Uint128Opt,
    cell_deps: UdtCellDeps,
}

vector UdtCfgInfos <UdtArgInfo>;

union FiberMessage {
    Init,
    OpenChannel,
    AcceptChannel,
    TxSignatures,
    TxUpdate,
    TxComplete,
    TxAbort,
    TxInitRBF,
    TxAckRBF,
    CommitmentSigned,
    ChannelReady,
    UpdateTlcInfo,
    AddTlc,
    RemoveTlc,
    RevokeAndAck,
    Shutdown,
    ClosingSigned,
    ReestablishChannel,
    AnnouncementSignatures,
}

option PaymentPreimageOpt (Byte32);
option PubkeyOpt (Pubkey);
table PaymentHopData {
    amount: Uint128,
    expiry: Uint64,
    payment_preimage: PaymentPreimageOpt,
    hash_algorithm: byte,
    funding_tx_hash: Byte32,
    next_hop: PubkeyOpt,
    custom_records: CustomRecordsOpt,
}

// Trampoline hop payload for forwarding nodes
table TrampolineForwardPayload {
    next_node_id: Pubkey,
    amount_to_forward: Uint128,
    hash_algorithm: byte,
    build_max_fee_amount: Uint128,
    tlc_expiry_delta: Uint64,
    tlc_expiry_limit: Uint64,
    max_parts: Uint64Opt,
}

// Trampoline hop payload for the final recipient
table TrampolineFinalPayload {
    final_amount: Uint128,
    final_tlc_expiry_delta: Uint64,
    payment_preimage: PaymentPreimageOpt,
    custom_records: CustomRecordsOpt,
}

// Trampoline onion hop payload (either forward or final)
union TrampolineHopPayload {
    TrampolineForwardPayload,
    TrampolineFinalPayload,
}

// A ChannelUpdate is a update to the public channel. Newer channel information may be updated with
// a ChannelUpdate with a larger timestamp.
struct ChannelUpdate {
    // Signature of the node that wants to update the channel information.
    signature: EcdsaSignature,
    chain_hash: Byte32,
    channel_outpoint: OutPoint,
    timestamp: Uint64,
    message_flags: Uint32,
    channel_flags: Uint32,
    tlc_expiry_delta: Uint64,
    tlc_minimum_value: Uint128,
    tlc_maximum_value: Uint128,
    tlc_fee_proportional_millionths: Uint128,
}

option ChannelUpdateOpt (ChannelUpdate);
table ChannelFailed {
    channel_outpoint: OutPoint,
    channel_update: ChannelUpdateOpt,
    node_id: Pubkey,
}

table NodeFailed {
    node_id: Pubkey,
}

table TrampolineFailed {
    node_id: Pubkey,
    inner_error_packet: Bytes,
}

union TlcErrData {
    ChannelFailed,
    NodeFailed,
    TrampolineFailed,
}

option TlcErrDataOpt (TlcErrData);
table TlcErr {
    error_code: Uint16,
    extra_data: TlcErrDataOpt,
}