Skip to content

Commit 2db382c

Browse files
author
Josh Long
committed
Merge branch 'master' of github.com:LIT-Protocol/js-sdk into feature/lit-2921-js-sdk-migrate-to-jest
2 parents 0aafdce + 6003741 commit 2db382c

Some content is hidden

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

54 files changed

+582
-214
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/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,
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+
};

package.json

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

packages/access-control-conditions/package.json

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

packages/auth-browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"tags": [
3131
"browser"
3232
],
33-
"version": "6.9.0",
33+
"version": "6.10.0",
3434
"main": "./dist/src/index.js",
3535
"typings": "./dist/src/index.d.ts"
3636
}

packages/auth-helpers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"crypto": false,
2929
"stream": false
3030
},
31-
"version": "6.9.0",
31+
"version": "6.10.0",
3232
"main": "./dist/src/index.js",
3333
"typings": "./dist/src/index.d.ts"
3434
}

packages/bls-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"buildOptions": {
2828
"genReact": false
2929
},
30-
"version": "6.9.0",
30+
"version": "6.10.0",
3131
"main": "./dist/src/index.js",
3232
"typings": "./dist/src/index.d.ts"
3333
}

packages/constants/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"tags": [
2121
"universal"
2222
],
23-
"version": "6.9.0",
23+
"version": "6.10.0",
2424
"main": "./dist/src/index.js",
2525
"typings": "./dist/src/index.d.ts"
2626
}

0 commit comments

Comments
 (0)