Skip to content

Commit

Permalink
feat: Lit protocol Mint capcity credit NFT
Browse files Browse the repository at this point in the history
  • Loading branch information
DaevMithran committed Sep 19, 2024
1 parent eb0ea0a commit c7656bc
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 32 deletions.
191 changes: 164 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"@cosmjs/stargate": "^0.32.4",
"@cosmjs/utils": "^0.32.4",
"@digitalbazaar/vc-status-list": "^8.0.0",
"@lit-protocol/contracts-sdk": "^6.5.1",
"@lit-protocol/encryption-v2": "npm:@lit-protocol/encryption@~2.2.63",
"@lit-protocol/lit-node-client": "^6.4.10",
"@lit-protocol/lit-node-client-v2": "npm:@lit-protocol/lit-node-client@~2.2.63",
Expand Down
16 changes: 11 additions & 5 deletions src/dkg-threshold/lit-protocol/v6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { OfflineAminoSigner, Secp256k1HdWallet, StdSignDoc } from '@cosmjs/amino
import { toString } from 'uint8arrays/to-string';
import { sha256 } from '@cosmjs/crypto';
import { LitNodeClientNodeJs, LitNodeClient } from '@lit-protocol/lit-node-client';
import { LitContracts } from '@lit-protocol/contracts-sdk';
import {
AccsCOSMOSParams,
ConditionType,
Expand Down Expand Up @@ -35,7 +36,7 @@ export type CosmosAuthSignature = {
};
export type CosmosAccessControlCondition = AccsCOSMOSParams & {
conditionType: ConditionType;
}
};
export type CosmosReturnValueTest = CosmosAccessControlCondition['returnValueTest'];
export type SaveEncryptionKeyArgs = {
unifiedAccessControlConditions: CosmosAccessControlCondition[];
Expand Down Expand Up @@ -79,6 +80,7 @@ export const TxNonceFormats = { entropy: 'entropy', uuid: 'uuid', timestamp: 'ti

export class LitProtocol {
client: LitNodeClientNodeJs | LitNodeClient;
contractClient: LitContracts;
litNetwork: LitNetwork = LitNetworks.datildev;
chain: LitCompatibleCosmosChain = LitCompatibleCosmosChains.cosmos;
private readonly cosmosAuthWallet: Secp256k1HdWallet;
Expand All @@ -101,19 +103,18 @@ export class LitProtocol {
if (isBrowser) return new LitNodeClient({ litNetwork: that.litNetwork, debug: LitProtocolDebugEnabled });
throw new Error('[did-provider-cheqd]: lit-protocol: Unsupported runtime environment');
})(this);

this.contractClient = new LitContracts({ network: this.litNetwork, signer: this.cosmosAuthWallet });
}

async connect(): Promise<void> {
return await this.client.connect();
await Promise.all([this.client.connect(), this.contractClient.connect()]);
}

async encrypt(
secret: Uint8Array,
unifiedAccessControlConditions: NonNullable<UnifiedAccessControlConditions>
): Promise<ThresholdEncryptionResult> {
// generate auth signature
const authSig = await LitProtocol.generateAuthSignature(this.cosmosAuthWallet);

// encrypt
const { ciphertext: encryptedString, dataToEncryptHash: stringHash } = (await this.client.encrypt({
dataToEncrypt: secret,
Expand All @@ -134,6 +135,11 @@ export class LitProtocol {
// generate auth signature
const authSig = await LitProtocol.generateAuthSignature(this.cosmosAuthWallet);

// mint capacity credits
await this.contractClient.mintCapacityCreditsNFT({
daysUntilUTCMidnightExpiration: 1,
});

// decrypt
const { decryptedData } = (await this.client.decrypt({
chain: this.chain,
Expand Down

0 comments on commit c7656bc

Please sign in to comment.