@portal-hq/utils 4.6.0 → 4.8.0

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getChainNameForId = exports.getChainIdForName = exports.chainNameToId = exports.chainIdToName = exports.CAIP2_CHAIN_ID_REGEX = exports.DEFAULT_CHAIN_ID_CAIP2 = exports.DEFAULT_CHAIN_ID_NUMERIC = exports.SUPPORTED_BITCOIN_P2WPKH_CHAINS = exports.FRIENDLY_CHAIN_NAME_TO_CAIP2 = exports.ALL_CHAIN_IDS = exports.BITCOIN_CHAIN_IDS = exports.SOLANA_CHAIN_IDS = exports.EVM_CHAIN_IDS = exports.NAMESPACE_TO_CURVE = exports.CHAIN_NAMESPACES = void 0;
3
+ exports.getChainNameForId = exports.getChainIdForName = exports.chainNameToId = exports.chainIdToName = exports.CAIP2_CHAIN_ID_REGEX = exports.DEFAULT_CHAIN_ID_CAIP2 = exports.DEFAULT_CHAIN_ID_NUMERIC = exports.SUPPORTED_BITCOIN_P2WPKH_CHAINS = exports.FRIENDLY_CHAIN_NAME_TO_CAIP2 = exports.ALL_CHAIN_IDS = exports.BITCOIN_CHAIN_IDS = exports.TRON_CHAIN_IDS = exports.SOLANA_CHAIN_IDS = exports.EVM_CHAIN_IDS = exports.NAMESPACE_TO_CURVE = exports.CHAIN_NAMESPACES = void 0;
4
4
  exports.CHAIN_NAMESPACES = {
5
5
  EIP155: 'eip155',
6
6
  SOLANA: 'solana',
@@ -34,11 +34,14 @@ exports.SOLANA_CHAIN_IDS = {
34
34
  SOLANA_MAINNET: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
35
35
  SOLANA_DEVNET: 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',
36
36
  };
37
+ exports.TRON_CHAIN_IDS = {
38
+ TRON_MAINNET: 'tron:mainnet',
39
+ };
37
40
  exports.BITCOIN_CHAIN_IDS = {
38
41
  BITCOIN_P2WPKH_MAINNET: 'bip122:000000000019d6689c085ae165831e93-p2wpkh',
39
42
  BITCOIN_P2WPKH_TESTNET: 'bip122:000000000933ea01ad0ee984209779ba-p2wpkh',
40
43
  };
41
- exports.ALL_CHAIN_IDS = Object.assign(Object.assign(Object.assign({}, exports.EVM_CHAIN_IDS), exports.SOLANA_CHAIN_IDS), exports.BITCOIN_CHAIN_IDS);
44
+ exports.ALL_CHAIN_IDS = Object.assign(Object.assign(Object.assign(Object.assign({}, exports.EVM_CHAIN_IDS), exports.SOLANA_CHAIN_IDS), exports.BITCOIN_CHAIN_IDS), exports.TRON_CHAIN_IDS);
42
45
  exports.FRIENDLY_CHAIN_NAME_TO_CAIP2 = {
43
46
  // EVM chains
44
47
  ethereum: exports.EVM_CHAIN_IDS.ETHEREUM_MAINNET,
@@ -1,9 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_HOSTS = void 0;
3
+ exports.buildDefaultGatewayConfig = exports.SUPPORTED_CHAINS = exports.DEFAULT_HOSTS = void 0;
4
4
  exports.DEFAULT_HOSTS = {
5
5
  API: 'api.portalhq.io',
6
6
  MPC: 'mpc.portalhq.io',
7
7
  ENCLAVE_MPC: 'mpc-client.portalhq.io',
8
8
  WEBSOCKET: 'connect.portalhq.io',
9
9
  };
10
+ /**
11
+ * Canonical list of chains covered by the default gateway config. Single
12
+ * source of truth for both `buildDefaultGatewayConfig` and its tests.
13
+ */
14
+ exports.SUPPORTED_CHAINS = [
15
+ { namespace: 'eip155', reference: '1' },
16
+ { namespace: 'eip155', reference: '11155111' },
17
+ { namespace: 'eip155', reference: '137' },
18
+ { namespace: 'eip155', reference: '80002' },
19
+ { namespace: 'eip155', reference: '8453' },
20
+ { namespace: 'eip155', reference: '84532' },
21
+ { namespace: 'eip155', reference: '143' },
22
+ { namespace: 'eip155', reference: '10143' },
23
+ { namespace: 'solana', reference: '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' },
24
+ { namespace: 'solana', reference: 'EtWTRABZaYq6iMfeYKouRu166VU2xqa1' },
25
+ ];
26
+ /**
27
+ * Builds a gateway config map for all Portal-supported chains using the given API host.
28
+ * Used as the default when no gatewayConfig is supplied to the Portal constructor.
29
+ */
30
+ function buildDefaultGatewayConfig(apiHost) {
31
+ const host = apiHost.replace(/\/$/, '');
32
+ const protocol = host.startsWith('localhost') ? 'http' : 'https';
33
+ const base = `${protocol}://${host}/rpc/v1`;
34
+ return exports.SUPPORTED_CHAINS.reduce((config, { namespace, reference }) => {
35
+ config[`${namespace}:${reference}`] = `${base}/${namespace}/${reference}`;
36
+ return config;
37
+ }, {});
38
+ }
39
+ exports.buildDefaultGatewayConfig = buildDefaultGatewayConfig;
@@ -19,6 +19,7 @@ var PortalRequestMethod;
19
19
  PortalRequestMethod["EthSendRawTransaction"] = "eth_sendRawTransaction";
20
20
  PortalRequestMethod["EthSign"] = "eth_sign";
21
21
  PortalRequestMethod["EthSignTransaction"] = "eth_signTransaction";
22
+ PortalRequestMethod["EthSignUserOperation"] = "eth_signUserOperation";
22
23
  PortalRequestMethod["EthSignTypedDataV3"] = "eth_signTypedData_v3";
23
24
  PortalRequestMethod["EthSignTypedDataV4"] = "eth_signTypedData_v4";
24
25
  PortalRequestMethod["PersonalSign"] = "personal_sign";
@@ -77,6 +77,12 @@ const parseRequest = (method, params) => __awaiter(void 0, void 0, void 0, funct
77
77
  data: requestData,
78
78
  };
79
79
  }
80
+ case 'eth_signUserOperation': {
81
+ return {
82
+ method,
83
+ data: txParam0,
84
+ };
85
+ }
80
86
  case 'eth_sign':
81
87
  case 'personal_sign':
82
88
  case 'eth_signTypedData_v3':
@@ -19,6 +19,7 @@ var Events;
19
19
  Events["GetSigningShareMetadata"] = "Get Signing Share Metadata";
20
20
  Events["GetSources"] = "Get Sources";
21
21
  Events["GetTransactions"] = "Get Transactions";
22
+ Events["GetTransactionHistory"] = "Get Transaction History";
22
23
  Events["PrepareClientEject"] = "Prepare Client Eject";
23
24
  Events["SimulateTransaction"] = "Simulate Transaction";
24
25
  Events["EvaluateTransaction"] = "Evaluate Transaction";
@@ -51,6 +52,7 @@ var Events;
51
52
  Events["HypernativeScanURL"] = "Hypernative Scan URL";
52
53
  Events["BlockaidScanEVMTx"] = "Blockaid Scan EVM Transaction";
53
54
  Events["BlockaidScanSolanaTx"] = "Blockaid Scan Solana Transaction";
55
+ Events["BlockaidScanTronTx"] = "Blockaid Scan Tron Transaction";
54
56
  Events["BlockaidScanAddress"] = "Blockaid Scan Address";
55
57
  Events["BlockaidScanTokens"] = "Blockaid Scan Tokens";
56
58
  Events["BlockaidScanURL"] = "Blockaid Scan URL";
@@ -71,5 +73,21 @@ var Events;
71
73
  Events["NoahGetPayoutQuote"] = "Noah Get Payout Quote";
72
74
  Events["NoahInitiatePayout"] = "Noah Initiate Payout";
73
75
  Events["NoahGetPaymentMethods"] = "Noah Get Payment Methods";
76
+ Events["MeldCreateCustomer"] = "Meld Create Customer";
77
+ Events["MeldSearchCustomer"] = "Meld Search Customer";
78
+ Events["MeldGetRetailQuote"] = "Meld Get Retail Quote";
79
+ Events["MeldCreateRetailWidget"] = "Meld Create Retail Widget";
80
+ Events["MeldSearchRetailTransactions"] = "Meld Search Retail Transactions";
81
+ Events["MeldGetRetailTransaction"] = "Meld Get Retail Transaction";
82
+ Events["MeldGetRetailTransactionBySession"] = "Meld Get Retail Transaction By Session";
83
+ Events["MeldGetServiceProviders"] = "Meld Get Service Providers";
84
+ Events["MeldGetCountries"] = "Meld Get Countries";
85
+ Events["MeldGetFiatCurrencies"] = "Meld Get Fiat Currencies";
86
+ Events["MeldGetCryptoCurrencies"] = "Meld Get Crypto Currencies";
87
+ Events["MeldGetPaymentMethods"] = "Meld Get Payment Methods";
88
+ Events["MeldGetDefaults"] = "Meld Get Defaults";
89
+ Events["MeldGetBuyLimits"] = "Meld Get Buy Limits";
90
+ Events["MeldGetSellLimits"] = "Meld Get Sell Limits";
91
+ Events["MeldGetKycLimits"] = "Meld Get Kyc Limits";
74
92
  })(Events || (Events = {}));
