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

Feature/lit 3125 sdk for wrapping up walletx 2 #487

Merged
merged 160 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
eff258b
feat(wrapped-keys): new package
Ansonhkg May 31, 2024
17f09a3
feat(test): add wrappedKey test template
Ansonhkg May 31, 2024
4436632
feat(wrapped-keys): add business logic
Ansonhkg May 31, 2024
b8a4283
feat(wrapped-keys): create interface for helper functions
Ansonhkg May 31, 2024
ae1339e
test: Wrapped keys utils
DashKash54 Jun 2, 2024
d008760
fix: Import key function
DashKash54 Jun 2, 2024
05ffdd1
feat: Generate new Solana private key as writing to the DB with the s…
DashKash54 Jun 2, 2024
a61e954
test: Failure tests for importing keys
DashKash54 Jun 2, 2024
d6df03d
test: Remaining import keys test
DashKash54 Jun 3, 2024
72be60c
feat: Add export key function
DashKash54 Jun 3, 2024
0585adc
test: Export keys
DashKash54 Jun 3, 2024
0a60643
fix: PKP Address match tests
DashKash54 Jun 3, 2024
4d493f5
feat: Proper error handling for signWithEncryptedKey & new param for …
DashKash54 Jun 3, 2024
8f0f710
fix: Sign transaction
DashKash54 Jun 4, 2024
fb33533
test: Failure tests for Signing Eth Wrapped Keys
DashKash54 Jun 4, 2024
d773c88
fix: Compute nonce inside Lit Action before signing
DashKash54 Jun 4, 2024
137d00a
feat: Add broadcast to Eth Signing Lit Action
DashKash54 Jun 4, 2024
c28e25b
feat(tinny): add `getFunds` function for tinny environment
Ansonhkg Jun 4, 2024
030c4f1
feat: Yarn build
DashKash54 Jun 6, 2024
7b5150c
Merge branch 'master' into feature/lit-3125-sdk-for-wrapping-up-walle…
DashKash54 Jun 6, 2024
c35ac80
feat: Yarn build
DashKash54 Jun 6, 2024
4920eab
Published version: 6.0.1@wrapped-keys
DashKash54 Jun 6, 2024
7065269
text: Fix broadcasting tx insufficient balance error
DashKash54 Jun 7, 2024
57f363e
fix: EVM signing Lit Action for Wrapped Keys
DashKash54 Jun 7, 2024
cd00901
Published version: 6.0.1@wrapped-keys
DashKash54 Jun 7, 2024
5e82abd
fix: EVM signing Lit Action only one node should broadcast
DashKash54 Jun 7, 2024
72fc629
Published version: 6.0.1@wrapped-keys
DashKash54 Jun 7, 2024
597e106
WIP
spacesailor24 Jun 7, 2024
3e49141
Update LA to fetch gasPrice and gas estimate. Init test
spacesailor24 Jun 7, 2024
94925f2
Fix bugs
spacesailor24 Jun 7, 2024
81c2237
Add gasLimit for Chronicle
spacesailor24 Jun 7, 2024
5a5317d
Debugging
spacesailor24 Jun 7, 2024
eca4744
Rename test file
spacesailor24 Jun 7, 2024
3f657a0
feat: Add prefix to private key to prevent leaking secrets for ED2551…
DashKash54 Jun 10, 2024
ec9d42d
feat: Use decryptToSingleNode in the signing Lit Action
DashKash54 Jun 11, 2024
dce75a3
feat: Catch error for timing out while broadcasting
DashKash54 Jun 11, 2024
b50f352
refac: Prettier & Build
DashKash54 Jun 11, 2024
f120052
Published version: 6.0.1@wrapped-keys
DashKash54 Jun 11, 2024
db26a05
refac: Separate signing message & tx functions
DashKash54 Jun 11, 2024
87ba2a9
refac: Extract fetching private key from database function
DashKash54 Jun 11, 2024
b5ecded
refac: Prettier
DashKash54 Jun 11, 2024
ada1ff3
feat: Add sign message function
DashKash54 Jun 11, 2024
67abb1a
refac: Rename tests
DashKash54 Jun 11, 2024
5a59aed
WIP
spacesailor24 Jun 11, 2024
a840ca1
Merge branch 'feature/lit-3125-sdk-for-wrapping-up-walletx-2' into wy…
spacesailor24 Jun 11, 2024
d2cd7c5
Undo LA rename
spacesailor24 Jun 11, 2024
edb7619
test: EVM Sign message
DashKash54 Jun 11, 2024
09736ba
refac: Prettier
DashKash54 Jun 11, 2024
d857535
Debugging dist file path resolution
spacesailor24 Jun 11, 2024
87f2f69
Merge branch 'feature/lit-3125-sdk-for-wrapping-up-walletx-2' into wy…
spacesailor24 Jun 11, 2024
70072f4
Published version: 6.0.1@wrapped-keys
DashKash54 Jun 11, 2024
8d26c2a
refac: Prettier
DashKash54 Jun 11, 2024
7dfc72f
feat: Generate private key inside Lit Action
DashKash54 Jun 11, 2024
01cd550
test: Generate key inside Lit Action
DashKash54 Jun 12, 2024
9b44746
refac: Prettier
DashKash54 Jun 12, 2024
cb0b79a
error: Data encrypted inside LA can be decrypted only inside it
DashKash54 Jun 12, 2024
2f61299
refac: Abstract storing to database
DashKash54 Jun 12, 2024
b0a9d94
refac: Prettier
DashKash54 Jun 12, 2024
bfd7440
test: Signing with Generated keys
DashKash54 Jun 13, 2024
4036b12
feat: Remove wait inside tx sign Lit Action
DashKash54 Jun 13, 2024
897abf8
Published version: 6.0.1@wrapped-keys
DashKash54 Jun 13, 2024
62e773d
Merge branch 'master' into feature/lit-3125-sdk-for-wrapping-up-walle…
DashKash54 Jun 13, 2024
fde703b
Published version: 6.0.2@wrapped-keys
DashKash54 Jun 13, 2024
62e95ea
feat: Update Readme
DashKash54 Jun 13, 2024
cdb4049
Update LA code to have syntax highlighting
spacesailor24 Jun 13, 2024
95dca48
Update test cmd statuses
spacesailor24 Jun 13, 2024
de8c6d9
Solve merge conflicts
spacesailor24 Jun 13, 2024
b5650a0
Merge branch 'feature/lit-3125-sdk-for-wrapping-up-walletx-2' into wy…
spacesailor24 Jun 13, 2024
0a81eb4
Rename test and add hexlify for gasPrice and gasLimit
spacesailor24 Jun 13, 2024
f3c373f
Add from to tx within LA before signing
spacesailor24 Jun 14, 2024
e9c58c8
Remove runOnce from gasPrice and gasLimit. Small refactors
spacesailor24 Jun 14, 2024
9770e85
Convert other functions
spacesailor24 Jun 14, 2024
64a5930
Remove bundled solana LAs
spacesailor24 Jun 14, 2024
b277753
Replace Solana LA with IPFS CIDs
spacesailor24 Jun 14, 2024
4ecd120
Merge branch 'feature/lit-3125-sdk-for-wrapping-up-walletx-2' into wy…
spacesailor24 Jun 14, 2024
4fdf8a3
WIP
spacesailor24 Jun 14, 2024
7ec6dc3
Fix LA and test for sign message
spacesailor24 Jun 14, 2024
edb781c
Init test sign tx. Update LA
spacesailor24 Jun 14, 2024
33a848f
Remove extra line from gitignore
spacesailor24 Jun 14, 2024
dbb9631
Remove extra file
spacesailor24 Jun 14, 2024
68d0c91
Undo rename of litActions file
spacesailor24 Jun 14, 2024
46579e1
Undo changes to wrapped-keys.ts
spacesailor24 Jun 14, 2024
84f344b
Rename Ethereum LA file
spacesailor24 Jun 14, 2024
3051354
Update packages/wrapped-keys/src/lib/litActions/solana/src/signMessag…
spacesailor24 Jun 15, 2024
31c8735
Update packages/wrapped-keys/src/lib/litActions/solana/src/signTransa…
spacesailor24 Jun 15, 2024
c20ef71
Update packages/wrapped-keys/src/lib/litActions/solana/src/signMessag…
spacesailor24 Jun 15, 2024
ca469da
Update packages/wrapped-keys/src/lib/litActions/solana/src/signTransa…
spacesailor24 Jun 15, 2024
80b2ebb
Update packages/wrapped-keys/src/lib/litActions/solana/src/signMessag…
spacesailor24 Jun 15, 2024
d60fba9
Ran prettier
spacesailor24 Jun 15, 2024
25d303f
Merge branch 'wyatt/add-solana-actions' of github.com:LIT-Protocol/js…
spacesailor24 Jun 15, 2024
23d8298
Add **/*/dist to prettierignore
spacesailor24 Jun 15, 2024
c538a1e
Use getEoaSessionSigs helper
spacesailor24 Jun 15, 2024
3f2be78
feat: Autogen on yarn build
DashKash54 Jun 16, 2024
58d3b7b
feat: Additional error handling for Lit Action opcodes
DashKash54 Jun 16, 2024
d542ef5
test: Decryption fails in Lit Action due to mismatch owner
DashKash54 Jun 16, 2024
ed2fdd4
Merge pull request #501 from LIT-Protocol/wyatt/fetch-gas-price-la
DashKash54 Jun 16, 2024
c17ec9f
feat: Support multiple innerAuthSigs for payment
DashKash54 Jun 17, 2024
cbb4582
refac: Remove dead tests
DashKash54 Jun 17, 2024
8911912
refac: Prettier
DashKash54 Jun 17, 2024
97dbc40
feat: Accept ipfsCid param for signMessage
DashKash54 Jun 19, 2024
d490657
feat: Update Solana tx signing to accept serialized tx string + new S…
DashKash54 Jun 19, 2024
501f229
Merge branch 'feature/lit-3125-sdk-for-wrapping-up-walletx-2' into wy…
DashKash54 Jun 19, 2024
486a0e4
Merge pull request #504 from LIT-Protocol/wyatt/add-solana-actions
DashKash54 Jun 19, 2024
e0d2647
Merge branch 'master' into feature/lit-3125-sdk-for-wrapping-up-walle…
DashKash54 Jun 19, 2024
836ab93
feat: Move ipfsCids to consts
DashKash54 Jun 19, 2024
53bb1c2
feat: Separate Eth Lit Actions into individual files for bundling
DashKash54 Jun 19, 2024
6b4def1
feat: Use ipfsId instead of string code for Eth Wrapped keys
DashKash54 Jun 19, 2024
4138df4
tests: Fix minor test bugs
DashKash54 Jun 19, 2024
625375c
refac: Remove logs from Wrapped Keys Lit Actions
DashKash54 Jun 19, 2024
6cb31d0
feat: Add function to generate encrypted Solana key
DashKash54 Jun 19, 2024
de897eb
Published version: 6.0.3@wrapped-keys
DashKash54 Jun 19, 2024
712a55e
fix: Remove post install script since it wasn't found while installin…
DashKash54 Jun 20, 2024
7d9c64a
Published version: 6.0.3@wrapped-keys
DashKash54 Jun 20, 2024
7b676f7
docs: Add JsDocs for Wrapped Keys functions & utilities
DashKash54 Jun 21, 2024
b80cee7
chore(test): organise tests order
Ansonhkg Jun 21, 2024
238b917
docs: JsDocs for Lit Actions
DashKash54 Jun 25, 2024
d3599a5
feat: Generate Wrapped Keys with Custom Lit Action
DashKash54 Jun 25, 2024
62e9aa4
test: Custom generate Wrapped Keys
DashKash54 Jun 25, 2024
9aa3faf
test: Fail Custom Wrapped Keys
DashKash54 Jun 25, 2024
0987047
feat: Custom signed message Wrapped Keys
DashKash54 Jun 25, 2024
9544af0
feat: Support Custom transaction signing Wrapped Keys
DashKash54 Jun 25, 2024
8bbd2be
feat: Add additional param for custom Wrapped Keys fields
DashKash54 Jun 25, 2024
d046b5e
refac: Prettier
DashKash54 Jun 25, 2024
ac70021
Published version: 6.0.3@wrapped-keys
DashKash54 Jun 25, 2024
21cfaf3
chore(types): LIT-3125 - Run eslint --fix on types.ts
MaximusHaximus Jun 25, 2024
d6c1a7b
types: LIT-3125 - Fix incorrect interface for SessionKeySignedMessage…
MaximusHaximus Jun 25, 2024
549cd84
feat(wrapped-keys): LIT-3125 - Add wrapped keys backend service clien…
MaximusHaximus Jun 25, 2024
46faa91
feat(wrapped-keys): LIT-3125 - Add wrapped keys LIT actions client layer
MaximusHaximus Jun 25, 2024
b05917a
feat(wrapped-keys): LIT-3125 - Constants, types and tests updates
MaximusHaximus Jun 25, 2024
ad58e5a
chore(wrapped-keys): LIT-3125 - Add note to LIT action about missing …
MaximusHaximus Jun 26, 2024
cba8d1d
chore(wrapped-keys): LIT-3125 - Add return type interface for export …
MaximusHaximus Jun 26, 2024
e3d2055
feat(wrapped-keys): LIT-3125 - Implement main API layer for wrapped keys
MaximusHaximus Jun 26, 2024
5b5abb1
chore(wrapped-keys): LIT-3125 - Update entrypoint exports to be expli…
MaximusHaximus Jun 26, 2024
d1e49f8
types(types): LIT-3125 - Revert change to AccessControlConditions typ…
MaximusHaximus Jun 26, 2024
5af0435
constants(wrapped-keys): LIT-3125 - Remove NETWORK_XXXX constants as …
MaximusHaximus Jun 26, 2024
5d89170
test(wrapped-keys): LIT-3125 - Update success tests to latest wrapped…
MaximusHaximus Jun 26, 2024
b66af98
test(wrapped-keys): LIT-3125 - Update fail tests
MaximusHaximus Jun 26, 2024
d8d17ce
chore(wrapped-keys): LIT-3125 - Rename `algo` to `keyType` to avoid c…
MaximusHaximus Jun 26, 2024
9eb0f47
chore(wrapped-keys): LIT-3125 - Remove 'custom' API behaviours and ty…
MaximusHaximus Jun 26, 2024
900ede1
chore(wrapped-keys): LIT-3125 - Remove 'custom' tests
MaximusHaximus Jun 26, 2024
e9d771e
docs(wrapped-keys): LIT-3125 - Update exports for JSDocs
MaximusHaximus Jun 26, 2024
8cff023
feat(wrapped-keys): LIT-3125 - Add storeEncryptedKeyMetadata() method…
MaximusHaximus Jun 26, 2024
241fa97
feat(wrapped-keys): LIT-3125 - Replace `address` with `publicKey`
MaximusHaximus Jun 26, 2024
c3166a5
test(wrapped-keys): LIT-3125 - Update tests to use `publicKey` instea…
MaximusHaximus Jun 26, 2024
ac8f173
chore(wrapped-keys): LIT-3125 - Make internal service client params i…
MaximusHaximus Jun 26, 2024
b48efc9
fix(wrapped-keys): LIT-3125 - Remove inadvertent imports from `index.…
MaximusHaximus Jun 27, 2024
8140964
Published version: 6.0.3@wrapped-keys
DashKash54 Jun 28, 2024
878c4fa
fix(wrapped-keys): LIT-3125 - Remove FIXME :)
MaximusHaximus Jun 28, 2024
acb10f2
test(wrapped-keys): LIT-3125 - Fix actually-failing-fail test string …
MaximusHaximus Jun 28, 2024
c3dafd0
fix(wrapped-keys): LIT-3125 - Add strong type for `KeyType`, and comp…
MaximusHaximus Jun 28, 2024
cbdc556
chore(wrapped-keys): LIT-3125 - Remove commented code and excess `con…
MaximusHaximus Jun 28, 2024
0be70bb
docs(wrapped-keys): LIT-3125 - Fix JSDoc for `StoreEncryptedKeyMetada…
MaximusHaximus Jun 28, 2024
6b72634
docs(wrapped-keys): LIT-3125 - Export constants for `keyType` and `ne…
MaximusHaximus Jun 28, 2024
3a7c943
refac: Prettier
DashKash54 Jun 29, 2024
4be606e
Merge pull request #513 from LIT-Protocol/wrapped-keys-multinetwork-a…
DashKash54 Jun 29, 2024
a1aab92
feat: Update sign Solana msg Ipfs Cid
DashKash54 Jul 1, 2024
3142a72
Published version: 6.0.3@wrapped-keys
DashKash54 Jul 1, 2024
ec92c77
refac: Prettier
DashKash54 Jul 1, 2024
ffe870b
feat: Freeze top-level ipfs repository
DashKash54 Jul 1, 2024
7af4f67
test(wrapped-keys): LIT-3125 - Fix nested object being merged into te…
MaximusHaximus Jul 1, 2024
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
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
/tmp
/packages/*/dist
.nx
tools
tools
**/*/dist
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ If you're a tech-savvy user and wish to utilize only specific submodules that ou
| [@lit-protocol/sev-snp-utils-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/sev-snp-utils-sdk) | ![sev-snp-utils-sdk](https://img.shields.io/badge/-universal-8A6496 'sev-snp-utils-sdk') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/sev-snp-utils-sdk"><img src="https://img.shields.io/npm/v/@lit-protocol/sev-snp-utils-sdk"/></a> |
| [@lit-protocol/types](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/types) | ![types](https://img.shields.io/badge/-universal-8A6496 'types') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/types"><img src="https://img.shields.io/npm/v/@lit-protocol/types"/></a> |
| [@lit-protocol/uint8arrays](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/uint8arrays) | ![uint8arrays](https://img.shields.io/badge/-universal-8A6496 'uint8arrays') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/uint8arrays"><img src="https://img.shields.io/npm/v/@lit-protocol/uint8arrays"/></a> |
| [@lit-protocol/wrapped-keys](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/wrapped-keys) | ![wrapped-keys](https://img.shields.io/badge/-universal-8A6496 'wrapped-keys') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/wrapped-keys"><img src="https://img.shields.io/npm/v/@lit-protocol/wrapped-keys"/></a> |
| [@lit-protocol/auth-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-browser) | ![auth-browser](https://img.shields.io/badge/-browser-E98869 'auth-browser') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/auth-browser"><img src="https://img.shields.io/npm/v/@lit-protocol/auth-browser"/></a> |
| [@lit-protocol/misc-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc-browser) | ![misc-browser](https://img.shields.io/badge/-browser-E98869 'misc-browser') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/misc-browser"><img src="https://img.shields.io/npm/v/@lit-protocol/misc-browser"/></a> |

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useNx": true,
"useWorkspaces": true,
"version": "6.0.3"
"version": "6.0.3-wrapped-keys.beta.5"
}
4 changes: 3 additions & 1 deletion local-tests/setup/session-sigs/get-pkp-session-sigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { TinnyPerson } from '../tinny-person';
export const getPkpSessionSigs = async (
devEnv: TinnyEnvironment,
alice: TinnyPerson,
resourceAbilityRequests?: LitResourceAbilityRequest[]
resourceAbilityRequests?: LitResourceAbilityRequest[],
expiration?: string
DashKash54 marked this conversation as resolved.
Show resolved Hide resolved
) => {
if (devEnv.litNodeClient.config.litNetwork === LitNetwork.Manzano) {
console.warn(
Expand All @@ -31,6 +32,7 @@ export const getPkpSessionSigs = async (
const pkpSessionSigs = await devEnv.litNodeClient.getPkpSessionSigs({
pkpPublicKey: alice.authMethodOwnedPkp.publicKey,
authMethods: [alice.authMethod],
expiration,
resourceAbilityRequests: _resourceAbilityRequests,

// -- only add this for manzano network
Expand Down
23 changes: 23 additions & 0 deletions local-tests/setup/tinny-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,29 @@ export class TinnyEnvironment {
}
//============= END SHIVA ENDPOINTS =============

/**
* Sends funds from the current wallet to the specified wallet address.
* @param walletAddress - The address of the recipient wallet.
* @param amount - The amount of funds to send (default: '0.001').
* @throws If there is an error sending the funds.
*/
getFunds = async (walletAddress: string, amount = '0.001') => {
try {
const privateKey = await this.getAvailablePrivateKey();
const provider = new ethers.providers.JsonRpcBatchProvider(this.rpc);
const wallet = new ethers.Wallet(privateKey.privateKey, provider);

const tx = await wallet.sendTransaction({
to: walletAddress,
value: ethers.utils.parseEther(amount),
});

await tx.wait();
} catch (e) {
throw new Error(`Failed to send funds to ${walletAddress}: ${e}`);
}
};

