Commit Graph

181 Commits

Author SHA1 Message Date
Michael Bradley, Jr 99a56e8aff refactor: all tests should write to `test/build/` relative to the root of the repo 2021-07-29 19:05:24 -05:00
Michael Bradley, Jr 24b8da461e refactor: update modules in examples/waku/ re: changes to the originals in nim-waku/examples/v2/ 2021-07-29 19:05:24 -05:00
Michael Bradley, Jr d45400f20e refactor: WakuNode.init -> WakuNode.new in status/waku
`status/waku.nim` is an older module that provided just enough waku v2
integration to allow for a test.

This commit modifies it re: the recent nim-waku refactor efforts so that it and
the test for it works correctly.

The module will soon be overhauled by moving the example client's waku
logic (with some adaptations) into `status/waku.nim`.
2021-07-29 19:05:24 -05:00
Michael Bradley, Jr 66ffd48fd4 build: bump vendor/nimbus-build-system 2021-07-29 19:05:24 -05:00
Michael Bradley, Jr 754d78e920 build: bump vendor/nim-sqlcipher 2021-07-29 19:05:24 -05:00
Michael Bradley, Jr 73922446a2 build: bump vendor/nim-web3 2021-07-29 19:05:24 -05:00
Michael Bradley, Jr 64340cf0e1 build: bump vendor/nim-waku 2021-07-29 19:05:24 -05:00
Michael Bradley, Jr 8a97ba3ad0 build: bump vendor/nim-task-runner 2021-07-29 19:05:24 -05:00
Michael Bradley, Jr a583204253 build: bump vendor/nim-chronos 2021-07-29 19:05:24 -05:00
Eric Mastro 1d1ba36380 feat: delete wallet account
Closes #225.

Deletes wallet account by wallet index.

Add account db tests for additional account procs: getWalletAccount, getWalletAccounts, and deleteWalletAccount

Add account generator tests for additional generator procs: deleteKeyFile
2021-07-29 18:53:26 -05:00
Michael Bradley, Jr af1584d617 refactor: examples/chat -> examples/client
The example client we're building is more than a "chat" program: it
has (beginnings of) support for wallets and eventually the full range of
capabilities implemented in nim-status.

Rename `examples/chat.nim` to `examples/client.nim` and make a number of
related changes/renamings that help to make it more clear that the example
client is a "client in general", not just a chat client.

Also, put the copied example waku chat2 code under `examples/waku/`.
2021-07-29 15:06:15 -05:00
Michael Bradley, Jr 54cb3d746f refactor: nim_status -> status
The name of the repo is not being changed. But instead of doing:

```nim
import nim_status
```

You would do:

```nim
import status
```

This is in line with nim-chronos (`import chronos`), nim-waku (`import waku`),
and many other Nim libs.
2021-07-29 14:23:26 -05:00
Michael Bradley, Jr 3c4af4d9f3
feat: en/decode Status payloads when sending/receiving messages (first steps)
Copy protobuf specs from status-go, make necessary adjustments for use via
nim-protobuf-serialization. Many thanks to @richard-ramos for his help with
this aspect and others!

Implement "first steps" towards encoding and decoding Status payloads when
sending and receiving messages.

That consists of using an incomplete
`ProtocolMessage(ApplicationMetadataMessage(ChatMessage)))` wrapping of
messages, assuming all messages currently being sent correspond to public
chats. It's incomplete because there are many fields for which values are not
being derived, and there is no encryption performed.

A series of future pull requests will fill in the missing pieces and expand our
usage of the protobuf specs, i.e. allow nim-status to send and receive more
kinds of Status messages.

Note that the waku v2 content topics are not yet using a hash of the
user-supplied topic name; that will also be addressed in a future pull request.

It's also important to note that a refactor is pending re: moving the import
and usage of nim-waku inside the `nim_status` library, as well refactorings re:
exception handling, imports and exports, and other aspects that have been
commented upon in other recent pull requests. This commit builds on the work
done to date in the same way as before, but there is already awareness of what
should be changed and can be improved.

