@shelby-protocol/cli 0.0.10 → 0.0.11

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.
Files changed (2) hide show
  1. package/bin/entry.js +10 -394
  2. package/package.json +5 -5
package/bin/entry.js CHANGED
@@ -4,7 +4,7 @@
4
4
  import { Command } from "commander";
5
5
 
6
6
  // package.json
7
- var version = "0.0.10";
7
+ var version = "0.0.11";
8
8
 
9
9
  // src/commands/account.tsx
10
10
  import readline from "readline";
@@ -75,7 +75,7 @@ import {
75
75
 
76
76
  // ../../packages/sdk/dist/chunk-I6NG5GNL.mjs
77
77
  function sleep(ms) {
78
- return new Promise((resolve3) => setTimeout(resolve3, ms));
78
+ return new Promise((resolve2) => setTimeout(resolve2, ms));
79
79
  }
80
80
 
81
81
  // ../../node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.mjs
@@ -3987,395 +3987,11 @@ var DEFAULT_ERASURE_D = ERASURE_CODE_PARAMS[
3987
3987
  ].erasure_d;
3988
3988
  var DEFAULT_ERASURE_M = DEFAULT_ERASURE_N - DEFAULT_ERASURE_K;
3989
3989
 
3990
- // ../../packages/clay-codes/dist/chunk-ST33RHQN.js
3991
- var alignToMask = (value, mask) => value + mask & ~mask;
3992
- function createBumpAllocator(memory, initialHeap, alignMask, pageSize, onGrow) {
3993
- let heap = alignToMask(initialHeap, alignMask);
3994
- const ensureCapacity = (end) => {
3995
- while (end > memory.buffer.byteLength) {
3996
- const deficit = end - memory.buffer.byteLength;
3997
- const pages = Math.ceil(deficit / pageSize);
3998
- memory.grow(Math.max(pages, 1));
3999
- onGrow();
4000
- }
4001
- };
4002
- const allocate = (size, customAlignMask = alignMask) => {
4003
- const ptr = alignToMask(heap, customAlignMask);
4004
- heap = alignToMask(ptr + size, alignMask);
4005
- ensureCapacity(heap);
4006
- return ptr;
4007
- };
4008
- return allocate;
4009
- }
4010
- function createWasmWorkspace(memory, initialHeap, { alignMask, pageSize }) {
4011
- let buffer = memory.buffer;
4012
- const refreshCallbacks = /* @__PURE__ */ new Set();
4013
- const refreshAll = () => {
4014
- buffer = memory.buffer;
4015
- for (const callback of refreshCallbacks) callback();
4016
- };
4017
- const alloc = createBumpAllocator(
4018
- memory,
4019
- initialHeap,
4020
- alignMask,
4021
- pageSize,
4022
- refreshAll
4023
- );
4024
- const createStagingBuffer = (size) => {
4025
- const pointer = alloc(size);
4026
- let view = new Uint8Array(buffer, pointer, size);
4027
- const refresh = () => {
4028
- view = new Uint8Array(memory.buffer, pointer, size);
4029
- };
4030
- refreshCallbacks.add(refresh);
4031
- return {
4032
- get pointer() {
4033
- return pointer;
4034
- },
4035
- write(data) {
4036
- if (data.byteLength !== size) {
4037
- throw new Error(
4038
- `Staging buffer expected ${size} bytes but received ${data.byteLength}`
4039
- );
4040
- }
4041
- view.set(data);
4042
- },
4043
- read() {
4044
- return view.slice();
4045
- }
4046
- };
4047
- };
4048
- return { alloc, createStagingBuffer };
4049
- }
4050
-
4051
- // ../../packages/clay-codes/dist/chunk-22OVODFS.js
4052
- function normaliseChunkInput(input, expectedCount, chunkSize, label) {
4053
- const total = expectedCount * chunkSize;
4054
- const err = (msg) => new Error(`${label} ${msg}`);
4055
- if (Array.isArray(input)) {
4056
- if (input.length !== expectedCount) {
4057
- throw err(
4058
- `expected ${expectedCount} chunks but received ${input.length}`
4059
- );
4060
- }
4061
- input.forEach((chunk, i) => {
4062
- if (chunk.byteLength !== chunkSize) {
4063
- throw err(
4064
- `expected chunk ${i} to be ${chunkSize} bytes but received ${chunk.byteLength} bytes`
4065
- );
4066
- }
4067
- });
4068
- return input;
4069
- }
4070
- if (input.byteLength !== total) {
4071
- throw err(
4072
- `expected buffer to be ${total} bytes but received ${input.byteLength} bytes`
4073
- );
4074
- }
4075
- const chunks = new Array(expectedCount);
4076
- for (let i = 0; i < expectedCount; i++) {
4077
- const start = i * chunkSize;
4078
- const end = start + chunkSize;
4079
- chunks[i] = input.subarray(start, end);
4080
- }
4081
- return chunks;
4082
- }
4083
- function buildChunkCollection(chunks, k) {
4084
- return {
4085
- chunks,
4086
- systematic: chunks.slice(0, k),
4087
- parity: chunks.slice(k)
4088
- };
4089
- }
4090
-
4091
- // ../../packages/clay-codes/dist/chunk-N26WXNR7.js
4092
- var DEFAULT_ALIGNMENT = 64;
4093
- var DEFAULT_ALIGN_MASK = DEFAULT_ALIGNMENT - 1;
4094
- var DEFAULT_PAGE_SIZE = 65536;
4095
- var CLAY_PARAMS_BYTES = 64;
4096
-
4097
- // ../../packages/clay-codes/dist/chunk-XAN62WH2.js
4098
- var InvalidChunkIndexError = class extends Error {
4099
- constructor(index, reason) {
4100
- super(`Invalid chunk index ${index}: ${reason}`);
4101
- this.index = index;
4102
- this.name = "InvalidChunkIndexError";
4103
- }
4104
- };
4105
- var DuplicateChunkIndexError = class extends Error {
4106
- constructor(index) {
4107
- super(`Duplicate chunk index ${index}`);
4108
- this.index = index;
4109
- this.name = "DuplicateChunkIndexError";
4110
- }
4111
- };
4112
-
4113
- // ../../packages/clay-codes/dist/chunk-F5HTEQPI.js
4114
- var MAX_WASM_MASK_BITS = 32;
4115
- function toMaskFromIndexes(indexes, totalChunks) {
4116
- let mask = 0;
4117
- for (const idx of indexes) {
4118
- if (!Number.isInteger(idx) || idx < 0) {
4119
- throw new InvalidChunkIndexError(idx, "not a valid non-negative integer");
4120
- }
4121
- if (idx >= totalChunks) {
4122
- throw new InvalidChunkIndexError(
4123
- idx,
4124
- `exceeds total chunks (${totalChunks})`
4125
- );
4126
- }
4127
- if (idx >= MAX_WASM_MASK_BITS) {
4128
- throw new InvalidChunkIndexError(
4129
- idx,
4130
- `exceeds mask width (${MAX_WASM_MASK_BITS} bits)`
4131
- );
4132
- }
4133
- const bit = 1 << idx;
4134
- if (mask & bit) {
4135
- throw new DuplicateChunkIndexError(idx);
4136
- }
4137
- mask |= bit;
4138
- }
4139
- return mask >>> 0;
4140
- }
4141
- function erasedMaskFromAvailable(availableIndexes, totalChunks) {
4142
- const available = /* @__PURE__ */ new Set();
4143
- for (const idx of availableIndexes) {
4144
- if (!Number.isInteger(idx) || idx < 0) {
4145
- throw new InvalidChunkIndexError(idx, "not a valid non-negative integer");
4146
- }
4147
- if (idx >= totalChunks) {
4148
- throw new InvalidChunkIndexError(
4149
- idx,
4150
- `exceeds total chunks (${totalChunks})`
4151
- );
4152
- }
4153
- if (idx >= MAX_WASM_MASK_BITS) {
4154
- throw new InvalidChunkIndexError(
4155
- idx,
4156
- `exceeds mask width (${MAX_WASM_MASK_BITS} bits)`
4157
- );
4158
- }
4159
- if (available.has(idx)) {
4160
- throw new DuplicateChunkIndexError(idx);
4161
- }
4162
- available.add(idx);
4163
- }
4164
- let mask = 0;
4165
- for (let idx = 0; idx < totalChunks; idx++) {
4166
- if (!available.has(idx)) {
4167
- mask |= 1 << idx;
4168
- }
4169
- }
4170
- return mask >>> 0;
4171
- }
4172
- function convertToErasedMask(options, totalChunks) {
4173
- if ("erasedChunksMask" in options) {
4174
- return options.erasedChunksMask >>> 0;
4175
- }
4176
- if ("erasedChunkIndexes" in options) {
4177
- return toMaskFromIndexes(options.erasedChunkIndexes, totalChunks);
4178
- }
4179
- return erasedMaskFromAvailable(options.availableChunkIndexes, totalChunks);
4180
- }
4181
- function makeDecoderAPI(instance, opts) {
4182
- const exp = instance.exports;
4183
- const workspace = createWasmWorkspace(exp.memory, exp.__heap_base.value, {
4184
- alignMask: DEFAULT_ALIGN_MASK,
4185
- pageSize: DEFAULT_PAGE_SIZE
4186
- });
4187
- const paramsPtr = workspace.alloc(CLAY_PARAMS_BYTES, DEFAULT_ALIGN_MASK);
4188
- exp.clay_params_init(paramsPtr, opts.n, opts.k, opts.d, opts.chunkSizeBytes);
4189
- if (typeof exp.clay_decoder_footprint !== "function") {
4190
- throw new Error(
4191
- "Decoder footprint export not available in wasm module; bindings expect a dedicated decoder footprint entry point."
4192
- );
4193
- }
4194
- const decoderSize = exp.clay_decoder_footprint(paramsPtr);
4195
- const decoderPtr = workspace.alloc(decoderSize);
4196
- const staging = workspace.createStagingBuffer(opts.chunkSizeBytes);
4197
- const missingIndexes = /* @__PURE__ */ new Set();
4198
- const availableIndexes = [];
4199
- const staged = /* @__PURE__ */ new Set();
4200
- const applyMask = (mask) => {
4201
- missingIndexes.clear();
4202
- availableIndexes.length = 0;
4203
- for (let idx = 0; idx < opts.n; idx++) {
4204
- if (mask >>> idx & 1) {
4205
- missingIndexes.add(idx);
4206
- } else {
4207
- availableIndexes.push(idx);
4208
- }
4209
- }
4210
- };
4211
- const initialMask = convertToErasedMask(opts, opts.n);
4212
- const returnedPtr = exp.clay_decoder_init_mds(
4213
- decoderPtr,
4214
- initialMask,
4215
- paramsPtr
4216
- );
4217
- const activeDecoderPtr = returnedPtr || decoderPtr;
4218
- applyMask(initialMask);
4219
- let cachedMask = initialMask;
4220
- const setChunk = (idx, data) => {
4221
- if (missingIndexes.has(idx)) {
4222
- throw new Error(`Chunk ${idx} is marked erased and cannot be staged`);
4223
- }
4224
- if (data.byteLength !== opts.chunkSizeBytes) {
4225
- throw new Error(
4226
- `Chunk ${idx} length ${data.byteLength} does not match chunkSizeBytes ${opts.chunkSizeBytes}`
4227
- );
4228
- }
4229
- staging.write(data);
4230
- exp.clay_decoder_set_slice(
4231
- activeDecoderPtr,
4232
- idx,
4233
- staging.pointer,
4234
- opts.chunkSizeBytes
4235
- );
4236
- staged.add(idx);
4237
- };
4238
- const run = () => {
4239
- if (staged.size < opts.k) {
4240
- throw new Error(
4241
- `Decoder requires at least ${opts.k} staged chunks but only ${staged.size} provided`
4242
- );
4243
- }
4244
- exp.clay_decoder_run(activeDecoderPtr);
4245
- };
4246
- const getChunk = (idx) => {
4247
- exp.clay_decoder_get_chunk(activeDecoderPtr, idx, staging.pointer);
4248
- return staging.read();
4249
- };
4250
- const reconfigure = (erasurePattern) => {
4251
- const mask = convertToErasedMask(erasurePattern, opts.n);
4252
- if (mask !== cachedMask) {
4253
- const returned = exp.clay_decoder_init_mds(
4254
- activeDecoderPtr,
4255
- mask,
4256
- paramsPtr
4257
- );
4258
- if (returned && returned !== activeDecoderPtr) {
4259
- throw new Error(
4260
- "Decoder reconfiguration returned unexpected pointer; multiple decoder instances are not supported in-place."
4261
- );
4262
- }
4263
- applyMask(mask);
4264
- cachedMask = mask;
4265
- }
4266
- staged.clear();
4267
- };
4268
- const decode = (available, erasurePattern) => {
4269
- reconfigure(erasurePattern);
4270
- const chunks = normaliseChunkInput(
4271
- available,
4272
- availableIndexes.length,
4273
- opts.chunkSizeBytes,
4274
- "decoder input"
4275
- );
4276
- for (let i = 0; i < availableIndexes.length; i++) {
4277
- setChunk(availableIndexes[i], chunks[i]);
4278
- }
4279
- run();
4280
- const outputs = new Array(opts.n);
4281
- for (let idx = 0; idx < opts.n; idx++) {
4282
- outputs[idx] = getChunk(idx);
4283
- }
4284
- return buildChunkCollection(outputs, opts.k);
4285
- };
4286
- return { setChunk, run, getChunk, decode };
4287
- }
4288
-
4289
- // ../../packages/clay-codes/dist/chunk-U2WMFYBV.js
4290
- function makeEncoderAPI(instance, opts) {
4291
- const exp = instance.exports;
4292
- const workspace = createWasmWorkspace(exp.memory, exp.__heap_base.value, {
4293
- alignMask: DEFAULT_ALIGN_MASK,
4294
- pageSize: DEFAULT_PAGE_SIZE
4295
- });
4296
- const paramsPtr = workspace.alloc(CLAY_PARAMS_BYTES, DEFAULT_ALIGN_MASK);
4297
- exp.clay_params_init(paramsPtr, opts.n, opts.k, opts.d, opts.chunkSizeBytes);
4298
- const encPtr = workspace.alloc(exp.clay_encoder_footprint(paramsPtr));
4299
- exp.clay_encoder_init(encPtr, paramsPtr);
4300
- const staging = workspace.createStagingBuffer(opts.chunkSizeBytes);
4301
- const setChunk = (idx, data) => {
4302
- if (data.byteLength !== opts.chunkSizeBytes) {
4303
- throw new Error(
4304
- `Chunk ${idx} length ${data.byteLength} does not match chunkSizeBytes ${opts.chunkSizeBytes}`
4305
- );
4306
- }
4307
- staging.write(data);
4308
- exp.clay_encoder_set_data_chunk(encPtr, idx, staging.pointer);
4309
- };
4310
- const run = () => {
4311
- exp.clay_encoder_run(encPtr);
4312
- };
4313
- const getChunk = (idx) => {
4314
- exp.clay_encoder_get_chunk(encPtr, idx, staging.pointer);
4315
- return staging.read();
4316
- };
4317
- const erasureCode = (input) => {
4318
- const chunks = normaliseChunkInput(
4319
- input,
4320
- opts.k,
4321
- opts.chunkSizeBytes,
4322
- "encoder input"
4323
- );
4324
- for (let idx = 0; idx < chunks.length; idx++) {
4325
- setChunk(idx, chunks[idx]);
4326
- }
4327
- run();
4328
- const outputs = new Array(opts.n);
4329
- for (let idx = 0; idx < opts.n; idx++) {
4330
- outputs[idx] = getChunk(idx);
4331
- }
4332
- return buildChunkCollection(outputs, opts.k);
4333
- };
4334
- return { setChunk, run, getChunk, erasureCode };
4335
- }
4336
-
4337
- // ../../packages/clay-codes/dist/index-node.js
4338
- import { readFile } from "fs/promises";
4339
- import { dirname, resolve } from "path";
4340
- import { fileURLToPath } from "url";
4341
- async function loadWasm() {
4342
- const here = dirname(fileURLToPath(import.meta.url));
4343
- const paths = [
4344
- resolve(here, "clay.wasm"),
4345
- resolve(here, "../dist/clay.wasm")
4346
- ];
4347
- let bytes;
4348
- for (const path6 of paths) {
4349
- try {
4350
- bytes = await readFile(path6);
4351
- break;
4352
- } catch {
4353
- }
4354
- }
4355
- if (!bytes) {
4356
- throw new Error(`Unable to locate clay.wasm. Tried: ${paths.join(", ")}`);
4357
- }
4358
- const defaultImports = {
4359
- env: {
4360
- abort: () => {
4361
- throw new Error("WASM abort called");
4362
- },
4363
- js_msg: (i) => console.log(`wasm msg: ${i}`)
4364
- }
4365
- };
4366
- const module = await WebAssembly.compile(bytes);
4367
- return WebAssembly.instantiate(module, defaultImports);
4368
- }
4369
- async function createEncoder(opts) {
4370
- const instance = await loadWasm();
4371
- return makeEncoderAPI(instance, opts);
4372
- }
4373
- async function createDecoder(opts) {
4374
- const instance = await loadWasm();
4375
- return makeDecoderAPI(instance, opts);
4376
- }
4377
-
4378
3990
  // ../../packages/sdk/dist/chunk-APML3CGJ.mjs
3991
+ import {
3992
+ createDecoder,
3993
+ createEncoder
3994
+ } from "@shelby-protocol/clay-codes";
4379
3995
  var CHUNK_SIZE_PARAMS = {
4380
3996
  [
4381
3997
  "ChunkSet10MiB_Chunk1MiB"
@@ -7381,10 +6997,10 @@ function askQuestion(question) {
7381
6997
  input: process.stdin,
7382
6998
  output: process.stdout
7383
6999
  });
7384
- return new Promise((resolve3) => {
7000
+ return new Promise((resolve2) => {
7385
7001
  rl.question(question, (answer) => {
7386
7002
  rl.close();
7387
- resolve3(answer.trim());
7003
+ resolve2(answer.trim());
7388
7004
  });
7389
7005
  });
7390
7006
  }
@@ -8685,7 +8301,7 @@ function uploadCommand(program) {
8685
8301
  }
8686
8302
  const cost = computeCost(filelist);
8687
8303
  if (!validatedOptions.assumeYes) {
8688
- const shouldContinue = await new Promise((resolve3) => {
8304
+ const shouldContinue = await new Promise((resolve2) => {
8689
8305
  const { unmount } = render4(
8690
8306
  /* @__PURE__ */ jsxs7(Box7, { flexDirection: "column", children: [
8691
8307
  /* @__PURE__ */ jsxs7(Text7, { children: [
@@ -8702,7 +8318,7 @@ function uploadCommand(program) {
8702
8318
  ],
8703
8319
  onSelect: (item) => {
8704
8320
  unmount();
8705
- resolve3(item.value);
8321
+ resolve2(item.value);
8706
8322
  }
8707
8323
  }
8708
8324
  )
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shelby-protocol/cli",
3
3
  "type": "module",
4
- "version": "0.0.10",
4
+ "version": "0.0.11",
5
5
  "private": false,
6
6
  "bin": {
7
7
  "shelby": "bin/entry.js"
@@ -37,7 +37,9 @@
37
37
  "which": "^5.0.0",
38
38
  "wrap-ansi": "^9.0.2",
39
39
  "yaml": "^2.7.1",
40
- "zod": "^3.22.4"
40
+ "zod": "^3.22.4",
41
+ "@shelby-protocol/clay-codes": "0.0.1",
42
+ "@shelby-protocol/sdk": "0.0.3"
41
43
  },
42
44
  "devDependencies": {
43
45
  "@types/fs-extra": "^11.0.4",
@@ -54,9 +56,7 @@
54
56
  "tsx": "^4.7.1",
55
57
  "typescript": "^5.8.3",
56
58
  "vite-tsconfig-paths": "^5.1.4",
57
- "vitest": "^3.1.2",
58
- "@shelby-protocol/sdk": "0.0.3",
59
- "@shelby-protocol/clay-codes": "0.0.1"
59
+ "vitest": "^3.1.2"
60
60
  },
61
61
  "scripts": {
62
62
  "lint": "biome check .",