Skip to content
Closed
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"tslib": "^2.3.0",
"tweetnacl": "^1.0.3",
"tweetnacl-util": "^0.15.1",
"typestub-ipfs-only-hash": "^4.0.0",
"uint8arrays": "^4.0.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-sdk/src/lib/contracts-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export class LitContracts {
this.randomPrivateKey = args?.randomPrivatekey ?? false;
this.options = args?.options;
this.debug = args?.debug ?? false;
this.network = args?.network || 'cayenne';
this.network = args?.network || 'datil-dev';
// if rpc is not specified, use the default rpc
if (!this.rpc) {
this.rpc = RPC_URL_BY_NETWORK[this.network];
Expand Down
69 changes: 23 additions & 46 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 { joinSignature, sha256 } from 'ethers/lib/utils';
import { SiweMessage } from 'siwe';
import Hash from "typestub-ipfs-only-hash";

import {
ILitResource,
Expand Down Expand Up @@ -135,8 +136,7 @@ import type {

export class LitNodeClientNodeJs
extends LitCore
implements LitClientSessionManager, ILitNodeClient
{
implements LitClientSessionManager, ILitNodeClient {
defaultAuthCallback?: (authSigParams: AuthCallbackParams) => Promise<AuthSig>;

// ========== Constructor ==========
Expand Down Expand Up @@ -654,40 +654,10 @@ export class LitNodeClientNodeJs
};

// ========== Promise Handlers ==========
getIpfsId = async ({
dataToHash,
sessionSigs,
}: {
dataToHash: string;
sessionSigs: SessionSigsMap;
debug?: boolean;
}) => {
const res = await this.executeJs({
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 @@ -716,10 +686,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,
});
}

// 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 Expand Up @@ -1293,8 +1270,8 @@ export class LitNodeClientNodeJs
// -- optional params
...(params.authMethods &&
params.authMethods.length > 0 && {
authMethods: params.authMethods,
}),
authMethods: params.authMethods,
}),
};

logWithRequestId(requestId, 'reqBody:', reqBody);
Expand Down Expand Up @@ -2103,8 +2080,8 @@ export class LitNodeClientNodeJs
const sessionCapabilityObject = params.sessionCapabilityObject
? params.sessionCapabilityObject
: await this.generateSessionCapabilityObjectWithWildcards(
params.resourceAbilityRequests.map((r) => r.resource)
);
params.resourceAbilityRequests.map((r) => r.resource)
);
const expiration = params.expiration || LitNodeClientNodeJs.getExpiration();

// -- (TRY) to get the wallet signature
Expand Down Expand Up @@ -2187,10 +2164,10 @@ export class LitNodeClientNodeJs

const capabilities = params.capacityDelegationAuthSig
? [
...(params.capabilityAuthSigs ?? []),
params.capacityDelegationAuthSig,
authSig,
]
...(params.capabilityAuthSigs ?? []),
params.capacityDelegationAuthSig,
authSig,
]
: [...(params.capabilityAuthSigs ?? []), authSig];

const signingTemplate = {
Expand Down
Loading