Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 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,8 @@
"genReact": false
},
"scripts": {
"generate-lit-actions": "yarn node ./esbuild.config.js"
"generate-lit-actions": "yarn node ./esbuild.config.js",
"publish-lit-actions": "yarn node ./sync-actions-to-ipfs"
},
"version": "6.10.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": []
},
"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
3 changes: 3 additions & 0 deletions packages/wrapped-keys/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"buildOptions": {
"genReact": false
},
"scripts": {
"update-ipfs-cids": "yarn node ./update-ipfs-cids.js"
},
"version": "6.10.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
82 changes: 82 additions & 0 deletions packages/wrapped-keys/update-ipfs-cids.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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() {
const constantsPath = path.join(
__dirname,
'./src/lib/lit-actions-client/constants.ts'
);
let constantsContent = fs.readFileSync(constantsPath, 'utf-8');

const newCIDs = {
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),
},
batchGenerateEncryptedKeys: await Hash.of(batchGenerateEncryptedKey),
};

Object.entries(newCIDs).forEach(([key, value]) => {
if (typeof value === 'object') {
Object.entries(value).forEach(([subKey, cid]) => {
const regex = new RegExp(
`(${key}:\\s*Object\\.freeze\\(\\{[^}]*${subKey}:\\s*')([a-zA-Z0-9]+)(')`,
'g'
);
constantsContent = constantsContent.replace(regex, `$1${cid}$3`);
});
} else {
const regex = new RegExp(`(${key}:\\s*')([a-zA-Z0-9]+)(')`, 'g');
constantsContent = constantsContent.replace(regex, `$1${value}$3`);
}
});

fs.writeFileSync(constantsPath, constantsContent, 'utf-8');
}

updateConstants()
.then(() => {
console.log('Constants file updated successfully!');
})
.catch((err) => {
console.error('Error updating constants:', err);
});
18 changes: 16 additions & 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 @@ -101,8 +100,23 @@ await question('Are you sure you want to publish to? (y/n)', {
// await 1 second
await new Promise((resolve) => setTimeout(resolve, 1000));

// first publish the wrapped keys lit actions by running yarn publish-lit-actions in ./packages/wrapped-keys-lit-actions
await spawnCommand(
'dotenvx',
['run', '-f', '../../.env', '--', 'yarn', 'publish-lit-actions'],
{
cwd: './packages/wrapped-keys-lit-actions',
},
{
logExit: false,
}
);

let counter = 0;

// await 10 seconds to ipfs getting updated
await new Promise((resolve) => setTimeout(resolve, 10*1000));

await asyncForEach(dirs, async (dir) => {
// read the package.json file
const pkg = await readJsonFile(`${dir}/package.json`);
Expand Down Expand Up @@ -178,7 +192,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