Skip to content

Commit

Permalink
Add more endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
jjramirezn committed Feb 22, 2024
1 parent 1068750 commit a430246
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 7 deletions.
8 changes: 2 additions & 6 deletions pages/wallet-provider/api/_meta.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
{
"index": "Intro",
"publish": "POST /publish",
"fetch": "GET /fetch",
"fetch": "POST /fetch",
"lnurlp-callback": "GET /lnurl/:pubkey/callback",
"card": "POST /card",
"card-pay-get": "GET /card/pay",
"card-pay-post": "POST /card/pay",
"card-scan": "GET /card/scan",
"card-reset-request": "POST /card/reset/request",
"card-reset-claim": "POST /card/reset/claim",
"card-config-request": "POST /card/config/request",
"card-data-request": "POST /card/data/request"
"card-scan": "GET /card/scan"
}
33 changes: 33 additions & 0 deletions pages/wallet-provider/api/card-pay-get.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# GET /card/pay

This is the second part of a [LUD-03](https://github.com/lnurl/luds/blob/luds/03.md)

Query parameters:

- **`k1: string`:** the `k1` value sent in the scan response.
- **`pr: string`:** the payment request generated by the POS.

## Examples

### Javascript
```js copy showLineNumbers
const options = {method: 'GET'};

fetch('https://api.lawallet.ar/card/pay?k1=DAnk15aXlNN4n1bln1oAbj&pr=lnbcrt1u1pj6txmspp5tgyd76xgfxqdxjwymyvyfjy4tg7y69t4227vzmzmkqgargezgfcsdqqcqzzsxqyz5vqsp5ej74wjyjylezg3kgg9s2g2tq6tr3cghjc5t53snelqm2j0qg7y4s9qyyssqmw45av50vj9y4975fdvd8svyl0uzt0mkwfa0rh7veuyyxm5xlqr5chz5953qjv8d3x4wtkhzlghy9hqpk9xpkszxy4gsrlx24d5tfkcpfytdt3', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
```

### Curl
``` bash copy
curl --request GET \
--url 'https://api.lawallet.ar/card/pay?k1=DAnk15aXlNN4n1bln1oAbj&pr=lnbcrt1u1pj6txmspp5tgyd76xgfxqdxjwymyvyfjy4tg7y69t4227vzmzmkqgargezgfcsdqqcqzzsxqyz5vqsp5ej74wjyjylezg3kgg9s2g2tq6tr3cghjc5t53snelqm2j0qg7y4s9qyyssqmw45av50vj9y4975fdvd8svyl0uzt0mkwfa0rh7veuyyxm5xlqr5chz5953qjv8d3x4wtkhzlghy9hqpk9xpkszxy4gsrlx24d5tfkcpfytdt3'
```

### Response
```json copy
{
"status": "OK"
}
```
64 changes: 64 additions & 0 deletions pages/wallet-provider/api/card-pay-post.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# POST /card/pay

This is the second part of an extended LUD-03 if on the extended scan we
determined that the card belongs to a lawallet federation that we know


## Examples
### Valid body
```json copy showLineNumbers
{
"k1": string, // the k1 value sent in the scan response
"npub": string, // the recipient's NPUB
"tokens": { // a list of amounts to request per token name
string: number, // a token name mapped to a token amount to withdraw
...
}
}
```

### Javascript
```js copy showLineNumbers
const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: '{"id":"243167e221d51886b98480acb1f9b61ad6855ebbd85830b79ee937760213719b","pubkey":"49001062a54bc52153dcc69b65927833be519104249324e462eab45d494a0c46","created_at":1698332759,"kind":21111,"tags":[["p","75a66127dea5733b9402bddf697d0b27d7a094dfad62d22d85fd7f9eb6973a6f"],["t","lawallet:withdrawRequest"]],"content":"{\n\t\"k1\": \"A-oH2Jb_RAIqgjgEPtU_Op\",\n\t\"npub\": \"npub1w38whq9ta2vuwtxeth0pp7ekmlqqxl0jeh8st90c9uld4yfjpdhqf6pwj4\",\n\t\"tokens\": {\n\t\t\"BTC\": 100000\n\t}\n}","sig":"277f099a823f68c02ecab3e9eba087db85e5a6bab535b75689ad275d80c6ace04fcae967e5a6040ec44e13c74e37be3045ce2550f6de73b1aaa34515436296ac"}'
};

fetch('https://api.lawallet.ar/card/pay', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
```

### Curl
``` bash copy
curl --request POST \
--url http://api.lawallet.ar/card/pay \
--header 'Content-Type: application/json' \
--data '{
"id": "243167e221d51886b98480acb1f9b61ad6855ebbd85830b79ee937760213719b",
"pubkey": "49001062a54bc52153dcc69b65927833be519104249324e462eab45d494a0c46",
"created_at": 1698332759,
"kind": 21111,
"tags": [
[
"p",
"75a66127dea5733b9402bddf697d0b27d7a094dfad62d22d85fd7f9eb6973a6f"
],
[
"t",
"lawallet:withdrawRequest"
]
],
"content": "{\n\t\"k1\": \"A-oH2Jb_RAIqgjgEPtU_Op\",\n\t\"npub\": \"npub1w38whq9ta2vuwtxeth0pp7ekmlqqxl0jeh8st90c9uld4yfjpdhqf6pwj4\",\n\t\"tokens\": {\n\t\t\"BTC\": 100000\n\t}\n}",
"sig": "277f099a823f68c02ecab3e9eba087db85e5a6bab535b75689ad275d80c6ace04fcae967e5a6040ec44e13c74e37be3045ce2550f6de73b1aaa34515436296ac"
}'
```

### Response
```json copy
{
"status": "OK"
}
```
53 changes: 53 additions & 0 deletions pages/wallet-provider/api/card-scan.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# GET /card/scan
This is the endpoint that is returned by the NFC card and supports both standard
[boltcard](https://www.boltcard.org/)

Query parameters:

- **`p: string`:** the PICC data returned by the NTAG.
- **`c: string`:** the HMAC returned by the NTAG.

Headers:

```http
X-LaWallet-Action: extendedScan
X-LaWallet-Param: federationId=<federation_id>
X-LaWallet-Param: tokens=<token>:<token>:...:<token>
```

Where:

- **`federation_id: string`:** the ID used to identify modules in the same "federation".
- **`token: string`:** the token names the POS is interested in.

Standard [LUD-03](https://github.com/lnurl/luds/blob/luds/03.md) result (returned when the header above **IS NOT** present, or present, but with a different federation ID):


```json
{
"tag": "withdrawRequest", // type of LNURL
"callback": "<API_BASE_URL>/card/pay", // The URL which LN SERVICE would accept a withdrawal Lightning invoice as query parameter
"k1": string, // Random or non-random string to identify the user's LN WALLET when using the callback URL
"defaultDescription": "LaWallet", // A default withdrawal invoice description
"minWithdrawable": 0, // Min amount (in millisatoshis) the user can withdraw
"maxWithdrawable": number, // Max amount (in millisatoshis) the user can withdraw
}
```

Extended [LUD-03](https://github.com/lnurl/luds/blob/luds/03.md) result (returned when the header above **IS** present and contains the same federation ID):

```json
{
"tag": "laWallet:withdrawRequest", // type of LNURL
"callback": "<API_BASE_URL>/card/pay", // The URL which LN SERVICE would accept a withdrawal extended invoice as request body
"k1": string, // Random or non-random string to identify the user's LN WALLET when using the callback URL
"defaultDescription": "LaWallet", // A default withdrawal invoice description
"tokens": { // A list of tokens available for withdrawal (a subset of the tokens given in the extension header)
string: { // The token name to provide extrema for
"minWithdrawable": 0, // Min amount (in the given token) the user can withdraw from LN SERVICE, or 0
"maxWithdrawable": number // Max amount (in the given token) the user can withdraw from LN SERVICE, or equal to minWithdrawable if the user has no choice over the amounts
},
...
}
}
```
61 changes: 61 additions & 0 deletions pages/wallet-provider/api/card.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# POST /card

This endpoint is for activating a card using a previously associated token (like
the ones usually given with cards the first time).

Request body: a NOSTR event with `content` like:

```json copy
{
"otc": string, // One-time-code linked to the card to associate
"delegation": { // NIP-26 delegation data (see: https://github.com/nostr-protocol/nips/blob/master/26.md)
"conditions": string, // a delegation condition query string
"token": string // the corresponding delegation token
}
}
```

Example:

```bash copy
curl --request POST \
--url http://localhost:3005/card/ \
--header 'Content-Type: application/json' \
--data '{
"id": "8fad06887f4f0475889f93e2291d0151da1157d2b7551a38afb865d47554b2e8",
"pubkey": "49001062a54bc52153dcc69b65927833be519104249324e462eab45d494a0c46",
"created_at": 1698091892,
"kind": 21111,
"tags": [
[
"p",
"75a66127dea5733b9402bddf697d0b27d7a094dfad62d22d85fd7f9eb6973a6f"
],
[
"t",
"card-activation-request"
]
],
"content": "{\"otc\":\"weirdcode\",\"delegation\":{\"conditions\":\"kind=1112&created_at<1700762400&created_at>1698080400\",\"token\":\"dbf1ef362920cf20f9b1c1861e5491061dfb386437edf09d00f53d3f987265057d0b731e7d71d7a3eeef3c870881cca5b82647a6efa8caf04f25e0ba52606aa5\"}}",
"sig": "285cbf75456456d7799a7450ac80b68d6ed31e833314a71609d2410016df34ef84d4c2187ae5670829909e60d0fdd73289250213e6ee90d98f7accce65317d2e"
}'
```


A `201` response status will contain a body consisting of a NOSTR event of the form:

```json copy
{
"id": "...",
"pubkey": "...",
"created_at": 1234567890,
"kind": 21111,
"tags": [
["p", "..."],
["e", "..."],
["t", "card-activate-response"]
],
"content": "{\"uuid\":\"...\",\"name\":\"...\",\"description\":\"...\",\"enabled\":true,\"holderPubKey\":\"...\",\"ntag424Cid\":\"...\"}",
"sig": "..."
}
```
101 changes: 101 additions & 0 deletions pages/wallet-provider/api/fetch.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# POST /fetch

This endpoint is for fetching events based on a filter, for uses where getting
events in a syncrhonous manner is desired. It receives a valid NOSTR as body
and returns an array of the events that match that filter

## Examples

### Valid Body
```json showLineNumbers copy
{
"#t": [
"internal-transaction-start"
],
"limit": 2
}
```

### Javascript
```js showLineNumbers copy
const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: '{"#t":["internal-transaction-start"]}'
};

fetch('https://api.lawallet.ar/nostr/fetch/', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
```

### Curl
```bash copy
curl --request POST \
--url https://api.lawallet.ar/nostr/fetch/ \
--header 'Content-Type: application/json' \
--data '{
"#t": [
"internal-transaction-start"
]
}'
```

## Response
```json showLineNumbers copy
[
{
"created_at": 1704494938,
"content": "{\"tokens\":{\"BTC\":10000}}",
"tags": [
[
"p",
"cdc5662509a7660dfef50c634f7f3e3f3b0d57d4ca49a42152ddac641ccfaeb2"
],
[
"p",
"e17feb5f2cf83546bcf7fd9c8237b05275be958bd521543c2285ffc6c2d654b3"
],
[
"t",
"internal-transaction-start"
],
[
"bolt11",
"lnbc100n1pjn6ey0pp5t7mtzhs8q8wfcwajrhfz94jxg87g70wuay4qw02ta8azx62wf0dqhp5wh3x2fmc3nwhjqfv3czss6lndyxsvyskykgdzus3t5cyjs0sf6sqcqzzsxqzjcsp5hueuk64e2ra4vm9j82zk827g8l7dss2my9wta68qj36yfg4v66ss9qyyssqz7gree6qkl57xalqlcpxf5ye9yvsnuf0wf54dle0kstrwgjm0hkpa3mvd9y6f90fe6p07c5kzgtelxwl32lxkwm2c0hjnwxvted6vzspah0cj0"
]
],
"kind": 1112,
"pubkey": "a4c10dc7da61602206cf4affe58cf721bae1593b23f76736ab1f65c8a1df9674",
"id": "7b6b54ee390ccd66b1340a2f5f4230420d8655fdc42ccf74136dd808840cfa18",
"sig": "7b0d274fd83b8def04624143e5c7205a52d368c05acbc4128c3d29cbc64f3ce424aba1f9e7ffdc2ce88ccdcdbc908462c50d8dc1b1c96fa7f93611e85f5eea71"
},
{
"created_at": 1704494923,
"content": "{\"tokens\":{\"BTC\":10000}}",
"tags": [
[
"p",
"cdc5662509a7660dfef50c634f7f3e3f3b0d57d4ca49a42152ddac641ccfaeb2"
],
[
"p",
"e17feb5f2cf83546bcf7fd9c8237b05275be958bd521543c2285ffc6c2d654b3"
],
[
"t",
"internal-transaction-start"
],
[
"bolt11",
"lnbc100n1pjn6ey0pp5t7mtzhs8q8wfcwajrhfz94jxg87g70wuay4qw02ta8azx62wf0dqhp5wh3x2fmc3nwhjqfv3czss6lndyxsvyskykgdzus3t5cyjs0sf6sqcqzzsxqzjcsp5hueuk64e2ra4vm9j82zk827g8l7dss2my9wta68qj36yfg4v66ss9qyyssqz7gree6qkl57xalqlcpxf5ye9yvsnuf0wf54dle0kstrwgjm0hkpa3mvd9y6f90fe6p07c5kzgtelxwl32lxkwm2c0hjnwxvted6vzspah0cj0"
]
],
"kind": 1112,
"pubkey": "a4c10dc7da61602206cf4affe58cf721bae1593b23f76736ab1f65c8a1df9674",
"id": "9d21651fac7b27b884bb802f6ba8af8cfd584020cb1c262fa88a9099882be444",
"sig": "0d6994e966292964136b5a7124c6e269cce0896fef98be25c0e4ad61c4b52f7b0fce537baddc8a0df283a1dae81983d25646dc3be28a994b3cabfed7e9815952"
}
]
```
37 changes: 37 additions & 0 deletions pages/wallet-provider/api/lnurlp-callback.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# GET /lnurl/:pubkey/callback

This endpoint generates and return an invoice that when paid, the corresponding
amount of sats will be accredited to the npub associated with it.

It accepts a path param that is a NOSTR pubkey (ANY valid NOSTR public), so
there is no need to have previously used Lawallet to receive money on a pubkey
that you have the privkey of.

It also accepts a query param of amount expressed in millisats

## Examples

### Javascript
```js copy showLineNumbers
const options = {method: 'GET'};

fetch('https://api.lawallet.ar/lnurlp/3699cf3fab1aa22dad84155639d35911013c63bbe6e26818e2584ed12cebeb6e/callback?amount=10000000', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
```

### Curl
```bash copy
curl --request GET \
--url 'https://api.lawallet.ar/lnurlp/3699cf3fab1aa22dad84155639d35911013c63bbe6e26818e2584ed12cebeb6e/callback?amount=10000000' \
--header 'User-Agent: insomnia/2023.5.8'
```

## Response
```json copy
{
"pr": "lnbc100u1pja0ynhpp5ufq0m7muf0wmwycpq6f9hgmytunvxkxj3az5w2em3u4pap899hgshp5quun9kwaplyekhdpjt7f88aelzwch82h579h9m6r0sh8xm8lqgwqcqzzsxqzjcsp5qshqdv98jtedq7vxx3qfzpvlqggjl8unu26lfm9tzglnlrqllxkq9qyyssqan0gdzmyzsgws97n79pg3s7dc9996m6hkcmke03agf30qaedjxq8eym39u83m6k3f9dhe37qz3kpwf7f28myn5gng488h870znskkvgqgp35yp",
"routes": []
}
```
2 changes: 1 addition & 1 deletion pages/wallet-provider/api/publish.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ curl --request POST \
}'
```

## Success
## Response

Upon successfully parsing and validating the request body, the asynchronous NOSTR API endpoint (ie. `{base API url}/nostr/publish`) will send an `EVENT` message to the Local NOSTR Relay (via WebSockets) with the request body as data and respond with:

Expand Down
2 changes: 2 additions & 0 deletions theme.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const config: DocsThemeConfig = {
),
},
sidebar: {
autoCollapse: true,
defaultMenuCollapseLevel: 0,
titleComponent({title}) {
const re = /^(?<method>.+) (?<name>.+$)/;
const match = re.exec(title);
Expand Down

0 comments on commit a430246

Please sign in to comment.