@varity-labs/client-js 2.0.0-alpha.1
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 +31 -0
- package/README.md +82 -0
- package/dist/VarityClient.d.ts +104 -0
- package/dist/VarityClient.js +212 -0
- package/dist/__tests__/client.test.d.ts +4 -0
- package/dist/__tests__/client.test.js +251 -0
- package/dist/auth/SIWEAuth.d.ts +105 -0
- package/dist/auth/SIWEAuth.js +328 -0
- package/dist/contracts/ContractManager.d.ts +109 -0
- package/dist/contracts/ContractManager.js +306 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +76 -0
- package/dist/react/hooks.d.ts +170 -0
- package/dist/react/hooks.js +398 -0
- package/dist/storage/StorageManager.d.ts +122 -0
- package/dist/storage/StorageManager.js +296 -0
- package/dist/types.d.ts +157 -0
- package/dist/types.js +51 -0
- package/dist/utils/formatting.d.ts +123 -0
- package/dist/utils/formatting.js +236 -0
- package/dist/varity-s3-client.d.ts +119 -0
- package/dist/varity-s3-client.js +179 -0
- package/dist/wallet/WalletManager.d.ts +120 -0
- package/dist/wallet/WalletManager.js +355 -0
- package/package.json +76 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility functions for formatting addresses, amounts, and other data
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.USDC_MULTIPLIER = exports.USDC_DECIMALS = void 0;
|
|
7
|
+
exports.formatUSDC = formatUSDC;
|
|
8
|
+
exports.parseUSDC = parseUSDC;
|
|
9
|
+
exports.getUSDCAmount = getUSDCAmount;
|
|
10
|
+
exports.isValidAddress = isValidAddress;
|
|
11
|
+
exports.formatAddress = formatAddress;
|
|
12
|
+
exports.shortenAddress = shortenAddress;
|
|
13
|
+
exports.shortenTxHash = shortenTxHash;
|
|
14
|
+
exports.formatEther = formatEther;
|
|
15
|
+
exports.parseEther = parseEther;
|
|
16
|
+
exports.getChainName = getChainName;
|
|
17
|
+
exports.getBlockExplorerUrl = getBlockExplorerUrl;
|
|
18
|
+
exports.getTxUrl = getTxUrl;
|
|
19
|
+
exports.getAddressUrl = getAddressUrl;
|
|
20
|
+
exports.formatTimestamp = formatTimestamp;
|
|
21
|
+
exports.formatGas = formatGas;
|
|
22
|
+
exports.formatPercentage = formatPercentage;
|
|
23
|
+
exports.formatNumber = formatNumber;
|
|
24
|
+
// USDC has 6 decimals on Varity L3
|
|
25
|
+
exports.USDC_DECIMALS = 6;
|
|
26
|
+
exports.USDC_MULTIPLIER = BigInt(10 ** exports.USDC_DECIMALS);
|
|
27
|
+
/**
|
|
28
|
+
* Format USDC amount from raw value (6 decimals)
|
|
29
|
+
* @param amount Raw USDC amount in smallest unit
|
|
30
|
+
* @returns Formatted USDC string
|
|
31
|
+
* @example
|
|
32
|
+
* formatUSDC(1000000n) // "1.000000"
|
|
33
|
+
* formatUSDC(1500000n) // "1.500000"
|
|
34
|
+
*/
|
|
35
|
+
function formatUSDC(amount) {
|
|
36
|
+
const wholePart = amount / exports.USDC_MULTIPLIER;
|
|
37
|
+
const fractionalPart = amount % exports.USDC_MULTIPLIER;
|
|
38
|
+
const fractionalStr = fractionalPart.toString().padStart(exports.USDC_DECIMALS, '0');
|
|
39
|
+
return `${wholePart}.${fractionalStr}`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parse USDC amount from string to raw value
|
|
43
|
+
* @param amount USDC amount as string (e.g., "1.5", "10", "0.000001")
|
|
44
|
+
* @returns Raw USDC amount in smallest unit
|
|
45
|
+
* @example
|
|
46
|
+
* parseUSDC("1.5") // 1500000n
|
|
47
|
+
* parseUSDC("10") // 10000000n
|
|
48
|
+
*/
|
|
49
|
+
function parseUSDC(amount) {
|
|
50
|
+
const [whole = '0', fractional = ''] = amount.split('.');
|
|
51
|
+
const paddedFractional = fractional.padEnd(exports.USDC_DECIMALS, '0').slice(0, exports.USDC_DECIMALS);
|
|
52
|
+
return BigInt(whole) * exports.USDC_MULTIPLIER + BigInt(paddedFractional);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get USDC amount with both raw and formatted values
|
|
56
|
+
* @param amount Raw USDC amount or string
|
|
57
|
+
* @returns USDCAmount object
|
|
58
|
+
*/
|
|
59
|
+
function getUSDCAmount(amount) {
|
|
60
|
+
const raw = typeof amount === 'string' ? parseUSDC(amount) : amount;
|
|
61
|
+
return {
|
|
62
|
+
raw,
|
|
63
|
+
formatted: formatUSDC(raw),
|
|
64
|
+
decimals: exports.USDC_DECIMALS,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Validate Ethereum address
|
|
69
|
+
* @param address Address to validate
|
|
70
|
+
* @returns True if valid
|
|
71
|
+
*/
|
|
72
|
+
function isValidAddress(address) {
|
|
73
|
+
return /^0x[a-fA-F0-9]{40}$/.test(address);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Format Ethereum address (checksum)
|
|
77
|
+
* @param address Address to format
|
|
78
|
+
* @returns Checksummed address
|
|
79
|
+
*/
|
|
80
|
+
function formatAddress(address) {
|
|
81
|
+
if (!isValidAddress(address)) {
|
|
82
|
+
throw new Error('Invalid Ethereum address');
|
|
83
|
+
}
|
|
84
|
+
// Simple checksum - in production, use ethers.getAddress()
|
|
85
|
+
return address.toLowerCase();
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Shorten address for display
|
|
89
|
+
* @param address Full address
|
|
90
|
+
* @param chars Number of characters to show on each side
|
|
91
|
+
* @returns Shortened address
|
|
92
|
+
* @example
|
|
93
|
+
* shortenAddress("0x1234567890123456789012345678901234567890") // "0x1234...7890"
|
|
94
|
+
*/
|
|
95
|
+
function shortenAddress(address, chars = 4) {
|
|
96
|
+
if (!isValidAddress(address)) {
|
|
97
|
+
return address;
|
|
98
|
+
}
|
|
99
|
+
return `${address.substring(0, chars + 2)}...${address.substring(42 - chars)}`;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Format transaction hash for display
|
|
103
|
+
* @param hash Transaction hash
|
|
104
|
+
* @param chars Number of characters to show on each side
|
|
105
|
+
* @returns Shortened hash
|
|
106
|
+
*/
|
|
107
|
+
function shortenTxHash(hash, chars = 6) {
|
|
108
|
+
if (!hash || hash.length < 10) {
|
|
109
|
+
return hash;
|
|
110
|
+
}
|
|
111
|
+
return `${hash.substring(0, chars + 2)}...${hash.substring(hash.length - chars)}`;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Convert Wei to Ether
|
|
115
|
+
* @param wei Amount in Wei
|
|
116
|
+
* @returns Amount in Ether as string
|
|
117
|
+
*/
|
|
118
|
+
function formatEther(wei) {
|
|
119
|
+
const ether = wei / BigInt(10 ** 18);
|
|
120
|
+
const remainder = wei % BigInt(10 ** 18);
|
|
121
|
+
const remainderStr = remainder.toString().padStart(18, '0');
|
|
122
|
+
return `${ether}.${remainderStr}`;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Parse Ether to Wei
|
|
126
|
+
* @param ether Amount in Ether as string
|
|
127
|
+
* @returns Amount in Wei
|
|
128
|
+
*/
|
|
129
|
+
function parseEther(ether) {
|
|
130
|
+
const [whole = '0', fractional = ''] = ether.split('.');
|
|
131
|
+
const paddedFractional = fractional.padEnd(18, '0').slice(0, 18);
|
|
132
|
+
return BigInt(whole) * BigInt(10 ** 18) + BigInt(paddedFractional);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get chain name from chain ID
|
|
136
|
+
* @param chainId Chain ID
|
|
137
|
+
* @returns Chain name
|
|
138
|
+
*/
|
|
139
|
+
function getChainName(chainId) {
|
|
140
|
+
const chains = {
|
|
141
|
+
33529: 'Varity L3',
|
|
142
|
+
421614: 'Arbitrum Sepolia',
|
|
143
|
+
42161: 'Arbitrum One',
|
|
144
|
+
1: 'Ethereum Mainnet',
|
|
145
|
+
11155111: 'Sepolia',
|
|
146
|
+
};
|
|
147
|
+
return chains[chainId] || `Chain ${chainId}`;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get block explorer URL
|
|
151
|
+
* @param chainId Chain ID
|
|
152
|
+
* @returns Block explorer URL
|
|
153
|
+
*/
|
|
154
|
+
function getBlockExplorerUrl(chainId) {
|
|
155
|
+
const explorers = {
|
|
156
|
+
33529: 'https://explorer.varity.network',
|
|
157
|
+
421614: 'https://sepolia.arbiscan.io',
|
|
158
|
+
42161: 'https://arbiscan.io',
|
|
159
|
+
1: 'https://etherscan.io',
|
|
160
|
+
11155111: 'https://sepolia.etherscan.io',
|
|
161
|
+
};
|
|
162
|
+
return explorers[chainId] || '';
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get transaction URL in block explorer
|
|
166
|
+
* @param chainId Chain ID
|
|
167
|
+
* @param txHash Transaction hash
|
|
168
|
+
* @returns Transaction URL
|
|
169
|
+
*/
|
|
170
|
+
function getTxUrl(chainId, txHash) {
|
|
171
|
+
const explorerUrl = getBlockExplorerUrl(chainId);
|
|
172
|
+
return explorerUrl ? `${explorerUrl}/tx/${txHash}` : '';
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Get address URL in block explorer
|
|
176
|
+
* @param chainId Chain ID
|
|
177
|
+
* @param address Address
|
|
178
|
+
* @returns Address URL
|
|
179
|
+
*/
|
|
180
|
+
function getAddressUrl(chainId, address) {
|
|
181
|
+
const explorerUrl = getBlockExplorerUrl(chainId);
|
|
182
|
+
return explorerUrl ? `${explorerUrl}/address/${address}` : '';
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Format timestamp to date string
|
|
186
|
+
* @param timestamp Unix timestamp in seconds
|
|
187
|
+
* @returns Formatted date string
|
|
188
|
+
*/
|
|
189
|
+
function formatTimestamp(timestamp) {
|
|
190
|
+
return new Date(timestamp * 1000).toLocaleString();
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Format gas amount for display
|
|
194
|
+
* @param gas Gas amount in wei
|
|
195
|
+
* @returns Formatted gas string
|
|
196
|
+
*/
|
|
197
|
+
function formatGas(gas) {
|
|
198
|
+
const gwei = gas / BigInt(10 ** 9);
|
|
199
|
+
const remainder = gas % BigInt(10 ** 9);
|
|
200
|
+
if (remainder === BigInt(0)) {
|
|
201
|
+
return `${gwei} Gwei`;
|
|
202
|
+
}
|
|
203
|
+
const decimal = Number(remainder) / 10 ** 9;
|
|
204
|
+
return `${Number(gwei) + decimal} Gwei`;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Calculate percentage
|
|
208
|
+
* @param value Current value
|
|
209
|
+
* @param total Total value
|
|
210
|
+
* @param decimals Number of decimal places
|
|
211
|
+
* @returns Percentage string
|
|
212
|
+
*/
|
|
213
|
+
function formatPercentage(value, total, decimals = 2) {
|
|
214
|
+
if (total === 0)
|
|
215
|
+
return '0%';
|
|
216
|
+
const percentage = (value / total) * 100;
|
|
217
|
+
return `${percentage.toFixed(decimals)}%`;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Format large numbers with K, M, B suffixes
|
|
221
|
+
* @param num Number to format
|
|
222
|
+
* @param decimals Number of decimal places
|
|
223
|
+
* @returns Formatted number string
|
|
224
|
+
*/
|
|
225
|
+
function formatNumber(num, decimals = 2) {
|
|
226
|
+
if (num >= 1000000000) {
|
|
227
|
+
return `${(num / 1000000000).toFixed(decimals)}B`;
|
|
228
|
+
}
|
|
229
|
+
if (num >= 1000000) {
|
|
230
|
+
return `${(num / 1000000).toFixed(decimals)}M`;
|
|
231
|
+
}
|
|
232
|
+
if (num >= 1000) {
|
|
233
|
+
return `${(num / 1000).toFixed(decimals)}K`;
|
|
234
|
+
}
|
|
235
|
+
return num.toFixed(decimals);
|
|
236
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Varity S3-Compatible Client
|
|
3
|
+
*
|
|
4
|
+
* AWS SDK-compatible client for Varity's decentralized storage infrastructure.
|
|
5
|
+
* Supports standard S3 operations with Filecoin/IPFS backend.
|
|
6
|
+
*
|
|
7
|
+
* @module @varity-labs/client-js
|
|
8
|
+
*/
|
|
9
|
+
import { S3Client, S3ClientConfig, PutObjectCommand, GetObjectCommand, DeleteObjectCommand, ListObjectsV2Command, HeadObjectCommand, CreateBucketCommand, DeleteBucketCommand, ListBucketsCommand, CopyObjectCommand, PutObjectCommandInput, GetObjectCommandInput, DeleteObjectCommandInput, ListObjectsV2CommandInput, HeadObjectCommandInput, CreateBucketCommandInput, DeleteBucketCommandInput, CopyObjectCommandInput } from '@aws-sdk/client-s3';
|
|
10
|
+
export interface VarityS3ClientConfig extends Omit<S3ClientConfig, 'endpoint'> {
|
|
11
|
+
endpoint?: string;
|
|
12
|
+
gatewayType?: 's3' | 'gcs';
|
|
13
|
+
network?: 'arbitrum-sepolia' | 'arbitrum-one' | 'mainnet';
|
|
14
|
+
storageBackend?: 'filecoin-ipfs' | 'filecoin-lighthouse';
|
|
15
|
+
encryptionEnabled?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Varity S3 Client
|
|
19
|
+
*
|
|
20
|
+
* Extends AWS S3Client with Varity-specific configurations and optimizations
|
|
21
|
+
* for decentralized storage infrastructure.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const client = new VarityS3Client({
|
|
26
|
+
* credentials: {
|
|
27
|
+
* accessKeyId: 'YOUR_ACCESS_KEY',
|
|
28
|
+
* secretAccessKey: 'YOUR_SECRET_KEY'
|
|
29
|
+
* },
|
|
30
|
+
* network: 'arbitrum-sepolia'
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Upload object
|
|
34
|
+
* await client.putObject({
|
|
35
|
+
* Bucket: 'my-bucket',
|
|
36
|
+
* Key: 'my-file.txt',
|
|
37
|
+
* Body: 'Hello, Varity!'
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Download object
|
|
41
|
+
* const response = await client.getObject({
|
|
42
|
+
* Bucket: 'my-bucket',
|
|
43
|
+
* Key: 'my-file.txt'
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare class VarityS3Client extends S3Client {
|
|
48
|
+
private readonly gatewayType;
|
|
49
|
+
private readonly network;
|
|
50
|
+
private readonly storageBackend;
|
|
51
|
+
private readonly encryptionEnabled;
|
|
52
|
+
constructor(config?: VarityS3ClientConfig);
|
|
53
|
+
/**
|
|
54
|
+
* Get default endpoint based on gateway type
|
|
55
|
+
*/
|
|
56
|
+
private static getDefaultEndpoint;
|
|
57
|
+
/**
|
|
58
|
+
* Upload object to Varity storage
|
|
59
|
+
*/
|
|
60
|
+
putObject(params: PutObjectCommandInput): Promise<any>;
|
|
61
|
+
/**
|
|
62
|
+
* Download object from Varity storage
|
|
63
|
+
*/
|
|
64
|
+
getObject(params: GetObjectCommandInput): Promise<any>;
|
|
65
|
+
/**
|
|
66
|
+
* Delete object from Varity storage
|
|
67
|
+
*/
|
|
68
|
+
deleteObject(params: DeleteObjectCommandInput): Promise<any>;
|
|
69
|
+
/**
|
|
70
|
+
* List objects in bucket
|
|
71
|
+
*/
|
|
72
|
+
listObjects(params: ListObjectsV2CommandInput): Promise<any>;
|
|
73
|
+
/**
|
|
74
|
+
* Get object metadata
|
|
75
|
+
*/
|
|
76
|
+
headObject(params: HeadObjectCommandInput): Promise<any>;
|
|
77
|
+
/**
|
|
78
|
+
* Create bucket
|
|
79
|
+
*/
|
|
80
|
+
createBucket(params: CreateBucketCommandInput): Promise<any>;
|
|
81
|
+
/**
|
|
82
|
+
* Delete bucket
|
|
83
|
+
*/
|
|
84
|
+
deleteBucket(params: DeleteBucketCommandInput): Promise<any>;
|
|
85
|
+
/**
|
|
86
|
+
* List all buckets
|
|
87
|
+
*/
|
|
88
|
+
listBuckets(): Promise<any>;
|
|
89
|
+
/**
|
|
90
|
+
* Copy object
|
|
91
|
+
*/
|
|
92
|
+
copyObject(params: CopyObjectCommandInput): Promise<any>;
|
|
93
|
+
/**
|
|
94
|
+
* Generate presigned URL for object access
|
|
95
|
+
*/
|
|
96
|
+
getSignedUrl(command: PutObjectCommand | GetObjectCommand, expiresIn?: number): Promise<string>;
|
|
97
|
+
/**
|
|
98
|
+
* Get client configuration
|
|
99
|
+
*/
|
|
100
|
+
getConfig(): {
|
|
101
|
+
gatewayType: "s3" | "gcs";
|
|
102
|
+
network: string;
|
|
103
|
+
storageBackend: string;
|
|
104
|
+
encryptionEnabled: boolean;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Stream upload for large files
|
|
108
|
+
*/
|
|
109
|
+
uploadStream(bucket: string, key: string, stream: ReadableStream | NodeJS.ReadableStream, metadata?: Record<string, string>): Promise<any>;
|
|
110
|
+
/**
|
|
111
|
+
* Stream download for large files
|
|
112
|
+
*/
|
|
113
|
+
downloadStream(bucket: string, key: string): Promise<any>;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Export commonly used types
|
|
117
|
+
*/
|
|
118
|
+
export { PutObjectCommand, GetObjectCommand, DeleteObjectCommand, ListObjectsV2Command, HeadObjectCommand, CreateBucketCommand, DeleteBucketCommand, ListBucketsCommand, CopyObjectCommand, type PutObjectCommandInput, type GetObjectCommandInput, type DeleteObjectCommandInput, type ListObjectsV2CommandInput, type HeadObjectCommandInput, type CreateBucketCommandInput, type DeleteBucketCommandInput, type CopyObjectCommandInput };
|
|
119
|
+
export default VarityS3Client;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Varity S3-Compatible Client
|
|
4
|
+
*
|
|
5
|
+
* AWS SDK-compatible client for Varity's decentralized storage infrastructure.
|
|
6
|
+
* Supports standard S3 operations with Filecoin/IPFS backend.
|
|
7
|
+
*
|
|
8
|
+
* @module @varity/client-js
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.CopyObjectCommand = exports.ListBucketsCommand = exports.DeleteBucketCommand = exports.CreateBucketCommand = exports.HeadObjectCommand = exports.ListObjectsV2Command = exports.DeleteObjectCommand = exports.GetObjectCommand = exports.PutObjectCommand = exports.VarityS3Client = void 0;
|
|
12
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
13
|
+
Object.defineProperty(exports, "PutObjectCommand", { enumerable: true, get: function () { return client_s3_1.PutObjectCommand; } });
|
|
14
|
+
Object.defineProperty(exports, "GetObjectCommand", { enumerable: true, get: function () { return client_s3_1.GetObjectCommand; } });
|
|
15
|
+
Object.defineProperty(exports, "DeleteObjectCommand", { enumerable: true, get: function () { return client_s3_1.DeleteObjectCommand; } });
|
|
16
|
+
Object.defineProperty(exports, "ListObjectsV2Command", { enumerable: true, get: function () { return client_s3_1.ListObjectsV2Command; } });
|
|
17
|
+
Object.defineProperty(exports, "HeadObjectCommand", { enumerable: true, get: function () { return client_s3_1.HeadObjectCommand; } });
|
|
18
|
+
Object.defineProperty(exports, "CreateBucketCommand", { enumerable: true, get: function () { return client_s3_1.CreateBucketCommand; } });
|
|
19
|
+
Object.defineProperty(exports, "DeleteBucketCommand", { enumerable: true, get: function () { return client_s3_1.DeleteBucketCommand; } });
|
|
20
|
+
Object.defineProperty(exports, "ListBucketsCommand", { enumerable: true, get: function () { return client_s3_1.ListBucketsCommand; } });
|
|
21
|
+
Object.defineProperty(exports, "CopyObjectCommand", { enumerable: true, get: function () { return client_s3_1.CopyObjectCommand; } });
|
|
22
|
+
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
23
|
+
/**
|
|
24
|
+
* Varity S3 Client
|
|
25
|
+
*
|
|
26
|
+
* Extends AWS S3Client with Varity-specific configurations and optimizations
|
|
27
|
+
* for decentralized storage infrastructure.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const client = new VarityS3Client({
|
|
32
|
+
* credentials: {
|
|
33
|
+
* accessKeyId: 'YOUR_ACCESS_KEY',
|
|
34
|
+
* secretAccessKey: 'YOUR_SECRET_KEY'
|
|
35
|
+
* },
|
|
36
|
+
* network: 'arbitrum-sepolia'
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* // Upload object
|
|
40
|
+
* await client.putObject({
|
|
41
|
+
* Bucket: 'my-bucket',
|
|
42
|
+
* Key: 'my-file.txt',
|
|
43
|
+
* Body: 'Hello, Varity!'
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* // Download object
|
|
47
|
+
* const response = await client.getObject({
|
|
48
|
+
* Bucket: 'my-bucket',
|
|
49
|
+
* Key: 'my-file.txt'
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
class VarityS3Client extends client_s3_1.S3Client {
|
|
54
|
+
constructor(config = {}) {
|
|
55
|
+
const endpoint = config.endpoint || VarityS3Client.getDefaultEndpoint(config.gatewayType);
|
|
56
|
+
const region = config.region || 'us-east-1';
|
|
57
|
+
super({
|
|
58
|
+
...config,
|
|
59
|
+
endpoint,
|
|
60
|
+
region,
|
|
61
|
+
forcePathStyle: true, // Required for S3-compatible APIs
|
|
62
|
+
});
|
|
63
|
+
this.gatewayType = config.gatewayType || 's3';
|
|
64
|
+
this.network = config.network || 'arbitrum-sepolia';
|
|
65
|
+
this.storageBackend = config.storageBackend || 'filecoin-ipfs';
|
|
66
|
+
this.encryptionEnabled = config.encryptionEnabled ?? true;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get default endpoint based on gateway type
|
|
70
|
+
*/
|
|
71
|
+
static getDefaultEndpoint(gatewayType) {
|
|
72
|
+
return gatewayType === 'gcs'
|
|
73
|
+
? 'http://localhost:8080' // GCS gateway default port
|
|
74
|
+
: 'http://localhost:3001'; // S3 gateway default port
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Upload object to Varity storage
|
|
78
|
+
*/
|
|
79
|
+
async putObject(params) {
|
|
80
|
+
const command = new client_s3_1.PutObjectCommand(params);
|
|
81
|
+
return this.send(command);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Download object from Varity storage
|
|
85
|
+
*/
|
|
86
|
+
async getObject(params) {
|
|
87
|
+
const command = new client_s3_1.GetObjectCommand(params);
|
|
88
|
+
return this.send(command);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Delete object from Varity storage
|
|
92
|
+
*/
|
|
93
|
+
async deleteObject(params) {
|
|
94
|
+
const command = new client_s3_1.DeleteObjectCommand(params);
|
|
95
|
+
return this.send(command);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* List objects in bucket
|
|
99
|
+
*/
|
|
100
|
+
async listObjects(params) {
|
|
101
|
+
const command = new client_s3_1.ListObjectsV2Command(params);
|
|
102
|
+
return this.send(command);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get object metadata
|
|
106
|
+
*/
|
|
107
|
+
async headObject(params) {
|
|
108
|
+
const command = new client_s3_1.HeadObjectCommand(params);
|
|
109
|
+
return this.send(command);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Create bucket
|
|
113
|
+
*/
|
|
114
|
+
async createBucket(params) {
|
|
115
|
+
const command = new client_s3_1.CreateBucketCommand(params);
|
|
116
|
+
return this.send(command);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Delete bucket
|
|
120
|
+
*/
|
|
121
|
+
async deleteBucket(params) {
|
|
122
|
+
const command = new client_s3_1.DeleteBucketCommand(params);
|
|
123
|
+
return this.send(command);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* List all buckets
|
|
127
|
+
*/
|
|
128
|
+
async listBuckets() {
|
|
129
|
+
const command = new client_s3_1.ListBucketsCommand({});
|
|
130
|
+
return this.send(command);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Copy object
|
|
134
|
+
*/
|
|
135
|
+
async copyObject(params) {
|
|
136
|
+
const command = new client_s3_1.CopyObjectCommand(params);
|
|
137
|
+
return this.send(command);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Generate presigned URL for object access
|
|
141
|
+
*/
|
|
142
|
+
async getSignedUrl(command, expiresIn = 3600) {
|
|
143
|
+
return (0, s3_request_presigner_1.getSignedUrl)(this, command, { expiresIn });
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get client configuration
|
|
147
|
+
*/
|
|
148
|
+
getConfig() {
|
|
149
|
+
return {
|
|
150
|
+
gatewayType: this.gatewayType,
|
|
151
|
+
network: this.network,
|
|
152
|
+
storageBackend: this.storageBackend,
|
|
153
|
+
encryptionEnabled: this.encryptionEnabled
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Stream upload for large files
|
|
158
|
+
*/
|
|
159
|
+
async uploadStream(bucket, key, stream, metadata) {
|
|
160
|
+
return this.putObject({
|
|
161
|
+
Bucket: bucket,
|
|
162
|
+
Key: key,
|
|
163
|
+
Body: stream,
|
|
164
|
+
Metadata: metadata
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Stream download for large files
|
|
169
|
+
*/
|
|
170
|
+
async downloadStream(bucket, key) {
|
|
171
|
+
const response = await this.getObject({
|
|
172
|
+
Bucket: bucket,
|
|
173
|
+
Key: key
|
|
174
|
+
});
|
|
175
|
+
return response.Body;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.VarityS3Client = VarityS3Client;
|
|
179
|
+
exports.default = VarityS3Client;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet Manager - Handle wallet connections and operations
|
|
3
|
+
*/
|
|
4
|
+
import { type ThirdwebClient, type Chain } from 'thirdweb';
|
|
5
|
+
import { type Account } from 'thirdweb/wallets';
|
|
6
|
+
import type { WalletConnectionOptions, WalletInfo } from '../types';
|
|
7
|
+
/**
|
|
8
|
+
* WalletManager - Manage wallet connections and operations
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Connect MetaMask
|
|
13
|
+
* const account = await walletManager.connect({ walletType: 'metamask' });
|
|
14
|
+
*
|
|
15
|
+
* // Get balance
|
|
16
|
+
* const balance = await walletManager.getBalance();
|
|
17
|
+
*
|
|
18
|
+
* // Disconnect
|
|
19
|
+
* walletManager.disconnect();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class WalletManager {
|
|
23
|
+
private readonly client;
|
|
24
|
+
private readonly chain;
|
|
25
|
+
private activeWallet;
|
|
26
|
+
private activeAccount;
|
|
27
|
+
constructor(client: ThirdwebClient, chain: Chain);
|
|
28
|
+
/**
|
|
29
|
+
* Connect wallet
|
|
30
|
+
* @param options Wallet connection options
|
|
31
|
+
* @returns Connected account
|
|
32
|
+
*/
|
|
33
|
+
connect(options: WalletConnectionOptions): Promise<Account>;
|
|
34
|
+
/**
|
|
35
|
+
* Disconnect wallet
|
|
36
|
+
*/
|
|
37
|
+
disconnect(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Get connected account
|
|
40
|
+
* @returns Active account or null
|
|
41
|
+
*/
|
|
42
|
+
getAccount(): Account | null;
|
|
43
|
+
/**
|
|
44
|
+
* Check if wallet is connected
|
|
45
|
+
* @returns True if connected
|
|
46
|
+
*/
|
|
47
|
+
isConnected(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Get wallet address
|
|
50
|
+
* @returns Wallet address or null
|
|
51
|
+
*/
|
|
52
|
+
getAddress(): string | null;
|
|
53
|
+
/**
|
|
54
|
+
* Get wallet balance (native currency)
|
|
55
|
+
* @returns Balance in wei/smallest unit
|
|
56
|
+
*/
|
|
57
|
+
getBalance(): Promise<bigint>;
|
|
58
|
+
/**
|
|
59
|
+
* Get wallet info with balance
|
|
60
|
+
* @returns Wallet information
|
|
61
|
+
*/
|
|
62
|
+
getWalletInfo(): Promise<WalletInfo>;
|
|
63
|
+
/**
|
|
64
|
+
* Sign message
|
|
65
|
+
* @param message Message to sign
|
|
66
|
+
* @returns Signature
|
|
67
|
+
*/
|
|
68
|
+
signMessage(message: string): Promise<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Sign typed data (EIP-712)
|
|
71
|
+
* @param domain Domain data
|
|
72
|
+
* @param types Type definitions
|
|
73
|
+
* @param value Value to sign
|
|
74
|
+
* @returns Signature
|
|
75
|
+
*/
|
|
76
|
+
signTypedData(domain: any, types: any, value: any): Promise<string>;
|
|
77
|
+
/**
|
|
78
|
+
* Switch chain
|
|
79
|
+
* @param chainId Chain ID to switch to
|
|
80
|
+
*/
|
|
81
|
+
switchChain(chainId: number): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Get chain ID from wallet
|
|
84
|
+
* @returns Current chain ID
|
|
85
|
+
*/
|
|
86
|
+
getChainId(): Promise<number>;
|
|
87
|
+
/**
|
|
88
|
+
* Send native currency transaction
|
|
89
|
+
* @param to Recipient address
|
|
90
|
+
* @param amount Amount to send (in wei/smallest unit)
|
|
91
|
+
* @returns Transaction hash
|
|
92
|
+
*/
|
|
93
|
+
sendTransaction(to: string, amount: bigint): Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
* Get transaction count (nonce)
|
|
96
|
+
* @returns Transaction count
|
|
97
|
+
*/
|
|
98
|
+
getTransactionCount(): Promise<number>;
|
|
99
|
+
/**
|
|
100
|
+
* Format balance with decimals
|
|
101
|
+
* @param balance Balance in smallest unit
|
|
102
|
+
* @param decimals Number of decimals
|
|
103
|
+
* @returns Formatted balance string
|
|
104
|
+
*/
|
|
105
|
+
private formatBalance;
|
|
106
|
+
/**
|
|
107
|
+
* Request wallet permissions
|
|
108
|
+
* @param permissions Permissions to request
|
|
109
|
+
*/
|
|
110
|
+
requestPermissions(permissions: string[]): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Add custom token to wallet
|
|
113
|
+
* @param tokenAddress Token contract address
|
|
114
|
+
* @param symbol Token symbol
|
|
115
|
+
* @param decimals Token decimals
|
|
116
|
+
* @param image Token image URL
|
|
117
|
+
*/
|
|
118
|
+
addToken(tokenAddress: string, symbol: string, decimals: number, image?: string): Promise<void>;
|
|
119
|
+
}
|
|
120
|
+
export default WalletManager;
|