@bsv/sdk 1.4.17 → 1.4.19
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/dist/cjs/package.json +1 -1
- package/dist/cjs/src/kvstore/LocalKVStore.js +152 -141
- package/dist/cjs/src/kvstore/LocalKVStore.js.map +1 -1
- package/dist/cjs/src/storage/StorageUploader.js +122 -14
- package/dist/cjs/src/storage/StorageUploader.js.map +1 -1
- package/dist/cjs/src/storage/__test/StorageUploader.test.js +85 -14
- package/dist/cjs/src/storage/__test/StorageUploader.test.js.map +1 -1
- package/dist/cjs/src/wallet/WERR_REVIEW_ACTIONS.js +29 -0
- package/dist/cjs/src/wallet/WERR_REVIEW_ACTIONS.js.map +1 -0
- package/dist/cjs/src/wallet/WalletError.js +4 -3
- package/dist/cjs/src/wallet/WalletError.js.map +1 -1
- package/dist/cjs/src/wallet/index.js +4 -1
- package/dist/cjs/src/wallet/index.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js +13 -6
- package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/kvstore/LocalKVStore.js +151 -141
- package/dist/esm/src/kvstore/LocalKVStore.js.map +1 -1
- package/dist/esm/src/storage/StorageUploader.js +119 -14
- package/dist/esm/src/storage/StorageUploader.js.map +1 -1
- package/dist/esm/src/storage/__test/StorageUploader.test.js +85 -14
- package/dist/esm/src/storage/__test/StorageUploader.test.js.map +1 -1
- package/dist/esm/src/wallet/WERR_REVIEW_ACTIONS.js +31 -0
- package/dist/esm/src/wallet/WERR_REVIEW_ACTIONS.js.map +1 -0
- package/dist/esm/src/wallet/WalletError.js +3 -2
- package/dist/esm/src/wallet/WalletError.js.map +1 -1
- package/dist/esm/src/wallet/index.js +2 -0
- package/dist/esm/src/wallet/index.js.map +1 -1
- package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js +13 -6
- package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/kvstore/LocalKVStore.d.ts +10 -4
- package/dist/types/src/kvstore/LocalKVStore.d.ts.map +1 -1
- package/dist/types/src/storage/StorageUploader.d.ts +77 -14
- package/dist/types/src/storage/StorageUploader.d.ts.map +1 -1
- package/dist/types/src/wallet/WERR_REVIEW_ACTIONS.d.ts +23 -0
- package/dist/types/src/wallet/WERR_REVIEW_ACTIONS.d.ts.map +1 -0
- package/dist/types/src/wallet/Wallet.interfaces.d.ts +22 -0
- package/dist/types/src/wallet/Wallet.interfaces.d.ts.map +1 -1
- package/dist/types/src/wallet/WalletError.d.ts +4 -3
- package/dist/types/src/wallet/WalletError.d.ts.map +1 -1
- package/dist/types/src/wallet/index.d.ts +1 -0
- package/dist/types/src/wallet/index.d.ts.map +1 -1
- package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/kvstore.md +9 -8
- package/docs/storage.md +117 -7
- package/docs/wallet.md +146 -38
- package/package.json +1 -1
- package/src/kvstore/LocalKVStore.ts +156 -151
- package/src/kvstore/__tests/LocalKVStore.test.ts +104 -193
- package/src/storage/StorageUploader.ts +156 -14
- package/src/storage/__test/StorageUploader.test.ts +134 -15
- package/src/wallet/WERR_REVIEW_ACTIONS.ts +30 -0
- package/src/wallet/Wallet.interfaces.ts +24 -0
- package/src/wallet/WalletError.ts +4 -2
- package/src/wallet/index.ts +2 -0
- package/src/wallet/substrates/HTTPWalletJSON.ts +12 -6
package/dist/cjs/package.json
CHANGED
|
@@ -26,11 +26,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const LockingScript_js_1 = __importDefault(require("../script/LockingScript.js"));
|
|
30
29
|
const PushDrop_js_1 = __importDefault(require("../script/templates/PushDrop.js"));
|
|
31
30
|
const Utils = __importStar(require("../primitives/utils.js"));
|
|
32
31
|
const WalletClient_js_1 = __importDefault(require("../wallet/WalletClient.js"));
|
|
33
32
|
const Transaction_js_1 = __importDefault(require("../transaction/Transaction.js"));
|
|
33
|
+
const Beef_js_1 = require("../transaction/Beef.js");
|
|
34
34
|
/**
|
|
35
35
|
* Implements a key-value storage system backed by transaction outputs managed by a wallet.
|
|
36
36
|
* Each key-value pair is represented by a PushDrop token output in a specific context (basket).
|
|
@@ -41,12 +41,12 @@ class LocalKVStore {
|
|
|
41
41
|
* Creates an instance of the localKVStore.
|
|
42
42
|
*
|
|
43
43
|
* @param {WalletInterface} [wallet=new WalletClient()] - The wallet interface to use. Defaults to a new WalletClient instance.
|
|
44
|
-
* @param {string} [context='
|
|
44
|
+
* @param {string} [context='kvstoredefault'] - The context (basket) for namespacing keys. Defaults to 'kvstore default'.
|
|
45
45
|
* @param {boolean} [encrypt=true] - Whether to encrypt values. Defaults to true.
|
|
46
46
|
* @param {string} [originator] — An originator to use with PushDrop and the wallet, if provided.
|
|
47
47
|
* @throws {Error} If the context is missing or empty.
|
|
48
48
|
*/
|
|
49
|
-
constructor(wallet = new WalletClient_js_1.default(), context = 'kvstore
|
|
49
|
+
constructor(wallet = new WalletClient_js_1.default(), context = 'kvstore default', encrypt = true, originator) {
|
|
50
50
|
if (typeof context !== 'string' || context.length < 1) {
|
|
51
51
|
throw new Error('A context in which to operate is required.');
|
|
52
52
|
}
|
|
@@ -55,6 +55,19 @@ class LocalKVStore {
|
|
|
55
55
|
this.encrypt = encrypt;
|
|
56
56
|
this.originator = originator;
|
|
57
57
|
}
|
|
58
|
+
getProtocol(key) {
|
|
59
|
+
return { protocolID: [2, this.context], keyID: key };
|
|
60
|
+
}
|
|
61
|
+
async getOutputs(key, limit) {
|
|
62
|
+
const results = await this.wallet.listOutputs({
|
|
63
|
+
basket: this.context,
|
|
64
|
+
tags: [key],
|
|
65
|
+
tagQueryMode: 'all',
|
|
66
|
+
include: 'entire transactions',
|
|
67
|
+
limit
|
|
68
|
+
});
|
|
69
|
+
return results;
|
|
70
|
+
}
|
|
58
71
|
/**
|
|
59
72
|
* Retrieves the value associated with a given key.
|
|
60
73
|
*
|
|
@@ -62,46 +75,82 @@ class LocalKVStore {
|
|
|
62
75
|
* @param {string | undefined} [defaultValue=undefined] - The value to return if the key is not found.
|
|
63
76
|
* @returns {Promise<string | undefined>} A promise that resolves to the value as a string,
|
|
64
77
|
* the defaultValue if the key is not found, or undefined if no defaultValue is provided.
|
|
65
|
-
* @throws {Error} If
|
|
78
|
+
* @throws {Error} If too many outputs are found for the key (ambiguous state).
|
|
66
79
|
* @throws {Error} If the found output's locking script cannot be decoded or represents an invalid token format.
|
|
67
80
|
*/
|
|
68
81
|
async get(key, defaultValue = undefined) {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
82
|
+
const r = await this.lookupValue(key, defaultValue, 5);
|
|
83
|
+
return r.value;
|
|
84
|
+
}
|
|
85
|
+
getLockingScript(output, beef) {
|
|
86
|
+
var _a;
|
|
87
|
+
const [txid, vout] = output.outpoint.split('.');
|
|
88
|
+
const tx = (_a = beef.findTxid(txid)) === null || _a === void 0 ? void 0 : _a.tx;
|
|
89
|
+
if (tx == null) {
|
|
90
|
+
throw new Error(`beef must contain txid ${txid}`);
|
|
76
91
|
}
|
|
77
|
-
|
|
78
|
-
|
|
92
|
+
const lockingScript = tx.outputs[Number(vout)].lockingScript;
|
|
93
|
+
return lockingScript;
|
|
94
|
+
}
|
|
95
|
+
async lookupValue(key, defaultValue, limit) {
|
|
96
|
+
const lor = await this.getOutputs(key, limit);
|
|
97
|
+
const r = { value: defaultValue, outpoint: undefined, lor };
|
|
98
|
+
const { outputs } = lor;
|
|
99
|
+
if (outputs.length === 0) {
|
|
100
|
+
return r;
|
|
79
101
|
}
|
|
80
|
-
|
|
102
|
+
const output = outputs.slice(-1)[0];
|
|
103
|
+
r.outpoint = output.outpoint;
|
|
104
|
+
let field;
|
|
81
105
|
try {
|
|
82
|
-
if (
|
|
83
|
-
throw new Error('
|
|
106
|
+
if (lor.BEEF === undefined) {
|
|
107
|
+
throw new Error('entire transactions listOutputs option must return valid BEEF');
|
|
84
108
|
}
|
|
85
|
-
const
|
|
86
|
-
|
|
109
|
+
const lockingScript = this.getLockingScript(output, Beef_js_1.Beef.fromBinary(lor.BEEF));
|
|
110
|
+
const decoded = PushDrop_js_1.default.decode(lockingScript);
|
|
111
|
+
if (decoded.fields.length < 1 || decoded.fields.length > 2) {
|
|
87
112
|
throw new Error('Invalid token.');
|
|
88
113
|
}
|
|
89
|
-
|
|
114
|
+
field = decoded.fields[0];
|
|
90
115
|
}
|
|
91
116
|
catch (_) {
|
|
92
|
-
throw new Error(`Invalid value found. You need to call set to collapse the corrupted state (or relinquish the corrupted ${
|
|
117
|
+
throw new Error(`Invalid value found. You need to call set to collapse the corrupted state (or relinquish the corrupted ${outputs[0].outpoint} output from the ${this.context} basket) before you can get this value again.`);
|
|
93
118
|
}
|
|
94
119
|
if (!this.encrypt) {
|
|
95
|
-
|
|
120
|
+
r.value = Utils.toUTF8(field);
|
|
96
121
|
}
|
|
97
122
|
else {
|
|
98
123
|
const { plaintext } = await this.wallet.decrypt({
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
124
|
+
...this.getProtocol(key),
|
|
125
|
+
ciphertext: field
|
|
126
|
+
});
|
|
127
|
+
r.value = Utils.toUTF8(plaintext);
|
|
128
|
+
}
|
|
129
|
+
return r;
|
|
130
|
+
}
|
|
131
|
+
getInputs(outputs) {
|
|
132
|
+
const inputs = [];
|
|
133
|
+
for (let i = 0; i < outputs.length; i++) {
|
|
134
|
+
inputs.push({
|
|
135
|
+
outpoint: outputs[i].outpoint,
|
|
136
|
+
unlockingScriptLength: 74,
|
|
137
|
+
inputDescription: 'Previous key-value token'
|
|
102
138
|
});
|
|
103
|
-
return Utils.toUTF8(plaintext);
|
|
104
139
|
}
|
|
140
|
+
return inputs;
|
|
141
|
+
}
|
|
142
|
+
async getSpends(key, outputs, pushdrop, atomicBEEF) {
|
|
143
|
+
const p = this.getProtocol(key);
|
|
144
|
+
const tx = Transaction_js_1.default.fromAtomicBEEF(atomicBEEF);
|
|
145
|
+
const spends = {};
|
|
146
|
+
for (let i = 0; i < outputs.length; i++) {
|
|
147
|
+
const unlocker = pushdrop.unlock(p.protocolID, p.keyID, 'self');
|
|
148
|
+
const unlockingScript = await unlocker.sign(tx, i);
|
|
149
|
+
spends[i] = {
|
|
150
|
+
unlockingScript: unlockingScript.toHex()
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return spends;
|
|
105
154
|
}
|
|
106
155
|
/**
|
|
107
156
|
* Sets or updates the value associated with a given key.
|
|
@@ -117,87 +166,64 @@ class LocalKVStore {
|
|
|
117
166
|
* @returns {Promise<OutpointString>} A promise that resolves to the outpoint string (txid.vout) of the new or updated token output.
|
|
118
167
|
*/
|
|
119
168
|
async set(key, value) {
|
|
169
|
+
const current = await this.lookupValue(key, undefined, 10);
|
|
170
|
+
if (current.value === value) {
|
|
171
|
+
if (current.outpoint === undefined) {
|
|
172
|
+
throw new Error('outpoint must be valid when value is valid and unchanged');
|
|
173
|
+
}
|
|
174
|
+
// Don't create a new transaction if the value doesn't need to change...
|
|
175
|
+
return current.outpoint;
|
|
176
|
+
}
|
|
177
|
+
const protocol = this.getProtocol(key);
|
|
120
178
|
let valueAsArray = Utils.toArray(value, 'utf8');
|
|
121
179
|
if (this.encrypt) {
|
|
122
180
|
const { ciphertext } = await this.wallet.encrypt({
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
keyID: key
|
|
181
|
+
...protocol,
|
|
182
|
+
plaintext: valueAsArray
|
|
126
183
|
});
|
|
127
184
|
valueAsArray = ciphertext;
|
|
128
185
|
}
|
|
129
186
|
const pushdrop = new PushDrop_js_1.default(this.wallet, this.originator);
|
|
130
|
-
const lockingScript = await pushdrop.lock([valueAsArray],
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
inputs,
|
|
150
|
-
outputs: [{
|
|
151
|
-
lockingScript: lockingScript.toHex(),
|
|
152
|
-
satoshis: 1,
|
|
153
|
-
outputDescription: 'Key-value token'
|
|
154
|
-
}],
|
|
155
|
-
options: {
|
|
156
|
-
acceptDelayedBroadcast: false,
|
|
157
|
-
randomizeOutputs: false
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
if (typeof signableTransaction !== 'object') {
|
|
161
|
-
throw new Error('Wallet did not return a signable transaction when expected.');
|
|
162
|
-
}
|
|
163
|
-
const tx = Transaction_js_1.default.fromAtomicBEEF(signableTransaction.tx);
|
|
164
|
-
const spends = {};
|
|
165
|
-
for (let i = 0; i < results.outputs.length; i++) {
|
|
166
|
-
const unlocker = pushdrop.unlock([2, this.context], key, 'self');
|
|
167
|
-
const unlockingScript = await unlocker.sign(tx, i);
|
|
168
|
-
spends[i] = {
|
|
169
|
-
unlockingScript: unlockingScript.toHex()
|
|
170
|
-
};
|
|
187
|
+
const lockingScript = await pushdrop.lock([valueAsArray], protocol.protocolID, protocol.keyID, 'self');
|
|
188
|
+
const { outputs, BEEF: inputBEEF } = current.lor;
|
|
189
|
+
let outpoint;
|
|
190
|
+
try {
|
|
191
|
+
const inputs = this.getInputs(outputs);
|
|
192
|
+
const { txid, signableTransaction } = await this.wallet.createAction({
|
|
193
|
+
description: `Update ${key} in ${this.context}`,
|
|
194
|
+
inputBEEF,
|
|
195
|
+
inputs,
|
|
196
|
+
outputs: [{
|
|
197
|
+
basket: this.context,
|
|
198
|
+
tags: [key],
|
|
199
|
+
lockingScript: lockingScript.toHex(),
|
|
200
|
+
satoshis: 1,
|
|
201
|
+
outputDescription: 'Key-value token'
|
|
202
|
+
}],
|
|
203
|
+
options: {
|
|
204
|
+
acceptDelayedBroadcast: false,
|
|
205
|
+
randomizeOutputs: false
|
|
171
206
|
}
|
|
207
|
+
});
|
|
208
|
+
if (outputs.length > 0 && typeof signableTransaction !== 'object') {
|
|
209
|
+
throw new Error('Wallet did not return a signable transaction when expected.');
|
|
210
|
+
}
|
|
211
|
+
if (signableTransaction == null) {
|
|
212
|
+
outpoint = `${txid}.0`;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
const spends = await this.getSpends(key, outputs, pushdrop, signableTransaction.tx);
|
|
172
216
|
const { txid } = await this.wallet.signAction({
|
|
173
217
|
reference: signableTransaction.reference,
|
|
174
218
|
spends
|
|
175
219
|
});
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
catch (_) {
|
|
179
|
-
// Signing failed, relinquish original outputs
|
|
180
|
-
for (let i = 0; i < results.outputs.length; i++) {
|
|
181
|
-
await this.wallet.relinquishOutput({
|
|
182
|
-
output: results.outputs[i].outpoint,
|
|
183
|
-
basket: this.context
|
|
184
|
-
});
|
|
185
|
-
}
|
|
220
|
+
outpoint = `${txid}.0`;
|
|
186
221
|
}
|
|
187
222
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
satoshis: 1,
|
|
193
|
-
outputDescription: 'Key-value token'
|
|
194
|
-
}],
|
|
195
|
-
options: {
|
|
196
|
-
acceptDelayedBroadcast: false,
|
|
197
|
-
randomizeOutputs: false
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
return `${txid}.0`;
|
|
223
|
+
catch (_) {
|
|
224
|
+
throw new Error(`There are ${outputs.length} outputs with tag ${key} that cannot be unlocked.`);
|
|
225
|
+
}
|
|
226
|
+
return outpoint;
|
|
201
227
|
}
|
|
202
228
|
/**
|
|
203
229
|
* Removes the key-value pair associated with the given key.
|
|
@@ -207,61 +233,46 @@ class LocalKVStore {
|
|
|
207
233
|
* If signing the removal transaction fails, it relinquishes the original outputs instead of spending.
|
|
208
234
|
*
|
|
209
235
|
* @param {string} key - The key to remove.
|
|
210
|
-
* @returns {Promise<string
|
|
236
|
+
* @returns {Promise<string[]>} A promise that resolves to the txids of the removal transactions if successful.
|
|
211
237
|
*/
|
|
212
238
|
async remove(key) {
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
239
|
+
const txids = [];
|
|
240
|
+
for (;;) {
|
|
241
|
+
const { outputs, BEEF: inputBEEF, totalOutputs } = await this.getOutputs(key);
|
|
242
|
+
if (outputs.length > 0) {
|
|
243
|
+
const pushdrop = new PushDrop_js_1.default(this.wallet, this.originator);
|
|
244
|
+
try {
|
|
245
|
+
const inputs = this.getInputs(outputs);
|
|
246
|
+
const { signableTransaction } = await this.wallet.createAction({
|
|
247
|
+
description: `Remove ${key} in ${this.context}`,
|
|
248
|
+
inputBEEF,
|
|
249
|
+
inputs,
|
|
250
|
+
options: {
|
|
251
|
+
acceptDelayedBroadcast: false
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
if (typeof signableTransaction !== 'object') {
|
|
255
|
+
throw new Error('Wallet did not return a signable transaction when expected.');
|
|
256
|
+
}
|
|
257
|
+
const spends = await this.getSpends(key, outputs, pushdrop, signableTransaction.tx);
|
|
258
|
+
const { txid } = await this.wallet.signAction({
|
|
259
|
+
reference: signableTransaction.reference,
|
|
260
|
+
spends
|
|
261
|
+
});
|
|
262
|
+
if (txid === undefined) {
|
|
263
|
+
throw new Error('signAction must return a valid txid');
|
|
264
|
+
}
|
|
265
|
+
txids.push(txid);
|
|
266
|
+
}
|
|
267
|
+
catch (_) {
|
|
268
|
+
throw new Error(`There are ${totalOutputs} outputs with tag ${key} that cannot be unlocked.`);
|
|
237
269
|
}
|
|
238
|
-
});
|
|
239
|
-
if (typeof signableTransaction !== 'object') {
|
|
240
|
-
throw new Error('Wallet did not return a signable transaction when expected.');
|
|
241
|
-
}
|
|
242
|
-
const tx = Transaction_js_1.default.fromAtomicBEEF(signableTransaction.tx);
|
|
243
|
-
const spends = {};
|
|
244
|
-
for (let i = 0; i < results.outputs.length; i++) {
|
|
245
|
-
const unlocker = pushdrop.unlock([2, this.context], key, 'self');
|
|
246
|
-
const unlockingScript = await unlocker.sign(tx, i);
|
|
247
|
-
spends[i] = {
|
|
248
|
-
unlockingScript: unlockingScript.toHex()
|
|
249
|
-
};
|
|
250
270
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
spends
|
|
254
|
-
});
|
|
255
|
-
return txid;
|
|
256
|
-
}
|
|
257
|
-
catch (_) {
|
|
258
|
-
for (let i = 0; i < results.outputs.length; i++) {
|
|
259
|
-
await this.wallet.relinquishOutput({
|
|
260
|
-
output: results.outputs[i].outpoint,
|
|
261
|
-
basket: this.context
|
|
262
|
-
});
|
|
271
|
+
if (outputs.length === totalOutputs) {
|
|
272
|
+
break;
|
|
263
273
|
}
|
|
264
274
|
}
|
|
275
|
+
return txids;
|
|
265
276
|
}
|
|
266
277
|
}
|
|
267
278
|
exports.default = LocalKVStore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalKVStore.js","sourceRoot":"","sources":["../../../../src/kvstore/LocalKVStore.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"LocalKVStore.js","sourceRoot":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GAAG,OAAO,IAAI,CAAC,OAAO,EAAE;wBAC/C,SAAS;wBACT,MAAM;wBACN,OAAO,EAAE;4BACP,sBAAsB,EAAE,KAAK;yBAC9B;qBACF,CAAC,CAAA;oBACF,IAAI,OAAO,mBAAmB,KAAK,QAAQ,EAAE;wBAC3C,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAA;qBAC/E;oBACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,CAAC,EAAE,CAAC,CAAA;oBACnF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;wBAC5C,SAAS,EAAE,mBAAmB,CAAC,SAAS;wBACxC,MAAM;qBACP,CAAC,CAAA;oBACF,IAAI,IAAI,KAAK,SAAS,EAAE;wBAAE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;qBAAE;oBAClF,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;iBACjB;gBAAC,OAAO,CAAC,EAAE;oBACV,MAAM,IAAI,KAAK,CAAC,aAAa,YAAY,qBAAqB,GAAG,2BAA2B,CAAC,CAAA;iBAC9F;aACF;YACD,IAAI,OAAO,CAAC,MAAM,KAAK,YAAY,EAAE;gBAAE,MAAK;aAAE;SAC/C;QACD,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AA3QD,+BA2QC"}
|
|
@@ -26,11 +26,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.StorageUploader = void 0;
|
|
27
27
|
const AuthFetch_js_1 = require("../auth/clients/AuthFetch.js");
|
|
28
28
|
const StorageUtils = __importStar(require("./StorageUtils.js"));
|
|
29
|
+
/**
|
|
30
|
+
* The StorageUploader class provides client-side methods for:
|
|
31
|
+
* - Uploading files with a specified retention period
|
|
32
|
+
* - Finding file metadata by UHRP URL
|
|
33
|
+
* - Listing all user uploads
|
|
34
|
+
* - Renewing an existing advertisement's expiry time
|
|
35
|
+
*/
|
|
29
36
|
class StorageUploader {
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new StorageUploader instance.
|
|
39
|
+
* @param {UploaderConfig} config - An object containing the storage server's URL and a wallet interface
|
|
40
|
+
*/
|
|
30
41
|
constructor(config) {
|
|
31
42
|
this.baseURL = config.storageURL;
|
|
32
43
|
this.authFetch = new AuthFetch_js_1.AuthFetch(config.wallet);
|
|
33
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Requests information from the server to upload a file (including presigned URL and headers).
|
|
47
|
+
* @private
|
|
48
|
+
* @param {number} fileSize - The size of the file, in bytes
|
|
49
|
+
* @param {number} retentionPeriod - The desired hosting time, in minutes
|
|
50
|
+
* @returns {Promise<{ uploadURL: string; requiredHeaders: Record<string, string>; amount?: number }>}
|
|
51
|
+
* @throws {Error} If the server returns a non-OK response or an error status
|
|
52
|
+
*/
|
|
34
53
|
async getUploadInfo(fileSize, retentionPeriod) {
|
|
35
54
|
const url = `${this.baseURL}/upload`;
|
|
36
55
|
const body = { fileSize, retentionPeriod };
|
|
@@ -52,6 +71,15 @@ class StorageUploader {
|
|
|
52
71
|
amount: data.amount
|
|
53
72
|
};
|
|
54
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Performs the actual file upload (HTTP PUT) to the presigned URL returned by the server.
|
|
76
|
+
* @private
|
|
77
|
+
* @param {string} uploadURL - The presigned URL where the file is to be uploaded
|
|
78
|
+
* @param {UploadableFile} file - The file to upload, including its raw data and MIME type
|
|
79
|
+
* @param {Record<string, string>} requiredHeaders - Additional headers required by the server (e.g. content-length)
|
|
80
|
+
* @returns {Promise<UploadFileResult>} An object indicating whether publishing was successful and the resulting UHRP URL
|
|
81
|
+
* @throws {Error} If the server returns a non-OK response
|
|
82
|
+
*/
|
|
55
83
|
async uploadFile(uploadURL, file, requiredHeaders) {
|
|
56
84
|
const body = Uint8Array.from(file.data);
|
|
57
85
|
const response = await fetch(uploadURL, {
|
|
@@ -72,26 +100,106 @@ class StorageUploader {
|
|
|
72
100
|
};
|
|
73
101
|
}
|
|
74
102
|
/**
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
*/
|
|
103
|
+
* Publishes a file to the storage server with the specified retention period.
|
|
104
|
+
*
|
|
105
|
+
* This will:
|
|
106
|
+
* 1. Request an upload URL from the server.
|
|
107
|
+
* 2. Perform an HTTP PUT to upload the file’s raw bytes.
|
|
108
|
+
* 3. Return a UHRP URL referencing the file once published.
|
|
109
|
+
*
|
|
110
|
+
* @param {Object} params
|
|
111
|
+
* @param {UploadableFile} params.file - The file data + type
|
|
112
|
+
* @param {number} params.retentionPeriod - Number of minutes to host the file
|
|
113
|
+
* @returns {Promise<UploadFileResult>} An object with the file's UHRP URL
|
|
114
|
+
* @throws {Error} If the server or upload step returns a non-OK response
|
|
115
|
+
*/
|
|
89
116
|
async publishFile(params) {
|
|
90
117
|
const { file, retentionPeriod } = params;
|
|
91
118
|
const fileSize = file.data.length;
|
|
92
119
|
const { uploadURL, requiredHeaders } = await this.getUploadInfo(fileSize, retentionPeriod);
|
|
93
120
|
return await this.uploadFile(uploadURL, file, requiredHeaders);
|
|
94
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Retrieves metadata for a file matching the given UHRP URL from the `/find` route.
|
|
124
|
+
* @param {string} uhrpUrl - The UHRP URL, e.g. "uhrp://abcd..."
|
|
125
|
+
* @returns {Promise<FindFileData>} An object with file name, size, MIME type, and expiry time
|
|
126
|
+
* @throws {Error} If the server or the route returns an error
|
|
127
|
+
*/
|
|
128
|
+
async findFile(uhrpUrl) {
|
|
129
|
+
var _a, _b;
|
|
130
|
+
const url = new URL(`${this.baseURL}/find`);
|
|
131
|
+
url.searchParams.set('uhrpUrl', uhrpUrl);
|
|
132
|
+
const response = await this.authFetch.fetch(url.toString(), {
|
|
133
|
+
method: 'GET'
|
|
134
|
+
});
|
|
135
|
+
if (!response.ok) {
|
|
136
|
+
throw new Error(`findFile request failed: HTTP ${response.status}`);
|
|
137
|
+
}
|
|
138
|
+
const data = await response.json();
|
|
139
|
+
if (data.status === 'error') {
|
|
140
|
+
const errCode = (_a = data.code) !== null && _a !== void 0 ? _a : 'unknown-code';
|
|
141
|
+
const errDesc = (_b = data.description) !== null && _b !== void 0 ? _b : 'no-description';
|
|
142
|
+
throw new Error(`findFile returned an error: ${errCode} - ${errDesc}`);
|
|
143
|
+
}
|
|
144
|
+
return data.data;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Lists all advertisements belonging to the user from the `/list` route.
|
|
148
|
+
* @returns {Promise<any>} The array of uploads returned by the server
|
|
149
|
+
* @throws {Error} If the server or the route returns an error
|
|
150
|
+
*/
|
|
151
|
+
async listUploads() {
|
|
152
|
+
var _a, _b;
|
|
153
|
+
const url = `${this.baseURL}/list`;
|
|
154
|
+
const response = await this.authFetch.fetch(url, {
|
|
155
|
+
method: 'GET'
|
|
156
|
+
});
|
|
157
|
+
if (!response.ok) {
|
|
158
|
+
throw new Error(`listUploads request failed: HTTP ${response.status}`);
|
|
159
|
+
}
|
|
160
|
+
const data = await response.json();
|
|
161
|
+
if (data.status === 'error') {
|
|
162
|
+
const errCode = (_a = data.code) !== null && _a !== void 0 ? _a : 'unknown-code';
|
|
163
|
+
const errDesc = (_b = data.description) !== null && _b !== void 0 ? _b : 'no-description';
|
|
164
|
+
throw new Error(`listUploads returned an error: ${errCode} - ${errDesc}`);
|
|
165
|
+
}
|
|
166
|
+
return data.uploads;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Renews the hosting time for an existing file advertisement identified by uhrpUrl.
|
|
170
|
+
* Calls the `/renew` route to add `additionalMinutes` to the GCS customTime
|
|
171
|
+
* and re-mint the advertisement token on-chain.
|
|
172
|
+
*
|
|
173
|
+
* @param {string} uhrpUrl - The UHRP URL of the file (e.g., "uhrp://abcd1234...")
|
|
174
|
+
* @param {number} additionalMinutes - The number of minutes to extend
|
|
175
|
+
* @returns {Promise<RenewFileResult>} An object with the new and previous expiry times, plus any cost
|
|
176
|
+
* @throws {Error} If the request fails or the server returns an error
|
|
177
|
+
*/
|
|
178
|
+
async renewFile(uhrpUrl, additionalMinutes) {
|
|
179
|
+
var _a, _b;
|
|
180
|
+
const url = `${this.baseURL}/renew`;
|
|
181
|
+
const body = { uhrpUrl, additionalMinutes };
|
|
182
|
+
const response = await this.authFetch.fetch(url, {
|
|
183
|
+
method: 'POST',
|
|
184
|
+
headers: { 'Content-Type': 'application/json' },
|
|
185
|
+
body: JSON.stringify(body)
|
|
186
|
+
});
|
|
187
|
+
if (!response.ok) {
|
|
188
|
+
throw new Error(`renewFile request failed: HTTP ${response.status}`);
|
|
189
|
+
}
|
|
190
|
+
const data = await response.json();
|
|
191
|
+
if (data.status === 'error') {
|
|
192
|
+
const errCode = (_a = data.code) !== null && _a !== void 0 ? _a : 'unknown-code';
|
|
193
|
+
const errDesc = (_b = data.description) !== null && _b !== void 0 ? _b : 'no-description';
|
|
194
|
+
throw new Error(`renewFile returned an error: ${errCode} - ${errDesc}`);
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
status: data.status,
|
|
198
|
+
prevExpiryTime: data.prevExpiryTime,
|
|
199
|
+
newExpiryTime: data.newExpiryTime,
|
|
200
|
+
amount: data.amount
|
|
201
|
+
};
|
|
202
|
+
}
|
|
95
203
|
}
|
|
96
204
|
exports.StorageUploader = StorageUploader;
|
|
97
205
|
//# sourceMappingURL=StorageUploader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageUploader.js","sourceRoot":"","sources":["../../../../src/storage/StorageUploader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAAwD;AAExD,gEAAiD;
|
|
1
|
+
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