{"modulePath":"github.com/data-preservation-programs/singularity","version":"v1.0.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package wallet\n\n## Functions\n\n```go\nfunc CountLegacyKeys(db *gorm.DB) int64\n```\ncounts actors that still have a non-empty private\\_key in the database. returns 0 if the column has been dropped.\n\n```go\nfunc DropPrivateKeyColumn(db *gorm.DB) error\n```\ndrops the private\\_key column from the actors table. caller is responsible for confirming this is desired.\n\n```go\nfunc GetKeystoreDir() string\n```\nreturns default keystore directory path TODO: make configurable via config file\n\n```go\nfunc GetOrCreateActor(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tlotusClient jsonrpc.RPCClient,\n\twallet *model.Wallet,\n) (*model.Actor, error)\n```\nlazy actor lookup and creation for a wallet workflow: import wallet offline → fund externally → first deal queries on-chain actor returns existing actor if wallet.ActorID already set, otherwise queries lotus and creates record\n\n```go\nfunc HasPrivateKeyColumn(db *gorm.DB) bool\n```\n\n```go\nfunc SignWithWallet(ks keystore.KeyStore, wallet model.Wallet, msg []byte) (*crypto.Signature, error)\n```\nloads private key from keystore and signs a filecoin message\n\n## Types\n\n```go\ntype DefaultHandler struct{}\n```\n\n```go\nfunc (DefaultHandler) AttachHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tpreparationID string,\n\twalletAddressOrID string,\n) (*model.Preparation, error)\n```\nattaches wallet to preparation for deal-making accepts wallet address or wallet ID\n\n```go\nfunc (DefaultHandler) DetachHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tpreparationID string,\n\twalletAddressOrID string,\n) (*model.Preparation, error)\n```\ndetaches wallet from preparation accepts wallet address or ID\n\n```go\nfunc (DefaultHandler) ImportKeystoreHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tks keystore.KeyStore,\n\trequest ImportKeystoreRequest,\n) (*model.Wallet, error)\n```\nimports wallet by saving private key to keystore and creating wallet record does not require actor to exist on-chain - wallet can be imported offline uses external keystore instead of storing keys in database\n\n```go\nfunc (DefaultHandler) ListAttachedHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tpreparationID string,\n) ([]model.Wallet, error)\n```\n\n```go\nfunc (DefaultHandler) ListHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n) ([]model.Wallet, error)\n```\nListHandler retrieves a list of all the wallets stored in the database.\n\nParameters:\n\n  - ctx: The context for database transactions and other operations.\n  - db: A pointer to the gorm.DB instance representing the database connection.\n\nReturns:\n\n  - A slice containing all Wallet models from the database.\n  - An error, if any occurred during the database fetch operation.\n\n```go\nfunc (DefaultHandler) RemoveHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tks keystore.KeyStore,\n\taddress string,\n) error\n```\nremoves wallet record and keystore file does not remove the associated actor — actors may be shared or tracked independently\n\n```go\ntype ExportKeysResult struct {\n\tExported int      // actors whose keys were saved to keystore + wallet record created\n\tSkipped  int      // actors whose wallet already exists (by address match)\n\tErrors   []string // actors that failed (logged but don't abort)\n}\n```\nExportKeysResult reports what export-keys did for each actor\n\n```go\nfunc ExportKeysHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tks keystore.KeyStore,\n) (*ExportKeysResult, error)\n```\nexports private keys from the legacy Actor.PrivateKey column into the filesystem keystore, creating Wallet records where needed. idempotent -- skips actors whose address already has a Wallet record. does not delete Actor.PrivateKey; caller decides when to drop the column.\n\n```go\ntype Handler interface {\n\tImportKeystoreHandler(\n\t\tctx context.Context,\n\t\tdb *gorm.DB,\n\t\tks keystore.KeyStore,\n\t\trequest ImportKeystoreRequest,\n\t) (*model.Wallet, error)\n\tAttachHandler(\n\t\tctx context.Context,\n\t\tdb *gorm.DB,\n\t\tpreparation string,\n\t\twallet string,\n\t) (*model.Preparation, error)\n\tDetachHandler(\n\t\tctx context.Context,\n\t\tdb *gorm.DB,\n\t\tpreparation string,\n\t\twallet string,\n\t) (*model.Preparation, error)\n\tListHandler(\n\t\tctx context.Context,\n\t\tdb *gorm.DB,\n\t) ([]model.Wallet, error)\n\tListAttachedHandler(\n\t\tctx context.Context,\n\t\tdb *gorm.DB,\n\t\tpreparation string,\n\t) ([]model.Wallet, error)\n\tRemoveHandler(\n\t\tctx context.Context,\n\t\tdb *gorm.DB,\n\t\tks keystore.KeyStore,\n\t\taddress string,\n\t) error\n}\n```\n\n```go\nvar Default Handler = \u0026DefaultHandler{}\n```\n\n```go\ntype ImportKeystoreRequest struct {\n\tPrivateKey string `json:\"privateKey\"` // lotus wallet export format\n\tName       string `json:\"name\"`       // optional human-readable name\n}\n```\n\n```go\ntype MockWallet struct {\n\tmock.Mock\n}\n```\n\n```go\nfunc (m *MockWallet) AttachHandler(ctx context.Context, db *gorm.DB, preparation string, wallet string) (*model.Preparation, error)\n```\n\n```go\nfunc (m *MockWallet) DetachHandler(ctx context.Context, db *gorm.DB, preparation string, wallet string) (*model.Preparation, error)\n```\n\n```go\nfunc (m *MockWallet) ImportKeystoreHandler(ctx context.Context, db *gorm.DB, ks keystore.KeyStore, request ImportKeystoreRequest) (*model.Wallet, error)\n```\n\n```go\nfunc (m *MockWallet) ListAttachedHandler(ctx context.Context, db *gorm.DB, preparation string) ([]model.Wallet, error)\n```\n\n```go\nfunc (m *MockWallet) ListHandler(ctx context.Context, db *gorm.DB) ([]model.Wallet, error)\n```\n\n```go\nfunc (m *MockWallet) RemoveHandler(ctx context.Context, db *gorm.DB, ks keystore.KeyStore, address string) error\n```\n\n","path":"github.com/data-preservation-programs/singularity/handler/wallet","name":"wallet","synopsis":"","isRedistributable":true}
