Interface

BatchEncoder

BatchEncoder

Members

number

# readonly slotCount

The total number of batching slots available to hold data

View Source batch-encoder.ts, line 222

Methods

# decode(plainText, signedopt, poolopt) → {Int32Array|Uint32Array}

Inverse of encode. This function "unbatches" a given PlainText into a matrix of signed or unsigned integers modulo the PlainText modulus, and stores the result in the destination parameter. The input PlainText must have degrees less than the polynomial modulus, and coefficients less than the PlainText modulus, i.e. it must be a valid PlainText for the encryption parameters. Dynamic memory allocations in the process are allocated from the memory pool pointed to by the given MemoryPoolHandle.
Parameters:
Name Type Attributes Default Description
plainText PlainText Data to decode
signed boolean <optional>
true By default, decode as an Int32Array. If false, decode as an Uint32Array
pool MemoryPoolHandle <optional>
MemoryPoolHandle.global

View Source batch-encoder.ts, line 132

TypedArray containing the decoded data
Int32Array | Uint32Array
Example
import SEAL from 'node-seal'
const seal = await SEAL()
...
const batchEncoder = seal.BatchEncoder(context)

const plainText = batchEncoder.encode(Int32Array.from([1, -2, 3]))
const plainTextU = batchEncoder.encode(Uint32Array.from([1, 2, 3]))

const result = batchEncoder.decode(plainText)
const resultU = batchEncoder.decode(plainTextU, false) // To decode as an Uint32Array

# decodeBigInt(plainText, signedopt, poolopt) → {BigInt64Array|BigUint64Array}

Performs the same function as the 32-bit decode, but supports true 64-bit values encapsulated by a BigInt. There's no official support for sending a BigInt64Array/BigUint64Array from C++ to JS, therefore this function uses string conversion to marshal data which is noticably slower. Use this function if you absolutely need to marshal values larger than 32 bits.
Parameters:
Name Type Attributes Default Description
plainText PlainText Data to decode
signed boolean <optional>
true By default, decode as an BigInt64Array. If false, decode as an BigUint64Array
pool MemoryPoolHandle <optional>
MemoryPoolHandle.global
See:

View Source batch-encoder.ts, line 181

TypedArray containing the decoded data
BigInt64Array | BigUint64Array
Example
import SEAL from 'node-seal'
const seal = await SEAL()
...
const batchEncoder = seal.BatchEncoder(context)

const plainText = batchEncoder.encode(BigInt64Array.from([1n, -2n, 3n]))
const plainTextU = batchEncoder.encode(BigUint64Array.from([1n, 2n, 3n]))

const result = batchEncoder.decodeBigInt(plainText)
const resultU = batchEncoder.decodeBigInt(plainTextU, false) // To decode as an BigUint64Array

# delete()

Delete the underlying WASM instance. Should be called before dereferencing this object to prevent the WASM heap from growing indefinitely.

View Source batch-encoder.ts, line 45

# encode(array, plainTextopt) → {PlainText|void}

Creates a PlainText from a given matrix. This function "batches" a given matrix of either signed or unsigned integers modulo the PlainText modulus into a PlainText element, and stores the result in the destination parameter. The input array must have size at most equal to the degree of the polynomial modulus. The first half of the elements represent the first row of the matrix, and the second half represent the second row. The numbers in the matrix can be at most equal to the PlainText modulus for it to represent a valid PlainText. If the destination PlainText overlaps the input values in memory, the behavior of this function is undefined.
Parameters:
Name Type Attributes Default Description
array Int32Array | Uint32Array | BigInt64Array | BigUint64Array Data to encode
plainText PlainText <optional>
null Destination to store the encoded result

View Source batch-encoder.ts, line 59

A new PlainText holding the encoded data or void if one was provided
PlainText | void
Example
import SEAL from 'node-seal'
const seal = await SEAL()
...
const batchEncoder = seal.BatchEncoder(context)

const plainText = batchEncoder.encode(Int32Array.from([1, -2, 3]))