Skip to content

Commit

Permalink
deps: remove deprecated only-hash
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Sep 23, 2024
1 parent d0e3531 commit 6e80af0
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 700 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bgd-labs/aave-cli",
"version": "0.17.0",
"version": "1.0.0",
"description": "A cli to perform various aave governance related tasks",
"private": false,
"sideEffects": false,
Expand Down Expand Up @@ -68,7 +68,7 @@
"dotenv": "^16.4.1",
"find-object-paths": "^1.1.0",
"gray-matter": "^4.0.3",
"ipfs-only-hash": "^4.0.0",
"ipfs-unixfs-importer": "^15.3.1",
"json-bigint": "^1.0.0",
"object-hash": "^3.0.0",
"viem": "^2.17.11",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/ipfsUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import fs from 'node:fs';
import path from 'node:path';
import type {Command} from '@commander-js/extra-typings';
import bs58 from 'bs58';
import Hash from 'ipfs-only-hash';
import {validateAIPHeader} from '../ipfs/aipValidation';
import {logError} from '../utils/logger';
import {Hash} from '../ipfs/onlyHash';

// https://ethereum.stackexchange.com/questions/44506/ipfs-hash-algorithm
async function getHash(data: string): Promise<string> {
Expand Down
1 change: 0 additions & 1 deletion src/declarations.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
declare module 'ipfs-only-hash';
declare module 'json-bigint';
29 changes: 29 additions & 0 deletions src/ipfs/onlyHash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Based on https://github.com/alanshaw/ipfs-only-hash/blob/master/index.js
// added types and updated dependencies
import {importer, ImporterOptions} from 'ipfs-unixfs-importer';

const block = {
get: async (cid: string) => {
throw new Error(`unexpected block API get for ${cid}`);
},
put: async () => {
throw new Error('unexpected block API put');
},
};

export const Hash = {
of: async (content: string | Uint8Array, options: ImporterOptions = {}) => {
options = options || {};

if (typeof content === 'string') {
content = new TextEncoder().encode(content);
}

let lastCid;
for await (const {cid} of importer([{content}], block, options)) {
lastCid = cid;
}

return `${lastCid}`;
},
};
Loading

0 comments on commit 6e80af0

Please sign in to comment.