Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion common/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"tslog": "^3.2.2",
"unique-names-generator": "^4.6.0",
"uuid": "^9.0.0",
"@shelby-protocol/sdk": "^0.0.4",
"@aptos-labs/ts-sdk": "^5.1.1",
"electron": "^38.3.0",
"got": "^14.6.1",
"@mysten/walrus": "^0.7.2",
"@mysten/sui": "^1.39.1"
},
Expand All @@ -51,7 +55,6 @@
"@types/jest": "^28.1.7",
"@types/jsonfile": "^6.0.1",
"@types/node": "^24.7.1",
"@types/node-fetch": "^2.6.13",
"@types/object-hash": "^2.2.1",
"@types/seedrandom": "^3.0.2",
"@types/semver": "^7.3.9",
Expand Down
128 changes: 128 additions & 0 deletions common/protocol/src/reactors/storageProviders/Shelby.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { Account, Ed25519PrivateKey, Network } from "@aptos-labs/ts-sdk";
import {
buildRequestUrl,
NetworkToShelbyRPCBaseUrl,
ShelbyNodeClient,
} from "@shelby-protocol/sdk/node";
import { v4 as uuidv4 } from "uuid";

import dotenv from "dotenv";
import { BundleTag, IStorageProvider } from "../../types/index.js";

const TIME_TO_LIVE = 60 * 60 * 1_000_000;

dotenv.config();

export class Shelby implements IStorageProvider {
public name = "Shelby";
public coinDecimals = 18;

private readonly client: ShelbyNodeClient;
private readonly signer: Account;

private readonly baseUrl: string;
private readonly apiKey: string;

constructor(storagePriv: string) {
if (!storagePriv) {
throw new Error(
"Aptos private key is empty. Please provide a valid key!"
);
}

if (!process.env.SHELBY_API_KEY) {
throw new Error(
"Shelby storage provider requires SHELBY_API_KEY environment variable"
);
}

this.signer = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(storagePriv),
});

const network = Network.SHELBYNET;

this.client = new ShelbyNodeClient({
network,
apiKey: process.env.SHELBY_API_KEY,
});

this.baseUrl = NetworkToShelbyRPCBaseUrl[network];
this.apiKey = process.env.SHELBY_API_KEY;
}

async getAddress() {
return this.signer.accountAddress.toString();
}

async getBalance() {
return "";
}

async getPrice(_: number) {
return "0";
}

async saveBundle(bundle: Buffer, _tags: BundleTag[]) {
const storageId = uuidv4();

await this.client.upload({
blobData: Uint8Array.from(bundle),
signer: this.signer,
blobName: storageId,
expirationMicros: Date.now() * 1000 + TIME_TO_LIVE,
});

return {
storageId,
storageData: bundle,
};
}

async retrieveBundle(storageId: string, _timeout: number) {
const url = buildRequestUrl(
`/v1/blobs/${this.signer.accountAddress.toString()}/${storageId}`,
this.baseUrl
);

const headers = new Headers();
headers.set("Range", `bytes=0-`);

const response = await fetch(url, {
headers: {
...headers,
...(this.apiKey ? { Authorization: `Bearer ${this.apiKey}` } : {}),
},
});

if (!response.ok) {
throw new Error(
`Failed to download blob: ${response.status} ${response.statusText}`
);
}
if (!response.body) {
throw new Error("Response body is null");
}
const contentLengthHeader = response.headers.get("content-length");
if (contentLengthHeader === null) {
throw new Error(
"Response did not have content-length header, which is required"
);
}
const expectedContentLength = Number.parseInt(contentLengthHeader, 10);
if (Number.isNaN(expectedContentLength)) {
throw new Error(
`Invalid content-length header received: ${contentLengthHeader}`
);
}

const stream = response.body;
const chunks = [];
for await (const chunk of stream) {
chunks.push(chunk);
}
const storageData = Buffer.concat(chunks);

return { storageId, storageData };
}
}
4 changes: 4 additions & 0 deletions common/protocol/src/reactors/storageProviders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Bundlr } from "./Bundlr.js";
import { Kyve } from "./Kyve.js";
import { Turbo } from "./Turbo.js";
import { Load } from "./Load.js";
import { Shelby } from "./Shelby.js";
import { Walrus } from "./Walrus.js";
import { NoStorageProvider } from "./NoStorageProvider.js";

