Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More

bitski-provider

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitski-provider - npm Package Compare versions

Comparing version 2.0.0-beta.0 to 2.0.0-beta.1

# bitski-provider
## 2.0.0-beta.1
### Patch Changes
- [#303](https://github.com/BitskiCo/bitski-js/pull/303) [`56c7b13`](https://github.com/BitskiCo/bitski-js/commit/56c7b13b128df0d77aae1f9e2144692727a082ce) Thanks [@pzuraq](https://github.com/pzuraq)! - Update external types for prepend middleware to expose fewer implementation details
## 2.0.0-beta.0

@@ -4,0 +10,0 @@

@@ -1,2 +0,2 @@

import { JsonRpcEngine } from 'json-rpc-engine';
import { createAsyncMiddleware, JsonRpcEngine, } from 'json-rpc-engine';
import { createFixtureMiddleware } from './middleware/fixture';

@@ -42,7 +42,10 @@ import { createTypedDataSanitizerMiddleware } from './middleware/typed-data-sanitizer';

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.0" }, ((_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.1" }, ((_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);
// Setup the engine
const engine = this.engine;
(_g = config.prependMiddleware) === null || _g === void 0 ? void 0 : _g.forEach((middleware) => engine.push(middleware));
(_g = config.prependMiddleware) === null || _g === void 0 ? void 0 : _g.forEach((middleware) =>
// TODO: Need to typecast because JSON RPC engine middleware can't have
// additional props on it, can get rid of this once we get rid of JSON RPC engine
engine.push(createAsyncMiddleware(middleware)));
// Handles static responses

@@ -49,0 +52,0 @@ engine.push(createFixtureMiddleware());

@@ -95,3 +95,3 @@ import { ethErrors } from 'eth-rpc-errors';

const { config } = requestContext;
const transaction = await createBitskiTransaction(method, params, requestContext);
const transaction = await createBitskiTransaction(method, params, requestContext.chain, requestContext.config.additionalSigningContext);
// If we have a callback URL, use the redirect flow

@@ -98,0 +98,0 @@ if (config.transactionCallbackUrl) {

@@ -8,4 +8,4 @@ import { ethErrors } from 'eth-rpc-errors';

*/
export const createBitskiTransaction = (method, params, requestContext) => {
const context = createContext(method, params, requestContext.chain, requestContext);
export const createBitskiTransaction = (method, params, chain, additionalContext) => {
const context = createContext(method, params, chain, additionalContext);
const kind = kindForMethod(method);

@@ -20,3 +20,3 @@ const extractedPayload = createPayload(method, params);

};
const createContext = (method, params, chain, requestContext) => {
const createContext = (method, params, chain, additionalContext) => {
switch (method) {

@@ -27,3 +27,3 @@ case 'personal_sign':

case "eth_signTransaction" /* eth_signTransaction */: {
return Object.assign({ chainId: parseInt(chain.chainId, 16), rpcUrl: !SUPPORTED_CHAIN_IDS.includes(chain.chainId) ? chain.rpcUrls[0] : undefined }, requestContext.signContext);
return Object.assign({ chainId: parseInt(chain.chainId, 16), rpcUrl: !SUPPORTED_CHAIN_IDS.includes(chain.chainId) ? chain.rpcUrls[0] : undefined }, additionalContext);
}

@@ -36,3 +36,3 @@ case "eth_signTypedData" /* eth_signTypedData */:

if (params && (params === null || params === void 0 ? void 0 : params.length) > 0) {
return Object.assign({ from: params[0] }, requestContext.signContext);
return Object.assign({ from: params[0] }, additionalContext);
}

@@ -39,0 +39,0 @@ throw ethErrors.rpc.invalidParams('Missing from');

@@ -48,7 +48,10 @@ "use strict";

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.0" }, ((_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.1" }, ((_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);
// Setup the engine
const engine = this.engine;
(_g = config.prependMiddleware) === null || _g === void 0 ? void 0 : _g.forEach((middleware) => engine.push(middleware));
(_g = config.prependMiddleware) === null || _g === void 0 ? void 0 : _g.forEach((middleware) =>
// TODO: Need to typecast because JSON RPC engine middleware can't have
// additional props on it, can get rid of this once we get rid of JSON RPC engine
engine.push((0, json_rpc_engine_1.createAsyncMiddleware)(middleware)));
// Handles static responses

@@ -55,0 +58,0 @@ engine.push((0, fixture_1.createFixtureMiddleware)());

@@ -97,3 +97,3 @@ "use strict";

const { config } = requestContext;
const transaction = await (0, transaction_1.createBitskiTransaction)(method, params, requestContext);
const transaction = await (0, transaction_1.createBitskiTransaction)(method, params, requestContext.chain, requestContext.config.additionalSigningContext);
// If we have a callback URL, use the redirect flow

@@ -100,0 +100,0 @@ if (config.transactionCallbackUrl) {

import { EthChainDefinition, EthEvent, EthEventParams, EthMethod, EthMethodParams, EthRequest, EthResult } from 'eth-provider-types';
import { JsonRpcMiddleware } from 'json-rpc-engine';
import { JsonRpcRequest, PendingJsonRpcResponse } from 'json-rpc-engine';
export interface User {

@@ -21,6 +21,7 @@ id: string;

additionalHeaders: Record<string, string>;
prependMiddleware?: JsonRpcMiddleware<unknown[], unknown>[];
prependMiddleware?: ProviderMiddleware[];
pollingInterval?: number;
disableCaching?: boolean;
disableValidation?: boolean;
additionalSigningContext?: Record<string, string>;
clientId: string;

@@ -44,6 +45,6 @@ apiBaseUrl: string;

*/
export interface RequestContext {
export interface RequestContext<T = unknown> {
chain: EthChainDefinitionWithRpcUrl;
config: InternalBitskiProviderConfig;
signContext?: Record<string, string>;
extra?: T;
emit: <T extends EthEvent>(eventName: T, ...params: EthEventParams[T]) => void;

@@ -58,4 +59,7 @@ request<T extends EthMethod>({ method, params }: EthRequest<T>, opts?: {

}
export declare type ProviderMiddleware<T = unknown[], U = unknown, V = unknown> = (req: JsonRpcRequest<T> & {
context: RequestContext<V>;
}, res: PendingJsonRpcResponse<U>, next: () => Promise<void>) => Promise<void>;
export declare type EthSignMethod = EthMethod.eth_sendTransaction | EthMethod.eth_signTransaction | EthMethod.eth_sign | EthMethod.eth_signTypedData | EthMethod.eth_signTypedData_v1 | EthMethod.eth_signTypedData_v3 | EthMethod.eth_signTypedData_v4 | 'personal_sign';
export declare type SignFn = <T extends EthSignMethod>(method: T, params: EthSignMethodParams[T], context: RequestContext) => Promise<string>;
export {};
import { EthTransactionSend, TypedData } from 'eth-provider-types';
import { EthSignMethod, EthSignMethodParams, RequestContext } from '../types';
import { EthSignMethod, EthSignMethodParams, EthChainDefinitionWithRpcUrl } from '../types';
export declare const enum TransactionKind {

@@ -31,2 +31,2 @@ SendTransaction = "ETH_SEND_TRANSACTION",

*/
export declare const createBitskiTransaction: <T extends EthSignMethod>(method: T, params: EthSignMethodParams[T], requestContext: Pick<RequestContext, 'chain' | 'signContext'>) => Transaction;
export declare const createBitskiTransaction: <T extends EthSignMethod>(method: T, params: EthSignMethodParams[T], chain: EthChainDefinitionWithRpcUrl, additionalContext?: Record<string, string> | undefined) => Transaction;

@@ -11,4 +11,4 @@ "use strict";

*/
const createBitskiTransaction = (method, params, requestContext) => {
const context = createContext(method, params, requestContext.chain, requestContext);
const createBitskiTransaction = (method, params, chain, additionalContext) => {
const context = createContext(method, params, chain, additionalContext);
const kind = kindForMethod(method);

@@ -24,3 +24,3 @@ const extractedPayload = createPayload(method, params);

exports.createBitskiTransaction = createBitskiTransaction;
const createContext = (method, params, chain, requestContext) => {
const createContext = (method, params, chain, additionalContext) => {
switch (method) {

@@ -31,3 +31,3 @@ case 'personal_sign':

case "eth_signTransaction" /* eth_signTransaction */: {
return Object.assign({ chainId: parseInt(chain.chainId, 16), rpcUrl: !constants_1.SUPPORTED_CHAIN_IDS.includes(chain.chainId) ? chain.rpcUrls[0] : undefined }, requestContext.signContext);
return Object.assign({ chainId: parseInt(chain.chainId, 16), rpcUrl: !constants_1.SUPPORTED_CHAIN_IDS.includes(chain.chainId) ? chain.rpcUrls[0] : undefined }, additionalContext);
}

@@ -40,3 +40,3 @@ case "eth_signTypedData" /* eth_signTypedData */:

if (params && (params === null || params === void 0 ? void 0 : params.length) > 0) {
return Object.assign({ from: params[0] }, requestContext.signContext);
return Object.assign({ from: params[0] }, additionalContext);
}

@@ -43,0 +43,0 @@ throw eth_rpc_errors_1.ethErrors.rpc.invalidParams('Missing from');

@@ -12,3 +12,3 @@ {

},
"version": "2.0.0-beta.0",
"version": "2.0.0-beta.1",
"scripts": {

@@ -15,0 +15,0 @@ "test": "jest",

@@ -47,2 +47,6 @@ # Bitski Provider

// Additional parameters added to the context of a sign request, e.g. the origin
// that is attempting to sign
additionalSigningContext?: Record<string, string>;
// The API base URL for RPC and other API requests. Defaults to

@@ -49,0 +53,0 @@ // https://api.bitski.com

@@ -1,3 +0,9 @@

import { JsonRpcEngine, JsonRpcFailure, JsonRpcSuccess, JsonRpcVersion } from 'json-rpc-engine';
import {
createAsyncMiddleware,
JsonRpcEngine,
JsonRpcFailure,
JsonRpcSuccess,
JsonRpcVersion,
} from 'json-rpc-engine';
import {
EthProvider,

@@ -87,3 +93,7 @@ EthMethod,

config.prependMiddleware?.forEach((middleware) => engine.push(middleware));
config.prependMiddleware?.forEach((middleware) =>
// TODO: Need to typecast because JSON RPC engine middleware can't have
// additional props on it, can get rid of this once we get rid of JSON RPC engine
engine.push(createAsyncMiddleware(middleware as any)),
);

@@ -90,0 +100,0 @@ // Handles static responses

@@ -133,3 +133,8 @@ import { ethErrors } from 'eth-rpc-errors';

const { config } = requestContext;
const transaction = await createBitskiTransaction(method, params, requestContext);
const transaction = await createBitskiTransaction(
method,
params,
requestContext.chain,
requestContext.config.additionalSigningContext,
);

@@ -136,0 +141,0 @@ // If we have a callback URL, use the redirect flow

@@ -10,3 +10,3 @@ import {

} from 'eth-provider-types';
import { JsonRpcMiddleware } from 'json-rpc-engine';
import { JsonRpcMiddleware, JsonRpcRequest, PendingJsonRpcResponse } from 'json-rpc-engine';

@@ -46,6 +46,7 @@ export interface User {

prependMiddleware?: JsonRpcMiddleware<unknown[], unknown>[];
prependMiddleware?: ProviderMiddleware[];
pollingInterval?: number;
disableCaching?: boolean;
disableValidation?: boolean;
additionalSigningContext?: Record<string, string>;

@@ -77,3 +78,3 @@ clientId: string;

*/
export interface RequestContext {
export interface RequestContext<T = unknown> {
// The current chain the request is being made on

@@ -85,5 +86,3 @@ chain: EthChainDefinitionWithRpcUrl;

// Additional parameters added to the context of a sign request, e.g. the origin
// that is attempting to sign
signContext?: Record<string, string>;
extra?: T;

@@ -107,2 +106,8 @@ // Allows middleware to emit an event on the provider

export type ProviderMiddleware<T = unknown[], U = unknown, V = unknown> = (
req: JsonRpcRequest<T> & { context: RequestContext<V> },
res: PendingJsonRpcResponse<U>,
next: () => Promise<void>,
) => Promise<void>;
export type EthSignMethod =

@@ -109,0 +114,0 @@ | EthMethod.eth_sendTransaction

import { EthMethod, EthTransactionSend, TypedData } from 'eth-provider-types';
import { ethErrors } from 'eth-rpc-errors';
import { SUPPORTED_CHAIN_IDS } from '../constants';
import {
EthSignMethod,
EthSignMethodParams,
EthChainDefinitionWithRpcUrl,
RequestContext,
} from '../types';
import { EthSignMethod, EthSignMethodParams, EthChainDefinitionWithRpcUrl } from '../types';
import { v4 as uuid } from 'uuid';

@@ -47,5 +42,6 @@

params: EthSignMethodParams[T],
requestContext: Pick<RequestContext, 'chain' | 'signContext'>,
chain: EthChainDefinitionWithRpcUrl,
additionalContext?: Record<string, string>,
): Transaction => {
const context = createContext(method, params, requestContext.chain, requestContext);
const context = createContext(method, params, chain, additionalContext);
const kind = kindForMethod(method);

@@ -65,3 +61,3 @@ const extractedPayload = createPayload(method, params);

chain: EthChainDefinitionWithRpcUrl,
requestContext: Pick<RequestContext, 'chain' | 'signContext'>,
additionalContext?: Record<string, string>,
): TransactionContext => {

@@ -76,3 +72,3 @@ switch (method) {

rpcUrl: !SUPPORTED_CHAIN_IDS.includes(chain.chainId) ? chain.rpcUrls[0] : undefined,
...requestContext.signContext,
...additionalContext,
};

@@ -88,3 +84,3 @@ }

from: params[0] as string,
...requestContext.signContext,
...additionalContext,
};

@@ -91,0 +87,0 @@ }

@@ -297,5 +297,3 @@ import { EthMethod } from 'eth-provider-types';

try {
createBitskiTransaction(EthMethod.eth_sendTransaction, undefined as any, {
chain: Mainnet,
});
createBitskiTransaction(EthMethod.eth_sendTransaction, undefined as any, Mainnet);
} catch (error) {

@@ -306,3 +304,3 @@ expect(error).toMatchObject({ message: 'Missing transaction' });

try {
createBitskiTransaction(EthMethod.eth_sendTransaction, [] as any, { chain: Mainnet });
createBitskiTransaction(EthMethod.eth_sendTransaction, [] as any, Mainnet);
} catch (error) {

@@ -313,3 +311,3 @@ expect(error).toMatchObject({ message: 'Missing transaction' });

try {
createBitskiTransaction(EthMethod.eth_sign, undefined as any, { chain: Mainnet });
createBitskiTransaction(EthMethod.eth_sign, undefined as any, Mainnet);
} catch (error) {

@@ -320,3 +318,3 @@ expect(error).toMatchObject({ message: 'Missing message' });

try {
createBitskiTransaction(EthMethod.eth_sign, [] as any, { chain: Mainnet });
createBitskiTransaction(EthMethod.eth_sign, [] as any, Mainnet);
} catch (error) {

@@ -327,3 +325,3 @@ expect(error).toMatchObject({ message: 'Missing message' });

try {
createBitskiTransaction('personal_sign', undefined as any, { chain: Mainnet });
createBitskiTransaction('personal_sign', undefined as any, Mainnet);
} catch (error) {

@@ -334,3 +332,3 @@ expect(error).toMatchObject({ message: 'Missing message' });

try {
createBitskiTransaction('personal_sign', [] as any, { chain: Mainnet });
createBitskiTransaction('personal_sign', [] as any, Mainnet);
} catch (error) {

@@ -341,5 +339,3 @@ expect(error).toMatchObject({ message: 'Missing message' });

try {
createBitskiTransaction(EthMethod.eth_signTypedData_v3, undefined as any, {
chain: Mainnet,
});
createBitskiTransaction(EthMethod.eth_signTypedData_v3, undefined as any, Mainnet);
} catch (error) {

@@ -350,5 +346,3 @@ expect(error).toMatchObject({ message: 'Missing from' });

try {
createBitskiTransaction(EthMethod.eth_signTypedData_v4, undefined as any, {
chain: Mainnet,
});
createBitskiTransaction(EthMethod.eth_signTypedData_v4, undefined as any, Mainnet);
} catch (error) {

@@ -359,3 +353,3 @@ expect(error).toMatchObject({ message: 'Missing from' });

try {
createBitskiTransaction(EthMethod.eth_signTypedData, [] as any, { chain: Mainnet });
createBitskiTransaction(EthMethod.eth_signTypedData, [] as any, Mainnet);
} catch (error) {

@@ -366,3 +360,3 @@ expect(error).toMatchObject({ message: 'Missing from' });

try {
createBitskiTransaction(EthMethod.eth_signTypedData_v1, [] as any, { chain: Mainnet });
createBitskiTransaction(EthMethod.eth_signTypedData_v1, [] as any, Mainnet);
} catch (error) {

@@ -382,5 +376,3 @@ expect(error).toMatchObject({ message: 'Missing from' });

const transaction = createBitskiTransaction(EthMethod.eth_sendTransaction, [txn], {
chain: Mainnet,
});
const transaction = createBitskiTransaction(EthMethod.eth_sendTransaction, [txn], Mainnet);

@@ -412,6 +404,4 @@ expect(transaction).toMatchObject({

const transaction = createBitskiTransaction(EthMethod.eth_sendTransaction, [txn], {
chain: {
chainId: '0x12345',
rpcUrls: ['https://custom.rpc'],
},
chainId: '0x12345',
rpcUrls: ['https://custom.rpc'],
});

@@ -439,3 +429,3 @@

['0x12312312312312312312312312312312312312', '0xf00'],
{ chain: Mainnet },
Mainnet,
);

@@ -442,0 +432,0 @@

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