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 5a91e1c
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 31 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
14 changes: 10 additions & 4 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,18 +103,22 @@ 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);
// mint capacity credits
await this.contractClient.mintCapacityCreditsNFT({
daysUntilUTCMidnightExpiration: 1,
});

// encrypt
const { ciphertext: encryptedString, dataToEncryptHash: stringHash } = (await this.client.encrypt({
Expand Down

0 comments on commit 5a91e1c

Please sign in to comment.