Skip to content

Commit 7bd4623

Browse files
authored
Merge pull request #713 from LIT-Protocol/feat/add-ipfs-hash-helper
feat: add ipfsHash helper
2 parents 6514a07 + 0683a68 commit 7bd4623

File tree

4 files changed

+203
-70
lines changed

4 files changed

+203
-70
lines changed

.editorconfig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,3 @@ trim_trailing_whitespace = true
1111
[*.md]
1212
max_line_length = off
1313
trim_trailing_whitespace = false
14-
15-
[*.rs]
16-
indent_size = 4

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"tslib": "^2.7.0",
7070
"tweetnacl": "^1.0.3",
7171
"tweetnacl-util": "^0.15.1",
72+
"typestub-ipfs-only-hash": "^4.0.0",
7273
"uint8arrays": "^4.0.3"
7374
},
7475
"devDependencies": {

packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { computeAddress } from '@ethersproject/transactions';
22
import { BigNumber, ethers } from 'ethers';
33
import { sha256 } from 'ethers/lib/utils';
44
import { SiweMessage } from 'siwe';
5+
import * as Hash from 'typestub-ipfs-only-hash';
56

67
import {
78
LitAccessControlConditionResource,
@@ -665,40 +666,8 @@ export class LitNodeClientNodeJs
665666
};
666667

667668
// ========== Promise Handlers ==========
668-
getIpfsId = async ({
669-
dataToHash,
670-
sessionSigs,
671-
}: {
672-
dataToHash: string;
673-
sessionSigs: SessionSigsMap;
674-
debug?: boolean;
675-
}) => {
676-
const res = await this.executeJs({
677-
ipfsId: LIT_ACTION_IPFS_HASH,
678-
sessionSigs,
679-
jsParams: {
680-
dataToHash,
681-
},
682-
}).catch((e) => {
683-
logError('Error getting IPFS ID', e);
684-
throw e;
685-
});
686-
687-
let data;
688-
689-
if (typeof res.response === 'string') {
690-
try {
691-
data = JSON.parse(res.response).res;
692-
} catch (e) {
693-
data = res.response;
694-
}
695-
}
696-
697-
if (!data.success) {
698-
logError('Error getting IPFS ID', data.data);
699-
}
700-
701-
return data.data;
669+
getIpfsId = async ({ str }: { str: string }): Promise<`Qm${string}`> => {
670+
return (await Hash.of(Buffer.from(str))) as `Qm${string}`;
702671
};
703672

704673
/**
@@ -730,10 +699,20 @@ export class LitNodeClientNodeJs
730699
);
731700
}
732701

702+
if (!params.code) {
703+
throw new InvalidParamType(
704+
{
705+
info: {
706+
params,
707+
},
708+
},
709+
'code is required'
710+
);
711+
}
712+
733713
// determine which node to run on
734714
const ipfsId = await this.getIpfsId({
735-
dataToHash: params.code!,
736-
sessionSigs: params.sessionSigs,
715+
str: params.code,
737716
});
738717

739718
// select targetNodeRange number of random index of the bootstrapUrls.length

0 commit comments

Comments
 (0)