75
93
  exports.default = Events;
@@ -3,7 +3,8 @@ 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.sdkLogger = exports.UUID_V4_REGEX = exports.TRACE_ID_HEADER = exports.createExecutionContext = exports.generateTraceId = exports.EvaluateTransactionOperationType = exports.HttpRequester = exports.PortalRequests = exports.HttpRequest = exports.parseRequest = exports.numberToHexString = exports.getClientPlatformVersion = 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.PortalRequestMethod = exports.PasswordStorage = exports.MpcStatuses = exports.KeychainAdapter = exports.convert = exports.convertCryptoToLocal = exports.convertLocalToCrypto = exports.DEFAULT_HOSTS = exports.NAMESPACE_TO_CURVE = exports.ALL_CHAIN_IDS = exports.BITCOIN_CHAIN_IDS = exports.SOLANA_CHAIN_IDS = exports.EVM_CHAIN_IDS = exports.DEFAULT_CHAIN_ID_CAIP2 = exports.DEFAULT_CHAIN_ID_NUMERIC = exports.CAIP2_CHAIN_ID_REGEX = exports.FRIENDLY_CHAIN_NAME_TO_CAIP2 = exports.SUPPORTED_BITCOIN_P2WPKH_CHAINS = exports.CHAIN_NAMESPACES = exports.getChainNameForId = exports.getChainIdForName = exports.chainNameToId = exports.chainIdToName = void 0;
6
+ exports.TRACE_ID_HEADER = exports.createExecutionContext = exports.generateTraceId = exports.EvaluateTransactionOperationType = exports.HttpRequester = exports.PortalRequests = exports.HttpRequest = exports.parseRequest = exports.numberToHexString = exports.getClientPlatformVersion = 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.PortalRequestMethod = exports.PasswordStorage = exports.MpcStatuses = exports.KeychainAdapter = exports.convert = exports.convertCryptoToLocal = exports.convertLocalToCrypto = exports.DEFAULT_HOSTS = exports.buildDefaultGatewayConfig = exports.NAMESPACE_TO_CURVE = exports.ALL_CHAIN_IDS = exports.BITCOIN_CHAIN_IDS = exports.TRON_CHAIN_IDS = exports.SOLANA_CHAIN_IDS = exports.EVM_CHAIN_IDS = exports.DEFAULT_CHAIN_ID_CAIP2 = exports.DEFAULT_CHAIN_ID_NUMERIC = exports.CAIP2_CHAIN_ID_REGEX = exports.FRIENDLY_CHAIN_NAME_TO_CAIP2 = exports.SUPPORTED_BITCOIN_P2WPKH_CHAINS = exports.CHAIN_NAMESPACES = exports.getChainNameForId = exports.getChainIdForName = exports.chainNameToId = exports.chainIdToName = void 0;
7
+ exports.sdkLogger = exports.UUID_V4_REGEX = void 0;
7
8
  var chains_1 = require("./chains");
