46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
/**
|
|
* Step 7 — Wallet API: serialize/deserialize for JSON-RPC
|
|
* Target: wallet-api packages/core/src/families/ethereum/serializer.ts
|
|
*
|
|
* Ethereum family already has serialization; ensure chainId is preserved.
|
|
* When adding a new family, implement serializeTransaction/deserializeTransaction
|
|
* for the new type and add to the union in packages/core/src/families/serializer.ts.
|
|
*/
|
|
|
|
import type { RawEthereumTransaction } from "./types.ethereum-chain138";
|
|
import type { EthereumTransaction } from "./types.ethereum-chain138";
|
|
|
|
export function serializeEthereumTransaction(
|
|
tx: EthereumTransaction
|
|
): RawEthereumTransaction {
|
|
return {
|
|
family: "ethereum",
|
|
amount: tx.amount,
|
|
recipient: tx.recipient,
|
|
gasPrice: tx.gasPrice,
|
|
maxFeePerGas: tx.maxFeePerGas,
|
|
maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
|
|
gasLimit: tx.gasLimit,
|
|
data: tx.data,
|
|
nonce: tx.nonce,
|
|
chainId: tx.chainId,
|
|
};
|
|
}
|
|
|
|
export function deserializeEthereumTransaction(
|
|
raw: RawEthereumTransaction
|
|
): EthereumTransaction {
|
|
return {
|
|
family: "ethereum",
|
|
amount: raw.amount,
|
|
recipient: raw.recipient,
|
|
gasPrice: raw.gasPrice,
|
|
maxFeePerGas: raw.maxFeePerGas,
|
|
maxPriorityFeePerGas: raw.maxPriorityFeePerGas,
|
|
gasLimit: raw.gasLimit,
|
|
data: raw.data,
|
|
nonce: raw.nonce,
|
|
chainId: raw.chainId,
|
|
};
|
|
}
|