Skip to content

Commit 733d9ca

Browse files
committed
Merge branch 'refs/heads/staging/v7' into feature/lit-3796-js-sdk-research-to-use-zod
# Conflicts: # packages/constants/src/lib/constants/constants.ts
2 parents a461e08 + 0bf0855 commit 733d9ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+800
-322
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#Default reviewers
2-
* @joshLong145 @Ansonhkg
2+
* @Ansonhkg

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
33
"useNx": true,
44
"useWorkspaces": true,
5-
"version": "6.9.0"
5+
"version": "6.10.0"
66
}

local-tests/test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ import { testExportWrappedKey } from './tests/wrapped-keys/testExportWrappedKey'
103103
import { testSignMessageWithSolanaEncryptedKey } from './tests/wrapped-keys/testSignMessageWithSolanaEncryptedKey';
104104
import { testSignTransactionWithSolanaEncryptedKey } from './tests/wrapped-keys/testSignTransactionWithSolanaEncryptedKey';
105105
import { testBatchGeneratePrivateKeys } from './tests/wrapped-keys/testBatchGeneratePrivateKeys';
106+
import { testFailBatchGeneratePrivateKeysAtomic } from './tests/wrapped-keys/testFailStoreEncryptedKeyBatchIsAtomic';
106107

107108
import { setLitActionsCodeToLocal } from './tests/wrapped-keys/util';
108109
import { testUseEoaSessionSigsToRequestSingleResponse } from './tests/testUseEoaSessionSigsToRequestSingleResponse';
@@ -149,6 +150,7 @@ setLitActionsCodeToLocal();
149150
testFailEthereumSignTransactionWrappedKeyWithMissingParam,
150151
testFailEthereumSignTransactionWrappedKeyWithInvalidParam,
151152
testFailEthereumSignTransactionWrappedKeyInvalidDecryption,
153+
testFailBatchGeneratePrivateKeysAtomic,
152154

153155
// -- import wrapped keys
154156
testFailImportWrappedKeysWithSamePrivateKey,

local-tests/tests/testEthAuthSigToEncryptDecryptString.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AccessControlConditions } from 'local-tests/setup/accs/accs';
33
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
44
import { log } from '@lit-protocol/misc';
55
import { encryptString, decryptToString } from '@lit-protocol/encryption';
6+
import { CENTRALISATION_BY_NETWORK } from '@lit-protocol/constants';
67

