|
| 1 | +import type { RpcMethod } from '.'; |
| 2 | +import type { CaipChainId } from '../session'; |
| 3 | + |
| 4 | +/** |
| 5 | + * A TronWeb transaction in serialized base64 format. |
| 6 | + * @see https://github.com/tronprotocol/tronweb/blob/master/src/types/Transaction.ts |
| 7 | + * |
| 8 | + * To serialize a TronWeb transaction object to this format: |
| 9 | + * ```typescript |
| 10 | + * import TronWeb from 'tronweb'; |
| 11 | + * |
| 12 | + * const tronWeb = new TronWeb({ |
| 13 | + * fullHost: 'https://api.trongrid.io' |
| 14 | + * }); |
| 15 | + * |
| 16 | + * // Create your transaction |
| 17 | + * const transaction = await tronWeb.transactionBuilder.sendTrx( |
| 18 | + * 'TGehVcNhud84JDCGrNHKVz9jEAVKUpbuiv', |
| 19 | + * 1000000, |
| 20 | + * 'TJRabPrwbZy45sbavfcjinPJC18kjpRTv8' |
| 21 | + * ); |
| 22 | + * |
| 23 | + * // Serialize to base64 |
| 24 | + * const txPb = tronWeb.utils.transaction.txJsonToPb(transaction); |
| 25 | + * const base64Transaction = Buffer.from(txPb.serializeBinary()).toString('base64'); |
| 26 | + * ``` |
| 27 | + * |
| 28 | + * To deserialize back to a transaction object: |
| 29 | + * ```typescript |
| 30 | + * const txBytes = Buffer.from(base64Transaction, 'base64'); |
| 31 | + * const txPb = tronWeb.utils.transaction.txPbToTxID(txBytes); |
| 32 | + * const transaction = tronWeb.utils.transaction.txPbToJson(txPb); |
| 33 | + * ``` |
| 34 | + */ |
| 35 | +export type Base64Transaction = string; |
| 36 | + |
| 37 | +/** |
| 38 | + * A Tron address in Base58Check format, starting with 'T'. |
| 39 | + * @example "TJRabPrwbZy45sbavfcjinPJC18kjpRTv8" |
| 40 | + */ |
| 41 | +export type TronAddress = `T${string}`; |
| 42 | + |
| 43 | +/** |
| 44 | + * A signature. |
| 45 | + */ |
| 46 | +export type Signature = `${string}`; |
| 47 | + |
| 48 | +/** |
| 49 | + * Signs a plain text message. |
| 50 | + * The signature can be used to verify ownership of the account. |
| 51 | + * |
| 52 | + * @param chainId - CAIP-2 chain ID identifying the Tron network (e.g., "tron:0x2b6653dc") |
| 53 | + * @param address - The Tron address that will sign the message |
| 54 | + * @param message - The message string to be signed |
| 55 | + * @returns An object containing the hexadecimal signature of the message |
| 56 | + */ |
| 57 | +export type SignMessageMethod = RpcMethod< |
| 58 | + { |
| 59 | + chainId: CaipChainId; |
| 60 | + address: TronAddress; |
| 61 | + message: string; |
| 62 | + }, |
| 63 | + { signature: Signature } |
| 64 | +>; |
| 65 | + |
| 66 | +/** |
| 67 | + * Signs a Tron transaction. |
| 68 | + * The transaction must be provided as a base64-encoded serialized transaction string. |
| 69 | + * |
| 70 | + * @param chainId - CAIP-2 chain ID identifying the Tron network (e.g., "tron:0x2b6653dc") |
| 71 | + * @param address - The Tron address that will sign the transaction |
| 72 | + * @param transaction - The Tron transaction in serialized base64 format |
| 73 | + * @returns An object containing the hexadecimal signature of the transaction |
| 74 | + */ |
| 75 | +export type SignTransactionMethod = RpcMethod< |
| 76 | + { |
| 77 | + chainId: CaipChainId; |
| 78 | + address: TronAddress; |
| 79 | + transaction: Base64Transaction; |
| 80 | + }, |
| 81 | + { signature: Signature } |
| 82 | +>; |
| 83 | + |
| 84 | +export type TronRpc = { |
| 85 | + methods: { |
| 86 | + signMessage: SignMessageMethod; |
| 87 | + signTransaction: SignTransactionMethod; |
| 88 | + }; |
| 89 | + events: []; |
| 90 | +}; |
0 commit comments