@hauska-sdk/adapters-blockchain-ethers 0.1.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/CHANGELOG.md +18 -0
- package/dist/index.d.ts +110 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +277 -0
- package/dist/index.js.map +1 -0
- package/package.json +77 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog - @hauska-sdk/adapters-blockchain-ethers
|
|
2
|
+
|
|
3
|
+
All notable changes to the Ethers.js Blockchain Adapter will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.1.0] - 2025-02-03
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- Initial release of Ethers.js Blockchain Adapter
|
|
9
|
+
- On-chain event emission for VDAs
|
|
10
|
+
- Access pass event emission
|
|
11
|
+
- Payment event emission
|
|
12
|
+
- Event querying functionality
|
|
13
|
+
- Optional enable/disable flag
|
|
14
|
+
- Read-only mode support
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
[0.1.0]: https://github.com/hauska-sdk/hauska-sdk/releases/tag/@hauska-sdk/adapters-blockchain-ethers@0.1.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hauska-sdk/adapters-blockchain-ethers
|
|
3
|
+
* CNS Protocol Ethers.js Blockchain Adapter
|
|
4
|
+
*
|
|
5
|
+
* Provides on-chain event emission for VDAs, access passes, and payments.
|
|
6
|
+
* This adapter is optional - the SDK works perfectly without it.
|
|
7
|
+
*/
|
|
8
|
+
import { ethers } from "ethers";
|
|
9
|
+
import type { VDA } from "@hauska-sdk/vda";
|
|
10
|
+
import type { PaymentRecord } from "@hauska-sdk/payment";
|
|
11
|
+
/**
|
|
12
|
+
* Blockchain Adapter Configuration
|
|
13
|
+
*/
|
|
14
|
+
export interface BlockchainAdapterConfig {
|
|
15
|
+
/**
|
|
16
|
+
* RPC URL for the blockchain network
|
|
17
|
+
*/
|
|
18
|
+
rpcUrl: string;
|
|
19
|
+
/**
|
|
20
|
+
* Contract address for the CNS Protocol registry
|
|
21
|
+
*/
|
|
22
|
+
contractAddress: string;
|
|
23
|
+
/**
|
|
24
|
+
* Private key or wallet for signing transactions
|
|
25
|
+
* If not provided, events will be emitted via contract calls (requires funded wallet)
|
|
26
|
+
*/
|
|
27
|
+
privateKey?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Chain ID (default: 8453 for Base L2)
|
|
30
|
+
*/
|
|
31
|
+
chainId?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Optional logging hook
|
|
34
|
+
*/
|
|
35
|
+
logHook?: (level: "info" | "warn" | "error", message: string, data?: any) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Whether to enable event emission (default: true)
|
|
38
|
+
* Set to false to disable all blockchain operations
|
|
39
|
+
*/
|
|
40
|
+
enabled?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Blockchain Adapter
|
|
44
|
+
*
|
|
45
|
+
* Emits on-chain events for CNS Protocol operations.
|
|
46
|
+
* All operations are non-blocking and handle errors gracefully.
|
|
47
|
+
*/
|
|
48
|
+
export declare class BlockchainAdapter {
|
|
49
|
+
private config;
|
|
50
|
+
private provider;
|
|
51
|
+
private signer;
|
|
52
|
+
private contract;
|
|
53
|
+
private enabled;
|
|
54
|
+
constructor(config: BlockchainAdapterConfig);
|
|
55
|
+
/**
|
|
56
|
+
* Initialize provider, signer, and contract
|
|
57
|
+
*/
|
|
58
|
+
private initialize;
|
|
59
|
+
/**
|
|
60
|
+
* Emit VDA minted event
|
|
61
|
+
*
|
|
62
|
+
* @param vda - The VDA that was minted
|
|
63
|
+
* @returns Transaction hash if successful, null if disabled or failed
|
|
64
|
+
*/
|
|
65
|
+
emitVDAMinted(vda: VDA): Promise<string | null>;
|
|
66
|
+
/**
|
|
67
|
+
* Emit access pass created event
|
|
68
|
+
*
|
|
69
|
+
* @param accessPass - The access pass VDA
|
|
70
|
+
* @returns Transaction hash if successful, null if disabled or failed
|
|
71
|
+
*/
|
|
72
|
+
emitAccessPassCreated(accessPass: VDA): Promise<string | null>;
|
|
73
|
+
/**
|
|
74
|
+
* Emit access pass revoked event
|
|
75
|
+
*
|
|
76
|
+
* @param accessPassId - The access pass VDA ID
|
|
77
|
+
* @returns Transaction hash if successful, null if disabled or failed
|
|
78
|
+
*/
|
|
79
|
+
emitAccessPassRevoked(accessPassId: string): Promise<string | null>;
|
|
80
|
+
/**
|
|
81
|
+
* Emit payment recorded event
|
|
82
|
+
*
|
|
83
|
+
* @param payment - The payment record
|
|
84
|
+
* @returns Transaction hash if successful, null if disabled or failed
|
|
85
|
+
*/
|
|
86
|
+
emitPaymentRecorded(payment: PaymentRecord): Promise<string | null>;
|
|
87
|
+
/**
|
|
88
|
+
* Query on-chain events
|
|
89
|
+
*
|
|
90
|
+
* @param eventName - Name of the event to query
|
|
91
|
+
* @param filters - Event filters
|
|
92
|
+
* @param fromBlock - Starting block number
|
|
93
|
+
* @param toBlock - Ending block number
|
|
94
|
+
* @returns Array of event logs
|
|
95
|
+
*/
|
|
96
|
+
queryEvents(eventName: "VDAMinted" | "AccessPassCreated" | "AccessPassRevoked" | "PaymentRecorded", filters?: any, fromBlock?: number, toBlock?: number): Promise<ethers.Log[]>;
|
|
97
|
+
/**
|
|
98
|
+
* Check if adapter is enabled and ready
|
|
99
|
+
*/
|
|
100
|
+
isEnabled(): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Check if adapter has signer (can emit events)
|
|
103
|
+
*/
|
|
104
|
+
hasSigner(): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Log a message using the configured log hook
|
|
107
|
+
*/
|
|
108
|
+
private log;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","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mB,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA6CzE;;;;;;;;OAQG;IACG,WAAW,CACf,SAAS,EAAE,WAAW,GAAG,mBAAmB,GAAG,mBAAmB,GAAG,iBAAiB,EACtF,OAAO,CAAC,EAAE,GAAG,EACb,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;IAuBxB;;OAEG;IACH,SAAS,IAAI,OAAO;IAIpB;;OAEG;IACH,SAAS,IAAI,OAAO;IAIpB;;OAEG;IACH,OAAO,CAAC,GAAG;CAKZ"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hauska-sdk/adapters-blockchain-ethers
|
|
3
|
+
* CNS Protocol Ethers.js Blockchain Adapter
|
|
4
|
+
*
|
|
5
|
+
* Provides on-chain event emission for VDAs, access passes, and payments.
|
|
6
|
+
* This adapter is optional - the SDK works perfectly without it.
|
|
7
|
+
*/
|
|
8
|
+
import { ethers } from "ethers";
|
|
9
|
+
/**
|
|
10
|
+
* CNS Protocol Registry Contract ABI
|
|
11
|
+
*
|
|
12
|
+
* Minimal ABI for event emission functions
|
|
13
|
+
*/
|
|
14
|
+
const CNS_REGISTRY_ABI = [
|
|
15
|
+
"function mintVDA(bytes32 vdaId, address owner, string calldata assetType, string calldata spoke, bytes32 ipfsCid, bytes32 addressHash) external",
|
|
16
|
+
"function createAccessPass(bytes32 passId, address grantor, address recipient, bytes32[] calldata accessibleVDAIds, uint256 expiresAt) external",
|
|
17
|
+
"function revokeAccessPass(bytes32 passId) external",
|
|
18
|
+
"function recordPayment(bytes32 resourceId, address payer, uint256 amount, string calldata currency, bytes32 ipfsCid) external",
|
|
19
|
+
"event VDAMinted(bytes32 indexed vdaId, address indexed owner, string assetType, string spoke, bytes32 ipfsCid, bytes32 addressHash, uint256 timestamp)",
|
|
20
|
+
"event AccessPassCreated(bytes32 indexed passId, address indexed grantor, address indexed recipient, bytes32[] accessibleVDAIds, uint256 expiresAt, uint256 timestamp)",
|
|
21
|
+
"event AccessPassRevoked(bytes32 indexed passId, uint256 timestamp)",
|
|
22
|
+
"event PaymentRecorded(bytes32 indexed resourceId, address indexed payer, uint256 amount, string currency, bytes32 ipfsCid, uint256 timestamp)",
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Blockchain Adapter
|
|
26
|
+
*
|
|
27
|
+
* Emits on-chain events for CNS Protocol operations.
|
|
28
|
+
* All operations are non-blocking and handle errors gracefully.
|
|
29
|
+
*/
|
|
30
|
+
export class BlockchainAdapter {
|
|
31
|
+
config;
|
|
32
|
+
provider = null;
|
|
33
|
+
signer = null;
|
|
34
|
+
contract = null;
|
|
35
|
+
enabled;
|
|
36
|
+
constructor(config) {
|
|
37
|
+
this.config = config;
|
|
38
|
+
this.enabled = config.enabled !== false;
|
|
39
|
+
if (!this.enabled) {
|
|
40
|
+
this.log("info", "Blockchain adapter disabled");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
this.initialize();
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
this.log("error", "Failed to initialize blockchain adapter", { error: error.message });
|
|
48
|
+
// Continue without blockchain - adapter is optional
|
|
49
|
+
this.enabled = false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Initialize provider, signer, and contract
|
|
54
|
+
*/
|
|
55
|
+
initialize() {
|
|
56
|
+
if (!this.enabled)
|
|
57
|
+
return;
|
|
58
|
+
// Initialize provider
|
|
59
|
+
this.provider = new ethers.JsonRpcProvider(this.config.rpcUrl);
|
|
60
|
+
// Initialize signer if private key provided
|
|
61
|
+
if (this.config.privateKey) {
|
|
62
|
+
this.signer = new ethers.Wallet(this.config.privateKey, this.provider);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// No signer - events can only be read, not emitted
|
|
66
|
+
this.log("warn", "No private key provided - events cannot be emitted, only read");
|
|
67
|
+
}
|
|
68
|
+
// Initialize contract
|
|
69
|
+
if (this.signer) {
|
|
70
|
+
this.contract = new ethers.Contract(this.config.contractAddress, CNS_REGISTRY_ABI, this.signer);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// Contract without signer (read-only)
|
|
74
|
+
this.contract = new ethers.Contract(this.config.contractAddress, CNS_REGISTRY_ABI, this.provider);
|
|
75
|
+
}
|
|
76
|
+
this.log("info", "Blockchain adapter initialized", {
|
|
77
|
+
network: this.config.rpcUrl,
|
|
78
|
+
contract: this.config.contractAddress,
|
|
79
|
+
hasSigner: !!this.signer,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Emit VDA minted event
|
|
84
|
+
*
|
|
85
|
+
* @param vda - The VDA that was minted
|
|
86
|
+
* @returns Transaction hash if successful, null if disabled or failed
|
|
87
|
+
*/
|
|
88
|
+
async emitVDAMinted(vda) {
|
|
89
|
+
if (!this.enabled || !this.contract || !this.signer) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
// Convert VDA ID to bytes32
|
|
94
|
+
const vdaIdBytes = ethers.id(vda.id);
|
|
95
|
+
// Convert IPFS CID to bytes32 (hash the CID string)
|
|
96
|
+
const ipfsCidBytes = vda.metadata.ipfsCid
|
|
97
|
+
? ethers.id(vda.metadata.ipfsCid)
|
|
98
|
+
: ethers.ZeroHash;
|
|
99
|
+
// Hash address for indexing (if present)
|
|
100
|
+
const addressHash = vda.metadata.address
|
|
101
|
+
? ethers.id(vda.metadata.address)
|
|
102
|
+
: ethers.ZeroHash;
|
|
103
|
+
// Call contract function
|
|
104
|
+
const tx = await this.contract.mintVDA(vdaIdBytes, vda.metadata.ownerWallet, vda.metadata.assetType, vda.metadata.spoke, ipfsCidBytes, addressHash);
|
|
105
|
+
// Wait for transaction (non-blocking - don't await in production)
|
|
106
|
+
const receipt = await tx.wait();
|
|
107
|
+
this.log("info", "VDA minted event emitted", {
|
|
108
|
+
vdaId: vda.id,
|
|
109
|
+
txHash: receipt.hash,
|
|
110
|
+
});
|
|
111
|
+
return receipt.hash;
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
this.log("error", "Failed to emit VDA minted event", {
|
|
115
|
+
vdaId: vda.id,
|
|
116
|
+
error: error.message,
|
|
117
|
+
});
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Emit access pass created event
|
|
123
|
+
*
|
|
124
|
+
* @param accessPass - The access pass VDA
|
|
125
|
+
* @returns Transaction hash if successful, null if disabled or failed
|
|
126
|
+
*/
|
|
127
|
+
async emitAccessPassCreated(accessPass) {
|
|
128
|
+
if (!this.enabled || !this.contract || !this.signer) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
// Convert access pass ID to bytes32
|
|
133
|
+
const passIdBytes = ethers.id(accessPass.id);
|
|
134
|
+
// Convert accessible VDA IDs to bytes32 array
|
|
135
|
+
const accessibleVDAIds = (accessPass.metadata.accessibleVDAs || []).map((id) => ethers.id(id));
|
|
136
|
+
// Get expiry timestamp
|
|
137
|
+
const expiresAt = accessPass.metadata.expiry || 0;
|
|
138
|
+
// Call contract function
|
|
139
|
+
const tx = await this.contract.createAccessPass(passIdBytes, accessPass.metadata.grantorWallet || accessPass.metadata.ownerWallet, accessPass.metadata.ownerWallet, // Recipient is the owner of the access pass
|
|
140
|
+
accessibleVDAIds, expiresAt);
|
|
141
|
+
// Wait for transaction
|
|
142
|
+
const receipt = await tx.wait();
|
|
143
|
+
this.log("info", "Access pass created event emitted", {
|
|
144
|
+
passId: accessPass.id,
|
|
145
|
+
txHash: receipt.hash,
|
|
146
|
+
});
|
|
147
|
+
return receipt.hash;
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
this.log("error", "Failed to emit access pass created event", {
|
|
151
|
+
passId: accessPass.id,
|
|
152
|
+
error: error.message,
|
|
153
|
+
});
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Emit access pass revoked event
|
|
159
|
+
*
|
|
160
|
+
* @param accessPassId - The access pass VDA ID
|
|
161
|
+
* @returns Transaction hash if successful, null if disabled or failed
|
|
162
|
+
*/
|
|
163
|
+
async emitAccessPassRevoked(accessPassId) {
|
|
164
|
+
if (!this.enabled || !this.contract || !this.signer) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
// Convert access pass ID to bytes32
|
|
169
|
+
const passIdBytes = ethers.id(accessPassId);
|
|
170
|
+
// Call contract function
|
|
171
|
+
const tx = await this.contract.revokeAccessPass(passIdBytes);
|
|
172
|
+
// Wait for transaction
|
|
173
|
+
const receipt = await tx.wait();
|
|
174
|
+
this.log("info", "Access pass revoked event emitted", {
|
|
175
|
+
passId: accessPassId,
|
|
176
|
+
txHash: receipt.hash,
|
|
177
|
+
});
|
|
178
|
+
return receipt.hash;
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
this.log("error", "Failed to emit access pass revoked event", {
|
|
182
|
+
passId: accessPassId,
|
|
183
|
+
error: error.message,
|
|
184
|
+
});
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Emit payment recorded event
|
|
190
|
+
*
|
|
191
|
+
* @param payment - The payment record
|
|
192
|
+
* @returns Transaction hash if successful, null if disabled or failed
|
|
193
|
+
*/
|
|
194
|
+
async emitPaymentRecorded(payment) {
|
|
195
|
+
if (!this.enabled || !this.contract || !this.signer) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
// Convert resource ID to bytes32
|
|
200
|
+
const resourceIdBytes = ethers.id(payment.resourceId);
|
|
201
|
+
// Convert amount to BigNumber (assuming currency has decimals)
|
|
202
|
+
// For simplicity, we'll use the amount as a string and let ethers parse it
|
|
203
|
+
const amount = ethers.parseUnits(payment.amount, 18); // Assuming 18 decimals
|
|
204
|
+
// Convert IPFS CID to bytes32 (if present in metadata)
|
|
205
|
+
const ipfsCidBytes = payment.metadata?.ipfsCid
|
|
206
|
+
? ethers.id(payment.metadata.ipfsCid)
|
|
207
|
+
: ethers.ZeroHash;
|
|
208
|
+
// Call contract function
|
|
209
|
+
const tx = await this.contract.recordPayment(resourceIdBytes, payment.fromAddress || ethers.ZeroAddress, amount, payment.currency, ipfsCidBytes);
|
|
210
|
+
// Wait for transaction
|
|
211
|
+
const receipt = await tx.wait();
|
|
212
|
+
this.log("info", "Payment recorded event emitted", {
|
|
213
|
+
resourceId: payment.resourceId,
|
|
214
|
+
txHash: receipt.hash,
|
|
215
|
+
});
|
|
216
|
+
return receipt.hash;
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
this.log("error", "Failed to emit payment recorded event", {
|
|
220
|
+
resourceId: payment.resourceId,
|
|
221
|
+
error: error.message,
|
|
222
|
+
});
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Query on-chain events
|
|
228
|
+
*
|
|
229
|
+
* @param eventName - Name of the event to query
|
|
230
|
+
* @param filters - Event filters
|
|
231
|
+
* @param fromBlock - Starting block number
|
|
232
|
+
* @param toBlock - Ending block number
|
|
233
|
+
* @returns Array of event logs
|
|
234
|
+
*/
|
|
235
|
+
async queryEvents(eventName, filters, fromBlock, toBlock) {
|
|
236
|
+
if (!this.enabled || !this.contract || !this.provider) {
|
|
237
|
+
return [];
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
const filter = this.contract.filters[eventName](filters);
|
|
241
|
+
const logs = await this.provider.getLogs({
|
|
242
|
+
...filter,
|
|
243
|
+
fromBlock: fromBlock || 0,
|
|
244
|
+
toBlock: toBlock || "latest",
|
|
245
|
+
});
|
|
246
|
+
return logs;
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
this.log("error", "Failed to query events", {
|
|
250
|
+
eventName,
|
|
251
|
+
error: error.message,
|
|
252
|
+
});
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Check if adapter is enabled and ready
|
|
258
|
+
*/
|
|
259
|
+
isEnabled() {
|
|
260
|
+
return this.enabled && !!this.contract;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Check if adapter has signer (can emit events)
|
|
264
|
+
*/
|
|
265
|
+
hasSigner() {
|
|
266
|
+
return this.enabled && !!this.signer;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Log a message using the configured log hook
|
|
270
|
+
*/
|
|
271
|
+
log(level, message, data) {
|
|
272
|
+
if (this.config.logHook) {
|
|
273
|
+
this.config.logHook(level, message, data);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAyChC;;;;GAIG;AACH,MAAM,gBAAgB,GAAG;IACvB,iJAAiJ;IACjJ,gJAAgJ;IAChJ,oDAAoD;IACpD,+HAA+H;IAC/H,wJAAwJ;IACxJ,uKAAuK;IACvK,oEAAoE;IACpE,+IAA+I;CACvI,CAAC;AAEX;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IACpB,MAAM,CAA0B;IAChC,QAAQ,GAA2B,IAAI,CAAC;IACxC,MAAM,GAAyB,IAAI,CAAC;IACpC,QAAQ,GAA2B,IAAI,CAAC;IACxC,OAAO,CAAU;IAEzB,YAAY,MAA+B;QACzC,IAAI,CAAC,MAAM,GAAG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SAAS;QACP,OAAO,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;IACvC,CAAC;IAED;;OAEG;IACK,GAAG,CAAC,KAAgC,EAAE,OAAe,EAAE,IAAU;QACvE,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACxB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hauska-sdk/adapters-blockchain-ethers",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CNS Protocol Ethers.js Blockchain Adapter",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"clean": "rimraf dist",
|
|
18
|
+
"test": "vitest run",
|
|
19
|
+
"test:watch": "vitest",
|
|
20
|
+
"test:coverage": "vitest run --coverage",
|
|
21
|
+
"type-check": "tsc --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@hauska-sdk/vda": "^0.1.0",
|
|
25
|
+
"@hauska-sdk/payment": "^0.1.0",
|
|
26
|
+
"ethers": "^6.16.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^20.19.31",
|
|
30
|
+
"rimraf": "^5.0.5",
|
|
31
|
+
"typescript": "^5.3.3",
|
|
32
|
+
"vitest": "^1.6.1"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"cns-protocol",
|
|
36
|
+
"blockchain",
|
|
37
|
+
"ethers",
|
|
38
|
+
"ethereum",
|
|
39
|
+
"adapter",
|
|
40
|
+
"base",
|
|
41
|
+
"l2",
|
|
42
|
+
"events"
|
|
43
|
+
],
|
|
44
|
+
"author": "Hauska SDK Team",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "https://github.com/hauska-sdk/hauska-sdk.git",
|
|
49
|
+
"directory": "packages/adapters/blockchain-ethers"
|
|
50
|
+
},
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/hauska-sdk/hauska-sdk/issues"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://github.com/hauska-sdk/hauska-sdk#readme",
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=18.0.0",
|
|
57
|
+
"npm": ">=9.0.0"
|
|
58
|
+
},
|
|
59
|
+
"files": [
|
|
60
|
+
"dist",
|
|
61
|
+
"README.md",
|
|
62
|
+
"CHANGELOG.md"
|
|
63
|
+
],
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsc",
|
|
66
|
+
"clean": "rimraf dist",
|
|
67
|
+
"test": "vitest run",
|
|
68
|
+
"test:watch": "vitest",
|
|
69
|
+
"test:coverage": "vitest run --coverage",
|
|
70
|
+
"type-check": "tsc --noEmit",
|
|
71
|
+
"prepublishOnly": "npm run build"
|
|
72
|
+
},
|
|
73
|
+
"publishConfig": {
|
|
74
|
+
"access": "public",
|
|
75
|
+
"registry": "https://registry.npmjs.org"
|
|
76
|
+
}
|
|
77
|
+
}
|