# @didtools/pkh-stacks

> Implements support to authenticate, authorize and verify with Stacks accounts as a did:pkh with SIWE(X) and CACAO. Primarly used with `did-session` and `@didtools/cacao`.

Latest version **0.2.0** (published 2024-01-04) · (Apache-2.0 OR MIT) license · 0 weekly downloads

## Install

```sh
npm install @didtools/pkh-stacks
pnpm add @didtools/pkh-stacks
yarn add @didtools/pkh-stacks
bun add @didtools/pkh-stacks
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2024-01-04 |
| First published | 2023-02-07 |
| Weekly downloads | 0 |
| License | (Apache-2.0 OR MIT) |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14.14 |
| Dependencies | 7 |
| Unpacked size | 14.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 103 |
| Maintainers | dbcfd, cb3box, ukstv, jpham2023, oed, paul_lecam |
| Keywords | DID, identity, did-provider, self-sovereign |

## Links

- npm: https://www.npmjs.com/package/@didtools/pkh-stacks
- Repository: https://github.com/ceramicnetwork/js-did
- Homepage: https://github.com/ceramicnetwork/js-did#readme
- Issues: https://github.com/ceramicnetwork/js-did/issues
- npm.io page: https://npm.io/package/@didtools/pkh-stacks

## Dependencies (7)

- [caip](https://npm.io/package/caip.md) ^1.1.0
- [jsontokens](https://npm.io/package/jsontokens.md) ^4.0.1
- [@stacks/common](https://npm.io/package/@stacks/common.md) ^6.10.0
- [@didtools/cacao](https://npm.io/package/@didtools/cacao.md) ^3.0.0
- [@stablelib/random](https://npm.io/package/@stablelib/random.md) ^1.0.2
- [@stacks/encryption](https://npm.io/package/@stacks/encryption.md) ^6.10.0
- [@stacks/transactions](https://npm.io/package/@stacks/transactions.md) ^6.10.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2024-01-04
- 0.1.1-next.0 (next) — 2023-10-27
- 0.1.0 — 2023-02-24
- 0.0.1 — 2023-02-07

## README

## Stacks AuthMethod and Verifier

Implements support to authenticate, authorize and verify with Stacks accounts as a did:pkh with SIWE(X) and CACAO.
Primarly used with `did-session` and `@didtools/cacao`.

## Installation

```
npm install --save @didtools/pkh-stacks
```

## Auth Usage

To Auth in web based env, use any injected web3 provider that implements the standard interface with `StacksWebAuth`.

```ts
// Web Auth Usage
import { StacksWebAuth, getAccountIdByNetwork, verifyStacksSignature } from '@didtools/pkh-stacks'
import { AppConfig, UserSession } from '@stacks/connect'

// ...
const stacksProvider = window.StacksProvider
const appConfig = new AppConfig(['store_write'])
const userSession = new UserSession({ appConfig })

const userData = userSession.loadUserData()
const address = user.profile.stxAddress.mainnet

const accountId = await getAccountIdByNetwork('mainnet', address)
const authMethod = await StacksWebAuth.getAuthMethod(stacksProvider, accountId, publicKey)
```

To use with did-session and reference did-session docs for more details.

```js
const session = await DIDSession.authorize(authMethod, { resources: ['ceramic://*'] })
```

## Configuration

AuthMethod creators consume a standard Stacks provider and an AccountId. AccountID follows the CAIP10 standard. The helper method `getAccountIdByNetwork` id provided, but you can also create an AccountID using the CAIP library directly.

```js
import { AccountId } from 'caip'
import { getAccountIdByNetwork } from '@didtools/pkh-stacks'
// Using network string
const accountId = getAccountIdByNetwork('mainnet', address)
// With CAIP
const stacksMainnetChainId = '1'
const chainNameSpace = 'stacks'
const chainId = `${chainNameSpace}:${stacksMainnetChainId}`
const accountIdCAIP = new AccountId({ address, chainId })
```

## Verifier Usage

Verifiers are needed to verify different did:pkh signed payloads using CACAO. Libraries that need them will
consume a verifiers map allowing your to register the verifiers you want to support.

```ts
import { Cacao } from '@didtools/cacao'
import { getStacksVerifier } from '@didtools/pkh-stacks'
import { DID } from 'dids'
const verifiers = {
  ...getStacksVerifier(),
}
// Directly with cacao
Cacao.verify(cacao, { verifiers, ...opts })
// With DIDS, reference DIDS for more details
const dids = //configured dids instance
  await dids.verifyJWS(jws, { capability, verifiers, ...opts })
```

## License

Apache-2.0 OR MIT

---
_Source: https://npm.io/package/@didtools/pkh-stacks · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
