@chainberry/berry-signer 1.0.2 → 1.0.4

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.
Files changed (2) hide show
  1. package/README.md +35 -36
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # BerrySigner
2
2
 
3
- Pure signing library for multiple blockchain networks. No network calls — takes an unsigned transaction prepared elsewhere and signs it locally with a private key. Designed to run on the frontend (mobile wallet, browser extension) while the unsigned transaction is prepared on the backend.
3
+ Pure signing library for multiple blockchain networks. No network calls — takes an unsigned transaction and signs it with a private key. Can run anywhere: frontend, mobile wallet, browser extension, or backend.
4
4
 
5
5
  ## Installation
6
6
 
@@ -22,7 +22,7 @@ npm install berry-signer
22
22
 
23
23
  ## Usage
24
24
 
25
- Each function takes a private key and an unsigned transaction prepared by the backend, and returns a signed transaction ready for broadcast.
25
+ Each function takes a private key and an unsigned transaction prepared elsewhere, and returns a signed transaction ready for broadcast.
26
26
 
27
27
  ### EVM (ETH, BNB, POL, AVAX, ARB, OP, BASE, SONIC)
28
28
 
@@ -94,16 +94,19 @@ const { bocBase64, txHash } = signTonTransaction(privateKeyHex, {
94
94
 
95
95
  ## Full Example — EVM
96
96
 
97
- This example shows the complete flow: backend prepares the unsigned transaction, frontend signs it, backend broadcasts it.
97
+ The client prepares the unsigned transaction, signs it locally, then sends the signed tx to the server for broadcast.
98
98
 
99
- **Backend (Node.js) — prepare unsigned tx:**
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
- // Send unsignedTx to frontend
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
- // Send signedTx back to backend
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
- **Backend — broadcast:**
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
- **Backendfetch seqno:**
135
+ **Clientprepare + sign:**
137
136
  ```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
- );
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
- // Send bocBase64 and txHash back to backend
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
- **Backend — broadcast:**
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 split between signing and broadcasting allows the private key to stay on the client:
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
- Backend Frontend (BerrySigner) Backend
177
-
178
- │── prepare unsigned tx ──────────────>│ │
179
- │── sign with key
180
- │<─────────────────────── signed tx ───│
181
-
182
- │── broadcast to network ──────────────────────────────────────>│
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.2",
3
+ "version": "1.0.4",
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"],