diff --git a/packages/snaps-controllers/coverage.json b/packages/snaps-controllers/coverage.json index 28873f6536..fa93d86e38 100644 --- a/packages/snaps-controllers/coverage.json +++ b/packages/snaps-controllers/coverage.json @@ -1,6 +1,6 @@ { "branches": 92.89, "functions": 96.71, - "lines": 98, + "lines": 98.01, "statements": 97.71 } diff --git a/packages/snaps-rpc-methods/jest.config.js b/packages/snaps-rpc-methods/jest.config.js index c02c90e6d6..c99e4be397 100644 --- a/packages/snaps-rpc-methods/jest.config.js +++ b/packages/snaps-rpc-methods/jest.config.js @@ -10,7 +10,7 @@ module.exports = deepmerge(baseConfig, { ], coverageThreshold: { global: { - branches: 92.88, + branches: 92.91, functions: 97.26, lines: 97.84, statements: 97.36, diff --git a/packages/snaps-rpc-methods/src/restricted/getBip32Entropy.test.ts b/packages/snaps-rpc-methods/src/restricted/getBip32Entropy.test.ts index 089a064cdd..5d8882c1f1 100644 --- a/packages/snaps-rpc-methods/src/restricted/getBip32Entropy.test.ts +++ b/packages/snaps-rpc-methods/src/restricted/getBip32Entropy.test.ts @@ -63,10 +63,15 @@ describe('getBip32EntropyImplementation', () => { const getMnemonic = jest .fn() .mockResolvedValue(TEST_SECRET_RECOVERY_PHRASE_BYTES); + const getClientCryptography = jest.fn().mockReturnValue({}); expect( - // @ts-expect-error Missing other required properties. - await getBip32EntropyImplementation({ getUnlockPromise, getMnemonic })({ + await getBip32EntropyImplementation({ + getUnlockPromise, + getMnemonic, + getClientCryptography, + // @ts-expect-error Missing other required properties. + })({ params: { path: ['m', "44'", "1'"], curve: 'secp256k1' }, }), ).toMatchInlineSnapshot(` @@ -76,6 +81,7 @@ describe('getBip32EntropyImplementation', () => { "depth": 2, "index": 2147483649, "masterFingerprint": 1404659567, + "network": "mainnet", "parentFingerprint": 1829122711, "privateKey": "0xc73cedb996e7294f032766853a8b7ba11ab4ce9755fc052f2f7b9000044c99af", "publicKey": "0x048e129862c1de5ca86468add43b001d32fd34b8113de716ecd63fa355b7f1165f0e76f5dc6095100f9fdaa76ddf28aa3f21406ac5fda7c71ffbedb45634fe2ceb", @@ -88,10 +94,15 @@ describe('getBip32EntropyImplementation', () => { const getMnemonic = jest .fn() .mockResolvedValue(TEST_SECRET_RECOVERY_PHRASE_BYTES); + const getClientCryptography = jest.fn().mockReturnValue({}); expect( - // @ts-expect-error Missing other required properties. - await getBip32EntropyImplementation({ getUnlockPromise, getMnemonic })({ + await getBip32EntropyImplementation({ + getUnlockPromise, + getMnemonic, + getClientCryptography, + // @ts-expect-error Missing other required properties. + })({ params: { path: ['m', "44'", "1'", "0'", '0', '1'], curve: 'secp256k1', @@ -104,6 +115,7 @@ describe('getBip32EntropyImplementation', () => { "depth": 5, "index": 1, "masterFingerprint": 1404659567, + "network": "mainnet", "parentFingerprint": 3495658567, "privateKey": "0x43a9353dfebf7209c3feb1843510299e2b0f4fa09151dccc3824df88451be37c", "publicKey": "0x0467f3cac111f47782b6c2d8d0984d51e22c128d24ec3eaca044509a386771d17206c740c7337c399d8ade8f52a60029340f288e11de82fffd3b69c5b863f6a515", @@ -117,9 +129,15 @@ describe('getBip32EntropyImplementation', () => { .fn() .mockResolvedValue(TEST_SECRET_RECOVERY_PHRASE_BYTES); + const getClientCryptography = jest.fn().mockReturnValue({}); + expect( - // @ts-expect-error Missing other required properties. - await getBip32EntropyImplementation({ getUnlockPromise, getMnemonic })({ + await getBip32EntropyImplementation({ + getUnlockPromise, + getMnemonic, + getClientCryptography, + // @ts-expect-error Missing other required properties. + })({ params: { path: ['m', "44'", "1'", "0'", "0'", "1'"], curve: 'ed25519', @@ -132,6 +150,7 @@ describe('getBip32EntropyImplementation', () => { "depth": 5, "index": 2147483649, "masterFingerprint": 650419359, + "network": "mainnet", "parentFingerprint": 660188756, "privateKey": "0x5e6ebe8f5c33833e6c86f8769da173daa206b9dfd1956efcd2b115d82376bb5e", "publicKey": "0x0012affaf55babdfb59b76adcf00f69442f019974124639108470409d47e25e19f", @@ -145,9 +164,15 @@ describe('getBip32EntropyImplementation', () => { .fn() .mockResolvedValue(TEST_SECRET_RECOVERY_PHRASE_BYTES); + const getClientCryptography = jest.fn().mockReturnValue({}); + expect( - // @ts-expect-error Missing other required properties. - await getBip32EntropyImplementation({ getUnlockPromise, getMnemonic })({ + await getBip32EntropyImplementation({ + getUnlockPromise, + getMnemonic, + getClientCryptography, + // @ts-expect-error Missing other required properties. + })({ params: { path: ['m', "44'", "1'", "0'", "0'", "1'"], curve: 'ed25519Bip32', @@ -160,6 +185,7 @@ describe('getBip32EntropyImplementation', () => { "depth": 5, "index": 2147483649, "masterFingerprint": 1587894111, + "network": "mainnet", "parentFingerprint": 3236688876, "privateKey": "0x88a59d7aa9fe82d8f98843ef474195178eb71956dee597252e7a5fbeebbc734e9b5bfdd17f82144a2bea78c8ab19bef26dc93f36e96eaa41453b65cb3daa1817", "publicKey": "0xd91d18b4540a2f30341e8463d5f9b25b14fae9a236dcbea338b668a318bb0867", diff --git a/packages/snaps-rpc-methods/src/restricted/getBip44Entropy.test.ts b/packages/snaps-rpc-methods/src/restricted/getBip44Entropy.test.ts index e6e0970997..8129f0814f 100644 --- a/packages/snaps-rpc-methods/src/restricted/getBip44Entropy.test.ts +++ b/packages/snaps-rpc-methods/src/restricted/getBip44Entropy.test.ts @@ -63,10 +63,15 @@ describe('getBip44EntropyImplementation', () => { const getMnemonic = jest .fn() .mockResolvedValue(TEST_SECRET_RECOVERY_PHRASE_BYTES); + const getClientCryptography = jest.fn().mockReturnValue({}); expect( - // @ts-expect-error Missing other required properties. - await getBip44EntropyImplementation({ getUnlockPromise, getMnemonic })({ + await getBip44EntropyImplementation({ + getUnlockPromise, + getMnemonic, + getClientCryptography, + // @ts-expect-error Missing other required properties. + })({ params: { coinType: 1 }, }), ).toMatchInlineSnapshot(` @@ -76,6 +81,7 @@ describe('getBip44EntropyImplementation', () => { "depth": 2, "index": 2147483649, "masterFingerprint": 1404659567, + "network": "mainnet", "parentFingerprint": 1829122711, "path": "m / bip32:44' / bip32:1'", "privateKey": "0xc73cedb996e7294f032766853a8b7ba11ab4ce9755fc052f2f7b9000044c99af", diff --git a/packages/snaps-rpc-methods/src/restricted/getEntropy.test.ts b/packages/snaps-rpc-methods/src/restricted/getEntropy.test.ts index 08e567573d..0aa77fd0b7 100644 --- a/packages/snaps-rpc-methods/src/restricted/getEntropy.test.ts +++ b/packages/snaps-rpc-methods/src/restricted/getEntropy.test.ts @@ -14,7 +14,7 @@ describe('getEntropyBuilder', () => { methodHooks: { getMnemonic: true, getUnlockPromise: true, - getClientCryptography: jest.fn(), + getClientCryptography: true, }, }); }); diff --git a/packages/snaps-rpc-methods/src/restricted/manageState.test.ts b/packages/snaps-rpc-methods/src/restricted/manageState.test.ts index f80238b139..a6b2cfc45b 100644 --- a/packages/snaps-rpc-methods/src/restricted/manageState.test.ts +++ b/packages/snaps-rpc-methods/src/restricted/manageState.test.ts @@ -19,6 +19,15 @@ const ENCRYPTION_KEY = describe('getEncryptionEntropy', () => { it('returns the encryption entropy for the snap ID', async () => { + const result = await getEncryptionEntropy({ + mnemonicPhrase: TEST_SECRET_RECOVERY_PHRASE_BYTES, + snapId: MOCK_SNAP_ID, + }); + + expect(result).toBe(ENCRYPTION_KEY); + }); + + it('accepts custom cryptographic functions', async () => { const result = await getEncryptionEntropy({ mnemonicPhrase: TEST_SECRET_RECOVERY_PHRASE_BYTES, snapId: MOCK_SNAP_ID, diff --git a/packages/snaps-rpc-methods/src/restricted/manageState.ts b/packages/snaps-rpc-methods/src/restricted/manageState.ts index d62cf0e2b6..0b5db5284d 100644 --- a/packages/snaps-rpc-methods/src/restricted/manageState.ts +++ b/packages/snaps-rpc-methods/src/restricted/manageState.ts @@ -112,7 +112,7 @@ export const STORAGE_SIZE_LIMIT = 104857600; // In bytes (100MB) type GetEncryptionKeyArgs = { snapId: string; mnemonicPhrase: Uint8Array; - cryptographicFunctions: CryptographicFunctions; + cryptographicFunctions?: CryptographicFunctions; }; /** @@ -133,7 +133,7 @@ type GetEncryptionKeyArgs = { export async function getEncryptionEntropy({ mnemonicPhrase, snapId, - cryptographicFunctions, + cryptographicFunctions = {}, }: GetEncryptionKeyArgs) { return await deriveEntropy({ mnemonicPhrase, diff --git a/packages/snaps-rpc-methods/src/utils.test.ts b/packages/snaps-rpc-methods/src/utils.test.ts index cc48a2fa4e..6241b90e4e 100644 --- a/packages/snaps-rpc-methods/src/utils.test.ts +++ b/packages/snaps-rpc-methods/src/utils.test.ts @@ -56,6 +56,7 @@ describe('getNode', () => { "depth": 2, "index": 2147483649, "masterFingerprint": 1404659567, + "network": "mainnet", "parentFingerprint": 1829122711, "privateKey": "0xc73cedb996e7294f032766853a8b7ba11ab4ce9755fc052f2f7b9000044c99af", "publicKey": "0x048e129862c1de5ca86468add43b001d32fd34b8113de716ecd63fa355b7f1165f0e76f5dc6095100f9fdaa76ddf28aa3f21406ac5fda7c71ffbedb45634fe2ceb", @@ -77,6 +78,7 @@ describe('getNode', () => { "depth": 2, "index": 2147483649, "masterFingerprint": 650419359, + "network": "mainnet", "parentFingerprint": 4080844380, "privateKey": "0x9dee85af06f9b94d2451549f5a9b0a3bbba9e2513daebc793ca5c9a13e80cafa", "publicKey": "0x00c9aaf347832dc3b1dbb7aab4f41e5e04c64446b819c0761571c27b9f90eacb27",