@meshconnect/uwc-ton-connector 0.8.3 → 0.9.0-snapshot.2007cea
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.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/jetton-transfer.d.ts.map +1 -1
- package/dist/jetton-transfer.js +21 -12
- package/dist/jetton-transfer.js.map +1 -1
- package/dist/text-comment.d.ts +60 -0
- package/dist/text-comment.d.ts.map +1 -0
- package/dist/text-comment.js +79 -0
- package/dist/text-comment.js.map +1 -0
- package/dist/ton-connect-connector.d.ts.map +1 -1
- package/dist/ton-connect-connector.js.map +1 -1
- package/dist/ton-transaction-utils.d.ts +7 -5
- package/dist/ton-transaction-utils.d.ts.map +1 -1
- package/dist/ton-transaction-utils.js +15 -6
- package/dist/ton-transaction-utils.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +1 -0
- package/src/jetton-transfer.test.ts +49 -0
- package/src/jetton-transfer.ts +25 -14
- package/src/text-comment.test.ts +113 -0
- package/src/text-comment.ts +93 -0
- package/src/ton-connect-connector.ts +1 -2
- package/src/ton-transaction-utils.test.ts +20 -9
- package/src/ton-transaction-utils.ts +19 -7
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { NamespacedStorage } from './namespaced-storage';
|
|
|
2
2
|
export { isValidBase64 } from './validation';
|
|
3
3
|
export { buildTonTransactionRequest, buildSignDataPayload, executeSignData, unwrapBoc, bocToHash, toFriendlyAddress } from './ton-transaction-utils';
|
|
4
4
|
export { buildJettonTransferPayload, buildTonNativeRequestFromJettonTransfer } from './jetton-transfer';
|
|
5
|
+
export { buildTonCommentPayload, MAX_TON_COMMENT_BYTES } from './text-comment';
|
|
5
6
|
export { TonConnectConnector } from './ton-connect-connector';
|
|
6
7
|
export { WALLET_RESPONSE_TIMEOUT_MS, withWalletResponseTimeout } from './ton-connect-session-restore';
|
|
7
8
|
export { TON_CONNECT_INJECTED_STORAGE_PREFIX, tryRestoreInjectedSession } from './ton-connect-injected-restore';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,eAAe,EACf,SAAS,EACT,SAAS,EACT,iBAAiB,EAClB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,0BAA0B,EAC1B,uCAAuC,EACxC,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EACL,0BAA0B,EAC1B,yBAAyB,EAC1B,MAAM,+BAA+B,CAAA;AACtC,OAAO,EACL,mCAAmC,EACnC,yBAAyB,EAC1B,MAAM,gCAAgC,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,eAAe,EACf,SAAS,EACT,SAAS,EACT,iBAAiB,EAClB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,0BAA0B,EAC1B,uCAAuC,EACxC,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EACL,0BAA0B,EAC1B,yBAAyB,EAC1B,MAAM,+BAA+B,CAAA;AACtC,OAAO,EACL,mCAAmC,EACnC,yBAAyB,EAC1B,MAAM,gCAAgC,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export { NamespacedStorage } from './namespaced-storage';
|
|
|
2
2
|
export { isValidBase64 } from './validation';
|
|
3
3
|
export { buildTonTransactionRequest, buildSignDataPayload, executeSignData, unwrapBoc, bocToHash, toFriendlyAddress } from './ton-transaction-utils';
|
|
4
4
|
export { buildJettonTransferPayload, buildTonNativeRequestFromJettonTransfer } from './jetton-transfer';
|
|
5
|
+
export { buildTonCommentPayload, MAX_TON_COMMENT_BYTES } from './text-comment';
|
|
5
6
|
export { TonConnectConnector } from './ton-connect-connector';
|
|
6
7
|
export { WALLET_RESPONSE_TIMEOUT_MS, withWalletResponseTimeout } from './ton-connect-session-restore';
|
|
7
8
|
export { TON_CONNECT_INJECTED_STORAGE_PREFIX, tryRestoreInjectedSession } from './ton-connect-injected-restore';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,eAAe,EACf,SAAS,EACT,SAAS,EACT,iBAAiB,EAClB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,0BAA0B,EAC1B,uCAAuC,EACxC,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EACL,0BAA0B,EAC1B,yBAAyB,EAC1B,MAAM,+BAA+B,CAAA;AACtC,OAAO,EACL,mCAAmC,EACnC,yBAAyB,EAC1B,MAAM,gCAAgC,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,eAAe,EACf,SAAS,EACT,SAAS,EACT,iBAAiB,EAClB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,0BAA0B,EAC1B,uCAAuC,EACxC,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EACL,0BAA0B,EAC1B,yBAAyB,EAC1B,MAAM,+BAA+B,CAAA;AACtC,OAAO,EACL,mCAAmC,EACnC,yBAAyB,EAC1B,MAAM,gCAAgC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jetton-transfer.d.ts","sourceRoot":"","sources":["../src/jetton-transfer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,wBAAwB,EACzB,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"jetton-transfer.d.ts","sourceRoot":"","sources":["../src/jetton-transfer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,wBAAwB,EACzB,MAAM,wBAAwB,CAAA;AAe/B;;;;;;;;;;GAUG;AACH,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,MAAM,CAAC,CA2EjB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,uCAAuC,CAC3D,MAAM,EAAE,uBAAuB,EAC/B,yBAAyB,EAAE,MAAM,EACjC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,wBAAwB,CAAC,CAQnC"}
|
package/dist/jetton-transfer.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { importTonCore } from './ton-core';
|
|
2
|
+
import { buildTextCommentCell } from './text-comment';
|
|
2
3
|
/**
|
|
3
4
|
* TEP-74 Jetton transfer op code. Identifies the message as a token transfer.
|
|
4
5
|
* This is a protocol-level constant defined in the standard — all Jetton contracts
|
|
@@ -6,8 +7,6 @@ import { importTonCore } from './ton-core';
|
|
|
6
7
|
* @see https://github.com/ton-blockchain/TEPs/blob/master/text/0074-jettons-standard.md
|
|
7
8
|
*/
|
|
8
9
|
const JETTON_TRANSFER_OP = 0x0f8a7ea5;
|
|
9
|
-
/** TEP-74 forward_payload comment op code (0 = text comment). */
|
|
10
|
-
const FORWARD_PAYLOAD_OP_COMMENT = 0;
|
|
11
10
|
/** Max value for a 64-bit unsigned integer (TEP-74 query_id). */
|
|
12
11
|
const MAX_UINT64 = 18446744073709551615n;
|
|
13
12
|
/**
|
|
@@ -22,7 +21,7 @@ const MAX_UINT64 = 18446744073709551615n;
|
|
|
22
21
|
* @returns Base64-encoded BOC of the transfer cell (use as payload in TonNativeTransferRequest)
|
|
23
22
|
*/
|
|
24
23
|
export async function buildJettonTransferPayload(params) {
|
|
25
|
-
const { beginCell, Address } = await importTonCore();
|
|
24
|
+
const { beginCell, Address, comment } = await importTonCore();
|
|
26
25
|
let queryId;
|
|
27
26
|
try {
|
|
28
27
|
queryId = BigInt(params.queryId ?? '0');
|
|
@@ -55,9 +54,21 @@ export async function buildJettonTransferPayload(params) {
|
|
|
55
54
|
if (forwardTonAmount < 0n) {
|
|
56
55
|
throw new Error('forwardTonAmount must be non-negative');
|
|
57
56
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
// An absent or empty comment means "no comment" — the conventional reading of an
|
|
58
|
+
// optional string. Anything else is a comment the caller means to deliver, and
|
|
59
|
+
// `buildTextCommentCell` is the authority on whether it can be (a whitespace-only
|
|
60
|
+
// memo attributes nothing, so it is rejected rather than sent).
|
|
61
|
+
const forwardComment = params.forwardComment != null && params.forwardComment !== ''
|
|
62
|
+
? params.forwardComment
|
|
63
|
+
: undefined;
|
|
64
|
+
// TEP-74 only delivers forward_payload alongside forwarded TON: with zero
|
|
65
|
+
// forwardTonAmount the recipient's jetton wallet is never notified and the
|
|
66
|
+
// comment is discarded on-chain. Silently dropping it is the exact failure this
|
|
67
|
+
// encoder exists to prevent, so refuse the combination instead.
|
|
68
|
+
if (forwardComment !== undefined && forwardTonAmount === 0n) {
|
|
69
|
+
throw new Error('forwardComment requires a non-zero forwardTonAmount; with no TON forwarded the ' +
|
|
70
|
+
'comment is not delivered to the recipient');
|
|
71
|
+
}
|
|
61
72
|
const body = beginCell()
|
|
62
73
|
.storeUint(JETTON_TRANSFER_OP, 32)
|
|
63
74
|
.storeUint(queryId, 64)
|
|
@@ -66,13 +77,11 @@ export async function buildJettonTransferPayload(params) {
|
|
|
66
77
|
.storeAddress(responseDestination)
|
|
67
78
|
.storeBit(0) // no custom_payload
|
|
68
79
|
.storeCoins(forwardTonAmount);
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
.storeStringTail(params.forwardComment)
|
|
73
|
-
.endCell();
|
|
80
|
+
if (forwardComment !== undefined) {
|
|
81
|
+
// Same text-comment encoding as a native transfer's comment payload, so the
|
|
82
|
+
// op code and the single-cell bound have one implementation between them.
|
|
74
83
|
body.storeBit(1);
|
|
75
|
-
body.storeRef(
|
|
84
|
+
body.storeRef(buildTextCommentCell(comment, forwardComment));
|
|
76
85
|
}
|
|
77
86
|
else {
|
|
78
87
|
body.storeBit(0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jetton-transfer.js","sourceRoot":"","sources":["../src/jetton-transfer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"jetton-transfer.js","sourceRoot":"","sources":["../src/jetton-transfer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAA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A;IAClB,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;IAC3B,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;AACxC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,uCAAuC,CAC3D,MAA+B,EAC/B,yBAAiC,EACjC,WAAmB,EACnB,WAAmB;IAEnB,MAAM,OAAO,GAAG,MAAM,0BAA0B,CAAC,MAAM,CAAC,CAAA;IACxD,OAAO;QACL,EAAE,EAAE,yBAAyB;QAC7B,MAAM,EAAE,WAAW;QACnB,IAAI,EAAE,WAAW;QACjB,OAAO;KACR,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Cell } from '@ton/core';
|
|
2
|
+
/** `@ton/core`'s canonical text-comment encoder. */
|
|
3
|
+
type CommentEncoder = typeof import('@ton/core').comment;
|
|
4
|
+
/**
|
|
5
|
+
* Comment bytes that fit in one cell alongside the op code.
|
|
6
|
+
*
|
|
7
|
+
* Exported so a caller can reject an unusable memo up front. The encoder throws
|
|
8
|
+
* on one too, but by then the caller is usually mid-transfer — Link reaches it
|
|
9
|
+
* only after pre-registering and emitting `transferInitiated`, which would leave
|
|
10
|
+
* a registered transfer that never gets signed.
|
|
11
|
+
*
|
|
12
|
+
* A cell holds 1023 bits; the 32-bit op leaves 991, or 123 whole bytes.
|
|
13
|
+
* `@ton/core` would silently chain the remainder into ref cells (TON's "snake"
|
|
14
|
+
* string layout). That is valid on-chain, but consumers vary in how faithfully
|
|
15
|
+
* they reassemble it, and a deposit memo that the receiving venue reads back
|
|
16
|
+
* truncated is worse than one we refused to send. So a comment is held to a
|
|
17
|
+
* single cell and anything longer is rejected.
|
|
18
|
+
*/
|
|
19
|
+
export declare const MAX_TON_COMMENT_BYTES = 123;
|
|
20
|
+
/**
|
|
21
|
+
* Build the text-comment cell for a message body.
|
|
22
|
+
*
|
|
23
|
+
* The encoding itself is `@ton/core`'s `comment()` — 32 zero bits followed by
|
|
24
|
+
* the UTF-8 string. Those leading bits are what makes the body unambiguously
|
|
25
|
+
* text: without them its first four bytes are read as an op code, so a comment
|
|
26
|
+
* colliding with a real op (a jetton transfer, an NFT transfer) would be
|
|
27
|
+
* executed as a command by the receiving contract instead of displayed. This
|
|
28
|
+
* wrapper exists for the length and blankness bounds, not to reimplement the
|
|
29
|
+
* layout — Tonkeeper encodes its own comments through the same function.
|
|
30
|
+
*
|
|
31
|
+
* Shared by the native-transfer comment payload and the TEP-74 jetton
|
|
32
|
+
* `forward_payload` so both carry identical bounds.
|
|
33
|
+
*
|
|
34
|
+
* @param encodeComment - `comment` from {@link importTonCore}; injected so
|
|
35
|
+
* callers that already hold the module don't import it twice.
|
|
36
|
+
* @throws if the comment is blank or exceeds {@link MAX_TON_COMMENT_BYTES}.
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildTextCommentCell(encodeComment: CommentEncoder, text: string): Cell;
|
|
39
|
+
/**
|
|
40
|
+
* Encode a text comment as a base64 BOC, ready to pass as the `payload` of a
|
|
41
|
+
* `TonNativeTransferRequest`.
|
|
42
|
+
*
|
|
43
|
+
* TON has no memo field. Exchanges that hand out a shared deposit address plus
|
|
44
|
+
* a per-user memo expect that memo as the message's comment, so a native
|
|
45
|
+
* transfer to such an address must carry this payload or the deposit arrives
|
|
46
|
+
* unattributable — confirmed on-chain, but credited to nobody.
|
|
47
|
+
*
|
|
48
|
+
* Callers must not hand-roll the BOC: `payload` is an opaque base64 cell, and
|
|
49
|
+
* `@tonconnect/sdk` rejects anything that isn't one — at send time, after the
|
|
50
|
+
* user has already committed to the transfer.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* const payload = await buildTonCommentPayload('846504056')
|
|
54
|
+
* await sendTransaction({ from, to, amount, payload })
|
|
55
|
+
*
|
|
56
|
+
* @throws if the comment is blank or exceeds {@link MAX_TON_COMMENT_BYTES}.
|
|
57
|
+
*/
|
|
58
|
+
export declare function buildTonCommentPayload(text: string): Promise<string>;
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=text-comment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-comment.d.ts","sourceRoot":"","sources":["../src/text-comment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAGrC,oDAAoD;AACpD,KAAK,cAAc,GAAG,cAAc,WAAW,EAAE,OAAO,CAAA;AAExD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qBAAqB,MAAM,CAAA;AAuBxC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CAClC,aAAa,EAAE,cAAc,EAC7B,IAAI,EAAE,MAAM,GACX,IAAI,CAGN;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAG1E"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { importTonCore } from './ton-core';
|
|
2
|
+
/**
|
|
3
|
+
* Comment bytes that fit in one cell alongside the op code.
|
|
4
|
+
*
|
|
5
|
+
* Exported so a caller can reject an unusable memo up front. The encoder throws
|
|
6
|
+
* on one too, but by then the caller is usually mid-transfer — Link reaches it
|
|
7
|
+
* only after pre-registering and emitting `transferInitiated`, which would leave
|
|
8
|
+
* a registered transfer that never gets signed.
|
|
9
|
+
*
|
|
10
|
+
* A cell holds 1023 bits; the 32-bit op leaves 991, or 123 whole bytes.
|
|
11
|
+
* `@ton/core` would silently chain the remainder into ref cells (TON's "snake"
|
|
12
|
+
* string layout). That is valid on-chain, but consumers vary in how faithfully
|
|
13
|
+
* they reassemble it, and a deposit memo that the receiving venue reads back
|
|
14
|
+
* truncated is worse than one we refused to send. So a comment is held to a
|
|
15
|
+
* single cell and anything longer is rejected.
|
|
16
|
+
*/
|
|
17
|
+
export const MAX_TON_COMMENT_BYTES = 123;
|
|
18
|
+
/** Stateless across `encode` calls, so one instance serves every comment. */
|
|
19
|
+
const utf8 = new TextEncoder();
|
|
20
|
+
/**
|
|
21
|
+
* Reject comments that cannot serve as an attribution key before encoding them.
|
|
22
|
+
*
|
|
23
|
+
* @throws if the comment is blank or exceeds {@link MAX_TON_COMMENT_BYTES}.
|
|
24
|
+
*/
|
|
25
|
+
function assertEncodableComment(text) {
|
|
26
|
+
if (typeof text !== 'string' || text.trim().length === 0) {
|
|
27
|
+
throw new Error('TON comment must be a non-empty, non-blank string');
|
|
28
|
+
}
|
|
29
|
+
const byteLength = utf8.encode(text).length;
|
|
30
|
+
if (byteLength > MAX_TON_COMMENT_BYTES) {
|
|
31
|
+
throw new Error(`TON comment is ${byteLength} bytes; the maximum that fits a single cell is ${MAX_TON_COMMENT_BYTES}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Build the text-comment cell for a message body.
|
|
36
|
+
*
|
|
37
|
+
* The encoding itself is `@ton/core`'s `comment()` — 32 zero bits followed by
|
|
38
|
+
* the UTF-8 string. Those leading bits are what makes the body unambiguously
|
|
39
|
+
* text: without them its first four bytes are read as an op code, so a comment
|
|
40
|
+
* colliding with a real op (a jetton transfer, an NFT transfer) would be
|
|
41
|
+
* executed as a command by the receiving contract instead of displayed. This
|
|
42
|
+
* wrapper exists for the length and blankness bounds, not to reimplement the
|
|
43
|
+
* layout — Tonkeeper encodes its own comments through the same function.
|
|
44
|
+
*
|
|
45
|
+
* Shared by the native-transfer comment payload and the TEP-74 jetton
|
|
46
|
+
* `forward_payload` so both carry identical bounds.
|
|
47
|
+
*
|
|
48
|
+
* @param encodeComment - `comment` from {@link importTonCore}; injected so
|
|
49
|
+
* callers that already hold the module don't import it twice.
|
|
50
|
+
* @throws if the comment is blank or exceeds {@link MAX_TON_COMMENT_BYTES}.
|
|
51
|
+
*/
|
|
52
|
+
export function buildTextCommentCell(encodeComment, text) {
|
|
53
|
+
assertEncodableComment(text);
|
|
54
|
+
return encodeComment(text);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Encode a text comment as a base64 BOC, ready to pass as the `payload` of a
|
|
58
|
+
* `TonNativeTransferRequest`.
|
|
59
|
+
*
|
|
60
|
+
* TON has no memo field. Exchanges that hand out a shared deposit address plus
|
|
61
|
+
* a per-user memo expect that memo as the message's comment, so a native
|
|
62
|
+
* transfer to such an address must carry this payload or the deposit arrives
|
|
63
|
+
* unattributable — confirmed on-chain, but credited to nobody.
|
|
64
|
+
*
|
|
65
|
+
* Callers must not hand-roll the BOC: `payload` is an opaque base64 cell, and
|
|
66
|
+
* `@tonconnect/sdk` rejects anything that isn't one — at send time, after the
|
|
67
|
+
* user has already committed to the transfer.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* const payload = await buildTonCommentPayload('846504056')
|
|
71
|
+
* await sendTransaction({ from, to, amount, payload })
|
|
72
|
+
*
|
|
73
|
+
* @throws if the comment is blank or exceeds {@link MAX_TON_COMMENT_BYTES}.
|
|
74
|
+
*/
|
|
75
|
+
export async function buildTonCommentPayload(text) {
|
|
76
|
+
const { comment } = await importTonCore();
|
|
77
|
+
return buildTextCommentCell(comment, text).toBoc().toString('base64');
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=text-comment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-comment.js","sourceRoot":"","sources":["../src/text-comment.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAK1C;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAA;AAExC,6EAA6E;AAC7E,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAA;AAE9B;;;;GAIG;AACH,SAAS,sBAAsB,CAAC,IAAY;IAC1C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI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C;CACF"}
|
|
@@ -28,12 +28,14 @@ export declare function buildTonTransactionMessage(request: TonNativeTransferReq
|
|
|
28
28
|
* The SDK expects `from` in raw format; the UI's user-friendly address (UQ...) is a fallback only.
|
|
29
29
|
*
|
|
30
30
|
* `validUntil` defaults to now + 5 min (TX_EXPIRY_SECONDS). TON transactions require an expiry.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
*
|
|
32
|
+
* The request carries exactly `validUntil` / `network` / `from` / `messages`.
|
|
33
|
+
* `@tonconnect/sdk` validates the shape before the wallet sees it and throws on
|
|
34
|
+
* any other top-level key, so nothing else may be added here.
|
|
35
|
+
*
|
|
36
|
+
* @throws if `request.sendMode` is set — see {@link TonNativeTransferRequest.sendMode}.
|
|
33
37
|
*/
|
|
34
|
-
export declare function buildTonTransactionRequest(request: TonNativeTransferRequest, senderRawAddress?: string): SendTransactionRequest
|
|
35
|
-
sendMode?: number;
|
|
36
|
-
};
|
|
38
|
+
export declare function buildTonTransactionRequest(request: TonNativeTransferRequest, senderRawAddress?: string): SendTransactionRequest;
|
|
37
39
|
export declare function buildSignDataPayload(message: string, override?: TonSignDataPayload): TonSignDataPayload;
|
|
38
40
|
/**
|
|
39
41
|
* Execute signData on the SDK, normalizing errors for wallets that don't support it.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ton-transaction-utils.d.ts","sourceRoot":"","sources":["../src/ton-transaction-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,kBAAkB,EAClB,aAAa,EACd,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AAQ7D;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,CAAC,mBAAmB,EAAE,MAAM,KAAK,MAAM,GACjD,MAAM,CAKR;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,OAA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AC,MAAM,CAAC,CAI5D"}
|
|
@@ -45,20 +45,29 @@ export function buildTonTransactionMessage(request) {
|
|
|
45
45
|
* The SDK expects `from` in raw format; the UI's user-friendly address (UQ...) is a fallback only.
|
|
46
46
|
*
|
|
47
47
|
* `validUntil` defaults to now + 5 min (TX_EXPIRY_SECONDS). TON transactions require an expiry.
|
|
48
|
-
*
|
|
49
|
-
*
|
|
48
|
+
*
|
|
49
|
+
* The request carries exactly `validUntil` / `network` / `from` / `messages`.
|
|
50
|
+
* `@tonconnect/sdk` validates the shape before the wallet sees it and throws on
|
|
51
|
+
* any other top-level key, so nothing else may be added here.
|
|
52
|
+
*
|
|
53
|
+
* @throws if `request.sendMode` is set — see {@link TonNativeTransferRequest.sendMode}.
|
|
50
54
|
*/
|
|
51
55
|
export function buildTonTransactionRequest(request, senderRawAddress) {
|
|
56
|
+
// TON Connect has no request-level send mode: the wallet picks one (Tonkeeper
|
|
57
|
+
// uses pay-gas-separately + ignore-errors). Forwarding `sendMode` produced a
|
|
58
|
+
// request the SDK rejected with "Request contains extra properties" — a
|
|
59
|
+
// failure that only surfaced at send time. Refuse it here, with the reason.
|
|
60
|
+
if (request.sendMode !== undefined) {
|
|
61
|
+
throw new Error('TON Connect does not accept a request-level sendMode; the wallet chooses the ' +
|
|
62
|
+
'message mode. Remove sendMode — to send an entire balance, compute the amount instead.');
|
|
63
|
+
}
|
|
52
64
|
const message = buildTonTransactionMessage(request);
|
|
53
|
-
|
|
65
|
+
return {
|
|
54
66
|
validUntil: request.validUntil ?? Math.floor(Date.now() / 1000) + TX_EXPIRY_SECONDS,
|
|
55
67
|
network: TON_MAINNET_CHAIN_ID,
|
|
56
68
|
from: senderRawAddress ?? request.from,
|
|
57
69
|
messages: [message]
|
|
58
70
|
};
|
|
59
|
-
if (request.sendMode !== undefined)
|
|
60
|
-
txRequest.sendMode = request.sendMode;
|
|
61
|
-
return txRequest;
|
|
62
71
|
}
|
|
63
72
|
export function buildSignDataPayload(message, override) {
|
|
64
73
|
return override ?? { type: 'text', text: message };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ton-transaction-utils.js","sourceRoot":"","sources":["../src/ton-transaction-utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE1C,uGAAuG;AACvG,MAAM,iBAAiB,GAAG,GAAG,CAAA;AAE7B;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAAkB,EAClB,SAAkD;IAElD,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7B,OAAO,SAAS,CAAC,UAAU,CAAC,CAAA;IAC9B,CAAC;IACD,OAAO,UAAU,CAAA;AACnB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B,CAAC,OAAiC;IAC1E,IAAI,OAAO,CAAC,OAAO,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CACb,+EAA+E;YAC7E,4CAA4C,CAC/C,CAAA;IACH,CAAC;IAED,IAAI,OAAO,CAAC,SAAS,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAC3D,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;IAC5D,CAAC;IAED,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,EAAE;QACnB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;QACpD,GAAG,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;KAC3D,CAAA;AACH,CAAC;AAED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AAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;YAC5D,MAAM,IAAI,KAAK,CACb,gEAAgE;gBAC9D,qDAAqD,CACxD,CAAA;QACH,CAAC;QACD,MAAM,KAAK,CAAA;IACb,CAAC;IAED,OAAO;QACL,IAAI,EAAE,KAAK;QACX,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,OAAO;KACR,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CACvB,MAAmD;IAEnD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAA;IAC7D,CAAC;IACD,MAAM,GAAG,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAA;IAC5D,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IACjD,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAW;IACzC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,aAAa,EAAE,CAAA;IACtC,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;IACjC,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AACpC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshconnect/uwc-ton-connector",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0-snapshot.2007cea",
|
|
4
4
|
"description": "TON Connect connector for Universal Wallet Connector — mobile QR/URI wallet connections",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@ton/core": "^0.63.1",
|
|
20
20
|
"@tonconnect/sdk": "^3.0.5",
|
|
21
|
-
"@meshconnect/uwc-constants": "0.7.
|
|
22
|
-
"@meshconnect/uwc-types": "0.27.
|
|
21
|
+
"@meshconnect/uwc-constants": "0.7.6-snapshot.2007cea",
|
|
22
|
+
"@meshconnect/uwc-types": "0.27.1-snapshot.2007cea"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"typescript": "^5.9.3"
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export {
|
|
|
12
12
|
buildJettonTransferPayload,
|
|
13
13
|
buildTonNativeRequestFromJettonTransfer
|
|
14
14
|
} from './jetton-transfer'
|
|
15
|
+
export { buildTonCommentPayload, MAX_TON_COMMENT_BYTES } from './text-comment'
|
|
15
16
|
export { TonConnectConnector } from './ton-connect-connector'
|
|
16
17
|
export {
|
|
17
18
|
WALLET_RESPONSE_TIMEOUT_MS,
|
|
@@ -60,6 +60,55 @@ describe('buildJettonTransferPayload', () => {
|
|
|
60
60
|
expect(comment).toBe('for coffee')
|
|
61
61
|
})
|
|
62
62
|
|
|
63
|
+
it('refuses a forward comment with no forwarded TON rather than dropping it', async () => {
|
|
64
|
+
// TEP-74 only delivers forward_payload alongside forwarded TON, so this
|
|
65
|
+
// combination would encode a comment the recipient never receives.
|
|
66
|
+
await expect(
|
|
67
|
+
buildJettonTransferPayload({
|
|
68
|
+
destination: DEST,
|
|
69
|
+
amount: '500000',
|
|
70
|
+
responseDestination: RESPONSE_DEST,
|
|
71
|
+
forwardComment: 'invoice-42'
|
|
72
|
+
})
|
|
73
|
+
).rejects.toThrow(/requires a non-zero forwardTonAmount/)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it.each([
|
|
77
|
+
['undefined', undefined],
|
|
78
|
+
['empty string', '']
|
|
79
|
+
])(
|
|
80
|
+
'treats a %s forward comment as absent, with no forward ref',
|
|
81
|
+
async (_, forwardComment) => {
|
|
82
|
+
const payload = await buildJettonTransferPayload({
|
|
83
|
+
destination: DEST,
|
|
84
|
+
amount: '500000',
|
|
85
|
+
responseDestination: RESPONSE_DEST,
|
|
86
|
+
forwardComment
|
|
87
|
+
})
|
|
88
|
+
const slice = Cell.fromBase64(payload).beginParse()
|
|
89
|
+
slice.loadUint(32) // op
|
|
90
|
+
slice.loadUintBig(64) // query_id
|
|
91
|
+
slice.loadCoins() // amount
|
|
92
|
+
slice.loadAddress() // destination
|
|
93
|
+
slice.loadAddress() // response_destination
|
|
94
|
+
slice.loadBit() // custom_payload
|
|
95
|
+
slice.loadCoins() // forward_ton_amount
|
|
96
|
+
expect(slice.loadBit()).toBe(false) // no forward_payload ref
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
it('rejects a whitespace-only forward comment — it attributes nothing', async () => {
|
|
101
|
+
await expect(
|
|
102
|
+
buildJettonTransferPayload({
|
|
103
|
+
destination: DEST,
|
|
104
|
+
amount: '500000',
|
|
105
|
+
responseDestination: RESPONSE_DEST,
|
|
106
|
+
forwardTonAmount: '20000000',
|
|
107
|
+
forwardComment: ' '
|
|
108
|
+
})
|
|
109
|
+
).rejects.toThrow(/non-empty, non-blank/)
|
|
110
|
+
})
|
|
111
|
+
|
|
63
112
|
it('uses custom queryId when provided', async () => {
|
|
64
113
|
const params: TonJettonTransferParams = {
|
|
65
114
|
destination: DEST,
|
package/src/jetton-transfer.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
TonNativeTransferRequest
|
|
4
4
|
} from '@meshconnect/uwc-types'
|
|
5
5
|
import { importTonCore } from './ton-core'
|
|
6
|
+
import { buildTextCommentCell } from './text-comment'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* TEP-74 Jetton transfer op code. Identifies the message as a token transfer.
|
|
@@ -12,9 +13,6 @@ import { importTonCore } from './ton-core'
|
|
|
12
13
|
*/
|
|
13
14
|
const JETTON_TRANSFER_OP = 0x0f8a7ea5
|
|
14
15
|
|
|
15
|
-
/** TEP-74 forward_payload comment op code (0 = text comment). */
|
|
16
|
-
const FORWARD_PAYLOAD_OP_COMMENT = 0
|
|
17
|
-
|
|
18
16
|
/** Max value for a 64-bit unsigned integer (TEP-74 query_id). */
|
|
19
17
|
const MAX_UINT64 = 18446744073709551615n
|
|
20
18
|
|
|
@@ -32,7 +30,7 @@ const MAX_UINT64 = 18446744073709551615n
|
|
|
32
30
|
export async function buildJettonTransferPayload(
|
|
33
31
|
params: TonJettonTransferParams
|
|
34
32
|
): Promise<string> {
|
|
35
|
-
const { beginCell, Address } = await importTonCore()
|
|
33
|
+
const { beginCell, Address, comment } = await importTonCore()
|
|
36
34
|
|
|
37
35
|
let queryId: bigint
|
|
38
36
|
try {
|
|
@@ -66,10 +64,25 @@ export async function buildJettonTransferPayload(
|
|
|
66
64
|
if (forwardTonAmount < 0n) {
|
|
67
65
|
throw new Error('forwardTonAmount must be non-negative')
|
|
68
66
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
// An absent or empty comment means "no comment" — the conventional reading of an
|
|
68
|
+
// optional string. Anything else is a comment the caller means to deliver, and
|
|
69
|
+
// `buildTextCommentCell` is the authority on whether it can be (a whitespace-only
|
|
70
|
+
// memo attributes nothing, so it is rejected rather than sent).
|
|
71
|
+
const forwardComment =
|
|
72
|
+
params.forwardComment != null && params.forwardComment !== ''
|
|
73
|
+
? params.forwardComment
|
|
74
|
+
: undefined
|
|
75
|
+
|
|
76
|
+
// TEP-74 only delivers forward_payload alongside forwarded TON: with zero
|
|
77
|
+
// forwardTonAmount the recipient's jetton wallet is never notified and the
|
|
78
|
+
// comment is discarded on-chain. Silently dropping it is the exact failure this
|
|
79
|
+
// encoder exists to prevent, so refuse the combination instead.
|
|
80
|
+
if (forwardComment !== undefined && forwardTonAmount === 0n) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
'forwardComment requires a non-zero forwardTonAmount; with no TON forwarded the ' +
|
|
83
|
+
'comment is not delivered to the recipient'
|
|
84
|
+
)
|
|
85
|
+
}
|
|
73
86
|
|
|
74
87
|
const body = beginCell()
|
|
75
88
|
.storeUint(JETTON_TRANSFER_OP, 32)
|
|
@@ -80,13 +93,11 @@ export async function buildJettonTransferPayload(
|
|
|
80
93
|
.storeBit(0) // no custom_payload
|
|
81
94
|
.storeCoins(forwardTonAmount)
|
|
82
95
|
|
|
83
|
-
if (
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
.storeStringTail(params.forwardComment as string)
|
|
87
|
-
.endCell()
|
|
96
|
+
if (forwardComment !== undefined) {
|
|
97
|
+
// Same text-comment encoding as a native transfer's comment payload, so the
|
|
98
|
+
// op code and the single-cell bound have one implementation between them.
|
|
88
99
|
body.storeBit(1)
|
|
89
|
-
body.storeRef(
|
|
100
|
+
body.storeRef(buildTextCommentCell(comment, forwardComment))
|
|
90
101
|
} else {
|
|
91
102
|
body.storeBit(0)
|
|
92
103
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { Cell } from '@ton/core'
|
|
3
|
+
import { buildTonCommentPayload, MAX_TON_COMMENT_BYTES } from './text-comment'
|
|
4
|
+
import { buildTonTransactionMessage } from './ton-transaction-utils'
|
|
5
|
+
import { isValidBase64 } from './validation'
|
|
6
|
+
|
|
7
|
+
/** Decode a base64 BOC the way a wallet or explorer would, via @ton/core. */
|
|
8
|
+
function decode(payload: string) {
|
|
9
|
+
const slice = Cell.fromBase64(payload).beginParse()
|
|
10
|
+
return { op: slice.loadUint(32), comment: slice.loadStringTail() }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe('buildTonCommentPayload', () => {
|
|
14
|
+
it('encodes a deposit memo as an op-0 text comment', async () => {
|
|
15
|
+
const payload = await buildTonCommentPayload('846504056')
|
|
16
|
+
expect(decode(payload)).toEqual({ op: 0, comment: '846504056' })
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('encodes a hex-style memo', async () => {
|
|
20
|
+
const payload = await buildTonCommentPayload('9FA1703C4278A5269762')
|
|
21
|
+
expect(decode(payload).comment).toBe('9FA1703C4278A5269762')
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('round-trips multi-byte UTF-8 without mangling', async () => {
|
|
25
|
+
const payload = await buildTonCommentPayload('メモ-café-😀')
|
|
26
|
+
expect(decode(payload).comment).toBe('メモ-café-😀')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('preserves surrounding whitespace rather than silently trimming it', async () => {
|
|
30
|
+
const payload = await buildTonCommentPayload(' 42 ')
|
|
31
|
+
expect(decode(payload).comment).toBe(' 42 ')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('produces base64 that survives the payload guard', async () => {
|
|
35
|
+
const payload = await buildTonCommentPayload('846504056')
|
|
36
|
+
expect(isValidBase64(payload)).toBe(true)
|
|
37
|
+
expect(
|
|
38
|
+
buildTonTransactionMessage({
|
|
39
|
+
from: 'UQDmiMK-9hmTn5b8FKuh-ovRVAdx4u-TXuwInN9yGIuhcTiP',
|
|
40
|
+
to: 'UQD0BRQt-QdIEbsjuRsMqzDlBkUAEfQixShDECoKEOXRc4eR',
|
|
41
|
+
amount: '100900900',
|
|
42
|
+
payload
|
|
43
|
+
})
|
|
44
|
+
).toMatchObject({ payload })
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('keeps the comment in a single cell at the documented maximum', async () => {
|
|
48
|
+
const payload = await buildTonCommentPayload(
|
|
49
|
+
'x'.repeat(MAX_TON_COMMENT_BYTES)
|
|
50
|
+
)
|
|
51
|
+
const cell = Cell.fromBase64(payload)
|
|
52
|
+
expect(cell.refs).toHaveLength(0)
|
|
53
|
+
expect(decode(payload).comment).toHaveLength(MAX_TON_COMMENT_BYTES)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('rejects a comment one byte past the single-cell maximum', async () => {
|
|
57
|
+
await expect(
|
|
58
|
+
buildTonCommentPayload('x'.repeat(MAX_TON_COMMENT_BYTES + 1))
|
|
59
|
+
).rejects.toThrow(/124 bytes/)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('measures the limit in bytes, not characters', async () => {
|
|
63
|
+
// 62 two-byte characters = 124 bytes, but only 62 characters.
|
|
64
|
+
await expect(buildTonCommentPayload('é'.repeat(62))).rejects.toThrow(
|
|
65
|
+
/124 bytes/
|
|
66
|
+
)
|
|
67
|
+
await expect(buildTonCommentPayload('é'.repeat(61))).resolves.toBeTypeOf(
|
|
68
|
+
'string'
|
|
69
|
+
)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it.each([
|
|
73
|
+
['empty', ''],
|
|
74
|
+
['spaces', ' '],
|
|
75
|
+
['tab and newline', '\t\n']
|
|
76
|
+
])(
|
|
77
|
+
'rejects a %s comment — a blank memo attributes nothing',
|
|
78
|
+
async (_, value) => {
|
|
79
|
+
await expect(buildTonCommentPayload(value)).rejects.toThrow(
|
|
80
|
+
/non-empty, non-blank/
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
// @tonconnect/sdk validates every message payload before the wallet sees it
|
|
86
|
+
// (`validateSendTransactionRequest` → `isValidBoc`) and throws a TonConnectError
|
|
87
|
+
// when it fails. Its check is a standard-base64 charset plus a literal 'te6cc'
|
|
88
|
+
// prefix — the base64 of a BOC's magic bytes. Encoding the cell any other way
|
|
89
|
+
// (base64url, hex, a bare string) would be refused at send time, so the shape
|
|
90
|
+
// is pinned here rather than discovered on a real transfer.
|
|
91
|
+
describe('@tonconnect/sdk payload validation', () => {
|
|
92
|
+
const SDK_BASE64 =
|
|
93
|
+
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/
|
|
94
|
+
|
|
95
|
+
it.each([
|
|
96
|
+
['a numeric memo', '846504056'],
|
|
97
|
+
['a hex-style memo', '9FA1703C4278A5269762'],
|
|
98
|
+
['multi-byte UTF-8', 'メモ-café-😀'],
|
|
99
|
+
['a maximum-length comment', 'x'.repeat(MAX_TON_COMMENT_BYTES)]
|
|
100
|
+
])('%s serializes to a BOC the SDK accepts', async (_, text) => {
|
|
101
|
+
const payload = await buildTonCommentPayload(text)
|
|
102
|
+
expect(payload.startsWith('te6cc')).toBe(true)
|
|
103
|
+
expect(SDK_BASE64.test(payload)).toBe(true)
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('never emits a body that could be read as another op code', async () => {
|
|
108
|
+
// A comment whose text is itself a jetton-transfer op code must still land
|
|
109
|
+
// as text: the 32 zero bits in front are what makes that unambiguous.
|
|
110
|
+
const payload = await buildTonCommentPayload('0f8a7ea5')
|
|
111
|
+
expect(decode(payload)).toEqual({ op: 0, comment: '0f8a7ea5' })
|
|
112
|
+
})
|
|
113
|
+
})
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Cell } from '@ton/core'
|
|
2
|
+
import { importTonCore } from './ton-core'
|
|
3
|
+
|
|
4
|
+
/** `@ton/core`'s canonical text-comment encoder. */
|
|
5
|
+
type CommentEncoder = typeof import('@ton/core').comment
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Comment bytes that fit in one cell alongside the op code.
|
|
9
|
+
*
|
|
10
|
+
* Exported so a caller can reject an unusable memo up front. The encoder throws
|
|
11
|
+
* on one too, but by then the caller is usually mid-transfer — Link reaches it
|
|
12
|
+
* only after pre-registering and emitting `transferInitiated`, which would leave
|
|
13
|
+
* a registered transfer that never gets signed.
|
|
14
|
+
*
|
|
15
|
+
* A cell holds 1023 bits; the 32-bit op leaves 991, or 123 whole bytes.
|
|
16
|
+
* `@ton/core` would silently chain the remainder into ref cells (TON's "snake"
|
|
17
|
+
* string layout). That is valid on-chain, but consumers vary in how faithfully
|
|
18
|
+
* they reassemble it, and a deposit memo that the receiving venue reads back
|
|
19
|
+
* truncated is worse than one we refused to send. So a comment is held to a
|
|
20
|
+
* single cell and anything longer is rejected.
|
|
21
|
+
*/
|
|
22
|
+
export const MAX_TON_COMMENT_BYTES = 123
|
|
23
|
+
|
|
24
|
+
/** Stateless across `encode` calls, so one instance serves every comment. */
|
|
25
|
+
const utf8 = new TextEncoder()
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Reject comments that cannot serve as an attribution key before encoding them.
|
|
29
|
+
*
|
|
30
|
+
* @throws if the comment is blank or exceeds {@link MAX_TON_COMMENT_BYTES}.
|
|
31
|
+
*/
|
|
32
|
+
function assertEncodableComment(text: string): void {
|
|
33
|
+
if (typeof text !== 'string' || text.trim().length === 0) {
|
|
34
|
+
throw new Error('TON comment must be a non-empty, non-blank string')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const byteLength = utf8.encode(text).length
|
|
38
|
+
if (byteLength > MAX_TON_COMMENT_BYTES) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`TON comment is ${byteLength} bytes; the maximum that fits a single cell is ${MAX_TON_COMMENT_BYTES}`
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Build the text-comment cell for a message body.
|
|
47
|
+
*
|
|
48
|
+
* The encoding itself is `@ton/core`'s `comment()` — 32 zero bits followed by
|
|
49
|
+
* the UTF-8 string. Those leading bits are what makes the body unambiguously
|
|
50
|
+
* text: without them its first four bytes are read as an op code, so a comment
|
|
51
|
+
* colliding with a real op (a jetton transfer, an NFT transfer) would be
|
|
52
|
+
* executed as a command by the receiving contract instead of displayed. This
|
|
53
|
+
* wrapper exists for the length and blankness bounds, not to reimplement the
|
|
54
|
+
* layout — Tonkeeper encodes its own comments through the same function.
|
|
55
|
+
*
|
|
56
|
+
* Shared by the native-transfer comment payload and the TEP-74 jetton
|
|
57
|
+
* `forward_payload` so both carry identical bounds.
|
|
58
|
+
*
|
|
59
|
+
* @param encodeComment - `comment` from {@link importTonCore}; injected so
|
|
60
|
+
* callers that already hold the module don't import it twice.
|
|
61
|
+
* @throws if the comment is blank or exceeds {@link MAX_TON_COMMENT_BYTES}.
|
|
62
|
+
*/
|
|
63
|
+
export function buildTextCommentCell(
|
|
64
|
+
encodeComment: CommentEncoder,
|
|
65
|
+
text: string
|
|
66
|
+
): Cell {
|
|
67
|
+
assertEncodableComment(text)
|
|
68
|
+
return encodeComment(text)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Encode a text comment as a base64 BOC, ready to pass as the `payload` of a
|
|
73
|
+
* `TonNativeTransferRequest`.
|
|
74
|
+
*
|
|
75
|
+
* TON has no memo field. Exchanges that hand out a shared deposit address plus
|
|
76
|
+
* a per-user memo expect that memo as the message's comment, so a native
|
|
77
|
+
* transfer to such an address must carry this payload or the deposit arrives
|
|
78
|
+
* unattributable — confirmed on-chain, but credited to nobody.
|
|
79
|
+
*
|
|
80
|
+
* Callers must not hand-roll the BOC: `payload` is an opaque base64 cell, and
|
|
81
|
+
* `@tonconnect/sdk` rejects anything that isn't one — at send time, after the
|
|
82
|
+
* user has already committed to the transfer.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* const payload = await buildTonCommentPayload('846504056')
|
|
86
|
+
* await sendTransaction({ from, to, amount, payload })
|
|
87
|
+
*
|
|
88
|
+
* @throws if the comment is blank or exceeds {@link MAX_TON_COMMENT_BYTES}.
|
|
89
|
+
*/
|
|
90
|
+
export async function buildTonCommentPayload(text: string): Promise<string> {
|
|
91
|
+
const { comment } = await importTonCore()
|
|
92
|
+
return buildTextCommentCell(comment, text).toBoc().toString('base64')
|
|
93
|
+
}
|
|
@@ -55,8 +55,7 @@ export class TonConnectConnector implements Connector {
|
|
|
55
55
|
private connectedNetworkId: NetworkId | null = null
|
|
56
56
|
private connectTimeout: ReturnType<typeof setTimeout> | null = null
|
|
57
57
|
private toUserFriendlyAddressFn:
|
|
58
|
-
|
|
59
|
-
| null = null
|
|
58
|
+
((hex: string, testOnly?: boolean) => string) | null = null
|
|
60
59
|
private UserRejectsErrorClass: (new (...args: never[]) => Error) | null = null
|
|
61
60
|
private connectInFlight = false
|
|
62
61
|
private abortPendingConnect: (() => void) | null = null
|
|
@@ -55,19 +55,30 @@ describe('buildTonTransactionRequest', () => {
|
|
|
55
55
|
expect(result.validUntil).toBe(9999999)
|
|
56
56
|
})
|
|
57
57
|
|
|
58
|
-
it('
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
it('refuses a sendMode instead of building a request the SDK will reject', () => {
|
|
59
|
+
// TON Connect has no request-level send mode. Forwarding it added a
|
|
60
|
+
// top-level key outside the allowed set, and @tonconnect/sdk threw
|
|
61
|
+
// "Request contains extra properties" at send time — after the caller had
|
|
62
|
+
// already committed to a transfer. Fail at build time, with the reason.
|
|
63
|
+
expect(() =>
|
|
64
|
+
buildTonTransactionRequest({
|
|
65
|
+
...baseRequest,
|
|
66
|
+
sendMode: 3
|
|
67
|
+
} as TonNativeTransferRequest)
|
|
68
|
+
).toThrow(/does not accept a request-level sendMode/)
|
|
65
69
|
})
|
|
66
70
|
|
|
67
|
-
it('
|
|
71
|
+
it('emits only the top-level keys @tonconnect/sdk allows', () => {
|
|
72
|
+
// Mirrors validateSendTransactionRequest's allowed-keys check. Anything else
|
|
73
|
+
// here is rejected before the wallet is ever asked to sign.
|
|
68
74
|
const result = buildTonTransactionRequest(baseRequest)
|
|
69
75
|
|
|
70
|
-
expect(result).
|
|
76
|
+
expect(Object.keys(result).sort()).toEqual([
|
|
77
|
+
'from',
|
|
78
|
+
'messages',
|
|
79
|
+
'network',
|
|
80
|
+
'validUntil'
|
|
81
|
+
])
|
|
71
82
|
})
|
|
72
83
|
|
|
73
84
|
it('overrides from with senderRawAddress when provided', () => {
|
|
@@ -62,25 +62,37 @@ export function buildTonTransactionMessage(request: TonNativeTransferRequest) {
|
|
|
62
62
|
* The SDK expects `from` in raw format; the UI's user-friendly address (UQ...) is a fallback only.
|
|
63
63
|
*
|
|
64
64
|
* `validUntil` defaults to now + 5 min (TX_EXPIRY_SECONDS). TON transactions require an expiry.
|
|
65
|
-
*
|
|
66
|
-
*
|
|
65
|
+
*
|
|
66
|
+
* The request carries exactly `validUntil` / `network` / `from` / `messages`.
|
|
67
|
+
* `@tonconnect/sdk` validates the shape before the wallet sees it and throws on
|
|
68
|
+
* any other top-level key, so nothing else may be added here.
|
|
69
|
+
*
|
|
70
|
+
* @throws if `request.sendMode` is set — see {@link TonNativeTransferRequest.sendMode}.
|
|
67
71
|
*/
|
|
68
72
|
export function buildTonTransactionRequest(
|
|
69
73
|
request: TonNativeTransferRequest,
|
|
70
74
|
senderRawAddress?: string
|
|
71
|
-
): SendTransactionRequest
|
|
75
|
+
): SendTransactionRequest {
|
|
76
|
+
// TON Connect has no request-level send mode: the wallet picks one (Tonkeeper
|
|
77
|
+
// uses pay-gas-separately + ignore-errors). Forwarding `sendMode` produced a
|
|
78
|
+
// request the SDK rejected with "Request contains extra properties" — a
|
|
79
|
+
// failure that only surfaced at send time. Refuse it here, with the reason.
|
|
80
|
+
if (request.sendMode !== undefined) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
'TON Connect does not accept a request-level sendMode; the wallet chooses the ' +
|
|
83
|
+
'message mode. Remove sendMode — to send an entire balance, compute the amount instead.'
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
72
87
|
const message = buildTonTransactionMessage(request)
|
|
73
88
|
|
|
74
|
-
|
|
89
|
+
return {
|
|
75
90
|
validUntil:
|
|
76
91
|
request.validUntil ?? Math.floor(Date.now() / 1000) + TX_EXPIRY_SECONDS,
|
|
77
92
|
network: TON_MAINNET_CHAIN_ID,
|
|
78
93
|
from: senderRawAddress ?? request.from,
|
|
79
94
|
messages: [message]
|
|
80
95
|
}
|
|
81
|
-
if (request.sendMode !== undefined) txRequest.sendMode = request.sendMode
|
|
82
|
-
|
|
83
|
-
return txRequest
|
|
84
96
|
}
|
|
85
97
|
|
|
86
98
|
export function buildSignDataPayload(
|