Observed since 20 Oct, 22:43 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
@0xbojack/fhevm-vue
Vue 3 composables for FHEVM SDK
Vue 3 composables for FHEVM SDK - Build privacy-preserving dApps with Fully Homomorphic Encryption.
npm install @fhevm/vue @fhevm/core ethers
# or
pnpm add @fhevm/vue @fhevm/core ethers
# or
yarn add @fhevm/vue @fhevm/core ethers
Install the FHEVM plugin in your Vue app:
// main.ts
import { createApp } from 'vue';
import { createFhevm, IndexedDBStorage } from '@fhevm/vue';
import App from './App.vue';
const app = createApp(App);
const fhevm = createFhevm({
config: { storage: new IndexedDBStorage() }
});
app.use(fhevm);
app.mount('#app');
<script setup lang="ts">
import { useInit } from '@fhevm/vue';
import { BrowserProvider } from 'ethers';
import { onMounted } from 'vue';
const { init, status, error, isReady } = useInit();
onMounted(async () => {
const provider = new BrowserProvider(window.ethereum);
await init({ provider });
});
</script>
<template>
<div v-if="status === 'loading'">Initializing FHEVM...</div>
<div v-else-if="error">Error: {{ error.message }}</div>
<div v-else-if="isReady">FHEVM Ready ✅</div>
<button v-else @click="init({ provider })">Initialize</button>
</template>
<script setup lang="ts">
import { useEncrypt, useStatus } from '@fhevm/vue';
const { encrypt, data, isLoading, error } = useEncrypt();
const { isReady } = useStatus();
const handleEncrypt = async () => {
await encrypt({
value: 42,
type: 'euint32',
contractAddress: '0x...',
userAddress: '0x...',
});
};
</script>
<template>
<div v-if="!isReady">Please initialize FHEVM first</div>
<div v-else>
<button @click="handleEncrypt" :disabled="isLoading">
{{ isLoading ? 'Encrypting...' : 'Encrypt Value' }}
</button>
<div v-if="error">Error: {{ error.message }}</div>
<pre v-if="data">{{ JSON.stringify(data, null, 2) }}</pre>
</div>
</template>
<script setup lang="ts">
import { useDecrypt } from '@fhevm/vue';
import { BrowserProvider } from 'ethers';
const { decrypt, data, isLoading, error } = useDecrypt();
const handleDecrypt = async () => {
const provider = new BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
await decrypt(
[{ handle: '0x...', contractAddress: '0x...' }],
signer
);
};
</script>
<template>
<button @click="handleDecrypt" :disabled="isLoading">
{{ isLoading ? 'Decrypting...' : 'Decrypt' }}
</button>
<div v-if="data">Result: {{ JSON.stringify(data) }}</div>
<div v-if="error">Error: {{ error.message }}</div>
</template>
createFhevm(options?)Create the FHEVM Vue plugin.
Parameters:
options.config?: FhevmConfig - Optional FHEVM configurationReturns: Vue plugin object
Example:
import { createFhevm, IndexedDBStorage } from '@fhevm/vue';
const fhevm = createFhevm({
config: { storage: new IndexedDBStorage() }
});
app.use(fhevm);
useInit()Initialize the FHEVM instance.
Returns:
init: (params: InitParams) => Promise<FhevmInstance | null> - Initialize functionstatus: Ref<FhevmStatus> - Current statusinstance: Ref<FhevmInstance | null> - FHEVM instanceerror: Ref<Error | null> - Error if initialization failedcancel: () => void - Cancel ongoing initializationisIdle: Ref<boolean> - Whether status is 'idle'isLoading: Ref<boolean> - Whether status is 'loading'isReady: Ref<boolean> - Whether status is 'ready'isError: Ref<boolean> - Whether status is 'error'Example:
<script setup>
const { init, status, isReady, cancel } = useInit();
// Initialize
await init({ provider });
// Or with RPC URL
await init({ provider: 'http://localhost:8545', chainId: 31337 });
// Cancel if needed
cancel();
</script>
useEncrypt()Encrypt data for on-chain computation.
Returns:
encrypt: (params: EncryptParams) => Promise<EncryptResult | null> - Encrypt functiondata: Ref<EncryptResult | null> - Encrypted resultisLoading: Ref<boolean> - Loading stateerror: Ref<Error | null> - Error if encryption failedreset: () => void - Reset stateSupported Types:
ebool - Encrypted booleaneuint8, euint16, euint32, euint64, euint128, euint256 - Encrypted unsigned integerseaddress - Encrypted addressExample:
<script setup>
const { encrypt, data, isLoading, reset } = useEncrypt();
await encrypt({
value: 100,
type: 'euint32',
contractAddress: '0x...',
userAddress: '0x...',
});
// Reset state
reset();
</script>
useDecrypt()Decrypt encrypted data (requires user signature).
Returns:
decrypt: (requests: DecryptRequest[], signer: JsonRpcSigner) => Promise<DecryptResult | null> - Decrypt functiondata: Ref<DecryptResult | null> - Decrypted resultisLoading: Ref<boolean> - Loading stateerror: Ref<Error | null> - Error if decryption failedreset: () => void - Reset stateExample:
<script setup>
const { decrypt, data, isLoading } = useDecrypt();
const provider = new BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
await decrypt(
[
{ handle: '0x...', contractAddress: '0x...' },
{ handle: '0x...', contractAddress: '0x...' },
],
signer
);
</script>
useStatus()Get current status with reactive computed properties.
Returns:
status: Ref<FhevmStatus> - Current statusisIdle: Ref<boolean> - Whether status is 'idle'isLoading: Ref<boolean> - Whether status is 'loading'isReady: Ref<boolean> - Whether status is 'ready'isError: Ref<boolean> - Whether status is 'error'Example:
<script setup>
const { status, isReady, isLoading, isError } = useStatus();
</script>
<template>
<Spinner v-if="isLoading" />
<Error v-else-if="isError" />
<App v-else-if="isReady" />
</template>
usePublicKey()Get the public key for encryption (only available after initialization).
Returns:
publicKey: Ref<string | null> - Public key (null if not ready)error: Ref<Error | null> - Error if getting public key failedExample:
<script setup>
const { publicKey, error } = usePublicKey();
</script>
<template>
<div v-if="publicKey">Public key: {{ publicKey }}</div>
</template>
useFhevmClient()Access the FHEVM client directly.
Returns: FhevmClient - FHEVM client instance
Example:
<script setup>
import { useFhevmClient } from '@fhevm/vue';
const client = useFhevmClient();
// Direct access to client methods
const instance = client.getInstance();
</script>
<!-- App.vue -->
<script setup lang="ts">
import { useInit, useEncrypt, useDecrypt, useStatus } from '@fhevm/vue';
import { BrowserProvider } from 'ethers';
import { onMounted } from 'vue';
const { init } = useInit();
const { isReady, isLoading, isError } = useStatus();
const { encrypt, data: encryptedData, isLoading: isEncrypting } = useEncrypt();
const { decrypt, data: decryptedData, isLoading: isDecrypting } = useDecrypt();
onMounted(async () => {
const provider = new BrowserProvider(window.ethereum);
await init({ provider });
});
const handleEncrypt = async () => {
await encrypt({
value: 42,
type: 'euint32',
contractAddress: '0x...',
userAddress: '0x...',
});
};
const handleDecrypt = async () => {
const provider = new BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
await decrypt(
[{ handle: '0x...', contractAddress: '0x...' }],
signer
);
};
</script>
<template>
<div class="app">
<h1>FHEVM Demo</h1>
<div v-if="isLoading">Loading FHEVM...</div>
<div v-else-if="isError">Failed to initialize FHEVM</div>
<div v-else-if="!isReady">Please connect wallet</div>
<div v-else>
<!-- Encrypt Section -->
<section>
<h2>Encrypt</h2>
<button @click="handleEncrypt" :disabled="isEncrypting">
{{ isEncrypting ? 'Encrypting...' : 'Encrypt Value' }}
</button>
<pre v-if="encryptedData">{{ encryptedData }}</pre>
</section>
<!-- Decrypt Section -->
<section>
<h2>Decrypt</h2>
<button @click="handleDecrypt" :disabled="isDecrypting">
{{ isDecrypting ? 'Decrypting...' : 'Decrypt Value' }}
</button>
<pre v-if="decryptedData">{{ decryptedData }}</pre>
</section>
</div>
</div>
</template>
// main.ts
import { createApp } from 'vue';
import { createFhevm, IndexedDBStorage } from '@fhevm/vue';
import App from './App.vue';
const app = createApp(App);
const fhevm = createFhevm({
config: { storage: new IndexedDBStorage() }
});
app.use(fhevm);
app.mount('#app');
Full TypeScript support with comprehensive type definitions.
import type {
FhevmConfig,
FhevmStatus,
InitParams,
EncryptParams,
EncryptResult,
DecryptRequest,
DecryptResult,
} from '@fhevm/vue';
This package supports Vue 3 Composition API only. Options API is not supported.
BSD-3-Clause-Clear
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
@0xbojack/fhevm-coreEnvironment{
"local_name": "@0xbojack/fhevm-core",
"alias": false,
"peer_metadata": null
} | ^0.2.0 | runtime |
@vue/test-utilsEnvironment{
"local_name": "@vue/test-utils",
"alias": false,
"peer_metadata": null
} | ^2.4.6 | development |
@types/nodeEnvironment{
"local_name": "@types/node",
"alias": false,
"peer_metadata": null
} | ^22.7.5 | development |
tsupEnvironment{
"local_name": "tsup",
"alias": false,
"peer_metadata": null
} | ^8.5.0 | development |
typescriptEnvironment{
"local_name": "typescript",
"alias": false,
"peer_metadata": null
} | ^5.9.2 | development |
vitestEnvironment{
"local_name": "vitest",
"alias": false,
"peer_metadata": null
} | ^2.1.9 | development |
vueEnvironment{
"local_name": "vue",
"alias": false,
"peer_metadata": null
} | ^3.5.13 | development |
vueEnvironment{
"local_name": "vue",
"alias": false,
"peer_metadata": null
} | ^3.0.0 | peer |
ethersEnvironment{
"local_name": "ethers",
"alias": false,
"peer_metadata": null
} | ^6.13.7 | peer |
Source distribution
{
"integrity": "sha512-U8De376+rj80nfkkxxtFxApUqKp5RCi2jvccTcQSpUEX0Ys9V/bJgfs7FtE7PlpXS0lOPv9rQbrw5n7AN2Z+3Q==",
"shasum": "b914ff6d630cbc29506cc2ea6bb427f4492af7ba",
"tarball": "https://registry.npmjs.org/@0xbojack/fhevm-vue/-/fhevm-vue-0.2.1.tgz",
"fileCount": 9,
"unpackedSize": 74050,
"signatures": [
{
"keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U",
"sig": "MEUCIQCX8rms9qLVK2T1/IGGc1/29OsNAqbW9iTwMANRfvQz8gIgEy7pl5wblkROLhws50Dub0r4iNlyEbZA5cbTmoIhqjs="
}
]
}Observed since 20 Oct, 22:43 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:25aa0e00da7f6db67ed499fdbae045879a68c2ae00b4455fa593cd5ecc902ad8