# decash-utils

> Utilities for DeCash tokens

Latest version **3.0.0** (published 2022-05-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install decash-utils
pnpm add decash-utils
yarn add decash-utils
bun add decash-utils
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2022-05-10 |
| First published | 2022-04-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 27.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | DeCash-Official |
| Maintainers | decash |
| Keywords | decash, utils, usdd, eurd, stablecoin, crypto, cryptocurrency |

## Links

- npm: https://www.npmjs.com/package/decash-utils
- Repository: https://github.com/DeCash-Official/decash-utils
- Homepage: https://github.com/DeCash-Official/decash-utils#readme
- Issues: https://github.com/DeCash-Official/decash-utils/issues
- npm.io page: https://npm.io/package/decash-utils

## Dependencies (1)

- [js-sha512](https://npm.io/package/js-sha512.md) ^0.8.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.0.0 (latest) — 2022-05-10
- 2.2.0 — 2022-05-07
- 2.1.1 — 2022-05-07
- 2.1.0 — 2022-05-07
- 2.0.0 — 2022-05-07
- 1.1.2 — 2022-05-07
- 1.1.0 — 2022-05-02
- 1.0.1 — 2022-04-28
- 1.0.0 — 2022-04-28

## README

![NPM version](https://img.shields.io/npm/v/decash-utils)
![LICENSE](https://img.shields.io/npm/l/decash-utils)
![Build & publish](https://github.com/DeCash-Official/decash-utils/actions/workflows/build-and-push.yaml/badge.svg)

# decash-utils

Utilities for building on top of [DeCash](https://decash.com) - the most easy-to-use and technically
perfected stablecoin.

Read more about DeCash at [docs.decash.com](https://docs.decash.com). Find the DeCash API reference
[here](http://docs.decash.com/docs/api/overview).

## Installation

```sh
npm install --save decash-utils
```

## Usage

### `algorandDecodeSignature({ logicsig })`

This example demonstrates how to decode a logic signature, which:

1. Shows whether the sender is a Delegated Wallet (when `senderDelegatedWallet` is returned).
2. Gets properties (like the owner or seed) of this Delegated Wallet.

```typescript
import { algorandDecodeSignature } from 'decash-utils';

// A part of the response from {Algorand Indexer (testnet)}/v2/blocks/21198914
const { senderDelegatedWallet } = algorandDecodeSignature({
  logicsig: {
    args: ['AA=='],
    logic:
      'BSACAAEmASDK6flECgvcY5MQRC3FjvVNKytcXjCk4eLKQJV+0fIxjShIgYCAgICAgICAAEgxIDIDEkQtFyMSQACHLRciEkAAeAAiNQA0ADIEDEEAfjQAOBCBBhJAAA8iQAAJNAAjCDUAQv/hI0M0ADgYgeCq7qGAgICAABJAAAQiQv/cNAA4GzEWDUAABCJC/840ADEWwhoiI1I0AUAAG4ABThJAAAQiQv+1NAA0AMIaIiNSgAF2EkL/pYABWUL/4ogAEDUBQv+BLjEXKAQ1AUL/dwAiNQA0ADIEDEEAFDQAOAAoEkAACTQAIwg1AEL/5iOJIok=',
  },
});

if (senderDelegatedWallet) {
  console.log(`
    The transaction sender is DeCash Delegated Wallet, owned by ${senderDelegatedWallet.owner};
    Wallet's seed: ${senderDelegatedWallet.seed};
    Validator smart contract ID: ${senderDelegatedWallet.validatorAppId}.
  `);
} else {
  console.log('The transaction sender is not a DeCash Delegated Wallet.');
}
```

### `algorandGetDelegatedWalletAddress({ owner, seed, validatorAppId })`

Returns the address of the Delegated Wallet with the given owner, validatorAppId and optional seed.

```typescript
import { algorandGetDelegatedWalletAddress } from 'decash-utils';

const address = algorandGetDelegatedWalletAddress({
  owner: 'ZLU7SRAKBPOGHEYQIQW4LDXVJUVSWXC6GCSODYWKICKX5UPSGGGYQCH654',
  validatorAppId: 71013728, // Network-dependent. Get the validator APP ID from https://docs.decash.com/docs/concepts/delegated-wallets#verifier
});
// address = 'QCLGDBMIGC5EV4WA4J4TZCUKZURQ5BORMC3WQYBWJCXDILCDQFLPMT4ZCE'
```

### `algorandGetDelegatedWalletLogicSig({ owner, seed, validatorAppId })`

This example demonstrates how to get the logic signature of a DeCash Delegated Wallet,
which then can be used to sing transaction outgoing from the Delegated Wallet.

```typescript
import { LogicSigAccount, signLogicSigTransaction } from 'algosdk';
import { algorandGetDelegatedWalletLogicSig } from 'decash-utils';

const delegatedWalletCode = algorandGetDelegatedWalletLogicSig({
  owner: '6E63EKJYUPLL4SKM5FNX3PD7HSWZ26XPS7BXYLVWJAPDEK3VA7DERTFV4E', // The owner of the delegated wallet.
  seed: 0, // Optional. Default is 0.
  validatorAppId: 71013728, // Network-dependent. Get the validator APP ID from https://docs.decash.com/docs/concepts/delegated-wallets#verifier
});

const logicSigAccount: LogicSigAccount = new LogicSigAccount(
  delegatedWalletCode,
  [new Buffer.from('\x00')] // "Self-sign"
);
const signedTx = signLogicSigTransaction(txn, logicSigAccount).blob;
```

### Utility functions

You can use these exported utility functions for various purposes.

```typescript
import {
  algorandAddressToUInt8Array,
  base32ToUInt8Array,
  base64ToUInt8Array,
  uInt8ArrayToAlgorandAddress,
  uInt8ArrayToBase32,
  uInt8ArrayToBase64,
  uInt8ArrayToVarInt,
  varIntToUInt8Array,
} from 'decash-utils';
```

## Development

To make a new package version,

1. Add your new code and tests.
2. Update the package version in `package.json`.
3. Push or pull request to `main`. The package will be deployed by GitHub Workflows.

## License

[MIT](LICENSE) © [DeCash](https://decash.com)

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