Skip to content

Commit

Permalink
working with up to date lib
Browse files Browse the repository at this point in the history
  • Loading branch information
moe-dev committed May 7, 2024
1 parent a1b3a24 commit dc1ff11
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
30 changes: 13 additions & 17 deletions Auth.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'react-native-get-random-values'
import React, { useState, useEffect } from 'react';
import { View, Text, TextInput, Button, StyleSheet } from 'react-native';
import {signWithApiKey} from '@turnkey/api-key-stamper'
import {generateTargetKey, decryptBundle, stringToBase64urlString, base64StringToBase64UrlEncodedString, uint8arrayToHexString, getPublicKey, uint8arrayFromHexString} from '@turnkey/crypto'
import {generateP256KeyPair, decryptBundle, getPublicKey, uint8ArrayFromHexString} from '@turnkey/crypto' // TODO: uint8arrayFromHexString Should live in /encoding
import {stringToBase64urlString, uint8ArrayToHexString} from '@turnkey/encoding'

const AuthScreen = () => {
const [embeddedKey, setEmbeddedKey] = useState<any>(null);
Expand All @@ -17,39 +19,32 @@ const AuthScreen = () => {

const handleGenerateKey = async () => {
try {
const key = await generateTargetKey();
const key = generateP256KeyPair();
setEmbeddedKey(key.privateKey);
const targetPubHex = uint8arrayToHexString(key.publicKey);
const targetPubHex = key.publicKeyUncompressed;
console.log(targetPubHex)
setPublicKey(targetPubHex);
setPublicKey(targetPubHex!);
} catch (error) {
console.error('Error generating key:', error);
}
};

const handleInjectBundle = async () => {
const handleInjectBundle = () => {
try{
const decryptedData = await decryptBundle(credentialBundle, embeddedKey) as Uint8Array
const decryptedData = decryptBundle(credentialBundle, embeddedKey) as Uint8Array

setDecryptedData(uint8arrayToHexString(decryptedData));
setDecryptedData(uint8ArrayToHexString(decryptedData));
}
catch (error) {
console.error('Error injecting bundle:', error);
}
};

const handleStampPayload = async () => { //TODO
const handleStampPayload = async () => {
try {
const content = JSON.stringify(payload)
const publicKey = uint8arrayToHexString(getPublicKey(uint8arrayFromHexString(decryptedData), true))
const publicKey = uint8ArrayToHexString(getPublicKey(uint8ArrayFromHexString(decryptedData), true))
const privateKey = decryptedData
const signature = await signWithApiKey({content, publicKey, privateKey} )
// // const rawSignature = await signPayload(credential, payload);
// const rawSignature: Uint8Array = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
// const derSignature = await convertEcdsaIeee1363ToDer(rawSignature);
console.log(payload)
console.log(content)
console.log(signature)
const signature = await signWithApiKey({content: payload, publicKey, privateKey} )
setSignature(signature);
const stamp = {
publicKey: publicKey,
Expand All @@ -62,6 +57,7 @@ const AuthScreen = () => {
}
};


return (
<View style={styles.container}>
<Text>Email Authentication</Text>
Expand Down
30 changes: 25 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
"@react-navigation/native": "^6.1.17",
"@react-navigation/native-stack": "^6.9.26",
"@turnkey/api-key-stamper": "^0.4.0",
"@turnkey/crypto": "https://pkg.csb.dev/tkhq/sdk/commit/a0979f21/@turnkey/crypto",
"@turnkey/crypto": "https://pkg.csb.dev/tkhq/sdk/commit/cd6088ad/@turnkey/crypto",
"@turnkey/http": "^2.7.0",
"@turnkey/react-native-passkey-stamper": "^0.1.0",
"crypto-js": "^4.2.0",
"expo": "^50.0.17",
"expo-status-bar": "~1.11.1",
"react": "18.2.0",
"react-native": "0.73.6",
"react-native-get-random-values": "^1.11.0",
"react-native-passkey": "^2.1.1",
"react-native-safe-area-context": "4.8.2",
"react-native-screens": "~3.29.0"
Expand Down

0 comments on commit dc1ff11

Please sign in to comment.