web3-types
Advanced tools
Comparing version 1.1.2-dev.a325689.0 to 1.1.2-dev.da3e2f5.0
@@ -29,2 +29,3 @@ import { Address, Uint } from './eth_types.js'; | ||
readonly syncWithContext?: boolean; | ||
readonly dataInputFill?: 'data' | 'input' | 'both'; | ||
} | ||
@@ -49,2 +50,4 @@ export interface NonPayableCallOptions { | ||
type?: string | number; | ||
data?: HexString; | ||
input?: HexString; | ||
} | ||
@@ -51,0 +54,0 @@ export interface PayableCallOptions extends NonPayableCallOptions { |
@@ -49,2 +49,5 @@ /// <reference types="node" /> | ||
} | ||
export declare type Eip1193Compatible<API extends Web3APISpec = EthExecutionAPI> = Omit<Omit<Web3BaseProvider, 'request'>, 'asEIP1193Provider'> & { | ||
request<Method extends Web3APIMethod<API>, ResultType = Web3APIReturnType<API, Method> | unknown>(request: Web3APIPayload<API, Method>): Promise<ResultType>; | ||
}; | ||
export declare abstract class Web3BaseProvider<API extends Web3APISpec = EthExecutionAPI> implements LegacySendProvider, LegacySendAsyncProvider, EIP1193Provider<API> { | ||
@@ -66,2 +69,19 @@ static isWeb3Provider(provider: unknown): boolean; | ||
sendAsync<R = JsonRpcResult, P = unknown>(payload: JsonRpcPayload<P>): Promise<JsonRpcResponse<R, JsonRpcResult>>; | ||
/** | ||
* Modify the return type of the request method to be fully compatible with EIP-1193 | ||
* | ||
* [deprecated] In the future major releases (\>= v5) all providers are supposed to be fully compatible with EIP-1193. | ||
* So this method will not be needed and would not be available in the future. | ||
* | ||
* @returns A new instance of the provider with the request method fully compatible with EIP-1193 | ||
* | ||
* @example | ||
* ```ts | ||
* const provider = new Web3HttpProvider('http://localhost:8545'); | ||
* const fullyCompatibleProvider = provider.asEIP1193Provider(); | ||
* const result = await fullyCompatibleProvider.request({ method: 'eth_getBalance' }); | ||
* console.log(result); // '0x0234c8a3397aab58' or something like that | ||
* ``` | ||
*/ | ||
asEIP1193Provider(): Eip1193Compatible<API>; | ||
abstract request<Method extends Web3APIMethod<API>, ResultType = Web3APIReturnType<API, Method> | unknown>(args: Web3APIPayload<API, Method>): Promise<JsonRpcResponseWithResult<ResultType>>; | ||
@@ -68,0 +88,0 @@ abstract on(type: 'disconnect', listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void; |
@@ -55,4 +55,37 @@ "use strict"; | ||
} | ||
/** | ||
* Modify the return type of the request method to be fully compatible with EIP-1193 | ||
* | ||
* [deprecated] In the future major releases (\>= v5) all providers are supposed to be fully compatible with EIP-1193. | ||
* So this method will not be needed and would not be available in the future. | ||
* | ||
* @returns A new instance of the provider with the request method fully compatible with EIP-1193 | ||
* | ||
* @example | ||
* ```ts | ||
* const provider = new Web3HttpProvider('http://localhost:8545'); | ||
* const fullyCompatibleProvider = provider.asEIP1193Provider(); | ||
* const result = await fullyCompatibleProvider.request({ method: 'eth_getBalance' }); | ||
* console.log(result); // '0x0234c8a3397aab58' or something like that | ||
* ``` | ||
*/ | ||
asEIP1193Provider() { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
const newObj = Object.create(this); | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
const originalRequest = newObj.request; | ||
newObj.request = function request(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion | ||
const response = (yield originalRequest(args)); | ||
return response.result; | ||
}); | ||
}; | ||
// @ts-expect-error the property should not be available in the new object because of using Object.create(this). | ||
// But it is available if we do not delete it. | ||
newObj.asEIP1193Provider = undefined; // to prevent the user for calling this method again | ||
return newObj; | ||
} | ||
} | ||
exports.Web3BaseProvider = Web3BaseProvider; | ||
//# sourceMappingURL=web3_base_provider.js.map |
@@ -52,3 +52,36 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
/** | ||
* Modify the return type of the request method to be fully compatible with EIP-1193 | ||
* | ||
* [deprecated] In the future major releases (\>= v5) all providers are supposed to be fully compatible with EIP-1193. | ||
* So this method will not be needed and would not be available in the future. | ||
* | ||
* @returns A new instance of the provider with the request method fully compatible with EIP-1193 | ||
* | ||
* @example | ||
* ```ts | ||
* const provider = new Web3HttpProvider('http://localhost:8545'); | ||
* const fullyCompatibleProvider = provider.asEIP1193Provider(); | ||
* const result = await fullyCompatibleProvider.request({ method: 'eth_getBalance' }); | ||
* console.log(result); // '0x0234c8a3397aab58' or something like that | ||
* ``` | ||
*/ | ||
asEIP1193Provider() { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
const newObj = Object.create(this); | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
const originalRequest = newObj.request; | ||
newObj.request = function request(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion | ||
const response = (yield originalRequest(args)); | ||
return response.result; | ||
}); | ||
}; | ||
// @ts-expect-error the property should not be available in the new object because of using Object.create(this). | ||
// But it is available if we do not delete it. | ||
newObj.asEIP1193Provider = undefined; // to prevent the user for calling this method again | ||
return newObj; | ||
} | ||
} | ||
//# sourceMappingURL=web3_base_provider.js.map |
@@ -29,2 +29,3 @@ import { Address, Uint } from './eth_types.js'; | ||
readonly syncWithContext?: boolean; | ||
readonly dataInputFill?: 'data' | 'input' | 'both'; | ||
} | ||
@@ -49,2 +50,4 @@ export interface NonPayableCallOptions { | ||
type?: string | number; | ||
data?: HexString; | ||
input?: HexString; | ||
} | ||
@@ -51,0 +54,0 @@ export interface PayableCallOptions extends NonPayableCallOptions { |
@@ -49,2 +49,5 @@ /// <reference types="node" /> | ||
} | ||
export declare type Eip1193Compatible<API extends Web3APISpec = EthExecutionAPI> = Omit<Omit<Web3BaseProvider, 'request'>, 'asEIP1193Provider'> & { | ||
request<Method extends Web3APIMethod<API>, ResultType = Web3APIReturnType<API, Method> | unknown>(request: Web3APIPayload<API, Method>): Promise<ResultType>; | ||
}; | ||
export declare abstract class Web3BaseProvider<API extends Web3APISpec = EthExecutionAPI> implements LegacySendProvider, LegacySendAsyncProvider, EIP1193Provider<API> { | ||
@@ -66,2 +69,19 @@ static isWeb3Provider(provider: unknown): boolean; | ||
sendAsync<R = JsonRpcResult, P = unknown>(payload: JsonRpcPayload<P>): Promise<JsonRpcResponse<R, JsonRpcResult>>; | ||
/** | ||
* Modify the return type of the request method to be fully compatible with EIP-1193 | ||
* | ||
* [deprecated] In the future major releases (\>= v5) all providers are supposed to be fully compatible with EIP-1193. | ||
* So this method will not be needed and would not be available in the future. | ||
* | ||
* @returns A new instance of the provider with the request method fully compatible with EIP-1193 | ||
* | ||
* @example | ||
* ```ts | ||
* const provider = new Web3HttpProvider('http://localhost:8545'); | ||
* const fullyCompatibleProvider = provider.asEIP1193Provider(); | ||
* const result = await fullyCompatibleProvider.request({ method: 'eth_getBalance' }); | ||
* console.log(result); // '0x0234c8a3397aab58' or something like that | ||
* ``` | ||
*/ | ||
asEIP1193Provider(): Eip1193Compatible<API>; | ||
abstract request<Method extends Web3APIMethod<API>, ResultType = Web3APIReturnType<API, Method> | unknown>(args: Web3APIPayload<API, Method>): Promise<JsonRpcResponseWithResult<ResultType>>; | ||
@@ -68,0 +88,0 @@ abstract on(type: 'disconnect', listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void; |
{ | ||
"name": "web3-types", | ||
"version": "1.1.2-dev.a325689.0+a325689", | ||
"version": "1.1.2-dev.da3e2f5.0+da3e2f5", | ||
"description": "Provide the common data structures and interfaces for web3 modules.", | ||
@@ -50,4 +50,4 @@ "main": "./lib/commonjs/index.js", | ||
"eslint": "^8.20.0", | ||
"eslint-config-base-web3": "0.1.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-config-web3-base": "0.1.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
@@ -60,3 +60,3 @@ "jest": "^28.1.3", | ||
}, | ||
"gitHead": "a325689a324c5bbfe050f5cc9af2ba41e44d1bfd" | ||
"gitHead": "da3e2f5d0fb4f042ae58e312b4515a07f9e30ca6" | ||
} |
@@ -48,2 +48,7 @@ /* | ||
readonly syncWithContext?: boolean; | ||
readonly dataInputFill?: 'data' | 'input' | 'both'; | ||
/** | ||
* this will make calls default to `data`, `input` or `both` | ||
*/ | ||
} | ||
@@ -69,2 +74,4 @@ | ||
type?: string | number; | ||
data?: HexString; | ||
input?: HexString; | ||
} | ||
@@ -71,0 +78,0 @@ |
@@ -136,2 +136,15 @@ /* | ||
export type Eip1193Compatible<API extends Web3APISpec = EthExecutionAPI> = Omit< | ||
// eslint-disable-next-line no-use-before-define | ||
Omit<Web3BaseProvider, 'request'>, | ||
'asEIP1193Provider' | ||
> & { | ||
request< | ||
Method extends Web3APIMethod<API>, | ||
ResultType = Web3APIReturnType<API, Method> | unknown, | ||
>( | ||
request: Web3APIPayload<API, Method>, | ||
): Promise<ResultType>; | ||
}; | ||
// Provider interface compatible with EIP-1193 | ||
@@ -193,2 +206,36 @@ // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1193.md | ||
/** | ||
* Modify the return type of the request method to be fully compatible with EIP-1193 | ||
* | ||
* [deprecated] In the future major releases (\>= v5) all providers are supposed to be fully compatible with EIP-1193. | ||
* So this method will not be needed and would not be available in the future. | ||
* | ||
* @returns A new instance of the provider with the request method fully compatible with EIP-1193 | ||
* | ||
* @example | ||
* ```ts | ||
* const provider = new Web3HttpProvider('http://localhost:8545'); | ||
* const fullyCompatibleProvider = provider.asEIP1193Provider(); | ||
* const result = await fullyCompatibleProvider.request({ method: 'eth_getBalance' }); | ||
* console.log(result); // '0x0234c8a3397aab58' or something like that | ||
* ``` | ||
*/ | ||
public asEIP1193Provider(): Eip1193Compatible<API> { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
const newObj = Object.create(this) as Eip1193Compatible<API>; | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
const originalRequest = newObj.request; | ||
newObj.request = async function request( | ||
args: Web3APIPayload<API, Web3APIMethod<API>>, | ||
): Promise<unknown> { | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion | ||
const response = (await originalRequest(args)) as JsonRpcResponseWithResult<unknown>; | ||
return response.result; | ||
} as typeof newObj.request; | ||
// @ts-expect-error the property should not be available in the new object because of using Object.create(this). | ||
// But it is available if we do not delete it. | ||
newObj.asEIP1193Provider = undefined; // to prevent the user for calling this method again | ||
return newObj; | ||
} | ||
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1193.md#request | ||
@@ -195,0 +242,0 @@ public abstract request< |
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
273483
4949