@portal-hq/utils
Advanced tools
Comparing version 3.0.6 to 4.0.0
@@ -5,5 +5,11 @@ "use strict"; | ||
class KeychainAdapter { | ||
loadMetadata() { | ||
throw new Error('[Portal] KeychainAdapter method loadMetadata cannot be called directly. Please extend KeychainAdapter.'); | ||
} | ||
deleteAddress() { | ||
throw new Error('[Portal] KeychainAdapter method deleteAddress cannot be called directly. Please extend KeychainAdapter.'); | ||
} | ||
deleteShares() { | ||
throw new Error('[Portal] KeychainAdapter method deleteAddress cannot be called directly. Please extend KeychainAdapter.'); | ||
} | ||
deleteDkgResult() { | ||
@@ -15,14 +21,28 @@ throw new Error('[Portal] KeychainAdapter method deleteDkgResult cannot be called directly. Please extend KeychainAdapter.'); | ||
} | ||
getDkgResult(isSim, _progress = () => { | ||
getDkgResult(isSim) { | ||
throw new Error(`[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`); | ||
} | ||
getShares(_progress = () => { | ||
// Noop | ||
}) { | ||
throw new Error(`[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`); | ||
throw new Error('[Portal] KeychainAdapter method getShares cannot be called directly. Please extend KeychainAdapter.'); | ||
} | ||
getSigningShare(curve, _progress = () => { | ||
// Noop | ||
}) { | ||
throw new Error(`[Portal] KeychainAdapter method getSigningShare(${curve}) cannot be called directly. Please extend KeychainAdapter.`); | ||
} | ||
getAddresses() { | ||
throw new Error('[Portal] KeychainAdapter method getAddresses cannot be called directly. Please extend KeychainAdapter.'); | ||
} | ||
getEip155Address() { | ||
throw new Error('[Portal] KeychainAdapter method getEip155Address cannot be called directly. Please extend KeychainAdapter.'); | ||
} | ||
storeAddress(address, isSim) { | ||
throw new Error(`[Portal] KeychainAdapter method storeAddress(${address}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`); | ||
} | ||
storeDkgResult(result, isSim, _progress = () => { | ||
storeShares(result, _progress = () => { | ||
// Noop | ||
}) { | ||
throw new Error(`[Portal] KeychainAdapter method storeDkgResult(${result}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`); | ||
throw new Error(`[Portal] KeychainAdapter method storeDkgResult(${result}) cannot be called directly. Please extend KeychainAdapter.`); | ||
} | ||
@@ -29,0 +49,0 @@ validateOperations() { |
@@ -18,3 +18,3 @@ "use strict"; | ||
// Sends the request with a formatted request body | ||
if (['POST', 'PUT'].includes(this.method)) { | ||
if (['POST', 'PUT', 'PATCH'].includes(this.method)) { | ||
const body = this.prepareBody(); | ||
@@ -21,0 +21,0 @@ this.request.send(body); |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.HttpRequester = exports.HttpRequest = exports.parseRequest = exports.numberToHexString = exports.Events = exports.RpcErrorCodes = exports.ProviderRpcError = exports.PortalMpcError = exports.PortalErrorCodeTypes = exports.PortalErrorCodes = exports.NoAddressError = exports.MpcSigningError = exports.MissingOptionError = exports.InvalidGatewayConfigError = exports.InvalidChainIdError = exports.InvalidApiKeyError = exports.HttpError = exports.CloudStorageReadError = exports.Storage = exports.MpcStatuses = exports.KeychainAdapter = exports.convert = exports.convertCryptoToLocal = exports.convertLocalToCrypto = exports.getChainNameForId = exports.getChainIdForName = exports.chainNameToId = exports.chainIdToName = void 0; | ||
exports.HttpRequester = exports.PortalRequests = exports.HttpRequest = exports.parseRequest = exports.numberToHexString = exports.Events = exports.RpcErrorCodes = exports.ProviderRpcError = exports.PortalMpcError = exports.PortalErrorCodeTypes = exports.PortalErrorCodes = exports.NoAddressError = exports.MpcSigningError = exports.MissingOptionError = exports.InvalidGatewayConfigError = exports.InvalidChainIdError = exports.InvalidApiKeyError = exports.HttpError = exports.CloudStorageReadError = exports.Storage = exports.MpcStatuses = exports.KeychainAdapter = exports.convert = exports.convertCryptoToLocal = exports.convertLocalToCrypto = exports.getChainNameForId = exports.getChainIdForName = exports.chainNameToId = exports.chainIdToName = void 0; | ||
var chains_1 = require("./chains"); | ||
@@ -42,3 +42,5 @@ Object.defineProperty(exports, "chainIdToName", { enumerable: true, get: function () { return chains_1.chainIdToName; } }); | ||
Object.defineProperty(exports, "HttpRequest", { enumerable: true, get: function () { return __importDefault(http_request_1).default; } }); | ||
var PortalRequests_1 = require("./PortalRequests"); | ||
Object.defineProperty(exports, "PortalRequests", { enumerable: true, get: function () { return __importDefault(PortalRequests_1).default; } }); | ||
var requesters_1 = require("./requesters"); | ||
Object.defineProperty(exports, "HttpRequester", { enumerable: true, get: function () { return requesters_1.HttpRequester; } }); |
@@ -74,3 +74,18 @@ "use strict"; | ||
} | ||
patch(path, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const requestOptions = { | ||
method: 'PATCH', | ||
url: `${this.baseUrl}${path}`, | ||
}; | ||
requestOptions.headers = this.buildHeaders((options === null || options === void 0 ? void 0 : options.headers) ? options.headers : {}); | ||
if (options && options.body) { | ||
requestOptions.body = options.body; | ||
} | ||
const request = new index_1.HttpRequest(requestOptions); | ||
const response = (yield request.send()); | ||
return response; | ||
}); | ||
} | ||
} | ||
exports.default = HttpRequester; |
export class KeychainAdapter { | ||
loadMetadata() { | ||
throw new Error('[Portal] KeychainAdapter method loadMetadata cannot be called directly. Please extend KeychainAdapter.'); | ||
} | ||
deleteAddress() { | ||
throw new Error('[Portal] KeychainAdapter method deleteAddress cannot be called directly. Please extend KeychainAdapter.'); | ||
} | ||
deleteShares() { | ||
throw new Error('[Portal] KeychainAdapter method deleteAddress cannot be called directly. Please extend KeychainAdapter.'); | ||
} | ||
deleteDkgResult() { | ||
@@ -11,14 +17,28 @@ throw new Error('[Portal] KeychainAdapter method deleteDkgResult cannot be called directly. Please extend KeychainAdapter.'); | ||
} | ||
getDkgResult(isSim, _progress = () => { | ||
getDkgResult(isSim) { | ||
throw new Error(`[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`); | ||
} | ||
getShares(_progress = () => { | ||
// Noop | ||
}) { | ||
throw new Error(`[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`); | ||
throw new Error('[Portal] KeychainAdapter method getShares cannot be called directly. Please extend KeychainAdapter.'); | ||
} | ||
getSigningShare(curve, _progress = () => { | ||
// Noop | ||
}) { | ||
throw new Error(`[Portal] KeychainAdapter method getSigningShare(${curve}) cannot be called directly. Please extend KeychainAdapter.`); | ||
} | ||
getAddresses() { | ||
throw new Error('[Portal] KeychainAdapter method getAddresses cannot be called directly. Please extend KeychainAdapter.'); | ||
} | ||
getEip155Address() { | ||
throw new Error('[Portal] KeychainAdapter method getEip155Address cannot be called directly. Please extend KeychainAdapter.'); | ||
} | ||
storeAddress(address, isSim) { | ||
throw new Error(`[Portal] KeychainAdapter method storeAddress(${address}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`); | ||
} | ||
storeDkgResult(result, isSim, _progress = () => { | ||
storeShares(result, _progress = () => { | ||
// Noop | ||
}) { | ||
throw new Error(`[Portal] KeychainAdapter method storeDkgResult(${result}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`); | ||
throw new Error(`[Portal] KeychainAdapter method storeDkgResult(${result}) cannot be called directly. Please extend KeychainAdapter.`); | ||
} | ||
@@ -25,0 +45,0 @@ validateOperations() { |
@@ -16,3 +16,3 @@ import { HttpError } from '../errors'; | ||
// Sends the request with a formatted request body | ||
if (['POST', 'PUT'].includes(this.method)) { | ||
if (['POST', 'PUT', 'PATCH'].includes(this.method)) { | ||
const body = this.prepareBody(); | ||
@@ -19,0 +19,0 @@ this.request.send(body); |
@@ -8,2 +8,3 @@ export { chainIdToName, chainNameToId, getChainIdForName, getChainNameForId, } from './chains'; | ||
export { default as HttpRequest } from './http-request'; | ||
export { default as PortalRequests } from './PortalRequests'; | ||
export { HttpRequester } from './requesters'; |
@@ -72,3 +72,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
patch(path, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const requestOptions = { | ||
method: 'PATCH', | ||
url: `${this.baseUrl}${path}`, | ||
}; | ||
requestOptions.headers = this.buildHeaders((options === null || options === void 0 ? void 0 : options.headers) ? options.headers : {}); | ||
if (options && options.body) { | ||
requestOptions.body = options.body; | ||
} | ||
const request = new HttpRequest(requestOptions); | ||
const response = (yield request.send()); | ||
return response; | ||
}); | ||
} | ||
} | ||
export default HttpRequester; |
{ | ||
"name": "@portal-hq/utils", | ||
"version": "3.0.6", | ||
"version": "4.0.0", | ||
"main": "lib/commonjs/index", | ||
@@ -29,3 +29,3 @@ "module": "lib/esm/index", | ||
}, | ||
"gitHead": "884d505870ff81f79fde92abdcea508619eaf86e" | ||
"gitHead": "a1c6f51ff156d3d1922cdaa29ee43fe4cfefd932" | ||
} |
import PortalConnect from '@portal-hq/connect' | ||
import type { | ||
AddressesByNamespace, | ||
BackupSharePairMetadata, | ||
Balance, | ||
ClientWithCustodianData, | ||
ClientResponse, | ||
Dapp, | ||
DkgData, | ||
GenerateResponse, | ||
GetTransactionsOrder, | ||
NFT, | ||
Network, | ||
PortalKeychainMetadata, | ||
ProgressCallback, | ||
QuoteArgs, | ||
QuoteResponse, | ||
Shares, | ||
SigningSharePairMetadata, | ||
@@ -20,2 +23,3 @@ SimulateTransactionParam, | ||
} from '../../types' | ||
import PortalRequests from '../PortalRequests' | ||
import { HttpRequester } from '../requesters' | ||
@@ -52,16 +56,22 @@ | ||
getBackupShareMetadata(): Promise<BackupSharePairMetadata[]> | ||
getBalances(): Promise<Balance[]> | ||
getClient(): Promise<ClientWithCustodianData> | ||
getBackupSharesMetadata(chainId?: string): Promise<BackupSharePairMetadata[]> | ||
getBalances(chainId?: string): Promise<Balance[]> | ||
getClient(): Promise<ClientResponse> | ||
getEnabledDapps(): Promise<Dapp[]> | ||
getNFTs(): Promise<NFT[]> | ||
getNFTs(chainId?: string): Promise<NFT[]> | ||
getNetworks(): Promise<Network[]> | ||
getQuote(apiKey: string, args: QuoteArgs): Promise<QuoteResponse> | ||
getSigningShareMetadata(): Promise<SigningSharePairMetadata[]> | ||
getSources(apiKey: string): Promise<Record<string, string>> | ||
getQuote( | ||
apiKey: string, | ||
args: QuoteArgs, | ||
chainId?: string, | ||
): Promise<QuoteResponse> | ||
getSigningSharesMetadata( | ||
chainId?: string, | ||
): Promise<SigningSharePairMetadata[]> | ||
getSources(apiKey: string, chainId?: string): Promise<Record<string, string>> | ||
getTransactions( | ||
chainId?: string, | ||
limit?: number, | ||
offset?: number, | ||
order?: GetTransactionsOrder, | ||
chainId?: number, | ||
): Promise<Transaction[]> | ||
@@ -71,3 +81,7 @@ identify(traits?: Record<string, any>): Promise<{ success: boolean }> | ||
params: SimulateTransactionParam, | ||
chainId?: string, | ||
): Promise<SimulatedTransaction> | ||
storedClientSigningShares(signingSharePairIds: string[]): Promise<void> | ||
storedClientBackupShares(backupSharePairIds: string[]): Promise<void> | ||
storedClientBackupSharesKey(backupSharePairIds: string[]): Promise<void> | ||
storedClientBackupShare( | ||
@@ -93,3 +107,3 @@ success: boolean, | ||
): Promise<void> | ||
storedClientSigningShare(signingSharePairId: string): Promise<void> | ||
storedClientSigningShares(signingSharePairIds: string[]): Promise<void> | ||
track( | ||
@@ -116,11 +130,10 @@ event: string, | ||
autoApprove: boolean | ||
chainId: number | ||
chainId?: string | ||
log: Console | ||
gateway: HttpRequester | ||
gateway: PortalRequests | ||
address: Promise<string | undefined> | ||
gatewayUrl: string | ||
addresses: Promise<AddressesByNamespace | undefined> | ||
emit(event: string, data: any): IPortalProvider | ||
getGatewayUrl(): string | ||
getGatewayUrl(chainId: string): string | ||
on(event: string, callback: EventHandler): IPortalProvider | ||
@@ -130,3 +143,6 @@ once(event: string, callback: EventHandler): IPortalProvider | ||
request(args: RequestArguments): Promise<any> | ||
setChainId(chainId: number, connect?: PortalConnect): Promise<IPortalProvider> | ||
setChainId( | ||
chainId: string | number, | ||
connect?: PortalConnect | undefined, | ||
): Promise<IPortalProvider> | ||
} | ||
@@ -136,3 +152,8 @@ | ||
public api?: IPortalApi | ||
public metadata?: PortalKeychainMetadata | ||
loadMetadata(): Promise<void> { | ||
throw new Error( | ||
'[Portal] KeychainAdapter method loadMetadata cannot be called directly. Please extend KeychainAdapter.', | ||
) | ||
} | ||
deleteAddress(): Promise<boolean> { | ||
@@ -143,2 +164,7 @@ throw new Error( | ||
} | ||
deleteShares(): Promise<boolean> { | ||
throw new Error( | ||
'[Portal] KeychainAdapter method deleteAddress cannot be called directly. Please extend KeychainAdapter.', | ||
) | ||
} | ||
deleteDkgResult(): Promise<boolean> { | ||
@@ -154,12 +180,36 @@ throw new Error( | ||
} | ||
getDkgResult( | ||
isSim?: boolean, | ||
getDkgResult(isSim?: boolean): Promise<string> { | ||
throw new Error( | ||
`[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`, | ||
) | ||
} | ||
getShares( | ||
_progress: ProgressCallback = () => { | ||
// Noop | ||
}, | ||
): Promise<string> { | ||
): Promise<Shares> { | ||
throw new Error( | ||
`[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`, | ||
'[Portal] KeychainAdapter method getShares cannot be called directly. Please extend KeychainAdapter.', | ||
) | ||
} | ||
getSigningShare( | ||
curve: string, | ||
_progress: ProgressCallback = () => { | ||
// Noop | ||
}, | ||
): Promise<GenerateResponse> { | ||
throw new Error( | ||
`[Portal] KeychainAdapter method getSigningShare(${curve}) cannot be called directly. Please extend KeychainAdapter.`, | ||
) | ||
} | ||
getAddresses(): Promise<AddressesByNamespace> { | ||
throw new Error( | ||
'[Portal] KeychainAdapter method getAddresses cannot be called directly. Please extend KeychainAdapter.', | ||
) | ||
} | ||
getEip155Address(): Promise<string> { | ||
throw new Error( | ||
'[Portal] KeychainAdapter method getEip155Address cannot be called directly. Please extend KeychainAdapter.', | ||
) | ||
} | ||
storeAddress(address: string, isSim?: boolean): Promise<void> { | ||
@@ -170,5 +220,4 @@ throw new Error( | ||
} | ||
storeDkgResult( | ||
result: DkgData, | ||
isSim?: boolean, | ||
storeShares( | ||
result: Shares, | ||
_progress: ProgressCallback = () => { | ||
@@ -179,3 +228,3 @@ // Noop | ||
throw new Error( | ||
`[Portal] KeychainAdapter method storeDkgResult(${result}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`, | ||
`[Portal] KeychainAdapter method storeDkgResult(${result}) cannot be called directly. Please extend KeychainAdapter.`, | ||
) | ||
@@ -182,0 +231,0 @@ } |
@@ -30,3 +30,3 @@ import { | ||
// Sends the request with a formatted request body | ||
if (['POST', 'PUT'].includes(this.method)) { | ||
if (['POST', 'PUT', 'PATCH'].includes(this.method)) { | ||
const body = this.prepareBody() | ||
@@ -33,0 +33,0 @@ this.request.send(body) |
@@ -43,2 +43,3 @@ export { | ||
export { default as PortalRequests } from './PortalRequests' | ||
export { HttpRequester } from './requesters' | ||
@@ -69,2 +70,3 @@ | ||
type Transaction, | ||
type Shares, | ||
} from '../types' |
@@ -93,4 +93,24 @@ import { | ||
} | ||
public async patch<T>(path: string, options: HttpOptions): Promise<T> { | ||
const requestOptions = { | ||
method: 'PATCH', | ||
url: `${this.baseUrl}${path}`, | ||
} as HttpRequestOptions | ||
requestOptions.headers = this.buildHeaders( | ||
options?.headers ? options.headers : {}, | ||
) | ||
if (options && options.body) { | ||
requestOptions.body = options.body | ||
} | ||
const request = new HttpRequest(requestOptions) | ||
const response = (await request.send()) as T | ||
return response | ||
} | ||
} | ||
export default HttpRequester |
133
types.d.ts
@@ -1,2 +0,7 @@ | ||
import { BackupMethods } from '@portal-hq/core' | ||
import { | ||
BackupMethods, | ||
PortalCurve, | ||
PortalNamespace, | ||
PortalSharePairStatus, | ||
} from '@portal-hq/core' | ||
@@ -11,3 +16,8 @@ import { MpcStatuses } from './src/definitions' | ||
export type ValidHttpRequestMethods = 'DELETE' | 'GET' | 'POST' | 'PUT' | ||
export type ValidHttpRequestMethods = | ||
| 'DELETE' | ||
| 'GET' | ||
| 'POST' | ||
| 'PUT' | ||
| 'PATCH' | ||
@@ -21,2 +31,59 @@ export type ValidRpcErrorCodes = 4001 | 4100 | 4200 | 4900 | 4901 | ||
interface ClientResponse { | ||
id: string | ||
custodian: ClientResponseCustodian | ||
createdAt: string | ||
environment?: ClientResponseEnvironment | ||
ejectedAt?: string | ||
isAccountAbstracted: boolean | ||
metadata: ClientResponseMetadata | ||
wallets: ClientResponseWallet[] | ||
} | ||
interface ClientResponseBackupSharePair { | ||
backupMethod: BackupMethods | ||
createdAt: string | ||
id: string | ||
status: PortalSharePairStatus | ||
} | ||
interface ClientResponseCustodian { | ||
id: string | ||
name: string | ||
} | ||
interface ClientResponseEnvironment { | ||
id: string | ||
name: string | ||
} | ||
interface ClientResponseMetadata { | ||
namespaces: ClientResponseMetadataNamespaces | ||
} | ||
interface ClientResponseMetadataNamespaces { | ||
eip155?: ClientResponseNamespaceMetadataItem | ||
solana?: ClientResponseNamespaceMetadataItem | ||
} | ||
interface ClientResponseNamespaceMetadataItem { | ||
address: string | ||
curve: PortalCurve | ||
} | ||
interface ClientResponseSharePair { | ||
id: string | ||
createdAt: string | ||
status: PortalSharePairStatus | ||
} | ||
interface ClientResponseWallet { | ||
id: string | ||
createdAt: string | ||
backupSharePairs: ClientResponseBackupSharePair[] | ||
curve: PortalCurve | ||
publicKey: string | ||
signingSharePairs: ClientResponseSharePair[] | ||
} | ||
export interface ClientWithCustodianData { | ||
@@ -63,2 +130,59 @@ id: string | ||
export interface GenerateResponse { | ||
id: string | ||
share: DkgData | ||
} | ||
export interface Shares { | ||
ed25519?: GenerateResponse | ||
secp256k1: GenerateResponse | ||
} | ||
export interface AddressesByNamespace { | ||
eip155: string | ||
solana?: string | ||
} | ||
export interface WalletsByCurve { | ||
[key in PortalCurve]: PortalKeychainClientMetadataWallet | ||
} | ||
export interface PortalKeychainClientMetadata { | ||
id: string | ||
addresses?: AddressesByNamespace | ||
custodian: ClientResponseCustodian | ||
wallets?: WalletsByCurve | ||
} | ||
export interface PortalKeychainClientMetadataWallet { | ||
id: string | ||
curve: PortalCurve | ||
publicKey: string | ||
backupShares: PortalKeychainClientMetadataWalletBackupShare[] | ||
signingShares: PortalKeychainClientMetadataWalletShare[] | ||
} | ||
export interface PortalKeychainClientMetadataWalletBackupShare { | ||
backupMethod: BackupMethods | ||
createdAt: string | ||
id: string | ||
status: PortalSharePairStatus | ||
} | ||
export interface PortalKeychainClientMetadataWalletShare { | ||
createdAt: string | ||
id: string | ||
status: PortalSharePairStatus | ||
} | ||
export type PortalKeychainClientShares = GenerateResponse | ||
export interface CurveByNamespace { | ||
[namespace: string]: PortalCurve | ||
} | ||
export interface PortalKeychainMetadata { | ||
namespaces: CurveByNamespace | ||
} | ||
export interface DkgData { | ||
@@ -74,2 +198,3 @@ allY: { [key: MpcMember]: Pubkey } | ||
signingSharePairId?: string | ||
backupSharePairId?: string | ||
ssid: string | ||
@@ -182,5 +307,7 @@ } | ||
export interface SigningRequestArguments { | ||
readonly chainId?: number | ||
readonly chainId: string | ||
readonly curve: PortalCurve | ||
readonly method: string | ||
readonly params?: unknown[] | SigningRequestParams | ||
readonly isRaw?: boolean | ||
} | ||
@@ -187,0 +314,0 @@ |
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
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
155075
75
4538