bitski-provider
Advanced tools
Comparing version 2.0.0-beta.2 to 2.0.0-beta.3
# bitski-provider | ||
## 2.0.0-beta.3 | ||
### Patch Changes | ||
- [#307](https://github.com/BitskiCo/bitski-js/pull/307) [`b00c69e`](https://github.com/BitskiCo/bitski-js/commit/b00c69e661383c5ed8268b3de4d8a22fdd3e3929) Thanks [@pzuraq](https://github.com/pzuraq)! - Fix generics for middleware + switch to standard enums | ||
- Updated dependencies [[`b00c69e`](https://github.com/BitskiCo/bitski-js/commit/b00c69e661383c5ed8268b3de4d8a22fdd3e3929)]: | ||
- eth-provider-types@0.1.0-beta.2 | ||
## 2.0.0-beta.2 | ||
@@ -4,0 +13,0 @@ |
import { createAsyncMiddleware, JsonRpcEngine, } from 'json-rpc-engine'; | ||
import { EthMethod, EthEvent, } from 'eth-provider-types'; | ||
import { createFixtureMiddleware } from './middleware/fixture'; | ||
@@ -23,12 +24,12 @@ import { createTypedDataSanitizerMiddleware } from './middleware/typed-data-sanitizer'; | ||
const SUB_METHODS = new Set([ | ||
"eth_subscribe" /* eth_subscribe */, | ||
"eth_newFilter" /* eth_newFilter */, | ||
"eth_newBlockFilter" /* eth_newBlockFilter */, | ||
"eth_newPendingTransactionFilter" /* eth_newPendingTransactionFilter */, | ||
EthMethod.eth_subscribe, | ||
EthMethod.eth_newFilter, | ||
EthMethod.eth_newBlockFilter, | ||
EthMethod.eth_newPendingTransactionFilter, | ||
]); | ||
const SUB_INTERACTION_METHODS = new Set([ | ||
"eth_getFilterChanges" /* eth_getFilterChanges */, | ||
"eth_getFilterLogs" /* eth_getFilterLogs */, | ||
EthMethod.eth_getFilterChanges, | ||
EthMethod.eth_getFilterLogs, | ||
]); | ||
const UNSUB_METHODS = new Set(["eth_unsubscribe" /* eth_unsubscribe */, "eth_uninstallFilter" /* eth_uninstallFilter */]); | ||
const UNSUB_METHODS = new Set([EthMethod.eth_unsubscribe, EthMethod.eth_uninstallFilter]); | ||
export class BitskiProvider { | ||
@@ -43,3 +44,3 @@ constructor(config) { | ||
this.activeSubs = new Set(); | ||
this.config = Object.assign(Object.assign({}, config), { fetch: (_a = config.fetch) !== null && _a !== void 0 ? _a : fetch, additionalHeaders: Object.assign({ 'X-API-KEY': config.clientId, 'X-CLIENT-ID': config.clientId, 'X-CLIENT-VERSION': "bitski-provider-v2.0.0-beta.2" }, ((_b = config.additionalHeaders) !== null && _b !== void 0 ? _b : {})), apiBaseUrl: (_c = config.apiBaseUrl) !== null && _c !== void 0 ? _c : BITSKI_API_BASE_URL, signerBaseUrl: (_d = config.signerBaseUrl) !== null && _d !== void 0 ? _d : BITSKI_SIGNER_BASE_URL, store: (_e = config.store) !== null && _e !== void 0 ? _e : new LocalStorageStore(), sign: (_f = config.sign) !== null && _f !== void 0 ? _f : createBrowserSigner() }); | ||
this.config = Object.assign(Object.assign({}, config), { fetch: (_a = config.fetch) !== null && _a !== void 0 ? _a : fetch, additionalHeaders: Object.assign({ 'X-API-KEY': config.clientId, 'X-CLIENT-ID': config.clientId, 'X-CLIENT-VERSION': "bitski-provider-v2.0.0-beta.3" }, ((_b = config.additionalHeaders) !== null && _b !== void 0 ? _b : {})), apiBaseUrl: (_c = config.apiBaseUrl) !== null && _c !== void 0 ? _c : BITSKI_API_BASE_URL, signerBaseUrl: (_d = config.signerBaseUrl) !== null && _d !== void 0 ? _d : BITSKI_SIGNER_BASE_URL, store: (_e = config.store) !== null && _e !== void 0 ? _e : new LocalStorageStore(), sign: (_f = config.sign) !== null && _f !== void 0 ? _f : createBrowserSigner() }); | ||
this.store = new BitskiProviderStateStore(this.config.store); | ||
@@ -91,7 +92,7 @@ // Setup the engine | ||
switch (method) { | ||
case "wallet_addEthereumChain" /* wallet_addEthereumChain */: | ||
case EthMethod.wallet_addEthereumChain: | ||
return this.addChain(params[0]); | ||
case "wallet_switchEthereumChain" /* wallet_switchEthereumChain */: | ||
case EthMethod.wallet_switchEthereumChain: | ||
return this.switchChain(params[0]); | ||
case "eth_chainId" /* eth_chainId */: | ||
case EthMethod.eth_chainId: | ||
return chainId; | ||
@@ -130,3 +131,3 @@ default: | ||
// added, to ensure apps have time to set up their listeners. | ||
if (eventName === "connect" /* connect */ && !this.didEmitConnect) { | ||
if (eventName === EthEvent.connect && !this.didEmitConnect) { | ||
this.didEmitConnect = true; | ||
@@ -136,3 +137,3 @@ this.store.getCurrentChainId().then((chainId) => { | ||
setTimeout(() => { | ||
this.events.emit("connect" /* connect */, { chainId }); | ||
this.events.emit(EthEvent.connect, { chainId }); | ||
}); | ||
@@ -139,0 +140,0 @@ }); |
@@ -0,1 +1,2 @@ | ||
import { EthMethod } from 'eth-provider-types'; | ||
import { toHex } from './utils/parse-utils'; | ||
@@ -8,8 +9,8 @@ // URLs | ||
export const SIGN_METHODS = [ | ||
"eth_sendTransaction" /* eth_sendTransaction */, | ||
"eth_signTransaction" /* eth_signTransaction */, | ||
"eth_sign" /* eth_sign */, | ||
"eth_signTypedData" /* eth_signTypedData */, | ||
"eth_signTypedData_v3" /* eth_signTypedData_v3 */, | ||
"eth_signTypedData_v4" /* eth_signTypedData_v4 */, | ||
EthMethod.eth_sendTransaction, | ||
EthMethod.eth_signTransaction, | ||
EthMethod.eth_sign, | ||
EthMethod.eth_signTypedData, | ||
EthMethod.eth_signTypedData_v3, | ||
EthMethod.eth_signTypedData_v4, | ||
// Kept for legacy compat | ||
@@ -20,4 +21,4 @@ 'personal_sign', | ||
export const AUTHENTICATED_METHODS = [ | ||
"eth_requestAccounts" /* eth_requestAccounts */, | ||
"eth_accounts" /* eth_accounts */, | ||
EthMethod.eth_requestAccounts, | ||
EthMethod.eth_accounts, | ||
...SIGN_METHODS, | ||
@@ -24,0 +25,0 @@ ]; |
@@ -0,1 +1,2 @@ | ||
import { EthMethod } from 'eth-provider-types'; | ||
import { createAsyncMiddleware } from 'json-rpc-engine'; | ||
@@ -20,3 +21,3 @@ import { BITSKI_RPC_BASE_URL } from '../constants'; | ||
jsonrpc: req.jsonrpc, | ||
method: "eth_accounts" /* eth_accounts */, | ||
method: EthMethod.eth_accounts, | ||
params: req.params, | ||
@@ -30,3 +31,3 @@ }, | ||
var _a, _b; | ||
if (req.method !== "eth_accounts" /* eth_accounts */ && req.method !== "eth_requestAccounts" /* eth_requestAccounts */) { | ||
if (req.method !== EthMethod.eth_accounts && req.method !== EthMethod.eth_requestAccounts) { | ||
return next(); | ||
@@ -33,0 +34,0 @@ } |
@@ -0,1 +1,2 @@ | ||
import { EthMethod } from 'eth-provider-types'; | ||
import { createAsyncMiddleware } from 'json-rpc-engine'; | ||
@@ -5,6 +6,6 @@ import { getRequestContext } from '../utils/request-context'; | ||
const MATCHING_METHODS = [ | ||
"eth_getBlockByNumber" /* eth_getBlockByNumber */, | ||
"eth_blockNumber" /* eth_blockNumber */, | ||
"net_version" /* net_version */, | ||
"eth_getLogs" /* eth_getLogs */, | ||
EthMethod.eth_getBlockByNumber, | ||
EthMethod.eth_blockNumber, | ||
EthMethod.net_version, | ||
EthMethod.eth_getLogs, | ||
]; | ||
@@ -11,0 +12,0 @@ export const createFetchRestMiddleware = () => { |
@@ -0,6 +1,7 @@ | ||
import { EthMethod } from 'eth-provider-types'; | ||
export const DEFAULT_FIXTURES = { | ||
["web3_clientVersion" /* web3_clientVersion */]: 'Bitski/latest', | ||
["net_listening" /* net_listening */]: true, | ||
["eth_hashrate" /* eth_hashrate */]: '0x00', | ||
["eth_mining" /* eth_mining */]: false, | ||
[EthMethod.web3_clientVersion]: 'Bitski/latest', | ||
[EthMethod.net_listening]: true, | ||
[EthMethod.eth_hashrate]: '0x00', | ||
[EthMethod.eth_mining]: false, | ||
}; | ||
@@ -7,0 +8,0 @@ export const createFixtureMiddleware = (fixtures = DEFAULT_FIXTURES) => { |
@@ -0,1 +1,2 @@ | ||
import { EthMethod } from 'eth-provider-types'; | ||
import { createAsyncMiddleware } from 'json-rpc-engine'; | ||
@@ -11,13 +12,13 @@ import { SIGN_METHODS, SUPPORTED_CHAIN_IDS } from '../constants'; | ||
const requiresLocalSend = !SUPPORTED_CHAIN_IDS.includes(context.chain.chainId) && | ||
req.method === "eth_sendTransaction" /* eth_sendTransaction */; | ||
req.method === EthMethod.eth_sendTransaction; | ||
// When we don't support a chain on the server (e.g. custom RPC url), we need | ||
// to sign the transaction via our flow, then send the signed payload locally | ||
const method = requiresLocalSend | ||
? "eth_signTransaction" /* eth_signTransaction */ | ||
? EthMethod.eth_signTransaction | ||
: req.method; | ||
const signedResponse = await context.config.sign(method, req.params, context); | ||
res.result = requiresLocalSend | ||
? context.request({ method: "eth_sendRawTransaction" /* eth_sendRawTransaction */, params: [signedResponse] }) | ||
? context.request({ method: EthMethod.eth_sendRawTransaction, params: [signedResponse] }) | ||
: signedResponse; | ||
}); | ||
}; |
import createSubscriptionManager from 'eth-json-rpc-filters/subscriptionManager'; | ||
import { createLegacyMiddleware } from '../utils/legacy-middleware'; | ||
import { EthEvent, EthProviderMessageType } from 'eth-provider-types'; | ||
export const createSubscriptionMiddleware = () => createLegacyMiddleware(({ blockTracker, provider, context }) => { | ||
@@ -7,7 +8,7 @@ const manager = createSubscriptionManager({ blockTracker, provider }); | ||
const data = Object.assign(Object.assign({}, notification.params), { subscription: `${context.chain.chainId}:${notification.params.subscription}` }); | ||
context.emit("message" /* message */, { | ||
type: "eth_subscription" /* eth_subscription */, | ||
context.emit(EthEvent.message, { | ||
type: EthProviderMessageType.eth_subscription, | ||
data, | ||
}); | ||
context.emit("data" /* data */, null, { params: data }); | ||
context.emit(EthEvent.data, null, { params: data }); | ||
}); | ||
@@ -14,0 +15,0 @@ context.addDestructor(manager.middleware.destroy); |
@@ -0,1 +1,2 @@ | ||
import { EthMethod } from 'eth-provider-types'; | ||
import { createAsyncMiddleware } from 'json-rpc-engine'; | ||
@@ -6,8 +7,8 @@ import { getRequestContext } from '../utils/request-context'; | ||
return createAsyncMiddleware(async (req, _res, next) => { | ||
if (req.method === "eth_sendTransaction" /* eth_sendTransaction */ || | ||
req.method === "eth_signTransaction" /* eth_signTransaction */) { | ||
if (req.method === EthMethod.eth_sendTransaction || | ||
req.method === EthMethod.eth_signTransaction) { | ||
const [transaction] = expect(req.params, `${req.method} request missing required parameters`); | ||
const context = getRequestContext(req); | ||
if (transaction.from === undefined) { | ||
const accounts = await context.request({ method: "eth_accounts" /* eth_accounts */ }); | ||
const accounts = await context.request({ method: EthMethod.eth_accounts }); | ||
transaction.from = accounts[0]; | ||
@@ -14,0 +15,0 @@ } |
@@ -0,1 +1,2 @@ | ||
import { EthMethod } from 'eth-provider-types'; | ||
import { ethErrors } from 'eth-rpc-errors'; | ||
@@ -5,6 +6,6 @@ import { encodeNumber } from '../utils/parse-utils'; | ||
return (req, _res, next, end) => { | ||
if (req.method === "eth_signTypedData" /* eth_signTypedData */ || | ||
req.method === "eth_signTypedData_v1" /* eth_signTypedData_v1 */ || | ||
req.method === "eth_signTypedData_v3" /* eth_signTypedData_v3 */ || | ||
req.method === "eth_signTypedData_v4" /* eth_signTypedData_v4 */) { | ||
if (req.method === EthMethod.eth_signTypedData || | ||
req.method === EthMethod.eth_signTypedData_v1 || | ||
req.method === EthMethod.eth_signTypedData_v3 || | ||
req.method === EthMethod.eth_signTypedData_v4) { | ||
try { | ||
@@ -11,0 +12,0 @@ sanitizeRequest(req); |
@@ -0,1 +1,2 @@ | ||
import { EthMethod } from 'eth-provider-types'; | ||
import { ethErrors } from 'eth-rpc-errors'; | ||
@@ -22,11 +23,11 @@ import { SUPPORTED_CHAIN_IDS } from '../constants'; | ||
case 'personal_sign': | ||
case "eth_sign" /* eth_sign */: | ||
case "eth_sendTransaction" /* eth_sendTransaction */: | ||
case "eth_signTransaction" /* eth_signTransaction */: { | ||
case EthMethod.eth_sign: | ||
case EthMethod.eth_sendTransaction: | ||
case EthMethod.eth_signTransaction: { | ||
return Object.assign({ chainId: parseInt(chain.chainId, 16), rpcUrl: !SUPPORTED_CHAIN_IDS.includes(chain.chainId) ? chain.rpcUrls[0] : undefined }, additionalContext); | ||
} | ||
case "eth_signTypedData" /* eth_signTypedData */: | ||
case "eth_signTypedData_v1" /* eth_signTypedData_v1 */: | ||
case "eth_signTypedData_v3" /* eth_signTypedData_v3 */: | ||
case "eth_signTypedData_v4" /* eth_signTypedData_v4 */: | ||
case EthMethod.eth_signTypedData: | ||
case EthMethod.eth_signTypedData_v1: | ||
case EthMethod.eth_signTypedData_v3: | ||
case EthMethod.eth_signTypedData_v4: | ||
// The from address should be the first parameter as a 20 byte hex string | ||
@@ -47,4 +48,4 @@ if (params && (params === null || params === void 0 ? void 0 : params.length) > 0) { | ||
switch (method) { | ||
case "eth_sendTransaction" /* eth_sendTransaction */: | ||
case "eth_signTransaction" /* eth_signTransaction */: | ||
case EthMethod.eth_sendTransaction: | ||
case EthMethod.eth_signTransaction: | ||
if (params && params.length > 0) { | ||
@@ -56,3 +57,3 @@ return params[0]; | ||
} | ||
case "eth_sign" /* eth_sign */: | ||
case EthMethod.eth_sign: | ||
if (params && params.length > 1) { | ||
@@ -79,6 +80,6 @@ return { from: params[0], message: params[1] }; | ||
} | ||
case "eth_signTypedData" /* eth_signTypedData */: | ||
case "eth_signTypedData_v1" /* eth_signTypedData_v1 */: | ||
case "eth_signTypedData_v3" /* eth_signTypedData_v3 */: | ||
case "eth_signTypedData_v4" /* eth_signTypedData_v4 */: | ||
case EthMethod.eth_signTypedData: | ||
case EthMethod.eth_signTypedData_v1: | ||
case EthMethod.eth_signTypedData_v3: | ||
case EthMethod.eth_signTypedData_v4: | ||
if (params && params.length > 1) { | ||
@@ -100,16 +101,16 @@ return params[1]; | ||
switch (method) { | ||
case "eth_sendTransaction" /* eth_sendTransaction */: | ||
case EthMethod.eth_sendTransaction: | ||
return "ETH_SEND_TRANSACTION" /* SendTransaction */; | ||
case "eth_signTransaction" /* eth_signTransaction */: | ||
case EthMethod.eth_signTransaction: | ||
return "ETH_SIGN_TRANSACTION" /* SignTransaction */; | ||
case "eth_sign" /* eth_sign */: | ||
case EthMethod.eth_sign: | ||
case 'personal_sign': | ||
return "ETH_SIGN" /* Sign */; | ||
case "eth_signTypedData" /* eth_signTypedData */: | ||
case EthMethod.eth_signTypedData: | ||
return "ETH_SIGN_TYPED_DATA" /* SignTypedData */; | ||
case "eth_signTypedData_v1" /* eth_signTypedData_v1 */: | ||
case EthMethod.eth_signTypedData_v1: | ||
return "ETH_SIGN_TYPED_DATA_V1" /* SignTypedDataV1 */; | ||
case "eth_signTypedData_v3" /* eth_signTypedData_v3 */: | ||
case EthMethod.eth_signTypedData_v3: | ||
return "ETH_SIGN_TYPED_DATA_V3" /* SignTypedDataV3 */; | ||
case "eth_signTypedData_v4" /* eth_signTypedData_v4 */: | ||
case EthMethod.eth_signTypedData_v4: | ||
return "ETH_SIGN_TYPED_DATA_V4" /* SignTypedDataV4 */; | ||
@@ -116,0 +117,0 @@ default: |
// jshint esversion: 9 | ||
const base = require('../../jest.config.base.js'); | ||
module.exports = { | ||
@@ -14,2 +12,5 @@ roots: ['<rootDir>/src', '<rootDir>/tests'], | ||
}, | ||
moduleNameMapper: { | ||
'eth-provider-types': '<rootDir>/../eth-provider-types/index.ts', | ||
}, | ||
testRegex: '(/tests/.*.(test|spec)).(jsx?|tsx?)$', | ||
@@ -16,0 +17,0 @@ automock: false, |
@@ -24,2 +24,2 @@ import { EthProvider, EthMethod, EthRequest, EthResult, EthEvent, EthEventListener } from 'eth-provider-types'; | ||
} | ||
export declare const createBitskiProvider: (config: BitskiProviderConfig) => BitskiProvider; | ||
export declare const createBitskiProvider: <Extra = unknown>(config: BitskiProviderConfig<Extra>) => BitskiProvider<Extra>; |
@@ -8,2 +8,3 @@ "use strict"; | ||
const json_rpc_engine_1 = require("json-rpc-engine"); | ||
const eth_provider_types_1 = require("eth-provider-types"); | ||
const fixture_1 = require("./middleware/fixture"); | ||
@@ -30,12 +31,12 @@ const typed_data_sanitizer_1 = require("./middleware/typed-data-sanitizer"); | ||
const SUB_METHODS = new Set([ | ||
"eth_subscribe" /* eth_subscribe */, | ||
"eth_newFilter" /* eth_newFilter */, | ||
"eth_newBlockFilter" /* eth_newBlockFilter */, | ||
"eth_newPendingTransactionFilter" /* eth_newPendingTransactionFilter */, | ||
eth_provider_types_1.EthMethod.eth_subscribe, | ||
eth_provider_types_1.EthMethod.eth_newFilter, | ||
eth_provider_types_1.EthMethod.eth_newBlockFilter, | ||
eth_provider_types_1.EthMethod.eth_newPendingTransactionFilter, | ||
]); | ||
const SUB_INTERACTION_METHODS = new Set([ | ||
"eth_getFilterChanges" /* eth_getFilterChanges */, | ||
"eth_getFilterLogs" /* eth_getFilterLogs */, | ||
eth_provider_types_1.EthMethod.eth_getFilterChanges, | ||
eth_provider_types_1.EthMethod.eth_getFilterLogs, | ||
]); | ||
const UNSUB_METHODS = new Set(["eth_unsubscribe" /* eth_unsubscribe */, "eth_uninstallFilter" /* eth_uninstallFilter */]); | ||
const UNSUB_METHODS = new Set([eth_provider_types_1.EthMethod.eth_unsubscribe, eth_provider_types_1.EthMethod.eth_uninstallFilter]); | ||
class BitskiProvider { | ||
@@ -50,3 +51,3 @@ constructor(config) { | ||
this.activeSubs = new Set(); | ||
this.config = Object.assign(Object.assign({}, config), { fetch: (_a = config.fetch) !== null && _a !== void 0 ? _a : fetch, additionalHeaders: Object.assign({ 'X-API-KEY': config.clientId, 'X-CLIENT-ID': config.clientId, 'X-CLIENT-VERSION': "bitski-provider-v2.0.0-beta.2" }, ((_b = config.additionalHeaders) !== null && _b !== void 0 ? _b : {})), apiBaseUrl: (_c = config.apiBaseUrl) !== null && _c !== void 0 ? _c : constants_1.BITSKI_API_BASE_URL, signerBaseUrl: (_d = config.signerBaseUrl) !== null && _d !== void 0 ? _d : constants_1.BITSKI_SIGNER_BASE_URL, store: (_e = config.store) !== null && _e !== void 0 ? _e : new store_1.LocalStorageStore(), sign: (_f = config.sign) !== null && _f !== void 0 ? _f : (0, browser_1.default)() }); | ||
this.config = Object.assign(Object.assign({}, config), { fetch: (_a = config.fetch) !== null && _a !== void 0 ? _a : fetch, additionalHeaders: Object.assign({ 'X-API-KEY': config.clientId, 'X-CLIENT-ID': config.clientId, 'X-CLIENT-VERSION': "bitski-provider-v2.0.0-beta.3" }, ((_b = config.additionalHeaders) !== null && _b !== void 0 ? _b : {})), apiBaseUrl: (_c = config.apiBaseUrl) !== null && _c !== void 0 ? _c : constants_1.BITSKI_API_BASE_URL, signerBaseUrl: (_d = config.signerBaseUrl) !== null && _d !== void 0 ? _d : constants_1.BITSKI_SIGNER_BASE_URL, store: (_e = config.store) !== null && _e !== void 0 ? _e : new store_1.LocalStorageStore(), sign: (_f = config.sign) !== null && _f !== void 0 ? _f : (0, browser_1.default)() }); | ||
this.store = new store_1.BitskiProviderStateStore(this.config.store); | ||
@@ -98,7 +99,7 @@ // Setup the engine | ||
switch (method) { | ||
case "wallet_addEthereumChain" /* wallet_addEthereumChain */: | ||
case eth_provider_types_1.EthMethod.wallet_addEthereumChain: | ||
return this.addChain(params[0]); | ||
case "wallet_switchEthereumChain" /* wallet_switchEthereumChain */: | ||
case eth_provider_types_1.EthMethod.wallet_switchEthereumChain: | ||
return this.switchChain(params[0]); | ||
case "eth_chainId" /* eth_chainId */: | ||
case eth_provider_types_1.EthMethod.eth_chainId: | ||
return chainId; | ||
@@ -137,3 +138,3 @@ default: | ||
// added, to ensure apps have time to set up their listeners. | ||
if (eventName === "connect" /* connect */ && !this.didEmitConnect) { | ||
if (eventName === eth_provider_types_1.EthEvent.connect && !this.didEmitConnect) { | ||
this.didEmitConnect = true; | ||
@@ -143,3 +144,3 @@ this.store.getCurrentChainId().then((chainId) => { | ||
setTimeout(() => { | ||
this.events.emit("connect" /* connect */, { chainId }); | ||
this.events.emit(eth_provider_types_1.EthEvent.connect, { chainId }); | ||
}); | ||
@@ -146,0 +147,0 @@ }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DEFAULT_CHAINS = exports.BinanceSmartChainTestnet = exports.BinanceSmartChain = exports.Mumbai = exports.Polygon = exports.Goerli = exports.Mainnet = exports.SUPPORTED_CHAIN_IDS = exports.UNAUTHORIZED_ERRORS = exports.RETRIABLE_ERRORS = exports.AUTHENTICATED_METHODS = exports.SIGN_METHODS = exports.IFRAME_MESSAGE_ORIGIN_ENDS_WITH = exports.BITSKI_SIGNER_BASE_URL = exports.BITSKI_RPC_BASE_URL = exports.BITSKI_API_BASE_URL = void 0; | ||
const eth_provider_types_1 = require("eth-provider-types"); | ||
const parse_utils_1 = require("./utils/parse-utils"); | ||
@@ -11,8 +12,8 @@ // URLs | ||
exports.SIGN_METHODS = [ | ||
"eth_sendTransaction" /* eth_sendTransaction */, | ||
"eth_signTransaction" /* eth_signTransaction */, | ||
"eth_sign" /* eth_sign */, | ||
"eth_signTypedData" /* eth_signTypedData */, | ||
"eth_signTypedData_v3" /* eth_signTypedData_v3 */, | ||
"eth_signTypedData_v4" /* eth_signTypedData_v4 */, | ||
eth_provider_types_1.EthMethod.eth_sendTransaction, | ||
eth_provider_types_1.EthMethod.eth_signTransaction, | ||
eth_provider_types_1.EthMethod.eth_sign, | ||
eth_provider_types_1.EthMethod.eth_signTypedData, | ||
eth_provider_types_1.EthMethod.eth_signTypedData_v3, | ||
eth_provider_types_1.EthMethod.eth_signTypedData_v4, | ||
// Kept for legacy compat | ||
@@ -23,4 +24,4 @@ 'personal_sign', | ||
exports.AUTHENTICATED_METHODS = [ | ||
"eth_requestAccounts" /* eth_requestAccounts */, | ||
"eth_accounts" /* eth_accounts */, | ||
eth_provider_types_1.EthMethod.eth_requestAccounts, | ||
eth_provider_types_1.EthMethod.eth_accounts, | ||
...exports.SIGN_METHODS, | ||
@@ -27,0 +28,0 @@ ]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createEthAccountsMiddleware = void 0; | ||
const eth_provider_types_1 = require("eth-provider-types"); | ||
const json_rpc_engine_1 = require("json-rpc-engine"); | ||
@@ -23,3 +24,3 @@ const constants_1 = require("../constants"); | ||
jsonrpc: req.jsonrpc, | ||
method: "eth_accounts" /* eth_accounts */, | ||
method: eth_provider_types_1.EthMethod.eth_accounts, | ||
params: req.params, | ||
@@ -33,3 +34,3 @@ }, | ||
var _a, _b; | ||
if (req.method !== "eth_accounts" /* eth_accounts */ && req.method !== "eth_requestAccounts" /* eth_requestAccounts */) { | ||
if (req.method !== eth_provider_types_1.EthMethod.eth_accounts && req.method !== eth_provider_types_1.EthMethod.eth_requestAccounts) { | ||
return next(); | ||
@@ -36,0 +37,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createFetchRestMiddleware = void 0; | ||
const eth_provider_types_1 = require("eth-provider-types"); | ||
const json_rpc_engine_1 = require("json-rpc-engine"); | ||
@@ -8,6 +9,6 @@ const request_context_1 = require("../utils/request-context"); | ||
const MATCHING_METHODS = [ | ||
"eth_getBlockByNumber" /* eth_getBlockByNumber */, | ||
"eth_blockNumber" /* eth_blockNumber */, | ||
"net_version" /* net_version */, | ||
"eth_getLogs" /* eth_getLogs */, | ||
eth_provider_types_1.EthMethod.eth_getBlockByNumber, | ||
eth_provider_types_1.EthMethod.eth_blockNumber, | ||
eth_provider_types_1.EthMethod.net_version, | ||
eth_provider_types_1.EthMethod.eth_getLogs, | ||
]; | ||
@@ -14,0 +15,0 @@ const createFetchRestMiddleware = () => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createFixtureMiddleware = exports.DEFAULT_FIXTURES = void 0; | ||
const eth_provider_types_1 = require("eth-provider-types"); | ||
exports.DEFAULT_FIXTURES = { | ||
["web3_clientVersion" /* web3_clientVersion */]: 'Bitski/latest', | ||
["net_listening" /* net_listening */]: true, | ||
["eth_hashrate" /* eth_hashrate */]: '0x00', | ||
["eth_mining" /* eth_mining */]: false, | ||
[eth_provider_types_1.EthMethod.web3_clientVersion]: 'Bitski/latest', | ||
[eth_provider_types_1.EthMethod.net_listening]: true, | ||
[eth_provider_types_1.EthMethod.eth_hashrate]: '0x00', | ||
[eth_provider_types_1.EthMethod.eth_mining]: false, | ||
}; | ||
@@ -10,0 +11,0 @@ const createFixtureMiddleware = (fixtures = exports.DEFAULT_FIXTURES) => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createSignatureMiddleware = void 0; | ||
const eth_provider_types_1 = require("eth-provider-types"); | ||
const json_rpc_engine_1 = require("json-rpc-engine"); | ||
@@ -14,11 +15,11 @@ const constants_1 = require("../constants"); | ||
const requiresLocalSend = !constants_1.SUPPORTED_CHAIN_IDS.includes(context.chain.chainId) && | ||
req.method === "eth_sendTransaction" /* eth_sendTransaction */; | ||
req.method === eth_provider_types_1.EthMethod.eth_sendTransaction; | ||
// When we don't support a chain on the server (e.g. custom RPC url), we need | ||
// to sign the transaction via our flow, then send the signed payload locally | ||
const method = requiresLocalSend | ||
? "eth_signTransaction" /* eth_signTransaction */ | ||
? eth_provider_types_1.EthMethod.eth_signTransaction | ||
: req.method; | ||
const signedResponse = await context.config.sign(method, req.params, context); | ||
res.result = requiresLocalSend | ||
? context.request({ method: "eth_sendRawTransaction" /* eth_sendRawTransaction */, params: [signedResponse] }) | ||
? context.request({ method: eth_provider_types_1.EthMethod.eth_sendRawTransaction, params: [signedResponse] }) | ||
: signedResponse; | ||
@@ -25,0 +26,0 @@ }); |
@@ -9,2 +9,3 @@ "use strict"; | ||
const legacy_middleware_1 = require("../utils/legacy-middleware"); | ||
const eth_provider_types_1 = require("eth-provider-types"); | ||
const createSubscriptionMiddleware = () => (0, legacy_middleware_1.createLegacyMiddleware)(({ blockTracker, provider, context }) => { | ||
@@ -14,7 +15,7 @@ const manager = (0, subscriptionManager_1.default)({ blockTracker, provider }); | ||
const data = Object.assign(Object.assign({}, notification.params), { subscription: `${context.chain.chainId}:${notification.params.subscription}` }); | ||
context.emit("message" /* message */, { | ||
type: "eth_subscription" /* eth_subscription */, | ||
context.emit(eth_provider_types_1.EthEvent.message, { | ||
type: eth_provider_types_1.EthProviderMessageType.eth_subscription, | ||
data, | ||
}); | ||
context.emit("data" /* data */, null, { params: data }); | ||
context.emit(eth_provider_types_1.EthEvent.data, null, { params: data }); | ||
}); | ||
@@ -21,0 +22,0 @@ context.addDestructor(manager.middleware.destroy); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createTransactionValidatorMiddleware = void 0; | ||
const eth_provider_types_1 = require("eth-provider-types"); | ||
const json_rpc_engine_1 = require("json-rpc-engine"); | ||
@@ -9,8 +10,8 @@ const request_context_1 = require("../utils/request-context"); | ||
return (0, json_rpc_engine_1.createAsyncMiddleware)(async (req, _res, next) => { | ||
if (req.method === "eth_sendTransaction" /* eth_sendTransaction */ || | ||
req.method === "eth_signTransaction" /* eth_signTransaction */) { | ||
if (req.method === eth_provider_types_1.EthMethod.eth_sendTransaction || | ||
req.method === eth_provider_types_1.EthMethod.eth_signTransaction) { | ||
const [transaction] = (0, type_utils_1.expect)(req.params, `${req.method} request missing required parameters`); | ||
const context = (0, request_context_1.getRequestContext)(req); | ||
if (transaction.from === undefined) { | ||
const accounts = await context.request({ method: "eth_accounts" /* eth_accounts */ }); | ||
const accounts = await context.request({ method: eth_provider_types_1.EthMethod.eth_accounts }); | ||
transaction.from = accounts[0]; | ||
@@ -17,0 +18,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createTypeMapping = exports.sanitizeType = exports.sanitizeMessage = exports.sanitizeDomain = exports.createTypedDataSanitizerMiddleware = void 0; | ||
const eth_provider_types_1 = require("eth-provider-types"); | ||
const eth_rpc_errors_1 = require("eth-rpc-errors"); | ||
@@ -8,6 +9,6 @@ const parse_utils_1 = require("../utils/parse-utils"); | ||
return (req, _res, next, end) => { | ||
if (req.method === "eth_signTypedData" /* eth_signTypedData */ || | ||
req.method === "eth_signTypedData_v1" /* eth_signTypedData_v1 */ || | ||
req.method === "eth_signTypedData_v3" /* eth_signTypedData_v3 */ || | ||
req.method === "eth_signTypedData_v4" /* eth_signTypedData_v4 */) { | ||
if (req.method === eth_provider_types_1.EthMethod.eth_signTypedData || | ||
req.method === eth_provider_types_1.EthMethod.eth_signTypedData_v1 || | ||
req.method === eth_provider_types_1.EthMethod.eth_signTypedData_v3 || | ||
req.method === eth_provider_types_1.EthMethod.eth_signTypedData_v4) { | ||
try { | ||
@@ -14,0 +15,0 @@ sanitizeRequest(req); |
@@ -22,3 +22,3 @@ import { EthChainDefinition, EthEvent, EthEventParams, EthMethod, EthMethodParams, EthRequest, EthResult } from 'eth-provider-types'; | ||
additionalHeaders: Record<string, string>; | ||
prependMiddleware?: ProviderMiddleware<Extra>[]; | ||
prependMiddleware?: ProviderMiddleware<unknown[], unknown, Extra>[]; | ||
pollingInterval?: number; | ||
@@ -25,0 +25,0 @@ disableCaching?: boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createBitskiTransaction = void 0; | ||
const eth_provider_types_1 = require("eth-provider-types"); | ||
const eth_rpc_errors_1 = require("eth-rpc-errors"); | ||
@@ -26,11 +27,11 @@ const constants_1 = require("../constants"); | ||
case 'personal_sign': | ||
case "eth_sign" /* eth_sign */: | ||
case "eth_sendTransaction" /* eth_sendTransaction */: | ||
case "eth_signTransaction" /* eth_signTransaction */: { | ||
case eth_provider_types_1.EthMethod.eth_sign: | ||
case eth_provider_types_1.EthMethod.eth_sendTransaction: | ||
case eth_provider_types_1.EthMethod.eth_signTransaction: { | ||
return Object.assign({ chainId: parseInt(chain.chainId, 16), rpcUrl: !constants_1.SUPPORTED_CHAIN_IDS.includes(chain.chainId) ? chain.rpcUrls[0] : undefined }, additionalContext); | ||
} | ||
case "eth_signTypedData" /* eth_signTypedData */: | ||
case "eth_signTypedData_v1" /* eth_signTypedData_v1 */: | ||
case "eth_signTypedData_v3" /* eth_signTypedData_v3 */: | ||
case "eth_signTypedData_v4" /* eth_signTypedData_v4 */: | ||
case eth_provider_types_1.EthMethod.eth_signTypedData: | ||
case eth_provider_types_1.EthMethod.eth_signTypedData_v1: | ||
case eth_provider_types_1.EthMethod.eth_signTypedData_v3: | ||
case eth_provider_types_1.EthMethod.eth_signTypedData_v4: | ||
// The from address should be the first parameter as a 20 byte hex string | ||
@@ -51,4 +52,4 @@ if (params && (params === null || params === void 0 ? void 0 : params.length) > 0) { | ||
switch (method) { | ||
case "eth_sendTransaction" /* eth_sendTransaction */: | ||
case "eth_signTransaction" /* eth_signTransaction */: | ||
case eth_provider_types_1.EthMethod.eth_sendTransaction: | ||
case eth_provider_types_1.EthMethod.eth_signTransaction: | ||
if (params && params.length > 0) { | ||
@@ -60,3 +61,3 @@ return params[0]; | ||
} | ||
case "eth_sign" /* eth_sign */: | ||
case eth_provider_types_1.EthMethod.eth_sign: | ||
if (params && params.length > 1) { | ||
@@ -83,6 +84,6 @@ return { from: params[0], message: params[1] }; | ||
} | ||
case "eth_signTypedData" /* eth_signTypedData */: | ||
case "eth_signTypedData_v1" /* eth_signTypedData_v1 */: | ||
case "eth_signTypedData_v3" /* eth_signTypedData_v3 */: | ||
case "eth_signTypedData_v4" /* eth_signTypedData_v4 */: | ||
case eth_provider_types_1.EthMethod.eth_signTypedData: | ||
case eth_provider_types_1.EthMethod.eth_signTypedData_v1: | ||
case eth_provider_types_1.EthMethod.eth_signTypedData_v3: | ||
case eth_provider_types_1.EthMethod.eth_signTypedData_v4: | ||
if (params && params.length > 1) { | ||
@@ -104,16 +105,16 @@ return params[1]; | ||
switch (method) { | ||
case "eth_sendTransaction" /* eth_sendTransaction */: | ||
case eth_provider_types_1.EthMethod.eth_sendTransaction: | ||
return "ETH_SEND_TRANSACTION" /* SendTransaction */; | ||
case "eth_signTransaction" /* eth_signTransaction */: | ||
case eth_provider_types_1.EthMethod.eth_signTransaction: | ||
return "ETH_SIGN_TRANSACTION" /* SignTransaction */; | ||
case "eth_sign" /* eth_sign */: | ||
case eth_provider_types_1.EthMethod.eth_sign: | ||
case 'personal_sign': | ||
return "ETH_SIGN" /* Sign */; | ||
case "eth_signTypedData" /* eth_signTypedData */: | ||
case eth_provider_types_1.EthMethod.eth_signTypedData: | ||
return "ETH_SIGN_TYPED_DATA" /* SignTypedData */; | ||
case "eth_signTypedData_v1" /* eth_signTypedData_v1 */: | ||
case eth_provider_types_1.EthMethod.eth_signTypedData_v1: | ||
return "ETH_SIGN_TYPED_DATA_V1" /* SignTypedDataV1 */; | ||
case "eth_signTypedData_v3" /* eth_signTypedData_v3 */: | ||
case eth_provider_types_1.EthMethod.eth_signTypedData_v3: | ||
return "ETH_SIGN_TYPED_DATA_V3" /* SignTypedDataV3 */; | ||
case "eth_signTypedData_v4" /* eth_signTypedData_v4 */: | ||
case eth_provider_types_1.EthMethod.eth_signTypedData_v4: | ||
return "ETH_SIGN_TYPED_DATA_V4" /* SignTypedDataV4 */; | ||
@@ -120,0 +121,0 @@ default: |
@@ -12,3 +12,3 @@ { | ||
}, | ||
"version": "2.0.0-beta.2", | ||
"version": "2.0.0-beta.3", | ||
"scripts": { | ||
@@ -27,3 +27,3 @@ "test": "jest", | ||
"eth-json-rpc-middleware": "^9.0.1", | ||
"eth-provider-types": "^0.1.0-beta.1", | ||
"eth-provider-types": "^0.1.0-beta.2", | ||
"eth-rpc-errors": "^4.0.3", | ||
@@ -30,0 +30,0 @@ "json-rpc-engine": "^6.1.0", |
@@ -272,4 +272,6 @@ import { | ||
export const createBitskiProvider = (config: BitskiProviderConfig): BitskiProvider => { | ||
export const createBitskiProvider = <Extra = unknown>( | ||
config: BitskiProviderConfig<Extra>, | ||
): BitskiProvider<Extra> => { | ||
return new BitskiProvider(config); | ||
}; |
@@ -47,3 +47,3 @@ import { | ||
prependMiddleware?: ProviderMiddleware<Extra>[]; | ||
prependMiddleware?: ProviderMiddleware<unknown[], unknown, Extra>[]; | ||
pollingInterval?: number; | ||
@@ -50,0 +50,0 @@ disableCaching?: boolean; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
348446
7558