@portal-hq/utils 4.7.0 → 4.9.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.
- package/lib/commonjs/chains/index.js +5 -2
- package/lib/commonjs/config/index.js +31 -1
- package/lib/commonjs/errors/http-error.js +1 -0
- package/lib/commonjs/events/index.js +19 -0
- package/lib/commonjs/index.js +4 -1
- package/lib/commonjs/version/version.json +1 -1
- package/lib/esm/chains/index.js +4 -1
- package/lib/esm/config/index.js +29 -0
- package/lib/esm/errors/http-error.js +1 -0
- package/lib/esm/events/index.js +19 -0
- package/lib/esm/index.js +2 -2
- package/lib/esm/version/version.json +1 -1
- package/package.json +2 -2
- package/src/chains/index.ts +5 -0
- package/src/config/index.ts +39 -0
- package/src/definitions/index.ts +9 -0
- package/src/errors/http-error.ts +5 -0
- package/src/events/index.ts +21 -0
- package/src/index.ts +2 -1
- package/src/version/version.json +1 -1
|
@@ -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;
|
|
@@ -52,6 +52,7 @@ var Events;
|
|
|
52
52
|
Events["HypernativeScanURL"] = "Hypernative Scan URL";
|
|
53
53
|
Events["BlockaidScanEVMTx"] = "Blockaid Scan EVM Transaction";
|
|
54
54
|
Events["BlockaidScanSolanaTx"] = "Blockaid Scan Solana Transaction";
|
|
55
|
+
Events["BlockaidScanTronTx"] = "Blockaid Scan Tron Transaction";
|
|
55
56
|
Events["BlockaidScanAddress"] = "Blockaid Scan Address";
|
|
56
57
|
Events["BlockaidScanTokens"] = "Blockaid Scan Tokens";
|
|
57
58
|
Events["BlockaidScanURL"] = "Blockaid Scan URL";
|
|
@@ -63,6 +64,8 @@ var Events;
|
|
|
63
64
|
Events["EvmAccountType7702BuildAuthorizationList"] = "Evm Account Type 7702 BuildAuthorizationList";
|
|
64
65
|
Events["EvmAccountType7702BuildUpgradeTx"] = "Evm Account Type 7702 BuildUpgradeTx";
|
|
65
66
|
Events["EvmAccountType7702Upgrade"] = "Evm Account Type 7702 Upgrade";
|
|
67
|
+
Events["UserOperationsBuildBatched"] = "UserOperations BuildBatched";
|
|
68
|
+
Events["UserOperationsBroadcastBatched"] = "UserOperations BroadcastBatched";
|
|
66
69
|
Events["NoahInitiateKyc"] = "Noah Initiate KYC";
|
|
67
70
|
Events["NoahInitiatePayin"] = "Noah Initiate Payin";
|
|
68
71
|
Events["NoahSimulatePayin"] = "Noah Simulate Payin";
|
|
@@ -72,5 +75,21 @@ var Events;
|
|
|
72
75
|
Events["NoahGetPayoutQuote"] = "Noah Get Payout Quote";
|
|
73
76
|
Events["NoahInitiatePayout"] = "Noah Initiate Payout";
|
|
74
77
|
Events["NoahGetPaymentMethods"] = "Noah Get Payment Methods";
|
|
78
|
+
Events["MeldCreateCustomer"] = "Meld Create Customer";
|
|
79
|
+
Events["MeldSearchCustomer"] = "Meld Search Customer";
|
|
80
|
+
Events["MeldGetRetailQuote"] = "Meld Get Retail Quote";
|
|
81
|
+
Events["MeldCreateRetailWidget"] = "Meld Create Retail Widget";
|
|
82
|
+
Events["MeldSearchRetailTransactions"] = "Meld Search Retail Transactions";
|
|
83
|
+
Events["MeldGetRetailTransaction"] = "Meld Get Retail Transaction";
|
|
84
|
+
Events["MeldGetRetailTransactionBySession"] = "Meld Get Retail Transaction By Session";
|
|
85
|
+
Events["MeldGetServiceProviders"] = "Meld Get Service Providers";
|
|
86
|
+
Events["MeldGetCountries"] = "Meld Get Countries";
|
|
87
|
+
Events["MeldGetFiatCurrencies"] = "Meld Get Fiat Currencies";
|
|
88
|
+
Events["MeldGetCryptoCurrencies"] = "Meld Get Crypto Currencies";
|
|
89
|
+
Events["MeldGetPaymentMethods"] = "Meld Get Payment Methods";
|
|
90
|
+
Events["MeldGetDefaults"] = "Meld Get Defaults";
|
|
91
|
+
Events["MeldGetBuyLimits"] = "Meld Get Buy Limits";
|
|
92
|
+
Events["MeldGetSellLimits"] = "Meld Get Sell Limits";
|
|
93
|
+
Events["MeldGetKycLimits"] = "Meld Get Kyc Limits";
|
|
75
94
|
})(Events || (Events = {}));
|
|
76
95
|
exports.default = Events;
|
package/lib/commonjs/index.js
CHANGED
|
@@ -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.
|
|
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.
|
|
1
|
+
{ "version": "4.9.0" }
|
package/lib/esm/chains/index.js
CHANGED
|
@@ -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,
|
package/lib/esm/config/index.js
CHANGED
|
@@ -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
|
+
}
|
package/lib/esm/events/index.js
CHANGED
|
@@ -50,6 +50,7 @@ var Events;
|
|
|
50
50
|
Events["HypernativeScanURL"] = "Hypernative Scan URL";
|
|
51
51
|
Events["BlockaidScanEVMTx"] = "Blockaid Scan EVM Transaction";
|
|
52
52
|
Events["BlockaidScanSolanaTx"] = "Blockaid Scan Solana Transaction";
|
|
53
|
+
Events["BlockaidScanTronTx"] = "Blockaid Scan Tron Transaction";
|
|
53
54
|
Events["BlockaidScanAddress"] = "Blockaid Scan Address";
|
|
54
55
|
Events["BlockaidScanTokens"] = "Blockaid Scan Tokens";
|
|
55
56
|
Events["BlockaidScanURL"] = "Blockaid Scan URL";
|
|
@@ -61,6 +62,8 @@ var Events;
|
|
|
61
62
|
Events["EvmAccountType7702BuildAuthorizationList"] = "Evm Account Type 7702 BuildAuthorizationList";
|
|
62
63
|
Events["EvmAccountType7702BuildUpgradeTx"] = "Evm Account Type 7702 BuildUpgradeTx";
|
|
63
64
|
Events["EvmAccountType7702Upgrade"] = "Evm Account Type 7702 Upgrade";
|
|
65
|
+
Events["UserOperationsBuildBatched"] = "UserOperations BuildBatched";
|
|
66
|
+
Events["UserOperationsBroadcastBatched"] = "UserOperations BroadcastBatched";
|
|
64
67
|
Events["NoahInitiateKyc"] = "Noah Initiate KYC";
|
|
65
68
|
Events["NoahInitiatePayin"] = "Noah Initiate Payin";
|
|
66
69
|
Events["NoahSimulatePayin"] = "Noah Simulate Payin";
|
|
@@ -70,5 +73,21 @@ var Events;
|
|
|
70
73
|
Events["NoahGetPayoutQuote"] = "Noah Get Payout Quote";
|
|
71
74
|
Events["NoahInitiatePayout"] = "Noah Initiate Payout";
|
|
72
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";
|
|
73
92
|
})(Events || (Events = {}));
|
|
74
93
|
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.
|
|
1
|
+
{ "version": "4.9.0" }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portal-hq/utils",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.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": "
|
|
29
|
+
"gitHead": "e4a470a7df8ccc90ff074f1e67d7d23bf436cbdc"
|
|
30
30
|
}
|
package/src/chains/index.ts
CHANGED
|
@@ -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 = {
|
package/src/config/index.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/definitions/index.ts
CHANGED
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
BuildSolanaTransactionResponse,
|
|
10
10
|
FundParams,
|
|
11
11
|
FundResponse,
|
|
12
|
+
GenerateApiResponse,
|
|
13
|
+
NFTAsset,
|
|
12
14
|
YieldXyzEnterRequest,
|
|
13
15
|
YieldXyzEnterYieldResponse,
|
|
14
16
|
YieldXyzExitRequest,
|
|
@@ -230,12 +232,17 @@ export interface IPortalApi {
|
|
|
230
232
|
traceId?: string,
|
|
231
233
|
): Promise<BuildEip155TransactionResponse | BuildSolanaTransactionResponse>
|
|
232
234
|
fund(chainId: string, params: FundParams): Promise<FundResponse>
|
|
235
|
+
generatePreGeneratedShares(
|
|
236
|
+
metadataStr: string,
|
|
237
|
+
traceId?: string,
|
|
238
|
+
): Promise<GenerateApiResponse>
|
|
233
239
|
getBackupSharesMetadata(chainId?: string): Promise<BackupSharePairMetadata[]>
|
|
234
240
|
getBalances(chainId?: string, traceId?: string): Promise<Balance[]>
|
|
235
241
|
getClient(traceId?: string): Promise<ClientResponse>
|
|
236
242
|
getClientCipherText(backupSharePairId: string): Promise<string>
|
|
237
243
|
getEnabledDapps(): Promise<Dapp[]>
|
|
238
244
|
getNFTs(chainId?: string, traceId?: string): Promise<NFT[]>
|
|
245
|
+
getNftAssets(chainId: string, traceId?: string): Promise<NFTAsset[]>
|
|
239
246
|
getNetworks(): Promise<Network[]>
|
|
240
247
|
getQuote(
|
|
241
248
|
apiKey: string,
|
|
@@ -336,10 +343,12 @@ export interface IPortalApi {
|
|
|
336
343
|
buildBitcoinP2wpkhTransaction(
|
|
337
344
|
chainId: string,
|
|
338
345
|
params: { to: string; token: string; amount: string },
|
|
346
|
+
traceId?: string,
|
|
339
347
|
): Promise<BuildBitcoinP2wpkhTransactionResponse>
|
|
340
348
|
broadcastBitcoinP2wpkhTransaction(
|
|
341
349
|
chainId: string,
|
|
342
350
|
params: BroadcastParam,
|
|
351
|
+
traceId?: string,
|
|
343
352
|
): Promise<BroadcastBitcoinP2wpkhTransactionResponse>
|
|
344
353
|
rawSign?(
|
|
345
354
|
message: string,
|
package/src/errors/http-error.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { type HttpErrorOptions } from '../../types'
|
|
2
2
|
|
|
3
3
|
class HttpError extends Error {
|
|
4
|
+
/** The HTTP status code that produced this error, so callers can distinguish retryable (5xx) from terminal (4xx) failures. */
|
|
5
|
+
public status: number
|
|
6
|
+
|
|
4
7
|
constructor({ message, status, statusText }: HttpErrorOptions) {
|
|
5
8
|
super(`${status} - ${statusText}: ${message}`)
|
|
6
9
|
|
|
7
10
|
// Set the prototype explicitly.
|
|
8
11
|
Object.setPrototypeOf(this, HttpError.prototype)
|
|
12
|
+
|
|
13
|
+
this.status = status
|
|
9
14
|
}
|
|
10
15
|
}
|
|
11
16
|
|
package/src/events/index.ts
CHANGED
|
@@ -53,6 +53,7 @@ enum Events {
|
|
|
53
53
|
|
|
54
54
|
BlockaidScanEVMTx = 'Blockaid Scan EVM Transaction',
|
|
55
55
|
BlockaidScanSolanaTx = 'Blockaid Scan Solana Transaction',
|
|
56
|
+
BlockaidScanTronTx = 'Blockaid Scan Tron Transaction',
|
|
56
57
|
BlockaidScanAddress = 'Blockaid Scan Address',
|
|
57
58
|
BlockaidScanTokens = 'Blockaid Scan Tokens',
|
|
58
59
|
BlockaidScanURL = 'Blockaid Scan URL',
|
|
@@ -67,6 +68,9 @@ enum Events {
|
|
|
67
68
|
EvmAccountType7702BuildUpgradeTx = 'Evm Account Type 7702 BuildUpgradeTx',
|
|
68
69
|
EvmAccountType7702Upgrade = 'Evm Account Type 7702 Upgrade',
|
|
69
70
|
|
|
71
|
+
UserOperationsBuildBatched = 'UserOperations BuildBatched',
|
|
72
|
+
UserOperationsBroadcastBatched = 'UserOperations BroadcastBatched',
|
|
73
|
+
|
|
70
74
|
NoahInitiateKyc = 'Noah Initiate KYC',
|
|
71
75
|
NoahInitiatePayin = 'Noah Initiate Payin',
|
|
72
76
|
NoahSimulatePayin = 'Noah Simulate Payin',
|
|
@@ -76,6 +80,23 @@ enum Events {
|
|
|
76
80
|
NoahGetPayoutQuote = 'Noah Get Payout Quote',
|
|
77
81
|
NoahInitiatePayout = 'Noah Initiate Payout',
|
|
78
82
|
NoahGetPaymentMethods = 'Noah Get Payment Methods',
|
|
83
|
+
|
|
84
|
+
MeldCreateCustomer = 'Meld Create Customer',
|
|
85
|
+
MeldSearchCustomer = 'Meld Search Customer',
|
|
86
|
+
MeldGetRetailQuote = 'Meld Get Retail Quote',
|
|
87
|
+
MeldCreateRetailWidget = 'Meld Create Retail Widget',
|
|
88
|
+
MeldSearchRetailTransactions = 'Meld Search Retail Transactions',
|
|
89
|
+
MeldGetRetailTransaction = 'Meld Get Retail Transaction',
|
|
90
|
+
MeldGetRetailTransactionBySession = 'Meld Get Retail Transaction By Session',
|
|
91
|
+
MeldGetServiceProviders = 'Meld Get Service Providers',
|
|
92
|
+
MeldGetCountries = 'Meld Get Countries',
|
|
93
|
+
MeldGetFiatCurrencies = 'Meld Get Fiat Currencies',
|
|
94
|
+
MeldGetCryptoCurrencies = 'Meld Get Crypto Currencies',
|
|
95
|
+
MeldGetPaymentMethods = 'Meld Get Payment Methods',
|
|
96
|
+
MeldGetDefaults = 'Meld Get Defaults',
|
|
97
|
+
MeldGetBuyLimits = 'Meld Get Buy Limits',
|
|
98
|
+
MeldGetSellLimits = 'Meld Get Sell Limits',
|
|
99
|
+
MeldGetKycLimits = 'Meld Get Kyc Limits',
|
|
79
100
|
}
|
|
80
101
|
|
|
81
102
|
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
|
|
package/src/version/version.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "version": "4.
|
|
1
|
+
{ "version": "4.9.0" }
|