@bronlabs/bron-ethers-signer 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.
- package/LICENSE +21 -0
- package/README.md +163 -0
- package/dist/BronSigner-CMusvgJo.d.cts +117 -0
- package/dist/BronSigner-CMusvgJo.d.ts +117 -0
- package/dist/hardhat.cjs +326 -0
- package/dist/hardhat.cjs.map +1 -0
- package/dist/hardhat.d.cts +39 -0
- package/dist/hardhat.d.ts +39 -0
- package/dist/hardhat.js +319 -0
- package/dist/hardhat.js.map +1 -0
- package/dist/index.cjs +284 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +35 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +273 -0
- package/dist/index.js.map +1 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Bron Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# @bronlabs/bron-ethers-signer
|
|
2
|
+
|
|
3
|
+
Ethers.js compatible signer for [Bron](https://bron.dev) custody platform.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @bronlabs/bron-ethers-signer ethers
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { BronSigner } from '@bronlabs/bron-ethers-signer';
|
|
15
|
+
import { ethers } from 'ethers';
|
|
16
|
+
|
|
17
|
+
// Create provider
|
|
18
|
+
const provider = new ethers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_KEY');
|
|
19
|
+
|
|
20
|
+
// Create BronSigner
|
|
21
|
+
const signer = new BronSigner({
|
|
22
|
+
provider,
|
|
23
|
+
apiKey: process.env.BRON_API_KEY!,
|
|
24
|
+
workspaceId: process.env.BRON_WORKSPACE_ID!,
|
|
25
|
+
accountId: process.env.BRON_ACCOUNT_ID!,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Get signer address
|
|
29
|
+
const address = await signer.getAddress();
|
|
30
|
+
console.log('Address:', address);
|
|
31
|
+
|
|
32
|
+
// Sign a message (EIP-191)
|
|
33
|
+
const signature = await signer.signMessage('Hello World');
|
|
34
|
+
console.log('Signature:', signature);
|
|
35
|
+
|
|
36
|
+
// Verify signature
|
|
37
|
+
const recovered = ethers.verifyMessage('Hello World', signature);
|
|
38
|
+
console.log('Recovered:', recovered);
|
|
39
|
+
|
|
40
|
+
// Sign typed data (EIP-712)
|
|
41
|
+
const domain = {
|
|
42
|
+
name: 'MyApp',
|
|
43
|
+
version: '1',
|
|
44
|
+
chainId: 1,
|
|
45
|
+
verifyingContract: '0x...',
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const types = {
|
|
49
|
+
Message: [
|
|
50
|
+
{ name: 'content', type: 'string' },
|
|
51
|
+
{ name: 'value', type: 'uint256' },
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const value = {
|
|
56
|
+
content: 'Hello',
|
|
57
|
+
value: 42,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const typedSignature = await signer.signTypedData(domain, types, value);
|
|
61
|
+
console.log('Typed Signature:', typedSignature);
|
|
62
|
+
|
|
63
|
+
// Send a transaction
|
|
64
|
+
const tx = await signer.sendTransaction({
|
|
65
|
+
to: '0x...',
|
|
66
|
+
value: ethers.parseEther('0.1'),
|
|
67
|
+
data: '0x',
|
|
68
|
+
});
|
|
69
|
+
console.log('Transaction hash:', tx.hash);
|
|
70
|
+
await tx.wait();
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Supported Networks
|
|
74
|
+
|
|
75
|
+
| Network | Chain ID |
|
|
76
|
+
|-----------|------------|
|
|
77
|
+
| Ethereum | 1 |
|
|
78
|
+
| Arbitrum | 42161 |
|
|
79
|
+
| Base | 8453 |
|
|
80
|
+
| Optimism | 10 |
|
|
81
|
+
| BNB Chain | 56 |
|
|
82
|
+
| Sepolia | 11155111 |
|
|
83
|
+
|
|
84
|
+
## API Reference
|
|
85
|
+
|
|
86
|
+
### `BronSigner`
|
|
87
|
+
|
|
88
|
+
#### Constructor
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
new BronSigner(options: BronSignerOptions)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Options:
|
|
95
|
+
- `provider` - Ethers.js provider instance
|
|
96
|
+
- `apiKey` - Bron API key
|
|
97
|
+
- `workspaceId` - Bron workspace ID
|
|
98
|
+
- `accountId` - Bron account ID
|
|
99
|
+
|
|
100
|
+
#### Methods
|
|
101
|
+
|
|
102
|
+
- `getAddress(): Promise<string>` - Get the signer's address
|
|
103
|
+
- `signMessage(message: string | Uint8Array): Promise<string>` - Sign a message (EIP-191)
|
|
104
|
+
- `signTypedData(domain, types, value): Promise<string>` - Sign typed data (EIP-712)
|
|
105
|
+
- `sendTransaction(tx): Promise<TransactionResponse>` - Send a transaction
|
|
106
|
+
- `connect(provider): BronSigner` - Connect to a different provider
|
|
107
|
+
|
|
108
|
+
### Utility Functions
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import {
|
|
112
|
+
getNetworkId,
|
|
113
|
+
getGasTokenId,
|
|
114
|
+
isChainSupported,
|
|
115
|
+
getSupportedChainIds
|
|
116
|
+
} from '@bronlabs/bron-ethers-signer';
|
|
117
|
+
|
|
118
|
+
// Get Bron network ID from chain ID
|
|
119
|
+
const networkId = getNetworkId(1); // 'ETH'
|
|
120
|
+
|
|
121
|
+
// Check if chain is supported
|
|
122
|
+
const supported = isChainSupported(42161); // true
|
|
123
|
+
|
|
124
|
+
// Get all supported chain IDs
|
|
125
|
+
const chainIds = getSupportedChainIds(); // [1, 42161, 8453, ...]
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Hardhat Integration
|
|
129
|
+
|
|
130
|
+
Simple one-liner to override `ethers.getSigners()` and `ethers.getSigner()`:
|
|
131
|
+
|
|
132
|
+
```javascript
|
|
133
|
+
// hardhat.config.js
|
|
134
|
+
require("dotenv").config();
|
|
135
|
+
const { extendHardhatWithBronSigner } = require("@bronlabs/bron-ethers-signer/hardhat");
|
|
136
|
+
|
|
137
|
+
extendHardhatWithBronSigner({
|
|
138
|
+
apiKey: process.env.BRON_API_KEY,
|
|
139
|
+
workspaceId: process.env.BRON_WORKSPACE_ID,
|
|
140
|
+
accountId: process.env.BRON_ACCOUNT_ID,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
module.exports = {
|
|
144
|
+
// ... your config
|
|
145
|
+
};
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Now all hardhat scripts using `ethers.getSigners()` will automatically use BronSigner for non-local networks.
|
|
149
|
+
|
|
150
|
+
### Options
|
|
151
|
+
|
|
152
|
+
```javascript
|
|
153
|
+
extendHardhatWithBronSigner({
|
|
154
|
+
apiKey: process.env.BRON_API_KEY,
|
|
155
|
+
workspaceId: process.env.BRON_WORKSPACE_ID,
|
|
156
|
+
accountId: process.env.BRON_ACCOUNT_ID,
|
|
157
|
+
excludeNetworks: ['hardhat', 'localhost'], // optional, these are defaults
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
|
|
163
|
+
MIT
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Provider, TypedDataField, TypedDataDomain, AbstractSigner, TransactionRequest, TransactionResponse } from 'ethers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for BronSigner
|
|
5
|
+
*/
|
|
6
|
+
interface BronSignerOptions {
|
|
7
|
+
/** Ethers.js provider instance */
|
|
8
|
+
provider: Provider;
|
|
9
|
+
/** Bron API key */
|
|
10
|
+
apiKey: string;
|
|
11
|
+
/** Bron workspace ID */
|
|
12
|
+
workspaceId: string;
|
|
13
|
+
/** Bron account ID */
|
|
14
|
+
accountId: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Network mapping configuration
|
|
18
|
+
*/
|
|
19
|
+
interface NetworkMapping {
|
|
20
|
+
/** Bron network ID */
|
|
21
|
+
networkId: string;
|
|
22
|
+
/** Bron gas token asset ID */
|
|
23
|
+
gasTokenId: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* EIP-712 typed data structure
|
|
27
|
+
*/
|
|
28
|
+
interface EIP712TypedData {
|
|
29
|
+
types: Record<string, TypedDataField[]>;
|
|
30
|
+
primaryType: string;
|
|
31
|
+
domain: TypedDataDomain;
|
|
32
|
+
message: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Bron transaction status
|
|
36
|
+
*/
|
|
37
|
+
type TransactionStatus = 'pending' | 'awaiting-approval' | 'approved' | 'signing' | 'broadcasting' | 'completed' | 'failed' | 'rejected' | 'canceled';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Ethers.js compatible signer that uses Bron custody platform for signing operations.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* import { BronSigner } from '@bronlabs/bron-ethers-signer';
|
|
45
|
+
* import { ethers } from 'ethers';
|
|
46
|
+
*
|
|
47
|
+
* const provider = new ethers.JsonRpcProvider('https://mainnet.infura.io/v3/...');
|
|
48
|
+
*
|
|
49
|
+
* const signer = new BronSigner({
|
|
50
|
+
* provider,
|
|
51
|
+
* apiKey: process.env.BRON_API_KEY!,
|
|
52
|
+
* workspaceId: process.env.BRON_WORKSPACE_ID!,
|
|
53
|
+
* accountId: process.env.BRON_ACCOUNT_ID!,
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* // Sign a message
|
|
57
|
+
* const signature = await signer.signMessage('Hello World');
|
|
58
|
+
*
|
|
59
|
+
* // Sign typed data (EIP-712)
|
|
60
|
+
* const typedSignature = await signer.signTypedData(domain, types, value);
|
|
61
|
+
*
|
|
62
|
+
* // Send a transaction
|
|
63
|
+
* const tx = await signer.sendTransaction({ to: '0x...', value: ethers.parseEther('1') });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare class BronSigner extends AbstractSigner {
|
|
67
|
+
private readonly bronApi;
|
|
68
|
+
private readonly apiKey;
|
|
69
|
+
private readonly workspaceId;
|
|
70
|
+
private readonly accountId;
|
|
71
|
+
constructor(options: BronSignerOptions);
|
|
72
|
+
/**
|
|
73
|
+
* Creates a new BronSigner connected to a different provider
|
|
74
|
+
*/
|
|
75
|
+
connect(provider: Provider): BronSigner;
|
|
76
|
+
/**
|
|
77
|
+
* Returns the address associated with this signer's Bron account
|
|
78
|
+
*/
|
|
79
|
+
getAddress(): Promise<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Sends a transaction through Bron custody platform.
|
|
82
|
+
* The transaction will be signed and broadcast by Bron.
|
|
83
|
+
*/
|
|
84
|
+
sendTransaction(tx: TransactionRequest): Promise<TransactionResponse>;
|
|
85
|
+
/**
|
|
86
|
+
* Transaction signing is not supported by BronSigner.
|
|
87
|
+
* Use sendTransaction() instead which handles signing and broadcasting internally.
|
|
88
|
+
* @throws Always throws - use sendTransaction instead
|
|
89
|
+
*/
|
|
90
|
+
signTransaction(_tx: TransactionRequest): Promise<string>;
|
|
91
|
+
/**
|
|
92
|
+
* Signs a message using the Bron custody platform.
|
|
93
|
+
* Uses EIP-191 personal_sign format.
|
|
94
|
+
*
|
|
95
|
+
* @param message - The message to sign (string, Buffer, or Uint8Array)
|
|
96
|
+
* @returns The signature as a hex string
|
|
97
|
+
*/
|
|
98
|
+
signMessage(message: string | Uint8Array): Promise<string>;
|
|
99
|
+
/**
|
|
100
|
+
* Signs typed data using EIP-712 standard through Bron custody platform.
|
|
101
|
+
*
|
|
102
|
+
* @param domain - The EIP-712 domain
|
|
103
|
+
* @param types - The type definitions
|
|
104
|
+
* @param value - The data to sign
|
|
105
|
+
* @returns The signature as a hex string
|
|
106
|
+
*/
|
|
107
|
+
signTypedData(domain: TypedDataDomain, types: Record<string, TypedDataField[]>, value: Record<string, unknown>): Promise<string>;
|
|
108
|
+
private assertProvider;
|
|
109
|
+
private getBronNetworkId;
|
|
110
|
+
private getBronGasTokenId;
|
|
111
|
+
private messageToHex;
|
|
112
|
+
private buildTypedData;
|
|
113
|
+
private sanitizeForJson;
|
|
114
|
+
private pollTransaction;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { BronSigner as B, type EIP712TypedData as E, type NetworkMapping as N, type TransactionStatus as T, type BronSignerOptions as a };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Provider, TypedDataField, TypedDataDomain, AbstractSigner, TransactionRequest, TransactionResponse } from 'ethers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for BronSigner
|
|
5
|
+
*/
|
|
6
|
+
interface BronSignerOptions {
|
|
7
|
+
/** Ethers.js provider instance */
|
|
8
|
+
provider: Provider;
|
|
9
|
+
/** Bron API key */
|
|
10
|
+
apiKey: string;
|
|
11
|
+
/** Bron workspace ID */
|
|
12
|
+
workspaceId: string;
|
|
13
|
+
/** Bron account ID */
|
|
14
|
+
accountId: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Network mapping configuration
|
|
18
|
+
*/
|
|
19
|
+
interface NetworkMapping {
|
|
20
|
+
/** Bron network ID */
|
|
21
|
+
networkId: string;
|
|
22
|
+
/** Bron gas token asset ID */
|
|
23
|
+
gasTokenId: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* EIP-712 typed data structure
|
|
27
|
+
*/
|
|
28
|
+
interface EIP712TypedData {
|
|
29
|
+
types: Record<string, TypedDataField[]>;
|
|
30
|
+
primaryType: string;
|
|
31
|
+
domain: TypedDataDomain;
|
|
32
|
+
message: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Bron transaction status
|
|
36
|
+
*/
|
|
37
|
+
type TransactionStatus = 'pending' | 'awaiting-approval' | 'approved' | 'signing' | 'broadcasting' | 'completed' | 'failed' | 'rejected' | 'canceled';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Ethers.js compatible signer that uses Bron custody platform for signing operations.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* import { BronSigner } from '@bronlabs/bron-ethers-signer';
|
|
45
|
+
* import { ethers } from 'ethers';
|
|
46
|
+
*
|
|
47
|
+
* const provider = new ethers.JsonRpcProvider('https://mainnet.infura.io/v3/...');
|
|
48
|
+
*
|
|
49
|
+
* const signer = new BronSigner({
|
|
50
|
+
* provider,
|
|
51
|
+
* apiKey: process.env.BRON_API_KEY!,
|
|
52
|
+
* workspaceId: process.env.BRON_WORKSPACE_ID!,
|
|
53
|
+
* accountId: process.env.BRON_ACCOUNT_ID!,
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* // Sign a message
|
|
57
|
+
* const signature = await signer.signMessage('Hello World');
|
|
58
|
+
*
|
|
59
|
+
* // Sign typed data (EIP-712)
|
|
60
|
+
* const typedSignature = await signer.signTypedData(domain, types, value);
|
|
61
|
+
*
|
|
62
|
+
* // Send a transaction
|
|
63
|
+
* const tx = await signer.sendTransaction({ to: '0x...', value: ethers.parseEther('1') });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare class BronSigner extends AbstractSigner {
|
|
67
|
+
private readonly bronApi;
|
|
68
|
+
private readonly apiKey;
|
|
69
|
+
private readonly workspaceId;
|
|
70
|
+
private readonly accountId;
|
|
71
|
+
constructor(options: BronSignerOptions);
|
|
72
|
+
/**
|
|
73
|
+
* Creates a new BronSigner connected to a different provider
|
|
74
|
+
*/
|
|
75
|
+
connect(provider: Provider): BronSigner;
|
|
76
|
+
/**
|
|
77
|
+
* Returns the address associated with this signer's Bron account
|
|
78
|
+
*/
|
|
79
|
+
getAddress(): Promise<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Sends a transaction through Bron custody platform.
|
|
82
|
+
* The transaction will be signed and broadcast by Bron.
|
|
83
|
+
*/
|
|
84
|
+
sendTransaction(tx: TransactionRequest): Promise<TransactionResponse>;
|
|
85
|
+
/**
|
|
86
|
+
* Transaction signing is not supported by BronSigner.
|
|
87
|
+
* Use sendTransaction() instead which handles signing and broadcasting internally.
|
|
88
|
+
* @throws Always throws - use sendTransaction instead
|
|
89
|
+
*/
|
|
90
|
+
signTransaction(_tx: TransactionRequest): Promise<string>;
|
|
91
|
+
/**
|
|
92
|
+
* Signs a message using the Bron custody platform.
|
|
93
|
+
* Uses EIP-191 personal_sign format.
|
|
94
|
+
*
|
|
95
|
+
* @param message - The message to sign (string, Buffer, or Uint8Array)
|
|
96
|
+
* @returns The signature as a hex string
|
|
97
|
+
*/
|
|
98
|
+
signMessage(message: string | Uint8Array): Promise<string>;
|
|
99
|
+
/**
|
|
100
|
+
* Signs typed data using EIP-712 standard through Bron custody platform.
|
|
101
|
+
*
|
|
102
|
+
* @param domain - The EIP-712 domain
|
|
103
|
+
* @param types - The type definitions
|
|
104
|
+
* @param value - The data to sign
|
|
105
|
+
* @returns The signature as a hex string
|
|
106
|
+
*/
|
|
107
|
+
signTypedData(domain: TypedDataDomain, types: Record<string, TypedDataField[]>, value: Record<string, unknown>): Promise<string>;
|
|
108
|
+
private assertProvider;
|
|
109
|
+
private getBronNetworkId;
|
|
110
|
+
private getBronGasTokenId;
|
|
111
|
+
private messageToHex;
|
|
112
|
+
private buildTypedData;
|
|
113
|
+
private sanitizeForJson;
|
|
114
|
+
private pollTransaction;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { BronSigner as B, type EIP712TypedData as E, type NetworkMapping as N, type TransactionStatus as T, type BronSignerOptions as a };
|