@parity/product-sdk-bulletin 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 +201 -0
- package/dist/index.d.ts +555 -0
- package/dist/index.js +1344 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
- package/src/authorization.ts +191 -0
- package/src/cid.ts +338 -0
- package/src/client.ts +255 -0
- package/src/errors.ts +235 -0
- package/src/gateway.ts +209 -0
- package/src/index.ts +38 -0
- package/src/query.ts +82 -0
- package/src/resolve-query.ts +192 -0
- package/src/resolve-signer.ts +66 -0
- package/src/types.ts +140 -0
- package/src/upload.ts +344 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
import { TypedApi, PolkadotSigner } from 'polkadot-api';
|
|
2
|
+
import { WaitFor, TxStatus } from '@parity/product-sdk-tx';
|
|
3
|
+
import { Environment } from '@parity/product-sdk-chain-client';
|
|
4
|
+
export { Environment } from '@parity/product-sdk-chain-client';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hash algorithms supported by the Bulletin Chain.
|
|
8
|
+
*
|
|
9
|
+
* Values are multihash codes as defined in the
|
|
10
|
+
* {@link https://github.com/multiformats/multicodec multicodec table}.
|
|
11
|
+
*/
|
|
12
|
+
declare const HashAlgorithm: {
|
|
13
|
+
/** BLAKE2b-256 — default for product-sdk and the chain SDK. */
|
|
14
|
+
readonly Blake2b256: 45600;
|
|
15
|
+
/** SHA2-256 — default for bulletin-deploy. */
|
|
16
|
+
readonly Sha2_256: 18;
|
|
17
|
+
/** Keccak-256 — Ethereum compatibility. */
|
|
18
|
+
readonly Keccak256: 27;
|
|
19
|
+
};
|
|
20
|
+
/** A multihash code supported by the Bulletin Chain. */
|
|
21
|
+
type HashAlgorithm = (typeof HashAlgorithm)[keyof typeof HashAlgorithm];
|
|
22
|
+
/**
|
|
23
|
+
* CID codecs supported by the Bulletin Chain.
|
|
24
|
+
*
|
|
25
|
+
* Values are multicodec codes.
|
|
26
|
+
*/
|
|
27
|
+
declare const CidCodec: {
|
|
28
|
+
/** Raw binary — default for single-chunk data. */
|
|
29
|
+
readonly Raw: 85;
|
|
30
|
+
/** DAG-PB — used for multi-chunk manifests / directory structures. */
|
|
31
|
+
readonly DagPb: 112;
|
|
32
|
+
/** DAG-CBOR — alternative DAG encoding. */
|
|
33
|
+
readonly DagCbor: 113;
|
|
34
|
+
};
|
|
35
|
+
/** A multicodec code supported by the Bulletin Chain. */
|
|
36
|
+
type CidCodec = (typeof CidCodec)[keyof typeof CidCodec];
|
|
37
|
+
/**
|
|
38
|
+
* Compute the CIDv1 (blake2b-256, raw codec) for arbitrary data.
|
|
39
|
+
* Deterministic: same input always produces the same CID.
|
|
40
|
+
*/
|
|
41
|
+
declare function computeCid(data: Uint8Array): string;
|
|
42
|
+
/**
|
|
43
|
+
* Extract the content hash digest from a CIDv1 string and return it as a
|
|
44
|
+
* `0x`-prefixed hex string — the preimage key format used by the host API.
|
|
45
|
+
*
|
|
46
|
+
* Accepts CIDv1 with any hash algorithm supported by the Bulletin Chain
|
|
47
|
+
* (blake2b-256, sha2-256, keccak-256).
|
|
48
|
+
*
|
|
49
|
+
* @param cid - CIDv1 base32 string (as produced by {@link computeCid} or {@link hashToCid}).
|
|
50
|
+
* @returns `0x`-prefixed hex string of the 32-byte hash digest.
|
|
51
|
+
* @throws If the CID is not CIDv1 or uses an unsupported hash algorithm.
|
|
52
|
+
*/
|
|
53
|
+
declare function cidToPreimageKey(cid: string): `0x${string}`;
|
|
54
|
+
/**
|
|
55
|
+
* Reconstruct a CIDv1 from a `0x`-prefixed hex hash stored on-chain.
|
|
56
|
+
*
|
|
57
|
+
* This is the inverse of {@link cidToPreimageKey}: given a 32-byte content hash
|
|
58
|
+
* and the CID configuration used when the data was stored, it rebuilds the
|
|
59
|
+
* original CIDv1 so you can construct IPFS gateway URLs.
|
|
60
|
+
*
|
|
61
|
+
* The Bulletin Chain supports multiple hash algorithms and codecs — pass the
|
|
62
|
+
* values that match the on-chain `TransactionInfo` to get the correct CID.
|
|
63
|
+
* When omitted, defaults match {@link computeCid} (blake2b-256, raw).
|
|
64
|
+
*
|
|
65
|
+
* @param hexHash - `0x`-prefixed hex string of a 32-byte hash digest
|
|
66
|
+
* (66 characters total: `"0x"` + 64 hex chars).
|
|
67
|
+
* @param hashCode - Multihash code of the hashing algorithm (default: blake2b-256 `0xb220`).
|
|
68
|
+
* Use {@link HashAlgorithm} for the supported values.
|
|
69
|
+
* @param codec - Multicodec code of the CID codec (default: raw `0x55`).
|
|
70
|
+
* Use {@link CidCodec} for the supported values.
|
|
71
|
+
* @returns Base32-lower CIDv1 string.
|
|
72
|
+
* @throws If `hexHash` is not exactly 66 characters, or if the hash/codec is unsupported.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { hashToCid, HashAlgorithm, CidCodec, gatewayUrl, getGateway } from "@parity/product-sdk-bulletin";
|
|
77
|
+
*
|
|
78
|
+
* // Default (blake2b-256, raw) — matches computeCid output
|
|
79
|
+
* const cid = hashToCid(onChainHash);
|
|
80
|
+
*
|
|
81
|
+
* // SHA2-256 content stored via bulletin-deploy
|
|
82
|
+
* const cid2 = hashToCid(onChainHash, HashAlgorithm.Sha2_256);
|
|
83
|
+
*
|
|
84
|
+
* // DAG-PB manifest with blake2b-256
|
|
85
|
+
* const cid3 = hashToCid(manifestHash, HashAlgorithm.Blake2b256, CidCodec.DagPb);
|
|
86
|
+
*
|
|
87
|
+
* const url = gatewayUrl(cid, getGateway("paseo"));
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @see {@link cidToPreimageKey} for the reverse direction (CID → hex hash).
|
|
91
|
+
* @see {@link computeCid} for computing a CID from raw data.
|
|
92
|
+
* @see {@link HashAlgorithm} for supported hash algorithms.
|
|
93
|
+
* @see {@link CidCodec} for supported CID codecs.
|
|
94
|
+
*/
|
|
95
|
+
declare function hashToCid(hexHash: `0x${string}`, hashCode?: HashAlgorithm, codec?: CidCodec): string;
|
|
96
|
+
|
|
97
|
+
/** Typed API for the Bulletin Chain, derived from PAPI descriptors. */
|
|
98
|
+
type BulletinApi = TypedApi<any>;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Options for {@link upload}.
|
|
102
|
+
*
|
|
103
|
+
* Note: `waitFor`, `timeoutMs`, and `onStatus` only apply to the **transaction**
|
|
104
|
+
* upload path (when an explicit signer is used or the dev signer fallback is active).
|
|
105
|
+
* The preimage path delegates to the host which controls its own submission
|
|
106
|
+
* lifecycle — these options are ignored in that case.
|
|
107
|
+
*/
|
|
108
|
+
interface UploadOptions {
|
|
109
|
+
/** IPFS gateway base URL (e.g., from `getGateway("paseo")`). If provided, result includes gatewayUrl. */
|
|
110
|
+
gateway?: string;
|
|
111
|
+
/** When to resolve: `"best-block"` (default) or `"finalized"`. Transaction path only. */
|
|
112
|
+
waitFor?: WaitFor;
|
|
113
|
+
/** Timeout in ms. Default: 300_000 (5 min). Transaction path only. */
|
|
114
|
+
timeoutMs?: number;
|
|
115
|
+
/** Lifecycle status callback for UI progress. Transaction path only. */
|
|
116
|
+
onStatus?: (status: TxStatus) => void;
|
|
117
|
+
}
|
|
118
|
+
/** Fields common to all upload results. */
|
|
119
|
+
interface UploadResultBase {
|
|
120
|
+
/** CIDv1 string (blake2b-256, raw codec). */
|
|
121
|
+
cid: string;
|
|
122
|
+
/** Gateway URL. Present only if `gateway` was provided in options. */
|
|
123
|
+
gatewayUrl?: string;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Result of a successful upload to the Bulletin Chain.
|
|
127
|
+
*
|
|
128
|
+
* Discriminated on `kind`:
|
|
129
|
+
* - `"transaction"` — uploaded via a signed `TransactionStorage.store` extrinsic.
|
|
130
|
+
* - `"preimage"` — uploaded via the host preimage API (no user signing).
|
|
131
|
+
*
|
|
132
|
+
* Use `result.kind` to narrow the type and access path-specific fields.
|
|
133
|
+
*/
|
|
134
|
+
type UploadResult = (UploadResultBase & {
|
|
135
|
+
/** Upload was performed via a signed transaction. */
|
|
136
|
+
kind: "transaction";
|
|
137
|
+
/** Block hash where the store transaction was included. */
|
|
138
|
+
blockHash: string;
|
|
139
|
+
}) | (UploadResultBase & {
|
|
140
|
+
/** Upload was performed via the host preimage API. */
|
|
141
|
+
kind: "preimage";
|
|
142
|
+
/** Hex key returned by the host preimage API. */
|
|
143
|
+
preimageKey: string;
|
|
144
|
+
});
|
|
145
|
+
/** A single item in a batch upload. */
|
|
146
|
+
interface BatchUploadItem {
|
|
147
|
+
/** Raw bytes to upload. */
|
|
148
|
+
data: Uint8Array;
|
|
149
|
+
/** Label for progress tracking (e.g., filename). */
|
|
150
|
+
label: string;
|
|
151
|
+
}
|
|
152
|
+
/** Fields common to all batch upload results. */
|
|
153
|
+
interface BatchUploadResultBase {
|
|
154
|
+
label: string;
|
|
155
|
+
cid: string;
|
|
156
|
+
gatewayUrl?: string;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Result for one item in a batch upload.
|
|
160
|
+
*
|
|
161
|
+
* Discriminated on `kind` (upload path) and `success` (outcome).
|
|
162
|
+
* Use `result.success` to check for errors, then `result.kind` to access
|
|
163
|
+
* path-specific fields like `blockHash` or `preimageKey`.
|
|
164
|
+
*/
|
|
165
|
+
type BatchUploadResult = (BatchUploadResultBase & {
|
|
166
|
+
kind: "transaction";
|
|
167
|
+
success: true;
|
|
168
|
+
/** Block hash where the store transaction was included. */
|
|
169
|
+
blockHash: string;
|
|
170
|
+
}) | (BatchUploadResultBase & {
|
|
171
|
+
kind: "preimage";
|
|
172
|
+
success: true;
|
|
173
|
+
/** Hex key returned by the host preimage API. */
|
|
174
|
+
preimageKey: string;
|
|
175
|
+
}) | (BatchUploadResultBase & {
|
|
176
|
+
kind: "transaction" | "preimage";
|
|
177
|
+
success: false;
|
|
178
|
+
/** Error message describing the failure. */
|
|
179
|
+
error: string;
|
|
180
|
+
});
|
|
181
|
+
/** Options for {@link batchUpload}. */
|
|
182
|
+
interface BatchUploadOptions extends UploadOptions {
|
|
183
|
+
/** Called after each item completes (success or failure). */
|
|
184
|
+
onProgress?: (completed: number, total: number, current: BatchUploadResult) => void;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Authorization status for a Bulletin Chain account.
|
|
188
|
+
*
|
|
189
|
+
* Returned by {@link checkAuthorization} to enable pre-flight checks before
|
|
190
|
+
* uploading. Consumers can use this to show "not authorized" or "insufficient
|
|
191
|
+
* quota" messages instead of letting the transaction fail.
|
|
192
|
+
*/
|
|
193
|
+
interface AuthorizationStatus {
|
|
194
|
+
/** Whether an authorization entry exists for this account. */
|
|
195
|
+
authorized: boolean;
|
|
196
|
+
/** Remaining transactions allowed. 0 if not authorized. */
|
|
197
|
+
remainingTransactions: number;
|
|
198
|
+
/** Remaining bytes allowed. 0n if not authorized. */
|
|
199
|
+
remainingBytes: bigint;
|
|
200
|
+
/** Block number when the authorization expires. 0 if not authorized. */
|
|
201
|
+
expiration: number;
|
|
202
|
+
}
|
|
203
|
+
/** Options for gateway fetch operations. */
|
|
204
|
+
interface FetchOptions {
|
|
205
|
+
/** Timeout in ms. Default: 30_000. */
|
|
206
|
+
timeoutMs?: number;
|
|
207
|
+
}
|
|
208
|
+
/** Options for query operations that support host lookup auto-resolution. */
|
|
209
|
+
interface QueryOptions extends FetchOptions {
|
|
210
|
+
/**
|
|
211
|
+
* Timeout for the host preimage lookup subscription in ms.
|
|
212
|
+
* Only applies when the query resolves through the host path.
|
|
213
|
+
* Default: 30_000.
|
|
214
|
+
*/
|
|
215
|
+
lookupTimeoutMs?: number;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Ergonomic entry point for Bulletin Chain operations.
|
|
220
|
+
*
|
|
221
|
+
* Bundles a typed Bulletin API (from chain-client) and an IPFS gateway URL
|
|
222
|
+
* so callers don't need to re-pass them on every call.
|
|
223
|
+
*
|
|
224
|
+
* Both upload and query paths use the host container APIs:
|
|
225
|
+
* - **Uploads** — the host preimage API signs and submits automatically.
|
|
226
|
+
* - **Queries** (`fetchBytes`/`fetchJson`) — uses host preimage lookup with caching.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* const bulletin = await BulletinClient.create("paseo");
|
|
231
|
+
* const result = await bulletin.upload(fileBytes);
|
|
232
|
+
* const metadata = await bulletin.fetchJson<Metadata>(result.cid);
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
declare class BulletinClient {
|
|
236
|
+
readonly api: BulletinApi;
|
|
237
|
+
readonly gateway: string;
|
|
238
|
+
private queryStrategyPromise;
|
|
239
|
+
private constructor();
|
|
240
|
+
/** Lazily resolve and cache the query strategy for the client lifetime. */
|
|
241
|
+
private resolveQuery;
|
|
242
|
+
/** Create from an environment — resolves API via chain-client, gateway from known list. */
|
|
243
|
+
static create(env: Environment): Promise<BulletinClient>;
|
|
244
|
+
/** Create from an explicit API and gateway (custom setups, testing). */
|
|
245
|
+
static from(api: BulletinApi, gateway: string): BulletinClient;
|
|
246
|
+
/** Compute CID without uploading. Static — no instance needed. */
|
|
247
|
+
static computeCid(data: Uint8Array): string;
|
|
248
|
+
/**
|
|
249
|
+
* Reconstruct a CID from a `0x`-prefixed hex hash. Static — no instance needed.
|
|
250
|
+
*
|
|
251
|
+
* Useful for converting on-chain hashes back to CIDs for IPFS gateway lookups.
|
|
252
|
+
* Pass optional hash algorithm and codec to match the on-chain CID configuration.
|
|
253
|
+
*
|
|
254
|
+
* @see {@link hashToCid} for full documentation.
|
|
255
|
+
*/
|
|
256
|
+
static hashToCid(hexHash: `0x${string}`, hashCode?: HashAlgorithm, codec?: CidCodec): string;
|
|
257
|
+
/**
|
|
258
|
+
* Upload data to the Bulletin Chain.
|
|
259
|
+
*
|
|
260
|
+
* @param data - Raw bytes to store.
|
|
261
|
+
* @param signer - Optional signer. When omitted, uses the host preimage API.
|
|
262
|
+
* @param options - Upload options (timeout, waitFor, status callback).
|
|
263
|
+
*/
|
|
264
|
+
upload(data: Uint8Array, signer?: PolkadotSigner, options?: Omit<UploadOptions, "gateway">): Promise<UploadResult>;
|
|
265
|
+
/**
|
|
266
|
+
* Upload multiple items sequentially.
|
|
267
|
+
*
|
|
268
|
+
* @param items - Array of items to upload, each with data and a label.
|
|
269
|
+
* @param signer - Optional signer. When omitted, auto-resolved.
|
|
270
|
+
* @param options - Batch upload options (timeout, progress callback).
|
|
271
|
+
*/
|
|
272
|
+
batchUpload(items: BatchUploadItem[], signer?: PolkadotSigner, options?: Omit<BatchUploadOptions, "gateway">): Promise<BatchUploadResult[]>;
|
|
273
|
+
/**
|
|
274
|
+
* Fetch raw bytes by CID.
|
|
275
|
+
*
|
|
276
|
+
* Uses host preimage lookup with caching.
|
|
277
|
+
*/
|
|
278
|
+
fetchBytes(cid: string, options?: QueryOptions): Promise<Uint8Array>;
|
|
279
|
+
/**
|
|
280
|
+
* Fetch and parse JSON by CID.
|
|
281
|
+
*
|
|
282
|
+
* Auto-resolves query path (same as {@link fetchBytes}).
|
|
283
|
+
*/
|
|
284
|
+
fetchJson<T>(cid: string, options?: QueryOptions): Promise<T>;
|
|
285
|
+
/** Check if a CID exists on the gateway. */
|
|
286
|
+
cidExists(cid: string): Promise<boolean>;
|
|
287
|
+
/** Build the full gateway URL for a CID. */
|
|
288
|
+
gatewayUrl(cid: string): string;
|
|
289
|
+
/**
|
|
290
|
+
* Check whether an account is authorized to store data on the Bulletin Chain.
|
|
291
|
+
*
|
|
292
|
+
* Use as a pre-flight check before {@link upload} to provide clear UX
|
|
293
|
+
* instead of letting the transaction fail mid-execution.
|
|
294
|
+
*
|
|
295
|
+
* @param address - SS58-encoded account address to check.
|
|
296
|
+
* @returns Authorization status with remaining quota.
|
|
297
|
+
*
|
|
298
|
+
* @see {@link checkAuthorization} for the standalone function equivalent.
|
|
299
|
+
*/
|
|
300
|
+
checkAuthorization(address: string): Promise<AuthorizationStatus>;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Check whether an account is authorized to store data on the Bulletin Chain.
|
|
305
|
+
*
|
|
306
|
+
* Queries `TransactionStorage.Authorizations` for the given address and returns
|
|
307
|
+
* the raw authorization quota. Use this as a pre-flight check before calling
|
|
308
|
+
* {@link upload} to provide clear UX ("not authorized" / "insufficient quota")
|
|
309
|
+
* instead of letting the transaction fail mid-execution.
|
|
310
|
+
*
|
|
311
|
+
* The expiration block number is returned as-is — the chain enforces expiration
|
|
312
|
+
* at submission time, so callers can optionally compare against the current
|
|
313
|
+
* block for display purposes.
|
|
314
|
+
*
|
|
315
|
+
* @param api - Typed Bulletin Chain API instance.
|
|
316
|
+
* @param address - SS58-encoded account address to check.
|
|
317
|
+
* @returns Authorization status with remaining quota.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```ts
|
|
321
|
+
* import { checkAuthorization } from "@parity/product-sdk-bulletin";
|
|
322
|
+
*
|
|
323
|
+
* const auth = await checkAuthorization(api, address);
|
|
324
|
+
* if (!auth.authorized) {
|
|
325
|
+
* console.error("Account is not authorized for bulletin storage");
|
|
326
|
+
* } else if (auth.remainingBytes < BigInt(fileBytes.length)) {
|
|
327
|
+
* console.error(`Insufficient quota: ${auth.remainingBytes} bytes remaining`);
|
|
328
|
+
* }
|
|
329
|
+
* ```
|
|
330
|
+
*
|
|
331
|
+
* @see {@link BulletinClient.checkAuthorization} for the client method equivalent.
|
|
332
|
+
*/
|
|
333
|
+
declare function checkAuthorization(api: BulletinApi, address: string): Promise<AuthorizationStatus>;
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Base class for all Bulletin Chain errors.
|
|
337
|
+
*
|
|
338
|
+
* Use `instanceof BulletinError` to catch any bulletin-related error.
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```ts
|
|
342
|
+
* try {
|
|
343
|
+
* await bulletin.upload(data);
|
|
344
|
+
* } catch (e) {
|
|
345
|
+
* if (e instanceof BulletinError) {
|
|
346
|
+
* console.error("Bulletin operation failed:", e.message);
|
|
347
|
+
* }
|
|
348
|
+
* }
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
declare class BulletinError extends Error {
|
|
352
|
+
constructor(message: string, options?: ErrorOptions);
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* The host preimage API is unavailable.
|
|
356
|
+
*
|
|
357
|
+
* Thrown when bulletin operations require the host container but it's not available.
|
|
358
|
+
* This typically means the SDK is running outside of Polkadot Browser/Desktop.
|
|
359
|
+
*/
|
|
360
|
+
declare class BulletinHostUnavailableError extends BulletinError {
|
|
361
|
+
constructor(operation: "upload" | "query");
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* The host preimage lookup timed out.
|
|
365
|
+
*
|
|
366
|
+
* The host was unable to retrieve the requested content within the timeout period.
|
|
367
|
+
* The content may still become available later.
|
|
368
|
+
*/
|
|
369
|
+
declare class BulletinLookupTimeoutError extends BulletinError {
|
|
370
|
+
/** The CID that was being looked up. */
|
|
371
|
+
readonly cid: string;
|
|
372
|
+
/** The timeout duration in milliseconds. */
|
|
373
|
+
readonly timeoutMs: number;
|
|
374
|
+
constructor(cid: string, timeoutMs: number);
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* The host interrupted the preimage lookup.
|
|
378
|
+
*
|
|
379
|
+
* The host terminated the lookup subscription, typically after repeated failures
|
|
380
|
+
* or when the host determines the content is unavailable.
|
|
381
|
+
*/
|
|
382
|
+
declare class BulletinLookupInterruptedError extends BulletinError {
|
|
383
|
+
/** The CID that was being looked up. */
|
|
384
|
+
readonly cid: string;
|
|
385
|
+
constructor(cid: string);
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Failed to check authorization status for an account.
|
|
389
|
+
*
|
|
390
|
+
* Wraps RPC or query errors that occur when checking if an account
|
|
391
|
+
* is authorized to store data on the Bulletin Chain.
|
|
392
|
+
*/
|
|
393
|
+
declare class BulletinAuthorizationError extends BulletinError {
|
|
394
|
+
/** The address that was being checked. */
|
|
395
|
+
readonly address: string;
|
|
396
|
+
constructor(address: string, cause?: unknown);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* The IPFS gateway for the specified environment is not available.
|
|
400
|
+
*
|
|
401
|
+
* Thrown when attempting to use gateway features for a network that
|
|
402
|
+
* doesn't have a live bulletin gateway yet.
|
|
403
|
+
*/
|
|
404
|
+
declare class BulletinGatewayUnavailableError extends BulletinError {
|
|
405
|
+
/** The environment that was requested. */
|
|
406
|
+
readonly environment: string;
|
|
407
|
+
constructor(environment: string);
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* An IPFS gateway request failed.
|
|
411
|
+
*
|
|
412
|
+
* Thrown when a fetch to the IPFS gateway returns a non-OK response.
|
|
413
|
+
*/
|
|
414
|
+
declare class BulletinGatewayFetchError extends BulletinError {
|
|
415
|
+
/** The CID that was being fetched. */
|
|
416
|
+
readonly cid: string;
|
|
417
|
+
/** The HTTP status code returned by the gateway. */
|
|
418
|
+
readonly status: number;
|
|
419
|
+
/** The HTTP status text returned by the gateway. */
|
|
420
|
+
readonly statusText: string;
|
|
421
|
+
constructor(cid: string, status: number, statusText: string);
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Invalid CID format or version.
|
|
425
|
+
*
|
|
426
|
+
* Thrown when a CID string cannot be parsed or has an unexpected version/codec.
|
|
427
|
+
*/
|
|
428
|
+
declare class BulletinCidError extends BulletinError {
|
|
429
|
+
/** The invalid CID string, if available. */
|
|
430
|
+
readonly cid?: string;
|
|
431
|
+
constructor(message: string, cid?: string);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Get the IPFS gateway URL for an environment.
|
|
436
|
+
* @throws {BulletinGatewayUnavailableError} If the network doesn't have a live gateway yet.
|
|
437
|
+
*/
|
|
438
|
+
declare function getGateway(env: Environment): string;
|
|
439
|
+
/** Build the full gateway URL for a CID. */
|
|
440
|
+
declare function gatewayUrl(cid: string, gateway: string): string;
|
|
441
|
+
/** Check if a CID exists on the gateway (HEAD request). Returns false on any error or timeout. */
|
|
442
|
+
declare function cidExists(cid: string, gateway: string, options?: FetchOptions): Promise<boolean>;
|
|
443
|
+
/**
|
|
444
|
+
* Fetch raw bytes from the gateway.
|
|
445
|
+
* @throws {BulletinGatewayFetchError} If the gateway returns a non-OK response.
|
|
446
|
+
*/
|
|
447
|
+
declare function fetchBytes(cid: string, gateway: string, options?: FetchOptions): Promise<Uint8Array>;
|
|
448
|
+
/** Fetch and parse JSON from the gateway. */
|
|
449
|
+
declare function fetchJson<T>(cid: string, gateway: string, options?: FetchOptions): Promise<T>;
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Query strategy for the Bulletin Chain.
|
|
453
|
+
*
|
|
454
|
+
* The host manages the lookup via its preimage subscription API,
|
|
455
|
+
* which includes local caching and managed IPFS polling.
|
|
456
|
+
*/
|
|
457
|
+
interface QueryStrategy {
|
|
458
|
+
kind: "host-lookup";
|
|
459
|
+
lookup: (cid: string, timeoutMs?: number) => Promise<Uint8Array>;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Determine the query strategy for the Bulletin Chain.
|
|
463
|
+
*
|
|
464
|
+
* Uses the host preimage lookup API which caches results and manages
|
|
465
|
+
* IPFS polling automatically.
|
|
466
|
+
*
|
|
467
|
+
* @returns The resolved query strategy.
|
|
468
|
+
* @throws {BulletinHostUnavailableError} If the host preimage manager is unavailable.
|
|
469
|
+
*/
|
|
470
|
+
declare function resolveQueryStrategy(): Promise<QueryStrategy>;
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Fetch raw bytes for a CID using the host preimage lookup.
|
|
474
|
+
*
|
|
475
|
+
* Uses local cache + managed IPFS polling via the host container.
|
|
476
|
+
*
|
|
477
|
+
* @param cid - CIDv1 string to fetch.
|
|
478
|
+
* @param options - Query options (lookupTimeoutMs for host).
|
|
479
|
+
* @returns Raw bytes of the content.
|
|
480
|
+
* @throws {Error} If the host preimage API is unavailable.
|
|
481
|
+
*/
|
|
482
|
+
declare function queryBytes(cid: string, options?: QueryOptions): Promise<Uint8Array>;
|
|
483
|
+
/**
|
|
484
|
+
* Fetch and parse JSON for a CID, auto-resolving the query path.
|
|
485
|
+
*
|
|
486
|
+
* Delegates to {@link queryBytes} and parses the result as JSON.
|
|
487
|
+
*
|
|
488
|
+
* @param cid - CIDv1 string to fetch.
|
|
489
|
+
* @param options - Query options.
|
|
490
|
+
* @returns Parsed JSON value.
|
|
491
|
+
* @throws {Error} If the host preimage API is unavailable.
|
|
492
|
+
*/
|
|
493
|
+
declare function queryJson<T>(cid: string, options?: QueryOptions): Promise<T>;
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Discriminated union describing how data will be uploaded to the Bulletin Chain.
|
|
497
|
+
*
|
|
498
|
+
* - `"preimage"` — the host handles signing and chain submission via its preimage API.
|
|
499
|
+
* - `"signer"` — a `TransactionStorage.store` transaction is signed and submitted directly.
|
|
500
|
+
*/
|
|
501
|
+
type UploadStrategy = {
|
|
502
|
+
kind: "preimage";
|
|
503
|
+
submit: (data: Uint8Array) => Promise<string>;
|
|
504
|
+
} | {
|
|
505
|
+
kind: "signer";
|
|
506
|
+
signer: PolkadotSigner;
|
|
507
|
+
};
|
|
508
|
+
/**
|
|
509
|
+
* Determine the upload strategy for the Bulletin Chain.
|
|
510
|
+
*
|
|
511
|
+
* Resolution order:
|
|
512
|
+
* 1. If an explicit signer is provided, use it directly.
|
|
513
|
+
* 2. Otherwise, use the host preimage API (the SDK is designed to run inside a container).
|
|
514
|
+
*
|
|
515
|
+
* @param explicitSigner - Optional signer provided by the caller. When present,
|
|
516
|
+
* skips host auto-detection entirely.
|
|
517
|
+
* @returns The resolved upload strategy.
|
|
518
|
+
* @throws {Error} If no signer is provided and the host preimage API is unavailable.
|
|
519
|
+
*/
|
|
520
|
+
declare function resolveUploadStrategy(explicitSigner?: PolkadotSigner): Promise<UploadStrategy>;
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Upload data to the Bulletin Chain.
|
|
524
|
+
*
|
|
525
|
+
* When a signer is provided, submits a `TransactionStorage.store` transaction
|
|
526
|
+
* directly. When omitted, uses the host preimage API — the host signs and
|
|
527
|
+
* submits automatically.
|
|
528
|
+
*
|
|
529
|
+
* Computes the CIDv1 (blake2b-256, raw codec) locally.
|
|
530
|
+
*
|
|
531
|
+
* @param api - Typed Bulletin Chain API.
|
|
532
|
+
* @param data - Raw bytes to store.
|
|
533
|
+
* @param signer - Optional signer. When omitted, uses host preimage API.
|
|
534
|
+
* @param options - Upload options (gateway, timeout, waitFor, status callback).
|
|
535
|
+
* @returns Upload result with CID and either blockHash or preimageKey.
|
|
536
|
+
*/
|
|
537
|
+
declare function upload(api: BulletinApi, data: Uint8Array, signer?: PolkadotSigner, options?: UploadOptions): Promise<UploadResult>;
|
|
538
|
+
/**
|
|
539
|
+
* Upload multiple items sequentially to the Bulletin Chain.
|
|
540
|
+
*
|
|
541
|
+
* Bulletin Chain requires sequential transaction submission (nonce ordering).
|
|
542
|
+
* Individual failures are captured in results — the batch does not abort.
|
|
543
|
+
*
|
|
544
|
+
* Signer resolution follows the same rules as {@link upload}: when omitted,
|
|
545
|
+
* the strategy is auto-resolved once and reused for all items.
|
|
546
|
+
*
|
|
547
|
+
* @param api - Typed Bulletin Chain API.
|
|
548
|
+
* @param items - Array of items to upload, each with data and a label.
|
|
549
|
+
* @param signer - Optional signer. When omitted, auto-resolved.
|
|
550
|
+
* @param options - Batch upload options (gateway, timeout, progress callback).
|
|
551
|
+
* @returns Array of results, one per item, preserving input order.
|
|
552
|
+
*/
|
|
553
|
+
declare function batchUpload(api: BulletinApi, items: BatchUploadItem[], signer?: PolkadotSigner, options?: BatchUploadOptions): Promise<BatchUploadResult[]>;
|
|
554
|
+
|
|
555
|
+
export { type AuthorizationStatus, type BatchUploadItem, type BatchUploadOptions, type BatchUploadResult, type BulletinApi, BulletinAuthorizationError, BulletinCidError, BulletinClient, BulletinError, BulletinGatewayFetchError, BulletinGatewayUnavailableError, BulletinHostUnavailableError, BulletinLookupInterruptedError, BulletinLookupTimeoutError, CidCodec, type FetchOptions, HashAlgorithm, type QueryOptions, type QueryStrategy, type UploadOptions, type UploadResult, type UploadStrategy, batchUpload, checkAuthorization, cidExists, cidToPreimageKey, computeCid, fetchBytes, fetchJson, gatewayUrl, getGateway, hashToCid, queryBytes, queryJson, resolveQueryStrategy, resolveUploadStrategy, upload };
|