8
9
  Object.defineProperty(exports, "chainIdToName", { enumerable: true, get: function () { return chains_1.chainIdToName; } });
9
10
  Object.defineProperty(exports, "chainNameToId", { enumerable: true, get: function () { return chains_1.chainNameToId; } });
@@ -17,10 +18,12 @@ Object.defineProperty(exports, "DEFAULT_CHAIN_ID_NUMERIC", { enumerable: true, g
17
18
  Object.defineProperty(exports, "DEFAULT_CHAIN_ID_CAIP2", { enumerable: true, get: function () { return chains_1.DEFAULT_CHAIN_ID_CAIP2; } });
18
19
  Object.defineProperty(exports, "EVM_CHAIN_IDS", { enumerable: true, get: function () { return chains_1.EVM_CHAIN_IDS; } });
19
20
  Object.defineProperty(exports, "SOLANA_CHAIN_IDS", { enumerable: true, get: function () { return chains_1.SOLANA_CHAIN_IDS; } });
21
+ Object.defineProperty(exports, "TRON_CHAIN_IDS", { enumerable: true, get: function () { return chains_1.TRON_CHAIN_IDS; } });
20
22
  Object.defineProperty(exports, "BITCOIN_CHAIN_IDS", { enumerable: true, get: function () { return chains_1.BITCOIN_CHAIN_IDS; } });
21
23
  Object.defineProperty(exports, "ALL_CHAIN_IDS", { enumerable: true, get: function () { return chains_1.ALL_CHAIN_IDS; } });
22
24
  Object.defineProperty(exports, "NAMESPACE_TO_CURVE", { enumerable: true, get: function () { return chains_1.NAMESPACE_TO_CURVE; } });
23
25
  var config_1 = require("./config");
26
+ Object.defineProperty(exports, "buildDefaultGatewayConfig", { enumerable: true, get: function () { return config_1.buildDefaultGatewayConfig; } });
24
27
  Object.defineProperty(exports, "DEFAULT_HOSTS", { enumerable: true, get: function () { return config_1.DEFAULT_HOSTS; } });
25
28
  var currency_1 = require("./currency");
26
29
  Object.defineProperty(exports, "convertLocalToCrypto", { enumerable: true, get: function () { return currency_1.convertLocalToCrypto; } });
@@ -1 +1 @@
1
- { "version": "4.6.0" }
1
+ { "version": "4.8.0" }
@@ -31,11 +31,14 @@ export const SOLANA_CHAIN_IDS = {
31
31
  SOLANA_MAINNET: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
32
32
  SOLANA_DEVNET: 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',
33
33
  };
34
+ export const TRON_CHAIN_IDS = {
35
+ TRON_MAINNET: 'tron:mainnet',
36
+ };
34
37
  export const BITCOIN_CHAIN_IDS = {
35
38
  BITCOIN_P2WPKH_MAINNET: 'bip122:000000000019d6689c085ae165831e93-p2wpkh',
36
39
  BITCOIN_P2WPKH_TESTNET: 'bip122:000000000933ea01ad0ee984209779ba-p2wpkh',
37
40
  };
38
- export const ALL_CHAIN_IDS = Object.assign(Object.assign(Object.assign({}, EVM_CHAIN_IDS), SOLANA_CHAIN_IDS), BITCOIN_CHAIN_IDS);
41
+ export const ALL_CHAIN_IDS = Object.assign(Object.assign(Object.assign(Object.assign({}, EVM_CHAIN_IDS), SOLANA_CHAIN_IDS), BITCOIN_CHAIN_IDS), TRON_CHAIN_IDS);
39
42
  export const FRIENDLY_CHAIN_NAME_TO_CAIP2 = {
40
43
  // EVM chains
41
44
  ethereum: EVM_CHAIN_IDS.ETHEREUM_MAINNET,
@@ -4,3 +4,32 @@ export const DEFAULT_HOSTS = {
4
4
  ENCLAVE_MPC: 'mpc-client.portalhq.io',
5
5
  WEBSOCKET: 'connect.portalhq.io',
6
6
  };
7
+ /**
8
+ * Canonical list of chains covered by the default gateway config. Single
9
+ * source of truth for both `buildDefaultGatewayConfig` and its tests.
10
+ */
11
+ export const SUPPORTED_CHAINS = [
12
+ { namespace: 'eip155', reference: '1' },
13
+ { namespace: 'eip155', reference: '11155111' },
14
+ { namespace: 'eip155', reference: '137' },
15
+ { namespace: 'eip155', reference: '80002' },
16
+ { namespace: 'eip155', reference: '8453' },
17
+ { namespace: 'eip155', reference: '84532' },
18
+ { namespace: 'eip155', reference: '143' },
19
+ { namespace: 'eip155', reference: '10143' },
20
+ { namespace: 'solana', reference: '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' },
21
+ { namespace: 'solana', reference: 'EtWTRABZaYq6iMfeYKouRu166VU2xqa1' },
22
+ ];
23
+ /**
24
+ * Builds a gateway config map for all Portal-supported chains using the given API host.
25
+ * Used as the default when no gatewayConfig is supplied to the Portal constructor.
26
+ */
27
+ export function buildDefaultGatewayConfig(apiHost) {
28
+ const host = apiHost.replace(/\/$/, '');
29
+ const protocol = host.startsWith('localhost') ? 'http' : 'https';
30
+ const base = `${protocol}://${host}/rpc/v1`;
31
+ return SUPPORTED_CHAINS.reduce((config, { namespace, reference }) => {
32
+ config[`${namespace}:${reference}`] = `${base}/${namespace}/${reference}`;
33
+ return config;
34
+ }, {});
35
+ }
@@ -16,6 +16,7 @@ export var PortalRequestMethod;
16
16
  PortalRequestMethod["EthSendRawTransaction"] = "eth_sendRawTransaction";
17
17
  PortalRequestMethod["EthSign"] = "eth_sign";
18
18
  PortalRequestMethod["EthSignTransaction"] = "eth_signTransaction";
19
+ PortalRequestMethod["EthSignUserOperation"] = "eth_signUserOperation";
19
20
  PortalRequestMethod["EthSignTypedDataV3"] = "eth_signTypedData_v3";
20
21
  PortalRequestMethod["EthSignTypedDataV4"] = "eth_signTypedData_v4";
21
22
  PortalRequestMethod["PersonalSign"] = "personal_sign";
@@ -70,6 +70,12 @@ export const parseRequest = (method, params) => __awaiter(void 0, void 0, void 0
70
70
  data: requestData,
71
71
  };
72
72
  }
73
+ case 'eth_signUserOperation': {
74
+ return {
75
+ method,
76
+ data: txParam0,
77
+ };
78
+ }
73
79
  case 'eth_sign':
74
80
  case 'personal_sign':
75
81
  case 'eth_signTypedData_v3':
@@ -17,6 +17,7 @@ var Events;
17
17
  Events["GetSigningShareMetadata"] = "Get Signing Share Metadata";
18
18
  Events["GetSources"] = "Get Sources";
19
19
  Events["GetTransactions"] = "Get Transactions";
20
+ Events["GetTransactionHistory"] = "Get Transaction History";
20
21
  Events["PrepareClientEject"] = "Prepare Client Eject";
21
22
  Events["SimulateTransaction"] = "Simulate Transaction";
22
23
  Events["EvaluateTransaction"] = "Evaluate Transaction";
@@ -49,6 +50,7 @@ var Events;
49
50
  Events["HypernativeScanURL"] = "Hypernative Scan URL";
50
51
  Events["BlockaidScanEVMTx"] = "Blockaid Scan EVM Transaction";
51
52
  Events["BlockaidScanSolanaTx"] = "Blockaid Scan Solana Transaction";
53
+ Events["BlockaidScanTronTx"] = "Blockaid Scan Tron Transaction";
52
54
  Events["BlockaidScanAddress"] = "Blockaid Scan Address";
53
55
  Events["BlockaidScanTokens"] = "Blockaid Scan Tokens";
54
56
  Events["BlockaidScanURL"] = "Blockaid Scan URL";
@@ -69,5 +71,21 @@ var Events;
69
71
  Events["NoahGetPayoutQuote"] = "Noah Get Payout Quote";
70
72
  Events["NoahInitiatePayout"] = "Noah Initiate Payout";
71
73
  Events["NoahGetPaymentMethods"] = "Noah Get Payment Methods";
74
+ Events["MeldCreateCustomer"] = "Meld Create Customer";
75
+ Events["MeldSearchCustomer"] = "Meld Search Customer";
76
+ Events["MeldGetRetailQuote"] = "Meld Get Retail Quote";
77
+ Events["MeldCreateRetailWidget"] = "Meld Create Retail Widget";
78
+ Events["MeldSearchRetailTransactions"] = "Meld Search Retail Transactions";
79
+ Events["MeldGetRetailTransaction"] = "Meld Get Retail Transaction";
80
+ Events["MeldGetRetailTransactionBySession"] = "Meld Get Retail Transaction By Session";
81
+ Events["MeldGetServiceProviders"] = "Meld Get Service Providers";
82
+ Events["MeldGetCountries"] = "Meld Get Countries";
83
+ Events["MeldGetFiatCurrencies"] = "Meld Get Fiat Currencies";
84
+ Events["MeldGetCryptoCurrencies"] = "Meld Get Crypto Currencies";
85
+ Events["MeldGetPaymentMethods"] = "Meld Get Payment Methods";
86
+ Events["MeldGetDefaults"] = "Meld Get Defaults";
87
+ Events["MeldGetBuyLimits"] = "Meld Get Buy Limits";
88
+ Events["MeldGetSellLimits"] = "Meld Get Sell Limits";
89
+ Events["MeldGetKycLimits"] = "Meld Get Kyc Limits";
72
90
  })(Events || (Events = {}));
