implement wallet address function
This commit is contained in:
parent
9c8ca28e2f
commit
ce4615d407
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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(() => {
|
||||
|
|
Loading…
Reference in New Issue