-
Notifications
You must be signed in to change notification settings - Fork 73
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/tinny standalone #722
Open
Ansonhkg
wants to merge
22
commits into
master
Choose a base branch
from
feat/tinny-standalone
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+610
−68
Open
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ac26418
feat: add package.json
Ansonhkg 48ee1e8
feat: add tinnytest package.json
Ansonhkg 24263e2
feat: tinny pkg works
Ansonhkg 8a0307c
Merge branch 'master' into feat/tinny-standalone
Ansonhkg 1f33367
chore: remove built files in local-tests directory
Ansonhkg 5148f01
chore: cleanup tinny build scripts
Ansonhkg 35d54f6
feat: add Ci to test & verify tinny build
Ansonhkg da2da73
fix: remove tinny build ci and override
Ansonhkg 5efd926
feat: duplicate the private keys if the length is only 1 cus it's gon…
Ansonhkg d40943e
fmt
Ansonhkg b976a41
feat: remove `BOOTSTRAP_URLS` as it's deprecated
Ansonhkg 4fdeddd
feat: export utils & add custom networkContext in TinnyEnv constructor
Ansonhkg 5a61adc
feat: include accs for tinny utils
Ansonhkg 5515e15
chore: remove ci tests
Ansonhkg 0453483
fmt
Ansonhkg 7cae5d8
feat: add back the CLI version of tinny to fix CI
Ansonhkg 7490d3f
fix: ci
Ansonhkg fbe39cc
chore: optimise build script
Ansonhkg ded0604
Merge branch 'master' into feat/tinny-standalone
Ansonhkg ccbf300
Merge branch 'master' into feat/tinny-standalone
Ansonhkg 86d8062
Merge branch 'master' into feat/tinny-standalone
Ansonhkg af92cd9
Merge branch 'master' into feat/tinny-standalone
Ansonhkg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
/out-tsc | ||
**/dist | ||
**/out-tsc | ||
local-tests/**/*.js | ||
|
||
# dependencies | ||
node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,66 @@ | ||
import * as esbuild from 'esbuild'; | ||
import { nodeExternalsPlugin } from 'esbuild-node-externals'; | ||
import fs from 'fs'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const TEST_DIR = 'local-tests'; | ||
const ALLOW_LIST = [ | ||
'ethers', | ||
'@lit-protocol/accs-schemas', | ||
'@lit-protocol/contracts', | ||
'crypto', | ||
'secp256k1', | ||
]; | ||
|
||
const getPath = (relativePath) => | ||
fileURLToPath(new URL(relativePath, import.meta.url)); | ||
|
||
/** | ||
* Builds the project using esbuild. | ||
* @returns {Promise<void>} A promise that resolves when the build is complete. | ||
* Common esbuild configuration options. | ||
* @param {string} entry - Entry file path. | ||
* @param {string} outfile - Output file path. | ||
* @param {string} [globalName] - Optional global name for the bundle. | ||
* @returns {esbuild.BuildOptions} Esbuild configuration object. | ||
*/ | ||
const createBuildConfig = (entry, outfile, globalName) => ({ | ||
entryPoints: [getPath(entry)], | ||
outfile: getPath(outfile), | ||
bundle: true, | ||
plugins: [ | ||
nodeExternalsPlugin({ | ||
allowList: ALLOW_LIST, | ||
}), | ||
], | ||
platform: 'node', | ||
target: 'esnext', | ||
format: 'esm', | ||
inject: [getPath('./shim.mjs')], | ||
mainFields: ['module', 'main'], | ||
...(globalName ? { globalName } : {}), | ||
}); | ||
|
||
/** | ||
* Builds the CLI-enabled version of Tinny. | ||
*/ | ||
export const build = async () => { | ||
await esbuild.build({ | ||
entryPoints: [`${TEST_DIR}/test.ts`], | ||
outfile: `./${TEST_DIR}/build/test.mjs`, | ||
bundle: true, | ||
plugins: [ | ||
nodeExternalsPlugin({ | ||
allowList: [ | ||
'ethers', | ||
'@lit-protocol/accs-schemas', | ||
'@lit-protocol/contracts', | ||
'crypto', | ||
'secp256k1', | ||
], | ||
}), | ||
], | ||
platform: 'node', | ||
target: 'esnext', | ||
format: 'esm', | ||
inject: [`./${TEST_DIR}/shim.mjs`], | ||
mainFields: ['module', 'main'], | ||
}); | ||
await esbuild.build(createBuildConfig('./test.ts', './build/test.mjs')); | ||
}; | ||
|
||
/** | ||
* Inserts a polyfill at the beginning of a file. | ||
* The polyfill ensures that the global `fetch` function is available. | ||
* @returns {void} | ||
* Bundles Tinny as a standalone package. | ||
*/ | ||
export const postBuildPolyfill = () => { | ||
try { | ||
const file = fs.readFileSync(`./${TEST_DIR}/build/test.mjs`, 'utf8'); | ||
const content = `import fetch from 'node-fetch'; | ||
try { | ||
if (!globalThis.fetch) { | ||
globalThis.fetch = fetch; | ||
} | ||
} catch (error) { | ||
console.error('❌ Error in polyfill', error); | ||
} | ||
`; | ||
const newFile = content + file; | ||
fs.writeFileSync(`./${TEST_DIR}/build/test.mjs`, newFile); | ||
} catch (e) { | ||
throw new Error(`Error in postBuildPolyfill: ${e}`); | ||
} | ||
export const bundle = async () => { | ||
await esbuild.build( | ||
createBuildConfig('./index.ts', './index.js', 'tinnySdk') | ||
); | ||
}; | ||
|
||
// Go! | ||
(async () => { | ||
const start = Date.now(); | ||
await build(); | ||
postBuildPolyfill(); | ||
console.log(`[build.mjs] 🚀 Build time: ${Date.now() - start}ms`); | ||
try { | ||
await build(); | ||
await bundle(); | ||
console.log(`[build.mjs] 🚀 Build time: ${Date.now() - start}ms`); | ||
} catch (error) { | ||
console.error(`[build.mjs] ❌ Build failed:`, error); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { TinnyEnvironment } from './setup/tinny-environment'; | ||
import { runInBand, runTestsParallel } from './setup/tinny-operations'; | ||
import * as tinnyTests from './tests'; | ||
import { getEoaSessionSigs } from './setup/session-sigs/get-eoa-session-sigs'; | ||
import { getLitActionSessionSigs } from './setup/session-sigs/get-lit-action-session-sigs'; | ||
import { getPkpSessionSigs } from './setup/session-sigs/get-pkp-session-sigs'; | ||
import { AccessControlConditions } from './setup/accs/accs'; | ||
|
||
export { | ||
TinnyEnvironment, | ||
runInBand, | ||
runTestsParallel, | ||
tinnyTests, | ||
getEoaSessionSigs, | ||
getLitActionSessionSigs, | ||
getPkpSessionSigs, | ||
AccessControlConditions, | ||
}; | ||
|
||
// Usage | ||
// const devEnv = new TinnyEnvironment(); | ||
|
||
// await devEnv.init(); | ||
|
||
// const testConfig = { | ||
// tests: { | ||
// testEthAuthSigToEncryptDecryptString, | ||
// }, | ||
// devEnv, | ||
// } | ||
|
||
// const res = await runTestsParallel(testConfig); | ||
// console.log("res:", res); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{ | ||
"name": "@lit-protocol/tinny", | ||
"version": "0.0.5", | ||
"description": "A package to run the test script for Lit Protocol with custom commands", | ||
"type": "module", | ||
"main": "./index.js", | ||
"typings": "./index.ts", | ||
"license": "MIT", | ||
"author": "Anson (https://github.com/ansonhkg)", | ||
"publishConfig": { | ||
"access": "public", | ||
"directory": "./" | ||
}, | ||
"dependencies": { | ||
"@cosmjs/amino": "0.30.1", | ||
"@cosmjs/crypto": "0.30.1", | ||
"@cosmjs/encoding": "0.30.1", | ||
"@cosmjs/proto-signing": "0.30.1", | ||
"@cosmjs/stargate": "0.30.1", | ||
"@cypress/code-coverage": "^3.10.0", | ||
"@cypress/react": "^6.2.0", | ||
"@cypress/webpack-dev-server": "^2.3.0", | ||
"@lit-protocol/accs-schemas": "0.0.7", | ||
"@metamask/eth-sig-util": "5.0.2", | ||
"@mysten/sui.js": "^0.37.1", | ||
"@playwright/test": "^1.25.2", | ||
"@simplewebauthn/browser": "^7.2.0", | ||
"@simplewebauthn/typescript-types": "^7.0.0", | ||
"@spruceid/siwe-parser": "2.0.0", | ||
"@synthetixio/js": "^2.41.0", | ||
"@testing-library/cypress": "^8.0.3", | ||
"@testing-library/react": "^13.4.0", | ||
"@types/testing-library__cypress": "^5.0.9", | ||
"@walletconnect/core": "2.9.2", | ||
"@walletconnect/ethereum-provider": "2.9.2", | ||
"@walletconnect/jsonrpc-utils": "1.0.8", | ||
"@walletconnect/modal": "2.6.1", | ||
"@walletconnect/types": "2.9.2", | ||
"@walletconnect/utils": "2.9.2", | ||
"@walletconnect/web3wallet": "1.8.8", | ||
"@websaam/nx-esbuild": "^0.0.1", | ||
"ajv": "^8.12.0", | ||
"axios": "^0.27.2", | ||
"base64url": "^3.0.1", | ||
"bitcoinjs-lib": "^6.1.0", | ||
"blockstore-core": "^3.0.0", | ||
"browserify-zlib": "^0.2.0", | ||
"bs58": "^5.0.0", | ||
"bytes32": "^0.0.3", | ||
"cbor-web": "^9.0.1", | ||
"commander": "^9.4.0", | ||
"concurrently": "^7.4.0", | ||
"core-js": "^3.6.5", | ||
"cross-fetch": "3.1.4", | ||
"crypto-browserify": "^3.12.0", | ||
"cypress-wait-until": "^1.7.2", | ||
"cypress-watch-and-reload": "^1.10.3", | ||
"date-and-time": "^2.4.1", | ||
"dotenv": "^16.0.2", | ||
"dotenv-parse-variables": "^2.0.0", | ||
"download": "^8.0.0", | ||
"ethers": "^5.7.1", | ||
"etherscan-api": "^10.2.0", | ||
"find-config": "^1.0.0", | ||
"g": "^2.0.1", | ||
"https-browserify": "^1.0.0", | ||
"jose": "^4.14.4", | ||
"jszip": "^3.10.1", | ||
"micromodal": "^0.4.10", | ||
"multiformats": "^9.7.1", | ||
"nanoid": "3.3.4", | ||
"next": "13.3.0", | ||
"react": "18.0.0", | ||
"react-dom": "18.0.0", | ||
"regenerator-runtime": "0.13.7", | ||
"secp256k1": "^5.0.0", | ||
"serve": "^14.0.1", | ||
"siwe": "^2.0.5", | ||
"siwe-recap": "0.0.2-alpha.0", | ||
"stream-browserify": "^3.0.0", | ||
"stream-http": "^3.2.0", | ||
"synthetix-js": "^2.74.1", | ||
"tslib": "^2.3.0", | ||
"tweetnacl": "^1.0.3", | ||
"tweetnacl-util": "^0.15.1", | ||
"uint8arrays": "^4.0.3", | ||
"@openagenda/verror": "^3.1.4", | ||
"ipfs-unixfs-importer": "12.0.1", | ||
"@solana/web3.js": "^1.95.3", | ||
"bech32": "^2.0.0", | ||
"pako": "^2.1.0", | ||
"@lit-protocol/misc": "^7.0.0", | ||
"@lit-protocol/lit-node-client": "^7.0.0", | ||
"@lit-protocol/lit-auth-client": "^7.0.0", | ||
"@lit-protocol/contracts": "^0.0.71" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will hide the error. We can add a
process.exit(1)
to notify caller