wallets

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package wallets provides operations for managing Smart Wallets in the CREC platform.

Smart Wallets are blockchain wallets that can be used to sign transactions and interact with smart contracts. They can be configured with allowed signers and are associated with specific blockchain networks through chain selectors.

Usage

Smart Wallets are typically accessed through the main SDK client:

client, _ := crec.NewClient(baseURL, apiKey)

wallet, err := client.Wallets.Create(ctx, CreateInput{
    Name:               "production-wallet",
    ChainSelector:      "5009297550715157269",
    WalletOwnerAddress: "0x1234...",
    WalletType:         "ecdsa",
})

For advanced use cases, create the client directly:

walletsClient, err := wallets.NewClient(&wallets.Options{
    APIClient: apiClient,
    Logger:    &logger,
})

Creating Smart Wallets

Smart Wallets support different cryptographic algorithms for signing:

  • ECDSA (Elliptic Curve Digital Signature Algorithm): Standard for Ethereum transactions, uses elliptic curve cryptography. Specify "ecdsa" as the wallet type and provide AllowedEcdsaSigners as hex-encoded public keys.
  • RSA (Rivest-Shamir-Adleman): Alternative signing algorithm using RSA keys. Specify "rsa" as the wallet type and provide AllowedRsaSigners with public exponent (E) and modulus (N) values.

Create a new Smart Wallet with required configuration:

wallet, err := client.Wallets.Create(ctx, CreateInput{
    Name:               "my-wallet",
    ChainSelector:      "5009297550715157269",
    WalletOwnerAddress: "0xabcdef...",
    WalletType:         "ecdsa",
    AllowedEcdsaSigners: &[]string{"0x123...", "0x456..."},
})
fmt.Printf("Created: %s (ID: %s, Address: %s)\n",
    wallet.Name, wallet.WalletId, wallet.Address)

Listing Smart Wallets

Use Client.List with optional filtering:

// List all Smart Wallets
wallets, hasMore, err := client.Wallets.List(ctx, ListInput{})

// Filter by name and chain selector
filterName := "production"
filterChain := "5009297550715157269"
wallets, hasMore, err := client.Wallets.List(ctx, ListInput{
    Name:          &filterName,
    ChainSelector: &filterChain,
    Limit:         ptr(10),
})

Getting, Updating, and Archiving Smart Wallets

Retrieve a specific Smart Wallet by ID:

wallet, err := client.Wallets.Get(ctx, walletID)

Update a Smart Wallet's name:

err := client.Wallets.Update(ctx, walletID, UpdateInput{
    Name: "updated-wallet-name",
})

Archive a Smart Wallet (sets status to "archived"):

wallet, err := client.Wallets.Archive(ctx, walletID)

Error Handling

All operations return typed errors that can be checked:

if errors.Is(err, wallets.ErrWalletNotFound) {
    // Handle not found case
}

if errors.Is(err, wallets.ErrNameRequired) {
    // Handle validation error
}

Index

Constants

View Source
const (
	MaxWalletNameLength = 255
)

Variables

View Source
var (
	// ErrWalletNotFound is returned when a wallet is not found (404 response)
	ErrWalletNotFound = errors.New("wallet not found")

	// Client initialization errors
	ErrOptionsRequired   = errors.New("options is required")
	ErrAPIClientRequired = errors.New("APIClient is required")

	// Validation errors
	ErrNameRequired               = errors.New("wallet name is required")
	ErrNameTooLong                = errors.New("wallet name too long")
	ErrChainSelectorRequired      = errors.New("chain selector is required")
	ErrWalletOwnerAddressRequired = errors.New("wallet owner address is required")
	ErrInvalidWalletOwnerAddress  = errors.New("wallet owner address must be a valid hex address")
	ErrWalletTypeRequired         = errors.New("wallet type is required")
	ErrUnsupportedWalletType      = errors.New("unsupported wallet type")
	ErrWalletIDRequired           = errors.New("wallet ID is required")
	ErrInvalidSignersForEcdsa     = errors.New("only allowed_ecdsa_signers can be provided for ecdsa wallet type")
	ErrInvalidSignersForRsa       = errors.New("only allowed_rsa_signers can be provided for rsa wallet type")
	ErrInvalidEcdsaSigner         = errors.New("all allowed_ecdsa_signers must be valid hex addresses")
	ErrInvalidRsaSigner           = errors.New("all allowed_rsa_signers must have non-empty E and N fields")
	ErrInvalidLimit               = errors.New("limit must be positive")
	ErrInvalidOffset              = errors.New("offset cannot be negative")
	ErrInvalidOwnerAddress        = errors.New("owner address must be a valid hex address")

	// API operation errors
	ErrCreateWallet  = errors.New("failed to create wallet")
	ErrGetWallet     = errors.New("failed to get wallet")
	ErrListWallets   = errors.New("failed to list wallets")
	ErrUpdateWallet  = errors.New("failed to update wallet")
	ErrArchiveWallet = errors.New("failed to archive wallet")

	// Response errors
	ErrUnexpectedStatusCode = errors.New("unexpected status code")
	ErrNilResponseBody      = errors.New("unexpected nil response body")
)

