edge-core-js 0.18.11 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +32 -15
  3. package/android/build.gradle +52 -0
  4. package/android/src/main/AndroidManifest.xml +3 -0
  5. package/android/src/main/assets/edge-core-js/edge-core.js +2 -0
  6. package/{lib/react-native → android/src/main/assets/edge-core-js}/edge-core.js.LICENSE.txt +0 -0
  7. package/android/src/main/cpp/CMakeLists.txt +16 -0
  8. package/android/src/main/cpp/edge-core-jni.c +36 -0
  9. package/android/src/main/cpp/scrypt/crypto_scrypt.c +284 -0
  10. package/android/src/main/cpp/scrypt/crypto_scrypt.h +46 -0
  11. package/android/src/main/cpp/scrypt/readme.md +13 -0
  12. package/android/src/main/cpp/scrypt/sha256.c +412 -0
  13. package/android/src/main/cpp/scrypt/sha256.h +62 -0
  14. package/android/src/main/cpp/scrypt/sysendian.h +140 -0
  15. package/android/src/main/java/app/edge/reactnative/core/Disklet.java +98 -0
  16. package/android/src/main/java/app/edge/reactnative/core/EdgeCorePackage.java +23 -0
  17. package/android/src/main/java/app/edge/reactnative/core/EdgeCoreWebView.java +209 -0
  18. package/android/src/main/java/app/edge/reactnative/core/EdgeCoreWebViewManager.java +53 -0
  19. package/edge-core-js.podspec +36 -0
  20. package/ios/Disklet.swift +75 -0
  21. package/ios/EdgeCoreWebView.swift +236 -0
  22. package/ios/EdgeCoreWebViewManager.m +8 -0
  23. package/ios/EdgeCoreWebViewManager.swift +15 -0
  24. package/ios/edge-core-js-Bridging-Header.h +4 -0
  25. package/ios/edge-core-js.xcodeproj/project.pbxproj +0 -0
  26. package/lib/core/account/account-api.js +3 -3
  27. package/lib/core/account/account-files.js +8 -4
  28. package/lib/core/account/account-init.js +4 -0
  29. package/lib/core/context/context-api.js +1 -1
  30. package/lib/core/currency/currency-selectors.js +2 -3
  31. package/lib/core/currency/wallet/currency-wallet-api.js +25 -13
  32. package/lib/core/currency/wallet/currency-wallet-callbacks.js +1 -1
  33. package/lib/core/currency/wallet/currency-wallet-export.js +2 -5
  34. package/lib/core/currency/wallet/currency-wallet-files.js +1 -1
  35. package/lib/core/currency/wallet/currency-wallet-pixie.js +1 -0
  36. package/lib/core/exchange/exchange-selectors.js +1 -0
  37. package/lib/core/fake/fake-db.js +15 -1
  38. package/lib/core/fake/fake-responses.js +16 -10
  39. package/lib/core/fake/fake-server.js +408 -334
  40. package/lib/core/fake/fake-world.js +3 -6
  41. package/lib/core/login/create.js +1 -2
  42. package/lib/core/login/edge.js +3 -1
  43. package/lib/core/login/keys.js +11 -13
  44. package/lib/core/login/login.js +37 -14
  45. package/lib/core/login/password.js +1 -1
  46. package/lib/core/login/pin2.js +8 -12
  47. package/lib/core/login/recovery2.js +4 -4
  48. package/lib/core/login/vouchers.js +1 -2
  49. package/lib/core/root.js +14 -22
  50. package/lib/core/storage/repo.js +12 -13
  51. package/lib/core/storage/storage-actions.js +1 -1
  52. package/lib/core/storage/storage-reducer.js +1 -1
  53. package/lib/exports.d.ts +38 -33
  54. package/lib/fake-types.d.ts +24 -0
  55. package/lib/io/react-native/native-bridge.js +85 -0
  56. package/lib/io/react-native/polyfills.js +2 -2
  57. package/lib/io/react-native/react-native-types.js +16 -0
  58. package/lib/io/react-native/react-native-webview.js +81 -121
  59. package/lib/io/react-native/react-native-worker.js +134 -56
  60. package/lib/io/react-native/yaob-callbacks.js +106 -0
  61. package/lib/node/index.js +637 -504
  62. package/lib/react-native.js +22 -40
  63. package/lib/types/exports.js +59 -33
  64. package/lib/types/exports.ts +53 -27
  65. package/lib/types/fake-types.js +40 -2
  66. package/lib/types/fake-types.ts +39 -1
  67. package/lib/types/types.js +34 -0
  68. package/lib/types/types.ts +189 -134
  69. package/lib/types.d.ts +146 -132
  70. package/package.json +15 -7
  71. package/src/types/exports.js +66 -40
  72. package/src/types/fake-types.js +40 -2
  73. package/src/types/types.js +189 -155
  74. package/lib/io/react-native/react-native-io.js +0 -87
  75. package/lib/react-native/edge-core.js +0 -3
  76. package/lib/react-native/edge-core.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # edge-core-js