/**
* Context: the reason this is created instead of individually is because we can't allocate capacity beyond the global
* max capacity.
Expand Down
14 changes: 14 additions & 0 deletions local-tests/setup/tinny-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,17 @@ export async function stringToIpfsHash(input: string): Promise<string> {

return ipfsHash;
}

export function randomSolanaPrivateKey() {
const BASE58_ALPHABET =
'123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
const SOLANA_PRIVATE_KEY_LENGTH = 88;

let result = '';
const charactersLength = BASE58_ALPHABET.length;
for (let i = 0; i < SOLANA_PRIVATE_KEY_LENGTH; i++) {
const randomIndex = Math.floor(Math.random() * charactersLength);
result += BASE58_ALPHABET.charAt(randomIndex);
}
return result;
}
63 changes: 63 additions & 0 deletions local-tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,73 @@ import { testExecuteJsSignAndCombineEcdsa } from './tests/testExecuteJsSignAndCo
import { testExecutJsDecryptAndCombine } from './tests/testExecuteJsDecryptAndCombine';
import { testExecuteJsBroadcastAndCollect } from './tests/testExecuteJsBroadcastAndCollect';

import { testEthereumSignMessageGeneratedKey } from './tests/testEthereumSignMessageGeneratedKey';
import { testEthereumBroadcastTransactionGeneratedKey } from './tests/testEthereumBroadcastTransactionGeneratedKey';
import { testEthereumSignMessageWrappedKey } from './tests/testEthereumSignMessageWrappedKey';
import { testFailEthereumSignTransactionWrappedKeyInvalidDecryption } from './tests/testFailEthereumSignTransactionWrappedKeyInvalidDecryption';
import { testEthereumSignTransactionWrappedKey } from './tests/testEthereumSignTransactionWrappedKey';
import { testFailEthereumSignTransactionWrappedKeyWithInvalidParam } from './tests/testFailEthereumSignTransactionWrappedKeyWithInvalidParam';
import { testFailEthereumSignTransactionWrappedKeyWithMissingParam } from './tests/testFailEthereumSignTransactionWrappedKeyWithMissingParam';
import { testEthereumBroadcastTransactionWrappedKey } from './tests/testEthereumBroadcastTransactionWrappedKey';
import { testEthereumBroadcastWrappedKeyWithFetchGasParams } from './tests/testEthereumBroadcastWrappedKeyWithFetchGasParams';
import { testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds } from './tests/testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds';
import { testImportWrappedKey } from './tests/testImportWrappedKey';
import { testGenerateEthereumWrappedKey } from './tests/testGenerateEthereumWrappedKey';
import { testGenerateSolanaWrappedKey } from './tests/testGenerateSolanaWrappedKey';
import { testFailImportWrappedKeysWithSamePkp } from './tests/testFailImportWrappedKeysWithSamePkp';
import { testFailImportWrappedKeysWithSamePrivateKey } from './tests/testFailImportWrappedKeysWithSamePrivateKey';
import { testFailImportWrappedKeysWithEoaSessionSig } from './tests/testFailImportWrappedKeysWithEoaSessionSig';
import { testFailImportWrappedKeysWithMaxExpirySessionSig } from './tests/testFailImportWrappedKeysWithMaxExpirySessionSig';
import { testFailImportWrappedKeysWithInvalidSessionSig } from './tests/testFailImportWrappedKeysWithInvalidSessionSig';
import { testFailImportWrappedKeysWithExpiredSessionSig } from './tests/testFailImportWrappedKeysWithExpiredSessionSig';
import { testExportWrappedKey } from './tests/testExportWrappedKey';
import { testSignMessageWithSolanaEncryptedKey } from './tests/testSignMessageWithSolanaEncryptedKey';
import { testSignTransactionWithSolanaEncryptedKey } from './tests/testSignTransactionWithSolanaEncryptedKey';

(async () => {
console.log('[𐬺🧪 Tinny𐬺] Running tests...');
const devEnv = new TinnyEnvironment();

await devEnv.init();

const wrappedKeysTests = {
// -- valid cases
testEthereumSignMessageGeneratedKey,
testEthereumBroadcastTransactionGeneratedKey,
testEthereumSignMessageWrappedKey,
testEthereumSignTransactionWrappedKey,
testEthereumBroadcastTransactionWrappedKey,
testEthereumBroadcastWrappedKeyWithFetchGasParams,

// -- generate wrapped keys
testGenerateEthereumWrappedKey,
testGenerateSolanaWrappedKey,

// -- import wrapped keys
testImportWrappedKey,

// -- export wrapped keys
testExportWrappedKey,

// -- solana wrapped keys
testSignMessageWithSolanaEncryptedKey,
testSignTransactionWithSolanaEncryptedKey,

// -- invalid cases
testFailEthereumSignTransactionWrappedKeyWithMissingParam,
testFailEthereumSignTransactionWrappedKeyWithInvalidParam,
testFailEthereumSignTransactionWrappedKeyInvalidDecryption,
testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds,

// -- import wrapped keys
testFailImportWrappedKeysWithSamePkp,
testFailImportWrappedKeysWithSamePrivateKey,
testFailImportWrappedKeysWithEoaSessionSig,
testFailImportWrappedKeysWithMaxExpirySessionSig,
testFailImportWrappedKeysWithInvalidSessionSig,
testFailImportWrappedKeysWithExpiredSessionSig,
};

const eoaSessionSigsTests = {
testUseEoaSessionSigsToExecuteJsSigning,
testUseEoaSessionSigsToPkpSign,
Expand Down Expand Up @@ -233,6 +294,8 @@ import { testExecuteJsBroadcastAndCollect } from './tests/testExecuteJsBroadcast
...litActionCombiningTests.broadcastAndCombine,
...litActionCombiningTests.decryptAndCombine,
...litActionCombiningTests.ecdsaSignAndCombine,

...wrappedKeysTests,
},
devEnv,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { log } from '@lit-protocol/misc';
import { ethers } from 'ethers';
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
import { api, EthereumLitTransaction } from '@lit-protocol/wrapped-keys';
import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs';

const { signTransactionWithEncryptedKey, generatePrivateKey } = api;

/**
* Test Commands:
* ✅ NETWORK=cayenne yarn test:local --filter=testEthereumBroadcastTransactionGeneratedKey
* ✅ NETWORK=manzano yarn test:local --filter=testEthereumBroadcastTransactionGeneratedKey
* ✅ NETWORK=localchain yarn test:local --filter=testEthereumBroadcastTransactionGeneratedKey
*/
export const testEthereumBroadcastTransactionGeneratedKey = async (
devEnv: TinnyEnvironment
) => {
const alice = await devEnv.createRandomPerson();

const pkpSessionSigs = await getPkpSessionSigs(
devEnv,
alice,
null,
new Date(Date.now() + 1000 * 60 * 10).toISOString()
); // 10 mins expiry

console.log(pkpSessionSigs);

const { pkpAddress, generatedPublicKey } = await generatePrivateKey({
pkpSessionSigs,
network: 'evm',
litNodeClient: devEnv.litNodeClient,
});

const generatedKeysWalletAddress =
ethers.utils.computeAddress(generatedPublicKey);
console.log(`Sending funds to ${generatedKeysWalletAddress}`);
await devEnv.getFunds(generatedKeysWalletAddress, '0.005');

const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress;
if (pkpAddress !== alicePkpAddress) {
throw new Error(
`Received address: ${pkpAddress} doesn't match Alice's PKP address: ${alicePkpAddress}`
);
}

const pkpSessionSigsSigning = await getPkpSessionSigs(
devEnv,
alice,
null,
new Date(Date.now() + 1000 * 60 * 10).toISOString()
); // 10 mins expiry

console.log(pkpSessionSigsSigning);

const unsignedTransaction: EthereumLitTransaction = {
toAddress: alice.wallet.address,
value: '0.0001', // in ethers (Lit tokens)
chainId: 175177, // Chronicle
gasPrice: '0.001',
gasLimit: 30000,
dataHex: ethers.utils.hexlify(
ethers.utils.toUtf8Bytes('Test transaction from Alice to bob')
),
chain: 'chronicleTestnet',
};

const signedTx = await signTransactionWithEncryptedKey({
pkpSessionSigs: pkpSessionSigsSigning,
network: 'evm',
unsignedTransaction,
broadcast: true,
litNodeClient: devEnv.litNodeClient,
});

console.log('signedTx');
console.log(signedTx);

if (!ethers.utils.isHexString(signedTx)) {
throw new Error(`signedTx isn't hex: ${signedTx}`);
}

log('✅ testEthereumBroadcastTransactionGeneratedKey');
};
89 changes: 89 additions & 0 deletions local-tests/tests/testEthereumBroadcastTransactionWrappedKey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { log } from '@lit-protocol/misc';
import { ethers } from 'ethers';
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
import { api, EthereumLitTransaction } from '@lit-protocol/wrapped-keys';
import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs';

