@dignetwork/dig-sdk 0.1.0 → 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/README.md +151 -6
- package/dist/adapters.cjs +56 -15
- package/dist/adapters.cjs.map +1 -1
- package/dist/adapters.d.cts +2 -2
- package/dist/adapters.d.ts +2 -2
- package/dist/adapters.js +56 -15
- package/dist/adapters.js.map +1 -1
- package/dist/{dev-shim-Bgw8X2E9.d.cts → dev-shim-DfKRA1ok.d.cts} +13 -3
- package/dist/{dev-shim-Bgw8X2E9.d.ts → dev-shim-DfKRA1ok.d.ts} +13 -3
- package/dist/{dig-client-entry-BIzuZ7Rs.d.cts → dig-client-entry-ChYxUvBn.d.cts} +110 -1
- package/dist/{dig-client-entry-BIzuZ7Rs.d.ts → dig-client-entry-ChYxUvBn.d.ts} +110 -1
- package/dist/dig-client.cjs +130 -17
- package/dist/dig-client.cjs.map +1 -1
- package/dist/dig-client.d.cts +1 -1
- package/dist/dig-client.d.ts +1 -1
- package/dist/dig-client.js +130 -17
- package/dist/dig-client.js.map +1 -1
- package/dist/index.cjs +462 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +313 -3
- package/dist/index.d.ts +313 -3
- package/dist/index.js +456 -31
- package/dist/index.js.map +1 -1
- package/dist/next.cjs +58 -15
- package/dist/next.cjs.map +1 -1
- package/dist/next.d.cts +1 -1
- package/dist/next.d.ts +1 -1
- package/dist/next.js +58 -15
- package/dist/next.js.map +1 -1
- package/dist/vite.cjs +58 -15
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +58 -15
- package/dist/vite.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { W as WalletBackend, a as WalletSession, S as SignResult, I as InjectedChiaProvider } from './dig-client-entry-
|
|
2
|
-
export { D as DEFAULT_RPC,
|
|
1
|
+
import { W as WalletBackend, a as WalletSession, S as SignResult, I as InjectedChiaProvider } from './dig-client-entry-ChYxUvBn.cjs';
|
|
2
|
+
export { C as CollectionItem, b as CollectionItemMetadata, c as CollectionItemsPage, d as CollectionMeta, D as DEFAULT_RPC, e as DIG_CLIENT_WASM_SHA256, f as DigClient, g as DigClientOptions, h as DigClientWasm, P as ParsedUrn, R as ReadOptions, i as ReadResult, U as UrnKeys, j as WasmConfig, k as configureWasm, l as isUrn, m as loadDigClientWasm, p as parseUrn, r as reconstructUrn, n as reconstructUrnWithRoot } from './dig-client-entry-ChYxUvBn.cjs';
|
|
3
3
|
|
|
4
4
|
/** A wallet transport: connect, then `request` CHIP-0002 methods through it. */
|
|
5
5
|
interface WalletTransport {
|
|
@@ -175,6 +175,176 @@ declare class InjectedTransport implements WalletTransport {
|
|
|
175
175
|
/** True iff `err` looks like a transient relay-publish failure (request never reached the wallet). */
|
|
176
176
|
declare function isTransientPublishError(err: unknown): boolean;
|
|
177
177
|
|
|
178
|
+
/** A payment asset: XCH, or a CAT identified by its tail hash (e.g. $DIG). */
|
|
179
|
+
type PaymentAssetSpec = {
|
|
180
|
+
xch: true;
|
|
181
|
+
assetId?: undefined;
|
|
182
|
+
} | {
|
|
183
|
+
xch?: false;
|
|
184
|
+
assetId: string;
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* The subset of `@dignetwork/chip35-dl-coin-wasm` the Paywall drives. The full wasm module satisfies
|
|
188
|
+
* this shape, so `import("@dignetwork/chip35-dl-coin-wasm")` (or the SDK's "./spend" re-export) can
|
|
189
|
+
* be passed directly. Declared as a structural type so the SDK does not statically import the
|
|
190
|
+
* (bundler-only) wasm and tests can inject a spy.
|
|
191
|
+
*/
|
|
192
|
+
interface MonetizationSpends {
|
|
193
|
+
/** wasm-bindgen init. Called once before building spends (a no-op if the runtime needs none). */
|
|
194
|
+
init?: () => unknown;
|
|
195
|
+
/** SHA-256-derive a 32-byte unlock nonce from request bytes. */
|
|
196
|
+
paymentNonce?: (requestBytes: Uint8Array) => Uint8Array;
|
|
197
|
+
/** Build the coin spends for an XCH payment. Returns `{ coinSpends, receipt }`. */
|
|
198
|
+
buildPayment?: (buyerSyntheticKey: Uint8Array, selectedCoins: unknown, ownerPuzzleHash: Uint8Array, amount: bigint, nonce: Uint8Array, fee: bigint) => {
|
|
199
|
+
coinSpends: unknown;
|
|
200
|
+
receipt: unknown;
|
|
201
|
+
};
|
|
202
|
+
/** Build the coin spends for a CAT (incl. DIG) payment. Returns `{ coinSpends, receipt }`. */
|
|
203
|
+
buildCatPayment?: (buyerSyntheticKey: Uint8Array, selectedCats: unknown, ownerPuzzleHash: Uint8Array, amount: bigint, nonce: Uint8Array) => {
|
|
204
|
+
coinSpends: unknown;
|
|
205
|
+
receipt: unknown;
|
|
206
|
+
};
|
|
207
|
+
/** Verify an observed payment unlocks the paywall. Returns `{ ok, error? }`. */
|
|
208
|
+
verifyPaymentReceipt?: (observed: unknown, ownerPuzzleHash: Uint8Array, minAmount: bigint, requiredAsset: unknown, requireNonce?: Uint8Array | null) => {
|
|
209
|
+
ok: boolean;
|
|
210
|
+
error?: string;
|
|
211
|
+
};
|
|
212
|
+
/** Prove NFT ownership (optionally gating on a launcher id). Returns `{ ok, proof?, error? }`. */
|
|
213
|
+
proveNftOwnership?: (parentSpend: unknown, claimedOwnerPuzzleHash: Uint8Array, requiredNft?: Uint8Array | null) => {
|
|
214
|
+
ok: boolean;
|
|
215
|
+
proof?: unknown;
|
|
216
|
+
error?: string;
|
|
217
|
+
};
|
|
218
|
+
/** Prove collection/creator membership for an owner. Returns `{ ok, proof?, error? }`. */
|
|
219
|
+
proveCollectionMembership?: (parentSpend: unknown, claimedOwnerPuzzleHash: Uint8Array, requiredDid: Uint8Array) => {
|
|
220
|
+
ok: boolean;
|
|
221
|
+
proof?: unknown;
|
|
222
|
+
error?: string;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/** Options for constructing a `Paywall`. */
|
|
226
|
+
interface PaywallOptions {
|
|
227
|
+
/**
|
|
228
|
+
* The canonical chip35 monetization spends. Defaults to a lazy
|
|
229
|
+
* `import("@dignetwork/chip35-dl-coin-wasm")` (and calls its `init()`), so a bundled dapp needs to
|
|
230
|
+
* pass nothing. Inject a builder for non-bundler runtimes or tests.
|
|
231
|
+
*/
|
|
232
|
+
spends?: MonetizationSpends;
|
|
233
|
+
}
|
|
234
|
+
/** Arguments for `Paywall.requestPayment`. */
|
|
235
|
+
interface RequestPaymentArgs {
|
|
236
|
+
/** Amount to pay, in mojos (XCH) or base units (CAT). Number or bigint. */
|
|
237
|
+
amount: number | bigint;
|
|
238
|
+
/** The dapp owner's puzzle hash to pay (hex, with or without `0x`). */
|
|
239
|
+
owner: string;
|
|
240
|
+
/** Pay in this CAT (tail hash hex). Omit for XCH. */
|
|
241
|
+
assetId?: string;
|
|
242
|
+
/**
|
|
243
|
+
* A free-form unlock identifier (e.g. `dappId|resource|user`). When given without an explicit
|
|
244
|
+
* `nonce`, the Paywall derives the 32-byte nonce from it via the wasm `paymentNonce` (deterministic
|
|
245
|
+
* convenience). Ignored when `nonce` is supplied.
|
|
246
|
+
*/
|
|
247
|
+
memo?: string;
|
|
248
|
+
/** An explicit 32-byte unlock nonce (hex). Overrides `memo`. Random 32 bytes are used if neither. */
|
|
249
|
+
nonce?: string;
|
|
250
|
+
/** Network fee in mojos (XCH payments only; CAT rings net to zero). Defaults to 0. */
|
|
251
|
+
fee?: number | bigint;
|
|
252
|
+
/** Cap on the number of buyer coins to source from the wallet. */
|
|
253
|
+
coinLimit?: number;
|
|
254
|
+
}
|
|
255
|
+
/** The result of a successful `requestPayment`: the wallet signature + the wasm receipt + spends. */
|
|
256
|
+
interface PaymentResult {
|
|
257
|
+
/** The aggregated BLS signature the wallet returned for the coin spends. */
|
|
258
|
+
signature: string;
|
|
259
|
+
/** The `PaymentReceipt` the wasm produced — persist it; `verifyReceipt` later checks the chain. */
|
|
260
|
+
receipt: unknown;
|
|
261
|
+
/** The exact coin spends the wasm built and the wallet signed. */
|
|
262
|
+
coinSpends: unknown;
|
|
263
|
+
/** The 32-byte unlock nonce embedded in the payment (hex). */
|
|
264
|
+
nonce: string;
|
|
265
|
+
}
|
|
266
|
+
/** Arguments for `Paywall.verifyReceipt`. */
|
|
267
|
+
interface VerifyReceiptArgs {
|
|
268
|
+
/** The `ObservedPayment` the dapp filled in after reading the owner's coin from the chain. */
|
|
269
|
+
observed: unknown;
|
|
270
|
+
/** The owner puzzle hash that must have been paid (hex). */
|
|
271
|
+
owner: string;
|
|
272
|
+
/** The minimum amount that must have been paid (mojos / base units). */
|
|
273
|
+
minAmount: number | bigint;
|
|
274
|
+
/** The required asset. Defaults to XCH; pass `{ assetId }` to require a CAT. */
|
|
275
|
+
asset?: PaymentAssetSpec;
|
|
276
|
+
/** Require this exact 32-byte nonce (hex) to be present in the payment. */
|
|
277
|
+
nonce?: string;
|
|
278
|
+
}
|
|
279
|
+
/** Arguments for `Paywall.proveAccess` — gate on NFT ownership XOR collection membership. */
|
|
280
|
+
interface ProveAccessArgs {
|
|
281
|
+
/** The coin spend that created the NFT's current coin (the wasm `CoinSpend` shape). */
|
|
282
|
+
parentSpend: unknown;
|
|
283
|
+
/** The puzzle hash claiming ownership (hex). */
|
|
284
|
+
owner: string;
|
|
285
|
+
/** Gate on this specific NFT launcher id (hex). Mutually exclusive with `collection`. */
|
|
286
|
+
nft?: string;
|
|
287
|
+
/** Gate on membership of this collection/creator DID (hex). Mutually exclusive with `nft`. */
|
|
288
|
+
collection?: string;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* High-level pay-to-unlock helper. Construct it from a connected `ChiaProvider`; it builds payment
|
|
292
|
+
* spends via the canonical chip35 wasm and pushes them to the wallet for signing.
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* const provider = await ChiaProvider.connect({ mode: "auto", walletConnect });
|
|
296
|
+
* const paywall = new Paywall(provider); // chip35 wasm loaded lazily under a bundler
|
|
297
|
+
* // Charge 0.25 XCH to unlock a resource:
|
|
298
|
+
* const { receipt } = await paywall.requestPayment({
|
|
299
|
+
* amount: 250_000_000_000n,
|
|
300
|
+
* owner: dappOwnerPuzzleHashHex,
|
|
301
|
+
* memo: `unlock:${resourceId}:${userId}`,
|
|
302
|
+
* });
|
|
303
|
+
* // Later, gate access by re-checking the receipt against the chain:
|
|
304
|
+
* const { ok } = await paywall.verifyReceipt({ observed, owner: dappOwnerPuzzleHashHex, minAmount: 250_000_000_000n });
|
|
305
|
+
*/
|
|
306
|
+
declare class Paywall {
|
|
307
|
+
private readonly provider;
|
|
308
|
+
private readonly injectedSpends?;
|
|
309
|
+
private spendsReady?;
|
|
310
|
+
constructor(provider: ChiaProvider, options?: PaywallOptions);
|
|
311
|
+
/**
|
|
312
|
+
* Resolve the canonical monetization spends (injected, or lazily imported + `init()`ed). Memoized.
|
|
313
|
+
* This is the ONLY source of coin-spend construction in the Paywall — there is no fallback that
|
|
314
|
+
* hand-rolls a spend.
|
|
315
|
+
*/
|
|
316
|
+
private spends;
|
|
317
|
+
/** The wallet's first synthetic public key, as bytes (the buyer key the spends are built against). */
|
|
318
|
+
private buyerKey;
|
|
319
|
+
/** Resolve the 32-byte unlock nonce: explicit hex, else derived from `memo`, else random. */
|
|
320
|
+
private resolveNonce;
|
|
321
|
+
/**
|
|
322
|
+
* Charge the buyer (the connected wallet) `amount` to pay the dapp `owner`, then push the
|
|
323
|
+
* wasm-built coin spends to the wallet for signing. Returns the wallet signature + the receipt.
|
|
324
|
+
* Builds via the canonical wasm `buildPayment` (XCH) or `buildCatPayment` (CAT) — never hand-rolled.
|
|
325
|
+
*/
|
|
326
|
+
requestPayment(args: RequestPaymentArgs): Promise<PaymentResult>;
|
|
327
|
+
/**
|
|
328
|
+
* Verify an observed on-chain payment unlocks the paywall (pay-to-unlock). Delegates to the wasm
|
|
329
|
+
* `verifyPaymentReceipt`; returns its `{ ok, error? }` verdict. `ok:true` grants access.
|
|
330
|
+
*/
|
|
331
|
+
verifyReceipt(args: VerifyReceiptArgs): Promise<{
|
|
332
|
+
ok: boolean;
|
|
333
|
+
error?: string;
|
|
334
|
+
}>;
|
|
335
|
+
/**
|
|
336
|
+
* Prove the `owner` holds access: gate on a specific NFT (`nft` launcher id) via the wasm
|
|
337
|
+
* `proveNftOwnership`, or on collection/creator membership (`collection` DID) via
|
|
338
|
+
* `proveCollectionMembership`. Returns `{ ok, proof?, error? }`. The caller still confirms the
|
|
339
|
+
* proof's coin is unspent on-chain for liveness.
|
|
340
|
+
*/
|
|
341
|
+
proveAccess(args: ProveAccessArgs): Promise<{
|
|
342
|
+
ok: boolean;
|
|
343
|
+
proof?: unknown;
|
|
344
|
+
error?: string;
|
|
345
|
+
}>;
|
|
346
|
+
}
|
|
347
|
+
|
|
178
348
|
/** The canonical CHIP-0002 / chia method names the SDK negotiates with the wallet. */
|
|
179
349
|
declare const WALLET_METHODS: readonly ["chip0002_connect", "chip0002_chainId", "chip0002_getPublicKeys", "chip0002_getAssetCoins", "chip0002_getAssetBalance", "chip0002_signCoinSpends", "chip0002_signMessage", "chia_getAddress", "chia_signMessageByAddress", "chia_takeOffer"];
|
|
180
350
|
/** Union of the canonical wallet method names. */
|
|
@@ -189,4 +359,144 @@ declare const SIGN_METHODS: readonly ["chia_signMessageByAddress", "chip0002_sig
|
|
|
189
359
|
/** Default Chia chain id (CAIP-2). Mainnet — there is no testnet flow. */
|
|
190
360
|
declare const DEFAULT_CHAIN = "chia:mainnet";
|
|
191
361
|
|
|
192
|
-
|
|
362
|
+
/**
|
|
363
|
+
* The stable error-code catalogue. Each value is an UPPER_SNAKE symbolic string that callers may
|
|
364
|
+
* branch on. Frozen so it can't be mutated at runtime; the README documents each meaning.
|
|
365
|
+
*/
|
|
366
|
+
declare const DIG_SDK_ERROR_CODES: Readonly<{
|
|
367
|
+
/** WalletConnect was requested/needed but no `walletConnect` options were supplied. */
|
|
368
|
+
readonly WC_OPTIONS_REQUIRED: "WC_OPTIONS_REQUIRED";
|
|
369
|
+
/** `mode: "injected"` (or the injected leg of `auto`) found no usable `window.chia`. */
|
|
370
|
+
readonly NO_INJECTED_WALLET: "NO_INJECTED_WALLET";
|
|
371
|
+
/** The optional `@walletconnect/sign-client` peer dependency is not installed/usable. */
|
|
372
|
+
readonly WC_DEPENDENCY_MISSING: "WC_DEPENDENCY_MISSING";
|
|
373
|
+
/** The active wallet session/transport does not grant the requested method. */
|
|
374
|
+
readonly METHOD_NOT_SUPPORTED: "METHOD_NOT_SUPPORTED";
|
|
375
|
+
/** A wallet RPC timed out (e.g. Sage did not respond within the per-request timeout). */
|
|
376
|
+
readonly WALLET_TIMEOUT: "WALLET_TIMEOUT";
|
|
377
|
+
/** The wallet returned no public keys / no key to sign with. */
|
|
378
|
+
readonly WALLET_NO_KEYS: "WALLET_NO_KEYS";
|
|
379
|
+
/** A content read needs a confirmed on-chain root and none was supplied/derivable. */
|
|
380
|
+
readonly ROOT_REQUIRED: "ROOT_REQUIRED";
|
|
381
|
+
/** The resource did not decrypt+authenticate under this URN (wrong key/salt, or a decoy). */
|
|
382
|
+
readonly DECRYPT_FAILED: "DECRYPT_FAILED";
|
|
383
|
+
/** The dig RPC could not be reached (network/transport failure). */
|
|
384
|
+
readonly RPC_TRANSPORT: "RPC_TRANSPORT";
|
|
385
|
+
/** The dig RPC responded with an HTTP error or a JSON-RPC `error` object. */
|
|
386
|
+
readonly RPC_ERROR: "RPC_ERROR";
|
|
387
|
+
/** The dig RPC returned a malformed / inconsistent payload (e.g. chunk-length mismatch). */
|
|
388
|
+
readonly RPC_MALFORMED_RESPONSE: "RPC_MALFORMED_RESPONSE";
|
|
389
|
+
/** The vendored read-crypto wasm failed its SRI integrity check — fail closed. */
|
|
390
|
+
readonly WASM_INTEGRITY: "WASM_INTEGRITY";
|
|
391
|
+
/** The read-crypto wasm could not be loaded (fetch/resolve failure). */
|
|
392
|
+
readonly WASM_LOAD_FAILED: "WASM_LOAD_FAILED";
|
|
393
|
+
/** The canonical chip35 wasm builder for this operation is unavailable (never hand-rolled). */
|
|
394
|
+
readonly SPEND_BUILDER_UNAVAILABLE: "SPEND_BUILDER_UNAVAILABLE";
|
|
395
|
+
/** No secure random source was available to generate a payment nonce. */
|
|
396
|
+
readonly NO_SECURE_RANDOM: "NO_SECURE_RANDOM";
|
|
397
|
+
/** The `digstore` binary could not be spawned (not installed / not on PATH). */
|
|
398
|
+
readonly DIGSTORE_NOT_FOUND: "DIGSTORE_NOT_FOUND";
|
|
399
|
+
/** `digstore deploy` exited non-zero. */
|
|
400
|
+
readonly DEPLOY_FAILED: "DEPLOY_FAILED";
|
|
401
|
+
/** `digstore deploy --json` output could not be parsed into a capsule result. */
|
|
402
|
+
readonly DEPLOY_OUTPUT_UNPARSEABLE: "DEPLOY_OUTPUT_UNPARSEABLE";
|
|
403
|
+
/** An argument was malformed (e.g. a non-hex string, a bad URN, mutually-exclusive options). */
|
|
404
|
+
readonly INVALID_ARGUMENT: "INVALID_ARGUMENT";
|
|
405
|
+
}>;
|
|
406
|
+
/** The union of every stable SDK error code. Branch on `err.code` against these. */
|
|
407
|
+
type DigSdkErrorCode = (typeof DIG_SDK_ERROR_CODES)[keyof typeof DIG_SDK_ERROR_CODES];
|
|
408
|
+
/** Structured, code-specific context attached to a {@link DigSdkError}. All fields optional. */
|
|
409
|
+
interface DigSdkErrorContext {
|
|
410
|
+
/** The dig RPC method involved (RPC_* errors). */
|
|
411
|
+
rpcMethod?: string;
|
|
412
|
+
/** The HTTP status returned (RPC_ERROR on a non-2xx). */
|
|
413
|
+
httpStatus?: number;
|
|
414
|
+
/** The JSON-RPC error code returned by the server (RPC_ERROR). */
|
|
415
|
+
rpcCode?: number;
|
|
416
|
+
/** The `digstore` process exit code (DEPLOY_FAILED). */
|
|
417
|
+
exitCode?: number | null;
|
|
418
|
+
/** The wallet method that was unsupported (METHOD_NOT_SUPPORTED). */
|
|
419
|
+
method?: string;
|
|
420
|
+
/** The connection mode in play (provider errors). */
|
|
421
|
+
mode?: string;
|
|
422
|
+
/** The offending value (INVALID_ARGUMENT — e.g. the bad hex / URN). */
|
|
423
|
+
value?: string;
|
|
424
|
+
/** The expected vs actual SRI digest (WASM_INTEGRITY). */
|
|
425
|
+
expected?: string;
|
|
426
|
+
actual?: string;
|
|
427
|
+
/** Any further structured detail; kept open so codes can carry extra fields. */
|
|
428
|
+
[key: string]: unknown;
|
|
429
|
+
}
|
|
430
|
+
declare class DigSdkError extends Error {
|
|
431
|
+
/** The stable machine code (UPPER_SNAKE). Branch on this, not the message. */
|
|
432
|
+
readonly code: DigSdkErrorCode;
|
|
433
|
+
/** Structured, code-specific context (rpcMethod, httpStatus, exitCode, …). */
|
|
434
|
+
readonly context: DigSdkErrorContext;
|
|
435
|
+
constructor(code: DigSdkErrorCode, message: string, context?: DigSdkErrorContext, options?: {
|
|
436
|
+
cause?: unknown;
|
|
437
|
+
});
|
|
438
|
+
/** A JSON-friendly view of the error: `{ code, message, context }`. */
|
|
439
|
+
toJSON(): {
|
|
440
|
+
code: DigSdkErrorCode;
|
|
441
|
+
message: string;
|
|
442
|
+
context: DigSdkErrorContext;
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* True iff `e` is a {@link DigSdkError} (optionally with a specific `code`). Uses a non-enumerable
|
|
447
|
+
* BRAND rather than `instanceof` so it recognizes coded errors thrown from any of the SDK's
|
|
448
|
+
* separately-bundled entry points (the main entry and `/adapters` inline distinct class identities).
|
|
449
|
+
*/
|
|
450
|
+
declare function isDigSdkError(e: unknown, code?: DigSdkErrorCode): e is DigSdkError;
|
|
451
|
+
|
|
452
|
+
/** The SDK's semver version, from package.json (injected at build time). */
|
|
453
|
+
declare const SDK_VERSION: string;
|
|
454
|
+
/** The machine-readable description of one SDK module. */
|
|
455
|
+
interface ModuleDescriptor {
|
|
456
|
+
/** The module's public name (the class/helper a consumer imports). */
|
|
457
|
+
readonly name: string;
|
|
458
|
+
/** One-line summary of what it does. */
|
|
459
|
+
readonly summary: string;
|
|
460
|
+
/** The import path it's reachable from (the package subpath). */
|
|
461
|
+
readonly entry: string;
|
|
462
|
+
}
|
|
463
|
+
/** The full machine-readable description of the SDK surface — what `capabilities()` returns. */
|
|
464
|
+
interface SdkCapabilities {
|
|
465
|
+
/** Always `"@dignetwork/dig-sdk"`. */
|
|
466
|
+
readonly name: string;
|
|
467
|
+
/** The SDK semver (= {@link SDK_VERSION}). */
|
|
468
|
+
readonly version: string;
|
|
469
|
+
/** The modules the SDK exposes (ChiaProvider, DigClient, Paywall, spend builders, adapters). */
|
|
470
|
+
readonly modules: readonly ModuleDescriptor[];
|
|
471
|
+
/** The canonical CHIP-0002 wallet method surface both transports negotiate. */
|
|
472
|
+
readonly walletMethods: readonly string[];
|
|
473
|
+
/** The message-signing methods, in preference order. */
|
|
474
|
+
readonly signMethods: readonly string[];
|
|
475
|
+
/** The wallet transports the SDK can connect through. */
|
|
476
|
+
readonly transports: readonly ("injected" | "walletconnect")[];
|
|
477
|
+
/** The CAIP-2 chains supported (mainnet only — there is no testnet flow). */
|
|
478
|
+
readonly chains: readonly string[];
|
|
479
|
+
/** The default dig RPC endpoint `DigClient` reads from. */
|
|
480
|
+
readonly defaultRpc: string;
|
|
481
|
+
/** The SRI digest of the vendored read-crypto wasm (fail-closed on mismatch). */
|
|
482
|
+
readonly readCryptoWasmSha256: string;
|
|
483
|
+
/** The stable error-code catalogue (UPPER_SNAKE) consumers can branch on. */
|
|
484
|
+
readonly errorCodes: readonly DigSdkErrorCode[];
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Describe the SDK's surface as machine-readable data: version, modules, methods, transports,
|
|
488
|
+
* chains, the default RPC, the read-crypto wasm digest, and the error-code catalogue. An agent can
|
|
489
|
+
* call this to introspect the SDK without reading source.
|
|
490
|
+
*
|
|
491
|
+
* @example
|
|
492
|
+
* import { capabilities } from "@dignetwork/dig-sdk";
|
|
493
|
+
* const cap = capabilities();
|
|
494
|
+
* cap.version; // "0.2.0"
|
|
495
|
+
* cap.walletMethods; // ["chip0002_connect", …]
|
|
496
|
+
* cap.errorCodes; // ["WC_OPTIONS_REQUIRED", …]
|
|
497
|
+
*/
|
|
498
|
+
declare function capabilities(): SdkCapabilities;
|
|
499
|
+
/** Alias for {@link capabilities} — the conventional `describe()` introspection name. */
|
|
500
|
+
declare const describe: typeof capabilities;
|
|
501
|
+
|
|
502
|
+
export { ChiaProvider, type ConnectOptions, DEFAULT_CHAIN, DIG_SDK_ERROR_CODES, DigSdkError, type DigSdkErrorCode, type DigSdkErrorContext, INJECTED_TOPIC, InjectedChiaProvider, InjectedTransport, type ModuleDescriptor, type MonetizationSpends, type PaymentAssetSpec, type PaymentResult, Paywall, type PaywallOptions, type ProveAccessArgs, type RequestPaymentArgs, SDK_VERSION, SIGN_METHODS, type SdkCapabilities, SignResult, type VerifyReceiptArgs, WALLET_METHODS, WalletBackend, type WalletConnectMetadata, type WalletConnectOptions, WalletConnectTransport, type WalletMethod, WalletSession, type WalletTransport, capabilities, connectWallet, describe, getInjectedProvider, isDigSdkError, isInjectedAvailable, isTransientPublishError };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { W as WalletBackend, a as WalletSession, S as SignResult, I as InjectedChiaProvider } from './dig-client-entry-
|
|
2
|
-
export { D as DEFAULT_RPC,
|
|
1
|
+
import { W as WalletBackend, a as WalletSession, S as SignResult, I as InjectedChiaProvider } from './dig-client-entry-ChYxUvBn.js';
|
|
2
|
+
export { C as CollectionItem, b as CollectionItemMetadata, c as CollectionItemsPage, d as CollectionMeta, D as DEFAULT_RPC, e as DIG_CLIENT_WASM_SHA256, f as DigClient, g as DigClientOptions, h as DigClientWasm, P as ParsedUrn, R as ReadOptions, i as ReadResult, U as UrnKeys, j as WasmConfig, k as configureWasm, l as isUrn, m as loadDigClientWasm, p as parseUrn, r as reconstructUrn, n as reconstructUrnWithRoot } from './dig-client-entry-ChYxUvBn.js';
|
|
3
3
|
|
|
4
4
|
/** A wallet transport: connect, then `request` CHIP-0002 methods through it. */
|
|
5
5
|
interface WalletTransport {
|
|
@@ -175,6 +175,176 @@ declare class InjectedTransport implements WalletTransport {
|
|
|
175
175
|
/** True iff `err` looks like a transient relay-publish failure (request never reached the wallet). */
|
|
176
176
|
declare function isTransientPublishError(err: unknown): boolean;
|
|
177
177
|
|
|
178
|
+
/** A payment asset: XCH, or a CAT identified by its tail hash (e.g. $DIG). */
|
|
179
|
+
type PaymentAssetSpec = {
|
|
180
|
+
xch: true;
|
|
181
|
+
assetId?: undefined;
|
|
182
|
+
} | {
|
|
183
|
+
xch?: false;
|
|
184
|
+
assetId: string;
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* The subset of `@dignetwork/chip35-dl-coin-wasm` the Paywall drives. The full wasm module satisfies
|
|
188
|
+
* this shape, so `import("@dignetwork/chip35-dl-coin-wasm")` (or the SDK's "./spend" re-export) can
|
|
189
|
+
* be passed directly. Declared as a structural type so the SDK does not statically import the
|
|
190
|
+
* (bundler-only) wasm and tests can inject a spy.
|
|
191
|
+
*/
|
|
192
|
+
interface MonetizationSpends {
|
|
193
|
+
/** wasm-bindgen init. Called once before building spends (a no-op if the runtime needs none). */
|
|
194
|
+
init?: () => unknown;
|
|
195
|
+
/** SHA-256-derive a 32-byte unlock nonce from request bytes. */
|
|
196
|
+
paymentNonce?: (requestBytes: Uint8Array) => Uint8Array;
|
|
197
|
+
/** Build the coin spends for an XCH payment. Returns `{ coinSpends, receipt }`. */
|
|
198
|
+
buildPayment?: (buyerSyntheticKey: Uint8Array, selectedCoins: unknown, ownerPuzzleHash: Uint8Array, amount: bigint, nonce: Uint8Array, fee: bigint) => {
|
|
199
|
+
coinSpends: unknown;
|
|
200
|
+
receipt: unknown;
|
|
201
|
+
};
|
|
202
|
+
/** Build the coin spends for a CAT (incl. DIG) payment. Returns `{ coinSpends, receipt }`. */
|
|
203
|
+
buildCatPayment?: (buyerSyntheticKey: Uint8Array, selectedCats: unknown, ownerPuzzleHash: Uint8Array, amount: bigint, nonce: Uint8Array) => {
|
|
204
|
+
coinSpends: unknown;
|
|
205
|
+
receipt: unknown;
|
|
206
|
+
};
|
|
207
|
+
/** Verify an observed payment unlocks the paywall. Returns `{ ok, error? }`. */
|
|
208
|
+
verifyPaymentReceipt?: (observed: unknown, ownerPuzzleHash: Uint8Array, minAmount: bigint, requiredAsset: unknown, requireNonce?: Uint8Array | null) => {
|
|
209
|
+
ok: boolean;
|
|
210
|
+
error?: string;
|
|
211
|
+
};
|
|
212
|
+
/** Prove NFT ownership (optionally gating on a launcher id). Returns `{ ok, proof?, error? }`. */
|
|
213
|
+
proveNftOwnership?: (parentSpend: unknown, claimedOwnerPuzzleHash: Uint8Array, requiredNft?: Uint8Array | null) => {
|
|
214
|
+
ok: boolean;
|
|
215
|
+
proof?: unknown;
|
|
216
|
+
error?: string;
|
|
217
|
+
};
|
|
218
|
+
/** Prove collection/creator membership for an owner. Returns `{ ok, proof?, error? }`. */
|
|
219
|
+
proveCollectionMembership?: (parentSpend: unknown, claimedOwnerPuzzleHash: Uint8Array, requiredDid: Uint8Array) => {
|
|
220
|
+
ok: boolean;
|
|
221
|
+
proof?: unknown;
|
|
222
|
+
error?: string;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/** Options for constructing a `Paywall`. */
|
|
226
|
+
interface PaywallOptions {
|
|
227
|
+
/**
|
|
228
|
+
* The canonical chip35 monetization spends. Defaults to a lazy
|
|
229
|
+
* `import("@dignetwork/chip35-dl-coin-wasm")` (and calls its `init()`), so a bundled dapp needs to
|
|
230
|
+
* pass nothing. Inject a builder for non-bundler runtimes or tests.
|
|
231
|
+
*/
|
|
232
|
+
spends?: MonetizationSpends;
|
|
233
|
+
}
|
|
234
|
+
/** Arguments for `Paywall.requestPayment`. */
|
|
235
|
+
interface RequestPaymentArgs {
|
|
236
|
+
/** Amount to pay, in mojos (XCH) or base units (CAT). Number or bigint. */
|
|
237
|
+
amount: number | bigint;
|
|
238
|
+
/** The dapp owner's puzzle hash to pay (hex, with or without `0x`). */
|
|
239
|
+
owner: string;
|
|
240
|
+
/** Pay in this CAT (tail hash hex). Omit for XCH. */
|
|
241
|
+
assetId?: string;
|
|
242
|
+
/**
|
|
243
|
+
* A free-form unlock identifier (e.g. `dappId|resource|user`). When given without an explicit
|
|
244
|
+
* `nonce`, the Paywall derives the 32-byte nonce from it via the wasm `paymentNonce` (deterministic
|
|
245
|
+
* convenience). Ignored when `nonce` is supplied.
|
|
246
|
+
*/
|
|
247
|
+
memo?: string;
|
|
248
|
+
/** An explicit 32-byte unlock nonce (hex). Overrides `memo`. Random 32 bytes are used if neither. */
|
|
249
|
+
nonce?: string;
|
|
250
|
+
/** Network fee in mojos (XCH payments only; CAT rings net to zero). Defaults to 0. */
|
|
251
|
+
fee?: number | bigint;
|
|
252
|
+
/** Cap on the number of buyer coins to source from the wallet. */
|
|
253
|
+
coinLimit?: number;
|
|
254
|
+
}
|
|
255
|
+
/** The result of a successful `requestPayment`: the wallet signature + the wasm receipt + spends. */
|
|
256
|
+
interface PaymentResult {
|
|
257
|
+
/** The aggregated BLS signature the wallet returned for the coin spends. */
|
|
258
|
+
signature: string;
|
|
259
|
+
/** The `PaymentReceipt` the wasm produced — persist it; `verifyReceipt` later checks the chain. */
|
|
260
|
+
receipt: unknown;
|
|
261
|
+
/** The exact coin spends the wasm built and the wallet signed. */
|
|
262
|
+
coinSpends: unknown;
|
|
263
|
+
/** The 32-byte unlock nonce embedded in the payment (hex). */
|
|
264
|
+
nonce: string;
|
|
265
|
+
}
|
|
266
|
+
/** Arguments for `Paywall.verifyReceipt`. */
|
|
267
|
+
interface VerifyReceiptArgs {
|
|
268
|
+
/** The `ObservedPayment` the dapp filled in after reading the owner's coin from the chain. */
|
|
269
|
+
observed: unknown;
|
|
270
|
+
/** The owner puzzle hash that must have been paid (hex). */
|
|
271
|
+
owner: string;
|
|
272
|
+
/** The minimum amount that must have been paid (mojos / base units). */
|
|
273
|
+
minAmount: number | bigint;
|
|
274
|
+
/** The required asset. Defaults to XCH; pass `{ assetId }` to require a CAT. */
|
|
275
|
+
asset?: PaymentAssetSpec;
|
|
276
|
+
/** Require this exact 32-byte nonce (hex) to be present in the payment. */
|
|
277
|
+
nonce?: string;
|
|
278
|
+
}
|
|
279
|
+
/** Arguments for `Paywall.proveAccess` — gate on NFT ownership XOR collection membership. */
|
|
280
|
+
interface ProveAccessArgs {
|
|
281
|
+
/** The coin spend that created the NFT's current coin (the wasm `CoinSpend` shape). */
|
|
282
|
+
parentSpend: unknown;
|
|
283
|
+
/** The puzzle hash claiming ownership (hex). */
|
|
284
|
+
owner: string;
|
|
285
|
+
/** Gate on this specific NFT launcher id (hex). Mutually exclusive with `collection`. */
|
|
286
|
+
nft?: string;
|
|
287
|
+
/** Gate on membership of this collection/creator DID (hex). Mutually exclusive with `nft`. */
|
|
288
|
+
collection?: string;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* High-level pay-to-unlock helper. Construct it from a connected `ChiaProvider`; it builds payment
|
|
292
|
+
* spends via the canonical chip35 wasm and pushes them to the wallet for signing.
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* const provider = await ChiaProvider.connect({ mode: "auto", walletConnect });
|
|
296
|
+
* const paywall = new Paywall(provider); // chip35 wasm loaded lazily under a bundler
|
|
297
|
+
* // Charge 0.25 XCH to unlock a resource:
|
|
298
|
+
* const { receipt } = await paywall.requestPayment({
|
|
299
|
+
* amount: 250_000_000_000n,
|
|
300
|
+
* owner: dappOwnerPuzzleHashHex,
|
|
301
|
+
* memo: `unlock:${resourceId}:${userId}`,
|
|
302
|
+
* });
|
|
303
|
+
* // Later, gate access by re-checking the receipt against the chain:
|
|
304
|
+
* const { ok } = await paywall.verifyReceipt({ observed, owner: dappOwnerPuzzleHashHex, minAmount: 250_000_000_000n });
|
|
305
|
+
*/
|
|
306
|
+
declare class Paywall {
|
|
307
|
+
private readonly provider;
|
|
308
|
+
private readonly injectedSpends?;
|
|
309
|
+
private spendsReady?;
|
|
310
|
+
constructor(provider: ChiaProvider, options?: PaywallOptions);
|
|
311
|
+
/**
|
|
312
|
+
* Resolve the canonical monetization spends (injected, or lazily imported + `init()`ed). Memoized.
|
|
313
|
+
* This is the ONLY source of coin-spend construction in the Paywall — there is no fallback that
|
|
314
|
+
* hand-rolls a spend.
|
|
315
|
+
*/
|
|
316
|
+
private spends;
|
|
317
|
+
/** The wallet's first synthetic public key, as bytes (the buyer key the spends are built against). */
|
|
318
|
+
private buyerKey;
|
|
319
|
+
/** Resolve the 32-byte unlock nonce: explicit hex, else derived from `memo`, else random. */
|
|
320
|
+
private resolveNonce;
|
|
321
|
+
/**
|
|
322
|
+
* Charge the buyer (the connected wallet) `amount` to pay the dapp `owner`, then push the
|
|
323
|
+
* wasm-built coin spends to the wallet for signing. Returns the wallet signature + the receipt.
|
|
324
|
+
* Builds via the canonical wasm `buildPayment` (XCH) or `buildCatPayment` (CAT) — never hand-rolled.
|
|
325
|
+
*/
|
|
326
|
+
requestPayment(args: RequestPaymentArgs): Promise<PaymentResult>;
|
|
327
|
+
/**
|
|
328
|
+
* Verify an observed on-chain payment unlocks the paywall (pay-to-unlock). Delegates to the wasm
|
|
329
|
+
* `verifyPaymentReceipt`; returns its `{ ok, error? }` verdict. `ok:true` grants access.
|
|
330
|
+
*/
|
|
331
|
+
verifyReceipt(args: VerifyReceiptArgs): Promise<{
|
|
332
|
+
ok: boolean;
|
|
333
|
+
error?: string;
|
|
334
|
+
}>;
|
|
335
|
+
/**
|
|
336
|
+
* Prove the `owner` holds access: gate on a specific NFT (`nft` launcher id) via the wasm
|
|
337
|
+
* `proveNftOwnership`, or on collection/creator membership (`collection` DID) via
|
|
338
|
+
* `proveCollectionMembership`. Returns `{ ok, proof?, error? }`. The caller still confirms the
|
|
339
|
+
* proof's coin is unspent on-chain for liveness.
|
|
340
|
+
*/
|
|
341
|
+
proveAccess(args: ProveAccessArgs): Promise<{
|
|
342
|
+
ok: boolean;
|
|
343
|
+
proof?: unknown;
|
|
344
|
+
error?: string;
|
|
345
|
+
}>;
|
|
346
|
+
}
|
|
347
|
+
|
|
178
348
|
/** The canonical CHIP-0002 / chia method names the SDK negotiates with the wallet. */
|
|
179
349
|
declare const WALLET_METHODS: readonly ["chip0002_connect", "chip0002_chainId", "chip0002_getPublicKeys", "chip0002_getAssetCoins", "chip0002_getAssetBalance", "chip0002_signCoinSpends", "chip0002_signMessage", "chia_getAddress", "chia_signMessageByAddress", "chia_takeOffer"];
|
|
180
350
|
/** Union of the canonical wallet method names. */
|
|
@@ -189,4 +359,144 @@ declare const SIGN_METHODS: readonly ["chia_signMessageByAddress", "chip0002_sig
|
|
|
189
359
|
/** Default Chia chain id (CAIP-2). Mainnet — there is no testnet flow. */
|
|
190
360
|
declare const DEFAULT_CHAIN = "chia:mainnet";
|
|
191
361
|
|
|
192
|
-
|
|
362
|
+
/**
|
|
363
|
+
* The stable error-code catalogue. Each value is an UPPER_SNAKE symbolic string that callers may
|
|
364
|
+
* branch on. Frozen so it can't be mutated at runtime; the README documents each meaning.
|
|
365
|
+
*/
|
|
366
|
+
declare const DIG_SDK_ERROR_CODES: Readonly<{
|
|
367
|
+
/** WalletConnect was requested/needed but no `walletConnect` options were supplied. */
|
|
368
|
+
readonly WC_OPTIONS_REQUIRED: "WC_OPTIONS_REQUIRED";
|
|
369
|
+
/** `mode: "injected"` (or the injected leg of `auto`) found no usable `window.chia`. */
|
|
370
|
+
readonly NO_INJECTED_WALLET: "NO_INJECTED_WALLET";
|
|
371
|
+
/** The optional `@walletconnect/sign-client` peer dependency is not installed/usable. */
|
|
372
|
+
readonly WC_DEPENDENCY_MISSING: "WC_DEPENDENCY_MISSING";
|
|
373
|
+
/** The active wallet session/transport does not grant the requested method. */
|
|
374
|
+
readonly METHOD_NOT_SUPPORTED: "METHOD_NOT_SUPPORTED";
|
|
375
|
+
/** A wallet RPC timed out (e.g. Sage did not respond within the per-request timeout). */
|
|
376
|
+
readonly WALLET_TIMEOUT: "WALLET_TIMEOUT";
|
|
377
|
+
/** The wallet returned no public keys / no key to sign with. */
|
|
378
|
+
readonly WALLET_NO_KEYS: "WALLET_NO_KEYS";
|
|
379
|
+
/** A content read needs a confirmed on-chain root and none was supplied/derivable. */
|
|
380
|
+
readonly ROOT_REQUIRED: "ROOT_REQUIRED";
|
|
381
|
+
/** The resource did not decrypt+authenticate under this URN (wrong key/salt, or a decoy). */
|
|
382
|
+
readonly DECRYPT_FAILED: "DECRYPT_FAILED";
|
|
383
|
+
/** The dig RPC could not be reached (network/transport failure). */
|
|
384
|
+
readonly RPC_TRANSPORT: "RPC_TRANSPORT";
|
|
385
|
+
/** The dig RPC responded with an HTTP error or a JSON-RPC `error` object. */
|
|
386
|
+
readonly RPC_ERROR: "RPC_ERROR";
|
|
387
|
+
/** The dig RPC returned a malformed / inconsistent payload (e.g. chunk-length mismatch). */
|
|
388
|
+
readonly RPC_MALFORMED_RESPONSE: "RPC_MALFORMED_RESPONSE";
|
|
389
|
+
/** The vendored read-crypto wasm failed its SRI integrity check — fail closed. */
|
|
390
|
+
readonly WASM_INTEGRITY: "WASM_INTEGRITY";
|
|
391
|
+
/** The read-crypto wasm could not be loaded (fetch/resolve failure). */
|
|
392
|
+
readonly WASM_LOAD_FAILED: "WASM_LOAD_FAILED";
|
|
393
|
+
/** The canonical chip35 wasm builder for this operation is unavailable (never hand-rolled). */
|
|
394
|
+
readonly SPEND_BUILDER_UNAVAILABLE: "SPEND_BUILDER_UNAVAILABLE";
|
|
395
|
+
/** No secure random source was available to generate a payment nonce. */
|
|
396
|
+
readonly NO_SECURE_RANDOM: "NO_SECURE_RANDOM";
|
|
397
|
+
/** The `digstore` binary could not be spawned (not installed / not on PATH). */
|
|
398
|
+
readonly DIGSTORE_NOT_FOUND: "DIGSTORE_NOT_FOUND";
|
|
399
|
+
/** `digstore deploy` exited non-zero. */
|
|
400
|
+
readonly DEPLOY_FAILED: "DEPLOY_FAILED";
|
|
401
|
+
/** `digstore deploy --json` output could not be parsed into a capsule result. */
|
|
402
|
+
readonly DEPLOY_OUTPUT_UNPARSEABLE: "DEPLOY_OUTPUT_UNPARSEABLE";
|
|
403
|
+
/** An argument was malformed (e.g. a non-hex string, a bad URN, mutually-exclusive options). */
|
|
404
|
+
readonly INVALID_ARGUMENT: "INVALID_ARGUMENT";
|
|
405
|
+
}>;
|
|
406
|
+
/** The union of every stable SDK error code. Branch on `err.code` against these. */
|
|
407
|
+
type DigSdkErrorCode = (typeof DIG_SDK_ERROR_CODES)[keyof typeof DIG_SDK_ERROR_CODES];
|
|
408
|
+
/** Structured, code-specific context attached to a {@link DigSdkError}. All fields optional. */
|
|
409
|
+
interface DigSdkErrorContext {
|
|
410
|
+
/** The dig RPC method involved (RPC_* errors). */
|
|
411
|
+
rpcMethod?: string;
|
|
412
|
+
/** The HTTP status returned (RPC_ERROR on a non-2xx). */
|
|
413
|
+
httpStatus?: number;
|
|
414
|
+
/** The JSON-RPC error code returned by the server (RPC_ERROR). */
|
|
415
|
+
rpcCode?: number;
|
|
416
|
+
/** The `digstore` process exit code (DEPLOY_FAILED). */
|
|
417
|
+
exitCode?: number | null;
|
|
418
|
+
/** The wallet method that was unsupported (METHOD_NOT_SUPPORTED). */
|
|
419
|
+
method?: string;
|
|
420
|
+
/** The connection mode in play (provider errors). */
|
|
421
|
+
mode?: string;
|
|
422
|
+
/** The offending value (INVALID_ARGUMENT — e.g. the bad hex / URN). */
|
|
423
|
+
value?: string;
|
|
424
|
+
/** The expected vs actual SRI digest (WASM_INTEGRITY). */
|
|
425
|
+
expected?: string;
|
|
426
|
+
actual?: string;
|
|
427
|
+
/** Any further structured detail; kept open so codes can carry extra fields. */
|
|
428
|
+
[key: string]: unknown;
|
|
429
|
+
}
|
|
430
|
+
declare class DigSdkError extends Error {
|
|
431
|
+
/** The stable machine code (UPPER_SNAKE). Branch on this, not the message. */
|
|
432
|
+
readonly code: DigSdkErrorCode;
|
|
433
|
+
/** Structured, code-specific context (rpcMethod, httpStatus, exitCode, …). */
|
|
434
|
+
readonly context: DigSdkErrorContext;
|
|
435
|
+
constructor(code: DigSdkErrorCode, message: string, context?: DigSdkErrorContext, options?: {
|
|
436
|
+
cause?: unknown;
|
|
437
|
+
});
|
|
438
|
+
/** A JSON-friendly view of the error: `{ code, message, context }`. */
|
|
439
|
+
toJSON(): {
|
|
440
|
+
code: DigSdkErrorCode;
|
|
441
|
+
message: string;
|
|
442
|
+
context: DigSdkErrorContext;
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* True iff `e` is a {@link DigSdkError} (optionally with a specific `code`). Uses a non-enumerable
|
|
447
|
+
* BRAND rather than `instanceof` so it recognizes coded errors thrown from any of the SDK's
|
|
448
|
+
* separately-bundled entry points (the main entry and `/adapters` inline distinct class identities).
|
|
449
|
+
*/
|
|
450
|
+
declare function isDigSdkError(e: unknown, code?: DigSdkErrorCode): e is DigSdkError;
|
|
451
|
+
|
|
452
|
+
/** The SDK's semver version, from package.json (injected at build time). */
|
|
453
|
+
declare const SDK_VERSION: string;
|
|
454
|
+
/** The machine-readable description of one SDK module. */
|
|
455
|
+
interface ModuleDescriptor {
|
|
456
|
+
/** The module's public name (the class/helper a consumer imports). */
|
|
457
|
+
readonly name: string;
|
|
458
|
+
/** One-line summary of what it does. */
|
|
459
|
+
readonly summary: string;
|
|
460
|
+
/** The import path it's reachable from (the package subpath). */
|
|
461
|
+
readonly entry: string;
|
|
462
|
+
}
|
|
463
|
+
/** The full machine-readable description of the SDK surface — what `capabilities()` returns. */
|
|
464
|
+
interface SdkCapabilities {
|
|
465
|
+
/** Always `"@dignetwork/dig-sdk"`. */
|
|
466
|
+
readonly name: string;
|
|
467
|
+
/** The SDK semver (= {@link SDK_VERSION}). */
|
|
468
|
+
readonly version: string;
|
|
469
|
+
/** The modules the SDK exposes (ChiaProvider, DigClient, Paywall, spend builders, adapters). */
|
|
470
|
+
readonly modules: readonly ModuleDescriptor[];
|
|
471
|
+
/** The canonical CHIP-0002 wallet method surface both transports negotiate. */
|
|
472
|
+
readonly walletMethods: readonly string[];
|
|
473
|
+
/** The message-signing methods, in preference order. */
|
|
474
|
+
readonly signMethods: readonly string[];
|
|
475
|
+
/** The wallet transports the SDK can connect through. */
|
|
476
|
+
readonly transports: readonly ("injected" | "walletconnect")[];
|
|
477
|
+
/** The CAIP-2 chains supported (mainnet only — there is no testnet flow). */
|
|
478
|
+
readonly chains: readonly string[];
|
|
479
|
+
/** The default dig RPC endpoint `DigClient` reads from. */
|
|
480
|
+
readonly defaultRpc: string;
|
|
481
|
+
/** The SRI digest of the vendored read-crypto wasm (fail-closed on mismatch). */
|
|
482
|
+
readonly readCryptoWasmSha256: string;
|
|
483
|
+
/** The stable error-code catalogue (UPPER_SNAKE) consumers can branch on. */
|
|
484
|
+
readonly errorCodes: readonly DigSdkErrorCode[];
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Describe the SDK's surface as machine-readable data: version, modules, methods, transports,
|
|
488
|
+
* chains, the default RPC, the read-crypto wasm digest, and the error-code catalogue. An agent can
|
|
489
|
+
* call this to introspect the SDK without reading source.
|
|
490
|
+
*
|
|
491
|
+
* @example
|
|
492
|
+
* import { capabilities } from "@dignetwork/dig-sdk";
|
|
493
|
+
* const cap = capabilities();
|
|
494
|
+
* cap.version; // "0.2.0"
|
|
495
|
+
* cap.walletMethods; // ["chip0002_connect", …]
|
|
496
|
+
* cap.errorCodes; // ["WC_OPTIONS_REQUIRED", …]
|
|
497
|
+
*/
|
|
498
|
+
declare function capabilities(): SdkCapabilities;
|
|
499
|
+
/** Alias for {@link capabilities} — the conventional `describe()` introspection name. */
|
|
500
|
+
declare const describe: typeof capabilities;
|
|
501
|
+
|
|
502
|
+
export { ChiaProvider, type ConnectOptions, DEFAULT_CHAIN, DIG_SDK_ERROR_CODES, DigSdkError, type DigSdkErrorCode, type DigSdkErrorContext, INJECTED_TOPIC, InjectedChiaProvider, InjectedTransport, type ModuleDescriptor, type MonetizationSpends, type PaymentAssetSpec, type PaymentResult, Paywall, type PaywallOptions, type ProveAccessArgs, type RequestPaymentArgs, SDK_VERSION, SIGN_METHODS, type SdkCapabilities, SignResult, type VerifyReceiptArgs, WALLET_METHODS, WalletBackend, type WalletConnectMetadata, type WalletConnectOptions, WalletConnectTransport, type WalletMethod, WalletSession, type WalletTransport, capabilities, connectWallet, describe, getInjectedProvider, isDigSdkError, isInjectedAvailable, isTransientPublishError };
|