Skip to content

Commit

Permalink
Accept authsig on decrypt && expopose mintCapacityCredit
Browse files Browse the repository at this point in the history
  • Loading branch information
DaevMithran committed Oct 15, 2024
1 parent 8646068 commit ff026b8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 32 deletions.
6 changes: 4 additions & 2 deletions src/agent/ICheqd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6635,7 +6635,8 @@ export class Cheqd implements IAgentPlugin {
return await lit.decrypt(
thresholdEncryptionCiphertext,
publishedList.metadata.statusListHash!,
unifiedAccessControlConditions
unifiedAccessControlConditions,
options?.topArgs?.dkgOptions?.capacityDelegationAuthSig
);
})()
: await (async function () {
Expand Down Expand Up @@ -6805,7 +6806,8 @@ export class Cheqd implements IAgentPlugin {
return await lit.decrypt(
thresholdEncryptionCiphertext,
publishedList.metadata.statusListHash!,
unifiedAccessControlConditions
unifiedAccessControlConditions,
options?.topArgs?.dkgOptions?.capacityDelegationAuthSig
);
})()
: await (async function () {
Expand Down
56 changes: 26 additions & 30 deletions src/dkg-threshold/lit-protocol/v6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import {
MintCapacityCreditsRes,
UnifiedAccessControlConditions,
AuthSig as GenericAuthSig,
CapacityCreditsRes,
SignerLike,
} from '@lit-protocol/types';
import { generateSymmetricKey, randomBytes } from '../../utils/helpers.js';
import { isBrowser, isNode } from '../../utils/env.js';
import { v4 } from 'uuid';
import { fromString } from 'uint8arrays';
import { LitProtocolDebugEnabled } from '../../utils/constants.js';
import { LitAccessControlConditionResource, LitRLIResource } from '@lit-protocol/auth-helpers';
import { LitAccessControlConditionResource } from '@lit-protocol/auth-helpers';
import ethers from 'ethers';
import { LIT_RPC } from '@lit-protocol/constants';

Expand Down Expand Up @@ -94,7 +93,6 @@ export type LitContractsCreateCapacityDelegationAuthSignatureOptions = {
};
export type MintCapacityCreditsResult = MintCapacityCreditsRes;
export type CreateCapacityDelegationAuthSignatureResult = {
litResource: LitRLIResource;
capacityDelegationAuthSig: GenericAuthSig;
};

Expand Down Expand Up @@ -179,20 +177,9 @@ export class LitProtocol {
async decrypt(
encryptedString: string,
stringHash: string,
unifiedAccessControlConditions: NonNullable<UnifiedAccessControlConditions>
unifiedAccessControlConditions: NonNullable<UnifiedAccessControlConditions>,
capacityDelegationAuthSig: GenericAuthSig
): Promise<string> {
// mint capacity credits
const { capacityTokenIdStr } = await this.contractClient.mintCapacityCreditsNFT({
daysUntilUTCMidnightExpiration: 1,
});

const { capacityDelegationAuthSig } = await this.createCapacityDelegationAuthSignature({
uses: '1',
dAppOwnerWallet: this.contractClient.signer,
capacityTokenId: capacityTokenIdStr,
delegateeAddresses: [],
});

// generate session signatures
const sessionSigs = await this.client.getSessionSigs({
chain: 'cheqd',
Expand Down Expand Up @@ -222,6 +209,29 @@ export class LitProtocol {
return toString(decryptedData, 'utf-8');
}

async createCapacityDelegationAuthSignature(
options: LitContractsCreateCapacityDelegationAuthSignatureOptions
): Promise<CreateCapacityDelegationAuthSignatureResult> {
return await this.client.createCapacityDelegationAuthSig({
dAppOwnerWallet: options.dAppOwnerWallet,
capacityTokenId: options.capacityTokenId,
delegateeAddresses: options.delegateeAddresses,
uses: options.uses,
domain: options.domain,
expiration: options.expiration,
statement: options.statement,
});
}

async mintCapacityCredits(options: LitContractsMintCapacityCreditsOptions): Promise<MintCapacityCreditsResult> {
return this.contractClient.mintCapacityCreditsNFT({
daysUntilUTCMidnightExpiration: options.effectiveDays,
requestsPerDay: options.requestsPerDay,
requestsPerSecond: options.requestsPerSecond,
requestsPerKilosecond: options.requestsPerKilosecond,
});
}

static async encryptDirect(data: Uint8Array): Promise<SymmetricEncryptionResult> {
try {
// generate symmetric key
Expand Down Expand Up @@ -421,20 +431,6 @@ export class LitProtocol {
returnValueTest,
};
}

async createCapacityDelegationAuthSignature(
options: LitContractsCreateCapacityDelegationAuthSignatureOptions
): Promise<CapacityCreditsRes> {
return await this.client.createCapacityDelegationAuthSig({
dAppOwnerWallet: options.dAppOwnerWallet,
capacityTokenId: options.capacityTokenId,
delegateeAddresses: options.delegateeAddresses,
uses: options.uses,
domain: options.domain,
expiration: options.expiration,
statement: options.statement,
});
}
}

export class LitContracts {
Expand Down

0 comments on commit ff026b8

Please sign in to comment.