@opendatalabs/vana-sdk 3.19.1 → 3.20.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/README.md +49 -0
- package/dist/config/contracts.config.cjs +8 -3
- package/dist/config/contracts.config.cjs.map +1 -1
- package/dist/config/contracts.config.js +8 -3
- package/dist/config/contracts.config.js.map +1 -1
- package/dist/direct/controller.cjs +3 -2
- package/dist/direct/controller.cjs.map +1 -1
- package/dist/direct/controller.d.ts +19 -2
- package/dist/direct/controller.js +3 -2
- package/dist/direct/controller.js.map +1 -1
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs +146 -512
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.ts +136 -412
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.js +146 -512
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.js.map +1 -1
- package/dist/generated/abi/DataPortabilityServersImplementation.cjs +391 -654
- package/dist/generated/abi/DataPortabilityServersImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityServersImplementation.d.ts +302 -505
- package/dist/generated/abi/DataPortabilityServersImplementation.js +391 -654
- package/dist/generated/abi/DataPortabilityServersImplementation.js.map +1 -1
- package/dist/generated/abi/index.d.ts +433 -912
- package/dist/generated/addresses.cjs +8 -8
- package/dist/generated/addresses.cjs.map +1 -1
- package/dist/generated/addresses.d.ts +8 -8
- package/dist/generated/addresses.js +8 -8
- package/dist/generated/addresses.js.map +1 -1
- package/dist/index.browser.js +556 -1185
- package/dist/index.browser.js.map +2 -2
- package/dist/index.node.cjs +556 -1185
- package/dist/index.node.cjs.map +2 -2
- package/dist/index.node.js +556 -1185
- package/dist/index.node.js.map +2 -2
- package/dist/server.cjs +28 -2
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +2 -0
- package/dist/server.js +29 -1
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -155,6 +155,55 @@ Use `network: "moksha"` to keep production app/API URLs while running escrow and
|
|
|
155
155
|
chain-aware defaults against Moksha. `env: "dev"` remains for Vana's internal dev
|
|
156
156
|
deployment and switches deployment URLs.
|
|
157
157
|
|
|
158
|
+
### Scope entries
|
|
159
|
+
|
|
160
|
+
A grant carries a list of **scope entries**, and each one is
|
|
161
|
+
`[operation:]scope`:
|
|
162
|
+
|
|
163
|
+
- no prefix means **read** — `spotify.savedTracks`, `chatgpt.*`, `*`;
|
|
164
|
+
- `write:` means **write** — `write:coach.weekly`, `write:chatgpt.*`;
|
|
165
|
+
- the operation is lowercase ASCII and matched exactly. `read:` is not an
|
|
166
|
+
alias for a bare entry, `delete:` is reserved but not implemented, and there
|
|
167
|
+
is no wildcard over operations: wildcards apply to the scope part only.
|
|
168
|
+
|
|
169
|
+
Read and write never cross. `write:coach.weekly` authorizes writing
|
|
170
|
+
`coach.weekly` and nothing else; reading it needs its own bare entry. A grant
|
|
171
|
+
that wants both carries both.
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import {
|
|
175
|
+
parseScopeEntry, // "write:coach.weekly" -> { scope: "coach.weekly", action: "write" }
|
|
176
|
+
formatScopeEntry, // { scope, action } -> the wire entry
|
|
177
|
+
grantPermissions, // a grant's scopes -> [{ scope, actions: ["read", "write"] }]
|
|
178
|
+
hasAction, // does this grant authorize `action` over `scope`?
|
|
179
|
+
} from "@opendatalabs/vana-sdk/server";
|
|
180
|
+
|
|
181
|
+
// Request read + write on a derived scope, computed from two sources.
|
|
182
|
+
export const vana = createDirectDataController({
|
|
183
|
+
// ...
|
|
184
|
+
source: "oura",
|
|
185
|
+
scopes: [
|
|
186
|
+
"oura.sleep",
|
|
187
|
+
"chatgpt.conversations",
|
|
188
|
+
"coach.weekly",
|
|
189
|
+
"write:coach.weekly",
|
|
190
|
+
],
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
hasAction(grant.scopes, "coach.weekly", "write"); // true
|
|
194
|
+
hasAction(grant.scopes, "oura.sleep", "write"); // false — read entry only
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Entries are passed through and signed verbatim, so build and read them with
|
|
198
|
+
these helpers rather than slicing the strings by hand. An entry whose
|
|
199
|
+
operation the SDK does not recognise never parses as read: `parseScopeEntry`
|
|
200
|
+
throws `InvalidScopeEntryError`, `hasAction` skips it, and `grantPermissions`
|
|
201
|
+
refuses the whole list (use `tryGrantPermissions` to get `undefined` instead
|
|
202
|
+
when rendering a grant a newer release may have written). The controller
|
|
203
|
+
accepts write entries in `scopes`, but its scope part must be a concrete
|
|
204
|
+
scope: this flow reads approved scopes back one at a time, so wildcards are
|
|
205
|
+
rejected there for read and write alike.
|
|
206
|
+
|
|
158
207
|
### Backend controller
|
|
159
208
|
|
|
160
209
|
```typescript
|
|
@@ -37,16 +37,21 @@ const CONTRACTS = {
|
|
|
37
37
|
1480: "0xb4FA18443E0FA6cdC0280D20b8cCDB2377D13Bf2"
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
|
+
// V2 deployment (DataPortabilityPermissionsV2Proxy). The gateway is the source
|
|
41
|
+
// of truth for which deployment is live; verify with
|
|
42
|
+
// `cast call <address> "eip712Domain()(bytes1,string,string,uint256,address,bytes32,uint256[])"`
|
|
43
|
+
// which must return the domain name "Vana Data Portability".
|
|
40
44
|
DataPortabilityPermissions: {
|
|
41
45
|
addresses: {
|
|
42
|
-
14800: "
|
|
43
|
-
1480: "
|
|
46
|
+
14800: "0x4d3FA76064D88e0454cFc4CaD7e5FeC3e3124011",
|
|
47
|
+
1480: "0x4d3FA76064D88e0454cFc4CaD7e5FeC3e3124011"
|
|
44
48
|
}
|
|
45
49
|
},
|
|
50
|
+
// V2 deployment (DataPortabilityServersV2Proxy) on both chains.
|
|
46
51
|
DataPortabilityServers: {
|
|
47
52
|
addresses: {
|
|
48
53
|
14800: "0xCae2CE0e9caa6643ed28186cF57bd40Bd9E17Eab",
|
|
49
|
-
1480: "
|
|
54
|
+
1480: "0xCae2CE0e9caa6643ed28186cF57bd40Bd9E17Eab"
|
|
50
55
|
}
|
|
51
56
|
},
|
|
52
57
|
DataPortabilityGrantees: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/config/contracts.config.ts"],"sourcesContent":["// SOURCE CONFIGURATION - Complete contract registry\n// Generated output: src/generated/addresses.ts\n\n/**\n * Complete contract configuration for the Vana protocol.\n *\n * ⚠️ THIS IS A SOURCE FILE - EDIT THIS TO ADD/UPDATE CONTRACTS\n *\n * @remarks\n * This file contains all contract addresses and discovery metadata in one place.\n *\n * **Contract Types:**\n * - Entry Points: Contracts without `discovery` field (must be known externally)\n * - Discoverable: Contracts with `discovery` field (auto-discovered from parent)\n *\n * **Build Process:**\n * 1. Edit this file to add/update contracts\n * 2. Run `npm run discover-addresses` to validate and generate complete registry\n * 3. Run `npm run fetch-abis` to fetch ABIs for all contracts\n *\n * @category Configuration\n * @internal This is a source file - apps should import from src/generated/addresses.ts\n */\n\ninterface DiscoveryMetadata {\n /** Parent contract to discover this from */\n parent: string;\n /** Getter function name on parent contract */\n getter: string;\n}\n\ninterface ContractConfig {\n addresses: {\n 14800: string;\n 1480: string;\n };\n /** If present, this contract can be auto-discovered from parent */\n discovery?: DiscoveryMetadata;\n}\n\nexport const CONTRACTS: Record<string, ContractConfig> = {\n // ========================================\n // DATA PORTABILITY CONTRACTS\n // ========================================\n DataPortabilityEscrow: {\n addresses: {\n 14800: \"0x07d7769081adc3a3DBe91f5E4B98E9A5a6B292e3\",\n 1480: \"0x07d7769081adc3a3DBe91f5E4B98E9A5a6B292e3\",\n },\n },\n FeeRegistry: {\n addresses: {\n 14800: \"0xb4FA18443E0FA6cdC0280D20b8cCDB2377D13Bf2\",\n 1480: \"0xb4FA18443E0FA6cdC0280D20b8cCDB2377D13Bf2\",\n },\n },\n DataPortabilityPermissions: {\n addresses: {\n 14800: \"0xD54523048AdD05b4d734aFaE7C68324Ebb7373eF\",\n 1480: \"0xD54523048AdD05b4d734aFaE7C68324Ebb7373eF\",\n },\n },\n DataPortabilityServers: {\n addresses: {\n 14800: \"0xCae2CE0e9caa6643ed28186cF57bd40Bd9E17Eab\",\n 1480: \"0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c\",\n },\n },\n DataPortabilityGrantees: {\n addresses: {\n 14800: \"0x8325C0A0948483EdA023A1A2Fd895e62C5131234\",\n 1480: \"0x8325C0A0948483EdA023A1A2Fd895e62C5131234\",\n },\n },\n DataRegistry: {\n addresses: {\n 14800: \"0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C\",\n 1480: \"0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C\",\n },\n },\n\n // ========================================\n // COMPUTING INFRASTRUCTURE\n // ========================================\n ComputeEngine: {\n addresses: {\n 14800: \"0xb2BFe33FA420c45F1Cf1287542ad81ae935447bd\",\n 1480: \"0xb2BFe33FA420c45F1Cf1287542ad81ae935447bd\",\n },\n },\n ComputeEngineTreasury: {\n addresses: {\n 14800: \"0xceB33C501B624D984bD1Ed3298f6D1d8F7CE03d1\",\n 1480: \"0xceB33C501B624D984bD1Ed3298f6D1d8F7CE03d1\",\n },\n discovery: {\n parent: \"ComputeEngine\",\n getter: \"computeEngineTreasury\",\n },\n },\n QueryEngine: {\n addresses: {\n 14800: \"0xd25Eb66EA2452cf3238A2eC6C1FD1B7F5B320490\",\n 1480: \"0xd25Eb66EA2452cf3238A2eC6C1FD1B7F5B320490\",\n },\n },\n VanaTreasury: {\n addresses: {\n 14800: \"0x8B32Ef32f22e72cc25D53f6E858f57cAe7E198f9\",\n 1480: \"0x8B32Ef32f22e72cc25D53f6E858f57cAe7E198f9\",\n },\n discovery: {\n parent: \"QueryEngine\",\n getter: \"queryEngineTreasury\",\n },\n },\n DataRefinerRegistry: {\n addresses: {\n 14800: \"0x93c3EF89369fDcf08Be159D9DeF0F18AB6Be008c\",\n 1480: \"0x93c3EF89369fDcf08Be159D9DeF0F18AB6Be008c\",\n },\n },\n ComputeInstructionRegistry: {\n addresses: {\n 14800: \"0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5\",\n 1480: \"0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5\",\n },\n },\n\n // ========================================\n // TEE POOLS (Canonical Deployments)\n // ========================================\n TeePoolPhala: {\n addresses: {\n 14800: \"0xE8EC6BD73b23Ad40E6B9a6f4bD343FAc411bD99A\",\n 1480: \"0xE8EC6BD73b23Ad40E6B9a6f4bD343FAc411bD99A\",\n },\n },\n TeePoolEphemeralStandard: {\n addresses: {\n 14800: \"0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A\",\n 1480: \"0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A\",\n },\n },\n TeePoolPersistentStandard: {\n addresses: {\n 14800: \"0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76\",\n 1480: \"0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76\",\n },\n },\n TeePoolPersistentGpu: {\n addresses: {\n 14800: \"0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9\",\n 1480: \"0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9\",\n },\n },\n TeePoolDedicatedStandard: {\n addresses: {\n 14800: \"0xf024b7ac5E8417416f53B41ecfa58C8e9396687d\",\n 1480: \"0xf024b7ac5E8417416f53B41ecfa58C8e9396687d\",\n },\n },\n TeePoolDedicatedGpu: {\n addresses: {\n 14800: \"0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E\",\n 1480: \"0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E\",\n },\n },\n\n // ========================================\n // VANA EPOCH / DLP REGISTRY\n // ========================================\n // Note: DLP rewards-specific contracts (DLPPerformance, DLPRewardDeployer,\n // DLPRewardDeployerTreasury, DLPRewardSwap, SwapHelper) were removed in the\n // protocol unification cleanup. VanaEpoch, DLPRegistry, and DLPRegistryTreasury\n // are kept because they may be referenced beyond the rewards system.\n VanaEpoch: {\n addresses: {\n 14800: \"0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0\",\n 1480: \"0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0\",\n },\n },\n DLPRegistry: {\n addresses: {\n 14800: \"0x4D59880a924526d1dD33260552Ff4328b1E18a43\",\n 1480: \"0x4D59880a924526d1dD33260552Ff4328b1E18a43\",\n },\n },\n DLPRegistryTreasury: {\n addresses: {\n 14800: \"0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a\",\n 1480: \"0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a\",\n },\n discovery: {\n parent: \"DLPRegistry\",\n getter: \"treasury\",\n },\n },\n\n // ========================================\n // VANA POOL (STAKING)\n // ========================================\n VanaPoolStaking: {\n addresses: {\n 14800: \"0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e\",\n 1480: \"0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e\",\n },\n },\n VanaPoolTreasury: {\n addresses: {\n 14800: \"0x143BE72CF2541604A7691933CAccd6D9cC17c003\",\n 1480: \"0x143BE72CF2541604A7691933CAccd6D9cC17c003\",\n },\n discovery: {\n parent: \"VanaPoolStaking\",\n getter: \"vanaPoolTreasury\",\n },\n },\n VanaPoolEntity: {\n addresses: {\n 14800: \"0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30\",\n 1480: \"0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30\",\n },\n discovery: {\n parent: \"VanaPoolStaking\",\n getter: \"vanaPoolEntity\",\n },\n },\n\n // ========================================\n // DLP DEPLOYMENT & TOKEN SYSTEM\n // ========================================\n DATFactory: {\n addresses: {\n 14800: \"0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644\",\n 1480: \"0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644\",\n },\n },\n DAT: {\n addresses: {\n 14800: \"0xA706b93ccED89f13340673889e29F0a5cd84212d\",\n 1480: \"0xA706b93ccED89f13340673889e29F0a5cd84212d\",\n },\n },\n DATPausable: {\n addresses: {\n 14800: \"0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e\",\n 1480: \"0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e\",\n },\n },\n DATVotes: {\n addresses: {\n 14800: \"0xaE04c8A77E9B27869eb563720524A9aE0baf1831\",\n 1480: \"0xaE04c8A77E9B27869eb563720524A9aE0baf1831\",\n },\n },\n\n // ========================================\n // EXTERNAL DEPENDENCIES (DeFi)\n // ========================================\n WVANA: {\n addresses: {\n 14800: \"0xbccc4b4c6530F82FE309c5E845E50b5E9C89f2AD\",\n 1480: \"0x00EDdD9621Fb08436d0331c149D1690909a5906d\",\n },\n },\n UniswapV3NonfungiblePositionManager: {\n addresses: {\n 14800: \"0x48Bd633f4B9128a38Ebb4a48b6975EB3Eaf1931b\",\n 1480: \"0x45a2992e1bFdCF9b9AcE0a84A238f2E56F481816\",\n },\n },\n UniswapV3QuoterV2: {\n addresses: {\n 14800: \"0x3152246f3CD4dD465292Dd4Ffd792E2Cf602e332\",\n 1480: \"0x1b13728ea3C90863990aC0e05987CfeC1888908c\",\n },\n },\n\n // ========================================\n // UTILITY CONTRACTS\n // ========================================\n Multicall3: {\n addresses: {\n 14800: \"0xD8d2dFca27E8797fd779F8547166A2d3B29d360E\",\n 1480: \"0xD8d2dFca27E8797fd779F8547166A2d3B29d360E\",\n },\n },\n Multisend: {\n addresses: {\n 14800: \"0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d\",\n 1480: \"0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d\",\n },\n },\n} as const;\n\n// Legacy DLPRoot* and deprecated TeePool entries were removed in the protocol\n// unification cleanup. They were part of the old DLP rewards system superseded\n// by other contracts.\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwCO,MAAM,YAA4C;AAAA;AAAA;AAAA;AAAA,EAIvD,uBAAuB;AAAA,IACrB,WAAW;AAAA,MACT,OAA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AAA,MACP,MAAM;AAAA,IACR;AAAA,IACA,WAAW;AAAA,MACT,QAAQ;AAAA,MACR,QAAQ;AAAA,IACV;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY;AAAA,IACV,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,KAAK;AAAA,IACH,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,aAAa;AAAA,IACX,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,UAAU;AAAA,IACR,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO;AAAA,IACL,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,qCAAqC;AAAA,IACnC,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,mBAAmB;AAAA,IACjB,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY;AAAA,IACV,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,WAAW;AAAA,IACT,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/config/contracts.config.ts"],"sourcesContent":["// SOURCE CONFIGURATION - Complete contract registry\n// Generated output: src/generated/addresses.ts\n\n/**\n * Complete contract configuration for the Vana protocol.\n *\n * ⚠️ THIS IS A SOURCE FILE - EDIT THIS TO ADD/UPDATE CONTRACTS\n *\n * @remarks\n * This file contains all contract addresses and discovery metadata in one place.\n *\n * **Contract Types:**\n * - Entry Points: Contracts without `discovery` field (must be known externally)\n * - Discoverable: Contracts with `discovery` field (auto-discovered from parent)\n *\n * **Build Process:**\n * 1. Edit this file to add/update contracts\n * 2. Run `npm run discover-addresses` to validate and generate complete registry\n * 3. Run `npm run fetch-abis` to fetch ABIs for all contracts\n *\n * @category Configuration\n * @internal This is a source file - apps should import from src/generated/addresses.ts\n */\n\ninterface DiscoveryMetadata {\n /** Parent contract to discover this from */\n parent: string;\n /** Getter function name on parent contract */\n getter: string;\n}\n\ninterface ContractConfig {\n addresses: {\n 14800: string;\n 1480: string;\n };\n /** If present, this contract can be auto-discovered from parent */\n discovery?: DiscoveryMetadata;\n}\n\nexport const CONTRACTS: Record<string, ContractConfig> = {\n // ========================================\n // DATA PORTABILITY CONTRACTS\n // ========================================\n DataPortabilityEscrow: {\n addresses: {\n 14800: \"0x07d7769081adc3a3DBe91f5E4B98E9A5a6B292e3\",\n 1480: \"0x07d7769081adc3a3DBe91f5E4B98E9A5a6B292e3\",\n },\n },\n FeeRegistry: {\n addresses: {\n 14800: \"0xb4FA18443E0FA6cdC0280D20b8cCDB2377D13Bf2\",\n 1480: \"0xb4FA18443E0FA6cdC0280D20b8cCDB2377D13Bf2\",\n },\n },\n // V2 deployment (DataPortabilityPermissionsV2Proxy). The gateway is the source\n // of truth for which deployment is live; verify with\n // `cast call <address> \"eip712Domain()(bytes1,string,string,uint256,address,bytes32,uint256[])\"`\n // which must return the domain name \"Vana Data Portability\".\n DataPortabilityPermissions: {\n addresses: {\n 14800: \"0x4d3FA76064D88e0454cFc4CaD7e5FeC3e3124011\",\n 1480: \"0x4d3FA76064D88e0454cFc4CaD7e5FeC3e3124011\",\n },\n },\n // V2 deployment (DataPortabilityServersV2Proxy) on both chains.\n DataPortabilityServers: {\n addresses: {\n 14800: \"0xCae2CE0e9caa6643ed28186cF57bd40Bd9E17Eab\",\n 1480: \"0xCae2CE0e9caa6643ed28186cF57bd40Bd9E17Eab\",\n },\n },\n DataPortabilityGrantees: {\n addresses: {\n 14800: \"0x8325C0A0948483EdA023A1A2Fd895e62C5131234\",\n 1480: \"0x8325C0A0948483EdA023A1A2Fd895e62C5131234\",\n },\n },\n DataRegistry: {\n addresses: {\n 14800: \"0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C\",\n 1480: \"0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C\",\n },\n },\n\n // ========================================\n // COMPUTING INFRASTRUCTURE\n // ========================================\n ComputeEngine: {\n addresses: {\n 14800: \"0xb2BFe33FA420c45F1Cf1287542ad81ae935447bd\",\n 1480: \"0xb2BFe33FA420c45F1Cf1287542ad81ae935447bd\",\n },\n },\n ComputeEngineTreasury: {\n addresses: {\n 14800: \"0xceB33C501B624D984bD1Ed3298f6D1d8F7CE03d1\",\n 1480: \"0xceB33C501B624D984bD1Ed3298f6D1d8F7CE03d1\",\n },\n discovery: {\n parent: \"ComputeEngine\",\n getter: \"computeEngineTreasury\",\n },\n },\n QueryEngine: {\n addresses: {\n 14800: \"0xd25Eb66EA2452cf3238A2eC6C1FD1B7F5B320490\",\n 1480: \"0xd25Eb66EA2452cf3238A2eC6C1FD1B7F5B320490\",\n },\n },\n VanaTreasury: {\n addresses: {\n 14800: \"0x8B32Ef32f22e72cc25D53f6E858f57cAe7E198f9\",\n 1480: \"0x8B32Ef32f22e72cc25D53f6E858f57cAe7E198f9\",\n },\n discovery: {\n parent: \"QueryEngine\",\n getter: \"queryEngineTreasury\",\n },\n },\n DataRefinerRegistry: {\n addresses: {\n 14800: \"0x93c3EF89369fDcf08Be159D9DeF0F18AB6Be008c\",\n 1480: \"0x93c3EF89369fDcf08Be159D9DeF0F18AB6Be008c\",\n },\n },\n ComputeInstructionRegistry: {\n addresses: {\n 14800: \"0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5\",\n 1480: \"0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5\",\n },\n },\n\n // ========================================\n // TEE POOLS (Canonical Deployments)\n // ========================================\n TeePoolPhala: {\n addresses: {\n 14800: \"0xE8EC6BD73b23Ad40E6B9a6f4bD343FAc411bD99A\",\n 1480: \"0xE8EC6BD73b23Ad40E6B9a6f4bD343FAc411bD99A\",\n },\n },\n TeePoolEphemeralStandard: {\n addresses: {\n 14800: \"0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A\",\n 1480: \"0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A\",\n },\n },\n TeePoolPersistentStandard: {\n addresses: {\n 14800: \"0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76\",\n 1480: \"0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76\",\n },\n },\n TeePoolPersistentGpu: {\n addresses: {\n 14800: \"0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9\",\n 1480: \"0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9\",\n },\n },\n TeePoolDedicatedStandard: {\n addresses: {\n 14800: \"0xf024b7ac5E8417416f53B41ecfa58C8e9396687d\",\n 1480: \"0xf024b7ac5E8417416f53B41ecfa58C8e9396687d\",\n },\n },\n TeePoolDedicatedGpu: {\n addresses: {\n 14800: \"0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E\",\n 1480: \"0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E\",\n },\n },\n\n // ========================================\n // VANA EPOCH / DLP REGISTRY\n // ========================================\n // Note: DLP rewards-specific contracts (DLPPerformance, DLPRewardDeployer,\n // DLPRewardDeployerTreasury, DLPRewardSwap, SwapHelper) were removed in the\n // protocol unification cleanup. VanaEpoch, DLPRegistry, and DLPRegistryTreasury\n // are kept because they may be referenced beyond the rewards system.\n VanaEpoch: {\n addresses: {\n 14800: \"0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0\",\n 1480: \"0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0\",\n },\n },\n DLPRegistry: {\n addresses: {\n 14800: \"0x4D59880a924526d1dD33260552Ff4328b1E18a43\",\n 1480: \"0x4D59880a924526d1dD33260552Ff4328b1E18a43\",\n },\n },\n DLPRegistryTreasury: {\n addresses: {\n 14800: \"0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a\",\n 1480: \"0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a\",\n },\n discovery: {\n parent: \"DLPRegistry\",\n getter: \"treasury\",\n },\n },\n\n // ========================================\n // VANA POOL (STAKING)\n // ========================================\n VanaPoolStaking: {\n addresses: {\n 14800: \"0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e\",\n 1480: \"0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e\",\n },\n },\n VanaPoolTreasury: {\n addresses: {\n 14800: \"0x143BE72CF2541604A7691933CAccd6D9cC17c003\",\n 1480: \"0x143BE72CF2541604A7691933CAccd6D9cC17c003\",\n },\n discovery: {\n parent: \"VanaPoolStaking\",\n getter: \"vanaPoolTreasury\",\n },\n },\n VanaPoolEntity: {\n addresses: {\n 14800: \"0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30\",\n 1480: \"0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30\",\n },\n discovery: {\n parent: \"VanaPoolStaking\",\n getter: \"vanaPoolEntity\",\n },\n },\n\n // ========================================\n // DLP DEPLOYMENT & TOKEN SYSTEM\n // ========================================\n DATFactory: {\n addresses: {\n 14800: \"0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644\",\n 1480: \"0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644\",\n },\n },\n DAT: {\n addresses: {\n 14800: \"0xA706b93ccED89f13340673889e29F0a5cd84212d\",\n 1480: \"0xA706b93ccED89f13340673889e29F0a5cd84212d\",\n },\n },\n DATPausable: {\n addresses: {\n 14800: \"0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e\",\n 1480: \"0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e\",\n },\n },\n DATVotes: {\n addresses: {\n 14800: \"0xaE04c8A77E9B27869eb563720524A9aE0baf1831\",\n 1480: \"0xaE04c8A77E9B27869eb563720524A9aE0baf1831\",\n },\n },\n\n // ========================================\n // EXTERNAL DEPENDENCIES (DeFi)\n // ========================================\n WVANA: {\n addresses: {\n 14800: \"0xbccc4b4c6530F82FE309c5E845E50b5E9C89f2AD\",\n 1480: \"0x00EDdD9621Fb08436d0331c149D1690909a5906d\",\n },\n },\n UniswapV3NonfungiblePositionManager: {\n addresses: {\n 14800: \"0x48Bd633f4B9128a38Ebb4a48b6975EB3Eaf1931b\",\n 1480: \"0x45a2992e1bFdCF9b9AcE0a84A238f2E56F481816\",\n },\n },\n UniswapV3QuoterV2: {\n addresses: {\n 14800: \"0x3152246f3CD4dD465292Dd4Ffd792E2Cf602e332\",\n 1480: \"0x1b13728ea3C90863990aC0e05987CfeC1888908c\",\n },\n },\n\n // ========================================\n // UTILITY CONTRACTS\n // ========================================\n Multicall3: {\n addresses: {\n 14800: \"0xD8d2dFca27E8797fd779F8547166A2d3B29d360E\",\n 1480: \"0xD8d2dFca27E8797fd779F8547166A2d3B29d360E\",\n },\n },\n Multisend: {\n addresses: {\n 14800: \"0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d\",\n 1480: \"0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d\",\n },\n },\n} as const;\n\n// Legacy DLPRoot* and deprecated TeePool entries were removed in the protocol\n// unification cleanup. They were part of the old DLP rewards system superseded\n// by other contracts.\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwCO,MAAM,YAA4C;AAAA;AAAA;AAAA;AAAA,EAIvD,uBAAuB;AAAA,IACrB,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,aAAa;AAAA,IACX,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,4BAA4B;AAAA,IAC1B,WAAW;AAAA,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AO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,KAAK;AAAA,IACH,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,aAAa;AAAA,IACX,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,UAAU;AAAA,IACR,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO;AAAA,IACL,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,qCAAqC;AAAA,IACnC,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,mBAAmB;AAAA,IACjB,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY;AAAA,IACV,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,WAAW;AAAA,IACT,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
|
|
@@ -14,16 +14,21 @@ const CONTRACTS = {
|
|
|
14
14
|
1480: "0xb4FA18443E0FA6cdC0280D20b8cCDB2377D13Bf2"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
|
+
// V2 deployment (DataPortabilityPermissionsV2Proxy). The gateway is the source
|
|
18
|
+
// of truth for which deployment is live; verify with
|
|
19
|
+
// `cast call <address> "eip712Domain()(bytes1,string,string,uint256,address,bytes32,uint256[])"`
|
|
20
|
+
// which must return the domain name "Vana Data Portability".
|
|
17
21
|
DataPortabilityPermissions: {
|
|
18
22
|
addresses: {
|
|
19
|
-
14800: "
|
|
20
|
-
1480: "
|
|
23
|
+
14800: "0x4d3FA76064D88e0454cFc4CaD7e5FeC3e3124011",
|
|
24
|
+
1480: "0x4d3FA76064D88e0454cFc4CaD7e5FeC3e3124011"
|
|
21
25
|
}
|
|
22
26
|
},
|
|
27
|
+
// V2 deployment (DataPortabilityServersV2Proxy) on both chains.
|
|
23
28
|
DataPortabilityServers: {
|
|
24
29
|
addresses: {
|
|
25
30
|
14800: "0xCae2CE0e9caa6643ed28186cF57bd40Bd9E17Eab",
|
|
26
|
-
1480: "
|
|
31
|
+
1480: "0xCae2CE0e9caa6643ed28186cF57bd40Bd9E17Eab"
|
|
27
32
|
}
|
|
28
33
|
},
|
|
29
34
|
DataPortabilityGrantees: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/config/contracts.config.ts"],"sourcesContent":["// SOURCE CONFIGURATION - Complete contract registry\n// Generated output: src/generated/addresses.ts\n\n/**\n * Complete contract configuration for the Vana protocol.\n *\n * ⚠️ THIS IS A SOURCE FILE - EDIT THIS TO ADD/UPDATE CONTRACTS\n *\n * @remarks\n * This file contains all contract addresses and discovery metadata in one place.\n *\n * **Contract Types:**\n * - Entry Points: Contracts without `discovery` field (must be known externally)\n * - Discoverable: Contracts with `discovery` field (auto-discovered from parent)\n *\n * **Build Process:**\n * 1. Edit this file to add/update contracts\n * 2. Run `npm run discover-addresses` to validate and generate complete registry\n * 3. Run `npm run fetch-abis` to fetch ABIs for all contracts\n *\n * @category Configuration\n * @internal This is a source file - apps should import from src/generated/addresses.ts\n */\n\ninterface DiscoveryMetadata {\n /** Parent contract to discover this from */\n parent: string;\n /** Getter function name on parent contract */\n getter: string;\n}\n\ninterface ContractConfig {\n addresses: {\n 14800: string;\n 1480: string;\n };\n /** If present, this contract can be auto-discovered from parent */\n discovery?: DiscoveryMetadata;\n}\n\nexport const CONTRACTS: Record<string, ContractConfig> = {\n // ========================================\n // DATA PORTABILITY CONTRACTS\n // ========================================\n DataPortabilityEscrow: {\n addresses: {\n 14800: \"0x07d7769081adc3a3DBe91f5E4B98E9A5a6B292e3\",\n 1480: \"0x07d7769081adc3a3DBe91f5E4B98E9A5a6B292e3\",\n },\n },\n FeeRegistry: {\n addresses: {\n 14800: \"0xb4FA18443E0FA6cdC0280D20b8cCDB2377D13Bf2\",\n 1480: \"0xb4FA18443E0FA6cdC0280D20b8cCDB2377D13Bf2\",\n },\n },\n DataPortabilityPermissions: {\n addresses: {\n 14800: \"0xD54523048AdD05b4d734aFaE7C68324Ebb7373eF\",\n 1480: \"0xD54523048AdD05b4d734aFaE7C68324Ebb7373eF\",\n },\n },\n DataPortabilityServers: {\n addresses: {\n 14800: \"0xCae2CE0e9caa6643ed28186cF57bd40Bd9E17Eab\",\n 1480: \"0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c\",\n },\n },\n DataPortabilityGrantees: {\n addresses: {\n 14800: \"0x8325C0A0948483EdA023A1A2Fd895e62C5131234\",\n 1480: \"0x8325C0A0948483EdA023A1A2Fd895e62C5131234\",\n },\n },\n DataRegistry: {\n addresses: {\n 14800: \"0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C\",\n 1480: \"0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C\",\n },\n },\n\n // ========================================\n // COMPUTING INFRASTRUCTURE\n // ========================================\n ComputeEngine: {\n addresses: {\n 14800: \"0xb2BFe33FA420c45F1Cf1287542ad81ae935447bd\",\n 1480: \"0xb2BFe33FA420c45F1Cf1287542ad81ae935447bd\",\n },\n },\n ComputeEngineTreasury: {\n addresses: {\n 14800: \"0xceB33C501B624D984bD1Ed3298f6D1d8F7CE03d1\",\n 1480: \"0xceB33C501B624D984bD1Ed3298f6D1d8F7CE03d1\",\n },\n discovery: {\n parent: \"ComputeEngine\",\n getter: \"computeEngineTreasury\",\n },\n },\n QueryEngine: {\n addresses: {\n 14800: \"0xd25Eb66EA2452cf3238A2eC6C1FD1B7F5B320490\",\n 1480: \"0xd25Eb66EA2452cf3238A2eC6C1FD1B7F5B320490\",\n },\n },\n VanaTreasury: {\n addresses: {\n 14800: \"0x8B32Ef32f22e72cc25D53f6E858f57cAe7E198f9\",\n 1480: \"0x8B32Ef32f22e72cc25D53f6E858f57cAe7E198f9\",\n },\n discovery: {\n parent: \"QueryEngine\",\n getter: \"queryEngineTreasury\",\n },\n },\n DataRefinerRegistry: {\n addresses: {\n 14800: \"0x93c3EF89369fDcf08Be159D9DeF0F18AB6Be008c\",\n 1480: \"0x93c3EF89369fDcf08Be159D9DeF0F18AB6Be008c\",\n },\n },\n ComputeInstructionRegistry: {\n addresses: {\n 14800: \"0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5\",\n 1480: \"0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5\",\n },\n },\n\n // ========================================\n // TEE POOLS (Canonical Deployments)\n // ========================================\n TeePoolPhala: {\n addresses: {\n 14800: \"0xE8EC6BD73b23Ad40E6B9a6f4bD343FAc411bD99A\",\n 1480: \"0xE8EC6BD73b23Ad40E6B9a6f4bD343FAc411bD99A\",\n },\n },\n TeePoolEphemeralStandard: {\n addresses: {\n 14800: \"0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A\",\n 1480: \"0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A\",\n },\n },\n TeePoolPersistentStandard: {\n addresses: {\n 14800: \"0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76\",\n 1480: \"0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76\",\n },\n },\n TeePoolPersistentGpu: {\n addresses: {\n 14800: \"0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9\",\n 1480: \"0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9\",\n },\n },\n TeePoolDedicatedStandard: {\n addresses: {\n 14800: \"0xf024b7ac5E8417416f53B41ecfa58C8e9396687d\",\n 1480: \"0xf024b7ac5E8417416f53B41ecfa58C8e9396687d\",\n },\n },\n TeePoolDedicatedGpu: {\n addresses: {\n 14800: \"0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E\",\n 1480: \"0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E\",\n },\n },\n\n // ========================================\n // VANA EPOCH / DLP REGISTRY\n // ========================================\n // Note: DLP rewards-specific contracts (DLPPerformance, DLPRewardDeployer,\n // DLPRewardDeployerTreasury, DLPRewardSwap, SwapHelper) were removed in the\n // protocol unification cleanup. VanaEpoch, DLPRegistry, and DLPRegistryTreasury\n // are kept because they may be referenced beyond the rewards system.\n VanaEpoch: {\n addresses: {\n 14800: \"0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0\",\n 1480: \"0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0\",\n },\n },\n DLPRegistry: {\n addresses: {\n 14800: \"0x4D59880a924526d1dD33260552Ff4328b1E18a43\",\n 1480: \"0x4D59880a924526d1dD33260552Ff4328b1E18a43\",\n },\n },\n DLPRegistryTreasury: {\n addresses: {\n 14800: \"0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a\",\n 1480: \"0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a\",\n },\n discovery: {\n parent: \"DLPRegistry\",\n getter: \"treasury\",\n },\n },\n\n // ========================================\n // VANA POOL (STAKING)\n // ========================================\n VanaPoolStaking: {\n addresses: {\n 14800: \"0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e\",\n 1480: \"0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e\",\n },\n },\n VanaPoolTreasury: {\n addresses: {\n 14800: \"0x143BE72CF2541604A7691933CAccd6D9cC17c003\",\n 1480: \"0x143BE72CF2541604A7691933CAccd6D9cC17c003\",\n },\n discovery: {\n parent: \"VanaPoolStaking\",\n getter: \"vanaPoolTreasury\",\n },\n },\n VanaPoolEntity: {\n addresses: {\n 14800: \"0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30\",\n 1480: \"0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30\",\n },\n discovery: {\n parent: \"VanaPoolStaking\",\n getter: \"vanaPoolEntity\",\n },\n },\n\n // ========================================\n // DLP DEPLOYMENT & TOKEN SYSTEM\n // ========================================\n DATFactory: {\n addresses: {\n 14800: \"0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644\",\n 1480: \"0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644\",\n },\n },\n DAT: {\n addresses: {\n 14800: \"0xA706b93ccED89f13340673889e29F0a5cd84212d\",\n 1480: \"0xA706b93ccED89f13340673889e29F0a5cd84212d\",\n },\n },\n DATPausable: {\n addresses: {\n 14800: \"0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e\",\n 1480: \"0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e\",\n },\n },\n DATVotes: {\n addresses: {\n 14800: \"0xaE04c8A77E9B27869eb563720524A9aE0baf1831\",\n 1480: \"0xaE04c8A77E9B27869eb563720524A9aE0baf1831\",\n },\n },\n\n // ========================================\n // EXTERNAL DEPENDENCIES (DeFi)\n // ========================================\n WVANA: {\n addresses: {\n 14800: \"0xbccc4b4c6530F82FE309c5E845E50b5E9C89f2AD\",\n 1480: \"0x00EDdD9621Fb08436d0331c149D1690909a5906d\",\n },\n },\n UniswapV3NonfungiblePositionManager: {\n addresses: {\n 14800: \"0x48Bd633f4B9128a38Ebb4a48b6975EB3Eaf1931b\",\n 1480: \"0x45a2992e1bFdCF9b9AcE0a84A238f2E56F481816\",\n },\n },\n UniswapV3QuoterV2: {\n addresses: {\n 14800: \"0x3152246f3CD4dD465292Dd4Ffd792E2Cf602e332\",\n 1480: \"0x1b13728ea3C90863990aC0e05987CfeC1888908c\",\n },\n },\n\n // ========================================\n // UTILITY CONTRACTS\n // ========================================\n Multicall3: {\n addresses: {\n 14800: \"0xD8d2dFca27E8797fd779F8547166A2d3B29d360E\",\n 1480: \"0xD8d2dFca27E8797fd779F8547166A2d3B29d360E\",\n },\n },\n Multisend: {\n addresses: {\n 14800: \"0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d\",\n 1480: \"0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d\",\n },\n },\n} as const;\n\n// Legacy DLPRoot* and deprecated TeePool entries were removed in the protocol\n// unification cleanup. They were part of the old DLP rewards system superseded\n// by other contracts.\n"],"mappings":"AAwCO,MAAM,YAA4C;AAAA;AAAA;AAAA;AAAA,EAIvD,uBAAuB;AAAA,IACrB,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,aAAa;AAAA,IACX,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,4BAA4B;AAAA,IAC1B,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,wBAAwB;AAAA,IACtB,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,yBAAyB;AAAA,IACvB,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,cAAc;AAAA,IACZ,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,eAAe;AAAA,IACb,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,uBAAuB;AAAA,IACrB,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,IACA,WAAW;AAAA,MACT,QAAQ;AAAA,MACR,QAAQ;AAAA,IACV;AAAA,EACF;AAAA,EACA,aAAa;AAAA,IACX,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,cAAc;AAAA,IACZ,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,IACA,WAAW;AAAA,MACT,QAAQ;AAAA,MACR,QAAQ;AAA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
+
{"version":3,"sources":["../../src/config/contracts.config.ts"],"sourcesContent":["// SOURCE CONFIGURATION - Complete contract registry\n// Generated output: src/generated/addresses.ts\n\n/**\n * Complete contract configuration for the Vana protocol.\n *\n * ⚠️ THIS IS A SOURCE FILE - EDIT THIS TO ADD/UPDATE CONTRACTS\n *\n * @remarks\n * This file contains all contract addresses and discovery metadata in one place.\n *\n * **Contract Types:**\n * - Entry Points: Contracts without `discovery` field (must be known externally)\n * - Discoverable: Contracts with `discovery` field (auto-discovered from parent)\n *\n * **Build Process:**\n * 1. Edit this file to add/update contracts\n * 2. Run `npm run discover-addresses` to validate and generate complete registry\n * 3. Run `npm run fetch-abis` to fetch ABIs for all contracts\n *\n * @category Configuration\n * @internal This is a source file - apps should import from src/generated/addresses.ts\n */\n\ninterface DiscoveryMetadata {\n /** Parent contract to discover this from */\n parent: string;\n /** Getter function name on parent contract */\n getter: string;\n}\n\ninterface ContractConfig {\n addresses: {\n 14800: string;\n 1480: string;\n };\n /** If present, this contract can be auto-discovered from parent */\n discovery?: DiscoveryMetadata;\n}\n\nexport const CONTRACTS: Record<string, ContractConfig> = {\n // ========================================\n // DATA PORTABILITY CONTRACTS\n // ========================================\n DataPortabilityEscrow: {\n addresses: {\n 14800: \"0x07d7769081adc3a3DBe91f5E4B98E9A5a6B292e3\",\n 1480: \"0x07d7769081adc3a3DBe91f5E4B98E9A5a6B292e3\",\n },\n },\n FeeRegistry: {\n addresses: {\n 14800: \"0xb4FA18443E0FA6cdC0280D20b8cCDB2377D13Bf2\",\n 1480: \"0xb4FA18443E0FA6cdC0280D20b8cCDB2377D13Bf2\",\n },\n },\n // V2 deployment (DataPortabilityPermissionsV2Proxy). The gateway is the source\n // of truth for which deployment is live; verify with\n // `cast call <address> \"eip712Domain()(bytes1,string,string,uint256,address,bytes32,uint256[])\"`\n // which must return the domain name \"Vana Data Portability\".\n DataPortabilityPermissions: {\n addresses: {\n 14800: \"0x4d3FA76064D88e0454cFc4CaD7e5FeC3e3124011\",\n 1480: \"0x4d3FA76064D88e0454cFc4CaD7e5FeC3e3124011\",\n },\n },\n // V2 deployment (DataPortabilityServersV2Proxy) on both chains.\n DataPortabilityServers: {\n addresses: {\n 14800: \"0xCae2CE0e9caa6643ed28186cF57bd40Bd9E17Eab\",\n 1480: \"0xCae2CE0e9caa6643ed28186cF57bd40Bd9E17Eab\",\n },\n },\n DataPortabilityGrantees: {\n addresses: {\n 14800: \"0x8325C0A0948483EdA023A1A2Fd895e62C5131234\",\n 1480: \"0x8325C0A0948483EdA023A1A2Fd895e62C5131234\",\n },\n },\n DataRegistry: {\n addresses: {\n 14800: \"0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C\",\n 1480: \"0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C\",\n },\n },\n\n // ========================================\n // COMPUTING INFRASTRUCTURE\n // ========================================\n ComputeEngine: {\n addresses: {\n 14800: \"0xb2BFe33FA420c45F1Cf1287542ad81ae935447bd\",\n 1480: \"0xb2BFe33FA420c45F1Cf1287542ad81ae935447bd\",\n },\n },\n ComputeEngineTreasury: {\n addresses: {\n 14800: \"0xceB33C501B624D984bD1Ed3298f6D1d8F7CE03d1\",\n 1480: \"0xceB33C501B624D984bD1Ed3298f6D1d8F7CE03d1\",\n },\n discovery: {\n parent: \"ComputeEngine\",\n getter: \"computeEngineTreasury\",\n },\n },\n QueryEngine: {\n addresses: {\n 14800: \"0xd25Eb66EA2452cf3238A2eC6C1FD1B7F5B320490\",\n 1480: \"0xd25Eb66EA2452cf3238A2eC6C1FD1B7F5B320490\",\n },\n },\n VanaTreasury: {\n addresses: {\n 14800: \"0x8B32Ef32f22e72cc25D53f6E858f57cAe7E198f9\",\n 1480: \"0x8B32Ef32f22e72cc25D53f6E858f57cAe7E198f9\",\n },\n discovery: {\n parent: \"QueryEngine\",\n getter: \"queryEngineTreasury\",\n },\n },\n DataRefinerRegistry: {\n addresses: {\n 14800: \"0x93c3EF89369fDcf08Be159D9DeF0F18AB6Be008c\",\n 1480: \"0x93c3EF89369fDcf08Be159D9DeF0F18AB6Be008c\",\n },\n },\n ComputeInstructionRegistry: {\n addresses: {\n 14800: \"0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5\",\n 1480: \"0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5\",\n },\n },\n\n // ========================================\n // TEE POOLS (Canonical Deployments)\n // ========================================\n TeePoolPhala: {\n addresses: {\n 14800: \"0xE8EC6BD73b23Ad40E6B9a6f4bD343FAc411bD99A\",\n 1480: \"0xE8EC6BD73b23Ad40E6B9a6f4bD343FAc411bD99A\",\n },\n },\n TeePoolEphemeralStandard: {\n addresses: {\n 14800: \"0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A\",\n 1480: \"0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A\",\n },\n },\n TeePoolPersistentStandard: {\n addresses: {\n 14800: \"0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76\",\n 1480: \"0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76\",\n },\n },\n TeePoolPersistentGpu: {\n addresses: {\n 14800: \"0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9\",\n 1480: \"0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9\",\n },\n },\n TeePoolDedicatedStandard: {\n addresses: {\n 14800: \"0xf024b7ac5E8417416f53B41ecfa58C8e9396687d\",\n 1480: \"0xf024b7ac5E8417416f53B41ecfa58C8e9396687d\",\n },\n },\n TeePoolDedicatedGpu: {\n addresses: {\n 14800: \"0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E\",\n 1480: \"0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E\",\n },\n },\n\n // ========================================\n // VANA EPOCH / DLP REGISTRY\n // ========================================\n // Note: DLP rewards-specific contracts (DLPPerformance, DLPRewardDeployer,\n // DLPRewardDeployerTreasury, DLPRewardSwap, SwapHelper) were removed in the\n // protocol unification cleanup. VanaEpoch, DLPRegistry, and DLPRegistryTreasury\n // are kept because they may be referenced beyond the rewards system.\n VanaEpoch: {\n addresses: {\n 14800: \"0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0\",\n 1480: \"0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0\",\n },\n },\n DLPRegistry: {\n addresses: {\n 14800: \"0x4D59880a924526d1dD33260552Ff4328b1E18a43\",\n 1480: \"0x4D59880a924526d1dD33260552Ff4328b1E18a43\",\n },\n },\n DLPRegistryTreasury: {\n addresses: {\n 14800: \"0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a\",\n 1480: \"0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a\",\n },\n discovery: {\n parent: \"DLPRegistry\",\n getter: \"treasury\",\n },\n },\n\n // ========================================\n // VANA POOL (STAKING)\n // ========================================\n VanaPoolStaking: {\n addresses: {\n 14800: \"0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e\",\n 1480: \"0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e\",\n },\n },\n VanaPoolTreasury: {\n addresses: {\n 14800: \"0x143BE72CF2541604A7691933CAccd6D9cC17c003\",\n 1480: \"0x143BE72CF2541604A7691933CAccd6D9cC17c003\",\n },\n discovery: {\n parent: \"VanaPoolStaking\",\n getter: \"vanaPoolTreasury\",\n },\n },\n VanaPoolEntity: {\n addresses: {\n 14800: \"0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30\",\n 1480: \"0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30\",\n },\n discovery: {\n parent: \"VanaPoolStaking\",\n getter: \"vanaPoolEntity\",\n },\n },\n\n // ========================================\n // DLP DEPLOYMENT & TOKEN SYSTEM\n // ========================================\n DATFactory: {\n addresses: {\n 14800: \"0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644\",\n 1480: \"0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644\",\n },\n },\n DAT: {\n addresses: {\n 14800: \"0xA706b93ccED89f13340673889e29F0a5cd84212d\",\n 1480: \"0xA706b93ccED89f13340673889e29F0a5cd84212d\",\n },\n },\n DATPausable: {\n addresses: {\n 14800: \"0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e\",\n 1480: \"0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e\",\n },\n },\n DATVotes: {\n addresses: {\n 14800: \"0xaE04c8A77E9B27869eb563720524A9aE0baf1831\",\n 1480: \"0xaE04c8A77E9B27869eb563720524A9aE0baf1831\",\n },\n },\n\n // ========================================\n // EXTERNAL DEPENDENCIES (DeFi)\n // ========================================\n WVANA: {\n addresses: {\n 14800: \"0xbccc4b4c6530F82FE309c5E845E50b5E9C89f2AD\",\n 1480: \"0x00EDdD9621Fb08436d0331c149D1690909a5906d\",\n },\n },\n UniswapV3NonfungiblePositionManager: {\n addresses: {\n 14800: \"0x48Bd633f4B9128a38Ebb4a48b6975EB3Eaf1931b\",\n 1480: \"0x45a2992e1bFdCF9b9AcE0a84A238f2E56F481816\",\n },\n },\n UniswapV3QuoterV2: {\n addresses: {\n 14800: \"0x3152246f3CD4dD465292Dd4Ffd792E2Cf602e332\",\n 1480: \"0x1b13728ea3C90863990aC0e05987CfeC1888908c\",\n },\n },\n\n // ========================================\n // UTILITY CONTRACTS\n // ========================================\n Multicall3: {\n addresses: {\n 14800: \"0xD8d2dFca27E8797fd779F8547166A2d3B29d360E\",\n 1480: \"0xD8d2dFca27E8797fd779F8547166A2d3B29d360E\",\n },\n },\n Multisend: {\n addresses: {\n 14800: \"0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d\",\n 1480: \"0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d\",\n },\n },\n} as const;\n\n// Legacy DLPRoot* and deprecated TeePool entries were removed in the protocol\n// unification cleanup. They were part of the old DLP rewards system superseded\n// by other contracts.\n"],"mappings":"AAwCO,MAAM,YAA4C;AAAA;AAAA;AAAA;AAAA,EAIvD,uBAAuB;AAAA,IACrB,WAAW;AAAA,MACT,OAAO;AAAA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,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,IACA,WAAW;AAAA,MACT,QAAQ;AAAA,MACR,QAAQ;AAAA,IACV;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY;AAAA,IACV,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,KAAK;AAAA,IACH,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,aAAa;AAAA,IACX,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,UAAU;AAAA,IACR,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO;AAAA,IACL,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,qCAAqC;AAAA,IACnC,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,mBAAmB;AAAA,IACjB,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY;AAAA,IACV,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,WAAW;AAAA,IACT,WAAW;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
|
|
@@ -23,6 +23,7 @@ __export(controller_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(controller_exports);
|
|
24
24
|
var import_accounts = require("viem/accounts");
|
|
25
25
|
var import_scopes = require("../protocol/scopes");
|
|
26
|
+
var import_scope_actions = require("../protocol/scope-actions");
|
|
26
27
|
var import_escrow = require("../protocol/escrow");
|
|
27
28
|
var import_addresses = require("../generated/addresses");
|
|
28
29
|
var import_access_request_client = require("./access-request-client");
|
|
@@ -45,8 +46,8 @@ function createDirectDataController(config) {
|
|
|
45
46
|
if (!config.scopes || config.scopes.length === 0) {
|
|
46
47
|
throw new import_errors.DirectConfigError("At least one scope is required");
|
|
47
48
|
}
|
|
48
|
-
for (const
|
|
49
|
-
(0, import_scopes.parseScope)(scope);
|
|
49
|
+
for (const entry of config.scopes) {
|
|
50
|
+
(0, import_scopes.parseScope)((0, import_scope_actions.parseScopeEntry)(entry).scope);
|
|
50
51
|
}
|
|
51
52
|
const env = config.env ?? "production";
|
|
52
53
|
const network = config.network ?? (0, import_endpoints.getDirectDefaultNetwork)(env);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/direct/controller.ts"],"sourcesContent":["/**\n * Direct Data Controller — the server-side facade for the two-tab Data\n * Portability flow.\n *\n * @remarks\n * One controller owns an app's private key, source, scopes, app identity, and\n * payment flow. It exposes the three methods the builder guide documents:\n *\n * - {@link DirectDataController.createAccessRequest} — start an approval request.\n * - {@link DirectDataController.getAccessRequestStatus} — poll while the Vana tab is open.\n * - {@link DirectDataController.readApprovedData} — read from the Personal Server,\n * handling 402 Payment Required.\n *\n * Access requests are created through the Vana Account access-request API; the\n * Personal Server read uses Web3Signed auth; and payment uses the DPv2 escrow\n * surface (`protocol/escrow`) — when a read returns `402`, the controller signs\n * a `GenericPayment` with the app key, settles it through the escrow gateway,\n * and retries.\n *\n * @category Direct\n * @module direct/controller\n */\n\nimport { privateKeyToAccount } from \"viem/accounts\";\nimport type { Hex } from \"viem\";\nimport type { Web3SignedSignFn } from \"../auth/web3-signed-builder\";\nimport { parseScope } from \"../protocol/scopes\";\nimport { createEscrowGatewayClient } from \"../protocol/escrow\";\nimport { CONTRACTS } from \"../generated/addresses\";\nimport {\n createDefaultAccessRequestClient,\n type FetchLike,\n} from \"./access-request-client\";\nimport {\n getDirectDefaultNetwork,\n getDirectEndpoints,\n getDirectNetworkChainId,\n} from \"./endpoints\";\nimport {\n AccessNotApprovedError,\n DirectConfigError,\n ScopeNotApprovedError,\n} from \"./errors\";\nimport {\n type EscrowPaymentConfig,\n type SignTypedDataFn,\n} from \"./escrow-payment\";\nimport {\n readPersonalServerData,\n type PersonalServerFetch,\n type PersonalServerTransportRetryOptions,\n} from \"./personal-server-read\";\nimport type {\n AccessRequest,\n AccessRequestClient,\n AccessRequestStatus,\n AccessRequestStatusValue,\n ApprovedDataResult,\n AppIdentity,\n DirectAppConfig,\n DirectEnv,\n DirectNetwork,\n DirectPaymentResponseMetadata,\n DirectServiceEndpoints,\n ForegroundDelivery,\n MultiScopeDataResult,\n} from \"./types\";\n\n/** Configuration for {@link createDirectDataController}. */\nexport interface DirectDataControllerConfig {\n /** Target environment. Defaults to `\"production\"`. */\n env?: DirectEnv;\n /**\n * Target Vana network for chain-aware defaults. Defaults to the selected\n * environment's historical network (`mainnet` for production, `moksha` for\n * dev). Use `network: \"moksha\"` with the default production env for\n * production app/API URLs on testnet.\n */\n network?: DirectNetwork;\n /**\n * The app private key (`0x`-prefixed, 32 bytes). Server-side only — this key\n * is the app's on-chain identity and is never exposed to the browser.\n */\n appPrivateKey?: string;\n /**\n * @deprecated Use {@link DirectDataControllerConfig.appPrivateKey}. Accepted as\n * a backwards-compatible alias; if both are set, `appPrivateKey` wins.\n */\n builderPrivateKey?: string;\n /** App identity advertised during approval. */\n app: DirectAppConfig;\n /** Data source key (e.g. `\"icloud_notes\"`). */\n source: string;\n /** Scopes to request (e.g. `[\"icloud_notes.notes\"]`). At least one required. */\n scopes: string[];\n /**\n * Override the resolved service endpoints (partial). Useful for pointing at a\n * non-standard deployment.\n */\n endpoints?: Partial<DirectServiceEndpoints>;\n /**\n * Client for the Vana Account access-request API. Defaults to a client against\n * the resolved Vana Account endpoints; inject your own to point at a custom\n * deployment or to supply a test double.\n */\n accessRequestClient?: AccessRequestClient;\n /**\n * Escrow settlement config used when a Personal Server read returns `402`.\n *\n * @remarks\n * Wires the DPv2 escrow gateway (`protocol/escrow`). The controller supplies\n * the EIP-712 `signTypedData` from the app key automatically.\n *\n * When omitted (or partially omitted), the SDK derives defaults from the\n * per-network endpoints table and the contract registry:\n * - `client` defaults to a gateway client at `endpoints.escrowGatewayUrl`\n * - `escrowContract` defaults to `CONTRACTS.DataPortabilityEscrow.addresses[chainId]`\n * - `chainId` defaults to the controller's resolved chain id\n *\n * Provide this field only to override a specific default.\n */\n escrow?: Partial<DirectEscrowConfig>;\n /** `fetch` used by the default access-request client. Defaults to `globalThis.fetch`. */\n fetchFn?: FetchLike;\n /** `fetch` used for the Personal Server read. Defaults to `globalThis.fetch`. */\n personalServerFetch?: PersonalServerFetch;\n /**\n * Transport-retry knobs for the Personal Server read\n * ({@link PersonalServerTransportRetryOptions}). Defaults to 3 attempts with\n * exponential backoff. Retries fire only when fetch throws (the browser-PS\n * relay reconnect window), never on a received HTTP status, and never\n * re-sign a payment.\n */\n personalServerTransportRetry?: PersonalServerTransportRetryOptions;\n}\n\n/**\n * Controller-level escrow config — the {@link EscrowPaymentConfig} minus the\n * `signTypedData` and `chainId` the controller injects itself.\n */\nexport interface DirectEscrowConfig extends Omit<\n EscrowPaymentConfig,\n \"signTypedData\" | \"chainId\"\n> {\n /**\n * Chain id for the EIP-712 domain. Defaults to the controller's environment\n * (1480 for mainnet, 14800 for moksha).\n */\n chainId?: number;\n}\n\n/**\n * Server-side controller for the direct Data Portability flow.\n *\n * @typeParam T - Shape of the data returned by {@link DirectDataController.readApprovedData}.\n */\nexport interface DirectDataController {\n /** The on-chain address of the app, derived from `appPrivateKey`. */\n readonly appAddress: string;\n\n /**\n * The app's on-chain address — the address to fund and inspect in the Builder\n * activity report. Equivalent to {@link DirectDataController.appAddress}.\n *\n * @returns The app's `0x`-prefixed address.\n */\n getAppAddress(): string;\n\n /**\n * The app's full identity: its configured id/name/homepage plus the derived\n * on-chain address. Useful for telling builders which app address to fund or\n * look up.\n *\n * @returns `{ id, name, homepageUrl, address }`.\n */\n getAppIdentity(): AppIdentity;\n\n /**\n * Create an access request the user can approve.\n *\n * @param input - The post-approval return URL and optional create retry key.\n * @returns The request id, HTTPS approval URL, and — for a pending deep Direct\n * request on mobile — an optional HTTPS `mobileContinuationUrl`.\n */\n createAccessRequest(input: {\n returnUrl: string;\n /** Optional foreground mobile delivery callback. */\n foregroundDelivery?: ForegroundDelivery;\n /**\n * Stable retry key when the caller retries after an uncertain response.\n * Each create without one gets its own generated key.\n */\n idempotencyKey?: string;\n }): Promise<AccessRequest>;\n\n /**\n * Fetch the current status of an access request.\n *\n * @param requestId - The `dcr_*` id from {@link DirectDataController.createAccessRequest}.\n * @returns `{ status, personalServerUrl?, grantId?, scope?, scopes? }`.\n */\n getAccessRequestStatus(requestId: string): Promise<AccessRequestStatus>;\n\n /**\n * Read the approved data from the user's Personal Server.\n *\n * @remarks\n * Resolves the request to its grant + Personal Server and performs a Web3Signed\n * read. Hides the `402 Payment Required` flow by default: if a read needs\n * payment, it signs the Personal Server's payment challenge, retries with\n * `X-PAYMENT`, and attaches shape-validated but unauthenticated\n * {@link DirectPaymentResponseMetadata} under `payment` when the Personal\n * Server returns it. After a successful read, the controller acknowledges\n * the DCR so Vana Web can close/redirect the approval tab.\n *\n * A request can approve several scopes. This reads **one** of them — `scope`\n * when given, otherwise the first approved scope. Use\n * {@link DirectDataController.readAllApprovedData} to read them all.\n *\n * Acknowledging moves the DCR to `completed`, which is terminal and no longer\n * read-ready. To read several scopes with your own loop, pass\n * `acknowledge: false` on every call but the last.\n *\n * @param input - The `dcr_*` request id, the optional `scope` to read, and an\n * optional `acknowledge` flag (default `true`).\n * @returns `{ scope, data, payment? }`.\n * @throws {@link AccessNotApprovedError} if the request is not approved.\n * @throws {@link ScopeNotApprovedError} if `scope` is not an approved scope.\n * @throws {@link PaymentRequiredError} if payment is required but unsettled.\n */\n readApprovedData<T = unknown>(input: {\n requestId: string;\n scope?: string;\n acknowledge?: boolean;\n }): Promise<ApprovedDataResult<T>>;\n\n /**\n * Read every scope the user approved on a request.\n *\n * @remarks\n * Reads the scopes in approval order, then acknowledges the DCR **once**,\n * after the last read — acknowledging earlier would move the request to\n * `completed` and make the remaining scopes unreadable.\n *\n * Each scope is a separate Personal Server read that settles its own\n * `data_access` fee from escrow, so reading N scopes costs N times a\n * single-scope read. The one-off registration fee is charged per grant, not\n * per scope.\n *\n * A scope that fails does not abort the rest: successes land in `results` and\n * failures in `errors`, because the fees for earlier scopes are already spent.\n * If any scope fails the request is left unacknowledged, so the scopes that\n * failed stay retryable — read them with `readApprovedData({ scope })` and\n * acknowledge on the last one.\n *\n * @param input - The `dcr_*` request id to read.\n * @returns `{ results, errors }`, both keyed by scope.\n * @throws {@link AccessNotApprovedError} if the request is not approved.\n */\n readAllApprovedData<T = unknown>(input: {\n requestId: string;\n }): Promise<MultiScopeDataResult<T>>;\n}\n\nfunction isHexPrivateKey(value: string): value is Hex {\n return /^0x[0-9a-fA-F]{64}$/.test(value);\n}\n\n// A DCR is read-ready only while the grant exists and the Personal Server is\n// still serving it: `approved` (durable PS) or `ready_for_read` (browser PS).\n// `completed` is terminal — the app already read and acknowledged, and the\n// browser PS may be gone — so it is deliberately excluded here.\nfunction isReadReadyStatus(status: AccessRequestStatusValue): boolean {\n return status === \"approved\" || status === \"ready_for_read\";\n}\n\n/**\n * Create a {@link DirectDataController}.\n *\n * @param config - Controller configuration (env, key, app identity, source, scopes).\n * @returns A ready-to-use controller.\n * @throws {@link DirectConfigError} when the key or scopes are invalid.\n */\nexport function createDirectDataController(\n config: DirectDataControllerConfig,\n): DirectDataController {\n // `appPrivateKey` is the documented field; `builderPrivateKey` is a\n // deprecated alias kept for backwards compatibility.\n const privateKey = config.appPrivateKey ?? config.builderPrivateKey;\n if (!privateKey || !isHexPrivateKey(privateKey)) {\n throw new DirectConfigError(\n \"appPrivateKey must be a 0x-prefixed 32-byte hex string\",\n );\n }\n if (!config.scopes || config.scopes.length === 0) {\n throw new DirectConfigError(\"At least one scope is required\");\n }\n // Validate scopes eagerly so misconfiguration fails at construction.\n for (const scope of config.scopes) {\n parseScope(scope);\n }\n\n const env: DirectEnv = config.env ?? \"production\";\n const network: DirectNetwork = config.network ?? getDirectDefaultNetwork(env);\n const defaultEndpoints = getDirectEndpoints(env);\n const chainId = config.endpoints?.chainId ?? getDirectNetworkChainId(network);\n const endpoints: DirectServiceEndpoints = {\n ...defaultEndpoints,\n ...config.endpoints,\n chainId,\n };\n\n const account = privateKeyToAccount(privateKey as Hex);\n const signMessage: Web3SignedSignFn = (message: string) =>\n account.signMessage({ message });\n // viem's account.signTypedData satisfies the structural SignTypedDataFn used\n // by the escrow GenericPayment signer.\n const signTypedData = account.signTypedData as unknown as SignTypedDataFn;\n const accessRequestClient: AccessRequestClient =\n config.accessRequestClient ??\n createDefaultAccessRequestClient({\n baseUrl: endpoints.accessRequestBaseUrl,\n approvalBaseUrl: endpoints.approvalAppBaseUrl,\n env,\n fetchFn: config.fetchFn,\n appAddress: account.address,\n signMessage,\n });\n\n // Build the escrow payment config, defaulting from the per-network endpoints\n // table and the contract registry when `config.escrow` is omitted or partial.\n const escrowChainId = config.escrow?.chainId ?? chainId;\n const defaultEscrowContract =\n CONTRACTS.DataPortabilityEscrow.addresses[\n escrowChainId as keyof typeof CONTRACTS.DataPortabilityEscrow.addresses\n ] ?? undefined;\n if (!config.escrow?.escrowContract && !defaultEscrowContract) {\n throw new DirectConfigError(\n `No DataPortabilityEscrow address found in the registry for chainId ${escrowChainId}. ` +\n `Provide an explicit escrow.escrowContract in the controller config.`,\n );\n }\n const escrow: EscrowPaymentConfig = {\n client:\n config.escrow?.client ??\n createEscrowGatewayClient(endpoints.escrowGatewayUrl),\n escrowContract:\n config.escrow?.escrowContract ?? (defaultEscrowContract as `0x${string}`),\n chainId: escrowChainId,\n nonceSource: config.escrow?.nonceSource,\n signTypedData,\n };\n\n return {\n appAddress: account.address,\n\n getAppAddress(): string {\n return account.address;\n },\n\n getAppIdentity(): AppIdentity {\n return {\n id: config.app.id,\n name: config.app.name,\n homepageUrl: config.app.homepageUrl,\n address: account.address,\n };\n },\n\n async createAccessRequest(input): Promise<AccessRequest> {\n return accessRequestClient.createAccessRequest({\n appAddress: account.address,\n app: config.app,\n source: config.source,\n scopes: config.scopes,\n returnUrl: input.returnUrl,\n network,\n ...(input.foregroundDelivery !== undefined\n ? { foregroundDelivery: input.foregroundDelivery }\n : {}),\n ...(input.idempotencyKey !== undefined\n ? { idempotencyKey: input.idempotencyKey }\n : {}),\n });\n },\n\n async getAccessRequestStatus(\n requestId: string,\n ): Promise<AccessRequestStatus> {\n return accessRequestClient.getAccessRequestStatus(requestId);\n },\n\n async readApprovedData<T = unknown>(input: {\n requestId: string;\n scope?: string;\n acknowledge?: boolean;\n }): Promise<ApprovedDataResult<T>> {\n const status = await requireReadReady(input.requestId);\n const scope = resolveRequestedScope(status, input.scope);\n\n const result = await readScope<T>(status, scope);\n if (input.acknowledge !== false) {\n await acknowledgeQuietly(input.requestId);\n }\n return result;\n },\n\n async readAllApprovedData<T = unknown>(input: {\n requestId: string;\n }): Promise<MultiScopeDataResult<T>> {\n const status = await requireReadReady(input.requestId);\n const scopes = approvedScopes(status);\n\n const results: Record<string, ApprovedDataResult<T>> = {};\n const errors: Record<string, Error> = {};\n // Sequential, not parallel: each read settles its own escrow payment and\n // the default nonce source is process-local, so concurrent reads would\n // race on the payment nonce.\n for (const scope of scopes) {\n try {\n results[scope] = await readScope<T>(status, scope);\n } catch (error) {\n errors[scope] =\n error instanceof Error ? error : new Error(String(error));\n }\n }\n\n // Acknowledge only after the last read, and only if every scope read —\n // acking moves the DCR to `completed`, which is terminal and no longer\n // read-ready, so acking on a partial failure would make the scope that\n // failed impossible to retry.\n if (Object.keys(errors).length === 0) {\n await acknowledgeQuietly(input.requestId);\n }\n\n return { results, errors };\n },\n };\n\n async function requireReadReady(\n requestId: string,\n ): Promise<AccessRequestStatus> {\n const status = await accessRequestClient.getAccessRequestStatus(requestId);\n // `scope` and `scopes` are both optional on the public status type, and a\n // client may return either one — require at least one approved scope rather\n // than the singular field specifically.\n if (\n !isReadReadyStatus(status.status) ||\n !status.personalServerUrl ||\n !status.grantId ||\n approvedScopes(status).length === 0\n ) {\n throw new AccessNotApprovedError(\n \"Request is not approved or is missing grantId/scope/personalServerUrl\",\n {\n requestId,\n status: status.status,\n hasPersonalServerUrl: Boolean(status.personalServerUrl),\n hasGrantId: Boolean(status.grantId),\n hasScope: approvedScopes(status).length > 0,\n },\n );\n }\n return status;\n }\n\n /** Approved scopes in approval order, falling back to the single `scope`. */\n function approvedScopes(status: AccessRequestStatus): string[] {\n if (status.scopes && status.scopes.length > 0) return status.scopes;\n return status.scope ? [status.scope] : [];\n }\n\n /**\n * Resolve which scope to read. Rejects an unapproved scope up front so it\n * never reaches the Personal Server and never settles a fee.\n */\n function resolveRequestedScope(\n status: AccessRequestStatus,\n requested?: string,\n ): string {\n const scopes = approvedScopes(status);\n if (requested === undefined) return scopes[0];\n if (!scopes.includes(requested)) {\n throw new ScopeNotApprovedError(\n `Scope \"${requested}\" is not approved on this request`,\n { requestedScope: requested, approvedScopes: scopes },\n );\n }\n return requested;\n }\n\n async function readScope<T>(\n status: AccessRequestStatus,\n scope: string,\n ): Promise<ApprovedDataResult<T>> {\n const result = await readPersonalServerData({\n personalServerUrl: status.personalServerUrl as string,\n scope,\n grantId: status.grantId as string,\n payerAddress: account.address,\n signMessage,\n escrow,\n fetchFn: config.personalServerFetch,\n transportRetry: config.personalServerTransportRetry,\n });\n return { scope, data: result.data as T, payment: result.payment };\n }\n\n async function acknowledgeQuietly(requestId: string): Promise<void> {\n try {\n await accessRequestClient.acknowledgeRead?.(requestId);\n } catch {\n // The read already succeeded; ack only drives Vana Web completion UX.\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBA,sBAAoC;AAGpC,oBAA2B;AAC3B,oBAA0C;AAC1C,uBAA0B;AAC1B,mCAGO;AACP,uBAIO;AACP,oBAIO;AAKP,kC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QACR,UAAU,SAAS;AAAA,QACnB,EAAE,gBAAgB,WAAW,gBAAgB,OAAO;AAAA,MACtD;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAEA,iBAAe,UACb,QACA,OACgC;AAChC,UAAM,SAAS,UAAM,oDAAuB;AAAA,MAC1C,mBAAmB,OAAO;AAAA,MAC1B;AAAA,MACA,SAAS,OAAO;AAAA,MAChB,cAAc,QAAQ;AAAA,MACtB;AAAA,MACA;AAAA,MACA,SAAS,OAAO;AAAA,MAChB,gBAAgB,OAAO;AAAA,IACzB,CAAC;AACD,WAAO,EAAE,OAAO,MAAM,OAAO,MAAW,SAAS,OAAO,QAAQ;AAAA,EAClE;AAEA,iBAAe,mBAAmB,WAAkC;AAClE,QAAI;AACF,YAAM,oBAAoB,kBAAkB,SAAS;AAAA,IACvD,QAAQ;AAAA,IAER;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/direct/controller.ts"],"sourcesContent":["/**\n * Direct Data Controller — the server-side facade for the two-tab Data\n * Portability flow.\n *\n * @remarks\n * One controller owns an app's private key, source, scopes, app identity, and\n * payment flow. It exposes the three methods the builder guide documents:\n *\n * - {@link DirectDataController.createAccessRequest} — start an approval request.\n * - {@link DirectDataController.getAccessRequestStatus} — poll while the Vana tab is open.\n * - {@link DirectDataController.readApprovedData} — read from the Personal Server,\n * handling 402 Payment Required.\n *\n * Access requests are created through the Vana Account access-request API; the\n * Personal Server read uses Web3Signed auth; and payment uses the DPv2 escrow\n * surface (`protocol/escrow`) — when a read returns `402`, the controller signs\n * a `GenericPayment` with the app key, settles it through the escrow gateway,\n * and retries.\n *\n * @category Direct\n * @module direct/controller\n */\n\nimport { privateKeyToAccount } from \"viem/accounts\";\nimport type { Hex } from \"viem\";\nimport type { Web3SignedSignFn } from \"../auth/web3-signed-builder\";\nimport { parseScope } from \"../protocol/scopes\";\nimport { parseScopeEntry } from \"../protocol/scope-actions\";\nimport { createEscrowGatewayClient } from \"../protocol/escrow\";\nimport { CONTRACTS } from \"../generated/addresses\";\nimport {\n createDefaultAccessRequestClient,\n type FetchLike,\n} from \"./access-request-client\";\nimport {\n getDirectDefaultNetwork,\n getDirectEndpoints,\n getDirectNetworkChainId,\n} from \"./endpoints\";\nimport {\n AccessNotApprovedError,\n DirectConfigError,\n ScopeNotApprovedError,\n} from \"./errors\";\nimport {\n type EscrowPaymentConfig,\n type SignTypedDataFn,\n} from \"./escrow-payment\";\nimport {\n readPersonalServerData,\n type PersonalServerFetch,\n type PersonalServerTransportRetryOptions,\n} from \"./personal-server-read\";\nimport type {\n AccessRequest,\n AccessRequestClient,\n AccessRequestStatus,\n AccessRequestStatusValue,\n ApprovedDataResult,\n AppIdentity,\n DirectAppConfig,\n DirectEnv,\n DirectNetwork,\n DirectPaymentResponseMetadata,\n DirectServiceEndpoints,\n ForegroundDelivery,\n MultiScopeDataResult,\n} from \"./types\";\n\n/** Configuration for {@link createDirectDataController}. */\nexport interface DirectDataControllerConfig {\n /** Target environment. Defaults to `\"production\"`. */\n env?: DirectEnv;\n /**\n * Target Vana network for chain-aware defaults. Defaults to the selected\n * environment's historical network (`mainnet` for production, `moksha` for\n * dev). Use `network: \"moksha\"` with the default production env for\n * production app/API URLs on testnet.\n */\n network?: DirectNetwork;\n /**\n * The app private key (`0x`-prefixed, 32 bytes). Server-side only — this key\n * is the app's on-chain identity and is never exposed to the browser.\n */\n appPrivateKey?: string;\n /**\n * @deprecated Use {@link DirectDataControllerConfig.appPrivateKey}. Accepted as\n * a backwards-compatible alias; if both are set, `appPrivateKey` wins.\n */\n builderPrivateKey?: string;\n /** App identity advertised during approval. */\n app: DirectAppConfig;\n /** Data source key (e.g. `\"icloud_notes\"`). */\n source: string;\n /**\n * Grant scope entries to request. At least one required.\n *\n * Each entry is `[operation:]scope` (see `parseScopeEntry`): a bare entry\n * such as `\"icloud_notes.notes\"` requests read, and `\"write:coach.weekly\"`\n * requests write. The entries are carried through to the access request\n * verbatim and become the grant's `scopes`, so a request can mix both\n * (`[\"oura.sleep\", \"coach.weekly\", \"write:coach.weekly\"]`).\n *\n * The scope part must be a concrete `{source}.{category}[.{subcategory}]`\n * scope: this flow reads approved scopes back one by one, so wildcard\n * patterns (`chatgpt.*`, `write:chatgpt.*`) are not accepted here for\n * either operation.\n */\n scopes: string[];\n /**\n * Override the resolved service endpoints (partial). Useful for pointing at a\n * non-standard deployment.\n */\n endpoints?: Partial<DirectServiceEndpoints>;\n /**\n * Client for the Vana Account access-request API. Defaults to a client against\n * the resolved Vana Account endpoints; inject your own to point at a custom\n * deployment or to supply a test double.\n */\n accessRequestClient?: AccessRequestClient;\n /**\n * Escrow settlement config used when a Personal Server read returns `402`.\n *\n * @remarks\n * Wires the DPv2 escrow gateway (`protocol/escrow`). The controller supplies\n * the EIP-712 `signTypedData` from the app key automatically.\n *\n * When omitted (or partially omitted), the SDK derives defaults from the\n * per-network endpoints table and the contract registry:\n * - `client` defaults to a gateway client at `endpoints.escrowGatewayUrl`\n * - `escrowContract` defaults to `CONTRACTS.DataPortabilityEscrow.addresses[chainId]`\n * - `chainId` defaults to the controller's resolved chain id\n *\n * Provide this field only to override a specific default.\n */\n escrow?: Partial<DirectEscrowConfig>;\n /** `fetch` used by the default access-request client. Defaults to `globalThis.fetch`. */\n fetchFn?: FetchLike;\n /** `fetch` used for the Personal Server read. Defaults to `globalThis.fetch`. */\n personalServerFetch?: PersonalServerFetch;\n /**\n * Transport-retry knobs for the Personal Server read\n * ({@link PersonalServerTransportRetryOptions}). Defaults to 3 attempts with\n * exponential backoff. Retries fire only when fetch throws (the browser-PS\n * relay reconnect window), never on a received HTTP status, and never\n * re-sign a payment.\n */\n personalServerTransportRetry?: PersonalServerTransportRetryOptions;\n}\n\n/**\n * Controller-level escrow config — the {@link EscrowPaymentConfig} minus the\n * `signTypedData` and `chainId` the controller injects itself.\n */\nexport interface DirectEscrowConfig extends Omit<\n EscrowPaymentConfig,\n \"signTypedData\" | \"chainId\"\n> {\n /**\n * Chain id for the EIP-712 domain. Defaults to the controller's environment\n * (1480 for mainnet, 14800 for moksha).\n */\n chainId?: number;\n}\n\n/**\n * Server-side controller for the direct Data Portability flow.\n *\n * @typeParam T - Shape of the data returned by {@link DirectDataController.readApprovedData}.\n */\nexport interface DirectDataController {\n /** The on-chain address of the app, derived from `appPrivateKey`. */\n readonly appAddress: string;\n\n /**\n * The app's on-chain address — the address to fund and inspect in the Builder\n * activity report. Equivalent to {@link DirectDataController.appAddress}.\n *\n * @returns The app's `0x`-prefixed address.\n */\n getAppAddress(): string;\n\n /**\n * The app's full identity: its configured id/name/homepage plus the derived\n * on-chain address. Useful for telling builders which app address to fund or\n * look up.\n *\n * @returns `{ id, name, homepageUrl, address }`.\n */\n getAppIdentity(): AppIdentity;\n\n /**\n * Create an access request the user can approve.\n *\n * @param input - The post-approval return URL and optional create retry key.\n * @returns The request id, HTTPS approval URL, and — for a pending deep Direct\n * request on mobile — an optional HTTPS `mobileContinuationUrl`.\n */\n createAccessRequest(input: {\n returnUrl: string;\n /** Optional foreground mobile delivery callback. */\n foregroundDelivery?: ForegroundDelivery;\n /**\n * Stable retry key when the caller retries after an uncertain response.\n * Each create without one gets its own generated key.\n */\n idempotencyKey?: string;\n }): Promise<AccessRequest>;\n\n /**\n * Fetch the current status of an access request.\n *\n * @param requestId - The `dcr_*` id from {@link DirectDataController.createAccessRequest}.\n * @returns `{ status, personalServerUrl?, grantId?, scope?, scopes? }`.\n */\n getAccessRequestStatus(requestId: string): Promise<AccessRequestStatus>;\n\n /**\n * Read the approved data from the user's Personal Server.\n *\n * @remarks\n * Resolves the request to its grant + Personal Server and performs a Web3Signed\n * read. Hides the `402 Payment Required` flow by default: if a read needs\n * payment, it signs the Personal Server's payment challenge, retries with\n * `X-PAYMENT`, and attaches shape-validated but unauthenticated\n * {@link DirectPaymentResponseMetadata} under `payment` when the Personal\n * Server returns it. After a successful read, the controller acknowledges\n * the DCR so Vana Web can close/redirect the approval tab.\n *\n * A request can approve several scopes. This reads **one** of them — `scope`\n * when given, otherwise the first approved scope. Use\n * {@link DirectDataController.readAllApprovedData} to read them all.\n *\n * Acknowledging moves the DCR to `completed`, which is terminal and no longer\n * read-ready. To read several scopes with your own loop, pass\n * `acknowledge: false` on every call but the last.\n *\n * @param input - The `dcr_*` request id, the optional `scope` to read, and an\n * optional `acknowledge` flag (default `true`).\n * @returns `{ scope, data, payment? }`.\n * @throws {@link AccessNotApprovedError} if the request is not approved.\n * @throws {@link ScopeNotApprovedError} if `scope` is not an approved scope.\n * @throws {@link PaymentRequiredError} if payment is required but unsettled.\n */\n readApprovedData<T = unknown>(input: {\n requestId: string;\n scope?: string;\n acknowledge?: boolean;\n }): Promise<ApprovedDataResult<T>>;\n\n /**\n * Read every scope the user approved on a request.\n *\n * @remarks\n * Reads the scopes in approval order, then acknowledges the DCR **once**,\n * after the last read — acknowledging earlier would move the request to\n * `completed` and make the remaining scopes unreadable.\n *\n * Each scope is a separate Personal Server read that settles its own\n * `data_access` fee from escrow, so reading N scopes costs N times a\n * single-scope read. The one-off registration fee is charged per grant, not\n * per scope.\n *\n * A scope that fails does not abort the rest: successes land in `results` and\n * failures in `errors`, because the fees for earlier scopes are already spent.\n * If any scope fails the request is left unacknowledged, so the scopes that\n * failed stay retryable — read them with `readApprovedData({ scope })` and\n * acknowledge on the last one.\n *\n * @param input - The `dcr_*` request id to read.\n * @returns `{ results, errors }`, both keyed by scope.\n * @throws {@link AccessNotApprovedError} if the request is not approved.\n */\n readAllApprovedData<T = unknown>(input: {\n requestId: string;\n }): Promise<MultiScopeDataResult<T>>;\n}\n\nfunction isHexPrivateKey(value: string): value is Hex {\n return /^0x[0-9a-fA-F]{64}$/.test(value);\n}\n\n// A DCR is read-ready only while the grant exists and the Personal Server is\n// still serving it: `approved` (durable PS) or `ready_for_read` (browser PS).\n// `completed` is terminal — the app already read and acknowledged, and the\n// browser PS may be gone — so it is deliberately excluded here.\nfunction isReadReadyStatus(status: AccessRequestStatusValue): boolean {\n return status === \"approved\" || status === \"ready_for_read\";\n}\n\n/**\n * Create a {@link DirectDataController}.\n *\n * @param config - Controller configuration (env, key, app identity, source, scopes).\n * @returns A ready-to-use controller.\n * @throws {@link DirectConfigError} when the key is missing or malformed, when\n * `scopes` is empty, or when no escrow contract can be resolved.\n * @throws InvalidScopeEntryError when a `scopes` entry does not fit the\n * `[operation:]scope` grammar (an unknown operation prefix such as `delete:`).\n * @throws ZodError when the scope part of an entry is not a valid scope.\n */\nexport function createDirectDataController(\n config: DirectDataControllerConfig,\n): DirectDataController {\n // `appPrivateKey` is the documented field; `builderPrivateKey` is a\n // deprecated alias kept for backwards compatibility.\n const privateKey = config.appPrivateKey ?? config.builderPrivateKey;\n if (!privateKey || !isHexPrivateKey(privateKey)) {\n throw new DirectConfigError(\n \"appPrivateKey must be a 0x-prefixed 32-byte hex string\",\n );\n }\n if (!config.scopes || config.scopes.length === 0) {\n throw new DirectConfigError(\"At least one scope is required\");\n }\n // Validate scopes eagerly so misconfiguration fails at construction. Each\n // element is a grant scope entry (`[operation:]scope`), so the operation\n // prefix is stripped first and only the scope part is checked against the\n // scope grammar — `write:coach.weekly` is a valid write-grant request, and\n // an unknown operation (`delete:x`) throws rather than being taken as read.\n // The entries themselves are passed through to the access request verbatim,\n // prefix included.\n for (const entry of config.scopes) {\n parseScope(parseScopeEntry(entry).scope);\n }\n\n const env: DirectEnv = config.env ?? \"production\";\n const network: DirectNetwork = config.network ?? getDirectDefaultNetwork(env);\n const defaultEndpoints = getDirectEndpoints(env);\n const chainId = config.endpoints?.chainId ?? getDirectNetworkChainId(network);\n const endpoints: DirectServiceEndpoints = {\n ...defaultEndpoints,\n ...config.endpoints,\n chainId,\n };\n\n const account = privateKeyToAccount(privateKey as Hex);\n const signMessage: Web3SignedSignFn = (message: string) =>\n account.signMessage({ message });\n // viem's account.signTypedData satisfies the structural SignTypedDataFn used\n // by the escrow GenericPayment signer.\n const signTypedData = account.signTypedData as unknown as SignTypedDataFn;\n const accessRequestClient: AccessRequestClient =\n config.accessRequestClient ??\n createDefaultAccessRequestClient({\n baseUrl: endpoints.accessRequestBaseUrl,\n approvalBaseUrl: endpoints.approvalAppBaseUrl,\n env,\n fetchFn: config.fetchFn,\n appAddress: account.address,\n signMessage,\n });\n\n // Build the escrow payment config, defaulting from the per-network endpoints\n // table and the contract registry when `config.escrow` is omitted or partial.\n const escrowChainId = config.escrow?.chainId ?? chainId;\n const defaultEscrowContract =\n CONTRACTS.DataPortabilityEscrow.addresses[\n escrowChainId as keyof typeof CONTRACTS.DataPortabilityEscrow.addresses\n ] ?? undefined;\n if (!config.escrow?.escrowContract && !defaultEscrowContract) {\n throw new DirectConfigError(\n `No DataPortabilityEscrow address found in the registry for chainId ${escrowChainId}. ` +\n `Provide an explicit escrow.escrowContract in the controller config.`,\n );\n }\n const escrow: EscrowPaymentConfig = {\n client:\n config.escrow?.client ??\n createEscrowGatewayClient(endpoints.escrowGatewayUrl),\n escrowContract:\n config.escrow?.escrowContract ?? (defaultEscrowContract as `0x${string}`),\n chainId: escrowChainId,\n nonceSource: config.escrow?.nonceSource,\n signTypedData,\n };\n\n return {\n appAddress: account.address,\n\n getAppAddress(): string {\n return account.address;\n },\n\n getAppIdentity(): AppIdentity {\n return {\n id: config.app.id,\n name: config.app.name,\n homepageUrl: config.app.homepageUrl,\n address: account.address,\n };\n },\n\n async createAccessRequest(input): Promise<AccessRequest> {\n return accessRequestClient.createAccessRequest({\n appAddress: account.address,\n app: config.app,\n source: config.source,\n scopes: config.scopes,\n returnUrl: input.returnUrl,\n network,\n ...(input.foregroundDelivery !== undefined\n ? { foregroundDelivery: input.foregroundDelivery }\n : {}),\n ...(input.idempotencyKey !== undefined\n ? { idempotencyKey: input.idempotencyKey }\n : {}),\n });\n },\n\n async getAccessRequestStatus(\n requestId: string,\n ): Promise<AccessRequestStatus> {\n return accessRequestClient.getAccessRequestStatus(requestId);\n },\n\n async readApprovedData<T = unknown>(input: {\n requestId: string;\n scope?: string;\n acknowledge?: boolean;\n }): Promise<ApprovedDataResult<T>> {\n const status = await requireReadReady(input.requestId);\n const scope = resolveRequestedScope(status, input.scope);\n\n const result = await readScope<T>(status, scope);\n if (input.acknowledge !== false) {\n await acknowledgeQuietly(input.requestId);\n }\n return result;\n },\n\n async readAllApprovedData<T = unknown>(input: {\n requestId: string;\n }): Promise<MultiScopeDataResult<T>> {\n const status = await requireReadReady(input.requestId);\n const scopes = approvedScopes(status);\n\n const results: Record<string, ApprovedDataResult<T>> = {};\n const errors: Record<string, Error> = {};\n // Sequential, not parallel: each read settles its own escrow payment and\n // the default nonce source is process-local, so concurrent reads would\n // race on the payment nonce.\n for (const scope of scopes) {\n try {\n results[scope] = await readScope<T>(status, scope);\n } catch (error) {\n errors[scope] =\n error instanceof Error ? error : new Error(String(error));\n }\n }\n\n // Acknowledge only after the last read, and only if every scope read —\n // acking moves the DCR to `completed`, which is terminal and no longer\n // read-ready, so acking on a partial failure would make the scope that\n // failed impossible to retry.\n if (Object.keys(errors).length === 0) {\n await acknowledgeQuietly(input.requestId);\n }\n\n return { results, errors };\n },\n };\n\n async function requireReadReady(\n requestId: string,\n ): Promise<AccessRequestStatus> {\n const status = await accessRequestClient.getAccessRequestStatus(requestId);\n // `scope` and `scopes` are both optional on the public status type, and a\n // client may return either one — require at least one approved scope rather\n // than the singular field specifically.\n if (\n !isReadReadyStatus(status.status) ||\n !status.personalServerUrl ||\n !status.grantId ||\n approvedScopes(status).length === 0\n ) {\n throw new AccessNotApprovedError(\n \"Request is not approved or is missing grantId/scope/personalServerUrl\",\n {\n requestId,\n status: status.status,\n hasPersonalServerUrl: Boolean(status.personalServerUrl),\n hasGrantId: Boolean(status.grantId),\n hasScope: approvedScopes(status).length > 0,\n },\n );\n }\n return status;\n }\n\n /** Approved scopes in approval order, falling back to the single `scope`. */\n function approvedScopes(status: AccessRequestStatus): string[] {\n if (status.scopes && status.scopes.length > 0) return status.scopes;\n return status.scope ? [status.scope] : [];\n }\n\n /**\n * Resolve which scope to read. Rejects an unapproved scope up front so it\n * never reaches the Personal Server and never settles a fee.\n */\n function resolveRequestedScope(\n status: AccessRequestStatus,\n requested?: string,\n ): string {\n const scopes = approvedScopes(status);\n if (requested === undefined) return scopes[0];\n if (!scopes.includes(requested)) {\n throw new ScopeNotApprovedError(\n `Scope \"${requested}\" is not approved on this request`,\n { requestedScope: requested, approvedScopes: scopes },\n );\n }\n return requested;\n }\n\n async function readScope<T>(\n status: AccessRequestStatus,\n scope: string,\n ): Promise<ApprovedDataResult<T>> {\n const result = await readPersonalServerData({\n personalServerUrl: status.personalServerUrl as string,\n scope,\n grantId: status.grantId as string,\n payerAddress: account.address,\n signMessage,\n escrow,\n fetchFn: config.personalServerFetch,\n transportRetry: config.personalServerTransportRetry,\n });\n return { scope, data: result.data as T, payment: result.payment };\n }\n\n async function acknowledgeQuietly(requestId: string): Promise<void> {\n try {\n await accessRequestClient.acknowledgeRead?.(requestId);\n } catch {\n // The read already succeeded; ack only drives Vana Web completion UX.\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBA,sBAAoC;AAGpC,oBAA2B;AAC3B,2BAAgC;AAChC,oBAA0C;AAC1C,uBAA0B;AAC1B,mCAGO;AACP,uBAIO;AACP,oBAIO;AAKP,kCAIO;AAkOP,SAAS,gBAAgB,OAA6B;AACpD,SAAO,sBAAsB,KAAK,KAAK;AACzC;AAMA,SAAS,kBAAkB,QAA2C;AACpE,SAAO,WAAW,cAAc,WAAW;AAC7C;AAaO,SAAS,2BACd,QACsB;AAGtB,QAAM,aAAa,OAAO,iBAAiB,OAAO;AAClD,MAAI,CAAC,cAAc,CAAC,gBAAgB,UAAU,GAAG;AAC/C,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,MAAI,CAAC,OAAO,UAAU,OAAO,OAAO,WAAW,GAAG;AAChD,UAAM,IAAI,gCAAkB,gCAAgC;AAAA,EAC9D;AAQA,aAAW,SAAS,OAAO,QAAQ;AACjC,sCAAW,sCAAgB,KAAK,EAAE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kC;AAClE,QAAI;AACF,YAAM,oBAAoB,kBAAkB,SAAS;AAAA,IACvD,QAAQ;AAAA,IAER;AAAA,EACF;AACF;","names":[]}
|
|
@@ -49,7 +49,20 @@ export interface DirectDataControllerConfig {
|
|
|
49
49
|
app: DirectAppConfig;
|
|
50
50
|
/** Data source key (e.g. `"icloud_notes"`). */
|
|
51
51
|
source: string;
|
|
52
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Grant scope entries to request. At least one required.
|
|
54
|
+
*
|
|
55
|
+
* Each entry is `[operation:]scope` (see `parseScopeEntry`): a bare entry
|
|
56
|
+
* such as `"icloud_notes.notes"` requests read, and `"write:coach.weekly"`
|
|
57
|
+
* requests write. The entries are carried through to the access request
|
|
58
|
+
* verbatim and become the grant's `scopes`, so a request can mix both
|
|
59
|
+
* (`["oura.sleep", "coach.weekly", "write:coach.weekly"]`).
|
|
60
|
+
*
|
|
61
|
+
* The scope part must be a concrete `{source}.{category}[.{subcategory}]`
|
|
62
|
+
* scope: this flow reads approved scopes back one by one, so wildcard
|
|
63
|
+
* patterns (`chatgpt.*`, `write:chatgpt.*`) are not accepted here for
|
|
64
|
+
* either operation.
|
|
65
|
+
*/
|
|
53
66
|
scopes: string[];
|
|
54
67
|
/**
|
|
55
68
|
* Override the resolved service endpoints (partial). Useful for pointing at a
|
|
@@ -213,6 +226,10 @@ export interface DirectDataController {
|
|
|
213
226
|
*
|
|
214
227
|
* @param config - Controller configuration (env, key, app identity, source, scopes).
|
|
215
228
|
* @returns A ready-to-use controller.
|
|
216
|
-
* @throws {@link DirectConfigError} when the key or
|
|
229
|
+
* @throws {@link DirectConfigError} when the key is missing or malformed, when
|
|
230
|
+
* `scopes` is empty, or when no escrow contract can be resolved.
|
|
231
|
+
* @throws InvalidScopeEntryError when a `scopes` entry does not fit the
|
|
232
|
+
* `[operation:]scope` grammar (an unknown operation prefix such as `delete:`).
|
|
233
|
+
* @throws ZodError when the scope part of an entry is not a valid scope.
|
|
217
234
|
*/
|
|
218
235
|
export declare function createDirectDataController(config: DirectDataControllerConfig): DirectDataController;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { privateKeyToAccount } from "viem/accounts";
|
|
2
2
|
import { parseScope } from "../protocol/scopes.js";
|
|
3
|
+
import { parseScopeEntry } from "../protocol/scope-actions.js";
|
|
3
4
|
import { createEscrowGatewayClient } from "../protocol/escrow.js";
|
|
4
5
|
import { CONTRACTS } from "../generated/addresses.js";
|
|
5
6
|
import {
|
|
@@ -34,8 +35,8 @@ function createDirectDataController(config) {
|
|
|
34
35
|
if (!config.scopes || config.scopes.length === 0) {
|
|
35
36
|
throw new DirectConfigError("At least one scope is required");
|
|
36
37
|
}
|
|
37
|
-
for (const
|
|
38
|
-
parseScope(scope);
|
|
38
|
+
for (const entry of config.scopes) {
|
|
39
|
+
parseScope(parseScopeEntry(entry).scope);
|
|
39
40
|
}
|
|
40
41
|
const env = config.env ?? "production";
|
|
41
42
|
const network = config.network ?? getDirectDefaultNetwork(env);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/direct/controller.ts"],"sourcesContent":["/**\n * Direct Data Controller — the server-side facade for the two-tab Data\n * Portability flow.\n *\n * @remarks\n * One controller owns an app's private key, source, scopes, app identity, and\n * payment flow. It exposes the three methods the builder guide documents:\n *\n * - {@link DirectDataController.createAccessRequest} — start an approval request.\n * - {@link DirectDataController.getAccessRequestStatus} — poll while the Vana tab is open.\n * - {@link DirectDataController.readApprovedData} — read from the Personal Server,\n * handling 402 Payment Required.\n *\n * Access requests are created through the Vana Account access-request API; the\n * Personal Server read uses Web3Signed auth; and payment uses the DPv2 escrow\n * surface (`protocol/escrow`) — when a read returns `402`, the controller signs\n * a `GenericPayment` with the app key, settles it through the escrow gateway,\n * and retries.\n *\n * @category Direct\n * @module direct/controller\n */\n\nimport { privateKeyToAccount } from \"viem/accounts\";\nimport type { Hex } from \"viem\";\nimport type { Web3SignedSignFn } from \"../auth/web3-signed-builder\";\nimport { parseScope } from \"../protocol/scopes\";\nimport { createEscrowGatewayClient } from \"../protocol/escrow\";\nimport { CONTRACTS } from \"../generated/addresses\";\nimport {\n createDefaultAccessRequestClient,\n type FetchLike,\n} from \"./access-request-client\";\nimport {\n getDirectDefaultNetwork,\n getDirectEndpoints,\n getDirectNetworkChainId,\n} from \"./endpoints\";\nimport {\n AccessNotApprovedError,\n DirectConfigError,\n ScopeNotApprovedError,\n} from \"./errors\";\nimport {\n type EscrowPaymentConfig,\n type SignTypedDataFn,\n} from \"./escrow-payment\";\nimport {\n readPersonalServerData,\n type PersonalServerFetch,\n type PersonalServerTransportRetryOptions,\n} from \"./personal-server-read\";\nimport type {\n AccessRequest,\n AccessRequestClient,\n AccessRequestStatus,\n AccessRequestStatusValue,\n ApprovedDataResult,\n AppIdentity,\n DirectAppConfig,\n DirectEnv,\n DirectNetwork,\n DirectPaymentResponseMetadata,\n DirectServiceEndpoints,\n ForegroundDelivery,\n MultiScopeDataResult,\n} from \"./types\";\n\n/** Configuration for {@link createDirectDataController}. */\nexport interface DirectDataControllerConfig {\n /** Target environment. Defaults to `\"production\"`. */\n env?: DirectEnv;\n /**\n * Target Vana network for chain-aware defaults. Defaults to the selected\n * environment's historical network (`mainnet` for production, `moksha` for\n * dev). Use `network: \"moksha\"` with the default production env for\n * production app/API URLs on testnet.\n */\n network?: DirectNetwork;\n /**\n * The app private key (`0x`-prefixed, 32 bytes). Server-side only — this key\n * is the app's on-chain identity and is never exposed to the browser.\n */\n appPrivateKey?: string;\n /**\n * @deprecated Use {@link DirectDataControllerConfig.appPrivateKey}. Accepted as\n * a backwards-compatible alias; if both are set, `appPrivateKey` wins.\n */\n builderPrivateKey?: string;\n /** App identity advertised during approval. */\n app: DirectAppConfig;\n /** Data source key (e.g. `\"icloud_notes\"`). */\n source: string;\n /** Scopes to request (e.g. `[\"icloud_notes.notes\"]`). At least one required. */\n scopes: string[];\n /**\n * Override the resolved service endpoints (partial). Useful for pointing at a\n * non-standard deployment.\n */\n endpoints?: Partial<DirectServiceEndpoints>;\n /**\n * Client for the Vana Account access-request API. Defaults to a client against\n * the resolved Vana Account endpoints; inject your own to point at a custom\n * deployment or to supply a test double.\n */\n accessRequestClient?: AccessRequestClient;\n /**\n * Escrow settlement config used when a Personal Server read returns `402`.\n *\n * @remarks\n * Wires the DPv2 escrow gateway (`protocol/escrow`). The controller supplies\n * the EIP-712 `signTypedData` from the app key automatically.\n *\n * When omitted (or partially omitted), the SDK derives defaults from the\n * per-network endpoints table and the contract registry:\n * - `client` defaults to a gateway client at `endpoints.escrowGatewayUrl`\n * - `escrowContract` defaults to `CONTRACTS.DataPortabilityEscrow.addresses[chainId]`\n * - `chainId` defaults to the controller's resolved chain id\n *\n * Provide this field only to override a specific default.\n */\n escrow?: Partial<DirectEscrowConfig>;\n /** `fetch` used by the default access-request client. Defaults to `globalThis.fetch`. */\n fetchFn?: FetchLike;\n /** `fetch` used for the Personal Server read. Defaults to `globalThis.fetch`. */\n personalServerFetch?: PersonalServerFetch;\n /**\n * Transport-retry knobs for the Personal Server read\n * ({@link PersonalServerTransportRetryOptions}). Defaults to 3 attempts with\n * exponential backoff. Retries fire only when fetch throws (the browser-PS\n * relay reconnect window), never on a received HTTP status, and never\n * re-sign a payment.\n */\n personalServerTransportRetry?: PersonalServerTransportRetryOptions;\n}\n\n/**\n * Controller-level escrow config — the {@link EscrowPaymentConfig} minus the\n * `signTypedData` and `chainId` the controller injects itself.\n */\nexport interface DirectEscrowConfig extends Omit<\n EscrowPaymentConfig,\n \"signTypedData\" | \"chainId\"\n> {\n /**\n * Chain id for the EIP-712 domain. Defaults to the controller's environment\n * (1480 for mainnet, 14800 for moksha).\n */\n chainId?: number;\n}\n\n/**\n * Server-side controller for the direct Data Portability flow.\n *\n * @typeParam T - Shape of the data returned by {@link DirectDataController.readApprovedData}.\n */\nexport interface DirectDataController {\n /** The on-chain address of the app, derived from `appPrivateKey`. */\n readonly appAddress: string;\n\n /**\n * The app's on-chain address — the address to fund and inspect in the Builder\n * activity report. Equivalent to {@link DirectDataController.appAddress}.\n *\n * @returns The app's `0x`-prefixed address.\n */\n getAppAddress(): string;\n\n /**\n * The app's full identity: its configured id/name/homepage plus the derived\n * on-chain address. Useful for telling builders which app address to fund or\n * look up.\n *\n * @returns `{ id, name, homepageUrl, address }`.\n */\n getAppIdentity(): AppIdentity;\n\n /**\n * Create an access request the user can approve.\n *\n * @param input - The post-approval return URL and optional create retry key.\n * @returns The request id, HTTPS approval URL, and — for a pending deep Direct\n * request on mobile — an optional HTTPS `mobileContinuationUrl`.\n */\n createAccessRequest(input: {\n returnUrl: string;\n /** Optional foreground mobile delivery callback. */\n foregroundDelivery?: ForegroundDelivery;\n /**\n * Stable retry key when the caller retries after an uncertain response.\n * Each create without one gets its own generated key.\n */\n idempotencyKey?: string;\n }): Promise<AccessRequest>;\n\n /**\n * Fetch the current status of an access request.\n *\n * @param requestId - The `dcr_*` id from {@link DirectDataController.createAccessRequest}.\n * @returns `{ status, personalServerUrl?, grantId?, scope?, scopes? }`.\n */\n getAccessRequestStatus(requestId: string): Promise<AccessRequestStatus>;\n\n /**\n * Read the approved data from the user's Personal Server.\n *\n * @remarks\n * Resolves the request to its grant + Personal Server and performs a Web3Signed\n * read. Hides the `402 Payment Required` flow by default: if a read needs\n * payment, it signs the Personal Server's payment challenge, retries with\n * `X-PAYMENT`, and attaches shape-validated but unauthenticated\n * {@link DirectPaymentResponseMetadata} under `payment` when the Personal\n * Server returns it. After a successful read, the controller acknowledges\n * the DCR so Vana Web can close/redirect the approval tab.\n *\n * A request can approve several scopes. This reads **one** of them — `scope`\n * when given, otherwise the first approved scope. Use\n * {@link DirectDataController.readAllApprovedData} to read them all.\n *\n * Acknowledging moves the DCR to `completed`, which is terminal and no longer\n * read-ready. To read several scopes with your own loop, pass\n * `acknowledge: false` on every call but the last.\n *\n * @param input - The `dcr_*` request id, the optional `scope` to read, and an\n * optional `acknowledge` flag (default `true`).\n * @returns `{ scope, data, payment? }`.\n * @throws {@link AccessNotApprovedError} if the request is not approved.\n * @throws {@link ScopeNotApprovedError} if `scope` is not an approved scope.\n * @throws {@link PaymentRequiredError} if payment is required but unsettled.\n */\n readApprovedData<T = unknown>(input: {\n requestId: string;\n scope?: string;\n acknowledge?: boolean;\n }): Promise<ApprovedDataResult<T>>;\n\n /**\n * Read every scope the user approved on a request.\n *\n * @remarks\n * Reads the scopes in approval order, then acknowledges the DCR **once**,\n * after the last read — acknowledging earlier would move the request to\n * `completed` and make the remaining scopes unreadable.\n *\n * Each scope is a separate Personal Server read that settles its own\n * `data_access` fee from escrow, so reading N scopes costs N times a\n * single-scope read. The one-off registration fee is charged per grant, not\n * per scope.\n *\n * A scope that fails does not abort the rest: successes land in `results` and\n * failures in `errors`, because the fees for earlier scopes are already spent.\n * If any scope fails the request is left unacknowledged, so the scopes that\n * failed stay retryable — read them with `readApprovedData({ scope })` and\n * acknowledge on the last one.\n *\n * @param input - The `dcr_*` request id to read.\n * @returns `{ results, errors }`, both keyed by scope.\n * @throws {@link AccessNotApprovedError} if the request is not approved.\n */\n readAllApprovedData<T = unknown>(input: {\n requestId: string;\n }): Promise<MultiScopeDataResult<T>>;\n}\n\nfunction isHexPrivateKey(value: string): value is Hex {\n return /^0x[0-9a-fA-F]{64}$/.test(value);\n}\n\n// A DCR is read-ready only while the grant exists and the Personal Server is\n// still serving it: `approved` (durable PS) or `ready_for_read` (browser PS).\n// `completed` is terminal — the app already read and acknowledged, and the\n// browser PS may be gone — so it is deliberately excluded here.\nfunction isReadReadyStatus(status: AccessRequestStatusValue): boolean {\n return status === \"approved\" || status === \"ready_for_read\";\n}\n\n/**\n * Create a {@link DirectDataController}.\n *\n * @param config - Controller configuration (env, key, app identity, source, scopes).\n * @returns A ready-to-use controller.\n * @throws {@link DirectConfigError} when the key or scopes are invalid.\n */\nexport function createDirectDataController(\n config: DirectDataControllerConfig,\n): DirectDataController {\n // `appPrivateKey` is the documented field; `builderPrivateKey` is a\n // deprecated alias kept for backwards compatibility.\n const privateKey = config.appPrivateKey ?? config.builderPrivateKey;\n if (!privateKey || !isHexPrivateKey(privateKey)) {\n throw new DirectConfigError(\n \"appPrivateKey must be a 0x-prefixed 32-byte hex string\",\n );\n }\n if (!config.scopes || config.scopes.length === 0) {\n throw new DirectConfigError(\"At least one scope is required\");\n }\n // Validate scopes eagerly so misconfiguration fails at construction.\n for (const scope of config.scopes) {\n parseScope(scope);\n }\n\n const env: DirectEnv = config.env ?? \"production\";\n const network: DirectNetwork = config.network ?? getDirectDefaultNetwork(env);\n const defaultEndpoints = getDirectEndpoints(env);\n const chainId = config.endpoints?.chainId ?? getDirectNetworkChainId(network);\n const endpoints: DirectServiceEndpoints = {\n ...defaultEndpoints,\n ...config.endpoints,\n chainId,\n };\n\n const account = privateKeyToAccount(privateKey as Hex);\n const signMessage: Web3SignedSignFn = (message: string) =>\n account.signMessage({ message });\n // viem's account.signTypedData satisfies the structural SignTypedDataFn used\n // by the escrow GenericPayment signer.\n const signTypedData = account.signTypedData as unknown as SignTypedDataFn;\n const accessRequestClient: AccessRequestClient =\n config.accessRequestClient ??\n createDefaultAccessRequestClient({\n baseUrl: endpoints.accessRequestBaseUrl,\n approvalBaseUrl: endpoints.approvalAppBaseUrl,\n env,\n fetchFn: config.fetchFn,\n appAddress: account.address,\n signMessage,\n });\n\n // Build the escrow payment config, defaulting from the per-network endpoints\n // table and the contract registry when `config.escrow` is omitted or partial.\n const escrowChainId = config.escrow?.chainId ?? chainId;\n const defaultEscrowContract =\n CONTRACTS.DataPortabilityEscrow.addresses[\n escrowChainId as keyof typeof CONTRACTS.DataPortabilityEscrow.addresses\n ] ?? undefined;\n if (!config.escrow?.escrowContract && !defaultEscrowContract) {\n throw new DirectConfigError(\n `No DataPortabilityEscrow address found in the registry for chainId ${escrowChainId}. ` +\n `Provide an explicit escrow.escrowContract in the controller config.`,\n );\n }\n const escrow: EscrowPaymentConfig = {\n client:\n config.escrow?.client ??\n createEscrowGatewayClient(endpoints.escrowGatewayUrl),\n escrowContract:\n config.escrow?.escrowContract ?? (defaultEscrowContract as `0x${string}`),\n chainId: escrowChainId,\n nonceSource: config.escrow?.nonceSource,\n signTypedData,\n };\n\n return {\n appAddress: account.address,\n\n getAppAddress(): string {\n return account.address;\n },\n\n getAppIdentity(): AppIdentity {\n return {\n id: config.app.id,\n name: config.app.name,\n homepageUrl: config.app.homepageUrl,\n address: account.address,\n };\n },\n\n async createAccessRequest(input): Promise<AccessRequest> {\n return accessRequestClient.createAccessRequest({\n appAddress: account.address,\n app: config.app,\n source: config.source,\n scopes: config.scopes,\n returnUrl: input.returnUrl,\n network,\n ...(input.foregroundDelivery !== undefined\n ? { foregroundDelivery: input.foregroundDelivery }\n : {}),\n ...(input.idempotencyKey !== undefined\n ? { idempotencyKey: input.idempotencyKey }\n : {}),\n });\n },\n\n async getAccessRequestStatus(\n requestId: string,\n ): Promise<AccessRequestStatus> {\n return accessRequestClient.getAccessRequestStatus(requestId);\n },\n\n async readApprovedData<T = unknown>(input: {\n requestId: string;\n scope?: string;\n acknowledge?: boolean;\n }): Promise<ApprovedDataResult<T>> {\n const status = await requireReadReady(input.requestId);\n const scope = resolveRequestedScope(status, input.scope);\n\n const result = await readScope<T>(status, scope);\n if (input.acknowledge !== false) {\n await acknowledgeQuietly(input.requestId);\n }\n return result;\n },\n\n async readAllApprovedData<T = unknown>(input: {\n requestId: string;\n }): Promise<MultiScopeDataResult<T>> {\n const status = await requireReadReady(input.requestId);\n const scopes = approvedScopes(status);\n\n const results: Record<string, ApprovedDataResult<T>> = {};\n const errors: Record<string, Error> = {};\n // Sequential, not parallel: each read settles its own escrow payment and\n // the default nonce source is process-local, so concurrent reads would\n // race on the payment nonce.\n for (const scope of scopes) {\n try {\n results[scope] = await readScope<T>(status, scope);\n } catch (error) {\n errors[scope] =\n error instanceof Error ? error : new Error(String(error));\n }\n }\n\n // Acknowledge only after the last read, and only if every scope read —\n // acking moves the DCR to `completed`, which is terminal and no longer\n // read-ready, so acking on a partial failure would make the scope that\n // failed impossible to retry.\n if (Object.keys(errors).length === 0) {\n await acknowledgeQuietly(input.requestId);\n }\n\n return { results, errors };\n },\n };\n\n async function requireReadReady(\n requestId: string,\n ): Promise<AccessRequestStatus> {\n const status = await accessRequestClient.getAccessRequestStatus(requestId);\n // `scope` and `scopes` are both optional on the public status type, and a\n // client may return either one — require at least one approved scope rather\n // than the singular field specifically.\n if (\n !isReadReadyStatus(status.status) ||\n !status.personalServerUrl ||\n !status.grantId ||\n approvedScopes(status).length === 0\n ) {\n throw new AccessNotApprovedError(\n \"Request is not approved or is missing grantId/scope/personalServerUrl\",\n {\n requestId,\n status: status.status,\n hasPersonalServerUrl: Boolean(status.personalServerUrl),\n hasGrantId: Boolean(status.grantId),\n hasScope: approvedScopes(status).length > 0,\n },\n );\n }\n return status;\n }\n\n /** Approved scopes in approval order, falling back to the single `scope`. */\n function approvedScopes(status: AccessRequestStatus): string[] {\n if (status.scopes && status.scopes.length > 0) return status.scopes;\n return status.scope ? [status.scope] : [];\n }\n\n /**\n * Resolve which scope to read. Rejects an unapproved scope up front so it\n * never reaches the Personal Server and never settles a fee.\n */\n function resolveRequestedScope(\n status: AccessRequestStatus,\n requested?: string,\n ): string {\n const scopes = approvedScopes(status);\n if (requested === undefined) return scopes[0];\n if (!scopes.includes(requested)) {\n throw new ScopeNotApprovedError(\n `Scope \"${requested}\" is not approved on this request`,\n { requestedScope: requested, approvedScopes: scopes },\n );\n }\n return requested;\n }\n\n async function readScope<T>(\n status: AccessRequestStatus,\n scope: string,\n ): Promise<ApprovedDataResult<T>> {\n const result = await readPersonalServerData({\n personalServerUrl: status.personalServerUrl as string,\n scope,\n grantId: status.grantId as string,\n payerAddress: account.address,\n signMessage,\n escrow,\n fetchFn: config.personalServerFetch,\n transportRetry: config.personalServerTransportRetry,\n });\n return { scope, data: result.data as T, payment: result.payment };\n }\n\n async function acknowledgeQuietly(requestId: string): Promise<void> {\n try {\n await accessRequestClient.acknowledgeRead?.(requestId);\n } catch {\n // The read already succeeded; ack only drives Vana Web completion UX.\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EAAG,QAAO,OAAO;AAC7D,WAAO,OAAO,QAAQ,CAAC,OAAO,KAAK,IAAI,CAAC;AAAA,EAC1C;AAMA,WAAS,sBACP,QACA,WACQ;AACR,UAAM,SAAS,eAAe,MAAM;AACpC,QAAI,cAAc,OAAW,QAAO,OAAO,CAAC;AAC5C,QAAI,CAAC,OAAO,SAAS,SAAS,GAAG;AAC/B,YAAM,IAAI;AAAA,QACR,UAAU,SAAS;AAAA,QACnB,EAAE,gBAAgB,WAAW,gBAAgB,OAAO;AAAA,MACtD;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAEA,iBAAe,UACb,QACA,OACgC;AAChC,UAAM,SAAS,MAAM,uBAAuB;AAAA,MAC1C,mBAAmB,OAAO;AAAA,MAC1B;AAAA,MACA,SAAS,OAAO;AAAA,MAChB,cAAc,QAAQ;AAAA,MACtB;AAAA,MACA;AAAA,MACA,SAAS,OAAO;AAAA,MAChB,gBAAgB,OAAO;AAAA,IACzB,CAAC;AACD,WAAO,EAAE,OAAO,MAAM,OAAO,MAAW,SAAS,OAAO,QAAQ;AAAA,EAClE;AAEA,iBAAe,mBAAmB,WAAkC;AAClE,QAAI;AACF,YAAM,oBAAoB,kBAAkB,SAAS;AAAA,IACvD,QAAQ;AAAA,IAER;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/direct/controller.ts"],"sourcesContent":["/**\n * Direct Data Controller — the server-side facade for the two-tab Data\n * Portability flow.\n *\n * @remarks\n * One controller owns an app's private key, source, scopes, app identity, and\n * payment flow. It exposes the three methods the builder guide documents:\n *\n * - {@link DirectDataController.createAccessRequest} — start an approval request.\n * - {@link DirectDataController.getAccessRequestStatus} — poll while the Vana tab is open.\n * - {@link DirectDataController.readApprovedData} — read from the Personal Server,\n * handling 402 Payment Required.\n *\n * Access requests are created through the Vana Account access-request API; the\n * Personal Server read uses Web3Signed auth; and payment uses the DPv2 escrow\n * surface (`protocol/escrow`) — when a read returns `402`, the controller signs\n * a `GenericPayment` with the app key, settles it through the escrow gateway,\n * and retries.\n *\n * @category Direct\n * @module direct/controller\n */\n\nimport { privateKeyToAccount } from \"viem/accounts\";\nimport type { Hex } from \"viem\";\nimport type { Web3SignedSignFn } from \"../auth/web3-signed-builder\";\nimport { parseScope } from \"../protocol/scopes\";\nimport { parseScopeEntry } from \"../protocol/scope-actions\";\nimport { createEscrowGatewayClient } from \"../protocol/escrow\";\nimport { CONTRACTS } from \"../generated/addresses\";\nimport {\n createDefaultAccessRequestClient,\n type FetchLike,\n} from \"./access-request-client\";\nimport {\n getDirectDefaultNetwork,\n getDirectEndpoints,\n getDirectNetworkChainId,\n} from \"./endpoints\";\nimport {\n AccessNotApprovedError,\n DirectConfigError,\n ScopeNotApprovedError,\n} from \"./errors\";\nimport {\n type EscrowPaymentConfig,\n type SignTypedDataFn,\n} from \"./escrow-payment\";\nimport {\n readPersonalServerData,\n type PersonalServerFetch,\n type PersonalServerTransportRetryOptions,\n} from \"./personal-server-read\";\nimport type {\n AccessRequest,\n AccessRequestClient,\n AccessRequestStatus,\n AccessRequestStatusValue,\n ApprovedDataResult,\n AppIdentity,\n DirectAppConfig,\n DirectEnv,\n DirectNetwork,\n DirectPaymentResponseMetadata,\n DirectServiceEndpoints,\n ForegroundDelivery,\n MultiScopeDataResult,\n} from \"./types\";\n\n/** Configuration for {@link createDirectDataController}. */\nexport interface DirectDataControllerConfig {\n /** Target environment. Defaults to `\"production\"`. */\n env?: DirectEnv;\n /**\n * Target Vana network for chain-aware defaults. Defaults to the selected\n * environment's historical network (`mainnet` for production, `moksha` for\n * dev). Use `network: \"moksha\"` with the default production env for\n * production app/API URLs on testnet.\n */\n network?: DirectNetwork;\n /**\n * The app private key (`0x`-prefixed, 32 bytes). Server-side only — this key\n * is the app's on-chain identity and is never exposed to the browser.\n */\n appPrivateKey?: string;\n /**\n * @deprecated Use {@link DirectDataControllerConfig.appPrivateKey}. Accepted as\n * a backwards-compatible alias; if both are set, `appPrivateKey` wins.\n */\n builderPrivateKey?: string;\n /** App identity advertised during approval. */\n app: DirectAppConfig;\n /** Data source key (e.g. `\"icloud_notes\"`). */\n source: string;\n /**\n * Grant scope entries to request. At least one required.\n *\n * Each entry is `[operation:]scope` (see `parseScopeEntry`): a bare entry\n * such as `\"icloud_notes.notes\"` requests read, and `\"write:coach.weekly\"`\n * requests write. The entries are carried through to the access request\n * verbatim and become the grant's `scopes`, so a request can mix both\n * (`[\"oura.sleep\", \"coach.weekly\", \"write:coach.weekly\"]`).\n *\n * The scope part must be a concrete `{source}.{category}[.{subcategory}]`\n * scope: this flow reads approved scopes back one by one, so wildcard\n * patterns (`chatgpt.*`, `write:chatgpt.*`) are not accepted here for\n * either operation.\n */\n scopes: string[];\n /**\n * Override the resolved service endpoints (partial). Useful for pointing at a\n * non-standard deployment.\n */\n endpoints?: Partial<DirectServiceEndpoints>;\n /**\n * Client for the Vana Account access-request API. Defaults to a client against\n * the resolved Vana Account endpoints; inject your own to point at a custom\n * deployment or to supply a test double.\n */\n accessRequestClient?: AccessRequestClient;\n /**\n * Escrow settlement config used when a Personal Server read returns `402`.\n *\n * @remarks\n * Wires the DPv2 escrow gateway (`protocol/escrow`). The controller supplies\n * the EIP-712 `signTypedData` from the app key automatically.\n *\n * When omitted (or partially omitted), the SDK derives defaults from the\n * per-network endpoints table and the contract registry:\n * - `client` defaults to a gateway client at `endpoints.escrowGatewayUrl`\n * - `escrowContract` defaults to `CONTRACTS.DataPortabilityEscrow.addresses[chainId]`\n * - `chainId` defaults to the controller's resolved chain id\n *\n * Provide this field only to override a specific default.\n */\n escrow?: Partial<DirectEscrowConfig>;\n /** `fetch` used by the default access-request client. Defaults to `globalThis.fetch`. */\n fetchFn?: FetchLike;\n /** `fetch` used for the Personal Server read. Defaults to `globalThis.fetch`. */\n personalServerFetch?: PersonalServerFetch;\n /**\n * Transport-retry knobs for the Personal Server read\n * ({@link PersonalServerTransportRetryOptions}). Defaults to 3 attempts with\n * exponential backoff. Retries fire only when fetch throws (the browser-PS\n * relay reconnect window), never on a received HTTP status, and never\n * re-sign a payment.\n */\n personalServerTransportRetry?: PersonalServerTransportRetryOptions;\n}\n\n/**\n * Controller-level escrow config — the {@link EscrowPaymentConfig} minus the\n * `signTypedData` and `chainId` the controller injects itself.\n */\nexport interface DirectEscrowConfig extends Omit<\n EscrowPaymentConfig,\n \"signTypedData\" | \"chainId\"\n> {\n /**\n * Chain id for the EIP-712 domain. Defaults to the controller's environment\n * (1480 for mainnet, 14800 for moksha).\n */\n chainId?: number;\n}\n\n/**\n * Server-side controller for the direct Data Portability flow.\n *\n * @typeParam T - Shape of the data returned by {@link DirectDataController.readApprovedData}.\n */\nexport interface DirectDataController {\n /** The on-chain address of the app, derived from `appPrivateKey`. */\n readonly appAddress: string;\n\n /**\n * The app's on-chain address — the address to fund and inspect in the Builder\n * activity report. Equivalent to {@link DirectDataController.appAddress}.\n *\n * @returns The app's `0x`-prefixed address.\n */\n getAppAddress(): string;\n\n /**\n * The app's full identity: its configured id/name/homepage plus the derived\n * on-chain address. Useful for telling builders which app address to fund or\n * look up.\n *\n * @returns `{ id, name, homepageUrl, address }`.\n */\n getAppIdentity(): AppIdentity;\n\n /**\n * Create an access request the user can approve.\n *\n * @param input - The post-approval return URL and optional create retry key.\n * @returns The request id, HTTPS approval URL, and — for a pending deep Direct\n * request on mobile — an optional HTTPS `mobileContinuationUrl`.\n */\n createAccessRequest(input: {\n returnUrl: string;\n /** Optional foreground mobile delivery callback. */\n foregroundDelivery?: ForegroundDelivery;\n /**\n * Stable retry key when the caller retries after an uncertain response.\n * Each create without one gets its own generated key.\n */\n idempotencyKey?: string;\n }): Promise<AccessRequest>;\n\n /**\n * Fetch the current status of an access request.\n *\n * @param requestId - The `dcr_*` id from {@link DirectDataController.createAccessRequest}.\n * @returns `{ status, personalServerUrl?, grantId?, scope?, scopes? }`.\n */\n getAccessRequestStatus(requestId: string): Promise<AccessRequestStatus>;\n\n /**\n * Read the approved data from the user's Personal Server.\n *\n * @remarks\n * Resolves the request to its grant + Personal Server and performs a Web3Signed\n * read. Hides the `402 Payment Required` flow by default: if a read needs\n * payment, it signs the Personal Server's payment challenge, retries with\n * `X-PAYMENT`, and attaches shape-validated but unauthenticated\n * {@link DirectPaymentResponseMetadata} under `payment` when the Personal\n * Server returns it. After a successful read, the controller acknowledges\n * the DCR so Vana Web can close/redirect the approval tab.\n *\n * A request can approve several scopes. This reads **one** of them — `scope`\n * when given, otherwise the first approved scope. Use\n * {@link DirectDataController.readAllApprovedData} to read them all.\n *\n * Acknowledging moves the DCR to `completed`, which is terminal and no longer\n * read-ready. To read several scopes with your own loop, pass\n * `acknowledge: false` on every call but the last.\n *\n * @param input - The `dcr_*` request id, the optional `scope` to read, and an\n * optional `acknowledge` flag (default `true`).\n * @returns `{ scope, data, payment? }`.\n * @throws {@link AccessNotApprovedError} if the request is not approved.\n * @throws {@link ScopeNotApprovedError} if `scope` is not an approved scope.\n * @throws {@link PaymentRequiredError} if payment is required but unsettled.\n */\n readApprovedData<T = unknown>(input: {\n requestId: string;\n scope?: string;\n acknowledge?: boolean;\n }): Promise<ApprovedDataResult<T>>;\n\n /**\n * Read every scope the user approved on a request.\n *\n * @remarks\n * Reads the scopes in approval order, then acknowledges the DCR **once**,\n * after the last read — acknowledging earlier would move the request to\n * `completed` and make the remaining scopes unreadable.\n *\n * Each scope is a separate Personal Server read that settles its own\n * `data_access` fee from escrow, so reading N scopes costs N times a\n * single-scope read. The one-off registration fee is charged per grant, not\n * per scope.\n *\n * A scope that fails does not abort the rest: successes land in `results` and\n * failures in `errors`, because the fees for earlier scopes are already spent.\n * If any scope fails the request is left unacknowledged, so the scopes that\n * failed stay retryable — read them with `readApprovedData({ scope })` and\n * acknowledge on the last one.\n *\n * @param input - The `dcr_*` request id to read.\n * @returns `{ results, errors }`, both keyed by scope.\n * @throws {@link AccessNotApprovedError} if the request is not approved.\n */\n readAllApprovedData<T = unknown>(input: {\n requestId: string;\n }): Promise<MultiScopeDataResult<T>>;\n}\n\nfunction isHexPrivateKey(value: string): value is Hex {\n return /^0x[0-9a-fA-F]{64}$/.test(value);\n}\n\n// A DCR is read-ready only while the grant exists and the Personal Server is\n// still serving it: `approved` (durable PS) or `ready_for_read` (browser PS).\n// `completed` is terminal — the app already read and acknowledged, and the\n// browser PS may be gone — so it is deliberately excluded here.\nfunction isReadReadyStatus(status: AccessRequestStatusValue): boolean {\n return status === \"approved\" || status === \"ready_for_read\";\n}\n\n/**\n * Create a {@link DirectDataController}.\n *\n * @param config - Controller configuration (env, key, app identity, source, scopes).\n * @returns A ready-to-use controller.\n * @throws {@link DirectConfigError} when the key is missing or malformed, when\n * `scopes` is empty, or when no escrow contract can be resolved.\n * @throws InvalidScopeEntryError when a `scopes` entry does not fit the\n * `[operation:]scope` grammar (an unknown operation prefix such as `delete:`).\n * @throws ZodError when the scope part of an entry is not a valid scope.\n */\nexport function createDirectDataController(\n config: DirectDataControllerConfig,\n): DirectDataController {\n // `appPrivateKey` is the documented field; `builderPrivateKey` is a\n // deprecated alias kept for backwards compatibility.\n const privateKey = config.appPrivateKey ?? config.builderPrivateKey;\n if (!privateKey || !isHexPrivateKey(privateKey)) {\n throw new DirectConfigError(\n \"appPrivateKey must be a 0x-prefixed 32-byte hex string\",\n );\n }\n if (!config.scopes || config.scopes.length === 0) {\n throw new DirectConfigError(\"At least one scope is required\");\n }\n // Validate scopes eagerly so misconfiguration fails at construction. Each\n // element is a grant scope entry (`[operation:]scope`), so the operation\n // prefix is stripped first and only the scope part is checked against the\n // scope grammar — `write:coach.weekly` is a valid write-grant request, and\n // an unknown operation (`delete:x`) throws rather than being taken as read.\n // The entries themselves are passed through to the access request verbatim,\n // prefix included.\n for (const entry of config.scopes) {\n parseScope(parseScopeEntry(entry).scope);\n }\n\n const env: DirectEnv = config.env ?? \"production\";\n const network: DirectNetwork = config.network ?? getDirectDefaultNetwork(env);\n const defaultEndpoints = getDirectEndpoints(env);\n const chainId = config.endpoints?.chainId ?? getDirectNetworkChainId(network);\n const endpoints: DirectServiceEndpoints = {\n ...defaultEndpoints,\n ...config.endpoints,\n chainId,\n };\n\n const account = privateKeyToAccount(privateKey as Hex);\n const signMessage: Web3SignedSignFn = (message: string) =>\n account.signMessage({ message });\n // viem's account.signTypedData satisfies the structural SignTypedDataFn used\n // by the escrow GenericPayment signer.\n const signTypedData = account.signTypedData as unknown as SignTypedDataFn;\n const accessRequestClient: AccessRequestClient =\n config.accessRequestClient ??\n createDefaultAccessRequestClient({\n baseUrl: endpoints.accessRequestBaseUrl,\n approvalBaseUrl: endpoints.approvalAppBaseUrl,\n env,\n fetchFn: config.fetchFn,\n appAddress: account.address,\n signMessage,\n });\n\n // Build the escrow payment config, defaulting from the per-network endpoints\n // table and the contract registry when `config.escrow` is omitted or partial.\n const escrowChainId = config.escrow?.chainId ?? chainId;\n const defaultEscrowContract =\n CONTRACTS.DataPortabilityEscrow.addresses[\n escrowChainId as keyof typeof CONTRACTS.DataPortabilityEscrow.addresses\n ] ?? undefined;\n if (!config.escrow?.escrowContract && !defaultEscrowContract) {\n throw new DirectConfigError(\n `No DataPortabilityEscrow address found in the registry for chainId ${escrowChainId}. ` +\n `Provide an explicit escrow.escrowContract in the controller config.`,\n );\n }\n const escrow: EscrowPaymentConfig = {\n client:\n config.escrow?.client ??\n createEscrowGatewayClient(endpoints.escrowGatewayUrl),\n escrowContract:\n config.escrow?.escrowContract ?? (defaultEscrowContract as `0x${string}`),\n chainId: escrowChainId,\n nonceSource: config.escrow?.nonceSource,\n signTypedData,\n };\n\n return {\n appAddress: account.address,\n\n getAppAddress(): string {\n return account.address;\n },\n\n getAppIdentity(): AppIdentity {\n return {\n id: config.app.id,\n name: config.app.name,\n homepageUrl: config.app.homepageUrl,\n address: account.address,\n };\n },\n\n async createAccessRequest(input): Promise<AccessRequest> {\n return accessRequestClient.createAccessRequest({\n appAddress: account.address,\n app: config.app,\n source: config.source,\n scopes: config.scopes,\n returnUrl: input.returnUrl,\n network,\n ...(input.foregroundDelivery !== undefined\n ? { foregroundDelivery: input.foregroundDelivery }\n : {}),\n ...(input.idempotencyKey !== undefined\n ? { idempotencyKey: input.idempotencyKey }\n : {}),\n });\n },\n\n async getAccessRequestStatus(\n requestId: string,\n ): Promise<AccessRequestStatus> {\n return accessRequestClient.getAccessRequestStatus(requestId);\n },\n\n async readApprovedData<T = unknown>(input: {\n requestId: string;\n scope?: string;\n acknowledge?: boolean;\n }): Promise<ApprovedDataResult<T>> {\n const status = await requireReadReady(input.requestId);\n const scope = resolveRequestedScope(status, input.scope);\n\n const result = await readScope<T>(status, scope);\n if (input.acknowledge !== false) {\n await acknowledgeQuietly(input.requestId);\n }\n return result;\n },\n\n async readAllApprovedData<T = unknown>(input: {\n requestId: string;\n }): Promise<MultiScopeDataResult<T>> {\n const status = await requireReadReady(input.requestId);\n const scopes = approvedScopes(status);\n\n const results: Record<string, ApprovedDataResult<T>> = {};\n const errors: Record<string, Error> = {};\n // Sequential, not parallel: each read settles its own escrow payment and\n // the default nonce source is process-local, so concurrent reads would\n // race on the payment nonce.\n for (const scope of scopes) {\n try {\n results[scope] = await readScope<T>(status, scope);\n } catch (error) {\n errors[scope] =\n error instanceof Error ? error : new Error(String(error));\n }\n }\n\n // Acknowledge only after the last read, and only if every scope read —\n // acking moves the DCR to `completed`, which is terminal and no longer\n // read-ready, so acking on a partial failure would make the scope that\n // failed impossible to retry.\n if (Object.keys(errors).length === 0) {\n await acknowledgeQuietly(input.requestId);\n }\n\n return { results, errors };\n },\n };\n\n async function requireReadReady(\n requestId: string,\n ): Promise<AccessRequestStatus> {\n const status = await accessRequestClient.getAccessRequestStatus(requestId);\n // `scope` and `scopes` are both optional on the public status type, and a\n // client may return either one — require at least one approved scope rather\n // than the singular field specifically.\n if (\n !isReadReadyStatus(status.status) ||\n !status.personalServerUrl ||\n !status.grantId ||\n approvedScopes(status).length === 0\n ) {\n throw new AccessNotApprovedError(\n \"Request is not approved or is missing grantId/scope/personalServerUrl\",\n {\n requestId,\n status: status.status,\n hasPersonalServerUrl: Boolean(status.personalServerUrl),\n hasGrantId: Boolean(status.grantId),\n hasScope: approvedScopes(status).length > 0,\n },\n );\n }\n return status;\n }\n\n /** Approved scopes in approval order, falling back to the single `scope`. */\n function approvedScopes(status: AccessRequestStatus): string[] {\n if (status.scopes && status.scopes.length > 0) return status.scopes;\n return status.scope ? [status.scope] : [];\n }\n\n /**\n * Resolve which scope to read. Rejects an unapproved scope up front so it\n * never reaches the Personal Server and never settles a fee.\n */\n function resolveRequestedScope(\n status: AccessRequestStatus,\n requested?: string,\n ): string {\n const scopes = approvedScopes(status);\n if (requested === undefined) return scopes[0];\n if (!scopes.includes(requested)) {\n throw new ScopeNotApprovedError(\n `Scope \"${requested}\" is not approved on this request`,\n { requestedScope: requested, approvedScopes: scopes },\n );\n }\n return requested;\n }\n\n async function readScope<T>(\n status: AccessRequestStatus,\n scope: string,\n ): Promise<ApprovedDataResult<T>> {\n const result = await readPersonalServerData({\n personalServerUrl: status.personalServerUrl as string,\n scope,\n grantId: status.grantId as string,\n payerAddress: account.address,\n signMessage,\n escrow,\n fetchFn: config.personalServerFetch,\n transportRetry: config.personalServerTransportRetry,\n });\n return { scope, data: result.data as T, payment: result.payment };\n }\n\n async function acknowledgeQuietly(requestId: string): Promise<void> {\n try {\n await accessRequestClient.acknowledgeRead?.(requestId);\n } catch {\n // The read already succeeded; ack only drives Vana Web completion UX.\n }\n }\n}\n"],"mappings":"AAuBA,SAAS,2BAA2B;AAGpC,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,SAAS,iCAAiC;AAC1C,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAKP;AAAA,EACE;AAAA,OAGK;AAkOP,SAAS,gBAAgB,OAA6B;AACpD,SAAO,sBAAsB,KAAK,KAAK;AACzC;AAMA,SAAS,kBAAkB,QAA2C;AACpE,SAAO,WAAW,cAAc,WAAW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