bitski-provider
Advanced tools
Comparing version 3.2.0 to 3.3.0
# bitski-provider | ||
## 3.3.0 | ||
### Minor Changes | ||
- [#390](https://github.com/BitskiCo/bitski-js/pull/390) [`007bdbd`](https://github.com/BitskiCo/bitski-js/commit/007bdbd583a0c59f9b55e38c2e9eb23e710a88d6) Thanks [@chronicIntrovert](https://github.com/chronicIntrovert)! - Add support for paymaster and waas config in bitski-provider | ||
## 3.2.0 | ||
@@ -4,0 +10,0 @@ |
@@ -80,3 +80,3 @@ import SafeEventEmitter from '@metamask/safe-event-emitter'; | ||
} | ||
this.config = Object.assign(Object.assign({}, config), { fetch: (_b = config.fetch) !== null && _b !== void 0 ? _b : fetch, additionalHeaders: Object.assign({ 'X-API-KEY': appId, 'X-CLIENT-ID': appId, 'X-CLIENT-VERSION': "bitski-provider-v3.2.0" }, ((_c = config.additionalHeaders) !== null && _c !== void 0 ? _c : {})), apiBaseUrl, 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 }); | ||
this.config = Object.assign(Object.assign({}, config), { fetch: (_b = config.fetch) !== null && _b !== void 0 ? _b : fetch, additionalHeaders: Object.assign({ 'X-API-KEY': appId, 'X-CLIENT-ID': appId, 'X-CLIENT-VERSION': "bitski-provider-v3.3.0" }, ((_c = config.additionalHeaders) !== null && _c !== void 0 ? _c : {})), apiBaseUrl, 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 }); | ||
this.store = new BitskiProviderStateStore(this.config.store); | ||
@@ -181,2 +181,3 @@ // Setup the engine | ||
config: this.config, | ||
paymaster: this.config.paymaster, | ||
store: this.store, | ||
@@ -183,0 +184,0 @@ emit: this.events.emit.bind(this.events), |
@@ -32,3 +32,3 @@ import { fetchJsonWithRetry } from '../utils/fetch'; | ||
const { config } = requestContext; | ||
const transaction = await createBitskiTransaction(method, params, requestContext.chain, requestContext.config.additionalSigningContext); | ||
const transaction = await createBitskiTransaction(method, params, requestContext.chain, requestContext.paymaster, requestContext.config.additionalSigningContext); | ||
// If we have a callback URL, use the redirect flow | ||
@@ -35,0 +35,0 @@ if (config.transactionCallbackUrl) { |
export const getSignerUrl = (transactionId, config) => { | ||
var _a, _b; | ||
var _a, _b, _c, _d, _e; | ||
const searchParams = (_a = config.signerQueryParams) !== null && _a !== void 0 ? _a : new URLSearchParams(); | ||
@@ -7,4 +7,7 @@ if (config.transactionCallbackUrl) { | ||
} | ||
if ((_b = config.waas) === null || _b === void 0 ? void 0 : _b.userId) { | ||
const federatedId = btoa(`${config.appId}:${config.waas.userId}`); | ||
if (((_b = config.waas) === null || _b === void 0 ? void 0 : _b.enabled) || ((_c = config.waas) === null || _c === void 0 ? void 0 : _c.userId)) { | ||
let federatedId = btoa(`${config.appId}`); | ||
if ((_d = config.waas) === null || _d === void 0 ? void 0 : _d.userId) { | ||
federatedId = btoa(`${config.appId}:${(_e = config.waas) === null || _e === void 0 ? void 0 : _e.userId}`); | ||
} | ||
searchParams.set('loginHint', `fa_${federatedId}`); | ||
@@ -11,0 +14,0 @@ } |
@@ -9,4 +9,4 @@ import { EthMethod } from 'eth-provider-types'; | ||
*/ | ||
export const createBitskiTransaction = (method, params, chain, additionalContext) => { | ||
const context = createContext(method, params, chain, additionalContext); | ||
export const createBitskiTransaction = (method, params, chain, paymaster, additionalContext) => { | ||
const context = createContext(method, params, chain, paymaster, additionalContext); | ||
const kind = kindForMethod(method); | ||
@@ -21,3 +21,3 @@ const extractedPayload = createPayload(method, params); | ||
}; | ||
const createContext = (method, params, chain, additionalContext) => { | ||
const createContext = (method, params, chain, paymaster, additionalContext) => { | ||
switch (method) { | ||
@@ -28,3 +28,3 @@ case 'personal_sign': | ||
case EthMethod.eth_signTransaction: { | ||
return Object.assign({ chainId: parseInt(chain.chainId, 16), rpcUrl: !SUPPORTED_CHAIN_IDS.includes(chain.chainId) ? chain.rpcUrls[0] : undefined }, additionalContext); | ||
return Object.assign(Object.assign({ chainId: parseInt(chain.chainId, 16), rpcUrl: !SUPPORTED_CHAIN_IDS.includes(chain.chainId) ? chain.rpcUrls[0] : undefined }, paymaster), additionalContext); | ||
} | ||
@@ -37,3 +37,3 @@ case EthMethod.eth_signTypedData: | ||
if (params && (params === null || params === void 0 ? void 0 : params.length) > 0) { | ||
return Object.assign({ from: params[0], chainId: parseInt(chain.chainId, 16), rpcUrl: !SUPPORTED_CHAIN_IDS.includes(chain.chainId) ? chain.rpcUrls[0] : undefined }, additionalContext); | ||
return Object.assign(Object.assign({ from: params[0], chainId: parseInt(chain.chainId, 16), rpcUrl: !SUPPORTED_CHAIN_IDS.includes(chain.chainId) ? chain.rpcUrls[0] : undefined }, paymaster), additionalContext); | ||
} | ||
@@ -40,0 +40,0 @@ throw ethErrors.rpc.invalidParams('Missing from'); |
@@ -86,3 +86,3 @@ "use strict"; | ||
} | ||
this.config = Object.assign(Object.assign({}, config), { fetch: (_b = config.fetch) !== null && _b !== void 0 ? _b : fetch, additionalHeaders: Object.assign({ 'X-API-KEY': appId, 'X-CLIENT-ID': appId, 'X-CLIENT-VERSION': "bitski-provider-v3.2.0" }, ((_c = config.additionalHeaders) !== null && _c !== void 0 ? _c : {})), apiBaseUrl, 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 }); | ||
this.config = Object.assign(Object.assign({}, config), { fetch: (_b = config.fetch) !== null && _b !== void 0 ? _b : fetch, additionalHeaders: Object.assign({ 'X-API-KEY': appId, 'X-CLIENT-ID': appId, 'X-CLIENT-VERSION': "bitski-provider-v3.3.0" }, ((_c = config.additionalHeaders) !== null && _c !== void 0 ? _c : {})), apiBaseUrl, 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 }); | ||
this.store = new store_1.BitskiProviderStateStore(this.config.store); | ||
@@ -187,2 +187,3 @@ // Setup the engine | ||
config: this.config, | ||
paymaster: this.config.paymaster, | ||
store: this.store, | ||
@@ -189,0 +190,0 @@ emit: this.events.emit.bind(this.events), |
@@ -34,3 +34,3 @@ "use strict"; | ||
const { config } = requestContext; | ||
const transaction = await (0, transaction_1.createBitskiTransaction)(method, params, requestContext.chain, requestContext.config.additionalSigningContext); | ||
const transaction = await (0, transaction_1.createBitskiTransaction)(method, params, requestContext.chain, requestContext.paymaster, requestContext.config.additionalSigningContext); | ||
// If we have a callback URL, use the redirect flow | ||
@@ -37,0 +37,0 @@ if (config.transactionCallbackUrl) { |
@@ -5,3 +5,3 @@ "use strict"; | ||
const getSignerUrl = (transactionId, config) => { | ||
var _a, _b; | ||
var _a, _b, _c, _d, _e; | ||
const searchParams = (_a = config.signerQueryParams) !== null && _a !== void 0 ? _a : new URLSearchParams(); | ||
@@ -11,4 +11,7 @@ if (config.transactionCallbackUrl) { | ||
} | ||
if ((_b = config.waas) === null || _b === void 0 ? void 0 : _b.userId) { | ||
const federatedId = btoa(`${config.appId}:${config.waas.userId}`); | ||
if (((_b = config.waas) === null || _b === void 0 ? void 0 : _b.enabled) || ((_c = config.waas) === null || _c === void 0 ? void 0 : _c.userId)) { | ||
let federatedId = btoa(`${config.appId}`); | ||
if ((_d = config.waas) === null || _d === void 0 ? void 0 : _d.userId) { | ||
federatedId = btoa(`${config.appId}:${(_e = config.waas) === null || _e === void 0 ? void 0 : _e.userId}`); | ||
} | ||
searchParams.set('loginHint', `fa_${federatedId}`); | ||
@@ -15,0 +18,0 @@ } |
import { EthChainDefinition, EthEvent, EthEventParams, EthMethod, EthMethodParams, EthRequest, EthResult } from 'eth-provider-types'; | ||
import { JsonRpcRequest, PendingJsonRpcResponse } from 'json-rpc-engine'; | ||
import type { BitskiProviderStateStore } from './store'; | ||
import { PaymasterDefinition, WaasDefinition } from './utils/transaction'; | ||
export interface User { | ||
@@ -23,2 +24,3 @@ id: string; | ||
additionalHeaders: Record<string, string>; | ||
paymaster?: PaymasterDefinition | PaymasterDefinition[]; | ||
prependMiddleware?: ProviderMiddleware<unknown[], unknown, Extra>[]; | ||
@@ -36,6 +38,3 @@ pollingInterval?: number; | ||
signerQueryParams?: URLSearchParams; | ||
waas?: { | ||
userId: string; | ||
transactionProxyUrl: string; | ||
}; | ||
waas?: WaasDefinition; | ||
store: BitskiProviderStore; | ||
@@ -59,2 +58,3 @@ sign: SignFn; | ||
chain: EthChainDefinitionWithRpcUrl; | ||
paymaster?: PaymasterDefinition | PaymasterDefinition[]; | ||
config: InternalBitskiProviderConfig<Extra>; | ||
@@ -61,0 +61,0 @@ store: BitskiProviderStateStore; |
@@ -18,5 +18,16 @@ import { EthTransactionSend, TypedData } from 'eth-provider-types'; | ||
} | ||
export interface PaymasterDefinition { | ||
paymasterUrl: string; | ||
policyId?: string; | ||
rpcMethod?: string; | ||
} | ||
export interface WaasDefinition { | ||
enabled: boolean; | ||
userId?: string; | ||
transactionProxyUrl?: string; | ||
} | ||
export interface TransactionContext { | ||
chainId?: number; | ||
rpcUrl?: string; | ||
paymaster?: PaymasterDefinition | PaymasterDefinition[]; | ||
from?: string; | ||
@@ -33,2 +44,2 @@ [key: string]: unknown; | ||
*/ | ||
export declare const createBitskiTransaction: <T extends EthSignMethod>(method: T, params: EthSignMethodParams[T], chain: EthChainDefinitionWithRpcUrl, additionalContext?: Record<string, string> | undefined) => Transaction; | ||
export declare const createBitskiTransaction: <T extends EthSignMethod>(method: T, params: EthSignMethodParams[T], chain: EthChainDefinitionWithRpcUrl, paymaster?: PaymasterDefinition | PaymasterDefinition[] | undefined, additionalContext?: Record<string, string> | undefined) => Transaction; |
@@ -12,4 +12,4 @@ "use strict"; | ||
*/ | ||
const createBitskiTransaction = (method, params, chain, additionalContext) => { | ||
const context = createContext(method, params, chain, additionalContext); | ||
const createBitskiTransaction = (method, params, chain, paymaster, additionalContext) => { | ||
const context = createContext(method, params, chain, paymaster, additionalContext); | ||
const kind = kindForMethod(method); | ||
@@ -25,3 +25,3 @@ const extractedPayload = createPayload(method, params); | ||
exports.createBitskiTransaction = createBitskiTransaction; | ||
const createContext = (method, params, chain, additionalContext) => { | ||
const createContext = (method, params, chain, paymaster, additionalContext) => { | ||
switch (method) { | ||
@@ -32,3 +32,3 @@ case 'personal_sign': | ||
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); | ||
return Object.assign(Object.assign({ chainId: parseInt(chain.chainId, 16), rpcUrl: !constants_1.SUPPORTED_CHAIN_IDS.includes(chain.chainId) ? chain.rpcUrls[0] : undefined }, paymaster), additionalContext); | ||
} | ||
@@ -41,3 +41,3 @@ case eth_provider_types_1.EthMethod.eth_signTypedData: | ||
if (params && (params === null || params === void 0 ? void 0 : params.length) > 0) { | ||
return Object.assign({ from: params[0], chainId: parseInt(chain.chainId, 16), rpcUrl: !constants_1.SUPPORTED_CHAIN_IDS.includes(chain.chainId) ? chain.rpcUrls[0] : undefined }, additionalContext); | ||
return Object.assign(Object.assign({ from: params[0], chainId: parseInt(chain.chainId, 16), rpcUrl: !constants_1.SUPPORTED_CHAIN_IDS.includes(chain.chainId) ? chain.rpcUrls[0] : undefined }, paymaster), additionalContext); | ||
} | ||
@@ -44,0 +44,0 @@ throw eth_rpc_errors_1.ethErrors.rpc.invalidParams('Missing from'); |
@@ -12,3 +12,3 @@ { | ||
}, | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"scripts": { | ||
@@ -15,0 +15,0 @@ "test": "jest", |
@@ -267,2 +267,3 @@ import SafeEventEmitter from '@metamask/safe-event-emitter'; | ||
config: this.config, | ||
paymaster: this.config.paymaster, | ||
store: this.store, | ||
@@ -269,0 +270,0 @@ emit: this.events.emit.bind(this.events), |
@@ -61,2 +61,3 @@ import { InternalBitskiProviderConfig, RequestContext, SignFn } from '../types'; | ||
requestContext.chain, | ||
requestContext.paymaster, | ||
requestContext.config.additionalSigningContext, | ||
@@ -63,0 +64,0 @@ ); |
@@ -13,5 +13,9 @@ import { InternalBitskiProviderConfig } from '../types'; | ||
if (config.waas?.userId) { | ||
const federatedId = btoa(`${config.appId}:${config.waas.userId}`); | ||
if (config.waas?.enabled || config.waas?.userId) { | ||
let federatedId = btoa(`${config.appId}`); | ||
if (config.waas?.userId) { | ||
federatedId = btoa(`${config.appId}:${config.waas?.userId}`); | ||
} | ||
searchParams.set('loginHint', `fa_${federatedId}`); | ||
@@ -18,0 +22,0 @@ } |
@@ -12,2 +12,3 @@ import { | ||
import type { BitskiProviderStateStore } from './store'; | ||
import { PaymasterDefinition, WaasDefinition } from './utils/transaction'; | ||
@@ -48,3 +49,3 @@ export interface User { | ||
additionalHeaders: Record<string, string>; | ||
paymaster?: PaymasterDefinition | PaymasterDefinition[]; | ||
prependMiddleware?: ProviderMiddleware<unknown[], unknown, Extra>[]; | ||
@@ -65,6 +66,3 @@ pollingInterval?: number; | ||
waas?: { | ||
userId: string; | ||
transactionProxyUrl: string; | ||
}; | ||
waas?: WaasDefinition; | ||
@@ -96,2 +94,3 @@ store: BitskiProviderStore; | ||
chain: EthChainDefinitionWithRpcUrl; | ||
paymaster?: PaymasterDefinition | PaymasterDefinition[]; | ||
@@ -98,0 +97,0 @@ // The configuration of the provider |
@@ -25,5 +25,18 @@ import { EthMethod, EthTransactionSend, TypedData } from 'eth-provider-types'; | ||
export interface PaymasterDefinition { | ||
paymasterUrl: string; | ||
policyId?: string; | ||
rpcMethod?: string; | ||
} | ||
export interface WaasDefinition { | ||
enabled: boolean; | ||
userId?: string; | ||
transactionProxyUrl?: string; | ||
} | ||
export interface TransactionContext { | ||
chainId?: number; | ||
rpcUrl?: string; | ||
paymaster?: PaymasterDefinition | PaymasterDefinition[]; | ||
from?: string; | ||
@@ -46,5 +59,6 @@ [key: string]: unknown; | ||
chain: EthChainDefinitionWithRpcUrl, | ||
paymaster?: PaymasterDefinition | PaymasterDefinition[], | ||
additionalContext?: Record<string, string>, | ||
): Transaction => { | ||
const context = createContext(method, params, chain, additionalContext); | ||
const context = createContext(method, params, chain, paymaster, additionalContext); | ||
const kind = kindForMethod(method); | ||
@@ -64,2 +78,3 @@ const extractedPayload = createPayload(method, params); | ||
chain: EthChainDefinitionWithRpcUrl, | ||
paymaster?: PaymasterDefinition | PaymasterDefinition[], | ||
additionalContext?: Record<string, string>, | ||
@@ -75,2 +90,3 @@ ): TransactionContext => { | ||
rpcUrl: !SUPPORTED_CHAIN_IDS.includes(chain.chainId) ? chain.rpcUrls[0] : undefined, | ||
...paymaster, | ||
...additionalContext, | ||
@@ -89,2 +105,3 @@ }; | ||
rpcUrl: !SUPPORTED_CHAIN_IDS.includes(chain.chainId) ? chain.rpcUrls[0] : undefined, | ||
...paymaster, | ||
...additionalContext, | ||
@@ -91,0 +108,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
Sorry, the diff of this file is not supported yet
398074
8265