@ton/ton 13.7.0 → 13.8.0

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.
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@ton/core");
4
+ const WalletV5Utils_1 = require("./WalletV5Utils");
5
+ const mockMessageRelaxed1 = {
6
+ info: {
7
+ type: 'external-out',
8
+ createdLt: 0n,
9
+ createdAt: 0,
10
+ dest: null,
11
+ src: null
12
+ },
13
+ body: (0, core_1.beginCell)().storeUint(0, 8).endCell(),
14
+ init: null
15
+ };
16
+ const mockData = (0, core_1.beginCell)().storeUint(123, 32).endCell();
17
+ const mockAddress = core_1.Address.parseRaw('0:' + '1'.repeat(64));
18
+ describe('Wallet V5 utils', () => {
19
+ const outActionSetDataTag = 0x1ff8ea0b;
20
+ const outActionAddExtensionTag = 0x1c40db9f;
21
+ const outActionRemoveExtensionTag = 0x5eaef4a4;
22
+ const outActionSendMsgTag = 0x0ec3c86d;
23
+ it('Should serialise set data action', () => {
24
+ const action = (0, WalletV5Utils_1.storeOutActionExtended)({
25
+ type: 'setData',
26
+ newData: mockData
27
+ });
28
+ const actual = (0, core_1.beginCell)().store(action).endCell();
29
+ const expected = (0, core_1.beginCell)()
30
+ .storeUint(outActionSetDataTag, 32)
31
+ .storeRef(mockData)
32
+ .endCell();
33
+ expect(expected.equals(actual)).toBeTruthy();
34
+ });
35
+ it('Should serialise add extension action', () => {
36
+ const action = (0, WalletV5Utils_1.storeOutActionExtended)({
37
+ type: 'addExtension',
38
+ address: mockAddress
39
+ });
40
+ const actual = (0, core_1.beginCell)().store(action).endCell();
41
+ const expected = (0, core_1.beginCell)()
42
+ .storeUint(outActionAddExtensionTag, 32)
43
+ .storeAddress(mockAddress)
44
+ .endCell();
45
+ expect(expected.equals(actual)).toBeTruthy();
46
+ });
47
+ it('Should serialise remove extension action', () => {
48
+ const action = (0, WalletV5Utils_1.storeOutActionExtended)({
49
+ type: 'removeExtension',
50
+ address: mockAddress
51
+ });
52
+ const actual = (0, core_1.beginCell)().store(action).endCell();
53
+ const expected = (0, core_1.beginCell)()
54
+ .storeUint(outActionRemoveExtensionTag, 32)
55
+ .storeAddress(mockAddress)
56
+ .endCell();
57
+ expect(expected.equals(actual)).toBeTruthy();
58
+ });
59
+ it('Should serialise wallet id', () => {
60
+ const walletId = {
61
+ walletVersion: 'v5',
62
+ networkGlobalId: -239,
63
+ workChain: 0,
64
+ subwalletNumber: 0
65
+ };
66
+ const actual = (0, core_1.beginCell)().store((0, WalletV5Utils_1.storeWalletId)(walletId)).endCell();
67
+ const expected = (0, core_1.beginCell)()
68
+ .storeInt(walletId.networkGlobalId, 32)
69
+ .storeInt(walletId.workChain, 8)
70
+ .storeUint(0, 8)
71
+ .storeUint(walletId.subwalletNumber, 32)
72
+ .endCell();
73
+ expect(expected.equals(actual)).toBeTruthy();
74
+ });
75
+ it('Should deserialise wallet id', () => {
76
+ const expected = {
77
+ walletVersion: 'v5',
78
+ networkGlobalId: -239,
79
+ workChain: 0,
80
+ subwalletNumber: 0
81
+ };
82
+ const actual = (0, WalletV5Utils_1.loadWalletId)((0, core_1.beginCell)()
83
+ .storeInt(expected.networkGlobalId, 32)
84
+ .storeInt(expected.workChain, 8)
85
+ .storeUint(0, 8)
86
+ .storeUint(expected.subwalletNumber, 32)
87
+ .endCell().beginParse());
88
+ expect(expected).toEqual(actual);
89
+ });
90
+ it('Should serialise wallet id', () => {
91
+ const walletId = {
92
+ walletVersion: 'v5',
93
+ networkGlobalId: -3,
94
+ workChain: -1,
95
+ subwalletNumber: 1234
96
+ };
97
+ const actual = (0, core_1.beginCell)().store((0, WalletV5Utils_1.storeWalletId)(walletId)).endCell();
98
+ const expected = (0, core_1.beginCell)()
99
+ .storeInt(walletId.networkGlobalId, 32)
100
+ .storeInt(walletId.workChain, 8)
101
+ .storeUint(0, 8)
102
+ .storeUint(walletId.subwalletNumber, 32)
103
+ .endCell();
104
+ expect(expected.equals(actual)).toBeTruthy();
105
+ });
106
+ it('Should deserialise wallet id', () => {
107
+ const expected = {
108
+ walletVersion: 'v5',
109
+ networkGlobalId: -239,
110
+ workChain: -1,
111
+ subwalletNumber: 1
112
+ };
113
+ const actual = (0, WalletV5Utils_1.loadWalletId)((0, core_1.beginCell)()
114
+ .storeInt(expected.networkGlobalId, 32)
115
+ .storeInt(expected.workChain, 8)
116
+ .storeUint(0, 8)
117
+ .storeUint(expected.subwalletNumber, 32)
118
+ .endCell().beginParse());
119
+ expect(expected).toEqual(actual);
120
+ });
121
+ it('Should serialize extended out list', () => {
122
+ const sendMode1 = core_1.SendMode.PAY_GAS_SEPARATELY;
123
+ const actions = [
124
+ {
125
+ type: 'addExtension',
126
+ address: mockAddress
127
+ },
128
+ {
129
+ type: 'sendMsg',
130
+ mode: sendMode1,
131
+ outMsg: mockMessageRelaxed1
132
+ }
133
+ ];
134
+ const actual = (0, core_1.beginCell)().store((0, WalletV5Utils_1.storeOutListExtended)(actions)).endCell();
135
+ const expected = (0, core_1.beginCell)()
136
+ .storeUint(1, 1)
137
+ .store((0, WalletV5Utils_1.storeOutActionExtended)(actions[0]))
138
+ .storeRef((0, core_1.beginCell)()
139
+ .storeUint(0, 1)
140
+ .storeRef((0, core_1.beginCell)()
141
+ .storeRef((0, core_1.beginCell)().endCell())
142
+ .storeUint(outActionSendMsgTag, 32)
143
+ .storeUint(sendMode1, 8)
144
+ .storeRef((0, core_1.beginCell)().store((0, core_1.storeMessageRelaxed)(mockMessageRelaxed1)).endCell())
145
+ .endCell())
146
+ .endCell())
147
+ .endCell();
148
+ expect(actual.equals(expected)).toBeTruthy();
149
+ });
150
+ it('Should deserialize extended out list', () => {
151
+ const sendMode1 = core_1.SendMode.PAY_GAS_SEPARATELY;
152
+ const expected = [
153
+ {
154
+ type: 'addExtension',
155
+ address: mockAddress
156
+ },
157
+ {
158
+ type: 'sendMsg',
159
+ mode: sendMode1,
160
+ outMsg: mockMessageRelaxed1
161
+ }
162
+ ];
163
+ const serialized = (0, core_1.beginCell)()
164
+ .storeUint(1, 1)
165
+ .store((0, WalletV5Utils_1.storeOutActionExtended)(expected[0]))
166
+ .storeRef((0, core_1.beginCell)()
167
+ .storeUint(0, 1)
168
+ .storeRef((0, core_1.beginCell)()
169
+ .storeRef((0, core_1.beginCell)().endCell())
170
+ .storeUint(outActionSendMsgTag, 32)
171
+ .storeUint(sendMode1, 8)
172
+ .storeRef((0, core_1.beginCell)().store((0, core_1.storeMessageRelaxed)(mockMessageRelaxed1)).endCell())
173
+ .endCell())
174
+ .endCell())
175
+ .endCell();
176
+ const actual = (0, WalletV5Utils_1.loadOutListExtended)(serialized.beginParse());
177
+ expect(expected.length).toEqual(actual.length);
178
+ expected.forEach((item1, index) => {
179
+ const item2 = actual[index];
180
+ expect(item1.type).toEqual(item2.type);
181
+ if (item1.type === 'sendMsg' && item2.type === 'sendMsg') {
182
+ expect(item1.mode).toEqual(item2.mode);
183
+ expect(item1.outMsg.body.equals(item2.outMsg.body)).toBeTruthy();
184
+ expect(item1.outMsg.info).toEqual(item2.outMsg.info);
185
+ expect(item1.outMsg.init).toEqual(item2.outMsg.init);
186
+ }
187
+ if (item1.type === 'addExtension' && item2.type === 'addExtension') {
188
+ expect(item1.address.equals(item2.address)).toBeTruthy();
189
+ }
190
+ });
191
+ });
192
+ });
@@ -6,8 +6,10 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  /// <reference types="node" />
9
- import { MessageRelaxed } from "@ton/core";
9
+ import { MessageRelaxed, OutAction, Builder } from "@ton/core";
10
10
  import { Maybe } from "../../utils/maybe";
