diff --git a/.nxignore b/.nxignore new file mode 100644 index 0000000000..7848200e91 --- /dev/null +++ b/.nxignore @@ -0,0 +1 @@ +packages/wrapped-keys/update-ipfs-cids.js diff --git a/nx.json b/nx.json index d51223447f..b5912ae3a3 100644 --- a/nx.json +++ b/nx.json @@ -12,6 +12,10 @@ } }, "targetDefaults": { + "prebuild": { + "dependsOn": ["^prebuild"], + "inputs": ["production", "^production"] + }, "build": { "dependsOn": ["^build"], "inputs": ["production", "^production"] diff --git a/package.json b/package.json index 18fa024f2d..7a3778b3f5 100644 --- a/package.json +++ b/package.json @@ -111,6 +111,7 @@ "eslint-plugin-import": "^2.29.1", "eslint-plugin-jsx-a11y": "6.9.0", "inquirer": "^9.2.21", + "ipfs-only-hash": "^4.0.0", "ipfs-unixfs-importer": "12.0.1", "jest": "27.5.1", "lerna": "^5.4.3", diff --git a/packages/wrapped-keys-lit-actions/package.json b/packages/wrapped-keys-lit-actions/package.json index a9776eb0a6..f42632cc65 100644 --- a/packages/wrapped-keys-lit-actions/package.json +++ b/packages/wrapped-keys-lit-actions/package.json @@ -24,7 +24,9 @@ "genReact": false }, "scripts": { - "generate-lit-actions": "yarn node ./esbuild.config.js" + "prepublishOnly": "yarn generate-lit-actions && yarn publish-lit-actions", + "generate-lit-actions": "yarn node ./esbuild.config.js", + "publish-lit-actions": "yarn node ./sync-actions-to-ipfs" }, "version": "7.1.0", "main": "./dist/src/index.js", diff --git a/packages/wrapped-keys-lit-actions/project.json b/packages/wrapped-keys-lit-actions/project.json index 6be195f3c2..bd6c5552c0 100644 --- a/packages/wrapped-keys-lit-actions/project.json +++ b/packages/wrapped-keys-lit-actions/project.json @@ -4,15 +4,15 @@ "sourceRoot": "packages/wrapped-keys-lit-actions/src", "projectType": "library", "targets": { - "build-la": { - "cache": false, + "prebuild": { "executor": "nx:run-commands", "options": { "commands": [ "yarn --cwd ./packages/wrapped-keys-lit-actions generate-lit-actions" ], "cwd": "." - } + }, + "dependsOn": [] }, "build": { "cache": false, @@ -32,7 +32,7 @@ ], "updateBuildableProjectDepsInPackageJson": true }, - "dependsOn": ["build-la", "^build"] + "dependsOn": ["wrapped-keys:build"] }, "lint": { "executor": "@nx/linter:eslint", diff --git a/packages/wrapped-keys/package.json b/packages/wrapped-keys/package.json index 6be4c243ed..962d15d537 100644 --- a/packages/wrapped-keys/package.json +++ b/packages/wrapped-keys/package.json @@ -23,6 +23,10 @@ "buildOptions": { "genReact": false }, + "scripts": { + "prepare": "yarn update-ipfs-cids", + "update-ipfs-cids": "yarn node ./update-ipfs-cids.js" + }, "version": "7.1.0", "main": "./dist/src/index.js", "typings": "./dist/src/index.d.ts" diff --git a/packages/wrapped-keys/project.json b/packages/wrapped-keys/project.json index e2e9a2caeb..91acd91242 100644 --- a/packages/wrapped-keys/project.json +++ b/packages/wrapped-keys/project.json @@ -4,6 +4,14 @@ "sourceRoot": "packages/wrapped-keys/src", "projectType": "library", "targets": { + "prebuild": { + "executor": "nx:run-commands", + "options": { + "commands": ["yarn --cwd ./packages/wrapped-keys update-ipfs-cids"], + "cwd": "." + }, + "dependsOn": ["wrapped-keys-lit-actions:prebuild"] + }, "build": { "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], @@ -13,7 +21,8 @@ "tsConfig": "packages/wrapped-keys/tsconfig.lib.json", "assets": ["packages/wrapped-keys/*.md"], "updateBuildableProjectDepsInPackageJson": true - } + }, + "dependsOn": ["prebuild", "^build"] }, "lint": { "executor": "@nx/linter:eslint", diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/constants.ts b/packages/wrapped-keys/src/lib/lit-actions-client/constants.ts index 83360f84fc..999191cd8a 100644 --- a/packages/wrapped-keys/src/lib/lit-actions-client/constants.ts +++ b/packages/wrapped-keys/src/lib/lit-actions-client/constants.ts @@ -1,26 +1,39 @@ +import * as GENERATED_LIT_ACTION_CID_REPOSITORY_COMMON from './lit-action-cid-repository-common.json'; +import * as GENERATED_LIT_ACTION_CID_REPOSITORY from './lit-action-cid-repository.json'; import { LitCidRepository, LitCidRepositoryCommon } from './types'; -const LIT_ACTION_CID_REPOSITORY: LitCidRepository = Object.freeze({ - signTransaction: Object.freeze({ - evm: 'QmRpAgGKEmgeBRhqdC2EH17QUt6puwsbm8Z2nNneVN4uJG', - solana: 'QmR1nPG2tnmC72zuCEMZUZrrMEkbDiMPNHW45Dsm2n7xnk', - }), - signMessage: Object.freeze({ - evm: 'QmXi9iqJvXrHoUGSo5WREonrruDhzQ7cFr7Cry3wX2hmue', - solana: 'QmcEJGVqRYtVukjm2prCPT7Fs66GpaqZwmZoxEHMHor6Jz', - }), - generateEncryptedKey: Object.freeze({ - evm: 'QmeD6NYCWhUCLgxgpkgSguaKjwnpCnJ6Yf8SdsyPpK4eKK', - solana: 'QmPkVD3hEjMi1T5zQuvdrFCXaGTEMHNdAhAL4WHkqxijrQ', - }), - exportPrivateKey: Object.freeze({ - evm: 'QmUJ74pTUqeeHzDGdfwCph1vJVNJ1rRzJdvMiTjS1BMwYj', - solana: 'QmUJ74pTUqeeHzDGdfwCph1vJVNJ1rRzJdvMiTjS1BMwYj', - }), +function deepFreeze>(obj: T): T { + Object.freeze(obj); + for (const key in obj) { + if (key in obj && typeof obj[key] === 'object') { + deepFreeze(obj[key]); + } + } + return obj; +} + +const LIT_ACTION_CID_REPOSITORY: LitCidRepository = deepFreeze({ + signTransaction: { + evm: GENERATED_LIT_ACTION_CID_REPOSITORY.signTransaction.evm, + solana: GENERATED_LIT_ACTION_CID_REPOSITORY.signTransaction.solana, + }, + signMessage: { + evm: GENERATED_LIT_ACTION_CID_REPOSITORY.signMessage.evm, + solana: GENERATED_LIT_ACTION_CID_REPOSITORY.signMessage.solana, + }, + generateEncryptedKey: { + evm: GENERATED_LIT_ACTION_CID_REPOSITORY.generateEncryptedKey.evm, + solana: GENERATED_LIT_ACTION_CID_REPOSITORY.generateEncryptedKey.solana, + }, + exportPrivateKey: { + evm: GENERATED_LIT_ACTION_CID_REPOSITORY.exportPrivateKey.evm, + solana: GENERATED_LIT_ACTION_CID_REPOSITORY.exportPrivateKey.solana, + }, }); const LIT_ACTION_CID_REPOSITORY_COMMON: LitCidRepositoryCommon = Object.freeze({ - batchGenerateEncryptedKeys: 'QmR8Zs7ctSEctxBrSnAYhMXFXCC1ub8K1xvMn5Js3NCSAA', + batchGenerateEncryptedKeys: + GENERATED_LIT_ACTION_CID_REPOSITORY_COMMON.batchGenerateEncryptedKeys, }); export { LIT_ACTION_CID_REPOSITORY, LIT_ACTION_CID_REPOSITORY_COMMON }; diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/lit-action-cid-repository-common.json b/packages/wrapped-keys/src/lib/lit-actions-client/lit-action-cid-repository-common.json new file mode 100644 index 0000000000..20b87f3ddc --- /dev/null +++ b/packages/wrapped-keys/src/lib/lit-actions-client/lit-action-cid-repository-common.json @@ -0,0 +1,3 @@ +{ + "batchGenerateEncryptedKeys": "QmQB1uSKwuzUWHiAgaGtTf3rFZf42AJWN1XKJSNNPuxKhB" +} diff --git a/packages/wrapped-keys/src/lib/lit-actions-client/lit-action-cid-repository.json b/packages/wrapped-keys/src/lib/lit-actions-client/lit-action-cid-repository.json new file mode 100644 index 0000000000..f1ae0aa6a6 --- /dev/null +++ b/packages/wrapped-keys/src/lib/lit-actions-client/lit-action-cid-repository.json @@ -0,0 +1,18 @@ +{ + "signTransaction": { + "evm": "QmYTEJyniRRkTxe3D9mmkURXCFBAXWK7TEGk5LxvWSETWn", + "solana": "QmWUozjthkrjEBGkkEvGTvCaxCaiPMTke6FUpiwhn28k8Z" + }, + "signMessage": { + "evm": "Qmdm4mGn6A8RmqeiDgRPXFt2yYEKCUMUVimSb5iPJfs31e", + "solana": "QmS4Y6f2zHriNzioxBbysbuXQbjX7ga468CCyYcuY2AeeH" + }, + "generateEncryptedKey": { + "evm": "QmfW6g5PJ8SVS56XwDVC5W4gcUnobEempNkR28bj2g99tk", + "solana": "QmWYcBCZqFmJJzsRfzVRHbPD5Hvuou45sbXPQcQzLbUgKd" + }, + "exportPrivateKey": { + "evm": "QmfZ8hYEmNFwHraNieSz25dAp65YBoNjAMC2tXm9oaQCt6", + "solana": "QmfZ8hYEmNFwHraNieSz25dAp65YBoNjAMC2tXm9oaQCt6" + } +} diff --git a/packages/wrapped-keys/tsconfig.json b/packages/wrapped-keys/tsconfig.json index f5b85657a8..ab0659018e 100644 --- a/packages/wrapped-keys/tsconfig.json +++ b/packages/wrapped-keys/tsconfig.json @@ -7,7 +7,8 @@ "noImplicitOverride": true, "noPropertyAccessFromIndexSignature": true, "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true + "noFallthroughCasesInSwitch": true, + "esModuleInterop": true }, "files": [], "include": [], diff --git a/packages/wrapped-keys/update-ipfs-cids.js b/packages/wrapped-keys/update-ipfs-cids.js new file mode 100644 index 0000000000..3f5b8d5583 --- /dev/null +++ b/packages/wrapped-keys/update-ipfs-cids.js @@ -0,0 +1,77 @@ +const fs = require('fs'); +const path = require('path'); + +const Hash = require('ipfs-only-hash'); + +const { + code: batchGenerateEncryptedKey, +} = require('../wrapped-keys-lit-actions/src/generated/common/batchGenerateEncryptedKeys'); +const { + code: exportPrivateKey, +} = require('../wrapped-keys-lit-actions/src/generated/common/exportPrivateKey'); +const { + code: generateEncryptedEthereumPrivateKey, +} = require('../wrapped-keys-lit-actions/src/generated/ethereum/generateEncryptedEthereumPrivateKey'); +const { + code: signMessageWithEncryptedEthereumKey, +} = require('../wrapped-keys-lit-actions/src/generated/ethereum/signMessageWithEncryptedEthereumKey'); +const { + code: signTransactionWithEncryptedEthereumKey, +} = require('../wrapped-keys-lit-actions/src/generated/ethereum/signTransactionWithEncryptedEthereumKey'); +const { + code: generateEncryptedSolanaPrivateKey, +} = require('../wrapped-keys-lit-actions/src/generated/solana/generateEncryptedSolanaPrivateKey'); +const { + code: signMessageWithEncryptedSolanaKey, +} = require('../wrapped-keys-lit-actions/src/generated/solana/signMessageWithEncryptedSolanaKey'); +const { + code: signTransactionWithEncryptedSolanaKey, +} = require('../wrapped-keys-lit-actions/src/generated/solana/signTransactionWithEncryptedSolanaKey'); + +async function updateConstants() { + // Generate new CID hashes + const litActionCIDRepository = { + signTransaction: { + evm: await Hash.of(signTransactionWithEncryptedEthereumKey), + solana: await Hash.of(signTransactionWithEncryptedSolanaKey), + }, + signMessage: { + evm: await Hash.of(signMessageWithEncryptedEthereumKey), + solana: await Hash.of(signMessageWithEncryptedSolanaKey), + }, + generateEncryptedKey: { + evm: await Hash.of(generateEncryptedEthereumPrivateKey), + solana: await Hash.of(generateEncryptedSolanaPrivateKey), + }, + exportPrivateKey: { + evm: await Hash.of(exportPrivateKey), + solana: await Hash.of(exportPrivateKey), + }, + }; + const litActionCIDRepositoryCommon = { + batchGenerateEncryptedKeys: await Hash.of(batchGenerateEncryptedKey), + }; + + // Write constant json files with lit action hashes + // Extra \n is for prettier rule + fs.writeFileSync( + path.join( + __dirname, + './src/lib/lit-actions-client/lit-action-cid-repository.json' + ), + JSON.stringify(litActionCIDRepository, null, 2) + '\n', + 'utf-8' + ); + fs.writeFileSync( + path.join( + __dirname, + './src/lib/lit-actions-client/lit-action-cid-repository-common.json' + ), + JSON.stringify(litActionCIDRepositoryCommon, null, 2) + '\n', + 'utf-8' + ); +} + +updateConstants().then(() => { + console.log('Constants file updated successfully!'); +}); diff --git a/tools/scripts/pub.mjs b/tools/scripts/pub.mjs index 5e79271a8e..dfc5c242b8 100644 --- a/tools/scripts/pub.mjs +++ b/tools/scripts/pub.mjs @@ -12,7 +12,6 @@ import { redLog, question, writeJsonFile, - yellowLog, } from './utils.mjs'; const args = getArgs(); @@ -178,7 +177,7 @@ await question('Are you sure you want to publish to? (y/n)', { }); while (true) { - // wait for 1 second + // wait a few secs to check again if all packages are published await new Promise((resolve) => setTimeout(resolve, 2000)); if (counter >= dirs.length) { greenLog('🎉 Publish complete!', true); diff --git a/tools/scripts/utils.mjs b/tools/scripts/utils.mjs index ab301ba8b6..5ebe87b9b1 100644 --- a/tools/scripts/utils.mjs +++ b/tools/scripts/utils.mjs @@ -185,7 +185,7 @@ export const spawnCommand = ( if (options2.logExit) { console.log(`child process exited with code ${code}`); } - options2.exitCallback(code); + options2.exitCallback?.(code); }); };