From dc1ff11cc4c1a7e5c7b3b32f6eed90ac1d27a220 Mon Sep 17 00:00:00 2001 From: Mohammad Cheikh Date: Tue, 7 May 2024 18:10:25 -0400 Subject: [PATCH] working with up to date lib --- Auth.tsx | 30 +++++++++++++----------------- package-lock.json | 30 +++++++++++++++++++++++++----- package.json | 3 ++- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/Auth.tsx b/Auth.tsx index 18d9ee6..0f76b6e 100644 --- a/Auth.tsx +++ b/Auth.tsx @@ -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(null); @@ -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, @@ -62,6 +57,7 @@ const AuthScreen = () => { } }; + return ( Email Authentication diff --git a/package-lock.json b/package-lock.json index 8488d17..8e3a212 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "@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", @@ -19,6 +19,7 @@ "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" @@ -7580,16 +7581,18 @@ }, "node_modules/@turnkey/crypto": { "version": "0.1.0", - "resolved": "https://pkg.csb.dev/tkhq/sdk/commit/a0979f21/@turnkey/crypto", - "integrity": "sha512-IbwdNtec326Tb7vuRjjpSMxICUaUAvCVdTN6pMG60d3L5dShaKRO2Cf7DhdHmBsblaXGgO5KHDETj4dEa2mrnA==", + "resolved": "https://pkg.csb.dev/tkhq/sdk/commit/cd6088ad/@turnkey/crypto", + "integrity": "sha512-gPrkwyfmx9xGqCHJ2y2FN6nDs/kkyuN0TKBUjDbbGhkUm3ZWd5v//66Lfv5SzzbS+c+SLS98vsrpzV9iVLVLww==", "license": "Apache-2.0", "dependencies": { "@noble/ciphers": "^0.5.3", "@noble/curves": "^1.4.0", "@noble/hashes": "^1.4.0", + "@turnkey/encoding": "https://pkg.csb.dev/tkhq/sdk/commit/cd6088ad/@turnkey/encoding", "bs58check": "^3.0.1", "jest": "^29.6.3", "react-native": "^0.74.0", + "react-native-get-random-values": "^1.11.0", "react-native-quick-base64": "^2.1.2", "typescript": "5.0.4" }, @@ -8352,8 +8355,9 @@ }, "node_modules/@turnkey/encoding": { "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@turnkey/encoding/-/encoding-0.1.0.tgz", - "integrity": "sha512-aLmLrWtvV1k9UyGzuzMpBFdwleCH8VpzXIriusVMrFLiQp+4uHCS9cwrEG1glg3207ewWFDtvgj31qLoJS29pg==", + "resolved": "https://pkg.csb.dev/tkhq/sdk/commit/cd6088ad/@turnkey/encoding", + "integrity": "sha512-l9gx/+6IU01a4oiOUXUqcH1lb7WsVP4yYnD54MpI4wbgJKsrNB+WbRi95vLjMP3kyMK7F2CDi1XYbsZzkik2KA==", + "license": "Apache-2.0", "engines": { "node": ">=18.0.0" } @@ -11288,6 +11292,11 @@ "resolved": "https://registry.npmjs.org/expo-status-bar/-/expo-status-bar-1.11.1.tgz", "integrity": "sha512-ddQEtCOgYHTLlFUe/yH67dDBIoct5VIULthyT3LRJbEwdpzAgueKsX2FYK02ldh440V87PWKCamh7R9evk1rrg==" }, + "node_modules/fast-base64-decode": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fast-base64-decode/-/fast-base64-decode-1.0.0.tgz", + "integrity": "sha512-qwaScUgUGBYeDNRnbc/KyllVU88Jk1pRHPStuF/lO7B0/RTRLj7U0lkdTAutlBblY08rwZDff6tNU9cjv6j//Q==" + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -16680,6 +16689,17 @@ "@babel/runtime": "^7.20.6" } }, + "node_modules/react-native-get-random-values": { + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/react-native-get-random-values/-/react-native-get-random-values-1.11.0.tgz", + "integrity": "sha512-4BTbDbRmS7iPdhYLRcz3PGFIpFJBwNZg9g42iwa2P6FOv9vZj/xJc678RZXnLNZzd0qd7Q3CCF6Yd+CU2eoXKQ==", + "dependencies": { + "fast-base64-decode": "^1.0.0" + }, + "peerDependencies": { + "react-native": ">=0.56" + } + }, "node_modules/react-native-passkey": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/react-native-passkey/-/react-native-passkey-2.1.1.tgz", diff --git a/package.json b/package.json index 3e11819..7cdb27a 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "@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", @@ -20,6 +20,7 @@ "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"