### Run Satellite Locally Source: https://github.com/lovvtide/satellite-web/blob/master/README.md Instructions for cloning the repository, installing dependencies using npm with legacy peer dependencies, and starting the development server. ```bash git clone git@github.com:lovvtide/satellite-web.git cd satellite-web npm i --legacy-peer-deps npm run dev ``` -------------------------------- ### Purchase Storage and Get Invoice Source: https://github.com/lovvtide/satellite-web/blob/master/docs/cdn.md Demonstrates how to request storage, obtain a payment offer, sign a payment event, and get a lightning invoice using the Satellite CDN API. Requires user interaction for signing Nostr events. ```js const requestCredit = await window.nostr.signEvent({ created_at: Math.ceil(Date.now() / 1000), content: 'Request Storage', kind: 22242, tags: [ [ 'gb_months', '1' ] ] }); const service = await fetch(`https://api.satellite.earth/v1/media/account/credit?auth=${encodeURIComponent(JSON.stringify(requestCredit))}`); const payment = await window.nostr.signEvent(service.payment); const invoice = await fetch(service.callback + `?amount=${service.amount}&nostr=${encodeURIComponent(JSON.stringify(payment))}`); ``` -------------------------------- ### Fetch Account Information Source: https://github.com/lovvtide/satellite-web/blob/master/docs/cdn.md Shows how to authenticate and fetch user account details from the Satellite CDN API to verify storage purchases. Requires user interaction for signing Nostr events. ```js const requestAccount = await window.nostr.signEvent({ created_at: Math.ceil(Date.now() / 1000), content: 'Authenticate User', kind: 22242, tags: [] }); const account = await fetch(`https://api.satellite.earth/v1/media/account?auth=${encodeURIComponent(JSON.stringify(requestAccount))}`); if (account.creditTotal > 0) { alert('payment succeeded'); } ``` -------------------------------- ### Request Credit Offer Source: https://github.com/lovvtide/satellite-web/blob/master/docs/cdn.md Requests an offer to buy credit for satellite services. Requires a signed authentication event specifying the desired GB months. ```APIDOC GET /account/credit - Get an offer to buy credit #### Params - `auth` - The signed, stringified, url-encoded kind `22242` event to request an offer of services on behalf of the user. The event MUST include a `gb_months` tag specifying an integer number (formatted as a string) of GB months credit the user wants to purchase. The value of the `content` field MUST be equal to `Request Storage`. #### Returns `200` - Fetched account - `callback` `String` - The URL to send to signed offer to - `amount` `Number` - The amount *in millisats* requried for payment of requested service - `rateFiat` `Object` - Cost per GB per month in various fiat currencies - `usd` `Number` - Rate per GB per month in US dollars - `offer` `Object` - Kind `9733` event representing Satellite's offer to purchase CDN service `403` - Auth missing or failed to verify ``` -------------------------------- ### Account Information Source: https://github.com/lovvtide/satellite-web/blob/master/docs/cdn.md Retrieves detailed account information, including storage usage, purchased credits, and file metadata. Requires authentication. ```APIDOC GET /account/credit - Get account information #### Returns `200` - Fetched account - `storageTotal` `Number` - Total bytes currently stored - `creditTotal` `Number` - Total number of GB months purchased to date - `usageTotal` `Number` - Total number of GB months used to date - `paidThrough` `Number` - Timestamp at which storage will expire - `timeRemaining` `Number` - Seconds remaining until storage expires, from time of request - `rateFiat` `Object` - Cost per GB per month in various fiat currencies - `usd` `Number` - Rate per GB per month in US dollars - `exchangeFiat` `Object` - Exchange rate between sats and various fiat currencies at time of request - `usd` `Number` - Exchange rate beteen sats and US dollars at time of request - `files` `Array` - Metadata for currently stored files - `File` `Object` - `transactions` `Array` - Record of paid invoices - `Transaction` `Object` - `order` `Object` - Kind `9733` event representing Satellite's offer to purchase CDN service - `payment` `Object` - Kind `9734` event representing user's payment for service - `receipt` `Object` - Kind `9735` event confirming purchase of service `403` - Auth missing or failed to verify ``` -------------------------------- ### Satellite CDN API Reference Source: https://github.com/lovvtide/satellite-web/blob/master/docs/cdn.md Provides an overview of the Satellite CDN API endpoints for managing media accounts and uploads. Includes details on authentication via Nostr events and parameters for various operations. ```APIDOC API Endpoints: 1. `/v1/media/account/credit` (GET) - Purpose: Request storage credit and receive a payment offer. - Authentication: Requires a signed Nostr `kind: 22242` event in the `auth` query parameter. The event content should indicate the storage request (e.g., `Request Storage`) and include `gb_months` tag. - Parameters: - `auth`: URI-encoded JSON string of the signed Nostr event. - Returns: JSON object containing payment details (`payment`, `amount`) and a callback URL (`callback`) for invoice generation. 2. `/v1/media/account` (GET) - Purpose: Fetch user account information, including storage credit and payment history. - Authentication: Requires a signed Nostr `kind: 22242` event in the `auth` query parameter. The event content should indicate authentication (e.g., `Authenticate User`). - Parameters: - `auth`: URI-encoded JSON string of the signed Nostr event. - Returns: JSON object with account details, including `creditTotal` (available storage in GB). 3. File Uploads: - (Details for file upload endpoint not provided in the source text, but implied by NIP-94 compatibility and serving files.) - NIP-94 Compliance: For each uploaded file, Satellite computes NIP-94 parameters which can be used to create Nostr `kind: 1063` events. ``` -------------------------------- ### Upload File with Nostr Auth Source: https://github.com/lovvtide/satellite-web/blob/master/docs/cdn.md Demonstrates how to sign an authorization event using Nostr and upload a file to Satellite.earth. This involves creating a kind 22242 event with specific tags for file metadata and then sending a PUT request with the file as the body. ```js const uploadAuth = await window.nostr.signEvent({ created_at: Math.ceil(Date.now() / 1000), kind: 22242, content: 'Authorize Upload', tags: [ [ 'name', file.name ], [ 'size', 1234567 ], [ 'label', 'foo' ] ] }); const response = await fetch(`https://api.satellite.earth/v1/media/item?auth=${encodeURIComponent(JSON.stringify(uploadAuth))}`, { method: 'PUT', body: file }); ``` -------------------------------- ### Satellite.earth Media API Source: https://github.com/lovvtide/satellite-web/blob/master/docs/cdn.md Provides details on the Satellite.earth media API endpoints for file management. It includes specifications for uploading, deleting, and retrieving account information, along with request parameters, response codes, and expected data formats. ```APIDOC PUT /item - Upload a file Params: - `auth` - The signed, stringified, url-encoded kind `22242` event to authorize a file upload. The value of the `content` field MUST be equal to `Authorize Upload`. Clients MAY include any or all of the following tags in the signed auth event: a `name` tag to indicate the file's name, a `size` tag (which, if present, will cause the request to fail if the actual size of the file does not match this value) and a `label` tag (the value being an arbitrary string which applications might need to otherwise classify/identify the uploaded file). Note that a unique auth event must be signed *per request*. Reusing an auth event will fail. Returns: `200` - File uploaded successfully - `created` `Number`- Time of upload, according to server - `sha256` `String` - SHA256 hash as computed by server - `name` `String` - Filename as provided by client - `url` `String` - URL to access file on CDN - `infohash` `String` - Torrent infohash as computed by server - `magnet` `String` - Torrent magnet link - `size` `Number` - File size in bytes - `type` `String` - File MIME type as inferred by server - `nip94` `Array` - Tags for creating NIP-94 event, if that's what the client wants to do - `label` `String` - Value from label tag in auth event, if provided `400` - Bad request `402` - Payment required (ensure that account has credit) `403` - Auth missing, failed to verify, or not unique Body: The body of the request MUST contain the file's data DELETE /item - Delete a file Params: - `auth` - The signed, stringified, url-encoded kind `22242` event to authorize a file deletion. Clients MUST specify the `sha256` hash of the file they wish to delete as a tag in this event. The value of the `content` field MUST be equal to `Delete Item`. Returns: `200` - File deleted successfully `400` - Bad request (probably missing `sha256` tag) `403` - Auth missing or failed to verify GET /account - Get user account info Params: - `auth` - The signed, stringified, url-encoded kind `22242` event to authorize fetching account info. The value of the `content` field MUST be equal to `Authenticate User`. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.