Skip to content

Commit ccff8a9

Browse files
feat(wrapped-keys): LIT-3956 - Fix encapsulation of getPkpAddressFromSessionSig(), 'getFirstSessionSig()' and getPkpAccessControlCondition() - all are api specific
- Also fixed `testImportWrappedKey` so it uses our `api` method to list keys after importing one instead of importing our internal `service-client` from a direct reference to a deep path in our local packages dir
1 parent ff03458 commit ccff8a9

19 files changed

+185
-180
lines changed

local-tests/test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -293,22 +293,22 @@ setLitActionsCodeToLocal();
293293
tests: {
294294
// testExample,
295295
// testBundleSpeed,
296-
...eoaSessionSigsTests,
297-
...pkpSessionSigsTests,
298-
...litActionSessionSigsTests,
299-
...litActionIpfsIdSessionSigsTests,
300-
...capacityDelegationTests,
301-
...bareAuthSigTests,
302-
303-
...pkpEthersTest.eoaSessionSigs,
304-
...pkpEthersTest.pkpSessionSigs,
305-
...pkpEthersTest.litActionSessionSigs,
306-
307-
...litActionCombiningTests.broadcastAndCombine,
308-
...litActionCombiningTests.decryptAndCombine,
309-
...litActionCombiningTests.ecdsaSignAndCombine,
310-
311-
...relayerTests,
296+
// ...eoaSessionSigsTests,
297+
// ...pkpSessionSigsTests,
298+
// ...litActionSessionSigsTests,
299+
// ...litActionIpfsIdSessionSigsTests,
300+
// ...capacityDelegationTests,
301+
// ...bareAuthSigTests,
302+
//
303+
// ...pkpEthersTest.eoaSessionSigs,
304+
// ...pkpEthersTest.pkpSessionSigs,
305+
// ...pkpEthersTest.litActionSessionSigs,
306+
//
307+
// ...litActionCombiningTests.broadcastAndCombine,
308+
// ...litActionCombiningTests.decryptAndCombine,
309+
// ...litActionCombiningTests.ecdsaSignAndCombine,
310+
//
311+
// ...relayerTests,
312312
...wrappedKeysTests,
313313
},
314314
devEnv,

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:

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@ import { log } from '@lit-protocol/misc';
22
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';
5-
import nacl from 'tweetnacl';
6-
import bs58 from 'bs58';
7-
import { ethers } from 'ethers';
8-
import { BatchGeneratePrivateKeysActionResult } from '../../../packages/wrapped-keys/src/lib/types';
95
import { batchGenerateKeysWithLitAction } from '../../../packages/wrapped-keys/src/lib/lit-actions-client';
6+
import { getLitActionCodeOrCidCommon } from '../../../packages/wrapped-keys/src/lib/lit-actions-client/utils';
107
import {
118
getFirstSessionSig,
9+
getKeyTypeFromNetwork,
1210
getPkpAccessControlCondition,
1311
getPkpAddressFromSessionSig,
14-
} from '../../../packages/wrapped-keys/src/lib/utils';
15-
import { getLitActionCodeOrCidCommon } from '../../../packages/wrapped-keys/src/lib/lit-actions-client/utils';
16-
import { getKeyTypeFromNetwork } from '../../../packages/wrapped-keys/src/lib/api/utils';
12+
} from '../../../packages/wrapped-keys/src/lib/api/utils';
1713
import { listEncryptedKeyMetadata } from '../../../packages/wrapped-keys/src/lib/api';
1814

19-
const { batchGeneratePrivateKeys, storeEncryptedKeyBatch } = api;
15+
const { storeEncryptedKeyBatch } = api;
2016

