@portal-hq/utils 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class CloudStorageReadError extends Error {
4
+ constructor() {
5
+ super('[Portal] Unable to read from Cloud Storage.');
6
+ // Set the prototype explicitly.
7
+ Object.setPrototypeOf(this, CloudStorageReadError.prototype);
8
+ }
9
+ }
10
+ exports.default = CloudStorageReadError;
@@ -17,7 +17,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.RpcErrorCodes = exports.ProviderRpcError = exports.NoAddressError = exports.MpcSigningError = exports.MissingOptionError = exports.InvalidGatewayConfigError = exports.InvalidChainIdError = exports.InvalidApiKeyError = exports.HttpError = void 0;
20
+ exports.RpcErrorCodes = exports.ProviderRpcError = exports.NoAddressError = exports.MpcSigningError = exports.MissingOptionError = exports.InvalidGatewayConfigError = exports.InvalidChainIdError = exports.InvalidApiKeyError = exports.HttpError = exports.CloudStorageReadError = void 0;
21
+ var cloud_storage_read_error_1 = require("./cloud-storage-read-error");
22
+ Object.defineProperty(exports, "CloudStorageReadError", { enumerable: true, get: function () { return __importDefault(cloud_storage_read_error_1).default; } });
21
23
  var http_error_1 = require("./http-error");
22
24
  Object.defineProperty(exports, "HttpError", { enumerable: true, get: function () { return __importDefault(http_error_1).default; } });
23
25
  var invalid_api_key_error_1 = require("./invalid-api-key-error");
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- 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.Storage = exports.MpcStatuses = exports.KeychainAdapter = exports.convert = exports.convertCryptoToLocal = exports.convertLocalToCrypto = exports.getChainNameForId = exports.getChainIdForName = exports.chainNameToId = exports.chainIdToName = void 0;
6
+ 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;
7
7
  var chains_1 = require("./chains");
8
8
  Object.defineProperty(exports, "chainIdToName", { enumerable: true, get: function () { return chains_1.chainIdToName; } });
9
9
  Object.defineProperty(exports, "chainNameToId", { enumerable: true, get: function () { return chains_1.chainNameToId; } });
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "KeychainAdapter", { enumerable: true, get: funct
18
18
  Object.defineProperty(exports, "MpcStatuses", { enumerable: true, get: function () { return definitions_1.MpcStatuses; } });
19
19
  Object.defineProperty(exports, "Storage", { enumerable: true, get: function () { return definitions_1.Storage; } });
20
20
  var errors_1 = require("./errors");
21
+ Object.defineProperty(exports, "CloudStorageReadError", { enumerable: true, get: function () { return errors_1.CloudStorageReadError; } });
21
22
  Object.defineProperty(exports, "HttpError", { enumerable: true, get: function () { return errors_1.HttpError; } });
22
23
  Object.defineProperty(exports, "InvalidApiKeyError", { enumerable: true, get: function () { return errors_1.InvalidApiKeyError; } });
23
24
  Object.defineProperty(exports, "InvalidChainIdError", { enumerable: true, get: function () { return errors_1.InvalidChainIdError; } });
@@ -0,0 +1,8 @@
1
+ class CloudStorageReadError extends Error {
2
+ constructor() {
3
+ super('[Portal] Unable to read from Cloud Storage.');
4
+ // Set the prototype explicitly.
5
+ Object.setPrototypeOf(this, CloudStorageReadError.prototype);
6
+ }
7
+ }
8
+ export default CloudStorageReadError;
@@ -1,3 +1,4 @@
1
+ export { default as CloudStorageReadError } from './cloud-storage-read-error';
1
2
  export { default as HttpError } from './http-error';
2
3
  export { default as InvalidApiKeyError } from './invalid-api-key-error';
3
4
  export { default as InvalidChainIdError } from './invalid-chain-id-error';
package/lib/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { chainIdToName, chainNameToId, getChainIdForName, getChainNameForId, } from './chains';
2
2
  export { convertLocalToCrypto, convertCryptoToLocal, convert } from './currency';
3
3
  export { KeychainAdapter, MpcStatuses, Storage, } from './definitions';
4
- export { HttpError, InvalidApiKeyError, InvalidChainIdError, InvalidGatewayConfigError, MissingOptionError, MpcSigningError, NoAddressError, PortalErrorCodes, PortalErrorCodeTypes, PortalMpcError, ProviderRpcError, RpcErrorCodes, } from './errors';
4
+ export { CloudStorageReadError, HttpError, InvalidApiKeyError, InvalidChainIdError, InvalidGatewayConfigError, MissingOptionError, MpcSigningError, NoAddressError, PortalErrorCodes, PortalErrorCodeTypes, PortalMpcError, ProviderRpcError, RpcErrorCodes, } from './errors';
5
5
  export { default as Events } from './events';
6
6
  export { numberToHexString, parseRequest } from './eth-requests';
7
7
  export { default as HttpRequest } from './http-request';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portal-hq/utils",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "main": "lib/commonjs/index",
5
5
  "module": "lib/esm/index",
6
6
  "source": "src/index",
@@ -26,5 +26,5 @@
26
26
  "ts-jest": "^29.0.3",
27
27
  "typescript": "^4.8.4"
28
28
  },