Expand All @@ -17,6 +18,7 @@ import { NoStorageProvider } from "./NoStorageProvider.js";
* 4 - Turbo
* 5 - Load
* 6 - Walrus
* 7 - Shelby
* x - NoStorageProvider (default)
*
* @method storageProviderFactory
Expand All @@ -36,6 +38,8 @@ export function storageProviderFactory(this: Validator): IStorageProvider {
return new Load(this.storagePriv);
case 6:
return new Walrus(this.storagePriv);
case 7:
return new Shelby(this.storagePriv);
default:
return new NoStorageProvider();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ export async function testStorageProvider(
): Promise<void> {
try {
const storageProvider = this.storageProviderFactory();

if (storageProvider.name === "NoStorageProvider") {
throw new Error(
`Storage provider id ${this.pool.data?.current_storage_provider_id} not found`
);
}

const bundle = Buffer.from(data);

this.logger.info(
Expand Down
2 changes: 1 addition & 1 deletion common/protocol/src/scripts/checksum.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import crypto from "crypto";
import * as crypto from "crypto";
import JSZip from "jszip";
import { createReadStream, readdirSync, readFileSync, writeFileSync } from "fs";

Expand Down
2 changes: 1 addition & 1 deletion common/protocol/src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigNumber } from "bignumber.js";
import crypto from "crypto";
import * as crypto from "crypto";
import { statSync, readdirSync } from "fs";
import { join } from "path";

Expand Down
2 changes: 1 addition & 1 deletion integrations/avail/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"dotenv": "^16.3.1"
},
"devDependencies": {
"pkg": "^5.8.0",
"@yao-pkg/pkg": "^6.10.1",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"typescript": "^4.7.4",
Expand Down
2 changes: 1 addition & 1 deletion integrations/ethereum-blobs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"dotenv": "^16.3.1"
},
"devDependencies": {
"pkg": "^5.8.0",
"@yao-pkg/pkg": "^6.10.1",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"typescript": "^4.7.4",
Expand Down
14 changes: 7 additions & 7 deletions integrations/ethereum-blobs/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import crypto from "crypto";
import axios from "axios";
import * as crypto from 'crypto';
import axios from 'axios';

export async function getTransactionByHash(rpc: string, hash: string) {
const data = {
method: 'eth_getTransactionByHash',
params: [hash],
id: 1,
jsonrpc: '2.0'
jsonrpc: '2.0',
};

try {
const response = await axios.post(rpc, data, {
headers: {
'Content-Type': 'application/json'
}
'Content-Type': 'application/json',
},
});
return response.data.result;
} catch (error) {
Expand All @@ -34,5 +34,5 @@ export function createVersionedHash(hex: string): string {

const formattedHash = '01' + hash.substring(2);

return "0x" + formattedHash;
}
return '0x' + formattedHash;
}
2 changes: 1 addition & 1 deletion integrations/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"ethers": "^5.6.5"
},
"devDependencies": {
"pkg": "^5.8.0",
"@yao-pkg/pkg": "^6.10.1",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"typescript": "^4.7.4",
Expand Down
2 changes: 1 addition & 1 deletion integrations/tendermint-bsync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"axios": "^0.27.2"
},
"devDependencies": {
"pkg": "^5.8.0",
"@yao-pkg/pkg": "^6.10.1",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"typescript": "^4.7.4",
Expand Down
2 changes: 1 addition & 1 deletion integrations/tendermint-ssync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"axios": "^0.27.2"
},
"devDependencies": {
"pkg": "^5.8.0",
"@yao-pkg/pkg": "^6.10.1",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"typescript": "^4.7.4",
Expand Down
9 changes: 6 additions & 3 deletions integrations/tendermint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
"license": "MIT",
"scripts": {
"build": "rimraf dist && tsc",
"transpile": "rimraf dist-cjs && webpack --config webpack.config.js && cp ../../node_modules/@mysten/walrus-wasm/walrus_wasm_bg.wasm dist-cjs",
"transpile": "rimraf dist-cjs && webpack --config webpack.config.js && cp ../../node_modules/@mysten/walrus-wasm/walrus_wasm_bg.wasm dist-cjs && cp ../../node_modules/@shelby-protocol/clay-codes/dist/clay.wasm dist-cjs",
"build:binaries": "yarn build && yarn transpile && rimraf out && pkg --no-bytecode --public-packages '*' --compress GZip --output out/kyve package.json && node ./dist-cjs/checksum.js",
"start": "node ./dist/src/index.js",
"format": "prettier --write ."
},
"bin": "./dist-cjs/bundle.js",
"pkg": {
"scripts": "./dist-cjs/bundle.js",
"assets": "./dist-cjs/walrus_wasm_bg.wasm",
"assets": [
"./dist-cjs/walrus_wasm_bg.wasm",
"./dist-cjs/clay.wasm"
],
"targets": [
"latest-linux-x64",
"latest-linux-arm64",
Expand All @@ -32,7 +35,7 @@
"dotenv": "^16.3.1"
},
"devDependencies": {
"pkg": "^5.8.0",
"@yao-pkg/pkg": "^6.10.1",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"typescript": "^4.7.4",
Expand Down
2 changes: 1 addition & 1 deletion tools/kysor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"dotenv": "^16.0.3",
"download": "^8.0.0",
"extract-zip": "^2.0.1",
"pkg": "^5.8.0",
"@yao-pkg/pkg": "^6.10.1",
"prompts": "^2.4.2",
"tslog": "^3.3.3"
},
Expand Down
2 changes: 1 addition & 1 deletion tools/kysor/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawn, SpawnOptionsWithoutStdio } from "child_process";
import crypto from "crypto";
import * as crypto from "crypto";
import fs from "fs";
import path from "path";
import { ILogObject, Logger } from "tslog";
Expand Down
Loading
Loading