@bsv/sdk 2.0.13 → 2.0.14
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 +2 -0
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/identity/IdentityClient.js +3 -3
- package/dist/cjs/src/identity/IdentityClient.js.map +1 -1
- package/dist/cjs/src/identity/types/index.js +1 -1
- package/dist/cjs/src/identity/types/index.js.map +1 -1
- package/dist/cjs/src/storage/StorageUploader.js +315 -96
- package/dist/cjs/src/storage/StorageUploader.js.map +1 -1
- package/dist/cjs/src/storage/index.js +3 -1
- package/dist/cjs/src/storage/index.js.map +1 -1
- package/dist/cjs/src/wallet/WERR_REVIEW_ACTIONS.js +2 -2
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/identity/IdentityClient.js +3 -3
- package/dist/esm/src/identity/IdentityClient.js.map +1 -1
- package/dist/esm/src/identity/types/index.js +1 -1
- package/dist/esm/src/identity/types/index.js.map +1 -1
- package/dist/esm/src/storage/StorageUploader.js +319 -95
- package/dist/esm/src/storage/StorageUploader.js.map +1 -1
- package/dist/esm/src/storage/index.js +1 -1
- package/dist/esm/src/storage/index.js.map +1 -1
- package/dist/esm/src/wallet/WERR_REVIEW_ACTIONS.js +2 -2
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/storage/StorageUploader.d.ts +94 -55
- package/dist/types/src/storage/StorageUploader.d.ts.map +1 -1
- package/dist/types/src/storage/index.d.ts +1 -1
- package/dist/types/src/storage/index.d.ts.map +1 -1
- package/dist/types/src/wallet/WERR_REVIEW_ACTIONS.d.ts +2 -2
- package/dist/types/src/wallet/Wallet.interfaces.d.ts +2 -2
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +4 -4
- package/dist/umd/bundle.js.map +1 -1
- package/docs/index.md +3 -1
- package/docs/reference/identity.md +1 -1
- package/docs/reference/storage.md +214 -85
- package/docs/reference/transaction.md +2 -2
- package/docs/reference/wallet.md +4 -4
- package/package.json +1 -1
- package/src/identity/IdentityClient.ts +3 -3
- package/src/identity/__tests/IdentityClient.additional.test.ts +3 -3
- package/src/identity/types/index.ts +1 -1
- package/src/storage/StorageUploader.ts +427 -105
- package/src/storage/__tests/StorageUploader.test.ts +881 -64
- package/src/storage/index.ts +1 -1
- package/src/wallet/WERR_REVIEW_ACTIONS.ts +2 -2
- package/src/wallet/Wallet.interfaces.ts +2 -2
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { WalletInterface } from '../wallet/Wallet.interfaces.js';
|
|
2
|
+
/** Default UHRP storage providers used when the caller passes no host list. */
|
|
3
|
+
export declare const DEFAULT_UHRP_SERVERS: string[];
|
|
2
4
|
export interface UploaderConfig {
|
|
3
|
-
|
|
5
|
+
/** Legacy single-host URL. Mutually exclusive with `storageURLs`. */
|
|
6
|
+
storageURL?: string;
|
|
7
|
+
/** Explicit provider list. Takes precedence over `storageURL`. */
|
|
8
|
+
storageURLs?: string[];
|
|
9
|
+
/** Minimum replicas to store the file on. Defaults to 1. */
|
|
10
|
+
resilienceLevel?: number;
|
|
4
11
|
wallet: WalletInterface;
|
|
5
12
|
}
|
|
6
13
|
export interface UploadableFile {
|
|
@@ -10,94 +17,126 @@ export interface UploadableFile {
|
|
|
10
17
|
export interface UploadFileResult {
|
|
11
18
|
published: boolean;
|
|
12
19
|
uhrpURL: string;
|
|
20
|
+
/** Providers that successfully hosted the file. */
|
|
21
|
+
hostedBy: string[];
|
|
13
22
|
}
|
|
14
23
|
export interface FindFileData {
|
|
15
24
|
name: string;
|
|
16
25
|
size: string;
|
|
17
26
|
mimeType: string;
|
|
18
27
|
expiryTime: number;
|
|
28
|
+
/** Providers that reported this UHRP URL. Omitted in single-host mode. */
|
|
29
|
+
hostedBy?: string[];
|
|
30
|
+
}
|
|
31
|
+
export interface RenewPerHostResult {
|
|
32
|
+
host: string;
|
|
33
|
+
status: 'success' | 'error';
|
|
34
|
+
prevExpiryTime?: number;
|
|
35
|
+
newExpiryTime?: number;
|
|
36
|
+
amount?: number;
|
|
37
|
+
error?: string;
|
|
19
38
|
}
|
|
20
39
|
export interface RenewFileResult {
|
|
21
40
|
status: string;
|
|
22
41
|
prevExpiryTime?: number;
|
|
23
42
|
newExpiryTime?: number;
|
|
43
|
+
/** Total satoshis paid across every host that renewed. */
|
|
24
44
|
amount?: number;
|
|
45
|
+
/** Per-host outcomes. Omitted in single-host mode. */
|
|
46
|
+
results?: RenewPerHostResult[];
|
|
47
|
+
}
|
|
48
|
+
export interface HostScopeOptions {
|
|
49
|
+
/** Restrict the operation to this subset of configured providers. */
|
|
50
|
+
hostedBy?: string[];
|
|
51
|
+
}
|
|
52
|
+
export interface EstimateCostResult {
|
|
53
|
+
/** Cheapest-first quotes from configured providers. */
|
|
54
|
+
quotes: Array<{
|
|
55
|
+
host: string;
|
|
56
|
+
amount: number;
|
|
57
|
+
}>;
|
|
58
|
+
resilienceLevel: number;
|
|
59
|
+
/** Sum of the cheapest `resilienceLevel` amounts (or all collected, if below threshold). */
|
|
60
|
+
totalForResilience: number;
|
|
61
|
+
/** False when `publishFile` would throw without uploading. */
|
|
62
|
+
meetsResilienceThreshold: boolean;
|
|
25
63
|
}
|
|
26
64
|
/**
|
|
27
|
-
*
|
|
28
|
-
* -
|
|
29
|
-
*
|
|
30
|
-
|
|
31
|
-
|
|
65
|
+
* Thrown by `renewFile` when successful renewals fall below the resilience
|
|
66
|
+
* threshold. Per-host outcomes are attached so callers can reconcile which
|
|
67
|
+
* providers were billed.
|
|
68
|
+
*/
|
|
69
|
+
export declare class RenewResiliencyError extends Error {
|
|
70
|
+
readonly results: RenewPerHostResult[];
|
|
71
|
+
readonly requiredSuccesses: number;
|
|
72
|
+
readonly successCount: number;
|
|
73
|
+
constructor(message: string, results: RenewPerHostResult[], requiredSuccesses: number, successCount: number);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Client for publishing, finding, listing, and renewing UHRP-hosted files
|
|
77
|
+
* across one or more storage providers.
|
|
32
78
|
*/
|
|
33
79
|
export declare class StorageUploader {
|
|
34
80
|
private readonly authFetch;
|
|
81
|
+
private readonly hosts;
|
|
82
|
+
private readonly resilienceLevel;
|
|
83
|
+
/** Primary host used for non-upload operations. */
|
|
35
84
|
private readonly baseURL;
|
|
36
|
-
/**
|
|
37
|
-
* Creates a new StorageUploader instance.
|
|
38
|
-
* @param {UploaderConfig} config - An object containing the storage server's URL and a wallet interface
|
|
39
|
-
*/
|
|
40
85
|
constructor(config: UploaderConfig);
|
|
86
|
+
/** Returns `null` when the provider is unreachable or errors out. */
|
|
87
|
+
private getQuote;
|
|
88
|
+
/** Drives the authenticated `/upload` route; `AuthFetch` handles the 402 payment flow. */
|
|
89
|
+
private getUploadURL;
|
|
90
|
+
private putFile;
|
|
41
91
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* @param {number} retentionPeriod - The desired hosting time, in minutes
|
|
46
|
-
* @returns {Promise<{ uploadURL: string; requiredHeaders: Record<string, string>; amount?: number }>}
|
|
47
|
-
* @throws {Error} If the server returns a non-OK response or an error status
|
|
92
|
+
* Collects quotes in parallel batches, shrinking each batch to only the
|
|
93
|
+
* remaining quotes still needed so we never over-query once the quote
|
|
94
|
+
* budget is satisfied.
|
|
48
95
|
*/
|
|
49
|
-
private
|
|
96
|
+
private collectQuotes;
|
|
50
97
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @param {UploadableFile} file - The file to upload, including its raw data and MIME type
|
|
55
|
-
* @param {Record<string, string>} requiredHeaders - Additional headers required by the server (e.g. content-length)
|
|
56
|
-
* @returns {Promise<UploadFileResult>} An object indicating whether publishing was successful and the resulting UHRP URL
|
|
57
|
-
* @throws {Error} If the server returns a non-OK response
|
|
98
|
+
* Queries the unauthenticated `/quote` endpoint on up to `2 * resilienceLevel`
|
|
99
|
+
* providers and returns the cheapest-first quote list plus the aggregate
|
|
100
|
+
* cost `publishFile` would pay. No provider is billed.
|
|
58
101
|
*/
|
|
59
|
-
|
|
102
|
+
estimateCost(params: {
|
|
103
|
+
fileSize: number;
|
|
104
|
+
retentionPeriod: number;
|
|
105
|
+
}): Promise<EstimateCostResult>;
|
|
60
106
|
/**
|
|
61
|
-
* Publishes a file
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* 1. Request an upload URL from the server.
|
|
65
|
-
* 2. Perform an HTTP PUT to upload the file’s raw bytes.
|
|
66
|
-
* 3. Return a UHRP URL referencing the file once published.
|
|
67
|
-
*
|
|
68
|
-
* @param {Object} params
|
|
69
|
-
* @param {UploadableFile} params.file - The file data + type
|
|
70
|
-
* @param {number} params.retentionPeriod - Number of minutes to host the file
|
|
71
|
-
* @returns {Promise<UploadFileResult>} An object with the file's UHRP URL
|
|
72
|
-
* @throws {Error} If the server or upload step returns a non-OK response
|
|
107
|
+
* Publishes a file across the cheapest configured providers, falling
|
|
108
|
+
* through to the next-cheapest quote if a paid upload fails. Throws when
|
|
109
|
+
* the resilience threshold cannot be met.
|
|
73
110
|
*/
|
|
74
111
|
publishFile(params: {
|
|
75
112
|
file: UploadableFile;
|
|
76
113
|
retentionPeriod: number;
|
|
77
114
|
}): Promise<UploadFileResult>;
|
|
115
|
+
private findFileAtHost;
|
|
116
|
+
private renewFileAtHost;
|
|
117
|
+
/** Intersects `hostedBy` with the configured host set; throws when empty. */
|
|
118
|
+
private resolveTargets;
|
|
78
119
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
120
|
+
* Fans `/find` out across configured hosts (UHRP storage is host-local,
|
|
121
|
+
* so any one host may not know the file) and returns the record with the
|
|
122
|
+
* longest remaining expiry. Single-host configurations preserve the
|
|
123
|
+
* legacy error-message contract verbatim.
|
|
83
124
|
*/
|
|
84
|
-
findFile(uhrpUrl: string): Promise<FindFileData>;
|
|
125
|
+
findFile(uhrpUrl: string, options?: HostScopeOptions): Promise<FindFileData>;
|
|
85
126
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
127
|
+
* Unions `/list` output across configured hosts, merging duplicate UHRP
|
|
128
|
+
* URLs by the longest expiry observed. One failing host does not hide
|
|
129
|
+
* the rest. Single-host configurations preserve the legacy error contract.
|
|
89
130
|
*/
|
|
90
|
-
listUploads(): Promise<any>;
|
|
131
|
+
listUploads(options?: HostScopeOptions): Promise<any>;
|
|
132
|
+
private listUploadsAtHost;
|
|
91
133
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* @param {number} additionalMinutes - The number of minutes to extend
|
|
98
|
-
* @returns {Promise<RenewFileResult>} An object with the new and previous expiry times, plus any cost
|
|
99
|
-
* @throws {Error} If the request fails or the server returns an error
|
|
134
|
+
* Fans `/renew` out across every configured host (each provider owns its
|
|
135
|
+
* own advertisement, so a single-host renewal would degrade resilience
|
|
136
|
+
* over time). Hosts that do not carry the file are not billed. Throws
|
|
137
|
+
* {@link RenewResiliencyError} when successful renewals fall below the
|
|
138
|
+
* resilience threshold.
|
|
100
139
|
*/
|
|
101
|
-
renewFile(uhrpUrl: string, additionalMinutes: number): Promise<RenewFileResult>;
|
|
140
|
+
renewFile(uhrpUrl: string, additionalMinutes: number, options?: HostScopeOptions): Promise<RenewFileResult>;
|
|
102
141
|
}
|
|
103
142
|
//# sourceMappingURL=StorageUploader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageUploader.d.ts","sourceRoot":"","sources":["../../../../src/storage/StorageUploader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAGhE,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"StorageUploader.d.ts","sourceRoot":"","sources":["../../../../src/storage/StorageUploader.ts"],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C,kBAAkB,CAAC;IAiB/B;;;;OAIG;IACU,WAAW,CAAE,MAAM,EAAE;QAChC,IAAI,EAAE,cAAc,CAAA;QACpB,eAAe,EAAE,MAAM,CAAA;KACxB,GAAG,OAAO,CAAC,gBAAgB,CAAC;YAgDf,cAAc;YA0Bd,eAAe;IAqC7B,6EAA6E;IAC7E,OAAO,CAAC,cAAc;IAatB;;;;;OAKG;IACU,QAAQ,CAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,YAAY,CAAC;IAiC9F;;;;OAIG;IACU,WAAW,CAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,GAAG,CAAC;YA6CzD,iBAAiB;IAe/B;;;;;;OAMG;IACU,SAAS,CACpB,OAAO,EAAE,MAAM,EACf,iBAAiB,EAAE,MAAM,EACzB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,eAAe,CAAC;CAmE5B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * as StorageUtils from './StorageUtils.js';
|
|
2
|
-
export { StorageUploader } from './StorageUploader.js';
|
|
2
|
+
export { StorageUploader, DEFAULT_UHRP_SERVERS, RenewResiliencyError } from './StorageUploader.js';
|
|
3
3
|
export { StorageDownloader } from './StorageDownloader.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AAEjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AAEjD,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAElG,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AtomicBEEF, OutpointString, ReviewActionResult, SendWithResult, TXIDHexString } from './Wallet.interfaces.js';
|
|
2
2
|
/**
|
|
3
3
|
* When a `createAction` or `signAction` is completed in undelayed mode (`acceptDelayedBroadcast`: false),
|
|
4
|
-
* any
|
|
4
|
+
* any unsuccessful result will return the results by way of this exception to ensure attention is
|
|
5
5
|
* paid to processing errors.
|
|
6
6
|
*/
|
|
7
7
|
export declare class WERR_REVIEW_ACTIONS extends Error {
|
|
@@ -13,7 +13,7 @@ export declare class WERR_REVIEW_ACTIONS extends Error {
|
|
|
13
13
|
code: number;
|
|
14
14
|
isError: boolean;
|
|
15
15
|
/**
|
|
16
|
-
* All parameters correspond to their comparable `createAction` or `
|
|
16
|
+
* All parameters correspond to their comparable `createAction` or `signAction` results
|
|
17
17
|
* with the exception of `reviewActionResults`;
|
|
18
18
|
* which contains more details, particularly for double spend results.
|
|
19
19
|
*/
|
|
@@ -254,10 +254,10 @@ export interface SendWithResult {
|
|
|
254
254
|
}
|
|
255
255
|
/**
|
|
256
256
|
* Indicates status of a new Action following a `createAction` or `signAction` in immediate mode:
|
|
257
|
-
* When `acceptDelayedBroadcast` is
|
|
257
|
+
* When `acceptDelayedBroadcast` is false.
|
|
258
258
|
*
|
|
259
259
|
* 'success': The action has been broadcast and accepted by the bitcoin processing network.
|
|
260
|
-
* '
|
|
260
|
+
* 'doubleSpend': The action has been confirmed to double spend one or more inputs, and by the "first-seen-rule" is the losing transaction.
|
|
261
261
|
* 'invalidTx': The action was rejected by the processing network as an invalid bitcoin transaction.
|
|
262
262
|
* 'serviceError': The broadcast services are currently unable to reach the bitcoin network. The action is now queued for delayed retries.
|
|
263
263
|
*/
|