@anywalletkit/extension-kit 0.3.5 → 0.3.6
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 +45 -129
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -52
- package/dist/index.d.ts +18 -52
- package/dist/index.js +47 -119
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { KeyringStorage, SecretStorage } from '@anywalletkit/keyring';
|
|
2
2
|
import { Quote, Swap2ExecutionPlan, CrossChainProvider, QuoteParams, IntentStatus } from '@anywalletkit/protocol-swap2-core';
|
|
3
|
+
import { TonSignDataPayload } from '@anywalletkit/wallet-ton/tonconnect';
|
|
4
|
+
export { TONCONNECT_ERRORS, TONCONNECT_MAX_MESSAGES, TONCONNECT_NETWORKS, TONCONNECT_SIGN_DATA_MAX, TonConnectError, TonConnectMessage, TonConnectParseOptions, TonConnectRequest, TonConnectSendOptions, TonConnectSendTransaction, TonSignDataPayload, parseConnectRequest, parseSendTransaction, parseSignData, sameTonConnectAddress, tonConnectFriendlyAddress, tonConnectRawAddress } from '@anywalletkit/wallet-ton/tonconnect';
|
|
3
5
|
|
|
4
6
|
/** A vault or session rule was broken. Messages are safe to show the user and never contain secrets. */
|
|
5
7
|
declare class VaultError extends Error {
|
|
@@ -1438,56 +1440,20 @@ declare function earnApprovalPayload(plan: EarnPlan, meta: EarnReviewMeta): Earn
|
|
|
1438
1440
|
/** One sheet for the plan; approve → pre-approve exactly its calls; decline → ReviewDeclined, nothing sent. */
|
|
1439
1441
|
declare function reviewEarnPlan(approvals: ApprovalQueue, gate: ReviewGate, meta: EarnReviewMeta, plan: EarnPlan): Promise<void>;
|
|
1440
1442
|
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
manifestUrl: string;
|
|
1456
|
-
/** `ton_addr` always; `ton_proof` with the dApp's payload when asked. */
|
|
1457
|
-
proofPayload?: string;
|
|
1458
|
-
}
|
|
1459
|
-
declare function parseConnectRequest(message: unknown): TonConnectRequest;
|
|
1460
|
-
interface TonConnectMessage {
|
|
1461
|
-
/** Destination, as given (friendly or raw). */
|
|
1462
|
-
address: string;
|
|
1463
|
-
/** Nanotons, decimal string. */
|
|
1464
|
-
amount: string;
|
|
1465
|
-
/** base64 BoC body. */
|
|
1466
|
-
payload?: string;
|
|
1467
|
-
/** base64 BoC state init. */
|
|
1468
|
-
stateInit?: string;
|
|
1469
|
-
}
|
|
1470
|
-
interface TonConnectSendTransaction {
|
|
1471
|
-
validUntil?: number;
|
|
1472
|
-
network?: string;
|
|
1473
|
-
from?: string;
|
|
1474
|
-
messages: TonConnectMessage[];
|
|
1475
|
-
}
|
|
1476
|
-
declare const TONCONNECT_MAX_MESSAGES = 4;
|
|
1477
|
-
/** `sendTransaction` params[0] (a JSON string per the spec, or an object). */
|
|
1478
|
-
declare function parseSendTransaction(param: unknown, options?: {
|
|
1479
|
-
maxMessages?: number;
|
|
1480
|
-
network?: string;
|
|
1481
|
-
}): TonConnectSendTransaction;
|
|
1482
|
-
type TonSignDataPayload = {
|
|
1483
|
-
type: 'text';
|
|
1484
|
-
text: string;
|
|
1485
|
-
} | {
|
|
1486
|
-
type: 'binary';
|
|
1487
|
-
bytes: string;
|
|
1488
|
-
};
|
|
1489
|
-
/** `signData` params[0]: text or binary only — `cell` payloads need schema-aware rendering and are refused by name. */
|
|
1490
|
-
declare function parseSignData(param: unknown): TonSignDataPayload;
|
|
1443
|
+
/**
|
|
1444
|
+
* TON Connect protocol v2 for the extension's JS bridge. Request parsing, error codes and the
|
|
1445
|
+
* signature digests live in one place, `@anywalletkit/wallet-ton/tonconnect`, shared with the
|
|
1446
|
+
* WalletConnect transport (`@anywalletkit/walletconnect-ton`); this module re-exports them and
|
|
1447
|
+
* keeps the bridge-side helpers (the page origin as the proof domain, relay errors as TON Connect
|
|
1448
|
+
* codes). The wallet side (keys, sheet, broadcast) lives in the extension; nothing here touches a key.
|
|
1449
|
+
*
|
|
1450
|
+
* To SIGN, use `WalletAccountTon.signTonProof` / `signTonConnectData` (wallet-ton): they build the
|
|
1451
|
+
* same digests from the request and the account's own address. `account.sign()` refuses these
|
|
1452
|
+
* 32-byte digests — 32 raw bytes may as well be the hash of a transfer — so the digest functions
|
|
1453
|
+
* here are for checking a proof, not for feeding `sign()`.
|
|
1454
|
+
*/
|
|
1455
|
+
|
|
1456
|
+
/** Workchain and 32-byte account hash of a TON address. */
|
|
1491
1457
|
interface TonAddressParts {
|
|
1492
1458
|
workchain: number;
|
|
1493
1459
|
hash: Uint8Array;
|
|
@@ -1506,7 +1472,7 @@ declare function tonSignDataMessage(input: {
|
|
|
1506
1472
|
timestamp: number;
|
|
1507
1473
|
payload: TonSignDataPayload;
|
|
1508
1474
|
}): Uint8Array;
|
|
1509
|
-
/** `0:abcd…` → parts
|
|
1475
|
+
/** `0:abcd…` → parts. Friendly addresses are the wallet package's job (it hands us the raw form). */
|
|
1510
1476
|
declare function parseRawAddress(raw: string): TonAddressParts;
|
|
1511
1477
|
/** The dApp's domain for proofs, from the page origin (host only, as the spec's `domain.value`). */
|
|
1512
1478
|
declare function proofDomain(origin: string): string;
|
|
@@ -1647,4 +1613,4 @@ declare class RecipientBook {
|
|
|
1647
1613
|
}>;
|
|
1648
1614
|
}
|
|
1649
1615
|
|
|
1650
|
-
export { ACTIVE_STATUSES, APPROVALS_MAX_PENDING_PER_ORIGIN, type AddChainApproval, type AlarmsLike, type ApprovalKind, ApprovalQueue, type ApprovalQueueOptions, type ApprovalRequest, 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, type GateMatcher, type GatedOp, type HostCheck, type JsonStorage, KEYRING_STORAGE_KEY, LOOKALIKE_PREFIX, LOOKALIKE_SUFFIX, 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, PhishingDetector, type PhishingList, type PortSender, type PreparedTx, QueueLimitError, type QuoteRoutesOptions, READ_METHODS, RELAY_ERRORS, RELAY_METHOD_MAX, 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 RouterDeps, RouterError, SESSION_DEFAULT_AUTOLOCK_MS, SIGNING_METHODS, SOLANA_CHAIN, SOLANA_RPCS, type SealedBox, Session, type SessionAlarms, type SessionOptions, type SessionStorage, type SignApproval, type SignDeps, type SignRequestInfo, type SiweContext, type SiweInfo, type SiweMessage, type StorageAreaLike, type SwapApproval, type SwapRecord, type SwapRecordStatus, type SwapReviewMeta, SwapTracker, type SwapTrackerDeps, SwapsStore, type SwitchChainApproval,
|
|
1616
|
+
export { ACTIVE_STATUSES, APPROVALS_MAX_PENDING_PER_ORIGIN, type AddChainApproval, type AlarmsLike, type ApprovalKind, ApprovalQueue, type ApprovalQueueOptions, type ApprovalRequest, 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, type GateMatcher, type GatedOp, type HostCheck, type JsonStorage, KEYRING_STORAGE_KEY, LOOKALIKE_PREFIX, LOOKALIKE_SUFFIX, 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, PhishingDetector, type PhishingList, type PortSender, type PreparedTx, QueueLimitError, type QuoteRoutesOptions, READ_METHODS, RELAY_ERRORS, RELAY_METHOD_MAX, 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 RouterDeps, RouterError, SESSION_DEFAULT_AUTOLOCK_MS, SIGNING_METHODS, SOLANA_CHAIN, SOLANA_RPCS, type SealedBox, Session, type SessionAlarms, type SessionOptions, type SessionStorage, type SignApproval, type SignDeps, type SignRequestInfo, type SiweContext, type SiweInfo, type SiweMessage, type StorageAreaLike, type SwapApproval, type SwapRecord, type SwapRecordStatus, type SwapReviewMeta, SwapTracker, type SwapTrackerDeps, SwapsStore, type SwitchChainApproval, TON_CHAIN, TON_ENDPOINTS, TRON_CHAIN, TRON_PROVIDERS, 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, chainHex, chainTxMatcher, checkSenderOrigin, chromeAlarms, chromeJsonStorage, chromeKeyringStorage, chromeLocalVaultStorage, chromeSessionStorage, classifySignRequest, createSignHandler, decodedMessage, derToRaw, describeSiwe, earnApprovalPayload, earnPlanMatchers, encodeApproveCalldata, evmCallMatcher, executionFloor, fromBase64Url, hostOf, isCatalogChain, isEnvelopeV1, isEnvelopeV2, isLocalHost, isPageEvent, isPageRequest, isPageResponse, isRelayMethod, isRelayRequest, isRelayToContent, levenshtein, lookalikeOf, memoryAlarms, memoryApprovalWindow, memoryJsonStorage, memorySessionStorage, memoryVaultStorage, messageText, newRequestId, nonEvmChain, normalizeHost, pageRequestFrom, parseAddChainParams, parseRawAddress, parseSiwe, parseSwapId, planMatchers, prepareTransaction, proofDomain, quoteRoutes, rank, rawToDer, relayError, reviewEarnPlan, reviewSwapPlan, siweProblems, stampOrigin, swapApprovalPayload, toBase64Url, toRelayError, tonConnectErrorCode, tonProofMessage, tonSignDataMessage, typedDataMatcher, vaultSecretStorage, verifyAssertion };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { KeyringStorage, SecretStorage } from '@anywalletkit/keyring';
|
|
2
2
|
import { Quote, Swap2ExecutionPlan, CrossChainProvider, QuoteParams, IntentStatus } from '@anywalletkit/protocol-swap2-core';
|
|
3
|
+
import { TonSignDataPayload } from '@anywalletkit/wallet-ton/tonconnect';
|
|
4
|
+
export { TONCONNECT_ERRORS, TONCONNECT_MAX_MESSAGES, TONCONNECT_NETWORKS, TONCONNECT_SIGN_DATA_MAX, TonConnectError, TonConnectMessage, TonConnectParseOptions, TonConnectRequest, TonConnectSendOptions, TonConnectSendTransaction, TonSignDataPayload, parseConnectRequest, parseSendTransaction, parseSignData, sameTonConnectAddress, tonConnectFriendlyAddress, tonConnectRawAddress } from '@anywalletkit/wallet-ton/tonconnect';
|
|
3
5
|
|
|
4
6
|
/** A vault or session rule was broken. Messages are safe to show the user and never contain secrets. */
|
|
5
7
|
declare class VaultError extends Error {
|
|
@@ -1438,56 +1440,20 @@ declare function earnApprovalPayload(plan: EarnPlan, meta: EarnReviewMeta): Earn
|
|
|
1438
1440
|
/** One sheet for the plan; approve → pre-approve exactly its calls; decline → ReviewDeclined, nothing sent. */
|
|
1439
1441
|
declare function reviewEarnPlan(approvals: ApprovalQueue, gate: ReviewGate, meta: EarnReviewMeta, plan: EarnPlan): Promise<void>;
|
|
1440
1442
|
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
manifestUrl: string;
|
|
1456
|
-
/** `ton_addr` always; `ton_proof` with the dApp's payload when asked. */
|
|
1457
|
-
proofPayload?: string;
|
|
1458
|
-
}
|
|
1459
|
-
declare function parseConnectRequest(message: unknown): TonConnectRequest;
|
|
1460
|
-
interface TonConnectMessage {
|
|
1461
|
-
/** Destination, as given (friendly or raw). */
|
|
1462
|
-
address: string;
|
|
1463
|
-
/** Nanotons, decimal string. */
|
|
1464
|
-
amount: string;
|
|
1465
|
-
/** base64 BoC body. */
|
|
1466
|
-
payload?: string;
|
|
1467
|
-
/** base64 BoC state init. */
|
|
1468
|
-
stateInit?: string;
|
|
1469
|
-
}
|
|
1470
|
-
interface TonConnectSendTransaction {
|
|
1471
|
-
validUntil?: number;
|
|
1472
|
-
network?: string;
|
|
1473
|
-
from?: string;
|
|
1474
|
-
messages: TonConnectMessage[];
|
|
1475
|
-
}
|
|
1476
|
-
declare const TONCONNECT_MAX_MESSAGES = 4;
|
|
1477
|
-
/** `sendTransaction` params[0] (a JSON string per the spec, or an object). */
|
|
1478
|
-
declare function parseSendTransaction(param: unknown, options?: {
|
|
1479
|
-
maxMessages?: number;
|
|
1480
|
-
network?: string;
|
|
1481
|
-
}): TonConnectSendTransaction;
|
|
1482
|
-
type TonSignDataPayload = {
|
|
1483
|
-
type: 'text';
|
|
1484
|
-
text: string;
|
|
1485
|
-
} | {
|
|
1486
|
-
type: 'binary';
|
|
1487
|
-
bytes: string;
|
|
1488
|
-
};
|
|
1489
|
-
/** `signData` params[0]: text or binary only — `cell` payloads need schema-aware rendering and are refused by name. */
|
|
1490
|
-
declare function parseSignData(param: unknown): TonSignDataPayload;
|
|
1443
|
+
/**
|
|
1444
|
+
* TON Connect protocol v2 for the extension's JS bridge. Request parsing, error codes and the
|
|
1445
|
+
* signature digests live in one place, `@anywalletkit/wallet-ton/tonconnect`, shared with the
|
|
1446
|
+
* WalletConnect transport (`@anywalletkit/walletconnect-ton`); this module re-exports them and
|
|
1447
|
+
* keeps the bridge-side helpers (the page origin as the proof domain, relay errors as TON Connect
|
|
1448
|
+
* codes). The wallet side (keys, sheet, broadcast) lives in the extension; nothing here touches a key.
|
|
1449
|
+
*
|
|
1450
|
+
* To SIGN, use `WalletAccountTon.signTonProof` / `signTonConnectData` (wallet-ton): they build the
|
|
1451
|
+
* same digests from the request and the account's own address. `account.sign()` refuses these
|
|
1452
|
+
* 32-byte digests — 32 raw bytes may as well be the hash of a transfer — so the digest functions
|
|
1453
|
+
* here are for checking a proof, not for feeding `sign()`.
|
|
1454
|
+
*/
|
|
1455
|
+
|
|
1456
|
+
/** Workchain and 32-byte account hash of a TON address. */
|
|
1491
1457
|
interface TonAddressParts {
|
|
1492
1458
|
workchain: number;
|
|
1493
1459
|
hash: Uint8Array;
|
|
@@ -1506,7 +1472,7 @@ declare function tonSignDataMessage(input: {
|
|
|
1506
1472
|
timestamp: number;
|
|
1507
1473
|
payload: TonSignDataPayload;
|
|
1508
1474
|
}): Uint8Array;
|
|
1509
|
-
/** `0:abcd…` → parts
|
|
1475
|
+
/** `0:abcd…` → parts. Friendly addresses are the wallet package's job (it hands us the raw form). */
|
|
1510
1476
|
declare function parseRawAddress(raw: string): TonAddressParts;
|
|
1511
1477
|
/** The dApp's domain for proofs, from the page origin (host only, as the spec's `domain.value`). */
|
|
1512
1478
|
declare function proofDomain(origin: string): string;
|
|
@@ -1647,4 +1613,4 @@ declare class RecipientBook {
|
|
|
1647
1613
|
}>;
|
|
1648
1614
|
}
|
|
1649
1615
|
|
|
1650
|
-
export { ACTIVE_STATUSES, APPROVALS_MAX_PENDING_PER_ORIGIN, type AddChainApproval, type AlarmsLike, type ApprovalKind, ApprovalQueue, type ApprovalQueueOptions, type ApprovalRequest, 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, type GateMatcher, type GatedOp, type HostCheck, type JsonStorage, KEYRING_STORAGE_KEY, LOOKALIKE_PREFIX, LOOKALIKE_SUFFIX, 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, PhishingDetector, type PhishingList, type PortSender, type PreparedTx, QueueLimitError, type QuoteRoutesOptions, READ_METHODS, RELAY_ERRORS, RELAY_METHOD_MAX, 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 RouterDeps, RouterError, SESSION_DEFAULT_AUTOLOCK_MS, SIGNING_METHODS, SOLANA_CHAIN, SOLANA_RPCS, type SealedBox, Session, type SessionAlarms, type SessionOptions, type SessionStorage, type SignApproval, type SignDeps, type SignRequestInfo, type SiweContext, type SiweInfo, type SiweMessage, type StorageAreaLike, type SwapApproval, type SwapRecord, type SwapRecordStatus, type SwapReviewMeta, SwapTracker, type SwapTrackerDeps, SwapsStore, type SwitchChainApproval,
|
|
1616
|
+
export { ACTIVE_STATUSES, APPROVALS_MAX_PENDING_PER_ORIGIN, type AddChainApproval, type AlarmsLike, type ApprovalKind, ApprovalQueue, type ApprovalQueueOptions, type ApprovalRequest, 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, type GateMatcher, type GatedOp, type HostCheck, type JsonStorage, KEYRING_STORAGE_KEY, LOOKALIKE_PREFIX, LOOKALIKE_SUFFIX, 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, PhishingDetector, type PhishingList, type PortSender, type PreparedTx, QueueLimitError, type QuoteRoutesOptions, READ_METHODS, RELAY_ERRORS, RELAY_METHOD_MAX, 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 RouterDeps, RouterError, SESSION_DEFAULT_AUTOLOCK_MS, SIGNING_METHODS, SOLANA_CHAIN, SOLANA_RPCS, type SealedBox, Session, type SessionAlarms, type SessionOptions, type SessionStorage, type SignApproval, type SignDeps, type SignRequestInfo, type SiweContext, type SiweInfo, type SiweMessage, type StorageAreaLike, type SwapApproval, type SwapRecord, type SwapRecordStatus, type SwapReviewMeta, SwapTracker, type SwapTrackerDeps, SwapsStore, type SwitchChainApproval, TON_CHAIN, TON_ENDPOINTS, TRON_CHAIN, TRON_PROVIDERS, 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, chainHex, chainTxMatcher, checkSenderOrigin, chromeAlarms, chromeJsonStorage, chromeKeyringStorage, chromeLocalVaultStorage, chromeSessionStorage, classifySignRequest, createSignHandler, decodedMessage, derToRaw, describeSiwe, earnApprovalPayload, earnPlanMatchers, encodeApproveCalldata, evmCallMatcher, executionFloor, fromBase64Url, hostOf, isCatalogChain, isEnvelopeV1, isEnvelopeV2, isLocalHost, isPageEvent, isPageRequest, isPageResponse, isRelayMethod, isRelayRequest, isRelayToContent, levenshtein, lookalikeOf, memoryAlarms, memoryApprovalWindow, memoryJsonStorage, memorySessionStorage, memoryVaultStorage, messageText, newRequestId, nonEvmChain, normalizeHost, pageRequestFrom, parseAddChainParams, parseRawAddress, parseSiwe, parseSwapId, planMatchers, prepareTransaction, proofDomain, quoteRoutes, rank, rawToDer, relayError, reviewEarnPlan, reviewSwapPlan, siweProblems, stampOrigin, swapApprovalPayload, toBase64Url, toRelayError, tonConnectErrorCode, tonProofMessage, tonSignDataMessage, typedDataMatcher, vaultSecretStorage, verifyAssertion };
|
package/dist/index.js
CHANGED
|
@@ -1999,15 +1999,15 @@ import { SWAP2_ID_PREFIX } from "@anywalletkit/protocol-swap2-core";
|
|
|
1999
1999
|
var ACTIVE_STATUSES = /* @__PURE__ */ new Set(["pending", "action-required", "refund-pending", "partial", "claiming"]);
|
|
2000
2000
|
function parseSwapId(id) {
|
|
2001
2001
|
if (!id.startsWith(`${SWAP2_ID_PREFIX}.`)) return null;
|
|
2002
|
-
const
|
|
2003
|
-
if (
|
|
2004
|
-
if (
|
|
2005
|
-
const provider = decodeURIComponent(
|
|
2006
|
-
const intentId = decodeURIComponent(
|
|
2007
|
-
const sourceTxHash =
|
|
2008
|
-
const destTxHash =
|
|
2002
|
+
const parts2 = id.slice(SWAP2_ID_PREFIX.length + 1).split(".");
|
|
2003
|
+
if (parts2.length < 2 || parts2.length > 5 || !parts2[0] || !parts2[1]) return null;
|
|
2004
|
+
if (parts2[4] !== void 0 && (parts2[4] !== "ok" || !parts2[3])) return null;
|
|
2005
|
+
const provider = decodeURIComponent(parts2[0]);
|
|
2006
|
+
const intentId = decodeURIComponent(parts2[1]);
|
|
2007
|
+
const sourceTxHash = parts2[2] ? decodeURIComponent(parts2[2]) : void 0;
|
|
2008
|
+
const destTxHash = parts2[3] ? decodeURIComponent(parts2[3]) : void 0;
|
|
2009
2009
|
if (destTxHash && !sourceTxHash) return null;
|
|
2010
|
-
return { provider, intentId, ...sourceTxHash ? { sourceTxHash } : {}, ...destTxHash ? { destTxHash } : {}, ...
|
|
2010
|
+
return { provider, intentId, ...sourceTxHash ? { sourceTxHash } : {}, ...destTxHash ? { destTxHash } : {}, ...parts2[4] !== void 0 ? { destTxConfirmed: true } : {} };
|
|
2011
2011
|
}
|
|
2012
2012
|
var SwapsStore = class {
|
|
2013
2013
|
constructor(storage) {
|
|
@@ -2146,115 +2146,38 @@ async function reviewEarnPlan(approvals, gate, meta, plan) {
|
|
|
2146
2146
|
}
|
|
2147
2147
|
|
|
2148
2148
|
// src/tonconnect.ts
|
|
2149
|
-
import {
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
for (const i of items) if (i?.name !== "ton_addr" && i?.name !== "ton_proof") throw new TonConnectError(TONCONNECT_ERRORS.badRequest, `Unknown connect item ${String(i?.name)}.`);
|
|
2167
|
-
return { manifestUrl: m.manifestUrl, ...proof ? { proofPayload: proof.payload } : {} };
|
|
2168
|
-
}
|
|
2169
|
-
var TONCONNECT_MAX_MESSAGES = 4;
|
|
2170
|
-
function parseSendTransaction(param, options = {}) {
|
|
2171
|
-
let o;
|
|
2172
|
-
try {
|
|
2173
|
-
o = typeof param === "string" ? JSON.parse(param) : param;
|
|
2174
|
-
} catch {
|
|
2175
|
-
throw new TonConnectError(TONCONNECT_ERRORS.badRequest, "sendTransaction params[0] is not valid JSON.");
|
|
2176
|
-
}
|
|
2177
|
-
if (!o || typeof o !== "object") throw new TonConnectError(TONCONNECT_ERRORS.badRequest, "sendTransaction needs a request object.");
|
|
2178
|
-
const network = options.network ?? "-239";
|
|
2179
|
-
if (o.network !== void 0 && String(o.network) !== network) throw new TonConnectError(TONCONNECT_ERRORS.badRequest, `This wallet is on network ${network}; the request names ${String(o.network)}.`);
|
|
2180
|
-
const raw = Array.isArray(o.messages) ? o.messages : [];
|
|
2181
|
-
if (raw.length === 0) throw new TonConnectError(TONCONNECT_ERRORS.badRequest, "sendTransaction has no messages.");
|
|
2182
|
-
if (raw.length > (options.maxMessages ?? TONCONNECT_MAX_MESSAGES)) throw new TonConnectError(TONCONNECT_ERRORS.badRequest, `At most ${options.maxMessages ?? TONCONNECT_MAX_MESSAGES} messages per transaction.`);
|
|
2183
|
-
const messages = raw.map((m, i) => {
|
|
2184
|
-
if (typeof m.address !== "string" || !m.address) throw new TonConnectError(TONCONNECT_ERRORS.badRequest, `Message ${i + 1} has no address.`);
|
|
2185
|
-
if (typeof m.amount !== "string" || !/^[0-9]+$/.test(m.amount)) throw new TonConnectError(TONCONNECT_ERRORS.badRequest, `Message ${i + 1} amount must be a decimal string of nanotons.`);
|
|
2186
|
-
if (m.payload !== void 0 && typeof m.payload !== "string") throw new TonConnectError(TONCONNECT_ERRORS.badRequest, `Message ${i + 1} payload must be a base64 BoC.`);
|
|
2187
|
-
if (m.stateInit !== void 0 && typeof m.stateInit !== "string") throw new TonConnectError(TONCONNECT_ERRORS.badRequest, `Message ${i + 1} stateInit must be a base64 BoC.`);
|
|
2188
|
-
return { address: m.address, amount: m.amount, ...m.payload ? { payload: m.payload } : {}, ...m.stateInit ? { stateInit: m.stateInit } : {} };
|
|
2189
|
-
});
|
|
2190
|
-
const validUntil = typeof o.valid_until === "number" ? o.valid_until : typeof o.validUntil === "number" ? o.validUntil : void 0;
|
|
2191
|
-
if (validUntil !== void 0 && validUntil * 1e3 < Date.now()) throw new TonConnectError(TONCONNECT_ERRORS.badRequest, "The request has expired (valid_until is in the past).");
|
|
2192
|
-
return { messages, ...validUntil !== void 0 ? { validUntil } : {}, ...o.network !== void 0 ? { network: String(o.network) } : {}, ...typeof o.from === "string" ? { from: o.from } : {} };
|
|
2193
|
-
}
|
|
2194
|
-
function parseSignData(param) {
|
|
2195
|
-
let o;
|
|
2196
|
-
try {
|
|
2197
|
-
o = typeof param === "string" ? JSON.parse(param) : param;
|
|
2198
|
-
} catch {
|
|
2199
|
-
throw new TonConnectError(TONCONNECT_ERRORS.badRequest, "signData params[0] is not valid JSON.");
|
|
2200
|
-
}
|
|
2201
|
-
if (o?.type === "text" && typeof o.text === "string") return { type: "text", text: o.text };
|
|
2202
|
-
if (o?.type === "binary" && typeof o.bytes === "string") return { type: "binary", bytes: o.bytes };
|
|
2203
|
-
if (o?.type === "cell") throw new TonConnectError(TONCONNECT_ERRORS.methodNotSupported, "signData with a cell payload is not supported by this wallet.");
|
|
2204
|
-
throw new TonConnectError(TONCONNECT_ERRORS.badRequest, 'signData payload must be { type: "text", text } or { type: "binary", bytes }.');
|
|
2205
|
-
}
|
|
2206
|
-
var utf82 = (s) => new TextEncoder().encode(s);
|
|
2207
|
-
var int32BE = (n) => {
|
|
2208
|
-
const b = new Uint8Array(4);
|
|
2209
|
-
new DataView(b.buffer).setInt32(0, n, false);
|
|
2210
|
-
return b;
|
|
2211
|
-
};
|
|
2212
|
-
var uint32LE = (n) => {
|
|
2213
|
-
const b = new Uint8Array(4);
|
|
2214
|
-
new DataView(b.buffer).setUint32(0, n, true);
|
|
2215
|
-
return b;
|
|
2216
|
-
};
|
|
2217
|
-
var uint32BE = (n) => {
|
|
2218
|
-
const b = new Uint8Array(4);
|
|
2219
|
-
new DataView(b.buffer).setUint32(0, n, false);
|
|
2220
|
-
return b;
|
|
2221
|
-
};
|
|
2222
|
-
var uint64LE = (n) => {
|
|
2223
|
-
const b = new Uint8Array(8);
|
|
2224
|
-
new DataView(b.buffer).setBigUint64(0, BigInt(n), true);
|
|
2225
|
-
return b;
|
|
2226
|
-
};
|
|
2227
|
-
var uint64BE = (n) => {
|
|
2228
|
-
const b = new Uint8Array(8);
|
|
2229
|
-
new DataView(b.buffer).setBigUint64(0, BigInt(n), false);
|
|
2230
|
-
return b;
|
|
2231
|
-
};
|
|
2232
|
-
var concat = (...parts) => {
|
|
2233
|
-
const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
|
|
2234
|
-
let o = 0;
|
|
2235
|
-
for (const p of parts) {
|
|
2236
|
-
out.set(p, o);
|
|
2237
|
-
o += p.length;
|
|
2238
|
-
}
|
|
2239
|
-
return out;
|
|
2149
|
+
import { TONCONNECT_ERRORS, TonConnectError, tonAddressParts, tonProofDigest, tonSignDataDigest } from "@anywalletkit/wallet-ton/tonconnect";
|
|
2150
|
+
import {
|
|
2151
|
+
TONCONNECT_ERRORS as TONCONNECT_ERRORS2,
|
|
2152
|
+
TONCONNECT_MAX_MESSAGES,
|
|
2153
|
+
TONCONNECT_NETWORKS,
|
|
2154
|
+
TONCONNECT_SIGN_DATA_MAX,
|
|
2155
|
+
TonConnectError as TonConnectError2,
|
|
2156
|
+
parseConnectRequest,
|
|
2157
|
+
parseSendTransaction,
|
|
2158
|
+
parseSignData,
|
|
2159
|
+
tonConnectRawAddress,
|
|
2160
|
+
tonConnectFriendlyAddress,
|
|
2161
|
+
sameTonConnectAddress
|
|
2162
|
+
} from "@anywalletkit/wallet-ton/tonconnect";
|
|
2163
|
+
var parts = (a) => {
|
|
2164
|
+
if (a.hash.length !== 32) throw new TonConnectError(TONCONNECT_ERRORS.unknown, "address hash must be 32 bytes");
|
|
2165
|
+
return { workChain: a.workchain, hash: a.hash };
|
|
2240
2166
|
};
|
|
2241
2167
|
function tonProofMessage(input) {
|
|
2242
|
-
|
|
2243
|
-
const domain = utf82(input.domain);
|
|
2244
|
-
const inner = concat(utf82("ton-proof-item-v2/"), int32BE(input.address.workchain), input.address.hash, uint32LE(domain.length), domain, uint64LE(input.timestamp), utf82(input.payload));
|
|
2245
|
-
return sha256(concat(new Uint8Array([255, 255]), utf82("ton-connect"), sha256(inner)));
|
|
2168
|
+
return tonProofDigest(parts(input.address), { domain: input.domain, timestamp: input.timestamp, payload: input.payload });
|
|
2246
2169
|
}
|
|
2247
2170
|
function tonSignDataMessage(input) {
|
|
2248
|
-
|
|
2249
|
-
const domain = utf82(input.domain);
|
|
2250
|
-
const payload = input.payload.type === "text" ? utf82(input.payload.text) : Uint8Array.from(atob(input.payload.bytes), (c) => c.charCodeAt(0));
|
|
2251
|
-
const prefix = utf82(input.payload.type === "text" ? "txt" : "bin");
|
|
2252
|
-
return sha256(concat(new Uint8Array([255, 255]), utf82("ton-connect/sign-data/"), int32BE(input.address.workchain), input.address.hash, uint32BE(domain.length), domain, uint64BE(input.timestamp), prefix, uint32BE(payload.length), payload));
|
|
2171
|
+
return tonSignDataDigest(parts(input.address), { domain: input.domain, timestamp: input.timestamp, payload: input.payload });
|
|
2253
2172
|
}
|
|
2254
2173
|
function parseRawAddress(raw) {
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2174
|
+
if (!/^-?\d+:[0-9a-fA-F]{64}$/.test(raw)) throw new TonConnectError(TONCONNECT_ERRORS.unknown, `not a raw TON address: ${raw}`);
|
|
2175
|
+
try {
|
|
2176
|
+
const p = tonAddressParts(raw);
|
|
2177
|
+
return { workchain: p.workChain, hash: p.hash };
|
|
2178
|
+
} catch {
|
|
2179
|
+
throw new TonConnectError(TONCONNECT_ERRORS.unknown, `not a raw TON address: ${raw}`);
|
|
2180
|
+
}
|
|
2258
2181
|
}
|
|
2259
2182
|
function proofDomain(origin) {
|
|
2260
2183
|
try {
|
|
@@ -2264,7 +2187,7 @@ function proofDomain(origin) {
|
|
|
2264
2187
|
}
|
|
2265
2188
|
}
|
|
2266
2189
|
function tonConnectErrorCode(e) {
|
|
2267
|
-
if (e instanceof TonConnectError) return e.code;
|
|
2190
|
+
if (e instanceof TonConnectError || e?.name === "TonConnectError") return e.code;
|
|
2268
2191
|
const code = e?.code;
|
|
2269
2192
|
if (code === 4001) return TONCONNECT_ERRORS.userDeclined;
|
|
2270
2193
|
if (code === 4100) return TONCONNECT_ERRORS.unknownApp;
|
|
@@ -2349,14 +2272,14 @@ function hostOf(hostOrOrigin) {
|
|
|
2349
2272
|
}
|
|
2350
2273
|
}
|
|
2351
2274
|
function matchesList(host, list) {
|
|
2352
|
-
const
|
|
2353
|
-
for (let i = 0; i <
|
|
2275
|
+
const parts2 = host.split(".");
|
|
2276
|
+
for (let i = 0; i < parts2.length - 1; i++) if (list.has(parts2.slice(i).join("."))) return true;
|
|
2354
2277
|
return list.has(host);
|
|
2355
2278
|
}
|
|
2356
2279
|
function stripForFuzzy(host) {
|
|
2357
|
-
const
|
|
2358
|
-
if (
|
|
2359
|
-
return
|
|
2280
|
+
const parts2 = host.replace(/^www\./, "").split(".");
|
|
2281
|
+
if (parts2.length > 1) parts2.pop();
|
|
2282
|
+
return parts2.join(".");
|
|
2360
2283
|
}
|
|
2361
2284
|
function levenshtein(a, b) {
|
|
2362
2285
|
if (a === b) return 0;
|
|
@@ -2542,13 +2465,15 @@ export {
|
|
|
2542
2465
|
Session,
|
|
2543
2466
|
SwapTracker,
|
|
2544
2467
|
SwapsStore,
|
|
2545
|
-
TONCONNECT_ERRORS,
|
|
2468
|
+
TONCONNECT_ERRORS2 as TONCONNECT_ERRORS,
|
|
2546
2469
|
TONCONNECT_MAX_MESSAGES,
|
|
2470
|
+
TONCONNECT_NETWORKS,
|
|
2471
|
+
TONCONNECT_SIGN_DATA_MAX,
|
|
2547
2472
|
TON_CHAIN,
|
|
2548
2473
|
TON_ENDPOINTS,
|
|
2549
2474
|
TRON_CHAIN,
|
|
2550
2475
|
TRON_PROVIDERS,
|
|
2551
|
-
TonConnectError,
|
|
2476
|
+
TonConnectError2 as TonConnectError,
|
|
2552
2477
|
VAULT_DEFAULT_ITERATIONS,
|
|
2553
2478
|
VAULT_LIMITS,
|
|
2554
2479
|
VAULT_MIN_ITERATIONS,
|
|
@@ -2620,12 +2545,15 @@ export {
|
|
|
2620
2545
|
relayError,
|
|
2621
2546
|
reviewEarnPlan,
|
|
2622
2547
|
reviewSwapPlan,
|
|
2548
|
+
sameTonConnectAddress,
|
|
2623
2549
|
siweProblems,
|
|
2624
2550
|
stampOrigin,
|
|
2625
2551
|
swapApprovalPayload,
|
|
2626
2552
|
toBase64Url,
|
|
2627
2553
|
toRelayError,
|
|
2628
2554
|
tonConnectErrorCode,
|
|
2555
|
+
tonConnectFriendlyAddress,
|
|
2556
|
+
tonConnectRawAddress,
|
|
2629
2557
|
tonProofMessage,
|
|
2630
2558
|
tonSignDataMessage,
|
|
2631
2559
|
typedDataMatcher,
|