Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions requests-responses.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The manifest and all the links in it must be publicly accessible from the intern

### Initiating connection

Apps request message is **InitialRequest**.
App's request message is **InitialRequest**.

```tsx
type ConnectRequest = {
Expand All @@ -47,6 +47,7 @@ type ConnectItem = TonAddressItem | TonProofItem | ...;

type TonAddressItem = {
name: "ton_addr";
network?: NETWORK_ID; // TON network global_id (e.g. '-239' mainnet, '-3' testnet, or any other id)
}
type TonProofItem = {
name: "ton_proof";
Expand Down Expand Up @@ -106,7 +107,7 @@ type ConnectItemReply = TonAddressItemReply | TonProofItemReply ...;
type TonAddressItemReply = {
name: "ton_addr";
address: string; // TON address raw (`0:<hex>`)
network: NETWORK; // network global_id
network: NETWORK_ID; // TON network global_id
publicKey: string; // HEX string without 0x
walletStateInit: string; // Base64 (not url safe) encoded stateinit cell for the wallet contract
}
Expand Down Expand Up @@ -138,6 +139,9 @@ enum NETWORK {
MAINNET = '-239',
TESTNET = '-3'
}

type NETWORK_ID = NETWORK | string;

```

**Connect event error codes:**
Expand Down Expand Up @@ -307,7 +311,7 @@ interface SendTransactionRequest {
Where `<transaction-payload>` is JSON string with following properties:

* `valid_until` (integer, optional): unix timestamp. after th moment transaction will be invalid.
* `network` (NETWORK, optional): The network (mainnet or testnet) where DApp intends to send the transaction. If not set, the transaction is sent to the network currently set in the wallet, but this is not safe and DApp should always strive to set the network. If the `network` parameter is set, but the wallet has a different network set, the wallet should show an alert and DO NOT ALLOW TO SEND this transaction.
* `network` (NETWORK_ID, optional): The TON network global_id where DApp intends to send the transaction (e.g. '-239' for mainnet, '-3' for testnet, or any other TON network id). If not set, the transaction is sent to the network currently set in the wallet, but this is not safe and DApp should always strive to set the network. If the `network` parameter is set, but the wallet has a different network set, the wallet should show an alert and DO NOT ALLOW TO SEND this transaction.
* `from` (string in raw or friendly format, optional) - The sender address from which DApp intends to send the transaction. If not set, wallet allows user to select the sender's address at the moment of transaction approval. If `from` parameter is set, the wallet should DO NOT ALLOW user to select the sender's address; If sending from the specified address is impossible, the wallet should show an alert and DO NOT ALLOW TO SEND this transaction.
* `messages` (array of messages): 1 to wallet's `maxMessages` outgoing messages from the wallet contract to other accounts. All messages MUST be sent within a single external message and processed by the wallet contract in the provided order, however **the wallet cannot guarantee that messages will be delivered and executed in the same order by the recipient contracts**.

Expand Down Expand Up @@ -353,7 +357,7 @@ To generate both address types using `@ton/core`:
```json5
{
"valid_until": 1658253458,
"network": "-239", // enum NETWORK { MAINNET = '-239', TESTNET = '-3'}
"network": "-239", // NETWORK_ID (e.g. '-239' mainnet, '-3' testnet, or any other id)
"from": "0:348bcf827469c5fc38541c77fdd91d4e347eac200f6f2d9fd62dc08885f0415f",
"messages": [
{
Expand Down Expand Up @@ -418,19 +422,19 @@ Where `<sign-data-payload>` is JSON string with one of the 3 types of payload:

- **Text**. JSON object with following properties:
- **type** (string): 'text'
- **network** (NETWORK, optional): The network (mainnet or testnet) where DApp intends to sign data. If not set, the data is signed with the network currently set in the wallet, but this is not safe and DApp should always strive to set the network. If the `network` parameter is set, but the wallet has a different network set, the wallet should show an alert and DO NOT ALLOW TO SIGN data.
- **network** (NETWORK_ID, optional): The TON network global_id where DApp intends to sign data (e.g. '-239' for mainnet, '-3' for testnet, or any other TON network id). If not set, the data is signed with the network currently set in the wallet, but this is not safe and DApp should always strive to set the network. If the `network` parameter is set, but the wallet has a different network set, the wallet should show an alert and DO NOT ALLOW TO SIGN data.
- **from** (string in raw or friendly format, optional): The signer address from which DApp intends to sign data. If not set, wallet allows user to select the signer's address at the moment of signing data. If `from` parameter is set, the wallet should DO NOT ALLOW user to select the signer's address; If signing from the specified address is impossible, the wallet should show an alert and DO NOT ALLOW TO SIGN data.
- **text** (string): arbitrary UTF-8 text to sign.

- **Binary**. JSON object with following properties:
- **type** (string): 'binary'
- **network** (NETWORK, optional): The network (mainnet or testnet) where DApp intends to sign data. If not set, the data is signed with the network currently set in the wallet, but this is not safe and DApp should always strive to set the network. If the `network` parameter is set, but the wallet has a different network set, the wallet should show an alert and DO NOT ALLOW TO SIGN data.
- **network** (NETWORK_ID, optional): The TON network global_id where DApp intends to sign data (e.g. '-239' for mainnet, '-3' for testnet, or any other TON network id). If not set, the data is signed with the network currently set in the wallet, but this is not safe and DApp should always strive to set the network. If the `network` parameter is set, but the wallet has a different network set, the wallet should show an alert and DO NOT ALLOW TO SIGN data.
- **from** (string in raw or friendly format, optional): The signer address from which DApp intends to sign data. If not set, wallet allows user to select the signer's address at the moment of signing data. If `from` parameter is set, the wallet should DO NOT ALLOW user to select the signer's address; If signing from the specified address is impossible, the wallet should show an alert and DO NOT ALLOW TO SIGN data.
- **bytes** (string): base64 (not url safe) encoded arbitrary bytes array to sign.

- **Cell**. JSON object with following properties:
- **type** (string): 'cell'
- **network** (NETWORK, optional): The network (mainnet or testnet) where DApp intends to sign data. If not set, the data is signed with the network currently set in the wallet, but this is not safe and DApp should always strive to set the network. If the `network` parameter is set, but the wallet has a different network set, the wallet should show an alert and DO NOT ALLOW TO SIGN data.
- **network** (NETWORK_ID, optional): The TON network global_id where DApp intends to sign data (e.g. '-239' for mainnet, '-3' for testnet, or any other TON network id). If not set, the data is signed with the network currently set in the wallet, but this is not safe and DApp should always strive to set the network. If the `network` parameter is set, but the wallet has a different network set, the wallet should show an alert and DO NOT ALLOW TO SIGN data.
- **from** (string in raw or friendly format, optional): The signer address from which DApp intends to sign data. If not set, wallet allows user to select the signer's address at the moment of signing data. If `from` parameter is set, the wallet should DO NOT ALLOW user to select the signer's address; If signing from the specified address is impossible, the wallet should show an alert and DO NOT ALLOW TO SIGN data.
- **schema** (string): TL-B schema of the cell payload as an UTF-8 string.
*If the schema contains several type definitions, the **last** declared type is treated as the root during serialization and deserialization.*
Expand All @@ -442,7 +446,7 @@ Where `<sign-data-payload>` is JSON string with one of the 3 types of payload:
{
"type": "text",
"text": "Confirm new 2fa number:\n+1 234 567 8901",
"network": "-239", // enum NETWORK { MAINNET = '-239', TESTNET = '-3'}
"network": "-239", // NETWORK_ID (e.g. '-239' mainnet, '-3' testnet, or any other id)
"from": "0:348bcf827469c5fc38541c77fdd91d4e347eac200f6f2d9fd62dc08885f0415f"
}
```
Expand All @@ -451,7 +455,7 @@ Where `<sign-data-payload>` is JSON string with one of the 3 types of payload:
{
"type": "binary",
"bytes": "1Z/SGh+3HFMKlVHSkN91DpcCzT4C5jzHT3sA/24C5A==",
"network": "-239", // enum NETWORK { MAINNET = '-239', TESTNET = '-3'}
"network": "-239", // NETWORK_ID (e.g. '-239' mainnet, '-3' testnet, or any other id)
"from": "0:348bcf827469c5fc38541c77fdd91d4e347eac200f6f2d9fd62dc08885f0415f"
}
```
Expand All @@ -461,7 +465,7 @@ Where `<sign-data-payload>` is JSON string with one of the 3 types of payload:
"type": "cell",
"schema": "transfer#0f8a7ea5 query_id:uint64 amount:(VarUInteger 16) destination:MsgAddress response_destination:MsgAddress custom_payload:(Maybe ^Cell) forward_ton_amount:(VarUInteger 16) forward_payload:(Either Cell ^Cell) = InternalMsgBody;",
"cell": "te6ccgEBAQEAVwAAqg+KfqVUbeTvKqB4h0AcnDgIAZucsOi6TLrfP6FcuPKEeTI6oB3fF/NBjyqtdov/KtutACCLqvfmyV9kH+Pyo5lcsrJzJDzjBJK6fd+ZnbFQe4+XggI=",
"network": "-239", // enum NETWORK { MAINNET = '-239', TESTNET = '-3'}
"network": "-239", // NETWORK_ID (e.g. '-239' mainnet, '-3' testnet, or any other id)
"from": "0:348bcf827469c5fc38541c77fdd91d4e347eac200f6f2d9fd62dc08885f0415f"
}
```
Expand Down
15 changes: 7 additions & 8 deletions wallet-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

## Networks

1) **There aren't many networks.**
1) **Network IDs**