2
2
 
3
+ ## v0.19.0 (2022-01-11)
4
+
5
+ This release completely changes the way React Native works, both to improve performance and to make integration and debugging much easier.
6
+
7
+ - changed: Simplify the React Native integration to "just work".
8
+ - Stop depending on external libraries such as react-native-fast-crypto, react-native-randombytes, or react-native-webview.
9
+ - Use React Native auto-linking to integrate all native code, HTML, and Javascript needed to run the core.
10
+ - Accept core plugins via a `pluginUris` prop to `MakeEdgeContext` or `MakeFakeEdgeWorld`.
11
+ - Allow core debugging by running `yarn start` in this repo to start a dev server, and then setting the `debug` prop to true.
12
+ - Accept an `allowDebugging` prop on Android to enable WebView debugging in general (useful for debugging plugins).
13
+ - changed: Require `EdgeCurrencyEngine` methods to return promises.
14
+ - changed: Mark methods as `readonly` in the TypeScript definitions, to match what Flow was already doing.
15
+
16
+ ## v0.18.14 (2021-01-06)
17
+
18
+ - fixed: Allow logins with an appId to approve or reject vouchers.
19
+ - added: Allow maximum swaps by passing "max" to `EdgeSwapRequest.quoteFor`.
20
+ - added: Add an `EdgeCurrencyEngine.getMaxSpendable` method for native max-spend calculations.
21
+
22
+ ## v0.18.13 (2021-12-17)
23
+
24
+ - added: `EdgeSpendTarget.memo`, which is a renamed version of `EdgeSpendTarget.uniqueIdentifier`.
25
+ - added: `EdgeCurrencyInfo.memoType`, `EdgeCurrencyInfo.memoMaxLength`, `EdgeCurrencyInfo.memoMaxValue`. Use these to learn which currencies support memos.
26
+ - added: `EdgeCurrencyTools.validateMemo` & `EdgeCurrencyWallet.validateMemo`. Use these to check memos for validity before sending.
27
+ - deprecated: `EdgeSpendTarget.uniqueIdentifier`. Use `EdgeSpendTarget.memo` instead.
28
+
29
+ ## v0.18.12 (2021-12-10)
30
+
31
+ - fixed: Gracefully handle errors while reading the exchange-rate hint cache.
32
+ - fixed: Correctly match server-returned children with their on-disk stash entries. This produces more accurate errors if the server loses a child.
33
+
3
34
  ## v0.18.11 (2021-11-07)
4
35
 
5
36
  - fixed: onWcNewContractCall callback type
package/README.md CHANGED
@@ -16,7 +16,9 @@ To quickly get up and running with the UI for account creation, login, and manag
16
16
 
17
17
  ## Setup
18
18
 
19
- Just use `npm install --save edge-core-js` to add this library to your project.
19
+ Add this library to your project using `npm install --save edge-core-js`.
20
+
21
+ ### Node.js & Browsers
20
22
 
21
23
  To create an `EdgeContext` object, which provides various methods for logging in and creating account, do something like this:
22
24
 
@@ -45,32 +47,47 @@ addEdgeCorePlugins(currencyPlugins)
45
47
  lockEdgeCorePlugins()
46
48
  ```
47
49
 
48
- The above code sample works for Node.js. For the browser and React Native, plugins load using a `<script>` tag. The `lockEdgeCorePlugins` is necessary on all platforms, and must happen before login can proceed.
50
+ If the core seems to hang forever when logging in, you probably forgot to call `lockEdgeCorePlugins`.
51
+
52
+ Please note that edge-core-js uses modern JavaScript syntax features such as `async`, so you may need to run the library through [Babel](https://babeljs.io/) if you plan to run it in a browser. Node 10+ supports these features natively.
49
53
 
50
54
  ### React Native
51
55
 
52
- This library has React Native support. Starting at version 0.15.0, however, it achieves this support by running most of its logic inside a WebView component. This has several important advantages, including better performance, but it makes integration quite complicated. We are in the process of simplifying and documenting the necessary steps. In the mean time, please refer to the [edge-react-gui](https://github.com/EdgeApp/edge-react-gui) project for an example of what this integration looks like.
56
+ Edge-core-js directly supports React Native v0.60+ with autolinking. Simply add edge-core-js to your application, and React Native will link the necessary native modules & assets.
53
57
 
54
- ### Platform Requirements
58
+ To create an `EdgeContext` object, you need to mount a component:
55
59
 
56
- This library uses modern Javascript syntax features from ES 2018. While these work fine in recent browsers, React Native, and Node 10+, you might need to run this library through [Babel](https://babeljs.io/) if you care about older systems.
60
+ ```jsx
61
+ <MakeEdgeContext
62
+ // Get this from our support team:
63
+ apiKey="..."
64
+ appId="com.your-app"
57
65
 
