@jibidieuw/dexes 0.0.0
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 +169 -0
- package/dist/index.d.mts +4749 -0
- package/dist/index.d.ts +4749 -0
- package/dist/index.js +4056 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4013 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +71 -0
package/README.md
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# Dexes - Web3PGP SDK
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for managing OpenPGP keys on Ethereum through the Web3PGP smart contracts. Build decentralized key infrastructure with cryptographic operations powered by OpenPGP.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ๐ **OpenPGP Integration**: Seamless integration with OpenPGP.js for cryptographic operations
|
|
8
|
+
- โ๏ธ **Ethereum Native**: Direct interaction with Web3PGP smart contracts
|
|
9
|
+
- ๐ **Event Searching**: Query blockchain events for key registrations, subkey additions, and revocations
|
|
10
|
+
- โก **Rate Limiting**: Built-in rate limiting to prevent RPC throttling
|
|
11
|
+
- ๐ฆ **TypeScript First**: Full type safety with comprehensive TypeScript support
|
|
12
|
+
- ๐งช **Well Tested**: Comprehensive integration tests with Anvil blockchain
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @cryptogram/dexes
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or with yarn:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
yarn add @cryptogram/dexes
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or with pnpm:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pnpm add @cryptogram/dexes
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
### Basic Usage
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { Web3PGP } from '@cryptogram/dexes';
|
|
38
|
+
import { createPublicClient, http } from 'viem';
|
|
39
|
+
import { inksepolia } from 'viem/chains';
|
|
40
|
+
|
|
41
|
+
// Create a Viem public client
|
|
42
|
+
const publicClient = createPublicClient({
|
|
43
|
+
chain: inksepolia,
|
|
44
|
+
transport: http('https://rpc-gel-sepolia.inkonchain.com'),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Initialize Web3PGP
|
|
48
|
+
const contractAddress = '0x...'; // Your Web3PGP contract address
|
|
49
|
+
const web3pgp = new Web3PGP(publicClient, contractAddress);
|
|
50
|
+
|
|
51
|
+
// Search for key events
|
|
52
|
+
const events = await web3pgp.searchKeyEvents('earliest', 'latest');
|
|
53
|
+
console.log(events);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### With Web3PGPService (High-Level API)
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { Web3PGPService, Web3PGP } from '@cryptogram/dexes';
|
|
60
|
+
import { createPublicClient, http } from 'viem';
|
|
61
|
+
|
|
62
|
+
const publicClient = createPublicClient({
|
|
63
|
+
chain: inksepolia,
|
|
64
|
+
transport: http('https://rpc-gel-sepolia.inkonchain.com'),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const web3pgp = new Web3PGP(publicClient, contractAddress);
|
|
68
|
+
const service = new Web3PGPService(web3pgp);
|
|
69
|
+
|
|
70
|
+
// Get a public key by fingerprint
|
|
71
|
+
const publicKey = await service.getPublicKey('0x1234567890abcdef...');
|
|
72
|
+
|
|
73
|
+
// Register a new key
|
|
74
|
+
await service.registerKey(armoredKey, walletClient);
|
|
75
|
+
|
|
76
|
+
// Add a subkey
|
|
77
|
+
await service.addSubkey(fingerprint, armoredSubkey, walletClient);
|
|
78
|
+
|
|
79
|
+
// Revoke a key
|
|
80
|
+
await service.revokeKey(fingerprint, revocationCertificate, walletClient);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## API Reference
|
|
84
|
+
|
|
85
|
+
### Web3PGP (Low-Level)
|
|
86
|
+
|
|
87
|
+
The `Web3PGP` class provides direct access to smart contract methods.
|
|
88
|
+
|
|
89
|
+
#### Methods
|
|
90
|
+
|
|
91
|
+
- `searchKeyEvents(fromBlock, toBlock)`: Search for key-related events
|
|
92
|
+
- `getPublicKey(fingerprint)`: Retrieve a public key from storage
|
|
93
|
+
- `registerKey(fingerprint, publicKey)`: Register a new key (requires wallet)
|
|
94
|
+
- `addSubkey(fingerprint, subkeyFingerprint, subkey)`: Add a subkey
|
|
95
|
+
- `revokeKey(fingerprint, revocationCertificate)`: Revoke a key
|
|
96
|
+
|
|
97
|
+
### Web3PGPService (High-Level)
|
|
98
|
+
|
|
99
|
+
The `Web3PGPService` class provides a higher-level API with OpenPGP integration.
|
|
100
|
+
|
|
101
|
+
#### Methods
|
|
102
|
+
|
|
103
|
+
- `getPublicKey(fingerprint)`: Get an OpenPGP PublicKey object
|
|
104
|
+
- `registerKey(armoredKey, walletClient)`: Register an armored key
|
|
105
|
+
- `addSubkey(fingerprint, armoredSubkey, walletClient)`: Add an armored subkey
|
|
106
|
+
- `revokeKey(fingerprint, revocationCertificate, walletClient)`: Revoke with certificate
|
|
107
|
+
- `searchKeyEvents(fromBlock, toBlock)`: Search for events with parsed results
|
|
108
|
+
|
|
109
|
+
## Environment
|
|
110
|
+
|
|
111
|
+
This SDK requires:
|
|
112
|
+
|
|
113
|
+
- **Node.js**: 18.x or higher
|
|
114
|
+
- **Viem**: ^2.0.0
|
|
115
|
+
|
|
116
|
+
## Testing
|
|
117
|
+
|
|
118
|
+
Run the test suite:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
# Unit tests
|
|
122
|
+
npm run test:unit
|
|
123
|
+
|
|
124
|
+
# Integration tests (requires Anvil)
|
|
125
|
+
npm run test:integration
|
|
126
|
+
|
|
127
|
+
# All tests
|
|
128
|
+
npm run test:all
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Updating Contract ABIs
|
|
132
|
+
|
|
133
|
+
The SDK includes contract ABIs that must stay synchronized with the deployed smart contracts. When the contracts in `/contracts` are modified, you need to refresh the ABIs:
|
|
134
|
+
|
|
135
|
+
### Why Update ABIs?
|
|
136
|
+
|
|
137
|
+
The ABIs define the smart contract function signatures, events, and error types. When contract changes are deployed, the ABIs must be updated to ensure:
|
|
138
|
+
- โ Type safety matches current contract implementation
|
|
139
|
+
- โ New functions/events are available to the SDK
|
|
140
|
+
- โ Integration tests work with the latest contract code
|
|
141
|
+
- โ No runtime errors from mismatched function signatures
|
|
142
|
+
|
|
143
|
+
### How to Update ABIs
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
npm run update-abis
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
This command:
|
|
150
|
+
1. Compiles smart contracts using Foundry (`forge build`)
|
|
151
|
+
2. Extracts ABIs from compiled artifacts
|
|
152
|
+
3. Generates TypeScript files in `src/abis/`
|
|
153
|
+
4. Validates all contract artifacts are present
|
|
154
|
+
|
|
155
|
+
**Note**: This task is automatically run before integration tests, but should be manually run whenever smart contracts are modified.
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
MIT License - see LICENSE file for details
|
|
160
|
+
|
|
161
|
+
## Contributing
|
|
162
|
+
|
|
163
|
+
Contributions are welcome! Please read our contributing guidelines and submit pull requests to the main repository.
|
|
164
|
+
|
|
165
|
+
## Support
|
|
166
|
+
|
|
167
|
+
For issues, questions, or contributions, please visit:
|
|
168
|
+
- GitHub: https://github.com/cryptogram/dexes
|
|
169
|
+
- Documentation: https://github.com/cryptogram/cryptogram
|