-
Notifications
You must be signed in to change notification settings - Fork 11
Fix/disableHashedFactorkey #223
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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f8ab2e1
fix: setDeviceFactor
ieow 979200a
fix: cleanup ts syntax
ieow 898d8a6
fix: update ed25519 tests
ieow 0712bff
fix: update session on commit
ieow 5a0a7f7
fix: revert ts changes
ieow 9296b87
fix: add pre check in inputfactorkey
ieow 3669bdb
fix: ts syntax, duplicated deleteMetadataShareBackup
ieow 26601cc
chore: revert session manager changes
ieow 1c6ea6f
fix: atomic sync for delete and backup metadata share
ieow 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -323,6 +323,11 @@ export class Web3AuthMPCCoreKit implements ICoreKit { | |
| if (this.isNodejsOrRN(this.options.uxMode)) { | ||
| throw CoreKitError.oauthLoginUnsupported(`Oauth login is NOT supported in ${this.options.uxMode} mode.`); | ||
| } | ||
|
|
||
| if (this.state.factorKey) { | ||
| throw CoreKitError.oauthLoginUnsupported("Instance is alreay login or rehydrated"); | ||
| } | ||
|
|
||
| const { importTssKey, registerExistingSFAKey } = params; | ||
| const tkeyServiceProvider = this.torusSp; | ||
|
|
||
|
|
@@ -677,7 +682,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit { | |
| */ | ||
| public getPubKey(): Buffer { | ||
| const { tssPubKey } = this.state; | ||
| return Buffer.from(tssPubKey); | ||
| return tssPubKey; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -756,7 +761,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit { | |
| } | ||
|
|
||
| // Client lib expects pub key in XY-format, base64-encoded. | ||
| const tssPubKeyBase64 = Buffer.from(tssPubKey.toSEC1(secp256k1).subarray(1)).toString("base64"); | ||
| const tssPubKeyBase64 = tssPubKey.toSEC1(secp256k1).subarray(1).toString("base64"); | ||
|
|
||
| const client = new Client( | ||
| currentSession, | ||
|
|
@@ -796,7 +801,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit { | |
| this.wasmLib = await this.loadTssWasm(); | ||
| if (this.keyType === KeyType.secp256k1) { | ||
| const sig = await this.sign_ECDSA_secp256k1(data, hashed, secp256k1Precompute); | ||
| return Buffer.concat([sig.r, sig.s, Buffer.from([sig.v])]); | ||
| return Buffer.concat([new Uint8Array(sig.r), new Uint8Array(sig.s), new Uint8Array([sig.v])]); | ||
| } else if (this.keyType === KeyType.ed25519) { | ||
| return this.sign_ed25519(data, hashed); | ||
| } | ||
|
|
@@ -892,6 +897,19 @@ export class Web3AuthMPCCoreKit implements ICoreKit { | |
| // manual call syncLocalMetadataTransitions() required to sync local transitions to storage | ||
| await this.tKey._syncShareMetadata(); | ||
| await this.tKey.syncLocalMetadataTransitions(); | ||
|
|
||
| if (this.sessionId) { | ||
| const payload: SessionData = { | ||
| postBoxKey: this.state.postBoxKey, | ||
| postboxKeyNodeIndexes: this.state.postboxKeyNodeIndexes || [], | ||
| factorKey: this.state.factorKey?.toString("hex"), | ||
| tssShareIndex: this.state.tssShareIndex as number, | ||
| tssPubKey: this.state.tssPubKey?.toString("hex"), | ||
| signatures: this.signatures, | ||
| userInfo: this.state.userInfo, | ||
| }; | ||
| this.sessionManager.updateSession(payload); | ||
| } | ||
| } catch (error: unknown) { | ||
| log.error("sync metadata error", error); | ||
| throw error; | ||
|
|
@@ -1107,6 +1125,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit { | |
| shareDescription: FactorKeyTypeShareDescription.Other, | ||
| updateMetadata: false, | ||
| }); | ||
| await this.setDeviceFactor(factorKey); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this means the factor key was previously not persisted here, which is kind of catastrophic. We should have a test that asserts this.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tests added |
||
| } else { | ||
| await this.addFactorDescription({ | ||
| factorKey, | ||
|
|
@@ -1199,8 +1218,16 @@ export class Web3AuthMPCCoreKit implements ICoreKit { | |
| signatures: result.signatures, | ||
| userInfo: result.userInfo, | ||
| }); | ||
|
|
||
| // update device factor if not present upon rehydration | ||
| if (this.options.disableHashedFactorKey) { | ||
| const deviceFactorKey = await this.getDeviceFactor(); | ||
| if (!deviceFactorKey && this.state.factorKey && this.state.tssShareIndex === TssShareType.DEVICE) { | ||
| await this.setDeviceFactor(this.state.factorKey); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| log.warn("failed to authorize session", err); | ||
| log.warn("failed to authorize session please use new", err); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1230,7 +1257,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit { | |
| postboxKeyNodeIndexes: postboxKeyNodeIndexes || [], | ||
| factorKey: factorKey?.toString("hex"), | ||
| tssShareIndex: tssShareIndex as number, | ||
| tssPubKey: Buffer.from(tssPubKey).toString("hex"), | ||
| tssPubKey: tssPubKey.toString("hex"), | ||
| signatures: this.signatures, | ||
| userInfo, | ||
| }; | ||
|
|
@@ -1507,7 +1534,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit { | |
| clientXCoord, | ||
| clientShareAdjustedHex, | ||
| pubKeyHex, | ||
| data, | ||
| new Uint8Array(data), | ||
| serverCoefficientsHex, | ||
| this.socketTransports | ||
| ); | ||
|
|
||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arch1995 should double check this. I'm not familiar with
sessionManager.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert the changes as finalizeTkey will create new session