73
91
  export default Events;
package/lib/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export { chainIdToName, chainNameToId, getChainIdForName, getChainNameForId, CHAIN_NAMESPACES, SUPPORTED_BITCOIN_P2WPKH_CHAINS, FRIENDLY_CHAIN_NAME_TO_CAIP2, CAIP2_CHAIN_ID_REGEX, DEFAULT_CHAIN_ID_NUMERIC, DEFAULT_CHAIN_ID_CAIP2, EVM_CHAIN_IDS, SOLANA_CHAIN_IDS, BITCOIN_CHAIN_IDS, ALL_CHAIN_IDS, NAMESPACE_TO_CURVE, } from './chains';
2
- export { DEFAULT_HOSTS } from './config';
1
+ export { chainIdToName, chainNameToId, getChainIdForName, getChainNameForId, CHAIN_NAMESPACES, SUPPORTED_BITCOIN_P2WPKH_CHAINS, FRIENDLY_CHAIN_NAME_TO_CAIP2, CAIP2_CHAIN_ID_REGEX, DEFAULT_CHAIN_ID_NUMERIC, DEFAULT_CHAIN_ID_CAIP2, EVM_CHAIN_IDS, SOLANA_CHAIN_IDS, TRON_CHAIN_IDS, BITCOIN_CHAIN_IDS, ALL_CHAIN_IDS, NAMESPACE_TO_CURVE, } from './chains';
2
+ export { buildDefaultGatewayConfig, DEFAULT_HOSTS } from './config';
3
3
  export { convertLocalToCrypto, convertCryptoToLocal, convert } from './currency';
