viem 0.0.0-main.20230603T024327 → 0.0.0-main.20230604T221342
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/dist/cjs/actions/ens/getEnsAddress.js +34 -23
- package/dist/cjs/actions/ens/getEnsAddress.js.map +1 -1
- package/dist/cjs/actions/public/call.js +1 -1
- package/dist/cjs/actions/public/call.js.map +1 -1
- package/dist/cjs/actions/public/createContractEventFilter.js +2 -1
- package/dist/cjs/actions/public/createContractEventFilter.js.map +1 -1
- package/dist/cjs/actions/public/createEventFilter.js +2 -1
- package/dist/cjs/actions/public/createEventFilter.js.map +1 -1
- package/dist/cjs/actions/public/estimateGas.js.map +1 -1
- package/dist/cjs/actions/public/getBlock.js.map +1 -1
- package/dist/cjs/actions/public/getBlockTransactionCount.js +1 -1
- package/dist/cjs/actions/public/getBlockTransactionCount.js.map +1 -1
- package/dist/cjs/actions/public/getChainId.js +3 -1
- package/dist/cjs/actions/public/getChainId.js.map +1 -1
- package/dist/cjs/actions/public/getFilterChanges.js +11 -3
- package/dist/cjs/actions/public/getFilterChanges.js.map +1 -1
- package/dist/cjs/actions/public/getFilterLogs.js +10 -2
- package/dist/cjs/actions/public/getFilterLogs.js.map +1 -1
- package/dist/cjs/actions/public/getGasPrice.js.map +1 -1
- package/dist/cjs/actions/public/getLogs.js +11 -3
- package/dist/cjs/actions/public/getLogs.js.map +1 -1
- package/dist/cjs/actions/public/getTransactionCount.js.map +1 -1
- package/dist/cjs/clients/createClient.js +1 -1
- package/dist/cjs/clients/createClient.js.map +1 -1
- package/dist/cjs/clients/createPublicClient.js.map +1 -1
- package/dist/cjs/clients/createTestClient.js.map +1 -1
- package/dist/cjs/clients/createWalletClient.js.map +1 -1
- package/dist/cjs/clients/decorators/public.js.map +1 -1
- package/dist/cjs/clients/transports/createTransport.js.map +1 -1
- package/dist/cjs/clients/transports/custom.js.map +1 -1
- package/dist/cjs/clients/transports/fallback.js.map +1 -1
- package/dist/cjs/clients/transports/http.js +25 -7
- package/dist/cjs/clients/transports/http.js.map +1 -1
- package/dist/cjs/clients/transports/webSocket.js +22 -14
- package/dist/cjs/clients/transports/webSocket.js.map +1 -1
- package/dist/cjs/errors/abi.js +15 -1
- package/dist/cjs/errors/abi.js.map +1 -1
- package/dist/cjs/errors/request.js.map +1 -1
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/eip1193.js.map +1 -1
- package/dist/cjs/utils/abi/decodeEventLog.js +10 -2
- package/dist/cjs/utils/abi/decodeEventLog.js.map +1 -1
- package/dist/cjs/utils/ens/encodeLabelhash.js +8 -0
- package/dist/cjs/utils/ens/encodeLabelhash.js.map +1 -0
- package/dist/cjs/utils/ens/encodedLabelToLabelhash.js +18 -0
- package/dist/cjs/utils/ens/encodedLabelToLabelhash.js.map +1 -0
- package/dist/cjs/utils/ens/labelhash.js +2 -1
- package/dist/cjs/utils/ens/labelhash.js.map +1 -1
- package/dist/cjs/utils/ens/namehash.js +5 -1
- package/dist/cjs/utils/ens/namehash.js.map +1 -1
- package/dist/cjs/utils/ens/packetToBytes.js +10 -9
- package/dist/cjs/utils/ens/packetToBytes.js.map +1 -1
- package/dist/cjs/utils/filters/createFilterRequestScope.js.map +1 -1
- package/dist/cjs/utils/formatters/log.js +2 -2
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/rpc.js +12 -17
- package/dist/cjs/utils/rpc.js.map +1 -1
- package/dist/esm/actions/ens/getEnsAddress.js +34 -23
- package/dist/esm/actions/ens/getEnsAddress.js.map +1 -1
- package/dist/esm/actions/public/call.js +1 -1
- package/dist/esm/actions/public/call.js.map +1 -1
- package/dist/esm/actions/public/createContractEventFilter.js +2 -1
- package/dist/esm/actions/public/createContractEventFilter.js.map +1 -1
- package/dist/esm/actions/public/createEventFilter.js +2 -1
- package/dist/esm/actions/public/createEventFilter.js.map +1 -1
- package/dist/esm/actions/public/estimateGas.js.map +1 -1
- package/dist/esm/actions/public/getBlock.js.map +1 -1
- package/dist/esm/actions/public/getBlockTransactionCount.js +1 -1
- package/dist/esm/actions/public/getBlockTransactionCount.js.map +1 -1
- package/dist/esm/actions/public/getChainId.js +3 -1
- package/dist/esm/actions/public/getChainId.js.map +1 -1
- package/dist/esm/actions/public/getFilterChanges.js +11 -3
- package/dist/esm/actions/public/getFilterChanges.js.map +1 -1
- package/dist/esm/actions/public/getFilterLogs.js +10 -2
- package/dist/esm/actions/public/getFilterLogs.js.map +1 -1
- package/dist/esm/actions/public/getGasPrice.js.map +1 -1
- package/dist/esm/actions/public/getLogs.js +11 -3
- package/dist/esm/actions/public/getLogs.js.map +1 -1
- package/dist/esm/actions/public/getTransactionCount.js.map +1 -1
- package/dist/esm/clients/createClient.js +1 -1
- package/dist/esm/clients/createClient.js.map +1 -1
- package/dist/esm/clients/createPublicClient.js.map +1 -1
- package/dist/esm/clients/createTestClient.js.map +1 -1
- package/dist/esm/clients/createWalletClient.js.map +1 -1
- package/dist/esm/clients/decorators/public.js.map +1 -1
- package/dist/esm/clients/transports/createTransport.js.map +1 -1
- package/dist/esm/clients/transports/custom.js.map +1 -1
- package/dist/esm/clients/transports/fallback.js.map +1 -1
- package/dist/esm/clients/transports/http.js +25 -7
- package/dist/esm/clients/transports/http.js.map +1 -1
- package/dist/esm/clients/transports/webSocket.js +22 -14
- package/dist/esm/clients/transports/webSocket.js.map +1 -1
- package/dist/esm/errors/abi.js +15 -1
- package/dist/esm/errors/abi.js.map +1 -1
- package/dist/esm/errors/request.js.map +1 -1
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/eip1193.js.map +1 -1
- package/dist/esm/utils/abi/decodeEventLog.js +10 -2
- package/dist/esm/utils/abi/decodeEventLog.js.map +1 -1
- package/dist/esm/utils/ens/encodeLabelhash.js +4 -0
- package/dist/esm/utils/ens/encodeLabelhash.js.map +1 -0
- package/dist/esm/utils/ens/encodedLabelToLabelhash.js +14 -0
- package/dist/esm/utils/ens/encodedLabelToLabelhash.js.map +1 -0
- package/dist/esm/utils/ens/labelhash.js +2 -1
- package/dist/esm/utils/ens/labelhash.js.map +1 -1
- package/dist/esm/utils/ens/namehash.js +6 -2
- package/dist/esm/utils/ens/namehash.js.map +1 -1
- package/dist/esm/utils/ens/packetToBytes.js +10 -9
- package/dist/esm/utils/ens/packetToBytes.js.map +1 -1
- package/dist/esm/utils/filters/createFilterRequestScope.js.map +1 -1
- package/dist/esm/utils/formatters/log.js +2 -2
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/rpc.js +13 -18
- package/dist/esm/utils/rpc.js.map +1 -1
- package/dist/types/actions/ens/getEnsAddress.d.ts.map +1 -1
- package/dist/types/actions/public/createContractEventFilter.d.ts +8 -3
- package/dist/types/actions/public/createContractEventFilter.d.ts.map +1 -1
- package/dist/types/actions/public/createEventFilter.d.ts +17 -5
- package/dist/types/actions/public/createEventFilter.d.ts.map +1 -1
- package/dist/types/actions/public/getChainId.d.ts.map +1 -1
- package/dist/types/actions/public/getFilterChanges.d.ts +4 -4
- package/dist/types/actions/public/getFilterChanges.d.ts.map +1 -1
- package/dist/types/actions/public/getFilterLogs.d.ts +4 -4
- package/dist/types/actions/public/getFilterLogs.d.ts.map +1 -1
- package/dist/types/actions/public/getLogs.d.ts +10 -4
- package/dist/types/actions/public/getLogs.d.ts.map +1 -1
- package/dist/types/chains.d.ts +4 -4
- package/dist/types/clients/createClient.d.ts +5 -5
- package/dist/types/clients/createClient.d.ts.map +1 -1
- package/dist/types/clients/createPublicClient.d.ts +3 -3
- package/dist/types/clients/createPublicClient.d.ts.map +1 -1
- package/dist/types/clients/createTestClient.d.ts +2 -2
- package/dist/types/clients/createTestClient.d.ts.map +1 -1
- package/dist/types/clients/createWalletClient.d.ts +2 -2
- package/dist/types/clients/createWalletClient.d.ts.map +1 -1
- package/dist/types/clients/decorators/public.d.ts +5 -5
- package/dist/types/clients/decorators/public.d.ts.map +1 -1
- package/dist/types/clients/transports/createTransport.d.ts +5 -8
- package/dist/types/clients/transports/createTransport.d.ts.map +1 -1
- package/dist/types/clients/transports/custom.d.ts +2 -2
- package/dist/types/clients/transports/custom.d.ts.map +1 -1
- package/dist/types/clients/transports/http.d.ts +11 -0
- package/dist/types/clients/transports/http.d.ts.map +1 -1
- package/dist/types/clients/transports/webSocket.d.ts.map +1 -1
- package/dist/types/errors/abi.d.ts +6 -4
- package/dist/types/errors/abi.d.ts.map +1 -1
- package/dist/types/errors/request.d.ts +16 -8
- package/dist/types/errors/request.d.ts.map +1 -1
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/contract.d.ts +6 -3
- package/dist/types/types/contract.d.ts.map +1 -1
- package/dist/types/types/eip1193.d.ts +1037 -872
- package/dist/types/types/eip1193.d.ts.map +1 -1
- package/dist/types/types/filter.d.ts +12 -3
- package/dist/types/types/filter.d.ts.map +1 -1
- package/dist/types/types/log.d.ts +10 -7
- package/dist/types/types/log.d.ts.map +1 -1
- package/dist/types/types/utils.d.ts +11 -0
- package/dist/types/types/utils.d.ts.map +1 -1
- package/dist/types/utils/abi/decodeEventLog.d.ts.map +1 -1
- package/dist/types/utils/ens/encodeLabelhash.d.ts +3 -0
- package/dist/types/utils/ens/encodeLabelhash.d.ts.map +1 -0
- package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts +3 -0
- package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts.map +1 -0
- package/dist/types/utils/ens/labelhash.d.ts.map +1 -1
- package/dist/types/utils/ens/namehash.d.ts.map +1 -1
- package/dist/types/utils/ens/packetToBytes.d.ts.map +1 -1
- package/dist/types/utils/filters/createFilterRequestScope.d.ts +6 -2
- package/dist/types/utils/filters/createFilterRequestScope.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/rpc.d.ts +18 -10
- package/dist/types/utils/rpc.d.ts.map +1 -1
- package/package.json +2 -11
- package/src/actions/ens/getEnsAddress.ts +37 -22
- package/src/actions/public/call.ts +1 -1
- package/src/actions/public/createContractEventFilter.ts +21 -4
- package/src/actions/public/createEventFilter.ts +34 -13
- package/src/actions/public/estimateGas.ts +1 -1
- package/src/actions/public/getBlock.ts +2 -2
- package/src/actions/public/getBlockTransactionCount.ts +1 -1
- package/src/actions/public/getChainId.ts +3 -1
- package/src/actions/public/getFilterChanges.ts +27 -7
- package/src/actions/public/getFilterLogs.ts +29 -8
- package/src/actions/public/getGasPrice.ts +1 -1
- package/src/actions/public/getLogs.ts +34 -10
- package/src/actions/public/getTransactionCount.ts +1 -1
- package/src/clients/createClient.ts +13 -11
- package/src/clients/createPublicClient.ts +3 -4
- package/src/clients/createTestClient.ts +2 -3
- package/src/clients/createWalletClient.ts +2 -3
- package/src/clients/decorators/public.ts +33 -14
- package/src/clients/transports/createTransport.ts +5 -9
- package/src/clients/transports/custom.ts +1 -2
- package/src/clients/transports/fallback.ts +1 -1
- package/src/clients/transports/http.ts +44 -7
- package/src/clients/transports/webSocket.ts +23 -15
- package/src/errors/abi.ts +16 -4
- package/src/errors/request.ts +4 -4
- package/src/errors/version.ts +1 -1
- package/src/index.ts +10 -5
- package/src/types/contract.ts +17 -7
- package/src/types/eip1193.ts +1079 -872
- package/src/types/filter.ts +15 -3
- package/src/types/log.ts +18 -9
- package/src/types/utils.ts +15 -0
- package/src/utils/abi/decodeEventLog.ts +10 -2
- package/src/utils/ens/encodeLabelhash.ts +5 -0
- package/src/utils/ens/encodedLabelToLabelhash.ts +11 -0
- package/src/utils/ens/labelhash.ts +2 -1
- package/src/utils/ens/namehash.ts +6 -2
- package/src/utils/ens/packetToBytes.ts +12 -8
- package/src/utils/filters/createFilterRequestScope.ts +12 -4
- package/src/utils/formatters/log.ts +2 -2
- package/src/utils/index.ts +6 -0
- package/src/utils/rpc.ts +52 -52
- package/dist/cjs/adapters/ethers.js +0 -56
- package/dist/cjs/adapters/ethers.js.map +0 -1
- package/dist/cjs/ethers.js +0 -6
- package/dist/cjs/ethers.js.map +0 -1
- package/dist/esm/adapters/ethers.js +0 -52
- package/dist/esm/adapters/ethers.js.map +0 -1
- package/dist/esm/ethers.js +0 -2
- package/dist/esm/ethers.js.map +0 -1
- package/dist/types/adapters/ethers.d.ts +0 -27
- package/dist/types/adapters/ethers.d.ts.map +0 -1
- package/dist/types/ethers.d.ts +0 -2
- package/dist/types/ethers.d.ts.map +0 -1
- package/ethers/package.json +0 -5
- package/src/adapters/ethers.ts +0 -99
- package/src/ethers.ts +0 -1
package/src/types/filter.ts
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
import type { Abi } from 'abitype'
|
2
2
|
|
3
3
|
import type { MaybeExtractEventArgsFromAbi } from './contract.js'
|
4
|
-
import type {
|
4
|
+
import type { EIP1193RequestFn, PublicRpcSchema } from './eip1193.js'
|
5
5
|
import type { Hex } from './misc.js'
|
6
|
+
import type { Filter as Filter_ } from './utils.js'
|
6
7
|
|
7
8
|
export type FilterType = 'transaction' | 'block' | 'event'
|
8
9
|
|
10
|
+
type FilterRpcSchema = Filter_<
|
11
|
+
PublicRpcSchema,
|
12
|
+
{
|
13
|
+
Method: 'eth_getFilterLogs' | 'eth_getFilterChanges' | 'eth_uninstallFilter'
|
14
|
+
}
|
15
|
+
>
|
16
|
+
|
9
17
|
export type Filter<
|
10
18
|
TFilterType extends FilterType = 'event',
|
11
19
|
TAbi extends Abi | readonly unknown[] = Abi,
|
@@ -13,10 +21,10 @@ export type Filter<
|
|
13
21
|
TArgs extends
|
14
22
|
| MaybeExtractEventArgsFromAbi<TAbi, TEventName>
|
15
23
|
| undefined = MaybeExtractEventArgsFromAbi<TAbi, TEventName>,
|
24
|
+
TStrict extends boolean | undefined = undefined,
|
16
25
|
> = {
|
17
26
|
id: Hex
|
18
|
-
|
19
|
-
request: Requests['request']
|
27
|
+
request: EIP1193RequestFn<FilterRpcSchema>
|
20
28
|
type: TFilterType
|
21
29
|
} & (TFilterType extends 'event'
|
22
30
|
? TAbi extends Abi
|
@@ -25,21 +33,25 @@ export type Filter<
|
|
25
33
|
abi: TAbi
|
26
34
|
args?: never
|
27
35
|
eventName?: never
|
36
|
+
strict?: TStrict
|
28
37
|
}
|
29
38
|
: TArgs extends MaybeExtractEventArgsFromAbi<TAbi, TEventName>
|
30
39
|
? {
|
31
40
|
abi: TAbi
|
32
41
|
args: TArgs
|
33
42
|
eventName: TEventName
|
43
|
+
strict?: TStrict
|
34
44
|
}
|
35
45
|
: {
|
36
46
|
abi: TAbi
|
37
47
|
args?: never
|
38
48
|
eventName: TEventName
|
49
|
+
strict?: TStrict
|
39
50
|
}
|
40
51
|
: {
|
41
52
|
abi?: never
|
42
53
|
args?: never
|
43
54
|
eventName?: never
|
55
|
+
strict?: never
|
44
56
|
}
|
45
57
|
: {})
|
package/src/types/log.ts
CHANGED
@@ -11,6 +11,7 @@ import type {
|
|
11
11
|
GetEventArgs,
|
12
12
|
} from './contract.js'
|
13
13
|
import type { Hash, Hex } from './misc.js'
|
14
|
+
import type { MaybeUndefined } from './utils.js'
|
14
15
|
|
15
16
|
export type Log<
|
16
17
|
TQuantity = bigint,
|
@@ -20,6 +21,7 @@ export type Log<
|
|
20
21
|
TEventName extends string | undefined = TAbiEvent extends AbiEvent
|
21
22
|
? TAbiEvent['name']
|
22
23
|
: undefined,
|
24
|
+
TStrict extends boolean | undefined = undefined,
|
23
25
|
> = {
|
24
26
|
/** The address from which this log originated */
|
25
27
|
address: Address
|
@@ -37,7 +39,7 @@ export type Log<
|
|
37
39
|
transactionIndex: TIndex | null
|
38
40
|
/** `true` if this filter has been destroyed and is invalid */
|
39
41
|
removed: boolean
|
40
|
-
} & GetInferredLogValues<TAbiEvent, TAbi, TEventName>
|
42
|
+
} & GetInferredLogValues<TAbiEvent, TAbi, TEventName, TStrict>
|
41
43
|
|
42
44
|
type Topics<
|
43
45
|
THead extends AbiEvent['inputs'],
|
@@ -82,6 +84,7 @@ type GetInferredLogValues<
|
|
82
84
|
TEventName extends string | undefined = TAbiEvent extends AbiEvent
|
83
85
|
? TAbiEvent['name']
|
84
86
|
: undefined,
|
87
|
+
TStrict extends boolean | undefined = undefined,
|
85
88
|
_EventNames extends string = TAbi extends Abi
|
86
89
|
? Abi extends TAbi
|
87
90
|
? string
|
@@ -90,10 +93,13 @@ type GetInferredLogValues<
|
|
90
93
|
> = TAbi extends Abi
|
91
94
|
? TEventName extends string
|
92
95
|
? {
|
93
|
-
args:
|
94
|
-
|
95
|
-
|
96
|
-
|
96
|
+
args: MaybeUndefined<
|
97
|
+
GetEventArgs<
|
98
|
+
TAbi,
|
99
|
+
TEventName,
|
100
|
+
{ EnableUnion: false; IndexedOnly: false; Required: true }
|
101
|
+
>,
|
102
|
+
TStrict extends true ? false : true
|
97
103
|
>
|
98
104
|
/** The event name decoded from `topics`. */
|
99
105
|
eventName: TEventName
|
@@ -102,10 +108,13 @@ type GetInferredLogValues<
|
|
102
108
|
}
|
103
109
|
: {
|
104
110
|
[TName in _EventNames]: {
|
105
|
-
args:
|
106
|
-
|
107
|
-
|
108
|
-
|
111
|
+
args: MaybeUndefined<
|
112
|
+
GetEventArgs<
|
113
|
+
TAbi,
|
114
|
+
string,
|
115
|
+
{ EnableUnion: false; IndexedOnly: false; Required: true }
|
116
|
+
>,
|
117
|
+
TStrict extends true ? false : true
|
109
118
|
>
|
110
119
|
/** The event name decoded from `topics`. */
|
111
120
|
eventName: TName
|
package/src/types/utils.ts
CHANGED
@@ -106,6 +106,21 @@ export type MaybeRequired<T, TRequired extends boolean> = TRequired extends true
|
|
106
106
|
? Required<T>
|
107
107
|
: T
|
108
108
|
|
109
|
+
/**
|
110
|
+
* @description Makes the attribute on the type T allow undefined if TUndefinedish is true.
|
111
|
+
*
|
112
|
+
* @example
|
113
|
+
* MaybeUndefined<string, true>
|
114
|
+
* => string | undefined
|
115
|
+
*
|
116
|
+
* MaybeUndefined<string, false>
|
117
|
+
* => string
|
118
|
+
*/
|
119
|
+
export type MaybeUndefined<
|
120
|
+
T,
|
121
|
+
TUndefinedish extends boolean,
|
122
|
+
> = TUndefinedish extends true ? T | undefined : T
|
123
|
+
|
109
124
|
/**
|
110
125
|
* @description Merges the intersection properties of T and U.
|
111
126
|
*
|
@@ -82,7 +82,7 @@ export function decodeEventLog<
|
|
82
82
|
x.type === 'event' &&
|
83
83
|
signature === getEventSelector(formatAbiItem(x) as EventDefinition),
|
84
84
|
)
|
85
|
-
if (!(abiItem && 'name' in abiItem))
|
85
|
+
if (!(abiItem && 'name' in abiItem) || abiItem.type !== 'event')
|
86
86
|
throw new AbiEventSignatureNotFoundError(signature, {
|
87
87
|
docsPath,
|
88
88
|
})
|
@@ -109,7 +109,14 @@ export function decodeEventLog<
|
|
109
109
|
|
110
110
|
// Decode data (non-indexed args).
|
111
111
|
const nonIndexedInputs = inputs.filter((x) => !('indexed' in x && x.indexed))
|
112
|
-
if (
|
112
|
+
if (nonIndexedInputs.length > 0) {
|
113
|
+
if (!data || data === '0x')
|
114
|
+
throw new DecodeLogDataMismatch({
|
115
|
+
abiItem,
|
116
|
+
data: '0x',
|
117
|
+
params: nonIndexedInputs,
|
118
|
+
size: 0,
|
119
|
+
})
|
113
120
|
try {
|
114
121
|
const decodedData = decodeAbiParameters(nonIndexedInputs, data)
|
115
122
|
if (decodedData) {
|
@@ -123,6 +130,7 @@ export function decodeEventLog<
|
|
123
130
|
} catch (err) {
|
124
131
|
if (err instanceof AbiDecodingDataSizeTooSmallError)
|
125
132
|
throw new DecodeLogDataMismatch({
|
133
|
+
abiItem,
|
126
134
|
data: err.data,
|
127
135
|
params: err.params,
|
128
136
|
size: err.size,
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import type { Hex } from '../../index.js'
|
2
|
+
import { isHex } from '../index.js'
|
3
|
+
|
4
|
+
export function encodedLabelToLabelhash(label: string): Hex | null {
|
5
|
+
if (label.length !== 66) return null
|
6
|
+
if (label.indexOf('[') !== 0) return null
|
7
|
+
if (label.indexOf(']') !== 65) return null
|
8
|
+
const hash = `0x${label.slice(1, 65)}`
|
9
|
+
if (!isHex(hash)) return null
|
10
|
+
return hash
|
11
|
+
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { stringToBytes } from '../encoding/toBytes.js'
|
2
2
|
import { bytesToHex } from '../encoding/toHex.js'
|
3
3
|
import { keccak256 } from '../hash/keccak256.js'
|
4
|
+
import { encodedLabelToLabelhash } from './encodedLabelToLabelhash.js'
|
4
5
|
|
5
6
|
/**
|
6
7
|
* @description Hashes ENS label
|
@@ -14,5 +15,5 @@ import { keccak256 } from '../hash/keccak256.js'
|
|
14
15
|
export function labelhash(label: string) {
|
15
16
|
const result = new Uint8Array(32).fill(0)
|
16
17
|
if (!label) return bytesToHex(result)
|
17
|
-
return keccak256(stringToBytes(label))
|
18
|
+
return encodedLabelToLabelhash(label) || keccak256(stringToBytes(label))
|
18
19
|
}
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { concat } from '../data/concat.js'
|
2
|
-
import { stringToBytes } from '../encoding/toBytes.js'
|
2
|
+
import { stringToBytes, toBytes } from '../encoding/toBytes.js'
|
3
3
|
import { bytesToHex } from '../encoding/toHex.js'
|
4
4
|
import { keccak256 } from '../hash/keccak256.js'
|
5
|
+
import { encodedLabelToLabelhash } from './encodedLabelToLabelhash.js'
|
5
6
|
|
6
7
|
/**
|
7
8
|
* @description Hashes ENS name
|
@@ -21,7 +22,10 @@ export function namehash(name: string) {
|
|
21
22
|
const labels = name.split('.')
|
22
23
|
// Iterate in reverse order building up hash
|
23
24
|
for (let i = labels.length - 1; i >= 0; i -= 1) {
|
24
|
-
const
|
25
|
+
const hashFromEncodedLabel = encodedLabelToLabelhash(labels[i])
|
26
|
+
const hashed = hashFromEncodedLabel
|
27
|
+
? toBytes(hashFromEncodedLabel)
|
28
|
+
: keccak256(stringToBytes(labels[i]), 'bytes')
|
25
29
|
result = keccak256(concat([result, hashed]), 'bytes')
|
26
30
|
}
|
27
31
|
|
@@ -1,29 +1,33 @@
|
|
1
1
|
// Adapted from https://github.com/mafintosh/dns-packet
|
2
2
|
import type { ByteArray } from '../../types/misc.js'
|
3
3
|
import { stringToBytes } from '../encoding/toBytes.js'
|
4
|
+
import { encodeLabelhash } from './encodeLabelhash.js'
|
5
|
+
import { labelhash } from './labelhash.js'
|
4
6
|
|
5
7
|
/*
|
6
8
|
* @description Encodes a DNS packet into a ByteArray containing a UDP payload.
|
7
9
|
*/
|
8
10
|
export function packetToBytes(packet: string): ByteArray {
|
9
|
-
function length(value: string) {
|
10
|
-
if (value === '.' || value === '..') return 1
|
11
|
-
return stringToBytes(value.replace(/^\.|\.$/gm, '')).length + 2
|
12
|
-
}
|
13
|
-
|
14
|
-
const bytes = new Uint8Array(length(packet))
|
15
11
|
// strip leading and trailing `.`
|
16
12
|
const value = packet.replace(/^\.|\.$/gm, '')
|
17
|
-
if (
|
13
|
+
if (value.length === 0) return new Uint8Array(1)
|
14
|
+
|
15
|
+
const bytes = new Uint8Array(stringToBytes(value).byteLength + 2)
|
18
16
|
|
19
17
|
let offset = 0
|
20
18
|
const list = value.split('.')
|
21
19
|
for (let i = 0; i < list.length; i++) {
|
22
|
-
|
20
|
+
let encoded = stringToBytes(list[i])
|
21
|
+
// if the length is > 255, make the encoded label value a labelhash
|
22
|
+
// this is compatible with the universal resolver
|
23
|
+
if (encoded.byteLength > 255)
|
24
|
+
encoded = stringToBytes(encodeLabelhash(labelhash(list[i])))
|
23
25
|
bytes[offset] = encoded.length
|
24
26
|
bytes.set(encoded, offset + 1)
|
25
27
|
offset += encoded.length + 1
|
26
28
|
}
|
27
29
|
|
30
|
+
if (bytes.byteLength !== offset + 1) return bytes.slice(0, offset + 1)
|
31
|
+
|
28
32
|
return bytes
|
29
33
|
}
|
@@ -2,8 +2,9 @@ import type { PublicClient } from '../../clients/createPublicClient.js'
|
|
2
2
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
3
3
|
import type { OnResponseFn } from '../../clients/transports/fallback.js'
|
4
4
|
import type { Chain } from '../../types/chain.js'
|
5
|
-
import type {
|
5
|
+
import type { EIP1193RequestFn, PublicRpcSchema } from '../../types/eip1193.js'
|
6
6
|
import type { Hex } from '../../types/misc.js'
|
7
|
+
import type { Filter } from '../../types/utils.js'
|
7
8
|
|
8
9
|
type CreateFilterRequestScopeParameters = {
|
9
10
|
method:
|
@@ -11,8 +12,15 @@ type CreateFilterRequestScopeParameters = {
|
|
11
12
|
| 'eth_newPendingTransactionFilter'
|
12
13
|
| 'eth_newBlockFilter'
|
13
14
|
}
|
14
|
-
|
15
|
-
type
|
15
|
+
|
16
|
+
type FilterRpcSchema = Filter<
|
17
|
+
PublicRpcSchema,
|
18
|
+
{ Method: 'eth_getFilterLogs' | 'eth_getFilterChanges' }
|
19
|
+
>
|
20
|
+
|
21
|
+
type CreateFilterRequestScopeReturnType = (
|
22
|
+
id: Hex,
|
23
|
+
) => EIP1193RequestFn<FilterRpcSchema>
|
16
24
|
|
17
25
|
/**
|
18
26
|
* Scopes `request` to the filter ID. If the client is a fallback, it will
|
@@ -23,7 +31,7 @@ export function createFilterRequestScope<TChain extends Chain | undefined>(
|
|
23
31
|
client: PublicClient<Transport, TChain>,
|
24
32
|
{ method }: CreateFilterRequestScopeParameters,
|
25
33
|
): CreateFilterRequestScopeReturnType {
|
26
|
-
const requestMap: Record<Hex,
|
34
|
+
const requestMap: Record<Hex, EIP1193RequestFn> = {}
|
27
35
|
|
28
36
|
if (client.transport.type === 'fallback')
|
29
37
|
client.transport.onResponse?.(
|
@@ -9,10 +9,10 @@ export function formatLog(
|
|
9
9
|
...log,
|
10
10
|
blockHash: log.blockHash ? log.blockHash : null,
|
11
11
|
blockNumber: log.blockNumber ? BigInt(log.blockNumber) : null,
|
12
|
-
logIndex: log.logIndex ?
|
12
|
+
logIndex: log.logIndex ? Number(log.logIndex) : null,
|
13
13
|
transactionHash: log.transactionHash ? log.transactionHash : null,
|
14
14
|
transactionIndex: log.transactionIndex
|
15
|
-
?
|
15
|
+
? Number(log.transactionIndex)
|
16
16
|
: null,
|
17
17
|
...(eventName ? { args, eventName } : {}),
|
18
18
|
} as Log
|
package/src/utils/index.ts
CHANGED
@@ -17,8 +17,14 @@ export { arrayRegex, bytesRegex, integerRegex } from './regex.js'
|
|
17
17
|
|
18
18
|
export {
|
19
19
|
type HttpOptions,
|
20
|
+
type HttpReturnType,
|
21
|
+
type RpcRequest,
|
20
22
|
type RpcResponse,
|
21
23
|
type Socket,
|
24
|
+
type WebSocketAsyncOptions,
|
25
|
+
type WebSocketAsyncReturnType,
|
26
|
+
type WebSocketOptions,
|
27
|
+
type WebSocketReturnType,
|
22
28
|
getSocket,
|
23
29
|
rpc,
|
24
30
|
} from './rpc.js'
|
package/src/utils/rpc.ts
CHANGED
@@ -2,7 +2,6 @@ import type { MessageEvent, WebSocket } from 'isomorphic-ws'
|
|
2
2
|
|
3
3
|
import {
|
4
4
|
HttpRequestError,
|
5
|
-
RpcRequestError,
|
6
5
|
TimeoutError,
|
7
6
|
WebSocketRequestError,
|
8
7
|
} from '../errors/request.js'
|
@@ -41,7 +40,7 @@ type Subscription<TResult, TError> = {
|
|
41
40
|
)
|
42
41
|
}
|
43
42
|
|
44
|
-
type RpcRequest = { method: string; params?: any }
|
43
|
+
export type RpcRequest = { method: string; params?: any }
|
45
44
|
|
46
45
|
export type RpcResponse<TResult = any, TError = any> = {
|
47
46
|
jsonrpc: `${number}`
|
@@ -55,26 +54,39 @@ export type RpcResponse<TResult = any, TError = any> = {
|
|
55
54
|
///////////////////////////////////////////////////
|
56
55
|
// HTTP
|
57
56
|
|
58
|
-
export type HttpOptions =
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
57
|
+
export type HttpOptions<TBody extends RpcRequest | RpcRequest[] = RpcRequest,> =
|
58
|
+
{
|
59
|
+
// The RPC request body.
|
60
|
+
body: TBody
|
61
|
+
// Request configuration to pass to `fetch`.
|
62
|
+
fetchOptions?: Omit<RequestInit, 'body'>
|
63
|
+
// The timeout (in ms) for the request.
|
64
|
+
timeout?: number
|
65
|
+
}
|
66
|
+
|
67
|
+
export type HttpReturnType<
|
68
|
+
TBody extends RpcRequest | RpcRequest[] = RpcRequest,
|
69
|
+
> = TBody extends RpcRequest[] ? RpcResponse[] : RpcResponse
|
66
70
|
|
67
|
-
async function http(
|
71
|
+
async function http<TBody extends RpcRequest | RpcRequest[]>(
|
68
72
|
url: string,
|
69
|
-
{ body, fetchOptions = {}, timeout = 10_000 }: HttpOptions
|
70
|
-
) {
|
73
|
+
{ body, fetchOptions = {}, timeout = 10_000 }: HttpOptions<TBody>,
|
74
|
+
): Promise<HttpReturnType<TBody>> {
|
71
75
|
const { headers, method, signal: signal_ } = fetchOptions
|
72
76
|
try {
|
73
77
|
const response = await withTimeout(
|
74
78
|
async ({ signal }) => {
|
75
79
|
const response = await fetch(url, {
|
76
80
|
...fetchOptions,
|
77
|
-
body:
|
81
|
+
body: Array.isArray(body)
|
82
|
+
? stringify(
|
83
|
+
body.map((body) => ({
|
84
|
+
jsonrpc: '2.0',
|
85
|
+
id: id++,
|
86
|
+
...body,
|
87
|
+
})),
|
88
|
+
)
|
89
|
+
: stringify({ jsonrpc: '2.0', id: id++, ...body }),
|
78
90
|
headers: {
|
79
91
|
...headers,
|
80
92
|
'Content-Type': 'application/json',
|
@@ -108,13 +120,9 @@ async function http(
|
|
108
120
|
})
|
109
121
|
}
|
110
122
|
|
111
|
-
|
112
|
-
throw new RpcRequestError({ body, error: data.error, url })
|
113
|
-
}
|
114
|
-
return data as RpcResponse
|
123
|
+
return data
|
115
124
|
} catch (err) {
|
116
125
|
if (err instanceof HttpRequestError) throw err
|
117
|
-
if (err instanceof RpcRequestError) throw err
|
118
126
|
if (err instanceof TimeoutError) throw err
|
119
127
|
throw new HttpRequestError({
|
120
128
|
body,
|
@@ -213,21 +221,19 @@ export async function getSocket(url_: string) {
|
|
213
221
|
return socket_
|
214
222
|
}
|
215
223
|
|
224
|
+
export type WebSocketOptions = {
|
225
|
+
/** The RPC request body. */
|
226
|
+
body: RpcRequest
|
227
|
+
/** The callback to invoke on response. */
|
228
|
+
onResponse?: (message: RpcResponse) => void
|
229
|
+
}
|
230
|
+
|
231
|
+
export type WebSocketReturnType = Socket
|
232
|
+
|
216
233
|
function webSocket(
|
217
234
|
socket: Socket,
|
218
|
-
{
|
219
|
-
|
220
|
-
onData,
|
221
|
-
onError,
|
222
|
-
}: {
|
223
|
-
// The RPC request body.
|
224
|
-
body: RpcRequest
|
225
|
-
// The callback to invoke when the request is successful.
|
226
|
-
onData?: (message: RpcResponse) => void
|
227
|
-
// The callback to invoke if the request errors.
|
228
|
-
onError?: (message: RpcResponse['error']) => void
|
229
|
-
},
|
230
|
-
) {
|
235
|
+
{ body, onResponse }: WebSocketOptions,
|
236
|
+
): WebSocketReturnType {
|
231
237
|
if (
|
232
238
|
socket.readyState === socket.CLOSED ||
|
233
239
|
socket.readyState === socket.CLOSING
|
@@ -245,13 +251,7 @@ function webSocket(
|
|
245
251
|
|
246
252
|
if (typeof message.id === 'number' && id_ !== message.id) return
|
247
253
|
|
248
|
-
|
249
|
-
onError?.(
|
250
|
-
new RpcRequestError({ body, error: message.error, url: socket.url }),
|
251
|
-
)
|
252
|
-
} else {
|
253
|
-
onData?.(message)
|
254
|
-
}
|
254
|
+
onResponse?.(message)
|
255
255
|
|
256
256
|
// If we are subscribing to a topic, we want to set up a listener for incoming
|
257
257
|
// messages.
|
@@ -271,25 +271,25 @@ function webSocket(
|
|
271
271
|
return socket
|
272
272
|
}
|
273
273
|
|
274
|
+
export type WebSocketAsyncOptions = {
|
275
|
+
/** The RPC request body. */
|
276
|
+
body: RpcRequest
|
277
|
+
/** The timeout (in ms) for the request. */
|
278
|
+
timeout?: number
|
279
|
+
}
|
280
|
+
|
281
|
+
export type WebSocketAsyncReturnType = RpcResponse
|
282
|
+
|
274
283
|
async function webSocketAsync(
|
275
284
|
socket: Socket,
|
276
|
-
{
|
277
|
-
|
278
|
-
timeout = 10_000,
|
279
|
-
}: {
|
280
|
-
// The RPC request body.
|
281
|
-
body: RpcRequest
|
282
|
-
// The timeout (in ms) for the request.
|
283
|
-
timeout?: number
|
284
|
-
},
|
285
|
-
) {
|
285
|
+
{ body, timeout = 10_000 }: WebSocketAsyncOptions,
|
286
|
+
): Promise<WebSocketAsyncReturnType> {
|
286
287
|
return withTimeout(
|
287
288
|
() =>
|
288
|
-
new Promise<RpcResponse>((
|
289
|
+
new Promise<RpcResponse>((onResponse) =>
|
289
290
|
rpc.webSocket(socket, {
|
290
291
|
body,
|
291
|
-
|
292
|
-
onError,
|
292
|
+
onResponse,
|
293
293
|
}),
|
294
294
|
),
|
295
295
|
{
|
@@ -1,56 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ethersWalletToAccount = void 0;
|
4
|
-
const toAccount_js_1 = require("../accounts/toAccount.js");
|
5
|
-
const toBytes_js_1 = require("../utils/encoding/toBytes.js");
|
6
|
-
const ethersWalletToAccount = (wallet) => (0, toAccount_js_1.toAccount)({
|
7
|
-
address: wallet.address,
|
8
|
-
async signMessage({ message }) {
|
9
|
-
const messageBytes = (() => {
|
10
|
-
if (typeof message === 'string')
|
11
|
-
return (0, toBytes_js_1.stringToBytes)(message);
|
12
|
-
if (message.raw instanceof Uint8Array)
|
13
|
-
return message.raw;
|
14
|
-
return (0, toBytes_js_1.toBytes)(message.raw);
|
15
|
-
})();
|
16
|
-
return (await wallet.signMessage(messageBytes));
|
17
|
-
},
|
18
|
-
async signTransaction(txn) {
|
19
|
-
let type = null;
|
20
|
-
if (txn.type === 'legacy') {
|
21
|
-
type = 0;
|
22
|
-
}
|
23
|
-
else if (txn.type === 'eip1559') {
|
24
|
-
type = 2;
|
25
|
-
}
|
26
|
-
else if (txn.type === 'eip2930') {
|
27
|
-
type = 1;
|
28
|
-
}
|
29
|
-
return (await wallet.signTransaction({
|
30
|
-
chainId: txn.chainId,
|
31
|
-
data: txn.data,
|
32
|
-
gasLimit: txn.gas,
|
33
|
-
gasPrice: txn.gasPrice,
|
34
|
-
nonce: txn.nonce,
|
35
|
-
to: txn.to,
|
36
|
-
type,
|
37
|
-
value: txn.value,
|
38
|
-
...(txn.type && txn.accessList ? { accessList: txn.accessList } : {}),
|
39
|
-
...(txn.type === 'eip1559' && txn.maxPriorityFeePerGas
|
40
|
-
? { maxPriorityFeePerGas: txn.maxPriorityFeePerGas }
|
41
|
-
: {}),
|
42
|
-
...(txn.type === 'eip1559' && txn.maxFeePerGas
|
43
|
-
? { maxFeePerGas: txn.maxFeePerGas }
|
44
|
-
: {}),
|
45
|
-
}));
|
46
|
-
},
|
47
|
-
async signTypedData({ domain, types: types_, message }) {
|
48
|
-
const { EIP712Domain: _, ...types } = types_;
|
49
|
-
const signTypedData = wallet.signTypedData
|
50
|
-
? wallet.signTypedData.bind(wallet)
|
51
|
-
: wallet._signTypedData.bind(wallet);
|
52
|
-
return (await signTypedData(domain ?? {}, types, message));
|
53
|
-
},
|
54
|
-
});
|
55
|
-
exports.ethersWalletToAccount = ethersWalletToAccount;
|
56
|
-
//# sourceMappingURL=ethers.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ethers.js","sourceRoot":"","sources":["../../../src/adapters/ethers.ts"],"names":[],"mappings":";;;AAEA,2DAAoD;AAEpD,6DAAqE;AAwC9D,MAAM,qBAAqB,GAAG,CAAC,MAAoB,EAAE,EAAE,CAC5D,IAAA,wBAAS,EAAC;IACR,OAAO,EAAE,MAAM,CAAC,OAAkB;IAClC,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE;QAC3B,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE;YACzB,IAAI,OAAO,OAAO,KAAK,QAAQ;gBAAE,OAAO,IAAA,0BAAa,EAAC,OAAO,CAAC,CAAA;YAC9D,IAAI,OAAO,CAAC,GAAG,YAAY,UAAU;gBAAE,OAAO,OAAO,CAAC,GAAG,CAAA;YACzD,OAAO,IAAA,oBAAO,EAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAC7B,CAAC,CAAC,EAAE,CAAA;QACJ,OAAO,CAAC,MAAM,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,CAAS,CAAA;IACzD,CAAC;IACD,KAAK,CAAC,eAAe,CAAC,GAAG;QAGvB,IAAI,IAAI,GAAG,IAAI,CAAA;QACf,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE;YACzB,IAAI,GAAG,CAAC,CAAA;SACT;aAAM,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,EAAE;YACjC,IAAI,GAAG,CAAC,CAAA;SACT;aAAM,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,EAAE;YACjC,IAAI,GAAG,CAAC,CAAA;SACT;QACD,OAAO,CAAC,MAAM,MAAM,CAAC,eAAe,CAAC;YAEnC,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,QAAQ,EAAE,GAAG,CAAC,GAAG;YACjB,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,IAAI;YACJ,KAAK,EAAE,GAAG,CAAC,KAAK;YAEhB,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAErE,GAAG,CAAC,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,GAAG,CAAC,oBAAoB;gBACpD,CAAC,CAAC,EAAE,oBAAoB,EAAE,GAAG,CAAC,oBAAoB,EAAE;gBACpD,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,GAAG,CAAC,YAAY;gBAC5C,CAAC,CAAC,EAAE,YAAY,EAAE,GAAG,CAAC,YAAY,EAAE;gBACpC,CAAC,CAAC,EAAE,CAAC;SACR,CAAC,CAAS,CAAA;IACb,CAAC;IACD,KAAK,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE;QACpD,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,MAAa,CAAA;QACnD,MAAM,aAAa,GAAG,MAAM,CAAC,aAAa;YACxC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC;YACnC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACtC,OAAO,CAAC,MAAM,aAAa,CACzB,MAAM,IAAI,EAAE,EACZ,KAAyC,EACzC,OAAO,CACR,CAAS,CAAA;IACZ,CAAC;CACF,CAAC,CAAA;AAtDS,QAAA,qBAAqB,yBAsD9B"}
|
package/dist/cjs/ethers.js
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ethersWalletToAccount = void 0;
|
4
|
-
var ethers_js_1 = require("./adapters/ethers.js");
|
5
|
-
Object.defineProperty(exports, "ethersWalletToAccount", { enumerable: true, get: function () { return ethers_js_1.ethersWalletToAccount; } });
|
6
|
-
//# sourceMappingURL=ethers.js.map
|
package/dist/cjs/ethers.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ethers.js","sourceRoot":"","sources":["../../src/ethers.ts"],"names":[],"mappings":";;;AAAA,kDAA4D;AAAnD,kHAAA,qBAAqB,OAAA"}
|
@@ -1,52 +0,0 @@
|
|
1
|
-
import { toAccount } from '../accounts/toAccount.js';
|
2
|
-
import { stringToBytes, toBytes } from '../utils/encoding/toBytes.js';
|
3
|
-
export const ethersWalletToAccount = (wallet) => toAccount({
|
4
|
-
address: wallet.address,
|
5
|
-
async signMessage({ message }) {
|
6
|
-
const messageBytes = (() => {
|
7
|
-
if (typeof message === 'string')
|
8
|
-
return stringToBytes(message);
|
9
|
-
if (message.raw instanceof Uint8Array)
|
10
|
-
return message.raw;
|
11
|
-
return toBytes(message.raw);
|
12
|
-
})();
|
13
|
-
return (await wallet.signMessage(messageBytes));
|
14
|
-
},
|
15
|
-
async signTransaction(txn) {
|
16
|
-
let type = null;
|
17
|
-
if (txn.type === 'legacy') {
|
18
|
-
type = 0;
|
19
|
-
}
|
20
|
-
else if (txn.type === 'eip1559') {
|
21
|
-
type = 2;
|
22
|
-
}
|
23
|
-
else if (txn.type === 'eip2930') {
|
24
|
-
type = 1;
|
25
|
-
}
|
26
|
-
return (await wallet.signTransaction({
|
27
|
-
chainId: txn.chainId,
|
28
|
-
data: txn.data,
|
29
|
-
gasLimit: txn.gas,
|
30
|
-
gasPrice: txn.gasPrice,
|
31
|
-
nonce: txn.nonce,
|
32
|
-
to: txn.to,
|
33
|
-
type,
|
34
|
-
value: txn.value,
|
35
|
-
...(txn.type && txn.accessList ? { accessList: txn.accessList } : {}),
|
36
|
-
...(txn.type === 'eip1559' && txn.maxPriorityFeePerGas
|
37
|
-
? { maxPriorityFeePerGas: txn.maxPriorityFeePerGas }
|
38
|
-
: {}),
|
39
|
-
...(txn.type === 'eip1559' && txn.maxFeePerGas
|
40
|
-
? { maxFeePerGas: txn.maxFeePerGas }
|
41
|
-
: {}),
|
42
|
-
}));
|
43
|
-
},
|
44
|
-
async signTypedData({ domain, types: types_, message }) {
|
45
|
-
const { EIP712Domain: _, ...types } = types_;
|
46
|
-
const signTypedData = wallet.signTypedData
|
47
|
-
? wallet.signTypedData.bind(wallet)
|
48
|
-
: wallet._signTypedData.bind(wallet);
|
49
|
-
return (await signTypedData(domain ?? {}, types, message));
|
50
|
-
},
|
51
|
-
});
|
52
|
-
//# sourceMappingURL=ethers.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ethers.js","sourceRoot":"","sources":["../../../src/adapters/ethers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAEpD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAwCrE,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,MAAoB,EAAE,EAAE,CAC5D,SAAS,CAAC;IACR,OAAO,EAAE,MAAM,CAAC,OAAkB;IAClC,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE;QAC3B,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE;YACzB,IAAI,OAAO,OAAO,KAAK,QAAQ;gBAAE,OAAO,aAAa,CAAC,OAAO,CAAC,CAAA;YAC9D,IAAI,OAAO,CAAC,GAAG,YAAY,UAAU;gBAAE,OAAO,OAAO,CAAC,GAAG,CAAA;YACzD,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAC7B,CAAC,CAAC,EAAE,CAAA;QACJ,OAAO,CAAC,MAAM,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,CAAS,CAAA;IACzD,CAAC;IACD,KAAK,CAAC,eAAe,CAAC,GAAG;QAGvB,IAAI,IAAI,GAAG,IAAI,CAAA;QACf,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE;YACzB,IAAI,GAAG,CAAC,CAAA;SACT;aAAM,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,EAAE;YACjC,IAAI,GAAG,CAAC,CAAA;SACT;aAAM,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,EAAE;YACjC,IAAI,GAAG,CAAC,CAAA;SACT;QACD,OAAO,CAAC,MAAM,MAAM,CAAC,eAAe,CAAC;YAEnC,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,QAAQ,EAAE,GAAG,CAAC,GAAG;YACjB,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,IAAI;YACJ,KAAK,EAAE,GAAG,CAAC,KAAK;YAEhB,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAErE,GAAG,CAAC,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,GAAG,CAAC,oBAAoB;gBACpD,CAAC,CAAC,EAAE,oBAAoB,EAAE,GAAG,CAAC,oBAAoB,EAAE;gBACpD,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,GAAG,CAAC,YAAY;gBAC5C,CAAC,CAAC,EAAE,YAAY,EAAE,GAAG,CAAC,YAAY,EAAE;gBACpC,CAAC,CAAC,EAAE,CAAC;SACR,CAAC,CAAS,CAAA;IACb,CAAC;IACD,KAAK,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE;QACpD,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,MAAa,CAAA;QACnD,MAAM,aAAa,GAAG,MAAM,CAAC,aAAa;YACxC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC;YACnC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACtC,OAAO,CAAC,MAAM,aAAa,CACzB,MAAM,IAAI,EAAE,EACZ,KAAyC,EACzC,OAAO,CACR,CAAS,CAAA;IACZ,CAAC;CACF,CAAC,CAAA"}
|
package/dist/esm/ethers.js
DELETED
package/dist/esm/ethers.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ethers.js","sourceRoot":"","sources":["../../src/ethers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA"}
|