Skip to content

Commit 7c60ecf

Browse files
committed
feat: build lit actions and update cids when building sdk
1 parent e61b5ff commit 7c60ecf

File tree

8 files changed

+282
-8
lines changed

8 files changed

+282
-8
lines changed

.nxignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages/wrapped-keys/update-ipfs-cids.js

nx.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
}
1313
},
1414
"targetDefaults": {
15+
"prebuild": {
16+
"dependsOn": ["^prebuild"],
17+
"inputs": ["production", "^production"]
18+
},
1519
"build": {
1620
"dependsOn": ["^build"],
1721
"inputs": ["production", "^production"]

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
"express": "^4.18.2",
123123
"form-data": "^4.0.0",
124124
"inquirer": "^9.2.21",
125+
"ipfs-only-hash": "^4.0.0",
125126
"ipfs-unixfs-importer": "12.0.1",
126127
"jest": "27.5.1",
127128
"lerna": "^5.4.3",

packages/wrapped-keys-lit-actions/project.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
"sourceRoot": "packages/wrapped-keys-lit-actions/src",
55
"projectType": "library",
66
"targets": {
7-
"build-la": {
8-
"cache": false,
7+
"prebuild": {
98
"executor": "nx:run-commands",
109
"options": {
1110
"commands": [
1211
"yarn --cwd ./packages/wrapped-keys-lit-actions generate-lit-actions"
1312
],
1413
"cwd": "."
15-
}
14+
},
15+
"dependsOn": []
1616
},
1717
"build": {
1818
"cache": false,
@@ -32,7 +32,7 @@
3232
],
3333
"updateBuildableProjectDepsInPackageJson": true
3434
},
35-
"dependsOn": ["build-la", "^build"]
35+
"dependsOn": ["wrapped-keys:build"]
3636
},
3737
"lint": {
3838
"executor": "@nx/linter:eslint",

packages/wrapped-keys/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
"buildOptions": {
2424
"genReact": false
2525
},
26+
"scripts": {
27+
"update-ipfs-cids": "yarn node ./update-ipfs-cids.js"
28+
},
2629
"version": "6.10.0",
2730
"main": "./dist/src/index.js",
2831
"typings": "./dist/src/index.d.ts"

packages/wrapped-keys/project.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
"sourceRoot": "packages/wrapped-keys/src",
55
"projectType": "library",
66
"targets": {
7+
"prebuild": {
8+
"executor": "nx:run-commands",
9+
"options": {
10+
"commands": ["yarn --cwd ./packages/wrapped-keys update-ipfs-cids"],
11+
"cwd": "."
12+
},
13+
"dependsOn": ["wrapped-keys-lit-actions:prebuild"]
14+
},
715
"build": {
816
"executor": "@nx/js:tsc",
917
"outputs": ["{options.outputPath}"],
@@ -13,7 +21,8 @@
1321
"tsConfig": "packages/wrapped-keys/tsconfig.lib.json",
1422
"assets": ["packages/wrapped-keys/*.md"],
1523
"updateBuildableProjectDepsInPackageJson": true
16-
}
24+
},
25+
"dependsOn": ["prebuild", "^build"]
1726
},
1827
"lint": {
1928
"executor": "@nx/linter:eslint",
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const Hash = require('ipfs-only-hash');
5+
6+
const {
7+
code: batchGenerateEncryptedKey,
8+
} = require('../wrapped-keys-lit-actions/src/generated/common/batchGenerateEncryptedKeys');
9+
const {
10+
code: exportPrivateKey,
11+
} = require('../wrapped-keys-lit-actions/src/generated/common/exportPrivateKey');
12+
const {
13+
code: generateEncryptedEthereumPrivateKey,
14+
} = require('../wrapped-keys-lit-actions/src/generated/ethereum/generateEncryptedEthereumPrivateKey');
15+
const {
16+
code: signMessageWithEncryptedEthereumKey,
17+
} = require('../wrapped-keys-lit-actions/src/generated/ethereum/signMessageWithEncryptedEthereumKey');
18+
const {
19+
code: signTransactionWithEncryptedEthereumKey,
20+
} = require('../wrapped-keys-lit-actions/src/generated/ethereum/signTransactionWithEncryptedEthereumKey');
21+
const {
22+
code: generateEncryptedSolanaPrivateKey,
23+
} = require('../wrapped-keys-lit-actions/src/generated/solana/generateEncryptedSolanaPrivateKey');
24+
const {
25+
code: signMessageWithEncryptedSolanaKey,
26+
} = require('../wrapped-keys-lit-actions/src/generated/solana/signMessageWithEncryptedSolanaKey');
27+
const {
28+
code: signTransactionWithEncryptedSolanaKey,
29+
} = require('../wrapped-keys-lit-actions/src/generated/solana/signTransactionWithEncryptedSolanaKey');
30+
31+
async function updateConstants() {
32+
const constantsPath = path.join(
33+
__dirname,
34+
'./src/lib/lit-actions-client/constants.ts'
35+
);
36+
let constantsContent = fs.readFileSync(constantsPath, 'utf-8');
37+
38+
const newCIDs = {
39+
signTransaction: {
40+
evm: await Hash.of(signTransactionWithEncryptedEthereumKey),
41+
solana: await Hash.of(signTransactionWithEncryptedSolanaKey),
42+
},
43+
signMessage: {
44+
evm: await Hash.of(signMessageWithEncryptedEthereumKey),
45+
solana: await Hash.of(signMessageWithEncryptedSolanaKey),
46+
},
47+
generateEncryptedKey: {
48+
evm: await Hash.of(generateEncryptedEthereumPrivateKey),
49+
solana: await Hash.of(generateEncryptedSolanaPrivateKey),
50+
},
51+
exportPrivateKey: {
52+
evm: await Hash.of(exportPrivateKey),
53+
solana: await Hash.of(exportPrivateKey),
54+
},
55+
batchGenerateEncryptedKeys: await Hash.of(batchGenerateEncryptedKey),
56+
};
57+
58+
Object.entries(newCIDs).forEach(([key, value]) => {
59+
if (typeof value === 'object') {
60+
Object.entries(value).forEach(([subKey, cid]) => {
61+
const regex = new RegExp(
62+
`(${key}:\\s*Object\\.freeze\\(\\{[^}]*${subKey}:\\s*')([a-zA-Z0-9]+)(')`,
63+
'g'
64+
);
65+
constantsContent = constantsContent.replace(regex, `$1${cid}$3`);
66+
});
67+
} else {
68+
const regex = new RegExp(`(${key}:\\s*')([a-zA-Z0-9]+)(')`, 'g');
69+
constantsContent = constantsContent.replace(regex, `$1${value}$3`);
70+
}
71+
});
72+
73+
fs.writeFileSync(constantsPath, constantsContent, 'utf-8');
74+
}
75+
76+
updateConstants()
77+
.then(() => {
78+
console.log('Constants file updated successfully!');
79+
})
80+
.catch((err) => {
81+
console.error('Error updating constants:', err);
82+
});

0 commit comments

Comments
 (0)