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

feat: add ipfsHash helper #713

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,3 @@ trim_trailing_whitespace = true
[*.md]
max_line_length = off
trim_trailing_whitespace = false

[*.rs]
indent_size = 4
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"tslib": "^2.7.0",
"tweetnacl": "^1.0.3",
"tweetnacl-util": "^0.15.1",
"typestub-ipfs-only-hash": "^4.0.0",
"uint8arrays": "^4.0.3"
},
"devDependencies": {
Expand Down
48 changes: 12 additions & 36 deletions packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { computeAddress } from '@ethersproject/transactions';
import { BigNumber, ethers } from 'ethers';
import { sha256 } from 'ethers/lib/utils';
import { SiweMessage } from 'siwe';
import * as Hash from 'typestub-ipfs-only-hash';

import {
LitAccessControlConditionResource,
Expand Down Expand Up @@ -662,40 +663,8 @@ export class LitNodeClientNodeJs
};

// ========== Promise Handlers ==========
getIpfsId = async ({
dataToHash,
sessionSigs,
}: {
dataToHash: string;
sessionSigs: SessionSigsMap;
debug?: boolean;
}) => {
const res = await this.executeJs({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were we using a LA for this? Seems like a tremendous overkill

ipfsId: LIT_ACTION_IPFS_HASH,
sessionSigs,
jsParams: {
dataToHash,
},
}).catch((e) => {
logError('Error getting IPFS ID', e);
throw e;
});

let data;

if (typeof res.response === 'string') {
try {
data = JSON.parse(res.response).res;
} catch (e) {
data = res.response;
}
}

if (!data.success) {
logError('Error getting IPFS ID', data.data);
}

return data.data;
getIpfsId = async ({ str }: { str: string }): Promise<`Qm${string}`> => {
return (await Hash.of(Buffer.from(str))) as `Qm${string}`;
};

/**
Expand Down Expand Up @@ -727,10 +696,17 @@ export class LitNodeClientNodeJs
);
}

if (!params.code) {
return throwError({
message: 'code is required',
errorKind: LIT_ERROR.INVALID_PARAM_TYPE.kind,
errorCode: LIT_ERROR.INVALID_PARAM_TYPE.name,
});
Comment on lines +700 to +704
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this PR is pointing to master (v7) it should be updated to use the new errors

}

// determine which node to run on
const ipfsId = await this.getIpfsId({
dataToHash: params.code!,
sessionSigs: params.sessionSigs,
str: params.code,
});

// select targetNodeRange number of random index of the bootstrapUrls.length
Expand Down
Loading
Loading