@dignetwork/dig-sdk 0.0.1-alpha.99 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -7
- package/README.md +267 -0
- package/dist/adapters.cjs +315 -0
- package/dist/adapters.cjs.map +1 -0
- package/dist/adapters.d.cts +20 -0
- package/dist/adapters.d.ts +20 -0
- package/dist/adapters.js +306 -0
- package/dist/adapters.js.map +1 -0
- package/dist/dev-shim-Bgw8X2E9.d.cts +118 -0
- package/dist/dev-shim-Bgw8X2E9.d.ts +118 -0
- package/dist/dig-client-entry-BIzuZ7Rs.d.cts +263 -0
- package/dist/dig-client-entry-BIzuZ7Rs.d.ts +263 -0
- package/dist/dig-client.cjs +330 -0
- package/dist/dig-client.cjs.map +1 -0
- package/dist/dig-client.d.cts +1 -0
- package/dist/dig-client.d.ts +1 -0
- package/dist/dig-client.js +319 -0
- package/dist/dig-client.js.map +1 -0
- package/dist/index.cjs +754 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +192 -0
- package/dist/index.d.ts +192 -5
- package/dist/index.js +731 -19
- package/dist/index.js.map +1 -0
- package/dist/next.cjs +326 -0
- package/dist/next.cjs.map +1 -0
- package/dist/next.d.cts +23 -0
- package/dist/next.d.ts +23 -0
- package/dist/next.js +319 -0
- package/dist/next.js.map +1 -0
- package/dist/spend.cjs +14 -0
- package/dist/spend.cjs.map +1 -0
- package/dist/spend.d.cts +1 -0
- package/dist/spend.d.ts +1 -0
- package/dist/spend.js +3 -0
- package/dist/spend.js.map +1 -0
- package/dist/vite.cjs +338 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.d.cts +35 -0
- package/dist/vite.d.ts +35 -0
- package/dist/vite.js +332 -0
- package/dist/vite.js.map +1 -0
- package/package.json +87 -59
- package/vendor/PROVENANCE.md +102 -0
- package/vendor/dig_client.d.ts +150 -0
- package/vendor/dig_client.mjs +805 -0
- package/vendor/dig_client_bg.wasm +0 -0
- package/dist/DataIntegrityTree/DataIntegrityTree.d.ts +0 -163
- package/dist/DataIntegrityTree/DataIntegrityTree.d.ts.map +0 -1
- package/dist/DataIntegrityTree/DataIntegrityTree.js +0 -707
- package/dist/DataIntegrityTree/DataLayerError.d.ts +0 -6
- package/dist/DataIntegrityTree/DataLayerError.d.ts.map +0 -1
- package/dist/DataIntegrityTree/DataLayerError.js +0 -17
- package/dist/DataIntegrityTree/index.d.ts +0 -2
- package/dist/DataIntegrityTree/index.d.ts.map +0 -1
- package/dist/DataIntegrityTree/index.js +0 -17
- package/dist/DigNetwork/ContentServer.d.ts +0 -31
- package/dist/DigNetwork/ContentServer.d.ts.map +0 -1
- package/dist/DigNetwork/ContentServer.js +0 -176
- package/dist/DigNetwork/DigChallenge.d.ts +0 -82
- package/dist/DigNetwork/DigChallenge.d.ts.map +0 -1
- package/dist/DigNetwork/DigChallenge.js +0 -144
- package/dist/DigNetwork/DigNetwork.d.ts +0 -14
- package/dist/DigNetwork/DigNetwork.d.ts.map +0 -1
- package/dist/DigNetwork/DigNetwork.js +0 -169
- package/dist/DigNetwork/DigPeer.d.ts +0 -24
- package/dist/DigNetwork/DigPeer.d.ts.map +0 -1
- package/dist/DigNetwork/DigPeer.js +0 -118
- package/dist/DigNetwork/IncentiveServer.d.ts +0 -13
- package/dist/DigNetwork/IncentiveServer.d.ts.map +0 -1
- package/dist/DigNetwork/IncentiveServer.js +0 -76
- package/dist/DigNetwork/PropagationServer.d.ts +0 -81
- package/dist/DigNetwork/PropagationServer.d.ts.map +0 -1
- package/dist/DigNetwork/PropagationServer.js +0 -563
- package/dist/DigNetwork/index.d.ts +0 -4
- package/dist/DigNetwork/index.d.ts.map +0 -1
- package/dist/DigNetwork/index.js +0 -19
- package/dist/blockchain/DataStore.d.ts +0 -67
- package/dist/blockchain/DataStore.d.ts.map +0 -1
- package/dist/blockchain/DataStore.js +0 -413
- package/dist/blockchain/DataStoreSerializer.d.ts +0 -52
- package/dist/blockchain/DataStoreSerializer.d.ts.map +0 -1
- package/dist/blockchain/DataStoreSerializer.js +0 -109
- package/dist/blockchain/FullNodePeer.d.ts +0 -31
- package/dist/blockchain/FullNodePeer.d.ts.map +0 -1
- package/dist/blockchain/FullNodePeer.js +0 -295
- package/dist/blockchain/ServerCoin.d.ts +0 -29
- package/dist/blockchain/ServerCoin.d.ts.map +0 -1
- package/dist/blockchain/ServerCoin.js +0 -324
- package/dist/blockchain/Wallet.d.ts +0 -28
- package/dist/blockchain/Wallet.d.ts.map +0 -1
- package/dist/blockchain/Wallet.js +0 -253
- package/dist/blockchain/coins.d.ts +0 -6
- package/dist/blockchain/coins.d.ts.map +0 -1
- package/dist/blockchain/coins.js +0 -102
- package/dist/blockchain/index.d.ts +0 -8
- package/dist/blockchain/index.d.ts.map +0 -1
- package/dist/blockchain/index.js +0 -36
- package/dist/index.d.ts.map +0 -1
- package/dist/prompts.d.ts +0 -21
- package/dist/prompts.d.ts.map +0 -1
- package/dist/prompts.js +0 -149
- package/dist/types.d.ts +0 -64
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/utils/ContentScanner.d.ts +0 -63
- package/dist/utils/ContentScanner.d.ts.map +0 -1
- package/dist/utils/ContentScanner.js +0 -175
- package/dist/utils/Environment.d.ts +0 -18
- package/dist/utils/Environment.d.ts.map +0 -1
- package/dist/utils/Environment.js +0 -85
- package/dist/utils/FileCache.d.ts +0 -11
- package/dist/utils/FileCache.d.ts.map +0 -1
- package/dist/utils/FileCache.js +0 -58
- package/dist/utils/FileTransfer.d.ts +0 -47
- package/dist/utils/FileTransfer.d.ts.map +0 -1
- package/dist/utils/FileTransfer.js +0 -209
- package/dist/utils/NconfManager.d.ts +0 -11
- package/dist/utils/NconfManager.d.ts.map +0 -1
- package/dist/utils/NconfManager.js +0 -56
- package/dist/utils/StoreArchiveManager.d.ts +0 -45
- package/dist/utils/StoreArchiveManager.d.ts.map +0 -1
- package/dist/utils/StoreArchiveManager.js +0 -153
- package/dist/utils/asyncPool.d.ts +0 -9
- package/dist/utils/asyncPool.d.ts.map +0 -1
- package/dist/utils/asyncPool.js +0 -23
- package/dist/utils/config.d.ts +0 -68
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js +0 -223
- package/dist/utils/connectionUtils.d.ts +0 -10
- package/dist/utils/connectionUtils.d.ts.map +0 -1
- package/dist/utils/connectionUtils.js +0 -18
- package/dist/utils/credentialsUtils.d.ts +0 -8
- package/dist/utils/credentialsUtils.d.ts.map +0 -1
- package/dist/utils/credentialsUtils.js +0 -122
- package/dist/utils/directoryUtils.d.ts +0 -9
- package/dist/utils/directoryUtils.d.ts.map +0 -1
- package/dist/utils/directoryUtils.js +0 -110
- package/dist/utils/encryption.d.ts +0 -8
- package/dist/utils/encryption.d.ts.map +0 -1
- package/dist/utils/encryption.js +0 -55
- package/dist/utils/hashUtils.d.ts +0 -8
- package/dist/utils/hashUtils.d.ts.map +0 -1
- package/dist/utils/hashUtils.js +0 -44
- package/dist/utils/index.d.ts +0 -14
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -29
- package/dist/utils/merkle.d.ts +0 -2
- package/dist/utils/merkle.d.ts.map +0 -1
- package/dist/utils/merkle.js +0 -28
- package/dist/utils/network.d.ts +0 -2
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js +0 -54
- package/dist/utils/spinnerUtils.d.ts +0 -2
- package/dist/utils/spinnerUtils.d.ts.map +0 -1
- package/dist/utils/spinnerUtils.js +0 -47
- package/dist/utils/ssl.d.ts +0 -5
- package/dist/utils/ssl.d.ts.map +0 -1
- package/dist/utils/ssl.js +0 -50
- package/dist/utils/validationUtils.d.ts +0 -9
- package/dist/utils/validationUtils.d.ts.map +0 -1
- package/dist/utils/validationUtils.js +0 -55
package/LICENSE
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DIG Network
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# @dignetwork/dig-sdk
|
|
2
|
+
|
|
3
|
+
The typed front door for building dapps on the **DIG Network**. One `npm i` gives you:
|
|
4
|
+
|
|
5
|
+
- **`ChiaProvider`** — a Chia wallet your dapp gets for free. It prefers the injected **DIG Browser**
|
|
6
|
+
wallet (`window.chia`) and falls back to **WalletConnect → Sage**, behind one normalized
|
|
7
|
+
CHIP-0002 surface (`getAddress`, `signMessage`, `signCoinSpends`, `takeOffer`, balances, coins).
|
|
8
|
+
- **`DigClient`** — read **verified, encrypted** content by URN. It derives the URN's keys in the
|
|
9
|
+
browser, verifies inclusion against the on-chain root, and decrypts — the serving host stays
|
|
10
|
+
blind (it only ever relays opaque ciphertext + proofs).
|
|
11
|
+
- **`@dignetwork/dig-sdk/spend`** — the canonical CHIP-0035 spend builder
|
|
12
|
+
(`@dignetwork/chip35-dl-coin-wasm`) re-exported. Build store / NFT / CAT spends through the SDK
|
|
13
|
+
and sign them with the wallet. Spends are **never** hand-rolled.
|
|
14
|
+
- **Framework adapters** — `@dignetwork/dig-sdk/vite` (a Vite plugin) and `@dignetwork/dig-sdk/next`
|
|
15
|
+
(a Next static-export adapter): inject a `window.chia` dev wallet during `dev`, and ship your
|
|
16
|
+
build to a DIG capsule on a `publish` script. See **[Framework adapters](#framework-adapters)**.
|
|
17
|
+
- **`@dignetwork/dig-sdk/dig-client`** — the read-crypto on its own (just `DigClient` + the loader +
|
|
18
|
+
URN helpers), for consumers that want only the read path (e.g. a worker). Same SRI-pinned wasm.
|
|
19
|
+
|
|
20
|
+
Ships **ESM + CJS + `.d.ts`**, runs in the **browser and Node 18+**, and is **eval-free** (usable
|
|
21
|
+
in CSP-strict contexts).
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm i @dignetwork/dig-sdk
|
|
25
|
+
# Optional: only if you use the WalletConnect → Sage fallback
|
|
26
|
+
npm i @walletconnect/sign-client
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Read verified, encrypted content in 5 lines
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { DigClient } from "@dignetwork/dig-sdk";
|
|
35
|
+
|
|
36
|
+
const dig = new DigClient(); // defaults to https://rpc.dig.net
|
|
37
|
+
const { bytes, decrypted, verified } = await dig.read({
|
|
38
|
+
urn: "urn:dig:chia:<storeId>/index.html", // the resource to read
|
|
39
|
+
root: "<onchain-root-hex>", // the trust anchor (from the chain)
|
|
40
|
+
});
|
|
41
|
+
console.log(decrypted, verified, new TextDecoder().decode(bytes));
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`read()` returns the authenticated **plaintext** when the URN key decrypts the served bytes
|
|
45
|
+
(`decrypted: true`); otherwise it returns the raw ciphertext (a decoy is just opaque bytes — the
|
|
46
|
+
model is oblivious, so a read is never a "not found" verdict). `verified` is the advisory
|
|
47
|
+
inclusion-proof check against `root`. For text, `await dig.readText({ urn, root })` returns the
|
|
48
|
+
decoded string (or throws if it didn't decrypt).
|
|
49
|
+
|
|
50
|
+
A private store adds a salt — either inline in the URN (`…/secret.txt?salt=<hex>`) or as
|
|
51
|
+
`dig.read({ urn, root, salt })`.
|
|
52
|
+
|
|
53
|
+
## Connect a wallet + sign
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { ChiaProvider } from "@dignetwork/dig-sdk";
|
|
57
|
+
|
|
58
|
+
// Prefers the injected DIG Browser wallet; falls back to WalletConnect → Sage.
|
|
59
|
+
const provider = await ChiaProvider.connect({
|
|
60
|
+
mode: "auto",
|
|
61
|
+
walletConnect: {
|
|
62
|
+
projectId: "<walletconnect-cloud-project-id>",
|
|
63
|
+
metadata: {
|
|
64
|
+
name: "My DIG dapp",
|
|
65
|
+
description: "Built with @dignetwork/dig-sdk",
|
|
66
|
+
url: "https://my-dapp.example",
|
|
67
|
+
icons: ["https://my-dapp.example/icon.png"],
|
|
68
|
+
},
|
|
69
|
+
onUri: (uri) => showWalletConnectQr(uri), // render the QR / copy-link for the fallback
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const address = await provider.getAddress();
|
|
74
|
+
const { publicKey, signature } = await provider.signMessage("Login to My DIG dapp");
|
|
75
|
+
// → verify the BLS signature server-side against the CHIP-0002 message hash + publicKey
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
If you only target the DIG Browser, drop `walletConnect` and use `mode: "injected"` (or `"auto"`,
|
|
79
|
+
which still prefers injected). `provider.backend` tells you which transport connected.
|
|
80
|
+
|
|
81
|
+
## Build + sign a store spend
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { ChiaProvider } from "@dignetwork/dig-sdk";
|
|
85
|
+
import * as spend from "@dignetwork/dig-sdk/spend"; // the canonical CHIP-0035 builder
|
|
86
|
+
|
|
87
|
+
spend.init();
|
|
88
|
+
// Build a spend bundle with the wasm builder (e.g. spend.mintStore(...) / spend.updateStoreMetadata(...)),
|
|
89
|
+
// then hand its coin spends to the wallet to sign:
|
|
90
|
+
const provider = await ChiaProvider.connect({ mode: "injected" });
|
|
91
|
+
const aggregatedSignature = await provider.signCoinSpends(/* coinSpends from the builder */ []);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The hub builds spend bundles in-browser via this wasm and pushes them to the wallet for signing —
|
|
95
|
+
your dapp does the same through the SDK.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## API surface
|
|
100
|
+
|
|
101
|
+
### `ChiaProvider`
|
|
102
|
+
|
|
103
|
+
| Member | Description |
|
|
104
|
+
|---|---|
|
|
105
|
+
| `static connect(options)` | Connect a wallet. `mode`: `"auto"` (default, prefer injected) / `"injected"` / `"walletconnect"`. |
|
|
106
|
+
| `connectWallet(options)` | Convenience alias for `ChiaProvider.connect`. |
|
|
107
|
+
| `backend` / `session` | The connected transport (`"injected"` \| `"walletconnect"`) and session descriptor. |
|
|
108
|
+
| `getAddress()` | The wallet's receive address (cached). |
|
|
109
|
+
| `getPublicKeys()` | The wallet's synthetic public keys. |
|
|
110
|
+
| `signMessage(message, address?)` | Sign a UTF-8 message; returns `{ publicKey, signature }` (0x-normalized). |
|
|
111
|
+
| `signCoinSpends(coinSpends)` | Sign raw CHIP-0035 coin spends (partialSign); returns the aggregated signature hex. |
|
|
112
|
+
| `takeOffer(offer, fee?)` | Accept a Chia offer string (e.g. an NFT offer). |
|
|
113
|
+
| `getXchBalance()` / `getCatBalance(assetId)` | Spendable balances (mojo/base-unit strings). |
|
|
114
|
+
| `getXchCoins(limit?)` / `getCatCoins(assetId, limit?)` | Unspent coins for funding a spend. |
|
|
115
|
+
| `request(method, params?)` | Escape hatch: a raw CHIP-0002 request through the active transport. |
|
|
116
|
+
| `supports(method)` / `disconnect()` | Capability check / teardown. |
|
|
117
|
+
|
|
118
|
+
Transports are also exported directly (`InjectedTransport`, `WalletConnectTransport`,
|
|
119
|
+
`isInjectedAvailable`, `getInjectedProvider`) for advanced flows (e.g. restoring a WC session via
|
|
120
|
+
`WalletConnectTransport.restore(...)`).
|
|
121
|
+
|
|
122
|
+
### `DigClient`
|
|
123
|
+
|
|
124
|
+
| Member | Description |
|
|
125
|
+
|---|---|
|
|
126
|
+
| `new DigClient({ rpc?, fetch? })` | RPC defaults to `https://rpc.dig.net`. |
|
|
127
|
+
| `read({ urn, root?, salt? }, opts?)` | Fetch + verify + decrypt → `{ bytes, verified, decrypted, … }`. |
|
|
128
|
+
| `readText({ urn, root?, salt? }, opts?)` | As `read`, decoded to a UTF-8 string (throws if not decrypted). |
|
|
129
|
+
| `readResource({ storeId, resourceKey, root, salt? }, opts?)` | Read by explicit parts instead of a URN. |
|
|
130
|
+
| `deriveUrnKeys({ urn, salt? })` | The root-independent `{ retrievalKey, decryptionKey }` for a URN. |
|
|
131
|
+
| `retrievalKey(storeId, key)` / `deriveKey(storeId, key, salt?)` | The individual derivations. |
|
|
132
|
+
| `verifyInclusion(ciphertext, proof, root)` / `reconstructUrn(...)` | Lower-level read-crypto. |
|
|
133
|
+
| `wasm()` | The raw SRI-verified read-crypto wasm (`decryptChunk`, `encryptResource`, `version`, …). |
|
|
134
|
+
|
|
135
|
+
### URN helpers (pure)
|
|
136
|
+
|
|
137
|
+
`parseUrn`, `isUrn`, `reconstructUrn`, `reconstructUrnWithRoot` and the `ParsedUrn` type — the same
|
|
138
|
+
URN grammar the hub, extension, and companion use.
|
|
139
|
+
|
|
140
|
+
### Spend builder
|
|
141
|
+
|
|
142
|
+
`import * as spend from "@dignetwork/dig-sdk/spend"` re-exports
|
|
143
|
+
[`@dignetwork/chip35-dl-coin-wasm`](https://www.npmjs.com/package/@dignetwork/chip35-dl-coin-wasm)
|
|
144
|
+
(≥ 0.5.0): store coins (`mintStore`, `meltStore`, `updateStoreMetadata`, `updateStoreOwnership`,
|
|
145
|
+
`oracleSpend`), assets (`mintNft`, `bulkMint`, `createDid`, `issueCat`), CHIP-0007 metadata
|
|
146
|
+
(`buildChip0007Metadata`, `validateChip0007`, `generateItemMetadata`), offers (`encodeOffer`,
|
|
147
|
+
`decodeOffer`), and helpers (`addFee`, `dataStoreFromSpend`, `hexSpendBundleToCoinSpends`,
|
|
148
|
+
`spendBundleToHex`, `digstoreOwnerHint`, `sha256`, `init`).
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Framework adapters
|
|
153
|
+
|
|
154
|
+
Make DIG a first-class deploy target for the frameworks you already use. Each adapter does two
|
|
155
|
+
things: injects a **`window.chia` dev wallet** during local `dev` (the same injected-provider
|
|
156
|
+
contract `ChiaProvider` detects in production, so the wallet path runs end-to-end locally), and
|
|
157
|
+
ships your build to a **DIG capsule** via `digstore deploy --json` on a `publish` script.
|
|
158
|
+
|
|
159
|
+
> Deploying **spends DIG** (each deploy publishes a new capsule), so it is a deliberate, credentialed
|
|
160
|
+
> step — never wired into the default `build`. Config + secrets are read from your project's
|
|
161
|
+
> `dig.toml` and `DIGSTORE_*` env vars, exactly like `digstore deploy`; the deploy key and store
|
|
162
|
+
> salt come from the env only (never argv) so they don't leak. Requires the `digstore` CLI on PATH.
|
|
163
|
+
|
|
164
|
+
### Vite — `@dignetwork/dig-sdk/vite`
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
// vite.config.ts
|
|
168
|
+
import { defineConfig } from "vite";
|
|
169
|
+
import { digVite } from "@dignetwork/dig-sdk/vite";
|
|
170
|
+
|
|
171
|
+
export default defineConfig({
|
|
172
|
+
plugins: [digVite()], // injects the window.chia dev shim during `vite dev`
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
```jsonc
|
|
177
|
+
// package.json — opt in to deploy with a publish script (after the build)
|
|
178
|
+
{
|
|
179
|
+
"scripts": {
|
|
180
|
+
"publish:dig": "vite build && node -e \"import('@dignetwork/dig-sdk/vite').then(m => m.digDeploy())\""
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
`digDeploy()` shells out to `digstore deploy --json`, ships the build dir to a new capsule, and
|
|
186
|
+
prints the `dig://` + `https://hub.dig.net/stores/<id>` URL. Disable the dev shim with
|
|
187
|
+
`digVite({ devWallet: false })`; set its mock address with `digVite({ devWalletOptions: { address } })`.
|
|
188
|
+
|
|
189
|
+
### Next.js (static export) — `@dignetwork/dig-sdk/next`
|
|
190
|
+
|
|
191
|
+
Next has no Vite-style HTML hook, so the dev shim is a helper you drop into your `<head>` (guarded to
|
|
192
|
+
dev), and `digDeploy()` ships the `out/` static export:
|
|
193
|
+
|
|
194
|
+
```tsx
|
|
195
|
+
// app/layout.tsx — dev-only window.chia shim
|
|
196
|
+
import { digNextDevShimTag } from "@dignetwork/dig-sdk/next";
|
|
197
|
+
|
|
198
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
199
|
+
return (
|
|
200
|
+
<html>
|
|
201
|
+
<head>
|
|
202
|
+
{process.env.NODE_ENV !== "production" && (
|
|
203
|
+
<script dangerouslySetInnerHTML={{ __html: digNextDevShimTag().replace(/^<script>|<\/script>$/g, "") }} />
|
|
204
|
+
)}
|
|
205
|
+
</head>
|
|
206
|
+
<body>{children}</body>
|
|
207
|
+
</html>
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
```jsonc
|
|
213
|
+
// package.json — deploy the static export (next.config: `output: "export"`)
|
|
214
|
+
{
|
|
215
|
+
"scripts": {
|
|
216
|
+
"publish:dig": "next build && node -e \"import('@dignetwork/dig-sdk/next').then(m => m.digDeploy())\""
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
`digDeploy()` defaults the output dir to `out` (Next's export dir); override any field via
|
|
222
|
+
`digDeploy({ outputDir, storeId, message, … })` or `dig.toml`.
|
|
223
|
+
|
|
224
|
+
### Configuration
|
|
225
|
+
|
|
226
|
+
Both adapters resolve config with this precedence: **`digDeploy()` options > `DIGSTORE_*` env >
|
|
227
|
+
`dig.toml` > defaults** (mirroring `digstore deploy`). Common keys: `store-id`, `output-dir`,
|
|
228
|
+
`message`, `network`, `remote` (in `dig.toml`); secrets `DIGSTORE_DEPLOY_KEY` and (private stores)
|
|
229
|
+
`DIGSTORE_STORE_SALT` from the env. The pure building blocks (config resolution, deploy-arg
|
|
230
|
+
construction, the dev-shim string, the `dig.toml` reader) are exported from
|
|
231
|
+
`@dignetwork/dig-sdk/adapters` if you want to compose your own deploy step.
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Key concepts
|
|
236
|
+
|
|
237
|
+
- **URN** — `urn:dig:chia:<storeId>[:<root>]/<resourceKey>[?salt=<hex>]` addresses one resource in
|
|
238
|
+
a store. The retrieval + decryption keys are **root-independent** (the root is only the trust
|
|
239
|
+
anchor for verification).
|
|
240
|
+
- **Oblivious / blind host** — the dig RPC returns indistinguishable ciphertext for any retrieval
|
|
241
|
+
key, so presence is unknowable. The client decrypts what it can; it never asks the host "is this
|
|
242
|
+
present?".
|
|
243
|
+
- **Trust anchor** — content is verified against an **on-chain root** that *you* resolve from the
|
|
244
|
+
chain (coinset.org / the store singleton) and pass to `read({ root })`. The serving host can
|
|
245
|
+
never be the trust anchor.
|
|
246
|
+
|
|
247
|
+
## Read-crypto wasm provenance
|
|
248
|
+
|
|
249
|
+
`DigClient` runs the **same** `dig_client` read-crypto WASM the DIG Browser, the
|
|
250
|
+
`dig-chrome-extension`, the `dig-companion`, and `hub.dig.net` use. It is vendored under `vendor/`,
|
|
251
|
+
pinned by SHA-256 (`ff486be8…`), and **SRI-verified at load** — a tampered or wrong artifact
|
|
252
|
+
**fails closed** rather than running unverified crypto. See `vendor/PROVENANCE.md`.
|
|
253
|
+
|
|
254
|
+
### CSP-strict / no-bundler browsers
|
|
255
|
+
|
|
256
|
+
The wasm is loaded lazily; in a bundler that resolves package files it is found automatically. If
|
|
257
|
+
your environment can't resolve the vendored files (or your CSP blocks runtime fetches), fetch +
|
|
258
|
+
verify the bytes yourself and hand them in **before** the first read:
|
|
259
|
+
|
|
260
|
+
```ts
|
|
261
|
+
import { configureWasm } from "@dignetwork/dig-sdk";
|
|
262
|
+
configureWasm({ wasmBytes: myVerifiedBytes, glueUrl: "/dig-client/dig_client.mjs" });
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## License
|
|
266
|
+
|
|
267
|
+
MIT
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/adapters/dig-toml.ts
|
|
4
|
+
var KEY_MAP = {
|
|
5
|
+
store_id: "storeId",
|
|
6
|
+
"store-id": "storeId",
|
|
7
|
+
output_dir: "outputDir",
|
|
8
|
+
"output-dir": "outputDir",
|
|
9
|
+
build_command: "buildCommand",
|
|
10
|
+
"build-command": "buildCommand",
|
|
11
|
+
message: "message",
|
|
12
|
+
network: "network",
|
|
13
|
+
remote: "remote",
|
|
14
|
+
wait_timeout: "waitTimeout",
|
|
15
|
+
"wait-timeout": "waitTimeout"
|
|
16
|
+
};
|
|
17
|
+
var APPLY_ORDER = Object.keys(KEY_MAP).sort(
|
|
18
|
+
(a) => a.includes("-") ? 1 : -1
|
|
19
|
+
);
|
|
20
|
+
function stripComment(line) {
|
|
21
|
+
let inSingle = false;
|
|
22
|
+
let inDouble = false;
|
|
23
|
+
for (let i = 0; i < line.length; i++) {
|
|
24
|
+
const ch = line[i];
|
|
25
|
+
if (ch === "'" && !inDouble) inSingle = !inSingle;
|
|
26
|
+
else if (ch === '"' && !inSingle) inDouble = !inDouble;
|
|
27
|
+
else if (ch === "#" && !inSingle && !inDouble) return line.slice(0, i);
|
|
28
|
+
}
|
|
29
|
+
return line;
|
|
30
|
+
}
|
|
31
|
+
function unquote(raw) {
|
|
32
|
+
const v = raw.trim();
|
|
33
|
+
if (v.startsWith('"') && v.endsWith('"') && v.length >= 2 || v.startsWith("'") && v.endsWith("'") && v.length >= 2) {
|
|
34
|
+
return v.slice(1, -1);
|
|
35
|
+
}
|
|
36
|
+
return v;
|
|
37
|
+
}
|
|
38
|
+
function parseDigToml(text) {
|
|
39
|
+
const raw = {};
|
|
40
|
+
for (const lineRaw of text.split(/\r?\n/)) {
|
|
41
|
+
const line = stripComment(lineRaw).trim();
|
|
42
|
+
if (!line || line.startsWith("[")) continue;
|
|
43
|
+
const eq = line.indexOf("=");
|
|
44
|
+
if (eq <= 0) continue;
|
|
45
|
+
const key = line.slice(0, eq).trim();
|
|
46
|
+
if (!(key in KEY_MAP)) continue;
|
|
47
|
+
raw[key] = unquote(line.slice(eq + 1));
|
|
48
|
+
}
|
|
49
|
+
const out = {};
|
|
50
|
+
for (const key of APPLY_ORDER) {
|
|
51
|
+
const value = raw[key];
|
|
52
|
+
const field = KEY_MAP[key];
|
|
53
|
+
if (value === void 0 || field === void 0) continue;
|
|
54
|
+
if (field === "waitTimeout") {
|
|
55
|
+
const n = Number.parseInt(value, 10);
|
|
56
|
+
if (Number.isFinite(n)) out.waitTimeout = n;
|
|
57
|
+
} else {
|
|
58
|
+
out[field] = value;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/adapters/config.ts
|
|
65
|
+
function envVal(env, key) {
|
|
66
|
+
const v = env[key];
|
|
67
|
+
if (v == null) return void 0;
|
|
68
|
+
const t = v.trim();
|
|
69
|
+
return t === "" ? void 0 : t;
|
|
70
|
+
}
|
|
71
|
+
function pick(...candidates) {
|
|
72
|
+
for (const c of candidates) if (c !== void 0) return c;
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
function resolveDeployConfig(input) {
|
|
76
|
+
const { options, digToml, env } = input;
|
|
77
|
+
const storeId = pick(
|
|
78
|
+
options.storeId,
|
|
79
|
+
envVal(env, "DIGSTORE_STORE_ID"),
|
|
80
|
+
digToml.storeId
|
|
81
|
+
);
|
|
82
|
+
const outputDir = pick(options.outputDir, envVal(env, "DIGSTORE_OUTPUT_DIR"), digToml.outputDir) ?? "dist";
|
|
83
|
+
const buildCommand = pick(
|
|
84
|
+
options.buildCommand,
|
|
85
|
+
envVal(env, "DIGSTORE_BUILD_COMMAND"),
|
|
86
|
+
digToml.buildCommand
|
|
87
|
+
);
|
|
88
|
+
const message = pick(options.message, envVal(env, "DIGSTORE_MESSAGE"), digToml.message);
|
|
89
|
+
const network = pick(options.network, envVal(env, "DIGSTORE_NETWORK"), digToml.network) ?? "mainnet";
|
|
90
|
+
const remote = pick(options.remote, envVal(env, "DIGSTORE_REMOTE"), digToml.remote);
|
|
91
|
+
const waitFromEnv = envVal(env, "DIGSTORE_WAIT_TIMEOUT");
|
|
92
|
+
const waitTimeout = pick(
|
|
93
|
+
options.waitTimeout,
|
|
94
|
+
waitFromEnv != null ? Number.parseInt(waitFromEnv, 10) : void 0,
|
|
95
|
+
digToml.waitTimeout
|
|
96
|
+
);
|
|
97
|
+
return {
|
|
98
|
+
storeId,
|
|
99
|
+
outputDir,
|
|
100
|
+
buildCommand,
|
|
101
|
+
message,
|
|
102
|
+
network,
|
|
103
|
+
remote,
|
|
104
|
+
waitTimeout: Number.isFinite(waitTimeout) ? waitTimeout : void 0,
|
|
105
|
+
// SECRETS — env only.
|
|
106
|
+
deployKey: envVal(env, "DIGSTORE_DEPLOY_KEY"),
|
|
107
|
+
salt: envVal(env, "DIGSTORE_STORE_SALT")
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/adapters/deploy.ts
|
|
112
|
+
function buildDeployArgs(cfg, opts = {}) {
|
|
113
|
+
const argv = ["deploy", "--json"];
|
|
114
|
+
if (cfg.storeId) argv.push("--store-id", cfg.storeId);
|
|
115
|
+
if (cfg.outputDir) argv.push("--output-dir", cfg.outputDir);
|
|
116
|
+
if (!opts.skipBuild && cfg.buildCommand) argv.push("--build-command", cfg.buildCommand);
|
|
117
|
+
if (cfg.message) argv.push("--message", cfg.message);
|
|
118
|
+
if (cfg.network) argv.push("--network", cfg.network);
|
|
119
|
+
if (cfg.remote) argv.push("--remote", cfg.remote);
|
|
120
|
+
if (cfg.waitTimeout != null) argv.push("--wait-timeout", String(cfg.waitTimeout));
|
|
121
|
+
return argv;
|
|
122
|
+
}
|
|
123
|
+
function buildDeployEnv(cfg) {
|
|
124
|
+
const env = {};
|
|
125
|
+
if (cfg.deployKey) env.DIGSTORE_DEPLOY_KEY = cfg.deployKey;
|
|
126
|
+
if (cfg.salt) env.DIGSTORE_STORE_SALT = cfg.salt;
|
|
127
|
+
return env;
|
|
128
|
+
}
|
|
129
|
+
var CAPSULE_RE = /^([0-9a-f]{64}):([0-9a-f]{64})$/i;
|
|
130
|
+
function parseDeployResult(stdout) {
|
|
131
|
+
const lines = stdout.split(/\r?\n/).map((l) => l.trim()).filter((l) => l.startsWith("{") && l.endsWith("}"));
|
|
132
|
+
if (lines.length === 0) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
`could not parse digstore deploy output (no JSON object found). Output was:
|
|
135
|
+
${stdout.slice(0, 500)}`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
let obj;
|
|
139
|
+
let fallback;
|
|
140
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
141
|
+
const line = lines[i];
|
|
142
|
+
if (line === void 0) continue;
|
|
143
|
+
let parsed;
|
|
144
|
+
try {
|
|
145
|
+
parsed = JSON.parse(line);
|
|
146
|
+
} catch {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (typeof parsed.capsule === "string") {
|
|
150
|
+
obj = parsed;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
if (!fallback) fallback = parsed;
|
|
154
|
+
}
|
|
155
|
+
if (!obj) {
|
|
156
|
+
if (fallback) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
`digstore deploy did not report a capsule (deploy may have failed). Output:
|
|
159
|
+
${JSON.stringify(fallback)}`
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
throw new Error(`could not parse digstore deploy output as JSON:
|
|
163
|
+
${stdout.slice(0, 500)}`);
|
|
164
|
+
}
|
|
165
|
+
const capsule = obj.capsule;
|
|
166
|
+
const m = CAPSULE_RE.exec(capsule);
|
|
167
|
+
if (!m || m[1] === void 0 || m[2] === void 0) {
|
|
168
|
+
throw new Error(`digstore deploy reported a malformed capsule "${capsule}" (expected storeId:root)`);
|
|
169
|
+
}
|
|
170
|
+
const storeId = m[1].toLowerCase();
|
|
171
|
+
const root = (typeof obj.root === "string" ? obj.root : m[2]).toLowerCase();
|
|
172
|
+
return {
|
|
173
|
+
capsule,
|
|
174
|
+
storeId,
|
|
175
|
+
root,
|
|
176
|
+
// dig:// names the store on the network (resolves to its latest published version).
|
|
177
|
+
digUrl: `dig://${storeId}`,
|
|
178
|
+
// Mirrors digstore deploy.rs::hub_url — the public DIGHub view of an owned store.
|
|
179
|
+
hubUrl: `https://hub.dig.net/stores/${storeId}`,
|
|
180
|
+
pushed: typeof obj.pushed === "boolean" ? obj.pushed : void 0
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/provider/injected.ts
|
|
185
|
+
var INJECTED_TOPIC = "injected";
|
|
186
|
+
|
|
187
|
+
// src/adapters/dev-shim.ts
|
|
188
|
+
var DEV_SHIM_MARKER = "dig-sdk:dev-wallet-shim";
|
|
189
|
+
var DEFAULT_DEV_ADDRESS = "xch1dev0000000000000000000000000000000000000000000000000000devshim";
|
|
190
|
+
function lit(s) {
|
|
191
|
+
return JSON.stringify(s);
|
|
192
|
+
}
|
|
193
|
+
function devShimScript(options = {}) {
|
|
194
|
+
const address = options.address ?? DEFAULT_DEV_ADDRESS;
|
|
195
|
+
return [
|
|
196
|
+
`/* ${DEV_SHIM_MARKER} \u2014 DEV ONLY. A stub wallet for local development; NOT a real wallet. */`,
|
|
197
|
+
`(function () {`,
|
|
198
|
+
` "use strict";`,
|
|
199
|
+
` if (typeof window === "undefined") return;`,
|
|
200
|
+
` // A real injected wallet (DIG Browser / extension) always wins \u2014 never clobber it.`,
|
|
201
|
+
` if (window.chia) return;`,
|
|
202
|
+
` var DEV_ADDRESS = ${lit(address)};`,
|
|
203
|
+
` var TOPIC = ${lit(INJECTED_TOPIC)};`,
|
|
204
|
+
` function ok(data) { return Promise.resolve({ data: data }); }`,
|
|
205
|
+
` function nope(method) {`,
|
|
206
|
+
` return Promise.reject(new Error(`,
|
|
207
|
+
` "[" + ${lit(DEV_SHIM_MARKER)} + "] '" + method + "' needs a real wallet; the dev shim does not sign. " +`,
|
|
208
|
+
` "Open in the DIG Browser or connect a wallet to sign for real."));`,
|
|
209
|
+
` }`,
|
|
210
|
+
` window.chia = {`,
|
|
211
|
+
` isDIG: true, // detected by the SDK's injected-provider check`,
|
|
212
|
+
` isDevShim: true, // so the app can tell it is the dev stub`,
|
|
213
|
+
` topic: TOPIC,`,
|
|
214
|
+
` connect: function () { return Promise.resolve(true); },`,
|
|
215
|
+
` request: function (args) {`,
|
|
216
|
+
` var method = args && args.method ? String(args.method) : "";`,
|
|
217
|
+
` switch (method) {`,
|
|
218
|
+
` case "chip0002_connect": return ok(true);`,
|
|
219
|
+
` case "chip0002_getPublicKeys": return ok([]);`,
|
|
220
|
+
` case "getAddress":`,
|
|
221
|
+
` case "chia_getAddress": return ok(DEV_ADDRESS);`,
|
|
222
|
+
` default:`,
|
|
223
|
+
` // Signing / spend methods must not be faked.`,
|
|
224
|
+
` return nope(method);`,
|
|
225
|
+
` }`,
|
|
226
|
+
` },`,
|
|
227
|
+
` on: function () {},`,
|
|
228
|
+
` off: function () {},`,
|
|
229
|
+
` };`,
|
|
230
|
+
` if (window.console && window.console.info) {`,
|
|
231
|
+
` window.console.info("[" + ${lit(DEV_SHIM_MARKER)} + "] installed a DEV window.chia (mock address " + DEV_ADDRESS + ").");`,
|
|
232
|
+
` }`,
|
|
233
|
+
`})();`
|
|
234
|
+
].join("\n");
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// src/adapters/run.ts
|
|
238
|
+
async function readDigToml(cwd) {
|
|
239
|
+
const { readFile } = await import('fs/promises');
|
|
240
|
+
const path = await import('path');
|
|
241
|
+
try {
|
|
242
|
+
const text = await readFile(path.join(cwd, "dig.toml"), "utf8");
|
|
243
|
+
return parseDigToml(text);
|
|
244
|
+
} catch {
|
|
245
|
+
return {};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async function runDeploy(options = {}) {
|
|
249
|
+
const cwd = options.cwd ?? process.cwd();
|
|
250
|
+
const bin = options.digstoreBin ?? "digstore";
|
|
251
|
+
const log = options.logger ?? ((l) => console.log(l));
|
|
252
|
+
const digToml = await readDigToml(cwd);
|
|
253
|
+
const cfg = resolveDeployConfig({
|
|
254
|
+
options: {
|
|
255
|
+
storeId: options.storeId,
|
|
256
|
+
outputDir: options.outputDir,
|
|
257
|
+
buildCommand: options.buildCommand,
|
|
258
|
+
message: options.message,
|
|
259
|
+
network: options.network,
|
|
260
|
+
remote: options.remote,
|
|
261
|
+
waitTimeout: options.waitTimeout
|
|
262
|
+
},
|
|
263
|
+
digToml,
|
|
264
|
+
env: process.env
|
|
265
|
+
});
|
|
266
|
+
const argv = buildDeployArgs(cfg, { skipBuild: options.skipBuild });
|
|
267
|
+
const childEnv = { ...process.env, ...buildDeployEnv(cfg) };
|
|
268
|
+
log(`\u25B6 digstore ${argv.filter((a) => a !== cfg.deployKey && a !== cfg.salt).join(" ")}`);
|
|
269
|
+
const { spawn } = await import('child_process');
|
|
270
|
+
const stdout = await new Promise((resolve, reject) => {
|
|
271
|
+
const child = spawn(bin, argv, {
|
|
272
|
+
cwd,
|
|
273
|
+
env: childEnv,
|
|
274
|
+
// digstore reads no stdin here; capture stdout (the JSON) and stream stderr through.
|
|
275
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
276
|
+
shell: false
|
|
277
|
+
});
|
|
278
|
+
let out = "";
|
|
279
|
+
let err = "";
|
|
280
|
+
child.stdout.on("data", (d) => {
|
|
281
|
+
out += d.toString();
|
|
282
|
+
});
|
|
283
|
+
child.stderr.on("data", (d) => {
|
|
284
|
+
err += d.toString();
|
|
285
|
+
});
|
|
286
|
+
child.on("error", (e) => {
|
|
287
|
+
reject(
|
|
288
|
+
new Error(
|
|
289
|
+
`could not run "${bin}" \u2014 is digstore installed and on PATH? (${e.message})`
|
|
290
|
+
)
|
|
291
|
+
);
|
|
292
|
+
});
|
|
293
|
+
child.on("close", (code) => {
|
|
294
|
+
if (code === 0) resolve(out);
|
|
295
|
+
else reject(new Error(`digstore deploy failed (exit ${code}).
|
|
296
|
+
${err || out}`));
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
const result = parseDeployResult(stdout);
|
|
300
|
+
log(`\u2713 deployed capsule ${result.capsule}`);
|
|
301
|
+
log(` dig:// ${result.digUrl}`);
|
|
302
|
+
log(` view ${result.hubUrl}`);
|
|
303
|
+
return result;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
exports.DEV_SHIM_MARKER = DEV_SHIM_MARKER;
|
|
307
|
+
exports.buildDeployArgs = buildDeployArgs;
|
|
308
|
+
exports.buildDeployEnv = buildDeployEnv;
|
|
309
|
+
exports.devShimScript = devShimScript;
|
|
310
|
+
exports.parseDeployResult = parseDeployResult;
|
|
311
|
+
exports.parseDigToml = parseDigToml;
|
|
312
|
+
exports.resolveDeployConfig = resolveDeployConfig;
|
|
313
|
+
exports.runDeploy = runDeploy;
|
|
314
|
+
//# sourceMappingURL=adapters.cjs.map
|
|
315
|
+
//# sourceMappingURL=adapters.cjs.map
|