2117
/**
2218
* Test Commands:

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) {

packages/wrapped-keys/src/lib/api/batch-generate-private-keys.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { getKeyTypeFromNetwork } from './utils';
1+
import {
2+
getFirstSessionSig,
3+
getKeyTypeFromNetwork,
4+
getPkpAccessControlCondition,
5+
getPkpAddressFromSessionSig,
6+
} from './utils';
27
import { batchGenerateKeysWithLitAction } from '../lit-actions-client';
38
import { getLitActionCodeOrCidCommon } from '../lit-actions-client/utils';
49
import { storePrivateKeyBatch } from '../service-client';
@@ -7,11 +12,6 @@ import {
712
BatchGeneratePrivateKeysParams,
813
BatchGeneratePrivateKeysResult,
914
} from '../types';
10-
import {
11-
getFirstSessionSig,
12-
getPkpAccessControlCondition,
13-
getPkpAddressFromSessionSig,
14-
} from '../utils';
1515

1616
/**
1717
* TODO: Document batch behaviour
@@ -50,7 +50,6 @@ export async function batchGeneratePrivateKeys(
5050
});
5151

5252
const { ids } = await storePrivateKeyBatch({
53-
pkpAddress,
5453
sessionSig,
5554
storedKeyMetadataBatch: keyParamsBatch,
5655
litNetwork: litNodeClient.config.litNetwork,

packages/wrapped-keys/src/lib/api/export-private-key.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import {
2+
getFirstSessionSig,
3+
getPkpAccessControlCondition,
4+
getPkpAddressFromSessionSig,
5+
} from './utils';
16
import { exportPrivateKeyWithLitAction } from '../lit-actions-client';
27
import { getLitActionCodeOrCid } from '../lit-actions-client/utils';
38
import { fetchPrivateKey } from '../service-client';
49
import { ExportPrivateKeyParams, ExportPrivateKeyResult } from '../types';
5-
import { getFirstSessionSig, getPkpAccessControlCondition } from '../utils';
610

711
/**
812
* Exports a previously persisted private key from the wrapped keys service for direct use by the caller, along with the keys metadata.
@@ -19,7 +23,10 @@ export async function exportPrivateKey(
1923
const { litNodeClient, network, pkpSessionSigs, id } = params;
2024

2125
const sessionSig = getFirstSessionSig(pkpSessionSigs);
26+
const pkpAddress = getPkpAddressFromSessionSig(sessionSig);
27+
2228
const storedKeyMetadata = await fetchPrivateKey({
29+
pkpAddress,
2330
id,
2431
sessionSig,
2532
litNetwork: litNodeClient.config.litNetwork,

packages/wrapped-keys/src/lib/api/generate-private-key.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { getKeyTypeFromNetwork } from './utils';
2-
import { generateKeyWithLitAction } from '../lit-actions-client';
3-
import { getLitActionCodeOrCid } from '../lit-actions-client/utils';
4-
import { storePrivateKey } from '../service-client';
5-
import { GeneratePrivateKeyParams, GeneratePrivateKeyResult } from '../types';
61
import {
72
getFirstSessionSig,
3+
getKeyTypeFromNetwork,
84
getPkpAccessControlCondition,
95
getPkpAddressFromSessionSig,
10-
} from '../utils';
6+
} from './utils';
7+
import { generateKeyWithLitAction } from '../lit-actions-client';
8+
import { getLitActionCodeOrCid } from '../lit-actions-client/utils';
9+
import { storePrivateKey } from '../service-client';
10+
import { GeneratePrivateKeyParams, GeneratePrivateKeyResult } from '../types';
1111

1212
/**
1313
* Generates a random private key inside a Lit Action, and persists the key and its metadata to the wrapped keys service.
@@ -55,7 +55,6 @@ export async function generatePrivateKey(
5555
publicKey,
5656
keyType: getKeyTypeFromNetwork(network),
5757
dataToEncryptHash,
58-
pkpAddress,
5958
memo,
6059
},
6160
litNetwork: litNodeClient.config.litNetwork,

packages/wrapped-keys/src/lib/api/get-encrypted-key.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { getFirstSessionSig, getPkpAddressFromSessionSig } from './utils';
12
import { fetchPrivateKey } from '../service-client';
23
import { GetEncryptedKeyDataParams, StoredKeyData } from '../types';
3-
import { getFirstSessionSig } from '../utils';
44

55
/** Get a previously encrypted and persisted private key and its metadata.
66
* Note that this method does _not_ decrypt the private key; only the _encrypted_ key and its metadata will be returned to the caller.
@@ -13,9 +13,13 @@ export async function getEncryptedKey(
1313
): Promise<StoredKeyData> {
1414
const { pkpSessionSigs, litNodeClient, id } = params;
1515

16+
const sessionSig = getFirstSessionSig(pkpSessionSigs);
17+
const pkpAddress = getPkpAddressFromSessionSig(sessionSig);
18+
1619
return fetchPrivateKey({
20+
pkpAddress,
1721
id,
18-
sessionSig: getFirstSessionSig(pkpSessionSigs),
22+
sessionSig,
1923
litNetwork: litNodeClient.config.litNetwork,
2024
});
2125
}

packages/wrapped-keys/src/lib/api/import-private-key.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { encryptString } from '@lit-protocol/encryption';
22

3-
import { LIT_PREFIX } from '../constants';
4-
import { storePrivateKey } from '../service-client';
5-
import { ImportPrivateKeyParams, ImportPrivateKeyResult } from '../types';
63
import {
74
getFirstSessionSig,
85
getPkpAccessControlCondition,
96
getPkpAddressFromSessionSig,
10-
} from '../utils';
7+
} from './utils';
8+
import { LIT_PREFIX } from '../constants';
9+
import { storePrivateKey } from '../service-client';
10+
import { ImportPrivateKeyParams, ImportPrivateKeyResult } from '../types';
1111

1212
/**
1313
* Import a provided private key into the wrapped keys service backend.
@@ -52,7 +52,6 @@ export async function importPrivateKey(
5252
publicKey,
5353
keyType,
5454
dataToEncryptHash,
55-
pkpAddress,
5655
memo,
5756
},
5857
});

packages/wrapped-keys/src/lib/api/list-encrypted-key-metadata.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { getFirstSessionSig, getPkpAddressFromSessionSig } from './utils';
12
import { listPrivateKeyMetadata } from '../service-client';
23
import { ListEncryptedKeyMetadataParams, StoredKeyMetadata } from '../types';
3-
import { getFirstSessionSig } from '../utils';
44

55
/** Get list of metadata for previously encrypted and persisted private keys
66
* Note that this method does include the `ciphertext` or `dataToEncryptHash` values necessary to decrypt the keys.
@@ -13,9 +13,12 @@ export async function listEncryptedKeyMetadata(
1313
params: ListEncryptedKeyMetadataParams
1414
): Promise<StoredKeyMetadata[]> {
1515
const { pkpSessionSigs, litNodeClient } = params;
16+
const sessionSig = getFirstSessionSig(pkpSessionSigs);
17+
const pkpAddress = getPkpAddressFromSessionSig(sessionSig);
1618

1719
return listPrivateKeyMetadata({
18-
sessionSig: getFirstSessionSig(pkpSessionSigs),
20+
pkpAddress,
21+
sessionSig,
1922
litNetwork: litNodeClient.config.litNetwork,
2023
});
2124
}

0 commit comments

Comments
 (0)