@portal-hq/core
Advanced tools
Comparing version 4.0.0 to 4.1.0-beta
@@ -49,2 +49,19 @@ "use strict"; | ||
} | ||
getClientCipherText(backupSharePairId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const path = `/api/v3/clients/me/backup-share-pairs/${backupSharePairId}/cipher-text`; | ||
const response = yield this.requests.get(path, { | ||
headers: { | ||
Authorization: `Bearer ${this.apiKey}`, | ||
}, | ||
}); | ||
try { | ||
void this.track(utils_1.Events.GetClientCipherText, { path }); | ||
} | ||
catch (error) { | ||
// Noop | ||
} | ||
return response.cipherText; | ||
}); | ||
} | ||
getEnabledDapps() { | ||
@@ -169,2 +186,24 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
prepareClientEject(walletId, backupMethod) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const path = `/api/v3/clients/me/wallets/${walletId}/prepare-eject`; | ||
const response = yield this.requests.post(path, { | ||
body: { | ||
backupMethod, | ||
}, | ||
headers: { | ||
Authorization: `Bearer ${this.apiKey}`, | ||
}, | ||
}); | ||
try { | ||
void this.track(utils_1.Events.PrepareClientEject, { | ||
path, | ||
}); | ||
} | ||
catch (error) { | ||
// Noop | ||
} | ||
return response.share; | ||
}); | ||
} | ||
simulateTransaction(transaction, chainId) { | ||
@@ -195,2 +234,26 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
storeClientCipherText(backupSharePairId, cipherText) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const path = `/api/v3/clients/me/backup-share-pairs/${backupSharePairId}/cipher-text`; | ||
yield this.requests.patch(path, { | ||
headers: { | ||
Authorization: `Bearer ${this.apiKey}`, | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
body: { | ||
clientCipherText: cipherText, | ||
}, | ||
}); | ||
try { | ||
void this.track(utils_1.Events.StoreClientCipherText, { | ||
path, | ||
}); | ||
} | ||
catch (error) { | ||
// Noop | ||
} | ||
return true; | ||
}); | ||
} | ||
getQuote(apiKey, args, chainId) { | ||
@@ -197,0 +260,0 @@ return __awaiter(this, void 0, void 0, function* () { |
@@ -145,3 +145,3 @@ "use strict"; | ||
} | ||
recoverWallet(cipherText, method, progress, backupConfig = {}) { | ||
recoverWallet(cipherText = '', method, progress, backupConfig = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -148,0 +148,0 @@ return yield this.mpc.recover(cipherText, method, progress, backupConfig); |
@@ -99,3 +99,3 @@ "use strict"; | ||
}, backupConfig = {}) { | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -108,2 +108,3 @@ if (this.version !== 'v6') { | ||
} | ||
const client = yield this.portal.api.getClient(); | ||
this.isWalletModificationInProgress = true; | ||
@@ -210,2 +211,7 @@ try { | ||
this.isWalletModificationInProgress = false; | ||
if ((_d = client.environment) === null || _d === void 0 ? void 0 : _d.backupWithPortalEnabled) { | ||
for (const [_, value] of Object.entries(shares)) { | ||
yield this.portal.api.storeClientCipherText(value.id, encryptedShares.cipherText); | ||
} | ||
} | ||
return encryptedShares.cipherText; | ||
@@ -402,3 +408,3 @@ } | ||
}, backupConfig = {}) { | ||
var _a; | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -411,2 +417,20 @@ if (this.version !== 'v6') { | ||
} | ||
let clientCipherText = cipherText; | ||
const client = yield this.portal.api.getClient(); | ||
if ((_a = client.environment) === null || _a === void 0 ? void 0 : _a.backupWithPortalEnabled) { | ||
let backupSharePairId = ''; | ||
for (const wallet of client.wallets) { | ||
for (const share of wallet.backupSharePairs) { | ||
if (share.backupMethod === backupMethod && | ||
share.status === 'completed') { | ||
backupSharePairId = share.id; | ||
break; | ||
} | ||
} | ||
} | ||
if (backupSharePairId.length === 0) { | ||
throw new Error('No valid backup found'); | ||
} | ||
clientCipherText = yield this.portal.api.getClientCipherText(backupSharePairId); | ||
} | ||
this.isWalletModificationInProgress = true; | ||
@@ -419,6 +443,6 @@ try { | ||
if (backupMethod === BackupMethods.Password && | ||
((_a = backupConfig.passwordStorage) === null || _a === void 0 ? void 0 : _a.password) === null) { | ||
((_b = backupConfig.passwordStorage) === null || _b === void 0 ? void 0 : _b.password) === null) { | ||
throw new errors_1.default(errors_1.MpcErrorCodes.PASSWORD_REQUIRED); | ||
} | ||
let backupShares = yield this.getBackupShares(cipherText, backupMethod, progress, backupConfig); | ||
let backupShares = yield this.getBackupShares(clientCipherText, backupMethod, progress, backupConfig); | ||
try { | ||
@@ -425,0 +449,0 @@ const tryShares = JSON.parse(backupShares); |
@@ -47,2 +47,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
getClientCipherText(backupSharePairId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const path = `/api/v3/clients/me/backup-share-pairs/${backupSharePairId}/cipher-text`; | ||
const response = yield this.requests.get(path, { | ||
headers: { | ||
Authorization: `Bearer ${this.apiKey}`, | ||
}, | ||
}); | ||
try { | ||
void this.track(Events.GetClientCipherText, { path }); | ||
} | ||
catch (error) { | ||
// Noop | ||
} | ||
return response.cipherText; | ||
}); | ||
} | ||
getEnabledDapps() { | ||
@@ -167,2 +184,24 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
prepareClientEject(walletId, backupMethod) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const path = `/api/v3/clients/me/wallets/${walletId}/prepare-eject`; | ||
const response = yield this.requests.post(path, { | ||
body: { | ||
backupMethod, | ||
}, | ||
headers: { | ||
Authorization: `Bearer ${this.apiKey}`, | ||
}, | ||
}); | ||
try { | ||
void this.track(Events.PrepareClientEject, { | ||
path, | ||
}); | ||
} | ||
catch (error) { | ||
// Noop | ||
} | ||
return response.share; | ||
}); | ||
} | ||
simulateTransaction(transaction, chainId) { | ||
@@ -193,2 +232,26 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
storeClientCipherText(backupSharePairId, cipherText) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const path = `/api/v3/clients/me/backup-share-pairs/${backupSharePairId}/cipher-text`; | ||
yield this.requests.patch(path, { | ||
headers: { | ||
Authorization: `Bearer ${this.apiKey}`, | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
body: { | ||
clientCipherText: cipherText, | ||
}, | ||
}); | ||
try { | ||
void this.track(Events.StoreClientCipherText, { | ||
path, | ||
}); | ||
} | ||
catch (error) { | ||
// Noop | ||
} | ||
return true; | ||
}); | ||
} | ||
getQuote(apiKey, args, chainId) { | ||
@@ -195,0 +258,0 @@ return __awaiter(this, void 0, void 0, function* () { |
@@ -129,3 +129,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
recoverWallet(cipherText, method, progress, backupConfig = {}) { | ||
recoverWallet(cipherText = '', method, progress, backupConfig = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -132,0 +132,0 @@ return yield this.mpc.recover(cipherText, method, progress, backupConfig); |
@@ -71,3 +71,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}, backupConfig = {}) { | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -80,2 +80,3 @@ if (this.version !== 'v6') { | ||
} | ||
const client = yield this.portal.api.getClient(); | ||
this.isWalletModificationInProgress = true; | ||
@@ -182,2 +183,7 @@ try { | ||
this.isWalletModificationInProgress = false; | ||
if ((_d = client.environment) === null || _d === void 0 ? void 0 : _d.backupWithPortalEnabled) { | ||
for (const [_, value] of Object.entries(shares)) { | ||
yield this.portal.api.storeClientCipherText(value.id, encryptedShares.cipherText); | ||
} | ||
} | ||
return encryptedShares.cipherText; | ||
@@ -374,3 +380,3 @@ } | ||
}, backupConfig = {}) { | ||
var _a; | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -383,2 +389,20 @@ if (this.version !== 'v6') { | ||
} | ||
let clientCipherText = cipherText; | ||
const client = yield this.portal.api.getClient(); | ||
if ((_a = client.environment) === null || _a === void 0 ? void 0 : _a.backupWithPortalEnabled) { | ||
let backupSharePairId = ''; | ||
for (const wallet of client.wallets) { | ||
for (const share of wallet.backupSharePairs) { | ||
if (share.backupMethod === backupMethod && | ||
share.status === 'completed') { | ||
backupSharePairId = share.id; | ||
break; | ||
} | ||
} | ||
} | ||
if (backupSharePairId.length === 0) { | ||
throw new Error('No valid backup found'); | ||
} | ||
clientCipherText = yield this.portal.api.getClientCipherText(backupSharePairId); | ||
} | ||
this.isWalletModificationInProgress = true; | ||
@@ -391,6 +415,6 @@ try { | ||
if (backupMethod === BackupMethods.Password && | ||
((_a = backupConfig.passwordStorage) === null || _a === void 0 ? void 0 : _a.password) === null) { | ||
((_b = backupConfig.passwordStorage) === null || _b === void 0 ? void 0 : _b.password) === null) { | ||
throw new MpcError(MpcErrorCodes.PASSWORD_REQUIRED); | ||
} | ||
let backupShares = yield this.getBackupShares(cipherText, backupMethod, progress, backupConfig); | ||
let backupShares = yield this.getBackupShares(clientCipherText, backupMethod, progress, backupConfig); | ||
try { | ||
@@ -397,0 +421,0 @@ const tryShares = JSON.parse(backupShares); |
@@ -6,3 +6,3 @@ { | ||
"homepage": "https://portalhq.io/", | ||
"version": "4.0.0", | ||
"version": "4.1.0-beta", | ||
"license": "MIT", | ||
@@ -31,7 +31,7 @@ "main": "lib/commonjs/index", | ||
"dependencies": { | ||
"@portal-hq/connect": "^4.0.0", | ||
"@portal-hq/keychain": "^4.0.0", | ||
"@portal-hq/provider": "^4.0.0", | ||
"@portal-hq/swaps": "^4.0.0", | ||
"@portal-hq/utils": "^4.0.0" | ||
"@portal-hq/connect": "^4.1.0-beta", | ||
"@portal-hq/keychain": "^4.1.0-beta", | ||
"@portal-hq/provider": "^4.1.0-beta", | ||
"@portal-hq/swaps": "^4.1.0-beta", | ||
"@portal-hq/utils": "^4.1.0-beta" | ||
}, | ||
@@ -53,3 +53,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "a1c6f51ff156d3d1922cdaa29ee43fe4cfefd932" | ||
"gitHead": "87317816c3fb6475dc655746b2023fa84e0417d7" | ||
} |
@@ -23,3 +23,3 @@ import { type QuoteArgs, type QuoteResponse } from '@portal-hq/swaps' | ||
import { type FeatureFlags, type PortalApiOptions } from '../../types' | ||
import { PortalCurve } from '../mpc' | ||
import { BackupMethods, PortalCurve } from '../mpc' | ||
@@ -74,2 +74,19 @@ class PortalApi implements IPortalApi { | ||
public async getClientCipherText(backupSharePairId: string): Promise<string> { | ||
const path = `/api/v3/clients/me/backup-share-pairs/${backupSharePairId}/cipher-text` | ||
const response = await this.requests.get<{ cipherText: string }>(path, { | ||
headers: { | ||
Authorization: `Bearer ${this.apiKey}`, | ||
}, | ||
}) | ||
try { | ||
void this.track(Events.GetClientCipherText, { path }) | ||
} catch (error) { | ||
// Noop | ||
} | ||
return response.cipherText | ||
} | ||
public async getEnabledDapps(): Promise<Dapp[]> { | ||
@@ -210,2 +227,28 @@ const dapps = await this.requests.get<Dapp[]>(`/api/v1/config/dapps`, { | ||
public async prepareClientEject( | ||
walletId: string, | ||
backupMethod: BackupMethods, | ||
): Promise<string> { | ||
const path = `/api/v3/clients/me/wallets/${walletId}/prepare-eject` | ||
const response = await this.requests.post<{ share: string }>(path, { | ||
body: { | ||
backupMethod, | ||
}, | ||
headers: { | ||
Authorization: `Bearer ${this.apiKey}`, | ||
}, | ||
}) | ||
try { | ||
void this.track(Events.PrepareClientEject, { | ||
path, | ||
}) | ||
} catch (error) { | ||
// Noop | ||
} | ||
return response.share | ||
} | ||
public async simulateTransaction( | ||
@@ -246,2 +289,30 @@ transaction: SimulateTransactionParam, | ||
public async storeClientCipherText( | ||
backupSharePairId: string, | ||
cipherText: string, | ||
): Promise<boolean> { | ||
const path = `/api/v3/clients/me/backup-share-pairs/${backupSharePairId}/cipher-text` | ||
await this.requests.patch(path, { | ||
headers: { | ||
Authorization: `Bearer ${this.apiKey}`, | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
body: { | ||
clientCipherText: cipherText, | ||
}, | ||
}) | ||
try { | ||
void this.track(Events.StoreClientCipherText, { | ||
path, | ||
}) | ||
} catch (error) { | ||
// Noop | ||
} | ||
return true | ||
} | ||
public async getQuote( | ||
@@ -248,0 +319,0 @@ apiKey: string, |
@@ -194,3 +194,3 @@ import PortalConnect from '@portal-hq/connect' | ||
public async recoverWallet( | ||
cipherText: string, | ||
cipherText: string = '', | ||
method: BackupMethods, | ||
@@ -197,0 +197,0 @@ progress?: ProgressCallback, |
@@ -131,2 +131,4 @@ import { PortalMobileMpcMetadata } from '@portal-hq/provider/types' | ||
const client = await this.portal.api.getClient() | ||
this.isWalletModificationInProgress = true | ||
@@ -290,2 +292,12 @@ | ||
this.isWalletModificationInProgress = false | ||
if (client.environment?.backupWithPortalEnabled) { | ||
for (const [_, value] of Object.entries(shares)) { | ||
await this.portal.api.storeClientCipherText( | ||
value.id as string, | ||
encryptedShares.cipherText, | ||
) | ||
} | ||
} | ||
return encryptedShares.cipherText | ||
@@ -560,2 +572,28 @@ } | ||
let clientCipherText = cipherText | ||
const client = await this.portal.api.getClient() | ||
if (client.environment?.backupWithPortalEnabled) { | ||
let backupSharePairId: string = '' | ||
for (const wallet of client.wallets) { | ||
for (const share of wallet.backupSharePairs) { | ||
if ( | ||
share.backupMethod === backupMethod && | ||
share.status === 'completed' | ||
) { | ||
backupSharePairId = share.id | ||
break | ||
} | ||
} | ||
} | ||
if (backupSharePairId.length === 0) { | ||
throw new Error('No valid backup found') | ||
} | ||
clientCipherText = await this.portal.api.getClientCipherText( | ||
backupSharePairId, | ||
) | ||
} | ||
this.isWalletModificationInProgress = true | ||
@@ -580,3 +618,3 @@ | ||
let backupShares = await this.getBackupShares( | ||
cipherText, | ||
clientCipherText, | ||
backupMethod, | ||
@@ -583,0 +621,0 @@ progress, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
124548305
6037
1
+ Added@portal-hq/connect@4.1.0-beta2(transitive)
+ Added@portal-hq/core@4.0.3(transitive)
+ Added@portal-hq/keychain@4.1.0-beta2(transitive)
+ Added@portal-hq/provider@4.1.0-beta2(transitive)
+ Added@portal-hq/swaps@4.1.0-beta2(transitive)
+ Added@portal-hq/utils@4.1.0-beta2(transitive)
Updated@portal-hq/swaps@^4.1.0-beta
Updated@portal-hq/utils@^4.1.0-beta