@chainberry/berry-signer 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,6 +92,82 @@ const { bocBase64, txHash } = signTonTransaction(privateKeyHex, {
|
|
|
92
92
|
// txHash is the pre-computed transaction hash (needed for TON broadcast fallback)
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
+
## Full Example — EVM
|
|
96
|
+
|
|
97
|
+
This example shows the complete flow: backend prepares the unsigned transaction, frontend signs it, backend broadcasts it.
|
|
98
|
+
|
|
99
|
+
**Backend (Node.js) — prepare unsigned tx:**
|
|
100
|
+
```ts
|
|
101
|
+
import { ethers } from "ethers";
|
|
102
|
+
|
|
103
|
+
const provider = new ethers.JsonRpcProvider("https://arb1.arbitrum.io/rpc");
|
|
104
|
+
const feeData = await provider.getFeeData();
|
|
105
|
+
const nonce = await provider.getTransactionCount(fromAddress, "latest");
|
|
106
|
+
|
|
107
|
+
const unsignedTx = {
|
|
108
|
+
to: toAddress,
|
|
109
|
+
chainId: 42161, // Arbitrum
|
|
110
|
+
nonce,
|
|
111
|
+
gasLimit: "21000",
|
|
112
|
+
maxFeePerGas: feeData.maxFeePerGas.toString(),
|
|
113
|
+
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas.toString(),
|
|
114
|
+
value: ethers.parseEther("0.01").toString(),
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// Send unsignedTx to frontend
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**Frontend — sign with BerrySigner:**
|
|
121
|
+
```ts
|
|
122
|
+
import { signEvmTransaction } from "@chainberry/berry-signer";
|
|
123
|
+
|
|
124
|
+
const signedTx = await signEvmTransaction(privateKeyHex, unsignedTx);
|
|
125
|
+
// Send signedTx back to backend
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**Backend — broadcast:**
|
|
129
|
+
```ts
|
|
130
|
+
const tx = await provider.broadcastTransaction(signedTx);
|
|
131
|
+
console.log("txHash:", tx.hash);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Full Example — TON
|
|
135
|
+
|
|
136
|
+
**Backend — fetch seqno:**
|
|
137
|
+
```ts
|
|
138
|
+
const response = await fetch(
|
|
139
|
+
"https://toncenter.com/api/v2/runGetMethod",
|
|
140
|
+
{ method: "POST", body: JSON.stringify({ address: walletAddress, method: "seqno", stack: [] }) }
|
|
141
|
+
);
|
|
142
|
+
const data = await response.json();
|
|
143
|
+
const seqno = data.result?.exit_code === 0
|
|
144
|
+
? parseInt(data.result.stack[0][1], 16)
|
|
145
|
+
: 0; // 0 = wallet not yet deployed
|
|
146
|
+
|
|
147
|
+
// Send seqno to frontend
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Frontend — sign:**
|
|
151
|
+
```ts
|
|
152
|
+
import { signTonTransaction } from "@chainberry/berry-signer";
|
|
153
|
+
|
|
154
|
+
const { bocBase64, txHash } = signTonTransaction(privateKeyHex, {
|
|
155
|
+
toAddress: "UQA...",
|
|
156
|
+
amount: "1.5",
|
|
157
|
+
seqno,
|
|
158
|
+
});
|
|
159
|
+
// Send bocBase64 and txHash back to backend
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Backend — broadcast:**
|
|
163
|
+
```ts
|
|
164
|
+
await fetch("https://toncenter.com/api/v2/sendBoc", {
|
|
165
|
+
method: "POST",
|
|
166
|
+
body: JSON.stringify({ boc: bocBase64 }),
|
|
167
|
+
});
|
|
168
|
+
console.log("txHash:", txHash);
|
|
169
|
+
```
|
|
170
|
+
|
|
95
171
|
## Design
|
|
96
172
|
|
|
97
173
|
The split between signing and broadcasting allows the private key to stay on the client:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainberry/berry-signer",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"files": ["dist", "README.md"],
|
|
5
5
|
"description": "Pure signing library for multiple blockchain networks — EVM, BTC, LTC, SOL, TRX, XRP, TON",
|
|
6
6
|
"keywords": ["blockchain", "signing", "wallet", "ethereum", "bitcoin", "solana", "tron", "ton", "xrp", "litecoin"],
|