Documentation
¶
Index ¶
- func DefaultRuntime(ctx context.Context) (wazero.Runtime, error)
- type CallFn
- type DefaultHasher
- type File
- type FileOption
- type Hasher
- type HostMethod
- type HostMethodFunc
- type Invoker
- type LiveRuntime
- func (l *LiveRuntime) Close(ctx context.Context) error
- func (l *LiveRuntime) HasPluginMethodID(methodID uint32) bool
- func (l *LiveRuntime) InvokeMethod(ctx context.Context, methodID uint32, payload []byte) ([]byte, error)
- func (l *LiveRuntime) InvokeMethodWithResponse(ctx context.Context, methodID uint32, payload []byte, fn func([]byte) error) error
- func (l *LiveRuntime) PluginHandshake() (runtimecontract.Handshake, bool)
- type NewRuntime
- type Option
- func WithContractSchema(schema runtimecontract.Schema) Option
- func WithFile(file string, opts ...FileOption) Option
- func WithHostMethodFns(fns ...HostMethod) Option
- func WithLogger(logFn logger.Logger) Option
- func WithRandSource(rand io.Reader) Option
- func WithStderr(stderr io.Writer) Option
- func WithStdout(stdout io.Writer) Option
- type PluginFunc
- type ReloadConfig
- type ReloadEvent
- type Runtime
- func (e *Runtime) Close(ctx context.Context) error
- func (e *Runtime) Compile() error
- func (e *Runtime) ContractHasMethodID(methodID uint32) bool
- func (e *Runtime) ContractSchema() (runtimecontract.Schema, bool)
- func (e *Runtime) ExpectedHandshake() (runtimecontract.Handshake, bool)
- func (e *Runtime) HasPluginCapabilities(mask uint64) bool
- func (e *Runtime) HasPluginMethodID(methodID uint32) bool
- func (e *Runtime) Init() error
- func (e *Runtime) InitConfig()
- func (e *Runtime) InitHookr() error
- func (e *Runtime) InitRuntime() error
- func (e *Runtime) Instantiate() error
- func (e *Runtime) InvokeMethod(ctx context.Context, methodID uint32, payload []byte) ([]byte, error)
- func (e *Runtime) InvokeMethodWithResponse(ctx context.Context, methodID uint32, payload []byte, fn func([]byte) error) error
- func (e *Runtime) MemorySize() uint32
- func (e *Runtime) PluginCapabilities() uint64
- func (e *Runtime) PluginHandshake() (runtimecontract.Handshake, bool)
- func (e *Runtime) PluginMethodIDs() []uint32
- func (e *Runtime) RegisterMethod(methodID uint32, fn CallFn)
- func (e *Runtime) SupportsMethodABI() bool
- type RuntimeInfo
- type Sha256Hasher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DefaultHasher ¶
type DefaultHasher struct{}
DefaultHasher is an explicit no-op hasher for trusted local development flows. It should not be used when loading untrusted plugins.
type File ¶
type File struct {
Path string
Hash string
Name string
AllowUnsigned bool
// contains filtered or unexported fields
}
File is a struct that represents a WebAssembly module that is stored in a file. We can possibly add more types of Wasm modules in the future, which have different sources.
func NewFile ¶
func NewFile(path string, opts ...FileOption) (*File, error)
NewFile creates a new File instance and verifies it. If the file or name is invalid, an error is returned. Otherwise the *File is returned.
type FileOption ¶
type FileOption func(*File)
func WithAllowUnsigned ¶ added in v1.3.0
func WithAllowUnsigned() FileOption
WithAllowUnsigned explicitly allows loading a plugin without a configured hash.
func WithHash ¶
func WithHash(hash string) FileOption
WithHash sets the expected Hash field of a File
func WithHasher ¶
func WithHasher(hasher Hasher) FileOption
WithHasher sets the Hasher to use for validating the hash of the File
type Hasher ¶
type Hasher interface {
// Hash returns a hash for the provided data
Hash(data []byte) (string, error)
// IsValid checks if a hash and data match
IsValid(hash string, data []byte) bool
}
Hasher hashes and validates byte arrays. It provides functionality for computing cryptographic hashes of data and validating data against a previously computed hash.
There are two built-in implementations:
- Sha256Hasher: Uses the SHA-256 algorithm for secure hashing
- DefaultHasher: A no-op implementation that performs no actual hashing
Example:
// Using Sha256Hasher
hasher := Sha256Hasher{}
// Compute hash of a file
data, _ := os.ReadFile("plugin.wasm")
hash, _ := hasher.Hash(data)
fmt.Println("SHA-256 hash:", hash)
// Verify file integrity
isValid := hasher.IsValid(hash, data)
fmt.Println("Is valid:", isValid)
type HostMethod ¶ added in v1.3.0
type HostMethodFunc ¶ added in v1.3.0
type HostMethodFunc struct {
// contains filtered or unexported fields
}
HostMethodFunc is a wrapper for method-ID based host callbacks.
func HostFnMethod ¶ added in v1.3.0
func HostFnMethod(id uint32, fn CallFn) HostMethodFunc
HostFnMethod creates a method-ID based host callback registration.
func (HostMethodFunc) FnMethod ¶ added in v1.3.0
func (f HostMethodFunc) FnMethod() (id uint32, fn CallFn)
FnMethod returns the method ID and callback.
type Invoker ¶ added in v1.3.0
type Invoker interface {
InvokeMethod(context.Context, uint32, []byte) ([]byte, error)
InvokeMethodWithResponse(context.Context, uint32, []byte, func([]byte) error) error
HasPluginMethodID(uint32) bool
PluginHandshake() (runtimecontract.Handshake, bool)
Close(context.Context) error
}
Invoker is the minimal runtime surface used by generated host SDKs and reload hooks.
type LiveRuntime ¶ added in v1.3.0
type LiveRuntime struct {
// contains filtered or unexported fields
}
LiveRuntime wraps Runtime with file watching and atomic reload behavior.
func NewLive ¶ added in v1.3.0
func NewLive(ctx context.Context, cfg ReloadConfig, opts ...Option) (*LiveRuntime, error)
NewLive creates a plugin runtime that watches the plugin file and reloads it when the artifact changes on disk.
func (*LiveRuntime) HasPluginMethodID ¶ added in v1.3.0
func (l *LiveRuntime) HasPluginMethodID(methodID uint32) bool
func (*LiveRuntime) InvokeMethod ¶ added in v1.3.0
func (*LiveRuntime) InvokeMethodWithResponse ¶ added in v1.3.0
func (*LiveRuntime) PluginHandshake ¶ added in v1.3.0
func (l *LiveRuntime) PluginHandshake() (runtimecontract.Handshake, bool)
type NewRuntime ¶
NewRuntime returns a new wazero runtime which is called when the New method on hookr.Runtime is called. The result is closed upon wapc.Module Close.
type Option ¶
func WithContractSchema ¶ added in v1.3.0
func WithContractSchema(schema runtimecontract.Schema) Option
WithContractSchema validates and configures expected schema + handshake requirements.
func WithFile ¶
func WithFile(file string, opts ...FileOption) Option
WithFile sets the file for the engine.
func WithHostMethodFns ¶ added in v1.3.0
func WithHostMethodFns(fns ...HostMethod) Option
WithHostMethodFns sets method-ID based host callbacks callable from method-ID plugins.
func WithLogger ¶
WithLogger sets the logger for the engine.
func WithRandSource ¶
WithRandSource sets the random source for the runtime.
func WithStderr ¶
WithStderr sets the stderr writer for the engine.
func WithStdout ¶
WithStdout sets the stdout writer for the engine.
type PluginFunc ¶
type ReloadConfig ¶ added in v1.3.0
type ReloadConfig struct {
Debounce time.Duration
OnReload func(context.Context, Invoker, ReloadEvent) error
OnReloadError func(context.Context, error)
}
ReloadConfig configures automatic live reload for a plugin runtime.
type ReloadEvent ¶ added in v1.3.0
type ReloadEvent struct {
PluginPath string
Time time.Time
Previous RuntimeInfo
Current RuntimeInfo
}
ReloadEvent describes a successful live reload attempt.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
func (*Runtime) Compile ¶
Compile compiles the plugin module. It must be called after the runtime is initialized and before the module is instantiated.
func (*Runtime) ContractHasMethodID ¶ added in v1.3.0
ContractHasMethodID reports whether the configured schema contains methodID.
func (*Runtime) ContractSchema ¶ added in v1.3.0
func (e *Runtime) ContractSchema() (runtimecontract.Schema, bool)
ContractSchema returns the configured expected schema metadata, when provided.
func (*Runtime) ExpectedHandshake ¶ added in v1.3.0
func (e *Runtime) ExpectedHandshake() (runtimecontract.Handshake, bool)
ExpectedHandshake returns the configured host-side handshake requirements.
func (*Runtime) HasPluginCapabilities ¶ added in v1.3.0
HasPluginCapabilities reports whether plugin capabilities include all bits in mask.
func (*Runtime) HasPluginMethodID ¶ added in v1.3.0
HasPluginMethodID reports whether the plugin declared support for methodID.
func (*Runtime) Init ¶
Init initializes the engine by setting up the runtime, config, and hookr. It is called when the engine is created.
func (*Runtime) InitConfig ¶
func (e *Runtime) InitConfig()
InitConfig initializes the wazero module config with the default settings.
func (*Runtime) InitHookr ¶
InitHookr initializes the hookr host module and sets it to the wazero runtime.
func (*Runtime) InitRuntime ¶
Will initialize the wazero runtime
func (*Runtime) Instantiate ¶
Instantiate instantiates the compiled module. It must be called after the module is compiled. It will also call the WASI and hookr start functions if
func (*Runtime) InvokeMethod ¶ added in v1.3.0
func (e *Runtime) InvokeMethod( ctx context.Context, methodID uint32, payload []byte, ) ([]byte, error)
InvokeMethod calls a plugin method-ID endpoint with the given payload.
func (*Runtime) InvokeMethodWithResponse ¶ added in v1.3.0
func (e *Runtime) InvokeMethodWithResponse( ctx context.Context, methodID uint32, payload []byte, fn func([]byte) error, ) error
InvokeMethodWithResponse calls a plugin method-ID endpoint and invokes fn with the response bytes before returning to the caller.
func (*Runtime) MemorySize ¶
MemorySize returns the size of the memory for this instance. This is the size in bytes, not the number of pages.
func (*Runtime) PluginCapabilities ¶ added in v1.3.0
PluginCapabilities returns plugin-reported capability bits (zero when unavailable).
func (*Runtime) PluginHandshake ¶ added in v1.3.0
func (e *Runtime) PluginHandshake() (runtimecontract.Handshake, bool)
PluginHandshake returns the plugin-reported handshake if available.
func (*Runtime) PluginMethodIDs ¶ added in v1.3.0
PluginMethodIDs returns the method IDs the plugin reported during startup introspection.
func (*Runtime) RegisterMethod ¶ added in v1.3.0
RegisterMethod registers a method-ID based host callback.
func (*Runtime) SupportsMethodABI ¶ added in v1.3.0
SupportsMethodABI reports whether the loaded plugin exports __plugin_call.
type RuntimeInfo ¶ added in v1.3.0
type RuntimeInfo struct {
SchemaHash [runtimecontract.SchemaHashLen]byte
ABIMajor uint16
ABIMinor uint16
Capabilities uint64
MethodIDs []uint32
}
RuntimeInfo captures the relevant runtime metadata for reload hooks.
type Sha256Hasher ¶
type Sha256Hasher struct{}
Sha256Hasher is an implementation of the Hasher interface. It uses SHA-256 hashing algorithm to hash and validate data. This provides a secure way to verify the integrity of WebAssembly modules.
Example:
hasher := Sha256Hasher{}
hash, _ := hasher.Hash(wasmBytes)
fmt.Println("Use this hash for verification:", hash)