At the moment, there are only two networks - mainnet and testnet.

In the foreseeable future, the emergence of new mainnet TON-like networks is not expected. Note that the current mainnet has a built-in mechanism for alternative networks - workchains.
TON Connect protocol supports any TON network ID.
The `network` parameter accepts any TON network global_id as a string (e.g., `-239`, `-3`, or any other network ID).


2) **Hide the testnet from ordinary users.**
Expand All @@ -22,13 +21,13 @@
For the same reason there is no `NetworkChanged` or `ChainChanged` event in the Ton Connect protocol.


3) **Do not send anything if the dapp is in testnet and the wallet is in mainnet.**
3) **Network mismatch protection**

It is necessary to prevent loss of funds when dapp tries to send a transaction in testnet, and the wallet sends it in mainnet.
It is necessary to prevent loss of funds when dapp tries to send a transaction to one network (e.g., testnet), and the wallet sends it to another network (e.g., mainnet).

Dapps should explicitly indicate `network` field in `SendTransaction` request.
Dapps should explicitly indicate `network` field in `SendTransaction` and `SignData` requests.

If the `network` parameter is set, but the wallet has a different network set, the wallet should show an alert and DO NOT ALLOW TO SEND this transaction.
If the `network` parameter is set, but the wallet has a different network set, the wallet should show an alert and DO NOT ALLOW TO SEND/SIGN this transaction.

The wallet SHOULD NOT offer to switch to another network in this case.

Expand Down