@anywalletkit/wallet-ton 0.2.2 → 0.2.3
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 +14 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +15 -19
- package/dist/index.js.map +1 -1
- package/package.json +9 -6
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Cell, StateInit, TupleReader, Address, TupleItem, Transaction, MessageRelaxed } from '@ton/core';
|
|
2
|
-
import { SignerError, IWalletAccountReadOnly, IWalletAccount, Signer, TransferResult, WalletManager, FeeRates } from '@anywalletkit/core';
|
|
2
|
+
import { SignerError, IWalletAccountReadOnly, IWalletAccount, Signer, WriteOptions, TransferResult, WalletManager, FeeRates } from '@anywalletkit/core';
|
|
3
3
|
export { HistoryFetch, HistoryUnavailableError, TonChainTx, TonHistoryBackend, TonHistoryCursor, TonHistoryOptions, TonHistoryPage, TonHistoryRaw, TonHistorySource, TonapiAction, TonapiEvent, V3Transaction, createTonHistory, decodeCursor as decodeHistoryCursor, encodeCursor as encodeHistoryCursor, mapActions as mapTonapiActions, mapTonapiEvent, mapToncenterTransaction, rawTonAddress, tonExplorerTxUrl, valueFlowTransfers } from './history.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -652,12 +652,12 @@ declare class WalletAccountTon extends WalletAccountReadOnlyTon implements IWall
|
|
|
652
652
|
private prepare;
|
|
653
653
|
private preflight;
|
|
654
654
|
/** Sign without broadcasting. Returns the external-message BODY as base64 BoC (pass it back to sendTransaction as a Cell). */
|
|
655
|
-
signTransaction(tx: TonSendable): Promise<string>;
|
|
655
|
+
signTransaction(tx: TonSendable, options?: WriteOptions): Promise<string>;
|
|
656
656
|
private broadcast;
|
|
657
657
|
/** Sign and broadcast; `hash` is the body hash (hex) — resolve it with getTransactionReceipt. */
|
|
658
|
-
sendTransaction(tx: TonSendable): Promise<TransferResult>;
|
|
658
|
+
sendTransaction(tx: TonSendable, options?: WriteOptions): Promise<TransferResult>;
|
|
659
659
|
/** TON (no `token`) or jetton transfer. */
|
|
660
|
-
transfer(o: TonTransferOptions): Promise<TransferResult>;
|
|
660
|
+
transfer(o: TonTransferOptions, writeOptions?: WriteOptions): Promise<TransferResult>;
|
|
661
661
|
/** The same wallet as a {@link WalletAccountReadOnlyTon}. */
|
|
662
662
|
toReadOnlyAccount(): IWalletAccountReadOnly;
|
|
663
663
|
/** Disposes the signer: a local key is zeroized, an external one is released. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Cell, StateInit, TupleReader, Address, TupleItem, Transaction, MessageRelaxed } from '@ton/core';
|
|
2
|
-
import { SignerError, IWalletAccountReadOnly, IWalletAccount, Signer, TransferResult, WalletManager, FeeRates } from '@anywalletkit/core';
|
|
2
|
+
import { SignerError, IWalletAccountReadOnly, IWalletAccount, Signer, WriteOptions, TransferResult, WalletManager, FeeRates } from '@anywalletkit/core';
|
|
3
3
|
export { HistoryFetch, HistoryUnavailableError, TonChainTx, TonHistoryBackend, TonHistoryCursor, TonHistoryOptions, TonHistoryPage, TonHistoryRaw, TonHistorySource, TonapiAction, TonapiEvent, V3Transaction, createTonHistory, decodeCursor as decodeHistoryCursor, encodeCursor as encodeHistoryCursor, mapActions as mapTonapiActions, mapTonapiEvent, mapToncenterTransaction, rawTonAddress, tonExplorerTxUrl, valueFlowTransfers } from './history.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -652,12 +652,12 @@ declare class WalletAccountTon extends WalletAccountReadOnlyTon implements IWall
|
|
|
652
652
|
private prepare;
|
|
653
653
|
private preflight;
|
|
654
654
|
/** Sign without broadcasting. Returns the external-message BODY as base64 BoC (pass it back to sendTransaction as a Cell). */
|
|
655
|
-
signTransaction(tx: TonSendable): Promise<string>;
|
|
655
|
+
signTransaction(tx: TonSendable, options?: WriteOptions): Promise<string>;
|
|
656
656
|
private broadcast;
|
|
657
657
|
/** Sign and broadcast; `hash` is the body hash (hex) — resolve it with getTransactionReceipt. */
|
|
658
|
-
sendTransaction(tx: TonSendable): Promise<TransferResult>;
|
|
658
|
+
sendTransaction(tx: TonSendable, options?: WriteOptions): Promise<TransferResult>;
|
|
659
659
|
/** TON (no `token`) or jetton transfer. */
|
|
660
|
-
transfer(o: TonTransferOptions): Promise<TransferResult>;
|
|
660
|
+
transfer(o: TonTransferOptions, writeOptions?: WriteOptions): Promise<TransferResult>;
|
|
661
661
|
/** The same wallet as a {@link WalletAccountReadOnlyTon}. */
|
|
662
662
|
toReadOnlyAccount(): IWalletAccountReadOnly;
|
|
663
663
|
/** Disposes the signer: a local key is zeroized, an external one is released. */
|
package/dist/index.js
CHANGED
|
@@ -934,7 +934,7 @@ function randomQueryId() {
|
|
|
934
934
|
}
|
|
935
935
|
|
|
936
936
|
// src/account.ts
|
|
937
|
-
import { LocalSigner, requireCurve } from "@anywalletkit/core";
|
|
937
|
+
import { LocalSigner, feeLimit, requireCurve } from "@anywalletkit/core";
|
|
938
938
|
import { Cell as Cell5 } from "@ton/core";
|
|
939
939
|
var toHex = (u8) => Array.from(u8, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
940
940
|
var WalletAccountTon = class _WalletAccountTon extends WalletAccountReadOnlyTon {
|
|
@@ -1002,12 +1002,12 @@ var WalletAccountTon = class _WalletAccountTon extends WalletAccountReadOnlyTon
|
|
|
1002
1002
|
return sim.fees.total;
|
|
1003
1003
|
}
|
|
1004
1004
|
/** Sign without broadcasting. Returns the external-message BODY as base64 BoC (pass it back to sendTransaction as a Cell). */
|
|
1005
|
-
async signTransaction(tx) {
|
|
1005
|
+
async signTransaction(tx, options = {}) {
|
|
1006
1006
|
if (tx instanceof Cell5) {
|
|
1007
|
-
await this.preflight(tx, this._config.transactionMaxFee, "transaction");
|
|
1007
|
+
await this.preflight(tx, feeLimit(this._config.transactionMaxFee, options), "transaction");
|
|
1008
1008
|
return tx.toBoc().toString("base64");
|
|
1009
1009
|
}
|
|
1010
|
-
const { body } = await this.prepare(this.toMessages(tx), this._config.transactionMaxFee, "transaction");
|
|
1010
|
+
const { body } = await this.prepare(this.toMessages(tx), feeLimit(this._config.transactionMaxFee, options), "transaction");
|
|
1011
1011
|
return body.toBoc().toString("base64");
|
|
1012
1012
|
}
|
|
1013
1013
|
async broadcast(body) {
|
|
@@ -1017,16 +1017,16 @@ var WalletAccountTon = class _WalletAccountTon extends WalletAccountReadOnlyTon
|
|
|
1017
1017
|
return body.hash().toString("hex");
|
|
1018
1018
|
}
|
|
1019
1019
|
/** Sign and broadcast; `hash` is the body hash (hex) — resolve it with getTransactionReceipt. */
|
|
1020
|
-
async sendTransaction(tx) {
|
|
1020
|
+
async sendTransaction(tx, options = {}) {
|
|
1021
1021
|
this.requireRpc("send transactions");
|
|
1022
|
-
const { body, fee } = tx instanceof Cell5 ? { body: tx, fee: await this.preflight(tx, this._config.transactionMaxFee, "transaction") } : await this.prepare(this.toMessages(tx), this._config.transactionMaxFee, "transaction");
|
|
1022
|
+
const { body, fee } = tx instanceof Cell5 ? { body: tx, fee: await this.preflight(tx, feeLimit(this._config.transactionMaxFee, options), "transaction") } : await this.prepare(this.toMessages(tx), feeLimit(this._config.transactionMaxFee, options), "transaction");
|
|
1023
1023
|
return { hash: await this.broadcast(body), fee };
|
|
1024
1024
|
}
|
|
1025
1025
|
/** TON (no `token`) or jetton transfer. */
|
|
1026
|
-
async transfer(o) {
|
|
1026
|
+
async transfer(o, writeOptions = {}) {
|
|
1027
1027
|
this.requireRpc("transfer tokens");
|
|
1028
1028
|
const message = o.token ? await this.jettonTransferMessage(o) : this.transactionMessage({ to: o.recipient, value: o.amount, ...o.memo !== void 0 ? { body: o.memo } : {} });
|
|
1029
|
-
const { body, fee } = await this.prepare([message], this._config.transferMaxFee, "transfer");
|
|
1029
|
+
const { body, fee } = await this.prepare([message], feeLimit(this._config.transferMaxFee, writeOptions), "transfer");
|
|
1030
1030
|
return { hash: await this.broadcast(body), fee };
|
|
1031
1031
|
}
|
|
1032
1032
|
/** The same wallet as a {@link WalletAccountReadOnlyTon}. */
|
|
@@ -1081,10 +1081,10 @@ var WalletManagerTon = class _WalletManagerTon extends WalletManager {
|
|
|
1081
1081
|
const full = path.startsWith("m/") ? path : `${TON_BASE_PATH}/${path}`;
|
|
1082
1082
|
const cached = this._accounts.get(full);
|
|
1083
1083
|
if (cached) return cached;
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1084
|
+
return this.cachedAccount(full, () => {
|
|
1085
|
+
const signer = LocalSigner2.leafFromSeed(this.seedBytes(), "ed25519", full);
|
|
1086
|
+
return new WalletAccountTon(signer, signer.publicKey, full, this._config);
|
|
1087
|
+
});
|
|
1088
1088
|
}
|
|
1089
1089
|
/** The one path a non-derivable signer answers to: its own, or 'external'. */
|
|
1090
1090
|
singlePath(signer) {
|
|
@@ -1093,22 +1093,18 @@ var WalletManagerTon = class _WalletManagerTon extends WalletManager {
|
|
|
1093
1093
|
/** Resolve `path` against an injected signer: the signer itself, or a child when it can derive there. */
|
|
1094
1094
|
async fromSigner(signer, path) {
|
|
1095
1095
|
this.requireSigner("ed25519");
|
|
1096
|
-
let
|
|
1096
|
+
let rel;
|
|
1097
1097
|
let key = this.singlePath(signer);
|
|
1098
1098
|
if (isSeedSigner(signer)) {
|
|
1099
1099
|
if (path === signer.path) key = path;
|
|
1100
1100
|
else if (path.startsWith(`${signer.path}/`)) {
|
|
1101
|
-
|
|
1101
|
+
rel = path.slice(signer.path.length + 1);
|
|
1102
1102
|
key = path;
|
|
1103
1103
|
} else throw new SignerError2(`This signer yields a single account at path '${signer.path}'; it cannot provide ${path}.`);
|
|
1104
1104
|
} else if (path !== `${TON_BASE_PATH}/0'` && path !== "external") {
|
|
1105
1105
|
throw new SignerError2(`An external signer yields a single account; ${path} is not derivable from it.`);
|
|
1106
1106
|
}
|
|
1107
|
-
|
|
1108
|
-
if (cached) return cached;
|
|
1109
|
-
const account = new WalletAccountTon(leaf, await leaf.getPublicKey(), key, this._config);
|
|
1110
|
-
this._accounts.set(key, account);
|
|
1111
|
-
return account;
|
|
1107
|
+
return this.signerAccount(key, signer, rel, (leaf, publicKey) => new WalletAccountTon(leaf, publicKey, key, this._config));
|
|
1112
1108
|
}
|
|
1113
1109
|
/** Watch-only account for a public key (hex or bytes) — TON addresses derive from the key, not the other way round. */
|
|
1114
1110
|
getReadOnlyAccount(publicKey) {
|