78
/**
89
* Test Commands:
@@ -15,6 +16,12 @@ export const testEthAuthSigToEncryptDecryptString = async (
1516
) => {
1617
const alice = await devEnv.createRandomPerson();
1718

19+
if (CENTRALISATION_BY_NETWORK[devEnv.network] === 'decentralised') {
20+
// The capacity credits NFT owner automatically uses the capacity credits
21+
// to pay for the encryption
22+
await alice.mintCapacityCreditsNFT();
23+
}
24+
1825
const accs = AccessControlConditions.getEmvBasicAccessControlConditions({
1926
userAddress: alice.authSig.address,
2027
});

local-tests/tests/wrapped-keys/testBatchGeneratePrivateKeys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import bs58 from 'bs58';
77
import { ethers } from 'ethers';
88
import { BatchGeneratePrivateKeysActionResult } from '../../../packages/wrapped-keys/src/lib/types';
99

10-
const { batchGeneratePrivateKeys, exportPrivateKey } = api;
10+
const { batchGeneratePrivateKeys } = api;
1111

1212
async function verifySolanaSignature(
1313
solanaResult: BatchGeneratePrivateKeysActionResult,

local-tests/tests/wrapped-keys/testFailEthereumSignTransactionWrappedKeyInvalidDecryption.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { log } from '@lit-protocol/misc';
22
import { ethers } from 'ethers';
33
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
4-
import { EthereumLitTransaction } from '@lit-protocol/wrapped-keys';
54
import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs';
6-
import { getPkpAccessControlCondition } from 'packages/wrapped-keys/src/lib/utils';
75
import { encryptString } from '@lit-protocol/encryption';
86
import { LIT_PREFIX } from 'packages/wrapped-keys/src/lib/constants';
97
import { LIT_ACTION_CID_REPOSITORY } from '../../../packages/wrapped-keys/src/lib/lit-actions-client/constants';
108
import { getBaseTransactionForNetwork } from './util';
119
import { GLOBAL_OVERWRITE_IPFS_CODE_BY_NETWORK } from '@lit-protocol/constants';
10+
import { getPkpAccessControlCondition } from '../../../packages/wrapped-keys/src/lib/api/utils';
1211

1312
/**
1413
* Test Commands:
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import { log } from '@lit-protocol/misc';
2+
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
3+
import { api } from '@lit-protocol/wrapped-keys';
4+
import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs';
5+
import { batchGenerateKeysWithLitAction } from '../../../packages/wrapped-keys/src/lib/lit-actions-client';
6+
import { getLitActionCodeOrCidCommon } from '../../../packages/wrapped-keys/src/lib/lit-actions-client/utils';
7+
import {
8+
getFirstSessionSig,
9+
getKeyTypeFromNetwork,
10+
getPkpAccessControlCondition,
11+
getPkpAddressFromSessionSig,
12+
} from '../../../packages/wrapped-keys/src/lib/api/utils';
13+
import { listEncryptedKeyMetadata } from '../../../packages/wrapped-keys/src/lib/api';
14+
15+
const { storeEncryptedKeyBatch } = api;
16+
17+
/**
18+
* Test Commands:
19+
* ✅ NETWORK=datil-dev yarn test:local --filter=testSignMessageWithSolanaEncryptedKey
20+
* ✅ NETWORK=datil-test yarn test:local --filter=testSignMessageWithSolanaEncryptedKey
21+
* ✅ NETWORK=localchain yarn test:local --filter=testSignMessageWithSolanaEncryptedKey
22+
*/
23+
export const testFailBatchGeneratePrivateKeysAtomic = async (
24+
devEnv: TinnyEnvironment
25+
) => {
26+
const alice = await devEnv.createRandomPerson();
27+
28+
try {
29+
const pkpSessionSigsSigning = await getPkpSessionSigs(
30+
devEnv,
31+
alice,
32+
null,
33+
new Date(Date.now() + 1000 * 60 * 10).toISOString()
34+
); // 10 mins expiry
35+
36+
const solanaMessageToSign = 'This is a test solana message';
37+
const evmMessageToSign = 'This is a test evm message';
38+
39+
const sessionSig = getFirstSessionSig(pkpSessionSigsSigning);
40+
const pkpAddress = getPkpAddressFromSessionSig(sessionSig);
41+
42+
const allowPkpAddressToDecrypt = getPkpAccessControlCondition(pkpAddress);
43+
44+
const { litActionCode, litActionIpfsCid } = getLitActionCodeOrCidCommon(
45+
'batchGenerateEncryptedKeys'
46+
);
47+
48+
const actionResults = await batchGenerateKeysWithLitAction({
49+
litNodeClient: devEnv.litNodeClient,
50+
litActionIpfsCid: litActionCode ? undefined : litActionIpfsCid,
51+
litActionCode: litActionCode ? litActionCode : undefined,
52+
accessControlConditions: [allowPkpAddressToDecrypt],
53+
actions: [
54+
{
55+
network: 'evm',
56+
signMessageParams: { messageToSign: evmMessageToSign },
57+
generateKeyParams: { memo: 'Test evm key' },
58+
},
59+
{
60+
network: 'solana',
61+
signMessageParams: { messageToSign: solanaMessageToSign },
62+
generateKeyParams: { memo: 'Test solana key' },
63+
},
64+
],
65+
pkpSessionSigs: pkpSessionSigsSigning,
66+
});
67+
68+
const keyParamsBatch = actionResults.map((keyData) => {
69+
const { generateEncryptedPrivateKey, network } = keyData;
70+
return {
71+
...generateEncryptedPrivateKey,
72+
keyType: getKeyTypeFromNetwork(network),
73+
};
74+
});
75+
76+
// Intentional failure to persist due to missing publicKey
77+
delete keyParamsBatch[0].publicKey;
78+
79+
try {
80+
await storeEncryptedKeyBatch({
81+
pkpSessionSigs: pkpSessionSigsSigning,
82+
litNodeClient: devEnv.litNodeClient,
83+
keyBatch: keyParamsBatch,
84+
});
85+
86+
throw new Error(
87+
'storeEncryptedKeyBatch() succeeded but we expected it to fail!'
88+
);
89+
} catch (err) {
90+
// We expect `storeEncryptedKeyBatch` to fail w/ a specific error
91+
if (
92+
err.message.includes(
93+
'storeEncryptedKeyBatch() succeeded but we expected it to fail!'
94+
) ||
95+
!err.message.includes(
96+
'keyParamsBatch[0]: Missing "publicKey" parameter in request'
97+
)
98+
) {
99+
throw err;
100+
}
101+
102+
try {
103+
const keys = await listEncryptedKeyMetadata({
104+
litNodeClient: devEnv.litNodeClient,
105+
pkpSessionSigs: pkpSessionSigsSigning,
106+
});
107+
108+
console.error(
109+
'Got a value back we shouldnt have from listEncryptedKeyMetadata()',
110+
keys
111+
);
112+
113+
throw new Error(
114+
'Expected `listEncryptedKeyMetadata() to fail, but it didnt!`'
115+
);
116+
} catch (err) {
117+
if (err.message.includes('No keys exist for pkpAddress')) {
118+
log('✅ testFailBatchGeneratePrivateKeysAtomic');
119+
} else {
120+
throw err;
121+
}
122+
}
123+
}
124+
} catch (err) {
125+
console.log(err.message, err, err.stack);
126+
throw err;
127+
} finally {
128+
devEnv.releasePrivateKeyFromUser(alice);
129+
}
130+
};

