@ton/ton 13.11.2 → 14.0.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.
- package/dist/client/TonClient.js +22 -14
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/dist/multisig/MultisigWallet.js +1 -1
- package/dist/wallets/WalletContractV3R1.d.ts +2 -7
- package/dist/wallets/WalletContractV3R1.js +2 -9
- package/dist/wallets/WalletContractV3R2.d.ts +2 -7
- package/dist/wallets/WalletContractV3R2.js +2 -9
- package/dist/wallets/WalletContractV3Types.d.ts +12 -0
- package/dist/wallets/WalletContractV3Types.js +2 -0
- package/dist/wallets/WalletContractV4.d.ts +10 -7
- package/dist/wallets/WalletContractV4.js +2 -9
- package/dist/wallets/WalletContractV5Beta.d.ts +3 -0
- package/dist/wallets/WalletContractV5Beta.js +19 -0
- package/dist/wallets/WalletContractV5R1.d.ts +3 -0
- package/dist/wallets/WalletContractV5R1.js +19 -0
- package/dist/wallets/signing/createWalletTransfer.d.ts +24 -15
- package/dist/wallets/signing/createWalletTransfer.js +85 -17
- package/dist/wallets/signing/singer.d.ts +9 -0
- package/dist/wallets/signing/singer.js +21 -0
- package/dist/wallets/v5beta/WalletContractV5Beta.d.ts +130 -0
- package/dist/wallets/v5beta/WalletContractV5Beta.js +211 -0
- package/dist/wallets/v5beta/WalletContractV5Beta.spec.d.ts +8 -0
- package/dist/wallets/v5beta/WalletContractV5Beta.spec.js +298 -0
- package/dist/wallets/v5beta/WalletV5BetaActions.d.ts +6 -0
- package/dist/wallets/v5beta/WalletV5BetaActions.js +92 -0
- package/dist/wallets/v5beta/WalletV5BetaActions.spec.d.ts +1 -0
- package/dist/wallets/v5beta/WalletV5BetaActions.spec.js +166 -0
- package/dist/wallets/v5beta/WalletV5BetaWalletId.d.ts +13 -0
- package/dist/wallets/v5beta/WalletV5BetaWalletId.js +31 -0
- package/dist/wallets/v5beta/WalletV5BetaWalletId.spec.d.ts +1 -0
- package/dist/wallets/v5beta/WalletV5BetaWalletId.spec.js +68 -0
- package/dist/wallets/v5beta/WalletV5OutActions.d.ts +17 -0
- package/dist/wallets/v5beta/WalletV5OutActions.js +11 -0
- package/dist/wallets/v5r1/WalletContractV5R1.d.ts +125 -0
- package/dist/wallets/v5r1/WalletContractV5R1.js +207 -0
- package/dist/wallets/v5r1/WalletContractV5R1.spec.d.ts +8 -0
- package/dist/wallets/v5r1/WalletContractV5R1.spec.js +321 -0
- package/dist/wallets/v5r1/WalletV5R1Actions.d.ts +12 -0
- package/dist/wallets/v5r1/WalletV5R1Actions.js +128 -0
- package/dist/wallets/v5r1/WalletV5R1Actions.spec.d.ts +1 -0
- package/dist/wallets/v5r1/WalletV5R1Actions.spec.js +262 -0
- package/dist/wallets/v5r1/WalletV5R1WalletId.d.ts +47 -0
- package/dist/wallets/v5r1/WalletV5R1WalletId.js +69 -0
- package/dist/wallets/v5r1/WalletV5R1WalletId.spec.d.ts +1 -0
- package/dist/wallets/v5r1/WalletV5R1WalletId.spec.js +72 -0
- package/package.json +1 -1
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@ton/core");
|
|
4
|
+
const WalletV5BetaActions_1 = require("./WalletV5BetaActions");
|
|
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 mockAddress = core_1.Address.parseRaw('0:' + '1'.repeat(64));
|
|
17
|
+
describe('Wallet V5Beta actions', () => {
|
|
18
|
+
const outActionSetIsPublicKeyEnabledTag = 0x20cbb95a;
|
|
19
|
+
const outActionAddExtensionTag = 0x1c40db9f;
|
|
20
|
+
const outActionRemoveExtensionTag = 0x5eaef4a4;
|
|
21
|
+
const outActionSendMsgTag = 0x0ec3c86d;
|
|
22
|
+
it('Should serialise setIsPublicKeyEnabled action with true flag', () => {
|
|
23
|
+
const action = (0, WalletV5BetaActions_1.storeOutActionExtendedV5Beta)({
|
|
24
|
+
type: 'setIsPublicKeyEnabled',
|
|
25
|
+
isEnabled: true
|
|
26
|
+
});
|
|
27
|
+
const actual = (0, core_1.beginCell)().store(action).endCell();
|
|
28
|
+
const expected = (0, core_1.beginCell)()
|
|
29
|
+
.storeUint(outActionSetIsPublicKeyEnabledTag, 32)
|
|
30
|
+
.storeBit(1)
|
|
31
|
+
.endCell();
|
|
32
|
+
expect(expected.equals(actual)).toBeTruthy();
|
|
33
|
+
});
|
|
34
|
+
it('Should serialise setIsPublicKeyEnabled action with false flag', () => {
|
|
35
|
+
const action = (0, WalletV5BetaActions_1.storeOutActionExtendedV5Beta)({
|
|
36
|
+
type: 'setIsPublicKeyEnabled',
|
|
37
|
+
isEnabled: false
|
|
38
|
+
});
|
|
39
|
+
const actual = (0, core_1.beginCell)().store(action).endCell();
|
|
40
|
+
const expected = (0, core_1.beginCell)()
|
|
41
|
+
.storeUint(outActionSetIsPublicKeyEnabledTag, 32)
|
|
42
|
+
.storeBit(0)
|
|
43
|
+
.endCell();
|
|
44
|
+
expect(expected.equals(actual)).toBeTruthy();
|
|
45
|
+
});
|
|
46
|
+
it('Should serialise add extension action', () => {
|
|
47
|
+
const action = (0, WalletV5BetaActions_1.storeOutActionExtendedV5Beta)({
|
|
48
|
+
type: 'addExtension',
|
|
49
|
+
address: mockAddress
|
|
50
|
+
});
|
|
51
|
+
const actual = (0, core_1.beginCell)().store(action).endCell();
|
|
52
|
+
const expected = (0, core_1.beginCell)()
|
|
53
|
+
.storeUint(outActionAddExtensionTag, 32)
|
|
54
|
+
.storeAddress(mockAddress)
|
|
55
|
+
.endCell();
|
|
56
|
+
expect(expected.equals(actual)).toBeTruthy();
|
|
57
|
+
});
|
|
58
|
+
it('Should serialise remove extension action', () => {
|
|
59
|
+
const action = (0, WalletV5BetaActions_1.storeOutActionExtendedV5Beta)({
|
|
60
|
+
type: 'removeExtension',
|
|
61
|
+
address: mockAddress
|
|
62
|
+
});
|
|
63
|
+
const actual = (0, core_1.beginCell)().store(action).endCell();
|
|
64
|
+
const expected = (0, core_1.beginCell)()
|
|
65
|
+
.storeUint(outActionRemoveExtensionTag, 32)
|
|
66
|
+
.storeAddress(mockAddress)
|
|
67
|
+
.endCell();
|
|
68
|
+
expect(expected.equals(actual)).toBeTruthy();
|
|
69
|
+
});
|
|
70
|
+
it('Should serialize extended out list', () => {
|
|
71
|
+
const sendMode1 = core_1.SendMode.PAY_GAS_SEPARATELY;
|
|
72
|
+
const isPublicKeyEnabled = false;
|
|
73
|
+
const actions = [
|
|
74
|
+
{
|
|
75
|
+
type: 'addExtension',
|
|
76
|
+
address: mockAddress
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
type: 'setIsPublicKeyEnabled',
|
|
80
|
+
isEnabled: isPublicKeyEnabled
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
type: 'sendMsg',
|
|
84
|
+
mode: sendMode1,
|
|
85
|
+
outMsg: mockMessageRelaxed1
|
|
86
|
+
}
|
|
87
|
+
];
|
|
88
|
+
const actual = (0, core_1.beginCell)().store((0, WalletV5BetaActions_1.storeOutListExtendedV5Beta)(actions)).endCell();
|
|
89
|
+
const expected = (0, core_1.beginCell)()
|
|
90
|
+
.storeUint(1, 1)
|
|
91
|
+
.storeUint(outActionAddExtensionTag, 32)
|
|
92
|
+
.storeAddress(mockAddress)
|
|
93
|
+
.storeRef((0, core_1.beginCell)()
|
|
94
|
+
.storeUint(1, 1)
|
|
95
|
+
.storeUint(outActionSetIsPublicKeyEnabledTag, 32)
|
|
96
|
+
.storeBit(isPublicKeyEnabled ? 1 : 0)
|
|
97
|
+
.storeRef((0, core_1.beginCell)()
|
|
98
|
+
.storeUint(0, 1)
|
|
99
|
+
.storeRef((0, core_1.beginCell)()
|
|
100
|
+
.storeRef((0, core_1.beginCell)().endCell())
|
|
101
|
+
.storeUint(outActionSendMsgTag, 32)
|
|
102
|
+
.storeUint(sendMode1, 8)
|
|
103
|
+
.storeRef((0, core_1.beginCell)().store((0, core_1.storeMessageRelaxed)(mockMessageRelaxed1)).endCell())
|
|
104
|
+
.endCell())
|
|
105
|
+
.endCell())
|
|
106
|
+
.endCell())
|
|
107
|
+
.endCell();
|
|
108
|
+
expect(actual.equals(expected)).toBeTruthy();
|
|
109
|
+
});
|
|
110
|
+
it('Should deserialize extended out list', () => {
|
|
111
|
+
const sendMode1 = core_1.SendMode.PAY_GAS_SEPARATELY;
|
|
112
|
+
const isPublicKeyEnabled = true;
|
|
113
|
+
const expected = [
|
|
114
|
+
{
|
|
115
|
+
type: 'addExtension',
|
|
116
|
+
address: mockAddress
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
type: 'setIsPublicKeyEnabled',
|
|
120
|
+
isEnabled: isPublicKeyEnabled
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
type: 'sendMsg',
|
|
124
|
+
mode: sendMode1,
|
|
125
|
+
outMsg: mockMessageRelaxed1
|
|
126
|
+
}
|
|
127
|
+
];
|
|
128
|
+
const serialized = (0, core_1.beginCell)()
|
|
129
|
+
.storeUint(1, 1)
|
|
130
|
+
.storeUint(outActionAddExtensionTag, 32)
|
|
131
|
+
.storeAddress(mockAddress)
|
|
132
|
+
.storeRef((0, core_1.beginCell)()
|
|
133
|
+
.storeUint(1, 1)
|
|
134
|
+
.storeUint(outActionSetIsPublicKeyEnabledTag, 32)
|
|
135
|
+
.storeBit(isPublicKeyEnabled ? 1 : 0)
|
|
136
|
+
.storeRef((0, core_1.beginCell)()
|
|
137
|
+
.storeUint(0, 1)
|
|
138
|
+
.storeRef((0, core_1.beginCell)()
|
|
139
|
+
.storeRef((0, core_1.beginCell)().endCell())
|
|
140
|
+
.storeUint(outActionSendMsgTag, 32)
|
|
141
|
+
.storeUint(sendMode1, 8)
|
|
142
|
+
.storeRef((0, core_1.beginCell)().store((0, core_1.storeMessageRelaxed)(mockMessageRelaxed1)).endCell())
|
|
143
|
+
.endCell())
|
|
144
|
+
.endCell())
|
|
145
|
+
.endCell())
|
|
146
|
+
.endCell();
|
|
147
|
+
const actual = (0, WalletV5BetaActions_1.loadOutListExtendedV5Beta)(serialized.beginParse());
|
|
148
|
+
expect(expected.length).toEqual(actual.length);
|
|
149
|
+
expected.forEach((item1, index) => {
|
|
150
|
+
const item2 = actual[index];
|
|
151
|
+
expect(item1.type).toEqual(item2.type);
|
|
152
|
+
if (item1.type === 'sendMsg' && item2.type === 'sendMsg') {
|
|
153
|
+
expect(item1.mode).toEqual(item2.mode);
|
|
154
|
+
expect(item1.outMsg.body.equals(item2.outMsg.body)).toBeTruthy();
|
|
155
|
+
expect(item1.outMsg.info).toEqual(item2.outMsg.info);
|
|
156
|
+
expect(item1.outMsg.init).toEqual(item2.outMsg.init);
|
|
157
|
+
}
|
|
158
|
+
if (item1.type === 'addExtension' && item2.type === 'addExtension') {
|
|
159
|
+
expect(item1.address.equals(item2.address)).toBeTruthy();
|
|
160
|
+
}
|
|
161
|
+
if (item1.type === 'setIsPublicKeyEnabled' && item2.type === 'setIsPublicKeyEnabled') {
|
|
162
|
+
expect(item1.isEnabled).toEqual(item2.isEnabled);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Builder, Slice } from '@ton/core';
|
|
3
|
+
export interface WalletIdV5Beta {
|
|
4
|
+
readonly walletVersion: 'v5';
|
|
5
|
+
/**
|
|
6
|
+
* -239 is mainnet, -3 is testnet
|
|
7
|
+
*/
|
|
8
|
+
readonly networkGlobalId: number;
|
|
9
|
+
readonly workChain: number;
|
|
10
|
+
readonly subwalletNumber: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function loadWalletIdV5Beta(value: bigint | Buffer | Slice): WalletIdV5Beta;
|
|
13
|
+
export declare function storeWalletIdV5Beta(walletId: WalletIdV5Beta): (builder: Builder) => void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.storeWalletIdV5Beta = exports.loadWalletIdV5Beta = void 0;
|
|
4
|
+
const core_1 = require("@ton/core");
|
|
5
|
+
const walletV5BetaVersionsSerialisation = {
|
|
6
|
+
v5: 0
|
|
7
|
+
};
|
|
8
|
+
function loadWalletIdV5Beta(value) {
|
|
9
|
+
const bitReader = new core_1.BitReader(new core_1.BitString(typeof value === 'bigint' ?
|
|
10
|
+
Buffer.from(value.toString(16), 'hex') :
|
|
11
|
+
value instanceof core_1.Slice ? value.loadBuffer(10) : value, 0, 80));
|
|
12
|
+
const networkGlobalId = bitReader.loadInt(32);
|
|
13
|
+
const workChain = bitReader.loadInt(8);
|
|
14
|
+
const walletVersionRaw = bitReader.loadUint(8);
|
|
15
|
+
const subwalletNumber = bitReader.loadUint(32);
|
|
16
|
+
const walletVersion = Object.entries(walletV5BetaVersionsSerialisation).find(([_, value]) => value === walletVersionRaw)?.[0];
|
|
17
|
+
if (walletVersion === undefined) {
|
|
18
|
+
throw new Error(`Can't deserialize walletId: unknown wallet version ${walletVersionRaw}`);
|
|
19
|
+
}
|
|
20
|
+
return { networkGlobalId, workChain, walletVersion, subwalletNumber };
|
|
21
|
+
}
|
|
22
|
+
exports.loadWalletIdV5Beta = loadWalletIdV5Beta;
|
|
23
|
+
function storeWalletIdV5Beta(walletId) {
|
|
24
|
+
return (builder) => {
|
|
25
|
+
builder.storeInt(walletId.networkGlobalId, 32);
|
|
26
|
+
builder.storeInt(walletId.workChain, 8);
|
|
27
|
+
builder.storeUint(walletV5BetaVersionsSerialisation[walletId.walletVersion], 8);
|
|
28
|
+
builder.storeUint(walletId.subwalletNumber, 32);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exports.storeWalletIdV5Beta = storeWalletIdV5Beta;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@ton/core");
|
|
4
|
+
const WalletV5BetaWalletId_1 = require("./WalletV5BetaWalletId");
|
|
5
|
+
describe('Wallet V5Beta wallet id', () => {
|
|
6
|
+
it('Should serialise wallet id', () => {
|
|
7
|
+
const walletId = {
|
|
8
|
+
walletVersion: 'v5',
|
|
9
|
+
networkGlobalId: -239,
|
|
10
|
+
workChain: 0,
|
|
11
|
+
subwalletNumber: 0
|
|
12
|
+
};
|
|
13
|
+
const actual = (0, core_1.beginCell)().store((0, WalletV5BetaWalletId_1.storeWalletIdV5Beta)(walletId)).endCell();
|
|
14
|
+
const expected = (0, core_1.beginCell)()
|
|
15
|
+
.storeInt(walletId.networkGlobalId, 32)
|
|
16
|
+
.storeInt(walletId.workChain, 8)
|
|
17
|
+
.storeUint(0, 8)
|
|
18
|
+
.storeUint(walletId.subwalletNumber, 32)
|
|
19
|
+
.endCell();
|
|
20
|
+
expect(expected.equals(actual)).toBeTruthy();
|
|
21
|
+
});
|
|
22
|
+
it('Should deserialise wallet id', () => {
|
|
23
|
+
const expected = {
|
|
24
|
+
walletVersion: 'v5',
|
|
25
|
+
networkGlobalId: -239,
|
|
26
|
+
workChain: 0,
|
|
27
|
+
subwalletNumber: 0
|
|
28
|
+
};
|
|
29
|
+
const actual = (0, WalletV5BetaWalletId_1.loadWalletIdV5Beta)((0, core_1.beginCell)()
|
|
30
|
+
.storeInt(expected.networkGlobalId, 32)
|
|
31
|
+
.storeInt(expected.workChain, 8)
|
|
32
|
+
.storeUint(0, 8)
|
|
33
|
+
.storeUint(expected.subwalletNumber, 32)
|
|
34
|
+
.endCell().beginParse());
|
|
35
|
+
expect(expected).toEqual(actual);
|
|
36
|
+
});
|
|
37
|
+
it('Should serialise wallet id', () => {
|
|
38
|
+
const walletId = {
|
|
39
|
+
walletVersion: 'v5',
|
|
40
|
+
networkGlobalId: -3,
|
|
41
|
+
workChain: -1,
|
|
42
|
+
subwalletNumber: 1234
|
|
43
|
+
};
|
|
44
|
+
const actual = (0, core_1.beginCell)().store((0, WalletV5BetaWalletId_1.storeWalletIdV5Beta)(walletId)).endCell();
|
|
45
|
+
const expected = (0, core_1.beginCell)()
|
|
46
|
+
.storeInt(walletId.networkGlobalId, 32)
|
|
47
|
+
.storeInt(walletId.workChain, 8)
|
|
48
|
+
.storeUint(0, 8)
|
|
49
|
+
.storeUint(walletId.subwalletNumber, 32)
|
|
50
|
+
.endCell();
|
|
51
|
+
expect(expected.equals(actual)).toBeTruthy();
|
|
52
|
+
});
|
|
53
|
+
it('Should deserialise wallet id', () => {
|
|
54
|
+
const expected = {
|
|
55
|
+
walletVersion: 'v5',
|
|
56
|
+
networkGlobalId: -239,
|
|
57
|
+
workChain: -1,
|
|
58
|
+
subwalletNumber: 1
|
|
59
|
+
};
|
|
60
|
+
const actual = (0, WalletV5BetaWalletId_1.loadWalletIdV5Beta)((0, core_1.beginCell)()
|
|
61
|
+
.storeInt(expected.networkGlobalId, 32)
|
|
62
|
+
.storeInt(expected.workChain, 8)
|
|
63
|
+
.storeUint(0, 8)
|
|
64
|
+
.storeUint(expected.subwalletNumber, 32)
|
|
65
|
+
.endCell().beginParse());
|
|
66
|
+
expect(expected).toEqual(actual);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Address, OutActionSendMsg } from '@ton/core';
|
|
2
|
+
export interface OutActionAddExtension {
|
|
3
|
+
type: 'addExtension';
|
|
4
|
+
address: Address;
|
|
5
|
+
}
|
|
6
|
+
export interface OutActionRemoveExtension {
|
|
7
|
+
type: 'removeExtension';
|
|
8
|
+
address: Address;
|
|
9
|
+
}
|
|
10
|
+
export interface OutActionSetIsPublicKeyEnabled {
|
|
11
|
+
type: 'setIsPublicKeyEnabled';
|
|
12
|
+
isEnabled: boolean;
|
|
13
|
+
}
|
|
14
|
+
export type OutActionExtended = OutActionSetIsPublicKeyEnabled | OutActionAddExtension | OutActionRemoveExtension;
|
|
15
|
+
export type OutActionWalletV5 = OutActionExtended | OutActionSendMsg;
|
|
16
|
+
export declare function isOutActionExtended(action: OutActionSendMsg | OutActionExtended): action is OutActionExtended;
|
|
17
|
+
export declare function isOutActionBasic(action: OutActionSendMsg | OutActionExtended): action is OutActionSendMsg;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isOutActionBasic = exports.isOutActionExtended = void 0;
|
|
4
|
+
function isOutActionExtended(action) {
|
|
5
|
+
return (action.type === 'setIsPublicKeyEnabled' || action.type === 'addExtension' || action.type === 'removeExtension');
|
|
6
|
+
}
|
|
7
|
+
exports.isOutActionExtended = isOutActionExtended;
|
|
8
|
+
function isOutActionBasic(action) {
|
|
9
|
+
return !isOutActionExtended(action);
|
|
10
|
+
}
|
|
11
|
+
exports.isOutActionBasic = isOutActionBasic;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Whales Corp.
|
|
3
|
+
* All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
/// <reference types="node" />
|
|
9
|
+
import { Address, Cell, Contract, ContractProvider, MessageRelaxed, Sender, SendMode } from "@ton/core";
|
|
10
|
+
import { Maybe } from "../../utils/maybe";
|
|
11
|
+
import { SendArgsSignable, SendArgsSigned } from "../signing/singer";
|
|
12
|
+
import { OutActionWalletV5 } from "../v5beta/WalletV5OutActions";
|
|
13
|
+
import { WalletIdV5R1, WalletIdV5R1ClientContext, WalletIdV5R1CustomContext } from "./WalletV5R1WalletId";
|
|
14
|
+
export type WalletV5R1BasicSendArgs = {
|
|
15
|
+
seqno: number;
|
|
16
|
+
timeout?: Maybe<number>;
|
|
17
|
+
};
|
|
18
|
+
export type WalletV5R1SendArgsSinged = WalletV5R1BasicSendArgs & SendArgsSigned & {
|
|
19
|
+
authType?: 'external' | 'internal';
|
|
20
|
+
};
|
|
21
|
+
export type WalletV5R1SendArgsSignable = WalletV5R1BasicSendArgs & SendArgsSignable & {
|
|
22
|
+
authType?: 'external' | 'internal';
|
|
23
|
+
};
|
|
24
|
+
export type Wallet5VR1SendArgsExtensionAuth = WalletV5R1BasicSendArgs & {
|
|
25
|
+
authType: 'extension';
|
|
26
|
+
queryId?: bigint;
|
|
27
|
+
};
|
|
28
|
+
export type WalletV5R1SendArgs = WalletV5R1SendArgsSinged | WalletV5R1SendArgsSignable | Wallet5VR1SendArgsExtensionAuth;
|
|
29
|
+
export type WalletV5R1PackedCell<T> = T extends WalletV5R1SendArgsSignable ? Promise<Cell> : Cell;
|
|
30
|
+
export declare class WalletContractV5R1 implements Contract {
|
|
31
|
+
readonly publicKey: Buffer;
|
|
32
|
+
readonly walletId: WalletIdV5R1<WalletIdV5R1ClientContext | WalletIdV5R1CustomContext>;
|
|
33
|
+
static OpCodes: {
|
|
34
|
+
auth_extension: number;
|
|
35
|
+
auth_signed_external: number;
|
|
36
|
+
auth_signed_internal: number;
|
|
37
|
+
};
|
|
38
|
+
static create<C extends WalletIdV5R1ClientContext | WalletIdV5R1CustomContext>(args: C extends WalletIdV5R1ClientContext ? {
|
|
39
|
+
walletId?: Maybe<WalletIdV5R1<C>>;
|
|
40
|
+
publicKey: Buffer;
|
|
41
|
+
} : {
|
|
42
|
+
workChain?: number;
|
|
43
|
+
publicKey: Buffer;
|
|
44
|
+
walletId?: Maybe<Partial<WalletIdV5R1<C>>>;
|
|
45
|
+
}): WalletContractV5R1;
|
|
46
|
+
readonly address: Address;
|
|
47
|
+
readonly init: {
|
|
48
|
+
data: Cell;
|
|
49
|
+
code: Cell;
|
|
50
|
+
};
|
|
51
|
+
private constructor();
|
|
52
|
+
/**
|
|
53
|
+
* Get Wallet Balance
|
|
54
|
+
*/
|
|
55
|
+
getBalance(provider: ContractProvider): Promise<bigint>;
|
|
56
|
+
/**
|
|
57
|
+
* Get Wallet Seqno
|
|
58
|
+
*/
|
|
59
|
+
getSeqno(provider: ContractProvider): Promise<number>;
|
|
60
|
+
/**
|
|
61
|
+
* Get Wallet Extensions
|
|
62
|
+
*/
|
|
63
|
+
getExtensions(provider: ContractProvider): Promise<Cell | null>;
|
|
64
|
+
/**
|
|
65
|
+
* Get Wallet Extensions
|
|
66
|
+
*/
|
|
67
|
+
getExtensionsArray(provider: ContractProvider): Promise<Address[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Get is secret-key authentication enabled
|
|
70
|
+
*/
|
|
71
|
+
getIsSecretKeyAuthEnabled(provider: ContractProvider): Promise<boolean>;
|
|
72
|
+
/**
|
|
73
|
+
* Send signed transfer
|
|
74
|
+
*/
|
|
75
|
+
send(provider: ContractProvider, message: Cell): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Sign and send transfer
|
|
78
|
+
*/
|
|
79
|
+
sendTransfer(provider: ContractProvider, args: WalletV5R1SendArgs & {
|
|
80
|
+
messages: MessageRelaxed[];
|
|
81
|
+
sendMode: SendMode;
|
|
82
|
+
}): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Sign and send add extension request
|
|
85
|
+
*/
|
|
86
|
+
sendAddExtension(provider: ContractProvider, args: WalletV5R1SendArgs & {
|
|
87
|
+
extensionAddress: Address;
|
|
88
|
+
}): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Sign and send remove extension request
|
|
91
|
+
*/
|
|
92
|
+
sendRemoveExtension(provider: ContractProvider, args: WalletV5R1SendArgs & {
|
|
93
|
+
extensionAddress: Address;
|
|
94
|
+
}): Promise<void>;
|
|
95
|
+
private createActions;
|
|
96
|
+
/**
|
|
97
|
+
* Create signed transfer
|
|
98
|
+
*/
|
|
99
|
+
createTransfer<T extends WalletV5R1SendArgs>(args: T & {
|
|
100
|
+
messages: MessageRelaxed[];
|
|
101
|
+
sendMode: SendMode;
|
|
102
|
+
}): WalletV5R1PackedCell<T>;
|
|
103
|
+
/**
|
|
104
|
+
* Create signed add extension request
|
|
105
|
+
*/
|
|
106
|
+
createAddExtension<T extends WalletV5R1SendArgs>(args: T & {
|
|
107
|
+
extensionAddress: Address;
|
|
108
|
+
}): WalletV5R1PackedCell<T>;
|
|
109
|
+
/**
|
|
110
|
+
* Create signed remove extension request
|
|
111
|
+
*/
|
|
112
|
+
createRemoveExtension<T extends WalletV5R1SendArgs>(args: T & {
|
|
113
|
+
extensionAddress: Address;
|
|
114
|
+
}): WalletV5R1PackedCell<T>;
|
|
115
|
+
/**
|
|
116
|
+
* Create signed request or extension auth request
|
|
117
|
+
*/
|
|
118
|
+
createRequest<T extends WalletV5R1SendArgs>(args: T & {
|
|
119
|
+
actions: OutActionWalletV5[];
|
|
120
|
+
}): WalletV5R1PackedCell<T>;
|
|
121
|
+
/**
|
|
122
|
+
* Create sender
|
|
123
|
+
*/
|
|
124
|
+
sender(provider: ContractProvider, secretKey: Buffer): Sender;
|
|
125
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Whales Corp.
|
|
4
|
+
* All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.WalletContractV5R1 = void 0;
|
|
11
|
+
const core_1 = require("@ton/core");
|
|
12
|
+
const createWalletTransfer_1 = require("../signing/createWalletTransfer");
|
|
13
|
+
const WalletV5R1WalletId_1 = require("./WalletV5R1WalletId");
|
|
14
|
+
class WalletContractV5R1 {
|
|
15
|
+
static create(args) {
|
|
16
|
+
let workChain = 0;
|
|
17
|
+
if ('workChain' in args && args.workChain != undefined) {
|
|
18
|
+
workChain = args.workChain;
|
|
19
|
+
}
|
|
20
|
+
if (args.walletId?.context && (0, WalletV5R1WalletId_1.isWalletIdV5R1ClientContext)(args.walletId.context) && args.walletId.context.workChain != undefined) {
|
|
21
|
+
workChain = args.walletId.context.workChain;
|
|
22
|
+
}
|
|
23
|
+
return new WalletContractV5R1(workChain, args.publicKey, {
|
|
24
|
+
networkGlobalId: args.walletId?.networkGlobalId ?? -239,
|
|
25
|
+
context: args.walletId?.context ?? {
|
|
26
|
+
workChain: 0,
|
|
27
|
+
walletVersion: 'v5r1',
|
|
28
|
+
subwalletNumber: 0
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
constructor(workChain, publicKey, walletId) {
|
|
33
|
+
this.publicKey = publicKey;
|
|
34
|
+
this.walletId = walletId;
|
|
35
|
+
this.walletId = walletId;
|
|
36
|
+
// https://github.com/ton-blockchain/wallet-contract-v5/blob/4fab977f4fae3a37c1aac216ed2b7e611a9bc2af/build/wallet_v5.compiled.json
|
|
37
|
+
let code = core_1.Cell.fromBoc(Buffer.from('b5ee9c7241021401000281000114ff00f4a413f4bcf2c80b01020120020d020148030402dcd020d749c120915b8f6320d70b1f2082106578746ebd21821073696e74bdb0925f03e082106578746eba8eb48020d72101d074d721fa4030fa44f828fa443058bd915be0ed44d0810141d721f4058307f40e6fa1319130e18040d721707fdb3ce03120d749810280b99130e070e2100f020120050c020120060902016e07080019adce76a2684020eb90eb85ffc00019af1df6a2684010eb90eb858fc00201480a0b0017b325fb51341c75c875c2c7e00011b262fb513435c280200019be5f0f6a2684080a0eb90fa02c0102f20e011e20d70b1f82107369676ebaf2e08a7f0f01e68ef0eda2edfb218308d722028308d723208020d721d31fd31fd31fed44d0d200d31f20d31fd3ffd70a000af90140ccf9109a28945f0adb31e1f2c087df02b35007b0f2d0845125baf2e0855036baf2e086f823bbf2d0882292f800de01a47fc8ca00cb1f01cf16c9ed542092f80fde70db3cd81003f6eda2edfb02f404216e926c218e4c0221d73930709421c700b38e2d01d72820761e436c20d749c008f2e09320d74ac002f2e09320d71d06c712c2005230b0f2d089d74cd7393001a4e86c128407bbf2e093d74ac000f2e093ed55e2d20001c000915be0ebd72c08142091709601d72c081c12e25210b1e30f20d74a111213009601fa4001fa44f828fa443058baf2e091ed44d0810141d718f405049d7fc8ca0040048307f453f2e08b8e14038307f45bf2e08c22d70a00216e01b3b0f2d090e2c85003cf1612f400c9ed54007230d72c08248e2d21f2e092d200ed44d0d2005113baf2d08f54503091319c01810140d721d70a00f2e08ee2c8ca0058cf16c9ed5493f2c08de20010935bdb31e1d74cd0b4d6c35e', 'hex'))[0];
|
|
38
|
+
let data = (0, core_1.beginCell)()
|
|
39
|
+
.storeUint(1, 1) // is signature auth allowed
|
|
40
|
+
.storeUint(0, 32) // Seqno
|
|
41
|
+
.store((0, WalletV5R1WalletId_1.storeWalletIdV5R1)(this.walletId))
|
|
42
|
+
.storeBuffer(this.publicKey, 32)
|
|
43
|
+
.storeBit(0) // Empty plugins dict
|
|
44
|
+
.endCell();
|
|
45
|
+
this.init = { code, data };
|
|
46
|
+
this.address = (0, core_1.contractAddress)(workChain, { code, data });
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get Wallet Balance
|
|
50
|
+
*/
|
|
51
|
+
async getBalance(provider) {
|
|
52
|
+
let state = await provider.getState();
|
|
53
|
+
return state.balance;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get Wallet Seqno
|
|
57
|
+
*/
|
|
58
|
+
async getSeqno(provider) {
|
|
59
|
+
let state = await provider.getState();
|
|
60
|
+
if (state.state.type === 'active') {
|
|
61
|
+
let res = await provider.get('seqno', []);
|
|
62
|
+
return res.stack.readNumber();
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get Wallet Extensions
|
|
70
|
+
*/
|
|
71
|
+
async getExtensions(provider) {
|
|
72
|
+
let state = await provider.getState();
|
|
73
|
+
if (state.state.type === 'active') {
|
|
74
|
+
const result = await provider.get('get_extensions', []);
|
|
75
|
+
return result.stack.readCellOpt();
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get Wallet Extensions
|
|
83
|
+
*/
|
|
84
|
+
async getExtensionsArray(provider) {
|
|
85
|
+
const extensions = await this.getExtensions(provider);
|
|
86
|
+
if (!extensions) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
const dict = core_1.Dictionary.loadDirect(core_1.Dictionary.Keys.BigUint(256), core_1.Dictionary.Values.BigInt(1), extensions);
|
|
90
|
+
return dict.keys().map(addressHex => {
|
|
91
|
+
const wc = this.address.workChain;
|
|
92
|
+
return core_1.Address.parseRaw(`${wc}:${addressHex.toString(16).padStart(64, '0')}`);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get is secret-key authentication enabled
|
|
97
|
+
*/
|
|
98
|
+
async getIsSecretKeyAuthEnabled(provider) {
|
|
99
|
+
let res = await provider.get('is_signature_allowed', []);
|
|
100
|
+
return res.stack.readBoolean();
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Send signed transfer
|
|
104
|
+
*/
|
|
105
|
+
async send(provider, message) {
|
|
106
|
+
await provider.external(message);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Sign and send transfer
|
|
110
|
+
*/
|
|
111
|
+
async sendTransfer(provider, args) {
|
|
112
|
+
const transfer = await this.createTransfer(args);
|
|
113
|
+
await this.send(provider, transfer);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Sign and send add extension request
|
|
117
|
+
*/
|
|
118
|
+
async sendAddExtension(provider, args) {
|
|
119
|
+
const request = await this.createAddExtension(args);
|
|
120
|
+
await this.send(provider, request);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Sign and send remove extension request
|
|
124
|
+
*/
|
|
125
|
+
async sendRemoveExtension(provider, args) {
|
|
126
|
+
const request = await this.createRemoveExtension(args);
|
|
127
|
+
await this.send(provider, request);
|
|
128
|
+
}
|
|
129
|
+
createActions(args) {
|
|
130
|
+
const actions = args.messages.map(message => ({ type: 'sendMsg', mode: args.sendMode, outMsg: message }));
|
|
131
|
+
return actions;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Create signed transfer
|
|
135
|
+
*/
|
|
136
|
+
createTransfer(args) {
|
|
137
|
+
return this.createRequest({
|
|
138
|
+
actions: this.createActions({ messages: args.messages, sendMode: args.sendMode }),
|
|
139
|
+
...args
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Create signed add extension request
|
|
144
|
+
*/
|
|
145
|
+
createAddExtension(args) {
|
|
146
|
+
return this.createRequest({
|
|
147
|
+
actions: [{
|
|
148
|
+
type: 'addExtension',
|
|
149
|
+
address: args.extensionAddress
|
|
150
|
+
}],
|
|
151
|
+
...args
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Create signed remove extension request
|
|
156
|
+
*/
|
|
157
|
+
createRemoveExtension(args) {
|
|
158
|
+
return this.createRequest({
|
|
159
|
+
actions: [{
|
|
160
|
+
type: 'removeExtension',
|
|
161
|
+
address: args.extensionAddress
|
|
162
|
+
}],
|
|
163
|
+
...args
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Create signed request or extension auth request
|
|
168
|
+
*/
|
|
169
|
+
createRequest(args) {
|
|
170
|
+
if (args.authType === 'extension') {
|
|
171
|
+
return (0, createWalletTransfer_1.createWalletTransferV5R1)(args);
|
|
172
|
+
}
|
|
173
|
+
return (0, createWalletTransfer_1.createWalletTransferV5R1)({
|
|
174
|
+
...args,
|
|
175
|
+
walletId: (0, WalletV5R1WalletId_1.storeWalletIdV5R1)(this.walletId)
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Create sender
|
|
180
|
+
*/
|
|
181
|
+
sender(provider, secretKey) {
|
|
182
|
+
return {
|
|
183
|
+
send: async (args) => {
|
|
184
|
+
let seqno = await this.getSeqno(provider);
|
|
185
|
+
let transfer = this.createTransfer({
|
|
186
|
+
seqno,
|
|
187
|
+
secretKey,
|
|
188
|
+
sendMode: args.sendMode ?? core_1.SendMode.PAY_GAS_SEPARATELY + core_1.SendMode.IGNORE_ERRORS,
|
|
189
|
+
messages: [(0, core_1.internal)({
|
|
190
|
+
to: args.to,
|
|
191
|
+
value: args.value,
|
|
192
|
+
init: args.init,
|
|
193
|
+
body: args.body,
|
|
194
|
+
bounce: args.bounce
|
|
195
|
+
})]
|
|
196
|
+
});
|
|
197
|
+
await this.send(provider, transfer);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
exports.WalletContractV5R1 = WalletContractV5R1;
|
|
203
|
+
WalletContractV5R1.OpCodes = {
|
|
204
|
+
auth_extension: 0x6578746e,
|
|
205
|
+
auth_signed_external: 0x7369676e,
|
|
206
|
+
auth_signed_internal: 0x73696e74
|
|
207
|
+
};
|