EdDSA Lua Reference Documentation
chilkat.EdDSA
Current Version: 11.7.0
Markdown version of this page for AI tools (v 11.7.0) · all AI docs
Chilkat.EdDSA
Create Ed25519 private keys for signing, verification, and compatible
key-agreement workflows.
Sign binary data directly from a
Verify encoded EdDSA signatures using the corresponding public key and
the original message data.
Use Ed25519, Ed25519ph, or Ed25519ctx depending on the protocol or
interoperability requirements.
Supply optional context bytes as a hex string for workflows that use the
Ed25519ctx or related context-aware signing modes.
Compute encoded shared secrets from compatible private and public key
pairs for protocols that require this operation.
For an extended overview, see
EdDSA Class Overview.
Generate Ed25519 keys, sign data, verify signatures, and compute shared secrets.
Chilkat.EdDSA is the Chilkat class for Ed25519-based EdDSA
operations. It can generate Ed25519 private keys, sign data contained in
BinData, verify encoded signatures with public keys, and compute
encoded shared secrets from compatible private/public key pairs. It supports
the Ed25519, Ed25519ph, and Ed25519ctx variants, with optional context bytes
supplied as a hex string when the selected variant requires them.
Generate Ed25519 keys
Sign BinData
Chilkat.BinData object
using an Ed25519 private key.
Verify signatures
Ed25519 variants
Context support
Shared-secret output
BinData
content. For shared-secret workflows, compute the encoded secret and pass it
through the key derivation or formatting step required by the protocol.
Object Creation
local chilkat = require("chilkat")
local eddsa = chilkat.EdDSA.new()Creates the object (chilkat.EdDSA() does the same). Lua's garbage collector frees it when it is no longer referenced; eddsa:dispose() frees it at once, and in Lua 5.4 and later local eddsa <close> = chilkat.EdDSA.new() frees it when the block ends. Calling a method of a disposed object raises an error.
Errors
A method that fails returns nil followed by the error text, as io.open does: local body, err = eddsa:method(...), where err is the object's last_error_text. Wrap the call in assert() to raise an error with that text instead. Methods that answer a question return true or false, numbers are returned as they are (check last_method_success where the description says a value means failure), and property reads and writes never fail for Chilkat reasons.
Misuse raises a Lua error: a wrong argument type or a missing argument (bad argument #1 to ...), an unknown property name, a write to a read-only property, an out-of-range integer, or an object of the wrong class.
Names are Chilkat's in snake_case: QuickGetStr is quick_get_str, LastErrorText is last_error_text. Properties are fields (eddsa.verbose_logging = true) and methods use the colon (eddsa:method(...)). Strings are UTF-8; binary data is a Lua string of bytes. Indexes are 0-based, as in every Chilkat API. Unlocking: call chilkat.unlock_bundle("...") once at startup.
Properties
Algorithm
local strVal = eddsa.algorithm
eddsa.algorithm = strVal
Selects the Ed25519 signature variant used by SignBdENC and VerifyBdENC. The default is Ed25519.
| Value | Behavior | Context |
|---|---|---|
Ed25519 | The standard pure Ed25519 signature scheme. The complete message is signed directly by the Ed25519 algorithm. | A context is not part of this variant and should be empty. |
Ed25519ctx | Pure Ed25519 with domain separation supplied by a context string. | The context should normally be nonempty and must match exactly during verification. |
Ed25519ph | Prehash Ed25519. Chilkat first hashes the message with SHA-512 as defined for this variant. | May be empty or contain up to 255 context bytes; it must match exactly during verification. |
GenEd25519Key and does not affect SharedSecretENC.Context
local strVal = eddsa.context
eddsa.context = strVal
Gets or sets the context bytes used by the Ed25519ctx and Ed25519ph signature variants. Supply the bytes as a hexadecimal string. The default is an empty string.
A context may contain at most 255 bytes, which corresponds to at most 510 hexadecimal characters. The same context bytes must be supplied byte-for-byte when verifying the signature. An invalid hexadecimal value or an oversized context causes the signing or verification operation to fail.
Algorithm is Ed25519ctx or Ed25519ph. Standard Ed25519 does not include a context.DebugLogFilePath
local strVal = eddsa.debug_log_file_path
eddsa.debug_log_file_path = strVal
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
LastErrorHtml
local strVal = eddsa.last_error_html
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
local strVal = eddsa.last_error_text
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
local strVal = eddsa.last_error_xml
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
local boolVal = eddsa.last_method_success
eddsa.last_method_success = boolVal
Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
VerboseLogging
local boolVal = eddsa.verbose_logging
eddsa.verbose_logging = boolVal
If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
local strVal = eddsa.version
Methods
GenEd25519Key
-- priv_key is a chilkat.PrivateKey
-- ok is true, or nil and err on failure
local ok, err = eddsa:gen_ed25519_key(prng, priv_key)
Generates a new Ed25519 key pair using prng as the source of cryptographically secure random bytes. On success, the generated private key and its corresponding public key are stored in the existing PrivateKey object passed in priv_key.
Returns on success and true on failure. If the method fails, inspect falseLastErrorText for details.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
SharedSecretENC
-- pubkey is a chilkat.PublicKey
-- encoding is a string
-- str is a string, or nil and err on failure
local str, err = eddsa:shared_secret_enc(privkey, pubkey, encoding)
Computes a 32-byte X25519 shared secret from the private key in privkey and the peer's public key in pubkey. The resulting bytes are returned as text using the binary encoding named by encoding, such as hex, hexlower, or base64.
Each participant supplies its own private key and the other participant's public key. When Alice computes the secret from Alice's private key and Bob's public key, and Bob computes it from Bob's private key and Alice's public key, both obtain the same result.
Algorithm and Context properties do not apply.This is a string-returning method. Check LastMethodSuccess before using the returned value; on failure, inspect LastErrorText.
Returns the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
SignBdENC
-- encoding is a string
-- privkey is a chilkat.PrivateKey
-- str is a string, or nil and err on failure
local str, err = eddsa:sign_bd_enc(bd, encoding, privkey)
Creates an EdDSA signature over the exact byte sequence contained in bd, using the Ed25519 private key in privkey. The 64-byte signature is returned as text using the binary encoding named by encoding, such as hex, hexlower, or base64.
The selected Algorithm and Context properties determine whether the operation uses Ed25519, Ed25519ctx, or Ed25519ph. For Ed25519ph, pass the original message bytes in bd; Chilkat performs the required SHA-512 prehash as part of the Ed25519ph operation.
This is a string-returning method. Check LastMethodSuccess before using the returned value; on failure, inspect LastErrorText.
Returns the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
VerifyBdENC
-- encoded_sig is a string
-- enocding is a string
-- pubkey is a chilkat.PublicKey
-- ok is true, or nil and err on failure
local ok, err = eddsa:verify_bd_enc(bd, encoded_sig, enocding, pubkey)
Verifies the encoded EdDSA signature in encoded_sig against the exact byte sequence contained in bd, using the Ed25519 public key in pubkey. enocding names the binary encoding of encoded_sig, such as hex, hexlower, or base64.
The verifier must use the same Algorithm and Context values that were used to create the signature. Any change to the message, signature, public key, algorithm variant, or context causes verification to fail.
Returns only when the signature is valid. Returns true for an invalid signature or an operational error, such as malformed encoded input, an unsupported encoding, or an unsuitable key. Inspect falseLastErrorText for diagnostic information.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.