From 171b4577dafefe6a7eeb6e281a37cb614473510c Mon Sep 17 00:00:00 2001 From: Dan Volkov Date: Wed, 25 Oct 2023 13:56:45 +0400 Subject: [PATCH] chore: remove wallet v5 due to unreadiness --- src/wallets/WalletContractV5.spec.ts | 179 -------------- src/wallets/WalletContractV5.ts | 258 ------------------- src/wallets/WalletV5Utils.spec.ts | 261 -------------------- src/wallets/WalletV5Utils.ts | 179 -------------- src/wallets/signing/createWalletTransfer.ts | 42 ---- 5 files changed, 919 deletions(-) delete mode 100644 src/wallets/WalletContractV5.spec.ts delete mode 100644 src/wallets/WalletContractV5.ts delete mode 100644 src/wallets/WalletV5Utils.spec.ts delete mode 100644 src/wallets/WalletV5Utils.ts diff --git a/src/wallets/WalletContractV5.spec.ts b/src/wallets/WalletContractV5.spec.ts deleted file mode 100644 index fa9253e..0000000 --- a/src/wallets/WalletContractV5.spec.ts +++ /dev/null @@ -1,179 +0,0 @@ -/** - * Copyright (c) Whales Corp. - * All Rights Reserved. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { randomTestKey } from "../utils/randomTestKey"; -import { Address, internal, OpenedContract } from "@ton/core"; -import { WalletContractV5 } from "./WalletContractV5"; -import { KeyPair } from "@ton/crypto"; -import { createTestClient } from "../utils/createTestClient"; -import { TonClient } from "../client/TonClient"; - -const getExtensionsArray = async (wallet: OpenedContract) => { - try { - return await wallet.getExtensionsArray(); - } catch (e) { - // Handle toncenter bug. Toncenter incorrectly returns 'list' in the stack in case of empty extensions dict - if (e instanceof Error && e.message === 'Unsupported stack item type: list') { - return []; - } - throw e; - } -} - -describe('WalletContractV5', () => { - let client: TonClient; - let walletKey: KeyPair; - let wallet: OpenedContract; - - beforeEach(() => { - client = createTestClient(); - walletKey = randomTestKey('v5-treasure'); - wallet = client.open(WalletContractV5.create({ walletId: { networkGlobalId: -3 }, publicKey: walletKey.publicKey })); - - }) - - it('should has balance and correct address', async () => { - const balance = await wallet.getBalance(); - - expect(wallet.address.equals(Address.parse('EQDv2B0jPmJZ1j-ne3Ko64eGqfYZRHGQbfSE5pUWVvUdQmDH'))).toBeTruthy(); - expect(balance > 0n).toBe(true); - }); - - it('should perform single transfer', async () => { - const seqno = await wallet.getSeqno(); - const transfer = wallet.createTransfer({ - seqno, - secretKey: walletKey.secretKey, - messages: [internal({ - to: 'EQDQ0PRYSWmW-v6LVHNYq5Uelpr5f7Ct7awG7Lao2HImrCzn', - value: '0.01', - body: 'Hello world single transfer!' - })] - }); - - await wallet.send(transfer); - }); - - it('should perform double transfer', async () => { - const seqno = await wallet.getSeqno(); - const transfer = wallet.createTransfer({ - seqno, - secretKey: walletKey.secretKey, - messages: [internal({ - to: 'EQDQ0PRYSWmW-v6LVHNYq5Uelpr5f7Ct7awG7Lao2HImrCzn', - value: '0.01', - body: 'Hello world to extension' - }), internal({ - to: 'EQAtHiE_vEyAogU1rHcz3uzp64h-yqeFJ2S2ChkKNwygLMk3', - value: '0.02', - body: 'Hello world to relayer' - })] - }); - - await wallet.send(transfer); - }); - - it('should add extension', async () => { - const extensionKey = randomTestKey('v5-treasure-extension'); - const extensionContract = client.open(WalletContractV5.create({ walletId: { workChain: 0, networkGlobalId: -3 }, publicKey: extensionKey.publicKey })); - - - const seqno = await wallet.getSeqno(); - const extensions = await getExtensionsArray(wallet); - - const extensionAlreadyAdded = extensions.some(address => address.equals(extensionContract.address)); - - if (!extensionAlreadyAdded) { - await wallet.sendAddExtension({ - seqno, - secretKey: walletKey.secretKey, - extensionAddress: extensionContract.address - }); - - const waitUntilExtensionAdded = async (attempt = 0): Promise => { - if (attempt >= 10) { - throw new Error('Extension was not added in 10 blocks'); - } - const extensions = await getExtensionsArray(wallet); - const extensionAdded = extensions.some(address => address.equals(extensionContract.address)); - if (extensionAdded) { - return; - } - - await new Promise(r => setTimeout(r, 1500)); - return waitUntilExtensionAdded(attempt + 1); - } - - await waitUntilExtensionAdded(); - } - - const extensionsSeqno = await extensionContract.getSeqno(); - await extensionContract.sendTransfer({ - seqno: extensionsSeqno, - secretKey: extensionKey.secretKey, - messages: [internal({ - to: wallet.address, - value: '0.1', - body: wallet.createTransfer({ - seqno: seqno + 1, - messages: [internal({ - to: 'kQD6oPnzaaAMRW24R8F0_nlSsJQni0cGHntR027eT9_sgtwt', - value: '0.03', - body: 'Hello world from plugin' - })] - }) - })] - }); - }, 60000); - - it('should remove extension', async () => { - const extensionKey = randomTestKey('v5-treasure-extension'); - const extensionContract = client.open(WalletContractV5.create({ walletId: { workChain: 0, networkGlobalId: -3 }, publicKey: extensionKey.publicKey })); - - - const seqno = await wallet.getSeqno(); - const extensions = await getExtensionsArray(wallet); - - const extensionAlreadyAdded = extensions.some(address => address.equals(extensionContract.address)); - - if (extensionAlreadyAdded) { - await wallet.sendRemoveExtension({ - seqno, - secretKey: walletKey.secretKey, - extensionAddress: extensionContract.address - }); - } - }); - - it('should send internal transfer via relayer', async () => { - const relaerKey = randomTestKey('v5-treasure-relayer'); - const relayerContract = client.open(WalletContractV5.create({ walletId: { workChain: 0, networkGlobalId: -3 }, publicKey: relaerKey.publicKey })); - - - const seqno = await wallet.getSeqno(); - - const relayerSeqno = await relayerContract.getSeqno(); - await relayerContract.sendTransfer({ - seqno: relayerSeqno, - secretKey: relaerKey.secretKey, - messages: [internal({ - to: wallet.address, - value: '0.1', - body: wallet.createTransfer({ - seqno: seqno, - secretKey: walletKey.secretKey, - messages: [internal({ - to: 'kQD6oPnzaaAMRW24R8F0_nlSsJQni0cGHntR027eT9_sgtwt', - value: '0.04', - body: 'Hello world from relayer' - })] - }) - })] - }); - }); -}); diff --git a/src/wallets/WalletContractV5.ts b/src/wallets/WalletContractV5.ts deleted file mode 100644 index c7d2ddb..0000000 --- a/src/wallets/WalletContractV5.ts +++ /dev/null @@ -1,258 +0,0 @@ -/** - * Copyright (c) Whales Corp. - * All Rights Reserved. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { - Address, - beginCell, - Cell, - Contract, - contractAddress, - ContractProvider, Dictionary, - internal, - MessageRelaxed, - OutAction, - Sender, - SendMode -} from "@ton/core"; -import { Maybe } from "../utils/maybe"; -import { createWalletTransferV5 } from "./signing/createWalletTransfer"; -import {OutActionExtended, storeWalletId, WalletId} from "./WalletV5Utils"; - - - -export type Wallet5BasicSendArgs = { - seqno: number; - sendMode?: Maybe; - timeout?: Maybe; -} - -export type SingedAuthWallet5SendArgs = Wallet5BasicSendArgs & { - secretKey: Buffer; -} - -export type ExtensionAuthWallet5SendArgs = Wallet5BasicSendArgs & { } - -export type Wallet5SendArgs = - | SingedAuthWallet5SendArgs - | ExtensionAuthWallet5SendArgs - - -export class WalletContractV5 implements Contract { - - static opCodes = { - auth_extension: 0x6578746e, - auth_signed: 0x7369676e - } - - static create(args: { - walletId?: Partial, - publicKey: Buffer - }) { - const walletId = { - networkGlobalId: args.walletId?.networkGlobalId ?? -239, - workChain: args?.walletId?.workChain ?? 0, - subwalletNumber: args?.walletId?.subwalletNumber ?? 0, - walletVersion: args?.walletId?.walletVersion ?? 'v5' - } - return new WalletContractV5(walletId, args.publicKey); - } - - readonly address: Address; - readonly init: { data: Cell, code: Cell }; - - private constructor( - readonly walletId: WalletId, - readonly publicKey: Buffer - ) { - this.walletId = walletId; - - // Build initial code and data - let code = Cell.fromBoc(Buffer.from('te6cckEBAQEAIwAIQgLND3fEdsoVqej99mmdJbaOAOcmH9K3vkNG64R7FPAsl9kimVw=', 'base64'))[0]; - let data = beginCell() - .storeUint(0, 32) // Seqno - .store(storeWalletId(this.walletId)) - .storeBuffer(this.publicKey) - .storeBit(0) // Empty plugins dict - .endCell(); - this.init = { code, data }; - this.address = contractAddress(this.walletId.workChain, { code, data }); - } - - /** - * Get Wallet Balance - */ - async getBalance(provider: ContractProvider) { - let state = await provider.getState(); - return state.balance; - } - - /** - * Get Wallet Seqno - */ - async getSeqno(provider: ContractProvider) { - let state = await provider.getState(); - if (state.state.type === 'active') { - let res = await provider.get('seqno', []); - return res.stack.readNumber(); - } else { - return 0; - } - } - - /** - * Get Wallet Extensions - */ - async getExtensions(provider: ContractProvider) { - let state = await provider.getState(); - if (state.state.type === 'active') { - const result = await provider.get('get_extensions', []); - return result.stack.readCellOpt(); - } else { - return null; - } - } - - /** - * Get Wallet Extensions - */ - async getExtensionsArray(provider: ContractProvider) { - const extensions = await this.getExtensions(provider); - if (!extensions) { - return []; - } - - const dict: Dictionary = Dictionary.loadDirect( - Dictionary.Keys.BigUint(256), - Dictionary.Values.BigInt(8), - extensions - ); - - return dict.keys().map(key => { - const wc = dict.get(key)!; - const addressHex = key ^ (wc + 1n); - return Address.parseRaw(`${wc}:${addressHex.toString(16)}`); - }) - } - - /** - * Send signed transfer - */ - async send(provider: ContractProvider, message: Cell) { - await provider.external(message); - } - - /** - * Sign and send transfer - */ - async sendTransfer(provider: ContractProvider, args: Wallet5SendArgs & { messages: MessageRelaxed[] }) { - const transfer = this.createTransfer(args); - await this.send(provider, transfer); - } - - /** - * Sign and send add extension request - */ - async sendAddExtension(provider: ContractProvider, args: Wallet5SendArgs & { extensionAddress: Address }) { - const request = this.createAddExtension(args); - await this.send(provider, request); - } - - /** - * Sign and send remove extension request - */ - async sendRemoveExtension(provider: ContractProvider, args: Wallet5SendArgs & { extensionAddress: Address, }) { - const request = this.createRemoveExtension(args); - await this.send(provider, request); - } - - /** - * Sign and send request - */ - async sendRequest(provider: ContractProvider, args: Wallet5SendArgs & { actions: (OutAction | OutActionExtended)[], }) { - const request = this.createRequest(args); - await this.send(provider, request); - } - - /** - * Create signed transfer - */ - createTransfer(args: Wallet5SendArgs & { messages: MessageRelaxed[] }) { - const { messages, ...rest } = args; - - const sendMode = args.sendMode ?? SendMode.PAY_GAS_SEPARATELY; - const actions: OutAction[] = messages.map(message => ({ type: 'sendMsg', mode: sendMode, outMsg: message})); - - return this.createRequest({ - ...rest, - actions - }) - } - - /** - * Create signed add extension request - */ - createAddExtension(args: Wallet5SendArgs & { extensionAddress: Address, }) { - const { extensionAddress, ...rest } = args; - return this.createRequest({ - actions: [{ - type: 'addExtension', - address: extensionAddress - }], - ...rest - }) - } - - /** - * Create signed remove extension request - */ - createRemoveExtension(args: Wallet5SendArgs & { extensionAddress: Address, }) { - const { extensionAddress, ...rest } = args; - return this.createRequest({ - actions: [{ - type: 'removeExtension', - address: extensionAddress - }], - ...rest - }) - } - - /** - * Create signed request - */ - createRequest(args: Wallet5SendArgs & { actions: (OutAction | OutActionExtended)[], }) { - return createWalletTransferV5({ - ...args, - sendMode: args.sendMode ?? SendMode.PAY_GAS_SEPARATELY, - walletId: storeWalletId(this.walletId) - }) - } - - /** - * Create sender - */ - sender(provider: ContractProvider, secretKey: Buffer): Sender { - return { - send: async (args) => { - let seqno = await this.getSeqno(provider); - let transfer = this.createTransfer({ - seqno, - secretKey, - sendMode: args.sendMode, - messages: [internal({ - to: args.to, - value: args.value, - init: args.init, - body: args.body, - bounce: args.bounce - })] - }); - await this.send(provider, transfer); - } - }; - } -} diff --git a/src/wallets/WalletV5Utils.spec.ts b/src/wallets/WalletV5Utils.spec.ts deleted file mode 100644 index da45ad6..0000000 --- a/src/wallets/WalletV5Utils.spec.ts +++ /dev/null @@ -1,261 +0,0 @@ -import { - beginCell, - SendMode, - storeMessageRelaxed, - storeOutAction, - Address, - OutAction, - storeOutList, - MessageRelaxed -} from "@ton/core"; -import { - loadOutListExtended, - loadWalletId, - OutActionExtended, - storeOutActionExtended, - storeOutListExtended, - storeWalletId, - WalletId -} from "./WalletV5Utils"; - -const mockMessageRelaxed1: MessageRelaxed = { - info: { - type: 'external-out', - createdLt: 0n, - createdAt: 0, - dest: null, - src: null - }, - body: beginCell().storeUint(0,8).endCell(), - init: null -} -const mockData = beginCell().storeUint(123, 32).endCell(); -const mockAddress = Address.parseRaw('0:' + '1'.repeat(64)) - -describe('Wallet V5 utils', () => { - const outActionSetDataTag = 0x1ff8ea0b; - const outActionAddExtensionTag = 0x1c40db9f; - const outActionRemoveExtensionTag = 0x5eaef4a4; - const outActionSendMsgTag = 0x0ec3c86d; - - it('Should serialise set data action', () => { - const action = storeOutActionExtended({ - type: 'setData', - newData: mockData - }) ; - - const actual = beginCell().store(action).endCell(); - - const expected = beginCell() - .storeUint(outActionSetDataTag, 32) - .storeRef(mockData) - .endCell(); - - expect(expected.equals(actual)).toBeTruthy(); - }); - - it('Should serialise add extension action', () => { - const action = storeOutActionExtended({ - type: 'addExtension', - address: mockAddress - }) ; - - const actual = beginCell().store(action).endCell(); - - const expected = beginCell() - .storeUint(outActionAddExtensionTag, 32) - .storeAddress(mockAddress) - .endCell(); - - expect(expected.equals(actual)).toBeTruthy(); - }); - - it('Should serialise remove extension action', () => { - const action = storeOutActionExtended({ - type: 'removeExtension', - address: mockAddress - }) ; - - const actual = beginCell().store(action).endCell(); - - const expected = beginCell() - .storeUint(outActionRemoveExtensionTag, 32) - .storeAddress(mockAddress) - .endCell(); - - expect(expected.equals(actual)).toBeTruthy(); - }); - - it('Should serialise wallet id', () => { - const walletId: WalletId = { - walletVersion: 'v5', - networkGlobalId: -239, - workChain: 0, - subwalletNumber: 0 - } - - const actual = beginCell().store(storeWalletId(walletId)).endCell(); - - const expected = beginCell() - .storeInt(walletId.networkGlobalId, 32) - .storeInt(walletId.workChain, 8) - .storeUint(0, 8) - .storeUint(walletId.subwalletNumber, 32) - .endCell(); - - expect(expected.equals(actual)).toBeTruthy(); - }); - - it('Should deserialise wallet id', () => { - const expected: WalletId = { - walletVersion: 'v5', - networkGlobalId: -239, - workChain: 0, - subwalletNumber: 0 - } - - const actual = loadWalletId(beginCell() - .storeInt(expected.networkGlobalId, 32) - .storeInt(expected.workChain, 8) - .storeUint(0, 8) - .storeUint(expected.subwalletNumber, 32) - .endCell().beginParse()); - - - expect(expected).toEqual(actual); - }); - - it('Should serialise wallet id', () => { - const walletId: WalletId = { - walletVersion: 'v5', - networkGlobalId: -3, - workChain: -1, - subwalletNumber: 1234 - } - - const actual = beginCell().store(storeWalletId(walletId)).endCell(); - - const expected = beginCell() - .storeInt(walletId.networkGlobalId, 32) - .storeInt(walletId.workChain, 8) - .storeUint(0, 8) - .storeUint(walletId.subwalletNumber, 32) - .endCell(); - - expect(expected.equals(actual)).toBeTruthy(); - }); - - it('Should deserialise wallet id', () => { - const expected: WalletId = { - walletVersion: 'v5', - networkGlobalId: -239, - workChain: -1, - subwalletNumber: 1 - } - - const actual = loadWalletId(beginCell() - .storeInt(expected.networkGlobalId, 32) - .storeInt(expected.workChain, 8) - .storeUint(0, 8) - .storeUint(expected.subwalletNumber, 32) - .endCell().beginParse()); - - - expect(expected).toEqual(actual); - }); - - it('Should serialize extended out list', () => { - const sendMode1 = SendMode.PAY_GAS_SEPARATELY; - - const actions: (OutActionExtended | OutAction)[] = [ - { - type: 'addExtension', - address: mockAddress - }, - { - type: 'sendMsg', - mode: sendMode1, - outMsg: mockMessageRelaxed1 - } - ] - - const actual = beginCell().store(storeOutListExtended(actions)).endCell(); - - const expected = - beginCell() - .storeUint(1, 1) - .store(storeOutActionExtended(actions[0] as OutActionExtended)) - .storeRef( - beginCell() - .storeUint(0, 1) - .storeRef( - beginCell() - .storeRef(beginCell().endCell()) - .storeUint(outActionSendMsgTag, 32) - .storeUint(sendMode1, 8) - .storeRef(beginCell().store(storeMessageRelaxed(mockMessageRelaxed1)).endCell()) - .endCell() - ) - .endCell() - ) - .endCell() - - - - expect(actual.equals(expected)).toBeTruthy(); - }); - - it('Should deserialize extended out list', () => { - const sendMode1 = SendMode.PAY_GAS_SEPARATELY; - - const expected: (OutActionExtended | OutAction)[] = [ - { - type: 'addExtension', - address: mockAddress - }, - { - type: 'sendMsg', - mode: sendMode1, - outMsg: mockMessageRelaxed1 - } - ] - - const serialized = - beginCell() - .storeUint(1, 1) - .store(storeOutActionExtended(expected[0] as OutActionExtended)) - .storeRef( - beginCell() - .storeUint(0, 1) - .storeRef( - beginCell() - .storeRef(beginCell().endCell()) - .storeUint(outActionSendMsgTag, 32) - .storeUint(sendMode1, 8) - .storeRef(beginCell().store(storeMessageRelaxed(mockMessageRelaxed1)).endCell()) - .endCell() - ) - .endCell() - ) - .endCell() - - const actual = loadOutListExtended(serialized.beginParse()) - - expect(expected.length).toEqual(actual.length); - expected.forEach((item1, index) => { - const item2 = actual[index]; - expect(item1.type).toEqual(item2.type); - - if (item1.type === 'sendMsg' && item2.type === 'sendMsg') { - expect(item1.mode).toEqual(item2.mode); - expect(item1.outMsg.body.equals(item2.outMsg.body)).toBeTruthy(); - expect(item1.outMsg.info).toEqual(item2.outMsg.info); - expect(item1.outMsg.init).toEqual(item2.outMsg.init); - } - - if (item1.type === 'addExtension' && item2.type === 'addExtension') { - expect(item1.address.equals(item2.address)).toBeTruthy(); - } - }) - }); -}) diff --git a/src/wallets/WalletV5Utils.ts b/src/wallets/WalletV5Utils.ts deleted file mode 100644 index 8abdb6b..0000000 --- a/src/wallets/WalletV5Utils.ts +++ /dev/null @@ -1,179 +0,0 @@ -import { - Address, - beginCell, - BitReader, BitString, - Builder, - Cell, - loadOutList, - OutAction, - Slice, - storeOutList -} from '@ton/core'; - -export interface OutActionSetData { - type: 'setData'; - newData: Cell; -} - -export interface OutActionAddExtension { - type: 'addExtension'; - address: Address; -} - -export interface OutActionRemoveExtension { - type: 'removeExtension'; - address: Address; -} - -export type OutActionExtended = OutActionSetData | OutActionAddExtension | OutActionRemoveExtension; - -const outActionSetDataTag = 0x1ff8ea0b; -function storeOutActionSetData(action: OutActionSetData) { - return (builder: Builder) => { - builder.storeUint(outActionSetDataTag, 32).storeRef(action.newData) - } -} - -const outActionAddExtensionTag = 0x1c40db9f; -function storeOutActionAddExtension(action: OutActionAddExtension) { - return (builder: Builder) => { - builder.storeUint(outActionAddExtensionTag, 32).storeAddress(action.address) - } -} - -const outActionRemoveExtensionTag = 0x5eaef4a4; -function storeOutActionRemoveExtension(action: OutActionRemoveExtension) { - return (builder: Builder) => { - builder.storeUint(outActionRemoveExtensionTag, 32).storeAddress(action.address) - } -} - -export function storeOutActionExtended(action: OutActionExtended) { - if (action.type === 'setData') { - return storeOutActionSetData(action); - } - - if (action.type === 'addExtension') { - return storeOutActionAddExtension(action); - } - - return storeOutActionRemoveExtension(action); -} - -export function loadOutActionExtended(slice: Slice): OutActionExtended { - const tag = slice.loadUint(32); - - switch (tag) { - case outActionSetDataTag: - return { - type: 'setData', - newData: slice.loadRef() - } - case outActionAddExtensionTag: - return { - type: 'addExtension', - address: slice.loadAddress() - } - case outActionRemoveExtensionTag: - return { - type: 'removeExtension', - address: slice.loadAddress() - } - default: - throw new Error(`Unknown extended out action tag 0x${tag.toString(16)}`); - } -} - -export function isOutActionExtended(action: OutAction | OutActionExtended): action is OutActionExtended { - return ( - action.type === 'setData' || action.type === 'addExtension' || action.type === 'removeExtension' - ); -} - -export function storeOutListExtended(actions: (OutActionExtended | OutAction)[]) { - const [action, ...rest] = actions; - - if (!action || !isOutActionExtended(action)) { - if (actions.some(isOutActionExtended)) { - throw new Error("Can't serialize actions list: all extended actions must be placed before out actions"); - } - - return (builder: Builder) => { - builder - .storeUint(0, 1) - .storeRef(beginCell().store(storeOutList(actions as OutAction[])).endCell()) - } - } - - return (builder: Builder) => { - builder.storeUint(1, 1) - .store(storeOutActionExtended(action)) - .storeRef(beginCell().store(storeOutListExtended(rest)).endCell()) - } -} - -export function loadOutListExtended(slice: Slice): (OutActionExtended | OutAction)[] { - const actions: (OutActionExtended | OutAction)[] = []; - - while (slice.loadUint(1)) { - const action = loadOutActionExtended(slice); - actions.push(action); - - slice = slice.loadRef().beginParse(); - } - - return actions.concat(loadOutList(slice.loadRef().beginParse())); -} - -export interface WalletId { - readonly walletVersion: 'v5'; - - /** - * -239 is mainnet, -3 is testnet - */ - readonly networkGlobalId: number; - - readonly workChain: number; - - readonly subwalletNumber: number; -} - -const walletVersionsSerialisation: Record = { - v5: 0 -}; -export function loadWalletId(value: bigint | Buffer | Slice): WalletId { - const bitReader = new BitReader( - new BitString( - typeof value === 'bigint' ? - Buffer.from(value.toString(16), 'hex') : - value instanceof Slice ? value.loadBuffer(10) : value, - 0, - 80 - ) - ); - const networkGlobalId = bitReader.loadInt(32); - const workChain = bitReader.loadInt(8); - const walletVersionRaw = bitReader.loadUint(8); - const subwalletNumber = bitReader.loadUint(32); - - const walletVersion = Object.entries(walletVersionsSerialisation).find( - ([_, value]) => value === walletVersionRaw - )?.[0] as WalletId['walletVersion'] | undefined; - - if (walletVersion === undefined) { - throw new Error( - `Can't deserialize walletId: unknown wallet version ${walletVersionRaw}` - ); - } - - return { networkGlobalId, workChain, walletVersion, subwalletNumber } -} - -export function storeWalletId(walletId: WalletId) { - return (builder: Builder) => { - builder.storeInt(walletId.networkGlobalId, 32); - builder.storeInt(walletId.workChain, 8); - builder.storeUint(walletVersionsSerialisation[walletId.walletVersion], 8); - builder.storeUint(walletId.subwalletNumber, 32); - } -} diff --git a/src/wallets/signing/createWalletTransfer.ts b/src/wallets/signing/createWalletTransfer.ts index 2bb900e..4d48008 100644 --- a/src/wallets/signing/createWalletTransfer.ts +++ b/src/wallets/signing/createWalletTransfer.ts @@ -9,14 +9,6 @@ import { beginCell, MessageRelaxed, storeMessageRelaxed, OutAction, Builder } from "@ton/core"; import { sign } from "@ton/crypto"; import { Maybe } from "../../utils/maybe"; -import { - Wallet5SendArgs, - WalletContractV5 -} from "../WalletContractV5"; -import { - OutActionExtended, - storeOutListExtended -} from "../WalletV5Utils"; export function createWalletTransferV1(args: { seqno: number, sendMode: number, message: Maybe, secretKey: Buffer }) { @@ -157,37 +149,3 @@ export function createWalletTransferV4(args: { return body; } - -export function createWalletTransferV5(args: Wallet5SendArgs & { actions: (OutAction | OutActionExtended)[], walletId: (builder: Builder) => void }) { - // Check number of actions - if (args.actions.length > 255) { - throw Error("Maximum number of OutActions in a single request is 255"); - } - - if (!('secretKey' in args) || !args.secretKey) { - return beginCell() - .storeUint(WalletContractV5.opCodes.auth_extension, 32) - .store(storeOutListExtended(args.actions)) - .endCell(); - } - - const message = beginCell().store(args.walletId); - if (args.seqno === 0) { - for (let i = 0; i < 32; i++) { - message.storeBit(1); - } - } else { - message.storeUint(args.timeout || Math.floor(Date.now() / 1e3) + 60, 32); // Default timeout: 60 seconds - } - - message.storeUint(args.seqno, 32).store(storeOutListExtended(args.actions)); - - // Sign message - const signature = sign(message.endCell().hash(), args.secretKey); - - return beginCell() - .storeUint(WalletContractV5.opCodes.auth_signed, 32) - .storeBuffer(signature) - .storeBuilder(message) - .endCell(); -}