-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cab): Use new verifiers with custom domains, update torus libs (#…
…4942) ### Description Kind of a two-birds-one-stone PR, both for [ACT-875](https://linear.app/valora/issue/ACT-875/use-a-custom-domain-with-auth0) and [ACT-876](https://linear.app/valora/issue/ACT-876/refactor-gettorusprivatekey-to-use-updated-torusweb3auth-dependencies). Basically the work that led to this PR progressed as follows: * Updated Auth0 to use custom domains for prod/dev * Tried to update our custom verifiers in web3auth dashboard to use new Auth0 domains * Our existing verifiers were nowhere to be found in the dashboard * Created new verifiers using the newest Sapphire main/devnets (as opposed to deprecated Cyan network, which our previous verifiers were on) * Had trouble adapting our existing wallet code to integrate with the new verifiers * Updated `@torus/*` libraries and referred to their docs for how to migrate, was able to connect to new verifiers * Was able to go through backup + restore using custom Auth0 domains _and_ new verifiers on Alfajores. This fulfills the requirements for both ACT-875 and ACT-876 AFAICT. I haven't yet tried to directly use the web3auth libs _instead_ of the torus libs; I'll give it a shot, but if it doesn't seem to work, the changes in this ticket should also suffice. ### Test plan Manual tested. ### Related issues - Fixes [ACT-875](https://linear.app/valora/issue/ACT-875/use-a-custom-domain-with-auth0) and [ACT-876](https://linear.app/valora/issue/ACT-876/refactor-gettorusprivatekey-to-use-updated-torusweb3auth-dependencies). ### Backwards compatibility This is not backwards compatible, in the sense that someone who's backed up will not be able to restore, but this shouldn't matter since we haven't gone live with CAB yet. ### Network scalability If a new NetworkId and/or Network are added in the future, the changes in this PR will: - [x] Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added) --------- Co-authored-by: Tom McGuire <Mcgtom10@gmail.com> Co-authored-by: Jacob Waterman <jacobrwaterman@gmail.com>
- Loading branch information
1 parent
b8156cc
commit e916b99
Showing
15 changed files
with
272 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { getTorusPrivateKey } from './web3auth' | ||
import Torus from '@toruslabs/torus.js' | ||
|
||
jest.mock('@toruslabs/torus.js') | ||
jest.mock('@toruslabs/fetch-node-details', () => { | ||
return () => { | ||
return { | ||
getNodeDetails: jest.fn().mockReturnValue({ | ||
torusNodeEndpoints: 'foo', | ||
torusNodePub: 'bar', | ||
torusIndexes: 'baz', | ||
}), | ||
} | ||
} | ||
}) | ||
|
||
// default JWT from https://jwt.io/ | ||
const MOCK_JWT = | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c' | ||
|
||
describe('getTorusPrivateKey', () => { | ||
let mockRetrieveShares: jest.Mock | ||
let mockGetPublicAddress: jest.Mock | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
|
||
mockRetrieveShares = jest.fn().mockReturnValue({ | ||
finalKeyData: { | ||
evmAddress: 'Some EVM address', | ||
privKey: 'some private key', | ||
}, | ||
}) | ||
mockGetPublicAddress = jest.fn().mockReturnValue({ | ||
finalKeyData: { | ||
evmAddress: 'Some EVM address', | ||
}, | ||
}) | ||
jest.mocked(Torus).mockReturnValue({ | ||
getPublicAddress: mockGetPublicAddress, | ||
retrieveShares: mockRetrieveShares, | ||
} as any) | ||
}) | ||
|
||
it('should retrun private key successfully', async () => { | ||
const result = await getTorusPrivateKey({ verifier: 'verifier', jwt: MOCK_JWT }) | ||
expect(result).toEqual('some private key') | ||
}) | ||
|
||
it('should throw when keyshare address does not match torus address', async () => { | ||
mockRetrieveShares.mockReturnValue({ | ||
finalKeyData: { | ||
evmAddress: 'Some different EVM address', | ||
privKey: 'some private key', | ||
}, | ||
}) | ||
await expect(getTorusPrivateKey({ verifier: 'verifier', jwt: MOCK_JWT })).rejects.toThrow( | ||
'sharesEthAddressLower does not match torusPubKey' | ||
) | ||
}) | ||
|
||
it('should throw when private key missing from share data', async () => { | ||
mockRetrieveShares.mockReturnValue({ | ||
finalKeyData: { | ||
evmAddress: 'Some EVM address', | ||
}, | ||
}) | ||
await expect(getTorusPrivateKey({ verifier: 'verifier', jwt: MOCK_JWT })).rejects.toThrow( | ||
'private key missing from share data' | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.