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

    A pool of Solana nonce accounts, used for durable transactions

    A nonce is reserved for a period of time. During this time, it can be locked for usage and will remain locked indefinitely until released. If a nonce is not locked within the reservation period, it return to the pool.

    This service can be used in two ways:

    a) We know who will be locking the nonce at reservation time:

    service.reserve({ reservedFor: "<locker id>" });
    // later...
    service.lock({ reservedFor: "<locker id>" })
    service.release({ reservedFor: "<locker id>" })

    b) We do not know the ID of locker upfront:

    service.reserve({ reservedFor: "<domain>.<purpose>" })
    // later...
    service.lock({ address, lockedBy: "<locker id>" })
    service.release({ address })

    In this scenario, you have to carry forward the nonce address in code so it can be supplied to lock().

    ATTENTION: If you are using this service in an application, please ensure fillSolanaNoncePoolWorkflow is added to the same worker where the durable transaction will be executed

    Index

    Constructors

    Methods

    • Lock a previously-reserved nonce

      This method is invoked differently, depending on how reservation was done:

      // An ID was provided during reservation
      lock({ reservedFor: "<ID>" });
      // Otherwise, lock by address and supply the ID now
      lock({ address, lockedBy: "<ID>" })

      Parameters

      • input:
            | { address: PublicKey; lockedBy: string }
            | { lockedBy?: string; reservedFor: string }
        • { address: PublicKey; lockedBy: string }
          • address: PublicKey
          • lockedBy: string

            ID

        • { lockedBy?: string; reservedFor: string }
          • OptionallockedBy?: string

            ID

          • reservedFor: string

            ID

      Returns Promise<{ ok: true; value: SolanaNonce } | { error: ServiceError; ok: false }>

    • Locked nonces must be released.

      Ideally this should be invoked in a finally logic to ensure it is executed regardless of errors.

      Parameters

      • input: { address: PublicKey } | { lockedBy: string }
        • { address: PublicKey }
        • { lockedBy: string }
          • lockedBy: string

            ID

      Returns Promise<{ ok: true; value: undefined }>

    • Reserve a nonce for later locking.

      If it is not locked in the reservation period, it is released back into the pool.

      Remember to sign the transaction that includes this nonce, with the nonce authority via sign

      Parameters

      • __namedParameters: { expiresAt?: Date; reservedFor: string }
        • OptionalexpiresAt?: Date

          How long the reservation is valid for. Default: 5 minutes

        • reservedFor: string

          The ID of what will be using the nonce, or alternatively <domain>[.<domain model>][.<purpose>], e.g. SWAP, or DEPOSIT.US_CASH.MINT

          The latter is informational only and won't be used in code logic.

      Returns Promise<{ ok: true; value: SolanaNonce }>