const { importPrivateKey, signTransactionWithEncryptedKey } = api;

/**
* Test Commands:
* ✅ NETWORK=cayenne yarn test:local --filter=testEthereumBroadcastTransactionWrappedKey
* ✅ NETWORK=manzano yarn test:local --filter=testEthereumBroadcastTransactionWrappedKey
* ✅ NETWORK=localchain yarn test:local --filter=testEthereumBroadcastTransactionWrappedKey
*/
export const testEthereumBroadcastTransactionWrappedKey = async (
devEnv: TinnyEnvironment
) => {
const alice = await devEnv.createRandomPerson();

const pkpSessionSigs = await getPkpSessionSigs(
devEnv,
alice,
null,
new Date(Date.now() + 1000 * 60 * 10).toISOString()
); // 10 mins expiry

console.log(pkpSessionSigs);

const wrappedKeysWallet = ethers.Wallet.createRandom();
const wrappedKeysWalletPrivateKey = wrappedKeysWallet.privateKey;

const wrappedKeysWalletAddress = wrappedKeysWallet.address;
console.log(`Sending funds to ${wrappedKeysWalletAddress}`);
await devEnv.getFunds(wrappedKeysWallet.address, '0.005');

const pkpAddress = await importPrivateKey({
pkpSessionSigs,
privateKey: wrappedKeysWalletPrivateKey,
litNodeClient: devEnv.litNodeClient,
publicKey: '0xdeadbeef',
keyType: 'K256',
});

const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress;
if (pkpAddress !== alicePkpAddress) {
throw new Error(
`Received address: ${pkpAddress} doesn't match Alice's PKP address: ${alicePkpAddress}`
);
}

const pkpSessionSigsSigning = await getPkpSessionSigs(
devEnv,
alice,
null,
new Date(Date.now() + 1000 * 60 * 10).toISOString()
); // 10 mins expiry

console.log(pkpSessionSigsSigning);

const unsignedTransaction: EthereumLitTransaction = {
toAddress: alice.wallet.address,
value: '0.0001', // in ethers (Lit tokens)
chainId: 175177, // Chronicle
gasPrice: '0.001',
gasLimit: 30000,
dataHex: ethers.utils.hexlify(
ethers.utils.toUtf8Bytes('Test transaction from Alice to bob')
),
chain: 'chronicleTestnet',
};

const signedTx = await signTransactionWithEncryptedKey({
pkpSessionSigs: pkpSessionSigsSigning,
network: 'evm',
unsignedTransaction,
broadcast: true,
litNodeClient: devEnv.litNodeClient,
});

console.log('signedTx');
console.log(signedTx);

// TODO: Get the raw input from the tx hash, convert it to UTF-8 and assert that it contains "Test transaction from Alice to bob"
if (!ethers.utils.isHexString(signedTx)) {
throw new Error(`signedTx isn't hex: ${signedTx}`);
}

log('✅ testEthereumBroadcastTransactionWrappedKey');
};
Loading
Loading