Skip to content

Commit

Permalink
Merge pull request #115 from cashubtc/staging
Browse files Browse the repository at this point in the history
Major Version 1.0.0
  • Loading branch information
gandlafbtc authored Jul 17, 2024
2 parents 4bb76a4 + 7c95ca4 commit 7c582f9
Show file tree
Hide file tree
Showing 32 changed files with 1,962 additions and 1,440 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
push:
branches:
- main
- staging

jobs:
build:
Expand All @@ -29,5 +30,5 @@ jobs:
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
destination_dir: coverage
destination_dir: coverage/${{ github.head_ref || github.ref_name }}
publish_dir: ./coverage/lcov-report
24 changes: 24 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Format Check

on: [push]

jobs:
tests:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Check format
run: npm run check-format
10 changes: 3 additions & 7 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@

name: Node.js CI

on:
pull_request:
types:
- ready_for_review
- opened
on: [push]

jobs:
build:
tests:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x, 16.x, 18.x]
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/nutshell-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Nutshell integration

on: [push, pull_request]

jobs:
integration-tests:
runs-on: ubuntu-latest
steps:
- name: Pull and start mint
run: |
docker run -d -p 3338:3338 --name nutshell -e MINT_LIGHTNING_BACKEND=FakeWallet -e MINT_LISTEN_HOST=0.0.0.0 -e MINT_LISTEN_PORT=3338 -e MINT_PRIVATE_KEY=TEST_PRIVATE_KEY cashubtc/nutshell:0.15.2 poetry run mint
- name: Check running containers
run: docker ps

# - name: Sleep 5 seconds and curl on localhost:3338/v1/info
# run: |
# sleep 5
# curl localhost:3338/v1/info

- name: Checkout cashu-ts repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
cache: 'npm'

- run: npm ci
- run: npm run compile
- run: npm run test-integration
3 changes: 2 additions & 1 deletion .github/workflows/typedoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- staging

