Compare commits

..

No commits in common. "master" and "v0.1.0" have entirely different histories.

11 changed files with 80 additions and 4671 deletions

View File

@ -183,8 +183,4 @@ class ReactNativeModule(reactContext: ReactApplicationContext) : ReactContextBas
promise.resolve(Gowaku.filterUnsubscribe(filterJSON, ms.toLong()))
}
@ReactMethod
fun dnsDiscovery(url: String, nameserver: String = "", ms: Double, promise: Promise) {
promise.resolve(Gowaku.dnsDiscovery(url, nameserver, ms.toLong()))
}
}

View File

@ -30,11 +30,11 @@ mkdir -p tmp
cd tmp
rm -f ${SHA_FILE}
wget "https://github.com/waku-org/go-waku/releases/download/v${VERSION}/${SHA_FILE}"
wget "https://github.com/status-im/go-waku/releases/download/v${VERSION}/${SHA_FILE}"
if [ "$DOWNLOAD_ANDROID" = true ]; then
rm -f ${ANDROID_TAR}
curl -L "https://github.com/waku-org/go-waku/releases/download/v${VERSION}/${ANDROID_TAR}" --output $ANDROID_TAR
wget "https://github.com/status-im/go-waku/releases/download/v${VERSION}/${ANDROID_TAR}"
sha256sum --status --ignore-missing -c ${SHA_FILE}
if ! sha256sum --status --ignore-missing -c ${SHA_FILE}; then
echo "checksum failed - verify download"
@ -47,7 +47,7 @@ fi
if [ "$DOWNLOAD_IOS" = true ]; then
rm -f ${IOS_TAR}
curl -L "https://github.com/waku-org/go-waku/releases/download/v${VERSION}/${IOS_TAR}" --output $IOS_TAR
wget "https://github.com/status-im/go-waku/releases/download/v${VERSION}/${IOS_TAR}"
if ! sha256sum --status --ignore-missing -c ${SHA_FILE}; then
echo "checksum failed - verify download"

View File

