Skip to content

Commit

Permalink
fix: use uint8array instead of buffer (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorency authored Dec 15, 2023
1 parent 50ca714 commit 0f7fde6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
14 changes: 7 additions & 7 deletions lib/ghostcloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ import {
AminoTypes,
calculateFee,
Coin,
GasPrice,
SigningStargateClient,
} from "@cosmjs/stargate"
import { hexToBytes } from "@metamask/utils"

async function createSigner(pk: Buffer) {
async function createSigner(pk: Uint8Array) {
const getSignerFromKey = async (): Promise<OfflineDirectSigner> => {
return DirectSecp256k1Wallet.fromKey(pk, GHOSTCLOUD_ADDRESS_PREFIX)
}
return await getSignerFromKey()
}
async function createStargateSigningClient(pk: Buffer) {
async function createStargateSigningClient(pk: Uint8Array) {
const signer = await createSigner(pk)
const protoRegistry: ReadonlyArray<[string, GeneratedType]> = [
...cosmosProtoRegistry,
Expand All @@ -71,7 +71,7 @@ async function createStargateSigningClient(pk: Buffer) {

// Create a client for sending transactions to Ghostcloud RPC endpoint
// The transaction signer is the given private key
async function createGhostcloudRpcClient(pk: Buffer) {
async function createGhostcloudRpcClient(pk: Uint8Array) {
return await createStargateSigningClient(pk)
}

Expand Down Expand Up @@ -115,7 +115,7 @@ export const useCreateDeployment = () => {
}

const client = await createGhostcloudRpcClient(
Buffer.from(await store.getPrivateKey(), "hex"),
hexToBytes(await store.getPrivateKey()),
)
const msg = await createDeploymentMsg(data, creator)
const gasEstimation = await client.simulate(creator, [msg], "")
Expand Down Expand Up @@ -185,7 +185,7 @@ export const useUpdateDeployment = () => {
}

const client = await createGhostcloudRpcClient(
Buffer.from(await store.getPrivateKey(), "hex"),
hexToBytes(await store.getPrivateKey()),
)
const msg = await updateDeploymentMsg(data, creator)
const gasEstimation = await client.simulate(creator, [msg], "")
Expand Down Expand Up @@ -236,7 +236,7 @@ export const useRemoveDeployment = () => {
}

const client = await createGhostcloudRpcClient(
Buffer.from(await store.getPrivateKey(), "hex"),
hexToBytes(await store.getPrivateKey()),
)
const msg = await removeDeploymentMsg(name, creator)
const gasEstimation = await client.simulate(creator, [msg], "")
Expand Down
3 changes: 2 additions & 1 deletion store/web3-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IProvider } from "@web3auth/base"
import { Web3Auth } from "@web3auth/modal"
import { GHOSTCLOUD_ADDRESS_PREFIX } from "../config/ghostcloud-chain"
import { DirectSecp256k1Wallet } from "@cosmjs/proto-signing"
import { hexToBytes } from "@metamask/utils"

interface Web3AuthState {
provider: IProvider | null
Expand Down Expand Up @@ -42,7 +43,7 @@ const useWeb3AuthStore = create<Web3AuthState>((set, get) => ({
if (buffer === null) {
return null
}
const privateKey = Buffer.from(buffer, "hex")
const privateKey = hexToBytes(buffer)
const walletPromise = await DirectSecp256k1Wallet.fromKey(
privateKey,
GHOSTCLOUD_ADDRESS_PREFIX,
Expand Down

0 comments on commit 0f7fde6

Please sign in to comment.