58
- On the other hand, this library avoids modern run-time features from ES 2015 or later, so you don't need to provide polyfills. The only features we use from ES 2015 or later are:
66
+ // Configure currencies and swap providers you want to use:
67
+ plugins={{
68
+ 'bitcoin': true
69
+ }}
70
+ pluginUris={[
71
+ "edge-currency-plugins.js",
72
+ "edge-exchange-plugins.js"
73
+ ]}
74
+
75
+ // Called when the core is done loading:
76
+ onLoad={edgeContext => {}}
77
+ onError={error => {}}
78
+ />
79
+ ```
59
80
 
60
- - `Object.assign`
61
- - `Promise`
62
- - `Uint8Array`
81
+ The core itself runs inside a hidden WebView, which this `MakeEdgeContext` component mounts & manages.
63
82
 
64
- If you want to run in the browser, you must also have:
83
+ The core creates a `<script>` tag for each source file in the `pluginUris` array. For this to work, you need to add these plugin files to your app's native asset bundle, which is located at `/android/app/src/main/assets/` on Android. For iOS, drag these files into the "Resources" section of your Xcode project.
65
84
 
66
- - `fetch`
67
- - `localStorage`
68
- - `Window.crypto.getRandomNumbers`
85
+ To debug the core, run `yarn start` inside the edge-core-js project, and then pass a `debug={true}` property to the `MakeEdgeContext` component. This tells the WebView to load the core from a local development server.
69
86
 
70
87
  ## Contributing
71
88
 
72
- Run `yarn` to download dependencies and build the library, then run `yarn test` to run the unit tests, and `yarn flow` to check for type errors.
89
+ Run `yarn` to download dependencies, and then run `yarn prepare` to build the library.
73
90
 
74
- All sources are in the [JavaScript Standard Style](http://standardjs.com/) + [Prettier](https://prettier.io/). We check files prior to each commit, so if you have formatting issues, you can run `yarn fix` to fix them automatically.
91
+ Use `yarn verify` to run all our code-quality tools. All sources are in the [JavaScript Standard Style](http://standardjs.com/) + [Prettier](https://prettier.io/). We check files prior to each commit, so if you have formatting issues, you can run `yarn fix` to fix them automatically.
75
92
 
76
93
  If you use Visual Studio Code, consider installing the [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) extension. This will give you nice error highlighting as you work, along with quick fixes for formatting issues.
@@ -0,0 +1,52 @@
1
+ buildscript {
2
+ repositories {
3
+ google()
4
+ jcenter()
5
+ }
6
+
7
+ dependencies {
8
+ classpath 'com.android.tools.build:gradle:3.6.0'
9
+ }
10
+ }
11
+
12
+ apply plugin: 'com.android.library'
13
+
14
+ def safeExtGet(prop, fallback) {
15
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
16
+ }
17
+
18
+ def DEFAULT_COMPILE_SDK_VERSION = 28
19
+ def DEFAULT_BUILD_TOOLS_VERSION = '28.0.2'
20
+ def DEFAULT_MIN_SDK_VERSION = 19
21
+ def DEFAULT_TARGET_SDK_VERSION = 27
22
+ def DEFAULT_WEBKIT_VERSION = '1.4.0'
23
+
24
+ android {
25
+ compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
26
+ buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
27
+
28
+ defaultConfig {
29
+ minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
30
+ targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
31
+ versionCode 1
32
+ versionName '1.0'
33
+ }
34
+ lintOptions {
35
+ abortOnError false
36
+ }
37
+ externalNativeBuild {
38
+ cmake {
39
+ path "src/main/cpp/CMakeLists.txt"
40
+ }
41
+ }
42
+ }
43
+
44
+ repositories {
45
+ }
46
+
47
+ def webkit_version = safeExtGet('webkitVersion', DEFAULT_WEBKIT_VERSION)
48
+
49
+ dependencies {
50
+ implementation "androidx.webkit:webkit:$webkit_version"
51
+ implementation 'com.facebook.react:react-native:+'
52
+ }
@@ -0,0 +1,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="app.edge.reactnative.core">
3
+ </manifest>