Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@portal-hq/core

Package Overview
Dependencies
Maintainers
6
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@portal-hq/core - npm Package Compare versions

Comparing version 0.2.0-beta6 to 0.2.0-beta7

82

lib/commonjs/index.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -39,7 +16,5 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

exports.Portal = exports.BackupMethods = exports.PortalApi = void 0;
const gdrive_storage_1 = __importDefault(require("@portal-hq/gdrive-storage"));
const icloud_storage_1 = __importDefault(require("@portal-hq/icloud-storage"));
const provider_1 = require("@portal-hq/provider");
const api_1 = __importDefault(require("./api"));
const mpc_1 = __importStar(require("./mpc"));
const mpc_1 = __importDefault(require("./mpc"));
// Exports

@@ -53,8 +28,3 @@ var api_2 = require("./api");

// Required
apiKey, backupConfig = {
method: mpc_1.BackupMethods.GoogleDrive,
androidClientId: 'PLEASE_CONFIGURE_GOOGLE_DRIVE',
folder: 'PLEASE_CONFIGURE_BACKUP_STORAGE_FOLDER',
iosClientId: 'PLEASE_CONFIGURE_GOOGLE_DRIVE',
}, chainId, infuraId, isSimulator, gatewayConfig,
apiKey, backup, chainId, isSimulator, keychain, gatewayConfig,
// Optional

@@ -64,5 +34,6 @@ address = null, apiHost = 'api.portalhq.io', autoApprove = false, mpcEnabled = true, mpcHost = 'mpc.portalhq.io', }) {

this.autoApprove = autoApprove;
this.backup = backup;
this.chainId = chainId;
this.infuraId = infuraId;
this.isSimulator = isSimulator;
this.keychain = keychain;
this.mpcEnabled = mpcEnabled;

@@ -85,26 +56,12 @@ this.gatewayConfig = gatewayConfig;

// Initialize the Portal MPC Client
const mpcOptions = {
this.mpc = new mpc_1.default({
apiKey,
chainId: this.chainId,
host: mpcHost,
infuraId: infuraId,
isSimulator,
};
// Initialize storage option
const { androidClientId, folder, iosClientId, method } = backupConfig;
if (method === mpc_1.BackupMethods.GoogleDrive) {
mpcOptions.storage = new gdrive_storage_1.default({
androidClientId,
api: this.api,
folder,
iosClientId,
});
}
else if (method === mpc_1.BackupMethods.iCloud) {
mpcOptions.storage = new icloud_storage_1.default({
api: this.api,
folder,
});
}
this.mpc = new mpc_1.default(mpcOptions);
keychain: keychain,
portal: this.api,
rpc: this.getGatewayUrl(),
storage: this.backup,
});
this.mpc.address.then((address) => __awaiter(this, void 0, void 0, function* () {

@@ -138,2 +95,3 @@ yield this.setAddress(address);

this.mpc.chainId = chainId;
this.mpc.rpc = this.getGatewayUrl();
}

@@ -221,4 +179,22 @@ }

}
getGatewayUrl() {
if (typeof this.gatewayConfig === 'string') {
// If the gatewayConfig is just a static URL, return that
return this.gatewayConfig;
}
else if (typeof this.gatewayConfig === 'object' &&
!this.gatewayConfig.hasOwnProperty(this.chainId)) {
// If there's no explicit mapping for the current chainId, error out
throw new Error(`[PortalProvider] No RPC endpoint configured for chainId: ${this.chainId}`);
}
// Get the entry for the current chainId from the gatewayConfig
const config = this.gatewayConfig[this.chainId];
if (typeof config === 'string') {
return config;
}
// If we got this far, there's no way to support the chain with the current config
throw new Error(`[PortalProvider] Could not find a valid gatewayConfig entry for chainId: ${this.chainId}`);
}
}
exports.Portal = Portal;
exports.default = Portal;

@@ -11,5 +11,2 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -19,20 +16,17 @@ exports.BackupMethods = void 0;

