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