11
+ import { Wallet5SendArgs } from "../WalletContractV5";
12
+ import { OutActionExtended } from "../WalletV5Utils";
11
13
  export declare function createWalletTransferV1(args: {
12
14
  seqno: number;
13
15
  sendMode: number;
@@ -37,3 +39,7 @@ export declare function createWalletTransferV4(args: {
37
39
  secretKey: Buffer;
38
40
  timeout?: Maybe<number>;
39
41
  }): import("@ton/core").Cell;
42
+ export declare function createWalletTransferV5(args: Wallet5SendArgs & {
43
+ actions: (OutAction | OutActionExtended)[];
44
+ walletId: (builder: Builder) => void;
45
+ }): import("@ton/core").Cell;
@@ -7,9 +7,11 @@
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.createWalletTransferV4 = exports.createWalletTransferV3 = exports.createWalletTransferV2 = exports.createWalletTransferV1 = void 0;
10
+ exports.createWalletTransferV5 = exports.createWalletTransferV4 = exports.createWalletTransferV3 = exports.createWalletTransferV2 = exports.createWalletTransferV1 = void 0;
11
11
  const core_1 = require("@ton/core");
12
12
  const crypto_1 = require("@ton/crypto");
13
+ const WalletContractV5_1 = require("../WalletContractV5");
14
+ const WalletV5Utils_1 = require("../WalletV5Utils");
13
15
  function createWalletTransferV1(args) {
14
16
  // Create message
15
17
  let signingMessage = (0, core_1.beginCell)()
@@ -120,3 +122,33 @@ function createWalletTransferV4(args) {
120
122
  return body;
121
123
  }
122
124
  exports.createWalletTransferV4 = createWalletTransferV4;
125
+ function createWalletTransferV5(args) {
126
+ // Check number of actions
127
+ if (args.actions.length > 255) {
128
+ throw Error("Maximum number of OutActions in a single request is 255");
129
+ }
130
+ if (!('secretKey' in args) || !args.secretKey) {
131
+ return (0, core_1.beginCell)()
132
+ .storeUint(WalletContractV5_1.WalletContractV5.opCodes.auth_extension, 32)
133
+ .store((0, WalletV5Utils_1.storeOutListExtended)(args.actions))
134
+ .endCell();
135
+ }
136
+ const message = (0, core_1.beginCell)().store(args.walletId);
137
+ if (args.seqno === 0) {
138
+ for (let i = 0; i < 32; i++) {
139
+ message.storeBit(1);
140
+ }
141
+ }
142
+ else {
143
+ message.storeUint(args.timeout || Math.floor(Date.now() / 1e3) + 60, 32); // Default timeout: 60 seconds
144
+ }
145
+ message.storeUint(args.seqno, 32).store((0, WalletV5Utils_1.storeOutListExtended)(args.actions));
146
+ // Sign message
147
+ const signature = (0, crypto_1.sign)(message.endCell().hash(), args.secretKey);
148
+ return (0, core_1.beginCell)()
149
+ .storeUint(WalletContractV5_1.WalletContractV5.opCodes.auth_signed, 32)
150
+ .storeBuffer(signature)
151
+ .storeBuilder(message)
152
+ .endCell();
153
+ }
154
+ exports.createWalletTransferV5 = createWalletTransferV5;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ton/ton",
3
- "version": "13.7.0",
3
+ "version": "13.8.0",
4
4
  "repository": "https://github.com/ton-org/ton.git",
5
5
  "author": "Whales Corp. <developers@whalescorp.com>",
6
6
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "devDependencies": {
18
18
  "@release-it/keep-a-changelog": "^3.1.0",
19
- "@ton/core": "^0.52.2",
19
+ "@ton/core": "^0.53.0",
20
20
  "@ton/crypto": "3.2.0",
21
21
  "@ton/emulator": "^2.1.1",
22
22
  "@types/jest": "^27.0.1",
@@ -47,7 +47,7 @@
47
47
  "zod": "^3.21.4"
48
48
  },
49
49
  "peerDependencies": {
50
- "@ton/core": ">=0.51.0",
50
+ "@ton/core": ">=0.53.0",
51
51
  "@ton/crypto": ">=3.2.0"
52
52
  },
53
53
  "publishConfig": {