# partisia-crypto

> ```bash npm i partisia-blockchain-applications-crypto ```

Latest version **1.0.19** (published 2023-07-06) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install partisia-crypto
pnpm add partisia-crypto
yarn add partisia-crypto
bun add partisia-crypto
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.19 |
| Published | 2023-07-06 |
| First published | 2022-08-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=16.20.0 |
| Dependencies | 7 |
| Unpacked size | 264.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | partisia_blockchain_applications |

## Links

- npm: https://www.npmjs.com/package/partisia-crypto
- npm.io page: https://npm.io/package/partisia-crypto

## Dependencies (7)

- [bip32](https://npm.io/package/bip32.md) ^2.0.6
- [bip39](https://npm.io/package/bip39.md) ^3.0.4
- [big.js](https://npm.io/package/big.js.md) ^6.1.1
- [elliptic](https://npm.io/package/elliptic.md) ^6.5.4
- [merkletreejs](https://npm.io/package/merkletreejs.md) ^0.2.31
- [partisia-rpc](https://npm.io/package/partisia-rpc.md) ^1.0.9
- [noble-bls12-381](https://npm.io/package/noble-bls12-381.md) ^0.15.0

## Recent versions

- 1.0.19 (latest) — 2023-07-06
- 1.0.18 — 2023-06-19
- 1.0.17 — 2023-04-03
- 1.0.16 — 2023-03-27
- 1.0.15 — 2023-03-23
- 1.0.14 — 2023-03-22
- 1.0.13 — 2023-03-22
- 1.0.12 — 2023-03-02
- 1.0.11 — 2023-02-28
- 1.0.10 — 2023-02-06
- 1.0.9 — 2023-02-01
- 1.0.8 — 2022-12-30
- 1.0.7 — 2022-11-28
- 1.0.6 — 2022-11-03
- 1.0.5 — 2022-10-10
- … 5 more at https://npm.io/package/partisia-crypto/versions

## README

## Install

```bash
npm i partisia-blockchain-applications-crypto
```

---

## Wallet

### Wallet Mnemonic

```ts
import { partisiaCrypto } from 'partisia-blockchain-applications-crypto'

// 24 word mnemonic
const mnemonic = partisiaCrypto.wallet.generateMnemonic(24)
const keyPair = partisiaCrypto.wallet.getKeyPairHD(mnemonic)

// this is you private key pair
const { address, privateKey, publicKey } = keyPair
```

### Wallet Legacy

```ts
import { partisiaCrypto } from 'partisia-blockchain-applications-crypto'

// 24 word mnemonic
const mnemonic = partisiaCrypto.wallet.generateMnemonic(24)
const keyPair = partisiaCrypto.wallet.getKeyPairLegacy(mnemonic)

// this is you private key pair
const { address, privateKey, publicKey } = keyPair
```

### If you have a private key

```ts
const address = partisiaCrypto.wallet.privateKeyToAccountAddress('<32 bytes private key>')
```

---

## Transaction

### Serialize and Deserialize a Public Contract Transaction

> See: https://gitlab.com/partisiablockchain/language/abi-client-ts

### Serialize and Deserialize a System Contract Transaction

```ts
// Serialize Transaction
const abi = partisiaCrypto.abi_system.Payload_MpcTransferWithMemo
const txSerialized = partisiaCrypto.transaction.serializedTransaction(
  {
    nonce: 1, //'<get from querying address on chain>'
  },
  {
    contract: '01a4082d9d560749ecd0ffa1dcaaaee2c2cb25d881',
  },
  {
    invocationByte: 23,
    recipient: '001122331122331122331122331122331122331122',
    amount: 10000,
    memo: 'Sending MPC',
  },
  abi
)

console.log('txSerialized', partisiaCrypto.txSerialized.toString('hex'))
// 000000000000000100000182f07ec3b6000000000000001401a4082d9d560749ecd0ffa1dcaaaee2c2cb25d8810000002d1700112233112233112233112233112233112233112200000000000027100000000b53656e64696e67204d5043

// Deserialize Transaction
const tx = partisiaCrypto.transaction.deserializeTransactionPayload(txSerialized, false)
console.log('tx', tx)

/* 
{
  signature: '',
  inner: { nonce: '1', validTo: '2022-08-30T20:45:09.493Z', cost: '20' },
  header: {
    contract: '01a4082d9d560749ecd0ffa1dcaaaee2c2cb25d881',
    payload_length: '45'
  },
  payload: '1700112233112233112233112233112233112233112200000000000027100000000b53656e64696e67204d5043',
  deserialized: {
    invocationByte: 23,
    recipient: '001122331122331122331122331122331122331122',
    amount: '10000',
    memo: 'Sending MPC'
  }
} 
*/
```

---

## Sign

### Sign Message

```ts
// Send message from Alice to Barry
// Alice encrypts message with Barry's public key
const message = 'hello'
const messageEncrypted = partisiaCrypto.wallet.encryptMessage('<public key of Barry>', message)

// Barry decrypts message with private key
const messageDecrypted = partisiaCrypto.wallet.decryptMessage('<private key>', messageEncrypted).toString('utf8')

assert(message === messageDecrypted)
```

### Sign Transaction

```ts
const digest = partisiaCrypto.transaction.deriveDigest(
  'Partisia Blockchain',
  Buffer.from(
    '000000000000000100000182f07ec3b6000000000000001401a4082d9d560749ecd0ffa1dcaaaee2c2cb25d8810000002d1700112233112233112233112233112233112233112200000000000027100000000b53656e64696e67204d5043',
    'hex'
  )
)
partisiaCrypto.wallet.signTransaction(digest, '<private key from wallet>')
```

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