photon-sdk / photon-lib

A high level library for building bitcoin wallets with react native
https://docs.photonsdk.org
MIT License
53 stars 12 forks source link

Question: nodejs compatibility? #19

Open Overtorment opened 3 years ago

Overtorment commented 3 years ago

I haven't tested this personally, but can this lib be consumed in nodejs/typescript?

tanx commented 3 years ago

Re node: well the unit/integration tests for the client library run under node with mocked react native modules. And the keyserver runs on node via AWS lambda functions.

Re typescript... I'm not very familiar with it myself. But are there any special requirements to consume regular ES6 modules?

Overtorment commented 3 years ago

no, if it runs under nodejs then it will most likely run under ts.

but is there a way to just throw in this lib as a dependency in nodejs project with minimal efforts (like, mocking RN modules)?

tanx commented 3 years ago

Are you thinking of backing up the LNDhub private key? If you already have a keystore solution you really only need the keybackup module. The only dependencies there are Frisbee (which runs under node anyway) and cloudstore which would need to be mocked with a cloud backend of your choice. There is a PR for the Gdrive REST api in the works. But hard to guess what the best solution is without better understanding your use case.

Overtorment commented 3 years ago

no I was thinking about, for example, starting new backend project and having all classes available to import mnemonics and create transactions. no relation to Lndhub

tanx commented 3 years ago

Ok cool. Well let me know if I can support you in anyway. Photon has profited immensely from your great work at BlueWallet. So whatever I can do to repay the favor :)

Overtorment commented 3 years ago

thanks! :-) so long story short, I wanted bluewallet code to be isomorphic, to reuse it on servers and in browsers, but BW grown too complex. one day I tried to setup nodejs project and add BW as a dependency just to reuse some classes without copy-paste, and failed miserably. so that would be really nice to have a project (like photon-lib) that can only be used as a dependency, and instantly provide some of bluewallet's classes to either nodejs, browser tab, react-native, or whatever (think javascript on microcontrollers).

Overtorment commented 3 years ago

bitcoinjs-lib already works everywhere, but its a bit too low-level

tanx commented 3 years ago

so long story short, I wanted bluewallet code to be isomorphic, to reuse it on servers and in browsers, but BW grown too complex.

That makes sense. I got the sense that's why you created the blue_modules folder?

so that would be really nice to have a project (like photon-lib) that can only be used as a dependency, and instantly provide some of bluewallet's classes to either nodejs, browser tab, react-native, or whatever (think javascript on microcontrollers).

Totally! That was precisely the idea behind the photon-lib. I think there would be tremendous value in consolidating library code between photon-lib and bluewallet. That way both projects share the maintenance cost and profit from security reviews, etc.

If that is valuable for you, I'm happy to share org access to photon-sdk with BlueWallet and we could start with consolidating the wallet modules, which both projects use?

Overtorment commented 3 years ago

the idea behind blue_modules was that sometimes pieces of code work better as OOP (with all that incapsulation and inheritance stuff), and sometimes code is organized well enough with plain modules. also, some external dependencies can be moved outside of node_modules into blue_modules to better keep an eye on them.

consolidating library code is not something I would do immediately for BW, but there is certainly value in making it work seamlessly on nodejs/rn/browser, this way next time I'll start a side project I won't have to copy-paste a bunch of code from BW.