Skip to content

Conversation

@zachfedor
Copy link
Collaborator

@zachfedor zachfedor commented Apr 4, 2025

This PR adds the ability to create a new Filecoin wallet via CLI or API endpoint using the Lotus RPC client, saving the new wallet address and private key to the database as if it was imported.

Fixes #469

@zachfedor zachfedor changed the title Add create wallet handler, cmd, and API #469 [DRAFT] Add create wallet handler, cmd, and API Apr 4, 2025
@zachfedor zachfedor changed the title [DRAFT] Add create wallet handler, cmd, and API [Draft] Add create wallet handler, cmd, and API Apr 4, 2025
@Sankara-Jefferson Sankara-Jefferson added the feature request Feature Request label Apr 7, 2025
@Sankara-Jefferson Sankara-Jefferson self-requested a review April 7, 2025 19:10
@parkan
Copy link
Collaborator

parkan commented Apr 9, 2025

you shouldn't need to RPC to lotus to generate keypairs, it's just a few calls to go-address/go-crypto, take a look in https://github.com/filecoin-project/lotus/blob/master/chain/wallet/key/key.go

RPCing to a node only makes sense if the user is running their own, public nodes (or SPs) will not give you write or admin privs to manage wallets

signing and other wallet-related functionality is already handled internally by singularity

@parkan
Copy link
Collaborator

parkan commented Apr 9, 2025

one thing to note is that after creating the keypair (by whatever means) the address will need to be initialized on-chain by sending a message referencing it, in most cases funding it with FIL or datacap

this needs to happen from a different, already existing actor for obvious reasons

(that is to say the state check here will likely fail after creation, however this is true even if the wallet is created via lotus RPC as no messages reference it at that point and therefore it won't be in chainstate -- my guess is that this is likely why wallet creation was not originally implemented inside singularity)

@parkan
Copy link
Collaborator

parkan commented May 1, 2025

hi @zachfedor I would suggest rebasing on #467 to get passing go-check

zachfedor added 2 commits May 12, 2025 12:01
- Add init function to create full current schema on brand new clean
databases and run missing migrations on any databases using old
auto-migrate strategy with existing data.
- Add CLI commands to migrate up, down, or to a specified version by ID
- Add utility functions to get list of migration IDs ran on current
database, check if migration has run by ID, etc.
Copy link
Contributor

@Sankara-Jefferson Sankara-Jefferson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zachfedor I pulled this and tested and the wallet addresses were created successfully and saved in the DB!
I can also list them using singularity wallet list command.

To make the CLI documentation clear and user-friendly, you should explicitly document:

  • What the [type] argument represents
  • What values are supported
  • What the default behavior is if not provided

My tests

jeffersonsankara@Jeffersons-MacBook-Pro singularity % ./singularity wallet create --help
NAME:
   singularity wallet create - Create a new wallet

USAGE:
   singularity wallet create [command options] [type]

OPTIONS:
   --help, -h  show help
jeffersonsankara@Jeffersons-MacBook-Pro singularity % ./singularity wallet create       
ID                                         Address                                    
f16wmhtwtu4aib5xazb3fwxvewue7b4dmyansznta  f16wmhtwtu4aib5xazb3fwxvewue7b4dmyansznta  
jeffersonsankara@Jeffersons-MacBook-Pro singularity % ./singularity wallet create secp256k1
ID                                         Address                                    
f1uwurfy2rdfsey4dwdnuk4utwm62fcxkehdjp2ki  f1uwurfy2rdfsey4dwdnuk4utwm62fcxkehdjp2ki  
jeffersonsankara@Jeffersons-MacBook-Pro singularity % ./singularity wallet create bls
ID                                                                                      Address                                                                                 
f3qya2n6wg2wgu5nrhyix7serr2llo64mbtgqtedxrywa6xanfdsalmkk4hotxvhw4zct2y4dqgc3quugbduaa  f3qya2n6wg2wgu5nrhyix7serr2llo64mbtgqtedxrywa6xanfdsalmkk4hotxvhw4zct2y4dqgc3quugbduaa  
jeffersonsankara@Jeffersons-MacBook-Pro singularity % 
jeffersonsankara@Jeffersons-MacBook-Pro singularity % ./singularity wallet list
ID                                                                                      Address                                                                                 
f03539246                                                                               f12syf7zd3lfsv43aj2kb454ymaqw7debhumjnbqa                                               
f16wmhtwtu4aib5xazb3fwxvewue7b4dmyansznta                                               f16wmhtwtu4aib5xazb3fwxvewue7b4dmyansznta                                               
f1uwurfy2rdfsey4dwdnuk4utwm62fcxkehdjp2ki                                               f1uwurfy2rdfsey4dwdnuk4utwm62fcxkehdjp2ki                                               
f3qya2n6wg2wgu5nrhyix7serr2llo64mbtgqtedxrywa6xanfdsalmkk4hotxvhw4zct2y4dqgc3quugbduaa  f3qya2n6wg2wgu5nrhyix7serr2llo64mbtgqtedxrywa6xanfdsalmkk4hotxvhw4zct2y4dqgc3quugbduaa  
jeffersonsankara@Jeffersons-MacBook-Pro singularity % 
jeffersonsankara@Jeffersons-MacBook-Pro singularity % ./singularity wallet remove --really-do-it f16wmhtwtu4aib5xazb3fwxvewue7b4dmyansznta
jeffersonsankara@Jeffersons-MacBook-Pro singularity % singularity wallet list                                 
ID                                                                                      Address                                                                                 
f03539246                                                                               f12syf7zd3lfsv43aj2kb454ymaqw7debhumjnbqa                                               
f1uwurfy2rdfsey4dwdnuk4utwm62fcxkehdjp2ki                                               f1uwurfy2rdfsey4dwdnuk4utwm62fcxkehdjp2ki                                               
f3qya2n6wg2wgu5nrhyix7serr2llo64mbtgqtedxrywa6xanfdsalmkk4hotxvhw4zct2y4dqgc3quugbduaa  f3qya2n6wg2wgu5nrhyix7serr2llo64mbtgqtedxrywa6xanfdsalmkk4hotxvhw4zct2y4dqgc3quugbduaa  
jeffersonsankara@Jeffersons-MacBook-Pro singularity % 


Unit tests

I ran this and the wallet create logic works as expected under the SQLite setup used in unit tests. It failed for Postgres and I was expecting that based on our last conversation.

Sample description to add to documentation:

Creates a new Filecoin wallet.

You can optionally specify the wallet type to generate. Supported types:

secp256k1 (default)
bls
If no type is specified, a secp256k1 wallet will be created by default.

Examples:
singularity wallet create
singularity wallet create secp256k1
singularity wallet create bls

@parkan
Copy link
Collaborator

parkan commented Jun 4, 2025

@zachfedor do you have preferences for release workflow (merge feature branches to main and tag release, create release branch, something else?)

additionally could you please PR with the new migration approach since it may affect how I'm handling min-piece-size and piece-type fields

@zachfedor
Copy link
Collaborator Author

@Sankara-Jefferson and @parkan I'm closing this to reopen a new PR rebased on #467 as mentioned above.

New PR is #496. It's got all the notes for migrations for you.

And I'm flexible on release workflow, @parkan. Looks like you've been merging to main and tagging releases. That's totally fine by me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request Feature Request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Creation of a new wallet address

3 participants