@ -24,11 +24,8 @@ import {
FilterSubscription,
ContentFilter,
filterSubscribe,
dnsDiscovery,
} from '@waku/react-native';
const myContentTopic = '/example/1/react-native-app/proto';
export default function App() {
const [result, setResult] = React.useState();
@ -42,16 +39,14 @@ export default function App() {
}
console.log('The node ID:', await peerID());
await relaySubscribe();
await relaySubscribe();
onMessage((event) => {
if (event.wakuMessage.contentTopic !== myContentTopic) return;
setResult(
'Message received: ' +
event.wakuMessage.timestamp +
' - payload:[' +
JSON.stringify(event.wakuMessage.payload) +
event.wakuMessage.payload +
']'
);
console.log('Message received: ', event);
@ -85,7 +80,7 @@ export default function App() {
console.log('Peers', await peers());
let msg = new WakuMessage();
msg.contentTopic = myContentTopic;
msg.contentTopic = 'ABC';
msg.payload = new Uint8Array([1, 2, 3, 4, 5]);
msg.timestamp = new Date();
msg.version = 0;
@ -97,21 +92,13 @@ export default function App() {
// TO RETRIEVE HISTORIC MESSAGES:
console.log('Retrieving messages from store node');
const query = new StoreQuery();
query.contentFilters.push(new ContentFilter(myContentTopic));
query.contentFilters.push(new ContentFilter('ABC'));
const queryResult = await storeQuery(
query,
'16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm'
);
console.log(queryResult);
// DNS Discovery
console.log('Retrieving Nodes using DNS Discovery');
const dnsDiscoveryResult = await dnsDiscovery(
'enrtree://AO47IDOLBKH72HIZZOXQP6NMRESAN7CHYWIBNXDXWRJRZWLODKII6@test.wakuv2.nodes.status.im',
'1.1.1.1'
);
console.log(dnsDiscoveryResult);
// USING FILTER INSTEAD OF RELAY:
// Instantiate the node passing these parameters:
// let config = new Config();

View File

@ -21,11 +21,11 @@
},
"..": {
"name": "@waku/react-native",
"version": "0.2.0",
"version": "0.0.12",
"license": "MIT",
"dependencies": {
"big-integer": "^1.6.51",
"buffer": "^6.0.3"
"base-64": "^1.0.0",
"big-integer": "^1.6.51"
},
"devDependencies": {
"@arkweid/lefthook": "^0.7.7",
@ -14055,8 +14055,8 @@
"@types/jest": "^28.1.2",
"@types/react": "~17.0.21",
"@types/react-native": "0.68.0",
"base-64": "^1.0.0",
"big-integer": "^1.6.51",
"buffer": "^6.0.3",
"commitlint": "^17.0.2",
"eslint": "^8.4.1",
"eslint-config-prettier": "^8.5.0",

View File

@ -7,8 +7,7 @@
"start": "expo start --dev-client",
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web",
"pods": "npx pod-install"
"web": "expo start --web"
},
"dependencies": {
"@waku/react-native": "file:../",

View File

@ -1 +1 @@
0.5.1
0.3.1

View File

@ -146,11 +146,5 @@ RCT_EXTERN_METHOD(filterUnsubscribe:(NSString *)filterJSON
withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(dnsDiscovery:(NSString *)url
withNameserver:(NSString *)nameserver
withMs:(nonnull NSNumber *)ms
withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)
@end

View File

@ -177,9 +177,4 @@ class ReactNative: RCTEventEmitter {
resolve(GowakuFilterUnsubscribe(filterJSON, ms))
}
@objc(dnsDiscovery:withNameserver:withMs:withResolver:withRejecter:)
func dnsDiscovery(url: String, nameserver: String, ms: Int, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
resolve(GowakuDnsDiscovery(url, nameserver, ms))
}
}

4549
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@waku/react-native",
"version": "0.2.0",
"version": "0.1.0",
"description": "Waku React Native",
"author": "Status Research & Development GMBH",
"authors": [
@ -21,8 +21,6 @@
"android",
"ios",
"cpp",
"download-gowaku.sh",
"go-waku.VERSION",
"waku-react-native.podspec",
"!lib/typescript/example",
"!android/build",
@ -38,7 +36,6 @@
"prepare": "bob build",
"release": "release-it",
"example": "yarn --cwd example",
"pods": "npx pod-install",
"bootstrap": "yarn example && yarn && yarn example pods"
},
"keywords": [
@ -161,7 +158,7 @@
]
},
"dependencies": {
"big-integer": "^1.6.51",
"buffer": "^6.0.3"
"base-64": "^1.0.0",
"big-integer": "^1.6.51"
}
}

View File

@ -1,6 +1,6 @@
import { NativeModules, Platform, NativeEventEmitter } from 'react-native';
import { decode, encode } from 'base-64';
import bigInt from 'big-integer';
import { Buffer } from 'buffer';
const LINKING_ERROR =
`The package '@waku/react-native' doesn't seem to be linked. Make sure: \n\n` +
@ -28,13 +28,14 @@ export class WakuMessage {
timestamp?: Date = undefined;
toJSON() {
const b64encoded = encode(String.fromCharCode(...this.payload));
return {
contentTopic: this.contentTopic,
version: this.version,
timestamp: this.timestamp
? bigInt(this.timestamp.valueOf()).multiply(OneMillion).toString(10)
: 0,
payload: Buffer.from(this.payload).toString('base64'),
payload: b64encoded,
};
}
}
@ -56,25 +57,24 @@ export function onMessage(cb: (arg0: any) => void) {
: undefined;
signal.event.wakuMessage.version = msg.version || 0;
signal.event.wakuMessage.contentTopic = msg.contentTopic;
signal.event.wakuMessage.payload = Buffer.from(msg.payload || [], 'base64');
signal.event.wakuMessage.payload = new Uint8Array(
decode(msg.payload ?? [])
.split('')
.map((c: any) => c.charCodeAt(0))
);
cb(signal.event);
});
}
export class Config {
host: String | null = null; // IP address. Default 0.0.0.0
port: Number | null = null; // TCP port to listen. Default 60000. Use 0 for random
advertiseAddr: String | null = null; // Advertise custom multiaddress
nodeKey: String | null = null; // secp256k1 private key. Default random
keepAliveInterval: Number | null = null; // interval in seconds to ping all peers
relay: Boolean | null = null; // enable waku relay
relayTopics: Array<String> = []; // array of pubsub topics that WakuRelay will automatically subscribe to when the node starts
host: String | null = null;
port: Number | null = null;
advertiseAddr: String | null = null;
nodeKey: String | null = null;
keepAliveInterval: Number | null = null;
relay: Boolean | null = null;
filter: Boolean | null = null;
minPeersToPublish: Number | null = null;
filter: Boolean | null = null; // enable waku filter
discv5: Boolean | null = null; // enable discv5
discV5BootstrapNodes: Array<String> = []; // array of bootstrap nodes ENR
discV5UDPPort: Number | null = null; // UDP port for DiscoveryV5
logLevel: String | null = null; // Set the log level. Default `INFO`. Allowed values "DEBUG", "INFO", "WARN", "ERROR", "DPANIC", "PANIC", "FATAL"
}
/**
@ -382,27 +382,6 @@ export function peerCnt(): Promise<Number> {
});
}
export class EncryptedPayload extends WakuMessage {
constructor(msg: WakuMessage) {
super();
this.contentTopic = msg.contentTopic;
this.version = msg.version;
this.timestamp = msg.timestamp;
this.payload = msg.payload;
}
toJSON() {
return {
contentTopic: this.contentTopic,
version: this.version,
timestamp: this.timestamp
? bigInt(this.timestamp.valueOf()).multiply(OneMillion).toJSNumber()
: 0,
payload: Buffer.from(Array.from(this.payload)).toString('base64'),
};
}
}
export class DecodedPayload {
payload: Uint8Array = new Uint8Array();
padding: Uint8Array = new Uint8Array();
@ -410,9 +389,11 @@ export class DecodedPayload {
signature: String | null = '';
toJSON() {
const b64payload = encode(String.fromCharCode(...this.payload));
const b64padding = encode(String.fromCharCode(...this.padding));
return {
payload: Buffer.from(this.payload).toString('base64'),
padding: Buffer.from(this.padding).toString('base64'),
payload: b64payload,
padding: b64padding,
pubkey: this.pubkey,
signature: this.signature,
};
@ -430,8 +411,7 @@ export function decodeSymmetric(
symmetricKey: String
): Promise<DecodedPayload> {
return new Promise<DecodedPayload>(async (resolve, reject) => {
let message = new EncryptedPayload(msg);
let messageJSON = JSON.stringify(message);
let messageJSON = JSON.stringify(msg);
let response = JSON.parse(
await ReactNative.decodeSymmetric(messageJSON, symmetricKey)
);
@ -439,8 +419,16 @@ export function decodeSymmetric(
reject(response.error);
} else {
let decodedPayload = new DecodedPayload();
decodedPayload.payload = Buffer.from(response.result.data, 'base64');
decodedPayload.padding = Buffer.from(response.result.padding, 'base64');
decodedPayload.payload = new Uint8Array(
atob(response.result.payload)
.split('')
.map((c) => c.charCodeAt(0))
);
decodedPayload.padding = new Uint8Array(
atob(response.result.padding)
.split('')
.map((c) => c.charCodeAt(0))
);
decodedPayload.pubkey = response.result.pubkey;
decodedPayload.signature = response.result.signature;
resolve(decodedPayload);
@ -459,17 +447,24 @@ export function decodeAsymmetric(
privateKey: String
): Promise<DecodedPayload> {
return new Promise<DecodedPayload>(async (resolve, reject) => {
let message = new EncryptedPayload(msg);
let messageJSON = JSON.stringify(message);
let messageJSON = JSON.stringify(msg);
let response = JSON.parse(
await ReactNative.decodeAsymmetric(messageJSON, privateKey)
await ReactNative.decodeSymmetric(messageJSON, privateKey)
);
if (response.error) {
reject(response.error);
} else {
let decodedPayload = new DecodedPayload();
decodedPayload.payload = Buffer.from(response.result.data, 'base64');
decodedPayload.padding = Buffer.from(response.result.padding, 'base64');
decodedPayload.payload = new Uint8Array(
atob(response.result.payload)
.split('')
.map((c) => c.charCodeAt(0))
);
decodedPayload.padding = new Uint8Array(
atob(response.result.padding)
.split('')
.map((c) => c.charCodeAt(0))
);
decodedPayload.pubkey = response.result.pubkey;
decodedPayload.signature = response.result.signature;
resolve(decodedPayload);
@ -562,8 +557,7 @@ export function lightpushPublishEncAsymmetric(
timeoutMs: Number = 0
): Promise<string> {
return new Promise<string>(async (resolve, reject) => {
let message = new EncryptedPayload(msg);
let messageJSON = JSON.stringify(message);
let messageJSON = JSON.stringify(msg);
let response = JSON.parse(
await ReactNative.lightpushPublishEncodeAsymmetric(
messageJSON,
@ -601,8 +595,7 @@ export function lightpushPublishEncSymmetric(
timeoutMs: Number = 0
): Promise<string> {
return new Promise<string>(async (resolve, reject) => {
let message = new EncryptedPayload(msg);
let messageJSON = JSON.stringify(message);
let messageJSON = JSON.stringify(msg);
let response = JSON.parse(
await ReactNative.lightpushPublishEncodeAsymmetric(
messageJSON,
@ -659,45 +652,6 @@ export function peers(): Promise<Array<Peer>> {
});
}
export class DiscoveredNode {
peerID: String = '';
addrs: Array<String> = Array();
enr: String = '';
constructor(
peerID: String,
addrs: Array<String>,
enr: String
) {
this.peerID = peerID;
this.addrs = addrs;
this.enr = enr;
}
}
/**
* Use DNS Discovery to retrieve a list of nodes from an enrtree:// URL
* @return List of Nodes
*/
export function dnsDiscovery(
url: String,
nameserver: String,
timeoutMs: Number = 0
): Promise<Array<DiscoveredNode>> {
return new Promise<Array<DiscoveredNode>>(async (resolve, reject) => {
let response = JSON.parse(await ReactNative.dnsDiscovery(url, nameserver, timeoutMs));
if (response.error) {
reject(response.error);
} else {
resolve(
response.result.map(
(x: any) => new DiscoveredNode(x.peerID, x.multiaddrs, x.enr)
)
);
}
});
}
export class Index {
digest: Uint8Array = new Uint8Array();
receiverTime: Number = 0;
@ -791,7 +745,9 @@ export function storeQuery(
? new Date(bigInt(t).divide(OneMillion).toJSNumber())
: undefined;
response.result.messages[i].payload = new Uint8Array(
Buffer.from(response.result.messages[i].payload ?? [], 'base64')
decode(response.result.messages[i].payload ?? [])
.split('')
.map((c) => c.charCodeAt(0))
);
}
}