/** * Copyright 2023 Fluence Labs Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { CallResultsArray } from "@fluencelabs/avm"; import { JSONValue } from "@fluencelabs/interfaces"; import { KeyPair } from "../keypair/index.js"; import { IParticle } from "./interfaces.js"; export declare class Particle implements IParticle { readonly id: string; readonly timestamp: number; readonly script: string; readonly data: Uint8Array; readonly ttl: number; readonly initPeerId: string; readonly signature: Uint8Array; constructor(id: string, timestamp: number, script: string, data: Uint8Array, ttl: number, initPeerId: string, signature: Uint8Array); static createNew(script: string, initPeerId: string, ttl: number, keyPair: KeyPair, _id?: string, _timestamp?: number, _data?: Uint8Array): Promise; static deserialize(bytes: Uint8Array): Particle; } /** * Builds particle message for signing */ export declare const buildParticleMessage: ({ id, timestamp, ttl, script, }: Omit) => Uint8Array; /** * Returns actual ttl of a particle, i.e. ttl - time passed since particle creation */ export declare const getActualTTL: (particle: IParticle) => number; /** * Returns true if particle has expired */ export declare const hasExpired: (particle: IParticle) => boolean; /** * Creates a particle clone with new data */ export declare const cloneWithNewData: (particle: IParticle, newData: Uint8Array) => IParticle; /** * Serializes particle into string suitable for sending through network */ export declare const serializeParticle: (particle: IParticle) => Uint8Array; /** * When particle is executed, it goes through different stages. The type describes all possible stages and their parameters */ export type ParticleExecutionStage = { stage: "received"; } | { stage: "interpreted"; } | { stage: "interpreterError"; errorMessage: string; } | { stage: "localWorkDone"; } | { stage: "sent"; } | { stage: "sendingError"; errorMessage: string; } | { stage: "expired"; }; /** * Particle queue item is a wrapper around particle, which contains additional information about particle execution */ export interface ParticleQueueItem { particle: IParticle; callResults: CallResultsArray; onSuccess: (result: JSONValue) => void; onError: (error: Error) => void; fireAndForget?: boolean; } /** * Helper function to handle particle at expired stage */ export declare const handleTimeout: (fn: () => void) => (error: Error) => void;