open-index/open-npm huggingface dataset:
npm package: @hazae41/disposable-stack-polyfill
Description: Polyfill for DisposableStack and AsyncDisposableStack
Author: hazae41
Latest version: 2.0.5

# DisposableStack and AsyncDisposableStack polyfill

Polyfill for `DisposableStack` and `AsyncDisposableStack`

```bash
npm install @hazae41/disposable-stack-polyfill
```

```bash
deno install jsr:@hazae41/disposable-stack-polyfill
```

[**📦 NPM**](https://www.npmjs.com/package/@hazae41/disposable-stack-polyfill) • [**📦 JSR**](https://jsr.io/@hazae41/disposable-stack-polyfill)

## Usage

### How?

```tsx
import "@hazae41/disposable-stack-polyfill"
```

### Where? 

You can import the polyfill **in your project entry file** or **in a specific file**, you just need to import it before anything that requires `DisposableStack`

(e.g. For a Next.js app, it can be in `_app.js`)

```tsx
/**
 * This polyfill at the top
 **/
import "@hazae41/disposable-stack-polyfill"

/**
 * Your imports that requires DisposableStack to work
 **/
import { a } from "a"
import { b } from "./b.js"

/**
 * Your code that requires DisposableStack to work
 **/
using x = new DisposableStack()
```
npm package: @hazae41/disposer
Description: Helpers for Disposable
Author: hazae41
Latest version: 2.0.20

# Disposer

A wrapper for an object with a dispose function

```bash
npm i @hazae41/disposer
```

[**Node Package 📦**](https://www.npmjs.com/package/@hazae41/disposer)

## Features

### Current features
- 100% TypeScript and ESM
- No external dependencies
- Create a disposable object from any object

## Usage

### Create a disposable object (Disposable or AsyncDisposable) from any object

```tsx
using d = new Disposer(something, () => { ... })
```

```tsx
await using d = new AsyncDisposer(something, async () => { ... })
```

You can get the inner object with `.inner` or `.get()` and the dispose function with `.dispose`

## Example

This can be useful for waiting for multiple listeners, and remove all listeners when one of them is triggered

```tsx
import { Future } from "@hazae41/future"
import { Disposer } from "@hazae41/disposer"

function waitA(): Disposer<Promise<"a">> {
  const future = new Future<"a">()
  const onevent = () => future.resolve("a")

  this.addEventListener("a", onevent)
  const off = () => this.removeEventListener("a", onevent)
  
  return new Disposer(future.promise, off)
}

function waitB(): Disposer<Promise<"b">> {
  const future = new Future<"b">()
  const onevent = () => future.resolve()

  this.addEventListener("b", onevent)
  const off = () => this.removeEventListener("b", onevent)
  
  return new Disposer(future.promise, off)
}

async function wait() {
  using a = waitA()
  using b = waitB()

  const x: "a" | "b" = await Promise.race([a.get(), b.get()])

  /**
   * All listeners will be removed
   */
}
```
npm package: @hazae41/echalote
Description: Zero-copy Tor protocol for the web
Author: hazae41
Latest version: 0.4.18

<div align="center">
<img src="https://user-images.githubusercontent.com/4405263/219942970-2b5fb519-7bbe-491a-a12b-6b71040febe4.png" />
</div>

```bash
npm i @hazae41/echalote
```

[**Node Package 📦**](https://www.npmjs.com/package/@hazae41/echalote) • [**Online Demo 🌐**](https://echalote-example-next.vercel.app) • [**Next.js CodeSandbox 🪣**](https://codesandbox.io/p/github/hazae41/echalote-example-next)

## Use at your own risk

This is experimental software in early development

1. It has security issues
2. Things change quickly

## Features

### Current features
- 100% TypeScript and ESM
- Zero-copy reading and writing
- Works in the browser
- All cryptography use either WebCrypto or reproducible WebAssembly ports of Rust implementations
- Unsafe Tor protocol (with Ed25519, ntor, kdf-tor)
- Meek (HTTP) transport (without domain-fronting)
- Snowflake (WebRTC/WebSocket) transport (without domain-fronting)
- Unsafe TLS using [Cadenas](https://github.com/hazae41/cadenas)
- HTTP and WebSocket messaging using [Fleche](https://github.com/hazae41/fleche)

### [Upcoming features](https://github.com/sponsors/hazae41)
- Better security

## Usage

```typescript
import { createWebSocketSnowflakeStream, TorClientDuplex, Consensus } from "@hazae41/echalote"
import { Ciphers, TlsClientDuplex } from "@hazae41/cadenas"

const tcp = await createWebSocketSnowflakeStream("wss://snowflake.bamsoftware.com/")
const tor = new TorClientDuplex()

tcp.outer.readable.pipeTo(tor.inner.writable).catch(() => {})
tor.inner.readable.pipeTo(tcp.outer.writable).catch(() => {})

await tor.waitOrThrow()

using circuit = await tor.createOrThrow()
const consensus = await Consensus.fetchOrThrow(circuit)

const middles = consensus.microdescs.filter(it => true
  && it.flags.includes("Fast")
  && it.flags.includes("Stable")
  && it.flags.includes("V2Dir"))

const exits = consensus.microdescs.filter(it => true
  && it.flags.includes("Fast")
  && it.flags.includes("Stable")
  && it.flags.includes("Exit")
  && !it.flags.includes("BadExit"))

const middle = middles[Math.floor(Math.random() * middles.length)]
const middle2 = await Consensus.Microdesc.fetchOrThrow(circuit, middle)
await circuit.extendOrThrow(middle2, AbortSignal.timeout(5000))

const exit = exits[Math.floor(Math.random() * middles.length)]
const exit2 = await Consensus.Microdesc.fetchOrThrow(circuit, exit)
await circuit.extendOrThrow(exit2, AbortSignal.timeout(5000))

const ttcp = await circuit.openOrThrow("twitter.com", 443)

const ciphers = [Ciphers.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384]
const ttls = new TlsClientDuplex({ host_name: url.hostname, ciphers })

ttcp.outer.readable.pipeTo(ttls.inner.writable).catch(() => { })
ttls.inner.readable.pipeTo(ttcp.outer.writable).catch(() => { })

const response = await fetch("https://twitter.com", { stream: ttls.outer })
const text = await response.text()
```
npm package: @hazae41/ed25519
Description: Ed25519 adapter for WebAssembly and JS implementations
Author: hazae41
Latest version: 2.1.24

# Ed25519

Ed25519 adapter for WebAssembly and JS implementations

```bash
npm i @hazae41/ed25519
```

[**Node Package 📦**](https://www.npmjs.com/package/@hazae41/ed25519)

## Features

### Current features
- 100% TypeScript and ESM
- No external dependencies

## Usage

### Native (WebCrypto)

https://github.com/tQsW/webcrypto-curve25519/blob/master/explainer.md

```typescript
import { Ed25519 } from "@hazae41/ed25519"

Ed25519.set(Ed25519.fromNative())
```

### WebAssembly

```bash
npm i @hazae41/ed25519.wasm
```

```typescript
import { Ed25519 } from "@hazae41/ed25519"
import { Ed25519Wasm } from "@hazae41/ed25519.wasm"

await Ed25519Wasm.initBundled()

Ed25519.set(await Ed25519.fromNativeOrWasm(Ed25519Wasm))
```

### Noble Curves (JavaScript)

```bash
npm i @noble/curves
```

```typescript
import { Ed25519 } from "@hazae41/ed25519"
import * as Ed25519Noble from "@noble/curves/ed25519"

Ed25519.set(await Ed25519.fromNativeOrNoble(Ed25519Noble))
```

### Noble Ed25519 (JavaScript)

```bash
npm i @noble/ed25519
```

```typescript
import { Ed25519 } from "@hazae41/ed25519"
import * as ed25519 from "@noble/ed25519"

Ed25519.set(await Ed25519.fromNativeOrNoble({ ed25519 }))
```