-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (54 loc) · 2.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { NativeModules } from 'react-native';
import * as RNFS from 'react-native-fs';
class SDK {
constructor() {
this.rnfsPath = RNFS.DocumentDirectoryPath;
this.connectionProfilePath = this.rnfsPath + "/connection_profile.json";
this.HlfWrapper = NativeModules.HlfWrapper;
}
// Native call test Function
async hello() {
return await this.HlfWrapper.sampleMethod();
}
getRNFSPath() {
return this.rnfsPath
}
async connectionProfileSetup(connectionProfile) {
connectionProfile.client.credentialStore.path = this.rnfsPath + '/wallet'
connectionProfile.client.credentialStore.cryptoStore.path = this.rnfsPath + '/msp'
RNFS.writeFile(this.connectionProfilePath, JSON.stringify(connectionProfile))
.then((success) => {
console.log('FILE WRITTEN!');
})
.catch((err) => {
console.log(err.message);
});
}
async enrollUser(user, secret) {
return await this.HlfWrapper.enroll(user, secret, this.connectionProfilePath);
}
async lsRNFS() {
// get a list of files and directories in the main bundle
console.log("list the RNFS dir")
await RNFS.readDir(this.rnfsPath)
.then((result) => {
console.log('GOT RESULT', result);
})
.catch((err) => {
console.log(err.message, err.code);
});
}
async loadPrivateKey(privateKeyName) {
// get a list of files and directories in the main bundle
console.log("reading private key from RNFS: " + this.rnfsPath + '/msp/keystore/' + privateKeyName)
return await RNFS.readFile(this.rnfsPath + '/msp/keystore/' + privateKeyName);
}
async query(user, channelName, chaincodeName, fnc, args) {
return await this.HlfWrapper.query(user, this.connectionProfilePath, channelName, chaincodeName, fnc, args);
}
async invoke(user, channelName, chaincodeName, fnc, args) {
return await this.HlfWrapper.invoke(user, this.connectionProfilePath, channelName, chaincodeName, fnc, args);
}
}
const HlfSdk = new SDK()
export default HlfSdk;