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 6b83415
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions src/dkg-threshold/lit-protocol/v6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
MintCapacityCreditsRes,
UnifiedAccessControlConditions,
AuthSig as GenericAuthSig,
CapacityCreditsRes,
SignerLike,
} from '@lit-protocol/types';
import { generateSymmetricKey, randomBytes } from '../../utils/helpers.js';
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 6b83415

Please sign in to comment.