Skip to content

Commit

Permalink
Merge pull request #52 from ZeusLN/master
Browse files Browse the repository at this point in the history
v0.0.6
  • Loading branch information
ZeusLN authored Mar 6, 2019
2 parents 31cce2e + 7245238 commit e6a70ed
Show file tree
Hide file tree
Showing 16 changed files with 220 additions and 163 deletions.
48 changes: 12 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,64 +18,40 @@ Zeus is built on TypeScript and React-Native. It runs on both iOS and Android.

## Connecting to your node

Currently, to use Zeus, you must have a Bitcoin Lightning node running
Currently, to use Zeus, you must have a Bitcoin Lightning node running
[Lightning Network Daemon (lnd)](https://github.com/LightningNetwork/lnd).

You must provide Zeus with your node's hostname, port number, and the lnd macaroon you choose to use in **hex format**. If you need help converting your macaroon to hex format we wrote up a Node.js script that can use
You must provide Zeus with your node's hostname, port number, and the lnd macaroon you choose to use in **hex format**. If you need help converting your macaroon to hex format we wrote up a Node.js script that can use
[here](https://github.com/ZeusLN/lnd-hex-macaroon-generator/).

If you would like to learn more about running your own guide we suggest checking out the following guides:
* If you're looking to run a full node on existing hardware running Windows or macOS, check out Pierre Rochard's
[Lightning Power Node Launcher](https://github.com/PierreRochard/node-launcher).
We recommend reading
* If you're looking to run a full node on existing hardware running Windows or macOS, check out Pierre Rochard's
[Lightning Power Node Launcher](https://github.com/PierreRochard/node-launcher).
We recommend reading
[this guide](https://medium.com/lightning-power-users/windows-macos-lightning-network-284bd5034340).
* If you're looking to run a full node on a dedicated piece of hardware like a Raspberry Pi, check out Stadicus'
* If you're looking to run a full node on a dedicated piece of hardware like a Raspberry Pi, check out Stadicus'
[Raspibolt Tutorial](https://github.com/Stadicus/guides/tree/master/raspibolt).

### Using a self-signed lnd cert with iOS

If you are using a self-signed lnd cert (as is the default in lnd), you must create a provisioning profile for your device or simulator in able to connect to your node.

Check out
[this guide](https://www.howtogeek.com/253325/how-to-create-an-ios-configuration-profile-and-alter-hidden-settings/)
for setting up a configuration profile. You want to add your LND cert to the section marked `Certificates` before associating the profile to your device.

## Building Zeus from source

**Don't trust, verify** the code with your own two eyes. Then when ready proceed to the steps below based on your platform.

### Android
1. install and setup react-native and its related dependencies under **"Building Projects with Native Code"** on
[react-native's Getting Started page](https://facebook.github.io/react-native/docs/getting-started.html)
[react-native's Getting Started page](https://facebook.github.io/react-native/docs/getting-started.html)
2. if using your phone,
[enable Developer mode and USB Debugging](https://developer.android.com/studio/debug/dev-options)
, then make sure it is connected to your computer by running `adb devices`
3. install node dependencies with `npm i`
4. open up your Android simulator or connect your phone and run `react-native run-android`

### iOS
1. if using a self-signed lnd cert with iOS, please read the section above titled
[Using a self-signed lnd cert with iOS](#using-a-self-signed-lnd-cert-with-ios)
2. install and setup react-native and its related dependencies under **"Building Projects with Native Code"** on
[react-native's Getting Started page](https://facebook.github.io/react-native/docs/getting-started.html)
3. install node dependencies with `npm i`
1. install and setup react-native and its related dependencies under **"Building Projects with Native Code"** on
[react-native's Getting Started page](https://facebook.github.io/react-native/docs/getting-started.html)
2. install node dependencies with `npm i`
3. apply patches with `npm run patch`
4. open `ios/zeus.xcodeproj` in Xcode and hit Run

#### Using a local lnd node with iOS

If you are running lnd on the same machine you're running your iOS simulator (for example, if you're using the Lightning Power Node Launcher mentioned above) you will have to use the following workaround.

Insert the following snippet right below the line `#pragma mark - NSURLSession delegate` in the file `node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm`.

```objectivec++
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler
{
completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
}
```

Do not use this workaround in production.

## Contributing

Please be sure to run `tsc` to check for type errors and `npm run test` to run all tests.
Expand All @@ -84,7 +60,7 @@ If you are making cosmetic changes please test on both Android and iOS as things

## Donations

If you'd like to help us with the cost of running Zeus project (iOS developer account, Google Play developer account, hosting) you can send a payment to
If you'd like to help us with the cost of running Zeus project (iOS developer account, Google Play developer account, hosting) you can send a payment to
[3Lbz4vdt15Fsa4wVD3Yk8uGf6ugKKY4zSc](https://blockstream.info/address/3Lbz4vdt15Fsa4wVD3Yk8uGf6ugKKY4zSc).

Thank you.
Expand Down
4 changes: 2 additions & 2 deletions ios/zeus.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = com.zeusln.zeus;
PRODUCT_NAME = zeus;
VERSIONING_SYSTEM = "apple-generic";
};
Expand Down Expand Up @@ -1689,7 +1689,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = com.zeusln.zeus;
PRODUCT_NAME = zeus;
VERSIONING_SYSTEM = "apple-generic";
};
Expand Down
12 changes: 6 additions & 6 deletions ios/zeus/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>0.0.6</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand All @@ -32,21 +32,23 @@
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPSLoads</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPSLoads</key>
<false/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>1.0</string>
<key>NSTemporaryExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
<key>NSCameraUsageDescription</key>
<string>Zeus Wallet would like permission to use your camera to scan QR codes</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string/>
<string></string>
<key>UIAppFonts</key>
<array>
<string>AntDesign.ttf</string>
Expand Down Expand Up @@ -79,7 +81,5 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSCameraUsageDescription</key>
<string>Zeus Wallet would like permission to use your camera to scan QR codes</string>
</dict>
</plist>
13 changes: 12 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"name": "zeus",
"version": "0.0.5",
"version": "0.0.6",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"patch": "git apply patches/RCTHTTPRequestHandler.mm.patch",
"test": "jest",
"tsc": "tsc"
},
"dependencies": {
"axios": "0.18.0",
"base-64": "0.1.0",
"identicon.js": "2.3.3",
"lodash": "4.17.11",
"mobx": "4.9.1",
Expand All @@ -28,6 +30,7 @@
},
"devDependencies": {
"@babel/plugin-proposal-decorators": "7.3.0",
"@types/base-64": "0.1.3",
"@types/jest": "23.3.13",
"@types/lodash": "4.14.120",
"@types/react": "16.7.22",
Expand All @@ -42,7 +45,7 @@
"jest": "24.0.0",
"metro-react-native-babel-preset": "0.51.1",
"react-test-renderer": "16.6.3",
"ts-jest": "^23.10.5",
"ts-jest": "23.10.5",
"typescript": "3.2.4"
},
"jest": {
Expand Down
16 changes: 16 additions & 0 deletions patches/RCTHTTPRequestHandler.mm.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--- a/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
+++ b/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
@@ -93,6 +93,10 @@ RCT_EXPORT_MODULE()
}

#pragma mark - NSURLSession delegate
+- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler
+{
+ completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
+}

- (void)URLSession:(NSURLSession *)session
task:(NSURLSessionTask *)task
--
2.20.1

5 changes: 5 additions & 0 deletions stores/InvoicesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export default class InvoicesStore {
this.settingsStore = settingsStore;
}

@action
public resetPaymentReq = () => {
this.payment_request = '';
}

@action
public getInvoices = () => {
const { settings } = this.settingsStore;
Expand Down
5 changes: 4 additions & 1 deletion stores/UnitsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default class UnitsStore {
this.units = this.units == 'sats' ? 'btc' : 'sats';
}

numberWithCommas = (x: string | number) => x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

@action
public getAmount = (value: string | number) => {
if (this.units === 'btc') {
Expand All @@ -31,6 +33,7 @@ export default class UnitsStore {
return `₿ ${Number(value || 0) / satoshisPerBTC}`;
}

return `${value || 0} ${Number(value) > 1 ? 'sats' : 'sat'}`;
const sats = `${value || 0} ${(Number(value) === 1 || Number(value) === -1) ? 'sat' : 'sats'}`;
return this.numberWithCommas(sats);
}
}
38 changes: 30 additions & 8 deletions utils/MacaroonUtils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
import { decode as atob } from 'base-64';

class MacaroonUtils {
asciiToHex = (input: string) => {
const arr1: Array<string> = [];
for (let n = 0, l = input.length; n < l; n++) {
const hex: string = Number(input.charCodeAt(n)).toString(16);
arr1.push(hex);
}
return arr1.join('');
};
base64UrlToHex = (input: string) => {
const raw = atob(this.base64UrlToBase64(input));
let HEX = '';

for (let i = 0; i < raw.length; i++) {
const hexChar = raw.charCodeAt(i).toString(16);
HEX += (hexChar.length === 2 ? hexChar : '0' + hexChar);
}
return HEX.toUpperCase();
}

base64UrlToBase64 = (input: string) => {
// Replace non-url compatible chars with base64 standard chars
input = input
.replace(/-/g, '+')
.replace(/_/g, '/');

// Pad out with standard base64 required padding characters
const pad = input.length % 4;
if (pad) {
if (pad === 1) {
throw new Error('InvalidLengthError: Input base64url string is the wrong length to determine padding');
}
input += new Array(5-pad).join('=');
}

return input;
}
};

const macaroonUtils = new MacaroonUtils();
Expand Down
10 changes: 7 additions & 3 deletions views/LNDConnectConfigQRScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ export default class LNDConnectConfigQRScanner extends React.Component<LNDConnec
handleLNDConnectConfigInvoiceScanned = ({ data }: any) => {
const { navigation } = this.props;

const host = data.split('lndconnect://')[1].split(':')[0];
const port = data.split('lndconnect://')[1].split(':')[1].split('?')[0];
const macaroonHex = data.split('&macaroon=')[1] && MacaroonUtils.asciiToHex(data.split('&macaroon=')[1]);
const host = data.split('lndconnect://')[1] &&
data.split('lndconnect://')[1].split(':')[0];
const port = data.split('lndconnect://')[1] &&
data.split('lndconnect://')[1].split(':')[1] &&
data.split('lndconnect://')[1].split(':')[1].split('?')[0];
const macaroonHex = data.split('&macaroon=')[1] && MacaroonUtils.base64UrlToHex(data.split('&macaroon=')[1]);


if (host && port && macaroonHex) {
navigation.navigate('Settings', { host, port, macaroonHex });
Expand Down
14 changes: 13 additions & 1 deletion views/OpenChannel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface OpenChannelState {
node_pubkey_string: string;
local_funding_amount: string;
min_confs: number;
sat_per_byte: string;
private: boolean;
host: string;
}
Expand All @@ -25,6 +26,7 @@ export default class OpenChannel extends React.Component<OpenChannelProps, OpenC
node_pubkey_string: '',
local_funding_amount: '',
min_confs: 1,
sat_per_byte: '2',
private: false,
host: ''
}
Expand All @@ -42,7 +44,7 @@ export default class OpenChannel extends React.Component<OpenChannelProps, OpenC

render() {
const { ChannelsStore, navigation } = this.props;
const { node_pubkey_string, local_funding_amount, min_confs, host } = this.state;
const { node_pubkey_string, local_funding_amount, min_confs, host, sat_per_byte } = this.state;
const privateChannel = this.state.private;

const { connectingToPeer, openingChannel, connectPeer, errorMsgChannel, errorMsgPeer, peerSuccess, channelSuccess } = ChannelsStore;
Expand Down Expand Up @@ -110,6 +112,16 @@ export default class OpenChannel extends React.Component<OpenChannelProps, OpenC
editable={!openingChannel}
/>

<FormLabel>Satoshis per byte</FormLabel>
<TextInput
placeholder={'2'}
value={sat_per_byte}
onChangeText={(text: string) => this.setState({ sat_per_byte: text })}
numberOfLines={1}
style={{ fontSize: 20, marginBottom: 10 }}
editable={!openingChannel}
/>

<CheckBox
title="Private"
checked={privateChannel}
Expand Down
Loading

0 comments on commit e6a70ed

Please sign in to comment.