Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New implementation based on Webnative 0.35 #12

Merged
merged 15 commits into from
Dec 15, 2022
Merged
32 changes: 14 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,35 @@ import { AppScenario } from "webnative"

// Initialise

const initialAppState = await walletauth.app({
const program = await walletauth.program({
// optional event handlers
onAccountChange: (newAppState) => handleAppState(newAppState),
onAccountChange: (newProgram) => handleProgram(newProgram),
onDisconnect: () => { /* eg. logout() */ }
})

handleAppState(initialAppState)
handleProgram(program)

function handleAppState(appState) {
switch (appState.scenario) {
case AppScenario.Authed:
// ✅ Authenticated
break;

case AppScenario.NotAuthed:
// Failed to authenticate with wallet
break;
function handleProgram(program) {
if (program.session) {
// ✅ Authenticated
} else {
// Failed to authenticate with wallet
}
}
```

Use a custom Ethereum provider:

```ts
import * as ethereum from "webnative-walletauth/wallet/ethereum.ts"
import * as ethereum from "webnative-walletauth/wallet/ethereum"

ethereum.setProvider(window.ethereum)
```

**You can also write an implementation for other wallets.** Note that the DID method has to be supported by the [Fission server](https://github.com/fission-codes/fission), unless you're using something else with webnative. At the moment of writing, you can only use the `key` method for DIDs with the Fission servers. It supports ED25519, RSA and SECP256K1 keys, same for the UCAN algorithms.

```ts
import * as walletImpl from "webnative-walletauth/wallet/implementation.ts"
import { Implementation } from "webnative-walletauth/wallet/types.ts"

import { Implementation } from "webnative-walletauth/wallet/implementation"

const impl: Implementation = {
decrypt: (encryptedMessage: Uint8Array) => Promise<Uint8Array>,
Expand All @@ -57,6 +51,8 @@ const impl: Implementation = {
verifySignedMessage: (args: { signature: Uint8Array; message: Uint8Array; publicKey?: Uint8Array }) => Promise<boolean>,
}

// NOTE: run this before you call `walletAuth.app()`
walletImpl.set(impl)
// When creating a Program indicate that you want to use your custom wallet implementation.
walletauth.program({
wallet: impl
})
```
Loading