@gvnrdao/dh-sdk 0.0.311 → 0.0.313
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/browser/dist/browser.js +1 -1
- package/dist/constants/chunks/deployment-addresses.d.ts +4 -0
- package/dist/constants/chunks/network-configs.d.ts +2 -0
- package/dist/contracts/typechain-contracts/factories/src/agent/AgentDelegationRegistry__factory.d.ts +1324 -0
- package/dist/contracts/typechain-contracts/src/agent/AgentDelegationRegistry.d.ts +995 -0
- package/dist/deployments.js +14 -7
- package/dist/deployments.mjs +14 -7
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2412 -337
- package/dist/index.mjs +2381 -306
- package/dist/interfaces/chunks/config.i.d.ts +17 -0
- package/dist/modules/diamond-hands-sdk.d.ts +59 -0
- package/dist/modules/loan/loan-creator.module.d.ts +26 -0
- package/dist/utils/agent-delegation.utils.d.ts +20 -0
- package/dist/utils/server-session.d.ts +30 -0
- package/package.json +3 -3
|
@@ -37,6 +37,10 @@ export interface ContractAddresses {
|
|
|
37
37
|
positionDelegateRegistry?: string;
|
|
38
38
|
/** BitcoinWithdrawalAddressRegistry proxy; per-wallet allowlist that gates borrower-initiated BTC withdrawal destinations (24h time-lock). */
|
|
39
39
|
bitcoinWithdrawalAddressRegistry?: string;
|
|
40
|
+
/** AgentDelegationRegistry proxy; protocol agent-delegation policy layer (MVP: auto-renew). Sepolia only. */
|
|
41
|
+
agentDelegationRegistry?: string;
|
|
42
|
+
/** DHAgentDelegate; EIP-7702 execution adapter (Gate 2) the borrower EOA delegates to. Sepolia only. */
|
|
43
|
+
dhAgentDelegate?: string;
|
|
40
44
|
mockUsdcToken?: string;
|
|
41
45
|
mockUsdcOwner?: string;
|
|
42
46
|
mockUsdtToken?: string;
|
|
@@ -71,6 +75,19 @@ interface BaseSDKConfig {
|
|
|
71
75
|
/** Custom store (e.g. a file-backed store for CLI daemons). */
|
|
72
76
|
store?: ServerSessionStore;
|
|
73
77
|
};
|
|
78
|
+
/**
|
|
79
|
+
* Audit M-8 audience the server-session login binds to. Defaults to
|
|
80
|
+
* `serviceEndpoint`.
|
|
81
|
+
*
|
|
82
|
+
* Set this only when ONE signature must authenticate several services — the
|
|
83
|
+
* browser frontend signs a single envelope and spends it at both
|
|
84
|
+
* lit-ops-server and the api, and a per-endpoint audience cannot name two
|
|
85
|
+
* endpoints. Every server the envelope is presented to must list this value as
|
|
86
|
+
* an accepted audience, so changing it requires a server-side config change
|
|
87
|
+
* FIRST. Node callers (CLI, MCP, cr-monitor) omit it and keep binding to the
|
|
88
|
+
* endpoint they call.
|
|
89
|
+
*/
|
|
90
|
+
loginAudience?: string;
|
|
74
91
|
/**
|
|
75
92
|
* Fires immediately before the server-session login requests a wallet
|
|
76
93
|
* signature — never on the silent re-mint paths. Lets UIs show a
|
|
@@ -18,6 +18,7 @@ import { SDKError } from "../utils/error-handler";
|
|
|
18
18
|
import type { CreateLoanRequest, CreateLoanResult, LoanDataDetail, UCDMintRequest, UCDMintResult, PartialPaymentRequest, PartialPaymentResult, BTCWithdrawalResult, RenewPositionRequest, RenewPositionResult, LiquidationRequest, LiquidationResult, ConfirmBalanceRequest, ConfirmBalanceResult, TermsWithFeesResult } from "../interfaces/chunks/loan-operations.i";
|
|
19
19
|
import type { DiamondHandsSDKConfig } from "../interfaces/chunks/config.i";
|
|
20
20
|
import type { PKPData } from "../interfaces/chunks/pkp-integration.i";
|
|
21
|
+
import type { DhServerLoginPayload } from "../utils/eip712-login";
|
|
21
22
|
import { type ReconciledWithdrawal } from "../utils/withdrawal-reconciliation.utils";
|
|
22
23
|
import { ContractManager } from "./contract/contract-manager.module";
|
|
23
24
|
import { WithdrawalAddressModule } from "./withdrawal-address/withdrawal-address.module";
|
|
@@ -125,6 +126,28 @@ export declare class DiamondHandsSDK {
|
|
|
125
126
|
* and never prompts the wallet.
|
|
126
127
|
*/
|
|
127
128
|
clearServerSession(): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Establish the lit-ops-server session from a login envelope the CALLER already
|
|
131
|
+
* had signed, instead of prompting the wallet for one.
|
|
132
|
+
*
|
|
133
|
+
* For a host that authenticates several services from one wallet signature (the
|
|
134
|
+
* browser frontend signs once and spends the same envelope at the api and here),
|
|
135
|
+
* this is what turns two wallet prompts into one — and for a multi-sig Safe each
|
|
136
|
+
* prompt saved is a whole propose-and-confirm ceremony across owners.
|
|
137
|
+
*
|
|
138
|
+
* Call it PROMPTLY after signing: each server pins the nonce on first use and
|
|
139
|
+
* requires that first use to be fresh (±120s EOA, ±600s contract wallet), and
|
|
140
|
+
* the two servers' replay stores are independent, so a late hand-off is rejected
|
|
141
|
+
* as stale even though the other service already accepted the same envelope.
|
|
142
|
+
* Once accepted, silent re-mint covers the next 24h with no further prompts.
|
|
143
|
+
*
|
|
144
|
+
* Requires `loginAudience` to be configured to a value BOTH servers accept —
|
|
145
|
+
* otherwise this service rejects the envelope as `audience_mismatch`.
|
|
146
|
+
*
|
|
147
|
+
* Throws if the exchange fails, so a caller can fall back to the prompt path.
|
|
148
|
+
* No-op in standalone mode (no server session to prime).
|
|
149
|
+
*/
|
|
150
|
+
primeServerSession(payload: DhServerLoginPayload): Promise<void>;
|
|
128
151
|
/**
|
|
129
152
|
* Audit H-9: invalidate the LoanQuery cache so subsequent reads return
|
|
130
153
|
* the post-write state. We clear the entire loan-query cache (not just
|
|
@@ -864,6 +887,42 @@ export declare class DiamondHandsSDK {
|
|
|
864
887
|
* @param options - Override timeout/interval for this call
|
|
865
888
|
* @throws if timeout is reached before subgraph catches up
|
|
866
889
|
*/
|
|
890
|
+
/** Guard: the AgentDelegationRegistry MVP is deployed on Sepolia only. */
|
|
891
|
+
private assertAgentDelegationSepolia;
|
|
892
|
+
/**
|
|
893
|
+
* Read a position's auto-renew delegation state (used to drive the Enable/Disable toggle).
|
|
894
|
+
* Pure view — no signer required.
|
|
895
|
+
*/
|
|
896
|
+
getAutoRenewStatus(positionId: string, user?: string): Promise<{
|
|
897
|
+
enabled: boolean;
|
|
898
|
+
borrower: string;
|
|
899
|
+
maxRenewals: number;
|
|
900
|
+
renewalsUsed: number;
|
|
901
|
+
agentActive: boolean | null;
|
|
902
|
+
canRenew: {
|
|
903
|
+
ok: boolean;
|
|
904
|
+
reason: number;
|
|
905
|
+
} | null;
|
|
906
|
+
}>;
|
|
907
|
+
/**
|
|
908
|
+
* Enable auto-renew delegation for a position. Orchestrates the first-time setup: if the
|
|
909
|
+
* borrower has no active agent, mints a fresh per-user agent PKP (via lit-ops-server) and
|
|
910
|
+
* registers it, then records the position's renew grant. Borrower-signed.
|
|
911
|
+
*/
|
|
912
|
+
enableAutoRenew(positionId: string, options?: {
|
|
913
|
+
maxRenewals?: number;
|
|
914
|
+
maxEndTimestamp?: number;
|
|
915
|
+
agentValiditySeconds?: number;
|
|
916
|
+
}): Promise<{
|
|
917
|
+
hash: string;
|
|
918
|
+
blockNumber: number;
|
|
919
|
+
agentAddress?: string;
|
|
920
|
+
}>;
|
|
921
|
+
/** Disable auto-renew delegation for a position (clears the grant). Borrower-signed. */
|
|
922
|
+
disableAutoRenew(positionId: string): Promise<{
|
|
923
|
+
hash: string;
|
|
924
|
+
blockNumber: number;
|
|
925
|
+
}>;
|
|
867
926
|
/**
|
|
868
927
|
* Get Bitcoin balance for an address
|
|
869
928
|
*
|
|
@@ -46,6 +46,15 @@ export interface LoanCreatorConfig {
|
|
|
46
46
|
debug?: boolean;
|
|
47
47
|
/** Transaction timeout (ms) */
|
|
48
48
|
transactionTimeoutMs?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Confirmations to wait for before trusting the `positionId` read from a
|
|
51
|
+
* createPosition receipt. Defaults to 1 on local chains and 3 elsewhere.
|
|
52
|
+
*
|
|
53
|
+
* `positionId` is derived on-chain from `block.timestamp` and a global counter, so a
|
|
54
|
+
* reorg re-executes the same transaction into a different id. Raise this on chains
|
|
55
|
+
* with deep reorgs; it trades loan-creation latency for id stability.
|
|
56
|
+
*/
|
|
57
|
+
createPositionConfirmations?: number;
|
|
49
58
|
/** Validator version for loan creation (createPosition) - REQUIRED */
|
|
50
59
|
loanCreationValidatorVersion: number;
|
|
51
60
|
/** EVM JSON-RPC URL for service-mode PKP flow (forwards to lit-ops-server) */
|
|
@@ -117,6 +126,23 @@ export declare class LoanCreator {
|
|
|
117
126
|
* Step 3: Submit loan creation transaction
|
|
118
127
|
*/
|
|
119
128
|
private submitLoanCreation;
|
|
129
|
+
/**
|
|
130
|
+
* Confirmation depth to wait for before trusting `positionId` from a receipt.
|
|
131
|
+
*
|
|
132
|
+
* Deeper is safer but slower, so local chains (instant mining, no reorgs) stay at 1.
|
|
133
|
+
* Override with `createPositionConfirmations` when a chain needs more.
|
|
134
|
+
*/
|
|
135
|
+
private createPositionConfirmations;
|
|
136
|
+
/**
|
|
137
|
+
* Re-read the receipt after confirmations and re-derive `positionId`, so a reorg
|
|
138
|
+
* cannot leave the caller holding an id that never survived to the canonical chain.
|
|
139
|
+
*
|
|
140
|
+
* Returns the authoritative id. If the re-read disagrees with what was first
|
|
141
|
+
* extracted, the fresh value wins and the divergence is logged loudly — silently
|
|
142
|
+
* returning a phantom id is how this surfaced as a `PositionNotFound()` hundreds of
|
|
143
|
+
* lines downstream, long after the real cause.
|
|
144
|
+
*/
|
|
145
|
+
private confirmPositionId;
|
|
120
146
|
/**
|
|
121
147
|
* Extract position ID from transaction receipt
|
|
122
148
|
*/
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent-delegation service helpers (auto-renew MVP).
|
|
3
|
+
*
|
|
4
|
+
* Kept separate from the generic `PKPManager` so that module stays focused on PKP lifecycle —
|
|
5
|
+
* this file owns the feature-specific orchestration (the lit-ops-server mint-agent endpoint).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Mint a fresh per-user AGENT PKP via lit-ops-server and return its Ethereum address, to be
|
|
9
|
+
* registered as the renewal agent in `AgentDelegationRegistry`. Each call yields a unique
|
|
10
|
+
* address (satisfies the registry's AR-1 non-reuse). Throws on failure.
|
|
11
|
+
*
|
|
12
|
+
* @param serviceEndpoint lit-ops-server base URL (the SDK's `serviceEndpoint`).
|
|
13
|
+
* @param authHeader Optional async/sync provider of auth headers (the SDK's session token).
|
|
14
|
+
* @param timeoutMs Request timeout (default 30s).
|
|
15
|
+
*/
|
|
16
|
+
export declare function mintAgentPkp(params: {
|
|
17
|
+
serviceEndpoint: string;
|
|
18
|
+
authHeader?: () => Promise<Record<string, string>> | Record<string, string>;
|
|
19
|
+
timeoutMs?: number;
|
|
20
|
+
}): Promise<string>;
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
* `~/.diamond-hands/session.json` for cross-invocation reuse.
|
|
23
23
|
*/
|
|
24
24
|
import type { Signer } from "ethers";
|
|
25
|
+
import { type DhServerLoginPayload } from "./eip712-login";
|
|
25
26
|
import { type ServerSessionStore } from "./server-session-store";
|
|
26
27
|
export interface ServerSessionOptions {
|
|
27
28
|
signer: Signer;
|
|
@@ -34,6 +35,16 @@ export interface ServerSessionOptions {
|
|
|
34
35
|
sessionStore?: ServerSessionStore;
|
|
35
36
|
/** Set false to disable persistence entirely (fresh signature per instance + expiry). */
|
|
36
37
|
persistSession?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Audit M-8 audience to bind the login to. Defaults to `serviceEndpoint`.
|
|
40
|
+
*
|
|
41
|
+
* A caller that shares ONE signature across several services (the browser
|
|
42
|
+
* frontend, which authenticates both lit-ops-server and the api from a single
|
|
43
|
+
* wallet prompt) cannot bind to a single endpoint, so it passes the app audience
|
|
44
|
+
* instead — and every server it talks to must accept that value. Node callers
|
|
45
|
+
* (CLI, MCP, cr-monitor) omit it and keep the endpoint binding unchanged.
|
|
46
|
+
*/
|
|
47
|
+
loginAudience?: string;
|
|
37
48
|
/**
|
|
38
49
|
* Fires immediately before a wallet signature is requested — i.e. only when
|
|
39
50
|
* neither the cached JWT nor the persisted envelope could renew the session,
|
|
@@ -59,6 +70,7 @@ export declare class ServerLoginError extends Error {
|
|
|
59
70
|
export declare class ServerSession {
|
|
60
71
|
private readonly signer;
|
|
61
72
|
private readonly serviceEndpoint;
|
|
73
|
+
private readonly loginAudience;
|
|
62
74
|
private readonly chainId;
|
|
63
75
|
private readonly store;
|
|
64
76
|
private readonly onSignaturePrompt?;
|
|
@@ -118,6 +130,24 @@ export declare class ServerSession {
|
|
|
118
130
|
* of server response so the client stops presenting the token.
|
|
119
131
|
*/
|
|
120
132
|
logout(): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Adopt a login envelope signed ELSEWHERE and exchange it for a session now.
|
|
135
|
+
*
|
|
136
|
+
* The browser frontend collects one wallet signature and spends it at both the
|
|
137
|
+
* api and this service, so the envelope is minted outside the SDK. Without this
|
|
138
|
+
* seam the SDK would mint its own — a second wallet prompt, which for a
|
|
139
|
+
* multi-sig Safe is another full propose-and-confirm ceremony across owners.
|
|
140
|
+
*
|
|
141
|
+
* Must be called PROMPTLY after signing. Each server pins the nonce on FIRST
|
|
142
|
+
* use and requires that first use to be fresh (±120s EOA, ±600s contract
|
|
143
|
+
* wallet); the stores are independent, so a late hand-off is rejected as
|
|
144
|
+
* `stale_first_use` even though the other service already accepted it. After a
|
|
145
|
+
* successful first use, silent re-mint covers the next 24h.
|
|
146
|
+
*
|
|
147
|
+
* No-ops the prompt path entirely: on success the session is cached and
|
|
148
|
+
* persisted exactly as a self-minted login would be.
|
|
149
|
+
*/
|
|
150
|
+
adoptLoginPayload(payload: DhServerLoginPayload): Promise<void>;
|
|
121
151
|
/**
|
|
122
152
|
* Resolve a session WITHOUT ever prompting for a wallet signature: a live
|
|
123
153
|
* cached token, else the persisted JWT (adopted if still fresh, otherwise
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gvnrdao/dh-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.313",
|
|
4
4
|
"description": "TypeScript SDK for Diamond Hands Protocol - Bitcoin-backed lending with LIT Protocol PKPs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -82,8 +82,8 @@
|
|
|
82
82
|
},
|
|
83
83
|
"sideEffects": false,
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@gvnrdao/dh-lit-actions": "^0.0.
|
|
86
|
-
"@gvnrdao/dh-lit-ops": "^0.0.
|
|
85
|
+
"@gvnrdao/dh-lit-actions": "^0.0.317",
|
|
86
|
+
"@gvnrdao/dh-lit-ops": "^0.0.308",
|
|
87
87
|
"@noble/hashes": "^1.5.0",
|
|
88
88
|
"axios": "^1.17.0",
|
|
89
89
|
"bech32": "^2.0.0",
|