jobs:
build:
Expand All @@ -28,5 +29,5 @@ jobs:
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
destination_dir: docs
destination_dir: docs/${{ github.head_ref || github.ref_name }}
publish_dir: ./docs
21 changes: 21 additions & 0 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish Package to npmjs
permissions:
contents: read
id-token: write
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'
- run: npm i
- run: npm run compile
- run: npm publish --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
dist
node_modules
package-lock.json
package-lock.json
coverage
docs
36 changes: 13 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Implemented [NUTs](https://github.com/cashubtc/nuts/):
- [x] [NUT-07](https://github.com/cashubtc/nuts/blob/main/07.md)
- [x] [NUT-08](https://github.com/cashubtc/nuts/blob/main/08.md)
- [x] [NUT-09](https://github.com/cashubtc/nuts/blob/main/09.md)
- [x] [NUT-11](https://github.com/cashubtc/nuts/blob/main/11.md)

Supported token formats:

Expand All @@ -44,42 +45,31 @@ Supported token formats:

## Usage

Go to the [docs](https://cashubtc.github.io/cashu-ts/docs) for detailed usage.
Go to the [docs](https://cashubtc.github.io/cashu-ts/docs) for detailed usage, or have a look at the [integration tests](./test/integration.test.ts) for examples on how to implement a wallet.

### Install

```shell
npm i @cashu/cashu-ts
```

### Import
### Example

```typescript
import { CashuMint, CashuWallet, getEncodedToken } from '@cashu/cashu-ts';

const wallet = new CashuWallet(new CashuMint('{MINT_URL}'));

const { pr, hash } = await wallet.requestMint(200);

//pay this LN invoice
console.log({ pr }, { hash });

async function invoiceHasBeenPaid() {
const { proofs } = await wallet.requestTokens(200, hash);
//Encoded proofs can be spent at the mint
const encoded = getEncodedToken({
token: [{ mint: '{MINT_URL}', proofs }]
});
console.log(encoded);
}
const mint = new CashuMint(mintUrl);
const wallet = new CashuWallet(mint);
const mintQuote = await wallet.mintQuote(64);
const tokens = await wallet.mintTokens(64, mintQuote.quote);
```

## Contribute

Contributions are very welcome.

If you want to contribute, please open an Issue or a PR.
If you open a PR, please do so from the `development` branch as the base branch.
If you want to contribute, please open an Issue or a PR.
If you open a PR, please do so from the `development` branch as the base branch.

### Version

Expand All @@ -90,17 +80,17 @@ If you open a PR, please do so from the `development` branch as the base branch.
| | * `hotfix`
| |
| * `staging`
| |\
| |\
| |\ \
| | | * `bugfix`
| | |
| | * `development`
| | |\
| | * `development`
| | |\
| | | * `feature1`
| | | |
| | |/
| | *
| | |\
| | |\
| | | * `feature2`
| | |/
| |/
Expand Down
114 changes: 114 additions & 0 deletions migration-1.0.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Version 1.0.0 Migration guide

⚠️ Upgrading to version 1.0.0 will come with breaking changes! Please follow the migration guide for a smooth transition to the new version.

## Context

In Version 1.0.0 the api version of mints has been upgraded to `v1`. Please read the `v1` [v1 cleanup PR](https://github.com/cashubtc/nuts/pull/55) to understand more about how the API has changed.

## Breaking changes

### ⚠️ Important! When upgrading to this version, the `hash2curve` function and the `default secret format` have changed. This means deterministic secret derivation will produce NOT THE SAME SECRETS as before. When upgrading to this version, wallets that have been using deterministic secrets (seed phrase) must reset counters and then `self spend`/`refresh` all proofs, so that the backups continue working.

---

### Decoding LN invoices

**Removed LN invoice decode:**
Decoding LN invoices is no longer used inside the lib.

**How to fix:** If you need to decode LN invoices, you can use

> npm i [@gandlaf21/bolt11-decode](https://www.npmjs.com/package/@gandlaf21/bolt11-decode)
---

### `CashuWallet` interface changes

**`receive()` does no longer support multi-token tokens**

To reduce complexity, simplify error handling and to prepare for token V4, this feature has been removed. only the first token inside a token will be processed

**optional function AND constructor parameters are now in an onpional `options?` Object**

Utility functions now have an `options` object for optional parameters, instead of passing them directly

**`requestMint(amount: number)` --> `createMintQuote(amount: number)`**
Now returns the following:

```typescript
type MintQuoteResponse = {
request: string;
quote: string;
paid: boolean;
expiry: number;
};
```

where `request` is the invoice to be paid, and `quote` is the identifier used to pass to `mintTokens()`.

**`requestTokens()` --> `mintTokens()`**

---

**`createMeltQuote(invoice: string)`** is now used to get fee estimation and conversion quotes instead of `getFee()` and returns:

```typescript
type MeltQuoteResponse = {
quote: string;
amount: number;
fee_reserve: number;
paid: boolean;
expiry: number;
};
```

where `quote` is the identifier to pass to `meltTokens()`

---

### Model changes

**`MintKeys`--> `Keys`**:
`MintKeys` now include the `keys`, `id` and `unit`

```typescript
type MintKeys = {
id: string;
unit: string;
keys: Keys;
};

type Keys = { [amount: number]: string };
```

---

**`MintKeyset`**:
Used to be a string array, but now contains the additional fields `active` and `unit`

```typescript
type MintKeyset = {
id: string;
unit: string;
active: boolean;
};
```

---

**`BlindedMessages`:** now include the field `id`, corresponding with the mints `keysetId`

```typescript
type BlindedMessage {
amount: number;
B_: ProjPointType<bigint>;
id: string;
}
```

---

### Pattern changes

**removed `newKeys` from returns**: Functions no longer return `newKeys`. Wallets now specify the keyset they use in the BlindedMessage via the `id` field.
Loading

0 comments on commit 7c582f9

Please sign in to comment.