@mysten/walrus 0.3.1 → 0.4.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/CHANGELOG.md +11 -0
- package/README.md +184 -23
- package/dist/cjs/client.d.ts +90 -2
- package/dist/cjs/client.js +300 -2
- package/dist/cjs/client.js.map +3 -3
- package/dist/cjs/files/blob.d.ts +21 -0
- package/dist/cjs/files/blob.js +94 -0
- package/dist/cjs/files/blob.js.map +7 -0
- package/dist/cjs/files/file.d.ts +21 -0
- package/dist/cjs/files/file.js +62 -0
- package/dist/cjs/files/file.js.map +7 -0
- package/dist/cjs/files/readers/blob.d.ts +70 -0
- package/dist/cjs/files/readers/blob.js +132 -0
- package/dist/cjs/files/readers/blob.js.map +7 -0
- package/dist/cjs/files/readers/local.d.ts +12 -0
- package/dist/cjs/files/readers/local.js +61 -0
- package/dist/cjs/files/readers/local.js.map +7 -0
- package/dist/cjs/files/readers/quilt-file.d.ts +21 -0
- package/dist/cjs/files/readers/quilt-file.js +75 -0
- package/dist/cjs/files/readers/quilt-file.js.map +7 -0
- package/dist/cjs/files/readers/quilt.d.ts +29 -0
- package/dist/cjs/files/readers/quilt.js +219 -0
- package/dist/cjs/files/readers/quilt.js.map +7 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +7 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.d.ts +28 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +15 -0
- package/dist/cjs/utils/index.js +42 -6
- package/dist/cjs/utils/index.js.map +2 -2
- package/dist/cjs/utils/quilts.d.ts +34 -0
- package/dist/cjs/utils/quilts.js +166 -14
- package/dist/cjs/utils/quilts.js.map +3 -3
- package/dist/esm/client.d.ts +90 -2
- package/dist/esm/client.js +300 -2
- package/dist/esm/client.js.map +3 -3
- package/dist/esm/files/blob.d.ts +21 -0
- package/dist/esm/files/blob.js +74 -0
- package/dist/esm/files/blob.js.map +7 -0
- package/dist/esm/files/file.d.ts +21 -0
- package/dist/esm/files/file.js +42 -0
- package/dist/esm/files/file.js.map +7 -0
- package/dist/esm/files/readers/blob.d.ts +70 -0
- package/dist/esm/files/readers/blob.js +112 -0
- package/dist/esm/files/readers/blob.js.map +7 -0
- package/dist/esm/files/readers/local.d.ts +12 -0
- package/dist/esm/files/readers/local.js +41 -0
- package/dist/esm/files/readers/local.js.map +7 -0
- package/dist/esm/files/readers/quilt-file.d.ts +21 -0
- package/dist/esm/files/readers/quilt-file.js +55 -0
- package/dist/esm/files/readers/quilt-file.js.map +7 -0
- package/dist/esm/files/readers/quilt.d.ts +29 -0
- package/dist/esm/files/readers/quilt.js +203 -0
- package/dist/esm/files/readers/quilt.js.map +7 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +7 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/types.d.ts +28 -1
- package/dist/esm/utils/index.d.ts +15 -0
- package/dist/esm/utils/index.js +42 -6
- package/dist/esm/utils/index.js.map +2 -2
- package/dist/esm/utils/quilts.d.ts +34 -0
- package/dist/esm/utils/quilts.js +169 -11
- 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 +13 -9
- package/dist/cjs/quilt/reader.d.ts +0 -27
- package/dist/cjs/quilt/reader.js +0 -267
- package/dist/cjs/quilt/reader.js.map +0 -7
- package/dist/cjs/quilt/write.d.ts +0 -21
- package/dist/cjs/quilt/write.js +0 -167
- package/dist/cjs/quilt/write.js.map +0 -7
- package/dist/esm/quilt/reader.d.ts +0 -27
- package/dist/esm/quilt/reader.js +0 -247
- package/dist/esm/quilt/reader.js.map +0 -7
- package/dist/esm/quilt/write.d.ts +0 -21
- package/dist/esm/quilt/write.js +0 -156
- package/dist/esm/quilt/write.js.map +0 -7
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __typeError = (msg) => {
|
|
7
|
+
throw TypeError(msg);
|
|
8
|
+
};
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
23
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
24
|
+
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);
|
|
25
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
26
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
27
|
+
var quilt_exports = {};
|
|
28
|
+
__export(quilt_exports, {
|
|
29
|
+
QuiltReader: () => QuiltReader
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(quilt_exports);
|
|
32
|
+
var import_experimental = require("@mysten/sui/experimental");
|
|
33
|
+
var import_bcs = require("../../utils/bcs.js");
|
|
34
|
+
var import_quilts = require("../../utils/quilts.js");
|
|
35
|
+
var import_bcs2 = require("@mysten/bcs");
|
|
36
|
+
var import_bcs3 = require("../../utils/bcs.js");
|
|
37
|
+
var import_bcs4 = require("../../utils/bcs.js");
|
|
38
|
+
var import_utils = require("../../utils/index.js");
|
|
39
|
+
var import_quilt_file = require("./quilt-file.js");
|
|
40
|
+
var _blob, _cache, _QuiltReader_instances, readBytesFromSlivers_fn, readBytesFromBlob_fn, readBytes_fn;
|
|
41
|
+
class QuiltReader {
|
|
42
|
+
constructor({ blob }) {
|
|
43
|
+
__privateAdd(this, _QuiltReader_instances);
|
|
44
|
+
__privateAdd(this, _blob);
|
|
45
|
+
__privateAdd(this, _cache, new import_experimental.ClientCache());
|
|
46
|
+
__privateSet(this, _blob, blob);
|
|
47
|
+
}
|
|
48
|
+
async getBlobHeader(sliverIndex) {
|
|
49
|
+
return __privateGet(this, _cache).read(["getBlobHeader", sliverIndex.toString()], async () => {
|
|
50
|
+
const blobHeader = import_bcs.QuiltPatchBlobHeader.parse(
|
|
51
|
+
await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, sliverIndex, import_quilts.QUILT_PATCH_BLOB_HEADER_SIZE)
|
|
52
|
+
);
|
|
53
|
+
let offset = import_quilts.QUILT_PATCH_BLOB_HEADER_SIZE;
|
|
54
|
+
let blobSize = blobHeader.length;
|
|
55
|
+
const identifierLength = new DataView(
|
|
56
|
+
(await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, sliverIndex, 2, offset)).buffer
|
|
57
|
+
).getUint16(0, true);
|
|
58
|
+
blobSize -= 2 + identifierLength;
|
|
59
|
+
offset += 2;
|
|
60
|
+
const identifier = import_bcs2.bcs.string().parse(await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, sliverIndex, identifierLength, offset));
|
|
61
|
+
offset += identifierLength;
|
|
62
|
+
let tags = null;
|
|
63
|
+
if (blobHeader.mask & import_quilts.HAS_TAGS_FLAG) {
|
|
64
|
+
const tagsSize = new DataView(
|
|
65
|
+
(await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, sliverIndex, 2, offset)).buffer
|
|
66
|
+
).getUint16(0, true);
|
|
67
|
+
offset += 2;
|
|
68
|
+
tags = import_bcs3.QuiltPatchTags.parse(await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, sliverIndex, tagsSize, offset));
|
|
69
|
+
blobSize -= tagsSize + 2;
|
|
70
|
+
offset += tagsSize;
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
identifier,
|
|
74
|
+
tags,
|
|
75
|
+
blobSize,
|
|
76
|
+
contentOffset: offset
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async readBlob(sliverIndex) {
|
|
81
|
+
const { identifier, tags, blobSize, contentOffset } = await this.getBlobHeader(sliverIndex);
|
|
82
|
+
const blobContents = await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, sliverIndex, blobSize, contentOffset);
|
|
83
|
+
return {
|
|
84
|
+
identifier,
|
|
85
|
+
tags,
|
|
86
|
+
blobContents
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
readerForPatchId(id) {
|
|
90
|
+
const { quiltId, patchId } = (0, import_quilts.parseQuiltPatchId)(id);
|
|
91
|
+
if (quiltId !== __privateGet(this, _blob).blobId) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`The requested patch ${patchId} is not part of the quilt ${__privateGet(this, _blob).blobId}`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
return new import_quilt_file.QuiltFileReader({ quilt: this, sliverIndex: patchId.startIndex });
|
|
97
|
+
}
|
|
98
|
+
async readIndex() {
|
|
99
|
+
const header = new DataView((await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, 0, 5)).buffer);
|
|
100
|
+
const version = header.getUint8(0);
|
|
101
|
+
if (version !== 1) {
|
|
102
|
+
throw new Error(`Unsupported quilt version ${version}`);
|
|
103
|
+
}
|
|
104
|
+
const indexSize = header.getUint32(1, true);
|
|
105
|
+
const indexBytes = await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, 0, indexSize, 5);
|
|
106
|
+
const columnSize = await __privateGet(this, _blob).getColumnSize();
|
|
107
|
+
const indexSlivers = Math.ceil(indexSize / columnSize);
|
|
108
|
+
const index = import_bcs4.QuiltIndexV1.parse(indexBytes);
|
|
109
|
+
return index.patches.map((patch, i) => {
|
|
110
|
+
const startIndex = i === 0 ? indexSlivers : index.patches[i - 1].endIndex;
|
|
111
|
+
const reader = new import_quilt_file.QuiltFileReader({
|
|
112
|
+
quilt: this,
|
|
113
|
+
sliverIndex: startIndex,
|
|
114
|
+
identifier: patch.identifier,
|
|
115
|
+
tags: patch.tags
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
identifier: patch.identifier,
|
|
119
|
+
patchId: (0, import_utils.urlSafeBase64)(
|
|
120
|
+
import_bcs.QuiltPatchId.serialize({
|
|
121
|
+
quiltId: __privateGet(this, _blob).blobId,
|
|
122
|
+
patchId: {
|
|
123
|
+
version: 1,
|
|
124
|
+
startIndex,
|
|
125
|
+
endIndex: patch.endIndex
|
|
126
|
+
}
|
|
127
|
+
}).toBytes()
|
|
128
|
+
),
|
|
129
|
+
tags: patch.tags,
|
|
130
|
+
reader
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
_blob = new WeakMap();
|
|
136
|
+
_cache = new WeakMap();
|
|
137
|
+
_QuiltReader_instances = new WeakSet();
|
|
138
|
+
readBytesFromSlivers_fn = async function(sliver, length, offset = 0, columnSize) {
|
|
139
|
+
if (!length) {
|
|
140
|
+
return new Uint8Array(0);
|
|
141
|
+
}
|
|
142
|
+
__privateGet(this, _blob).getSecondarySliver({ sliverIndex: sliver }).catch(() => {
|
|
143
|
+
});
|
|
144
|
+
columnSize = columnSize ?? await __privateGet(this, _blob).getColumnSize();
|
|
145
|
+
const columnOffset = Math.floor(offset / columnSize);
|
|
146
|
+
let remainingOffset = offset % columnSize;
|
|
147
|
+
const bytes = new Uint8Array(length);
|
|
148
|
+
let bytesRead = 0;
|
|
149
|
+
const nSlivers = Math.ceil(length / columnSize);
|
|
150
|
+
const slivers = new Array(nSlivers).fill(0).map((_, i) => __privateGet(this, _blob).getSecondarySliver({ sliverIndex: sliver + columnOffset + i }));
|
|
151
|
+
slivers.forEach((p) => p.catch(() => {
|
|
152
|
+
}));
|
|
153
|
+
for (const sliverPromise of slivers) {
|
|
154
|
+
const sliver2 = await sliverPromise;
|
|
155
|
+
let chunk = remainingOffset > 0 ? sliver2.subarray(remainingOffset) : sliver2;
|
|
156
|
+
remainingOffset -= chunk.length;
|
|
157
|
+
if (chunk.length > length - bytesRead) {
|
|
158
|
+
chunk = chunk.subarray(0, length - bytesRead);
|
|
159
|
+
}
|
|
160
|
+
bytes.set(chunk, bytesRead);
|
|
161
|
+
bytesRead += chunk.length;
|
|
162
|
+
if (bytesRead >= length) {
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return bytes;
|
|
167
|
+
};
|
|
168
|
+
readBytesFromBlob_fn = async function(startColumn, length, offset = 0) {
|
|
169
|
+
const result = new Uint8Array(length);
|
|
170
|
+
if (!length) {
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
const blob = await __privateGet(this, _blob).getBytes();
|
|
174
|
+
const [rowSize, symbolSize] = await Promise.all([
|
|
175
|
+
__privateGet(this, _blob).getRowSize(),
|
|
176
|
+
__privateGet(this, _blob).getSymbolSize()
|
|
177
|
+
]);
|
|
178
|
+
const nRows = blob.length / rowSize;
|
|
179
|
+
const symbolsToSkip = Math.floor(offset / symbolSize);
|
|
180
|
+
let remainingOffset = offset % symbolSize;
|
|
181
|
+
let currentCol = startColumn + Math.floor(symbolsToSkip / nRows);
|
|
182
|
+
let currentRow = symbolsToSkip % nRows;
|
|
183
|
+
let bytesRead = 0;
|
|
184
|
+
while (bytesRead < length) {
|
|
185
|
+
const baseIndex = currentRow * rowSize + currentCol * symbolSize;
|
|
186
|
+
const startIndex = baseIndex + remainingOffset;
|
|
187
|
+
const endIndex = Math.min(
|
|
188
|
+
baseIndex + symbolSize,
|
|
189
|
+
startIndex + length - bytesRead,
|
|
190
|
+
blob.length
|
|
191
|
+
);
|
|
192
|
+
if (startIndex >= blob.length) {
|
|
193
|
+
throw new Error("Index out of bounds");
|
|
194
|
+
}
|
|
195
|
+
const size = endIndex - startIndex;
|
|
196
|
+
for (let i = 0; i < size; i++) {
|
|
197
|
+
result[bytesRead + i] = blob[startIndex + i];
|
|
198
|
+
}
|
|
199
|
+
bytesRead += size;
|
|
200
|
+
remainingOffset = 0;
|
|
201
|
+
currentRow = (currentRow + 1) % nRows;
|
|
202
|
+
if (currentRow === 0) {
|
|
203
|
+
currentCol += 1;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return result;
|
|
207
|
+
};
|
|
208
|
+
readBytes_fn = async function(sliver, length, offset = 0, columnSize) {
|
|
209
|
+
if (__privateGet(this, _blob).hasStartedLoadingFullBlob) {
|
|
210
|
+
return __privateMethod(this, _QuiltReader_instances, readBytesFromBlob_fn).call(this, sliver, length, offset);
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
const bytes = await __privateMethod(this, _QuiltReader_instances, readBytesFromSlivers_fn).call(this, sliver, length, offset, columnSize);
|
|
214
|
+
return bytes;
|
|
215
|
+
} catch (_error) {
|
|
216
|
+
return __privateMethod(this, _QuiltReader_instances, readBytesFromBlob_fn).call(this, sliver, length, offset);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
//# sourceMappingURL=quilt.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/files/readers/quilt.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { ClientCache } from '@mysten/sui/experimental';\nimport type { BlobReader } from './blob.js';\nimport { QuiltPatchBlobHeader, QuiltPatchId } from '../../utils/bcs.js';\nimport {\n\tHAS_TAGS_FLAG,\n\tparseQuiltPatchId,\n\tQUILT_PATCH_BLOB_HEADER_SIZE,\n} from '../../utils/quilts.js';\nimport { bcs } from '@mysten/bcs';\nimport { QuiltPatchTags } from '../../utils/bcs.js';\nimport { QuiltIndexV1 } from '../../utils/bcs.js';\nimport { urlSafeBase64 } from '../../utils/index.js';\nimport { QuiltFileReader } from './quilt-file.js';\n\nexport interface QuiltReaderOptions {\n\tblob: BlobReader;\n}\n\nexport class QuiltReader {\n\t#blob: BlobReader;\n\t#cache = new ClientCache();\n\n\tconstructor({ blob }: QuiltReaderOptions) {\n\t\tthis.#blob = blob;\n\t}\n\n\tasync #readBytesFromSlivers(sliver: number, length: number, offset = 0, columnSize?: number) {\n\t\tif (!length) {\n\t\t\treturn new Uint8Array(0);\n\t\t}\n\n\t\t// start loading the first sliver, but don't wait for it (may improve columnSize lookup)\n\t\tthis.#blob.getSecondarySliver({ sliverIndex: sliver }).catch(() => {});\n\n\t\tcolumnSize = columnSize ?? (await this.#blob.getColumnSize());\n\t\tconst columnOffset = Math.floor(offset / columnSize);\n\t\tlet remainingOffset = offset % columnSize;\n\t\tconst bytes = new Uint8Array(length);\n\n\t\tlet bytesRead = 0;\n\n\t\tconst nSlivers = Math.ceil(length / columnSize);\n\t\tconst slivers = new Array(nSlivers)\n\t\t\t.fill(0)\n\t\t\t.map((_, i) => this.#blob.getSecondarySliver({ sliverIndex: sliver + columnOffset + i }));\n\n\t\t// ignore errors from slivers that are not consumed below\n\t\tslivers.forEach((p) => p.catch(() => {}));\n\n\t\tfor (const sliverPromise of slivers) {\n\t\t\tconst sliver = await sliverPromise;\n\t\t\tlet chunk = remainingOffset > 0 ? sliver.subarray(remainingOffset) : sliver;\n\t\t\tremainingOffset -= chunk.length;\n\t\t\tif (chunk.length > length - bytesRead) {\n\t\t\t\tchunk = chunk.subarray(0, length - bytesRead);\n\t\t\t}\n\n\t\t\tbytes.set(chunk, bytesRead);\n\t\t\tbytesRead += chunk.length;\n\n\t\t\tif (bytesRead >= length) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\treturn bytes;\n\t}\n\n\tasync #readBytesFromBlob(startColumn: number, length: number, offset = 0) {\n\t\tconst result = new Uint8Array(length);\n\n\t\tif (!length) {\n\t\t\treturn result;\n\t\t}\n\t\tconst blob = await this.#blob.getBytes();\n\n\t\tconst [rowSize, symbolSize] = await Promise.all([\n\t\t\tthis.#blob.getRowSize(),\n\t\t\tthis.#blob.getSymbolSize(),\n\t\t]);\n\n\t\tconst nRows = blob.length / rowSize;\n\t\tconst symbolsToSkip = Math.floor(offset / symbolSize);\n\t\tlet remainingOffset = offset % symbolSize;\n\t\tlet currentCol = startColumn + Math.floor(symbolsToSkip / nRows);\n\t\tlet currentRow = symbolsToSkip % nRows;\n\n\t\tlet bytesRead = 0;\n\n\t\twhile (bytesRead < length) {\n\t\t\tconst baseIndex = currentRow * rowSize + currentCol * symbolSize;\n\t\t\tconst startIndex = baseIndex + remainingOffset;\n\t\t\tconst endIndex = Math.min(\n\t\t\t\tbaseIndex + symbolSize,\n\t\t\t\tstartIndex + length - bytesRead,\n\t\t\t\tblob.length,\n\t\t\t);\n\n\t\t\tif (startIndex >= blob.length) {\n\t\t\t\tthrow new Error('Index out of bounds');\n\t\t\t}\n\n\t\t\tconst size = endIndex - startIndex;\n\n\t\t\tfor (let i = 0; i < size; i++) {\n\t\t\t\tresult[bytesRead + i] = blob[startIndex + i];\n\t\t\t}\n\n\t\t\tbytesRead += size;\n\n\t\t\tremainingOffset = 0;\n\n\t\t\tcurrentRow = (currentRow + 1) % nRows;\n\t\t\tif (currentRow === 0) {\n\t\t\t\tcurrentCol += 1;\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tasync #readBytes(sliver: number, length: number, offset = 0, columnSize?: number) {\n\t\tif (this.#blob.hasStartedLoadingFullBlob) {\n\t\t\treturn this.#readBytesFromBlob(sliver, length, offset);\n\t\t}\n\n\t\ttry {\n\t\t\tconst bytes = await this.#readBytesFromSlivers(sliver, length, offset, columnSize);\n\n\t\t\treturn bytes;\n\t\t} catch (_error) {\n\t\t\t// fallback to reading the full blob\n\t\t\treturn this.#readBytesFromBlob(sliver, length, offset);\n\t\t}\n\t}\n\n\tasync getBlobHeader(sliverIndex: number) {\n\t\treturn this.#cache.read(['getBlobHeader', sliverIndex.toString()], async () => {\n\t\t\tconst blobHeader = QuiltPatchBlobHeader.parse(\n\t\t\t\tawait this.#readBytes(sliverIndex, QUILT_PATCH_BLOB_HEADER_SIZE),\n\t\t\t);\n\n\t\t\tlet offset = QUILT_PATCH_BLOB_HEADER_SIZE;\n\t\t\tlet blobSize = blobHeader.length;\n\n\t\t\tconst identifierLength = new DataView(\n\t\t\t\t(await this.#readBytes(sliverIndex, 2, offset)).buffer,\n\t\t\t).getUint16(0, true);\n\t\t\tblobSize -= 2 + identifierLength;\n\t\t\toffset += 2;\n\n\t\t\tconst identifier = bcs\n\t\t\t\t.string()\n\t\t\t\t.parse(await this.#readBytes(sliverIndex, identifierLength, offset));\n\n\t\t\toffset += identifierLength;\n\n\t\t\tlet tags: Record<string, string> | null = null;\n\t\t\tif (blobHeader.mask & HAS_TAGS_FLAG) {\n\t\t\t\tconst tagsSize = new DataView(\n\t\t\t\t\t(await this.#readBytes(sliverIndex, 2, offset)).buffer,\n\t\t\t\t).getUint16(0, true);\n\t\t\t\toffset += 2;\n\n\t\t\t\ttags = QuiltPatchTags.parse(await this.#readBytes(sliverIndex, tagsSize, offset));\n\t\t\t\tblobSize -= tagsSize + 2;\n\t\t\t\toffset += tagsSize;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tidentifier,\n\t\t\t\ttags,\n\t\t\t\tblobSize,\n\t\t\t\tcontentOffset: offset,\n\t\t\t};\n\t\t});\n\t}\n\n\tasync readBlob(sliverIndex: number) {\n\t\tconst { identifier, tags, blobSize, contentOffset } = await this.getBlobHeader(sliverIndex);\n\n\t\tconst blobContents = await this.#readBytes(sliverIndex, blobSize, contentOffset);\n\n\t\treturn {\n\t\t\tidentifier,\n\t\t\ttags,\n\t\t\tblobContents,\n\t\t};\n\t}\n\n\treaderForPatchId(id: string) {\n\t\tconst { quiltId, patchId } = parseQuiltPatchId(id);\n\n\t\tif (quiltId !== this.#blob.blobId) {\n\t\t\tthrow new Error(\n\t\t\t\t`The requested patch ${patchId} is not part of the quilt ${this.#blob.blobId}`,\n\t\t\t);\n\t\t}\n\n\t\treturn new QuiltFileReader({ quilt: this, sliverIndex: patchId.startIndex });\n\t}\n\n\tasync readIndex() {\n\t\tconst header = new DataView((await this.#readBytes(0, 5)).buffer);\n\n\t\tconst version = header.getUint8(0);\n\n\t\tif (version !== 1) {\n\t\t\tthrow new Error(`Unsupported quilt version ${version}`);\n\t\t}\n\n\t\tconst indexSize = header.getUint32(1, true);\n\t\tconst indexBytes = await this.#readBytes(0, indexSize, 5);\n\t\tconst columnSize = await this.#blob.getColumnSize();\n\t\tconst indexSlivers = Math.ceil(indexSize / columnSize);\n\t\tconst index = QuiltIndexV1.parse(indexBytes);\n\n\t\treturn index.patches.map((patch, i) => {\n\t\t\tconst startIndex = i === 0 ? indexSlivers : index.patches[i - 1].endIndex;\n\t\t\tconst reader = new QuiltFileReader({\n\t\t\t\tquilt: this,\n\t\t\t\tsliverIndex: startIndex,\n\t\t\t\tidentifier: patch.identifier,\n\t\t\t\ttags: patch.tags,\n\t\t\t});\n\n\t\t\treturn {\n\t\t\t\tidentifier: patch.identifier,\n\t\t\t\tpatchId: urlSafeBase64(\n\t\t\t\t\tQuiltPatchId.serialize({\n\t\t\t\t\t\tquiltId: this.#blob.blobId,\n\t\t\t\t\t\tpatchId: {\n\t\t\t\t\t\t\tversion: 1,\n\t\t\t\t\t\t\tstartIndex,\n\t\t\t\t\t\t\tendIndex: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AAAA,EACD;AAEA,SAAO;AACR;AAEM,eAAU,eAAC,QAAgB,QAAgB,SAAS,GAAG,YAAqB;AACjF,MAAI,mBAAK,OAAM,2BAA2B;AACzC,WAAO,sBAAK,8CAAL,WAAwB,QAAQ,QAAQ;AAAA,EAChD;AAEA,MAAI;AACH,UAAM,QAAQ,MAAM,sBAAK,iDAAL,WAA2B,QAAQ,QAAQ,QAAQ;AAEvE,WAAO;AAAA,EACR,SAAS,QAAQ;AAEhB,WAAO,sBAAK,8CAAL,WAAwB,QAAQ,QAAQ;AAAA,EAChD;AACD;",
|
|
6
|
+
"names": ["import_bcs", "sliver"]
|
|
7
|
+
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -5,4 +5,7 @@ export { type StorageNodeClientOptions } from './storage-node/client.js';
|
|
|
5
5
|
export type * from './types.js';
|
|
6
6
|
export * from './storage-node/error.js';
|
|
7
7
|
export * from './error.js';
|
|
8
|
+
export { encodeQuilt, type EncodeQuiltOptions } from './utils/quilts.js';
|
|
8
9
|
export { blobIdFromInt, blobIdToInt } from './utils/bcs.js';
|
|
10
|
+
export { WalrusFile, type FileReader } from './files/file.js';
|
|
11
|
+
export { WalrusBlob } from './files/blob.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -21,14 +21,20 @@ var index_exports = {};
|
|
|
21
21
|
__export(index_exports, {
|
|
22
22
|
MAINNET_WALRUS_PACKAGE_CONFIG: () => import_constants.MAINNET_WALRUS_PACKAGE_CONFIG,
|
|
23
23
|
TESTNET_WALRUS_PACKAGE_CONFIG: () => import_constants.TESTNET_WALRUS_PACKAGE_CONFIG,
|
|
24
|
+
WalrusBlob: () => import_blob.WalrusBlob,
|
|
24
25
|
WalrusClient: () => import_client.WalrusClient,
|
|
26
|
+
WalrusFile: () => import_file.WalrusFile,
|
|
25
27
|
blobIdFromInt: () => import_bcs.blobIdFromInt,
|
|
26
|
-
blobIdToInt: () => import_bcs.blobIdToInt
|
|
28
|
+
blobIdToInt: () => import_bcs.blobIdToInt,
|
|
29
|
+
encodeQuilt: () => import_quilts.encodeQuilt
|
|
27
30
|
});
|
|
28
31
|
module.exports = __toCommonJS(index_exports);
|
|
29
32
|
var import_client = require("./client.js");
|
|
30
33
|
var import_constants = require("./constants.js");
|
|
31
34
|
__reExport(index_exports, require("./storage-node/error.js"), module.exports);
|
|
32
35
|
__reExport(index_exports, require("./error.js"), module.exports);
|
|
36
|
+
var import_quilts = require("./utils/quilts.js");
|
|
33
37
|
var import_bcs = require("./utils/bcs.js");
|
|
38
|
+
var import_file = require("./files/file.js");
|
|
39
|
+
var import_blob = require("./files/blob.js");
|
|
34
40
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport { WalrusClient } from './client.js';\nexport { type WalrusClientConfig, type WalrusPackageConfig } from './types.js';\nexport { TESTNET_WALRUS_PACKAGE_CONFIG, MAINNET_WALRUS_PACKAGE_CONFIG } from './constants.js';\nexport { type StorageNodeClientOptions } from './storage-node/client.js';\nexport type * from './types.js';\nexport * from './storage-node/error.js';\nexport * from './error.js';\n\nexport { blobIdFromInt, blobIdToInt } from './utils/bcs.js';\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA6B;AAE7B,uBAA6E;AAG7E,0BAAc,oCARd;AASA,0BAAc,uBATd;AAWA,iBAA2C;",
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport { WalrusClient } from './client.js';\nexport { type WalrusClientConfig, type WalrusPackageConfig } from './types.js';\nexport { TESTNET_WALRUS_PACKAGE_CONFIG, MAINNET_WALRUS_PACKAGE_CONFIG } from './constants.js';\nexport { type StorageNodeClientOptions } from './storage-node/client.js';\nexport type * from './types.js';\nexport * from './storage-node/error.js';\nexport * from './error.js';\n\nexport { encodeQuilt, type EncodeQuiltOptions } from './utils/quilts.js';\nexport { blobIdFromInt, blobIdToInt } from './utils/bcs.js';\n\nexport { WalrusFile, type FileReader } from './files/file.js';\nexport { WalrusBlob } from './files/blob.js';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA6B;AAE7B,uBAA6E;AAG7E,0BAAc,oCARd;AASA,0BAAc,uBATd;AAWA,oBAAqD;AACrD,iBAA2C;AAE3C,kBAA4C;AAC5C,kBAA2B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { SuiClient } from '@mysten/sui/client';
|
|
2
2
|
import type { Signer } from '@mysten/sui/cryptography';
|
|
3
3
|
import type { ClientWithExtensions } from '@mysten/sui/experimental';
|
|
4
|
-
import type { TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
4
|
+
import type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
5
5
|
import type { StorageNodeInfo } from './contracts/walrus/storage_node.js';
|
|
6
6
|
import type { RequestOptions, StorageNodeClientOptions } from './storage-node/client.js';
|
|
7
7
|
import type { StorageConfirmation, StoreBlobMetadataRequestInput, StoreSliverRequestInput, Uploadable } from './storage-node/types.js';
|
|
8
8
|
import type { BlobMetadata, EncodingType } from './utils/bcs.js';
|
|
9
9
|
import type { UploadRelayClientOptions } from './upload-relay/client.js';
|
|
10
|
+
import type { WalrusFile } from './files/file.js';
|
|
11
|
+
import type { Blob } from './contracts/walrus/blob.js';
|
|
10
12
|
/**
|
|
11
13
|
* Configuration for the Walrus package on sui
|
|
12
14
|
*
|
|
@@ -195,6 +197,31 @@ export type WriteBlobOptions = {
|
|
|
195
197
|
/** The attributes to write for the blob. */
|
|
196
198
|
attributes?: Record<string, string | null>;
|
|
197
199
|
} & WalrusClientRequestOptions;
|
|
200
|
+
export interface WriteQuiltOptions extends Omit<WriteBlobOptions, 'blob'> {
|
|
201
|
+
blobs: {
|
|
202
|
+
contents: Uint8Array;
|
|
203
|
+
identifier: string;
|
|
204
|
+
tags?: Record<string, string>;
|
|
205
|
+
}[];
|
|
206
|
+
}
|
|
207
|
+
export interface WriteFilesOptions extends Omit<WriteBlobOptions, 'blob'> {
|
|
208
|
+
files: WalrusFile[];
|
|
209
|
+
}
|
|
210
|
+
export interface WriteFilesFlowOptions extends Omit<WriteBlobOptions, 'blob' | 'signer'> {
|
|
211
|
+
files: WalrusFile[];
|
|
212
|
+
owner: string;
|
|
213
|
+
}
|
|
214
|
+
export interface WriteFilesFlow {
|
|
215
|
+
encode: () => Promise<void>;
|
|
216
|
+
register: () => Transaction;
|
|
217
|
+
upload: () => Promise<void>;
|
|
218
|
+
certify: () => Transaction;
|
|
219
|
+
listFiles: () => Promise<{
|
|
220
|
+
id: string;
|
|
221
|
+
blobId: string;
|
|
222
|
+
blobObject: ReturnType<typeof Blob>['$inferType'];
|
|
223
|
+
}[]>;
|
|
224
|
+
}
|
|
198
225
|
export interface DeleteBlobOptions {
|
|
199
226
|
blobObjectId: string;
|
|
200
227
|
}
|
package/dist/cjs/types.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/types.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SuiClient } from '@mysten/sui/client';\nimport type { Signer } from '@mysten/sui/cryptography';\nimport type { ClientWithExtensions } from '@mysten/sui/experimental';\nimport type { TransactionObjectArgument } from '@mysten/sui/transactions';\n\nimport type { StorageNodeInfo } from './contracts/walrus/storage_node.js';\nimport type { RequestOptions, StorageNodeClientOptions } from './storage-node/client.js';\nimport type {\n\tStorageConfirmation,\n\tStoreBlobMetadataRequestInput,\n\tStoreSliverRequestInput,\n\tUploadable,\n} from './storage-node/types.js';\nimport type { BlobMetadata, EncodingType } from './utils/bcs.js';\nimport type { UploadRelayClientOptions } from './upload-relay/client.js';\n\n/**\n * Configuration for the Walrus package on sui\n *\n * This is used to configure the Walrus package to use a specific package ID, system object ID, staking pool ID, and WAL package ID.\n */\nexport interface WalrusPackageConfig {\n\t/** The system object ID of the Walrus package */\n\tsystemObjectId: string;\n\t/** The staking pool ID of the Walrus package */\n\tstakingPoolId: string;\n\tsubsidiesObjectId?: string;\n\texchangeIds?: string[];\n}\n\ntype SuiClientOrRpcUrl =\n\t| {\n\t\t\tsuiClient: ClientWithExtensions<{\n\t\t\t\tjsonRpc: SuiClient;\n\t\t\t}>;\n\t\t\tsuiRpcUrl?: never;\n\t }\n\t| {\n\t\t\tsuiRpcUrl: string;\n\t\t\tsuiClient?: never;\n\t };\n\ntype WalrusNetworkOrPackageConfig =\n\t| {\n\t\t\tnetwork: 'mainnet' | 'testnet';\n\t\t\tpackageConfig?: WalrusPackageConfig;\n\t }\n\t| {\n\t\t\tnetwork?: never;\n\t\t\tpackageConfig: WalrusPackageConfig;\n\t };\n\nexport type TipStrategy =\n\t| {\n\t\t\tconst: number | bigint;\n\t }\n\t| {\n\t\t\tlinear: {\n\t\t\t\tbase: number | bigint;\n\t\t\t\tperEncodedKib: number | bigint;\n\t\t\t};\n\t };\n\nexport type UploadRelayTipConfig = {\n\taddress: string;\n\tmax?: number;\n\tkind: TipStrategy;\n};\n\nexport interface UploadRelayConfig extends UploadRelayClientOptions {\n\tsendTip?:\n\t\t| null\n\t\t| UploadRelayTipConfig\n\t\t| {\n\t\t\t\tmax: number;\n\t\t };\n}\n\ninterface BaseWalrusClientConfig {\n\tstorageNodeClientOptions?: StorageNodeClientOptions;\n\twasmUrl?: string;\n\tuploadRelay?: UploadRelayConfig;\n}\n\n/**\n * Configuration for the Walrus client.\n *\n * This is used to configure the Walrus client to use a specific storage node client options, network, and Sui client or RPC URL.\n */\nexport type WalrusClientConfig = BaseWalrusClientConfig &\n\tWalrusNetworkOrPackageConfig &\n\tSuiClientOrRpcUrl;\n\nexport type WalrusClientExtensionOptions = BaseWalrusClientConfig & {\n\tpackageConfig?: WalrusPackageConfig;\n\tnetwork?: 'mainnet' | 'testnet';\n};\n\nexport type WalrusClientRequestOptions = Pick<RequestOptions, 'signal'>;\n\nexport interface StorageNode {\n\tnetworkUrl: string;\n\tinfo: ReturnType<typeof StorageNodeInfo>['$inferType'];\n\tshardIndices: number[];\n\tnodeIndex: number;\n\tid: string;\n}\n\nexport interface CommitteeInfo {\n\tbyShardIndex: Map<number, StorageNode>;\n\tnodes: StorageNode[];\n}\n\nexport interface StorageWithSizeOptions {\n\t/** The encoded size of the blob. */\n\tsize: number;\n\t/** The number of epoch the storage will be reserved for. */\n\tepochs: number;\n\t/** Owner of the storage object. */\n\towner: string;\n\t/** optionally specify a WAL coin pay for the registration. This will consume WAL from the signer by default. */\n\twalCoin?: TransactionObjectArgument;\n}\n\nexport interface RegisterBlobOptions extends StorageWithSizeOptions {\n\tblobId: string;\n\trootHash: Uint8Array;\n\tdeletable: boolean;\n\t/** optionally specify a WAL coin pay for the registration. This will consume WAL from the signer by default. */\n\twalCoin?: TransactionObjectArgument;\n\t/** The attributes to write for the blob. */\n\tattributes?: Record<string, string | null>;\n}\n\nexport type CertifyBlobOptions = {\n\tblobId: string;\n\tblobObjectId: string;\n\tdeletable: boolean;\n} & (\n\t| {\n\t\t\t/** An array of confirmations.\n\t\t\t * These confirmations must be provided in the same order as the nodes in the committee.\n\t\t\t * For nodes that have not provided a confirmation you can pass `null` */\n\t\t\tconfirmations: (StorageConfirmation | null)[];\n\t\t\tcertificate?: never;\n\t }\n\t| {\n\t\t\tcertificate: ProtocolMessageCertificate;\n\t\t\tconfirmations?: never;\n\t }\n);\n\nexport type DeletableConfirmationOptions =\n\t| { deletable: false; objectId?: string }\n\t| { deletable: true; objectId: string };\n\nexport type GetStorageConfirmationOptions = {\n\tblobId: string;\n\tnodeIndex: number;\n} & DeletableConfirmationOptions &\n\tWalrusClientRequestOptions;\n\nexport type ReadBlobOptions = {\n\tblobId: string;\n} & WalrusClientRequestOptions;\n\nexport type GetCertificationEpochOptions = ReadBlobOptions;\n\nexport type GetBlobMetadataOptions = ReadBlobOptions;\n\nexport type GetSliversOptions = ReadBlobOptions;\n\nexport interface GetSecondarySliverOptions extends WalrusClientRequestOptions {\n\tblobId: string;\n\tindex: number;\n}\n\nexport type GetVerifiedBlobStatusOptions = ReadBlobOptions;\n\nexport type ComputeBlobMetadataOptions = {\n\tbytes: Uint8Array;\n\tnumShards?: number;\n};\n\nexport interface SliversForNode {\n\tprimary: {\n\t\tsliverIndex: number;\n\t\tsliverPairIndex: number;\n\t\tshardIndex: number;\n\t\tsliver: Uint8Array;\n\t}[];\n\tsecondary: {\n\t\tsliverIndex: number;\n\t\tsliverPairIndex: number;\n\t\tshardIndex: number;\n\t\tsliver: Uint8Array;\n\t}[];\n}\n\nexport type WriteSliversToNodeOptions = {\n\tblobId: string;\n\tnodeIndex: number;\n\tslivers: SliversForNode;\n} & WalrusClientRequestOptions;\n\nexport type WriteSliverOptions = StoreSliverRequestInput & WalrusClientRequestOptions;\n\nexport type WriteMetadataOptions = {\n\tnodeIndex: number;\n\tmetadata: Uploadable | typeof BlobMetadata.$inferInput;\n} & StoreBlobMetadataRequestInput &\n\tWalrusClientRequestOptions;\n\nexport type WriteEncodedBlobOptions = {\n\tblobId: string;\n\tnodeIndex: number;\n\tmetadata: Uploadable | typeof BlobMetadata.$inferInput;\n\tslivers: SliversForNode;\n} & DeletableConfirmationOptions &\n\tWalrusClientRequestOptions;\n\nexport type WriteEncodedBlobToNodesOptions = {\n\tblobId: string;\n\tmetadata: Uploadable | typeof BlobMetadata.$inferInput;\n\tsliversByNode: SliversForNode[];\n} & DeletableConfirmationOptions &\n\tWalrusClientRequestOptions;\n\nexport type WriteBlobToUploadRelayOptions = {\n\tblobId: string;\n\tblob: Uint8Array;\n\tnonce: Uint8Array;\n\ttxDigest: string;\n\tblobObjectId: string;\n\tdeletable: boolean;\n\tencodingType?: EncodingType;\n} & WalrusClientRequestOptions;\n\nexport type WriteBlobOptions = {\n\tblob: Uint8Array;\n\tdeletable: boolean;\n\t/** The number of epochs the blob should be stored for. */\n\tepochs: number;\n\tsigner: Signer;\n\t/** Where the blob should be transferred to after it is registered. Defaults to the signer address. */\n\towner?: string;\n\t/** The attributes to write for the blob. */\n\tattributes?: Record<string, string | null>;\n} & WalrusClientRequestOptions;\n\nexport interface DeleteBlobOptions {\n\tblobObjectId: string;\n}\n\nexport type ExtendBlobOptions = {\n\tblobObjectId: string;\n\towner: string;\n\t/** optionally specify a WAL coin pay for the registration. This will consume WAL from the signer by default. */\n\twalCoin?: TransactionObjectArgument;\n} & (\n\t| {\n\t\t\t/** The number of epochs the blob should be stored for. */\n\t\t\tepochs: number;\n\t\t\tendEpoch?: never;\n\t }\n\t| {\n\t\t\t/** The new end epoch for the storage period of the blob. */\n\t\t\tendEpoch: number;\n\t\t\tepochs?: never;\n\t }\n);\n\nexport type WriteBlobAttributesOptions = {\n\tattributes: Record<string, string | null>;\n} & (\n\t| {\n\t\t\tblobObject: TransactionObjectArgument;\n\t\t\tblobObjectId?: never;\n\t }\n\t| {\n\t\t\tblobObjectId: string;\n\t\t\tblobObject?: never;\n\t }\n);\n\nexport type EncodingType = Extract<typeof EncodingType.$inferInput, string>;\n\nexport interface ProtocolMessageCertificate {\n\tsigners: number[];\n\tserializedMessage: Uint8Array;\n\tsignature: Uint8Array;\n}\n"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SuiClient } from '@mysten/sui/client';\nimport type { Signer } from '@mysten/sui/cryptography';\nimport type { ClientWithExtensions } from '@mysten/sui/experimental';\nimport type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';\n\nimport type { StorageNodeInfo } from './contracts/walrus/storage_node.js';\nimport type { RequestOptions, StorageNodeClientOptions } from './storage-node/client.js';\nimport type {\n\tStorageConfirmation,\n\tStoreBlobMetadataRequestInput,\n\tStoreSliverRequestInput,\n\tUploadable,\n} from './storage-node/types.js';\nimport type { BlobMetadata, EncodingType } from './utils/bcs.js';\nimport type { UploadRelayClientOptions } from './upload-relay/client.js';\nimport type { WalrusFile } from './files/file.js';\nimport type { Blob } from './contracts/walrus/blob.js';\n\n/**\n * Configuration for the Walrus package on sui\n *\n * This is used to configure the Walrus package to use a specific package ID, system object ID, staking pool ID, and WAL package ID.\n */\nexport interface WalrusPackageConfig {\n\t/** The system object ID of the Walrus package */\n\tsystemObjectId: string;\n\t/** The staking pool ID of the Walrus package */\n\tstakingPoolId: string;\n\tsubsidiesObjectId?: string;\n\texchangeIds?: string[];\n}\n\ntype SuiClientOrRpcUrl =\n\t| {\n\t\t\tsuiClient: ClientWithExtensions<{\n\t\t\t\tjsonRpc: SuiClient;\n\t\t\t}>;\n\t\t\tsuiRpcUrl?: never;\n\t }\n\t| {\n\t\t\tsuiRpcUrl: string;\n\t\t\tsuiClient?: never;\n\t };\n\ntype WalrusNetworkOrPackageConfig =\n\t| {\n\t\t\tnetwork: 'mainnet' | 'testnet';\n\t\t\tpackageConfig?: WalrusPackageConfig;\n\t }\n\t| {\n\t\t\tnetwork?: never;\n\t\t\tpackageConfig: WalrusPackageConfig;\n\t };\n\nexport type TipStrategy =\n\t| {\n\t\t\tconst: number | bigint;\n\t }\n\t| {\n\t\t\tlinear: {\n\t\t\t\tbase: number | bigint;\n\t\t\t\tperEncodedKib: number | bigint;\n\t\t\t};\n\t };\n\nexport type UploadRelayTipConfig = {\n\taddress: string;\n\tmax?: number;\n\tkind: TipStrategy;\n};\n\nexport interface UploadRelayConfig extends UploadRelayClientOptions {\n\tsendTip?:\n\t\t| null\n\t\t| UploadRelayTipConfig\n\t\t| {\n\t\t\t\tmax: number;\n\t\t };\n}\n\ninterface BaseWalrusClientConfig {\n\tstorageNodeClientOptions?: StorageNodeClientOptions;\n\twasmUrl?: string;\n\tuploadRelay?: UploadRelayConfig;\n}\n\n/**\n * Configuration for the Walrus client.\n *\n * This is used to configure the Walrus client to use a specific storage node client options, network, and Sui client or RPC URL.\n */\nexport type WalrusClientConfig = BaseWalrusClientConfig &\n\tWalrusNetworkOrPackageConfig &\n\tSuiClientOrRpcUrl;\n\nexport type WalrusClientExtensionOptions = BaseWalrusClientConfig & {\n\tpackageConfig?: WalrusPackageConfig;\n\tnetwork?: 'mainnet' | 'testnet';\n};\n\nexport type WalrusClientRequestOptions = Pick<RequestOptions, 'signal'>;\n\nexport interface StorageNode {\n\tnetworkUrl: string;\n\tinfo: ReturnType<typeof StorageNodeInfo>['$inferType'];\n\tshardIndices: number[];\n\tnodeIndex: number;\n\tid: string;\n}\n\nexport interface CommitteeInfo {\n\tbyShardIndex: Map<number, StorageNode>;\n\tnodes: StorageNode[];\n}\n\nexport interface StorageWithSizeOptions {\n\t/** The encoded size of the blob. */\n\tsize: number;\n\t/** The number of epoch the storage will be reserved for. */\n\tepochs: number;\n\t/** Owner of the storage object. */\n\towner: string;\n\t/** optionally specify a WAL coin pay for the registration. This will consume WAL from the signer by default. */\n\twalCoin?: TransactionObjectArgument;\n}\n\nexport interface RegisterBlobOptions extends StorageWithSizeOptions {\n\tblobId: string;\n\trootHash: Uint8Array;\n\tdeletable: boolean;\n\t/** optionally specify a WAL coin pay for the registration. This will consume WAL from the signer by default. */\n\twalCoin?: TransactionObjectArgument;\n\t/** The attributes to write for the blob. */\n\tattributes?: Record<string, string | null>;\n}\n\nexport type CertifyBlobOptions = {\n\tblobId: string;\n\tblobObjectId: string;\n\tdeletable: boolean;\n} & (\n\t| {\n\t\t\t/** An array of confirmations.\n\t\t\t * These confirmations must be provided in the same order as the nodes in the committee.\n\t\t\t * For nodes that have not provided a confirmation you can pass `null` */\n\t\t\tconfirmations: (StorageConfirmation | null)[];\n\t\t\tcertificate?: never;\n\t }\n\t| {\n\t\t\tcertificate: ProtocolMessageCertificate;\n\t\t\tconfirmations?: never;\n\t }\n);\n\nexport type DeletableConfirmationOptions =\n\t| { deletable: false; objectId?: string }\n\t| { deletable: true; objectId: string };\n\nexport type GetStorageConfirmationOptions = {\n\tblobId: string;\n\tnodeIndex: number;\n} & DeletableConfirmationOptions &\n\tWalrusClientRequestOptions;\n\nexport type ReadBlobOptions = {\n\tblobId: string;\n} & WalrusClientRequestOptions;\n\nexport type GetCertificationEpochOptions = ReadBlobOptions;\n\nexport type GetBlobMetadataOptions = ReadBlobOptions;\n\nexport type GetSliversOptions = ReadBlobOptions;\n\nexport interface GetSecondarySliverOptions extends WalrusClientRequestOptions {\n\tblobId: string;\n\tindex: number;\n}\n\nexport type GetVerifiedBlobStatusOptions = ReadBlobOptions;\n\nexport type ComputeBlobMetadataOptions = {\n\tbytes: Uint8Array;\n\tnumShards?: number;\n};\n\nexport interface SliversForNode {\n\tprimary: {\n\t\tsliverIndex: number;\n\t\tsliverPairIndex: number;\n\t\tshardIndex: number;\n\t\tsliver: Uint8Array;\n\t}[];\n\tsecondary: {\n\t\tsliverIndex: number;\n\t\tsliverPairIndex: number;\n\t\tshardIndex: number;\n\t\tsliver: Uint8Array;\n\t}[];\n}\n\nexport type WriteSliversToNodeOptions = {\n\tblobId: string;\n\tnodeIndex: number;\n\tslivers: SliversForNode;\n} & WalrusClientRequestOptions;\n\nexport type WriteSliverOptions = StoreSliverRequestInput & WalrusClientRequestOptions;\n\nexport type WriteMetadataOptions = {\n\tnodeIndex: number;\n\tmetadata: Uploadable | typeof BlobMetadata.$inferInput;\n} & StoreBlobMetadataRequestInput &\n\tWalrusClientRequestOptions;\n\nexport type WriteEncodedBlobOptions = {\n\tblobId: string;\n\tnodeIndex: number;\n\tmetadata: Uploadable | typeof BlobMetadata.$inferInput;\n\tslivers: SliversForNode;\n} & DeletableConfirmationOptions &\n\tWalrusClientRequestOptions;\n\nexport type WriteEncodedBlobToNodesOptions = {\n\tblobId: string;\n\tmetadata: Uploadable | typeof BlobMetadata.$inferInput;\n\tsliversByNode: SliversForNode[];\n} & DeletableConfirmationOptions &\n\tWalrusClientRequestOptions;\n\nexport type WriteBlobToUploadRelayOptions = {\n\tblobId: string;\n\tblob: Uint8Array;\n\tnonce: Uint8Array;\n\ttxDigest: string;\n\tblobObjectId: string;\n\tdeletable: boolean;\n\tencodingType?: EncodingType;\n} & WalrusClientRequestOptions;\n\nexport type WriteBlobOptions = {\n\tblob: Uint8Array;\n\tdeletable: boolean;\n\t/** The number of epochs the blob should be stored for. */\n\tepochs: number;\n\tsigner: Signer;\n\t/** Where the blob should be transferred to after it is registered. Defaults to the signer address. */\n\towner?: string;\n\t/** The attributes to write for the blob. */\n\tattributes?: Record<string, string | null>;\n} & WalrusClientRequestOptions;\n\nexport interface WriteQuiltOptions extends Omit<WriteBlobOptions, 'blob'> {\n\tblobs: {\n\t\tcontents: Uint8Array;\n\t\tidentifier: string;\n\t\ttags?: Record<string, string>;\n\t}[];\n}\n\nexport interface WriteFilesOptions extends Omit<WriteBlobOptions, 'blob'> {\n\tfiles: WalrusFile[];\n}\n\nexport interface WriteFilesFlowOptions extends Omit<WriteBlobOptions, 'blob' | 'signer'> {\n\tfiles: WalrusFile[];\n\towner: string;\n}\n\nexport interface WriteFilesFlow {\n\tencode: () => Promise<void>;\n\tregister: () => Transaction;\n\tupload: () => Promise<void>;\n\tcertify: () => Transaction;\n\tlistFiles: () => Promise<\n\t\t{\n\t\t\tid: string;\n\t\t\tblobId: string;\n\t\t\tblobObject: ReturnType<typeof Blob>['$inferType'];\n\t\t}[]\n\t>;\n}\n\nexport interface DeleteBlobOptions {\n\tblobObjectId: string;\n}\n\nexport type ExtendBlobOptions = {\n\tblobObjectId: string;\n\towner: string;\n\t/** optionally specify a WAL coin pay for the registration. This will consume WAL from the signer by default. */\n\twalCoin?: TransactionObjectArgument;\n} & (\n\t| {\n\t\t\t/** The number of epochs the blob should be stored for. */\n\t\t\tepochs: number;\n\t\t\tendEpoch?: never;\n\t }\n\t| {\n\t\t\t/** The new end epoch for the storage period of the blob. */\n\t\t\tendEpoch: number;\n\t\t\tepochs?: never;\n\t }\n);\n\nexport type WriteBlobAttributesOptions = {\n\tattributes: Record<string, string | null>;\n} & (\n\t| {\n\t\t\tblobObject: TransactionObjectArgument;\n\t\t\tblobObjectId?: never;\n\t }\n\t| {\n\t\t\tblobObjectId: string;\n\t\t\tblobObject?: never;\n\t }\n);\n\nexport type EncodingType = Extract<typeof EncodingType.$inferInput, string>;\n\nexport interface ProtocolMessageCertificate {\n\tsigners: number[];\n\tserializedMessage: Uint8Array;\n\tsignature: Uint8Array;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,7 +2,16 @@ import type { InferBcsType } from '@mysten/bcs';
|
|
|
2
2
|
import type { SuiMoveNormalizedType } from '@mysten/sui/client';
|
|
3
3
|
import type { Committee } from '../contracts/walrus/committee.js';
|
|
4
4
|
import type { EncodingType } from '../types.js';
|
|
5
|
+
export declare const REQUIRED_ALIGNMENT_BY_ENCODING_TYPE: {
|
|
6
|
+
RS2: number;
|
|
7
|
+
RedStuff: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const MAX_SYMBOL_SIZE_BY_ENCODING_TYPE: {
|
|
10
|
+
RS2: number;
|
|
11
|
+
RedStuff: number;
|
|
12
|
+
};
|
|
5
13
|
export declare function encodedBlobLength(unencodedLength: number, nShards: number, encodingType?: EncodingType): number;
|
|
14
|
+
export declare function encodedSliverSize(unencodedLength: number, nShards: number, encodingType?: EncodingType): number;
|
|
6
15
|
export declare function getSourceSymbols(nShards: number, encodingType?: EncodingType): {
|
|
7
16
|
primarySymbols: number;
|
|
8
17
|
secondarySymbols: number;
|
|
@@ -21,3 +30,9 @@ export declare function nodesByShardIndex(committee: InferBcsType<ReturnType<typ
|
|
|
21
30
|
export declare function toTypeString(type: SuiMoveNormalizedType): string;
|
|
22
31
|
export declare function urlSafeBase64(bytes: Uint8Array): string;
|
|
23
32
|
export declare function fromUrlSafeBase64(base64: string): Uint8Array;
|
|
33
|
+
export declare function getSizes(blobSize: number, numShards: number): {
|
|
34
|
+
symbolSize: number;
|
|
35
|
+
rowSize: number;
|
|
36
|
+
columnSize: number;
|
|
37
|
+
blobSize: number;
|
|
38
|
+
};
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -18,10 +18,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var utils_exports = {};
|
|
20
20
|
__export(utils_exports, {
|
|
21
|
+
MAX_SYMBOL_SIZE_BY_ENCODING_TYPE: () => MAX_SYMBOL_SIZE_BY_ENCODING_TYPE,
|
|
22
|
+
REQUIRED_ALIGNMENT_BY_ENCODING_TYPE: () => REQUIRED_ALIGNMENT_BY_ENCODING_TYPE,
|
|
21
23
|
encodedBlobLength: () => encodedBlobLength,
|
|
24
|
+
encodedSliverSize: () => encodedSliverSize,
|
|
22
25
|
fromUrlSafeBase64: () => fromUrlSafeBase64,
|
|
23
26
|
getMaxFaultyNodes: () => getMaxFaultyNodes,
|
|
24
27
|
getShardIndicesByNodeId: () => getShardIndicesByNodeId,
|
|
28
|
+
getSizes: () => getSizes,
|
|
25
29
|
getSourceSymbols: () => getSourceSymbols,
|
|
26
30
|
isAboveValidity: () => isAboveValidity,
|
|
27
31
|
isQuorum: () => isQuorum,
|
|
@@ -40,15 +44,27 @@ var import_bcs = require("@mysten/bcs");
|
|
|
40
44
|
var import_bcs2 = require("./bcs.js");
|
|
41
45
|
const DIGEST_LEN = 32;
|
|
42
46
|
const BLOB_ID_LEN = 32;
|
|
47
|
+
const REQUIRED_ALIGNMENT_BY_ENCODING_TYPE = {
|
|
48
|
+
RS2: 2,
|
|
49
|
+
RedStuff: 2
|
|
50
|
+
};
|
|
51
|
+
const MAX_SYMBOL_SIZE_BY_ENCODING_TYPE = {
|
|
52
|
+
RS2: 2 ** 16 - 1,
|
|
53
|
+
RedStuff: 2 ** 16 - 1
|
|
54
|
+
};
|
|
43
55
|
function encodedBlobLength(unencodedLength, nShards, encodingType = "RS2") {
|
|
56
|
+
const sliverSize = encodedSliverSize(unencodedLength, nShards, encodingType);
|
|
57
|
+
const metadata = nShards * DIGEST_LEN * 2 + BLOB_ID_LEN;
|
|
58
|
+
return nShards * metadata + sliverSize;
|
|
59
|
+
}
|
|
60
|
+
function encodedSliverSize(unencodedLength, nShards, encodingType = "RS2") {
|
|
44
61
|
const { primarySymbols, secondarySymbols } = getSourceSymbols(nShards, encodingType);
|
|
45
|
-
let
|
|
46
|
-
if (encodingType === "RS2" &&
|
|
47
|
-
|
|
62
|
+
let symbolSize = Math.floor((Math.max(unencodedLength, 1) - 1) / (primarySymbols * secondarySymbols)) + 1;
|
|
63
|
+
if (encodingType === "RS2" && symbolSize % 2 === 1) {
|
|
64
|
+
symbolSize = symbolSize + 1;
|
|
48
65
|
}
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
return nShards * metadata + sliversSize;
|
|
66
|
+
const singleShardSize = (primarySymbols + secondarySymbols) * symbolSize;
|
|
67
|
+
return singleShardSize * nShards;
|
|
52
68
|
}
|
|
53
69
|
function getSourceSymbols(nShards, encodingType = "RS2") {
|
|
54
70
|
const safetyLimit = decodingSafetyLimit(nShards, encodingType);
|
|
@@ -181,4 +197,24 @@ function urlSafeBase64(bytes) {
|
|
|
181
197
|
function fromUrlSafeBase64(base64) {
|
|
182
198
|
return (0, import_bcs.fromBase64)(base64.replaceAll("-", "+").replaceAll("_", "/"));
|
|
183
199
|
}
|
|
200
|
+
function getSizes(blobSize, numShards) {
|
|
201
|
+
const encodedBlobSize = encodedSliverSize(blobSize, numShards);
|
|
202
|
+
const { primarySymbols, secondarySymbols } = getSourceSymbols(numShards);
|
|
203
|
+
const totalSymbols = (primarySymbols + secondarySymbols) * numShards;
|
|
204
|
+
if (encodedBlobSize % totalSymbols !== 0) {
|
|
205
|
+
throw new Error("encoded blob size should be divisible by total symbols");
|
|
206
|
+
}
|
|
207
|
+
const symbolSize = encodedBlobSize / totalSymbols;
|
|
208
|
+
if (encodedBlobSize % totalSymbols !== 0) {
|
|
209
|
+
throw new Error("blob length should be divisible by total symbols");
|
|
210
|
+
}
|
|
211
|
+
const rowSize = symbolSize * secondarySymbols;
|
|
212
|
+
const columnSize = symbolSize * primarySymbols;
|
|
213
|
+
return {
|
|
214
|
+
symbolSize,
|
|
215
|
+
rowSize,
|
|
216
|
+
columnSize,
|
|
217
|
+
blobSize
|
|
218
|
+
};
|
|
219
|
+
}
|
|
184
220
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64 } from '@mysten/bcs';\nimport type { InferBcsType } from '@mysten/bcs';\nimport type { SuiMoveNormalizedType } from '@mysten/sui/client';\n\nimport type { Committee } from '../contracts/walrus/committee.js';\nimport type { EncodingType } from '../types.js';\nimport { BlobId } from './bcs.js';\n\nconst DIGEST_LEN = 32;\nconst BLOB_ID_LEN = 32;\n\nexport function encodedBlobLength(\n\tunencodedLength: number,\n\tnShards: number,\n\tencodingType: EncodingType = 'RS2',\n): number {\n\tconst { primarySymbols, secondarySymbols } = getSourceSymbols(nShards, encodingType);\n\n\tlet
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAqC;AAMrC,IAAAA,cAAuB;AAEvB,MAAM,aAAa;AACnB,MAAM,cAAc;AAEb,SAAS,kBACf,iBACA,SACA,eAA6B,OACpB;AACT,QAAM,EAAE,gBAAgB,iBAAiB,IAAI,iBAAiB,SAAS,YAAY;AAEnF,MAAI,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64 } from '@mysten/bcs';\nimport type { InferBcsType } from '@mysten/bcs';\nimport type { SuiMoveNormalizedType } from '@mysten/sui/client';\n\nimport type { Committee } from '../contracts/walrus/committee.js';\nimport type { EncodingType } from '../types.js';\nimport { BlobId } from './bcs.js';\n\nconst DIGEST_LEN = 32;\nconst BLOB_ID_LEN = 32;\n\nexport const REQUIRED_ALIGNMENT_BY_ENCODING_TYPE = {\n\tRS2: 2,\n\tRedStuff: 2,\n};\n\nexport const MAX_SYMBOL_SIZE_BY_ENCODING_TYPE = {\n\tRS2: 2 ** 16 - 1,\n\tRedStuff: 2 ** 16 - 1,\n};\n\n// TODO: this name is kinda bad\nexport function encodedBlobLength(\n\tunencodedLength: number,\n\tnShards: number,\n\tencodingType: EncodingType = 'RS2',\n): number {\n\tconst sliverSize = encodedSliverSize(unencodedLength, nShards, encodingType);\n\tconst metadata = nShards * DIGEST_LEN * 2 + BLOB_ID_LEN;\n\treturn nShards * metadata + sliverSize;\n}\n\nexport function encodedSliverSize(\n\tunencodedLength: number,\n\tnShards: number,\n\tencodingType: EncodingType = 'RS2',\n): number {\n\tconst { primarySymbols, secondarySymbols } = getSourceSymbols(nShards, encodingType);\n\n\tlet symbolSize =\n\t\tMath.floor((Math.max(unencodedLength, 1) - 1) / (primarySymbols * secondarySymbols)) + 1;\n\n\tif (encodingType === 'RS2' && symbolSize % 2 === 1) {\n\t\tsymbolSize = symbolSize + 1;\n\t}\n\n\tconst singleShardSize = (primarySymbols + secondarySymbols) * symbolSize;\n\n\treturn singleShardSize * nShards;\n}\n\nexport function getSourceSymbols(nShards: number, encodingType: EncodingType = 'RS2') {\n\tconst safetyLimit = decodingSafetyLimit(nShards, encodingType);\n\tconst maxFaulty = getMaxFaultyNodes(nShards);\n\tconst minCorrect = nShards - maxFaulty;\n\n\treturn {\n\t\tprimarySymbols: minCorrect - maxFaulty - safetyLimit,\n\t\tsecondarySymbols: minCorrect - safetyLimit,\n\t};\n}\n\nexport function isQuorum(size: number, nShards: number): boolean {\n\tconst maxFaulty = getMaxFaultyNodes(nShards);\n\treturn size > 2 * maxFaulty;\n}\n\nexport function isAboveValidity(size: number, nShards: number): boolean {\n\tconst maxFaulty = getMaxFaultyNodes(nShards);\n\treturn size > maxFaulty;\n}\n\nexport function getMaxFaultyNodes(nShards: number): number {\n\treturn Math.floor((nShards - 1) / 3);\n}\n\nfunction decodingSafetyLimit(nShards: number, encodingType: EncodingType): number {\n\tswitch (encodingType) {\n\t\tcase 'RedStuff':\n\t\t\treturn Math.min(5, Math.floor(getMaxFaultyNodes(nShards) / 5));\n\t\tcase 'RS2':\n\t\t\treturn 0;\n\t\tdefault:\n\t\t\tthrow new Error(`Encountered unknown encoding type of ${encodingType}`);\n\t}\n}\n\nconst BYTES_PER_UNIT_SIZE = 1024 * 1024;\n\nexport function storageUnitsFromSize(size: number): number {\n\treturn Math.ceil(size / BYTES_PER_UNIT_SIZE);\n}\n\nfunction rotationOffset(bytes: Uint8Array, modulus: number): number {\n\treturn bytes.reduce((acc, byte) => (acc * 256 + byte) % modulus, 0);\n}\n\nexport function toShardIndex(sliverPairIndex: number, blobId: string, numShards: number): number {\n\tconst offset = rotationOffset(BlobId.serialize(blobId).toBytes(), numShards);\n\treturn (sliverPairIndex + offset) % numShards;\n}\n\nexport function sliverPairIndexFromSecondarySliverIndex(\n\tsliverIndex: number,\n\tnumShards: number,\n): number {\n\treturn numShards - sliverIndex - 1;\n}\n\nexport function shardIndexFromSecondarySliverIndex(\n\tsliverIndex: number,\n\tblobId: string,\n\tnumShards: number,\n): number {\n\tconst sliverPairIndex = sliverPairIndexFromSecondarySliverIndex(sliverIndex, numShards);\n\treturn toShardIndex(sliverPairIndex, blobId, numShards);\n}\n\nexport function toPairIndex(shardIndex: number, blobId: string, numShards: number): number {\n\tconst offset = rotationOffset(BlobId.serialize(blobId).toBytes(), numShards);\n\treturn (numShards + shardIndex - offset) % numShards;\n}\n\nexport function signersToBitmap(signers: number[], committeeSize: number): Uint8Array {\n\tconst bitmapSize = Math.ceil(committeeSize / 8);\n\tconst bitmap = new Uint8Array(bitmapSize);\n\n\tfor (const signer of signers) {\n\t\tconst byteIndex = Math.floor(signer / 8);\n\t\tconst bitIndex = signer % 8;\n\t\tbitmap[byteIndex] |= 1 << bitIndex;\n\t}\n\n\treturn bitmap;\n}\n\nexport function getShardIndicesByNodeId(committee: InferBcsType<ReturnType<typeof Committee>>) {\n\tconst shardIndicesByNodeId = new Map<string, number[]>();\n\n\tfor (const node of committee[0].contents) {\n\t\tif (!shardIndicesByNodeId.has(node.key)) {\n\t\t\tshardIndicesByNodeId.set(node.key, []);\n\t\t}\n\t\tshardIndicesByNodeId.get(node.key)!.push(...node.value);\n\t}\n\n\treturn shardIndicesByNodeId;\n}\n\nexport function nodesByShardIndex(committee: InferBcsType<ReturnType<typeof Committee>>) {\n\tconst nodesByShardIndex = new Map<number, string>();\n\n\tfor (const node of committee[0].contents) {\n\t\tfor (const shardIndex of node.value) {\n\t\t\tnodesByShardIndex.set(shardIndex, node.key);\n\t\t}\n\t}\n\n\treturn nodesByShardIndex;\n}\n\nexport function toTypeString(type: SuiMoveNormalizedType): string {\n\tif (typeof type === 'string') {\n\t\tswitch (type) {\n\t\t\tcase 'Address':\n\t\t\t\treturn 'address';\n\t\t\tcase 'Bool':\n\t\t\t\treturn 'bool';\n\t\t\tcase 'U8':\n\t\t\t\treturn 'u8';\n\t\t\tcase 'U16':\n\t\t\t\treturn 'u16';\n\t\t\tcase 'U32':\n\t\t\t\treturn 'u32';\n\t\t\tcase 'U64':\n\t\t\t\treturn 'u64';\n\t\t\tcase 'U128':\n\t\t\t\treturn 'u128';\n\t\t\tcase 'U256':\n\t\t\t\treturn 'u256';\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unexpected type ${type}`);\n\t\t}\n\t}\n\n\tif ('Vector' in type) {\n\t\treturn `vector<${toTypeString(type.Vector)}>`;\n\t}\n\n\tif ('Struct' in type) {\n\t\tif (type.Struct.typeArguments.length > 0) {\n\t\t\treturn `${type.Struct.address}::${type.Struct.module}::${type.Struct.name}<${type.Struct.typeArguments.map(toTypeString).join(',')}>`;\n\t\t} else {\n\t\t\treturn `${type.Struct.address}::${type.Struct.module}::${type.Struct.name}`;\n\t\t}\n\t}\n\n\tif ('TypeParameter' in type) {\n\t\tthrow new Error(`Type parameters can't be converted to type strings`);\n\t}\n\n\tif ('Reference' in type) {\n\t\treturn toTypeString(type.Reference);\n\t}\n\n\tif ('MutableReference' in type) {\n\t\treturn toTypeString(type.MutableReference);\n\t}\n\n\tthrow new Error(`Unexpected type ${JSON.stringify(type)}`);\n}\n\nexport function urlSafeBase64(bytes: Uint8Array): string {\n\treturn toBase64(bytes).replace(/=*$/, '').replaceAll('+', '-').replaceAll('/', '_');\n}\n\nexport function fromUrlSafeBase64(base64: string): Uint8Array {\n\treturn fromBase64(base64.replaceAll('-', '+').replaceAll('_', '/'));\n}\n\nexport function getSizes(blobSize: number, numShards: number) {\n\tconst encodedBlobSize = encodedSliverSize(blobSize, numShards);\n\tconst { primarySymbols, secondarySymbols } = getSourceSymbols(numShards);\n\tconst totalSymbols = (primarySymbols + secondarySymbols) * numShards;\n\n\tif (encodedBlobSize % totalSymbols !== 0) {\n\t\tthrow new Error('encoded blob size should be divisible by total symbols');\n\t}\n\n\tconst symbolSize = encodedBlobSize / totalSymbols;\n\n\tif (encodedBlobSize % totalSymbols !== 0) {\n\t\tthrow new Error('blob length should be divisible by total symbols');\n\t}\n\n\tconst rowSize = symbolSize * secondarySymbols;\n\tconst columnSize = symbolSize * primarySymbols;\n\n\treturn {\n\t\tsymbolS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AAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
6
|
"names": ["import_bcs", "nodesByShardIndex"]
|
|
7
7
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { EncodingType } from '../types.js';
|
|
2
|
+
import type { QuiltPatchV1 } from './bcs.js';
|
|
3
|
+
import { QuiltPatchId } from './bcs.js';
|
|
2
4
|
export declare const QUILT_INDEX_SIZE_BYTES_LENGTH = 4;
|
|
3
5
|
export declare const QUILT_VERSION_BYTES_LENGTH = 1;
|
|
4
6
|
export declare const QUILT_INDEX_PREFIX_SIZE: number;
|
|
@@ -36,3 +38,35 @@ export declare function parseQuiltPatchId(id: string): {
|
|
|
36
38
|
endIndex: number;
|
|
37
39
|
};
|
|
38
40
|
};
|
|
41
|
+
export declare function encodeQuiltPatchId(id: typeof QuiltPatchId.$inferInput): string;
|
|
42
|
+
export declare function parseWalrusId(id: string): {
|
|
43
|
+
kind: "blob";
|
|
44
|
+
id: string;
|
|
45
|
+
} | {
|
|
46
|
+
kind: "quiltPatch";
|
|
47
|
+
id: {
|
|
48
|
+
quiltId: string;
|
|
49
|
+
patchId: {
|
|
50
|
+
version: number;
|
|
51
|
+
startIndex: number;
|
|
52
|
+
endIndex: number;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export interface EncodeQuiltOptions {
|
|
57
|
+
blobs: {
|
|
58
|
+
contents: Uint8Array;
|
|
59
|
+
identifier: string;
|
|
60
|
+
tags?: Record<string, string>;
|
|
61
|
+
}[];
|
|
62
|
+
numShards: number;
|
|
63
|
+
encodingType?: EncodingType;
|
|
64
|
+
}
|
|
65
|
+
export declare function encodeQuilt({ blobs, numShards, encodingType }: EncodeQuiltOptions): {
|
|
66
|
+
quilt: Uint8Array<ArrayBuffer>;
|
|
67
|
+
index: {
|
|
68
|
+
patches: (typeof QuiltPatchV1.$inferInput & {
|
|
69
|
+
startIndex: number;
|
|
70
|
+
})[];
|
|
71
|
+
};
|
|
72
|
+
};
|