0.1.44 • Published 10 months ago
@lawallet/sdk v0.1.44
@lawallet/sdk
SDK for LaWallet
Installation
pnpm add @lawallet/sdk @nostr-dev-kit/ndk
Usage examples
Fetch
import { NDKPrivateKeySigner } from '@nostr-dev-kit/ndk';
import { Wallet } from '@lawallet/sdk';
const Alice = new Wallet({ signer: NDKPrivateKeySigner.generate() });
const Bob = new Wallet({ signer: NDKPrivateKeySigner.generate() });
Alice.fetch().then(({ lnurlpData, nostr }) => {
// returns lnurlpData -> /.well-known/lnurlp/<user> response
console.log('lnurlpData: ', lnurlpData);
// returns nostr profile
console.log('Nostr Profile: ', nostr);
});
getBalance
// Returns BTC balance in millisatoshis
Alice.getBalance('BTC').then((bal) => {
console.log(`Account BTC Balance: ${bal} milisatoshis ~ ${(bal / 100000000).toFixed(8)} BTC`);
});
getTransactions
// Returns all transactions
Alice.getTransactions().then((transactions) => {
console.log('Total account transactions: ', transactions.length);
});
Cards
Alice.addCard('CARD_NONCE');
Alice.getCards().then(async (cards) => {
if (cards.length) {
// Get first card
let firstCard = cards[0];
// Pause first card
await firstCard.disable();
// Add card limit -> 1000 satoshis every 12 hours
await firstCard.addLimit({
tokenId: 'BTC',
limitType: 'hours',
limitTime: 12,
limitAmount: 1000000,
});
// Set card metadata (name, description)
await firstCard.setMetadata({ name: 'card name', description: 'card description' });
// Prepare the event to transfer the card
const transferEvent = await firstCard.createTransferEvent();
// Claim card with another account
await Bob.claimCardTransfer(transferEvent);
}
});
Payments
Alice.generateInvoice({ milisatoshis: 1000 }).then((invoice) => {
// Generate payment request of this wallet
console.log(invoice.pr);
});
Alice.createZap({ milisatoshis: 1000, receiverPubkey: Bob.pubkey }).then((invoice) => {
// Generate zap request -> returns payment request of zap request
const { pr: paymentRequest } = invoice;
// Pay invoice
Alice.payInvoice({
paymentRequest,
onSuccess: () => {
console.log('Invoice paid successfully');
},
});
});
// Send transaction
Alice.sendTransaction({
tokenId: 'BTC',
receiver: 'cuervo@lawallet.ar',
amount: 1000,
comment: 'Hello!',
onSuccess: () => {
console.log('Transaction successfully sent');
},
onError: () => {
console.log('An error occurred with the transaction');
},
});
// Send internal transaction
Alice.sendInternalTransaction({
tokenId: 'BTC',
receiver: 'USER_HEX_PUBKEY',
amount: 1000,
comment: 'Hello!',
onSuccess: () => {
console.log('Transaction successfully sent');
},
onError: () => {
console.log('An error occurred with the transaction');
},
});
To - do
- Project startup (Linters, Typescript, Dependencies)
- Federation
- Identity
- Pubkey info
- Lightning Info
- Nostr Profile
- Card
- info (design, name, description)
- limits
- enable/disable
- setMetadata
- addLimit
- restartLimits
- replaceLimits
- createTransferEvent
Wallet
- Signer + Identity
- Wallet Information
- getBalance
- getTransactions
- getCards
- signEvent
- createZap
- createInvoice
- sendTransaction
- send internal / lud16 / lnurl transfer
- onSuccess()
- onError()
- payInvoice
- claimCardTransfer
- addCard / activateCard
- registerHandle (request + payment + claim)
Tests coverage
- Federation
- Identity
- Wallet
0.1.43
10 months ago
0.1.44
10 months ago
0.1.41
10 months ago
0.1.42
10 months ago
0.1.40
10 months ago
0.1.39
10 months ago
0.1.34
10 months ago
0.1.35
10 months ago
0.1.36
10 months ago
0.1.37
10 months ago
0.1.38
10 months ago
0.1.32
10 months ago
0.1.33
10 months ago
0.1.30
10 months ago
0.1.31
10 months ago
0.1.23
10 months ago
0.1.24
10 months ago
0.1.25
10 months ago
0.1.26
10 months ago
0.1.27
10 months ago
0.1.28
10 months ago
0.1.21
10 months ago
0.1.22
10 months ago
0.1.2
10 months ago
0.1.10
11 months ago
0.1.0
11 months ago