Skip to main content

Installation

npm install @inco/lightning

Types

  • ebool: Encrypted bool
  • euint256: Encrypted uint256
  • eaddress: Encrypted address

Math operations

All arithmetic operations return an euint256. All binary operations may use either an euint256 or a regular uint256 as the first or second argument, or two euint256s. Bitwise operations work on both euint256 and ebool types, and may use either encrypted or plain values as arguments.
NameFunctionTypeReturns
Additione.addBinaryeuint256
Subtractione.subBinaryeuint256
Multiplicatione.mulBinaryeuint256
Divisione.divBinaryeuint256
Remaindere.remBinaryeuint256
BitAnde.andBinaryeuint256 or ebool
BitOre.orBinaryeuint256 or ebool
BitXore.xorBinaryeuint256 or ebool
Shift Righte.shrBinaryeuint256
Shift Lefte.shlBinaryeuint256
Rotate Righte.rotrBinaryeuint256
Rotate Lefte.rotlBinaryeuint256

Comparison operations

NameFunctionTypeReturnsNotes
Equale.eqBinaryeboolWorks with euint256, eaddress, and combinations with plain types
Not equale.neBinaryeboolWorks with euint256, eaddress, and combinations with plain types
Greater than or equale.geBinaryebooleuint256 only
Greater thane.gtBinaryebooleuint256 only
Less than or equale.leBinaryebooleuint256 only
Less thane.ltBinaryebooleuint256 only
Mine.minBinaryeuint256euint256 only
Maxe.maxBinaryeuint256euint256 only
Note.notUnaryeboolebool only

Multiplexer

  • e.select(ebool, euint256, euint256) returns(euint256): Select between two euint256s based on an ebool condition
  • e.select(ebool, ebool, ebool) returns(ebool): Select between two ebools based on an ebool condition
  • e.select(ebool, eaddress, eaddress) returns(eaddress): Select between two eaddresses based on an ebool condition

Random Functions

All random functions require payment of the Inco fee.
  • e.rand() returns(euint256): Generate a random euint256 value
  • e.randBounded(uint256) returns(euint256): Generate a random euint256 value bounded by a uint256 upper limit
  • e.randBounded(euint256) returns(euint256): Generate a random euint256 value bounded by an euint256 upper limit

Inputs

  • e.asEuint256(uint256) returns(euint256): Convert a uint256 to an euint256 (trivial encrypt)
  • e.asEbool(bool) returns(ebool): Convert a bool to an ebool (trivial encrypt)
  • e.asEaddress(address) returns(eaddress): Convert an address to an eaddress (trivial encrypt)
  • e.newEuint256(bytes memory input) returns(euint256): Create a new euint256 from a ciphertext
  • e.newEbool(bytes memory input) returns(ebool): Create a new ebool from a ciphertext
  • e.newEaddress(bytes memory input) returns(eaddress): Create a new eaddress from a ciphertext

Type Casting

  • e.asEbool(euint256) returns(ebool): Cast an euint256 to an ebool
  • e.asEuint256(ebool) returns(euint256): Cast an ebool to an euint256

Access control

  • e.allow(euint256, address): Allow a user to access an euint256 value permanently
  • e.allow(ebool, address): Allow a user to access an ebool value permanently
  • e.allow(eaddress, address): Allow a user to access an eaddress value permanently
  • e.allowThis(euint256): Allow the current contract to access an euint256 value permanently
  • e.allowThis(ebool): Allow the current contract to access an ebool value permanently
  • e.allowThis(eaddress): Allow the current contract to access an eaddress value permanently
  • e.reveal(euint256): Make an euint256 value publicly accessible
  • e.reveal(ebool): Make an ebool value publicly accessible
  • e.reveal(eaddress): Make an eaddress value publicly accessible
  • e.isAllowed(address, euint256) returns(bool): Check if a user is allowed to access an euint256 value