29
- "gitHead": "2ba5caccbaae676a2b207bab294bbd59cfc136ca"
29
+ "gitHead": "169a9045d5cfb542b037a26d0ebcc53f51eec8dd"
30
30
  }
@@ -1,13 +1,107 @@
1
- import {
2
- type ClientWithCustodianData,
3
- type Dapp,
4
- type DkgData,
5
- type Network,
6
- type ProgressCallback,
1
+ import { HttpRequester } from '../requesters'
2
+ import type {
3
+ Balance,
4
+ ClientWithCustodianData,
5
+ Dapp,
6
+ DkgData,
7
+ NFT,
8
+ Network,
9
+ ProgressCallback,
10
+ QuoteArgs,
11
+ QuoteResponse,
12
+ SimulateTransactionParam,
13
+ SimulatedTransaction,
14
+ Transaction,
7
15
  } from '../../types'
16
+ import PortalConnect from '@portal-hq/connect'
17
+
18
+ export type EventHandler = (data: any) => void
19
+
20
+ export interface Eip1559 {
21
+ gasLimit?: string
22
+ maxPriorityFeePerGas?: string
23
+ maxFeePerGas?: string
24
+ [key: string]: any
25
+ }
26
+
27
+ export interface LegacyTx {
28
+ gasLimit?: string
29
+ gasPrice?: string
30
+ [key: string]: any
31
+ }
32
+
33
+ export interface RequestArguments {
34
+ method: string
35
+ params?: unknown[] | SigningRequestParams
36
+ connect?: PortalConnect
37
+ }
38
+
39
+ export type SigningRequestParams = Eip1559 | LegacyTx
40
+
41
+ export interface IPortalApi {
42
+ apiKey: string
43
+ apiUrl: string
44
+ requests: HttpRequester
45
+
46
+ getClient(): Promise<ClientWithCustodianData>
47
+ getEnabledDapps(): Promise<Dapp[]>
48
+ getNetworks(): Promise<Network[]>
49
+ getNFTs(): Promise<NFT[]>
50
+ getTransactions(): Promise<Transaction[]>
51
+ getBalances(): Promise<Balance[]>
52
+ simulateTransaction(
53
+ params: SimulateTransactionParam,
54
+ ): Promise<SimulatedTransaction>
55
+ getQuote(apiKey: string, args: QuoteArgs): Promise<QuoteResponse>
56
+ getSources(apiKey: string): Promise<Record<string, string>>
57
+ storedClientSigningShare(options?: {
58
+ recoverSigning?: boolean
59
+ }): Promise<void>
60
+ storedClientBackupShareKey(backupMethod?: string): Promise<void>
61
+ storedClientBackupShare(
62
+ success: boolean,
63
+ backupMethod?: string,
64
+ ): Promise<void>
65
+ identify(traits?: Record<string, any>): Promise<{ success: boolean }>
66
+ track(
67
+ event: string,
68
+ properties?: Record<string, any>,
69
+ ): Promise<{ success: boolean }>
70
+ }
71
+
72
+ export interface IPortalConnect {
73
+ connected: boolean
74
+ connect(uri: string): Promise<void>
75
+ deinit(): void
76
+ disconnect(): void
77
+ emit(event: string, data: any): PortalConnect
78
+ on(event: string, callback: EventHandler): PortalConnect
79
+ once(event: string, callback: EventHandler): PortalConnect
80
+ removeEventListener(event: string, listenerToRemove?: EventHandler): void
81
+ setChainId(chainId: number): Promise<void>
82
+ }
83
+
84
+ export interface IPortalProvider {
85
+ apiKey: string
86
+ autoApprove: boolean
87
+ chainId: number
88
+ log: Console
89
+ gateway: HttpRequester
90
+
91
+ address: Promise<string | undefined>
92
+ gatewayUrl: string
93
+
94
+ emit(event: string, data: any): IPortalProvider
95
+ getGatewayUrl(): string
96
+ on(event: string, callback: EventHandler): IPortalProvider
97
+ once(event: string, callback: EventHandler): IPortalProvider
98
+ removeEventListener(event: string, listenerToRemove?: EventHandler): void
99
+ request(args: RequestArguments): Promise<any>
100
+ setChainId(chainId: number, connect?: PortalConnect): Promise<IPortalProvider>
101
+ }
8
102
 
9
103
  export abstract class KeychainAdapter {
10
- public api?: PortalApi
104
+ public api?: IPortalApi
11
105
 
12
106
  deleteAddress(): Promise<boolean> {
13
107
  throw new Error(
@@ -65,14 +159,8 @@ export enum MpcStatuses {
65
159
  StoringShare = 'Storing share',
66
160
  }
67
161
 
68
- export declare class PortalApi {
69
- getClient(): Promise<ClientWithCustodianData>
70
- getEnabledDapps(): Promise<Dapp[]>
71
- getNetworks(): Promise<Network[]>
72
- }
73
-
74
162
  export abstract class Storage {
75
- public api?: PortalApi
163
+ public api?: IPortalApi
76
164
 
77
165
  delete(): Promise<boolean> {
78
166
  throw new Error(
@@ -0,0 +1,10 @@
1
+ class CloudStorageReadError extends Error {
2
+ constructor() {
3
+ super('[Portal] Unable to read from Cloud Storage.')
4
+
5
+ // Set the prototype explicitly.
6
+ Object.setPrototypeOf(this, CloudStorageReadError.prototype)
7
+ }
8
+ }
9
+
10
+ export default CloudStorageReadError
@@ -1,3 +1,4 @@
1
+ export { default as CloudStorageReadError } from './cloud-storage-read-error'
1
2
  export { default as HttpError } from './http-error'
2
3
  export { default as InvalidApiKeyError } from './invalid-api-key-error'
3
4
  export { default as InvalidChainIdError } from './invalid-chain-id-error'
package/src/index.ts CHANGED
@@ -8,13 +8,17 @@ export {
8
8
  export { convertLocalToCrypto, convertCryptoToLocal, convert } from './currency'
9
9
 
10
10
  export {
11
+ type IPortalApi,
12
+ type IPortalConnect,
13
+ type IPortalProvider,
11
14
  KeychainAdapter,
12
15
  MpcStatuses,
13
- type PortalApi,
16
+ type RequestArguments,
14
17
  Storage,
15
18
  } from './definitions'
16
19
 
17
20
  export {
21
+ CloudStorageReadError,
18
22
  HttpError,
19
23
  InvalidApiKeyError,
20
24
  InvalidChainIdError,
package/types.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { MpcStatuses } from './src/definitions'
2
2
 
3
+ export type MpcMember = 'client' | 'server'
4
+
3
5
  export type OutgoingRequestData = MessageData | SignableTransactionData
4
6
 
5
7
  export type ProgressCallback = (status: MpcStatus) => void | Promise<void>
@@ -57,12 +59,20 @@ export interface DkgData {
57
59
  share: string
58
60
  ssid: string
59
61
  pubkey: Pubkey
60
- partialPubKey: Pubkey[]
61
- allY: Pubkey[]
62
+ partialPubkey: {
63
+ [key: MpcMember]: Pubkey
64
+ }
65
+ allY: {
66
+ [key: MpcMember]: Pubkey
67
+ }
62
68
  p: string
63
69
  q: string
64
- pederson: PedersonParams[]
65
- bks: Bk[]
70
+ pederson: {
71
+ [key: MpcMember]: PedersonParams
72
+ }
73
+ bks: {
74
+ [key: MpcMember]: Bk
75
+ }
66
76
  }
67
77
 
68
78
  export interface PedersonParams {
@@ -123,6 +133,30 @@ export interface Pubkey {
123
133
  Y: string
124
134
  }
125
135
 
136
+ export interface QuoteArgs {
137
+ affiliateAddress?: string
138
+ buyAmount?: number
139
+ buyToken: string
140
+ buyTokenPercentageFee?: number
141
+ enableSlippageProtection?: boolean
142
+ excludedSources?: string
143
+ feeRecipient?: string
144
+ gasPrice?: number
145
+ includedSources?: string
146
+ intentOnFilling?: boolean
147
+ priceImpactProtectionPercentage?: number
148
+ sellAmount?: number
149
+ sellToken: string
150
+ skipValidation?: boolean
151
+ slippagePercentage?: number
152
+ takerAddress?: string
153
+ }
154
+
155
+ export interface QuoteResponse {
156
+ cost: string
157
+ transaction: Eip1559 | LegacyTx
158
+ }
159
+
126
160
  export interface RequesterOptions {}
127
161
 
128
162
  export interface RpcErrorDefinition {
@@ -191,6 +225,41 @@ export interface Transaction {
191
225
  value: number
192
226
  }
193
227
 
228
+ export interface SimulateTransactionParam {
229
+ to: string
230
+ value?: string
231
+ data?: string
232
+ gas?: string
233
+ gasPrice?: string
234
+ maxFeePerGas?: string
235
+ maxPriorityFeePerGas?: string
236
+ }
237
+
238
+ export interface SimulatedTransactionChange {
239
+ amount?: string
240
+ assetType?: string
241
+ changeType?: string
242
+ contractAddress?: string
243
+ decimals?: number
244
+ from?: string
245
+ name?: string
246
+ rawAmount?: string
247
+ symbol?: string
248
+ to?: string
249
+ tokenId?: number
250
+ }
251
+
252
+ export interface SimulatedTransactionError {
253
+ message: string
254
+ }
255
+
256
+ export interface SimulatedTransaction {
257
+ changes: SimulatedTransactionChange[]
258
+ gasUsed?: string
259
+ error?: SimulatedTransactionError
260
+ requestError?: SimulatedTransactionError
261
+ }
262
+
194
263
  export interface Balance {
195
264
  contractAddress: string
196
265
  balance: string