Sentinel errors

Functions

This section is empty.

Types

type Client

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

Client provides operations for managing CREC wallets. Wallets are blockchain wallets that can be used to sign transactions and interact with smart contracts.

func NewClient

func NewClient(opts *Options) (*Client, error)

NewClient creates a new CREC Wallets client with the provided options. Returns a pointer to the Client and an error if any issues occur during initialization.

  • opts: Options for configuring the CREC Wallets client, see Options for details.

func (*Client) Archive

func (c *Client) Archive(ctx context.Context, walletID uuid.UUID) error

Archive archives a wallet by transitioning it to archived status via PATCH. Archiving is synchronous and returns the wallet in "archived" status.

Parameters:

  • ctx: The context for the request.
  • walletID: The UUID of the wallet to archive.

Returns an error if the operation fails or the wallet is not found.

func (*Client) Create

func (c *Client) Create(ctx context.Context, input CreateInput) (*apiClient.Wallet, error)

Create creates a new wallet in the CREC backend.

Parameters:

  • ctx: The context for the request.
  • input: The wallet creation parameters.

Returns the created wallet or an error if the operation fails.

func (*Client) Get

func (c *Client) Get(ctx context.Context, walletID uuid.UUID) (*apiClient.Wallet, error)

Get retrieves a specific wallet by its ID.

Parameters:

  • ctx: The context for the request.
  • walletID: The UUID of the wallet to retrieve.

Returns the wallet or an error if the operation fails or the wallet is not found.

func (*Client) List

func (c *Client) List(ctx context.Context, input ListInput) ([]apiClient.Wallet, bool, error)

List retrieves a list of wallets.

Parameters:

  • ctx: The context for the request.
  • input: The list parameters including filters and pagination.

Returns a list of wallets and a boolean indicating if there are more results.

func (*Client) Update

func (c *Client) Update(ctx context.Context, walletID uuid.UUID, input UpdateInput) error

Update updates a wallet's information.

Parameters:

  • ctx: The context for the request.
  • walletID: The UUID of the wallet to update.
  • input: The wallet update parameters.

Returns an error if the operation fails or the wallet is not found.

type CreateInput

type CreateInput struct {
	Name                string
	ChainSelector       string
	WalletOwnerAddress  string
	WalletType          apiClient.WalletType
	AllowedEcdsaSigners *[]string
	AllowedRsaSigners   *apiClient.RSASignersList
	StatusChannelId     *uuid.UUID `json:"status_channel_id,omitempty"`
}

CreateInput defines the input parameters for creating a new wallet.

  • Name: The name of the wallet.
  • ChainSelector: The chain selector identifying the blockchain network.
  • WalletOwnerAddress: The wallet contract owner address (42-character hex string starting with 0x).
  • WalletType: The type of the wallet (e.g., "ecdsa").
  • AllowedEcdsaSigners: Optional list of allowed ECDSA public signing keys.
  • AllowedRsaSigners: Optional list of allowed RSA public signing keys.
  • StatusChannelId: Optional unique identifier for the channel where the wallet status will be published

type ListInput

type ListInput struct {
	Name          *string
	ChainSelector *string
	Owner         *string
	Address       *string
	Type          *apiClient.WalletType
	Status        *[]apiClient.WalletStatus
	Limit         *int
	Offset        *int64
}

ListInput defines the input parameters for listing wallets.

  • Name: Optional filter to search wallets by name (case-insensitive partial match).
  • ChainSelector: Optional filter to search wallets by chain selector.
  • Owner: Optional filter to search wallets by owner address (42-character hex string starting with 0x).
  • Address: Optional filter to search wallets by wallet address (42-character hex string starting with 0x).
  • Type: Optional filter to search wallets by type (e.g., "ecdsa", "rsa").
  • Status: Optional filter to search wallets by status (e.g., "deployed", "deploying", "failed", "pending", "deleted").
  • Limit: Maximum number of wallets to return per page.
  • Offset: Number of wallets to skip for pagination (default: 0).

type Options

type Options struct {
	Logger    *slog.Logger
	APIClient *apiClient.ClientWithResponses
}

Options defines the options for creating a new CREC Wallets client.

  • Logger: Optional logger instance.
  • APIClient: The CREC API client instance.

type UpdateInput

type UpdateInput struct {
	Name string
}

UpdateInput defines the input parameters for updating a wallet.

  • Name: The new name for the wallet.

Jump to

Keyboard shortcuts

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