From 5a91e1ca5e0f7b217d7452bccda7e813c9d5ab83 Mon Sep 17 00:00:00 2001 From: DaevMithran Date: Thu, 19 Sep 2024 13:28:05 +0530 Subject: [PATCH] feat: Lit protocol Mint capcity credit NFT --- package-lock.json | 191 +++++++++++++++++++++++---- package.json | 1 + src/dkg-threshold/lit-protocol/v6.ts | 14 +- 3 files changed, 175 insertions(+), 31 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2ae8969..c65000c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,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", @@ -2782,10 +2783,9 @@ } }, "node_modules/@lit-protocol/contracts-sdk": { - "version": "6.4.10", - "resolved": "https://registry.npmjs.org/@lit-protocol/contracts-sdk/-/contracts-sdk-6.4.10.tgz", - "integrity": "sha512-QQIDXzXAdpEeZw+RPWiiFV243ZR1vI1bmXZ1S4FmBeYGtXTcwHGqDdWb44GiBqKK0xMp+XCchpG2CtFt9ACDOg==", - "license": "MIT", + "version": "6.5.1", + "resolved": "https://registry.npmjs.org/@lit-protocol/contracts-sdk/-/contracts-sdk-6.5.1.tgz", + "integrity": "sha512-HTBKeFW5EBq7qH82bYp74hBpMqPc+qgvQdLywbVVJg6lGGzOGhRr7H+tr29EhR4Dchd7/TxpKt18jjrgp4ds5g==", "dependencies": { "@cosmjs/amino": "0.30.1", "@cosmjs/crypto": "0.30.1", @@ -2794,12 +2794,12 @@ "@ethersproject/abstract-provider": "5.7.0", "@ethersproject/contracts": "5.7.0", "@ethersproject/providers": "5.7.2", - "@lit-protocol/accs-schemas": "^0.0.11", - "@lit-protocol/constants": "6.4.10", + "@lit-protocol/accs-schemas": "^0.0.12", + "@lit-protocol/constants": "6.5.1", "@lit-protocol/contracts": "^0.0.63", - "@lit-protocol/logger": "6.4.10", - "@lit-protocol/misc": "6.4.10", - "@lit-protocol/types": "6.4.10", + "@lit-protocol/logger": "6.5.1", + "@lit-protocol/misc": "6.5.1", + "@lit-protocol/types": "6.5.1", "ajv": "^8.12.0", "bitcoinjs-lib": "^6.1.0", "ethers": "^5.7.1", @@ -2866,36 +2866,60 @@ "integrity": "sha512-KvvX58MGMWh7xA+N+deCfunkA/ZNDvFLw4YbOmX3f/XBIkqrVY7qlotfy2aNb1kgp6h4B6Yc8YawJPDTfvWX7g==", "license": "Apache-2.0" }, + "node_modules/@lit-protocol/contracts-sdk/node_modules/@lit-protocol/accs-schemas": { + "version": "0.0.12", + "resolved": "https://registry.npmjs.org/@lit-protocol/accs-schemas/-/accs-schemas-0.0.12.tgz", + "integrity": "sha512-tkAddbEexpjbIY01TFB8YWffe6PFWkxdiSZsriPINfVAL5VmTiL6YH9D3faDP+rNaGMUXu0/AMQ0Dft/iGuLLA==", + "dependencies": { + "ajv": "^8.12.0" + } + }, "node_modules/@lit-protocol/contracts-sdk/node_modules/@lit-protocol/constants": { - "version": "6.4.10", - "resolved": "https://registry.npmjs.org/@lit-protocol/constants/-/constants-6.4.10.tgz", - "integrity": "sha512-vfMjrkBgWThY2zC44/jGpic9rqYBawmKShFoHIFmOgxMpR/EX5OK0tucjl02C1RFmsn77b/PiHRWe1gzayehpA==", - "license": "MIT", + "version": "6.5.1", + "resolved": "https://registry.npmjs.org/@lit-protocol/constants/-/constants-6.5.1.tgz", + "integrity": "sha512-BQlklrLFtLbugab17SNFU2tzAgT/zXkhrTtgaOOOn/HUrSYzhNe/S68TSmODV4b3dU/Eo0ZBN3sjH+3epLxtrQ==", "dependencies": { "@ethersproject/abstract-provider": "5.7.0", - "@lit-protocol/accs-schemas": "^0.0.11", + "@lit-protocol/accs-schemas": "^0.0.12", "@lit-protocol/contracts": "^0.0.63", - "@lit-protocol/types": "6.4.10", + "@lit-protocol/types": "6.5.1", "ethers": "^5.7.1", "jszip": "^3.10.1", "siwe": "^2.0.5", "tslib": "1.14.1" } }, + "node_modules/@lit-protocol/contracts-sdk/node_modules/@lit-protocol/logger": { + "version": "6.5.1", + "resolved": "https://registry.npmjs.org/@lit-protocol/logger/-/logger-6.5.1.tgz", + "integrity": "sha512-oHWIeqNOwZGd0RchBoGKUvEAVWNj3L3k7GR8V+0GOaCkX2bqGjtJfZqpX4ANSssVYFvUonZl+rq+WcP0sR123g==", + "dependencies": { + "@ethersproject/abstract-provider": "5.7.0", + "@lit-protocol/accs-schemas": "^0.0.12", + "@lit-protocol/constants": "6.5.1", + "@lit-protocol/contracts": "^0.0.63", + "@lit-protocol/types": "6.5.1", + "ethers": "^5.7.1", + "jszip": "^3.10.1", + "punycode": "2.3.1", + "siwe": "^2.0.5", + "tslib": "1.14.1", + "uint8arrays": "^4.0.3" + } + }, "node_modules/@lit-protocol/contracts-sdk/node_modules/@lit-protocol/misc": { - "version": "6.4.10", - "resolved": "https://registry.npmjs.org/@lit-protocol/misc/-/misc-6.4.10.tgz", - "integrity": "sha512-NJ7ia4M5tcW/MZyRvWbaR5wEmjDy2s/pEV30Os2IyatL+Fjzo1BNh69VmGMqQkEi46UJH99hGIFZnl3TwvojNw==", - "license": "MIT", + "version": "6.5.1", + "resolved": "https://registry.npmjs.org/@lit-protocol/misc/-/misc-6.5.1.tgz", + "integrity": "sha512-FFth4zmOkiA2dPdB/n5fwzVYZe7rE182vYa4N/dnMNMRwwmmlLzKTSfWs3UrQ+ui6b9Z+4B/ra//FITLevM5tg==", "dependencies": { "@ethersproject/abstract-provider": "5.7.0", "@ethersproject/contracts": "5.7.0", "@ethersproject/providers": "5.7.2", - "@lit-protocol/accs-schemas": "^0.0.11", - "@lit-protocol/constants": "6.4.10", + "@lit-protocol/accs-schemas": "^0.0.12", + "@lit-protocol/constants": "6.5.1", "@lit-protocol/contracts": "^0.0.63", - "@lit-protocol/logger": "6.4.10", - "@lit-protocol/types": "6.4.10", + "@lit-protocol/logger": "6.5.1", + "@lit-protocol/types": "6.5.1", "ajv": "^8.12.0", "ethers": "^5.7.1", "jszip": "^3.10.1", @@ -2906,11 +2930,23 @@ "util": "0.12.5" } }, + "node_modules/@lit-protocol/contracts-sdk/node_modules/@lit-protocol/types": { + "version": "6.5.1", + "resolved": "https://registry.npmjs.org/@lit-protocol/types/-/types-6.5.1.tgz", + "integrity": "sha512-Vqf3txWivc1UGbCDk8/vnfUusG5CiZRU2oeUIz5AZr5a5djcGWNwL/hqblyMTiaB3OB7cLyLUENI4Mt8VYd54w==", + "dependencies": { + "@ethersproject/abstract-provider": "5.7.0", + "@lit-protocol/accs-schemas": "^0.0.12", + "ethers": "^5.7.1", + "jszip": "^3.10.1", + "siwe": "^2.0.5", + "tslib": "1.14.1" + } + }, "node_modules/@lit-protocol/contracts-sdk/node_modules/multiformats": { "version": "12.1.3", "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-12.1.3.tgz", "integrity": "sha512-eajQ/ZH7qXZQR2AgtfpmSMizQzmyYVmCql7pdhldPuYQi4atACekbJaQplk6dWyIi10jCaFnd6pqvcEFXjbaJw==", - "license": "Apache-2.0 OR MIT", "engines": { "node": ">=16.0.0", "npm": ">=7.0.0" @@ -2919,14 +2955,12 @@ "node_modules/@lit-protocol/contracts-sdk/node_modules/tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", - "license": "0BSD" + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" }, "node_modules/@lit-protocol/contracts-sdk/node_modules/uint8arrays": { "version": "4.0.10", "resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-4.0.10.tgz", "integrity": "sha512-AnJNUGGDJAgFw/eWu/Xb9zrVKEGlwJJCaeInlf3BkecE/zcTobk5YXYIPNQJO1q5Hh1QZrQQHf0JvcHqz2hqoA==", - "license": "Apache-2.0 OR MIT", "dependencies": { "multiformats": "^12.0.1" } @@ -3055,6 +3089,37 @@ "tslib": "1.14.1" } }, + "node_modules/@lit-protocol/core/node_modules/@lit-protocol/contracts-sdk": { + "version": "6.4.10", + "resolved": "https://registry.npmjs.org/@lit-protocol/contracts-sdk/-/contracts-sdk-6.4.10.tgz", + "integrity": "sha512-QQIDXzXAdpEeZw+RPWiiFV243ZR1vI1bmXZ1S4FmBeYGtXTcwHGqDdWb44GiBqKK0xMp+XCchpG2CtFt9ACDOg==", + "dependencies": { + "@cosmjs/amino": "0.30.1", + "@cosmjs/crypto": "0.30.1", + "@cosmjs/encoding": "0.30.1", + "@ethersproject/abi": "5.7.0", + "@ethersproject/abstract-provider": "5.7.0", + "@ethersproject/contracts": "5.7.0", + "@ethersproject/providers": "5.7.2", + "@lit-protocol/accs-schemas": "^0.0.11", + "@lit-protocol/constants": "6.4.10", + "@lit-protocol/contracts": "^0.0.63", + "@lit-protocol/logger": "6.4.10", + "@lit-protocol/misc": "6.4.10", + "@lit-protocol/types": "6.4.10", + "ajv": "^8.12.0", + "bitcoinjs-lib": "^6.1.0", + "ethers": "^5.7.1", + "jose": "^4.14.4", + "jszip": "^3.10.1", + "process": "0.11.10", + "punycode": "2.3.1", + "siwe": "^2.0.5", + "tslib": "1.14.1", + "uint8arrays": "^4.0.3", + "util": "0.12.5" + } + }, "node_modules/@lit-protocol/core/node_modules/@lit-protocol/crypto": { "version": "6.4.10", "resolved": "https://registry.npmjs.org/@lit-protocol/crypto/-/crypto-6.4.10.tgz", @@ -3670,6 +3735,42 @@ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", "license": "0BSD" }, + "node_modules/@lit-protocol/lit-node-client-nodejs/node_modules/@lit-protocol/contracts-sdk": { + "version": "6.4.10", + "resolved": "https://registry.npmjs.org/@lit-protocol/contracts-sdk/-/contracts-sdk-6.4.10.tgz", + "integrity": "sha512-QQIDXzXAdpEeZw+RPWiiFV243ZR1vI1bmXZ1S4FmBeYGtXTcwHGqDdWb44GiBqKK0xMp+XCchpG2CtFt9ACDOg==", + "dependencies": { + "@cosmjs/amino": "0.30.1", + "@cosmjs/crypto": "0.30.1", + "@cosmjs/encoding": "0.30.1", + "@ethersproject/abi": "5.7.0", + "@ethersproject/abstract-provider": "5.7.0", + "@ethersproject/contracts": "5.7.0", + "@ethersproject/providers": "5.7.2", + "@lit-protocol/accs-schemas": "^0.0.11", + "@lit-protocol/constants": "6.4.10", + "@lit-protocol/contracts": "^0.0.63", + "@lit-protocol/logger": "6.4.10", + "@lit-protocol/misc": "6.4.10", + "@lit-protocol/types": "6.4.10", + "ajv": "^8.12.0", + "bitcoinjs-lib": "^6.1.0", + "ethers": "^5.7.1", + "jose": "^4.14.4", + "jszip": "^3.10.1", + "process": "0.11.10", + "punycode": "2.3.1", + "siwe": "^2.0.5", + "tslib": "1.14.1", + "uint8arrays": "^4.0.3", + "util": "0.12.5" + } + }, + "node_modules/@lit-protocol/lit-node-client-nodejs/node_modules/@lit-protocol/contracts-sdk/node_modules/tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" + }, "node_modules/@lit-protocol/lit-node-client-nodejs/node_modules/@lit-protocol/crypto": { "version": "6.4.10", "resolved": "https://registry.npmjs.org/@lit-protocol/crypto/-/crypto-6.4.10.tgz", @@ -4942,6 +5043,42 @@ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", "license": "0BSD" }, + "node_modules/@lit-protocol/lit-node-client/node_modules/@lit-protocol/contracts-sdk": { + "version": "6.4.10", + "resolved": "https://registry.npmjs.org/@lit-protocol/contracts-sdk/-/contracts-sdk-6.4.10.tgz", + "integrity": "sha512-QQIDXzXAdpEeZw+RPWiiFV243ZR1vI1bmXZ1S4FmBeYGtXTcwHGqDdWb44GiBqKK0xMp+XCchpG2CtFt9ACDOg==", + "dependencies": { + "@cosmjs/amino": "0.30.1", + "@cosmjs/crypto": "0.30.1", + "@cosmjs/encoding": "0.30.1", + "@ethersproject/abi": "5.7.0", + "@ethersproject/abstract-provider": "5.7.0", + "@ethersproject/contracts": "5.7.0", + "@ethersproject/providers": "5.7.2", + "@lit-protocol/accs-schemas": "^0.0.11", + "@lit-protocol/constants": "6.4.10", + "@lit-protocol/contracts": "^0.0.63", + "@lit-protocol/logger": "6.4.10", + "@lit-protocol/misc": "6.4.10", + "@lit-protocol/types": "6.4.10", + "ajv": "^8.12.0", + "bitcoinjs-lib": "^6.1.0", + "ethers": "^5.7.1", + "jose": "^4.14.4", + "jszip": "^3.10.1", + "process": "0.11.10", + "punycode": "2.3.1", + "siwe": "^2.0.5", + "tslib": "1.14.1", + "uint8arrays": "^4.0.3", + "util": "0.12.5" + } + }, + "node_modules/@lit-protocol/lit-node-client/node_modules/@lit-protocol/contracts-sdk/node_modules/tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" + }, "node_modules/@lit-protocol/lit-node-client/node_modules/@lit-protocol/crypto": { "version": "6.4.10", "resolved": "https://registry.npmjs.org/@lit-protocol/crypto/-/crypto-6.4.10.tgz", diff --git a/package.json b/package.json index 5a410ae..fd5c62e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/dkg-threshold/lit-protocol/v6.ts b/src/dkg-threshold/lit-protocol/v6.ts index f3a7cd4..38abdd6 100644 --- a/src/dkg-threshold/lit-protocol/v6.ts +++ b/src/dkg-threshold/lit-protocol/v6.ts @@ -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, @@ -35,7 +36,7 @@ export type CosmosAuthSignature = { }; export type CosmosAccessControlCondition = AccsCOSMOSParams & { conditionType: ConditionType; -} +}; export type CosmosReturnValueTest = CosmosAccessControlCondition['returnValueTest']; export type SaveEncryptionKeyArgs = { unifiedAccessControlConditions: CosmosAccessControlCondition[]; @@ -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; @@ -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 { - return await this.client.connect(); + await Promise.all([this.client.connect(), this.contractClient.connect()]); } async encrypt( secret: Uint8Array, unifiedAccessControlConditions: NonNullable ): Promise { - // 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({