local-tests/tests/wrapped-keys/testImportWrappedKey.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
33
import { api } from '@lit-protocol/wrapped-keys';
44
import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs';
55
import { randomSolanaPrivateKey } from 'local-tests/setup/tinny-utils';
6-
import { listPrivateKeyMetadata } from '../../../packages/wrapped-keys/src/lib/service-client';
7-
import { getFirstSessionSig } from '../../../packages/wrapped-keys/src/lib/utils';
86

9-
const { importPrivateKey } = api;
7+
const { importPrivateKey, listEncryptedKeyMetadata } = api;
108

119
/**
1210
* Test Commands:
@@ -44,9 +42,9 @@ export const testImportWrappedKey = async (devEnv: TinnyEnvironment) => {
4442
);
4543
}
4644

47-
const keys = await listPrivateKeyMetadata({
48-
sessionSig: getFirstSessionSig(pkpSessionSigs),
49-
litNetwork: devEnv.litNodeClient.config.litNetwork,
45+
const keys = await listEncryptedKeyMetadata({
46+
pkpSessionSigs,
47+
litNodeClient: devEnv.litNodeClient,
5048
});
5149

5250
if (keys.length !== 1 || keys[0].id !== id) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"@cosmjs/proto-signing": "0.30.1",
4141
"@cosmjs/stargate": "0.30.1",
4242
"@dotenvx/dotenvx": "^1.6.4",
43-
"@lit-protocol/accs-schemas": "^0.0.14",
43+
"@lit-protocol/accs-schemas": "^0.0.15",
4444
"@lit-protocol/contracts": "^0.0.63",
4545
"@metamask/eth-sig-util": "5.0.2",
4646
"@mysten/sui.js": "^0.37.1",

packages/access-control-conditions/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,5 @@
2121
"tags": [
2222
"universal"
2323
],
24-
"version": "6.9.0",
25-
"main": "./dist/src/index.js",
26-
"typings": "./dist/src/index.d.ts"
24+
"version": "6.10.0"
2725
}

0 commit comments

Comments
 (0)