-
Notifications
You must be signed in to change notification settings - Fork 180
introduce usePrepareDocumentProof in mobile SDK #1176
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,9 +2,10 @@ | |||||||||||||||||||||||||||||||||||||||
| // SPDX-License-Identifier: BUSL-1.1 | ||||||||||||||||||||||||||||||||||||||||
| // NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| import { createContext, type PropsWithChildren, useContext, useMemo } from 'react'; | ||||||||||||||||||||||||||||||||||||||||
| import { createContext, type PropsWithChildren, useContext, useEffect, useMemo } from 'react'; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| import { createSelfClient } from './client'; | ||||||||||||||||||||||||||||||||||||||||
| import { loadSelectedDocument } from './documents/utils'; | ||||||||||||||||||||||||||||||||||||||||
| import { SdkEvents } from './types/events'; | ||||||||||||||||||||||||||||||||||||||||
| import type { Adapters, Config, SelfClient } from './types/public'; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -56,6 +57,35 @@ export function SelfClientProvider({ | |||||||||||||||||||||||||||||||||||||||
| return <SelfClientContext.Provider value={client}>{children}</SelfClientContext.Provider>; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| export function usePrepareDocumentProof() { | ||||||||||||||||||||||||||||||||||||||||
| const selfClient = useSelfClient(); | ||||||||||||||||||||||||||||||||||||||||
| const { useProvingStore } = selfClient; | ||||||||||||||||||||||||||||||||||||||||
| const currentState = useProvingStore(state => state.currentState); | ||||||||||||||||||||||||||||||||||||||||
| const init = useProvingStore(state => state.init); | ||||||||||||||||||||||||||||||||||||||||
| const setUserConfirmed = useProvingStore(state => state.setUserConfirmed); | ||||||||||||||||||||||||||||||||||||||||
| const isReadyToProve = currentState === 'ready_to_prove'; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||
| const initializeProving = async () => { | ||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||
| const selectedDocument = await loadSelectedDocument(selfClient); | ||||||||||||||||||||||||||||||||||||||||
| if (selectedDocument?.data?.documentCategory === 'aadhaar') { | ||||||||||||||||||||||||||||||||||||||||
| init(selfClient, 'register'); | ||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||
| init(selfClient, 'dsc'); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||
| console.error('Error loading selected document:', error); | ||||||||||||||||||||||||||||||||||||||||
| init(selfClient, 'dsc'); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+73
to
+80
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. Await init call - init(selfClient, 'register');
+ await init(selfClient, 'register');
} else {
- init(selfClient, 'dsc');
+ await init(selfClient, 'dsc');
}
} catch (error) {
- console.error('Error loading selected document:', error);
- init(selfClient, 'dsc');
+ console.error('Error loading selected document:', error instanceof Error ? error.message : 'unknown');
+ await init(selfClient, 'dsc');📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Collaborator
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. this code has only been moved, can be tackled separately (if needed)
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. @shazarre, understood! Since this is moved code, it makes sense to keep the refactoring focused and address the async handling in a follow-up if needed. Thanks for clarifying! 👍 |
||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| initializeProving(); | ||||||||||||||||||||||||||||||||||||||||
| }, [init, selfClient]); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| return { setUserConfirmed, isReadyToProve }; | ||||||||||||||||||||||||||||||||||||||||
|
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. Bug: Stale Closures and Missing DependenciesThe
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. you trippin. |
||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * Retrieves the current {@link SelfClient} from context. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
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.
Avoid logging PII
Line 89 logs the full
errorobject fromloadSelectedDocument. That error can include passport metadata or other sensitive identifiers, which would then land in device logs—clear violation of our no-PII logging rule for SDK code. Please log only a sanitized message (e.g., the generic string or a whitelisted code) instead of the entire object.📝 Committable suggestion
🤖 Prompt for AI Agents
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.
this code has only been moved, can be tackled separately
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.
@shazarre, understood—I'll defer this for now since it's pre-existing code. Would you like me to open a follow-up issue to track the PII logging cleanup separately?