# Wallets

{% code title="/" %}

```typescript
import { initLearnCard } from '@learncard/init';

const learnCard = await initLearnCard();

await learnCard.invoke.installChapiHandler();
```

{% endcode %}

{% code title="/manifest.json" %}

```json
{
  "name": "LearnCard Demo CHAPI Wallet",
  "short_name": "LearnCard Demo CHAPI Wallet",
  "icons": [
    {
      "sizes": "64x64",
      "src": "icon.png",
      "type": "image/png"
    }

  ],
  "credential_handler": {
    "url": "/wallet-worker",
    "enabledTypes": ["VerifiablePresentation"]
  }
}
```

{% endcode %}

{% code title="/wallet-worker" %}

```typescript
import { initLearnCard } from '@learncard/init';

const learnCard = await initLearnCard();

learnCard.invoke.activateChapiHandler({
    get: async () => {
        // Return an arbitrary route to display to users when requesting a credential
        // or using DIDAuth with your application
        return { type: 'redirect', url: `${window.location.origin}/get` };
    },
    store: async () => {
        // Return an arbitrary route to display to users when storing a credential
        // with your application
        return { type: 'redirect', url: `${window.location.origin}/store` };
    },
});
```

{% endcode %}

{% code title="/store" %}

```typescript
import { initLearnCard } from '@learncard/init';

const learnCard = await initLearnCard({ seed });

const event = await learnCard.invoke.receiveChapiEvent();

const vp = event.credential.data;

const vc = Array.isArray(vp.verifiableCredential)
    ? vp.verifiableCredential[0]
    : vp.verifiableCredential;
    
const accept = async () => {
    const uri = await learnCard.store.Ceramic.upload(vc);
    await wallet.index.IDX.add({ uri, id });
    event.respondWith(Promise.resolve({ dataType: 'VerifiablePresentation', data: vp }); 
};

const reject = () => event.respondWith(Promise.resolve(null));
```

{% endcode %}

{% code title="/get" %}

```typescript
import { initLearnCard } from '@learncard/init';

const learnCard = await initLearnCard({ seed });

const event = await learnCard.invoke.receiveChapiEvent();
const origin = event.credentialRequestOrigin;

const accept = () => {
    const presentation = event.credentialRequestOptions.web.VerifiablePresentation;
    const { challenge, domain } = presentation;

    event.respondWith(
        Promise.resolve({
            dataType: 'VerifiablePresentation',
            data: await learnCard.invoke.issuePresentation(await learnCard.invoke.getTestVp(), {
                challenge,
                domain,
                proofPurpose: 'authentication',
            }),
        })
    );
};

const reject = () => event.respondWith(Promise.resolve(null));
```

{% endcode %}

### More Info

{% content-ref url="/pages/9OUXr96cFl5PkSW71flf" %}
[CHAPI Wallet Setup Guide](/how-to-guides/implement-flows/chapi/chapi-wallet-setup-guide.md)
{% endcontent-ref %}

{% content-ref url="/pages/zk9ScZY7S9mndeLVUMZt" %}
[Demo Application](/how-to-guides/implement-flows/chapi/demo-application.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.learncard.com/how-to-guides/implement-flows/chapi/cheat-sheets/wallets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
