CodeSign React Native Reference Documentation
CodeSign
Current Version: 11.6.1
Chilkat.CodeSign
Apply Authenticode signatures to Windows executable files using a
certificate and associated private key.
Check whether a signed executable has a valid signature and whether the
signing certificate chain can be trusted.
Extract details about the Authenticode signature, including signer
information and signature-related metadata.
Get the certificate used to sign the executable and inspect it with
Remove an existing Authenticode signature from a Windows executable when
an unsigned output file is required.
Use detailed diagnostic output to troubleshoot signing, certificate,
trust-chain, timestamping, or validation problems.
For an extended overview, see
CodeSign Class Overview.
Sign, verify, inspect, and remove Authenticode signatures on Windows executables.
Chilkat.CodeSign works directly with Authenticode signatures on
Windows executable files such as .exe and .dll.
It provides functionality for applying a code-signing signature, validating
whether a signed executable can be trusted, extracting signature information,
retrieving the signer certificate, and removing an existing signature.
Sign EXE and DLL files
Validate trust
Inspect signatures
Retrieve signer certificates
Chilkat.Cert.
Remove signatures
Diagnostics
.exe or .dll, optionally add
timestamping if supported by the signing workflow, then verify the resulting
signature and inspect diagnostics if validation does not succeed.
Object Creation
// npm install @chilkat/react-native react-native-nitro-modules
// (React Native 0.76+ with the New Architecture; then `pod install` for iOS. The Chilkat
// native library is downloaded and verified during the native build -- see the package README.)
import { Chilkat, CodeSign } from '@chilkat/react-native'
// Once per app start, before any other Chilkat call:
Chilkat.unlockBundle('Anything for 30-day trial') // shorthand for new Global().unlockBundle(..)
const codeSign = new CodeSign()
// ... the native object is released when `codeSign` is garbage collected, or now with codeSign.dispose()Creates the underlying native Chilkat object. CodeSign is a Nitro Module HybridObject: use it from the JavaScript thread only (it cannot be passed to a Worklet or another runtime). Every member is synchronous and blocks the JavaScript thread until Chilkat returns; a method that can take a while also exists as a ...Async twin returning a Promise, which runs the same call on a native worker thread so the UI keeps rendering. While such a call is pending, every other call on this object throws, except abort() and assigning onPercentDone / onProgressInfo.
Releases the native object immediately instead of waiting for garbage collection (useful for a large BinData or an open socket). Calling it more than once is harmless; any other use of the object afterwards throws. An object with a pending ...Async call cannot be disposed until the promise settles.
Errors
A method that can fail throws a plain Error: a method whose only outcome is success or failure returns void and throws on failure; a method producing a string or an object returns it and throws where Chilkat would have returned null. The error's message is "Class.method(...): reason", where the reason is the last informative line of the object's lastErrorText, which holds the full Chilkat log of the failed call. A ...Async twin rejects its promise with the same Error instead of throwing. Properties never throw, and methods that answer a question (has..., is..., ...) return a plain boolean.
try {
codeSign.someMethod(...)
} catch (e) {
console.log((e as Error).message) // CodeSign.someMethod(...): <reason>
console.log(codeSign.lastErrorText) // the full Chilkat log of the failed call
}
// The same call without blocking the JavaScript thread:
try {
await codeSign.someMethodAsync(...)
} catch (e) {
console.log((e as Error).message) // CodeSign.someMethodAsync: <reason>
}
Properties
DebugLogFilePath
debugLogFilePath: string
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.
HeartbeatMs
heartbeatMs: number
Specifies the approximate interval, in milliseconds, between AbortCheck event callbacks during supported operations. An event handler can request that the current operation be aborted.
The default is 0, which disables AbortCheck callbacks. Setting a positive value enables periodic callbacks when an operation is sufficiently long-running; methods that finish quickly may complete without generating one.
LastErrorHtml
readonly lastErrorHtml: string
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
readonly lastErrorText: string
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
readonly lastErrorXml: string
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
lastMethodSuccess: boolean
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.
UncommonOptions
uncommonOptions: string
Provides a comma-separated list of specialized compatibility or validation options. The default is an empty string, which is appropriate for normal use.
| Option | Effect |
|---|---|
codesign-allow-expired-cert | Prevents Authenticode verification from failing solely because the signing certificate is expired. |
VerboseLogging
verboseLogging: boolean
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
readonly version: string
Methods
AddSignature
Adds a Microsoft Authenticode signature to the Windows executable or DLL specified by path. The file is modified in place. cert supplies the code-signing certificate and must provide access to its associated private key. options supplies the signing configuration as JSON.
Common options options include:
| JSON member | Purpose |
|---|---|
hashAlg | Selects the file-digest algorithm, such as sha256. |
timestampToken.enabled | Enables an RFC 3161 timestamp token. |
timestampToken.tsaUrl | Specifies the timestamp authority URL. |
timestampToken.requestTsaCert | Requests inclusion of the timestamp authority certificate. |
timestampToken.hashAlg | Selects the timestamp-request digest algorithm, such as sha256. |
{
"hashAlg": "sha256",
"timestampToken": {
"enabled": true,
"tsaUrl": "http://timestamp.example.com",
"requestTsaCert": true,
"hashAlg": "sha256"
}
}
Returns normally on success; throws an Error on failure.
AddSignatureAsync
Asynchronous form of AddSignature: the same call on a native worker thread, so the JavaScript thread (and the UI) stays responsive. Takes the same arguments and resolves with the same result. While the returned Promise is pending, every other call on this object throws (the object is busy), except abort(), which cancels the call, and assigning the onPercentDone / onProgressInfo callbacks, which report its progress.
Note: the onPercentDone and onProgressInfo callbacks run on the JavaScript thread while the promise is pending, so they can update the UI directly. A rejection's message is "Class.methodAsync: reason"; the full log is in lastErrorText.
Returns a Promise that resolves with the synchronous method's result (undefined for a void method) and rejects with an Error where the synchronous method would throw.
GetSignerCert
Retrieves the X.509 signer certificate discovered by the most recent call to VerifySignature on this CodeSign object. If the certificate is fully available, cert is loaded with it and the method returns true. Otherwise, the method returns false.
The returned object contains the public certificate only; it does not provide the signer's private key. Call this method after VerifySignature and use the same CodeSign instance.
VerifySignature and the returned signature information when making a trust decision.Returns normally on success; throws an Error on failure.
RemoveSignature
Removes the embedded Authenticode signature from the Windows executable or DLL specified by path. The file is modified in place. Returns true if the signature is successfully removed; otherwise returns false.
Returns normally on success; throws an Error on failure.
VerifySignature
Verifies the embedded Microsoft Authenticode signature of the Windows executable or DLL specified by path. Structured information about the signature, signer, certificate chain, digest algorithms, timestamp, and validation result is written to sigInfo.
Returns true when the signature satisfies the applicable Authenticode validation checks under the current Windows trust configuration. This includes confirming that the signed portions of the file have not changed and evaluating the signing certificate and timestamp information, as applicable. An unsigned file or a signature that does not validate causes the method to return false. Inspect sigInfo and LastErrorText for details.
Returns normally on success; throws an Error on failure.
Events
While a method runs, CodeSign reports progress through two optional callback properties. Assign a function to receive the event, or undefined to stop receiving it. The callbacks are delivered on the JavaScript thread, so they are useful with the ...Async methods: during a synchronous call the JavaScript thread is busy inside Chilkat, and the events can only arrive after it returns.
const codeSign = new CodeSign()
codeSign.onPercentDone = (pct) => setProgress(pct) // pct is 0..100
codeSign.onProgressInfo = (name, value) => console.log(`${name}: ${value}`)
codeSign.heartbeatMs = 250 // let abort() take effect within a quarter second
const pending = codeSign.someMethodAsync(...)
cancelButton.onPress = () => codeSign.abort() // the promise then rejects
await pendingPercentDone fires when an operation's completion percentage is known; ProgressInfo delivers named progress values (what is reported depends on the class and method). There is no AbortCheck callback: to cancel a pending ...Async call, call abort() on the object. Chilkat notices the request at its next progress check, which happens at least every heartbeatMs milliseconds on the classes that have that property (0, the default, disables the heartbeat, so set it for a responsive cancel), and the promise rejects with Chilkat's abort error. abort() is harmless when nothing is pending.
PercentDone
onPercentDone?: (pctDone: number) => void
This provides the percentage completion for any method involving network communications or time-consuming processing, assuming the progress can be measured as a percentage. This event is triggered only when it's possible and logical to express the operation's progress as a percentage. The pctDone argument will range from 1 to 100. For methods that finish quickly, the number of PercentDone callbacks may vary, but the final callback will have pctDone equal to 100. For longer operations, callbacks will not exceed one per percentage point (e.g., 1, 2, 3, ..., 98, 99, 100).
The PercentDone callback also acts as an AbortCheck event. For fast methods where PercentDone fires, an AbortCheck event may not trigger since the PercentDone callback already provides an opportunity to abort. For longer operations, where time between PercentDone callbacks is extended, AbortCheck callbacks enable more responsive operation termination.
To abort the operation, set the abort output argument to true. This will cause the method to terminate and return a failure status or corresponding failure value.
Example:
codeSign.onPercentDone = (pct) => {
// pct ranges from 0 to 100.
setProgress(pct) // runs on the JavaScript thread: React state may be updated directly
}
await codeSign.someMethodAsync(...)
// To stop an operation from within the callback, call codeSign.abort()ProgressInfo
onProgressInfo?: (name: string, value: string) => void
This event callback provides tag name/value pairs that detail what occurs during a method call. To discover existing tag names, create code to handle the event, emit the pairs, and review them. Most tag names are self-explanatory.
Note: Some Chilkat methods don't fire any ProgressInfo events.
Example:
codeSign.onProgressInfo = (name, value) => console.log(`${name}: ${value}`)
await codeSign.someMethodAsync(...)