-
Notifications
You must be signed in to change notification settings - Fork 307
refactor(abstract-substrate): extract MPCv2 helpers into SubstrateCoin #9408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vibhavgo
wants to merge
1
commit into
master
Choose a base branch
from
feat/abstract-substrate/WCI-1239
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+157
−34
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
57 changes: 57 additions & 0 deletions
57
modules/abstract-substrate/test/unit/abstractSubstrateCoin.ts
This file contains hidden or 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,57 @@ | ||
| import * as sinon from 'sinon'; | ||
| // Cross-module relative import: tsx resolves TypeScript source directly in the monorepo, | ||
| // avoiding a circular devDependency (sdk-coin-tao depends on abstract-substrate at runtime). | ||
| import { Ttao } from '../../../sdk-coin-tao/src'; | ||
|
|
||
| interface SubstrateCoinTestAccessor { | ||
| isMpcV2Keycard(userKey: string, walletPassphrase: string): Promise<{ version: 'v1' | 'v2' }>; | ||
| } | ||
|
|
||
| describe('SubstrateCoin MPCv2 recovery helpers:', function () { | ||
| const sandBox = sinon.createSandbox(); | ||
| // Bypass the constructor (which requires a full BitGoBase) — we only need the | ||
| // prototype methods. | ||
| const basecoin = Object.create(Ttao.prototype) as Ttao & SubstrateCoinTestAccessor; | ||
| // isEddsaMpcV1SigningMaterial is gated behind non-configurable namespace getters that | ||
| // sinon cannot replace. Provide bitgo.decrypt so it uses that path instead of sjcl, | ||
| // then control V1 vs V2 detection by returning JSON (V1) or non-JSON (V2). | ||
| let decryptStub: sinon.SinonStub; | ||
|
|
||
| beforeEach(function () { | ||
| decryptStub = sinon.stub(); | ||
| (basecoin as unknown as { bitgo: unknown }).bitgo = { decrypt: decryptStub }; | ||
| }); | ||
|
|
||
| afterEach(function () { | ||
| sandBox.restore(); | ||
| }); | ||
|
|
||
| describe('isMpcV2Keycard()', function () { | ||
| it('should return version v2 for a CBOR (MPCv2) keycard', async function () { | ||
| // Non-JSON decrypted value → V2 CBOR keycard | ||
| decryptStub.resolves('not-json-cbor-bytes'); | ||
| const result = await basecoin.isMpcV2Keycard('encryptedKey', 'passphrase'); | ||
| result.version.should.equal('v2'); | ||
| }); | ||
|
|
||
| it('should return version v1 for a JSON (MPCv1) keycard', async function () { | ||
| // isMpcV2Keycard checks uShare.seed + bitgoYShare.u + backupYShare.u | ||
| decryptStub.resolves( | ||
| JSON.stringify({ | ||
| uShare: { seed: 'deadbeef' }, | ||
| bitgoYShare: { u: 'aabbcc' }, | ||
| backupYShare: { u: 'ddeeff' }, | ||
| }) | ||
| ); | ||
| const result = await basecoin.isMpcV2Keycard('encryptedKey', 'passphrase'); | ||
| result.version.should.equal('v1'); | ||
| }); | ||
|
|
||
| it('should throw with a descriptive message when decryption fails', async function () { | ||
| decryptStub.rejects(new Error('bad password')); | ||
| await basecoin | ||
| .isMpcV2Keycard('encryptedKey', 'wrong-passphrase') | ||
| .should.be.rejectedWith(/Error decrypting user keychain/); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.