Skip to content

Commit

Permalink
docs(rgbpp-sdk/btc): explain the difference between origin/domain (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShookLyngs authored Mar 24, 2024
1 parent 709c181 commit f71f216
Showing 1 changed file with 52 additions and 21 deletions.
73 changes: 52 additions & 21 deletions packages/btc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,64 @@ This is the BTC part of the rgbpp-sdk for:

This lib is based on the foundation of the [unisat wallet-sdk](https://github.com/unisat-wallet/wallet-sdk) ([license](https://github.com/unisat-wallet/wallet-sdk/blob/master/LICENSE)). We've simplified the logic of transaction construction and fee collection process to adapt to the specific needs of RGBPP. You can refer to the unisat wallet-sdk repo for more difference.

## Getting started
## Installation

```bash
# Install via npm:
$ npm i @rgbpp-sdk/btc
# Install via yarn:
$ yarn add @rgbpp-sdk/btc
# Install via pnpm:
$ pnpm add @rgbpp-sdk/btc
```

## BtcAssetsApi

### Get an access token

The BtcAssetsApi is currently limited to verified apps only.
If you're a developer and want to access the BtcAssetsApi service,
please email us to request a JWT token for your app: [email protected].

### Using the `btc-assets-api` service
In the email, you should provide us some information about your app:

Initialize BtcAssetsApi service with your access token (API-Key):
- `name`: Your app name, e.g. "rgbpp-app"
- `domain`: Your app domain, e.g. "rgbpp.app" (without protocol)

### Initialize the service

#### Browser

Initialize BtcAssetsApi service with your access token:

```typescript
import { BtcAssetsApi } from '@rgbpp-sdk/btc';

const service = BtcAssetsApi.fromToken('https://your-btc-assets-api.url', 'token');
const service = BtcAssetsApi.fromToken('https://your-btc-assets-api.url', 'your_access_token');
```

When initializing the service in Node.js, you should pass an extra `origin` param, which should be a URL matching your domain, or matching the domain of your token:
#### Node.js

You should pass `origin` when initializing BtcAssetsApi service in Node.js:

```typescript
import { BtcAssetsApi } from '@rgbpp-sdk/btc';

// Without token
const service = new BtcAssetsApi({
url: 'https://your-btc-assets-api.url',
app: 'your-test-app-name',
domain: 'your.app',
origin: 'https://your.app',
});

// With token
const service = BtcAssetsApi.fromToken('https://your-btc-assets-api.url', 'token', 'https://your.app');
const service = BtcAssetsApi.fromToken('https://your-btc-assets-api.url', 'your_access_token', 'https://your.app');
```

The `origin` prop is used to verify your token's corresponding `domain`.
For example, if your token was generated in the domain of `your.app`,
you should pass `https://your.app` as the `origin` prop.
Otherwise, the service will reject your request.

Note the format difference `domain` and `origin`:

- `domain`: `your.app`, without protocol (`https://`, `http://`, etc.)
- `origin`: `https://your.app`, with protocol `https://`

### Start using the service

Once the initialization is complete, you can query from the service:

```typescript
Expand All @@ -53,9 +82,11 @@ console.log(res);
// }
```

### Constructing transaction
All available APIs in the [BtcAssetsApi](#btcassetsapi-1) section.

## Transaction

Transfer BTC from a `P2WPKH` address:
### Transfer BTC from a `P2WPKH` address

```typescript
import { sendBtc, BtcAssetsApi, DataSource, NetworkType } from '@rgbpp-sdk/btc';
Expand Down Expand Up @@ -85,7 +116,7 @@ const res = await service.sendTransaction(tx.toHex());
console.log('txid:', res.txid);
```

Transfer BTC from a `P2TR` address:
### Transfer BTC from a `P2TR` address

```typescript
import { sendBtc, BtcAssetsApi, DataSource, NetworkType } from '@rgbpp-sdk/btc';
Expand Down Expand Up @@ -121,7 +152,7 @@ const res = await service.sendTransaction(tx.toHex());
console.log('txid:', res.txid);
```

Create an `OP_RETURN` output:
### Create an `OP_RETURN` output

```typescript
import { sendBtc, BtcAssetsApi, DataSource, NetworkType } from '@rgbpp-sdk/btc';
Expand Down Expand Up @@ -153,7 +184,7 @@ const res = await service.sendTransaction(tx.toHex());
console.log('txid:', res.txid);
```

Transfer with predefined inputs/outputs:
### Transfer with predefined inputs/outputs

```typescript
import { sendUtxos, BtcAssetsApi, DataSource, NetworkType } from '@rgbpp-sdk/btc';
Expand Down Expand Up @@ -202,7 +233,7 @@ const res = await service.sendTransaction(tx.toHex());
console.log('txid:', res.txid);
```

Construct a isomorphic RGBPP BTC transaction from a CKB virtual transaction:
### Construct a isomorphic RGBPP transaction

```typescript
import { sendRgbppUtxos, BtcAssetsApi, DataSource, NetworkType } from '@rgbpp-sdk/btc';
Expand Down

1 comment on commit f71f216

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[{"name":"@rgbpp-sdk/btc","version":"0.0.0-snap-20240324134200"},{"name":"@rgbpp-sdk/ckb","version":"0.0.0-snap-20240324134200"}]

Please sign in to comment.