@chainberry/berry-signer 1.0.1 → 1.0.3
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 +83 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,18 +92,93 @@ 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
|
+
The client prepares the unsigned transaction, signs it locally, then sends the signed tx to the server for broadcast.
|
|
98
|
+
|
|
99
|
+
**Client — prepare + sign:**
|
|
100
|
+
```ts
|
|
101
|
+
import { ethers } from "ethers";
|
|
102
|
+
import { signEvmTransaction } from "@chainberry/berry-signer";
|
|
103
|
+
|
|
104
|
+
// 1. Fetch network data
|
|
105
|
+
const provider = new ethers.JsonRpcProvider("https://arb1.arbitrum.io/rpc");
|
|
106
|
+
const feeData = await provider.getFeeData();
|
|
107
|
+
const nonce = await provider.getTransactionCount(fromAddress, "latest");
|
|
108
|
+
|
|
109
|
+
// 2. Build unsigned tx
|
|
110
|
+
const unsignedTx = {
|
|
111
|
+
to: toAddress,
|
|
112
|
+
chainId: 42161, // Arbitrum
|
|
113
|
+
nonce,
|
|
114
|
+
gasLimit: "21000",
|
|
115
|
+
maxFeePerGas: feeData.maxFeePerGas.toString(),
|
|
116
|
+
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas.toString(),
|
|
117
|
+
value: ethers.parseEther("0.01").toString(),
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// 3. Sign locally — private key never leaves the client
|
|
121
|
+
const signedTx = await signEvmTransaction(privateKeyHex, unsignedTx);
|
|
122
|
+
|
|
123
|
+
// 4. Send signed tx to server for broadcast
|
|
124
|
+
await fetch("/api/broadcast", { method: "POST", body: JSON.stringify({ signedTx }) });
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Server — broadcast only:**
|
|
128
|
+
```ts
|
|
129
|
+
const tx = await provider.broadcastTransaction(signedTx);
|
|
130
|
+
console.log("txHash:", tx.hash);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Full Example — TON
|
|
134
|
+
|
|
135
|
+
**Client — prepare + sign:**
|
|
136
|
+
```ts
|
|
137
|
+
import { signTonTransaction } from "@chainberry/berry-signer";
|
|
138
|
+
|
|
139
|
+
// 1. Fetch seqno from network
|
|
140
|
+
const response = await fetch("https://toncenter.com/api/v2/runGetMethod", {
|
|
141
|
+
method: "POST",
|
|
142
|
+
body: JSON.stringify({ address: walletAddress, method: "seqno", stack: [] }),
|
|
143
|
+
});
|
|
144
|
+
const data = await response.json();
|
|
145
|
+
const seqno = data.result?.exit_code === 0
|
|
146
|
+
? parseInt(data.result.stack[0][1], 16)
|
|
147
|
+
: 0; // 0 = wallet not yet deployed, init will be included automatically
|
|
148
|
+
|
|
149
|
+
// 2. Sign locally
|
|
150
|
+
const { bocBase64, txHash } = signTonTransaction(privateKeyHex, {
|
|
151
|
+
toAddress: "UQA...",
|
|
152
|
+
amount: "1.5",
|
|
153
|
+
seqno,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// 3. Send to server for broadcast
|
|
157
|
+
await fetch("/api/broadcast", { method: "POST", body: JSON.stringify({ bocBase64, txHash }) });
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Server — broadcast only:**
|
|
161
|
+
```ts
|
|
162
|
+
await fetch("https://toncenter.com/api/v2/sendBoc", {
|
|
163
|
+
method: "POST",
|
|
164
|
+
body: JSON.stringify({ boc: bocBase64 }),
|
|
165
|
+
});
|
|
166
|
+
console.log("txHash:", txHash);
|
|
167
|
+
```
|
|
168
|
+
|
|
95
169
|
## Design
|
|
96
170
|
|
|
97
|
-
The
|
|
171
|
+
The private key never leaves the client. The client prepares and signs the transaction locally, then sends only the signed tx to the server for broadcast.
|
|
98
172
|
|
|
99
173
|
```
|
|
100
|
-
|
|
101
|
-
│
|
|
102
|
-
│──
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
│
|
|
106
|
-
│──
|
|
174
|
+
Client (BerrySigner) Server
|
|
175
|
+
│ │
|
|
176
|
+
│── fetch nonce/fee/seqno from network ───────>│ (or directly from RPC)
|
|
177
|
+
│── build unsigned tx │
|
|
178
|
+
│── sign with private key (stays on client) │
|
|
179
|
+
│ │
|
|
180
|
+
│── send signed tx ───────────────────────────>│
|
|
181
|
+
│ │── broadcast to network
|
|
107
182
|
```
|
|
108
183
|
|
|
109
184
|
## Private Key Format
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainberry/berry-signer",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
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"],
|