@dignetwork/dig-sdk 0.0.1-alpha.99 → 0.2.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 +412 -0
- package/dist/adapters.cjs +356 -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 +347 -0
- package/dist/adapters.js.map +1 -0
- package/dist/dev-shim-DfKRA1ok.d.cts +128 -0
- package/dist/dev-shim-DfKRA1ok.d.ts +128 -0
- package/dist/dig-client-entry-ChYxUvBn.d.cts +372 -0
- package/dist/dig-client-entry-ChYxUvBn.d.ts +372 -0
- package/dist/dig-client.cjs +443 -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 +432 -0
- package/dist/dig-client.js.map +1 -0
- package/dist/index.cjs +1186 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +502 -0
- package/dist/index.d.ts +502 -5
- package/dist/index.js +1156 -19
- package/dist/index.js.map +1 -0
- package/dist/next.cjs +369 -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 +362 -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 +381 -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 +375 -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,412 @@
|
|
|
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
|
+
- **`Paywall`** — a high-level **pay-to-unlock** helper. Charge XCH or a CAT (e.g. $DIG) to unlock a
|
|
15
|
+
resource, then gate access by verifying the payment — or gate on holding an **NFT** / a
|
|
16
|
+
**collection** membership. It composes `ChiaProvider` with the canonical monetization spends; the
|
|
17
|
+
wasm builds every coin spend, the wallet signs it.
|
|
18
|
+
- **Framework adapters** — `@dignetwork/dig-sdk/vite` (a Vite plugin) and `@dignetwork/dig-sdk/next`
|
|
19
|
+
(a Next static-export adapter): inject a `window.chia` dev wallet during `dev`, and ship your
|
|
20
|
+
build to a DIG capsule on a `publish` script. See **[Framework adapters](#framework-adapters)**.
|
|
21
|
+
- **`@dignetwork/dig-sdk/dig-client`** — the read-crypto on its own (just `DigClient` + the loader +
|
|
22
|
+
URN helpers), for consumers that want only the read path (e.g. a worker). Same SRI-pinned wasm.
|
|
23
|
+
|
|
24
|
+
Ships **ESM + CJS + `.d.ts`**, runs in the **browser and Node 18+**, and is **eval-free** (usable
|
|
25
|
+
in CSP-strict contexts).
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm i @dignetwork/dig-sdk
|
|
29
|
+
# Optional: only if you use the WalletConnect → Sage fallback
|
|
30
|
+
npm i @walletconnect/sign-client
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Read verified, encrypted content in 5 lines
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { DigClient } from "@dignetwork/dig-sdk";
|
|
39
|
+
|
|
40
|
+
const dig = new DigClient(); // defaults to https://rpc.dig.net
|
|
41
|
+
const { bytes, decrypted, verified } = await dig.read({
|
|
42
|
+
urn: "urn:dig:chia:<storeId>/index.html", // the resource to read
|
|
43
|
+
root: "<onchain-root-hex>", // the trust anchor (from the chain)
|
|
44
|
+
});
|
|
45
|
+
console.log(decrypted, verified, new TextDecoder().decode(bytes));
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`read()` returns the authenticated **plaintext** when the URN key decrypts the served bytes
|
|
49
|
+
(`decrypted: true`); otherwise it returns the raw ciphertext (a decoy is just opaque bytes — the
|
|
50
|
+
model is oblivious, so a read is never a "not found" verdict). `verified` is the advisory
|
|
51
|
+
inclusion-proof check against `root`. For text, `await dig.readText({ urn, root })` returns the
|
|
52
|
+
decoded string (or throws if it didn't decrypt).
|
|
53
|
+
|
|
54
|
+
A private store adds a salt — either inline in the URN (`…/secret.txt?salt=<hex>`) or as
|
|
55
|
+
`dig.read({ urn, root, salt })`.
|
|
56
|
+
|
|
57
|
+
## Connect a wallet + sign
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { ChiaProvider } from "@dignetwork/dig-sdk";
|
|
61
|
+
|
|
62
|
+
// Prefers the injected DIG Browser wallet; falls back to WalletConnect → Sage.
|
|
63
|
+
const provider = await ChiaProvider.connect({
|
|
64
|
+
mode: "auto",
|
|
65
|
+
walletConnect: {
|
|
66
|
+
projectId: "<walletconnect-cloud-project-id>",
|
|
67
|
+
metadata: {
|
|
68
|
+
name: "My DIG dapp",
|
|
69
|
+
description: "Built with @dignetwork/dig-sdk",
|
|
70
|
+
url: "https://my-dapp.example",
|
|
71
|
+
icons: ["https://my-dapp.example/icon.png"],
|
|
72
|
+
},
|
|
73
|
+
onUri: (uri) => showWalletConnectQr(uri), // render the QR / copy-link for the fallback
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const address = await provider.getAddress();
|
|
78
|
+
const { publicKey, signature } = await provider.signMessage("Login to My DIG dapp");
|
|
79
|
+
// → verify the BLS signature server-side against the CHIP-0002 message hash + publicKey
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
If you only target the DIG Browser, drop `walletConnect` and use `mode: "injected"` (or `"auto"`,
|
|
83
|
+
which still prefers injected). `provider.backend` tells you which transport connected.
|
|
84
|
+
|
|
85
|
+
## Build + sign a store spend
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { ChiaProvider } from "@dignetwork/dig-sdk";
|
|
89
|
+
import * as spend from "@dignetwork/dig-sdk/spend"; // the canonical CHIP-0035 builder
|
|
90
|
+
|
|
91
|
+
spend.init();
|
|
92
|
+
// Build a spend bundle with the wasm builder (e.g. spend.mintStore(...) / spend.updateStoreMetadata(...)),
|
|
93
|
+
// then hand its coin spends to the wallet to sign:
|
|
94
|
+
const provider = await ChiaProvider.connect({ mode: "injected" });
|
|
95
|
+
const aggregatedSignature = await provider.signCoinSpends(/* coinSpends from the builder */ []);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The hub builds spend bundles in-browser via this wasm and pushes them to the wallet for signing —
|
|
99
|
+
your dapp does the same through the SDK.
|
|
100
|
+
|
|
101
|
+
## Charge for access (Paywall)
|
|
102
|
+
|
|
103
|
+
`Paywall` turns the monetization spends into a pay-to-unlock flow. It sources the buyer's coins from
|
|
104
|
+
the connected wallet, asks the wasm to build the payment, pushes those coin spends to the wallet to
|
|
105
|
+
sign, and hands you back a **receipt** — it never assembles a spend itself.
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import { ChiaProvider, Paywall } from "@dignetwork/dig-sdk";
|
|
109
|
+
|
|
110
|
+
const provider = await ChiaProvider.connect({ mode: "auto", walletConnect });
|
|
111
|
+
const paywall = new Paywall(provider); // chip35 monetization wasm is loaded lazily under a bundler
|
|
112
|
+
|
|
113
|
+
// Charge 0.25 XCH to unlock a resource (amount is mojos). `memo` derives a deterministic unlock nonce.
|
|
114
|
+
const { receipt, signature } = await paywall.requestPayment({
|
|
115
|
+
amount: 250_000_000_000n,
|
|
116
|
+
owner: dappOwnerPuzzleHashHex,
|
|
117
|
+
memo: `unlock:${resourceId}:${userId}`,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// …or charge a CAT (e.g. $DIG) by passing its tail hash:
|
|
121
|
+
await paywall.requestPayment({ amount: 100n, owner: dappOwnerPuzzleHashHex, assetId: digTailHashHex });
|
|
122
|
+
|
|
123
|
+
// Later, gate access by re-checking the on-chain payment against the receipt:
|
|
124
|
+
const { ok } = await paywall.verifyReceipt({
|
|
125
|
+
observed: observedPayment, // an ObservedPayment you filled in after reading the owner's coin
|
|
126
|
+
owner: dappOwnerPuzzleHashHex,
|
|
127
|
+
minAmount: 250_000_000_000n,
|
|
128
|
+
});
|
|
129
|
+
if (ok) grantAccess();
|
|
130
|
+
|
|
131
|
+
// Or gate on holding an NFT (or a collection membership) instead of a payment:
|
|
132
|
+
const access = await paywall.proveAccess({ parentSpend, owner, nft: nftLauncherIdHex });
|
|
133
|
+
// const access = await paywall.proveAccess({ parentSpend, owner, collection: creatorDidHex });
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
> No bundler? Pass the spend builder in yourself — `new Paywall(provider, { spends })`, where
|
|
137
|
+
> `spends` is `import * as spends from "@dignetwork/dig-sdk/spend"` (or the chip35 module). The
|
|
138
|
+
> builder is always the canonical wasm; the Paywall only orchestrates it.
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## API surface
|
|
143
|
+
|
|
144
|
+
### `ChiaProvider`
|
|
145
|
+
|
|
146
|
+
| Member | Description |
|
|
147
|
+
|---|---|
|
|
148
|
+
| `static connect(options)` | Connect a wallet. See **`ConnectOptions`** below. |
|
|
149
|
+
| `connectWallet(options)` | Convenience alias for `ChiaProvider.connect`. |
|
|
150
|
+
| `backend` / `session` | The connected transport (`"injected"` \| `"walletconnect"`) and session descriptor. |
|
|
151
|
+
| `getAddress()` | The wallet's receive address (cached). |
|
|
152
|
+
| `getPublicKeys()` | The wallet's synthetic public keys. |
|
|
153
|
+
| `signMessage(message, address?)` | Sign a UTF-8 message; returns `{ publicKey, signature }` (0x-normalized). |
|
|
154
|
+
| `signCoinSpends(coinSpends)` | Sign raw CHIP-0035 coin spends (partialSign); returns the aggregated signature hex. |
|
|
155
|
+
| `takeOffer(offer, fee?)` | Accept a Chia offer string (e.g. an NFT offer). |
|
|
156
|
+
| `getXchBalance()` / `getCatBalance(assetId)` | Spendable balances (mojo/base-unit strings). |
|
|
157
|
+
| `getXchCoins(limit?)` / `getCatCoins(assetId, limit?)` | Unspent coins for funding a spend. |
|
|
158
|
+
| `request(method, params?)` | Escape hatch: a raw CHIP-0002 request through the active transport. |
|
|
159
|
+
| `supports(method)` / `disconnect()` | Capability check / teardown. |
|
|
160
|
+
|
|
161
|
+
Transports are also exported directly (`InjectedTransport`, `WalletConnectTransport`,
|
|
162
|
+
`isInjectedAvailable`, `getInjectedProvider`) for advanced flows (e.g. restoring a WC session via
|
|
163
|
+
`WalletConnectTransport.restore(...)`).
|
|
164
|
+
|
|
165
|
+
#### `ConnectOptions`
|
|
166
|
+
|
|
167
|
+
| Field | Type | Default | Description |
|
|
168
|
+
|---|---|---|---|
|
|
169
|
+
| `mode` | `"auto"` \| `"injected"` \| `"walletconnect"` | `"auto"` | `"auto"` prefers the injected DIG wallet and falls back to WalletConnect; `"injected"` requires the injected wallet (throws `NO_INJECTED_WALLET` if absent); `"walletconnect"` forces WalletConnect→Sage (throws `WC_OPTIONS_REQUIRED` if `walletConnect` is omitted). |
|
|
170
|
+
| `walletConnect` | `WalletConnectOptions` | — | Required for the WalletConnect fallback/force path (`projectId`, `metadata`, `onUri`). Omit if you only target the injected DIG Browser wallet. |
|
|
171
|
+
| `chain` | `string` | `"chia:mainnet"` | CAIP-2 chain id. Mainnet only — there is no testnet flow. |
|
|
172
|
+
| `acceptAnyInjected` | `boolean` | `false` | Accept any `window.chia` for the injected path, not just the DIG Browser's unspoofable `isDIG` provider. Use with care — a non-DIG provider is not feature-detected. |
|
|
173
|
+
|
|
174
|
+
### `DigClient`
|
|
175
|
+
|
|
176
|
+
| Member | Description |
|
|
177
|
+
|---|---|
|
|
178
|
+
| `new DigClient({ rpc?, fetch? })` | RPC defaults to `https://rpc.dig.net`. |
|
|
179
|
+
| `read({ urn, root?, salt? }, opts?)` | Fetch + verify + decrypt → `{ bytes, verified, decrypted, … }`. |
|
|
180
|
+
| `readText({ urn, root?, salt? }, opts?)` | As `read`, decoded to a UTF-8 string (throws if not decrypted). |
|
|
181
|
+
| `readResource({ storeId, resourceKey, root, salt? }, opts?)` | Read by explicit parts instead of a URN. |
|
|
182
|
+
| `deriveUrnKeys({ urn, salt? })` | The root-independent `{ retrievalKey, decryptionKey }` for a URN. |
|
|
183
|
+
| `retrievalKey(storeId, key)` / `deriveKey(storeId, key, salt?)` | The individual derivations. |
|
|
184
|
+
| `verifyInclusion(ciphertext, proof, root)` / `reconstructUrn(...)` | Lower-level read-crypto. |
|
|
185
|
+
| `getCollection({ launcherIds, did? }, opts?)` | Public NFT-collection facts → `{ did, declared_did, item_count, resolved_count, royalty_basis_points }`. |
|
|
186
|
+
| `listCollectionItems({ launcherIds, offset?, limit? }, opts?)` | A page of items resolved to their CURRENT on-chain owner + royalty + CHIP-0007 metadata → `{ items, offset, limit, total, next_offset }`. |
|
|
187
|
+
| `wasm()` | The raw SRI-verified read-crypto wasm (`decryptChunk`, `encryptResource`, `version`, …). |
|
|
188
|
+
|
|
189
|
+
### `Paywall`
|
|
190
|
+
|
|
191
|
+
| Member | Description |
|
|
192
|
+
|---|---|
|
|
193
|
+
| `new Paywall(provider, { spends? })` | Wrap a connected `ChiaProvider`. `spends` defaults to a lazy `import("@dignetwork/chip35-dl-coin-wasm")` (pass it for non-bundler runtimes). |
|
|
194
|
+
| `requestPayment({ amount, owner, assetId?, memo?, nonce?, fee?, coinLimit? })` | Build the payment via the wasm (`buildPayment` XCH / `buildCatPayment` CAT) and push it to the wallet to sign. Returns `{ signature, receipt, coinSpends, nonce }`. |
|
|
195
|
+
| `verifyReceipt({ observed, owner, minAmount, asset?, nonce? })` | Verify an observed on-chain payment unlocks the paywall (wasm `verifyPaymentReceipt`). Returns `{ ok, error? }`. |
|
|
196
|
+
| `proveAccess({ parentSpend, owner, nft? \| collection? })` | Prove NFT ownership (`proveNftOwnership`) or collection membership (`proveCollectionMembership`). Returns `{ ok, proof?, error? }`. |
|
|
197
|
+
|
|
198
|
+
`amount` / `minAmount` / `fee` accept a `number` or `bigint`; hashes/ids/nonces are hex (with or
|
|
199
|
+
without `0x`). The Paywall holds **no** spend-assembly logic — if the canonical wasm builder is
|
|
200
|
+
unavailable it throws rather than fabricate a spend.
|
|
201
|
+
|
|
202
|
+
### URN helpers (pure)
|
|
203
|
+
|
|
204
|
+
`parseUrn`, `isUrn`, `reconstructUrn`, `reconstructUrnWithRoot` and the `ParsedUrn` type — the same
|
|
205
|
+
URN grammar the hub, extension, and companion use.
|
|
206
|
+
|
|
207
|
+
### Spend builder
|
|
208
|
+
|
|
209
|
+
`import * as spend from "@dignetwork/dig-sdk/spend"` re-exports
|
|
210
|
+
[`@dignetwork/chip35-dl-coin-wasm`](https://www.npmjs.com/package/@dignetwork/chip35-dl-coin-wasm)
|
|
211
|
+
(≥ 0.7.0): store coins (`mintStore`, `meltStore`, `updateStoreMetadata`, `updateStoreOwnership`,
|
|
212
|
+
`oracleSpend`), assets (`mintNft`, `bulkMint`, `createDid`, `issueCat`), CHIP-0007 metadata
|
|
213
|
+
(`buildChip0007Metadata`, `validateChip0007`, `generateItemMetadata`), offers (`encodeOffer`,
|
|
214
|
+
`decodeOffer`), monetization (`buildPayment`, `buildCatPayment`, `paymentNonce`,
|
|
215
|
+
`verifyPaymentReceipt`, `proveNftOwnership`, `proveCollectionMembership` — these back the
|
|
216
|
+
[`Paywall`](#paywall) helper), and helpers (`addFee`, `dataStoreFromSpend`,
|
|
217
|
+
`hexSpendBundleToCoinSpends`, `spendBundleToHex`, `digstoreOwnerHint`, `sha256`, `init`).
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## Framework adapters
|
|
222
|
+
|
|
223
|
+
Make DIG a first-class deploy target for the frameworks you already use. Each adapter does two
|
|
224
|
+
things: injects a **`window.chia` dev wallet** during local `dev` (the same injected-provider
|
|
225
|
+
contract `ChiaProvider` detects in production, so the wallet path runs end-to-end locally), and
|
|
226
|
+
ships your build to a **DIG capsule** via `digstore deploy --json` on a `publish` script.
|
|
227
|
+
|
|
228
|
+
> Deploying **spends $DIG** (each deploy publishes a new capsule), so it is a deliberate, credentialed
|
|
229
|
+
> step — never wired into the default `build`. Config + secrets are read from your project's
|
|
230
|
+
> `dig.toml` and `DIGSTORE_*` env vars, exactly like `digstore deploy`; the deploy key and store
|
|
231
|
+
> salt come from the env only (never argv) so they don't leak. Requires the `digstore` CLI on PATH.
|
|
232
|
+
|
|
233
|
+
### Vite — `@dignetwork/dig-sdk/vite`
|
|
234
|
+
|
|
235
|
+
```ts
|
|
236
|
+
// vite.config.ts
|
|
237
|
+
import { defineConfig } from "vite";
|
|
238
|
+
import { digVite } from "@dignetwork/dig-sdk/vite";
|
|
239
|
+
|
|
240
|
+
export default defineConfig({
|
|
241
|
+
plugins: [digVite()], // injects the window.chia dev shim during `vite dev`
|
|
242
|
+
});
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
```jsonc
|
|
246
|
+
// package.json — opt in to deploy with a publish script (after the build)
|
|
247
|
+
{
|
|
248
|
+
"scripts": {
|
|
249
|
+
"publish:dig": "vite build && node -e \"import('@dignetwork/dig-sdk/vite').then(m => m.digDeploy())\""
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
`digDeploy()` shells out to `digstore deploy --json`, ships the build dir to a new capsule, and
|
|
255
|
+
prints the `chia://` content-open address + the `https://hub.dig.net/stores/<id>` DIGHUb view URL
|
|
256
|
+
(`result.chiaUrl` / `result.hubUrl`; `result.digUrl` is a deprecated alias of `chiaUrl`). Disable the dev shim with
|
|
257
|
+
`digVite({ devWallet: false })`; set its mock address with `digVite({ devWalletOptions: { address } })`.
|
|
258
|
+
|
|
259
|
+
### Next.js (static export) — `@dignetwork/dig-sdk/next`
|
|
260
|
+
|
|
261
|
+
Next has no Vite-style HTML hook, so the dev shim is a helper you drop into your `<head>` (guarded to
|
|
262
|
+
dev), and `digDeploy()` ships the `out/` static export:
|
|
263
|
+
|
|
264
|
+
```tsx
|
|
265
|
+
// app/layout.tsx — dev-only window.chia shim
|
|
266
|
+
import { digNextDevShimTag } from "@dignetwork/dig-sdk/next";
|
|
267
|
+
|
|
268
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
269
|
+
return (
|
|
270
|
+
<html>
|
|
271
|
+
<head>
|
|
272
|
+
{process.env.NODE_ENV !== "production" && (
|
|
273
|
+
<script dangerouslySetInnerHTML={{ __html: digNextDevShimTag().replace(/^<script>|<\/script>$/g, "") }} />
|
|
274
|
+
)}
|
|
275
|
+
</head>
|
|
276
|
+
<body>{children}</body>
|
|
277
|
+
</html>
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
```jsonc
|
|
283
|
+
// package.json — deploy the static export (next.config: `output: "export"`)
|
|
284
|
+
{
|
|
285
|
+
"scripts": {
|
|
286
|
+
"publish:dig": "next build && node -e \"import('@dignetwork/dig-sdk/next').then(m => m.digDeploy())\""
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
`digDeploy()` defaults the output dir to `out` (Next's export dir); override any field via
|
|
292
|
+
`digDeploy({ outputDir, storeId, message, … })` or `dig.toml`.
|
|
293
|
+
|
|
294
|
+
### Configuration
|
|
295
|
+
|
|
296
|
+
Both adapters resolve config with this precedence: **`digDeploy()` options > `DIGSTORE_*` env >
|
|
297
|
+
`dig.toml` > defaults** (mirroring `digstore deploy`). Common keys: `store-id`, `output-dir`,
|
|
298
|
+
`message`, `network`, `remote` (in `dig.toml`); secrets `DIGSTORE_DEPLOY_KEY` and (private stores)
|
|
299
|
+
`DIGSTORE_STORE_SALT` from the env. The pure building blocks (config resolution, deploy-arg
|
|
300
|
+
construction, the dev-shim string, the `dig.toml` reader) are exported from
|
|
301
|
+
`@dignetwork/dig-sdk/adapters` if you want to compose your own deploy step.
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## Machine-readable surface (for agents)
|
|
306
|
+
|
|
307
|
+
The SDK is self-describing: an agent can introspect its version, modules, methods, chains, and the
|
|
308
|
+
full error catalogue without reading source, and every failure carries a stable machine code.
|
|
309
|
+
|
|
310
|
+
### Capabilities & version
|
|
311
|
+
|
|
312
|
+
```ts
|
|
313
|
+
import { SDK_VERSION, capabilities } from "@dignetwork/dig-sdk";
|
|
314
|
+
|
|
315
|
+
SDK_VERSION; // "0.2.0" — the published version, injected from package.json at build time
|
|
316
|
+
capabilities(); // (alias: describe()) the machine-readable surface ↓
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
`capabilities()` (and its alias `describe()`) returns:
|
|
320
|
+
|
|
321
|
+
| Field | Type | Description |
|
|
322
|
+
|---|---|---|
|
|
323
|
+
| `name` | `string` | `"@dignetwork/dig-sdk"`. |
|
|
324
|
+
| `version` | `string` | `SDK_VERSION`. |
|
|
325
|
+
| `modules` | `{ name, summary, entry }[]` | The pillars: `ChiaProvider`, `DigClient`, `Paywall`, `spend`, `adapters` (each with its import `entry`). |
|
|
326
|
+
| `walletMethods` | `string[]` | The canonical CHIP-0002 method surface both transports negotiate. |
|
|
327
|
+
| `signMethods` | `string[]` | Message-signing methods, in preference order. |
|
|
328
|
+
| `transports` | `("injected" \| "walletconnect")[]` | The wallet transports. |
|
|
329
|
+
| `chains` | `string[]` | CAIP-2 chains — `["chia:mainnet"]` (no testnet flow). |
|
|
330
|
+
| `defaultRpc` | `string` | The default dig RPC endpoint `DigClient` reads from. |
|
|
331
|
+
| `readCryptoWasmSha256` | `string` | SRI digest of the vendored read-crypto wasm (fail-closed on mismatch). |
|
|
332
|
+
| `errorCodes` | `string[]` | The full stable error-code catalogue (see below). |
|
|
333
|
+
|
|
334
|
+
### Error codes
|
|
335
|
+
|
|
336
|
+
Every failure the SDK surfaces is a **`DigSdkError`** (an `Error` subclass) with a stable, documented
|
|
337
|
+
`.code` (UPPER_SNAKE) plus structured `.context`. Branch on `err.code` (or the `isDigSdkError(err, code)`
|
|
338
|
+
type guard) — never on the human `.message`.
|
|
339
|
+
|
|
340
|
+
```ts
|
|
341
|
+
import { DigClient, DigSdkError, isDigSdkError } from "@dignetwork/dig-sdk";
|
|
342
|
+
|
|
343
|
+
try {
|
|
344
|
+
await new DigClient().read({ urn });
|
|
345
|
+
} catch (e) {
|
|
346
|
+
if (isDigSdkError(e, "ROOT_REQUIRED")) promptForRoot();
|
|
347
|
+
else if (isDigSdkError(e, "RPC_TRANSPORT")) retryLater();
|
|
348
|
+
else throw e;
|
|
349
|
+
}
|
|
350
|
+
// DigSdkError also has .toJSON() → { code, message, context }
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
The catalogue is exported as the typed `DIG_SDK_ERROR_CODES` const (and the `DigSdkErrorCode` union),
|
|
354
|
+
and is also returned by `capabilities().errorCodes`:
|
|
355
|
+
|
|
356
|
+
| Code | Thrown when | Key context fields |
|
|
357
|
+
|---|---|---|
|
|
358
|
+
| `WC_OPTIONS_REQUIRED` | WalletConnect was needed but no `walletConnect` options were given. | `mode` |
|
|
359
|
+
| `NO_INJECTED_WALLET` | `mode:"injected"` (or the injected leg of `auto`) found no usable `window.chia`. | `mode`, `acceptAnyInjected` |
|
|
360
|
+
| `WC_DEPENDENCY_MISSING` | The optional `@walletconnect/sign-client` peer dep is not installed. | — |
|
|
361
|
+
| `METHOD_NOT_SUPPORTED` | The active session/transport does not grant the requested method. | `method` |
|
|
362
|
+
| `WALLET_TIMEOUT` | A wallet RPC timed out (e.g. Sage did not respond). | `method`, `timeoutMs` |
|
|
363
|
+
| `WALLET_NO_KEYS` | The wallet returned no public keys / no key to sign with. | — |
|
|
364
|
+
| `ROOT_REQUIRED` | A content read needs a confirmed on-chain root and none was supplied. | `urn` |
|
|
365
|
+
| `DECRYPT_FAILED` | The resource did not decrypt under this URN (wrong key/salt, or a decoy). | `urn` |
|
|
366
|
+
| `RPC_TRANSPORT` | The dig RPC could not be reached (network/transport failure). | `rpcMethod` |
|
|
367
|
+
| `RPC_ERROR` | The dig RPC returned an HTTP error or a JSON-RPC `error`. | `rpcMethod`, `httpStatus`, `rpcCode` |
|
|
368
|
+
| `RPC_MALFORMED_RESPONSE` | The dig RPC returned a malformed/inconsistent payload. | `rpcMethod` |
|
|
369
|
+
| `WASM_INTEGRITY` | The read-crypto wasm failed its SRI check — fail closed. | `expected`, `actual` |
|
|
370
|
+
| `WASM_LOAD_FAILED` | The read-crypto wasm could not be loaded. | `httpStatus`, `wasmUrl` |
|
|
371
|
+
| `SPEND_BUILDER_UNAVAILABLE` | The canonical chip35 wasm builder for the operation is unavailable (never hand-rolled). | `builder` |
|
|
372
|
+
| `NO_SECURE_RANDOM` | No secure random source to generate a payment nonce. | — |
|
|
373
|
+
| `DIGSTORE_NOT_FOUND` | The `digstore` binary could not be spawned (not installed / not on PATH). | `bin` |
|
|
374
|
+
| `DEPLOY_FAILED` | `digstore deploy` exited non-zero. | `exitCode`, `stderr` |
|
|
375
|
+
| `DEPLOY_OUTPUT_UNPARSEABLE` | `digstore deploy --json` output could not be parsed into a capsule. | `stdout` |
|
|
376
|
+
| `INVALID_ARGUMENT` | A malformed argument (non-hex, bad URN, mutually-exclusive options, malformed capsule). | `value`, `expected` |
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
## Key concepts
|
|
381
|
+
|
|
382
|
+
- **URN** — `urn:dig:chia:<storeId>[:<root>]/<resourceKey>[?salt=<hex>]` addresses one resource in
|
|
383
|
+
a store. The retrieval + decryption keys are **root-independent** (the root is only the trust
|
|
384
|
+
anchor for verification).
|
|
385
|
+
- **Oblivious / blind host** — the dig RPC returns indistinguishable ciphertext for any retrieval
|
|
386
|
+
key, so presence is unknowable. The client decrypts what it can; it never asks the host "is this
|
|
387
|
+
present?".
|
|
388
|
+
- **Trust anchor** — content is verified against an **on-chain root** that *you* resolve from the
|
|
389
|
+
chain (coinset.org / the store singleton) and pass to `read({ root })`. The serving host can
|
|
390
|
+
never be the trust anchor.
|
|
391
|
+
|
|
392
|
+
## Read-crypto wasm provenance
|
|
393
|
+
|
|
394
|
+
`DigClient` runs the **same** `dig_client` read-crypto WASM the DIG Browser, the
|
|
395
|
+
`dig-chrome-extension`, the `dig-companion`, and `hub.dig.net` use. It is vendored under `vendor/`,
|
|
396
|
+
pinned by SHA-256 (`ff486be8…`), and **SRI-verified at load** — a tampered or wrong artifact
|
|
397
|
+
**fails closed** rather than running unverified crypto. See `vendor/PROVENANCE.md`.
|
|
398
|
+
|
|
399
|
+
### CSP-strict / no-bundler browsers
|
|
400
|
+
|
|
401
|
+
The wasm is loaded lazily; in a bundler that resolves package files it is found automatically. If
|
|
402
|
+
your environment can't resolve the vendored files (or your CSP blocks runtime fetches), fetch +
|
|
403
|
+
verify the bytes yourself and hand them in **before** the first read:
|
|
404
|
+
|
|
405
|
+
```ts
|
|
406
|
+
import { configureWasm } from "@dignetwork/dig-sdk";
|
|
407
|
+
configureWasm({ wasmBytes: myVerifiedBytes, glueUrl: "/dig-client/dig_client.mjs" });
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
## License
|
|
411
|
+
|
|
412
|
+
MIT
|