@gvnrdao/dh-sdk 0.0.337 → 0.0.339
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/deployments.js +8 -8
- package/dist/deployments.mjs +8 -8
- package/dist/graphs/diamond-hands.d.ts +14 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +259 -44
- package/dist/index.mjs +260 -45
- package/dist/interfaces/chunks/config.i.d.ts +19 -0
- package/dist/interfaces/chunks/loan-operations.i.d.ts +34 -0
- package/dist/modules/diamond-hands-sdk.d.ts +10 -0
- package/dist/modules/loan/loan-query.module.d.ts +12 -1
- package/dist/safe-delegation.js +8 -8
- package/dist/safe-delegation.mjs +8 -8
- package/dist/sign-guard.d.ts +26 -0
- package/dist/sign-guard.js +1008 -0
- package/dist/sign-guard.mjs +941 -0
- package/dist/utils/borrower-authorization-712.d.ts +1 -1
- package/dist/utils/borrower-ucd-debt-summary.d.ts +44 -0
- package/dist/utils/eip712-login.d.ts +34 -1
- package/dist/utils/server-session-store.d.ts +15 -0
- package/dist/utils/server-session.d.ts +13 -0
- package/dist/utils/sign-guard/errors.d.ts +9 -0
- package/dist/utils/sign-guard/extend-fee-bound.d.ts +15 -0
- package/dist/utils/sign-guard/fee-ceiling.d.ts +40 -0
- package/dist/utils/sign-guard/index.d.ts +9 -0
- package/dist/utils/sign-guard/lit-ops-client.d.ts +107 -0
- package/dist/utils/sign-guard/op-envelope.d.ts +88 -0
- package/dist/utils/sign-guard/op-specs.d.ts +51 -0
- package/dist/utils/sign-guard/sign-and-broadcast.d.ts +56 -0
- package/dist/utils/sign-guard/signable-functions.d.ts +41 -0
- package/dist/utils/sign-guard/tx-validator.d.ts +148 -0
- package/package.json +26 -4
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { type FeeCeiling } from "./fee-ceiling";
|
|
2
|
+
/**
|
|
3
|
+
* Structural contract registry. `DeploymentContracts` from the SDK's deployment
|
|
4
|
+
* table satisfies it; test doubles and mock upstreams can fill it from their
|
|
5
|
+
* own sink constants without touching the registry.
|
|
6
|
+
*/
|
|
7
|
+
export interface ContractRegistry {
|
|
8
|
+
PositionManager?: string;
|
|
9
|
+
UCDToken?: string;
|
|
10
|
+
[name: string]: string | undefined;
|
|
11
|
+
}
|
|
12
|
+
export type ExpectedAction = {
|
|
13
|
+
kind: "mint";
|
|
14
|
+
positionId: string;
|
|
15
|
+
amountWei: string;
|
|
16
|
+
/**
|
|
17
|
+
* Audit H-2: required. An earlier shape made this optional, so a
|
|
18
|
+
* malicious or buggy server that omitted `mintFee` from its response
|
|
19
|
+
* silently bypassed the client pin and let the on-chain validator
|
|
20
|
+
* signature be the sole defense. Callers refuse to validate if the
|
|
21
|
+
* server did not echo the fee.
|
|
22
|
+
*/
|
|
23
|
+
mintFeeWei: string;
|
|
24
|
+
} | {
|
|
25
|
+
kind: "repay";
|
|
26
|
+
positionId: string;
|
|
27
|
+
amountWei: string;
|
|
28
|
+
} | {
|
|
29
|
+
kind: "extend";
|
|
30
|
+
positionId: string;
|
|
31
|
+
selectedTerm: number;
|
|
32
|
+
/**
|
|
33
|
+
* Audit H-3: optional upper bound on the server-supplied
|
|
34
|
+
* `proRataRenewalFee` (args[5] of `extendPosition`). The validator
|
|
35
|
+
* decodes the value from the tx and refuses to sign if it exceeds this
|
|
36
|
+
* bound. Computed off-chain as `ucdDebt × extensionFeeRateBps / 10000`
|
|
37
|
+
* — the baseline-without-credit fee, which a compromised validator key
|
|
38
|
+
* could otherwise inflate to drain UCD. See `computeExtendFeeUpperBound`.
|
|
39
|
+
*/
|
|
40
|
+
upperBoundProRataFeeWei?: string;
|
|
41
|
+
} | {
|
|
42
|
+
kind: "withdraw-btc";
|
|
43
|
+
positionId: string;
|
|
44
|
+
btcAddress: string;
|
|
45
|
+
/**
|
|
46
|
+
* Audit M-9: upper bound on the on-chain `totalDeduction` (withdrawBTC
|
|
47
|
+
* params index 6 — the collateral debited from the vault). The validator
|
|
48
|
+
* refuses to sign if the value exceeds it, so a compromised
|
|
49
|
+
* server/validator cannot inflate the deduction beyond what the user
|
|
50
|
+
* approved. The CLI pins it to the requested `amountSats`, which is an
|
|
51
|
+
* exact bound: the LIT action defines `totalDeduction =
|
|
52
|
+
* withdrawalAmountInSats` and takes the network fee *out of* that total.
|
|
53
|
+
*/
|
|
54
|
+
upperBoundTotalDeduction?: string;
|
|
55
|
+
} | {
|
|
56
|
+
/**
|
|
57
|
+
* On-chain position creation (`PositionManager.createPosition`), reached
|
|
58
|
+
* via `sdk.createLoan`. Pins the target and the USER-INTENDED term;
|
|
59
|
+
* pkpId / vaults / validator payloads are server-derived and are
|
|
60
|
+
* displayed, never pinned.
|
|
61
|
+
*/
|
|
62
|
+
kind: "create-position";
|
|
63
|
+
selectedTerm: number;
|
|
64
|
+
}
|
|
65
|
+
/** Server-built UCD allowance ahead of `makePayment`: min/cap band, spender SET. */
|
|
66
|
+
| {
|
|
67
|
+
kind: "ucd-approve";
|
|
68
|
+
spenderCandidates: string[];
|
|
69
|
+
minAmountWei: string;
|
|
70
|
+
} | {
|
|
71
|
+
kind: "set-position-delegate";
|
|
72
|
+
positionId: string;
|
|
73
|
+
delegate: string;
|
|
74
|
+
registryAddress: string;
|
|
75
|
+
}
|
|
76
|
+
/** BitcoinWithdrawalAddressRegistry.addAddress — pins the registry target and the EXACT destination string. */
|
|
77
|
+
| {
|
|
78
|
+
kind: "bwar-add-address";
|
|
79
|
+
btcAddress: string;
|
|
80
|
+
registryAddress: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* PSM pair. `ucd-approve` pins target=UCDToken with a min/cap band and a
|
|
84
|
+
* spender SET — it cannot express the PSM's asymmetric, EXACT-amount
|
|
85
|
+
* approvals, and is deliberately NOT widened. Each PSM expectation pins BOTH
|
|
86
|
+
* the token contract (tx target) and the ONE exact spender, and the amount
|
|
87
|
+
* EXACTLY (never a band — exact-amount approvals are the standing rule;
|
|
88
|
+
* the SDK's MaxUint256 helpers are banned on these paths). Addresses come
|
|
89
|
+
* from the caller's own registry so decode-equivalence stays registry-neutral.
|
|
90
|
+
*/
|
|
91
|
+
| {
|
|
92
|
+
kind: "stablecoin-approve";
|
|
93
|
+
tokenAddress: string;
|
|
94
|
+
spender: string;
|
|
95
|
+
amountUnits: string;
|
|
96
|
+
} | {
|
|
97
|
+
kind: "ucd-approve-controller";
|
|
98
|
+
ucdTokenAddress: string;
|
|
99
|
+
spender: string;
|
|
100
|
+
amountWei: string;
|
|
101
|
+
} | {
|
|
102
|
+
kind: "psm-swap";
|
|
103
|
+
psmAddress: string;
|
|
104
|
+
stablecoin: string;
|
|
105
|
+
amountIn: string;
|
|
106
|
+
minOut: string;
|
|
107
|
+
} | {
|
|
108
|
+
kind: "psm-redeem";
|
|
109
|
+
psmAddress: string;
|
|
110
|
+
stablecoin: string;
|
|
111
|
+
amountUcdWei: string;
|
|
112
|
+
minOut: string;
|
|
113
|
+
};
|
|
114
|
+
export interface ValidationContext {
|
|
115
|
+
chainId: number;
|
|
116
|
+
network: string;
|
|
117
|
+
contracts: ContractRegistry;
|
|
118
|
+
/** Omit for the SDK defaults; consumers with a user-raisable cap pass their own. */
|
|
119
|
+
feeCeiling?: FeeCeiling;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* SDK-registry-backed validation context. Keys: `sepolia` | `localhost` |
|
|
123
|
+
* `mainnet`; `hardhat` / `local` are accepted as aliases for chainId 31337.
|
|
124
|
+
*/
|
|
125
|
+
export declare function buildValidationContext(network: string, chainId: number, feeCeiling?: FeeCeiling): ValidationContext;
|
|
126
|
+
/**
|
|
127
|
+
* Validates a server-returned unsigned transaction against the action the user
|
|
128
|
+
* authorized. Throws `TxValidationError` on any mismatch.
|
|
129
|
+
*
|
|
130
|
+
* Defense in depth — the signed authMessage already binds chainId + positionId
|
|
131
|
+
* + amount, but only the server interprets that. This is the last line where
|
|
132
|
+
* the client can refuse to sign something the user did not approve.
|
|
133
|
+
*/
|
|
134
|
+
export declare function validateUnsignedTx(unsignedTx: Record<string, unknown>, expected: ExpectedAction, vctx: ValidationContext): void;
|
|
135
|
+
/**
|
|
136
|
+
* Read the fee fields relevant to cost, for display. Never throws — a banner
|
|
137
|
+
* must not be the thing that fails a sign; `validateUnsignedTx` owns rejection.
|
|
138
|
+
*/
|
|
139
|
+
export declare function readTxFeeFields(unsignedTx: Record<string, unknown>): {
|
|
140
|
+
gasLimit: bigint | null;
|
|
141
|
+
maxFeePerGas: bigint | null;
|
|
142
|
+
};
|
|
143
|
+
/** Target, decoded function name (or `"<unparseable>"`) and chainId, for banners. */
|
|
144
|
+
export declare function describeUnsignedTx(unsignedTx: Record<string, unknown>): {
|
|
145
|
+
to: string;
|
|
146
|
+
fn: string;
|
|
147
|
+
chainId: number | null;
|
|
148
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gvnrdao/dh-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.339",
|
|
4
4
|
"description": "TypeScript SDK for Diamond Hands Protocol",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -34,6 +34,11 @@
|
|
|
34
34
|
"types": "./dist/safe-delegation.d.ts",
|
|
35
35
|
"import": "./dist/safe-delegation.mjs",
|
|
36
36
|
"require": "./dist/safe-delegation.js"
|
|
37
|
+
},
|
|
38
|
+
"./sign-guard": {
|
|
39
|
+
"types": "./dist/sign-guard.d.ts",
|
|
40
|
+
"import": "./dist/sign-guard.mjs",
|
|
41
|
+
"require": "./dist/sign-guard.js"
|
|
37
42
|
}
|
|
38
43
|
},
|
|
39
44
|
"files": [
|
|
@@ -66,8 +71,9 @@
|
|
|
66
71
|
"test:watch": "jest --watch",
|
|
67
72
|
"test:coverage": "jest --coverage",
|
|
68
73
|
"authorize:pkp": "node scripts/authorize-pkp-actions.js",
|
|
69
|
-
"lint": "eslint src --ext .ts && npm run lint:server-boundary",
|
|
74
|
+
"lint": "eslint src --ext .ts && npm run lint:server-boundary && npm run lint:sign-guard",
|
|
70
75
|
"lint:server-boundary": "node scripts/check-pkp-mint-server-imports.mjs",
|
|
76
|
+
"lint:sign-guard": "node scripts/check-sign-guard-imports.mjs",
|
|
71
77
|
"clean": "rm -rf dist && rm -rf browser/dist"
|
|
72
78
|
},
|
|
73
79
|
"keywords": [
|
|
@@ -88,7 +94,7 @@
|
|
|
88
94
|
"sideEffects": false,
|
|
89
95
|
"dependencies": {
|
|
90
96
|
"@gvnrdao/dh-lit-actions": "^0.0.322",
|
|
91
|
-
"@gvnrdao/dh-lit-ops": "^0.0.
|
|
97
|
+
"@gvnrdao/dh-lit-ops": "^0.0.316",
|
|
92
98
|
"@noble/hashes": "^1.5.0",
|
|
93
99
|
"axios": "^1.17.0",
|
|
94
100
|
"bech32": "^2.0.0",
|
|
@@ -131,5 +137,21 @@
|
|
|
131
137
|
"bugs": {
|
|
132
138
|
"url": "https://github.com/gvnrdao/diamond-hands/issues"
|
|
133
139
|
},
|
|
134
|
-
"homepage": "https://diamond-hands-protocol.com"
|
|
140
|
+
"homepage": "https://diamond-hands-protocol.com",
|
|
141
|
+
"typesVersions": {
|
|
142
|
+
"*": {
|
|
143
|
+
"server": [
|
|
144
|
+
"./dist/server.d.ts"
|
|
145
|
+
],
|
|
146
|
+
"deployments": [
|
|
147
|
+
"./dist/deployments.d.ts"
|
|
148
|
+
],
|
|
149
|
+
"safe-delegation": [
|
|
150
|
+
"./dist/safe-delegation.d.ts"
|
|
151
|
+
],
|
|
152
|
+
"sign-guard": [
|
|
153
|
+
"./dist/sign-guard.d.ts"
|
|
154
|
+
]
|
|
155
|
+
}
|
|
156
|
+
}
|
|
135
157
|
}
|