Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SBP-M1 review comments #66

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions android/src/main/java/land/fx/fula/FulaModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,7 @@ public void shutdown(Promise promise) {
//////////////////////ANYTHING BELOW IS FOR BLOCKCHAIN/////
///////////////////////////////////////////////////////////
@ReactMethod
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
public void createAccount(String seedString, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "createAccount: seedString = " + seedString);
Expand Down Expand Up @@ -1186,6 +1187,7 @@ public void checkAccountExists(String accountString, Promise promise) {
}

@ReactMethod
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
public void createPool(String seedString, String poolName, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "createPool: seedString = " + seedString + "; poolName = " + poolName);
Expand Down Expand Up @@ -1216,6 +1218,7 @@ public void listPools(Promise promise) {
}

@ReactMethod
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
public void joinPool(String seedString, long poolID, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "joinPool: seedString = " + seedString + "; poolID = " + poolID);
Expand All @@ -1231,6 +1234,7 @@ public void joinPool(String seedString, long poolID, Promise promise) {
}

@ReactMethod
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
public void cancelPoolJoin(String seedString, long poolID, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "cancelPoolJoin: seedString = " + seedString + "; poolID = " + poolID);
Expand Down Expand Up @@ -1261,6 +1265,7 @@ public void listPoolJoinRequests(long poolID, Promise promise) {
}

@ReactMethod
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
public void votePoolJoinRequest(String seedString, long poolID, String accountString, boolean accept, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "votePoolJoinRequest: seedString = " + seedString + "; poolID = " + poolID + "; accountString = " + accountString + "; accept = " + accept);
Expand All @@ -1276,6 +1281,7 @@ public void votePoolJoinRequest(String seedString, long poolID, String accountSt
}

@ReactMethod
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
public void leavePool(String seedString, long poolID, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "leavePool: seedString = " + seedString + "; poolID = " + poolID);
Expand All @@ -1291,6 +1297,7 @@ public void leavePool(String seedString, long poolID, Promise promise) {
}

@ReactMethod
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
public void newReplicationRequest(String seedString, long poolID, long replicationFactor, String cid, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "newReplicationRequest: seedString = " + seedString + "; poolID = " + poolID + "; replicationFactor = " + replicationFactor + "; cid = " + cid);
Expand All @@ -1306,6 +1313,7 @@ public void newReplicationRequest(String seedString, long poolID, long replicati
}

@ReactMethod
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
public void newStoreRequest(String seedString, long poolID, String uploader, String cid, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "newStoreRequest: seedString = " + seedString + "; poolID = " + poolID + "; uploader = " + uploader + "; cid = " + cid);
Expand Down Expand Up @@ -1336,6 +1344,7 @@ public void listAvailableReplicationRequests(long poolID, Promise promise) {
}

@ReactMethod
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
public void removeReplicationRequest(String seedString, long poolID, String cid, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "newReplicationRequest: seedString = " + seedString + "; poolID = " + poolID + "; cid = " + cid);
Expand All @@ -1351,6 +1360,7 @@ public void removeReplicationRequest(String seedString, long poolID, String cid,
}

@ReactMethod
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
public void removeStorer(String seedString, String storage, long poolID, String cid, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "removeStorer: seedString = " + seedString + "; storage = " + storage + "; poolID = " + poolID + "; cid = " + cid);
Expand All @@ -1366,6 +1376,7 @@ public void removeStorer(String seedString, String storage, long poolID, String
}

@ReactMethod
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
public void removeStoredReplication(String seedString, String uploader, long poolID, String cid, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "removeStoredReplication: seedString = " + seedString + "; uploader = " + uploader + "; poolID = " + poolID + "; cid = " + cid);
Expand Down
11 changes: 11 additions & 0 deletions src/interfaces/fulaNativeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,45 +51,56 @@ interface FulaNativeModule {
testData: (identity: string, bloxAddr: string) => Promise<string>;

//Blockchain related functions
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
createAccount: (seed: string) => Promise<string>;
checkAccountExists: (account: string) => Promise<string>;
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
createPool: (seed: string, poolName: string) => Promise<string>;
listPools: () => Promise<string>;
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
joinPool: (seed: string, poolID: number) => Promise<string>;
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
leavePool: (seed: string, poolID: number) => Promise<string>;
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
cancelPoolJoin: (seed: string, poolID: number) => Promise<string>;
listPoolJoinRequests: (poolID: number) => Promise<string>;
votePoolJoinRequest: (
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
seed: string,
poolID: number,
account: string,
accept: boolean
) => Promise<string>;
newReplicationRequest: (
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
seed: string,
poolID: number,
replicationFactor: number,
cid: string
) => Promise<string>;
newStoreRequest: (
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
seed: string,
poolID: number,
uploader: string,
cid: string
) => Promise<string>;
listAvailableReplicationRequests: (poolID: number) => Promise<string>;
removeReplicationRequest: (
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
seed: string,
poolID: number,
cid: string
) => Promise<string>;
removeStorer: (
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
seed: string,
storer: string,
poolID: number,
cid: string
) => Promise<string>;
removeStoredReplication: (
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
seed: string,
uploader: string,
poolID: number,
Expand Down
17 changes: 17 additions & 0 deletions src/protocols/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import type * as BType from '../types/blockchain';
createAccount: This function takes a seed argument, which is used to create an account. The seed must start with "/". The function returns a promise of an object that contains the seed and the account that was created.
*/
export const createAccount = (
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
seed: string //seed that is used to create the account. It must start with "/"
): Promise<BType.SeededResponse> => {
// SBP-M1 review: seed phrase exposed in logs, remove this.
console.log('createAccount in react-native started', seed);
let res = Fula.createAccount(seed)
.then((res) => {
Expand Down Expand Up @@ -57,9 +59,11 @@ export const checkAccountExists = (
createPool: This function takes two arguments: seed and poolName. The seed is used to identify the account that is creating the pool, and the poolName is the name of the pool being created. The function returns a promise of an object that contains the owner of the pool and the poolID of the created pool.
*/
export const createPool = (
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
seed: string,
poolName: string
): Promise<BType.PoolCreateResponse> => {
// SBP-M1 review: seed phrase exposed in logs, remove this.
console.log('createPool in react-native started', seed, poolName);
let res = Fula.createPool(seed, poolName)
.then((res) => {
Expand Down Expand Up @@ -109,9 +113,11 @@ export const listPools = (): Promise<BType.PoolListResponse> => {
*/

export const joinPool = (
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
seed: string,
poolID: number
): Promise<BType.PoolJoinResponse> => {
// SBP-M1 review: seed phrase exposed in logs, remove this.
console.log('joinPool in react-native started', seed, poolID);
let res = Fula.joinPool(seed, poolID)
.then((res) => {
Expand All @@ -137,9 +143,11 @@ export const joinPool = (
*/

export const leavePool = (
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
seed: string,
poolID: number
): Promise<BType.PoolLeaveResponse> => {
// SBP-M1 review: seed phrase exposed in logs, remove this.
console.log('leavePool in react-native started', seed, poolID);
let res = Fula.leavePool(seed, poolID)
.then((res) => {
Expand All @@ -161,9 +169,11 @@ export const leavePool = (
};

export const cancelPoolJoin = (
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
seed: string,
poolID: number
): Promise<BType.PoolCancelJoinResponse> => {
// SBP-M1 review: seed phrase exposed in logs, remove this.
console.log('cancelPoolJoin in react-native started', seed, poolID);
let res = Fula.cancelPoolJoin(seed, poolID)
.then((res) => {
Expand Down Expand Up @@ -214,11 +224,13 @@ accept is a boolean value that indicates whether to accept or reject the join re
It returns a promise of BType.PoolVoteResponse which includes the account and poolID
*/
export const votePoolJoinRequest = (
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
seed: string,
poolID: number,
account: string,
accept: boolean
): Promise<BType.PoolVoteResponse> => {
// SBP-M1 review: seed phrase exposed in logs, remove this.
console.log(
'votePoolJoinRequest in react-native started',
seed,
Expand Down Expand Up @@ -255,6 +267,7 @@ cid is the content identifier of the content to be replicated.
It returns a promise of BType.ManifestUploadResponse which includes the uploader, storage, ManifestMetadata, and poolID
*/
export const newReplicationRequest = (
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
seed: string,
poolID: number,
replicationFactor: number,
Expand Down Expand Up @@ -296,6 +309,7 @@ cid is the content identifier of the content to be stored.
It returns a promise of BType.ManifestUploadResponse which includes the uploader, storage, ManifestMetadata, and poolID
*/
export const newStoreRequest = (
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
seed: string,
poolID: number,
uploader: string,
Expand Down Expand Up @@ -368,6 +382,7 @@ cid is the content ID of the replication request being removed
It returns a promise of BType.ManifestUploadResponse which is the removed replication request, including the uploader, storage, ManifestMetadata, and poolID
*/
export const removeReplicationRequest = (
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
seed: string,
poolID: number,
cid: string
Expand Down Expand Up @@ -407,6 +422,7 @@ cid is the content ID of the replication request for which the storer is being r
It returns a promise of BType.ManifestUploadResponse which is the replication request, including the uploader, storage, ManifestMetadata, and poolID after the storer has been removed.
*/
export const removeStorer = (
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
seed: string,
storer: string,
poolID: number,
Expand Down Expand Up @@ -448,6 +464,7 @@ cid is the content ID of the replication request for which the stored replicatio
It returns a promise of BType.ManifestUploadResponse which is the replication request, including the uploader, storage, ManifestMetadata, and poolID after the stored replication has been removed.
*/
export const removeStoredReplication = (
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
seed: string,
uploader: string,
poolID: number,
Expand Down
4 changes: 4 additions & 0 deletions src/protocols/chain-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { default as EventTypes } from '../interfaces/api-lookup';

import { ApiPromise, WsProvider } from '@polkadot/api';
// SBP-M1 review: remove commented out code
//import { Keyring } from '@polkadot/keyring';
import type * as BType from '../types/blockchain';

Expand All @@ -9,6 +10,7 @@ const types = {
};

export const init = async (
// SBP-M1 review: consider making configurable
wsAddress: string = 'wss://node3.functionyard.fx.land'
): Promise<ApiPromise> => {
const provider = new WsProvider(wsAddress);
Expand All @@ -23,6 +25,7 @@ export const disconnectApi = async (api: ApiPromise): Promise<void> => {
await api.disconnect();
};

// SBP-M1 review: remove commented out code
/*
createAccount: This function takes a seed and returns am account
*/
Expand Down Expand Up @@ -98,6 +101,7 @@ export const listPools = async (
}
};

// SBP-M1 review: typo
/*
checkJoinRequest: This function takes poolId and AccontId and returns a promise of an object that contains request to the pools.
*/
Expand Down
1 change: 1 addition & 0 deletions src/types/blockchain.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SBP-M1 review: create seed on device and store securely, then use PolkadotJS API to sign an extrinsic which can then be submitted to the node/api. The seed should never leave the device. Remove the seed from here.
export interface SeededResponse {
seed: string;
account: string;
Expand Down