Help us shape the future of Go! Take the 2026 Go Developer Survey

signing

package
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package signing implements Hyperliquid L1 agent signing (sign_l1_action), ported from trade/src/app/features/perps/lib/hyperliquid{,Hash}.ts.

Only the mainnet "a" source is supported because the Oku backend hardcodes Hyperliquid mainnet (account/src/connectapi/perps/signing.go).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActionHash

func ActionHash(actionJSON string, vault string, nonce uint64) ([32]byte, error)

ActionHash returns keccak256(msgpack(action) || nonce_be64 || vaultFlag).

func AddressOf

func AddressOf(pub *secp256k1.PublicKey) string

AddressOf returns the EIP-55 checksummed address of a public key.

func AgentDigest

func AgentDigest(connectionID [32]byte) [32]byte

AgentDigest returns the EIP-712 digest for Agent{source:"a", connectionId} in domain {name:"Exchange", version:"1", chainId:1337, verifyingContract:0x0}.

func EncodeActionJSON

func EncodeActionJSON(actionJSON string) ([]byte, error)

EncodeActionJSON msgpack-encodes a JSON document preserving object key order, matching @msgpack/msgpack encode(JSON.parse(actionJSON)) as used by trade/src/app/features/perps/lib/hyperliquidHash.ts. The JSON is walked token by token so key order is exactly the wire order; the msgpack wire primitives come from github.com/vmihailenco/msgpack/v5, the library the account backend uses for the same hash. Non-integer numbers are rejected (fail closed): no Oku action currently contains them and float encoding differs across SDKs.

func GenerateKey

func GenerateKey() ([]byte, error)

GenerateKey returns 32 random key bytes.

func RecoverAddress

func RecoverAddress(d [32]byte, sig Signature) (string, error)

RecoverAddress recovers the signer address for a digest, for self-checks.

Types

type KeySigner

type KeySigner struct {
	// contains filtered or unexported fields
}

KeySigner signs with an in-memory secp256k1 key.

func NewKeySigner

func NewKeySigner(raw []byte) (*KeySigner, error)

NewKeySigner builds a signer from 32 raw key bytes.

func (*KeySigner) Address

func (k *KeySigner) Address() string

Address implements Signer.

func (*KeySigner) SignDigest

func (k *KeySigner) SignDigest(d [32]byte) (Signature, error)

SignDigest implements Signer. v is normalized to 27/28 like the frontend.

type Signature

type Signature struct {
	R string `json:"r"`
	S string `json:"s"`
	V uint64 `json:"v"`
}

Signature is an EVM signature in the shape ConfirmAction expects.

type SignedAction

type SignedAction struct {
	ActionJSON string    `json:"actionJson"`
	Nonce      string    `json:"nonce"` // int64 encoded as string per protojson
	Signature  Signature `json:"signature"`
}

SignedAction mirrors gfxcafe.oku.account.v2.SignedAction.

func SignAction

func SignAction(s Signer, actionJSON string, nonce uint64) (SignedAction, error)

SignAction signs the exact actionJSON for the master account. Vault and subaccount routing is deliberately unsupported (v1 is master-only), so the vault flag is always 0x00.

func SignActionContext

func SignActionContext(ctx context.Context, s Signer, actionJSON string, nonce uint64) (SignedAction, error)

SignActionContext propagates cancellation to remote signing implementations.

type Signer

type Signer interface {
	Address() string
	SignDigest(digest [32]byte) (Signature, error)
}

Signer signs an L1 connection id. Implementations must never expose key material through this interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL