Skip to content

Commit

Permalink
Add wallet version to signer
Browse files Browse the repository at this point in the history
  • Loading branch information
KuznetsovNikita committed May 24, 2024
1 parent 5a3795a commit 567f338
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
24 changes: 21 additions & 3 deletions packages/core/src/service/signerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,39 @@ export const parseSignerSignature = (payload: string): Buffer => {
return Buffer.from(sign, 'hex');
};

export const createTransferQr = (publicKey: string, boc: string) => {
const walletVersionText = (version: WalletVersion) => {
switch (version) {
case WalletVersion.V3R1:
return 'v3r1';
case WalletVersion.V3R2:
return 'v3r2';
case WalletVersion.V4R2:
return 'v4r2';
case WalletVersion.W5:
return 'v5r1';
default:
return String(version);
}
};

export const createTransferQr = (publicKey: string, version: WalletVersion, boc: string) => {
const body = Buffer.from(boc, 'base64').toString('hex');
return `tonsign://v1/?network=ton&pk=${publicKey}&body=${body}`;
return `tonsign://v1/?network=ton&pk=${publicKey}&body=${body}&v=${walletVersionText(version)}`;
};

export const storeTransactionAndCreateDeepLink = async (
sdk: IAppSdk,
publicKey: string,
version: WalletVersion,
messageBase64: string
) => {
await sdk.storage.set(AppKey.SIGNER_MESSAGE, messageBase64);

const body = Buffer.from(messageBase64, 'base64').toString('hex');
const back = encodeURIComponent('https://wallet.tonkeeper.com/');
return `tonsign://v1/?network=ton&pk=${publicKey}&body=${body}&return=${back}`;
return `tonsign://v1/?network=ton&pk=${publicKey}&body=${body}&v=${walletVersionText(
version
)}&return=${back}`;
};

export const publishSignerMessage = async (
Expand Down
2 changes: 1 addition & 1 deletion packages/uikit/src/components/PairSignerNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const SignerContent: FC<{
const openScanner = useScanner(null, onSubmit);

const message = useMemo(() => {
return createTransferQr(wallet.publicKey, boc);
return createTransferQr(wallet.publicKey, wallet.active.version, boc);
}, [wallet, boc]);

return (
Expand Down
3 changes: 3 additions & 0 deletions packages/uikit/src/state/mnemonic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
parseSignerSignature,
storeTransactionAndCreateDeepLink
} from '@tonkeeper/core/dist/service/signerService';
import { getWalletStateOrDie } from '@tonkeeper/core/dist/service/wallet/storeService';
import { getWalletAuthState } from '@tonkeeper/core/dist/service/walletService';
import { delay } from '@tonkeeper/core/dist/utils/common';
import nacl from 'tweetnacl';
Expand Down Expand Up @@ -77,9 +78,11 @@ export const getSigner = async (
}
case 'signer-deeplink': {
const callback = async (message: Cell) => {
const wallet = await getWalletStateOrDie(sdk.storage, publicKey);
const deeplink = await storeTransactionAndCreateDeepLink(
sdk,
publicKey,
wallet.active.version,
message.toBoc({ idx: false }).toString('base64')
);

Expand Down

0 comments on commit 567f338

Please sign in to comment.