@lifi/sdk-provider-ethereum 4.0.12 → 4.0.14
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/CHANGELOG.md +16 -0
- package/dist/cjs/actions/checkPermitSupport.js +2 -1
- package/dist/cjs/actions/checkPermitSupport.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumNativePermitTask.js +2 -1
- package/dist/cjs/core/tasks/EthereumNativePermitTask.js.map +1 -1
- package/dist/cjs/permits/acceptsRawEcdsaSignature.d.ts +18 -0
- package/dist/cjs/permits/acceptsRawEcdsaSignature.js +58 -0
- package/dist/cjs/permits/acceptsRawEcdsaSignature.js.map +1 -0
- package/dist/cjs/permits/canAccountUseNativePermits.d.ts +28 -6
- package/dist/cjs/permits/canAccountUseNativePermits.js +30 -10
- package/dist/cjs/permits/canAccountUseNativePermits.js.map +1 -1
- package/dist/cjs/permits/canAccountUsePermit2.js +2 -57
- package/dist/cjs/permits/canAccountUsePermit2.js.map +1 -1
- package/dist/cjs/permits/getNativePermit.d.ts +7 -1
- package/dist/cjs/permits/getNativePermit.js +12 -9
- package/dist/cjs/permits/getNativePermit.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/actions/checkPermitSupport.js +2 -1
- package/dist/esm/actions/checkPermitSupport.js.map +1 -1
- package/dist/esm/core/tasks/EthereumNativePermitTask.js +2 -1
- package/dist/esm/core/tasks/EthereumNativePermitTask.js.map +1 -1
- package/dist/esm/permits/acceptsRawEcdsaSignature.d.ts +18 -0
- package/dist/esm/permits/acceptsRawEcdsaSignature.d.ts.map +1 -0
- package/dist/esm/permits/acceptsRawEcdsaSignature.js +57 -0
- package/dist/esm/permits/acceptsRawEcdsaSignature.js.map +1 -0
- package/dist/esm/permits/canAccountUseNativePermits.d.ts +28 -6
- package/dist/esm/permits/canAccountUseNativePermits.d.ts.map +1 -1
- package/dist/esm/permits/canAccountUseNativePermits.js +30 -10
- package/dist/esm/permits/canAccountUseNativePermits.js.map +1 -1
- package/dist/esm/permits/canAccountUsePermit2.d.ts.map +1 -1
- package/dist/esm/permits/canAccountUsePermit2.js +1 -56
- package/dist/esm/permits/canAccountUsePermit2.js.map +1 -1
- package/dist/esm/permits/getNativePermit.d.ts +7 -1
- package/dist/esm/permits/getNativePermit.d.ts.map +1 -1
- package/dist/esm/permits/getNativePermit.js +12 -9
- package/dist/esm/permits/getNativePermit.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +3 -3
- package/src/actions/checkPermitSupport.ts +8 -2
- package/src/core/tasks/EthereumNativePermitTask.ts +1 -0
- package/src/permits/acceptsRawEcdsaSignature.ts +73 -0
- package/src/permits/canAccountUseNativePermits.ts +38 -18
- package/src/permits/canAccountUsePermit2.ts +2 -76
- package/src/permits/getNativePermit.ts +23 -9
- package/src/version.ts +1 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { SDKClient } from '@lifi/sdk'
|
|
2
|
+
import { type Address, encodeFunctionData, type Hex } from 'viem'
|
|
3
|
+
import { call } from 'viem/actions'
|
|
4
|
+
import { getAction } from 'viem/utils'
|
|
5
|
+
import { getPublicClient } from '../client/publicClient.js'
|
|
6
|
+
|
|
7
|
+
const ERC1271_ABI = [
|
|
8
|
+
{
|
|
9
|
+
name: 'isValidSignature',
|
|
10
|
+
type: 'function',
|
|
11
|
+
stateMutability: 'view',
|
|
12
|
+
inputs: [{ type: 'bytes32' }, { type: 'bytes' }],
|
|
13
|
+
outputs: [{ type: 'bytes4' }],
|
|
14
|
+
},
|
|
15
|
+
] as const
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A real 65-byte signature over {@link PROBE_HASH} from the public key `0x01…01`,
|
|
19
|
+
* recovering to a third party — never the account under test. Throwaway probe
|
|
20
|
+
* value, not a credential.
|
|
21
|
+
*
|
|
22
|
+
* MUST stay recoverable. An unrecoverable signature makes implementations that
|
|
23
|
+
* revert (rather than return a failure value) look like they rejected the
|
|
24
|
+
* envelope, misclassifying accounts that would have accepted ours.
|
|
25
|
+
*/
|
|
26
|
+
const PROBE_HASH = `0x${'ab'.repeat(32)}` as Hex
|
|
27
|
+
const PROBE_SIGNATURE =
|
|
28
|
+
'0x997c61aa10e2330c076d6ba7abca1e71703a8f039291db103a62e085c9b2cf0d3f7e31ec9028229acc83093fbb722fa700fd6e4ea15d584df1bf384eb0051e0d1c' as Hex
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Asks an account with code whether it evaluates a plain 65-byte ECDSA
|
|
32
|
+
* signature: a return means it recovered a signer and merely found a mismatch,
|
|
33
|
+
* so the real root-key signature will verify, while a revert means it rejected
|
|
34
|
+
* the envelope and nothing we produce will. Keyed on revert-vs-return, never on
|
|
35
|
+
* the value — the probe signature recovers to a third party on purpose, so a
|
|
36
|
+
* correct implementation returns a *non*-magic value, and comparing against the
|
|
37
|
+
* magic value would reject every wallet this exists to accept. Only call it for
|
|
38
|
+
* accounts that have code; a code-less address returns empty data and would read
|
|
39
|
+
* as incapable.
|
|
40
|
+
*/
|
|
41
|
+
export const acceptsRawEcdsaSignature = async (
|
|
42
|
+
client: SDKClient,
|
|
43
|
+
chainId: number,
|
|
44
|
+
address: Address
|
|
45
|
+
): Promise<boolean> => {
|
|
46
|
+
try {
|
|
47
|
+
const publicClient = await getPublicClient(client, chainId)
|
|
48
|
+
const { data } = await getAction(
|
|
49
|
+
// CCIP-Read off, or an `OffchainLookup` revert comes back as a return and
|
|
50
|
+
// inverts the signal read below. viem gates it on the client, not the
|
|
51
|
+
// call, so clone rather than disable it on the shared ENS-using client.
|
|
52
|
+
// Relies on `getPublicClient` staying bare: add `publicActions` and
|
|
53
|
+
// `getAction` prefers a decorated `client.call`, re-enabling CCIP-Read.
|
|
54
|
+
{ ...publicClient, ccipRead: false },
|
|
55
|
+
call,
|
|
56
|
+
'call'
|
|
57
|
+
)({
|
|
58
|
+
to: address,
|
|
59
|
+
data: encodeFunctionData({
|
|
60
|
+
abi: ERC1271_ABI,
|
|
61
|
+
functionName: 'isValidSignature',
|
|
62
|
+
args: [PROBE_HASH, PROBE_SIGNATURE],
|
|
63
|
+
}),
|
|
64
|
+
})
|
|
65
|
+
// A full 32-byte word (`0x` + 64 chars) or nothing: verifiers compare against
|
|
66
|
+
// a magic value, so anything shorter can only be a false positive.
|
|
67
|
+
return !!data && data.length >= 66
|
|
68
|
+
} catch {
|
|
69
|
+
// Revert, or an RPC failure we can't tell apart from one. Either way we
|
|
70
|
+
// must not promise the signature will verify.
|
|
71
|
+
return false
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -1,31 +1,51 @@
|
|
|
1
1
|
import type { SDKClient } from '@lifi/sdk'
|
|
2
|
-
import type {
|
|
2
|
+
import type { Address } from 'viem'
|
|
3
3
|
import { getAccountCode } from '../actions/getAccountCode.js'
|
|
4
|
-
import {
|
|
4
|
+
import { acceptsRawEcdsaSignature } from './acceptsRawEcdsaSignature.js'
|
|
5
|
+
import { isDelegationDesignatorCode } from './isDelegationDesignatorCode.js'
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
* Whether the account can
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Whether the account can produce a signature an EIP-2612 `permit` will accept.
|
|
9
|
+
*
|
|
10
|
+
* Signing ECDSA is not the question — verification is. Tokens whose `permit`
|
|
11
|
+
* routes through a `SignatureChecker` branch on `owner.code.length` exactly as
|
|
12
|
+
* Permit2 does, so an owner with code takes the EIP-1271 path where strict
|
|
13
|
+
* delegates reject a bare signature (Circle's `FiatTokenV2_2`, i.e. USDC), hence
|
|
14
|
+
* the {@link acceptsRawEcdsaSignature} probe for EIP-7702 delegates.
|
|
15
|
+
*
|
|
16
|
+
* Other contract accounts stay blocked on shape alone and are never probed.
|
|
17
|
+
* `encodeNativePermitData` splits the signature with `parseSignature`, so this
|
|
18
|
+
* path needs 65 ECDSA bytes — which a 7702 delegate signing with its root key
|
|
19
|
+
* always produces, and a contract wallet generally does not. Probing them would
|
|
20
|
+
* admit any implementation that *returns* a failure value rather than reverting,
|
|
21
|
+
* skip the approval, then throw after the user had already signed.
|
|
22
|
+
*
|
|
23
|
+
* The probe describes the account while the verifier lives in the token, so a
|
|
24
|
+
* strict delegate spending a plain-`ecrecover` token is refused a permit it
|
|
25
|
+
* could have used — an approval rather than a revert, and the token's path is
|
|
26
|
+
* not reliably introspectable. `false` on RPC failure.
|
|
27
|
+
*
|
|
28
|
+
* Takes the chain and owner explicitly, mirroring {@link canAccountUsePermit2}:
|
|
29
|
+
* reading them off a wallet client silently reported "no native permit" for
|
|
30
|
+
* every caller that falls back to a public client.
|
|
11
31
|
*/
|
|
12
32
|
export const canAccountUseNativePermits = async (
|
|
13
33
|
client: SDKClient,
|
|
14
|
-
|
|
34
|
+
{ chainId, address }: { chainId: number; address: Address }
|
|
15
35
|
): Promise<boolean> => {
|
|
16
|
-
const
|
|
17
|
-
|
|
36
|
+
const code = await getAccountCode({ client, chainId, address })
|
|
37
|
+
// `undefined` means the lookup failed, not "no code" — `getAccountCode`
|
|
38
|
+
// normalizes an empty result to `'0x'` precisely so these stay distinct.
|
|
39
|
+
if (code === undefined) {
|
|
18
40
|
return false
|
|
19
41
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// would flip RPC failure from "no permits" to "use permits" (regression).
|
|
27
|
-
if (code === undefined) {
|
|
42
|
+
if (code === '0x') {
|
|
43
|
+
return true
|
|
44
|
+
}
|
|
45
|
+
// Shape first: only 7702 delegates reach the probe. See the note above on
|
|
46
|
+
// `parseSignature` — deliberately narrower than the Permit2 gate.
|
|
47
|
+
if (!isDelegationDesignatorCode(code)) {
|
|
28
48
|
return false
|
|
29
49
|
}
|
|
30
|
-
return
|
|
50
|
+
return acceptsRawEcdsaSignature(client, chainId, address)
|
|
31
51
|
}
|
|
@@ -1,81 +1,7 @@
|
|
|
1
1
|
import type { SDKClient } from '@lifi/sdk'
|
|
2
|
-
import {
|
|
3
|
-
import { call } from 'viem/actions'
|
|
4
|
-
import { getAction } from 'viem/utils'
|
|
2
|
+
import type { Address } from 'viem'
|
|
5
3
|
import { getAccountCode } from '../actions/getAccountCode.js'
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
const ERC1271_ABI = [
|
|
9
|
-
{
|
|
10
|
-
name: 'isValidSignature',
|
|
11
|
-
type: 'function',
|
|
12
|
-
stateMutability: 'view',
|
|
13
|
-
inputs: [{ type: 'bytes32' }, { type: 'bytes' }],
|
|
14
|
-
outputs: [{ type: 'bytes4' }],
|
|
15
|
-
},
|
|
16
|
-
] as const
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* A real 65-byte signature over {@link PROBE_HASH} from the public key `0x01…01`,
|
|
20
|
-
* recovering to a third party — never the account under test. Throwaway probe
|
|
21
|
-
* value, not a credential.
|
|
22
|
-
*
|
|
23
|
-
* MUST stay recoverable. An unrecoverable signature makes implementations that
|
|
24
|
-
* revert (rather than return a failure value) look like they rejected the
|
|
25
|
-
* envelope, misclassifying accounts that would have accepted ours.
|
|
26
|
-
*/
|
|
27
|
-
const PROBE_HASH = `0x${'ab'.repeat(32)}` as Hex
|
|
28
|
-
const PROBE_SIGNATURE =
|
|
29
|
-
'0x997c61aa10e2330c076d6ba7abca1e71703a8f039291db103a62e085c9b2cf0d3f7e31ec9028229acc83093fbb722fa700fd6e4ea15d584df1bf384eb0051e0d1c' as Hex
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Asks a code-bearing account the same question Permit2 will: does it evaluate a
|
|
33
|
-
* plain 65-byte ECDSA signature, or reject it outright?
|
|
34
|
-
*
|
|
35
|
-
* - **Returns** → it recovered a signer and found a mismatch, so it will accept
|
|
36
|
-
* the real root-key signature (MetaMask's `EIP7702StatelessDeleGator`).
|
|
37
|
-
* - **Reverts** → it rejected the envelope before recovery and can't validate
|
|
38
|
-
* anything we produce (Alchemy's ERC-6900 `SemiModularAccount7702`).
|
|
39
|
-
*
|
|
40
|
-
* Keyed on revert-vs-return, never on the value returned: the probe signature
|
|
41
|
-
* recovers to a third party on purpose, so a correct implementation must return
|
|
42
|
-
* a *non*-magic value, and comparing against the magic value would reject every
|
|
43
|
-
* wallet this exists to accept. Accepted cost: an implementation that returns
|
|
44
|
-
* failure for *everything* is classified capable and still fails on-chain.
|
|
45
|
-
*/
|
|
46
|
-
const acceptsRawEcdsaSignature = async (
|
|
47
|
-
client: SDKClient,
|
|
48
|
-
chainId: number,
|
|
49
|
-
address: Address
|
|
50
|
-
): Promise<boolean> => {
|
|
51
|
-
try {
|
|
52
|
-
const publicClient = await getPublicClient(client, chainId)
|
|
53
|
-
const { data } = await getAction(
|
|
54
|
-
// CCIP-Read off, or an `OffchainLookup` revert comes back as a return and
|
|
55
|
-
// inverts the signal read below. viem gates it on the client, not the
|
|
56
|
-
// call, so clone rather than disable it on the shared ENS-using client.
|
|
57
|
-
// Relies on `getPublicClient` staying bare: add `publicActions` and
|
|
58
|
-
// `getAction` prefers a decorated `client.call`, re-enabling CCIP-Read.
|
|
59
|
-
{ ...publicClient, ccipRead: false },
|
|
60
|
-
call,
|
|
61
|
-
'call'
|
|
62
|
-
)({
|
|
63
|
-
to: address,
|
|
64
|
-
data: encodeFunctionData({
|
|
65
|
-
abi: ERC1271_ABI,
|
|
66
|
-
functionName: 'isValidSignature',
|
|
67
|
-
args: [PROBE_HASH, PROBE_SIGNATURE],
|
|
68
|
-
}),
|
|
69
|
-
})
|
|
70
|
-
// A full 32-byte word (`0x` + 64 chars) or nothing: Permit2 compares against
|
|
71
|
-
// a magic value, so anything shorter can only be a false positive.
|
|
72
|
-
return !!data && data.length >= 66
|
|
73
|
-
} catch {
|
|
74
|
-
// Revert, or an RPC failure we can't tell apart from one. Either way we
|
|
75
|
-
// must not promise Permit2 will work.
|
|
76
|
-
return false
|
|
77
|
-
}
|
|
78
|
-
}
|
|
4
|
+
import { acceptsRawEcdsaSignature } from './acceptsRawEcdsaSignature.js'
|
|
79
5
|
|
|
80
6
|
/**
|
|
81
7
|
* Whether the account can produce a signature Uniswap Permit2 will accept.
|
|
@@ -29,6 +29,12 @@ type GetNativePermitParams = {
|
|
|
29
29
|
tokenAddress: Address
|
|
30
30
|
spenderAddress: Address
|
|
31
31
|
amount: bigint
|
|
32
|
+
/**
|
|
33
|
+
* The address that will sign the permit. Passed explicitly rather than read
|
|
34
|
+
* off `viemClient.account`, which is absent whenever a caller falls back to a
|
|
35
|
+
* public client (`checkPermitSupport` does) — that used to throw here.
|
|
36
|
+
*/
|
|
37
|
+
ownerAddress: Address
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
function makeDomainSeparator({
|
|
@@ -139,7 +145,8 @@ const getEIP712DomainData = async (
|
|
|
139
145
|
client: SDKClient,
|
|
140
146
|
viemClient: Client,
|
|
141
147
|
chainId: number,
|
|
142
|
-
tokenAddress: Address
|
|
148
|
+
tokenAddress: Address,
|
|
149
|
+
ownerAddress: Address
|
|
143
150
|
) => {
|
|
144
151
|
try {
|
|
145
152
|
const multicallAddress = await getMulticallAddress(client, chainId)
|
|
@@ -154,7 +161,7 @@ const getEIP712DomainData = async (
|
|
|
154
161
|
address: tokenAddress,
|
|
155
162
|
abi: eip2612Abi,
|
|
156
163
|
functionName: 'nonces',
|
|
157
|
-
args: [
|
|
164
|
+
args: [ownerAddress],
|
|
158
165
|
},
|
|
159
166
|
] as const
|
|
160
167
|
|
|
@@ -296,7 +303,8 @@ const getContractData = async (
|
|
|
296
303
|
client: SDKClient,
|
|
297
304
|
viemClient: Client,
|
|
298
305
|
chainId: number,
|
|
299
|
-
tokenAddress: Address
|
|
306
|
+
tokenAddress: Address,
|
|
307
|
+
ownerAddress: Address
|
|
300
308
|
) => {
|
|
301
309
|
try {
|
|
302
310
|
// First try EIP-5267 approach - returns domain object directly
|
|
@@ -304,7 +312,8 @@ const getContractData = async (
|
|
|
304
312
|
client,
|
|
305
313
|
viemClient,
|
|
306
314
|
chainId,
|
|
307
|
-
tokenAddress
|
|
315
|
+
tokenAddress,
|
|
316
|
+
ownerAddress
|
|
308
317
|
)
|
|
309
318
|
if (eip5267Data) {
|
|
310
319
|
return eip5267Data
|
|
@@ -333,7 +342,7 @@ const getContractData = async (
|
|
|
333
342
|
address: tokenAddress,
|
|
334
343
|
abi: eip2612Abi,
|
|
335
344
|
functionName: 'nonces',
|
|
336
|
-
args: [
|
|
345
|
+
args: [ownerAddress],
|
|
337
346
|
},
|
|
338
347
|
{
|
|
339
348
|
address: tokenAddress,
|
|
@@ -479,10 +488,14 @@ export const getNativePermit = async (
|
|
|
479
488
|
tokenAddress,
|
|
480
489
|
spenderAddress,
|
|
481
490
|
amount,
|
|
491
|
+
ownerAddress,
|
|
482
492
|
}: GetNativePermitParams
|
|
483
493
|
): Promise<NativePermitData | undefined> => {
|
|
484
|
-
// Check
|
|
485
|
-
const canUsePermits = await canAccountUseNativePermits(client,
|
|
494
|
+
// Check that the account can produce a signature the token will accept
|
|
495
|
+
const canUsePermits = await canAccountUseNativePermits(client, {
|
|
496
|
+
chainId,
|
|
497
|
+
address: ownerAddress,
|
|
498
|
+
})
|
|
486
499
|
if (!canUsePermits) {
|
|
487
500
|
return undefined
|
|
488
501
|
}
|
|
@@ -491,7 +504,8 @@ export const getNativePermit = async (
|
|
|
491
504
|
client,
|
|
492
505
|
viemClient,
|
|
493
506
|
chainId,
|
|
494
|
-
tokenAddress
|
|
507
|
+
tokenAddress,
|
|
508
|
+
ownerAddress
|
|
495
509
|
)
|
|
496
510
|
if (!contractData) {
|
|
497
511
|
return undefined
|
|
@@ -506,7 +520,7 @@ export const getNativePermit = async (
|
|
|
506
520
|
const deadline = BigInt(Math.floor(Date.now() / 1000) + 30 * 60).toString() // 30 minutes
|
|
507
521
|
|
|
508
522
|
const message = {
|
|
509
|
-
owner:
|
|
523
|
+
owner: ownerAddress,
|
|
510
524
|
spender: spenderAddress,
|
|
511
525
|
value: amount.toString(),
|
|
512
526
|
nonce: contractData.nonce!.toString(),
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk-provider-ethereum'
|
|
2
|
-
export const version = '4.0.
|
|
2
|
+
export const version = '4.0.14'
|