@gvnrdao/dh-sdk 0.0.166 → 0.0.205
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 +86 -5
- package/browser/dist/397.browser.js +1 -1
- package/browser/dist/833.browser.js +1 -1
- package/browser/dist/browser.js +1 -13
- package/browser/dist/browser.js.LICENSE.txt +1 -70
- package/browser/dist/index.d.ts +3 -4
- package/browser/dist/index.d.ts.map +1 -1
- package/browser/dist/index.js +4 -3
- package/dist/constants/chunks/contract-abis.d.ts +7 -0
- package/dist/constants/chunks/deployment-addresses.d.ts +68 -0
- package/dist/constants/chunks/encrypted-provider-params.d.ts +21 -0
- package/dist/constants/chunks/environment.browser.d.ts +45 -0
- package/dist/constants/chunks/environment.d.ts +57 -0
- package/dist/constants/chunks/network-configs.d.ts +65 -0
- package/dist/constants/chunks/sdk-config.d.ts +33 -0
- package/dist/constants/chunks/sdk-limits.d.ts +66 -0
- package/dist/constants/index.d.ts +15 -0
- package/dist/graphs/client.d.ts +19 -0
- package/dist/graphs/diamond-hands.d.ts +248 -0
- package/dist/index.d.ts +47 -7391
- package/dist/index.js +4525 -16860
- package/dist/index.mjs +4489 -16801
- package/dist/interfaces/chunks/btc.i.d.ts +36 -0
- package/dist/interfaces/chunks/config.i.d.ts +250 -0
- package/dist/interfaces/chunks/contract-interactions.i.d.ts +64 -0
- package/dist/interfaces/chunks/contract-types.i.d.ts +165 -0
- package/dist/interfaces/chunks/lit-actions-results.i.d.ts +165 -0
- package/dist/interfaces/chunks/lit-actions.i.d.ts +98 -0
- package/dist/interfaces/chunks/loan-operations.i.d.ts +332 -0
- package/dist/interfaces/chunks/pkp-integration.i.d.ts +87 -0
- package/dist/interfaces/chunks/position-query.i.d.ts +76 -0
- package/dist/interfaces/chunks/requests.i.d.ts +55 -0
- package/dist/interfaces/chunks/ucd-minting.i.d.ts +34 -0
- package/dist/interfaces/chunks/utility.i.d.ts +64 -0
- package/dist/interfaces/index.d.ts +17 -0
- package/dist/modules/bitcoin/bitcoin-operations.module.d.ts +223 -0
- package/dist/modules/cache/cache-manager.module.d.ts +92 -0
- package/dist/modules/contract/contract-manager.module.d.ts +136 -0
- package/dist/modules/diamond-hands-sdk.d.ts +669 -0
- package/dist/modules/loan/loan-creator.module.d.ts +143 -0
- package/dist/modules/loan/loan-query.module.d.ts +206 -0
- package/dist/modules/mock/mock-token-manager.module.d.ts +83 -0
- package/dist/modules/pkp/pkp-manager.module.d.ts +136 -0
- package/dist/protocol/protocol-pause.d.ts +19 -0
- package/dist/server.d.ts +17 -0
- package/dist/server.js +285 -0
- package/dist/server.mjs +242 -0
- package/dist/types/authorization-params.d.ts +160 -0
- package/dist/types/branded/domain-values.d.ts +138 -0
- package/dist/types/branded/ids.d.ts +23 -0
- package/dist/types/event-types.d.ts +235 -0
- package/dist/types/graph-dtos.d.ts +228 -0
- package/dist/types/loanStatus.d.ts +10 -0
- package/dist/types/result.d.ts +120 -0
- package/dist/utils/bitcoin-address-cache.utils.d.ts +87 -0
- package/dist/utils/bitcoin-provider.utils.d.ts +48 -0
- package/dist/utils/bitcoin-signature.d.ts +20 -0
- package/dist/utils/chunks/bitcoin-utils.d.ts +75 -0
- package/dist/utils/chunks/eip1559-broadcast.utils.d.ts +24 -0
- package/dist/utils/error-handler.d.ts +106 -0
- package/dist/utils/ethers-interop.utils.d.ts +146 -0
- package/dist/utils/extend-authorization.utils.d.ts +61 -0
- package/dist/utils/lit-signature.utils.d.ts +6 -0
- package/dist/utils/logger.utils.d.ts +142 -0
- package/dist/utils/mint-authorization.utils.d.ts +224 -0
- package/dist/utils/quantum-timing.d.ts +75 -0
- package/dist/utils/signature-tempering.utils.d.ts +31 -0
- package/dist/utils/telegram-messaging.utils.d.ts +188 -0
- package/package.json +43 -22
- package/dist/index.d.mts +0 -7392
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result type for standardized error handling across the SDK
|
|
3
|
+
*
|
|
4
|
+
* This is a discriminated union that provides type-safe error handling
|
|
5
|
+
* without throwing exceptions. Inspired by Rust's Result<T, E> type.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* async function createLoan(request: CreateLoanRequest): Promise<Result<LoanData, SDKError>> {
|
|
10
|
+
* try {
|
|
11
|
+
* const loan = await performCreation(request);
|
|
12
|
+
* return success(loan);
|
|
13
|
+
* } catch (error) {
|
|
14
|
+
* return failure(SDKError.from(error));
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* // Usage
|
|
19
|
+
* const result = await createLoan(request);
|
|
20
|
+
* if (result.success) {
|
|
21
|
+
* console.log('Loan created:', result.value);
|
|
22
|
+
* } else {
|
|
23
|
+
* console.error('Failed:', result.error);
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Success variant of Result<T, E>
|
|
29
|
+
*/
|
|
30
|
+
export interface Success<T> {
|
|
31
|
+
success: true;
|
|
32
|
+
value: T;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Failure variant of Result<T, E>
|
|
36
|
+
*/
|
|
37
|
+
export interface Failure<E> {
|
|
38
|
+
success: false;
|
|
39
|
+
error: E;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Result type - either Success<T> or Failure<E>
|
|
43
|
+
*/
|
|
44
|
+
export type Result<T, E = Error> = Success<T> | Failure<E>;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a successful Result
|
|
47
|
+
*/
|
|
48
|
+
export declare function success<T>(value: T): Success<T>;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a failed Result
|
|
51
|
+
*/
|
|
52
|
+
export declare function failure<E>(error: E): Failure<E>;
|
|
53
|
+
/**
|
|
54
|
+
* Type guard to check if Result is successful
|
|
55
|
+
*/
|
|
56
|
+
export declare function isSuccess<T, E>(result: Result<T, E>): result is Success<T>;
|
|
57
|
+
/**
|
|
58
|
+
* Type guard to check if Result is a failure
|
|
59
|
+
*/
|
|
60
|
+
export declare function isFailure<T, E>(result: Result<T, E>): result is Failure<E>;
|
|
61
|
+
/**
|
|
62
|
+
* Unwraps a Result, returning the value or throwing the error
|
|
63
|
+
*/
|
|
64
|
+
export declare function unwrap<T, E extends Error>(result: Result<T, E>): T;
|
|
65
|
+
/**
|
|
66
|
+
* Unwraps a Result, returning the value or a default
|
|
67
|
+
*/
|
|
68
|
+
export declare function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T;
|
|
69
|
+
/**
|
|
70
|
+
* Maps a Result<T, E> to Result<U, E> by applying a function to the success value
|
|
71
|
+
*/
|
|
72
|
+
export declare function map<T, U, E>(result: Result<T, E>, fn: (value: T) => U): Result<U, E>;
|
|
73
|
+
/**
|
|
74
|
+
* Maps a Result<T, E> to Result<T, F> by applying a function to the error value
|
|
75
|
+
*/
|
|
76
|
+
export declare function mapError<T, E, F>(result: Result<T, E>, fn: (error: E) => F): Result<T, F>;
|
|
77
|
+
/**
|
|
78
|
+
* Chains Result-returning operations together (flatMap)
|
|
79
|
+
*/
|
|
80
|
+
export declare function andThen<T, U, E>(result: Result<T, E>, fn: (value: T) => Result<U, E>): Result<U, E>;
|
|
81
|
+
/**
|
|
82
|
+
* Returns the first successful Result, or the last error if all fail
|
|
83
|
+
*/
|
|
84
|
+
export declare function firstSuccess<T, E>(results: Result<T, E>[]): Result<T, E>;
|
|
85
|
+
/**
|
|
86
|
+
* Collects all successful Results into an array
|
|
87
|
+
*/
|
|
88
|
+
export declare function collectSuccesses<T, E>(results: Result<T, E>[]): T[];
|
|
89
|
+
/**
|
|
90
|
+
* Collects all failures into an array
|
|
91
|
+
*/
|
|
92
|
+
export declare function collectFailures<T, E>(results: Result<T, E>[]): E[];
|
|
93
|
+
/**
|
|
94
|
+
* Combines multiple Results into a single Result containing an array
|
|
95
|
+
* If any Result fails, returns the first failure
|
|
96
|
+
*/
|
|
97
|
+
export declare function combine<T, E>(results: Result<T, E>[]): Result<T[], E>;
|
|
98
|
+
/**
|
|
99
|
+
* Wraps an async function that may throw into one that returns a Result
|
|
100
|
+
*/
|
|
101
|
+
export declare function tryCatch<T, E = Error>(fn: () => T, errorHandler?: (error: unknown) => E): Result<T, E>;
|
|
102
|
+
/**
|
|
103
|
+
* Async version of tryCatch
|
|
104
|
+
*/
|
|
105
|
+
export declare function tryCatchAsync<T, E = Error>(fn: () => Promise<T>, errorHandler?: (error: unknown) => E): Promise<Result<T, E>>;
|
|
106
|
+
/**
|
|
107
|
+
* Converts a Result to a Promise that rejects on failure
|
|
108
|
+
*/
|
|
109
|
+
export declare function toPromise<T, E extends Error>(result: Result<T, E>): Promise<T>;
|
|
110
|
+
/**
|
|
111
|
+
* Converts a Promise to a Result (will never reject)
|
|
112
|
+
*/
|
|
113
|
+
export declare function fromPromise<T, E = Error>(promise: Promise<T>, errorHandler?: (error: unknown) => E): Promise<Result<T, E>>;
|
|
114
|
+
/**
|
|
115
|
+
* Utility to match on a Result and handle both cases
|
|
116
|
+
*/
|
|
117
|
+
export declare function match<T, E, U>(result: Result<T, E>, handlers: {
|
|
118
|
+
success: (value: T) => U;
|
|
119
|
+
failure: (error: E) => U;
|
|
120
|
+
}): U;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bitcoin Address Derivation Cache Utility
|
|
3
|
+
* Implements LRU (Least Recently Used) caching for Bitcoin address derivation from PKP
|
|
4
|
+
* Avoids repeated SHA256+RIPEMD160 operations for the same PKP ID
|
|
5
|
+
*/
|
|
6
|
+
import type { BitcoinAddresses } from '../interfaces';
|
|
7
|
+
/**
|
|
8
|
+
* Cache statistics
|
|
9
|
+
*/
|
|
10
|
+
export interface AddressCacheStats {
|
|
11
|
+
size: number;
|
|
12
|
+
hits: number;
|
|
13
|
+
misses: number;
|
|
14
|
+
evictions: number;
|
|
15
|
+
hitRate: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Address cache configuration
|
|
19
|
+
*/
|
|
20
|
+
export interface AddressCacheConfig {
|
|
21
|
+
maxSize?: number;
|
|
22
|
+
ttlMs?: number;
|
|
23
|
+
debug?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* LRU Cache for Bitcoin address derivation
|
|
27
|
+
*
|
|
28
|
+
* Features:
|
|
29
|
+
* - TTL-based expiration
|
|
30
|
+
* - LRU eviction when max size reached
|
|
31
|
+
* - Hit/miss statistics tracking
|
|
32
|
+
* - Memory-efficient (stores only PKP ID and derived addresses)
|
|
33
|
+
*/
|
|
34
|
+
export declare class BitcoinAddressCache {
|
|
35
|
+
private cache;
|
|
36
|
+
private maxSize;
|
|
37
|
+
private ttlMs;
|
|
38
|
+
private debug;
|
|
39
|
+
private stats;
|
|
40
|
+
constructor(config?: AddressCacheConfig);
|
|
41
|
+
/**
|
|
42
|
+
* Get addresses from cache
|
|
43
|
+
* Returns null if not found or expired
|
|
44
|
+
*/
|
|
45
|
+
get(pkpId: string): BitcoinAddresses | null;
|
|
46
|
+
/**
|
|
47
|
+
* Set addresses in cache
|
|
48
|
+
* Evicts LRU entry if cache is full
|
|
49
|
+
*/
|
|
50
|
+
set(pkpId: string, value: BitcoinAddresses): void;
|
|
51
|
+
/**
|
|
52
|
+
* Check if entry is expired
|
|
53
|
+
*/
|
|
54
|
+
private isExpired;
|
|
55
|
+
/**
|
|
56
|
+
* Evict least recently used entry
|
|
57
|
+
*/
|
|
58
|
+
private evictLRU;
|
|
59
|
+
/**
|
|
60
|
+
* Clear all entries
|
|
61
|
+
*/
|
|
62
|
+
clear(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Get cache statistics
|
|
65
|
+
*/
|
|
66
|
+
getStats(): AddressCacheStats;
|
|
67
|
+
/**
|
|
68
|
+
* Get cache size
|
|
69
|
+
*/
|
|
70
|
+
size(): number;
|
|
71
|
+
/**
|
|
72
|
+
* Check if cache has entry
|
|
73
|
+
*/
|
|
74
|
+
has(pkpId: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Delete specific entry
|
|
77
|
+
*/
|
|
78
|
+
delete(pkpId: string): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Get all cached PKP IDs (for debugging)
|
|
81
|
+
*/
|
|
82
|
+
getKeys(): string[];
|
|
83
|
+
/**
|
|
84
|
+
* Clean expired entries
|
|
85
|
+
*/
|
|
86
|
+
cleanExpired(): number;
|
|
87
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bitcoin Provider Utilities
|
|
3
|
+
* Handles multi-provider consensus for Bitcoin blockchain queries
|
|
4
|
+
*/
|
|
5
|
+
import type { BitcoinProviderConfig } from '../interfaces/chunks/config.i';
|
|
6
|
+
import type { BitcoinBalanceResult } from '../interfaces/chunks/position-query.i';
|
|
7
|
+
/**
|
|
8
|
+
* Bitcoin Provider with consensus support
|
|
9
|
+
*/
|
|
10
|
+
export declare class BitcoinProvider {
|
|
11
|
+
private providers;
|
|
12
|
+
private consensusMode;
|
|
13
|
+
private debug;
|
|
14
|
+
constructor(configs: BitcoinProviderConfig[], consensusMode?: 'single' | 'majority', debug?: boolean);
|
|
15
|
+
/**
|
|
16
|
+
* Get UTXOs for a Bitcoin address with consensus
|
|
17
|
+
*/
|
|
18
|
+
getUnspentsFor(address: string): Promise<BitcoinBalanceResult>;
|
|
19
|
+
/**
|
|
20
|
+
* Get UTXOs from a single provider
|
|
21
|
+
*/
|
|
22
|
+
private getUnspentsSingle;
|
|
23
|
+
/**
|
|
24
|
+
* Check if a provider error is retryable
|
|
25
|
+
*/
|
|
26
|
+
private isRetryableProviderError;
|
|
27
|
+
/**
|
|
28
|
+
* Get UTXOs with 2-of-3 consensus
|
|
29
|
+
*/
|
|
30
|
+
private getUnspentsWithConsensus;
|
|
31
|
+
/**
|
|
32
|
+
* Find consensus among multiple provider results
|
|
33
|
+
*/
|
|
34
|
+
private findConsensus;
|
|
35
|
+
/**
|
|
36
|
+
* Create a signature for a UTXO set (for comparison)
|
|
37
|
+
*/
|
|
38
|
+
private getUTXOSetSignature;
|
|
39
|
+
private fetchUtxosFromProvider;
|
|
40
|
+
/**
|
|
41
|
+
* Get balance for an address (sum of UTXOs)
|
|
42
|
+
*/
|
|
43
|
+
getBalance(address: string): Promise<bigint>;
|
|
44
|
+
/**
|
|
45
|
+
* Check if an address has received at least a specific amount
|
|
46
|
+
*/
|
|
47
|
+
hasReceivedAmount(address: string, expectedAmount: bigint): Promise<boolean>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bitcoin Signature Utilities
|
|
3
|
+
*
|
|
4
|
+
* Converts Ethereum ECDSA signatures to Bitcoin DER format
|
|
5
|
+
*
|
|
6
|
+
* Trusted implementation from btc-always-signer.test.ts
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Convert Ethereum signature to Bitcoin DER format
|
|
10
|
+
*
|
|
11
|
+
* Handles BIP 62 normalization (low-s requirement) and DER encoding
|
|
12
|
+
*
|
|
13
|
+
* @param signature - Ethereum signature (hex string or {r, s, v} object)
|
|
14
|
+
* @returns DER-encoded signature as hex string
|
|
15
|
+
*/
|
|
16
|
+
export declare function convertEthereumSignatureToBitcoinDER(signature: string | {
|
|
17
|
+
r: string;
|
|
18
|
+
s: string;
|
|
19
|
+
v?: number;
|
|
20
|
+
}): string;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { BitcoinAddressCache } from "../bitcoin-address-cache.utils";
|
|
2
|
+
import type { BitcoinAddresses } from "../../interfaces";
|
|
3
|
+
/**
|
|
4
|
+
* Initialize the global address cache with sensible defaults
|
|
5
|
+
*/
|
|
6
|
+
export declare function initializeAddressCache(config?: {
|
|
7
|
+
maxSize?: number;
|
|
8
|
+
ttlMs?: number;
|
|
9
|
+
debug?: boolean;
|
|
10
|
+
}): void;
|
|
11
|
+
/**
|
|
12
|
+
* Get the global address cache instance
|
|
13
|
+
*/
|
|
14
|
+
export declare function getAddressCache(): BitcoinAddressCache | null;
|
|
15
|
+
/**
|
|
16
|
+
* Convert hex string to Uint8Array
|
|
17
|
+
* @param hexString Hex string
|
|
18
|
+
* @returns Uint8Array
|
|
19
|
+
*/
|
|
20
|
+
export declare const hexToUint8Array: (hexString: string) => Uint8Array;
|
|
21
|
+
/**
|
|
22
|
+
* SHA256 hash using Node.js crypto module
|
|
23
|
+
* @param data Uint8Array
|
|
24
|
+
* @returns Uint8Array
|
|
25
|
+
*/
|
|
26
|
+
export declare const sha256: (data: Uint8Array) => Uint8Array;
|
|
27
|
+
/**
|
|
28
|
+
* RIPEMD160 hash using native Web Crypto API
|
|
29
|
+
* @param data Uint8Array
|
|
30
|
+
* @returns Promise<Uint8Array>
|
|
31
|
+
*/
|
|
32
|
+
export declare const ripemd160: (data: Uint8Array) => Uint8Array;
|
|
33
|
+
/**
|
|
34
|
+
* Convert CryptoJS WordArray to Uint8Array (fallback for RIPEMD160)
|
|
35
|
+
* @param wordArray CryptoJS WordArray
|
|
36
|
+
* @returns Uint8Array
|
|
37
|
+
*/
|
|
38
|
+
export declare const wordArrayToUint8Array: (wordArray: any) => Uint8Array;
|
|
39
|
+
/**
|
|
40
|
+
* Generate a Bitcoin address from a PKP public key for regtest or mainnet.
|
|
41
|
+
* @param pkpPublicKey Hex string public key (with or without '0x' prefix)
|
|
42
|
+
* @param network "regtest" | "mainnet" | "testnet"
|
|
43
|
+
* @returns Bitcoin address (string)
|
|
44
|
+
*/
|
|
45
|
+
export declare function getBitcoinAddressFromPkp(pkpPublicKey: string, network?: "regtest" | "mainnet" | "testnet"): Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Generate multiple Bitcoin addresses from a PKP public key for different networks.
|
|
48
|
+
* Uses caching to avoid repeated SHA256+RIPEMD160 operations for the same PKP ID.
|
|
49
|
+
* @param pkpPublicKey Hex string public key (with or without '0x' prefix)
|
|
50
|
+
* @returns Object containing addresses for different networks
|
|
51
|
+
*/
|
|
52
|
+
export declare function getBitcoinAddressesFromPkp(pkpPublicKey: string): Promise<BitcoinAddresses>;
|
|
53
|
+
export declare class BitcoinUtils {
|
|
54
|
+
static validateAddress(address: string): boolean;
|
|
55
|
+
static formatTransaction(hash: string, amount: string, recipient: string): {
|
|
56
|
+
hash: string;
|
|
57
|
+
amount: string;
|
|
58
|
+
recipient: string;
|
|
59
|
+
timestamp: number;
|
|
60
|
+
};
|
|
61
|
+
static calculateFee(inputAmount: string, outputAmount: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Generate Bitcoin addresses from PKP public key
|
|
64
|
+
* @param pkpPublicKey PKP public key
|
|
65
|
+
* @param network Bitcoin network
|
|
66
|
+
* @returns Bitcoin address
|
|
67
|
+
*/
|
|
68
|
+
static getBitcoinAddress(pkpPublicKey: string, network?: "regtest" | "mainnet" | "testnet"): Promise<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Generate Bitcoin addresses for all networks
|
|
71
|
+
* @param pkpPublicKey PKP public key
|
|
72
|
+
* @returns Object with addresses for all networks
|
|
73
|
+
*/
|
|
74
|
+
static getAllBitcoinAddresses(pkpPublicKey: string): Promise<BitcoinAddresses>;
|
|
75
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EIP-1559 transaction broadcast helpers for paths that need explicit gas limits
|
|
3
|
+
* (e.g. large mintUCD) without manual signDigest / eth_sendRawTransaction.
|
|
4
|
+
*/
|
|
5
|
+
import { ethers as ethers5 } from "ethers";
|
|
6
|
+
import type { BigNumber, providers, Signer } from "ethers";
|
|
7
|
+
/** Observed mintUCD + LIT validation can exceed 7M gas; cap avoids block limit issues. */
|
|
8
|
+
export declare const MINT_UCD_GAS_CEILING: ethers5.BigNumber;
|
|
9
|
+
/** Headroom on eth_estimateGas (25%). */
|
|
10
|
+
export declare const MINT_UCD_ESTIMATE_MARGIN_BPS = 2500;
|
|
11
|
+
/**
|
|
12
|
+
* Returns gas limit with margin, capped, or null if estimateGas reverts/fails.
|
|
13
|
+
*/
|
|
14
|
+
export declare function estimateContractCallGasWithMargin(provider: providers.Provider, from: string, to: string, data: string, marginBps: number, ceiling: BigNumber): Promise<BigNumber | null>;
|
|
15
|
+
export declare function resolveEip1559FeeFields(provider: providers.Provider): Promise<{
|
|
16
|
+
maxFeePerGas: BigNumber;
|
|
17
|
+
maxPriorityFeePerGas: BigNumber;
|
|
18
|
+
}>;
|
|
19
|
+
export declare function sendEip1559Transaction(params: {
|
|
20
|
+
signer: Signer;
|
|
21
|
+
to: string;
|
|
22
|
+
data: string;
|
|
23
|
+
gasLimit: BigNumber;
|
|
24
|
+
}): Promise<ethers5.providers.TransactionResponse>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Production-Ready Error Handler for PKP Validation and Loan Creation
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Error categories for SDK operations
|
|
6
|
+
*/
|
|
7
|
+
export declare enum ErrorCategory {
|
|
8
|
+
CONFIGURATION = "CONFIGURATION",
|
|
9
|
+
INITIALIZATION = "INITIALIZATION",
|
|
10
|
+
NETWORK = "NETWORK",
|
|
11
|
+
CONTRACT = "CONTRACT",
|
|
12
|
+
PKP = "PKP",
|
|
13
|
+
BITCOIN = "BITCOIN",
|
|
14
|
+
AUTHORIZATION = "AUTHORIZATION",
|
|
15
|
+
VALIDATION = "VALIDATION",
|
|
16
|
+
TRANSACTION = "TRANSACTION",
|
|
17
|
+
SUBGRAPH = "SUBGRAPH",
|
|
18
|
+
CACHE = "CACHE",
|
|
19
|
+
UNKNOWN = "UNKNOWN"
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Error severity levels
|
|
23
|
+
*/
|
|
24
|
+
export declare enum ErrorSeverity {
|
|
25
|
+
LOW = "LOW",
|
|
26
|
+
MEDIUM = "MEDIUM",
|
|
27
|
+
HIGH = "HIGH",
|
|
28
|
+
CRITICAL = "CRITICAL"
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Modern SDK Error class with structured error handling
|
|
32
|
+
*/
|
|
33
|
+
export declare class SDKError extends Error {
|
|
34
|
+
readonly code: string;
|
|
35
|
+
readonly category: ErrorCategory;
|
|
36
|
+
readonly severity: ErrorSeverity;
|
|
37
|
+
readonly retryable: boolean;
|
|
38
|
+
readonly context?: Record<string, unknown>;
|
|
39
|
+
readonly originalError?: Error;
|
|
40
|
+
readonly cause?: unknown;
|
|
41
|
+
readonly timestamp: number;
|
|
42
|
+
constructor(params: {
|
|
43
|
+
code?: string;
|
|
44
|
+
message: string;
|
|
45
|
+
category: ErrorCategory;
|
|
46
|
+
severity: ErrorSeverity;
|
|
47
|
+
retryable?: boolean;
|
|
48
|
+
context?: Record<string, unknown>;
|
|
49
|
+
originalError?: Error;
|
|
50
|
+
cause?: unknown;
|
|
51
|
+
});
|
|
52
|
+
/**
|
|
53
|
+
* Convert to JSON-serializable format
|
|
54
|
+
*/
|
|
55
|
+
toJSON(): {
|
|
56
|
+
name: string;
|
|
57
|
+
code: string;
|
|
58
|
+
message: string;
|
|
59
|
+
category: ErrorCategory;
|
|
60
|
+
severity: ErrorSeverity;
|
|
61
|
+
retryable: boolean;
|
|
62
|
+
context: Record<string, unknown> | undefined;
|
|
63
|
+
timestamp: number;
|
|
64
|
+
stack: string | undefined;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export interface ErrorContext {
|
|
68
|
+
operation: string;
|
|
69
|
+
network: string;
|
|
70
|
+
timestamp: number;
|
|
71
|
+
attemptNumber?: number;
|
|
72
|
+
duration?: number;
|
|
73
|
+
additionalInfo?: Record<string, any>;
|
|
74
|
+
}
|
|
75
|
+
export interface PKPValidationError {
|
|
76
|
+
code: string;
|
|
77
|
+
message: string;
|
|
78
|
+
context: ErrorContext;
|
|
79
|
+
severity: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
|
|
80
|
+
retryable: boolean;
|
|
81
|
+
userMessage?: string;
|
|
82
|
+
}
|
|
83
|
+
export declare class PKPErrorHandler {
|
|
84
|
+
static classifyError(error: any, context: ErrorContext): PKPValidationError;
|
|
85
|
+
static shouldRetry(error: PKPValidationError, attemptNumber: number, maxAttempts: number): boolean;
|
|
86
|
+
static getRetryDelay(error: PKPValidationError, attemptNumber: number): number;
|
|
87
|
+
static logError(error: PKPValidationError, context?: {
|
|
88
|
+
userId?: string;
|
|
89
|
+
sessionId?: string;
|
|
90
|
+
}): {
|
|
91
|
+
timestamp: string;
|
|
92
|
+
errorCode: string;
|
|
93
|
+
severity: "LOW" | "MEDIUM" | "HIGH" | "CRITICAL";
|
|
94
|
+
operation: string;
|
|
95
|
+
network: string;
|
|
96
|
+
attemptNumber: number | undefined;
|
|
97
|
+
duration: number | undefined;
|
|
98
|
+
retryable: boolean;
|
|
99
|
+
message: string;
|
|
100
|
+
userId: string | undefined;
|
|
101
|
+
sessionId: string | undefined;
|
|
102
|
+
};
|
|
103
|
+
static createUserFriendlyMessage(error: PKPValidationError, context?: {
|
|
104
|
+
isRetrying?: boolean;
|
|
105
|
+
}): string;
|
|
106
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ethers v5/v6 Interop Utilities
|
|
3
|
+
* Systematic normalization of BigNumber fields for cross-version compatibility
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Normalize a single BigNumberish value to string
|
|
7
|
+
* Handles ethers v5 BigNumber, native bigint, hex strings, and numbers
|
|
8
|
+
* @param value BigNumberish value to normalize
|
|
9
|
+
* @returns Normalized string representation
|
|
10
|
+
*/
|
|
11
|
+
export declare function normalizeBigNumberish(value: unknown): string;
|
|
12
|
+
/**
|
|
13
|
+
* Normalize transaction receipt for cross-version compatibility
|
|
14
|
+
* Converts all BigNumber fields to strings
|
|
15
|
+
* @param receipt Transaction receipt to normalize
|
|
16
|
+
* @returns Normalized transaction receipt
|
|
17
|
+
*/
|
|
18
|
+
export declare function normalizeTransactionReceipt(receipt: unknown): Record<string, unknown> | null | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Normalize transaction response for cross-version compatibility
|
|
21
|
+
* Converts all BigNumber fields to strings and preserves methods
|
|
22
|
+
* @param tx Transaction response to normalize
|
|
23
|
+
* @returns Normalized transaction response
|
|
24
|
+
*/
|
|
25
|
+
export declare function normalizeTransactionResponse(tx: unknown): Record<string, unknown> | null | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Normalize contract method result for cross-version compatibility
|
|
28
|
+
* Recursively converts all BigNumber fields to strings
|
|
29
|
+
* @param result Contract method result to normalize
|
|
30
|
+
* @returns Normalized result
|
|
31
|
+
*/
|
|
32
|
+
export declare function normalizeContractResult(result: unknown): unknown;
|
|
33
|
+
/**
|
|
34
|
+
* Normalize event logs for cross-version compatibility
|
|
35
|
+
* @param logs Array of event logs to normalize
|
|
36
|
+
* @returns Normalized logs
|
|
37
|
+
*/
|
|
38
|
+
export declare function normalizeLogs(logs: unknown): unknown[] | unknown;
|
|
39
|
+
/**
|
|
40
|
+
* Normalize loan data for cross-version compatibility
|
|
41
|
+
* Specifically handles loan-related BigNumber fields
|
|
42
|
+
* @param loanData Loan data to normalize
|
|
43
|
+
* @returns Normalized loan data
|
|
44
|
+
*/
|
|
45
|
+
export declare function normalizeLoanData(loanData: unknown): Record<string, unknown> | null | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Normalize position data for cross-version compatibility
|
|
48
|
+
* Specifically handles position-related BigNumber fields
|
|
49
|
+
* @param positionData Position data to normalize
|
|
50
|
+
* @returns Normalized position data
|
|
51
|
+
*/
|
|
52
|
+
export declare function normalizePositionData(positionData: unknown): Record<string, unknown> | null | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Create a comprehensive normalizer for any data structure
|
|
55
|
+
* Automatically detects and normalizes BigNumber fields
|
|
56
|
+
* @param data Data to normalize
|
|
57
|
+
* @returns Normalized data
|
|
58
|
+
*/
|
|
59
|
+
export declare function normalizeForEthersInterop(data: unknown): unknown;
|
|
60
|
+
/**
|
|
61
|
+
* BigInt Utility Functions for Ethers v6 Compatibility
|
|
62
|
+
* Native bigint doesn't have methods like BigNumber did in ethers v5
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* Convert bigint to number (like BigNumber.toNumber())
|
|
66
|
+
* @param value bigint value
|
|
67
|
+
* @returns number representation
|
|
68
|
+
* @throws if value is too large for safe integer
|
|
69
|
+
*/
|
|
70
|
+
export declare function toNumber(value: bigint): number;
|
|
71
|
+
/**
|
|
72
|
+
* Greater than comparison (like BigNumber.gt())
|
|
73
|
+
* @param a First value
|
|
74
|
+
* @param b Second value
|
|
75
|
+
* @returns true if a > b
|
|
76
|
+
*/
|
|
77
|
+
export declare function gt(a: bigint, b: bigint): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Less than comparison (like BigNumber.lt())
|
|
80
|
+
* @param a First value
|
|
81
|
+
* @param b Second value
|
|
82
|
+
* @returns true if a < b
|
|
83
|
+
*/
|
|
84
|
+
export declare function lt(a: bigint, b: bigint): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Addition (like BigNumber.add())
|
|
87
|
+
* @param a First value
|
|
88
|
+
* @param b Second value
|
|
89
|
+
* @returns Sum of a and b
|
|
90
|
+
*/
|
|
91
|
+
export declare function add(a: bigint, b: bigint): bigint;
|
|
92
|
+
/**
|
|
93
|
+
* Subtraction (like BigNumber.sub())
|
|
94
|
+
* @param a First value
|
|
95
|
+
* @param b Second value
|
|
96
|
+
* @returns Difference of a and b
|
|
97
|
+
*/
|
|
98
|
+
export declare function sub(a: bigint, b: bigint): bigint;
|
|
99
|
+
/**
|
|
100
|
+
* Multiplication (like BigNumber.mul())
|
|
101
|
+
* @param a First value
|
|
102
|
+
* @param b Second value
|
|
103
|
+
* @returns Product of a and b
|
|
104
|
+
*/
|
|
105
|
+
export declare function mul(a: bigint, b: bigint): bigint;
|
|
106
|
+
/**
|
|
107
|
+
* Division (like BigNumber.div())
|
|
108
|
+
* @param a First value
|
|
109
|
+
* @param b Second value
|
|
110
|
+
* @returns Quotient of a and b
|
|
111
|
+
*/
|
|
112
|
+
export declare function div(a: bigint, b: bigint): bigint;
|
|
113
|
+
/**
|
|
114
|
+
* Equals comparison (like BigNumber.eq())
|
|
115
|
+
* @param a First value
|
|
116
|
+
* @param b Second value
|
|
117
|
+
* @returns true if a equals b
|
|
118
|
+
*/
|
|
119
|
+
export declare function eq(a: bigint, b: bigint): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Safe wait for transaction confirmation with ethers v5/v6 compatibility
|
|
122
|
+
*
|
|
123
|
+
* The issue: ethers v5 uses receipt.confirmations() as a function
|
|
124
|
+
* while ethers v6 uses receipt.confirmations as a property (number).
|
|
125
|
+
* When v5 and v6 are mixed in the dependency tree, the internal
|
|
126
|
+
* polling mechanism can fail with "receipt.confirmations is not a function".
|
|
127
|
+
*
|
|
128
|
+
* This wrapper provides a safe way to wait for transactions that handles
|
|
129
|
+
* the version incompatibility gracefully.
|
|
130
|
+
*
|
|
131
|
+
* @param tx Transaction response with wait() method
|
|
132
|
+
* @param confirmations Number of confirmations to wait for (default: 1)
|
|
133
|
+
* @param timeout Timeout in milliseconds (default: 60000)
|
|
134
|
+
* @returns Normalized transaction receipt
|
|
135
|
+
*/
|
|
136
|
+
export declare function safeWaitForTransaction(tx: {
|
|
137
|
+
wait?: (confirmations?: number) => Promise<unknown>;
|
|
138
|
+
hash?: string;
|
|
139
|
+
provider?: unknown;
|
|
140
|
+
}, confirmations?: number, timeout?: number): Promise<Record<string, unknown>>;
|
|
141
|
+
/**
|
|
142
|
+
* Check if an error is related to ethers v5/v6 compatibility issues
|
|
143
|
+
* @param error Error to check
|
|
144
|
+
* @returns true if this is an ethers compatibility error
|
|
145
|
+
*/
|
|
146
|
+
export declare function isEthersCompatibilityError(error: unknown): boolean;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extend Position Authorization Utilities
|
|
3
|
+
*
|
|
4
|
+
* Generates authorization signatures for extend position requests
|
|
5
|
+
* that can be verified by the extend-position-validator LIT Action.
|
|
6
|
+
*/
|
|
7
|
+
import { ethers as ethers5 } from "ethers";
|
|
8
|
+
/**
|
|
9
|
+
* Extend Owner Authorization Interface (matches lit-actions)
|
|
10
|
+
*/
|
|
11
|
+
export interface ExtendOwnerAuthorization {
|
|
12
|
+
positionId: string;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
chainId: number;
|
|
15
|
+
newTerm: number;
|
|
16
|
+
action: string;
|
|
17
|
+
signature: string;
|
|
18
|
+
callerAddress: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build the extend authorization message hash without signing.
|
|
22
|
+
*
|
|
23
|
+
* Use this when signing with a smart contract wallet (e.g. Safe) that
|
|
24
|
+
* needs to wrap the hash in its own domain before signing.
|
|
25
|
+
*
|
|
26
|
+
* @param positionId - Position identifier
|
|
27
|
+
* @param newTerm - Extension term in months (number)
|
|
28
|
+
* @param chainId - Chain ID for cross-chain replay protection
|
|
29
|
+
* @returns { hash, timestamp } — pass these to Safe for signing
|
|
30
|
+
*/
|
|
31
|
+
export declare function buildExtendAuthorizationHash(positionId: string, newTerm: number, chainId: number): {
|
|
32
|
+
hash: string;
|
|
33
|
+
timestamp: number;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Generate extend position authorization signature
|
|
37
|
+
*
|
|
38
|
+
* Creates a signature that matches the format expected by
|
|
39
|
+
* AuthorizationModule.verifyExtendAuthorization in lit-actions.
|
|
40
|
+
*
|
|
41
|
+
* Message structure:
|
|
42
|
+
* solidityKeccak256(
|
|
43
|
+
* ["bytes32", "uint256", "uint256", "uint256", "bytes32"],
|
|
44
|
+
* [positionId, timestamp, chainId, newTerm, actionHash]
|
|
45
|
+
* )
|
|
46
|
+
*
|
|
47
|
+
* Where:
|
|
48
|
+
* - actionHash = keccak256("extend-position")
|
|
49
|
+
* - Signer address is recovered from signature by LIT Action
|
|
50
|
+
* - LIT Action validates recovered address === position owner
|
|
51
|
+
*
|
|
52
|
+
* @param positionId - Position identifier
|
|
53
|
+
* @param newTerm - Extension term in months (number)
|
|
54
|
+
* @param chainId - Chain ID for cross-chain replay protection
|
|
55
|
+
* @param signerOrPrecomputed - Either an ethers Wallet (EOA) or { timestamp, signature } for smart contract wallets
|
|
56
|
+
* @returns Authorization object with signature
|
|
57
|
+
*/
|
|
58
|
+
export declare function generateExtendAuthorization(positionId: string, newTerm: number, chainId: number, signerOrPrecomputed: ethers5.Wallet | {
|
|
59
|
+
timestamp: number;
|
|
60
|
+
signature: string;
|
|
61
|
+
}): Promise<ExtendOwnerAuthorization>;
|