Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build lit actions and update cids when building sdk #698

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions .nxignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages/wrapped-keys/update-ipfs-cids.js
4 changes: 4 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
}
},
"targetDefaults": {
"prebuild": {
"dependsOn": ["^prebuild"],
"inputs": ["production", "^production"]
},
"build": {
"dependsOn": ["^build"],
"inputs": ["production", "^production"]
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"express": "^4.18.2",
"form-data": "^4.0.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",
Expand Down
4 changes: 3 additions & 1 deletion packages/wrapped-keys-lit-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "6.11.0",
"main": "./dist/src/index.js",
Expand Down
8 changes: 4 additions & 4 deletions packages/wrapped-keys-lit-actions/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
FedericoAmura marked this conversation as resolved.
Show resolved Hide resolved
},
"build": {
"cache": false,
Expand All @@ -32,7 +32,7 @@
],
"updateBuildableProjectDepsInPackageJson": true
},
"dependsOn": ["build-la", "^build"]
"dependsOn": ["wrapped-keys:build"]
},
"lint": {
"executor": "@nx/linter:eslint",
Expand Down
4 changes: 4 additions & 0 deletions packages/wrapped-keys/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"buildOptions": {
"genReact": false
},
"scripts": {
"prepare": "yarn update-ipfs-cids",
"update-ipfs-cids": "yarn node ./update-ipfs-cids.js"
},
"version": "6.11.0",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
Expand Down
11 changes: 10 additions & 1 deletion packages/wrapped-keys/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}"],
Expand All @@ -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",
Expand Down
49 changes: 31 additions & 18 deletions packages/wrapped-keys/src/lib/lit-actions-client/constants.ts
Original file line number Diff line number Diff line change
@@ -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<T>(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 };
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"batchGenerateEncryptedKeys": "QmR8Zs7ctSEctxBrSnAYhMXFXCC1ub8K1xvMn5Js3NCSAA"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"signTransaction": {
"evm": "QmRpAgGKEmgeBRhqdC2EH17QUt6puwsbm8Z2nNneVN4uJG",
"solana": "QmR1nPG2tnmC72zuCEMZUZrrMEkbDiMPNHW45Dsm2n7xnk"
},
"signMessage": {
"evm": "QmXi9iqJvXrHoUGSo5WREonrruDhzQ7cFr7Cry3wX2hmue",
"solana": "QmcEJGVqRYtVukjm2prCPT7Fs66GpaqZwmZoxEHMHor6Jz"
},
"generateEncryptedKey": {
"evm": "QmeD6NYCWhUCLgxgpkgSguaKjwnpCnJ6Yf8SdsyPpK4eKK",
"solana": "QmPkVD3hEjMi1T5zQuvdrFCXaGTEMHNdAhAL4WHkqxijrQ"
},
"exportPrivateKey": {
"evm": "QmUJ74pTUqeeHzDGdfwCph1vJVNJ1rRzJdvMiTjS1BMwYj",
"solana": "QmUJ74pTUqeeHzDGdfwCph1vJVNJ1rRzJdvMiTjS1BMwYj"
}
}
3 changes: 2 additions & 1 deletion packages/wrapped-keys/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true
},
"files": [],
"include": [],
Expand Down
77 changes: 77 additions & 0 deletions packages/wrapped-keys/update-ipfs-cids.js
Original file line number Diff line number Diff line change
@@ -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!');
});
3 changes: 1 addition & 2 deletions tools/scripts/pub.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
redLog,
question,
writeJsonFile,
yellowLog,
} from './utils.mjs';

const args = getArgs();
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tools/scripts/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export const spawnCommand = (
if (options2.logExit) {
console.log(`child process exited with code ${code}`);
}
options2.exitCallback(code);
options2.exitCallback?.(code);
});
};

Expand Down
Loading
Loading