@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.cjs
CHANGED
|
@@ -57,13 +57,15 @@ __export(src_exports, {
|
|
|
57
57
|
Session: () => Session,
|
|
58
58
|
SwapTracker: () => SwapTracker,
|
|
59
59
|
SwapsStore: () => SwapsStore,
|
|
60
|
-
TONCONNECT_ERRORS: () => TONCONNECT_ERRORS,
|
|
61
|
-
TONCONNECT_MAX_MESSAGES: () => TONCONNECT_MAX_MESSAGES,
|
|
60
|
+
TONCONNECT_ERRORS: () => import_tonconnect2.TONCONNECT_ERRORS,
|
|
61
|
+
TONCONNECT_MAX_MESSAGES: () => import_tonconnect2.TONCONNECT_MAX_MESSAGES,
|
|
62
|
+
TONCONNECT_NETWORKS: () => import_tonconnect2.TONCONNECT_NETWORKS,
|
|
63
|
+
TONCONNECT_SIGN_DATA_MAX: () => import_tonconnect2.TONCONNECT_SIGN_DATA_MAX,
|
|
62
64
|
TON_CHAIN: () => TON_CHAIN,
|
|
63
65
|
TON_ENDPOINTS: () => TON_ENDPOINTS,
|
|
64
66
|
TRON_CHAIN: () => TRON_CHAIN,
|
|
65
67
|
TRON_PROVIDERS: () => TRON_PROVIDERS,
|
|
66
|
-
TonConnectError: () => TonConnectError,
|
|
68
|
+
TonConnectError: () => import_tonconnect2.TonConnectError,
|
|
67
69
|
VAULT_DEFAULT_ITERATIONS: () => VAULT_DEFAULT_ITERATIONS,
|
|
68
70
|
VAULT_LIMITS: () => VAULT_LIMITS,
|
|
69
71
|
VAULT_MIN_ITERATIONS: () => VAULT_MIN_ITERATIONS,
|
|
@@ -120,10 +122,10 @@ __export(src_exports, {
|
|
|
120
122
|
normalizeHost: () => normalizeHost,
|
|
121
123
|
pageRequestFrom: () => pageRequestFrom,
|
|
122
124
|
parseAddChainParams: () => parseAddChainParams,
|
|
123
|
-
parseConnectRequest: () => parseConnectRequest,
|
|
125
|
+
parseConnectRequest: () => import_tonconnect2.parseConnectRequest,
|
|
124
126
|
parseRawAddress: () => parseRawAddress,
|
|
125
|
-
parseSendTransaction: () => parseSendTransaction,
|
|
126
|
-
parseSignData: () => parseSignData,
|
|
127
|
+
parseSendTransaction: () => import_tonconnect2.parseSendTransaction,
|
|
128
|
+
parseSignData: () => import_tonconnect2.parseSignData,
|
|
127
129
|
parseSiwe: () => parseSiwe,
|
|
128
130
|
parseSwapId: () => parseSwapId,
|
|
129
131
|
planMatchers: () => planMatchers,
|
|
@@ -135,12 +137,15 @@ __export(src_exports, {
|
|
|
135
137
|
relayError: () => relayError,
|
|
136
138
|
reviewEarnPlan: () => reviewEarnPlan,
|
|
137
139
|
reviewSwapPlan: () => reviewSwapPlan,
|
|
140
|
+
sameTonConnectAddress: () => import_tonconnect2.sameTonConnectAddress,
|
|
138
141
|
siweProblems: () => siweProblems,
|
|
139
142
|
stampOrigin: () => stampOrigin,
|
|
140
143
|
swapApprovalPayload: () => swapApprovalPayload,
|
|
141
144
|
toBase64Url: () => toBase64Url,
|
|
142
145
|
toRelayError: () => toRelayError,
|
|
143
146
|
tonConnectErrorCode: () => tonConnectErrorCode,
|
|
147
|
+
tonConnectFriendlyAddress: () => import_tonconnect2.tonConnectFriendlyAddress,
|
|
148
|
+
tonConnectRawAddress: () => import_tonconnect2.tonConnectRawAddress,
|
|
144
149
|
tonProofMessage: () => tonProofMessage,
|
|
145
150
|
tonSignDataMessage: () => tonSignDataMessage,
|
|
146
151
|
typedDataMatcher: () => typedDataMatcher,
|
|
@@ -2150,15 +2155,15 @@ var import_protocol_swap2_core2 = require("@anywalletkit/protocol-swap2-core");
|
|
|
2150
2155
|
var ACTIVE_STATUSES = /* @__PURE__ */ new Set(["pending", "action-required", "refund-pending", "partial", "claiming"]);
|
|
2151
2156
|
function parseSwapId(id) {
|
|
2152
2157
|
if (!id.startsWith(`${import_protocol_swap2_core2.SWAP2_ID_PREFIX}.`)) return null;
|
|
2153
|
-
const
|
|
2154
|
-
if (
|
|
2155
|
-
if (
|
|
2156
|
-
const provider = decodeURIComponent(
|
|
2157
|
-
const intentId = decodeURIComponent(
|
|
2158
|
-
const sourceTxHash =
|
|
2159
|
-
const destTxHash =
|
|
2158
|
+
const parts2 = id.slice(import_protocol_swap2_core2.SWAP2_ID_PREFIX.length + 1).split(".");
|
|
2159
|
+
if (parts2.length < 2 || parts2.length > 5 || !parts2[0] || !parts2[1]) return null;
|
|
2160
|
+
if (parts2[4] !== void 0 && (parts2[4] !== "ok" || !parts2[3])) return null;
|
|
2161
|
+
const provider = decodeURIComponent(parts2[0]);
|
|
2162
|
+
const intentId = decodeURIComponent(parts2[1]);
|
|
2163
|
+
const sourceTxHash = parts2[2] ? decodeURIComponent(parts2[2]) : void 0;
|
|
2164
|
+
const destTxHash = parts2[3] ? decodeURIComponent(parts2[3]) : void 0;
|
|
2160
2165
|
if (destTxHash && !sourceTxHash) return null;
|
|
2161
|
-
return { provider, intentId, ...sourceTxHash ? { sourceTxHash } : {}, ...destTxHash ? { destTxHash } : {}, ...
|
|
2166
|
+
return { provider, intentId, ...sourceTxHash ? { sourceTxHash } : {}, ...destTxHash ? { destTxHash } : {}, ...parts2[4] !== void 0 ? { destTxConfirmed: true } : {} };
|
|
2162
2167
|
}
|
|
2163
2168
|
var SwapsStore = class {
|
|
2164
2169
|
constructor(storage) {
|
|
@@ -2297,131 +2302,42 @@ async function reviewEarnPlan(approvals, gate, meta, plan) {
|
|
|
2297
2302
|
}
|
|
2298
2303
|
|
|
2299
2304
|
// src/tonconnect.ts
|
|
2300
|
-
var
|
|
2301
|
-
var
|
|
2302
|
-
var
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
this.code = code;
|
|
2306
|
-
this.name = "TonConnectError";
|
|
2307
|
-
}
|
|
2308
|
-
code;
|
|
2309
|
-
};
|
|
2310
|
-
function parseConnectRequest(message) {
|
|
2311
|
-
const m = message;
|
|
2312
|
-
if (!m || typeof m.manifestUrl !== "string" || !/^https:\/\//.test(m.manifestUrl)) throw new TonConnectError(TONCONNECT_ERRORS.badRequest, "ConnectRequest needs an https manifestUrl.");
|
|
2313
|
-
const items = Array.isArray(m.items) ? m.items : [];
|
|
2314
|
-
if (!items.some((i) => i?.name === "ton_addr")) throw new TonConnectError(TONCONNECT_ERRORS.badRequest, "ConnectRequest must ask for ton_addr.");
|
|
2315
|
-
const proof = items.find((i) => i?.name === "ton_proof");
|
|
2316
|
-
if (proof && typeof proof.payload !== "string") throw new TonConnectError(TONCONNECT_ERRORS.badRequest, "ton_proof needs a string payload.");
|
|
2317
|
-
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)}.`);
|
|
2318
|
-
return { manifestUrl: m.manifestUrl, ...proof ? { proofPayload: proof.payload } : {} };
|
|
2319
|
-
}
|
|
2320
|
-
var TONCONNECT_MAX_MESSAGES = 4;
|
|
2321
|
-
function parseSendTransaction(param, options = {}) {
|
|
2322
|
-
let o;
|
|
2323
|
-
try {
|
|
2324
|
-
o = typeof param === "string" ? JSON.parse(param) : param;
|
|
2325
|
-
} catch {
|
|
2326
|
-
throw new TonConnectError(TONCONNECT_ERRORS.badRequest, "sendTransaction params[0] is not valid JSON.");
|
|
2327
|
-
}
|
|
2328
|
-
if (!o || typeof o !== "object") throw new TonConnectError(TONCONNECT_ERRORS.badRequest, "sendTransaction needs a request object.");
|
|
2329
|
-
const network = options.network ?? "-239";
|
|
2330
|
-
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)}.`);
|
|
2331
|
-
const raw = Array.isArray(o.messages) ? o.messages : [];
|
|
2332
|
-
if (raw.length === 0) throw new TonConnectError(TONCONNECT_ERRORS.badRequest, "sendTransaction has no messages.");
|
|
2333
|
-
if (raw.length > (options.maxMessages ?? TONCONNECT_MAX_MESSAGES)) throw new TonConnectError(TONCONNECT_ERRORS.badRequest, `At most ${options.maxMessages ?? TONCONNECT_MAX_MESSAGES} messages per transaction.`);
|
|
2334
|
-
const messages = raw.map((m, i) => {
|
|
2335
|
-
if (typeof m.address !== "string" || !m.address) throw new TonConnectError(TONCONNECT_ERRORS.badRequest, `Message ${i + 1} has no address.`);
|
|
2336
|
-
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.`);
|
|
2337
|
-
if (m.payload !== void 0 && typeof m.payload !== "string") throw new TonConnectError(TONCONNECT_ERRORS.badRequest, `Message ${i + 1} payload must be a base64 BoC.`);
|
|
2338
|
-
if (m.stateInit !== void 0 && typeof m.stateInit !== "string") throw new TonConnectError(TONCONNECT_ERRORS.badRequest, `Message ${i + 1} stateInit must be a base64 BoC.`);
|
|
2339
|
-
return { address: m.address, amount: m.amount, ...m.payload ? { payload: m.payload } : {}, ...m.stateInit ? { stateInit: m.stateInit } : {} };
|
|
2340
|
-
});
|
|
2341
|
-
const validUntil = typeof o.valid_until === "number" ? o.valid_until : typeof o.validUntil === "number" ? o.validUntil : void 0;
|
|
2342
|
-
if (validUntil !== void 0 && validUntil * 1e3 < Date.now()) throw new TonConnectError(TONCONNECT_ERRORS.badRequest, "The request has expired (valid_until is in the past).");
|
|
2343
|
-
return { messages, ...validUntil !== void 0 ? { validUntil } : {}, ...o.network !== void 0 ? { network: String(o.network) } : {}, ...typeof o.from === "string" ? { from: o.from } : {} };
|
|
2344
|
-
}
|
|
2345
|
-
function parseSignData(param) {
|
|
2346
|
-
let o;
|
|
2347
|
-
try {
|
|
2348
|
-
o = typeof param === "string" ? JSON.parse(param) : param;
|
|
2349
|
-
} catch {
|
|
2350
|
-
throw new TonConnectError(TONCONNECT_ERRORS.badRequest, "signData params[0] is not valid JSON.");
|
|
2351
|
-
}
|
|
2352
|
-
if (o?.type === "text" && typeof o.text === "string") return { type: "text", text: o.text };
|
|
2353
|
-
if (o?.type === "binary" && typeof o.bytes === "string") return { type: "binary", bytes: o.bytes };
|
|
2354
|
-
if (o?.type === "cell") throw new TonConnectError(TONCONNECT_ERRORS.methodNotSupported, "signData with a cell payload is not supported by this wallet.");
|
|
2355
|
-
throw new TonConnectError(TONCONNECT_ERRORS.badRequest, 'signData payload must be { type: "text", text } or { type: "binary", bytes }.');
|
|
2356
|
-
}
|
|
2357
|
-
var utf82 = (s) => new TextEncoder().encode(s);
|
|
2358
|
-
var int32BE = (n) => {
|
|
2359
|
-
const b = new Uint8Array(4);
|
|
2360
|
-
new DataView(b.buffer).setInt32(0, n, false);
|
|
2361
|
-
return b;
|
|
2362
|
-
};
|
|
2363
|
-
var uint32LE = (n) => {
|
|
2364
|
-
const b = new Uint8Array(4);
|
|
2365
|
-
new DataView(b.buffer).setUint32(0, n, true);
|
|
2366
|
-
return b;
|
|
2367
|
-
};
|
|
2368
|
-
var uint32BE = (n) => {
|
|
2369
|
-
const b = new Uint8Array(4);
|
|
2370
|
-
new DataView(b.buffer).setUint32(0, n, false);
|
|
2371
|
-
return b;
|
|
2372
|
-
};
|
|
2373
|
-
var uint64LE = (n) => {
|
|
2374
|
-
const b = new Uint8Array(8);
|
|
2375
|
-
new DataView(b.buffer).setBigUint64(0, BigInt(n), true);
|
|
2376
|
-
return b;
|
|
2377
|
-
};
|
|
2378
|
-
var uint64BE = (n) => {
|
|
2379
|
-
const b = new Uint8Array(8);
|
|
2380
|
-
new DataView(b.buffer).setBigUint64(0, BigInt(n), false);
|
|
2381
|
-
return b;
|
|
2382
|
-
};
|
|
2383
|
-
var concat = (...parts) => {
|
|
2384
|
-
const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
|
|
2385
|
-
let o = 0;
|
|
2386
|
-
for (const p of parts) {
|
|
2387
|
-
out.set(p, o);
|
|
2388
|
-
o += p.length;
|
|
2389
|
-
}
|
|
2390
|
-
return out;
|
|
2305
|
+
var import_tonconnect = require("@anywalletkit/wallet-ton/tonconnect");
|
|
2306
|
+
var import_tonconnect2 = require("@anywalletkit/wallet-ton/tonconnect");
|
|
2307
|
+
var parts = (a) => {
|
|
2308
|
+
if (a.hash.length !== 32) throw new import_tonconnect.TonConnectError(import_tonconnect.TONCONNECT_ERRORS.unknown, "address hash must be 32 bytes");
|
|
2309
|
+
return { workChain: a.workchain, hash: a.hash };
|
|
2391
2310
|
};
|
|
2392
2311
|
function tonProofMessage(input) {
|
|
2393
|
-
|
|
2394
|
-
const domain = utf82(input.domain);
|
|
2395
|
-
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));
|
|
2396
|
-
return (0, import_sha2.sha256)(concat(new Uint8Array([255, 255]), utf82("ton-connect"), (0, import_sha2.sha256)(inner)));
|
|
2312
|
+
return (0, import_tonconnect.tonProofDigest)(parts(input.address), { domain: input.domain, timestamp: input.timestamp, payload: input.payload });
|
|
2397
2313
|
}
|
|
2398
2314
|
function tonSignDataMessage(input) {
|
|
2399
|
-
|
|
2400
|
-
const domain = utf82(input.domain);
|
|
2401
|
-
const payload = input.payload.type === "text" ? utf82(input.payload.text) : Uint8Array.from(atob(input.payload.bytes), (c) => c.charCodeAt(0));
|
|
2402
|
-
const prefix = utf82(input.payload.type === "text" ? "txt" : "bin");
|
|
2403
|
-
return (0, import_sha2.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));
|
|
2315
|
+
return (0, import_tonconnect.tonSignDataDigest)(parts(input.address), { domain: input.domain, timestamp: input.timestamp, payload: input.payload });
|
|
2404
2316
|
}
|
|
2405
2317
|
function parseRawAddress(raw) {
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2318
|
+
if (!/^-?\d+:[0-9a-fA-F]{64}$/.test(raw)) throw new import_tonconnect.TonConnectError(import_tonconnect.TONCONNECT_ERRORS.unknown, `not a raw TON address: ${raw}`);
|
|
2319
|
+
try {
|
|
2320
|
+
const p = (0, import_tonconnect.tonAddressParts)(raw);
|
|
2321
|
+
return { workchain: p.workChain, hash: p.hash };
|
|
2322
|
+
} catch {
|
|
2323
|
+
throw new import_tonconnect.TonConnectError(import_tonconnect.TONCONNECT_ERRORS.unknown, `not a raw TON address: ${raw}`);
|
|
2324
|
+
}
|
|
2409
2325
|
}
|
|
2410
2326
|
function proofDomain(origin) {
|
|
2411
2327
|
try {
|
|
2412
2328
|
return new URL(origin).host;
|
|
2413
2329
|
} catch {
|
|
2414
|
-
throw new TonConnectError(TONCONNECT_ERRORS.badRequest, `bad origin ${origin}`);
|
|
2330
|
+
throw new import_tonconnect.TonConnectError(import_tonconnect.TONCONNECT_ERRORS.badRequest, `bad origin ${origin}`);
|
|
2415
2331
|
}
|
|
2416
2332
|
}
|
|
2417
2333
|
function tonConnectErrorCode(e) {
|
|
2418
|
-
if (e instanceof TonConnectError) return e.code;
|
|
2334
|
+
if (e instanceof import_tonconnect.TonConnectError || e?.name === "TonConnectError") return e.code;
|
|
2419
2335
|
const code = e?.code;
|
|
2420
|
-
if (code === 4001) return TONCONNECT_ERRORS.userDeclined;
|
|
2421
|
-
if (code === 4100) return TONCONNECT_ERRORS.unknownApp;
|
|
2422
|
-
if (code === 4200) return TONCONNECT_ERRORS.methodNotSupported;
|
|
2423
|
-
if (code === -32602) return TONCONNECT_ERRORS.badRequest;
|
|
2424
|
-
return TONCONNECT_ERRORS.unknown;
|
|
2336
|
+
if (code === 4001) return import_tonconnect.TONCONNECT_ERRORS.userDeclined;
|
|
2337
|
+
if (code === 4100) return import_tonconnect.TONCONNECT_ERRORS.unknownApp;
|
|
2338
|
+
if (code === 4200) return import_tonconnect.TONCONNECT_ERRORS.methodNotSupported;
|
|
2339
|
+
if (code === -32602) return import_tonconnect.TONCONNECT_ERRORS.badRequest;
|
|
2340
|
+
return import_tonconnect.TONCONNECT_ERRORS.unknown;
|
|
2425
2341
|
}
|
|
2426
2342
|
|
|
2427
2343
|
// src/phishing.ts
|
|
@@ -2500,14 +2416,14 @@ function hostOf(hostOrOrigin) {
|
|
|
2500
2416
|
}
|
|
2501
2417
|
}
|
|
2502
2418
|
function matchesList(host, list) {
|
|
2503
|
-
const
|
|
2504
|
-
for (let i = 0; i <
|
|
2419
|
+
const parts2 = host.split(".");
|
|
2420
|
+
for (let i = 0; i < parts2.length - 1; i++) if (list.has(parts2.slice(i).join("."))) return true;
|
|
2505
2421
|
return list.has(host);
|
|
2506
2422
|
}
|
|
2507
2423
|
function stripForFuzzy(host) {
|
|
2508
|
-
const
|
|
2509
|
-
if (
|
|
2510
|
-
return
|
|
2424
|
+
const parts2 = host.replace(/^www\./, "").split(".");
|
|
2425
|
+
if (parts2.length > 1) parts2.pop();
|
|
2426
|
+
return parts2.join(".");
|
|
2511
2427
|
}
|
|
2512
2428
|
function levenshtein(a, b) {
|
|
2513
2429
|
if (a === b) return 0;
|