implement wallet address function

This commit is contained in:
Michele Balistreri 2024-10-02 09:55:12 +02:00
parent 9c8ca28e2f
commit ce4615d407
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
3 changed files with 24 additions and 1 deletions

7
package-lock.json generated
View File

@ -10,6 +10,7 @@
"dependencies": {
"@noble/hashes": "^1.5.0",
"@react-native-async-storage/async-storage": "^2.0.0",
"bech32": "^2.0.0",
"react": "18.3.1",
"react-native": "0.75.3",
"react-native-modal": "^13.0.1",
@ -5709,6 +5710,12 @@
],
"license": "MIT"
},
"node_modules/bech32": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/bech32/-/bech32-2.0.0.tgz",
"integrity": "sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg==",
"license": "MIT"
},
"node_modules/bl": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz",

View File

@ -13,6 +13,7 @@
"dependencies": {
"@noble/hashes": "^1.5.0",
"@react-native-async-storage/async-storage": "^2.0.0",
"bech32": "^2.0.0",
"react": "18.3.1",
"react-native": "0.75.3",
"react-native-modal": "^13.0.1",

View File

@ -2,6 +2,10 @@ import {FC, useEffect, useState } from "react";
import { SafeAreaView, StyleSheet, Text, View } from "react-native";
import Button from "../Button";
import { Camera, useCameraDevice, useCameraPermission, useCodeScanner } from "react-native-vision-camera";
import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
import { bech32 } from "bech32";
import { ripemd160 } from "@noble/hashes/ripemd160";
import { sha256 } from "@noble/hashes/sha256";
enum HomeSteps {
Home,
@ -41,7 +45,18 @@ const HomeScreen: FC<HomeScreenProps> = props => {
});
const walletAddress = () => {
return walletKey;
var pubkey = hexToBytes(walletKey);
if (pubkey[0] == 0x04 && (pubkey.length == 65)) {
pubkey[0] = 0x02 | (pubkey[64] & 1);
pubkey = pubkey.slice(0, 33);
}
const hash = ripemd160(sha256(pubkey));
var words = bech32.toWords(hash);
words.unshift(0);
return bech32.encode('bc', words);
}
useEffect(() => {