@tonconnect/protocol
Advanced tools
Comparing version 0.0.4 to 0.0.5
{ | ||
"name": "@tonconnect/protocol", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
# TON Connect protocol models | ||
⚠️ Package is work in progress right now. | ||
⚠️ TonConnect is currently in beta testing. Use it at your own risk. | ||
ℹ️ If you want to integrate TonConnect to your dApp, you should use [@tonconnect/sdk](https://www.npmjs.com/package/@tonconnect/sdk) | ||
## Summary | ||
Package contains protocol requests, responses and event models and encoding, decoding functions. | ||
You can use it to integrate TonConnect to your wallet app (written with TypeScript). | ||
## Get started | ||
### Install package | ||
`npm i @tonconnect/protocol` | ||
### Use protocol models in your app | ||
```ts | ||
import { AppRequest, RpcMethod, WalletResponse } from '@tonconnect/protocol'; | ||
function myWalletAppRequestsHandler<T extends RpcMethod>(request: AppRequest<T>): Promise<WalletResponse<T>> { | ||
// handle request, ask the user for a confirmation and return WalletResponse | ||
} | ||
``` | ||
### Use protocol cryptography in your app | ||
```ts | ||
import { SessionCrypto, WalletMessage, Base64, hexToByteArray } from '@tonconnect/protocol'; | ||
function encodeIncommingHTTPBridgeRequest(encryptedMessage: string, from: string): WalletMessage { | ||
const sessionCrypto = new SessionCrypto(yourStoredSessionReypair); | ||
const decryptedMessage = | ||
sessionCrypto.decrypt( | ||
Base64.decode(bridgeIncomingMessage.message).toUint8Array(), | ||
hexToByteArray(bridgeIncomingMessage.from) | ||
); | ||
return JSON.parse(decryptedMessage); | ||
} | ||
``` |
32062
45