siacentral / sia-lite-wallet-web

Secure non-custodial cryptocurrency wallet with support for Siacoin (SC) and the Ledger Nano S/X
https://wallet.siacentral.com
GNU Affero General Public License v3.0
34 stars 12 forks source link

export crypto package #11

Open roccomuso opened 3 years ago

roccomuso commented 3 years ago

Would be useful to extract all the siacoin related crypto fns in a separate package.

Is there any doc available around that show how to encode a siacoin address and create and sign a tx?

n8maninger commented 3 years ago

I agree, the WASM code is pretty poorly architected and a major source of maintenance issues. The frontend handles a lot of the structure and management of wallets right now, something I'd like to move away from.

I have started to restructure and shift management fully into a separate package with the goal being a single open source package with simple "lite" non-custodial support of multiple currencies: SC, HNS, BTC, ETH, etc. Ideally they would be fairly independent so wrappers could be created for use outside of browsers.

Since the important crypto functions are written in Go a lot of the Siacoin logic and types are imported directly from gitlab.com/NebulousLabs/Sia. The only places where this is not true is where there were dependencies that would not work in WASM like BBolt.

How addresses are encoded: https://gitlab.com/NebulousLabs/Sia/-/blob/master/types/signatures.go#L181

For building a transaction, there is no great documentation I'm aware of. The closest thing is probably looking at the official Sia Ledger support article. It covers the basic structure of building a transaction towards the bottom.

https://support.sia.tech/article/1tteqxvgh0-sia-ledger https://gitlab.com/NebulousLabs/nanos-app-sia/-/blob/master/sialedger.go

Another good place is Luke's Walrus server and Walrus-CLI. It's similar, but takes a different approach to how keys are managed.

https://github.com/lukechampine/walrus https://github.com/lukechampine/walrus-cli