4
4
  export { KeychainAdapter, MpcStatuses, PasswordStorage, PortalRequestMethod, Storage, } from './definitions';
5
5
  export { CloudStorageReadError, HttpError, InvalidApiKeyError, InvalidChainIdError, InvalidGatewayConfigError, MissingOptionError, MpcSigningError, NoAddressError, PortalErrorCodes, PortalErrorCodeTypes, PortalMpcError, ProviderRpcError, RpcErrorCodes, } from './errors';
@@ -1 +1 @@
1
- { "version": "4.6.0" }
1
+ { "version": "4.8.0" }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portal-hq/utils",
3
- "version": "4.6.0",
3
+ "version": "4.8.0",
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": "81e3ade6164a87aa8fc8942af4c770d04f73bc55"
29
+ "gitHead": "c67b5068d5245eeab6b760ee01298d88965bf386"
30
30
  }
@@ -38,6 +38,10 @@ export const SOLANA_CHAIN_IDS = {
38
38
  SOLANA_DEVNET: 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',
39
39
  } as const
40
40
 
41
+ export const TRON_CHAIN_IDS = {
42
+ TRON_MAINNET: 'tron:mainnet',
43
+ } as const
44
+
41
45
  export const BITCOIN_CHAIN_IDS = {
42
46
  BITCOIN_P2WPKH_MAINNET: 'bip122:000000000019d6689c085ae165831e93-p2wpkh',
43
47
  BITCOIN_P2WPKH_TESTNET: 'bip122:000000000933ea01ad0ee984209779ba-p2wpkh',
@@ -47,6 +51,7 @@ export const ALL_CHAIN_IDS = {
47
51
  ...EVM_CHAIN_IDS,
48
52
  ...SOLANA_CHAIN_IDS,
49
53
  ...BITCOIN_CHAIN_IDS,
54
+ ...TRON_CHAIN_IDS,
50
55
  } as const
51
56
 
52
57
  export const FRIENDLY_CHAIN_NAME_TO_CAIP2 = {
@@ -4,3 +4,42 @@ export const DEFAULT_HOSTS = {
4
4
  ENCLAVE_MPC: 'mpc-client.portalhq.io',
5
5
  WEBSOCKET: 'connect.portalhq.io',
6
6
  } as const
7
+
8
+ /**
9
+ * Canonical list of chains covered by the default gateway config. Single
10
+ * source of truth for both `buildDefaultGatewayConfig` and its tests.
11
+ */
12
+ export const SUPPORTED_CHAINS: ReadonlyArray<{
13
+ namespace: string
14
+ reference: string
15
+ }> = [
16
+ { namespace: 'eip155', reference: '1' },
17
+ { namespace: 'eip155', reference: '11155111' },
18
+ { namespace: 'eip155', reference: '137' },
19
+ { namespace: 'eip155', reference: '80002' },
20
+ { namespace: 'eip155', reference: '8453' },
21
+ { namespace: 'eip155', reference: '84532' },
22
+ { namespace: 'eip155', reference: '143' },
23
+ { namespace: 'eip155', reference: '10143' },
24
+ { namespace: 'solana', reference: '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' },
25
+ { namespace: 'solana', reference: 'EtWTRABZaYq6iMfeYKouRu166VU2xqa1' },
26
+ ]
27
+
28
+ /**
29
+ * Builds a gateway config map for all Portal-supported chains using the given API host.
30
+ * Used as the default when no gatewayConfig is supplied to the Portal constructor.
31
+ */
32
+ export function buildDefaultGatewayConfig(
33
+ apiHost: string,
34
+ ): Record<string, string> {
35
+ const host = apiHost.replace(/\/$/, '')
36
+ const protocol = host.startsWith('localhost') ? 'http' : 'https'
37
+ const base = `${protocol}://${host}/rpc/v1`
38
+ return SUPPORTED_CHAINS.reduce<Record<string, string>>(
39
+ (config, { namespace, reference }) => {
40
+ config[`${namespace}:${reference}`] = `${base}/${namespace}/${reference}`
41
+ return config
42
+ },
43
+ {},
44
+ )
45
+ }
@@ -9,6 +9,7 @@ import {
9
9
  BuildSolanaTransactionResponse,
10
10
  FundParams,
11
11
  FundResponse,
12
+ NFTAsset,
12
13
  YieldXyzEnterRequest,
13
14
  YieldXyzEnterYieldResponse,
14
15
  YieldXyzExitRequest,
@@ -38,6 +39,8 @@ import type {
38
39
  Dapp,
39
40
  EvaluateTransactionParam,
40
41
  GenerateResponse,
42
+ GetTransactionHistoryParams,
43
+ GetTransactionHistoryResponse,
41
44
  GetTransactionsOrder,
42
45
  NFT,
43
46
  Network,
@@ -102,6 +105,7 @@ export enum PortalRequestMethod {
102
105
  EthSendRawTransaction = 'eth_sendRawTransaction',
103
106
  EthSign = 'eth_sign',
104
107
  EthSignTransaction = 'eth_signTransaction',
108
+ EthSignUserOperation = 'eth_signUserOperation',
105
109
  EthSignTypedDataV3 = 'eth_signTypedData_v3',
106
110
  EthSignTypedDataV4 = 'eth_signTypedData_v4',
107
111
  PersonalSign = 'personal_sign',
@@ -233,6 +237,7 @@ export interface IPortalApi {
233
237
  getClientCipherText(backupSharePairId: string): Promise<string>
234
238
  getEnabledDapps(): Promise<Dapp[]>
235
239
  getNFTs(chainId?: string, traceId?: string): Promise<NFT[]>
240
+ getNftAssets(chainId: string, traceId?: string): Promise<NFTAsset[]>
236
241
  getNetworks(): Promise<Network[]>
237
242
  getQuote(
238
243
  apiKey: string,
@@ -250,6 +255,10 @@ export interface IPortalApi {
250
255
  order?: GetTransactionsOrder,
251
256
  traceId?: string,
252
257
  ): Promise<Transaction[]>
258
+ getTransactionHistory(
259
+ params: GetTransactionHistoryParams,
260
+ traceId?: string,
261
+ ): Promise<GetTransactionHistoryResponse>
253
262
  prepareClientEject(
254
263
  walletId: string,
255
264
  backupMethod: BackupMethodsUpperCase,
@@ -279,6 +288,7 @@ export interface IPortalApi {
279
288
  | 'ICLOUD'
280
289
  | 'PASSKEY'
281
290
  | 'PASSWORD'
291
+ | 'FIREBASE'
282
292
  | 'UNKNOWN',
283
293
  ): Promise<void>
284
294
  storedClientBackupShareKey(
@@ -287,6 +297,7 @@ export interface IPortalApi {
287
297
  | 'CUSTOM'
288
298
  | 'GDRIVE'
289
299
  | 'ICLOUD'
300
+ | 'FIREBASE'
290
301
  | 'PASSKEY'
291
302
  | 'PASSWORD'
292
303
  | 'UNKNOWN',
@@ -327,10 +338,12 @@ export interface IPortalApi {
327
338
  buildBitcoinP2wpkhTransaction(
328
339
  chainId: string,
329
340
  params: { to: string; token: string; amount: string },
341
+ traceId?: string,
330
342
  ): Promise<BuildBitcoinP2wpkhTransactionResponse>
331
343
  broadcastBitcoinP2wpkhTransaction(
332
344
  chainId: string,
333
345
  params: BroadcastParam,
346
+ traceId?: string,
334
347
  ): Promise<BroadcastBitcoinP2wpkhTransactionResponse>
335
348
  rawSign?(
336
349
  message: string,
@@ -552,3 +565,10 @@ export class PasswordStorage implements Storage {
552
565
  })
553
566
  }
554
567
  }
568
+ export type BackupMethod =
569
+ | 'PASSWORD'
570
+ | 'PASSKEY'
571
+ | 'GDRIVE'
572
+ | 'ICLOUD'
573
+ | 'CUSTOM'
574
+ | 'FIREBASE'
@@ -3,6 +3,7 @@ import {
3
3
  type OutgoingRequest,
4
4
  type OutgoingRequestData,
5
5
  type SignableTransactionData,
6
+ type UserOperation,
6
7
  } from '../../types'
7
8
  import { convert } from '../currency'
8
9
 
@@ -95,6 +96,12 @@ export const parseRequest = async (
95
96
  data: requestData,
96
97
  }
97
98
  }
99
+ case 'eth_signUserOperation': {
100
+ return {
101
+ method,
102
+ data: txParam0 as UserOperation,
103
+ }
104
+ }
98
105
  case 'eth_sign':
99
106
  case 'personal_sign':
100
107
  case 'eth_signTypedData_v3':
@@ -17,6 +17,7 @@ enum Events {
17
17
  GetSigningShareMetadata = 'Get Signing Share Metadata',
18
18
  GetSources = 'Get Sources',
19
19
  GetTransactions = 'Get Transactions',
20
+ GetTransactionHistory = 'Get Transaction History',
20
21
  PrepareClientEject = 'Prepare Client Eject',
21
22
  SimulateTransaction = 'Simulate Transaction',
22
23
  EvaluateTransaction = 'Evaluate Transaction',
@@ -52,6 +53,7 @@ enum Events {
52
53
 
53
54
  BlockaidScanEVMTx = 'Blockaid Scan EVM Transaction',
54
55
  BlockaidScanSolanaTx = 'Blockaid Scan Solana Transaction',
56
+ BlockaidScanTronTx = 'Blockaid Scan Tron Transaction',
55
57
  BlockaidScanAddress = 'Blockaid Scan Address',
56
58
  BlockaidScanTokens = 'Blockaid Scan Tokens',
57
59
  BlockaidScanURL = 'Blockaid Scan URL',
@@ -75,6 +77,23 @@ enum Events {
75
77
  NoahGetPayoutQuote = 'Noah Get Payout Quote',
76
78
  NoahInitiatePayout = 'Noah Initiate Payout',
77
79
  NoahGetPaymentMethods = 'Noah Get Payment Methods',
80
+
81
+ MeldCreateCustomer = 'Meld Create Customer',
82
+ MeldSearchCustomer = 'Meld Search Customer',
83
+ MeldGetRetailQuote = 'Meld Get Retail Quote',
84
+ MeldCreateRetailWidget = 'Meld Create Retail Widget',
85
+ MeldSearchRetailTransactions = 'Meld Search Retail Transactions',
86
+ MeldGetRetailTransaction = 'Meld Get Retail Transaction',
87
+ MeldGetRetailTransactionBySession = 'Meld Get Retail Transaction By Session',
88
+ MeldGetServiceProviders = 'Meld Get Service Providers',
89
+ MeldGetCountries = 'Meld Get Countries',
90
+ MeldGetFiatCurrencies = 'Meld Get Fiat Currencies',
91
+ MeldGetCryptoCurrencies = 'Meld Get Crypto Currencies',
92
+ MeldGetPaymentMethods = 'Meld Get Payment Methods',
93
+ MeldGetDefaults = 'Meld Get Defaults',
94
+ MeldGetBuyLimits = 'Meld Get Buy Limits',
95
+ MeldGetSellLimits = 'Meld Get Sell Limits',
96
+ MeldGetKycLimits = 'Meld Get Kyc Limits',
78
97
  }
79
98
 
80
99
  export default Events
package/src/index.ts CHANGED
@@ -11,6 +11,7 @@ export {
11
11
  DEFAULT_CHAIN_ID_CAIP2,
12
12
  EVM_CHAIN_IDS,
13
13
  SOLANA_CHAIN_IDS,
14
+ TRON_CHAIN_IDS,
14
15
  BITCOIN_CHAIN_IDS,
15
16
  ALL_CHAIN_IDS,
16
17
  NAMESPACE_TO_CURVE,
@@ -18,7 +19,7 @@ export {
18
19
  type FriendlyChainName,
19
20
  } from './chains'
20
21
 
21
- export { DEFAULT_HOSTS } from './config'
22
+ export { buildDefaultGatewayConfig, DEFAULT_HOSTS } from './config'
22
23
 
23
24
  export { convertLocalToCrypto, convertCryptoToLocal, convert } from './currency'
24
25
 
@@ -91,6 +92,8 @@ export type {
91
92
  DappOnNetwork,
92
93
  DkgData,
93
94
  EvaluateTransactionParam,
95
+ GetTransactionHistoryParams,
96
+ GetTransactionHistoryResponse,
94
97
  GetTransactionsOrder,
95
98
  HttpOptions,
96
99
  HttpRequestOptions,
@@ -105,6 +108,9 @@ export type {
105
108
  SignableTransactionData,
106
109
  SigningRequestArguments,
107
110
  SigningResponse,
111
+ SolanaTransactionDetails,
108
112
  Transaction,
113
+ TransactionHistoryItem,
114
+ UserOperation,
109
115
  Shares,
110
116
  } from '../types'
@@ -1 +1 @@
1
- { "version": "4.6.0" }
1
+ { "version": "4.8.0" }
package/types.d.ts CHANGED
@@ -7,7 +7,10 @@ import {
7
7
 
8
8
  import { MpcStatuses } from './src/definitions'
9
9
 
10
- export type OutgoingRequestData = MessageData | SignableTransactionData
10
+ export type OutgoingRequestData =
11
+ | MessageData
12
+ | SignableTransactionData
13
+ | UserOperation
11
14
 
12
15
  export type ProgressCallback = (status: MpcStatus) => void | Promise<void>
13
16
 
@@ -320,6 +323,7 @@ export enum GetTransactionsOrder {
320
323
  DESC = 'desc',
321
324
  }
322
325
 
326
+ /** @deprecated Use TransactionHistoryItem instead */
323
327
  export interface Transaction {
324
328
  asset: string
325
329
  blockNum: string
@@ -343,6 +347,198 @@ export interface Transaction {
343
347
  value: number
344
348
  }
345
349
 
350
+ export type SolanaError =
351
+ | string
352
+ | {
353
+ code?: string | number
354
+ message?: string
355
+ data?: unknown
356
+ }
357
+ | null
358
+
359
+ export interface SolanaTransactionInstruction {
360
+ accounts: number[]
361
+ data: string
362
+ programIdIndex: number
363
+ stackHeight?: number
364
+ parsed?: unknown
365
+ program?: string
366
+ programId?: string
367
+ }
368
+
369
+ export interface SolanaTokenBalance {
370
+ accountIndex: number
371
+ mint: string
372
+ owner?: string
373
+ programId?: string
374
+ uiTokenAmount?: {
375
+ amount: string
376
+ decimals: number
377
+ uiAmount: number | null
378
+ uiAmountString: string
379
+ }
380
+ }
381
+
382
+ export interface SolanaInnerInstruction {
383
+ index: number
384
+ instructions: Array<{
385
+ accounts: number[]
386
+ data: string
387
+ programIdIndex: number
388
+ parsed?: unknown
389
+ }>
390
+ }
391
+
392
+ export interface SolanaReward {
393
+ pubkey: string
394
+ lamports: number
395
+ postBalance: number
396
+ rewardType: string | null
397
+ commission: number | null
398
+ }
399
+
400
+ interface BaseTransactionHistoryItem {
401
+ hash: string
402
+ from: string
403
+ to: string | null
404
+ value: string
405
+ blockNumber: string | null
406
+ blockTimestamp: number | null
407
+ status: string | null
408
+ chainId: string
409
+ }
410
+
411
+ export interface RegularTransaction extends BaseTransactionHistoryItem {
412
+ type: 'transaction'
413
+ asset?: string
414
+ tokenAddress?: string
415
+ tokenDecimals?: number
416
+ userOpHash?: never
417
+ entryPoint?: never
418
+ actualGasCost?: never
419
+ actualGasUsed?: never
420
+ }
421
+
422
+ export interface UserOperation {
423
+ sender: string
424
+ nonce: string
425
+ initCode: string
426
+ callData: string
427
+ callGasLimit: string
428
+ verificationGasLimit: string
429
+ preVerificationGas: string
430
+ maxFeePerGas: string
431
+ maxPriorityFeePerGas: string
432
+ paymasterAndData: string
433
+ signature: string
434
+ }
435
+
436
+ export interface UserOperationTransaction extends BaseTransactionHistoryItem {
437
+ type: 'userOperation'
438
+ to: null
439
+ value: '0'
440
+ userOpHash: string
441
+ entryPoint: string
442
+ actualGasCost?: string
443
+ actualGasUsed?: string
444
+ asset?: never
445
+ tokenAddress?: never
446
+ tokenDecimals?: never
447
+ }
448
+
449
+ export type TransactionHistoryItem =
450
+ | RegularTransaction
451
+ | UserOperationTransaction
452
+
453
+ export interface SolanaTransactionDetails {
454
+ blockTime: number
455
+ error: SolanaError
456
+ signature: string
457
+ status: string
458
+ tokenMint: string | null
459
+ transactionDetails: {
460
+ transaction: {
461
+ message: {
462
+ accountKeys: string[]
463
+ header: {
464
+ numRequiredSignatures: number
465
+ numReadonlySignedAccounts: number
466
+ numReadonlyUnsignedAccounts: number
467
+ }
468
+ instructions: SolanaTransactionInstruction[]
469
+ recentBlockhash: string
470
+ }
471
+ signatures: string[]
472
+ } | null
473
+ signatureDetails: {
474
+ blockTime: number
475
+ confirmationStatus: string
476
+ error: SolanaError
477
+ memo: string | null
478
+ signature: string
479
+ slot: number
480
+ } | null
481
+ metadata: {
482
+ blockTime: number | null
483
+ slot: number | null
484
+ error: SolanaError
485
+ fee: number | null
486
+ innerInstructions?: SolanaInnerInstruction[] | null
487
+ loadedAddresses?: {
488
+ readonly: string[]
489
+ writable: string[]
490
+ } | null
491
+ logMessages: string[] | null
492
+ postBalances: number[] | null
493
+ postTokenBalances?: SolanaTokenBalance[] | null
494
+ preBalances: number[] | null
495
+ preTokenBalances?: SolanaTokenBalance[] | null
496
+ rewards?: SolanaReward[] | null
497
+ status: {
498
+ Ok?: null | unknown
499
+ Err?: unknown
500
+ } | null
501
+ version: 'legacy' | number | null
502
+ } | null
503
+ } | null
504
+ }
505
+
506
+ export interface GetTransactionHistoryParams {
507
+ chainId: string
508
+ limit?: number
509
+ offset?: number
510
+ order?: 'asc' | 'desc'
511
+ address?: string
512
+ userOperations?: 'include' | 'only' | 'exclude'
513
+ }
514
+
515
+ export interface GetTransactionHistoryMetadata {
516
+ address: string
517
+ chainId: string
518
+ clientId: string
519
+ limit: number
520
+ offset: number
521
+ count: number
522
+ }
523
+
524
+ export interface SolanaTransactionsResponse {
525
+ data: {
526
+ transactions: SolanaTransactionDetails[]
527
+ }
528
+ metadata: GetTransactionHistoryMetadata
529
+ }
530
+
531
+ export interface UnifiedTransactionsResponse {
532
+ data: {
533
+ transactions: TransactionHistoryItem[]
534
+ }
535
+ metadata: GetTransactionHistoryMetadata
536
+ }
537
+
538
+ export type GetTransactionHistoryResponse =
539
+ | SolanaTransactionsResponse
540
+ | UnifiedTransactionsResponse
541
+
346
542
  export interface SimulateTransactionParam {
347
543
  to: string
348
544
  value?: string