Skip to content

Commit

Permalink
fixed a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yashgo0018 committed Dec 17, 2023
1 parent 9900e6c commit 0bb3790
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 6 additions & 5 deletions utils/SecretManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
bytesToHex,
isHex,
hexToBytes,
stringToHex,
} from "viem";
import { IFunctionsRouter$Type } from "../artifacts/@chainlink/contracts/src/v0.8/functions/dev/v1_0_0/interfaces/IFunctionsRouter.sol/IFunctionsRouter";
import { IFunctionsCoordinator$Type } from "../artifacts/@chainlink/contracts/src/v0.8/functions/dev/v1_0_0/interfaces/IFunctionsCoordinator.sol/IFunctionsCoordinator";
Expand Down Expand Up @@ -69,15 +70,13 @@ export class SecretsManager {

public async initialize(): Promise<void> {
const donIdBytes32 = isHex(this.donId)
? hexToBytes(this.donId)
: stringToBytes(this.donId!, { size: 32 });
? this.donId
: stringToHex(this.donId!, { size: 32 });

let functionsCoordinatorAddress: `0x${string}`;
try {
functionsCoordinatorAddress =
await this.functionsRouter.read.getContractById([
bytesToHex(donIdBytes32),
]);
await this.functionsRouter.read.getContractById([donIdBytes32]);
} catch (error) {
throw Error(
`${error}\n\nError encountered when attempting to fetch the FunctionsCoordinator address.\nEnsure the FunctionsRouter address and donId are correct and that that the provider is able to connect to the blockchain.`
Expand Down Expand Up @@ -218,6 +217,8 @@ export class SecretsManager {
signature,
});

console.log(signedSecrets);

const encryptedSignedSecrets = EthCrypto.cipher.stringify(
await EthCrypto.encryptWithPublicKey(donPublicKey, signedSecrets)
);
Expand Down
6 changes: 5 additions & 1 deletion utils/generateAndUploadEncryptedFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function generateAndUploadEncryptedFile({
secrets: Record<string, string>;
routerAddress: `0x${string}`;
donId: string;
}): Promise<string> {
}): Promise<`0x${string}`> {
const secretsManager = new SecretsManager({
walletClient,
functionsRouterAddress: routerAddress,
Expand Down Expand Up @@ -48,6 +48,10 @@ export async function generateAndUploadEncryptedFile({
};
const fileHash = data.IpfsHash;

const secreturl = `https://gateway.pinata.cloud/ipfs/${fileHash}`;

console.log(await secretsManager.verifyOffchainSecrets([secreturl]));

const encryptedSecretsUrls = await secretsManager.encryptSecretsUrls([
`https://gateway.pinata.cloud/ipfs/${fileHash}`,
]);
Expand Down

0 comments on commit 0bb3790

Please sign in to comment.