Tor build and cashu-ts request injection POC

This commit is contained in:
minibits-cash
2023-10-09 22:29:01 +02:00
parent 022048f537
commit dce1959a12
8 changed files with 6368 additions and 31 deletions
+1
View File
@@ -179,6 +179,7 @@ dependencies {
implementation("com.facebook.react:react-android")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
implementation files("../../node_modules/react-native-tor/android/libs/sifir_android.aar") // react-native-tor
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
+3 -2
View File
@@ -3,13 +3,14 @@
buildscript {
ext {
buildToolsVersion = "33.0.0"
minSdkVersion = 23
minSdkVersion = 26 // react-native-tor // 23
compileSdkVersion = 33
targetSdkVersion = 33
// We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
ndkVersion = "23.1.7779620"
kotlin_version = "1.7.21" // minibits_wallet:react-native-camera-kit
kotlin_version = "1.9.0" // minibits_wallet:react-native-camera-kit // 1.7.21
kotlinVersion = "1.8.0"
}
repositories {
google()
+2 -1
View File
@@ -15,7 +15,7 @@
"postinstall": "patch-package"
},
"dependencies": {
"@cashu/cashu-ts": "^0.8.0-rc.6",
"@cashu/cashu-ts": "minibits-cash/cashu-ts#custom-request",
"@fortawesome/fontawesome-svg-core": "^6.4.0",
"@fortawesome/free-regular-svg-icons": "^6.4.0",
"@fortawesome/free-solid-svg-icons": "^6.4.0",
@@ -63,6 +63,7 @@
"react-native-screens": "^3.20.0",
"react-native-svg": "^13.9.0",
"react-native-tab-view": "^3.5.2",
"react-native-tor": "^0.1.8",
"react-native-url-polyfill": "^1.3.0",
"text-encoding-polyfill": "^0.6.7"
},
File diff suppressed because one or more lines are too long
+10
View File
@@ -0,0 +1,10 @@
diff --git a/node_modules/react-native-tor/android/gradle.properties b/node_modules/react-native-tor/android/gradle.properties
index c47c23d..1fe7399 100644
--- a/node_modules/react-native-tor/android/gradle.properties
+++ b/node_modules/react-native-tor/android/gradle.properties
@@ -1,4 +1,4 @@
-Tor_kotlinVersion=1.3.50
+Tor_kotlinVersion=1.6.20
Tor_compileSdkVersion=30
Tor_buildToolsVersion=30.0.1
Tor_targetSdkVersion=30
+17 -7
View File
@@ -5,6 +5,7 @@ import {
PayLnInvoiceResponse,
type Proof as CashuProof,
} from '@cashu/cashu-ts'
import torRequest from './tor/torRequest'
import {CashuUtils} from './cashu/cashuUtils'
import AppError, {Err} from '../utils/AppError'
import {log} from '../utils/logger'
@@ -18,14 +19,22 @@ let _mints: {[mintUrl: string]: CashuMint} = {}
let _wallets: {[mintUrl: string]: CashuWallet} = {}
const getMint = function (mintUrl: string) {
if (_mints[mintUrl]) {
return _mints[mintUrl]
}
if (_mints[mintUrl]) {
return _mints[mintUrl]
}
const mint = new CashuMint(mintUrl)
_mints[mintUrl] = mint
if(mintUrl.includes('.onion')) {
log.trace('Creating mint instance with .onion mintUrl', {mintUrl}, 'getMint')
const mint = new CashuMint(mintUrl, torRequest)
_mints[mintUrl] = mint
return mint
return mint
}
const mint = new CashuMint(mintUrl)
_mints[mintUrl] = mint
return mint
}
const getWallet = function (mintUrl: string) {
@@ -47,11 +56,12 @@ const getMintKeys = async function (mintUrl: string) {
try {
// keysets = await mint.getKeySets()
log.trace('Sending getKeys request', {mintUrl}, 'getMintKeys')
keys = await mint.getKeys()
} catch (e: any) {
throw new AppError(
Err.CONNECTION_ERROR,
`Could not connect to the selected mint.}`,
`Could not connect to the selected mint.`,
[e.message, mintUrl],
)
}
+91
View File
@@ -0,0 +1,91 @@
import Tor, { RequestMethod } from 'react-native-tor'
import AppError, { Err } from '../../utils/AppError';
import { log } from '../../utils/logger';
log.trace('Creating tor instance')
const tor = Tor()
type RequestArgs = {
endpoint: string;
requestBody?: Record<string, unknown>;
headers?: Record<string, string>;
method?: RequestMethod,
};
type RequestOptions = RequestArgs & Omit<RequestInit, 'body' | 'headers'>;
let globalRequestOptions: Partial<RequestOptions> = {};
export function setGlobalRequestOptions(options: Partial<RequestOptions>): void {
globalRequestOptions = options;
}
async function _request<T>({
endpoint,
requestBody,
headers: requestHeaders,
method: requestMethod,
...options
}: RequestOptions): Promise<T> {
log.trace('Starting tor if not yer running')
await tor.startIfNotStarted()
const body = requestBody ? JSON.stringify(requestBody) : undefined;
const method = requestMethod ? requestMethod : RequestMethod.GET
const headers = {
...{ Accept: 'application/json, text/plain' },
...(body ? { 'Content-Type': 'application/json' } : undefined),
...requestHeaders
};
switch (method.toLowerCase()) {
case RequestMethod.GET:
log.trace('GET tor request', {endpoint})
const getResult = await tor.get(endpoint, headers, true);
if (getResult.json) {
log.trace('GET tor response', {response: getResult.json})
return getResult.json;
}
break;
case RequestMethod.POST:
log.trace('POST tor request', {endpoint})
const postResult = await tor.post(
endpoint,
body || '',
headers,
true
);
if (postResult.json) {
log.trace('POST tor response', {response: postResult.json})
return postResult.json;
}
break;
case RequestMethod.DELETE:
const deleteResult = await tor.delete(endpoint, body, headers, true);
if (deleteResult.json) {
return deleteResult.json;
}
break;
}
throw new AppError(Err.VALIDATION_ERROR, 'Invalid method', {method})
}
export default async function torRequest<T>(options: RequestOptions): Promise<T> {
const response = await _request({ ...options, ...globalRequestOptions });
checkResponse(response);
return response as T;
}
function checkResponse(data: any) {
if (!isObj(data)) {
throw new AppError(Err.VALIDATION_ERROR, 'Invalid data', {data})
};
}
function isObj(v: unknown): v is object {
return typeof v === 'object';
}
+30 -21
View File
@@ -1175,14 +1175,12 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@cashu/cashu-ts@^0.8.0-rc.6":
version "0.8.0-rc.6"
resolved "https://registry.yarnpkg.com/@cashu/cashu-ts/-/cashu-ts-0.8.0-rc.6.tgz#c2f91e56d723b16aeee5cf4c775d12fba963bac5"
integrity sha512-gW6BhafKMy7AwH3D+u04CDPc2dIrnR+EFWZqg7KjlSs8bmofeAzGVFb6FGAXvTUjC77vSkrdBfmNYdSwVAn9oQ==
"@cashu/cashu-ts@minibits-cash/cashu-ts#custom-request":
version "0.8.2-rc.6"
resolved "https://codeload.github.com/minibits-cash/cashu-ts/tar.gz/3277659cb1722778a630ed2c8018113f888ee637"
dependencies:
"@gandlaf21/bolt11-decode" "^3.0.6"
"@noble/curves" "^1.0.0"
axios "^1.4.0"
buffer "^6.0.3"
"@craftzdog/react-native-buffer@^6.0.5":
@@ -1605,18 +1603,30 @@
resolved "https://registry.yarnpkg.com/@nicolo-ribaudo/semver-v6/-/semver-v6-6.3.3.tgz#ea6d23ade78a325f7a52750aab1526b02b628c29"
integrity sha512-3Yc1fUTs69MG/uZbJlLSI3JISMn2UV2rg+1D/vROUqZyh3l6iYHCs7GMp+M40ZD7yOdDbYjJcU1oTJhrc+dGKg==
"@noble/curves@1.1.0", "@noble/curves@^1.0.0", "@noble/curves@~1.1.0":
"@noble/curves@1.1.0", "@noble/curves@~1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.1.0.tgz#f13fc667c89184bc04cccb9b11e8e7bae27d8c3d"
integrity sha512-091oBExgENk/kGj3AZmtBDMpxQPDtxQABR2B9lb1JbVTs6ytdzZNwvhxQ4MWasRNEzlbEH8jCWFCwhF/Obj5AA==
dependencies:
"@noble/hashes" "1.3.1"
"@noble/curves@^1.0.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35"
integrity sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==
dependencies:
"@noble/hashes" "1.3.2"
"@noble/hashes@1.3.1", "@noble/hashes@~1.3.0", "@noble/hashes@~1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.1.tgz#8831ef002114670c603c458ab8b11328406953a9"
integrity sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==
"@noble/hashes@1.3.2":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39"
integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==
"@nodelib/fs.scandir@2.1.5":
version "2.1.5"
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5"
@@ -2136,6 +2146,11 @@
resolved "https://registry.yarnpkg.com/@types/aes-js/-/aes-js-3.1.2.tgz#9bd9fa645dadbcd8f0c9f774c33d8a778f1a7a31"
integrity sha512-bKms4q1H3YCcLMKvqE9kUefE1TXc9/QhurzMRVqY9Qevodl0Fxyt6GQcUQ4TkmuWLdGQM1xL+yhSUBTJJRfBFA==
"@types/async@^3.2.6":
version "3.2.21"
resolved "https://registry.yarnpkg.com/@types/async/-/async-3.2.21.tgz#470b06c25fc104c169e80a9c91866e8204e91175"
integrity sha512-msYM0OYxzkwpiDJZZDo7XsYuFIpiAOh+o3hygudSpSzeW+R0DAEKZvdQriHYT95m9CvscLDg5s0Mxlrlhoy2qw==
"@types/babel__core@^7.1.14":
version "7.20.1"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.20.1.tgz#916ecea274b0c776fec721e333e55762d3a9614b"
@@ -2636,7 +2651,7 @@ async-limiter@~1.0.0:
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd"
integrity sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==
async@^3.2.2:
async@^3.2.0, async@^3.2.2:
version "3.2.4"
resolved "https://registry.yarnpkg.com/async/-/async-3.2.4.tgz#2d22e00f8cddeb5fde5dd33522b56d1cf569a81c"
integrity sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==
@@ -2656,15 +2671,6 @@ available-typed-arrays@^1.0.5:
resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7"
integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==
axios@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.4.0.tgz#38a7bf1224cd308de271146038b551d725f0be1f"
integrity sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==
dependencies:
follow-redirects "^1.15.0"
form-data "^4.0.0"
proxy-from-env "^1.1.0"
babel-core@^7.0.0-bridge.0:
version "7.0.0-bridge.0"
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece"
@@ -4273,11 +4279,6 @@ flow-parser@^0.206.0:
resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.206.0.tgz#f4f794f8026535278393308e01ea72f31000bfef"
integrity sha512-HVzoK3r6Vsg+lKvlIZzaWNBVai+FXTX1wdYhz/wVlH13tb/gOdLXmlTqy6odmTBhT5UoWUbq0k8263Qhr9d88w==
follow-redirects@^1.15.0:
version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
for-each@^0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.3.tgz#69b447e88a0a5d32c3e7084f3f1710034b21376e"
@@ -7069,6 +7070,14 @@ react-native-tab-view@^3.5.2:
dependencies:
use-latest-callback "^0.1.5"
react-native-tor@^0.1.8:
version "0.1.8"
resolved "https://registry.yarnpkg.com/react-native-tor/-/react-native-tor-0.1.8.tgz#7e888aecaeb69aae5da2348639e761b6ee97c1a2"
integrity sha512-rRArwpqTQoUrQ3WQxc1WLkk1Eg/yjiwU775AxnSt6E7Nfy1V9H6+R9reMD5PJ/39qcuDYv3F7i3MR8Rjy7lOZA==
dependencies:
"@types/async" "^3.2.6"
async "^3.2.0"
react-native-url-polyfill@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/react-native-url-polyfill/-/react-native-url-polyfill-1.3.0.tgz#c1763de0f2a8c22cc3e959b654c8790622b6ef6a"