@cfxlabsinc/b2b-services
    Preparing search index...

    Interact with the CFX escrow Solana program.

    The escrow program lets a sender lock funds on chain that an as-yet-unknown recipient (identified by a hashed secret — typically derived from their phone number) can later claim. Once the recipient signs up and a wallet is known, the update authority calls update_escrow to bind that wallet. The release authority can then release funds to the recipient or, in the reject / expiry case, cancel the escrow and refund the sender.

    This service returns kit Instruction[] — composition, signing, and submission stay in SolanaTransactionService.

    Index

    Constructors

    Methods

    • Build the create_escrow instruction. Sender must sign (their token authority moves funds into the escrow); payer pays rent for the new PDAs.

      Parameters

      • __namedParameters: Omit<EscrowParticipants, "sender"> & {
            payer: KeyPairSigner;
            sender: KeyPairSigner;
            tokenProgram?: Address;
        }

      Returns Promise<
          Instruction<
              string,
              readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[],
          >,
      >

    • Build a createUser instruction that initializes the sender's UserInfo PDA. Sender signs; payer pays rent.

      Parameters

      • __namedParameters: { payer: KeyPairSigner; user: KeyPairSigner }

      Returns Promise<
          Instruction<
              string,
              readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[],
          >,
      >

    • Read the sender's UserInfo PDA and derive the next-to-be-used escrow nonce. Matches the movemoney parity scheme — opened + 1 when the PDA exists, 1 otherwise. When userInfoExists is false, the caller is responsible for prepending a createUser instruction before create_escrow.

      Parameters

      • sender: Address

      Returns Promise<{ nonce: bigint; userInfoExists: boolean }>

    • Build the release_authority_cancel_escrow instruction — the reject / expire path. Funds return to the sender; escrow PDA closes.

      Parameters

      • __namedParameters: Omit<EscrowParticipants, "releaseAuthority"> & {
            payer: KeyPairSigner;
            releaseAuthority: KeyPairSigner;
            tokenProgram?: Address;
        }

      Returns Promise<
          Instruction<
              string,
              readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[],
          >,
      >

    • Build the release_authority_release_escrow instruction. Same as the with-reward variant minus the fee carve-out — useful when no reward structure is needed.

      Parameters

      • __namedParameters: Omit<EscrowParticipants, "releaseAuthority"> & {
            payer: KeyPairSigner;
            receiver: Address;
            releaseAuthority: KeyPairSigner;
            tokenProgram?: Address;
        }

      Returns Promise<
          Instruction<
              string,
              readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[],
          >,
      >

    • Build the release_authority_release_escrow_with_reward instruction — the recipient-claim path. The release authority signs and may skim a reward amount to its own ATA (set reward = 0n for the no-fee case).

      Parameters

      • __namedParameters: Omit<EscrowParticipants, "releaseAuthority"> & {
            payer: KeyPairSigner;
            receiver: Address;
            releaseAuthority: KeyPairSigner;
            reward: bigint | null;
            tokenProgram?: Address;
        }

      Returns Promise<
          Instruction<
              string,
              readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[],
          >,
      >

    • Build the sender_cancel_escrow instruction — the sender-cancel path. Sender signs; funds return to sender.

      Parameters

      • __namedParameters: Omit<EscrowParticipants, "sender"> & {
            payer: KeyPairSigner;
            sender: KeyPairSigner;
            tokenProgram?: Address;
        }

      Returns Promise<
          Instruction<
              string,
              readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[],
          >,
      >

    • Build the update_escrow instruction that attaches a recipient wallet to a previously-created escrow. Update authority signs; payer pays.

      secret must be the preimage of the escrow's stored hash, otherwise the on-chain assertion will fail.

      Parameters

      • __namedParameters: Omit<EscrowParticipants, "updateAuthority"> & {
            payer: KeyPairSigner;
            receiver: Address;
            secret: string;
            tokenProgram?: Address;
            updateAuthority: KeyPairSigner;
        }

      Returns Promise<
          Instruction<
              string,
              readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[],
          >,
      >

    • Derive the deterministic update-secret for a phone-keyed escrow.

      customerId namespaces the secret so two customers sending to the same phone never produce the same hash.

      Parameters

      • __namedParameters: { customerId: string; recipientPhone: string }

      Returns string

    • Compute the on-chain hash from a sender-supplied secret preimage.

      The on-chain program stores only the SHA-256 hash at create time and asserts sha256(secret) === hash at update time. The preimage is service-defined; we use a phone-derived deterministic string so the update authority can recompute it after recipient signup without storing the secret server-side.

      Parameters

      • secret: string

      Returns Buffer