Skip to content

Commit

Permalink
♻️ Use keccak256 module instead of jsdelivr
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Dec 14, 2024
1 parent a21f956 commit 95d6bed
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 17 deletions.
6 changes: 3 additions & 3 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@
</template>
<script setup lang="ts">
import { bech32 } from 'bech32'
import { Buffer } from 'node:buffer'
import keccak256 from 'keccak256'
import { Buffer } from 'buffer'
declare global {
interface Window {
keplr?: any;
ethereum?: any;
keccak256?: any;
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ const convertedEvmAddress = computed(() => {
if (convertedWords.value.length === 0) return ''
const data = bech32.fromWords(convertedWords.value)
const address = Buffer.from(data).toString('hex');
const hash = window.keccak256(address).toString('hex');
const hash = keccak256(address).toString('hex');
// Apply checksum
let checksumAddress = '0x';
for (let i = 0; i < address.length; i++) {
Expand Down
43 changes: 29 additions & 14 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
import path from "path";

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
app: {
head: {
title: 'Bech32 Wallet Address Prefix Web Converter',
title: "Bech32 Wallet Address Prefix Web Converter",
meta: [
{ name: 'og:title', content: 'Bech32 Wallet Address Prefix Web Converter' },
{ name: 'description', content: 'Convert between Cosmos(cosmos1), Ethereum(0x) and different cosmos-based chain using bech32 address prefixes.' }
{
name: "og:title",
content: "Bech32 Wallet Address Prefix Web Converter",
},
{
name: "description",
content:
"Convert between Cosmos(cosmos1), Ethereum(0x) and different cosmos-based chain using bech32 address prefixes.",
},
],
link: [
{ rel: 'preload', href: 'https://cdn.jsdelivr.net/npm/keccak256@latest/keccak256.js', as: 'script' },
{ rel: 'preload', href: 'https://www.googletagmanager.com/gtag/js?id=G-J481P5HG5T', as: 'script' },
],
script: [
{ src: 'https://cdn.jsdelivr.net/npm/keccak256@latest/keccak256.js', body: true },
{
rel: "preload",
href: "https://www.googletagmanager.com/gtag/js?id=G-J481P5HG5T",
as: "script",
},
],
},
},
modules: [
'nuxt-gtag',
'@vueuse/nuxt',
],
modules: ["nuxt-gtag", "@vueuse/nuxt"],
gtag: {
id: "G-J481P5HG5T",
},
compatibilityDate: '2024-04-03',
plugins: ["~/plugins/node.client.ts"],
alias: {
"readable-stream": path.resolve(__dirname, "node_modules/readable-stream"),
"process/": path.resolve(
__dirname,
"node_modules/unenv/runtime/node/process"
),
events: path.resolve(__dirname, "node_modules/events"),
},
compatibilityDate: "2024-04-03",
devtools: { enabled: true },
experimental: {
clientNodeCompat: true,
},
})
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@vueuse/core": "^11.2.0",
"@vueuse/nuxt": "^11.2.0",
"bech32": "^2.0.0",
"keccak256": "^1.0.6",
"nuxt": "^3.12.3",
"nuxt-gtag": "^3.0.1",
"vue": "latest"
Expand Down
5 changes: 5 additions & 0 deletions plugins/node.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Buffer } from 'buffer'

globalThis.Buffer = Buffer

export default defineNuxtPlugin({})
33 changes: 33 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,11 @@ birpc@^0.2.17:
resolved "https://registry.yarnpkg.com/birpc/-/birpc-0.2.17.tgz#d0bdb90d4d063061156637f03b7b0adea1779734"
integrity sha512-+hkTxhot+dWsLpp3gia5AkVHIsKlZybNT5gIYiDlNzJrmYPcTM9k5/w2uaj3IPpd7LlEYpmCj4Jj1nC41VhDFg==

bn.js@^5.2.0:
version "5.2.1"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.1.tgz#0bc527a6a0d18d0aa8d5b0538ce4a77dccfa7b70"
integrity sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ==

boolbase@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e"
Expand Down Expand Up @@ -3492,6 +3497,24 @@ jsonfile@^6.0.1:
optionalDependencies:
graceful-fs "^4.1.6"

keccak256@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/keccak256/-/keccak256-1.0.6.tgz#dd32fb771558fed51ce4e45a035ae7515573da58"
integrity sha512-8GLiM01PkdJVGUhR1e6M/AvWnSqYS0HaERI+K/QtStGDGlSTx2B1zTqZk4Zlqu5TxHJNTxWAdP9Y+WI50OApUw==
dependencies:
bn.js "^5.2.0"
buffer "^6.0.3"
keccak "^3.0.2"

keccak@^3.0.2:
version "3.0.4"
resolved "https://registry.yarnpkg.com/keccak/-/keccak-3.0.4.tgz#edc09b89e633c0549da444432ecf062ffadee86d"
integrity sha512-3vKuW0jV8J3XNTzvfyicFR5qvxrSAGl7KIhvgOu5cmWwM7tZRj3fMbj/pfIf4be7aznbc+prBWGjywox/g2Y6Q==
dependencies:
node-addon-api "^2.0.0"
node-gyp-build "^4.2.0"
readable-stream "^3.6.0"

kleur@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
Expand Down Expand Up @@ -3874,6 +3897,11 @@ nitropack@^2.9.7:
unstorage "^1.10.2"
unwasm "^0.3.9"

node-addon-api@^2.0.0:
version "2.0.2"
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-2.0.2.tgz#432cfa82962ce494b132e9d72a15b29f71ff5d32"
integrity sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==

node-addon-api@^7.0.0:
version "7.1.1"
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-7.1.1.tgz#1aba6693b0f255258a049d621329329322aad558"
Expand All @@ -3896,6 +3924,11 @@ node-forge@^1.3.1:
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-1.3.1.tgz#be8da2af243b2417d5f646a770663a92b7e9ded3"
integrity sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==

node-gyp-build@^4.2.0:
version "4.8.4"
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.8.4.tgz#8a70ee85464ae52327772a90d66c6077a900cfc8"
integrity sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==

node-gyp-build@^4.2.2:
version "4.8.1"
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.8.1.tgz#976d3ad905e71b76086f4f0b0d3637fe79b6cda5"
Expand Down

0 comments on commit 95d6bed

Please sign in to comment.