# @signumjs/crypto

> Cryptographic functions for building Signum Network apps.

Latest version **3.3.7** (published 2026-10-17) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @signumjs/crypto
pnpm add @signumjs/crypto
yarn add @signumjs/crypto
bun add @signumjs/crypto
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.3.7 |
| Published | 2026-10-17 |
| First published | 2021-06-02 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 3 |
| Unpacked size | 909.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 17 |
| Maintainers | ohager |
| Keywords | signum, signum-network, blockchain, smartcontracts, crypto, cryptography, signumjs |

## Links

- npm: https://www.npmjs.com/package/@signumjs/crypto
- Repository: https://github.com/signum-network/signumjs
- Homepage: https://github.com/signum-network/signumjs#readme
- Issues: https://github.com/signum-network/signumjs/issues
- npm.io page: https://npm.io/package/@signumjs/crypto

## Dependencies (3)

- [pako](https://npm.io/package/pako.md) ^1.0.11
- [buffer](https://npm.io/package/buffer.md) ^6.0.3
- [js-sha256](https://npm.io/package/js-sha256.md) ^0.11.0

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 3.3.7 (latest) — 2026-10-17
- 3.3.6 — 2026-10-17
- 3.3.5 — 2026-10-16
- 3.3.4 — 2026-08-02
- 3.3.3 — 2026-08-01
- 3.3.2 — 2026-07-31
- 3.3.1 — 2026-07-31
- 3.3.0 — 2026-07-25
- 3.2.2 — 2026-07-24
- 3.2.1 — 2026-07-24
- 3.2.0 — 2026-07-24
- 3.1.0 — 2026-04-16
- 3.0.10 — 2026-04-05
- 3.0.9 — 2026-03-31
- 3.0.7 — 2026-03-22
- … 91 more at https://npm.io/package/@signumjs/crypto/versions

## README

# @signumjs/crypto

Cryptographic functions for building Signum apps.

[![Featured on Openbase](https://badges.openbase.com/js/featured/@signumjs/crypto.svg?token=ShJWpDur1ZmdRPNkvCiTvHa1r/JOG+8TkABhdRCIZbI=)](https://openbase.com/js/@signumjs/crypto?utm_source=embedded&amp;utm_medium=badge&amp;utm_campaign=rate-badge)

## Installation

SignumJS can be used with NodeJS or Web. Two formats are available

### Using with NodeJS and/or modern web frameworks

Install using [npm](https://www.npmjs.org/):

```
npm install @signumjs/crypto
```

or using [yarn](https://yarnpkg.com/):

``` yarn
yarn add @signumjs/crypto
```

#### Example

```js
import {sha256AsHex, Crypto, NodeJSCryptoProvider} from '@signumjs/crypto'

Crypto.init(new NodeJSCryptoProvider()); // or WebCryptoProvider
console.log(sha256AsHex('test'))
```


### Using in classic `<script>`

Each package is available as bundled standalone library using UMD.
This way _signumJS_ can be used also within `<script>`-Tags.
This might be useful for Wordpress and/or other PHP applications.

Just import the package using the HTML `<script>` tag.

`<script src='https://cdn.jsdelivr.net/npm/@signumjs/crypto/dist/signumjs.crypto.min.js'></script>`


#### Example

```js
console.log(sig$crypto.sha256AsHex('test'))
```

> The "legacy" web bundle initializes the Crypto module automatically with the WebCryptoAdapter. So, no initialization is necessary.

See more here:
[@signumjs/crypto Online Documentation](https://signum-network.github.io/signumjs/modules/crypto.html)


## Crossplatform Usage

As there are different crypto implementations for different platforms available the underlying crypto contexts need to be initialized. 
The crypto package provides used out of the box implementations for modern web browsers and NodeJS (and alike backends, i.e. deno and bun).
Depending on the runtime environment the correct `CryptoAdapter`-implementation needs to be set for cryptographic routines.
In a web browser the [Crypto Web API](https://developer.mozilla.org/en-US/docs/Web/API/Crypto) is used, i.e. a secure (https) environment is required.
In NodeJS the [NodeJS Crypto API](https://nodejs.org/api/crypto.html) is used.

Run the following before any usage of crypto functions

__Web__

```ts
import {Crypto, WebCryptoAdapter} from "@signumjs/crypto"
Crypto.init(new WebCryptoAdapter());
```

__NodeJS__ (Deno, Bun)

```ts
import {Crypto, NodeJSCryptoAdapter} from "@signumjs/crypto"
Crypto.init(new NodeJSCryptoAdapter());
```


> For web `localhost` is considered a secure context

> If using `signumjs.crypto.min.js` the initialization is not required. It is automatically set to `WebCryptoAdapter`


### Implementing CryptoAdapter-Interface

If needed in other environments, e.g. React Native, a custom implementation of the `CryptoAdapter` interface is required.
The interface implements the bare minimum crypto functions needed for Signum:

```ts
export interface CryptoAdapter {
    encryptAes256Cbc(plaintext: Uint8Array, key: Uint8Array): Promise<Uint8Array>;

    decryptAes256Cbc(ciphertext: Uint8Array, key: Uint8Array): Promise<Uint8Array>;

    sha256(data: ArrayBuffer): Promise<Uint8Array>;

    getRandomValues(array: Uint8Array): Uint8Array;
}
```

Like this:

```ts
import {type CryptoAdapter} from '@signumjs/crypto'

class CustomCryptoAdapter implements CryptoAdapter {
    decryptAes256Cbc(ciphertext: Uint8Array, key: Uint8Array): Promise<Uint8Array> {
        // Do your platforms implementation here
        return Promise.resolve(undefined);
    }

    encryptAes256Cbc(plaintext: Uint8Array, key: Uint8Array): Promise<Uint8Array> {
        // Do your platforms implementation here
        return Promise.resolve(undefined);
    }

    getRandomValues(array: Uint8Array): Uint8Array {
        // Do your platforms implementation here
        return undefined;
    }

    sha256(data: ArrayBuffer): Uint8Array {
        // Do your platforms implementation here
        return undefined;
    }

}
```

Then use the custom crypto provider like this:

```ts
import {Crypto, sha256AsHex} from '@signumjs/crypto'

Crypto.init(new CustomCryptoAdapter());

(async ()=> {
    // internally uses the custom crypto provider
    console.log("SHA256", await sha256AsHex("blablubb"))
})()

```

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