@anywalletkit/extension-kit 0.5.1 → 0.6.0
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/index.cjs +42 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -2
- package/dist/index.d.ts +32 -2
- package/dist/index.js +43 -4
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -1323,6 +1323,18 @@ declare function evmCallMatcher(expected: {
|
|
|
1323
1323
|
data?: string | undefined;
|
|
1324
1324
|
value: bigint;
|
|
1325
1325
|
}): GateMatcher;
|
|
1326
|
+
/**
|
|
1327
|
+
* Matcher for a Permit2 signature-transfer swap call (`Swap2ExecutionPlan.source.permit2Transfer`): the engine sends
|
|
1328
|
+
* the reviewed calldata followed by `uint256(n)` and exactly `n` signature bytes (64 to 2048: an EOA's 64/65, a
|
|
1329
|
+
* contract account's longer one). Same chain, `to` and value; the calldata must be exactly that structure — never a
|
|
1330
|
+
* bare prefix, and the unsigned calldata alone does not pass.
|
|
1331
|
+
*/
|
|
1332
|
+
declare function evmSignedCallMatcher(expected: {
|
|
1333
|
+
caip2: string;
|
|
1334
|
+
to: string;
|
|
1335
|
+
data: string;
|
|
1336
|
+
value: bigint;
|
|
1337
|
+
}): GateMatcher;
|
|
1326
1338
|
/** Matcher for one EIP-712 payload on one chain, by the digest the account signs (`typedDataHash` from `@anywalletkit/wallet-evm`). */
|
|
1327
1339
|
declare function typedDataMatcher(expected: {
|
|
1328
1340
|
caip2: string;
|
|
@@ -1494,6 +1506,20 @@ interface SwapApproval {
|
|
|
1494
1506
|
data?: string;
|
|
1495
1507
|
value: string;
|
|
1496
1508
|
deposit?: string;
|
|
1509
|
+
/**
|
|
1510
|
+
* Permit2 signature-transfer swaps (0x): the EIP-712 `PermitTransferFrom` the account signs for this swap,
|
|
1511
|
+
* rebuilt by the engine from checked values — `typedData` to render, `text` pretty JSON, and its fields read
|
|
1512
|
+
* out (token, exact amount, the one contract that may use it, deadline in unix seconds). The call then goes
|
|
1513
|
+
* out as `data` followed by the signature.
|
|
1514
|
+
*/
|
|
1515
|
+
permit2Transfer?: {
|
|
1516
|
+
typedData: TypedData;
|
|
1517
|
+
text: string;
|
|
1518
|
+
token: string;
|
|
1519
|
+
amount: string;
|
|
1520
|
+
spender: string;
|
|
1521
|
+
deadline: number;
|
|
1522
|
+
};
|
|
1497
1523
|
} | {
|
|
1498
1524
|
kind: 'token-transfer';
|
|
1499
1525
|
token: string;
|
|
@@ -1524,7 +1550,11 @@ interface SwapApproval {
|
|
|
1524
1550
|
}
|
|
1525
1551
|
declare const encodeApproveCalldata: (spender: string, amount: bigint) => string;
|
|
1526
1552
|
declare function swapApprovalPayload(plan: Swap2ExecutionPlan, meta: SwapReviewMeta): SwapApproval;
|
|
1527
|
-
/**
|
|
1553
|
+
/**
|
|
1554
|
+
* Matchers for exactly the operations the plan will perform, in the engine's order. A Permit2 signature-transfer swap
|
|
1555
|
+
* is three operations: the permit (signed first, matched by its EIP-712 digest), the approvals, then the call carrying
|
|
1556
|
+
* the signature (matched by its exact structure, see {@link evmSignedCallMatcher}).
|
|
1557
|
+
*/
|
|
1528
1558
|
declare function planMatchers(plan: Swap2ExecutionPlan): GateMatcher[];
|
|
1529
1559
|
/** The engine's `reviewExecution`: one sheet for the plan; approve → pre-approve exactly its operations; decline → nothing sent. */
|
|
1530
1560
|
declare function reviewSwapPlan(approvals: ApprovalQueue, gate: ReviewGate, meta: SwapReviewMeta): (plan: Swap2ExecutionPlan) => Promise<void>;
|
|
@@ -2077,4 +2107,4 @@ declare class TokenBucket {
|
|
|
2077
2107
|
private prune;
|
|
2078
2108
|
}
|
|
2079
2109
|
|
|
2080
|
-
export { ACTIVE_STATUSES, APPROVALS_MAX_PENDING_PER_ORIGIN, APPROVALS_MAX_PENDING_PER_SITE, APPROVALS_MAX_PENDING_TOTAL, type AddChainApproval, type AlarmsLike, type ApprovalKind, ApprovalQueue, type ApprovalQueueOptions, type ApprovalRateOptions, type ApprovalRequest, type ApprovalRequestOptions, type ApprovalWindow, type AssertionExpectations, type AssertionInput, type AssertionVerdict, BTC_CHAIN, BTC_ESPLORA, CHAIN_ACCOUNT_KEYS, type ChainAccountsKey, type ChainDescriptor, type ConnectApproval, DEFAULT_CHAIN, DEFAULT_NETWORKS, type EarnApproval, type EarnPlan, type EarnReviewMeta, type EarnTx, type EvmNetwork, type EvmSigner, FLOOR_TOLERANCE_BPS, GETLOGS_MAX_SPAN_UNCONNECTED, type GateMatcher, type GatedOp, type HostCheck, type JsonStorage, KEYRING_STORAGE_KEY, LOOKALIKE_PREFIX, LOOKALIKE_SUFFIX, MAX_FEE_REASKS, MULTI_LABEL_SUFFIXES, type MacJsonStorage, type MacJsonStorageOptions, type MacRead, type MacState, NEAR_CHAIN, NEAR_PROVIDERS, NON_EVM_CHAINS, NetworksTable, type OriginPermission, OriginRefused, type OriginVia, PAGE_TARGET, PORT_NAME, type PageEvent, type PageMessageEvent, type PageRequest, type PageResponse, type PageWindow, PermissionStore, type PermissionsState, type PersonalSignBlindHashForm, PhishingDetector, type PhishingList, type PortSender, type PreparedTx, QueueLimitError, type QuoteRoutesOptions, READ_METHODS, RELAY_ERRORS, RELAY_METHOD_MAX, type RankOptions, RecipientBook, type RecipientsState, type RelayChain, type RelayError, type RelayErrorOptions, type RelayEvent, type RelayRequest, type RelayResponse, type RelayToContent, type RelayToWorker, RequestRouter, ReviewDeclined, ReviewGate, type RouteListView, type RouteView, type RouteWarning, type RouterDeps, RouterError, SESSION_DEFAULT_AUTOLOCK_MS, SIGNING_METHODS, SIWE_FORBIDDEN_CHARS, SOLANA_CHAIN, SOLANA_RPCS, STORAGE_MAC_FIELD, STORAGE_VERSION_FIELD, type SealedBox, Session, type SessionAlarms, type SessionOptions, type SessionStorage, type SignApproval, type SignDeps, type SignRequestInfo, type SiweContext, type SiweInfo, type SiweMessage, type StorageAreaLike, type StorageVersionLedger, type StorageVersionLedgerOptions, type StorageVersionOps, type StorageVersions, type SwapApproval, type SwapRecord, type SwapRecordStatus, type SwapReviewMeta, SwapTracker, type SwapTrackerDeps, SwapsStore, type SwitchChainApproval, TON_CHAIN, TON_ENDPOINTS, TRON_CHAIN, TRON_PROVIDERS, TokenBucket, type TokenBucketOptions, type TonAddressParts, type TypedData, VAULT_DEFAULT_ITERATIONS, VAULT_LIMITS, VAULT_MIN_ITERATIONS, VAULT_MIN_PASSWORD_LENGTH, VAULT_MIN_SCRYPT, VAULT_SCRYPT, VAULT_STORAGE_KEY, Vault, type VaultEnvelope, type VaultEnvelopeV1, type VaultEnvelopeV2, VaultError, type VaultErrorCode, type VaultKdfInfo, type VaultOptions, type VaultPasskey, type VaultStorage, ZCASH_BLOCKCHAIR, ZCASH_CHAIN, approvalChallenge, caip2FromChainId, canonicalJson, chainHex, chainTxMatcher, checkSenderOrigin, chromeAlarms, chromeJsonStorage, chromeKeyringStorage, chromeLocalVaultStorage, chromeSessionStorage, classifySignRequest, createSignHandler, decodedMessage, derToRaw, deriveStorageMacKey, describeSiwe, earnApprovalPayload, earnPlanMatchers, encodeApproveCalldata, evmCallMatcher, executionFloor, fromBase64Url, gasLimitExcessive, hostOf, isCatalogChain, isEnvelopeV1, isEnvelopeV2, isLocalHost, isPageEvent, isPageRequest, isPageResponse, isRelayMethod, isRelayRequest, isRelayToContent, levenshtein, lookalikeOf, macJsonStorage, memoryAlarms, memoryApprovalWindow, memoryJsonStorage, memorySessionStorage, memoryVaultStorage, messageText, newRequestId, nonEvmChain, normalizeHost, pageRequestFrom, parseAddChainParams, parseRawAddress, parseSiwe, parseSwapId, planMatchers, prepareTransaction, proofDomain, quoteRoutes, rank, rawToDer, relayError, revealHidden, reviewEarnPlan, reviewSwapPlan, siteOf, siweCrossSite, siweProblems, stampOrigin, storageVersionLedger, swapApprovalPayload, toBase64Url, toRelayError, tonConnectErrorCode, tonProofMessage, tonSignDataMessage, typedDataMatcher, vaultSecretStorage, verifyAssertion };
|
|
2110
|
+
export { ACTIVE_STATUSES, APPROVALS_MAX_PENDING_PER_ORIGIN, APPROVALS_MAX_PENDING_PER_SITE, APPROVALS_MAX_PENDING_TOTAL, type AddChainApproval, type AlarmsLike, type ApprovalKind, ApprovalQueue, type ApprovalQueueOptions, type ApprovalRateOptions, type ApprovalRequest, type ApprovalRequestOptions, type ApprovalWindow, type AssertionExpectations, type AssertionInput, type AssertionVerdict, BTC_CHAIN, BTC_ESPLORA, CHAIN_ACCOUNT_KEYS, type ChainAccountsKey, type ChainDescriptor, type ConnectApproval, DEFAULT_CHAIN, DEFAULT_NETWORKS, type EarnApproval, type EarnPlan, type EarnReviewMeta, type EarnTx, type EvmNetwork, type EvmSigner, FLOOR_TOLERANCE_BPS, GETLOGS_MAX_SPAN_UNCONNECTED, type GateMatcher, type GatedOp, type HostCheck, type JsonStorage, KEYRING_STORAGE_KEY, LOOKALIKE_PREFIX, LOOKALIKE_SUFFIX, MAX_FEE_REASKS, MULTI_LABEL_SUFFIXES, type MacJsonStorage, type MacJsonStorageOptions, type MacRead, type MacState, NEAR_CHAIN, NEAR_PROVIDERS, NON_EVM_CHAINS, NetworksTable, type OriginPermission, OriginRefused, type OriginVia, PAGE_TARGET, PORT_NAME, type PageEvent, type PageMessageEvent, type PageRequest, type PageResponse, type PageWindow, PermissionStore, type PermissionsState, type PersonalSignBlindHashForm, PhishingDetector, type PhishingList, type PortSender, type PreparedTx, QueueLimitError, type QuoteRoutesOptions, READ_METHODS, RELAY_ERRORS, RELAY_METHOD_MAX, type RankOptions, RecipientBook, type RecipientsState, type RelayChain, type RelayError, type RelayErrorOptions, type RelayEvent, type RelayRequest, type RelayResponse, type RelayToContent, type RelayToWorker, RequestRouter, ReviewDeclined, ReviewGate, type RouteListView, type RouteView, type RouteWarning, type RouterDeps, RouterError, SESSION_DEFAULT_AUTOLOCK_MS, SIGNING_METHODS, SIWE_FORBIDDEN_CHARS, SOLANA_CHAIN, SOLANA_RPCS, STORAGE_MAC_FIELD, STORAGE_VERSION_FIELD, type SealedBox, Session, type SessionAlarms, type SessionOptions, type SessionStorage, type SignApproval, type SignDeps, type SignRequestInfo, type SiweContext, type SiweInfo, type SiweMessage, type StorageAreaLike, type StorageVersionLedger, type StorageVersionLedgerOptions, type StorageVersionOps, type StorageVersions, type SwapApproval, type SwapRecord, type SwapRecordStatus, type SwapReviewMeta, SwapTracker, type SwapTrackerDeps, SwapsStore, type SwitchChainApproval, TON_CHAIN, TON_ENDPOINTS, TRON_CHAIN, TRON_PROVIDERS, TokenBucket, type TokenBucketOptions, type TonAddressParts, type TypedData, VAULT_DEFAULT_ITERATIONS, VAULT_LIMITS, VAULT_MIN_ITERATIONS, VAULT_MIN_PASSWORD_LENGTH, VAULT_MIN_SCRYPT, VAULT_SCRYPT, VAULT_STORAGE_KEY, Vault, type VaultEnvelope, type VaultEnvelopeV1, type VaultEnvelopeV2, VaultError, type VaultErrorCode, type VaultKdfInfo, type VaultOptions, type VaultPasskey, type VaultStorage, ZCASH_BLOCKCHAIR, ZCASH_CHAIN, approvalChallenge, caip2FromChainId, canonicalJson, chainHex, chainTxMatcher, checkSenderOrigin, chromeAlarms, chromeJsonStorage, chromeKeyringStorage, chromeLocalVaultStorage, chromeSessionStorage, classifySignRequest, createSignHandler, decodedMessage, derToRaw, deriveStorageMacKey, describeSiwe, earnApprovalPayload, earnPlanMatchers, encodeApproveCalldata, evmCallMatcher, evmSignedCallMatcher, executionFloor, fromBase64Url, gasLimitExcessive, hostOf, isCatalogChain, isEnvelopeV1, isEnvelopeV2, isLocalHost, isPageEvent, isPageRequest, isPageResponse, isRelayMethod, isRelayRequest, isRelayToContent, levenshtein, lookalikeOf, macJsonStorage, memoryAlarms, memoryApprovalWindow, memoryJsonStorage, memorySessionStorage, memoryVaultStorage, messageText, newRequestId, nonEvmChain, normalizeHost, pageRequestFrom, parseAddChainParams, parseRawAddress, parseSiwe, parseSwapId, planMatchers, prepareTransaction, proofDomain, quoteRoutes, rank, rawToDer, relayError, revealHidden, reviewEarnPlan, reviewSwapPlan, siteOf, siweCrossSite, siweProblems, stampOrigin, storageVersionLedger, swapApprovalPayload, toBase64Url, toRelayError, tonConnectErrorCode, tonProofMessage, tonSignDataMessage, typedDataMatcher, vaultSecretStorage, verifyAssertion };
|
package/dist/index.d.ts
CHANGED
|
@@ -1323,6 +1323,18 @@ declare function evmCallMatcher(expected: {
|
|
|
1323
1323
|
data?: string | undefined;
|
|
1324
1324
|
value: bigint;
|
|
1325
1325
|
}): GateMatcher;
|
|
1326
|
+
/**
|
|
1327
|
+
* Matcher for a Permit2 signature-transfer swap call (`Swap2ExecutionPlan.source.permit2Transfer`): the engine sends
|
|
1328
|
+
* the reviewed calldata followed by `uint256(n)` and exactly `n` signature bytes (64 to 2048: an EOA's 64/65, a
|
|
1329
|
+
* contract account's longer one). Same chain, `to` and value; the calldata must be exactly that structure — never a
|
|
1330
|
+
* bare prefix, and the unsigned calldata alone does not pass.
|
|
1331
|
+
*/
|
|
1332
|
+
declare function evmSignedCallMatcher(expected: {
|
|
1333
|
+
caip2: string;
|
|
1334
|
+
to: string;
|
|
1335
|
+
data: string;
|
|
1336
|
+
value: bigint;
|
|
1337
|
+
}): GateMatcher;
|
|
1326
1338
|
/** Matcher for one EIP-712 payload on one chain, by the digest the account signs (`typedDataHash` from `@anywalletkit/wallet-evm`). */
|
|
1327
1339
|
declare function typedDataMatcher(expected: {
|
|
1328
1340
|
caip2: string;
|
|
@@ -1494,6 +1506,20 @@ interface SwapApproval {
|
|
|
1494
1506
|
data?: string;
|
|
1495
1507
|
value: string;
|
|
1496
1508
|
deposit?: string;
|
|
1509
|
+
/**
|
|
1510
|
+
* Permit2 signature-transfer swaps (0x): the EIP-712 `PermitTransferFrom` the account signs for this swap,
|
|
1511
|
+
* rebuilt by the engine from checked values — `typedData` to render, `text` pretty JSON, and its fields read
|
|
1512
|
+
* out (token, exact amount, the one contract that may use it, deadline in unix seconds). The call then goes
|
|
1513
|
+
* out as `data` followed by the signature.
|
|
1514
|
+
*/
|
|
1515
|
+
permit2Transfer?: {
|
|
1516
|
+
typedData: TypedData;
|
|
1517
|
+
text: string;
|
|
1518
|
+
token: string;
|
|
1519
|
+
amount: string;
|
|
1520
|
+
spender: string;
|
|
1521
|
+
deadline: number;
|
|
1522
|
+
};
|
|
1497
1523
|
} | {
|
|
1498
1524
|
kind: 'token-transfer';
|
|
1499
1525
|
token: string;
|
|
@@ -1524,7 +1550,11 @@ interface SwapApproval {
|
|
|
1524
1550
|
}
|
|
1525
1551
|
declare const encodeApproveCalldata: (spender: string, amount: bigint) => string;
|
|
1526
1552
|
declare function swapApprovalPayload(plan: Swap2ExecutionPlan, meta: SwapReviewMeta): SwapApproval;
|
|
1527
|
-
/**
|
|
1553
|
+
/**
|
|
1554
|
+
* Matchers for exactly the operations the plan will perform, in the engine's order. A Permit2 signature-transfer swap
|
|
1555
|
+
* is three operations: the permit (signed first, matched by its EIP-712 digest), the approvals, then the call carrying
|
|
1556
|
+
* the signature (matched by its exact structure, see {@link evmSignedCallMatcher}).
|
|
1557
|
+
*/
|
|
1528
1558
|
declare function planMatchers(plan: Swap2ExecutionPlan): GateMatcher[];
|
|
1529
1559
|
/** The engine's `reviewExecution`: one sheet for the plan; approve → pre-approve exactly its operations; decline → nothing sent. */
|
|
1530
1560
|
declare function reviewSwapPlan(approvals: ApprovalQueue, gate: ReviewGate, meta: SwapReviewMeta): (plan: Swap2ExecutionPlan) => Promise<void>;
|
|
@@ -2077,4 +2107,4 @@ declare class TokenBucket {
|
|
|
2077
2107
|
private prune;
|
|
2078
2108
|
}
|
|
2079
2109
|
|
|
2080
|
-
export { ACTIVE_STATUSES, APPROVALS_MAX_PENDING_PER_ORIGIN, APPROVALS_MAX_PENDING_PER_SITE, APPROVALS_MAX_PENDING_TOTAL, type AddChainApproval, type AlarmsLike, type ApprovalKind, ApprovalQueue, type ApprovalQueueOptions, type ApprovalRateOptions, type ApprovalRequest, type ApprovalRequestOptions, type ApprovalWindow, type AssertionExpectations, type AssertionInput, type AssertionVerdict, BTC_CHAIN, BTC_ESPLORA, CHAIN_ACCOUNT_KEYS, type ChainAccountsKey, type ChainDescriptor, type ConnectApproval, DEFAULT_CHAIN, DEFAULT_NETWORKS, type EarnApproval, type EarnPlan, type EarnReviewMeta, type EarnTx, type EvmNetwork, type EvmSigner, FLOOR_TOLERANCE_BPS, GETLOGS_MAX_SPAN_UNCONNECTED, type GateMatcher, type GatedOp, type HostCheck, type JsonStorage, KEYRING_STORAGE_KEY, LOOKALIKE_PREFIX, LOOKALIKE_SUFFIX, MAX_FEE_REASKS, MULTI_LABEL_SUFFIXES, type MacJsonStorage, type MacJsonStorageOptions, type MacRead, type MacState, NEAR_CHAIN, NEAR_PROVIDERS, NON_EVM_CHAINS, NetworksTable, type OriginPermission, OriginRefused, type OriginVia, PAGE_TARGET, PORT_NAME, type PageEvent, type PageMessageEvent, type PageRequest, type PageResponse, type PageWindow, PermissionStore, type PermissionsState, type PersonalSignBlindHashForm, PhishingDetector, type PhishingList, type PortSender, type PreparedTx, QueueLimitError, type QuoteRoutesOptions, READ_METHODS, RELAY_ERRORS, RELAY_METHOD_MAX, type RankOptions, RecipientBook, type RecipientsState, type RelayChain, type RelayError, type RelayErrorOptions, type RelayEvent, type RelayRequest, type RelayResponse, type RelayToContent, type RelayToWorker, RequestRouter, ReviewDeclined, ReviewGate, type RouteListView, type RouteView, type RouteWarning, type RouterDeps, RouterError, SESSION_DEFAULT_AUTOLOCK_MS, SIGNING_METHODS, SIWE_FORBIDDEN_CHARS, SOLANA_CHAIN, SOLANA_RPCS, STORAGE_MAC_FIELD, STORAGE_VERSION_FIELD, type SealedBox, Session, type SessionAlarms, type SessionOptions, type SessionStorage, type SignApproval, type SignDeps, type SignRequestInfo, type SiweContext, type SiweInfo, type SiweMessage, type StorageAreaLike, type StorageVersionLedger, type StorageVersionLedgerOptions, type StorageVersionOps, type StorageVersions, type SwapApproval, type SwapRecord, type SwapRecordStatus, type SwapReviewMeta, SwapTracker, type SwapTrackerDeps, SwapsStore, type SwitchChainApproval, TON_CHAIN, TON_ENDPOINTS, TRON_CHAIN, TRON_PROVIDERS, TokenBucket, type TokenBucketOptions, type TonAddressParts, type TypedData, VAULT_DEFAULT_ITERATIONS, VAULT_LIMITS, VAULT_MIN_ITERATIONS, VAULT_MIN_PASSWORD_LENGTH, VAULT_MIN_SCRYPT, VAULT_SCRYPT, VAULT_STORAGE_KEY, Vault, type VaultEnvelope, type VaultEnvelopeV1, type VaultEnvelopeV2, VaultError, type VaultErrorCode, type VaultKdfInfo, type VaultOptions, type VaultPasskey, type VaultStorage, ZCASH_BLOCKCHAIR, ZCASH_CHAIN, approvalChallenge, caip2FromChainId, canonicalJson, chainHex, chainTxMatcher, checkSenderOrigin, chromeAlarms, chromeJsonStorage, chromeKeyringStorage, chromeLocalVaultStorage, chromeSessionStorage, classifySignRequest, createSignHandler, decodedMessage, derToRaw, deriveStorageMacKey, describeSiwe, earnApprovalPayload, earnPlanMatchers, encodeApproveCalldata, evmCallMatcher, executionFloor, fromBase64Url, gasLimitExcessive, hostOf, isCatalogChain, isEnvelopeV1, isEnvelopeV2, isLocalHost, isPageEvent, isPageRequest, isPageResponse, isRelayMethod, isRelayRequest, isRelayToContent, levenshtein, lookalikeOf, macJsonStorage, memoryAlarms, memoryApprovalWindow, memoryJsonStorage, memorySessionStorage, memoryVaultStorage, messageText, newRequestId, nonEvmChain, normalizeHost, pageRequestFrom, parseAddChainParams, parseRawAddress, parseSiwe, parseSwapId, planMatchers, prepareTransaction, proofDomain, quoteRoutes, rank, rawToDer, relayError, revealHidden, reviewEarnPlan, reviewSwapPlan, siteOf, siweCrossSite, siweProblems, stampOrigin, storageVersionLedger, swapApprovalPayload, toBase64Url, toRelayError, tonConnectErrorCode, tonProofMessage, tonSignDataMessage, typedDataMatcher, vaultSecretStorage, verifyAssertion };
|
|
2110
|
+
export { ACTIVE_STATUSES, APPROVALS_MAX_PENDING_PER_ORIGIN, APPROVALS_MAX_PENDING_PER_SITE, APPROVALS_MAX_PENDING_TOTAL, type AddChainApproval, type AlarmsLike, type ApprovalKind, ApprovalQueue, type ApprovalQueueOptions, type ApprovalRateOptions, type ApprovalRequest, type ApprovalRequestOptions, type ApprovalWindow, type AssertionExpectations, type AssertionInput, type AssertionVerdict, BTC_CHAIN, BTC_ESPLORA, CHAIN_ACCOUNT_KEYS, type ChainAccountsKey, type ChainDescriptor, type ConnectApproval, DEFAULT_CHAIN, DEFAULT_NETWORKS, type EarnApproval, type EarnPlan, type EarnReviewMeta, type EarnTx, type EvmNetwork, type EvmSigner, FLOOR_TOLERANCE_BPS, GETLOGS_MAX_SPAN_UNCONNECTED, type GateMatcher, type GatedOp, type HostCheck, type JsonStorage, KEYRING_STORAGE_KEY, LOOKALIKE_PREFIX, LOOKALIKE_SUFFIX, MAX_FEE_REASKS, MULTI_LABEL_SUFFIXES, type MacJsonStorage, type MacJsonStorageOptions, type MacRead, type MacState, NEAR_CHAIN, NEAR_PROVIDERS, NON_EVM_CHAINS, NetworksTable, type OriginPermission, OriginRefused, type OriginVia, PAGE_TARGET, PORT_NAME, type PageEvent, type PageMessageEvent, type PageRequest, type PageResponse, type PageWindow, PermissionStore, type PermissionsState, type PersonalSignBlindHashForm, PhishingDetector, type PhishingList, type PortSender, type PreparedTx, QueueLimitError, type QuoteRoutesOptions, READ_METHODS, RELAY_ERRORS, RELAY_METHOD_MAX, type RankOptions, RecipientBook, type RecipientsState, type RelayChain, type RelayError, type RelayErrorOptions, type RelayEvent, type RelayRequest, type RelayResponse, type RelayToContent, type RelayToWorker, RequestRouter, ReviewDeclined, ReviewGate, type RouteListView, type RouteView, type RouteWarning, type RouterDeps, RouterError, SESSION_DEFAULT_AUTOLOCK_MS, SIGNING_METHODS, SIWE_FORBIDDEN_CHARS, SOLANA_CHAIN, SOLANA_RPCS, STORAGE_MAC_FIELD, STORAGE_VERSION_FIELD, type SealedBox, Session, type SessionAlarms, type SessionOptions, type SessionStorage, type SignApproval, type SignDeps, type SignRequestInfo, type SiweContext, type SiweInfo, type SiweMessage, type StorageAreaLike, type StorageVersionLedger, type StorageVersionLedgerOptions, type StorageVersionOps, type StorageVersions, type SwapApproval, type SwapRecord, type SwapRecordStatus, type SwapReviewMeta, SwapTracker, type SwapTrackerDeps, SwapsStore, type SwitchChainApproval, TON_CHAIN, TON_ENDPOINTS, TRON_CHAIN, TRON_PROVIDERS, TokenBucket, type TokenBucketOptions, type TonAddressParts, type TypedData, VAULT_DEFAULT_ITERATIONS, VAULT_LIMITS, VAULT_MIN_ITERATIONS, VAULT_MIN_PASSWORD_LENGTH, VAULT_MIN_SCRYPT, VAULT_SCRYPT, VAULT_STORAGE_KEY, Vault, type VaultEnvelope, type VaultEnvelopeV1, type VaultEnvelopeV2, VaultError, type VaultErrorCode, type VaultKdfInfo, type VaultOptions, type VaultPasskey, type VaultStorage, ZCASH_BLOCKCHAIR, ZCASH_CHAIN, approvalChallenge, caip2FromChainId, canonicalJson, chainHex, chainTxMatcher, checkSenderOrigin, chromeAlarms, chromeJsonStorage, chromeKeyringStorage, chromeLocalVaultStorage, chromeSessionStorage, classifySignRequest, createSignHandler, decodedMessage, derToRaw, deriveStorageMacKey, describeSiwe, earnApprovalPayload, earnPlanMatchers, encodeApproveCalldata, evmCallMatcher, evmSignedCallMatcher, executionFloor, fromBase64Url, gasLimitExcessive, hostOf, isCatalogChain, isEnvelopeV1, isEnvelopeV2, isLocalHost, isPageEvent, isPageRequest, isPageResponse, isRelayMethod, isRelayRequest, isRelayToContent, levenshtein, lookalikeOf, macJsonStorage, memoryAlarms, memoryApprovalWindow, memoryJsonStorage, memorySessionStorage, memoryVaultStorage, messageText, newRequestId, nonEvmChain, normalizeHost, pageRequestFrom, parseAddChainParams, parseRawAddress, parseSiwe, parseSwapId, planMatchers, prepareTransaction, proofDomain, quoteRoutes, rank, rawToDer, relayError, revealHidden, reviewEarnPlan, reviewSwapPlan, siteOf, siweCrossSite, siweProblems, stampOrigin, storageVersionLedger, swapApprovalPayload, toBase64Url, toRelayError, tonConnectErrorCode, tonProofMessage, tonSignDataMessage, typedDataMatcher, vaultSecretStorage, verifyAssertion };
|
package/dist/index.js
CHANGED
|
@@ -2323,6 +2323,19 @@ function evmCallMatcher(expected) {
|
|
|
2323
2323
|
const data = expected.data && expected.data !== "0x" ? lc2(expected.data) : void 0;
|
|
2324
2324
|
return (op) => op.kind === "evm-tx" && op.caip2 === expected.caip2 && lc2(op.to) === lc2(expected.to) && (op.data && op.data !== "0x" ? lc2(op.data) : void 0) === data && op.value === expected.value;
|
|
2325
2325
|
}
|
|
2326
|
+
function evmSignedCallMatcher(expected) {
|
|
2327
|
+
const base = lc2(expected.data);
|
|
2328
|
+
return (op) => {
|
|
2329
|
+
if (op.kind !== "evm-tx" || op.caip2 !== expected.caip2 || lc2(op.to) !== lc2(expected.to) || op.value !== expected.value || !op.data) return false;
|
|
2330
|
+
const data = lc2(op.data);
|
|
2331
|
+
if (!data.startsWith(base)) return false;
|
|
2332
|
+
const tail = data.slice(base.length);
|
|
2333
|
+
const word = /^0{60}([0-9a-f]{4})/.exec(tail);
|
|
2334
|
+
if (!word || !/^[0-9a-f]*$/.test(tail)) return false;
|
|
2335
|
+
const n = parseInt(word[1], 16);
|
|
2336
|
+
return n >= 64 && n <= 2048 && tail.length === 64 + 2 * n;
|
|
2337
|
+
};
|
|
2338
|
+
}
|
|
2326
2339
|
function typedDataMatcher(expected) {
|
|
2327
2340
|
const hash = lc2(expected.typedDataHash);
|
|
2328
2341
|
return (op) => op.kind === "evm-typed-data" && op.caip2 === expected.caip2 && lc2(op.typedDataHash) === hash;
|
|
@@ -2332,7 +2345,7 @@ function chainTxMatcher(expected) {
|
|
|
2332
2345
|
}
|
|
2333
2346
|
|
|
2334
2347
|
// src/swap.ts
|
|
2335
|
-
import { slippageFloor, validQuote } from "@anywalletkit/protocol-swap2-core";
|
|
2348
|
+
import { PERMIT2_ADDRESS, slippageFloor, validQuote } from "@anywalletkit/protocol-swap2-core";
|
|
2336
2349
|
import { typedDataHash } from "@anywalletkit/wallet-evm";
|
|
2337
2350
|
async function quoteRoutes(providers, params, options = {}) {
|
|
2338
2351
|
const timeoutMs = options.timeoutMs ?? 2e4;
|
|
@@ -2474,8 +2487,14 @@ function swapApprovalPayload(plan, meta) {
|
|
|
2474
2487
|
let source;
|
|
2475
2488
|
if (s.kind === "call") {
|
|
2476
2489
|
const deposit = depositOf(s, plan.approvals.length);
|
|
2477
|
-
|
|
2490
|
+
const permit = s.permit2Transfer !== void 0 ? parsePermit2Transfer(s.permit2Transfer) : void 0;
|
|
2491
|
+
source = { kind: "call", to: s.to, ...s.data ? { data: s.data } : {}, value: s.value.toString(), ...deposit ? { deposit } : {}, ...permit ? { permit2Transfer: permit } : {} };
|
|
2478
2492
|
checks.push(deposit || assigned ? depositCheck : { status: "ok", label: `Calls the ${meta.providerLabel} contract` });
|
|
2493
|
+
if (permit) {
|
|
2494
|
+
const exact = BigInt(permit.amount) === plan.sourceAmount && lc3(permit.spender) === lc3(s.to);
|
|
2495
|
+
const minutes = Math.max(0, Math.ceil((permit.deadline * 1e3 - Date.now()) / 6e4));
|
|
2496
|
+
checks.push(exact ? { status: "ok", label: `Permit2 signature: exactly the amount sold, usable only by ${s.to.slice(0, 6)}\u2026${s.to.slice(-4)} in this swap, expires in ${minutes} min` } : { status: "warn", label: "Permit2 signature does not match this swap (amount or contract)" });
|
|
2497
|
+
}
|
|
2479
2498
|
} else if (s.kind === "token-transfer") {
|
|
2480
2499
|
source = { kind: "token-transfer", token: s.token, recipient: s.recipient, amount: s.amount.toString(), ...s.memo ? { memo: s.memo } : {} };
|
|
2481
2500
|
checks.push(depositCheck);
|
|
@@ -2488,6 +2507,7 @@ function swapApprovalPayload(plan, meta) {
|
|
|
2488
2507
|
checks.push({ status: "ok", label: "Signed order \u2014 no transaction is sent from your wallet" });
|
|
2489
2508
|
}
|
|
2490
2509
|
for (const a of plan.approvals) checks.push(a.amount > plan.sourceAmount ? { status: "warn", label: "Approval is larger than this swap needs" } : { status: "ok", label: "Approval is exactly the amount needed" });
|
|
2510
|
+
if (plan.approvals.some((a) => a.amount > 0n && lc3(a.spender) === lc3(PERMIT2_ADDRESS))) checks.push({ status: "ok", label: "Approval goes to Permit2 (shared by many apps): only the signed permit decides who can use it" });
|
|
2491
2511
|
if (plan.approvals.length > 1) checks.push({ status: "ok", label: `${plan.approvals.length} approvals (reset to 0 first)` });
|
|
2492
2512
|
checks.push(!isOwn ? { status: "warn", label: `Funds arrive at ${plan.recipient.slice(0, 6)}\u2026${plan.recipient.slice(-4)}, not your address` } : assigned ? { status: "unknown", label: `Delivery to your address is the ${meta.providerLabel} server\u2019s promise \u2014 this transaction does not enforce it` } : { status: "ok", label: "Funds arrive at your address" });
|
|
2493
2513
|
let slippage;
|
|
@@ -2518,16 +2538,34 @@ function swapApprovalPayload(plan, meta) {
|
|
|
2518
2538
|
...assigned ? { depositAssignedByProvider: true } : {}
|
|
2519
2539
|
};
|
|
2520
2540
|
}
|
|
2541
|
+
function parsePermit2Transfer(json) {
|
|
2542
|
+
const typedData = parseTypedOrder(json);
|
|
2543
|
+
const m = typedData.message;
|
|
2544
|
+
const token = m.permitted?.token;
|
|
2545
|
+
const amount = m.permitted?.amount;
|
|
2546
|
+
const deadline = m.deadline;
|
|
2547
|
+
if (typedData.primaryType !== "PermitTransferFrom" || typeof token !== "string" || typeof amount !== "string" || !/^[0-9]{1,78}$/.test(amount) || typeof m.spender !== "string" || typeof deadline !== "string" || !/^[0-9]{1,12}$/.test(deadline)) {
|
|
2548
|
+
throw new Error("The swap's Permit2 transfer is not a PermitTransferFrom.");
|
|
2549
|
+
}
|
|
2550
|
+
return { typedData, text: JSON.stringify(typedData, null, 2), token, amount, spender: m.spender, deadline: Number(deadline) };
|
|
2551
|
+
}
|
|
2521
2552
|
function parseTypedOrder(json) {
|
|
2522
2553
|
const t = JSON.parse(json);
|
|
2523
2554
|
if (!t || typeof t !== "object" || !t.domain || typeof t.domain !== "object" || !t.types || typeof t.types !== "object" || !t.message || typeof t.message !== "object") throw new Error("The swap order is not EIP-712 typed data.");
|
|
2524
2555
|
return t;
|
|
2525
2556
|
}
|
|
2526
2557
|
function planMatchers(plan) {
|
|
2527
|
-
const m =
|
|
2558
|
+
const m = [];
|
|
2528
2559
|
const s = plan.source;
|
|
2560
|
+
const permit = s.kind === "call" && s.permit2Transfer !== void 0 && plan.fromChain.startsWith("eip155:");
|
|
2561
|
+
if (permit) {
|
|
2562
|
+
if (!s.data) throw new Error("A Permit2 swap plan carries no calldata.");
|
|
2563
|
+
m.push(typedDataMatcher({ caip2: plan.fromChain, typedDataHash: typedDataHash(parsePermit2Transfer(s.permit2Transfer).typedData) }));
|
|
2564
|
+
}
|
|
2565
|
+
m.push(...plan.approvals.map((a) => evmCallMatcher({ caip2: plan.fromChain, to: a.token, data: encodeApproveCalldata(a.spender, a.amount), value: 0n })));
|
|
2529
2566
|
if (s.kind === "call") {
|
|
2530
|
-
if (
|
|
2567
|
+
if (permit) m.push(evmSignedCallMatcher({ caip2: plan.fromChain, to: s.to, data: s.data, value: s.value }));
|
|
2568
|
+
else if (plan.fromChain.startsWith("eip155:")) m.push(evmCallMatcher({ caip2: plan.fromChain, to: s.to, data: s.data, value: s.value }));
|
|
2531
2569
|
else if (plan.fromChain.startsWith("solana:")) m.push((op) => op.kind === "solana-tx" && op.to === s.to && op.value === s.value);
|
|
2532
2570
|
else m.push(chainTxMatcher({ chain: plan.fromChain, to: s.to, amount: s.value, memo: s.memo }));
|
|
2533
2571
|
} else if (s.kind === "token-transfer") {
|
|
@@ -3309,6 +3347,7 @@ export {
|
|
|
3309
3347
|
earnPlanMatchers,
|
|
3310
3348
|
encodeApproveCalldata,
|
|
3311
3349
|
evmCallMatcher,
|
|
3350
|
+
evmSignedCallMatcher,
|
|
3312
3351
|
executionFloor,
|
|
3313
3352
|
fromBase64Url,
|
|
3314
3353
|
gasLimitExcessive,
|