Ensure that joined waku v2 content topics (whether joined in the TUI or
specified on the command-line) conform to the recommendations in
[23/WAKU2-TOPICS](https://rfc.vac.dev/spec/23/).

Unrelated to the main focus of this commit: use a fixed-length array instead of
a sequence for collecting bytes of user input (keyboard and mouse) in the
`input` worker thread. It's more efficient to do it that way: less allocation
and garbage collection.

---

Closes #217.
2021-07-29 12:27:06 +03:00
Vitaliy Vlasov b8ffb5e1ea
Custom tokens support in example client app 2021-07-29 12:26:58 +03:00
Eric Mastro 5a33df2f47 feat: Add watch-only wallet account
Closes: #226

Add command (`/addwalletwatch`, `/addwatch`) that allows adding a watch-only account to the example client.
2021-07-26 12:03:27 +10:00
Eric Mastro dde6957cab feat: import wallet account via mnemonic
Closes: #224.

Allows a user to import a wallet account via 12-word mnemonic seed.

The account is first imported in the account generator. Then a wallet account is derived at the root wallet path (m/44'/60’/0’/0/0) from the master key of the mnemonic. This account is then stored in the Accounts table of the user’s db.
2021-07-25 16:55:43 +10:00
Michael Bradley, Jr 651f533f1c refactor: use SQLCipher v4 defaults re: algorithms, iterations, etc.
Comment out and provide an explanatory comment re: the custom settings that we
originally carried over from status-go.

Closes #209.
2021-07-22 10:39:50 -05:00
Michael Bradley, Jr a570e8b2db refactor: use now().utc when generating keystore files 2021-07-22 15:55:36 +10:00
Eric Mastro ba3aea2393 feat: support importing wallet accout via private key
Add funcs to support importing a wallet account via private key.

Support password validation before importing the keystore file. Prevent duplicate keystore files from being imported.

Add keystore file unit tests for storing and loading of key files

Add import wallet pk command to example chat client

Refactor web3_conversions imports to insteaad import `nim_status/conversions`.
2021-07-22 15:55:36 +10:00
Eric Mastro d0a3e4ff01 refactor: add Event suffix to all event types 2021-07-22 12:19:57 +10:00
Michael Bradley, Jr e3626d1379 fix: restore topic to constructor call for UserMessage 2021-07-22 12:19:57 +10:00
Eric Mastro e2596a0c18 feat: generate wallet account
Closes: #214, #215.

Almost all the work for #197 is included in this PR.

Generate a new wallet account using `/add`, `/addaccount`

feat: create settings when creating/importing a login account
When creating or importing a new account (a login account, not a wallet account), settings are now created.

feat: list wallet accounts
Wallet accounts can be listed using `/wallets`, `/listwalletaccounts`, and `/listwallets`. This gets all accounts in the user db that are not chat accounts. It would be much better to store all wallet accounts in the db using the `wallet` flag, however status-go did not do this, reserving that flag for the root wallet account and creating a unique db constraint on that column.
2021-07-22 12:19:57 +10:00
Michael Bradley, Jr faa16c2078 build: switch from MSYS2 MINGW64 to MSYS2 UCRT64
Gives better compatibility at compile and runtime, and notably better
performance re: e.g. disk IO.
2021-07-18 23:19:39 -05:00
Michael Bradley, Jr 185edf73e1 refactor: import task_runner from vendor and remove task_runnner modules under examples/chat 2021-07-18 23:19:15 -05:00
Michael Bradley, Jr 075b205aad build: bump vendor/nim-task-runner to HEAD of its impl/beta2 branch 2021-07-18 23:19:15 -05:00
Eric Mastro cd1ceadb4b
fix: remove unneeded serialization 2021-07-16 16:00:26 +10:00
Eric Mastro 68c11caad8 feat: user db accounts CRUD
Closes: #204
Closes: #205

feat: insert accounts in user db during create account
feat: insert accounts in user db during import mnemonic

1. This only handles `createAccount`. No other parts of CRUD are handled yet.
2021-07-15 17:11:39 -05:00
Michael Bradley, Jr 3c2834d4d0 refactor: early return from importMnemonic if error
An early return is used by createAccount when an error is encountered;
importMnemonic should do the same.
2021-07-15 15:54:55 -05:00
Michael Bradley, Jr 6c70c1c0fc refactor: epochTime() -> getTime().toUnix() 2021-07-15 15:54:55 -05:00
Eric Mastro f81027c7d5 refactor(nim-status): change to a port of status-go's account generation
Closes: #199

Some functions in `nim-status` were attempting to do too much in comparison to their `status-go` counterparts. The filesystem in `nim-status` varied quite a lot from the filesystem in `status-go`, which made comparing functions difficult. The end result was that certain cryptographic operations, such as generating a `keyUid` did not match between `nim-status` and `status-go`.

This PR fixes this problem by first moving some account generation files around in the filesystem to more closely mirror `status-go`. Then, the account generation functions from `status-go` were ported over to `nim-status` and the example chat client was changed to use these new functions.

Once the port from `status-go` had been completed, it could be more clearly seen that the cause of the `keyUid` mismatch was due to the use of `nim-eth`’s `PrivateKey` type over `secp256k1`’s `SkPrivateKey`. `nim-eth` does not include the `0x04` prefix that `secp256k1` uses, because `nim-eth` is more focused on ethereum implementations which do not need the prefix. Switching `PrivateKey` (in `nim-eth`) to `SkPrivateKey` (in `secp256k1`) and `PublicKey` to `SkPublicKey` allowed the `keyUid` generation to match between `nim-status` and `status-go`.

There was also some confusion between two different `Account` types in the codebase. One `Account` type was for public consumption and stored in the unencrypted accounts db. The other `Account` type contained private keys and was meant to be stored in the encrypted user db. The public `Account` type was changed to `PublicAccount` to avoid confusion.

Other notable changes include:

- chore(nim-status): Keccak 256 hash the plain text db password before keying the db.
- feat(ex-client): Move the db interactions to the nim-status client instead of doing all of it in the task.
- chore(ex-client): Remove `bip32passphrase` from `/import` arg and assume an empty string for now.

### Todo:

1. Adjust `derive` to use hardened children. This can be shown in the “derive address from imported key” test that fails when uncommented. [An issue has been created for this]([https://github.com/status-im/nim-status/issues/211](https://github.com/status-im/nim-status/issues/211))
2021-07-15 15:54:55 -05:00
Eric Mastro 48b4eb390d refactor: move funcs to resemble status-go
Reshuffle and organise files to resemble how status-go has organised its files. This helps to not confuse migration efforts and reorganises some nim-status code that was not well organised.

refactor: accounts.Account -> PublicAccount
2021-07-15 15:54:55 -05:00
Michael Bradley, Jr f4e4474d50 feat: in example client's TUI user messages are labeled according to their waku v2 content topic 2021-07-15 10:07:07 -05:00
Michael Bradley, Jr bbf25d7873 feat: add join, leave, and topics commands to example client 2021-07-15 15:27:37 +10:00
Eric Mastro 4fc6d7641a feat: Add help command and help definitions
Add support for the `/help` command, which dynamically builds a list of help commands based on the `help()` procs defined for each command type, ie `Login`.

The `help` proc returns a type of `HelpText`, which contains all the information necessary to render help information for that command. It contains the command, parameters (each parameters contains a name and description), aliases, and a description.

The help text is generated (at compile time) by a macro called `buildCommandHelp()`. Once the `/help` command is executed, the output of `buildCommandHelp()` is passed to the task runner so that a `HelpResult` event can be created and the help text can be displayed on screen. Because the text is generated at compile time, it is not necessary to pass this text through the task runner, and is displayed directly on screen in the main thread.

## NOTES
1. The help text is quite long, especially given there are blank spaces in between each command. This would require the chat client to be able to scroll unless it is sufficiently tall.
2. I am not married to the display output at all, even after experimenting with a few different layouts. There is some leftover rendering code in the `HelpResult` action which allows for the the command description to be written on the same line as the command name and keep the description spaced in line with all other descriptions, but it didn’t appear as readable as the format that I settled on in the end. I left it in there in case we wanted to change up how help is rendered.
2021-07-07 20:03:40 +10:00
Michael Bradley, Jr 85453f37d9 feat: add login and logout commands to example client 2021-07-07 16:23:32 +10:00
Michael Bradley, Jr b36f908bbe chore: delete examples/chat/task_runner/tasks_playground.nim
It's no longer in use nor serving as a helpful reference, so delete it.
2021-07-06 13:09:32 -05:00
Michael Bradley, Jr 941576e529 refactor: remove all use of cast in tests 2021-07-06 13:09:05 -05:00
Michael Bradley, Jr f389c91a9a refactor: remove unnecessary use of cast in modules within examples
A few uses remain:

* In `examples/waku_chat2.nim`; that code was copied from nim-waku and is only
for reference.
* In `chat/client/tasks.nim`, where the signature of
`proc statusContext*(arg: ContextArg)` is intended to match `type Context` of
`examples/chat/task_runner/tasks.nim` but we know the argument passed to it is
actually of `type StatusArg`.
* In multiple modules within `examples/chat/task_runner/`, where casting plays
a role in de/serializing data sent across instances of `AsyncChannel`, and
resolving the correct type of worker (thread or pool) per `kind` metatdata
tracked as part of worker creation.
2021-07-06 13:09:05 -05:00
Michael Bradley, Jr 16045f5cee refactor: remove all use of cast in modules within nim_status 2021-07-06 17:36:17 +10:00
Vitaliy Vlasov 9e70dbc89a feat: add importmnemonic command 2021-07-06 17:36:17 +10:00
Eric Mastro 0e4fd872fa feat: Add create account and list accounts commands
Closes: #180.
Closes: #177.
Closes: #184.

Accounts can be created with the `/create` or `/createaccount` command. Existing accounts can be listed with the `/list` or `/listaccounts` command.

Account keyuid is now being generated on the multiaccount.

account.loginTimestamp is now NULL when inserted in the DB, and can be updated using `updateAccount` or `updateAccountTimestamp`.

fix: run migrations only on non-existant DBs
Removes the need to pass in a migration definition file. We do not need to run migrations, unless we are instantiating a DB.
2021-06-30 23:15:18 -05:00
Michael Bradley, Jr dfe472953a ci: remove workaround re: setting RUSTFLAGS env var in Windows
It's no longer necessary owing to changes made yesterday by the MSYS2
maintainers/contributors.
2021-06-30 09:53:21 -05:00
Michael Bradley, Jr 0340fc0ea5 ci: limit to static linking in test workflow in GitHub Actions
Using a full matrix of static/shared linking has been useful in the past for
catching edge cases, but none have been experienced in recent months so limit
to static linking to reduce build and run times in this workflow. The full
matrix can always be activated in a PR branch if it's suspected we're bumping
into an edge case as experienced previously.
2021-06-29 15:12:27 -05:00
Michael Bradley, Jr 9aec834b05 ci: implement workaround re: Rust in MSYS2/MINGW64 on Windows
See: https://github.com/msys2/MINGW-packages/issues/9010

Also remove a previous workaround re: Rust in MSYS2/MINGW64 on Windows that's
no longer necessary.

And cleanup implementation of a workaround re: the `ar` utility on macOS,
i.e. do it the same way using an `if..fi` block.
2021-06-29 13:42:13 -05:00
Michael Bradley, Jr 78ba4759e5 feat: example client 2021-06-28 17:50:19 -04:00
Vitaliy Vlasov 3bdbbce3cf Add mnemonic phrase generation; generateAndDeriveAddresses, storeDerived, loadAccount 2021-06-25 16:42:15 -05:00
Vitaliy Vlasov 32376442ec Add StatusConfig and more methods to StatusObject 2021-06-25 16:02:32 -05:00
Eric Mastro 91376957b0 Transaction history 2021-06-25 15:33:48 -05:00
Michael Bradley, Jr 21aebe41be refactor: remove status-go and shim/related modules in nim_status
Also adjust Makefile, GitHub Actions workflow, etc.
2021-03-18 10:36:21 -05:00
Michael Bradley, Jr ace63694ad experiment: client init() proc, openAccounts(), starting waku in a separate thread 2021-03-18 10:36:21 -05:00