Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): replace ipfs-http-client with kubo-rpc-client #2829

Merged
merged 1 commit into from
Nov 15, 2023
Merged
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
3 changes: 3 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
"ipaddress",
"ipfs",
"IPFSHTTP",
"IPLD",
"ipld",
"Iroha",
"Irohad",
"isready",
Expand Down Expand Up @@ -148,6 +150,7 @@
"txqueue",
"Uisrs",
"undici",
"unixfs",
"Unmarshal",
"uuidv",
"vscc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
"dotenv": "^16.0.1",
"fabric-network": "2.2.19",
"fs-extra": "10.1.0",
"ipfs-http-client": "60.0.1",
"knex": "2.5.1",
"kubo-rpc-client": "3.0.1",
"nyc": "^13.1.0",
"openapi-types": "9.1.0",
"sqlite3": "^5.0.8",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import path from "path";
import { v4 as uuidv4 } from "uuid";
import fs from "fs-extra";
import { create } from "ipfs-http-client";
import {
Logger,
Checks,
Expand Down Expand Up @@ -289,7 +288,8 @@ export class CbdcBridgingAppDummyInfrastructure {
public async createIPFSConnector(): Promise<PluginObjectStoreIpfs> {
this.log.info(`Creating Besu Connector...`);

const ipfsClientOrOptions = create({
const kuboRpcClientModule = await import("kubo-rpc-client");
const ipfsClientOrOptions = kuboRpcClientModule.create({
url: await this.ipfs.getApiUrl(),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"outDir": "./dist/lib/",
"declarationDir": "dist/lib",
"rootDir": "./src",
"moduleResolution": "Node16",
"tsBuildInfoFile": "../../.build-cache/cactus-example-cbdc-bridging-backend.tsbuildinfo",
},
"references": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* transferNumericAsset.ts
*/

import { io } from "socket.io-client";
import { io } from "socket.io-client-fixed-types";

{
// Validator test program.(socket.io client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* transferNumericAsset.ts
*/

import { io } from "socket.io-client";
import { io } from "socket.io-client-fixed-types";

{
// Validator test program.(socket.io client)
Expand Down
4 changes: 2 additions & 2 deletions extensions/cactus-plugin-htlc-coordinator-besu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
"joi": "14.3.1",
"openapi-types": "7.0.1",
"prom-client": "13.1.0",
"run-time-error": "1.4.0",
"socket.io-client": "4.5.4",
"run-time-error-cjs": "1.4.0",
"socket.io-client-fixed-types": "4.5.4",
"typescript-optional": "2.0.1",
"uuid": "9.0.1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { v4 as uuidv4 } from "uuid";
import { Express } from "express";
import { promisify } from "util";
import { Optional } from "typescript-optional";
import { RuntimeError } from "run-time-error";
import { RuntimeError } from "run-time-error-cjs";
import fastSafeStringify from "fast-safe-stringify";
import OAS from "../json/openapi.json";
import {
Expand Down
2 changes: 1 addition & 1 deletion extensions/cactus-plugin-object-store-ipfs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ This plugin uses OpenAPI to generate the API paths. There are three endpoints de
Firstly create an instance of the plugin.

```typescript
import { create } from "ipfs-http-client";
import { create } from "kubo-rpc-client";

const logLevel: LogLevelDesc = "TRACE";
const ipfsClientOrOptions = create();
Expand Down
9 changes: 6 additions & 3 deletions extensions/cactus-plugin-object-store-ipfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,22 @@
"@hyperledger/cactus-core": "2.0.0-alpha.2",
"@hyperledger/cactus-core-api": "2.0.0-alpha.2",
"axios": "1.5.1",
"ipfs-http-client": "60.0.1",
"run-time-error": "1.4.0",
"run-time-error-cjs": "1.4.0",
"typescript-optional": "2.0.1",
"uuid": "8.3.2"
},
"devDependencies": {
"@hyperledger/cactus-test-tooling": "2.0.0-alpha.2",
"@multiformats/multiaddr": "11.6.1",
"@types/body-parser": "1.19.4",
"@types/express": "4.17.19",
"body-parser": "1.20.2",
"express": "4.18.2",
"ipfs-core-types": "0.14.1",
"multiformats": "9.4.9"
"ipfs-unixfs": "9.0.1",
"kubo-rpc-client": "3.0.1",
"kubo-rpc-client-esm-cjs": "3.0.1",
"multiformats": "11.0.2"
},
"engines": {
"node": ">=10",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/**
* Since kubo-rpc-client uses ESM only, we can't import it to get types (since we use CJS).
* To fix this we define required types here, based on their counterparts in kubo-rpc-client.
*/

// @ts-ignore
import type { Multiaddr } from "@multiformats/multiaddr";
// @ts-ignore
import type { MultihashHasher } from "multiformats/hashes/interface";
import type { Agent as HttpAgent } from "http";
import type { Agent as HttpsAgent } from "https";
// @ts-ignore
import type { CID } from "multiformats/cid";
// @ts-ignore
import type { Mtime } from "ipfs-unixfs";

/////////////////////////////////////
// Types from kubo-rpc-client
/////////////////////////////////////
// Some are simplified when details are not needed

export type MultibaseCodec<Prefix extends string = any> =
// @ts-ignore
import("multiformats/bases/interface").MultibaseCodec<Prefix>;
export type BlockCodec<
T1 = any,
T2 = any,
// @ts-ignore
> = import("multiformats/codecs/interface").BlockCodec<T1, T2>;

export interface LoadBaseFn {
(codeOrName: number | string): Promise<MultibaseCodec<any>>;
}
export interface LoadCodecFn {
(codeOrName: number | string): Promise<BlockCodec<any, any>>;
}
export interface LoadHasherFn {
(codeOrName: number | string): Promise<MultihashHasher>;
}

export interface IPLDOptions {
loadBase: LoadBaseFn;
loadCodec: LoadCodecFn;
loadHasher: LoadHasherFn;
bases: Array<MultibaseCodec<any>>;
codecs: Array<BlockCodec<any, any>>;
hashers: MultihashHasher[];
}

export interface Options {
host?: string;
port?: number;
protocol?: string;
headers?: Headers | Record<string, string>;
timeout?: number | string;
apiPath?: string;
url?: URL | string | Multiaddr;
ipld?: Partial<IPLDOptions>;
agent?: HttpAgent | HttpsAgent;
}

export type IPFSPath = CID | string;

export interface StatResult {
cid: CID;
size: number;
cumulativeSize: number;
type: "directory" | "file";
blocks: number;
withLocality: boolean;
local?: boolean;
sizeLocal?: number;
mode?: number;
mtime?: Mtime;
}

/////////////////////////////////////////////////////////
// LikeIpfsHttpClient instead of full IpfsHttpClient
/////////////////////////////////////////////////////////

/**
* Connector only needs these methods to work.
* More methods can be added in the future.
*/
export interface LikeIpfsHttpClientFile {
read: (
ipfsPath: IPFSPath,
options?: Record<string, unknown>,
) => AsyncIterable<Uint8Array>;

write: (
ipfsPath: string,
content:
| string
| Uint8Array
| Blob
| AsyncIterable<Uint8Array>
| Iterable<Uint8Array>,
options?: Record<string, unknown>,
) => Promise<void>;

stat: (
ipfsPath: IPFSPath,
options?: Record<string, unknown>,
) => Promise<StatResult>;
}

export function isLikeIpfsHttpClientFile(
x: unknown,
): x is LikeIpfsHttpClientFile {
if (!x) {
return false;
}
return (
typeof (x as LikeIpfsHttpClientFile).read === "function" &&
typeof (x as LikeIpfsHttpClientFile).write === "function" &&
typeof (x as LikeIpfsHttpClientFile).stat === "function"
);
}

/**
* Only files API is used
*/
export interface LikeIpfsHttpClient {
files: LikeIpfsHttpClientFile;
}

export function isLikeIpfsHttpClient(x: unknown): x is LikeIpfsHttpClient {
if (!x) {
return false;
}
return isLikeIpfsHttpClientFile((x as LikeIpfsHttpClient).files);
}
Loading
Loading