-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
172 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.developer.associated-appclip-app-identifiers</key> | ||
<array> | ||
<string>5B29R5LYHQ.com.warroom.proofofpassport.Clip</string> | ||
</array> | ||
<key>com.apple.developer.associated-domains</key> | ||
<array> | ||
<string>appclips:openpassport.app</string> | ||
<string>appclips:staging.openpassport.app</string> | ||
<string>appclips:appclip.openpassport.app</string> | ||
<string>applinks:proofofpassport-merkle-tree.xyz</string> | ||
</array> | ||
<key>com.apple.developer.nfc.readersession.formats</key> | ||
<array> | ||
<string>TAG</string> | ||
</array> | ||
<key>com.apple.security.device.camera</key> | ||
<true/> | ||
</dict> | ||
</plist> |
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 |
---|---|---|
@@ -1,94 +1,152 @@ | ||
import { NativeModules, Platform } from "react-native"; | ||
import { NativeModules, Platform, Linking } from "react-native"; | ||
// import { AppType, reconstructAppType } from "../../../common/src/utils/appType"; | ||
import useNavigationStore from '../stores/navigationStore'; | ||
import { getCircuitName, parseDSC } from "../../../common/src/utils/certificates/handleCertificate"; | ||
import useUserStore from "../stores/userStore"; | ||
import { downloadZkey } from "./zkeyDownload"; | ||
import msgpack from "msgpack-lite"; | ||
import pako from "pako"; | ||
import { OpenPassportApp } from "../../../common/src/utils/appType"; | ||
import { Mode, OpenPassportApp } from "../../../common/src/utils/appType"; | ||
|
||
const parseUrlParams = (url: string): Map<string, string> => { | ||
const [, queryString] = url.split('?'); | ||
const params = new Map<string, string>(); | ||
if (queryString) { | ||
queryString.split('&').forEach(pair => { | ||
const [key, value] = pair.split('='); | ||
params.set(key, decodeURIComponent(value)); | ||
}); | ||
} | ||
return params; | ||
}; | ||
|
||
export const scanQRCode = () => { | ||
const { toast, setSelectedApp, setSelectedTab } = useNavigationStore.getState(); | ||
|
||
if (Platform.OS === 'ios') { | ||
if (NativeModules.QRScannerBridge && NativeModules.QRScannerBridge.scanQRCode) { | ||
NativeModules.QRScannerBridge.scanQRCode() | ||
.then((result: string) => { | ||
handleQRCodeScan(result, toast, setSelectedApp, setSelectedTab); | ||
}) | ||
.catch((error: any) => { | ||
console.error('QR Scanner Error:', error); | ||
Linking.getInitialURL().then((url) => { | ||
if (url) { | ||
handleUniversalLink(url); | ||
} else { | ||
if (Platform.OS === 'ios') { | ||
console.log("Scanning QR code on iOS without Universal Link"); | ||
|
||
const qrScanner = NativeModules.QRScannerBridge; | ||
if (qrScanner && qrScanner.scanQRCode) { | ||
qrScanner.scanQRCode() | ||
.then((result: string) => { | ||
const params = parseUrlParams(result); | ||
const encodedData = params.get('data'); | ||
handleQRCodeScan(encodedData as string, toast, setSelectedApp, setSelectedTab); | ||
}) | ||
.catch((error: any) => { | ||
console.error('QR Scanner Error:', error); | ||
toast.show('Error', { | ||
message: 'Failed to scan QR code', | ||
type: 'error', | ||
}); | ||
}); | ||
} else { | ||
console.error('QR Scanner module not found for iOS'); | ||
toast.show('Error', { | ||
message: 'Failed to scan QR code', | ||
message: 'QR Scanner not available', | ||
type: 'error', | ||
}); | ||
}); | ||
} else { | ||
console.error('QR Scanner module not found for iOS'); | ||
toast.show('Error', { | ||
message: 'QR Scanner not available', | ||
type: 'error', | ||
}); | ||
} | ||
} else if (Platform.OS === 'android') { | ||
if (NativeModules.QRCodeScanner && NativeModules.QRCodeScanner.scanQRCode) { | ||
NativeModules.QRCodeScanner.scanQRCode() | ||
.then((result: string) => { | ||
handleQRCodeScan(result, toast, setSelectedApp, setSelectedTab); | ||
}) | ||
.catch((error: any) => { | ||
console.error('QR Scanner Error:', error); | ||
} | ||
} else if (Platform.OS === 'android') { | ||
const qrScanner = NativeModules.QRCodeScanner; | ||
if (qrScanner && qrScanner.scanQRCode) { | ||
qrScanner.scanQRCode() | ||
.then((result: string) => { | ||
handleQRCodeScan(result, toast, setSelectedApp, setSelectedTab); | ||
}) | ||
.catch((error: any) => { | ||
console.error('QR Scanner Error:', error); | ||
toast.show('Error', { | ||
message: 'Failed to scan QR code', | ||
type: 'error', | ||
}); | ||
}); | ||
} else { | ||
console.error('QR Scanner module not found for Android'); | ||
toast.show('Error', { | ||
message: 'Failed to scan QR code', | ||
message: 'QR Scanner not available', | ||
type: 'error', | ||
}); | ||
}); | ||
} else { | ||
console.error('QR Scanner module not found for Android'); | ||
toast.show('Error', { | ||
message: 'QR Scanner not available', | ||
type: 'error', | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
}).catch(err => { | ||
console.error('An error occurred while getting initial URL', err); | ||
toast.show('Error', { | ||
message: 'Failed to process initial link', | ||
type: 'error', | ||
}); | ||
}); | ||
}; | ||
|
||
const handleQRCodeScan = (result: string, toast: any, setSelectedApp: any, setSelectedTab: any) => { | ||
try { | ||
console.log(result); | ||
const decodedResult = atob(result); | ||
const uint8Array = new Uint8Array(decodedResult.split('').map(char => char.charCodeAt(0))); | ||
const decompressedData = pako.inflate(uint8Array); | ||
const unpackedData = msgpack.decode(decompressedData); | ||
console.log(unpackedData); | ||
const openPassportApp: OpenPassportApp = unpackedData; | ||
setSelectedApp(openPassportApp); | ||
|
||
const dsc = useUserStore.getState().passportData.dsc; | ||
const sigAlgName = parseDSC(dsc!); | ||
if (openPassportApp.mode == 'vc_and_disclose') { | ||
downloadZkey('vc_and_disclose'); | ||
} | ||
else { | ||
const circuitName = getCircuitName("prove", sigAlgName.signatureAlgorithm, sigAlgName.hashFunction); | ||
downloadZkey(circuitName as any); | ||
} | ||
|
||
const circuitName = openPassportApp.mode === 'vc_and_disclose' | ||
? 'vc_and_disclose' | ||
: getCircuitName("prove" as Mode, sigAlgName.signatureAlgorithm, sigAlgName.hashFunction); | ||
downloadZkey(circuitName as any); | ||
|
||
setSelectedTab("prove"); | ||
toast.show('✅', { | ||
message: "QR code scanned", | ||
customData: { | ||
type: "success", | ||
}, | ||
}) | ||
|
||
|
||
}); | ||
} catch (error) { | ||
console.error('Error parsing QR code result:', error); | ||
toast.show('Try again', { | ||
message: "Error reading QR code", | ||
message: "Error reading QR code: " + (error as Error).message, | ||
customData: { | ||
type: "info", | ||
type: "error", | ||
}, | ||
}) | ||
}); | ||
} | ||
}; | ||
|
||
const handleUniversalLink = (url: string) => { | ||
const { toast, setSelectedApp, setSelectedTab } = useNavigationStore.getState(); | ||
const params = parseUrlParams(url); | ||
const encodedData = params.get('data'); | ||
console.log("Encoded data:", encodedData); | ||
if (encodedData) { | ||
handleQRCodeScan(encodedData, toast, setSelectedApp, setSelectedTab); | ||
} else { | ||
console.error('No data found in the Universal Link'); | ||
toast.show('Error', { | ||
message: 'Invalid link', | ||
type: 'error', | ||
}); | ||
} | ||
}; | ||
}; | ||
|
||
export const setupUniversalLinkListener = () => { | ||
Linking.getInitialURL().then((url) => { | ||
if (url) { | ||
handleUniversalLink(url); | ||
} | ||
}); | ||
|
||
const linkingEventListener = Linking.addEventListener('url', ({ url }) => { | ||
handleUniversalLink(url); | ||
}); | ||
|
||
return () => { | ||
linkingEventListener.remove(); | ||
}; | ||
}; |
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