Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better typedefs for some NUTs #1

Closed
Closed
Changes from 6 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
706c2e0
Update README.md
gandlafbtc Feb 20, 2024
bc6724a
Update README.md
gandlafbtc Feb 20, 2024
4bb76a4
Update README.md
gandlafbtc Feb 20, 2024
53f015a
NUT-06: new info endpoint with monkeypatch for old format, see https:…
callebtc Jul 15, 2024
042bf2b
npm run format
callebtc Jul 16, 2024
ff1f316
contact field explicit type
callebtc Jul 16, 2024
00d3bc6
add state enum changes of NUT-04 and NUT-05
callebtc Jul 16, 2024
a247b7f
console log instead of warnings
callebtc Jul 16, 2024
ef8111f
fix errors in test
callebtc Jul 16, 2024
15411d1
Merge pull request #148 from cashubtc/nut-05-add-state
callebtc Jul 16, 2024
de011a1
Merge branch 'nut-05-add-state' into nut-06-fix-contact
callebtc Jul 16, 2024
18855eb
refactor depercated contact handler
callebtc Jul 16, 2024
a752c0d
typo
callebtc Jul 16, 2024
f90eead
erge branch 'development' into nut-06-fix-contact
callebtc Jul 16, 2024
70e93f4
npm run format
callebtc Jul 16, 2024
559080d
Format checker in gihtub pipeline
callebtc Jul 16, 2024
0952172
test format mismatch, should fail
callebtc Jul 16, 2024
097f7ec
install dep[s
callebtc Jul 16, 2024
f34276c
fix format, should succeed
callebtc Jul 16, 2024
5b0f667
Merge pull request #149 from cashubtc/ci-add-prettier-check
callebtc Jul 16, 2024
1d315e2
Merge remote-tracking branch 'upstream/v1.0.0-rc.9-minibits' into fix…
KraXen72 Jul 16, 2024
46a53f5
improve type definitions for GetInfoResponse
KraXen72 Jul 16, 2024
aba81e5
fix definition of NUT15Entry in GetInfoResponse
KraXen72 Jul 16, 2024
6c6cf0d
Merge pull request #147 from cashubtc/nut-06-fix-contact
callebtc Jul 16, 2024
53c1af3
updated naming on mint / melt
Egge21M Jul 5, 2024
c5b509a
updated tests / all green
Egge21M Jul 5, 2024
13c115f
updated migration doc
Egge21M Jul 15, 2024
4ce0716
mint and wallet same naming
Egge21M Jul 16, 2024
4909e39
1.0.0-rc.10
Egge21M Jul 16, 2024
9d42535
implement nut17 type defs
KraXen72 Jul 16, 2024
142d671
remove unused import
callebtc Jul 16, 2024
55dc4fa
Merge pull request #145 from Egge21M/naming
callebtc Jul 16, 2024
16954c7
Merge branch 'main' into development
callebtc Jul 16, 2024
b99ad29
Merge pull request #150 from cashubtc/dev-sync-main-readme
callebtc Jul 16, 2024
3bd7cea
Merge branch 'development' into staging
Egge21M Jul 16, 2024
ce81a59
1.0.0-rc.11
Egge21M Jul 16, 2024
4e3869b
audit fix deps
gandlafbtc Jul 17, 2024
7c95ca4
1.0.0-rc.12
gandlafbtc Jul 17, 2024
7c582f9
Merge pull request #115 from cashubtc/staging
gandlafbtc Jul 17, 2024
4797c05
Update version.yml
gandlafbtc Jul 17, 2024
7dd0cad
Merge remote-tracking branch 'cashubtc/main' into fixed-typedef
KraXen72 Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions migration-1.0.0.md
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ To reduce complexity, simplify error handling and to prepare for token V4, this

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

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

```typescript
@@ -51,7 +51,7 @@ where `request` is the invoice to be paid, and `quote` is the identifier used to

---

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

```typescript
type MeltQuoteResponse = {
24 changes: 12 additions & 12 deletions src/CashuMint.ts
Original file line number Diff line number Diff line change
@@ -111,7 +111,7 @@ class CashuMint {
* @param customRequest
* @returns the mint will create and return a new mint quote containing a payment request for the specified amount and unit
*/
public static async mintQuote(
public static async createMintQuote(
mintUrl: string,
mintQuotePayload: MintQuotePayload,
customRequest?: typeof request
@@ -130,8 +130,8 @@ class CashuMint {
* @param mintQuotePayload Payload for creating a new mint quote
* @returns the mint will create and return a new mint quote containing a payment request for the specified amount and unit
*/
async mintQuote(mintQuotePayload: MintQuotePayload): Promise<MintQuoteResponse> {
return CashuMint.mintQuote(this._mintUrl, mintQuotePayload, this._customRequest);
async createMintQuote(mintQuotePayload: MintQuotePayload): Promise<MintQuoteResponse> {
return CashuMint.createMintQuote(this._mintUrl, mintQuotePayload, this._customRequest);
}

/**
@@ -141,7 +141,7 @@ class CashuMint {
* @param customRequest
* @returns the mint will create and return a Lightning invoice for the specified amount
*/
public static async getMintQuote(
public static async checkMintQuote(
mintUrl: string,
quote: string,
customRequest?: typeof request
@@ -160,8 +160,8 @@ class CashuMint {
* @param quote Quote ID
* @returns the mint will create and return a Lightning invoice for the specified amount
*/
async getMintQuote(quote: string): Promise<MintQuoteResponse> {
return CashuMint.getMintQuote(this._mintUrl, quote, this._customRequest);
async checkMintQuote(quote: string): Promise<MintQuoteResponse> {
return CashuMint.checkMintQuote(this._mintUrl, quote, this._customRequest);
}

/**
@@ -204,7 +204,7 @@ class CashuMint {
* @param MeltQuotePayload
* @returns
*/
public static async meltQuote(
public static async createMeltQuote(
mintUrl: string,
meltQuotePayload: MeltQuotePayload,
customRequest?: typeof request
@@ -233,8 +233,8 @@ class CashuMint {
* @param MeltQuotePayload
* @returns
*/
async meltQuote(meltQuotePayload: MeltQuotePayload): Promise<MeltQuoteResponse> {
return CashuMint.meltQuote(this._mintUrl, meltQuotePayload, this._customRequest);
async createMeltQuote(meltQuotePayload: MeltQuotePayload): Promise<MeltQuoteResponse> {
return CashuMint.createMeltQuote(this._mintUrl, meltQuotePayload, this._customRequest);
}

/**
@@ -243,7 +243,7 @@ class CashuMint {
* @param quote Quote ID
* @returns
*/
public static async getMeltQuote(
public static async checkMeltQuote(
mintUrl: string,
quote: string,
customRequest?: typeof request
@@ -274,8 +274,8 @@ class CashuMint {
* @param quote Quote ID
* @returns
*/
async getMeltQuote(quote: string): Promise<MeltQuoteResponse> {
return CashuMint.getMeltQuote(this._mintUrl, quote, this._customRequest);
async checkMeltQuote(quote: string): Promise<MeltQuoteResponse> {
return CashuMint.checkMeltQuote(this._mintUrl, quote, this._customRequest);
}

/**
18 changes: 9 additions & 9 deletions src/CashuWallet.ts
Original file line number Diff line number Diff line change
@@ -341,21 +341,21 @@ class CashuWallet {
* @param amount Amount requesting for mint.
* @returns the mint will return a mint quote with a Lightning invoice for minting tokens of the specified amount and unit
*/
async mintQuote(amount: number) {
async createMintQuote(amount: number) {
const mintQuotePayload: MintQuotePayload = {
unit: this._unit,
amount: amount
};
return await this.mint.mintQuote(mintQuotePayload);
return await this.mint.createMintQuote(mintQuotePayload);
}

/**
* Gets an existing mint quote from the mint.
* @param quote Quote ID
* @returns the mint will create and return a Lightning invoice for the specified amount
*/
async getMintQuote(quote: string) {
return await this.mint.getMintQuote(quote);
async checkMintQuote(quote: string) {
return await this.mint.checkMintQuote(quote);
}

/**
@@ -397,12 +397,12 @@ class CashuWallet {
* @param invoice LN invoice that needs to get a fee estimate
* @returns the mint will create and return a melt quote for the invoice with an amount and fee reserve
*/
async meltQuote(invoice: string): Promise<MeltQuoteResponse> {
async createMeltQuote(invoice: string): Promise<MeltQuoteResponse> {
const meltQuotePayload: MeltQuotePayload = {
unit: this._unit,
request: invoice
};
const meltQuote = await this.mint.meltQuote(meltQuotePayload);
const meltQuote = await this.mint.createMeltQuote(meltQuotePayload);
return meltQuote;
}

@@ -411,8 +411,8 @@ class CashuWallet {
* @param quote ID of the melt quote
* @returns the mint will return an existing melt quote
*/
async getMeltQuote(quote: string): Promise<MeltQuoteResponse> {
const meltQuote = await this.mint.getMeltQuote(quote);
async checkMeltQuote(quote: string): Promise<MeltQuoteResponse> {
const meltQuote = await this.mint.checkMeltQuote(quote);
return meltQuote;
}

@@ -476,7 +476,7 @@ class CashuWallet {
}
): Promise<MeltTokensResponse> {
if (!meltQuote) {
meltQuote = await this.mint.meltQuote({ unit: this._unit, request: invoice });
meltQuote = await this.mint.createMeltQuote({ unit: this._unit, request: invoice });
}
return await this.meltTokens(meltQuote, proofsToSend, {
keysetId: options?.keysetId,
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { encodeBase64ToJson, encodeJsonToBase64 } from './base64.js';
import { AmountPreference, Keys, Proof, Token, TokenEntry, TokenV2 } from './model/types/index.js';
import { AmountPreference, Keys, Proof, Token, TokenV2 } from './model/types/index.js';
import { TOKEN_PREFIX, TOKEN_VERSION } from './utils/Constants.js';
import { bytesToHex, hexToBytes } from '@noble/curves/abstract/utils';
import { sha256 } from '@noble/hashes/sha256';
36 changes: 18 additions & 18 deletions test/integration.test.ts
Original file line number Diff line number Diff line change
@@ -36,15 +36,15 @@ describe('mint api', () => {
test('request mint', async () => {
const mint = new CashuMint(mintUrl);
const wallet = new CashuWallet(mint, { unit });
const request = await wallet.mintQuote(100);
const request = await wallet.createMintQuote(100);
expect(request).toBeDefined();
const mintQuote = await wallet.getMintQuote(request.quote);
const mintQuote = await wallet.checkMintQuote(request.quote);
expect(mintQuote).toBeDefined();
});
test('mint tokens', async () => {
const mint = new CashuMint(mintUrl);
const wallet = new CashuWallet(mint, { unit });
const request = await wallet.mintQuote(1337);
const request = await wallet.createMintQuote(1337);
expect(request).toBeDefined();
expect(request.request).toContain('lnbc1337');
const tokens = await wallet.mintTokens(1337, request.quote);
@@ -55,34 +55,34 @@ describe('mint api', () => {
test('get fee for local invoice', async () => {
const mint = new CashuMint(mintUrl);
const wallet = new CashuWallet(mint, { unit });
const request = await wallet.mintQuote(100);
const fee = (await wallet.meltQuote(request.request)).fee_reserve;
const request = await wallet.createMintQuote(100);
const fee = (await wallet.createMeltQuote(request.request)).fee_reserve;
expect(fee).toBeDefined();
// because local invoice, fee should be 0
expect(fee).toBe(0);
});
test('get fee for external invoice', async () => {
const mint = new CashuMint(mintUrl);
const wallet = new CashuWallet(mint, { unit });
const fee = (await wallet.meltQuote(externalInvoice)).fee_reserve;
const fee = (await wallet.createMeltQuote(externalInvoice)).fee_reserve;
expect(fee).toBeDefined();
// because external invoice, fee should be > 0
expect(fee).toBeGreaterThan(0);
});
test('pay local invoice', async () => {
const mint = new CashuMint(mintUrl);
const wallet = new CashuWallet(mint, { unit });
const request = await wallet.mintQuote(100);
const request = await wallet.createMintQuote(100);
const tokens = await wallet.mintTokens(100, request.quote);

// expect no fee because local invoice
const mintQuote = await wallet.mintQuote(10);
const quote = await wallet.meltQuote(mintQuote.request);
const mintQuote = await wallet.createMintQuote(10);
const quote = await wallet.createMeltQuote(mintQuote.request);
const fee = quote.fee_reserve;
expect(fee).toBe(0);

// get the quote from the mint
const quote_ = await wallet.getMeltQuote(quote.quote);
const quote_ = await wallet.checkMeltQuote(quote.quote);
expect(quote_).toBeDefined();

const sendResponse = await wallet.send(10, tokens.proofs);
@@ -104,15 +104,15 @@ describe('mint api', () => {
test('pay external invoice', async () => {
const mint = new CashuMint(mintUrl);
const wallet = new CashuWallet(mint, { unit });
const request = await wallet.mintQuote(3000);
const request = await wallet.createMintQuote(3000);
const tokens = await wallet.mintTokens(3000, request.quote);

const meltQuote = await wallet.meltQuote(externalInvoice);
const meltQuote = await wallet.createMeltQuote(externalInvoice);
const fee = meltQuote.fee_reserve;
expect(fee).toBeGreaterThan(0);

// get the quote from the mint
const quote_ = await wallet.getMeltQuote(meltQuote.quote);
const quote_ = await wallet.checkMeltQuote(meltQuote.quote);
expect(quote_).toBeDefined();

const sendResponse = await wallet.send(2000 + fee, tokens.proofs);
@@ -135,7 +135,7 @@ describe('mint api', () => {
test('test send tokens exact without previous split', async () => {
const mint = new CashuMint(mintUrl);
const wallet = new CashuWallet(mint, { unit });
const request = await wallet.mintQuote(64);
const request = await wallet.createMintQuote(64);
const tokens = await wallet.mintTokens(64, request.quote);

const sendResponse = await wallet.send(64, tokens.proofs);
@@ -148,7 +148,7 @@ describe('mint api', () => {
test('test send tokens with change', async () => {
const mint = new CashuMint(mintUrl);
const wallet = new CashuWallet(mint, { unit });
const request = await wallet.mintQuote(100);
const request = await wallet.createMintQuote(100);
const tokens = await wallet.mintTokens(100, request.quote);

const sendResponse = await wallet.send(10, tokens.proofs);
@@ -161,7 +161,7 @@ describe('mint api', () => {
test('receive tokens with previous split', async () => {
const mint = new CashuMint(mintUrl);
const wallet = new CashuWallet(mint, { unit });
const request = await wallet.mintQuote(100);
const request = await wallet.createMintQuote(100);
const tokens = await wallet.mintTokens(100, request.quote);

const sendResponse = await wallet.send(10, tokens.proofs);
@@ -174,7 +174,7 @@ describe('mint api', () => {
test('receive tokens with previous mint', async () => {
const mint = new CashuMint(mintUrl);
const wallet = new CashuWallet(mint, { unit });
const request = await wallet.mintQuote(64);
const request = await wallet.createMintQuote(64);
const tokens = await wallet.mintTokens(64, request.quote);
const encoded = getEncodedToken({
token: [{ mint: mintUrl, proofs: tokens.proofs }]
@@ -192,7 +192,7 @@ describe('mint api', () => {
const privKeyBob = secp256k1.utils.randomPrivateKey();
const pubKeyBob = secp256k1.getPublicKey(privKeyBob);

const request = await wallet.mintQuote(64);
const request = await wallet.createMintQuote(64);
const tokens = await wallet.mintTokens(64, request.quote);

const { send } = await wallet.send(64, tokens.proofs, { pubkey: bytesToHex(pubKeyBob) });
4 changes: 2 additions & 2 deletions test/request.test.ts
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ describe('requests', () => {
});

const wallet = new CashuWallet(mint, { unit });
await wallet.getMeltQuote('test');
await wallet.checkMeltQuote('test');

expect(request).toBeDefined();
// expect(request!['content-type']).toContain('application/json');
@@ -61,7 +61,7 @@ describe('requests', () => {
const wallet = new CashuWallet(mint, { unit });
setGlobalRequestOptions({ headers: { 'x-cashu': 'xyz-123-abc' } });

await wallet.getMeltQuote('test');
await wallet.checkMeltQuote('test');

expect(request).toBeDefined();
expect(request!['x-cashu']).toContain('xyz-123-abc');
6 changes: 3 additions & 3 deletions test/wallet.test.ts
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ describe('test fees', () => {
} as MeltQuoteResponse);
const wallet = new CashuWallet(mint, { unit });

const fee = await wallet.getMeltQuote('test');
const fee = await wallet.checkMeltQuote('test');
const amount = 2000;

expect(fee.fee_reserve + amount).toEqual(2020);
@@ -242,7 +242,7 @@ describe('payLnInvoice', () => {
} as MeltQuoteResponse);

const wallet = new CashuWallet(mint, { unit });
const meltQuote = await wallet.getMeltQuote('test');
const meltQuote = await wallet.checkMeltQuote('test');

const result = await wallet.payLnInvoice(invoice, proofs, meltQuote);

@@ -291,7 +291,7 @@ describe('payLnInvoice', () => {
});

const wallet = new CashuWallet(mint, { unit });
const meltQuote = await wallet.getMeltQuote('test');
const meltQuote = await wallet.checkMeltQuote('test');
const result = await wallet.payLnInvoice(invoice, [{ ...proofs[0], amount: 3 }], meltQuote);

expect(result.isPaid).toBe(true);