@anywalletkit/wallet-ton 0.2.2 → 0.2.4

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 CHANGED
@@ -1061,12 +1061,12 @@ var WalletAccountTon = class _WalletAccountTon extends WalletAccountReadOnlyTon
1061
1061
  return sim.fees.total;
1062
1062
  }
1063
1063
  /** Sign without broadcasting. Returns the external-message BODY as base64 BoC (pass it back to sendTransaction as a Cell). */
1064
- async signTransaction(tx) {
1064
+ async signTransaction(tx, options = {}) {
1065
1065
  if (tx instanceof import_core10.Cell) {
1066
- await this.preflight(tx, this._config.transactionMaxFee, "transaction");
1066
+ await this.preflight(tx, (0, import_core9.feeLimit)(this._config.transactionMaxFee, options), "transaction");
1067
1067
  return tx.toBoc().toString("base64");
1068
1068
  }
1069
- const { body } = await this.prepare(this.toMessages(tx), this._config.transactionMaxFee, "transaction");
1069
+ const { body } = await this.prepare(this.toMessages(tx), (0, import_core9.feeLimit)(this._config.transactionMaxFee, options), "transaction");
1070
1070
  return body.toBoc().toString("base64");
1071
1071
  }
1072
1072
  async broadcast(body) {
@@ -1076,16 +1076,16 @@ var WalletAccountTon = class _WalletAccountTon extends WalletAccountReadOnlyTon
1076
1076
  return body.hash().toString("hex");
1077
1077
  }
1078
1078
  /** Sign and broadcast; `hash` is the body hash (hex) — resolve it with getTransactionReceipt. */
1079
- async sendTransaction(tx) {
1079
+ async sendTransaction(tx, options = {}) {
1080
1080
  this.requireRpc("send transactions");
1081
- const { body, fee } = tx instanceof import_core10.Cell ? { body: tx, fee: await this.preflight(tx, this._config.transactionMaxFee, "transaction") } : await this.prepare(this.toMessages(tx), this._config.transactionMaxFee, "transaction");
1081
+ const { body, fee } = tx instanceof import_core10.Cell ? { body: tx, fee: await this.preflight(tx, (0, import_core9.feeLimit)(this._config.transactionMaxFee, options), "transaction") } : await this.prepare(this.toMessages(tx), (0, import_core9.feeLimit)(this._config.transactionMaxFee, options), "transaction");
1082
1082
  return { hash: await this.broadcast(body), fee };
1083
1083
  }
1084
1084
  /** TON (no `token`) or jetton transfer. */
1085
- async transfer(o) {
1085
+ async transfer(o, writeOptions = {}) {
1086
1086
  this.requireRpc("transfer tokens");
1087
1087
  const message = o.token ? await this.jettonTransferMessage(o) : this.transactionMessage({ to: o.recipient, value: o.amount, ...o.memo !== void 0 ? { body: o.memo } : {} });
1088
- const { body, fee } = await this.prepare([message], this._config.transferMaxFee, "transfer");
1088
+ const { body, fee } = await this.prepare([message], (0, import_core9.feeLimit)(this._config.transferMaxFee, writeOptions), "transfer");
1089
1089
  return { hash: await this.broadcast(body), fee };
1090
1090
  }
1091
1091
  /** The same wallet as a {@link WalletAccountReadOnlyTon}. */
@@ -1140,10 +1140,10 @@ var WalletManagerTon = class _WalletManagerTon extends import_core11.WalletManag
1140
1140
  const full = path.startsWith("m/") ? path : `${TON_BASE_PATH}/${path}`;
1141
1141
  const cached = this._accounts.get(full);
1142
1142
  if (cached) return cached;
1143
- const signer = import_core11.LocalSigner.leafFromSeed(this.seedBytes(), "ed25519", full);
1144
- const account = new WalletAccountTon(signer, signer.publicKey, full, this._config);
1145
- this._accounts.set(full, account);
1146
- return account;
1143
+ return this.cachedAccount(full, () => {
1144
+ const signer = import_core11.LocalSigner.leafFromSeed(this.seedBytes(), "ed25519", full);
1145
+ return new WalletAccountTon(signer, signer.publicKey, full, this._config);
1146
+ });
1147
1147
  }
1148
1148
  /** The one path a non-derivable signer answers to: its own, or 'external'. */
1149
1149
  singlePath(signer) {
@@ -1152,22 +1152,18 @@ var WalletManagerTon = class _WalletManagerTon extends import_core11.WalletManag
1152
1152
  /** Resolve `path` against an injected signer: the signer itself, or a child when it can derive there. */
1153
1153
  async fromSigner(signer, path) {
1154
1154
  this.requireSigner("ed25519");
1155
- let leaf = signer;
1155
+ let rel;
1156
1156
  let key = this.singlePath(signer);
1157
1157
  if ((0, import_core11.isSeedSigner)(signer)) {
1158
1158
  if (path === signer.path) key = path;
1159
1159
  else if (path.startsWith(`${signer.path}/`)) {
1160
- leaf = await (signer.deriveLeaf ?? signer.derive).call(signer, path.slice(signer.path.length + 1));
1160
+ rel = path.slice(signer.path.length + 1);
1161
1161
  key = path;
1162
1162
  } else throw new import_core11.SignerError(`This signer yields a single account at path '${signer.path}'; it cannot provide ${path}.`);
1163
1163
  } else if (path !== `${TON_BASE_PATH}/0'` && path !== "external") {
1164
1164
  throw new import_core11.SignerError(`An external signer yields a single account; ${path} is not derivable from it.`);
1165
1165
  }
1166
- const cached = this._accounts.get(key);
1167
- if (cached) return cached;
1168
- const account = new WalletAccountTon(leaf, await leaf.getPublicKey(), key, this._config);
1169
- this._accounts.set(key, account);
1170
- return account;
1166
+ return this.signerAccount(key, signer, rel, (leaf, publicKey) => new WalletAccountTon(leaf, publicKey, key, this._config));
1171
1167
  }
1172
1168
  /** Watch-only account for a public key (hex or bytes) — TON addresses derive from the key, not the other way round. */
1173
1169
  getReadOnlyAccount(publicKey) {