@mysten/walrus 0.2.3 → 0.3.1
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/CHANGELOG.md +13 -0
- package/README.md +83 -0
- package/dist/cjs/client.d.ts +6 -6
- package/dist/cjs/client.js +29 -29
- package/dist/cjs/client.js.map +2 -2
- package/dist/{esm/read/quilt.d.ts → cjs/quilt/reader.d.ts} +7 -3
- package/dist/cjs/{read/quilt.js → quilt/reader.js} +32 -18
- package/dist/cjs/quilt/reader.js.map +7 -0
- package/dist/cjs/quilt/write.d.ts +21 -0
- package/dist/cjs/quilt/write.js +167 -0
- package/dist/cjs/quilt/write.js.map +7 -0
- package/dist/cjs/types.d.ts +7 -7
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/{fan-out-proxy → upload-relay}/client.d.ts +7 -7
- package/dist/cjs/{fan-out-proxy → upload-relay}/client.js +9 -9
- package/dist/cjs/upload-relay/client.js.map +7 -0
- package/dist/cjs/utils/bcs.d.ts +11 -5
- package/dist/cjs/utils/bcs.js +10 -6
- package/dist/cjs/utils/bcs.js.map +2 -2
- package/dist/cjs/utils/quilts.d.ts +6 -1
- package/dist/cjs/utils/quilts.js +12 -2
- package/dist/cjs/utils/quilts.js.map +2 -2
- package/dist/esm/client.d.ts +6 -6
- package/dist/esm/client.js +29 -29
- package/dist/esm/client.js.map +2 -2
- package/dist/{cjs/read/quilt.d.ts → esm/quilt/reader.d.ts} +7 -3
- package/dist/esm/{read/quilt.js → quilt/reader.js} +31 -17
- package/dist/esm/quilt/reader.js.map +7 -0
- package/dist/esm/quilt/write.d.ts +21 -0
- package/dist/esm/quilt/write.js +156 -0
- package/dist/esm/quilt/write.js.map +7 -0
- package/dist/esm/types.d.ts +7 -7
- package/dist/esm/{fan-out-proxy → upload-relay}/client.d.ts +7 -7
- package/dist/esm/{fan-out-proxy → upload-relay}/client.js +9 -9
- package/dist/esm/upload-relay/client.js.map +7 -0
- package/dist/esm/utils/bcs.d.ts +11 -5
- package/dist/esm/utils/bcs.js +10 -6
- package/dist/esm/utils/bcs.js.map +2 -2
- package/dist/esm/utils/quilts.d.ts +6 -1
- package/dist/esm/utils/quilts.js +12 -2
- package/dist/esm/utils/quilts.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/dist/cjs/fan-out-proxy/client.js.map +0 -7
- package/dist/cjs/read/quilt.js.map +0 -7
- package/dist/esm/fan-out-proxy/client.js.map +0 -7
- package/dist/esm/read/quilt.js.map +0 -7
package/dist/cjs/utils/quilts.js
CHANGED
|
@@ -18,10 +18,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var quilts_exports = {};
|
|
20
20
|
__export(quilts_exports, {
|
|
21
|
+
BLOB_IDENTIFIER_SIZE_BYTES_LENGTH: () => BLOB_IDENTIFIER_SIZE_BYTES_LENGTH,
|
|
22
|
+
HAS_TAGS_FLAG: () => HAS_TAGS_FLAG,
|
|
23
|
+
MAX_BLOB_IDENTIFIER_BYTES_LENGTH: () => MAX_BLOB_IDENTIFIER_BYTES_LENGTH,
|
|
24
|
+
MAX_NUM_SLIVERS_FOR_QUILT_INDEX: () => MAX_NUM_SLIVERS_FOR_QUILT_INDEX,
|
|
21
25
|
QUILT_INDEX_PREFIX_SIZE: () => QUILT_INDEX_PREFIX_SIZE,
|
|
22
26
|
QUILT_INDEX_SIZE_BYTES_LENGTH: () => QUILT_INDEX_SIZE_BYTES_LENGTH,
|
|
23
27
|
QUILT_PATCH_BLOB_HEADER_SIZE: () => QUILT_PATCH_BLOB_HEADER_SIZE,
|
|
24
28
|
QUILT_VERSION_BYTES_LENGTH: () => QUILT_VERSION_BYTES_LENGTH,
|
|
29
|
+
TAGS_SIZE_BYTES_LENGTH: () => TAGS_SIZE_BYTES_LENGTH,
|
|
25
30
|
computeSymbolSize: () => computeSymbolSize,
|
|
26
31
|
parseQuiltPatchId: () => parseQuiltPatchId
|
|
27
32
|
});
|
|
@@ -32,6 +37,11 @@ const QUILT_INDEX_SIZE_BYTES_LENGTH = 4;
|
|
|
32
37
|
const QUILT_VERSION_BYTES_LENGTH = 1;
|
|
33
38
|
const QUILT_INDEX_PREFIX_SIZE = QUILT_VERSION_BYTES_LENGTH + QUILT_INDEX_SIZE_BYTES_LENGTH;
|
|
34
39
|
const QUILT_PATCH_BLOB_HEADER_SIZE = 1 + 4 + 1;
|
|
40
|
+
const BLOB_IDENTIFIER_SIZE_BYTES_LENGTH = 2;
|
|
41
|
+
const TAGS_SIZE_BYTES_LENGTH = 2;
|
|
42
|
+
const MAX_BLOB_IDENTIFIER_BYTES_LENGTH = (1 << 8 * BLOB_IDENTIFIER_SIZE_BYTES_LENGTH) - 1;
|
|
43
|
+
const MAX_NUM_SLIVERS_FOR_QUILT_INDEX = 10;
|
|
44
|
+
const HAS_TAGS_FLAG = 1 << 0;
|
|
35
45
|
const REQUIRED_ALIGNMENT_BY_ENCODING_TYPE = {
|
|
36
46
|
RS2: 2,
|
|
37
47
|
RedStuff: 2
|
|
@@ -40,7 +50,7 @@ const MAX_SYMBOL_SIZE_BY_ENCODING_TYPE = {
|
|
|
40
50
|
RS2: 2 ** 16 - 1,
|
|
41
51
|
RedStuff: 2 ** 16 - 1
|
|
42
52
|
};
|
|
43
|
-
function computeSymbolSize(blobsSizes, nColumns, nRows, maxNumColumnsForQuiltIndex, encodingType) {
|
|
53
|
+
function computeSymbolSize(blobsSizes, nColumns, nRows, maxNumColumnsForQuiltIndex, encodingType = "RS2") {
|
|
44
54
|
if (blobsSizes.length > nColumns) {
|
|
45
55
|
throw new Error("Too many blobs, the number of blobs must be less than the number of columns");
|
|
46
56
|
}
|
|
@@ -61,7 +71,7 @@ function computeSymbolSize(blobsSizes, nColumns, nRows, maxNumColumnsForQuiltInd
|
|
|
61
71
|
minVal = mid + 1;
|
|
62
72
|
}
|
|
63
73
|
}
|
|
64
|
-
const symbolSize = Math.ceil(minVal / REQUIRED_ALIGNMENT_BY_ENCODING_TYPE[encodingType]);
|
|
74
|
+
const symbolSize = Math.ceil(minVal / REQUIRED_ALIGNMENT_BY_ENCODING_TYPE[encodingType]) * REQUIRED_ALIGNMENT_BY_ENCODING_TYPE[encodingType];
|
|
65
75
|
if (!canBlobsFitIntoMatrix(blobsSizes, nColumns, symbolSize * nRows)) {
|
|
66
76
|
throw new Error("Quilt oversize");
|
|
67
77
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/quilts.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { EncodingType } from '../types.js';\nimport { QuiltPatchId } from './bcs.js';\nimport { fromUrlSafeBase64 } from './index.js';\n\nexport const QUILT_INDEX_SIZE_BYTES_LENGTH = 4;\nexport const QUILT_VERSION_BYTES_LENGTH = 1;\nexport const QUILT_INDEX_PREFIX_SIZE = QUILT_VERSION_BYTES_LENGTH + QUILT_INDEX_SIZE_BYTES_LENGTH;\nexport const QUILT_PATCH_BLOB_HEADER_SIZE = 1 + 4 + 1; // bcs length of QuiltPatchBlobHeader\n\nconst REQUIRED_ALIGNMENT_BY_ENCODING_TYPE = {\n\tRS2: 2,\n\tRedStuff: 2,\n};\n\nconst MAX_SYMBOL_SIZE_BY_ENCODING_TYPE = {\n\tRS2: 2 ** 16 - 1,\n\tRedStuff: 2 ** 16 - 1,\n};\n\n/**\n * Finds the minimum symbol size needed to store blobs in a fixed number of columns.\n * Each blob must be stored in consecutive columns exclusively.\n *\n * A binary search is used to find the minimum symbol size:\n * 1. Compute the upper and lower bounds for the symbol size.\n * 2. Check if the all the blobs can be fit into the quilt with the current symbol size.\n * 3. Adjust the bounds based on the result and repeat until the symbol size is found.\n *\n * @param blobsSizes - Slice of blob lengths, including the index size as the first element.\n * Note that the len of the blob_size should be between 1 and n_columns.\n * @param nColumns - Number of columns available.\n * @param nRows - Number of rows available.\n * @param maxNumColumnsForQuiltIndex - The maximum number of columns that can be used to\n * store the quilt index.\n * @param encodingType - The encoding type to use.\n *\n * @returns The minimum symbol size needed.\n **/\nexport function computeSymbolSize(\n\tblobsSizes: number[],\n\tnColumns: number,\n\tnRows: number,\n\tmaxNumColumnsForQuiltIndex: number,\n\tencodingType: EncodingType,\n): number {\n\tif (blobsSizes.length > nColumns) {\n\t\tthrow new Error('Too many blobs, the number of blobs must be less than the number of columns');\n\t}\n\n\tif (blobsSizes.length === 0) {\n\t\tthrow new Error('No blobs provided');\n\t}\n\n\tlet minVal = Math.max(\n\t\tblobsSizes.reduce((acc, size) => acc + size, 0) / (nColumns * nRows),\n\t\tblobsSizes[0] / (nRows * maxNumColumnsForQuiltIndex),\n\t\tMath.ceil(QUILT_INDEX_PREFIX_SIZE / nRows),\n\t);\n\n\tlet maxVal = Math.ceil((Math.max(...blobsSizes) / (nColumns / blobsSizes.length)) * nRows);\n\n\twhile (minVal < maxVal) {\n\t\tconst mid = (minVal + maxVal) / 2;\n\t\tif (canBlobsFitIntoMatrix(blobsSizes, nColumns, mid * nRows)) {\n\t\t\tmaxVal = mid;\n\t\t} else {\n\t\t\tminVal = mid + 1;\n\t\t}\n\t}\n\n\tconst symbolSize
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,iBAA6B;AAC7B,mBAAkC;AAE3B,MAAM,gCAAgC;AACtC,MAAM,6BAA6B;AACnC,MAAM,0BAA0B,6BAA6B;AAC7D,MAAM,+BAA+B,IAAI,IAAI;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { EncodingType } from '../types.js';\nimport { QuiltPatchId } from './bcs.js';\nimport { fromUrlSafeBase64 } from './index.js';\n\nexport const QUILT_INDEX_SIZE_BYTES_LENGTH = 4;\nexport const QUILT_VERSION_BYTES_LENGTH = 1;\nexport const QUILT_INDEX_PREFIX_SIZE = QUILT_VERSION_BYTES_LENGTH + QUILT_INDEX_SIZE_BYTES_LENGTH;\nexport const QUILT_PATCH_BLOB_HEADER_SIZE = 1 + 4 + 1; // bcs length of QuiltPatchBlobHeader\n\nexport const BLOB_IDENTIFIER_SIZE_BYTES_LENGTH = 2;\nexport const TAGS_SIZE_BYTES_LENGTH = 2;\nexport const MAX_BLOB_IDENTIFIER_BYTES_LENGTH = (1 << (8 * BLOB_IDENTIFIER_SIZE_BYTES_LENGTH)) - 1;\nexport const MAX_NUM_SLIVERS_FOR_QUILT_INDEX = 10;\n\nexport const HAS_TAGS_FLAG = 1 << 0;\n\nconst REQUIRED_ALIGNMENT_BY_ENCODING_TYPE = {\n\tRS2: 2,\n\tRedStuff: 2,\n};\n\nconst MAX_SYMBOL_SIZE_BY_ENCODING_TYPE = {\n\tRS2: 2 ** 16 - 1,\n\tRedStuff: 2 ** 16 - 1,\n};\n\n/**\n * Finds the minimum symbol size needed to store blobs in a fixed number of columns.\n * Each blob must be stored in consecutive columns exclusively.\n *\n * A binary search is used to find the minimum symbol size:\n * 1. Compute the upper and lower bounds for the symbol size.\n * 2. Check if the all the blobs can be fit into the quilt with the current symbol size.\n * 3. Adjust the bounds based on the result and repeat until the symbol size is found.\n *\n * @param blobsSizes - Slice of blob lengths, including the index size as the first element.\n * Note that the len of the blob_size should be between 1 and n_columns.\n * @param nColumns - Number of columns available.\n * @param nRows - Number of rows available.\n * @param maxNumColumnsForQuiltIndex - The maximum number of columns that can be used to\n * store the quilt index.\n * @param encodingType - The encoding type to use.\n *\n * @returns The minimum symbol size needed.\n **/\nexport function computeSymbolSize(\n\tblobsSizes: number[],\n\tnColumns: number,\n\tnRows: number,\n\tmaxNumColumnsForQuiltIndex: number,\n\tencodingType: EncodingType = 'RS2',\n): number {\n\tif (blobsSizes.length > nColumns) {\n\t\tthrow new Error('Too many blobs, the number of blobs must be less than the number of columns');\n\t}\n\n\tif (blobsSizes.length === 0) {\n\t\tthrow new Error('No blobs provided');\n\t}\n\n\tlet minVal = Math.max(\n\t\tblobsSizes.reduce((acc, size) => acc + size, 0) / (nColumns * nRows),\n\t\tblobsSizes[0] / (nRows * maxNumColumnsForQuiltIndex),\n\t\tMath.ceil(QUILT_INDEX_PREFIX_SIZE / nRows),\n\t);\n\n\tlet maxVal = Math.ceil((Math.max(...blobsSizes) / (nColumns / blobsSizes.length)) * nRows);\n\n\twhile (minVal < maxVal) {\n\t\tconst mid = (minVal + maxVal) / 2;\n\t\tif (canBlobsFitIntoMatrix(blobsSizes, nColumns, mid * nRows)) {\n\t\t\tmaxVal = mid;\n\t\t} else {\n\t\t\tminVal = mid + 1;\n\t\t}\n\t}\n\n\tconst symbolSize =\n\t\tMath.ceil(minVal / REQUIRED_ALIGNMENT_BY_ENCODING_TYPE[encodingType]) *\n\t\tREQUIRED_ALIGNMENT_BY_ENCODING_TYPE[encodingType];\n\n\tif (!canBlobsFitIntoMatrix(blobsSizes, nColumns, symbolSize * nRows)) {\n\t\tthrow new Error('Quilt oversize');\n\t}\n\n\tif (symbolSize > MAX_SYMBOL_SIZE_BY_ENCODING_TYPE[encodingType]) {\n\t\tthrow new Error(\n\t\t\t`Quilt oversize: the resulting symbol size ${symbolSize} is larger than the maximum symbol size ${MAX_SYMBOL_SIZE_BY_ENCODING_TYPE[encodingType]}; remove some blobs`,\n\t\t);\n\t}\n\n\treturn symbolSize;\n}\n\nfunction canBlobsFitIntoMatrix(\n\tblobsSizes: number[],\n\tnColumns: number,\n\tcolumnSize: number,\n): boolean {\n\treturn blobsSizes.reduce((acc, size) => acc + Math.ceil(size / columnSize), 0) <= nColumns;\n}\n\nexport function parseQuiltPatchId(id: string) {\n\treturn QuiltPatchId.parse(fromUrlSafeBase64(id));\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,iBAA6B;AAC7B,mBAAkC;AAE3B,MAAM,gCAAgC;AACtC,MAAM,6BAA6B;AACnC,MAAM,0BAA0B,6BAA6B;AAC7D,MAAM,+BAA+B,IAAI,IAAI;AAE7C,MAAM,oCAAoC;AAC1C,MAAM,yBAAyB;AAC/B,MAAM,oCAAoC,KAAM,IAAI,qCAAsC;AAC1F,MAAM,kCAAkC;AAExC,MAAM,gBAAgB,KAAK;AAElC,MAAM,sCAAsC;AAAA,EAC3C,KAAK;AAAA,EACL,UAAU;AACX;AAEA,MAAM,mCAAmC;AAAA,EACxC,KAAK,KAAK,KAAK;AAAA,EACf,UAAU,KAAK,KAAK;AACrB;AAqBO,SAAS,kBACf,YACA,UACA,OACA,4BACA,eAA6B,OACpB;AACT,MAAI,WAAW,SAAS,UAAU;AACjC,UAAM,IAAI,MAAM,6EAA6E;AAAA,EAC9F;AAEA,MAAI,WAAW,WAAW,GAAG;AAC5B,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACpC;AAEA,MAAI,SAAS,KAAK;AAAA,IACjB,WAAW,OAAO,CAAC,KAAK,SAAS,MAAM,MAAM,CAAC,KAAK,WAAW;AAAA,IAC9D,WAAW,CAAC,KAAK,QAAQ;AAAA,IACzB,KAAK,KAAK,0BAA0B,KAAK;AAAA,EAC1C;AAEA,MAAI,SAAS,KAAK,KAAM,KAAK,IAAI,GAAG,UAAU,KAAK,WAAW,WAAW,UAAW,KAAK;AAEzF,SAAO,SAAS,QAAQ;AACvB,UAAM,OAAO,SAAS,UAAU;AAChC,QAAI,sBAAsB,YAAY,UAAU,MAAM,KAAK,GAAG;AAC7D,eAAS;AAAA,IACV,OAAO;AACN,eAAS,MAAM;AAAA,IAChB;AAAA,EACD;AAEA,QAAM,aACL,KAAK,KAAK,SAAS,oCAAoC,YAAY,CAAC,IACpE,oCAAoC,YAAY;AAEjD,MAAI,CAAC,sBAAsB,YAAY,UAAU,aAAa,KAAK,GAAG;AACrE,UAAM,IAAI,MAAM,gBAAgB;AAAA,EACjC;AAEA,MAAI,aAAa,iCAAiC,YAAY,GAAG;AAChE,UAAM,IAAI;AAAA,MACT,6CAA6C,UAAU,2CAA2C,iCAAiC,YAAY,CAAC;AAAA,IACjJ;AAAA,EACD;AAEA,SAAO;AACR;AAEA,SAAS,sBACR,YACA,UACA,YACU;AACV,SAAO,WAAW,OAAO,CAAC,KAAK,SAAS,MAAM,KAAK,KAAK,OAAO,UAAU,GAAG,CAAC,KAAK;AACnF;AAEO,SAAS,kBAAkB,IAAY;AAC7C,SAAO,wBAAa,UAAM,gCAAkB,EAAE,CAAC;AAChD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { TransactionResult } from '@mysten/sui/transactions';
|
|
|
5
5
|
import { Transaction } from '@mysten/sui/transactions';
|
|
6
6
|
import { Blob } from './contracts/walrus/blob.js';
|
|
7
7
|
import type { BlobStatus } from './storage-node/types.js';
|
|
8
|
-
import type { CertifyBlobOptions, ComputeBlobMetadataOptions, DeleteBlobOptions, ExtendBlobOptions, GetBlobMetadataOptions, GetSecondarySliverOptions, GetSliversOptions, GetStorageConfirmationOptions, GetVerifiedBlobStatusOptions, ProtocolMessageCertificate, ReadBlobOptions, RegisterBlobOptions, SliversForNode, StorageWithSizeOptions, WalrusClientConfig, WalrusClientExtensionOptions, WriteBlobAttributesOptions, WriteBlobOptions,
|
|
8
|
+
import type { CertifyBlobOptions, ComputeBlobMetadataOptions, DeleteBlobOptions, ExtendBlobOptions, GetBlobMetadataOptions, GetSecondarySliverOptions, GetSliversOptions, GetStorageConfirmationOptions, GetVerifiedBlobStatusOptions, ProtocolMessageCertificate, ReadBlobOptions, RegisterBlobOptions, SliversForNode, StorageWithSizeOptions, WalrusClientConfig, WalrusClientExtensionOptions, WriteBlobAttributesOptions, WriteBlobOptions, WriteBlobToUploadRelayOptions, WriteEncodedBlobOptions, WriteEncodedBlobToNodesOptions, WriteMetadataOptions, WriteSliverOptions, WriteSliversToNodeOptions } from './types.js';
|
|
9
9
|
export declare class WalrusClient {
|
|
10
10
|
#private;
|
|
11
11
|
constructor(config: WalrusClientConfig);
|
|
@@ -269,10 +269,10 @@ export declare class WalrusClient {
|
|
|
269
269
|
blobDigest: Uint8Array | (() => Promise<Uint8Array>);
|
|
270
270
|
nonce: Uint8Array;
|
|
271
271
|
}): (transaction: Transaction) => Promise<void>;
|
|
272
|
-
|
|
272
|
+
calculateUploadRelayTip(options: {
|
|
273
273
|
size: number;
|
|
274
274
|
}): Promise<number | bigint>;
|
|
275
|
-
|
|
275
|
+
sendUploadRelayTip({ size, blobDigest, nonce, }: {
|
|
276
276
|
size: number;
|
|
277
277
|
blobDigest: Uint8Array | (() => Promise<Uint8Array>);
|
|
278
278
|
nonce: Uint8Array;
|
|
@@ -537,14 +537,14 @@ export declare class WalrusClient {
|
|
|
537
537
|
*/
|
|
538
538
|
writeEncodedBlobToNodes({ blobId, metadata, sliversByNode, signal, ...options }: WriteEncodedBlobToNodesOptions): Promise<(import("./storage-node/types.js").StorageConfirmation | null)[]>;
|
|
539
539
|
/**
|
|
540
|
-
* Writes a blob to to
|
|
540
|
+
* Writes a blob to to an upload relay
|
|
541
541
|
*
|
|
542
542
|
* @usage
|
|
543
543
|
* ```ts
|
|
544
|
-
* await client.
|
|
544
|
+
* await client.writeBlobToUploadRelay({ blob, deletable, epochs, signer });
|
|
545
545
|
* ```
|
|
546
546
|
*/
|
|
547
|
-
|
|
547
|
+
writeBlobToUploadRelay(options: WriteBlobToUploadRelayOptions): Promise<{
|
|
548
548
|
blobId: string;
|
|
549
549
|
certificate: ProtocolMessageCertificate;
|
|
550
550
|
}>;
|
package/dist/esm/client.js
CHANGED
|
@@ -6,7 +6,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
6
6
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
7
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
8
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
9
|
-
var _storageNodeClient, _wasmUrl, _packageConfig, _suiClient, _objectLoader, _blobMetadataConcurrencyLimit, _readCommittee, _cache,
|
|
9
|
+
var _storageNodeClient, _wasmUrl, _packageConfig, _suiClient, _objectLoader, _blobMetadataConcurrencyLimit, _readCommittee, _cache, _uploadRelayConfig, _uploadRelayClient, _WalrusClient_instances, walType_fn, getPackageId_fn, getWalrusPackageId_fn, getSubsidiesPackageId_fn, wasmBindings_fn, internalReadBlob_fn, getCertificationEpoch_fn, getReadCommittee_fn, forceGetReadCommittee_fn, withWal_fn, loadTipConfig_fn, writeBlobAttributesForRef_fn, executeTransaction_fn, getCommittee_fn, getActiveCommittee_fn, stakingPool_fn, getNodeByShardIndex_fn, retryOnPossibleEpochChange_fn;
|
|
10
10
|
import { bcs } from "@mysten/bcs";
|
|
11
11
|
import { SuiClient } from "@mysten/sui/client";
|
|
12
12
|
import { coinWithBalance, Transaction } from "@mysten/sui/transactions";
|
|
@@ -70,7 +70,7 @@ import { SuiObjectDataLoader } from "./utils/object-loader.js";
|
|
|
70
70
|
import { shuffle, weightedShuffle } from "./utils/randomness.js";
|
|
71
71
|
import { getWasmBindings } from "./wasm.js";
|
|
72
72
|
import { chunk } from "@mysten/utils";
|
|
73
|
-
import {
|
|
73
|
+
import { UploadRelayClient } from "./upload-relay/client.js";
|
|
74
74
|
const _WalrusClient = class _WalrusClient {
|
|
75
75
|
constructor(config) {
|
|
76
76
|
__privateAdd(this, _WalrusClient_instances);
|
|
@@ -82,8 +82,8 @@ const _WalrusClient = class _WalrusClient {
|
|
|
82
82
|
__privateAdd(this, _blobMetadataConcurrencyLimit, 10);
|
|
83
83
|
__privateAdd(this, _readCommittee);
|
|
84
84
|
__privateAdd(this, _cache);
|
|
85
|
-
__privateAdd(this,
|
|
86
|
-
__privateAdd(this,
|
|
85
|
+
__privateAdd(this, _uploadRelayConfig, null);
|
|
86
|
+
__privateAdd(this, _uploadRelayClient, null);
|
|
87
87
|
/** Read a blob from the storage nodes */
|
|
88
88
|
this.readBlob = __privateMethod(this, _WalrusClient_instances, retryOnPossibleEpochChange_fn).call(this, __privateMethod(this, _WalrusClient_instances, internalReadBlob_fn));
|
|
89
89
|
if (config.network && !config.packageConfig) {
|
|
@@ -102,9 +102,9 @@ const _WalrusClient = class _WalrusClient {
|
|
|
102
102
|
__privateSet(this, _packageConfig, config.packageConfig);
|
|
103
103
|
}
|
|
104
104
|
__privateSet(this, _wasmUrl, config.wasmUrl);
|
|
105
|
-
__privateSet(this,
|
|
106
|
-
if (__privateGet(this,
|
|
107
|
-
__privateSet(this,
|
|
105
|
+
__privateSet(this, _uploadRelayConfig, config.uploadRelay ?? null);
|
|
106
|
+
if (__privateGet(this, _uploadRelayConfig)) {
|
|
107
|
+
__privateSet(this, _uploadRelayClient, new UploadRelayClient(__privateGet(this, _uploadRelayConfig)));
|
|
108
108
|
}
|
|
109
109
|
__privateSet(this, _suiClient, config.suiClient ?? new SuiClient({
|
|
110
110
|
url: config.suiRpcUrl
|
|
@@ -618,7 +618,7 @@ const _WalrusClient = class _WalrusClient {
|
|
|
618
618
|
transaction.pure(authPayload);
|
|
619
619
|
};
|
|
620
620
|
}
|
|
621
|
-
async
|
|
621
|
+
async calculateUploadRelayTip(options) {
|
|
622
622
|
const systemState = await this.systemState();
|
|
623
623
|
const encodedSize = encodedBlobLength(options.size, systemState.committee.n_shards);
|
|
624
624
|
const tipConfig = await __privateMethod(this, _WalrusClient_instances, loadTipConfig_fn).call(this);
|
|
@@ -626,7 +626,7 @@ const _WalrusClient = class _WalrusClient {
|
|
|
626
626
|
return 0n;
|
|
627
627
|
}
|
|
628
628
|
const { max, kind } = tipConfig;
|
|
629
|
-
const amount = "const" in kind ? kind.const : BigInt(kind.linear.base) + BigInt(kind.linear.
|
|
629
|
+
const amount = "const" in kind ? kind.const : BigInt(kind.linear.base) + BigInt(kind.linear.perEncodedKib) * ((BigInt(encodedSize) + 1023n) / 1024n);
|
|
630
630
|
if (max != null && amount > max) {
|
|
631
631
|
throw new WalrusClientError(
|
|
632
632
|
`Tip amount (${amount}) exceeds the maximum allowed tip (${max})`
|
|
@@ -634,7 +634,7 @@ const _WalrusClient = class _WalrusClient {
|
|
|
634
634
|
}
|
|
635
635
|
return amount;
|
|
636
636
|
}
|
|
637
|
-
|
|
637
|
+
sendUploadRelayTip({
|
|
638
638
|
size,
|
|
639
639
|
blobDigest,
|
|
640
640
|
nonce
|
|
@@ -643,7 +643,7 @@ const _WalrusClient = class _WalrusClient {
|
|
|
643
643
|
const tipConfig = await __privateMethod(this, _WalrusClient_instances, loadTipConfig_fn).call(this);
|
|
644
644
|
if (tipConfig) {
|
|
645
645
|
transaction.add(this.addAuthPayload({ size, blobDigest, nonce }));
|
|
646
|
-
const amount = await this.
|
|
646
|
+
const amount = await this.calculateUploadRelayTip({ size });
|
|
647
647
|
const { address } = tipConfig;
|
|
648
648
|
transaction.transferObjects(
|
|
649
649
|
[
|
|
@@ -1203,20 +1203,20 @@ const _WalrusClient = class _WalrusClient {
|
|
|
1203
1203
|
return confirmations;
|
|
1204
1204
|
}
|
|
1205
1205
|
/**
|
|
1206
|
-
* Writes a blob to to
|
|
1206
|
+
* Writes a blob to to an upload relay
|
|
1207
1207
|
*
|
|
1208
1208
|
* @usage
|
|
1209
1209
|
* ```ts
|
|
1210
|
-
* await client.
|
|
1210
|
+
* await client.writeBlobToUploadRelay({ blob, deletable, epochs, signer });
|
|
1211
1211
|
* ```
|
|
1212
1212
|
*/
|
|
1213
|
-
async
|
|
1214
|
-
if (!__privateGet(this,
|
|
1215
|
-
throw new WalrusClientError("
|
|
1213
|
+
async writeBlobToUploadRelay(options) {
|
|
1214
|
+
if (!__privateGet(this, _uploadRelayClient)) {
|
|
1215
|
+
throw new WalrusClientError("Upload relay not configured");
|
|
1216
1216
|
}
|
|
1217
|
-
return __privateGet(this,
|
|
1217
|
+
return __privateGet(this, _uploadRelayClient).writeBlob({
|
|
1218
1218
|
...options,
|
|
1219
|
-
requiresTip: !!__privateGet(this,
|
|
1219
|
+
requiresTip: !!__privateGet(this, _uploadRelayConfig)?.sendTip
|
|
1220
1220
|
});
|
|
1221
1221
|
}
|
|
1222
1222
|
/**
|
|
@@ -1265,7 +1265,7 @@ const _WalrusClient = class _WalrusClient {
|
|
|
1265
1265
|
owner,
|
|
1266
1266
|
attributes
|
|
1267
1267
|
}) {
|
|
1268
|
-
if (!__privateGet(this,
|
|
1268
|
+
if (!__privateGet(this, _uploadRelayConfig)) {
|
|
1269
1269
|
const encoded = await this.encodeBlob(blob);
|
|
1270
1270
|
const blobId = encoded.blobId;
|
|
1271
1271
|
const { sliversByNode, metadata: metadata2, rootHash } = encoded;
|
|
@@ -1306,7 +1306,7 @@ const _WalrusClient = class _WalrusClient {
|
|
|
1306
1306
|
const blobId = metadata2.blobId;
|
|
1307
1307
|
const transaction = new Transaction();
|
|
1308
1308
|
transaction.add(
|
|
1309
|
-
this.
|
|
1309
|
+
this.sendUploadRelayTip({
|
|
1310
1310
|
size: blob.length,
|
|
1311
1311
|
blobDigest: metadata2.blobDigest,
|
|
1312
1312
|
nonce: metadata2.nonce
|
|
@@ -1326,7 +1326,7 @@ const _WalrusClient = class _WalrusClient {
|
|
|
1326
1326
|
await __privateGet(this, _suiClient).core.waitForTransaction({
|
|
1327
1327
|
digest: registerResult.digest
|
|
1328
1328
|
});
|
|
1329
|
-
const result = await this.
|
|
1329
|
+
const result = await this.writeBlobToUploadRelay({
|
|
1330
1330
|
blobId,
|
|
1331
1331
|
blob,
|
|
1332
1332
|
nonce: metadata2.nonce,
|
|
@@ -1372,8 +1372,8 @@ _objectLoader = new WeakMap();
|
|
|
1372
1372
|
_blobMetadataConcurrencyLimit = new WeakMap();
|
|
1373
1373
|
_readCommittee = new WeakMap();
|
|
1374
1374
|
_cache = new WeakMap();
|
|
1375
|
-
|
|
1376
|
-
|
|
1375
|
+
_uploadRelayConfig = new WeakMap();
|
|
1376
|
+
_uploadRelayClient = new WeakMap();
|
|
1377
1377
|
_WalrusClient_instances = new WeakSet();
|
|
1378
1378
|
/** The Move type for a WAL coin */
|
|
1379
1379
|
walType_fn = function() {
|
|
@@ -1507,17 +1507,17 @@ withWal_fn = function(amount, owner, source, withSubsidies, fn) {
|
|
|
1507
1507
|
};
|
|
1508
1508
|
};
|
|
1509
1509
|
loadTipConfig_fn = function() {
|
|
1510
|
-
return __privateGet(this, _cache).read(["
|
|
1511
|
-
if (!__privateGet(this,
|
|
1510
|
+
return __privateGet(this, _cache).read(["upload-relay-tip-config"], async () => {
|
|
1511
|
+
if (!__privateGet(this, _uploadRelayConfig)?.sendTip || !__privateGet(this, _uploadRelayClient)) {
|
|
1512
1512
|
return null;
|
|
1513
1513
|
}
|
|
1514
|
-
if ("kind" in __privateGet(this,
|
|
1515
|
-
return __privateGet(this,
|
|
1514
|
+
if ("kind" in __privateGet(this, _uploadRelayConfig).sendTip) {
|
|
1515
|
+
return __privateGet(this, _uploadRelayConfig).sendTip;
|
|
1516
1516
|
}
|
|
1517
|
-
const tipConfig = await __privateGet(this,
|
|
1517
|
+
const tipConfig = await __privateGet(this, _uploadRelayClient).tipConfig();
|
|
1518
1518
|
return {
|
|
1519
1519
|
...tipConfig,
|
|
1520
|
-
max: __privateGet(this,
|
|
1520
|
+
max: __privateGet(this, _uploadRelayConfig).sendTip.max
|
|
1521
1521
|
};
|
|
1522
1522
|
});
|
|
1523
1523
|
};
|