const react_native_rsa_native_1 = require("react-native-rsa-native");
const keychain_1 = __importDefault(require("@portal-hq/keychain"));
var BackupMethods;
(function (BackupMethods) {
BackupMethods["GoogleDrive"] = "Google Drive";
BackupMethods["iCloud"] = "iCloud";
BackupMethods["GoogleDrive"] = "gdrive";
BackupMethods["iCloud"] = "icloud";
})(BackupMethods = exports.BackupMethods || (exports.BackupMethods = {}));
class PortalMpc {
constructor({ apiKey, chainId, host = 'mpc.portalhq.io', infuraId, isSimulator, portal, storage, rpc, }) {
constructor({ apiKey, chainId, host = 'mpc.portalhq.io', isSimulator, keychain, portal, storage, rpc, }) {
this.apiKey = apiKey;
this.infuraId = infuraId;
this.isSimulator = isSimulator;
this.chainId = chainId;
this.host = host;
this.keychain = new keychain_1.default();
this.keychain = keychain;
this.portal = portal;
this.storage = storage;
this.rpc = rpc;
this.infuraId = infuraId;
this.mpc = react_native_1.NativeModules.PortalMobileMpc;

@@ -91,3 +85,3 @@ if (!this.mpc) {

*/
backup() {
backup(method) {
return __awaiter(this, void 0, void 0, function* () {

@@ -112,3 +106,7 @@ let res;

const encryptedShare = yield this.encryptShare(backupDkg);
yield this.storage.write(encryptedShare.privateKey);
const storage = this.storage[method];
if (!storage) {
throw new Error(`[PortalMpc] Unsupported storage method ${method}`);
}
yield storage.write(encryptedShare.privateKey);
return encryptedShare.cipherText;

@@ -176,3 +174,3 @@ }

console.log(`[PortalMpc] Started sign for method: '${method}'`);
const rpcUrl = `${this.rpc}/${this.infuraId}`;
const rpcUrl = `${this.rpc}`;
res = yield this.mpc.sign(this.apiKey, this.host, dkgResult, method, params, rpcUrl, this.chainId.toString());

@@ -205,5 +203,9 @@ JSON.parse(res);

*/
recover(cipherText) {
recover(cipherText, method) {
return __awaiter(this, void 0, void 0, function* () {
const privateKey = yield this.storage.read();
const storage = this.storage[method];
if (!storage) {
throw new Error(`[PortalMpc] Unsupported storage method ${method}`);
}
const privateKey = yield storage.read();
const backupDkg = yield this.decryptShare(cipherText, privateKey);

@@ -220,3 +222,3 @@ // recoverSigning also writes to the keychain

const backupShare = yield this.encryptShare(newBackupDkg);
yield this.storage.write(backupShare.privateKey);
yield storage.write(backupShare.privateKey);
return backupShare.cipherText;

@@ -223,0 +225,0 @@ });

@@ -10,7 +10,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
import GoogleStorage from '@portal-hq/gdrive-storage';
import ICloudStorage from '@portal-hq/icloud-storage';
import { Provider } from '@portal-hq/provider';
import PortalApi from './api';
import PortalMpc, { BackupMethods } from './mpc';
import PortalMpc from './mpc';
// Exports

@@ -22,8 +20,3 @@ export { default as PortalApi } from './api';

// Required
apiKey, backupConfig = {
method: BackupMethods.GoogleDrive,
androidClientId: 'PLEASE_CONFIGURE_GOOGLE_DRIVE',
folder: 'PLEASE_CONFIGURE_BACKUP_STORAGE_FOLDER',
iosClientId: 'PLEASE_CONFIGURE_GOOGLE_DRIVE',
}, chainId, infuraId, isSimulator, gatewayConfig,
apiKey, backup, chainId, isSimulator, keychain, gatewayConfig,
// Optional

@@ -33,5 +26,6 @@ address = null, apiHost = 'api.portalhq.io', autoApprove = false, mpcEnabled = true, mpcHost = 'mpc.portalhq.io', }) {

this.autoApprove = autoApprove;
this.backup = backup;
this.chainId = chainId;
this.infuraId = infuraId;
this.isSimulator = isSimulator;
this.keychain = keychain;
this.mpcEnabled = mpcEnabled;

@@ -54,26 +48,12 @@ this.gatewayConfig = gatewayConfig;

// Initialize the Portal MPC Client
const mpcOptions = {
this.mpc = new PortalMpc({
apiKey,
chainId: this.chainId,
host: mpcHost,
infuraId: infuraId,
isSimulator,
};
// Initialize storage option
const { androidClientId, folder, iosClientId, method } = backupConfig;
if (method === BackupMethods.GoogleDrive) {
mpcOptions.storage = new GoogleStorage({
androidClientId,
api: this.api,
folder,
iosClientId,
});
}
else if (method === BackupMethods.iCloud) {
mpcOptions.storage = new ICloudStorage({
api: this.api,
folder,
});
}
this.mpc = new PortalMpc(mpcOptions);
keychain: keychain,
portal: this.api,
rpc: this.getGatewayUrl(),
storage: this.backup,
});
this.mpc.address.then((address) => __awaiter(this, void 0, void 0, function* () {

@@ -107,2 +87,3 @@ yield this.setAddress(address);

this.mpc.chainId = chainId;
this.mpc.rpc = this.getGatewayUrl();
}

@@ -190,3 +171,21 @@ }

}
getGatewayUrl() {
if (typeof this.gatewayConfig === 'string') {
// If the gatewayConfig is just a static URL, return that
return this.gatewayConfig;
}
else if (typeof this.gatewayConfig === 'object' &&
!this.gatewayConfig.hasOwnProperty(this.chainId)) {
// If there's no explicit mapping for the current chainId, error out
throw new Error(`[PortalProvider] No RPC endpoint configured for chainId: ${this.chainId}`);
}
// Get the entry for the current chainId from the gatewayConfig
const config = this.gatewayConfig[this.chainId];
if (typeof config === 'string') {
return config;
}
// If we got this far, there's no way to support the chain with the current config
throw new Error(`[PortalProvider] Could not find a valid gatewayConfig entry for chainId: ${this.chainId}`);
}
}
export default Portal;

@@ -12,20 +12,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

import { RSA } from 'react-native-rsa-native';
import Keychain from '@portal-hq/keychain';
export var BackupMethods;
(function (BackupMethods) {
BackupMethods["GoogleDrive"] = "Google Drive";
BackupMethods["iCloud"] = "iCloud";
BackupMethods["GoogleDrive"] = "gdrive";
BackupMethods["iCloud"] = "icloud";
})(BackupMethods || (BackupMethods = {}));
class PortalMpc {
constructor({ apiKey, chainId, host = 'mpc.portalhq.io', infuraId, isSimulator, portal, storage, rpc, }) {
constructor({ apiKey, chainId, host = 'mpc.portalhq.io', isSimulator, keychain, portal, storage, rpc, }) {
this.apiKey = apiKey;
this.infuraId = infuraId;
this.isSimulator = isSimulator;
this.chainId = chainId;
this.host = host;
this.keychain = new Keychain();
this.keychain = keychain;
this.portal = portal;
this.storage = storage;
this.rpc = rpc;
this.infuraId = infuraId;
this.mpc = NativeModules.PortalMobileMpc;

@@ -84,3 +81,3 @@ if (!this.mpc) {

*/
backup() {
backup(method) {
return __awaiter(this, void 0, void 0, function* () {

@@ -105,3 +102,7 @@ let res;

const encryptedShare = yield this.encryptShare(backupDkg);
yield this.storage.write(encryptedShare.privateKey);
const storage = this.storage[method];
if (!storage) {
throw new Error(`[PortalMpc] Unsupported storage method ${method}`);
}
yield storage.write(encryptedShare.privateKey);
return encryptedShare.cipherText;

@@ -169,3 +170,3 @@ }

console.log(`[PortalMpc] Started sign for method: '${method}'`);
const rpcUrl = `${this.rpc}/${this.infuraId}`;
const rpcUrl = `${this.rpc}`;
res = yield this.mpc.sign(this.apiKey, this.host, dkgResult, method, params, rpcUrl, this.chainId.toString());

@@ -198,5 +199,9 @@ JSON.parse(res);

*/
recover(cipherText) {
recover(cipherText, method) {
return __awaiter(this, void 0, void 0, function* () {
const privateKey = yield this.storage.read();
const storage = this.storage[method];
if (!storage) {
throw new Error(`[PortalMpc] Unsupported storage method ${method}`);
}
const privateKey = yield storage.read();
const backupDkg = yield this.decryptShare(cipherText, privateKey);

@@ -213,3 +218,3 @@ // recoverSigning also writes to the keychain

const backupShare = yield this.encryptShare(newBackupDkg);
yield this.storage.write(backupShare.privateKey);
yield storage.write(backupShare.privateKey);
return backupShare.cipherText;

@@ -216,0 +221,0 @@ });

{
"name": "@portal-hq/core",
"version": "0.2.0-beta6",
"version": "0.2.0-beta7",
"license": "MIT",

@@ -25,5 +25,5 @@ "main": "lib/commonjs/index",

"dependencies": {
"@portal-hq/keychain": "^0.2.0-beta6",
"@portal-hq/provider": "^0.2.0-beta6",
"@portal-hq/utils": "^0.2.0-beta6",
"@portal-hq/keychain": "^0.2.0-beta7",
"@portal-hq/provider": "^0.2.0-beta7",
"@portal-hq/utils": "^0.2.0-beta7",
"react-native-rsa-native": "^2.0.5"

@@ -30,0 +30,0 @@ },

@@ -16,16 +16,14 @@ # `Portal`

```typescript
import { BackupMethods, Portal } from '@portal-hq/react-native'
import { BackupMethods, Portal } from '@portal-hq/core'
const portal = new Portal({
apiKey: 'YOUR_PORTAL_CLIENT_API_KEY',
backupConfig: {
method: BackupMethods.GoogleDrive,
androidClientId: 'YOUR_GOOGLE_DRIVE_CLIENT_ID',
folder: 'YOUR_PREFERRED_FOLDER_NAME',
iosClientId: 'YOUR_GOOGLE_DRICE_CLIENT_ID',
backup: {
gdrive: gDriveStorage, // See: @portal-hq/gdrive-storage
icloud: iCloudStorage, // See: @portal-hq/icloud-storage
},
chainId: 1,
infuraId: 'YOUR_INFURA_ID',
gatewayConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
isSimulator: DeviceInfo.isEmulator(),
rpcConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
keychain: keychain, // See: @portal-hq/keychain
})

@@ -42,13 +40,10 @@ ```

- `backupConfig` **object**
- `method` **BackupMethods** the supported backup method you'd like to use for storing backup MPC
- You can use the exported enum `BackupMethods` to set this value which contains the following supported backup methods:
- `GoogleDrive`
- `iCloud`
- `androidClientId` **string** (only used for `GoogleDrive`) the Android Client ID ([get one](https://docs.portalhq.io/guides/backup#google-drive-backup))
- `iosClientId` **string** (only used for `GoogleDrive`) the iOS Client ID ([get one](https://docs.portalhq.io/guides/backup#google-drive-backup))
- `folder` **string** the folder you'd like to store backup shares in (this folder will be created in the root of your users' Google Drive or iCloud)
- `gdrive` **Storage** (optional) expects an instance of `@portal-hq/gdrive-storage`
- `icloud` **Storage** (optional) expects an instance of `@portal-hq/icloud-storage`
- `chainId` **number** the ID of the current Ethereum chain you'd like to perform actions on
- You can update this property on your `Portal` instance later – if your app requires this – by setting `portal.chainId` property
- `infuraId` **string** your Infura API Key – this will be used for making read requests in the provider
- `gatewayConfig` **string** or **GatewayConfig** the base url (including your API key) you'd like us to use for Gateway requests (reading from and writing to chain) _**Note: this will be required in the future**_
- `GatewayConfig` – if you don't want to use the same url for all requests, you can instead provide a chain-level config for all Gateway RPC calls this can be passed in as an object with key/value pairs where the `key` is the `chainId` as a number and the value is the base url you'd like to use when performing actions on this `chainId`
- `isSimulator` **boolean** whether or not you're currently running the app in a simulator (this is required to ensure that keychain storage is configured appropriately for the current device)
- `keychain` **Keychain** expects an instance of either `@portal-hq/keychain` or `@portal-hq/mobile-key-values`

@@ -59,4 +54,2 @@ #### Optional properties

- `mpcEnabled` **boolean** (default: `true`) whether or not to use MPC
- `rpcConfig` **string** or **RpcConfig** the base url (including your API key) you'd like us to use for Gateway requests (reading from and writing to chain) _**Note: this will be required in the future**_
- `RpcConfig` – if you don't want to use the same url for all requests, you can instead provide a chain-level config for all Gateway RPC calls this can be passed in as an object with key/value pairs where the `key` is the `chainId` as a number and the value is the base url you'd like to use when performing actions on this `chainId`

@@ -78,11 +71,10 @@ ## `api`

apiKey: 'YOUR_PORTAL_CLIENT_API_KEY',
backupConfig: {
method: BackupMethods.GoogleDrive,
androidClientId: 'YOUR_GOOGLE_DRIVE_CLIENT_ID',
iosClientId: 'YOUR_GOOGLE_DRICE_CLIENT_ID',
backup: {
gdrive: gDriveStorage, // See: @portal-hq/gdrive-storage
icloud: iCloudStorage, // See: @portal-hq/icloud-storage
},
chainId: 1,
infuraId: 'YOUR_INFURA_ID',
isSimulator: DeviceInfo.isEmulator(),
rpcConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
gatewayConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
isSimulator: DeviceInfo.isEmulator(),,
keychain: keychain // See: @portal-hq/keychain
})

@@ -102,11 +94,10 @@

apiKey: 'YOUR_PORTAL_CLIENT_API_KEY',
backupConfig: {
method: BackupMethods.GoogleDrive,
androidClientId: 'YOUR_GOOGLE_DRIVE_CLIENT_ID',
iosClientId: 'YOUR_GOOGLE_DRICE_CLIENT_ID',
backup: {
gdrive: gDriveStorage, // See: @portal-hq/gdrive-storage
icloud: iCloudStorage, // See: @portal-hq/icloud-storage
},
chainId: 1,
infuraId: 'YOUR_INFURA_ID',
isSimulator: DeviceInfo.isEmulator(),
rpcConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
gatewayConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
isSimulator: DeviceInfo.isEmulator(),,
keychain: keychain // See: @portal-hq/keychain
})

@@ -132,11 +123,10 @@

apiKey: 'YOUR_PORTAL_CLIENT_API_KEY',
backupConfig: {
method: BackupMethods.GoogleDrive,
androidClientId: 'YOUR_GOOGLE_DRIVE_CLIENT_ID',
iosClientId: 'YOUR_GOOGLE_DRICE_CLIENT_ID',
backup: {
gdrive: gDriveStorage, // See: @portal-hq/gdrive-storage
icloud: iCloudStorage, // See: @portal-hq/icloud-storage
},
chainId: 1,
infuraId: 'YOUR_INFURA_ID',
isSimulator: DeviceInfo.isEmulator(),
rpcConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
gatewayConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
isSimulator: DeviceInfo.isEmulator(),,
keychain: keychain // See: @portal-hq/keychain
})

@@ -158,11 +148,10 @@

apiKey: 'YOUR_PORTAL_CLIENT_API_KEY',
backupConfig: {
method: BackupMethods.GoogleDrive,
androidClientId: 'YOUR_GOOGLE_DRIVE_CLIENT_ID',
iosClientId: 'YOUR_GOOGLE_DRICE_CLIENT_ID',
backup: {
gdrive: gDriveStorage, // See: @portal-hq/gdrive-storage
icloud: iCloudStorage, // See: @portal-hq/icloud-storage
},
chainId: 1,
infuraId: 'YOUR_INFURA_ID',
isSimulator: DeviceInfo.isEmulator(),
rpcConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
gatewayConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
isSimulator: DeviceInfo.isEmulator(),,
keychain: keychain, // See: @portal-hq/keychain
})

@@ -184,11 +173,10 @@

apiKey: 'YOUR_PORTAL_CLIENT_API_KEY',
backupConfig: {
method: BackupMethods.GoogleDrive,
androidClientId: 'YOUR_GOOGLE_DRIVE_CLIENT_ID',
iosClientId: 'YOUR_GOOGLE_DRICE_CLIENT_ID',
backup: {
gdrive: gDriveStorage, // See: @portal-hq/gdrive-storage
icloud: iCloudStorage, // See: @portal-hq/icloud-storage
},
chainId: 1,
infuraId: 'YOUR_INFURA_ID',
gatewayConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
isSimulator: DeviceInfo.isEmulator(),
rpcConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
keychain: keychain, // See: @portal-hq/keychain
})

@@ -195,0 +183,0 @@

@@ -1,8 +0,6 @@

import GoogleStorage from '@portal-hq/gdrive-storage'
import ICloudStorage from '@portal-hq/icloud-storage'
import { Provider, type GatewayLike } from '@portal-hq/provider'
import PortalApi from './api'
import PortalMpc, { BackupMethods } from './mpc'
import { type PortalMpcOptions, type PortalOptions } from '../types'
import PortalMpc from './mpc'
import { BackupOptions, KeychainAdapter, type PortalOptions } from '../types'

@@ -23,3 +21,2 @@ // Exports

public autoApprove: boolean
public infuraId: string
public isSimulator: boolean

@@ -33,2 +30,4 @@ public mpc: PortalMpc

private _chainId: number
private backup: BackupOptions
private keychain: KeychainAdapter

@@ -38,11 +37,6 @@ constructor({

apiKey,
backupConfig = {
method: BackupMethods.GoogleDrive,
androidClientId: 'PLEASE_CONFIGURE_GOOGLE_DRIVE',
folder: 'PLEASE_CONFIGURE_BACKUP_STORAGE_FOLDER',
iosClientId: 'PLEASE_CONFIGURE_GOOGLE_DRIVE',
},
backup,
chainId,
infuraId,
isSimulator,
keychain,
gatewayConfig,

@@ -59,5 +53,6 @@

this.autoApprove = autoApprove
this.backup = backup
this.chainId = chainId
this.infuraId = infuraId
this.isSimulator = isSimulator
this.keychain = keychain
this.mpcEnabled = mpcEnabled

@@ -83,29 +78,13 @@ this.gatewayConfig = gatewayConfig

// Initialize the Portal MPC Client
const mpcOptions = {
this.mpc = new PortalMpc({
apiKey,
chainId: this.chainId,
host: mpcHost,
infuraId: infuraId,
isSimulator,
} as PortalMpcOptions
keychain: keychain,
portal: this.api,
rpc: this.getGatewayUrl(),
storage: this.backup,
})
// Initialize storage option
const { androidClientId, folder, iosClientId, method } = backupConfig
if (method === BackupMethods.GoogleDrive) {
mpcOptions.storage = new GoogleStorage({
androidClientId,
api: this.api,
folder,
iosClientId,
})
} else if (method === BackupMethods.iCloud) {
mpcOptions.storage = new ICloudStorage({
api: this.api,
folder,
})
}
this.mpc = new PortalMpc(mpcOptions)
this.mpc.address.then(async (address) => {

@@ -142,2 +121,3 @@ await this.setAddress(address)

this.mpc.chainId = chainId
this.mpc.rpc = this.getGatewayUrl()
}

@@ -225,4 +205,31 @@ }

}
private getGatewayUrl(): string {
if (typeof this.gatewayConfig === 'string') {
// If the gatewayConfig is just a static URL, return that
return this.gatewayConfig
} else if (
typeof this.gatewayConfig === 'object' &&
!this.gatewayConfig.hasOwnProperty(this.chainId)
) {
// If there's no explicit mapping for the current chainId, error out
throw new Error(
`[PortalProvider] No RPC endpoint configured for chainId: ${this.chainId}`,
)
}
// Get the entry for the current chainId from the gatewayConfig
const config = this.gatewayConfig[this.chainId]
if (typeof config === 'string') {
return config
}
// If we got this far, there's no way to support the chain with the current config
throw new Error(
`[PortalProvider] Could not find a valid gatewayConfig entry for chainId: ${this.chainId}`,
)
}
}
export default Portal

@@ -6,2 +6,4 @@ import { NativeModules } from 'react-native'

import {
KeychainAdapter,
type BackupOptions,
type DkgResult,

@@ -21,4 +23,4 @@ type EncryptedData,

export enum BackupMethods {
GoogleDrive = 'Google Drive',
iCloud = 'iCloud',
GoogleDrive = 'gdrive',
iCloud = 'icloud',
}

@@ -34,9 +36,7 @@

private isSimulator: boolean
private keychain: Keychain
private storage: Storage
private keychain: KeychainAdapter
private storage: BackupOptions
private mpc: PortalMobileMpc
private portal: Portal
public infuraId: string
constructor({

@@ -46,4 +46,4 @@ apiKey,

host = 'mpc.portalhq.io',
infuraId,
isSimulator,
keychain,
portal,

@@ -54,7 +54,6 @@ storage,

this.apiKey = apiKey
this.infuraId = infuraId
this.isSimulator = isSimulator
this.chainId = chainId
this.host = host
this.keychain = new Keychain()
this.keychain = keychain
this.portal = portal

@@ -64,3 +63,2 @@ this.storage = storage

this.rpc = rpc
this.infuraId = infuraId
this.mpc = NativeModules.PortalMobileMpc

@@ -136,3 +134,3 @@

*/
public async backup(): Promise<string> {
public async backup(method: BackupMethods): Promise<string> {
let res: string

@@ -162,5 +160,10 @@

const encryptedShare = await this.encryptShare(backupDkg)
const storage = this.storage[method] as Storage
await this.storage.write(encryptedShare.privateKey)
if (!storage) {
throw new Error(`[PortalMpc] Unsupported storage method ${method}`)
}
await storage.write(encryptedShare.privateKey)
return encryptedShare.cipherText

@@ -227,3 +230,3 @@ }

console.log(`[PortalMpc] Started sign for method: '${method}'`)
const rpcUrl = `${this.rpc}/${this.infuraId}`
const rpcUrl = `${this.rpc}`
res = await this.mpc.sign(

@@ -264,4 +267,13 @@ this.apiKey,

*/
public async recover(cipherText: string): Promise<string> {
const privateKey = await this.storage.read()
public async recover(
cipherText: string,
method: BackupMethods,
): Promise<string> {
const storage = this.storage[method] as Storage
if (!storage) {
throw new Error(`[PortalMpc] Unsupported storage method ${method}`)
}
const privateKey = await storage.read()
const backupDkg = await this.decryptShare(cipherText, privateKey)

@@ -283,3 +295,3 @@

await this.storage.write(backupShare.privateKey)
await storage.write(backupShare.privateKey)

@@ -286,0 +298,0 @@ return backupShare.cipherText

@@ -1,2 +0,2 @@

import { BackupMethods } from './src//mpc'
import { BackupMethods } from './src/mpc'

@@ -7,2 +7,6 @@ export type GatewayLike = GatewayConfig | string

export interface BackupOptions {
gdrive?: Storage
icloud?: Storage
}
export interface Bk {

@@ -100,7 +104,7 @@ X: string

chainId: number
infuraId: string
isSimulator: boolean
storage: Storage
keychain: KeychainAdapter
portal: Portal
rpc: string
portal: Portal
storage: BackupOptions

@@ -114,12 +118,5 @@ // Optional options

apiKey: string
backupConfig: {
method: BackupMethods
// Only used for GoogleDrive
androidClientId?: string
folder: string
iosClientId?: string
}
backup: BackupOptions
chainId: number
infuraId: string
keychain: KeychainAdapter
isSimulator: boolean

@@ -160,2 +157,11 @@ gatewayConfig: GatewayLike

export declare class KeychainAdapter {
deleteAddress: () => Promise<boolean>
deleteDkgResult: () => Promise<boolean>
getAddress: (isSim?: boolean) => Promise<string>
getDkgResult: (isSim?: boolean) => Promise<string>
storeAddress: (address: string, isSim?: boolean) => Promise<void>
storeDkgResult: (result: DkgData, isSim?: boolean) => Promise<void>
}
export declare class Storage {

@@ -162,0 +168,0 @@ read(): Promise<string>

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc