From 7c60ecfc2cd82b29613019c1b27c23992654046d Mon Sep 17 00:00:00 2001 From: FedericoAmura Date: Wed, 16 Oct 2024 21:08:32 +0200 Subject: [PATCH 1/7] feat: build lit actions and update cids when building sdk --- .nxignore | 1 + nx.json | 4 + package.json | 1 + .../wrapped-keys-lit-actions/project.json | 8 +- packages/wrapped-keys/package.json | 3 + packages/wrapped-keys/project.json | 11 +- packages/wrapped-keys/update-ipfs-cids.js | 82 ++++++++ yarn.lock | 180 +++++++++++++++++- 8 files changed, 282 insertions(+), 8 deletions(-) create mode 100644 .nxignore create mode 100644 packages/wrapped-keys/update-ipfs-cids.js 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 5eb612672f..62d3a462dc 100644 --- a/package.json +++ b/package.json @@ -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", 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 ddcba2a6f6..96819b9652 100644 --- a/packages/wrapped-keys/package.json +++ b/packages/wrapped-keys/package.json @@ -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" 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/update-ipfs-cids.js b/packages/wrapped-keys/update-ipfs-cids.js new file mode 100644 index 0000000000..d6b7bedc06 --- /dev/null +++ b/packages/wrapped-keys/update-ipfs-cids.js @@ -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); + }); diff --git a/yarn.lock b/yarn.lock index bddb688a6d..b759a07a8f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3594,6 +3594,11 @@ "@motionone/dom" "^10.16.4" tslib "^2.3.1" +"@multiformats/base-x@^4.0.1": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@multiformats/base-x/-/base-x-4.0.1.tgz#95ff0fa58711789d53aefb2590a8b7a4e715d121" + integrity sha512-eMk0b9ReBbV23xXU693TAIrLyeO5iTgBZGSJfpqriG8UkYvr/hC9u9pyMlAakDNHWmbhMZCDs6KQO0jzKD8OTw== + "@multiformats/murmur3@^2.0.0": version "2.1.8" resolved "https://registry.yarnpkg.com/@multiformats/murmur3/-/murmur3-2.1.8.tgz#81c1c15b6391109f3febfca4b3205196615a04e9" @@ -9294,6 +9299,16 @@ cids@^0.7.1: multicodec "^1.0.0" multihashes "~0.4.15" +cids@^1.0.0, cids@^1.1.5, cids@^1.1.6: + version "1.1.9" + resolved "https://registry.yarnpkg.com/cids/-/cids-1.1.9.tgz#402c26db5c07059377bcd6fb82f2a24e7f2f4a4f" + integrity sha512-l11hWRfugIcbGuTZwAM5PwpjPPjyb6UZOGwlHSnOBV5o07XhQ4gNpBN67FbODvpjyHtd+0Xs6KNvUcGBiDRsdg== + dependencies: + multibase "^4.0.1" + multicodec "^3.0.1" + multihashes "^4.0.1" + uint8arrays "^3.0.0" + cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3: version "1.0.4" resolved "https://registry.yarnpkg.com/cipher-base/-/cipher-base-1.0.4.tgz#8760e4ecc272f4c363532f926d874aae2c1397de" @@ -11401,7 +11416,7 @@ err-code@^2.0.2: resolved "https://registry.yarnpkg.com/err-code/-/err-code-2.0.3.tgz#23c2f3b756ffdfc608d30e27c9a941024807e7f9" integrity sha512-2bmlRpNKBxT/CRmPOlyISQpNj+qSeYvcym/uT0Jx2bMOlKLtSy1ZmLuVxSEKKyor/N5yhvp/ZiG1oE3DEYMSFA== -err-code@^3.0.1: +err-code@^3.0.0, err-code@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/err-code/-/err-code-3.0.1.tgz#a444c7b992705f2b120ee320b09972eef331c920" integrity sha512-GiaH0KJUewYok+eeY05IIgjtAe4Yltygk9Wqp1V5yVWLdhf0hYZchRjNIT9bb0mSwRcIusT3cx7PJUf3zEIfUA== @@ -14114,6 +14129,14 @@ h3@^1.10.2, h3@^1.11.1: uncrypto "^0.1.3" unenv "^1.9.0" +hamt-sharding@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/hamt-sharding/-/hamt-sharding-2.0.1.tgz#f45686d0339e74b03b233bee1bde9587727129b6" + integrity sha512-vnjrmdXG9dDs1m/H4iJ6z0JFI2NtgsW5keRkTcM85NGak69Mkf5PHUqBz+Xs0T4sg0ppvj9O5EGAJo40FTxmmA== + dependencies: + sparse-array "^1.3.1" + uint8arrays "^3.0.0" + hamt-sharding@^3.0.0: version "3.0.6" resolved "https://registry.yarnpkg.com/hamt-sharding/-/hamt-sharding-3.0.6.tgz#3643107a3021af66ac95684aec87b196add5ba57" @@ -14879,6 +14902,15 @@ interface-blockstore@^4.0.0: interface-store "^3.0.0" multiformats "^11.0.0" +interface-ipld-format@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/interface-ipld-format/-/interface-ipld-format-1.0.1.tgz#bee39c70c584a033e186ff057a2be89f215963e3" + integrity sha512-WV/ar+KQJVoQpqRDYdo7YPGYIUHJxCuOEhdvsRpzLqoOIVCqPKdMMYmsLL1nCRsF3yYNio+PAJbCKiv6drrEAg== + dependencies: + cids "^1.1.6" + multicodec "^3.0.1" + multihashes "^4.0.2" + interface-store@^3.0.0: version "3.0.4" resolved "https://registry.yarnpkg.com/interface-store/-/interface-store-3.0.4.tgz#670d95ef45f3b7061d154c3cbfaf39a538167ad7" @@ -14939,6 +14971,14 @@ ipaddr.js@1.9.1: resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.9.1.tgz#bff38543eeb8984825079ff3a2a8e6cbd46781b3" integrity sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g== +ipfs-only-hash@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/ipfs-only-hash/-/ipfs-only-hash-4.0.0.tgz#b3bd60a244d9eb7394961aa9d812a2e5ac7c04d6" + integrity sha512-TE1DZCvfw8i3gcsTq3P4TFx3cKFJ3sluu/J3XINkJhIN9OwJgNMqKA+WnKx6ByCb1IoPXsTp1KM7tupElb6SyA== + dependencies: + ipfs-unixfs-importer "^7.0.1" + meow "^9.0.0" + ipfs-unixfs-importer@12.0.1: version "12.0.1" resolved "https://registry.yarnpkg.com/ipfs-unixfs-importer/-/ipfs-unixfs-importer-12.0.1.tgz#316a52d8a793e9e006b1ee43edc50b83e00ef306" @@ -14960,6 +15000,34 @@ ipfs-unixfs-importer@12.0.1: uint8arraylist "^2.3.3" uint8arrays "^4.0.2" +ipfs-unixfs-importer@^7.0.1: + version "7.0.3" + resolved "https://registry.yarnpkg.com/ipfs-unixfs-importer/-/ipfs-unixfs-importer-7.0.3.tgz#b850e831ca9647d589ef50bc33421f65bab7bba6" + integrity sha512-qeFOlD3AQtGzr90sr5Tq1Bi8pT5Nr2tSI8z310m7R4JDYgZc6J1PEZO3XZQ8l1kuGoqlAppBZuOYmPEqaHcVQQ== + dependencies: + bl "^5.0.0" + cids "^1.1.5" + err-code "^3.0.1" + hamt-sharding "^2.0.0" + ipfs-unixfs "^4.0.3" + ipld-dag-pb "^0.22.2" + it-all "^1.0.5" + it-batch "^1.0.8" + it-first "^1.0.6" + it-parallel-batch "^1.0.9" + merge-options "^3.0.4" + multihashing-async "^2.1.0" + rabin-wasm "^0.1.4" + uint8arrays "^2.1.2" + +ipfs-unixfs@^4.0.3: + version "4.0.3" + resolved "https://registry.yarnpkg.com/ipfs-unixfs/-/ipfs-unixfs-4.0.3.tgz#7c43e5726052ade4317245358ac541ef3d63d94e" + integrity sha512-hzJ3X4vlKT8FQ3Xc4M1szaFVjsc1ZydN+E4VQ91aXxfpjFn9G2wsMo1EFdAXNq/BUnN5dgqIOMP5zRYr3DTsAw== + dependencies: + err-code "^3.0.1" + protobufjs "^6.10.2" + ipfs-unixfs@^9.0.0: version "9.0.1" resolved "https://registry.yarnpkg.com/ipfs-unixfs/-/ipfs-unixfs-9.0.1.tgz#d06e688e07ef4ce08d610337ba2fe8c143c386e7" @@ -14968,6 +15036,19 @@ ipfs-unixfs@^9.0.0: err-code "^3.0.1" protobufjs "^7.0.0" +ipld-dag-pb@^0.22.2: + version "0.22.3" + resolved "https://registry.yarnpkg.com/ipld-dag-pb/-/ipld-dag-pb-0.22.3.tgz#6d5af28b5752236a5cb0e0a1888c87dd733b55cd" + integrity sha512-dfG5C5OVAR4FEP7Al2CrHWvAyIM7UhAQrjnOYOIxXGQz5NlEj6wGX0XQf6Ru6or1na6upvV3NQfstapQG8X2rg== + dependencies: + cids "^1.0.0" + interface-ipld-format "^1.0.0" + multicodec "^3.0.1" + multihashing-async "^2.0.0" + protobufjs "^6.10.2" + stable "^0.1.8" + uint8arrays "^2.0.5" + iron-webcrypto@^1.1.1: version "1.2.1" resolved "https://registry.yarnpkg.com/iron-webcrypto/-/iron-webcrypto-1.2.1.tgz#aa60ff2aa10550630f4c0b11fd2442becdb35a6f" @@ -15668,21 +15749,43 @@ isurl@^1.0.0-alpha5: has-to-string-tag-x "^1.2.0" is-object "^1.0.1" +it-all@^1.0.5: + version "1.0.6" + resolved "https://registry.yarnpkg.com/it-all/-/it-all-1.0.6.tgz#852557355367606295c4c3b7eff0136f07749335" + integrity sha512-3cmCc6Heqe3uWi3CVM/k51fa/XbMFpQVzFoDsV0IZNHSQDyAXl3c4MjHkFX5kF3922OGj7Myv1nSEUgRtcuM1A== + it-all@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/it-all/-/it-all-2.0.1.tgz#45d530ecf6e13fb81d7ba583cdfd55ffdb376b05" integrity sha512-9UuJcCRZsboz+HBQTNOau80Dw+ryGaHYFP/cPYzFBJBFcfDathMYnhHk4t52en9+fcyDGPTdLB+lFc1wzQIroA== +it-batch@^1.0.8, it-batch@^1.0.9: + version "1.0.9" + resolved "https://registry.yarnpkg.com/it-batch/-/it-batch-1.0.9.tgz#7e95aaacb3f9b1b8ca6c8b8367892171d6a5b37f" + integrity sha512-7Q7HXewMhNFltTsAMdSz6luNhyhkhEtGGbYek/8Xb/GiqYMtwUmopE1ocPSiJKKp3rM4Dt045sNFoUu+KZGNyA== + it-batch@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/it-batch/-/it-batch-2.0.1.tgz#a0822be9b18743c41d8525835f788a7f297ba41f" integrity sha512-2gWFuPzamh9Dh3pW+OKjc7UwJ41W4Eu2AinVAfXDMfrC5gXfm3b1TF+1UzsygBUgKBugnxnGP+/fFRyn+9y1mQ== +it-first@^1.0.6: + version "1.0.7" + resolved "https://registry.yarnpkg.com/it-first/-/it-first-1.0.7.tgz#a4bef40da8be21667f7d23e44dae652f5ccd7ab1" + integrity sha512-nvJKZoBpZD/6Rtde6FXqwDqDZGF1sCADmr2Zoc0hZsIvnE449gRFnGctxDf09Bzc/FWnHXAdaHVIetY6lrE0/g== + it-first@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/it-first/-/it-first-2.0.1.tgz#75d66b254c385ae3a1906def060a69006a437cef" integrity sha512-noC1oEQcWZZMUwq7VWxHNLML43dM+5bviZpfmkxkXlvBe60z7AFRqpZSga9uQBo792jKv9otnn1IjA4zwgNARw== +it-parallel-batch@^1.0.9: + version "1.0.11" + resolved "https://registry.yarnpkg.com/it-parallel-batch/-/it-parallel-batch-1.0.11.tgz#f889b4e1c7a62ef24111dbafbaaa010b33d00f69" + integrity sha512-UWsWHv/kqBpMRmyZJzlmZeoAMA0F3SZr08FBdbhtbe+MtoEBgr/ZUAKrnenhXCBrsopy76QjRH2K/V8kNdupbQ== + dependencies: + it-batch "^1.0.9" + it-parallel-batch@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/it-parallel-batch/-/it-parallel-batch-2.0.1.tgz#23eb07bbeb73521253d7c8a1566b53137103077c" @@ -17817,6 +17920,24 @@ meow@^8.0.0: type-fest "^0.18.0" yargs-parser "^20.2.3" +meow@^9.0.0: + version "9.0.0" + resolved "https://registry.yarnpkg.com/meow/-/meow-9.0.0.tgz#cd9510bc5cac9dee7d03c73ee1f9ad959f4ea364" + integrity sha512-+obSblOQmRhcyBt62furQqRAQpNyWXo8BuQ5bN7dG8wmwQ+vwHKp/rCFD4CrTP8CsDQD1sjoZ94K417XEUk8IQ== + dependencies: + "@types/minimist" "^1.2.0" + camelcase-keys "^6.2.2" + decamelize "^1.2.0" + decamelize-keys "^1.1.0" + hard-rejection "^2.1.0" + minimist-options "4.1.0" + normalize-package-data "^3.0.0" + read-pkg-up "^7.0.1" + redent "^3.0.0" + trim-newlines "^3.0.0" + type-fest "^0.18.0" + yargs-parser "^20.2.3" + merge-descriptors@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61" @@ -18300,6 +18421,13 @@ multibase@^0.7.0: base-x "^3.0.8" buffer "^5.5.0" +multibase@^4.0.1: + version "4.0.6" + resolved "https://registry.yarnpkg.com/multibase/-/multibase-4.0.6.tgz#6e624341483d6123ca1ede956208cb821b440559" + integrity sha512-x23pDe5+svdLz/k5JPGCVdfn7Q5mZVMBETiC+ORfO+sor9Sgs0smJzAjfTbM5tckeCqnaUuMYoz+k3RXMmJClQ== + dependencies: + "@multiformats/base-x" "^4.0.1" + multibase@~0.6.0: version "0.6.1" resolved "https://registry.yarnpkg.com/multibase/-/multibase-0.6.1.tgz#b76df6298536cc17b9f6a6db53ec88f85f8cc12b" @@ -18323,6 +18451,14 @@ multicodec@^1.0.0: buffer "^5.6.0" varint "^5.0.0" +multicodec@^3.0.1: + version "3.2.1" + resolved "https://registry.yarnpkg.com/multicodec/-/multicodec-3.2.1.tgz#82de3254a0fb163a107c1aab324f2a91ef51efb2" + integrity sha512-+expTPftro8VAW8kfvcuNNNBgb9gPeNYV9dn+z1kJRWF2vih+/S79f2RVeIwmrJBUJ6NT9IUPWnZDQvegEh5pw== + dependencies: + uint8arrays "^3.0.0" + varint "^6.0.0" + multiformats@^11.0.0, multiformats@^11.0.2: version "11.0.2" resolved "https://registry.yarnpkg.com/multiformats/-/multiformats-11.0.2.tgz#b14735efc42cd8581e73895e66bebb9752151b60" @@ -18352,6 +18488,27 @@ multihashes@^0.4.15, multihashes@~0.4.15: multibase "^0.7.0" varint "^5.0.0" +multihashes@^4.0.1, multihashes@^4.0.2: + version "4.0.3" + resolved "https://registry.yarnpkg.com/multihashes/-/multihashes-4.0.3.tgz#426610539cd2551edbf533adeac4c06b3b90fb05" + integrity sha512-0AhMH7Iu95XjDLxIeuCOOE4t9+vQZsACyKZ9Fxw2pcsRmlX4iCn1mby0hS0bb+nQOVpdQYWPpnyusw4da5RPhA== + dependencies: + multibase "^4.0.1" + uint8arrays "^3.0.0" + varint "^5.0.2" + +multihashing-async@^2.0.0, multihashing-async@^2.1.0: + version "2.1.4" + resolved "https://registry.yarnpkg.com/multihashing-async/-/multihashing-async-2.1.4.tgz#26dce2ec7a40f0e7f9e732fc23ca5f564d693843" + integrity sha512-sB1MiQXPSBTNRVSJc2zM157PXgDtud2nMFUEIvBrsq5Wv96sUclMRK/ecjoP1T/W61UJBqt4tCTwMkUpt2Gbzg== + dependencies: + blakejs "^1.1.0" + err-code "^3.0.0" + js-sha3 "^0.8.0" + multihashes "^4.0.1" + murmurhash3js-revisited "^3.0.0" + uint8arrays "^3.0.0" + multimatch@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/multimatch/-/multimatch-5.0.0.tgz#932b800963cea7a31a033328fa1e0c3a1874dbe6" @@ -20360,7 +20517,7 @@ proto-list@~1.2.1: resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849" integrity sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA== -protobufjs@^6.8.8, protobufjs@~6.11.2, protobufjs@~6.11.3: +protobufjs@^6.10.2, protobufjs@^6.8.8, protobufjs@~6.11.2, protobufjs@~6.11.3: version "6.11.4" resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.11.4.tgz#29a412c38bf70d89e537b6d02d904a6f448173aa" integrity sha512-5kQWPaJHi1WoCpjTGszzQ32PG2F4+wRY6BmAT4Vfw56Q2FZ4YZzK20xUYQH4YkfehY1e6QSICrJquM6xXZNcrw== @@ -22281,6 +22438,11 @@ ssri@^9.0.0, ssri@^9.0.1: dependencies: minipass "^3.1.1" +stable@^0.1.8: + version "0.1.8" + resolved "https://registry.yarnpkg.com/stable/-/stable-0.1.8.tgz#836eb3c8382fe2936feaf544631017ce7d47a3cf" + integrity sha512-ji9qxRnOVfcuLDySj9qzhGSEFVobyt1kIOSkj1qZzYLzq7Tos/oUUWvotUPQLlrsidqsK6tBH89Bc9kL5zHA6w== + stack-trace@0.0.x: version "0.0.10" resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0" @@ -23570,6 +23732,13 @@ uint8arrays@3.1.0: dependencies: multiformats "^9.4.2" +uint8arrays@^2.0.5, uint8arrays@^2.1.2: + version "2.1.10" + resolved "https://registry.yarnpkg.com/uint8arrays/-/uint8arrays-2.1.10.tgz#34d023c843a327c676e48576295ca373c56e286a" + integrity sha512-Q9/hhJa2836nQfEJSZTmr+pg9+cDJS9XEAp7N2Vg5MzL3bK/mkMVfjscRGYruP9jNda6MAdf4QD/y78gSzkp6A== + dependencies: + multiformats "^9.4.2" + uint8arrays@^3.0.0, uint8arrays@^3.1.0: version "3.1.1" resolved "https://registry.yarnpkg.com/uint8arrays/-/uint8arrays-3.1.1.tgz#2d8762acce159ccd9936057572dade9459f65ae0" @@ -24083,11 +24252,16 @@ valtio@1.11.0: proxy-compare "2.5.1" use-sync-external-store "1.2.0" -varint@^5.0.0: +varint@^5.0.0, varint@^5.0.2: version "5.0.2" resolved "https://registry.yarnpkg.com/varint/-/varint-5.0.2.tgz#5b47f8a947eb668b848e034dcfa87d0ff8a7f7a4" integrity sha512-lKxKYG6H03yCZUpAGOPOsMcGxd1RHCu1iKvEHYDPmTyq2HueGhD73ssNBqqQWfvYs04G9iUFRvmAVLW20Jw6ow== +varint@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/varint/-/varint-6.0.0.tgz#9881eb0ce8feaea6512439d19ddf84bf551661d0" + integrity sha512-cXEIW6cfr15lFv563k4GuVuW/fiwjknytD37jIOLSdSWuOI6WnO/oKwmP2FQTU2l01LP8/M5TSAJpzUaGe3uWg== + varuint-bitcoin@^1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/varuint-bitcoin/-/varuint-bitcoin-1.1.2.tgz#e76c138249d06138b480d4c5b40ef53693e24e92" From b37e08f29516390235e6f55f505e4aeacd0f9af9 Mon Sep 17 00:00:00 2001 From: FedericoAmura Date: Thu, 17 Oct 2024 16:50:46 +0200 Subject: [PATCH 2/7] feat: publish lit actions code to ipfs automatically before publishing packages to npm --- packages/wrapped-keys-lit-actions/package.json | 3 ++- tools/scripts/pub.mjs | 18 ++++++++++++++++-- tools/scripts/utils.mjs | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/wrapped-keys-lit-actions/package.json b/packages/wrapped-keys-lit-actions/package.json index 768c8050c3..595c306456 100644 --- a/packages/wrapped-keys-lit-actions/package.json +++ b/packages/wrapped-keys-lit-actions/package.json @@ -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", diff --git a/tools/scripts/pub.mjs b/tools/scripts/pub.mjs index 5e79271a8e..42baf03a3b 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(); @@ -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`); @@ -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); 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); }); }; From c3ed484f5005de92f9f72651e9c45cb32c0f6bd1 Mon Sep 17 00:00:00 2001 From: FedericoAmura Date: Wed, 23 Oct 2024 17:18:44 +0200 Subject: [PATCH 3/7] fix: remove catch swallowing error on LA CID constants update script --- packages/wrapped-keys/update-ipfs-cids.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/packages/wrapped-keys/update-ipfs-cids.js b/packages/wrapped-keys/update-ipfs-cids.js index d6b7bedc06..405e681c16 100644 --- a/packages/wrapped-keys/update-ipfs-cids.js +++ b/packages/wrapped-keys/update-ipfs-cids.js @@ -70,13 +70,6 @@ async function updateConstants() { } }); - fs.writeFileSync(constantsPath, constantsContent, 'utf-8'); -} - -updateConstants() - .then(() => { - console.log('Constants file updated successfully!'); - }) - .catch((err) => { - console.error('Error updating constants:', err); - }); +updateConstants().then(() => { + console.log('Constants file updated successfully!'); +}); From 8750d1d1fb6d737f73aef7c44e7ec9ca30c2477f Mon Sep 17 00:00:00 2001 From: FedericoAmura Date: Wed, 23 Oct 2024 17:19:49 +0200 Subject: [PATCH 4/7] feat: update CID generation script and storage to use independent json files we can handle more easily --- .../src/lib/lit-actions-client/constants.ts | 49 ++++++++++++------- .../lit-action-cid-repository-common.json | 3 ++ .../lit-action-cid-repository.json | 18 +++++++ packages/wrapped-keys/tsconfig.json | 3 +- packages/wrapped-keys/update-ipfs-cids.js | 43 ++++++++-------- 5 files changed, 76 insertions(+), 40 deletions(-) create mode 100644 packages/wrapped-keys/src/lib/lit-actions-client/lit-action-cid-repository-common.json create mode 100644 packages/wrapped-keys/src/lib/lit-actions-client/lit-action-cid-repository.json 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..098b97e331 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..5735a34866 --- /dev/null +++ b/packages/wrapped-keys/src/lib/lit-actions-client/lit-action-cid-repository-common.json @@ -0,0 +1,3 @@ +{ + "batchGenerateEncryptedKeys": "QmR8Zs7ctSEctxBrSnAYhMXFXCC1ub8K1xvMn5Js3NCSAA" +} \ No newline at end of file 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..c1ad5e4447 --- /dev/null +++ b/packages/wrapped-keys/src/lib/lit-actions-client/lit-action-cid-repository.json @@ -0,0 +1,18 @@ +{ + "signTransaction": { + "evm": "QmRpAgGKEmgeBRhqdC2EH17QUt6puwsbm8Z2nNneVN4uJG", + "solana": "QmR1nPG2tnmC72zuCEMZUZrrMEkbDiMPNHW45Dsm2n7xnk" + }, + "signMessage": { + "evm": "QmXi9iqJvXrHoUGSo5WREonrruDhzQ7cFr7Cry3wX2hmue", + "solana": "QmcEJGVqRYtVukjm2prCPT7Fs66GpaqZwmZoxEHMHor6Jz" + }, + "generateEncryptedKey": { + "evm": "QmeD6NYCWhUCLgxgpkgSguaKjwnpCnJ6Yf8SdsyPpK4eKK", + "solana": "QmPkVD3hEjMi1T5zQuvdrFCXaGTEMHNdAhAL4WHkqxijrQ" + }, + "exportPrivateKey": { + "evm": "QmUJ74pTUqeeHzDGdfwCph1vJVNJ1rRzJdvMiTjS1BMwYj", + "solana": "QmUJ74pTUqeeHzDGdfwCph1vJVNJ1rRzJdvMiTjS1BMwYj" + } +} \ No newline at end of file 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 index 405e681c16..687f73db06 100644 --- a/packages/wrapped-keys/update-ipfs-cids.js +++ b/packages/wrapped-keys/update-ipfs-cids.js @@ -29,13 +29,8 @@ const { } = 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 = { + // Generate new CID hashes + const litActionCIDRepository = { signTransaction: { evm: await Hash.of(signTransactionWithEncryptedEthereumKey), solana: await Hash.of(signTransactionWithEncryptedSolanaKey), @@ -52,23 +47,29 @@ async function updateConstants() { evm: await Hash.of(exportPrivateKey), solana: await Hash.of(exportPrivateKey), }, + }; + const litActionCIDRepositoryCommon = { 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`); - } - }); + // Write constant json files with lit action hashes + fs.writeFileSync( + path.join( + __dirname, + './src/lib/lit-actions-client/lit-action-cid-repository.json' + ), + JSON.stringify(litActionCIDRepository, null, 2), + 'utf-8' + ); + fs.writeFileSync( + path.join( + __dirname, + './src/lib/lit-actions-client/lit-action-cid-repository-common.json' + ), + JSON.stringify(litActionCIDRepositoryCommon, null, 2), + 'utf-8' + ); +} updateConstants().then(() => { console.log('Constants file updated successfully!'); From 61ef9fdd216179afaeb0a67bfc981d5200b08a09 Mon Sep 17 00:00:00 2001 From: FedericoAmura Date: Wed, 23 Oct 2024 17:21:39 +0200 Subject: [PATCH 5/7] feat: make WKLA update and publish the LAs automatically on prepublishOnly and LA update its CIDs based on WKLAs code on install and publish --- packages/wrapped-keys/package.json | 1 + tools/scripts/pub.mjs | 15 --------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/packages/wrapped-keys/package.json b/packages/wrapped-keys/package.json index 96819b9652..93449c4b2b 100644 --- a/packages/wrapped-keys/package.json +++ b/packages/wrapped-keys/package.json @@ -24,6 +24,7 @@ "genReact": false }, "scripts": { + "prepare": "yarn update-ipfs-cids", "update-ipfs-cids": "yarn node ./update-ipfs-cids.js" }, "version": "6.10.0", diff --git a/tools/scripts/pub.mjs b/tools/scripts/pub.mjs index 42baf03a3b..dfc5c242b8 100644 --- a/tools/scripts/pub.mjs +++ b/tools/scripts/pub.mjs @@ -100,23 +100,8 @@ 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`); From 01e8dc4f25381f001f5ae3f03f57e8d9dbeeb8fc Mon Sep 17 00:00:00 2001 From: FedericoAmura Date: Wed, 23 Oct 2024 17:23:21 +0200 Subject: [PATCH 6/7] feat: npm script missed on previous commit --- packages/wrapped-keys-lit-actions/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/wrapped-keys-lit-actions/package.json b/packages/wrapped-keys-lit-actions/package.json index e86f7c580f..78e3bf79f5 100644 --- a/packages/wrapped-keys-lit-actions/package.json +++ b/packages/wrapped-keys-lit-actions/package.json @@ -24,6 +24,7 @@ "genReact": false }, "scripts": { + "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" }, From 4e97c6e33dfb3ba4b6627802b04706332043c8c7 Mon Sep 17 00:00:00 2001 From: FedericoAmura Date: Wed, 23 Oct 2024 17:43:53 +0200 Subject: [PATCH 7/7] fix: prettier validation on json files --- .../lit-actions-client/lit-action-cid-repository-common.json | 2 +- .../lib/lit-actions-client/lit-action-cid-repository.json | 2 +- packages/wrapped-keys/update-ipfs-cids.js | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) 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 index 5735a34866..144b8793e3 100644 --- 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 @@ -1,3 +1,3 @@ { "batchGenerateEncryptedKeys": "QmR8Zs7ctSEctxBrSnAYhMXFXCC1ub8K1xvMn5Js3NCSAA" -} \ No newline at end of file +} 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 index c1ad5e4447..947bad46e5 100644 --- 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 @@ -15,4 +15,4 @@ "evm": "QmUJ74pTUqeeHzDGdfwCph1vJVNJ1rRzJdvMiTjS1BMwYj", "solana": "QmUJ74pTUqeeHzDGdfwCph1vJVNJ1rRzJdvMiTjS1BMwYj" } -} \ No newline at end of file +} diff --git a/packages/wrapped-keys/update-ipfs-cids.js b/packages/wrapped-keys/update-ipfs-cids.js index 687f73db06..3f5b8d5583 100644 --- a/packages/wrapped-keys/update-ipfs-cids.js +++ b/packages/wrapped-keys/update-ipfs-cids.js @@ -53,12 +53,13 @@ async function updateConstants() { }; // 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), + JSON.stringify(litActionCIDRepository, null, 2) + '\n', 'utf-8' ); fs.writeFileSync( @@ -66,7 +67,7 @@ async function updateConstants() { __dirname, './src/lib/lit-actions-client/lit-action-cid-repository-common.json' ), - JSON.stringify(litActionCIDRepositoryCommon, null, 2), + JSON.stringify(litActionCIDRepositoryCommon, null, 2) + '\n', 'utf-8' ); }